From patchwork Wed Apr 5 14:08:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13201807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DBD4C76188 for ; Wed, 5 Apr 2023 14:10:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238079AbjDEOKr (ORCPT ); Wed, 5 Apr 2023 10:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbjDEOK0 (ORCPT ); Wed, 5 Apr 2023 10:10:26 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 189AA6E93; Wed, 5 Apr 2023 07:09:52 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,319,1673881200"; d="scan'208";a="158393597" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 05 Apr 2023 23:08:58 +0900 Received: from localhost.localdomain (unknown [10.226.93.81]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 232F442D781B; Wed, 5 Apr 2023 23:08:55 +0900 (JST) From: Biju Das To: Vinod Koul Cc: Biju Das , Lad Prabhakar , Geert Uytterhoeven , dmaengine@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 1/5] dmaengine: sh: rz-dmac: Add rz_dmac_invalidate_lmdesc() Date: Wed, 5 Apr 2023 15:08:38 +0100 Message-Id: <20230405140842.201883-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405140842.201883-1-biju.das.jz@bp.renesas.com> References: <20230405140842.201883-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org rz_dmac_terminate_all() must invalidate lmdescriptor in order to reuse the hardware descriptors in rz_dmac_lmdesc_recycle(). Add rz_dmac_invalidate_lmdesc() so that the same code can be shared between rz_dmac_terminate_all() and rz_dmac_free_chan_resources(). Based on a patch in the BSP by Long Luu Signed-off-by: Biju Das --- v1->v2: * Introduced rz_dmac_invalidate_lmdesc(), so that same code is shared between rz_dmac_free_chan_resources() and rz_dmac_terminate_all() for invalidating hardware descriptors. * updated commit description. --- drivers/dma/sh/rz-dmac.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 9479f29692d3..81e72529f7d3 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -236,6 +236,16 @@ static void rz_lmdesc_setup(struct rz_dmac_chan *channel, * Descriptors preparation */ +static void rz_dmac_invalidate_lmdesc(struct rz_dmac_chan *channel) +{ + struct rz_lmdesc *lmdesc = channel->lmdesc.base; + + for (; lmdesc < channel->lmdesc.base + DMAC_NR_LMDESC; lmdesc++) { + if (lmdesc->header) + lmdesc->header = 0; + } +} + static void rz_dmac_lmdesc_recycle(struct rz_dmac_chan *channel) { struct rz_lmdesc *lmdesc = channel->lmdesc.head; @@ -437,16 +447,11 @@ static void rz_dmac_free_chan_resources(struct dma_chan *chan) { struct rz_dmac_chan *channel = to_rz_dmac_chan(chan); struct rz_dmac *dmac = to_rz_dmac(chan->device); - struct rz_lmdesc *lmdesc = channel->lmdesc.base; struct rz_dmac_desc *desc, *_desc; unsigned long flags; - unsigned int i; spin_lock_irqsave(&channel->vc.lock, flags); - - for (i = 0; i < DMAC_NR_LMDESC; i++) - lmdesc[i].header = 0; - + rz_dmac_invalidate_lmdesc(channel); rz_dmac_disable_hw(channel); list_splice_tail_init(&channel->ld_active, &channel->ld_free); list_splice_tail_init(&channel->ld_queue, &channel->ld_free); @@ -537,6 +542,7 @@ static int rz_dmac_terminate_all(struct dma_chan *chan) rz_dmac_disable_hw(channel); spin_lock_irqsave(&channel->vc.lock, flags); + rz_dmac_invalidate_lmdesc(channel); list_splice_tail_init(&channel->ld_active, &channel->ld_free); list_splice_tail_init(&channel->ld_queue, &channel->ld_free); spin_unlock_irqrestore(&channel->vc.lock, flags); From patchwork Wed Apr 5 14:08:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13201808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCCC6C76188 for ; Wed, 5 Apr 2023 14:10:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238407AbjDEOK4 (ORCPT ); Wed, 5 Apr 2023 10:10:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238417AbjDEOKi (ORCPT ); Wed, 5 Apr 2023 10:10:38 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 23D2665B0; Wed, 5 Apr 2023 07:10:08 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,319,1673881200"; d="scan'208";a="158393604" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 05 Apr 2023 23:09:00 +0900 Received: from localhost.localdomain (unknown [10.226.93.81]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 9E85842D7816; Wed, 5 Apr 2023 23:08:58 +0900 (JST) From: Biju Das To: Vinod Koul Cc: Biju Das , Lad Prabhakar , Geert Uytterhoeven , dmaengine@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 2/5] dmaengine: sh: rz-dmac: Add device_tx_status() callback Date: Wed, 5 Apr 2023 15:08:39 +0100 Message-Id: <20230405140842.201883-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405140842.201883-1-biju.das.jz@bp.renesas.com> References: <20230405140842.201883-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org Add support for device_tx_status() callback as it is needed for RZ/G2L SCIFA driver. Based on a patch in the BSP by Long Luu similar to rcar-dmac Signed-off-by: Biju Das --- v1->v2: * Replaced the loop for->for_each_sg and dropped sgl and sg_len variables from calculate_total_bytes_in_vd(). * Updated commit description. --- drivers/dma/sh/rz-dmac.c | 169 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 1 deletion(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 81e72529f7d3..aaaae1c090ad 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -108,10 +108,12 @@ struct rz_dmac { * Registers */ +#define CRTB 0x0020 #define CHSTAT 0x0024 #define CHCTRL 0x0028 #define CHCFG 0x002c #define NXLA 0x0038 +#define CRLA 0x003c #define DCTRL 0x0000 @@ -650,6 +652,171 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan) rz_dmac_set_dmars_register(dmac, channel->index, 0); } +static unsigned int calculate_total_bytes_in_vd(struct rz_dmac_desc *desc) +{ + unsigned int i, size = 0; + struct scatterlist *sg; + + for_each_sg(desc->sg, sg, desc->sgcount, i) + size += sg_dma_len(sg); + + return size; +} + +static unsigned int calculate_residue_bytes_in_vd(struct rz_dmac_chan *channel) +{ + struct rz_lmdesc *lmdesc = channel->lmdesc.head; + struct dma_chan *chan = &channel->vc.chan; + struct rz_dmac *dmac = to_rz_dmac(chan->device); + unsigned int residue = 0, i = 0; + unsigned int crla; + + /* get current lmdesc */ + crla = rz_dmac_ch_readl(channel, CRLA, 1); + while (!(lmdesc->nxla == crla)) { + lmdesc++; + if (lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC)) + lmdesc = channel->lmdesc.base; + i++; + /* Not found current lmdesc */ + if (i > DMAC_NR_LMDESC) + return 0; + } + + /* Point to current processing lmdesc in hardware */ + lmdesc++; + if (lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC)) + lmdesc = channel->lmdesc.base; + + /* Calculate residue from next lmdesc to end of virtual desc*/ + while (lmdesc->chcfg & CHCFG_DEM) { + lmdesc++; + if (lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC)) + lmdesc = channel->lmdesc.base; + residue += lmdesc->tb; + } + + dev_dbg(dmac->dev, "%s: Getting residue is %d\n", __func__, residue); + + return residue; +} + +static unsigned int rz_dmac_chan_get_residue(struct rz_dmac_chan *channel, + dma_cookie_t cookie) +{ + struct rz_dmac_desc *current_desc, *desc; + enum dma_status status; + unsigned int residue; + unsigned int crla; + unsigned int crtb; + unsigned int i; + + /* Get current processing virtual descriptor */ + current_desc = list_first_entry(&channel->ld_active, + struct rz_dmac_desc, node); + if (!current_desc) + return 0; + + /* + * If the cookie corresponds to a descriptor that has been completed + * there is no residue. The same check has already been performed by the + * caller but without holding the channel lock, so the descriptor could + * now be complete. + */ + status = dma_cookie_status(&channel->vc.chan, cookie, NULL); + if (status == DMA_COMPLETE) + return 0; + + /* + * If the cookie doesn't correspond to the currently processing virtual + * descriptor then the descriptor hasn't been processed yet, and the + * residue is equal to the full descriptor size. + * Also, a client driver is possible to call this function before + * rz_dmac_irq_handler_thread() runs. In this case, the running + * descriptor will be the next descriptor, and the done list will + * appear. So, if the argument cookie matches the done list's cookie, + * we can assume the residue is zero. + */ + if (cookie != current_desc->vd.tx.cookie) { + list_for_each_entry(desc, &channel->ld_free, node) { + if (cookie == desc->vd.tx.cookie) + return 0; + } + + list_for_each_entry(desc, &channel->ld_queue, node) { + if (cookie == desc->vd.tx.cookie) + return calculate_total_bytes_in_vd(desc); + } + + list_for_each_entry(desc, &channel->ld_active, node) { + if (cookie == desc->vd.tx.cookie) + return calculate_total_bytes_in_vd(desc); + } + + /* + * No descriptor found for the cookie, there's thus no residue. + * This shouldn't happen if the calling driver passes a correct + * cookie value. + */ + WARN(1, "No descriptor for cookie!"); + return 0; + } + + /* + * Correspond to the currently processing virtual descriptor + * + * Make sure the hardware does not move to next lmdesc + * while reading the counter. + * Trying it 3 times should be enough: Initial read, retry, retry + * for the paranoid. + * The current lmdesc running in hardware is channel.lmdesc.head + */ + for (i = 0; i < 3; i++) { + crla = rz_dmac_ch_readl(channel, CRLA, 1); + crtb = rz_dmac_ch_readl(channel, CRTB, 1); + /* Still the same? */ + if (crla == rz_dmac_ch_readl(channel, CRLA, 1)) + break; + } + + WARN_ONCE(i >= 3, "residue might be not continuous!"); + + /* + * Calculate number of byte transferred in processing virtual descriptor + * One virtual descriptor can have many lmdesc + */ + residue = crtb; + residue += calculate_residue_bytes_in_vd(channel); + + return residue; +} + +static enum dma_status rz_dmac_tx_status(struct dma_chan *chan, + dma_cookie_t cookie, + struct dma_tx_state *txstate) +{ + struct rz_dmac_chan *channel = to_rz_dmac_chan(chan); + enum dma_status status; + unsigned int residue; + unsigned long flags; + + status = dma_cookie_status(chan, cookie, txstate); + if (status == DMA_COMPLETE || !txstate) + return status; + + spin_lock_irqsave(&channel->vc.lock, flags); + residue = rz_dmac_chan_get_residue(channel, cookie); + spin_unlock_irqrestore(&channel->vc.lock, flags); + + /* if there's no residue, the cookie is complete */ + if (!residue) + return DMA_COMPLETE; + + dma_set_residue(txstate, residue); + + return status; +} + /* * ----------------------------------------------------------------------------- * IRQ handling @@ -932,7 +1099,7 @@ static int rz_dmac_probe(struct platform_device *pdev) engine->device_alloc_chan_resources = rz_dmac_alloc_chan_resources; engine->device_free_chan_resources = rz_dmac_free_chan_resources; - engine->device_tx_status = dma_cookie_status; + engine->device_tx_status = rz_dmac_tx_status; engine->device_prep_slave_sg = rz_dmac_prep_slave_sg; engine->device_prep_dma_memcpy = rz_dmac_prep_dma_memcpy; engine->device_config = rz_dmac_config; From patchwork Wed Apr 5 14:10:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13201811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD8B1C761A6 for ; Wed, 5 Apr 2023 14:11:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238529AbjDEOLd (ORCPT ); Wed, 5 Apr 2023 10:11:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237448AbjDEOLM (ORCPT ); Wed, 5 Apr 2023 10:11:12 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ED57765BF; Wed, 5 Apr 2023 07:10:41 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,319,1673881200"; d="scan'208";a="158393799" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 05 Apr 2023 23:10:41 +0900 Received: from localhost.localdomain (unknown [10.226.93.81]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id C821B42DB43A; Wed, 5 Apr 2023 23:10:39 +0900 (JST) From: Biju Das To: Vinod Koul Cc: Biju Das , Geert Uytterhoeven , Lad Prabhakar , dmaengine@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 3/5] dmaengine: sh: rz-dmac: Add device_{pause,resume}() callbacks Date: Wed, 5 Apr 2023 15:10:37 +0100 Message-Id: <20230405141037.201999-1-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org Add support for device_{pause, resume}() callbacks as it is needed for RZ/G2L SCIFA driver. Based on a patch in the BSP by Long Luu Signed-off-by: Biju Das --- v1->v2: * Added resume callback(). * Updated commit description. --- drivers/dma/sh/rz-dmac.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index aaaae1c090ad..3ef516aee4fc 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -817,6 +817,35 @@ static enum dma_status rz_dmac_tx_status(struct dma_chan *chan, return status; } +static int rz_dmac_device_pause(struct dma_chan *chan) +{ + struct rz_dmac_chan *channel = to_rz_dmac_chan(chan); + struct rz_dmac *dmac = to_rz_dmac(chan->device); + unsigned int i; + u32 chstat; + + for (i = 0; i < 1024; i++) { + chstat = rz_dmac_ch_readl(channel, CHSTAT, 1); + if (!(chstat & CHSTAT_EN)) + break; + udelay(1); + } + + rz_dmac_set_dmars_register(dmac, channel->index, 0); + + return 0; +} + +static int rz_dmac_device_resume(struct dma_chan *chan) +{ + struct rz_dmac_chan *channel = to_rz_dmac_chan(chan); + struct rz_dmac *dmac = to_rz_dmac(chan->device); + + rz_dmac_set_dmars_register(dmac, channel->index, channel->mid_rid); + + return 0; +} + /* * ----------------------------------------------------------------------------- * IRQ handling @@ -1106,6 +1135,8 @@ static int rz_dmac_probe(struct platform_device *pdev) engine->device_terminate_all = rz_dmac_terminate_all; engine->device_issue_pending = rz_dmac_issue_pending; engine->device_synchronize = rz_dmac_device_synchronize; + engine->device_pause = rz_dmac_device_pause; + engine->device_resume = rz_dmac_device_resume; engine->copy_align = DMAENGINE_ALIGN_1_BYTE; dma_set_max_seg_size(engine->dev, U32_MAX); From patchwork Wed Apr 5 14:08:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13201809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13C3DC76188 for ; Wed, 5 Apr 2023 14:11:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238451AbjDEOLB (ORCPT ); Wed, 5 Apr 2023 10:11:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238488AbjDEOKm (ORCPT ); Wed, 5 Apr 2023 10:10:42 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 685A06A68; Wed, 5 Apr 2023 07:10:15 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,319,1673881200"; d="scan'208";a="158393613" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 05 Apr 2023 23:09:04 +0900 Received: from localhost.localdomain (unknown [10.226.93.81]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 6EB3642D7816; Wed, 5 Apr 2023 23:09:02 +0900 (JST) From: Biju Das To: Vinod Koul Cc: Biju Das , Geert Uytterhoeven , Lad Prabhakar , dmaengine@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 4/5] dmaengine: sh: rz-dmac: Trivial code clean-ups Date: Wed, 5 Apr 2023 15:08:41 +0100 Message-Id: <20230405140842.201883-5-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405140842.201883-1-biju.das.jz@bp.renesas.com> References: <20230405140842.201883-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org Some trivial code clean-ups for rz_dmac_lmdesc_recycle() and rz_dmac_prep_slave_sg(). Drop unnecessary lmdesc invalidation in rz_dmac_lmdesc_recycle() as the lmdesc is already invalidated. Drop redundant assignment of i to "0" and change the variable type of "i" to unsigned int to match with the variable type of sg_len in rz_dmac_prep_slave_sg(). While at it, Remove the braces around for_each_sg loop as it has a single statement. Signed-off-by: Biju Das --- v2: * New patch. --- drivers/dma/sh/rz-dmac.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index 3ef516aee4fc..153893045932 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -253,7 +253,6 @@ static void rz_dmac_lmdesc_recycle(struct rz_dmac_chan *channel) struct rz_lmdesc *lmdesc = channel->lmdesc.head; while (!(lmdesc->header & HEADER_LV)) { - lmdesc->header = 0; lmdesc++; if (lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC)) lmdesc = channel->lmdesc.base; @@ -510,16 +509,15 @@ rz_dmac_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, struct rz_dmac_desc *desc; struct scatterlist *sg; int dma_length = 0; - int i = 0; + unsigned int i; if (list_empty(&channel->ld_free)) return NULL; desc = list_first_entry(&channel->ld_free, struct rz_dmac_desc, node); - for_each_sg(sgl, sg, sg_len, i) { + for_each_sg(sgl, sg, sg_len, i) dma_length += sg_dma_len(sg); - } desc->type = RZ_DMAC_DESC_SLAVE_SG; desc->sg = sgl; From patchwork Wed Apr 5 14:08:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13201810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2F27C77B6E for ; Wed, 5 Apr 2023 14:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238509AbjDEOLL (ORCPT ); Wed, 5 Apr 2023 10:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238504AbjDEOKq (ORCPT ); Wed, 5 Apr 2023 10:10:46 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4CE8CC5; Wed, 5 Apr 2023 07:10:18 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.98,319,1673881200"; d="scan'208";a="158393620" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 05 Apr 2023 23:09:06 +0900 Received: from localhost.localdomain (unknown [10.226.93.81]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id EACF242D8EF2; Wed, 5 Apr 2023 23:09:04 +0900 (JST) From: Biju Das To: Vinod Koul Cc: Biju Das , Geert Uytterhoeven , Lad Prabhakar , 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 Date: Wed, 5 Apr 2023 15:08:42 +0100 Message-Id: <20230405140842.201883-6-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405140842.201883-1-biju.das.jz@bp.renesas.com> References: <20230405140842.201883-1-biju.das.jz@bp.renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org 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 --- 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; + if (++lmdesc >= (channel->lmdesc.base + DMAC_NR_LMDESC)) lmdesc = channel->lmdesc.base; }