]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ses: add reliable slot attribute
authorDan Williams <dan.j.williams@intel.com>
Tue, 30 Dec 2014 22:46:17 +0000 (14:46 -0800)
committerChristoph Hellwig <hch@lst.de>
Fri, 9 Jan 2015 14:44:19 +0000 (15:44 +0100)
The name provided by firmware is in a vendor specific format, publish
the slot number to have a reliable mechanism for identifying slots
across firmware implementations.  If the enclosure does not provide a
slot number fallback to the component number which is guaranteed unique,
and usually mirrors the slot number.

Cleaned up the unused ses_component.desc in the process.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Jens Axboe <axboe@fb.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/misc/enclosure.c
drivers/scsi/ses.c
include/linux/enclosure.h

index 958ee988a1e15e31e3fe434f80c354c3372c5535..b62314d627ae8c593001806c2ddac26a2d349e8e 100644 (file)
@@ -145,8 +145,10 @@ enclosure_register(struct device *dev, const char *name, int components,
        if (err)
                goto err;
 
-       for (i = 0; i < components; i++)
+       for (i = 0; i < components; i++) {
                edev->component[i].number = -1;
+               edev->component[i].slot = -1;
+       }
 
        mutex_lock(&container_list_lock);
        list_add_tail(&edev->node, &container_list);
@@ -589,6 +591,20 @@ static ssize_t get_component_type(struct device *cdev,
        return snprintf(buf, 40, "%s\n", enclosure_type[ecomp->type]);
 }
 
+static ssize_t get_component_slot(struct device *cdev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+       int slot;
+
+       /* if the enclosure does not override then use 'number' as a stand-in */
+       if (ecomp->slot >= 0)
+               slot = ecomp->slot;
+       else
+               slot = ecomp->number;
+
+       return snprintf(buf, 40, "%d\n", slot);
+}
 
 static DEVICE_ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault,
                    set_component_fault);
@@ -599,6 +615,7 @@ static DEVICE_ATTR(active, S_IRUGO | S_IWUSR, get_component_active,
 static DEVICE_ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate,
                   set_component_locate);
 static DEVICE_ATTR(type, S_IRUGO, get_component_type, NULL);
+static DEVICE_ATTR(slot, S_IRUGO, get_component_slot, NULL);
 
 static struct attribute *enclosure_component_attrs[] = {
        &dev_attr_fault.attr,
@@ -606,6 +623,7 @@ static struct attribute *enclosure_component_attrs[] = {
        &dev_attr_active.attr,
        &dev_attr_locate.attr,
        &dev_attr_type.attr,
+       &dev_attr_slot.attr,
        NULL
 };
 ATTRIBUTE_GROUPS(enclosure_component);
index 1041556cdbf3d5b3dc0e510ce57f219588692e33..433de8e6f5387249e8d7b59d076f1817a35409a5 100644 (file)
@@ -47,7 +47,6 @@ struct ses_device {
 
 struct ses_component {
        u64 addr;
-       unsigned char *desc;
 };
 
 static int ses_probe(struct device *dev)
@@ -307,19 +306,26 @@ static void ses_process_descriptor(struct enclosure_component *ecomp,
        int invalid = desc[0] & 0x80;
        enum scsi_protocol proto = desc[0] & 0x0f;
        u64 addr = 0;
+       int slot = -1;
        struct ses_component *scomp = ecomp->scratch;
        unsigned char *d;
 
-       scomp->desc = desc;
-
        if (invalid)
                return;
 
        switch (proto) {
+       case SCSI_PROTOCOL_FCP:
+               if (eip) {
+                       d = desc + 4;
+                       slot = d[3];
+               }
+               break;
        case SCSI_PROTOCOL_SAS:
-               if (eip)
+               if (eip) {
+                       d = desc + 4;
+                       slot = d[3];
                        d = desc + 8;
-               else
+               else
                        d = desc + 4;
                /* only take the phy0 addr */
                addr = (u64)d[12] << 56 |
@@ -335,6 +341,7 @@ static void ses_process_descriptor(struct enclosure_component *ecomp,
                /* FIXME: Need to add more protocols than just SAS */
                break;
        }
+       ecomp->slot = slot;
        scomp->addr = addr;
 }
 
index 807622b252a41ca0332dd5408fe64dd8d886e50a..0f826c14a337a4005e09192407069acaacd9fef3 100644 (file)
@@ -92,6 +92,7 @@ struct enclosure_component {
        int fault;
        int active;
        int locate;
+       int slot;
        enum enclosure_status status;
 };