Skip to contentSkip to conversation

APM X-Gene PCIe DMA driver

PATCH New Mayuresh Chitale 2 participants 16 messages Jan 7, 2015 – Jan 8, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover APM X-Gene PCIe DMA driver

This patch adds the APM X-Gene SOC PCIe DMA driver. It can be used to transfer data between PCIe RC and PCIe endpoints. It supports only dma slave transfers.

Mayuresh Chitale (4):
MAINTAINERS: Add entry for X-Gene PCIE DMA driver
Documentation: dt-bindings: Add the binding info for APM X-Gene PCIe
DMA driver
arm64: dts: Add APM X-Gene PCIe DMA device tree nodes
dma: X-Gene PCIE DMA Driver

 .../devicetree/bindings/dma/xgene-pciedma.txt      |  16 +
 MAINTAINERS                                        |   8 +
 arch/arm64/boot/dts/apm/apm-storm.dtsi             |  40 ++
 drivers/dma/Kconfig                                |  11 +
 drivers/dma/Makefile                               |   1 +
 drivers/dma/xgene-pcie-dma.c                       | 709 +++++++++++++++++++++
 6 files changed, 785 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/xgene-pciedma.txt
 create mode 100644 drivers/dma/xgene-pcie-dma.c
Signature · 1 line
2.2.1.212.gc5b9256
#1 lore raw

PATCH 1/4 MAINTAINERS: Add entry for X-Gene PCIE DMA driver

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index ddb9ac8..9d24a02 100644
@@ -7228,6 +7228,14 @@ L:	linux-arm-kernel at lists.infradead.org
 S:	Maintained
 F:	drivers/pci/host/*layerscape*
 
+PCI DMA DRIVER FOR APPLIEDMICRO XGENE
+M:	Mayuresh Chitale <[email protected]>
+L:	dmaengine at vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/dma/xgene-pcie-dma.txt
+F:	drivers/dma/xgene-pcie-dma.c
+
+
 PCI DRIVER FOR IMX6
 M:	Richard Zhu <[email protected]>
 M:	Lucas Stach <[email protected]>
Signature · 1 line
2.2.1.212.gc5b9256
#2 lore raw

PATCH 2/4 Documentation: dt-bindings: Add the binding info for APM X-Gene PCIe DMA driver

In reply to Mayuresh Chitale

This patch adds the device tree binding information for X-Gene PCIe DMA driver.

---
 Documentation/devicetree/bindings/dma/xgene-pciedma.txt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/xgene-pciedma.txt
Documentation/devicetree/bindings/dma/xgene-pciedma.txt new file +16 -0
new file mode 100644
index 0000000..52ee87a
@@ -0,0 +1,16 @@
+* X-Gene PCIe Direct Memory Access Controller
+
+Required properties:
+- compatible :
+	- "apm,xgene-pciedma" for pcie DMA on X-Gene SoC
+- interrupts : An interrupt-specifier which is used to handle DMA interrupts
+
+Examples:
+		pciedma0 {
+			status = "disabled";
+			compatible = "apm,xgene-pciedma";
+			reg = < 0x0 0x1F2B0154 0x0 0xC
+				0x0 0x1F2B0058 0x0 0x8>;
+			reg-names = "cfg", "intr";
+			interrupts = <0x0 0xC6 0x4>;
+		};
Signature · 1 line
2.2.1.212.gc5b9256
#5 lore raw

PATCH 3/4 arm64: dts: Add APM X-Gene PCIe DMA device tree nodes

In reply to Mayuresh Chitale

Add the device tree nodes for APM X-Gene PCIe DMA engine. Since X-Gene SOC supports maximum 5 PCIe ports, 5 dts nodes are added.

---
 arch/arm64/boot/dts/apm/apm-storm.dtsi | 40 ++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
arch/arm64/boot/dts/apm/apm-storm.dtsi +40 -0
index f1ad9c2..2993d1e 100644
@@ -469,6 +469,46 @@
 			clocks = <&pcie4clk 0>;
 		};
 
+		xpdma0: dma0 at 1f2b0154 {
+			status = "disabled";
+			compatible = "apm,xgene-pciedma";
+			reg = < 0x0 0x1f2b0154 0x0 0xc
+				0x0 0x1f2b0058 0x0 0x8>;
+			interrupts = <0x0 0xc6 0x4>;
+		};
+
+		xpdma1: dma1 at 1f2c0154 {
+			status = "disabled";
+			compatible = "apm,xgene-pciedma";
+			reg = < 0x0 0x1f2c0154 0x0 0xc
+				0x0 0x1f2c0058 0x0 0x8>;
+			interrupts = <0x0 0xcc 0x4>;
+		};
+
+		xpdma2: dma2 at 1f2d0154 {
+			status = "disabled";
+			compatible = "apm,xgene-pciedma";
+			reg = < 0x0 0x1f2d0154 0x0 0xc
+				0x0 0x1f2d0058 0x0 0x8>;
+			interrupts = <0x0 0xd2 0x4>;
+		};
+
+		xpdma3: dma3 at 1f500154 {
+			status = "disabled";
+			compatible = "apm,xgene-pciedma";
+			reg = < 0x0 0x1f500154 0x0 0xc
+				0x0 0x1f500058 0x0 0x8>;
+			interrupts = <0x0 0xd8 0x4>;
+		};
+
+		xpdma4: dma4 at 1f510154 {
+			status = "disabled";
+			compatible = "apm,xgene-pciedma";
+			reg = < 0x0 0x1f510154 0x0 0xc
+				0x0 0x1f510058 0x0 0x8>;
+			interrupts = <0x0 0xde 0x4>;
+		};
+
 		serial0: serial at 1c020000 {
 			status = "disabled";
 			device_type = "serial";
Signature · 1 line
2.2.1.212.gc5b9256
#9 lore raw

PATCH 4/4 dma: X-Gene PCIE DMA Driver

In reply to Mayuresh Chitale

This patch implements DMA engine API for DMA controller on APM X-Gene PCIe controller. DMA engine can support up to 4 channels per port and up to 2048 outstanding requests per channel. This is intended to be used on ports that are configured in EP mode or to transfer data from a RC port that is connected to a X-Gene EP port.

---
 drivers/dma/Kconfig          |  11 +
 drivers/dma/Makefile         |   1 +
 drivers/dma/xgene-pcie-dma.c | 709 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 721 insertions(+)
 create mode 100644 drivers/dma/xgene-pcie-dma.c
drivers/dma/Kconfig +11 -0
index f2b2c4e..9f50759 100644
@@ -464,4 +464,15 @@ config QCOM_BAM_DMA
 	  Enable support for the QCOM BAM DMA controller.  This controller
 	  provides DMA capabilities for a variety of on-chip devices.
 
+config XGENE_PCIE_DMA
+	tristate "X-Gene PCIe DMA support for PCIe Devices"
+	depends on PCI_XGENE
+	select DMA_ENGINE
+	default n
+	help
+	  Enable support for the X-Gene PCIe DMA engine. This can be used
+	  to transfer data between PCIe RC and PCIe endpoints only.
+
+	  If unsure, say N.
+
 endif
drivers/dma/Makefile +1 -0
index 2022b54..6a75698 100644
@@ -50,3 +50,4 @@ obj-y += xilinx/
 obj-$(CONFIG_INTEL_MIC_X100_DMA) += mic_x100_dma.o
 obj-$(CONFIG_NBPFAXI_DMA) += nbpfaxi.o
 obj-$(CONFIG_DMA_SUN6I) += sun6i-dma.o
+obj-$(CONFIG_XGENE_PCIE_DMA) += xgene-pcie-dma.o
drivers/dma/xgene-pcie-dma.c new file +709 -0

709 lines not on this page · raw message

Signature · 1 line
2.2.1.212.gc5b9256
#3 lore raw

PATCH 2/4 Documentation: dt-bindings: Add the binding info for APM X-Gene PCIe DMA driver

In reply to Mayuresh Chitale
Quoted 5 lines · On Wednesday 07 January 2015 10:58:55 Mayuresh Chitale wrote:
Documentation/devicetree/bindings/dma/xgene-pciedma.txt new file +4 -0
+Required properties:
+- compatible :
+       - "apm,xgene-pciedma" for pcie DMA on X-Gene SoC
+- interrupts : An interrupt-specifier which is used to handle DMA interrupts

Documentation/devicetree/bindings/dma/xgene-pciedma.txt line 16

Quoted 10 lines
Documentation/devicetree/bindings/dma/xgene-pciedma.txt new file +10 -0
+
+Examples:
+               pciedma0 {
+                       status = "disabled";
+                       compatible = "apm,xgene-pciedma";
+                       reg = < 0x0 0x1F2B0154 0x0 0xC
+                               0x0 0x1F2B0058 0x0 0x8>;
+                       reg-names = "cfg", "intr";
+                       interrupts = <0x0 0xC6 0x4>;
+               };

The example contains a "reg-names" property that is neither listed as optional nor mandatory, and that is not used by the driver. Bettter drop that from the example.

The 'reg' property is not documented in the binding. Please document which register each index refers to.

Arnd

#10 lore raw

PATCH 4/4 dma: X-Gene PCIE DMA Driver

In reply to Mayuresh Chitale
Quoted 5 lines · On Wednesday 07 January 2015 10:58:57 Mayuresh Chitale wrote:

This patch implements DMA engine API for DMA controller on APM X-Gene PCIe controller. DMA engine can support up to 4 channels per port and up to 2048 outstanding requests per channel. This is intended to be used on ports that are configured in EP mode or to transfer data from a RC port that is connected to a X-Gene EP port.

Linux currently does not support PCIe endpoints. Do you plan to submit a driver for that as well?

Quoted 4 lines
drivers/dma/xgene-pcie-dma.c new file +4 -0
+
+static void xpdma_setup_dma_dev(struct dma_device *dev)
+{
+	dma_cap_zero(dev->cap_mask);

drivers/dma/xgene-pcie-dma.c line 424

Quoted 10 lines
drivers/dma/xgene-pcie-dma.c new file +10 -0
+	dma_cap_set(DMA_SLAVE, dev->cap_mask);
+	dma_cap_set(DMA_PRIVATE, dev->cap_mask);
+
+	dev->device_alloc_chan_resources = xpdma_alloc_chan_resources;
+	dev->device_free_chan_resources = xpdma_free_chan_resources;
+	dev->device_tx_status = xpdma_tx_status;
+	dev->device_issue_pending = xpdma_issue_pending;
+	dev->device_prep_slave_sg = xpdma_prep_slave_sg;
+	dev->device_control = xpdma_device_control;
+}

You are setting up DMA_SLAVE here but do not use the DT binding for slave DMA. Can your driver handle slave DMA? If it can, you should use the appropriate binding, if not then don't set DMA_SLAVE here.

Quoted 5 lines
drivers/dma/xgene-pcie-dma.c new file +5 -0
+static int xpdma_setup_dma_channel(struct platform_device *pdev,
+		struct xpdma_port *port)
+{
+	int i, ret = 0;
+	struct xpdma_chan *chan;

drivers/dma/xgene-pcie-dma.c line 569

Quoted 10 lines
drivers/dma/xgene-pcie-dma.c new file +10 -0
+	resource_size_t dma_base;
+
+	dma_base = MAKE_U64(readl(port->cfg + PORT_CFG_HI), readl(port->cfg)) +
+		CHAN_REG_BASE;
+	port->dma = devm_ioremap(&pdev->dev, dma_base,
+			CHAN_REG_SIZE * MAX_DMA_CHAN);
+	if (port->dma == NULL) {
+		dev_err(&pdev->dev, "Could not get base addressc$\n");
+		return -ENOMEM;
+	}

The registers are not listed in the 'reg' property. Why is that?

You should probably use devm_request_mem_region or devm_ioremap_resource here to ensure manage the mmio range.

Quoted 17 lines
drivers/dma/xgene-pcie-dma.c new file +17 -0
+static int xpdma_probe(struct platform_device *pdev)
+{
+	int err;
+	u32 mask;
+	struct resource *res;
+	struct xpdma_port *port;
+
+	port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
+	if (!port)
+		return -ENOMEM;
+
+	port->dma_dev.dev = &pdev->dev;
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "No cfg resource\n");
+		return -EINVAL;
+	}

drivers/dma/xgene-pcie-dma.c line 625

Quoted 10 lines
drivers/dma/xgene-pcie-dma.c new file +10 -0
+
+	port->cfg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+	if (IS_ERR(port->cfg))
+		return PTR_ERR(port->cfg);
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	if (!res) {
+		dev_err(&pdev->dev, "No intr resource\n");
+		return -EINVAL;
+	}

from binding, these two register ranges look like they are part of another device. Which device is that:

+ reg = < 0x0 0x1f2b0154 0x0 0xc
+ 0x0 0x1f2b0058 0x0 0x8>;

Is this some kind of syscon node that contains all sorts of registers munged together, or is this the same register set that is used for the channels?

In the former case, better use a syscon reference instead of 'reg' and use syscon_regmap_lookup_by_phandle to get the regmap, in the second case, just list the entire registers.

drivers/dma/xgene-pcie-dma.c line 665

Quoted 9 lines
drivers/dma/xgene-pcie-dma.c new file +9 -0
+
+	xpdma_setup_dma_dev(&port->dma_dev);
+	/* Setup DMA mask - 32 for 32-bit system and 64 for 64-bit system */
+	err = dma_set_mask_and_coherent(&pdev->dev,
+			DMA_BIT_MASK(8*sizeof(void *)));
+	if (err) {
+		dev_err(&pdev->dev, "Unable to set dma mask\n");
+		return err;
+	}

Just use a 64-bit dma-mask all the time, and fall back to a 32-bit mask if that doesn't work, the dma mask is completely independent of the word size of the CPU.

You also have to make sure that the parent of the device contains a proper dma-ranges property that allows a 64-bit mask. We currently have a bug in the kernel that makes dma_set_mask_and_coherent always succeed, and we need to fix that so it fails if you have a 64-bit dma capable device on a 32-bit wide bus.

drivers/dma/xgene-pcie-dma.c line 694

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

This is a rather generic compatible string. Is this device present in identical form on all xgene variants?

As xgene is a marketing name and you have now announce the speciifc model numbers, better use the first model that has this hardware.

Arnd

#6 lore raw

PATCH 3/4 arm64: dts: Add APM X-Gene PCIe DMA device tree nodes

In reply to Mayuresh Chitale
Quoted 8 lines · On Wednesday 07 January 2015 10:58:56 Mayuresh Chitale wrote:
arch/arm64/boot/dts/apm/apm-storm.dtsi +6 -0
+               xpdma0: dma0 at 1f2b0154 {
+                       status = "disabled";
+                       compatible = "apm,xgene-pciedma";
+                       reg = < 0x0 0x1f2b0154 0x0 0xc
+                               0x0 0x1f2b0058 0x0 0x8>;
+                       interrupts = <0x0 0xc6 0x4>;

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

Quoted 10 lines
arch/arm64/boot/dts/apm/apm-storm.dtsi +10 -0
+               };
+
+               xpdma1: dma1 at 1f2c0154 {
+                       status = "disabled";
+                       compatible = "apm,xgene-pciedma";
+                       reg = < 0x0 0x1f2c0154 0x0 0xc
+                               0x0 0x1f2c0058 0x0 0x8>;
+                       interrupts = <0x0 0xcc 0x4>;
+               };
+

Something's wrong here: you have the same addresses for all the nodes but use different names. Please change the names to all say 'dma' and set the correct addresses.

Arnd

#4 lore raw

PATCH 2/4 Documentation: dt-bindings: Add the binding info for APM X-Gene PCIe DMA driver

In reply to Arnd Bergmann

Hi Arnd,

Thanks for you comments. Please see inline.

--Mayuresh.

Quoted 21 lines · Arnd Bergmann
Quoted 5 lines · On Wednesday 07 January 2015 10:58:55 Mayuresh Chitale wrote:
Documentation/devicetree/bindings/dma/xgene-pciedma.txt new file +4 -0
+Required properties:
+- compatible :
+       - "apm,xgene-pciedma" for pcie DMA on X-Gene SoC
+- interrupts : An interrupt-specifier which is used to handle DMA interrupts

Documentation/devicetree/bindings/dma/xgene-pciedma.txt line 16

Quoted 10 lines
Documentation/devicetree/bindings/dma/xgene-pciedma.txt new file +10 -0
+
+Examples:
+               pciedma0 {
+                       status = "disabled";
+                       compatible = "apm,xgene-pciedma";
+                       reg = < 0x0 0x1F2B0154 0x0 0xC
+                               0x0 0x1F2B0058 0x0 0x8>;
+                       reg-names = "cfg", "intr";
+                       interrupts = <0x0 0xC6 0x4>;
+               };

The example contains a "reg-names" property that is neither listed as optional nor mandatory, and that is not used by the driver. Bettter drop that from the example.

Quoted 2 lines

The 'reg' property is not documented in the binding. Please document which register each index refers to.

Ok. I will make those changes.

Quoted 2 lines

Arnd

#7 lore raw

PATCH 3/4 arm64: dts: Add APM X-Gene PCIe DMA device tree nodes

In reply to Arnd Bergmann

Hi Arnd,

Actually the addresses are different. For e.g port 0 base address is 1F2B0000 and port 1 base address is 1F2C0000 and so on.

Thanks,
Mayuresh.

Quoted 29 lines · Arnd Bergmann
Quoted 8 lines · On Wednesday 07 January 2015 10:58:56 Mayuresh Chitale wrote:
arch/arm64/boot/dts/apm/apm-storm.dtsi +6 -0
+               xpdma0: dma0 at 1f2b0154 {
+                       status = "disabled";
+                       compatible = "apm,xgene-pciedma";
+                       reg = < 0x0 0x1f2b0154 0x0 0xc
+                               0x0 0x1f2b0058 0x0 0x8>;
+                       interrupts = <0x0 0xc6 0x4>;

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

Quoted 10 lines
arch/arm64/boot/dts/apm/apm-storm.dtsi +10 -0
+               };
+
+               xpdma1: dma1 at 1f2c0154 {
+                       status = "disabled";
+                       compatible = "apm,xgene-pciedma";
+                       reg = < 0x0 0x1f2c0154 0x0 0xc
+                               0x0 0x1f2c0058 0x0 0x8>;
+                       interrupts = <0x0 0xcc 0x4>;
+               };
+

Something's wrong here: you have the same addresses for all the nodes but use different names. Please change the names to all say 'dma' and set the correct addresses.

Arnd
--
To unsubscribe from this list: send the line "unsubscribe dmaengine" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

PATCH 4/4 dma: X-Gene PCIE DMA Driver

In reply to Arnd Bergmann

Hi Arnd,

Please see inline.

Thanks,
Mayuresh.

Quoted 21 lines · Arnd Bergmann
Quoted 5 lines · On Wednesday 07 January 2015 10:58:57 Mayuresh Chitale wrote:

This patch implements DMA engine API for DMA controller on APM X-Gene PCIe controller. DMA engine can support up to 4 channels per port and up to 2048 outstanding requests per channel. This is intended to be used on ports that are configured in EP mode or to transfer data from a RC port that is connected to a X-Gene EP port.

Linux currently does not support PCIe endpoints. Do you plan to submit a driver for that as well?

Quoted 11 lines
drivers/dma/xgene-pcie-dma.c new file +11 -0
+
+static void xpdma_setup_dma_dev(struct dma_device *dev)
+{
+     dma_cap_zero(dev->cap_mask);
+     dma_cap_set(DMA_SLAVE, dev->cap_mask);
+     dma_cap_set(DMA_PRIVATE, dev->cap_mask);
+
+     dev->device_alloc_chan_resources = xpdma_alloc_chan_resources;
+     dev->device_free_chan_resources = xpdma_free_chan_resources;
+     dev->device_tx_status = xpdma_tx_status;
+     dev->device_issue_pending = xpdma_issue_pending;
Quoted 8 lines

drivers/dma/xgene-pcie-dma.c line 424

Quoted 3 lines
drivers/dma/xgene-pcie-dma.c new file +3 -0
+     dev->device_prep_slave_sg = xpdma_prep_slave_sg;
+     dev->device_control = xpdma_device_control;
+}

You are setting up DMA_SLAVE here but do not use the DT binding for slave DMA. Can your driver handle slave DMA? If it can, you should use the appropriate binding, if not then don't set DMA_SLAVE here.

Are you referring to DT DMA helpers? If so, I will add it.

Quoted 10 lines
Quoted 10 lines
drivers/dma/xgene-pcie-dma.c new file +9 -0
+static int xpdma_setup_dma_channel(struct platform_device *pdev,
+             struct xpdma_port *port)
+{
+     int i, ret = 0;
+     struct xpdma_chan *chan;
+     resource_size_t dma_base;
+
+     dma_base = MAKE_U64(readl(port->cfg + PORT_CFG_HI), readl(port->cfg)) +
+             CHAN_REG_BASE;
Quoted 8 lines

drivers/dma/xgene-pcie-dma.c line 569

Quoted 6 lines
drivers/dma/xgene-pcie-dma.c new file +6 -0
+     port->dma = devm_ioremap(&pdev->dev, dma_base,
+                     CHAN_REG_SIZE * MAX_DMA_CHAN);
+     if (port->dma == NULL) {
+             dev_err(&pdev->dev, "Could not get base addressc$\n");
+             return -ENOMEM;
+     }

The registers are not listed in the 'reg' property. Why is that?

Actually these registers have to accessed via the PCIe config space region for that port. Since the config space base address is programmed by host controller driver we can know the base address only by reading the corresponding config space bar at runtime.

Quoted 35 lines

You should probably use devm_request_mem_region or devm_ioremap_resource here to ensure manage the mmio range.

Quoted 17 lines
drivers/dma/xgene-pcie-dma.c new file +17 -0
+static int xpdma_probe(struct platform_device *pdev)
+{
+     int err;
+     u32 mask;
+     struct resource *res;
+     struct xpdma_port *port;
+
+     port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
+     if (!port)
+             return -ENOMEM;
+
+     port->dma_dev.dev = &pdev->dev;
+     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+     if (!res) {
+             dev_err(&pdev->dev, "No cfg resource\n");
+             return -EINVAL;
+     }

drivers/dma/xgene-pcie-dma.c line 625

Quoted 10 lines
drivers/dma/xgene-pcie-dma.c new file +10 -0
+
+     port->cfg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+     if (IS_ERR(port->cfg))
+             return PTR_ERR(port->cfg);
+
+     res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+     if (!res) {
+             dev_err(&pdev->dev, "No intr resource\n");
+             return -EINVAL;
+     }

from binding, these two register ranges look like they are part of another device. Which device is that:

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       reg = < 0x0 0x1f2b0154 0x0 0xc
+                               0x0 0x1f2b0058 0x0 0x8>;

These are registers inside PCIe host controller that contains information required such as the dma base address, interrupt configuration. So this will be used for the channels. I am not aware about syscon but will see if it better represents these registers.

Quoted 19 lines

Is this some kind of syscon node that contains all sorts of registers munged together, or is this the same register set that is used for the channels?

In the former case, better use a syscon reference instead of 'reg' and use syscon_regmap_lookup_by_phandle to get the regmap, in the second case, just list the entire registers.

drivers/dma/xgene-pcie-dma.c line 665

Quoted 9 lines
drivers/dma/xgene-pcie-dma.c new file +9 -0
+
+     xpdma_setup_dma_dev(&port->dma_dev);
+     /* Setup DMA mask - 32 for 32-bit system and 64 for 64-bit system */
+     err = dma_set_mask_and_coherent(&pdev->dev,
+                     DMA_BIT_MASK(8*sizeof(void *)));
+     if (err) {
+             dev_err(&pdev->dev, "Unable to set dma mask\n");
+             return err;
+     }
Quoted 3 lines

Just use a 64-bit dma-mask all the time, and fall back to a 32-bit mask if that doesn't work, the dma mask is completely independent of the word size of the CPU.

okay.

Quoted 7 lines

You also have to make sure that the parent of the device contains a proper dma-ranges property that allows a 64-bit mask. We currently have a bug in the kernel that makes dma_set_mask_and_coherent always succeed, and we need to fix that so it fails if you have a 64-bit dma capable device on a 32-bit wide bus.

Quoted 7 lines

drivers/dma/xgene-pcie-dma.c line 694

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

This is a rather generic compatible string. Is this device present in identical form on all xgene variants?

Yes.

Quoted 3 lines

As xgene is a marketing name and you have now announce the speciifc model numbers, better use the first model that has this hardware.

okay.

Quoted 2 lines

Arnd

#8 lore raw

PATCH 3/4 arm64: dts: Add APM X-Gene PCIe DMA device tree nodes

In reply to Mayuresh Chitale
Quoted 5 lines · On Wednesday 07 January 2015 16:15:54 Mayuresh Chitale wrote:

Hi Arnd,

Actually the addresses are different. For e.g port 0 base address is 1F2B0000 and port 1 base address is 1F2C0000 and so on.

Ah, I see now. Just change the name to 'dma' then.

Arnd

#12 lore raw

PATCH 4/4 dma: X-Gene PCIE DMA Driver

In reply to Mayuresh Chitale
Quoted 32 lines · On Wednesday 07 January 2015 16:55:33 Mayuresh Chitale wrote:
Quoted 21 lines · Arnd Bergmann
Quoted 5 lines · On Wednesday 07 January 2015 10:58:57 Mayuresh Chitale wrote:

This patch implements DMA engine API for DMA controller on APM X-Gene PCIe controller. DMA engine can support up to 4 channels per port and up to 2048 outstanding requests per channel. This is intended to be used on ports that are configured in EP mode or to transfer data from a RC port that is connected to a X-Gene EP port.

Linux currently does not support PCIe endpoints. Do you plan to submit a driver for that as well?

Quoted 11 lines
drivers/dma/xgene-pcie-dma.c new file +11 -0
+
+static void xpdma_setup_dma_dev(struct dma_device *dev)
+{
+     dma_cap_zero(dev->cap_mask);
+     dma_cap_set(DMA_SLAVE, dev->cap_mask);
+     dma_cap_set(DMA_PRIVATE, dev->cap_mask);
+
+     dev->device_alloc_chan_resources = xpdma_alloc_chan_resources;
+     dev->device_free_chan_resources = xpdma_free_chan_resources;
+     dev->device_tx_status = xpdma_tx_status;
+     dev->device_issue_pending = xpdma_issue_pending;
Quoted 8 lines

drivers/dma/xgene-pcie-dma.c line 424

Quoted 3 lines
drivers/dma/xgene-pcie-dma.c new file +3 -0
+     dev->device_prep_slave_sg = xpdma_prep_slave_sg;
+     dev->device_control = xpdma_device_control;
+}

You are setting up DMA_SLAVE here but do not use the DT binding for slave DMA. Can your driver handle slave DMA? If it can, you should use the appropriate binding, if not then don't set DMA_SLAVE here.

Quoted 1 line

Are you referring to DT DMA helpers? If so, I will add it.

Yes, you will need a '#dma-cells' property in the device node, and call of_dma_controller_register with an appropriate xlate function so a slave can find the right channel.

Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
drivers/dma/xgene-pcie-dma.c new file +9 -0
+static int xpdma_setup_dma_channel(struct platform_device *pdev,
+             struct xpdma_port *port)
+{
+     int i, ret = 0;
+     struct xpdma_chan *chan;
+     resource_size_t dma_base;
+
+     dma_base = MAKE_U64(readl(port->cfg + PORT_CFG_HI), readl(port->cfg)) +
+             CHAN_REG_BASE;
Quoted 8 lines

drivers/dma/xgene-pcie-dma.c line 569

Quoted 6 lines
drivers/dma/xgene-pcie-dma.c new file +6 -0
+     port->dma = devm_ioremap(&pdev->dev, dma_base,
+                     CHAN_REG_SIZE * MAX_DMA_CHAN);
+     if (port->dma == NULL) {
+             dev_err(&pdev->dev, "Could not get base addressc$\n");
+             return -ENOMEM;
+     }

The registers are not listed in the 'reg' property. Why is that?

Quoted 4 lines

Actually these registers have to accessed via the PCIe config space region for that port. Since the config space base address is programmed by host controller driver we can know the base address only by reading the corresponding config space bar at runtime.

I think I'm missing something important here. What exactly is the interaction with PCI here? Is it possible to use the dmaengine driver at all when the PCI host controller is not in endpoint mode?

Does the dmaengine show up as a PCI device when the PCI controller is in host mode?

Quoted 34 lines
Quoted 34 lines

You should probably use devm_request_mem_region or devm_ioremap_resource here to ensure manage the mmio range.

Quoted 17 lines
drivers/dma/xgene-pcie-dma.c new file +17 -0
+static int xpdma_probe(struct platform_device *pdev)
+{
+     int err;
+     u32 mask;
+     struct resource *res;
+     struct xpdma_port *port;
+
+     port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
+     if (!port)
+             return -ENOMEM;
+
+     port->dma_dev.dev = &pdev->dev;
+     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+     if (!res) {
+             dev_err(&pdev->dev, "No cfg resource\n");
+             return -EINVAL;
+     }

drivers/dma/xgene-pcie-dma.c line 625

Quoted 10 lines
drivers/dma/xgene-pcie-dma.c new file +10 -0
+
+     port->cfg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+     if (IS_ERR(port->cfg))
+             return PTR_ERR(port->cfg);
+
+     res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+     if (!res) {
+             dev_err(&pdev->dev, "No intr resource\n");
+             return -EINVAL;
+     }

from binding, these two register ranges look like they are part of another device. Which device is that:

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       reg = < 0x0 0x1f2b0154 0x0 0xc
+                               0x0 0x1f2b0058 0x0 0x8>;

These are registers inside PCIe host controller that contains information required such as the dma base address, interrupt configuration. So this will be used for the channels. I am not aware about syscon but will see if it better represents these registers.

If the dmaengine is tightly connected to the PCI host controller and only usable in endpoint mode, maybe it's better to use a completely different model here, depending on how the PCI endpoint programming model will look like in the end. We are in fact in need of a generic abstraction for endpoints. There are some beginnings in drivers/ntb, and maybe it should build on that instead?

Arnd

#13 lore raw

PATCH 4/4 dma: X-Gene PCIE DMA Driver

Hi Arnd,

Thanks again for your inputs. Please see inline.

--Mayuresh.

Quoted 56 lines · Arnd Bergmann
Quoted 32 lines · On Wednesday 07 January 2015 16:55:33 Mayuresh Chitale wrote:
Quoted 21 lines · Arnd Bergmann
Quoted 5 lines · On Wednesday 07 January 2015 10:58:57 Mayuresh Chitale wrote:

This patch implements DMA engine API for DMA controller on APM X-Gene PCIe controller. DMA engine can support up to 4 channels per port and up to 2048 outstanding requests per channel. This is intended to be used on ports that are configured in EP mode or to transfer data from a RC port that is connected to a X-Gene EP port.

Linux currently does not support PCIe endpoints. Do you plan to submit a driver for that as well?

Quoted 11 lines
drivers/dma/xgene-pcie-dma.c new file +11 -0
+
+static void xpdma_setup_dma_dev(struct dma_device *dev)
+{
+     dma_cap_zero(dev->cap_mask);
+     dma_cap_set(DMA_SLAVE, dev->cap_mask);
+     dma_cap_set(DMA_PRIVATE, dev->cap_mask);
+
+     dev->device_alloc_chan_resources = xpdma_alloc_chan_resources;
+     dev->device_free_chan_resources = xpdma_free_chan_resources;
+     dev->device_tx_status = xpdma_tx_status;
+     dev->device_issue_pending = xpdma_issue_pending;
Quoted 8 lines

drivers/dma/xgene-pcie-dma.c line 424

Quoted 3 lines
drivers/dma/xgene-pcie-dma.c new file +3 -0
+     dev->device_prep_slave_sg = xpdma_prep_slave_sg;
+     dev->device_control = xpdma_device_control;
+}

You are setting up DMA_SLAVE here but do not use the DT binding for slave DMA. Can your driver handle slave DMA? If it can, you should use the appropriate binding, if not then don't set DMA_SLAVE here.

Quoted 1 line

Are you referring to DT DMA helpers? If so, I will add it.

Yes, you will need a '#dma-cells' property in the device node, and call of_dma_controller_register with an appropriate xlate function so a slave can find the right channel.

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
drivers/dma/xgene-pcie-dma.c new file +5 -0
+static int xpdma_setup_dma_channel(struct platform_device *pdev,
+             struct xpdma_port *port)
+{
+     int i, ret = 0;
+     struct xpdma_chan *chan;

drivers/dma/xgene-pcie-dma.c line 569

Quoted 10 lines
drivers/dma/xgene-pcie-dma.c new file +10 -0
+     resource_size_t dma_base;
+
+     dma_base = MAKE_U64(readl(port->cfg + PORT_CFG_HI), readl(port->cfg)) +
+             CHAN_REG_BASE;
+     port->dma = devm_ioremap(&pdev->dev, dma_base,
+                     CHAN_REG_SIZE * MAX_DMA_CHAN);
+     if (port->dma == NULL) {
+             dev_err(&pdev->dev, "Could not get base addressc$\n");
+             return -ENOMEM;
+     }

The registers are not listed in the 'reg' property. Why is that?

Quoted 8 lines
Quoted 4 lines

Actually these registers have to accessed via the PCIe config space region for that port. Since the config space base address is programmed by host controller driver we can know the base address only by reading the corresponding config space bar at runtime.

I think I'm missing something important here. What exactly is the interaction with PCI here? Is it possible to use the dmaengine driver at all when the PCI host controller is not in endpoint mode?

Yes. Dmaengine driver can be used when port is configured as RC or EP.

Quoted 3 lines

Does the dmaengine show up as a PCI device when the PCI controller is in host mode?

No. It sits between AXI and PCI interfaces but it needs to be programmed via the config bar.

Quoted 43 lines
Quoted 35 lines
Quoted 35 lines

You should probably use devm_request_mem_region or devm_ioremap_resource here to ensure manage the mmio range.

Quoted 17 lines
drivers/dma/xgene-pcie-dma.c new file +17 -0
+static int xpdma_probe(struct platform_device *pdev)
+{
+     int err;
+     u32 mask;
+     struct resource *res;
+     struct xpdma_port *port;
+
+     port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
+     if (!port)
+             return -ENOMEM;
+
+     port->dma_dev.dev = &pdev->dev;
+     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+     if (!res) {
+             dev_err(&pdev->dev, "No cfg resource\n");
+             return -EINVAL;
+     }

drivers/dma/xgene-pcie-dma.c line 625

Quoted 10 lines
drivers/dma/xgene-pcie-dma.c new file +10 -0
+
+     port->cfg = devm_ioremap(&pdev->dev, res->start, resource_size(res));
+     if (IS_ERR(port->cfg))
+             return PTR_ERR(port->cfg);
+
+     res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+     if (!res) {
+             dev_err(&pdev->dev, "No intr resource\n");
+             return -EINVAL;
+     }

from binding, these two register ranges look like they are part of another device. Which device is that:

Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       reg = < 0x0 0x1f2b0154 0x0 0xc
+                               0x0 0x1f2b0058 0x0 0x8>;

These are registers inside PCIe host controller that contains information required such as the dma base address, interrupt configuration. So this will be used for the channels. I am not aware about syscon but will see if it better represents these registers.

Quoted 6 lines

If the dmaengine is tightly connected to the PCI host controller and only usable in endpoint mode, maybe it's better to use a completely different model here, depending on how the PCI endpoint programming model will look like in the end. We are in fact in need of a generic abstraction for endpoints. There are some beginnings in drivers/ntb, and maybe it should build on that instead?

It can be used in both RC and EP modes but let me look in the ntb code too.

Quoted 2 lines

Arnd

#14 lore raw

PATCH 4/4 dma: X-Gene PCIE DMA Driver

Quoted 10 lines · On Wednesday 07 January 2015 21:35:22 Mayuresh Chitale wrote:
Quoted 4 lines

I think I'm missing something important here. What exactly is the interaction with PCI here? Is it possible to use the dmaengine driver at all when the PCI host controller is not in endpoint mode?

Yes. Dmaengine driver can be used when port is configured as RC or EP.

Quoted 3 lines

Does the dmaengine show up as a PCI device when the PCI controller is in host mode?

No. It sits between AXI and PCI interfaces but it needs to be programmed via the config bar.

Ok, I see. So in RC mode, it sounds like this is a regular DMA engine that could be used with arbitrary slaves, but in EP mode it would actually be controlled by the remote host, right?

When we are in RC mode, who sets up that BAR? If this is set up by the firmware, we can just have the register appear in the DT as well, as it's known, and when we are in EP mode, it sounds like we would not even use the dmaengine because it's owned by the other host.

Or is there a way that in EP mode, both sides would access the dma engine simultaneously?

Arnd

#15 lore raw

PATCH 4/4 dma: X-Gene PCIE DMA Driver

Quoted 7 lines · Arnd Bergmann
Quoted 6 lines · On Wednesday 07 January 2015 21:35:22 Mayuresh Chitale wrote:
Quoted 4 lines

I think I'm missing something important here. What exactly is the interaction with PCI here? Is it possible to use the dmaengine driver at all when the PCI host controller is not in endpoint mode?

Yes. Dmaengine driver can be used when port is configured as RC or EP.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Does the dmaengine show up as a PCI device when the PCI controller is in host mode?

No. It sits between AXI and PCI interfaces but it needs to be programmed via the config bar.

Ok, I see. So in RC mode, it sounds like this is a regular DMA engine that could be used with arbitrary slaves, but in EP mode it would actually be controlled by the remote host, right?

No. EP can configure its own DMA engine via config bar, same as RC. There could be a dependency on RC in terms of which memory region the EP is allowed to DMA to but I think that is outside the scope of this driver.

Quoted 5 lines

When we are in RC mode, who sets up that BAR? If this is set up by the firmware, we can just have the register appear in the DT as well, as it's known, and when we are in EP mode, it sounds like we would not even use the dmaengine because it's owned by the other host.

The config bar is setup by host controller driver. For e.g you can see cfg reg in pcie at 1f2b0000 node in arch/arm64/boot/dts/apm/apm-storm.dtsi. The dmaengine driver is simply going to read this reg to know the config base and access its own registers accordingly. In this patch config base register is present in each node.
For e.g for port0 it is 0x1f2b0154.

Quoted 5 lines

Or is there a way that in EP mode, both sides would access the dma engine simultaneously?

Arnd