From patchwork Mon Sep 24 06:35:11 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: 10611925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 260FE13A4 for ; Mon, 24 Sep 2018 06:35:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 334A82867F for ; Mon, 24 Sep 2018 06:35:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2759D29BD9; Mon, 24 Sep 2018 06:35:32 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 842F52867F for ; Mon, 24 Sep 2018 06:35:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726218AbeIXMgD (ORCPT ); Mon, 24 Sep 2018 08:36:03 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43306 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725982AbeIXMgD (ORCPT ); Mon, 24 Sep 2018 08:36:03 -0400 Received: by mail-pg1-f194.google.com with SMTP id q19-v6so7862490pgn.10 for ; Sun, 23 Sep 2018 23:35:30 -0700 (PDT) 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=bAnr+XZjx2o/sIi56CxxaeJ/uJF1SYkVYGPhWo5CVu8=; b=arOaSUWWmGzd8mnGzjC+upKzptZtPMp99JHxpgwyHMBYw7LZL5qhWyLhj55nHrcpL2 iNzKLPDX5upsEM840MgGP/eh5197scWW8lq4+TeHqFPhyrfKfTQPesL/kzBmz2Q/J1u+ oTtoRecpZZGLOrZqBq5cE0bsLD1oGx+2Z0i/E= 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=bAnr+XZjx2o/sIi56CxxaeJ/uJF1SYkVYGPhWo5CVu8=; b=qFuIQhPIZB0w28zPhhfM+XvtDh674s1gFDRP39CNEHd1ZhGEhngQf8PLgrpovZsz0l nr6+IJ+5u+vWUtzPYQdrgSCYklj0B4hCWtCKjxSZ3XCWqBnNfciBWMNuSD8SADTLiwUk d9sJChzVdMXmhhh5aWh/gv0lZM5VRUK9AovAli+VjiqNU0BDZ/ipkufNpPwlq5Rmn+TM jYGiOV4YxKExX1kmnIS9mA+I1I71zjSLpircOX5rtCCH6oRQU4qQKgOFZVze8s/itoF2 rUFpaM2viQTRqb/gbu7JxUC9kGLmb1WSGq7GRj0tHZ60fBeid9T0+zO2ij8poGoMFGa0 OkXg== X-Gm-Message-State: ABuFfogcSjynWI13xsbdS1pjs5yIsdU8scsyn4IWvSwYL/NDyPwspL2w zzmI/gQqnCj/mQHoiVrs2wqGiIaGmUo= X-Google-Smtp-Source: ACcGV60EhIB4vXbQkF9KxnTOXk0CWXnZUUaw+pWhsZt6ErmXTPmnAtLnWvsDiwvUQ/+85uia2qFfcQ== X-Received: by 2002:a63:69c3:: with SMTP id e186-v6mr8083298pgc.431.1537770929396; Sun, 23 Sep 2018 23:35:29 -0700 (PDT) Received: from dhcp-10-123-74-106.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id 203-v6sm12287064pge.25.2018.09.23.23.35.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Sep 2018 23:35:28 -0700 (PDT) From: Suganath Prabu S To: linux-scsi@vger.kernel.org Cc: Sathya.Prakash@broadcom.com, sreekanth.reddy@broadcom.com, Suganath Prabu S Subject: [PATCH v3 1/6] mpt3sas: Introduce mpt3sas_base_pci_device_is_available Date: Mon, 24 Sep 2018 12:05:11 +0530 Message-Id: <1537770916-16337-2-git-send-email-suganath-prabu.subramani@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537770916-16337-1-git-send-email-suganath-prabu.subramani@broadcom.com> References: <1537770916-16337-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 * Driver uses "pci_device_is_present" to check whether If Hot unplugged: the outstanding IOs with 'DID_NO_CONNECT' before removing the drives attached to the HBA. "DID_NO_CONNECT" status and free the smid, if driver detects that HBA is hot unplugged. * In the hard reset flush out all the outstanding IOs even if diag reset fails and also if driver detects that HBA is hot unplugged. v1 change set: ============== unlock mutex before goto "out_unlocked", if active reset is in progress. v2 change set: ============== 1) Use pci_device_is_present instead of mpt3sas_base_pci_device_is_unplugged. 2) As suggested by Lukas, removed using watchdog thread for checking hba hot unplug(Patch 02 of V1). Added Hot unplug checks in scan finish and reset paths. v3 Change Set: ============= Simplified function "mpt3sas_base_pci_device_is_available" and made inline. Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_base.c | 41 +++++++++++++++++++++++++++++ drivers/scsi/mpt3sas/mpt3sas_base.h | 3 ++- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 50 ++++++++++++++++++++++++++++++++---- 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 59d7844..c98d8e2 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -543,6 +543,20 @@ static int mpt3sas_remove_dead_ioc_func(void *arg) } /** + * mpt3sas_base_pci_device_is_available - check whether pci device is + * available for any transactions with FW + * + * @ioc: per adapter object + * + * Return 1 if pci device state is up and running else return 0. + */ +inline bool +mpt3sas_base_pci_device_is_available(struct MPT3SAS_ADAPTER *ioc) +{ + return !ioc->pci_error_recovery && pci_device_is_present(ioc->pdev); +} + +/** * _base_fault_reset_work - workq handling ioc fault conditions * @work: input argument, used to derive ioc * @@ -6122,6 +6136,11 @@ _base_diag_reset(struct MPT3SAS_ADAPTER *ioc) count = 0; do { + if (!pci_device_is_present(ioc->pdev)) { + ioc->remove_host = 1; + pr_err(MPT3SAS_FMT "Hba Hot unplugged\n", ioc->name); + goto out; + } /* Write magic sequence to WriteSequence register * Loop until in diagnostic mode */ @@ -6853,6 +6872,14 @@ mpt3sas_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc) ioc->pending_io_count = 0; + if (!mpt3sas_base_pci_device_is_available(ioc)) { + pr_err(MPT3SAS_FMT + "%s: pci error recovery reset or" + " pci device unplug occurred\n", + ioc->name, __func__); + return; + } + ioc_state = mpt3sas_base_get_iocstate(ioc, 0); if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) return; @@ -6899,6 +6926,20 @@ mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER *ioc, /* wait for an active reset in progress to complete */ mutex_lock(&ioc->reset_in_progress_mutex); + if (!mpt3sas_base_pci_device_is_available(ioc)) { + pr_err(MPT3SAS_FMT + "%s: pci error recovery reset or" + " pci device unplug occurred\n", + ioc->name, __func__); + if (!pci_device_is_present(ioc->pdev)) + ioc->schedule_dead_ioc_flush_running_cmds(ioc); + r = 0; + mutex_unlock(&ioc->reset_in_progress_mutex); + goto out_unlocked; + } + + mpt3sas_halt_firmware(ioc); + spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); ioc->shost_recovery = 1; spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h index 96dc15e..a802ad4 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.h +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h @@ -1474,7 +1474,8 @@ void mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER *ioc, u16 device_missing_delay, u8 io_missing_delay); int mpt3sas_port_enable(struct MPT3SAS_ADAPTER *ioc); - +inline bool mpt3sas_base_pci_device_is_available( + struct MPT3SAS_ADAPTER *ioc); void mpt3sas_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc); diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 53133cf..566a550 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -2846,9 +2846,19 @@ scsih_abort(struct scsi_cmnd *scmd) "attempting task abort! scmd(%p)\n", scmd); _scsih_tm_display_info(ioc, scmd); + if (!pci_device_is_present(ioc->pdev) || ioc->remove_host) { + sdev_printk(KERN_INFO, scmd->device, "%s scmd(%p)\n", + ((ioc->remove_host) ? ("shost is getting removed!") : + ("pci device been removed!")), scmd); + if (st && st->smid) + mpt3sas_base_free_smid(ioc, st->smid); + scmd->result = DID_NO_CONNECT << 16; + r = FAST_IO_FAIL; + goto out; + } + sas_device_priv_data = scmd->device->hostdata; - if (!sas_device_priv_data || !sas_device_priv_data->sas_target || - ioc->remove_host) { + if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { sdev_printk(KERN_INFO, scmd->device, "device been deleted! scmd(%p)\n", scmd); scmd->result = DID_NO_CONNECT << 16; @@ -2918,6 +2928,15 @@ scsih_dev_reset(struct scsi_cmnd *scmd) "attempting device reset! scmd(%p)\n", scmd); _scsih_tm_display_info(ioc, scmd); + if (!pci_device_is_present(ioc->pdev) || ioc->remove_host) { + sdev_printk(KERN_INFO, scmd->device, "%s scmd(%p)\n", + ((ioc->remove_host) ? ("shost is getting removed!") : + ("pci device been removed!")), scmd); + scmd->result = DID_NO_CONNECT << 16; + r = FAST_IO_FAIL; + goto out; + } + sas_device_priv_data = scmd->device->hostdata; if (!sas_device_priv_data || !sas_device_priv_data->sas_target || ioc->remove_host) { @@ -2995,9 +3014,17 @@ scsih_target_reset(struct scsi_cmnd *scmd) scmd); _scsih_tm_display_info(ioc, scmd); + if ((!pci_device_is_present(ioc->pdev)) || ioc->remove_host) { + sdev_printk(KERN_INFO, scmd->device, "%s scmd(%p)\n", + ((ioc->remove_host) ? ("shost is getting removed!") : + ("pci device been removed!")), scmd); + scmd->result = DID_NO_CONNECT << 16; + r = FAST_IO_FAIL; + goto out; + } + sas_device_priv_data = scmd->device->hostdata; - if (!sas_device_priv_data || !sas_device_priv_data->sas_target || - ioc->remove_host) { + if (!sas_device_priv_data || !sas_device_priv_data->sas_target) { starget_printk(KERN_INFO, starget, "target been deleted! scmd(%p)\n", scmd); scmd->result = DID_NO_CONNECT << 16; @@ -4474,7 +4501,9 @@ _scsih_flush_running_cmds(struct MPT3SAS_ADAPTER *ioc) st = scsi_cmd_priv(scmd); mpt3sas_base_clear_st(ioc, st); scsi_dma_unmap(scmd); - if (ioc->pci_error_recovery || ioc->remove_host) + + if ((!mpt3sas_base_pci_device_is_available(ioc)) + || ioc->remove_host) scmd->result = DID_NO_CONNECT << 16; else scmd->result = DID_RESET << 16; @@ -9726,6 +9755,9 @@ _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) if (list_empty(&ioc->raid_device_list)) return; + if (!pci_device_is_present(ioc->pdev)) + return; + mutex_lock(&ioc->scsih_cmds.mutex); if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) { @@ -10247,6 +10279,14 @@ scsih_scan_finished(struct Scsi_Host *shost, unsigned long time) { struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + if (!pci_device_is_present(ioc->pdev)) { + complete(&ioc->port_enable_cmds.done); + ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; + ioc->is_driver_loading = 0; + ioc->remove_host = 1; + return 1; + } + if (disable_discovery > 0) { ioc->is_driver_loading = 0; ioc->wait_for_discovery_to_complete = 0;