PCI: dwc: Add ECAM support with iATU configuration
Subsystems (9)
Manivannan Sadhasivam
maintainerv10 cover PCI: dwc: Add ECAM support with iATU configuration
The current implementation requires iATU for every configuration space access which increases latency & cpu utilization.
Designware databook 5.20a, section 3.10.10.3 says about CFG Shift Feature, which shifts/maps the BDF (bits [31:16] of the third header DWORD, which would be matched against the Base and Limit addresses) of the incoming CfgRd0/CfgWr0 down to bits[27:12]of the translated address.
Configuring iATU in config shift mode enables ECAM feature to access the config space, which avoids iATU configuration for every config access.
Add cfg_shft_mode into struct dw_pcie_ob_atu_cfg to enable config shift mode.
As DBI comes under config space, this avoids remapping of DBI space separately. Instead, it uses the mapped config space address returned from ECAM initialization. Change the order of dw_pcie_get_resources() execution to acheive this.
Enable the ECAM feature if the config space size is equal to size required to represent number of buses in the bus range property.
ELBI registers are optional registers which are part of dwc. So move ELBI resource mapping to dwc. Also change the dtbinding and devicetree to make the elbi registers as optional one. Having ELBI as the required one is making the ecam feature complicated.
The ELBI registers falls after the DBI space, PARF_SLV_DBI_ELBI register gives us the offset from which ELBI starts. so use this offset and cfg win to map these regions instead of doing the ioremap again.
On root bus, we have only the root port. Any access other than that should not go out of the link and should return all F's. Since the iATU is configured for the buses which starts after root bus, block the transactions starting from function 1 of the root bus to the end of the root bus (i.e from dbi_base + 4kb to dbi_base + 1MB) from going outside the link through ECAM blocker through PARF registers.
---
Changes in v10:
- Moved qcom_pci_config_ecam() to qcom_pcie_host_init()
- Reworded the comment in patch 3
- Rebased on top of pci/controller/qcom
- Link to v9: https://lore.kernel.org/r/[email protected]
Changes in v9:
- Splitted the ECAM enablement change to avoid bisect hole and excluded pcie-al driver from DWC ECAM since it uses its own ECAM mechanism.
- Squashed the patches 2 and 3 as patch 2 won't work without 3.
For the rest of the history, please refer v8 changeset:
https://lore.kernel.org/linux-pci/[email protected]
---
Krishna Chaitanya Chundru (4):
PCI: dwc: Add support for ELBI resource mapping
PCI: dwc: Prepare the driver for enabling ECAM mechanism using iATU 'CFG Shift Feature'
PCI: qcom: Prepare for the DWC ECAM enablement
PCI: dwc: Support ECAM mechanism by enabling iATU 'CFG Shift Feature'
drivers/pci/controller/dwc/Kconfig | 1 + drivers/pci/controller/dwc/pci-exynos.c | 62 ++++----- drivers/pci/controller/dwc/pcie-al.c | 1 + drivers/pci/controller/dwc/pcie-designware-host.c | 148 ++++++++++++++++++++-- drivers/pci/controller/dwc/pcie-designware.c | 10 +- drivers/pci/controller/dwc/pcie-designware.h | 7 + drivers/pci/controller/dwc/pcie-qcom-ep.c | 15 +-- drivers/pci/controller/dwc/pcie-qcom.c | 84 ++++++++++-- 8 files changed, 261 insertions(+), 67 deletions(-)
---
base-commit: af8df709bf365f5583d31091280354e1ef0b201f
change-id: 20250908-controller-dwc-ecam-4c7c3136de14
Best regards,
Signature · 1 line
Manivannan Sadhasivam <[email protected]>
Manivannan Sadhasivam
maintainerPATCH v10 1/4 PCI: dwc: Add support for ELBI resource mapping
From: Krishna Chaitanya Chundru <[email protected]>
External Local Bus Interface (ELBI) is an optional register space for all DWC IPs containing the vendor specific registers. There is no need for the vendor glue drivers to fetch and map the ELBI region separately.
Hence, optionally fetch and map the resource from DT in the DWC core. This also warrants dropping the corresponding code from glue drivers. Hence, drop the ELBI resource fetch and map logic from glue drivers and convert them to use 'dw_pci::elbi_base'.
Note that the pcie-qcom-ep driver used devm_pci_remap_cfg_resource() to map the ELBI resource previously. But it was a mistake since devm_pci_remap_cfg_resource() should only be used for mapping the PCIe config space region as it maps the region as Non-Posted. As ELBI is used to hold vendor specific registers, there is no need to map the region as Non-Posted. With this conversion, the region will get mapped as normal MMIO memory.
--- drivers/pci/controller/dwc/pci-exynos.c | 62 ++++++++++++++-------------- drivers/pci/controller/dwc/pcie-designware.c | 8 ++++ drivers/pci/controller/dwc/pcie-designware.h | 1 + drivers/pci/controller/dwc/pcie-qcom-ep.c | 15 ++----- drivers/pci/controller/dwc/pcie-qcom.c | 16 ++++--- 5 files changed, 50 insertions(+), 52 deletions(-)
drivers/pci/controller/dwc/pci-exynos.c +31 -31
@@ -53,7 +53,6 @@struct exynos_pcie {struct dw_pcie pci; -void __iomem *elbi_base;struct clk_bulk_data *clks;struct phy *phy;struct regulator_bulk_data supplies[2 ];
@@ -71,73 +70,78 @@ static u32 exynos_pcie_readl(void __iomem *base, u32 reg)static void exynos_pcie_sideband_dbi_w_mode (struct exynos_pcie *ep,bool on) { +struct dw_pcie *pci = &ep->pci;u32 val; - val =exynos_pcie_readl (ep->elbi_base,PCIE_ELBI_SLV_AWMISC ); + val =exynos_pcie_readl (pci->elbi_base,PCIE_ELBI_SLV_AWMISC );if (on) val |=PCIE_ELBI_SLV_DBI_ENABLE ;else val &= ~PCIE_ELBI_SLV_DBI_ENABLE ; -exynos_pcie_writel (ep->elbi_base, val,PCIE_ELBI_SLV_AWMISC ); +exynos_pcie_writel (pci->elbi_base, val,PCIE_ELBI_SLV_AWMISC ); }static void exynos_pcie_sideband_dbi_r_mode (struct exynos_pcie *ep,bool on) { +struct dw_pcie *pci = &ep->pci;u32 val; - val =exynos_pcie_readl (ep->elbi_base,PCIE_ELBI_SLV_ARMISC ); + val =exynos_pcie_readl (pci->elbi_base,PCIE_ELBI_SLV_ARMISC );if (on) val |=PCIE_ELBI_SLV_DBI_ENABLE ;else val &= ~PCIE_ELBI_SLV_DBI_ENABLE ; -exynos_pcie_writel (ep->elbi_base, val,PCIE_ELBI_SLV_ARMISC ); +exynos_pcie_writel (pci->elbi_base, val,PCIE_ELBI_SLV_ARMISC ); }static void exynos_pcie_assert_core_reset (struct exynos_pcie *ep) { +struct dw_pcie *pci = &ep->pci;u32 val; - val =exynos_pcie_readl (ep->elbi_base,PCIE_CORE_RESET ); + val =exynos_pcie_readl (pci->elbi_base,PCIE_CORE_RESET ); val &= ~PCIE_CORE_RESET_ENABLE ; -exynos_pcie_writel (ep->elbi_base, val,PCIE_CORE_RESET ); -exynos_pcie_writel (ep->elbi_base,0 ,PCIE_STICKY_RESET ); -exynos_pcie_writel (ep->elbi_base,0 ,PCIE_NONSTICKY_RESET ); +exynos_pcie_writel (pci->elbi_base, val,PCIE_CORE_RESET ); +exynos_pcie_writel (pci->elbi_base,0 ,PCIE_STICKY_RESET ); +exynos_pcie_writel (pci->elbi_base,0 ,PCIE_NONSTICKY_RESET ); }static void exynos_pcie_deassert_core_reset (struct exynos_pcie *ep) { +struct dw_pcie *pci = &ep->pci;u32 val; - val =exynos_pcie_readl (ep->elbi_base,PCIE_CORE_RESET ); + val =exynos_pcie_readl (pci->elbi_base,PCIE_CORE_RESET ); val |=PCIE_CORE_RESET_ENABLE ; -exynos_pcie_writel (ep->elbi_base, val,PCIE_CORE_RESET ); -exynos_pcie_writel (ep->elbi_base,1 ,PCIE_STICKY_RESET ); -exynos_pcie_writel (ep->elbi_base,1 ,PCIE_NONSTICKY_RESET ); -exynos_pcie_writel (ep->elbi_base,1 ,PCIE_APP_INIT_RESET ); -exynos_pcie_writel (ep->elbi_base,0 ,PCIE_APP_INIT_RESET ); +exynos_pcie_writel (pci->elbi_base, val,PCIE_CORE_RESET ); +exynos_pcie_writel (pci->elbi_base,1 ,PCIE_STICKY_RESET ); +exynos_pcie_writel (pci->elbi_base,1 ,PCIE_NONSTICKY_RESET ); +exynos_pcie_writel (pci->elbi_base,1 ,PCIE_APP_INIT_RESET ); +exynos_pcie_writel (pci->elbi_base,0 ,PCIE_APP_INIT_RESET ); }static int exynos_pcie_start_link (struct dw_pcie *pci) { -struct exynos_pcie *ep =to_exynos_pcie (pci);u32 val; - val =exynos_pcie_readl (ep->elbi_base,PCIE_SW_WAKE ); + val =exynos_pcie_readl (pci->elbi_base,PCIE_SW_WAKE ); val &= ~PCIE_BUS_EN ; -exynos_pcie_writel (ep->elbi_base, val,PCIE_SW_WAKE ); +exynos_pcie_writel (pci->elbi_base, val,PCIE_SW_WAKE );/* assert LTSSM enable */ -exynos_pcie_writel (ep->elbi_base,PCIE_ELBI_LTSSM_ENABLE , +exynos_pcie_writel (pci->elbi_base,PCIE_ELBI_LTSSM_ENABLE ,PCIE_APP_LTSSM_ENABLE );return 0 ; }static void exynos_pcie_clear_irq_pulse (struct exynos_pcie *ep) { -u32 val =exynos_pcie_readl (ep->elbi_base,PCIE_IRQ_PULSE ); +struct dw_pcie *pci = &ep->pci; -exynos_pcie_writel (ep->elbi_base, val,PCIE_IRQ_PULSE ); +u32 val =exynos_pcie_readl (pci->elbi_base,PCIE_IRQ_PULSE ); + +exynos_pcie_writel (pci->elbi_base, val,PCIE_IRQ_PULSE ); }static irqreturn_t exynos_pcie_irq_handler (int irq,void *arg)
@@ -150,12 +154,14 @@ static irqreturn_t exynos_pcie_irq_handler(int irq, void *arg)static void exynos_pcie_enable_irq_pulse (struct exynos_pcie *ep) { +struct dw_pcie *pci = &ep->pci; +u32 val =IRQ_INTA_ASSERT |IRQ_INTB_ASSERT |IRQ_INTC_ASSERT |IRQ_INTD_ASSERT ; -exynos_pcie_writel (ep->elbi_base, val,PCIE_IRQ_EN_PULSE ); -exynos_pcie_writel (ep->elbi_base,0 ,PCIE_IRQ_EN_LEVEL ); -exynos_pcie_writel (ep->elbi_base,0 ,PCIE_IRQ_EN_SPECIAL ); +exynos_pcie_writel (pci->elbi_base, val,PCIE_IRQ_EN_PULSE ); +exynos_pcie_writel (pci->elbi_base,0 ,PCIE_IRQ_EN_LEVEL ); +exynos_pcie_writel (pci->elbi_base,0 ,PCIE_IRQ_EN_SPECIAL ); } static u32 exynos_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base,
@@ -211,8 +217,7 @@ static struct pci_ops exynos_pci_ops = {static bool exynos_pcie_link_up (struct dw_pcie *pci) { -struct exynos_pcie *ep =to_exynos_pcie (pci); -u32 val =exynos_pcie_readl (ep->elbi_base,PCIE_ELBI_RDLH_LINKUP ); +u32 val =exynos_pcie_readl (pci->elbi_base,PCIE_ELBI_RDLH_LINKUP );return val &PCIE_ELBI_XMLH_LINKUP ; }
@@ -295,11 +300,6 @@ static int exynos_pcie_probe(struct platform_device *pdev)if (IS_ERR (ep->phy))return PTR_ERR (ep->phy); -/* External Local Bus interface (ELBI) registers */ - ep->elbi_base =devm_platform_ioremap_resource_byname (pdev,"elbi" ); -if (IS_ERR (ep->elbi_base)) -return PTR_ERR (ep->elbi_base); - ret =devm_clk_bulk_get_all_enabled (dev, &ep->clks);if (ret <0 )return ret;
drivers/pci/controller/dwc/pcie-designware.c +8 -0
@@ -167,6 +167,14 @@ int dw_pcie_get_resources(struct dw_pcie *pci) } } +/* ELBI is an optional resource */ + res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"elbi" ); +if (res) { + pci->elbi_base =devm_ioremap_resource (pci->dev, res); +if (IS_ERR (pci->elbi_base)) +return PTR_ERR (pci->elbi_base); + } +/* LLDD is supposed to manually switch the clocks and resets state */ if (dw_pcie_cap_is (pci,REQ_RES )) { ret =dw_pcie_get_clocks (pci);
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -491,6 +491,7 @@ struct dw_pcie {resource_size_t dbi_phys_addr;void __iomem *dbi_base2;void __iomem *atu_base; +void __iomem *elbi_base;resource_size_t atu_phys_addr;size_t atu_size;resource_size_t parent_bus_offset;
drivers/pci/controller/dwc/pcie-qcom-ep.c +3 -12
@@ -179,7 +179,6 @@ struct qcom_pcie_ep_cfg {* struct qcom_pcie_ep - Qualcomm PCIe Endpoint Controller * @pci: Designware PCIe controller struct * @parf: Qualcomm PCIe specific PARF register base -* @elbi: Designware PCIe specific ELBI register base * @mmio: MMIO register base * @perst_map: PERST regmap * @mmio_res: MMIO region resource
@@ -202,7 +201,6 @@ struct qcom_pcie_ep {struct dw_pcie pci;void __iomem *parf; -void __iomem *elbi;void __iomem *mmio;struct regmap *perst_map;struct resource *mmio_res;
@@ -267,10 +265,9 @@ static void qcom_pcie_ep_configure_tcsr(struct qcom_pcie_ep *pcie_ep)static bool qcom_pcie_dw_link_up (struct dw_pcie *pci) { -struct qcom_pcie_ep *pcie_ep =to_pcie_ep (pci);u32 reg; - reg =readl_relaxed (pcie_ep->elbi +ELBI_SYS_STTS ); + reg =readl_relaxed (pci->elbi_base +ELBI_SYS_STTS );return reg &XMLH_LINK_UP ; }
@@ -294,16 +291,15 @@ static void qcom_pcie_dw_stop_link(struct dw_pcie *pci)static void qcom_pcie_dw_write_dbi2 (struct dw_pcie *pci,void __iomem *base,u32 reg,size_t size,u32 val) { -struct qcom_pcie_ep *pcie_ep =to_pcie_ep (pci);int ret; -writel (1 , pcie_ep->elbi +ELBI_CS2_ENABLE ); +writel (1 , pci->elbi_base +ELBI_CS2_ENABLE ); ret =dw_pcie_write (pci->dbi_base2 + reg, size, val);if (ret)dev_err (pci->dev,"Failed to write DBI2 register (0x%x): %d\n" , reg, ret); -writel (0 , pcie_ep->elbi +ELBI_CS2_ENABLE ); +writel (0 , pci->elbi_base +ELBI_CS2_ENABLE ); }static void qcom_pcie_ep_icc_update (struct qcom_pcie_ep *pcie_ep)
@@ -583,11 +579,6 @@ static int qcom_pcie_ep_get_io_resources(struct platform_device *pdev,return PTR_ERR (pci->dbi_base); pci->dbi_base2 = pci->dbi_base; - res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"elbi" ); - pcie_ep->elbi =devm_pci_remap_cfg_resource (dev, res); -if (IS_ERR (pcie_ep->elbi)) -return PTR_ERR (pcie_ep->elbi); - pcie_ep->mmio_res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"mmio" );if (!pcie_ep->mmio_res) {
drivers/pci/controller/dwc/pcie-qcom.c +7 -9
@@ -276,7 +276,6 @@ struct qcom_pcie_port {struct qcom_pcie {struct dw_pcie *pci;void __iomem *parf;/* DT parf */ -void __iomem *elbi;/* DT elbi */ void __iomem *mhi;union qcom_pcie_resources res;struct icc_path *icc_mem;
@@ -409,12 +408,17 @@ static void qcom_pcie_configure_dbi_atu_base(struct qcom_pcie *pcie)static void qcom_pcie_2_1_0_ltssm_enable (struct qcom_pcie *pcie) { +struct dw_pcie *pci = pcie->pci;u32 val; +if (!pci->elbi_base) { +dev_err (pci->dev,"ELBI is not present\n" ); +return ; + }/* enable link training */ - val =readl (pcie->elbi +ELBI_SYS_CTRL ); + val =readl (pci->elbi_base +ELBI_SYS_CTRL ); val |=ELBI_SYS_CTRL_LT_ENABLE ; -writel (val, pcie->elbi +ELBI_SYS_CTRL ); +writel (val, pci->elbi_base +ELBI_SYS_CTRL ); }static int qcom_pcie_get_resources_2_1_0 (struct qcom_pcie *pcie)
@@ -1847,12 +1851,6 @@ static int qcom_pcie_probe(struct platform_device *pdev) goto err_pm_runtime_put; } - pcie->elbi =devm_platform_ioremap_resource_byname (pdev,"elbi" ); -if (IS_ERR (pcie->elbi)) { - ret =PTR_ERR (pcie->elbi); - goto err_pm_runtime_put; - } -/* MHI region is optional */ res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"mhi" );if (res) {
Signature · 1 line
2.48.1
Manivannan Sadhasivam
maintainerPATCH v10 2/4 PCI: dwc: Prepare the driver for enabling ECAM mechanism using iATU 'CFG Shift Feature'
In reply to Manivannan SadhasivamFrom: Krishna Chaitanya Chundru <[email protected]>
In order to enable PCIe ECAM mechanism in DWC driver as per the 'CFG Shift Feature' documented in Designware databook r5.20a, sec 3.10.10.3, prepare the driver to handle the one time iATU setup and creating ECAM window.
--- drivers/pci/controller/dwc/Kconfig | 1 + drivers/pci/controller/dwc/pcie-designware-host.c | 116 +++++++++++++++++++--- drivers/pci/controller/dwc/pcie-designware.c | 2 +- drivers/pci/controller/dwc/pcie-designware.h | 5 + 4 files changed, 109 insertions(+), 15 deletions(-)
drivers/pci/controller/dwc/Kconfig +1 -0
@@ -20,6 +20,7 @@ config PCIE_DW_HOST bool select PCIE_DW select IRQ_MSI_LIB + select PCI_HOST_COMMON config PCIE_DW_EP bool
drivers/pci/controller/dwc/pcie-designware-host.c +102 -14
167 lines not on this page · raw message
drivers/pci/controller/dwc/pcie-designware.c +1 -1
@@ -575,7 +575,7 @@ int dw_pcie_prog_outbound_atu(struct dw_pcie *pci, val =dw_pcie_enable_ecrc (val);dw_pcie_writel_atu_ob (pci, atu->index,PCIE_ATU_REGION_CTRL1 , val); - val =PCIE_ATU_ENABLE ; + val =PCIE_ATU_ENABLE | atu->ctrl2;if (atu->type ==PCIE_ATU_TYPE_MSG ) {/* The data-less messages only for now */ val |=PCIE_ATU_INHIBIT_PAYLOAD | atu->code;
drivers/pci/controller/dwc/pcie-designware.h +5 -0
@@ -20,6 +20,7 @@#include <linux/irq.h> #include <linux/msi.h> #include <linux/pci.h> +#include <linux/pci-ecam.h> #include <linux/reset.h> #include <linux/pci-epc.h>
@@ -168,6 +169,7 @@#define PCIE_ATU_REGION_CTRL2 0x004#define PCIE_ATU_ENABLE BIT(31)#define PCIE_ATU_BAR_MODE_ENABLE BIT(30) +#define PCIE_ATU_CFG_SHIFT_MODE_ENABLE BIT(28)#define PCIE_ATU_INHIBIT_PAYLOAD BIT(22)#define PCIE_ATU_FUNC_NUM_MATCH_EN BIT(19)#define PCIE_ATU_LOWER_BASE 0x008
@@ -386,6 +388,7 @@ struct dw_pcie_ob_atu_cfg {u8 func_no;u8 code;u8 routing; +u32 ctrl2;u64 parent_bus_addr;u64 pci_addr;u64 size;
@@ -424,6 +427,8 @@ struct dw_pcie_rp {struct resource *msg_res;bool use_linkup_irq;struct pci_eq_presets presets; +struct pci_config_window *cfg; +bool ecam_enabled; };struct dw_pcie_ep_ops {
Signature · 1 line
2.48.1
Manivannan Sadhasivam
maintainerPATCH v10 3/4 PCI: qcom: Prepare for the DWC ECAM enablement
In reply to Manivannan SadhasivamFrom: Krishna Chaitanya Chundru <[email protected]>
To support the DWC ECAM mechanism, prepare the driver by performing below configurations:
1. Since the ELBI region will be covered by the ECAM 'config' space, override the 'elbi_base' with the address derived from 'dbi_base' and the offset from PARF_SLV_DBI_ELBI register.
2. Block the transactions from the host bridge to devices other than Root Port on the root bus to return all F's. This is required when the 'CFG Shift Feature' of iATU is enabled.
--- drivers/pci/controller/dwc/pcie-qcom.c | 68 ++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
drivers/pci/controller/dwc/pcie-qcom.c +68 -0
@@ -55,6 +55,7 @@#define PARF_AXI_MSTR_WR_ADDR_HALT_V2 0x1a8#define PARF_Q2A_FLUSH 0x1ac#define PARF_LTSSM 0x1b0 +#define PARF_SLV_DBI_ELBI 0x1b4#define PARF_INT_ALL_STATUS 0x224#define PARF_INT_ALL_CLEAR 0x228#define PARF_INT_ALL_MASK 0x22c
@@ -64,6 +65,16 @@#define PARF_DBI_BASE_ADDR_V2_HI 0x354#define PARF_SLV_ADDR_SPACE_SIZE_V2 0x358#define PARF_SLV_ADDR_SPACE_SIZE_V2_HI 0x35c +#define PARF_BLOCK_SLV_AXI_WR_BASE 0x360 +#define PARF_BLOCK_SLV_AXI_WR_BASE_HI 0x364 +#define PARF_BLOCK_SLV_AXI_WR_LIMIT 0x368 +#define PARF_BLOCK_SLV_AXI_WR_LIMIT_HI 0x36c +#define PARF_BLOCK_SLV_AXI_RD_BASE 0x370 +#define PARF_BLOCK_SLV_AXI_RD_BASE_HI 0x374 +#define PARF_BLOCK_SLV_AXI_RD_LIMIT 0x378 +#define PARF_BLOCK_SLV_AXI_RD_LIMIT_HI 0x37c +#define PARF_ECAM_BASE 0x380 +#define PARF_ECAM_BASE_HI 0x384#define PARF_NO_SNOOP_OVERRIDE 0x3d4#define PARF_ATU_BASE_ADDR 0x634#define PARF_ATU_BASE_ADDR_HI 0x638
@@ -87,6 +98,7 @@/* PARF_SYS_CTRL register fields */ #define MAC_PHY_POWERDOWN_IN_P2_D_MUX_EN BIT(29) +#define PCIE_ECAM_BLOCKER_EN BIT(26)#define MST_WAKEUP_EN BIT(13)#define SLV_WAKEUP_EN BIT(12)#define MSTR_ACLK_CGC_DIS BIT(10)
@@ -134,6 +146,9 @@/* PARF_LTSSM register fields */ #define LTSSM_EN BIT(8) +/* PARF_SLV_DBI_ELBI */ +#define SLV_DBI_ELBI_ADDR_BASE GENMASK(11, 0) +/* PARF_INT_ALL_{STATUS/CLEAR/MASK} register fields */ #define PARF_INT_ALL_LINK_UP BIT(13)#define PARF_INT_MSI_DEV_0_7 GENMASK(30, 23)
@@ -312,6 +327,47 @@ static void qcom_ep_reset_deassert(struct qcom_pcie *pcie)qcom_perst_assert (pcie, false); } +static void qcom_pci_config_ecam (struct dw_pcie_rp *pp) +{ +struct dw_pcie *pci =to_dw_pcie_from_pp (pp); +struct qcom_pcie *pcie =to_qcom_pcie (pci); +u64 addr, addr_end; +u32 val; + +writel_relaxed (lower_32_bits (pci->dbi_phys_addr), pcie->parf +PARF_ECAM_BASE ); +writel_relaxed (upper_32_bits (pci->dbi_phys_addr), pcie->parf +PARF_ECAM_BASE_HI ); + +/* +* The only device on the root bus is a single Root Port. If we try to +* access any devices other than Device/Function 00.0 on Bus 0, the TLP +* will go outside of the controller to the PCI bus. But with CFG Shift +* Feature (ECAM) enabled in iATU, there is no guarantee that the +* response is going to be all F's. Hence, to make sure that the +* requester gets all F's response for accesses other than the Root +* Port, configure iATU to block the transactions starting from +* function 1 of the root bus to the end of the root bus (i.e., from +* dbi_base + 4KB to dbi_base + 1MB). +*/ + addr = pci->dbi_phys_addr +SZ_4K ; +writel_relaxed (lower_32_bits (addr), pcie->parf +PARF_BLOCK_SLV_AXI_WR_BASE ); +writel_relaxed (upper_32_bits (addr), pcie->parf +PARF_BLOCK_SLV_AXI_WR_BASE_HI ); + +writel_relaxed (lower_32_bits (addr), pcie->parf +PARF_BLOCK_SLV_AXI_RD_BASE ); +writel_relaxed (upper_32_bits (addr), pcie->parf +PARF_BLOCK_SLV_AXI_RD_BASE_HI ); + + addr_end = pci->dbi_phys_addr +SZ_1M -1 ; + +writel_relaxed (lower_32_bits (addr_end), pcie->parf +PARF_BLOCK_SLV_AXI_WR_LIMIT ); +writel_relaxed (upper_32_bits (addr_end), pcie->parf +PARF_BLOCK_SLV_AXI_WR_LIMIT_HI ); + +writel_relaxed (lower_32_bits (addr_end), pcie->parf +PARF_BLOCK_SLV_AXI_RD_LIMIT ); +writel_relaxed (upper_32_bits (addr_end), pcie->parf +PARF_BLOCK_SLV_AXI_RD_LIMIT_HI ); + + val =readl_relaxed (pcie->parf +PARF_SYS_CTRL ); + val |=PCIE_ECAM_BLOCKER_EN ; +writel_relaxed (val, pcie->parf +PARF_SYS_CTRL ); +} +static int qcom_pcie_start_link (struct dw_pcie *pci) {struct qcom_pcie *pcie =to_qcom_pcie (pci);
@@ -1284,6 +1340,7 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp) {struct dw_pcie *pci =to_dw_pcie_from_pp (pp);struct qcom_pcie *pcie =to_qcom_pcie (pci); +u16 offset;int ret;qcom_ep_reset_assert (pcie);
@@ -1292,6 +1349,17 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)if (ret)return ret; +if (pp->ecam_enabled) { +/* +* Override ELBI when ECAM is enabled, as when ECAM is enabled, +* ELBI moves under the 'config' space. +*/ + offset =FIELD_GET (SLV_DBI_ELBI_ADDR_BASE ,readl (pcie->parf +PARF_SLV_DBI_ELBI )); + pci->elbi_base = pci->dbi_base + offset; + +qcom_pci_config_ecam (pp); + } + ret =qcom_pcie_phy_power_on (pcie);if (ret) goto err_deinit;
Signature · 1 line
2.48.1
Manivannan Sadhasivam
maintainerPATCH v10 4/4 PCI: dwc: Support ECAM mechanism by enabling iATU 'CFG Shift Feature'
In reply to Manivannan SadhasivamFrom: Krishna Chaitanya Chundru <[email protected]>
Designware databook r5.20a, sec 3.10.10.3 documents the 'CFG Shift Feature' of the internal Address Translation Unit (iATU). When this feature is enabled, it shifts/maps the BDF contained in the bits [27:12] of the target address in MEM TLP to become BDF of the CFG TLP. This essentially implements the Enhanced Configuration Address Mapping (ECAM) mechanism as defined in PCIe r6.0, sec 7.2.2.
Currently, the driver is not making use of this CFG shift feature, thereby creating the iATU outbound map for each config access to the devices, causing latency and wasting CPU cycles.
So to avoid this, configure the controller to enable CFG shift feature by enabling the 'CFG Shift' bit of the 'iATU Control 2 Register'.
As a result of enabling CFG shift (ECAM), there is longer a need to map the DBI register space separately as the DBI region falls under the 'config' space used for ECAM (as DBI is used to access the Root Port).
For enabling ECAM using CFG shift, the platform has to satisfy following requirements:
1. Size of the 'config' memory space to be used as ECAM memory should be able to accommodate the number of buses defined in the 'bus-range' property of the host bridge DT node.
2. The 'config' memory space should be 256 MiB aligned. This requirement comes from PCIe r6.0, sec 7.2.2, which says the base address of ECAM memory should be aligned to a 2^(n+20) byte address boundary. For the DWC cores, n is 8, so this results in 2^28 byte alignment requirement.
It should be noted that some DWC vendor glue drivers like pcie-al may use their own ECAM mechanism. For those controllers, set 'dw_pcie_rp::native_ecam' flag and skip enabling the CFG Shift feature in the DWC core.
--- drivers/pci/controller/dwc/pcie-al.c | 1 + drivers/pci/controller/dwc/pcie-designware-host.c | 32 +++++++++++++++++++++++ drivers/pci/controller/dwc/pcie-designware.h | 1 + 3 files changed, 34 insertions(+)
drivers/pci/controller/dwc/pcie-al.c +1 -0
@@ -352,6 +352,7 @@ static int al_pcie_probe(struct platform_device *pdev)return -ENOENT ; } al_pcie->ecam_size =resource_size (ecam_res); + pci->pp.native_ecam = true; controller_res =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"controller" );
drivers/pci/controller/dwc/pcie-designware-host.c +32 -0
@@ -8,6 +8,7 @@* Author: Jingoo Han <[email protected]> */ +#include <linux/align.h> #include <linux/iopoll.h> #include <linux/irqchip/chained_irq.h> #include <linux/irqchip/irq-msi-lib.h>
@@ -32,6 +33,8 @@ static struct pci_ops dw_child_pcie_ops; MSI_FLAG_PCI_MSIX | \ MSI_GENERIC_FLAGS_MASK) +#define IS_256MB_ALIGNED (x) IS_ALIGNED(x, SZ_256M) +static const struct msi_parent_ops dw_pcie_msi_parent_ops = { .required_flags =DW_PCIE_MSI_FLAGS_REQUIRED , .supported_flags =DW_PCIE_MSI_FLAGS_SUPPORTED ,
@@ -474,6 +477,34 @@ static int dw_pcie_create_ecam_window(struct dw_pcie_rp *pp, struct resource *rereturn 0 ; } +static bool dw_pcie_ecam_enabled (struct dw_pcie_rp *pp,struct resource *config_res) +{ +struct resource *bus_range; +u64 nr_buses; + +/* Vendor glue drivers may implement their own ECAM mechanism */ +if (pp->native_ecam) +return false; + +/* +* PCIe spec r6.0, sec 7.2.2 mandates the base address used for ECAM to +* be aligned on a 2^(n+20) byte boundary, where n is the number of bits +* used for representing 'bus' in BDF. Since the DWC cores always use 8 +* bits for representing 'bus', the base address has to be aligned to +* 2^28 byte boundary, which is 256 MiB. +*/ +if (!IS_256MB_ALIGNED (config_res->start)) +return false; + + bus_range =resource_list_first_type (&pp->bridge->windows,IORESOURCE_BUS )->res; +if (!bus_range) +return false; + + nr_buses =resource_size (config_res) >>PCIE_ECAM_BUS_SHIFT ; + +return nr_buses >=resource_size (bus_range); +} +static int dw_pcie_host_get_resources (struct dw_pcie_rp *pp) {struct dw_pcie *pci =to_dw_pcie_from_pp (pp);
@@ -492,6 +523,7 @@ static int dw_pcie_host_get_resources(struct dw_pcie_rp *pp) pp->cfg0_size =resource_size (res); pp->cfg0_base = res->start; + pp->ecam_enabled =dw_pcie_ecam_enabled (pp, res);if (pp->ecam_enabled) { ret =dw_pcie_create_ecam_window (pp, res);if (ret)
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -429,6 +429,7 @@ struct dw_pcie_rp {struct pci_eq_presets presets;struct pci_config_window *cfg;bool ecam_enabled; +bool native_ecam; };struct dw_pcie_ep_ops {
Signature · 1 line
2.48.1
Quoted 9 lines · Manivannan Sadhasivam
The current implementation requires iATU for every configuration space access which increases latency & cpu utilization.
Designware databook 5.20a, section 3.10.10.3 says about CFG Shift Feature, which shifts/maps the BDF (bits [31:16] of the third header DWORD, which would be matched against the Base and Limit addresses) of the incoming CfgRd0/CfgWr0 down to bits[27:12]of the translated address.
[...]
Applied to pci/controller/qcom, thanks!
[1/4] PCI: dwc: Add support for ELBI resource mapping
commit: c96992a24beca0768c1c42ad25d6a466e17ec70f
[2/4] PCI: dwc: Prepare the driver for enabling ECAM mechanism using iATU 'CFG Shift Feature'
commit: f6fd357f7afbeb34a633e5688a23b9d7eb49d558
[3/4] PCI: qcom: Prepare for the DWC ECAM enablement
commit: 4660e50cf81800f82eeecf743ad1e3e97ab72190
[4/4] PCI: dwc: Support ECAM mechanism by enabling iATU 'CFG Shift Feature'
commit: 0da48c5b2fa731b21bc523c82d927399a1e508b0Best regards,
Signature · 1 line
Manivannan Sadhasivam <[email protected]>