diff options
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
-rw-r--r-- | drivers/scsi/libata-scsi.c | 140 |
1 files changed, 91 insertions, 49 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c index 07b1e7cc61df..2d328b3af067 100644 --- a/drivers/scsi/libata-scsi.c +++ b/drivers/scsi/libata-scsi.c | |||
@@ -151,7 +151,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
151 | struct scsi_sense_hdr sshdr; | 151 | struct scsi_sense_hdr sshdr; |
152 | enum dma_data_direction data_dir; | 152 | enum dma_data_direction data_dir; |
153 | 153 | ||
154 | if (NULL == (void *)arg) | 154 | if (arg == NULL) |
155 | return -EINVAL; | 155 | return -EINVAL; |
156 | 156 | ||
157 | if (copy_from_user(args, arg, sizeof(args))) | 157 | if (copy_from_user(args, arg, sizeof(args))) |
@@ -201,7 +201,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
201 | /* Need code to retrieve data from check condition? */ | 201 | /* Need code to retrieve data from check condition? */ |
202 | 202 | ||
203 | if ((argbuf) | 203 | if ((argbuf) |
204 | && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize)) | 204 | && copy_to_user(arg + sizeof(args), argbuf, argsize)) |
205 | rc = -EFAULT; | 205 | rc = -EFAULT; |
206 | error: | 206 | error: |
207 | if (argbuf) | 207 | if (argbuf) |
@@ -228,7 +228,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
228 | u8 args[7]; | 228 | u8 args[7]; |
229 | struct scsi_sense_hdr sshdr; | 229 | struct scsi_sense_hdr sshdr; |
230 | 230 | ||
231 | if (NULL == (void *)arg) | 231 | if (arg == NULL) |
232 | return -EINVAL; | 232 | return -EINVAL; |
233 | 233 | ||
234 | if (copy_from_user(args, arg, sizeof(args))) | 234 | if (copy_from_user(args, arg, sizeof(args))) |
@@ -738,17 +738,64 @@ int ata_scsi_error(struct Scsi_Host *host) | |||
738 | ap = (struct ata_port *) &host->hostdata[0]; | 738 | ap = (struct ata_port *) &host->hostdata[0]; |
739 | ap->ops->eng_timeout(ap); | 739 | ap->ops->eng_timeout(ap); |
740 | 740 | ||
741 | /* TODO: this is per-command; when queueing is supported | 741 | assert(host->host_failed == 0 && list_empty(&host->eh_cmd_q)); |
742 | * this code will either change or move to a more | 742 | |
743 | * appropriate place | 743 | scsi_eh_flush_done_q(&ap->eh_done_q); |
744 | */ | ||
745 | host->host_failed--; | ||
746 | INIT_LIST_HEAD(&host->eh_cmd_q); | ||
747 | 744 | ||
748 | DPRINTK("EXIT\n"); | 745 | DPRINTK("EXIT\n"); |
749 | return 0; | 746 | return 0; |
750 | } | 747 | } |
751 | 748 | ||
749 | static void ata_eh_scsidone(struct scsi_cmnd *scmd) | ||
750 | { | ||
751 | /* nada */ | ||
752 | } | ||
753 | |||
754 | static void __ata_eh_qc_complete(struct ata_queued_cmd *qc) | ||
755 | { | ||
756 | struct ata_port *ap = qc->ap; | ||
757 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
758 | unsigned long flags; | ||
759 | |||
760 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
761 | qc->scsidone = ata_eh_scsidone; | ||
762 | ata_qc_complete(qc); | ||
763 | assert(!ata_tag_valid(qc->tag)); | ||
764 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
765 | |||
766 | scsi_eh_finish_cmd(scmd, &ap->eh_done_q); | ||
767 | } | ||
768 | |||
769 | /** | ||
770 | * ata_eh_qc_complete - Complete an active ATA command from EH | ||
771 | * @qc: Command to complete | ||
772 | * | ||
773 | * Indicate to the mid and upper layers that an ATA command has | ||
774 | * completed. To be used from EH. | ||
775 | */ | ||
776 | void ata_eh_qc_complete(struct ata_queued_cmd *qc) | ||
777 | { | ||
778 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
779 | scmd->retries = scmd->allowed; | ||
780 | __ata_eh_qc_complete(qc); | ||
781 | } | ||
782 | |||
783 | /** | ||
784 | * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH | ||
785 | * @qc: Command to retry | ||
786 | * | ||
787 | * Indicate to the mid and upper layers that an ATA command | ||
788 | * should be retried. To be used from EH. | ||
789 | * | ||
790 | * SCSI midlayer limits the number of retries to scmd->allowed. | ||
791 | * This function might need to adjust scmd->retries for commands | ||
792 | * which get retried due to unrelated NCQ failures. | ||
793 | */ | ||
794 | void ata_eh_qc_retry(struct ata_queued_cmd *qc) | ||
795 | { | ||
796 | __ata_eh_qc_complete(qc); | ||
797 | } | ||
798 | |||
752 | /** | 799 | /** |
753 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command | 800 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command |
754 | * @qc: Storage for translated ATA taskfile | 801 | * @qc: Storage for translated ATA taskfile |
@@ -985,9 +1032,13 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
985 | if (dev->flags & ATA_DFLAG_LBA) { | 1032 | if (dev->flags & ATA_DFLAG_LBA) { |
986 | tf->flags |= ATA_TFLAG_LBA; | 1033 | tf->flags |= ATA_TFLAG_LBA; |
987 | 1034 | ||
988 | if (dev->flags & ATA_DFLAG_LBA48) { | 1035 | if (lba_28_ok(block, n_block)) { |
989 | if (n_block > (64 * 1024)) | 1036 | /* use LBA28 */ |
990 | goto invalid_fld; | 1037 | tf->command = ATA_CMD_VERIFY; |
1038 | tf->device |= (block >> 24) & 0xf; | ||
1039 | } else if (lba_48_ok(block, n_block)) { | ||
1040 | if (!(dev->flags & ATA_DFLAG_LBA48)) | ||
1041 | goto out_of_range; | ||
991 | 1042 | ||
992 | /* use LBA48 */ | 1043 | /* use LBA48 */ |
993 | tf->flags |= ATA_TFLAG_LBA48; | 1044 | tf->flags |= ATA_TFLAG_LBA48; |
@@ -998,15 +1049,9 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
998 | tf->hob_lbah = (block >> 40) & 0xff; | 1049 | tf->hob_lbah = (block >> 40) & 0xff; |
999 | tf->hob_lbam = (block >> 32) & 0xff; | 1050 | tf->hob_lbam = (block >> 32) & 0xff; |
1000 | tf->hob_lbal = (block >> 24) & 0xff; | 1051 | tf->hob_lbal = (block >> 24) & 0xff; |
1001 | } else { | 1052 | } else |
1002 | if (n_block > 256) | 1053 | /* request too large even for LBA48 */ |
1003 | goto invalid_fld; | 1054 | goto out_of_range; |
1004 | |||
1005 | /* use LBA28 */ | ||
1006 | tf->command = ATA_CMD_VERIFY; | ||
1007 | |||
1008 | tf->device |= (block >> 24) & 0xf; | ||
1009 | } | ||
1010 | 1055 | ||
1011 | tf->nsect = n_block & 0xff; | 1056 | tf->nsect = n_block & 0xff; |
1012 | 1057 | ||
@@ -1019,8 +1064,8 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
1019 | /* CHS */ | 1064 | /* CHS */ |
1020 | u32 sect, head, cyl, track; | 1065 | u32 sect, head, cyl, track; |
1021 | 1066 | ||
1022 | if (n_block > 256) | 1067 | if (!lba_28_ok(block, n_block)) |
1023 | goto invalid_fld; | 1068 | goto out_of_range; |
1024 | 1069 | ||
1025 | /* Convert LBA to CHS */ | 1070 | /* Convert LBA to CHS */ |
1026 | track = (u32)block / dev->sectors; | 1071 | track = (u32)block / dev->sectors; |
@@ -1139,9 +1184,11 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1139 | if (dev->flags & ATA_DFLAG_LBA) { | 1184 | if (dev->flags & ATA_DFLAG_LBA) { |
1140 | tf->flags |= ATA_TFLAG_LBA; | 1185 | tf->flags |= ATA_TFLAG_LBA; |
1141 | 1186 | ||
1142 | if (dev->flags & ATA_DFLAG_LBA48) { | 1187 | if (lba_28_ok(block, n_block)) { |
1143 | /* The request -may- be too large for LBA48. */ | 1188 | /* use LBA28 */ |
1144 | if ((block >> 48) || (n_block > 65536)) | 1189 | tf->device |= (block >> 24) & 0xf; |
1190 | } else if (lba_48_ok(block, n_block)) { | ||
1191 | if (!(dev->flags & ATA_DFLAG_LBA48)) | ||
1145 | goto out_of_range; | 1192 | goto out_of_range; |
1146 | 1193 | ||
1147 | /* use LBA48 */ | 1194 | /* use LBA48 */ |
@@ -1152,15 +1199,9 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1152 | tf->hob_lbah = (block >> 40) & 0xff; | 1199 | tf->hob_lbah = (block >> 40) & 0xff; |
1153 | tf->hob_lbam = (block >> 32) & 0xff; | 1200 | tf->hob_lbam = (block >> 32) & 0xff; |
1154 | tf->hob_lbal = (block >> 24) & 0xff; | 1201 | tf->hob_lbal = (block >> 24) & 0xff; |
1155 | } else { | 1202 | } else |
1156 | /* use LBA28 */ | 1203 | /* request too large even for LBA48 */ |
1157 | 1204 | goto out_of_range; | |
1158 | /* The request -may- be too large for LBA28. */ | ||
1159 | if ((block >> 28) || (n_block > 256)) | ||
1160 | goto out_of_range; | ||
1161 | |||
1162 | tf->device |= (block >> 24) & 0xf; | ||
1163 | } | ||
1164 | 1205 | ||
1165 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) | 1206 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) |
1166 | goto invalid_fld; | 1207 | goto invalid_fld; |
@@ -1178,7 +1219,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1178 | u32 sect, head, cyl, track; | 1219 | u32 sect, head, cyl, track; |
1179 | 1220 | ||
1180 | /* The request -may- be too large for CHS addressing. */ | 1221 | /* The request -may- be too large for CHS addressing. */ |
1181 | if ((block >> 28) || (n_block > 256)) | 1222 | if (!lba_28_ok(block, n_block)) |
1182 | goto out_of_range; | 1223 | goto out_of_range; |
1183 | 1224 | ||
1184 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) | 1225 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) |
@@ -1225,7 +1266,7 @@ nothing_to_do: | |||
1225 | return 1; | 1266 | return 1; |
1226 | } | 1267 | } |
1227 | 1268 | ||
1228 | static int ata_scsi_qc_complete(struct ata_queued_cmd *qc) | 1269 | static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) |
1229 | { | 1270 | { |
1230 | struct scsi_cmnd *cmd = qc->scsicmd; | 1271 | struct scsi_cmnd *cmd = qc->scsicmd; |
1231 | u8 *cdb = cmd->cmnd; | 1272 | u8 *cdb = cmd->cmnd; |
@@ -1262,7 +1303,7 @@ static int ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
1262 | 1303 | ||
1263 | qc->scsidone(cmd); | 1304 | qc->scsidone(cmd); |
1264 | 1305 | ||
1265 | return 0; | 1306 | ata_qc_free(qc); |
1266 | } | 1307 | } |
1267 | 1308 | ||
1268 | /** | 1309 | /** |
@@ -1328,8 +1369,9 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
1328 | goto early_finish; | 1369 | goto early_finish; |
1329 | 1370 | ||
1330 | /* select device, send command to hardware */ | 1371 | /* select device, send command to hardware */ |
1331 | if (ata_qc_issue(qc)) | 1372 | qc->err_mask = ata_qc_issue(qc); |
1332 | goto err_did; | 1373 | if (qc->err_mask) |
1374 | ata_qc_complete(qc); | ||
1333 | 1375 | ||
1334 | VPRINTK("EXIT\n"); | 1376 | VPRINTK("EXIT\n"); |
1335 | return; | 1377 | return; |
@@ -2013,7 +2055,7 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8 | |||
2013 | done(cmd); | 2055 | done(cmd); |
2014 | } | 2056 | } |
2015 | 2057 | ||
2016 | static int atapi_sense_complete(struct ata_queued_cmd *qc) | 2058 | static void atapi_sense_complete(struct ata_queued_cmd *qc) |
2017 | { | 2059 | { |
2018 | if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) | 2060 | if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) |
2019 | /* FIXME: not quite right; we don't want the | 2061 | /* FIXME: not quite right; we don't want the |
@@ -2024,7 +2066,7 @@ static int atapi_sense_complete(struct ata_queued_cmd *qc) | |||
2024 | ata_gen_ata_desc_sense(qc); | 2066 | ata_gen_ata_desc_sense(qc); |
2025 | 2067 | ||
2026 | qc->scsidone(qc->scsicmd); | 2068 | qc->scsidone(qc->scsicmd); |
2027 | return 0; | 2069 | ata_qc_free(qc); |
2028 | } | 2070 | } |
2029 | 2071 | ||
2030 | /* is it pointless to prefer PIO for "safety reasons"? */ | 2072 | /* is it pointless to prefer PIO for "safety reasons"? */ |
@@ -2073,15 +2115,14 @@ static void atapi_request_sense(struct ata_queued_cmd *qc) | |||
2073 | 2115 | ||
2074 | qc->complete_fn = atapi_sense_complete; | 2116 | qc->complete_fn = atapi_sense_complete; |
2075 | 2117 | ||
2076 | if (ata_qc_issue(qc)) { | 2118 | qc->err_mask = ata_qc_issue(qc); |
2077 | qc->err_mask |= AC_ERR_OTHER; | 2119 | if (qc->err_mask) |
2078 | ata_qc_complete(qc); | 2120 | ata_qc_complete(qc); |
2079 | } | ||
2080 | 2121 | ||
2081 | DPRINTK("EXIT\n"); | 2122 | DPRINTK("EXIT\n"); |
2082 | } | 2123 | } |
2083 | 2124 | ||
2084 | static int atapi_qc_complete(struct ata_queued_cmd *qc) | 2125 | static void atapi_qc_complete(struct ata_queued_cmd *qc) |
2085 | { | 2126 | { |
2086 | struct scsi_cmnd *cmd = qc->scsicmd; | 2127 | struct scsi_cmnd *cmd = qc->scsicmd; |
2087 | unsigned int err_mask = qc->err_mask; | 2128 | unsigned int err_mask = qc->err_mask; |
@@ -2091,7 +2132,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2091 | if (unlikely(err_mask & AC_ERR_DEV)) { | 2132 | if (unlikely(err_mask & AC_ERR_DEV)) { |
2092 | cmd->result = SAM_STAT_CHECK_CONDITION; | 2133 | cmd->result = SAM_STAT_CHECK_CONDITION; |
2093 | atapi_request_sense(qc); | 2134 | atapi_request_sense(qc); |
2094 | return 1; | 2135 | return; |
2095 | } | 2136 | } |
2096 | 2137 | ||
2097 | else if (unlikely(err_mask)) | 2138 | else if (unlikely(err_mask)) |
@@ -2131,7 +2172,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2131 | } | 2172 | } |
2132 | 2173 | ||
2133 | qc->scsidone(cmd); | 2174 | qc->scsidone(cmd); |
2134 | return 0; | 2175 | ata_qc_free(qc); |
2135 | } | 2176 | } |
2136 | /** | 2177 | /** |
2137 | * atapi_xlat - Initialize PACKET taskfile | 2178 | * atapi_xlat - Initialize PACKET taskfile |
@@ -2517,7 +2558,8 @@ out_unlock: | |||
2517 | 2558 | ||
2518 | /** | 2559 | /** |
2519 | * ata_scsi_simulate - simulate SCSI command on ATA device | 2560 | * ata_scsi_simulate - simulate SCSI command on ATA device |
2520 | * @id: current IDENTIFY data for target device. | 2561 | * @ap: port the device is connected to |
2562 | * @dev: the target device | ||
2521 | * @cmd: SCSI command being sent to device. | 2563 | * @cmd: SCSI command being sent to device. |
2522 | * @done: SCSI command completion function. | 2564 | * @done: SCSI command completion function. |
2523 | * | 2565 | * |