ata: libata: Add ata_port_classify() helper
authorHannes Reinecke <hare@suse.de>
Tue, 21 Dec 2021 07:20:26 +0000 (08:20 +0100)
committerDamien Le Moal <damien.lemoal@opensource.wdc.com>
Tue, 4 Jan 2022 11:00:45 +0000 (20:00 +0900)
Add an ata_port_classify() helper to print out the results from
the device classification and remove the debugging statements
from ata_dev_classify().

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
drivers/ata/libahci.c
drivers/ata/libata-core.c
drivers/ata/libata-sff.c
drivers/ata/libata-transport.c
drivers/ata/sata_fsl.c
drivers/ata/sata_inic162x.c
drivers/ata/sata_sil24.c
include/linux/libata.h

index 94edbc89a48c61b7cb1963365d8a2d497e706967..b7b460560a92d762b5d8bce32c6ccaf9056b7bf7 100644 (file)
@@ -1300,7 +1300,7 @@ unsigned int ahci_dev_classify(struct ata_port *ap)
        tf.lbal         = (tmp >> 8)    & 0xff;
        tf.nsect        = (tmp)         & 0xff;
 
-       return ata_dev_classify(&tf);
+       return ata_port_classify(ap, &tf);
 }
 EXPORT_SYMBOL_GPL(ahci_dev_classify);
 
index 72f56c32fe833f80f0b15ab283200ba1865f3e2d..28645ac04d9f3695f46d623d4c101c57c8124987 100644 (file)
@@ -1007,32 +1007,21 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
         * SEMB signature.  This is worked around in
         * ata_dev_read_id().
         */
-       if ((tf->lbam == 0) && (tf->lbah == 0)) {
-               DPRINTK("found ATA device by sig\n");
+       if (tf->lbam == 0 && tf->lbah == 0)
                return ATA_DEV_ATA;
-       }
 
-       if ((tf->lbam == 0x14) && (tf->lbah == 0xeb)) {
-               DPRINTK("found ATAPI device by sig\n");
+       if (tf->lbam == 0x14 && tf->lbah == 0xeb)
                return ATA_DEV_ATAPI;
-       }
 
-       if ((tf->lbam == 0x69) && (tf->lbah == 0x96)) {
-               DPRINTK("found PMP device by sig\n");
+       if (tf->lbam == 0x69 && tf->lbah == 0x96)
                return ATA_DEV_PMP;
-       }
 
-       if ((tf->lbam == 0x3c) && (tf->lbah == 0xc3)) {
-               DPRINTK("found SEMB device by sig (could be ATA device)\n");
+       if (tf->lbam == 0x3c && tf->lbah == 0xc3)
                return ATA_DEV_SEMB;
-       }
 
-       if ((tf->lbam == 0xcd) && (tf->lbah == 0xab)) {
-               DPRINTK("found ZAC device by sig\n");
+       if (tf->lbam == 0xcd && tf->lbah == 0xab)
                return ATA_DEV_ZAC;
-       }
 
-       DPRINTK("unknown device\n");
        return ATA_DEV_UNKNOWN;
 }
 EXPORT_SYMBOL_GPL(ata_dev_classify);
index 39c026f3948c2d4ee66d7777b33f0e68a4ea3d8a..a119fabe09193c32edc83ceb270b0119458ec84e 100644 (file)
@@ -1853,7 +1853,7 @@ unsigned int ata_sff_dev_classify(struct ata_device *dev, int present,
                return ATA_DEV_NONE;
 
        /* determine if device is ATA or ATAPI */
-       class = ata_dev_classify(&tf);
+       class = ata_port_classify(ap, &tf);
 
        if (class == ATA_DEV_UNKNOWN) {
                /* If the device failed diagnostic, it's likely to
index 4162d625fc9248c3799ed133f99750079184a1a0..ca129854a88c77a7301ece33fc9d73d3f3b218d6 100644 (file)
@@ -321,6 +321,36 @@ int ata_tport_add(struct device *parent,
        return error;
 }
 
+/**
+ *     ata_port_classify - determine device type based on ATA-spec signature
+ *     @ap: ATA port device on which the classification should be run
+ *     @tf: ATA taskfile register set for device to be identified
+ *
+ *     A wrapper around ata_dev_classify() to provide additional logging
+ *
+ *     RETURNS:
+ *     Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, %ATA_DEV_PMP,
+ *     %ATA_DEV_ZAC, or %ATA_DEV_UNKNOWN the event of failure.
+ */
+unsigned int ata_port_classify(struct ata_port *ap,
+                              const struct ata_taskfile *tf)
+{
+       int i;
+       unsigned int class = ata_dev_classify(tf);
+
+       /* Start with index '1' to skip the 'unknown' entry */
+       for (i = 1; i < ARRAY_SIZE(ata_class_names); i++) {
+               if (ata_class_names[i].value == class) {
+                       ata_port_dbg(ap, "found %s device by sig\n",
+                                    ata_class_names[i].name);
+                       return class;
+               }
+       }
+
+       ata_port_info(ap, "found unknown device (class %u)\n", class);
+       return class;
+}
+EXPORT_SYMBOL_GPL(ata_port_classify);
 
 /*
  * ATA link attributes
index ec52511ae60fc2764461a1cb4fa98668f16df75d..7504d9fbff2a61a2b9c0432c044f78b39f2f3cc0 100644 (file)
@@ -814,7 +814,7 @@ static unsigned int sata_fsl_dev_classify(struct ata_port *ap)
        tf.lbal = (temp >> 8) & 0xff;
        tf.nsect = temp & 0xff;
 
-       return ata_dev_classify(&tf);
+       return ata_port_classify(ap, &tf);
 }
 
 static int sata_fsl_hardreset(struct ata_link *link, unsigned int *class,
index e517bd8822a5faaeef2039a356518ed5a4e970da..b6239dae524a403a5d10a13b2edaf9a37bebe904 100644 (file)
@@ -657,7 +657,7 @@ static int inic_hardreset(struct ata_link *link, unsigned int *class,
                }
 
                inic_tf_read(ap, &tf);
-               *class = ata_dev_classify(&tf);
+               *class = ata_port_classify(ap, &tf);
        }
 
        return 0;
index f99ec6f7d7c07728bc6de1822f20aea3a95e7d0d..7e9c1945dc81fb66ed43c1978d86fa8748118809 100644 (file)
@@ -680,7 +680,7 @@ static int sil24_softreset(struct ata_link *link, unsigned int *class,
        }
 
        sil24_read_tf(ap, 0, &tf);
-       *class = ata_dev_classify(&tf);
+       *class = ata_port_classify(ap, &tf);
 
        DPRINTK("EXIT, class=%u\n", *class);
        return 0;
index 2a8404b26083c0d35265ec4a6106e3cf2d47feab..235fdbeb19eac0fe932d6fe5d1ae1b9b2bd752c0 100644 (file)
@@ -1160,6 +1160,8 @@ extern enum ata_completion_errors ata_noop_qc_prep(struct ata_queued_cmd *qc);
 extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
                 unsigned int n_elem);
 extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
+extern unsigned int ata_port_classify(struct ata_port *ap,
+                                     const struct ata_taskfile *tf);
 extern void ata_dev_disable(struct ata_device *adev);
 extern void ata_id_string(const u16 *id, unsigned char *s,
                          unsigned int ofs, unsigned int len);