From patchwork Mon Mar 4 07:56:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Behme X-Patchwork-Id: 10837435 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 289961390 for ; Mon, 4 Mar 2019 08:04:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CDD02936C for ; Mon, 4 Mar 2019 08:04:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F145129C77; Mon, 4 Mar 2019 08:04:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F10B2936C for ; Mon, 4 Mar 2019 08:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726032AbfCDIEk (ORCPT ); Mon, 4 Mar 2019 03:04:40 -0500 Received: from de-deferred2.bosch-org.com ([139.15.180.217]:55012 "EHLO de-deferred2.bosch-org.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725997AbfCDIEj (ORCPT ); Mon, 4 Mar 2019 03:04:39 -0500 X-Greylist: delayed 487 seconds by postgrey-1.27 at vger.kernel.org; Mon, 04 Mar 2019 03:04:38 EST Received: from de-out1.bosch-org.com (unknown [139.15.180.215]) by fe0vms0193.rbdmz01.com (Postfix) with ESMTPS id 44CXR23ZWjz2kj; Mon, 4 Mar 2019 08:56:30 +0100 (CET) Received: from si0vm1947.rbesz01.com (unknown [139.15.230.188]) by fe0vms0186.rbdmz01.com (Postfix) with ESMTPS id 44CXR02Pzzz1XLFjP; Mon, 4 Mar 2019 08:56:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1551686188; bh=NJEzbVtRLgM7qYE9X5B0j8kwymv1uaTDWBadZxvwBis=; l=10; h=From:From:Reply-To:Sender; b=ZS41g9FgLCOL9iQ4bOcyewKI058uWyegh91psCpFr95yV1urib4rNO4LqGpJomVmZ ilMsoS70tmmiYFR9QRNl02qvPwtCSvcL+jvj53/0pdA8lPaKeV0JcHbUYRcQ1uCYJK lk5XXfRSI//4kpE0rhEsxlVdnJswLLLnj3XyHG20= Received: from fe0vm02900.rbesz01.com (unknown [10.58.172.176]) by si0vm1947.rbesz01.com (Postfix) with ESMTPS id 44CXR01t5rz6CjTc1; Mon, 4 Mar 2019 08:56:28 +0100 (CET) X-AuditID: 0a3aad0c-805ff7000000255a-a4-5c7cda2c538d Received: from fe0vm1652.rbesz01.com ( [10.58.173.29]) (using TLS with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by fe0vm02900.rbesz01.com (SMG Outbound) with SMTP id 6C.9A.09562.C2ADC7C5; Mon, 4 Mar 2019 08:56:28 +0100 (CET) Received: from FE-HUB2000.de.bosch.com (unknown [10.4.103.109]) by fe0vm1652.rbesz01.com (Postfix) with ESMTPS id 44CXQz6zcQzQ2l; Mon, 4 Mar 2019 08:56:27 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.1713.5; Mon, 4 Mar 2019 08:56:19 +0100 From: Dirk Behme To: CC: , , , , , , , Hiroyuki Yokoyama , Subject: [PATCH 1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid Date: Mon, 4 Mar 2019 08:56:09 +0100 Message-ID: <20190304075610.10810-1-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.20.0 MIME-Version: 1.0 X-Originating-IP: [10.34.218.219] X-Brightmail-Tracker: H4sIAAAAAAAAA22SbUxbZRTHeXrbu0vTi5cLg7MOcF6NJmxgYZpVJURlurpl6pyJBsu0yKWt 9oXcW3Awog268TLJCrMQKDA0THkTXbsXyge21eDAjLGMiW7pGiUibExi0jGEhem9FNZ+8Nt5 /uf8zv95/nkIjA6sUxJGi43lLDoTg8ul8me/TU7bcr1cq7o3hat7nMsydaurHqnPXEtX11X4 pepTN+ck6hsjW9TtJyaR2usfxp4nNHWjaRpXVZNM4+6uxjXT4wu45u7FOqkm6E55Hc+VZxWw JmMJyz2Z/Z7c8NXyl3hRS/T+swP1Ujv6c10NiiaAegqGpyslYk1TlRIY/SKvBsmFugfBWGej LHT4DsGhywO4OIVTqeB1VK3Q8dQTsHzjCiYOYdRpCRzs/EEqNuKoPXBp1reyVko9Bo2eb2Ri TVJZEJj+Gg9ZPwwNPTWSkB4LI01/rLCYoH96yoWFaoDzMzNYaP4R6G32yhzooeYIpDkCaY5A 2hHWjRIKWVWJWZX5jEqVzuWzfJkqI/19q9mNQoEr+tFQh96HKAIxCrLtXLmWlulK+FKzDz1N SJj15HShIMXkWwtKDTre8C5XbGJ5RkkmXd6ppeMeyHxxvtnI80arxYeAwJh4cnBc4MgCXWkZ y1lDmA9tJKRMIqknXtPSlF5nYz9k2SKWW+s+RxAMkEu/CGAsx+rZ/YVGk22tzSSTKCoqik6I 7ETaSohoH9pKKATvw7+K3nyRzswb9av4hhBOr6lh9CeUQ/x+MNiK0VKL1cIqE8nvxStQ4qSh 2PLgBsokcvGlA1p6fUQjvOUWuoaEDOPIN0RzhfCvw95AbhTjil0Vw1DmcYGhBmXQUTuJoK1/ HoGz9jcc7p+uIODOySYCLnpGSZivuh8DJ4/ZKXAvHKMg8PcJGqp7B+IhUDWUCFen5pPg9uxI Mlz1tKRAYNm7CZzHFzeDf2ImDQK1ixng/tGZCX2Oo1vhbO3P2+DSwl/ZMFx9/UVhVcN2qJ+t 2wnevrHdcKSv8VX4x337TfA3dObB59VTeRC4s7TvlhCsRAg2OH5ADNams/1PsKtq+HVKO3Je QL15rm0f2x/9QLa5S2Efbrwb/Gi+Zs+A1uSpYBVzO84zcz0Tm3bsPVr+SmugK/aF7r7SKzk3 D2d36d/Jzd1uw4MpL/8bNfa2Z9eio2migxvae05RljoZ1etva40rSklwtQf8+fyGmE8c9w59 dkazr2WQi+lfeutCZZZK5Xg8J4GR8gZdRirG8br/AHj1p2lxBAAA Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Having a cyclic DMA, a residue 0 is not an indication of a completed DMA. In case of cyclic DMA make sure that dma_set_residue() is called and with this a residue of 0 is forwarded correctly to the caller. Fixes: 3544d2878817 ("dmaengine: rcar-dmac: use result of updated get_residue in tx_status") Signed-off-by: Dirk Behme Signed-off-by: Achim Dahlhoff Signed-off-by: Hiroyuki Yokoyama Cc: # v4.8+ --- Note: Patch done against mainline v5.0 drivers/dma/sh/rcar-dmac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 2b4f25698169..2ea59229d7f5 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1378,7 +1378,7 @@ static enum dma_status rcar_dmac_tx_status(struct dma_chan *chan, spin_unlock_irqrestore(&rchan->lock, flags); /* if there's no residue, the cookie is complete */ - if (!residue) + if (!residue && !rchan->desc.running->cyclic) return DMA_COMPLETE; dma_set_residue(txstate, residue); From patchwork Mon Mar 4 07:56:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Behme X-Patchwork-Id: 10837433 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1317F180E for ; Mon, 4 Mar 2019 08:04:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 006D92936C for ; Mon, 4 Mar 2019 08:04:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E51B529C95; Mon, 4 Mar 2019 08:04:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8321329438 for ; Mon, 4 Mar 2019 08:04:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726038AbfCDIEl (ORCPT ); Mon, 4 Mar 2019 03:04:41 -0500 Received: from de-deferred1.bosch-org.com ([139.15.180.216]:57948 "EHLO de-deferred1.bosch-org.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726001AbfCDIEk (ORCPT ); Mon, 4 Mar 2019 03:04:40 -0500 Received: from de-out1.bosch-org.com (unknown [139.15.180.215]) by si0vms0224.rbdmz01.com (Postfix) with ESMTPS id 44CXR94SlZz2mB; Mon, 4 Mar 2019 08:56:37 +0100 (CET) Received: from fe0vm1649.rbesz01.com (unknown [139.15.230.188]) by si0vms0216.rbdmz01.com (Postfix) with ESMTPS id 44CXR80ygXz1XLG75; Mon, 4 Mar 2019 08:56:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1551686196; bh=uzfkAeBUABvAjefBm6TuwCwstgh+jM8v7OZAw7mZ6fo=; l=10; h=From:From:Reply-To:Sender; b=AlmnSkPHaWa004eA7u1ViBeUto4PSvnEw/7hmMcwVLm7BNaWgdvoXqvJwumQu4Whp ktOSEaCxDli5hdnAd1BWt1PBlbSoxy/Pg27A3Zs7jUcrnqljlz/ifiJij2+pQIyDUA DO/7k1QA4tGUZpAZ/N2d3gS48Nz0WdSEP5/EoM/w= Received: from fe0vm1740.rbesz01.com (unknown [10.58.172.176]) by fe0vm1649.rbesz01.com (Postfix) with ESMTPS id 44CXR80FHHz309; Mon, 4 Mar 2019 08:56:36 +0100 (CET) X-AuditID: 0a3aad14-3f3ff70000000792-28-5c7cda339568 Received: from si0vm1950.rbesz01.com ( [10.58.173.29]) (using TLS with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by fe0vm1740.rbesz01.com (SMG Outbound) with SMTP id 84.31.01938.33ADC7C5; Mon, 4 Mar 2019 08:56:35 +0100 (CET) Received: from FE-HUB2000.de.bosch.com (fe-hub2000.de.bosch.com [10.4.103.109]) by si0vm1950.rbesz01.com (Postfix) with ESMTPS id 44CXR750jlz4bp; Mon, 4 Mar 2019 08:56:35 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by FE-HUB2000.de.bosch.com (10.4.103.109) with Microsoft SMTP Server id 15.1.1713.5; Mon, 4 Mar 2019 08:56:26 +0100 From: Dirk Behme To: CC: , , , , , , , Subject: [PATCH 2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status Date: Mon, 4 Mar 2019 08:56:10 +0100 Message-ID: <20190304075610.10810-2-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20190304075610.10810-1-dirk.behme@de.bosch.com> References: <20190304075610.10810-1-dirk.behme@de.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.34.218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kH1+sk3b+T7HL0/jX yetQbd+FE76ig/deHi6MLPhyHO/eD9LyTUfWJF0/YtAL8kqyj/4syFW/ecvXH3q131VwR1HW XBVpKFIX77SoPt/Rm9u6pfPjY+Nd3t9Wn874Ye521Sv7q6oLj71Ynv1N6K/eh63GnMCHOWXT e+ipN3blfrSx2/e6zPaOYa5aP15ctvsWtuULpZA10ep1mIOl/wM7LuNHfwQAAA== Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Achim Dahlhoff The tx_status poll in the rcar_dmac driver reads the status register which indicates which chunk is busy (DMACHCRB). Afterwards the point inside the chunk is read from DMATCRB. It is possible that the chunk has changed between the two reads. The result is a non-monotonous increase of the residue. Fix this by introducing a 'safe read' logic. Fixes: 73a47bd0da66 ("dmaengine: rcar-dmac: use TCRB instead of TCR for residue") Signed-off-by: Achim Dahlhoff Signed-off-by: Dirk Behme Cc: # v4.16+ --- Note: Patch done against mainline v5.0 drivers/dma/sh/rcar-dmac.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 2ea59229d7f5..b8afd7f4e07c 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1273,6 +1273,13 @@ static int rcar_dmac_chan_terminate_all(struct dma_chan *chan) return 0; } +static inline +unsigned int rcar_dmac_read_chcrb_mask(struct rcar_dmac_chan *chan) +{ + return rcar_dmac_chan_read(chan, RCAR_DMACHCRB) & + RCAR_DMACHCRB_DPTR_MASK; +} + static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, dma_cookie_t cookie) { @@ -1282,6 +1289,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, enum dma_status status; unsigned int residue = 0; unsigned int dptr = 0; + unsigned int tcrb, chcrb; if (!desc) return 0; @@ -1329,6 +1337,17 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, return 0; } + /* + * We need to read two registers. + * Make sure the control register does not skip to next chunk + * while reading the counter. + */ + retry: + chcrb = rcar_dmac_read_chcrb_mask(chan); + tcrb = rcar_dmac_chan_read(chan, RCAR_DMATCRB); + if (chcrb != rcar_dmac_read_chcrb_mask(chan)) /* Still the same? */ + goto retry; + /* * In descriptor mode the descriptor running pointer is not maintained * by the interrupt handler, find the running descriptor from the @@ -1336,8 +1355,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, * mode just use the running descriptor pointer. */ if (desc->hwdescs.use) { - dptr = (rcar_dmac_chan_read(chan, RCAR_DMACHCRB) & - RCAR_DMACHCRB_DPTR_MASK) >> RCAR_DMACHCRB_DPTR_SHIFT; + dptr = chcrb >> RCAR_DMACHCRB_DPTR_SHIFT; if (dptr == 0) dptr = desc->nchunks; dptr--; @@ -1355,7 +1373,7 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, } /* Add the residue for the current chunk. */ - residue += rcar_dmac_chan_read(chan, RCAR_DMATCRB) << desc->xfer_shift; + residue += tcrb << desc->xfer_shift; return residue; }