cxgb{3,4}*: improve Kconfig dependencies
[linux-2.6.git] / drivers / scsi / scsi_transport_spi.c
index 3a26f74..8a172d4 100644 (file)
@@ -24,6 +24,8 @@
 #include <linux/workqueue.h>
 #include <linux/blkdev.h>
 #include <linux/mutex.h>
+#include <linux/sysfs.h>
+#include <linux/slab.h>
 #include <scsi/scsi.h>
 #include "scsi_priv.h"
 #include <scsi/scsi_device.h>
 #define DV_RETRIES     3       /* should only need at most 
                                 * two cc/ua clears */
 
+/* Our blacklist flags */
+enum {
+       SPI_BLIST_NOIUS = 0x1,
+};
+
+/* blacklist table, modelled on scsi_devinfo.c */
+static struct {
+       char *vendor;
+       char *model;
+       unsigned flags;
+} spi_static_device_list[] __initdata = {
+       {"HP", "Ultrium 3-SCSI", SPI_BLIST_NOIUS },
+       {"IBM", "ULTRIUM-TD3", SPI_BLIST_NOIUS },
+       {NULL, NULL, 0}
+};
+
 /* Private data accessors (keep these out of the header file) */
 #define spi_dv_in_progress(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_in_progress)
 #define spi_dv_mutex(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_mutex)
@@ -108,8 +126,11 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd,
        for(i = 0; i < DV_RETRIES; i++) {
                result = scsi_execute(sdev, cmd, dir, buffer, bufflen,
                                      sense, DV_TIMEOUT, /* retries */ 1,
-                                     REQ_FAILFAST);
-               if (result & DRIVER_SENSE) {
+                                     REQ_FAILFAST_DEV |
+                                     REQ_FAILFAST_TRANSPORT |
+                                     REQ_FAILFAST_DRIVER,
+                                     NULL);
+               if (driver_byte(result) & DRIVER_SENSE) {
                        struct scsi_sense_hdr sshdr_tmp;
                        if (!sshdr)
                                sshdr = &sshdr_tmp;
@@ -203,6 +224,9 @@ static int spi_device_configure(struct transport_container *tc,
 {
        struct scsi_device *sdev = to_scsi_device(dev);
        struct scsi_target *starget = sdev->sdev_target;
+       unsigned bflags = scsi_get_device_flags_keyed(sdev, &sdev->inquiry[8],
+                                                     &sdev->inquiry[16],
+                                                     SCSI_DEVINFO_SPI);
 
        /* Populate the target capability fields with the values
         * gleaned from the device inquiry */
@@ -212,6 +236,10 @@ static int spi_device_configure(struct transport_container *tc,
        spi_support_dt(starget) = scsi_device_dt(sdev);
        spi_support_dt_only(starget) = scsi_device_dt_only(sdev);
        spi_support_ius(starget) = scsi_device_ius(sdev);
+       if (bflags & SPI_BLIST_NOIUS) {
+               dev_info(dev, "Information Units disabled by blacklist\n");
+               spi_support_ius(starget) = 0;
+       }
        spi_support_qas(starget) = scsi_device_qas(sdev);
 
        return 0;
@@ -230,8 +258,10 @@ static int spi_setup_transport_attrs(struct transport_container *tc,
        spi_width(starget) = 0; /* narrow */
        spi_max_width(starget) = 1;
        spi_iu(starget) = 0;    /* no IU */
+       spi_max_iu(starget) = 1;
        spi_dt(starget) = 0;    /* ST */
        spi_qas(starget) = 0;
+       spi_max_qas(starget) = 1;
        spi_wr_flow(starget) = 0;
        spi_rd_strm(starget) = 0;
        spi_rti(starget) = 0;
@@ -356,21 +386,23 @@ static DEVICE_ATTR(field, S_IRUGO,                                \
 /* The Parallel SCSI Tranport Attributes: */
 spi_transport_max_attr(offset, "%d\n");
 spi_transport_max_attr(width, "%d\n");
-spi_transport_rd_attr(iu, "%d\n");
+spi_transport_max_attr(iu, "%d\n");
 spi_transport_rd_attr(dt, "%d\n");
-spi_transport_rd_attr(qas, "%d\n");
+spi_transport_max_attr(qas, "%d\n");
 spi_transport_rd_attr(wr_flow, "%d\n");
 spi_transport_rd_attr(rd_strm, "%d\n");
 spi_transport_rd_attr(rti, "%d\n");
 spi_transport_rd_attr(pcomp_en, "%d\n");
 spi_transport_rd_attr(hold_mcs, "%d\n");
 
-/* we only care about the first child device so we return 1 */
+/* we only care about the first child device that's a real SCSI device
+ * so we return 1 to terminate the iteration when we find it */
 static int child_iter(struct device *dev, void *data)
 {
-       struct scsi_device *sdev = to_scsi_device(dev);
+       if (!scsi_is_sdev_device(dev))
+               return 0;
 
-       spi_dv_device(sdev);
+       spi_dv_device(to_scsi_device(dev));
        return 1;
 }
 
@@ -825,7 +857,7 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer)
                return;
        }
 
-       if (!scsi_device_wide(sdev)) {
+       if (!spi_support_wide(starget)) {
                spi_max_width(starget) = 0;
                max_width = 0;
        }
@@ -852,7 +884,7 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer)
                return;
 
        /* device can't handle synchronous */
-       if (!scsi_device_sync(sdev) && !scsi_device_dt(sdev))
+       if (!spi_support_sync(starget) && !spi_support_dt(starget))
                return;
 
        /* len == -1 is the signal that we need to ascertain the
@@ -868,13 +900,14 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer)
 
        /* try QAS requests; this should be harmless to set if the
         * target supports it */
-       if (scsi_device_qas(sdev)) {
+       if (spi_support_qas(starget) && spi_max_qas(starget)) {
                DV_SET(qas, 1);
        } else {
                DV_SET(qas, 0);
        }
 
-       if (scsi_device_ius(sdev) && min_period < 9) {
+       if (spi_support_ius(starget) && spi_max_iu(starget) &&
+           min_period < 9) {
                /* This u320 (or u640). Set IU transfers */
                DV_SET(iu, 1);
                /* Then set the optional parameters */
@@ -894,7 +927,7 @@ spi_dv_device_internal(struct scsi_device *sdev, u8 *buffer)
                i->f->get_signalling(shost);
        if (spi_signalling(shost) == SPI_SIGNAL_SE ||
            spi_signalling(shost) == SPI_SIGNAL_HVD ||
-           !scsi_device_dt(sdev)) {
+           !spi_support_dt(starget)) {
                DV_SET(dt, 0);
        } else {
                DV_SET(dt, 1);
@@ -1406,12 +1439,18 @@ static mode_t target_attribute_is_visible(struct kobject *kobj,
        else if (attr == &dev_attr_iu.attr &&
                 spi_support_ius(starget))
                return TARGET_ATTRIBUTE_HELPER(iu);
+       else if (attr == &dev_attr_max_iu.attr &&
+                spi_support_ius(starget))
+               return TARGET_ATTRIBUTE_HELPER(iu);
        else if (attr == &dev_attr_dt.attr &&
                 spi_support_dt(starget))
                return TARGET_ATTRIBUTE_HELPER(dt);
        else if (attr == &dev_attr_qas.attr &&
                 spi_support_qas(starget))
                return TARGET_ATTRIBUTE_HELPER(qas);
+       else if (attr == &dev_attr_max_qas.attr &&
+                spi_support_qas(starget))
+               return TARGET_ATTRIBUTE_HELPER(qas);
        else if (attr == &dev_attr_wr_flow.attr &&
                 spi_support_ius(starget))
                return TARGET_ATTRIBUTE_HELPER(wr_flow);
@@ -1441,8 +1480,10 @@ static struct attribute *target_attributes[] = {
        &dev_attr_width.attr,
        &dev_attr_max_width.attr,
        &dev_attr_iu.attr,
+       &dev_attr_max_iu.attr,
        &dev_attr_dt.attr,
        &dev_attr_qas.attr,
+       &dev_attr_max_qas.attr,
        &dev_attr_wr_flow.attr,
        &dev_attr_rd_strm.attr,
        &dev_attr_rti.attr,
@@ -1507,7 +1548,21 @@ EXPORT_SYMBOL(spi_release_transport);
 
 static __init int spi_transport_init(void)
 {
-       int error = transport_class_register(&spi_transport_class);
+       int error = scsi_dev_info_add_list(SCSI_DEVINFO_SPI,
+                                          "SCSI Parallel Transport Class");
+       if (!error) {
+               int i;
+
+               for (i = 0; spi_static_device_list[i].vendor; i++)
+                       scsi_dev_info_list_add_keyed(1, /* compatible */
+                                                    spi_static_device_list[i].vendor,
+                                                    spi_static_device_list[i].model,
+                                                    NULL,
+                                                    spi_static_device_list[i].flags,
+                                                    SCSI_DEVINFO_SPI);
+       }
+
+       error = transport_class_register(&spi_transport_class);
        if (error)
                return error;
        error = anon_transport_class_register(&spi_device_class);
@@ -1519,6 +1574,7 @@ static void __exit spi_transport_exit(void)
        transport_class_unregister(&spi_transport_class);
        anon_transport_class_unregister(&spi_device_class);
        transport_class_unregister(&spi_host_class);
+       scsi_dev_info_remove_list(SCSI_DEVINFO_SPI);
 }
 
 MODULE_AUTHOR("Martin Hicks");