]>
Commit | Line | Data |
---|---|---|
00e5a55c BS |
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 | |
5 | References: bnc#441420 | |
6 | ||
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 | |
10 | to extend. | |
11 | ||
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> | |
15 | --- | |
16 | drivers/ata/libata-core.c | 30 ++++++++++++++++++++++++++++++ | |
17 | include/linux/libata.h | 35 +++++++++-------------------------- | |
18 | 2 files changed, 39 insertions(+), 26 deletions(-) | |
19 | ||
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); | |
24 | ||
25 | ||
26 | +/* | |
27 | + * Iterator helpers. Don't use directly. | |
28 | + * | |
29 | + * LOCKING: | |
30 | + * Host lock or EH context. | |
31 | + */ | |
32 | +struct ata_link *__ata_port_next_link(struct ata_port *ap, | |
33 | + struct ata_link *link, bool dev_only) | |
34 | +{ | |
35 | + /* NULL link indicates start of iteration */ | |
36 | + if (!link) { | |
37 | + if (dev_only && sata_pmp_attached(ap)) | |
38 | + return ap->pmp_link; | |
39 | + return &ap->link; | |
40 | + } | |
41 | + | |
42 | + /* we just iterated over the host link, what's next? */ | |
43 | + if (ata_is_host_link(link)) { | |
44 | + if (!sata_pmp_attached(ap)) | |
45 | + return NULL; | |
46 | + return ap->pmp_link; | |
47 | + } | |
48 | + | |
49 | + /* iterate to the next PMP link */ | |
50 | + if (++link < ap->pmp_link + ap->nr_pmp_links) | |
51 | + return link; | |
52 | + return NULL; | |
53 | +} | |
54 | + | |
55 | /** | |
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; | |
70 | } | |
71 | ||
72 | -static inline struct ata_link *ata_port_first_link(struct ata_port *ap) | |
73 | -{ | |
74 | - if (sata_pmp_attached(ap)) | |
75 | - return ap->pmp_link; | |
76 | - return &ap->link; | |
77 | -} | |
78 | - | |
79 | -static inline struct ata_link *ata_port_next_link(struct ata_link *link) | |
80 | -{ | |
81 | - struct ata_port *ap = link->ap; | |
82 | - | |
83 | - if (ata_is_host_link(link)) { | |
84 | - if (!sata_pmp_attached(ap)) | |
85 | - return NULL; | |
86 | - return ap->pmp_link; | |
87 | - } | |
88 | - | |
89 | - if (++link < ap->nr_pmp_links + ap->pmp_link) | |
90 | - return link; | |
91 | - return NULL; | |
92 | -} | |
93 | - | |
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, | |
98 | + bool dev_only); | |
99 | + | |
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)) | |
103 | ||
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)) | |
109 | ||
110 | #define ata_link_for_each_dev(dev, link) \ | |
111 | for ((dev) = (link)->device; \ |