Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1395177rdh; Fri, 24 Nov 2023 11:26:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQE8r5lDbxgO5V4e/r08oPfsd7hhO1I7X8HA2ljtkeuyNpg0mj7jXWi31DQRiNoDfFC5TR X-Received: by 2002:a05:6a20:160b:b0:18c:1af0:ad56 with SMTP id l11-20020a056a20160b00b0018c1af0ad56mr1802875pzj.8.1700853997119; Fri, 24 Nov 2023 11:26:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700853997; cv=none; d=google.com; s=arc-20160816; b=lo7vBGrbEH+OUOroZivhCan0eDF7dGwgMhp7uhsnfHSXHBPCLbYEu0+XY4SnC9w+d1 Oo/EndC4yBupYY+Ujb8v9swHURbS6ty1TIpZ2lby8ugPFsmvMoHz9t7R5pfXCX/9Fn6F iIbhgtErT9vEpTcwciEURj4i3cwZeYsnjwO6KFH7tMGwXHIbG54+MW2Fd88uoY+QEjW+ VHr1T491dS1uwlARWxIdT3KX3gb6JjOrT1pUnnkmDTsOvupCAlFgcgdHutJJctK7a8TH nkVupU9RCcNEYCAiabHCFVxc8Fwm+YWSRpCbHblkBwFi9E3nwdDmXPpg4g7zkx3jkMCZ Zr5Q== 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=7vqJzCSKmffoYniIho4qYT8MOcj1+wJs//YsF1u/zCk=; fh=5oQXmq3tgP56Sn2YSHNFNW/thZW9bzO7oAoCayAstmg=; b=zjPvg602qaWvZWm+SIUXUlncRk7tzDpIUvrcOWQ7tUW8TO+L2QI45AF+IwEjd67uUz WeHgSo9RHM1RtNzG612cNGEt8oISG0m4FyEqqYWiIEpGHnMXWkhJGd9DB+y3U8xAhu9k z7KmJLspAhk2xJ/uvSeaEMkUFTxQZfmCc3oWOVV+X29BHp8ryXwCTfeTYOz3Y1wjMVDA xF49K0ylxl3OUxDN9FBYgKM6q1Q1A/mFfCV4JtpszuVY8TrLYoP5Vs74a+rpuXZk8gAN 3skQ6bvkUtGziRDsgqGc7mvnC7u/7tQtjp2du0aKRk1tqI7iRu/3Lxl4YQZDN7WzHumg dB1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alatek.krakow.pl header.s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3 header.b=CRCZpVGt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id y184-20020a6364c1000000b005bdd82f2821si4119709pgb.551.2023.11.24.11.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 11:26:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=fail header.i=@alatek.krakow.pl header.s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3 header.b=CRCZpVGt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 907B180B8DDF; Fri, 24 Nov 2023 11:26:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345982AbjKXT0R (ORCPT + 99 others); Fri, 24 Nov 2023 14:26:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345941AbjKXT0Q (ORCPT ); Fri, 24 Nov 2023 14:26:16 -0500 Received: from helios.alatek.com.pl (helios.alatek.com.pl [85.14.123.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E26B3596; Fri, 24 Nov 2023 11:26:22 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by helios.alatek.com.pl (Postfix) with ESMTP id 5669A2CE00D5; Fri, 24 Nov 2023 20:26:20 +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 8aBC_2sWDiXG; Fri, 24 Nov 2023 20:26:19 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by helios.alatek.com.pl (Postfix) with ESMTP id DDF102CE00D3; Fri, 24 Nov 2023 20:26:18 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 helios.alatek.com.pl DDF102CE00D3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alatek.krakow.pl; s=99EE5E86-D06A-11EC-BE24-DBCCD0A148D3; t=1700853978; bh=7vqJzCSKmffoYniIho4qYT8MOcj1+wJs//YsF1u/zCk=; h=From:To:Date:Message-Id:MIME-Version; b=CRCZpVGtj7ibXqSULhLgSaCATfP/8Kcl6ic7dfdDryItjWl5ejWoiC3CjLVJkX7BG NRXHZsLoSXgVBI9a5d6P7vxLkXqipK5/znT8c0DugE8sL826BA9+B+FDCq1Ba3lIvA uumnnJXDu7r7wUwJocfcO15XWJ7R3r1GEin/K3O5y9Dz00RYjLc298Xdg02jFtgOAt ZGAcn1uTZ1rPXka+3MMdb2xq6UGq1vgPK31qY0qjDSEUCfgHAmJyemhHjGSIFDg0WR KMuSNBclRG/qrsmCTsNnuWnYDkzVCZyZs4SiUy1qCVCjO3+/rv+aVC8Wa8+rKkXgcT MlkcUwfVf+BTA== 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 kvSdhwQaJYn8; Fri, 24 Nov 2023 20:26:18 +0100 (CET) Received: from ideapad.. (unknown [10.0.2.2]) by helios.alatek.com.pl (Postfix) with ESMTPSA id 955922CE00D1; Fri, 24 Nov 2023 20:26:18 +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, runtimeca39d@amd.com Cc: Jan Kuliga Subject: [PATCH v3 1/5] dmaengine: xilinx: xdma: Add transfer termination callbacks Date: Fri, 24 Nov 2023 20:25:54 +0100 Message-Id: <20231124192558.135004-2-jankul@alatek.krakow.pl> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231124192524.134989-1-jankul@alatek.krakow.pl> References: <20231124192524.134989-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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 24 Nov 2023 11:26:34 -0800 (PST) The xdma driver currently doesn't implement proper transfer termination callbacks. Therefore, there is no way to gracefully terminate the on-going DMA transactions. That is particularly useful for cyclic DMA transfers. Implement these callbacks. Signed-off-by: Jan Kuliga --- drivers/dma/xilinx/xdma-regs.h | 1 + drivers/dma/xilinx/xdma.c | 60 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/dma/xilinx/xdma-regs.h b/drivers/dma/xilinx/xdma-reg= s.h index e641a5083e14..1f17ce165f92 100644 --- a/drivers/dma/xilinx/xdma-regs.h +++ b/drivers/dma/xilinx/xdma-regs.h @@ -76,6 +76,7 @@ struct xdma_hw_desc { #define XDMA_CHAN_CONTROL_W1S 0x8 #define XDMA_CHAN_CONTROL_W1C 0xc #define XDMA_CHAN_STATUS 0x40 +#define XDMA_CHAN_STATUS_RC 0x44 #define XDMA_CHAN_COMPLETED_DESC 0x48 #define XDMA_CHAN_ALIGNMENTS 0x4c #define XDMA_CHAN_INTR_ENABLE 0x90 diff --git a/drivers/dma/xilinx/xdma.c b/drivers/dma/xilinx/xdma.c index 84a88029226f..b8de15e3dcfc 100644 --- a/drivers/dma/xilinx/xdma.c +++ b/drivers/dma/xilinx/xdma.c @@ -632,6 +632,64 @@ xdma_prep_dma_cyclic(struct dma_chan *chan, dma_addr= _t address, return NULL; } =20 +/** + * xdma_terminate_all - Halt the DMA channel + * @chan: DMA channel + */ +static int xdma_terminate_all(struct dma_chan *chan) +{ + int ret; + u32 val; + unsigned long flags; + struct xdma_chan *xchan =3D to_xdma_chan(chan); + struct xdma_device *xdev =3D xchan->xdev_hdl; + struct virt_dma_desc *vd; + LIST_HEAD(head); + + /* Clear the RUN bit to stop the transfer */ + ret =3D regmap_write(xdev->rmap, xchan->base + XDMA_CHAN_CONTROL_W1C, + CHAN_CTRL_RUN_STOP); + if (ret) + return ret; + + /* Clear the channel status register */ + ret =3D regmap_read(xdev->rmap, xchan->base + XDMA_CHAN_STATUS_RC, &val= ); + if (ret) + return ret; + + spin_lock_irqsave(&xchan->vchan.lock, flags); + + /* Don't care if there were no descriptors issued */ + vd =3D vchan_next_desc(&xchan->vchan); + if (vd) { + /* + * No need to delete the vd from the vc.desc_issued list, + * every desc list is going to be spliced into vc.desc_terminated + * and initialized anyway. + */ + dma_cookie_complete(&vd->tx); + vchan_terminate_vdesc(vd); + } + vchan_get_all_descriptors(&xchan->vchan, &head); + list_splice_tail(&head, &xchan->vchan.desc_terminated); + + xchan->busy =3D false; + spin_unlock_irqrestore(&xchan->vchan.lock, flags); + + return 0; +} + +/** + * xdma_synchronize - Synchronize current execution context to the DMA c= hannel + * @chan: DMA channel + */ +static void xdma_synchronize(struct dma_chan *chan) +{ + struct xdma_chan *xchan =3D to_xdma_chan(chan); + + vchan_synchronize(&xchan->vchan); +} + /** * xdma_device_config - Configure the DMA channel * @chan: DMA channel @@ -1093,6 +1151,8 @@ static int xdma_probe(struct platform_device *pdev) xdev->dma_dev.filter.mapcnt =3D pdata->device_map_cnt; xdev->dma_dev.filter.fn =3D xdma_filter_fn; xdev->dma_dev.device_prep_dma_cyclic =3D xdma_prep_dma_cyclic; + xdev->dma_dev.device_terminate_all =3D xdma_terminate_all; + xdev->dma_dev.device_synchronize =3D xdma_synchronize; =20 ret =3D dma_async_device_register(&xdev->dma_dev); if (ret) { --=20 2.34.1