Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4724066pxj; Wed, 12 May 2021 11:45:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeL1JNFQ9tcogm10sD1ZRd3BIpSs8CxPH+HXmFB3PsVWgSKR9joCXgXJLlS16jjQwu2/W9 X-Received: by 2002:a05:6402:6d9:: with SMTP id n25mr37096233edy.229.1620845152991; Wed, 12 May 2021 11:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620845152; cv=none; d=google.com; s=arc-20160816; b=ckxc8e7b3GOObjiorQS18l/lZ9ryDKoEKu4aVXrBw/B8fE3o7IuWQfT585qNctphmR Vif9kQ9FCyyTMLmVysX9mlhxWuUEg7EfvFs0zc0ksYN2vo1XJex7pqOcj0H2TI8JsSVA E2MwbBqvIrltc65xmHxXNewZpk9xHd13nPRuHREwHsc7T1bVarGDVXCVCcbXLHnw55Kh szUCDsNtKCTfNhD0M3qUK0HJdHwbCjCLJI94WvkmBCB3jpJqLDOf7w5pC2ldR2Pekw4t nO7dafME1h4rZH1Ex9HQTe7bFGge2wDEeS8G4I0rYr7zElgx3pFGilq4uptXHNzIzQbH zrog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4b4sXQDsVoBz/4mzCijH99/7QsVk0sqDHbkJEKKpO2c=; b=z/2cAzv42UoS+TAdKrifk+1qDHLEaSAFSxPXskKIH37HJaCOxU44Kxt0tcXxjzoSe7 SjBmvA3czqL7z+ilrsXiVhtnOjkRZgePL54X63syA0wI/U6f40kgeo14ZTOAya9zysNt pDpNGwdwUTes1qg8ltWHstiELKu8/1xoWqmHtl/M3UxwZWDgY+O2SbBVVQL4Jkql3DbH 1nRXFTX567/D7L9TkI2/Ku0ZGyIQzP2g9HVFFMNVmkhOogRbsMSTKvU3Qv5pkimmBBAv tYaitu2P4rt6JXgMvunNgzj9LoRYObZhF+tbL4NRi0K985t2/Oq9IydvSANFJE8zZ6PV p9cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="xurA/4a2"; 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=pass (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 k9si833253eje.366.2021.05.12.11.45.29; Wed, 12 May 2021 11:45:52 -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=@linuxfoundation.org header.s=korg header.b="xurA/4a2"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356989AbhELShq (ORCPT + 99 others); Wed, 12 May 2021 14:37:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:57122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243268AbhELQhB (ORCPT ); Wed, 12 May 2021 12:37:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EBD4661C7A; Wed, 12 May 2021 16:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835319; bh=Q5BspRQzNnqc+6X4c93kwbJhgMHXEihDL2kbOP77Tp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xurA/4a2BZHpOfWr9s4+OkTPdMd7OhEVYHJASTf7Ntak3c3dxeSh84nd7yq4NU7XE ai8EkmQ2nFXDi0rjTkNkWyOiZoW7MwNWAA5Wj0JEHMpw+hCCe95z2DGwZ0numcMQOl mmsfG4b4alho4KJ/uBlWGgDP/3UDxdio2vcRS074= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quanyang Wang , Amit Kumar Mahapatra , Mark Brown , Sasha Levin Subject: [PATCH 5.12 295/677] spi: spi-zynqmp-gqspi: transmit dummy circles by using the controllers internal functionality Date: Wed, 12 May 2021 16:45:41 +0200 Message-Id: <20210512144847.016849355@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quanyang Wang [ Upstream commit 8ad07d79bd56a531990a1a3f3f1c0eb19d2de806 ] There is a data corruption issue that occurs in the reading operation (cmd:0x6c) when transmitting common data as dummy circles. The gqspi controller has the functionality to send dummy clock circles. When writing data with the fields [receive, transmit, data_xfer] = [0,0,1] to the Generic FIFO, and configuring the correct SPI mode, the controller will transmit dummy circles. So let's switch to hardware dummy cycles transfer to fix this issue. Fixes: 1c26372e5aa9 ("spi: spi-zynqmp-gqspi: Update driver to use spi-mem framework") Signed-off-by: Quanyang Wang Reviewed-by: Amit Kumar Mahapatra Link: https://lore.kernel.org/r/20210408040223.23134-4-quanyang.wang@windriver.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-zynqmp-gqspi.c | 40 +++++++++++++++------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c index 3b39461d58b3..cf73a069b759 100644 --- a/drivers/spi/spi-zynqmp-gqspi.c +++ b/drivers/spi/spi-zynqmp-gqspi.c @@ -521,7 +521,7 @@ static void zynqmp_qspi_filltxfifo(struct zynqmp_qspi *xqspi, int size) { u32 count = 0, intermediate; - while ((xqspi->bytes_to_transfer > 0) && (count < size)) { + while ((xqspi->bytes_to_transfer > 0) && (count < size) && (xqspi->txbuf)) { memcpy(&intermediate, xqspi->txbuf, 4); zynqmp_gqspi_write(xqspi, GQSPI_TXD_OFST, intermediate); @@ -580,7 +580,7 @@ static void zynqmp_qspi_fillgenfifo(struct zynqmp_qspi *xqspi, u8 nbits, genfifoentry |= GQSPI_GENFIFO_DATA_XFER; genfifoentry |= GQSPI_GENFIFO_TX; transfer_len = xqspi->bytes_to_transfer; - } else { + } else if (xqspi->rxbuf) { genfifoentry &= ~GQSPI_GENFIFO_TX; genfifoentry |= GQSPI_GENFIFO_DATA_XFER; genfifoentry |= GQSPI_GENFIFO_RX; @@ -588,6 +588,11 @@ static void zynqmp_qspi_fillgenfifo(struct zynqmp_qspi *xqspi, u8 nbits, transfer_len = xqspi->dma_rx_bytes; else transfer_len = xqspi->bytes_to_receive; + } else { + /* Sending dummy circles here */ + genfifoentry &= ~(GQSPI_GENFIFO_TX | GQSPI_GENFIFO_RX); + genfifoentry |= GQSPI_GENFIFO_DATA_XFER; + transfer_len = xqspi->bytes_to_transfer; } genfifoentry |= zynqmp_qspi_selectspimode(xqspi, nbits); xqspi->genfifoentry = genfifoentry; @@ -1011,32 +1016,23 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, } if (op->dummy.nbytes) { - tmpbuf = kzalloc(op->dummy.nbytes, GFP_KERNEL | GFP_DMA); - if (!tmpbuf) - return -ENOMEM; - memset(tmpbuf, 0xff, op->dummy.nbytes); - reinit_completion(&xqspi->data_completion); - xqspi->txbuf = tmpbuf; + xqspi->txbuf = NULL; xqspi->rxbuf = NULL; - xqspi->bytes_to_transfer = op->dummy.nbytes; + /* + * xqspi->bytes_to_transfer here represents the dummy circles + * which need to be sent. + */ + xqspi->bytes_to_transfer = op->dummy.nbytes * 8 / op->dummy.buswidth; xqspi->bytes_to_receive = 0; - zynqmp_qspi_write_op(xqspi, op->dummy.buswidth, + /* + * Using op->data.buswidth instead of op->dummy.buswidth here because + * we need to use it to configure the correct SPI mode. + */ + zynqmp_qspi_write_op(xqspi, op->data.buswidth, genfifoentry); zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST, zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST) | GQSPI_CFG_START_GEN_FIFO_MASK); - zynqmp_gqspi_write(xqspi, GQSPI_IER_OFST, - GQSPI_IER_TXEMPTY_MASK | - GQSPI_IER_GENFIFOEMPTY_MASK | - GQSPI_IER_TXNOT_FULL_MASK); - if (!wait_for_completion_interruptible_timeout - (&xqspi->data_completion, msecs_to_jiffies(1000))) { - err = -ETIMEDOUT; - kfree(tmpbuf); - goto return_err; - } - - kfree(tmpbuf); } if (op->data.nbytes) { -- 2.30.2