diff options
author | Tejun Heo <htejun@gmail.com> | 2007-08-06 05:36:23 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-10-12 14:55:30 -0400 |
commit | f58229f8060055b08b34008ea08f31de1e2f003c (patch) | |
tree | 6ca5ef546671cb975ef3632fb032c238eaf1bb4c /drivers/ata | |
parent | 9af5c9c97dc9d599281778864c72b385f0c63341 (diff) |
libata-link: implement and use link/device iterators
Multiple links and different number of devices per link should be
considered to iterate over links and devices. This patch implements
and uses link and device iterators - ata_port_for_each_link() and
ata_link_for_each_dev() - and ata_link_max_devices().
This change makes a lot of functions iterate over only possible
devices instead of from dev 0 to dev ATA_MAX_DEVICES. All such
changes have been examined and nothing should be broken.
While at it, add a separating comment before device helpers to
distinguish them better from link helpers and others.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata')
-rw-r--r-- | drivers/ata/ata_generic.c | 7 | ||||
-rw-r--r-- | drivers/ata/libata-acpi.c | 6 | ||||
-rw-r--r-- | drivers/ata/libata-core.c | 58 | ||||
-rw-r--r-- | drivers/ata/libata-eh.c | 117 | ||||
-rw-r--r-- | drivers/ata/libata-scsi.c | 26 | ||||
-rw-r--r-- | drivers/ata/pata_it821x.c | 5 | ||||
-rw-r--r-- | drivers/ata/pata_ixp4xx_cf.c | 5 | ||||
-rw-r--r-- | drivers/ata/pata_legacy.c | 5 | ||||
-rw-r--r-- | drivers/ata/pata_pdc2027x.c | 13 | ||||
-rw-r--r-- | drivers/ata/pata_platform.c | 6 | ||||
-rw-r--r-- | drivers/ata/pata_rz1000.c | 5 | ||||
-rw-r--r-- | drivers/ata/sata_sil.c | 12 |
12 files changed, 120 insertions, 145 deletions
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c index b5e390ff5bd..44328a16075 100644 --- a/drivers/ata/ata_generic.c +++ b/drivers/ata/ata_generic.c | |||
@@ -46,21 +46,20 @@ | |||
46 | static int generic_set_mode(struct ata_port *ap, struct ata_device **unused) | 46 | static int generic_set_mode(struct ata_port *ap, struct ata_device **unused) |
47 | { | 47 | { |
48 | int dma_enabled = 0; | 48 | int dma_enabled = 0; |
49 | int i; | 49 | struct ata_device *dev; |
50 | 50 | ||
51 | /* Bits 5 and 6 indicate if DMA is active on master/slave */ | 51 | /* Bits 5 and 6 indicate if DMA is active on master/slave */ |
52 | if (ap->ioaddr.bmdma_addr) | 52 | if (ap->ioaddr.bmdma_addr) |
53 | dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); | 53 | dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); |
54 | 54 | ||
55 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 55 | ata_link_for_each_dev(dev, &ap->link) { |
56 | struct ata_device *dev = &ap->link.device[i]; | ||
57 | if (ata_dev_enabled(dev)) { | 56 | if (ata_dev_enabled(dev)) { |
58 | /* We don't really care */ | 57 | /* We don't really care */ |
59 | dev->pio_mode = XFER_PIO_0; | 58 | dev->pio_mode = XFER_PIO_0; |
60 | dev->dma_mode = XFER_MW_DMA_0; | 59 | dev->dma_mode = XFER_MW_DMA_0; |
61 | /* We do need the right mode information for DMA or PIO | 60 | /* We do need the right mode information for DMA or PIO |
62 | and this comes from the current configuration flags */ | 61 | and this comes from the current configuration flags */ |
63 | if (dma_enabled & (1 << (5 + i))) { | 62 | if (dma_enabled & (1 << (5 + dev->devno))) { |
64 | ata_id_to_dma_mode(dev, XFER_MW_DMA_0); | 63 | ata_id_to_dma_mode(dev, XFER_MW_DMA_0); |
65 | dev->flags &= ~ATA_DFLAG_PIO; | 64 | dev->flags &= ~ATA_DFLAG_PIO; |
66 | } else { | 65 | } else { |
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c index 0023ac4ff49..43af2e06d44 100644 --- a/drivers/ata/libata-acpi.c +++ b/drivers/ata/libata-acpi.c | |||
@@ -509,7 +509,7 @@ int ata_acpi_on_suspend(struct ata_port *ap) | |||
509 | */ | 509 | */ |
510 | void ata_acpi_on_resume(struct ata_port *ap) | 510 | void ata_acpi_on_resume(struct ata_port *ap) |
511 | { | 511 | { |
512 | int i; | 512 | struct ata_device *dev; |
513 | 513 | ||
514 | if (ap->acpi_handle && (ap->pflags & ATA_PFLAG_GTM_VALID)) { | 514 | if (ap->acpi_handle && (ap->pflags & ATA_PFLAG_GTM_VALID)) { |
515 | BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA); | 515 | BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA); |
@@ -519,8 +519,8 @@ void ata_acpi_on_resume(struct ata_port *ap) | |||
519 | } | 519 | } |
520 | 520 | ||
521 | /* schedule _GTF */ | 521 | /* schedule _GTF */ |
522 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 522 | ata_link_for_each_dev(dev, &ap->link) |
523 | ap->link.device[i].flags |= ATA_DFLAG_ACPI_PENDING; | 523 | dev->flags |= ATA_DFLAG_ACPI_PENDING; |
524 | } | 524 | } |
525 | 525 | ||
526 | /** | 526 | /** |
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index dd2de485124..f30c4771b3a 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -2105,21 +2105,19 @@ int ata_bus_probe(struct ata_port *ap) | |||
2105 | { | 2105 | { |
2106 | unsigned int classes[ATA_MAX_DEVICES]; | 2106 | unsigned int classes[ATA_MAX_DEVICES]; |
2107 | int tries[ATA_MAX_DEVICES]; | 2107 | int tries[ATA_MAX_DEVICES]; |
2108 | int i, rc; | 2108 | int rc; |
2109 | struct ata_device *dev; | 2109 | struct ata_device *dev; |
2110 | 2110 | ||
2111 | ata_port_probe(ap); | 2111 | ata_port_probe(ap); |
2112 | 2112 | ||
2113 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 2113 | ata_link_for_each_dev(dev, &ap->link) |
2114 | tries[i] = ATA_PROBE_MAX_TRIES; | 2114 | tries[dev->devno] = ATA_PROBE_MAX_TRIES; |
2115 | 2115 | ||
2116 | retry: | 2116 | retry: |
2117 | /* reset and determine device classes */ | 2117 | /* reset and determine device classes */ |
2118 | ap->ops->phy_reset(ap); | 2118 | ap->ops->phy_reset(ap); |
2119 | 2119 | ||
2120 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2120 | ata_link_for_each_dev(dev, &ap->link) { |
2121 | dev = &ap->link.device[i]; | ||
2122 | |||
2123 | if (!(ap->flags & ATA_FLAG_DISABLED) && | 2121 | if (!(ap->flags & ATA_FLAG_DISABLED) && |
2124 | dev->class != ATA_DEV_UNKNOWN) | 2122 | dev->class != ATA_DEV_UNKNOWN) |
2125 | classes[dev->devno] = dev->class; | 2123 | classes[dev->devno] = dev->class; |
@@ -2134,18 +2132,16 @@ int ata_bus_probe(struct ata_port *ap) | |||
2134 | /* after the reset the device state is PIO 0 and the controller | 2132 | /* after the reset the device state is PIO 0 and the controller |
2135 | state is undefined. Record the mode */ | 2133 | state is undefined. Record the mode */ |
2136 | 2134 | ||
2137 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 2135 | ata_link_for_each_dev(dev, &ap->link) |
2138 | ap->link.device[i].pio_mode = XFER_PIO_0; | 2136 | dev->pio_mode = XFER_PIO_0; |
2139 | 2137 | ||
2140 | /* read IDENTIFY page and configure devices. We have to do the identify | 2138 | /* read IDENTIFY page and configure devices. We have to do the identify |
2141 | specific sequence bass-ackwards so that PDIAG- is released by | 2139 | specific sequence bass-ackwards so that PDIAG- is released by |
2142 | the slave device */ | 2140 | the slave device */ |
2143 | 2141 | ||
2144 | for (i = ATA_MAX_DEVICES - 1; i >= 0; i--) { | 2142 | ata_link_for_each_dev(dev, &ap->link) { |
2145 | dev = &ap->link.device[i]; | 2143 | if (tries[dev->devno]) |
2146 | 2144 | dev->class = classes[dev->devno]; | |
2147 | if (tries[i]) | ||
2148 | dev->class = classes[i]; | ||
2149 | 2145 | ||
2150 | if (!ata_dev_enabled(dev)) | 2146 | if (!ata_dev_enabled(dev)) |
2151 | continue; | 2147 | continue; |
@@ -2163,8 +2159,7 @@ int ata_bus_probe(struct ata_port *ap) | |||
2163 | /* After the identify sequence we can now set up the devices. We do | 2159 | /* After the identify sequence we can now set up the devices. We do |
2164 | this in the normal order so that the user doesn't get confused */ | 2160 | this in the normal order so that the user doesn't get confused */ |
2165 | 2161 | ||
2166 | for(i = 0; i < ATA_MAX_DEVICES; i++) { | 2162 | ata_link_for_each_dev(dev, &ap->link) { |
2167 | dev = &ap->link.device[i]; | ||
2168 | if (!ata_dev_enabled(dev)) | 2163 | if (!ata_dev_enabled(dev)) |
2169 | continue; | 2164 | continue; |
2170 | 2165 | ||
@@ -2180,8 +2175,8 @@ int ata_bus_probe(struct ata_port *ap) | |||
2180 | if (rc) | 2175 | if (rc) |
2181 | goto fail; | 2176 | goto fail; |
2182 | 2177 | ||
2183 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 2178 | ata_link_for_each_dev(dev, &ap->link) |
2184 | if (ata_dev_enabled(&ap->link.device[i])) | 2179 | if (ata_dev_enabled(dev)) |
2185 | return 0; | 2180 | return 0; |
2186 | 2181 | ||
2187 | /* no device present, disable port */ | 2182 | /* no device present, disable port */ |
@@ -2803,16 +2798,14 @@ static int ata_dev_set_mode(struct ata_device *dev) | |||
2803 | 2798 | ||
2804 | int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev) | 2799 | int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev) |
2805 | { | 2800 | { |
2801 | struct ata_link *link = &ap->link; | ||
2806 | struct ata_device *dev; | 2802 | struct ata_device *dev; |
2807 | int i, rc = 0, used_dma = 0, found = 0; | 2803 | int rc = 0, used_dma = 0, found = 0; |
2808 | |||
2809 | 2804 | ||
2810 | /* step 1: calculate xfer_mask */ | 2805 | /* step 1: calculate xfer_mask */ |
2811 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2806 | ata_link_for_each_dev(dev, link) { |
2812 | unsigned int pio_mask, dma_mask; | 2807 | unsigned int pio_mask, dma_mask; |
2813 | 2808 | ||
2814 | dev = &ap->link.device[i]; | ||
2815 | |||
2816 | if (!ata_dev_enabled(dev)) | 2809 | if (!ata_dev_enabled(dev)) |
2817 | continue; | 2810 | continue; |
2818 | 2811 | ||
@@ -2831,8 +2824,7 @@ int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev) | |||
2831 | goto out; | 2824 | goto out; |
2832 | 2825 | ||
2833 | /* step 2: always set host PIO timings */ | 2826 | /* step 2: always set host PIO timings */ |
2834 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2827 | ata_link_for_each_dev(dev, link) { |
2835 | dev = &ap->link.device[i]; | ||
2836 | if (!ata_dev_enabled(dev)) | 2828 | if (!ata_dev_enabled(dev)) |
2837 | continue; | 2829 | continue; |
2838 | 2830 | ||
@@ -2849,9 +2841,7 @@ int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev) | |||
2849 | } | 2841 | } |
2850 | 2842 | ||
2851 | /* step 3: set host DMA timings */ | 2843 | /* step 3: set host DMA timings */ |
2852 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2844 | ata_link_for_each_dev(dev, link) { |
2853 | dev = &ap->link.device[i]; | ||
2854 | |||
2855 | if (!ata_dev_enabled(dev) || !dev->dma_mode) | 2845 | if (!ata_dev_enabled(dev) || !dev->dma_mode) |
2856 | continue; | 2846 | continue; |
2857 | 2847 | ||
@@ -2862,9 +2852,7 @@ int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev) | |||
2862 | } | 2852 | } |
2863 | 2853 | ||
2864 | /* step 4: update devices' xfer mode */ | 2854 | /* step 4: update devices' xfer mode */ |
2865 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2855 | ata_link_for_each_dev(dev, link) { |
2866 | dev = &ap->link.device[i]; | ||
2867 | |||
2868 | /* don't update suspended devices' xfer mode */ | 2856 | /* don't update suspended devices' xfer mode */ |
2869 | if (!ata_dev_enabled(dev)) | 2857 | if (!ata_dev_enabled(dev)) |
2870 | continue; | 2858 | continue; |
@@ -6113,6 +6101,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host) | |||
6113 | 6101 | ||
6114 | ap->link.ap = ap; | 6102 | ap->link.ap = ap; |
6115 | 6103 | ||
6104 | /* can't use iterator, ap isn't initialized yet */ | ||
6116 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 6105 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
6117 | struct ata_device *dev = &ap->link.device[i]; | 6106 | struct ata_device *dev = &ap->link.device[i]; |
6118 | dev->link = &ap->link; | 6107 | dev->link = &ap->link; |
@@ -6453,7 +6442,8 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht) | |||
6453 | /* kick EH for boot probing */ | 6442 | /* kick EH for boot probing */ |
6454 | spin_lock_irqsave(ap->lock, flags); | 6443 | spin_lock_irqsave(ap->lock, flags); |
6455 | 6444 | ||
6456 | ehi->probe_mask = (1 << ATA_MAX_DEVICES) - 1; | 6445 | ehi->probe_mask = |
6446 | (1 << ata_link_max_devices(&ap->link)) - 1; | ||
6457 | ehi->action |= ATA_EH_SOFTRESET; | 6447 | ehi->action |= ATA_EH_SOFTRESET; |
6458 | ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; | 6448 | ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; |
6459 | 6449 | ||
@@ -6551,7 +6541,7 @@ int ata_host_activate(struct ata_host *host, int irq, | |||
6551 | void ata_port_detach(struct ata_port *ap) | 6541 | void ata_port_detach(struct ata_port *ap) |
6552 | { | 6542 | { |
6553 | unsigned long flags; | 6543 | unsigned long flags; |
6554 | int i; | 6544 | struct ata_device *dev; |
6555 | 6545 | ||
6556 | if (!ap->ops->error_handler) | 6546 | if (!ap->ops->error_handler) |
6557 | goto skip_eh; | 6547 | goto skip_eh; |
@@ -6568,8 +6558,8 @@ void ata_port_detach(struct ata_port *ap) | |||
6568 | */ | 6558 | */ |
6569 | spin_lock_irqsave(ap->lock, flags); | 6559 | spin_lock_irqsave(ap->lock, flags); |
6570 | 6560 | ||
6571 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 6561 | ata_link_for_each_dev(dev, &ap->link) |
6572 | ata_dev_disable(&ap->link.device[i]); | 6562 | ata_dev_disable(dev); |
6573 | 6563 | ||
6574 | spin_unlock_irqrestore(ap->lock, flags); | 6564 | spin_unlock_irqrestore(ap->lock, flags); |
6575 | 6565 | ||
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index e2681f56ed4..8c37ec0bbf6 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c | |||
@@ -200,23 +200,24 @@ static unsigned int ata_eh_dev_action(struct ata_device *dev) | |||
200 | return ehc->i.action | ehc->i.dev_action[dev->devno]; | 200 | return ehc->i.action | ehc->i.dev_action[dev->devno]; |
201 | } | 201 | } |
202 | 202 | ||
203 | static void ata_eh_clear_action(struct ata_device *dev, | 203 | static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev, |
204 | struct ata_eh_info *ehi, unsigned int action) | 204 | struct ata_eh_info *ehi, unsigned int action) |
205 | { | 205 | { |
206 | int i; | 206 | struct ata_device *tdev; |
207 | 207 | ||
208 | if (!dev) { | 208 | if (!dev) { |
209 | ehi->action &= ~action; | 209 | ehi->action &= ~action; |
210 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 210 | ata_link_for_each_dev(tdev, link) |
211 | ehi->dev_action[i] &= ~action; | 211 | ehi->dev_action[tdev->devno] &= ~action; |
212 | } else { | 212 | } else { |
213 | /* doesn't make sense for port-wide EH actions */ | 213 | /* doesn't make sense for port-wide EH actions */ |
214 | WARN_ON(!(action & ATA_EH_PERDEV_MASK)); | 214 | WARN_ON(!(action & ATA_EH_PERDEV_MASK)); |
215 | 215 | ||
216 | /* break ehi->action into ehi->dev_action */ | 216 | /* break ehi->action into ehi->dev_action */ |
217 | if (ehi->action & action) { | 217 | if (ehi->action & action) { |
218 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 218 | ata_link_for_each_dev(tdev, link) |
219 | ehi->dev_action[i] |= ehi->action & action; | 219 | ehi->dev_action[tdev->devno] |= |
220 | ehi->action & action; | ||
220 | ehi->action &= ~action; | 221 | ehi->action &= ~action; |
221 | } | 222 | } |
222 | 223 | ||
@@ -922,7 +923,8 @@ void ata_eh_qc_retry(struct ata_queued_cmd *qc) | |||
922 | */ | 923 | */ |
923 | static void ata_eh_detach_dev(struct ata_device *dev) | 924 | static void ata_eh_detach_dev(struct ata_device *dev) |
924 | { | 925 | { |
925 | struct ata_port *ap = dev->link->ap; | 926 | struct ata_link *link = dev->link; |
927 | struct ata_port *ap = link->ap; | ||
926 | unsigned long flags; | 928 | unsigned long flags; |
927 | 929 | ||
928 | ata_dev_disable(dev); | 930 | ata_dev_disable(dev); |
@@ -937,8 +939,8 @@ static void ata_eh_detach_dev(struct ata_device *dev) | |||
937 | } | 939 | } |
938 | 940 | ||
939 | /* clear per-dev EH actions */ | 941 | /* clear per-dev EH actions */ |
940 | ata_eh_clear_action(dev, &dev->link->eh_info, ATA_EH_PERDEV_MASK); | 942 | ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK); |
941 | ata_eh_clear_action(dev, &dev->link->eh_context.i, ATA_EH_PERDEV_MASK); | 943 | ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK); |
942 | 944 | ||
943 | spin_unlock_irqrestore(ap->lock, flags); | 945 | spin_unlock_irqrestore(ap->lock, flags); |
944 | } | 946 | } |
@@ -978,7 +980,7 @@ static void ata_eh_about_to_do(struct ata_port *ap, struct ata_device *dev, | |||
978 | ehi->flags &= ~ATA_EHI_RESET_MODIFIER_MASK; | 980 | ehi->flags &= ~ATA_EHI_RESET_MODIFIER_MASK; |
979 | } | 981 | } |
980 | 982 | ||
981 | ata_eh_clear_action(dev, ehi, action); | 983 | ata_eh_clear_action(&ap->link, dev, ehi, action); |
982 | 984 | ||
983 | if (!(ehc->i.flags & ATA_EHI_QUIET)) | 985 | if (!(ehc->i.flags & ATA_EHI_QUIET)) |
984 | ap->pflags |= ATA_PFLAG_RECOVERED; | 986 | ap->pflags |= ATA_PFLAG_RECOVERED; |
@@ -1009,7 +1011,7 @@ static void ata_eh_done(struct ata_port *ap, struct ata_device *dev, | |||
1009 | ehc->i.flags &= ~ATA_EHI_RESET_MODIFIER_MASK; | 1011 | ehc->i.flags &= ~ATA_EHI_RESET_MODIFIER_MASK; |
1010 | } | 1012 | } |
1011 | 1013 | ||
1012 | ata_eh_clear_action(dev, &ehc->i, action); | 1014 | ata_eh_clear_action(&ap->link, dev, &ehc->i, action); |
1013 | } | 1015 | } |
1014 | 1016 | ||
1015 | /** | 1017 | /** |
@@ -1736,10 +1738,11 @@ static void ata_eh_report(struct ata_port *ap) | |||
1736 | static int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset, | 1738 | static int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset, |
1737 | unsigned int *classes, unsigned long deadline) | 1739 | unsigned int *classes, unsigned long deadline) |
1738 | { | 1740 | { |
1739 | int i, rc; | 1741 | struct ata_device *dev; |
1742 | int rc; | ||
1740 | 1743 | ||
1741 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1744 | ata_link_for_each_dev(dev, &ap->link) |
1742 | classes[i] = ATA_DEV_UNKNOWN; | 1745 | classes[dev->devno] = ATA_DEV_UNKNOWN; |
1743 | 1746 | ||
1744 | rc = reset(ap, classes, deadline); | 1747 | rc = reset(ap, classes, deadline); |
1745 | if (rc) | 1748 | if (rc) |
@@ -1749,14 +1752,16 @@ static int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset, | |||
1749 | * is complete and convert all ATA_DEV_UNKNOWN to | 1752 | * is complete and convert all ATA_DEV_UNKNOWN to |
1750 | * ATA_DEV_NONE. | 1753 | * ATA_DEV_NONE. |
1751 | */ | 1754 | */ |
1752 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1755 | ata_link_for_each_dev(dev, &ap->link) |
1753 | if (classes[i] != ATA_DEV_UNKNOWN) | 1756 | if (classes[dev->devno] != ATA_DEV_UNKNOWN) |
1754 | break; | 1757 | break; |
1755 | 1758 | ||
1756 | if (i < ATA_MAX_DEVICES) | 1759 | if (dev) { |
1757 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1760 | ata_link_for_each_dev(dev, &ap->link) { |
1758 | if (classes[i] == ATA_DEV_UNKNOWN) | 1761 | if (classes[dev->devno] == ATA_DEV_UNKNOWN) |
1759 | classes[i] = ATA_DEV_NONE; | 1762 | classes[dev->devno] = ATA_DEV_NONE; |
1763 | } | ||
1764 | } | ||
1760 | 1765 | ||
1761 | return 0; | 1766 | return 0; |
1762 | } | 1767 | } |
@@ -1781,10 +1786,11 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1781 | unsigned int *classes = ehc->classes; | 1786 | unsigned int *classes = ehc->classes; |
1782 | int verbose = !(ehc->i.flags & ATA_EHI_QUIET); | 1787 | int verbose = !(ehc->i.flags & ATA_EHI_QUIET); |
1783 | int try = 0; | 1788 | int try = 0; |
1789 | struct ata_device *dev; | ||
1784 | unsigned long deadline; | 1790 | unsigned long deadline; |
1785 | unsigned int action; | 1791 | unsigned int action; |
1786 | ata_reset_fn_t reset; | 1792 | ata_reset_fn_t reset; |
1787 | int i, rc; | 1793 | int rc; |
1788 | 1794 | ||
1789 | /* about to reset */ | 1795 | /* about to reset */ |
1790 | ata_eh_about_to_do(ap, NULL, ehc->i.action & ATA_EH_RESET_MASK); | 1796 | ata_eh_about_to_do(ap, NULL, ehc->i.action & ATA_EH_RESET_MASK); |
@@ -1808,8 +1814,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1808 | "port disabled. ignoring.\n"); | 1814 | "port disabled. ignoring.\n"); |
1809 | ehc->i.action &= ~ATA_EH_RESET_MASK; | 1815 | ehc->i.action &= ~ATA_EH_RESET_MASK; |
1810 | 1816 | ||
1811 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1817 | ata_link_for_each_dev(dev, &ap->link) |
1812 | classes[i] = ATA_DEV_NONE; | 1818 | classes[dev->devno] = ATA_DEV_NONE; |
1813 | 1819 | ||
1814 | rc = 0; | 1820 | rc = 0; |
1815 | } else | 1821 | } else |
@@ -1826,8 +1832,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1826 | reset = softreset; | 1832 | reset = softreset; |
1827 | else { | 1833 | else { |
1828 | /* prereset told us not to reset, bang classes and return */ | 1834 | /* prereset told us not to reset, bang classes and return */ |
1829 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1835 | ata_link_for_each_dev(dev, &ap->link) |
1830 | classes[i] = ATA_DEV_NONE; | 1836 | classes[dev->devno] = ATA_DEV_NONE; |
1831 | rc = 0; | 1837 | rc = 0; |
1832 | goto out; | 1838 | goto out; |
1833 | } | 1839 | } |
@@ -1908,8 +1914,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1908 | /* After the reset, the device state is PIO 0 and the | 1914 | /* After the reset, the device state is PIO 0 and the |
1909 | * controller state is undefined. Record the mode. | 1915 | * controller state is undefined. Record the mode. |
1910 | */ | 1916 | */ |
1911 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1917 | ata_link_for_each_dev(dev, &ap->link) |
1912 | ap->link.device[i].pio_mode = XFER_PIO_0; | 1918 | dev->pio_mode = XFER_PIO_0; |
1913 | 1919 | ||
1914 | /* record current link speed */ | 1920 | /* record current link speed */ |
1915 | if (sata_scr_read(ap, SCR_STATUS, &sstatus) == 0) | 1921 | if (sata_scr_read(ap, SCR_STATUS, &sstatus) == 0) |
@@ -1935,7 +1941,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap, | |||
1935 | struct ata_device *dev; | 1941 | struct ata_device *dev; |
1936 | unsigned int new_mask = 0; | 1942 | unsigned int new_mask = 0; |
1937 | unsigned long flags; | 1943 | unsigned long flags; |
1938 | int i, rc = 0; | 1944 | int rc = 0; |
1939 | 1945 | ||
1940 | DPRINTK("ENTER\n"); | 1946 | DPRINTK("ENTER\n"); |
1941 | 1947 | ||
@@ -1943,11 +1949,9 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap, | |||
1943 | * be done backwards such that PDIAG- is released by the slave | 1949 | * be done backwards such that PDIAG- is released by the slave |
1944 | * device before the master device is identified. | 1950 | * device before the master device is identified. |
1945 | */ | 1951 | */ |
1946 | for (i = ATA_MAX_DEVICES - 1; i >= 0; i--) { | 1952 | ata_link_for_each_dev_reverse(dev, &ap->link) { |
1947 | unsigned int action, readid_flags = 0; | 1953 | unsigned int action = ata_eh_dev_action(dev); |
1948 | 1954 | unsigned int readid_flags = 0; | |
1949 | dev = &ap->link.device[i]; | ||
1950 | action = ata_eh_dev_action(dev); | ||
1951 | 1955 | ||
1952 | if (ehc->i.flags & ATA_EHI_DID_RESET) | 1956 | if (ehc->i.flags & ATA_EHI_DID_RESET) |
1953 | readid_flags |= ATA_READID_POSTRESET; | 1957 | readid_flags |= ATA_READID_POSTRESET; |
@@ -1981,7 +1985,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap, | |||
1981 | dev->id); | 1985 | dev->id); |
1982 | switch (rc) { | 1986 | switch (rc) { |
1983 | case 0: | 1987 | case 0: |
1984 | new_mask |= 1 << i; | 1988 | new_mask |= 1 << dev->devno; |
1985 | break; | 1989 | break; |
1986 | case -ENOENT: | 1990 | case -ENOENT: |
1987 | /* IDENTIFY was issued to non-existent | 1991 | /* IDENTIFY was issued to non-existent |
@@ -2005,10 +2009,8 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap, | |||
2005 | /* Configure new devices forward such that user doesn't see | 2009 | /* Configure new devices forward such that user doesn't see |
2006 | * device detection messages backwards. | 2010 | * device detection messages backwards. |
2007 | */ | 2011 | */ |
2008 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2012 | ata_link_for_each_dev(dev, &ap->link) { |
2009 | dev = &ap->link.device[i]; | 2013 | if (!(new_mask & (1 << dev->devno))) |
2010 | |||
2011 | if (!(new_mask & (1 << i))) | ||
2012 | continue; | 2014 | continue; |
2013 | 2015 | ||
2014 | ehc->i.flags |= ATA_EHI_PRINTINFO; | 2016 | ehc->i.flags |= ATA_EHI_PRINTINFO; |
@@ -2035,20 +2037,22 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap, | |||
2035 | 2037 | ||
2036 | static int ata_port_nr_enabled(struct ata_port *ap) | 2038 | static int ata_port_nr_enabled(struct ata_port *ap) |
2037 | { | 2039 | { |
2038 | int i, cnt = 0; | 2040 | struct ata_device *dev; |
2041 | int cnt = 0; | ||
2039 | 2042 | ||
2040 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 2043 | ata_link_for_each_dev(dev, &ap->link) |
2041 | if (ata_dev_enabled(&ap->link.device[i])) | 2044 | if (ata_dev_enabled(dev)) |
2042 | cnt++; | 2045 | cnt++; |
2043 | return cnt; | 2046 | return cnt; |
2044 | } | 2047 | } |
2045 | 2048 | ||
2046 | static int ata_port_nr_vacant(struct ata_port *ap) | 2049 | static int ata_port_nr_vacant(struct ata_port *ap) |
2047 | { | 2050 | { |
2048 | int i, cnt = 0; | 2051 | struct ata_device *dev; |
2052 | int cnt = 0; | ||
2049 | 2053 | ||
2050 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 2054 | ata_link_for_each_dev(dev, &ap->link) |
2051 | if (ap->link.device[i].class == ATA_DEV_UNKNOWN) | 2055 | if (dev->class == ATA_DEV_UNKNOWN) |
2052 | cnt++; | 2056 | cnt++; |
2053 | return cnt; | 2057 | return cnt; |
2054 | } | 2058 | } |
@@ -2056,7 +2060,7 @@ static int ata_port_nr_vacant(struct ata_port *ap) | |||
2056 | static int ata_eh_skip_recovery(struct ata_port *ap) | 2060 | static int ata_eh_skip_recovery(struct ata_port *ap) |
2057 | { | 2061 | { |
2058 | struct ata_eh_context *ehc = &ap->link.eh_context; | 2062 | struct ata_eh_context *ehc = &ap->link.eh_context; |
2059 | int i; | 2063 | struct ata_device *dev; |
2060 | 2064 | ||
2061 | /* thaw frozen port, resume link and recover failed devices */ | 2065 | /* thaw frozen port, resume link and recover failed devices */ |
2062 | if ((ap->pflags & ATA_PFLAG_FROZEN) || | 2066 | if ((ap->pflags & ATA_PFLAG_FROZEN) || |
@@ -2064,9 +2068,7 @@ static int ata_eh_skip_recovery(struct ata_port *ap) | |||
2064 | return 0; | 2068 | return 0; |
2065 | 2069 | ||
2066 | /* skip if class codes for all vacant slots are ATA_DEV_NONE */ | 2070 | /* skip if class codes for all vacant slots are ATA_DEV_NONE */ |
2067 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2071 | ata_link_for_each_dev(dev, &ap->link) { |
2068 | struct ata_device *dev = &ap->link.device[i]; | ||
2069 | |||
2070 | if (dev->class == ATA_DEV_UNKNOWN && | 2072 | if (dev->class == ATA_DEV_UNKNOWN && |
2071 | ehc->classes[dev->devno] != ATA_DEV_NONE) | 2073 | ehc->classes[dev->devno] != ATA_DEV_NONE) |
2072 | return 0; | 2074 | return 0; |
@@ -2153,19 +2155,18 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
2153 | { | 2155 | { |
2154 | struct ata_eh_context *ehc = &ap->link.eh_context; | 2156 | struct ata_eh_context *ehc = &ap->link.eh_context; |
2155 | struct ata_device *dev; | 2157 | struct ata_device *dev; |
2156 | int i, rc; | 2158 | int rc; |
2157 | 2159 | ||
2158 | DPRINTK("ENTER\n"); | 2160 | DPRINTK("ENTER\n"); |
2159 | 2161 | ||
2160 | /* prep for recovery */ | 2162 | /* prep for recovery */ |
2161 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2163 | ata_link_for_each_dev(dev, &ap->link) { |
2162 | dev = &ap->link.device[i]; | ||
2163 | |||
2164 | ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; | 2164 | ehc->tries[dev->devno] = ATA_EH_DEV_TRIES; |
2165 | 2165 | ||
2166 | /* collect port action mask recorded in dev actions */ | 2166 | /* collect port action mask recorded in dev actions */ |
2167 | ehc->i.action |= ehc->i.dev_action[i] & ~ATA_EH_PERDEV_MASK; | 2167 | ehc->i.action |= |
2168 | ehc->i.dev_action[i] &= ATA_EH_PERDEV_MASK; | 2168 | ehc->i.dev_action[dev->devno] & ~ATA_EH_PERDEV_MASK; |
2169 | ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK; | ||
2169 | 2170 | ||
2170 | /* process hotplug request */ | 2171 | /* process hotplug request */ |
2171 | if (dev->flags & ATA_DFLAG_DETACH) | 2172 | if (dev->flags & ATA_DFLAG_DETACH) |
@@ -2192,8 +2193,8 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
2192 | if (ata_eh_skip_recovery(ap)) | 2193 | if (ata_eh_skip_recovery(ap)) |
2193 | ehc->i.action = 0; | 2194 | ehc->i.action = 0; |
2194 | 2195 | ||
2195 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 2196 | ata_link_for_each_dev(dev, &ap->link) |
2196 | ehc->classes[i] = ATA_DEV_UNKNOWN; | 2197 | ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; |
2197 | 2198 | ||
2198 | /* reset */ | 2199 | /* reset */ |
2199 | if (ehc->i.action & ATA_EH_RESET_MASK) { | 2200 | if (ehc->i.action & ATA_EH_RESET_MASK) { |
@@ -2241,8 +2242,8 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset, | |||
2241 | 2242 | ||
2242 | out: | 2243 | out: |
2243 | if (rc) { | 2244 | if (rc) { |
2244 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 2245 | ata_link_for_each_dev(dev, &ap->link); |
2245 | ata_dev_disable(&ap->link.device[i]); | 2246 | ata_dev_disable(dev); |
2246 | } | 2247 | } |
2247 | 2248 | ||
2248 | DPRINTK("EXIT, rc=%d\n", rc); | 2249 | DPRINTK("EXIT, rc=%d\n", rc); |
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index ec0e2638200..3d6d5f73799 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -2425,7 +2425,7 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) | |||
2425 | 2425 | ||
2426 | static struct ata_device * ata_find_dev(struct ata_port *ap, int id) | 2426 | static struct ata_device * ata_find_dev(struct ata_port *ap, int id) |
2427 | { | 2427 | { |
2428 | if (likely(id < ATA_MAX_DEVICES)) | 2428 | if (likely(id < ata_link_max_devices(&ap->link))) |
2429 | return &ap->link.device[id]; | 2429 | return &ap->link.device[id]; |
2430 | return NULL; | 2430 | return NULL; |
2431 | } | 2431 | } |
@@ -2952,21 +2952,18 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync) | |||
2952 | int tries = 5; | 2952 | int tries = 5; |
2953 | struct ata_device *last_failed_dev = NULL; | 2953 | struct ata_device *last_failed_dev = NULL; |
2954 | struct ata_device *dev; | 2954 | struct ata_device *dev; |
2955 | unsigned int i; | ||
2956 | 2955 | ||
2957 | if (ap->flags & ATA_FLAG_DISABLED) | 2956 | if (ap->flags & ATA_FLAG_DISABLED) |
2958 | return; | 2957 | return; |
2959 | 2958 | ||
2960 | repeat: | 2959 | repeat: |
2961 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2960 | ata_link_for_each_dev(dev, &ap->link) { |
2962 | struct scsi_device *sdev; | 2961 | struct scsi_device *sdev; |
2963 | 2962 | ||
2964 | dev = &ap->link.device[i]; | ||
2965 | |||
2966 | if (!ata_dev_enabled(dev) || dev->sdev) | 2963 | if (!ata_dev_enabled(dev) || dev->sdev) |
2967 | continue; | 2964 | continue; |
2968 | 2965 | ||
2969 | sdev = __scsi_add_device(ap->scsi_host, 0, i, 0, NULL); | 2966 | sdev = __scsi_add_device(ap->scsi_host, 0, dev->devno, 0, NULL); |
2970 | if (!IS_ERR(sdev)) { | 2967 | if (!IS_ERR(sdev)) { |
2971 | dev->sdev = sdev; | 2968 | dev->sdev = sdev; |
2972 | scsi_device_put(sdev); | 2969 | scsi_device_put(sdev); |
@@ -2977,12 +2974,11 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync) | |||
2977 | * failure occurred, scan would have failed silently. Check | 2974 | * failure occurred, scan would have failed silently. Check |
2978 | * whether all devices are attached. | 2975 | * whether all devices are attached. |
2979 | */ | 2976 | */ |
2980 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2977 | ata_link_for_each_dev(dev, &ap->link) { |
2981 | dev = &ap->link.device[i]; | ||
2982 | if (ata_dev_enabled(dev) && !dev->sdev) | 2978 | if (ata_dev_enabled(dev) && !dev->sdev) |
2983 | break; | 2979 | break; |
2984 | } | 2980 | } |
2985 | if (i == ATA_MAX_DEVICES) | 2981 | if (!dev) |
2986 | return; | 2982 | return; |
2987 | 2983 | ||
2988 | /* we're missing some SCSI devices */ | 2984 | /* we're missing some SCSI devices */ |
@@ -3112,7 +3108,7 @@ void ata_scsi_hotplug(struct work_struct *work) | |||
3112 | { | 3108 | { |
3113 | struct ata_port *ap = | 3109 | struct ata_port *ap = |
3114 | container_of(work, struct ata_port, hotplug_task.work); | 3110 | container_of(work, struct ata_port, hotplug_task.work); |
3115 | int i; | 3111 | struct ata_device *dev; |
3116 | 3112 | ||
3117 | if (ap->pflags & ATA_PFLAG_UNLOADING) { | 3113 | if (ap->pflags & ATA_PFLAG_UNLOADING) { |
3118 | DPRINTK("ENTER/EXIT - unloading\n"); | 3114 | DPRINTK("ENTER/EXIT - unloading\n"); |
@@ -3122,8 +3118,7 @@ void ata_scsi_hotplug(struct work_struct *work) | |||
3122 | DPRINTK("ENTER\n"); | 3118 | DPRINTK("ENTER\n"); |
3123 | 3119 | ||
3124 | /* unplug detached devices */ | 3120 | /* unplug detached devices */ |
3125 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 3121 | ata_link_for_each_dev(dev, &ap->link) { |
3126 | struct ata_device *dev = &ap->link.device[i]; | ||
3127 | unsigned long flags; | 3122 | unsigned long flags; |
3128 | 3123 | ||
3129 | if (!(dev->flags & ATA_DFLAG_DETACHED)) | 3124 | if (!(dev->flags & ATA_DFLAG_DETACHED)) |
@@ -3176,7 +3171,7 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, | |||
3176 | spin_lock_irqsave(ap->lock, flags); | 3171 | spin_lock_irqsave(ap->lock, flags); |
3177 | 3172 | ||
3178 | if (id == SCAN_WILD_CARD) { | 3173 | if (id == SCAN_WILD_CARD) { |
3179 | ehi->probe_mask |= (1 << ATA_MAX_DEVICES) - 1; | 3174 | ehi->probe_mask |= (1 << ata_link_max_devices(&ap->link)) - 1; |
3180 | ehi->action |= ATA_EH_SOFTRESET; | 3175 | ehi->action |= ATA_EH_SOFTRESET; |
3181 | } else { | 3176 | } else { |
3182 | struct ata_device *dev = ata_find_dev(ap, id); | 3177 | struct ata_device *dev = ata_find_dev(ap, id); |
@@ -3215,13 +3210,12 @@ void ata_scsi_dev_rescan(struct work_struct *work) | |||
3215 | { | 3210 | { |
3216 | struct ata_port *ap = | 3211 | struct ata_port *ap = |
3217 | container_of(work, struct ata_port, scsi_rescan_task); | 3212 | container_of(work, struct ata_port, scsi_rescan_task); |
3213 | struct ata_device *dev; | ||
3218 | unsigned long flags; | 3214 | unsigned long flags; |
3219 | unsigned int i; | ||
3220 | 3215 | ||
3221 | spin_lock_irqsave(ap->lock, flags); | 3216 | spin_lock_irqsave(ap->lock, flags); |
3222 | 3217 | ||
3223 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 3218 | ata_link_for_each_dev(dev, &ap->link) { |
3224 | struct ata_device *dev = &ap->link.device[i]; | ||
3225 | struct scsi_device *sdev = dev->sdev; | 3219 | struct scsi_device *sdev = dev->sdev; |
3226 | 3220 | ||
3227 | if (!ata_dev_enabled(dev) || !sdev) | 3221 | if (!ata_dev_enabled(dev) || !sdev) |
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c index ece1a28f0a4..088eb1d2376 100644 --- a/drivers/ata/pata_it821x.c +++ b/drivers/ata/pata_it821x.c | |||
@@ -461,10 +461,9 @@ static unsigned int it821x_passthru_qc_issue_prot(struct ata_queued_cmd *qc) | |||
461 | 461 | ||
462 | static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused) | 462 | static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused) |
463 | { | 463 | { |
464 | int i; | 464 | struct ata_device *dev; |
465 | 465 | ||
466 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 466 | ata_link_for_each_dev(dev, &ap->link) { |
467 | struct ata_device *dev = &ap->link.device[i]; | ||
468 | if (ata_dev_enabled(dev)) { | 467 | if (ata_dev_enabled(dev)) { |
469 | /* We don't really care */ | 468 | /* We don't really care */ |
470 | dev->pio_mode = XFER_PIO_0; | 469 | dev->pio_mode = XFER_PIO_0; |
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c index 3e2b8ce5fa3..7db315a9baa 100644 --- a/drivers/ata/pata_ixp4xx_cf.c +++ b/drivers/ata/pata_ixp4xx_cf.c | |||
@@ -28,10 +28,9 @@ | |||
28 | 28 | ||
29 | static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device **error) | 29 | static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device **error) |
30 | { | 30 | { |
31 | int i; | 31 | struct ata_device *dev; |
32 | 32 | ||
33 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 33 | ata_link_for_each_dev(dev, &ap->link) { |
34 | struct ata_device *dev = &ap->link.device[i]; | ||
35 | if (ata_dev_enabled(dev)) { | 34 | if (ata_dev_enabled(dev)) { |
36 | ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n"); | 35 | ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n"); |
37 | dev->pio_mode = XFER_PIO_0; | 36 | dev->pio_mode = XFER_PIO_0; |
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c index 4bcc0ae8d10..9d92843b033 100644 --- a/drivers/ata/pata_legacy.c +++ b/drivers/ata/pata_legacy.c | |||
@@ -109,10 +109,9 @@ static int iordy_mask = 0xFFFFFFFF; /* Use iordy if available */ | |||
109 | 109 | ||
110 | static int legacy_set_mode(struct ata_port *ap, struct ata_device **unused) | 110 | static int legacy_set_mode(struct ata_port *ap, struct ata_device **unused) |
111 | { | 111 | { |
112 | int i; | 112 | struct ata_device *dev; |
113 | 113 | ||
114 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 114 | ata_link_for_each_dev(dev, &ap->link) { |
115 | struct ata_device *dev = &ap->link.device[i]; | ||
116 | if (ata_dev_enabled(dev)) { | 115 | if (ata_dev_enabled(dev)) { |
117 | ata_dev_printk(dev, KERN_INFO, "configured for PIO\n"); | 116 | ata_dev_printk(dev, KERN_INFO, "configured for PIO\n"); |
118 | dev->pio_mode = XFER_PIO_0; | 117 | dev->pio_mode = XFER_PIO_0; |
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c index fa780509a1d..83c90cabc7f 100644 --- a/drivers/ata/pata_pdc2027x.c +++ b/drivers/ata/pata_pdc2027x.c | |||
@@ -479,15 +479,14 @@ static void pdc2027x_set_dmamode(struct ata_port *ap, struct ata_device *adev) | |||
479 | */ | 479 | */ |
480 | static int pdc2027x_set_mode(struct ata_port *ap, struct ata_device **r_failed) | 480 | static int pdc2027x_set_mode(struct ata_port *ap, struct ata_device **r_failed) |
481 | { | 481 | { |
482 | int i; | 482 | struct ata_device *dev; |
483 | 483 | int rc; | |
484 | i = ata_do_set_mode(ap, r_failed); | ||
485 | if (i < 0) | ||
486 | return i; | ||
487 | 484 | ||
488 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 485 | rc = ata_do_set_mode(ap, r_failed); |
489 | struct ata_device *dev = &ap->link.device[i]; | 486 | if (rc < 0) |
487 | return rc; | ||
490 | 488 | ||
489 | ata_link_for_each_dev(dev, &ap->link) { | ||
491 | if (ata_dev_enabled(dev)) { | 490 | if (ata_dev_enabled(dev)) { |
492 | 491 | ||
493 | pdc2027x_set_piomode(ap, dev); | 492 | pdc2027x_set_piomode(ap, dev); |
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c index e89656bffa8..ee1605bfc29 100644 --- a/drivers/ata/pata_platform.c +++ b/drivers/ata/pata_platform.c | |||
@@ -32,11 +32,9 @@ static int pio_mask = 1; | |||
32 | */ | 32 | */ |
33 | static int pata_platform_set_mode(struct ata_port *ap, struct ata_device **unused) | 33 | static int pata_platform_set_mode(struct ata_port *ap, struct ata_device **unused) |
34 | { | 34 | { |
35 | int i; | 35 | struct ata_device *dev; |
36 | |||
37 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | ||
38 | struct ata_device *dev = &ap->link.device[i]; | ||
39 | 36 | ||
37 | ata_link_for_each_dev(dev, &ap->link) { | ||
40 | if (ata_dev_enabled(dev)) { | 38 | if (ata_dev_enabled(dev)) { |
41 | /* We don't really care */ | 39 | /* We don't really care */ |
42 | dev->pio_mode = dev->xfer_mode = XFER_PIO_0; | 40 | dev->pio_mode = dev->xfer_mode = XFER_PIO_0; |
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c index 57363c0ce06..300b3d5de81 100644 --- a/drivers/ata/pata_rz1000.c +++ b/drivers/ata/pata_rz1000.c | |||
@@ -36,10 +36,9 @@ | |||
36 | 36 | ||
37 | static int rz1000_set_mode(struct ata_port *ap, struct ata_device **unused) | 37 | static int rz1000_set_mode(struct ata_port *ap, struct ata_device **unused) |
38 | { | 38 | { |
39 | int i; | 39 | struct ata_device *dev; |
40 | 40 | ||
41 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 41 | ata_link_for_each_dev(dev, &ap->link) { |
42 | struct ata_device *dev = &ap->link.device[i]; | ||
43 | if (ata_dev_enabled(dev)) { | 42 | if (ata_dev_enabled(dev)) { |
44 | /* We don't really care */ | 43 | /* We don't really care */ |
45 | dev->pio_mode = XFER_PIO_0; | 44 | dev->pio_mode = XFER_PIO_0; |
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c index 2ddbe4cc71e..4c9295a49a4 100644 --- a/drivers/ata/sata_sil.c +++ b/drivers/ata/sata_sil.c | |||
@@ -303,22 +303,20 @@ static int sil_set_mode (struct ata_port *ap, struct ata_device **r_failed) | |||
303 | struct ata_device *dev; | 303 | struct ata_device *dev; |
304 | void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR]; | 304 | void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR]; |
305 | void __iomem *addr = mmio_base + sil_port[ap->port_no].xfer_mode; | 305 | void __iomem *addr = mmio_base + sil_port[ap->port_no].xfer_mode; |
306 | u32 tmp, dev_mode[2]; | 306 | u32 tmp, dev_mode[2] = { }; |
307 | unsigned int i; | ||
308 | int rc; | 307 | int rc; |
309 | 308 | ||
310 | rc = ata_do_set_mode(ap, r_failed); | 309 | rc = ata_do_set_mode(ap, r_failed); |
311 | if (rc) | 310 | if (rc) |
312 | return rc; | 311 | return rc; |
313 | 312 | ||
314 | for (i = 0; i < 2; i++) { | 313 | ata_link_for_each_dev(dev, &ap->link) { |
315 | dev = &ap->link.device[i]; | ||
316 | if (!ata_dev_enabled(dev)) | 314 | if (!ata_dev_enabled(dev)) |
317 | dev_mode[i] = 0; /* PIO0/1/2 */ | 315 | dev_mode[dev->devno] = 0; /* PIO0/1/2 */ |
318 | else if (dev->flags & ATA_DFLAG_PIO) | 316 | else if (dev->flags & ATA_DFLAG_PIO) |
319 | dev_mode[i] = 1; /* PIO3/4 */ | 317 | dev_mode[dev->devno] = 1; /* PIO3/4 */ |
320 | else | 318 | else |
321 | dev_mode[i] = 3; /* UDMA */ | 319 | dev_mode[dev->devno] = 3; /* UDMA */ |
322 | /* value 2 indicates MDMA */ | 320 | /* value 2 indicates MDMA */ |
323 | } | 321 | } |
324 | 322 | ||