]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ata/libata-scsi.c
libata-pmp-prep: implement sata_async_notification()
[linux-2.6-omap-h63xx.git] / drivers / ata / libata-scsi.c
index 79550908adccfadab22e70eb6f4165bb91aaa94d..df2e05738f3b3806238e10d5cc78bdb222270217 100644 (file)
@@ -71,11 +71,10 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
 #define ALL_SUB_MPAGES 0xff
 
 
-static const u8 def_rw_recovery_mpage[] = {
+static const u8 def_rw_recovery_mpage[RW_RECOVERY_MPAGE_LEN] = {
        RW_RECOVERY_MPAGE,
        RW_RECOVERY_MPAGE_LEN - 2,
-       (1 << 7) |      /* AWRE, sat-r06 say it shall be 0 */
-           (1 << 6),   /* ARRE (auto read reallocation) */
+       (1 << 7),       /* AWRE */
        0,              /* read retry count */
        0, 0, 0, 0,
        0,              /* write retry count */
@@ -750,6 +749,13 @@ static void ata_scsi_sdev_config(struct scsi_device *sdev)
 {
        sdev->use_10_for_rw = 1;
        sdev->use_10_for_ms = 1;
+
+       /* Schedule policy is determined by ->qc_defer() callback and
+        * it needs to see every deferred qc.  Set dev_blocked to 1 to
+        * prevent SCSI midlayer from automatically deferring
+        * requests.
+        */
+       sdev->max_device_blocked = 1;
 }
 
 static void ata_scsi_dev_config(struct scsi_device *sdev,
@@ -938,6 +944,13 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc)
                goto invalid_fld;       /* LOEJ bit set not supported */
        if (((cdb[4] >> 4) & 0xf) != 0)
                goto invalid_fld;       /* power conditions not supported */
+
+       if (qc->dev->horkage & ATA_HORKAGE_SKIP_PM) {
+               /* the device lacks PM support, finish without doing anything */
+               scmd->result = SAM_STAT_GOOD;
+               return 1;
+       }
+
        if (cdb[4] & 0x1) {
                tf->nsect = 1;  /* 1 sector, lba=0 */
 
@@ -1416,37 +1429,6 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
        ata_qc_free(qc);
 }
 
-/**
- *     ata_scmd_need_defer - Check whether we need to defer scmd
- *     @dev: ATA device to which the command is addressed
- *     @is_io: Is the command IO (and thus possibly NCQ)?
- *
- *     NCQ and non-NCQ commands cannot run together.  As upper layer
- *     only knows the queue depth, we are responsible for maintaining
- *     exclusion.  This function checks whether a new command can be
- *     issued to @dev.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- *
- *     RETURNS:
- *     1 if deferring is needed, 0 otherwise.
- */
-static int ata_scmd_need_defer(struct ata_device *dev, int is_io)
-{
-       struct ata_link *link = dev->link;
-       int is_ncq = is_io && ata_ncq_enabled(dev);
-
-       if (is_ncq) {
-               if (!ata_tag_valid(link->active_tag))
-                       return 0;
-       } else {
-               if (!ata_tag_valid(link->active_tag) && !link->sactive)
-                       return 0;
-       }
-       return 1;
-}
-
 /**
  *     ata_scsi_translate - Translate then issue SCSI command to ATA device
  *     @dev: ATA device to which the command is addressed
@@ -1478,14 +1460,12 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
                              void (*done)(struct scsi_cmnd *),
                              ata_xlat_func_t xlat_func)
 {
+       struct ata_port *ap = dev->link->ap;
        struct ata_queued_cmd *qc;
-       int is_io = xlat_func == ata_scsi_rw_xlat;
+       int rc;
 
        VPRINTK("ENTER\n");
 
-       if (unlikely(ata_scmd_need_defer(dev, is_io)))
-               goto defer;
-
        qc = ata_scsi_qc_new(dev, cmd, done);
        if (!qc)
                goto err_mem;
@@ -1509,6 +1489,11 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
        if (xlat_func(qc))
                goto early_finish;
 
+       if (ap->ops->qc_defer) {
+               if ((rc = ap->ops->qc_defer(qc)))
+                       goto defer;
+       }
+
        /* select device, send command to hardware */
        ata_qc_issue(qc);
 
@@ -1530,8 +1515,12 @@ err_mem:
        return 0;
 
 defer:
+       ata_qc_free(qc);
        DPRINTK("EXIT - defer\n");
-       return SCSI_MLQUEUE_DEVICE_BUSY;
+       if (rc == ATA_DEFER_LINK)
+               return SCSI_MLQUEUE_DEVICE_BUSY;
+       else
+               return SCSI_MLQUEUE_HOST_BUSY;
 }
 
 /**
@@ -1832,8 +1821,9 @@ unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf,
        pbuf[2] = (0x238 >> 8);         /* page size fixed at 238h */
        pbuf[3] = (0x238 & 0xff);
 
-       memcpy(&pbuf[8], "ATA     ", 8);
-       ata_id_string(args->id, &pbuf[16], ATA_ID_PROD, 16);
+       memcpy(&pbuf[8], "linux   ", 8);
+       memcpy(&pbuf[16], "libata          ", 16);
+       memcpy(&pbuf[32], DRV_VERSION, 4);
        ata_id_string(args->id, &pbuf[32], ATA_ID_FW_REV, 4);
 
        /* we don't store the ATA device signature, so we fake it */
@@ -2920,14 +2910,9 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
        args.done = done;
 
        switch(scsicmd[0]) {
-               /* no-op's, complete with success */
-               case SYNCHRONIZE_CACHE:
-               case REZERO_UNIT:
-               case SEEK_6:
-               case SEEK_10:
-               case TEST_UNIT_READY:
-               case FORMAT_UNIT:               /* FIXME: correct? */
-                       ata_scsi_rbuf_fill(&args, ata_scsiop_noop);
+               /* TODO: worth improving? */
+               case FORMAT_UNIT:
+                       ata_scsi_invalid_field(cmd, done);
                        break;
 
                case INQUIRY:
@@ -2985,6 +2970,20 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
                        done(cmd);
                        break;
 
+               /* if we reach this, then writeback caching is disabled,
+                * turning this into a no-op.
+                */
+               case SYNCHRONIZE_CACHE:
+                       /* fall through */
+
+               /* no-op's, complete with success */
+               case REZERO_UNIT:
+               case SEEK_6:
+               case SEEK_10:
+               case TEST_UNIT_READY:
+                       ata_scsi_rbuf_fill(&args, ata_scsiop_noop);
+                       break;
+
                case SEND_DIAGNOSTIC:
                        tmp8 = scsicmd[1] & ~(1 << 3);
                        if ((tmp8 == 0x4) && (!scsicmd[3]) && (!scsicmd[4]))
@@ -3025,6 +3024,13 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
                shost->max_channel = 1;
                shost->max_cmd_len = 16;
 
+               /* Schedule policy is determined by ->qc_defer()
+                * callback and it needs to see every deferred qc.
+                * Set host_blocked to 1 to prevent SCSI midlayer from
+                * automatically deferring requests.
+                */
+               shost->max_host_blocked = 1;
+
                rc = scsi_add_host(ap->scsi_host, ap->host->dev);
                if (rc)
                        goto err_add;
@@ -3229,15 +3235,15 @@ static void ata_scsi_handle_link_detach(struct ata_link *link)
  *     event.
  *
  *     LOCKING:
- *     interrupt context, may not sleep.
+ *     spin_lock_irqsave(host lock)
  */
-void ata_scsi_media_change_notify(struct ata_device *atadev)
+void ata_scsi_media_change_notify(struct ata_device *dev)
 {
 #ifdef OTHER_AN_PATCHES_HAVE_BEEN_APPLIED
-       scsi_device_event_notify(atadev->sdev, SDEV_MEDIA_CHANGE);
+       if (dev->sdev)
+               scsi_device_event_notify(dev->sdev, SDEV_MEDIA_CHANGE);
 #endif
 }
-EXPORT_SYMBOL_GPL(ata_scsi_media_change_notify);
 
 /**
  *     ata_scsi_hotplug - SCSI part of hotplug