From patchwork Wed Dec 27 04:34:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghava Aditya Renukunta X-Patchwork-Id: 10133435 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 13F8F6037D for ; Wed, 27 Dec 2017 04:35:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F086A2DA63 for ; Wed, 27 Dec 2017 04:35:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E482C2DAA2; Wed, 27 Dec 2017 04:35:54 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 6F8C52DA63 for ; Wed, 27 Dec 2017 04:35:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751887AbdL0Efx (ORCPT ); Tue, 26 Dec 2017 23:35:53 -0500 Received: from mail-bn3nam01on0062.outbound.protection.outlook.com ([104.47.33.62]:5888 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751641AbdL0EfT (ORCPT ); Tue, 26 Dec 2017 23:35:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mscc365.onmicrosoft.com; s=selector1-microsemi-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CuUPBjeY7WPtGTWvty5N/9/FGzuo8YqC4bJcHeeuG7s=; b=KEz+jRD07BwVRf+HOhLC6q5kArhBb9jVgT9Vkr8PVCScu6bcPJbEHwna0s1J6QR78AG3jkFlWyRMr5iYyqSQj5IQVdZ3z7tkqitA6cO1AFGv3xkw340laOnSMYFcvHY6Dru7aCeg2kNLKPmToRC6ak+5GaP6bCiiVNMhsmfbhpk= Received: from MWHPR0201CA0048.namprd02.prod.outlook.com (2603:10b6:301:73::25) by CO1PR02MB142.namprd02.prod.outlook.com (2a01:111:e400:101e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.366.8; Wed, 27 Dec 2017 04:35:16 +0000 Received: from BL2FFO11FD050.protection.gbl (2a01:111:f400:7c09::151) by MWHPR0201CA0048.outlook.office365.com (2603:10b6:301:73::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.366.8 via Frontend Transport; Wed, 27 Dec 2017 04:35:16 +0000 Authentication-Results: spf=pass (sender IP is 208.19.100.21) smtp.mailfrom=microsemi.com; wdc.com; dkim=none (message not signed) header.d=none;wdc.com; dmarc=bestguesspass action=none header.from=microsemi.com; Received-SPF: Pass (protection.outlook.com: domain of microsemi.com designates 208.19.100.21 as permitted sender) receiver=protection.outlook.com; client-ip=208.19.100.21; helo=avsrvexchhts1.microsemi.net; Received: from avsrvexchhts1.microsemi.net (208.19.100.21) by BL2FFO11FD050.mail.protection.outlook.com (10.173.161.212) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.20.345.12 via Frontend Transport; Wed, 27 Dec 2017 04:34:56 +0000 Received: from localhost (10.181.72.13) by avsrvexchhts1.microsemi.net (10.100.34.105) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 26 Dec 2017 20:34:59 -0800 From: Raghava Aditya Renukunta To: , , CC: , , , "Guilherme G . Piccoli" , Bart Van Assche Subject: [PATCH v2 21/30] scsi: aacraid: Refactor resolve luns code and scsi functions Date: Tue, 26 Dec 2017 20:34:42 -0800 Message-ID: <20171227043451.27813-22-RaghavaAditya.Renukunta@microsemi.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20171227043451.27813-1-RaghavaAditya.Renukunta@microsemi.com> References: <20171227043451.27813-1-RaghavaAditya.Renukunta@microsemi.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:208.19.100.21; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(39860400002)(346002)(376002)(39380400002)(396003)(2980300002)(438002)(199004)(189003)(104016004)(106466001)(97736004)(48376002)(50466002)(53936002)(36756003)(76176011)(68736007)(1076002)(2906002)(2201001)(86362001)(72206003)(54906003)(5660300001)(2950100002)(8936002)(76506005)(356003)(81166006)(110136005)(51416003)(4326008)(316002)(77096006)(16586007)(106002)(8676002)(305945005)(57986006)(50226002)(6666003)(478600001)(81156014)(47776003)(69596002); DIR:OUT; SFP:1101; SCL:1; SRVR:CO1PR02MB142; H:avsrvexchhts1.microsemi.net; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD050; 1:Y2WkuzTXx9uuhN0Py1Q2Srmtc9E6i4Vq+0Z3DDzo2CXh5nBWqCbzoJBvT0Vha/e5TwrNkkcxW+7cJGKu3+KU4vQZKljBVDA/Itf7BlMSWslbAcURNnz6r/ehfTutYXwh X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e8b99d7b-fdf6-431e-4506-08d54ce32eea X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603307)(7153060); SRVR:CO1PR02MB142; X-Microsoft-Exchange-Diagnostics: 1; CO1PR02MB142; 3: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hnYSUAXh70SsdStc7gFgkmdt/4q5RfCqyJRnW9s2u+B9vMDuf7fkfN80gnEcMiTnp6p7sORw/Vb69d8zrPGyCKtzGO8tiscamGr18DwS+ohxw18xHM3nyba4PaBpX0h6sNFY2q4p7dfv2j9J3wHx4PYWBwwIvUK30ShuZBZBBT8H1+wp/+ksNIIv1/QdOoIUB+Mr0hc8C4/MIRzjkdNGcjUmmSju5F54b9xo3PanRHo1Pdveb7mNOoCuqFnlSZkJSNuoypz5/Hw6t9dqAB6zDGePYAkR9PoYERZAl4gkXyjLxqo0BNC+fSGU3S45eOc/rJ8LEFGBE0+1Ox6wsayB7/5Gsg6yhmLMzyK/LgrcKgI1dxtVE8gQBhjlCsMxq0Ly6brlzSYFiR9z50vSWKGiLeUtkscOH8pNP7xmfwCWiM2bnXI1pQ9l2U6IRRBdYPydfccCedTnJEEy6GTe2aqzP1rsG1/PsL+WI+8blsA6zHtOPEtjCC9YfqM+JN6nRYaUWJ0Dz6Uslynk/h3fT/DV5fPZigo9OcGMF1vpgiWYQF6NhJE10= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72170198267865); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93004095)(3231023)(944501075)(6055026)(6041268)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(6072148)(201708071742011); SRVR:CO1PR02MB142; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CO1PR02MB142; X-Microsoft-Exchange-Diagnostics: 1; CO1PR02MB142; 4:orpY+cmihJj9YUdUGBopaFhZmjMB1ZyXvuVhHLjGz5tAFzL9rJZ9lPLN/7SbieaelrrWmBXrWLrZo9maHnGngzfHcmrjYTR90oPhkV5aXl6mBsTIEz2YORp+2WqQWfmq6bg228/bpxEhXxSqfziLU2lHjUTAJ7z0tIG4O7a6U6C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FeHIawwhtd3kSXqYy9fxrVZWfmagtKSt3aD5Pzn0WbhTUKEyD5tpyU/+7+FrbloBeIIlRR1IfxPN5107EdNn+arubbrY1NE=; 7:U27p85sV/uz4lop7Qgvfc+odsVnE3tPsJ/ELFtX3BmF0XX0R/73iXda1t5LMUCYmAOs6WnOziQ4TEYwsQLCsVkscYEAosk23mGUIMjwJRGwNnCMFsTb9tRm86qyA8Tpebra6wlU1t7XgWKbJsKh/EHdkvgRujNbCZvETldBhpkr10ghW658oaPfEApnFayprHXT5KrNWeYwT1/BhB8yvFHvaT/5MYzlyxSDd7qMqCulbOM91Ou2dQNL1YkCi/gsc SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: microsemi.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Dec 2017 04:34:56.7909 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e8b99d7b-fdf6-431e-4506-08d54ce32eea X-MS-Exchange-CrossTenant-Id: f267a5c8-86d8-4cc9-af71-1fd2c67c8fad X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f267a5c8-86d8-4cc9-af71-1fd2c67c8fad; Ip=[208.19.100.21]; Helo=[avsrvexchhts1.microsemi.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR02MB142 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 Resolve luns checks the if a sdev is already present in the os to figure out if it needs to be removed. Internally the driver exposes HBA on bus 2 even though its bus 1 in the fw. Its mildly confusing. Refactor out the sdev lookup into its function to check if sdev has been added to the kernel or not. Add helper functions to add, remove and put devices based on their fw bus and target number. Signed-off-by: Raghava Aditya Renukunta --- Changes in V2: Removed unnecessary check and assignment for bus number drivers/scsi/aacraid/commsup.c | 71 ++++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c index 8966371..5b7a4f5 100644 --- a/drivers/scsi/aacraid/commsup.c +++ b/drivers/scsi/aacraid/commsup.c @@ -1874,6 +1874,39 @@ static inline int is_safw_raid_volume(struct aac_dev *aac, int bus, int target) return bus == CONTAINER_CHANNEL && target < aac->maximum_num_containers; } +static struct scsi_device *aac_lookup_safw_scsi_device(struct aac_dev *dev, + int bus, + int target) +{ + if (bus != CONTAINER_CHANNEL) + bus = aac_phys_to_logical(bus); + + return scsi_device_lookup(dev->scsi_host_ptr, bus, target, 0); +} + +static int aac_add_safw_device(struct aac_dev *dev, int bus, int target) +{ + if (bus != CONTAINER_CHANNEL) + bus = aac_phys_to_logical(bus); + + return scsi_add_device(dev->scsi_host_ptr, bus, target, 0); +} + +static void aac_put_safw_scsi_device(struct scsi_device *sdev) +{ + if (sdev) + scsi_device_put(sdev); +} + +static void aac_remove_safw_device(struct aac_dev *dev, int bus, int target) +{ + struct scsi_device *sdev; + + sdev = aac_lookup_safw_scsi_device(dev, bus, target); + scsi_remove_device(sdev); + aac_put_safw_scsi_device(sdev); +} + static inline int aac_is_safw_scan_count_equal(struct aac_dev *dev, int bus, int target) { @@ -1888,33 +1921,37 @@ static int aac_is_safw_target_valid(struct aac_dev *dev, int bus, int target) return aac_is_safw_scan_count_equal(dev, bus, target); } +static int aac_is_safw_device_exposed(struct aac_dev *dev, int bus, int target) +{ + int is_exposed = 0; + struct scsi_device *sdev; + + sdev = aac_lookup_safw_scsi_device(dev, bus, target); + if (sdev) + is_exposed = 1; + aac_put_safw_scsi_device(sdev); + + return is_exposed; +} + static void aac_resolve_luns(struct aac_dev *dev) { int i; - int bus, target, channel; - struct scsi_device *sdev; + int bus, target; + int is_exposed = 0; for (i = 0; i < AAC_BUS_TARGET_LOOP; i++) { bus = get_bus_number(i); target = get_target_number(i); - if (bus == CONTAINER_CHANNEL) - channel = CONTAINER_CHANNEL; - else - channel = aac_phys_to_logical(bus); - - sdev = scsi_device_lookup(dev->scsi_host_ptr, channel, - target, 0); - - if (!sdev && aac_is_safw_target_valid(dev, bus, target)) - scsi_add_device(dev->scsi_host_ptr, channel, - target, 0); - else if (sdev && aac_is_safw_target_valid(dev, bus, target)) - scsi_remove_device(sdev); + is_exposed = aac_is_safw_device_exposed(dev, bus, target); - if (sdev) - scsi_device_put(sdev); + if (aac_is_safw_target_valid(dev, bus, target) && !is_exposed) + aac_add_safw_device(dev, bus, target); + else if (!aac_is_safw_target_valid(dev, bus, target) && + is_exposed) + aac_remove_safw_device(dev, bus, target); } }