From: Tejun Heo <htejun@gmail.com>
To: Jeff Garzik <jeff@garzik.org>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
linux-ide@vger.kernel.org, Forrest Zhao <forrest.zhao@gmail.com>
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 08/14] libata-link: separate out link initialization functions
Date: Mon, 16 Jul 2007 18:34:40 +0900 [thread overview]
Message-ID: <1184578480953-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11845784783033-git-send-email-htejun@gmail.com>
Separate out link initialization into ata_link_init() and
ata_link_init_sata_spd().
Signed-off-by: Tejun Heo <htejun@gmail.com>
---
drivers/ata/libata-core.c | 84 ++++++++++++++++++++++++++++++++++-----------
1 files changed, 64 insertions(+), 20 deletions(-)
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index f580903..bb6405c 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -6039,6 +6039,68 @@ void ata_dev_init(struct ata_device *dev)
}
/**
+ * ata_link_init - Initialize an ata_link structure
+ * @ap: ATA port link is attached to
+ * @link: Link structure to initialize
+ *
+ * Initialize @link.
+ *
+ * LOCKING:
+ * Kernel thread context (may sleep)
+ */
+static void ata_link_init(struct ata_port *ap, struct ata_link *link)
+{
+ int i;
+
+ /* clear everything except for devices */
+ memset(link, 0, offsetof(struct ata_link, device[0]));
+
+ link->ap = ap;
+ link->active_tag = ATA_TAG_POISON;
+ link->hw_sata_spd_limit = UINT_MAX;
+
+ /* can't use iterator, ap isn't initialized yet */
+ for (i = 0; i < ATA_MAX_DEVICES; i++) {
+ struct ata_device *dev = &link->device[i];
+
+ dev->link = link;
+ dev->devno = dev - link->device;
+ ata_dev_init(dev);
+ }
+}
+
+/**
+ * sata_link_init_spd - Initialize link->sata_spd_limit
+ * @link: Link to configure sata_spd_limit for
+ *
+ * Initialize @link->[hw_]sata_spd_limit to the currently
+ * configured value.
+ *
+ * LOCKING:
+ * Kernel thread context (may sleep).
+ *
+ * RETURNS:
+ * 0 on success, -errno on failure.
+ */
+static int sata_link_init_spd(struct ata_link *link)
+{
+ u32 scontrol, spd;
+ int rc;
+
+ rc = sata_scr_read(link, SCR_CONTROL, &scontrol);
+ if (rc)
+ return rc;
+
+ spd = (scontrol >> 4) & 0xf;
+ if (spd)
+ link->hw_sata_spd_limit &= (1 << spd) - 1;
+
+ link->sata_spd_limit = link->hw_sata_spd_limit;
+
+ return 0;
+}
+
+/**
* ata_port_alloc - allocate and initialize basic ATA port resources
* @host: ATA host this allocated port belongs to
*
@@ -6053,7 +6115,6 @@ void ata_dev_init(struct ata_device *dev)
struct ata_port *ata_port_alloc(struct ata_host *host)
{
struct ata_port *ap;
- unsigned int i;
DPRINTK("ENTER\n");
@@ -6068,9 +6129,6 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
ap->ctl = ATA_DEVCTL_OBS;
ap->host = host;
ap->dev = host->dev;
-
- ap->link.hw_sata_spd_limit = UINT_MAX;
- ap->link.active_tag = ATA_TAG_POISON;
ap->last_ctl = 0xFF;
#if defined(ATA_VERBOSE_DEBUG)
@@ -6093,15 +6151,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
ap->cbl = ATA_CBL_NONE;
- ap->link.ap = ap;
-
- /* can't use iterator, ap isn't initialized yet */
- for (i = 0; i < ATA_MAX_DEVICES; i++) {
- struct ata_device *dev = &ap->link.device[i];
- dev->link = &ap->link;
- dev->devno = i;
- ata_dev_init(dev);
- }
+ ata_link_init(ap, &ap->link);
#ifdef ATA_IRQ_TRAP
ap->stats.unhandled_irq = 1;
@@ -6384,7 +6434,6 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
for (i = 0; i < host->n_ports; i++) {
struct ata_port *ap = host->ports[i];
int irq_line;
- u32 scontrol;
unsigned long xfer_mask;
/* set SATA cable type if still unset */
@@ -6392,12 +6441,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
ap->cbl = ATA_CBL_SATA;
/* init sata_spd_limit to the current value */
- if (sata_scr_read(&ap->link, SCR_CONTROL, &scontrol) == 0) {
- int spd = (scontrol >> 4) & 0xf;
- if (spd)
- ap->link.hw_sata_spd_limit &= (1 << spd) - 1;
- }
- ap->link.sata_spd_limit = ap->link.hw_sata_spd_limit;
+ sata_link_init_spd(&ap->link);
/* report the secondary IRQ for second channel legacy */
irq_line = host->irq;
--
1.5.0.3
next prev parent reply other threads:[~2007-07-16 9:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-16 9:34 [PATCHSET 2/4] libata: implement ata_link, take 5 Tejun Heo
2007-07-16 9:34 ` [PATCH 02/14] libata-link: implement and use link/device iterators Tejun Heo
2007-07-16 9:34 ` [PATCH 01/14] libata-link: introduce ata_link Tejun Heo
2007-07-16 9:34 ` [PATCH 06/14] libata-link: linkify config/EH related functions Tejun Heo
2007-07-16 9:34 ` [PATCH 05/14] libata-link: linkify reset Tejun Heo
2007-07-16 9:34 ` [PATCH 03/14] libata-link: linkify PHY-related functions Tejun Heo
2007-07-16 9:34 ` [PATCH 07/14] libata-link: make two port flags HRST_TO_RESUME and SKIP_D2H_BSY link flags Tejun Heo
2007-07-16 9:34 ` [PATCH 04/14] libata-link: linkify EH action helpers Tejun Heo
2007-07-16 9:34 ` [PATCH 13/14] libata-link: update hotplug to handle PMP links Tejun Heo
2007-07-16 9:34 ` Tejun Heo [this message]
2007-07-16 9:34 ` [PATCH 12/14] libata-link: update EH to deal with " Tejun Heo
2007-07-16 9:34 ` [PATCH 11/14] libata-link: update ata_scsi_error() to handle " Tejun Heo
2007-07-16 9:34 ` [PATCH 09/14] libata-link: implement ata_link_abort() Tejun Heo
2007-07-16 9:34 ` [PATCH 10/14] libata-link: add PMP links Tejun Heo
2007-07-16 9:34 ` [PATCH 14/14] libata-link: update Power Management to handle " Tejun Heo
2007-07-16 9:42 ` [PATCHSET 2/4] libata: implement ata_link, take 5 Tejun Heo
-- strict thread matches above, loose matches on Subject: below --
2007-08-04 8:42 [PATCHSET] libata: implement ata_link, take 6 Tejun Heo
2007-08-04 8:42 ` [PATCH 08/14] libata-link: separate out link initialization functions Tejun Heo
2007-08-06 9:36 [PATCHSET 2/4] libata: implement ata_link, take 7 Tejun Heo
2007-08-06 9:36 ` [PATCH 08/14] libata-link: separate out link initialization functions 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=1184578480953-git-send-email-htejun@gmail.com \
--to=htejun@gmail.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=forrest.zhao@gmail.com \
--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).