From: Boris Brezillon <boris.brezillon@collabora.com>
To: <Tudor.Ambarus@microchip.com>
Cc: yogeshnarayan.gaur@nxp.com, vigneshr@ti.com,
bbrezillon@kernel.org, richard@nod.at,
linux-kernel@vger.kernel.org, marek.vasut@gmail.com,
linux-mtd@lists.infradead.org, miquel.raynal@bootlin.com
Subject: Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c
Date: Thu, 25 Jul 2019 16:00:25 +0200 [thread overview]
Message-ID: <20190725160025.2d8e24f8@collabora.com> (raw)
In-Reply-To: <dbb33973-bb6f-9a01-b821-693387aff98a@microchip.com>
On Thu, 25 Jul 2019 13:17:07 +0000
<Tudor.Ambarus@microchip.com> wrote:
> Hi, Boris,
>
> On 07/25/2019 03:37 PM, Boris Brezillon wrote:
> > External E-Mail
> >
> >
> > On Thu, 25 Jul 2019 11:19:06 +0000
> > <Tudor.Ambarus@microchip.com> wrote:
> >
> >>> + */
> >>> +static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
> >>> + u64 *addr, void *buf, size_t len)
> >>> +{
> >>> + int ret;
> >>> + bool usebouncebuf = false;
> >>
> >> I don't think we need a bounce buffer for regs. What is the maximum size that we
> >> read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?
> >>
> >> In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is
> >> SPI_NOR_MAX_ID_LEN(6).
> >>
> >> I can provide a patch to always use nor->cmd_buf when reading/writing regs so
> >> you respin the series on top of it, if you feel the same.
> >>
> >> With nor->cmd_buf this function will be reduced to the following:
> >>
> >> static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)
> >> {
> >> if (!op || (op->data.nbytes && !nor->cmd_buf))
> >> return -EINVAL;
> >>
> >> return spi_mem_exec_op(nor->spimem, op);
> >> }
> >
> > Well, I don't think that's a good idea. ->cmd_buf is an array in the
> > middle of the spi_nor struct, which means it won't be aligned on a
> > cache line and you'll have to be extra careful not to touch the spi_nor
> > fields when calling spi_mem_exec_op(). Might work, but I wouldn't take
> > the risk if I were you.
> >
>
> u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE] ____cacheline_aligned;
>
> Does this help?
I guess you'll also need one on the following field to guarantee that
cmd_buf is covering the whole cache line. TBH, I really prefer the
option of allocating ->cmd_buf.
>
> > Another option would be to allocate ->cmd_buf with kmalloc() instead of
> > having it defined as a static array.
> >
> >>
> >> spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't
> >> need buf anymore and you can retrieve the length from op->data.nbytes. Now that
> >> we trimmed the arguments, I think I would get rid of the
> >> spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.
> >
> > I think I added the addr param for a good reason (probably to support
> > Octo mode cmds that take an address parameter). This being said, I
> > agree with you, we should just pass everything through the op parameter
> > (including the address if we ever need to add one).
> >
> >
> >>> +
> >>> +/**
> >>> + * spi_nor_spimem_xfer_data() - helper function to read/write data to
> >>> + * flash's memory region
> >>> + * @nor: pointer to 'struct spi_nor'
> >>> + * @op: pointer to 'struct spi_mem_op' template for transfer
> >>> + * @proto: protocol to be used for transfer
> >>> + *
> >>> + * Return: number of bytes transferred on success, -errno otherwise
> >>> + */
> >>> +static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
> >>> + struct spi_mem_op *op,
> >>> + enum spi_nor_protocol proto)
> >>> +{
> >>> + bool usebouncebuf = false;
> >>
> >> declare bool at the end to avoid stack padding.
> >
> > But it breaks the reverse-xmas-tree formatting :-).
> >
> >>
> >>> + void *rdbuf = NULL;
> >>> + const void *buf;
> >>
> >> you can get rid of rdbuf and buf if you pass buf as argument.
> >
> > Hm, passing the buffer to send data from/receive data into is already
> > part of the spi_mem_op definition process (which is done in the caller
> > of this func) so why bother passing an extra arg to the function.
> > Note that you had the exact opposite argument for the
> > spi_nor_spimem_xfer_reg() prototype you suggested above (which I
> > agree with BTW) :P.
>
> In order to avoid if clauses like "if (op->data.dir == SPI_MEM_DATA_IN)". You
> can't use op->data.buf directly, the *out const qualifier can be discarded.
Not entirely sure why you think this is important to avoid that
test (looks like a micro-optimization to me), but if you really want to
have a non-const buffer, just use the one pointed by op->data.buf.in
(buf is a union so both in and out point to the same thing). Note that
we'd need a comment explaining why this is safe to do that, because
bypassing constness constraints is usually a bad thing.
>
> pointer to buf was not needed in spi_nor_spimem_xfer_reg(), we could use
> nor->cmd_buf.
Do you mean that callers of spi_nor_spimem_xfer_data() should put data
into/read from ->cmd_buf and let spi_nor_spimem_xfer_data() assign
op->data.buf.{in,out} to ->cmd_buf?
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
WARNING: multiple messages have this Message-ID (diff)
From: Boris Brezillon <boris.brezillon@collabora.com>
To: <Tudor.Ambarus@microchip.com>
Cc: <vigneshr@ti.com>, <miquel.raynal@bootlin.com>, <richard@nod.at>,
<marek.vasut@gmail.com>, <bbrezillon@kernel.org>,
<yogeshnarayan.gaur@nxp.com>, <linux-kernel@vger.kernel.org>,
<linux-mtd@lists.infradead.org>
Subject: Re: [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c
Date: Thu, 25 Jul 2019 16:00:25 +0200 [thread overview]
Message-ID: <20190725160025.2d8e24f8@collabora.com> (raw)
In-Reply-To: <dbb33973-bb6f-9a01-b821-693387aff98a@microchip.com>
On Thu, 25 Jul 2019 13:17:07 +0000
<Tudor.Ambarus@microchip.com> wrote:
> Hi, Boris,
>
> On 07/25/2019 03:37 PM, Boris Brezillon wrote:
> > External E-Mail
> >
> >
> > On Thu, 25 Jul 2019 11:19:06 +0000
> > <Tudor.Ambarus@microchip.com> wrote:
> >
> >>> + */
> >>> +static int spi_nor_exec_op(struct spi_nor *nor, struct spi_mem_op *op,
> >>> + u64 *addr, void *buf, size_t len)
> >>> +{
> >>> + int ret;
> >>> + bool usebouncebuf = false;
> >>
> >> I don't think we need a bounce buffer for regs. What is the maximum size that we
> >> read/write regs, SPI_NOR_MAX_CMD_SIZE(8)?
> >>
> >> In spi-nor.c the maximum length that we pass to nor->read_reg()/write_reg() is
> >> SPI_NOR_MAX_ID_LEN(6).
> >>
> >> I can provide a patch to always use nor->cmd_buf when reading/writing regs so
> >> you respin the series on top of it, if you feel the same.
> >>
> >> With nor->cmd_buf this function will be reduced to the following:
> >>
> >> static int spi_nor_spimem_xfer_reg(struct spi_nor *nor, struct spi_mem_op *op)
> >> {
> >> if (!op || (op->data.nbytes && !nor->cmd_buf))
> >> return -EINVAL;
> >>
> >> return spi_mem_exec_op(nor->spimem, op);
> >> }
> >
> > Well, I don't think that's a good idea. ->cmd_buf is an array in the
> > middle of the spi_nor struct, which means it won't be aligned on a
> > cache line and you'll have to be extra careful not to touch the spi_nor
> > fields when calling spi_mem_exec_op(). Might work, but I wouldn't take
> > the risk if I were you.
> >
>
> u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE] ____cacheline_aligned;
>
> Does this help?
I guess you'll also need one on the following field to guarantee that
cmd_buf is covering the whole cache line. TBH, I really prefer the
option of allocating ->cmd_buf.
>
> > Another option would be to allocate ->cmd_buf with kmalloc() instead of
> > having it defined as a static array.
> >
> >>
> >> spi_nor_exec_op() always received a NULL addr, let's get rid of it. We won't
> >> need buf anymore and you can retrieve the length from op->data.nbytes. Now that
> >> we trimmed the arguments, I think I would get rid of the
> >> spi_nor_data/nodata_op() wrappers and use spi_nor_spimem_xfer_reg() directly.
> >
> > I think I added the addr param for a good reason (probably to support
> > Octo mode cmds that take an address parameter). This being said, I
> > agree with you, we should just pass everything through the op parameter
> > (including the address if we ever need to add one).
> >
> >
> >>> +
> >>> +/**
> >>> + * spi_nor_spimem_xfer_data() - helper function to read/write data to
> >>> + * flash's memory region
> >>> + * @nor: pointer to 'struct spi_nor'
> >>> + * @op: pointer to 'struct spi_mem_op' template for transfer
> >>> + * @proto: protocol to be used for transfer
> >>> + *
> >>> + * Return: number of bytes transferred on success, -errno otherwise
> >>> + */
> >>> +static ssize_t spi_nor_spimem_xfer_data(struct spi_nor *nor,
> >>> + struct spi_mem_op *op,
> >>> + enum spi_nor_protocol proto)
> >>> +{
> >>> + bool usebouncebuf = false;
> >>
> >> declare bool at the end to avoid stack padding.
> >
> > But it breaks the reverse-xmas-tree formatting :-).
> >
> >>
> >>> + void *rdbuf = NULL;
> >>> + const void *buf;
> >>
> >> you can get rid of rdbuf and buf if you pass buf as argument.
> >
> > Hm, passing the buffer to send data from/receive data into is already
> > part of the spi_mem_op definition process (which is done in the caller
> > of this func) so why bother passing an extra arg to the function.
> > Note that you had the exact opposite argument for the
> > spi_nor_spimem_xfer_reg() prototype you suggested above (which I
> > agree with BTW) :P.
>
> In order to avoid if clauses like "if (op->data.dir == SPI_MEM_DATA_IN)". You
> can't use op->data.buf directly, the *out const qualifier can be discarded.
Not entirely sure why you think this is important to avoid that
test (looks like a micro-optimization to me), but if you really want to
have a non-const buffer, just use the one pointed by op->data.buf.in
(buf is a union so both in and out point to the same thing). Note that
we'd need a comment explaining why this is safe to do that, because
bypassing constness constraints is usually a bad thing.
>
> pointer to buf was not needed in spi_nor_spimem_xfer_reg(), we could use
> nor->cmd_buf.
Do you mean that callers of spi_nor_spimem_xfer_data() should put data
into/read from ->cmd_buf and let spi_nor_spimem_xfer_data() assign
op->data.buf.{in,out} to ->cmd_buf?
next prev parent reply other threads:[~2019-07-25 14:00 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-20 8:00 [PATCH v2 0/2] ] Merge m25p80 into spi-nor Vignesh Raghavendra
2019-07-20 8:00 ` Vignesh Raghavendra
2019-07-20 8:00 ` [PATCH v2 1/2] mtd: spi-nor: Move m25p80 code in spi-nor.c Vignesh Raghavendra
2019-07-20 8:00 ` Vignesh Raghavendra
2019-07-25 11:19 ` Tudor.Ambarus
2019-07-25 11:19 ` Tudor.Ambarus
2019-07-25 11:44 ` Tudor.Ambarus
2019-07-25 11:44 ` Tudor.Ambarus
2019-07-25 12:37 ` Boris Brezillon
2019-07-25 12:37 ` Boris Brezillon
2019-07-25 13:17 ` Tudor.Ambarus
2019-07-25 13:17 ` Tudor.Ambarus
2019-07-25 13:35 ` Tudor.Ambarus
2019-07-25 13:35 ` Tudor.Ambarus
2019-07-25 14:00 ` Boris Brezillon [this message]
2019-07-25 14:00 ` Boris Brezillon
2019-07-25 14:36 ` Tudor.Ambarus
2019-07-25 14:36 ` Tudor.Ambarus
2019-07-30 18:04 ` Vignesh Raghavendra
2019-07-30 18:04 ` Vignesh Raghavendra
2019-07-31 6:19 ` Tudor.Ambarus
2019-07-31 6:19 ` Tudor.Ambarus
2019-07-20 8:00 ` [PATCH v2 2/2] mtd: spi-nor: Rework hwcaps selection for the spi-mem case Vignesh Raghavendra
2019-07-20 8:00 ` Vignesh Raghavendra
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=20190725160025.2d8e24f8@collabora.com \
--to=boris.brezillon@collabora.com \
--cc=Tudor.Ambarus@microchip.com \
--cc=bbrezillon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--cc=yogeshnarayan.gaur@nxp.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.