]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
scsi: mpt3sas: Get sas_device objects using device's rphy
authorSreekanth Reddy <sreekanth.reddy@broadcom.com>
Tue, 27 Oct 2020 13:08:40 +0000 (18:38 +0530)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Mon, 18 Jan 2021 16:26:12 +0000 (17:26 +0100)
BugLink: https://bugs.launchpad.net/bugs/1899802
In the following scsi_host_template and sas_function_template callback
functions the driver does not have PhysicalPort number information to
retrieve the sas_device object using SAS Address & PhysicalPort number. 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 its address is
saved in corresponding sas_device object's rphy field. In
__mpt3sas_get_sdev_by_rphy(), the driver loops over all the sas_device
objects from sas_device_list list to retrieve the sas_device objects whose
rphy matches the provided rphy.

Link: https://lore.kernel.org/r/20201027130847.9962-8-sreekanth.reddy@broadcom.com
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
(cherry picked from commit 6df6be9168f50369ba843f2a12fe8537effbaff1)
Signed-off-by: Michael Reed <Michael.Reed@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Ian May <ian.may@canonical.com>
drivers/scsi/mpt3sas/mpt3sas_base.h
drivers/scsi/mpt3sas/mpt3sas_scsih.c
drivers/scsi/mpt3sas/mpt3sas_transport.c

index 0bf7adde1c4704d3328cbb2ebfe0184fe537a81a..a28a07f1cb97ad28d3b26e436b170cfec770224d 100644 (file)
@@ -536,6 +536,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;
@@ -563,6 +565,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)
@@ -1666,6 +1669,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,
index fe38d6406fd66fdbcd276a2c6cafb55aef17eee8..955d2770a8db1bd3faad83ef8373d20550e40956 100644 (file)
@@ -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
@@ -1755,8 +1793,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;
index 560ce323646f19c6dcff727ea268447c9dd15de6..3cc78c214ec47c8a135e6ef68244af2b2ad89ad7 100644 (file)
@@ -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);