Skip to content

Commit 93e2631

Browse files
CL WangCharlesWu465
authored andcommitted
mmc: andes: ftsdc010: Only MMC block commands use DMA mode for data transfer (torvalds#223)
Determine if DMA mode should be used for the current command. DMA mode is preferred for block transfers to optimize performance, but it may not be used in certain situations: 1. Only block transfer commands (CMD17, CMD18, CMD24, CMD25) will utilize DMA to minimize overhead for smaller commands. 2. PIO mode is used for CMD6 to avoid potential hangup issues during system resumes on specific FPGA implementations. Signed-off-by: CL Wang <[email protected]> Reviewed-on: https://gitea.andestech.com/RD-SW/linux/pulls/223 Reviewed-by: randolph <[email protected]> Reviewed-by: Leo Yu-Chi Liang <[email protected]> Reviewed-by: Locus Wei-Han Chen <[email protected]> Reviewed-by: Tim Shih-Ting OuYang <[email protected]> Co-authored-by: CL Wang <[email protected]> Co-committed-by: CL Wang <[email protected]>
1 parent e78d0d1 commit 93e2631

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

drivers/mmc/host/ftsdc010.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,32 @@ static void dbg_dumpregs(struct ftsdc_host *host, char *prefix)
162162

163163
#endif /* CONFIG_MMC_DEBUG */
164164

165-
static inline bool ftsdc_dmaexist(struct ftsdc_host *host)
165+
/**
166+
* ftsdc_use_dma_by_cmd - Check if the current command can use DMA mode
167+
* @host: The FTSDC host containing the current command and DMA channel status
168+
*
169+
* Returns true if the command can use DMA mode, false otherwise.
170+
*/
171+
static bool ftsdc_use_dma_by_cmd(struct ftsdc_host *host)
166172
{
167-
return (host->dma.chan != NULL);
173+
struct mmc_command *cmd = host->cmd_is_stop ? host->mrq->stop : host->mrq->cmd;
174+
175+
/*
176+
* Determine if DMA mode should be used for the current command.
177+
* DMA mode is preferred for block transfers to optimize performance,
178+
* but it may not be used in certain situations:
179+
* 1. Only block transfer commands (CMD17, CMD18, CMD24, CMD25)
180+
* will utilize DMA to minimize overhead for smaller commands.
181+
* 2. PIO mode is used for CMD6 to avoid potential hangup issues
182+
* during system resume on specific FPGA implementations.
183+
*/
184+
if (unlikely(!host->dma.chan))
185+
return false;
186+
187+
return (cmd->opcode == MMC_READ_SINGLE_BLOCK ||
188+
cmd->opcode == MMC_READ_MULTIPLE_BLOCK ||
189+
cmd->opcode == MMC_WRITE_BLOCK ||
190+
cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK);
168191
}
169192

170193
static inline u32 enable_imask(struct ftsdc_host *host, u32 imask)
@@ -724,13 +747,14 @@ static int ftsdc_setup_data(struct ftsdc_host *host, struct mmc_data *data)
724747

725748
/* enable data transfer which will be pended until cmd is send */
726749
dcon |= SDC_DATA_CTRL_REG_DATA_EN;
727-
if (ftsdc_dmaexist(host) &&
750+
if (ftsdc_use_dma_by_cmd(host) &&
728751
((data->blksz * data->blocks) & 0xf) == 0) {
729752
newmask &= ~SDC_INT_MASK_REG_FIFO_OVERRUN;
730753
dcon |= SDC_DATA_CTRL_REG_DMA_EN;
731754
dcon |= SDC_DMA_TYPE_4;
732755
host->dodma = true;
733-
756+
} else {
757+
host->dodma = false;
734758
}
735759
REG_WRITE(dcon, SDC_DATA_CTRL_REG);
736760
/* add to IMASK register */
@@ -1175,7 +1199,7 @@ static int ftsdc_state_show(struct seq_file *seq, void *v)
11751199
seq_printf(seq, "IRQ = %d\n", host->irq);
11761200
seq_printf(seq, "IRQ enabled = %d\n", host->irq_enabled);
11771201
seq_printf(seq, "complete what = %d\n", host->complete_what);
1178-
seq_printf(seq, "dma support = %d\n", ftsdc_dmaexist(host));
1202+
seq_printf(seq, "dma support = %d\n", host->dma.chan != NULL);
11791203
seq_printf(seq, "use dma = %d\n", host->dodma);
11801204

11811205
return 0;

0 commit comments

Comments
 (0)