Skip to contentSkip to conversation

APM X-Gene PCIe controller

PATCH Superseded Tanmay Inamdar 3 participants 14 messages Mar 6, 2014 – Mar 15, 2014

Subsystems (3)

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v4 cover APM X-Gene PCIe controller

This patch adds support for AppliedMicro X-Gene PCIe host controller. The driver is tested on X-Gene platform with different gen1/2/3 PCIe endpoint cards.

X-Gene PCIe controller driver has depedency on the pcie arm64 arch support. Liviu Dudau from ARM has sent a patch set for pcie arm64 arch support and support for creating generic pcie bridge from device tree. Liviu's patches are available here
1. https://lkml.org/lkml/2014/3/5/179
2. https://lkml.org/lkml/2014/3/5/41

If someone wishes to test PCIe on X-Gene with this patch set, above mentioned patches from Liviu must be applied before the patches in this patch set.

changes since V3:
1. remove 'struct hw_pci' and supporting ops in hw_pci
2. add code to create the host bridge from dts
3. add code to scan the the host bridge
4. modify outbound windows setup function to get resource information from 'bridge->windows'
5. add compatible string in pcie dts node with current X-Gene SOC name.

changes since V2:
1. redefined each PCI port in different PCI domain correctly.
2. removed setup_lane and setup_link functions from driver.
3. removed scan_bus wrapper and set_primary_bus hack.
4. added pci_ioremap_io for io resources.

changes since V1:
1. added PCI domain support
2. reading cpu and pci addresses from device tree to configure regions.
3. got rid of unnecessary wrappers for readl and writel.
4. got rid of endpoint configuration code.
5. added 'dma-ranges' property support to read inbound region configuration.
6. renamed host driver file to 'pci-xgene.c' from 'pcie-xgene.c'
7. dropped 'clock-names' property from bindings
8. added comments whereever requested.

Tanmay Inamdar (4):
pci: APM X-Gene PCIe controller driver
arm64: dts: APM X-Gene PCIe device tree nodes
dt-bindings: pci: xgene pcie device tree bindings
MAINTAINERS: entry for APM X-Gene PCIe host driver

 .../devicetree/bindings/pci/xgene-pci.txt          |   52 ++
 MAINTAINERS                                        |    7 +
 arch/arm64/boot/dts/apm-mustang.dts                |    8 +
 arch/arm64/boot/dts/apm-storm.dtsi                 |  155 ++++
 drivers/pci/host/Kconfig                           |   10 +
 drivers/pci/host/Makefile                          |    1 +
 drivers/pci/host/pci-xgene.c                       |  739 ++++++++++++++++++++
 7 files changed, 972 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/xgene-pci.txt
 create mode 100644 drivers/pci/host/pci-xgene.c
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v4 1/4 pci: APM X-Gene PCIe controller driver

This patch adds the AppliedMicro X-Gene SOC PCIe controller driver. X-Gene PCIe controller supports maxmum upto 8 lanes and GEN3 speed. X-Gene SOC supports maximum 5 PCIe ports.

---
 drivers/pci/host/Kconfig     |   10 +
 drivers/pci/host/Makefile    |    1 +
 drivers/pci/host/pci-xgene.c |  739 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 750 insertions(+)
 create mode 100644 drivers/pci/host/pci-xgene.c
drivers/pci/host/Kconfig +10 -0
index 47d46c6..19ce97d 100644
@@ -33,4 +33,14 @@ config PCI_RCAR_GEN2
 	  There are 3 internal PCI controllers available with a single
 	  built-in EHCI/OHCI host controller present on each one.
 
+config PCI_XGENE
+	bool "X-Gene PCIe controller"
+	depends on ARCH_XGENE
+	depends on OF
+	select PCIEPORTBUS
+	help
+	  Say Y here if you want internal PCI support on APM X-Gene SoC.
+	  There are 5 internal PCIe ports available. Each port is GEN3 capable
+	  and have varied lanes from x1 to x8.
+
 endmenu
drivers/pci/host/Makefile +1 -0
index 13fb333..34c7c36 100644
@@ -4,3 +4,4 @@ obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
 obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
 obj-$(CONFIG_PCI_TEGRA) += pci-tegra.o
 obj-$(CONFIG_PCI_RCAR_GEN2) += pci-rcar-gen2.o
+obj-$(CONFIG_PCI_XGENE) += pci-xgene.o
drivers/pci/host/pci-xgene.c new file +739 -0

739 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v4 1/4] pci: APM X-Gene PCIe controller driver

Quoted 1 line · Tanmay Inamdar

Hi Tanmay Inamdar,

I added some minor comments. :-)

Quoted 2 lines

This patch adds the AppliedMicro X-Gene SOC PCIe controller driver. X-Gene PCIe controller supports maxmum upto 8 lanes and GEN3 speed.

Would you fix the followings?

s/maxmum/maximum
s/upto/up to

Quoted 9 lines

X-Gene SOC supports maximum 5 PCIe ports.

---
 drivers/pci/host/Kconfig     |   10 +
 drivers/pci/host/Makefile    |    1 +
 drivers/pci/host/pci-xgene.c |  739 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 750 insertions(+)
 create mode 100644 drivers/pci/host/pci-xgene.c

[.....]

Quoted 2 lines
drivers/pci/host/pci-xgene.c new file +0 -0

[.....]

Quoted 15 lines
drivers/pci/host/pci-xgene.c new file +15 -0
+
+static int xgene_pcie_parse_map_dma_ranges(struct xgene_pcie_port *port)
+{
+	struct device_node *np = port->node;
+	struct of_pci_range range;
+	struct of_pci_range_parser parser;
+	struct device *dev = port->dev;
+	u8 ib_reg_mask = 0;
+
+	if (pci_dma_range_parser_init(&parser, np)) {
+		dev_err(dev, "missing dma-ranges property\n");
+		return -EINVAL;
+	}
+
+	/* Get the dma-ranges from DT */

drivers/pci/host/pci-xgene.c line 672

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+	for_each_of_pci_range(&parser, &range) {
+		u64 end = range.cpu_addr + range.size - 1;
+		dev_dbg(port->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
+			range.flags, range.cpu_addr, end, range.pci_addr);
+		xgene_pcie_setup_ib_reg(port, &range, &ib_reg_mask);
+	}
+	return 0;
+}
+
+static int __init xgene_pcie_probe_bridge(struct platform_device *pdev)

Please, remove '__init' marker in order to fix section mismatch warning.

Quoted 40 lines
drivers/pci/host/pci-xgene.c new file +40 -0
+{
+	struct device_node *np = of_node_get(pdev->dev.of_node);
+	struct xgene_pcie_port *port;
+	struct pci_host_bridge *bridge;
+	resource_size_t lastbus;
+	u32 lanes = 0, speed = 0;
+	u64 cfg_addr = 0;
+	int ret;
+
+	port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
+	if (!port)
+		return -ENOMEM;
+	port->node = np;
+	port->dev = &pdev->dev;
+
+	ret = xgene_pcie_map_reg(port, pdev, &cfg_addr);
+	if (ret)
+		return ret;
+
+	ret = xgene_pcie_init_port(port);
+	if (ret)
+		return ret;
+	xgene_pcie_program_core(port->csr_base);
+	xgene_pcie_setup_root_complex(port);
+
+	bridge = of_create_pci_host_bridge(&pdev->dev, &xgene_pcie_ops, port);
+	if (IS_ERR_OR_NULL(bridge))
+		return PTR_ERR(bridge);
+
+	ret = xgene_pcie_map_ranges(port, bridge, cfg_addr);
+	if (ret)
+		return ret;
+
+	ret = xgene_pcie_parse_map_dma_ranges(port);
+	if (ret)
+		return ret;
+
+	xgene_pcie_poll_linkup(port, &lanes, &speed);
+	if (!port->link_up)
+		dev_info(port->dev, "(rc) link down\n");

drivers/pci/host/pci-xgene.c line 722

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+	else
+		dev_info(port->dev, "(rc) x%d gen-%d link up\n",
+				lanes, speed + 1);
+	platform_set_drvdata(pdev, port);
+	lastbus = pci_rescan_bus(bridge->bus);
+	pci_bus_update_busn_res_end(bridge->bus, lastbus);
+	return 0;
+}
+
+static const struct of_device_id xgene_pcie_match_table[] __initconst = {

Please, remove '__initconst' marker in order to fix section mismatch warning.

drivers/pci/host/pci-xgene.c line 732

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+	{.compatible = "apm,xgene-pcie",},
+	{},
+};
+
+static struct platform_driver xgene_pcie_driver = {
+	.driver = {
+		   .name = "xgene-pcie",
+		   .owner = THIS_MODULE,
+		   .of_match_table = of_match_ptr(xgene_pcie_match_table),
+		  },

Please fix this indent style, as below:

+ },

See you later. :-)

Best regards,
Jingoo Han

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +7 -1
+	.probe = xgene_pcie_probe_bridge,
+};
+module_platform_driver(xgene_pcie_driver);
+
+MODULE_AUTHOR("Tanmay Inamdar <[email protected]>");
+MODULE_DESCRIPTION("APM X-Gene PCIe driver");
+MODULE_LICENSE("GPL v2");
--

1.7.9.5

#3 lore raw

Re: [PATCH v4 1/4] pci: APM X-Gene PCIe controller driver

Thanks for reviewing and the comments. I will surely include them in next version.

-Tanmay

Quoted 145 lines · Jingoo Han
Quoted 1 line · Tanmay Inamdar

Hi Tanmay Inamdar,

I added some minor comments. :-)

Quoted 2 lines

This patch adds the AppliedMicro X-Gene SOC PCIe controller driver. X-Gene PCIe controller supports maxmum upto 8 lanes and GEN3 speed.

Would you fix the followings?

s/maxmum/maximum
s/upto/up to

Quoted 9 lines

X-Gene SOC supports maximum 5 PCIe ports.

---
 drivers/pci/host/Kconfig     |   10 +
 drivers/pci/host/Makefile    |    1 +
 drivers/pci/host/pci-xgene.c |  739 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 750 insertions(+)
 create mode 100644 drivers/pci/host/pci-xgene.c

[.....]

Quoted 2 lines
drivers/pci/host/pci-xgene.c new file +0 -0

[.....]

Quoted 15 lines
drivers/pci/host/pci-xgene.c new file +15 -0
+
+static int xgene_pcie_parse_map_dma_ranges(struct xgene_pcie_port *port)
+{
+     struct device_node *np = port->node;
+     struct of_pci_range range;
+     struct of_pci_range_parser parser;
+     struct device *dev = port->dev;
+     u8 ib_reg_mask = 0;
+
+     if (pci_dma_range_parser_init(&parser, np)) {
+             dev_err(dev, "missing dma-ranges property\n");
+             return -EINVAL;
+     }
+
+     /* Get the dma-ranges from DT */

drivers/pci/host/pci-xgene.c line 672

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     for_each_of_pci_range(&parser, &range) {
+             u64 end = range.cpu_addr + range.size - 1;
+             dev_dbg(port->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
+                     range.flags, range.cpu_addr, end, range.pci_addr);
+             xgene_pcie_setup_ib_reg(port, &range, &ib_reg_mask);
+     }
+     return 0;
+}
+
+static int __init xgene_pcie_probe_bridge(struct platform_device *pdev)

Please, remove '__init' marker in order to fix section mismatch warning.

Quoted 40 lines
drivers/pci/host/pci-xgene.c new file +40 -0
+{
+     struct device_node *np = of_node_get(pdev->dev.of_node);
+     struct xgene_pcie_port *port;
+     struct pci_host_bridge *bridge;
+     resource_size_t lastbus;
+     u32 lanes = 0, speed = 0;
+     u64 cfg_addr = 0;
+     int ret;
+
+     port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
+     if (!port)
+             return -ENOMEM;
+     port->node = np;
+     port->dev = &pdev->dev;
+
+     ret = xgene_pcie_map_reg(port, pdev, &cfg_addr);
+     if (ret)
+             return ret;
+
+     ret = xgene_pcie_init_port(port);
+     if (ret)
+             return ret;
+     xgene_pcie_program_core(port->csr_base);
+     xgene_pcie_setup_root_complex(port);
+
+     bridge = of_create_pci_host_bridge(&pdev->dev, &xgene_pcie_ops, port);
+     if (IS_ERR_OR_NULL(bridge))
+             return PTR_ERR(bridge);
+
+     ret = xgene_pcie_map_ranges(port, bridge, cfg_addr);
+     if (ret)
+             return ret;
+
+     ret = xgene_pcie_parse_map_dma_ranges(port);
+     if (ret)
+             return ret;
+
+     xgene_pcie_poll_linkup(port, &lanes, &speed);
+     if (!port->link_up)
+             dev_info(port->dev, "(rc) link down\n");

drivers/pci/host/pci-xgene.c line 722

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     else
+             dev_info(port->dev, "(rc) x%d gen-%d link up\n",
+                             lanes, speed + 1);
+     platform_set_drvdata(pdev, port);
+     lastbus = pci_rescan_bus(bridge->bus);
+     pci_bus_update_busn_res_end(bridge->bus, lastbus);
+     return 0;
+}
+
+static const struct of_device_id xgene_pcie_match_table[] __initconst = {

Please, remove '__initconst' marker in order to fix section mismatch warning.

drivers/pci/host/pci-xgene.c line 732

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     {.compatible = "apm,xgene-pcie",},
+     {},
+};
+
+static struct platform_driver xgene_pcie_driver = {
+     .driver = {
+                .name = "xgene-pcie",
+                .owner = THIS_MODULE,
+                .of_match_table = of_match_ptr(xgene_pcie_match_table),
+               },

Please fix this indent style, as below:

+ },

See you later. :-)

Best regards,
Jingoo Han

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +7 -1
+     .probe = xgene_pcie_probe_bridge,
+};
+module_platform_driver(xgene_pcie_driver);
+
+MODULE_AUTHOR("Tanmay Inamdar <[email protected]>");
+MODULE_DESCRIPTION("APM X-Gene PCIe driver");
+MODULE_LICENSE("GPL v2");
--

1.7.9.5

#4 lore raw

Re: [PATCH v4 1/4] pci: APM X-Gene PCIe controller driver

In reply to Tanmay Inamdar

drivers/pci/host/pci-xgene.c line 106

Quoted 3 lines · Tanmay Inamdar
drivers/pci/host/pci-xgene.c new file +3 -0
+static inline void xgene_pcie_cfg_out16(void __iomem *addr, u16 val)
+{
+	u64 temp_addr = (u64)addr & ~0x3;

Please use 'unsigned long' as the type for calculations like this one, to make the code more portable. You mentioned before that the same PCI host controller is used on some ppc4xx, and we may want to share the code later.

Quoted 8 lines
drivers/pci/host/pci-xgene.c new file +8 -0
+static int xgene_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
+				  int offset, int len, u32 *val)
+{
+	struct xgene_pcie_port *port = bus->sysdata;
+	void __iomem *addr;
+	u8 val8;
+	u16 val16;
+

drivers/pci/host/pci-xgene.c line 248

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+	if ((pci_is_root_bus(bus) && devfn != 0) || !port->link_up)
+		return PCIBIOS_DEVICE_NOT_FOUND;
+
+	xgene_pcie_set_rtdid_reg(bus, devfn);
+	addr = xgene_pcie_get_cfg_base(bus);
+	switch (len) {
+	case 1:
+		xgene_pcie_cfg_in8(addr + offset, &val8);
+		*val = val8;
+		break;

Actually it would be better to just pass both addr and offset down into the low-level accessors and then do the calculation on 'offset', which is already a scalar.

Quoted 17 lines
drivers/pci/host/pci-xgene.c new file +17 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port,
+				   u32 *lanes, u32 *speed)
+{
+	void __iomem *csr_base = port->csr_base;
+	u32 val32;
+	u64 start_time, time;
+
+	/*
+	 * A component enters the LTSSM Detect state within
+	 * 20ms of the end of fundamental core reset.
+	 */
+	msleep(XGENE_LTSSM_DETECT_WAIT);
+	port->link_up = 0;
+	start_time = jiffies;
+	do {
+		val32 = readl(csr_base + PCIECORE_CTLANDSTATUS);
+		if (val32 & LINK_UP_MASK) {

drivers/pci/host/pci-xgene.c line 355

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+			port->link_up = 1;
+			*speed = PIPE_PHY_RATE_RD(val32);
+			val32 = readl(csr_base + BRIDGE_STATUS_0);
+			*lanes = val32 >> 26;
+			break;
+		}
+		msleep(1);
+		time = jiffies_to_msecs(jiffies - start_time);
+	} while (time <= XGENE_LTSSM_L0_WAIT);
+}

This can be written ina simpler way using 'time_before()'.

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+/* Return 0 on success */
+static int xgene_pcie_init_ecc(struct xgene_pcie_port *port)
+{
+	void __iomem *csr_base = port->csr_base;
+	u64 start_time, time = 0;
+	u32 val;
+
+	val = readl(csr_base + MEM_RAM_SHUTDOWN);
+	if (!val)

drivers/pci/host/pci-xgene.c line 406

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+		return 0;
+	writel(0x0, csr_base + MEM_RAM_SHUTDOWN);
+	start_time = jiffies;
+	do {
+		val = readl(csr_base + BLOCK_MEM_RDY);
+		if (val == BLOCK_MEM_RDY_VAL)
+			break;
+		msleep(1);
+		time = jiffies_to_msecs(jiffies - start_time);
+	} while (time < XGENE_PCIE_ECC_TIMEOUT);

Same here.

drivers/pci/host/pci-xgene.c line 419

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+static int xgene_pcie_init_port(struct xgene_pcie_port *port)
+{
+	int rc;
+
+	port->clk = clk_get(port->dev, NULL);
+	if (IS_ERR_OR_NULL(port->clk)) {
+		dev_err(port->dev, "clock not available\n");
+		return -ENODEV;
+	}

Practically every use of IS_ERR_OR_NULL() is a bug, don't do that. NULL is a valid return code from clk_get(), and should not be treated as an error.

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+static int xgene_pcie_map_ranges(struct xgene_pcie_port *port,
+				 struct pci_host_bridge *bridge,
+				 u64 cfg_addr)
+{
+	struct device *dev = port->dev;
+	struct pci_host_bridge_window *window;
+
+	list_for_each_entry(window, &bridge->windows, list) {
+		struct resource *res = window->res;

drivers/pci/host/pci-xgene.c line 531

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+		u64 restype = resource_type(res);
+		dev_dbg(port->dev, "0x%08lx 0x%016llx...0x%016llx\n",
+			res->flags, res->start, res->end);
+
+		switch (restype) {
+		case IORESOURCE_IO:
+			xgene_pcie_setup_ob_reg(port, res, OMR2BARL,
+						bridge->io_base);
+			BUG_ON(pci_ioremap_io(res, bridge->io_base) < 0);
+			break;

No need to BUG_ON() here, this is not a fatal condition, just don't register the I/O space resource if this fails.

I think as the PCI base support patch series evolves, you will actually not have to do this at all.

Arnd

#5 lore raw

Re: [PATCH v4 1/4] pci: APM X-Gene PCIe controller driver

Thanks for the review and comments. I will incorporate the comments from you and Jingoo Han in next version.

-Tanmay

Quoted 128 lines · Arnd Bergmann

drivers/pci/host/pci-xgene.c line 106

Quoted 3 lines · Tanmay Inamdar
drivers/pci/host/pci-xgene.c new file +3 -0
+static inline void xgene_pcie_cfg_out16(void __iomem *addr, u16 val)
+{
+     u64 temp_addr = (u64)addr & ~0x3;

Please use 'unsigned long' as the type for calculations like this one, to make the code more portable. You mentioned before that the same PCI host controller is used on some ppc4xx, and we may want to share the code later.

Quoted 8 lines
drivers/pci/host/pci-xgene.c new file +8 -0
+static int xgene_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
+                               int offset, int len, u32 *val)
+{
+     struct xgene_pcie_port *port = bus->sysdata;
+     void __iomem *addr;
+     u8 val8;
+     u16 val16;
+

drivers/pci/host/pci-xgene.c line 248

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     if ((pci_is_root_bus(bus) && devfn != 0) || !port->link_up)
+             return PCIBIOS_DEVICE_NOT_FOUND;
+
+     xgene_pcie_set_rtdid_reg(bus, devfn);
+     addr = xgene_pcie_get_cfg_base(bus);
+     switch (len) {
+     case 1:
+             xgene_pcie_cfg_in8(addr + offset, &val8);
+             *val = val8;
+             break;

Actually it would be better to just pass both addr and offset down into the low-level accessors and then do the calculation on 'offset', which is already a scalar.

Quoted 17 lines
drivers/pci/host/pci-xgene.c new file +17 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port,
+                                u32 *lanes, u32 *speed)
+{
+     void __iomem *csr_base = port->csr_base;
+     u32 val32;
+     u64 start_time, time;
+
+     /*
+      * A component enters the LTSSM Detect state within
+      * 20ms of the end of fundamental core reset.
+      */
+     msleep(XGENE_LTSSM_DETECT_WAIT);
+     port->link_up = 0;
+     start_time = jiffies;
+     do {
+             val32 = readl(csr_base + PCIECORE_CTLANDSTATUS);
+             if (val32 & LINK_UP_MASK) {

drivers/pci/host/pci-xgene.c line 355

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+                     port->link_up = 1;
+                     *speed = PIPE_PHY_RATE_RD(val32);
+                     val32 = readl(csr_base + BRIDGE_STATUS_0);
+                     *lanes = val32 >> 26;
+                     break;
+             }
+             msleep(1);
+             time = jiffies_to_msecs(jiffies - start_time);
+     } while (time <= XGENE_LTSSM_L0_WAIT);
+}

This can be written ina simpler way using 'time_before()'.

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+/* Return 0 on success */
+static int xgene_pcie_init_ecc(struct xgene_pcie_port *port)
+{
+     void __iomem *csr_base = port->csr_base;
+     u64 start_time, time = 0;
+     u32 val;
+
+     val = readl(csr_base + MEM_RAM_SHUTDOWN);
+     if (!val)

drivers/pci/host/pci-xgene.c line 406

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+             return 0;
+     writel(0x0, csr_base + MEM_RAM_SHUTDOWN);
+     start_time = jiffies;
+     do {
+             val = readl(csr_base + BLOCK_MEM_RDY);
+             if (val == BLOCK_MEM_RDY_VAL)
+                     break;
+             msleep(1);
+             time = jiffies_to_msecs(jiffies - start_time);
+     } while (time < XGENE_PCIE_ECC_TIMEOUT);

Same here.

drivers/pci/host/pci-xgene.c line 419

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+static int xgene_pcie_init_port(struct xgene_pcie_port *port)
+{
+     int rc;
+
+     port->clk = clk_get(port->dev, NULL);
+     if (IS_ERR_OR_NULL(port->clk)) {
+             dev_err(port->dev, "clock not available\n");
+             return -ENODEV;
+     }

Practically every use of IS_ERR_OR_NULL() is a bug, don't do that. NULL is a valid return code from clk_get(), and should not be treated as an error.

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+static int xgene_pcie_map_ranges(struct xgene_pcie_port *port,
+                              struct pci_host_bridge *bridge,
+                              u64 cfg_addr)
+{
+     struct device *dev = port->dev;
+     struct pci_host_bridge_window *window;
+
+     list_for_each_entry(window, &bridge->windows, list) {
+             struct resource *res = window->res;

drivers/pci/host/pci-xgene.c line 531

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+             u64 restype = resource_type(res);
+             dev_dbg(port->dev, "0x%08lx 0x%016llx...0x%016llx\n",
+                     res->flags, res->start, res->end);
+
+             switch (restype) {
+             case IORESOURCE_IO:
+                     xgene_pcie_setup_ob_reg(port, res, OMR2BARL,
+                                             bridge->io_base);
+                     BUG_ON(pci_ioremap_io(res, bridge->io_base) < 0);
+                     break;

No need to BUG_ON() here, this is not a fatal condition, just don't register the I/O space resource if this fails.

I think as the PCI base support patch series evolves, you will actually not have to do this at all.

Arnd

#6 lore raw

PATCH v4 2/4 arm64: dts: APM X-Gene PCIe device tree nodes

In reply to Tanmay Inamdar

This patch adds the device tree nodes for APM X-Gene PCIe controller and PCIe clock interface. Since X-Gene SOC supports maximum 5 ports, 5 dts nodes are added.

---
 arch/arm64/boot/dts/apm-mustang.dts |    8 ++
 arch/arm64/boot/dts/apm-storm.dtsi  |  155 +++++++++++++++++++++++++++++++++++
 2 files changed, 163 insertions(+)
arch/arm64/boot/dts/apm-mustang.dts +8 -0
index 1247ca1..507b6c9 100644
@@ -24,3 +24,11 @@
 		reg = < 0x1 0x00000000 0x0 0x80000000 >; /* Updated by bootloader */
 	};
 };
+
+&pcie0clk {
+	status = "ok";
+};
+
+&pcie0 {
+	status = "ok";
+};
arch/arm64/boot/dts/apm-storm.dtsi +155 -0

161 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH v4 2/4] arm64: dts: APM X-Gene PCIe device tree nodes

Quoted 10 lines · Tanmay Inamdar

This patch adds the device tree nodes for APM X-Gene PCIe controller and PCIe clock interface. Since X-Gene SOC supports maximum 5 ports, 5 dts nodes are added.

---
 arch/arm64/boot/dts/apm-mustang.dts |    8 ++
 arch/arm64/boot/dts/apm-storm.dtsi  |  155 +++++++++++++++++++++++++++++++++++
 2 files changed, 163 insertions(+)

[.....]

Quoted 2 lines
arch/arm64/boot/dts/apm-storm.dtsi +0 -0

[.....]

arch/arm64/boot/dts/apm-storm.dtsi line 242

Quoted 13 lines
arch/arm64/boot/dts/apm-storm.dtsi +13 -0
+
+		pcie0: pcie at 1f2b0000 {
+			status = "disabled";
+			device_type = "pci";
+			compatible = "apm,xgene-storm-pcie", "apm,xgene-pcie";
+			#interrupt-cells = <1>;
+			#size-cells = <2>;
+			#address-cells = <3>;
+			reg = < 0x00 0x1f2b0000 0x0 0x00010000   /* Controller registers */
+				0xe0 0xd0000000 0x0 0x00200000>; /* PCI config space */
+			reg-names = "csr", "cfg";
+			ranges = <0x01000000 0x00 0x00000000 0xe0 0x00000000 0x00 0x00010000   /* io */
+				  0x02000000 0x00 0x10000000 0xe0 0x10000000 0x00 0x80000000>; /* mem */
                                                                          ^^^

I have a question about the fourth number '0xe0' of 'ranges' property. Would you let me know what the '0xe0' means?

Best regards,
Jingoo Han

Quoted 8 lines
arch/arm64/boot/dts/apm-storm.dtsi +8 -0
+			dma-ranges = <0x42000000 0x40 0x00000000 0x40 0x00000000 0x40 0x00000000>;
+			interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+			interrupt-map = <0x0 0x0 0x0 0x1 &gic 0x0 0xc2 0x1
+					 0x0 0x0 0x0 0x2 &gic 0x0 0xc3 0x1
+					 0x0 0x0 0x0 0x3 &gic 0x0 0xc4 0x1
+					 0x0 0x0 0x0 0x4 &gic 0x0 0xc5 0x1>;
+			clocks = <&pcie0clk 0>;
+		};
#8 lore raw

Re: [PATCH v4 2/4] arm64: dts: APM X-Gene PCIe device tree nodes

Hello Jingoo Han,

Quoted 32 lines · Jingoo Han
Quoted 10 lines · Tanmay Inamdar

This patch adds the device tree nodes for APM X-Gene PCIe controller and PCIe clock interface. Since X-Gene SOC supports maximum 5 ports, 5 dts nodes are added.

---
 arch/arm64/boot/dts/apm-mustang.dts |    8 ++
 arch/arm64/boot/dts/apm-storm.dtsi  |  155 +++++++++++++++++++++++++++++++++++
 2 files changed, 163 insertions(+)

[.....]

Quoted 2 lines
arch/arm64/boot/dts/apm-storm.dtsi +0 -0

[.....]

arch/arm64/boot/dts/apm-storm.dtsi line 242

Quoted 13 lines
arch/arm64/boot/dts/apm-storm.dtsi +13 -0
+
+             pcie0: pcie at 1f2b0000 {
+                     status = "disabled";
+                     device_type = "pci";
+                     compatible = "apm,xgene-storm-pcie", "apm,xgene-pcie";
+                     #interrupt-cells = <1>;
+                     #size-cells = <2>;
+                     #address-cells = <3>;
+                     reg = < 0x00 0x1f2b0000 0x0 0x00010000   /* Controller registers */
+                             0xe0 0xd0000000 0x0 0x00200000>; /* PCI config space */
+                     reg-names = "csr", "cfg";
+                     ranges = <0x01000000 0x00 0x00000000 0xe0 0x00000000 0x00 0x00010000   /* io */
+                               0x02000000 0x00 0x10000000 0xe0 0x10000000 0x00 0x80000000>; /* mem */
Quoted 5 lines
                                                                          ^^^

I have a question about the fourth number '0xe0' of 'ranges' property. Would you let me know what the '0xe0' means?

In X-Gene address map, the physical address range starting from 0xe0_00000000 is reserved for PCIe Port 0 outbound memory mappings.

Quoted 12 lines

Best regards,
Jingoo Han

Quoted 8 lines
arch/arm64/boot/dts/apm-storm.dtsi +8 -0
+                     dma-ranges = <0x42000000 0x40 0x00000000 0x40 0x00000000 0x40 0x00000000>;
+                     interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+                     interrupt-map = <0x0 0x0 0x0 0x1 &gic 0x0 0xc2 0x1
+                                      0x0 0x0 0x0 0x2 &gic 0x0 0xc3 0x1
+                                      0x0 0x0 0x0 0x3 &gic 0x0 0xc4 0x1
+                                      0x0 0x0 0x0 0x4 &gic 0x0 0xc5 0x1>;
+                     clocks = <&pcie0clk 0>;
+             };
#9 lore raw

Re: [PATCH v4 2/4] arm64: dts: APM X-Gene PCIe device tree nodes

In reply to Tanmay Inamdar
Quoted 10 lines · Tanmay Inamdar
arch/arm64/boot/dts/apm-storm.dtsi +10 -0
+		pcie0: pcie at 1f2b0000 {
+			status = "disabled";
+			device_type = "pci";
+			compatible = "apm,xgene-storm-pcie", "apm,xgene-pcie";
+			#interrupt-cells = <1>;
+			#size-cells = <2>;
+			#address-cells = <3>;
+			reg = < 0x00 0x1f2b0000 0x0 0x00010000   /* Controller registers */
+				0xe0 0xd0000000 0x0 0x00200000>; /* PCI config space */
+			reg-names = "csr", "cfg";

arch/arm64/boot/dts/apm-storm.dtsi line 250

Quoted 10 lines
arch/arm64/boot/dts/apm-storm.dtsi +10 -0
+			ranges = <0x01000000 0x00 0x00000000 0xe0 0x00000000 0x00 0x00010000   /* io */
+				  0x02000000 0x00 0x10000000 0xe0 0x10000000 0x00 0x80000000>; /* mem */
+			dma-ranges = <0x42000000 0x40 0x00000000 0x40 0x00000000 0x40 0x00000000>;
+			interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+			interrupt-map = <0x0 0x0 0x0 0x1 &gic 0x0 0xc2 0x1
+					 0x0 0x0 0x0 0x2 &gic 0x0 0xc3 0x1
+					 0x0 0x0 0x0 0x3 &gic 0x0 0xc4 0x1
+					 0x0 0x0 0x0 0x4 &gic 0x0 0xc5 0x1>;
+			clocks = <&pcie0clk 0>;
+		};

Is 0x40.0x00000000 the start of your RAM? I had expected RAM to start at 0.0, and in that case the dma-ranges property would be wrong.

Arnd

#10 lore raw

Re: [PATCH v4 2/4] arm64: dts: APM X-Gene PCIe device tree nodes

Quoted 22 lines · Arnd Bergmann
Quoted 10 lines · Tanmay Inamdar
arch/arm64/boot/dts/apm-storm.dtsi +10 -0
+             pcie0: pcie at 1f2b0000 {
+                     status = "disabled";
+                     device_type = "pci";
+                     compatible = "apm,xgene-storm-pcie", "apm,xgene-pcie";
+                     #interrupt-cells = <1>;
+                     #size-cells = <2>;
+                     #address-cells = <3>;
+                     reg = < 0x00 0x1f2b0000 0x0 0x00010000   /* Controller registers */
+                             0xe0 0xd0000000 0x0 0x00200000>; /* PCI config space */
+                     reg-names = "csr", "cfg";

arch/arm64/boot/dts/apm-storm.dtsi line 250

Quoted 10 lines
arch/arm64/boot/dts/apm-storm.dtsi +10 -0
+                     ranges = <0x01000000 0x00 0x00000000 0xe0 0x00000000 0x00 0x00010000   /* io */
+                               0x02000000 0x00 0x10000000 0xe0 0x10000000 0x00 0x80000000>; /* mem */
+                     dma-ranges = <0x42000000 0x40 0x00000000 0x40 0x00000000 0x40 0x00000000>;
+                     interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+                     interrupt-map = <0x0 0x0 0x0 0x1 &gic 0x0 0xc2 0x1
+                                      0x0 0x0 0x0 0x2 &gic 0x0 0xc3 0x1
+                                      0x0 0x0 0x0 0x3 &gic 0x0 0xc4 0x1
+                                      0x0 0x0 0x0 0x4 &gic 0x0 0xc5 0x1>;
+                     clocks = <&pcie0clk 0>;
+             };
Quoted 2 lines

Is 0x40.0x00000000 the start of your RAM? I had expected RAM to start at 0.0, and in that case the dma-ranges property would be wrong.

RAM starting address is 0x40_00000000.

Quoted 10 lines

Arnd
CONFIDENTIALITY NOTICE: This e-mail message, including any attachments,
is for the sole use of the intended recipient(s) and contains information
that is confidential and proprietary to Applied Micro Circuits Corporation or its subsidiaries. It is to be used solely for the purpose of furthering the parties' business relationship. All unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

#11 lore raw

Re: [PATCH v4 2/4] arm64: dts: APM X-Gene PCIe device tree nodes

Quoted 23 lines · Tanmay Inamdar
Quoted 22 lines · Arnd Bergmann
Quoted 20 lines · Tanmay Inamdar
arch/arm64/boot/dts/apm-storm.dtsi +20 -0
+             pcie0: pcie at 1f2b0000 {
+                     status = "disabled";
+                     device_type = "pci";
+                     compatible = "apm,xgene-storm-pcie", "apm,xgene-pcie";
+                     #interrupt-cells = <1>;
+                     #size-cells = <2>;
+                     #address-cells = <3>;
+                     reg = < 0x00 0x1f2b0000 0x0 0x00010000   /* Controller registers */
+                             0xe0 0xd0000000 0x0 0x00200000>; /* PCI config space */
+                     reg-names = "csr", "cfg";
+                     ranges = <0x01000000 0x00 0x00000000 0xe0 0x00000000 0x00 0x00010000   /* io */
+                               0x02000000 0x00 0x10000000 0xe0 0x10000000 0x00 0x80000000>; /* mem */
+                     dma-ranges = <0x42000000 0x40 0x00000000 0x40 0x00000000 0x40 0x00000000>;
+                     interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+                     interrupt-map = <0x0 0x0 0x0 0x1 &gic 0x0 0xc2 0x1
+                                      0x0 0x0 0x0 0x2 &gic 0x0 0xc3 0x1
+                                      0x0 0x0 0x0 0x3 &gic 0x0 0xc4 0x1
+                                      0x0 0x0 0x0 0x4 &gic 0x0 0xc5 0x1>;
+                     clocks = <&pcie0clk 0>;
+             };
Quoted 4 lines
Quoted 2 lines

Is 0x40.0x00000000 the start of your RAM? I had expected RAM to start at 0.0, and in that case the dma-ranges property would be wrong.

RAM starting address is 0x40_00000000.

Ok, it's good then. Thanks for the clarification, I keep losing track of how each of the ~40 SoCs I'm dealing with handles these things.

Arnd

#12 lore raw

PATCH v4 3/4 dt-bindings: pci: xgene pcie device tree bindings

In reply to Tanmay Inamdar

This patch adds the bindings for X-Gene PCIe driver. The driver resides under 'drivers/pci/host/pci-xgene.c' file.

---
 .../devicetree/bindings/pci/xgene-pci.txt          |   52 ++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/xgene-pci.txt
Documentation/devicetree/bindings/pci/xgene-pci.txt new file +52 -0
new file mode 100644
index 0000000..e19fdb8
@@ -0,0 +1,52 @@
+* AppliedMicro X-Gene PCIe interface
+
+Required properties:
+- device_type: set to "pci"
+- compatible: should contain "apm,xgene-pcie" to identify the core.
+- reg: A list of physical base address and length 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:
+  "csr": controller configuration registers.
+  "cfg": pcie configuration space registers.
+- #address-cells: set to <3>
+- #size-cells: set to <2>
+- ranges: ranges for the outbound memory, I/O regions.
+- dma-ranges: ranges for the inbound memory regions.
+- #interrupt-cells: set to <1>
+- interrupt-map-mask and interrupt-map: standard PCI properties
+	to define the mapping of the PCIe interface to interrupt
+	numbers.
+- clocks: from common clock binding: handle to pci clock.
+
+Optional properties:
+- status: Either "ok" or "disabled".
+
+Example:
+
+SoC specific DT Entry:
+	pcie0: pcie at 1f2b0000 {
+		status = "disabled";
+		device_type = "pci";
+		compatible = "apm,xgene-storm-pcie", "apm,xgene-pcie";
+		#interrupt-cells = <1>;
+		#size-cells = <2>;
+		#address-cells = <3>;
+		reg = < 0x00 0x1f2b0000 0x0 0x00010000   /* Controller registers */
+			0xe0 0xd0000000 0x0 0x00200000>; /* PCI config space */
+		reg-names = "csr", "cfg";
+		ranges = <0x01000000 0x00 0x00000000 0xe0 0x00000000 0x00 0x00010000   /* io */
+			  0x02000000 0x00 0x10000000 0xe0 0x10000000 0x00 0x80000000>; /* mem */
+		dma-ranges = <0x42000000 0x40 0x00000000 0x40 0x00000000 0x40 0x00000000>;
+		interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+		interrupt-map = <0x0 0x0 0x0 0x1 &gic 0x0 0xc2 0x1
+				 0x0 0x0 0x0 0x2 &gic 0x0 0xc3 0x1
+				 0x0 0x0 0x0 0x3 &gic 0x0 0xc4 0x1
+				 0x0 0x0 0x0 0x4 &gic 0x0 0xc5 0x1>;
+		clocks = <&pcie0clk 0>;
+	};
+
+Board specific DT Entry:
+	&pcie0 {
+		status = "ok";
+	};
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH v4 4/4 MAINTAINERS: entry for APM X-Gene PCIe host driver

In reply to Tanmay Inamdar

Add entry for AppliedMicro X-Gene PCIe host driver.

---
 MAINTAINERS |    7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index e1297ff..80b7fe5 100644
@@ -6629,6 +6629,13 @@ L:	linux-pci at vger.kernel.org
 S:	Maintained
 F:	drivers/pci/host/*designware*
 
+PCI DRIVER FOR APPLIEDMICRO XGENE
+M:	Tanmay Inamdar <[email protected]>
+L:	linux-pci at vger.kernel.org
+L:	linux-arm-kernel at lists.infradead.org
+S:	Maintained
+F:	drivers/pci/host/pci-xgene.c
+
 PCMCIA SUBSYSTEM
 P:	Linux PCMCIA Team
 L:	linux-pcmcia at lists.infradead.org
Signature · 1 line
1.7.9.5