Skip to contentSkip to conversation

CPM6 Channel Separation Support

PATCH Superseded Devendra K Verma 3 participants 17 messages Jul 22 – Jul 27

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover CPM6 Channel Separation Support

'Designware Cores PCI Express DM Controller - Reference Manual', section 3.2.34.3, VSEC for DEVICE INFORMATION supports the channel separation mechanisms. Basically, the HDMA IP allows the user to configure the separation between DMA channel registers and retrieve it via the VSEC capability mentioned above.
In order to use the VSEC functionality following changes have been made:

o For Xilinx IP alone, the macros declared are made device name agnostic to expand the usage of macros for similar functionality.
o Utilize the existing VSEC implementation to retrieve the channel separation and translate it to correct size.
o Modify the structs and functions to calculate correct DMA channel register base using the channel, direction and channel separation selected.

Devendra K Verma (3):
dmaengine: dw-edma: Make Xilinx Macros Dev Name Agnostic
dmaengine: dw-edma: Enable Chan Separation via VSEC
dmaengine: dw-edma: Add changes to support Channel Separation

 drivers/dma/dw-edma/dw-edma-pcie.c       | 87 +++++++++++++++---------
 drivers/dma/dw-edma/dw-hdma-v0-core.c    | 23 ++++---
 drivers/dma/dw-edma/dw-hdma-v0-debugfs.c | 17 ++---
 drivers/dma/dw-edma/dw-hdma-v0-regs.h    | 10 ---
 include/linux/dma/edma.h                 |  1 +
 5 files changed, 77 insertions(+), 61 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 dmaengine: dw-edma: Make Xilinx Macros Dev Name Agnostic

Xilinx specific macros for MDB device can be reused for the Xilinx supported other similar IP such as CPM6.
Renamed the Xilinx specific macros in a way that can be reused for Xilinx supported upcoming IP, CPM6.
Naming is in accordance with the naming done for Synopsys macros.

---
 drivers/dma/dw-edma/dw-edma-pcie.c | 58 +++++++++++++++---------------
 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +29 -29
index 791c46e8ae4c..ec5e057a0f11 100644
@@ -29,21 +29,21 @@
 #define PCI_DEVICE_ID_XILINX_B054		0xb054
 #define PCI_DEVICE_ID_XILINX_B00F		0xb00f
 
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_ID		0x6
-#define DW_PCIE_XILINX_MDB_VSEC_ID		0x20
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_BAR		GENMASK(10, 8)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_MAP		GENMASK(2, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH	GENMASK(9, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH	GENMASK(25, 16)
-
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH	0xc
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW	0x8
-#define DW_PCIE_XILINX_MDB_INVALID_ADDR		(~0ULL)
-
-#define DW_PCIE_XILINX_MDB_LL_OFF_GAP		0x200000
-#define DW_PCIE_XILINX_MDB_LL_SIZE		0x800
-#define DW_PCIE_XILINX_MDB_DT_OFF_GAP		0x100000
-#define DW_PCIE_XILINX_MDB_DT_SIZE		0x800
+#define DW_PCIE_XILINX_VSEC_DMA_ID		0x6
+#define DW_PCIE_XILINX_VSEC_ID			0x20
+#define DW_PCIE_XILINX_VSEC_DMA_BAR		GENMASK(10, 8)
+#define DW_PCIE_XILINX_VSEC_DMA_MAP		GENMASK(2, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_WR_CH		GENMASK(9, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_RD_CH		GENMASK(25, 16)
+
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH	0xc
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW	0x8
+#define DW_PCIE_XILINX_INVALID_ADDR		(~0ULL)
+
+#define DW_PCIE_XILINX_LL_OFF_GAP		0x200000
+#define DW_PCIE_XILINX_LL_SIZE			0x800
+#define DW_PCIE_XILINX_DT_OFF_GAP		0x100000
+#define DW_PCIE_XILINX_DT_SIZE			0x800
 
 #define DW_BLOCK(a, b, c) \
 	{ \
@@ -258,10 +258,10 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 	u16 vsec;
 	u64 off;
 
-	pdata->devmem_phys_off = DW_PCIE_XILINX_MDB_INVALID_ADDR;
+	pdata->devmem_phys_off = DW_PCIE_XILINX_INVALID_ADDR;
 
 	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_DMA_ID);
+					DW_PCIE_XILINX_VSEC_DMA_ID);
 	if (!vsec)
 		return;
 
@@ -272,18 +272,18 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 
 	pci_dbg(pdev, "Detected Xilinx PCIe Vendor-Specific Extended Capability DMA\n");
 	pci_read_config_dword(pdev, vsec + 0x8, &val);
-	map = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_MAP, val);
+	map = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_MAP, val);
 	if (map != EDMA_MF_HDMA_NATIVE)
 		return;
 
 	pdata->mf = map;
-	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_BAR, val);
+	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_BAR, val);
 
 	pci_read_config_dword(pdev, vsec + 0xc, &val);
 	pdata->wr_ch_cnt = min(pdata->wr_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_WR_CH, val));
 	pdata->rd_ch_cnt = min(pdata->rd_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_RD_CH, val));
 
 	pci_read_config_dword(pdev, vsec + 0x14, &val);
 	off = val;
@@ -293,16 +293,16 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 	pdata->rg.off = off;
 
 	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_ID);
+					DW_PCIE_XILINX_VSEC_ID);
 	if (!vsec)
 		return;
 
 	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH,
 			      &val);
 	off = val;
 	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW,
 			      &val);
 	off <<= 32;
 	off |= val;
@@ -360,7 +360,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 		 * address use the non-LL mode or simple mode supported by
 		 * the HDMA IP.
 		 */
-		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_MDB_INVALID_ADDR)
+		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_INVALID_ADDR)
 			non_ll = true;
 
 		/*
@@ -370,10 +370,10 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 		 */
 		if (!non_ll)
 			dw_edma_set_chan_region_offset(vsec_data, BAR_2, 0,
-						       DW_PCIE_XILINX_MDB_LL_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_LL_SIZE,
-						       DW_PCIE_XILINX_MDB_DT_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_DT_SIZE);
+						       DW_PCIE_XILINX_LL_OFF_GAP,
+						       DW_PCIE_XILINX_LL_SIZE,
+						       DW_PCIE_XILINX_DT_OFF_GAP,
+						       DW_PCIE_XILINX_DT_SIZE);
 	}
 
 	/* Mapping PCI BAR regions */
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v1 1/3] dmaengine: dw-edma: Make Xilinx Macros Dev Name Agnostic

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Xilinx specific macros for MDB device can be reused for the Xilinx supported other similar IP such as CPM6.
Renamed the Xilinx specific macros in a way that can be reused for Xilinx supported upcoming IP, CPM6.
Naming is in accordance with the naming done for Synopsys macros.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v1 1/3] dmaengine: dw-edma: Make Xilinx Macros Dev Name Agnostic

In reply to Devendra K Verma
Quoted 8 lines · Devendra K Verma

Xilinx specific macros for MDB device can be reused for the Xilinx supported other similar IP such as CPM6.
Renamed the Xilinx specific macros in a way that can be reused for Xilinx supported upcoming IP, CPM6.
Naming is in accordance with the naming done for Synopsys macros.

---

I don't think it is necessary to remove MDB. You may mention somewhere CMP6 compatible with MDB. It is quite common in driver.

The major concerns is that if a incompatible devices appear, such as CMP7, which have special registers, need add _MDB_ back.

Frank

Quoted 127 lines
 drivers/dma/dw-edma/dw-edma-pcie.c | 58 +++++++++++++++---------------
 1 file changed, 29 insertions(+), 29 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +29 -30
index 791c46e8ae4c..ec5e057a0f11 100644
@@ -29,21 +29,21 @@
 #define PCI_DEVICE_ID_XILINX_B054		0xb054
 #define PCI_DEVICE_ID_XILINX_B00F		0xb00f
 
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_ID		0x6
-#define DW_PCIE_XILINX_MDB_VSEC_ID		0x20
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_BAR		GENMASK(10, 8)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_MAP		GENMASK(2, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH	GENMASK(9, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH	GENMASK(25, 16)
-
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH	0xc
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW	0x8
-#define DW_PCIE_XILINX_MDB_INVALID_ADDR		(~0ULL)
-
-#define DW_PCIE_XILINX_MDB_LL_OFF_GAP		0x200000
-#define DW_PCIE_XILINX_MDB_LL_SIZE		0x800
-#define DW_PCIE_XILINX_MDB_DT_OFF_GAP		0x100000
-#define DW_PCIE_XILINX_MDB_DT_SIZE		0x800
+#define DW_PCIE_XILINX_VSEC_DMA_ID		0x6
+#define DW_PCIE_XILINX_VSEC_ID			0x20
+#define DW_PCIE_XILINX_VSEC_DMA_BAR		GENMASK(10, 8)
+#define DW_PCIE_XILINX_VSEC_DMA_MAP		GENMASK(2, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_WR_CH		GENMASK(9, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_RD_CH		GENMASK(25, 16)
+
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH	0xc
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW	0x8
+#define DW_PCIE_XILINX_INVALID_ADDR		(~0ULL)
+
+#define DW_PCIE_XILINX_LL_OFF_GAP		0x200000
+#define DW_PCIE_XILINX_LL_SIZE			0x800
+#define DW_PCIE_XILINX_DT_OFF_GAP		0x100000
+#define DW_PCIE_XILINX_DT_SIZE			0x800
 
 #define DW_BLOCK(a, b, c) \
 	{ \
@@ -258,10 +258,10 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 	u16 vsec;
 	u64 off;
 
-	pdata->devmem_phys_off = DW_PCIE_XILINX_MDB_INVALID_ADDR;
+	pdata->devmem_phys_off = DW_PCIE_XILINX_INVALID_ADDR;
 
 	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_DMA_ID);
+					DW_PCIE_XILINX_VSEC_DMA_ID);
 	if (!vsec)
 		return;
 
@@ -272,18 +272,18 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 
 	pci_dbg(pdev, "Detected Xilinx PCIe Vendor-Specific Extended Capability DMA\n");
 	pci_read_config_dword(pdev, vsec + 0x8, &val);
-	map = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_MAP, val);
+	map = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_MAP, val);
 	if (map != EDMA_MF_HDMA_NATIVE)
 		return;
 
 	pdata->mf = map;
-	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_BAR, val);
+	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_BAR, val);
 
 	pci_read_config_dword(pdev, vsec + 0xc, &val);
 	pdata->wr_ch_cnt = min(pdata->wr_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_WR_CH, val));
 	pdata->rd_ch_cnt = min(pdata->rd_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_RD_CH, val));
 
 	pci_read_config_dword(pdev, vsec + 0x14, &val);
 	off = val;
@@ -293,16 +293,16 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 	pdata->rg.off = off;
 
 	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_ID);
+					DW_PCIE_XILINX_VSEC_ID);
 	if (!vsec)
 		return;
 
 	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH,
 			      &val);
 	off = val;
 	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW,
 			      &val);
 	off <<= 32;
 	off |= val;
@@ -360,7 +360,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 		 * address use the non-LL mode or simple mode supported by
 		 * the HDMA IP.
 		 */
-		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_MDB_INVALID_ADDR)
+		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_INVALID_ADDR)
 			non_ll = true;
 
 		/*
@@ -370,10 +370,10 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 		 */
 		if (!non_ll)
 			dw_edma_set_chan_region_offset(vsec_data, BAR_2, 0,
-						       DW_PCIE_XILINX_MDB_LL_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_LL_SIZE,
-						       DW_PCIE_XILINX_MDB_DT_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_DT_SIZE);
+						       DW_PCIE_XILINX_LL_OFF_GAP,
+						       DW_PCIE_XILINX_LL_SIZE,
+						       DW_PCIE_XILINX_DT_OFF_GAP,
+						       DW_PCIE_XILINX_DT_SIZE);
 	}
 
 	/* Mapping PCI BAR regions */
--

2.43.0

#4 lore raw

Re: [PATCH v1 1/3] dmaengine: dw-edma: Make Xilinx Macros Dev Name Agnostic

Quoted 10 lines · Frank Li
Quoted 8 lines · Devendra K Verma

Xilinx specific macros for MDB device can be reused for the Xilinx supported other similar IP such as CPM6.
Renamed the Xilinx specific macros in a way that can be reused for Xilinx supported upcoming IP, CPM6.
Naming is in accordance with the naming done for Synopsys macros.

---

Quoted 8 lines

I don't think it is necessary to remove MDB. You may mention somewhere CMP6 compatible with MDB. It is quite common in driver.

The major concerns is that if a incompatible devices appear, such as CMP7, which have special registers, need add _MDB_ back.

Frank

The MDB was used cause at that time only Xilinx MDB was the IP to go public.
I agree with your suggestion but the idea used here is that, for the common functionalities use the names which are affiliated to vendor that is Xilinx and can be used across the IP having the similarity. In case specific functionality is required for MDB or CPM6 then it can be associated using vendor + device name, that way it is easy to identify which ones are common and specific to the IP.

Currently, if any functionality added for MDB ONLY then it would be assumed to be supported on Xilinx CPM6 as well. To remove the confusion extra comment would be required to inform which functionality is supported for which IP. That is why the removal of MDB appoach was taken to reduce the confusion and work. The first approach looked clean.

Please let me know your thougths.

-Devendra

Quoted 127 lines
Quoted 127 lines
  drivers/dma/dw-edma/dw-edma-pcie.c | 58 +++++++++++++++---------------
  1 file changed, 29 insertions(+), 29 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +29 -30
index 791c46e8ae4c..ec5e057a0f11 100644
@@ -29,21 +29,21 @@
  #define PCI_DEVICE_ID_XILINX_B054		0xb054
  #define PCI_DEVICE_ID_XILINX_B00F		0xb00f
 
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_ID		0x6
-#define DW_PCIE_XILINX_MDB_VSEC_ID		0x20
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_BAR		GENMASK(10, 8)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_MAP		GENMASK(2, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH	GENMASK(9, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH	GENMASK(25, 16)
-
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH	0xc
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW	0x8
-#define DW_PCIE_XILINX_MDB_INVALID_ADDR		(~0ULL)
-
-#define DW_PCIE_XILINX_MDB_LL_OFF_GAP		0x200000
-#define DW_PCIE_XILINX_MDB_LL_SIZE		0x800
-#define DW_PCIE_XILINX_MDB_DT_OFF_GAP		0x100000
-#define DW_PCIE_XILINX_MDB_DT_SIZE		0x800
+#define DW_PCIE_XILINX_VSEC_DMA_ID		0x6
+#define DW_PCIE_XILINX_VSEC_ID			0x20
+#define DW_PCIE_XILINX_VSEC_DMA_BAR		GENMASK(10, 8)
+#define DW_PCIE_XILINX_VSEC_DMA_MAP		GENMASK(2, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_WR_CH		GENMASK(9, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_RD_CH		GENMASK(25, 16)
+
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH	0xc
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW	0x8
+#define DW_PCIE_XILINX_INVALID_ADDR		(~0ULL)
+
+#define DW_PCIE_XILINX_LL_OFF_GAP		0x200000
+#define DW_PCIE_XILINX_LL_SIZE			0x800
+#define DW_PCIE_XILINX_DT_OFF_GAP		0x100000
+#define DW_PCIE_XILINX_DT_SIZE			0x800
 
  #define DW_BLOCK(a, b, c) \
  	{ \
@@ -258,10 +258,10 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
  	u16 vsec;
  	u64 off;
 
-	pdata->devmem_phys_off = DW_PCIE_XILINX_MDB_INVALID_ADDR;
+	pdata->devmem_phys_off = DW_PCIE_XILINX_INVALID_ADDR;
 
  	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_DMA_ID);
+					DW_PCIE_XILINX_VSEC_DMA_ID);
  	if (!vsec)
  		return;
 
@@ -272,18 +272,18 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 
  	pci_dbg(pdev, "Detected Xilinx PCIe Vendor-Specific Extended Capability DMA\n");
  	pci_read_config_dword(pdev, vsec + 0x8, &val);
-	map = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_MAP, val);
+	map = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_MAP, val);
  	if (map != EDMA_MF_HDMA_NATIVE)
  		return;
 
  	pdata->mf = map;
-	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_BAR, val);
+	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_BAR, val);
 
  	pci_read_config_dword(pdev, vsec + 0xc, &val);
  	pdata->wr_ch_cnt = min(pdata->wr_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_WR_CH, val));
  	pdata->rd_ch_cnt = min(pdata->rd_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_RD_CH, val));
 
  	pci_read_config_dword(pdev, vsec + 0x14, &val);
  	off = val;
@@ -293,16 +293,16 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
  	pdata->rg.off = off;
 
  	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_ID);
+					DW_PCIE_XILINX_VSEC_ID);
  	if (!vsec)
  		return;
 
  	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH,
  			      &val);
  	off = val;
  	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW,
  			      &val);
  	off <<= 32;
  	off |= val;
@@ -360,7 +360,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
  		 * address use the non-LL mode or simple mode supported by
  		 * the HDMA IP.
  		 */
-		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_MDB_INVALID_ADDR)
+		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_INVALID_ADDR)
  			non_ll = true;
 
  		/*
@@ -370,10 +370,10 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
  		 */
  		if (!non_ll)
  			dw_edma_set_chan_region_offset(vsec_data, BAR_2, 0,
-						       DW_PCIE_XILINX_MDB_LL_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_LL_SIZE,
-						       DW_PCIE_XILINX_MDB_DT_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_DT_SIZE);
+						       DW_PCIE_XILINX_LL_OFF_GAP,
+						       DW_PCIE_XILINX_LL_SIZE,
+						       DW_PCIE_XILINX_DT_OFF_GAP,
+						       DW_PCIE_XILINX_DT_SIZE);
  	}
 
  	/* Mapping PCI BAR regions */
--

2.43.0

#5 lore raw

Re: [PATCH v1 1/3] dmaengine: dw-edma: Make Xilinx Macros Dev Name Agnostic

Quoted 31 lines · Devendra
Quoted 10 lines · Frank Li
Quoted 8 lines · Devendra K Verma

Xilinx specific macros for MDB device can be reused for the Xilinx supported other similar IP such as CPM6.
Renamed the Xilinx specific macros in a way that can be reused for Xilinx supported upcoming IP, CPM6.
Naming is in accordance with the naming done for Synopsys macros.

---

Quoted 8 lines

I don't think it is necessary to remove MDB. You may mention somewhere CMP6 compatible with MDB. It is quite common in driver.

The major concerns is that if a incompatible devices appear, such as CMP7, which have special registers, need add _MDB_ back.

Frank

The MDB was used cause at that time only Xilinx MDB was the IP to go public.
I agree with your suggestion but the idea used here is that, for the common functionalities use the names which are affiliated to vendor that is Xilinx and can be used across the IP having the similarity. In case specific functionality is required for MDB or CPM6 then it can be associated using vendor + device name, that way it is easy to identify which ones are common and specific to the IP.

Quoted 2 lines

Currently, if any functionality added for MDB ONLY then it would be assumed to be supported on Xilinx CPM6 as well.

Rename when this case really appear.

Frank

Quoted 137 lines

To remove the confusion
extra comment would be required to inform which functionality is supported for which IP. That is why the removal of MDB appoach was taken to reduce the confusion and work. The first approach looked clean.

Please let me know your thougths.

-Devendra

Quoted 127 lines
Quoted 127 lines
  drivers/dma/dw-edma/dw-edma-pcie.c | 58 +++++++++++++++---------------
  1 file changed, 29 insertions(+), 29 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +29 -30
index 791c46e8ae4c..ec5e057a0f11 100644
@@ -29,21 +29,21 @@
  #define PCI_DEVICE_ID_XILINX_B054		0xb054
  #define PCI_DEVICE_ID_XILINX_B00F		0xb00f
 
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_ID		0x6
-#define DW_PCIE_XILINX_MDB_VSEC_ID		0x20
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_BAR		GENMASK(10, 8)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_MAP		GENMASK(2, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH	GENMASK(9, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH	GENMASK(25, 16)
-
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH	0xc
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW	0x8
-#define DW_PCIE_XILINX_MDB_INVALID_ADDR		(~0ULL)
-
-#define DW_PCIE_XILINX_MDB_LL_OFF_GAP		0x200000
-#define DW_PCIE_XILINX_MDB_LL_SIZE		0x800
-#define DW_PCIE_XILINX_MDB_DT_OFF_GAP		0x100000
-#define DW_PCIE_XILINX_MDB_DT_SIZE		0x800
+#define DW_PCIE_XILINX_VSEC_DMA_ID		0x6
+#define DW_PCIE_XILINX_VSEC_ID			0x20
+#define DW_PCIE_XILINX_VSEC_DMA_BAR		GENMASK(10, 8)
+#define DW_PCIE_XILINX_VSEC_DMA_MAP		GENMASK(2, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_WR_CH		GENMASK(9, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_RD_CH		GENMASK(25, 16)
+
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH	0xc
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW	0x8
+#define DW_PCIE_XILINX_INVALID_ADDR		(~0ULL)
+
+#define DW_PCIE_XILINX_LL_OFF_GAP		0x200000
+#define DW_PCIE_XILINX_LL_SIZE			0x800
+#define DW_PCIE_XILINX_DT_OFF_GAP		0x100000
+#define DW_PCIE_XILINX_DT_SIZE			0x800
 
  #define DW_BLOCK(a, b, c) \
  	{ \
@@ -258,10 +258,10 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
  	u16 vsec;
  	u64 off;
 
-	pdata->devmem_phys_off = DW_PCIE_XILINX_MDB_INVALID_ADDR;
+	pdata->devmem_phys_off = DW_PCIE_XILINX_INVALID_ADDR;
 
  	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_DMA_ID);
+					DW_PCIE_XILINX_VSEC_DMA_ID);
  	if (!vsec)
  		return;
 
@@ -272,18 +272,18 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 
  	pci_dbg(pdev, "Detected Xilinx PCIe Vendor-Specific Extended Capability DMA\n");
  	pci_read_config_dword(pdev, vsec + 0x8, &val);
-	map = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_MAP, val);
+	map = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_MAP, val);
  	if (map != EDMA_MF_HDMA_NATIVE)
  		return;
 
  	pdata->mf = map;
-	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_BAR, val);
+	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_BAR, val);
 
  	pci_read_config_dword(pdev, vsec + 0xc, &val);
  	pdata->wr_ch_cnt = min(pdata->wr_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_WR_CH, val));
  	pdata->rd_ch_cnt = min(pdata->rd_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_RD_CH, val));
 
  	pci_read_config_dword(pdev, vsec + 0x14, &val);
  	off = val;
@@ -293,16 +293,16 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
  	pdata->rg.off = off;
 
  	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_ID);
+					DW_PCIE_XILINX_VSEC_ID);
  	if (!vsec)
  		return;
 
  	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH,
  			      &val);
  	off = val;
  	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW,
  			      &val);
  	off <<= 32;
  	off |= val;
@@ -360,7 +360,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
  		 * address use the non-LL mode or simple mode supported by
  		 * the HDMA IP.
  		 */
-		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_MDB_INVALID_ADDR)
+		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_INVALID_ADDR)
  			non_ll = true;
 
  		/*
@@ -370,10 +370,10 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
  		 */
  		if (!non_ll)
  			dw_edma_set_chan_region_offset(vsec_data, BAR_2, 0,
-						       DW_PCIE_XILINX_MDB_LL_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_LL_SIZE,
-						       DW_PCIE_XILINX_MDB_DT_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_DT_SIZE);
+						       DW_PCIE_XILINX_LL_OFF_GAP,
+						       DW_PCIE_XILINX_LL_SIZE,
+						       DW_PCIE_XILINX_DT_OFF_GAP,
+						       DW_PCIE_XILINX_DT_SIZE);
  	}
 
  	/* Mapping PCI BAR regions */
--

2.43.0

#6 lore raw

Re: [PATCH v1 1/3] dmaengine: dw-edma: Make Xilinx Macros Dev Name Agnostic

Quoted 32 lines · Frank Li
Quoted 31 lines · Devendra
Quoted 10 lines · Frank Li
Quoted 8 lines · Devendra K Verma

Xilinx specific macros for MDB device can be reused for the Xilinx supported other similar IP such as CPM6.
Renamed the Xilinx specific macros in a way that can be reused for Xilinx supported upcoming IP, CPM6.
Naming is in accordance with the naming done for Synopsys macros.

---

Quoted 8 lines

I don't think it is necessary to remove MDB. You may mention somewhere CMP6 compatible with MDB. It is quite common in driver.

The major concerns is that if a incompatible devices appear, such as CMP7, which have special registers, need add _MDB_ back.

Frank

The MDB was used cause at that time only Xilinx MDB was the IP to go public.
I agree with your suggestion but the idea used here is that, for the common functionalities use the names which are affiliated to vendor that is Xilinx and can be used across the IP having the similarity. In case specific functionality is required for MDB or CPM6 then it can be associated using vendor + device name, that way it is easy to identify which ones are common and specific to the IP.

Quoted 4 lines
Quoted 2 lines

Currently, if any functionality added for MDB ONLY then it would be assumed to be supported on Xilinx CPM6 as well.

Rename when this case really appear.

OK, I take this suggestion. The channel separation is supported for CPM6 so the specific macro will be associated with Vendor + Device name. The rest of the macros could remain generic.
The macro name was kept generic cause the ch_sep_sz for the other Xilinx devices will always be 0 (256B).

-Devendra

Quoted 140 lines

Frank

Quoted 137 lines

To remove the confusion
extra comment would be required to inform which functionality is supported for which IP. That is why the removal of MDB appoach was taken to reduce the confusion and work. The first approach looked clean.

Please let me know your thougths.

-Devendra

Quoted 127 lines
Quoted 127 lines
   drivers/dma/dw-edma/dw-edma-pcie.c | 58 +++++++++++++++---------------
   1 file changed, 29 insertions(+), 29 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +29 -30
index 791c46e8ae4c..ec5e057a0f11 100644
@@ -29,21 +29,21 @@
   #define PCI_DEVICE_ID_XILINX_B054		0xb054
   #define PCI_DEVICE_ID_XILINX_B00F		0xb00f
 
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_ID		0x6
-#define DW_PCIE_XILINX_MDB_VSEC_ID		0x20
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_BAR		GENMASK(10, 8)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_MAP		GENMASK(2, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH	GENMASK(9, 0)
-#define DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH	GENMASK(25, 16)
-
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH	0xc
-#define DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW	0x8
-#define DW_PCIE_XILINX_MDB_INVALID_ADDR		(~0ULL)
-
-#define DW_PCIE_XILINX_MDB_LL_OFF_GAP		0x200000
-#define DW_PCIE_XILINX_MDB_LL_SIZE		0x800
-#define DW_PCIE_XILINX_MDB_DT_OFF_GAP		0x100000
-#define DW_PCIE_XILINX_MDB_DT_SIZE		0x800
+#define DW_PCIE_XILINX_VSEC_DMA_ID		0x6
+#define DW_PCIE_XILINX_VSEC_ID			0x20
+#define DW_PCIE_XILINX_VSEC_DMA_BAR		GENMASK(10, 8)
+#define DW_PCIE_XILINX_VSEC_DMA_MAP		GENMASK(2, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_WR_CH		GENMASK(9, 0)
+#define DW_PCIE_XILINX_VSEC_DMA_RD_CH		GENMASK(25, 16)
+
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH	0xc
+#define DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW	0x8
+#define DW_PCIE_XILINX_INVALID_ADDR		(~0ULL)
+
+#define DW_PCIE_XILINX_LL_OFF_GAP		0x200000
+#define DW_PCIE_XILINX_LL_SIZE			0x800
+#define DW_PCIE_XILINX_DT_OFF_GAP		0x100000
+#define DW_PCIE_XILINX_DT_SIZE			0x800
 
   #define DW_BLOCK(a, b, c) \
   	{ \
@@ -258,10 +258,10 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
   	u16 vsec;
   	u64 off;
 
-	pdata->devmem_phys_off = DW_PCIE_XILINX_MDB_INVALID_ADDR;
+	pdata->devmem_phys_off = DW_PCIE_XILINX_INVALID_ADDR;
 
   	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_DMA_ID);
+					DW_PCIE_XILINX_VSEC_DMA_ID);
   	if (!vsec)
   		return;
 
@@ -272,18 +272,18 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 
   	pci_dbg(pdev, "Detected Xilinx PCIe Vendor-Specific Extended Capability DMA\n");
   	pci_read_config_dword(pdev, vsec + 0x8, &val);
-	map = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_MAP, val);
+	map = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_MAP, val);
   	if (map != EDMA_MF_HDMA_NATIVE)
   		return;
 
   	pdata->mf = map;
-	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_BAR, val);
+	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_BAR, val);
 
   	pci_read_config_dword(pdev, vsec + 0xc, &val);
   	pdata->wr_ch_cnt = min(pdata->wr_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_WR_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_WR_CH, val));
   	pdata->rd_ch_cnt = min(pdata->rd_ch_cnt,
-			       FIELD_GET(DW_PCIE_XILINX_MDB_VSEC_DMA_RD_CH, val));
+			       FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_RD_CH, val));
 
   	pci_read_config_dword(pdev, vsec + 0x14, &val);
   	off = val;
@@ -293,16 +293,16 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
   	pdata->rg.off = off;
 
   	vsec = pci_find_vsec_capability(pdev, PCI_VENDOR_ID_XILINX,
-					DW_PCIE_XILINX_MDB_VSEC_ID);
+					DW_PCIE_XILINX_VSEC_ID);
   	if (!vsec)
   		return;
 
   	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_HIGH,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_HIGH,
   			      &val);
   	off = val;
   	pci_read_config_dword(pdev,
-			      vsec + DW_PCIE_XILINX_MDB_DEVMEM_OFF_REG_LOW,
+			      vsec + DW_PCIE_XILINX_DEVMEM_OFF_REG_LOW,
   			      &val);
   	off <<= 32;
   	off |= val;
@@ -360,7 +360,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
   		 * address use the non-LL mode or simple mode supported by
   		 * the HDMA IP.
   		 */
-		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_MDB_INVALID_ADDR)
+		if (vsec_data->devmem_phys_off == DW_PCIE_XILINX_INVALID_ADDR)
   			non_ll = true;
 
   		/*
@@ -370,10 +370,10 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
   		 */
   		if (!non_ll)
   			dw_edma_set_chan_region_offset(vsec_data, BAR_2, 0,
-						       DW_PCIE_XILINX_MDB_LL_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_LL_SIZE,
-						       DW_PCIE_XILINX_MDB_DT_OFF_GAP,
-						       DW_PCIE_XILINX_MDB_DT_SIZE);
+						       DW_PCIE_XILINX_LL_OFF_GAP,
+						       DW_PCIE_XILINX_LL_SIZE,
+						       DW_PCIE_XILINX_DT_OFF_GAP,
+						       DW_PCIE_XILINX_DT_SIZE);
   	}
 
   	/* Mapping PCI BAR regions */
--

2.43.0

#7 lore raw

PATCH 2/3 dmaengine: dw-edma: Enable Chan Separation via VSEC

In reply to Devendra K Verma

As per, 'Designware Cores PCI Express DM Controller - Reference Manual', section 3.2.34.3, VSEC for DEVICE INFORMATION supports the channel separation mechanisms. Basically, the HDMA IP allows the user to configure the separation between DMA channel registers and retrieve it via the VSEC capability mentioned above.

HDMA IP supports the channel separation up to 32K but for the simplicity channel separation support has been added till 4K. As and when required the function can be expanded to include the higher sizes for channel separation.
Supported and missed out sizes are:
8K (0x5), 16K (0x6), 32K (0x7)

---
 drivers/dma/dw-edma/dw-edma-pcie.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +23 -2
index ec5e057a0f11..6295d01ba2f7 100644
@@ -33,6 +33,7 @@
 #define DW_PCIE_XILINX_VSEC_ID			0x20
 #define DW_PCIE_XILINX_VSEC_DMA_BAR		GENMASK(10, 8)
 #define DW_PCIE_XILINX_VSEC_DMA_MAP		GENMASK(2, 0)
+#define DW_PCIE_XILINX_VSEC_CH_SEP		GENMASK(18, 16)
 #define DW_PCIE_XILINX_VSEC_DMA_WR_CH		GENMASK(9, 0)
 #define DW_PCIE_XILINX_VSEC_DMA_RD_CH		GENMASK(25, 16)
 
@@ -73,6 +74,7 @@ struct dw_edma_pcie_data {
 	u16				wr_ch_cnt;
 	u16				rd_ch_cnt;
 	u64				devmem_phys_off;
+	u32				ch_sep_sz;
 };
 
 static const struct dw_edma_pcie_data snps_edda_data = {
@@ -127,7 +129,7 @@ static const struct dw_edma_pcie_data xilinx_mdb_data = {
 };
 
 static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
-	/* MDB registers location */
+	/* CPM6 registers location */
 	.rg.bar				= BAR_0,
 	.rg.off				= SZ_4K,	/*  4 Kbytes */
 	.rg.sz				= SZ_8K,	/*  8 Kbytes */
@@ -189,6 +191,23 @@ static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr)
 	return pci_irq_vector(to_pci_dev(dev), nr);
 }
 
+static u32 dw_edma_get_ch_sep_sz(u32 ch_sep_val)
+{
+	switch (ch_sep_val) {
+	default:
+	case 0:
+		return 256;
+	case 1:
+		return 512;
+	case 2:
+		return 1024;
+	case 3:
+		return 2048;
+	case 4:
+		return 4096;
+	}
+}
+
 static u64 dw_edma_pcie_address(struct device *dev, phys_addr_t cpu_addr)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -278,6 +297,8 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 
 	pdata->mf = map;
 	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_BAR, val);
+	pdata->ch_sep_sz = dw_edma_get_ch_sep_sz(FIELD_GET(DW_PCIE_XILINX_VSEC_CH_SEP,
+							   val));
 
 	pci_read_config_dword(pdev, vsec + 0xc, &val);
 	pdata->wr_ch_cnt = min(pdata->wr_ch_cnt,
@@ -324,9 +345,9 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 	struct dw_edma_pcie_data *pdata = (void *)pid->driver_data;
 	struct device *dev = &pdev->dev;
 	struct dw_edma_chip *chip;
+	bool non_ll = false;
 	int err, nr_irqs;
 	int i, mask;
-	bool non_ll = false;
 
 	if (!pdata)
 		return -ENODEV;
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH v1 2/3] dmaengine: dw-edma: Enable Chan Separation via VSEC

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] The parsed channel separation size (`ch_sep_sz`) is a dead store; it is never passed to the core…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The parsed channel separation size (ch_sep_sz) is a dead store; it is never passed to the core DMA driver.
- [Medium] dw_edma_get_ch_sep_sz() silently falls back to 256 bytes for unsupported hardware channel separation values.
- [Medium] The newly added ch_sep_sz field is left uninitialized (implicitly 0) for statically defined devices. --

--- Patch [2]: [PATCH v1 2/3] dmaengine: dw-edma: Enable Chan Separation via VSEC --- commit 5d0ec977534da50b8d8937caafb8d91a21d54565
Author: Devendra K Verma <[email protected]>

dmaengine: dw-edma: Enable Chan Separation via VSEC

This commit aims to enable channel separation via the VSEC capability for DEVICE INFORMATION. It parses the channel separation size from the hardware registers up to 4K.

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0 -0
index ec5e057a0f11b..6295d01ba2f71 100644

[ ... ]

drivers/dma/dw-edma/dw-edma-pcie.c struct dw_edma_pcie_data { · line 80

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -0
@@ -73,6 +74,7 @@ struct dw_edma_pcie_data {
 	u16				wr_ch_cnt;
 	u16				rd_ch_cnt;
 	u64				devmem_phys_off;
+	u32				ch_sep_sz;
 };
 
 static const struct dw_edma_pcie_data snps_edda_data = {

[Severity: Medium]
Does this leave the newly added ch_sep_sz field uninitialized (implicitly 0) for statically defined devices like snps_edda_data?

If the core driver begins relying on this field to space out channel registers, will preexisting devices calculate an offset of 0 for all channels and break DMA functionality?

[ ... ]

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr) · line 199

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-pcie.c +6 -0
@@ -189,6 +191,23 @@ static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr)
 	return pci_irq_vector(to_pci_dev(dev), nr);
 }
 
+static u32 dw_edma_get_ch_sep_sz(u32 ch_sep_val)
+{
+	switch (ch_sep_val) {
+	default:
+	case 0:
+		return 256;

[Severity: Medium]
If a hardware device advertises a channel separation size greater than 4K (e.g., 8K/0x5, 16K/0x6, 32K/0x7 as mentioned in the commit message), will this switch statement silently hit the default case and return 256 bytes instead of the actual hardware size, leading to incorrect memory offsets?

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-pcie.c +10 -0
+	case 1:
+		return 512;
+	case 2:
+		return 1024;
+	case 3:
+		return 2048;
+	case 4:
+		return 4096;
+	}
+}

[ ... ]

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_probe(struct pci_dev *pdev, · line 353

Quoted 11 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -1
@@ -324,9 +345,9 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 	struct dw_edma_pcie_data *pdata = (void *)pid->driver_data;
 	struct device *dev = &pdev->dev;
 	struct dw_edma_chip *chip;
+	bool non_ll = false;
 	int err, nr_irqs;
 	int i, mask;
-	bool non_ll = false;
 
 	if (!pdata)
 		return -ENODEV;

[Severity: High]
Is the parsed channel separation size actually used by the core driver?

The VSEC capability is parsed into pdata->ch_sep_sz in this patch, but it doesn't appear to be copied to the struct dw_edma_chip or used anywhere to calculate register offsets, leaving the feature non-functional.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#9 lore raw

Re: [PATCH v1 2/3] dmaengine: dw-edma: Enable Chan Separation via VSEC

In reply to Devendra K Verma
Quoted 24 lines · Devendra K Verma

As per, 'Designware Cores PCI Express DM Controller - Reference Manual', section 3.2.34.3, VSEC for DEVICE INFORMATION supports the channel separation mechanisms. Basically, the HDMA IP allows the user to configure the separation between DMA channel registers and retrieve it via the VSEC capability mentioned above.

HDMA IP supports the channel separation up to 32K but for the simplicity channel separation support has been added till 4K. As and when required the function can be expanded to include the higher sizes for channel separation.
Supported and missed out sizes are:
8K (0x5), 16K (0x6), 32K (0x7)

---
 drivers/dma/dw-edma/dw-edma-pcie.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +0 -0
index ec5e057a0f11..6295d01ba2f7 100644

drivers/dma/dw-edma/dw-edma-pcie.c line 36

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -0
@@ -33,6 +33,7 @@
 #define DW_PCIE_XILINX_VSEC_ID			0x20
 #define DW_PCIE_XILINX_VSEC_DMA_BAR		GENMASK(10, 8)
 #define DW_PCIE_XILINX_VSEC_DMA_MAP		GENMASK(2, 0)
+#define DW_PCIE_XILINX_VSEC_CH_SEP		GENMASK(18, 16)

Can keep as bit pos order for the same register?

Quoted 29 lines
drivers/dma/dw-edma/dw-edma-pcie.c +7 -1
 #define DW_PCIE_XILINX_VSEC_DMA_WR_CH		GENMASK(9, 0)
 #define DW_PCIE_XILINX_VSEC_DMA_RD_CH		GENMASK(25, 16)
 
@@ -73,6 +74,7 @@ struct dw_edma_pcie_data {
 	u16				wr_ch_cnt;
 	u16				rd_ch_cnt;
 	u64				devmem_phys_off;
+	u32				ch_sep_sz;
 };
 
 static const struct dw_edma_pcie_data snps_edda_data = {
@@ -127,7 +129,7 @@ static const struct dw_edma_pcie_data xilinx_mdb_data = {
 };
 
 static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
-	/* MDB registers location */
+	/* CPM6 registers location */
 	.rg.bar				= BAR_0,
 	.rg.off				= SZ_4K,	/*  4 Kbytes */
 	.rg.sz				= SZ_8K,	/*  8 Kbytes */
@@ -189,6 +191,23 @@ static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr)
 	return pci_irq_vector(to_pci_dev(dev), nr);
 }
 
+static u32 dw_edma_get_ch_sep_sz(u32 ch_sep_val)
+{
+	switch (ch_sep_val) {
+	default:
+	case 0:

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr) · line 208

Quoted 10 lines
drivers/dma/dw-edma/dw-edma-pcie.c +10 -0
+		return 256;
+	case 1:
+		return 512;
+	case 2:
+		return 1024;
+	case 3:
+		return 2048;
+	case 4:
+		return 4096;
+	}
	256 << ch_sep_val ?
Quoted 15 lines
drivers/dma/dw-edma/dw-edma-pcie.c +4 -0
+}
+
 static u64 dw_edma_pcie_address(struct device *dev, phys_addr_t cpu_addr)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
@@ -278,6 +297,8 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 
 	pdata->mf = map;
 	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_BAR, val);
+	pdata->ch_sep_sz = dw_edma_get_ch_sep_sz(FIELD_GET(DW_PCIE_XILINX_VSEC_CH_SEP,
+							   val));
 
 	pci_read_config_dword(pdev, vsec + 0xc, &val);
 	pdata->wr_ch_cnt = min(pdata->wr_ch_cnt,

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_probe(struct pci_dev *pdev, · line 329

Quoted 7 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -1
@@ -324,9 +345,9 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 	struct dw_edma_pcie_data *pdata = (void *)pid->driver_data;
 	struct device *dev = &pdev->dev;
 	struct dw_edma_chip *chip;
+	bool non_ll = false;
 	int err, nr_irqs;
 	int i, mask;
-	bool non_ll = false;

unnessary change here.

Frank

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0 -1
 	if (!pdata)
 		return -ENODEV;
--

2.43.0

#10 lore raw

Re: [PATCH v1 2/3] dmaengine: dw-edma: Enable Chan Separation via VSEC

Quoted 65 lines · Frank Li
Quoted 24 lines · Devendra K Verma

As per, 'Designware Cores PCI Express DM Controller - Reference Manual', section 3.2.34.3, VSEC for DEVICE INFORMATION supports the channel separation mechanisms. Basically, the HDMA IP allows the user to configure the separation between DMA channel registers and retrieve it via the VSEC capability mentioned above.

HDMA IP supports the channel separation up to 32K but for the simplicity channel separation support has been added till 4K. As and when required the function can be expanded to include the higher sizes for channel separation.
Supported and missed out sizes are:
8K (0x5), 16K (0x6), 32K (0x7)

---
  drivers/dma/dw-edma/dw-edma-pcie.c | 25 +++++++++++++++++++++++--
  1 file changed, 23 insertions(+), 2 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +0 -0
index ec5e057a0f11..6295d01ba2f7 100644

drivers/dma/dw-edma/dw-edma-pcie.c line 36

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -0
@@ -33,6 +33,7 @@
  #define DW_PCIE_XILINX_VSEC_ID			0x20
  #define DW_PCIE_XILINX_VSEC_DMA_BAR		GENMASK(10, 8)
  #define DW_PCIE_XILINX_VSEC_DMA_MAP		GENMASK(2, 0)
+#define DW_PCIE_XILINX_VSEC_CH_SEP		GENMASK(18, 16)

Can keep as bit pos order for the same register?

Quoted 33 lines
drivers/dma/dw-edma/dw-edma-pcie.c +11 -1
  #define DW_PCIE_XILINX_VSEC_DMA_WR_CH		GENMASK(9, 0)
  #define DW_PCIE_XILINX_VSEC_DMA_RD_CH		GENMASK(25, 16)
 
@@ -73,6 +74,7 @@ struct dw_edma_pcie_data {
  	u16				wr_ch_cnt;
  	u16				rd_ch_cnt;
  	u64				devmem_phys_off;
+	u32				ch_sep_sz;
  };
 
  static const struct dw_edma_pcie_data snps_edda_data = {
@@ -127,7 +129,7 @@ static const struct dw_edma_pcie_data xilinx_mdb_data = {
  };
 
  static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
-	/* MDB registers location */
+	/* CPM6 registers location */
  	.rg.bar				= BAR_0,
  	.rg.off				= SZ_4K,	/*  4 Kbytes */
  	.rg.sz				= SZ_8K,	/*  8 Kbytes */
@@ -189,6 +191,23 @@ static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr)
  	return pci_irq_vector(to_pci_dev(dev), nr);
  }
 
+static u32 dw_edma_get_ch_sep_sz(u32 ch_sep_val)
+{
+	switch (ch_sep_val) {
+	default:
+	case 0:
+		return 256;
+	case 1:
+		return 512;
+	case 2:
Quoted 9 lines

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr) · line 208

Quoted 6 lines
drivers/dma/dw-edma/dw-edma-pcie.c +6 -0
+		return 1024;
+	case 3:
+		return 2048;
+	case 4:
+		return 4096;
+	}
	256 << ch_sep_val ?

Thank you for this suggestion.

Quoted 26 lines
Quoted 16 lines
drivers/dma/dw-edma/dw-edma-pcie.c +4 -0
+}
+
  static u64 dw_edma_pcie_address(struct device *dev, phys_addr_t cpu_addr)
  {
  	struct pci_dev *pdev = to_pci_dev(dev);
@@ -278,6 +297,8 @@ static void dw_edma_pcie_get_xilinx_dma_data(struct pci_dev *pdev,
 
  	pdata->mf = map;
  	pdata->rg.bar = FIELD_GET(DW_PCIE_XILINX_VSEC_DMA_BAR, val);
+	pdata->ch_sep_sz = dw_edma_get_ch_sep_sz(FIELD_GET(DW_PCIE_XILINX_VSEC_CH_SEP,
+							   val));
 
  	pci_read_config_dword(pdev, vsec + 0xc, &val);
  	pdata->wr_ch_cnt = min(pdata->wr_ch_cnt,

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_probe(struct pci_dev *pdev, · line 329

Quoted 7 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -1
@@ -324,9 +345,9 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
  	struct dw_edma_pcie_data *pdata = (void *)pid->driver_data;
  	struct device *dev = &pdev->dev;
  	struct dw_edma_chip *chip;
+	bool non_ll = false;
  	int err, nr_irqs;
  	int i, mask;
-	bool non_ll = false;

unnessary change here.

Quoted 1 line

Frank

Just wanted to maintain the inverted X-tree formatting. Missed this in the previous submitted patch series.

Quoted 6 lines
Quoted 6 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0 -1
  	if (!pdata)
  		return -ENODEV;
--

2.43.0

#11 lore raw

PATCH 3/3 dmaengine: dw-edma: Add changes to support Channel Separation

In reply to Devendra K Verma

Following changes are made:
o In 'struct dw_hdma_v0_ch_regs', it is assumed the channel separation as 256-bytes which is default, but if an IP is configured for a different size of channel separation then user can retrieve it using the supported VSEC (0x6). Modified the struct to work with the channel separation supported by IP.
CPM6 supports channel separation, default is 512.
o Changes in macros / functions where address of the channel is accessed based on channel index and direction. It enables the calculation of the channel reg base address based on the selected channel separation.
o Struct removed - dw_hdma_v0_ch, dw_hdma_v0_regs
o Functions removed - __dw_regs()

---
 drivers/dma/dw-edma/dw-edma-pcie.c       |  4 ++++
 drivers/dma/dw-edma/dw-hdma-v0-core.c    | 23 ++++++++++++++---------
 drivers/dma/dw-edma/dw-hdma-v0-debugfs.c | 17 ++++++-----------
 drivers/dma/dw-edma/dw-hdma-v0-regs.h    | 10 ----------
 include/linux/dma/edma.h                 |  1 +
 5 files changed, 25 insertions(+), 30 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +4 -0
index 6295d01ba2f7..ca2a4be2f3a5 100644
@@ -113,6 +113,7 @@ static const struct dw_edma_pcie_data snps_edda_data = {
 	.irqs				= 1,
 	.wr_ch_cnt			= 2,
 	.rd_ch_cnt			= 2,
+	.ch_sep_sz			= 256,
 };
 
 static const struct dw_edma_pcie_data xilinx_mdb_data = {
@@ -126,6 +127,7 @@ static const struct dw_edma_pcie_data xilinx_mdb_data = {
 	.irqs				= 1,
 	.wr_ch_cnt			= 8,
 	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 256,
 };
 
 static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
@@ -139,6 +141,7 @@ static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
 	.irqs				= 1,
 	.wr_ch_cnt			= 8,
 	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 512,
 };
 
 static void dw_edma_set_chan_region_offset(struct dw_edma_pcie_data *pdata,
@@ -443,6 +446,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 	chip->nr_irqs = nr_irqs;
 	chip->ops = &dw_edma_pcie_plat_ops;
 	chip->cfg_non_ll = non_ll;
+	chip->ch_sep_sz = vsec_data->ch_sep_sz;
 
 	chip->ll_wr_cnt = vsec_data->wr_ch_cnt;
 	chip->ll_rd_cnt = vsec_data->rd_ch_cnt;
drivers/dma/dw-edma/dw-hdma-v0-core.c +14 -9
index 632abb8b481c..3f27a93c4d8c 100644
@@ -23,18 +23,23 @@ enum dw_hdma_control {
 	DW_HDMA_V0_LLE					= BIT(9),
 };
 
-static inline struct dw_hdma_v0_regs __iomem *__dw_regs(struct dw_edma *dw)
-{
-	return dw->chip->reg_base;
-}
-
 static inline struct dw_hdma_v0_ch_regs __iomem *
 __dw_ch_regs(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch)
 {
-	if (dir == EDMA_DIR_WRITE)
-		return &(__dw_regs(dw)->ch[ch].wr);
-	else
-		return &(__dw_regs(dw)->ch[ch].rd);
+	u32 ch_base;
+
+	/*
+	 * For Write, the channel register index starts at
+	 * wr_base(ch_idx) = (2 * ch_idx) * ch_sep_sz
+	 *
+	 * For Read channel,
+	 * rd_base(ch_idx) = (2 * ch_idx + 1) * ch_sep_sz
+	 */
+	ch_base = 2 * ch;
+	if (dir == EDMA_DIR_READ)
+		ch_base += 1;
+
+	return dw->chip->reg_base + (ch_base * dw->chip->ch_sep_sz);
 }
 
 #define SET_CH_32(dw, dir, ch, name, value) \
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +6 -11
index dcdc57fe976c..33128685bbd9 100644
@@ -13,22 +13,17 @@
 #include "dw-hdma-v0-regs.h"
 #include "dw-edma-core.h"
 
-#define REGS_ADDR(dw, name)						       \
-	({								       \
-		struct dw_hdma_v0_regs __iomem *__regs = (dw)->chip->reg_base; \
-									       \
-		(void __iomem *)&__regs->name;				       \
-	})
-
 #define REGS_CH_ADDR(dw, name, _dir, _ch)				       \
 	({								       \
-		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;		       \
+		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;                  \
+		off_t __off = (dw)->chip->ch_sep_sz;			       \
 									       \
-		if (_dir == EDMA_DIR_READ)				       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].rd);		       \
+		if ((_dir) == EDMA_DIR_READ)				       \
+			__off *= (2 * (_ch) + 1);			       \
 		else							       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].wr);		       \
+			__off *= (2 * (_ch));				       \
 									       \
+		__ch_regs = ((dw)->chip->reg_base + __off);		       \
 		(void __iomem *)&__ch_regs->name;			       \
 	})
 
drivers/dma/dw-edma/dw-hdma-v0-regs.h +0 -10
index 7759ba9b4850..2475b8d96133 100644
@@ -84,16 +84,6 @@ struct dw_hdma_v0_ch_regs {
 		};
 	} msi_abort;
 	u32 msi_msgdata;			/* 0x00a8 */
-	u32 padding_2[21];			/* 0x00ac..0x00fc */
-} __packed;
-
-struct dw_hdma_v0_ch {
-	struct dw_hdma_v0_ch_regs wr;		/* 0x0000 */
-	struct dw_hdma_v0_ch_regs rd;		/* 0x0100 */
-} __packed;
-
-struct dw_hdma_v0_regs {
-	struct dw_hdma_v0_ch ch[HDMA_V0_MAX_NR_CH];	/* 0x0000..0x0fa8 */
 } __packed;
 
 struct dw_hdma_v0_lli {
include/linux/dma/edma.h +1 -0
index 1fafd5b0e315..a6c5728f03d3 100644
@@ -104,6 +104,7 @@ struct dw_edma_chip {
 
 	struct dw_edma		*dw;
 	bool			cfg_non_ll;
+	u32			ch_sep_sz;
 };
 
 /* Export to the platform drivers */
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH v1 3/3] dmaengine: dw-edma: Add changes to support Channel Separation

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] The newly introduced ch_sep_sz field in struct dw_edma_chip is uninitialized (defaults to 0) for platform drivers outside of dw-edma-pcie that use HDMA natively, causing all channel register accesses to map to identical offset 0.
- [High] The driver trusts the device-provided VSEC configuration to calculate DMA channel register offsets but never verifies if these offsets remain within the mapped PCI BAR region.

Pre-existing issues:
- [High] Pre-existing double free of IRQ vectors in dw_edma_pcie_remove() due to devres interference. --

--- Patch [3]: [PATCH v1 3/3] dmaengine: dw-edma: Add changes to support Channel Separation --- commit 2ad7c860cd4c4a1bef961b814db689f718e1407c
Author: Devendra K Verma <[email protected]>

dmaengine: dw-edma: Add changes to support Channel Separation

This patch modifies the dw-edma driver to support configurable channel separation sizes. It updates the register offset calculations to use a dynamic size provided by the hardware IP instead of assuming a default 256-byte separation.

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0 -0
index 6295d01ba2f71..ca2a4be2f3a50 100644

[ ... ]

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_probe(struct pci_dev *pdev, · line 452

Quoted 8 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -0
@@ -443,6 +446,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 	chip->nr_irqs = nr_irqs;
 	chip->ops = &dw_edma_pcie_plat_ops;
 	chip->cfg_non_ll = non_ll;
+	chip->ch_sep_sz = vsec_data->ch_sep_sz;
 
 	chip->ll_wr_cnt = vsec_data->wr_ch_cnt;
 	chip->ll_rd_cnt = vsec_data->rd_ch_cnt;

[Severity: High]
This is a pre-existing issue, but does dw_edma_pcie_remove() explicitly call pci_free_irq_vectors(pdev)?

Since pcim_enable_device(pdev) is called during dw_edma_pcie_probe(), it automatically manages subsequent IRQ vectors via devres. When the driver is unbound, the devres cleanup routine will attempt to free the already-freed vectors, which could cause a double-free kernel panic on the device unbind or module unload path.

Quoted 4 lines
drivers/dma/dw-edma/dw-hdma-v0-core.c +0 -0
index 632abb8b481cf..3f27a93c4d8c8 100644

[ ... ]

Quoted 20 lines
drivers/dma/dw-edma/dw-hdma-v0-core.c +4 -9
@@ -23,18 +23,23 @@ enum dw_hdma_control {
 	DW_HDMA_V0_LLE					= BIT(9),
 };
 
-static inline struct dw_hdma_v0_regs __iomem *__dw_regs(struct dw_edma *dw)
-{
-	return dw->chip->reg_base;
-}
-
 static inline struct dw_hdma_v0_ch_regs __iomem *
 __dw_ch_regs(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch)
 {
-	if (dir == EDMA_DIR_WRITE)
-		return &(__dw_regs(dw)->ch[ch].wr);
-	else
-		return &(__dw_regs(dw)->ch[ch].rd);
+	u32 ch_base;
+
+	/*
+	 * For Write, the channel register index starts at

drivers/dma/dw-edma/dw-hdma-v0-core.c enum dw_hdma_control { · line 42

Quoted 10 lines
drivers/dma/dw-edma/dw-hdma-v0-core.c +10 -0
+	 * wr_base(ch_idx) = (2 * ch_idx) * ch_sep_sz
+	 *
+	 * For Read channel,
+	 * rd_base(ch_idx) = (2 * ch_idx + 1) * ch_sep_sz
+	 */
+	ch_base = 2 * ch;
+	if (dir == EDMA_DIR_READ)
+		ch_base += 1;
+
+	return dw->chip->reg_base + (ch_base * dw->chip->ch_sep_sz);

[Severity: High]
Does this code verify that the computed channel register offset remains within the mapped PCI BAR region?

If a malicious or misconfigured PCIe endpoint provides a large channel separation size, could this calculation result in out-of-bounds MMIO accesses?

[Severity: High]
If platform drivers outside of dw-edma-pcie use HDMA natively and allocate struct dw_edma_chip via devm_kzalloc without explicitly initializing ch_sep_sz, does ch_sep_sz default to 0?

Could this cause all channel register accesses to map to offset 0, leading to data corruption by incorrectly targeting Write Channel 0's registers?

Quoted 6 lines
drivers/dma/dw-edma/dw-hdma-v0-core.c +0 -0
 }
 
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +0 -0
index dcdc57fe976c1..33128685bbd90 100644

[ ... ]

Quoted 16 lines
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +2 -8
@@ -13,22 +13,17 @@
 #include "dw-hdma-v0-regs.h"
 #include "dw-edma-core.h"
 
-#define REGS_ADDR(dw, name)						       \
-	({								       \
-		struct dw_hdma_v0_regs __iomem *__regs = (dw)->chip->reg_base; \
-									       \
-		(void __iomem *)&__regs->name;				       \
-	})
-
 #define REGS_CH_ADDR(dw, name, _dir, _ch)				       \
 	({								       \
-		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;		       \
+		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;                  \
+		off_t __off = (dw)->chip->ch_sep_sz;			       \

drivers/dma/dw-edma/dw-hdma-v0-debugfs.c line 26

Quoted 10 lines
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +4 -3
 									       \
-		if (_dir == EDMA_DIR_READ)				       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].rd);		       \
+		if ((_dir) == EDMA_DIR_READ)				       \
+			__off *= (2 * (_ch) + 1);			       \
 		else							       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].wr);		       \
+			__off *= (2 * (_ch));				       \
 									       \
+		__ch_regs = ((dw)->chip->reg_base + __off);		       \

[Severity: High]
Could this also lead to out-of-bounds MMIO accesses during debugfs reads?

If the untrusted channel separation size is used to compute the offset, and userspace triggers a debugfs read, it seems this could be exploited if not validated against the BAR size.

include/linux/dma/edma.h struct dw_edma_chip { · line 107

Quoted 12 lines
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +0 -0
 		(void __iomem *)&__ch_regs->name;			       \
 	})
 
include/linux/dma/edma.h +1 -0
index 1fafd5b0e3153..a6c5728f03d38 100644
@@ -104,6 +104,7 @@ struct dw_edma_chip {
 
 	struct dw_edma		*dw;
 	bool			cfg_non_ll;
+	u32			ch_sep_sz;

[Severity: High]
Does this new field need a fallback default for non-PCIe drivers?

Other core drivers that instantiate struct dw_edma_chip for HDMA might not explicitly set this, leaving it uninitialized.

Quoted 3 lines
include/linux/dma/edma.h +0 -0
 };
 
 /* Export to the platform drivers */
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#13 lore raw

Re: [PATCH v1 3/3] dmaengine: dw-edma: Add changes to support Channel Separation

In reply to Devendra K Verma

On Wed, Jul 22, 2026 at 04:46:40PM +0530, Devendra K Verma wrote:

Add Koichiro Den, who did many work with this edma driver recently

Quoted 3 lines

Following changes are made:
o In 'struct dw_hdma_v0_ch_regs', it is assumed the channel separation as 256-bytes which is default, but if an IP is

channel register space size?

Quoted 7 lines

configured for a different size of channel separation then user can retrieve it using the supported VSEC (0x6). Modified the struct to work with the channel separation supported by IP.
CPM6 supports channel separation, default is 512.

Quoted 6 lines

o Changes in macros / functions where address of the channel is accessed based on channel index and direction. It enables the calculation of the channel reg base address based on the selected channel separation.
o Struct removed - dw_hdma_v0_ch, dw_hdma_v0_regs
o Functions removed - __dw_regs()

Can you summary change and purpose? such as

Support difference channel register space size for difference IP. Previous use fix default value 256, CMP6 support difference register space size, which default value is 512.

Update channel register base address caluator method by use ch_space_sze and remove unused dw_hdma_v0_ch, dw_hdma_v0_regs.

You can rephrase.

Quoted 39 lines
---
 drivers/dma/dw-edma/dw-edma-pcie.c       |  4 ++++
 drivers/dma/dw-edma/dw-hdma-v0-core.c    | 23 ++++++++++++++---------
 drivers/dma/dw-edma/dw-hdma-v0-debugfs.c | 17 ++++++-----------
 drivers/dma/dw-edma/dw-hdma-v0-regs.h    | 10 ----------
 include/linux/dma/edma.h                 |  1 +
 5 files changed, 25 insertions(+), 30 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +3 -0
index 6295d01ba2f7..ca2a4be2f3a5 100644
@@ -113,6 +113,7 @@ static const struct dw_edma_pcie_data snps_edda_data = {
 	.irqs				= 1,
 	.wr_ch_cnt			= 2,
 	.rd_ch_cnt			= 2,
+	.ch_sep_sz			= 256,
 };
 
 static const struct dw_edma_pcie_data xilinx_mdb_data = {
@@ -126,6 +127,7 @@ static const struct dw_edma_pcie_data xilinx_mdb_data = {
 	.irqs				= 1,
 	.wr_ch_cnt			= 8,
 	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 256,
 };
 
 static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
@@ -139,6 +141,7 @@ static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
 	.irqs				= 1,
 	.wr_ch_cnt			= 8,
 	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 512,
 };
 
 static void dw_edma_set_chan_region_offset(struct dw_edma_pcie_data *pdata,

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_probe(struct pci_dev *pdev, · line 449

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -0
@@ -443,6 +446,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
 	chip->nr_irqs = nr_irqs;
 	chip->ops = &dw_edma_pcie_plat_ops;
 	chip->cfg_non_ll = non_ll;
+	chip->ch_sep_sz = vsec_data->ch_sep_sz;

This blocks PCI endpoint DMA, this driver is not only used by this. EPC controller will not set this value, so ch_sep_sz will be 0 for EPC controller.

Frank

Quoted 109 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0 -0
 	chip->ll_wr_cnt = vsec_data->wr_ch_cnt;
 	chip->ll_rd_cnt = vsec_data->rd_ch_cnt;
drivers/dma/dw-edma/dw-hdma-v0-core.c +14 -9
index 632abb8b481c..3f27a93c4d8c 100644
@@ -23,18 +23,23 @@ enum dw_hdma_control {
 	DW_HDMA_V0_LLE					= BIT(9),
 };
 
-static inline struct dw_hdma_v0_regs __iomem *__dw_regs(struct dw_edma *dw)
-{
-	return dw->chip->reg_base;
-}
-
 static inline struct dw_hdma_v0_ch_regs __iomem *
 __dw_ch_regs(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch)
 {
-	if (dir == EDMA_DIR_WRITE)
-		return &(__dw_regs(dw)->ch[ch].wr);
-	else
-		return &(__dw_regs(dw)->ch[ch].rd);
+	u32 ch_base;
+
+	/*
+	 * For Write, the channel register index starts at
+	 * wr_base(ch_idx) = (2 * ch_idx) * ch_sep_sz
+	 *
+	 * For Read channel,
+	 * rd_base(ch_idx) = (2 * ch_idx + 1) * ch_sep_sz
+	 */
+	ch_base = 2 * ch;
+	if (dir == EDMA_DIR_READ)
+		ch_base += 1;
+
+	return dw->chip->reg_base + (ch_base * dw->chip->ch_sep_sz);
 }
 
 #define SET_CH_32(dw, dir, ch, name, value) \
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +6 -11
index dcdc57fe976c..33128685bbd9 100644
@@ -13,22 +13,17 @@
 #include "dw-hdma-v0-regs.h"
 #include "dw-edma-core.h"
 
-#define REGS_ADDR(dw, name)						       \
-	({								       \
-		struct dw_hdma_v0_regs __iomem *__regs = (dw)->chip->reg_base; \
-									       \
-		(void __iomem *)&__regs->name;				       \
-	})
-
 #define REGS_CH_ADDR(dw, name, _dir, _ch)				       \
 	({								       \
-		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;		       \
+		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;                  \
+		off_t __off = (dw)->chip->ch_sep_sz;			       \
 									       \
-		if (_dir == EDMA_DIR_READ)				       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].rd);		       \
+		if ((_dir) == EDMA_DIR_READ)				       \
+			__off *= (2 * (_ch) + 1);			       \
 		else							       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].wr);		       \
+			__off *= (2 * (_ch));				       \
 									       \
+		__ch_regs = ((dw)->chip->reg_base + __off);		       \
 		(void __iomem *)&__ch_regs->name;			       \
 	})
 
drivers/dma/dw-edma/dw-hdma-v0-regs.h +0 -10
index 7759ba9b4850..2475b8d96133 100644
@@ -84,16 +84,6 @@ struct dw_hdma_v0_ch_regs {
 		};
 	} msi_abort;
 	u32 msi_msgdata;			/* 0x00a8 */
-	u32 padding_2[21];			/* 0x00ac..0x00fc */
-} __packed;
-
-struct dw_hdma_v0_ch {
-	struct dw_hdma_v0_ch_regs wr;		/* 0x0000 */
-	struct dw_hdma_v0_ch_regs rd;		/* 0x0100 */
-} __packed;
-
-struct dw_hdma_v0_regs {
-	struct dw_hdma_v0_ch ch[HDMA_V0_MAX_NR_CH];	/* 0x0000..0x0fa8 */
 } __packed;
 
 struct dw_hdma_v0_lli {
include/linux/dma/edma.h +1 -1
index 1fafd5b0e315..a6c5728f03d3 100644
@@ -104,6 +104,7 @@ struct dw_edma_chip {
 
 	struct dw_edma		*dw;
 	bool			cfg_non_ll;
+	u32			ch_sep_sz;
 };
 
 /* Export to the platform drivers */
--

2.43.0

#14 lore raw

Re: [PATCH v1 3/3] dmaengine: dw-edma: Add changes to support Channel Separation

Quoted 4 lines · Frank Li

On Wed, Jul 22, 2026 at 04:46:40PM +0530, Devendra K Verma wrote:

Add Koichiro Den, who did many work with this edma driver recently

Sure, thanks!

Quoted 22 lines
Quoted 3 lines

Following changes are made:
o In 'struct dw_hdma_v0_ch_regs', it is assumed the channel separation as 256-bytes which is default, but if an IP is

channel register space size?

Quoted 7 lines

configured for a different size of channel separation then user can retrieve it using the supported VSEC (0x6). Modified the struct to work with the channel separation supported by IP.
CPM6 supports channel separation, default is 512.

Quoted 6 lines

o Changes in macros / functions where address of the channel is accessed based on channel index and direction. It enables the calculation of the channel reg base address based on the selected channel separation.
o Struct removed - dw_hdma_v0_ch, dw_hdma_v0_regs
o Functions removed - __dw_regs()

Can you summary change and purpose? such as

Quoted 9 lines

Support difference channel register space size for difference IP. Previous use fix default value 256, CMP6 support difference register space size, which default value is 512.

Update channel register base address caluator method by use ch_space_sze and remove unused dw_hdma_v0_ch, dw_hdma_v0_regs.

You can rephrase.

Sure, I will rephrase this. Thank you for the suggestion!

Quoted 49 lines
Quoted 39 lines
---
  drivers/dma/dw-edma/dw-edma-pcie.c       |  4 ++++
  drivers/dma/dw-edma/dw-hdma-v0-core.c    | 23 ++++++++++++++---------
  drivers/dma/dw-edma/dw-hdma-v0-debugfs.c | 17 ++++++-----------
  drivers/dma/dw-edma/dw-hdma-v0-regs.h    | 10 ----------
  include/linux/dma/edma.h                 |  1 +
  5 files changed, 25 insertions(+), 30 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +3 -0
index 6295d01ba2f7..ca2a4be2f3a5 100644
@@ -113,6 +113,7 @@ static const struct dw_edma_pcie_data snps_edda_data = {
  	.irqs				= 1,
  	.wr_ch_cnt			= 2,
  	.rd_ch_cnt			= 2,
+	.ch_sep_sz			= 256,
  };
 
  static const struct dw_edma_pcie_data xilinx_mdb_data = {
@@ -126,6 +127,7 @@ static const struct dw_edma_pcie_data xilinx_mdb_data = {
  	.irqs				= 1,
  	.wr_ch_cnt			= 8,
  	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 256,
  };
 
  static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
@@ -139,6 +141,7 @@ static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
  	.irqs				= 1,
  	.wr_ch_cnt			= 8,
  	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 512,
  };
 
  static void dw_edma_set_chan_region_offset(struct dw_edma_pcie_data *pdata,

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_probe(struct pci_dev *pdev, · line 449

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -0
@@ -443,6 +446,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
  	chip->nr_irqs = nr_irqs;
  	chip->ops = &dw_edma_pcie_plat_ops;
  	chip->cfg_non_ll = non_ll;
+	chip->ch_sep_sz = vsec_data->ch_sep_sz;

This blocks PCI endpoint DMA, this driver is not only used by this. EPC controller will not set this value, so ch_sep_sz will be 0 for EPC controller.

Quoted 2 lines

Frank

The EPC driver is using the chip->reg_base + reg_offset for computing the final addresse and not using the register mappings. If the reg_offset are correct then this ch_sep_sz change will not affect the EPC driver.

Quoted 109 lines
Quoted 109 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0 -0
  	chip->ll_wr_cnt = vsec_data->wr_ch_cnt;
  	chip->ll_rd_cnt = vsec_data->rd_ch_cnt;
drivers/dma/dw-edma/dw-hdma-v0-core.c +14 -9
index 632abb8b481c..3f27a93c4d8c 100644
@@ -23,18 +23,23 @@ enum dw_hdma_control {
  	DW_HDMA_V0_LLE					= BIT(9),
  };
 
-static inline struct dw_hdma_v0_regs __iomem *__dw_regs(struct dw_edma *dw)
-{
-	return dw->chip->reg_base;
-}
-
  static inline struct dw_hdma_v0_ch_regs __iomem *
  __dw_ch_regs(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch)
  {
-	if (dir == EDMA_DIR_WRITE)
-		return &(__dw_regs(dw)->ch[ch].wr);
-	else
-		return &(__dw_regs(dw)->ch[ch].rd);
+	u32 ch_base;
+
+	/*
+	 * For Write, the channel register index starts at
+	 * wr_base(ch_idx) = (2 * ch_idx) * ch_sep_sz
+	 *
+	 * For Read channel,
+	 * rd_base(ch_idx) = (2 * ch_idx + 1) * ch_sep_sz
+	 */
+	ch_base = 2 * ch;
+	if (dir == EDMA_DIR_READ)
+		ch_base += 1;
+
+	return dw->chip->reg_base + (ch_base * dw->chip->ch_sep_sz);
  }
 
  #define SET_CH_32(dw, dir, ch, name, value) \
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +6 -11
index dcdc57fe976c..33128685bbd9 100644
@@ -13,22 +13,17 @@
  #include "dw-hdma-v0-regs.h"
  #include "dw-edma-core.h"
 
-#define REGS_ADDR(dw, name)						       \
-	({								       \
-		struct dw_hdma_v0_regs __iomem *__regs = (dw)->chip->reg_base; \
-									       \
-		(void __iomem *)&__regs->name;				       \
-	})
-
  #define REGS_CH_ADDR(dw, name, _dir, _ch)				       \
  	({								       \
-		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;		       \
+		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;                  \
+		off_t __off = (dw)->chip->ch_sep_sz;			       \
  									       \
-		if (_dir == EDMA_DIR_READ)				       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].rd);		       \
+		if ((_dir) == EDMA_DIR_READ)				       \
+			__off *= (2 * (_ch) + 1);			       \
  		else							       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].wr);		       \
+			__off *= (2 * (_ch));				       \
  									       \
+		__ch_regs = ((dw)->chip->reg_base + __off);		       \
  		(void __iomem *)&__ch_regs->name;			       \
  	})
 
drivers/dma/dw-edma/dw-hdma-v0-regs.h +0 -10
index 7759ba9b4850..2475b8d96133 100644
@@ -84,16 +84,6 @@ struct dw_hdma_v0_ch_regs {
  		};
  	} msi_abort;
  	u32 msi_msgdata;			/* 0x00a8 */
-	u32 padding_2[21];			/* 0x00ac..0x00fc */
-} __packed;
-
-struct dw_hdma_v0_ch {
-	struct dw_hdma_v0_ch_regs wr;		/* 0x0000 */
-	struct dw_hdma_v0_ch_regs rd;		/* 0x0100 */
-} __packed;
-
-struct dw_hdma_v0_regs {
-	struct dw_hdma_v0_ch ch[HDMA_V0_MAX_NR_CH];	/* 0x0000..0x0fa8 */
  } __packed;
 
  struct dw_hdma_v0_lli {
include/linux/dma/edma.h +1 -1
index 1fafd5b0e315..a6c5728f03d3 100644
@@ -104,6 +104,7 @@ struct dw_edma_chip {
 
  	struct dw_edma		*dw;
  	bool			cfg_non_ll;
+	u32			ch_sep_sz;
  };
 
  /* Export to the platform drivers */
--

2.43.0

#15 lore raw

Re: [PATCH v1 3/3] dmaengine: dw-edma: Add changes to support Channel Separation

Quoted 93 lines · Devendra
Quoted 4 lines · Frank Li

On Wed, Jul 22, 2026 at 04:46:40PM +0530, Devendra K Verma wrote:

Add Koichiro Den, who did many work with this edma driver recently

Sure, thanks!

Quoted 22 lines
Quoted 3 lines

Following changes are made:
o In 'struct dw_hdma_v0_ch_regs', it is assumed the channel separation as 256-bytes which is default, but if an IP is

channel register space size?

Quoted 7 lines

configured for a different size of channel separation then user can retrieve it using the supported VSEC (0x6). Modified the struct to work with the channel separation supported by IP.
CPM6 supports channel separation, default is 512.

Quoted 6 lines

o Changes in macros / functions where address of the channel is accessed based on channel index and direction. It enables the calculation of the channel reg base address based on the selected channel separation.
o Struct removed - dw_hdma_v0_ch, dw_hdma_v0_regs
o Functions removed - __dw_regs()

Can you summary change and purpose? such as

Quoted 9 lines

Support difference channel register space size for difference IP. Previous use fix default value 256, CMP6 support difference register space size, which default value is 512.

Update channel register base address caluator method by use ch_space_sze and remove unused dw_hdma_v0_ch, dw_hdma_v0_regs.

You can rephrase.

Sure, I will rephrase this. Thank you for the suggestion!

Quoted 49 lines
Quoted 39 lines
---
  drivers/dma/dw-edma/dw-edma-pcie.c       |  4 ++++
  drivers/dma/dw-edma/dw-hdma-v0-core.c    | 23 ++++++++++++++---------
  drivers/dma/dw-edma/dw-hdma-v0-debugfs.c | 17 ++++++-----------
  drivers/dma/dw-edma/dw-hdma-v0-regs.h    | 10 ----------
  include/linux/dma/edma.h                 |  1 +
  5 files changed, 25 insertions(+), 30 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +3 -0
index 6295d01ba2f7..ca2a4be2f3a5 100644
@@ -113,6 +113,7 @@ static const struct dw_edma_pcie_data snps_edda_data = {
  	.irqs				= 1,
  	.wr_ch_cnt			= 2,
  	.rd_ch_cnt			= 2,
+	.ch_sep_sz			= 256,
  };
 
  static const struct dw_edma_pcie_data xilinx_mdb_data = {
@@ -126,6 +127,7 @@ static const struct dw_edma_pcie_data xilinx_mdb_data = {
  	.irqs				= 1,
  	.wr_ch_cnt			= 8,
  	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 256,
  };
 
  static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
@@ -139,6 +141,7 @@ static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
  	.irqs				= 1,
  	.wr_ch_cnt			= 8,
  	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 512,
  };
 
  static void dw_edma_set_chan_region_offset(struct dw_edma_pcie_data *pdata,

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_probe(struct pci_dev *pdev, · line 449

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -0
@@ -443,6 +446,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
  	chip->nr_irqs = nr_irqs;
  	chip->ops = &dw_edma_pcie_plat_ops;
  	chip->cfg_non_ll = non_ll;
+	chip->ch_sep_sz = vsec_data->ch_sep_sz;

This blocks PCI endpoint DMA, this driver is not only used by this. EPC controller will not set this value, so ch_sep_sz will be 0 for EPC controller.

Quoted 7 lines
Quoted 2 lines

Frank

The EPC driver is using the chip->reg_base + reg_offset for computing the final addresse and not using the register mappings. If the reg_offset are correct then this ch_sep_sz change will not affect the EPC driver.

show me, how work, both use below method to get channel register address

__dw_ch_regs () {
return dw->chip->reg_base + (ch_base * dw->chip->ch_sep_sz) }

Frank

Quoted 111 lines
Quoted 110 lines
Quoted 110 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0 -0
  	chip->ll_wr_cnt = vsec_data->wr_ch_cnt;
  	chip->ll_rd_cnt = vsec_data->rd_ch_cnt;
drivers/dma/dw-edma/dw-hdma-v0-core.c +14 -9
index 632abb8b481c..3f27a93c4d8c 100644
@@ -23,18 +23,23 @@ enum dw_hdma_control {
  	DW_HDMA_V0_LLE					= BIT(9),
  };
 
-static inline struct dw_hdma_v0_regs __iomem *__dw_regs(struct dw_edma *dw)
-{
-	return dw->chip->reg_base;
-}
-
  static inline struct dw_hdma_v0_ch_regs __iomem *
  __dw_ch_regs(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch)
  {
-	if (dir == EDMA_DIR_WRITE)
-		return &(__dw_regs(dw)->ch[ch].wr);
-	else
-		return &(__dw_regs(dw)->ch[ch].rd);
+	u32 ch_base;
+
+	/*
+	 * For Write, the channel register index starts at
+	 * wr_base(ch_idx) = (2 * ch_idx) * ch_sep_sz
+	 *
+	 * For Read channel,
+	 * rd_base(ch_idx) = (2 * ch_idx + 1) * ch_sep_sz
+	 */
+	ch_base = 2 * ch;
+	if (dir == EDMA_DIR_READ)
+		ch_base += 1;
+
+	return dw->chip->reg_base + (ch_base * dw->chip->ch_sep_sz);
  }
 
  #define SET_CH_32(dw, dir, ch, name, value) \
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +6 -11
index dcdc57fe976c..33128685bbd9 100644
@@ -13,22 +13,17 @@
  #include "dw-hdma-v0-regs.h"
  #include "dw-edma-core.h"
 
-#define REGS_ADDR(dw, name)						       \
-	({								       \
-		struct dw_hdma_v0_regs __iomem *__regs = (dw)->chip->reg_base; \
-									       \
-		(void __iomem *)&__regs->name;				       \
-	})
-
  #define REGS_CH_ADDR(dw, name, _dir, _ch)				       \
  	({								       \
-		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;		       \
+		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;                  \
+		off_t __off = (dw)->chip->ch_sep_sz;			       \
  									       \
-		if (_dir == EDMA_DIR_READ)				       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].rd);		       \
+		if ((_dir) == EDMA_DIR_READ)				       \
+			__off *= (2 * (_ch) + 1);			       \
  		else							       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].wr);		       \
+			__off *= (2 * (_ch));				       \
  									       \
+		__ch_regs = ((dw)->chip->reg_base + __off);		       \
  		(void __iomem *)&__ch_regs->name;			       \
  	})
 
drivers/dma/dw-edma/dw-hdma-v0-regs.h +0 -10
index 7759ba9b4850..2475b8d96133 100644
@@ -84,16 +84,6 @@ struct dw_hdma_v0_ch_regs {
  		};
  	} msi_abort;
  	u32 msi_msgdata;			/* 0x00a8 */
-	u32 padding_2[21];			/* 0x00ac..0x00fc */
-} __packed;
-
-struct dw_hdma_v0_ch {
-	struct dw_hdma_v0_ch_regs wr;		/* 0x0000 */
-	struct dw_hdma_v0_ch_regs rd;		/* 0x0100 */
-} __packed;
-
-struct dw_hdma_v0_regs {
-	struct dw_hdma_v0_ch ch[HDMA_V0_MAX_NR_CH];	/* 0x0000..0x0fa8 */
  } __packed;
 
  struct dw_hdma_v0_lli {
include/linux/dma/edma.h +1 -1
index 1fafd5b0e315..a6c5728f03d3 100644
@@ -104,6 +104,7 @@ struct dw_edma_chip {
 
  	struct dw_edma		*dw;
  	bool			cfg_non_ll;
+	u32			ch_sep_sz;
  };
 
  /* Export to the platform drivers */
--

2.43.0

#16 lore raw

Re: [PATCH v1 3/3] dmaengine: dw-edma: Add changes to support Channel Separation

Quoted 102 lines · Frank Li
Quoted 93 lines · Devendra
Quoted 4 lines · Frank Li

On Wed, Jul 22, 2026 at 04:46:40PM +0530, Devendra K Verma wrote:

Add Koichiro Den, who did many work with this edma driver recently

Sure, thanks!

Quoted 22 lines
Quoted 3 lines

Following changes are made:
o In 'struct dw_hdma_v0_ch_regs', it is assumed the channel separation as 256-bytes which is default, but if an IP is

channel register space size?

Quoted 7 lines

configured for a different size of channel separation then user can retrieve it using the supported VSEC (0x6). Modified the struct to work with the channel separation supported by IP.
CPM6 supports channel separation, default is 512.

Quoted 6 lines

o Changes in macros / functions where address of the channel is accessed based on channel index and direction. It enables the calculation of the channel reg base address based on the selected channel separation.
o Struct removed - dw_hdma_v0_ch, dw_hdma_v0_regs
o Functions removed - __dw_regs()

Can you summary change and purpose? such as

Quoted 9 lines

Support difference channel register space size for difference IP. Previous use fix default value 256, CMP6 support difference register space size, which default value is 512.

Update channel register base address caluator method by use ch_space_sze and remove unused dw_hdma_v0_ch, dw_hdma_v0_regs.

You can rephrase.

Sure, I will rephrase this. Thank you for the suggestion!

Quoted 49 lines
Quoted 39 lines
---
   drivers/dma/dw-edma/dw-edma-pcie.c       |  4 ++++
   drivers/dma/dw-edma/dw-hdma-v0-core.c    | 23 ++++++++++++++---------
   drivers/dma/dw-edma/dw-hdma-v0-debugfs.c | 17 ++++++-----------
   drivers/dma/dw-edma/dw-hdma-v0-regs.h    | 10 ----------
   include/linux/dma/edma.h                 |  1 +
   5 files changed, 25 insertions(+), 30 deletions(-)
drivers/dma/dw-edma/dw-edma-pcie.c +3 -0
index 6295d01ba2f7..ca2a4be2f3a5 100644
@@ -113,6 +113,7 @@ static const struct dw_edma_pcie_data snps_edda_data = {
   	.irqs				= 1,
   	.wr_ch_cnt			= 2,
   	.rd_ch_cnt			= 2,
+	.ch_sep_sz			= 256,
   };
 
   static const struct dw_edma_pcie_data xilinx_mdb_data = {
@@ -126,6 +127,7 @@ static const struct dw_edma_pcie_data xilinx_mdb_data = {
   	.irqs				= 1,
   	.wr_ch_cnt			= 8,
   	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 256,
   };
 
   static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
@@ -139,6 +141,7 @@ static const struct dw_edma_pcie_data xilinx_cpm6_dma_data = {
   	.irqs				= 1,
   	.wr_ch_cnt			= 8,
   	.rd_ch_cnt			= 8,
+	.ch_sep_sz			= 512,
   };
 
   static void dw_edma_set_chan_region_offset(struct dw_edma_pcie_data *pdata,

drivers/dma/dw-edma/dw-edma-pcie.c static int dw_edma_pcie_probe(struct pci_dev *pdev, · line 449

Quoted 4 lines
drivers/dma/dw-edma/dw-edma-pcie.c +1 -0
@@ -443,6 +446,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev,
   	chip->nr_irqs = nr_irqs;
   	chip->ops = &dw_edma_pcie_plat_ops;
   	chip->cfg_non_ll = non_ll;
+	chip->ch_sep_sz = vsec_data->ch_sep_sz;

This blocks PCI endpoint DMA, this driver is not only used by this. EPC controller will not set this value, so ch_sep_sz will be 0 for EPC controller.

Quoted 7 lines
Quoted 2 lines

Frank

The EPC driver is using the chip->reg_base + reg_offset for computing the final addresse and not using the register mappings. If the reg_offset are correct then this ch_sep_sz change will not affect the EPC driver.

Quoted 6 lines

show me, how work, both use below method to get channel register address

__dw_ch_regs () {
return dw->chip->reg_base + (ch_base * dw->chip->ch_sep_sz) }

Yes, the dw_edma_probe() gets called in the EPC driver, I had checked based on the dw_pcie->edma.reg_base. The ch_sep_sz is required. I have added the ch_sep_sz as part of dw_pcie_edma_init_data(). Thanks for the suggestion.

-Devendra

Quoted 113 lines

Frank

Quoted 111 lines
Quoted 110 lines
Quoted 110 lines
drivers/dma/dw-edma/dw-edma-pcie.c +0 -0
   	chip->ll_wr_cnt = vsec_data->wr_ch_cnt;
   	chip->ll_rd_cnt = vsec_data->rd_ch_cnt;
drivers/dma/dw-edma/dw-hdma-v0-core.c +14 -9
index 632abb8b481c..3f27a93c4d8c 100644
@@ -23,18 +23,23 @@ enum dw_hdma_control {
   	DW_HDMA_V0_LLE					= BIT(9),
   };
 
-static inline struct dw_hdma_v0_regs __iomem *__dw_regs(struct dw_edma *dw)
-{
-	return dw->chip->reg_base;
-}
-
   static inline struct dw_hdma_v0_ch_regs __iomem *
   __dw_ch_regs(struct dw_edma *dw, enum dw_edma_dir dir, u16 ch)
   {
-	if (dir == EDMA_DIR_WRITE)
-		return &(__dw_regs(dw)->ch[ch].wr);
-	else
-		return &(__dw_regs(dw)->ch[ch].rd);
+	u32 ch_base;
+
+	/*
+	 * For Write, the channel register index starts at
+	 * wr_base(ch_idx) = (2 * ch_idx) * ch_sep_sz
+	 *
+	 * For Read channel,
+	 * rd_base(ch_idx) = (2 * ch_idx + 1) * ch_sep_sz
+	 */
+	ch_base = 2 * ch;
+	if (dir == EDMA_DIR_READ)
+		ch_base += 1;
+
+	return dw->chip->reg_base + (ch_base * dw->chip->ch_sep_sz);
   }
 
   #define SET_CH_32(dw, dir, ch, name, value) \
drivers/dma/dw-edma/dw-hdma-v0-debugfs.c +6 -11
index dcdc57fe976c..33128685bbd9 100644
@@ -13,22 +13,17 @@
   #include "dw-hdma-v0-regs.h"
   #include "dw-edma-core.h"
 
-#define REGS_ADDR(dw, name)						       \
-	({								       \
-		struct dw_hdma_v0_regs __iomem *__regs = (dw)->chip->reg_base; \
-									       \
-		(void __iomem *)&__regs->name;				       \
-	})
-
   #define REGS_CH_ADDR(dw, name, _dir, _ch)				       \
   	({								       \
-		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;		       \
+		struct dw_hdma_v0_ch_regs __iomem *__ch_regs;                  \
+		off_t __off = (dw)->chip->ch_sep_sz;			       \
   									       \
-		if (_dir == EDMA_DIR_READ)				       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].rd);		       \
+		if ((_dir) == EDMA_DIR_READ)				       \
+			__off *= (2 * (_ch) + 1);			       \
   		else							       \
-			__ch_regs = REGS_ADDR(dw, ch[_ch].wr);		       \
+			__off *= (2 * (_ch));				       \
   									       \
+		__ch_regs = ((dw)->chip->reg_base + __off);		       \
   		(void __iomem *)&__ch_regs->name;			       \
   	})
 
drivers/dma/dw-edma/dw-hdma-v0-regs.h +0 -10
index 7759ba9b4850..2475b8d96133 100644
@@ -84,16 +84,6 @@ struct dw_hdma_v0_ch_regs {
   		};
   	} msi_abort;
   	u32 msi_msgdata;			/* 0x00a8 */
-	u32 padding_2[21];			/* 0x00ac..0x00fc */
-} __packed;
-
-struct dw_hdma_v0_ch {
-	struct dw_hdma_v0_ch_regs wr;		/* 0x0000 */
-	struct dw_hdma_v0_ch_regs rd;		/* 0x0100 */
-} __packed;
-
-struct dw_hdma_v0_regs {
-	struct dw_hdma_v0_ch ch[HDMA_V0_MAX_NR_CH];	/* 0x0000..0x0fa8 */
   } __packed;
 
   struct dw_hdma_v0_lli {
include/linux/dma/edma.h +1 -1
index 1fafd5b0e315..a6c5728f03d3 100644
@@ -104,6 +104,7 @@ struct dw_edma_chip {
 
   	struct dw_edma		*dw;
   	bool			cfg_non_ll;
+	u32			ch_sep_sz;
   };
 
   /* Export to the platform drivers */
--

2.43.0