diff options
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
| -rw-r--r-- | drivers/scsi/libata-scsi.c | 272 |
1 files changed, 218 insertions, 54 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c index 9871f8272df0..996058af1bcd 100644 --- a/drivers/scsi/libata-scsi.c +++ b/drivers/scsi/libata-scsi.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include <scsi/scsi_eh.h> | 41 | #include <scsi/scsi_eh.h> |
| 42 | #include <scsi/scsi_device.h> | 42 | #include <scsi/scsi_device.h> |
| 43 | #include <scsi/scsi_request.h> | 43 | #include <scsi/scsi_request.h> |
| 44 | #include <scsi/scsi_tcq.h> | ||
| 44 | #include <scsi/scsi_transport.h> | 45 | #include <scsi/scsi_transport.h> |
| 45 | #include <linux/libata.h> | 46 | #include <linux/libata.h> |
| 46 | #include <linux/hdreg.h> | 47 | #include <linux/hdreg.h> |
| @@ -302,7 +303,6 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) | |||
| 302 | 303 | ||
| 303 | /** | 304 | /** |
| 304 | * ata_scsi_qc_new - acquire new ata_queued_cmd reference | 305 | * ata_scsi_qc_new - acquire new ata_queued_cmd reference |
| 305 | * @ap: ATA port to which the new command is attached | ||
| 306 | * @dev: ATA device to which the new command is attached | 306 | * @dev: ATA device to which the new command is attached |
| 307 | * @cmd: SCSI command that originated this ATA command | 307 | * @cmd: SCSI command that originated this ATA command |
| 308 | * @done: SCSI command completion function | 308 | * @done: SCSI command completion function |
| @@ -321,14 +321,13 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) | |||
| 321 | * RETURNS: | 321 | * RETURNS: |
| 322 | * Command allocated, or %NULL if none available. | 322 | * Command allocated, or %NULL if none available. |
| 323 | */ | 323 | */ |
| 324 | struct ata_queued_cmd *ata_scsi_qc_new(struct ata_port *ap, | 324 | struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev, |
| 325 | struct ata_device *dev, | ||
| 326 | struct scsi_cmnd *cmd, | 325 | struct scsi_cmnd *cmd, |
| 327 | void (*done)(struct scsi_cmnd *)) | 326 | void (*done)(struct scsi_cmnd *)) |
| 328 | { | 327 | { |
| 329 | struct ata_queued_cmd *qc; | 328 | struct ata_queued_cmd *qc; |
| 330 | 329 | ||
| 331 | qc = ata_qc_new_init(ap, dev); | 330 | qc = ata_qc_new_init(dev); |
| 332 | if (qc) { | 331 | if (qc) { |
| 333 | qc->scsicmd = cmd; | 332 | qc->scsicmd = cmd; |
| 334 | qc->scsidone = done; | 333 | qc->scsidone = done; |
| @@ -398,7 +397,7 @@ int ata_scsi_device_resume(struct scsi_device *sdev) | |||
| 398 | struct ata_port *ap = ata_shost_to_port(sdev->host); | 397 | struct ata_port *ap = ata_shost_to_port(sdev->host); |
| 399 | struct ata_device *dev = &ap->device[sdev->id]; | 398 | struct ata_device *dev = &ap->device[sdev->id]; |
| 400 | 399 | ||
| 401 | return ata_device_resume(ap, dev); | 400 | return ata_device_resume(dev); |
| 402 | } | 401 | } |
| 403 | 402 | ||
| 404 | int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) | 403 | int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) |
| @@ -406,7 +405,7 @@ int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) | |||
| 406 | struct ata_port *ap = ata_shost_to_port(sdev->host); | 405 | struct ata_port *ap = ata_shost_to_port(sdev->host); |
| 407 | struct ata_device *dev = &ap->device[sdev->id]; | 406 | struct ata_device *dev = &ap->device[sdev->id]; |
| 408 | 407 | ||
| 409 | return ata_device_suspend(ap, dev, state); | 408 | return ata_device_suspend(dev, state); |
| 410 | } | 409 | } |
| 411 | 410 | ||
| 412 | /** | 411 | /** |
| @@ -417,6 +416,7 @@ int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) | |||
| 417 | * @sk: the sense key we'll fill out | 416 | * @sk: the sense key we'll fill out |
| 418 | * @asc: the additional sense code we'll fill out | 417 | * @asc: the additional sense code we'll fill out |
| 419 | * @ascq: the additional sense code qualifier we'll fill out | 418 | * @ascq: the additional sense code qualifier we'll fill out |
| 419 | * @verbose: be verbose | ||
| 420 | * | 420 | * |
| 421 | * Converts an ATA error into a SCSI error. Fill out pointers to | 421 | * Converts an ATA error into a SCSI error. Fill out pointers to |
| 422 | * SK, ASC, and ASCQ bytes for later use in fixed or descriptor | 422 | * SK, ASC, and ASCQ bytes for later use in fixed or descriptor |
| @@ -426,7 +426,7 @@ int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t state) | |||
| 426 | * spin_lock_irqsave(host_set lock) | 426 | * spin_lock_irqsave(host_set lock) |
| 427 | */ | 427 | */ |
| 428 | void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | 428 | void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, |
| 429 | u8 *ascq) | 429 | u8 *ascq, int verbose) |
| 430 | { | 430 | { |
| 431 | int i; | 431 | int i; |
| 432 | 432 | ||
| @@ -491,8 +491,9 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | |||
| 491 | } | 491 | } |
| 492 | } | 492 | } |
| 493 | /* No immediate match */ | 493 | /* No immediate match */ |
| 494 | printk(KERN_WARNING "ata%u: no sense translation for " | 494 | if (verbose) |
| 495 | "error 0x%02x\n", id, drv_err); | 495 | printk(KERN_WARNING "ata%u: no sense translation for " |
| 496 | "error 0x%02x\n", id, drv_err); | ||
| 496 | } | 497 | } |
| 497 | 498 | ||
| 498 | /* Fall back to interpreting status bits */ | 499 | /* Fall back to interpreting status bits */ |
| @@ -505,8 +506,9 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | |||
| 505 | } | 506 | } |
| 506 | } | 507 | } |
| 507 | /* No error? Undecoded? */ | 508 | /* No error? Undecoded? */ |
| 508 | printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n", | 509 | if (verbose) |
| 509 | id, drv_stat); | 510 | printk(KERN_WARNING "ata%u: no sense translation for " |
| 511 | "status: 0x%02x\n", id, drv_stat); | ||
| 510 | 512 | ||
| 511 | /* We need a sensible error return here, which is tricky, and one | 513 | /* We need a sensible error return here, which is tricky, and one |
| 512 | that won't cause people to do things like return a disk wrongly */ | 514 | that won't cause people to do things like return a disk wrongly */ |
| @@ -515,9 +517,10 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | |||
| 515 | *ascq = 0x00; | 517 | *ascq = 0x00; |
| 516 | 518 | ||
| 517 | translate_done: | 519 | translate_done: |
| 518 | printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to " | 520 | if (verbose) |
| 519 | "SCSI SK/ASC/ASCQ 0x%x/%02x/%02x\n", id, drv_stat, drv_err, | 521 | printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x " |
| 520 | *sk, *asc, *ascq); | 522 | "to SCSI SK/ASC/ASCQ 0x%x/%02x/%02x\n", |
| 523 | id, drv_stat, drv_err, *sk, *asc, *ascq); | ||
| 521 | return; | 524 | return; |
| 522 | } | 525 | } |
| 523 | 526 | ||
| @@ -537,9 +540,10 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | |||
| 537 | void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | 540 | void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) |
| 538 | { | 541 | { |
| 539 | struct scsi_cmnd *cmd = qc->scsicmd; | 542 | struct scsi_cmnd *cmd = qc->scsicmd; |
| 540 | struct ata_taskfile *tf = &qc->tf; | 543 | struct ata_taskfile *tf = &qc->result_tf; |
| 541 | unsigned char *sb = cmd->sense_buffer; | 544 | unsigned char *sb = cmd->sense_buffer; |
| 542 | unsigned char *desc = sb + 8; | 545 | unsigned char *desc = sb + 8; |
| 546 | int verbose = qc->ap->ops->error_handler == NULL; | ||
| 543 | 547 | ||
| 544 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); | 548 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); |
| 545 | 549 | ||
| @@ -552,7 +556,7 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | |||
| 552 | if (qc->err_mask || | 556 | if (qc->err_mask || |
| 553 | tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { | 557 | tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { |
| 554 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, | 558 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, |
| 555 | &sb[1], &sb[2], &sb[3]); | 559 | &sb[1], &sb[2], &sb[3], verbose); |
| 556 | sb[1] &= 0x0f; | 560 | sb[1] &= 0x0f; |
| 557 | } | 561 | } |
| 558 | 562 | ||
| @@ -608,8 +612,9 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | |||
| 608 | void ata_gen_fixed_sense(struct ata_queued_cmd *qc) | 612 | void ata_gen_fixed_sense(struct ata_queued_cmd *qc) |
| 609 | { | 613 | { |
| 610 | struct scsi_cmnd *cmd = qc->scsicmd; | 614 | struct scsi_cmnd *cmd = qc->scsicmd; |
| 611 | struct ata_taskfile *tf = &qc->tf; | 615 | struct ata_taskfile *tf = &qc->result_tf; |
| 612 | unsigned char *sb = cmd->sense_buffer; | 616 | unsigned char *sb = cmd->sense_buffer; |
| 617 | int verbose = qc->ap->ops->error_handler == NULL; | ||
| 613 | 618 | ||
| 614 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); | 619 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); |
| 615 | 620 | ||
| @@ -622,7 +627,7 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc) | |||
| 622 | if (qc->err_mask || | 627 | if (qc->err_mask || |
| 623 | tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { | 628 | tf->command & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { |
| 624 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, | 629 | ata_to_sense_error(qc->ap->id, tf->command, tf->feature, |
| 625 | &sb[2], &sb[12], &sb[13]); | 630 | &sb[2], &sb[12], &sb[13], verbose); |
| 626 | sb[2] &= 0x0f; | 631 | sb[2] &= 0x0f; |
| 627 | } | 632 | } |
| 628 | 633 | ||
| @@ -680,6 +685,14 @@ static void ata_scsi_dev_config(struct scsi_device *sdev, | |||
| 680 | request_queue_t *q = sdev->request_queue; | 685 | request_queue_t *q = sdev->request_queue; |
| 681 | blk_queue_max_hw_segments(q, q->max_hw_segments - 1); | 686 | blk_queue_max_hw_segments(q, q->max_hw_segments - 1); |
| 682 | } | 687 | } |
| 688 | |||
| 689 | if (dev->flags & ATA_DFLAG_NCQ) { | ||
| 690 | int depth; | ||
| 691 | |||
| 692 | depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); | ||
| 693 | depth = min(ATA_MAX_QUEUE - 1, depth); | ||
| 694 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); | ||
| 695 | } | ||
| 683 | } | 696 | } |
| 684 | 697 | ||
| 685 | /** | 698 | /** |
| @@ -714,6 +727,43 @@ int ata_scsi_slave_config(struct scsi_device *sdev) | |||
| 714 | } | 727 | } |
| 715 | 728 | ||
| 716 | /** | 729 | /** |
| 730 | * ata_scsi_change_queue_depth - SCSI callback for queue depth config | ||
| 731 | * @sdev: SCSI device to configure queue depth for | ||
| 732 | * @queue_depth: new queue depth | ||
| 733 | * | ||
| 734 | * This is libata standard hostt->change_queue_depth callback. | ||
| 735 | * SCSI will call into this callback when user tries to set queue | ||
| 736 | * depth via sysfs. | ||
| 737 | * | ||
| 738 | * LOCKING: | ||
| 739 | * SCSI layer (we don't care) | ||
| 740 | * | ||
| 741 | * RETURNS: | ||
| 742 | * Newly configured queue depth. | ||
| 743 | */ | ||
| 744 | int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth) | ||
| 745 | { | ||
| 746 | struct ata_port *ap = ata_shost_to_port(sdev->host); | ||
| 747 | struct ata_device *dev; | ||
| 748 | int max_depth; | ||
| 749 | |||
| 750 | if (queue_depth < 1) | ||
| 751 | return sdev->queue_depth; | ||
| 752 | |||
| 753 | dev = ata_scsi_find_dev(ap, sdev); | ||
| 754 | if (!dev || !ata_dev_enabled(dev)) | ||
| 755 | return sdev->queue_depth; | ||
| 756 | |||
| 757 | max_depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); | ||
| 758 | max_depth = min(ATA_MAX_QUEUE - 1, max_depth); | ||
| 759 | if (queue_depth > max_depth) | ||
| 760 | queue_depth = max_depth; | ||
| 761 | |||
| 762 | scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, queue_depth); | ||
| 763 | return queue_depth; | ||
| 764 | } | ||
| 765 | |||
| 766 | /** | ||
| 717 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command | 767 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command |
| 718 | * @qc: Storage for translated ATA taskfile | 768 | * @qc: Storage for translated ATA taskfile |
| 719 | * @scsicmd: SCSI command to translate | 769 | * @scsicmd: SCSI command to translate |
| @@ -748,7 +798,7 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc, | |||
| 748 | tf->nsect = 1; /* 1 sector, lba=0 */ | 798 | tf->nsect = 1; /* 1 sector, lba=0 */ |
| 749 | 799 | ||
| 750 | if (qc->dev->flags & ATA_DFLAG_LBA) { | 800 | if (qc->dev->flags & ATA_DFLAG_LBA) { |
| 751 | qc->tf.flags |= ATA_TFLAG_LBA; | 801 | tf->flags |= ATA_TFLAG_LBA; |
| 752 | 802 | ||
| 753 | tf->lbah = 0x0; | 803 | tf->lbah = 0x0; |
| 754 | tf->lbam = 0x0; | 804 | tf->lbam = 0x0; |
| @@ -1099,7 +1149,36 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
| 1099 | */ | 1149 | */ |
| 1100 | goto nothing_to_do; | 1150 | goto nothing_to_do; |
| 1101 | 1151 | ||
| 1102 | if (dev->flags & ATA_DFLAG_LBA) { | 1152 | if ((dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ) { |
| 1153 | /* yay, NCQ */ | ||
| 1154 | if (!lba_48_ok(block, n_block)) | ||
| 1155 | goto out_of_range; | ||
| 1156 | |||
| 1157 | tf->protocol = ATA_PROT_NCQ; | ||
| 1158 | tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; | ||
| 1159 | |||
| 1160 | if (tf->flags & ATA_TFLAG_WRITE) | ||
| 1161 | tf->command = ATA_CMD_FPDMA_WRITE; | ||
| 1162 | else | ||
| 1163 | tf->command = ATA_CMD_FPDMA_READ; | ||
| 1164 | |||
| 1165 | qc->nsect = n_block; | ||
| 1166 | |||
| 1167 | tf->nsect = qc->tag << 3; | ||
| 1168 | tf->hob_feature = (n_block >> 8) & 0xff; | ||
| 1169 | tf->feature = n_block & 0xff; | ||
| 1170 | |||
| 1171 | tf->hob_lbah = (block >> 40) & 0xff; | ||
| 1172 | tf->hob_lbam = (block >> 32) & 0xff; | ||
| 1173 | tf->hob_lbal = (block >> 24) & 0xff; | ||
| 1174 | tf->lbah = (block >> 16) & 0xff; | ||
| 1175 | tf->lbam = (block >> 8) & 0xff; | ||
| 1176 | tf->lbal = block & 0xff; | ||
| 1177 | |||
| 1178 | tf->device = 1 << 6; | ||
| 1179 | if (tf->flags & ATA_TFLAG_FUA) | ||
| 1180 | tf->device |= 1 << 7; | ||
| 1181 | } else if (dev->flags & ATA_DFLAG_LBA) { | ||
| 1103 | tf->flags |= ATA_TFLAG_LBA; | 1182 | tf->flags |= ATA_TFLAG_LBA; |
| 1104 | 1183 | ||
| 1105 | if (lba_28_ok(block, n_block)) { | 1184 | if (lba_28_ok(block, n_block)) { |
| @@ -1199,14 +1278,11 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
| 1199 | */ | 1278 | */ |
| 1200 | if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && | 1279 | if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && |
| 1201 | ((cdb[2] & 0x20) || need_sense)) { | 1280 | ((cdb[2] & 0x20) || need_sense)) { |
| 1202 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
| 1203 | ata_gen_ata_desc_sense(qc); | 1281 | ata_gen_ata_desc_sense(qc); |
| 1204 | } else { | 1282 | } else { |
| 1205 | if (!need_sense) { | 1283 | if (!need_sense) { |
| 1206 | cmd->result = SAM_STAT_GOOD; | 1284 | cmd->result = SAM_STAT_GOOD; |
| 1207 | } else { | 1285 | } else { |
| 1208 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
| 1209 | |||
| 1210 | /* TODO: decide which descriptor format to use | 1286 | /* TODO: decide which descriptor format to use |
| 1211 | * for 48b LBA devices and call that here | 1287 | * for 48b LBA devices and call that here |
| 1212 | * instead of the fixed desc, which is only | 1288 | * instead of the fixed desc, which is only |
| @@ -1217,10 +1293,8 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
| 1217 | } | 1293 | } |
| 1218 | } | 1294 | } |
| 1219 | 1295 | ||
| 1220 | if (need_sense) { | 1296 | if (need_sense && !qc->ap->ops->error_handler) |
| 1221 | /* The ata_gen_..._sense routines fill in tf */ | 1297 | ata_dump_status(qc->ap->id, &qc->result_tf); |
| 1222 | ata_dump_status(qc->ap->id, &qc->tf); | ||
| 1223 | } | ||
| 1224 | 1298 | ||
| 1225 | qc->scsidone(cmd); | 1299 | qc->scsidone(cmd); |
| 1226 | 1300 | ||
| @@ -1228,8 +1302,40 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
| 1228 | } | 1302 | } |
| 1229 | 1303 | ||
| 1230 | /** | 1304 | /** |
| 1305 | * ata_scmd_need_defer - Check whether we need to defer scmd | ||
| 1306 | * @dev: ATA device to which the command is addressed | ||
| 1307 | * @is_io: Is the command IO (and thus possibly NCQ)? | ||
| 1308 | * | ||
| 1309 | * NCQ and non-NCQ commands cannot run together. As upper layer | ||
| 1310 | * only knows the queue depth, we are responsible for maintaining | ||
| 1311 | * exclusion. This function checks whether a new command can be | ||
| 1312 | * issued to @dev. | ||
| 1313 | * | ||
| 1314 | * LOCKING: | ||
| 1315 | * spin_lock_irqsave(host_set lock) | ||
| 1316 | * | ||
| 1317 | * RETURNS: | ||
| 1318 | * 1 if deferring is needed, 0 otherwise. | ||
| 1319 | */ | ||
| 1320 | static int ata_scmd_need_defer(struct ata_device *dev, int is_io) | ||
| 1321 | { | ||
| 1322 | struct ata_port *ap = dev->ap; | ||
| 1323 | |||
| 1324 | if (!(dev->flags & ATA_DFLAG_NCQ)) | ||
| 1325 | return 0; | ||
| 1326 | |||
| 1327 | if (is_io) { | ||
| 1328 | if (!ata_tag_valid(ap->active_tag)) | ||
| 1329 | return 0; | ||
| 1330 | } else { | ||
| 1331 | if (!ata_tag_valid(ap->active_tag) && !ap->sactive) | ||
| 1332 | return 0; | ||
| 1333 | } | ||
| 1334 | return 1; | ||
| 1335 | } | ||
| 1336 | |||
| 1337 | /** | ||
| 1231 | * ata_scsi_translate - Translate then issue SCSI command to ATA device | 1338 | * ata_scsi_translate - Translate then issue SCSI command to ATA device |
| 1232 | * @ap: ATA port to which the command is addressed | ||
| 1233 | * @dev: ATA device to which the command is addressed | 1339 | * @dev: ATA device to which the command is addressed |
| 1234 | * @cmd: SCSI command to execute | 1340 | * @cmd: SCSI command to execute |
| 1235 | * @done: SCSI command completion function | 1341 | * @done: SCSI command completion function |
| @@ -1250,19 +1356,25 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
| 1250 | * | 1356 | * |
| 1251 | * LOCKING: | 1357 | * LOCKING: |
| 1252 | * spin_lock_irqsave(host_set lock) | 1358 | * spin_lock_irqsave(host_set lock) |
| 1359 | * | ||
| 1360 | * RETURNS: | ||
| 1361 | * 0 on success, SCSI_ML_QUEUE_DEVICE_BUSY if the command | ||
| 1362 | * needs to be deferred. | ||
| 1253 | */ | 1363 | */ |
| 1254 | 1364 | static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd, | |
| 1255 | static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | ||
| 1256 | struct scsi_cmnd *cmd, | ||
| 1257 | void (*done)(struct scsi_cmnd *), | 1365 | void (*done)(struct scsi_cmnd *), |
| 1258 | ata_xlat_func_t xlat_func) | 1366 | ata_xlat_func_t xlat_func) |
| 1259 | { | 1367 | { |
| 1260 | struct ata_queued_cmd *qc; | 1368 | struct ata_queued_cmd *qc; |
| 1261 | u8 *scsicmd = cmd->cmnd; | 1369 | u8 *scsicmd = cmd->cmnd; |
| 1370 | int is_io = xlat_func == ata_scsi_rw_xlat; | ||
| 1262 | 1371 | ||
| 1263 | VPRINTK("ENTER\n"); | 1372 | VPRINTK("ENTER\n"); |
| 1264 | 1373 | ||
| 1265 | qc = ata_scsi_qc_new(ap, dev, cmd, done); | 1374 | if (unlikely(ata_scmd_need_defer(dev, is_io))) |
| 1375 | goto defer; | ||
| 1376 | |||
| 1377 | qc = ata_scsi_qc_new(dev, cmd, done); | ||
| 1266 | if (!qc) | 1378 | if (!qc) |
| 1267 | goto err_mem; | 1379 | goto err_mem; |
| 1268 | 1380 | ||
| @@ -1270,8 +1382,8 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
| 1270 | if (cmd->sc_data_direction == DMA_FROM_DEVICE || | 1382 | if (cmd->sc_data_direction == DMA_FROM_DEVICE || |
| 1271 | cmd->sc_data_direction == DMA_TO_DEVICE) { | 1383 | cmd->sc_data_direction == DMA_TO_DEVICE) { |
| 1272 | if (unlikely(cmd->request_bufflen < 1)) { | 1384 | if (unlikely(cmd->request_bufflen < 1)) { |
| 1273 | printk(KERN_WARNING "ata%u(%u): WARNING: zero len r/w req\n", | 1385 | ata_dev_printk(dev, KERN_WARNING, |
| 1274 | ap->id, dev->devno); | 1386 | "WARNING: zero len r/w req\n"); |
| 1275 | goto err_did; | 1387 | goto err_did; |
| 1276 | } | 1388 | } |
| 1277 | 1389 | ||
| @@ -1293,13 +1405,13 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
| 1293 | ata_qc_issue(qc); | 1405 | ata_qc_issue(qc); |
| 1294 | 1406 | ||
| 1295 | VPRINTK("EXIT\n"); | 1407 | VPRINTK("EXIT\n"); |
| 1296 | return; | 1408 | return 0; |
| 1297 | 1409 | ||
| 1298 | early_finish: | 1410 | early_finish: |
| 1299 | ata_qc_free(qc); | 1411 | ata_qc_free(qc); |
| 1300 | done(cmd); | 1412 | done(cmd); |
| 1301 | DPRINTK("EXIT - early finish (good or error)\n"); | 1413 | DPRINTK("EXIT - early finish (good or error)\n"); |
| 1302 | return; | 1414 | return 0; |
| 1303 | 1415 | ||
| 1304 | err_did: | 1416 | err_did: |
| 1305 | ata_qc_free(qc); | 1417 | ata_qc_free(qc); |
| @@ -1307,7 +1419,11 @@ err_mem: | |||
| 1307 | cmd->result = (DID_ERROR << 16); | 1419 | cmd->result = (DID_ERROR << 16); |
| 1308 | done(cmd); | 1420 | done(cmd); |
| 1309 | DPRINTK("EXIT - internal\n"); | 1421 | DPRINTK("EXIT - internal\n"); |
| 1310 | return; | 1422 | return 0; |
| 1423 | |||
| 1424 | defer: | ||
| 1425 | DPRINTK("EXIT - defer\n"); | ||
| 1426 | return SCSI_MLQUEUE_DEVICE_BUSY; | ||
| 1311 | } | 1427 | } |
| 1312 | 1428 | ||
| 1313 | /** | 1429 | /** |
| @@ -2004,7 +2120,6 @@ static void atapi_sense_complete(struct ata_queued_cmd *qc) | |||
| 2004 | * a sense descriptors, since that's only | 2120 | * a sense descriptors, since that's only |
| 2005 | * correct for ATA, not ATAPI | 2121 | * correct for ATA, not ATAPI |
| 2006 | */ | 2122 | */ |
| 2007 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
| 2008 | ata_gen_ata_desc_sense(qc); | 2123 | ata_gen_ata_desc_sense(qc); |
| 2009 | } | 2124 | } |
| 2010 | 2125 | ||
| @@ -2070,6 +2185,26 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) | |||
| 2070 | 2185 | ||
| 2071 | VPRINTK("ENTER, err_mask 0x%X\n", err_mask); | 2186 | VPRINTK("ENTER, err_mask 0x%X\n", err_mask); |
| 2072 | 2187 | ||
| 2188 | /* handle completion from new EH */ | ||
| 2189 | if (unlikely(qc->ap->ops->error_handler && | ||
| 2190 | (err_mask || qc->flags & ATA_QCFLAG_SENSE_VALID))) { | ||
| 2191 | |||
| 2192 | if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) { | ||
| 2193 | /* FIXME: not quite right; we don't want the | ||
| 2194 | * translation of taskfile registers into a | ||
| 2195 | * sense descriptors, since that's only | ||
| 2196 | * correct for ATA, not ATAPI | ||
| 2197 | */ | ||
| 2198 | ata_gen_ata_desc_sense(qc); | ||
| 2199 | } | ||
| 2200 | |||
| 2201 | qc->scsicmd->result = SAM_STAT_CHECK_CONDITION; | ||
| 2202 | qc->scsidone(cmd); | ||
| 2203 | ata_qc_free(qc); | ||
| 2204 | return; | ||
| 2205 | } | ||
| 2206 | |||
| 2207 | /* successful completion or old EH failure path */ | ||
| 2073 | if (unlikely(err_mask & AC_ERR_DEV)) { | 2208 | if (unlikely(err_mask & AC_ERR_DEV)) { |
| 2074 | cmd->result = SAM_STAT_CHECK_CONDITION; | 2209 | cmd->result = SAM_STAT_CHECK_CONDITION; |
| 2075 | atapi_request_sense(qc); | 2210 | atapi_request_sense(qc); |
| @@ -2080,7 +2215,6 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) | |||
| 2080 | * a sense descriptors, since that's only | 2215 | * a sense descriptors, since that's only |
| 2081 | * correct for ATA, not ATAPI | 2216 | * correct for ATA, not ATAPI |
| 2082 | */ | 2217 | */ |
| 2083 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
| 2084 | ata_gen_ata_desc_sense(qc); | 2218 | ata_gen_ata_desc_sense(qc); |
| 2085 | } else { | 2219 | } else { |
| 2086 | u8 *scsicmd = cmd->cmnd; | 2220 | u8 *scsicmd = cmd->cmnd; |
| @@ -2211,8 +2345,9 @@ ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev) | |||
| 2211 | 2345 | ||
| 2212 | if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) { | 2346 | if (!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) { |
| 2213 | if (unlikely(dev->class == ATA_DEV_ATAPI)) { | 2347 | if (unlikely(dev->class == ATA_DEV_ATAPI)) { |
| 2214 | printk(KERN_WARNING "ata%u(%u): WARNING: ATAPI is %s, device ignored.\n", | 2348 | ata_dev_printk(dev, KERN_WARNING, |
| 2215 | ap->id, dev->devno, atapi_enabled ? "not supported with this driver" : "disabled"); | 2349 | "WARNING: ATAPI is %s, device ignored.\n", |
| 2350 | atapi_enabled ? "not supported with this driver" : "disabled"); | ||
| 2216 | return NULL; | 2351 | return NULL; |
| 2217 | } | 2352 | } |
| 2218 | } | 2353 | } |
| @@ -2361,6 +2496,9 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd) | |||
| 2361 | */ | 2496 | */ |
| 2362 | qc->nsect = cmd->bufflen / ATA_SECT_SIZE; | 2497 | qc->nsect = cmd->bufflen / ATA_SECT_SIZE; |
| 2363 | 2498 | ||
| 2499 | /* request result TF */ | ||
| 2500 | qc->flags |= ATA_QCFLAG_RESULT_TF; | ||
| 2501 | |||
| 2364 | return 0; | 2502 | return 0; |
| 2365 | 2503 | ||
| 2366 | invalid_fld: | 2504 | invalid_fld: |
| @@ -2437,19 +2575,24 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap, | |||
| 2437 | #endif | 2575 | #endif |
| 2438 | } | 2576 | } |
| 2439 | 2577 | ||
| 2440 | static inline void __ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), | 2578 | static inline int __ata_scsi_queuecmd(struct scsi_cmnd *cmd, |
| 2441 | struct ata_port *ap, struct ata_device *dev) | 2579 | void (*done)(struct scsi_cmnd *), |
| 2580 | struct ata_device *dev) | ||
| 2442 | { | 2581 | { |
| 2582 | int rc = 0; | ||
| 2583 | |||
| 2443 | if (dev->class == ATA_DEV_ATA) { | 2584 | if (dev->class == ATA_DEV_ATA) { |
| 2444 | ata_xlat_func_t xlat_func = ata_get_xlat_func(dev, | 2585 | ata_xlat_func_t xlat_func = ata_get_xlat_func(dev, |
| 2445 | cmd->cmnd[0]); | 2586 | cmd->cmnd[0]); |
| 2446 | 2587 | ||
| 2447 | if (xlat_func) | 2588 | if (xlat_func) |
| 2448 | ata_scsi_translate(ap, dev, cmd, done, xlat_func); | 2589 | rc = ata_scsi_translate(dev, cmd, done, xlat_func); |
| 2449 | else | 2590 | else |
| 2450 | ata_scsi_simulate(ap, dev, cmd, done); | 2591 | ata_scsi_simulate(dev, cmd, done); |
| 2451 | } else | 2592 | } else |
| 2452 | ata_scsi_translate(ap, dev, cmd, done, atapi_xlat); | 2593 | rc = ata_scsi_translate(dev, cmd, done, atapi_xlat); |
| 2594 | |||
| 2595 | return rc; | ||
| 2453 | } | 2596 | } |
| 2454 | 2597 | ||
| 2455 | /** | 2598 | /** |
| @@ -2468,15 +2611,16 @@ static inline void __ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struc | |||
| 2468 | * Releases scsi-layer-held lock, and obtains host_set lock. | 2611 | * Releases scsi-layer-held lock, and obtains host_set lock. |
| 2469 | * | 2612 | * |
| 2470 | * RETURNS: | 2613 | * RETURNS: |
| 2471 | * Zero. | 2614 | * Return value from __ata_scsi_queuecmd() if @cmd can be queued, |
| 2615 | * 0 otherwise. | ||
| 2472 | */ | 2616 | */ |
| 2473 | |||
| 2474 | int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) | 2617 | int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) |
| 2475 | { | 2618 | { |
| 2476 | struct ata_port *ap; | 2619 | struct ata_port *ap; |
| 2477 | struct ata_device *dev; | 2620 | struct ata_device *dev; |
| 2478 | struct scsi_device *scsidev = cmd->device; | 2621 | struct scsi_device *scsidev = cmd->device; |
| 2479 | struct Scsi_Host *shost = scsidev->host; | 2622 | struct Scsi_Host *shost = scsidev->host; |
| 2623 | int rc = 0; | ||
| 2480 | 2624 | ||
| 2481 | ap = ata_shost_to_port(shost); | 2625 | ap = ata_shost_to_port(shost); |
| 2482 | 2626 | ||
| @@ -2487,7 +2631,7 @@ int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) | |||
| 2487 | 2631 | ||
| 2488 | dev = ata_scsi_find_dev(ap, scsidev); | 2632 | dev = ata_scsi_find_dev(ap, scsidev); |
| 2489 | if (likely(dev)) | 2633 | if (likely(dev)) |
| 2490 | __ata_scsi_queuecmd(cmd, done, ap, dev); | 2634 | rc = __ata_scsi_queuecmd(cmd, done, dev); |
| 2491 | else { | 2635 | else { |
| 2492 | cmd->result = (DID_BAD_TARGET << 16); | 2636 | cmd->result = (DID_BAD_TARGET << 16); |
| 2493 | done(cmd); | 2637 | done(cmd); |
| @@ -2495,12 +2639,11 @@ int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) | |||
| 2495 | 2639 | ||
| 2496 | spin_unlock(&ap->host_set->lock); | 2640 | spin_unlock(&ap->host_set->lock); |
| 2497 | spin_lock(shost->host_lock); | 2641 | spin_lock(shost->host_lock); |
| 2498 | return 0; | 2642 | return rc; |
| 2499 | } | 2643 | } |
| 2500 | 2644 | ||
| 2501 | /** | 2645 | /** |
| 2502 | * ata_scsi_simulate - simulate SCSI command on ATA device | 2646 | * ata_scsi_simulate - simulate SCSI command on ATA device |
| 2503 | * @ap: port the device is connected to | ||
| 2504 | * @dev: the target device | 2647 | * @dev: the target device |
| 2505 | * @cmd: SCSI command being sent to device. | 2648 | * @cmd: SCSI command being sent to device. |
| 2506 | * @done: SCSI command completion function. | 2649 | * @done: SCSI command completion function. |
| @@ -2512,14 +2655,12 @@ int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) | |||
| 2512 | * spin_lock_irqsave(host_set lock) | 2655 | * spin_lock_irqsave(host_set lock) |
| 2513 | */ | 2656 | */ |
| 2514 | 2657 | ||
| 2515 | void ata_scsi_simulate(struct ata_port *ap, struct ata_device *dev, | 2658 | void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd, |
| 2516 | struct scsi_cmnd *cmd, | ||
| 2517 | void (*done)(struct scsi_cmnd *)) | 2659 | void (*done)(struct scsi_cmnd *)) |
| 2518 | { | 2660 | { |
| 2519 | struct ata_scsi_args args; | 2661 | struct ata_scsi_args args; |
| 2520 | const u8 *scsicmd = cmd->cmnd; | 2662 | const u8 *scsicmd = cmd->cmnd; |
| 2521 | 2663 | ||
| 2522 | args.ap = ap; | ||
| 2523 | args.dev = dev; | 2664 | args.dev = dev; |
| 2524 | args.id = dev->id; | 2665 | args.id = dev->id; |
| 2525 | args.cmd = cmd; | 2666 | args.cmd = cmd; |
| @@ -2605,3 +2746,26 @@ void ata_scsi_scan_host(struct ata_port *ap) | |||
| 2605 | } | 2746 | } |
| 2606 | } | 2747 | } |
| 2607 | 2748 | ||
| 2749 | /** | ||
| 2750 | * ata_schedule_scsi_eh - schedule EH for SCSI host | ||
| 2751 | * @shost: SCSI host to invoke error handling on. | ||
| 2752 | * | ||
| 2753 | * Schedule SCSI EH without scmd. This is a hack. | ||
| 2754 | * | ||
| 2755 | * LOCKING: | ||
| 2756 | * spin_lock_irqsave(host_set lock) | ||
| 2757 | **/ | ||
| 2758 | void ata_schedule_scsi_eh(struct Scsi_Host *shost) | ||
| 2759 | { | ||
| 2760 | unsigned long flags; | ||
| 2761 | |||
| 2762 | spin_lock_irqsave(shost->host_lock, flags); | ||
| 2763 | |||
| 2764 | if (scsi_host_set_state(shost, SHOST_RECOVERY) == 0 || | ||
| 2765 | scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY) == 0) { | ||
| 2766 | shost->host_eh_scheduled++; | ||
| 2767 | scsi_eh_wakeup(shost); | ||
| 2768 | } | ||
| 2769 | |||
| 2770 | spin_unlock_irqrestore(shost->host_lock, flags); | ||
| 2771 | } | ||
