Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp1684322rwe; Sat, 15 Apr 2023 04:15:27 -0700 (PDT) X-Google-Smtp-Source: AKy350bCH6LQWOJPFEufDwuDwftEcpTqFXJKa/NIHioinnpJSW1mfE+NxDNQqjEyrd4eyO2gBm3k X-Received: by 2002:a05:6a20:244b:b0:ef:1d4e:cf3e with SMTP id t11-20020a056a20244b00b000ef1d4ecf3emr459482pzc.50.1681557327083; Sat, 15 Apr 2023 04:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681557327; cv=none; d=google.com; s=arc-20160816; b=bvQB3ur5Tf7VuWMUHzLAis0HueZ+rRnDl96oc5Xca4CTeljNYqxbz1pJQ4XVPTKduI AWtEcWgrZNEgkOfv1UjO8udbD9hjZ+6Rrv1egXuxWgsHIv5q1T6Hzu8hVpUm2fLb2AO8 3dPTBoqUps0ud5/O5lRzZHTP35LHxf8sOO4FvABL9bW3FXInKfjIMH8anA01ber7FZAE 9VaFu/ktdtIZ0GkFrzYF7wAVFxauZXNdwNVuq7Mc3kGXJhZJpEbceJpZ5UOU3yV5eWzf ERIhPIWXIMRgMXlHy7HTbqCOD7QeQrm3uJHM6ScbbdSIVRywrWrn69E12pDmGfqfR4mA xf5A== 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; bh=Onr1c9wwoqj8oofKbwPgpp76A8KTznpIrNIIGtjTu+Q=; b=DzXFSOg3MLjfcMXYAqW5jCjgLGw22XyirfKZfoaYeK6dwmqB8TlVe1f+RtqDQwxJjk Wb5V34Zxaa50nYkdMbpuq4ixEUE5l3eQJBM/g7MMB3o4eCTWwyLoqtm3cmRh6Fdj0FNN FiUCEymvemf1VQkS5/TRpGgD5iGdzeUHKT3UlC+TZtN+pletyS0Pw1M2fxEx1rCUNmBb FFiQJ+vLEEsOI0Dk+BBeoON+Wljx95W4Zh+KXonnTYW4PX3SytKvv2H0raPIqiWrjxJv YqLAK+Pr8MqYzgmFE29akOCHqol72KJTN1KxdwvNup4HJJ7luJkZcWjnMfM3e/ylEkT6 YJtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oZm1bHl7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r21-20020a63d915000000b00518c878b1dbsi6614185pgg.356.2023.04.15.04.15.10; Sat, 15 Apr 2023 04:15:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oZm1bHl7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230270AbjDOKuJ (ORCPT + 99 others); Sat, 15 Apr 2023 06:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231133AbjDOKtw (ORCPT ); Sat, 15 Apr 2023 06:49:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F3894EF4; Sat, 15 Apr 2023 03:49:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ABDE5617E4; Sat, 15 Apr 2023 10:47:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FA17C433D2; Sat, 15 Apr 2023 10:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681555629; bh=eA2ZxLGWNR6IdxbFmS127kxHvHFaTkPGETvRqPfSGHI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oZm1bHl7XW9SxEIIxUAftIHPOTtnfokBHFkTXliyMMm0VDJq0rS4/lb9Rsl65rgQv w/kF0nIlnI2ayXKT6YTcwti6KXBoP6YpssS7xQXh4K4ezaQ9FWfRbeFqVRSVGFm1c2 i7PCsG4PiOii528r5pJfKaPemJRou+sHlcWhstzi8FEcBJbpjflb5NHBEYTTSMKgTp fUqsA82F/Q1KGdXYQstbf0DUXyim6zw8KbETAK8p5QAl5WmqWFpB1NbjyWJ9w/oOHL IXCBMOzDrTx/XypzjjKxQ/2Uyb5tEZdow9cTx8cYeFA0kiX0CgCP8Z92G5ezcjC/LF RV8LGYwuN8n8Q== From: Jisheng Zhang To: Eugeniy Paltsev , Vinod Koul Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/11] dmaengine: dw-axi-dmac: try best to get residue when tx is running Date: Sat, 15 Apr 2023 18:35:59 +0800 Message-Id: <20230415103601.2979-10-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230415103601.2979-1-jszhang@kernel.org> References: <20230415103601.2979-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When tx is running, vchan_find_desc() will return NULL, try our best to get the residue in this case. Signed-off-by: Jisheng Zhang --- drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c index a6e46cb66000..1c1b9574985a 100644 --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c @@ -305,6 +305,7 @@ dma_chan_tx_status(struct dma_chan *dchan, dma_cookie_t cookie, struct dma_tx_state *txstate) { struct axi_dma_chan *chan = dchan_to_axi_dma_chan(dchan); + struct axi_dma_desc *desc = NULL; struct virt_dma_desc *vdesc; enum dma_status status; u32 completed_length; @@ -322,9 +323,15 @@ dma_chan_tx_status(struct dma_chan *dchan, dma_cookie_t cookie, vdesc = vchan_find_desc(&chan->vc, cookie); if (vdesc) { - length = vd_to_axi_desc(vdesc)->length; - completed_blocks = vd_to_axi_desc(vdesc)->completed_blocks; - len = vd_to_axi_desc(vdesc)->hw_desc[0].len; + desc = vd_to_axi_desc(vdesc); + } else if (chan->desc && chan->desc->vd.tx.cookie == cookie) { + desc = chan->desc; + } + + if (desc) { + length = desc->length; + completed_blocks = desc->completed_blocks; + len = desc->hw_desc[0].len; completed_length = completed_blocks * len; bytes = length - completed_length; } @@ -425,6 +432,7 @@ static void axi_chan_block_xfer_start(struct axi_dma_chan *chan, axi_chan_irq_set(chan, irq_mask); axi_chan_enable(chan); + chan->desc = first; } static void axi_chan_start_first_queued(struct axi_dma_chan *chan) @@ -1188,6 +1196,7 @@ static int dma_chan_terminate_all(struct dma_chan *dchan) spin_unlock_irqrestore(&chan->vc.lock, flags); vchan_dma_desc_free_list(&chan->vc, &head); + chan->desc = NULL; dev_vdbg(dchan2dev(dchan), "terminated: %s\n", axi_chan_name(chan)); -- 2.39.2