diff mbox series

[v2,5/5] dmaengine: sh: rz-dmac: rz_dmac_prepare_descs_for_slave_sg() improvements

Message ID 20230405140842.201883-6-biju.das.jz@bp.renesas.com (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show
Series RZ/G2L DMAC enhancements | expand

Commit Message

Biju Das April 5, 2023, 2:08 p.m. UTC
Some code improvements for rz_dmac_prepare_descs_for_slave_sg().

Replace the loop for->for_each_sg and drop the variables sgl and sg_len.
Also improve the logic for assigning lmdesc->chcfg and lmdesc->header and
lastly, add lmdesc assignment along with the declaration.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
v2:
 * New patch.
---
 drivers/dma/sh/rz-dmac.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

Comments

Biju Das April 12, 2023, 7:29 a.m. UTC | #1
> -----Original Message-----
> From: Biju Das <biju.das.jz@bp.renesas.com>
> Sent: Wednesday, April 5, 2023 3:09 PM
> To: Vinod Koul <vkoul@kernel.org>
> Cc: Biju Das <biju.das.jz@bp.renesas.com>; Geert Uytterhoeven
> <geert+renesas@glider.be>; Prabhakar Mahadev Lad <prabhakar.mahadev-
> lad.rj@bp.renesas.com>; dmaengine@vger.kernel.org; linux-renesas-
> soc@vger.kernel.org
> Subject: [PATCH v2 5/5] dmaengine: sh: rz-dmac:
> rz_dmac_prepare_descs_for_slave_sg() improvements
> 
> Some code improvements for rz_dmac_prepare_descs_for_slave_sg().
> 
> Replace the loop for->for_each_sg and drop the variables sgl and sg_len.
> Also improve the logic for assigning lmdesc->chcfg and lmdesc->header and
> lastly, add lmdesc assignment along with the declaration.
> 
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
> v2:
>  * New patch.
> ---
>  drivers/dma/sh/rz-dmac.c | 22 +++++++++-------------
>  1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index
> 153893045932..c6150d7ae8a7 100644
> --- a/drivers/dma/sh/rz-dmac.c
> +++ b/drivers/dma/sh/rz-dmac.c
> @@ -342,12 +342,12 @@ static void rz_dmac_prepare_desc_for_memcpy(struct
> rz_dmac_chan *channel)
> 
>  static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan
> *channel)  {
> +	struct rz_lmdesc *lmdesc = channel->lmdesc.tail;
>  	struct dma_chan *chan = &channel->vc.chan;
>  	struct rz_dmac *dmac = to_rz_dmac(chan->device);
>  	struct rz_dmac_desc *d = channel->desc;
> -	struct scatterlist *sg, *sgl = d->sg;
> -	struct rz_lmdesc *lmdesc;
> -	unsigned int i, sg_len = d->sgcount;
> +	struct scatterlist *sg;
> +	unsigned int i;
> 
>  	channel->chcfg |= CHCFG_SEL(channel->index) | CHCFG_DEM | CHCFG_DMS;
> 
> @@ -358,9 +358,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct
> rz_dmac_chan *channel)
>  		channel->chcfg |= CHCFG_DAD | CHCFG_REQD;
>  	}
> 
> -	lmdesc = channel->lmdesc.tail;
> -
> -	for (i = 0, sg = sgl; i < sg_len; i++, sg = sg_next(sg)) {
> +	for_each_sg(d->sg, sg, d->sgcount, i) {
>  		if (d->direction == DMA_DEV_TO_MEM) {
>  			lmdesc->sa = channel->src_per_address;
>  			lmdesc->da = sg_dma_address(sg);
> @@ -372,13 +370,11 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct
> rz_dmac_chan *channel)
>  		lmdesc->tb = sg_dma_len(sg);
>  		lmdesc->chitvl = 0;
>  		lmdesc->chext = 0;
> -		if (i == (sg_len - 1)) {
> -			lmdesc->chcfg = (channel->chcfg & ~CHCFG_DEM);
> -			lmdesc->header = HEADER_LV;
> -		} else {
> -			lmdesc->chcfg = channel->chcfg;
> -			lmdesc->header = HEADER_LV;
> -		}
> +		lmdesc->chcfg = channel->chcfg;
> +		lmdesc->header = HEADER_LV;
> +		if (i == (d->sgcount - 1))
> +			lmdesc->chcfg &= ~CHCFG_DEM;

To match with previous code flow,

lmdesc->header = HEADER_LV; should be after lmdesc->chcfg &= ~CHCFG_DEM;

I will change this in next version.

Cheers,
Biju




> +
>  		if (++lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC))
>  			lmdesc = channel->lmdesc.base;
>  	}
> --
> 2.25.1
diff mbox series

Patch

diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index 153893045932..c6150d7ae8a7 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -342,12 +342,12 @@  static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
 
 static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
 {
+	struct rz_lmdesc *lmdesc = channel->lmdesc.tail;
 	struct dma_chan *chan = &channel->vc.chan;
 	struct rz_dmac *dmac = to_rz_dmac(chan->device);
 	struct rz_dmac_desc *d = channel->desc;
-	struct scatterlist *sg, *sgl = d->sg;
-	struct rz_lmdesc *lmdesc;
-	unsigned int i, sg_len = d->sgcount;
+	struct scatterlist *sg;
+	unsigned int i;
 
 	channel->chcfg |= CHCFG_SEL(channel->index) | CHCFG_DEM | CHCFG_DMS;
 
@@ -358,9 +358,7 @@  static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
 		channel->chcfg |= CHCFG_DAD | CHCFG_REQD;
 	}
 
-	lmdesc = channel->lmdesc.tail;
-
-	for (i = 0, sg = sgl; i < sg_len; i++, sg = sg_next(sg)) {
+	for_each_sg(d->sg, sg, d->sgcount, i) {
 		if (d->direction == DMA_DEV_TO_MEM) {
 			lmdesc->sa = channel->src_per_address;
 			lmdesc->da = sg_dma_address(sg);
@@ -372,13 +370,11 @@  static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
 		lmdesc->tb = sg_dma_len(sg);
 		lmdesc->chitvl = 0;
 		lmdesc->chext = 0;
-		if (i == (sg_len - 1)) {
-			lmdesc->chcfg = (channel->chcfg & ~CHCFG_DEM);
-			lmdesc->header = HEADER_LV;
-		} else {
-			lmdesc->chcfg = channel->chcfg;
-			lmdesc->header = HEADER_LV;
-		}
+		lmdesc->chcfg = channel->chcfg;
+		lmdesc->header = HEADER_LV;
+		if (i == (d->sgcount - 1))
+			lmdesc->chcfg &= ~CHCFG_DEM;
+
 		if (++lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC))
 			lmdesc = channel->lmdesc.base;
 	}