aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-scsi.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-04-12 16:54:16 -0400
committerJeff Garzik <jeff@garzik.org>2006-04-12 16:54:16 -0400
commit875999c5539999f61a45620aae0c3e5fb1d2b035 (patch)
tree4535032a8a10f5782c0aef6a620b1a624ea9f863 /drivers/scsi/libata-scsi.c
parent79072f38909e3d9883317238887460c39ddcc4cb (diff)
parent26ec634c31a11a003040e10b4d650495158632fd (diff)
Merge branch 'upstream'
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
-rw-r--r--drivers/scsi/libata-scsi.c199
1 files changed, 26 insertions, 173 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 410c78795ca8..159537879f7e 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -53,7 +53,6 @@
53typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd); 53typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd);
54static struct ata_device * 54static struct ata_device *
55ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); 55ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev);
56enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
57 56
58#define RW_RECOVERY_MPAGE 0x1 57#define RW_RECOVERY_MPAGE 0x1
59#define RW_RECOVERY_MPAGE_LEN 12 58#define RW_RECOVERY_MPAGE_LEN 12
@@ -99,6 +98,7 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
99 * It just needs the eh_timed_out hook. 98 * It just needs the eh_timed_out hook.
100 */ 99 */
101struct scsi_transport_template ata_scsi_transport_template = { 100struct scsi_transport_template ata_scsi_transport_template = {
101 .eh_strategy_handler = ata_scsi_error,
102 .eh_timed_out = ata_scsi_timed_out, 102 .eh_timed_out = ata_scsi_timed_out,
103}; 103};
104 104
@@ -395,7 +395,7 @@ void ata_dump_status(unsigned id, struct ata_taskfile *tf)
395 395
396int ata_scsi_device_resume(struct scsi_device *sdev) 396int ata_scsi_device_resume(struct scsi_device *sdev)
397{ 397{
398 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0]; 398 struct ata_port *ap = ata_shost_to_port(sdev->host);
399 struct ata_device *dev = &ap->device[sdev->id]; 399 struct ata_device *dev = &ap->device[sdev->id];
400 400
401 return ata_device_resume(ap, dev); 401 return ata_device_resume(ap, dev);
@@ -403,7 +403,7 @@ int ata_scsi_device_resume(struct scsi_device *sdev)
403 403
404int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) 404int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state)
405{ 405{
406 struct ata_port *ap = (struct ata_port *) &sdev->host->hostdata[0]; 406 struct ata_port *ap = ata_shost_to_port(sdev->host);
407 struct ata_device *dev = &ap->device[sdev->id]; 407 struct ata_device *dev = &ap->device[sdev->id];
408 408
409 return ata_device_suspend(ap, dev, state); 409 return ata_device_suspend(ap, dev, state);
@@ -546,16 +546,11 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc)
546 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; 546 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
547 547
548 /* 548 /*
549 * Read the controller registers.
550 */
551 WARN_ON(qc->ap->ops->tf_read == NULL);
552 qc->ap->ops->tf_read(qc->ap, tf);
553
554 /*
555 * Use ata_to_sense_error() to map status register bits 549 * Use ata_to_sense_error() to map status register bits
556 * onto sense key, asc & ascq. 550 * onto sense key, asc & ascq.
557 */ 551 */
558 if (tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { 552 if (qc->err_mask ||
553 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
559 ata_to_sense_error(qc->ap->id, tf->command, tf->feature, 554 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
560 &sb[1], &sb[2], &sb[3]); 555 &sb[1], &sb[2], &sb[3]);
561 sb[1] &= 0x0f; 556 sb[1] &= 0x0f;
@@ -621,16 +616,11 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc)
621 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; 616 cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
622 617
623 /* 618 /*
624 * Read the controller registers.
625 */
626 WARN_ON(qc->ap->ops->tf_read == NULL);
627 qc->ap->ops->tf_read(qc->ap, tf);
628
629 /*
630 * Use ata_to_sense_error() to map status register bits 619 * Use ata_to_sense_error() to map status register bits
631 * onto sense key, asc & ascq. 620 * onto sense key, asc & ascq.
632 */ 621 */
633 if (tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { 622 if (qc->err_mask ||
623 tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) {
634 ata_to_sense_error(qc->ap->id, tf->command, tf->feature, 624 ata_to_sense_error(qc->ap->id, tf->command, tf->feature,
635 &sb[2], &sb[12], &sb[13]); 625 &sb[2], &sb[12], &sb[13]);
636 sb[2] &= 0x0f; 626 sb[2] &= 0x0f;
@@ -714,7 +704,7 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
714 struct ata_port *ap; 704 struct ata_port *ap;
715 struct ata_device *dev; 705 struct ata_device *dev;
716 706
717 ap = (struct ata_port *) &sdev->host->hostdata[0]; 707 ap = ata_shost_to_port(sdev->host);
718 dev = &ap->device[sdev->id]; 708 dev = &ap->device[sdev->id];
719 709
720 ata_scsi_dev_config(sdev, dev); 710 ata_scsi_dev_config(sdev, dev);
@@ -724,141 +714,6 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
724} 714}
725 715
726/** 716/**
727 * ata_scsi_timed_out - SCSI layer time out callback
728 * @cmd: timed out SCSI command
729 *
730 * Handles SCSI layer timeout. We race with normal completion of
731 * the qc for @cmd. If the qc is already gone, we lose and let
732 * the scsi command finish (EH_HANDLED). Otherwise, the qc has
733 * timed out and EH should be invoked. Prevent ata_qc_complete()
734 * from finishing it by setting EH_SCHEDULED and return
735 * EH_NOT_HANDLED.
736 *
737 * LOCKING:
738 * Called from timer context
739 *
740 * RETURNS:
741 * EH_HANDLED or EH_NOT_HANDLED
742 */
743enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
744{
745 struct Scsi_Host *host = cmd->device->host;
746 struct ata_port *ap = (struct ata_port *) &host->hostdata[0];
747 unsigned long flags;
748 struct ata_queued_cmd *qc;
749 enum scsi_eh_timer_return ret = EH_HANDLED;
750
751 DPRINTK("ENTER\n");
752
753 spin_lock_irqsave(&ap->host_set->lock, flags);
754 qc = ata_qc_from_tag(ap, ap->active_tag);
755 if (qc) {
756 WARN_ON(qc->scsicmd != cmd);
757 qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
758 qc->err_mask |= AC_ERR_TIMEOUT;
759 ret = EH_NOT_HANDLED;
760 }
761 spin_unlock_irqrestore(&ap->host_set->lock, flags);
762
763 DPRINTK("EXIT, ret=%d\n", ret);
764 return ret;
765}
766
767/**
768 * ata_scsi_error - SCSI layer error handler callback
769 * @host: SCSI host on which error occurred
770 *
771 * Handles SCSI-layer-thrown error events.
772 *
773 * LOCKING:
774 * Inherited from SCSI layer (none, can sleep)
775 *
776 * RETURNS:
777 * Zero.
778 */
779
780int ata_scsi_error(struct Scsi_Host *host)
781{
782 struct ata_port *ap;
783 unsigned long flags;
784
785 DPRINTK("ENTER\n");
786
787 ap = (struct ata_port *) &host->hostdata[0];
788
789 spin_lock_irqsave(&ap->host_set->lock, flags);
790 WARN_ON(ap->flags & ATA_FLAG_IN_EH);
791 ap->flags |= ATA_FLAG_IN_EH;
792 WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL);
793 spin_unlock_irqrestore(&ap->host_set->lock, flags);
794
795 ata_port_flush_task(ap);
796
797 ap->ops->eng_timeout(ap);
798
799 WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q));
800
801 scsi_eh_flush_done_q(&ap->eh_done_q);
802
803 spin_lock_irqsave(&ap->host_set->lock, flags);
804 ap->flags &= ~ATA_FLAG_IN_EH;
805 spin_unlock_irqrestore(&ap->host_set->lock, flags);
806
807 DPRINTK("EXIT\n");
808 return 0;
809}
810
811static void ata_eh_scsidone(struct scsi_cmnd *scmd)
812{
813 /* nada */
814}
815
816static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
817{
818 struct ata_port *ap = qc->ap;
819 struct scsi_cmnd *scmd = qc->scsicmd;
820 unsigned long flags;
821
822 spin_lock_irqsave(&ap->host_set->lock, flags);
823 qc->scsidone = ata_eh_scsidone;
824 __ata_qc_complete(qc);
825 WARN_ON(ata_tag_valid(qc->tag));
826 spin_unlock_irqrestore(&ap->host_set->lock, flags);
827
828 scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
829}
830
831/**
832 * ata_eh_qc_complete - Complete an active ATA command from EH
833 * @qc: Command to complete
834 *
835 * Indicate to the mid and upper layers that an ATA command has
836 * completed. To be used from EH.
837 */
838void ata_eh_qc_complete(struct ata_queued_cmd *qc)
839{
840 struct scsi_cmnd *scmd = qc->scsicmd;
841 scmd->retries = scmd->allowed;
842 __ata_eh_qc_complete(qc);
843}
844
845/**
846 * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
847 * @qc: Command to retry
848 *
849 * Indicate to the mid and upper layers that an ATA command
850 * should be retried. To be used from EH.
851 *
852 * SCSI midlayer limits the number of retries to scmd->allowed.
853 * This function might need to adjust scmd->retries for commands
854 * which get retried due to unrelated NCQ failures.
855 */
856void ata_eh_qc_retry(struct ata_queued_cmd *qc)
857{
858 __ata_eh_qc_complete(qc);
859}
860
861/**
862 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command 717 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
863 * @qc: Storage for translated ATA taskfile 718 * @qc: Storage for translated ATA taskfile
864 * @scsicmd: SCSI command to translate 719 * @scsicmd: SCSI command to translate
@@ -1197,6 +1052,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1197 u64 block; 1052 u64 block;
1198 u32 n_block; 1053 u32 n_block;
1199 1054
1055 qc->flags |= ATA_QCFLAG_IO;
1200 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 1056 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1201 1057
1202 if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 || 1058 if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 ||
@@ -1343,11 +1199,14 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1343 */ 1199 */
1344 if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && 1200 if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) &&
1345 ((cdb[2] & 0x20) || need_sense)) { 1201 ((cdb[2] & 0x20) || need_sense)) {
1202 qc->ap->ops->tf_read(qc->ap, &qc->tf);
1346 ata_gen_ata_desc_sense(qc); 1203 ata_gen_ata_desc_sense(qc);
1347 } else { 1204 } else {
1348 if (!need_sense) { 1205 if (!need_sense) {
1349 cmd->result = SAM_STAT_GOOD; 1206 cmd->result = SAM_STAT_GOOD;
1350 } else { 1207 } else {
1208 qc->ap->ops->tf_read(qc->ap, &qc->tf);
1209
1351 /* TODO: decide which descriptor format to use 1210 /* TODO: decide which descriptor format to use
1352 * for 48b LBA devices and call that here 1211 * for 48b LBA devices and call that here
1353 * instead of the fixed desc, which is only 1212 * instead of the fixed desc, which is only
@@ -1431,9 +1290,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
1431 goto early_finish; 1290 goto early_finish;
1432 1291
1433 /* select device, send command to hardware */ 1292 /* select device, send command to hardware */
1434 qc->err_mask = ata_qc_issue(qc); 1293 ata_qc_issue(qc);
1435 if (qc->err_mask)
1436 ata_qc_complete(qc);
1437 1294
1438 VPRINTK("EXIT\n"); 1295 VPRINTK("EXIT\n");
1439 return; 1296 return;
@@ -2141,13 +1998,15 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8
2141 1998
2142static void atapi_sense_complete(struct ata_queued_cmd *qc) 1999static void atapi_sense_complete(struct ata_queued_cmd *qc)
2143{ 2000{
2144 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) 2001 if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) {
2145 /* FIXME: not quite right; we don't want the 2002 /* FIXME: not quite right; we don't want the
2146 * translation of taskfile registers into 2003 * translation of taskfile registers into
2147 * a sense descriptors, since that's only 2004 * a sense descriptors, since that's only
2148 * correct for ATA, not ATAPI 2005 * correct for ATA, not ATAPI
2149 */ 2006 */
2007 qc->ap->ops->tf_read(qc->ap, &qc->tf);
2150 ata_gen_ata_desc_sense(qc); 2008 ata_gen_ata_desc_sense(qc);
2009 }
2151 2010
2152 qc->scsidone(qc->scsicmd); 2011 qc->scsidone(qc->scsicmd);
2153 ata_qc_free(qc); 2012 ata_qc_free(qc);
@@ -2199,9 +2058,7 @@ static void atapi_request_sense(struct ata_queued_cmd *qc)
2199 2058
2200 qc->complete_fn = atapi_sense_complete; 2059 qc->complete_fn = atapi_sense_complete;
2201 2060
2202 qc->err_mask = ata_qc_issue(qc); 2061 ata_qc_issue(qc);
2203 if (qc->err_mask)
2204 ata_qc_complete(qc);
2205 2062
2206 DPRINTK("EXIT\n"); 2063 DPRINTK("EXIT\n");
2207} 2064}
@@ -2217,17 +2074,15 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
2217 cmd->result = SAM_STAT_CHECK_CONDITION; 2074 cmd->result = SAM_STAT_CHECK_CONDITION;
2218 atapi_request_sense(qc); 2075 atapi_request_sense(qc);
2219 return; 2076 return;
2220 } 2077 } else if (unlikely(err_mask)) {
2221
2222 else if (unlikely(err_mask))
2223 /* FIXME: not quite right; we don't want the 2078 /* FIXME: not quite right; we don't want the
2224 * translation of taskfile registers into 2079 * translation of taskfile registers into
2225 * a sense descriptors, since that's only 2080 * a sense descriptors, since that's only
2226 * correct for ATA, not ATAPI 2081 * correct for ATA, not ATAPI
2227 */ 2082 */
2083 qc->ap->ops->tf_read(qc->ap, &qc->tf);
2228 ata_gen_ata_desc_sense(qc); 2084 ata_gen_ata_desc_sense(qc);
2229 2085 } else {
2230 else {
2231 u8 *scsicmd = cmd->cmnd; 2086 u8 *scsicmd = cmd->cmnd;
2232 2087
2233 if ((scsicmd[0] == INQUIRY) && ((scsicmd[1] & 0x03) == 0)) { 2088 if ((scsicmd[0] == INQUIRY) && ((scsicmd[1] & 0x03) == 0)) {
@@ -2309,11 +2164,9 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
2309 qc->tf.protocol = ATA_PROT_ATAPI_DMA; 2164 qc->tf.protocol = ATA_PROT_ATAPI_DMA;
2310 qc->tf.feature |= ATAPI_PKT_DMA; 2165 qc->tf.feature |= ATAPI_PKT_DMA;
2311 2166
2312#ifdef ATAPI_ENABLE_DMADIR 2167 if (atapi_dmadir && (cmd->sc_data_direction != DMA_TO_DEVICE))
2313 /* some SATA bridges need us to indicate data xfer direction */ 2168 /* some SATA bridges need us to indicate data xfer direction */
2314 if (cmd->sc_data_direction != DMA_TO_DEVICE)
2315 qc->tf.feature |= ATAPI_DMADIR; 2169 qc->tf.feature |= ATAPI_DMADIR;
2316#endif
2317 } 2170 }
2318 2171
2319 qc->nbytes = cmd->bufflen; 2172 qc->nbytes = cmd->bufflen;
@@ -2353,7 +2206,7 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev)
2353 (scsidev->lun != 0))) 2206 (scsidev->lun != 0)))
2354 return NULL; 2207 return NULL;
2355 2208
2356 if (unlikely(!ata_dev_present(dev))) 2209 if (unlikely(!ata_dev_enabled(dev)))
2357 return NULL; 2210 return NULL;
2358 2211
2359 if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) { 2212 if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) {
@@ -2625,7 +2478,7 @@ int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
2625 struct scsi_device *scsidev = cmd->device; 2478 struct scsi_device *scsidev = cmd->device;
2626 struct Scsi_Host *shost = scsidev->host; 2479 struct Scsi_Host *shost = scsidev->host;
2627 2480
2628 ap = (struct ata_port *) &shost->hostdata[0]; 2481 ap = ata_shost_to_port(shost);
2629 2482
2630 spin_unlock(shost->host_lock); 2483 spin_unlock(shost->host_lock);
2631 spin_lock(&ap->host_set->lock); 2484 spin_lock(&ap->host_set->lock);
@@ -2741,13 +2594,13 @@ void ata_scsi_scan_host(struct ata_port *ap)
2741 struct ata_device *dev; 2594 struct ata_device *dev;
2742 unsigned int i; 2595 unsigned int i;
2743 2596
2744 if (ap->flags & ATA_FLAG_PORT_DISABLED) 2597 if (ap->flags & ATA_FLAG_DISABLED)
2745 return; 2598 return;
2746 2599
2747 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2600 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2748 dev = &ap->device[i]; 2601 dev = &ap->device[i];
2749 2602
2750 if (ata_dev_present(dev)) 2603 if (ata_dev_enabled(dev))
2751 scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0); 2604 scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0);
2752 } 2605 }
2753} 2606}