From patchwork Fri Aug 31 04:34:35 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: 10583105 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 32C7B14BD for ; Fri, 31 Aug 2018 04:35:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 223D72C18F for ; Fri, 31 Aug 2018 04:35:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1447B2C1C2; Fri, 31 Aug 2018 04:35:12 +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 6D5E32C18F for ; Fri, 31 Aug 2018 04:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727123AbeHaIko (ORCPT ); Fri, 31 Aug 2018 04:40:44 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:52319 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbeHaIko (ORCPT ); Fri, 31 Aug 2018 04:40:44 -0400 Received: by mail-wm0-f67.google.com with SMTP id y139-v6so3853058wmc.2 for ; Thu, 30 Aug 2018 21:35:08 -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=QHcgQME80DsHtaKy6NqIGHu7+kRUNklmJKt/I/gHnhk=; b=hNvzp5gOPOCMeqMmYYHuBeSIXceqxQ3uGn+p4u3T9hO9afDB7L/MSdOV/mxBBgadXO vMw+JSr0DYdCxlIow1KynJtXG/MdFZFeiLbPW9qt1N/ILcPRzxnLyZyZ8aZDcSqihiQP AHq5aL6gVoPMMl/ofbjG4ZYTxq+e6GVevdzS4= 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=QHcgQME80DsHtaKy6NqIGHu7+kRUNklmJKt/I/gHnhk=; b=DBihOJsCzTfBgur/ncEve609+ZcDlMf4c+pLyKe5xWRXoqfJ/Dau9norDtPnQAV08o Ths6biOFERtwZQp7s44GjVDQDRIRwPOyD6PTbdKzEGc7zIr1MRHNRNj/se2LAWir0LZP SPA994g9xN2+C9Zif1/kE7v3D9/j6DvhwggtfO9HLlAiwmIGUY3JCoZmlfeBfgQdz39R 4jbaYU3GeWVa3r/NalxL35l74XwtLKVWZC5M6GnjuTvL0kaO8yyjS9CY5ceyuMF5BWNo p74McJcVOWxWvXyhIMXtWjziDGaCUSqJg5uyZs1OEbweustjpXEwcRIHQScrBINB3uuu mIqA== X-Gm-Message-State: APzg51AS5wEATt2uu3uuspKgJ9V9JlEBRtiIHrJGlnHoPOumFbas95Ay 2lVYvL9fUN9+ZrzALwtNj/QQp5LXhm4= X-Google-Smtp-Source: ANB0VdZRyJ3gFBU6furoTpq68+5k0o6TtiX6H7FF27CPC/XOLlJcexQg2qXTCDjmiT5iasQPZ4PQ3w== X-Received: by 2002:a1c:82c8:: with SMTP id e191-v6mr3332787wmd.35.1535690107084; Thu, 30 Aug 2018 21:35:07 -0700 (PDT) Received: from localhost.localdomain.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id h15-v6sm2261735wmb.21.2018.08.30.21.35.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 21:35:06 -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 v1 1/7] mpt3sas: Introduce mpt3sas_base_pci_device_is_unplugged Date: Fri, 31 Aug 2018 00:34:35 -0400 Message-Id: <1535690081-16116-2-git-send-email-suganath-prabu.subramani@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1535690081-16116-1-git-send-email-suganath-prabu.subramani@broadcom.com> References: <1535690081-16116-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 does a PCIe read to check whether HBA is hot unplugged or not. If the returned vendor ID is 0xFFFFFFFF/0x0, then this indicates that the device might have been hot removed and the device will be removed from driver. * In the PCI device remove() callback function, flush out all the outstanding IOs with 'DID_NO_CONNECT' before removing the drives attached to the HBA. * In the TM abort() callback function return the scmd with "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. Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_base.c | 62 +++++++++++++++++++++++++++++++++++- drivers/scsi/mpt3sas/mpt3sas_base.h | 3 +- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 42 +++++++++++++++++++++--- 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 836b2e1..8b33670 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -61,7 +61,7 @@ #include #include /* To get host page size per arch */ #include - +#include <../drivers/pci/pci.h> #include "mpt3sas_base.h" @@ -543,6 +543,44 @@ static int mpt3sas_remove_dead_ioc_func(void *arg) } /** + * mpt3sas_base_pci_device_is_unplugged - Check whether HBA device is + * hot unplugged or not + * @ioc: per adapter object + * + * Return 1 if the HBA device is hot unplugged else return 0. + */ +u8 +mpt3sas_base_pci_device_is_unplugged(struct MPT3SAS_ADAPTER *ioc) +{ + struct pci_dev *pdev = ioc->pdev; + int devfn = pdev->devfn; + u32 l; + + if (pci_bus_read_dev_vendor_id(pdev->bus, devfn, &l, 0)) + return 0; + + return 1; +} + +/** + * 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. + */ +u8 +mpt3sas_base_pci_device_is_available(struct MPT3SAS_ADAPTER *ioc) +{ + if (ioc->pci_error_recovery || + mpt3sas_base_pci_device_is_unplugged(ioc)) + return 0; + + return 1; +} + +/** * _base_fault_reset_work - workq handling ioc fault conditions * @work: input argument, used to derive ioc * @@ -6853,6 +6891,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 +6945,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 (mpt3sas_base_pci_device_is_unplugged(ioc)) + 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..8ee3ba7 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); - +u8 mpt3sas_base_pci_device_is_unplugged(struct MPT3SAS_ADAPTER *ioc); +u8 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 8dd3d67..eeee9da 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 (mpt3sas_base_pci_device_is_unplugged(ioc) || 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 (mpt3sas_base_pci_device_is_unplugged(ioc) || 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 (mpt3sas_base_pci_device_is_unplugged(ioc) || 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 (mpt3sas_base_pci_device_is_unplugged(ioc)) + return; + mutex_lock(&ioc->scsih_cmds.mutex); if (ioc->scsih_cmds.status != MPT3_CMD_NOT_USED) {