Skip to contentSkip to conversation

Add support for PCIe endpoint mode in Tegra194

PATCH Superseded Vidya Sagar 5 participants 23 messages Nov 22, 2019 – Dec 5, 2019

Subsystems (5)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Add support for PCIe endpoint mode in Tegra194

Tegra194 has three (C0, C4 & C5) dual mode PCIe controllers that can operate either in root port mode or in end point mode but only in one mode at a time. Platform P2972-0000 supports enabling endpoint mode for C5 controller. This patch series adds support for PCIe endpoint mode in both the driver as well as in DT.
This patch series depends on the changes made for Synopsys DesignWare endpoint mode subsystem that are currently under review
@ https://patchwork.kernel.org/project/linux-pci/list/?series=202211
which in turn depends on the patch made by Kishon
@ https://patchwork.kernel.org/patch/10975123/
which is also under review.

Vidya Sagar (6):
soc/tegra: bpmp: Update ABI header
dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194
PCI: tegra: Add support for PCIe endpoint mode in Tegra194
arm64: tegra: Add PCIe endpoint controllers nodes for Tegra194
arm64: tegra: Enable GPIO controllers nodes for P2972-0000 platform
arm64: tegra: Add support for PCIe endpoint mode in P2972-0000
platform

 .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++
 .../boot/dts/nvidia/tegra194-p2972-0000.dts   |  37 +
 arch/arm64/boot/dts/nvidia/tegra194.dtsi      |  99 +++
 drivers/pci/controller/dwc/Kconfig            |  30 +-
 drivers/pci/controller/dwc/pcie-tegra194.c    | 751 +++++++++++++++++-
 include/soc/tegra/bpmp-abi.h                  |  10 +-
 6 files changed, 1048 insertions(+), 17 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/6 soc/tegra: bpmp: Update ABI header

Update the firmware header to support uninitialization of UPHY PLL when the PCIe controller is operating in endpoint mode and host cuts the PCIe reference clock.

---
 include/soc/tegra/bpmp-abi.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
include/soc/tegra/bpmp-abi.h +9 -1
index cac6f610b3fe..322d06e21918 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (c) 2014-2018, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2014-2019, NVIDIA CORPORATION.  All rights reserved.
  */
 
 #ifndef _ABI_BPMP_ABI_H_
@@ -2119,6 +2119,7 @@ enum {
 	CMD_UPHY_PCIE_LANE_MARGIN_STATUS = 2,
 	CMD_UPHY_PCIE_EP_CONTROLLER_PLL_INIT = 3,
 	CMD_UPHY_PCIE_CONTROLLER_STATE = 4,
+	CMD_UPHY_PCIE_EP_CONTROLLER_PLL_OFF = 5,
 	CMD_UPHY_MAX,
 };
 
@@ -2151,6 +2152,11 @@ struct cmd_uphy_pcie_controller_state_request {
 	uint8_t enable;
 } __ABI_PACKED;
 
+struct cmd_uphy_ep_controller_pll_off_request {
+	/** @brief EP controller number, valid: 0, 4, 5 */
+	uint8_t ep_controller;
+} __ABI_PACKED;
+
 /**
  * @ingroup UPHY
  * @brief Request with #MRQ_UPHY
@@ -2165,6 +2171,7 @@ struct cmd_uphy_pcie_controller_state_request {
  * |CMD_UPHY_PCIE_LANE_MARGIN_STATUS     |                                        |
  * |CMD_UPHY_PCIE_EP_CONTROLLER_PLL_INIT |cmd_uphy_ep_controller_pll_init_request |
  * |CMD_UPHY_PCIE_CONTROLLER_STATE       |cmd_uphy_pcie_controller_state_request  |
+ * |CMD_UPHY_PCIE_EP_CONTROLLER_PLL_OFF  |cmd_uphy_ep_controller_pll_off_request  |
  *
  */
 
@@ -2178,6 +2185,7 @@ struct mrq_uphy_request {
 		struct cmd_uphy_margin_control_request uphy_set_margin_control;
 		struct cmd_uphy_ep_controller_pll_init_request ep_ctrlr_pll_init;
 		struct cmd_uphy_pcie_controller_state_request controller_state;
+		struct cmd_uphy_ep_controller_pll_off_request ep_ctrlr_pll_off;
 	} __UNION_ANON;
 } __ABI_PACKED;
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/6 dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194

In reply to Vidya Sagar

Add support for PCIe controllers that can operate in endpoint mode in Tegra194.

---
 .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++++++++++++++++
 1 file changed, 138 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +138 -0
new file mode 100644
index 000000000000..4676ccf7dfa5
@@ -0,0 +1,138 @@
+NVIDIA Tegra PCIe Endpoint mode controller (Synopsys DesignWare Core based)
+
+Some of the PCIe controllers which are based on Synopsys DesignWare PCIe IP
+are dual mode i.e. they can work in root port mode or endpoint mode but one
+ at a time. Since they are based on DesignWare IP, they inherit all the common
+properties defined in designware-pcie.txt.
+
+Required properties:
+- compatible: For Tegra19x, must contain "nvidia,tegra194-pcie".
+  Tegra194: Only C0, C4 & C5 controllers are dual mode controllers.
+- power-domains: A phandle to the node that controls power to the respective
+  PCIe controller and a specifier name for the PCIe controller. Following are
+  the specifiers for the different PCIe controllers
+    TEGRA194_POWER_DOMAIN_PCIEX8B: C0
+    TEGRA194_POWER_DOMAIN_PCIEX4A: C4
+    TEGRA194_POWER_DOMAIN_PCIEX8A: C5
+  these specifiers are defined in
+  "include/dt-bindings/power/tegra194-powergate.h" file.
+- reg: A list of physical base address and length pairs for each set of
+  controller registers. Must contain an entry for each entry in the reg-names
+  property.
+- reg-names: Must include the following entries:
+  "appl": Controller's application logic registers
+  "atu_dma": iATU and DMA registers. This is where the iATU (internal Address
+             Translation Unit) registers of the PCIe core are made available
+             for SW access.
+  "dbi": The aperture where root port's own configuration registers are
+         available
+  "addr_space": Used to map remote RC address space
+- interrupts: A list of interrupt outputs of the controller. Must contain an
+  entry for each entry in the interrupt-names property.
+- interrupt-names: Must include the following entry:
+  "intr": The Tegra interrupt that is asserted for controller interrupts
+- clocks: Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names: Must include the following entries:
+  - core
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: Must include the following entries:
+  - apb
+  - core
+- phys: Must contain a phandle to P2U PHY for each entry in phy-names.
+- phy-names: Must include an entry for each active lane.
+  "p2u-N": where N ranges from 0 to one less than the total number of lanes
+- nvidia,bpmp: Must contain a pair of phandle to BPMP controller node followed
+  by controller-id. Following are the controller ids for each controller.
+    0: C0
+    4: C4
+    5: C5
+- vddio-pex-ctl-supply: Regulator supply for PCIe side band signals
+- nvidia,pex-rst-gpio: Must contain a phandle to a GPIO controller followed by
+  GPIO that is being used as PERST signal
+
+Optional properties:
+- pinctrl-names: A list of pinctrl state names.
+  It is mandatory for C5 controller and optional for other controllers.
+  - "default": Configures PCIe I/O for proper operation.
+- pinctrl-0: phandle for the 'default' state of pin configuration.
+  It is mandatory for C5 controller and optional for other controllers.
+- supports-clkreq: Refer to Documentation/devicetree/bindings/pci/pci.txt
+- nvidia,update-fc-fixup: This is a boolean property and needs to be present to
+    improve performance when a platform is designed in such a way that it
+    satisfies at least one of the following conditions thereby enabling root
+    port to exchange optimum number of FC (Flow Control) credits with
+    downstream devices
+    1. If C0/C4/C5 run at x1/x2 link widths (irrespective of speed and MPS)
+    2. If C0/C4/C5 operate at their respective max link widths and
+       a) speed is Gen-2 and MPS is 256B
+       b) speed is >= Gen-3 with any MPS
+- nvidia,aspm-cmrt-us: Common Mode Restore Time for proper operation of ASPM
+   to be specified in microseconds
+- nvidia,aspm-pwr-on-t-us: Power On time for proper operation of ASPM to be
+   specified in microseconds
+- nvidia,aspm-l0s-entrance-latency-us: ASPM L0s entrance latency to be
+   specified in microseconds
+
+NOTE:- On Tegra194's P2972-0000 platform, only C5 controller can be enabled to
+operate in the endpoint mode because of the way the platform is designed.
+There is a mux that needs to be programmed to let the REFCLK from the host to
+flow into C5 controller when it operates in the endpoint mode. This mux is
+controlled by the GPIO (AA, 5) and it needs to be driven 'high'. For this to
+happen, set status of "pex-refclk-sel-high" node under "gpio@c2f0000" node to
+'okay'.
+	When any dual mode controller is made to operate in the endpoint mode,
+please make sure that its respective root port node's status is set to
+'disabled'.
+
+Examples:
+=========
+
+Tegra194:
+--------
+
+	pcie_ep@141a0000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>;
+		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		num-lanes = <8>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&clkreq_c5_bi_dir_state>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX1_CORE_5>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX1_CORE_5_APB>,
+			 <&bpmp TEGRA194_RESET_PEX1_CORE_5>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 5>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
Signature · 1 line
2.17.1
#10 lore raw

PATCH 3/6 PCI: tegra: Add support for PCIe endpoint mode in Tegra194

In reply to Vidya Sagar

Add support for the endpoint mode of Synopsys DesignWare core based dual mode PCIe controllers present in Tegra194 SoC.

---
 drivers/pci/controller/dwc/Kconfig         |  30 +-
 drivers/pci/controller/dwc/pcie-tegra194.c | 751 ++++++++++++++++++++-
 2 files changed, 765 insertions(+), 16 deletions(-)
drivers/pci/controller/dwc/Kconfig +27 -3
index 0ba988b5b5bc..32165a77c94c 100644
@@ -237,14 +237,38 @@ config PCI_MESON
 	  implement the driver.
 
 config PCIE_TEGRA194
-	tristate "NVIDIA Tegra194 (and later) PCIe controller"
+	tristate
+
+config PCIE_TEGRA194_HOST
+	tristate "NVIDIA Tegra194 (and later) PCIe controller - Host Mode"
 	depends on ARCH_TEGRA_194_SOC || COMPILE_TEST
 	depends on PCI_MSI_IRQ_DOMAIN
 	select PCIE_DW_HOST
 	select PHY_TEGRA194_P2U
+	select PCIE_TEGRA194
+	default y
+	help
+	  Enables support for the PCIe controller in the NVIDIA Tegra194 SoC to
+	  work in host mode. There are two instances of PCIe controllers in
+	  Tegra194. This controller can work either as EP or RC. In order to
+	  enable host-specific features PCIE_TEGRA194_HOST must be selected and
+	  in order to enable device-specific features PCIE_TEGRA194_EP must be
+	  selected. This uses the DesignWare core.
+
+config PCIE_TEGRA194_EP
+	tristate "NVIDIA Tegra194 (and later) PCIe controller - Endpoint Mode"
+	depends on ARCH_TEGRA_194_SOC || COMPILE_TEST
+	depends on PCI_ENDPOINT
+	select PCIE_DW_EP
+	select PHY_TEGRA194_P2U
+	select PCIE_TEGRA194
 	help
-	  Say Y here if you want support for DesignWare core based PCIe host
-	  controller found in NVIDIA Tegra194 SoC.
+	  Enables support for the PCIe controller in the NVIDIA Tegra194 SoC to
+	  work in host mode. There are two instances of PCIe controllers in
+	  Tegra194. This controller can work either as EP or RC. In order to
+	  enable host-specific features PCIE_TEGRA194_HOST must be selected and
+	  in order to enable device-specific features PCIE_TEGRA194_EP must be
+	  selected. This uses the DesignWare core.
 
 config PCIE_UNIPHIER
 	bool "Socionext UniPhier PCIe controllers"
drivers/pci/controller/dwc/pcie-tegra194.c +738 -13

882 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

PATCH 4/6 arm64: tegra: Add PCIe endpoint controllers nodes for Tegra194

In reply to Vidya Sagar

Add endpoint mode controllers nodes for the dual mode PCIe controllers present in Tegra194 SoC.

---
 arch/arm64/boot/dts/nvidia/tegra194.dtsi | 99 ++++++++++++++++++++++++
 1 file changed, 99 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194.dtsi +99 -0
index 11220d97adb8..2c8fae854a23 100644
@@ -1425,6 +1425,105 @@
 			  0x82000000 0x0  0x40000000 0x1f 0x40000000 0x0 0xc0000000>; /* non-prefetchable memory (3GB) */
 	};
 
+	pcie_ep@14160000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX4A>;
+		reg = <0x00 0x14160000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x36040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x36080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x14 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		status = "disabled";
+
+		num-lanes = <4>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX0_CORE_4>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX0_CORE_4_APB>,
+			 <&bpmp TEGRA194_RESET_PEX0_CORE_4>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 51 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 4>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+	};
+
+	pcie_ep@14180000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8B>;
+		reg = <0x00 0x14180000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x38040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x38080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x18 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		status = "disabled";
+
+		num-lanes = <8>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX0_CORE_0>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX0_CORE_0_APB>,
+			 <&bpmp TEGRA194_RESET_PEX0_CORE_0>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 0>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+	};
+
+	pcie_ep@141a0000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>;
+		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		status = "disabled";
+
+		num-lanes = <8>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&clkreq_c5_bi_dir_state>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX1_CORE_5>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX1_CORE_5_APB>,
+			 <&bpmp TEGRA194_RESET_PEX1_CORE_5>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 5>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+	};
+
 	sysram@40000000 {
 		compatible = "nvidia,tegra194-sysram", "mmio-sram";
 		reg = <0x0 0x40000000 0x0 0x50000>;
Signature · 1 line
2.17.1
#14 lore raw

PATCH 5/6 arm64: tegra: Enable GPIO controllers nodes for P2972-0000 platform

In reply to Vidya Sagar

Enable GPIO controllers nodes for P2972-0000 platform which are required by other controllers in the SoC for example when PCIe C5 controller operates in endpoint mode.

---
 arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +8 -0
index 353a6a22196d..7eb64b816e08 100644
@@ -37,6 +37,14 @@
 			status = "okay";
 		};
 
+		gpio@2200000 {
+			status = "okay";
+		};
+
+		gpio@c2f0000 {
+			status = "okay";
+		};
+
 		pwm@c340000 {
 			status = "okay";
 		};
Signature · 1 line
2.17.1
#17 lore raw

PATCH 6/6 arm64: tegra: Add support for PCIe endpoint mode in P2972-0000 platform

In reply to Vidya Sagar

Add endpoint mode support for PCIe C5 controller in P2972-0000 platform with information about supplies, PHY, PERST GPIO and GPIO that controls PCIe reference clock coming from the host system.

---
 .../boot/dts/nvidia/tegra194-p2972-0000.dts   | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +29 -0
index 7eb64b816e08..58c3a9677bc8 100644
@@ -43,6 +43,19 @@
 
 		gpio@c2f0000 {
 			status = "okay";
+			/*
+			 * Change the below node's status to 'okay' when
+			 * PCIe C5 controller is enabled to operate in endpoint
+			 * to allow REFCLK from the host system to flow into
+			 * the controller.
+			 */
+			pex-refclk-sel-high {
+				gpio-hog;
+				output-high;
+				gpios = <TEGRA194_AON_GPIO(AA, 5) 0>;
+				label = "pex_refclk_sel_high";
+				status = "disabled";
+			};
 		};
 
 		pwm@c340000 {
@@ -144,6 +157,22 @@
 			    "p2u-5", "p2u-6", "p2u-7";
 	};
 
+	pcie_ep@141a0000 {
+		status = "disabled";
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
+
 	fan: fan {
 		compatible = "pwm-fan";
 		pwms = <&pwm4 0 45334>;
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 2/6] dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194

In reply to Vidya Sagar
Quoted 8 lines · Vidya Sagar

Add support for PCIe controllers that can operate in endpoint mode in Tegra194.

---
 .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++++++++++++++++
 1 file changed, 138 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt

The vast majority of this is a duplication of the host mode device tree bindings. I think it'd be best to combine both and only highlight where both modes differ.

The designware-pcie.txt binding does something similar.

Quoted 6 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +0 -0
new file mode 100644
index 000000000000..4676ccf7dfa5

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +9 -0
@@ -0,0 +1,138 @@
+NVIDIA Tegra PCIe Endpoint mode controller (Synopsys DesignWare Core based)
+
+Some of the PCIe controllers which are based on Synopsys DesignWare PCIe IP
+are dual mode i.e. they can work in root port mode or endpoint mode but one
+ at a time. Since they are based on DesignWare IP, they inherit all the common
+properties defined in designware-pcie.txt.
+
+Required properties:
+- compatible: For Tegra19x, must contain "nvidia,tegra194-pcie".

The device tree snippets that you added have "nvidia,tegra194-pcie-ep" for EP mode controllers. So either this is wrong or the DTS files are wrong.

This device tree binding describes the exact same hardware, so I don't think we necessarily need two different compatible strings. It's fairly easy to distinguish between which mode to run in by looking at which properties exist. EP mode for example is the only one that uses the "addr_space" reg entry.

Rob, do you know why a different compatible string was chosen for the EP mode? Looking at the driver, there are only a handful of differences in the programming, but most of the driver remains identical. An extra DT compatible string seems a bit exaggerated since it suggests that this is actually different hardware, where it clearly isn't.

Quoted 34 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +34 -0
+  Tegra194: Only C0, C4 & C5 controllers are dual mode controllers.
+- power-domains: A phandle to the node that controls power to the respective
+  PCIe controller and a specifier name for the PCIe controller. Following are
+  the specifiers for the different PCIe controllers
+    TEGRA194_POWER_DOMAIN_PCIEX8B: C0
+    TEGRA194_POWER_DOMAIN_PCIEX4A: C4
+    TEGRA194_POWER_DOMAIN_PCIEX8A: C5
+  these specifiers are defined in
+  "include/dt-bindings/power/tegra194-powergate.h" file.
+- reg: A list of physical base address and length pairs for each set of
+  controller registers. Must contain an entry for each entry in the reg-names
+  property.
+- reg-names: Must include the following entries:
+  "appl": Controller's application logic registers
+  "atu_dma": iATU and DMA registers. This is where the iATU (internal Address
+             Translation Unit) registers of the PCIe core are made available
+             for SW access.
+  "dbi": The aperture where root port's own configuration registers are
+         available
+  "addr_space": Used to map remote RC address space
+- interrupts: A list of interrupt outputs of the controller. Must contain an
+  entry for each entry in the interrupt-names property.
+- interrupt-names: Must include the following entry:
+  "intr": The Tegra interrupt that is asserted for controller interrupts
+- clocks: Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names: Must include the following entries:
+  - core
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: Must include the following entries:
+  - apb
+  - core
+- phys: Must contain a phandle to P2U PHY for each entry in phy-names.

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 53

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+- phy-names: Must include an entry for each active lane.
+  "p2u-N": where N ranges from 0 to one less than the total number of lanes
+- nvidia,bpmp: Must contain a pair of phandle to BPMP controller node followed
+  by controller-id. Following are the controller ids for each controller.
+    0: C0
+    4: C4
+    5: C5
+- vddio-pex-ctl-supply: Regulator supply for PCIe side band signals
+- nvidia,pex-rst-gpio: Must contain a phandle to a GPIO controller followed by
+  GPIO that is being used as PERST signal

Why is this NVIDIA specific? Do other instantiations of the DW IP not also need a means to define which GPIO is the reset?

Quoted 24 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +24 -0
+
+Optional properties:
+- pinctrl-names: A list of pinctrl state names.
+  It is mandatory for C5 controller and optional for other controllers.
+  - "default": Configures PCIe I/O for proper operation.
+- pinctrl-0: phandle for the 'default' state of pin configuration.
+  It is mandatory for C5 controller and optional for other controllers.
+- supports-clkreq: Refer to Documentation/devicetree/bindings/pci/pci.txt
+- nvidia,update-fc-fixup: This is a boolean property and needs to be present to
+    improve performance when a platform is designed in such a way that it
+    satisfies at least one of the following conditions thereby enabling root
+    port to exchange optimum number of FC (Flow Control) credits with
+    downstream devices
+    1. If C0/C4/C5 run at x1/x2 link widths (irrespective of speed and MPS)
+    2. If C0/C4/C5 operate at their respective max link widths and
+       a) speed is Gen-2 and MPS is 256B
+       b) speed is >= Gen-3 with any MPS
+- nvidia,aspm-cmrt-us: Common Mode Restore Time for proper operation of ASPM
+   to be specified in microseconds
+- nvidia,aspm-pwr-on-t-us: Power On time for proper operation of ASPM to be
+   specified in microseconds
+- nvidia,aspm-l0s-entrance-latency-us: ASPM L0s entrance latency to be
+   specified in microseconds
+

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+NOTE:- On Tegra194's P2972-0000 platform, only C5 controller can be enabled to
+operate in the endpoint mode because of the way the platform is designed.
+There is a mux that needs to be programmed to let the REFCLK from the host to
+flow into C5 controller when it operates in the endpoint mode. This mux is
+controlled by the GPIO (AA, 5) and it needs to be driven 'high'. For this to
+happen, set status of "pex-refclk-sel-high" node under "gpio@c2f0000" node to
+'okay'.
+	When any dual mode controller is made to operate in the endpoint mode,
+please make sure that its respective root port node's status is set to
+'disabled'.

This seems very brittle to me. There's no good way how we can detect such misconfigurations. If instead we only have one node describing the hardware fully, the chances of configuring things wrong (by for example enabling both the host and EP mode device tree nodes) can be reduced.

So I think instead of duplicating all of the device tree content to have both a host and an EP node for each controller, it'd be better to just have a single node and let the device tree bindings specify which changes to apply to switch into EP mode.

For example, there should be nothing wrong with specifying some of the EP-only properties (like num-ib-windows and num-ob-windows) all the time and only use them when we actually run in EP mode.

As I mentioned earlier, there are a couple of easy ways to distinguish the modes. The presence of the "addr_space" reg entry is one example, but we could also key off the nvidia,pex-rst-gpio property, since that (presumably) wouldn't be needed for host mode.

That way we can just add default, host mode entries to tegra194.dtsi and whenever somebody wants to enable EP mode, they can just override the node in the board-level DTS file, like so:

	pcie@141a0000 {
		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
		reg-names = "appl", "atu_dma", "dbi", "addr_space";

		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1) GPIO_ACTIVE_LOW>;
	};

Thierry

Quoted 54 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +51 -0
+
+Examples:
+=========
+
+Tegra194:
+--------
+
+	pcie_ep@141a0000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>;
+		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		num-lanes = <8>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&clkreq_c5_bi_dir_state>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX1_CORE_5>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX1_CORE_5_APB>,
+			 <&bpmp TEGRA194_RESET_PEX1_CORE_5>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 5>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
Signature · 1 line
2.17.1
#15 lore raw

Re: [PATCH 5/6] arm64: tegra: Enable GPIO controllers nodes for P2972-0000 platform

In reply to Vidya Sagar
Quoted 8 lines · Vidya Sagar

Enable GPIO controllers nodes for P2972-0000 platform which are required by other controllers in the SoC for example when PCIe C5 controller operates in endpoint mode.

---
 arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts | 8 ++++++++
 1 file changed, 8 insertions(+)

The GPIO controllers are enabled by default, so there's no need to explicitly enable them.

Thierry

Quoted 23 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +8 -0
index 353a6a22196d..7eb64b816e08 100644
@@ -37,6 +37,14 @@
 			status = "okay";
 		};
 
+		gpio@2200000 {
+			status = "okay";
+		};
+
+		gpio@c2f0000 {
+			status = "okay";
+		};
+
 		pwm@c340000 {
 			status = "okay";
 		};
Signature · 1 line
2.17.1
#18 lore raw

Re: [PATCH 6/6] arm64: tegra: Add support for PCIe endpoint mode in P2972-0000 platform

In reply to Vidya Sagar
Quoted 20 lines · Vidya Sagar

Add endpoint mode support for PCIe C5 controller in P2972-0000 platform with information about supplies, PHY, PERST GPIO and GPIO that controls PCIe reference clock coming from the host system.

---
 .../boot/dts/nvidia/tegra194-p2972-0000.dts   | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +3 -0
index 7eb64b816e08..58c3a9677bc8 100644
@@ -43,6 +43,19 @@
 
 		gpio@c2f0000 {
 			status = "okay";
+			/*
+			 * Change the below node's status to 'okay' when
+			 * PCIe C5 controller is enabled to operate in endpoint

arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts line 58

Quoted 10 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +10 -0
+			 * to allow REFCLK from the host system to flow into
+			 * the controller.
+			 */
+			pex-refclk-sel-high {
+				gpio-hog;
+				output-high;
+				gpios = <TEGRA194_AON_GPIO(AA, 5) 0>;
+				label = "pex_refclk_sel_high";
+				status = "disabled";
+			};

Why don't we put this into the PCIe controller's node as a reference to that GPIO? Seems like the controller would know exactly when this pin needs to go high or low, so why does it have to be a hog?

Thierry

Quoted 29 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +16 -0
 		};
 
 		pwm@c340000 {
@@ -144,6 +157,22 @@
 			    "p2u-5", "p2u-6", "p2u-7";
 	};
 
+	pcie_ep@141a0000 {
+		status = "disabled";
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
+
 	fan: fan {
 		compatible = "pwm-fan";
 		pwms = <&pwm4 0 45334>;
Signature · 1 line
2.17.1
#16 lore raw

Re: [PATCH 5/6] arm64: tegra: Enable GPIO controllers nodes for P2972-0000 platform

In reply to Thierry Reding
Quoted 5 lines · Thierry Reding
Quoted 4 lines · Vidya Sagar

Enable GPIO controllers nodes for P2972-0000 platform which are required by other controllers in the SoC for example when PCIe C5 controller operates in endpoint mode.

Quoted 7 lines
Quoted 4 lines
---
  arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts | 8 ++++++++
  1 file changed, 8 insertions(+)

The GPIO controllers are enabled by default, so there's no need to explicitly enable them.

Yup. I'll remove this patch.
Since I didn't see 'status' entry in GPIO nodes in tegra194.dtsi file, I thought it means 'disabled'. But, contrary to my understanding, absence of 'status' entry seems to mean 'okay'.

- Vidya Sagar

Quoted 26 lines

Thierry

Quoted 23 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +8 -0
index 353a6a22196d..7eb64b816e08 100644
@@ -37,6 +37,14 @@
  			status = "okay";
  		};
 
+		gpio@2200000 {
+			status = "okay";
+		};
+
+		gpio@c2f0000 {
+			status = "okay";
+		};
+
  		pwm@c340000 {
  			status = "okay";
  		};
Signature · 1 line
2.17.1
#19 lore raw

Re: [PATCH 6/6] arm64: tegra: Add support for PCIe endpoint mode in P2972-0000 platform

In reply to Thierry Reding
Quoted 36 lines · Thierry Reding
Quoted 20 lines · Vidya Sagar

Add endpoint mode support for PCIe C5 controller in P2972-0000 platform with information about supplies, PHY, PERST GPIO and GPIO that controls PCIe reference clock coming from the host system.

---
  .../boot/dts/nvidia/tegra194-p2972-0000.dts   | 29 +++++++++++++++++++
  1 file changed, 29 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +3 -0
index 7eb64b816e08..58c3a9677bc8 100644
@@ -43,6 +43,19 @@
 
  		gpio@c2f0000 {
  			status = "okay";
+			/*
+			 * Change the below node's status to 'okay' when
+			 * PCIe C5 controller is enabled to operate in endpoint

arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts line 58

Quoted 10 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +10 -0
+			 * to allow REFCLK from the host system to flow into
+			 * the controller.
+			 */
+			pex-refclk-sel-high {
+				gpio-hog;
+				output-high;
+				gpios = <TEGRA194_AON_GPIO(AA, 5) 0>;
+				label = "pex_refclk_sel_high";
+				status = "disabled";
+			};

Why don't we put this into the PCIe controller's node as a reference to that GPIO? Seems like the controller would know exactly when this pin needs to go high or low, so why does it have to be a hog?

Quoted 1 line

Thierry

Are you saying something like 'nvidia,enable-refclk-in'?
I was thinking, since this is like a board level configuration specific to Jetson-Xavier, it would suffice to just hog it according to the mode of operation of PCIe controller. But, I see one advantage of referencing it in the PCIe node (so that the driver can configure it as and when needed) is that one has to be careful just to enable either PCIe RP or EP node and not worry about other thing (like this).
Let me know if I got this right.

- Vidya Sagar

Quoted 30 lines
Quoted 30 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +16 -0
  		};
 
  		pwm@c340000 {
@@ -144,6 +157,22 @@
  			    "p2u-5", "p2u-6", "p2u-7";
  	};
 
+	pcie_ep@141a0000 {
+		status = "disabled";
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
+
  	fan: fan {
  		compatible = "pwm-fan";
  		pwms = <&pwm4 0 45334>;
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH 2/6] dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194

In reply to Thierry Reding
Quoted 10 lines · Thierry Reding
Quoted 8 lines · Vidya Sagar

Add support for PCIe controllers that can operate in endpoint mode in Tegra194.

---
  .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++++++++++++++++
  1 file changed, 138 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt

Quoted 5 lines

The vast majority of this is a duplication of the host mode device tree bindings. I think it'd be best to combine both and only highlight where both modes differ.

The designware-pcie.txt binding does something similar.

Ok. I'll merge this into the host mode bindings file and in that differentiate between root mode and endpoint mode.

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +5 -0
new file mode 100644
index 000000000000..4676ccf7dfa5
@@ -0,0 +1,138 @@
+NVIDIA Tegra PCIe Endpoint mode controller (Synopsys DesignWare Core based)
+
+Some of the PCIe controllers which are based on Synopsys DesignWare PCIe IP
+are dual mode i.e. they can work in root port mode or endpoint mode but one
+ at a time. Since they are based on DesignWare IP, they inherit all the common
Quoted 8 lines

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 9

Quoted 4 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +4 -0
+properties defined in designware-pcie.txt.
+
+Required properties:
+- compatible: For Tegra19x, must contain "nvidia,tegra194-pcie".

The device tree snippets that you added have "nvidia,tegra194-pcie-ep" for EP mode controllers. So either this is wrong or the DTS files are wrong.

DTS file are correct. This is a mistake in this file. I'll correct this.

Quoted 7 lines

This device tree binding describes the exact same hardware, so I don't think we necessarily need two different compatible strings. It's fairly easy to distinguish between which mode to run in by looking at which properties exist. EP mode for example is the only one that uses the "addr_space" reg entry.

Quoted 5 lines

Rob, do you know why a different compatible string was chosen for the EP mode? Looking at the driver, there are only a handful of differences in the programming, but most of the driver remains identical. An extra DT compatible string seems a bit exaggerated since it suggests that this is actually different hardware, where it clearly isn't.

Since all other implementations have done it this way, I just followed to be in sync with them. Even I would also like to hear from Rob on the rationale behind this.

Quoted 46 lines
Quoted 35 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +34 -0
+  Tegra194: Only C0, C4 & C5 controllers are dual mode controllers.
+- power-domains: A phandle to the node that controls power to the respective
+  PCIe controller and a specifier name for the PCIe controller. Following are
+  the specifiers for the different PCIe controllers
+    TEGRA194_POWER_DOMAIN_PCIEX8B: C0
+    TEGRA194_POWER_DOMAIN_PCIEX4A: C4
+    TEGRA194_POWER_DOMAIN_PCIEX8A: C5
+  these specifiers are defined in
+  "include/dt-bindings/power/tegra194-powergate.h" file.
+- reg: A list of physical base address and length pairs for each set of
+  controller registers. Must contain an entry for each entry in the reg-names
+  property.
+- reg-names: Must include the following entries:
+  "appl": Controller's application logic registers
+  "atu_dma": iATU and DMA registers. This is where the iATU (internal Address
+             Translation Unit) registers of the PCIe core are made available
+             for SW access.
+  "dbi": The aperture where root port's own configuration registers are
+         available
+  "addr_space": Used to map remote RC address space
+- interrupts: A list of interrupt outputs of the controller. Must contain an
+  entry for each entry in the interrupt-names property.
+- interrupt-names: Must include the following entry:
+  "intr": The Tegra interrupt that is asserted for controller interrupts
+- clocks: Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names: Must include the following entries:
+  - core
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: Must include the following entries:
+  - apb
+  - core
+- phys: Must contain a phandle to P2U PHY for each entry in phy-names.

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 53

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+- phy-names: Must include an entry for each active lane.
+  "p2u-N": where N ranges from 0 to one less than the total number of lanes
+- nvidia,bpmp: Must contain a pair of phandle to BPMP controller node followed
+  by controller-id. Following are the controller ids for each controller.
+    0: C0
+    4: C4
+    5: C5
+- vddio-pex-ctl-supply: Regulator supply for PCIe side band signals
+- nvidia,pex-rst-gpio: Must contain a phandle to a GPIO controller followed by
+  GPIO that is being used as PERST signal
Quoted 2 lines

Why is this NVIDIA specific? Do other instantiations of the DW IP not also need a means to define which GPIO is the reset?

I'm not sure. At least I didn't find anything like this in other implementations. My understanding is that, controller handles assert/de-assert on the PERST line automatically without SW intervention. I think it is for the same reason that other implementations don't wait for the REFCLK to flow in from host to configure the IP. I think they just use some internal clock for the configuration and switch to running the core based on REFCLK as and when it is available
(i.e. whenever a de-assert is perceived on PERST line by the controller)

Quoted 69 lines
Quoted 25 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +24 -0
+
+Optional properties:
+- pinctrl-names: A list of pinctrl state names.
+  It is mandatory for C5 controller and optional for other controllers.
+  - "default": Configures PCIe I/O for proper operation.
+- pinctrl-0: phandle for the 'default' state of pin configuration.
+  It is mandatory for C5 controller and optional for other controllers.
+- supports-clkreq: Refer to Documentation/devicetree/bindings/pci/pci.txt
+- nvidia,update-fc-fixup: This is a boolean property and needs to be present to
+    improve performance when a platform is designed in such a way that it
+    satisfies at least one of the following conditions thereby enabling root
+    port to exchange optimum number of FC (Flow Control) credits with
+    downstream devices
+    1. If C0/C4/C5 run at x1/x2 link widths (irrespective of speed and MPS)
+    2. If C0/C4/C5 operate at their respective max link widths and
+       a) speed is Gen-2 and MPS is 256B
+       b) speed is >= Gen-3 with any MPS
+- nvidia,aspm-cmrt-us: Common Mode Restore Time for proper operation of ASPM
+   to be specified in microseconds
+- nvidia,aspm-pwr-on-t-us: Power On time for proper operation of ASPM to be
+   specified in microseconds
+- nvidia,aspm-l0s-entrance-latency-us: ASPM L0s entrance latency to be
+   specified in microseconds
+

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+NOTE:- On Tegra194's P2972-0000 platform, only C5 controller can be enabled to
+operate in the endpoint mode because of the way the platform is designed.
+There is a mux that needs to be programmed to let the REFCLK from the host to
+flow into C5 controller when it operates in the endpoint mode. This mux is
+controlled by the GPIO (AA, 5) and it needs to be driven 'high'. For this to
+happen, set status of "pex-refclk-sel-high" node under "gpio@c2f0000" node to
+'okay'.
+	When any dual mode controller is made to operate in the endpoint mode,
+please make sure that its respective root port node's status is set to
+'disabled'.

This seems very brittle to me. There's no good way how we can detect such misconfigurations. If instead we only have one node describing the hardware fully, the chances of configuring things wrong (by for example enabling both the host and EP mode device tree nodes) can be reduced.

So I think instead of duplicating all of the device tree content to have both a host and an EP node for each controller, it'd be better to just have a single node and let the device tree bindings specify which changes to apply to switch into EP mode.

For example, there should be nothing wrong with specifying some of the EP-only properties (like num-ib-windows and num-ob-windows) all the time and only use them when we actually run in EP mode.

As I mentioned earlier, there are a couple of easy ways to distinguish the modes. The presence of the "addr_space" reg entry is one example, but we could also key off the nvidia,pex-rst-gpio property, since that (presumably) wouldn't be needed for host mode.

That way we can just add default, host mode entries to tegra194.dtsi and whenever somebody wants to enable EP mode, they can just override the node in the board-level DTS file, like so:

	pcie@141a0000 {
		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
		reg-names = "appl", "atu_dma", "dbi", "addr_space";

		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1) GPIO_ACTIVE_LOW>;
	};
Quoted 1 line

Thierry

I like it and fine with making these modifications also but would like to hear from Rob also on this.

- Vidya Sagar

Quoted 55 lines
Quoted 55 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +51 -0
+
+Examples:
+=========
+
+Tegra194:
+--------
+
+	pcie_ep@141a0000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>;
+		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		num-lanes = <8>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&clkreq_c5_bi_dir_state>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX1_CORE_5>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX1_CORE_5_APB>,
+			 <&bpmp TEGRA194_RESET_PEX1_CORE_5>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 5>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
Signature · 1 line
2.17.1
#20 lore raw

Re: [PATCH 6/6] arm64: tegra: Add support for PCIe endpoint mode in P2972-0000 platform

In reply to Vidya Sagar
Quoted 36 lines · Vidya Sagar
Quoted 35 lines · Thierry Reding
Quoted 19 lines · Vidya Sagar

Add endpoint mode support for PCIe C5 controller in P2972-0000 platform with information about supplies, PHY, PERST GPIO and GPIO that controls PCIe reference clock coming from the host system.

---
  .../boot/dts/nvidia/tegra194-p2972-0000.dts   | 29 +++++++++++++++++++
  1 file changed, 29 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +3 -0
index 7eb64b816e08..58c3a9677bc8 100644
@@ -43,6 +43,19 @@
  		gpio@c2f0000 {
  			status = "okay";
+			/*
+			 * Change the below node's status to 'okay' when
+			 * PCIe C5 controller is enabled to operate in endpoint

arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts line 57

Quoted 10 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +10 -0
+			 * to allow REFCLK from the host system to flow into
+			 * the controller.
+			 */
+			pex-refclk-sel-high {
+				gpio-hog;
+				output-high;
+				gpios = <TEGRA194_AON_GPIO(AA, 5) 0>;
+				label = "pex_refclk_sel_high";
+				status = "disabled";
+			};

Why don't we put this into the PCIe controller's node as a reference to that GPIO? Seems like the controller would know exactly when this pin needs to go high or low, so why does it have to be a hog?

Quoted 8 lines
Quoted 1 line

Thierry

Are you saying something like 'nvidia,enable-refclk-in'?
I was thinking, since this is like a board level configuration specific to Jetson-Xavier, it would suffice to just hog it according to the mode of operation of PCIe controller. But, I see one advantage of referencing it in the PCIe node (so that the driver can configure it as and when needed) is that one has to be careful just to enable either PCIe RP or EP node and not worry about other thing (like this).
Let me know if I got this right.

Yeah, that's exactly why I think referencing this from the controller and controlling it in the driver is preferable.

If this is some sort of select signal I think it makes sense to name it "nvidia,refclk-select-gpios" or something. Does this appear in the schematic somewhere? Or does the IP have a name for this? Those are usually good places to look for inspiration on the name because it's what hardware designers will be familiar with and they are technically the ones who should write the DT, even if that's rarely the case.

Thierry

Quoted 32 lines

- Vidya Sagar

Quoted 28 lines
Quoted 28 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +16 -0
  		};
  		pwm@c340000 {
@@ -144,6 +157,22 @@
  			    "p2u-5", "p2u-6", "p2u-7";
  	};
+	pcie_ep@141a0000 {
+		status = "disabled";
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
+
  	fan: fan {
  		compatible = "pwm-fan";
  		pwms = <&pwm4 0 45334>;
Signature · 1 line
2.17.1
#21 lore raw

Re: [PATCH 6/6] arm64: tegra: Add support for PCIe endpoint mode in P2972-0000 platform

Quoted 49 lines · Thierry Reding
Quoted 36 lines · Vidya Sagar
Quoted 35 lines · Thierry Reding
Quoted 19 lines · Vidya Sagar

Add endpoint mode support for PCIe C5 controller in P2972-0000 platform with information about supplies, PHY, PERST GPIO and GPIO that controls PCIe reference clock coming from the host system.

---
   .../boot/dts/nvidia/tegra194-p2972-0000.dts   | 29 +++++++++++++++++++
   1 file changed, 29 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +3 -0
index 7eb64b816e08..58c3a9677bc8 100644
@@ -43,6 +43,19 @@
   		gpio@c2f0000 {
   			status = "okay";
+			/*
+			 * Change the below node's status to 'okay' when
+			 * PCIe C5 controller is enabled to operate in endpoint

arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts line 57

Quoted 10 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +10 -0
+			 * to allow REFCLK from the host system to flow into
+			 * the controller.
+			 */
+			pex-refclk-sel-high {
+				gpio-hog;
+				output-high;
+				gpios = <TEGRA194_AON_GPIO(AA, 5) 0>;
+				label = "pex_refclk_sel_high";
+				status = "disabled";
+			};

Why don't we put this into the PCIe controller's node as a reference to that GPIO? Seems like the controller would know exactly when this pin needs to go high or low, so why does it have to be a hog?

Quoted 8 lines
Quoted 1 line

Thierry

Are you saying something like 'nvidia,enable-refclk-in'?
I was thinking, since this is like a board level configuration specific to Jetson-Xavier, it would suffice to just hog it according to the mode of operation of PCIe controller. But, I see one advantage of referencing it in the PCIe node (so that the driver can configure it as and when needed) is that one has to be careful just to enable either PCIe RP or EP node and not worry about other thing (like this).
Let me know if I got this right.

Yeah, that's exactly why I think referencing this from the controller and controlling it in the driver is preferable.

Quoted 6 lines

If this is some sort of select signal I think it makes sense to name it "nvidia,refclk-select-gpios" or something. Does this appear in the schematic somewhere? Or does the IP have a name for this? Those are usually good places to look for inspiration on the name because it's what hardware designers will be familiar with and they are technically the ones who should write the DT, even if that's rarely the case.

Schematic has "PEX_REFCLK_SEL" name.
I would go with 'nvidia,refclk-select-gpios' and make the change.

- Vidya Sagar

Quoted 35 lines

Thierry

Quoted 32 lines

- Vidya Sagar

Quoted 28 lines
Quoted 28 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +16 -0
   		};
   		pwm@c340000 {
@@ -144,6 +157,22 @@
   			    "p2u-5", "p2u-6", "p2u-7";
   	};
+	pcie_ep@141a0000 {
+		status = "disabled";
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
+
   	fan: fan {
   		compatible = "pwm-fan";
   		pwms = <&pwm4 0 45334>;
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 2/6] dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194

In reply to Vidya Sagar
Quoted 104 lines · Vidya Sagar
Quoted 10 lines · Thierry Reding
Quoted 8 lines · Vidya Sagar

Add support for PCIe controllers that can operate in endpoint mode in Tegra194.

---
  .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++++++++++++++++
  1 file changed, 138 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt

Quoted 5 lines

The vast majority of this is a duplication of the host mode device tree bindings. I think it'd be best to combine both and only highlight where both modes differ.

The designware-pcie.txt binding does something similar.

Ok. I'll merge this into the host mode bindings file and in that differentiate between root mode and endpoint mode.

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +5 -0
new file mode 100644
index 000000000000..4676ccf7dfa5
@@ -0,0 +1,138 @@
+NVIDIA Tegra PCIe Endpoint mode controller (Synopsys DesignWare Core based)
+
+Some of the PCIe controllers which are based on Synopsys DesignWare PCIe IP
+are dual mode i.e. they can work in root port mode or endpoint mode but one
+ at a time. Since they are based on DesignWare IP, they inherit all the common
Quoted 8 lines

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 9

Quoted 4 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +4 -0
+properties defined in designware-pcie.txt.
+
+Required properties:
+- compatible: For Tegra19x, must contain "nvidia,tegra194-pcie".

The device tree snippets that you added have "nvidia,tegra194-pcie-ep" for EP mode controllers. So either this is wrong or the DTS files are wrong.

DTS file are correct. This is a mistake in this file. I'll correct this.

Quoted 7 lines

This device tree binding describes the exact same hardware, so I don't think we necessarily need two different compatible strings. It's fairly easy to distinguish between which mode to run in by looking at which properties exist. EP mode for example is the only one that uses the "addr_space" reg entry.

Quoted 5 lines

Rob, do you know why a different compatible string was chosen for the EP mode? Looking at the driver, there are only a handful of differences in the programming, but most of the driver remains identical. An extra DT compatible string seems a bit exaggerated since it suggests that this is actually different hardware, where it clearly isn't.

Since all other implementations have done it this way, I just followed to be in sync with them. Even I would also like to hear from Rob on the rationale behind this.

Quoted 46 lines
Quoted 35 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +34 -0
+  Tegra194: Only C0, C4 & C5 controllers are dual mode controllers.
+- power-domains: A phandle to the node that controls power to the respective
+  PCIe controller and a specifier name for the PCIe controller. Following are
+  the specifiers for the different PCIe controllers
+    TEGRA194_POWER_DOMAIN_PCIEX8B: C0
+    TEGRA194_POWER_DOMAIN_PCIEX4A: C4
+    TEGRA194_POWER_DOMAIN_PCIEX8A: C5
+  these specifiers are defined in
+  "include/dt-bindings/power/tegra194-powergate.h" file.
+- reg: A list of physical base address and length pairs for each set of
+  controller registers. Must contain an entry for each entry in the reg-names
+  property.
+- reg-names: Must include the following entries:
+  "appl": Controller's application logic registers
+  "atu_dma": iATU and DMA registers. This is where the iATU (internal Address
+             Translation Unit) registers of the PCIe core are made available
+             for SW access.
+  "dbi": The aperture where root port's own configuration registers are
+         available
+  "addr_space": Used to map remote RC address space
+- interrupts: A list of interrupt outputs of the controller. Must contain an
+  entry for each entry in the interrupt-names property.
+- interrupt-names: Must include the following entry:
+  "intr": The Tegra interrupt that is asserted for controller interrupts
+- clocks: Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names: Must include the following entries:
+  - core
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: Must include the following entries:
+  - apb
+  - core
+- phys: Must contain a phandle to P2U PHY for each entry in phy-names.

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 53

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+- phy-names: Must include an entry for each active lane.
+  "p2u-N": where N ranges from 0 to one less than the total number of lanes
+- nvidia,bpmp: Must contain a pair of phandle to BPMP controller node followed
+  by controller-id. Following are the controller ids for each controller.
+    0: C0
+    4: C4
+    5: C5
+- vddio-pex-ctl-supply: Regulator supply for PCIe side band signals
+- nvidia,pex-rst-gpio: Must contain a phandle to a GPIO controller followed by
+  GPIO that is being used as PERST signal
Quoted 2 lines

Why is this NVIDIA specific? Do other instantiations of the DW IP not also need a means to define which GPIO is the reset?

Quoted 7 lines

I'm not sure. At least I didn't find anything like this in other implementations. My understanding is that, controller handles assert/de-assert on the PERST line automatically without SW intervention. I think it is for the same reason that other implementations don't wait for the REFCLK to flow in from host to configure the IP. I think they just use some internal clock for the configuration and switch to running the core based on REFCLK as and when it is available
(i.e. whenever a de-assert is perceived on PERST line by the controller)

That would be somewhat surprising, though. The IP used in Tegra must be pretty close to the IP used in other SoCs, and the code that we need in pex_ep_event_pex_rst_{assert,deassert}() is pretty significant. Why the other instantiations wouldn't need something similar seems unlikely to me.

Perhaps Jingoo or Gustavo can shed some light on this.

Thierry

Quoted 131 lines
Quoted 70 lines
Quoted 26 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +24 -0
+
+Optional properties:
+- pinctrl-names: A list of pinctrl state names.
+  It is mandatory for C5 controller and optional for other controllers.
+  - "default": Configures PCIe I/O for proper operation.
+- pinctrl-0: phandle for the 'default' state of pin configuration.
+  It is mandatory for C5 controller and optional for other controllers.
+- supports-clkreq: Refer to Documentation/devicetree/bindings/pci/pci.txt
+- nvidia,update-fc-fixup: This is a boolean property and needs to be present to
+    improve performance when a platform is designed in such a way that it
+    satisfies at least one of the following conditions thereby enabling root
+    port to exchange optimum number of FC (Flow Control) credits with
+    downstream devices
+    1. If C0/C4/C5 run at x1/x2 link widths (irrespective of speed and MPS)
+    2. If C0/C4/C5 operate at their respective max link widths and
+       a) speed is Gen-2 and MPS is 256B
+       b) speed is >= Gen-3 with any MPS
+- nvidia,aspm-cmrt-us: Common Mode Restore Time for proper operation of ASPM
+   to be specified in microseconds
+- nvidia,aspm-pwr-on-t-us: Power On time for proper operation of ASPM to be
+   specified in microseconds
+- nvidia,aspm-l0s-entrance-latency-us: ASPM L0s entrance latency to be
+   specified in microseconds
+

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+NOTE:- On Tegra194's P2972-0000 platform, only C5 controller can be enabled to
+operate in the endpoint mode because of the way the platform is designed.
+There is a mux that needs to be programmed to let the REFCLK from the host to
+flow into C5 controller when it operates in the endpoint mode. This mux is
+controlled by the GPIO (AA, 5) and it needs to be driven 'high'. For this to
+happen, set status of "pex-refclk-sel-high" node under "gpio@c2f0000" node to
+'okay'.
+	When any dual mode controller is made to operate in the endpoint mode,
+please make sure that its respective root port node's status is set to
+'disabled'.

This seems very brittle to me. There's no good way how we can detect such misconfigurations. If instead we only have one node describing the hardware fully, the chances of configuring things wrong (by for example enabling both the host and EP mode device tree nodes) can be reduced.

So I think instead of duplicating all of the device tree content to have both a host and an EP node for each controller, it'd be better to just have a single node and let the device tree bindings specify which changes to apply to switch into EP mode.

For example, there should be nothing wrong with specifying some of the EP-only properties (like num-ib-windows and num-ob-windows) all the time and only use them when we actually run in EP mode.

As I mentioned earlier, there are a couple of easy ways to distinguish the modes. The presence of the "addr_space" reg entry is one example, but we could also key off the nvidia,pex-rst-gpio property, since that (presumably) wouldn't be needed for host mode.

That way we can just add default, host mode entries to tegra194.dtsi and whenever somebody wants to enable EP mode, they can just override the node in the board-level DTS file, like so:

	pcie@141a0000 {
		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
		reg-names = "appl", "atu_dma", "dbi", "addr_space";

		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1) GPIO_ACTIVE_LOW>;
	};
Quoted 1 line

Thierry

I like it and fine with making these modifications also but would like to hear from Rob also on this.

- Vidya Sagar

Quoted 55 lines
Quoted 55 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +51 -0
+
+Examples:
+=========
+
+Tegra194:
+--------
+
+	pcie_ep@141a0000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>;
+		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		num-lanes = <8>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&clkreq_c5_bi_dir_state>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX1_CORE_5>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX1_CORE_5_APB>,
+			 <&bpmp TEGRA194_RESET_PEX1_CORE_5>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 5>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
Signature · 1 line
2.17.1
#22 lore raw

Re: [PATCH 6/6] arm64: tegra: Add support for PCIe endpoint mode in P2972-0000 platform

In reply to Vidya Sagar
Quoted 50 lines · Vidya Sagar
Quoted 49 lines · Thierry Reding
Quoted 36 lines · Vidya Sagar
Quoted 35 lines · Thierry Reding
Quoted 19 lines · Vidya Sagar

Add endpoint mode support for PCIe C5 controller in P2972-0000 platform with information about supplies, PHY, PERST GPIO and GPIO that controls PCIe reference clock coming from the host system.

---
   .../boot/dts/nvidia/tegra194-p2972-0000.dts   | 29 +++++++++++++++++++
   1 file changed, 29 insertions(+)
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +3 -0
index 7eb64b816e08..58c3a9677bc8 100644
@@ -43,6 +43,19 @@
   		gpio@c2f0000 {
   			status = "okay";
+			/*
+			 * Change the below node's status to 'okay' when
+			 * PCIe C5 controller is enabled to operate in endpoint

arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts line 57

Quoted 10 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +10 -0
+			 * to allow REFCLK from the host system to flow into
+			 * the controller.
+			 */
+			pex-refclk-sel-high {
+				gpio-hog;
+				output-high;
+				gpios = <TEGRA194_AON_GPIO(AA, 5) 0>;
+				label = "pex_refclk_sel_high";
+				status = "disabled";
+			};

Why don't we put this into the PCIe controller's node as a reference to that GPIO? Seems like the controller would know exactly when this pin needs to go high or low, so why does it have to be a hog?

Quoted 8 lines
Quoted 1 line

Thierry

Are you saying something like 'nvidia,enable-refclk-in'?
I was thinking, since this is like a board level configuration specific to Jetson-Xavier, it would suffice to just hog it according to the mode of operation of PCIe controller. But, I see one advantage of referencing it in the PCIe node (so that the driver can configure it as and when needed) is that one has to be careful just to enable either PCIe RP or EP node and not worry about other thing (like this).
Let me know if I got this right.

Yeah, that's exactly why I think referencing this from the controller and controlling it in the driver is preferable.

Quoted 8 lines
Quoted 6 lines

If this is some sort of select signal I think it makes sense to name it "nvidia,refclk-select-gpios" or something. Does this appear in the schematic somewhere? Or does the IP have a name for this? Those are usually good places to look for inspiration on the name because it's what hardware designers will be familiar with and they are technically the ones who should write the DT, even if that's rarely the case.

Schematic has "PEX_REFCLK_SEL" name.
I would go with 'nvidia,refclk-select-gpios' and make the change.

It might be worth checking the interface definition of the IP if you have access to that, since it may be using a different name from the one that we have in the schematics.

Also, given that other instantiations don't have this, I'm beginning to wonder if this is perhaps somehow specific to how this is used in this particular board design. If it is, then I think the nvidia, prefix would be appropriate. But if this is something that is part of the IP interface then we can probably drop the prefix since it would be applicable to non-NVIDIA instantiations as well.

Thierry

Quoted 38 lines

- Vidya Sagar

Quoted 35 lines

Thierry

Quoted 32 lines

- Vidya Sagar

Quoted 28 lines
Quoted 28 lines
arch/arm64/boot/dts/nvidia/tegra194-p2972-0000.dts +16 -0
   		};
   		pwm@c340000 {
@@ -144,6 +157,22 @@
   			    "p2u-5", "p2u-6", "p2u-7";
   	};
+	pcie_ep@141a0000 {
+		status = "disabled";
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
+
   	fan: fan {
   		compatible = "pwm-fan";
   		pwms = <&pwm4 0 45334>;
Signature · 1 line
2.17.1
#6 lore raw

RE: [PATCH 2/6] dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194

In reply to Thierry Reding
Quoted 113 lines · Thierry Reding
Quoted 104 lines · Vidya Sagar
Quoted 10 lines · Thierry Reding
Quoted 8 lines · Vidya Sagar

Add support for PCIe controllers that can operate in endpoint mode in Tegra194.

---
  .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++++++++++++++++
  1 file changed, 138 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt

Quoted 5 lines

The vast majority of this is a duplication of the host mode device tree bindings. I think it'd be best to combine both and only highlight where both modes differ.

The designware-pcie.txt binding does something similar.

Ok. I'll merge this into the host mode bindings file and in that differentiate between root mode and endpoint mode.

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +5 -0
new file mode 100644
index 000000000000..4676ccf7dfa5
@@ -0,0 +1,138 @@
+NVIDIA Tegra PCIe Endpoint mode controller (Synopsys DesignWare Core based)
+
+Some of the PCIe controllers which are based on Synopsys DesignWare PCIe IP
+are dual mode i.e. they can work in root port mode or endpoint mode but one
+ at a time. Since they are based on DesignWare IP, they inherit all the common
Quoted 8 lines

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 9

Quoted 4 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +4 -0
+properties defined in designware-pcie.txt.
+
+Required properties:
+- compatible: For Tegra19x, must contain "nvidia,tegra194-pcie".

The device tree snippets that you added have "nvidia,tegra194-pcie-ep" for EP mode controllers. So either this is wrong or the DTS files are wrong.

DTS file are correct. This is a mistake in this file. I'll correct this.

Quoted 7 lines

This device tree binding describes the exact same hardware, so I don't think we necessarily need two different compatible strings. It's fairly easy to distinguish between which mode to run in by looking at which properties exist. EP mode for example is the only one that uses the "addr_space" reg entry.

Quoted 5 lines

Rob, do you know why a different compatible string was chosen for the EP mode? Looking at the driver, there are only a handful of differences in the programming, but most of the driver remains identical. An extra DT compatible string seems a bit exaggerated since it suggests that this is actually different hardware, where it clearly isn't.

Since all other implementations have done it this way, I just followed to be in sync with them. Even I would also like to hear from Rob on the rationale behind this.

Quoted 46 lines
Quoted 35 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +34 -0
+  Tegra194: Only C0, C4 & C5 controllers are dual mode controllers.
+- power-domains: A phandle to the node that controls power to the respective
+  PCIe controller and a specifier name for the PCIe controller. Following are
+  the specifiers for the different PCIe controllers
+    TEGRA194_POWER_DOMAIN_PCIEX8B: C0
+    TEGRA194_POWER_DOMAIN_PCIEX4A: C4
+    TEGRA194_POWER_DOMAIN_PCIEX8A: C5
+  these specifiers are defined in
+  "include/dt-bindings/power/tegra194-powergate.h" file.
+- reg: A list of physical base address and length pairs for each set of
+  controller registers. Must contain an entry for each entry in the reg-names
+  property.
+- reg-names: Must include the following entries:
+  "appl": Controller's application logic registers
+  "atu_dma": iATU and DMA registers. This is where the iATU (internal Address
+             Translation Unit) registers of the PCIe core are made available
+             for SW access.
+  "dbi": The aperture where root port's own configuration registers are
+         available
+  "addr_space": Used to map remote RC address space
+- interrupts: A list of interrupt outputs of the controller. Must contain an
+  entry for each entry in the interrupt-names property.
+- interrupt-names: Must include the following entry:
+  "intr": The Tegra interrupt that is asserted for controller interrupts
+- clocks: Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names: Must include the following entries:
+  - core
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: Must include the following entries:
+  - apb
+  - core
+- phys: Must contain a phandle to P2U PHY for each entry in phy-names.

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 53

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+- phy-names: Must include an entry for each active lane.
+  "p2u-N": where N ranges from 0 to one less than the total number of lanes
+- nvidia,bpmp: Must contain a pair of phandle to BPMP controller node followed
+  by controller-id. Following are the controller ids for each controller.
+    0: C0
+    4: C4
+    5: C5
+- vddio-pex-ctl-supply: Regulator supply for PCIe side band signals
+- nvidia,pex-rst-gpio: Must contain a phandle to a GPIO controller followed by
+  GPIO that is being used as PERST signal
Quoted 2 lines

Why is this NVIDIA specific? Do other instantiations of the DW IP not also need a means to define which GPIO is the reset?

Quoted 7 lines

I'm not sure. At least I didn't find anything like this in other implementations. My understanding is that, controller handles assert/de-assert on the PERST line automatically without SW intervention. I think it is for the same reason that other implementations don't wait for the REFCLK to flow in from host to configure the IP. I think they just use some internal clock for the configuration and switch to running the core based on REFCLK as and when it is available
(i.e. whenever a de-assert is perceived on PERST line by the controller)

Quoted 7 lines

That would be somewhat surprising, though. The IP used in Tegra must be pretty close to the IP used in other SoCs, and the code that we need in pex_ep_event_pex_rst_{assert,deassert}() is pretty significant. Why the other instantiations wouldn't need something similar seems unlikely to me.

Perhaps Jingoo or Gustavo can shed some light on this.

On my current FPGA prototyping solution, I don't need to control the PERST line and it's very likely that I don't even have access to control it. I guess due to some particularity of my solution, the HW team probably has decided to wire it up directly for some unknown reason to me.

However, It seems to me that exynos, imx6, keystone, meson, al, histb, kirin, and qcom drivers controls the PERST line in spite of others driver that doesn't do it like in my prototype solution.
In the end I'd says that depends of how the IP solution of design by the HW team.

Gustavo

Quoted 134 lines

Thierry

Quoted 131 lines
Quoted 70 lines
Quoted 26 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +24 -0
+
+Optional properties:
+- pinctrl-names: A list of pinctrl state names.
+  It is mandatory for C5 controller and optional for other controllers.
+  - "default": Configures PCIe I/O for proper operation.
+- pinctrl-0: phandle for the 'default' state of pin configuration.
+  It is mandatory for C5 controller and optional for other controllers.
+- supports-clkreq: Refer to Documentation/devicetree/bindings/pci/pci.txt
+- nvidia,update-fc-fixup: This is a boolean property and needs to be present to
+    improve performance when a platform is designed in such a way that it
+    satisfies at least one of the following conditions thereby enabling root
+    port to exchange optimum number of FC (Flow Control) credits with
+    downstream devices
+    1. If C0/C4/C5 run at x1/x2 link widths (irrespective of speed and MPS)
+    2. If C0/C4/C5 operate at their respective max link widths and
+       a) speed is Gen-2 and MPS is 256B
+       b) speed is >= Gen-3 with any MPS
+- nvidia,aspm-cmrt-us: Common Mode Restore Time for proper operation of ASPM
+   to be specified in microseconds
+- nvidia,aspm-pwr-on-t-us: Power On time for proper operation of ASPM to be
+   specified in microseconds
+- nvidia,aspm-l0s-entrance-latency-us: ASPM L0s entrance latency to be
+   specified in microseconds
+

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+NOTE:- On Tegra194's P2972-0000 platform, only C5 controller can be enabled to
+operate in the endpoint mode because of the way the platform is designed.
+There is a mux that needs to be programmed to let the REFCLK from the host to
+flow into C5 controller when it operates in the endpoint mode. This mux is
+controlled by the GPIO (AA, 5) and it needs to be driven 'high'. For this to
+happen, set status of "pex-refclk-sel-high" node under "gpio@c2f0000" node to
+'okay'.
+	When any dual mode controller is made to operate in the endpoint mode,
+please make sure that its respective root port node's status is set to
+'disabled'.

This seems very brittle to me. There's no good way how we can detect such misconfigurations. If instead we only have one node describing the hardware fully, the chances of configuring things wrong (by for example enabling both the host and EP mode device tree nodes) can be reduced.

So I think instead of duplicating all of the device tree content to have both a host and an EP node for each controller, it'd be better to just have a single node and let the device tree bindings specify which changes to apply to switch into EP mode.

For example, there should be nothing wrong with specifying some of the EP-only properties (like num-ib-windows and num-ob-windows) all the time and only use them when we actually run in EP mode.

As I mentioned earlier, there are a couple of easy ways to distinguish the modes. The presence of the "addr_space" reg entry is one example, but we could also key off the nvidia,pex-rst-gpio property, since that (presumably) wouldn't be needed for host mode.

That way we can just add default, host mode entries to tegra194.dtsi and whenever somebody wants to enable EP mode, they can just override the node in the board-level DTS file, like so:

	pcie@141a0000 {
		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
		reg-names = "appl", "atu_dma", "dbi", "addr_space";

		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1) GPIO_ACTIVE_LOW>;
	};
Quoted 1 line

Thierry

I like it and fine with making these modifications also but would like to hear from Rob also on this.

- Vidya Sagar

Quoted 55 lines
Quoted 55 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +51 -0
+
+Examples:
+=========
+
+Tegra194:
+--------
+
+	pcie_ep@141a0000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>;
+		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		num-lanes = <8>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&clkreq_c5_bi_dir_state>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX1_CORE_5>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX1_CORE_5_APB>,
+			 <&bpmp TEGRA194_RESET_PEX1_CORE_5>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 5>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
Signature · 1 line
2.17.1
#11 lore raw

Re: [PATCH 3/6] PCI: tegra: Add support for PCIe endpoint mode in Tegra194

In reply to Vidya Sagar
Quoted 18 lines · Vidya Sagar

Add support for the endpoint mode of Synopsys DesignWare core based dual mode PCIe controllers present in Tegra194 SoC.

drivers/pci/controller/dwc/pcie-tegra194.c +15 -0
+static irqreturn_t tegra_pcie_ep_irq_handler(struct tegra_pcie_dw *pcie)
+{
+	struct dw_pcie_ep *ep = &pcie->pci.ep;
+	u32 val, tmp;
+
+	val = appl_readl(pcie, APPL_INTR_STATUS_L0);
+	if (val & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
+		val = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
+		appl_writel(pcie, val, APPL_INTR_STATUS_L1_0_0);
+		if (val & APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE) {
+			/* clear any stale PEX_RST interrupt */
+			if (!kfifo_put(&pcie->event_fifo, EP_HOT_RST_DONE)) {
+				dev_err(pcie->dev, "EVENT FIFO is full\n");
+				return IRQ_HANDLED;
+			}

drivers/pci/controller/dwc/pcie-tegra194.c static irqreturn_t tegra_pcie_rp_irq_handler(struct tegra_pcie_dw *pcie) · line 492

Quoted 10 lines
drivers/pci/controller/dwc/pcie-tegra194.c +10 -0
+			wake_up(&pcie->wq);
+		}
+		if (val & APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED) {
+			tmp = appl_readl(pcie, APPL_LINK_STATUS);
+			if (tmp & APPL_LINK_STATUS_RDLH_LINK_UP) {
+				dev_info(pcie->dev, "Link is up with Host\n");
+				dw_pcie_ep_linkup(ep);
+			}
+		}
+	} else if (val & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {

Is it really the case that only one of
APPL_INTR_STATUS_L0_LINK_STATE_INT and
APPL_INTR_STATUS_L0_PCI_CMD_EN_INT can be set?

If it's possible that both could be set, maybe this should be something like this?

  int spurious = 1;

  if (val & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
    ...
    spurious = 0;
  }
  if (val & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {
    ...
    spurious = 0;
  }

  if (spurious) {
    dev_warn(...)
  }
Quoted 52 lines
(quoted diff) +51 -0
+		val = appl_readl(pcie, APPL_INTR_STATUS_L1_15);
+		appl_writel(pcie, val, APPL_INTR_STATUS_L1_15);
+		if (val & APPL_INTR_STATUS_L1_15_CFG_BME_CHGED) {
+			if (!kfifo_put(&pcie->event_fifo, EP_BME_CHANGE)) {
+				dev_err(pcie->dev, "EVENT FIFO is full\n");
+				return IRQ_HANDLED;
+			}
+			wake_up(&pcie->wq);
+		}
+	} else {
+		dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n",
+			 val);
+		appl_writel(pcie, val, APPL_INTR_STATUS_L0);
+	}
+
+	return IRQ_HANDLED;
+}
 
+static int tegra_pcie_ep_work_thread(void *p)
+{
+	struct tegra_pcie_dw *pcie = (struct tegra_pcie_dw *)p;
+	u32 event;
+
+	while (true) {
+		wait_event_interruptible(pcie->wq,
+					 !kfifo_is_empty(&pcie->event_fifo));
+
+		if (kthread_should_stop())
+			break;
+
+		if (!kfifo_get(&pcie->event_fifo, &event)) {
+			dev_warn(pcie->dev, "EVENT FIFO is empty\n");
+			continue;
+		}
+
+		switch (event) {
+		case EP_PEX_RST_DEASSERT:
+			dev_info(pcie->dev, "EVENT: EP_PEX_RST_DEASSERT\n");
+			pex_ep_event_pex_rst_deassert(pcie);
+			break;
+
+		case EP_PEX_RST_ASSERT:
+			dev_info(pcie->dev, "EVENT: EP_PEX_RST_ASSERT\n");
+			pex_ep_event_pex_rst_assert(pcie);
+			break;
+
+		case EP_HOT_RST_DONE:
+			dev_info(pcie->dev, "EVENT: EP_HOT_RST_DONE\n");
+			pex_ep_event_hot_rst_done(pcie);
+			break;
+
+		case EP_BME_CHANGE:

Review

Quoted 10 lines
(quoted diff) +10 -0
+			dev_info(pcie->dev, "EVENT: EP_BME_CHANGE\n");
+			pex_ep_event_bme_change(pcie);
+			break;
+
+		case EP_EVENT_EXIT:
+			dev_info(pcie->dev, "EVENT: EP_EVENT_EXIT\n");
+			return 0;
+
+		default:
+			dev_warn(pcie->dev, "Invalid PCIe EP event\n");

Maybe include the invalid event value in the message?

Quoted 6 lines
drivers/pci/controller/dwc/pcie-tegra194.c +6 -0
+			break;
+		}
+	}
+
+	return 0;
+}
#12 lore raw

Re: [PATCH 3/6] PCI: tegra: Add support for PCIe endpoint mode in Tegra194

Quoted 25 lines · Bjorn Helgaas
Quoted 24 lines · Vidya Sagar

Add support for the endpoint mode of Synopsys DesignWare core based dual mode PCIe controllers present in Tegra194 SoC.

drivers/pci/controller/dwc/pcie-tegra194.c +21 -0
+static irqreturn_t tegra_pcie_ep_irq_handler(struct tegra_pcie_dw *pcie)
+{
+	struct dw_pcie_ep *ep = &pcie->pci.ep;
+	u32 val, tmp;
+
+	val = appl_readl(pcie, APPL_INTR_STATUS_L0);
+	if (val & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
+		val = appl_readl(pcie, APPL_INTR_STATUS_L1_0_0);
+		appl_writel(pcie, val, APPL_INTR_STATUS_L1_0_0);
+		if (val & APPL_INTR_STATUS_L1_0_0_HOT_RESET_DONE) {
+			/* clear any stale PEX_RST interrupt */
+			if (!kfifo_put(&pcie->event_fifo, EP_HOT_RST_DONE)) {
+				dev_err(pcie->dev, "EVENT FIFO is full\n");
+				return IRQ_HANDLED;
+			}
+			wake_up(&pcie->wq);
+		}
+		if (val & APPL_INTR_STATUS_L1_0_0_RDLH_LINK_UP_CHGED) {
+			tmp = appl_readl(pcie, APPL_LINK_STATUS);
+			if (tmp & APPL_LINK_STATUS_RDLH_LINK_UP) {
+				dev_info(pcie->dev, "Link is up with Host\n");
Quoted 8 lines

drivers/pci/controller/dwc/pcie-tegra194.c static irqreturn_t tegra_pcie_rp_irq_handler(struct tegra_pcie_dw *pcie) · line 492

Quoted 4 lines
drivers/pci/controller/dwc/pcie-tegra194.c +4 -0
+				dw_pcie_ep_linkup(ep);
+			}
+		}
+	} else if (val & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {

Is it really the case that only one of
APPL_INTR_STATUS_L0_LINK_STATE_INT and
APPL_INTR_STATUS_L0_PCI_CMD_EN_INT can be set?

Not really.

Quoted 4 lines

If it's possible that both could be set, maybe this should be something like this?

Quoted 14 lines
   int spurious = 1;

   if (val & APPL_INTR_STATUS_L0_LINK_STATE_INT) {
     ...
     spurious = 0;
   }
   if (val & APPL_INTR_STATUS_L0_PCI_CMD_EN_INT) {
     ...
     spurious = 0;
   }

   if (spurious) {
     dev_warn(...)
   }

I'll take care of this in the next patch series.

Quoted 57 lines
Quoted 57 lines
(quoted diff) +55 -0
+		val = appl_readl(pcie, APPL_INTR_STATUS_L1_15);
+		appl_writel(pcie, val, APPL_INTR_STATUS_L1_15);
+		if (val & APPL_INTR_STATUS_L1_15_CFG_BME_CHGED) {
+			if (!kfifo_put(&pcie->event_fifo, EP_BME_CHANGE)) {
+				dev_err(pcie->dev, "EVENT FIFO is full\n");
+				return IRQ_HANDLED;
+			}
+			wake_up(&pcie->wq);
+		}
+	} else {
+		dev_warn(pcie->dev, "Random interrupt (STATUS = 0x%08X)\n",
+			 val);
+		appl_writel(pcie, val, APPL_INTR_STATUS_L0);
+	}
+
+	return IRQ_HANDLED;
+}
 
+static int tegra_pcie_ep_work_thread(void *p)
+{
+	struct tegra_pcie_dw *pcie = (struct tegra_pcie_dw *)p;
+	u32 event;
+
+	while (true) {
+		wait_event_interruptible(pcie->wq,
+					 !kfifo_is_empty(&pcie->event_fifo));
+
+		if (kthread_should_stop())
+			break;
+
+		if (!kfifo_get(&pcie->event_fifo, &event)) {
+			dev_warn(pcie->dev, "EVENT FIFO is empty\n");
+			continue;
+		}
+
+		switch (event) {
+		case EP_PEX_RST_DEASSERT:
+			dev_info(pcie->dev, "EVENT: EP_PEX_RST_DEASSERT\n");
+			pex_ep_event_pex_rst_deassert(pcie);
+			break;
+
+		case EP_PEX_RST_ASSERT:
+			dev_info(pcie->dev, "EVENT: EP_PEX_RST_ASSERT\n");
+			pex_ep_event_pex_rst_assert(pcie);
+			break;
+
+		case EP_HOT_RST_DONE:
+			dev_info(pcie->dev, "EVENT: EP_HOT_RST_DONE\n");
+			pex_ep_event_hot_rst_done(pcie);
+			break;
+
+		case EP_BME_CHANGE:
+			dev_info(pcie->dev, "EVENT: EP_BME_CHANGE\n");
+			pex_ep_event_bme_change(pcie);
+			break;
+
Quoted 8 lines

drivers/pci/controller/dwc/pcie-tegra194.c static int tegra_pcie_config_rp(struct tegra_pcie_dw *pcie) · line 1931

Quoted 6 lines
drivers/pci/controller/dwc/pcie-tegra194.c +6 -0
+		case EP_EVENT_EXIT:
+			dev_info(pcie->dev, "EVENT: EP_EVENT_EXIT\n");
+			return 0;
+
+		default:
+			dev_warn(pcie->dev, "Invalid PCIe EP event\n");

Maybe include the invalid event value in the message?

I'll take care of this in the next patch series

Quoted 7 lines
Quoted 7 lines
drivers/pci/controller/dwc/pcie-tegra194.c +6 -0
+			break;
+		}
+	}
+
+	return 0;
+}
#7 lore raw

Re: [PATCH 2/6] dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194

In reply to Gustavo Pimentel
Quoted 52 lines · Gustavo Pimentel
Quoted 49 lines · Thierry Reding
Quoted 48 lines · Vidya Sagar
Quoted 10 lines · Thierry Reding
Quoted 8 lines · Vidya Sagar

Add support for PCIe controllers that can operate in endpoint mode in Tegra194.

---
   .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++++++++++++++++
   1 file changed, 138 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt

Quoted 5 lines

The vast majority of this is a duplication of the host mode device tree bindings. I think it'd be best to combine both and only highlight where both modes differ.

The designware-pcie.txt binding does something similar.

Ok. I'll merge this into the host mode bindings file and in that differentiate between root mode and endpoint mode.

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +5 -0
new file mode 100644
index 000000000000..4676ccf7dfa5
@@ -0,0 +1,138 @@
+NVIDIA Tegra PCIe Endpoint mode controller (Synopsys DesignWare Core based)
+
+Some of the PCIe controllers which are based on Synopsys DesignWare PCIe IP
+are dual mode i.e. they can work in root port mode or endpoint mode but one
+ at a time. Since they are based on DesignWare IP, they inherit all the common
Quoted 8 lines

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 9

Quoted 4 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +4 -0
+properties defined in designware-pcie.txt.
+
+Required properties:
+- compatible: For Tegra19x, must contain "nvidia,tegra194-pcie".

The device tree snippets that you added have "nvidia,tegra194-pcie-ep" for EP mode controllers. So either this is wrong or the DTS files are wrong.

DTS file are correct. This is a mistake in this file. I'll correct this.

Quoted 7 lines

This device tree binding describes the exact same hardware, so I don't think we necessarily need two different compatible strings. It's fairly easy to distinguish between which mode to run in by looking at which properties exist. EP mode for example is the only one that uses the "addr_space" reg entry.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Rob, do you know why a different compatible string was chosen for the EP mode? Looking at the driver, there are only a handful of differences in the programming, but most of the driver remains identical. An extra DT compatible string seems a bit exaggerated since it suggests that this is actually different hardware, where it clearly isn't.

Since all other implementations have done it this way, I just followed to be in sync with them. Even I would also like to hear from Rob on the rationale behind this.

Rob, Could you please update on this?

Quoted 215 lines
Quoted 57 lines
Quoted 49 lines
Quoted 47 lines
Quoted 36 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +34 -0
+  Tegra194: Only C0, C4 & C5 controllers are dual mode controllers.
+- power-domains: A phandle to the node that controls power to the respective
+  PCIe controller and a specifier name for the PCIe controller. Following are
+  the specifiers for the different PCIe controllers
+    TEGRA194_POWER_DOMAIN_PCIEX8B: C0
+    TEGRA194_POWER_DOMAIN_PCIEX4A: C4
+    TEGRA194_POWER_DOMAIN_PCIEX8A: C5
+  these specifiers are defined in
+  "include/dt-bindings/power/tegra194-powergate.h" file.
+- reg: A list of physical base address and length pairs for each set of
+  controller registers. Must contain an entry for each entry in the reg-names
+  property.
+- reg-names: Must include the following entries:
+  "appl": Controller's application logic registers
+  "atu_dma": iATU and DMA registers. This is where the iATU (internal Address
+             Translation Unit) registers of the PCIe core are made available
+             for SW access.
+  "dbi": The aperture where root port's own configuration registers are
+         available
+  "addr_space": Used to map remote RC address space
+- interrupts: A list of interrupt outputs of the controller. Must contain an
+  entry for each entry in the interrupt-names property.
+- interrupt-names: Must include the following entry:
+  "intr": The Tegra interrupt that is asserted for controller interrupts
+- clocks: Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names: Must include the following entries:
+  - core
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: Must include the following entries:
+  - apb
+  - core
+- phys: Must contain a phandle to P2U PHY for each entry in phy-names.

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 53

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+- phy-names: Must include an entry for each active lane.
+  "p2u-N": where N ranges from 0 to one less than the total number of lanes
+- nvidia,bpmp: Must contain a pair of phandle to BPMP controller node followed
+  by controller-id. Following are the controller ids for each controller.
+    0: C0
+    4: C4
+    5: C5
+- vddio-pex-ctl-supply: Regulator supply for PCIe side band signals
+- nvidia,pex-rst-gpio: Must contain a phandle to a GPIO controller followed by
+  GPIO that is being used as PERST signal
Quoted 2 lines

Why is this NVIDIA specific? Do other instantiations of the DW IP not also need a means to define which GPIO is the reset?

Quoted 7 lines

I'm not sure. At least I didn't find anything like this in other implementations. My understanding is that, controller handles assert/de-assert on the PERST line automatically without SW intervention. I think it is for the same reason that other implementations don't wait for the REFCLK to flow in from host to configure the IP. I think they just use some internal clock for the configuration and switch to running the core based on REFCLK as and when it is available
(i.e. whenever a de-assert is perceived on PERST line by the controller)

Quoted 7 lines

That would be somewhat surprising, though. The IP used in Tegra must be pretty close to the IP used in other SoCs, and the code that we need in pex_ep_event_pex_rst_{assert,deassert}() is pretty significant. Why the other instantiations wouldn't need something similar seems unlikely to me.

Perhaps Jingoo or Gustavo can shed some light on this.

On my current FPGA prototyping solution, I don't need to control the PERST line and it's very likely that I don't even have access to control it. I guess due to some particularity of my solution, the HW team probably has decided to wire it up directly for some unknown reason to me.

However, It seems to me that exynos, imx6, keystone, meson, al, histb, kirin, and qcom drivers controls the PERST line in spite of others driver that doesn't do it like in my prototype solution.
In the end I'd says that depends of how the IP solution of design by the HW team.

Gustavo

Quoted 134 lines

Thierry

Quoted 131 lines
Quoted 70 lines
Quoted 26 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +24 -0
+
+Optional properties:
+- pinctrl-names: A list of pinctrl state names.
+  It is mandatory for C5 controller and optional for other controllers.
+  - "default": Configures PCIe I/O for proper operation.
+- pinctrl-0: phandle for the 'default' state of pin configuration.
+  It is mandatory for C5 controller and optional for other controllers.
+- supports-clkreq: Refer to Documentation/devicetree/bindings/pci/pci.txt
+- nvidia,update-fc-fixup: This is a boolean property and needs to be present to
+    improve performance when a platform is designed in such a way that it
+    satisfies at least one of the following conditions thereby enabling root
+    port to exchange optimum number of FC (Flow Control) credits with
+    downstream devices
+    1. If C0/C4/C5 run at x1/x2 link widths (irrespective of speed and MPS)
+    2. If C0/C4/C5 operate at their respective max link widths and
+       a) speed is Gen-2 and MPS is 256B
+       b) speed is >= Gen-3 with any MPS
+- nvidia,aspm-cmrt-us: Common Mode Restore Time for proper operation of ASPM
+   to be specified in microseconds
+- nvidia,aspm-pwr-on-t-us: Power On time for proper operation of ASPM to be
+   specified in microseconds
+- nvidia,aspm-l0s-entrance-latency-us: ASPM L0s entrance latency to be
+   specified in microseconds
+

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+NOTE:- On Tegra194's P2972-0000 platform, only C5 controller can be enabled to
+operate in the endpoint mode because of the way the platform is designed.
+There is a mux that needs to be programmed to let the REFCLK from the host to
+flow into C5 controller when it operates in the endpoint mode. This mux is
+controlled by the GPIO (AA, 5) and it needs to be driven 'high'. For this to
+happen, set status of "pex-refclk-sel-high" node under "gpio@c2f0000" node to
+'okay'.
+	When any dual mode controller is made to operate in the endpoint mode,
+please make sure that its respective root port node's status is set to
+'disabled'.

This seems very brittle to me. There's no good way how we can detect such misconfigurations. If instead we only have one node describing the hardware fully, the chances of configuring things wrong (by for example enabling both the host and EP mode device tree nodes) can be reduced.

So I think instead of duplicating all of the device tree content to have both a host and an EP node for each controller, it'd be better to just have a single node and let the device tree bindings specify which changes to apply to switch into EP mode.

For example, there should be nothing wrong with specifying some of the EP-only properties (like num-ib-windows and num-ob-windows) all the time and only use them when we actually run in EP mode.

As I mentioned earlier, there are a couple of easy ways to distinguish the modes. The presence of the "addr_space" reg entry is one example, but we could also key off the nvidia,pex-rst-gpio property, since that (presumably) wouldn't be needed for host mode.

That way we can just add default, host mode entries to tegra194.dtsi and whenever somebody wants to enable EP mode, they can just override the node in the board-level DTS file, like so:

	pcie@141a0000 {
		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
		reg-names = "appl", "atu_dma", "dbi", "addr_space";

		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1) GPIO_ACTIVE_LOW>;
	};
Quoted 1 line

Thierry

I like it and fine with making these modifications also but would like to hear from Rob also on this.

- Vidya Sagar

Quoted 55 lines
Quoted 55 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +51 -0
+
+Examples:
+=========
+
+Tegra194:
+--------
+
+	pcie_ep@141a0000 {
+		compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+		power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>;
+		reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
+		       0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+		       0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
+		       0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+		reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+		num-lanes = <8>;
+		num-ib-windows = <2>;
+		num-ob-windows = <8>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&clkreq_c5_bi_dir_state>;
+
+		clocks = <&bpmp TEGRA194_CLK_PEX1_CORE_5>;
+		clock-names = "core";
+
+		resets = <&bpmp TEGRA194_RESET_PEX1_CORE_5_APB>,
+			 <&bpmp TEGRA194_RESET_PEX1_CORE_5>;
+		reset-names = "apb", "core";
+
+		interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>;	/* controller interrupt */
+		interrupt-names = "intr";
+
+		nvidia,bpmp = <&bpmp 5>;
+
+		nvidia,aspm-cmrt-us = <60>;
+		nvidia,aspm-pwr-on-t-us = <20>;
+		nvidia,aspm-l0s-entrance-latency-us = <3>;
+
+		vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+		nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+					GPIO_ACTIVE_LOW>;
+
+		phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+		       <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+		       <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+		phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+			    "p2u-5", "p2u-6", "p2u-7";
+	};
Signature · 1 line
2.17.1
maintainer
#9 lore raw

Re: [PATCH 2/6] dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194

In reply to Thierry Reding
Quoted 10 lines · Thierry Reding
Quoted 8 lines · Vidya Sagar

Add support for PCIe controllers that can operate in endpoint mode in Tegra194.

---
 .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++++++++++++++++
 1 file changed, 138 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt
Quoted 3 lines

The vast majority of this is a duplication of the host mode device tree bindings. I think it'd be best to combine both and only highlight where both modes differ.

That will not work so well as a schema because all the common PCI bus related properties don't apply. Child nodes if any for an EP aren't PCI devices either. Though you could have 3 files with common properties, host binding and ep bindings.

While we don't have anything in terms of common PCI EP bindings, I somewhat expect that to change. There's been something for how to define multiple EP functions for example.

Quoted 28 lines

The designware-pcie.txt binding does something similar.

Quoted 6 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +0 -0
new file mode 100644
index 000000000000..4676ccf7dfa5

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +9 -0
@@ -0,0 +1,138 @@
+NVIDIA Tegra PCIe Endpoint mode controller (Synopsys DesignWare Core based)
+
+Some of the PCIe controllers which are based on Synopsys DesignWare PCIe IP
+are dual mode i.e. they can work in root port mode or endpoint mode but one
+ at a time. Since they are based on DesignWare IP, they inherit all the common
+properties defined in designware-pcie.txt.
+
+Required properties:
+- compatible: For Tegra19x, must contain "nvidia,tegra194-pcie".

The device tree snippets that you added have "nvidia,tegra194-pcie-ep" for EP mode controllers. So either this is wrong or the DTS files are wrong.

This device tree binding describes the exact same hardware, so I don't think we necessarily need two different compatible strings. It's fairly easy to distinguish between which mode to run in by looking at which properties exist. EP mode for example is the only one that uses the "addr_space" reg entry.

Quoted 5 lines

Rob, do you know why a different compatible string was chosen for the EP mode? Looking at the driver, there are only a handful of differences in the programming, but most of the driver remains identical. An extra DT compatible string seems a bit exaggerated since it suggests that this is actually different hardware, where it clearly isn't.

Whether the driver shares a lot of code or not, it's fundamentally a different device and driver stack.

Quoted 45 lines
Quoted 34 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +34 -0
+  Tegra194: Only C0, C4 & C5 controllers are dual mode controllers.
+- power-domains: A phandle to the node that controls power to the respective
+  PCIe controller and a specifier name for the PCIe controller. Following are
+  the specifiers for the different PCIe controllers
+    TEGRA194_POWER_DOMAIN_PCIEX8B: C0
+    TEGRA194_POWER_DOMAIN_PCIEX4A: C4
+    TEGRA194_POWER_DOMAIN_PCIEX8A: C5
+  these specifiers are defined in
+  "include/dt-bindings/power/tegra194-powergate.h" file.
+- reg: A list of physical base address and length pairs for each set of
+  controller registers. Must contain an entry for each entry in the reg-names
+  property.
+- reg-names: Must include the following entries:
+  "appl": Controller's application logic registers
+  "atu_dma": iATU and DMA registers. This is where the iATU (internal Address
+             Translation Unit) registers of the PCIe core are made available
+             for SW access.
+  "dbi": The aperture where root port's own configuration registers are
+         available
+  "addr_space": Used to map remote RC address space
+- interrupts: A list of interrupt outputs of the controller. Must contain an
+  entry for each entry in the interrupt-names property.
+- interrupt-names: Must include the following entry:
+  "intr": The Tegra interrupt that is asserted for controller interrupts
+- clocks: Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names: Must include the following entries:
+  - core
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: Must include the following entries:
+  - apb
+  - core
+- phys: Must contain a phandle to P2U PHY for each entry in phy-names.

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 53

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+- phy-names: Must include an entry for each active lane.
+  "p2u-N": where N ranges from 0 to one less than the total number of lanes
+- nvidia,bpmp: Must contain a pair of phandle to BPMP controller node followed
+  by controller-id. Following are the controller ids for each controller.
+    0: C0
+    4: C4
+    5: C5
+- vddio-pex-ctl-supply: Regulator supply for PCIe side band signals
+- nvidia,pex-rst-gpio: Must contain a phandle to a GPIO controller followed by
+  GPIO that is being used as PERST signal
Quoted 2 lines

Why is this NVIDIA specific? Do other instantiations of the DW IP not also need a means to define which GPIO is the reset?

'reset-gpios' is used for PERST. Though in this case it's an input rather than output.

Rob

#8 lore raw

Re: [PATCH 2/6] dt-bindings: PCI: tegra: Add DT support for PCIe EP nodes in Tegra194

In reply to Vidya Sagar

On 11/29/2019 6:56 PM, Vidya Sagar wrote:

Rob, Can you please update your comments on this?

Thanks,
Vidya Sagar

Quoted 278 lines · Gustavo Pimentel
Quoted 52 lines
Quoted 49 lines · Thierry Reding
Quoted 48 lines · Vidya Sagar
Quoted 10 lines · Thierry Reding
Quoted 8 lines · Vidya Sagar

Add support for PCIe controllers that can operate in endpoint mode in Tegra194.

---
   .../bindings/pci/nvidia,tegra194-pcie-ep.txt  | 138 ++++++++++++++++++

   1 file changed, 138 insertions(+)

   create mode 100644 Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt

Quoted 5 lines

The vast majority of this is a duplication of the host mode device tree bindings. I think it'd be best to combine both and only highlight where both modes differ.

The designware-pcie.txt binding does something similar.

Ok. I'll merge this into the host mode bindings file and in that differentiate between root mode and endpoint mode.

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +5 -0
new file mode 100644
index 000000000000..4676ccf7dfa5
@@ -0,0 +1,138 @@
+NVIDIA Tegra PCIe Endpoint mode controller (Synopsys DesignWare Core based)
+
+Some of the PCIe controllers which are based on Synopsys DesignWare PCIe IP
+are dual mode i.e. they can work in root port mode or endpoint mode but one
+ at a time. Since they are based on DesignWare IP, they inherit all the common
Quoted 8 lines

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 9

Quoted 4 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +4 -0
+properties defined in designware-pcie.txt.
+
+Required properties:
+- compatible: For Tegra19x, must contain "nvidia,tegra194-pcie".

The device tree snippets that you added have "nvidia,tegra194-pcie-ep" for EP mode controllers. So either this is wrong or the DTS files are wrong.

DTS file are correct. This is a mistake in this file. I'll correct this.

Quoted 7 lines

This device tree binding describes the exact same hardware, so I don't think we necessarily need two different compatible strings. It's fairly easy to distinguish between which mode to run in by looking at which properties exist. EP mode for example is the only one that uses the "addr_space" reg entry.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Rob, do you know why a different compatible string was chosen for the EP mode? Looking at the driver, there are only a handful of differences in the programming, but most of the driver remains identical. An extra DT compatible string seems a bit exaggerated since it suggests that this is actually different hardware, where it clearly isn't.

Since all other implementations have done it this way, I just followed to be in sync with them. Even I would also like to hear from Rob on the rationale behind this.

Rob, Could you please update on this?

Quoted 215 lines
Quoted 57 lines
Quoted 49 lines
Quoted 47 lines
Quoted 36 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +34 -0
+  Tegra194: Only C0, C4 & C5 controllers are dual mode controllers.
+- power-domains: A phandle to the node that controls power to the respective
+  PCIe controller and a specifier name for the PCIe controller. Following are
+  the specifiers for the different PCIe controllers
+    TEGRA194_POWER_DOMAIN_PCIEX8B: C0
+    TEGRA194_POWER_DOMAIN_PCIEX4A: C4
+    TEGRA194_POWER_DOMAIN_PCIEX8A: C5
+  these specifiers are defined in
+  "include/dt-bindings/power/tegra194-powergate.h" file.
+- reg: A list of physical base address and length pairs for each set of
+  controller registers. Must contain an entry for each entry in the reg-names
+  property.
+- reg-names: Must include the following entries:
+  "appl": Controller's application logic registers
+  "atu_dma": iATU and DMA registers. This is where the iATU (internal Address
+             Translation Unit) registers of the PCIe core are made available
+             for SW access.
+  "dbi": The aperture where root port's own configuration registers are
+         available
+  "addr_space": Used to map remote RC address space
+- interrupts: A list of interrupt outputs of the controller. Must contain an
+  entry for each entry in the interrupt-names property.
+- interrupt-names: Must include the following entry:
+  "intr": The Tegra interrupt that is asserted for controller interrupts
+- clocks: Must contain an entry for each entry in clock-names.
+  See ../clocks/clock-bindings.txt for details.
+- clock-names: Must include the following entries:
+  - core
+- resets: Must contain an entry for each entry in reset-names.
+  See ../reset/reset.txt for details.
+- reset-names: Must include the following entries:
+  - apb
+  - core
+- phys: Must contain a phandle to P2U PHY for each entry in phy-names.

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 53

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+- phy-names: Must include an entry for each active lane.
+  "p2u-N": where N ranges from 0 to one less than the total number of lanes
+- nvidia,bpmp: Must contain a pair of phandle to BPMP controller node followed
+  by controller-id. Following are the controller ids for each controller.
+    0: C0
+    4: C4
+    5: C5
+- vddio-pex-ctl-supply: Regulator supply for PCIe side band signals
+- nvidia,pex-rst-gpio: Must contain a phandle to a GPIO controller followed by
+  GPIO that is being used as PERST signal
Quoted 2 lines

Why is this NVIDIA specific? Do other instantiations of the DW IP not also need a means to define which GPIO is the reset?

Quoted 7 lines

I'm not sure. At least I didn't find anything like this in other implementations. My understanding is that, controller handles assert/de-assert on the PERST line automatically without SW intervention. I think it is for the same reason that other implementations don't wait for the REFCLK to flow in from host to configure the IP. I think they just use some internal clock for the configuration and switch to running the core based on REFCLK as and when it is available
(i.e. whenever a de-assert is perceived on PERST line by the controller)

Quoted 7 lines

That would be somewhat surprising, though. The IP used in Tegra must be pretty close to the IP used in other SoCs, and the code that we need in pex_ep_event_pex_rst_{assert,deassert}() is pretty significant. Why the other instantiations wouldn't need something similar seems unlikely to me.

Perhaps Jingoo or Gustavo can shed some light on this.

On my current FPGA prototyping solution, I don't need to control the PERST line and it's very likely that I don't even have access to control it. I guess due to some particularity of my solution, the HW team probably has decided to wire it up directly for some unknown reason to me.

However, It seems to me that exynos, imx6, keystone, meson, al, histb, kirin, and qcom drivers controls the PERST line in spite of others driver that doesn't do it like in my prototype solution.
In the end I'd says that depends of how the IP solution of design by the HW team.

Gustavo

Quoted 134 lines

Thierry

Quoted 131 lines
Quoted 67 lines
Quoted 26 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +24 -0
+
+Optional properties:
+- pinctrl-names: A list of pinctrl state names.
+  It is mandatory for C5 controller and optional for other controllers.
+  - "default": Configures PCIe I/O for proper operation.
+- pinctrl-0: phandle for the 'default' state of pin configuration.
+  It is mandatory for C5 controller and optional for other controllers.
+- supports-clkreq: Refer to Documentation/devicetree/bindings/pci/pci.txt
+- nvidia,update-fc-fixup: This is a boolean property and needs to be present to
+    improve performance when a platform is designed in such a way that it
+    satisfies at least one of the following conditions thereby enabling root
+    port to exchange optimum number of FC (Flow Control) credits with
+    downstream devices
+    1. If C0/C4/C5 run at x1/x2 link widths (irrespective of speed and MPS)
+    2. If C0/C4/C5 operate at their respective max link widths and
+       a) speed is Gen-2 and MPS is 256B
+       b) speed is >= Gen-3 with any MPS
+- nvidia,aspm-cmrt-us: Common Mode Restore Time for proper operation of ASPM
+   to be specified in microseconds
+- nvidia,aspm-pwr-on-t-us: Power On time for proper operation of ASPM to be
+   specified in microseconds
+- nvidia,aspm-l0s-entrance-latency-us: ASPM L0s entrance latency to be
+   specified in microseconds
+

Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt line 87

Quoted 10 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +10 -0
+NOTE:- On Tegra194's P2972-0000 platform, only C5 controller can be enabled to
+operate in the endpoint mode because of the way the platform is designed.
+There is a mux that needs to be programmed to let the REFCLK from the host to
+flow into C5 controller when it operates in the endpoint mode. This mux is
+controlled by the GPIO (AA, 5) and it needs to be driven 'high'. For this to
+happen, set status of "pex-refclk-sel-high" node under "gpio@c2f0000" node to
+'okay'.
+    When any dual mode controller is made to operate in the endpoint mode,
+please make sure that its respective root port node's status is set to
+'disabled'.

This seems very brittle to me. There's no good way how we can detect such misconfigurations. If instead we only have one node describing the hardware fully, the chances of configuring things wrong (by for example enabling both the host and EP mode device tree nodes) can be reduced.

So I think instead of duplicating all of the device tree content to have both a host and an EP node for each controller, it'd be better to just have a single node and let the device tree bindings specify which changes to apply to switch into EP mode.

For example, there should be nothing wrong with specifying some of the EP-only properties (like num-ib-windows and num-ob-windows) all the time and only use them when we actually run in EP mode.

As I mentioned earlier, there are a couple of easy ways to distinguish the modes. The presence of the "addr_space" reg entry is one example, but we could also key off the nvidia,pex-rst-gpio property, since that (presumably) wouldn't be needed for host mode.

That way we can just add default, host mode entries to tegra194.dtsi and whenever somebody wants to enable EP mode, they can just override the node in the board-level DTS file, like so:

    pcie@141a0000 {
        reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */ 0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */ 0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */ 0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */ reg-names = "appl", "atu_dma", "dbi", "addr_space";

Quoted 4 lines

        nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1) GPIO_ACTIVE_LOW>; };

Thierry

I like it and fine with making these modifications also but would like to hear from Rob also on this.

- Vidya Sagar

Quoted 55 lines
Quoted 55 lines
Documentation/devicetree/bindings/pci/nvidia,tegra194-pcie-ep.txt new file +51 -0
+
+Examples:
+=========
+
+Tegra194:
+--------
+
+    pcie_ep@141a0000 {
+        compatible = "nvidia,tegra194-pcie-ep", "snps,dw-pcie-ep";
+        power-domains = <&bpmp TEGRA194_POWER_DOMAIN_PCIEX8A>;
+        reg = <0x00 0x141a0000 0x0 0x00020000   /* appl registers (128K)      */
+               0x00 0x3a040000 0x0 0x00040000   /* iATU_DMA reg space (256K)  */
+               0x00 0x3a080000 0x0 0x00040000   /* DBI reg space (256K)       */
+               0x1c 0x00000000 0x4 0x00000000>; /* Address Space (16G)        */
+        reg-names = "appl", "atu_dma", "dbi", "addr_space";
+
+        num-lanes = <8>;
+        num-ib-windows = <2>;
+        num-ob-windows = <8>;
+
+        pinctrl-names = "default";
+        pinctrl-0 = <&clkreq_c5_bi_dir_state>;
+
+        clocks = <&bpmp TEGRA194_CLK_PEX1_CORE_5>;
+        clock-names = "core";
+
+        resets = <&bpmp TEGRA194_RESET_PEX1_CORE_5_APB>,
+             <&bpmp TEGRA194_RESET_PEX1_CORE_5>;
+        reset-names = "apb", "core";
+
+        interrupts = <GIC_SPI 53 IRQ_TYPE_LEVEL_HIGH>;    /* controller interrupt */
+        interrupt-names = "intr";
+
+        nvidia,bpmp = <&bpmp 5>;
+
+        nvidia,aspm-cmrt-us = <60>;
+        nvidia,aspm-pwr-on-t-us = <20>;
+        nvidia,aspm-l0s-entrance-latency-us = <3>;
+
+        vddio-pex-ctl-supply = <&vdd_1v8ao>;
+
+        nvidia,pex-rst-gpio = <&gpio TEGRA194_MAIN_GPIO(GG, 1)
+                    GPIO_ACTIVE_LOW>;
+
+        phys = <&p2u_nvhs_0>, <&p2u_nvhs_1>, <&p2u_nvhs_2>,
+               <&p2u_nvhs_3>, <&p2u_nvhs_4>, <&p2u_nvhs_5>,
+               <&p2u_nvhs_6>, <&p2u_nvhs_7>;
+
+        phy-names = "p2u-0", "p2u-1", "p2u-2", "p2u-3", "p2u-4",
+                "p2u-5", "p2u-6", "p2u-7";
+    };
Signature · 1 line
2.17.1