devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Gabriel L. Somlo" <gsomlo@gmail.com>
To: Joel Stanley <joel@jms.id.au>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	linux-mmc <linux-mmc@vger.kernel.org>,
	Karol Gugala <kgugala@antmicro.com>,
	Mateusz Holenko <mholenko@antmicro.com>,
	krakoczy@antmicro.com, mdudek@internships.antmicro.com,
	Paul Mackerras <paulus@ozlabs.org>,
	Stafford Horne <shorne@gmail.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	david.abdurachmanov@sifive.com,
	Florent Kermarrec <florent@enjoy-digital.fr>
Subject: Re: [PATCH v1 3/3] mmc: Add driver for LiteX's LiteSDCard interface
Date: Wed, 8 Dec 2021 11:46:36 -0500	[thread overview]
Message-ID: <YbDhbLnZVUhw/mz4@errol.ini.cmu.edu> (raw)
In-Reply-To: <CACPK8XfO_8=vgedmZddz1YmWbyxiM1-azF_j88wEBHzXnP6y_g@mail.gmail.com>

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

      parent reply	other threads:[~2021-12-08 16:46 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03 23:41 [PATCH v1 0/3] mmc: Add LiteSDCard mmc driver Gabriel Somlo
2021-12-03 23:41 ` [PATCH v1 1/3] MAINTAINERS: co-maintain LiteX platform Gabriel Somlo
2021-12-03 23:41 ` [PATCH v1 2/3] dt-bindings: mmc: Add bindings for LiteSDCard Gabriel Somlo
2021-12-06  9:38   ` Geert Uytterhoeven
2021-12-06 12:35     ` Gabriel L. Somlo
2021-12-03 23:41 ` [PATCH v1 3/3] mmc: Add driver for LiteX's LiteSDCard interface Gabriel Somlo
2021-12-04  0:20   ` Randy Dunlap
2021-12-04  0:33     ` Gabriel L. Somlo
2021-12-04  4:41   ` kernel test robot
2021-12-04  7:29   ` Stafford Horne
2021-12-05 21:39   ` Stafford Horne
2021-12-05 22:55     ` Gabriel L. Somlo
2021-12-06 10:53   ` Joel Stanley
2021-12-06 12:16     ` Geert Uytterhoeven
2021-12-06 23:51       ` Joel Stanley
2021-12-07  0:53         ` Gabriel L. Somlo
2021-12-07  8:01         ` Geert Uytterhoeven
2021-12-07  1:23     ` Gabriel L. Somlo
2021-12-07  2:46       ` Joel Stanley
2021-12-07 18:51         ` Gabriel L. Somlo
2021-12-08 16:46     ` Gabriel L. Somlo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YbDhbLnZVUhw/mz4@errol.ini.cmu.edu \
    --to=gsomlo@gmail.com \
    --cc=david.abdurachmanov@sifive.com \
    --cc=devicetree@vger.kernel.org \
    --cc=florent@enjoy-digital.fr \
    --cc=geert@linux-m68k.org \
    --cc=joel@jms.id.au \
    --cc=kgugala@antmicro.com \
    --cc=krakoczy@antmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=mdudek@internships.antmicro.com \
    --cc=mholenko@antmicro.com \
    --cc=paulus@ozlabs.org \
    --cc=robh+dt@kernel.org \
    --cc=shorne@gmail.com \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).