Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp70619ybj; Thu, 19 Sep 2019 10:51:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzxMiXqe61d3rpeV3EqA5WcM3WV5l4HLOh2dwBNegpdJoZu8Ra7VCJPm3IP9Jc9K2Mswfa3 X-Received: by 2002:a50:f09d:: with SMTP id v29mr17073038edl.4.1568915477355; Thu, 19 Sep 2019 10:51:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568915477; cv=none; d=google.com; s=arc-20160816; b=rheZQ98FX9kQFKdACbzLV9lT0v3dRTEKN9pscQBiga+OwFtmYcKV1uD8Ko+NhOK35E s/EAEnQwi0o1oBGUWr3mS65S8Y08vY8BS9Uqvagr7n521t289Y/X1TBNEdi2NS6rpCWk ByrEDdeugXj01u9BLU4kwmM7XQ6aPDLkUQ3VomkXBAqZDjzyHX6MOWCx5/iblODLwYyu P7dzM9qEt5iLbwE00rLrrTceOztzRikoWqtbzlfVV4aqk2z8o9Wi45vjkZ3OypN2IE8T trGBg1Asfp5HBW2T/49Yoq4+gsNq7xR9muZPGtGywoK2w+VO4Ik5O52MvS7uvpw+uj07 D7qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id; bh=Rb29Vmfc/7Ikb0cp54b3MmKJARpSadr7wfNnKql0MWY=; b=t+52WdTptBto5gI4DDF9d772824LG7PDxutJuEzP9V6vIbPkhPdiJmckL65kPKshN2 RTaBvRDOkUhUMFS5Bhci4pKg5t0dbh8Tobi6wWABI4EvDwnpCkEQcwolwIIxy2NhZQPT DSnb94EV7yMKgUb1U2dtLtLb5CNn8bG9oKHjXCj33hynuKZaz0Newy5SRwmYMMtkEE67 iM8R8dhPaFRgO+EWFaZA4A/GvKOsHpCj24WHrWuLdcqYoYSMIr7SiT2VBzsqsVDdBcV6 pwtI9jh65nxwOzGkofhZCGvJRM2/kWHKRD2aYTkXUhqnk4CzswgC0e4pu5qOnLS0Z4ZL u0Gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w55si5849744eda.15.2019.09.19.10.50.53; Thu, 19 Sep 2019 10:51:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391193AbfISPTo (ORCPT + 99 others); Thu, 19 Sep 2019 11:19:44 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:42347 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391183AbfISPTn (ORCPT ); Thu, 19 Sep 2019 11:19:43 -0400 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iAyDd-0003JN-7Q; Thu, 19 Sep 2019 17:19:41 +0200 Received: from localhost ([127.0.0.1]) by ptx.hi.pengutronix.de with esmtp (Exim 4.89) (envelope-from ) id 1iAyDc-00018D-7s; Thu, 19 Sep 2019 17:19:40 +0200 Message-ID: Subject: Re: [PATCH v4 2/3] dmaengine: imx-sdma: fix dma freezes From: Jan =?ISO-8859-1?Q?L=FCbbe?= To: Philipp Puschmann , linux-kernel@vger.kernel.org Cc: fugang.duan@nxp.com, festevam@gmail.com, s.hauer@pengutronix.de, vkoul@kernel.org, linux-imx@nxp.com, kernel@pengutronix.de, dan.j.williams@intel.com, yibin.gong@nxp.com, shawnguo@kernel.org, dmaengine@vger.kernel.or, linux-arm-kernel@lists.infradead.org, l.stach@pengutronix.de Date: Thu, 19 Sep 2019 17:19:39 +0200 In-Reply-To: <20190919142942.12469-3-philipp.puschmann@emlix.com> References: <20190919142942.12469-1-philipp.puschmann@emlix.com> <20190919142942.12469-3-philipp.puschmann@emlix.com> Content-Type: multipart/mixed; boundary="=-sqfX9QZyaTnBJ7ZxOgmw" User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: jlu@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-sqfX9QZyaTnBJ7ZxOgmw Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Hi Philipp, see below... On Thu, 2019-09-19 at 16:29 +0200, Philipp Puschmann wrote: > For some years and since many kernel versions there are reports that the > RX UART SDMA channel stops working at some point. The workaround was to > disable DMA for RX. This commit tries to fix the problem itself. > > Due to its license i wasn't able to debug the sdma script itself but it > somehow leads to blocking the scheduling of the channel script when a > running sdma script does not find any free descriptor in the ring to put > its data into. > > If we detect such a potential case we manually restart the channel. > > As sdmac->desc is constant we can move desc out of the loop. > > Fixes: 1ec1e82f2510 ("dmaengine: Add Freescale i.MX SDMA support") > Signed-off-by: Philipp Puschmann > Reviewed-by: Lucas Stach > --- > > Changelog v4: > - fixed the fixes tag > > Changelog v3: > - use correct dma_wmb() instead of dma_wb() > - add fixes tag > > Changelog v2: > - clarify comment and commit description > > drivers/dma/imx-sdma.c | 21 +++++++++++++++++---- > 1 file changed, 17 insertions(+), 4 deletions(-) > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c > index e029a2443cfc..a32b5962630e 100644 > --- a/drivers/dma/imx-sdma.c > +++ b/drivers/dma/imx-sdma.c > @@ -775,21 +775,23 @@ static void sdma_start_desc(struct sdma_channel *sdmac) > static void sdma_update_channel_loop(struct sdma_channel *sdmac) > { > struct sdma_buffer_descriptor *bd; > - int error = 0; > - enum dma_status old_status = sdmac->status; > + struct sdma_desc *desc = sdmac->desc; > + int error = 0, cnt = 0; > + enum dma_status old_status = sdmac->status; > > /* > * loop mode. Iterate over descriptors, re-setup them and > * call callback function. > */ > - while (sdmac->desc) { > - struct sdma_desc *desc = sdmac->desc; > + while (desc) { > > bd = &desc->bd[desc->buf_tail]; > > if (bd->mode.status & BD_DONE) > break; > > + cnt++; > + > if (bd->mode.status & BD_RROR) { > bd->mode.status &= ~BD_RROR; > sdmac->status = DMA_ERROR; > @@ -822,6 +824,17 @@ static void sdma_update_channel_loop(struct sdma_channel *sdmac) > if (error) > sdmac->status = old_status; > } > + > + /* In some situations it may happen that the sdma does not found any ^ hasn't > + * usable descriptor in the ring to put data into. The channel is > + * stopped then. While there is no specific error condition we can > + * check for, a necessary condition is that all available buffers for > + * the current channel have been written to by the sdma script. In > + * this case and after we have made the buffers available again, > + * we restart the channel. > + */ Are you sure we can't miss cases where we only had to make some buffers available again, but the SDMA already ran out of buffers before? A while ago, I was debugging a similar issue triggered by receiving data with a wrong baud rate, which leads to all descriptors being marked with the error flag very quickly (and the SDMA stalling). I noticed that you can check if the channel is still running by checking the SDMA_H_STATSTOP register & BIT(sdmac->channel). I also added a flag for the sdmac->flags field to allow stopping the channel from the callback (otherwise it would enable the channel again). Attached is my current version of that patch for reference. > + if (cnt >= desc->num_bd) > + sdma_enable_channel(sdmac->sdma, sdmac->channel); > } > > static void mxc_sdma_handle_channel_normal(struct sdma_channel *data) --=-sqfX9QZyaTnBJ7ZxOgmw Content-Disposition: attachment; filename*0=0001-dmaengine-imx-sdma-restart-stopped-cyclic-transfers.patc; filename*1=h Content-Type: text/x-patch; name="0001-dmaengine-imx-sdma-restart-stopped-cyclic-transfers.patch"; charset="UTF-8" Content-Transfer-Encoding: base64 RnJvbSA3M2Q3ZGNmODRkYWM1NTEyYzUwNDQ4ZmY2YWRmMDg0ZjFhOWJkNmY5IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBKYW4gTHVlYmJlIDxqbHVAcGVuZ3V0cm9uaXguZGU+CkRhdGU6 IFR1ZSwgMTYgQXByIDIwMTkgMTg6MzU6MDQgKzAyMDAKU3ViamVjdDogW1BBVENIXSBkbWFlbmdp bmU6IGlteC1zZG1hOiByZXN0YXJ0IHN0b3BwZWQgY3ljbGljIHRyYW5zZmVycwoKRm9yIGN5Y2xp YyBETUEgdHJhbnNmZXJzLCB3ZSBoYXZlIGF0IGxlYXN0IHR3byBjYXNlcyB3aGVyZSB3ZSBjYW4g cnVuCm91dCBkZXNjcmlwdG9ycyBhdmFpbGFibGUgdG8gdGhlIGVuZ2luZToKLSBJbnRlcnJ1cHMg YXJlIGRpc2FibGVkIGZvciB0b28gbG9uZyBhbmQgYWxsIGJ1ZmZlcnMgYSBmaWxsZWQgd2l0aAog IGRhdGEuCi0gRE1BIGVycm9ycyAoc3VjaCBhcyBnZW5lcmF0ZWQgYnkgYmF1ZCByYXRlIG1pc21h dGNoIHdpdGggaW14LXVhcnQpIHVzZQogIHVwIGFsbCBkZXNjcmlwdG9ycyBiZWZvcmUgd2UgY2Fu IHJlYWN0LgoKSW4gdGhpcyBjYXNlLCBTRE1BIHN0b3BzIHRoZSBjaGFubmVsIGFuZCBubyBmdXJ0 aGVyIHRyYW5zZmVycyBhcmUgZG9uZQp1bnRpbCB0aGUgcmVzcGVjdGl2ZSBjaGFubmVsIGlzIGRp c2FibGVkIGFuZCByZS1lbmFibGVkLgoKVGhlIGJlc3Qgd2UgY2FuIGRvIGluIHRoaXMgY2FzZSBp cyB0byBjaGVjayBpZiB0aGUgdHJhbnNmZXIgc2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