From patchwork Tue Mar 5 05:56:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Behme X-Patchwork-Id: 10839055 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 15F47180E for ; Tue, 5 Mar 2019 05:56:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 063762BE2C for ; Tue, 5 Mar 2019 05:56:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE8DA2BE31; Tue, 5 Mar 2019 05:56:37 +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 66D202BE2D for ; Tue, 5 Mar 2019 05:56:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726200AbfCEF4f (ORCPT ); Tue, 5 Mar 2019 00:56:35 -0500 Received: from de-out1.bosch-org.com ([139.15.230.186]:52152 "EHLO de-out1.bosch-org.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfCEF4f (ORCPT ); Tue, 5 Mar 2019 00:56:35 -0500 Received: from si0vm1947.rbesz01.com (unknown [139.15.230.188]) by si0vms0217.rbdmz01.com (Postfix) with ESMTPS id 44D5k90ybDz4f3kZ2; Tue, 5 Mar 2019 06:56:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1551765393; bh=NJEzbVtRLgM7qYE9X5B0j8kwymv1uaTDWBadZxvwBis=; l=10; h=From:From:Reply-To:Sender; b=dMWSHP4jO9XTBPMCwxg5p4MDCTGBWm4kb70u41KOscP8yoj0YXJ+gS9SeIQWKxjqq d09vuRcKyzXvJoTjtSsLlNQt3cvcie3TgIX7pgWBaBXfaBN1D5jFSqTWlw5RNoBDqX Ta+iWDREELVr6QaeX/bmtvfkTkA5Rh0SkoNT6fqE= Received: from fe0vm1740.rbesz01.com (unknown [10.58.172.176]) by si0vm1947.rbesz01.com (Postfix) with ESMTPS id 44D5k90WyXz6CjQfJ; Tue, 5 Mar 2019 06:56:33 +0100 (CET) X-AuditID: 0a3aad14-3dbff70000000792-42-5c7e0f9051ba 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 fe0vm1740.rbesz01.com (SMG Outbound) with SMTP id 60.EC.01938.09F0E7C5; Tue, 5 Mar 2019 06:56:32 +0100 (CET) Received: from SI-HUB2000.de.bosch.com (si-hub2000.de.bosch.com [10.4.103.108]) by fe0vm1652.rbesz01.com (Postfix) with ESMTPS id 44D5k85RJXzQ2v; Tue, 5 Mar 2019 06:56:32 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by SI-HUB2000.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 15.1.1713.5; Tue, 5 Mar 2019 06:56:32 +0100 From: Dirk Behme To: CC: , , , , , , , Hiroyuki Yokoyama , Subject: [PATCH v2 1/2] dmaengine: sh: rcar-dmac: With cyclic DMA residue 0 is valid Date: Tue, 5 Mar 2019 06:56:27 +0100 Message-ID: <20190305055628.11826-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: H4sIAAAAAAAAA22Sf0wTZxjHeX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vd3P7u97d5eoWLwwuXe5Lc3Zu8aXD5asI+d71Efa+zDyI7MHDgeaFD/8dbQ Q1tA5rJ0tDz1WtPIqdjDm98bDqr60//tgNKWhEuXXHHb7RfbjrQ6+u5ey+173WOj1Ve1682r +K+9aT8ljvJr02/tzzlxhZYLBjZrDcYL7H/ol6MacAQAAA== 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 Changes in v2: None 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 Tue Mar 5 05:56:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Behme X-Patchwork-Id: 10839059 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 1E1AE17E4 for ; Tue, 5 Mar 2019 05:56:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FA442BE2C for ; Tue, 5 Mar 2019 05:56:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0373A2BE2D; Tue, 5 Mar 2019 05:56:40 +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 3C1212BE31 for ; Tue, 5 Mar 2019 05:56:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726277AbfCEF4h (ORCPT ); Tue, 5 Mar 2019 00:56:37 -0500 Received: from de-out1.bosch-org.com ([139.15.230.186]:45646 "EHLO de-out1.bosch-org.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725909AbfCEF4h (ORCPT ); Tue, 5 Mar 2019 00:56:37 -0500 X-Greylist: delayed 79205 seconds by postgrey-1.27 at vger.kernel.org; Tue, 05 Mar 2019 00:56:34 EST Received: from fe0vm1650.rbesz01.com (unknown [139.15.230.188]) by fe0vms0186.rbdmz01.com (Postfix) with ESMTPS id 44D5k91jlxz1XLFjj; Tue, 5 Mar 2019 06:56:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=de.bosch.com; s=2015-01-21; t=1551765393; bh=uzfkAeBUABvAjefBm6TuwCwstgh+jM8v7OZAw7mZ6fo=; l=10; h=From:From:Reply-To:Sender; b=xAHg6EQYNz23Ytf8oKYHOO7rsHG77Bzmv+bb7IU245kOCYnWxRlNw+HvwiUKDcZDM dFmMp6wtRPYh3cHq2nbJLShE2t3C7nZGulKc7OxW9b1YkxR6Oo9FpXmiRJYmyj899l clzwMwMv4Y78HFOwHraytAynS1xZOgcNIno+nptk= Received: from si0vm2083.rbesz01.com (unknown [10.58.172.176]) by fe0vm1650.rbesz01.com (Postfix) with ESMTPS id 44D5k91MSZz1Cy; Tue, 5 Mar 2019 06:56:33 +0100 (CET) X-AuditID: 0a3aad17-68bff70000004a10-b1-5c7e0f91428c Received: from fe0vm1651.rbesz01.com ( [10.58.173.29]) (using TLS with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by si0vm2083.rbesz01.com (SMG Outbound) with SMTP id 5B.E2.18960.19F0E7C5; Tue, 5 Mar 2019 06:56:33 +0100 (CET) Received: from SI-HUB2000.de.bosch.com (si-hub2000.de.bosch.com [10.4.103.108]) by fe0vm1651.rbesz01.com (Postfix) with ESMTPS id 44D5k870DxzQn5; Tue, 5 Mar 2019 06:56:32 +0100 (CET) Received: from HI-Z0EVG.hi.de.bosch.com (10.34.218.219) by SI-HUB2000.de.bosch.com (10.4.103.108) with Microsoft SMTP Server id 15.1.1713.5; Tue, 5 Mar 2019 06:56:32 +0100 From: Dirk Behme To: CC: , , , , , , , Subject: [PATCH 2/2] dmaengine: sh: rcar-dmac: Fix glitch in dmaengine_tx_status Date: Tue, 5 Mar 2019 06:56:28 +0100 Message-ID: <20190305055628.11826-2-dirk.behme@de.bosch.com> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20190305055628.11826-1-dirk.behme@de.bosch.com> References: <20190305055628.11826-1-dirk.behme@de.bosch.com> MIME-Version: 1.0 X-Originating-IP: [10.34.218.219] X-Brightmail-Tracker: H4sIAAAAAAAAA22Sa0xTZxzG+55z2p52HDw93P60ItmZ26JTB3hJozh3zRq/yDKzD0sNFjnS Zr2QcwqjNDMElSBKBkswaxs7ES8Iuk4IiThlsxtZywQvLDgERiQ6kRBM1iFrJrJzKNh+2Lcn /+f/e5/3ffKSOPNYqSUt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vUnc0SgtmUuxbnBdN/GjfSB3wEAAA= 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 Changes in v2: Switch goto/retry to for loop drivers/dma/sh/rcar-dmac.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 2ea59229d7f5..cceddc7099b0 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1282,6 +1282,9 @@ 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 chcrb; + unsigned int tcrb; + unsigned int i; if (!desc) return 0; @@ -1329,6 +1332,24 @@ 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. + * Trying it 3 times should be enough: Initial read, retry, retry + * for the paranoid. + */ + for (i = 0; i < 3; i++) { + chcrb = rcar_dmac_chan_read(chan, RCAR_DMACHCRB) & + RCAR_DMACHCRB_DPTR_MASK; + tcrb = rcar_dmac_chan_read(chan, RCAR_DMATCRB); + /* Still the same? */ + if (chcrb == (rcar_dmac_chan_read(chan, RCAR_DMACHCRB) & + RCAR_DMACHCRB_DPTR_MASK)) + break; + } + WARN_ONCE(i >= 3, "residue might be not continuous!"); + /* * In descriptor mode the descriptor running pointer is not maintained * by the interrupt handler, find the running descriptor from the @@ -1336,8 +1357,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 +1375,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; }