From: Tejun Heo <htejun@gmail.com>
To: Jeff Garzik <jgarzik@pobox.com>, albertcc@tw.ibm.com, liml@rtr.ca
Cc: linux-ide@vger.kernel.org
Subject: [PATCH 11/14] ahci: convert to new reset mechanism
Date: Sun, 18 Dec 2005 22:49:24 +0900 [thread overview]
Message-ID: <20051218134924.GL31571@htj.dyndns.org> (raw)
In-Reply-To: <20051218133305.GA31571@htj.dyndns.org>
Convert ahci ->phy_reset to ->hard_reset. The original ->phy_reset
simply called __sata_phy_reset() to perform reset; however, AHCI spec
mandates to turn off START bit during reset. New ->hard_reset method
properly follows AHCI reset procedure.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Index: work/drivers/scsi/ahci.c
===================================================================
--- work.orig/drivers/scsi/ahci.c 2005-12-18 22:23:38.000000000 +0900
+++ work/drivers/scsi/ahci.c 2005-12-18 22:24:04.000000000 +0900
@@ -186,7 +186,8 @@ static void ahci_scr_write (struct ata_p
static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
static int ahci_qc_issue(struct ata_queued_cmd *qc);
static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
-static void ahci_phy_reset(struct ata_port *ap);
+static int ahci_hardreset(struct ata_port *ap, unsigned int *classes);
+static void ahci_postreset(struct ata_port *ap, const unsigned int *classes);
static void ahci_irq_clear(struct ata_port *ap);
static void ahci_eng_timeout(struct ata_port *ap);
static int ahci_port_start(struct ata_port *ap);
@@ -226,7 +227,8 @@ static const struct ata_port_operations
.tf_read = ahci_tf_read,
- .phy_reset = ahci_phy_reset,
+ .hard_reset = ahci_hardreset,
+ .post_reset = ahci_postreset,
.qc_prep = ahci_qc_prep,
.qc_issue = ahci_qc_issue,
@@ -248,8 +250,7 @@ static const struct ata_port_info ahci_p
{
.sht = &ahci_sht,
.host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
- ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
- ATA_FLAG_PIO_DMA,
+ ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
.pio_mask = 0x1f, /* pio0-4 */
.udma_mask = 0x7f, /* udma0-6 ; FIXME */
.port_ops = &ahci_ops,
@@ -474,17 +475,30 @@ static void ahci_start_engine(struct ata
readl(port_mmio + PORT_CMD); /* flush */
}
-static void ahci_phy_reset(struct ata_port *ap)
+static int ahci_wait_for_bit(void __iomem *reg, u32 mask, u32 val,
+ unsigned long interval_msec,
+ unsigned long timeout_msec)
{
- void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
- struct ata_taskfile tf;
- struct ata_device *dev = &ap->device[0];
- u32 new_tmp, tmp;
+ unsigned long timeout;
+ u32 tmp;
+
+ timeout = jiffies + (timeout_msec * HZ) / 1000;
+ do {
+ tmp = readl(reg);
+ if ((tmp & mask) != val)
+ return 0;
+ msleep(interval_msec);
+ } while (time_before(jiffies, timeout));
- __sata_phy_reset(ap);
+ return -1;
+}
- if (ap->flags & ATA_FLAG_PORT_DISABLED)
- return;
+static unsigned int ahci_dev_classify(struct ata_port *ap)
+{
+ void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
+ struct ata_taskfile tf;
+ unsigned int class;
+ u32 tmp;
tmp = readl(port_mmio + PORT_SIG);
tf.lbah = (tmp >> 24) & 0xff;
@@ -492,15 +506,58 @@ static void ahci_phy_reset(struct ata_po
tf.lbal = (tmp >> 8) & 0xff;
tf.nsect = (tmp) & 0xff;
- dev->class = ata_dev_classify(&tf);
- if (!ata_dev_present(dev)) {
- ata_port_disable(ap);
- return;
- }
+ class = ata_dev_classify(&tf);
+ if (class == ATA_DEV_UNKNOWN)
+ class = ATA_DEV_NONE;
+ return class;
+}
+
+static int ahci_hardreset(struct ata_port *ap, unsigned int *classes)
+{
+ void __iomem *mmio = ap->host_set->mmio_base;
+ void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
+ u32 tmp;
+
+ DPRINTK("ENTER\n");
+
+ /* stop engine */
+ ahci_stop_engine(ap);
+
+ /* issue COMRESET */
+ writel(0x301, port_mmio + PORT_SCR_CTL);
+ readl(port_mmio + PORT_SCR_CTL); /* flush */
+ msleep(1);
+ writel(0x300, port_mmio + PORT_SCR_CTL);
+ readl(port_mmio + PORT_SCR_CTL); /* flush */
+
+ msleep(200);
+ ahci_wait_for_bit(port_mmio + PORT_SCR_STAT, 0xf, 0x1, 1, 5000);
+
+ /* clear SATA phy error, if any */
+ tmp = readl(port_mmio + PORT_SCR_ERR);
+ writel(tmp, port_mmio + PORT_SCR_ERR);
+
+ /* re-start engine */
+ ahci_start_engine(ap);
+
+ classes[0] = ATA_DEV_NONE;
+ if (sata_dev_present(ap))
+ classes[0] = ahci_dev_classify(ap);
+
+ DPRINTK("EXIT, class=%u\n", classes[0]);
+ return 0;
+}
+
+static void ahci_postreset(struct ata_port *ap, const unsigned int *classes)
+{
+ void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
+ u32 new_tmp, tmp;
+
+ ata_std_postreset(ap, classes);
/* Make sure port's ATAPI bit is set appropriately */
new_tmp = tmp = readl(port_mmio + PORT_CMD);
- if (dev->class == ATA_DEV_ATAPI)
+ if (classes[0] == ATA_DEV_ATAPI)
new_tmp |= PORT_CMD_ATAPI;
else
new_tmp &= ~PORT_CMD_ATAPI;
next prev parent reply other threads:[~2005-12-18 13:49 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-18 13:33 [RFC/PATCHSET] libata: new reset mechanism Tejun Heo
2005-12-18 13:36 ` [PATCH 01/14] libata: modify ata_dev_try_classify Tejun Heo
2005-12-18 13:38 ` [PATCH 02/14] libata: implement new reset mechanism Tejun Heo
2005-12-19 5:31 ` Jeff Garzik
2005-12-19 6:33 ` Tejun Heo
2005-12-18 13:40 ` [PATCH 03/14] libata: implement standard reset methods Tejun Heo
2005-12-18 13:41 ` [PATCH 04/14] libata: export ata_busy_sleep() Tejun Heo
2005-12-18 13:42 ` [PATCH 05/14] sata_sil: convert to new reset mechanism Tejun Heo
2005-12-18 13:43 ` [PATCH 06/14] sata_sil24: " Tejun Heo
2005-12-18 13:44 ` [PATCH 07/14] sata_sil24: add hardreset Tejun Heo
2005-12-18 13:46 ` [PATCH 08/14] ata_piix: convert pata to new reset mechanism Tejun Heo
2005-12-18 13:47 ` [PATCH 09/14] ata_piix: convert sata " Tejun Heo
2005-12-18 13:48 ` [PATCH 10/14] ahci: separate out ahci_stop/start_engine() Tejun Heo
2005-12-19 5:33 ` Jeff Garzik
2005-12-19 6:05 ` Tejun Heo
2005-12-18 13:49 ` Tejun Heo [this message]
2005-12-19 5:33 ` [PATCH 11/14] ahci: convert to new reset mechanism Jeff Garzik
2005-12-19 6:07 ` Tejun Heo
2005-12-18 13:50 ` [PATCH 12/14] ahci: separate out ahci_cmd_prep() Tejun Heo
2005-12-19 5:34 ` Jeff Garzik
2005-12-18 13:51 ` [PATCH 13/14] ahci: add constants for SRST Tejun Heo
2005-12-19 5:35 ` Jeff Garzik
2005-12-18 13:51 ` [PATCH 14/14] ahci: add softreset Tejun Heo
2005-12-19 5:36 ` Jeff Garzik
2005-12-19 6:12 ` Tejun Heo
2005-12-19 6:40 ` Jeff Garzik
2005-12-19 7:13 ` Tejun Heo
2006-01-29 5:11 ` Jeff Garzik
2005-12-19 5:20 ` [RFC/PATCHSET] libata: new reset mechanism Jeff Garzik
2005-12-19 6:03 ` Tejun Heo
2006-01-29 5:20 ` Jeff Garzik
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=20051218134924.GL31571@htj.dyndns.org \
--to=htejun@gmail.com \
--cc=albertcc@tw.ibm.com \
--cc=jgarzik@pobox.com \
--cc=liml@rtr.ca \
--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).