aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/ata/ahci.c8
-rw-r--r--drivers/ata/ata_generic.c5
-rw-r--r--drivers/ata/libata-acpi.c19
-rw-r--r--drivers/ata/libata-core.c183
-rw-r--r--drivers/ata/libata-eh.c84
-rw-r--r--drivers/ata/libata-pmp.c22
-rw-r--r--drivers/ata/libata-scsi.c22
-rw-r--r--drivers/ata/pata_it821x.c34
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c14
-rw-r--r--drivers/ata/pata_legacy.c17
-rw-r--r--drivers/ata/pata_pdc2027x.c31
-rw-r--r--drivers/ata/pata_platform.c14
-rw-r--r--drivers/ata/pata_rz1000.c16
-rw-r--r--drivers/ata/sata_sil.c2
-rw-r--r--include/linux/libata.h76
15 files changed, 307 insertions, 240 deletions
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index a67b8e7c712d..656448c7fef9 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1119,14 +1119,14 @@ static void ahci_start_port(struct ata_port *ap)
1119 1119
1120 /* turn on LEDs */ 1120 /* turn on LEDs */
1121 if (ap->flags & ATA_FLAG_EM) { 1121 if (ap->flags & ATA_FLAG_EM) {
1122 ata_port_for_each_link(link, ap) { 1122 ata_for_each_link(link, ap, EDGE) {
1123 emp = &pp->em_priv[link->pmp]; 1123 emp = &pp->em_priv[link->pmp];
1124 ahci_transmit_led_message(ap, emp->led_state, 4); 1124 ahci_transmit_led_message(ap, emp->led_state, 4);
1125 } 1125 }
1126 } 1126 }
1127 1127
1128 if (ap->flags & ATA_FLAG_SW_ACTIVITY) 1128 if (ap->flags & ATA_FLAG_SW_ACTIVITY)
1129 ata_port_for_each_link(link, ap) 1129 ata_for_each_link(link, ap, EDGE)
1130 ahci_init_sw_activity(link); 1130 ahci_init_sw_activity(link);
1131 1131
1132} 1132}
@@ -1361,7 +1361,7 @@ static ssize_t ahci_led_show(struct ata_port *ap, char *buf)
1361 struct ahci_em_priv *emp; 1361 struct ahci_em_priv *emp;
1362 int rc = 0; 1362 int rc = 0;
1363 1363
1364 ata_port_for_each_link(link, ap) { 1364 ata_for_each_link(link, ap, EDGE) {
1365 emp = &pp->em_priv[link->pmp]; 1365 emp = &pp->em_priv[link->pmp];
1366 rc += sprintf(buf, "%lx\n", emp->led_state); 1366 rc += sprintf(buf, "%lx\n", emp->led_state);
1367 } 1367 }
@@ -1941,7 +1941,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1941 u32 serror; 1941 u32 serror;
1942 1942
1943 /* determine active link */ 1943 /* determine active link */
1944 ata_port_for_each_link(link, ap) 1944 ata_for_each_link(link, ap, EDGE)
1945 if (ata_link_active(link)) 1945 if (ata_link_active(link))
1946 break; 1946 break;
1947 if (!link) 1947 if (!link)
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index 5c33767e66de..dc48a6398abe 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -57,10 +57,7 @@ static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
57 if (pdev->vendor == PCI_VENDOR_ID_CENATEK) 57 if (pdev->vendor == PCI_VENDOR_ID_CENATEK)
58 dma_enabled = 0xFF; 58 dma_enabled = 0xFF;
59 59
60 ata_link_for_each_dev(dev, link) { 60 ata_for_each_dev(dev, link, ENABLED) {
61 if (!ata_dev_enabled(dev))
62 continue;
63
64 /* We don't really care */ 61 /* We don't really care */
65 dev->pio_mode = XFER_PIO_0; 62 dev->pio_mode = XFER_PIO_0;
66 dev->dma_mode = XFER_MW_DMA_0; 63 dev->dma_mode = XFER_MW_DMA_0;
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index c012307d0ba6..ef02e488d468 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -89,7 +89,7 @@ void ata_acpi_associate_sata_port(struct ata_port *ap)
89 89
90 ap->link.device->acpi_handle = NULL; 90 ap->link.device->acpi_handle = NULL;
91 91
92 ata_port_for_each_link(link, ap) { 92 ata_for_each_link(link, ap, EDGE) {
93 acpi_integer adr = SATA_ADR(ap->port_no, link->pmp); 93 acpi_integer adr = SATA_ADR(ap->port_no, link->pmp);
94 94
95 link->device->acpi_handle = 95 link->device->acpi_handle =
@@ -129,8 +129,8 @@ static void ata_acpi_detach_device(struct ata_port *ap, struct ata_device *dev)
129 struct ata_link *tlink; 129 struct ata_link *tlink;
130 struct ata_device *tdev; 130 struct ata_device *tdev;
131 131
132 ata_port_for_each_link(tlink, ap) 132 ata_for_each_link(tlink, ap, EDGE)
133 ata_link_for_each_dev(tdev, tlink) 133 ata_for_each_dev(tdev, tlink, ALL)
134 tdev->flags |= ATA_DFLAG_DETACH; 134 tdev->flags |= ATA_DFLAG_DETACH;
135 } 135 }
136 136
@@ -588,12 +588,9 @@ int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm)
588{ 588{
589 struct ata_device *dev; 589 struct ata_device *dev;
590 590
591 ata_link_for_each_dev(dev, &ap->link) { 591 ata_for_each_dev(dev, &ap->link, ENABLED) {
592 unsigned long xfer_mask, udma_mask; 592 unsigned long xfer_mask, udma_mask;
593 593
594 if (!ata_dev_enabled(dev))
595 continue;
596
597 xfer_mask = ata_acpi_gtm_xfermask(dev, gtm); 594 xfer_mask = ata_acpi_gtm_xfermask(dev, gtm);
598 ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask); 595 ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask);
599 596
@@ -893,7 +890,7 @@ void ata_acpi_on_resume(struct ata_port *ap)
893 * use values set by _STM. Cache _GTF result and 890 * use values set by _STM. Cache _GTF result and
894 * schedule _GTF. 891 * schedule _GTF.
895 */ 892 */
896 ata_link_for_each_dev(dev, &ap->link) { 893 ata_for_each_dev(dev, &ap->link, ALL) {
897 ata_acpi_clear_gtf(dev); 894 ata_acpi_clear_gtf(dev);
898 if (ata_dev_enabled(dev) && 895 if (ata_dev_enabled(dev) &&
899 ata_dev_get_GTF(dev, NULL) >= 0) 896 ata_dev_get_GTF(dev, NULL) >= 0)
@@ -904,7 +901,7 @@ void ata_acpi_on_resume(struct ata_port *ap)
904 * there's no reason to evaluate IDE _GTF early 901 * there's no reason to evaluate IDE _GTF early
905 * without _STM. Clear cache and schedule _GTF. 902 * without _STM. Clear cache and schedule _GTF.
906 */ 903 */
907 ata_link_for_each_dev(dev, &ap->link) { 904 ata_for_each_dev(dev, &ap->link, ALL) {
908 ata_acpi_clear_gtf(dev); 905 ata_acpi_clear_gtf(dev);
909 if (ata_dev_enabled(dev)) 906 if (ata_dev_enabled(dev))
910 dev->flags |= ATA_DFLAG_ACPI_PENDING; 907 dev->flags |= ATA_DFLAG_ACPI_PENDING;
@@ -932,8 +929,8 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
932 if (state.event == PM_EVENT_ON) 929 if (state.event == PM_EVENT_ON)
933 acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0); 930 acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
934 931
935 ata_link_for_each_dev(dev, &ap->link) { 932 ata_for_each_dev(dev, &ap->link, ENABLED) {
936 if (dev->acpi_handle && ata_dev_enabled(dev)) 933 if (dev->acpi_handle)
937 acpi_bus_set_power(dev->acpi_handle, 934 acpi_bus_set_power(dev->acpi_handle,
938 state.event == PM_EVENT_ON ? 935 state.event == PM_EVENT_ON ?
939 ACPI_STATE_D0 : ACPI_STATE_D3); 936 ACPI_STATE_D0 : ACPI_STATE_D3);
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index bc6695e3c848..ffd98e4e65b4 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -163,43 +163,119 @@ MODULE_LICENSE("GPL");
163MODULE_VERSION(DRV_VERSION); 163MODULE_VERSION(DRV_VERSION);
164 164
165 165
166/* 166/**
167 * Iterator helpers. Don't use directly. 167 * ata_link_next - link iteration helper
168 * @link: the previous link, NULL to start
169 * @ap: ATA port containing links to iterate
170 * @mode: iteration mode, one of ATA_LITER_*
171 *
172 * LOCKING:
173 * Host lock or EH context.
168 * 174 *
169 * LOCKING: 175 * RETURNS:
170 * Host lock or EH context. 176 * Pointer to the next link.
171 */ 177 */
172struct ata_link *__ata_port_next_link(struct ata_port *ap, 178struct ata_link *ata_link_next(struct ata_link *link, struct ata_port *ap,
173 struct ata_link *link, bool dev_only) 179 enum ata_link_iter_mode mode)
174{ 180{
181 BUG_ON(mode != ATA_LITER_EDGE &&
182 mode != ATA_LITER_PMP_FIRST && mode != ATA_LITER_HOST_FIRST);
183
175 /* NULL link indicates start of iteration */ 184 /* NULL link indicates start of iteration */
176 if (!link) { 185 if (!link)
177 if (dev_only && sata_pmp_attached(ap)) 186 switch (mode) {
178 return ap->pmp_link; 187 case ATA_LITER_EDGE:
179 return &ap->link; 188 case ATA_LITER_PMP_FIRST:
180 } 189 if (sata_pmp_attached(ap))
190 return ap->pmp_link;
191 /* fall through */
192 case ATA_LITER_HOST_FIRST:
193 return &ap->link;
194 }
181 195
182 /* we just iterated over the host master link, what's next? */ 196 /* we just iterated over the host link, what's next? */
183 if (link == &ap->link) { 197 if (link == &ap->link)
184 if (!sata_pmp_attached(ap)) { 198 switch (mode) {
185 if (unlikely(ap->slave_link) && !dev_only) 199 case ATA_LITER_HOST_FIRST:
200 if (sata_pmp_attached(ap))
201 return ap->pmp_link;
202 /* fall through */
203 case ATA_LITER_PMP_FIRST:
204 if (unlikely(ap->slave_link))
186 return ap->slave_link; 205 return ap->slave_link;
206 /* fall through */
207 case ATA_LITER_EDGE:
187 return NULL; 208 return NULL;
188 } 209 }
189 return ap->pmp_link;
190 }
191 210
192 /* slave_link excludes PMP */ 211 /* slave_link excludes PMP */
193 if (unlikely(link == ap->slave_link)) 212 if (unlikely(link == ap->slave_link))
194 return NULL; 213 return NULL;
195 214
196 /* iterate to the next PMP link */ 215 /* we were over a PMP link */
197 if (++link < ap->pmp_link + ap->nr_pmp_links) 216 if (++link < ap->pmp_link + ap->nr_pmp_links)
198 return link; 217 return link;
218
219 if (mode == ATA_LITER_PMP_FIRST)
220 return &ap->link;
221
199 return NULL; 222 return NULL;
200} 223}
201 224
202/** 225/**
226 * ata_dev_next - device iteration helper
227 * @dev: the previous device, NULL to start
228 * @link: ATA link containing devices to iterate
229 * @mode: iteration mode, one of ATA_DITER_*
230 *
231 * LOCKING:
232 * Host lock or EH context.
233 *
234 * RETURNS:
235 * Pointer to the next device.
236 */
237struct ata_device *ata_dev_next(struct ata_device *dev, struct ata_link *link,
238 enum ata_dev_iter_mode mode)
239{
240 BUG_ON(mode != ATA_DITER_ENABLED && mode != ATA_DITER_ENABLED_REVERSE &&
241 mode != ATA_DITER_ALL && mode != ATA_DITER_ALL_REVERSE);
242
243 /* NULL dev indicates start of iteration */
244 if (!dev)
245 switch (mode) {
246 case ATA_DITER_ENABLED:
247 case ATA_DITER_ALL:
248 dev = link->device;
249 goto check;
250 case ATA_DITER_ENABLED_REVERSE:
251 case ATA_DITER_ALL_REVERSE:
252 dev = link->device + ata_link_max_devices(link) - 1;
253 goto check;
254 }
255
256 next:
257 /* move to the next one */
258 switch (mode) {
259 case ATA_DITER_ENABLED:
260 case ATA_DITER_ALL:
261 if (++dev < link->device + ata_link_max_devices(link))
262 goto check;
263 return NULL;
264 case ATA_DITER_ENABLED_REVERSE:
265 case ATA_DITER_ALL_REVERSE:
266 if (--dev >= link->device)
267 goto check;
268 return NULL;
269 }
270
271 check:
272 if ((mode == ATA_DITER_ENABLED || mode == ATA_DITER_ENABLED_REVERSE) &&
273 !ata_dev_enabled(dev))
274 goto next;
275 return dev;
276}
277
278/**
203 * ata_dev_phys_link - find physical link for a device 279 * ata_dev_phys_link - find physical link for a device
204 * @dev: ATA device to look up physical link for 280 * @dev: ATA device to look up physical link for
205 * 281 *
@@ -1107,8 +1183,8 @@ static void ata_lpm_enable(struct ata_host *host)
1107 1183
1108 for (i = 0; i < host->n_ports; i++) { 1184 for (i = 0; i < host->n_ports; i++) {
1109 ap = host->ports[i]; 1185 ap = host->ports[i];
1110 ata_port_for_each_link(link, ap) { 1186 ata_for_each_link(link, ap, EDGE) {
1111 ata_link_for_each_dev(dev, link) 1187 ata_for_each_dev(dev, link, ALL)
1112 ata_dev_disable_pm(dev); 1188 ata_dev_disable_pm(dev);
1113 } 1189 }
1114 } 1190 }
@@ -2594,11 +2670,11 @@ int ata_bus_probe(struct ata_port *ap)
2594 2670
2595 ata_port_probe(ap); 2671 ata_port_probe(ap);
2596 2672
2597 ata_link_for_each_dev(dev, &ap->link) 2673 ata_for_each_dev(dev, &ap->link, ALL)
2598 tries[dev->devno] = ATA_PROBE_MAX_TRIES; 2674 tries[dev->devno] = ATA_PROBE_MAX_TRIES;
2599 2675
2600 retry: 2676 retry:
2601 ata_link_for_each_dev(dev, &ap->link) { 2677 ata_for_each_dev(dev, &ap->link, ALL) {
2602 /* If we issue an SRST then an ATA drive (not ATAPI) 2678 /* If we issue an SRST then an ATA drive (not ATAPI)
2603 * may change configuration and be in PIO0 timing. If 2679 * may change configuration and be in PIO0 timing. If
2604 * we do a hard reset (or are coming from power on) 2680 * we do a hard reset (or are coming from power on)
@@ -2620,7 +2696,7 @@ int ata_bus_probe(struct ata_port *ap)
2620 /* reset and determine device classes */ 2696 /* reset and determine device classes */
2621 ap->ops->phy_reset(ap); 2697 ap->ops->phy_reset(ap);
2622 2698
2623 ata_link_for_each_dev(dev, &ap->link) { 2699 ata_for_each_dev(dev, &ap->link, ALL) {
2624 if (!(ap->flags & ATA_FLAG_DISABLED) && 2700 if (!(ap->flags & ATA_FLAG_DISABLED) &&
2625 dev->class != ATA_DEV_UNKNOWN) 2701 dev->class != ATA_DEV_UNKNOWN)
2626 classes[dev->devno] = dev->class; 2702 classes[dev->devno] = dev->class;
@@ -2636,7 +2712,7 @@ int ata_bus_probe(struct ata_port *ap)
2636 specific sequence bass-ackwards so that PDIAG- is released by 2712 specific sequence bass-ackwards so that PDIAG- is released by
2637 the slave device */ 2713 the slave device */
2638 2714
2639 ata_link_for_each_dev_reverse(dev, &ap->link) { 2715 ata_for_each_dev(dev, &ap->link, ALL_REVERSE) {
2640 if (tries[dev->devno]) 2716 if (tries[dev->devno])
2641 dev->class = classes[dev->devno]; 2717 dev->class = classes[dev->devno];
2642 2718
@@ -2653,24 +2729,19 @@ int ata_bus_probe(struct ata_port *ap)
2653 if (ap->ops->cable_detect) 2729 if (ap->ops->cable_detect)
2654 ap->cbl = ap->ops->cable_detect(ap); 2730 ap->cbl = ap->ops->cable_detect(ap);
2655 2731
2656 /* We may have SATA bridge glue hiding here irrespective of the 2732 /* We may have SATA bridge glue hiding here irrespective of
2657 reported cable types and sensed types */ 2733 * the reported cable types and sensed types. When SATA
2658 ata_link_for_each_dev(dev, &ap->link) { 2734 * drives indicate we have a bridge, we don't know which end
2659 if (!ata_dev_enabled(dev)) 2735 * of the link the bridge is which is a problem.
2660 continue; 2736 */
2661 /* SATA drives indicate we have a bridge. We don't know which 2737 ata_for_each_dev(dev, &ap->link, ENABLED)
2662 end of the link the bridge is which is a problem */
2663 if (ata_id_is_sata(dev->id)) 2738 if (ata_id_is_sata(dev->id))
2664 ap->cbl = ATA_CBL_SATA; 2739 ap->cbl = ATA_CBL_SATA;
2665 }
2666 2740
2667 /* After the identify sequence we can now set up the devices. We do 2741 /* After the identify sequence we can now set up the devices. We do
2668 this in the normal order so that the user doesn't get confused */ 2742 this in the normal order so that the user doesn't get confused */
2669 2743
2670 ata_link_for_each_dev(dev, &ap->link) { 2744 ata_for_each_dev(dev, &ap->link, ENABLED) {
2671 if (!ata_dev_enabled(dev))
2672 continue;
2673
2674 ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO; 2745 ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO;
2675 rc = ata_dev_configure(dev); 2746 rc = ata_dev_configure(dev);
2676 ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO; 2747 ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO;
@@ -2683,9 +2754,8 @@ int ata_bus_probe(struct ata_port *ap)
2683 if (rc) 2754 if (rc)
2684 goto fail; 2755 goto fail;
2685 2756
2686 ata_link_for_each_dev(dev, &ap->link) 2757 ata_for_each_dev(dev, &ap->link, ENABLED)
2687 if (ata_dev_enabled(dev)) 2758 return 0;
2688 return 0;
2689 2759
2690 /* no device present, disable port */ 2760 /* no device present, disable port */
2691 ata_port_disable(ap); 2761 ata_port_disable(ap);
@@ -3331,13 +3401,10 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3331 int rc = 0, used_dma = 0, found = 0; 3401 int rc = 0, used_dma = 0, found = 0;
3332 3402
3333 /* step 1: calculate xfer_mask */ 3403 /* step 1: calculate xfer_mask */
3334 ata_link_for_each_dev(dev, link) { 3404 ata_for_each_dev(dev, link, ENABLED) {
3335 unsigned long pio_mask, dma_mask; 3405 unsigned long pio_mask, dma_mask;
3336 unsigned int mode_mask; 3406 unsigned int mode_mask;
3337 3407
3338 if (!ata_dev_enabled(dev))
3339 continue;
3340
3341 mode_mask = ATA_DMA_MASK_ATA; 3408 mode_mask = ATA_DMA_MASK_ATA;
3342 if (dev->class == ATA_DEV_ATAPI) 3409 if (dev->class == ATA_DEV_ATAPI)
3343 mode_mask = ATA_DMA_MASK_ATAPI; 3410 mode_mask = ATA_DMA_MASK_ATAPI;
@@ -3366,10 +3433,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3366 goto out; 3433 goto out;
3367 3434
3368 /* step 2: always set host PIO timings */ 3435 /* step 2: always set host PIO timings */
3369 ata_link_for_each_dev(dev, link) { 3436 ata_for_each_dev(dev, link, ENABLED) {
3370 if (!ata_dev_enabled(dev))
3371 continue;
3372
3373 if (dev->pio_mode == 0xff) { 3437 if (dev->pio_mode == 0xff) {
3374 ata_dev_printk(dev, KERN_WARNING, "no PIO support\n"); 3438 ata_dev_printk(dev, KERN_WARNING, "no PIO support\n");
3375 rc = -EINVAL; 3439 rc = -EINVAL;
@@ -3383,8 +3447,8 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3383 } 3447 }
3384 3448
3385 /* step 3: set host DMA timings */ 3449 /* step 3: set host DMA timings */
3386 ata_link_for_each_dev(dev, link) { 3450 ata_for_each_dev(dev, link, ENABLED) {
3387 if (!ata_dev_enabled(dev) || !ata_dma_enabled(dev)) 3451 if (!ata_dma_enabled(dev))
3388 continue; 3452 continue;
3389 3453
3390 dev->xfer_mode = dev->dma_mode; 3454 dev->xfer_mode = dev->dma_mode;
@@ -3394,11 +3458,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3394 } 3458 }
3395 3459
3396 /* step 4: update devices' xfer mode */ 3460 /* step 4: update devices' xfer mode */
3397 ata_link_for_each_dev(dev, link) { 3461 ata_for_each_dev(dev, link, ENABLED) {
3398 /* don't update suspended devices' xfer mode */
3399 if (!ata_dev_enabled(dev))
3400 continue;
3401
3402 rc = ata_dev_set_mode(dev); 3462 rc = ata_dev_set_mode(dev);
3403 if (rc) 3463 if (rc)
3404 goto out; 3464 goto out;
@@ -4263,9 +4323,9 @@ static int cable_is_40wire(struct ata_port *ap)
4263 * - if you have a non detect capable drive you don't want it 4323 * - if you have a non detect capable drive you don't want it
4264 * to colour the choice 4324 * to colour the choice
4265 */ 4325 */
4266 ata_port_for_each_link(link, ap) { 4326 ata_for_each_link(link, ap, EDGE) {
4267 ata_link_for_each_dev(dev, link) { 4327 ata_for_each_dev(dev, link, ENABLED) {
4268 if (ata_dev_enabled(dev) && !ata_is_40wire(dev)) 4328 if (!ata_is_40wire(dev))
4269 return 0; 4329 return 0;
4270 } 4330 }
4271 } 4331 }
@@ -5218,7 +5278,7 @@ static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg,
5218 } 5278 }
5219 5279
5220 ap->pflags |= ATA_PFLAG_PM_PENDING; 5280 ap->pflags |= ATA_PFLAG_PM_PENDING;
5221 __ata_port_for_each_link(link, ap) { 5281 ata_for_each_link(link, ap, HOST_FIRST) {
5222 link->eh_info.action |= action; 5282 link->eh_info.action |= action;
5223 link->eh_info.flags |= ehi_flags; 5283 link->eh_info.flags |= ehi_flags;
5224 } 5284 }
@@ -6063,9 +6123,9 @@ static void ata_port_detach(struct ata_port *ap)
6063 /* EH is now guaranteed to see UNLOADING - EH context belongs 6123 /* EH is now guaranteed to see UNLOADING - EH context belongs
6064 * to us. Restore SControl and disable all existing devices. 6124 * to us. Restore SControl and disable all existing devices.
6065 */ 6125 */
6066 __ata_port_for_each_link(link, ap) { 6126 ata_for_each_link(link, ap, HOST_FIRST) {
6067 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0); 6127 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0);
6068 ata_link_for_each_dev(dev, link) 6128 ata_for_each_dev(dev, link, ALL)
6069 ata_dev_disable(dev); 6129 ata_dev_disable(dev);
6070 } 6130 }
6071 6131
@@ -6528,7 +6588,8 @@ EXPORT_SYMBOL_GPL(ata_base_port_ops);
6528EXPORT_SYMBOL_GPL(sata_port_ops); 6588EXPORT_SYMBOL_GPL(sata_port_ops);
6529EXPORT_SYMBOL_GPL(ata_dummy_port_ops); 6589EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
6530EXPORT_SYMBOL_GPL(ata_dummy_port_info); 6590EXPORT_SYMBOL_GPL(ata_dummy_port_info);
6531EXPORT_SYMBOL_GPL(__ata_port_next_link); 6591EXPORT_SYMBOL_GPL(ata_link_next);
6592EXPORT_SYMBOL_GPL(ata_dev_next);
6532EXPORT_SYMBOL_GPL(ata_std_bios_param); 6593EXPORT_SYMBOL_GPL(ata_std_bios_param);
6533EXPORT_SYMBOL_GPL(ata_host_init); 6594EXPORT_SYMBOL_GPL(ata_host_init);
6534EXPORT_SYMBOL_GPL(ata_host_alloc); 6595EXPORT_SYMBOL_GPL(ata_host_alloc);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 32da9a93ce44..d673f3712bdc 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -422,7 +422,7 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
422 422
423 if (!dev) { 423 if (!dev) {
424 ehi->action &= ~action; 424 ehi->action &= ~action;
425 ata_link_for_each_dev(tdev, link) 425 ata_for_each_dev(tdev, link, ALL)
426 ehi->dev_action[tdev->devno] &= ~action; 426 ehi->dev_action[tdev->devno] &= ~action;
427 } else { 427 } else {
428 /* doesn't make sense for port-wide EH actions */ 428 /* doesn't make sense for port-wide EH actions */
@@ -430,7 +430,7 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
430 430
431 /* break ehi->action into ehi->dev_action */ 431 /* break ehi->action into ehi->dev_action */
432 if (ehi->action & action) { 432 if (ehi->action & action) {
433 ata_link_for_each_dev(tdev, link) 433 ata_for_each_dev(tdev, link, ALL)
434 ehi->dev_action[tdev->devno] |= 434 ehi->dev_action[tdev->devno] |=
435 ehi->action & action; 435 ehi->action & action;
436 ehi->action &= ~action; 436 ehi->action &= ~action;
@@ -592,7 +592,7 @@ void ata_scsi_error(struct Scsi_Host *host)
592 /* fetch & clear EH info */ 592 /* fetch & clear EH info */
593 spin_lock_irqsave(ap->lock, flags); 593 spin_lock_irqsave(ap->lock, flags);
594 594
595 __ata_port_for_each_link(link, ap) { 595 ata_for_each_link(link, ap, HOST_FIRST) {
596 struct ata_eh_context *ehc = &link->eh_context; 596 struct ata_eh_context *ehc = &link->eh_context;
597 struct ata_device *dev; 597 struct ata_device *dev;
598 598
@@ -600,12 +600,9 @@ void ata_scsi_error(struct Scsi_Host *host)
600 link->eh_context.i = link->eh_info; 600 link->eh_context.i = link->eh_info;
601 memset(&link->eh_info, 0, sizeof(link->eh_info)); 601 memset(&link->eh_info, 0, sizeof(link->eh_info));
602 602
603 ata_link_for_each_dev(dev, link) { 603 ata_for_each_dev(dev, link, ENABLED) {
604 int devno = dev->devno; 604 int devno = dev->devno;
605 605
606 if (!ata_dev_enabled(dev))
607 continue;
608
609 ehc->saved_xfer_mode[devno] = dev->xfer_mode; 606 ehc->saved_xfer_mode[devno] = dev->xfer_mode;
610 if (ata_ncq_enabled(dev)) 607 if (ata_ncq_enabled(dev))
611 ehc->saved_ncq_enabled |= 1 << devno; 608 ehc->saved_ncq_enabled |= 1 << devno;
@@ -644,7 +641,7 @@ void ata_scsi_error(struct Scsi_Host *host)
644 } 641 }
645 642
646 /* this run is complete, make sure EH info is clear */ 643 /* this run is complete, make sure EH info is clear */
647 __ata_port_for_each_link(link, ap) 644 ata_for_each_link(link, ap, HOST_FIRST)
648 memset(&link->eh_info, 0, sizeof(link->eh_info)); 645 memset(&link->eh_info, 0, sizeof(link->eh_info));
649 646
650 /* Clear host_eh_scheduled while holding ap->lock such 647 /* Clear host_eh_scheduled while holding ap->lock such
@@ -1025,7 +1022,7 @@ int sata_async_notification(struct ata_port *ap)
1025 struct ata_link *link; 1022 struct ata_link *link;
1026 1023
1027 /* check and notify ATAPI AN */ 1024 /* check and notify ATAPI AN */
1028 ata_port_for_each_link(link, ap) { 1025 ata_for_each_link(link, ap, EDGE) {
1029 if (!(sntf & (1 << link->pmp))) 1026 if (!(sntf & (1 << link->pmp)))
1030 continue; 1027 continue;
1031 1028
@@ -2005,7 +2002,7 @@ void ata_eh_autopsy(struct ata_port *ap)
2005{ 2002{
2006 struct ata_link *link; 2003 struct ata_link *link;
2007 2004
2008 ata_port_for_each_link(link, ap) 2005 ata_for_each_link(link, ap, EDGE)
2009 ata_eh_link_autopsy(link); 2006 ata_eh_link_autopsy(link);
2010 2007
2011 /* Handle the frigging slave link. Autopsy is done similarly 2008 /* Handle the frigging slave link. Autopsy is done similarly
@@ -2219,7 +2216,7 @@ void ata_eh_report(struct ata_port *ap)
2219{ 2216{
2220 struct ata_link *link; 2217 struct ata_link *link;
2221 2218
2222 __ata_port_for_each_link(link, ap) 2219 ata_for_each_link(link, ap, HOST_FIRST)
2223 ata_eh_link_report(link); 2220 ata_eh_link_report(link);
2224} 2221}
2225 2222
@@ -2230,7 +2227,7 @@ static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset,
2230 struct ata_device *dev; 2227 struct ata_device *dev;
2231 2228
2232 if (clear_classes) 2229 if (clear_classes)
2233 ata_link_for_each_dev(dev, link) 2230 ata_for_each_dev(dev, link, ALL)
2234 classes[dev->devno] = ATA_DEV_UNKNOWN; 2231 classes[dev->devno] = ATA_DEV_UNKNOWN;
2235 2232
2236 return reset(link, classes, deadline); 2233 return reset(link, classes, deadline);
@@ -2294,7 +2291,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2294 2291
2295 ata_eh_about_to_do(link, NULL, ATA_EH_RESET); 2292 ata_eh_about_to_do(link, NULL, ATA_EH_RESET);
2296 2293
2297 ata_link_for_each_dev(dev, link) { 2294 ata_for_each_dev(dev, link, ALL) {
2298 /* If we issue an SRST then an ATA drive (not ATAPI) 2295 /* If we issue an SRST then an ATA drive (not ATAPI)
2299 * may change configuration and be in PIO0 timing. If 2296 * may change configuration and be in PIO0 timing. If
2300 * we do a hard reset (or are coming from power on) 2297 * we do a hard reset (or are coming from power on)
@@ -2355,7 +2352,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2355 "port disabled. ignoring.\n"); 2352 "port disabled. ignoring.\n");
2356 ehc->i.action &= ~ATA_EH_RESET; 2353 ehc->i.action &= ~ATA_EH_RESET;
2357 2354
2358 ata_link_for_each_dev(dev, link) 2355 ata_for_each_dev(dev, link, ALL)
2359 classes[dev->devno] = ATA_DEV_NONE; 2356 classes[dev->devno] = ATA_DEV_NONE;
2360 2357
2361 rc = 0; 2358 rc = 0;
@@ -2369,7 +2366,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2369 * bang classes and return. 2366 * bang classes and return.
2370 */ 2367 */
2371 if (reset && !(ehc->i.action & ATA_EH_RESET)) { 2368 if (reset && !(ehc->i.action & ATA_EH_RESET)) {
2372 ata_link_for_each_dev(dev, link) 2369 ata_for_each_dev(dev, link, ALL)
2373 classes[dev->devno] = ATA_DEV_NONE; 2370 classes[dev->devno] = ATA_DEV_NONE;
2374 rc = 0; 2371 rc = 0;
2375 goto out; 2372 goto out;
@@ -2454,7 +2451,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2454 /* 2451 /*
2455 * Post-reset processing 2452 * Post-reset processing
2456 */ 2453 */
2457 ata_link_for_each_dev(dev, link) { 2454 ata_for_each_dev(dev, link, ALL) {
2458 /* After the reset, the device state is PIO 0 and the 2455 /* After the reset, the device state is PIO 0 and the
2459 * controller state is undefined. Reset also wakes up 2456 * controller state is undefined. Reset also wakes up
2460 * drives from sleeping mode. 2457 * drives from sleeping mode.
@@ -2510,7 +2507,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2510 * can be reliably detected and retried. 2507 * can be reliably detected and retried.
2511 */ 2508 */
2512 nr_unknown = 0; 2509 nr_unknown = 0;
2513 ata_link_for_each_dev(dev, link) { 2510 ata_for_each_dev(dev, link, ALL) {
2514 /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */ 2511 /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */
2515 if (classes[dev->devno] == ATA_DEV_UNKNOWN) { 2512 if (classes[dev->devno] == ATA_DEV_UNKNOWN) {
2516 classes[dev->devno] = ATA_DEV_NONE; 2513 classes[dev->devno] = ATA_DEV_NONE;
@@ -2619,8 +2616,8 @@ static inline void ata_eh_pull_park_action(struct ata_port *ap)
2619 2616
2620 spin_lock_irqsave(ap->lock, flags); 2617 spin_lock_irqsave(ap->lock, flags);
2621 INIT_COMPLETION(ap->park_req_pending); 2618 INIT_COMPLETION(ap->park_req_pending);
2622 ata_port_for_each_link(link, ap) { 2619 ata_for_each_link(link, ap, EDGE) {
2623 ata_link_for_each_dev(dev, link) { 2620 ata_for_each_dev(dev, link, ALL) {
2624 struct ata_eh_info *ehi = &link->eh_info; 2621 struct ata_eh_info *ehi = &link->eh_info;
2625 2622
2626 link->eh_context.i.dev_action[dev->devno] |= 2623 link->eh_context.i.dev_action[dev->devno] |=
@@ -2675,7 +2672,7 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
2675 * be done backwards such that PDIAG- is released by the slave 2672 * be done backwards such that PDIAG- is released by the slave
2676 * device before the master device is identified. 2673 * device before the master device is identified.
2677 */ 2674 */
2678 ata_link_for_each_dev_reverse(dev, link) { 2675 ata_for_each_dev(dev, link, ALL_REVERSE) {
2679 unsigned int action = ata_eh_dev_action(dev); 2676 unsigned int action = ata_eh_dev_action(dev);
2680 unsigned int readid_flags = 0; 2677 unsigned int readid_flags = 0;
2681 2678
@@ -2744,7 +2741,7 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
2744 /* Configure new devices forward such that user doesn't see 2741 /* Configure new devices forward such that user doesn't see
2745 * device detection messages backwards. 2742 * device detection messages backwards.
2746 */ 2743 */
2747 ata_link_for_each_dev(dev, link) { 2744 ata_for_each_dev(dev, link, ALL) {
2748 if (!(new_mask & (1 << dev->devno)) || 2745 if (!(new_mask & (1 << dev->devno)) ||
2749 dev->class == ATA_DEV_PMP) 2746 dev->class == ATA_DEV_PMP)
2750 continue; 2747 continue;
@@ -2793,10 +2790,7 @@ int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
2793 int rc; 2790 int rc;
2794 2791
2795 /* if data transfer is verified, clear DUBIOUS_XFER on ering top */ 2792 /* if data transfer is verified, clear DUBIOUS_XFER on ering top */
2796 ata_link_for_each_dev(dev, link) { 2793 ata_for_each_dev(dev, link, ENABLED) {
2797 if (!ata_dev_enabled(dev))
2798 continue;
2799
2800 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) { 2794 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) {
2801 struct ata_ering_entry *ent; 2795 struct ata_ering_entry *ent;
2802 2796
@@ -2813,14 +2807,11 @@ int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
2813 rc = ata_do_set_mode(link, r_failed_dev); 2807 rc = ata_do_set_mode(link, r_failed_dev);
2814 2808
2815 /* if transfer mode has changed, set DUBIOUS_XFER on device */ 2809 /* if transfer mode has changed, set DUBIOUS_XFER on device */
2816 ata_link_for_each_dev(dev, link) { 2810 ata_for_each_dev(dev, link, ENABLED) {
2817 struct ata_eh_context *ehc = &link->eh_context; 2811 struct ata_eh_context *ehc = &link->eh_context;
2818 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno]; 2812 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno];
2819 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno)); 2813 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno));
2820 2814
2821 if (!ata_dev_enabled(dev))
2822 continue;
2823
2824 if (dev->xfer_mode != saved_xfer_mode || 2815 if (dev->xfer_mode != saved_xfer_mode ||
2825 ata_ncq_enabled(dev) != saved_ncq) 2816 ata_ncq_enabled(dev) != saved_ncq)
2826 dev->flags |= ATA_DFLAG_DUBIOUS_XFER; 2817 dev->flags |= ATA_DFLAG_DUBIOUS_XFER;
@@ -2881,9 +2872,8 @@ static int ata_link_nr_enabled(struct ata_link *link)
2881 struct ata_device *dev; 2872 struct ata_device *dev;
2882 int cnt = 0; 2873 int cnt = 0;
2883 2874
2884 ata_link_for_each_dev(dev, link) 2875 ata_for_each_dev(dev, link, ENABLED)
2885 if (ata_dev_enabled(dev)) 2876 cnt++;
2886 cnt++;
2887 return cnt; 2877 return cnt;
2888} 2878}
2889 2879
@@ -2892,7 +2882,7 @@ static int ata_link_nr_vacant(struct ata_link *link)
2892 struct ata_device *dev; 2882 struct ata_device *dev;
2893 int cnt = 0; 2883 int cnt = 0;
2894 2884
2895 ata_link_for_each_dev(dev, link) 2885 ata_for_each_dev(dev, link, ALL)
2896 if (dev->class == ATA_DEV_UNKNOWN) 2886 if (dev->class == ATA_DEV_UNKNOWN)
2897 cnt++; 2887 cnt++;
2898 return cnt; 2888 return cnt;
@@ -2918,7 +2908,7 @@ static int ata_eh_skip_recovery(struct ata_link *link)
2918 return 0; 2908 return 0;
2919 2909
2920 /* skip if class codes for all vacant slots are ATA_DEV_NONE */ 2910 /* skip if class codes for all vacant slots are ATA_DEV_NONE */
2921 ata_link_for_each_dev(dev, link) { 2911 ata_for_each_dev(dev, link, ALL) {
2922 if (dev->class == ATA_DEV_UNKNOWN && 2912 if (dev->class == ATA_DEV_UNKNOWN &&
2923 ehc->classes[dev->devno] != ATA_DEV_NONE) 2913 ehc->classes[dev->devno] != ATA_DEV_NONE)
2924 return 0; 2914 return 0;
@@ -3026,7 +3016,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3026 DPRINTK("ENTER\n"); 3016 DPRINTK("ENTER\n");
3027 3017
3028 /* prep for recovery */ 3018 /* prep for recovery */
3029 ata_port_for_each_link(link, ap) { 3019 ata_for_each_link(link, ap, EDGE) {
3030 struct ata_eh_context *ehc = &link->eh_context; 3020 struct ata_eh_context *ehc = &link->eh_context;
3031 3021
3032 /* re-enable link? */ 3022 /* re-enable link? */
@@ -3038,7 +3028,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3038 ata_eh_done(link, NULL, ATA_EH_ENABLE_LINK); 3028 ata_eh_done(link, NULL, ATA_EH_ENABLE_LINK);
3039 } 3029 }
3040 3030
3041 ata_link_for_each_dev(dev, link) { 3031 ata_for_each_dev(dev, link, ALL) {
3042 if (link->flags & ATA_LFLAG_NO_RETRY) 3032 if (link->flags & ATA_LFLAG_NO_RETRY)
3043 ehc->tries[dev->devno] = 1; 3033 ehc->tries[dev->devno] = 1;
3044 else 3034 else
@@ -3068,19 +3058,19 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3068 goto out; 3058 goto out;
3069 3059
3070 /* prep for EH */ 3060 /* prep for EH */
3071 ata_port_for_each_link(link, ap) { 3061 ata_for_each_link(link, ap, EDGE) {
3072 struct ata_eh_context *ehc = &link->eh_context; 3062 struct ata_eh_context *ehc = &link->eh_context;
3073 3063
3074 /* skip EH if possible. */ 3064 /* skip EH if possible. */
3075 if (ata_eh_skip_recovery(link)) 3065 if (ata_eh_skip_recovery(link))
3076 ehc->i.action = 0; 3066 ehc->i.action = 0;
3077 3067
3078 ata_link_for_each_dev(dev, link) 3068 ata_for_each_dev(dev, link, ALL)
3079 ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; 3069 ehc->classes[dev->devno] = ATA_DEV_UNKNOWN;
3080 } 3070 }
3081 3071
3082 /* reset */ 3072 /* reset */
3083 ata_port_for_each_link(link, ap) { 3073 ata_for_each_link(link, ap, EDGE) {
3084 struct ata_eh_context *ehc = &link->eh_context; 3074 struct ata_eh_context *ehc = &link->eh_context;
3085 3075
3086 if (!(ehc->i.action & ATA_EH_RESET)) 3076 if (!(ehc->i.action & ATA_EH_RESET))
@@ -3105,8 +3095,8 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3105 ata_eh_pull_park_action(ap); 3095 ata_eh_pull_park_action(ap);
3106 3096
3107 deadline = jiffies; 3097 deadline = jiffies;
3108 ata_port_for_each_link(link, ap) { 3098 ata_for_each_link(link, ap, EDGE) {
3109 ata_link_for_each_dev(dev, link) { 3099 ata_for_each_dev(dev, link, ALL) {
3110 struct ata_eh_context *ehc = &link->eh_context; 3100 struct ata_eh_context *ehc = &link->eh_context;
3111 unsigned long tmp; 3101 unsigned long tmp;
3112 3102
@@ -3134,8 +3124,8 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3134 deadline = wait_for_completion_timeout(&ap->park_req_pending, 3124 deadline = wait_for_completion_timeout(&ap->park_req_pending,
3135 deadline - now); 3125 deadline - now);
3136 } while (deadline); 3126 } while (deadline);
3137 ata_port_for_each_link(link, ap) { 3127 ata_for_each_link(link, ap, EDGE) {
3138 ata_link_for_each_dev(dev, link) { 3128 ata_for_each_dev(dev, link, ALL) {
3139 if (!(link->eh_context.unloaded_mask & 3129 if (!(link->eh_context.unloaded_mask &
3140 (1 << dev->devno))) 3130 (1 << dev->devno)))
3141 continue; 3131 continue;
@@ -3146,7 +3136,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3146 } 3136 }
3147 3137
3148 /* the rest */ 3138 /* the rest */
3149 ata_port_for_each_link(link, ap) { 3139 ata_for_each_link(link, ap, EDGE) {
3150 struct ata_eh_context *ehc = &link->eh_context; 3140 struct ata_eh_context *ehc = &link->eh_context;
3151 3141
3152 /* revalidate existing devices and attach new ones */ 3142 /* revalidate existing devices and attach new ones */
@@ -3172,7 +3162,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3172 * disrupting the current users of the device. 3162 * disrupting the current users of the device.
3173 */ 3163 */
3174 if (ehc->i.flags & ATA_EHI_DID_RESET) { 3164 if (ehc->i.flags & ATA_EHI_DID_RESET) {
3175 ata_link_for_each_dev(dev, link) { 3165 ata_for_each_dev(dev, link, ALL) {
3176 if (dev->class != ATA_DEV_ATAPI) 3166 if (dev->class != ATA_DEV_ATAPI)
3177 continue; 3167 continue;
3178 rc = atapi_eh_clear_ua(dev); 3168 rc = atapi_eh_clear_ua(dev);
@@ -3183,7 +3173,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3183 3173
3184 /* configure link power saving */ 3174 /* configure link power saving */
3185 if (ehc->i.action & ATA_EH_LPM) 3175 if (ehc->i.action & ATA_EH_LPM)
3186 ata_link_for_each_dev(dev, link) 3176 ata_for_each_dev(dev, link, ALL)
3187 ata_dev_enable_pm(dev, ap->pm_policy); 3177 ata_dev_enable_pm(dev, ap->pm_policy);
3188 3178
3189 /* this link is okay now */ 3179 /* this link is okay now */
@@ -3288,7 +3278,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
3288 rc = ata_eh_recover(ap, prereset, softreset, hardreset, postreset, 3278 rc = ata_eh_recover(ap, prereset, softreset, hardreset, postreset,
3289 NULL); 3279 NULL);
3290 if (rc) { 3280 if (rc) {
3291 ata_link_for_each_dev(dev, &ap->link) 3281 ata_for_each_dev(dev, &ap->link, ALL)
3292 ata_dev_disable(dev); 3282 ata_dev_disable(dev);
3293 } 3283 }
3294 3284
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index b65db309c181..98ca07a2db87 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -321,7 +321,7 @@ static void sata_pmp_quirks(struct ata_port *ap)
321 321
322 if (vendor == 0x1095 && devid == 0x3726) { 322 if (vendor == 0x1095 && devid == 0x3726) {
323 /* sil3726 quirks */ 323 /* sil3726 quirks */
324 ata_port_for_each_link(link, ap) { 324 ata_for_each_link(link, ap, EDGE) {
325 /* Class code report is unreliable and SRST 325 /* Class code report is unreliable and SRST
326 * times out under certain configurations. 326 * times out under certain configurations.
327 */ 327 */
@@ -336,7 +336,7 @@ static void sata_pmp_quirks(struct ata_port *ap)
336 } 336 }
337 } else if (vendor == 0x1095 && devid == 0x4723) { 337 } else if (vendor == 0x1095 && devid == 0x4723) {
338 /* sil4723 quirks */ 338 /* sil4723 quirks */
339 ata_port_for_each_link(link, ap) { 339 ata_for_each_link(link, ap, EDGE) {
340 /* class code report is unreliable */ 340 /* class code report is unreliable */
341 if (link->pmp < 2) 341 if (link->pmp < 2)
342 link->flags |= ATA_LFLAG_ASSUME_ATA; 342 link->flags |= ATA_LFLAG_ASSUME_ATA;
@@ -348,7 +348,7 @@ static void sata_pmp_quirks(struct ata_port *ap)
348 } 348 }
349 } else if (vendor == 0x1095 && devid == 0x4726) { 349 } else if (vendor == 0x1095 && devid == 0x4726) {
350 /* sil4726 quirks */ 350 /* sil4726 quirks */
351 ata_port_for_each_link(link, ap) { 351 ata_for_each_link(link, ap, EDGE) {
352 /* Class code report is unreliable and SRST 352 /* Class code report is unreliable and SRST
353 * times out under certain configurations. 353 * times out under certain configurations.
354 * Config device can be at port 0 or 5 and 354 * Config device can be at port 0 or 5 and
@@ -450,7 +450,7 @@ int sata_pmp_attach(struct ata_device *dev)
450 if (ap->ops->pmp_attach) 450 if (ap->ops->pmp_attach)
451 ap->ops->pmp_attach(ap); 451 ap->ops->pmp_attach(ap);
452 452
453 ata_port_for_each_link(tlink, ap) 453 ata_for_each_link(tlink, ap, EDGE)
454 sata_link_init_spd(tlink); 454 sata_link_init_spd(tlink);
455 455
456 ata_acpi_associate_sata_port(ap); 456 ata_acpi_associate_sata_port(ap);
@@ -487,7 +487,7 @@ static void sata_pmp_detach(struct ata_device *dev)
487 if (ap->ops->pmp_detach) 487 if (ap->ops->pmp_detach)
488 ap->ops->pmp_detach(ap); 488 ap->ops->pmp_detach(ap);
489 489
490 ata_port_for_each_link(tlink, ap) 490 ata_for_each_link(tlink, ap, EDGE)
491 ata_eh_detach_dev(tlink->device); 491 ata_eh_detach_dev(tlink->device);
492 492
493 spin_lock_irqsave(ap->lock, flags); 493 spin_lock_irqsave(ap->lock, flags);
@@ -700,7 +700,7 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
700 } 700 }
701 701
702 /* PMP is reset, SErrors cannot be trusted, scan all */ 702 /* PMP is reset, SErrors cannot be trusted, scan all */
703 ata_port_for_each_link(tlink, ap) { 703 ata_for_each_link(tlink, ap, EDGE) {
704 struct ata_eh_context *ehc = &tlink->eh_context; 704 struct ata_eh_context *ehc = &tlink->eh_context;
705 705
706 ehc->i.probe_mask |= ATA_ALL_DEVICES; 706 ehc->i.probe_mask |= ATA_ALL_DEVICES;
@@ -768,7 +768,7 @@ static int sata_pmp_eh_handle_disabled_links(struct ata_port *ap)
768 768
769 spin_lock_irqsave(ap->lock, flags); 769 spin_lock_irqsave(ap->lock, flags);
770 770
771 ata_port_for_each_link(link, ap) { 771 ata_for_each_link(link, ap, EDGE) {
772 if (!(link->flags & ATA_LFLAG_DISABLED)) 772 if (!(link->flags & ATA_LFLAG_DISABLED))
773 continue; 773 continue;
774 774
@@ -852,7 +852,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
852 int cnt, rc; 852 int cnt, rc;
853 853
854 pmp_tries = ATA_EH_PMP_TRIES; 854 pmp_tries = ATA_EH_PMP_TRIES;
855 ata_port_for_each_link(link, ap) 855 ata_for_each_link(link, ap, EDGE)
856 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES; 856 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
857 857
858 retry: 858 retry:
@@ -861,7 +861,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
861 rc = ata_eh_recover(ap, ops->prereset, ops->softreset, 861 rc = ata_eh_recover(ap, ops->prereset, ops->softreset,
862 ops->hardreset, ops->postreset, NULL); 862 ops->hardreset, ops->postreset, NULL);
863 if (rc) { 863 if (rc) {
864 ata_link_for_each_dev(dev, &ap->link) 864 ata_for_each_dev(dev, &ap->link, ALL)
865 ata_dev_disable(dev); 865 ata_dev_disable(dev);
866 return rc; 866 return rc;
867 } 867 }
@@ -870,7 +870,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
870 return 0; 870 return 0;
871 871
872 /* new PMP online */ 872 /* new PMP online */
873 ata_port_for_each_link(link, ap) 873 ata_for_each_link(link, ap, EDGE)
874 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES; 874 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
875 875
876 /* fall through */ 876 /* fall through */
@@ -942,7 +942,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
942 } 942 }
943 943
944 cnt = 0; 944 cnt = 0;
945 ata_port_for_each_link(link, ap) { 945 ata_for_each_link(link, ap, EDGE) {
946 if (!(gscr_error & (1 << link->pmp))) 946 if (!(gscr_error & (1 << link->pmp)))
947 continue; 947 continue;
948 948
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 47c7afcb36f2..0b2e14f67655 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -3229,12 +3229,12 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
3229 return; 3229 return;
3230 3230
3231 repeat: 3231 repeat:
3232 ata_port_for_each_link(link, ap) { 3232 ata_for_each_link(link, ap, EDGE) {
3233 ata_link_for_each_dev(dev, link) { 3233 ata_for_each_dev(dev, link, ENABLED) {
3234 struct scsi_device *sdev; 3234 struct scsi_device *sdev;
3235 int channel = 0, id = 0; 3235 int channel = 0, id = 0;
3236 3236
3237 if (!ata_dev_enabled(dev) || dev->sdev) 3237 if (dev->sdev)
3238 continue; 3238 continue;
3239 3239
3240 if (ata_is_host_link(link)) 3240 if (ata_is_host_link(link))
@@ -3255,9 +3255,9 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
3255 * failure occurred, scan would have failed silently. Check 3255 * failure occurred, scan would have failed silently. Check
3256 * whether all devices are attached. 3256 * whether all devices are attached.
3257 */ 3257 */
3258 ata_port_for_each_link(link, ap) { 3258 ata_for_each_link(link, ap, EDGE) {
3259 ata_link_for_each_dev(dev, link) { 3259 ata_for_each_dev(dev, link, ENABLED) {
3260 if (ata_dev_enabled(dev) && !dev->sdev) 3260 if (!dev->sdev)
3261 goto exit_loop; 3261 goto exit_loop;
3262 } 3262 }
3263 } 3263 }
@@ -3381,7 +3381,7 @@ static void ata_scsi_handle_link_detach(struct ata_link *link)
3381 struct ata_port *ap = link->ap; 3381 struct ata_port *ap = link->ap;
3382 struct ata_device *dev; 3382 struct ata_device *dev;
3383 3383
3384 ata_link_for_each_dev(dev, link) { 3384 ata_for_each_dev(dev, link, ALL) {
3385 unsigned long flags; 3385 unsigned long flags;
3386 3386
3387 if (!(dev->flags & ATA_DFLAG_DETACHED)) 3387 if (!(dev->flags & ATA_DFLAG_DETACHED))
@@ -3496,7 +3496,7 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
3496 if (devno == SCAN_WILD_CARD) { 3496 if (devno == SCAN_WILD_CARD) {
3497 struct ata_link *link; 3497 struct ata_link *link;
3498 3498
3499 ata_port_for_each_link(link, ap) { 3499 ata_for_each_link(link, ap, EDGE) {
3500 struct ata_eh_info *ehi = &link->eh_info; 3500 struct ata_eh_info *ehi = &link->eh_info;
3501 ehi->probe_mask |= ATA_ALL_DEVICES; 3501 ehi->probe_mask |= ATA_ALL_DEVICES;
3502 ehi->action |= ATA_EH_RESET; 3502 ehi->action |= ATA_EH_RESET;
@@ -3544,11 +3544,11 @@ void ata_scsi_dev_rescan(struct work_struct *work)
3544 3544
3545 spin_lock_irqsave(ap->lock, flags); 3545 spin_lock_irqsave(ap->lock, flags);
3546 3546
3547 ata_port_for_each_link(link, ap) { 3547 ata_for_each_link(link, ap, EDGE) {
3548 ata_link_for_each_dev(dev, link) { 3548 ata_for_each_dev(dev, link, ENABLED) {
3549 struct scsi_device *sdev = dev->sdev; 3549 struct scsi_device *sdev = dev->sdev;
3550 3550
3551 if (!ata_dev_enabled(dev) || !sdev) 3551 if (!sdev)
3552 continue; 3552 continue;
3553 if (scsi_device_get(sdev)) 3553 if (scsi_device_get(sdev))
3554 continue; 3554 continue;
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 860ede526282..f828a29d7756 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -465,24 +465,22 @@ static int it821x_smart_set_mode(struct ata_link *link, struct ata_device **unus
465{ 465{
466 struct ata_device *dev; 466 struct ata_device *dev;
467 467
468 ata_link_for_each_dev(dev, link) { 468 ata_for_each_dev(dev, link, ENABLED) {
469 if (ata_dev_enabled(dev)) { 469 /* We don't really care */
470 /* We don't really care */ 470 dev->pio_mode = XFER_PIO_0;
471 dev->pio_mode = XFER_PIO_0; 471 dev->dma_mode = XFER_MW_DMA_0;
472 dev->dma_mode = XFER_MW_DMA_0; 472 /* We do need the right mode information for DMA or PIO
473 /* We do need the right mode information for DMA or PIO 473 and this comes from the current configuration flags */
474 and this comes from the current configuration flags */ 474 if (ata_id_has_dma(dev->id)) {
475 if (ata_id_has_dma(dev->id)) { 475 ata_dev_printk(dev, KERN_INFO, "configured for DMA\n");
476 ata_dev_printk(dev, KERN_INFO, "configured for DMA\n"); 476 dev->xfer_mode = XFER_MW_DMA_0;
477 dev->xfer_mode = XFER_MW_DMA_0; 477 dev->xfer_shift = ATA_SHIFT_MWDMA;
478 dev->xfer_shift = ATA_SHIFT_MWDMA; 478 dev->flags &= ~ATA_DFLAG_PIO;
479 dev->flags &= ~ATA_DFLAG_PIO; 479 } else {
480 } else { 480 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
481 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n"); 481 dev->xfer_mode = XFER_PIO_0;
482 dev->xfer_mode = XFER_PIO_0; 482 dev->xfer_shift = ATA_SHIFT_PIO;
483 dev->xfer_shift = ATA_SHIFT_PIO; 483 dev->flags |= ATA_DFLAG_PIO;
484 dev->flags |= ATA_DFLAG_PIO;
485 }
486 } 484 }
487 } 485 }
488 return 0; 486 return 0;
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index 2014253f6c88..b173c157ab00 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -30,14 +30,12 @@ static int ixp4xx_set_mode(struct ata_link *link, struct ata_device **error)
30{ 30{
31 struct ata_device *dev; 31 struct ata_device *dev;
32 32
33 ata_link_for_each_dev(dev, link) { 33 ata_for_each_dev(dev, link, ENABLED) {
34 if (ata_dev_enabled(dev)) { 34 ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n");
35 ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n"); 35 dev->pio_mode = XFER_PIO_0;
36 dev->pio_mode = XFER_PIO_0; 36 dev->xfer_mode = XFER_PIO_0;
37 dev->xfer_mode = XFER_PIO_0; 37 dev->xfer_shift = ATA_SHIFT_PIO;
38 dev->xfer_shift = ATA_SHIFT_PIO; 38 dev->flags |= ATA_DFLAG_PIO;
39 dev->flags |= ATA_DFLAG_PIO;
40 }
41 } 39 }
42 return 0; 40 return 0;
43} 41}
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index 930c2208640b..cbd98c16eea4 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -194,15 +194,12 @@ static int legacy_set_mode(struct ata_link *link, struct ata_device **unused)
194{ 194{
195 struct ata_device *dev; 195 struct ata_device *dev;
196 196
197 ata_link_for_each_dev(dev, link) { 197 ata_for_each_dev(dev, link, ENABLED) {
198 if (ata_dev_enabled(dev)) { 198 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
199 ata_dev_printk(dev, KERN_INFO, 199 dev->pio_mode = XFER_PIO_0;
200 "configured for PIO\n"); 200 dev->xfer_mode = XFER_PIO_0;
201 dev->pio_mode = XFER_PIO_0; 201 dev->xfer_shift = ATA_SHIFT_PIO;
202 dev->xfer_mode = XFER_PIO_0; 202 dev->flags |= ATA_DFLAG_PIO;
203 dev->xfer_shift = ATA_SHIFT_PIO;
204 dev->flags |= ATA_DFLAG_PIO;
205 }
206 } 203 }
207 return 0; 204 return 0;
208} 205}
@@ -1028,7 +1025,7 @@ static __init int legacy_init_one(struct legacy_probe *probe)
1028 /* Nothing found means we drop the port as its probably not there */ 1025 /* Nothing found means we drop the port as its probably not there */
1029 1026
1030 ret = -ENODEV; 1027 ret = -ENODEV;
1031 ata_link_for_each_dev(dev, &ap->link) { 1028 ata_for_each_dev(dev, &ap->link, ALL) {
1032 if (!ata_dev_absent(dev)) { 1029 if (!ata_dev_absent(dev)) {
1033 legacy_host[probe->slot] = host; 1030 legacy_host[probe->slot] = host;
1034 ld->platform_dev = pdev; 1031 ld->platform_dev = pdev;
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index 0e1c2c1134d3..d43e8be96b88 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -406,23 +406,20 @@ static int pdc2027x_set_mode(struct ata_link *link, struct ata_device **r_failed
406 if (rc < 0) 406 if (rc < 0)
407 return rc; 407 return rc;
408 408
409 ata_link_for_each_dev(dev, link) { 409 ata_for_each_dev(dev, link, ENABLED) {
410 if (ata_dev_enabled(dev)) { 410 pdc2027x_set_piomode(ap, dev);
411 411
412 pdc2027x_set_piomode(ap, dev); 412 /*
413 413 * Enable prefetch if the device support PIO only.
414 /* 414 */
415 * Enable prefetch if the device support PIO only. 415 if (dev->xfer_shift == ATA_SHIFT_PIO) {
416 */ 416 u32 ctcr1 = ioread32(dev_mmio(ap, dev, PDC_CTCR1));
417 if (dev->xfer_shift == ATA_SHIFT_PIO) { 417 ctcr1 |= (1 << 25);
418 u32 ctcr1 = ioread32(dev_mmio(ap, dev, PDC_CTCR1)); 418 iowrite32(ctcr1, dev_mmio(ap, dev, PDC_CTCR1));
419 ctcr1 |= (1 << 25); 419
420 iowrite32(ctcr1, dev_mmio(ap, dev, PDC_CTCR1)); 420 PDPRINTK("Turn on prefetch\n");
421 421 } else {
422 PDPRINTK("Turn on prefetch\n"); 422 pdc2027x_set_dmamode(ap, dev);
423 } else {
424 pdc2027x_set_dmamode(ap, dev);
425 }
426 } 423 }
427 } 424 }
428 return 0; 425 return 0;
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 77e4e3b17f54..6afa07a37648 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -34,14 +34,12 @@ static int pata_platform_set_mode(struct ata_link *link, struct ata_device **unu
34{ 34{
35 struct ata_device *dev; 35 struct ata_device *dev;
36 36
37 ata_link_for_each_dev(dev, link) { 37 ata_for_each_dev(dev, link, ENABLED) {
38 if (ata_dev_enabled(dev)) { 38 /* We don't really care */
39 /* We don't really care */ 39 dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
40 dev->pio_mode = dev->xfer_mode = XFER_PIO_0; 40 dev->xfer_shift = ATA_SHIFT_PIO;
41 dev->xfer_shift = ATA_SHIFT_PIO; 41 dev->flags |= ATA_DFLAG_PIO;
42 dev->flags |= ATA_DFLAG_PIO; 42 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
43 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
44 }
45 } 43 }
46 return 0; 44 return 0;
47} 45}
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 7dfd1f3f6f3a..46d6bc1bf1e9 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -38,15 +38,13 @@ static int rz1000_set_mode(struct ata_link *link, struct ata_device **unused)
38{ 38{
39 struct ata_device *dev; 39 struct ata_device *dev;
40 40
41 ata_link_for_each_dev(dev, link) { 41 ata_for_each_dev(dev, link, ENABLED) {
42 if (ata_dev_enabled(dev)) { 42 /* We don't really care */
43 /* We don't really care */ 43 dev->pio_mode = XFER_PIO_0;
44 dev->pio_mode = XFER_PIO_0; 44 dev->xfer_mode = XFER_PIO_0;
45 dev->xfer_mode = XFER_PIO_0; 45 dev->xfer_shift = ATA_SHIFT_PIO;
46 dev->xfer_shift = ATA_SHIFT_PIO; 46 dev->flags |= ATA_DFLAG_PIO;
47 dev->flags |= ATA_DFLAG_PIO; 47 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
48 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
49 }
50 } 48 }
51 return 0; 49 return 0;
52} 50}
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 031d7b7dee34..177370921774 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -278,7 +278,7 @@ static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed)
278 if (rc) 278 if (rc)
279 return rc; 279 return rc;
280 280
281 ata_link_for_each_dev(dev, link) { 281 ata_for_each_dev(dev, link, ALL) {
282 if (!ata_dev_enabled(dev)) 282 if (!ata_dev_enabled(dev))
283 dev_mode[dev->devno] = 0; /* PIO0/1/2 */ 283 dev_mode[dev->devno] = 0; /* PIO0/1/2 */
284 else if (dev->flags & ATA_DFLAG_PIO) 284 else if (dev->flags & ATA_DFLAG_PIO)
diff --git a/include/linux/libata.h b/include/linux/libata.h
index ed3f26eb5df1..3b2a0c6444ee 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1285,26 +1285,62 @@ static inline int ata_link_active(struct ata_link *link)
1285 return ata_tag_valid(link->active_tag) || link->sactive; 1285 return ata_tag_valid(link->active_tag) || link->sactive;
1286} 1286}
1287 1287
1288extern struct ata_link *__ata_port_next_link(struct ata_port *ap, 1288/*
1289 struct ata_link *link, 1289 * Iterators
1290 bool dev_only); 1290 *
1291 1291 * ATA_LITER_* constants are used to select link iteration mode and
1292#define __ata_port_for_each_link(link, ap) \ 1292 * ATA_DITER_* device iteration mode.
1293 for ((link) = __ata_port_next_link((ap), NULL, false); (link); \ 1293 *
1294 (link) = __ata_port_next_link((ap), (link), false)) 1294 * For a custom iteration directly using ata_{link|dev}_next(), if
1295 1295 * @link or @dev, respectively, is NULL, the first element is
1296#define ata_port_for_each_link(link, ap) \ 1296 * returned. @dev and @link can be any valid device or link and the
1297 for ((link) = __ata_port_next_link((ap), NULL, true); (link); \ 1297 * next element according to the iteration mode will be returned.
1298 (link) = __ata_port_next_link((ap), (link), true)) 1298 * After the last element, NULL is returned.
1299 1299 */
1300#define ata_link_for_each_dev(dev, link) \ 1300enum ata_link_iter_mode {
1301 for ((dev) = (link)->device; \ 1301 ATA_LITER_EDGE, /* if present, PMP links only; otherwise,
1302 (dev) < (link)->device + ata_link_max_devices(link) || ((dev) = NULL); \ 1302 * host link. no slave link */
1303 (dev)++) 1303 ATA_LITER_HOST_FIRST, /* host link followed by PMP or slave links */
1304 1304 ATA_LITER_PMP_FIRST, /* PMP links followed by host link,
1305#define ata_link_for_each_dev_reverse(dev, link) \ 1305 * slave link still comes after host link */
1306 for ((dev) = (link)->device + ata_link_max_devices(link) - 1; \ 1306};
1307 (dev) >= (link)->device || ((dev) = NULL); (dev)--) 1307
1308enum ata_dev_iter_mode {
1309 ATA_DITER_ENABLED,
1310 ATA_DITER_ENABLED_REVERSE,
1311 ATA_DITER_ALL,
1312 ATA_DITER_ALL_REVERSE,
1313};
1314
1315extern struct ata_link *ata_link_next(struct ata_link *link,
1316 struct ata_port *ap,
1317 enum ata_link_iter_mode mode);
1318
1319extern struct ata_device *ata_dev_next(struct ata_device *dev,
1320 struct ata_link *link,
1321 enum ata_dev_iter_mode mode);
1322
1323/*
1324 * Shortcut notation for iterations
1325 *
1326 * ata_for_each_link() iterates over each link of @ap according to
1327 * @mode. @link points to the current link in the loop. @link is
1328 * NULL after loop termination. ata_for_each_dev() works the same way
1329 * except that it iterates over each device of @link.
1330 *
1331 * Note that the mode prefixes ATA_{L|D}ITER_ shouldn't need to be
1332 * specified when using the following shorthand notations. Only the
1333 * mode itself (EDGE, HOST_FIRST, ENABLED, etc...) should be
1334 * specified. This not only increases brevity but also makes it
1335 * impossible to use ATA_LITER_* for device iteration or vice-versa.
1336 */
1337#define ata_for_each_link(link, ap, mode) \
1338 for ((link) = ata_link_next(NULL, (ap), ATA_LITER_##mode); (link); \
1339 (link) = ata_link_next((link), (ap), ATA_LITER_##mode))
1340
1341#define ata_for_each_dev(dev, link, mode) \
1342 for ((dev) = ata_dev_next(NULL, (link), ATA_DITER_##mode); (dev); \
1343 (dev) = ata_dev_next((dev), (link), ATA_DITER_##mode))
1308 1344
1309/** 1345/**
1310 * ata_ncq_enabled - Test whether NCQ is enabled 1346 * ata_ncq_enabled - Test whether NCQ is enabled