mmc: mmc_spi: Allow the driver to be built when CONFIG_HAS_DMA is unset
Subsystems (3)
PATCH v2 1/1 mmc: mmc_spi: Allow the driver to be built when CONFIG_HAS_DMA is unset
The commit cd57d07b1e4e ("sh: don't allow non-coherent DMA for NOMMU") made CONFIG_NO_DMA to be set for some platforms, for good reasons. Consequentially, CONFIG_HAS_DMA doesn't get set, which makes the DMA mapping interface to be built as stub functions, but also prevent the mmc_spi driver from being built as it depends on CONFIG_HAS_DMA.
It turns out that for some odd cases, the driver still relied on the DMA mapping interface, even if the DMA was not actively being used.
To fixup the behaviour, let's drop the build dependency for CONFIG_HAS_DMA. Moreover, as to allow the driver to succeed probing, let's move the DMA initializations behind "#ifdef CONFIG_HAS_DMA".
---
Changes in v2:
- Drop build dependency to CONFIG_HAS_DMA.
- Rephrase commit message and its header, to reflect the updated change.
--- drivers/mmc/host/Kconfig | 2 +- drivers/mmc/host/mmc_spi.c | 86 +++++++++++++++++++++++--------------- 2 files changed, 53 insertions(+), 35 deletions(-)
drivers/mmc/host/Kconfig +1 -1
@@ -602,7 +602,7 @@ config MMC_GOLDFISH config MMC_SPI tristate "MMC/SD/SDIO over SPI" - depends on SPI_MASTER && HAS_DMA + depends on SPI_MASTER select CRC7 select CRC_ITU_T help
drivers/mmc/host/mmc_spi.c +52 -34
114 lines not on this page · raw message
Signature · 1 line
2.25.1
drivers/mmc/host/mmc_spi.c mmc_spi_detect_irq(int irq, void *mmc) · line 1288
Quoted 8 lines · Ulf Hansson
drivers/mmc/host/mmc_spi.c +8
-0+#ifdef CONFIG_HAS_DMA +static int mmc_spi_dma_alloc (struct mmc_spi_host *host) +{ +struct spi_device *spi = host->spi; +struct device *dev; + +if (!spi->master->dev.parent->dma_mask) +return 0 ;
I still don't think this makes sense, as the dma_mask should always be non-NULL here.
Quoted 13 lines · Christoph Hellwig
drivers/mmc/host/mmc_spi.c mmc_spi_detect_irq(int irq, void *mmc) · line 1288
Quoted 8 lines · Ulf Hansson
drivers/mmc/host/mmc_spi.c +8
-0+#ifdef CONFIG_HAS_DMA +static int mmc_spi_dma_alloc (struct mmc_spi_host *host) +{ +struct spi_device *spi = host->spi; +struct device *dev; + +if (!spi->master->dev.parent->dma_mask) +return 0 ;I still don't think this makes sense, as the
dma_maskshould always be non-NULL here.
If that is the case, I wonder how the driver could even have worked without DMA.
Because in the existing code, host->dma_dev gets assigned to spi->master->dev.parent->dma_mask - which seems to turn on the DMA usage in the driver.
What am I missing?
Kind regards
Uffe
Quoted 10 lines · Ulf Hansson
Quoted 2 lines
I still don't think this makes sense, as the
dma_maskshould always be non-NULL here.If that is the case, I wonder how the driver could even have worked without DMA.
Because in the existing code,
host->dma_devgets assigned tospi->master->dev.parent->dma_mask- which seems to turn on the DMA usage in the driver.What am I missing?
Do you know of other non-DMA users? For SH nommu it probably worked because SH nommu used to provide a DMA implementation that worked fine for streaming maps, but was completely broken for coherent allocation. And this driver appears to only use the former.
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Ulf Hansson
Quoted 2 lines
I still don't think this makes sense, as the
dma_maskshould always be non-NULL here.If that is the case, I wonder how the driver could even have worked without DMA.
Quoted 7 lines
Quoted 5 lines
Because in the existing code,
host->dma_devgets assigned tospi->master->dev.parent->dma_mask- which seems to turn on the DMA usage in the driver.What am I missing?
Do you know of other non-DMA users? For SH nommu it probably worked
I don't know of other non-DMA users. As I said, I wish someone could step in and take better care of mmc_spi - as I know it's being used a lot.
Quoted 3 lines
because SH nommu used to provide a DMA implementation that worked fine for streaming maps, but was completely broken for coherent allocation. And this driver appears to only use the former.
Alright, so you are saying the DMA support may potentially never have been optional to this driver. In any case, I can remove the check in $subject patch, as it shouldn't matter.
Anyway, let's see what Rich thinks of this. I am curious to see if the patch works on his SH boards - as I haven't been able to test it.
Kind regards
Uffe
Rich Felker
maintainerQuoted 20 lines · Ulf Hansson
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Ulf Hansson
Quoted 2 lines
I still don't think this makes sense, as the
dma_maskshould always be non-NULL here.If that is the case, I wonder how the driver could even have worked without DMA.
Quoted 7 lines
Quoted 5 lines
Because in the existing code,
host->dma_devgets assigned tospi->master->dev.parent->dma_mask- which seems to turn on the DMA usage in the driver.What am I missing?
Do you know of other non-DMA users? For SH nommu it probably worked
I don't know of other non-DMA users. As I said, I wish someone could step in and take better care of
mmc_spi- as I know it's being used a lot.
Quoted 7 lines
Quoted 3 lines
because SH nommu used to provide a DMA implementation that worked fine for streaming maps, but was completely broken for coherent allocation. And this driver appears to only use the former.
Alright, so you are saying the DMA support may potentially never have been optional to this driver. In any case, I can remove the check in $subject patch, as it shouldn't matter.
DMA support was always optional, because even on systems where DMA is present, it doesn't necessarily mean the SPI controller uses DMA. In particular, pure bit-banged SPI via GPIOs doesn't have DMA, but has always worked. See my previous reply to Christoph about host->dma_dev for my current-best understanding of what's going on here.
Quoted 2 lines
Anyway, let's see what Rich thinks of this. I am curious to see if the patch works on his SH boards - as I haven't been able to test it.
I'll rebuild and retest just to confirm, but I already tested a functionally equivalent patch that just did the #ifdef inline (rather than moving the logic out to separate functions) and it worked fine.
Rich
Hi Rich,
Quoted 34 lines · Rich Felker
Quoted 19 lines · Ulf Hansson
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Ulf Hansson
Quoted 2 lines
I still don't think this makes sense, as the
dma_maskshould always be non-NULL here.If that is the case, I wonder how the driver could even have worked without DMA.
Quoted 7 lines
Quoted 5 lines
Because in the existing code,
host->dma_devgets assigned tospi->master->dev.parent->dma_mask- which seems to turn on the DMA usage in the driver.What am I missing?
Do you know of other non-DMA users? For SH nommu it probably worked
I don't know of other non-DMA users. As I said, I wish someone could step in and take better care of
mmc_spi- as I know it's being used a lot.Quoted 7 lines
Quoted 3 lines
because SH nommu used to provide a DMA implementation that worked fine for streaming maps, but was completely broken for coherent allocation. And this driver appears to only use the former.
Alright, so you are saying the DMA support may potentially never have been optional to this driver. In any case, I can remove the check in $subject patch, as it shouldn't matter.
DMA support was always optional, because even on systems where DMA is present, it doesn't necessarily mean the SPI controller uses DMA. In particular, pure bit-banged SPI via GPIOs doesn't have DMA, but has always worked. See my previous reply to Christoph about
host->dma_devfor my current-best understanding of what's going on here.
Quoted 6 lines
Quoted 2 lines
Anyway, let's see what Rich thinks of this. I am curious to see if the patch works on his SH boards - as I haven't been able to test it.
I'll rebuild and retest just to confirm, but I already tested a functionally equivalent patch that just did the #ifdef inline (rather than moving the logic out to separate functions) and it worked fine.
Hence, Tested-by? ;-)
Thanks!
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 37 lines · Geert Uytterhoeven
Hi Rich,
Quoted 34 lines · Rich Felker
Quoted 19 lines · Ulf Hansson
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Ulf Hansson
Quoted 2 lines
I still don't think this makes sense, as the
dma_maskshould always be non-NULL here.If that is the case, I wonder how the driver could even have worked without DMA.
Quoted 7 lines
Quoted 5 lines
Because in the existing code,
host->dma_devgets assigned tospi->master->dev.parent->dma_mask- which seems to turn on the DMA usage in the driver.What am I missing?
Do you know of other non-DMA users? For SH nommu it probably worked
I don't know of other non-DMA users. As I said, I wish someone could step in and take better care of
mmc_spi- as I know it's being used a lot.Quoted 7 lines
Quoted 3 lines
because SH nommu used to provide a DMA implementation that worked fine for streaming maps, but was completely broken for coherent allocation. And this driver appears to only use the former.
Alright, so you are saying the DMA support may potentially never have been optional to this driver. In any case, I can remove the check in $subject patch, as it shouldn't matter.
DMA support was always optional, because even on systems where DMA is present, it doesn't necessarily mean the SPI controller uses DMA. In particular, pure bit-banged SPI via GPIOs doesn't have DMA, but has always worked. See my previous reply to Christoph about
host->dma_devfor my current-best understanding of what's going on here.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Anyway, let's see what Rich thinks of this. I am curious to see if the patch works on his SH boards - as I haven't been able to test it.
I'll rebuild and retest just to confirm, but I already tested a functionally equivalent patch that just did the #ifdef inline (rather than moving the logic out to separate functions) and it worked fine.
Hence, Tested-by? ;-)
Confirmed that this version of the patch works too. Thus,
Quoted 46 lines · Rich Felker
Quoted 44 lines · Geert Uytterhoeven
Hi Rich,
Quoted 40 lines · Rich Felker
Quoted 19 lines · Ulf Hansson
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Ulf Hansson
Quoted 2 lines
I still don't think this makes sense, as the
dma_maskshould always be non-NULL here.If that is the case, I wonder how the driver could even have worked without DMA.
Quoted 7 lines
Quoted 5 lines
Because in the existing code,
host->dma_devgets assigned tospi->master->dev.parent->dma_mask- which seems to turn on the DMA usage in the driver.What am I missing?
Do you know of other non-DMA users? For SH nommu it probably worked
I don't know of other non-DMA users. As I said, I wish someone could step in and take better care of
mmc_spi- as I know it's being used a lot.Quoted 7 lines
Quoted 3 lines
because SH nommu used to provide a DMA implementation that worked fine for streaming maps, but was completely broken for coherent allocation. And this driver appears to only use the former.
Alright, so you are saying the DMA support may potentially never have been optional to this driver. In any case, I can remove the check in $subject patch, as it shouldn't matter.
DMA support was always optional, because even on systems where DMA is present, it doesn't necessarily mean the SPI controller uses DMA. In particular, pure bit-banged SPI via GPIOs doesn't have DMA, but has always worked. See my previous reply to Christoph about
host->dma_devfor my current-best understanding of what's going on here.Quoted 2 lines
Anyway, let's see what Rich thinks of this. I am curious to see if the patch works on his SH boards - as I haven't been able to test it.
I'll rebuild and retest just to confirm, but I already tested a functionally equivalent patch that just did the #ifdef inline (rather than moving the logic out to separate functions) and it worked fine.
Quoted 5 lines
Quoted 1 line
Hence, Tested-by? ;-)
Confirmed that this version of the patch works too. Thus,
Tested-by Rich Felker <[email protected]>
I have applied the patch for fixes, thanks for testing!
Christoph, when it comes to the check of "spi->master->dev.parent->dma_mask", I am keeping it for now. I am simply not sure that all spi masters assign the pointer (even if most are platform drivers). I think it's better that we remove that check in a separate patch - to get it tested.
Kind regards
Uffe
Rich Felker
maintainerQuoted 10 lines · Christoph Hellwig
Quoted 9 lines · Ulf Hansson
Quoted 2 lines
I still don't think this makes sense, as the
dma_maskshould always be non-NULL here.If that is the case, I wonder how the driver could even have worked without DMA.
Because in the existing code,
host->dma_devgets assigned tospi->master->dev.parent->dma_mask- which seems to turn on the DMA usage in the driver.
Quoted 6 lines
Quoted 1 line
What am I missing?
Do you know of other non-DMA users? For SH nommu it probably worked because SH nommu used to provide a DMA implementation that worked fine for streaming maps, but was completely broken for coherent allocation. And this driver appears to only use the former.
On the system we're using it on, there's no DMA whatsoever. It just used to allow memory allocations suitable for DMA (which any allocation vacuuously is when there's no DMA) but now it doesn't, due to your change.
Just below the if block in question in this thread is:
host->readback.is_dma_mapped = (host->dma_dev != NULL);
and similar conditions appear elsewhere all over the file in the form of if (host->dma_dev). Of course doing DMA requires a link to a DMA controller device, and plenty SPI devices (most obviously bit-banged ones) lack DMA.
The right condition for the block in question here is probably just checking dma_dev instead of dma_mask or CONFIG_HAS_DMA, but it seems useful to optimize out the code if CONFIG_HAS_DMA is false, anyway.
Rich