From patchwork Thu Dec 21 17:34:12 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: 10128129 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 A437260318 for ; Thu, 21 Dec 2017 17:35:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 928FA2847A for ; Thu, 21 Dec 2017 17:35:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86FD529D37; Thu, 21 Dec 2017 17:35:33 +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 191AA2847A for ; Thu, 21 Dec 2017 17:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755116AbdLURfa (ORCPT ); Thu, 21 Dec 2017 12:35:30 -0500 Received: from mail-sn1nam01on0059.outbound.protection.outlook.com ([104.47.32.59]:30848 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754520AbdLURet (ORCPT ); Thu, 21 Dec 2017 12:34:49 -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=czddbj3Y8mCYd1d16GmqLTf9rrtaX0cLECOWHfvk1ag=; b=lWKIP1sWICRfAvT59sjIMJme3D3VI1Mv9q7OpT9vK7D0cIZTJq6oYQE6bM6fu7oUpaxQWGtvZaUMD6PO/mfDwpbYstjNBzjYGVmFHSsZWUDnrvteWy1FFYQ8tUTi0zFxQyrLVXkFsL3Y32Tm8fZFKB/WqMUTnz0X7CQ4XRqimDo= Received: from MWHPR0201CA0061.namprd02.prod.outlook.com (10.167.160.38) by SN1PR0201MB1837.namprd02.prod.outlook.com (10.162.228.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.345.14; Thu, 21 Dec 2017 17:34:47 +0000 Received: from BN1BFFO11FD012.protection.gbl (2a01:111:f400:7c10::1:183) by MWHPR0201CA0061.outlook.office365.com (2603:10b6:301:73::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.345.14 via Frontend Transport; Thu, 21 Dec 2017 17:34:47 +0000 Authentication-Results: spf=pass (sender IP is 208.19.100.21) smtp.mailfrom=microsemi.com; linux.vnet.ibm.com; dkim=none (message not signed) header.d=none; linux.vnet.ibm.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 BN1BFFO11FD012.mail.protection.outlook.com (10.58.144.75) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.20.302.6 via Frontend Transport; Thu, 21 Dec 2017 17:34:33 +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; Thu, 21 Dec 2017 09:34:27 -0800 From: Raghava Aditya Renukunta To: , , CC: , , , "Guilherme G . Piccoli" Subject: [PATCH 21/29] scsi: aacraid: Refactor resolve luns code and scsi functions Date: Thu, 21 Dec 2017 09:34:12 -0800 Message-ID: <20171221173420.8213-22-RaghavaAditya.Renukunta@microsemi.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20171221173420.8213-1-RaghavaAditya.Renukunta@microsemi.com> References: <20171221173420.8213-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)(376002)(39860400002)(346002)(39380400002)(396003)(2980300002)(438002)(199004)(189003)(50466002)(48376002)(1076002)(478600001)(72206003)(36756003)(356003)(305945005)(106466001)(86362001)(69596002)(57986006)(76176011)(76506005)(51416003)(106002)(8676002)(77096006)(97736004)(4326008)(16586007)(54906003)(50226002)(316002)(81166006)(104016004)(68736007)(81156014)(6666003)(8936002)(53936002)(47776003)(110136005)(2950100002)(2201001)(5660300001)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR0201MB1837; H:avsrvexchhts1.microsemi.net; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD012; 1:R/htBFF7KI3qrHH2XbrjfmIejSTKVOimtqizPi2ivI1JZ+1mqGqejR7A6nmX/3WzPqigwILUSo3DaQsLylZzdpAg7M6hPbntdDmwHOFTpz8IsVRNbWgMTaxmNDwsICUB X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8988f45a-a575-4d51-761c-08d548991948 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603307)(7153060); SRVR:SN1PR0201MB1837; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0201MB1837; 3:FTHMUWAQ/ZldNh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9yFIr57HNuPj+brLxOk90Lw6CorCQrfhGUWpt9K7hczfYefKBTtiufNtZpzHt9/D8y9oV1B0sO+3qdF47exCUF/a2DZLHrE2GqSi5p2Q02tW6YuRjkBjKW7OgdCeDUrr+jBLiUUZp5NrquiaIUJe/r2BM43437Qq9grizvr1/mV0d7+7GVSjQ6jvCJNQS7l4sT8ffaHlcLW2WH95fhG5NWKGUbPc9pzWIhGBK/FR59FXQQyRVB7O/9TPrKr71ZzVjZ/zq9WYVqwdY+PMHYdsC0uOihIz3cFqR6T1uIBTWGdmXw75nhufEFFOLP1JYYYmEuCtq9ZVWqzp2r2Oco0yeuwq5ZELxNeA8U1wY9oOeMvRbp30kbctHgORTm0u+YwRXirmFT0BVJUsm2q51fI8eWneR8f7Vhozymu7u1I/sm+TroMFMNgaCnhtsvmo6pOhJkT+3IDlg2rg0v7qLRn9GEqxXDT8sL4w0vEnyjZFj5tYawqnKcrIVoYRjX28JvrRAn4Llq85RvF6dxqeNmqXsJEtbJEkuTUHnVVEPB6E= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72170198267865); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(10201501046)(3231023)(93006095)(93004095)(3002001)(6055026)(6041268)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:SN1PR0201MB1837; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:SN1PR0201MB1837; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0201MB1837; 4:/73LoexBvArmczqLeEq/Tzi6Y3THujTGMqC437F9Fc2XsX9QMxdgaSLjbXPheOVgtVmGe4lKOGIGzfvhnhhzUURnn2txexQOAnAxRixma+5sdmmMyljEtHlm3K7yypIzbWwZopD6cJ5lOaNK9V2yuAs4NDlgZtF0+OyE73ABUmg6LywkSJHOlzywiOKOuRhYEedVWoSUIotsKzyjriFFZATCzXOZ8bYXrNPloJCo42UfFOpkTHFBCG/wlF3AMs6J96sKjpCypjMGIz2zcD4kEI+HtMkNruiBSJJrQNaXI20afyltl3wG/ER0MoDFiRmf X-Forefront-PRVS: 0528942FD8 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR0201MB1837; 23:JNyD+BekWB/zR9EGwLfHzDL9X1Rx+BcEwXSl+I4?= =?us-ascii?Q?B56xGZcGifFkjyxic6wDxQOTCTMBYsr1BUbmMzBga7ny6p9WRVVWYpL+tRE5?= =?us-ascii?Q?IBWTaK9A9phSefy12wgaGia0aueulh+IBYu1B0TkTJlHtliJgEQ4JbSXJsrP?= =?us-ascii?Q?fd4wCWGE0P46orHgZZ4+g8Q+TuKuXpNpTkxaBBidkjCpxfiB36MBuoULiK/r?= =?us-ascii?Q?yQu8uQIMXSQgTCNGvQaNB23JgbCsMoLsECfulKOjKFjFnM6wRBJq0u7soSMK?= =?us-ascii?Q?4Tv2906QHk3Mz35Z8lYHFeM7FOOwwAwaxBbkVW/EBHdXiXfCoCH/ocqqrsL1?= =?us-ascii?Q?b6aqhoywN9eCnVKEqAwzcgR/SGA4pWc9+49krOqlcIyTjeT/J7ABi6ztSm4L?= =?us-ascii?Q?48UTreDORp5nZjTLbi46BfRvwZ0RM9hfeLB3cvafrxIDFDdoIQbbPtuv2V4Y?= =?us-ascii?Q?1lOg27OOcC+CN0hJP6ZmXnvt+/TlAPOQxASe+z9aKBmoFLo2RPFF2qKRdi8X?= =?us-ascii?Q?8pLMxWf76AnjttQtSLCG0X3NV/n+wMoQ+goexqS4UbY0MSw/7vQQ7cQG+6E4?= =?us-ascii?Q?vEyy/AQ56gupFm6QlhrYSiGAELZTedCG7DNNNpJ2IEugK6qgPvzqXPksMdPG?= =?us-ascii?Q?x6B2UDMiFZPjoc41M1VKnbbpQd8KSSXhmVJPTNgJONcWaVigVPzIsibS1CLh?= =?us-ascii?Q?hzfLLATrJOWY5mqXy39HA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2BupcDZKgzWflVPvMryyb4TZVZk+651QU4TsVzT6RgCxD0MZPD12rujqGCco0/vJjgT3Kx4=; 7:BdccykMns0aU1mnMChfoUw68A0FGr4ubmKBRHJ4nx6ScZp2hYM5StDKTDT4EVwSwKkEkszY0xDv00iV1y7o4t7VDeLT/INaqQNIOXRrV1ftTUs4Uvwg0t32oVZ7lsUkZqgBha/r9HrVvTsz0uFZkehG80Y/v39qvBJG47L6y8LXTwm7y+EYEaIcNkmw9UdiK0Wry+/SPPsrlG/p/FRJw9ggC4LFXwUGAlv9Y9TuDPGaysTaYDYkZJ6u1Kt0HRaY0 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: microsemi.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2017 17:34:33.0736 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8988f45a-a575-4d51-761c-08d548991948 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: SN1PR0201MB1837 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 --- drivers/scsi/aacraid/commsup.c | 75 ++++++++++++++++++++++++++++++++---------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c index 8966371..2cd880f 100644 --- a/drivers/scsi/aacraid/commsup.c +++ b/drivers/scsi/aacraid/commsup.c @@ -1874,6 +1874,43 @@ 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 = CONTAINER_CHANNEL; + else + 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 = CONTAINER_CHANNEL; + else + 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 +1925,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); } }