Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2664545pxa; Mon, 17 Aug 2020 15:57:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5fnz2/A0X3hZITcSvVe3ja+dCiyR+4CL5gNC4db7LKGWfNkcKfD356/0hIqN7s748gGm8 X-Received: by 2002:a17:906:aad2:: with SMTP id kt18mr18022663ejb.537.1597705064657; Mon, 17 Aug 2020 15:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597705064; cv=none; d=google.com; s=arc-20160816; b=HkbuF/wUuhJWbuNR5Xd1RLNqfF30haCssLJ6p6Xkiy0dAkUV2IrMHFZQ13kZ1b2rty DBzW4/GiDtumXqdg6rTpqSeWRrXnerz3K9xGn0gFKoTskbd1kSVH7S04UoL2FRon1Ga5 Z7vmPN4/+l7sGqWfmOrlAs8oViHiscKUcy/siX0BQ/ExDAVLHOjs5Bl7JzBdkuzbG3LJ r4uc8bLT+q84zNXLq21HehX7y1Rd08eSsUV0dYMGK/8QBnpL7tP8TYwH7e6k9PrzbFtc 7Qp4G9HxvDOoYsMUb+HO0BlyMgk7LX8kzSFLJmeZkkYqwDhWmI/woEyHz0kSTswmBW8L Qjfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1j/MARYPJgj/g3hY7fp+esTkUmQEgWD1B7u/sMptpSU=; b=M0iND2Or15ptH4V1b2V+rigaSOZtKuuatPsLl3nRwsChwpf4gxXKffccY45VxJewPS xDsFMreVwHVUqIM3g+n1H8RYEiL/A/U/8BrBgileJBxShLIFUyRtbHAYh0ak1tDM4r5j 1cd2cnGUO3CzKDdf0McsW5DQcQ0BVcEeRzyyTVjGdH75Ah4Bwo75mTuITSNTr6Vc+hlc UAoyVOzscS6nIbg2QEEixbpTA1LXbcNj+MOOum5Py1OfIpOXHAMrC+c78Xn8xHlB4PPP OaP54V9+5ONSBTIeb8G8okBuc/ZWYusmUYL1cz2OrCTJc9BvMUi81Nv3+9asEGz3kcve Lipw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r6iXPp+q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd22si13794150ejb.33.2020.08.17.15.57.20; Mon, 17 Aug 2020 15:57:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r6iXPp+q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732742AbgHQTs0 (ORCPT + 99 others); Mon, 17 Aug 2020 15:48:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:42056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729257AbgHQPUR (ORCPT ); Mon, 17 Aug 2020 11:20:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 287DD2072E; Mon, 17 Aug 2020 15:20:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597677616; bh=vbTAb44KZTHCUUR1fLwfmZ7ptgPtMwcHogXlu5gZoe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r6iXPp+qbpvczvjoxK8LhxyiHeNJuPw31DAwdY+0l5ieZ9F7GeBWBHKdrdF50t839 oihCwIyA/rXhlQEzD7u+Qx/3kV1lXdRLM8lA+BomO3F2nuf3QAABfpiWlXW55NcOBL dzh3lMTXFnaI++52booGZah3BzcliFBEC3M195KQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Serge Semin , Andy Shevchenko , Alexey Malahov , Feng Tang , Mark Brown , Sasha Levin Subject: [PATCH 5.8 046/464] spi: dw-dma: Fix Tx DMA channel working too fast Date: Mon, 17 Aug 2020 17:09:59 +0200 Message-Id: <20200817143835.965128606@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Serge Semin [ Upstream commit affe93dd5b35bb0e7b0aa0505ae432dd0ac72c3f ] It turns out having a Rx DMA channel serviced with higher priority than a Tx DMA channel is not enough to provide a well balanced DMA-based SPI transfer interface. There might still be moments when the Tx DMA channel is occasionally handled faster than the Rx DMA channel. That in its turn will eventually cause the SPI Rx FIFO overflow if SPI bus speed is high enough to fill the SPI Rx FIFO in before it's cleared by the Rx DMA channel. That's why having the DMA-based SPI Tx interface too optimized is the errors prone, so the commit 0b2b66514fc9 ("spi: dw: Use DMA max burst to set the request thresholds") though being perfectly normal from the standard functionality point of view implicitly introduced the problem described above. In order to fix that the Tx DMA activity is intentionally slowed down by limiting the SPI Tx FIFO depth with a value twice bigger than the Tx burst length calculated earlier by the dw_spi_dma_maxburst_init() method. Fixes: 0b2b66514fc9 ("spi: dw: Use DMA max burst to set the request thresholds") Signed-off-by: Serge Semin Reviewed-by: Andy Shevchenko Cc: Andy Shevchenko Cc: Alexey Malahov Cc: Feng Tang Link: https://lore.kernel.org/r/20200721203951.2159-1-Sergey.Semin@baikalelectronics.ru Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-dw-dma.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index 5986c520b1965..bb390ff67d1d8 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -372,8 +372,20 @@ static int dw_spi_dma_setup(struct dw_spi *dws, struct spi_transfer *xfer) { u16 imr = 0, dma_ctrl = 0; + /* + * Having a Rx DMA channel serviced with higher priority than a Tx DMA + * channel might not be enough to provide a well balanced DMA-based + * SPI transfer interface. There might still be moments when the Tx DMA + * channel is occasionally handled faster than the Rx DMA channel. + * That in its turn will eventually cause the SPI Rx FIFO overflow if + * SPI bus speed is high enough to fill the SPI Rx FIFO in before it's + * cleared by the Rx DMA channel. In order to fix the problem the Tx + * DMA activity is intentionally slowed down by limiting the SPI Tx + * FIFO depth with a value twice bigger than the Tx burst length + * calculated earlier by the dw_spi_dma_maxburst_init() method. + */ dw_writel(dws, DW_SPI_DMARDLR, dws->rxburst - 1); - dw_writel(dws, DW_SPI_DMATDLR, dws->fifo_len - dws->txburst); + dw_writel(dws, DW_SPI_DMATDLR, dws->txburst); if (xfer->tx_buf) dma_ctrl |= SPI_DMA_TDMAE; -- 2.25.1