diff options
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
-rw-r--r-- | drivers/scsi/libata-scsi.c | 179 |
1 files changed, 19 insertions, 160 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c index a0289ec3e283..5ae7613bc157 100644 --- a/drivers/scsi/libata-scsi.c +++ b/drivers/scsi/libata-scsi.c | |||
@@ -53,8 +53,6 @@ | |||
53 | typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd); | 53 | typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd); |
54 | static struct ata_device * | 54 | static struct ata_device * |
55 | ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); | 55 | ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); |
56 | static void ata_scsi_error(struct Scsi_Host *host); | ||
57 | enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); | ||
58 | 56 | ||
59 | #define RW_RECOVERY_MPAGE 0x1 | 57 | #define RW_RECOVERY_MPAGE 0x1 |
60 | #define RW_RECOVERY_MPAGE_LEN 12 | 58 | #define RW_RECOVERY_MPAGE_LEN 12 |
@@ -548,16 +546,11 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | |||
548 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | 546 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; |
549 | 547 | ||
550 | /* | 548 | /* |
551 | * Read the controller registers. | ||
552 | */ | ||
553 | WARN_ON(qc->ap->ops->tf_read == NULL); | ||
554 | qc->ap->ops->tf_read(qc->ap, tf); | ||
555 | |||
556 | /* | ||
557 | * Use ata_to_sense_error() to map status register bits | 549 | * Use ata_to_sense_error() to map status register bits |
558 | * onto sense key, asc & ascq. | 550 | * onto sense key, asc & ascq. |
559 | */ | 551 | */ |
560 | 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)) { | ||
561 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, | 554 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, |
562 | &sb[1], &sb[2], &sb[3]); | 555 | &sb[1], &sb[2], &sb[3]); |
563 | sb[1] &= 0x0f; | 556 | sb[1] &= 0x0f; |
@@ -623,16 +616,11 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc) | |||
623 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | 616 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; |
624 | 617 | ||
625 | /* | 618 | /* |
626 | * Read the controller registers. | ||
627 | */ | ||
628 | WARN_ON(qc->ap->ops->tf_read == NULL); | ||
629 | qc->ap->ops->tf_read(qc->ap, tf); | ||
630 | |||
631 | /* | ||
632 | * Use ata_to_sense_error() to map status register bits | 619 | * Use ata_to_sense_error() to map status register bits |
633 | * onto sense key, asc & ascq. | 620 | * onto sense key, asc & ascq. |
634 | */ | 621 | */ |
635 | 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)) { | ||
636 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, | 624 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, |
637 | &sb[2], &sb[12], &sb[13]); | 625 | &sb[2], &sb[12], &sb[13]); |
638 | sb[2] &= 0x0f; | 626 | sb[2] &= 0x0f; |
@@ -726,137 +714,6 @@ int ata_scsi_slave_config(struct scsi_device *sdev) | |||
726 | } | 714 | } |
727 | 715 | ||
728 | /** | 716 | /** |
729 | * ata_scsi_timed_out - SCSI layer time out callback | ||
730 | * @cmd: timed out SCSI command | ||
731 | * | ||
732 | * Handles SCSI layer timeout. We race with normal completion of | ||
733 | * the qc for @cmd. If the qc is already gone, we lose and let | ||
734 | * the scsi command finish (EH_HANDLED). Otherwise, the qc has | ||
735 | * timed out and EH should be invoked. Prevent ata_qc_complete() | ||
736 | * from finishing it by setting EH_SCHEDULED and return | ||
737 | * EH_NOT_HANDLED. | ||
738 | * | ||
739 | * LOCKING: | ||
740 | * Called from timer context | ||
741 | * | ||
742 | * RETURNS: | ||
743 | * EH_HANDLED or EH_NOT_HANDLED | ||
744 | */ | ||
745 | enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd) | ||
746 | { | ||
747 | struct Scsi_Host *host = cmd->device->host; | ||
748 | struct ata_port *ap = (struct ata_port *) &host->hostdata[0]; | ||
749 | unsigned long flags; | ||
750 | struct ata_queued_cmd *qc; | ||
751 | enum scsi_eh_timer_return ret = EH_HANDLED; | ||
752 | |||
753 | DPRINTK("ENTER\n"); | ||
754 | |||
755 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
756 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
757 | if (qc) { | ||
758 | WARN_ON(qc->scsicmd != cmd); | ||
759 | qc->flags |= ATA_QCFLAG_EH_SCHEDULED; | ||
760 | qc->err_mask |= AC_ERR_TIMEOUT; | ||
761 | ret = EH_NOT_HANDLED; | ||
762 | } | ||
763 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
764 | |||
765 | DPRINTK("EXIT, ret=%d\n", ret); | ||
766 | return ret; | ||
767 | } | ||
768 | |||
769 | /** | ||
770 | * ata_scsi_error - SCSI layer error handler callback | ||
771 | * @host: SCSI host on which error occurred | ||
772 | * | ||
773 | * Handles SCSI-layer-thrown error events. | ||
774 | * | ||
775 | * LOCKING: | ||
776 | * Inherited from SCSI layer (none, can sleep) | ||
777 | */ | ||
778 | |||
779 | static void ata_scsi_error(struct Scsi_Host *host) | ||
780 | { | ||
781 | struct ata_port *ap; | ||
782 | unsigned long flags; | ||
783 | |||
784 | DPRINTK("ENTER\n"); | ||
785 | |||
786 | ap = (struct ata_port *) &host->hostdata[0]; | ||
787 | |||
788 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
789 | WARN_ON(ap->flags & ATA_FLAG_IN_EH); | ||
790 | ap->flags |= ATA_FLAG_IN_EH; | ||
791 | WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL); | ||
792 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
793 | |||
794 | ata_port_flush_task(ap); | ||
795 | |||
796 | ap->ops->eng_timeout(ap); | ||
797 | |||
798 | WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q)); | ||
799 | |||
800 | scsi_eh_flush_done_q(&ap->eh_done_q); | ||
801 | |||
802 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
803 | ap->flags &= ~ATA_FLAG_IN_EH; | ||
804 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
805 | |||
806 | DPRINTK("EXIT\n"); | ||
807 | } | ||
808 | |||
809 | static void ata_eh_scsidone(struct scsi_cmnd *scmd) | ||
810 | { | ||
811 | /* nada */ | ||
812 | } | ||
813 | |||
814 | static void __ata_eh_qc_complete(struct ata_queued_cmd *qc) | ||
815 | { | ||
816 | struct ata_port *ap = qc->ap; | ||
817 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
818 | unsigned long flags; | ||
819 | |||
820 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
821 | qc->scsidone = ata_eh_scsidone; | ||
822 | __ata_qc_complete(qc); | ||
823 | WARN_ON(ata_tag_valid(qc->tag)); | ||
824 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
825 | |||
826 | scsi_eh_finish_cmd(scmd, &ap->eh_done_q); | ||
827 | } | ||
828 | |||
829 | /** | ||
830 | * ata_eh_qc_complete - Complete an active ATA command from EH | ||
831 | * @qc: Command to complete | ||
832 | * | ||
833 | * Indicate to the mid and upper layers that an ATA command has | ||
834 | * completed. To be used from EH. | ||
835 | */ | ||
836 | void ata_eh_qc_complete(struct ata_queued_cmd *qc) | ||
837 | { | ||
838 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
839 | scmd->retries = scmd->allowed; | ||
840 | __ata_eh_qc_complete(qc); | ||
841 | } | ||
842 | |||
843 | /** | ||
844 | * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH | ||
845 | * @qc: Command to retry | ||
846 | * | ||
847 | * Indicate to the mid and upper layers that an ATA command | ||
848 | * should be retried. To be used from EH. | ||
849 | * | ||
850 | * SCSI midlayer limits the number of retries to scmd->allowed. | ||
851 | * This function might need to adjust scmd->retries for commands | ||
852 | * which get retried due to unrelated NCQ failures. | ||
853 | */ | ||
854 | void ata_eh_qc_retry(struct ata_queued_cmd *qc) | ||
855 | { | ||
856 | __ata_eh_qc_complete(qc); | ||
857 | } | ||
858 | |||
859 | /** | ||
860 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command | 717 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command |
861 | * @qc: Storage for translated ATA taskfile | 718 | * @qc: Storage for translated ATA taskfile |
862 | * @scsicmd: SCSI command to translate | 719 | * @scsicmd: SCSI command to translate |
@@ -1195,6 +1052,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1195 | u64 block; | 1052 | u64 block; |
1196 | u32 n_block; | 1053 | u32 n_block; |
1197 | 1054 | ||
1055 | qc->flags |= ATA_QCFLAG_IO; | ||
1198 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | 1056 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
1199 | 1057 | ||
1200 | if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 || | 1058 | if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 || |
@@ -1341,11 +1199,14 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
1341 | */ | 1199 | */ |
1342 | if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && | 1200 | if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && |
1343 | ((cdb[2] & 0x20) || need_sense)) { | 1201 | ((cdb[2] & 0x20) || need_sense)) { |
1202 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
1344 | ata_gen_ata_desc_sense(qc); | 1203 | ata_gen_ata_desc_sense(qc); |
1345 | } else { | 1204 | } else { |
1346 | if (!need_sense) { | 1205 | if (!need_sense) { |
1347 | cmd->result = SAM_STAT_GOOD; | 1206 | cmd->result = SAM_STAT_GOOD; |
1348 | } else { | 1207 | } else { |
1208 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
1209 | |||
1349 | /* TODO: decide which descriptor format to use | 1210 | /* TODO: decide which descriptor format to use |
1350 | * for 48b LBA devices and call that here | 1211 | * for 48b LBA devices and call that here |
1351 | * instead of the fixed desc, which is only | 1212 | * instead of the fixed desc, which is only |
@@ -2137,13 +1998,15 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8 | |||
2137 | 1998 | ||
2138 | static void atapi_sense_complete(struct ata_queued_cmd *qc) | 1999 | static void atapi_sense_complete(struct ata_queued_cmd *qc) |
2139 | { | 2000 | { |
2140 | if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) | 2001 | if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) { |
2141 | /* FIXME: not quite right; we don't want the | 2002 | /* FIXME: not quite right; we don't want the |
2142 | * translation of taskfile registers into | 2003 | * translation of taskfile registers into |
2143 | * a sense descriptors, since that's only | 2004 | * a sense descriptors, since that's only |
2144 | * correct for ATA, not ATAPI | 2005 | * correct for ATA, not ATAPI |
2145 | */ | 2006 | */ |
2007 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
2146 | ata_gen_ata_desc_sense(qc); | 2008 | ata_gen_ata_desc_sense(qc); |
2009 | } | ||
2147 | 2010 | ||
2148 | qc->scsidone(qc->scsicmd); | 2011 | qc->scsidone(qc->scsicmd); |
2149 | ata_qc_free(qc); | 2012 | ata_qc_free(qc); |
@@ -2211,17 +2074,15 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2211 | cmd->result = SAM_STAT_CHECK_CONDITION; | 2074 | cmd->result = SAM_STAT_CHECK_CONDITION; |
2212 | atapi_request_sense(qc); | 2075 | atapi_request_sense(qc); |
2213 | return; | 2076 | return; |
2214 | } | 2077 | } else if (unlikely(err_mask)) { |
2215 | |||
2216 | else if (unlikely(err_mask)) | ||
2217 | /* FIXME: not quite right; we don't want the | 2078 | /* FIXME: not quite right; we don't want the |
2218 | * translation of taskfile registers into | 2079 | * translation of taskfile registers into |
2219 | * a sense descriptors, since that's only | 2080 | * a sense descriptors, since that's only |
2220 | * correct for ATA, not ATAPI | 2081 | * correct for ATA, not ATAPI |
2221 | */ | 2082 | */ |
2083 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
2222 | ata_gen_ata_desc_sense(qc); | 2084 | ata_gen_ata_desc_sense(qc); |
2223 | 2085 | } else { | |
2224 | else { | ||
2225 | u8 *scsicmd = cmd->cmnd; | 2086 | u8 *scsicmd = cmd->cmnd; |
2226 | 2087 | ||
2227 | if ((scsicmd[0] == INQUIRY) && ((scsicmd[1] & 0x03) == 0)) { | 2088 | if ((scsicmd[0] == INQUIRY) && ((scsicmd[1] & 0x03) == 0)) { |
@@ -2303,11 +2164,9 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd) | |||
2303 | qc->tf.protocol = ATA_PROT_ATAPI_DMA; | 2164 | qc->tf.protocol = ATA_PROT_ATAPI_DMA; |
2304 | qc->tf.feature |= ATAPI_PKT_DMA; | 2165 | qc->tf.feature |= ATAPI_PKT_DMA; |
2305 | 2166 | ||
2306 | #ifdef ATAPI_ENABLE_DMADIR | 2167 | if (atapi_dmadir && (cmd->sc_data_direction != DMA_TO_DEVICE)) |
2307 | /* some SATA bridges need us to indicate data xfer direction */ | 2168 | /* some SATA bridges need us to indicate data xfer direction */ |
2308 | if (cmd->sc_data_direction != DMA_TO_DEVICE) | ||
2309 | qc->tf.feature |= ATAPI_DMADIR; | 2169 | qc->tf.feature |= ATAPI_DMADIR; |
2310 | #endif | ||
2311 | } | 2170 | } |
2312 | 2171 | ||
2313 | qc->nbytes = cmd->bufflen; | 2172 | qc->nbytes = cmd->bufflen; |
@@ -2347,7 +2206,7 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev) | |||
2347 | (scsidev->lun != 0))) | 2206 | (scsidev->lun != 0))) |
2348 | return NULL; | 2207 | return NULL; |
2349 | 2208 | ||
2350 | if (unlikely(!ata_dev_present(dev))) | 2209 | if (unlikely(!ata_dev_enabled(dev))) |
2351 | return NULL; | 2210 | return NULL; |
2352 | 2211 | ||
2353 | if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) { | 2212 | if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) { |
@@ -2735,13 +2594,13 @@ void ata_scsi_scan_host(struct ata_port *ap) | |||
2735 | struct ata_device *dev; | 2594 | struct ata_device *dev; |
2736 | unsigned int i; | 2595 | unsigned int i; |
2737 | 2596 | ||
2738 | if (ap->flags & ATA_FLAG_PORT_DISABLED) | 2597 | if (ap->flags & ATA_FLAG_DISABLED) |
2739 | return; | 2598 | return; |
2740 | 2599 | ||
2741 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2600 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
2742 | dev = &ap->device[i]; | 2601 | dev = &ap->device[i]; |
2743 | 2602 | ||
2744 | if (ata_dev_present(dev)) | 2603 | if (ata_dev_enabled(dev)) |
2745 | scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0); | 2604 | scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0); |
2746 | } | 2605 | } |
2747 | } | 2606 | } |