From patchwork Thu Jan 4 12:57:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suganath Prabu S X-Patchwork-Id: 10144709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2AAB96034B for ; Thu, 4 Jan 2018 12:58:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17F932817F for ; Thu, 4 Jan 2018 12:58:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CDD528635; Thu, 4 Jan 2018 12:58:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 985002817F for ; Thu, 4 Jan 2018 12:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752858AbeADM6D (ORCPT ); Thu, 4 Jan 2018 07:58:03 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:33314 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752671AbeADM6B (ORCPT ); Thu, 4 Jan 2018 07:58:01 -0500 Received: by mail-qt0-f196.google.com with SMTP id e2so1738033qti.0 for ; Thu, 04 Jan 2018 04:58:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EtnBnpf/OmtPEGs+pDjjgkCcw9+EG+hpqL3LAwau+kU=; b=g7Ib13fAlCaFNRwk/7N+yH+NHscuQfRmV3Ck4mgYMdewweYOL8wYf9tUGKAqF5N1ol b3ov9/W7o8Ns2XsFsilqipHXwhsxfE/dTbtqHGe6AB2QluljGozIpyy9OR4O1vE0CYwc 16MtI4sBXriDH/HHkCXTj5KvjjchDJkIUC5BI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EtnBnpf/OmtPEGs+pDjjgkCcw9+EG+hpqL3LAwau+kU=; b=RgYXOHnrD4ZD9TczCtJJGPE+iael4zHYAIzCJpPJtJc+kD9fCg00MN5bbzP838Db5Z SGSCCVBKvD5rJxRLi1XMjhJW6HvNwArSJgOHgyHKjHdKOdh0eVl4Rf5jOYpE0pKwELyv d+Ae3e59kqsWcNvMg8C5/HPrD/Q6+d3z7eJorMdbbRHPGah/8+DEMNFiJZFbLtTStUkh lK+Ids4CiDDsUQzUq4hpqBe5gXi/wWxmyzXJ0oM/NQYbCcn4hmlCismLeh1rZUlCEkP6 roYcPHE8pRs1J8u32cTaOXRsSO0ru2kUYGbshfGOfTt2QEkoA8zRxKPtpIEaYYSr+JvO 2XTw== X-Gm-Message-State: AKGB3mLEGewLH+eiN2GuV1bw7c5C/IjW9bUyltMEI/nTVvKWMeK5qVuF v+IpttPEW3LJHIbKYjuuIJ8Xxy73 X-Google-Smtp-Source: ACJfBou3eCk0TbhFlenvSZIHKwL+c/YB2hDItfq3bXudLk7xON+FwHpzmYwEWCOe7o80XY7kWuL20w== X-Received: by 10.200.54.176 with SMTP id a45mr5781075qtc.176.1515070680261; Thu, 04 Jan 2018 04:58:00 -0800 (PST) Received: from dhcp-135-24-192-103.dhcp.broadcom.net ([192.19.239.250]) by smtp.googlemail.com with ESMTPSA id v58sm2064328qtk.18.2018.01.04.04.57.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Jan 2018 04:57:59 -0800 (PST) From: Suganath Prabu S To: linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org Cc: Sathya.Prakash@broadcom.com, sreekanth.reddy@broadcom.com, chaitra.basappa@broadcom.com, Hannes Reinecke , Hannes Reinecke , Suganath Prabu S Subject: [Resend 08/11] mpt3sas: simplify task management functions Date: Thu, 4 Jan 2018 04:57:08 -0800 Message-Id: <1515070631-14740-9-git-send-email-suganath-prabu.subramani@broadcom.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1515070631-14740-1-git-send-email-suganath-prabu.subramani@broadcom.com> References: <1515070631-14740-1-git-send-email-suganath-prabu.subramani@broadcom.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hannes Reinecke No functional change. Code optimization. One can simply check 'target_busy' or 'device_busy' when figuring out if there are outstanding commands; no need to painstakingly counting them by hand. Signed-off-by: Hannes Reinecke Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 88 +++--------------------------------- 1 file changed, 7 insertions(+), 81 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 8870cef..c6cbadc 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -1517,74 +1517,6 @@ _scsih_scsi_lookup_find_by_scmd(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd } /** - * _scsih_scsi_lookup_find_by_target - search for matching channel:id - * @ioc: per adapter object - * @id: target id - * @channel: channel - * Context: This function will acquire ioc->scsi_lookup_lock. - * - * This will search for a matching channel:id in the scsi_lookup array, - * returning 1 if found. - */ -static u8 -_scsih_scsi_lookup_find_by_target(struct MPT3SAS_ADAPTER *ioc, int id, - int channel) -{ - u8 found; - unsigned long flags; - int i; - - spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); - found = 0; - for (i = 0 ; i < ioc->scsiio_depth; i++) { - if (ioc->scsi_lookup[i].scmd && - (ioc->scsi_lookup[i].scmd->device->id == id && - ioc->scsi_lookup[i].scmd->device->channel == channel)) { - found = 1; - goto out; - } - } - out: - spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); - return found; -} - -/** - * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun - * @ioc: per adapter object - * @id: target id - * @lun: lun number - * @channel: channel - * Context: This function will acquire ioc->scsi_lookup_lock. - * - * This will search for a matching channel:id:lun in the scsi_lookup array, - * returning 1 if found. - */ -static u8 -_scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id, - unsigned int lun, int channel) -{ - u8 found; - unsigned long flags; - int i; - - spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); - found = 0; - for (i = 0 ; i < ioc->scsiio_depth; i++) { - if (ioc->scsi_lookup[i].scmd && - (ioc->scsi_lookup[i].scmd->device->id == id && - ioc->scsi_lookup[i].scmd->device->channel == channel && - ioc->scsi_lookup[i].scmd->device->lun == lun)) { - found = 1; - goto out; - } - } - out: - spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); - return found; -} - -/** * scsih_change_queue_depth - setting device queue depth * @sdev: scsi device struct * @qdepth: requested queue depth @@ -2849,19 +2781,9 @@ mpt3sas_scsih_issue_tm(struct MPT3SAS_ADAPTER *ioc, u16 handle, uint channel, rc = FAILED; break; - case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: - if (_scsih_scsi_lookup_find_by_target(ioc, id, channel)) - rc = FAILED; - else - rc = SUCCESS; - break; case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET: - if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel)) - rc = FAILED; - else - rc = SUCCESS; - break; + case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: rc = SUCCESS; break; @@ -3082,7 +3004,9 @@ scsih_dev_reset(struct scsi_cmnd *scmd) r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, scmd->device->id, scmd->device->lun, MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30); - + /* Check for busy commands after reset */ + if (r == SUCCESS && atomic_read(&scmd->device->device_busy)) + r = FAILED; out: sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n", ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); @@ -3144,7 +3068,9 @@ scsih_target_reset(struct scsi_cmnd *scmd) r = mpt3sas_scsih_issue_locked_tm(ioc, handle, scmd->device->channel, scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30); - + /* Check for busy commands after reset */ + if (r == SUCCESS && atomic_read(&starget->target_busy)) + r = FAILED; out: starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n", ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);