Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2349554rdb; Fri, 8 Dec 2023 05:51:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkINvh34CXzSbyUiYe1MIbYhTdO0n9wJJUwbnx5yacIFeuiOooYvdzUNLZIMIDqTyAM7sf X-Received: by 2002:a17:903:22cb:b0:1d0:6ffe:1e6c with SMTP id y11-20020a17090322cb00b001d06ffe1e6cmr22876plg.79.1702043505416; Fri, 08 Dec 2023 05:51:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702043505; cv=none; d=google.com; s=arc-20160816; b=fiac6D8CBsYIYOLBA26DPZ3P1o1YpH7TEC/ciQ+igtPCOUST7TvkH3jrVkmUoNPt6q aYNOM3UNgE/cpJsy3ps4cXfrb+88LGRVHiuNYGfYfkQSrFxxSKZThEZ493el7hfjUvAj Hh2Y/vjrBPyfjU1Xe0Ma9k/0qJRDVJxb9nY1vz0xcgqEIXRvJsy3+HpU/aDFWMaxOK6K iOJMRir/JnWC1izr7+N0AYNzhphvIPBF2TQIjZFcX82q+A3MBDya5KP7inEDzeF/39qY xtjuntMOAlbpICcgPm1dxEV4hAsjNOxc/XQkKjjhCgvMdZ8gv0sXCzv7K0XVahdpUnIJ 3ovg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=6V3WJLvQetDJFUFw2ejBdQkm4Gnf+EJHfVJ4Ltyxaz8=; fh=1pmAyp3xZ8sWUV98t98q7URUgX68KjDmTZriOyZWZ/U=; b=KIJFAhMMWTbvDdydpoHNIs2B/etsXhJo7EsvvvAlCIdPfR35Ng1iUjt5eiq/FeOuWG 2jxVSok6LyA/bxHVQifOY7W+755oRdiNLmI8qf1cTENFwVeGHuUayLyNJWpjItdpUr5A CTU/Gv+VlEoaff/8nUDZ/t+LQY2y1vXeKuvegzoXLPjV6+CUFk8gUEffXibuqDdzz+UU bOjfpI/DCjc5nryyg4h/0f4LlZzvRYlTUS8cVPcy8qtnc7YXdmEAeep5KNPafN31n3fz QAeIxS++Tewc7JLUQVumNuJPwEKg8ob1K2fz4BUNkqm9JLrQALgbqOsJk+w1T46/Dg95 AYXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alatek.krakow.pl header.s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3 header.b=MiebR+WE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alatek.krakow.pl Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id j9-20020a17090276c900b001ce5b7bd150si1594246plt.607.2023.12.08.05.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 05:51:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=fail header.i=@alatek.krakow.pl header.s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3 header.b=MiebR+WE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alatek.krakow.pl Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 8B14082CD60F; Fri, 8 Dec 2023 05:51:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573879AbjLHNuk (ORCPT + 99 others); Fri, 8 Dec 2023 08:50:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573876AbjLHNui (ORCPT ); Fri, 8 Dec 2023 08:50:38 -0500 Received: from helios.alatek.com.pl (helios.alatek.com.pl [85.14.123.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FCE4172B; Fri, 8 Dec 2023 05:50:44 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by helios.alatek.com.pl (Postfix) with ESMTP id 363BF2D00F5B; Fri, 8 Dec 2023 14:50:42 +0100 (CET) Received: from helios.alatek.com.pl ([127.0.0.1]) by localhost (helios.alatek.com.pl [127.0.0.1]) (amavis, port 10032) with ESMTP id BIgErhrAl4bM; Fri, 8 Dec 2023 14:50:41 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by helios.alatek.com.pl (Postfix) with ESMTP id 4E01B2D00F5A; Fri, 8 Dec 2023 14:50:41 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 helios.alatek.com.pl 4E01B2D00F5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alatek.krakow.pl; s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3; t=1702043441; bh=6V3WJLvQetDJFUFw2ejBdQkm4Gnf+EJHfVJ4Ltyxaz8=; h=From:To:Date:Message-Id:MIME-Version; b=MiebR+WECW1ymOgup1ZnZ/vgfxuT+DUvzcWa+NNyeiguxmrMofZ20+wOhK0/24QY4 IkJ0r5+upK9aNTVTd3fwWdONfgQOUbz0ST1GC+vE8/xWD1FeWf7AuulOyM1TSqF8Xw Tk8DHIIPWh8rdRlG0lxtme9/t43XX5nGs/l91wBhDeWGNxZcPkw9tUdxSgYHs9uwjc reLF5G2HPzsVmQDSZ5vcXgYUzyJUtO+xMyjXRhg15O0CAUQt99fZhG678SuXQ3rE35 2Kw6BX13f0oTzguwu1WZVnHm5tnVjx8RE0XS580PSmtVyQIcuYAx2WB/KuAo5rmSl7 HC7y4+9DwuBSg== X-Virus-Scanned: amavis at alatek.com.pl Received: from helios.alatek.com.pl ([127.0.0.1]) by localhost (helios.alatek.com.pl [127.0.0.1]) (amavis, port 10026) with ESMTP id m8XgVQ_-GNA2; Fri, 8 Dec 2023 14:50:41 +0100 (CET) Received: from localhost.localdomain (unknown [10.125.125.6]) by helios.alatek.com.pl (Postfix) with ESMTPSA id ACD152D00F4D; Fri, 8 Dec 2023 14:50:40 +0100 (CET) From: Jan Kuliga To: lizhi.hou@amd.com, brian.xu@amd.com, raj.kumar.rampelli@amd.com, vkoul@kernel.org, michal.simek@amd.com, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, miquel.raynal@bootlin.com Cc: jankul@alatek.krakow.pl Subject: [PATCH v4 7/8] dmaengine: xilinx: xdma: Prepare the introduction of interleaved DMA transfers Date: Fri, 8 Dec 2023 14:49:28 +0100 Message-Id: <20231208134929.49523-8-jankul@alatek.krakow.pl> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231208134838.49500-1-jankul@alatek.krakow.pl> References: <20231208134838.49500-1-jankul@alatek.krakow.pl> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 08 Dec 2023 05:51:02 -0800 (PST) Make generic code generic. As descriptor-filling logic stays the same regardless of a dmaengine's type of transfer, it is possible to write the descriptor-filling function in a generic way, so that it can be used for every single type of transfer preparation callback. Signed-off-by: Jan Kuliga --- drivers/dma/xilinx/xdma.c | 101 +++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/drivers/dma/xilinx/xdma.c b/drivers/dma/xilinx/xdma.c index dbde6905acc7..c8ac047249bc 100644 --- a/drivers/dma/xilinx/xdma.c +++ b/drivers/dma/xilinx/xdma.c @@ -542,6 +542,43 @@ static void xdma_synchronize(struct dma_chan *chan) vchan_synchronize(&xdma_chan->vchan); } +/** + * xdma_fill_descs - Fill hardware descriptors with contiguous memory bl= ock addresses + * @sw_desc - tx descriptor state container + * @src_addr - Value for a ->src_addr field of a first descriptor + * @dst_addr - Value for a ->dst_addr field of a first descriptor + * @size - Total size of a contiguous memory block + * @filled_descs_num - Number of filled hardware descriptors for corresp= onding sw_desc + */ +static inline u32 xdma_fill_descs(struct xdma_desc *sw_desc, u64 src_add= r, + u64 dst_addr, u32 size, u32 filled_descs_num) +{ + u32 left =3D size, len, desc_num =3D filled_descs_num; + struct xdma_desc_block *dblk; + struct xdma_hw_desc *desc; + + dblk =3D sw_desc->desc_blocks + (desc_num / XDMA_DESC_ADJACENT); + desc =3D dblk->virt_addr; + desc +=3D desc_num & XDMA_DESC_ADJACENT_MASK; + do { + len =3D min_t(u32, left, XDMA_DESC_BLEN_MAX); + /* set hardware descriptor */ + desc->bytes =3D cpu_to_le32(len); + desc->src_addr =3D cpu_to_le64(src_addr); + desc->dst_addr =3D cpu_to_le64(dst_addr); + if (!(++desc_num & XDMA_DESC_ADJACENT_MASK)) + desc =3D (++dblk)->virt_addr; + else + desc++; + + src_addr +=3D len; + dst_addr +=3D len; + left -=3D len; + } while (left); + + return desc_num - filled_descs_num; +} + /** * xdma_prep_device_sg - prepare a descriptor for a DMA transaction * @chan: DMA channel pointer @@ -558,13 +595,10 @@ xdma_prep_device_sg(struct dma_chan *chan, struct s= catterlist *sgl, { struct xdma_chan *xdma_chan =3D to_xdma_chan(chan); struct dma_async_tx_descriptor *tx_desc; - u32 desc_num =3D 0, i, len, rest; - struct xdma_desc_block *dblk; - struct xdma_hw_desc *desc; struct xdma_desc *sw_desc; - u64 dev_addr, *src, *dst; + u32 desc_num =3D 0, i; + u64 addr, dev_addr, *src, *dst; struct scatterlist *sg; - u64 addr; for_each_sg(sgl, sg, sg_len, i) desc_num +=3D DIV_ROUND_UP(sg_dma_len(sg), XDMA_DESC_BLEN_MAX); @@ -584,32 +618,11 @@ xdma_prep_device_sg(struct dma_chan *chan, struct s= catterlist *sgl, dst =3D &addr; } - dblk =3D sw_desc->desc_blocks; - desc =3D dblk->virt_addr; - desc_num =3D 1; + desc_num =3D 0; for_each_sg(sgl, sg, sg_len, i) { addr =3D sg_dma_address(sg); - rest =3D sg_dma_len(sg); - - do { - len =3D min_t(u32, rest, XDMA_DESC_BLEN_MAX); - /* set hardware descriptor */ - desc->bytes =3D cpu_to_le32(len); - desc->src_addr =3D cpu_to_le64(*src); - desc->dst_addr =3D cpu_to_le64(*dst); - - if (!(desc_num & XDMA_DESC_ADJACENT_MASK)) { - dblk++; - desc =3D dblk->virt_addr; - } else { - desc++; - } - - desc_num++; - dev_addr +=3D len; - addr +=3D len; - rest -=3D len; - } while (rest); + desc_num +=3D xdma_fill_descs(sw_desc, *src, *dst, sg_dma_len(sg), des= c_num); + dev_addr +=3D sg_dma_len(sg); } tx_desc =3D vchan_tx_prep(&xdma_chan->vchan, &sw_desc->vdesc, flags); @@ -643,9 +656,9 @@ xdma_prep_dma_cyclic(struct dma_chan *chan, dma_addr_= t address, struct xdma_device *xdev =3D xdma_chan->xdev_hdl; unsigned int periods =3D size / period_size; struct dma_async_tx_descriptor *tx_desc; - struct xdma_desc_block *dblk; - struct xdma_hw_desc *desc; struct xdma_desc *sw_desc; + u64 addr, dev_addr, *src, *dst; + u32 desc_num; unsigned int i; /* @@ -670,21 +683,21 @@ xdma_prep_dma_cyclic(struct dma_chan *chan, dma_add= r_t address, sw_desc->period_size =3D period_size; sw_desc->dir =3D dir; - dblk =3D sw_desc->desc_blocks; - desc =3D dblk->virt_addr; + addr =3D address; + if (dir =3D=3D DMA_MEM_TO_DEV) { + dev_addr =3D xdma_chan->cfg.dst_addr; + src =3D &addr; + dst =3D &dev_addr; + } else { + dev_addr =3D xdma_chan->cfg.src_addr; + src =3D &dev_addr; + dst =3D &addr; + } - /* fill hardware descriptor */ + desc_num =3D 0; for (i =3D 0; i < periods; i++) { - desc->bytes =3D cpu_to_le32(period_size); - if (dir =3D=3D DMA_MEM_TO_DEV) { - desc->src_addr =3D cpu_to_le64(address + i * period_size); - desc->dst_addr =3D cpu_to_le64(xdma_chan->cfg.dst_addr); - } else { - desc->src_addr =3D cpu_to_le64(xdma_chan->cfg.src_addr); - desc->dst_addr =3D cpu_to_le64(address + i * period_size); - } - - desc++; + desc_num +=3D xdma_fill_descs(sw_desc, *src, *dst, period_size, desc_n= um); + addr +=3D i * period_size; } tx_desc =3D vchan_tx_prep(&xdma_chan->vchan, &sw_desc->vdesc, flags); -- 2.34.1