Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp775103ybc; Sat, 16 Nov 2019 08:28:15 -0800 (PST) X-Google-Smtp-Source: APXvYqxqtYgx3CrQIpejqZgWzEm1PfABL7n5vl0cvinHYcYWWW9jm5fZ8Ev1kryIeq+42idjlArP X-Received: by 2002:a17:906:5586:: with SMTP id y6mr10850618ejp.76.1573921694984; Sat, 16 Nov 2019 08:28:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921694; cv=none; d=google.com; s=arc-20160816; b=Livs+HX0un3ZSuHb5vUAiqs9D73kYt3htzVruq27WVQ7Figph6JSAf1jdSJUvs7288 yp+ELQxMOKbfamfi2C+y23XbpKLaJV6MU85UXMcS7QRa1Y9Us8pODr4/z1UROgxaiQ3P IpXhkCuawH9kSbbEQdQb2eDqE0ojKL48CsBB3jT6txhgq/SNRq+phzTdSHP5CKPb2e4p e7l2QFLEbMPAmYiYoiCzXXuG4obdbbBSIx4wKVqIcAqMVh8J0g9Mnailh1+OYu5UkUCX DWFwDWdAXnqCII+a926Sqq+GsMbcyVl1oBZvPIpQDleZxy8pnb2SqOHrmHegHMIU2YkM 2IDw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aLaViW3rZXDzx9E10+OuakS6sBwabY/2FE9xxMqUwEg=; b=eyvilY0NKHrvmbchqqOslKnKM6IxDyVp5LC80N2IvyPqkrnmF+3CzihqW7v9jbiOH0 KeNn4T/4Pg8Q8qsJ/a+6q95w0EQWVT84PfCuWqe5IsdA/tcKslOUNnQQl8I7C6MwBWjo r1IWz+o3l8LIWSCglX96B/HFcF54M6JkQFDlSF6+yNh3kMYpA0t5wE+dfdqHsniLcds/ JwoaJyj39AyHvn2wD0FB9ZwANCml1wIOIbA6MRkrRwbe2DWlc79ktw3pmpT2LMdYJun5 wtvioYRsmykWnObTZONvM5zi07vjLQodOn+8FzfNVXt0ouEvwBFLUlKfJsjSlCpX4fO8 YScw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Z/RWTECY"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si6698594edd.445.2019.11.16.08.27.50; Sat, 16 Nov 2019 08:28:14 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="Z/RWTECY"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729837AbfKPQXa (ORCPT + 99 others); Sat, 16 Nov 2019 11:23:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:46686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728489AbfKPPmw (ORCPT ); Sat, 16 Nov 2019 10:42:52 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 69E222083B; Sat, 16 Nov 2019 15:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918971; bh=Mr7tKvRZ502cywgXVcx/jiSQvnfQj4wn5VzQkntfH5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z/RWTECYg/NG/Xf5dj/3oRZNxHSraP4rpttLTcqSGgkFsAwlDssWnUyPgmmo2ONuz k4cO4mvGfzs+UorOhgldLWSxDZYMjGgIl7uwf4YxFWc/6BfwEGEhH9UvuPeMgXILvL c6Msf2/mbKGmJHDnrIrvGUWFV9uK9qPEpXXqRUQ0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vignesh R , Mark Brown , Sasha Levin , linux-spi@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 087/237] spi: omap2-mcspi: Set FIFO DMA trigger level to word length Date: Sat, 16 Nov 2019 10:38:42 -0500 Message-Id: <20191116154113.7417-87-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vignesh R [ Upstream commit b682cffa3ac6d9d9e16e9b413c45caee3b391fab ] McSPI has 32 byte FIFO in Transmit-Receive mode. Current code tries to configuration FIFO watermark level for DMA trigger to be GCD of transfer length and max FIFO size which would mean trigger level may be set to 32 for transmit-receive mode if length is aligned. This does not work in case of SPI slave mode where FIFO always needs to have data ready whenever master starts the clock. With DMA trigger size of 32 there will be a small window during slave TX where DMA is still putting data into FIFO but master would have started clock for next byte, resulting in shifting out of stale data. Similarly, on Slave RX side there may be RX FIFO overflow Fix this by setting FIFO watermark for DMA trigger to word length. This means DMA is triggered as soon as FIFO has space for word length bytes and DMA would make sure FIFO is almost always full therefore improving FIFO occupancy in both master and slave mode. Signed-off-by: Vignesh R Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-omap2-mcspi.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index e2be7da743438..f50cb8a4b4138 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -299,7 +299,7 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi, struct omap2_mcspi_cs *cs = spi->controller_state; struct omap2_mcspi *mcspi; unsigned int wcnt; - int max_fifo_depth, fifo_depth, bytes_per_word; + int max_fifo_depth, bytes_per_word; u32 chconf, xferlevel; mcspi = spi_master_get_devdata(master); @@ -315,10 +315,6 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi, else max_fifo_depth = OMAP2_MCSPI_MAX_FIFODEPTH; - fifo_depth = gcd(t->len, max_fifo_depth); - if (fifo_depth < 2 || fifo_depth % bytes_per_word != 0) - goto disable_fifo; - wcnt = t->len / bytes_per_word; if (wcnt > OMAP2_MCSPI_MAX_FIFOWCNT) goto disable_fifo; @@ -326,16 +322,17 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi, xferlevel = wcnt << 16; if (t->rx_buf != NULL) { chconf |= OMAP2_MCSPI_CHCONF_FFER; - xferlevel |= (fifo_depth - 1) << 8; + xferlevel |= (bytes_per_word - 1) << 8; } + if (t->tx_buf != NULL) { chconf |= OMAP2_MCSPI_CHCONF_FFET; - xferlevel |= fifo_depth - 1; + xferlevel |= bytes_per_word - 1; } mcspi_write_reg(master, OMAP2_MCSPI_XFERLEVEL, xferlevel); mcspi_write_chconf0(spi, chconf); - mcspi->fifo_depth = fifo_depth; + mcspi->fifo_depth = max_fifo_depth; return; } @@ -585,7 +582,6 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) struct dma_slave_config cfg; enum dma_slave_buswidth width; unsigned es; - u32 burst; void __iomem *chstat_reg; void __iomem *irqstat_reg; int wait_res; @@ -605,22 +601,14 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) } count = xfer->len; - burst = 1; - - if (mcspi->fifo_depth > 0) { - if (count > mcspi->fifo_depth) - burst = mcspi->fifo_depth / es; - else - burst = count / es; - } memset(&cfg, 0, sizeof(cfg)); cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0; cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0; cfg.src_addr_width = width; cfg.dst_addr_width = width; - cfg.src_maxburst = burst; - cfg.dst_maxburst = burst; + cfg.src_maxburst = es; + cfg.dst_maxburst = es; rx = xfer->rx_buf; tx = xfer->tx_buf; -- 2.20.1