Skip to contentSkip to conversation

libata/ahci: quirk for JMB585/JMB582

PATCH In review MD Lin 2 participants 3 messages Sep 7, 2022 – Sep 8, 2022 libata

lore
Share & tools
lore

MD Lin

author
#0 lore raw

PATCH 1/1 libata/ahci: quirk for JMB585/JMB582

This patch adds a quirk, which enable error bit handling functions and SATA configuration for JMicron JMB585/JMB582.

---
 drivers/ata/ahci.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
drivers/ata/ahci.c +65 -0
index 505920d45..b0768fae3 100755
@@ -1657,6 +1657,68 @@ static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp
 	}
 }
 
+static void ahci_jmb585_write_sata_phy(void __iomem *mmio, u32 addr, u32 data)
+{
+	writel((addr & 0x01FFFUL) + (1UL << 18UL), mmio + 0xC0);
+	writel(data, mmio + 0xC8);
+}
+
+static void ahci_jmicron_585_quirk(void __iomem *mmio)
+{
+	u32 pi = readl(mmio + HOST_PORTS_IMPL);
+	u32 b8_data;
+
+	/*
+	 * enable error bit handling functions, these might overwrite
+	 * the setting which loads from external SPI flash
+	 */
+	b8_data = (pi > 3) ? 0x13 : 0x92;
+	writel(0x03060004+b8_data, mmio + 0xB8);
+	writel(0x00FF0B01,         mmio + 0x30);
+	writel(0x0000003F,         mmio + 0x34);
+	writel(0x0000001F,         mmio + 0x38);
+	writel(0x03060000+b8_data, mmio + 0xB8);
+	writel(0xF9E4EFBF,         mmio + 0xB0);
+
+	/*
+	 * set SATA configuration, these might overwrite
+	 * the setting which loads from external SPI flash
+	 */
+	ahci_jmb585_write_sata_phy(mmio, 0x06, 0x70005BE3); /* port0 */
+	ahci_jmb585_write_sata_phy(mmio, 0x13, 0x70005BE3); /* port1 */
+	ahci_jmb585_write_sata_phy(mmio, 0x73, 0x000001E5); /* port0 */
+	ahci_jmb585_write_sata_phy(mmio, 0x75, 0x000001E5); /* port1 */
+	ahci_jmb585_write_sata_phy(mmio, 0x74, 0x00000024); /* port0 */
+	ahci_jmb585_write_sata_phy(mmio, 0x80, 0x250B0003); /* port1 */
+	if (pi > 3) {
+		ahci_jmb585_write_sata_phy(mmio, 0x20, 0x70005BE3); /* port2 */
+		ahci_jmb585_write_sata_phy(mmio, 0x2D, 0x70005BE3); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x3A, 0x70005BE3); /* port4 */
+		ahci_jmb585_write_sata_phy(mmio, 0x79, 0x000001E5); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x83, 0x250B0003); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x7A, 0x00000024); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x84, 0x250B0003); /* port3 */
+	}
+}
+
+static void ahci_jmicron_quirk(struct pci_dev *pdev,
+			struct ahci_host_priv *hpriv)
+{
+	void __iomem *mmio = hpriv->mmio;
+	u8 tmp8;
+
+	if (pdev->vendor != PCI_VENDOR_ID_JMICRON)
+		return;
+
+	switch (pdev->device) {
+	case 0x585: /* check if the chip is JMB585 */
+		tmp8 = readb(mmio + 0x44);
+		if (tmp8)
+			ahci_jmicron_585_quirk(mmio);
+		break;
+	}
+}
+
 static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	unsigned int board_id = ent->driver_data;
@@ -1775,6 +1837,9 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 */
 	ahci_intel_pcs_quirk(pdev, hpriv);
 
+	/* set JMicron configuration */
+	ahci_jmicron_quirk(pdev, hpriv);
+
 	/* prepare host */
 	if (hpriv->cap & HOST_CAP_NCQ) {
 		pi.flags |= ATA_FLAG_NCQ;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · MD Lin

This patch adds a quirk, which enable error bit handling functions and SATA configuration for JMicron JMB585/JMB582.

Please use scripts/get_maintainer.pl to check to whom ata patches should be addressed. If you do not send patches to me, there is a high chance that I will miss them.

The patch title should be:

ata: ahci: Add initialization quirk for Jmicro 585/582 controllers

Or equivalent, that is, a little more descriptive.

The commit message also does not explain WHY this quirk is necessary (the problem is not described) and there is also no description of HOW your patch address the issue. Please be a little more verbose with the commit message to better describe the patch.

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1660

Quoted 13 lines
---
 drivers/ata/ahci.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
drivers/ata/ahci.c +1 -0
index 505920d45..b0768fae3 100755
@@ -1657,6 +1657,68 @@ static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp
 	}
 }
 
+static void ahci_jmb585_write_sata_phy(void __iomem *mmio, u32 addr, u32 data)

The patch title said jmb585 and jmb582. So should this be called ahci_jmb58x_write_sata_phy() ?

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1666

Quoted 6 lines
drivers/ata/ahci.c +6 -0
+{
+	writel((addr & 0x01FFFUL) + (1UL << 18UL), mmio + 0xC0);
+	writel(data, mmio + 0xC8);
+}
+
+static void ahci_jmicron_585_quirk(void __iomem *mmio)

Same here. Also, please be consistent with the names: spell out jmicron or use jmb, either is fine with me, but once you choose one, stick with it. So:

ahci_jmb58x_write_sata_phy()
ahci_jmb58x_quirk()

or

ahci_jmicron_58x_write_sata_phy()
ahci_jmicron_58x_quirk()

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1676

Quoted 10 lines
drivers/ata/ahci.c +10 -0
+{
+	u32 pi = readl(mmio + HOST_PORTS_IMPL);
+	u32 b8_data;
+
+	/*
+	 * enable error bit handling functions, these might overwrite
+	 * the setting which loads from external SPI flash
+	 */
+	b8_data = (pi > 3) ? 0x13 : 0x92;
+	writel(0x03060004+b8_data, mmio + 0xB8);

Spaces missing around the "+" in the first argument.

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1680

Quoted 4 lines
drivers/ata/ahci.c +4 -0
+	writel(0x00FF0B01,         mmio + 0x30);
+	writel(0x0000003F,         mmio + 0x34);
+	writel(0x0000001F,         mmio + 0x38);
+	writel(0x03060000+b8_data, mmio + 0xB8);

Same here.

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1681

Quoted 1 line
drivers/ata/ahci.c +1 -0
+	writel(0xF9E4EFBF,         mmio + 0xB0);

And what are all these magic values ? Where do they come from ? It would be nice to have these defined as macros with descriptive names in drivers/ata/ahci.h.

Quoted 10 lines
drivers/ata/ahci.c +10 -0
+
+	/*
+	 * set SATA configuration, these might overwrite
+	 * the setting which loads from external SPI flash
+	 */
+	ahci_jmb585_write_sata_phy(mmio, 0x06, 0x70005BE3); /* port0 */
+	ahci_jmb585_write_sata_phy(mmio, 0x13, 0x70005BE3); /* port1 */
+	ahci_jmb585_write_sata_phy(mmio, 0x73, 0x000001E5); /* port0 */
+	ahci_jmb585_write_sata_phy(mmio, 0x75, 0x000001E5); /* port1 */
+	ahci_jmb585_write_sata_phy(mmio, 0x74, 0x00000024); /* port0 */

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1701

Quoted 10 lines
drivers/ata/ahci.c +10 -0
+	ahci_jmb585_write_sata_phy(mmio, 0x80, 0x250B0003); /* port1 */
+	if (pi > 3) {
+		ahci_jmb585_write_sata_phy(mmio, 0x20, 0x70005BE3); /* port2 */
+		ahci_jmb585_write_sata_phy(mmio, 0x2D, 0x70005BE3); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x3A, 0x70005BE3); /* port4 */
+		ahci_jmb585_write_sata_phy(mmio, 0x79, 0x000001E5); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x83, 0x250B0003); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x7A, 0x00000024); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x84, 0x250B0003); /* port3 */
+	}

Same here, lots of "magic" values that cannot be checked. Please use macros and add comments describing where these come from (adapter specs ?).

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1714

Quoted 13 lines
drivers/ata/ahci.c +13 -0
+}
+
+static void ahci_jmicron_quirk(struct pci_dev *pdev,
+			struct ahci_host_priv *hpriv)
+{
+	void __iomem *mmio = hpriv->mmio;
+	u8 tmp8;
+
+	if (pdev->vendor != PCI_VENDOR_ID_JMICRON)
+		return;
+
+	switch (pdev->device) {
+	case 0x585: /* check if the chip is JMB585 */

The comment can be removed. This is obvious.

Also, there is no case for jmb582 model which the patch title mentions. Is it the same number for both models ? If that is the case, then please add a comment above the switch() describing that.

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1717

Quoted 3 lines
drivers/ata/ahci.c +3 -0
+		tmp8 = readb(mmio + 0x44);
+		if (tmp8)
+			ahci_jmicron_585_quirk(mmio);

The tmp8 variable is not necessary.

drivers/ata/ahci.c static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 1840

Quoted 12 lines
drivers/ata/ahci.c +5 -0
+		break;
+	}
+}
+
 static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	unsigned int board_id = ent->driver_data;
@@ -1775,6 +1837,9 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	 */
 	ahci_intel_pcs_quirk(pdev, hpriv);
 
+	/* set JMicron configuration */

This is obvious from the function name. So you can drop this comment.

Quoted 5 lines
drivers/ata/ahci.c +2 -0
+	ahci_jmicron_quirk(pdev, hpriv);
+
 	/* prepare host */
 	if (hpriv->cap & HOST_CAP_NCQ) {
 		pi.flags |= ATA_FLAG_NCQ;
Signature · 2 lines
Damien Le Moal
Western Digital Research
author
#2 lore raw

Hi Damien,
Thank you very much for the detailed suggestion. I will modify the patch, commit message and send to you again.

Best regards,
MD Lin (林明德)

JMicron Technology
Tel : 03-5797389  Ext. 8727
Fax : 03-5799566
E-mail : [email protected]

-----Original Message-----
From: Damien Le Moal <[email protected]>
Sent: Thursday, September 08, 2022 6:13 AM
To: Md Lin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Kevin Liu <[email protected]>; Charon Chen <[email protected]>; Cora Huang <[email protected]>; Ming Chen <[email protected]>; George Chao <[email protected]>; Banks <[email protected]>; Tzuwei Hung <[email protected]>
Subject: Re: [PATCH] libata/ahci: quirk for JMB585/JMB582

Quoted 4 lines · MD Lin

This patch adds a quirk, which enable error bit handling functions and SATA configuration for JMicron JMB585/JMB582.

Please use scripts/get_maintainer.pl to check to whom ata patches should be addressed. If you do not send patches to me, there is a high chance that I will miss them.

The patch title should be:

ata: ahci: Add initialization quirk for Jmicro 585/582 controllers

Or equivalent, that is, a little more descriptive.

The commit message also does not explain WHY this quirk is necessary (the problem is not described) and there is also no description of HOW your patch address the issue. Please be a little more verbose with the commit message to better describe the patch.

Quoted 10 lines
---
 drivers/ata/ahci.c | 65 
++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
drivers/ata/ahci.c index renamed from drivers/ata/ahci.c +0 -0

505920d45..b0768fae3 100755

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1661

Quoted 5 lines
drivers/ata/ahci.c +2 -0
@@ -1657,6 +1657,68 @@ static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp
 	}
 }
 
+static void ahci_jmb585_write_sata_phy(void __iomem *mmio, u32 addr, 
+u32 data)

The patch title said jmb585 and jmb582. So should this be called ahci_jmb58x_write_sata_phy() ?

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1666

Quoted 6 lines
drivers/ata/ahci.c +6 -0
+{
+	writel((addr & 0x01FFFUL) + (1UL << 18UL), mmio + 0xC0);
+	writel(data, mmio + 0xC8);
+}
+
+static void ahci_jmicron_585_quirk(void __iomem *mmio)

Same here. Also, please be consistent with the names: spell out jmicron or use jmb, either is fine with me, but once you choose one, stick with it. So:

ahci_jmb58x_write_sata_phy()
ahci_jmb58x_quirk()

or

ahci_jmicron_58x_write_sata_phy()
ahci_jmicron_58x_quirk()

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1676

Quoted 10 lines
drivers/ata/ahci.c +10 -0
+{
+	u32 pi = readl(mmio + HOST_PORTS_IMPL);
+	u32 b8_data;
+
+	/*
+	 * enable error bit handling functions, these might overwrite
+	 * the setting which loads from external SPI flash
+	 */
+	b8_data = (pi > 3) ? 0x13 : 0x92;
+	writel(0x03060004+b8_data, mmio + 0xB8);

Spaces missing around the "+" in the first argument.

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1680

Quoted 4 lines
drivers/ata/ahci.c +4 -0
+	writel(0x00FF0B01,         mmio + 0x30);
+	writel(0x0000003F,         mmio + 0x34);
+	writel(0x0000001F,         mmio + 0x38);
+	writel(0x03060000+b8_data, mmio + 0xB8);

Same here.

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1681

Quoted 1 line
drivers/ata/ahci.c +1 -0
+	writel(0xF9E4EFBF,         mmio + 0xB0);

And what are all these magic values ? Where do they come from ?
It would be nice to have these defined as macros with descriptive names in drivers/ata/ahci.h.

Quoted 10 lines
drivers/ata/ahci.c +10 -0
+
+	/*
+	 * set SATA configuration, these might overwrite
+	 * the setting which loads from external SPI flash
+	 */
+	ahci_jmb585_write_sata_phy(mmio, 0x06, 0x70005BE3); /* port0 */
+	ahci_jmb585_write_sata_phy(mmio, 0x13, 0x70005BE3); /* port1 */
+	ahci_jmb585_write_sata_phy(mmio, 0x73, 0x000001E5); /* port0 */
+	ahci_jmb585_write_sata_phy(mmio, 0x75, 0x000001E5); /* port1 */
+	ahci_jmb585_write_sata_phy(mmio, 0x74, 0x00000024); /* port0 */

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1701

Quoted 10 lines
drivers/ata/ahci.c +10 -0
+	ahci_jmb585_write_sata_phy(mmio, 0x80, 0x250B0003); /* port1 */
+	if (pi > 3) {
+		ahci_jmb585_write_sata_phy(mmio, 0x20, 0x70005BE3); /* port2 */
+		ahci_jmb585_write_sata_phy(mmio, 0x2D, 0x70005BE3); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x3A, 0x70005BE3); /* port4 */
+		ahci_jmb585_write_sata_phy(mmio, 0x79, 0x000001E5); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x83, 0x250B0003); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x7A, 0x00000024); /* port3 */
+		ahci_jmb585_write_sata_phy(mmio, 0x84, 0x250B0003); /* port3 */
+	}

Same here, lots of "magic" values that cannot be checked. Please use macros and add comments describing where these come from (adapter specs ?).

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1714

Quoted 13 lines
drivers/ata/ahci.c +13 -0
+}
+
+static void ahci_jmicron_quirk(struct pci_dev *pdev,
+			struct ahci_host_priv *hpriv)
+{
+	void __iomem *mmio = hpriv->mmio;
+	u8 tmp8;
+
+	if (pdev->vendor != PCI_VENDOR_ID_JMICRON)
+		return;
+
+	switch (pdev->device) {
+	case 0x585: /* check if the chip is JMB585 */

The comment can be removed. This is obvious.

Also, there is no case for jmb582 model which the patch title mentions. Is it the same number for both models ? If that is the case, then please add a comment above the switch() describing that.

drivers/ata/ahci.c static void ahci_intel_pcs_quirk(struct pci_dev *pdev, struct ahci_host_priv *hp · line 1717

Quoted 3 lines
drivers/ata/ahci.c +3 -0
+		tmp8 = readb(mmio + 0x44);
+		if (tmp8)
+			ahci_jmicron_585_quirk(mmio);

The tmp8 variable is not necessary.

drivers/ata/ahci.c static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 1840

Quoted 12 lines
drivers/ata/ahci.c +4 -0
+		break;
+	}
+}
+
 static int ahci_init_one(struct pci_dev *pdev, const struct 
 pci_device_id *ent)  {
 	unsigned int board_id = ent->driver_data; @@ -1775,6 +1837,9 @@ 

static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)

drivers/ata/ahci.c +1 -0
 	 */
 	ahci_intel_pcs_quirk(pdev, hpriv);
 
+	/* set JMicron configuration */

This is obvious from the function name. So you can drop this comment.

drivers/ata/ahci.c static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 1845

Quoted 5 lines
drivers/ata/ahci.c +2 -0
+	ahci_jmicron_quirk(pdev, hpriv);
+
 	/* prepare host */
 	if (hpriv->cap & HOST_CAP_NCQ) {
 		pi.flags |= ATA_FLAG_NCQ;

--
Damien Le Moal
Western Digital Research