aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2008-07-31 04:02:41 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-09-29 00:22:30 -0400
commitaadffb682cc5572f48cc24883681db65530bd284 (patch)
tree24ab92ec9b0cdd9e6f4c0bf7a8a4c04635be03db
parent82ef04fb4c82542b3eda81cca461f0594ce9cd0b (diff)
libata: reimplement link iterator
Implement __ata_port_next_link() and reimplement __ata_port_for_each_link() and ata_port_for_each_link() using it. This removes relatively large inlined code and makes iteration easier to extend. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
-rw-r--r--drivers/ata/libata-core.c30
-rw-r--r--include/linux/libata.h33
2 files changed, 38 insertions, 25 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 825461a33abe..d156616f45f5 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -163,6 +163,35 @@ MODULE_LICENSE("GPL");
163MODULE_VERSION(DRV_VERSION); 163MODULE_VERSION(DRV_VERSION);
164 164
165 165
166/*
167 * Iterator helpers. Don't use directly.
168 *
169 * LOCKING:
170 * Host lock or EH context.
171 */
172struct ata_link *__ata_port_next_link(struct ata_port *ap,
173 struct ata_link *link, bool dev_only)
174{
175 /* NULL link indicates start of iteration */
176 if (!link) {
177 if (dev_only && sata_pmp_attached(ap))
178 return ap->pmp_link;
179 return &ap->link;
180 }
181
182 /* we just iterated over the host link, what's next? */
183 if (ata_is_host_link(link)) {
184 if (!sata_pmp_attached(ap))
185 return NULL;
186 return ap->pmp_link;
187 }
188
189 /* iterate to the next PMP link */
190 if (++link < ap->pmp_link + ap->nr_pmp_links)
191 return link;
192 return NULL;
193}
194
166/** 195/**
167 * ata_force_cbl - force cable type according to libata.force 196 * ata_force_cbl - force cable type according to libata.force
168 * @ap: ATA port of interest 197 * @ap: ATA port of interest
@@ -6255,6 +6284,7 @@ EXPORT_SYMBOL_GPL(ata_base_port_ops);
6255EXPORT_SYMBOL_GPL(sata_port_ops); 6284EXPORT_SYMBOL_GPL(sata_port_ops);
6256EXPORT_SYMBOL_GPL(ata_dummy_port_ops); 6285EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
6257EXPORT_SYMBOL_GPL(ata_dummy_port_info); 6286EXPORT_SYMBOL_GPL(ata_dummy_port_info);
6287EXPORT_SYMBOL_GPL(__ata_port_next_link);
6258EXPORT_SYMBOL_GPL(ata_std_bios_param); 6288EXPORT_SYMBOL_GPL(ata_std_bios_param);
6259EXPORT_SYMBOL_GPL(ata_host_init); 6289EXPORT_SYMBOL_GPL(ata_host_init);
6260EXPORT_SYMBOL_GPL(ata_host_alloc); 6290EXPORT_SYMBOL_GPL(ata_host_alloc);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index ffd622fa319c..3eaca347ce29 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1265,34 +1265,17 @@ static inline int ata_link_active(struct ata_link *link)
1265 return ata_tag_valid(link->active_tag) || link->sactive; 1265 return ata_tag_valid(link->active_tag) || link->sactive;
1266} 1266}
1267 1267
1268static inline struct ata_link *ata_port_first_link(struct ata_port *ap) 1268extern struct ata_link *__ata_port_next_link(struct ata_port *ap,
1269{ 1269 struct ata_link *link,
1270 if (sata_pmp_attached(ap)) 1270 bool dev_only);
1271 return ap->pmp_link;
1272 return &ap->link;
1273}
1274
1275static inline struct ata_link *ata_port_next_link(struct ata_link *link)
1276{
1277 struct ata_port *ap = link->ap;
1278
1279 if (ata_is_host_link(link)) {
1280 if (!sata_pmp_attached(ap))
1281 return NULL;
1282 return ap->pmp_link;
1283 }
1284
1285 if (++link < ap->nr_pmp_links + ap->pmp_link)
1286 return link;
1287 return NULL;
1288}
1289 1271
1290#define __ata_port_for_each_link(lk, ap) \ 1272#define __ata_port_for_each_link(link, ap) \
1291 for ((lk) = &(ap)->link; (lk); (lk) = ata_port_next_link(lk)) 1273 for ((link) = __ata_port_next_link((ap), NULL, false); (link); \
1274 (link) = __ata_port_next_link((ap), (link), false))
1292 1275
1293#define ata_port_for_each_link(link, ap) \ 1276#define ata_port_for_each_link(link, ap) \
1294 for ((link) = ata_port_first_link(ap); (link); \ 1277 for ((link) = __ata_port_next_link((ap), NULL, true); (link); \
1295 (link) = ata_port_next_link(link)) 1278 (link) = __ata_port_next_link((ap), (link), true))
1296 1279
1297#define ata_link_for_each_dev(dev, link) \ 1280#define ata_link_for_each_dev(dev, link) \
1298 for ((dev) = (link)->device; \ 1281 for ((dev) = (link)->device; \