Skip to content

Commit

Permalink
libata: beef up iterators
Browse files Browse the repository at this point in the history
There currently are the following looping constructs.

* __ata_port_for_each_link() for all available links
* ata_port_for_each_link() for edge links
* ata_link_for_each_dev() for all devices
* ata_link_for_each_dev_reverse() for all devices in reverse order

Now there's a need for looping construct which is similar to
__ata_port_for_each_link() but iterates over PMP links before the host
link.  Instead of adding another one with long name, do the following
cleanup.

* Implement and export ata_link_next() and ata_dev_next() which take
  @mode parameter and can be used to build custom loop.
* Implement ata_for_each_link() and ata_for_each_dev() which take
  looping mode explicitly.

The following iteration modes are implemented.

* ATA_LITER_EDGE		: loop over edge links
* ATA_LITER_HOST_FIRST		: loop over all links, host link first
* ATA_LITER_PMP_FIRST		: loop over all links, PMP links first

* ATA_DITER_ENABLED		: loop over enabled devices
* ATA_DITER_ENABLED_REVERSE	: loop over enabled devices in reverse order
* ATA_DITER_ALL			: loop over all devices
* ATA_DITER_ALL_REVERSE		: loop over all devices in reverse order

This change removes exlicit device enabledness checks from many loops
and makes it clear which ones are iterated over in which direction.

Signed-off-by: Tejun Heo <[email protected]>
Signed-off-by: Jeff Garzik <[email protected]>
  • Loading branch information
htejun authored and Jeff Garzik committed Dec 29, 2008
1 parent 3c92ec8 commit 1eca436
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 240 deletions.
8 changes: 4 additions & 4 deletions drivers/ata/ahci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1119,14 +1119,14 @@ static void ahci_start_port(struct ata_port *ap)

/* turn on LEDs */
if (ap->flags & ATA_FLAG_EM) {
ata_port_for_each_link(link, ap) {
ata_for_each_link(link, ap, EDGE) {
emp = &pp->em_priv[link->pmp];
ahci_transmit_led_message(ap, emp->led_state, 4);
}
}

if (ap->flags & ATA_FLAG_SW_ACTIVITY)
ata_port_for_each_link(link, ap)
ata_for_each_link(link, ap, EDGE)
ahci_init_sw_activity(link);

}
Expand Down Expand Up @@ -1361,7 +1361,7 @@ static ssize_t ahci_led_show(struct ata_port *ap, char *buf)
struct ahci_em_priv *emp;
int rc = 0;

ata_port_for_each_link(link, ap) {
ata_for_each_link(link, ap, EDGE) {
emp = &pp->em_priv[link->pmp];
rc += sprintf(buf, "%lx\n", emp->led_state);
}
Expand Down Expand Up @@ -1941,7 +1941,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
u32 serror;

/* determine active link */
ata_port_for_each_link(link, ap)
ata_for_each_link(link, ap, EDGE)
if (ata_link_active(link))
break;
if (!link)
Expand Down
5 changes: 1 addition & 4 deletions drivers/ata/ata_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
if (pdev->vendor == PCI_VENDOR_ID_CENATEK)
dma_enabled = 0xFF;

ata_link_for_each_dev(dev, link) {
if (!ata_dev_enabled(dev))
continue;

ata_for_each_dev(dev, link, ENABLED) {
/* We don't really care */
dev->pio_mode = XFER_PIO_0;
dev->dma_mode = XFER_MW_DMA_0;
Expand Down
19 changes: 8 additions & 11 deletions drivers/ata/libata-acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void ata_acpi_associate_sata_port(struct ata_port *ap)

ap->link.device->acpi_handle = NULL;

ata_port_for_each_link(link, ap) {
ata_for_each_link(link, ap, EDGE) {
acpi_integer adr = SATA_ADR(ap->port_no, link->pmp);

link->device->acpi_handle =
Expand Down Expand Up @@ -129,8 +129,8 @@ static void ata_acpi_detach_device(struct ata_port *ap, struct ata_device *dev)
struct ata_link *tlink;
struct ata_device *tdev;

ata_port_for_each_link(tlink, ap)
ata_link_for_each_dev(tdev, tlink)
ata_for_each_link(tlink, ap, EDGE)
ata_for_each_dev(tdev, tlink, ALL)
tdev->flags |= ATA_DFLAG_DETACH;
}

Expand Down Expand Up @@ -588,12 +588,9 @@ int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm)
{
struct ata_device *dev;

ata_link_for_each_dev(dev, &ap->link) {
ata_for_each_dev(dev, &ap->link, ENABLED) {
unsigned long xfer_mask, udma_mask;

if (!ata_dev_enabled(dev))
continue;

xfer_mask = ata_acpi_gtm_xfermask(dev, gtm);
ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask);

Expand Down Expand Up @@ -893,7 +890,7 @@ void ata_acpi_on_resume(struct ata_port *ap)
* use values set by _STM. Cache _GTF result and
* schedule _GTF.
*/
ata_link_for_each_dev(dev, &ap->link) {
ata_for_each_dev(dev, &ap->link, ALL) {
ata_acpi_clear_gtf(dev);
if (ata_dev_enabled(dev) &&
ata_dev_get_GTF(dev, NULL) >= 0)
Expand All @@ -904,7 +901,7 @@ void ata_acpi_on_resume(struct ata_port *ap)
* there's no reason to evaluate IDE _GTF early
* without _STM. Clear cache and schedule _GTF.
*/
ata_link_for_each_dev(dev, &ap->link) {
ata_for_each_dev(dev, &ap->link, ALL) {
ata_acpi_clear_gtf(dev);
if (ata_dev_enabled(dev))
dev->flags |= ATA_DFLAG_ACPI_PENDING;
Expand Down Expand Up @@ -932,8 +929,8 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
if (state.event == PM_EVENT_ON)
acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);

ata_link_for_each_dev(dev, &ap->link) {
if (dev->acpi_handle && ata_dev_enabled(dev))
ata_for_each_dev(dev, &ap->link, ENABLED) {
if (dev->acpi_handle)
acpi_bus_set_power(dev->acpi_handle,
state.event == PM_EVENT_ON ?
ACPI_STATE_D0 : ACPI_STATE_D3);
Expand Down
Loading

0 comments on commit 1eca436

Please sign in to comment.