Skip to contentSkip to conversation

dmaengine: dw: Select only supported masters for ACPI devices

PATCH Superseded Serge Semin 3 participants 7 messages Sep 19, 2024 – Sep 20, 2024

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

PATCH 1/1 dmaengine: dw: Select only supported masters for ACPI devices

The recently submitted fix-commit revealed a problem in the iDMA32 platform code. Even though the controller supported only a single master the dw_dma_acpi_filter() method hard-coded two master interfaces with IDs 0 and 1. As a result the sanity check implemented in the commit b336268dde75 ("dmaengine: dw: Add peripheral bus width verification") got incorrect interface data width and thus prevented the client drivers from configuring the DMA-channel with the EINVAL error returned. E.g. the next error was printed for the PXA2xx SPI controller driver trying to configure the requested channels:

Quoted 3 lines
[  164.525604] pxa2xx_spi_pci 0000:00:07.1: DMA slave config failed
[  164.536105] pxa2xx_spi_pci 0000:00:07.1: failed to get DMA TX descriptor
[  164.543213] spidev spi-SPT0001:00: SPI transfer failed: -16

The problem would have been spotted much earlier if the iDMA32 controller supported more than one master interfaces. But since it supports just a single master and the iDMA32-specific code just ignores the master IDs in the CTLLO preparation method, the issue has been gone unnoticed so far.

Fix the problem by specifying a single master ID for both memory and peripheral devices on the ACPI-based platforms if there is only one master available on the controller. Thus the issue noticed for the iDMA32 controllers will be eliminated and the ACPI-probed DW DMA controllers will be configured with the correct master ID by default.

Fixes b336268dde75 ("dmaengine: dw: Add peripheral bus width verification")
Fixes 199244d69458 ("dmaengine: dw: add support of iDMA 32-bit hardware")

---

Note I haven't got any device with the Intel Merrifield iDMA32 + SPI PXA2xx pair to test out the solution. So any tests are very welcome. But based on Andy' (see the reported-by links) and my investigations the fix seems correct.

---
 drivers/dma/dw/acpi.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/dma/dw/acpi.c +11 -1
index c510c109d2c3..efbe8baeccbc 100644
@@ -8,15 +8,25 @@
 
 static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param)
 {
+	struct dw_dma *dw = to_dw_dma(chan->device);
 	struct acpi_dma_spec *dma_spec = param;
 	struct dw_dma_slave slave = {
 		.dma_dev = dma_spec->dev,
 		.src_id = dma_spec->slave_id,
 		.dst_id = dma_spec->slave_id,
 		.m_master = 0,
-		.p_master = 1,
 	};
 
+	/*
+	 * Fallback to using a single interface for both memory and peripheral
+	 * device if there is only one master I/F supported (e.g. iDMA32)
+	 */
+	if (dw->pdata->nr_masters == 0)
+		slave.p_master = 0;
+	else
+		slave.p_master = 1;
+
+
 	return dw_dma_filter(chan, &slave);
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 24 lines · Serge Semin

The recently submitted fix-commit revealed a problem in the iDMA32 platform code. Even though the controller supported only a single master the dw_dma_acpi_filter() method hard-coded two master interfaces with IDs 0 and 1. As a result the sanity check implemented in the commit b336268dde75 ("dmaengine: dw: Add peripheral bus width verification") got incorrect interface data width and thus prevented the client drivers from configuring the DMA-channel with the EINVAL error returned. E.g. the next error was printed for the PXA2xx SPI controller driver trying to configure the requested channels:

Quoted 3 lines
[  164.525604] pxa2xx_spi_pci 0000:00:07.1: DMA slave config failed
[  164.536105] pxa2xx_spi_pci 0000:00:07.1: failed to get DMA TX descriptor
[  164.543213] spidev spi-SPT0001:00: SPI transfer failed: -16

The problem would have been spotted much earlier if the iDMA32 controller supported more than one master interfaces. But since it supports just a single master and the iDMA32-specific code just ignores the master IDs in the CTLLO preparation method, the issue has been gone unnoticed so far.

Fix the problem by specifying a single master ID for both memory and peripheral devices on the ACPI-based platforms if there is only one master available on the controller. Thus the issue noticed for the iDMA32 controllers will be eliminated and the ACPI-probed DW DMA controllers will be configured with the correct master ID by default.

...

drivers/dma/dw/acpi.c line 17

Quoted 10 lines

static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param) {

drivers/dma/dw/acpi.c +1 -1
+	struct dw_dma *dw = to_dw_dma(chan->device);
 	struct acpi_dma_spec *dma_spec = param;
 	struct dw_dma_slave slave = {
 		.dma_dev = dma_spec->dev,
 		.src_id = dma_spec->slave_id,
 		.dst_id = dma_spec->slave_id,
 		.m_master = 0,
-		.p_master = 1,

I would leave this line as is and it makes more consistent in my opinion with the below comments which starts with the words "Fallback to...".

drivers/dma/dw/acpi.c line 24

Quoted 7 lines
drivers/dma/dw/acpi.c +5 -0
 	};
 
+	/*
+	 * Fallback to using a single interface for both memory and peripheral
+	 * device if there is only one master I/F supported (e.g. iDMA32)
+	 */
+	if (dw->pdata->nr_masters == 0)

Why '== 0' and not '== 1'? Or '>= 2' if you wish to be on the save side (however, that '== 0' case is not obvious to me — do we really have that IRL?).

drivers/dma/dw/acpi.c

Quoted 6 lines
drivers/dma/dw/acpi.c +5 -0
+		slave.p_master = 0;
+	else
+		slave.p_master = 1;
 
+
+

One blank line is enough.

Quoted 2 lines

return dw_dma_filter(chan, &slave);
}

...

P.S. I'll test it later this or next week, if Ferry wouldn't beat me up to it.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 28 lines · Andy Shevchenko
Quoted 24 lines · Serge Semin

The recently submitted fix-commit revealed a problem in the iDMA32 platform code. Even though the controller supported only a single master the dw_dma_acpi_filter() method hard-coded two master interfaces with IDs 0 and 1. As a result the sanity check implemented in the commit b336268dde75 ("dmaengine: dw: Add peripheral bus width verification") got incorrect interface data width and thus prevented the client drivers from configuring the DMA-channel with the EINVAL error returned. E.g. the next error was printed for the PXA2xx SPI controller driver trying to configure the requested channels:

Quoted 3 lines
[  164.525604] pxa2xx_spi_pci 0000:00:07.1: DMA slave config failed
[  164.536105] pxa2xx_spi_pci 0000:00:07.1: failed to get DMA TX descriptor
[  164.543213] spidev spi-SPT0001:00: SPI transfer failed: -16

The problem would have been spotted much earlier if the iDMA32 controller supported more than one master interfaces. But since it supports just a single master and the iDMA32-specific code just ignores the master IDs in the CTLLO preparation method, the issue has been gone unnoticed so far.

Fix the problem by specifying a single master ID for both memory and peripheral devices on the ACPI-based platforms if there is only one master available on the controller. Thus the issue noticed for the iDMA32 controllers will be eliminated and the ACPI-probed DW DMA controllers will be configured with the correct master ID by default.

...

Quoted 14 lines

drivers/dma/dw/acpi.c line 17

Quoted 10 lines

static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param) {

drivers/dma/dw/acpi.c +1 -1
+	struct dw_dma *dw = to_dw_dma(chan->device);
 	struct acpi_dma_spec *dma_spec = param;
 	struct dw_dma_slave slave = {
 		.dma_dev = dma_spec->dev,
 		.src_id = dma_spec->slave_id,
 		.dst_id = dma_spec->slave_id,
 		.m_master = 0,
-		.p_master = 1,

I would leave this line as is and it makes more consistent in my opinion with the below comments which starts with the words "Fallback to...".

Ok.

Quoted 12 lines

drivers/dma/dw/acpi.c line 24

Quoted 8 lines
drivers/dma/dw/acpi.c +5 -0
 	};
 
+	/*
+	 * Fallback to using a single interface for both memory and peripheral
+	 * device if there is only one master I/F supported (e.g. iDMA32)
+	 */
+	if (dw->pdata->nr_masters == 0)

Why '== 0' and not '== 1'? Or '>= 2' if you wish to be on the save side (however, that '== 0' case is not obvious to me — do we really have that IRL?).

I several times checked the patch and never noticed this obvious typo. Indeed nr_masters is the actual number of masters. So the statement should have been '== 1'.

Quoted 10 lines

drivers/dma/dw/acpi.c

Quoted 7 lines
drivers/dma/dw/acpi.c +5 -0
+		slave.p_master = 0;
+	else
+		slave.p_master = 1;
 
+
+

One blank line is enough.

Fully agreed.

I guess I was too hurrying to submit the fix so missed two stupid mistakes in just 7-lines patch. "Nice" anti-record for me. Sorry about that and much appreciated for reviewing the bit. I'll resubmit v2 shortly.

-Serge(y)

Quoted 13 lines
Quoted 3 lines

return dw_dma_filter(chan, &slave);
}

...

P.S. I'll test it later this or next week, if Ferry wouldn't beat me up to it.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

PATCH v2 1/1 dmaengine: dw: Select only supported masters for ACPI devices

In reply to Serge Semin

The recently submitted fix-commit revealed a problem in the iDMA32 platform code. Even though the controller supported only a single master the dw_dma_acpi_filter() method hard-coded two master interfaces with IDs 0 and 1. As a result the sanity check implemented in the commit b336268dde75 ("dmaengine: dw: Add peripheral bus width verification") got incorrect interface data width and thus prevented the client drivers from configuring the DMA-channel with the EINVAL error returned. E.g. the next error was printed for the PXA2xx SPI controller driver trying to configure the requested channels:

Quoted 3 lines
[  164.525604] pxa2xx_spi_pci 0000:00:07.1: DMA slave config failed
[  164.536105] pxa2xx_spi_pci 0000:00:07.1: failed to get DMA TX descriptor
[  164.543213] spidev spi-SPT0001:00: SPI transfer failed: -16

The problem would have been spotted much earlier if the iDMA32 controller supported more than one master interfaces. But since it supports just a single master and the iDMA32-specific code just ignores the master IDs in the CTLLO preparation method, the issue has been gone unnoticed so far.

Fix the problem by specifying a single master ID for both memory and peripheral devices on the ACPI-based platforms if there is only one master available on the controller. Thus the issue noticed for the iDMA32 controllers will be eliminated and the ACPI-probed DW DMA controllers will be configured with the correct master ID by default.

Fixes b336268dde75 ("dmaengine: dw: Add peripheral bus width verification")
Fixes 199244d69458 ("dmaengine: dw: add support of iDMA 32-bit hardware")

---

Note I haven't got any device with the Intel Merrifield iDMA32 + SPI PXA2xx pair to test out the solution. So any tests are very welcome. But based on Andy' (see the reported-by links) and my investigations the fix seems correct.

Changelog v2:
- Implement only the "fallback" conditional statement (@Andy)
- Fix incorrect NoF masters literal (@Andy)
- Drop redundant empty line (@Andy)

---
 drivers/dma/dw/acpi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/dma/dw/acpi.c +8 -0
index c510c109d2c3..806620f5a406 100644
@@ -8,6 +8,7 @@
 
 static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param)
 {
+	struct dw_dma *dw = to_dw_dma(chan->device);
 	struct acpi_dma_spec *dma_spec = param;
 	struct dw_dma_slave slave = {
 		.dma_dev = dma_spec->dev,
@@ -17,6 +18,13 @@ static bool dw_dma_acpi_filter(struct dma_chan *chan, void *param)
 		.p_master = 1,
 	};
 
+	/*
+	 * Fallback to using a single interface for both memory and peripheral
+	 * device if there is only one master I/F supported (e.g. iDMA32)
+	 */
+	if (dw->pdata->nr_masters == 1)
+		slave.p_master = 0;
+
 	return dw_dma_filter(chan, &slave);
 }
 
Signature · 1 line
2.43.0
reviewer Tested-by on v2 1/1
#4 lore raw
Quoted 19 lines · Serge Semin

The recently submitted fix-commit revealed a problem in the iDMA32 platform code. Even though the controller supported only a single master the dw_dma_acpi_filter() method hard-coded two master interfaces with IDs 0 and 1. As a result the sanity check implemented in the commit b336268dde75 ("dmaengine: dw: Add peripheral bus width verification") got incorrect interface data width and thus prevented the client drivers from configuring the DMA-channel with the EINVAL error returned. E.g. the next error was printed for the PXA2xx SPI controller driver trying to configure the requested channels:

Quoted 3 lines
[  164.525604] pxa2xx_spi_pci 0000:00:07.1: DMA slave config failed
[  164.536105] pxa2xx_spi_pci 0000:00:07.1: failed to get DMA TX descriptor
[  164.543213] spidev spi-SPT0001:00: SPI transfer failed: -16

The problem would have been spotted much earlier if the iDMA32 controller supported more than one master interfaces. But since it supports just a single master and the iDMA32-specific code just ignores the master IDs in the CTLLO preparation method, the issue has been gone unnoticed so far.

Quoted 5 lines

Fix the problem by specifying a single master ID for both memory and peripheral devices on the ACPI-based platforms if there is only one master available on the controller. Thus the issue noticed for the iDMA32 controllers will be eliminated and the ACPI-probed DW DMA controllers will be configured with the correct master ID by default.

Seems this fixes the bug I have seen.
Ferry, can you confirm?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Hi,

Op donderdag 19 september 2024 22:06:24 CEST schreef Andy Shevchenko:

Quoted 26 lines · Serge Semin
Quoted 19 lines

The recently submitted fix-commit revealed a problem in the iDMA32 platform code. Even though the controller supported only a single master the dw_dma_acpi_filter() method hard-coded two master interfaces with IDs 0 and 1. As a result the sanity check implemented in the commit b336268dde75 ("dmaengine: dw: Add peripheral bus width verification") got incorrect interface data width and thus prevented the client drivers from configuring the DMA-channel with the EINVAL error returned. E.g. the next error was printed for the PXA2xx SPI controller driver trying to configure the requested channels:

Quoted 3 lines
[  164.525604] pxa2xx_spi_pci 0000:00:07.1: DMA slave config failed
[  164.536105] pxa2xx_spi_pci 0000:00:07.1: failed to get DMA TX descriptor
[  164.543213] spidev spi-SPT0001:00: SPI transfer failed: -16

The problem would have been spotted much earlier if the iDMA32 controller supported more than one master interfaces. But since it supports just a single master and the iDMA32-specific code just ignores the master IDs in the CTLLO preparation method, the issue has been gone unnoticed so far.

Quoted 5 lines

Fix the problem by specifying a single master ID for both memory and peripheral devices on the ACPI-based platforms if there is only one master available on the controller. Thus the issue noticed for the iDMA32 controllers will be eliminated and the ACPI-probed DW DMA controllers will be configured with the correct master ID by default.

Quoted 3 lines

Seems this fixes the bug I have seen.
Ferry, can you confirm?

I was testing something else and broke my setup :-( I’ll fix that and test this patch this weekend.

#6 lore raw
Quoted 2 lines · Ferry Toth

Op donderdag 19 september 2024 22:06:24 CEST schreef Andy Shevchenko:

Quoted 1 line · Serge Semin

...

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines

Fix the problem by specifying a single master ID for both memory and peripheral devices on the ACPI-based platforms if there is only one master available on the controller. Thus the issue noticed for the iDMA32 controllers will be eliminated and the ACPI-probed DW DMA controllers will be configured with the correct master ID by default.

Seems this fixes the bug I have seen.
Ferry, can you confirm?

I was testing something else and broke my setup :-( I’ll fix that and test this patch this weekend.

Thinking about this more I believe it's not the best what we can do. Because this leaves a potential gap for the devices of more than one master but in different order.

I'll send another patch after my testing.

Signature · 2 lines
With Best Regards,
Andy Shevchenko