diff options
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r-- | drivers/scsi/libata-core.c | 874 |
1 files changed, 574 insertions, 300 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index e5b01997117a..f53d7b8ac33f 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include <linux/completion.h> | 48 | #include <linux/completion.h> |
49 | #include <linux/suspend.h> | 49 | #include <linux/suspend.h> |
50 | #include <linux/workqueue.h> | 50 | #include <linux/workqueue.h> |
51 | #include <linux/jiffies.h> | ||
51 | #include <scsi/scsi.h> | 52 | #include <scsi/scsi.h> |
52 | #include "scsi.h" | 53 | #include "scsi.h" |
53 | #include "scsi_priv.h" | 54 | #include "scsi_priv.h" |
@@ -62,14 +63,15 @@ | |||
62 | static unsigned int ata_busy_sleep (struct ata_port *ap, | 63 | static unsigned int ata_busy_sleep (struct ata_port *ap, |
63 | unsigned long tmout_pat, | 64 | unsigned long tmout_pat, |
64 | unsigned long tmout); | 65 | unsigned long tmout); |
66 | static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev); | ||
67 | static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev); | ||
65 | static void ata_set_mode(struct ata_port *ap); | 68 | static void ata_set_mode(struct ata_port *ap); |
66 | static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev); | 69 | static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev); |
67 | static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift); | 70 | static unsigned int ata_get_mode_mask(const struct ata_port *ap, int shift); |
68 | static int fgb(u32 bitmap); | 71 | static int fgb(u32 bitmap); |
69 | static int ata_choose_xfer_mode(struct ata_port *ap, | 72 | static int ata_choose_xfer_mode(const struct ata_port *ap, |
70 | u8 *xfer_mode_out, | 73 | u8 *xfer_mode_out, |
71 | unsigned int *xfer_shift_out); | 74 | unsigned int *xfer_shift_out); |
72 | static int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat); | ||
73 | static void __ata_qc_complete(struct ata_queued_cmd *qc); | 75 | static void __ata_qc_complete(struct ata_queued_cmd *qc); |
74 | 76 | ||
75 | static unsigned int ata_unique_id = 1; | 77 | static unsigned int ata_unique_id = 1; |
@@ -85,7 +87,7 @@ MODULE_LICENSE("GPL"); | |||
85 | MODULE_VERSION(DRV_VERSION); | 87 | MODULE_VERSION(DRV_VERSION); |
86 | 88 | ||
87 | /** | 89 | /** |
88 | * ata_tf_load - send taskfile registers to host controller | 90 | * ata_tf_load_pio - send taskfile registers to host controller |
89 | * @ap: Port to which output is sent | 91 | * @ap: Port to which output is sent |
90 | * @tf: ATA taskfile register set | 92 | * @tf: ATA taskfile register set |
91 | * | 93 | * |
@@ -95,7 +97,7 @@ MODULE_VERSION(DRV_VERSION); | |||
95 | * Inherited from caller. | 97 | * Inherited from caller. |
96 | */ | 98 | */ |
97 | 99 | ||
98 | static void ata_tf_load_pio(struct ata_port *ap, struct ata_taskfile *tf) | 100 | static void ata_tf_load_pio(struct ata_port *ap, const struct ata_taskfile *tf) |
99 | { | 101 | { |
100 | struct ata_ioports *ioaddr = &ap->ioaddr; | 102 | struct ata_ioports *ioaddr = &ap->ioaddr; |
101 | unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; | 103 | unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; |
@@ -153,7 +155,7 @@ static void ata_tf_load_pio(struct ata_port *ap, struct ata_taskfile *tf) | |||
153 | * Inherited from caller. | 155 | * Inherited from caller. |
154 | */ | 156 | */ |
155 | 157 | ||
156 | static void ata_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf) | 158 | static void ata_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf) |
157 | { | 159 | { |
158 | struct ata_ioports *ioaddr = &ap->ioaddr; | 160 | struct ata_ioports *ioaddr = &ap->ioaddr; |
159 | unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; | 161 | unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; |
@@ -222,7 +224,7 @@ static void ata_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf) | |||
222 | * LOCKING: | 224 | * LOCKING: |
223 | * Inherited from caller. | 225 | * Inherited from caller. |
224 | */ | 226 | */ |
225 | void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) | 227 | void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf) |
226 | { | 228 | { |
227 | if (ap->flags & ATA_FLAG_MMIO) | 229 | if (ap->flags & ATA_FLAG_MMIO) |
228 | ata_tf_load_mmio(ap, tf); | 230 | ata_tf_load_mmio(ap, tf); |
@@ -242,7 +244,7 @@ void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) | |||
242 | * spin_lock_irqsave(host_set lock) | 244 | * spin_lock_irqsave(host_set lock) |
243 | */ | 245 | */ |
244 | 246 | ||
245 | static void ata_exec_command_pio(struct ata_port *ap, struct ata_taskfile *tf) | 247 | static void ata_exec_command_pio(struct ata_port *ap, const struct ata_taskfile *tf) |
246 | { | 248 | { |
247 | DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command); | 249 | DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command); |
248 | 250 | ||
@@ -263,7 +265,7 @@ static void ata_exec_command_pio(struct ata_port *ap, struct ata_taskfile *tf) | |||
263 | * spin_lock_irqsave(host_set lock) | 265 | * spin_lock_irqsave(host_set lock) |
264 | */ | 266 | */ |
265 | 267 | ||
266 | static void ata_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf) | 268 | static void ata_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf) |
267 | { | 269 | { |
268 | DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command); | 270 | DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command); |
269 | 271 | ||
@@ -283,7 +285,7 @@ static void ata_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf) | |||
283 | * LOCKING: | 285 | * LOCKING: |
284 | * spin_lock_irqsave(host_set lock) | 286 | * spin_lock_irqsave(host_set lock) |
285 | */ | 287 | */ |
286 | void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf) | 288 | void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf) |
287 | { | 289 | { |
288 | if (ap->flags & ATA_FLAG_MMIO) | 290 | if (ap->flags & ATA_FLAG_MMIO) |
289 | ata_exec_command_mmio(ap, tf); | 291 | ata_exec_command_mmio(ap, tf); |
@@ -303,7 +305,7 @@ void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf) | |||
303 | * Obtains host_set lock. | 305 | * Obtains host_set lock. |
304 | */ | 306 | */ |
305 | 307 | ||
306 | static inline void ata_exec(struct ata_port *ap, struct ata_taskfile *tf) | 308 | static inline void ata_exec(struct ata_port *ap, const struct ata_taskfile *tf) |
307 | { | 309 | { |
308 | unsigned long flags; | 310 | unsigned long flags; |
309 | 311 | ||
@@ -326,7 +328,7 @@ static inline void ata_exec(struct ata_port *ap, struct ata_taskfile *tf) | |||
326 | * Obtains host_set lock. | 328 | * Obtains host_set lock. |
327 | */ | 329 | */ |
328 | 330 | ||
329 | static void ata_tf_to_host(struct ata_port *ap, struct ata_taskfile *tf) | 331 | static void ata_tf_to_host(struct ata_port *ap, const struct ata_taskfile *tf) |
330 | { | 332 | { |
331 | ap->ops->tf_load(ap, tf); | 333 | ap->ops->tf_load(ap, tf); |
332 | 334 | ||
@@ -346,7 +348,7 @@ static void ata_tf_to_host(struct ata_port *ap, struct ata_taskfile *tf) | |||
346 | * spin_lock_irqsave(host_set lock) | 348 | * spin_lock_irqsave(host_set lock) |
347 | */ | 349 | */ |
348 | 350 | ||
349 | void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf) | 351 | void ata_tf_to_host_nolock(struct ata_port *ap, const struct ata_taskfile *tf) |
350 | { | 352 | { |
351 | ap->ops->tf_load(ap, tf); | 353 | ap->ops->tf_load(ap, tf); |
352 | ap->ops->exec_command(ap, tf); | 354 | ap->ops->exec_command(ap, tf); |
@@ -556,7 +558,7 @@ u8 ata_chk_err(struct ata_port *ap) | |||
556 | * Inherited from caller. | 558 | * Inherited from caller. |
557 | */ | 559 | */ |
558 | 560 | ||
559 | void ata_tf_to_fis(struct ata_taskfile *tf, u8 *fis, u8 pmp) | 561 | void ata_tf_to_fis(const struct ata_taskfile *tf, u8 *fis, u8 pmp) |
560 | { | 562 | { |
561 | fis[0] = 0x27; /* Register - Host to Device FIS */ | 563 | fis[0] = 0x27; /* Register - Host to Device FIS */ |
562 | fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number, | 564 | fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number, |
@@ -597,7 +599,7 @@ void ata_tf_to_fis(struct ata_taskfile *tf, u8 *fis, u8 pmp) | |||
597 | * Inherited from caller. | 599 | * Inherited from caller. |
598 | */ | 600 | */ |
599 | 601 | ||
600 | void ata_tf_from_fis(u8 *fis, struct ata_taskfile *tf) | 602 | void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf) |
601 | { | 603 | { |
602 | tf->command = fis[2]; /* status */ | 604 | tf->command = fis[2]; /* status */ |
603 | tf->feature = fis[3]; /* error */ | 605 | tf->feature = fis[3]; /* error */ |
@@ -615,79 +617,53 @@ void ata_tf_from_fis(u8 *fis, struct ata_taskfile *tf) | |||
615 | tf->hob_nsect = fis[13]; | 617 | tf->hob_nsect = fis[13]; |
616 | } | 618 | } |
617 | 619 | ||
618 | /** | 620 | static const u8 ata_rw_cmds[] = { |
619 | * ata_prot_to_cmd - determine which read/write opcodes to use | 621 | /* pio multi */ |
620 | * @protocol: ATA_PROT_xxx taskfile protocol | 622 | ATA_CMD_READ_MULTI, |
621 | * @lba48: true is lba48 is present | 623 | ATA_CMD_WRITE_MULTI, |
622 | * | 624 | ATA_CMD_READ_MULTI_EXT, |
623 | * Given necessary input, determine which read/write commands | 625 | ATA_CMD_WRITE_MULTI_EXT, |
624 | * to use to transfer data. | 626 | /* pio */ |
625 | * | 627 | ATA_CMD_PIO_READ, |
626 | * LOCKING: | 628 | ATA_CMD_PIO_WRITE, |
627 | * None. | 629 | ATA_CMD_PIO_READ_EXT, |
628 | */ | 630 | ATA_CMD_PIO_WRITE_EXT, |
629 | static int ata_prot_to_cmd(int protocol, int lba48) | 631 | /* dma */ |
630 | { | 632 | ATA_CMD_READ, |
631 | int rcmd = 0, wcmd = 0; | 633 | ATA_CMD_WRITE, |
632 | 634 | ATA_CMD_READ_EXT, | |
633 | switch (protocol) { | 635 | ATA_CMD_WRITE_EXT |
634 | case ATA_PROT_PIO: | 636 | }; |
635 | if (lba48) { | ||
636 | rcmd = ATA_CMD_PIO_READ_EXT; | ||
637 | wcmd = ATA_CMD_PIO_WRITE_EXT; | ||
638 | } else { | ||
639 | rcmd = ATA_CMD_PIO_READ; | ||
640 | wcmd = ATA_CMD_PIO_WRITE; | ||
641 | } | ||
642 | break; | ||
643 | |||
644 | case ATA_PROT_DMA: | ||
645 | if (lba48) { | ||
646 | rcmd = ATA_CMD_READ_EXT; | ||
647 | wcmd = ATA_CMD_WRITE_EXT; | ||
648 | } else { | ||
649 | rcmd = ATA_CMD_READ; | ||
650 | wcmd = ATA_CMD_WRITE; | ||
651 | } | ||
652 | break; | ||
653 | |||
654 | default: | ||
655 | return -1; | ||
656 | } | ||
657 | |||
658 | return rcmd | (wcmd << 8); | ||
659 | } | ||
660 | 637 | ||
661 | /** | 638 | /** |
662 | * ata_dev_set_protocol - set taskfile protocol and r/w commands | 639 | * ata_rwcmd_protocol - set taskfile r/w commands and protocol |
663 | * @dev: device to examine and configure | 640 | * @qc: command to examine and configure |
664 | * | 641 | * |
665 | * Examine the device configuration, after we have | 642 | * Examine the device configuration and tf->flags to calculate |
666 | * read the identify-device page and configured the | 643 | * the proper read/write commands and protocol to use. |
667 | * data transfer mode. Set internal state related to | ||
668 | * the ATA taskfile protocol (pio, pio mult, dma, etc.) | ||
669 | * and calculate the proper read/write commands to use. | ||
670 | * | 644 | * |
671 | * LOCKING: | 645 | * LOCKING: |
672 | * caller. | 646 | * caller. |
673 | */ | 647 | */ |
674 | static void ata_dev_set_protocol(struct ata_device *dev) | 648 | void ata_rwcmd_protocol(struct ata_queued_cmd *qc) |
675 | { | 649 | { |
676 | int pio = (dev->flags & ATA_DFLAG_PIO); | 650 | struct ata_taskfile *tf = &qc->tf; |
677 | int lba48 = (dev->flags & ATA_DFLAG_LBA48); | 651 | struct ata_device *dev = qc->dev; |
678 | int proto, cmd; | ||
679 | 652 | ||
680 | if (pio) | 653 | int index, lba48, write; |
681 | proto = dev->xfer_protocol = ATA_PROT_PIO; | 654 | |
682 | else | 655 | lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; |
683 | proto = dev->xfer_protocol = ATA_PROT_DMA; | 656 | write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; |
684 | 657 | ||
685 | cmd = ata_prot_to_cmd(proto, lba48); | 658 | if (dev->flags & ATA_DFLAG_PIO) { |
686 | if (cmd < 0) | 659 | tf->protocol = ATA_PROT_PIO; |
687 | BUG(); | 660 | index = dev->multi_count ? 0 : 4; |
661 | } else { | ||
662 | tf->protocol = ATA_PROT_DMA; | ||
663 | index = 8; | ||
664 | } | ||
688 | 665 | ||
689 | dev->read_cmd = cmd & 0xff; | 666 | tf->command = ata_rw_cmds[index + lba48 + write]; |
690 | dev->write_cmd = (cmd >> 8) & 0xff; | ||
691 | } | 667 | } |
692 | 668 | ||
693 | static const char * xfer_mode_str[] = { | 669 | static const char * xfer_mode_str[] = { |
@@ -869,7 +845,7 @@ static unsigned int ata_devchk(struct ata_port *ap, | |||
869 | * the event of failure. | 845 | * the event of failure. |
870 | */ | 846 | */ |
871 | 847 | ||
872 | unsigned int ata_dev_classify(struct ata_taskfile *tf) | 848 | unsigned int ata_dev_classify(const struct ata_taskfile *tf) |
873 | { | 849 | { |
874 | /* Apple's open source Darwin code hints that some devices only | 850 | /* Apple's open source Darwin code hints that some devices only |
875 | * put a proper signature into the LBA mid/high registers, | 851 | * put a proper signature into the LBA mid/high registers, |
@@ -961,7 +937,7 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device) | |||
961 | * caller. | 937 | * caller. |
962 | */ | 938 | */ |
963 | 939 | ||
964 | void ata_dev_id_string(u16 *id, unsigned char *s, | 940 | void ata_dev_id_string(const u16 *id, unsigned char *s, |
965 | unsigned int ofs, unsigned int len) | 941 | unsigned int ofs, unsigned int len) |
966 | { | 942 | { |
967 | unsigned int c; | 943 | unsigned int c; |
@@ -1078,7 +1054,7 @@ void ata_dev_select(struct ata_port *ap, unsigned int device, | |||
1078 | * caller. | 1054 | * caller. |
1079 | */ | 1055 | */ |
1080 | 1056 | ||
1081 | static inline void ata_dump_id(struct ata_device *dev) | 1057 | static inline void ata_dump_id(const struct ata_device *dev) |
1082 | { | 1058 | { |
1083 | DPRINTK("49==0x%04x " | 1059 | DPRINTK("49==0x%04x " |
1084 | "53==0x%04x " | 1060 | "53==0x%04x " |
@@ -1106,6 +1082,31 @@ static inline void ata_dump_id(struct ata_device *dev) | |||
1106 | dev->id[93]); | 1082 | dev->id[93]); |
1107 | } | 1083 | } |
1108 | 1084 | ||
1085 | /* | ||
1086 | * Compute the PIO modes available for this device. This is not as | ||
1087 | * trivial as it seems if we must consider early devices correctly. | ||
1088 | * | ||
1089 | * FIXME: pre IDE drive timing (do we care ?). | ||
1090 | */ | ||
1091 | |||
1092 | static unsigned int ata_pio_modes(const struct ata_device *adev) | ||
1093 | { | ||
1094 | u16 modes; | ||
1095 | |||
1096 | /* Usual case. Word 53 indicates word 88 is valid */ | ||
1097 | if (adev->id[ATA_ID_FIELD_VALID] & (1 << 2)) { | ||
1098 | modes = adev->id[ATA_ID_PIO_MODES] & 0x03; | ||
1099 | modes <<= 3; | ||
1100 | modes |= 0x7; | ||
1101 | return modes; | ||
1102 | } | ||
1103 | |||
1104 | /* If word 88 isn't valid then Word 51 holds the PIO timing number | ||
1105 | for the maximum. Turn it into a mask and return it */ | ||
1106 | modes = (2 << (adev->id[ATA_ID_OLD_PIO_MODES] & 0xFF)) - 1 ; | ||
1107 | return modes; | ||
1108 | } | ||
1109 | |||
1109 | /** | 1110 | /** |
1110 | * ata_dev_identify - obtain IDENTIFY x DEVICE page | 1111 | * ata_dev_identify - obtain IDENTIFY x DEVICE page |
1111 | * @ap: port on which device we wish to probe resides | 1112 | * @ap: port on which device we wish to probe resides |
@@ -1131,7 +1132,7 @@ static inline void ata_dump_id(struct ata_device *dev) | |||
1131 | static void ata_dev_identify(struct ata_port *ap, unsigned int device) | 1132 | static void ata_dev_identify(struct ata_port *ap, unsigned int device) |
1132 | { | 1133 | { |
1133 | struct ata_device *dev = &ap->device[device]; | 1134 | struct ata_device *dev = &ap->device[device]; |
1134 | unsigned int i; | 1135 | unsigned int major_version; |
1135 | u16 tmp; | 1136 | u16 tmp; |
1136 | unsigned long xfer_modes; | 1137 | unsigned long xfer_modes; |
1137 | u8 status; | 1138 | u8 status; |
@@ -1229,9 +1230,9 @@ retry: | |||
1229 | * common ATA, ATAPI feature tests | 1230 | * common ATA, ATAPI feature tests |
1230 | */ | 1231 | */ |
1231 | 1232 | ||
1232 | /* we require LBA and DMA support (bits 8 & 9 of word 49) */ | 1233 | /* we require DMA support (bits 8 of word 49) */ |
1233 | if (!ata_id_has_dma(dev->id) || !ata_id_has_lba(dev->id)) { | 1234 | if (!ata_id_has_dma(dev->id)) { |
1234 | printk(KERN_DEBUG "ata%u: no dma/lba\n", ap->id); | 1235 | printk(KERN_DEBUG "ata%u: no dma\n", ap->id); |
1235 | goto err_out_nosup; | 1236 | goto err_out_nosup; |
1236 | } | 1237 | } |
1237 | 1238 | ||
@@ -1239,10 +1240,8 @@ retry: | |||
1239 | xfer_modes = dev->id[ATA_ID_UDMA_MODES]; | 1240 | xfer_modes = dev->id[ATA_ID_UDMA_MODES]; |
1240 | if (!xfer_modes) | 1241 | if (!xfer_modes) |
1241 | xfer_modes = (dev->id[ATA_ID_MWDMA_MODES]) << ATA_SHIFT_MWDMA; | 1242 | xfer_modes = (dev->id[ATA_ID_MWDMA_MODES]) << ATA_SHIFT_MWDMA; |
1242 | if (!xfer_modes) { | 1243 | if (!xfer_modes) |
1243 | xfer_modes = (dev->id[ATA_ID_PIO_MODES]) << (ATA_SHIFT_PIO + 3); | 1244 | xfer_modes = ata_pio_modes(dev); |
1244 | xfer_modes |= (0x7 << ATA_SHIFT_PIO); | ||
1245 | } | ||
1246 | 1245 | ||
1247 | ata_dump_id(dev); | 1246 | ata_dump_id(dev); |
1248 | 1247 | ||
@@ -1251,32 +1250,75 @@ retry: | |||
1251 | if (!ata_id_is_ata(dev->id)) /* sanity check */ | 1250 | if (!ata_id_is_ata(dev->id)) /* sanity check */ |
1252 | goto err_out_nosup; | 1251 | goto err_out_nosup; |
1253 | 1252 | ||
1253 | /* get major version */ | ||
1254 | tmp = dev->id[ATA_ID_MAJOR_VER]; | 1254 | tmp = dev->id[ATA_ID_MAJOR_VER]; |
1255 | for (i = 14; i >= 1; i--) | 1255 | for (major_version = 14; major_version >= 1; major_version--) |
1256 | if (tmp & (1 << i)) | 1256 | if (tmp & (1 << major_version)) |
1257 | break; | 1257 | break; |
1258 | 1258 | ||
1259 | /* we require at least ATA-3 */ | 1259 | /* |
1260 | if (i < 3) { | 1260 | * The exact sequence expected by certain pre-ATA4 drives is: |
1261 | printk(KERN_DEBUG "ata%u: no ATA-3\n", ap->id); | 1261 | * SRST RESET |
1262 | goto err_out_nosup; | 1262 | * IDENTIFY |
1263 | * INITIALIZE DEVICE PARAMETERS | ||
1264 | * anything else.. | ||
1265 | * Some drives were very specific about that exact sequence. | ||
1266 | */ | ||
1267 | if (major_version < 4 || (!ata_id_has_lba(dev->id))) { | ||
1268 | ata_dev_init_params(ap, dev); | ||
1269 | |||
1270 | /* current CHS translation info (id[53-58]) might be | ||
1271 | * changed. reread the identify device info. | ||
1272 | */ | ||
1273 | ata_dev_reread_id(ap, dev); | ||
1263 | } | 1274 | } |
1264 | 1275 | ||
1265 | if (ata_id_has_lba48(dev->id)) { | 1276 | if (ata_id_has_lba(dev->id)) { |
1266 | dev->flags |= ATA_DFLAG_LBA48; | 1277 | dev->flags |= ATA_DFLAG_LBA; |
1267 | dev->n_sectors = ata_id_u64(dev->id, 100); | 1278 | |
1268 | } else { | 1279 | if (ata_id_has_lba48(dev->id)) { |
1269 | dev->n_sectors = ata_id_u32(dev->id, 60); | 1280 | dev->flags |= ATA_DFLAG_LBA48; |
1281 | dev->n_sectors = ata_id_u64(dev->id, 100); | ||
1282 | } else { | ||
1283 | dev->n_sectors = ata_id_u32(dev->id, 60); | ||
1284 | } | ||
1285 | |||
1286 | /* print device info to dmesg */ | ||
1287 | printk(KERN_INFO "ata%u: dev %u ATA-%d, max %s, %Lu sectors:%s\n", | ||
1288 | ap->id, device, | ||
1289 | major_version, | ||
1290 | ata_mode_string(xfer_modes), | ||
1291 | (unsigned long long)dev->n_sectors, | ||
1292 | dev->flags & ATA_DFLAG_LBA48 ? " LBA48" : " LBA"); | ||
1293 | } else { | ||
1294 | /* CHS */ | ||
1295 | |||
1296 | /* Default translation */ | ||
1297 | dev->cylinders = dev->id[1]; | ||
1298 | dev->heads = dev->id[3]; | ||
1299 | dev->sectors = dev->id[6]; | ||
1300 | dev->n_sectors = dev->cylinders * dev->heads * dev->sectors; | ||
1301 | |||
1302 | if (ata_id_current_chs_valid(dev->id)) { | ||
1303 | /* Current CHS translation is valid. */ | ||
1304 | dev->cylinders = dev->id[54]; | ||
1305 | dev->heads = dev->id[55]; | ||
1306 | dev->sectors = dev->id[56]; | ||
1307 | |||
1308 | dev->n_sectors = ata_id_u32(dev->id, 57); | ||
1309 | } | ||
1310 | |||
1311 | /* print device info to dmesg */ | ||
1312 | printk(KERN_INFO "ata%u: dev %u ATA-%d, max %s, %Lu sectors: CHS %d/%d/%d\n", | ||
1313 | ap->id, device, | ||
1314 | major_version, | ||
1315 | ata_mode_string(xfer_modes), | ||
1316 | (unsigned long long)dev->n_sectors, | ||
1317 | (int)dev->cylinders, (int)dev->heads, (int)dev->sectors); | ||
1318 | |||
1270 | } | 1319 | } |
1271 | 1320 | ||
1272 | ap->host->max_cmd_len = 16; | 1321 | ap->host->max_cmd_len = 16; |
1273 | |||
1274 | /* print device info to dmesg */ | ||
1275 | printk(KERN_INFO "ata%u: dev %u ATA, max %s, %Lu sectors:%s\n", | ||
1276 | ap->id, device, | ||
1277 | ata_mode_string(xfer_modes), | ||
1278 | (unsigned long long)dev->n_sectors, | ||
1279 | dev->flags & ATA_DFLAG_LBA48 ? " lba48" : ""); | ||
1280 | } | 1322 | } |
1281 | 1323 | ||
1282 | /* ATAPI-specific feature tests */ | 1324 | /* ATAPI-specific feature tests */ |
@@ -1310,7 +1352,7 @@ err_out: | |||
1310 | } | 1352 | } |
1311 | 1353 | ||
1312 | 1354 | ||
1313 | static inline u8 ata_dev_knobble(struct ata_port *ap) | 1355 | static inline u8 ata_dev_knobble(const struct ata_port *ap) |
1314 | { | 1356 | { |
1315 | return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(ap->device->id))); | 1357 | return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(ap->device->id))); |
1316 | } | 1358 | } |
@@ -1496,7 +1538,153 @@ void ata_port_disable(struct ata_port *ap) | |||
1496 | ap->flags |= ATA_FLAG_PORT_DISABLED; | 1538 | ap->flags |= ATA_FLAG_PORT_DISABLED; |
1497 | } | 1539 | } |
1498 | 1540 | ||
1499 | static struct { | 1541 | /* |
1542 | * This mode timing computation functionality is ported over from | ||
1543 | * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik | ||
1544 | */ | ||
1545 | /* | ||
1546 | * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). | ||
1547 | * These were taken from ATA/ATAPI-6 standard, rev 0a, except | ||
1548 | * for PIO 5, which is a nonstandard extension and UDMA6, which | ||
1549 | * is currently supported only by Maxtor drives. | ||
1550 | */ | ||
1551 | |||
1552 | static const struct ata_timing ata_timing[] = { | ||
1553 | |||
1554 | { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 }, | ||
1555 | { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 }, | ||
1556 | { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 30 }, | ||
1557 | { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 45 }, | ||
1558 | |||
1559 | { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 60 }, | ||
1560 | { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 }, | ||
1561 | { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, | ||
1562 | |||
1563 | /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */ | ||
1564 | |||
1565 | { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, | ||
1566 | { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, | ||
1567 | { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, | ||
1568 | |||
1569 | { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, | ||
1570 | { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, | ||
1571 | { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, | ||
1572 | |||
1573 | /* { XFER_PIO_5, 20, 50, 30, 100, 50, 30, 100, 0 }, */ | ||
1574 | { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 }, | ||
1575 | { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 }, | ||
1576 | |||
1577 | { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 240, 0 }, | ||
1578 | { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 383, 0 }, | ||
1579 | { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0 }, | ||
1580 | |||
1581 | /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */ | ||
1582 | |||
1583 | { 0xFF } | ||
1584 | }; | ||
1585 | |||
1586 | #define ENOUGH(v,unit) (((v)-1)/(unit)+1) | ||
1587 | #define EZ(v,unit) ((v)?ENOUGH(v,unit):0) | ||
1588 | |||
1589 | static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q, int T, int UT) | ||
1590 | { | ||
1591 | q->setup = EZ(t->setup * 1000, T); | ||
1592 | q->act8b = EZ(t->act8b * 1000, T); | ||
1593 | q->rec8b = EZ(t->rec8b * 1000, T); | ||
1594 | q->cyc8b = EZ(t->cyc8b * 1000, T); | ||
1595 | q->active = EZ(t->active * 1000, T); | ||
1596 | q->recover = EZ(t->recover * 1000, T); | ||
1597 | q->cycle = EZ(t->cycle * 1000, T); | ||
1598 | q->udma = EZ(t->udma * 1000, UT); | ||
1599 | } | ||
1600 | |||
1601 | void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b, | ||
1602 | struct ata_timing *m, unsigned int what) | ||
1603 | { | ||
1604 | if (what & ATA_TIMING_SETUP ) m->setup = max(a->setup, b->setup); | ||
1605 | if (what & ATA_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b); | ||
1606 | if (what & ATA_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b); | ||
1607 | if (what & ATA_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b); | ||
1608 | if (what & ATA_TIMING_ACTIVE ) m->active = max(a->active, b->active); | ||
1609 | if (what & ATA_TIMING_RECOVER) m->recover = max(a->recover, b->recover); | ||
1610 | if (what & ATA_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle); | ||
1611 | if (what & ATA_TIMING_UDMA ) m->udma = max(a->udma, b->udma); | ||
1612 | } | ||
1613 | |||
1614 | static const struct ata_timing* ata_timing_find_mode(unsigned short speed) | ||
1615 | { | ||
1616 | const struct ata_timing *t; | ||
1617 | |||
1618 | for (t = ata_timing; t->mode != speed; t++) | ||
1619 | if (t->mode == 0xFF) | ||
1620 | return NULL; | ||
1621 | return t; | ||
1622 | } | ||
1623 | |||
1624 | int ata_timing_compute(struct ata_device *adev, unsigned short speed, | ||
1625 | struct ata_timing *t, int T, int UT) | ||
1626 | { | ||
1627 | const struct ata_timing *s; | ||
1628 | struct ata_timing p; | ||
1629 | |||
1630 | /* | ||
1631 | * Find the mode. | ||
1632 | */ | ||
1633 | |||
1634 | if (!(s = ata_timing_find_mode(speed))) | ||
1635 | return -EINVAL; | ||
1636 | |||
1637 | /* | ||
1638 | * If the drive is an EIDE drive, it can tell us it needs extended | ||
1639 | * PIO/MW_DMA cycle timing. | ||
1640 | */ | ||
1641 | |||
1642 | if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */ | ||
1643 | memset(&p, 0, sizeof(p)); | ||
1644 | if(speed >= XFER_PIO_0 && speed <= XFER_SW_DMA_0) { | ||
1645 | if (speed <= XFER_PIO_2) p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO]; | ||
1646 | else p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO_IORDY]; | ||
1647 | } else if(speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) { | ||
1648 | p.cycle = adev->id[ATA_ID_EIDE_DMA_MIN]; | ||
1649 | } | ||
1650 | ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B); | ||
1651 | } | ||
1652 | |||
1653 | /* | ||
1654 | * Convert the timing to bus clock counts. | ||
1655 | */ | ||
1656 | |||
1657 | ata_timing_quantize(s, t, T, UT); | ||
1658 | |||
1659 | /* | ||
1660 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, S.M.A.R.T | ||
1661 | * and some other commands. We have to ensure that the DMA cycle timing is | ||
1662 | * slower/equal than the fastest PIO timing. | ||
1663 | */ | ||
1664 | |||
1665 | if (speed > XFER_PIO_4) { | ||
1666 | ata_timing_compute(adev, adev->pio_mode, &p, T, UT); | ||
1667 | ata_timing_merge(&p, t, t, ATA_TIMING_ALL); | ||
1668 | } | ||
1669 | |||
1670 | /* | ||
1671 | * Lenghten active & recovery time so that cycle time is correct. | ||
1672 | */ | ||
1673 | |||
1674 | if (t->act8b + t->rec8b < t->cyc8b) { | ||
1675 | t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; | ||
1676 | t->rec8b = t->cyc8b - t->act8b; | ||
1677 | } | ||
1678 | |||
1679 | if (t->active + t->recover < t->cycle) { | ||
1680 | t->active += (t->cycle - (t->active + t->recover)) / 2; | ||
1681 | t->recover = t->cycle - t->active; | ||
1682 | } | ||
1683 | |||
1684 | return 0; | ||
1685 | } | ||
1686 | |||
1687 | static const struct { | ||
1500 | unsigned int shift; | 1688 | unsigned int shift; |
1501 | u8 base; | 1689 | u8 base; |
1502 | } xfer_mode_classes[] = { | 1690 | } xfer_mode_classes[] = { |
@@ -1603,7 +1791,7 @@ static void ata_host_set_dma(struct ata_port *ap, u8 xfer_mode, | |||
1603 | */ | 1791 | */ |
1604 | static void ata_set_mode(struct ata_port *ap) | 1792 | static void ata_set_mode(struct ata_port *ap) |
1605 | { | 1793 | { |
1606 | unsigned int i, xfer_shift; | 1794 | unsigned int xfer_shift; |
1607 | u8 xfer_mode; | 1795 | u8 xfer_mode; |
1608 | int rc; | 1796 | int rc; |
1609 | 1797 | ||
@@ -1632,11 +1820,6 @@ static void ata_set_mode(struct ata_port *ap) | |||
1632 | if (ap->ops->post_set_mode) | 1820 | if (ap->ops->post_set_mode) |
1633 | ap->ops->post_set_mode(ap); | 1821 | ap->ops->post_set_mode(ap); |
1634 | 1822 | ||
1635 | for (i = 0; i < 2; i++) { | ||
1636 | struct ata_device *dev = &ap->device[i]; | ||
1637 | ata_dev_set_protocol(dev); | ||
1638 | } | ||
1639 | |||
1640 | return; | 1823 | return; |
1641 | 1824 | ||
1642 | err_out: | 1825 | err_out: |
@@ -1910,7 +2093,8 @@ err_out: | |||
1910 | DPRINTK("EXIT\n"); | 2093 | DPRINTK("EXIT\n"); |
1911 | } | 2094 | } |
1912 | 2095 | ||
1913 | static void ata_pr_blacklisted(struct ata_port *ap, struct ata_device *dev) | 2096 | static void ata_pr_blacklisted(const struct ata_port *ap, |
2097 | const struct ata_device *dev) | ||
1914 | { | 2098 | { |
1915 | printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, disabling DMA\n", | 2099 | printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, disabling DMA\n", |
1916 | ap->id, dev->devno); | 2100 | ap->id, dev->devno); |
@@ -1948,7 +2132,7 @@ static const char * ata_dma_blacklist [] = { | |||
1948 | "_NEC DV5800A", | 2132 | "_NEC DV5800A", |
1949 | }; | 2133 | }; |
1950 | 2134 | ||
1951 | static int ata_dma_blacklisted(struct ata_port *ap, struct ata_device *dev) | 2135 | static int ata_dma_blacklisted(const struct ata_device *dev) |
1952 | { | 2136 | { |
1953 | unsigned char model_num[40]; | 2137 | unsigned char model_num[40]; |
1954 | char *s; | 2138 | char *s; |
@@ -1973,9 +2157,9 @@ static int ata_dma_blacklisted(struct ata_port *ap, struct ata_device *dev) | |||
1973 | return 0; | 2157 | return 0; |
1974 | } | 2158 | } |
1975 | 2159 | ||
1976 | static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift) | 2160 | static unsigned int ata_get_mode_mask(const struct ata_port *ap, int shift) |
1977 | { | 2161 | { |
1978 | struct ata_device *master, *slave; | 2162 | const struct ata_device *master, *slave; |
1979 | unsigned int mask; | 2163 | unsigned int mask; |
1980 | 2164 | ||
1981 | master = &ap->device[0]; | 2165 | master = &ap->device[0]; |
@@ -1987,14 +2171,14 @@ static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift) | |||
1987 | mask = ap->udma_mask; | 2171 | mask = ap->udma_mask; |
1988 | if (ata_dev_present(master)) { | 2172 | if (ata_dev_present(master)) { |
1989 | mask &= (master->id[ATA_ID_UDMA_MODES] & 0xff); | 2173 | mask &= (master->id[ATA_ID_UDMA_MODES] & 0xff); |
1990 | if (ata_dma_blacklisted(ap, master)) { | 2174 | if (ata_dma_blacklisted(master)) { |
1991 | mask = 0; | 2175 | mask = 0; |
1992 | ata_pr_blacklisted(ap, master); | 2176 | ata_pr_blacklisted(ap, master); |
1993 | } | 2177 | } |
1994 | } | 2178 | } |
1995 | if (ata_dev_present(slave)) { | 2179 | if (ata_dev_present(slave)) { |
1996 | mask &= (slave->id[ATA_ID_UDMA_MODES] & 0xff); | 2180 | mask &= (slave->id[ATA_ID_UDMA_MODES] & 0xff); |
1997 | if (ata_dma_blacklisted(ap, slave)) { | 2181 | if (ata_dma_blacklisted(slave)) { |
1998 | mask = 0; | 2182 | mask = 0; |
1999 | ata_pr_blacklisted(ap, slave); | 2183 | ata_pr_blacklisted(ap, slave); |
2000 | } | 2184 | } |
@@ -2004,14 +2188,14 @@ static unsigned int ata_get_mode_mask(struct ata_port *ap, int shift) | |||
2004 | mask = ap->mwdma_mask; | 2188 | mask = ap->mwdma_mask; |
2005 | if (ata_dev_present(master)) { | 2189 | if (ata_dev_present(master)) { |
2006 | mask &= (master->id[ATA_ID_MWDMA_MODES] & 0x07); | 2190 | mask &= (master->id[ATA_ID_MWDMA_MODES] & 0x07); |
2007 | if (ata_dma_blacklisted(ap, master)) { | 2191 | if (ata_dma_blacklisted(master)) { |
2008 | mask = 0; | 2192 | mask = 0; |
2009 | ata_pr_blacklisted(ap, master); | 2193 | ata_pr_blacklisted(ap, master); |
2010 | } | 2194 | } |
2011 | } | 2195 | } |
2012 | if (ata_dev_present(slave)) { | 2196 | if (ata_dev_present(slave)) { |
2013 | mask &= (slave->id[ATA_ID_MWDMA_MODES] & 0x07); | 2197 | mask &= (slave->id[ATA_ID_MWDMA_MODES] & 0x07); |
2014 | if (ata_dma_blacklisted(ap, slave)) { | 2198 | if (ata_dma_blacklisted(slave)) { |
2015 | mask = 0; | 2199 | mask = 0; |
2016 | ata_pr_blacklisted(ap, slave); | 2200 | ata_pr_blacklisted(ap, slave); |
2017 | } | 2201 | } |
@@ -2075,7 +2259,7 @@ static int fgb(u32 bitmap) | |||
2075 | * Zero on success, negative on error. | 2259 | * Zero on success, negative on error. |
2076 | */ | 2260 | */ |
2077 | 2261 | ||
2078 | static int ata_choose_xfer_mode(struct ata_port *ap, | 2262 | static int ata_choose_xfer_mode(const struct ata_port *ap, |
2079 | u8 *xfer_mode_out, | 2263 | u8 *xfer_mode_out, |
2080 | unsigned int *xfer_shift_out) | 2264 | unsigned int *xfer_shift_out) |
2081 | { | 2265 | { |
@@ -2144,6 +2328,110 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) | |||
2144 | } | 2328 | } |
2145 | 2329 | ||
2146 | /** | 2330 | /** |
2331 | * ata_dev_reread_id - Reread the device identify device info | ||
2332 | * @ap: port where the device is | ||
2333 | * @dev: device to reread the identify device info | ||
2334 | * | ||
2335 | * LOCKING: | ||
2336 | */ | ||
2337 | |||
2338 | static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev) | ||
2339 | { | ||
2340 | DECLARE_COMPLETION(wait); | ||
2341 | struct ata_queued_cmd *qc; | ||
2342 | unsigned long flags; | ||
2343 | int rc; | ||
2344 | |||
2345 | qc = ata_qc_new_init(ap, dev); | ||
2346 | BUG_ON(qc == NULL); | ||
2347 | |||
2348 | ata_sg_init_one(qc, dev->id, sizeof(dev->id)); | ||
2349 | qc->dma_dir = DMA_FROM_DEVICE; | ||
2350 | |||
2351 | if (dev->class == ATA_DEV_ATA) { | ||
2352 | qc->tf.command = ATA_CMD_ID_ATA; | ||
2353 | DPRINTK("do ATA identify\n"); | ||
2354 | } else { | ||
2355 | qc->tf.command = ATA_CMD_ID_ATAPI; | ||
2356 | DPRINTK("do ATAPI identify\n"); | ||
2357 | } | ||
2358 | |||
2359 | qc->tf.flags |= ATA_TFLAG_DEVICE; | ||
2360 | qc->tf.protocol = ATA_PROT_PIO; | ||
2361 | qc->nsect = 1; | ||
2362 | |||
2363 | qc->waiting = &wait; | ||
2364 | qc->complete_fn = ata_qc_complete_noop; | ||
2365 | |||
2366 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
2367 | rc = ata_qc_issue(qc); | ||
2368 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
2369 | |||
2370 | if (rc) | ||
2371 | goto err_out; | ||
2372 | |||
2373 | wait_for_completion(&wait); | ||
2374 | |||
2375 | swap_buf_le16(dev->id, ATA_ID_WORDS); | ||
2376 | |||
2377 | ata_dump_id(dev); | ||
2378 | |||
2379 | DPRINTK("EXIT\n"); | ||
2380 | |||
2381 | return; | ||
2382 | err_out: | ||
2383 | ata_port_disable(ap); | ||
2384 | } | ||
2385 | |||
2386 | /** | ||
2387 | * ata_dev_init_params - Issue INIT DEV PARAMS command | ||
2388 | * @ap: Port associated with device @dev | ||
2389 | * @dev: Device to which command will be sent | ||
2390 | * | ||
2391 | * LOCKING: | ||
2392 | */ | ||
2393 | |||
2394 | static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev) | ||
2395 | { | ||
2396 | DECLARE_COMPLETION(wait); | ||
2397 | struct ata_queued_cmd *qc; | ||
2398 | int rc; | ||
2399 | unsigned long flags; | ||
2400 | u16 sectors = dev->id[6]; | ||
2401 | u16 heads = dev->id[3]; | ||
2402 | |||
2403 | /* Number of sectors per track 1-255. Number of heads 1-16 */ | ||
2404 | if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16) | ||
2405 | return; | ||
2406 | |||
2407 | /* set up init dev params taskfile */ | ||
2408 | DPRINTK("init dev params \n"); | ||
2409 | |||
2410 | qc = ata_qc_new_init(ap, dev); | ||
2411 | BUG_ON(qc == NULL); | ||
2412 | |||
2413 | qc->tf.command = ATA_CMD_INIT_DEV_PARAMS; | ||
2414 | qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | ||
2415 | qc->tf.protocol = ATA_PROT_NODATA; | ||
2416 | qc->tf.nsect = sectors; | ||
2417 | qc->tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ | ||
2418 | |||
2419 | qc->waiting = &wait; | ||
2420 | qc->complete_fn = ata_qc_complete_noop; | ||
2421 | |||
2422 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
2423 | rc = ata_qc_issue(qc); | ||
2424 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
2425 | |||
2426 | if (rc) | ||
2427 | ata_port_disable(ap); | ||
2428 | else | ||
2429 | wait_for_completion(&wait); | ||
2430 | |||
2431 | DPRINTK("EXIT\n"); | ||
2432 | } | ||
2433 | |||
2434 | /** | ||
2147 | * ata_sg_clean - Unmap DMA memory associated with command | 2435 | * ata_sg_clean - Unmap DMA memory associated with command |
2148 | * @qc: Command containing DMA memory to be released | 2436 | * @qc: Command containing DMA memory to be released |
2149 | * | 2437 | * |
@@ -2413,32 +2701,32 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | |||
2413 | 2701 | ||
2414 | /** | 2702 | /** |
2415 | * ata_pio_poll - | 2703 | * ata_pio_poll - |
2416 | * @ap: | 2704 | * @ap: the target ata_port |
2417 | * | 2705 | * |
2418 | * LOCKING: | 2706 | * LOCKING: |
2419 | * None. (executing in kernel thread context) | 2707 | * None. (executing in kernel thread context) |
2420 | * | 2708 | * |
2421 | * RETURNS: | 2709 | * RETURNS: |
2422 | * | 2710 | * timeout value to use |
2423 | */ | 2711 | */ |
2424 | 2712 | ||
2425 | static unsigned long ata_pio_poll(struct ata_port *ap) | 2713 | static unsigned long ata_pio_poll(struct ata_port *ap) |
2426 | { | 2714 | { |
2427 | u8 status; | 2715 | u8 status; |
2428 | unsigned int poll_state = PIO_ST_UNKNOWN; | 2716 | unsigned int poll_state = HSM_ST_UNKNOWN; |
2429 | unsigned int reg_state = PIO_ST_UNKNOWN; | 2717 | unsigned int reg_state = HSM_ST_UNKNOWN; |
2430 | const unsigned int tmout_state = PIO_ST_TMOUT; | 2718 | const unsigned int tmout_state = HSM_ST_TMOUT; |
2431 | 2719 | ||
2432 | switch (ap->pio_task_state) { | 2720 | switch (ap->hsm_task_state) { |
2433 | case PIO_ST: | 2721 | case HSM_ST: |
2434 | case PIO_ST_POLL: | 2722 | case HSM_ST_POLL: |
2435 | poll_state = PIO_ST_POLL; | 2723 | poll_state = HSM_ST_POLL; |
2436 | reg_state = PIO_ST; | 2724 | reg_state = HSM_ST; |
2437 | break; | 2725 | break; |
2438 | case PIO_ST_LAST: | 2726 | case HSM_ST_LAST: |
2439 | case PIO_ST_LAST_POLL: | 2727 | case HSM_ST_LAST_POLL: |
2440 | poll_state = PIO_ST_LAST_POLL; | 2728 | poll_state = HSM_ST_LAST_POLL; |
2441 | reg_state = PIO_ST_LAST; | 2729 | reg_state = HSM_ST_LAST; |
2442 | break; | 2730 | break; |
2443 | default: | 2731 | default: |
2444 | BUG(); | 2732 | BUG(); |
@@ -2448,20 +2736,20 @@ static unsigned long ata_pio_poll(struct ata_port *ap) | |||
2448 | status = ata_chk_status(ap); | 2736 | status = ata_chk_status(ap); |
2449 | if (status & ATA_BUSY) { | 2737 | if (status & ATA_BUSY) { |
2450 | if (time_after(jiffies, ap->pio_task_timeout)) { | 2738 | if (time_after(jiffies, ap->pio_task_timeout)) { |
2451 | ap->pio_task_state = tmout_state; | 2739 | ap->hsm_task_state = tmout_state; |
2452 | return 0; | 2740 | return 0; |
2453 | } | 2741 | } |
2454 | ap->pio_task_state = poll_state; | 2742 | ap->hsm_task_state = poll_state; |
2455 | return ATA_SHORT_PAUSE; | 2743 | return ATA_SHORT_PAUSE; |
2456 | } | 2744 | } |
2457 | 2745 | ||
2458 | ap->pio_task_state = reg_state; | 2746 | ap->hsm_task_state = reg_state; |
2459 | return 0; | 2747 | return 0; |
2460 | } | 2748 | } |
2461 | 2749 | ||
2462 | /** | 2750 | /** |
2463 | * ata_pio_complete - | 2751 | * ata_pio_complete - check if drive is busy or idle |
2464 | * @ap: | 2752 | * @ap: the target ata_port |
2465 | * | 2753 | * |
2466 | * LOCKING: | 2754 | * LOCKING: |
2467 | * None. (executing in kernel thread context) | 2755 | * None. (executing in kernel thread context) |
@@ -2480,14 +2768,14 @@ static int ata_pio_complete (struct ata_port *ap) | |||
2480 | * we enter, BSY will be cleared in a chk-status or two. If not, | 2768 | * we enter, BSY will be cleared in a chk-status or two. If not, |
2481 | * the drive is probably seeking or something. Snooze for a couple | 2769 | * the drive is probably seeking or something. Snooze for a couple |
2482 | * msecs, then chk-status again. If still busy, fall back to | 2770 | * msecs, then chk-status again. If still busy, fall back to |
2483 | * PIO_ST_POLL state. | 2771 | * HSM_ST_POLL state. |
2484 | */ | 2772 | */ |
2485 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); | 2773 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); |
2486 | if (drv_stat & (ATA_BUSY | ATA_DRQ)) { | 2774 | if (drv_stat & (ATA_BUSY | ATA_DRQ)) { |
2487 | msleep(2); | 2775 | msleep(2); |
2488 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); | 2776 | drv_stat = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 10); |
2489 | if (drv_stat & (ATA_BUSY | ATA_DRQ)) { | 2777 | if (drv_stat & (ATA_BUSY | ATA_DRQ)) { |
2490 | ap->pio_task_state = PIO_ST_LAST_POLL; | 2778 | ap->hsm_task_state = HSM_ST_LAST_POLL; |
2491 | ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; | 2779 | ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; |
2492 | return 0; | 2780 | return 0; |
2493 | } | 2781 | } |
@@ -2495,14 +2783,14 @@ static int ata_pio_complete (struct ata_port *ap) | |||
2495 | 2783 | ||
2496 | drv_stat = ata_wait_idle(ap); | 2784 | drv_stat = ata_wait_idle(ap); |
2497 | if (!ata_ok(drv_stat)) { | 2785 | if (!ata_ok(drv_stat)) { |
2498 | ap->pio_task_state = PIO_ST_ERR; | 2786 | ap->hsm_task_state = HSM_ST_ERR; |
2499 | return 0; | 2787 | return 0; |
2500 | } | 2788 | } |
2501 | 2789 | ||
2502 | qc = ata_qc_from_tag(ap, ap->active_tag); | 2790 | qc = ata_qc_from_tag(ap, ap->active_tag); |
2503 | assert(qc != NULL); | 2791 | assert(qc != NULL); |
2504 | 2792 | ||
2505 | ap->pio_task_state = PIO_ST_IDLE; | 2793 | ap->hsm_task_state = HSM_ST_IDLE; |
2506 | 2794 | ||
2507 | ata_poll_qc_complete(qc, drv_stat); | 2795 | ata_poll_qc_complete(qc, drv_stat); |
2508 | 2796 | ||
@@ -2513,7 +2801,7 @@ static int ata_pio_complete (struct ata_port *ap) | |||
2513 | 2801 | ||
2514 | 2802 | ||
2515 | /** | 2803 | /** |
2516 | * swap_buf_le16 - | 2804 | * swap_buf_le16 - swap halves of 16-words in place |
2517 | * @buf: Buffer to swap | 2805 | * @buf: Buffer to swap |
2518 | * @buf_words: Number of 16-bit words in buffer. | 2806 | * @buf_words: Number of 16-bit words in buffer. |
2519 | * | 2807 | * |
@@ -2522,6 +2810,7 @@ static int ata_pio_complete (struct ata_port *ap) | |||
2522 | * vice-versa. | 2810 | * vice-versa. |
2523 | * | 2811 | * |
2524 | * LOCKING: | 2812 | * LOCKING: |
2813 | * Inherited from caller. | ||
2525 | */ | 2814 | */ |
2526 | void swap_buf_le16(u16 *buf, unsigned int buf_words) | 2815 | void swap_buf_le16(u16 *buf, unsigned int buf_words) |
2527 | { | 2816 | { |
@@ -2544,7 +2833,6 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words) | |||
2544 | * | 2833 | * |
2545 | * LOCKING: | 2834 | * LOCKING: |
2546 | * Inherited from caller. | 2835 | * Inherited from caller. |
2547 | * | ||
2548 | */ | 2836 | */ |
2549 | 2837 | ||
2550 | static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, | 2838 | static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, |
@@ -2590,7 +2878,6 @@ static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, | |||
2590 | * | 2878 | * |
2591 | * LOCKING: | 2879 | * LOCKING: |
2592 | * Inherited from caller. | 2880 | * Inherited from caller. |
2593 | * | ||
2594 | */ | 2881 | */ |
2595 | 2882 | ||
2596 | static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, | 2883 | static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, |
@@ -2630,7 +2917,6 @@ static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, | |||
2630 | * | 2917 | * |
2631 | * LOCKING: | 2918 | * LOCKING: |
2632 | * Inherited from caller. | 2919 | * Inherited from caller. |
2633 | * | ||
2634 | */ | 2920 | */ |
2635 | 2921 | ||
2636 | static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, | 2922 | static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, |
@@ -2662,7 +2948,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) | |||
2662 | unsigned char *buf; | 2948 | unsigned char *buf; |
2663 | 2949 | ||
2664 | if (qc->cursect == (qc->nsect - 1)) | 2950 | if (qc->cursect == (qc->nsect - 1)) |
2665 | ap->pio_task_state = PIO_ST_LAST; | 2951 | ap->hsm_task_state = HSM_ST_LAST; |
2666 | 2952 | ||
2667 | page = sg[qc->cursg].page; | 2953 | page = sg[qc->cursg].page; |
2668 | offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE; | 2954 | offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE; |
@@ -2712,7 +2998,7 @@ static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | |||
2712 | unsigned int offset, count; | 2998 | unsigned int offset, count; |
2713 | 2999 | ||
2714 | if (qc->curbytes + bytes >= qc->nbytes) | 3000 | if (qc->curbytes + bytes >= qc->nbytes) |
2715 | ap->pio_task_state = PIO_ST_LAST; | 3001 | ap->hsm_task_state = HSM_ST_LAST; |
2716 | 3002 | ||
2717 | next_sg: | 3003 | next_sg: |
2718 | if (unlikely(qc->cursg >= qc->n_elem)) { | 3004 | if (unlikely(qc->cursg >= qc->n_elem)) { |
@@ -2734,7 +3020,7 @@ next_sg: | |||
2734 | for (i = 0; i < words; i++) | 3020 | for (i = 0; i < words; i++) |
2735 | ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write); | 3021 | ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write); |
2736 | 3022 | ||
2737 | ap->pio_task_state = PIO_ST_LAST; | 3023 | ap->hsm_task_state = HSM_ST_LAST; |
2738 | return; | 3024 | return; |
2739 | } | 3025 | } |
2740 | 3026 | ||
@@ -2783,7 +3069,6 @@ next_sg: | |||
2783 | * | 3069 | * |
2784 | * LOCKING: | 3070 | * LOCKING: |
2785 | * Inherited from caller. | 3071 | * Inherited from caller. |
2786 | * | ||
2787 | */ | 3072 | */ |
2788 | 3073 | ||
2789 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) | 3074 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) |
@@ -2815,12 +3100,12 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc) | |||
2815 | err_out: | 3100 | err_out: |
2816 | printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", | 3101 | printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", |
2817 | ap->id, dev->devno); | 3102 | ap->id, dev->devno); |
2818 | ap->pio_task_state = PIO_ST_ERR; | 3103 | ap->hsm_task_state = HSM_ST_ERR; |
2819 | } | 3104 | } |
2820 | 3105 | ||
2821 | /** | 3106 | /** |
2822 | * ata_pio_sector - | 3107 | * ata_pio_block - start PIO on a block |
2823 | * @ap: | 3108 | * @ap: the target ata_port |
2824 | * | 3109 | * |
2825 | * LOCKING: | 3110 | * LOCKING: |
2826 | * None. (executing in kernel thread context) | 3111 | * None. (executing in kernel thread context) |
@@ -2832,19 +3117,19 @@ static void ata_pio_block(struct ata_port *ap) | |||
2832 | u8 status; | 3117 | u8 status; |
2833 | 3118 | ||
2834 | /* | 3119 | /* |
2835 | * This is purely hueristic. This is a fast path. | 3120 | * This is purely heuristic. This is a fast path. |
2836 | * Sometimes when we enter, BSY will be cleared in | 3121 | * Sometimes when we enter, BSY will be cleared in |
2837 | * a chk-status or two. If not, the drive is probably seeking | 3122 | * a chk-status or two. If not, the drive is probably seeking |
2838 | * or something. Snooze for a couple msecs, then | 3123 | * or something. Snooze for a couple msecs, then |
2839 | * chk-status again. If still busy, fall back to | 3124 | * chk-status again. If still busy, fall back to |
2840 | * PIO_ST_POLL state. | 3125 | * HSM_ST_POLL state. |
2841 | */ | 3126 | */ |
2842 | status = ata_busy_wait(ap, ATA_BUSY, 5); | 3127 | status = ata_busy_wait(ap, ATA_BUSY, 5); |
2843 | if (status & ATA_BUSY) { | 3128 | if (status & ATA_BUSY) { |
2844 | msleep(2); | 3129 | msleep(2); |
2845 | status = ata_busy_wait(ap, ATA_BUSY, 10); | 3130 | status = ata_busy_wait(ap, ATA_BUSY, 10); |
2846 | if (status & ATA_BUSY) { | 3131 | if (status & ATA_BUSY) { |
2847 | ap->pio_task_state = PIO_ST_POLL; | 3132 | ap->hsm_task_state = HSM_ST_POLL; |
2848 | ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; | 3133 | ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; |
2849 | return; | 3134 | return; |
2850 | } | 3135 | } |
@@ -2856,7 +3141,7 @@ static void ata_pio_block(struct ata_port *ap) | |||
2856 | if (is_atapi_taskfile(&qc->tf)) { | 3141 | if (is_atapi_taskfile(&qc->tf)) { |
2857 | /* no more data to transfer or unsupported ATAPI command */ | 3142 | /* no more data to transfer or unsupported ATAPI command */ |
2858 | if ((status & ATA_DRQ) == 0) { | 3143 | if ((status & ATA_DRQ) == 0) { |
2859 | ap->pio_task_state = PIO_ST_LAST; | 3144 | ap->hsm_task_state = HSM_ST_LAST; |
2860 | return; | 3145 | return; |
2861 | } | 3146 | } |
2862 | 3147 | ||
@@ -2864,7 +3149,7 @@ static void ata_pio_block(struct ata_port *ap) | |||
2864 | } else { | 3149 | } else { |
2865 | /* handle BSY=0, DRQ=0 as error */ | 3150 | /* handle BSY=0, DRQ=0 as error */ |
2866 | if ((status & ATA_DRQ) == 0) { | 3151 | if ((status & ATA_DRQ) == 0) { |
2867 | ap->pio_task_state = PIO_ST_ERR; | 3152 | ap->hsm_task_state = HSM_ST_ERR; |
2868 | return; | 3153 | return; |
2869 | } | 3154 | } |
2870 | 3155 | ||
@@ -2884,7 +3169,7 @@ static void ata_pio_error(struct ata_port *ap) | |||
2884 | printk(KERN_WARNING "ata%u: PIO error, drv_stat 0x%x\n", | 3169 | printk(KERN_WARNING "ata%u: PIO error, drv_stat 0x%x\n", |
2885 | ap->id, drv_stat); | 3170 | ap->id, drv_stat); |
2886 | 3171 | ||
2887 | ap->pio_task_state = PIO_ST_IDLE; | 3172 | ap->hsm_task_state = HSM_ST_IDLE; |
2888 | 3173 | ||
2889 | ata_poll_qc_complete(qc, drv_stat | ATA_ERR); | 3174 | ata_poll_qc_complete(qc, drv_stat | ATA_ERR); |
2890 | } | 3175 | } |
@@ -2899,25 +3184,25 @@ fsm_start: | |||
2899 | timeout = 0; | 3184 | timeout = 0; |
2900 | qc_completed = 0; | 3185 | qc_completed = 0; |
2901 | 3186 | ||
2902 | switch (ap->pio_task_state) { | 3187 | switch (ap->hsm_task_state) { |
2903 | case PIO_ST_IDLE: | 3188 | case HSM_ST_IDLE: |
2904 | return; | 3189 | return; |
2905 | 3190 | ||
2906 | case PIO_ST: | 3191 | case HSM_ST: |
2907 | ata_pio_block(ap); | 3192 | ata_pio_block(ap); |
2908 | break; | 3193 | break; |
2909 | 3194 | ||
2910 | case PIO_ST_LAST: | 3195 | case HSM_ST_LAST: |
2911 | qc_completed = ata_pio_complete(ap); | 3196 | qc_completed = ata_pio_complete(ap); |
2912 | break; | 3197 | break; |
2913 | 3198 | ||
2914 | case PIO_ST_POLL: | 3199 | case HSM_ST_POLL: |
2915 | case PIO_ST_LAST_POLL: | 3200 | case HSM_ST_LAST_POLL: |
2916 | timeout = ata_pio_poll(ap); | 3201 | timeout = ata_pio_poll(ap); |
2917 | break; | 3202 | break; |
2918 | 3203 | ||
2919 | case PIO_ST_TMOUT: | 3204 | case HSM_ST_TMOUT: |
2920 | case PIO_ST_ERR: | 3205 | case HSM_ST_ERR: |
2921 | ata_pio_error(ap); | 3206 | ata_pio_error(ap); |
2922 | return; | 3207 | return; |
2923 | } | 3208 | } |
@@ -2928,52 +3213,6 @@ fsm_start: | |||
2928 | goto fsm_start; | 3213 | goto fsm_start; |
2929 | } | 3214 | } |
2930 | 3215 | ||
2931 | static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, | ||
2932 | struct scsi_cmnd *cmd) | ||
2933 | { | ||
2934 | DECLARE_COMPLETION(wait); | ||
2935 | struct ata_queued_cmd *qc; | ||
2936 | unsigned long flags; | ||
2937 | int rc; | ||
2938 | |||
2939 | DPRINTK("ATAPI request sense\n"); | ||
2940 | |||
2941 | qc = ata_qc_new_init(ap, dev); | ||
2942 | BUG_ON(qc == NULL); | ||
2943 | |||
2944 | /* FIXME: is this needed? */ | ||
2945 | memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer)); | ||
2946 | |||
2947 | ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); | ||
2948 | qc->dma_dir = DMA_FROM_DEVICE; | ||
2949 | |||
2950 | memset(&qc->cdb, 0, ap->cdb_len); | ||
2951 | qc->cdb[0] = REQUEST_SENSE; | ||
2952 | qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; | ||
2953 | |||
2954 | qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; | ||
2955 | qc->tf.command = ATA_CMD_PACKET; | ||
2956 | |||
2957 | qc->tf.protocol = ATA_PROT_ATAPI; | ||
2958 | qc->tf.lbam = (8 * 1024) & 0xff; | ||
2959 | qc->tf.lbah = (8 * 1024) >> 8; | ||
2960 | qc->nbytes = SCSI_SENSE_BUFFERSIZE; | ||
2961 | |||
2962 | qc->waiting = &wait; | ||
2963 | qc->complete_fn = ata_qc_complete_noop; | ||
2964 | |||
2965 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
2966 | rc = ata_qc_issue(qc); | ||
2967 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
2968 | |||
2969 | if (rc) | ||
2970 | ata_port_disable(ap); | ||
2971 | else | ||
2972 | wait_for_completion(&wait); | ||
2973 | |||
2974 | DPRINTK("EXIT\n"); | ||
2975 | } | ||
2976 | |||
2977 | /** | 3216 | /** |
2978 | * ata_qc_timeout - Handle timeout of queued command | 3217 | * ata_qc_timeout - Handle timeout of queued command |
2979 | * @qc: Command that timed out | 3218 | * @qc: Command that timed out |
@@ -3091,14 +3330,14 @@ void ata_eng_timeout(struct ata_port *ap) | |||
3091 | DPRINTK("ENTER\n"); | 3330 | DPRINTK("ENTER\n"); |
3092 | 3331 | ||
3093 | qc = ata_qc_from_tag(ap, ap->active_tag); | 3332 | qc = ata_qc_from_tag(ap, ap->active_tag); |
3094 | if (!qc) { | 3333 | if (qc) |
3334 | ata_qc_timeout(qc); | ||
3335 | else { | ||
3095 | printk(KERN_ERR "ata%u: BUG: timeout without command\n", | 3336 | printk(KERN_ERR "ata%u: BUG: timeout without command\n", |
3096 | ap->id); | 3337 | ap->id); |
3097 | goto out; | 3338 | goto out; |
3098 | } | 3339 | } |
3099 | 3340 | ||
3100 | ata_qc_timeout(qc); | ||
3101 | |||
3102 | out: | 3341 | out: |
3103 | DPRINTK("EXIT\n"); | 3342 | DPRINTK("EXIT\n"); |
3104 | } | 3343 | } |
@@ -3155,15 +3394,12 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, | |||
3155 | qc->nbytes = qc->curbytes = 0; | 3394 | qc->nbytes = qc->curbytes = 0; |
3156 | 3395 | ||
3157 | ata_tf_init(ap, &qc->tf, dev->devno); | 3396 | ata_tf_init(ap, &qc->tf, dev->devno); |
3158 | |||
3159 | if (dev->flags & ATA_DFLAG_LBA48) | ||
3160 | qc->tf.flags |= ATA_TFLAG_LBA48; | ||
3161 | } | 3397 | } |
3162 | 3398 | ||
3163 | return qc; | 3399 | return qc; |
3164 | } | 3400 | } |
3165 | 3401 | ||
3166 | static int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat) | 3402 | int ata_qc_complete_noop(struct ata_queued_cmd *qc, u8 drv_stat) |
3167 | { | 3403 | { |
3168 | return 0; | 3404 | return 0; |
3169 | } | 3405 | } |
@@ -3201,7 +3437,6 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc) | |||
3201 | * | 3437 | * |
3202 | * LOCKING: | 3438 | * LOCKING: |
3203 | * spin_lock_irqsave(host_set lock) | 3439 | * spin_lock_irqsave(host_set lock) |
3204 | * | ||
3205 | */ | 3440 | */ |
3206 | void ata_qc_free(struct ata_queued_cmd *qc) | 3441 | void ata_qc_free(struct ata_queued_cmd *qc) |
3207 | { | 3442 | { |
@@ -3221,7 +3456,6 @@ void ata_qc_free(struct ata_queued_cmd *qc) | |||
3221 | * | 3456 | * |
3222 | * LOCKING: | 3457 | * LOCKING: |
3223 | * spin_lock_irqsave(host_set lock) | 3458 | * spin_lock_irqsave(host_set lock) |
3224 | * | ||
3225 | */ | 3459 | */ |
3226 | 3460 | ||
3227 | void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | 3461 | void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) |
@@ -3360,7 +3594,7 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc) | |||
3360 | case ATA_PROT_PIO: /* load tf registers, initiate polling pio */ | 3594 | case ATA_PROT_PIO: /* load tf registers, initiate polling pio */ |
3361 | ata_qc_set_polling(qc); | 3595 | ata_qc_set_polling(qc); |
3362 | ata_tf_to_host_nolock(ap, &qc->tf); | 3596 | ata_tf_to_host_nolock(ap, &qc->tf); |
3363 | ap->pio_task_state = PIO_ST; | 3597 | ap->hsm_task_state = HSM_ST; |
3364 | queue_work(ata_wq, &ap->pio_task); | 3598 | queue_work(ata_wq, &ap->pio_task); |
3365 | break; | 3599 | break; |
3366 | 3600 | ||
@@ -3586,7 +3820,7 @@ u8 ata_bmdma_status(struct ata_port *ap) | |||
3586 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; | 3820 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; |
3587 | host_stat = readb(mmio + ATA_DMA_STATUS); | 3821 | host_stat = readb(mmio + ATA_DMA_STATUS); |
3588 | } else | 3822 | } else |
3589 | host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); | 3823 | host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); |
3590 | return host_stat; | 3824 | return host_stat; |
3591 | } | 3825 | } |
3592 | 3826 | ||
@@ -3715,7 +3949,6 @@ idle_irq: | |||
3715 | * | 3949 | * |
3716 | * RETURNS: | 3950 | * RETURNS: |
3717 | * IRQ_NONE or IRQ_HANDLED. | 3951 | * IRQ_NONE or IRQ_HANDLED. |
3718 | * | ||
3719 | */ | 3952 | */ |
3720 | 3953 | ||
3721 | irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs) | 3954 | irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs) |
@@ -3806,7 +4039,7 @@ static void atapi_packet_task(void *_data) | |||
3806 | ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); | 4039 | ata_data_xfer(ap, qc->cdb, ap->cdb_len, 1); |
3807 | 4040 | ||
3808 | /* PIO commands are handled by polling */ | 4041 | /* PIO commands are handled by polling */ |
3809 | ap->pio_task_state = PIO_ST; | 4042 | ap->hsm_task_state = HSM_ST; |
3810 | queue_work(ata_wq, &ap->pio_task); | 4043 | queue_work(ata_wq, &ap->pio_task); |
3811 | } | 4044 | } |
3812 | 4045 | ||
@@ -3827,6 +4060,7 @@ err_out: | |||
3827 | * May be used as the port_start() entry in ata_port_operations. | 4060 | * May be used as the port_start() entry in ata_port_operations. |
3828 | * | 4061 | * |
3829 | * LOCKING: | 4062 | * LOCKING: |
4063 | * Inherited from caller. | ||
3830 | */ | 4064 | */ |
3831 | 4065 | ||
3832 | int ata_port_start (struct ata_port *ap) | 4066 | int ata_port_start (struct ata_port *ap) |
@@ -3852,6 +4086,7 @@ int ata_port_start (struct ata_port *ap) | |||
3852 | * May be used as the port_stop() entry in ata_port_operations. | 4086 | * May be used as the port_stop() entry in ata_port_operations. |
3853 | * | 4087 | * |
3854 | * LOCKING: | 4088 | * LOCKING: |
4089 | * Inherited from caller. | ||
3855 | */ | 4090 | */ |
3856 | 4091 | ||
3857 | void ata_port_stop (struct ata_port *ap) | 4092 | void ata_port_stop (struct ata_port *ap) |
@@ -3874,6 +4109,7 @@ void ata_host_stop (struct ata_host_set *host_set) | |||
3874 | * @do_unregister: 1 if we fully unregister, 0 to just stop the port | 4109 | * @do_unregister: 1 if we fully unregister, 0 to just stop the port |
3875 | * | 4110 | * |
3876 | * LOCKING: | 4111 | * LOCKING: |
4112 | * Inherited from caller. | ||
3877 | */ | 4113 | */ |
3878 | 4114 | ||
3879 | static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister) | 4115 | static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister) |
@@ -3901,12 +4137,11 @@ static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister) | |||
3901 | * | 4137 | * |
3902 | * LOCKING: | 4138 | * LOCKING: |
3903 | * Inherited from caller. | 4139 | * Inherited from caller. |
3904 | * | ||
3905 | */ | 4140 | */ |
3906 | 4141 | ||
3907 | static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, | 4142 | static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, |
3908 | struct ata_host_set *host_set, | 4143 | struct ata_host_set *host_set, |
3909 | struct ata_probe_ent *ent, unsigned int port_no) | 4144 | const struct ata_probe_ent *ent, unsigned int port_no) |
3910 | { | 4145 | { |
3911 | unsigned int i; | 4146 | unsigned int i; |
3912 | 4147 | ||
@@ -3962,10 +4197,9 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, | |||
3962 | * | 4197 | * |
3963 | * RETURNS: | 4198 | * RETURNS: |
3964 | * New ata_port on success, for NULL on error. | 4199 | * New ata_port on success, for NULL on error. |
3965 | * | ||
3966 | */ | 4200 | */ |
3967 | 4201 | ||
3968 | static struct ata_port * ata_host_add(struct ata_probe_ent *ent, | 4202 | static struct ata_port * ata_host_add(const struct ata_probe_ent *ent, |
3969 | struct ata_host_set *host_set, | 4203 | struct ata_host_set *host_set, |
3970 | unsigned int port_no) | 4204 | unsigned int port_no) |
3971 | { | 4205 | { |
@@ -4010,10 +4244,9 @@ err_out: | |||
4010 | * | 4244 | * |
4011 | * RETURNS: | 4245 | * RETURNS: |
4012 | * Number of ports registered. Zero on error (no ports registered). | 4246 | * Number of ports registered. Zero on error (no ports registered). |
4013 | * | ||
4014 | */ | 4247 | */ |
4015 | 4248 | ||
4016 | int ata_device_add(struct ata_probe_ent *ent) | 4249 | int ata_device_add(const struct ata_probe_ent *ent) |
4017 | { | 4250 | { |
4018 | unsigned int count = 0, i; | 4251 | unsigned int count = 0, i; |
4019 | struct device *dev = ent->dev; | 4252 | struct device *dev = ent->dev; |
@@ -4113,7 +4346,7 @@ int ata_device_add(struct ata_probe_ent *ent) | |||
4113 | for (i = 0; i < count; i++) { | 4346 | for (i = 0; i < count; i++) { |
4114 | struct ata_port *ap = host_set->ports[i]; | 4347 | struct ata_port *ap = host_set->ports[i]; |
4115 | 4348 | ||
4116 | scsi_scan_host(ap->host); | 4349 | ata_scsi_scan_host(ap); |
4117 | } | 4350 | } |
4118 | 4351 | ||
4119 | dev_set_drvdata(dev, host_set); | 4352 | dev_set_drvdata(dev, host_set); |
@@ -4142,7 +4375,6 @@ err_out: | |||
4142 | * Inherited from calling layer (may sleep). | 4375 | * Inherited from calling layer (may sleep). |
4143 | */ | 4376 | */ |
4144 | 4377 | ||
4145 | |||
4146 | void ata_host_set_remove(struct ata_host_set *host_set) | 4378 | void ata_host_set_remove(struct ata_host_set *host_set) |
4147 | { | 4379 | { |
4148 | struct ata_port *ap; | 4380 | struct ata_port *ap; |
@@ -4232,7 +4464,7 @@ void ata_std_ports(struct ata_ioports *ioaddr) | |||
4232 | } | 4464 | } |
4233 | 4465 | ||
4234 | static struct ata_probe_ent * | 4466 | static struct ata_probe_ent * |
4235 | ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port) | 4467 | ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port) |
4236 | { | 4468 | { |
4237 | struct ata_probe_ent *probe_ent; | 4469 | struct ata_probe_ent *probe_ent; |
4238 | 4470 | ||
@@ -4273,85 +4505,86 @@ void ata_pci_host_stop (struct ata_host_set *host_set) | |||
4273 | * ata_pci_init_native_mode - Initialize native-mode driver | 4505 | * ata_pci_init_native_mode - Initialize native-mode driver |
4274 | * @pdev: pci device to be initialized | 4506 | * @pdev: pci device to be initialized |
4275 | * @port: array[2] of pointers to port info structures. | 4507 | * @port: array[2] of pointers to port info structures. |
4508 | * @ports: bitmap of ports present | ||
4276 | * | 4509 | * |
4277 | * Utility function which allocates and initializes an | 4510 | * Utility function which allocates and initializes an |
4278 | * ata_probe_ent structure for a standard dual-port | 4511 | * ata_probe_ent structure for a standard dual-port |
4279 | * PIO-based IDE controller. The returned ata_probe_ent | 4512 | * PIO-based IDE controller. The returned ata_probe_ent |
4280 | * structure can be passed to ata_device_add(). The returned | 4513 | * structure can be passed to ata_device_add(). The returned |
4281 | * ata_probe_ent structure should then be freed with kfree(). | 4514 | * ata_probe_ent structure should then be freed with kfree(). |
4515 | * | ||
4516 | * The caller need only pass the address of the primary port, the | ||
4517 | * secondary will be deduced automatically. If the device has non | ||
4518 | * standard secondary port mappings this function can be called twice, | ||
4519 | * once for each interface. | ||
4282 | */ | 4520 | */ |
4283 | 4521 | ||
4284 | struct ata_probe_ent * | 4522 | struct ata_probe_ent * |
4285 | ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) | 4523 | ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports) |
4286 | { | 4524 | { |
4287 | struct ata_probe_ent *probe_ent = | 4525 | struct ata_probe_ent *probe_ent = |
4288 | ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); | 4526 | ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); |
4527 | int p = 0; | ||
4528 | |||
4289 | if (!probe_ent) | 4529 | if (!probe_ent) |
4290 | return NULL; | 4530 | return NULL; |
4291 | 4531 | ||
4292 | probe_ent->n_ports = 2; | ||
4293 | probe_ent->irq = pdev->irq; | 4532 | probe_ent->irq = pdev->irq; |
4294 | probe_ent->irq_flags = SA_SHIRQ; | 4533 | probe_ent->irq_flags = SA_SHIRQ; |
4295 | 4534 | ||
4296 | probe_ent->port[0].cmd_addr = pci_resource_start(pdev, 0); | 4535 | if (ports & ATA_PORT_PRIMARY) { |
4297 | probe_ent->port[0].altstatus_addr = | 4536 | probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0); |
4298 | probe_ent->port[0].ctl_addr = | 4537 | probe_ent->port[p].altstatus_addr = |
4299 | pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; | 4538 | probe_ent->port[p].ctl_addr = |
4300 | probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4); | 4539 | pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; |
4301 | 4540 | probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4); | |
4302 | probe_ent->port[1].cmd_addr = pci_resource_start(pdev, 2); | 4541 | ata_std_ports(&probe_ent->port[p]); |
4303 | probe_ent->port[1].altstatus_addr = | 4542 | p++; |
4304 | probe_ent->port[1].ctl_addr = | 4543 | } |
4305 | pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS; | ||
4306 | probe_ent->port[1].bmdma_addr = pci_resource_start(pdev, 4) + 8; | ||
4307 | 4544 | ||
4308 | ata_std_ports(&probe_ent->port[0]); | 4545 | if (ports & ATA_PORT_SECONDARY) { |
4309 | ata_std_ports(&probe_ent->port[1]); | 4546 | probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 2); |
4547 | probe_ent->port[p].altstatus_addr = | ||
4548 | probe_ent->port[p].ctl_addr = | ||
4549 | pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS; | ||
4550 | probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4) + 8; | ||
4551 | ata_std_ports(&probe_ent->port[p]); | ||
4552 | p++; | ||
4553 | } | ||
4310 | 4554 | ||
4555 | probe_ent->n_ports = p; | ||
4311 | return probe_ent; | 4556 | return probe_ent; |
4312 | } | 4557 | } |
4313 | 4558 | ||
4314 | static struct ata_probe_ent * | 4559 | static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info **port, int port_num) |
4315 | ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port, | ||
4316 | struct ata_probe_ent **ppe2) | ||
4317 | { | 4560 | { |
4318 | struct ata_probe_ent *probe_ent, *probe_ent2; | 4561 | struct ata_probe_ent *probe_ent; |
4319 | 4562 | ||
4320 | probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); | 4563 | probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); |
4321 | if (!probe_ent) | 4564 | if (!probe_ent) |
4322 | return NULL; | 4565 | return NULL; |
4323 | probe_ent2 = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[1]); | ||
4324 | if (!probe_ent2) { | ||
4325 | kfree(probe_ent); | ||
4326 | return NULL; | ||
4327 | } | ||
4328 | |||
4329 | probe_ent->n_ports = 1; | ||
4330 | probe_ent->irq = 14; | ||
4331 | 4566 | ||
4332 | probe_ent->hard_port_no = 0; | ||
4333 | probe_ent->legacy_mode = 1; | 4567 | probe_ent->legacy_mode = 1; |
4334 | 4568 | probe_ent->n_ports = 1; | |
4335 | probe_ent2->n_ports = 1; | 4569 | probe_ent->hard_port_no = port_num; |
4336 | probe_ent2->irq = 15; | 4570 | |
4337 | 4571 | switch(port_num) | |
4338 | probe_ent2->hard_port_no = 1; | 4572 | { |
4339 | probe_ent2->legacy_mode = 1; | 4573 | case 0: |
4340 | 4574 | probe_ent->irq = 14; | |
4341 | probe_ent->port[0].cmd_addr = 0x1f0; | 4575 | probe_ent->port[0].cmd_addr = 0x1f0; |
4342 | probe_ent->port[0].altstatus_addr = | 4576 | probe_ent->port[0].altstatus_addr = |
4343 | probe_ent->port[0].ctl_addr = 0x3f6; | 4577 | probe_ent->port[0].ctl_addr = 0x3f6; |
4344 | probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4); | 4578 | break; |
4345 | 4579 | case 1: | |
4346 | probe_ent2->port[0].cmd_addr = 0x170; | 4580 | probe_ent->irq = 15; |
4347 | probe_ent2->port[0].altstatus_addr = | 4581 | probe_ent->port[0].cmd_addr = 0x170; |
4348 | probe_ent2->port[0].ctl_addr = 0x376; | 4582 | probe_ent->port[0].altstatus_addr = |
4349 | probe_ent2->port[0].bmdma_addr = pci_resource_start(pdev, 4)+8; | 4583 | probe_ent->port[0].ctl_addr = 0x376; |
4350 | 4584 | break; | |
4585 | } | ||
4586 | probe_ent->port[0].bmdma_addr = pci_resource_start(pdev, 4) + 8 * port_num; | ||
4351 | ata_std_ports(&probe_ent->port[0]); | 4587 | ata_std_ports(&probe_ent->port[0]); |
4352 | ata_std_ports(&probe_ent2->port[0]); | ||
4353 | |||
4354 | *ppe2 = probe_ent2; | ||
4355 | return probe_ent; | 4588 | return probe_ent; |
4356 | } | 4589 | } |
4357 | 4590 | ||
@@ -4374,13 +4607,12 @@ ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port, | |||
4374 | * | 4607 | * |
4375 | * RETURNS: | 4608 | * RETURNS: |
4376 | * Zero on success, negative on errno-based value on error. | 4609 | * Zero on success, negative on errno-based value on error. |
4377 | * | ||
4378 | */ | 4610 | */ |
4379 | 4611 | ||
4380 | int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | 4612 | int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, |
4381 | unsigned int n_ports) | 4613 | unsigned int n_ports) |
4382 | { | 4614 | { |
4383 | struct ata_probe_ent *probe_ent, *probe_ent2 = NULL; | 4615 | struct ata_probe_ent *probe_ent = NULL, *probe_ent2 = NULL; |
4384 | struct ata_port_info *port[2]; | 4616 | struct ata_port_info *port[2]; |
4385 | u8 tmp8, mask; | 4617 | u8 tmp8, mask; |
4386 | unsigned int legacy_mode = 0; | 4618 | unsigned int legacy_mode = 0; |
@@ -4397,7 +4629,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | |||
4397 | 4629 | ||
4398 | if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0 | 4630 | if ((port[0]->host_flags & ATA_FLAG_NO_LEGACY) == 0 |
4399 | && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { | 4631 | && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { |
4400 | /* TODO: support transitioning to native mode? */ | 4632 | /* TODO: What if one channel is in native mode ... */ |
4401 | pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8); | 4633 | pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8); |
4402 | mask = (1 << 2) | (1 << 0); | 4634 | mask = (1 << 2) | (1 << 0); |
4403 | if ((tmp8 & mask) != mask) | 4635 | if ((tmp8 & mask) != mask) |
@@ -4405,11 +4637,20 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | |||
4405 | } | 4637 | } |
4406 | 4638 | ||
4407 | /* FIXME... */ | 4639 | /* FIXME... */ |
4408 | if ((!legacy_mode) && (n_ports > 1)) { | 4640 | if ((!legacy_mode) && (n_ports > 2)) { |
4409 | printk(KERN_ERR "ata: BUG: native mode, n_ports > 1\n"); | 4641 | printk(KERN_ERR "ata: BUG: native mode, n_ports > 2\n"); |
4410 | return -EINVAL; | 4642 | n_ports = 2; |
4643 | /* For now */ | ||
4411 | } | 4644 | } |
4412 | 4645 | ||
4646 | /* FIXME: Really for ATA it isn't safe because the device may be | ||
4647 | multi-purpose and we want to leave it alone if it was already | ||
4648 | enabled. Secondly for shared use as Arjan says we want refcounting | ||
4649 | |||
4650 | Checking dev->is_enabled is insufficient as this is not set at | ||
4651 | boot for the primary video which is BIOS enabled | ||
4652 | */ | ||
4653 | |||
4413 | rc = pci_enable_device(pdev); | 4654 | rc = pci_enable_device(pdev); |
4414 | if (rc) | 4655 | if (rc) |
4415 | return rc; | 4656 | return rc; |
@@ -4420,6 +4661,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | |||
4420 | goto err_out; | 4661 | goto err_out; |
4421 | } | 4662 | } |
4422 | 4663 | ||
4664 | /* FIXME: Should use platform specific mappers for legacy port ranges */ | ||
4423 | if (legacy_mode) { | 4665 | if (legacy_mode) { |
4424 | if (!request_region(0x1f0, 8, "libata")) { | 4666 | if (!request_region(0x1f0, 8, "libata")) { |
4425 | struct resource *conflict, res; | 4667 | struct resource *conflict, res; |
@@ -4464,10 +4706,17 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, | |||
4464 | goto err_out_regions; | 4706 | goto err_out_regions; |
4465 | 4707 | ||
4466 | if (legacy_mode) { | 4708 | if (legacy_mode) { |
4467 | probe_ent = ata_pci_init_legacy_mode(pdev, port, &probe_ent2); | 4709 | if (legacy_mode & (1 << 0)) |
4468 | } else | 4710 | probe_ent = ata_pci_init_legacy_port(pdev, port, 0); |
4469 | probe_ent = ata_pci_init_native_mode(pdev, port); | 4711 | if (legacy_mode & (1 << 1)) |
4470 | if (!probe_ent) { | 4712 | probe_ent2 = ata_pci_init_legacy_port(pdev, port, 1); |
4713 | } else { | ||
4714 | if (n_ports == 2) | ||
4715 | probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); | ||
4716 | else | ||
4717 | probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY); | ||
4718 | } | ||
4719 | if (!probe_ent && !probe_ent2) { | ||
4471 | rc = -ENOMEM; | 4720 | rc = -ENOMEM; |
4472 | goto err_out_regions; | 4721 | goto err_out_regions; |
4473 | } | 4722 | } |
@@ -4505,7 +4754,7 @@ err_out: | |||
4505 | * @pdev: PCI device that was removed | 4754 | * @pdev: PCI device that was removed |
4506 | * | 4755 | * |
4507 | * PCI layer indicates to libata via this hook that | 4756 | * PCI layer indicates to libata via this hook that |
4508 | * hot-unplug or module unload event has occured. | 4757 | * hot-unplug or module unload event has occurred. |
4509 | * Handle this by unregistering all objects associated | 4758 | * Handle this by unregistering all objects associated |
4510 | * with this PCI device. Free those objects. Then finally | 4759 | * with this PCI device. Free those objects. Then finally |
4511 | * release PCI resources and disable device. | 4760 | * release PCI resources and disable device. |
@@ -4526,7 +4775,7 @@ void ata_pci_remove_one (struct pci_dev *pdev) | |||
4526 | } | 4775 | } |
4527 | 4776 | ||
4528 | /* move to PCI subsystem */ | 4777 | /* move to PCI subsystem */ |
4529 | int pci_test_config_bits(struct pci_dev *pdev, struct pci_bits *bits) | 4778 | int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits) |
4530 | { | 4779 | { |
4531 | unsigned long tmp = 0; | 4780 | unsigned long tmp = 0; |
4532 | 4781 | ||
@@ -4579,6 +4828,27 @@ static void __exit ata_exit(void) | |||
4579 | module_init(ata_init); | 4828 | module_init(ata_init); |
4580 | module_exit(ata_exit); | 4829 | module_exit(ata_exit); |
4581 | 4830 | ||
4831 | static unsigned long ratelimit_time; | ||
4832 | static spinlock_t ata_ratelimit_lock = SPIN_LOCK_UNLOCKED; | ||
4833 | |||
4834 | int ata_ratelimit(void) | ||
4835 | { | ||
4836 | int rc; | ||
4837 | unsigned long flags; | ||
4838 | |||
4839 | spin_lock_irqsave(&ata_ratelimit_lock, flags); | ||
4840 | |||
4841 | if (time_after(jiffies, ratelimit_time)) { | ||
4842 | rc = 1; | ||
4843 | ratelimit_time = jiffies + (HZ/5); | ||
4844 | } else | ||
4845 | rc = 0; | ||
4846 | |||
4847 | spin_unlock_irqrestore(&ata_ratelimit_lock, flags); | ||
4848 | |||
4849 | return rc; | ||
4850 | } | ||
4851 | |||
4582 | /* | 4852 | /* |
4583 | * libata is essentially a library of internal helper functions for | 4853 | * libata is essentially a library of internal helper functions for |
4584 | * low-level ATA host controller drivers. As such, the API/ABI is | 4854 | * low-level ATA host controller drivers. As such, the API/ABI is |
@@ -4620,6 +4890,7 @@ EXPORT_SYMBOL_GPL(sata_phy_reset); | |||
4620 | EXPORT_SYMBOL_GPL(__sata_phy_reset); | 4890 | EXPORT_SYMBOL_GPL(__sata_phy_reset); |
4621 | EXPORT_SYMBOL_GPL(ata_bus_reset); | 4891 | EXPORT_SYMBOL_GPL(ata_bus_reset); |
4622 | EXPORT_SYMBOL_GPL(ata_port_disable); | 4892 | EXPORT_SYMBOL_GPL(ata_port_disable); |
4893 | EXPORT_SYMBOL_GPL(ata_ratelimit); | ||
4623 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); | 4894 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); |
4624 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); | 4895 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
4625 | EXPORT_SYMBOL_GPL(ata_scsi_error); | 4896 | EXPORT_SYMBOL_GPL(ata_scsi_error); |
@@ -4631,6 +4902,9 @@ EXPORT_SYMBOL_GPL(ata_dev_id_string); | |||
4631 | EXPORT_SYMBOL_GPL(ata_dev_config); | 4902 | EXPORT_SYMBOL_GPL(ata_dev_config); |
4632 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); | 4903 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); |
4633 | 4904 | ||
4905 | EXPORT_SYMBOL_GPL(ata_timing_compute); | ||
4906 | EXPORT_SYMBOL_GPL(ata_timing_merge); | ||
4907 | |||
4634 | #ifdef CONFIG_PCI | 4908 | #ifdef CONFIG_PCI |
4635 | EXPORT_SYMBOL_GPL(pci_test_config_bits); | 4909 | EXPORT_SYMBOL_GPL(pci_test_config_bits); |
4636 | EXPORT_SYMBOL_GPL(ata_pci_host_stop); | 4910 | EXPORT_SYMBOL_GPL(ata_pci_host_stop); |