diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-10-09 11:16:14 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-10-09 11:16:14 -0400 |
commit | c4052da6f0c01a0b059d125d72bb934d0980b798 (patch) | |
tree | ad50a17e4d14b8f6f1773158d956d424575d1712 /drivers/scsi/libata-scsi.c | |
parent | cedc9a478d8c6265879dc3839ef3d4849a709184 (diff) | |
parent | 3d3467f0fdf61a421361c00cf84fcf0f1a6dc1e8 (diff) |
Merge branch 'upstream'
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
-rw-r--r-- | drivers/scsi/libata-scsi.c | 689 |
1 files changed, 502 insertions, 187 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c index ee3f1050fb5f..4cf43de4060e 100644 --- a/drivers/scsi/libata-scsi.c +++ b/drivers/scsi/libata-scsi.c | |||
@@ -49,6 +49,14 @@ static struct ata_device * | |||
49 | ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev); | 49 | ata_scsi_find_dev(struct ata_port *ap, struct scsi_device *scsidev); |
50 | 50 | ||
51 | 51 | ||
52 | static void ata_scsi_invalid_field(struct scsi_cmnd *cmd, | ||
53 | void (*done)(struct scsi_cmnd *)) | ||
54 | { | ||
55 | ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, 0x24, 0x0); | ||
56 | /* "Invalid field in cbd" */ | ||
57 | done(cmd); | ||
58 | } | ||
59 | |||
52 | /** | 60 | /** |
53 | * ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd. | 61 | * ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd. |
54 | * @sdev: SCSI device for which BIOS geometry is to be determined | 62 | * @sdev: SCSI device for which BIOS geometry is to be determined |
@@ -182,7 +190,6 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) | |||
182 | { | 190 | { |
183 | struct scsi_cmnd *cmd = qc->scsicmd; | 191 | struct scsi_cmnd *cmd = qc->scsicmd; |
184 | u8 err = 0; | 192 | u8 err = 0; |
185 | unsigned char *sb = cmd->sense_buffer; | ||
186 | /* Based on the 3ware driver translation table */ | 193 | /* Based on the 3ware driver translation table */ |
187 | static unsigned char sense_table[][4] = { | 194 | static unsigned char sense_table[][4] = { |
188 | /* BBD|ECC|ID|MAR */ | 195 | /* BBD|ECC|ID|MAR */ |
@@ -225,8 +232,6 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) | |||
225 | }; | 232 | }; |
226 | int i = 0; | 233 | int i = 0; |
227 | 234 | ||
228 | cmd->result = SAM_STAT_CHECK_CONDITION; | ||
229 | |||
230 | /* | 235 | /* |
231 | * Is this an error we can process/parse | 236 | * Is this an error we can process/parse |
232 | */ | 237 | */ |
@@ -281,11 +286,9 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) | |||
281 | /* Look for best matches first */ | 286 | /* Look for best matches first */ |
282 | if((sense_table[i][0] & err) == sense_table[i][0]) | 287 | if((sense_table[i][0] & err) == sense_table[i][0]) |
283 | { | 288 | { |
284 | sb[0] = 0x70; | 289 | ata_scsi_set_sense(cmd, sense_table[i][1] /* sk */, |
285 | sb[2] = sense_table[i][1]; | 290 | sense_table[i][2] /* asc */, |
286 | sb[7] = 0x0a; | 291 | sense_table[i][3] /* ascq */ ); |
287 | sb[12] = sense_table[i][2]; | ||
288 | sb[13] = sense_table[i][3]; | ||
289 | return; | 292 | return; |
290 | } | 293 | } |
291 | i++; | 294 | i++; |
@@ -300,11 +303,9 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) | |||
300 | { | 303 | { |
301 | if(stat_table[i][0] & drv_stat) | 304 | if(stat_table[i][0] & drv_stat) |
302 | { | 305 | { |
303 | sb[0] = 0x70; | 306 | ata_scsi_set_sense(cmd, sense_table[i][1] /* sk */, |
304 | sb[2] = stat_table[i][1]; | 307 | sense_table[i][2] /* asc */, |
305 | sb[7] = 0x0a; | 308 | sense_table[i][3] /* ascq */ ); |
306 | sb[12] = stat_table[i][2]; | ||
307 | sb[13] = stat_table[i][3]; | ||
308 | return; | 309 | return; |
309 | } | 310 | } |
310 | i++; | 311 | i++; |
@@ -313,15 +314,12 @@ void ata_to_sense_error(struct ata_queued_cmd *qc, u8 drv_stat) | |||
313 | printk(KERN_ERR "ata%u: called with no error (%02X)!\n", qc->ap->id, drv_stat); | 314 | printk(KERN_ERR "ata%u: called with no error (%02X)!\n", qc->ap->id, drv_stat); |
314 | /* additional-sense-code[-qualifier] */ | 315 | /* additional-sense-code[-qualifier] */ |
315 | 316 | ||
316 | sb[0] = 0x70; | ||
317 | sb[2] = MEDIUM_ERROR; | ||
318 | sb[7] = 0x0A; | ||
319 | if (cmd->sc_data_direction == DMA_FROM_DEVICE) { | 317 | if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
320 | sb[12] = 0x11; /* "unrecovered read error" */ | 318 | ata_scsi_set_sense(cmd, MEDIUM_ERROR, 0x11, 0x4); |
321 | sb[13] = 0x04; | 319 | /* "unrecovered read error" */ |
322 | } else { | 320 | } else { |
323 | sb[12] = 0x0C; /* "write error - */ | 321 | ata_scsi_set_sense(cmd, MEDIUM_ERROR, 0xc, 0x2); |
324 | sb[13] = 0x02; /* auto-reallocation failed" */ | 322 | /* "write error - auto-reallocation failed" */ |
325 | } | 323 | } |
326 | } | 324 | } |
327 | 325 | ||
@@ -440,15 +438,26 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc, | |||
440 | ; /* ignore IMMED bit, violates sat-r05 */ | 438 | ; /* ignore IMMED bit, violates sat-r05 */ |
441 | } | 439 | } |
442 | if (scsicmd[4] & 0x2) | 440 | if (scsicmd[4] & 0x2) |
443 | return 1; /* LOEJ bit set not supported */ | 441 | goto invalid_fld; /* LOEJ bit set not supported */ |
444 | if (((scsicmd[4] >> 4) & 0xf) != 0) | 442 | if (((scsicmd[4] >> 4) & 0xf) != 0) |
445 | return 1; /* power conditions not supported */ | 443 | goto invalid_fld; /* power conditions not supported */ |
446 | if (scsicmd[4] & 0x1) { | 444 | if (scsicmd[4] & 0x1) { |
447 | tf->nsect = 1; /* 1 sector, lba=0 */ | 445 | tf->nsect = 1; /* 1 sector, lba=0 */ |
448 | tf->lbah = 0x0; | 446 | |
449 | tf->lbam = 0x0; | 447 | if (qc->dev->flags & ATA_DFLAG_LBA) { |
450 | tf->lbal = 0x0; | 448 | qc->tf.flags |= ATA_TFLAG_LBA; |
451 | tf->device |= ATA_LBA; | 449 | |
450 | tf->lbah = 0x0; | ||
451 | tf->lbam = 0x0; | ||
452 | tf->lbal = 0x0; | ||
453 | tf->device |= ATA_LBA; | ||
454 | } else { | ||
455 | /* CHS */ | ||
456 | tf->lbal = 0x1; /* sect */ | ||
457 | tf->lbam = 0x0; /* cyl low */ | ||
458 | tf->lbah = 0x0; /* cyl high */ | ||
459 | } | ||
460 | |||
452 | tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ | 461 | tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ |
453 | } else { | 462 | } else { |
454 | tf->nsect = 0; /* time period value (0 implies now) */ | 463 | tf->nsect = 0; /* time period value (0 implies now) */ |
@@ -463,6 +472,11 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc, | |||
463 | */ | 472 | */ |
464 | 473 | ||
465 | return 0; | 474 | return 0; |
475 | |||
476 | invalid_fld: | ||
477 | ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); | ||
478 | /* "Invalid field in cbd" */ | ||
479 | return 1; | ||
466 | } | 480 | } |
467 | 481 | ||
468 | 482 | ||
@@ -498,6 +512,99 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | |||
498 | } | 512 | } |
499 | 513 | ||
500 | /** | 514 | /** |
515 | * scsi_6_lba_len - Get LBA and transfer length | ||
516 | * @scsicmd: SCSI command to translate | ||
517 | * | ||
518 | * Calculate LBA and transfer length for 6-byte commands. | ||
519 | * | ||
520 | * RETURNS: | ||
521 | * @plba: the LBA | ||
522 | * @plen: the transfer length | ||
523 | */ | ||
524 | |||
525 | static void scsi_6_lba_len(u8 *scsicmd, u64 *plba, u32 *plen) | ||
526 | { | ||
527 | u64 lba = 0; | ||
528 | u32 len = 0; | ||
529 | |||
530 | VPRINTK("six-byte command\n"); | ||
531 | |||
532 | lba |= ((u64)scsicmd[2]) << 8; | ||
533 | lba |= ((u64)scsicmd[3]); | ||
534 | |||
535 | len |= ((u32)scsicmd[4]); | ||
536 | |||
537 | *plba = lba; | ||
538 | *plen = len; | ||
539 | } | ||
540 | |||
541 | /** | ||
542 | * scsi_10_lba_len - Get LBA and transfer length | ||
543 | * @scsicmd: SCSI command to translate | ||
544 | * | ||
545 | * Calculate LBA and transfer length for 10-byte commands. | ||
546 | * | ||
547 | * RETURNS: | ||
548 | * @plba: the LBA | ||
549 | * @plen: the transfer length | ||
550 | */ | ||
551 | |||
552 | static void scsi_10_lba_len(u8 *scsicmd, u64 *plba, u32 *plen) | ||
553 | { | ||
554 | u64 lba = 0; | ||
555 | u32 len = 0; | ||
556 | |||
557 | VPRINTK("ten-byte command\n"); | ||
558 | |||
559 | lba |= ((u64)scsicmd[2]) << 24; | ||
560 | lba |= ((u64)scsicmd[3]) << 16; | ||
561 | lba |= ((u64)scsicmd[4]) << 8; | ||
562 | lba |= ((u64)scsicmd[5]); | ||
563 | |||
564 | len |= ((u32)scsicmd[7]) << 8; | ||
565 | len |= ((u32)scsicmd[8]); | ||
566 | |||
567 | *plba = lba; | ||
568 | *plen = len; | ||
569 | } | ||
570 | |||
571 | /** | ||
572 | * scsi_16_lba_len - Get LBA and transfer length | ||
573 | * @scsicmd: SCSI command to translate | ||
574 | * | ||
575 | * Calculate LBA and transfer length for 16-byte commands. | ||
576 | * | ||
577 | * RETURNS: | ||
578 | * @plba: the LBA | ||
579 | * @plen: the transfer length | ||
580 | */ | ||
581 | |||
582 | static void scsi_16_lba_len(u8 *scsicmd, u64 *plba, u32 *plen) | ||
583 | { | ||
584 | u64 lba = 0; | ||
585 | u32 len = 0; | ||
586 | |||
587 | VPRINTK("sixteen-byte command\n"); | ||
588 | |||
589 | lba |= ((u64)scsicmd[2]) << 56; | ||
590 | lba |= ((u64)scsicmd[3]) << 48; | ||
591 | lba |= ((u64)scsicmd[4]) << 40; | ||
592 | lba |= ((u64)scsicmd[5]) << 32; | ||
593 | lba |= ((u64)scsicmd[6]) << 24; | ||
594 | lba |= ((u64)scsicmd[7]) << 16; | ||
595 | lba |= ((u64)scsicmd[8]) << 8; | ||
596 | lba |= ((u64)scsicmd[9]); | ||
597 | |||
598 | len |= ((u32)scsicmd[10]) << 24; | ||
599 | len |= ((u32)scsicmd[11]) << 16; | ||
600 | len |= ((u32)scsicmd[12]) << 8; | ||
601 | len |= ((u32)scsicmd[13]); | ||
602 | |||
603 | *plba = lba; | ||
604 | *plen = len; | ||
605 | } | ||
606 | |||
607 | /** | ||
501 | * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one | 608 | * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one |
502 | * @qc: Storage for translated ATA taskfile | 609 | * @qc: Storage for translated ATA taskfile |
503 | * @scsicmd: SCSI command to translate | 610 | * @scsicmd: SCSI command to translate |
@@ -514,79 +621,102 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | |||
514 | static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | 621 | static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) |
515 | { | 622 | { |
516 | struct ata_taskfile *tf = &qc->tf; | 623 | struct ata_taskfile *tf = &qc->tf; |
624 | struct ata_device *dev = qc->dev; | ||
625 | unsigned int lba = tf->flags & ATA_TFLAG_LBA; | ||
517 | unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; | 626 | unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; |
518 | u64 dev_sectors = qc->dev->n_sectors; | 627 | u64 dev_sectors = qc->dev->n_sectors; |
519 | u64 sect = 0; | 628 | u64 block; |
520 | u32 n_sect = 0; | 629 | u32 n_block; |
521 | 630 | ||
522 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | 631 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
523 | tf->protocol = ATA_PROT_NODATA; | 632 | tf->protocol = ATA_PROT_NODATA; |
524 | tf->device |= ATA_LBA; | ||
525 | |||
526 | if (scsicmd[0] == VERIFY) { | ||
527 | sect |= ((u64)scsicmd[2]) << 24; | ||
528 | sect |= ((u64)scsicmd[3]) << 16; | ||
529 | sect |= ((u64)scsicmd[4]) << 8; | ||
530 | sect |= ((u64)scsicmd[5]); | ||
531 | |||
532 | n_sect |= ((u32)scsicmd[7]) << 8; | ||
533 | n_sect |= ((u32)scsicmd[8]); | ||
534 | } | ||
535 | |||
536 | else if (scsicmd[0] == VERIFY_16) { | ||
537 | sect |= ((u64)scsicmd[2]) << 56; | ||
538 | sect |= ((u64)scsicmd[3]) << 48; | ||
539 | sect |= ((u64)scsicmd[4]) << 40; | ||
540 | sect |= ((u64)scsicmd[5]) << 32; | ||
541 | sect |= ((u64)scsicmd[6]) << 24; | ||
542 | sect |= ((u64)scsicmd[7]) << 16; | ||
543 | sect |= ((u64)scsicmd[8]) << 8; | ||
544 | sect |= ((u64)scsicmd[9]); | ||
545 | |||
546 | n_sect |= ((u32)scsicmd[10]) << 24; | ||
547 | n_sect |= ((u32)scsicmd[11]) << 16; | ||
548 | n_sect |= ((u32)scsicmd[12]) << 8; | ||
549 | n_sect |= ((u32)scsicmd[13]); | ||
550 | } | ||
551 | 633 | ||
634 | if (scsicmd[0] == VERIFY) | ||
635 | scsi_10_lba_len(scsicmd, &block, &n_block); | ||
636 | else if (scsicmd[0] == VERIFY_16) | ||
637 | scsi_16_lba_len(scsicmd, &block, &n_block); | ||
552 | else | 638 | else |
553 | return 1; | 639 | goto invalid_fld; |
554 | 640 | ||
555 | if (!n_sect) | 641 | if (!n_block) |
556 | return 1; | 642 | goto nothing_to_do; |
557 | if (sect >= dev_sectors) | 643 | if (block >= dev_sectors) |
558 | return 1; | 644 | goto out_of_range; |
559 | if ((sect + n_sect) > dev_sectors) | 645 | if ((block + n_block) > dev_sectors) |
560 | return 1; | 646 | goto out_of_range; |
561 | if (lba48) { | 647 | if (lba48) { |
562 | if (n_sect > (64 * 1024)) | 648 | if (n_block > (64 * 1024)) |
563 | return 1; | 649 | goto invalid_fld; |
564 | } else { | 650 | } else { |
565 | if (n_sect > 256) | 651 | if (n_block > 256) |
566 | return 1; | 652 | goto invalid_fld; |
567 | } | 653 | } |
568 | 654 | ||
569 | if (lba48) { | 655 | if (lba) { |
570 | tf->command = ATA_CMD_VERIFY_EXT; | 656 | if (lba48) { |
657 | tf->command = ATA_CMD_VERIFY_EXT; | ||
658 | |||
659 | tf->hob_nsect = (n_block >> 8) & 0xff; | ||
660 | |||
661 | tf->hob_lbah = (block >> 40) & 0xff; | ||
662 | tf->hob_lbam = (block >> 32) & 0xff; | ||
663 | tf->hob_lbal = (block >> 24) & 0xff; | ||
664 | } else { | ||
665 | tf->command = ATA_CMD_VERIFY; | ||
666 | |||
667 | tf->device |= (block >> 24) & 0xf; | ||
668 | } | ||
571 | 669 | ||
572 | tf->hob_nsect = (n_sect >> 8) & 0xff; | 670 | tf->nsect = n_block & 0xff; |
573 | 671 | ||
574 | tf->hob_lbah = (sect >> 40) & 0xff; | 672 | tf->lbah = (block >> 16) & 0xff; |
575 | tf->hob_lbam = (sect >> 32) & 0xff; | 673 | tf->lbam = (block >> 8) & 0xff; |
576 | tf->hob_lbal = (sect >> 24) & 0xff; | 674 | tf->lbal = block & 0xff; |
675 | |||
676 | tf->device |= ATA_LBA; | ||
577 | } else { | 677 | } else { |
678 | /* CHS */ | ||
679 | u32 sect, head, cyl, track; | ||
680 | |||
681 | /* Convert LBA to CHS */ | ||
682 | track = (u32)block / dev->sectors; | ||
683 | cyl = track / dev->heads; | ||
684 | head = track % dev->heads; | ||
685 | sect = (u32)block % dev->sectors + 1; | ||
686 | |||
687 | DPRINTK("block %u track %u cyl %u head %u sect %u\n", | ||
688 | (u32)block, track, cyl, head, sect); | ||
689 | |||
690 | /* Check whether the converted CHS can fit. | ||
691 | Cylinder: 0-65535 | ||
692 | Head: 0-15 | ||
693 | Sector: 1-255*/ | ||
694 | if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) | ||
695 | goto out_of_range; | ||
696 | |||
578 | tf->command = ATA_CMD_VERIFY; | 697 | tf->command = ATA_CMD_VERIFY; |
579 | 698 | tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ | |
580 | tf->device |= (sect >> 24) & 0xf; | 699 | tf->lbal = sect; |
700 | tf->lbam = cyl; | ||
701 | tf->lbah = cyl >> 8; | ||
702 | tf->device |= head; | ||
581 | } | 703 | } |
582 | 704 | ||
583 | tf->nsect = n_sect & 0xff; | 705 | return 0; |
584 | 706 | ||
585 | tf->lbah = (sect >> 16) & 0xff; | 707 | invalid_fld: |
586 | tf->lbam = (sect >> 8) & 0xff; | 708 | ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); |
587 | tf->lbal = sect & 0xff; | 709 | /* "Invalid field in cbd" */ |
710 | return 1; | ||
588 | 711 | ||
589 | return 0; | 712 | out_of_range: |
713 | ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0); | ||
714 | /* "Logical Block Address out of range" */ | ||
715 | return 1; | ||
716 | |||
717 | nothing_to_do: | ||
718 | qc->scsicmd->result = SAM_STAT_GOOD; | ||
719 | return 1; | ||
590 | } | 720 | } |
591 | 721 | ||
592 | /** | 722 | /** |
@@ -612,11 +742,14 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | |||
612 | static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | 742 | static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) |
613 | { | 743 | { |
614 | struct ata_taskfile *tf = &qc->tf; | 744 | struct ata_taskfile *tf = &qc->tf; |
745 | struct ata_device *dev = qc->dev; | ||
746 | unsigned int lba = tf->flags & ATA_TFLAG_LBA; | ||
615 | unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; | 747 | unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; |
748 | u64 block; | ||
749 | u32 n_block; | ||
616 | 750 | ||
617 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | 751 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
618 | tf->protocol = qc->dev->xfer_protocol; | 752 | tf->protocol = qc->dev->xfer_protocol; |
619 | tf->device |= ATA_LBA; | ||
620 | 753 | ||
621 | if (scsicmd[0] == READ_10 || scsicmd[0] == READ_6 || | 754 | if (scsicmd[0] == READ_10 || scsicmd[0] == READ_6 || |
622 | scsicmd[0] == READ_16) { | 755 | scsicmd[0] == READ_16) { |
@@ -626,89 +759,115 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd) | |||
626 | tf->flags |= ATA_TFLAG_WRITE; | 759 | tf->flags |= ATA_TFLAG_WRITE; |
627 | } | 760 | } |
628 | 761 | ||
629 | if (scsicmd[0] == READ_10 || scsicmd[0] == WRITE_10) { | 762 | /* Calculate the SCSI LBA and transfer length. */ |
630 | if (lba48) { | 763 | switch (scsicmd[0]) { |
631 | tf->hob_nsect = scsicmd[7]; | 764 | case READ_10: |
632 | tf->hob_lbal = scsicmd[2]; | 765 | case WRITE_10: |
633 | 766 | scsi_10_lba_len(scsicmd, &block, &n_block); | |
634 | qc->nsect = ((unsigned int)scsicmd[7] << 8) | | 767 | break; |
635 | scsicmd[8]; | 768 | case READ_6: |
636 | } else { | 769 | case WRITE_6: |
637 | /* if we don't support LBA48 addressing, the request | 770 | scsi_6_lba_len(scsicmd, &block, &n_block); |
638 | * -may- be too large. */ | ||
639 | if ((scsicmd[2] & 0xf0) || scsicmd[7]) | ||
640 | return 1; | ||
641 | |||
642 | /* stores LBA27:24 in lower 4 bits of device reg */ | ||
643 | tf->device |= scsicmd[2]; | ||
644 | 771 | ||
645 | qc->nsect = scsicmd[8]; | 772 | /* for 6-byte r/w commands, transfer length 0 |
646 | } | 773 | * means 256 blocks of data, not 0 block. |
774 | */ | ||
775 | if (!n_block) | ||
776 | n_block = 256; | ||
777 | break; | ||
778 | case READ_16: | ||
779 | case WRITE_16: | ||
780 | scsi_16_lba_len(scsicmd, &block, &n_block); | ||
781 | break; | ||
782 | default: | ||
783 | DPRINTK("no-byte command\n"); | ||
784 | goto invalid_fld; | ||
785 | } | ||
647 | 786 | ||
648 | tf->nsect = scsicmd[8]; | 787 | /* Check and compose ATA command */ |
649 | tf->lbal = scsicmd[5]; | 788 | if (!n_block) |
650 | tf->lbam = scsicmd[4]; | 789 | /* For 10-byte and 16-byte SCSI R/W commands, transfer |
651 | tf->lbah = scsicmd[3]; | 790 | * length 0 means transfer 0 block of data. |
791 | * However, for ATA R/W commands, sector count 0 means | ||
792 | * 256 or 65536 sectors, not 0 sectors as in SCSI. | ||
793 | */ | ||
794 | goto nothing_to_do; | ||
652 | 795 | ||
653 | VPRINTK("ten-byte command\n"); | 796 | if (lba) { |
654 | if (qc->nsect == 0) /* we don't support length==0 cmds */ | 797 | if (lba48) { |
655 | return 1; | 798 | /* The request -may- be too large for LBA48. */ |
656 | return 0; | 799 | if ((block >> 48) || (n_block > 65536)) |
657 | } | 800 | goto out_of_range; |
658 | 801 | ||
659 | if (scsicmd[0] == READ_6 || scsicmd[0] == WRITE_6) { | 802 | tf->hob_nsect = (n_block >> 8) & 0xff; |
660 | qc->nsect = tf->nsect = scsicmd[4]; | ||
661 | if (!qc->nsect) { | ||
662 | qc->nsect = 256; | ||
663 | if (lba48) | ||
664 | tf->hob_nsect = 1; | ||
665 | } | ||
666 | 803 | ||
667 | tf->lbal = scsicmd[3]; | 804 | tf->hob_lbah = (block >> 40) & 0xff; |
668 | tf->lbam = scsicmd[2]; | 805 | tf->hob_lbam = (block >> 32) & 0xff; |
669 | tf->lbah = scsicmd[1] & 0x1f; /* mask out reserved bits */ | 806 | tf->hob_lbal = (block >> 24) & 0xff; |
807 | } else { | ||
808 | /* LBA28 */ | ||
670 | 809 | ||
671 | VPRINTK("six-byte command\n"); | 810 | /* The request -may- be too large for LBA28. */ |
672 | return 0; | 811 | if ((block >> 28) || (n_block > 256)) |
673 | } | 812 | goto out_of_range; |
674 | 813 | ||
675 | if (scsicmd[0] == READ_16 || scsicmd[0] == WRITE_16) { | 814 | tf->device |= (block >> 24) & 0xf; |
676 | /* rule out impossible LBAs and sector counts */ | 815 | } |
677 | if (scsicmd[2] || scsicmd[3] || scsicmd[10] || scsicmd[11]) | ||
678 | return 1; | ||
679 | 816 | ||
680 | if (lba48) { | 817 | qc->nsect = n_block; |
681 | tf->hob_nsect = scsicmd[12]; | 818 | tf->nsect = n_block & 0xff; |
682 | tf->hob_lbal = scsicmd[6]; | ||
683 | tf->hob_lbam = scsicmd[5]; | ||
684 | tf->hob_lbah = scsicmd[4]; | ||
685 | 819 | ||
686 | qc->nsect = ((unsigned int)scsicmd[12] << 8) | | 820 | tf->lbah = (block >> 16) & 0xff; |
687 | scsicmd[13]; | 821 | tf->lbam = (block >> 8) & 0xff; |
688 | } else { | 822 | tf->lbal = block & 0xff; |
689 | /* once again, filter out impossible non-zero values */ | ||
690 | if (scsicmd[4] || scsicmd[5] || scsicmd[12] || | ||
691 | (scsicmd[6] & 0xf0)) | ||
692 | return 1; | ||
693 | 823 | ||
694 | /* stores LBA27:24 in lower 4 bits of device reg */ | 824 | tf->device |= ATA_LBA; |
695 | tf->device |= scsicmd[6]; | 825 | } else { |
826 | /* CHS */ | ||
827 | u32 sect, head, cyl, track; | ||
828 | |||
829 | /* The request -may- be too large for CHS addressing. */ | ||
830 | if ((block >> 28) || (n_block > 256)) | ||
831 | goto out_of_range; | ||
832 | |||
833 | /* Convert LBA to CHS */ | ||
834 | track = (u32)block / dev->sectors; | ||
835 | cyl = track / dev->heads; | ||
836 | head = track % dev->heads; | ||
837 | sect = (u32)block % dev->sectors + 1; | ||
838 | |||
839 | DPRINTK("block %u track %u cyl %u head %u sect %u\n", | ||
840 | (u32)block, track, cyl, head, sect); | ||
841 | |||
842 | /* Check whether the converted CHS can fit. | ||
843 | Cylinder: 0-65535 | ||
844 | Head: 0-15 | ||
845 | Sector: 1-255*/ | ||
846 | if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) | ||
847 | goto out_of_range; | ||
848 | |||
849 | qc->nsect = n_block; | ||
850 | tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ | ||
851 | tf->lbal = sect; | ||
852 | tf->lbam = cyl; | ||
853 | tf->lbah = cyl >> 8; | ||
854 | tf->device |= head; | ||
855 | } | ||
696 | 856 | ||
697 | qc->nsect = scsicmd[13]; | 857 | return 0; |
698 | } | ||
699 | 858 | ||
700 | tf->nsect = scsicmd[13]; | 859 | invalid_fld: |
701 | tf->lbal = scsicmd[9]; | 860 | ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); |
702 | tf->lbam = scsicmd[8]; | 861 | /* "Invalid field in cbd" */ |
703 | tf->lbah = scsicmd[7]; | 862 | return 1; |
704 | 863 | ||
705 | VPRINTK("sixteen-byte command\n"); | 864 | out_of_range: |
706 | if (qc->nsect == 0) /* we don't support length==0 cmds */ | 865 | ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0); |
707 | return 1; | 866 | /* "Logical Block Address out of range" */ |
708 | return 0; | 867 | return 1; |
709 | } | ||
710 | 868 | ||
711 | DPRINTK("no-byte command\n"); | 869 | nothing_to_do: |
870 | qc->scsicmd->result = SAM_STAT_GOOD; | ||
712 | return 1; | 871 | return 1; |
713 | } | 872 | } |
714 | 873 | ||
@@ -741,6 +900,12 @@ static int ata_scsi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | |||
741 | * This function sets up an ata_queued_cmd structure for the | 900 | * This function sets up an ata_queued_cmd structure for the |
742 | * SCSI command, and sends that ata_queued_cmd to the hardware. | 901 | * SCSI command, and sends that ata_queued_cmd to the hardware. |
743 | * | 902 | * |
903 | * The xlat_func argument (actor) returns 0 if ready to execute | ||
904 | * ATA command, else 1 to finish translation. If 1 is returned | ||
905 | * then cmd->result (and possibly cmd->sense_buffer) are assumed | ||
906 | * to be set reflecting an error condition or clean (early) | ||
907 | * termination. | ||
908 | * | ||
744 | * LOCKING: | 909 | * LOCKING: |
745 | * spin_lock_irqsave(host_set lock) | 910 | * spin_lock_irqsave(host_set lock) |
746 | */ | 911 | */ |
@@ -757,7 +922,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
757 | 922 | ||
758 | qc = ata_scsi_qc_new(ap, dev, cmd, done); | 923 | qc = ata_scsi_qc_new(ap, dev, cmd, done); |
759 | if (!qc) | 924 | if (!qc) |
760 | return; | 925 | goto err_mem; |
761 | 926 | ||
762 | /* data is present; dma-map it */ | 927 | /* data is present; dma-map it */ |
763 | if (cmd->sc_data_direction == DMA_FROM_DEVICE || | 928 | if (cmd->sc_data_direction == DMA_FROM_DEVICE || |
@@ -765,7 +930,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
765 | if (unlikely(cmd->request_bufflen < 1)) { | 930 | if (unlikely(cmd->request_bufflen < 1)) { |
766 | printk(KERN_WARNING "ata%u(%u): WARNING: zero len r/w req\n", | 931 | printk(KERN_WARNING "ata%u(%u): WARNING: zero len r/w req\n", |
767 | ap->id, dev->devno); | 932 | ap->id, dev->devno); |
768 | goto err_out; | 933 | goto err_did; |
769 | } | 934 | } |
770 | 935 | ||
771 | if (cmd->use_sg) | 936 | if (cmd->use_sg) |
@@ -780,19 +945,28 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
780 | qc->complete_fn = ata_scsi_qc_complete; | 945 | qc->complete_fn = ata_scsi_qc_complete; |
781 | 946 | ||
782 | if (xlat_func(qc, scsicmd)) | 947 | if (xlat_func(qc, scsicmd)) |
783 | goto err_out; | 948 | goto early_finish; |
784 | 949 | ||
785 | /* select device, send command to hardware */ | 950 | /* select device, send command to hardware */ |
786 | if (ata_qc_issue(qc)) | 951 | if (ata_qc_issue(qc)) |
787 | goto err_out; | 952 | goto err_did; |
788 | 953 | ||
789 | VPRINTK("EXIT\n"); | 954 | VPRINTK("EXIT\n"); |
790 | return; | 955 | return; |
791 | 956 | ||
792 | err_out: | 957 | early_finish: |
958 | ata_qc_free(qc); | ||
959 | done(cmd); | ||
960 | DPRINTK("EXIT - early finish (good or error)\n"); | ||
961 | return; | ||
962 | |||
963 | err_did: | ||
793 | ata_qc_free(qc); | 964 | ata_qc_free(qc); |
794 | ata_bad_cdb(cmd, done); | 965 | err_mem: |
795 | DPRINTK("EXIT - badcmd\n"); | 966 | cmd->result = (DID_ERROR << 16); |
967 | done(cmd); | ||
968 | DPRINTK("EXIT - internal\n"); | ||
969 | return; | ||
796 | } | 970 | } |
797 | 971 | ||
798 | /** | 972 | /** |
@@ -859,7 +1033,8 @@ static inline void ata_scsi_rbuf_put(struct scsi_cmnd *cmd, u8 *buf) | |||
859 | * Mapping the response buffer, calling the command's handler, | 1033 | * Mapping the response buffer, calling the command's handler, |
860 | * and handling the handler's return value. This return value | 1034 | * and handling the handler's return value. This return value |
861 | * indicates whether the handler wishes the SCSI command to be | 1035 | * indicates whether the handler wishes the SCSI command to be |
862 | * completed successfully, or not. | 1036 | * completed successfully (0), or not (in which case cmd->result |
1037 | * and sense buffer are assumed to be set). | ||
863 | * | 1038 | * |
864 | * LOCKING: | 1039 | * LOCKING: |
865 | * spin_lock_irqsave(host_set lock) | 1040 | * spin_lock_irqsave(host_set lock) |
@@ -878,12 +1053,9 @@ void ata_scsi_rbuf_fill(struct ata_scsi_args *args, | |||
878 | rc = actor(args, rbuf, buflen); | 1053 | rc = actor(args, rbuf, buflen); |
879 | ata_scsi_rbuf_put(cmd, rbuf); | 1054 | ata_scsi_rbuf_put(cmd, rbuf); |
880 | 1055 | ||
881 | if (rc) | 1056 | if (rc == 0) |
882 | ata_bad_cdb(cmd, args->done); | ||
883 | else { | ||
884 | cmd->result = SAM_STAT_GOOD; | 1057 | cmd->result = SAM_STAT_GOOD; |
885 | args->done(cmd); | 1058 | args->done(cmd); |
886 | } | ||
887 | } | 1059 | } |
888 | 1060 | ||
889 | /** | 1061 | /** |
@@ -1189,8 +1361,16 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf, | |||
1189 | * in the same manner) | 1361 | * in the same manner) |
1190 | */ | 1362 | */ |
1191 | page_control = scsicmd[2] >> 6; | 1363 | page_control = scsicmd[2] >> 6; |
1192 | if ((page_control != 0) && (page_control != 3)) | 1364 | switch (page_control) { |
1193 | return 1; | 1365 | case 0: /* current */ |
1366 | break; /* supported */ | ||
1367 | case 3: /* saved */ | ||
1368 | goto saving_not_supp; | ||
1369 | case 1: /* changeable */ | ||
1370 | case 2: /* defaults */ | ||
1371 | default: | ||
1372 | goto invalid_fld; | ||
1373 | } | ||
1194 | 1374 | ||
1195 | if (six_byte) | 1375 | if (six_byte) |
1196 | output_len = 4; | 1376 | output_len = 4; |
@@ -1221,7 +1401,7 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf, | |||
1221 | break; | 1401 | break; |
1222 | 1402 | ||
1223 | default: /* invalid page code */ | 1403 | default: /* invalid page code */ |
1224 | return 1; | 1404 | goto invalid_fld; |
1225 | } | 1405 | } |
1226 | 1406 | ||
1227 | if (six_byte) { | 1407 | if (six_byte) { |
@@ -1234,6 +1414,16 @@ unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf, | |||
1234 | } | 1414 | } |
1235 | 1415 | ||
1236 | return 0; | 1416 | return 0; |
1417 | |||
1418 | invalid_fld: | ||
1419 | ata_scsi_set_sense(args->cmd, ILLEGAL_REQUEST, 0x24, 0x0); | ||
1420 | /* "Invalid field in cbd" */ | ||
1421 | return 1; | ||
1422 | |||
1423 | saving_not_supp: | ||
1424 | ata_scsi_set_sense(args->cmd, ILLEGAL_REQUEST, 0x39, 0x0); | ||
1425 | /* "Saving parameters not supported" */ | ||
1426 | return 1; | ||
1237 | } | 1427 | } |
1238 | 1428 | ||
1239 | /** | 1429 | /** |
@@ -1256,10 +1446,20 @@ unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf, | |||
1256 | 1446 | ||
1257 | VPRINTK("ENTER\n"); | 1447 | VPRINTK("ENTER\n"); |
1258 | 1448 | ||
1259 | if (ata_id_has_lba48(args->id)) | 1449 | if (ata_id_has_lba(args->id)) { |
1260 | n_sectors = ata_id_u64(args->id, 100); | 1450 | if (ata_id_has_lba48(args->id)) |
1261 | else | 1451 | n_sectors = ata_id_u64(args->id, 100); |
1262 | n_sectors = ata_id_u32(args->id, 60); | 1452 | else |
1453 | n_sectors = ata_id_u32(args->id, 60); | ||
1454 | } else { | ||
1455 | /* CHS default translation */ | ||
1456 | n_sectors = args->id[1] * args->id[3] * args->id[6]; | ||
1457 | |||
1458 | if (ata_id_current_chs_valid(args->id)) | ||
1459 | /* CHS current translation */ | ||
1460 | n_sectors = ata_id_u32(args->id, 57); | ||
1461 | } | ||
1462 | |||
1263 | n_sectors--; /* ATA TotalUserSectors - 1 */ | 1463 | n_sectors--; /* ATA TotalUserSectors - 1 */ |
1264 | 1464 | ||
1265 | if (args->cmd->cmnd[0] == READ_CAPACITY) { | 1465 | if (args->cmd->cmnd[0] == READ_CAPACITY) { |
@@ -1323,6 +1523,34 @@ unsigned int ata_scsiop_report_luns(struct ata_scsi_args *args, u8 *rbuf, | |||
1323 | } | 1523 | } |
1324 | 1524 | ||
1325 | /** | 1525 | /** |
1526 | * ata_scsi_set_sense - Set SCSI sense data and status | ||
1527 | * @cmd: SCSI request to be handled | ||
1528 | * @sk: SCSI-defined sense key | ||
1529 | * @asc: SCSI-defined additional sense code | ||
1530 | * @ascq: SCSI-defined additional sense code qualifier | ||
1531 | * | ||
1532 | * Helper function that builds a valid fixed format, current | ||
1533 | * response code and the given sense key (sk), additional sense | ||
1534 | * code (asc) and additional sense code qualifier (ascq) with | ||
1535 | * a SCSI command status of %SAM_STAT_CHECK_CONDITION and | ||
1536 | * DRIVER_SENSE set in the upper bits of scsi_cmnd::result . | ||
1537 | * | ||
1538 | * LOCKING: | ||
1539 | * Not required | ||
1540 | */ | ||
1541 | |||
1542 | void ata_scsi_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq) | ||
1543 | { | ||
1544 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | ||
1545 | |||
1546 | cmd->sense_buffer[0] = 0x70; /* fixed format, current */ | ||
1547 | cmd->sense_buffer[2] = sk; | ||
1548 | cmd->sense_buffer[7] = 18 - 8; /* additional sense length */ | ||
1549 | cmd->sense_buffer[12] = asc; | ||
1550 | cmd->sense_buffer[13] = ascq; | ||
1551 | } | ||
1552 | |||
1553 | /** | ||
1326 | * ata_scsi_badcmd - End a SCSI request with an error | 1554 | * ata_scsi_badcmd - End a SCSI request with an error |
1327 | * @cmd: SCSI request to be handled | 1555 | * @cmd: SCSI request to be handled |
1328 | * @done: SCSI command completion function | 1556 | * @done: SCSI command completion function |
@@ -1340,30 +1568,84 @@ unsigned int ata_scsiop_report_luns(struct ata_scsi_args *args, u8 *rbuf, | |||
1340 | void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8 asc, u8 ascq) | 1568 | void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8 asc, u8 ascq) |
1341 | { | 1569 | { |
1342 | DPRINTK("ENTER\n"); | 1570 | DPRINTK("ENTER\n"); |
1343 | cmd->result = SAM_STAT_CHECK_CONDITION; | 1571 | ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, asc, ascq); |
1344 | |||
1345 | cmd->sense_buffer[0] = 0x70; | ||
1346 | cmd->sense_buffer[2] = ILLEGAL_REQUEST; | ||
1347 | cmd->sense_buffer[7] = 14 - 8; /* addnl. sense len. FIXME: correct? */ | ||
1348 | cmd->sense_buffer[12] = asc; | ||
1349 | cmd->sense_buffer[13] = ascq; | ||
1350 | 1572 | ||
1351 | done(cmd); | 1573 | done(cmd); |
1352 | } | 1574 | } |
1353 | 1575 | ||
1576 | void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, | ||
1577 | struct scsi_cmnd *cmd) | ||
1578 | { | ||
1579 | DECLARE_COMPLETION(wait); | ||
1580 | struct ata_queued_cmd *qc; | ||
1581 | unsigned long flags; | ||
1582 | int rc; | ||
1583 | |||
1584 | DPRINTK("ATAPI request sense\n"); | ||
1585 | |||
1586 | qc = ata_qc_new_init(ap, dev); | ||
1587 | BUG_ON(qc == NULL); | ||
1588 | |||
1589 | /* FIXME: is this needed? */ | ||
1590 | memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer)); | ||
1591 | |||
1592 | ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); | ||
1593 | qc->dma_dir = DMA_FROM_DEVICE; | ||
1594 | |||
1595 | memset(&qc->cdb, 0, ap->cdb_len); | ||
1596 | qc->cdb[0] = REQUEST_SENSE; | ||
1597 | qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; | ||
1598 | |||
1599 | qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | ||
1600 | qc->tf.command = ATA_CMD_PACKET; | ||
1601 | |||
1602 | qc->tf.protocol = ATA_PROT_ATAPI; | ||
1603 | qc->tf.lbam = (8 * 1024) & 0xff; | ||
1604 | qc->tf.lbah = (8 * 1024) >> 8; | ||
1605 | qc->nbytes = SCSI_SENSE_BUFFERSIZE; | ||
1606 | |||
1607 | qc->waiting = &wait; | ||
1608 | qc->complete_fn = ata_qc_complete_noop; | ||
1609 | |||
1610 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
1611 | rc = ata_qc_issue(qc); | ||
1612 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
1613 | |||
1614 | if (rc) | ||
1615 | ata_port_disable(ap); | ||
1616 | else | ||
1617 | wait_for_completion(&wait); | ||
1618 | |||
1619 | DPRINTK("EXIT\n"); | ||
1620 | } | ||
1621 | |||
1354 | static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | 1622 | static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) |
1355 | { | 1623 | { |
1356 | struct scsi_cmnd *cmd = qc->scsicmd; | 1624 | struct scsi_cmnd *cmd = qc->scsicmd; |
1357 | 1625 | ||
1358 | if (unlikely(drv_stat & (ATA_ERR | ATA_BUSY | ATA_DRQ))) { | 1626 | VPRINTK("ENTER, drv_stat == 0x%x\n", drv_stat); |
1627 | |||
1628 | if (unlikely(drv_stat & (ATA_BUSY | ATA_DRQ))) | ||
1629 | ata_to_sense_error(qc, drv_stat); | ||
1630 | |||
1631 | else if (unlikely(drv_stat & ATA_ERR)) { | ||
1359 | DPRINTK("request check condition\n"); | 1632 | DPRINTK("request check condition\n"); |
1360 | 1633 | ||
1634 | /* FIXME: command completion with check condition | ||
1635 | * but no sense causes the error handler to run, | ||
1636 | * which then issues REQUEST SENSE, fills in the sense | ||
1637 | * buffer, and completes the command (for the second | ||
1638 | * time). We need to issue REQUEST SENSE some other | ||
1639 | * way, to avoid completing the command twice. | ||
1640 | */ | ||
1361 | cmd->result = SAM_STAT_CHECK_CONDITION; | 1641 | cmd->result = SAM_STAT_CHECK_CONDITION; |
1362 | 1642 | ||
1363 | qc->scsidone(cmd); | 1643 | qc->scsidone(cmd); |
1364 | 1644 | ||
1365 | return 1; | 1645 | return 1; |
1366 | } else { | 1646 | } |
1647 | |||
1648 | else { | ||
1367 | u8 *scsicmd = cmd->cmnd; | 1649 | u8 *scsicmd = cmd->cmnd; |
1368 | 1650 | ||
1369 | if (scsicmd[0] == INQUIRY) { | 1651 | if (scsicmd[0] == INQUIRY) { |
@@ -1371,15 +1653,30 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | |||
1371 | unsigned int buflen; | 1653 | unsigned int buflen; |
1372 | 1654 | ||
1373 | buflen = ata_scsi_rbuf_get(cmd, &buf); | 1655 | buflen = ata_scsi_rbuf_get(cmd, &buf); |
1374 | buf[2] = 0x5; | 1656 | |
1375 | buf[3] = (buf[3] & 0xf0) | 2; | 1657 | /* ATAPI devices typically report zero for their SCSI version, |
1658 | * and sometimes deviate from the spec WRT response data | ||
1659 | * format. If SCSI version is reported as zero like normal, | ||
1660 | * then we make the following fixups: 1) Fake MMC-5 version, | ||
1661 | * to indicate to the Linux scsi midlayer this is a modern | ||
1662 | * device. 2) Ensure response data format / ATAPI information | ||
1663 | * are always correct. | ||
1664 | */ | ||
1665 | /* FIXME: do we ever override EVPD pages and the like, with | ||
1666 | * this code? | ||
1667 | */ | ||
1668 | if (buf[2] == 0) { | ||
1669 | buf[2] = 0x5; | ||
1670 | buf[3] = 0x32; | ||
1671 | } | ||
1672 | |||
1376 | ata_scsi_rbuf_put(cmd, buf); | 1673 | ata_scsi_rbuf_put(cmd, buf); |
1377 | } | 1674 | } |
1675 | |||
1378 | cmd->result = SAM_STAT_GOOD; | 1676 | cmd->result = SAM_STAT_GOOD; |
1379 | } | 1677 | } |
1380 | 1678 | ||
1381 | qc->scsidone(cmd); | 1679 | qc->scsidone(cmd); |
1382 | |||
1383 | return 0; | 1680 | return 0; |
1384 | } | 1681 | } |
1385 | /** | 1682 | /** |
@@ -1640,7 +1937,7 @@ void ata_scsi_simulate(u16 *id, | |||
1640 | 1937 | ||
1641 | case INQUIRY: | 1938 | case INQUIRY: |
1642 | if (scsicmd[1] & 2) /* is CmdDt set? */ | 1939 | if (scsicmd[1] & 2) /* is CmdDt set? */ |
1643 | ata_bad_cdb(cmd, done); | 1940 | ata_scsi_invalid_field(cmd, done); |
1644 | else if ((scsicmd[1] & 1) == 0) /* is EVPD clear? */ | 1941 | else if ((scsicmd[1] & 1) == 0) /* is EVPD clear? */ |
1645 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_std); | 1942 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_std); |
1646 | else if (scsicmd[2] == 0x00) | 1943 | else if (scsicmd[2] == 0x00) |
@@ -1650,7 +1947,7 @@ void ata_scsi_simulate(u16 *id, | |||
1650 | else if (scsicmd[2] == 0x83) | 1947 | else if (scsicmd[2] == 0x83) |
1651 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_83); | 1948 | ata_scsi_rbuf_fill(&args, ata_scsiop_inq_83); |
1652 | else | 1949 | else |
1653 | ata_bad_cdb(cmd, done); | 1950 | ata_scsi_invalid_field(cmd, done); |
1654 | break; | 1951 | break; |
1655 | 1952 | ||
1656 | case MODE_SENSE: | 1953 | case MODE_SENSE: |
@@ -1660,7 +1957,7 @@ void ata_scsi_simulate(u16 *id, | |||
1660 | 1957 | ||
1661 | case MODE_SELECT: /* unconditionally return */ | 1958 | case MODE_SELECT: /* unconditionally return */ |
1662 | case MODE_SELECT_10: /* bad-field-in-cdb */ | 1959 | case MODE_SELECT_10: /* bad-field-in-cdb */ |
1663 | ata_bad_cdb(cmd, done); | 1960 | ata_scsi_invalid_field(cmd, done); |
1664 | break; | 1961 | break; |
1665 | 1962 | ||
1666 | case READ_CAPACITY: | 1963 | case READ_CAPACITY: |
@@ -1671,7 +1968,7 @@ void ata_scsi_simulate(u16 *id, | |||
1671 | if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16) | 1968 | if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16) |
1672 | ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap); | 1969 | ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap); |
1673 | else | 1970 | else |
1674 | ata_bad_cdb(cmd, done); | 1971 | ata_scsi_invalid_field(cmd, done); |
1675 | break; | 1972 | break; |
1676 | 1973 | ||
1677 | case REPORT_LUNS: | 1974 | case REPORT_LUNS: |
@@ -1683,8 +1980,26 @@ void ata_scsi_simulate(u16 *id, | |||
1683 | 1980 | ||
1684 | /* all other commands */ | 1981 | /* all other commands */ |
1685 | default: | 1982 | default: |
1686 | ata_bad_scsiop(cmd, done); | 1983 | ata_scsi_set_sense(cmd, ILLEGAL_REQUEST, 0x20, 0x0); |
1984 | /* "Invalid command operation code" */ | ||
1985 | done(cmd); | ||
1687 | break; | 1986 | break; |
1688 | } | 1987 | } |
1689 | } | 1988 | } |
1690 | 1989 | ||
1990 | void ata_scsi_scan_host(struct ata_port *ap) | ||
1991 | { | ||
1992 | struct ata_device *dev; | ||
1993 | unsigned int i; | ||
1994 | |||
1995 | if (ap->flags & ATA_FLAG_PORT_DISABLED) | ||
1996 | return; | ||
1997 | |||
1998 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | ||
1999 | dev = &ap->device[i]; | ||
2000 | |||
2001 | if (ata_dev_present(dev)) | ||
2002 | scsi_scan_target(&ap->host->shost_gendev, 0, i, 0, 0); | ||
2003 | } | ||
2004 | } | ||
2005 | |||