From patchwork Thu Nov 16 04:34:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 10060711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 59BA6604D3 for ; Thu, 16 Nov 2017 04:34:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CB2D2A729 for ; Thu, 16 Nov 2017 04:34:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 419B92A75B; Thu, 16 Nov 2017 04:34:23 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 623A92A729 for ; Thu, 16 Nov 2017 04:34:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933159AbdKPEeP (ORCPT ); Wed, 15 Nov 2017 23:34:15 -0500 Received: from relmlor3.renesas.com ([210.160.252.173]:34563 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759339AbdKPEeF (ORCPT ); Wed, 15 Nov 2017 23:34:05 -0500 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie2.idc.renesas.com with ESMTP; 16 Nov 2017 13:34:03 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 792BF79BC0; Thu, 16 Nov 2017 13:34:03 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.44,402,1505746800"; d="scan'208";a="262422234" Received: from mail-sg2apc01lp0245.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.245]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 16 Nov 2017 13:34:02 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Sf3SYNz1YYwJ2gnMXuJJK4DJ54wEPYNsUCbpcMoj53I=; b=JwxB0kxu3wY+wG+ubA1516t/fsRDGWZEdX5frpoHAULAlXPqy4gFYdHUHB/GvOSeoD6WSz6TqeVtNBMuo2g/nvnSiVN9U4AwWJQVLgUJAEpb6o/E7raZ2uQQ7WJm6AoZYQzlEo0bLC8bsrR1IO8fjWGgBSAqngURf5VydijxFQI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=kuninori.morimoto.gx@renesas.com; Received: from morimoto-PC.renesas.com (211.11.155.138) by KL1PR0601MB1879.apcprd06.prod.outlook.com (2603:1096:802:8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.239.5; Thu, 16 Nov 2017 04:34:00 +0000 Message-ID: <87mv3mg89g.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 2/2 v2] dmaengine: rcar-dmac: use TCRB instead of TCR for residue User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") To: Geert Uytterhoeven , Laurent Pinchart , Dan Williams , Vinod Koul Cc: Niklas =?ISO-8859-1?Q?S=F6derlund?= , dmaengine@vger.kernel.org, "linux-kernel@vger.kernel.org" , Hiroyuki Yokoyama In-Reply-To: <87po8ig8eg.wl%kuninori.morimoto.gx@renesas.com> References: <87po8ig8eg.wl%kuninori.morimoto.gx@renesas.com> Date: Thu, 16 Nov 2017 04:34:00 +0000 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: SG2PR0401CA0010.apcprd04.prod.outlook.com (2603:1096:3:1::20) To KL1PR0601MB1879.apcprd06.prod.outlook.com (2603:1096:802:8::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a616376a-2406-4118-bfb9-08d52cab4299 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603199); SRVR:KL1PR0601MB1879; X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1879; 3:Nd7Rq/ezR5WUZhCVJ6n9Gdok2mHWzGSSWXfXg4m8baPV+FsowBKNnvSySqiSnAPpgXcYjj/HuIpzvWxDNg3p/gmfvb7NqfJFBtEGVZCLSh/fVN7IbVUxwDvqbafIipd4AoXfWi3CpoxKZ86m/AqhEdDjD4+gCn6ejzbk+/bMN6b+jD/OYFAqgTH6fhLf67X1Mm16ZAamtltpAFEv5gYT+gQFiYeNrPSLQPY1S3Ww+zMWfH/z0TpZF0hHHtVZXJKb; 25:2aPRydO5EN4mCB9gjh7N6Kd/JK+gq/tvIvYIre7Tk/pcXbFqjWbSXSMJZRr2kiYDUV7y0OFL5I9EoLb1+h164wITVKd6EfcUW4NVhOPrthy62M2MkABcHAbDdT0D1aGzD+asiuJt/kpCCxnrImNzDXG0EFHTp8vYNvBbLI2CYXupS7KLD55yKFpaFDk1AhNWhLv+SzpPku1pS0XzUG8kKdzZCXYosb66r6VuQHYwwVptcKawXVIguvaFf3DJLEU2HC3vFcmrIEZhcJ0q0dwy6FAyA11F0lSkzrT8wTicqj/Y0EWOnTHCTbr3w3qv6S6pNLQakOzUuQbq6GaXUKQvOw==; 31:okA3Pc4W2ft8vieEPaMJiJ2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microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(100000703101)(100105400095)(3002001)(10201501046)(3231022)(6055026)(6041248)(20161123560025)(20161123564025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:KL1PR0601MB1879; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:KL1PR0601MB1879; X-Forefront-PRVS: 0493852DA9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(346002)(376002)(39860400002)(189002)(199003)(53416004)(36756003)(69596002)(25786009)(478600001)(316002)(54906003)(16586007)(2950100002)(5660300001)(6116002)(3846002)(50466002)(47776003)(66066001)(110136005)(23726003)(83506002)(97736004)(58126008)(305945005)(7736002)(68736007)(81156014)(33646002)(106356001)(6486002)(105586002)(81166006)(53936002)(86362001)(8676002)(16526018)(2906002)(189998001)(76176999)(101416001)(54356999)(50986999)(8936002)(4326008)(107886003)(16060500001); DIR:OUT; SFP:1102; SCL:1; SRVR:KL1PR0601MB1879; H:morimoto-PC.renesas.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: renesas.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; KL1PR0601MB1879; 23:y5MsgBoGJ6bf/gYEkmjYS7Y6hwFxhWLhpX7myXu?= =?us-ascii?Q?wAnMPJ4UNWCNpXTSw9SNZ9hHg0M8U7WrX5Qim2E/NEn9MVc4poMcajg5i+6k?= =?us-ascii?Q?k3c3JHpyLdsP4DuvzqN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k/uSyLuwC7E2/oQnyJgfuC7ej+WEeo0yFe+OagEkGzy+MtHce7aE6JS8WzSojXcRxZZ044ZLbg/cNGpLlsPaKLxZmaQCQjD/yYznD7770Ebg5e5cKLfoRNPHeRAcjsmN SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; KL1PR0601MB1879; 20:1lnE9+nW1yujkSHkSfMIk5GvNb4ds/dj1i6xAiXXTt5GhB542StuoyUvrZ2vjGs/ayDIhsYfIm3X4QjLQFVQqo9Gu0jd2mPkEKquRvhWXW/p+ZIFUQyUZR5GIh5N95rbmUhNxqMYeqK71UP0FVBhH400GLsAy/b14rgs605Rjf0= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Nov 2017 04:34:00.1976 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a616376a-2406-4118-bfb9-08d52cab4299 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB1879 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kuninori Morimoto SYS/RT/Audio DMAC includes independent data buffers for reading and writing. Therefore, the read transfer counter and write transfer counter have different values. TCR indicates read counter, and TCRB indicates write counter. The relationship is like below. TCR TCRB [SOURCE] -> [DMAC] -> [SINK] In the MEM_TO_DEV direction, what really matters is how much data has been written to the device. If the DMA is interrupted between read and write, then, the data doesn't end up in the destination, so shouldn't be counted. TCRB is thus the register we should use in this cases. In the DEV_TO_MEM direction, the situation is more complex. Both the read and write side are important. What matters from a data consumer point of view is how much data has been written to memory. On the other hand, if the transfer is interrupted between read and write, we'll end up losing data. It can also be important to report. In the MEM_TO_MEM direction, what matters is of course how much data has been written to memory from data consumer point of view. Here, because read and write have independent data buffers, it will take a while for TCR and TCRB to become equal. Thus we should check TCRB in this case, too. Thus, all cases we should check TCRB instead of TCR. Without this patch, Sound Capture has noise after PluseAudio support (= 07b7acb51d2 ("ASoC: rsnd: update pointer more accurate")), because the recorder will use wrong residue counter which indicates transferred from sound device, but in reality the data was not yet put to memory and recorder will record it. However, because DMAC is buffering data until it can be transferable size, TCRB might not be updated. For example, if consumer doesn't know how much data can be receaved, it requests enough size to DMAC. But in reality, it might receave very few data. In such case, DMAC just buffered it untile transferable size, and no TCRB updated. In such case, this buffered data will be transferred if CHCR::DE bit was cleared, and this is happen if rcar_dmac_chan_halt(). In other word, it happen when consumer called dmaengine_terminate_all(). Because of this behavior, it need to flush buffered data when it returns "residue" (= dmaengine_tx_status()). Otherwise, consumer might calculate wrong things if it called dmaengine_tx_status() and dmaengine_terminate_all() consecutively. Tested-by: Hiroyuki Yokoyama Tested-by: Ryo Kodama Signed-off-by: Kuninori Morimoto Tested-by: Geert Uytterhoeven --- drivers/dma/sh/rcar-dmac.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 16ebd5d..9cb85b2 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -761,6 +761,23 @@ static void rcar_dmac_chcr_de_barrier(struct rcar_dmac_chan *chan) dev_err(chan->chan.device->dev, "CHCR DE check error\n"); } +static void rcar_dmac_sync_tcr(struct rcar_dmac_chan *chan) +{ + u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); + + if (!(chcr & RCAR_DMACHCR_DE)) + return; + + /* set DE=0 and flush remaining data */ + rcar_dmac_chan_write(chan, RCAR_DMACHCR, (chcr & ~RCAR_DMACHCR_DE)); + + /* make sure all remaining data was fulshed */ + rcar_dmac_chcr_de_barrier(chan); + + /* back DE */ + rcar_dmac_chan_write(chan, RCAR_DMACHCR, chcr); +} + static void rcar_dmac_chan_halt(struct rcar_dmac_chan *chan) { u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR); @@ -1329,8 +1346,11 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, residue += chunk->size; } + if (desc->direction == DMA_DEV_TO_MEM) + rcar_dmac_sync_tcr(chan); + /* Add the residue for the current chunk. */ - residue += rcar_dmac_chan_read(chan, RCAR_DMATCR) << desc->xfer_shift; + residue += rcar_dmac_chan_read(chan, RCAR_DMATCRB) << desc->xfer_shift; return residue; }