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) { From patchwork Fri Aug 31 04:34:36 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: 10583107 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 75436920 for ; Fri, 31 Aug 2018 04:35:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6564A2C18F for ; Fri, 31 Aug 2018 04:35:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 597DE2C1D8; Fri, 31 Aug 2018 04:35:14 +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 78F6C2C18F for ; Fri, 31 Aug 2018 04:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727207AbeHaIkq (ORCPT ); Fri, 31 Aug 2018 04:40:46 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:51156 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbeHaIkq (ORCPT ); Fri, 31 Aug 2018 04:40:46 -0400 Received: by mail-wm0-f66.google.com with SMTP id s12-v6so3884588wmc.0 for ; Thu, 30 Aug 2018 21:35:11 -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=d+ciiSHeZp3R3Bt8isCsC2o69svRUrpIgsGj3GYAPgY=; b=O6MNkW3eq4xAmC4r/oCvWCa9SRrj5TGA8CeqAtnJxFbzYAxT8KOvFAHoIXYodPBbV2 Z7XuanMD0HFEBGV3gnR7cIVQNL5Fxdmr+shgFIQs60+b5QSlz2aEOOznJlfv3VQFzf9f P8IhFLDuQdSHDPT9gQHVgM64hzmybqiSBSXBU= 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=d+ciiSHeZp3R3Bt8isCsC2o69svRUrpIgsGj3GYAPgY=; b=WP+FEUfuk4Ut1gdog6REJzL1AvPIGggCthcomNH9tpS92LRBGS25niKNLq2Cd/iLSC 9zWVKK90mow3FvlWtDhKLe3Y5a9Rx/YkJoqQtwhiooynEHV2h/gghXUzqFdpTGyz3vRG wT88PRG3qIMRyNRtWJ+stRB2PLjbGQeCkcEI3mF/MaFYGLLAJA2TkHSnrsqhKOO07ZYv 01/ByES5zj0mLKmA1shYplp6R7PhFm09KwYcDrAjSAsbF7/QyCgZuRrTBYw+KyVcZF6m wCKhWUeP8WtrJQInUmkGFPa2H8gxd2xmV1JJ1VB9epEG6mz/jYRH5r9MSkK+cbxasoMB BQ3g== X-Gm-Message-State: APzg51DKT7mThEt/99a1VPry6JcdD4YOdH9yO2TmZlDVeLJPgXiNTWEK T4x9PIrJrjH2voFdfqHyE1Eu910F4pA= X-Google-Smtp-Source: ANB0VdYxQ/RWadfLNVCn7ZT6Bp+ofci0me5gwoUiWJxPqQqO8wkd4TiQExjosr6PEk1ZiTTXDyomPw== X-Received: by 2002:a1c:2787:: with SMTP id n129-v6mr3461281wmn.101.1535690110068; Thu, 30 Aug 2018 21:35:10 -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.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 21:35:09 -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 2/7] mpt3sas: Add HBA hot plug watchdog thread. Date: Fri, 31 Aug 2018 00:34:36 -0400 Message-Id: <1535690081-16116-3-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 During driver load create a hba hot unplug watchdog thread "_base_hba_hot_unplug_work". This will poll whether HBA device is unplugged or not by reading IOC's vendor field in IOC's PCI configuration space for every one second. If hot unplug is detected, it terminates all the outstanding IOs and hence kernels's PCIe hotplug module (i.e. pciehp) will clear the instances of the hot unplugged PCI device. Below functions starts and stops the watchdog. mpt3sas_base_start_hba_unplug_watchdog mpt3sas_base_stop_hba_unplug_watchdog Watchdog thread starts immediately once IOC becomes operational. Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_base.c | 92 +++++++++++++++++++++++++++++++++++- drivers/scsi/mpt3sas/mpt3sas_base.h | 6 +++ drivers/scsi/mpt3sas/mpt3sas_scsih.c | 7 +++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 8b33670..6c8a30f 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -69,6 +69,7 @@ static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS]; #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */ +#define HBA_HOTUNPLUG_POLLING_INTERVAL 1000 /* in milliseconds */ /* maximum controller queue depth */ #define MAX_HBA_QUEUE_DEPTH 30000 @@ -672,6 +673,46 @@ _base_fault_reset_work(struct work_struct *work) spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); } +static void +_base_hba_hot_unplug_work(struct work_struct *work) +{ + struct MPT3SAS_ADAPTER *ioc = + container_of(work, struct MPT3SAS_ADAPTER, + hba_hot_unplug_work.work); + unsigned long flags; + + spin_lock_irqsave(&ioc->hba_hot_unplug_lock, flags); + if (ioc->shost_recovery || ioc->pci_error_recovery) + goto rearm_timer; + + if (mpt3sas_base_pci_device_is_unplugged(ioc)) { + if (ioc->remove_host) { + pr_err(MPT3SAS_FMT + "The IOC seems hot unplugged and the driver is " + "waiting for pciehp module to remove the PCIe " + "device instance associated with IOC!!!\n", + ioc->name); + goto rearm_timer; + } + + /* Set remove_host flag here, since kernel will invoke driver's + * .remove() callback function one after the other for all hot + * un-plugged devices, so it may take some time to call + * .remove() function for subsequent hot un-plugged + * PCI devices. + */ + ioc->remove_host = 1; + } + +rearm_timer: + if (ioc->hba_hot_unplug_work_q) + queue_delayed_work(ioc->hba_hot_unplug_work_q, + &ioc->hba_hot_unplug_work, + msecs_to_jiffies(HBA_HOTUNPLUG_POLLING_INTERVAL)); + spin_unlock_irqrestore(&ioc->hba_hot_unplug_lock, flags); +} + + /** * mpt3sas_base_start_watchdog - start the fault_reset_work_q * @ioc: per adapter object @@ -730,6 +771,54 @@ mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER *ioc) } } +void +mpt3sas_base_start_hba_unplug_watchdog(struct MPT3SAS_ADAPTER *ioc) +{ + unsigned long flags; + + if (ioc->hba_hot_unplug_work_q) + return; + + /* Initialize hba hot unplug polling */ + INIT_DELAYED_WORK(&ioc->hba_hot_unplug_work, + _base_hba_hot_unplug_work); + snprintf(ioc->hba_hot_unplug_work_q_name, + sizeof(ioc->hba_hot_unplug_work_q_name), "poll_%s%d_hba_unplug", + ioc->driver_name, ioc->id); + ioc->hba_hot_unplug_work_q = + create_singlethread_workqueue(ioc->hba_hot_unplug_work_q_name); + if (!ioc->hba_hot_unplug_work_q) { + pr_err(MPT3SAS_FMT "%s: failed (line=%d)\n", + ioc->name, __func__, __LINE__); + return; + } + + spin_lock_irqsave(&ioc->hba_hot_unplug_lock, flags); + if (ioc->hba_hot_unplug_work_q) + queue_delayed_work(ioc->hba_hot_unplug_work_q, + &ioc->hba_hot_unplug_work, + msecs_to_jiffies(HBA_HOTUNPLUG_POLLING_INTERVAL)); + spin_unlock_irqrestore(&ioc->hba_hot_unplug_lock, flags); +} + +void +mpt3sas_base_stop_hba_unplug_watchdog(struct MPT3SAS_ADAPTER *ioc) +{ + unsigned long flags; + struct workqueue_struct *wq; + + spin_lock_irqsave(&ioc->hba_hot_unplug_lock, flags); + wq = ioc->hba_hot_unplug_work_q; + ioc->hba_hot_unplug_work_q = NULL; + spin_unlock_irqrestore(&ioc->hba_hot_unplug_lock, flags); + + if (wq) { + if (!cancel_delayed_work_sync(&ioc->hba_hot_unplug_work)) + flush_workqueue(wq); + destroy_workqueue(wq); + } +} + /** * mpt3sas_base_fault_info - verbose translation of firmware FAULT code * @ioc: per adapter object @@ -6458,7 +6547,7 @@ _base_make_ioc_operational(struct MPT3SAS_ADAPTER *ioc) } skip_init_reply_post_host_index: - + mpt3sas_base_start_hba_unplug_watchdog(ioc); _base_unmask_interrupts(ioc); if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { @@ -6789,6 +6878,7 @@ mpt3sas_base_detach(struct MPT3SAS_ADAPTER *ioc) __func__)); mpt3sas_base_stop_watchdog(ioc); + mpt3sas_base_stop_hba_unplug_watchdog(ioc); mpt3sas_base_free_resources(ioc); _base_release_memory_pools(ioc); mpt3sas_free_enclosure_list(ioc); diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h index 8ee3ba7..4186bc9 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.h +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h @@ -1140,8 +1140,11 @@ struct MPT3SAS_ADAPTER { /* fw fault handler */ char fault_reset_work_q_name[20]; + char hba_hot_unplug_work_q_name[20]; struct workqueue_struct *fault_reset_work_q; + struct workqueue_struct *hba_hot_unplug_work_q; struct delayed_work fault_reset_work; + struct delayed_work hba_hot_unplug_work; /* fw event handler */ char firmware_event_name[20]; @@ -1158,6 +1161,7 @@ struct MPT3SAS_ADAPTER { struct mutex reset_in_progress_mutex; spinlock_t ioc_reset_in_progress_lock; + spinlock_t hba_hot_unplug_lock; u8 ioc_link_reset_in_progress; u8 ignore_loginfos; @@ -1482,6 +1486,8 @@ mpt3sas_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc); u8 mpt3sas_base_check_cmd_timeout(struct MPT3SAS_ADAPTER *ioc, u8 status, void *mpi_request, int sz); +void mpt3sas_base_start_hba_unplug_watchdog(struct MPT3SAS_ADAPTER *ioc); +void mpt3sas_base_stop_hba_unplug_watchdog(struct MPT3SAS_ADAPTER *ioc); /* scsih shared API */ struct scsi_cmnd *mpt3sas_scsih_scsi_lookup_get(struct MPT3SAS_ADAPTER *ioc, u16 smid); diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index eeee9da..7e0c4ec 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -9828,9 +9828,11 @@ static void scsih_remove(struct pci_dev *pdev) ioc->remove_host = 1; mpt3sas_wait_for_commands_to_complete(ioc); + spin_lock_irqsave(&ioc->hba_hot_unplug_lock, flags); _scsih_flush_running_cmds(ioc); _scsih_fw_event_cleanup_queue(ioc); + spin_unlock_irqrestore(&ioc->hba_hot_unplug_lock, flags); spin_lock_irqsave(&ioc->fw_event_lock, flags); wq = ioc->firmware_event_thread; @@ -10724,6 +10726,7 @@ scsih_suspend(struct pci_dev *pdev, pm_message_t state) pci_power_t device_state; mpt3sas_base_stop_watchdog(ioc); + mpt3sas_base_stop_hba_unplug_watchdog(ioc); flush_scheduled_work(); scsi_block_requests(shost); device_state = pci_choose_state(pdev, state); @@ -10766,6 +10769,7 @@ scsih_resume(struct pci_dev *pdev) mpt3sas_base_hard_reset_handler(ioc, SOFT_RESET); scsi_unblock_requests(shost); mpt3sas_base_start_watchdog(ioc); + mpt3sas_base_start_hba_unplug_watchdog(ioc); return 0; } #endif /* CONFIG_PM */ @@ -10796,12 +10800,14 @@ scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) ioc->pci_error_recovery = 1; scsi_block_requests(ioc->shost); mpt3sas_base_stop_watchdog(ioc); + mpt3sas_base_stop_hba_unplug_watchdog(ioc); mpt3sas_base_free_resources(ioc); return PCI_ERS_RESULT_NEED_RESET; case pci_channel_io_perm_failure: /* Permanent error, prepare for device removal */ ioc->pci_error_recovery = 1; mpt3sas_base_stop_watchdog(ioc); + mpt3sas_base_stop_hba_unplug_watchdog(ioc); _scsih_flush_running_cmds(ioc); return PCI_ERS_RESULT_DISCONNECT; } @@ -10862,6 +10868,7 @@ scsih_pci_resume(struct pci_dev *pdev) pci_cleanup_aer_uncorrect_error_status(pdev); mpt3sas_base_start_watchdog(ioc); + mpt3sas_base_start_hba_unplug_watchdog(ioc); scsi_unblock_requests(ioc->shost); } From patchwork Fri Aug 31 04:34:37 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: 10583109 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 71A4A14BD for ; Fri, 31 Aug 2018 04:35:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FF762C18F for ; Fri, 31 Aug 2018 04:35:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 544942C1D8; Fri, 31 Aug 2018 04:35:17 +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 6F8F32C18F for ; Fri, 31 Aug 2018 04:35:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727227AbeHaIku (ORCPT ); Fri, 31 Aug 2018 04:40:50 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:51394 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbeHaIkt (ORCPT ); Fri, 31 Aug 2018 04:40:49 -0400 Received: by mail-wm0-f68.google.com with SMTP id y2-v6so3887540wma.1 for ; Thu, 30 Aug 2018 21:35:14 -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=VY2FM0phfEFnWfLSEetlkYCiIxnfu3jvnXehk2xcxkk=; b=JqqC9J3WzYY2Mj5o/1ybbvqFQv15nSafQfF3g3gzDx20HjsSchsgeHh0c0OHsAiGpr e1WgreE7rICgdp3RVYtseVWPNJcWC4hYfHY4mddwrUpJw98mnUsp1OpX8GecBGusMozb 583cFV2b0JX6YcWEYyOoOxxbkqNgzloZI1nV4= 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=VY2FM0phfEFnWfLSEetlkYCiIxnfu3jvnXehk2xcxkk=; b=X4VacKK5jAUuaYhlfArX/tgcm1Tn00UNnjvBwYxsg/17TikFWJ/zVJ4X+xg0K3uiEz lt75IoQYhQbSaCMalemMmJQ4u2kzHLuztGpjnndQPsjMWIKAJ1xLNQhALmXGwqWbGokx UyTHNzpuyFXRI1cEOzzpTJvSHFBjyrbEgBpP3GfwUZYxfm9oY9nuu8qc8mxFDDrD6D5j JUspA7QXYuMB5ta09SURveHVNoxGsJG3QN5RUyV3Y0oyPRvcfNofmIqNauQ2CyVSkGiZ PrWr421XN1bx63zbkmxeTnlicYqf77FyfVJIxcOZK8+m1buh11n14tV/+5sb8pSqsVZ+ u2YQ== X-Gm-Message-State: APzg51B0pXFEj8IQRdxQwBUk2xDU4WG6cr+/ZL6r4QyvPcYa2qbpLySx yl1E+BI00sNG5O5yYNIvTiw6LzN7Itk= X-Google-Smtp-Source: ANB0Vda3Wb7HM5fPsxoZ2pxh7YrY5h0Ync6QQfJyyyBIpSNWhNG3oUMYlozBCAlWmKRwJTIHr0oGcA== X-Received: by 2002:a1c:ee15:: with SMTP id m21-v6mr3638934wmh.112.1535690113359; Thu, 30 Aug 2018 21:35:13 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 21:35:12 -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 3/7] mpt3sas: Seperate out mpt3sas_wait_for_ioc_to_operational Date: Fri, 31 Aug 2018 00:34:37 -0400 Message-Id: <1535690081-16116-4-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 Introduce mpt3sas_wait_for_ioc_to_operational. This section of code "wait for IOC to be operational" is used in many places across the driver, and hence moved this section of code in to the function "mpt3sas_wait_for_ioc_to_operational". Also added HBA hot unplug checks, and this returns with error code EFAULT, if it detects HBA is hot unplugged or IOC is not in operational state. Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_base.c | 92 +++++++++++++++++++------------- drivers/scsi/mpt3sas/mpt3sas_base.h | 4 ++ drivers/scsi/mpt3sas/mpt3sas_config.c | 28 +++------- drivers/scsi/mpt3sas/mpt3sas_ctl.c | 26 ++------- drivers/scsi/mpt3sas/mpt3sas_transport.c | 75 +++++--------------------- 5 files changed, 81 insertions(+), 144 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index 6c8a30f..a46ded8 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -5289,6 +5289,53 @@ _base_send_ioc_reset(struct MPT3SAS_ADAPTER *ioc, u8 reset_type, int timeout) } /** + * mpt3sas_wait_for_ioc_to_operational - IOC's operational + * state and HBA hot unplug status are checked here. + * @ioc: per adapter object + * @wait_count: timeout in seconds + * + * Return: Returns EFAULT, if HBA is hot unplugged or IOC is + * not in operational state, within the wait_count. + * And returns 0, If not hot unplugged Or ioc is in + * operational state. + */ + +int +mpt3sas_wait_for_ioc_to_operational(struct MPT3SAS_ADAPTER *ioc, + int wait_count) +{ + int wait_state_count = 0; + u32 ioc_state; + + if (mpt3sas_base_pci_device_is_unplugged(ioc)) + return -EFAULT; + + ioc_state = mpt3sas_base_get_iocstate(ioc, 1); + while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { + + if (mpt3sas_base_pci_device_is_unplugged(ioc)) + return -EFAULT; + + if (wait_state_count++ == wait_count) { + pr_err(MPT3SAS_FMT + "%s: failed due to ioc not operational\n", + ioc->name, __func__); + return -EFAULT; + } + ssleep(1); + ioc_state = mpt3sas_base_get_iocstate(ioc, 1); + pr_info(MPT3SAS_FMT "%s: waiting for " + "operational state(count=%d)\n", ioc->name, + __func__, wait_state_count); + } + if (wait_state_count) + pr_info(MPT3SAS_FMT "%s: ioc is operational\n", + ioc->name, __func__); + + return 0; +} + +/** * _base_handshake_req_reply_wait - send request thru doorbell interface * @ioc: per adapter object * @request_bytes: request length @@ -5429,11 +5476,9 @@ mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER *ioc, Mpi2SasIoUnitControlRequest_t *mpi_request) { u16 smid; - u32 ioc_state; u8 issue_reset = 0; int rc; void *request; - u16 wait_state_count; dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, __func__)); @@ -5447,22 +5492,10 @@ mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER *ioc, goto out; } - wait_state_count = 0; - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { - if (wait_state_count++ == 10) { - pr_err(MPT3SAS_FMT - "%s: failed due to ioc not operational\n", - ioc->name, __func__); - rc = -EFAULT; - goto out; - } - ssleep(1); - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - pr_info(MPT3SAS_FMT - "%s: waiting for operational state(count=%d)\n", - ioc->name, __func__, wait_state_count); - } + rc = mpt3sas_wait_for_ioc_to_operational(ioc, + IOC_OPERATIONAL_WAIT_COUNT); + if (rc) + goto out; smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); if (!smid) { @@ -5529,11 +5562,9 @@ mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER *ioc, Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request) { u16 smid; - u32 ioc_state; u8 issue_reset = 0; int rc; void *request; - u16 wait_state_count; dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, __func__)); @@ -5547,23 +5578,10 @@ mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER *ioc, goto out; } - wait_state_count = 0; - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { - if (wait_state_count++ == 10) { - pr_err(MPT3SAS_FMT - "%s: failed due to ioc not operational\n", - ioc->name, __func__); - rc = -EFAULT; - goto out; - } - ssleep(1); - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - pr_info(MPT3SAS_FMT - "%s: waiting for operational state(count=%d)\n", - ioc->name, - __func__, wait_state_count); - } + rc = mpt3sas_wait_for_ioc_to_operational(ioc, + IOC_OPERATIONAL_WAIT_COUNT); + if (rc) + goto out; smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); if (!smid) { diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h index 4186bc9..8b2cc66 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.h +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h @@ -139,6 +139,8 @@ #define DEFAULT_NUM_FWCHAIN_ELEMTS 8 #define FW_IMG_HDR_READ_TIMEOUT 15 + +#define IOC_OPERATIONAL_WAIT_COUNT 10 /* * NVMe defines */ @@ -1486,6 +1488,8 @@ mpt3sas_wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc); u8 mpt3sas_base_check_cmd_timeout(struct MPT3SAS_ADAPTER *ioc, u8 status, void *mpi_request, int sz); +int mpt3sas_wait_for_ioc_to_operational(struct MPT3SAS_ADAPTER *ioc, + int wait_count); void mpt3sas_base_start_hba_unplug_watchdog(struct MPT3SAS_ADAPTER *ioc); void mpt3sas_base_stop_hba_unplug_watchdog(struct MPT3SAS_ADAPTER *ioc); /* scsih shared API */ diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c index d29a2dc..5713a2d 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_config.c +++ b/drivers/scsi/mpt3sas/mpt3sas_config.c @@ -303,11 +303,10 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t void *config_page, u16 config_page_sz) { u16 smid; - u32 ioc_state; Mpi2ConfigRequest_t *config_request; int r; u8 retry_count, issue_host_reset = 0; - u16 wait_state_count; + struct config_request mem; u32 ioc_status = UINT_MAX; @@ -365,26 +364,11 @@ _config_request(struct MPT3SAS_ADAPTER *ioc, Mpi2ConfigRequest_t pr_info(MPT3SAS_FMT "%s: attempting retry (%d)\n", ioc->name, __func__, retry_count); } - wait_state_count = 0; - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { - if (wait_state_count++ == MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT) { - pr_err(MPT3SAS_FMT - "%s: failed due to ioc not operational\n", - ioc->name, __func__); - ioc->config_cmds.status = MPT3_CMD_NOT_USED; - r = -EFAULT; - goto free_mem; - } - ssleep(1); - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - pr_info(MPT3SAS_FMT - "%s: waiting for operational state(count=%d)\n", - ioc->name, __func__, wait_state_count); - } - if (wait_state_count) - pr_info(MPT3SAS_FMT "%s: ioc is operational\n", - ioc->name, __func__); + + r = mpt3sas_wait_for_ioc_to_operational(ioc, + MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT); + if (r) + goto free_mem; smid = mpt3sas_base_get_smid(ioc, ioc->config_cb_idx); if (!smid) { diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c index 5e8c059..a46039c 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c @@ -652,7 +652,6 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg, MPI2DefaultReply_t *mpi_reply; Mpi26NVMeEncapsulatedRequest_t *nvme_encap_request = NULL; struct _pcie_device *pcie_device = NULL; - u32 ioc_state; u16 smid; u8 timeout; u8 issue_reset; @@ -665,7 +664,6 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg, dma_addr_t data_in_dma = 0; size_t data_in_sz = 0; long ret; - u16 wait_state_count; u16 device_handle = MPT3SAS_INVALID_DEVICE_HANDLE; u8 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; @@ -678,26 +676,10 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg, goto out; } - wait_state_count = 0; - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { - if (wait_state_count++ == 10) { - pr_err(MPT3SAS_FMT - "%s: failed due to ioc not operational\n", - ioc->name, __func__); - ret = -EFAULT; - goto out; - } - ssleep(1); - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - pr_info(MPT3SAS_FMT - "%s: waiting for operational state(count=%d)\n", - ioc->name, - __func__, wait_state_count); - } - if (wait_state_count) - pr_info(MPT3SAS_FMT "%s: ioc is operational\n", - ioc->name, __func__); + ret = mpt3sas_wait_for_ioc_to_operational(ioc, + IOC_OPERATIONAL_WAIT_COUNT); + if (ret) + goto out; mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL); if (!mpi_request) { diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c index f8cc267..b10d73e 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_transport.c +++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c @@ -299,7 +299,6 @@ _transport_expander_report_manufacture(struct MPT3SAS_ADAPTER *ioc, struct rep_manu_request *manufacture_request; int rc; u16 smid; - u32 ioc_state; void *psge; u8 issue_reset = 0; void *data_out = NULL; @@ -307,7 +306,6 @@ _transport_expander_report_manufacture(struct MPT3SAS_ADAPTER *ioc, dma_addr_t data_in_dma; size_t data_in_sz; size_t data_out_sz; - u16 wait_state_count; if (ioc->shost_recovery || ioc->pci_error_recovery) { pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", @@ -325,25 +323,10 @@ _transport_expander_report_manufacture(struct MPT3SAS_ADAPTER *ioc, } ioc->transport_cmds.status = MPT3_CMD_PENDING; - wait_state_count = 0; - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { - if (wait_state_count++ == 10) { - pr_err(MPT3SAS_FMT - "%s: failed due to ioc not operational\n", - ioc->name, __func__); - rc = -EFAULT; - goto out; - } - ssleep(1); - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - pr_info(MPT3SAS_FMT - "%s: waiting for operational state(count=%d)\n", - ioc->name, __func__, wait_state_count); - } - if (wait_state_count) - pr_info(MPT3SAS_FMT "%s: ioc is operational\n", - ioc->name, __func__); + rc = mpt3sas_wait_for_ioc_to_operational(ioc, + IOC_OPERATIONAL_WAIT_COUNT); + if (rc) + goto out; smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx); if (!smid) { @@ -1089,13 +1072,11 @@ _transport_get_expander_phy_error_log(struct MPT3SAS_ADAPTER *ioc, struct phy_error_log_reply *phy_error_log_reply; int rc; u16 smid; - u32 ioc_state; void *psge; u8 issue_reset = 0; void *data_out = NULL; dma_addr_t data_out_dma; u32 sz; - u16 wait_state_count; if (ioc->shost_recovery || ioc->pci_error_recovery) { pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", @@ -1113,25 +1094,10 @@ _transport_get_expander_phy_error_log(struct MPT3SAS_ADAPTER *ioc, } ioc->transport_cmds.status = MPT3_CMD_PENDING; - wait_state_count = 0; - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { - if (wait_state_count++ == 10) { - pr_err(MPT3SAS_FMT - "%s: failed due to ioc not operational\n", - ioc->name, __func__); - rc = -EFAULT; - goto out; - } - ssleep(1); - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - pr_info(MPT3SAS_FMT - "%s: waiting for operational state(count=%d)\n", - ioc->name, __func__, wait_state_count); - } - if (wait_state_count) - pr_info(MPT3SAS_FMT "%s: ioc is operational\n", - ioc->name, __func__); + rc = mpt3sas_wait_for_ioc_to_operational(ioc, + IOC_OPERATIONAL_WAIT_COUNT); + if (rc) + goto out; smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx); if (!smid) { @@ -1402,13 +1368,11 @@ _transport_expander_phy_control(struct MPT3SAS_ADAPTER *ioc, struct phy_control_reply *phy_control_reply; int rc; u16 smid; - u32 ioc_state; void *psge; u8 issue_reset = 0; void *data_out = NULL; dma_addr_t data_out_dma; u32 sz; - u16 wait_state_count; if (ioc->shost_recovery || ioc->pci_error_recovery) { pr_info(MPT3SAS_FMT "%s: host reset in progress!\n", @@ -1426,25 +1390,10 @@ _transport_expander_phy_control(struct MPT3SAS_ADAPTER *ioc, } ioc->transport_cmds.status = MPT3_CMD_PENDING; - wait_state_count = 0; - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { - if (wait_state_count++ == 10) { - pr_err(MPT3SAS_FMT - "%s: failed due to ioc not operational\n", - ioc->name, __func__); - rc = -EFAULT; - goto out; - } - ssleep(1); - ioc_state = mpt3sas_base_get_iocstate(ioc, 1); - pr_info(MPT3SAS_FMT - "%s: waiting for operational state(count=%d)\n", - ioc->name, __func__, wait_state_count); - } - if (wait_state_count) - pr_info(MPT3SAS_FMT "%s: ioc is operational\n", - ioc->name, __func__); + rc = mpt3sas_wait_for_ioc_to_operational(ioc, + IOC_OPERATIONAL_WAIT_COUNT); + if (rc) + goto out; smid = mpt3sas_base_get_smid(ioc, ioc->transport_cb_idx); if (!smid) { From patchwork Fri Aug 31 04:34:38 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: 10583111 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 ACB2314BD for ; Fri, 31 Aug 2018 04:35:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D0042C18F for ; Fri, 31 Aug 2018 04:35:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 914BB2C1D8; Fri, 31 Aug 2018 04:35:19 +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 0B0082C18F for ; Fri, 31 Aug 2018 04:35:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727230AbeHaIkw (ORCPT ); Fri, 31 Aug 2018 04:40:52 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40321 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbeHaIkw (ORCPT ); Fri, 31 Aug 2018 04:40:52 -0400 Received: by mail-wr1-f67.google.com with SMTP id n2-v6so9902693wrw.7 for ; Thu, 30 Aug 2018 21:35:17 -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=HI35y/L3200GR8R++CHCn/fbAmgZDygUDDKi3dtV03g=; b=SMrInaYDoV6k/8NvNGCG5+hI4i/xd287GZVDWiJAz/o8Y3TTyx16LRuPzTHJ3EggUM 7w4lqfMoE0hYypeHyfK66GXicisELtoDX+nwbPg8hLDD43rsT9ojjIptC+yVVP9/9Noe DL9r3kR2QbPnPAa3ziekae+SqnociVXvjYZgU= 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=HI35y/L3200GR8R++CHCn/fbAmgZDygUDDKi3dtV03g=; b=AZ2DHkmqNxgFO5A7ApcCBFCjPrL1Y/PMo/mukiDchliU2KZBfXlwEqyDSMTLsJkleb bqe29KgRSQgqCGWuPwcyiYV5lIPgPoUwwj+4R6tErnd8bAPoSmJ8uYk8cBq+9X7Vbtkk /XNCvy+aDyzM1wE8blhOPqD+Mg9BtQGCyBvSSezVo98Nb054pocAhPI5mXof7UlHvmO5 q4p2eWBsqWoVTZJ5p0dsUzd4J+zy4vX0Opm3EKZOkpREFkcBgBRb+pmbPtRWt7PtR/iM aGP6DVwl2qBM+3yX1oMe2m6eUuY9TOsgZoXTgcksyQ3rBQnIGTe7jldKJI6sWiDgYzcC Wgmw== X-Gm-Message-State: APzg51Ax73mVpYX2FYK8mo74EOBtudsNgKy0yFzLsKwul6jB8ta4HyXF 1FATsyRjM2QxZDgoO4RjngUKAIQbQIY= X-Google-Smtp-Source: ANB0VdbO3t0sB3+V/U9mEPktoKJDPKdNy7UQSHgPW7sc8StxzOOLFNIaOjaXnVhASFmHfOtoltcpXA== X-Received: by 2002:adf:b519:: with SMTP id a25-v6mr10060103wrd.273.1535690116309; Thu, 30 Aug 2018 21:35:16 -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.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 21:35:15 -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 4/7] mpt3sas: Introdude _scsih_get_shost_and_ioc. Date: Fri, 31 Aug 2018 00:34:38 -0400 Message-Id: <1535690081-16116-5-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 The code for getting shost and IOC is redundant so moved that to function "scsih_get_shost_and_ioc". Also checks for NULL are added to IOC and shost. Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 98 ++++++++++++++++++++++++++++++------ 1 file changed, 82 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 7e0c4ec..2c7f44c 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -9809,6 +9809,35 @@ _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) } /** + * _scsih_get_shost_and_ioc - get shost and ioc + * and verify whether they are NULL or not + * @pdev: PCI device struct + * @shost: address of scsi host pointer + * @ioc: address of HBA adapter pointer + * + * Return zero if *shost and *ioc are not NULL otherwise return error number. + */ +static int +_scsih_get_shost_and_ioc(struct pci_dev *pdev, + struct Scsi_Host **shost, struct MPT3SAS_ADAPTER **ioc) +{ + *shost = pci_get_drvdata(pdev); + if (*shost == NULL) { + dev_err(&pdev->dev, "pdev's driver data is null\n"); + return -ENXIO; + } + + *ioc = shost_priv(*shost); + if (*ioc == NULL) { + dev_err(&pdev->dev, "shost's private data is null\n"); + return -ENXIO; + } + + return 0; +} + + +/** * scsih_remove - detach and remove add host * @pdev: PCI device struct * @@ -9816,8 +9845,8 @@ _scsih_ir_shutdown(struct MPT3SAS_ADAPTER *ioc) */ static void scsih_remove(struct pci_dev *pdev) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); - struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + struct Scsi_Host *shost = NULL; + struct MPT3SAS_ADAPTER *ioc = NULL; struct _sas_port *mpt3sas_port, *next_port; struct _raid_device *raid_device, *next; struct MPT3SAS_TARGET *sas_target_priv_data; @@ -9825,6 +9854,10 @@ static void scsih_remove(struct pci_dev *pdev) struct workqueue_struct *wq; unsigned long flags; + if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc)) { + dev_err(&pdev->dev, "unable to remove device\n"); + return; + } ioc->remove_host = 1; mpt3sas_wait_for_commands_to_complete(ioc); @@ -9900,11 +9933,16 @@ static void scsih_remove(struct pci_dev *pdev) static void scsih_shutdown(struct pci_dev *pdev) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); - struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + struct Scsi_Host *shost = NULL; + struct MPT3SAS_ADAPTER *ioc = NULL; struct workqueue_struct *wq; unsigned long flags; + if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc)) { + dev_err(&pdev->dev, "unable to shutdown device\n"); + return; + } + ioc->remove_host = 1; mpt3sas_wait_for_commands_to_complete(ioc); @@ -10721,10 +10759,16 @@ out_add_shost_fail: static int scsih_suspend(struct pci_dev *pdev, pm_message_t state) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); - struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + struct Scsi_Host *shost = NULL; + struct MPT3SAS_ADAPTER *ioc = NULL; pci_power_t device_state; + int rc; + rc = _scsih_get_shost_and_ioc(pdev, &shost, &ioc); + if (rc) { + dev_err(&pdev->dev, "unable to suspend device\n"); + return rc; + } mpt3sas_base_stop_watchdog(ioc); mpt3sas_base_stop_hba_unplug_watchdog(ioc); flush_scheduled_work(); @@ -10749,11 +10793,17 @@ scsih_suspend(struct pci_dev *pdev, pm_message_t state) static int scsih_resume(struct pci_dev *pdev) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); - struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + struct Scsi_Host *shost = NULL; + struct MPT3SAS_ADAPTER *ioc = NULL; pci_power_t device_state = pdev->current_state; int r; + r = _scsih_get_shost_and_ioc(pdev, &shost, &ioc); + if (r) { + dev_err(&pdev->dev, "unable to resume device\n"); + return r; + } + pr_info(MPT3SAS_FMT "pdev=0x%p, slot=%s, previous operating state [D%d]\n", ioc->name, pdev, pci_name(pdev), device_state); @@ -10786,9 +10836,13 @@ scsih_resume(struct pci_dev *pdev) static pci_ers_result_t scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); - struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + struct Scsi_Host *shost = NULL; + struct MPT3SAS_ADAPTER *ioc = NULL; + if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc)) { + dev_err(&pdev->dev, "device unavailable\n"); + return PCI_ERS_RESULT_DISCONNECT; + } pr_info(MPT3SAS_FMT "PCI error: detected callback, state(%d)!!\n", ioc->name, state); @@ -10825,10 +10879,14 @@ scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) static pci_ers_result_t scsih_pci_slot_reset(struct pci_dev *pdev) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); - struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + struct Scsi_Host *shost = NULL; + struct MPT3SAS_ADAPTER *ioc = NULL; int rc; + if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc)) { + dev_err(&pdev->dev, "unable to perform slot reset\n"); + return PCI_ERS_RESULT_DISCONNECT; + } pr_info(MPT3SAS_FMT "PCI error: slot reset callback!!\n", ioc->name); @@ -10861,9 +10919,13 @@ scsih_pci_slot_reset(struct pci_dev *pdev) static void scsih_pci_resume(struct pci_dev *pdev) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); - struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + struct Scsi_Host *shost = NULL; + struct MPT3SAS_ADAPTER *ioc = NULL; + if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc)) { + dev_err(&pdev->dev, "unable to resume device\n"); + return; + } pr_info(MPT3SAS_FMT "PCI error: resume callback!!\n", ioc->name); pci_cleanup_aer_uncorrect_error_status(pdev); @@ -10879,9 +10941,13 @@ scsih_pci_resume(struct pci_dev *pdev) static pci_ers_result_t scsih_pci_mmio_enabled(struct pci_dev *pdev) { - struct Scsi_Host *shost = pci_get_drvdata(pdev); - struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); + struct Scsi_Host *shost = NULL; + struct MPT3SAS_ADAPTER *ioc = NULL; + if (_scsih_get_shost_and_ioc(pdev, &shost, &ioc)) { + dev_err(&pdev->dev, "unable to enable mmio\n"); + return PCI_ERS_RESULT_DISCONNECT; + } pr_info(MPT3SAS_FMT "PCI error: mmio enabled callback!!\n", ioc->name); From patchwork Fri Aug 31 04:34:39 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: 10583113 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 C3472920 for ; Fri, 31 Aug 2018 04:35:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B46F62C18F for ; Fri, 31 Aug 2018 04:35:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8F5E2C1D8; Fri, 31 Aug 2018 04:35:22 +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 47AD62C18F for ; Fri, 31 Aug 2018 04:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727234AbeHaIkz (ORCPT ); Fri, 31 Aug 2018 04:40:55 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:52326 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbeHaIkz (ORCPT ); Fri, 31 Aug 2018 04:40:55 -0400 Received: by mail-wm0-f65.google.com with SMTP id y139-v6so3853332wmc.2 for ; Thu, 30 Aug 2018 21:35:20 -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=ohzi7KpBFCyiWNATnJhkmbRSw0M3V5klQnjk6KxZQkw=; b=DNWums5qigBUlgqiu0MyfI3DClz4VC54MQlHYp9XQkPxoD9KDalR0Yk7Xpt2KzakDg 0AxI84Crn79YJB1e5An8c6aF5qIa5aHp6Gk+kDWj1pMS1dYbcnHcKOTAGcL8oHnzQvQc xrAhytlCwxdWg6+mrhjKU1AfeM0A2DgxYYeYE= 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=ohzi7KpBFCyiWNATnJhkmbRSw0M3V5klQnjk6KxZQkw=; b=mRUid+2mkEqle4qKch4fgytoFOxGMiCRCvwdUdqgGkwshF4u3r/WYCaIh1aeh8D1DE /pV14MS6wKcQAjUkZJHZ0lCrmFuoISIlhXEsZtTPL3GXSN6XL+pK0qYR/3QJWn7MxH3I mfnExa+iM3x4pMu0auPmK+pLvYfqDUN6n5CA7Aa1WU7tW6q4I7L+Joe6SMgg/tJIe/XE kACj9pWEovp/IKi5NiATsJwvOztJnIL3xj9viuH0bzGQBobQ6Px/rlk/MN4QPgiIX/9K 2dYw7LMXDVUJClhmTSI8m5v44x63SapnJmxA1aKZoLCxUG98ErPj893fTVhiN0v2Jsxr xpDA== X-Gm-Message-State: APzg51AGdQxG/mujZOS1BKNB+1yG8ALjtkHZAgBb9irhP7LbXjbg5CVe R0FJ2Ef5uD7MgSV1iGpcp1AC371yzLM= X-Google-Smtp-Source: ANB0Vdb9wT23EmqhjkwMjliS98BEjlTHHKMc6qy1w0JApjcFtp0oABTzOvubfLOu7La2uHkQMTc/4g== X-Received: by 2002:a1c:398b:: with SMTP id g133-v6mr3318207wma.5.1535690119588; Thu, 30 Aug 2018 21:35:19 -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.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 21:35:19 -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 5/7] mpt3sas: Fix Sync cache command failure during driver unload. Date: Fri, 31 Aug 2018 00:34:39 -0400 Message-Id: <1535690081-16116-6-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 This is to fix Sync cache and start stop command failures with DID_NO_CONNECT during driver unload. 1) Release drives first from SML, then remove internally in driver. 2) And allow sync cache and Start stop commands to firmware, even when remove_host flag is set Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 41 ++++++++++++++++++++++++++++++-- drivers/scsi/mpt3sas/mpt3sas_transport.c | 7 ++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 2c7f44c..f796808 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -3806,6 +3806,43 @@ _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, return _scsih_check_for_pending_tm(ioc, smid); } +/** _scsih_allow_scmd_to_device - check whether scmd needs to + * issue to IOC or not. + * @ioc: per adapter object + * @scmd: pointer to scsi command object + * + * Returns true if scmd can be issued to IOC otherwise returns false. + */ +inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc, + struct scsi_cmnd *scmd) +{ + + if (ioc->pci_error_recovery) + return false; + + if (ioc->hba_mpi_version_belonged == MPI2_VERSION) { + if (ioc->remove_host) + return false; + + return true; + } + + + if (ioc->remove_host) { + if (mpt3sas_base_pci_device_is_unplugged(ioc)) + return false; + + switch (scmd->cmnd[0]) { + case SYNCHRONIZE_CACHE: + case START_STOP: + return true; + default: + return false; + } + } + + return true; +} /** * _scsih_sas_control_complete - completion routine @@ -4640,7 +4677,7 @@ scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd) return 0; } - if (ioc->pci_error_recovery || ioc->remove_host) { + if (!(_scsih_allow_scmd_to_device(ioc, scmd))) { scmd->result = DID_NO_CONNECT << 16; scmd->scsi_done(scmd); return 0; @@ -9876,6 +9913,7 @@ static void scsih_remove(struct pci_dev *pdev) /* release all the volumes */ _scsih_ir_shutdown(ioc); + sas_remove_host(shost); list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list, list) { if (raid_device->starget) { @@ -9918,7 +9956,6 @@ static void scsih_remove(struct pci_dev *pdev) ioc->sas_hba.num_phys = 0; } - sas_remove_host(shost); mpt3sas_base_detach(ioc); spin_lock(&gioc_lock); list_del(&ioc->list); diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c index b10d73e..742da74 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_transport.c +++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c @@ -817,10 +817,13 @@ mpt3sas_transport_port_remove(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, mpt3sas_port->remote_identify.sas_address, mpt3sas_phy->phy_id); mpt3sas_phy->phy_belongs_to_port = 0; - sas_port_delete_phy(mpt3sas_port->port, mpt3sas_phy->phy); + if (!ioc->remove_host) + sas_port_delete_phy(mpt3sas_port->port, + mpt3sas_phy->phy); list_del(&mpt3sas_phy->port_siblings); } - sas_port_delete(mpt3sas_port->port); + if (!ioc->remove_host) + sas_port_delete(mpt3sas_port->port); kfree(mpt3sas_port); } From patchwork Fri Aug 31 04:34:40 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: 10583115 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 EEBC814BD for ; Fri, 31 Aug 2018 04:35:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEAF92C18F for ; Fri, 31 Aug 2018 04:35:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2FBB2C1D8; Fri, 31 Aug 2018 04:35:25 +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 828972C18F for ; Fri, 31 Aug 2018 04:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727240AbeHaIk7 (ORCPT ); Fri, 31 Aug 2018 04:40:59 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:52331 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbeHaIk7 (ORCPT ); Fri, 31 Aug 2018 04:40:59 -0400 Received: by mail-wm0-f66.google.com with SMTP id y139-v6so3853415wmc.2 for ; Thu, 30 Aug 2018 21:35:24 -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=mQI7Kz+eUmlAYDX8/WCTH/9Q+lnyZaPfLRghzEpIaeI=; b=cIfrKQS+NjmGrzThfvL9IPvpFdqVp2+gBsCsnsYzFWePFcBBSIhuSvWn2kxNFzr+lX HCJqUoRUNER2ApwxpEObBoo+KHAQOF1ql33uyeYAlMczgwxAWa1Fa5pHtoeGcRq10wOU 4Ostt5JSt5+xqPEtpDK7VK3EqYtFTcuu9daH0= 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=mQI7Kz+eUmlAYDX8/WCTH/9Q+lnyZaPfLRghzEpIaeI=; b=XoV+tfX7HJEcGa596l7F0ba1GtdH/Nj5Wf7etws/EwspYuuXQSlNHaN7AM/DvgP8Br rgGLGOFwKabjPrvukSl31ZeA7SdL6EYzphOQElGPDwrbgX7DnH4io+AoBgpk9I4JQMt+ 8dAV/aWvqg1dJvxz7RX9WUHfeDliKrogyzMdXMlP4SSr9tkpKzU9nffKUO+MAim8BdcV 6Uenn2+84XELGzbnSxg2GwqHoF7VaSNntpZu/PRJ5YAEYbs9bCr0OURn/2tcbrGh9yPu IXOg7cFzq2EQiuQqXGW2OrZVsPt7IbzxC/a2TWL3epkzLgMdG+YnViD4FxwI8cTJ89iJ 5g0w== X-Gm-Message-State: APzg51CHmqFFtLD5wDZ3VVup/O4sRfUgvYckyxeE+/FcpEjuz/wrOjv+ ff9nCktsvkXcIQp8zG2lMhKN0xd9E8k= X-Google-Smtp-Source: ANB0VdZi6Uk3ucPo2xkll7VkYVJNUs4zRnjdB1oeV3PCHRxehtAS4TE6cw1CHTPpfsmxXvdtdKBlsg== X-Received: by 2002:a1c:7301:: with SMTP id d1-v6mr3428330wmb.34.1535690122965; Thu, 30 Aug 2018 21:35:22 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 21:35:22 -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 6/7] mpt3sas: Fix driver modifying NVRAM/persistent data. Date: Fri, 31 Aug 2018 00:34:40 -0400 Message-Id: <1535690081-16116-7-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 * If EEDPTagMode field in manufacturing page11 is set, unset it. This is needed to fix a hardware bug in SAS3/SAS2 cards, So, skipping EEDPTagMode changes in Manufacturing page11 for SAS35 controllers. * Fix driver modifying NVRAM/persistent data in Manufacturing page11 along with current copy. Driver should change only current copy of Manufacturing page11 Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_base.c | 2 +- drivers/scsi/mpt3sas/mpt3sas_config.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c index a46ded8..92637c5 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.c +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c @@ -4235,7 +4235,7 @@ _base_static_config_pages(struct MPT3SAS_ADAPTER *ioc) * flag unset in NVDATA. */ mpt3sas_config_get_manufacturing_pg11(ioc, &mpi_reply, &ioc->manu_pg11); - if (ioc->manu_pg11.EEDPTagMode == 0) { + if ((!ioc->is_gen35_ioc) && (ioc->manu_pg11.EEDPTagMode == 0)) { pr_err("%s: overriding NVDATA EEDPTagMode setting\n", ioc->name); ioc->manu_pg11.EEDPTagMode &= ~0x3; diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c index 5713a2d..f2a326a 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_config.c +++ b/drivers/scsi/mpt3sas/mpt3sas_config.c @@ -676,10 +676,6 @@ mpt3sas_config_set_manufacturing_pg11(struct MPT3SAS_ADAPTER *ioc, r = _config_request(ioc, &mpi_request, mpi_reply, MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sizeof(*config_page)); - mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM; - r = _config_request(ioc, &mpi_request, mpi_reply, - MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, - sizeof(*config_page)); out: return r; } From patchwork Fri Aug 31 04:34:41 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: 10583117 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 3EBEE14BD for ; Fri, 31 Aug 2018 04:35:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EEB32C18F for ; Fri, 31 Aug 2018 04:35:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 236BF2C1D8; Fri, 31 Aug 2018 04:35:29 +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 C62C32C18F for ; Fri, 31 Aug 2018 04:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727255AbeHaIlC (ORCPT ); Fri, 31 Aug 2018 04:41:02 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33740 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726660AbeHaIlC (ORCPT ); Fri, 31 Aug 2018 04:41:02 -0400 Received: by mail-wm0-f65.google.com with SMTP id r1-v6so226205wmh.0 for ; Thu, 30 Aug 2018 21:35:27 -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=pSL42ZrYpV5PZYdarHq28SRqqp3zwRPeMM5LXPN3TKU=; b=R7F5PNaT2nI0jXAtiYPooia5bY1ifgkEEngzXZ/heCOluh2MbIb18Er11MyI3X5iKc OGNAlaSPfOs86XKQGtzBphtfTonMmE+n4LZ8h1Epa7reLcY4G2jlmKkL1lIfHLs03bZ/ Zpb44hiHhmPw7rUfunFIjibDuRiGoDZoG9oWQ= 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=pSL42ZrYpV5PZYdarHq28SRqqp3zwRPeMM5LXPN3TKU=; b=htuynRu/MJd/c4ZVQpRnfBMqBNGQrC9A5j5pdGnym/nRceo3qOlHYDItOAKna0slzI MfVz2YnNSWWCb8v/IeG/ZWHjuXYSSt6iI9p+Zt/0dbII3L7LFqfIdeIQFLbENoerS7dM iYSShBqOLG/UjvkcpVOQl5UPgfhGq7W32thU8rIP88y948EkvU7Hn8qlcy3HV1OlFQxu lPp/L4bCF7FMUuAcPMcufMiBGA0ojlVRybstqZWtxwv0xMwwp+xH1B7wtwWw+psQ9g8o 9TelHLkw4BlrkwzytUdiHc38fXQRE0EAkwYbULl/7hZhpripjX0T3RelhJHICVR0nHTB Cd5A== X-Gm-Message-State: APzg51Ap8l7YU9FpsmPcbow8v4Ffwy/X87eryhuiWSHPX5aM314Fq1RF pfaRfCAihMfN/EyK2soSidPuv00vE4U= X-Google-Smtp-Source: ANB0VdaIlrP/mEJ4OSwKVFolrRFN0dfvNlxZoU+xURZh/0Wa3SmcFyyYHso1xXtClDY0WNw/SwebRw== X-Received: by 2002:a1c:357:: with SMTP id 84-v6mr3467297wmd.8.1535690126338; Thu, 30 Aug 2018 21:35:26 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 21:35:25 -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 7/7] mpt3sas: Bump driver version to 27.100.00.00. Date: Fri, 31 Aug 2018 00:34:41 -0400 Message-Id: <1535690081-16116-8-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 Modify driver version to 27.100.00.00 (which is equivalent to PH8 OOB driver) Signed-off-by: Suganath Prabu S --- drivers/scsi/mpt3sas/mpt3sas_base.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h index 8b2cc66..7f29b0e 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.h +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h @@ -74,8 +74,8 @@ #define MPT3SAS_DRIVER_NAME "mpt3sas" #define MPT3SAS_AUTHOR "Avago Technologies " #define MPT3SAS_DESCRIPTION "LSI MPT Fusion SAS 3.0 Device Driver" -#define MPT3SAS_DRIVER_VERSION "26.100.00.00" -#define MPT3SAS_MAJOR_VERSION 26 +#define MPT3SAS_DRIVER_VERSION "27.100.00.00" +#define MPT3SAS_MAJOR_VERSION 27 #define MPT3SAS_MINOR_VERSION 100 #define MPT3SAS_BUILD_VERSION 0 #define MPT3SAS_RELEASE_VERSION 00