Skip to contentSkip to conversation

APM X-Gene PCIe controller

RFC PATCH Superseded Tanmay Inamdar 3 participants 16 messages Jan 14, 2014 – Jan 29, 2014

Subsystems (3)

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v2 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 arch support for arm64. The arm64 pcie arch support is not yet part of mainline Linux kernel and approach for arch support is under discussion with arm64 maintainers. The reference patch can be found here --> https://lkml.org/lkml/2013/10/23/244

If someone wishes to test PCIe on X-Gene, arch support patch must be applied before the patches in this patch set.

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-pcie.txt         |   45 +
 MAINTAINERS                                        |    7 +
 arch/arm64/boot/dts/apm-mustang.dts                |    4 +
 arch/arm64/boot/dts/apm-storm.dtsi                 |  144 +++
 drivers/pci/host/Kconfig                           |   10 +
 drivers/pci/host/Makefile                          |    1 +
 drivers/pci/host/pci-xgene.c                       |  934 ++++++++++++++++++++
 7 files changed, 1145 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/xgene-pcie.txt
 create mode 100644 drivers/pci/host/pci-xgene.c
Signature · 1 line
1.7.9.5
#1 lore raw

RFC PATCH v2 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 has maximum 5 PCIe ports supported.

---
 drivers/pci/host/Kconfig     |   10 +
 drivers/pci/host/Makefile    |    1 +
 drivers/pci/host/pci-xgene.c |  934 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 945 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 +934 -0

934 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

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

Quoted 5 lines · Tanmay Inamdar

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 has maximum 5 PCIe ports supported.

This already looks much better than the first version, but I have a more comments. Most importantly, it would help to know how the root ports are structured. Is this a standard root complex and multiple ports, multiple root complexes with one port each, or a nonstandard organization that is a mix of those two models?

Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+
+/* When the address bit [17:16] is 2'b01, the Configuration access will be
+ * treated as Type 1 and it will be forwarded to external PCIe device.
+ */

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+static void __iomem *xgene_pcie_get_cfg_base(struct pci_bus *bus)
+{
+	struct xgene_pcie_port *port = xgene_pcie_bus_to_port(bus);
+	u64 addr = (u64)port->cfg_base;
+
+	if (bus->number >= (port->first_busno + 1))
+		addr |= AXI_EP_CFG_ACCESS;
+
+	return (void *)addr;
+}

Wrong type, it should be 'void __iomem *'. Also you can't assume that bit operations work on virtual __iomem addresses, so it should be better to just add a constant integer to the pointer, which is a valid operation.

I also wonder why you need to do this at all. If there isn't a global config space for all ports, but rather a separate type0/type1 config cycle based on the bus number, I see that as an indication that the ports are in fact separate domains and should each start with bus 0.

Quoted 19 lines
drivers/pci/host/pci-xgene.c new file +19 -0
+static void xgene_pcie_setup_lanes(struct xgene_pcie_port *port)
+{
+	void *csr_base = port->csr_base;
+	u32 val;
+
+	val = readl(csr_base + BRIDGE_8G_CFG_8);
+	val = eq_pre_cursor_lane0_set(val, 0x7);
+	val = eq_pre_cursor_lane1_set(val, 0x7);
+	writel(val, csr_base + BRIDGE_8G_CFG_8);
+
+	val = readl(csr_base + BRIDGE_8G_CFG_9);
+	val = eq_pre_cursor_lane0_set(val, 0x7);
+	val = eq_pre_cursor_lane1_set(val, 0x7);
+	writel(val, csr_base + BRIDGE_8G_CFG_9);
+
+	val = readl(csr_base + BRIDGE_8G_CFG_10);
+	val = eq_pre_cursor_lane0_set(val, 0x7);
+	val = eq_pre_cursor_lane1_set(val, 0x7);
+	writel(val, csr_base + BRIDGE_8G_CFG_10);

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+
+	val = readl(csr_base + BRIDGE_8G_CFG_11);
+	val = eq_pre_cursor_lane0_set(val, 0x7);
+	val = eq_pre_cursor_lane1_set(val, 0x7);
+	writel(val, csr_base + BRIDGE_8G_CFG_11);
+
+	val = readl(csr_base + BRIDGE_8G_CFG_4);
+	val = (val & ~0x30) | (1 << 4);
+	writel(val, csr_base + BRIDGE_8G_CFG_4);
+}

Please document what you are actually setting here. If the configuration of the lanes is always the same, why do you have to set it here. If not, why do you set constant values?

Quoted 15 lines
drivers/pci/host/pci-xgene.c new file +15 -0
+static void xgene_pcie_setup_link(struct xgene_pcie_port *port)
+{
+	void *csr_base = port->csr_base;
+	u32 val;
+
+	val = readl(csr_base + BRIDGE_CFG_14);
+	val |= DIRECT_TO_8GTS_MASK;
+	val |= SUPPORT_5GTS_MASK;
+	val |= SUPPORT_8GTS_MASK;
+	val |= DIRECT_TO_5GTS_MASK;
+	writel(val, csr_base + BRIDGE_CFG_14);
+
+	val = readl(csr_base + BRIDGE_CFG_14);
+	val &= ~ADVT_INFINITE_CREDITS;
+	writel(val, csr_base + BRIDGE_CFG_14);

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+
+	val = readl(csr_base + BRIDGE_8G_CFG_0);
+	val |= (val & ~0xf) | 7;
+	val |= (val & ~0xf00) | ((7 << 8) & 0xf00);
+	writel(val, csr_base + BRIDGE_8G_CFG_0);
+
+	val = readl(csr_base + BRIDGE_8G_CFG_0);
+	val |= DWNSTRM_EQ_SKP_PHS_2_3;
+	writel(val, csr_base + BRIDGE_8G_CFG_0);
+}

Same here.

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

Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +12 -0
+static void xgene_pcie_program_core(void *csr_base)
+{
+	u32 val;
+
+	val = readl(csr_base + BRIDGE_CFG_0);
+	val |= AER_OPTIONAL_ERROR_EN;
+	writel(val, csr_base + BRIDGE_CFG_0);
+	writel(0x0, csr_base + INTXSTATUSMASK);
+	val = readl(csr_base + BRIDGE_CTRL_1);
+	val = (val & ~0xffff) | XGENE_PCIE_DEV_CTRL;
+	writel(val, csr_base + BRIDGE_CTRL_1);
+}

'program_core'?

Quoted 14 lines
drivers/pci/host/pci-xgene.c new file +14 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port, u32 *lanes)
+{
+	void *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 {

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+		val32 = readl(csr_base + PCIECORE_CTLANDSTATUS);
+		if (val32 & LINK_UP_MASK) {
+			port->link_up = 1;
+			port->link_speed = PIPE_PHY_RATE_RD(val32);
+			val32 = readl(csr_base + BRIDGE_STATUS_0);
+			*lanes = val32 >> 26;
+		}
+		time = jiffies_to_msecs(jiffies - start_time);
+	} while ((!port->link_up) || (time <= XGENE_LTSSM_L0_WAIT));
+}

Maybe another msleep() in the loop? It seems weird to first do an unconditional sleep but then busy-wait for the result.

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

Quoted 11 lines
drivers/pci/host/pci-xgene.c new file +11 -0
+static void xgene_pcie_setup_primary_bus(struct xgene_pcie_port *port,
+					 u32 first_busno, u32 last_busno)
+{
+	u32 val;
+	void *cfg_addr = port->cfg_base;
+
+	val = readl(cfg_addr + PCI_PRIMARY_BUS);
+	val &= ~PCI_PRIMARY_BUS_MASK;
+	val |= (last_busno << 16) | ((first_busno + 1) << 8) | (first_busno);
+	writel(val, cfg_addr + PCI_PRIMARY_BUS);
+}

Please explain what you are doing here. As mentioned above, I would expect that each domain has visibility of all 255 buses. You shouldn't need any hacks where you try to artificially squeeze the ports into a single domain when they are separate in hardware.

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

Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+/*
+ * read configuration values from DTS
+ */
+static int xgene_pcie_read_dts_config(struct xgene_pcie_port *port)

The comment and function name don't seem to match what the function does. The main purpose of this function seems to be to ioremap the resources, which have nothing to with configuration.

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

Quoted 11 lines
drivers/pci/host/pci-xgene.c new file +11 -0
+{
+	struct device_node *np = port->node;
+	struct resource csr_res;
+	struct resource cfg_res;
+
+	/* Get CSR space registers address */
+	if (of_address_to_resource(np, 0, &csr_res))
+		return -EINVAL;
+
+	port->csr_base = devm_ioremap_nocache(port->dev, csr_res.start,
+					      resource_size(&csr_res));

You can also use platform_get_resource() to access the resource that is already there, rather than creating another one.

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+static void xgene_pcie_setup_ob_reg(struct xgene_pcie_port *port,
+				    u32 addr, u32 restype)
+{
+	struct resource *res = NULL;
+	void *base = port->csr_base + addr;
+	resource_size_t size;
+	u64 cpu_addr = 0;
+	u64 pci_addr = 0;
+	u64 mask = 0;
+	u32 min_size = 0;

A general note: don't initialize local variables to a bogus valus (e.g. 0) in their declaration. It prevents the compiler from warning about incorrect uses.

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

Quoted 1 line
drivers/pci/host/pci-xgene.c new file +1 -0
+	u32 flag = EN_REG;

This one on the other hand is ok, because you are actually going to use that value.

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

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+	switch (restype) {
+	case IORESOURCE_MEM:
+		res = &port->mem.res;
+		pci_addr = port->mem.pci_addr;
+		min_size = SZ_128M;
+		break;
+	case IORESOURCE_IO:
+		res = &port->io.res;
+		pci_addr = port->io.pci_addr;
+		min_size = 128;
+		flag |= OB_LO_IO;
+		break;
+	}

I assume this works ok, but seems wrong in one detail: If the resource is marked IORESOURCE_IO, res->start is supposed to be in I/O space, not in memory space, which would make it the wrong number to program into the hardware registers.

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

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+static int xgene_pcie_parse_map_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;
+
+	if (of_pci_range_parser_init(&parser, np)) {
+		dev_err(dev, "missing ranges property\n");
+		return -EINVAL;
+	}
+
+	/* Get the I/O, memory, config ranges from DT */

The comment needs updating now that you don't read config space here any more.

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+/* X-Gene PCIe support maximum 3 inbound memory regions
+ * This function helps to select a region based on size of region
+ */
+static int xgene_pcie_select_ib_reg(u64 size)
+{
+	static u8 ib_reg_mask;
+
+	if ((size > 4) && (size < SZ_16M) && !(ib_reg_mask & (1 << 1))) {
+		ib_reg_mask |= (1 << 1);
+		return 1;
+	}
+
+	if ((size > SZ_1K) && (size < SZ_1T) && !(ib_reg_mask & (1 << 0))) {

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+		ib_reg_mask |= (1 << 0);
+		return 0;
+	}
+
+	if ((size > SZ_1M) && (size < SZ_1T) && !(ib_reg_mask & (1 << 2))) {
+		ib_reg_mask |= (1 << 2);
+		return 2;
+	}
+	return -EINVAL;
+}

Shouldn't the ib_reg_mask variable be per host bridge? Static variables are dangerous if you ever get multiple instances of the hardware in one system.

Quoted 18 lines
drivers/pci/host/pci-xgene.c new file +18 -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;
+	int region;
+
+	if (pci_dma_range_parser_init(&parser, np)) {
+		dev_err(dev, "missing dma-ranges property\n");
+		return -EINVAL;
+	}
+
+	/* Get the dma-ranges from DT */
+	for_each_of_pci_range(&parser, &range) {
+		u64 restype = range.flags & IORESOURCE_TYPE_BITS;
+		u64 end = range.cpu_addr + range.size - 1;
+		dev_dbg(port->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+			range.flags, range.cpu_addr, end, range.pci_addr);
+		region = xgene_pcie_select_ib_reg(range.size);
+		if (region == -EINVAL) {
+			dev_warn(port->dev, "invalid pcie dma-range config\n");
+			continue;
+		}
+		xgene_pcie_setup_ib_reg(port, &range, restype, region);
+	}
+	return 0;
+}

I guess is could even be a local variable in this function, which you pass by reference.

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

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+
+static int xgene_pcie_setup(int nr, struct pci_sys_data *sys)
+{
+	struct xgene_pcie_port *pp = xgene_pcie_sys_to_port(sys);
+
+	if (pp == NULL)
+		return 0;
+
+	sys->mem_offset = pp->mem.res.start - pp->mem.pci_addr;
+	pci_add_resource_offset(&sys->resources, &pp->mem.res,
+				sys->mem_offset);
+	return 1;
+}

Please follow the regular error handling conventions, which are to pass a negative errno value on error and zero on success.

Also, what would be a reason for the port to be zero here? If it's something that can't happen in practice, don't try to handle it gracefully. You can use BUG_ON() for fatal conditions that are supposed to be impossible to reach.

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+static struct pci_bus __init *xgene_pcie_scan_bus(int nr,
+						  struct pci_sys_data *sys)
+{
+	struct xgene_pcie_port *pp = xgene_pcie_sys_to_port(sys);
+
+	pp->first_busno = sys->busnr;
+	xgene_pcie_setup_primary_bus(pp, sys->busnr, 0xff);
+	return pci_scan_root_bus(NULL, sys->busnr, &xgene_pcie_ops,
+				 sys, &sys->resources);
+}

You have a number of helper functions that don't seem to gain much at all. Just move the call to pci_scan_root_bus() into xgene_pcie_setup_primary_bus() here, and use that as the .scan callback.

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

Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +12 -0
+	if (!port->link_up)
+		dev_info(port->dev, "(rc) link down\n");
+	else
+		dev_info(port->dev, "(rc) x%d gen-%d link up\n",
+				lanes, port->link_speed + 1);
+#ifdef CONFIG_PCI_DOMAINS
+	xgene_pcie_hw.domain++;
+#endif
+	xgene_pcie_hw.private_data[index++] = port;
+	platform_set_drvdata(pdev, port);
+	return 0;
+}

Do you have multiple domains or not? I don't see how it can work if you make the domain setup conditional on a kernel configuration option. If you in fact have multiple domains, make sure in Kconfig that CONFIG_PCI_DOMAINS is enabled. Otherwise don't mess with the domain number...

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

Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+static const struct of_device_id xgene_pcie_match_table[] __initconst = {
+	{.compatible = "apm,xgene-pcie",},
+	{},
+};

Another general note: Your "compatible" strings are rather unspecific. Do you have a version number for this IP block? I suppose that it's related to one that has been used in other chips before, or will be used in future chips, if it's not actually licensed from some other company.

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

Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+static int __init xgene_pcie_init(void)
+{
+	void *private;
+	int ret;
+
+	pr_info("X-Gene: PCIe driver\n");
+
+	/* allocate private data to keep xgene_pcie_port information */
+	private = kzalloc((XGENE_PCIE_MAX_PORTS * sizeof(void *)), GFP_KERNEL);

This should not be done unconditionally: There is no point in printing a message or allocating memory if you don't actually run on a system with this device.

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

Quoted 2 lines
drivers/pci/host/pci-xgene.c new file +2 -0
+	if (private == NULL)
+		return -ENOMEM;

Style: if you are testing for an object, just write 'if (private)' or 'if (!private)', but don't compare against NULL.

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

Quoted 7 lines
drivers/pci/host/pci-xgene.c new file +7 -0
+	xgene_pcie_hw.private_data = private;
+	ret = platform_driver_probe(&xgene_pcie_driver,
+				    xgene_pcie_probe_bridge);
+	if (ret)
+		return ret;
+	pci_common_init(&xgene_pcie_hw);
+	return 0;

This seems wrong: You should not use platform_driver_probe() because that has issues with deferred probing.

Arnd

#3 lore raw

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

Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Tanmay Inamdar

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 has maximum 5 PCIe ports supported.

Quoted 7 lines
Quoted 1 line

This already looks much better than the first version, but I have a more comments. Most importantly, it would help to know how the root ports are structured. Is this a standard root complex and multiple ports, multiple root complexes with one port each, or a nonstandard organization that is a mix of those two models?

This is multiple root complexes with one port each.

Quoted 12 lines
Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +11 -0
+
+/* When the address bit [17:16] is 2'b01, the Configuration access will be
+ * treated as Type 1 and it will be forwarded to external PCIe device.
+ */
+static void __iomem *xgene_pcie_get_cfg_base(struct pci_bus *bus)
+{
+     struct xgene_pcie_port *port = xgene_pcie_bus_to_port(bus);
+     u64 addr = (u64)port->cfg_base;
+
+     if (bus->number >= (port->first_busno + 1))
+             addr |= AXI_EP_CFG_ACCESS;
Quoted 8 lines

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

Quoted 3 lines
drivers/pci/host/pci-xgene.c new file +3 -0
+
+     return (void *)addr;
+}

Wrong type, it should be 'void __iomem *'. Also you can't assume that bit operations work on virtual __iomem addresses, so it should be better to just add a constant integer to the pointer, which is a valid operation.

ok.

Quoted 5 lines

I also wonder why you need to do this at all. If there isn't a global config space for all ports, but rather a separate type0/type1 config cycle based on the bus number, I see that as an indication that the ports are in fact separate domains and should each start with bus 0.

It is not a standard ECAM layout. We also have a separate RTDID register as well to program bus, device, function. While accessing EP config space, we have to set the bit 17:16 as 2b'01. The same config space address is utilized for enabling a customized nonstandard PCIe DMA feature. The bits are defined to differentiate the access purpose. The feature is not supported in this driver yet.

Secondly I don't think it will matter if each port starts with bus 0. As long as we set the correct BDF in RTDID and set correct bits in config address, the config reads and writes would work. Right?

Quoted 26 lines
Quoted 26 lines
drivers/pci/host/pci-xgene.c new file +25 -0
+static void xgene_pcie_setup_lanes(struct xgene_pcie_port *port)
+{
+     void *csr_base = port->csr_base;
+     u32 val;
+
+     val = readl(csr_base + BRIDGE_8G_CFG_8);
+     val = eq_pre_cursor_lane0_set(val, 0x7);
+     val = eq_pre_cursor_lane1_set(val, 0x7);
+     writel(val, csr_base + BRIDGE_8G_CFG_8);
+
+     val = readl(csr_base + BRIDGE_8G_CFG_9);
+     val = eq_pre_cursor_lane0_set(val, 0x7);
+     val = eq_pre_cursor_lane1_set(val, 0x7);
+     writel(val, csr_base + BRIDGE_8G_CFG_9);
+
+     val = readl(csr_base + BRIDGE_8G_CFG_10);
+     val = eq_pre_cursor_lane0_set(val, 0x7);
+     val = eq_pre_cursor_lane1_set(val, 0x7);
+     writel(val, csr_base + BRIDGE_8G_CFG_10);
+
+     val = readl(csr_base + BRIDGE_8G_CFG_11);
+     val = eq_pre_cursor_lane0_set(val, 0x7);
+     val = eq_pre_cursor_lane1_set(val, 0x7);
+     writel(val, csr_base + BRIDGE_8G_CFG_11);
+
Quoted 8 lines

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

Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+     val = readl(csr_base + BRIDGE_8G_CFG_4);
+     val = (val & ~0x30) | (1 << 4);
+     writel(val, csr_base + BRIDGE_8G_CFG_4);
+}

Please document what you are actually setting here. If the configuration of the lanes is always the same, why do you have to set it here. If not, why do you set constant values?

Good point. Let me check if these values should be constant or tune-able.

Quoted 29 lines
Quoted 16 lines
drivers/pci/host/pci-xgene.c new file +15 -0
+static void xgene_pcie_setup_link(struct xgene_pcie_port *port)
+{
+     void *csr_base = port->csr_base;
+     u32 val;
+
+     val = readl(csr_base + BRIDGE_CFG_14);
+     val |= DIRECT_TO_8GTS_MASK;
+     val |= SUPPORT_5GTS_MASK;
+     val |= SUPPORT_8GTS_MASK;
+     val |= DIRECT_TO_5GTS_MASK;
+     writel(val, csr_base + BRIDGE_CFG_14);
+
+     val = readl(csr_base + BRIDGE_CFG_14);
+     val &= ~ADVT_INFINITE_CREDITS;
+     writel(val, csr_base + BRIDGE_CFG_14);

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+
+     val = readl(csr_base + BRIDGE_8G_CFG_0);
+     val |= (val & ~0xf) | 7;
+     val |= (val & ~0xf00) | ((7 << 8) & 0xf00);
+     writel(val, csr_base + BRIDGE_8G_CFG_0);
+
+     val = readl(csr_base + BRIDGE_8G_CFG_0);
+     val |= DWNSTRM_EQ_SKP_PHS_2_3;
+     writel(val, csr_base + BRIDGE_8G_CFG_0);
+}

Same here.

Quoted 14 lines

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

Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +12 -0
+static void xgene_pcie_program_core(void *csr_base)
+{
+     u32 val;
+
+     val = readl(csr_base + BRIDGE_CFG_0);
+     val |= AER_OPTIONAL_ERROR_EN;
+     writel(val, csr_base + BRIDGE_CFG_0);
+     writel(0x0, csr_base + INTXSTATUSMASK);
+     val = readl(csr_base + BRIDGE_CTRL_1);
+     val = (val & ~0xffff) | XGENE_PCIE_DEV_CTRL;
+     writel(val, csr_base + BRIDGE_CTRL_1);
+}

'program_core'?

Some of the PCIe core related misc configurations.

Quoted 20 lines
Quoted 20 lines
drivers/pci/host/pci-xgene.c new file +19 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port, u32 *lanes)
+{
+     void *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) {
+                     port->link_up = 1;
+                     port->link_speed = PIPE_PHY_RATE_RD(val32);
+                     val32 = readl(csr_base + BRIDGE_STATUS_0);
Quoted 8 lines

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

Quoted 5 lines
drivers/pci/host/pci-xgene.c new file +5 -0
+                     *lanes = val32 >> 26;
+             }
+             time = jiffies_to_msecs(jiffies - start_time);
+     } while ((!port->link_up) || (time <= XGENE_LTSSM_L0_WAIT));
+}

Maybe another msleep() in the loop? It seems weird to first do an unconditional sleep but then busy-wait for the result.

ok.

Quoted 17 lines

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

Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +11 -0
+static void xgene_pcie_setup_primary_bus(struct xgene_pcie_port *port,
+                                      u32 first_busno, u32 last_busno)
+{
+     u32 val;
+     void *cfg_addr = port->cfg_base;
+
+     val = readl(cfg_addr + PCI_PRIMARY_BUS);
+     val &= ~PCI_PRIMARY_BUS_MASK;
+     val |= (last_busno << 16) | ((first_busno + 1) << 8) | (first_busno);
+     writel(val, cfg_addr + PCI_PRIMARY_BUS);
+}

Please explain what you are doing here. As mentioned above, I would expect that each domain has visibility of all 255 buses. You shouldn't need any hacks where you try to artificially squeeze the ports into a single domain when they are separate in hardware.

ok. I will check and get back.

Quoted 9 lines

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

Quoted 5 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+/*
+ * read configuration values from DTS
+ */
+static int xgene_pcie_read_dts_config(struct xgene_pcie_port *port)

The comment and function name don't seem to match what the function does. The main purpose of this function seems to be to ioremap the resources, which have nothing to with configuration.

ok.

Quoted 15 lines

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

Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +11 -0
+{
+     struct device_node *np = port->node;
+     struct resource csr_res;
+     struct resource cfg_res;
+
+     /* Get CSR space registers address */
+     if (of_address_to_resource(np, 0, &csr_res))
+             return -EINVAL;
+
+     port->csr_base = devm_ioremap_nocache(port->dev, csr_res.start,
+                                           resource_size(&csr_res));

You can also use platform_get_resource() to access the resource that is already there, rather than creating another one.

ok.

Quoted 15 lines

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

Quoted 11 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+static void xgene_pcie_setup_ob_reg(struct xgene_pcie_port *port,
+                                 u32 addr, u32 restype)
+{
+     struct resource *res = NULL;
+     void *base = port->csr_base + addr;
+     resource_size_t size;
+     u64 cpu_addr = 0;
+     u64 pci_addr = 0;
+     u64 mask = 0;
+     u32 min_size = 0;

A general note: don't initialize local variables to a bogus valus (e.g. 0) in their declaration. It prevents the compiler from warning about incorrect uses.

ok.

Quoted 20 lines
Quoted 2 lines

+ u32 flag = EN_REG;

This one on the other hand is ok, because you are actually going to use that value.

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

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+     switch (restype) {
+     case IORESOURCE_MEM:
+             res = &port->mem.res;
+             pci_addr = port->mem.pci_addr;
+             min_size = SZ_128M;
+             break;
+     case IORESOURCE_IO:
+             res = &port->io.res;
+             pci_addr = port->io.pci_addr;
+             min_size = 128;
+             flag |= OB_LO_IO;
+             break;
+     }
Quoted 4 lines

I assume this works ok, but seems wrong in one detail: If the resource is marked IORESOURCE_IO, res->start is supposed to be in I/O space, not in memory space, which would make it the wrong number to program into the hardware registers.

Yes for using ioport resource. However we have decided to defer using it since 'pci_ioremap_io' is not yet supported from arm64 side.

Quoted 1 line

From HW point of view, for memory mapped IO space, it is nothing but a

piece taken out of the ranges in address map for outbound accesses. So while configuring registers from SOC side, it should take the CPU address which is address from SOC address map. Right?

Later on we can have a separate io resource like 'realio' similar to what pci-mvebu.c does.

Quoted 16 lines
Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +3 -0
+static int xgene_pcie_parse_map_ranges(struct xgene_pcie_port *port)
+{
+     struct device_node *np = port->node;

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     struct of_pci_range range;
+     struct of_pci_range_parser parser;
+     struct device *dev = port->dev;
+
+     if (of_pci_range_parser_init(&parser, np)) {
+             dev_err(dev, "missing ranges property\n");
+             return -EINVAL;
+     }
+
+     /* Get the I/O, memory, config ranges from DT */

The comment needs updating now that you don't read config space here any more.

ok.

Quoted 20 lines
Quoted 20 lines
drivers/pci/host/pci-xgene.c new file +19 -0
+/* X-Gene PCIe support maximum 3 inbound memory regions
+ * This function helps to select a region based on size of region
+ */
+static int xgene_pcie_select_ib_reg(u64 size)
+{
+     static u8 ib_reg_mask;
+
+     if ((size > 4) && (size < SZ_16M) && !(ib_reg_mask & (1 << 1))) {
+             ib_reg_mask |= (1 << 1);
+             return 1;
+     }
+
+     if ((size > SZ_1K) && (size < SZ_1T) && !(ib_reg_mask & (1 << 0))) {
+             ib_reg_mask |= (1 << 0);
+             return 0;
+     }
+
+     if ((size > SZ_1M) && (size < SZ_1T) && !(ib_reg_mask & (1 << 2))) {
+             ib_reg_mask |= (1 << 2);
Quoted 8 lines

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

Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+             return 2;
+     }
+     return -EINVAL;
+}

Shouldn't the ib_reg_mask variable be per host bridge? Static variables are dangerous if you ever get multiple instances of the hardware in one system.

Yes. You are right. Thanks.

Quoted 33 lines
Quoted 19 lines
drivers/pci/host/pci-xgene.c new file +18 -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;
+     int region;
+
+     if (pci_dma_range_parser_init(&parser, np)) {
+             dev_err(dev, "missing dma-ranges property\n");
+             return -EINVAL;
+     }
+
+     /* Get the dma-ranges from DT */
+     for_each_of_pci_range(&parser, &range) {
+             u64 restype = range.flags & IORESOURCE_TYPE_BITS;
+             u64 end = range.cpu_addr + range.size - 1;
+             dev_dbg(port->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+                     range.flags, range.cpu_addr, end, range.pci_addr);
+             region = xgene_pcie_select_ib_reg(range.size);
+             if (region == -EINVAL) {
+                     dev_warn(port->dev, "invalid pcie dma-range config\n");
+                     continue;
+             }
+             xgene_pcie_setup_ib_reg(port, &range, restype, region);
+     }
+     return 0;
+}

I guess is could even be a local variable in this function, which you pass by reference.

Quoted 16 lines

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

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+
+static int xgene_pcie_setup(int nr, struct pci_sys_data *sys)
+{
+     struct xgene_pcie_port *pp = xgene_pcie_sys_to_port(sys);
+
+     if (pp == NULL)
+             return 0;
+
+     sys->mem_offset = pp->mem.res.start - pp->mem.pci_addr;
+     pci_add_resource_offset(&sys->resources, &pp->mem.res,
+                             sys->mem_offset);
+     return 1;
+}

Please follow the regular error handling conventions, which are to pass a negative errno value on error and zero on success.

ok.

Quoted 5 lines

Also, what would be a reason for the port to be zero here? If it's something that can't happen in practice, don't try to handle it gracefully. You can use BUG_ON() for fatal conditions that are supposed to be impossible to reach.

This function is a hook to upper layer. We register nr_controllers in hw_pci structure as MAX_PORTS we support. It can happen that number of ports actually enabled from device tree are less than the number in nr_controllers.

Quoted 17 lines

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

Quoted 11 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+static struct pci_bus __init *xgene_pcie_scan_bus(int nr,
+                                               struct pci_sys_data *sys)
+{
+     struct xgene_pcie_port *pp = xgene_pcie_sys_to_port(sys);
+
+     pp->first_busno = sys->busnr;
+     xgene_pcie_setup_primary_bus(pp, sys->busnr, 0xff);
+     return pci_scan_root_bus(NULL, sys->busnr, &xgene_pcie_ops,
+                              sys, &sys->resources);
+}

You have a number of helper functions that don't seem to gain much at all. Just move the call to pci_scan_root_bus() into xgene_pcie_setup_primary_bus() here, and use that as the .scan callback.

I can do that if I can get rid of setup_primary_bus api. Let me check.

Quoted 11 lines
Quoted 11 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     if (!port->link_up)
+             dev_info(port->dev, "(rc) link down\n");
+     else
+             dev_info(port->dev, "(rc) x%d gen-%d link up\n",
+                             lanes, port->link_speed + 1);
+#ifdef CONFIG_PCI_DOMAINS
+     xgene_pcie_hw.domain++;
+#endif
+     xgene_pcie_hw.private_data[index++] = port;
+     platform_set_drvdata(pdev, port);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+     return 0;
+}

Do you have multiple domains or not? I don't see how it can work if you make the domain setup conditional on a kernel configuration option. If you in fact have multiple domains, make sure in Kconfig that CONFIG_PCI_DOMAINS is enabled. Otherwise don't mess with the domain number...

It is enabled in Kconfig.

Quoted 10 lines

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

Quoted 5 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+static const struct of_device_id xgene_pcie_match_table[] __initconst = {
+     {.compatible = "apm,xgene-pcie",},
+     {},
+};

Another general note: Your "compatible" strings are rather unspecific. Do you have a version number for this IP block? I suppose that it's related to one that has been used in other chips before, or will be used in future chips, if it's not actually licensed from some other company.

I will have to check this.

Quoted 14 lines

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+static int __init xgene_pcie_init(void)
+{
+     void *private;
+     int ret;
+
+     pr_info("X-Gene: PCIe driver\n");
+
+     /* allocate private data to keep xgene_pcie_port information */
+     private = kzalloc((XGENE_PCIE_MAX_PORTS * sizeof(void *)), GFP_KERNEL);

This should not be done unconditionally: There is no point in printing a message or allocating memory if you don't actually run on a system with this device.

I am doing this here because I have one instance of hw_pci structure with multiple pcie controllers. I can't do it from probe since it will be called once per instance in device tree.

Quoted 6 lines

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

Quoted 3 lines
drivers/pci/host/pci-xgene.c new file +2 -0
+     if (private == NULL)
+             return -ENOMEM;

Style: if you are testing for an object, just write 'if (private)' or 'if (!private)', but don't compare against NULL.

ok.

Quoted 11 lines

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

Quoted 8 lines
drivers/pci/host/pci-xgene.c new file +7 -0
+     xgene_pcie_hw.private_data = private;
+     ret = platform_driver_probe(&xgene_pcie_driver,
+                                 xgene_pcie_probe_bridge);
+     if (ret)
+             return ret;
+     pci_common_init(&xgene_pcie_hw);
+     return 0;

This seems wrong: You should not use platform_driver_probe() because that has issues with deferred probing.

I think 'platform_driver_probe' prevents the deferred probing. 'pci_common_init' needs to be called only once with current driver structure. The probes for all pcie ports should be finished (ports initialized) before 'pci_common_init' gets called.

Quoted 2 lines

Arnd

#4 lore raw

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

Quoted 8 lines · Tanmay Inamdar
Quoted 7 lines · Arnd Bergmann
Quoted 5 lines · Tanmay Inamdar

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 has maximum 5 PCIe ports supported.

Quoted 7 lines
Quoted 5 lines

This already looks much better than the first version, but I have a more comments. Most importantly, it would help to know how the root ports are structured. Is this a standard root complex and multiple ports, multiple root complexes with one port each, or a nonstandard organization that is a mix of those two models?

This is multiple root complexes with one port each.

Ok.

Quoted 12 lines
Quoted 4 lines

I also wonder why you need to do this at all. If there isn't a global config space for all ports, but rather a separate type0/type1 config cycle based on the bus number, I see that as an indication that the ports are in fact separate domains and should each start with bus 0.

It is not a standard ECAM layout. We also have a separate RTDID register as well to program bus, device, function. While accessing EP config space, we have to set the bit 17:16 as 2b'01. The same config space address is utilized for enabling a customized nonstandard PCIe DMA feature. The bits are defined to differentiate the access purpose. The feature is not supported in this driver yet.

Quoted 3 lines

Secondly I don't think it will matter if each port starts with bus 0. As long as we set the correct BDF in RTDID and set correct bits in config address, the config reads and writes would work. Right?

Yes, I think the current code will work (aside from my other comment), but it seems unnecessary to do this if you use pci domains correctly:

If you have one pci domain and one root port per root complex, you would not get any config space cycles for the root port and can do away with the special case here, as well as with the xgene_pcie_fixup_bridge() that seems to be a special case to avoid touching the root ports as well.

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+     switch (restype) {
+     case IORESOURCE_MEM:
+             res = &port->mem.res;
+             pci_addr = port->mem.pci_addr;
+             min_size = SZ_128M;
+             break;
+     case IORESOURCE_IO:
+             res = &port->io.res;
+             pci_addr = port->io.pci_addr;
+             min_size = 128;
+             flag |= OB_LO_IO;
+             break;
+     }
Quoted 4 lines
Quoted 4 lines

I assume this works ok, but seems wrong in one detail: If the resource is marked IORESOURCE_IO, res->start is supposed to be in I/O space, not in memory space, which would make it the wrong number to program into the hardware registers.

Sorry, I was actually wrong with my statement above and I thought I had deleted my comment before sending the mail.

Quoted 10 lines

Yes for using ioport resource. However we have decided to defer using it since 'pci_ioremap_io' is not yet supported from arm64 side.

From HW point of view, for memory mapped IO space, it is nothing but a piece taken out of the ranges in address map for outbound accesses. So while configuring registers from SOC side, it should take the CPU address which is address from SOC address map. Right?

Later on we can have a separate io resource like 'realio' similar to what pci-mvebu.c does.

I think your code is actually correct here, but please also add the pci_ioremap_io implementation for arm64 in a separate patch in this series. It shouldn't be hard and we need it for every pci host driver anyway.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+static int xgene_pcie_setup(int nr, struct pci_sys_data *sys)
+{
+     struct xgene_pcie_port *pp = xgene_pcie_sys_to_port(sys);
+
+     if (pp == NULL)
+             return 0;
+
+     sys->mem_offset = pp->mem.res.start - pp->mem.pci_addr;
+     pci_add_resource_offset(&sys->resources, &pp->mem.res,
Quoted 8 lines

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

Quoted 3 lines
drivers/pci/host/pci-xgene.c new file +3 -0
+                             sys->mem_offset);
+     return 1;
+}

Also, what would be a reason for the port to be zero here? If it's something that can't happen in practice, don't try to handle it gracefully. You can use BUG_ON() for fatal conditions that are supposed to be impossible to reach.

Quoted 4 lines

This function is a hook to upper layer. We register nr_controllers in hw_pci structure as MAX_PORTS we support. It can happen that number of ports actually enabled from device tree are less than the number in nr_controllers.

I see. I'll comment more on this below.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     if (!port->link_up)
+             dev_info(port->dev, "(rc) link down\n");
+     else
+             dev_info(port->dev, "(rc) x%d gen-%d link up\n",
+                             lanes, port->link_speed + 1);
+#ifdef CONFIG_PCI_DOMAINS
+     xgene_pcie_hw.domain++;
+#endif
+     xgene_pcie_hw.private_data[index++] = port;
+     platform_set_drvdata(pdev, port);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+     return 0;
+}

Do you have multiple domains or not? I don't see how it can work if you make the domain setup conditional on a kernel configuration option. If you in fact have multiple domains, make sure in Kconfig that CONFIG_PCI_DOMAINS is enabled. Otherwise don't mess with the domain number...

Quoted 1 line

It is enabled in Kconfig.

Ok, then remove the #ifdef here.

Quoted 27 lines
Quoted 5 lines
Quoted 5 lines
drivers/pci/host/pci-xgene.c new file +5 -0
+static int __init xgene_pcie_init(void)
+{
+     void *private;
+     int ret;
+
Quoted 8 lines

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

Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+     pr_info("X-Gene: PCIe driver\n");
+
+     /* allocate private data to keep xgene_pcie_port information */
+     private = kzalloc((XGENE_PCIE_MAX_PORTS * sizeof(void *)), GFP_KERNEL);

This should not be done unconditionally: There is no point in printing a message or allocating memory if you don't actually run on a system with this device.

I am doing this here because I have one instance of hw_pci structure with multiple pcie controllers. I can't do it from probe since it will be called once per instance in device tree.

Quoted 9 lines
Quoted 8 lines
drivers/pci/host/pci-xgene.c new file +7 -0
+     xgene_pcie_hw.private_data = private;
+     ret = platform_driver_probe(&xgene_pcie_driver,
+                                 xgene_pcie_probe_bridge);
+     if (ret)
+             return ret;
+     pci_common_init(&xgene_pcie_hw);
+     return 0;
Quoted 7 lines
Quoted 2 lines

This seems wrong: You should not use platform_driver_probe() because that has issues with deferred probing.

I think 'platform_driver_probe' prevents the deferred probing. 'pci_common_init' needs to be called only once with current driver structure. The probes for all pcie ports should be finished (ports initialized) before 'pci_common_init' gets called.

I think it would be cleaner for dynamically registered host controllers to call pci_common_init_dev() with nr_controllers=1 once for each root complex in the probe() function. This should take care of a few other things I've mentioned as well.

Arnd

#5 lore raw

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

In reply to Tanmay Inamdar
Quoted 168 lines · Tanmay Inamdar
Quoted 5 lines · Arnd Bergmann
Quoted 4 lines · Tanmay Inamdar

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 has maximum 5 PCIe ports supported.

Quoted 7 lines
Quoted 1 line

This already looks much better than the first version, but I have a more comments. Most importantly, it would help to know how the root ports are structured. Is this a standard root complex and multiple ports, multiple root complexes with one port each, or a nonstandard organization that is a mix of those two models?

This is multiple root complexes with one port each.

Quoted 12 lines
Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +11 -0
+
+/* When the address bit [17:16] is 2'b01, the Configuration access will be
+ * treated as Type 1 and it will be forwarded to external PCIe device.
+ */
+static void __iomem *xgene_pcie_get_cfg_base(struct pci_bus *bus)
+{
+     struct xgene_pcie_port *port = xgene_pcie_bus_to_port(bus);
+     u64 addr = (u64)port->cfg_base;
+
+     if (bus->number >= (port->first_busno + 1))
+             addr |= AXI_EP_CFG_ACCESS;
Quoted 8 lines

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

Quoted 3 lines
drivers/pci/host/pci-xgene.c new file +3 -0
+
+     return (void *)addr;
+}

Wrong type, it should be 'void __iomem *'. Also you can't assume that bit operations work on virtual __iomem addresses, so it should be better to just add a constant integer to the pointer, which is a valid operation.

ok.

Quoted 5 lines

I also wonder why you need to do this at all. If there isn't a global config space for all ports, but rather a separate type0/type1 config cycle based on the bus number, I see that as an indication that the ports are in fact separate domains and should each start with bus 0.

It is not a standard ECAM layout. We also have a separate RTDID register as well to program bus, device, function. While accessing EP config space, we have to set the bit 17:16 as 2b'01. The same config space address is utilized for enabling a customized nonstandard PCIe DMA feature. The bits are defined to differentiate the access purpose. The feature is not supported in this driver yet.

Secondly I don't think it will matter if each port starts with bus 0. As long as we set the correct BDF in RTDID and set correct bits in config address, the config reads and writes would work. Right?

Quoted 26 lines
Quoted 26 lines
drivers/pci/host/pci-xgene.c new file +25 -0
+static void xgene_pcie_setup_lanes(struct xgene_pcie_port *port)
+{
+     void *csr_base = port->csr_base;
+     u32 val;
+
+     val = readl(csr_base + BRIDGE_8G_CFG_8);
+     val = eq_pre_cursor_lane0_set(val, 0x7);
+     val = eq_pre_cursor_lane1_set(val, 0x7);
+     writel(val, csr_base + BRIDGE_8G_CFG_8);
+
+     val = readl(csr_base + BRIDGE_8G_CFG_9);
+     val = eq_pre_cursor_lane0_set(val, 0x7);
+     val = eq_pre_cursor_lane1_set(val, 0x7);
+     writel(val, csr_base + BRIDGE_8G_CFG_9);
+
+     val = readl(csr_base + BRIDGE_8G_CFG_10);
+     val = eq_pre_cursor_lane0_set(val, 0x7);
+     val = eq_pre_cursor_lane1_set(val, 0x7);
+     writel(val, csr_base + BRIDGE_8G_CFG_10);
+
+     val = readl(csr_base + BRIDGE_8G_CFG_11);
+     val = eq_pre_cursor_lane0_set(val, 0x7);
+     val = eq_pre_cursor_lane1_set(val, 0x7);
+     writel(val, csr_base + BRIDGE_8G_CFG_11);
+
Quoted 8 lines

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

Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+     val = readl(csr_base + BRIDGE_8G_CFG_4);
+     val = (val & ~0x30) | (1 << 4);
+     writel(val, csr_base + BRIDGE_8G_CFG_4);
+}

Please document what you are actually setting here. If the configuration of the lanes is always the same, why do you have to set it here. If not, why do you set constant values?

Good point. Let me check if these values should be constant or tune-able.

Quoted 29 lines
Quoted 16 lines
drivers/pci/host/pci-xgene.c new file +15 -0
+static void xgene_pcie_setup_link(struct xgene_pcie_port *port)
+{
+     void *csr_base = port->csr_base;
+     u32 val;
+
+     val = readl(csr_base + BRIDGE_CFG_14);
+     val |= DIRECT_TO_8GTS_MASK;
+     val |= SUPPORT_5GTS_MASK;
+     val |= SUPPORT_8GTS_MASK;
+     val |= DIRECT_TO_5GTS_MASK;
+     writel(val, csr_base + BRIDGE_CFG_14);
+
+     val = readl(csr_base + BRIDGE_CFG_14);
+     val &= ~ADVT_INFINITE_CREDITS;
+     writel(val, csr_base + BRIDGE_CFG_14);

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+
+     val = readl(csr_base + BRIDGE_8G_CFG_0);
+     val |= (val & ~0xf) | 7;
+     val |= (val & ~0xf00) | ((7 << 8) & 0xf00);
+     writel(val, csr_base + BRIDGE_8G_CFG_0);
+
+     val = readl(csr_base + BRIDGE_8G_CFG_0);
+     val |= DWNSTRM_EQ_SKP_PHS_2_3;
+     writel(val, csr_base + BRIDGE_8G_CFG_0);
+}

Same here.

Quoted 14 lines

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

Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +12 -0
+static void xgene_pcie_program_core(void *csr_base)
+{
+     u32 val;
+
+     val = readl(csr_base + BRIDGE_CFG_0);
+     val |= AER_OPTIONAL_ERROR_EN;
+     writel(val, csr_base + BRIDGE_CFG_0);
+     writel(0x0, csr_base + INTXSTATUSMASK);
+     val = readl(csr_base + BRIDGE_CTRL_1);
+     val = (val & ~0xffff) | XGENE_PCIE_DEV_CTRL;
+     writel(val, csr_base + BRIDGE_CTRL_1);
+}

'program_core'?

Some of the PCIe core related misc configurations.

Quoted 20 lines
Quoted 20 lines
drivers/pci/host/pci-xgene.c new file +19 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port, u32 *lanes)
+{
+     void *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) {
+                     port->link_up = 1;
+                     port->link_speed = PIPE_PHY_RATE_RD(val32);
+                     val32 = readl(csr_base + BRIDGE_STATUS_0);
Quoted 8 lines

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

Quoted 5 lines
drivers/pci/host/pci-xgene.c new file +5 -0
+                     *lanes = val32 >> 26;
+             }
+             time = jiffies_to_msecs(jiffies - start_time);
+     } while ((!port->link_up) || (time <= XGENE_LTSSM_L0_WAIT));
+}

Maybe another msleep() in the loop? It seems weird to first do an unconditional sleep but then busy-wait for the result.

Quoted 1 line

ok.

This loop can execute for maximum 4 msec. So putting msleep(1) won't get us much.

Quoted 19 lines
Quoted 18 lines

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

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +11 -0
+static void xgene_pcie_setup_primary_bus(struct xgene_pcie_port *port,
+                                      u32 first_busno, u32 last_busno)
+{
+     u32 val;
+     void *cfg_addr = port->cfg_base;
+
+     val = readl(cfg_addr + PCI_PRIMARY_BUS);
+     val &= ~PCI_PRIMARY_BUS_MASK;
+     val |= (last_busno << 16) | ((first_busno + 1) << 8) | (first_busno);
+     writel(val, cfg_addr + PCI_PRIMARY_BUS);
+}

Please explain what you are doing here. As mentioned above, I would expect that each domain has visibility of all 255 buses. You shouldn't need any hacks where you try to artificially squeeze the ports into a single domain when they are separate in hardware.

Quoted 1 line

ok. I will check and get back.

You are right. I have removed this hack. It will be fixed in next version.

Quoted 251 lines
Quoted 10 lines

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

Quoted 6 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+/*
+ * read configuration values from DTS
+ */
+static int xgene_pcie_read_dts_config(struct xgene_pcie_port *port)

The comment and function name don't seem to match what the function does. The main purpose of this function seems to be to ioremap the resources, which have nothing to with configuration.

ok.

Quoted 15 lines

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

Quoted 12 lines
drivers/pci/host/pci-xgene.c new file +11 -0
+{
+     struct device_node *np = port->node;
+     struct resource csr_res;
+     struct resource cfg_res;
+
+     /* Get CSR space registers address */
+     if (of_address_to_resource(np, 0, &csr_res))
+             return -EINVAL;
+
+     port->csr_base = devm_ioremap_nocache(port->dev, csr_res.start,
+                                           resource_size(&csr_res));

You can also use platform_get_resource() to access the resource that is already there, rather than creating another one.

ok.

Quoted 15 lines

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

Quoted 11 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+static void xgene_pcie_setup_ob_reg(struct xgene_pcie_port *port,
+                                 u32 addr, u32 restype)
+{
+     struct resource *res = NULL;
+     void *base = port->csr_base + addr;
+     resource_size_t size;
+     u64 cpu_addr = 0;
+     u64 pci_addr = 0;
+     u64 mask = 0;
+     u32 min_size = 0;

A general note: don't initialize local variables to a bogus valus (e.g. 0) in their declaration. It prevents the compiler from warning about incorrect uses.

ok.

Quoted 20 lines
Quoted 2 lines

+ u32 flag = EN_REG;

This one on the other hand is ok, because you are actually going to use that value.

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

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+     switch (restype) {
+     case IORESOURCE_MEM:
+             res = &port->mem.res;
+             pci_addr = port->mem.pci_addr;
+             min_size = SZ_128M;
+             break;
+     case IORESOURCE_IO:
+             res = &port->io.res;
+             pci_addr = port->io.pci_addr;
+             min_size = 128;
+             flag |= OB_LO_IO;
+             break;
+     }
Quoted 4 lines

I assume this works ok, but seems wrong in one detail: If the resource is marked IORESOURCE_IO, res->start is supposed to be in I/O space, not in memory space, which would make it the wrong number to program into the hardware registers.

Yes for using ioport resource. However we have decided to defer using it since 'pci_ioremap_io' is not yet supported from arm64 side.

From HW point of view, for memory mapped IO space, it is nothing but a piece taken out of the ranges in address map for outbound accesses. So while configuring registers from SOC side, it should take the CPU address which is address from SOC address map. Right?

Later on we can have a separate io resource like 'realio' similar to what pci-mvebu.c does.

Quoted 16 lines
Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +3 -0
+static int xgene_pcie_parse_map_ranges(struct xgene_pcie_port *port)
+{
+     struct device_node *np = port->node;

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     struct of_pci_range range;
+     struct of_pci_range_parser parser;
+     struct device *dev = port->dev;
+
+     if (of_pci_range_parser_init(&parser, np)) {
+             dev_err(dev, "missing ranges property\n");
+             return -EINVAL;
+     }
+
+     /* Get the I/O, memory, config ranges from DT */

The comment needs updating now that you don't read config space here any more.

ok.

Quoted 20 lines
Quoted 20 lines
drivers/pci/host/pci-xgene.c new file +19 -0
+/* X-Gene PCIe support maximum 3 inbound memory regions
+ * This function helps to select a region based on size of region
+ */
+static int xgene_pcie_select_ib_reg(u64 size)
+{
+     static u8 ib_reg_mask;
+
+     if ((size > 4) && (size < SZ_16M) && !(ib_reg_mask & (1 << 1))) {
+             ib_reg_mask |= (1 << 1);
+             return 1;
+     }
+
+     if ((size > SZ_1K) && (size < SZ_1T) && !(ib_reg_mask & (1 << 0))) {
+             ib_reg_mask |= (1 << 0);
+             return 0;
+     }
+
+     if ((size > SZ_1M) && (size < SZ_1T) && !(ib_reg_mask & (1 << 2))) {
+             ib_reg_mask |= (1 << 2);
Quoted 8 lines

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

Quoted 4 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+             return 2;
+     }
+     return -EINVAL;
+}

Shouldn't the ib_reg_mask variable be per host bridge? Static variables are dangerous if you ever get multiple instances of the hardware in one system.

Yes. You are right. Thanks.

Quoted 33 lines
Quoted 19 lines
drivers/pci/host/pci-xgene.c new file +18 -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;
+     int region;
+
+     if (pci_dma_range_parser_init(&parser, np)) {
+             dev_err(dev, "missing dma-ranges property\n");
+             return -EINVAL;
+     }
+
+     /* Get the dma-ranges from DT */
+     for_each_of_pci_range(&parser, &range) {
+             u64 restype = range.flags & IORESOURCE_TYPE_BITS;
+             u64 end = range.cpu_addr + range.size - 1;
+             dev_dbg(port->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+                     range.flags, range.cpu_addr, end, range.pci_addr);
+             region = xgene_pcie_select_ib_reg(range.size);
+             if (region == -EINVAL) {
+                     dev_warn(port->dev, "invalid pcie dma-range config\n");
+                     continue;
+             }
+             xgene_pcie_setup_ib_reg(port, &range, restype, region);
+     }
+     return 0;
+}

I guess is could even be a local variable in this function, which you pass by reference.

Quoted 16 lines

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

Quoted 13 lines
drivers/pci/host/pci-xgene.c new file +13 -0
+
+static int xgene_pcie_setup(int nr, struct pci_sys_data *sys)
+{
+     struct xgene_pcie_port *pp = xgene_pcie_sys_to_port(sys);
+
+     if (pp == NULL)
+             return 0;
+
+     sys->mem_offset = pp->mem.res.start - pp->mem.pci_addr;
+     pci_add_resource_offset(&sys->resources, &pp->mem.res,
+                             sys->mem_offset);
+     return 1;
+}

Please follow the regular error handling conventions, which are to pass a negative errno value on error and zero on success.

ok.

Quoted 5 lines

Also, what would be a reason for the port to be zero here? If it's something that can't happen in practice, don't try to handle it gracefully. You can use BUG_ON() for fatal conditions that are supposed to be impossible to reach.

This function is a hook to upper layer. We register nr_controllers in hw_pci structure as MAX_PORTS we support. It can happen that number of ports actually enabled from device tree are less than the number in nr_controllers.

Quoted 17 lines

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

Quoted 11 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+static struct pci_bus __init *xgene_pcie_scan_bus(int nr,
+                                               struct pci_sys_data *sys)
+{
+     struct xgene_pcie_port *pp = xgene_pcie_sys_to_port(sys);
+
+     pp->first_busno = sys->busnr;
+     xgene_pcie_setup_primary_bus(pp, sys->busnr, 0xff);
+     return pci_scan_root_bus(NULL, sys->busnr, &xgene_pcie_ops,
+                              sys, &sys->resources);
+}

You have a number of helper functions that don't seem to gain much at all. Just move the call to pci_scan_root_bus() into xgene_pcie_setup_primary_bus() here, and use that as the .scan callback.

I can do that if I can get rid of setup_primary_bus api. Let me check.

Quoted 11 lines
Quoted 11 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+     if (!port->link_up)
+             dev_info(port->dev, "(rc) link down\n");
+     else
+             dev_info(port->dev, "(rc) x%d gen-%d link up\n",
+                             lanes, port->link_speed + 1);
+#ifdef CONFIG_PCI_DOMAINS
+     xgene_pcie_hw.domain++;
+#endif
+     xgene_pcie_hw.private_data[index++] = port;
+     platform_set_drvdata(pdev, port);
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+     return 0;
+}

Do you have multiple domains or not? I don't see how it can work if you make the domain setup conditional on a kernel configuration option. If you in fact have multiple domains, make sure in Kconfig that CONFIG_PCI_DOMAINS is enabled. Otherwise don't mess with the domain number...

It is enabled in Kconfig.

Quoted 10 lines

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

Quoted 5 lines
drivers/pci/host/pci-xgene.c new file +4 -0
+static const struct of_device_id xgene_pcie_match_table[] __initconst = {
+     {.compatible = "apm,xgene-pcie",},
+     {},
+};

Another general note: Your "compatible" strings are rather unspecific. Do you have a version number for this IP block? I suppose that it's related to one that has been used in other chips before, or will be used in future chips, if it's not actually licensed from some other company.

Quoted 2 lines

I will have to check this.

We have decided to stick with current compatible string for now.

Quoted 47 lines
Quoted 14 lines

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +9 -0
+static int __init xgene_pcie_init(void)
+{
+     void *private;
+     int ret;
+
+     pr_info("X-Gene: PCIe driver\n");
+
+     /* allocate private data to keep xgene_pcie_port information */
+     private = kzalloc((XGENE_PCIE_MAX_PORTS * sizeof(void *)), GFP_KERNEL);

This should not be done unconditionally: There is no point in printing a message or allocating memory if you don't actually run on a system with this device.

I am doing this here because I have one instance of hw_pci structure with multiple pcie controllers. I can't do it from probe since it will be called once per instance in device tree.

Quoted 6 lines

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

Quoted 3 lines
drivers/pci/host/pci-xgene.c new file +2 -0
+     if (private == NULL)
+             return -ENOMEM;

Style: if you are testing for an object, just write 'if (private)' or 'if (!private)', but don't compare against NULL.

ok.

Quoted 11 lines

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

Quoted 8 lines
drivers/pci/host/pci-xgene.c new file +7 -0
+     xgene_pcie_hw.private_data = private;
+     ret = platform_driver_probe(&xgene_pcie_driver,
+                                 xgene_pcie_probe_bridge);
+     if (ret)
+             return ret;
+     pci_common_init(&xgene_pcie_hw);
+     return 0;

This seems wrong: You should not use platform_driver_probe() because that has issues with deferred probing.

I think 'platform_driver_probe' prevents the deferred probing. 'pci_common_init' needs to be called only once with current driver structure. The probes for all pcie ports should be finished (ports initialized) before 'pci_common_init' gets called.

Quoted 2 lines

Arnd

#6 lore raw

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

Quoted 33 lines · On Friday 24 January 2014 13:28:22 Tanmay Inamdar wrote:
Quoted 32 lines · Tanmay Inamdar
Quoted 30 lines · Arnd Bergmann
Quoted 14 lines · Tanmay Inamdar
drivers/pci/host/pci-xgene.c new file +14 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port, u32 *lanes)
+{
+     void *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 {

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+             val32 = readl(csr_base + PCIECORE_CTLANDSTATUS);
+             if (val32 & LINK_UP_MASK) {
+                     port->link_up = 1;
+                     port->link_speed = PIPE_PHY_RATE_RD(val32);
+                     val32 = readl(csr_base + BRIDGE_STATUS_0);
+                     *lanes = val32 >> 26;
+             }
+             time = jiffies_to_msecs(jiffies - start_time);
+     } while ((!port->link_up) || (time <= XGENE_LTSSM_L0_WAIT));
+}

Maybe another msleep() in the loop? It seems weird to first do an unconditional sleep but then busy-wait for the result.

Quoted 4 lines
Quoted 1 line

ok.

This loop can execute for maximum 4 msec. So putting msleep(1) won't get us much.

4 msec is still quite a long time for a busy loop that can be spent doing useful work in another thread.

Quoted 10 lines
Quoted 8 lines
Quoted 5 lines

Another general note: Your "compatible" strings are rather unspecific. Do you have a version number for this IP block? I suppose that it's related to one that has been used in other chips before, or will be used in future chips, if it's not actually licensed from some other company.

I will have to check this.

We have decided to stick with current compatible string for now.

Can you elaborate on your reasoning? Does this mean X-Gene is a one-off product and you won't be doing any new chips based on the same hardware components?

Arnd

#7 lore raw

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

Quoted 34 lines · Arnd Bergmann
Quoted 33 lines · On Friday 24 January 2014 13:28:22 Tanmay Inamdar wrote:
Quoted 32 lines · Tanmay Inamdar
Quoted 30 lines · Arnd Bergmann
Quoted 14 lines · Tanmay Inamdar
drivers/pci/host/pci-xgene.c new file +14 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port, u32 *lanes)
+{
+     void *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 {

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+             val32 = readl(csr_base + PCIECORE_CTLANDSTATUS);
+             if (val32 & LINK_UP_MASK) {
+                     port->link_up = 1;
+                     port->link_speed = PIPE_PHY_RATE_RD(val32);
+                     val32 = readl(csr_base + BRIDGE_STATUS_0);
+                     *lanes = val32 >> 26;
+             }
+             time = jiffies_to_msecs(jiffies - start_time);
+     } while ((!port->link_up) || (time <= XGENE_LTSSM_L0_WAIT));
+}

Maybe another msleep() in the loop? It seems weird to first do an unconditional sleep but then busy-wait for the result.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

ok.

This loop can execute for maximum 4 msec. So putting msleep(1) won't get us much.

4 msec is still quite a long time for a busy loop that can be spent doing useful work in another thread.

Right. If 'msleep(1)' is used, then 'checkpatch' throws a warning saying that it can actually sleep for 20ms in some cases. I will check if 'usleep_range' is useful here.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Another general note: Your "compatible" strings are rather unspecific. Do you have a version number for this IP block? I suppose that it's related to one that has been used in other chips before, or will be used in future chips, if it's not actually licensed from some other company.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I will have to check this.

We have decided to stick with current compatible string for now.

Can you elaborate on your reasoning? Does this mean X-Gene is a one-off product and you won't be doing any new chips based on the same hardware components?

The current convention is to key upon the family name - X-Gene. Future chips will also be a part of X-Gene family. Right now it is unclear if there are any obvious feature additions to be done in Linux PCIe driver. Until then same driver is expected to work as is in future chips.

Quoted 2 lines

Arnd

#8 lore raw

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

Quoted 14 lines · Tanmay Inamdar
Quoted 13 lines · Arnd Bergmann
Quoted 11 lines · On Friday 24 January 2014 13:28:22 Tanmay Inamdar wrote:
Quoted 7 lines · Tanmay Inamdar
Quoted 4 lines · Arnd Bergmann

On Wednesday 15 January 2014, Tanmay Inamdar wrote:

Maybe another msleep() in the loop? It seems weird to first do an unconditional sleep but then busy-wait for the result.

ok.

This loop can execute for maximum 4 msec. So putting msleep(1) won't get us much.

Quoted 7 lines
Quoted 3 lines

4 msec is still quite a long time for a busy loop that can be spent doing useful work in another thread.

Right. If 'msleep(1)' is used, then 'checkpatch' throws a warning saying that it can actually sleep for 20ms in some cases. I will check if 'usleep_range' is useful here.

Sound good. This is really a false positive from checkpatch though, with the timeout handling in place, everything's fine even with msleep(1).

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Another general note: Your "compatible" strings are rather unspecific. Do you have a version number for this IP block? I suppose that it's related to one that has been used in other chips before, or will be used in future chips, if it's not actually licensed from some other company.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I will have to check this.

We have decided to stick with current compatible string for now.

Can you elaborate on your reasoning? Does this mean X-Gene is a one-off product and you won't be doing any new chips based on the same hardware components?

Quoted 5 lines

The current convention is to key upon the family name - X-Gene. Future chips will also be a part of X-Gene family. Right now it is unclear if there are any obvious feature additions to be done in Linux PCIe driver. Until then same driver is expected to work as is in future chips.

This is not enough for me. Of course you hope that things keep working, but experience shows that sometimes hardware has slight differences that you need to work around later. It's better to always be specific and at least as a secondary identifier list the exact model of the component, or if that is not know, the model of the SoC. The driver can bind to the most generic string, but in DT you should have a specific one as well.

You could for instance have something like

	compatible = "apm,xgene-1234w78-pcie", "thirdparty,pcie-1.23", "apm,xgene-pcie", "thirdparty,pcie";

as an example where you licensed the pcie block version 1.23 from a company named thirdparty and integrated it into the xgene variant with product code 1234w78.

Arnd

maintainer
#9 lore raw

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

In reply to Arnd Bergmann

We're only seeing Arnd's side of the conversation on linux-pci. Tanmay, are your messages being rejected because they're too "fancy", per the definition here: http://vger.kernel.org/majordomo-info.html ?

Quoted 58 lines · Arnd Bergmann
Quoted 33 lines · On Friday 24 January 2014 13:28:22 Tanmay Inamdar wrote:
Quoted 32 lines · Tanmay Inamdar
Quoted 30 lines · Arnd Bergmann
Quoted 14 lines · Tanmay Inamdar
drivers/pci/host/pci-xgene.c new file +14 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port, u32 *lanes)
+{
+     void *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 {

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+             val32 = readl(csr_base + PCIECORE_CTLANDSTATUS);
+             if (val32 & LINK_UP_MASK) {
+                     port->link_up = 1;
+                     port->link_speed = PIPE_PHY_RATE_RD(val32);
+                     val32 = readl(csr_base + BRIDGE_STATUS_0);
+                     *lanes = val32 >> 26;
+             }
+             time = jiffies_to_msecs(jiffies - start_time);
+     } while ((!port->link_up) || (time <= XGENE_LTSSM_L0_WAIT));
+}

Maybe another msleep() in the loop? It seems weird to first do an unconditional sleep but then busy-wait for the result.

Quoted 4 lines
Quoted 1 line

ok.

This loop can execute for maximum 4 msec. So putting msleep(1) won't get us much.

4 msec is still quite a long time for a busy loop that can be spent doing useful work in another thread.

Quoted 10 lines
Quoted 8 lines
Quoted 5 lines

Another general note: Your "compatible" strings are rather unspecific. Do you have a version number for this IP block? I suppose that it's related to one that has been used in other chips before, or will be used in future chips, if it's not actually licensed from some other company.

I will have to check this.

We have decided to stick with current compatible string for now.

Can you elaborate on your reasoning? Does this mean X-Gene is a one-off product and you won't be doing any new chips based on the same hardware components?

Arnd

#10 lore raw

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

Quoted 4 lines · Bjorn Helgaas

We're only seeing Arnd's side of the conversation on linux-pci. Tanmay, are your messages being rejected because they're too "fancy", per the definition here: http://vger.kernel.org/majordomo-info.html ?

Thanks for pointing out. I am not sure though what's being detected as fancy. I checked that my emails are received as plaintext on majordomo. They are also displayed fine on LKML.

In this email, I have tried to keep the format of to: and cc: same as first email in the thread. Not sure if this fixes the problem.

Again.. sorry for spamming.

Quoted 59 lines · Arnd Bergmann
Quoted 58 lines · On Friday 24 January 2014 13:28:22 Tanmay Inamdar wrote:
Quoted 33 lines · Tanmay Inamdar
Quoted 32 lines · Arnd Bergmann
Quoted 30 lines · Tanmay Inamdar
Quoted 16 lines
drivers/pci/host/pci-xgene.c new file +14 -0
+static void xgene_pcie_poll_linkup(struct xgene_pcie_port *port, u32 *lanes)
+{
+     void *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 {

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

Quoted 10 lines
drivers/pci/host/pci-xgene.c new file +10 -0
+             val32 = readl(csr_base + PCIECORE_CTLANDSTATUS);
+             if (val32 & LINK_UP_MASK) {
+                     port->link_up = 1;
+                     port->link_speed = PIPE_PHY_RATE_RD(val32);
+                     val32 = readl(csr_base + BRIDGE_STATUS_0);
+                     *lanes = val32 >> 26;
+             }
+             time = jiffies_to_msecs(jiffies - start_time);
+     } while ((!port->link_up) || (time <= XGENE_LTSSM_L0_WAIT));
+}

Maybe another msleep() in the loop? It seems weird to first do an unconditional sleep but then busy-wait for the result.

Quoted 4 lines
Quoted 1 line

ok.

This loop can execute for maximum 4 msec. So putting msleep(1) won't get us much.

4 msec is still quite a long time for a busy loop that can be spent doing useful work in another thread.

Quoted 10 lines
Quoted 8 lines
Quoted 5 lines

Another general note: Your "compatible" strings are rather unspecific. Do you have a version number for this IP block? I suppose that it's related to one that has been used in other chips before, or will be used in future chips, if it's not actually licensed from some other company.

I will have to check this.

We have decided to stick with current compatible string for now.

Can you elaborate on your reasoning? Does this mean X-Gene is a one-off product and you won't be doing any new chips based on the same hardware components?

Arnd

#11 lore raw

RFC PATCH v2 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 |    4 +
 arch/arm64/boot/dts/apm-storm.dtsi  |  144 +++++++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+)
arch/arm64/boot/dts/apm-mustang.dts +4 -0
index 1247ca1..ab2b95f 100644
@@ -24,3 +24,7 @@
 		reg = < 0x1 0x00000000 0x0 0x80000000 >; /* Updated by bootloader */
 	};
 };
+
+&pcie0 {
+	status = "ok";
+};
arch/arm64/boot/dts/apm-storm.dtsi +144 -0

150 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#12 lore raw

RFC PATCH v2 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-pcie.txt         |   45 ++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/xgene-pcie.txt
Documentation/devicetree/bindings/pci/xgene-pcie.txt new file +45 -0
new file mode 100644
index 0000000..19b9c28
@@ -0,0 +1,45 @@
+* AppliedMicro X-Gene PCIe interface
+
+Required properties:
+- status: Either "ok" or "disabled".
+- device_type: set to "pci"
+- compatible: should contain "xgene,pcie" to identify the core.
+- reg: base addresses and lengths of the pcie controller configuration
+	space register.
+- #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.
+
+Example:
+
+SoC specific DT Entry:
+	pcie0: pcie at 1f2b0000 {
+		status = "disabled";
+		device_type = "pci";
+		compatible = "apm,xgene-pcie";
+		#interrupt-cells = <1>;
+		#size-cells = <2>;
+		#address-cells = <3>;
+		reg = < 0x00 0x1f2b0000 0x0 0x00010000
+			0xe0 0xd0000000 0x0 0x00200000>;
+		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

Re: [RFC PATCH V2 3/4] dt-bindings: pci: xgene pcie device tree bindings

Quoted 15 lines · 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-pcie.txt         |   45 ++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/xgene-pcie.txt
Documentation/devicetree/bindings/pci/xgene-pcie.txt new file +0 -0
new file mode 100644
index 0000000..19b9c28

Documentation/devicetree/bindings/pci/xgene-pcie.txt line 4

Quoted 4 lines
Documentation/devicetree/bindings/pci/xgene-pcie.txt new file +4 -0
@@ -0,0 +1,45 @@
+* AppliedMicro X-Gene PCIe interface
+
+Required properties:
+- status: Either "ok" or "disabled".

"status" isn't normally a required property. The default interpretation is that a node without a status property is active.

Documentation/devicetree/bindings/pci/xgene-pcie.txt line 8

Quoted 4 lines
Documentation/devicetree/bindings/pci/xgene-pcie.txt new file +4 -0
+- device_type: set to "pci"
+- compatible: should contain "xgene,pcie" to identify the core.
+- reg: base addresses and lengths of the pcie controller configuration
+	space register.

Doesn't match the code or example: You only list one area here, but you actually need to register sets.

Looks good otherwise now.

Arnd

#14 lore raw

Re: [RFC PATCH V2 3/4] dt-bindings: pci: xgene pcie device tree bindings

Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · 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-pcie.txt         |   45 ++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/xgene-pcie.txt
Quoted 13 lines

Documentation/devicetree/bindings/pci/xgene-pcie.txt line 4

Quoted 10 lines
Documentation/devicetree/bindings/pci/xgene-pcie.txt new file +4 -0
new file mode 100644
index 0000000..19b9c28
@@ -0,0 +1,45 @@
+* AppliedMicro X-Gene PCIe interface
+
+Required properties:
+- status: Either "ok" or "disabled".

"status" isn't normally a required property. The default interpretation is that a node without a status property is active.

ok. I will move 'status' under optional properties.

Quoted 8 lines

Documentation/devicetree/bindings/pci/xgene-pcie.txt line 8

Quoted 5 lines
Documentation/devicetree/bindings/pci/xgene-pcie.txt new file +4 -0
+- device_type: set to "pci"
+- compatible: should contain "xgene,pcie" to identify the core.
+- reg: base addresses and lengths of the pcie controller configuration
+     space register.

Doesn't match the code or example: You only list one area here, but you actually need to register sets.

ok. I will update

Quoted 4 lines

Looks good otherwise now.

Arnd

#15 lore raw

RFC PATCH v2 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 6c20792..9e3ed53 100644
@@ -6531,6 +6531,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