libata-pmp-prep: implement ops->qc_defer()
[safe/jmp/linux-2.6] / drivers / ata / libata-core.c
index ea8c07b..b666f51 100644 (file)
@@ -59,8 +59,6 @@
 
 #include "libata.h"
 
-#define DRV_VERSION    "2.21"  /* must be exactly four chars */
-
 
 /* debounce timing parameters in msecs { interval, duration, timeout } */
 const unsigned long sata_deb_timing_normal[]           = {   5,  100, 2000 };
@@ -751,10 +749,20 @@ unsigned int ata_dev_try_classify(struct ata_device *dev, int present,
        /* determine if device is ATA or ATAPI */
        class = ata_dev_classify(&tf);
 
-       if (class == ATA_DEV_UNKNOWN)
-               return ATA_DEV_NONE;
-       if ((class == ATA_DEV_ATA) && (ata_chk_status(ap) == 0))
-               return ATA_DEV_NONE;
+       if (class == ATA_DEV_UNKNOWN) {
+               /* If the device failed diagnostic, it's likely to
+                * have reported incorrect device signature too.
+                * Assume ATA device if the device seems present but
+                * device signature is invalid with diagnostic
+                * failure.
+                */
+               if (present && (dev->horkage & ATA_HORKAGE_DIAGNOSTIC))
+                       class = ATA_DEV_ATA;
+               else
+                       class = ATA_DEV_NONE;
+       } else if ((class == ATA_DEV_ATA) && (ata_chk_status(ap) == 0))
+               class = ATA_DEV_NONE;
+
        return class;
 }
 
@@ -2002,7 +2010,8 @@ int ata_dev_configure(struct ata_device *dev)
 
        /* ATAPI-specific feature tests */
        else if (dev->class == ATA_DEV_ATAPI) {
-               char *cdb_intr_string = "";
+               const char *cdb_intr_string = "";
+               const char *atapi_an_string = "";
 
                rc = atapi_cdb_len(id);
                if ((rc < 12) || (rc > ATAPI_CDB_LEN)) {
@@ -2018,16 +2027,19 @@ int ata_dev_configure(struct ata_device *dev)
                 * check to see if this ATAPI device supports
                 * Asynchronous Notification
                 */
-               if ((ap->flags & ATA_FLAG_AN) && ata_id_has_AN(id)) {
-                       int err;
+               if ((ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id)) {
+                       unsigned int err_mask;
+
                        /* issue SET feature command to turn this on */
-                       err = ata_dev_set_AN(dev, SETFEATURES_SATA_ENABLE);
-                       if (err)
+                       err_mask = ata_dev_set_AN(dev, SETFEATURES_SATA_ENABLE);
+                       if (err_mask)
                                ata_dev_printk(dev, KERN_ERR,
-                                               "unable to set AN, err %x\n",
-                                               err);
-                       else
+                                       "failed to enable ATAPI AN "
+                                       "(err_mask=0x%x)\n", err_mask);
+                       else {
                                dev->flags |= ATA_DFLAG_AN;
+                               atapi_an_string = ", ATAPI AN";
+                       }
                }
 
                if (ata_id_cdb_intr(dev->id)) {
@@ -2038,10 +2050,10 @@ int ata_dev_configure(struct ata_device *dev)
                /* print device info to dmesg */
                if (ata_msg_drv(ap) && print_info)
                        ata_dev_printk(dev, KERN_INFO,
-                                      "ATAPI: %s, %s, max %s%s\n",
+                                      "ATAPI: %s, %s, max %s%s%s\n",
                                       modelbuf, fwrevbuf,
                                       ata_mode_string(xfer_mask),
-                                      cdb_intr_string);
+                                      cdb_intr_string, atapi_an_string);
        }
 
        /* determine max_sectors */
@@ -2834,7 +2846,7 @@ static int ata_dev_set_mode(struct ata_device *dev)
        }
 
        ehc->i.flags |= ATA_EHI_POST_SETMODE;
-       rc = ata_dev_revalidate(dev, 0);
+       rc = ata_dev_revalidate(dev, ATA_DEV_UNKNOWN, 0);
        ehc->i.flags &= ~ATA_EHI_POST_SETMODE;
        if (rc)
                return rc;
@@ -3738,6 +3750,7 @@ int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags)
 /**
  *     ata_dev_revalidate - Revalidate ATA device
  *     @dev: device to revalidate
+ *     @new_class: new class code
  *     @readid_flags: read ID flags
  *
  *     Re-read IDENTIFY page, make sure @dev is still attached to the
@@ -3749,7 +3762,8 @@ int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags)
  *     RETURNS:
  *     0 on success, negative errno otherwise
  */
-int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags)
+int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
+                      unsigned int readid_flags)
 {
        u64 n_sectors = dev->n_sectors;
        int rc;
@@ -3757,6 +3771,15 @@ int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags)
        if (!ata_dev_enabled(dev))
                return -ENODEV;
 
+       /* fail early if !ATA && !ATAPI to avoid issuing [P]IDENTIFY to PMP */
+       if (ata_class_enabled(new_class) &&
+           new_class != ATA_DEV_ATA && new_class != ATA_DEV_ATAPI) {
+               ata_dev_printk(dev, KERN_INFO, "class mismatch %u != %u\n",
+                              dev->class, new_class);
+               rc = -ENODEV;
+               goto fail;
+       }
+
        /* re-read ID */
        rc = ata_dev_reread_id(dev, readid_flags);
        if (rc)
@@ -4323,6 +4346,36 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
 }
 
 /**
+ *     ata_std_qc_defer - Check whether a qc needs to be deferred
+ *     @qc: ATA command in question
+ *
+ *     Non-NCQ commands cannot run with any other command, NCQ or
+ *     not.  As upper layer only knows the queue depth, we are
+ *     responsible for maintaining exclusion.  This function checks
+ *     whether a new command @qc can be issued.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ *
+ *     RETURNS:
+ *     ATA_DEFER_* if deferring is needed, 0 otherwise.
+ */
+int ata_std_qc_defer(struct ata_queued_cmd *qc)
+{
+       struct ata_link *link = qc->dev->link;
+
+       if (qc->tf.protocol == ATA_PROT_NCQ) {
+               if (!ata_tag_valid(link->active_tag))
+                       return 0;
+       } else {
+               if (!ata_tag_valid(link->active_tag) && !link->sactive)
+                       return 0;
+       }
+
+       return ATA_DEFER_LINK;
+}
+
+/**
  *     ata_qc_prep - Prepare taskfile for submission
  *     @qc: Metadata associated with taskfile to be prepared
  *
@@ -6195,7 +6248,7 @@ void ata_dev_init(struct ata_device *dev)
  *     LOCKING:
  *     Kernel thread context (may sleep)
  */
-static void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp)
+void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp)
 {
        int i;
 
@@ -6230,7 +6283,7 @@ static void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp)
  *     RETURNS:
  *     0 on success, -errno on failure.
  */
-static int sata_link_init_spd(struct ata_link *link)
+int sata_link_init_spd(struct ata_link *link)
 {
        u32 scontrol, spd;
        int rc;
@@ -7088,6 +7141,7 @@ EXPORT_SYMBOL_GPL(ata_interrupt);
 EXPORT_SYMBOL_GPL(ata_do_set_mode);
 EXPORT_SYMBOL_GPL(ata_data_xfer);
 EXPORT_SYMBOL_GPL(ata_data_xfer_noirq);
+EXPORT_SYMBOL_GPL(ata_std_qc_defer);
 EXPORT_SYMBOL_GPL(ata_qc_prep);
 EXPORT_SYMBOL_GPL(ata_dumb_qc_prep);
 EXPORT_SYMBOL_GPL(ata_noop_qc_prep);