mmc: tmio: use PIO for short transfers

This patch allows transferring of some requests in PIO and some in DMA
mode and defaults to using DMA only for transfers longer than 8 bytes.
This is especially useful with SDIO, which can have lots of 2- and 4-byte
transfers, creating unnecessary high overhead, when executed in DMA.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Chris Ball <cjb@laptop.org>

authored by Guennadi Liakhovetski and committed by Chris Ball 5f52c355 51fc7b2c

+23 -10
+23 -10
drivers/mmc/host/tmio_mmc.c
··· 100 100 TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT) 101 101 #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD) 102 102 103 + #define TMIO_MIN_DMA_LEN 8 104 + 103 105 #define enable_mmc_irqs(host, i) \ 104 106 do { \ 105 107 u32 mask;\ ··· 149 147 struct platform_device *pdev; 150 148 151 149 /* DMA support */ 150 + bool force_pio; 152 151 struct dma_chan *chan_rx; 153 152 struct dma_chan *chan_tx; 154 153 struct tasklet_struct dma_complete; ··· 388 385 host->cmd = NULL; 389 386 host->data = NULL; 390 387 host->mrq = NULL; 388 + host->force_pio = false; 391 389 392 390 spin_unlock_irqrestore(&host->lock, flags); 393 391 ··· 408 404 host->mrq = NULL; 409 405 host->cmd = NULL; 410 406 host->data = NULL; 407 + host->force_pio = false; 411 408 412 409 cancel_delayed_work(&host->delayed_reset_work); 413 410 ··· 490 485 unsigned int count; 491 486 unsigned long flags; 492 487 493 - if (host->chan_tx || host->chan_rx) { 488 + if ((host->chan_tx || host->chan_rx) && !host->force_pio) { 494 489 pr_err("PIO IRQ in DMA mode!\n"); 495 490 return; 496 491 } else if (!data) { ··· 556 551 */ 557 552 558 553 if (data->flags & MMC_DATA_READ) { 559 - if (!host->chan_rx) 560 - disable_mmc_irqs(host, TMIO_MASK_READOP); 561 - else 554 + if (host->chan_rx && !host->force_pio) 562 555 tmio_check_bounce_buffer(host); 563 556 dev_dbg(&host->pdev->dev, "Complete Rx request %p\n", 564 557 host->mrq); 565 558 } else { 566 - if (!host->chan_tx) 567 - disable_mmc_irqs(host, TMIO_MASK_WRITEOP); 568 559 dev_dbg(&host->pdev->dev, "Complete Tx request %p\n", 569 560 host->mrq); 570 561 } ··· 584 583 if (!data) 585 584 goto out; 586 585 587 - if (host->chan_tx && (data->flags & MMC_DATA_WRITE)) { 586 + if (host->chan_tx && (data->flags & MMC_DATA_WRITE) && !host->force_pio) { 588 587 /* 589 588 * Has all data been written out yet? Testing on SuperH showed, 590 589 * that in most cases the first interrupt comes already with the ··· 597 596 disable_mmc_irqs(host, TMIO_STAT_DATAEND); 598 597 tasklet_schedule(&host->dma_complete); 599 598 } 600 - } else if (host->chan_rx && (data->flags & MMC_DATA_READ)) { 599 + } else if (host->chan_rx && (data->flags & MMC_DATA_READ) && !host->force_pio) { 601 600 disable_mmc_irqs(host, TMIO_STAT_DATAEND); 602 601 tasklet_schedule(&host->dma_complete); 603 602 } else { 604 603 tmio_mmc_do_data_irq(host); 604 + disable_mmc_irqs(host, TMIO_MASK_READOP | TMIO_MASK_WRITEOP); 605 605 } 606 606 out: 607 607 spin_unlock(&host->lock); ··· 651 649 */ 652 650 if (host->data && !cmd->error) { 653 651 if (host->data->flags & MMC_DATA_READ) { 654 - if (!host->chan_rx) 652 + if (host->force_pio || !host->chan_rx) 655 653 enable_mmc_irqs(host, TMIO_MASK_READOP); 656 654 else 657 655 tasklet_schedule(&host->dma_issue); 658 656 } else { 659 - if (!host->chan_tx) 657 + if (host->force_pio || !host->chan_tx) 660 658 enable_mmc_irqs(host, TMIO_MASK_WRITEOP); 661 659 else 662 660 tasklet_schedule(&host->dma_issue); ··· 812 810 goto pio; 813 811 } 814 812 813 + if (sg->length < TMIO_MIN_DMA_LEN) { 814 + host->force_pio = true; 815 + return; 816 + } 817 + 815 818 disable_mmc_irqs(host, TMIO_STAT_RXRDY); 816 819 817 820 /* The only sg element can be unaligned, use our bounce buffer then */ ··· 883 876 align >= MAX_ALIGN)) || !multiple) { 884 877 ret = -EINVAL; 885 878 goto pio; 879 + } 880 + 881 + if (sg->length < TMIO_MIN_DMA_LEN) { 882 + host->force_pio = true; 883 + return; 886 884 } 887 885 888 886 disable_mmc_irqs(host, TMIO_STAT_TXRQ); ··· 1131 1119 1132 1120 fail: 1133 1121 host->mrq = NULL; 1122 + host->force_pio = false; 1134 1123 mrq->cmd->error = ret; 1135 1124 mmc_request_done(mmc, mrq); 1136 1125 }