Skip to contentSkip to conversation

Add StarFive JH7110 PCIe drvier support

PATCH Superseded Minda Chen 2 participants 8 messages Mar 29, 2023 – Apr 7, 2023

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Minda Chen

author
#0 lore raw

v3 cover Add StarFive JH7110 PCIe drvier support

This patchset needs to apply after patchset in [1]. These PCIe series patches are based on the JH7110 RISC-V SoC and VisionFive V2 board.

[1] https://patchwork.ozlabs.org/project/uboot/cover/[email protected]

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init. The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards. The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

previous patch version

v1: https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/
v2: https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/

changes
v2
1. remove clock commit. The pcie clocks change has been includeded in [1].
2. Using GENMASK marco1 in patch1.
3. remove the syscon dts node in patch3. The syscon dts dts node has been included in [1].

v3
patch 1
1. remove the read vendor ID delay
2. remove starfive_pcie_hide_rc_bar function. do not hide host
bridge BAR write.
3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
4. Add comments for bus and address limitation reason in function starfive_pcie_addr_valid
5. Change the multiple line comments in Line 373
6. Using gpio_request_by_name to get PCIe reset gpio,and using dm_gpio_set_value set GPIO value.
patch 2
1. support PCIeboth 12a and 13b vf2 board.
patch 3
1. reset dts change to reset-gpio.

---

The JH7110 minimal system patchset upstream is in progress. PCIe driver patches is based on this patchset.

The JH7110 minimal system patchset details are listed in [1].

For more JH7110 and visionFive v2 information and support, you can visit RVspace wiki[2].

[2] https://wiki.rvspace.org/

Mason Huo (3):
starfive: pci: Add StarFive JH7110 pcie driver
configs: starfive-jh7110: Add support for PCIe host driver
riscv: dts: starfive: Enable PCIe host controller

 .../dts/jh7110-starfive-visionfive-2.dtsi     |  11 +
 arch/riscv/dts/jh7110.dtsi                    |  74 +++
 configs/starfive_visionfive2_12a_defconfig    |   9 +
 configs/starfive_visionfive2_13b_defconfig    |   9 +
 drivers/pci/Kconfig                           |  11 +
 drivers/pci/Makefile                          |   1 +
 drivers/pci/pcie_starfive_jh7110.c            | 463 ++++++++++++++++++
 7 files changed, 578 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

base-commit: 41a88ad529b3943b1e465846eb24fe2c29203e35
prerequisite-patch-id: a84452ba131408ff842b65ae19a3a05f64b3ff60
prerequisite-patch-id: 4abb46d56dbaf36017b2866688f31a73c2cacd0d
prerequisite-patch-id: ef5e9d61f7392c7d2e5321aa8a10996ca8eae5fc
prerequisite-patch-id: 26dfdb401d680ecd9449acf09131cf4790e987b7
prerequisite-patch-id: a0cfa5d8cdb49bbe9d4739afa90991f882950881
prerequisite-patch-id: 61ceecb41cfd9029bfb267f7b7c5330a2d7e5edc
prerequisite-patch-id: d834ece14ffb525b8c3e661e78736692f33fca9b
prerequisite-patch-id: 88c9f9637335fdc4107d42db67b9110c9b73ead3
prerequisite-patch-id: ebc26ed3f97f7babc0fc805152acb578f5eff922
prerequisite-patch-id: e85a9ca22facac4d5b5562a2708b7332478d6db4
prerequisite-patch-id: ff5bd799e4cb905fef6cf1cd0ce757980e1d34b7
prerequisite-patch-id: a341d4e8a8e25cb711309123939235fcb3c10c1a
prerequisite-patch-id: 749e4eafb431857ee2bec4ac8e78a682f6a57588
prerequisite-patch-id: d4a3666ce2e7135402537cea60e9e6f0435230bf
prerequisite-patch-id: fa8ad1bfce7d6ab74ad63ff8d31dff3c2ccb5e43
prerequisite-patch-id: cc352634b8dfaf2d4243819362326a579e010c94
prerequisite-patch-id: 8e0fa3d987020ca06e22401bc4c69f834c38c3dc

Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v3 1/3 starfive: pci: Add StarFive JH7110 pcie driver

From: Mason Huo <[email protected]>

Add pcie driver for StarFive JH7110, the driver depends on starfive gpio, pinctrl, clk and reset driver to do init.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

---
 drivers/pci/Kconfig                |  11 +
 drivers/pci/Makefile               |   1 +
 drivers/pci/pcie_starfive_jh7110.c | 463 +++++++++++++++++++++++++++++
 3 files changed, 475 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c
drivers/pci/Kconfig +11 -0
index ef328d2652..e7b0ff5bc3 100644
@@ -374,4 +374,15 @@ config PCIE_UNIPHIER
 	  Say Y here if you want to enable PCIe controller support on
 	  UniPhier SoCs.
 
+config PCIE_STARFIVE_JH7110
+	bool "Enable Starfive JH7110 PCIe driver"
+	depends on STARFIVE_JH7110
+	depends on PINCTRL_STARFIVE_JH7110
+	depends on CLK_JH7110
+	depends on RESET_JH7110
+	default y
+	help
+	  Say Y here if you want to enable PCIe controller support on
+	  StarFive JH7110 SoC.
+
 endif
drivers/pci/Makefile +1 -0
index 49506e7ba5..bbe3323bb5 100644
@@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
 obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
drivers/pci/pcie_starfive_jh7110.c new file +462 -0

462 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v3 1/3] starfive: pci: Add StarFive JH7110 pcie driver

Hello!

Quoted 23 lines · On Wednesday 29 March 2023 18:01:41 Minda Chen wrote:

From: Mason Huo <[email protected]>

Add pcie driver for StarFive JH7110, the driver depends on starfive gpio, pinctrl, clk and reset driver to do init.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

---
 drivers/pci/Kconfig                |  11 +
 drivers/pci/Makefile               |   1 +
 drivers/pci/pcie_starfive_jh7110.c | 463 +++++++++++++++++++++++++++++
 3 files changed, 475 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c
drivers/pci/Kconfig +0 -0
index ef328d2652..e7b0ff5bc3 100644

drivers/pci/Kconfig config PCIE_UNIPHIER · line 382

Quoted 9 lines
drivers/pci/Kconfig +6 -0
@@ -374,4 +374,15 @@ config PCIE_UNIPHIER
 	  Say Y here if you want to enable PCIe controller support on
 	  UniPhier SoCs.
 
+config PCIE_STARFIVE_JH7110
+	bool "Enable Starfive JH7110 PCIe driver"
+	depends on STARFIVE_JH7110
+	depends on PINCTRL_STARFIVE_JH7110
+	depends on CLK_JH7110
+	depends on RESET_JH7110

There is no direct hard dependency on on these 4 symbols (or at least I do not see any in include header files). So to allow compile time checks, change it to just soft dependency by switching from "depends" to "imply" keyword.

Quoted 6 lines
drivers/pci/Kconfig +5 -0
+	default y
+	help
+	  Say Y here if you want to enable PCIe controller support on
+	  StarFive JH7110 SoC.
+
 endif

...

Quoted 5 lines
drivers/pci/pcie_starfive_jh7110.c new file +0 -0
new file mode 100644
index 0000000000..1005ed9919

...

drivers/pci/pcie_starfive_jh7110.c line 101

Quoted 7 lines
drivers/pci/pcie_starfive_jh7110.c new file +7 -0
+static int starfive_pcie_off_conf(pci_dev_t bdf, uint offset)
+{
+	unsigned int bus = PCI_BUS(bdf);
+	unsigned int dev = PCI_DEV(bdf);
+	unsigned int func = PCI_FUNC(bdf);
+
+	return PCIE_ECAM_OFFSET(bus, dev, func, offset);

This function is used just on one place, it is pretty straightforward and nothing starfive_pcie-specific. Just directly inline it into starfive_pcie_conf_address() function?

  int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset);

drivers/pci/pcie_starfive_jh7110.c line 114

Quoted 13 lines
drivers/pci/pcie_starfive_jh7110.c new file +13 -0
+}
+
+static int starfive_pcie_addr_valid(pci_dev_t bdf, int first_busno)
+{
+	/*
+	 * Single device limitation.
+	 * For JH7110 SoC limitation, one bus can only connnect one device.
+	 * And PCIe controller contain HW issue that non-root host bridge
+	 * bus emumerate duplicate devices.
+	 * Only can access device 0 in Bus 1 host bridge.
+	 */
+	if ((PCI_BUS(bdf) != first_busno) && (PCI_DEV(bdf) > 0))
+		return 0;

In v2 discussion you wrote that the issue with duplicate devices is on the bus 1, which is secondary bus - the bus behind the root port.

So check against root port bus (first_busno) is not correct, you need to check it against bus behind the root port (secondary bus).

Current check completely filters all devices with numbers higher than 0 behind the secondary bus, which completely breaks support for PCIe switches. Moreover behind PCIe switch can be anything with more complicated topology.

That secondary bus number is dynamically allocated / assigned by U-Boot core code, so you need to check PCI_SECONDARY_BUS register of the root port.

In pci_mvebu.c is this value cached in "->sec_busno" member. You can reuse this pattern.

You probably want this kind of check:

  if (PCI_BUS(bdf) == priv->sec_busno && PCI_DEV(bdf) > 0)
    return false;
  else
    return true;

Also comment "non-root host bridge bus" is strange. Bus of the host bridge is always the root one. You probably want to write the bus immediately behind the root bus / host bridge OR the secondary bus of the host bridge.

drivers/pci/pcie_starfive_jh7110.c line 125

Quoted 11 lines
drivers/pci/pcie_starfive_jh7110.c new file +11 -0
+	return 1;
+}
+
+static int starfive_pcie_conf_address(const struct udevice *udev, pci_dev_t bdf,
+				      uint offset, void **paddr)
+{
+	struct starfive_pcie *priv = dev_get_priv(udev);
+	int where = starfive_pcie_off_conf(bdf, offset);
+
+	if (!starfive_pcie_addr_valid(bdf, priv->first_busno))
+		return -EINVAL;

Maybe better error code is -ENODEV? As technically access request is valid but there is no device on it.

Quoted 5 lines
drivers/pci/pcie_starfive_jh7110.c new file +5 -0
+
+	*paddr = (void *)(priv->cfg_base + where);
+	return 0;
+}
+

...

Quoted 44 lines
drivers/pci/pcie_starfive_jh7110.c new file +44 -0
+static int starfive_pcie_init_port(struct udevice *dev)
+{
+	int ret, i;
+	unsigned int value;
+	struct starfive_pcie *priv = dev_get_priv(dev);
+
+	ret = clk_enable_bulk(&priv->clks);
+	if (ret) {
+		dev_err(dev, "Failed to enable clks (ret=%d)\n", ret);
+		return ret;
+	}
+
+	ret = reset_deassert_bulk(&priv->rsts);
+	if (ret) {
+		dev_err(dev, "Failed to deassert resets (ret=%d)\n", ret);
+		goto err_deassert_clk;
+	}
+
+	dm_gpio_set_value(&priv->reset_gpio, 1);
+	/* Disable physical functions except #0 */
+	for (i = 1; i < PLDA_FUNC_NUM; i++) {
+		regmap_update_bits(priv->regmap,
+				   priv->stg_arfun,
+				   STG_SYSCON_AXI4_SLVL_ARFUNC_MASK,
+				   (i << PLDA_PHY_FUNC_SHIFT) <<
+				   STG_SYSCON_AXI4_SLVL_ARFUNC_SHIFT);
+		regmap_update_bits(priv->regmap,
+				   priv->stg_awfun,
+				   STG_SYSCON_AXI4_SLVL_AWFUNC_MASK,
+				   i << PLDA_PHY_FUNC_SHIFT);
+
+		value = readl(priv->reg_base + PCI_MISC);
+		value |= PLDA_FUNCTION_DIS;
+		writel(value, priv->reg_base + PCI_MISC);
+	}
+
+	/* Disable physical functions */
+	regmap_update_bits(priv->regmap,
+			   priv->stg_arfun,
+			   STG_SYSCON_AXI4_SLVL_ARFUNC_MASK,
+			   0);
+	regmap_update_bits(priv->regmap,
+			   priv->stg_awfun,
+			   STG_SYSCON_AXI4_SLVL_AWFUNC_MASK,

drivers/pci/pcie_starfive_jh7110.c line 376

Quoted 10 lines
drivers/pci/pcie_starfive_jh7110.c new file +10 -0
+			   0);
+
+	/* Enable root port */
+	value = readl(priv->reg_base + GEN_SETTINGS);
+	value |= PLDA_RP_ENABLE;
+	writel(value, priv->reg_base + GEN_SETTINGS);
+
+	/* PCIe PCI Standard Configuration Identification Settings. */
+	value = (PCI_CLASS_BRIDGE_PCI_NORMAL << IDS_CLASS_CODE_SHIFT) | IDS_REVISION_ID;
+	writel(value, priv->reg_base + PCIE_PCI_IDS);

This looks like configuration of the PCI_CLASS_REVISION read-only register. Is there any reason why you are removing the original "revision" information by hardcoded IDS_REVISION_ID constant?

Quoted 9 lines
drivers/pci/pcie_starfive_jh7110.c new file +9 -0
+
+	/*
+	 * The LTR message forwarding of PCIe Message Reception was set by core
+	 * as default, but the forward id & addr are also need to be reset.
+	 * If we do not disable LTR message forwarding here, or set a legal
+	 * forwarding address, the kernel will get stuck after this driver probe.
+	 * To workaround, disable the LTR message forwarding support on
+	 * PCIe Message Reception.
+	 */

drivers/pci/pcie_starfive_jh7110.c line 395

Quoted 10 lines
drivers/pci/pcie_starfive_jh7110.c new file +10 -0
+	value = readl(priv->reg_base + PMSG_SUPPORT_RX);
+	value &= ~PMSG_LTR_SUPPORT;
+	writel(value, priv->reg_base + PMSG_SUPPORT_RX);
+
+	/* Prefetchable memory window 64-bit addressing support */
+	value = readl(priv->reg_base + PCIE_WINROM);
+	value |= PREF_MEM_WIN_64_SUPPORT;
+	writel(value, priv->reg_base + PCIE_WINROM);
+
+	starfive_pcie_atr_init(priv);

This function may fail. But return value is ignored here.

Quoted 11 lines
drivers/pci/pcie_starfive_jh7110.c new file +11 -0
+
+	dm_gpio_set_value(&priv->reset_gpio, 0);
+	/* Ensure that PERST in default at least 300 ms */
+	mdelay(300);
+
+	return 0;
+
+err_deassert_clk:
+	clk_disable_bulk(&priv->clks);
+	return ret;
+}
author
#3 lore raw

Re: [PATCH v3 1/3] starfive: pci: Add StarFive JH7110 pcie driver

Quoted 29 lines · Pali Rohár

Hello!

Quoted 26 lines · On Wednesday 29 March 2023 18:01:41 Minda Chen wrote:

From: Mason Huo <[email protected]>

Add pcie driver for StarFive JH7110, the driver depends on starfive gpio, pinctrl, clk and reset driver to do init.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

---
 drivers/pci/Kconfig                |  11 +
 drivers/pci/Makefile               |   1 +
 drivers/pci/pcie_starfive_jh7110.c | 463 +++++++++++++++++++++++++++++
 3 files changed, 475 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c
drivers/pci/Kconfig +0 -0
index ef328d2652..e7b0ff5bc3 100644
@@ -374,4 +374,15 @@ config PCIE_UNIPHIER
 	  Say Y here if you want to enable PCIe controller support on
 	  UniPhier SoCs.
 
Quoted 12 lines

drivers/pci/Kconfig config PCIE_UNIPHIER · line 382

Quoted 6 lines
drivers/pci/Kconfig +6 -0
+config PCIE_STARFIVE_JH7110
+	bool "Enable Starfive JH7110 PCIe driver"
+	depends on STARFIVE_JH7110
+	depends on PINCTRL_STARFIVE_JH7110
+	depends on CLK_JH7110
+	depends on RESET_JH7110

There is no direct hard dependency on on these 4 symbols (or at least I do not see any in include header files). So to allow compile time checks, change it to just soft dependency by switching from "depends" to "imply" keyword.

ok, I will change this.

Quoted 25 lines
Quoted 6 lines
drivers/pci/Kconfig +5 -0
+	default y
+	help
+	  Say Y here if you want to enable PCIe controller support on
+	  StarFive JH7110 SoC.
+
 endif

...

Quoted 5 lines
drivers/pci/pcie_starfive_jh7110.c new file +0 -0
new file mode 100644
index 0000000000..1005ed9919

...

drivers/pci/pcie_starfive_jh7110.c line 101

Quoted 7 lines
drivers/pci/pcie_starfive_jh7110.c new file +7 -0
+static int starfive_pcie_off_conf(pci_dev_t bdf, uint offset)
+{
+	unsigned int bus = PCI_BUS(bdf);
+	unsigned int dev = PCI_DEV(bdf);
+	unsigned int func = PCI_FUNC(bdf);
+
+	return PCIE_ECAM_OFFSET(bus, dev, func, offset);

This function is used just on one place, it is pretty straightforward and nothing starfive_pcie-specific. Just directly inline it into starfive_pcie_conf_address() function?

Quoted 2 lines
  int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset);

ok, thanks

Quoted 32 lines

drivers/pci/pcie_starfive_jh7110.c line 114

Quoted 13 lines
drivers/pci/pcie_starfive_jh7110.c new file +13 -0
+}
+
+static int starfive_pcie_addr_valid(pci_dev_t bdf, int first_busno)
+{
+	/*
+	 * Single device limitation.
+	 * For JH7110 SoC limitation, one bus can only connnect one device.
+	 * And PCIe controller contain HW issue that non-root host bridge
+	 * bus emumerate duplicate devices.
+	 * Only can access device 0 in Bus 1 host bridge.
+	 */
+	if ((PCI_BUS(bdf) != first_busno) && (PCI_DEV(bdf) > 0))
+		return 0;

In v2 discussion you wrote that the issue with duplicate devices is on the bus 1, which is secondary bus - the bus behind the root port.

So check against root port bus (first_busno) is not correct, you need to check it against bus behind the root port (secondary bus).

Current check completely filters all devices with numbers higher than 0 behind the secondary bus, which completely breaks support for PCIe switches. Moreover behind PCIe switch can be anything with more complicated topology.

That secondary bus number is dynamically allocated / assigned by U-Boot core code, so you need to check PCI_SECONDARY_BUS register of the root port.

In pci_mvebu.c is this value cached in "->sec_busno" member. You can reuse this pattern.

Quoted 7 lines

You probably want this kind of check:

  if (PCI_BUS(bdf) == priv->sec_busno && PCI_DEV(bdf) > 0)
    return false;
  else
    return true;

OK, thanks, I will record secondary busno according PCI_SECONDARY_BUS register

Quoted 5 lines

Also comment "non-root host bridge bus" is strange. Bus of the host bridge is always the root one. You probably want to write the bus immediately behind the root bus / host bridge OR the secondary bus of the host bridge.

ok

Quoted 6 lines
Quoted 6 lines
drivers/pci/pcie_starfive_jh7110.c new file +6 -0
+	return 1;
+}
+
+static int starfive_pcie_conf_address(const struct udevice *udev, pci_dev_t bdf,
+				      uint offset, void **paddr)
+{
Quoted 9 lines

drivers/pci/pcie_starfive_jh7110.c line 125

Quoted 5 lines
drivers/pci/pcie_starfive_jh7110.c new file +5 -0
+	struct starfive_pcie *priv = dev_get_priv(udev);
+	int where = starfive_pcie_off_conf(bdf, offset);
+
+	if (!starfive_pcie_addr_valid(bdf, priv->first_busno))
+		return -EINVAL;

Maybe better error code is -ENODEV? As technically access request is valid but there is no device on it.

ok

Quoted 56 lines
Quoted 5 lines
drivers/pci/pcie_starfive_jh7110.c new file +5 -0
+
+	*paddr = (void *)(priv->cfg_base + where);
+	return 0;
+}
+

...

Quoted 50 lines
drivers/pci/pcie_starfive_jh7110.c new file +50 -0
+static int starfive_pcie_init_port(struct udevice *dev)
+{
+	int ret, i;
+	unsigned int value;
+	struct starfive_pcie *priv = dev_get_priv(dev);
+
+	ret = clk_enable_bulk(&priv->clks);
+	if (ret) {
+		dev_err(dev, "Failed to enable clks (ret=%d)\n", ret);
+		return ret;
+	}
+
+	ret = reset_deassert_bulk(&priv->rsts);
+	if (ret) {
+		dev_err(dev, "Failed to deassert resets (ret=%d)\n", ret);
+		goto err_deassert_clk;
+	}
+
+	dm_gpio_set_value(&priv->reset_gpio, 1);
+	/* Disable physical functions except #0 */
+	for (i = 1; i < PLDA_FUNC_NUM; i++) {
+		regmap_update_bits(priv->regmap,
+				   priv->stg_arfun,
+				   STG_SYSCON_AXI4_SLVL_ARFUNC_MASK,
+				   (i << PLDA_PHY_FUNC_SHIFT) <<
+				   STG_SYSCON_AXI4_SLVL_ARFUNC_SHIFT);
+		regmap_update_bits(priv->regmap,
+				   priv->stg_awfun,
+				   STG_SYSCON_AXI4_SLVL_AWFUNC_MASK,
+				   i << PLDA_PHY_FUNC_SHIFT);
+
+		value = readl(priv->reg_base + PCI_MISC);
+		value |= PLDA_FUNCTION_DIS;
+		writel(value, priv->reg_base + PCI_MISC);
+	}
+
+	/* Disable physical functions */
+	regmap_update_bits(priv->regmap,
+			   priv->stg_arfun,
+			   STG_SYSCON_AXI4_SLVL_ARFUNC_MASK,
+			   0);
+	regmap_update_bits(priv->regmap,
+			   priv->stg_awfun,
+			   STG_SYSCON_AXI4_SLVL_AWFUNC_MASK,
+			   0);
+
+	/* Enable root port */
+	value = readl(priv->reg_base + GEN_SETTINGS);
+	value |= PLDA_RP_ENABLE;
+	writel(value, priv->reg_base + GEN_SETTINGS);
Quoted 9 lines

drivers/pci/pcie_starfive_jh7110.c line 376

Quoted 4 lines
drivers/pci/pcie_starfive_jh7110.c new file +4 -0
+
+	/* PCIe PCI Standard Configuration Identification Settings. */
+	value = (PCI_CLASS_BRIDGE_PCI_NORMAL << IDS_CLASS_CODE_SHIFT) | IDS_REVISION_ID;
+	writel(value, priv->reg_base + PCIE_PCI_IDS);

This looks like configuration of the PCI_CLASS_REVISION read-only register. Is there any reason why you are removing the original "revision" information by hardcoded IDS_REVISION_ID constant?

This register is not read-only register, consist resion ID and class code.
Bit [39:32]: Revision ID
Bit [63:40]: Class code
And the register reset value is zero, Our PCIe version is 2.0. So set value 2. Maybe I will add comment to this.

Quoted 13 lines
Quoted 13 lines
drivers/pci/pcie_starfive_jh7110.c new file +13 -0
+
+	/*
+	 * The LTR message forwarding of PCIe Message Reception was set by core
+	 * as default, but the forward id & addr are also need to be reset.
+	 * If we do not disable LTR message forwarding here, or set a legal
+	 * forwarding address, the kernel will get stuck after this driver probe.
+	 * To workaround, disable the LTR message forwarding support on
+	 * PCIe Message Reception.
+	 */
+	value = readl(priv->reg_base + PMSG_SUPPORT_RX);
+	value &= ~PMSG_LTR_SUPPORT;
+	writel(value, priv->reg_base + PMSG_SUPPORT_RX);
+
Quoted 9 lines

drivers/pci/pcie_starfive_jh7110.c line 395

Quoted 6 lines
drivers/pci/pcie_starfive_jh7110.c new file +6 -0
+	/* Prefetchable memory window 64-bit addressing support */
+	value = readl(priv->reg_base + PCIE_WINROM);
+	value |= PREF_MEM_WIN_64_SUPPORT;
+	writel(value, priv->reg_base + PCIE_WINROM);
+
+	starfive_pcie_atr_init(priv);

This function may fail. But return value is ignored here.

ok

Quoted 11 lines
Quoted 11 lines
drivers/pci/pcie_starfive_jh7110.c new file +11 -0
+
+	dm_gpio_set_value(&priv->reset_gpio, 0);
+	/* Ensure that PERST in default at least 300 ms */
+	mdelay(300);
+
+	return 0;
+
+err_deassert_clk:
+	clk_disable_bulk(&priv->clks);
+	return ret;
+}
#4 lore raw

Re: [PATCH v3 1/3] starfive: pci: Add StarFive JH7110 pcie driver

Quoted 12 lines · On Friday 31 March 2023 18:35:00 Minda Chen wrote:
Quoted 11 lines · Pali Rohár

Hello!

drivers/pci/pcie_starfive_jh7110.c line 376

Quoted 3 lines · On Wednesday 29 March 2023 18:01:41 Minda Chen wrote:
drivers/pci/pcie_starfive_jh7110.c new file +3 -0
+	/* PCIe PCI Standard Configuration Identification Settings. */
+	value = (PCI_CLASS_BRIDGE_PCI_NORMAL << IDS_CLASS_CODE_SHIFT) | IDS_REVISION_ID;
+	writel(value, priv->reg_base + PCIE_PCI_IDS);

This looks like configuration of the PCI_CLASS_REVISION read-only register. Is there any reason why you are removing the original "revision" information by hardcoded IDS_REVISION_ID constant?

Quoted 3 lines

This register is not read-only register, consist resion ID and class code.
Bit [39:32]: Revision ID
Bit [63:40]: Class code

I mean that this "priv->reg_base + PCIE_PCI_IDS" read-write register configures what is visible when reading read-only standard PCI register PCI_CLASS_REVISION.

PCIe Root Port is by definition of PCI-to-PCI Bridge class and therefore reading from PCI_CLASS_REVISION must return PCI_CLASS_BRIDGE_PCI_* value. This is required by PCIe spec.

With above driver init code it looks like that your PCIe controller does not set correct value into PCI_CLASS_REVISION register after power-on and manually setting correct value via "priv->reg_base + PCIE_PCI_IDS" is a workaround.

Hopefully it is a more clear what I mean in my previous email.

Also mvebu controller has this issue and has similar workaround in pci_mvebu.c driver.

Quoted 2 lines

And the register reset value is zero, Our PCIe version is 2.0. So set value 2. Maybe I will add comment to this.

Well, Revision ID (low 8 bits of PCI_CLASS_REVISION) is the extension to the vendor / device id register. It is not version of PCIe standard.

I would expect that this Vendor ID, Device ID and Revision ID values are not being changed by the driver as they identify PCI and PCIe devices.

author
#5 lore raw

Re: [PATCH v3 1/3] starfive: pci: Add StarFive JH7110 pcie driver

Quoted 36 lines · Pali Rohár
Quoted 12 lines · On Friday 31 March 2023 18:35:00 Minda Chen wrote:
Quoted 11 lines · Pali Rohár

Hello!

drivers/pci/pcie_starfive_jh7110.c line 376

Quoted 3 lines · On Wednesday 29 March 2023 18:01:41 Minda Chen wrote:
drivers/pci/pcie_starfive_jh7110.c new file +3 -0
+	/* PCIe PCI Standard Configuration Identification Settings. */
+	value = (PCI_CLASS_BRIDGE_PCI_NORMAL << IDS_CLASS_CODE_SHIFT) | IDS_REVISION_ID;
+	writel(value, priv->reg_base + PCIE_PCI_IDS);

This looks like configuration of the PCI_CLASS_REVISION read-only register. Is there any reason why you are removing the original "revision" information by hardcoded IDS_REVISION_ID constant?

Quoted 3 lines

This register is not read-only register, consist resion ID and class code.
Bit [39:32]: Revision ID
Bit [63:40]: Class code

I mean that this "priv->reg_base + PCIE_PCI_IDS" read-write register configures what is visible when reading read-only standard PCI register PCI_CLASS_REVISION.

PCIe Root Port is by definition of PCI-to-PCI Bridge class and therefore reading from PCI_CLASS_REVISION must return PCI_CLASS_BRIDGE_PCI_* value. This is required by PCIe spec.

With above driver init code it looks like that your PCIe controller does not set correct value into PCI_CLASS_REVISION register after power-on and manually setting correct value via "priv->reg_base + PCIE_PCI_IDS" is a workaround.

Hopefully it is a more clear what I mean in my previous email.

Also mvebu controller has this issue and has similar workaround in pci_mvebu.c driver.

Quoted 8 lines
Quoted 2 lines

And the register reset value is zero, Our PCIe version is 2.0. So set value 2. Maybe I will add comment to this.

Well, Revision ID (low 8 bits of PCI_CLASS_REVISION) is the extension to the vendor / device id register. It is not version of PCIe standard.

I would expect that this Vendor ID, Device ID and Revision ID values are not being changed by the driver as they identify PCI and PCIe devices.

I am sorry. It is PCIe controller IP revision ID. I have make a mistake for it. So zero value is correct. I will remove writing IDS_REVISION_ID value.

author
#6 lore raw

PATCH v3 2/3 configs: starfive-jh7110: Add support for PCIe host driver

In reply to Minda Chen

From: Mason Huo <[email protected]>

also add the nvme driver and rtl8169 support.

---
 configs/starfive_visionfive2_12a_defconfig | 9 +++++++++
 configs/starfive_visionfive2_13b_defconfig | 9 +++++++++
 2 files changed, 18 insertions(+)
configs/starfive_visionfive2_12a_defconfig +9 -0
index e0f98292ff..2a7563743b 100644
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x82000000
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x40000000
 CONFIG_ARCH_RV64I=y
@@ -49,9 +50,12 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x4000000
+CONFIG_CMD_PCI=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,11 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
configs/starfive_visionfive2_13b_defconfig +9 -0
index 550d0ff3ab..98d23d9461 100644
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x82000000
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x40000000
 CONFIG_ARCH_RV64I=y
@@ -50,8 +51,11 @@ CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x4000000
 CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,11 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
Signature · 1 line
2.17.1
author
#7 lore raw

PATCH v3 3/3 riscv: dts: starfive: Enable PCIe host controller

In reply to Minda Chen

From: Mason Huo <[email protected]>

Enable and add pinctrl configuration for PCIe host controller. Also add JH7110 stg syscon configuration.

---
 .../dts/jh7110-starfive-visionfive-2.dtsi     | 11 +++
 arch/riscv/dts/jh7110.dtsi                    | 74 +++++++++++++++++++
 2 files changed, 85 insertions(+)
arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi +11 -0
index c6b6dfa940..12245576ac 100644
@@ -7,6 +7,7 @@
 
 #include "jh7110.dtsi"
 #include <dt-bindings/pinctrl/pinctrl-starfive-jh7110.h>
+#include <dt-bindings/gpio/gpio.h>
 / {
 	aliases {
 		serial0 = &uart0;
@@ -300,6 +301,16 @@
 	};
 };
 
+&pcie0 {
+	reset-gpios = <&sysgpio 26 GPIO_ACTIVE_LOW>;
+	status = "disabled";
+};
+
+&pcie1 {
+	reset-gpios = <&sysgpio 28 GPIO_ACTIVE_LOW>;
+	status = "okay";
+};
+
 &syscrg {
 	assigned-clocks = <&syscrg JH7110_SYSCLK_CPU_ROOT>,
 			  <&syscrg JH7110_SYSCLK_BUS_ROOT>,
arch/riscv/dts/jh7110.dtsi +74 -0

79 lines not on this page · raw message

Signature · 1 line
2.17.1