From patchwork Tue Jan 14 17:13:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Conor Dooley X-Patchwork-Id: 13938988 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D6201D5154; Tue, 14 Jan 2025 17:13:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736874837; cv=none; b=FdoWOvKX3NRioSR0xAiGbJg+zZ/RFZDEVV2/bD1aYEWSgGC7IQI19Gtc7Ur7y2/y6ZSMI26jj/YgkUyGPdiP3FqCuBFENrNbyC/AhDSOaAgdrnRJLuJu7zoxeFroG1Nuta1AZLFBXbkt7YrifIIIjujG5fRpYe6xExlMb1l3UfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736874837; c=relaxed/simple; bh=+cPongiPTXfYF42ILAuhGmrFbcuJWkTa3K4+cXN5O1Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cN5+EGLFZTx13CiyXxoZ2gTu2hfJUJuIgBn5++vHJk0solxpN9HsDOJRJXoQplhzcW6Sk76dv0Y0c05pRupCtRNzMVFzLXgLwBP1L5Fw5W7lqJyWCGWEM3mNMJsD03a3yuq/6cH0y6h3EVeNUrf3uEoCdJtMeFRY3xezZqUrAwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gonFpl1k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gonFpl1k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1053FC4CEDD; Tue, 14 Jan 2025 17:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736874836; bh=+cPongiPTXfYF42ILAuhGmrFbcuJWkTa3K4+cXN5O1Q=; h=From:To:Cc:Subject:Date:From; b=gonFpl1kdx+aThw1x31zHGRxllAoIkG+ONJ+m/IW2Rjgb2AuitvfDkZ/+LXLEJLYS CGhu4+kt+Uqe4U+Zl06fYObMJL3C/gUmTwYIivcm+nGkn1+Ptlit1LtXmpPzVbh0W0 pjHNAhUINgyHzn5TsHTQxflGHuRjtXgYeDlZ+tFV5X3036WpvXQZT9e6Y2QGNP9jcB xTOGc1ntQAH0FtlmqdOEjUQDJGeCt7GG5QaYfzAE+AqMEebTuVCOBMFStlO9dt/9Q7 anqM/lIdtf4pCPUNPV/oZi2IxWLy0fbUF+sWxzFeYd+TlzBm4QXWcUKWkSh/BCMTKf 4y8BP6vHyyFDg== From: Conor Dooley To: linux-spi@vger.kernel.org Cc: conor@kernel.org, Conor Dooley , stable@vger.kernel.org, Daire McNamara , Mark Brown , linux-kernel@vger.kernel.org Subject: [PATCH] spi: microchip-core: prevent RX overflows when transmit size > FIFO size Date: Tue, 14 Jan 2025 17:13:49 +0000 Message-ID: <20250114-easiness-pregame-d1d2d4b57e7b@spud> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2024; i=conor.dooley@microchip.com; h=from:subject:message-id; bh=zOeZgEc8f7sCpwLYHd+UXUO6lO4YDxO0JUopvPbfNLw=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDOlts/2sn27c7rF6dq3FDIMZKpNDZGzWHQqaU6WW413A5 lz1fxV7RykLgxgHg6yYIkvi7b4WqfV/XHY497yFmcPKBDKEgYtTACZy5zvDP73Uhzs9iwIT7ugu 87Cov3dKM6I3iHumIct2k8a9Lle7HjL8T3fVuxL0n7uwZMJ6ba0o6YBvd1a/Xlb0Mu9u9tXTh2Q zeAE= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C From: Conor Dooley When the size of a transfer exceeds the size of the FIFO (32 bytes), RX overflows will be generated and receive data will be corrupted and warnings will be produced. For example, here's an error generated by a transfer of 36 bytes: spi_master spi0: mchp_corespi_interrupt: RX OVERFLOW: rxlen: 4, txlen: 0 I am not entirely sure how this happens, as rxlen being 4 means that 32 of 36 bytes have been read from the RX FIFO so there should be sufficient room for 4 more bytes but timing is likely a factor as simply adding a delay in the transmit path is enough to avoid the overflows. CC: stable@vger.kernel.org Fixes: 9ac8d17694b6 ("spi: add support for microchip fpga spi controllers") Signed-off-by: Conor Dooley --- Been sitting on this one for a bit, original reporter claims the problem isn't fixed, but it fixed the issue on my setup so I am sending the patch as it's an improvement on the status quo at the very least. CC: Conor Dooley CC: Daire McNamara CC: Mark Brown CC: linux-spi@vger.kernel.org CC: linux-kernel@vger.kernel.org --- drivers/spi/spi-microchip-core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/spi/spi-microchip-core.c b/drivers/spi/spi-microchip-core.c index 5b6af55855ef..3582fe8d3fc4 100644 --- a/drivers/spi/spi-microchip-core.c +++ b/drivers/spi/spi-microchip-core.c @@ -221,6 +221,13 @@ static inline void mchp_corespi_write_fifo(struct mchp_corespi *spi) while ((i < fifo_max) && !(mchp_corespi_read(spi, REG_STATUS) & STATUS_TXFIFO_FULL)) { u32 word; + /* + * If the transfer is larger than FIFO_DEPTH, spin until space + * is made in the RX FIFO to avoid losing data to RX overflows + */ + while (mchp_corespi_read(spi, REG_STATUS) & STATUS_RXFIFO_FULL) + ; + if (spi->n_bytes == 4) word = spi->tx_buf ? *((u32 *)spi->tx_buf) : 0xaa; else if (spi->n_bytes == 2)