Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4601096pxj; Wed, 12 May 2021 09:02:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlK2bJOEzZ82hwCs11DbIJYVdL15fdot4vgjA2rCh4xetbqLkmsYlx/Ozo84ILx5w4UHSJ X-Received: by 2002:adf:a4c4:: with SMTP id h4mr3877611wrb.330.1620835318354; Wed, 12 May 2021 09:01:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835318; cv=none; d=google.com; s=arc-20160816; b=HFH31/byppq6pwG7ef2G4csWlxXj1bTX+RQz48nPTJbjhlhK4tzf23a4ytcy9YwRdr xrXtsRbyNNzb1lQGOW44c6ovTrW/sUpU6D2ZQkc642X9rJ/GvBGPB4U/YLQCthRlCPIG HKQUY2GBEYMRUw/Btt7RV4oVI9diMEqV7w2aBMII32FWA3rt/0ul72R2s581ExvTyMhd frn/HmgdP5tjpAOqVYzV5WRw9KAozp/naYy2ZWeriZDOExww/pvfAhFxeqWBxZ7d7MLV AIfPalT+J6il5TRTs9jgilaCQ91cM+/BR3rhgvIM+4xQvf7gRy+hpu5G8sIZ6dcf0QrH zqAg== 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=zy6BY46c0q/u9NE3nZGsS99v9yU6UNw3W48TelTcR9WbXUiDIlPP3zHrR4U3v0pIGO UOdb4ZzEognGxkcBg5DK/4/HndsbCnoEYodE3cTWH9DJIt5mTXTf3rEy6pZDC5B5kwh1 PlphvqRk2wbHuaKsiaR0rHFnHjNIsewRyn/AlHNTIVk3g7pTKgG9qQP/4VJ3e+xbL19J IH8lPBYziCKAoRycLzph4JHvGhnFL00mYcpP7CKVBVN76k4LcdxDc061rd0XoMoA2Rdb ZSUnDKJ0Uq4tJ/lyUPbvv5WIMT23pUmTVIxMTn1G/dcZFyZu6pZ5qeQN5KghqpPRA/V4 JEug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xBhfEdjy; 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 j8si295181ejk.38.2021.05.12.09.01.26; Wed, 12 May 2021 09:01:58 -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=xBhfEdjy; 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 S237907AbhELP4w (ORCPT + 99 others); Wed, 12 May 2021 11:56:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:38508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235284AbhELP12 (ORCPT ); Wed, 12 May 2021 11:27:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4760561C18; Wed, 12 May 2021 15:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832339; bh=Q5BspRQzNnqc+6X4c93kwbJhgMHXEihDL2kbOP77Tp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xBhfEdjypOBzWZenMTQC3Z3/3W6gXlMr/RkbAac6Hq2YRCBnwAdjAX1em414kbfxT c6dmesHhbdVLBGVFkwA4yOXKDkQOctogpmpHf34044yYuqVrfh5U1gH7Co4mBpUxHc vtAOQpAwcVMWKCrbStBTPIe36O2gB/Hhj6KgBCfI= 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.10 239/530] spi: spi-zynqmp-gqspi: transmit dummy circles by using the controllers internal functionality Date: Wed, 12 May 2021 16:45:49 +0200 Message-Id: <20210512144827.694619648@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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