diff options
author | Trond Myklebust <Trond.Myklebust@netapp.com> | 2006-03-23 23:44:19 -0500 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2006-03-23 23:44:19 -0500 |
commit | 1ebbe2b20091d306453a5cf480a87e6cd28ae76f (patch) | |
tree | f5cd7a0fa69b8b1938cb5a0faed2e7b0628072a5 /drivers/scsi/libata-scsi.c | |
parent | ac58c9059da8886b5e8cde012a80266b18ca146e (diff) | |
parent | 674a396c6d2ba0341ebdd7c1c9950f32f018e2dd (diff) |
Merge branch 'linus'
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
-rw-r--r-- | drivers/scsi/libata-scsi.c | 372 |
1 files changed, 255 insertions, 117 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c index 59503c9ccac9..a1259b242b8e 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_transport.h> | ||
44 | #include <linux/libata.h> | 45 | #include <linux/libata.h> |
45 | #include <linux/hdreg.h> | 46 | #include <linux/hdreg.h> |
46 | #include <asm/uaccess.h> | 47 | #include <asm/uaccess.h> |
@@ -52,6 +53,7 @@ | |||
52 | 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); |
53 | static struct ata_device * | 54 | static struct ata_device * |
54 | 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 | enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); | ||
55 | 57 | ||
56 | #define RW_RECOVERY_MPAGE 0x1 | 58 | #define RW_RECOVERY_MPAGE 0x1 |
57 | #define RW_RECOVERY_MPAGE_LEN 12 | 59 | #define RW_RECOVERY_MPAGE_LEN 12 |
@@ -92,6 +94,14 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = { | |||
92 | 0, 30 /* extended self test time, see 05-359r1 */ | 94 | 0, 30 /* extended self test time, see 05-359r1 */ |
93 | }; | 95 | }; |
94 | 96 | ||
97 | /* | ||
98 | * libata transport template. libata doesn't do real transport stuff. | ||
99 | * It just needs the eh_timed_out hook. | ||
100 | */ | ||
101 | struct scsi_transport_template ata_scsi_transport_template = { | ||
102 | .eh_timed_out = ata_scsi_timed_out, | ||
103 | }; | ||
104 | |||
95 | 105 | ||
96 | static void ata_scsi_invalid_field(struct scsi_cmnd *cmd, | 106 | static void ata_scsi_invalid_field(struct scsi_cmnd *cmd, |
97 | void (*done)(struct scsi_cmnd *)) | 107 | void (*done)(struct scsi_cmnd *)) |
@@ -151,7 +161,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
151 | struct scsi_sense_hdr sshdr; | 161 | struct scsi_sense_hdr sshdr; |
152 | enum dma_data_direction data_dir; | 162 | enum dma_data_direction data_dir; |
153 | 163 | ||
154 | if (NULL == (void *)arg) | 164 | if (arg == NULL) |
155 | return -EINVAL; | 165 | return -EINVAL; |
156 | 166 | ||
157 | if (copy_from_user(args, arg, sizeof(args))) | 167 | if (copy_from_user(args, arg, sizeof(args))) |
@@ -201,7 +211,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
201 | /* Need code to retrieve data from check condition? */ | 211 | /* Need code to retrieve data from check condition? */ |
202 | 212 | ||
203 | if ((argbuf) | 213 | if ((argbuf) |
204 | && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize)) | 214 | && copy_to_user(arg + sizeof(args), argbuf, argsize)) |
205 | rc = -EFAULT; | 215 | rc = -EFAULT; |
206 | error: | 216 | error: |
207 | if (argbuf) | 217 | if (argbuf) |
@@ -228,7 +238,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
228 | u8 args[7]; | 238 | u8 args[7]; |
229 | struct scsi_sense_hdr sshdr; | 239 | struct scsi_sense_hdr sshdr; |
230 | 240 | ||
231 | if (NULL == (void *)arg) | 241 | if (arg == NULL) |
232 | return -EINVAL; | 242 | return -EINVAL; |
233 | 243 | ||
234 | if (copy_from_user(args, arg, sizeof(args))) | 244 | if (copy_from_user(args, arg, sizeof(args))) |
@@ -511,13 +521,11 @@ void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, | |||
511 | printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n", | 521 | printk(KERN_WARNING "ata%u: no sense translation for status: 0x%02x\n", |
512 | id, drv_stat); | 522 | id, drv_stat); |
513 | 523 | ||
514 | /* For our last chance pick, use medium read error because | 524 | /* We need a sensible error return here, which is tricky, and one |
515 | * it's much more common than an ATA drive telling you a write | 525 | that won't cause people to do things like return a disk wrongly */ |
516 | * has failed. | 526 | *sk = ABORTED_COMMAND; |
517 | */ | 527 | *asc = 0x00; |
518 | *sk = MEDIUM_ERROR; | 528 | *ascq = 0x00; |
519 | *asc = 0x11; /* "unrecovered read error" */ | ||
520 | *ascq = 0x04; /* "auto-reallocation failed" */ | ||
521 | 529 | ||
522 | translate_done: | 530 | translate_done: |
523 | printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to " | 531 | printk(KERN_ERR "ata%u: translated ATA stat/err 0x%02x/%02x to " |
@@ -553,7 +561,7 @@ void ata_gen_ata_desc_sense(struct ata_queued_cmd *qc) | |||
553 | /* | 561 | /* |
554 | * Read the controller registers. | 562 | * Read the controller registers. |
555 | */ | 563 | */ |
556 | assert(NULL != qc->ap->ops->tf_read); | 564 | WARN_ON(qc->ap->ops->tf_read == NULL); |
557 | qc->ap->ops->tf_read(qc->ap, tf); | 565 | qc->ap->ops->tf_read(qc->ap, tf); |
558 | 566 | ||
559 | /* | 567 | /* |
@@ -628,7 +636,7 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc) | |||
628 | /* | 636 | /* |
629 | * Read the controller registers. | 637 | * Read the controller registers. |
630 | */ | 638 | */ |
631 | assert(NULL != qc->ap->ops->tf_read); | 639 | WARN_ON(qc->ap->ops->tf_read == NULL); |
632 | qc->ap->ops->tf_read(qc->ap, tf); | 640 | qc->ap->ops->tf_read(qc->ap, tf); |
633 | 641 | ||
634 | /* | 642 | /* |
@@ -662,6 +670,41 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc) | |||
662 | } | 670 | } |
663 | } | 671 | } |
664 | 672 | ||
673 | static void ata_scsi_sdev_config(struct scsi_device *sdev) | ||
674 | { | ||
675 | sdev->use_10_for_rw = 1; | ||
676 | sdev->use_10_for_ms = 1; | ||
677 | } | ||
678 | |||
679 | static void ata_scsi_dev_config(struct scsi_device *sdev, | ||
680 | struct ata_device *dev) | ||
681 | { | ||
682 | unsigned int max_sectors; | ||
683 | |||
684 | /* TODO: 2048 is an arbitrary number, not the | ||
685 | * hardware maximum. This should be increased to | ||
686 | * 65534 when Jens Axboe's patch for dynamically | ||
687 | * determining max_sectors is merged. | ||
688 | */ | ||
689 | max_sectors = ATA_MAX_SECTORS; | ||
690 | if (dev->flags & ATA_DFLAG_LBA48) | ||
691 | max_sectors = 2048; | ||
692 | if (dev->max_sectors) | ||
693 | max_sectors = dev->max_sectors; | ||
694 | |||
695 | blk_queue_max_sectors(sdev->request_queue, max_sectors); | ||
696 | |||
697 | /* | ||
698 | * SATA DMA transfers must be multiples of 4 byte, so | ||
699 | * we need to pad ATAPI transfers using an extra sg. | ||
700 | * Decrement max hw segments accordingly. | ||
701 | */ | ||
702 | if (dev->class == ATA_DEV_ATAPI) { | ||
703 | request_queue_t *q = sdev->request_queue; | ||
704 | blk_queue_max_hw_segments(q, q->max_hw_segments - 1); | ||
705 | } | ||
706 | } | ||
707 | |||
665 | /** | 708 | /** |
666 | * ata_scsi_slave_config - Set SCSI device attributes | 709 | * ata_scsi_slave_config - Set SCSI device attributes |
667 | * @sdev: SCSI device to examine | 710 | * @sdev: SCSI device to examine |
@@ -676,8 +719,7 @@ void ata_gen_fixed_sense(struct ata_queued_cmd *qc) | |||
676 | 719 | ||
677 | int ata_scsi_slave_config(struct scsi_device *sdev) | 720 | int ata_scsi_slave_config(struct scsi_device *sdev) |
678 | { | 721 | { |
679 | sdev->use_10_for_rw = 1; | 722 | ata_scsi_sdev_config(sdev); |
680 | sdev->use_10_for_ms = 1; | ||
681 | 723 | ||
682 | blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD); | 724 | blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD); |
683 | 725 | ||
@@ -688,35 +730,54 @@ int ata_scsi_slave_config(struct scsi_device *sdev) | |||
688 | ap = (struct ata_port *) &sdev->host->hostdata[0]; | 730 | ap = (struct ata_port *) &sdev->host->hostdata[0]; |
689 | dev = &ap->device[sdev->id]; | 731 | dev = &ap->device[sdev->id]; |
690 | 732 | ||
691 | /* TODO: 1024 is an arbitrary number, not the | 733 | ata_scsi_dev_config(sdev, dev); |
692 | * hardware maximum. This should be increased to | ||
693 | * 65534 when Jens Axboe's patch for dynamically | ||
694 | * determining max_sectors is merged. | ||
695 | */ | ||
696 | if ((dev->flags & ATA_DFLAG_LBA48) && | ||
697 | ((dev->flags & ATA_DFLAG_LOCK_SECTORS) == 0)) { | ||
698 | /* | ||
699 | * do not overwrite sdev->host->max_sectors, since | ||
700 | * other drives on this host may not support LBA48 | ||
701 | */ | ||
702 | blk_queue_max_sectors(sdev->request_queue, 2048); | ||
703 | } | ||
704 | |||
705 | /* | ||
706 | * SATA DMA transfers must be multiples of 4 byte, so | ||
707 | * we need to pad ATAPI transfers using an extra sg. | ||
708 | * Decrement max hw segments accordingly. | ||
709 | */ | ||
710 | if (dev->class == ATA_DEV_ATAPI) { | ||
711 | request_queue_t *q = sdev->request_queue; | ||
712 | blk_queue_max_hw_segments(q, q->max_hw_segments - 1); | ||
713 | } | ||
714 | } | 734 | } |
715 | 735 | ||
716 | return 0; /* scsi layer doesn't check return value, sigh */ | 736 | return 0; /* scsi layer doesn't check return value, sigh */ |
717 | } | 737 | } |
718 | 738 | ||
719 | /** | 739 | /** |
740 | * ata_scsi_timed_out - SCSI layer time out callback | ||
741 | * @cmd: timed out SCSI command | ||
742 | * | ||
743 | * Handles SCSI layer timeout. We race with normal completion of | ||
744 | * the qc for @cmd. If the qc is already gone, we lose and let | ||
745 | * the scsi command finish (EH_HANDLED). Otherwise, the qc has | ||
746 | * timed out and EH should be invoked. Prevent ata_qc_complete() | ||
747 | * from finishing it by setting EH_SCHEDULED and return | ||
748 | * EH_NOT_HANDLED. | ||
749 | * | ||
750 | * LOCKING: | ||
751 | * Called from timer context | ||
752 | * | ||
753 | * RETURNS: | ||
754 | * EH_HANDLED or EH_NOT_HANDLED | ||
755 | */ | ||
756 | enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd) | ||
757 | { | ||
758 | struct Scsi_Host *host = cmd->device->host; | ||
759 | struct ata_port *ap = (struct ata_port *) &host->hostdata[0]; | ||
760 | unsigned long flags; | ||
761 | struct ata_queued_cmd *qc; | ||
762 | enum scsi_eh_timer_return ret = EH_HANDLED; | ||
763 | |||
764 | DPRINTK("ENTER\n"); | ||
765 | |||
766 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
767 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
768 | if (qc) { | ||
769 | WARN_ON(qc->scsicmd != cmd); | ||
770 | qc->flags |= ATA_QCFLAG_EH_SCHEDULED; | ||
771 | qc->err_mask |= AC_ERR_TIMEOUT; | ||
772 | ret = EH_NOT_HANDLED; | ||
773 | } | ||
774 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
775 | |||
776 | DPRINTK("EXIT, ret=%d\n", ret); | ||
777 | return ret; | ||
778 | } | ||
779 | |||
780 | /** | ||
720 | * ata_scsi_error - SCSI layer error handler callback | 781 | * ata_scsi_error - SCSI layer error handler callback |
721 | * @host: SCSI host on which error occurred | 782 | * @host: SCSI host on which error occurred |
722 | * | 783 | * |
@@ -732,23 +793,84 @@ int ata_scsi_slave_config(struct scsi_device *sdev) | |||
732 | int ata_scsi_error(struct Scsi_Host *host) | 793 | int ata_scsi_error(struct Scsi_Host *host) |
733 | { | 794 | { |
734 | struct ata_port *ap; | 795 | struct ata_port *ap; |
796 | unsigned long flags; | ||
735 | 797 | ||
736 | DPRINTK("ENTER\n"); | 798 | DPRINTK("ENTER\n"); |
737 | 799 | ||
738 | ap = (struct ata_port *) &host->hostdata[0]; | 800 | ap = (struct ata_port *) &host->hostdata[0]; |
801 | |||
802 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
803 | WARN_ON(ap->flags & ATA_FLAG_IN_EH); | ||
804 | ap->flags |= ATA_FLAG_IN_EH; | ||
805 | WARN_ON(ata_qc_from_tag(ap, ap->active_tag) == NULL); | ||
806 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
807 | |||
808 | ata_port_flush_task(ap); | ||
809 | |||
739 | ap->ops->eng_timeout(ap); | 810 | ap->ops->eng_timeout(ap); |
740 | 811 | ||
741 | /* TODO: this is per-command; when queueing is supported | 812 | WARN_ON(host->host_failed || !list_empty(&host->eh_cmd_q)); |
742 | * this code will either change or move to a more | 813 | |
743 | * appropriate place | 814 | scsi_eh_flush_done_q(&ap->eh_done_q); |
744 | */ | 815 | |
745 | host->host_failed--; | 816 | spin_lock_irqsave(&ap->host_set->lock, flags); |
746 | INIT_LIST_HEAD(&host->eh_cmd_q); | 817 | ap->flags &= ~ATA_FLAG_IN_EH; |
818 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
747 | 819 | ||
748 | DPRINTK("EXIT\n"); | 820 | DPRINTK("EXIT\n"); |
749 | return 0; | 821 | return 0; |
750 | } | 822 | } |
751 | 823 | ||
824 | static void ata_eh_scsidone(struct scsi_cmnd *scmd) | ||
825 | { | ||
826 | /* nada */ | ||
827 | } | ||
828 | |||
829 | static void __ata_eh_qc_complete(struct ata_queued_cmd *qc) | ||
830 | { | ||
831 | struct ata_port *ap = qc->ap; | ||
832 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
833 | unsigned long flags; | ||
834 | |||
835 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
836 | qc->scsidone = ata_eh_scsidone; | ||
837 | __ata_qc_complete(qc); | ||
838 | WARN_ON(ata_tag_valid(qc->tag)); | ||
839 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
840 | |||
841 | scsi_eh_finish_cmd(scmd, &ap->eh_done_q); | ||
842 | } | ||
843 | |||
844 | /** | ||
845 | * ata_eh_qc_complete - Complete an active ATA command from EH | ||
846 | * @qc: Command to complete | ||
847 | * | ||
848 | * Indicate to the mid and upper layers that an ATA command has | ||
849 | * completed. To be used from EH. | ||
850 | */ | ||
851 | void ata_eh_qc_complete(struct ata_queued_cmd *qc) | ||
852 | { | ||
853 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
854 | scmd->retries = scmd->allowed; | ||
855 | __ata_eh_qc_complete(qc); | ||
856 | } | ||
857 | |||
858 | /** | ||
859 | * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH | ||
860 | * @qc: Command to retry | ||
861 | * | ||
862 | * Indicate to the mid and upper layers that an ATA command | ||
863 | * should be retried. To be used from EH. | ||
864 | * | ||
865 | * SCSI midlayer limits the number of retries to scmd->allowed. | ||
866 | * This function might need to adjust scmd->retries for commands | ||
867 | * which get retried due to unrelated NCQ failures. | ||
868 | */ | ||
869 | void ata_eh_qc_retry(struct ata_queued_cmd *qc) | ||
870 | { | ||
871 | __ata_eh_qc_complete(qc); | ||
872 | } | ||
873 | |||
752 | /** | 874 | /** |
753 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command | 875 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command |
754 | * @qc: Storage for translated ATA taskfile | 876 | * @qc: Storage for translated ATA taskfile |
@@ -985,9 +1107,13 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
985 | if (dev->flags & ATA_DFLAG_LBA) { | 1107 | if (dev->flags & ATA_DFLAG_LBA) { |
986 | tf->flags |= ATA_TFLAG_LBA; | 1108 | tf->flags |= ATA_TFLAG_LBA; |
987 | 1109 | ||
988 | if (dev->flags & ATA_DFLAG_LBA48) { | 1110 | if (lba_28_ok(block, n_block)) { |
989 | if (n_block > (64 * 1024)) | 1111 | /* use LBA28 */ |
990 | goto invalid_fld; | 1112 | tf->command = ATA_CMD_VERIFY; |
1113 | tf->device |= (block >> 24) & 0xf; | ||
1114 | } else if (lba_48_ok(block, n_block)) { | ||
1115 | if (!(dev->flags & ATA_DFLAG_LBA48)) | ||
1116 | goto out_of_range; | ||
991 | 1117 | ||
992 | /* use LBA48 */ | 1118 | /* use LBA48 */ |
993 | tf->flags |= ATA_TFLAG_LBA48; | 1119 | tf->flags |= ATA_TFLAG_LBA48; |
@@ -998,15 +1124,9 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
998 | tf->hob_lbah = (block >> 40) & 0xff; | 1124 | tf->hob_lbah = (block >> 40) & 0xff; |
999 | tf->hob_lbam = (block >> 32) & 0xff; | 1125 | tf->hob_lbam = (block >> 32) & 0xff; |
1000 | tf->hob_lbal = (block >> 24) & 0xff; | 1126 | tf->hob_lbal = (block >> 24) & 0xff; |
1001 | } else { | 1127 | } else |
1002 | if (n_block > 256) | 1128 | /* request too large even for LBA48 */ |
1003 | goto invalid_fld; | 1129 | goto out_of_range; |
1004 | |||
1005 | /* use LBA28 */ | ||
1006 | tf->command = ATA_CMD_VERIFY; | ||
1007 | |||
1008 | tf->device |= (block >> 24) & 0xf; | ||
1009 | } | ||
1010 | 1130 | ||
1011 | tf->nsect = n_block & 0xff; | 1131 | tf->nsect = n_block & 0xff; |
1012 | 1132 | ||
@@ -1019,8 +1139,8 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
1019 | /* CHS */ | 1139 | /* CHS */ |
1020 | u32 sect, head, cyl, track; | 1140 | u32 sect, head, cyl, track; |
1021 | 1141 | ||
1022 | if (n_block > 256) | 1142 | if (!lba_28_ok(block, n_block)) |
1023 | goto invalid_fld; | 1143 | goto out_of_range; |
1024 | 1144 | ||
1025 | /* Convert LBA to CHS */ | 1145 | /* Convert LBA to CHS */ |
1026 | track = (u32)block / dev->sectors; | 1146 | track = (u32)block / dev->sectors; |
@@ -1139,9 +1259,11 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1139 | if (dev->flags & ATA_DFLAG_LBA) { | 1259 | if (dev->flags & ATA_DFLAG_LBA) { |
1140 | tf->flags |= ATA_TFLAG_LBA; | 1260 | tf->flags |= ATA_TFLAG_LBA; |
1141 | 1261 | ||
1142 | if (dev->flags & ATA_DFLAG_LBA48) { | 1262 | if (lba_28_ok(block, n_block)) { |
1143 | /* The request -may- be too large for LBA48. */ | 1263 | /* use LBA28 */ |
1144 | if ((block >> 48) || (n_block > 65536)) | 1264 | tf->device |= (block >> 24) & 0xf; |
1265 | } else if (lba_48_ok(block, n_block)) { | ||
1266 | if (!(dev->flags & ATA_DFLAG_LBA48)) | ||
1145 | goto out_of_range; | 1267 | goto out_of_range; |
1146 | 1268 | ||
1147 | /* use LBA48 */ | 1269 | /* use LBA48 */ |
@@ -1152,15 +1274,9 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1152 | tf->hob_lbah = (block >> 40) & 0xff; | 1274 | tf->hob_lbah = (block >> 40) & 0xff; |
1153 | tf->hob_lbam = (block >> 32) & 0xff; | 1275 | tf->hob_lbam = (block >> 32) & 0xff; |
1154 | tf->hob_lbal = (block >> 24) & 0xff; | 1276 | tf->hob_lbal = (block >> 24) & 0xff; |
1155 | } else { | 1277 | } else |
1156 | /* use LBA28 */ | 1278 | /* request too large even for LBA48 */ |
1157 | 1279 | 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 | 1280 | ||
1165 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) | 1281 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) |
1166 | goto invalid_fld; | 1282 | goto invalid_fld; |
@@ -1178,7 +1294,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1178 | u32 sect, head, cyl, track; | 1294 | u32 sect, head, cyl, track; |
1179 | 1295 | ||
1180 | /* The request -may- be too large for CHS addressing. */ | 1296 | /* The request -may- be too large for CHS addressing. */ |
1181 | if ((block >> 28) || (n_block > 256)) | 1297 | if (!lba_28_ok(block, n_block)) |
1182 | goto out_of_range; | 1298 | goto out_of_range; |
1183 | 1299 | ||
1184 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) | 1300 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) |
@@ -1225,7 +1341,7 @@ nothing_to_do: | |||
1225 | return 1; | 1341 | return 1; |
1226 | } | 1342 | } |
1227 | 1343 | ||
1228 | static int ata_scsi_qc_complete(struct ata_queued_cmd *qc) | 1344 | static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) |
1229 | { | 1345 | { |
1230 | struct scsi_cmnd *cmd = qc->scsicmd; | 1346 | struct scsi_cmnd *cmd = qc->scsicmd; |
1231 | u8 *cdb = cmd->cmnd; | 1347 | u8 *cdb = cmd->cmnd; |
@@ -1262,7 +1378,7 @@ static int ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
1262 | 1378 | ||
1263 | qc->scsidone(cmd); | 1379 | qc->scsidone(cmd); |
1264 | 1380 | ||
1265 | return 0; | 1381 | ata_qc_free(qc); |
1266 | } | 1382 | } |
1267 | 1383 | ||
1268 | /** | 1384 | /** |
@@ -1328,8 +1444,9 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
1328 | goto early_finish; | 1444 | goto early_finish; |
1329 | 1445 | ||
1330 | /* select device, send command to hardware */ | 1446 | /* select device, send command to hardware */ |
1331 | if (ata_qc_issue(qc)) | 1447 | qc->err_mask = ata_qc_issue(qc); |
1332 | goto err_did; | 1448 | if (qc->err_mask) |
1449 | ata_qc_complete(qc); | ||
1333 | 1450 | ||
1334 | VPRINTK("EXIT\n"); | 1451 | VPRINTK("EXIT\n"); |
1335 | return; | 1452 | return; |
@@ -1445,7 +1562,7 @@ void ata_scsi_rbuf_fill(struct ata_scsi_args *args, | |||
1445 | * @buflen: Response buffer length. | 1562 | * @buflen: Response buffer length. |
1446 | * | 1563 | * |
1447 | * Returns standard device identification data associated | 1564 | * Returns standard device identification data associated |
1448 | * with non-EVPD INQUIRY command output. | 1565 | * with non-VPD INQUIRY command output. |
1449 | * | 1566 | * |
1450 | * LOCKING: | 1567 | * LOCKING: |
1451 | * spin_lock_irqsave(host_set lock) | 1568 | * spin_lock_irqsave(host_set lock) |
@@ -1472,8 +1589,8 @@ unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, | |||
1472 | 1589 | ||
1473 | if (buflen > 35) { | 1590 | if (buflen > 35) { |
1474 | memcpy(&rbuf[8], "ATA ", 8); | 1591 | memcpy(&rbuf[8], "ATA ", 8); |
1475 | ata_dev_id_string(args->id, &rbuf[16], ATA_ID_PROD_OFS, 16); | 1592 | ata_id_string(args->id, &rbuf[16], ATA_ID_PROD_OFS, 16); |
1476 | ata_dev_id_string(args->id, &rbuf[32], ATA_ID_FW_REV_OFS, 4); | 1593 | ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV_OFS, 4); |
1477 | if (rbuf[32] == 0 || rbuf[32] == ' ') | 1594 | if (rbuf[32] == 0 || rbuf[32] == ' ') |
1478 | memcpy(&rbuf[32], "n/a ", 4); | 1595 | memcpy(&rbuf[32], "n/a ", 4); |
1479 | } | 1596 | } |
@@ -1496,12 +1613,12 @@ unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, | |||
1496 | } | 1613 | } |
1497 | 1614 | ||
1498 | /** | 1615 | /** |
1499 | * ata_scsiop_inq_00 - Simulate INQUIRY EVPD page 0, list of pages | 1616 | * ata_scsiop_inq_00 - Simulate INQUIRY VPD page 0, list of pages |
1500 | * @args: device IDENTIFY data / SCSI command of interest. | 1617 | * @args: device IDENTIFY data / SCSI command of interest. |
1501 | * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. | 1618 | * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. |
1502 | * @buflen: Response buffer length. | 1619 | * @buflen: Response buffer length. |
1503 | * | 1620 | * |
1504 | * Returns list of inquiry EVPD pages available. | 1621 | * Returns list of inquiry VPD pages available. |
1505 | * | 1622 | * |
1506 | * LOCKING: | 1623 | * LOCKING: |
1507 | * spin_lock_irqsave(host_set lock) | 1624 | * spin_lock_irqsave(host_set lock) |
@@ -1515,7 +1632,7 @@ unsigned int ata_scsiop_inq_00(struct ata_scsi_args *args, u8 *rbuf, | |||
1515 | 0x80, /* page 0x80, unit serial no page */ | 1632 | 0x80, /* page 0x80, unit serial no page */ |
1516 | 0x83 /* page 0x83, device ident page */ | 1633 | 0x83 /* page 0x83, device ident page */ |
1517 | }; | 1634 | }; |
1518 | rbuf[3] = sizeof(pages); /* number of supported EVPD pages */ | 1635 | rbuf[3] = sizeof(pages); /* number of supported VPD pages */ |
1519 | 1636 | ||
1520 | if (buflen > 6) | 1637 | if (buflen > 6) |
1521 | memcpy(rbuf + 4, pages, sizeof(pages)); | 1638 | memcpy(rbuf + 4, pages, sizeof(pages)); |
@@ -1524,7 +1641,7 @@ unsigned int ata_scsiop_inq_00(struct ata_scsi_args *args, u8 *rbuf, | |||
1524 | } | 1641 | } |
1525 | 1642 | ||
1526 | /** | 1643 | /** |
1527 | * ata_scsiop_inq_80 - Simulate INQUIRY EVPD page 80, device serial number | 1644 | * ata_scsiop_inq_80 - Simulate INQUIRY VPD page 80, device serial number |
1528 | * @args: device IDENTIFY data / SCSI command of interest. | 1645 | * @args: device IDENTIFY data / SCSI command of interest. |
1529 | * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. | 1646 | * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. |
1530 | * @buflen: Response buffer length. | 1647 | * @buflen: Response buffer length. |
@@ -1547,22 +1664,22 @@ unsigned int ata_scsiop_inq_80(struct ata_scsi_args *args, u8 *rbuf, | |||
1547 | memcpy(rbuf, hdr, sizeof(hdr)); | 1664 | memcpy(rbuf, hdr, sizeof(hdr)); |
1548 | 1665 | ||
1549 | if (buflen > (ATA_SERNO_LEN + 4 - 1)) | 1666 | if (buflen > (ATA_SERNO_LEN + 4 - 1)) |
1550 | ata_dev_id_string(args->id, (unsigned char *) &rbuf[4], | 1667 | ata_id_string(args->id, (unsigned char *) &rbuf[4], |
1551 | ATA_ID_SERNO_OFS, ATA_SERNO_LEN); | 1668 | ATA_ID_SERNO_OFS, ATA_SERNO_LEN); |
1552 | 1669 | ||
1553 | return 0; | 1670 | return 0; |
1554 | } | 1671 | } |
1555 | 1672 | ||
1556 | static const char * const inq_83_str = "Linux ATA-SCSI simulator"; | ||
1557 | |||
1558 | /** | 1673 | /** |
1559 | * ata_scsiop_inq_83 - Simulate INQUIRY EVPD page 83, device identity | 1674 | * ata_scsiop_inq_83 - Simulate INQUIRY VPD page 83, device identity |
1560 | * @args: device IDENTIFY data / SCSI command of interest. | 1675 | * @args: device IDENTIFY data / SCSI command of interest. |
1561 | * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. | 1676 | * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. |
1562 | * @buflen: Response buffer length. | 1677 | * @buflen: Response buffer length. |
1563 | * | 1678 | * |
1564 | * Returns device identification. Currently hardcoded to | 1679 | * Yields two logical unit device identification designators: |
1565 | * return "Linux ATA-SCSI simulator". | 1680 | * - vendor specific ASCII containing the ATA serial number |
1681 | * - SAT defined "t10 vendor id based" containing ASCII vendor | ||
1682 | * name ("ATA "), model and serial numbers. | ||
1566 | * | 1683 | * |
1567 | * LOCKING: | 1684 | * LOCKING: |
1568 | * spin_lock_irqsave(host_set lock) | 1685 | * spin_lock_irqsave(host_set lock) |
@@ -1571,16 +1688,39 @@ static const char * const inq_83_str = "Linux ATA-SCSI simulator"; | |||
1571 | unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf, | 1688 | unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf, |
1572 | unsigned int buflen) | 1689 | unsigned int buflen) |
1573 | { | 1690 | { |
1574 | rbuf[1] = 0x83; /* this page code */ | 1691 | int num; |
1575 | rbuf[3] = 4 + strlen(inq_83_str); /* page len */ | 1692 | const int sat_model_serial_desc_len = 68; |
1693 | const int ata_model_byte_len = 40; | ||
1576 | 1694 | ||
1577 | /* our one and only identification descriptor (vendor-specific) */ | 1695 | rbuf[1] = 0x83; /* this page code */ |
1578 | if (buflen > (strlen(inq_83_str) + 4 + 4 - 1)) { | 1696 | num = 4; |
1579 | rbuf[4 + 0] = 2; /* code set: ASCII */ | 1697 | |
1580 | rbuf[4 + 3] = strlen(inq_83_str); | 1698 | if (buflen > (ATA_SERNO_LEN + num + 3)) { |
1581 | memcpy(rbuf + 4 + 4, inq_83_str, strlen(inq_83_str)); | 1699 | /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */ |
1700 | rbuf[num + 0] = 2; | ||
1701 | rbuf[num + 3] = ATA_SERNO_LEN; | ||
1702 | num += 4; | ||
1703 | ata_id_string(args->id, (unsigned char *) rbuf + num, | ||
1704 | ATA_ID_SERNO_OFS, ATA_SERNO_LEN); | ||
1705 | num += ATA_SERNO_LEN; | ||
1582 | } | 1706 | } |
1583 | 1707 | if (buflen > (sat_model_serial_desc_len + num + 3)) { | |
1708 | /* SAT defined lu model and serial numbers descriptor */ | ||
1709 | /* piv=0, assoc=lu, code_set=ACSII, designator=t10 vendor id */ | ||
1710 | rbuf[num + 0] = 2; | ||
1711 | rbuf[num + 1] = 1; | ||
1712 | rbuf[num + 3] = sat_model_serial_desc_len; | ||
1713 | num += 4; | ||
1714 | memcpy(rbuf + num, "ATA ", 8); | ||
1715 | num += 8; | ||
1716 | ata_id_string(args->id, (unsigned char *) rbuf + num, | ||
1717 | ATA_ID_PROD_OFS, ata_model_byte_len); | ||
1718 | num += ata_model_byte_len; | ||
1719 | ata_id_string(args->id, (unsigned char *) rbuf + num, | ||
1720 | ATA_ID_SERNO_OFS, ATA_SERNO_LEN); | ||
1721 | num += ATA_SERNO_LEN; | ||
1722 | } | ||
1723 | rbuf[3] = num - 4; /* page len (assume less than 256 bytes) */ | ||
1584 | return 0; | 1724 | return 0; |
1585 | } | 1725 | } |
1586 | 1726 | ||
@@ -1713,15 +1853,12 @@ static int ata_dev_supports_fua(u16 *id) | |||
1713 | if (!ata_id_has_fua(id)) | 1853 | if (!ata_id_has_fua(id)) |
1714 | return 0; | 1854 | return 0; |
1715 | 1855 | ||
1716 | model[40] = '\0'; | 1856 | ata_id_c_string(id, model, ATA_ID_PROD_OFS, sizeof(model)); |
1717 | fw[8] = '\0'; | 1857 | ata_id_c_string(id, fw, ATA_ID_FW_REV_OFS, sizeof(fw)); |
1718 | |||
1719 | ata_dev_id_string(id, model, ATA_ID_PROD_OFS, sizeof(model) - 1); | ||
1720 | ata_dev_id_string(id, fw, ATA_ID_FW_REV_OFS, sizeof(fw) - 1); | ||
1721 | 1858 | ||
1722 | if (strncmp(model, "Maxtor", 6)) | 1859 | if (strcmp(model, "Maxtor")) |
1723 | return 1; | 1860 | return 1; |
1724 | if (strncmp(fw, "BANC1G10", 8)) | 1861 | if (strcmp(fw, "BANC1G10")) |
1725 | return 1; | 1862 | return 1; |
1726 | 1863 | ||
1727 | return 0; /* blacklisted */ | 1864 | return 0; /* blacklisted */ |
@@ -2015,7 +2152,7 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8 | |||
2015 | done(cmd); | 2152 | done(cmd); |
2016 | } | 2153 | } |
2017 | 2154 | ||
2018 | static int atapi_sense_complete(struct ata_queued_cmd *qc) | 2155 | static void atapi_sense_complete(struct ata_queued_cmd *qc) |
2019 | { | 2156 | { |
2020 | if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) | 2157 | if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) |
2021 | /* FIXME: not quite right; we don't want the | 2158 | /* FIXME: not quite right; we don't want the |
@@ -2026,7 +2163,7 @@ static int atapi_sense_complete(struct ata_queued_cmd *qc) | |||
2026 | ata_gen_ata_desc_sense(qc); | 2163 | ata_gen_ata_desc_sense(qc); |
2027 | 2164 | ||
2028 | qc->scsidone(qc->scsicmd); | 2165 | qc->scsidone(qc->scsicmd); |
2029 | return 0; | 2166 | ata_qc_free(qc); |
2030 | } | 2167 | } |
2031 | 2168 | ||
2032 | /* is it pointless to prefer PIO for "safety reasons"? */ | 2169 | /* is it pointless to prefer PIO for "safety reasons"? */ |
@@ -2056,7 +2193,7 @@ static void atapi_request_sense(struct ata_queued_cmd *qc) | |||
2056 | ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); | 2193 | ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); |
2057 | qc->dma_dir = DMA_FROM_DEVICE; | 2194 | qc->dma_dir = DMA_FROM_DEVICE; |
2058 | 2195 | ||
2059 | memset(&qc->cdb, 0, ap->cdb_len); | 2196 | memset(&qc->cdb, 0, qc->dev->cdb_len); |
2060 | qc->cdb[0] = REQUEST_SENSE; | 2197 | qc->cdb[0] = REQUEST_SENSE; |
2061 | qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; | 2198 | qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; |
2062 | 2199 | ||
@@ -2075,15 +2212,14 @@ static void atapi_request_sense(struct ata_queued_cmd *qc) | |||
2075 | 2212 | ||
2076 | qc->complete_fn = atapi_sense_complete; | 2213 | qc->complete_fn = atapi_sense_complete; |
2077 | 2214 | ||
2078 | if (ata_qc_issue(qc)) { | 2215 | qc->err_mask = ata_qc_issue(qc); |
2079 | qc->err_mask |= AC_ERR_OTHER; | 2216 | if (qc->err_mask) |
2080 | ata_qc_complete(qc); | 2217 | ata_qc_complete(qc); |
2081 | } | ||
2082 | 2218 | ||
2083 | DPRINTK("EXIT\n"); | 2219 | DPRINTK("EXIT\n"); |
2084 | } | 2220 | } |
2085 | 2221 | ||
2086 | static int atapi_qc_complete(struct ata_queued_cmd *qc) | 2222 | static void atapi_qc_complete(struct ata_queued_cmd *qc) |
2087 | { | 2223 | { |
2088 | struct scsi_cmnd *cmd = qc->scsicmd; | 2224 | struct scsi_cmnd *cmd = qc->scsicmd; |
2089 | unsigned int err_mask = qc->err_mask; | 2225 | unsigned int err_mask = qc->err_mask; |
@@ -2093,7 +2229,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2093 | if (unlikely(err_mask & AC_ERR_DEV)) { | 2229 | if (unlikely(err_mask & AC_ERR_DEV)) { |
2094 | cmd->result = SAM_STAT_CHECK_CONDITION; | 2230 | cmd->result = SAM_STAT_CHECK_CONDITION; |
2095 | atapi_request_sense(qc); | 2231 | atapi_request_sense(qc); |
2096 | return 1; | 2232 | return; |
2097 | } | 2233 | } |
2098 | 2234 | ||
2099 | else if (unlikely(err_mask)) | 2235 | else if (unlikely(err_mask)) |
@@ -2133,7 +2269,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2133 | } | 2269 | } |
2134 | 2270 | ||
2135 | qc->scsidone(cmd); | 2271 | qc->scsidone(cmd); |
2136 | return 0; | 2272 | ata_qc_free(qc); |
2137 | } | 2273 | } |
2138 | /** | 2274 | /** |
2139 | * atapi_xlat - Initialize PACKET taskfile | 2275 | * atapi_xlat - Initialize PACKET taskfile |
@@ -2159,7 +2295,7 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd) | |||
2159 | if (ata_check_atapi_dma(qc)) | 2295 | if (ata_check_atapi_dma(qc)) |
2160 | using_pio = 1; | 2296 | using_pio = 1; |
2161 | 2297 | ||
2162 | memcpy(&qc->cdb, scsicmd, qc->ap->cdb_len); | 2298 | memcpy(&qc->cdb, scsicmd, dev->cdb_len); |
2163 | 2299 | ||
2164 | qc->complete_fn = atapi_qc_complete; | 2300 | qc->complete_fn = atapi_qc_complete; |
2165 | 2301 | ||
@@ -2263,9 +2399,6 @@ ata_scsi_map_proto(u8 byte1) | |||
2263 | 2399 | ||
2264 | case 4: /* PIO Data-in */ | 2400 | case 4: /* PIO Data-in */ |
2265 | case 5: /* PIO Data-out */ | 2401 | case 5: /* PIO Data-out */ |
2266 | if (byte1 & 0xe0) { | ||
2267 | return ATA_PROT_PIO_MULT; | ||
2268 | } | ||
2269 | return ATA_PROT_PIO; | 2402 | return ATA_PROT_PIO; |
2270 | 2403 | ||
2271 | case 10: /* Device Reset */ | 2404 | case 10: /* Device Reset */ |
@@ -2304,6 +2437,10 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd) | |||
2304 | if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN) | 2437 | if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN) |
2305 | goto invalid_fld; | 2438 | goto invalid_fld; |
2306 | 2439 | ||
2440 | if (scsicmd[1] & 0xe0) | ||
2441 | /* PIO multi not supported yet */ | ||
2442 | goto invalid_fld; | ||
2443 | |||
2307 | /* | 2444 | /* |
2308 | * 12 and 16 byte CDBs use different offsets to | 2445 | * 12 and 16 byte CDBs use different offsets to |
2309 | * provide the various register values. | 2446 | * provide the various register values. |
@@ -2519,7 +2656,8 @@ out_unlock: | |||
2519 | 2656 | ||
2520 | /** | 2657 | /** |
2521 | * ata_scsi_simulate - simulate SCSI command on ATA device | 2658 | * ata_scsi_simulate - simulate SCSI command on ATA device |
2522 | * @id: current IDENTIFY data for target device. | 2659 | * @ap: port the device is connected to |
2660 | * @dev: the target device | ||
2523 | * @cmd: SCSI command being sent to device. | 2661 | * @cmd: SCSI command being sent to device. |
2524 | * @done: SCSI command completion function. | 2662 | * @done: SCSI command completion function. |
2525 | * | 2663 | * |