mmc: bcm2835: DMA mapping improvements
Subsystems (3)
PATCH 1/1 mmc: bcm2835: DMA mapping improvements
As pointed out by sashiko bot in [0], recent proposed changes to dma_max_mapping_size() may affect the driver.
While the issue reported may be a false positive, Robin pointed out some other DMA-related issues in the driver which are addressed here:
- the DMA max mapping size is irrelevant for the programmed IO mode of operation
- we should not call dma_max_mapping_size() on the MMC host platform device, but rather the DMA engine device
In addition, it's better to use the device returned from dmaengine_get_dma_device() for dma_umap_sg() and dma_unmap_sg(), and not reference the DMA channel device directly.
[0] https://lore.kernel.org/linux-scsi/[email protected]/#t
---
Compile tested only. And I doubt that this change needs to be merged prior to [0], above.
drivers/mmc/host/bcm2835.c +16 -14
@@ -188,7 +188,7 @@ struct bcm2835_host {u32 drain_words;struct page *drain_page;u32 drain_offset; -bool use_dma; +struct device *dma_dev; }; static void bcm2835_dumpcmd(struct bcm2835_host *host, struct mmc_command *cmd,
@@ -494,8 +494,7 @@ void bcm2835_prepare_dma(struct bcm2835_host *host, struct mmc_data *data) &host->dma_cfg_rx : &host->dma_cfg_tx); - sg_len =dma_map_sg (dma_chan->device->dev, data->sg, data->sg_len, - dir_data); + sg_len =dma_map_sg (host->dma_dev, data->sg, data->sg_len, dir_data);if (!sg_len)return ;
@@ -503,8 +502,7 @@ void bcm2835_prepare_dma(struct bcm2835_host *host, struct mmc_data *data) DMA_PREP_INTERRUPT | DMA_CTRL_ACK);if (!desc) { -dma_unmap_sg (dma_chan->device->dev, data->sg, data->sg_len, - dir_data); +dma_unmap_sg (host->dma_dev, data->sg, data->sg_len, dir_data);return ; }
@@ -1201,7 +1199,7 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)return ; } -if (host->use_dma && mrq->data && (mrq->data->blocks >PIO_THRESHOLD )) +if (host->dma_dev && mrq->data && (mrq->data->blocks >PIO_THRESHOLD ))bcm2835_prepare_dma (host, mrq->data); host->use_sbc = !!mrq->sbc && host->mrq->data &&
@@ -1281,10 +1279,8 @@ static int bcm2835_add_host(struct bcm2835_host *host)if (!host->dma_chan_rxtx) {dev_warn (dev,"unable to initialise DMA channel. Falling back to PIO\n" ); - host->use_dma = false; + host->dma_dev =NULL ; }else { - host->use_dma = true; - host->dma_cfg_tx.src_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ; host->dma_cfg_tx.dst_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ; host->dma_cfg_tx.direction =DMA_MEM_TO_DEV ;
@@ -1300,12 +1296,18 @@ static int bcm2835_add_host(struct bcm2835_host *host)if (dmaengine_slave_config (host->dma_chan_rxtx, &host->dma_cfg_tx) !=0 ||dmaengine_slave_config (host->dma_chan_rxtx, - &host->dma_cfg_rx) !=0 ) - host->use_dma = false; + &host->dma_cfg_rx) !=0 ) { + host->dma_dev = +dmaengine_get_dma_device (host->dma_chan_rxtx); + } } mmc->max_segs =128 ; - mmc->max_req_size =min_t (size_t,524288 ,dma_max_mapping_size (dev)); + mmc->max_req_size =524288 ; +if (host->dma_dev) { + mmc->max_req_size =min_t (size_t, mmc->max_req_size, +dma_max_mapping_size (host->dma_dev)); + } mmc->max_seg_size = mmc->max_req_size; mmc->max_blk_size =1024 ; mmc->max_blk_count =65535 ;
@@ -1336,10 +1338,10 @@ static int bcm2835_add_host(struct bcm2835_host *host) } pio_limit_string[0 ] ='\0' ; -if (host->use_dma && (PIO_THRESHOLD >0 )) +if (host->dma_dev && (PIO_THRESHOLD >0 ))sprintf (pio_limit_string," (>%d)" ,PIO_THRESHOLD );dev_info (dev,"loaded - DMA %s%s\n" , - host->use_dma ?"enabled" :"disabled" , pio_limit_string); + host->dma_dev ?"enabled" :"disabled" , pio_limit_string);return 0 ; }
Signature · 1 line
2.43.7
Quoted 11 lines · John Garry
As pointed out by sashiko bot in [0], recent proposed changes to
dma_max_mapping_size()may affect the driver.While the issue reported may be a false positive, Robin pointed out some other DMA-related issues in the driver which are addressed here:
- the DMA max mapping size is irrelevant for the programmed IO mode of operation
- we should not calldma_max_mapping_size()on the MMC host platform device, but rather the DMA engine device
Quoted 7 lines
In addition, it's better to use the device returned from
dmaengine_get_dma_device()fordma_umap_sg()anddma_unmap_sg(), and not reference the DMA channel device directly.[0] https://lore.kernel.org/linux-scsi/[email protected]/#t
Signed-off-by John Garry <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 96 lines
---
Compile tested only. And I doubt that this change needs to be merged prior to [0], above.drivers/mmc/host/bcm2835.c +16
-15@@ -188,7 +188,7 @@ struct bcm2835_host {u32 drain_words;struct page *drain_page;u32 drain_offset; -bool use_dma; +struct device *dma_dev; }; static void bcm2835_dumpcmd(struct bcm2835_host *host, struct mmc_command *cmd,@@ -494,8 +494,7 @@ void bcm2835_prepare_dma(struct bcm2835_host *host, struct mmc_data *data) &host->dma_cfg_rx : &host->dma_cfg_tx); - sg_len =dma_map_sg (dma_chan->device->dev, data->sg, data->sg_len, - dir_data); + sg_len =dma_map_sg (host->dma_dev, data->sg, data->sg_len, dir_data);if (!sg_len)return ;@@ -503,8 +502,7 @@ void bcm2835_prepare_dma(struct bcm2835_host *host, struct mmc_data *data) DMA_PREP_INTERRUPT | DMA_CTRL_ACK);if (!desc) { -dma_unmap_sg (dma_chan->device->dev, data->sg, data->sg_len, - dir_data); +dma_unmap_sg (host->dma_dev, data->sg, data->sg_len, dir_data);return ; }@@ -1201,7 +1199,7 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)return ; } -if (host->use_dma && mrq->data && (mrq->data->blocks >PIO_THRESHOLD )) +if (host->dma_dev && mrq->data && (mrq->data->blocks >PIO_THRESHOLD ))bcm2835_prepare_dma (host, mrq->data); host->use_sbc = !!mrq->sbc && host->mrq->data &&@@ -1281,10 +1279,8 @@ static int bcm2835_add_host(struct bcm2835_host *host)if (!host->dma_chan_rxtx) {dev_warn (dev,"unable to initialise DMA channel. Falling back to PIO\n" ); - host->use_dma = false; + host->dma_dev =NULL ; }else { - host->use_dma = true; - host->dma_cfg_tx.src_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ; host->dma_cfg_tx.dst_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ; host->dma_cfg_tx.direction =DMA_MEM_TO_DEV ;@@ -1300,12 +1296,18 @@ static int bcm2835_add_host(struct bcm2835_host *host)if (dmaengine_slave_config (host->dma_chan_rxtx, &host->dma_cfg_tx) !=0 ||dmaengine_slave_config (host->dma_chan_rxtx, - &host->dma_cfg_rx) !=0 ) - host->use_dma = false; + &host->dma_cfg_rx) !=0 ) { + host->dma_dev = +dmaengine_get_dma_device (host->dma_chan_rxtx); + } } mmc->max_segs =128 ; - mmc->max_req_size =min_t (size_t,524288 ,dma_max_mapping_size (dev)); + mmc->max_req_size =524288 ; +if (host->dma_dev) { + mmc->max_req_size =min_t (size_t, mmc->max_req_size, +dma_max_mapping_size (host->dma_dev)); + } mmc->max_seg_size = mmc->max_req_size; mmc->max_blk_size =1024 ; mmc->max_blk_count =65535 ;@@ -1336,10 +1338,10 @@ static int bcm2835_add_host(struct bcm2835_host *host) } pio_limit_string[0 ] ='\0' ; -if (host->use_dma && (PIO_THRESHOLD >0 )) +if (host->dma_dev && (PIO_THRESHOLD >0 ))sprintf (pio_limit_string," (>%d)" ,PIO_THRESHOLD );dev_info (dev,"loaded - DMA %s%s\n" , - host->use_dma ?"enabled" :"disabled" , pio_limit_string); + host->dma_dev ?"enabled" :"disabled" , pio_limit_string);return 0 ; } --2.43.7
On 13/07/2026 12:25 pm, Ulf Hansson wrote:
[...]
Quoted 11 lines
Quoted 11 lines
drivers/mmc/host/bcm2835.c +1
-3@@ -1281,10 +1279,8 @@ static int bcm2835_add_host(struct bcm2835_host *host)if (!host->dma_chan_rxtx) {dev_warn (dev,"unable to initialise DMA channel. Falling back to PIO\n" ); - host->use_dma = false; + host->dma_dev =NULL ; }else { - host->use_dma = true; - host->dma_cfg_tx.src_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ; host->dma_cfg_tx.dst_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES ;
Quoted 8 lines
drivers/mmc/host/bcm2835.c static int bcm2835_add_host(struct bcm2835_host *host) · line 1299
Quoted 8 lines
drivers/mmc/host/bcm2835.c +1
-2host->dma_cfg_tx.direction =DMA_MEM_TO_DEV ;@@ -1300,12 +1296,18 @@ static int bcm2835_add_host(struct bcm2835_host *host)if (dmaengine_slave_config (host->dma_chan_rxtx, &host->dma_cfg_tx) !=0 ||dmaengine_slave_config (host->dma_chan_rxtx, - &host->dma_cfg_rx) !=0 ) - host->use_dma = false; + &host->dma_cfg_rx) !=0 ) {
Hang on, doesn't this whole if condition need to be inverted? It's true upon dma config _failure_, thanks to the original use_dma logic being a bit backwards here.
Thanks,
Robin.
Quoted 31 lines
Quoted 31 lines
drivers/mmc/host/bcm2835.c +10
-4+ host->dma_dev = +dmaengine_get_dma_device (host->dma_chan_rxtx); + } } mmc->max_segs =128 ; - mmc->max_req_size =min_t (size_t,524288 ,dma_max_mapping_size (dev)); + mmc->max_req_size =524288 ; +if (host->dma_dev) { + mmc->max_req_size =min_t (size_t, mmc->max_req_size, +dma_max_mapping_size (host->dma_dev)); + } mmc->max_seg_size = mmc->max_req_size; mmc->max_blk_size =1024 ; mmc->max_blk_count =65535 ;@@ -1336,10 +1338,10 @@ static int bcm2835_add_host(struct bcm2835_host *host) } pio_limit_string[0 ] ='\0' ; -if (host->use_dma && (PIO_THRESHOLD >0 )) +if (host->dma_dev && (PIO_THRESHOLD >0 ))sprintf (pio_limit_string," (>%d)" ,PIO_THRESHOLD );dev_info (dev,"loaded - DMA %s%s\n" , - host->use_dma ?"enabled" :"disabled" , pio_limit_string); + host->dma_dev ?"enabled" :"disabled" , pio_limit_string);return 0 ; } --2.43.7
Quoted 17 lines · Robin Murphy
On 13/07/2026 12:25 pm, Ulf Hansson wrote:
[...]Quoted 15 lines
Quoted 15 lines
drivers/mmc/host/bcm2835.c +1
-3@@ -1281,10 +1279,8 @@ static int bcm2835_add_host(struct bcm2835_host *host) if (!host->dma_chan_rxtx) { dev_warn(dev, "unable to initialise DMA channel. Falling back to PIO\n"); - host->use_dma = false; + host->dma_dev = NULL; } else { - host->use_dma = true; - host->dma_cfg_tx.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; host->dma_cfg_tx.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
host->dma_cfg_tx.direction=DMA_MEM_TO_DEV;(quoted diff) +0
-0@@ -1300,12 +1296,18 @@ static int bcm2835_add_host(struct bcm2835_host *host)
Quoted 8 lines
Quoted 6 lines
drivers/mmc/host/bcm2835.c static int bcm2835_add_host(struct bcm2835_host *host) · line 1299
Quoted 6 lines
drivers/mmc/host/bcm2835.c +1
-2if (dmaengine_slave_config(host->dma_chan_rxtx, &host->dma_cfg_tx) !=0 ||dmaengine_slave_config (host->dma_chan_rxtx, - &host->dma_cfg_rx) !=0 ) - host->use_dma = false; + &host->dma_cfg_rx) !=0 ) {Hang on, doesn't this whole if condition need to be inverted? It's true upon dma config _failure_, thanks to the original
use_dmalogic being a bit backwards here.
Ah, yes, my mistake. It should be:
if (!dmaengine_slave_config(..., &host->dma_cfg_tx) &&
!dmaengine_slave_config(..., &host->dma_cfg_rx)) dma_dev =
And I don't think that the first dmaengine_slave_config() needs to be undone in case of failure for the second call.
Ulf, how to handle a fix? should I send an update on top of this patch?
thanks
Quoted 24 lines · John Garry
Quoted 22 lines · Robin Murphy
On 13/07/2026 12:25 pm, Ulf Hansson wrote:
[...]Quoted 20 lines
Quoted 20 lines
drivers/mmc/host/bcm2835.c +1
-3@@ -1281,10 +1279,8 @@ static int bcm2835_add_host(struct bcm2835_host *host)if (!host->dma_chan_rxtx) { dev_warn(dev, "unable to initialise DMA channel. Falling back to PIO\n"); - host->use_dma = false; + host->dma_dev = NULL; }else { - host->use_dma = true; - host->dma_cfg_tx.src_addr_width =DMA_SLAVE_BUSWIDTH_4_BYTES; host->dma_cfg_tx.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; host->dma_cfg_tx.direction = DMA_MEM_TO_DEV;drivers/mmc/host/bcm2835.c +0
-0@@ -1300,12 +1296,18 @@ static int bcm2835_add_host(struct bcm2835_host *host) if (dmaengine_slave_config(host->dma_chan_rxtx, &host->dma_cfg_tx) != 0 ||
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
drivers/mmc/host/bcm2835.c static int bcm2835_add_host(struct bcm2835_host *host) · line 1299
Quoted 4 lines
drivers/mmc/host/bcm2835.c +1
-2dmaengine_slave_config(host->dma_chan_rxtx, - &host->dma_cfg_rx) != 0) - host->use_dma = false; + &host->dma_cfg_rx) != 0) {Hang on, doesn't this whole if condition need to be inverted? It's true upon dma config _failure_, thanks to the original
use_dmalogic being a bit backwards here.
Robin, thanks for catching this!
Quoted 11 lines
Ah, yes, my mistake. It should be:
if (!dmaengine_slave_config(...,
&host->dma_cfg_tx) &&!dmaengine_slave_config(..., &host->dma_cfg_rx)) dma_dev =And I don't think that the first
dmaengine_slave_config()needs to be undone in case of failure for the second call.Ulf, how to handle a fix? should I send an update on top of this patch?
I have dropped the $subject patch from my next branch, so please submit a new version.
Quoted 4 lines
thanks
Kind regards
Uffe