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>
This commit is contained in:
Tejun Heo
2007-08-06 18:36:23 +09:00
committed by Jeff Garzik
parent 9af5c9c97d
commit f58229f806
13 changed files with 134 additions and 148 deletions

View File

@ -1030,15 +1030,26 @@ static inline unsigned int ata_dev_absent(const struct ata_device *dev)
}
/*
* port helpers
* link helpers
*/
static inline int ata_port_max_devices(const struct ata_port *ap)
static inline int ata_link_max_devices(const struct ata_link *link)
{
if (ap->flags & ATA_FLAG_SLAVE_POSS)
if (link->ap->flags & ATA_FLAG_SLAVE_POSS)
return 2;
return 1;
}
#define ata_port_for_each_link(lk, ap) \
for ((lk) = &(ap)->link; (lk); (lk) = NULL)
#define ata_link_for_each_dev(dev, link) \
for ((dev) = (link)->device; \
(dev) < (link)->device + ata_link_max_devices(link) || ((dev) = NULL); \
(dev)++)
#define ata_link_for_each_dev_reverse(dev, link) \
for ((dev) = (link)->device + ata_link_max_devices(link) - 1; \
(dev) >= (link)->device || ((dev) = NULL); (dev)--)
static inline u8 ata_chk_status(struct ata_port *ap)
{