Skip to contentSkip to conversation

The definition of ahci_start_fis_rx() and ahci_stop_fis_rx()

PATCH In review zhao, forrest 5 participants 8 messages Jun 2, 2006 – Jun 3, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/6 The definition of ahci_start_fis_rx() and ahci_stop_fis_rx()

Put the "start/stop FIS RX" operation into ahci_start_fis_rx() and
ahci_stop_fis_rx().

---

 drivers/scsi/ahci.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 0 deletions(-)

81f3915bccdf294fd627f2b3b0e98b1a6a457cf5

drivers/scsi/ahci.c +80 -0
index d2b35c4..34e6c73 100644
@@ -202,6 +202,10 @@ static unsigned int ahci_qc_issue(struct
 static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
 static int ahci_start_engine(void __iomem *port_mmio);
 static int ahci_stop_engine(void __iomem *port_mmio);
+static void ahci_start_fis_rx(void __iomem *port_mmio,
+			     struct ahci_port_priv *pp,
+			     struct ahci_host_priv *hpriv);
+static int ahci_stop_fis_rx(void __iomem *port_mmio);
 static int ahci_probe_reset(struct ata_port *ap, unsigned int *classes);
 static void ahci_irq_clear(struct ata_port *ap);
 static int ahci_port_start(struct ata_port *ap);
@@ -558,6 +562,82 @@ static int ahci_start_engine(void __iome
 	return 0;
 }
 
+static int ahci_stop_fis_rx(void __iomem *port_mmio)
+{
+	u32 tmp;
+	int work = 1000;
+
+	/*
+	 * Get current status
+	 */
+	tmp = readl(port_mmio + PORT_CMD);
+
+	/* Check if FIS RX is already disabled */
+	if ((tmp & PORT_CMD_FIS_RX) == 0)
+		return 0;
+
+	/*
+	 * AHCI Rev 1.1 section 10.3.2
+	 * Software shall not clear PxCMD.FRE while
+	 * PxCMD.ST or PxCMD.CR is set to '1'
+	 */
+	if (tmp & (PORT_CMD_LIST_ON | PORT_CMD_START)) {
+		return -EPERM;
+	}
+
+	/*
+	 * Disable FIS reception
+	 *
+	 * AHCI Rev 1.1 Section 10.1.2:
+	 * If PxCMD.FRE is set to '1', software should clear it
+	 * to '0' and wait at least 500 milliseconds for PxCMD.FR
+	 * to return '0' when read. If PxCMD.FR does not clear
+	 * '0' correctly, then software may attempt a port reset
+	 * of a full HBA reset to recover.
+	 */
+	tmp &= ~(PORT_CMD_FIS_RX);
+	writel(tmp, port_mmio + PORT_CMD);
+
+	mdelay(500);
+	work = 1000;
+	while (work-- > 0) {
+		tmp = readl(port_mmio + PORT_CMD);
+		if ((tmp & PORT_CMD_FIS_ON) == 0)
+			return 0;
+		udelay(10);
+	}
+
+	return -EBUSY;
+}
+
+static void ahci_start_fis_rx(void __iomem *port_mmio,
+                             struct ahci_port_priv *pp,
+                             struct ahci_host_priv *hpriv)
+{
+	u32 tmp;
+
+	/*
+	 * Set FIS registers
+	 */
+	if (hpriv->cap & HOST_CAP_64)
+		writel((pp->cmd_slot_dma >> 16) >> 16, port_mmio + PORT_LST_ADDR_HI);
+	writel(pp->cmd_slot_dma & 0xffffffff, port_mmio + PORT_LST_ADDR);
+	readl(port_mmio + PORT_LST_ADDR); /* flush */
+
+	if (hpriv->cap & HOST_CAP_64)
+		writel((pp->rx_fis_dma >> 16) >> 16, port_mmio + PORT_FIS_ADDR_HI);
+	writel(pp->rx_fis_dma & 0xffffffff, port_mmio + PORT_FIS_ADDR);
+	readl(port_mmio + PORT_FIS_ADDR); /* flush */
+
+	/*
+	 * Enable FIS reception
+	 */
+	tmp = readl(port_mmio + PORT_CMD);
+	tmp |= PORT_CMD_FIS_RX;
+	writel(tmp, port_mmio + PORT_CMD);
+	readl(port_mmio + PORT_CMD); /* flush */
+}
+
 static unsigned int ahci_dev_classify(struct ata_port *ap)
 {
 	void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
Signature · 1 line
1.2.6
#2 lore raw
In reply to zhao, forrest
Quoted 5 lines · forrest
drivers/scsi/ahci.c +5 -0
+	/*
+	 * Disable FIS reception
+	 *
+	 * AHCI Rev 1.1 Section 10.1.2:
+	 * If PxCMD.FRE is set to '1', software should clear it

drivers/scsi/ahci.c static int ahci_start_engine(void __iome · line 602

Quoted 10 lines
drivers/scsi/ahci.c +10 -0
+	 * to '0' and wait at least 500 milliseconds for PxCMD.FR
+	 * to return '0' when read. If PxCMD.FR does not clear
+	 * '0' correctly, then software may attempt a port reset
+	 * of a full HBA reset to recover.
+	 */
+	tmp &= ~(PORT_CMD_FIS_RX);
+	writel(tmp, port_mmio + PORT_CMD);
+
+	mdelay(500);
+	work = 1000;

The spec states that you should wait up to 500msec for this condition to happen, not wait 500msec before looking at it! So please rework this bit, a half second potentially wasted busy loop is quite nasty.

Other than that, this part looks good too. If you fix it up, I can add my signed-off to this bit as well.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 12 lines · Jens Axboe
Quoted 11 lines · forrest
drivers/scsi/ahci.c +11 -0
+	/*
+	 * Disable FIS reception
+	 *
+	 * AHCI Rev 1.1 Section 10.1.2:
+	 * If PxCMD.FRE is set to '1', software should clear it
+	 * to '0' and wait at least 500 milliseconds for PxCMD.FR
+	 * to return '0' when read. If PxCMD.FR does not clear
+	 * '0' correctly, then software may attempt a port reset
+	 * of a full HBA reset to recover.
+	 */
+	tmp &= ~(PORT_CMD_FIS_RX);
Quoted 8 lines

drivers/scsi/ahci.c static int ahci_start_engine(void __iome · line 602

Quoted 4 lines
drivers/scsi/ahci.c +4 -0
+	writel(tmp, port_mmio + PORT_CMD);
+
+	mdelay(500);
+	work = 1000;

The spec states that you should wait up to 500msec for this condition to happen, not wait 500msec before looking at it! So please rework this bit, a half second potentially wasted busy loop is quite nasty.

The spec says If PxCMD.FRE is set to '1', software should clear it to '0' and wait *at least* 500 milliseconds for PxCMD.FR to return '0' when read.

It's "at least", not "up to".

Thanks,
Forrest

#4 lore raw
Quoted 22 lines · forrest
Quoted 12 lines · Jens Axboe
Quoted 11 lines · forrest
drivers/scsi/ahci.c +11 -0
+	/*
+	 * Disable FIS reception
+	 *
+	 * AHCI Rev 1.1 Section 10.1.2:
+	 * If PxCMD.FRE is set to '1', software should clear it
+	 * to '0' and wait at least 500 milliseconds for PxCMD.FR
+	 * to return '0' when read. If PxCMD.FR does not clear
+	 * '0' correctly, then software may attempt a port reset
+	 * of a full HBA reset to recover.
+	 */
+	tmp &= ~(PORT_CMD_FIS_RX);
Quoted 8 lines

drivers/scsi/ahci.c static int ahci_start_engine(void __iome · line 602

Quoted 4 lines
drivers/scsi/ahci.c +4 -0
+	writel(tmp, port_mmio + PORT_CMD);
+
+	mdelay(500);
+	work = 1000;

The spec states that you should wait up to 500msec for this condition to happen, not wait 500msec before looking at it! So please rework this bit, a half second potentially wasted busy loop is quite nasty.

Quoted 5 lines

The spec says If PxCMD.FRE is set to '1', software should clear it to '0' and wait *at least* 500 milliseconds for PxCMD.FR to return '0' when read.

It's "at least", not "up to".

That still doesn't make the code right. So make it wait 1 seconds max, but don't delay 500msec at the beginning. That's my problem.

Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 23 lines · Jens Axboe
Quoted 22 lines · forrest
Quoted 20 lines · Jens Axboe
Quoted 5 lines · forrest
drivers/scsi/ahci.c +5 -0
+	/*
+	 * Disable FIS reception
+	 *
+	 * AHCI Rev 1.1 Section 10.1.2:
+	 * If PxCMD.FRE is set to '1', software should clear it

drivers/scsi/ahci.c static int ahci_start_engine(void __iome · line 602

Quoted 10 lines
drivers/scsi/ahci.c +10 -0
+	 * to '0' and wait at least 500 milliseconds for PxCMD.FR
+	 * to return '0' when read. If PxCMD.FR does not clear
+	 * '0' correctly, then software may attempt a port reset
+	 * of a full HBA reset to recover.
+	 */
+	tmp &= ~(PORT_CMD_FIS_RX);
+	writel(tmp, port_mmio + PORT_CMD);
+
+	mdelay(500);
+	work = 1000;

The spec states that you should wait up to 500msec for this condition to happen, not wait 500msec before looking at it! So please rework this bit, a half second potentially wasted busy loop is quite nasty.

Quoted 8 lines
Quoted 5 lines

The spec says If PxCMD.FRE is set to '1', software should clear it to '0' and wait *at least* 500 milliseconds for PxCMD.FR to return '0' when read.

It's "at least", not "up to".

That still doesn't make the code right. So make it wait 1 seconds max, but don't delay 500msec at the beginning. That's my problem.

OK. I'll fix it after we collect all comments from mailing list :)

Forrest

#6 lore raw
In reply to zhao, forrest
Quoted 12 lines · forrest
drivers/scsi/ahci.c +12 -0
+static int ahci_stop_fis_rx(void __iomem *port_mmio)
+{
+	u32 tmp;
+	int work = 1000;
+
+	/*
+	 * Get current status
+	 */
+	tmp = readl(port_mmio + PORT_CMD);
+
+	/* Check if FIS RX is already disabled */
+	if ((tmp & PORT_CMD_FIS_RX) == 0)

drivers/scsi/ahci.c static int ahci_start_engine(void __iome · line 586

Quoted 10 lines
drivers/scsi/ahci.c +10 -0
+		return 0;
+
+	/*
+	 * AHCI Rev 1.1 section 10.3.2
+	 * Software shall not clear PxCMD.FRE while
+	 * PxCMD.ST or PxCMD.CR is set to '1'
+	 */
+	if (tmp & (PORT_CMD_LIST_ON | PORT_CMD_START)) {
+		return -EPERM;
+	}

Same here. I'm not sure whether the above two tests are necessary, but that might be just me. :)

Quoted 11 lines
drivers/scsi/ahci.c +11 -0
+	/*
+	 * Disable FIS reception
+	 *
+	 * AHCI Rev 1.1 Section 10.1.2:
+	 * If PxCMD.FRE is set to '1', software should clear it
+	 * to '0' and wait at least 500 milliseconds for PxCMD.FR
+	 * to return '0' when read. If PxCMD.FR does not clear
+	 * '0' correctly, then software may attempt a port reset
+	 * of a full HBA reset to recover.
+	 */
+	tmp &= ~(PORT_CMD_FIS_RX);

drivers/scsi/ahci.c static int ahci_start_engine(void __iome · line 608

Quoted 10 lines
drivers/scsi/ahci.c +10 -0
+	writel(tmp, port_mmio + PORT_CMD);
+
+	mdelay(500);
+	work = 1000;
+	while (work-- > 0) {
+		tmp = readl(port_mmio + PORT_CMD);
+		if ((tmp & PORT_CMD_FIS_ON) == 0)
+			return 0;
+		udelay(10);
+	}

Please convert to ata_wait_register(). Also, I share Jens' opinion. The way I read the spec is that the timeout should be at least 500ms not that we have to wait 500ms before polling for !FIS_ON.

Signature · 1 line
tejun
#7 lore raw
Quoted 3 lines · Tejun Heo

Please convert to ata_wait_register(). Also, I share Jens' opinion. The way I read the spec is that the timeout should be at least 500ms not that we have to wait 500ms before polling for !FIS_ON.

Correct.

Jeff

P.S. FWIW I'm still travelling. Have email, but no merges until June 8.