Skip to contentSkip to conversation

Introduce SpacemiT K1 PCIe phy and host controller

PATCH Superseded Alex Elder 6 participants 40 messages Oct 13, 2025 – Nov 3, 2025

Subsystems (6)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

v2 cover Introduce SpacemiT K1 PCIe phy and host controller

This series introduces a PHY driver and a PCIe driver to support PCIe on the SpacemiT K1 SoC. The PCIe implementation is derived from a Synopsys DesignWare PCIe IP. The PHY driver supports one combination PCIe/USB PHY as well as two PCIe-only PHYs. The combo PHY port uses one PCIe lane, and the other two ports each have two lanes. All PCIe ports operate at 5 GT/second.

The PCIe PHYs must be configured using a value that can only be determined using the combo PHY, operating in PCIe mode. To allow that PHY to be used for USB, the calibration step is performed by the PHY driver automatically at probe time. Once this step is done, the PHY can be used for either PCIe or USB.

Version 2 of this series incorporates suggestions made during the review of version 1. Specific highlights are detailed below.

-Alex

This series is available here:
https://github.com/riscstar/linux/tree/outgoing/pcie-v2

Between version 1 and version 2:
- General
- VENDOR ID 0x201f is now registered with PCI SIG: "SpacemiT (Hangzhou) Technology Co. Ltd"
https://pcisig.com/membership/member-companies?combine=201f
- The PCIe host compatible string is now "spacemit,k1-pcie"
- Reimplemented the PHY PLL as a clock registered with the common clock framework, driven by an external oscillator
- Added the external oscillator clock to the PHY binding
- Renamed the PCIe driver source file "pcie-spacemit-k1.c"
- Kconfig
- Renamed the PCIe driver Kconfig option PCIE_SPACEMIT_K1
- The PCIe driver is now defined as tristate, not Boolean
- Updated the PCIe host Kconfig based on Bjorn H's feedback
- DT Bindings
- Corrected PCIe node ranges properties
- Replaced "interrupts-extended" property with just "interrupts" in the PCIe host binding
- Named the single PCIe interrupt "msi" to clarify its purpose
- Added a new vpcie3v3-supply property for PCIe ports
- Renamed a syscon property to align with other SpacemiT bindings
- Removed labels and status properties in DT binding examples
- Added a '>' to DT binding descriptions to preserve formatting
- Consistently ended DT binding descriptions with no period
- Dropped ".yaml" from the PCIe host compatible string
- Dropped unneeded max-link-speed property from PCIe binding, relying on the hardware default value instead
- No longer require the bus-ranges PCIe property; if not provided, the default value used is exactly what's desired
- Code
- Renamed the symbols representing the PCI vendor and device IDs to align with <linux/pci_ids.h>
- Use PCIE_T_PVPERL_MS rather than 100 to represent a standard delay period.
- Use platform (not dev) driver-data access functions; assignment is done only after the private structure is initialized
- Deleted some unneeded includes in the PCIe driver.
- Dropped error checking when operating on MMIO-backed regmaps
- Added a regmap_read() call in two places, to ensure a specified delay occurs *after* the a MMIO write has reached its target.
- Used ARRAY_SIZE() (not a local variable value) in a few spots
- Now use readl_relaxed()/writel_relaxed() when operating on the "link" I/O memory space in the PCIe driver
- Updated a few error messages for consistency
- No longer specify suppress_bind_attrs in the PCIe driver
- Now specify PCIe driver probe type as PROBE_PREFER_ASYNCHRONOUS
- Miscellany
- Subject on the PCIe host binding includes "pci", not "phy"
- Clarified that the DesignWare built-in MSI controller is used
- Use "PCIe gen2" terminology (rather than "PCIe v2")
- No longer use (void) cast to indicate ignored return values

Here is version 1 of this series:
https://lore.kernel.org/lkml/[email protected]/

Alex Elder (7):
dt-bindings: phy: spacemit: add SpacemiT PCIe/combo PHY
dt-bindings: phy: spacemit: introduce PCIe PHY
dt-bindings: pci: spacemit: introduce PCIe host controller
phy: spacemit: introduce PCIe/combo PHY
PCI: spacemit: introduce SpacemiT PCIe host driver
riscv: dts: spacemit: add a PCIe regulator
riscv: dts: spacemit: PCIe and PHY-related updates

 .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++
 .../bindings/phy/spacemit,k1-combo-phy.yaml   | 114 +++
 .../bindings/phy/spacemit,k1-pcie-phy.yaml    |  59 ++
 .../boot/dts/spacemit/k1-bananapi-f3.dts      |  38 +
 arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi  |  33 +
 arch/riscv/boot/dts/spacemit/k1.dtsi          | 151 ++++
 drivers/pci/controller/dwc/Kconfig            |  10 +
 drivers/pci/controller/dwc/Makefile           |   1 +
 drivers/pci/controller/dwc/pcie-spacemit-k1.c | 319 +++++++++
 drivers/phy/Kconfig                           |  11 +
 drivers/phy/Makefile                          |   1 +
 drivers/phy/phy-spacemit-k1-pcie.c            | 672 ++++++++++++++++++
 12 files changed, 1565 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml
 create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml
 create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yaml
 create mode 100644 drivers/pci/controller/dwc/pcie-spacemit-k1.c
 create mode 100644 drivers/phy/phy-spacemit-k1-pcie.c

base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787

Signature · 1 line
2.48.1
author
#1 lore raw

PATCH v2 1/7 dt-bindings: phy: spacemit: add SpacemiT PCIe/combo PHY

Add the Device Tree binding for the PCIe/USB 3.0 combo PHY found in the SpacemiT K1 SoC. This is one of three PCIe PHYs, and is unusual in that only the combo PHY can perform a calibration step needed to determine settings used by the other two PCIe PHYs.

Calibration must be done with the combo PHY in PCIe mode, and to allow this to occur independent of the eventual use for the PHY (PCIe or USB) some PCIe-related properties must be supplied: clocks; resets; and a syscon phandle.

---
v2: - Added '>' to the description, and reworded it a bit
- Added an external oscillator clock, "refclk"
- Renamed the "global" reset to be "phy"
- Renamed a phandle property to be "spacemit,apmu"
- Dropped the label and status property from the example

 .../bindings/phy/spacemit,k1-combo-phy.yaml   | 114 ++++++++++++++++++
 1 file changed, 114 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml
Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml new file +114 -0
new file mode 100644
index 0000000000000..6e2f401b0ac27
@@ -0,0 +1,114 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/spacemit,k1-combo-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCIe/USB3 Combo PHY
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  Of the three PHYs on the SpacemiT K1 SoC capable of being used for
+  PCIe, one is a combo PHY that can also be configured for use by a
+  USB 3 controller.  Using PCIe or USB 3 is a board design decision.
+
+  The combo PHY is also the only PCIe PHY that is able to determine
+  PCIe calibration values to use, and this must be determined before
+  the other two PCIe PHYs can be used.  This calibration must be
+  performed with the combo PHY in PCIe mode, and is this is done
+  when the combo PHY is probed.
+
+  The combo PHY uses an external oscillator as a reference clock.
+  During normal operation, the PCIe or USB port driver is responsible
+  for ensuring all other clocks needed by a PHY are enabled, and all
+  resets affecting the PHY are deasserted.  However, for the combo
+  PHY to perform calibration independent of whether it's later used
+  for PCIe or USB, all PCIe mode clocks and resets must be defined.
+
+properties:
+  compatible:
+    const: spacemit,k1-combo-phy
+
+  reg:
+    items:
+      - description: PHY control registers
+
+  clocks:
+    items:
+      - description: External oscillator used by the PHY PLL
+      - description: DWC PCIe Data Bus Interface (DBI) clock
+      - description: DWC PCIe application AXI-bus Master interface clock
+      - description: DWC PCIe application AXI-bus slave interface clock
+
+  clock-names:
+    items:
+      - const: refclk
+      - const: dbi
+      - const: mstr
+      - const: slv
+
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset
+      - description: DWC PCIe application AXI-bus Master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: PHY reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy
+
+  spacemit,apmu:
+    description:
+      A phandle that refers to the APMU system controller, whose
+      regmap is used in setting the mode
+    $ref: /schemas/types.yaml#/definitions/phandle
+
+  "#phy-cells":
+    const: 1
+    description:
+      The argument value (PHY_TYPE_PCIE or PHY_TYPE_USB3) determines
+      whether the PHY operates in PCIe or USB3 mode.
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - spacemit,apmu
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/spacemit,k1-syscon.h>
+    phy@c0b10000 {
+        compatible = "spacemit,k1-combo-phy";
+        reg = <0xc0b10000 0x1000>;
+        clocks = <&vctcxo_24m>,
+                 <&syscon_apmu CLK_PCIE0_DBI>,
+                 <&syscon_apmu CLK_PCIE0_MASTER>,
+                 <&syscon_apmu CLK_PCIE0_SLAVE>;
+        clock-names = "refclk",
+                      "dbi",
+                      "mstr",
+                      "slv";
+        resets = <&syscon_apmu RESET_PCIE0_DBI>,
+                 <&syscon_apmu RESET_PCIE0_MASTER>,
+                 <&syscon_apmu RESET_PCIE0_SLAVE>,
+                 <&syscon_apmu RESET_PCIE0_GLOBAL>;
+        reset-names = "dbi",
+                      "mstr",
+                      "slv",
+                      "phy";
+        spacemit,apmu = <&syscon_apmu>;
+        #phy-cells = <1>;
+    };
Signature · 1 line
2.48.1
maintainer Reviewed-by on v2 1/7
#2 lore raw

Re: [PATCH v2 1/7] dt-bindings: phy: spacemit: add SpacemiT PCIe/combo PHY

Quoted 82 lines · Alex Elder

Add the Device Tree binding for the PCIe/USB 3.0 combo PHY found in the SpacemiT K1 SoC. This is one of three PCIe PHYs, and is unusual in that only the combo PHY can perform a calibration step needed to determine settings used by the other two PCIe PHYs.

Calibration must be done with the combo PHY in PCIe mode, and to allow this to occur independent of the eventual use for the PHY (PCIe or USB) some PCIe-related properties must be supplied: clocks; resets; and a syscon phandle.

---
v2: - Added '>' to the description, and reworded it a bit
- Added an external oscillator clock, "refclk"
- Renamed the "global" reset to be "phy"
- Renamed a phandle property to be "spacemit,apmu"
- Dropped the label and status property from the example

 .../bindings/phy/spacemit,k1-combo-phy.yaml   | 114 ++++++++++++++++++
 1 file changed, 114 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml
Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml new file +54 -0
new file mode 100644
index 0000000000000..6e2f401b0ac27
@@ -0,0 +1,114 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/spacemit,k1-combo-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCIe/USB3 Combo PHY
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  Of the three PHYs on the SpacemiT K1 SoC capable of being used for
+  PCIe, one is a combo PHY that can also be configured for use by a
+  USB 3 controller.  Using PCIe or USB 3 is a board design decision.
+
+  The combo PHY is also the only PCIe PHY that is able to determine
+  PCIe calibration values to use, and this must be determined before
+  the other two PCIe PHYs can be used.  This calibration must be
+  performed with the combo PHY in PCIe mode, and is this is done
+  when the combo PHY is probed.
+
+  The combo PHY uses an external oscillator as a reference clock.
+  During normal operation, the PCIe or USB port driver is responsible
+  for ensuring all other clocks needed by a PHY are enabled, and all
+  resets affecting the PHY are deasserted.  However, for the combo
+  PHY to perform calibration independent of whether it's later used
+  for PCIe or USB, all PCIe mode clocks and resets must be defined.
+
+properties:
+  compatible:
+    const: spacemit,k1-combo-phy
+
+  reg:
+    items:
+      - description: PHY control registers
+
+  clocks:
+    items:
+      - description: External oscillator used by the PHY PLL
+      - description: DWC PCIe Data Bus Interface (DBI) clock
+      - description: DWC PCIe application AXI-bus Master interface clock
+      - description: DWC PCIe application AXI-bus slave interface clock
+
+  clock-names:
+    items:
+      - const: refclk
+      - const: dbi
+      - const: mstr
+      - const: slv
+
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset

Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml line 64

Quoted 10 lines
Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml new file +10 -0
+      - description: DWC PCIe application AXI-bus Master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: PHY reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy

I think phy should be first as that's the main one to the phy and the others are somewhat questionable. Otherwise,

author
#3 lore raw

Re: [PATCH v2 1/7] dt-bindings: phy: spacemit: add SpacemiT PCIe/combo PHY

Quoted 13 lines · Rob Herring

Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml line 64

Quoted 13 lines
Documentation/devicetree/bindings/phy/spacemit,k1-combo-phy.yaml new file +13 -0
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset
+      - description: DWC PCIe application AXI-bus Master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: PHY reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy
Quoted 4 lines

I think phy should be first as that's the main one to the phy and the others are somewhat questionable. Otherwise,

OK I'll arrange them that way in v3. Thank you. -Alex

author
#4 lore raw

PATCH v2 2/7 dt-bindings: phy: spacemit: introduce PCIe PHY

In reply to Alex Elder

Add the Device Tree binding for two PCIe PHYs present on the SpacemiT K1 SoC. These PHYs are dependent on a separate combo PHY, which determines at probe time the calibration values used by the PCIe-only PHYs.

---
v2: - Added '>' to the description, and reworded it a bit
- Added clocks and clock-names properties
- Dropped the label and status property from the example

 .../bindings/phy/spacemit,k1-pcie-phy.yaml    | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yaml
Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yaml new file +59 -0
new file mode 100644
index 0000000000000..c821f6cafcdae
@@ -0,0 +1,59 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/spacemit,k1-pcie-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCIe PHY
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  There are two PHYs on the SpacemiT K1 SoC used for PCIe (only).
+  These PHYs must be configured using calibration values that are
+  determined by a third "combo PHY".  The combo PHY determines
+  these calibration values during probe so they can be used for
+  the two PCIe-only PHYs.
+
+  The PHY uses an external oscillator as a reference clock.  During
+  normal operation, the PCIe host driver is responsible for ensuring
+  all other clocks needed by a PHY are enabled, and all resets
+  affecting the PHY are deasserted.
+
+properties:
+  compatible:
+    const: spacemit,k1-pcie-phy
+
+  reg:
+    items:
+      - description: PHY control registers
+
+  clocks:
+    items:
+      - description: External oscillator used by the PHY PLL
+
+  clock-names:
+    const: refclk
+
+  "#phy-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    phy@c0c10000 {
+        compatible = "spacemit,k1-pcie-phy";
+        reg = <0xc0c10000 0x1000>;
+        clocks = <&vctcxo_24m>;
+        clock-names = "refclk";
+        #phy-cells = <0>;
+    };
Signature · 1 line
2.48.1
maintainer Reviewed-by on v2 2/7
#5 lore raw

Re: [PATCH v2 2/7] dt-bindings: phy: spacemit: introduce PCIe PHY

Quoted 6 lines · Alex Elder

Add the Device Tree binding for two PCIe PHYs present on the SpacemiT K1 SoC. These PHYs are dependent on a separate combo PHY, which determines at probe time the calibration values used by the PCIe-only PHYs.

Quoted 9 lines

---
v2: - Added '>' to the description, and reworded it a bit
- Added clocks and clock-names properties
- Dropped the label and status property from the example

 .../bindings/phy/spacemit,k1-pcie-phy.yaml    | 59 +++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yaml
author
#6 lore raw

Re: [PATCH v2 2/7] dt-bindings: phy: spacemit: introduce PCIe PHY

Quoted 13 lines · Rob Herring (Arm)
Quoted 11 lines · Alex Elder

Add the Device Tree binding for two PCIe PHYs present on the SpacemiT K1 SoC. These PHYs are dependent on a separate combo PHY, which determines at probe time the calibration values used by the PCIe-only PHYs.

---
v2: - Added '>' to the description, and reworded it a bit
- Added clocks and clock-names properties
- Dropped the label and status property from the example

Quoted 6 lines
Quoted 4 lines
  .../bindings/phy/spacemit,k1-pcie-phy.yaml    | 59 +++++++++++++++++++
  1 file changed, 59 insertions(+)

create mode 100644 Documentation/devicetree/bindings/phy/spacemit,k1-pcie-phy.yaml

Thanks. -Alex

author
#7 lore raw

PATCH v2 3/7 dt-bindings: pci: spacemit: introduce PCIe host controller

In reply to Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

 .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
 1 file changed, 156 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +156 -0
new file mode 100644
index 0000000000000..87745d49c53a1
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  The SpacemiT K1 SoC PCIe host controller is based on the Synopsys
+  DesignWare PCIe IP.  The controller uses the DesignWare built-in
+  MSI interrupt controller, and supports 256 MSIs.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: spacemit,k1-pcie
+
+  reg:
+    items:
+      - description: DesignWare PCIe registers
+      - description: ATU address space
+      - description: PCIe configuration space
+      - description: Link control registers
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: atu
+      - const: config
+      - const: link
+
+  spacemit,apmu:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description:
+      A phandle that refers to the APMU system controller, whose
+      regmap is used in managing resets and link state, along with
+      and offset of its reset control register.
+    items:
+      - items:
+          - description: phandle to APMU system controller
+          - description: register offset
+
+  clocks:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) clock
+      - description: DWC PCIe application AXI-bus master interface clock
+      - description: DWC PCIe application AXI-bus slave interface clock
+
+  clock-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset
+      - description: DWC PCIe application AXI-bus master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: Global reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy
+
+  interrupts:
+    items:
+      - description: Interrupt used for MSIs
+
+  interrupt-names:
+    const: msi
+
+  phys:
+    maxItems: 1
+
+  vpcie3v3-supply:
+    description:
+      A phandle for 3.3v regulator to use for PCIe
+
+  device_type:
+    const: pci
+
+  num-viewport:
+    const: 8
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - spacemit,apmu
+  - "#address-cells"
+  - "#size-cells"
+  - ranges
+  - clocks
+  - clock-names
+  - resets
+  - reset-names
+  - interrupts
+  - interrupt-names
+  - phys
+  - vpcie3v3-supply
+  - device_type
+  - num-viewport
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/spacemit,k1-syscon.h>
+    pcie@ca400000 {
+        compatible = "spacemit,k1-pcie";
+        reg = <0xca400000 0x00001000>,
+              <0xca700000 0x0001ff24>,
+              <0x9f000000 0x00002000>,
+              <0xc0c20000 0x00001000>;
+        reg-names = "dbi",
+                    "atu",
+                    "config",
+                    "link";
+        #address-cells = <3>;
+        #size-cells = <2>;
+        ranges = <0x01000000 0x0 0x00000000 0x9f002000 0x0 0x00100000>,
+                 <0x02000000 0x0 0x90000000 0x90000000 0x0 0x0f000000>;
+        interrupts = <142>;
+        interrupt-names = "msi";
+        clocks = <&syscon_apmu CLK_PCIE1_DBI>,
+                 <&syscon_apmu CLK_PCIE1_MASTER>,
+                 <&syscon_apmu CLK_PCIE1_SLAVE>;
+        clock-names = "dbi",
+                      "mstr",
+                      "slv";
+        resets = <&syscon_apmu RESET_PCIE1_DBI>,
+                 <&syscon_apmu RESET_PCIE1_MASTER>,
+                 <&syscon_apmu RESET_PCIE1_SLAVE>,
+                 <&syscon_apmu RESET_PCIE1_GLOBAL>;
+        reset-names = "dbi",
+                      "mstr",
+                      "slv",
+                      "phy";
+        phys = <&pcie1_phy>;
+        vpcie3v3-supply = <&pcie_vcc_3v3>;
+        device_type = "pci";
+        num-viewport = <8>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&pcie1_3_cfg>;
+        spacemit,apmu = <&syscon_apmu 0x3d4>;
+    };
Signature · 1 line
2.48.1
#8 lore raw

Re: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller

Quoted 52 lines · Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

 .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
 1 file changed, 156 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +20 -0
new file mode 100644
index 0000000000000..87745d49c53a1
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  The SpacemiT K1 SoC PCIe host controller is based on the Synopsys
+  DesignWare PCIe IP.  The controller uses the DesignWare built-in
+  MSI interrupt controller, and supports 256 MSIs.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:

...

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 93

Quoted 2 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +2 -0
+  num-viewport:
+    const: 8

This property has been deprecated for a long time, and the driver now detects viewports at runtime since commit 281f1f99cf3a (PCI: dwc: Detect number of iATU windows, 2020-11-05), IOW, it makes no effect with the current mainline DWC PCIe driver. Is it really necessary?

Best regards,
Yao Zi

author
#9 lore raw

Re: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller

Quoted 56 lines · Yao Zi
Quoted 52 lines · Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

  .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
  1 file changed, 156 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +20 -0
new file mode 100644
index 0000000000000..87745d49c53a1
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  The SpacemiT K1 SoC PCIe host controller is based on the Synopsys
+  DesignWare PCIe IP.  The controller uses the DesignWare built-in
+  MSI interrupt controller, and supports 256 MSIs.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:

...

Quoted 7 lines

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 93

Quoted 2 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +2 -0
+  num-viewport:
+    const: 8

This property has been deprecated for a long time, and the driver now detects viewports at runtime since commit 281f1f99cf3a (PCI: dwc: Detect number of iATU windows, 2020-11-05), IOW, it makes no effect with the current mainline DWC PCIe driver. Is it really necessary?

Based on what you say, the answer is "no" and I'll gladly remove it.

Thanks.

-Alex

Quoted 2 lines

Best regards,
Yao Zi

maintainer
#10 lore raw

Re: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller

In reply to Alex Elder
Quoted 95 lines · Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

 .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
 1 file changed, 156 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +63 -0
new file mode 100644
index 0000000000000..87745d49c53a1
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  The SpacemiT K1 SoC PCIe host controller is based on the Synopsys
+  DesignWare PCIe IP.  The controller uses the DesignWare built-in
+  MSI interrupt controller, and supports 256 MSIs.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: spacemit,k1-pcie
+
+  reg:
+    items:
+      - description: DesignWare PCIe registers
+      - description: ATU address space
+      - description: PCIe configuration space
+      - description: Link control registers
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: atu
+      - const: config
+      - const: link
+
+  spacemit,apmu:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description:
+      A phandle that refers to the APMU system controller, whose
+      regmap is used in managing resets and link state, along with
+      and offset of its reset control register.
+    items:
+      - items:
+          - description: phandle to APMU system controller
+          - description: register offset
+
+  clocks:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) clock
+      - description: DWC PCIe application AXI-bus master interface clock
+      - description: DWC PCIe application AXI-bus slave interface clock
+
+  clock-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 73

Quoted 10 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +10 -0
+      - description: DWC PCIe application AXI-bus master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: Global reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy

You expect/need the phy driver and PCIe driver to both reset the PHY? You should do that indirectly with the PHY API when you reset the controller.

Rob

author
#11 lore raw

Re: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller

Quoted 102 lines · Rob Herring
Quoted 101 lines · Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

  .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
  1 file changed, 156 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +69 -0
new file mode 100644
index 0000000000000..87745d49c53a1
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  The SpacemiT K1 SoC PCIe host controller is based on the Synopsys
+  DesignWare PCIe IP.  The controller uses the DesignWare built-in
+  MSI interrupt controller, and supports 256 MSIs.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: spacemit,k1-pcie
+
+  reg:
+    items:
+      - description: DesignWare PCIe registers
+      - description: ATU address space
+      - description: PCIe configuration space
+      - description: Link control registers
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: atu
+      - const: config
+      - const: link
+
+  spacemit,apmu:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description:
+      A phandle that refers to the APMU system controller, whose
+      regmap is used in managing resets and link state, along with
+      and offset of its reset control register.
+    items:
+      - items:
+          - description: phandle to APMU system controller
+          - description: register offset
+
+  clocks:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) clock
+      - description: DWC PCIe application AXI-bus master interface clock
+      - description: DWC PCIe application AXI-bus slave interface clock
+
+  clock-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset
+      - description: DWC PCIe application AXI-bus master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: Global reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
Quoted 8 lines

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 73

Quoted 4 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +4 -0
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy

You expect/need the phy driver and PCIe driver to both reset the PHY? You should do that indirectly with the PHY API when you reset the controller.

This was previously called the "global" reset, and I renamed it to align with one of the existing DWC "app" resets.

I put it here because I had the impression that it was required to be deasserted for both PCIe and the PHY to function. Currently only the combo PHY gets and deasserts the PHY reset (for the benefit of USB).

Instead, I'll require this global/phy reset for both the combo PHY and the PCIe PHYs. I will get it (deasserted) during probe for all of them. Then I'll remove it from the list of resets required/managed for PCIe ports.

I'm going to keep your Reviewed-by on patch 2, even though I'll be adding "reset" and "reset-names" as required properties.

Please tell me if you'd like me not to do that.

Thanks for the review.

-Alex

Quoted 1 line

Rob

#12 lore raw

Re: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller

In reply to Alex Elder
Quoted 109 lines · Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

 .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
 1 file changed, 156 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +77 -0
new file mode 100644
index 0000000000000..87745d49c53a1
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  The SpacemiT K1 SoC PCIe host controller is based on the Synopsys
+  DesignWare PCIe IP.  The controller uses the DesignWare built-in
+  MSI interrupt controller, and supports 256 MSIs.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: spacemit,k1-pcie
+
+  reg:
+    items:
+      - description: DesignWare PCIe registers
+      - description: ATU address space
+      - description: PCIe configuration space
+      - description: Link control registers
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: atu
+      - const: config
+      - const: link
+
+  spacemit,apmu:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description:
+      A phandle that refers to the APMU system controller, whose
+      regmap is used in managing resets and link state, along with
+      and offset of its reset control register.
+    items:
+      - items:
+          - description: phandle to APMU system controller
+          - description: register offset
+
+  clocks:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) clock
+      - description: DWC PCIe application AXI-bus master interface clock
+      - description: DWC PCIe application AXI-bus slave interface clock
+
+  clock-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset
+      - description: DWC PCIe application AXI-bus master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: Global reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy
+
+  interrupts:
+    items:
+      - description: Interrupt used for MSIs

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +10 -0
+
+  interrupt-names:
+    const: msi
+
+  phys:
+    maxItems: 1
+
+  vpcie3v3-supply:
+    description:
+      A phandle for 3.3v regulator to use for PCIe

Could you please move these Root Port specific properties (phy, vpcie3v3-supply) to the Root Port node?

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/pci/st,stm32-pcie-host.yaml

For handling the 'vpcie3v3-supply', you can rely on PCI_PWRCTRL_SLOT driver.

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 91

Quoted 4 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +4 -0
+
+  device_type:
+    const: pci
+

This is part of the PCI bus schema itself.

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 94

Quoted 3 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +3 -0
+  num-viewport:
+    const: 8
+

This property has been deprecated in favor of driver auto-detecting the iATU regions.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
author
#13 lore raw

Re: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller

Quoted 124 lines · Manivannan Sadhasivam
Quoted 109 lines · Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

  .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
  1 file changed, 156 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +77 -0
new file mode 100644
index 0000000000000..87745d49c53a1
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  The SpacemiT K1 SoC PCIe host controller is based on the Synopsys
+  DesignWare PCIe IP.  The controller uses the DesignWare built-in
+  MSI interrupt controller, and supports 256 MSIs.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: spacemit,k1-pcie
+
+  reg:
+    items:
+      - description: DesignWare PCIe registers
+      - description: ATU address space
+      - description: PCIe configuration space
+      - description: Link control registers
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: atu
+      - const: config
+      - const: link
+
+  spacemit,apmu:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description:
+      A phandle that refers to the APMU system controller, whose
+      regmap is used in managing resets and link state, along with
+      and offset of its reset control register.
+    items:
+      - items:
+          - description: phandle to APMU system controller
+          - description: register offset
+
+  clocks:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) clock
+      - description: DWC PCIe application AXI-bus master interface clock
+      - description: DWC PCIe application AXI-bus slave interface clock
+
+  clock-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset
+      - description: DWC PCIe application AXI-bus master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: Global reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy
+
+  interrupts:
+    items:
+      - description: Interrupt used for MSIs

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +10 -0
+
+  interrupt-names:
+    const: msi
+
+  phys:
+    maxItems: 1
+
+  vpcie3v3-supply:
+    description:
+      A phandle for 3.3v regulator to use for PCIe

Could you please move these Root Port specific properties (phy, vpcie3v3-supply) to the Root Port node?

Quoted 1 line

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/pci/st,stm32-pcie-host.yaml

OK, I'll try to follow what that ST binding does (and the matching driver).

Quoted 1 line

For handling the 'vpcie3v3-supply', you can rely on PCI_PWRCTRL_SLOT driver.

I looked at the code under pci/pwrctrl. But is there some other documentation I should be looking at for this?

It looks like it involves creating a new node compatible with "pciclass,0604". And that the purpose of that driver was to ensure certain resources are enabled before the "real" PCI device gets probed.

I see two arm64 DTS files using it: x1e80100.dtsi and r8a779g0.dtsi. Both define this node inside the main PCIe controller node.

Will this model (with the parent pwrctrl node and child PCI controller node) be used for all PCI controllers from here on?

Or are you saying this properly represents the relationship of the supply with the PCIe port in this SpacemiT case?

Quoted 6 lines

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 91

Quoted 4 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +4 -0
+
+  device_type:
+    const: pci
+

This is part of the PCI bus schema itself.

That means I don't have to specify it here. I'll remove it. I will also remove it from the list of required properties.

Quoted 6 lines

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 94

Quoted 3 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +3 -0
+  num-viewport:
+    const: 8
+

This property has been deprecated in favor of driver auto-detecting the iATU regions.

Yes, that got removed in v3 of the series.

Thanks.

-Alex

Quoted 3 lines

- Mani

#14 lore raw

Re: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller

Quoted 125 lines · Alex Elder
Quoted 124 lines · Manivannan Sadhasivam
Quoted 109 lines · Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

  .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
  1 file changed, 156 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +77 -0
new file mode 100644
index 0000000000000..87745d49c53a1
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller
+
+maintainers:
+  - Alex Elder <[email protected]>
+
+description: >
+  The SpacemiT K1 SoC PCIe host controller is based on the Synopsys
+  DesignWare PCIe IP.  The controller uses the DesignWare built-in
+  MSI interrupt controller, and supports 256 MSIs.
+
+allOf:
+  - $ref: /schemas/pci/snps,dw-pcie.yaml#
+
+properties:
+  compatible:
+    const: spacemit,k1-pcie
+
+  reg:
+    items:
+      - description: DesignWare PCIe registers
+      - description: ATU address space
+      - description: PCIe configuration space
+      - description: Link control registers
+
+  reg-names:
+    items:
+      - const: dbi
+      - const: atu
+      - const: config
+      - const: link
+
+  spacemit,apmu:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description:
+      A phandle that refers to the APMU system controller, whose
+      regmap is used in managing resets and link state, along with
+      and offset of its reset control register.
+    items:
+      - items:
+          - description: phandle to APMU system controller
+          - description: register offset
+
+  clocks:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) clock
+      - description: DWC PCIe application AXI-bus master interface clock
+      - description: DWC PCIe application AXI-bus slave interface clock
+
+  clock-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+
+  resets:
+    items:
+      - description: DWC PCIe Data Bus Interface (DBI) reset
+      - description: DWC PCIe application AXI-bus master interface reset
+      - description: DWC PCIe application AXI-bus slave interface reset
+      - description: Global reset; must be deasserted for PHY to function
+
+  reset-names:
+    items:
+      - const: dbi
+      - const: mstr
+      - const: slv
+      - const: phy
+
+  interrupts:
+    items:
+      - description: Interrupt used for MSIs

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +10 -0
+
+  interrupt-names:
+    const: msi
+
+  phys:
+    maxItems: 1
+
+  vpcie3v3-supply:
+    description:
+      A phandle for 3.3v regulator to use for PCIe

Could you please move these Root Port specific properties (phy, vpcie3v3-supply) to the Root Port node?

Quoted 9 lines
Quoted 1 line

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/pci/st,stm32-pcie-host.yaml

OK, I'll try to follow what that ST binding does (and the matching driver).

Quoted 1 line

For handling the 'vpcie3v3-supply', you can rely on PCI_PWRCTRL_SLOT driver.

I looked at the code under pci/pwrctrl. But is there some other documentation I should be looking at for this?

Sorry, nothing available atm. But I will create one, once we fix some core issues with pwrctrl so that it becomes useable for all (more in the driver patch).

Quoted 11 lines

It looks like it involves creating a new node compatible with "pciclass,0604". And that the purpose of that driver was to ensure certain resources are enabled before the "real" PCI device gets probed.

I see two arm64 DTS files using it: x1e80100.dtsi and r8a779g0.dtsi. Both define this node inside the main PCIe controller node.

Will this model (with the parent pwrctrl node and child PCI controller node) be used for all PCI controllers from here on?

The PCI controller (host bridge) node is the parent and the Root Port node (which gets bind to pwrctrl slot driver) will be the child.

Quoted 3 lines

Or are you saying this properly represents the relationship of the supply with the PCIe port in this SpacemiT case?

We want to use this for all the new platforms and also try to convert the old ones too gradually.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
author
#15 lore raw

Re: [PATCH v2 3/7] dt-bindings: pci: spacemit: introduce PCIe host controller

Quoted 29 lines · Manivannan Sadhasivam
Quoted 28 lines · Alex Elder
Quoted 27 lines · Manivannan Sadhasivam
Quoted 26 lines · Alex Elder

Add the Device Tree binding for the PCIe root complex found on the SpacemiT K1 SoC. This device is derived from the Synopsys Designware PCIe IP. It supports up to three PCIe ports operating at PCIe gen 2 link speeds (5 GT/sec). One of the ports uses a combo PHY, which is typically used to support a USB 3 port.

---
v2: - Renamed the binding, using "host controller"
- Added '>' to the description, and reworded it a bit
- Added reference to /schemas/pci/snps,dw-pcie.yaml
- Fixed and renamed the compatible string
- Renamed the PMU property, and fixed its description
- Consistently omit the period at the end of descriptions
- Renamed the "global" clock to be "phy"
- Use interrupts rather than interrupts-extended, and name the one interrupt "msi" to make clear its purpose
- Added a vpcie3v3-supply property
- Dropped the max-link-speed property
- Changed additionalProperties to unevaluatedProperties
- Dropped the label and status property from the example

   .../bindings/pci/spacemit,k1-pcie-host.yaml   | 156 ++++++++++++++++++
   1 file changed, 156 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +0 -0
new file mode 100644
index 0000000000000..87745d49c53a1
Quoted 8 lines
Quoted 8 lines

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 7

Quoted 8 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +7 -0
@@ -0,0 +1,156 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/pci/spacemit,k1-pcie-host.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SpacemiT K1 PCI Express Host Controller

. . .

Quoted 18 lines
Quoted 18 lines
Quoted 13 lines

Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml line 87

Quoted 9 lines
Documentation/devicetree/bindings/pci/spacemit,k1-pcie-host.yaml new file +9 -0
+  interrupt-names:
+    const: msi
+
+  phys:
+    maxItems: 1
+
+  vpcie3v3-supply:
+    description:
+      A phandle for 3.3v regulator to use for PCIe

Could you please move these Root Port specific properties (phy, vpcie3v3-supply) to the Root Port node?

Quoted 1 line

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/pci/st,stm32-pcie-host.yaml

OK, I'll try to follow what that ST binding does (and the matching driver).

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

For handling the 'vpcie3v3-supply', you can rely on PCI_PWRCTRL_SLOT driver.

I looked at the code under pci/pwrctrl. But is there some other documentation I should be looking at for this?

Sorry, nothing available atm. But I will create one, once we fix some core issues with pwrctrl so that it becomes useable for all (more in the driver patch).

Sounds good, I think it's necessary. I might not get it completely right on the next try but I trust you'll help me understand what I need to do.

Quoted 8 lines
Quoted 8 lines

It looks like it involves creating a new node compatible with "pciclass,0604". And that the purpose of that driver was to ensure certain resources are enabled before the "real" PCI device gets probed.

I see two arm64 DTS files using it: x1e80100.dtsi and r8a779g0.dtsi. Both define this node inside the main PCIe controller node.

Quoted 6 lines
Quoted 3 lines

Will this model (with the parent pwrctrl node and child PCI controller node) be used for all PCI controllers from here on?

The PCI controller (host bridge) node is the parent and the Root Port node (which gets bind to pwrctrl slot driver) will be the child.

That makes sense to me.

Quoted 6 lines
Quoted 3 lines

Or are you saying this properly represents the relationship of the supply with the PCIe port in this SpacemiT case?

We want to use this for all the new platforms and also try to convert the old ones too gradually.

OK, understood.

Thank you.

-Alex

Quoted 3 lines

- Mani

author
#16 lore raw

PATCH v2 4/7 phy: spacemit: introduce PCIe/combo PHY

In reply to Alex Elder

Introduce a driver that supports three PHYs found on the SpacemiT K1 SoC. The first PHY is a combo PHY that can be configured for use for either USB 3 or PCIe. The other two PHYs support PCIe only.

All three PHYs must be programmed with an 8 bit receiver termination value, which must be determined dynamically. Only the combo PHY is able to determine this value. The combo PHY performs a special calibration step at probe time to discover this, and that value is used to program each PHY that operates in PCIe mode. The combo PHY must therefore be probed before either of the PCIe-only PHYs will be used.

Each PHY has an internal PLL driven from an external oscillator. This PLL started when the PHY is first initialized, and stays on thereafter.

During normal operation, the USB or PCIe driver using the PHY must ensure (other) clocks and resets are set up properly.

However PCIe mode clocks are enabled and resets are de-asserted temporarily by this driver to perform the calibration step on the combo PHY.

---
v2: - Renamed the PCIe driver Kconfig option PCIE_SPACEMIT_K1
- Reimplemented the PHY PLL as a clock registered with the common clock framework, driven by an external oscillator
- Memory-mapped regmap operations no longer check for errors
- Bulk clocks are now named, allowing the PLL clock to be managed separate from the rest
- No longer use a "virt" local variable for read/modify/write
- Deleted a few unused symbol definitions
- Added and reworded some comments

 drivers/phy/Kconfig                |  11 +
 drivers/phy/Makefile               |   1 +
 drivers/phy/phy-spacemit-k1-pcie.c | 672 +++++++++++++++++++++++++++++
 3 files changed, 684 insertions(+)
 create mode 100644 drivers/phy/phy-spacemit-k1-pcie.c
drivers/phy/Kconfig +11 -0
index 678dd0452f0aa..1984c2e56122e 100644
@@ -101,6 +101,17 @@ config PHY_NXP_PTN3222
 	  schemes. It supports all three USB 2.0 data rates: Low Speed, Full
 	  Speed and High Speed.
 
+config PHY_SPACEMIT_K1_PCIE
+	tristate "PCIe and combo PHY driver for the SpacemiT K1 SoC"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on HAS_IOMEM
+	depends on OF
+	select GENERIC_PHY
+	default ARCH_SPACEMIT
+	help
+	  Enable support for the PCIe and USB 3 combo PHY and two
+	  PCIe-only PHYs used in the SpacemiT K1 SoC.
+
 source "drivers/phy/allwinner/Kconfig"
 source "drivers/phy/amlogic/Kconfig"
 source "drivers/phy/broadcom/Kconfig"
drivers/phy/Makefile +1 -0
index bfb27fb5a4942..a206133a35151 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_PHY_SNPS_EUSB2)		+= phy-snps-eusb2.o
 obj-$(CONFIG_USB_LGM_PHY)		+= phy-lgm-usb.o
 obj-$(CONFIG_PHY_AIROHA_PCIE)		+= phy-airoha-pcie.o
 obj-$(CONFIG_PHY_NXP_PTN3222)		+= phy-nxp-ptn3222.o
+obj-$(CONFIG_PHY_SPACEMIT_K1_PCIE)	+= phy-spacemit-k1-pcie.o
 obj-y					+= allwinner/	\
 					   amlogic/	\
 					   broadcom/	\
drivers/phy/phy-spacemit-k1-pcie.c new file +672 -0

672 lines not on this page · raw message

Signature · 1 line
2.48.1
#17 lore raw

Re: [PATCH v2 4/7] phy: spacemit: introduce PCIe/combo PHY

Hi,

Quoted 20 lines · Alex Elder

Introduce a driver that supports three PHYs found on the SpacemiT K1 SoC. The first PHY is a combo PHY that can be configured for use for either USB 3 or PCIe. The other two PHYs support PCIe only.

All three PHYs must be programmed with an 8 bit receiver termination value, which must be determined dynamically. Only the combo PHY is able to determine this value. The combo PHY performs a special calibration step at probe time to discover this, and that value is used to program each PHY that operates in PCIe mode. The combo PHY must therefore be probed before either of the PCIe-only PHYs will be used.

Each PHY has an internal PLL driven from an external oscillator. This PLL started when the PHY is first initialized, and stays on thereafter.

During normal operation, the USB or PCIe driver using the PHY must ensure (other) clocks and resets are set up properly.

Quoted 6 lines

However PCIe mode clocks are enabled and resets are de-asserted temporarily by this driver to perform the calibration step on the combo PHY.

Thanks for this new version. I have tried it on top of v6.18-rc1 + spacemit DTS commits from next on a BPI-F3, and it fails calibrating the PHY with:

[    2.748405] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: calibration failed
[    2.755300] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: error probing combo phy
[    2.763088] spacemit-k1-pcie-phy c0b10000.phy: probe with driver spacemit-k1-pcie-phy failed with error -2
[   14.309031] platform c0d10000.phy: deferred probe pending: (reason unknown)
[   14.313426] platform c0c10000.phy: deferred probe pending: (reason unknown)
[   14.320347] platform ca400000.pcie: deferred probe pending: platform: supplier c0c10000.phy not ready
[   14.329542] platform ca800000.pcie: deferred probe pending: platform: supplier c0d10000.phy not ready

Note that version 1 was working fine on the same board.

[ snip ]

Quoted 5 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +0 -0
new file mode 100644
index 0000000000000..81bc05823d080

[ snip ]

Quoted 38 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +38 -0
+static int k1_pcie_combo_phy_calibrate(struct k1_pcie_phy *k1_phy)
+{
+	struct reset_control_bulk_data resets[] = {
+		{ .id = "dbi", },
+		{ .id = "mstr", },
+		{ .id = "slv", },
+	};
+	struct clk_bulk_data clocks[] = {
+		{ .id = "dbi", },
+		{ .id = "mstr", },
+		{ .id = "slv", },
+	};
+	struct device *dev = k1_phy->dev;
+	struct reset_control *phy_reset;
+	int ret = 0;
+	int val;
+
+	/* Nothing to do if we already set the receiver termination value */
+	if (k1_phy_rterm_valid())
+		return 0;
+
+	/* De-assert the PHY (global) reset and leave it that way for USB */
+	phy_reset = devm_reset_control_get_exclusive_deasserted(dev, "phy");
+	if (IS_ERR(phy_reset))
+		return PTR_ERR(phy_reset);
+
+	/*
+	 * We also guarantee the APP_HOLD_PHY_RESET bit is clear.  We can
+	 * leave this bit clear even if an error happens below.
+	 */
+	regmap_assign_bits(k1_phy->pmu, PCIE_CLK_RES_CTRL,
+			   PCIE_APP_HOLD_PHY_RST, false);
+
+	/* If the calibration already completed (e.g. by U-Boot), we're done */
+	val = readl(k1_phy->regs + PCIE_RCAL_RESULT);
+	if (val & R_TUNE_DONE)
+		goto out_tune_done;
+

drivers/phy/phy-spacemit-k1-pcie.c line 492

Quoted 10 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +10 -0
+	/* Put the PHY into PCIe mode */
+	k1_combo_phy_sel(k1_phy, false);
+
+	/* Get and enable the PCIe app clocks */
+	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
+	if (ret <= 0) {
+		if (!ret)
+			ret = -ENOENT;
+		goto out_tune_done;
+	}

This part doesn't look correct. The documentation says this function "returns 0 if all clocks specified in clk_bulk_data table are obtained successfully, or valid IS_ERR() condition containing errno."

To me, it seems the code should only be:

	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
	if (ret)
		goto out_tune_done;

[snip]

drivers/phy/phy-spacemit-k1-pcie.c line 524

Quoted 2 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +2 -0
+out_put_clocks:
+	clk_bulk_put_all(ARRAY_SIZE(clocks), clocks);

When fixing the above bug, this then crashes with:

[    2.776109] Unable to handle kernel paging request at virtual address ffffffc41a0110c8
[    2.783958] Current kworker/u36:0 pgtable: 4K pagesize, 39-bit VAs, pgdp=0x00000000022a7000
[    2.792302] [ffffffc41a0110c8] pgd=0000000000000000, p4d=0000000000000000, pud=0000000000000000
[    2.800980] Oops [#1]
[    2.803217] Modules linked in:
[    2.806261] CPU: 3 UID: 0 PID: 58 Comm: kworker/u36:0 Not tainted 6.18.0-rc1+ #4 PREEMPTLAZY 
[    2.814763] Hardware name: Banana Pi BPI-F3 (DT)
[    2.819366] Workqueue: events_unbound deferred_probe_work_func
[    2.825180] epc : virt_to_folio+0x5e/0xb8
[    2.829172]  ra : kfree+0x3a/0x528
[    2.832558] epc : ffffffff8034e12e ra : ffffffff8035557a sp : ffffffc600243980
[    2.839762]  gp : ffffffff82074258 tp : ffffffd700994d80 t0 : ffffffff80021540
[    2.846967]  t1 : 0000000000000018 t2 : 2d74696d65636170 s0 : ffffffc600243990
[    2.854172]  s1 : ffffffc600243ab8 a0 : 03ffffc41a0110c0 a1 : ffffffff82123bd0
[    2.861377]  a2 : 7c137c69131cec36 a3 : ffffffff816606d8 a4 : 0000000000000000
[    2.868583]  a5 : ffffffc500000000 a6 : 0000000000000004 a7 : 0000000000000004
[    2.875787]  s2 : ffffffd700b98410 s3 : ffffffc600243ab8 s4 : 0000000000000000
[    2.882991]  s5 : ffffffff80828f1c s6 : 0000000000008437 s7 : ffffffd700b98410
[    2.890197]  s8 : ffffffd700b98410 s9 : ffffffd700900240 s10: ffffffff81fc4100
[    2.897401]  s11: ffffffd700987400 t3 : 0000000000000004 t4 : 0000000000000001
[    2.904607]  t5 : 000000000000001f t6 : 0000000000000003
[    2.909902] status: 0000000200000120 badaddr: ffffffc41a0110c8 cause: 000000000000000d
[    2.917802] [<ffffffff8034e12e>] virt_to_folio+0x5e/0xb8
[    2.923097] [<ffffffff8035557a>] kfree+0x3a/0x528
[    2.927784] [<ffffffff80828f1c>] clk_bulk_put_all+0x64/0x78
[    2.933340] [<ffffffff807249d6>] k1_pcie_phy_probe+0x4ee/0x618
[    2.939155] [<ffffffff808e35e6>] platform_probe+0x56/0x98
[    2.944538] [<ffffffff808e0328>] really_probe+0xa0/0x348
[    2.949832] [<ffffffff808e064c>] __driver_probe_device+0x7c/0x140
[    2.955909] [<ffffffff808e07f8>] driver_probe_device+0x38/0xd0
[    2.961724] [<ffffffff808e0912>] __device_attach_driver+0x82/0xf0
[    2.967801] [<ffffffff808dde6a>] bus_for_each_drv+0x72/0xd0
[    2.973356] [<ffffffff808e0cac>] __device_attach+0x94/0x198
[    2.978912] [<ffffffff808e0fca>] device_initial_probe+0x1a/0x30
[    2.984815] [<ffffffff808defee>] bus_probe_device+0x96/0xa0
[    2.990370] [<ffffffff808dff0e>] deferred_probe_work_func+0xa6/0x110
[    2.996707] [<ffffffff8005cb66>] process_one_work+0x15e/0x340
[    3.002436] [<ffffffff8005d58c>] worker_thread+0x22c/0x348
[    3.007905] [<ffffffff80066b7c>] kthread+0x10c/0x208
[    3.012853] [<ffffffff80014de0>] ret_from_fork_kernel+0x18/0x1c0
[    3.018843] [<ffffffff80c917d6>] ret_from_fork_kernel_asm+0x16/0x18
[    3.025098] Code: 7a98 8d19 2717 0131 3703 5fa7 8131 8d19 051a 953e (651c) f713 
[    3.032497] ---[ end trace 0000000000000000 ]---

It seems that we want clk_bulk_put() and not clk_bulk_put_all(). The latter free the clocks, while they have been allocated on the stack.

Regards,
Aurelien

Signature · 7 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                     http://aurel32.net

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
author
#18 lore raw

Re: [PATCH v2 4/7] phy: spacemit: introduce PCIe/combo PHY

Quoted 27 lines · Aurelien Jarno

Hi,

Quoted 24 lines · Alex Elder

Introduce a driver that supports three PHYs found on the SpacemiT K1 SoC. The first PHY is a combo PHY that can be configured for use for either USB 3 or PCIe. The other two PHYs support PCIe only.

All three PHYs must be programmed with an 8 bit receiver termination value, which must be determined dynamically. Only the combo PHY is able to determine this value. The combo PHY performs a special calibration step at probe time to discover this, and that value is used to program each PHY that operates in PCIe mode. The combo PHY must therefore be probed before either of the PCIe-only PHYs will be used.

Each PHY has an internal PLL driven from an external oscillator. This PLL started when the PHY is first initialized, and stays on thereafter.

During normal operation, the USB or PCIe driver using the PHY must ensure (other) clocks and resets are set up properly.

However PCIe mode clocks are enabled and resets are de-asserted temporarily by this driver to perform the calibration step on the combo PHY.

Quoted 6 lines
Quoted 2 lines

Thanks for this new version. I have tried it on top of v6.18-rc1 + spacemit DTS commits from next on a BPI-F3, and it fails calibrating the PHY with:

I don't see this on my BPI-F3, but I now understand why.

Quoted 49 lines
[    2.748405] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: calibration failed
[    2.755300] spacemit-k1-pcie-phy c0b10000.phy: error -ENOENT: error probing combo phy
[    2.763088] spacemit-k1-pcie-phy c0b10000.phy: probe with driver spacemit-k1-pcie-phy failed with error -2
[   14.309031] platform c0d10000.phy: deferred probe pending: (reason unknown)
[   14.313426] platform c0c10000.phy: deferred probe pending: (reason unknown)
[   14.320347] platform ca400000.pcie: deferred probe pending: platform: supplier c0c10000.phy not ready
[   14.329542] platform ca800000.pcie: deferred probe pending: platform: supplier c0d10000.phy not ready

Note that version 1 was working fine on the same board.

[ snip ]

Quoted 5 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +0 -0
new file mode 100644
index 0000000000000..81bc05823d080

[ snip ]

Quoted 29 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +29 -0
+static int k1_pcie_combo_phy_calibrate(struct k1_pcie_phy *k1_phy)
+{
+	struct reset_control_bulk_data resets[] = {
+		{ .id = "dbi", },
+		{ .id = "mstr", },
+		{ .id = "slv", },
+	};
+	struct clk_bulk_data clocks[] = {
+		{ .id = "dbi", },
+		{ .id = "mstr", },
+		{ .id = "slv", },
+	};
+	struct device *dev = k1_phy->dev;
+	struct reset_control *phy_reset;
+	int ret = 0;
+	int val;
+
+	/* Nothing to do if we already set the receiver termination value */
+	if (k1_phy_rterm_valid())
+		return 0;
+
+	/* De-assert the PHY (global) reset and leave it that way for USB */
+	phy_reset = devm_reset_control_get_exclusive_deasserted(dev, "phy");
+	if (IS_ERR(phy_reset))
+		return PTR_ERR(phy_reset);
+
+	/*
+	 * We also guarantee the APP_HOLD_PHY_RESET bit is clear.  We can
+	 * leave this bit clear even if an error happens below.
Quoted 8 lines

drivers/phy/phy-spacemit-k1-pcie.c line 481

Quoted 8 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +8 -0
+	 */
+	regmap_assign_bits(k1_phy->pmu, PCIE_CLK_RES_CTRL,
+			   PCIE_APP_HOLD_PHY_RST, false);
+
+	/* If the calibration already completed (e.g. by U-Boot), we're done */
+	val = readl(k1_phy->regs + PCIE_RCAL_RESULT);
+	if (val & R_TUNE_DONE)
+		goto out_tune_done;

I refer to the above three lines, below.

Quoted 15 lines

drivers/phy/phy-spacemit-k1-pcie.c line 492

Quoted 10 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +10 -0
+	/* Put the PHY into PCIe mode */
+	k1_combo_phy_sel(k1_phy, false);
+
+	/* Get and enable the PCIe app clocks */
+	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
+	if (ret <= 0) {
+		if (!ret)
+			ret = -ENOENT;
+		goto out_tune_done;
+	}

This part doesn't look correct. The documentation says this function "returns 0 if all clocks specified in clk_bulk_data table are obtained successfully, or valid IS_ERR() condition containing errno."

Quoted 5 lines

To me, it seems the code should only be:

	ret = clk_bulk_get(dev, ARRAY_SIZE(clocks), clocks);
	if (ret)
		goto out_tune_done;

OK I understand the problem here.

On v1 of the series, this used clk_bulk_get_all(), and I changed that to clk_bulk_get(). There is now an additional reference clock defined, used by the PLL clock. So here we only want to get three clocks, not that new one.

The return value from clk_bulk_get_all() is the number of clocks, and 0 means "not found". So I guess I neglected to change the handling of the return value here when I changed the function.

The reason I didn't see this is that calibration only ever has to happen once (per boot). In the lines I noted earlier, the PCIE_RCAL_RESULT register is read, and if the R_TUNE_DONE bit is already set, calibration is complete (probably done by the boot loader).

In my case, calibration was already done, so I never had to get the clock or resets, etc. In your case, this driver had to do the calibration, so you (successfully) got the clocks, and that (erroneously) resulted in an error.

I reproduced the problem(s) you observed by forcing the calibration on my machine.

Thank you very much for reporting this. Your fix is correct, and I will include it in v3 of the series.

Quoted 51 lines

[snip]

drivers/phy/phy-spacemit-k1-pcie.c line 524

Quoted 2 lines
drivers/phy/phy-spacemit-k1-pcie.c new file +2 -0
+out_put_clocks:
+	clk_bulk_put_all(ARRAY_SIZE(clocks), clocks);

When fixing the above bug, this then crashes with:

[    2.776109] Unable to handle kernel paging request at virtual address ffffffc41a0110c8
[    2.783958] Current kworker/u36:0 pgtable: 4K pagesize, 39-bit VAs, pgdp=0x00000000022a7000
[    2.792302] [ffffffc41a0110c8] pgd=0000000000000000, p4d=0000000000000000, pud=0000000000000000
[    2.800980] Oops [#1]
[    2.803217] Modules linked in:
[    2.806261] CPU: 3 UID: 0 PID: 58 Comm: kworker/u36:0 Not tainted 6.18.0-rc1+ #4 PREEMPTLAZY
[    2.814763] Hardware name: Banana Pi BPI-F3 (DT)
[    2.819366] Workqueue: events_unbound deferred_probe_work_func
[    2.825180] epc : virt_to_folio+0x5e/0xb8
[    2.829172]  ra : kfree+0x3a/0x528
[    2.832558] epc : ffffffff8034e12e ra : ffffffff8035557a sp : ffffffc600243980
[    2.839762]  gp : ffffffff82074258 tp : ffffffd700994d80 t0 : ffffffff80021540
[    2.846967]  t1 : 0000000000000018 t2 : 2d74696d65636170 s0 : ffffffc600243990
[    2.854172]  s1 : ffffffc600243ab8 a0 : 03ffffc41a0110c0 a1 : ffffffff82123bd0
[    2.861377]  a2 : 7c137c69131cec36 a3 : ffffffff816606d8 a4 : 0000000000000000
[    2.868583]  a5 : ffffffc500000000 a6 : 0000000000000004 a7 : 0000000000000004
[    2.875787]  s2 : ffffffd700b98410 s3 : ffffffc600243ab8 s4 : 0000000000000000
[    2.882991]  s5 : ffffffff80828f1c s6 : 0000000000008437 s7 : ffffffd700b98410
[    2.890197]  s8 : ffffffd700b98410 s9 : ffffffd700900240 s10: ffffffff81fc4100
[    2.897401]  s11: ffffffd700987400 t3 : 0000000000000004 t4 : 0000000000000001
[    2.904607]  t5 : 000000000000001f t6 : 0000000000000003
[    2.909902] status: 0000000200000120 badaddr: ffffffc41a0110c8 cause: 000000000000000d
[    2.917802] [<ffffffff8034e12e>] virt_to_folio+0x5e/0xb8
[    2.923097] [<ffffffff8035557a>] kfree+0x3a/0x528
[    2.927784] [<ffffffff80828f1c>] clk_bulk_put_all+0x64/0x78
[    2.933340] [<ffffffff807249d6>] k1_pcie_phy_probe+0x4ee/0x618
[    2.939155] [<ffffffff808e35e6>] platform_probe+0x56/0x98
[    2.944538] [<ffffffff808e0328>] really_probe+0xa0/0x348
[    2.949832] [<ffffffff808e064c>] __driver_probe_device+0x7c/0x140
[    2.955909] [<ffffffff808e07f8>] driver_probe_device+0x38/0xd0
[    2.961724] [<ffffffff808e0912>] __device_attach_driver+0x82/0xf0
[    2.967801] [<ffffffff808dde6a>] bus_for_each_drv+0x72/0xd0
[    2.973356] [<ffffffff808e0cac>] __device_attach+0x94/0x198
[    2.978912] [<ffffffff808e0fca>] device_initial_probe+0x1a/0x30
[    2.984815] [<ffffffff808defee>] bus_probe_device+0x96/0xa0
[    2.990370] [<ffffffff808dff0e>] deferred_probe_work_func+0xa6/0x110
[    2.996707] [<ffffffff8005cb66>] process_one_work+0x15e/0x340
[    3.002436] [<ffffffff8005d58c>] worker_thread+0x22c/0x348
[    3.007905] [<ffffffff80066b7c>] kthread+0x10c/0x208
[    3.012853] [<ffffffff80014de0>] ret_from_fork_kernel+0x18/0x1c0
[    3.018843] [<ffffffff80c917d6>] ret_from_fork_kernel_asm+0x16/0x18
[    3.025098] Code: 7a98 8d19 2717 0131 3703 5fa7 8131 8d19 051a 953e (651c) f713
[    3.032497] ---[ end trace 0000000000000000 ]---
Quoted 2 lines

It seems that we want clk_bulk_put() and not clk_bulk_put_all(). The latter free the clocks, while they have been allocated on the stack.

Yes, you are correct. This too is an artifact of me doing a bad job switching to the clk_bulk_get() interface.

Thanks again for your message. Reviews are awesome, but someone actually testing it is a good way to find problems like this.

-Alex

Quoted 4 lines

Regards,
Aurelien

author
#19 lore raw

PATCH v2 5/7 PCI: spacemit: introduce SpacemiT PCIe host driver

In reply to Alex Elder

Introduce a driver for the PCIe host controller found in the SpacemiT K1 SoC. The hardware is derived from the Synopsys DesignWare PCIe IP. The driver supports three PCIe ports that operate at PCIe gen2 transfer rates (5 GT/sec). The first port uses a combo PHY, which may be configured for use for USB 3 instead.

---
v2: - Renamed the PCIe driver source file "pcie-spacemit-k1.c"
- Renamed the PCIe driver Kconfig option PCIE_SPACEMIT_K1; it is now tristate rather than Boolean
- The PCIe host compatible string is now "spacemit,k1-pcie"
- Renamed the PMU syscon property to be "spacemit,apmu"
- Renamed the symbols representing the PCI vendor and device IDs to align with <linux/pci_ids.h>
- Use PCIE_T_PVPERL_MS rather than 100 to represent a standard delay period.
- Use platform (not dev) driver-data access functions; assignment is done only after the private structure is initialized
- Deleted some unneeded includes in the PCIe driver.
- Dropped error checking when operating on MMIO-backed regmaps
- Added a regmap_read() call in two places, to ensure a specified delay occurs *after* the a MMIO write has reached its target.
- Used ARRAY_SIZE() (not a local variable value) in a few spots
- Now use readl_relaxed()/writel_relaxed() when operating on the "link" I/O memory space in the PCIe driver
- Updated a few error messages for consistency
- No longer specify suppress_bind_attrs in the PCIe driver
- Now specify PCIe driver probe type as PROBE_PREFER_ASYNCHRONOUS
- No longer use (void) cast to indicate ignored return values

 drivers/pci/controller/dwc/Kconfig            |  10 +
 drivers/pci/controller/dwc/Makefile           |   1 +
 drivers/pci/controller/dwc/pcie-spacemit-k1.c | 319 ++++++++++++++++++
 3 files changed, 330 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-spacemit-k1.c
drivers/pci/controller/dwc/Kconfig +10 -0
index 349d4657393c9..ede59b34c99ba 100644
@@ -509,6 +509,16 @@ config PCI_KEYSTONE_EP
 	  on DesignWare hardware and therefore the driver re-uses the
 	  DesignWare core functions to implement the driver.
 
+config PCIE_SPACEMIT_K1
+	tristate "SpacemiT K1 PCIe controller (host mode)"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on PCI && OF && HAS_IOMEM
+	select PCIE_DW_HOST
+	default ARCH_SPACEMIT
+	help
+	  Enables support for the PCIe controller in the K1 SoC operating
+	  in host mode.
+
 config PCIE_VISCONTI_HOST
 	bool "Toshiba Visconti PCIe controller"
 	depends on ARCH_VISCONTI || COMPILE_TEST
drivers/pci/controller/dwc/Makefile +1 -0
index 7ae28f3b0fb39..662b0a219ddc4 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_PCIE_UNIPHIER) += pcie-uniphier.o
 obj-$(CONFIG_PCIE_UNIPHIER_EP) += pcie-uniphier-ep.o
 obj-$(CONFIG_PCIE_VISCONTI_HOST) += pcie-visconti.o
 obj-$(CONFIG_PCIE_RCAR_GEN4) += pcie-rcar-gen4.o
+obj-$(CONFIG_PCIE_SPACEMIT_K1) += pcie-spacemit-k1.o
 obj-$(CONFIG_PCIE_STM32_HOST) += pcie-stm32.o
 obj-$(CONFIG_PCIE_STM32_EP) += pcie-stm32-ep.o
 
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +319 -0

319 lines not on this page · raw message

Signature · 1 line
2.48.1
#20 lore raw

Re: [PATCH v2 5/7] PCI: spacemit: introduce SpacemiT PCIe host driver

Quoted 94 lines · Alex Elder

Introduce a driver for the PCIe host controller found in the SpacemiT K1 SoC. The hardware is derived from the Synopsys DesignWare PCIe IP. The driver supports three PCIe ports that operate at PCIe gen2 transfer rates (5 GT/sec). The first port uses a combo PHY, which may be configured for use for USB 3 instead.

---
v2: - Renamed the PCIe driver source file "pcie-spacemit-k1.c"
- Renamed the PCIe driver Kconfig option PCIE_SPACEMIT_K1; it is now tristate rather than Boolean
- The PCIe host compatible string is now "spacemit,k1-pcie"
- Renamed the PMU syscon property to be "spacemit,apmu"
- Renamed the symbols representing the PCI vendor and device IDs to align with <linux/pci_ids.h>
- Use PCIE_T_PVPERL_MS rather than 100 to represent a standard delay period.
- Use platform (not dev) driver-data access functions; assignment is done only after the private structure is initialized
- Deleted some unneeded includes in the PCIe driver.
- Dropped error checking when operating on MMIO-backed regmaps
- Added a regmap_read() call in two places, to ensure a specified delay occurs *after* the a MMIO write has reached its target.
- Used ARRAY_SIZE() (not a local variable value) in a few spots
- Now use readl_relaxed()/writel_relaxed() when operating on the "link" I/O memory space in the PCIe driver
- Updated a few error messages for consistency
- No longer specify suppress_bind_attrs in the PCIe driver
- Now specify PCIe driver probe type as PROBE_PREFER_ASYNCHRONOUS
- No longer use (void) cast to indicate ignored return values

 drivers/pci/controller/dwc/Kconfig            |  10 +
 drivers/pci/controller/dwc/Makefile           |   1 +
 drivers/pci/controller/dwc/pcie-spacemit-k1.c | 319 ++++++++++++++++++
 3 files changed, 330 insertions(+)
 create mode 100644 drivers/pci/controller/dwc/pcie-spacemit-k1.c
drivers/pci/controller/dwc/Kconfig +10 -0
index 349d4657393c9..ede59b34c99ba 100644
@@ -509,6 +509,16 @@ config PCI_KEYSTONE_EP
 	  on DesignWare hardware and therefore the driver re-uses the
 	  DesignWare core functions to implement the driver.
 
+config PCIE_SPACEMIT_K1
+	tristate "SpacemiT K1 PCIe controller (host mode)"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on PCI && OF && HAS_IOMEM
+	select PCIE_DW_HOST
+	default ARCH_SPACEMIT
+	help
+	  Enables support for the PCIe controller in the K1 SoC operating
+	  in host mode.
+
 config PCIE_VISCONTI_HOST
 	bool "Toshiba Visconti PCIe controller"
 	depends on ARCH_VISCONTI || COMPILE_TEST
drivers/pci/controller/dwc/Makefile +1 -0
index 7ae28f3b0fb39..662b0a219ddc4 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_PCIE_UNIPHIER) += pcie-uniphier.o
 obj-$(CONFIG_PCIE_UNIPHIER_EP) += pcie-uniphier-ep.o
 obj-$(CONFIG_PCIE_VISCONTI_HOST) += pcie-visconti.o
 obj-$(CONFIG_PCIE_RCAR_GEN4) += pcie-rcar-gen4.o
+obj-$(CONFIG_PCIE_SPACEMIT_K1) += pcie-spacemit-k1.o
 obj-$(CONFIG_PCIE_STM32_HOST) += pcie-stm32.o
 obj-$(CONFIG_PCIE_STM32_EP) += pcie-stm32-ep.o
 
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +18 -0
new file mode 100644
index 0000000000000..d58232cbb8a02
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SpacemiT K1 PCIe host driver
+ *
+ * Copyright (C) 2025 by RISCstar Solutions Corporation.  All rights reserved.
+ * Copyright (c) 2023, spacemit Corporation.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gfp.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mod_devicetable.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 28

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+#include <linux/reset.h>
+#include <linux/types.h>
+
+#include "pcie-designware.h"
+
+#define PCI_VENDOR_ID_SPACEMIT		0x201f
+#define PCI_DEVICE_ID_SPACEMIT_K1	0x0001
+
+/* Offsets and field definitions for link management registers */
+

nit: drop the extra newline

Quoted 5 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +5 -0
+#define K1_PHY_AHB_IRQ_EN			0x0000
+#define PCIE_INTERRUPT_EN		BIT(0)
+
+#define K1_PHY_AHB_LINK_STS			0x0004
+#define SMLH_LINK_UP			BIT(1)

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 43

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+#define RDLH_LINK_UP			BIT(12)
+
+#define INTR_ENABLE				0x0014
+#define MSI_CTRL_INT			BIT(11)
+
+/* Some controls require APMU regmap access */
+#define SYSCON_APMU			"spacemit,apmu"
+
+/* Offsets and field definitions for APMU registers */
+

here also

Quoted 31 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +31 -0
+#define PCIE_CLK_RESET_CONTROL			0x0000
+#define LTSSM_EN			BIT(6)
+#define PCIE_AUX_PWR_DET		BIT(9)
+#define PCIE_RC_PERST			BIT(12)	/* 1: assert PERST# */
+#define APP_HOLD_PHY_RST		BIT(30)
+#define DEVICE_TYPE_RC			BIT(31)	/* 0: endpoint; 1: RC */
+
+#define PCIE_CONTROL_LOGIC			0x0004
+#define PCIE_SOFT_RESET			BIT(0)
+
+struct k1_pcie {
+	struct dw_pcie pci;
+	struct phy *phy;
+	void __iomem *link;
+	struct regmap *pmu;	/* Errors ignored; MMIO-backed regmap */
+	u32 pmu_off;
+};
+
+#define to_k1_pcie(dw_pcie) \
+		platform_get_drvdata(to_platform_device((dw_pcie)->dev))
+
+static void k1_pcie_toggle_soft_reset(struct k1_pcie *k1)
+{
+	u32 offset;
+	u32 val;
+
+	/*
+	 * Write, then read back to guarantee it has reached the device
+	 * before we start the delay.
+	 */
+	offset = k1->pmu_off + PCIE_CONTROL_LOGIC;

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 84

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+	regmap_set_bits(k1->pmu, offset, PCIE_SOFT_RESET);
+	regmap_read(k1->pmu, offset, &val);
+
+	mdelay(2);
+
+	regmap_clear_bits(k1->pmu, offset, PCIE_SOFT_RESET);
+}
+
+/* Enable app clocks, deassert resets */
+static int k1_pcie_activate(struct k1_pcie *k1)

k1_pcie_enable_resources()?

Quoted 20 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +20 -0
+{
+	struct dw_pcie *pci = &k1->pci;
+	int ret;
+
+	ret = clk_bulk_prepare_enable(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+	if (ret)
+		return ret;
+
+	ret = reset_control_bulk_deassert(ARRAY_SIZE(pci->app_rsts),
+					  pci->app_rsts);
+	if (ret)
+		goto err_disable_clks;
+
+	ret = reset_control_bulk_deassert(ARRAY_SIZE(pci->core_rsts),
+					  pci->core_rsts);
+	if (ret)
+		goto err_assert_resets;
+
+	return 0;
+

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 114

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+err_assert_resets:
+	reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts);
+err_disable_clks:
+	clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+
+	return ret;
+}
+
+/* Assert resets, disable app clocks */
+static void k1_pcie_deactivate(struct k1_pcie *k1)

k1_pcie_disable_resources()?

Quoted 28 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +28 -0
+{
+	struct dw_pcie *pci = &k1->pci;
+
+	reset_control_bulk_assert(ARRAY_SIZE(pci->core_rsts), pci->core_rsts);
+	reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts);
+	clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+}
+
+static int k1_pcie_init(struct dw_pcie_rp *pp)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 offset;
+	u32 mask;
+	u32 val;
+	int ret;
+
+	k1_pcie_toggle_soft_reset(k1);
+
+	ret = k1_pcie_activate(k1);
+	if (ret)
+		return ret;
+
+	ret = phy_init(k1->phy);
+	if (ret) {
+		k1_pcie_deactivate(k1);
+
+		return ret;

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 152

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+	}
+
+	/* Set the PCI vendor and device ID */
+	dw_pcie_dbi_ro_wr_en(pci);
+	dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, PCI_VENDOR_ID_SPACEMIT);
+	dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, PCI_DEVICE_ID_SPACEMIT_K1);
+	dw_pcie_dbi_ro_wr_dis(pci);
+
+	/*
+	 * Assert fundamental reset (drive PERST# low).  Put the port in

s/port/controller

Quoted 19 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +19 -0
+	 * root complex mode, and indicate that Vaux (3.3v) is present.
+	 */
+	mask = PCIE_RC_PERST;
+	mask |= DEVICE_TYPE_RC | PCIE_AUX_PWR_DET;
+
+	/*
+	 * Write, then read back to guarantee it has reached the device
+	 * before we start the delay.
+	 */
+	offset = k1->pmu_off + PCIE_CLK_RESET_CONTROL;
+	regmap_set_bits(k1->pmu, offset, mask);
+	regmap_read(k1->pmu, offset, &val);
+
+	mdelay(PCIE_T_PVPERL_MS);
+
+	/* Deassert fundamental reset (drive PERST# high) */
+	regmap_clear_bits(k1->pmu, offset, PCIE_RC_PERST);
+
+	return 0;

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 181

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+}
+
+static void k1_pcie_deinit(struct dw_pcie_rp *pp)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+
+	/* Assert fundamental reset (drive PERST# low) */
+	regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			PCIE_RC_PERST);

You need assert PERST# here.

Quoted 80 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +80 -0
+
+	phy_exit(k1->phy);
+
+	k1_pcie_deactivate(k1);
+}
+
+static const struct dw_pcie_host_ops k1_pcie_host_ops = {
+	.init		= k1_pcie_init,
+	.deinit		= k1_pcie_deinit,
+};
+
+static bool k1_pcie_link_up(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	val = readl_relaxed(k1->link + K1_PHY_AHB_LINK_STS);
+
+	return (val & RDLH_LINK_UP) && (val & SMLH_LINK_UP);
+}
+
+static int k1_pcie_start_link(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	/* Stop holding the PHY in reset, and enable link training */
+	regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			   APP_HOLD_PHY_RST | LTSSM_EN, LTSSM_EN);
+
+	/* Enable the MSI interrupt */
+	writel_relaxed(MSI_CTRL_INT, k1->link + INTR_ENABLE);
+
+	/* Top-level interrupt enable */
+	val = readl_relaxed(k1->link + K1_PHY_AHB_IRQ_EN);
+	val |= PCIE_INTERRUPT_EN;
+	writel_relaxed(val, k1->link + K1_PHY_AHB_IRQ_EN);
+
+	return 0;
+}
+
+static void k1_pcie_stop_link(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	/* Disable interrupts */
+	val = readl_relaxed(k1->link + K1_PHY_AHB_IRQ_EN);
+	val &= ~PCIE_INTERRUPT_EN;
+	writel_relaxed(val, k1->link + K1_PHY_AHB_IRQ_EN);
+
+	writel_relaxed(0, k1->link + INTR_ENABLE);
+
+	/* Disable the link and hold the PHY in reset */
+	regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			   APP_HOLD_PHY_RST | LTSSM_EN, APP_HOLD_PHY_RST);
+}
+
+static const struct dw_pcie_ops k1_pcie_ops = {
+	.link_up	= k1_pcie_link_up,
+	.start_link	= k1_pcie_start_link,
+	.stop_link	= k1_pcie_stop_link,
+};
+
+static int k1_pcie_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct k1_pcie *k1;
+	int ret;
+
+	k1 = devm_kzalloc(dev, sizeof(*k1), GFP_KERNEL);
+	if (!k1)
+		return -ENOMEM;
+
+	k1->pmu = syscon_regmap_lookup_by_phandle_args(dev_of_node(dev),
+						       SYSCON_APMU, 1,
+						       &k1->pmu_off);
+	if (IS_ERR(k1->pmu))
+		return dev_err_probe(dev, PTR_ERR(k1->pmu),
+				     "failed to lookup PMU registers\n");

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 271

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+
+	k1->link = devm_platform_ioremap_resource_byname(pdev, "link");
+	if (!k1->link)
+		return dev_err_probe(dev, -ENOMEM,
+				     "failed to map \"link\" registers\n");
+
+	ret = devm_regulator_get_enable(dev, "vpcie3v3-supply");
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to get \"vpcie3v3\" supply\n");

As mentioned in the bindings patch, you should rely on the PWRCTRL_SLOT driver to handle the power supplies. It is not yet handling the PERST#, but I have a series floating for that:
https://lore.kernel.org/linux-pci/[email protected]/

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 280

Quoted 9 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +9 -0
+
+	/* Hold the PHY in reset until we start the link */
+	regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			APP_HOLD_PHY_RST);
+
+	k1->phy = devm_phy_get(dev, NULL);
+	if (IS_ERR(k1->phy))
+		return dev_err_probe(dev, PTR_ERR(k1->phy),
+				     "failed to get PHY\n");

Once you move these properties to Root Port binding, you need to have per-Root Port parser. Again, you can refer the STM32 driver.

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 287

Quoted 7 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +7 -0
+
+	k1->pci.dev = dev;
+	k1->pci.ops = &k1_pcie_ops;
+	dw_pcie_cap_set(&k1->pci, REQ_RES);
+
+	k1->pci.pp.ops = &k1_pcie_host_ops;
+	k1->pci.pp.num_vectors = MAX_MSI_IRQS;

This driver is just using a single 'msi' vector, which can only support 32 MSIs. But MAX_MSI_IRQS is 256. So this looks wrong.

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 290

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +3 -0
+
+	platform_set_drvdata(pdev, k1);
+

For setting the correct runtime PM state of the controller, you should do:

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

This will fix the runtime PM hierarchy of PCIe chain (from host controller to client drivers). Otherwise, it will be broken.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
author
#21 lore raw

Re: [PATCH v2 5/7] PCI: spacemit: introduce SpacemiT PCIe host driver

Quoted 99 lines · Manivannan Sadhasivam
Quoted 98 lines · Alex Elder

Introduce a driver for the PCIe host controller found in the SpacemiT K1 SoC. The hardware is derived from the Synopsys DesignWare PCIe IP. The driver supports three PCIe ports that operate at PCIe gen2 transfer rates (5 GT/sec). The first port uses a combo PHY, which may be configured for use for USB 3 instead.

---
v2: - Renamed the PCIe driver source file "pcie-spacemit-k1.c"
- Renamed the PCIe driver Kconfig option PCIE_SPACEMIT_K1; it is now tristate rather than Boolean
- The PCIe host compatible string is now "spacemit,k1-pcie"
- Renamed the PMU syscon property to be "spacemit,apmu"
- Renamed the symbols representing the PCI vendor and device IDs to align with <linux/pci_ids.h>
- Use PCIE_T_PVPERL_MS rather than 100 to represent a standard delay period.
- Use platform (not dev) driver-data access functions; assignment is done only after the private structure is initialized
- Deleted some unneeded includes in the PCIe driver.
- Dropped error checking when operating on MMIO-backed regmaps
- Added a regmap_read() call in two places, to ensure a specified delay occurs *after* the a MMIO write has reached its target.
- Used ARRAY_SIZE() (not a local variable value) in a few spots
- Now use readl_relaxed()/writel_relaxed() when operating on the "link" I/O memory space in the PCIe driver
- Updated a few error messages for consistency
- No longer specify suppress_bind_attrs in the PCIe driver
- Now specify PCIe driver probe type as PROBE_PREFER_ASYNCHRONOUS
- No longer use (void) cast to indicate ignored return values

  drivers/pci/controller/dwc/Kconfig            |  10 +
  drivers/pci/controller/dwc/Makefile           |   1 +
  drivers/pci/controller/dwc/pcie-spacemit-k1.c | 319 ++++++++++++++++++
  3 files changed, 330 insertions(+)

create mode 100644 drivers/pci/controller/dwc/pcie-spacemit-k1.c

drivers/pci/controller/dwc/Kconfig +10 -0
index 349d4657393c9..ede59b34c99ba 100644
@@ -509,6 +509,16 @@ config PCI_KEYSTONE_EP
  	  on DesignWare hardware and therefore the driver re-uses the
  	  DesignWare core functions to implement the driver.
 
+config PCIE_SPACEMIT_K1
+	tristate "SpacemiT K1 PCIe controller (host mode)"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on PCI && OF && HAS_IOMEM
+	select PCIE_DW_HOST
+	default ARCH_SPACEMIT
+	help
+	  Enables support for the PCIe controller in the K1 SoC operating
+	  in host mode.
+
  config PCIE_VISCONTI_HOST
  	bool "Toshiba Visconti PCIe controller"
  	depends on ARCH_VISCONTI || COMPILE_TEST
drivers/pci/controller/dwc/Makefile +1 -0
index 7ae28f3b0fb39..662b0a219ddc4 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_PCIE_UNIPHIER) += pcie-uniphier.o
  obj-$(CONFIG_PCIE_UNIPHIER_EP) += pcie-uniphier-ep.o
  obj-$(CONFIG_PCIE_VISCONTI_HOST) += pcie-visconti.o
  obj-$(CONFIG_PCIE_RCAR_GEN4) += pcie-rcar-gen4.o
+obj-$(CONFIG_PCIE_SPACEMIT_K1) += pcie-spacemit-k1.o
  obj-$(CONFIG_PCIE_STM32_HOST) += pcie-stm32.o
  obj-$(CONFIG_PCIE_STM32_EP) += pcie-stm32-ep.o
 
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +22 -0
new file mode 100644
index 0000000000000..d58232cbb8a02
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SpacemiT K1 PCIe host driver
+ *
+ * Copyright (C) 2025 by RISCstar Solutions Corporation.  All rights reserved.
+ * Copyright (c) 2023, spacemit Corporation.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gfp.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mod_devicetable.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/types.h>
+
+#include "pcie-designware.h"
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 28

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+
+#define PCI_VENDOR_ID_SPACEMIT		0x201f
+#define PCI_DEVICE_ID_SPACEMIT_K1	0x0001
+
+/* Offsets and field definitions for link management registers */
+

nit: drop the extra newline

OK.

Quoted 9 lines
Quoted 9 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +9 -0
+#define K1_PHY_AHB_IRQ_EN			0x0000
+#define PCIE_INTERRUPT_EN		BIT(0)
+
+#define K1_PHY_AHB_LINK_STS			0x0004
+#define SMLH_LINK_UP			BIT(1)
+#define RDLH_LINK_UP			BIT(12)
+
+#define INTR_ENABLE				0x0014
+#define MSI_CTRL_INT			BIT(11)
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 43

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+
+/* Some controls require APMU regmap access */
+#define SYSCON_APMU			"spacemit,apmu"
+
+/* Offsets and field definitions for APMU registers */
+

here also

OK.

Quoted 35 lines
Quoted 35 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +35 -0
+#define PCIE_CLK_RESET_CONTROL			0x0000
+#define LTSSM_EN			BIT(6)
+#define PCIE_AUX_PWR_DET		BIT(9)
+#define PCIE_RC_PERST			BIT(12)	/* 1: assert PERST# */
+#define APP_HOLD_PHY_RST		BIT(30)
+#define DEVICE_TYPE_RC			BIT(31)	/* 0: endpoint; 1: RC */
+
+#define PCIE_CONTROL_LOGIC			0x0004
+#define PCIE_SOFT_RESET			BIT(0)
+
+struct k1_pcie {
+	struct dw_pcie pci;
+	struct phy *phy;
+	void __iomem *link;
+	struct regmap *pmu;	/* Errors ignored; MMIO-backed regmap */
+	u32 pmu_off;
+};
+
+#define to_k1_pcie(dw_pcie) \
+		platform_get_drvdata(to_platform_device((dw_pcie)->dev))
+
+static void k1_pcie_toggle_soft_reset(struct k1_pcie *k1)
+{
+	u32 offset;
+	u32 val;
+
+	/*
+	 * Write, then read back to guarantee it has reached the device
+	 * before we start the delay.
+	 */
+	offset = k1->pmu_off + PCIE_CONTROL_LOGIC;
+	regmap_set_bits(k1->pmu, offset, PCIE_SOFT_RESET);
+	regmap_read(k1->pmu, offset, &val);
+
+	mdelay(2);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 84

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+
+	regmap_clear_bits(k1->pmu, offset, PCIE_SOFT_RESET);
+}
+
+/* Enable app clocks, deassert resets */
+static int k1_pcie_activate(struct k1_pcie *k1)

k1_pcie_enable_resources()?

OK, I'll use k1_pcie_{enable,disable}_resources().

Quoted 65 lines
Quoted 20 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +20 -0
+{
+	struct dw_pcie *pci = &k1->pci;
+	int ret;
+
+	ret = clk_bulk_prepare_enable(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+	if (ret)
+		return ret;
+
+	ret = reset_control_bulk_deassert(ARRAY_SIZE(pci->app_rsts),
+					  pci->app_rsts);
+	if (ret)
+		goto err_disable_clks;
+
+	ret = reset_control_bulk_deassert(ARRAY_SIZE(pci->core_rsts),
+					  pci->core_rsts);
+	if (ret)
+		goto err_assert_resets;
+
+	return 0;
+

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 114

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+err_assert_resets:
+	reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts);
+err_disable_clks:
+	clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+
+	return ret;
+}
+
+/* Assert resets, disable app clocks */
+static void k1_pcie_deactivate(struct k1_pcie *k1)

k1_pcie_disable_resources()?

Quoted 32 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +32 -0
+{
+	struct dw_pcie *pci = &k1->pci;
+
+	reset_control_bulk_assert(ARRAY_SIZE(pci->core_rsts), pci->core_rsts);
+	reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts);
+	clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+}
+
+static int k1_pcie_init(struct dw_pcie_rp *pp)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 offset;
+	u32 mask;
+	u32 val;
+	int ret;
+
+	k1_pcie_toggle_soft_reset(k1);
+
+	ret = k1_pcie_activate(k1);
+	if (ret)
+		return ret;
+
+	ret = phy_init(k1->phy);
+	if (ret) {
+		k1_pcie_deactivate(k1);
+
+		return ret;
+	}
+
+	/* Set the PCI vendor and device ID */
+	dw_pcie_dbi_ro_wr_en(pci);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 152

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+	dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, PCI_VENDOR_ID_SPACEMIT);
+	dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, PCI_DEVICE_ID_SPACEMIT_K1);
+	dw_pcie_dbi_ro_wr_dis(pci);
+
+	/*
+	 * Assert fundamental reset (drive PERST# low).  Put the port in

s/port/controller

OK.

Quoted 23 lines
Quoted 23 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +23 -0
+	 * root complex mode, and indicate that Vaux (3.3v) is present.
+	 */
+	mask = PCIE_RC_PERST;
+	mask |= DEVICE_TYPE_RC | PCIE_AUX_PWR_DET;
+
+	/*
+	 * Write, then read back to guarantee it has reached the device
+	 * before we start the delay.
+	 */
+	offset = k1->pmu_off + PCIE_CLK_RESET_CONTROL;
+	regmap_set_bits(k1->pmu, offset, mask);
+	regmap_read(k1->pmu, offset, &val);
+
+	mdelay(PCIE_T_PVPERL_MS);
+
+	/* Deassert fundamental reset (drive PERST# high) */
+	regmap_clear_bits(k1->pmu, offset, PCIE_RC_PERST);
+
+	return 0;
+}
+
+static void k1_pcie_deinit(struct dw_pcie_rp *pp)
+{
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 181

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+
+	/* Assert fundamental reset (drive PERST# low) */
+	regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			PCIE_RC_PERST);

You need assert PERST# here.

I don't understand this comment.

Setting PCIE_RC_PERST in this register drives PERST# low.

Quoted 86 lines
Quoted 86 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +86 -0
+	phy_exit(k1->phy);
+
+	k1_pcie_deactivate(k1);
+}
+
+static const struct dw_pcie_host_ops k1_pcie_host_ops = {
+	.init		= k1_pcie_init,
+	.deinit		= k1_pcie_deinit,
+};
+
+static bool k1_pcie_link_up(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	val = readl_relaxed(k1->link + K1_PHY_AHB_LINK_STS);
+
+	return (val & RDLH_LINK_UP) && (val & SMLH_LINK_UP);
+}
+
+static int k1_pcie_start_link(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	/* Stop holding the PHY in reset, and enable link training */
+	regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			   APP_HOLD_PHY_RST | LTSSM_EN, LTSSM_EN);
+
+	/* Enable the MSI interrupt */
+	writel_relaxed(MSI_CTRL_INT, k1->link + INTR_ENABLE);
+
+	/* Top-level interrupt enable */
+	val = readl_relaxed(k1->link + K1_PHY_AHB_IRQ_EN);
+	val |= PCIE_INTERRUPT_EN;
+	writel_relaxed(val, k1->link + K1_PHY_AHB_IRQ_EN);
+
+	return 0;
+}
+
+static void k1_pcie_stop_link(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	/* Disable interrupts */
+	val = readl_relaxed(k1->link + K1_PHY_AHB_IRQ_EN);
+	val &= ~PCIE_INTERRUPT_EN;
+	writel_relaxed(val, k1->link + K1_PHY_AHB_IRQ_EN);
+
+	writel_relaxed(0, k1->link + INTR_ENABLE);
+
+	/* Disable the link and hold the PHY in reset */
+	regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			   APP_HOLD_PHY_RST | LTSSM_EN, APP_HOLD_PHY_RST);
+}
+
+static const struct dw_pcie_ops k1_pcie_ops = {
+	.link_up	= k1_pcie_link_up,
+	.start_link	= k1_pcie_start_link,
+	.stop_link	= k1_pcie_stop_link,
+};
+
+static int k1_pcie_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct k1_pcie *k1;
+	int ret;
+
+	k1 = devm_kzalloc(dev, sizeof(*k1), GFP_KERNEL);
+	if (!k1)
+		return -ENOMEM;
+
+	k1->pmu = syscon_regmap_lookup_by_phandle_args(dev_of_node(dev),
+						       SYSCON_APMU, 1,
+						       &k1->pmu_off);
+	if (IS_ERR(k1->pmu))
+		return dev_err_probe(dev, PTR_ERR(k1->pmu),
+				     "failed to lookup PMU registers\n");
+
+	k1->link = devm_platform_ioremap_resource_byname(pdev, "link");
+	if (!k1->link)
+		return dev_err_probe(dev, -ENOMEM,
+				     "failed to map \"link\" registers\n");
+
+	ret = devm_regulator_get_enable(dev, "vpcie3v3-supply");
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 271

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +3 -0
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to get \"vpcie3v3\" supply\n");

As mentioned in the bindings patch, you should rely on the PWRCTRL_SLOT driver to handle the power supplies. It is not yet handling the PERST#, but I have a series floating for that:
https://lore.kernel.org/linux-pci/[email protected]/

I think that just means that I'll define a DT node compatible with "pciclass,0604", and in that node I'll specify the vpcie3v3-supply property. That will cause that (pwrctrl) device to get and enable the supply before the "real" PCIe device probes.

And once your PERST work gets merged into the PCI power control framework, a callback will allow that to assert PERST# as needed surrounding power transitions. (But I won't worry about that for now.)

Is that right?

Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +4 -0
+
+	/* Hold the PHY in reset until we start the link */
+	regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			APP_HOLD_PHY_RST);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 280

Quoted 5 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +5 -0
+
+	k1->phy = devm_phy_get(dev, NULL);
+	if (IS_ERR(k1->phy))
+		return dev_err_probe(dev, PTR_ERR(k1->phy),
+				     "failed to get PHY\n");

Once you move these properties to Root Port binding, you need to have per-Root Port parser. Again, you can refer the STM32 driver.

I see getting the PHY in stm32_pcie_parse_port(), but nothing about the supply (which you mentioned in the other message).

Quoted 10 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 287

Quoted 7 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +7 -0
+
+	k1->pci.dev = dev;
+	k1->pci.ops = &k1_pcie_ops;
+	dw_pcie_cap_set(&k1->pci, REQ_RES);
+
+	k1->pci.pp.ops = &k1_pcie_host_ops;
+	k1->pci.pp.num_vectors = MAX_MSI_IRQS;

This driver is just using a single 'msi' vector, which can only support 32 MSIs. But MAX_MSI_IRQS is 256. So this looks wrong.

In dw_pcie_host_init(), if unspecified, MSI_DEF_NUM_VECTORS=32 is used for num_vectors. If it is specified, only if the value exceeds MAX_MSI_IRQS=256 is an error returned.

In dw_handle_msi_irq(), "num_ctrls" is computed based on num_vectors / MAX_MSI_IRQS_PER_CTRL=32. A loop then iterates over those "controllers"(?) to handle each bit set in their corresponding register.

This seems OK. Can you explain why you think it's wrong?

Quoted 9 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 290

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +3 -0
+
+	platform_set_drvdata(pdev, k1);
+

For setting the correct runtime PM state of the controller, you should do:

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

OK, that's easy enough.

Quoted 2 lines

This will fix the runtime PM hierarchy of PCIe chain (from host controller to client drivers). Otherwise, it will be broken.

Is this documented somewhere? (It wouldn't surprise me if it is and I just missed it.)

This driver has as its origins some vendor code, and I simply removed the runtime PM calls. I didn't realize something would be broken without making pm_runtime*() calls.

Thank you for your review Mani.

-Alex

Quoted 2 lines

- Mani

#22 lore raw

Re: [PATCH v2 5/7] PCI: spacemit: introduce SpacemiT PCIe host driver

Quoted 283 lines · Alex Elder
Quoted 97 lines · Manivannan Sadhasivam
Quoted 96 lines · Alex Elder

Introduce a driver for the PCIe host controller found in the SpacemiT K1 SoC. The hardware is derived from the Synopsys DesignWare PCIe IP. The driver supports three PCIe ports that operate at PCIe gen2 transfer rates (5 GT/sec). The first port uses a combo PHY, which may be configured for use for USB 3 instead.

---
v2: - Renamed the PCIe driver source file "pcie-spacemit-k1.c"
- Renamed the PCIe driver Kconfig option PCIE_SPACEMIT_K1; it is now tristate rather than Boolean
- The PCIe host compatible string is now "spacemit,k1-pcie"
- Renamed the PMU syscon property to be "spacemit,apmu"
- Renamed the symbols representing the PCI vendor and device IDs to align with <linux/pci_ids.h>
- Use PCIE_T_PVPERL_MS rather than 100 to represent a standard delay period.
- Use platform (not dev) driver-data access functions; assignment is done only after the private structure is initialized
- Deleted some unneeded includes in the PCIe driver.
- Dropped error checking when operating on MMIO-backed regmaps
- Added a regmap_read() call in two places, to ensure a specified delay occurs *after* the a MMIO write has reached its target.
- Used ARRAY_SIZE() (not a local variable value) in a few spots
- Now use readl_relaxed()/writel_relaxed() when operating on the "link" I/O memory space in the PCIe driver
- Updated a few error messages for consistency
- No longer specify suppress_bind_attrs in the PCIe driver
- Now specify PCIe driver probe type as PROBE_PREFER_ASYNCHRONOUS
- No longer use (void) cast to indicate ignored return values

  drivers/pci/controller/dwc/Kconfig            |  10 +
  drivers/pci/controller/dwc/Makefile           |   1 +
  drivers/pci/controller/dwc/pcie-spacemit-k1.c | 319 ++++++++++++++++++
  3 files changed, 330 insertions(+)

create mode 100644 drivers/pci/controller/dwc/pcie-spacemit-k1.c

drivers/pci/controller/dwc/Kconfig +10 -0
index 349d4657393c9..ede59b34c99ba 100644
@@ -509,6 +509,16 @@ config PCI_KEYSTONE_EP
  	  on DesignWare hardware and therefore the driver re-uses the
  	  DesignWare core functions to implement the driver.
+config PCIE_SPACEMIT_K1
+	tristate "SpacemiT K1 PCIe controller (host mode)"
+	depends on ARCH_SPACEMIT || COMPILE_TEST
+	depends on PCI && OF && HAS_IOMEM
+	select PCIE_DW_HOST
+	default ARCH_SPACEMIT
+	help
+	  Enables support for the PCIe controller in the K1 SoC operating
+	  in host mode.
+
  config PCIE_VISCONTI_HOST
  	bool "Toshiba Visconti PCIe controller"
  	depends on ARCH_VISCONTI || COMPILE_TEST
drivers/pci/controller/dwc/Makefile +1 -0
index 7ae28f3b0fb39..662b0a219ddc4 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_PCIE_UNIPHIER) += pcie-uniphier.o
  obj-$(CONFIG_PCIE_UNIPHIER_EP) += pcie-uniphier-ep.o
  obj-$(CONFIG_PCIE_VISCONTI_HOST) += pcie-visconti.o
  obj-$(CONFIG_PCIE_RCAR_GEN4) += pcie-rcar-gen4.o
+obj-$(CONFIG_PCIE_SPACEMIT_K1) += pcie-spacemit-k1.o
  obj-$(CONFIG_PCIE_STM32_HOST) += pcie-stm32.o
  obj-$(CONFIG_PCIE_STM32_EP) += pcie-stm32-ep.o
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +22 -0
new file mode 100644
index 0000000000000..d58232cbb8a02
@@ -0,0 +1,319 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SpacemiT K1 PCIe host driver
+ *
+ * Copyright (C) 2025 by RISCstar Solutions Corporation.  All rights reserved.
+ * Copyright (c) 2023, spacemit Corporation.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gfp.h>
+#include <linux/mfd/syscon.h>
+#include <linux/mod_devicetable.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/types.h>
+
+#include "pcie-designware.h"
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 28

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+
+#define PCI_VENDOR_ID_SPACEMIT		0x201f
+#define PCI_DEVICE_ID_SPACEMIT_K1	0x0001
+
+/* Offsets and field definitions for link management registers */
+

nit: drop the extra newline

OK.

Quoted 9 lines
Quoted 9 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +9 -0
+#define K1_PHY_AHB_IRQ_EN			0x0000
+#define PCIE_INTERRUPT_EN		BIT(0)
+
+#define K1_PHY_AHB_LINK_STS			0x0004
+#define SMLH_LINK_UP			BIT(1)
+#define RDLH_LINK_UP			BIT(12)
+
+#define INTR_ENABLE				0x0014
+#define MSI_CTRL_INT			BIT(11)
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 43

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+
+/* Some controls require APMU regmap access */
+#define SYSCON_APMU			"spacemit,apmu"
+
+/* Offsets and field definitions for APMU registers */
+

here also

OK.

Quoted 35 lines
Quoted 35 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +35 -0
+#define PCIE_CLK_RESET_CONTROL			0x0000
+#define LTSSM_EN			BIT(6)
+#define PCIE_AUX_PWR_DET		BIT(9)
+#define PCIE_RC_PERST			BIT(12)	/* 1: assert PERST# */
+#define APP_HOLD_PHY_RST		BIT(30)
+#define DEVICE_TYPE_RC			BIT(31)	/* 0: endpoint; 1: RC */
+
+#define PCIE_CONTROL_LOGIC			0x0004
+#define PCIE_SOFT_RESET			BIT(0)
+
+struct k1_pcie {
+	struct dw_pcie pci;
+	struct phy *phy;
+	void __iomem *link;
+	struct regmap *pmu;	/* Errors ignored; MMIO-backed regmap */
+	u32 pmu_off;
+};
+
+#define to_k1_pcie(dw_pcie) \
+		platform_get_drvdata(to_platform_device((dw_pcie)->dev))
+
+static void k1_pcie_toggle_soft_reset(struct k1_pcie *k1)
+{
+	u32 offset;
+	u32 val;
+
+	/*
+	 * Write, then read back to guarantee it has reached the device
+	 * before we start the delay.
+	 */
+	offset = k1->pmu_off + PCIE_CONTROL_LOGIC;
+	regmap_set_bits(k1->pmu, offset, PCIE_SOFT_RESET);
+	regmap_read(k1->pmu, offset, &val);
+
+	mdelay(2);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 84

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+
+	regmap_clear_bits(k1->pmu, offset, PCIE_SOFT_RESET);
+}
+
+/* Enable app clocks, deassert resets */
+static int k1_pcie_activate(struct k1_pcie *k1)

k1_pcie_enable_resources()?

OK, I'll use k1_pcie_{enable,disable}_resources().

Quoted 65 lines
Quoted 20 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +20 -0
+{
+	struct dw_pcie *pci = &k1->pci;
+	int ret;
+
+	ret = clk_bulk_prepare_enable(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+	if (ret)
+		return ret;
+
+	ret = reset_control_bulk_deassert(ARRAY_SIZE(pci->app_rsts),
+					  pci->app_rsts);
+	if (ret)
+		goto err_disable_clks;
+
+	ret = reset_control_bulk_deassert(ARRAY_SIZE(pci->core_rsts),
+					  pci->core_rsts);
+	if (ret)
+		goto err_assert_resets;
+
+	return 0;
+

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 114

Quoted 10 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +10 -0
+err_assert_resets:
+	reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts);
+err_disable_clks:
+	clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+
+	return ret;
+}
+
+/* Assert resets, disable app clocks */
+static void k1_pcie_deactivate(struct k1_pcie *k1)

k1_pcie_disable_resources()?

Quoted 32 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +32 -0
+{
+	struct dw_pcie *pci = &k1->pci;
+
+	reset_control_bulk_assert(ARRAY_SIZE(pci->core_rsts), pci->core_rsts);
+	reset_control_bulk_assert(ARRAY_SIZE(pci->app_rsts), pci->app_rsts);
+	clk_bulk_disable_unprepare(ARRAY_SIZE(pci->app_clks), pci->app_clks);
+}
+
+static int k1_pcie_init(struct dw_pcie_rp *pp)
+{
+	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 offset;
+	u32 mask;
+	u32 val;
+	int ret;
+
+	k1_pcie_toggle_soft_reset(k1);
+
+	ret = k1_pcie_activate(k1);
+	if (ret)
+		return ret;
+
+	ret = phy_init(k1->phy);
+	if (ret) {
+		k1_pcie_deactivate(k1);
+
+		return ret;
+	}
+
+	/* Set the PCI vendor and device ID */
+	dw_pcie_dbi_ro_wr_en(pci);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 152

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+	dw_pcie_writew_dbi(pci, PCI_VENDOR_ID, PCI_VENDOR_ID_SPACEMIT);
+	dw_pcie_writew_dbi(pci, PCI_DEVICE_ID, PCI_DEVICE_ID_SPACEMIT_K1);
+	dw_pcie_dbi_ro_wr_dis(pci);
+
+	/*
+	 * Assert fundamental reset (drive PERST# low).  Put the port in

s/port/controller

OK.

Quoted 23 lines
Quoted 23 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +23 -0
+	 * root complex mode, and indicate that Vaux (3.3v) is present.
+	 */
+	mask = PCIE_RC_PERST;
+	mask |= DEVICE_TYPE_RC | PCIE_AUX_PWR_DET;
+
+	/*
+	 * Write, then read back to guarantee it has reached the device
+	 * before we start the delay.
+	 */
+	offset = k1->pmu_off + PCIE_CLK_RESET_CONTROL;
+	regmap_set_bits(k1->pmu, offset, mask);
+	regmap_read(k1->pmu, offset, &val);
+
+	mdelay(PCIE_T_PVPERL_MS);
+
+	/* Deassert fundamental reset (drive PERST# high) */
+	regmap_clear_bits(k1->pmu, offset, PCIE_RC_PERST);
+
+	return 0;
+}
+
+static void k1_pcie_deinit(struct dw_pcie_rp *pp)
+{
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 181

Quoted 6 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +6 -0
+	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+
+	/* Assert fundamental reset (drive PERST# low) */
+	regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			PCIE_RC_PERST);

You need assert PERST# here.

Quoted 4 lines

I don't understand this comment.

Setting PCIE_RC_PERST in this register drives PERST# low.

Sorry, it was a brain fade from my side. Ignore my comment.

Quoted 95 lines
Quoted 86 lines
Quoted 86 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +86 -0
+	phy_exit(k1->phy);
+
+	k1_pcie_deactivate(k1);
+}
+
+static const struct dw_pcie_host_ops k1_pcie_host_ops = {
+	.init		= k1_pcie_init,
+	.deinit		= k1_pcie_deinit,
+};
+
+static bool k1_pcie_link_up(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	val = readl_relaxed(k1->link + K1_PHY_AHB_LINK_STS);
+
+	return (val & RDLH_LINK_UP) && (val & SMLH_LINK_UP);
+}
+
+static int k1_pcie_start_link(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	/* Stop holding the PHY in reset, and enable link training */
+	regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			   APP_HOLD_PHY_RST | LTSSM_EN, LTSSM_EN);
+
+	/* Enable the MSI interrupt */
+	writel_relaxed(MSI_CTRL_INT, k1->link + INTR_ENABLE);
+
+	/* Top-level interrupt enable */
+	val = readl_relaxed(k1->link + K1_PHY_AHB_IRQ_EN);
+	val |= PCIE_INTERRUPT_EN;
+	writel_relaxed(val, k1->link + K1_PHY_AHB_IRQ_EN);
+
+	return 0;
+}
+
+static void k1_pcie_stop_link(struct dw_pcie *pci)
+{
+	struct k1_pcie *k1 = to_k1_pcie(pci);
+	u32 val;
+
+	/* Disable interrupts */
+	val = readl_relaxed(k1->link + K1_PHY_AHB_IRQ_EN);
+	val &= ~PCIE_INTERRUPT_EN;
+	writel_relaxed(val, k1->link + K1_PHY_AHB_IRQ_EN);
+
+	writel_relaxed(0, k1->link + INTR_ENABLE);
+
+	/* Disable the link and hold the PHY in reset */
+	regmap_update_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			   APP_HOLD_PHY_RST | LTSSM_EN, APP_HOLD_PHY_RST);
+}
+
+static const struct dw_pcie_ops k1_pcie_ops = {
+	.link_up	= k1_pcie_link_up,
+	.start_link	= k1_pcie_start_link,
+	.stop_link	= k1_pcie_stop_link,
+};
+
+static int k1_pcie_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct k1_pcie *k1;
+	int ret;
+
+	k1 = devm_kzalloc(dev, sizeof(*k1), GFP_KERNEL);
+	if (!k1)
+		return -ENOMEM;
+
+	k1->pmu = syscon_regmap_lookup_by_phandle_args(dev_of_node(dev),
+						       SYSCON_APMU, 1,
+						       &k1->pmu_off);
+	if (IS_ERR(k1->pmu))
+		return dev_err_probe(dev, PTR_ERR(k1->pmu),
+				     "failed to lookup PMU registers\n");
+
+	k1->link = devm_platform_ioremap_resource_byname(pdev, "link");
+	if (!k1->link)
+		return dev_err_probe(dev, -ENOMEM,
+				     "failed to map \"link\" registers\n");
+
+	ret = devm_regulator_get_enable(dev, "vpcie3v3-supply");
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 271

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +3 -0
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to get \"vpcie3v3\" supply\n");

As mentioned in the bindings patch, you should rely on the PWRCTRL_SLOT driver to handle the power supplies. It is not yet handling the PERST#, but I have a series floating for that:
https://lore.kernel.org/linux-pci/[email protected]/

Quoted 5 lines

I think that just means that I'll define a DT node compatible with "pciclass,0604", and in that node I'll specify the vpcie3v3-supply property. That will cause that (pwrctrl) device to get and enable the supply before the "real" PCIe device probes.

Right.

Quoted 5 lines

And once your PERST work gets merged into the PCI power control framework, a callback will allow that to assert PERST# as needed surrounding power transitions. (But I won't worry about that for now.)

I'm still nervous to say that you should not worry about it (about not deasserting PERST# at the right time) as it goes against the PCIe spec. Current pwrctrl platforms supporting PERST# are working fine due to sheer luck.

So it would be better to leave the pwrctrl driver out of the equation now and enable the supply in this driver itself. Later, once my pwrctrl rework gets merged, I will try to switch this driver to use it.

Quoted 15 lines

Is that right?

Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +4 -0
+
+	/* Hold the PHY in reset until we start the link */
+	regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			APP_HOLD_PHY_RST);
Quoted 8 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 280

Quoted 5 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +5 -0
+
+	k1->phy = devm_phy_get(dev, NULL);
+	if (IS_ERR(k1->phy))
+		return dev_err_probe(dev, PTR_ERR(k1->phy),
+				     "failed to get PHY\n");

Once you move these properties to Root Port binding, you need to have per-Root Port parser. Again, you can refer the STM32 driver.

Quoted 3 lines

I see getting the PHY in stm32_pcie_parse_port(), but nothing about the supply (which you mentioned in the other message).

To conclude, you should move forward with defining the PHY and supply properties in the Root Port node, but parse/handle them in this driver itself.

Quoted 11 lines
Quoted 10 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 287

Quoted 7 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +7 -0
+
+	k1->pci.dev = dev;
+	k1->pci.ops = &k1_pcie_ops;
+	dw_pcie_cap_set(&k1->pci, REQ_RES);
+
+	k1->pci.pp.ops = &k1_pcie_host_ops;
+	k1->pci.pp.num_vectors = MAX_MSI_IRQS;

This driver is just using a single 'msi' vector, which can only support 32 MSIs. But MAX_MSI_IRQS is 256. So this looks wrong.

Quoted 4 lines

In dw_pcie_host_init(), if unspecified, MSI_DEF_NUM_VECTORS=32 is used for num_vectors. If it is specified, only if the value exceeds MAX_MSI_IRQS=256 is an error returned.

Yes, because the driver trusts the glue drivers to provide the num_vectors if they support more than 32.

Quoted 7 lines

In dw_handle_msi_irq(), "num_ctrls" is computed based on num_vectors / MAX_MSI_IRQS_PER_CTRL=32. A loop then iterates over those "controllers"(?) to handle each bit set in their corresponding register.

This seems OK. Can you explain why you think it's wrong?

So both 'ctrl' and 'msi' IRQs are interrelated. Each 'ctrl' can have upto 32 MSI vectors only. If your platform supports more than 32 MSI vectors, like 256, then the platform DT should provide 8 'msi' IRQs.

Currently the driver is not strict about this requirement. I will send a patch to print an error message if this requirement is not satisfied.

Quoted 10 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 290

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +3 -0
+
+	platform_set_drvdata(pdev, k1);
+

For setting the correct runtime PM state of the controller, you should do:

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Quoted 7 lines

OK, that's easy enough.

Quoted 2 lines

This will fix the runtime PM hierarchy of PCIe chain (from host controller to client drivers). Otherwise, it will be broken.

Is this documented somewhere? (It wouldn't surprise me if it is and I just missed it.)

Sorry no. It is on my todo list. But I'm getting motivation now.

Quoted 4 lines

This driver has as its origins some vendor code, and I simply removed the runtime PM calls. I didn't realize something would be broken without making pm_runtime*() calls.

It is the PM framework requirement to mark the device as 'active' to allow it to participate in runtime PM. If you do not mark it as 'active' and 'enable' it, the framework will not allow propagating the runtime PM changes before *this* device. For instance, consider the generic PCI topology:

PCI controller (platform device)

	|
PCI host bridge
	|
PCI Root Port
	|

PCI endpoint device

If the runtime PM is not enabled for the PCI Root Port, then if the PCI endpoint device runtime suspends, it will not trigger runtime suspend for the Root Port and also for the PCI controller. Also, since the runtime PM framework doesn't have the visibility of the devices underneath the bus (like endpoint), it may assume that no devices (children) are currently active and may trigger runtime suspend of the Root Port (parent) even though the endpoint device could be 'active'.

For all these reasons, it is recommended to properly reflect the runtime PM status of the device even if the driver doesn't do anything special about it. This is also the reason why I asked you to set pm_runtime_no_callbacks() since this driver doesn't register any runtime PM ops.

Since this controller driver is the top of the hierarchy, you may ask what could happen if this driver runtime PM status is not reflected correctly. Well, most controllers have some power domain associated with them controlled by the genpd framework. If the runtime PM framework thinks that there are no devices connected to the bus and the controller driver also doesn't have the state enabled, it may disable the power domain associated with it. If that happens, the PCI controller will not work and so the devices in the hierarchy.

Hope this clarifies.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
author
#23 lore raw

Re: [PATCH v2 5/7] PCI: spacemit: introduce SpacemiT PCIe host driver

Quoted 11 lines · Manivannan Sadhasivam
Quoted 10 lines · Alex Elder
Quoted 9 lines · Manivannan Sadhasivam
Quoted 8 lines · Alex Elder

Introduce a driver for the PCIe host controller found in the SpacemiT K1 SoC. The hardware is derived from the Synopsys DesignWare PCIe IP. The driver supports three PCIe ports that operate at PCIe gen2 transfer rates (5 GT/sec). The first port uses a combo PHY, which may be configured for use for USB 3 instead.

---

. . .

Quoted 24 lines
Quoted 10 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 271

Quoted 4 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +4 -0
+	ret = devm_regulator_get_enable(dev, "vpcie3v3-supply");
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to get \"vpcie3v3\" supply\n");

As mentioned in the bindings patch, you should rely on the PWRCTRL_SLOT driver to handle the power supplies. It is not yet handling the PERST#, but I have a series floating for that:
https://lore.kernel.org/linux-pci/[email protected]/

Quoted 5 lines

I think that just means that I'll define a DT node compatible with "pciclass,0604", and in that node I'll specify the vpcie3v3-supply property. That will cause that (pwrctrl) device to get and enable the supply before the "real" PCIe device probes.

Right.

Quoted 5 lines

And once your PERST work gets merged into the PCI power control framework, a callback will allow that to assert PERST# as needed surrounding power transitions. (But I won't worry about that for now.)

Quoted 7 lines

I'm still nervous to say that you should not worry about it (about not deasserting PERST# at the right time) as it goes against the PCIe spec. Current pwrctrl platforms supporting PERST# are working fine due to sheer luck.

So it would be better to leave the pwrctrl driver out of the equation now and enable the supply in this driver itself. Later, once my pwrctrl rework gets merged, I will try to switch this driver to use it.

As I understand it, PERST# should be only be deasserted after all power rails are known to be stable.

This driver enables the regulator during probe, shortly before calling dw_pcie_host_init(). That function calls back to k1_pcie_init(), which enables clocks, deasserts resets, and initializes the PHY before it changes the PERST# state.

By "changing the PERST# state" I mean it is asserted (driven low), then deasserted after 100 milliseconds (PCIE_T_PVPERL_MS).

I have two questions on this:
- You say the PCI spec talks about the "right time" to deassert PERST# (relative to power). Is that at all related to PCIE_T_PVPERL_MS?
- I notice that PERST# is in a deasserted state at the time I assert it in this sequence. Do you see any reason I should assert it early as an initialization step, or is asserting it and holding it there for 100 msec sufficient?

Quoted 15 lines
Quoted 15 lines

Is that right?

Quoted 12 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 280

Quoted 9 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +9 -0
+
+	/* Hold the PHY in reset until we start the link */
+	regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			APP_HOLD_PHY_RST);
+
+	k1->phy = devm_phy_get(dev, NULL);
+	if (IS_ERR(k1->phy))
+		return dev_err_probe(dev, PTR_ERR(k1->phy),
+				     "failed to get PHY\n");

Once you move these properties to Root Port binding, you need to have per-Root Port parser. Again, you can refer the STM32 driver.

Quoted 6 lines
Quoted 3 lines

I see getting the PHY in stm32_pcie_parse_port(), but nothing about the supply (which you mentioned in the other message).

To conclude, you should move forward with defining the PHY and supply properties in the Root Port node, but parse/handle them in this driver itself.

Got it.

Quoted 24 lines
Quoted 11 lines
Quoted 10 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 287

Quoted 7 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +7 -0
+
+	k1->pci.dev = dev;
+	k1->pci.ops = &k1_pcie_ops;
+	dw_pcie_cap_set(&k1->pci, REQ_RES);
+
+	k1->pci.pp.ops = &k1_pcie_host_ops;
+	k1->pci.pp.num_vectors = MAX_MSI_IRQS;

This driver is just using a single 'msi' vector, which can only support 32 MSIs. But MAX_MSI_IRQS is 256. So this looks wrong.

Quoted 4 lines

In dw_pcie_host_init(), if unspecified, MSI_DEF_NUM_VECTORS=32 is used for num_vectors. If it is specified, only if the value exceeds MAX_MSI_IRQS=256 is an error returned.

Yes, because the driver trusts the glue drivers to provide the num_vectors if they support more than 32.

Quoted 5 lines

In dw_handle_msi_irq(), "num_ctrls" is computed based on num_vectors / MAX_MSI_IRQS_PER_CTRL=32. A loop then iterates over those "controllers"(?) to handle each bit set in their corresponding register.

Quoted 6 lines
Quoted 2 lines

This seems OK. Can you explain why you think it's wrong?

So both 'ctrl' and 'msi' IRQs are interrelated. Each 'ctrl' can have upto 32 MSI vectors only. If your platform supports more than 32 MSI vectors, like 256, then the platform DT should provide 8 'msi' IRQs.

I have asked SpacemiT about this, specifically whether there are additional interrupts (I don't think there are), or if not that, additional registers to support MSI 32+ (see below). In their downstream driver they handle interrupts differently. I suspect num_vectors needs to be set to 32 (or I'll leave it unset and take the default).

In the DesignWare driver, there are up to 8 "ctrls", and each ctrl has 32 bit positions representing 32 MSI vectors. Each can have an msi_irq defined. An msi_irq is always set up for ctrl 0.

For any ctrl with an msi_irq assigned, dw_pcie_msi_host_init() sets its interrupt handler to dw_chained_msi_isr(), which just calls dw_handle_msi_irq().

The way dw_handle_msi_irq() works, a single ctrl apparently can handle up to 256 MSI vectors, as long as the block of 3 registers that manage the ctrl (ENABLE, MASK, and STATUS presumably) are consecutive in I/O memory for consecutive ctrls.

I looked for other examples. I see that "pcie-fu740.c", which supports compatible "sifive,fu740-pcie", sets num_vectors to MAX_MSI_IRQS, but "fu740-c000.dtsi" defines just one "msi" interrupt. And "pci-dra7xx.c" seems to do something similar, and maybe "pcie-rcar-gen4.c" too.

Quoted 41 lines

Currently the driver is not strict about this requirement. I will send a patch to print an error message if this requirement is not satisfied.

Quoted 10 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 290

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +3 -0
+
+	platform_set_drvdata(pdev, k1);
+

For setting the correct runtime PM state of the controller, you should do:

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Quoted 7 lines

OK, that's easy enough.

Quoted 2 lines

This will fix the runtime PM hierarchy of PCIe chain (from host controller to client drivers). Otherwise, it will be broken.

Is this documented somewhere? (It wouldn't surprise me if it is and I just missed it.)

Sorry no. It is on my todo list. But I'm getting motivation now.

Quoted 4 lines

This driver has as its origins some vendor code, and I simply removed the runtime PM calls. I didn't realize something would be broken without making pm_runtime*() calls.

It is the PM framework requirement to mark the device as 'active' to allow it to participate in runtime PM. If you do not mark it as 'active' and 'enable' it, the framework will not allow propagating the runtime PM changes before *this* device. For instance, consider the generic PCI topology:

PCI controller (platform device)

	|
PCI host bridge
	|
PCI Root Port
	|

PCI endpoint device

Quoted 7 lines

If the runtime PM is not enabled for the PCI Root Port, then if the PCI endpoint device runtime suspends, it will not trigger runtime suspend for the Root Port and also for the PCI controller. Also, since the runtime PM framework doesn't have the visibility of the devices underneath the bus (like endpoint), it may assume that no devices (children) are currently active and may trigger runtime suspend of the Root Port (parent) even though the endpoint device could be 'active'.

So this basically marks this controller as a pass-through device that doesn't itself change state for runtime PM, but still communicates that somewhere at or below it there might be devices that do participate.

Quoted 1 line

For all these reasons, it is recommended to properly reflect the

runtime PM

Quoted 3 lines

status of the device even if the driver doesn't do anything special about it. This is also the reason why I asked you to set pm_runtime_no_callbacks() since this driver doesn't register any runtime PM ops.

OK, I think understand now.

Quoted 9 lines

Since this controller driver is the top of the hierarchy, you may ask what could happen if this driver runtime PM status is not reflected correctly. Well, most controllers have some power domain associated with them controlled by the genpd framework. If the runtime PM framework thinks that there are no devices connected to the bus and the controller driver also doesn't have the state enabled, it may disable the power domain associated with it. If that happens, the PCI controller will not work and so the devices in the hierarchy.

Hope this clarifies.

Yes, it helps a lot. Thank you.

-Alex

Quoted 2 lines

- Mani

#24 lore raw

Re: [PATCH v2 5/7] PCI: spacemit: introduce SpacemiT PCIe host driver

Quoted 43 lines · Alex Elder
Quoted 11 lines · Manivannan Sadhasivam
Quoted 10 lines · Alex Elder
Quoted 9 lines · Manivannan Sadhasivam
Quoted 8 lines · Alex Elder

Introduce a driver for the PCIe host controller found in the SpacemiT K1 SoC. The hardware is derived from the Synopsys DesignWare PCIe IP. The driver supports three PCIe ports that operate at PCIe gen2 transfer rates (5 GT/sec). The first port uses a combo PHY, which may be configured for use for USB 3 instead.

---

. . .

Quoted 28 lines
Quoted 10 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 271

Quoted 4 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +4 -0
+	ret = devm_regulator_get_enable(dev, "vpcie3v3-supply");
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to get \"vpcie3v3\" supply\n");

As mentioned in the bindings patch, you should rely on the PWRCTRL_SLOT driver to handle the power supplies. It is not yet handling the PERST#, but I have a series floating for that:
https://lore.kernel.org/linux-pci/[email protected]/

Quoted 5 lines

I think that just means that I'll define a DT node compatible with "pciclass,0604", and in that node I'll specify the vpcie3v3-supply property. That will cause that (pwrctrl) device to get and enable the supply before the "real" PCIe device probes.

Right.

Quoted 5 lines

And once your PERST work gets merged into the PCI power control framework, a callback will allow that to assert PERST# as needed surrounding power transitions. (But I won't worry about that for now.)

I'm still nervous to say that you should not worry about it (about not deasserting PERST# at the right time) as it goes against the PCIe spec. Current pwrctrl platforms supporting PERST# are working fine due to sheer luck.

Quoted 7 lines
Quoted 3 lines

So it would be better to leave the pwrctrl driver out of the equation now and enable the supply in this driver itself. Later, once my pwrctrl rework gets merged, I will try to switch this driver to use it.

As I understand it, PERST# should be only be deasserted after all power rails are known to be stable.

Yes

Quoted 6 lines

This driver enables the regulator during probe, shortly before calling dw_pcie_host_init(). That function calls back to k1_pcie_init(), which enables clocks, deasserts resets, and initializes the PHY before it changes the PERST# state.

Quoted 8 lines

By "changing the PERST# state" I mean it is asserted (driven low), then deasserted after 100 milliseconds (PCIE_T_PVPERL_MS).

I have two questions on this:
- You say the PCI spec talks about the "right time" to deassert PERST# (relative to power). Is that at all related to PCIE_T_PVPERL_MS?

The PCI CEM spec says that PERST# should be deasserted atleast 100ms after the power becomes stable. But with the current pwrctrl design, the host controller deasserts the PERST# even before the pwrctrl probe. So this is in violation of the spec. But depending on the endpoint device design, this might not cause any issue as PERST# is a level triggered signal. So once the endpoint boots up, it will see the PERST# deassert and will start working. I'm not justifying the current design, but just mentioning that you might not see any issue.

That being said, we are going to submit a series that reworks pwrctrl framework such that each controller can call an API to probe pwrctrl drivers. This way, host controller driver can make sure that the device will get powered ON before it deasserts the PERST#.

Quoted 6 lines

- I notice that PERST# is in a deasserted state at the time I assert it in this sequence. Do you see any reason I should assert it early as an initialization step, or is asserting it and holding it there for 100 msec sufficient?

You should assert PERST# before doing any controller initialization sequence as that may affect the endpoint. Once PERST# is asserted, it will cause the endpoint to 'reset'. So you do your initialization sequence and deassert it once done.

Quoted 68 lines
Quoted 15 lines
Quoted 15 lines

Is that right?

Quoted 12 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 280

Quoted 9 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +9 -0
+
+	/* Hold the PHY in reset until we start the link */
+	regmap_set_bits(k1->pmu, k1->pmu_off + PCIE_CLK_RESET_CONTROL,
+			APP_HOLD_PHY_RST);
+
+	k1->phy = devm_phy_get(dev, NULL);
+	if (IS_ERR(k1->phy))
+		return dev_err_probe(dev, PTR_ERR(k1->phy),
+				     "failed to get PHY\n");

Once you move these properties to Root Port binding, you need to have per-Root Port parser. Again, you can refer the STM32 driver.

Quoted 6 lines
Quoted 3 lines

I see getting the PHY in stm32_pcie_parse_port(), but nothing about the supply (which you mentioned in the other message).

To conclude, you should move forward with defining the PHY and supply properties in the Root Port node, but parse/handle them in this driver itself.

Got it.

Quoted 24 lines
Quoted 11 lines
Quoted 10 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 287

Quoted 7 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +7 -0
+
+	k1->pci.dev = dev;
+	k1->pci.ops = &k1_pcie_ops;
+	dw_pcie_cap_set(&k1->pci, REQ_RES);
+
+	k1->pci.pp.ops = &k1_pcie_host_ops;
+	k1->pci.pp.num_vectors = MAX_MSI_IRQS;

This driver is just using a single 'msi' vector, which can only support 32 MSIs. But MAX_MSI_IRQS is 256. So this looks wrong.

Quoted 4 lines

In dw_pcie_host_init(), if unspecified, MSI_DEF_NUM_VECTORS=32 is used for num_vectors. If it is specified, only if the value exceeds MAX_MSI_IRQS=256 is an error returned.

Yes, because the driver trusts the glue drivers to provide the num_vectors if they support more than 32.

Quoted 5 lines

In dw_handle_msi_irq(), "num_ctrls" is computed based on num_vectors / MAX_MSI_IRQS_PER_CTRL=32. A loop then iterates over those "controllers"(?) to handle each bit set in their corresponding register.

Quoted 6 lines
Quoted 2 lines

This seems OK. Can you explain why you think it's wrong?

So both 'ctrl' and 'msi' IRQs are interrelated. Each 'ctrl' can have upto 32 MSI vectors only. If your platform supports more than 32 MSI vectors, like 256, then the platform DT should provide 8 'msi' IRQs.

I have asked SpacemiT about this, specifically whether there are additional interrupts (I don't think there are), or if not that, additional registers to support MSI 32+ (see below). In their downstream driver they handle interrupts differently. I suspect num_vectors needs to be set to 32 (or I'll leave it unset and take the default).

In the DesignWare driver, there are up to 8 "ctrls", and each ctrl has 32 bit positions representing 32 MSI vectors. Each can have an msi_irq defined. An msi_irq is always set up for ctrl 0.

Quoted 9 lines

For any ctrl with an msi_irq assigned, dw_pcie_msi_host_init() sets its interrupt handler to dw_chained_msi_isr(), which just calls dw_handle_msi_irq().

The way dw_handle_msi_irq() works, a single ctrl apparently can handle up to 256 MSI vectors, as long as the block of 3 registers that manage the ctrl (ENABLE, MASK, and STATUS presumably) are consecutive in I/O memory for consecutive ctrls.

I'm not sure how you came up with this observation. dw_handle_msi_irq() loops over the 'status' using find_next_bit() of size MAX_MSI_IRQS_PER_CTRL, which is
32. So I don't see how a single ctrl can handle up to 256 vectors.

Quoted 7 lines

I looked for other examples. I see that "pcie-fu740.c", which supports compatible "sifive,fu740-pcie", sets num_vectors to MAX_MSI_IRQS, but "fu740-c000.dtsi" defines just one "msi" interrupt. And "pci-dra7xx.c" seems to do something similar, and maybe "pcie-rcar-gen4.c" too.

Yes. But I think those are mistakes. I will submit patches to fix them.

Quoted 49 lines
Quoted 41 lines

Currently the driver is not strict about this requirement. I will send a patch to print an error message if this requirement is not satisfied.

Quoted 10 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 290

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +3 -0
+
+	platform_set_drvdata(pdev, k1);
+

For setting the correct runtime PM state of the controller, you should do:

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Quoted 7 lines

OK, that's easy enough.

Quoted 2 lines

This will fix the runtime PM hierarchy of PCIe chain (from host controller to client drivers). Otherwise, it will be broken.

Is this documented somewhere? (It wouldn't surprise me if it is and I just missed it.)

Sorry no. It is on my todo list. But I'm getting motivation now.

Quoted 4 lines

This driver has as its origins some vendor code, and I simply removed the runtime PM calls. I didn't realize something would be broken without making pm_runtime*() calls.

It is the PM framework requirement to mark the device as 'active' to allow it to participate in runtime PM. If you do not mark it as 'active' and 'enable' it, the framework will not allow propagating the runtime PM changes before *this* device. For instance, consider the generic PCI topology:

PCI controller (platform device)

	|
PCI host bridge
	|
PCI Root Port
	|

PCI endpoint device

Quoted 7 lines

If the runtime PM is not enabled for the PCI Root Port, then if the PCI endpoint device runtime suspends, it will not trigger runtime suspend for the Root Port and also for the PCI controller. Also, since the runtime PM framework doesn't have the visibility of the devices underneath the bus (like endpoint), it may assume that no devices (children) are currently active and may trigger runtime suspend of the Root Port (parent) even though the endpoint device could be 'active'.

Quoted 3 lines

So this basically marks this controller as a pass-through device that doesn't itself change state for runtime PM, but still communicates that somewhere at or below it there might be devices that do participate.

Yes.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
author
#25 lore raw

Re: [PATCH v2 5/7] PCI: spacemit: introduce SpacemiT PCIe host driver

Quoted 64 lines · Manivannan Sadhasivam
Quoted 43 lines · Alex Elder
Quoted 11 lines · Manivannan Sadhasivam
Quoted 10 lines · Alex Elder
Quoted 9 lines · Manivannan Sadhasivam
Quoted 8 lines · Alex Elder

Introduce a driver for the PCIe host controller found in the SpacemiT K1 SoC. The hardware is derived from the Synopsys DesignWare PCIe IP. The driver supports three PCIe ports that operate at PCIe gen2 transfer rates (5 GT/sec). The first port uses a combo PHY, which may be configured for use for USB 3 instead.

---

. . .

Quoted 28 lines
Quoted 10 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 271

Quoted 4 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +4 -0
+	ret = devm_regulator_get_enable(dev, "vpcie3v3-supply");
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to get \"vpcie3v3\" supply\n");

As mentioned in the bindings patch, you should rely on the PWRCTRL_SLOT driver to handle the power supplies. It is not yet handling the PERST#, but I have a series floating for that:
https://lore.kernel.org/linux-pci/[email protected]/

Quoted 5 lines

I think that just means that I'll define a DT node compatible with "pciclass,0604", and in that node I'll specify the vpcie3v3-supply property. That will cause that (pwrctrl) device to get and enable the supply before the "real" PCIe device probes.

Right.

Quoted 5 lines

And once your PERST work gets merged into the PCI power control framework, a callback will allow that to assert PERST# as needed surrounding power transitions. (But I won't worry about that for now.)

I'm still nervous to say that you should not worry about it (about not deasserting PERST# at the right time) as it goes against the PCIe spec. Current pwrctrl platforms supporting PERST# are working fine due to sheer luck.

Quoted 7 lines
Quoted 3 lines

So it would be better to leave the pwrctrl driver out of the equation now and enable the supply in this driver itself. Later, once my pwrctrl rework gets merged, I will try to switch this driver to use it.

As I understand it, PERST# should be only be deasserted after all power rails are known to be stable.

Yes

Quoted 10 lines

This driver enables the regulator during probe, shortly before calling dw_pcie_host_init(). That function calls back to k1_pcie_init(), which enables clocks, deasserts resets, and initializes the PHY before it changes the PERST# state.

By "changing the PERST# state" I mean it is asserted (driven low), then deasserted after 100 milliseconds (PCIE_T_PVPERL_MS).

Quoted 7 lines
Quoted 4 lines

I have two questions on this:
- You say the PCI spec talks about the "right time" to deassert PERST# (relative to power). Is that at all related to PCIE_T_PVPERL_MS?

The PCI CEM spec says that PERST# should be deasserted atleast 100ms after the power becomes stable. But with the current pwrctrl design, the host controller

So it *is* related to that delay, but the concern you have is about the pwrctrl design. Simply probing the pwrctrl device enables all its regulators, but that probe is not synchronized with the host controller driver. In this driver, PERST# is deasserted in the dw_pcie_host_ops->init callback, which could be called *before* the pwrctrl probe, and we want it to occur only *after* it.

I find on my system that (at least based on printk() time stamps) the PERST# is deasserted *before* regulator_bulk_enable() in pci_pwrctrl_slot_probe() has completed. So you're absolutely right about the problem. The NVMe device doesn't probe until at least 5 seconds later.

I don't want to rely on this sketchy behavior, so here is what I plan to do (please tell me whether you agree).

I will back out the change that moves the regulator into the root port. I will still use the pwrctrl model--meaning the root port will still be compatible with "pciclass,0604"--but because it will define no regulators or clocks, it just won't do anything of value for now.

Later, when you add the callback to the pwrctrl framework, we can implement that callback and then move the regulator definitions into the root port, and no longer enable them in the host controller driver.

Quoted 5 lines

deasserts the PERST# even before the pwrctrl probe. So this is in violation of the spec. But depending on the endpoint device design, this might not cause any issue as PERST# is a level triggered signal. So once the endpoint boots up, it will see the PERST# deassert and will start working. I'm not justifying the current design, but just mentioning that you might not see any issue.

I'm not seeing any issue, but it's true, the sequence of events is not compliant with what you describe from the spec.

Quoted 4 lines

That being said, we are going to submit a series that reworks pwrctrl framework such that each controller can call an API to probe pwrctrl drivers. This way, host controller driver can make sure that the device will get powered ON before it deasserts the PERST#.

For DesignWare-based devices that might mean a new dw_pcie_host_ops callback function, or maybe it can just defer calling its ->init callback until it knows power is enabled and stable.

Quoted 11 lines
Quoted 6 lines

- I notice that PERST# is in a deasserted state at the time I assert it in this sequence. Do you see any reason I should assert it early as an initialization step, or is asserting it and holding it there for 100 msec sufficient?

You should assert PERST# before doing any controller initialization sequence as that may affect the endpoint. Once PERST# is asserted, it will cause the endpoint to 'reset'. So you do your initialization sequence and deassert it once done.

Basically the probe function does basic setup, then calls dw_pcie_host_init(). The next thing that's expected is the ->init callback from the DesignWare core code, and that's where PERST# is asserted, then deasserted after some other actions.

I think I'll assert PERST# (and delay 100 msec) a little earlier though.

. . .

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines

In dw_handle_msi_irq(), "num_ctrls" is computed based on num_vectors / MAX_MSI_IRQS_PER_CTRL=32. A loop then iterates over those "controllers"(?) to handle each bit set in their corresponding register.

This seems OK. Can you explain why you think it's wrong?

So both 'ctrl' and 'msi' IRQs are interrelated. Each 'ctrl' can have upto 32 MSI vectors only. If your platform supports more than 32 MSI vectors, like 256, then the platform DT should provide 8 'msi' IRQs.

Quoted 6 lines
Quoted 6 lines

I have asked SpacemiT about this, specifically whether there are additional interrupts (I don't think there are), or if not that, additional registers to support MSI 32+ (see below). In their downstream driver they handle interrupts differently. I suspect num_vectors needs to be set to 32 (or I'll leave it unset and take the default).

This was changed to use the default (32 MSI vectors) in v4 of this series. I haven't heard back from SpacemiT but I'm pretty sure this is correct.

Quoted 15 lines
Quoted 5 lines

In the DesignWare driver, there are up to 8 "ctrls", and each ctrl has 32 bit positions representing 32 MSI vectors. Each can have an msi_irq defined. An msi_irq is always set up for ctrl 0.

Quoted 9 lines

For any ctrl with an msi_irq assigned, dw_pcie_msi_host_init() sets its interrupt handler to dw_chained_msi_isr(), which just calls dw_handle_msi_irq().

The way dw_handle_msi_irq() works, a single ctrl apparently can handle up to 256 MSI vectors, as long as the block of 3 registers that manage the ctrl (ENABLE, MASK, and STATUS presumably) are consecutive in I/O memory for consecutive ctrls.

Quoted 3 lines

I'm not sure how you came up with this observation. dw_handle_msi_irq() loops over the 'status' using find_next_bit() of size MAX_MSI_IRQS_PER_CTRL, which is
32. So I don't see how a single ctrl can handle up to 256 vectors.

This doesn't matter, because you say it's not correct, but I'll explain what I meant.

I'm saying *if* there were 8 consecutive sets of 3 registers for these ctrls:

          ----------
ctrl0:    | ENABLE |
          |--------|
          | STATUS |
          |--------|
          |  MASK  |
          |--------|
ctrl1:    | ENABLE |
          |--------|
          | STATUS |
          |--------|
          |  MASK  |
          |--------|
             ...

then they could all be handled by a single interrupt, based on the way the loop works.

If every ctrl has its own interrupt, then the interrupt handler could just handle the one ctrl's 32 possible interrupts.

This loop structure is why I thought it was OK to have 256 MSI vectors with the one handler.

Quoted 8 lines
Quoted 6 lines

I looked for other examples. I see that "pcie-fu740.c", which supports compatible "sifive,fu740-pcie", sets num_vectors to MAX_MSI_IRQS, but "fu740-c000.dtsi" defines just one "msi" interrupt. And "pci-dra7xx.c" seems to do something similar, and maybe "pcie-rcar-gen4.c" too.

Yes. But I think those are mistakes. I will submit patches to fix them.

OK. They reinforced my thought that this was doing the right thing. The warning you added makes it clear it is not.

Thank you very much for your explanation Mani.

-Alex

Quoted 56 lines
Quoted 49 lines
Quoted 41 lines

Currently the driver is not strict about this requirement. I will send a patch to print an error message if this requirement is not satisfied.

Quoted 10 lines
Quoted 9 lines

drivers/pci/controller/dwc/pcie-spacemit-k1.c line 290

Quoted 3 lines
drivers/pci/controller/dwc/pcie-spacemit-k1.c new file +3 -0
+
+	platform_set_drvdata(pdev, k1);
+

For setting the correct runtime PM state of the controller, you should do:

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Quoted 7 lines

OK, that's easy enough.

Quoted 2 lines

This will fix the runtime PM hierarchy of PCIe chain (from host controller to client drivers). Otherwise, it will be broken.

Is this documented somewhere? (It wouldn't surprise me if it is and I just missed it.)

Sorry no. It is on my todo list. But I'm getting motivation now.

Quoted 4 lines

This driver has as its origins some vendor code, and I simply removed the runtime PM calls. I didn't realize something would be broken without making pm_runtime*() calls.

It is the PM framework requirement to mark the device as 'active' to allow it to participate in runtime PM. If you do not mark it as 'active' and 'enable' it, the framework will not allow propagating the runtime PM changes before *this* device. For instance, consider the generic PCI topology:

PCI controller (platform device)

	|
PCI host bridge
	|
PCI Root Port
	|

PCI endpoint device

Quoted 7 lines

If the runtime PM is not enabled for the PCI Root Port, then if the PCI endpoint device runtime suspends, it will not trigger runtime suspend for the Root Port and also for the PCI controller. Also, since the runtime PM framework doesn't have the visibility of the devices underneath the bus (like endpoint), it may assume that no devices (children) are currently active and may trigger runtime suspend of the Root Port (parent) even though the endpoint device could be 'active'.

Quoted 3 lines

So this basically marks this controller as a pass-through device that doesn't itself change state for runtime PM, but still communicates that somewhere at or below it there might be devices that do participate.

Yes.

- Mani

author
#26 lore raw

PATCH v2 6/7 riscv: dts: spacemit: add a PCIe regulator

In reply to Alex Elder

Define a 3.3v fixed voltage regulator to be used by PCIe on the Banana Pi BPI-F3. On this platform, this regulator is always on.

---
v2: - New patch, for a newly-added regulator

 arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +8 -0
index 2aaaff77831e1..046ad441b7b4e 100644
@@ -30,6 +30,14 @@ led1 {
 			default-state = "on";
 		};
 	};
+
+	pcie_vcc_3v3: pcie-vcc3v3 {
+		compatible = "regulator-fixed";
+		regulator-name = "PCIE_VCC3V3";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+		regulator-always-on;
+	};
 };
 
 &emmc {
Signature · 1 line
2.48.1
author
#27 lore raw

PATCH v2 7/7 riscv: dts: spacemit: PCIe and PHY-related updates

In reply to Alex Elder

Define PCIe and PHY-related Device Tree nodes for the SpacemiT K1 SoC.

Enable the combo PHY and the two PCIe-only PHYs on the Banana Pi BPI-F3 board. The combo PHY is used for USB on this board, and that will be enabled when USB 3 support is accepted.

The combo PHY must perform a calibration step to determine configuration values used by the PCIe-only PHYs. As a result, it must be enabled if either of the other two PHYs is enabled.

---
v2: - Added vpcie3v3-supply nodes to PCIe ports
- Combo PHY node is now defined earlier in the file (alphabetized)

 .../boot/dts/spacemit/k1-bananapi-f3.dts      |  30 ++++
 arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi  |  33 ++++
 arch/riscv/boot/dts/spacemit/k1.dtsi          | 151 ++++++++++++++++++
 3 files changed, 214 insertions(+)
arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +30 -0
index 046ad441b7b4e..6d566780aed9d 100644
@@ -40,6 +40,12 @@ pcie_vcc_3v3: pcie-vcc3v3 {
 	};
 };
 
+&combo_phy {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pcie0_3_cfg>;
+	status = "okay";
+};
+
 &emmc {
 	bus-width = <8>;
 	mmc-hs400-1_8v;
@@ -100,6 +106,30 @@ &pdma {
 	status = "okay";
 };
 
+&pcie1_phy {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pcie1_3_cfg>;
+	status = "okay";
+};
+
+&pcie2_phy {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pcie2_4_cfg>;
+	status = "okay";
+};
+
+&pcie1 {
+	phys = <&pcie1_phy>;
+	vpcie3v3-supply = <&pcie_vcc_3v3>;
+	status = "okay";
+};
+
+&pcie2 {
+	phys = <&pcie2_phy>;
+	vpcie3v3-supply = <&pcie_vcc_3v3>;
+	status = "okay";
+};
+
 &uart0 {
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart0_2_cfg>;
arch/riscv/boot/dts/spacemit/k1-pinctrl.dtsi +33 -0
index aff19c86d5ff3..5bacb6aff23f8 100644
@@ -69,6 +69,39 @@ uart0-2-pins {
 		};
 	};
 
+	pcie0_3_cfg: pcie0-3-cfg {
+		pcie0-3-pins {
+			pinmux = <K1_PADCONF(54, 3)>,	/* PERST# */
+				 <K1_PADCONF(55, 3)>,	/* WAKE# */
+				 <K1_PADCONF(53, 3)>;	/* CLKREQ# */
+
+			bias-pull-up = <0>;
+			drive-strength = <21>;
+		};
+	};
+
+	pcie1_3_cfg: pcie1-3-cfg {
+		pcie1-3-pins {
+			pinmux = <K1_PADCONF(59, 4)>,	/* PERST# */
+				 <K1_PADCONF(60, 4)>,	/* WAKE# */
+				 <K1_PADCONF(61, 4)>;	/* CLKREQ# */
+
+			bias-pull-up = <0>;
+			drive-strength = <21>;
+		};
+	};
+
+	pcie2_4_cfg: pcie2-4-cfg {
+		pcie2-4-pins {
+			pinmux = <K1_PADCONF(62, 4)>,	/* PERST# */
+				 <K1_PADCONF(112, 3)>,	/* WAKE# */
+				 <K1_PADCONF(117, 4)>;	/* CLKREQ# */
+
+			bias-pull-up = <0>;
+			drive-strength = <21>;
+		};
+	};
+
 	pwm14_1_cfg: pwm14-1-cfg {
 		pwm14-1-pins {
 			pinmux = <K1_PADCONF(44, 4)>;
arch/riscv/boot/dts/spacemit/k1.dtsi +151 -0

169 lines not on this page · raw message

Signature · 1 line
2.48.1
#28 lore raw
In reply to Alex Elder

Hi Alex,

Quoted 7 lines · Alex Elder

This series introduces a PHY driver and a PCIe driver to support PCIe on the SpacemiT K1 SoC. The PCIe implementation is derived from a Synopsys DesignWare PCIe IP. The PHY driver supports one combination PCIe/USB PHY as well as two PCIe-only PHYs. The combo PHY port uses one PCIe lane, and the other two ports each have two lanes. All PCIe ports operate at 5 GT/second.

Quoted 8 lines

The PCIe PHYs must be configured using a value that can only be determined using the combo PHY, operating in PCIe mode. To allow that PHY to be used for USB, the calibration step is performed by the PHY driver automatically at probe time. Once this step is done, the PHY can be used for either PCIe or USB.

Version 2 of this series incorporates suggestions made during the review of version 1. Specific highlights are detailed below.

With the issues mentioned in patch 4 fixed, this patchset works fine for me. That said I had to disable ASPM by passing pcie_aspm=off on the command line, as it is now enabled by default since 6.18-rc1 [1]. At this stage, I am not sure if it is an issue with my NVME drive or an issue with the controller.

Regards
Aurelien

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f3ac2ff14834a0aa056ee3ae0e4b8c641c579961

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                     http://aurel32.net
author
#29 lore raw
Quoted 16 lines · Aurelien Jarno

Hi Alex,

Quoted 13 lines · Alex Elder

This series introduces a PHY driver and a PCIe driver to support PCIe on the SpacemiT K1 SoC. The PCIe implementation is derived from a Synopsys DesignWare PCIe IP. The PHY driver supports one combination PCIe/USB PHY as well as two PCIe-only PHYs. The combo PHY port uses one PCIe lane, and the other two ports each have two lanes. All PCIe ports operate at 5 GT/second.

The PCIe PHYs must be configured using a value that can only be determined using the combo PHY, operating in PCIe mode. To allow that PHY to be used for USB, the calibration step is performed by the PHY driver automatically at probe time. Once this step is done, the PHY can be used for either PCIe or USB.

Quoted 8 lines
Quoted 2 lines

Version 2 of this series incorporates suggestions made during the review of version 1. Specific highlights are detailed below.

With the issues mentioned in patch 4 fixed, this patchset works fine for me. That said I had to disable ASPM by passing pcie_aspm=off on the command line, as it is now enabled by default since 6.18-rc1 [1]. At this stage, I am not sure if it is an issue with my NVME drive or an issue with the controller.

Can you describe what symptoms you had that required you to pass "pcie_aspm=off" on the kernel command line?

I see these lines in my boot log related to ASPM (and added by the commit you link to), for both pcie1 and pcie2:

pci 0000:01:00.0: ASPM: DT platform, enabling L0s-up L0s-dw L1 AS
PM-L1.1 ASPM-L1.2 PCI-PM-L1.1 PCI-PM-L1.2
pci 0000:01:00.0: ASPM: DT platform, enabling ClockPM

. . .

nvme nvme0: pci function 0000:01:00.0
nvme 0000:01:00.0: enabling device (0000 -> 0002) nvme nvme0: allocated 64 MiB host memory buffer (16 segments). nvme nvme0: 8/0/0 default/read/poll queues
nvme0n1: p1

My NVMe drive on pcie1 works correctly.
https://www.crucial.com/ssd/p3/CT1000P3SSD8

  root@bananapif3:~# df /a
  Filesystem     1K-blocks     Used Available Use% Mounted on
  /dev/nvme0n1p1 960302804 32063304 879385040   4% /a
  root@bananapif3:~#

I basically want to know if there's something I should do with this driver to address this. (Mani, can you explain?)

Thank you.

-Alex

Quoted 5 lines

Regards
Aurelien

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f3ac2ff14834a0aa056ee3ae0e4b8c641c579961

#30 lore raw

Hi Alex,

Quoted 44 lines · Alex Elder
Quoted 16 lines · Aurelien Jarno

Hi Alex,

Quoted 13 lines · Alex Elder

This series introduces a PHY driver and a PCIe driver to support PCIe on the SpacemiT K1 SoC. The PCIe implementation is derived from a Synopsys DesignWare PCIe IP. The PHY driver supports one combination PCIe/USB PHY as well as two PCIe-only PHYs. The combo PHY port uses one PCIe lane, and the other two ports each have two lanes. All PCIe ports operate at 5 GT/second.

The PCIe PHYs must be configured using a value that can only be determined using the combo PHY, operating in PCIe mode. To allow that PHY to be used for USB, the calibration step is performed by the PHY driver automatically at probe time. Once this step is done, the PHY can be used for either PCIe or USB.

Quoted 8 lines
Quoted 2 lines

Version 2 of this series incorporates suggestions made during the review of version 1. Specific highlights are detailed below.

With the issues mentioned in patch 4 fixed, this patchset works fine for me. That said I had to disable ASPM by passing pcie_aspm=off on the command line, as it is now enabled by default since 6.18-rc1 [1]. At this stage, I am not sure if it is an issue with my NVME drive or an issue with the controller.

Can you describe what symptoms you had that required you to pass "pcie_aspm=off" on the kernel command line?

I see these lines in my boot log related to ASPM (and added by the commit you link to), for both pcie1 and pcie2:

pci 0000:01:00.0: ASPM: DT platform, enabling L0s-up L0s-dw L1 AS
PM-L1.1 ASPM-L1.2 PCI-PM-L1.1 PCI-PM-L1.2
pci 0000:01:00.0: ASPM: DT platform, enabling ClockPM

. . .

nvme nvme0: pci function 0000:01:00.0
nvme 0000:01:00.0: enabling device (0000 -> 0002) nvme nvme0: allocated 64 MiB host memory buffer (16 segments). nvme nvme0: 8/0/0 default/read/poll queues
nvme0n1: p1

Quoted 7 lines

My NVMe drive on pcie1 works correctly.
https://www.crucial.com/ssd/p3/CT1000P3SSD8

  root@bananapif3:~# df /a
  Filesystem     1K-blocks     Used Available Use% Mounted on
  /dev/nvme0n1p1 960302804 32063304 879385040   4% /a
  root@bananapif3:~#

Sorry for the delay, it took me time to test some more things and different SSDs. First of all I still see the issue with your v3 on top of v6.18-rc3, which includes some fixes for ASPM support [1].

I have tried 3 different SSDs, none of them are working, but the symptoms are different, although all related with ASPM (pcie_aspm=off workarounds the issue).

With a Fox Spirit PM18 SSD (Silicon Motion, Inc. SM2263EN/SM2263XT controller), I do not have more than this:

[    5.196723] nvme nvme0: pci function 0000:01:00.0
[    5.198843] nvme 0000:01:00.0: enabling device (0000 -> 0002)

With a WD Blue SN570 SSD, I get this:

[    5.199513] nvme nvme0: pci function 0000:01:00.0
[    5.201653] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[    5.270334] nvme nvme0: allocated 32 MiB host memory buffer (8 segments).
[    5.277624] nvme nvme0: 8/0/0 default/read/poll queues
[   19.192350] nvme nvme0: using unchecked data buffer
[   48.108400] nvme nvme0: controller is down; will reset: CSTS=0xffffffff, PCI_STATUS=0x10
[   48.113885] nvme nvme0: Does your device have a faulty power saving mode enabled?
[   48.121346] nvme nvme0: Try "nvme_core.default_ps_max_latency_us=0 pcie_aspm=off pcie_port_pm=off" and report a bug
[   48.176878] nvme0n1: I/O Cmd(0x2) @ LBA 0, 8 blocks, I/O Error (sct 0x3 / sc 0x71) 
[   48.181926] I/O error, dev nvme0n1, sector 0 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 2
[   48.243670] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[   48.246914] nvme nvme0: Disabling device after reset failure: -19
[   48.280495] Buffer I/O error on dev nvme0n1, logical block 0, async page read

Finally with a PNY CS1030 SSD (Phison PS5015-E15 controller), I get this:

[    5.215631] nvme nvme0: pci function 0000:01:00.0
[    5.220435] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[    5.329565] nvme nvme0: allocated 64 MiB host memory buffer (16 segments).
[   66.540485] nvme nvme0: I/O tag 28 (401c) QID 0 timeout, disable controller
[   66.585245] nvme 0000:01:00.0: probe with driver nvme failed with error -4

Note that I also tested this latest SSD on a VisionFive 2 board with exactly the same kernel (I just moved the SSD and booted), and it works fine with ASPM enabled (confirmed with lspci).

Quoted 2 lines

I basically want to know if there's something I should do with this driver to address this. (Mani, can you explain?)

I am not sure on my side how to debug that. What I know is that it is linked to ASPM L1, L0 works fine. In other words the SSDs work fine with this patch:

drivers/pci/pcie/aspm.c +2 -2
index 79b9651584737..1a134ec68b591 100644
@@ -801,8 +801,8 @@ static void pcie_aspm_override_default_link_state(struct pcie_link_state *link)
 	if (of_have_populated_dt()) {
 		if (link->aspm_support & PCIE_LINK_STATE_L0S)
 			link->aspm_default |= PCIE_LINK_STATE_L0S;
-		if (link->aspm_support & PCIE_LINK_STATE_L1)
-			link->aspm_default |= PCIE_LINK_STATE_L1;
+//		if (link->aspm_support & PCIE_LINK_STATE_L1)
+//			link->aspm_default |= PCIE_LINK_STATE_L1;
 		override = link->aspm_default & ~link->aspm_enabled;
 		if (override)
 			pci_info(pdev, "ASPM: default states%s%s\n",

I can test more things if needed, but I don't know where to start.

Regards
Aurelien

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=df5192d9bb0e38bf831fb93e8026e346aa017ca8

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                     http://aurel32.net
#31 lore raw
Quoted 91 lines · Aurelien Jarno

Hi Alex,

Quoted 44 lines · Alex Elder
Quoted 16 lines · Aurelien Jarno

Hi Alex,

Quoted 13 lines · Alex Elder

This series introduces a PHY driver and a PCIe driver to support PCIe on the SpacemiT K1 SoC. The PCIe implementation is derived from a Synopsys DesignWare PCIe IP. The PHY driver supports one combination PCIe/USB PHY as well as two PCIe-only PHYs. The combo PHY port uses one PCIe lane, and the other two ports each have two lanes. All PCIe ports operate at 5 GT/second.

The PCIe PHYs must be configured using a value that can only be determined using the combo PHY, operating in PCIe mode. To allow that PHY to be used for USB, the calibration step is performed by the PHY driver automatically at probe time. Once this step is done, the PHY can be used for either PCIe or USB.

Quoted 8 lines
Quoted 2 lines

Version 2 of this series incorporates suggestions made during the review of version 1. Specific highlights are detailed below.

With the issues mentioned in patch 4 fixed, this patchset works fine for me. That said I had to disable ASPM by passing pcie_aspm=off on the command line, as it is now enabled by default since 6.18-rc1 [1]. At this stage, I am not sure if it is an issue with my NVME drive or an issue with the controller.

Can you describe what symptoms you had that required you to pass "pcie_aspm=off" on the kernel command line?

I see these lines in my boot log related to ASPM (and added by the commit you link to), for both pcie1 and pcie2:

pci 0000:01:00.0: ASPM: DT platform, enabling L0s-up L0s-dw L1 AS
PM-L1.1 ASPM-L1.2 PCI-PM-L1.1 PCI-PM-L1.2
pci 0000:01:00.0: ASPM: DT platform, enabling ClockPM

. . .

nvme nvme0: pci function 0000:01:00.0
nvme 0000:01:00.0: enabling device (0000 -> 0002) nvme nvme0: allocated 64 MiB host memory buffer (16 segments). nvme nvme0: 8/0/0 default/read/poll queues
nvme0n1: p1

Quoted 7 lines

My NVMe drive on pcie1 works correctly.
https://www.crucial.com/ssd/p3/CT1000P3SSD8

  root@bananapif3:~# df /a
  Filesystem     1K-blocks     Used Available Use% Mounted on
  /dev/nvme0n1p1 960302804 32063304 879385040   4% /a
  root@bananapif3:~#

Sorry for the delay, it took me time to test some more things and different SSDs. First of all I still see the issue with your v3 on top of v6.18-rc3, which includes some fixes for ASPM support [1].

I have tried 3 different SSDs, none of them are working, but the symptoms are different, although all related with ASPM (pcie_aspm=off workarounds the issue).

With a Fox Spirit PM18 SSD (Silicon Motion, Inc. SM2263EN/SM2263XT controller), I do not have more than this:

[    5.196723] nvme nvme0: pci function 0000:01:00.0
[    5.198843] nvme 0000:01:00.0: enabling device (0000 -> 0002)

With a WD Blue SN570 SSD, I get this:

[    5.199513] nvme nvme0: pci function 0000:01:00.0
[    5.201653] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[    5.270334] nvme nvme0: allocated 32 MiB host memory buffer (8 segments).
[    5.277624] nvme nvme0: 8/0/0 default/read/poll queues
[   19.192350] nvme nvme0: using unchecked data buffer
[   48.108400] nvme nvme0: controller is down; will reset: CSTS=0xffffffff, PCI_STATUS=0x10
[   48.113885] nvme nvme0: Does your device have a faulty power saving mode enabled?
[   48.121346] nvme nvme0: Try "nvme_core.default_ps_max_latency_us=0 pcie_aspm=off pcie_port_pm=off" and report a bug
[   48.176878] nvme0n1: I/O Cmd(0x2) @ LBA 0, 8 blocks, I/O Error (sct 0x3 / sc 0x71) 
[   48.181926] I/O error, dev nvme0n1, sector 0 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 2
[   48.243670] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[   48.246914] nvme nvme0: Disabling device after reset failure: -19
[   48.280495] Buffer I/O error on dev nvme0n1, logical block 0, async page read

Finally with a PNY CS1030 SSD (Phison PS5015-E15 controller), I get this:

[    5.215631] nvme nvme0: pci function 0000:01:00.0
[    5.220435] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[    5.329565] nvme nvme0: allocated 64 MiB host memory buffer (16 segments).
[   66.540485] nvme nvme0: I/O tag 28 (401c) QID 0 timeout, disable controller
[   66.585245] nvme 0000:01:00.0: probe with driver nvme failed with error -4
Quoted 3 lines

Note that I also tested this latest SSD on a VisionFive 2 board with exactly the same kernel (I just moved the SSD and booted), and it works fine with ASPM enabled (confirmed with lspci).

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

Of note, I don't have this problem with the vendor 6.6.63 kernel.

Quoted 23 lines
Quoted 2 lines

I basically want to know if there's something I should do with this driver to address this. (Mani, can you explain?)

I am not sure on my side how to debug that. What I know is that it is linked to ASPM L1, L0 works fine. In other words the SSDs work fine with this patch:

drivers/pci/pcie/aspm.c +2 -2
index 79b9651584737..1a134ec68b591 100644
@@ -801,8 +801,8 @@ static void pcie_aspm_override_default_link_state(struct pcie_link_state *link)
 	if (of_have_populated_dt()) {
 		if (link->aspm_support & PCIE_LINK_STATE_L0S)
 			link->aspm_default |= PCIE_LINK_STATE_L0S;
-		if (link->aspm_support & PCIE_LINK_STATE_L1)
-			link->aspm_default |= PCIE_LINK_STATE_L1;
+//		if (link->aspm_support & PCIE_LINK_STATE_L1)
+//			link->aspm_default |= PCIE_LINK_STATE_L1;
 		override = link->aspm_default & ~link->aspm_enabled;
 		if (override)
 			pci_info(pdev, "ASPM: default states%s%s\n",
Quoted 1 line

I can test more things if needed, but I don't know where to start.

I'm not a PCIe expert, but I'm more than happy to test as well.

JE

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
author
#32 lore raw
Quoted 96 lines · Johannes Erdfelt
Quoted 91 lines · Aurelien Jarno

Hi Alex,

Quoted 44 lines · Alex Elder
Quoted 16 lines · Aurelien Jarno

Hi Alex,

Quoted 13 lines · Alex Elder

This series introduces a PHY driver and a PCIe driver to support PCIe on the SpacemiT K1 SoC. The PCIe implementation is derived from a Synopsys DesignWare PCIe IP. The PHY driver supports one combination PCIe/USB PHY as well as two PCIe-only PHYs. The combo PHY port uses one PCIe lane, and the other two ports each have two lanes. All PCIe ports operate at 5 GT/second.

The PCIe PHYs must be configured using a value that can only be determined using the combo PHY, operating in PCIe mode. To allow that PHY to be used for USB, the calibration step is performed by the PHY driver automatically at probe time. Once this step is done, the PHY can be used for either PCIe or USB.

Quoted 8 lines
Quoted 2 lines

Version 2 of this series incorporates suggestions made during the review of version 1. Specific highlights are detailed below.

With the issues mentioned in patch 4 fixed, this patchset works fine for me. That said I had to disable ASPM by passing pcie_aspm=off on the command line, as it is now enabled by default since 6.18-rc1 [1]. At this stage, I am not sure if it is an issue with my NVME drive or an issue with the controller.

Can you describe what symptoms you had that required you to pass "pcie_aspm=off" on the kernel command line?

I see these lines in my boot log related to ASPM (and added by the commit you link to), for both pcie1 and pcie2:

pci 0000:01:00.0: ASPM: DT platform, enabling L0s-up L0s-dw L1 AS
PM-L1.1 ASPM-L1.2 PCI-PM-L1.1 PCI-PM-L1.2
pci 0000:01:00.0: ASPM: DT platform, enabling ClockPM

   . . .

   nvme nvme0: pci function 0000:01:00.0
   nvme 0000:01:00.0: enabling device (0000 -> 0002)
   nvme nvme0: allocated 64 MiB host memory buffer (16 segments).
   nvme nvme0: 8/0/0 default/read/poll queues
    nvme0n1: p1
Quoted 7 lines

My NVMe drive on pcie1 works correctly.
https://www.crucial.com/ssd/p3/CT1000P3SSD8

   root@bananapif3:~# df /a
   Filesystem     1K-blocks     Used Available Use% Mounted on
   /dev/nvme0n1p1 960302804 32063304 879385040   4% /a
   root@bananapif3:~#

Sorry for the delay, it took me time to test some more things and different SSDs. First of all I still see the issue with your v3 on top of v6.18-rc3, which includes some fixes for ASPM support [1].

I have tried 3 different SSDs, none of them are working, but the symptoms are different, although all related with ASPM (pcie_aspm=off workarounds the issue).

With a Fox Spirit PM18 SSD (Silicon Motion, Inc. SM2263EN/SM2263XT controller), I do not have more than this:

[    5.196723] nvme nvme0: pci function 0000:01:00.0
[    5.198843] nvme 0000:01:00.0: enabling device (0000 -> 0002)

With a WD Blue SN570 SSD, I get this:

[    5.199513] nvme nvme0: pci function 0000:01:00.0
[    5.201653] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[    5.270334] nvme nvme0: allocated 32 MiB host memory buffer (8 segments).
[    5.277624] nvme nvme0: 8/0/0 default/read/poll queues
[   19.192350] nvme nvme0: using unchecked data buffer
[   48.108400] nvme nvme0: controller is down; will reset: CSTS=0xffffffff, PCI_STATUS=0x10
[   48.113885] nvme nvme0: Does your device have a faulty power saving mode enabled?
[   48.121346] nvme nvme0: Try "nvme_core.default_ps_max_latency_us=0 pcie_aspm=off pcie_port_pm=off" and report a bug
[   48.176878] nvme0n1: I/O Cmd(0x2) @ LBA 0, 8 blocks, I/O Error (sct 0x3 / sc 0x71)
[   48.181926] I/O error, dev nvme0n1, sector 0 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 2
[   48.243670] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[   48.246914] nvme nvme0: Disabling device after reset failure: -19
[   48.280495] Buffer I/O error on dev nvme0n1, logical block 0, async page read

Finally with a PNY CS1030 SSD (Phison PS5015-E15 controller), I get this:

[    5.215631] nvme nvme0: pci function 0000:01:00.0
[    5.220435] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[    5.329565] nvme nvme0: allocated 64 MiB host memory buffer (16 segments).
[   66.540485] nvme nvme0: I/O tag 28 (401c) QID 0 timeout, disable controller
[   66.585245] nvme 0000:01:00.0: probe with driver nvme failed with error -4
Quoted 3 lines

Note that I also tested this latest SSD on a VisionFive 2 board with exactly the same kernel (I just moved the SSD and booted), and it works fine with ASPM enabled (confirmed with lspci).

Quoted 7 lines

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

I don't see this problem, and haven't tried to reproduce it yet.

Mani told me I needed to add these lines to ensure the "runtime PM hierarchy of PCIe chain" won't be "broken":

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Just out of curiosity, could you try with those lines added just before these assignments in k1_pcie_probe()?

	k1->pci.dev = dev;
	k1->pci.ops = &k1_pcie_ops;
	dw_pcie_cap_set(&k1->pci, REQ_RES);

I doubt it will fix what you're seeing, but at the moment I'm working on something else.

Thanks.

-Alex

Quoted 31 lines

Of note, I don't have this problem with the vendor 6.6.63 kernel.

Quoted 23 lines
Quoted 2 lines

I basically want to know if there's something I should do with this driver to address this. (Mani, can you explain?)

I am not sure on my side how to debug that. What I know is that it is linked to ASPM L1, L0 works fine. In other words the SSDs work fine with this patch:

drivers/pci/pcie/aspm.c +2 -2
index 79b9651584737..1a134ec68b591 100644
@@ -801,8 +801,8 @@ static void pcie_aspm_override_default_link_state(struct pcie_link_state *link)
  	if (of_have_populated_dt()) {
  		if (link->aspm_support & PCIE_LINK_STATE_L0S)
  			link->aspm_default |= PCIE_LINK_STATE_L0S;
-		if (link->aspm_support & PCIE_LINK_STATE_L1)
-			link->aspm_default |= PCIE_LINK_STATE_L1;
+//		if (link->aspm_support & PCIE_LINK_STATE_L1)
+//			link->aspm_default |= PCIE_LINK_STATE_L1;
  		override = link->aspm_default & ~link->aspm_enabled;
  		if (override)
  			pci_info(pdev, "ASPM: default states%s%s\n",
Quoted 1 line

I can test more things if needed, but I don't know where to start.

I'm not a PCIe expert, but I'm more than happy to test as well.

JE

#33 lore raw
Quoted 21 lines · Alex Elder
Quoted 7 lines · Johannes Erdfelt

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

I don't see this problem, and haven't tried to reproduce it yet.

Mani told me I needed to add these lines to ensure the "runtime PM hierarchy of PCIe chain" won't be "broken":

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Just out of curiosity, could you try with those lines added just before these assignments in k1_pcie_probe()?

Quoted 6 lines
	k1->pci.dev = dev;
	k1->pci.ops = &k1_pcie_ops;
	dw_pcie_cap_set(&k1->pci, REQ_RES);

I doubt it will fix what you're seeing, but at the moment I'm working on something else.

Unfortunately there is no difference with the runtime PM hierarchy additions.

JE

author
#34 lore raw
Quoted 26 lines · Johannes Erdfelt
Quoted 25 lines · Alex Elder
Quoted 7 lines · Johannes Erdfelt

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

I don't see this problem, and haven't tried to reproduce it yet.

Mani told me I needed to add these lines to ensure the "runtime PM hierarchy of PCIe chain" won't be "broken":

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Just out of curiosity, could you try with those lines added just before these assignments in k1_pcie_probe()?

	k1->pci.dev = dev;
	k1->pci.ops = &k1_pcie_ops;
	dw_pcie_cap_set(&k1->pci, REQ_RES);
Quoted 7 lines
Quoted 2 lines

I doubt it will fix what you're seeing, but at the moment I'm working on something else.

Unfortunately there is no difference with the runtime PM hierarchy additions.

JE

Thank you very much for testing. I'll try to learn more about this in the next day or so and will resolve it if possible before I send the next version of this code.

-Alex

#35 lore raw
In reply to Johannes Erdfelt

+ Aurelien

Quoted 26 lines · Johannes Erdfelt
Quoted 25 lines · Alex Elder
Quoted 7 lines · Johannes Erdfelt

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

I don't see this problem, and haven't tried to reproduce it yet.

Mani told me I needed to add these lines to ensure the "runtime PM hierarchy of PCIe chain" won't be "broken":

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Just out of curiosity, could you try with those lines added just before these assignments in k1_pcie_probe()?

	k1->pci.dev = dev;
	k1->pci.ops = &k1_pcie_ops;
	dw_pcie_cap_set(&k1->pci, REQ_RES);
Quoted 6 lines
Quoted 2 lines

I doubt it will fix what you're seeing, but at the moment I'm working on something else.

Unfortunately there is no difference with the runtime PM hierarchy additions.

These are not supposed to fix the issues you were facing. I discussed with Alex offline and figured out that L1 works fine on his BPI-F3 board with a NVMe SSD.

And I believe, Aurelien is also using that same board, but with different SSDs. But what is puzzling me is, L1 is breaking Aurelien's setup with 3 SSDs from different vendors. It apparently works fine on Alex's setup. So it somehow confirms that Root Port supports and behaves correctly with L1. But at the same time, I cannot just say without evidence that L1 is broken on all these SSDs that you and Aurelien tested with.

So until that is figured out, I've asked Alex to disable L1 CAP in the controller driver. So in the next version of this series, your SSDs should work out of the box.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#36 lore raw

Hi Mani,

Quoted 39 lines · Manivannan Sadhasivam

+ Aurelien

Quoted 26 lines · Johannes Erdfelt
Quoted 25 lines · Alex Elder
Quoted 7 lines · Johannes Erdfelt

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

I don't see this problem, and haven't tried to reproduce it yet.

Mani told me I needed to add these lines to ensure the "runtime PM hierarchy of PCIe chain" won't be "broken":

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Just out of curiosity, could you try with those lines added just before these assignments in k1_pcie_probe()?

	k1->pci.dev = dev;
	k1->pci.ops = &k1_pcie_ops;
	dw_pcie_cap_set(&k1->pci, REQ_RES);
Quoted 6 lines
Quoted 2 lines

I doubt it will fix what you're seeing, but at the moment I'm working on something else.

Unfortunately there is no difference with the runtime PM hierarchy additions.

These are not supposed to fix the issues you were facing. I discussed with Alex offline and figured out that L1 works fine on his BPI-F3 board with a NVMe SSD.

Quoted 6 lines

And I believe, Aurelien is also using that same board, but with different SSDs. But what is puzzling me is, L1 is breaking Aurelien's setup with 3 SSDs from different vendors. It apparently works fine on Alex's setup. So it somehow confirms that Root Port supports and behaves correctly with L1. But at the same time, I cannot just say without evidence that L1 is broken on all these SSDs that you and Aurelien tested with.

It could be that we have different revision of the BPI-F3 board, it's not impossible that I got an early-ish version. That said I just visually checked the PCB against the schematics, and the devices on the CLKREQN line appear to be installed.

If someone has contacts to check what changes have been done between the different board revision, that could help. Or same if there are different revisions of the SpacemiT K1 chip.

Quoted 3 lines

So until that is figured out, I've asked Alex to disable L1 CAP in the controller driver. So in the next version of this series, your SSDs should work out of the box.

Thanks, that sounds good.

Regards
Aurelien

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                     http://aurel32.net
#37 lore raw
Quoted 49 lines · Aurelien Jarno

Hi Mani,

Quoted 39 lines · Manivannan Sadhasivam

+ Aurelien

Quoted 26 lines · Johannes Erdfelt
Quoted 25 lines · Alex Elder
Quoted 7 lines · Johannes Erdfelt

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

I don't see this problem, and haven't tried to reproduce it yet.

Mani told me I needed to add these lines to ensure the "runtime PM hierarchy of PCIe chain" won't be "broken":

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Just out of curiosity, could you try with those lines added just before these assignments in k1_pcie_probe()?

	k1->pci.dev = dev;
	k1->pci.ops = &k1_pcie_ops;
	dw_pcie_cap_set(&k1->pci, REQ_RES);
Quoted 6 lines
Quoted 2 lines

I doubt it will fix what you're seeing, but at the moment I'm working on something else.

Unfortunately there is no difference with the runtime PM hierarchy additions.

These are not supposed to fix the issues you were facing. I discussed with Alex offline and figured out that L1 works fine on his BPI-F3 board with a NVMe SSD.

Quoted 6 lines

And I believe, Aurelien is also using that same board, but with different SSDs. But what is puzzling me is, L1 is breaking Aurelien's setup with 3 SSDs from different vendors. It apparently works fine on Alex's setup. So it somehow confirms that Root Port supports and behaves correctly with L1. But at the same time, I cannot just say without evidence that L1 is broken on all these SSDs that you and Aurelien tested with.

Quoted 5 lines

It could be that we have different revision of the BPI-F3 board, it's not impossible that I got an early-ish version. That said I just visually checked the PCB against the schematics, and the devices on the CLKREQN line appear to be installed.

CLKREQ# is only needed for L1 PM Substates (L1.1 and L1.2). In other ASPM states (L0s and L1), REFCLK is supposed to be ON. So those don't need CLKREQ# assertion by the endpoint.

The L1 issue you are facing could be due to the board routing issue also. I'm just speculating here.

Quoted 4 lines

If someone has contacts to check what changes have been done between the different board revision, that could help. Or same if there are different revisions of the SpacemiT K1 chip.

I hope Alex can get this information.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
author
#38 lore raw
Quoted 43 lines · Manivannan Sadhasivam
Quoted 42 lines · Aurelien Jarno

Hi Mani,

Quoted 39 lines · Manivannan Sadhasivam

+ Aurelien

Quoted 26 lines · Johannes Erdfelt
Quoted 25 lines · Alex Elder
Quoted 7 lines · Johannes Erdfelt

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

I don't see this problem, and haven't tried to reproduce it yet.

Mani told me I needed to add these lines to ensure the "runtime PM hierarchy of PCIe chain" won't be "broken":

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Just out of curiosity, could you try with those lines added just before these assignments in k1_pcie_probe()?

	k1->pci.dev = dev;
	k1->pci.ops = &k1_pcie_ops;
	dw_pcie_cap_set(&k1->pci, REQ_RES);
Quoted 6 lines
Quoted 2 lines

I doubt it will fix what you're seeing, but at the moment I'm working on something else.

Unfortunately there is no difference with the runtime PM hierarchy additions.

These are not supposed to fix the issues you were facing. I discussed with Alex offline and figured out that L1 works fine on his BPI-F3 board with a NVMe SSD.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

And I believe, Aurelien is also using that same board, but with different SSDs. But what is puzzling me is, L1 is breaking Aurelien's setup with 3 SSDs from different vendors. It apparently works fine on Alex's setup. So it somehow confirms that Root Port supports and behaves correctly with L1. But at the same time, I cannot just say without evidence that L1 is broken on all these SSDs that you and Aurelien tested with.

Aurelien, can you please confirm that your reports are with the BPI-F3 board? I believe you identified the three SSDs that were failing. I am considering buying one of those models to see if I can reproduce the problem and troubleshoot it.

Quoted 13 lines
Quoted 5 lines

It could be that we have different revision of the BPI-F3 board, it's not impossible that I got an early-ish version. That said I just visually checked the PCB against the schematics, and the devices on the CLKREQN line appear to be installed.

CLKREQ# is only needed for L1 PM Substates (L1.1 and L1.2). In other ASPM states (L0s and L1), REFCLK is supposed to be ON. So those don't need CLKREQ# assertion by the endpoint.

The L1 issue you are facing could be due to the board routing issue also. I'm just speculating here.

Quoted 6 lines
Quoted 4 lines

If someone has contacts to check what changes have been done between the different board revision, that could help. Or same if there are different revisions of the SpacemiT K1 chip.

I hope Alex can get this information.

I have sent a message to SpacemiT to explain that these issues are being reported, and asking for any useful information about the BPI-F3 (including whether there are different versions, or different versions of firmware, and how someone can identify what they have).

Thanks.

-Alex

Quoted 2 lines

- Mani

#39 lore raw
In reply to Alex Elder
Quoted 117 lines · Alex Elder
Quoted 96 lines · Johannes Erdfelt
Quoted 91 lines · Aurelien Jarno

Hi Alex,

Quoted 44 lines · Alex Elder
Quoted 16 lines · Aurelien Jarno

Hi Alex,

Quoted 13 lines · Alex Elder

This series introduces a PHY driver and a PCIe driver to support PCIe on the SpacemiT K1 SoC. The PCIe implementation is derived from a Synopsys DesignWare PCIe IP. The PHY driver supports one combination PCIe/USB PHY as well as two PCIe-only PHYs. The combo PHY port uses one PCIe lane, and the other two ports each have two lanes. All PCIe ports operate at 5 GT/second.

The PCIe PHYs must be configured using a value that can only be determined using the combo PHY, operating in PCIe mode. To allow that PHY to be used for USB, the calibration step is performed by the PHY driver automatically at probe time. Once this step is done, the PHY can be used for either PCIe or USB.

Quoted 8 lines
Quoted 2 lines

Version 2 of this series incorporates suggestions made during the review of version 1. Specific highlights are detailed below.

With the issues mentioned in patch 4 fixed, this patchset works fine for me. That said I had to disable ASPM by passing pcie_aspm=off on the command line, as it is now enabled by default since 6.18-rc1 [1]. At this stage, I am not sure if it is an issue with my NVME drive or an issue with the controller.

Can you describe what symptoms you had that required you to pass "pcie_aspm=off" on the kernel command line?

I see these lines in my boot log related to ASPM (and added by the commit you link to), for both pcie1 and pcie2:

pci 0000:01:00.0: ASPM: DT platform, enabling L0s-up L0s-dw L1 AS
PM-L1.1 ASPM-L1.2 PCI-PM-L1.1 PCI-PM-L1.2
pci 0000:01:00.0: ASPM: DT platform, enabling ClockPM

   . . .

   nvme nvme0: pci function 0000:01:00.0
   nvme 0000:01:00.0: enabling device (0000 -> 0002)
   nvme nvme0: allocated 64 MiB host memory buffer (16 segments).
   nvme nvme0: 8/0/0 default/read/poll queues
    nvme0n1: p1
Quoted 7 lines

My NVMe drive on pcie1 works correctly.
https://www.crucial.com/ssd/p3/CT1000P3SSD8

   root@bananapif3:~# df /a
   Filesystem     1K-blocks     Used Available Use% Mounted on
   /dev/nvme0n1p1 960302804 32063304 879385040   4% /a
   root@bananapif3:~#

Sorry for the delay, it took me time to test some more things and different SSDs. First of all I still see the issue with your v3 on top of v6.18-rc3, which includes some fixes for ASPM support [1].

I have tried 3 different SSDs, none of them are working, but the symptoms are different, although all related with ASPM (pcie_aspm=off workarounds the issue).

With a Fox Spirit PM18 SSD (Silicon Motion, Inc. SM2263EN/SM2263XT controller), I do not have more than this:

[    5.196723] nvme nvme0: pci function 0000:01:00.0
[    5.198843] nvme 0000:01:00.0: enabling device (0000 -> 0002)

With a WD Blue SN570 SSD, I get this:

[    5.199513] nvme nvme0: pci function 0000:01:00.0
[    5.201653] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[    5.270334] nvme nvme0: allocated 32 MiB host memory buffer (8 segments).
[    5.277624] nvme nvme0: 8/0/0 default/read/poll queues
[   19.192350] nvme nvme0: using unchecked data buffer
[   48.108400] nvme nvme0: controller is down; will reset: CSTS=0xffffffff, PCI_STATUS=0x10
[   48.113885] nvme nvme0: Does your device have a faulty power saving mode enabled?
[   48.121346] nvme nvme0: Try "nvme_core.default_ps_max_latency_us=0 pcie_aspm=off pcie_port_pm=off" and report a bug
[   48.176878] nvme0n1: I/O Cmd(0x2) @ LBA 0, 8 blocks, I/O Error (sct 0x3 / sc 0x71)
[   48.181926] I/O error, dev nvme0n1, sector 0 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 2
[   48.243670] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[   48.246914] nvme nvme0: Disabling device after reset failure: -19
[   48.280495] Buffer I/O error on dev nvme0n1, logical block 0, async page read

Finally with a PNY CS1030 SSD (Phison PS5015-E15 controller), I get this:

[    5.215631] nvme nvme0: pci function 0000:01:00.0
[    5.220435] nvme 0000:01:00.0: enabling device (0000 -> 0002)
[    5.329565] nvme nvme0: allocated 64 MiB host memory buffer (16 segments).
[   66.540485] nvme nvme0: I/O tag 28 (401c) QID 0 timeout, disable controller
[   66.585245] nvme 0000:01:00.0: probe with driver nvme failed with error -4
Quoted 3 lines

Note that I also tested this latest SSD on a VisionFive 2 board with exactly the same kernel (I just moved the SSD and booted), and it works fine with ASPM enabled (confirmed with lspci).

Quoted 7 lines

I have been testing this patchset recently as well, but on an Orange Pi RV2 board instead (and an extra RV2 specific patch to enable power to the M.2 slot).

I ran into the same symptoms you had ("QID 0 timeout" after about 60 seconds). However, I'm using an Intel 600p. I can confirm my NVME drive seems to work fine with the "pcie_aspm=off" workaround as well.

I don't see this problem, and haven't tried to reproduce it yet.

Mani told me I needed to add these lines to ensure the "runtime PM hierarchy of PCIe chain" won't be "broken":

pm_runtime_set_active()
pm_runtime_no_callbacks()
devm_pm_runtime_enable()

Just out of curiosity, could you try with those lines added just before these assignments in k1_pcie_probe()?

Quoted 7 lines
	k1->pci.dev = dev;
	k1->pci.ops = &k1_pcie_ops;
	dw_pcie_cap_set(&k1->pci, REQ_RES);

I doubt it will fix what you're seeing, but at the moment I'm working on something else.

Thanks for your fast answer. I have just tried this patch:

drivers/pci/controller/dwc/pcie-spacemit-k1.c +10 -0
@@ -271,6 +271,16 @@ static int k1_pcie_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, PTR_ERR(k1->phy),
 				     "failed to get PHY\n");
 
+	ret = pm_runtime_set_active(dev);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to activate runtime PM\n");
+
+	pm_runtime_no_callbacks(dev);
+
+	ret = devm_pm_runtime_enable(dev);
+	if (ret < 0)
+		return dev_err_probe(dev, ret, "Failed to enable runtime PM\n");
+
 	k1->pci.dev = dev;
 	k1->pci.ops = &k1_pcie_ops;
 	dw_pcie_cap_set(&k1->pci, REQ_RES);

Unfortunately this doesn't fix the issue. On the positive side, things still work with it and pcie_aspm=off.

Regards
AUrelien

Signature · 2 lines
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
[email protected]                     http://aurel32.net