Skip to contentSkip to conversation

Add the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

PATCH New Suman Tripathi 3 participants 7 messages Jan 6, 2015 1 message not in the archive

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

cover Add the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

This patch set implements the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

---

Suman Tripathi (2):
ahci_xgene: Implement the xgene_ahci_poll_reg_val to support PMP.
ahci_xgene: Implement the workaround to support PMP enumeration and
discovery.

 drivers/ata/ahci_xgene.c | 189 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 182 insertions(+), 7 deletions(-)

--
1.8.2.1

A message that is not in the archive (sent off-list or not yet received): 1420538536-32165-1-git-send-email-stripathi-qTEPVZfXA3Y@public.gmane.org

#2 lore raw

PATCH 1/2 ahci_xgene: Implement the xgene_ahci_poll_reg_val to support PMP.

This patch implements the function xgene_ahci_poll_reg_val to poll PxCI for multiple IDENTIFY DEVICE commands to finish before restarting the DMA engine.

---
 drivers/ata/ahci_xgene.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 54 insertions(+), 2 deletions(-)
drivers/ata/ahci_xgene.c +54 -2
index cbcd208..afa9c03 100644
@@ -105,17 +105,69 @@ static int xgene_ahci_init_memram(struct xgene_ahci_context *ctx)
 }
 
 /**
+ * xgene_ahci_poll_reg_val- Poll a register on a specific value.
+ * @ap : ATA port of interest.
+ * @reg : Register of interest.
+ * @val : Value to be attained.
+ * @interval : waiting interval for polling.
+ * @timeout : timeout for achieving the value.
+ */
+static int xgene_ahci_poll_reg_val(struct ata_port *ap,
+				   void __iomem *reg, unsigned
+				   int val, unsigned long interval,
+				   unsigned long timeout)
+{
+	unsigned long deadline;
+	unsigned int tmp;
+
+	tmp = ioread32(reg);
+	deadline = ata_deadline(jiffies, timeout);
+
+	while (tmp != val && time_before(jiffies, deadline)) {
+		ata_msleep(ap, interval);
+		tmp = ioread32(reg);
+	}
+
+	return tmp;
+}
+
+/**
  * xgene_ahci_restart_engine - Restart the dma engine.
  * @ap : ATA port of interest
  *
- * Restarts the dma engine inside the controller.
+ * Waits for completion of multiple commands and restarts
+ * the DMA engine inside the controller.
  */
 static int xgene_ahci_restart_engine(struct ata_port *ap)
 {
 	struct ahci_host_priv *hpriv = ap->host->private_data;
+	struct ahci_port_priv *pp = ap->private_data;
+	void __iomem *port_mmio = ahci_port_base(ap);
+	u32 fbs;
+
+	/*
+	 * In case of PMP multiple IDENTIFY DEVICE commands can be
+	 * issued inside PxCI. So need to poll PxCI for the
+	 * completion of outstanding IDENTIFY DEVICE commands before
+	 * we restart the DMA engine.
+	 */
+	if (xgene_ahci_poll_reg_val(ap, port_mmio +
+				    PORT_CMD_ISSUE, 0x0, 1, 100))
+		  return -EBUSY;
 
 	ahci_stop_engine(ap);
 	ahci_start_fis_rx(ap);
+
+	/*
+	 * Enable the PxFBS.FBS_EN bit as it
+	 * gets cleared due to stopping the engine.
+	 */
+	if (pp->fbs_supported) {
+		fbs = readl(port_mmio + PORT_FBS);
+		writel(fbs | PORT_FBS_EN, port_mmio + PORT_FBS);
+		fbs = readl(port_mmio + PORT_FBS);
+	}
+
 	hpriv->start_engine(ap);
 
 	return 0;
@@ -374,7 +426,7 @@ static struct ata_port_operations xgene_ahci_ops = {
 };
 
 static const struct ata_port_info xgene_ahci_port_info = {
-	.flags = AHCI_FLAG_COMMON,
+	.flags = AHCI_FLAG_COMMON | ATA_FLAG_PMP,
 	.pio_mask = ATA_PIO4,
 	.udma_mask = ATA_UDMA6,
 	.port_ops = &xgene_ahci_ops,

--
1.8.2.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

PATCH 2/2 ahci_xgene: Implement the workaround to support PMP enumeration and discovery.

In reply to Suman Tripathi

Due to H/W errata, the controller is unable to save the PMP field fetched from command header before sending the H2D FIS. When the device returns the PMP port field in the D2H FIS, there is a mismatch and results in command completion failure. The workaround is to write the pmp value to PxFBS.DEV field before issuing any command to PMP.

---
 drivers/ata/ahci_xgene.c | 133 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 128 insertions(+), 5 deletions(-)
drivers/ata/ahci_xgene.c +128 -5
index afa9c03..7f68875 100644
@@ -85,6 +85,7 @@ struct xgene_ahci_context {
 	struct ahci_host_priv *hpriv;
 	struct device *dev;
 	u8 last_cmd[MAX_AHCI_CHN_PERCTR]; /* tracking the last command issued*/
+	u32 class[MAX_AHCI_CHN_PERCTR]; /* tracking the class of device */
 	void __iomem *csr_core;		/* Core CSR address of IP */
 	void __iomem *csr_diag;		/* Diag CSR address of IP */
 	void __iomem *csr_axi;		/* AXI CSR address of IP */
@@ -177,11 +178,17 @@ static int xgene_ahci_restart_engine(struct ata_port *ap)
  * xgene_ahci_qc_issue - Issue commands to the device
  * @qc: Command to issue
  *
- * Due to Hardware errata for IDENTIFY DEVICE command and PACKET
- * command of ATAPI protocol set, the controller cannot clear the BSY bit
- * after receiving the PIO setup FIS. This results in the DMA state machine
- * going into the CMFatalErrorUpdate state and locks up. By restarting the
- * DMA engine, it removes the controller out of lock up state.
+ * Due to Hardware errata for IDENTIFY DEVICE command, the controller cannot
+ * clear the BSY bit after receiving the PIO setup FIS. This results in the dma
+ * state machine goes into the CMFatalErrorUpdate state and locks up. By
+ * restarting the dma engine, it removes the controller out of lock up state.
+ *
+ * Due to H/W errata, the controller is unable to save the PMP
+ * field fetched from command header before sending the H2D FIS.
+ * When the device returns the PMP port field in the D2H FIS, there is
+ * a mismatch and results in command completion failure. The
+ * workaround is to write the pmp value to PxFBS.DEV field before issuing
+ * any command to PMP.
  */
 static unsigned int xgene_ahci_qc_issue(struct ata_queued_cmd *qc)
 {
@@ -189,6 +196,19 @@ static unsigned int xgene_ahci_qc_issue(struct ata_queued_cmd *qc)
 	struct ahci_host_priv *hpriv = ap->host->private_data;
 	struct xgene_ahci_context *ctx = hpriv->plat_data;
 	int rc = 0;
+	u32 port_fbs;
+	void *port_mmio = ahci_port_base(ap);
+
+	/*
+	 * Write the pmp value to PxFBS.DEV
+	 * for case of Port Mulitplier.
+	 */
+	if (ctx->class[ap->port_no] == ATA_DEV_PMP) {
+		port_fbs = readl(port_mmio + PORT_FBS);
+		port_fbs &= ~PORT_FBS_DEV_MASK;
+		port_fbs |= qc->dev->link->pmp << PORT_FBS_DEV_OFFSET;
+		writel(port_fbs, port_mmio + PORT_FBS);
+	}
 
 	if (unlikely((ctx->last_cmd[ap->port_no] == ATA_CMD_ID_ATA) ||
 	    (ctx->last_cmd[ap->port_no] == ATA_CMD_PACKET)))
@@ -417,12 +437,115 @@ static void xgene_ahci_host_stop(struct ata_host *host)
 	ahci_platform_disable_resources(hpriv);
 }
 
+/**
+ * xgene_ahci_pmp_softreset - Issue the softreset to the drives connected
+ *                            to Port Multiplier.
+ * @link: link to reset
+ * @class: Return value to indicate class of device
+ * @deadline: deadline jiffies for the operation
+ *
+ * Due to H/W errata, the controller is unable to save the PMP
+ * field fetched from command header before sending the H2D FIS.
+ * When the device returns the PMP port field in the D2H FIS, there is
+ * a mismatch and results in command completion failure. The workaround
+ * is to write the pmp value to PxFBS.DEV field before issuing any command
+ * to PMP.
+ */
+static int xgene_ahci_pmp_softreset(struct ata_link *link, unsigned int *class,
+			  unsigned long deadline)
+{
+	int pmp = sata_srst_pmp(link);
+	struct ata_port *ap = link->ap;
+	u32 rc;
+	void *port_mmio = ahci_port_base(ap);
+	u32 port_fbs;
+
+	/*
+	 * Set PxFBS.DEV field with pmp
+	 * value.
+	 */
+	port_fbs = readl(port_mmio + PORT_FBS);
+	port_fbs &= ~PORT_FBS_DEV_MASK;
+	port_fbs |= pmp << PORT_FBS_DEV_OFFSET;
+	writel(port_fbs, port_mmio + PORT_FBS);
+
+	rc = ahci_do_softreset(link, class, pmp, deadline, ahci_check_ready);
+
+	return rc;
+}
+
+/**
+ * xgene_ahci_softreset - Issue the softreset to the drive.
+ * @link: link to reset
+ * @class: Return value to indicate class of device
+ * @deadline: deadline jiffies for the operation
+ *
+ * Due to H/W errata, the controller is unable to save the PMP
+ * field fetched from command header before sending the H2D FIS.
+ * When the device returns the PMP port field in the D2H FIS, there is
+ * a mismatch and results in command completion failure. The workaround
+ * is to write the pmp value to PxFBS.DEV field before issuing any command
+ * to PMP. Here is the algorithm to detect PMP :
+ *
+ * 1. Save the PxFBS value
+ * 2. Program PxFBS.DEV with pmp value send by framework. Framework sends
+ *    0xF for both PMP/NON-PMP initially
+ * 3. Issue softreset
+ * 4. If signature class is PMP goto 6
+ * 5. restore the original PxFBS and goto 3
+ * 6. return
+ */
+static int xgene_ahci_softreset(struct ata_link *link, unsigned int *class,
+			  unsigned long deadline)
+{
+	int pmp = sata_srst_pmp(link);
+	struct ata_port *ap = link->ap;
+	struct ahci_host_priv *hpriv = ap->host->private_data;
+	struct xgene_ahci_context *ctx = hpriv->plat_data;
+	void *port_mmio = ahci_port_base(ap);
+	u32 port_fbs;
+	u32 port_fbs_save;
+	u32 retry = 1;
+	u32 rc;
+
+	port_fbs_save = readl(port_mmio + PORT_FBS);
+
+	/*
+	 * Set PxFBS.DEV field with pmp
+	 * value.
+	 */
+	port_fbs = readl(port_mmio + PORT_FBS);
+	port_fbs &= ~PORT_FBS_DEV_MASK;
+	port_fbs |= pmp << PORT_FBS_DEV_OFFSET;
+	writel(port_fbs, port_mmio + PORT_FBS);
+
+softreset_retry:
+	rc = ahci_do_softreset(link, class, pmp,
+			       deadline, ahci_check_ready);
+
+	ctx->class[ap->port_no] = *class;
+	if (*class != ATA_DEV_PMP) {
+		/*
+		 * Retry for normal drives without
+		 * setting PxFBS.DEV field with pmp value.
+		 */
+		if (retry--) {
+			writel(port_fbs_save, port_mmio + PORT_FBS);
+			goto softreset_retry;
+		}
+	}
+
+	return rc;
+}
+
 static struct ata_port_operations xgene_ahci_ops = {
 	.inherits = &ahci_ops,
 	.host_stop = xgene_ahci_host_stop,
 	.hardreset = xgene_ahci_hardreset,
 	.read_id = xgene_ahci_read_id,
 	.qc_issue = xgene_ahci_qc_issue,
+	.softreset = xgene_ahci_softreset,
+	.pmp_softreset = xgene_ahci_pmp_softreset
 };
 
 static const struct ata_port_info xgene_ahci_port_info = {

--
1.8.2.1

#4 lore raw

cover Add the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

In reply to Suman Tripathi
Quoted 1 line · Suman Tripathi

This patch set implements the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

Hmm... still doesn't apply to for-3.20 after pulling in for-3.19-fixes.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git for-3.20

What am I doing wrong?

Thanks.

Signature · 1 line
tejun
#5 lore raw

cover Add the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

Hi ,

Quoted 1 line · Suman Tripathi

This patch set implements the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

Hmm... still doesn't apply to for-3.20 after pulling in for-3.19-fixes.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git for-3.20

What am I doing wrong?

I just again cloned git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git

switched to remotes/origin/for-3.20

git apply 0001-ahci_xgene-Implement-the-xgene_ahci_poll_reg_val-to-.patch git apply 0002-ahci_xgene-Implement-the-workaround-to-support-PMP-e.patch

Even tried with

patch -p1 < 0001-ahci_xgene-Implement-the-xgene_ahci_poll_reg_val-to-.patch patch -p1 < 0002-ahci_xgene-Implement-the-workaround-to-support-PMP-e.patch

Both are working fine. Not sure what's wrong with your environment.

Quoted 14 lines · Tejun Heo
Quoted 1 line · Suman Tripathi

This patch set implements the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

Hmm... still doesn't apply to for-3.20 after pulling in for-3.19-fixes.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git for-3.20

What am I doing wrong?

Thanks.

--
tejun

Signature · 10 lines
Thanks,
with regards,
Suman Tripathi
CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, 
is for the sole use of the intended recipient(s) and contains information
that is confidential and proprietary to Applied Micro Circuits Corporation or its subsidiaries. 
It is to be used solely for the purpose of furthering the parties' business relationship. 
All unauthorized review, use, disclosure or distribution is prohibited. 
If you are not the intended recipient, please contact the sender by reply e-mail 
and destroy all copies of the original message.
#6 lore raw

cover Add the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

Hi ,

For more info here is the git log output before applying the patch.

git log

commit b84b25cb0900b99b28c742dd33101be779f58259
Merge: 0628ee7 36aae28
Author: Tejun Heo <[email protected]>
Date: Tue Jan 6 07:48:24 2015 -0500
Merge branch 'for-3.19-fixes' of git://git.kernel.org/pub/scm/linux/kernel/g

Pull to receive the following two ahci_xgene fixes for the planned xgene PMP support patches.

5c0b8e0de76a8 ("ahci_xgene: Fix the endianess issue in APM X-Gene SoC AHCI 1102407bb714d ("ahci_xgene: Fix the DMA state machine lockup for the ATA_CM

commit 36aae28e3df4127e296f2680d65cb6310ce61021

Author: Andy Shevchenko <[email protected]>
Date:   Fri Dec 12 17:16:31 2014 +0200

libata: export ata_get_cmd_descript()

The driver sata_dwc_460ex is using this symbol. To build it as a module we have to have the symbol exported. This patch adds
Broken pipe

Quoted 48 lines · Suman Tripathi

Hi ,

Quoted 1 line · Suman Tripathi

This patch set implements the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

Hmm... still doesn't apply to for-3.20 after pulling in for-3.19-fixes.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git for-3.20

What am I doing wrong?

I just again cloned git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git

switched to remotes/origin/for-3.20

git apply 0001-ahci_xgene-Implement-the-xgene_ahci_poll_reg_val-to-.patch git apply 0002-ahci_xgene-Implement-the-workaround-to-support-PMP-e.patch

Even tried with

patch -p1 < 0001-ahci_xgene-Implement-the-xgene_ahci_poll_reg_val-to-.patch patch -p1 < 0002-ahci_xgene-Implement-the-workaround-to-support-PMP-e.patch

Both are working fine. Not sure what's wrong with your environment.

Quoted 6 lines · Tejun Heo
Quoted 1 line · Suman Tripathi

This patch set implements the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

Hmm... still doesn't apply to for-3.20 after pulling in for-3.19-fixes.

Quoted 8 lines

git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata.git for-3.20

What am I doing wrong?

Thanks.

--
tejun

--
Thanks,
with regards,
Suman Tripathi

Signature · 10 lines
Thanks,
with regards,
Suman Tripathi
CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, 
is for the sole use of the intended recipient(s) and contains information
that is confidential and proprietary to Applied Micro Circuits Corporation or its subsidiaries. 
It is to be used solely for the purpose of furthering the parties' business relationship. 
All unauthorized review, use, disclosure or distribution is prohibited. 
If you are not the intended recipient, please contact the sender by reply e-mail 
and destroy all copies of the original message.
#7 lore raw

cover Add the PMP support for APM X-Gene SoC AHCI SATA Host Controller driver.

Quoted 21 lines · Suman Tripathi

Hi ,

For more info here is the git log output before applying the patch.

git log

commit b84b25cb0900b99b28c742dd33101be779f58259
Merge: 0628ee7 36aae28
Author: Tejun Heo <[email protected]>
Date: Tue Jan 6 07:48:24 2015 -0500
Merge branch 'for-3.19-fixes' of git://git.kernel.org/pub/scm/linux/kernel/g

Pull to receive the following two ahci_xgene fixes for the planned xgene PMP support patches.

5c0b8e0de76a8 ("ahci_xgene: Fix the endianess issue in APM X-Gene SoC AHCI 1102407bb714d ("ahci_xgene: Fix the DMA state machine lockup for the ATA_CM

commit 36aae28e3df4127e296f2680d65cb6310ce61021

Quoted 8 lines
Author: Andy Shevchenko <[email protected]>
Date:   Fri Dec 12 17:16:31 2014 +0200

libata: export ata_get_cmd_descript()

The driver sata_dwc_460ex is using this symbol. To build it as a module we have to have the symbol exported. This patch adds
Broken pipe

Ah, this was me being stupid. I was using the old patches. Sorry about that. Applied to libata/for-3.20.

Thanks.

Signature · 1 line
tejun