From patchwork Tue Oct 10 13:11:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreekanth Reddy X-Patchwork-Id: 9996095 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 4B2AB603B5 for ; Tue, 10 Oct 2017 13:13:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BFEB285C9 for ; Tue, 10 Oct 2017 13:13:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30CF4285CC; Tue, 10 Oct 2017 13:13:49 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable 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 21F97285C9 for ; Tue, 10 Oct 2017 13:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932177AbdJJNMh (ORCPT ); Tue, 10 Oct 2017 09:12:37 -0400 Received: from mail-qt0-f182.google.com ([209.85.216.182]:48749 "EHLO mail-qt0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932165AbdJJNMb (ORCPT ); Tue, 10 Oct 2017 09:12:31 -0400 Received: by mail-qt0-f182.google.com with SMTP id f8so15931704qta.5 for ; Tue, 10 Oct 2017 06:12:31 -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=hPFlcdmqlJqnWZAd4dvA7dMyIYzwLZgTDZScq+RMUMY=; b=chDpYvNe6sCxJV9Eedyf93UqzsJrSUsSQX87ZK5k7Kr9h71XSBvWsgBCSkpjXTDHCy g7HQMUI/1pVa5247NL9eKoeCkwn482Zv69+Qkg2od5WMWLTZ6FjsRhY3hNo6/GnUqxTa AZdNKWRgmjW0//G7vNEhE2PRNgQtjlHKIebWk= 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=hPFlcdmqlJqnWZAd4dvA7dMyIYzwLZgTDZScq+RMUMY=; b=O52L96bOaDf6LQReNO1ZSLs+QIQe9tmCNLQvIviqvsSvJ8vnvbExTT3jPBqclqPvCw JG6elJc9oNBIhn3qF/LsdsuyrYv6ZflsWOboNoY/8am4D/acc8WW7+LaOIcPNNJgqmlY dBXkVGBbuDQqpOlpnOk4agvEbs4qBjpgXBLQRm8VX/o6vPB/IsYOgpS4i5tD0mtaZXhG jvj3vG3laQNBaAFbHOQjY/0sp4QdO0xDupnXbjBZMr+5AM5rlr06gcMnOe+TKn5ZwpCI XidKCrgFVuM2gkHMjgbq1FSiW2yOMvlflgz1v4Qb4vn1CM5K/b36G5c1PFbwLcZxMQCr V7mQ== X-Gm-Message-State: AMCzsaX4IoTGrPGRTq9DHiGI/MR5tD2S12u+t5tXI4vRlvJJkX544iOW PJvyjZ62OFme2UkuNNhyEBrtDXxE X-Google-Smtp-Source: AOwi7QAHdo5ncOPYeU23K41WuDAw6ZCP4FLG+JzbBCtKwlV9rvExRVfgOI5TElOtXPfiFg2PTJ4c9A== X-Received: by 10.55.212.219 with SMTP id s88mr13751723qks.188.1507641150561; Tue, 10 Oct 2017 06:12:30 -0700 (PDT) Received: from host1.dhcp.avagotech.net ([192.19.239.250]) by smtp.gmail.com with ESMTPSA id h135sm634004qke.5.2017.10.10.06.12.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 06:12:29 -0700 (PDT) From: Sreekanth Reddy X-Google-Original-From: Sreekanth Reddy To: linux-scsi@vger.kernel.org, hch@infradead.org Cc: martin.petersen@oracle.com, JBottomley@Parallels.com, Sathya.Prakash@broadcom.com, linux-kernel@vger.kernel.org, Sreekanth Reddy Subject: [PATCH 08/10] mpt3sas: Fix possibility of using invalid Enclosure Handles for SAS device after host reset Date: Tue, 10 Oct 2017 18:41:21 +0530 Message-Id: <1507641083-20207-9-git-send-email-Sreekanth.Reddy@broadcom.com> X-Mailer: git-send-email 2.0.2 In-Reply-To: <1507641083-20207-1-git-send-email-Sreekanth.Reddy@broadcom.com> References: <1507641083-20207-1-git-send-email-Sreekanth.Reddy@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 Enclosure handles are not updated after host reset. As a result, driver device structure is holding previously assigned enclosure handle which is different from the enclosure handle populated in the corresponding device page. Modified the driver to update devices enclosure handles after host reset to current value, by referring the enclosure handles from corresponding device pages Signed-off-by: Sreekanth Reddy Signed-off-by: Tomas Henzl Reviewed-by: Tomas Henzl --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 117 ++++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 36 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 17b934b..b819914 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -5383,6 +5383,52 @@ _scsih_check_access_status(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, } /** + * _scsih_get_enclosure_logicalid_chassis_slot - get device's + * EnclosureLogicalID and ChassisSlot information. + * @ioc: per adapter object + * @sas_device_pg0: SAS device page0 + * @sas_device: per sas device object + * + * Returns nothing. + */ +static void +_scsih_get_enclosure_logicalid_chassis_slot(struct MPT3SAS_ADAPTER *ioc, + Mpi2SasDevicePage0_t *sas_device_pg0, struct _sas_device *sas_device) +{ + Mpi2ConfigReply_t mpi_reply; + Mpi2SasEnclosurePage0_t enclosure_pg0; + + if (!sas_device_pg0 || !sas_device) + return; + + sas_device->enclosure_handle = + le16_to_cpu(sas_device_pg0->EnclosureHandle); + sas_device->is_chassis_slot_valid = 0; + + if (!le16_to_cpu(sas_device_pg0->EnclosureHandle)) + return; + + if (mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, + &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, + le16_to_cpu(sas_device_pg0->EnclosureHandle))) { + pr_err(MPT3SAS_FMT + "Enclosure Pg0 read failed for handle(0x%04x)\n", + ioc->name, le16_to_cpu(sas_device_pg0->EnclosureHandle)); + return; + } + + sas_device->enclosure_logical_id = + le64_to_cpu(enclosure_pg0.EnclosureLogicalID); + + if (le16_to_cpu(enclosure_pg0.Flags) & + MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { + sas_device->is_chassis_slot_valid = 1; + sas_device->chassis_slot = enclosure_pg0.ChassisSlot; + } +} + + +/** * _scsih_check_device - checking device responsiveness * @ioc: per adapter object * @parent_sas_address: sas address of parent expander or sas host @@ -5398,7 +5444,6 @@ _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, { Mpi2ConfigReply_t mpi_reply; Mpi2SasDevicePage0_t sas_device_pg0; - Mpi2SasEnclosurePage0_t enclosure_pg0; struct _sas_device *sas_device; u32 ioc_status; unsigned long flags; @@ -5407,7 +5452,6 @@ _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, struct MPT3SAS_TARGET *sas_target_priv_data; u32 device_info; - if ((mpt3sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) return; @@ -5454,18 +5498,9 @@ _scsih_check_device(struct MPT3SAS_ADAPTER *ioc, sas_device->enclosure_level = 0; sas_device->connector_name[0] = '\0'; } - sas_device->is_chassis_slot_valid = 0; - if (sas_device->enclosure_handle && - !(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, - &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, - sas_device->enclosure_handle))) { - if (le16_to_cpu(enclosure_pg0.Flags) & - MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { - sas_device->is_chassis_slot_valid = 1; - sas_device->chassis_slot = - enclosure_pg0.ChassisSlot; - } - } + + _scsih_get_enclosure_logicalid_chassis_slot(ioc, + &sas_device_pg0, sas_device); } /* check if device is present */ @@ -7088,10 +7123,8 @@ Mpi2SasDevicePage0_t *sas_device_pg0) { struct MPT3SAS_TARGET *sas_target_priv_data = NULL; struct scsi_target *starget; - struct _sas_device *sas_device; + struct _sas_device *sas_device = NULL; unsigned long flags; - Mpi2SasEnclosurePage0_t enclosure_pg0; - Mpi2ConfigReply_t mpi_reply; spin_lock_irqsave(&ioc->sas_device_lock, flags); list_for_each_entry(sas_device, &ioc->sas_device_list, list) { @@ -7131,18 +7164,8 @@ Mpi2SasDevicePage0_t *sas_device_pg0) sas_device->connector_name[0] = '\0'; } - sas_device->is_chassis_slot_valid = 0; - if (sas_device->enclosure_handle && - !(mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, - &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, - sas_device->enclosure_handle))) { - if (le16_to_cpu(enclosure_pg0.Flags) & - MPI2_SAS_ENCLS0_FLAGS_CHASSIS_SLOT_VALID) { - sas_device->is_chassis_slot_valid = 1; - sas_device->chassis_slot = - enclosure_pg0.ChassisSlot; - } - } + _scsih_get_enclosure_logicalid_chassis_slot(ioc, + sas_device_pg0, sas_device); if (sas_device->handle == sas_device_pg0->DevHandle) goto out; @@ -7340,8 +7363,7 @@ _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) /** * _scsih_mark_responding_expander - mark a expander as responding * @ioc: per adapter object - * @sas_address: sas address - * @handle: + * @expander_pg0:SAS Expander Config Page0 * * After host reset, find out whether devices are still responding. * Used in _scsih_remove_unresponsive_expanders. @@ -7349,18 +7371,41 @@ _scsih_search_responding_raid_devices(struct MPT3SAS_ADAPTER *ioc) * Return nothing. */ static void -_scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, u64 sas_address, - u16 handle) +_scsih_mark_responding_expander(struct MPT3SAS_ADAPTER *ioc, + Mpi2ExpanderPage0_t *expander_pg0) { - struct _sas_node *sas_expander; + struct _sas_node *sas_expander = NULL; unsigned long flags; - int i; + int i, encl_pg0_rc = -1; + Mpi2ConfigReply_t mpi_reply; + Mpi2SasEnclosurePage0_t enclosure_pg0; + u16 handle = le16_to_cpu(expander_pg0->DevHandle); + u64 sas_address = le64_to_cpu(expander_pg0->SASAddress); + + if (le16_to_cpu(expander_pg0->EnclosureHandle)) { + encl_pg0_rc = mpt3sas_config_get_enclosure_pg0(ioc, &mpi_reply, + &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE, + le16_to_cpu(expander_pg0->EnclosureHandle)); + if (encl_pg0_rc) + pr_info(MPT3SAS_FMT + "Enclosure Pg0 read failed for handle(0x%04x)\n", + ioc->name, + le16_to_cpu(expander_pg0->EnclosureHandle)); + } spin_lock_irqsave(&ioc->sas_node_lock, flags); list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) { if (sas_expander->sas_address != sas_address) continue; sas_expander->responding = 1; + + if (!encl_pg0_rc) + sas_expander->enclosure_logical_id = + le64_to_cpu(enclosure_pg0.EnclosureLogicalID); + + sas_expander->enclosure_handle = + le16_to_cpu(expander_pg0->EnclosureHandle); + if (sas_expander->handle == handle) goto out; pr_info("\texpander(0x%016llx): handle changed" \ @@ -7413,7 +7458,7 @@ _scsih_search_responding_expanders(struct MPT3SAS_ADAPTER *ioc) pr_info("\texpander present: handle(0x%04x), sas_addr(0x%016llx)\n", handle, (unsigned long long)sas_address); - _scsih_mark_responding_expander(ioc, sas_address, handle); + _scsih_mark_responding_expander(ioc, &expander_pg0); } out: