From: Tejun Heo <tj@kernel.org>
To: jeff@garzik.org, linux-ide@vger.kernel.org,
alan@lxorguk.ukuu.org.uk, JosephChan@via.com.tw
Cc: Tejun Heo <tj@kernel.org>
Subject: [PATCH 2/5] libata: reimplement link iterator
Date: Thu, 31 Jul 2008 17:02:41 +0900 [thread overview]
Message-ID: <1217491364-19725-3-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1217491364-19725-1-git-send-email-tj@kernel.org>
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>
---
drivers/ata/libata-core.c | 30 ++++++++++++++++++++++++++++++
include/linux/libata.h | 33 ++++++++-------------------------
2 files changed, 38 insertions(+), 25 deletions(-)
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 03151a1..f7049cd 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -162,6 +162,35 @@ MODULE_LICENSE("GPL");
MODULE_VERSION(DRV_VERSION);
+/*
+ * Iterator helpers. Don't use directly.
+ *
+ * LOCKING:
+ * Host lock or EH context.
+ */
+struct ata_link *__ata_port_next_link(struct ata_port *ap,
+ struct ata_link *link, bool dev_only)
+{
+ /* NULL link indicates start of iteration */
+ if (!link) {
+ if (dev_only && sata_pmp_attached(ap))
+ return ap->pmp_link;
+ return &ap->link;
+ }
+
+ /* we just iterated over the host link, what's next? */
+ if (ata_is_host_link(link)) {
+ if (!sata_pmp_attached(ap))
+ return NULL;
+ return ap->pmp_link;
+ }
+
+ /* iterate to the next PMP link */
+ if (++link < ap->pmp_link + ap->nr_pmp_links)
+ return link;
+ return NULL;
+}
+
/**
* ata_force_cbl - force cable type according to libata.force
* @ap: ATA port of interest
@@ -6207,6 +6236,7 @@ EXPORT_SYMBOL_GPL(ata_base_port_ops);
EXPORT_SYMBOL_GPL(sata_port_ops);
EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
EXPORT_SYMBOL_GPL(ata_dummy_port_info);
+EXPORT_SYMBOL_GPL(__ata_port_next_link);
EXPORT_SYMBOL_GPL(ata_std_bios_param);
EXPORT_SYMBOL_GPL(ata_host_init);
EXPORT_SYMBOL_GPL(ata_host_alloc);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 1418a21..42c4b6f 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1261,34 +1261,17 @@ static inline int ata_link_active(struct ata_link *link)
return ata_tag_valid(link->active_tag) || link->sactive;
}
-static inline struct ata_link *ata_port_first_link(struct ata_port *ap)
-{
- if (sata_pmp_attached(ap))
- return ap->pmp_link;
- return &ap->link;
-}
-
-static inline struct ata_link *ata_port_next_link(struct ata_link *link)
-{
- struct ata_port *ap = link->ap;
-
- if (ata_is_host_link(link)) {
- if (!sata_pmp_attached(ap))
- return NULL;
- return ap->pmp_link;
- }
-
- if (++link < ap->nr_pmp_links + ap->pmp_link)
- return link;
- return NULL;
-}
+extern struct ata_link *__ata_port_next_link(struct ata_port *ap,
+ struct ata_link *link,
+ bool dev_only);
-#define __ata_port_for_each_link(lk, ap) \
- for ((lk) = &(ap)->link; (lk); (lk) = ata_port_next_link(lk))
+#define __ata_port_for_each_link(link, ap) \
+ for ((link) = __ata_port_next_link((ap), NULL, false); (link); \
+ (link) = __ata_port_next_link((ap), (link), false))
#define ata_port_for_each_link(link, ap) \
- for ((link) = ata_port_first_link(ap); (link); \
- (link) = ata_port_next_link(link))
+ for ((link) = __ata_port_next_link((ap), NULL, true); (link); \
+ (link) = __ata_port_next_link((ap), (link), true))
#define ata_link_for_each_dev(dev, link) \
for ((dev) = (link)->device; \
--
1.5.4.5
next prev parent reply other threads:[~2008-07-31 8:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-31 8:02 [PATCHSET #upstream] libata: implement slave_link Tejun Heo
2008-07-31 8:02 ` [PATCH 1/5] libata: make SCR access ops per-link Tejun Heo
2008-09-29 4:33 ` Jeff Garzik
2008-07-31 8:02 ` Tejun Heo [this message]
2008-07-31 8:02 ` [PATCH 3/5] libata: misc updates to prepare for slave link Tejun Heo
2008-07-31 8:02 ` [PATCH 4/5] libata: implement slave_link Tejun Heo
2008-07-31 8:02 ` [PATCH 5/5] ata_piix: drop merged SCR access and use slave_link instead Tejun Heo
2008-09-04 10:36 ` Jeff Garzik
2008-09-04 10:36 ` Tejun Heo
2008-08-13 9:41 ` [PATCHSET #upstream] libata: implement slave_link Tejun Heo
2008-08-13 9:45 ` JosephChan
2008-08-13 10:14 ` Tejun Heo
2008-09-04 9:57 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1217491364-19725-3-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=JosephChan@via.com.tw \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=jeff@garzik.org \
--cc=linux-ide@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).