* [v1,2/4] dmaengine: imx-sdma: add check_bd_buswidth() to kill the dulicated code
@ 2018-07-10 15:31 Vinod Koul
0 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2018-07-10 15:31 UTC (permalink / raw)
To: Robin Gong
Cc: dan.j.williams, shawnguo, s.hauer, fabio.estevam, linux,
linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx
On 11-07-18, 00:23, Robin Gong wrote:
> Add check_bd_buswidth() to minimize the code size.
this looks mostly fine and I think this should be first patch..
>
> Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> ---
> drivers/dma/imx-sdma.c | 64 +++++++++++++++++++++++---------------------------
> 1 file changed, 29 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> index 27ccabf..ed2267d 100644
> --- a/drivers/dma/imx-sdma.c
> +++ b/drivers/dma/imx-sdma.c
> @@ -1326,6 +1326,33 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
> return NULL;
> }
>
> +static int check_bd_buswidth(struct sdma_buffer_descriptor *bd,
> + struct sdma_channel *sdmac, int count,
> + dma_addr_t dma_dst, dma_addr_t dma_src)
> +{
> + int ret = 0;
> +
> + switch (sdmac->word_size) {
> + case DMA_SLAVE_BUSWIDTH_4_BYTES:
> + bd->mode.command = 0;
> + if ((count | dma_dst | dma_src) & 3)
> + ret = -EINVAL;
> + break;
empty line after each break please
> + case DMA_SLAVE_BUSWIDTH_2_BYTES:
> + bd->mode.command = 2;
> + if ((count | dma_dst | dma_src) & 1)
> + ret = -EINVAL;
> + break;
> + case DMA_SLAVE_BUSWIDTH_1_BYTE:
> + bd->mode.command = 1;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return ret;
> +}
> +
^ permalink raw reply [flat|nested] 4+ messages in thread* [v1,2/4] dmaengine: imx-sdma: add check_bd_buswidth() to kill the dulicated code
@ 2018-07-10 16:23 Robin Gong
0 siblings, 0 replies; 4+ messages in thread
From: Robin Gong @ 2018-07-10 16:23 UTC (permalink / raw)
To: vkoul, dan.j.williams, shawnguo, s.hauer, fabio.estevam, linux
Cc: linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx
Add check_bd_buswidth() to minimize the code size.
Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
drivers/dma/imx-sdma.c | 64 +++++++++++++++++++++++---------------------------
1 file changed, 29 insertions(+), 35 deletions(-)
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 27ccabf..ed2267d 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -1326,6 +1326,33 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
return NULL;
}
+static int check_bd_buswidth(struct sdma_buffer_descriptor *bd,
+ struct sdma_channel *sdmac, int count,
+ dma_addr_t dma_dst, dma_addr_t dma_src)
+{
+ int ret = 0;
+
+ switch (sdmac->word_size) {
+ case DMA_SLAVE_BUSWIDTH_4_BYTES:
+ bd->mode.command = 0;
+ if ((count | dma_dst | dma_src) & 3)
+ ret = -EINVAL;
+ break;
+ case DMA_SLAVE_BUSWIDTH_2_BYTES:
+ bd->mode.command = 2;
+ if ((count | dma_dst | dma_src) & 1)
+ ret = -EINVAL;
+ break;
+ case DMA_SLAVE_BUSWIDTH_1_BYTE:
+ bd->mode.command = 1;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return ret;
+}
+
static struct dma_async_tx_descriptor *sdma_prep_memcpy(
struct dma_chan *chan, dma_addr_t dma_dst,
dma_addr_t dma_src, size_t len, unsigned long flags)
@@ -1357,23 +1384,8 @@ static struct dma_async_tx_descriptor *sdma_prep_memcpy(
bd->mode.count = count;
desc->chn_count += count;
- switch (sdmac->word_size) {
- case DMA_SLAVE_BUSWIDTH_4_BYTES:
- bd->mode.command = 0;
- if ((count | dma_src | dma_dst) & 3)
- goto err_bd_out;
- break;
- case DMA_SLAVE_BUSWIDTH_2_BYTES:
- bd->mode.command = 2;
- if ((count | dma_src | dma_dst) & 1)
- goto err_bd_out;
- break;
- case DMA_SLAVE_BUSWIDTH_1_BYTE:
- bd->mode.command = 1;
- break;
- default:
+ if (check_bd_buswidth(bd, sdmac, count, dma_dst, dma_src))
goto err_bd_out;
- }
dma_src += count;
dma_dst += count;
@@ -1440,27 +1452,9 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg(
bd->mode.count = count;
desc->chn_count += count;
- if (sdmac->word_size > DMA_SLAVE_BUSWIDTH_4_BYTES)
+ if (check_bd_buswidth(bd, sdmac, count, 0, sg->dma_address))
goto err_bd_out;
- switch (sdmac->word_size) {
- case DMA_SLAVE_BUSWIDTH_4_BYTES:
- bd->mode.command = 0;
- if (count & 3 || sg->dma_address & 3)
- goto err_bd_out;
- break;
- case DMA_SLAVE_BUSWIDTH_2_BYTES:
- bd->mode.command = 2;
- if (count & 1 || sg->dma_address & 1)
- goto err_bd_out;
- break;
- case DMA_SLAVE_BUSWIDTH_1_BYTE:
- bd->mode.command = 1;
- break;
- default:
- goto err_bd_out;
- }
-
param = BD_DONE | BD_EXTD | BD_CONT;
if (i + 1 == sg_len) {
^ permalink raw reply related [flat|nested] 4+ messages in thread* [v1,2/4] dmaengine: imx-sdma: add check_bd_buswidth() to kill the dulicated code
@ 2018-07-11 5:36 Robin Gong
0 siblings, 0 replies; 4+ messages in thread
From: Robin Gong @ 2018-07-11 5:36 UTC (permalink / raw)
To: Vinod
Cc: dan.j.williams@intel.com, shawnguo@kernel.org,
s.hauer@pengutronix.de, Fabio Estevam, linux@armlinux.org.uk,
linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de,
dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
dl-linux-imx
> -----Original Message-----
> From: Vinod [mailto:vkoul@kernel.org]
> Sent: 2018年7月10日 23:31
> To: Robin Gong <yibin.gong@nxp.com>
> Cc: dan.j.williams@intel.com; shawnguo@kernel.org;
> s.hauer@pengutronix.de; Fabio Estevam <fabio.estevam@nxp.com>;
> linux@armlinux.org.uk; linux-arm-kernel@lists.infradead.org;
> kernel@pengutronix.de; dmaengine@vger.kernel.org;
> linux-kernel@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH v1 2/4] dmaengine: imx-sdma: add check_bd_buswidth() to
> kill the dulicated code
>
> On 11-07-18, 00:23, Robin Gong wrote:
> > Add check_bd_buswidth() to minimize the code size.
>
> this looks mostly fine and I think this should be first patch..
Since no need to check bus width in memcpy case, I'll remove this patch too.
>
> >
> > Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> > ---
> > drivers/dma/imx-sdma.c | 64
> > +++++++++++++++++++++++---------------------------
> > 1 file changed, 29 insertions(+), 35 deletions(-)
> >
> > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index
> > 27ccabf..ed2267d 100644
> > --- a/drivers/dma/imx-sdma.c
> > +++ b/drivers/dma/imx-sdma.c
> > @@ -1326,6 +1326,33 @@ static struct sdma_desc
> *sdma_transfer_init(struct sdma_channel *sdmac,
> > return NULL;
> > }
> >
> > +static int check_bd_buswidth(struct sdma_buffer_descriptor *bd,
> > + struct sdma_channel *sdmac, int count,
> > + dma_addr_t dma_dst, dma_addr_t dma_src) {
> > + int ret = 0;
> > +
> > + switch (sdmac->word_size) {
> > + case DMA_SLAVE_BUSWIDTH_4_BYTES:
> > + bd->mode.command = 0;
> > + if ((count | dma_dst | dma_src) & 3)
> > + ret = -EINVAL;
> > + break;
>
> empty line after each break please
>
> > + case DMA_SLAVE_BUSWIDTH_2_BYTES:
> > + bd->mode.command = 2;
> > + if ((count | dma_dst | dma_src) & 1)
> > + ret = -EINVAL;
> > + break;
> > + case DMA_SLAVE_BUSWIDTH_1_BYTE:
> > + bd->mode.command = 1;
> > + break;
> > + default:
> > + return -EINVAL;
> > + }
> > +
> > + return ret;
> > +}
> > +
> --
> ~Vinod
^ permalink raw reply [flat|nested] 4+ messages in thread* [v1,2/4] dmaengine: imx-sdma: add check_bd_buswidth() to kill the dulicated code
@ 2018-07-11 6:32 Sascha Hauer
0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2018-07-11 6:32 UTC (permalink / raw)
To: Robin Gong
Cc: vkoul, dan.j.williams, shawnguo, fabio.estevam, linux,
linux-arm-kernel, kernel, dmaengine, linux-kernel, linux-imx
On Wed, Jul 11, 2018 at 12:23:11AM +0800, Robin Gong wrote:
> Add check_bd_buswidth() to minimize the code size.
>
> Signed-off-by: Robin Gong <yibin.gong@nxp.com>
> ---
> drivers/dma/imx-sdma.c | 64 +++++++++++++++++++++++---------------------------
> 1 file changed, 29 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
> index 27ccabf..ed2267d 100644
> --- a/drivers/dma/imx-sdma.c
> +++ b/drivers/dma/imx-sdma.c
> @@ -1326,6 +1326,33 @@ static struct sdma_desc *sdma_transfer_init(struct sdma_channel *sdmac,
> return NULL;
> }
>
> +static int check_bd_buswidth(struct sdma_buffer_descriptor *bd,
> + struct sdma_channel *sdmac, int count,
> + dma_addr_t dma_dst, dma_addr_t dma_src)
> +{
Better name this function set_bd_buswidth. I would assume that a
function named check_foo actually checks something, but doesn't set
anything.
Sascha
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-07-11 6:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-10 15:31 [v1,2/4] dmaengine: imx-sdma: add check_bd_buswidth() to kill the dulicated code Vinod Koul
-- strict thread matches above, loose matches on Subject: below --
2018-07-10 16:23 Robin Gong
2018-07-11 5:36 Robin Gong
2018-07-11 6:32 Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox