From patchwork Tue Oct 27 13:08:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sreekanth Reddy X-Patchwork-Id: 287049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_HEADER_CTYPE_ONLY, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, T_TVD_MIME_NO_HEADERS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 293C5C55178 for ; Tue, 27 Oct 2020 13:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAD7320878 for ; Tue, 27 Oct 2020 13:08:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="fZsA3uBB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751865AbgJ0NIl (ORCPT ); Tue, 27 Oct 2020 09:08:41 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:45345 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751852AbgJ0NIl (ORCPT ); Tue, 27 Oct 2020 09:08:41 -0400 Received: by mail-pg1-f196.google.com with SMTP id 15so745118pgd.12 for ; Tue, 27 Oct 2020 06:08:40 -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=hfqCKRckxrrzOwggH/TOoty5GuNnaDCeUHf8tUcMNjQ=; b=fZsA3uBBte8o59It44IPXQ88CgRSqlgE784gkz94HxGMau4atho2iokkxCW7lY2l7R GCf1sNydZT7T3B7GmmRp/DiSttSEz74jvRlVVokYCDWWVhHsEtBRc1znkXdkNLegseZ1 oa9YCT4PMcHtADE2N0RDBeFHmPcqr2UTGsPSM= 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=hfqCKRckxrrzOwggH/TOoty5GuNnaDCeUHf8tUcMNjQ=; b=TNk5PIe6uQLk61HnpZAajpEpGVEFKQkzmV5FTV6YfniXIIGpeMRE2/33usrCezeGBT /UX/4DSI2uQrpeJlq4vyoq9QvnRBR8PU69gnnFP/h2kzvCL11WABJRxY+Vwr/dAhxS3V I5Rwlkr4xOVSx3WqxD4Xd7Ls1afOYbHz7z5F60d6pzPPrYCmlh1NHthDJ9Ow7W+Cuaju uIdofQI0jvoZftnNrUXUZzIz72p3U7yVf4DDoF6g2a9+xwmHz+Sw5ztxvE1wrLNBVQCy zd5jNPi67wSa9Be6AU5YvYXv7Gj0za2Mc3AeRP04LnBgHjT84Orqbbzq5IFeRV0eHGfy h0cg== X-Gm-Message-State: AOAM532xGwufJT9w6tI9TtD799kH4jxe3Xwio27fGZw94/+U7enTLsKw qxyUVbPHjtVeVqIrGZJj1XI6OQ== X-Google-Smtp-Source: ABdhPJy+e5igyUqq7cNuQBUdgYGfOnVYozCJrRP0i1zHQJ0egQO8MzfEWNpfecipjpe4w4CFsHm4pg== X-Received: by 2002:a63:1d53:: with SMTP id d19mr1883905pgm.289.1603804119810; Tue, 27 Oct 2020 06:08:39 -0700 (PDT) Received: from dhcp-10-123-20-36.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id b24sm2009319pge.59.2020.10.27.06.08.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 06:08:39 -0700 (PDT) From: Sreekanth Reddy To: martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, sathya.prakash@broadcom.com, suganath-prabu.subramani@broadcom.com, Sreekanth Reddy Subject: [PATCH v1 07/14] mpt3sas: Get sas_device objects using device's rphy Date: Tue, 27 Oct 2020 18:38:40 +0530 Message-Id: <20201027130847.9962-8-sreekanth.reddy@broadcom.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20201027130847.9962-1-sreekanth.reddy@broadcom.com> References: <20201027130847.9962-1-sreekanth.reddy@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In below scsi_host_template & sas_function_template callback functions, the driver won't have PhysicalPort number information to retrieve the sas_device object using SAS Address & PhysicalPort number. So, in these callback functions the device's rphy object is used to retrieve sas_device object for the device. .target_alloc, .get_enclosure_identifier .get_bay_identifier When a rphy (of type sas_rphy) object is allocated then it's address is saved in corresponding sas_device object's rphy field. so in __mpt3sas_get_sdev_by_rphy(), driver loops over all the sas_device objects from sas_device_list list to retrieve the sas_device objects who's rphy matches with provided rphy. Signed-off-by: Sreekanth Reddy --- v1: No change. drivers/scsi/mpt3sas/mpt3sas_base.h | 5 +++ drivers/scsi/mpt3sas/mpt3sas_scsih.c | 41 ++++++++++++++++++++++-- drivers/scsi/mpt3sas/mpt3sas_transport.c | 7 ++-- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.h b/drivers/scsi/mpt3sas/mpt3sas_base.h index 24db627..047d234 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_base.h +++ b/drivers/scsi/mpt3sas/mpt3sas_base.h @@ -537,6 +537,8 @@ struct _internal_cmd { * @chassis_slot: chassis slot * @is_chassis_slot_valid: chassis slot valid or not * @port: hba port entry containing device's port number info + * @rphy: device's sas_rphy address used to identify this device structure in + * target_alloc callback function */ struct _sas_device { struct list_head list; @@ -564,6 +566,7 @@ struct _sas_device { u8 connector_name[5]; struct kref refcount; struct hba_port *port; + struct sas_rphy *rphy; }; static inline void sas_device_get(struct _sas_device *s) @@ -1681,6 +1684,8 @@ void mpt3sas_port_enable_complete(struct MPT3SAS_ADAPTER *ioc); struct _raid_device * mpt3sas_raid_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle); void mpt3sas_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth); +struct _sas_device * +__mpt3sas_get_sdev_by_rphy(struct MPT3SAS_ADAPTER *ioc, struct sas_rphy *rphy); /* config shared API */ u8 mpt3sas_config_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 4542d66..afb381d 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -638,6 +638,44 @@ mpt3sas_get_pdev_from_target(struct MPT3SAS_ADAPTER *ioc, return ret; } + +/** + * __mpt3sas_get_sdev_by_rphy - sas device search + * @ioc: per adapter object + * @rphy: sas_rphy pointer + * + * Context: This function will acquire ioc->sas_device_lock and will release + * before returning the sas_device object. + * + * This searches for sas_device from rphy object + * then return sas_device object. + */ +struct _sas_device * +__mpt3sas_get_sdev_by_rphy(struct MPT3SAS_ADAPTER *ioc, + struct sas_rphy *rphy) +{ + struct _sas_device *sas_device; + + assert_spin_locked(&ioc->sas_device_lock); + + list_for_each_entry(sas_device, &ioc->sas_device_list, list) { + if (sas_device->rphy != rphy) + continue; + sas_device_get(sas_device); + return sas_device; + } + + sas_device = NULL; + list_for_each_entry(sas_device, &ioc->sas_device_init_list, list) { + if (sas_device->rphy != rphy) + continue; + sas_device_get(sas_device); + return sas_device; + } + + return NULL; +} + /** * mpt3sas_get_sdev_by_addr - get _sas_device object corresponding to provided * sas address from sas_device_list list @@ -1815,8 +1853,7 @@ scsih_target_alloc(struct scsi_target *starget) /* sas/sata devices */ spin_lock_irqsave(&ioc->sas_device_lock, flags); rphy = dev_to_rphy(starget->dev.parent); - sas_device = __mpt3sas_get_sdev_by_addr(ioc, - rphy->identify.sas_address, NULL); + sas_device = __mpt3sas_get_sdev_by_rphy(ioc, rphy); if (sas_device) { sas_target_priv_data->handle = sas_device->handle; diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c index 560ce32..3cc78c2 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_transport.c +++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c @@ -733,6 +733,7 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle, mpt3sas_port->port = port; if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) { rphy = sas_end_device_alloc(port); + sas_device->rphy = rphy; if (sas_node->handle <= ioc->sas_hba.num_phys) hba_port->sas_address = sas_device->sas_address; } else { @@ -1342,8 +1343,7 @@ _transport_get_enclosure_identifier(struct sas_rphy *rphy, u64 *identifier) int rc; spin_lock_irqsave(&ioc->sas_device_lock, flags); - sas_device = __mpt3sas_get_sdev_by_addr(ioc, - rphy->identify.sas_address, 0); + sas_device = __mpt3sas_get_sdev_by_rphy(ioc, rphy); if (sas_device) { *identifier = sas_device->enclosure_logical_id; rc = 0; @@ -1372,8 +1372,7 @@ _transport_get_bay_identifier(struct sas_rphy *rphy) int rc; spin_lock_irqsave(&ioc->sas_device_lock, flags); - sas_device = __mpt3sas_get_sdev_by_addr(ioc, - rphy->identify.sas_address, 0); + sas_device = __mpt3sas_get_sdev_by_rphy(ioc, rphy); if (sas_device) { rc = sas_device->slot; sas_device_put(sas_device);