From patchwork Tue Oct 31 10:45:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10034075 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 414B3600C5 for ; Tue, 31 Oct 2017 10:45:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4128D284B5 for ; Tue, 31 Oct 2017 10:45:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33E5228732; Tue, 31 Oct 2017 10:45:42 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 29CC8284B5 for ; Tue, 31 Oct 2017 10:45:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752411AbdJaKpk (ORCPT ); Tue, 31 Oct 2017 06:45:40 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:50827 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751894AbdJaKpj (ORCPT ); Tue, 31 Oct 2017 06:45:39 -0400 Received: by mail-qt0-f193.google.com with SMTP id d9so20063534qtd.7; Tue, 31 Oct 2017 03:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=a5leVE68//oueXYdJgk2u4MVwbAu0ni1bNc6Y3eRLio=; b=hQaVqygzo+Ulvjajiol5S/ghvJ0vobbAwyoZFHwtLXhClT7WHiEkWh9W3/VyEnnsUw r0CqrZdyC02CV1i2vwjvqkrkUsMUhq3IBLxbTJ1J4ipvi8r6O65HFD6tBRE5+RWPUvtk fjAnrv7ho0ThBnoWmaMPEhMe0zN5uW2ceJpaOWQ1O7DH82gO0ioTaVOSK8RGU5KRNKJK a8NbIEyRJ4+fJyCwEInzpQJw/ny27+B6SdxY2lTfavvt2wIa1y4uxarvM/MiqrVGiKxl EehLJ41O33UzYRKHz0K0c2EXLWAKwNPv5sG6NAYCHPvm5F83W0kIPCLZk+UcY59OCAck SUxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=a5leVE68//oueXYdJgk2u4MVwbAu0ni1bNc6Y3eRLio=; b=Q5KPewdf+iZZW/Xg/RC6DKqR7GtyAUccaa0CaMkmuvATCFIP8BuCxAPuLFX+54HlRU edb3PMOlP7dm9CT4v6+sndbzVbwL5GO+hGRghmuVWJm8Txf006hmyR6d/b4GDYpn1yz8 9jkme6bjPWoqRvrLOJI0X6Ne82nPfnv9reKbdzJmRfTE6NZv9OMhZQswG+FfdMj3PFN1 sOCWyN3yToOXLI9uE7Qj7Uf0U29MGK4KxNlTw17HVJF+YVDioFq7iHuqX2j5e6nek19B Dj52rhRr+gWoZeA27QJzAv7Z/7S63SG8WHAhIM984DS+5DtxLlkrbRZuzUOipvKoFTc+ 6VPg== X-Gm-Message-State: AMCzsaXaoJuSJ/ekQBbN5HDpTU7GZK9ywuJchGlztGzAkjAESCER0AQL +byOOCqunFwDJ14Qt02qfdRY+Pi3IoaOgS9cn7Y= X-Google-Smtp-Source: ABhQp+SE5m85OWg1TyxxXhSXLj8r6X019rzPWOYgfOl2yKtP6n8+fUfKFd4WNmz8LgyQb/I4wmkplxGDxj9MnC0bkHY= X-Received: by 10.200.53.200 with SMTP id l8mr2100177qtb.49.1509446738136; Tue, 31 Oct 2017 03:45:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.200.45.66 with HTTP; Tue, 31 Oct 2017 03:45:37 -0700 (PDT) In-Reply-To: <20171020061516.GM30097@localhost> References: <87bml4c5e0.wl%kuninori.morimoto.gx@renesas.com> <20171020061516.GM30097@localhost> From: Geert Uytterhoeven Date: Tue, 31 Oct 2017 11:45:37 +0100 X-Google-Sender-Auth: DzB40fs5pHwohzPF7gRdZ2zN7EA Message-ID: Subject: Re: [PATCH v3] dmaengine: rcar-dmac: use TCRB instead of TCR for residue To: Vinod Koul Cc: Kuninori Morimoto , Laurent Pinchart , Dan Williams , =?UTF-8?Q?Niklas_S=C3=B6derlund?= , dmaengine@vger.kernel.org, "linux-kernel@vger.kernel.org" , Hiroyuki Yokoyama Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Vinod, Morimoto-san, Yokoyama-san, On Fri, Oct 20, 2017 at 8:15 AM, Vinod Koul wrote: > On Thu, Oct 19, 2017 at 01:15:13AM +0000, Kuninori Morimoto wrote: >> From: Hiroyuki Yokoyama >> >> 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. > > Applied, thanks. This is now commit 847449f23dcbff68 ("dmaengine: rcar-dmac: use TCRB instead of TCR for residue") in slave-dma/next, and breaks serial console input on koelsch (shmobile_defconfig) and salvator-x (renesas_defconfig). Reverting that commit fixes the issue for me. Large serial console input (copy and pasting long lines) works, as that uses DMA. Small serial console input (typing) doesn't work. Apparently for the serial port, TCR contains the value we need (< 0x20), while TCRB always contains 0x20. Perhaps the code should use the minimum of both registers instead? For reference, below is the (gmail-whitespace-damaged) patch I used for debugging (note that you cannot print from rcar_dmac_chan_get_residue()!): Gr{oetje,eeting}s, Geert --- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds -- To unsubscribe from this list: send the line "unsubscribe dmaengine" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 50c4950050bea876..c2683294d1c735aa 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1237,6 +1237,10 @@ static int rcar_dmac_chan_terminate_all(struct dma_chan *chan) return 0; } +unsigned int different, same; +unsigned int diff_cnt; +u32 diff_tcr[100], diff_tcrb[100]; + static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, dma_cookie_t cookie) { @@ -1310,7 +1314,21 @@ 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; +{ +u32 tcr = rcar_dmac_chan_read(chan, RCAR_DMATCR); +u32 tcrb = rcar_dmac_chan_read(chan, RCAR_DMATCRB); +if (tcr == tcrb) { + same++; +} else { + different++; + if (diff_cnt < ARRAY_SIZE(diff_tcr)) { + diff_tcr[diff_cnt] = tcr; + diff_tcrb[diff_cnt] = tcrb; + diff_cnt++; + } +} + residue += tcrb << desc->xfer_shift; +} return residue; } diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index d5714deaaf928b3d..25df0288c85be9e0 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -1389,6 +1389,10 @@ static void work_fn_tx(struct work_struct *work) dma_async_issue_pending(chan); } +extern unsigned int different, same; +extern unsigned int diff_cnt; +extern u32 diff_tcr[100], diff_tcrb[100]; + static void rx_timer_fn(unsigned long arg) { struct sci_port *s = (struct sci_port *)arg; @@ -1402,6 +1406,13 @@ static void rx_timer_fn(unsigned long arg) u16 scr; dev_dbg(port->dev, "DMA Rx timed out\n"); +if (diff_cnt) { + unsigned int i; + + for (i = 0; i < diff_cnt; i++) + pr_info("tcr[%u] = 0x%x != tcrb[%u] = 0x%x (same %u, different %u)\n", i, diff_tcr[i], i, diff_tcrb[i], same, different); + diff_cnt = 0; +} spin_lock_irqsave(&port->lock, flags);