Re: [PATCH v1 3/3] mmc: Add driver for LiteX's LiteSDCard interface

Gabriel L. Somlo
2021-12-08T16:46:43Z

Hi Joel,

On Mon, Dec 06, 2021 at 10:53:17AM +0000, Joel Stanley wrote:
> On Fri, 3 Dec 2021 at 23:42, Gabriel Somlo <gsomlo@gmail.com> wrote:
> > +static void
> litex_request> +litex_request(struct mmc_host *mmc, struct mmc_request *mrq)
> > +{
> > + struct litex_mmc_host *host = mmc_priv(mmc);
> > + struct platform_device *pdev = to_platform_device(mmc->parent);
> > + struct device *dev = &pdev->dev;
> > + struct mmc_data *data = mrq->data;
> > + struct mmc_command *sbc = mrq->sbc;
> > + struct mmc_command *cmd = mrq->cmd;
> > + struct mmc_command *stop = mrq->stop;
> > + unsigned int retries = cmd->retries;
> > + int status;
> > + int sg_count;
> > + enum dma_data_direction dir = DMA_TO_DEVICE;
> > + bool direct = false;
> > + dma_addr_t dma;
> > + unsigned int len = 0;
> > +
> > + u32 response_len = litex_response_len(cmd);
> > + u32 transfer = SDCARD_CTRL_DATA_TRANSFER_NONE;
> > +
> > + /* First check that the card is still there */
> > + if (!litex_get_cd(mmc)) {
> > + cmd->error = -ENOMEDIUM;
> > + mmc_request_done(mmc, mrq);
> > + return;
> > + }
> > +
> > + /* Send set-block-count command if needed */
> > + if (sbc) {
> > + status = send_cmd(host, sbc->opcode, sbc->arg,
> > + litex_response_len(sbc),
> > + SDCARD_CTRL_DATA_TRANSFER_NONE);
> > + sbc->error = litex_map_status(status);
> > + if (status != SD_OK) {
> > + host->is_bus_width_set = false;
> > + mmc_request_done(mmc, mrq);
> > + return;
> > + }
> > + }
> > +
> > + if (data) {
>
> This is a big ol' if(). Consider splitting it (or some of it?) out
> into some other functions to make it easier to read.
>

I can factor out the dma transfer portion into a dedicated helper
function:

static void litex_mmc_data_dma_transfer(struct litex_mmc_host *host,
struct mmc_data *data,
unsigned int *len,
bool *direct,
u8 *transfer)

where `len`, `direct`, and `transfer` are passed in as pointers,
because the helper function modifies their values and the caller
(i.e., `litex_[mmc_]request()`) is subsequently using those
potentially modified-by-the-callee values.

If you still feel the extra call overhead is worth the tradeoff in
improved legibility and code grouping, let me know and I can have it
out in version 4 (I sent out v3 earlier this morning without changing
this part).

Thanks,
--Gabriel