Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1705172rwd; Sun, 21 May 2023 04:46:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7DM/Mk2nur0bwtqur2m3lOlTNP5a19gTv9oIrhpr3x98uwqC17coljMVhqhO0hsSBvQGq3 X-Received: by 2002:a17:903:124b:b0:1ae:a44:841c with SMTP id u11-20020a170903124b00b001ae0a44841cmr8899039plh.42.1684669596855; Sun, 21 May 2023 04:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684669596; cv=none; d=google.com; s=arc-20160816; b=UepkV60t7WSyc9dizKcVNygLUaPmJkls7kZ3iDUUamSAhbYqbBbccZdA9WT9DChv/b rOpY9RtuyMyaEecuuOpYRFqYDDAYJq0PYywGvw+dUOMILy6SVHxjo75JQICv9qHq0FWR 4CXVkxIM/KhAWzPF3obcIy1yx4WN7oVkwh2XjQaw1Scc03/k8h6ceuOVXhvVs6UoN/n/ LoRWzjaDe7Wj7c3ij7UmM8ccoJGq2eCqY7md2/JoRK426rNw+VfraWxQMrT9ME5EQsKa MEPHRucwURjYwfLaKvAA83gtG4HQE8PuHMzaKoOTTXzfkR1rLEbQ3cvIYpGakV2TMpWu TDNQ== 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=wnYxM4InXVvn7k1FuTZnoBuLxYn2svTwQ5NvVnolpyw=; b=oKkWMCJMNe48JbjSheK5SuNRzv2u4aYgBthJ6diUPUNyYY7IKFLahjVl/aqTXZsl4V ciz0e5J/EIVY2Gs6uLIyNArgVvAXO0U6oOcvDq3cbIdpLfhNswhozowTMXbk72ejSFKD f+aQBMKg0ap4CjCuw5QxV0MfxHV34kuYkSZ1SzqnoUUdmuEHNUl/i/2LwjhioYFs37m1 6TI5kzXoCTcsfe3ZbpDZCTIFx8eWU+krs60rJqcw0C+Sh/detfPpH9afeqt3s/FDRGp0 oTEIUX/rpq//zDxhScFrlQidKBPlYIUGHJDXT+vA0KmQRy1XL/M8E68GPZUlHz/b/amn RYDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AvSff5Qr; 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 10-20020a170902c14a00b001ae4ba0af73si3021597plj.175.2023.05.21.04.46.22; Sun, 21 May 2023 04:46:36 -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=AvSff5Qr; 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 S231843AbjEUKrg (ORCPT + 99 others); Sun, 21 May 2023 06:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbjEUK1w (ORCPT ); Sun, 21 May 2023 06:27:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C84210EC; Sun, 21 May 2023 03:23:38 -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 A4E6F60E74; Sun, 21 May 2023 10:23:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A01AC433D2; Sun, 21 May 2023 10:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684664617; bh=wuVX/0YvZSuO5U9SVtkLtDjCssqIgDDcmJ1FV8R4DUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AvSff5QrbnWVP3y0CGYY3/phzmkCqWYAL7qL7/ZyeLhCrD5tXdwcj7HvafpUNDXEE yIhivZGr/ZmbayQikZ+dqPITjxqZUvHF3BRIJMfizara/A7zB/cFhnT/lTzm7jFL+Z 3jvG9acunlQQTnF+g3+L2Q7zRueUQXaMUg0n5hCzAvkPa6J7LaDPfW2AqSjHIxB0e7 jPHHQmzu/bSD1yScYIUk8LgqnBMjrx/WvFizDZKoH3fte7tw5DE4IxvKacr5VzPWQl hqFcFhsbZBfLOd9oGZyxrWtihuyELUNIpHfFDK+9Bhzwa3ilPhObIgRnW7i2wBG8X8 +YfeEt/5LisKA== From: Jisheng Zhang To: Eugeniy Paltsev , Vinod Koul Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 09/11] dmaengine: dw-axi-dmac: try best to get residue when tx is running Date: Sun, 21 May 2023 18:12:14 +0800 Message-Id: <20230521101216.4084-10-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230521101216.4084-1-jszhang@kernel.org> References: <20230521101216.4084-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,T_SCC_BODY_TEXT_LINE 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 f0bd8a7e3caf..f14fdfc9c7e9 100644 --- a/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +++ b/drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c @@ -312,6 +312,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; @@ -329,9 +330,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; } @@ -432,6 +439,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) @@ -1195,6 +1203,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.40.0