1 From aadffb682cc5572f48cc24883681db65530bd284 Mon Sep 17 00:00:00 2001
2 From: Tejun Heo <tj@kernel.org>
3 Date: Thu, 31 Jul 2008 17:02:41 +0900
4 Subject: [PATCH] libata: reimplement link iterator
7 Implement __ata_port_next_link() and reimplement
8 __ata_port_for_each_link() and ata_port_for_each_link() using it.
9 This removes relatively large inlined code and makes iteration easier
12 Signed-off-by: Tejun Heo <tj@kernel.org>
13 Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
14 Signed-off-by: Tejun Heo <teheo@suse.de>
16 drivers/ata/libata-core.c | 30 ++++++++++++++++++++++++++++++
17 include/linux/libata.h | 35 +++++++++--------------------------
18 2 files changed, 39 insertions(+), 26 deletions(-)
20 --- a/drivers/ata/libata-core.c
21 +++ b/drivers/ata/libata-core.c
22 @@ -163,6 +163,35 @@ MODULE_LICENSE("GPL");
23 MODULE_VERSION(DRV_VERSION);
27 + * Iterator helpers. Don't use directly.
30 + * Host lock or EH context.
32 +struct ata_link *__ata_port_next_link(struct ata_port *ap,
33 + struct ata_link *link, bool dev_only)
35 + /* NULL link indicates start of iteration */
37 + if (dev_only && sata_pmp_attached(ap))
38 + return ap->pmp_link;
42 + /* we just iterated over the host link, what's next? */
43 + if (ata_is_host_link(link)) {
44 + if (!sata_pmp_attached(ap))
46 + return ap->pmp_link;
49 + /* iterate to the next PMP link */
50 + if (++link < ap->pmp_link + ap->nr_pmp_links)
56 * ata_force_cbl - force cable type according to libata.force
57 * @ap: ATA port of interest
58 @@ -6333,6 +6362,7 @@ EXPORT_SYMBOL_GPL(ata_base_port_ops);
59 EXPORT_SYMBOL_GPL(sata_port_ops);
60 EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
61 EXPORT_SYMBOL_GPL(ata_dummy_port_info);
62 +EXPORT_SYMBOL_GPL(__ata_port_next_link);
63 EXPORT_SYMBOL_GPL(ata_std_bios_param);
64 EXPORT_SYMBOL_GPL(ata_host_init);
65 EXPORT_SYMBOL_GPL(ata_host_alloc);
66 --- a/include/linux/libata.h
67 +++ b/include/linux/libata.h
68 @@ -1266,34 +1266,17 @@ static inline int ata_link_active(struct
69 return ata_tag_valid(link->active_tag) || link->sactive;
72 -static inline struct ata_link *ata_port_first_link(struct ata_port *ap)
74 - if (sata_pmp_attached(ap))
75 - return ap->pmp_link;
79 -static inline struct ata_link *ata_port_next_link(struct ata_link *link)
81 - struct ata_port *ap = link->ap;
83 - if (ata_is_host_link(link)) {
84 - if (!sata_pmp_attached(ap))
86 - return ap->pmp_link;
89 - if (++link < ap->nr_pmp_links + ap->pmp_link)
94 -#define __ata_port_for_each_link(lk, ap) \
95 - for ((lk) = &(ap)->link; (lk); (lk) = ata_port_next_link(lk))
96 +extern struct ata_link *__ata_port_next_link(struct ata_port *ap,
97 + struct ata_link *link,
100 +#define __ata_port_for_each_link(link, ap) \
101 + for ((link) = __ata_port_next_link((ap), NULL, false); (link); \
102 + (link) = __ata_port_next_link((ap), (link), false))
104 #define ata_port_for_each_link(link, ap) \
105 - for ((link) = ata_port_first_link(ap); (link); \
106 - (link) = ata_port_next_link(link))
107 + for ((link) = __ata_port_next_link((ap), NULL, true); (link); \
108 + (link) = __ata_port_next_link((ap), (link), true))
110 #define ata_link_for_each_dev(dev, link) \
111 for ((dev) = (link)->device; \