From nobody Fri Oct 3 10:12:39 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5F942D3EC7 for ; Tue, 2 Sep 2025 12:46:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817170; cv=none; b=cg4zLeKTDIICqYB3FAtj99NkWra/r1LAULYfqfskKYkAlOAWp81a76r7JtI0lM+oita+IDMXOkrvsF21c05mm5Sllr0EihSQJxA7mQcXilDcII8gRPkPu1Oqy94LKxHmo+vEAEdTHRm4FDWqjQyJevQTbcRk13QgGBBL5464hck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817170; c=relaxed/simple; bh=8/fgw25QdB1ZgzdAKtXHCLtofKXduBfFQhmuMPgookE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TBVG812EhkazQ7SmH1PYbQ6MPMG4TxylYb+/Dmqjt0BaYoaupR2zE7Hh8FRE943Zku3zGyK76bd4kyJflLTyYz7qGqMFZx5QGt5l/jjpkc6gcG1OaDIj0ifhHFT+G3lrdiVEaxT2wvtKoQST6mzjJXkUvdarNHF/tO5b9PB4/aw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=WUb5ZQkM; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WUb5ZQkM" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-45b7c56a987so16861925e9.1 for ; Tue, 02 Sep 2025 05:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756817167; x=1757421967; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5r9IPHLuMKz/CQAQPk4+OYtt68jBsvmpWFMRP88G9KI=; b=WUb5ZQkMRb/nX8f2m5X0PRpMMRJu8VSdeLcLLMx/sAKY6k1ta06F2t0JD/BF5X5zZ2 G0E5SbmWYRUmCbccvh1ySU5zjVNWguy/FLBXXG+zF30OYYH+Ntcu7JlVUtBBcvzMiPje Hr5Rn9FIp+fvYb56Mh3kBYYCb5WYRSlc9dT3/vXv9cEDHCzbVckzygWGUPDDTzNtI8cW kBJ9xiIa7JBgTThsPu8R9V2zDHOkVY81xu3Kouvpy0OauU24eDPSmNQdvhUCOjcICzCJ WkGcM7fXtlpwJW1x/TKmFG1OUwV//a+zSXPXYb7ydsa7g1o0guSTYm+E0zvFs49Z3bXi 5ONw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756817167; x=1757421967; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5r9IPHLuMKz/CQAQPk4+OYtt68jBsvmpWFMRP88G9KI=; b=GixgfU+ByE6fdI4grQEpFCsybTmFnNz5n6arf09vLZ4/N2Qv15gTw/cbIOaONPG5T0 NBXAD9+2QD1R2U17XPE15HCqViJqirpVx25DHwVkZUMHw4BHKQZTD8tYxrlATBkrHD4T xlLKtzVz56FjBRA9fzN80CPP5BZHViaA2CyAQy4EGBYVZO60AatvpMwlwKTCYZncLhPX NuIrZeshrMbBYrzw3db2ZzR0xAwS9agwk7mpr0qnVZiMSpKW87vHYzVKHj0yEAKSTrdd NY+yH8tRs9HQUBzex0EHdYo7H/6ms4bHCP+OBqo0MhNuJByYQjMyU/Sqd4kPNRQq+Ya0 sIyg== X-Forwarded-Encrypted: i=1; AJvYcCUD6nFqJIyoeODtRAFWECQt7XIRD0xkRSpW4vLkgSiR8pFBegJgEKS4QJSPrcutx9k6qLTG54KI+qA+OvU=@vger.kernel.org X-Gm-Message-State: AOJu0YyVIcvyjR20qkkOO3h7BmCNi4FjGCN0vXYULMWN7A1+CodWaXiA 26zC/IzQ/1XPYdpOjFi6IgnrjOd8cSPg/DGlyERX2i9LpuEB7nN58fxIPCGDMIKxu+8= X-Gm-Gg: ASbGncsR42EqThu5Fd1tvptXnYtzlV33ZvrjFB+fAV9srpgqd+ma6PM7o69J2JbHd9L 4B9t75DavM7IZ5j2/1YKg4N1FuS0mAugOpPjqknhem46EVjg5MQKERWxCKxDg/+Fq1dQDY7Zh4D uWiUVw3SzZHKO1BshO21Uz9cFf5YLuv+qYR/GZDNjGLDp9A+BawUL4vl6fXIXNkIiVDyuAecjF6 bBpNYeZ+N8ClSZcCfEjAk8iCjFnJYFQsB8JMpLqdTSC62WcyIQyfvtZ6fjKaVxvwJw07AuSPzdG QfDl3eZAtMGs3p3uypU4tIJ6Im0H+4xfWhow51u6sD3sXZ31fWMW0809cjR0cJxHdSG9/6n48d6 iD0qn9WkWzJqrI+nMLi0W3KGcOmBBE3k= X-Google-Smtp-Source: AGHT+IFiBte5oIm9wgYp4QL6sXIclbo20jvsZNvWU5oy5exkamtVaSde2J41wTdC4z94mkJWGbNsYw== X-Received: by 2002:a05:6000:3112:b0:3d1:42dc:c710 with SMTP id ffacd0b85a97d-3d1dcb76607mr9142347f8f.16.1756817167187; Tue, 02 Sep 2025 05:46:07 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cf275d2717sm19589896f8f.15.2025.09.02.05.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 05:46:06 -0700 (PDT) From: James Clark Date: Tue, 02 Sep 2025 13:44:53 +0100 Subject: [PATCH v6 1/7] spi: fsl-dspi: Avoid using -EINPROGRESS error code Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-james-nxp-spi-dma-v6-1-f7aa2c5e56e2@linaro.org> References: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> In-Reply-To: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> To: Vladimir Oltean , Mark Brown , Vladimir Oltean , Arnd Bergmann , Larisa Grigore , Frank Li , Christoph Hellwig Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 Refactor dspi_rxtx() and dspi_poll() to not return -EINPROGRESS because this isn't actually a status that is ever returned to the core layer but some internal state. Use true/false return value on dspi_rxtx() for this instead. This will help separate internal vs external status for the later change to store the external status directly in cur_msg->status. No functional changes intended. Co-developed-by: Vladimir Oltean Signed-off-by: Vladimir Oltean Signed-off-by: James Clark Reviewed-by: Vladimir Oltean --- drivers/spi/spi-fsl-dspi.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 4bd4377551b5..654905a358e8 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -986,36 +986,45 @@ static void dspi_fifo_write(struct fsl_dspi *dspi) dspi->progress, !dspi->irq); } =20 -static int dspi_rxtx(struct fsl_dspi *dspi) +/* + * Read the previous transfer from the FIFO and transmit the next one. + * + * Returns false if the buffer to be transmitted is empty, and true if the= re is + * still data to transmit. + */ +static bool dspi_rxtx(struct fsl_dspi *dspi) { dspi_fifo_read(dspi); =20 if (!dspi->len) /* Success! */ - return 0; + return false; =20 dspi_fifo_write(dspi); =20 - return -EINPROGRESS; + return true; } =20 static int dspi_poll(struct fsl_dspi *dspi) { - int tries =3D 1000; + int tries; + int err =3D 0; u32 spi_sr; =20 do { - regmap_read(dspi->regmap, SPI_SR, &spi_sr); - regmap_write(dspi->regmap, SPI_SR, spi_sr); - - if (spi_sr & SPI_SR_CMDTCF) + for (tries =3D 1000; tries > 0; --tries) { + regmap_read(dspi->regmap, SPI_SR, &spi_sr); + regmap_write(dspi->regmap, SPI_SR, spi_sr); + if (spi_sr & SPI_SR_CMDTCF) + break; + } + if (!tries) { + err =3D -ETIMEDOUT; break; - } while (--tries); - - if (!tries) - return -ETIMEDOUT; + } + } while (dspi_rxtx(dspi)); =20 - return dspi_rxtx(dspi); + return err; } =20 static irqreturn_t dspi_interrupt(int irq, void *dev_id) @@ -1029,7 +1038,7 @@ static irqreturn_t dspi_interrupt(int irq, void *dev_= id) if (!(spi_sr & SPI_SR_CMDTCF)) return IRQ_NONE; =20 - if (dspi_rxtx(dspi) =3D=3D 0) + if (dspi_rxtx(dspi) =3D=3D false) complete(&dspi->xfer_done); =20 return IRQ_HANDLED; @@ -1137,9 +1146,7 @@ static int dspi_transfer_one_message(struct spi_contr= oller *ctlr, if (dspi->irq) { wait_for_completion(&dspi->xfer_done); } else { - do { - status =3D dspi_poll(dspi); - } while (status =3D=3D -EINPROGRESS); + status =3D dspi_poll(dspi); } } if (status) --=20 2.34.1 From nobody Fri Oct 3 10:12:39 2025 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 034962D47FD for ; Tue, 2 Sep 2025 12:46:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817172; cv=none; b=nLzKy7lQ9qp35MQfWs/gs+iZ76+84wPfD8Xc6yPo59klUrpAznHqgvDZqOwg2/uMSjiBL466sGuOzR4OqpETpFELR3lbcvsh0YcuzL98qLNhtCoZNrmJPjfEJfFmQfag+aJPbDZNPYiUG3z1G4+qqzZiW9fw9+10FFtawd8Cu/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817172; c=relaxed/simple; bh=C9oJkV3mHs12c4uHbbNxH2PTvvxlVuP9ivdk16TivuE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UIBGx6g48wznRE8LtpcUHY2umluPCQi8STTrccrm3ZfEOd8ggcDfmy0RdiOyraUQONG1fZYoXPacubh8So+TTaPOrWqIevXdIwnbgwjzhbBKY6P/NO0UlnvMhCRXyC8hV8qL0QiXj7zCU4/se5WvSNAlKLuHKLPKk64SjVwf0fo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=hmZRKMed; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hmZRKMed" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-3d19699240dso2185964f8f.1 for ; Tue, 02 Sep 2025 05:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756817168; x=1757421968; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=kn8pqlkvI8BkvlrFlfSozqitc0dmKXQH5rpgTQNMM/U=; b=hmZRKMeddOeB2iSqdWCOzXZDSPwYEy2kc9Ne9sr4fQXBRk1ApyuWlQpBuwiaENjVC8 3d89NrluwMA9xLxnpCH07qGaG/w1um7GCC8MnfNnt9qKW+BctvqCiENxkTSPt7KMnsmG CW+vwHKs1IRA1B2Ju1u5Lj1lBnNWIhBrsJmvvXPoTzkCGanCb1C/o9645OT6nAA+6GMG igYm/5XmVcQg5wyqWE5qv56JhBWz6wMsKJzD0edG+2pWrbHkx5NE2wC5pJJHZHyhJqlQ x+RjiMtsAW8GTKfBlCz6gSbZnHPPtIa0SSUEIvBYyBKjAFWEODW3eDGA/CgONT8Hmn1g ZEQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756817168; x=1757421968; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kn8pqlkvI8BkvlrFlfSozqitc0dmKXQH5rpgTQNMM/U=; b=H3ir07hLjPl7WtXTS1FZeFPcBFDGP+OUzqLq07ZM04vE7jWjB+DsfU/tv+tdBY4YUh t4EJ7L9e9/Lgl160vbtvR/TbgewXmLMv2PjWqn7ryxed0OqctjiC1vHnCBeE7OYgSSfm YKi2nw/hms2v+m7yoMhQcf8t2wukXnFnw9Kv0u8hcSTpbV+sL7sCV+uFW9YKNEUCXY4C N2ll4Q+xycCZislPC7EWh1O1eU2PDQo3KLvOdX1PTpDbskjD6Nxwrp5/37kZbTrNePh/ 5cP1a3j1R9ceXQZj13rMPVKpFufxR9MBoTI6bix8EDhD9Vnj9fGEUY+toHJvbzF2Fb4W q4xg== X-Forwarded-Encrypted: i=1; AJvYcCXzuqwp4OvPLuimSxwkHUpoORClSjbn/B2JeG0hYM1Dqm5queFDMdVePGUM5k5fWl9YhnVWWMe/nnXVnsg=@vger.kernel.org X-Gm-Message-State: AOJu0YxfPVdDawlXpYbLYKotrrXEuLXeTaO5I5g9dv97iFLJa+han7n6 vDVqXR3GA2f0VoARSQrroPG0hv0xWbK8wD9h37BjLFJ5msT0FlisyquQCapv280SkB7g4Be0zgW nRyDmpBo= X-Gm-Gg: ASbGnct0FGM2uQu1eB592Vaz4m8E+V/oBYKp+VhG9RJ67A2Fd786cYwu7Q115vxwETF tao6if4cP1N7aE4Fb1P+wLDjo3bf55IiOm7prdjsT6HE1/VS21+rFRQbmIp1YfzXE4rbnQFd2Pd /QI0Ye4Qq60pn2FXqaCRp7bRwTpN9oue2oleyFXeel1PmS2GwSS785yy/VGujWmO8f8aHZa0a3U vyb+JSjerigaodc3AROZ/DhMCYdMMLexqBXzv6Jei4P457B7juVXT0Bn4tJ17OikYRJgOMGJ9vH mdVnpt276w+2DN9B5npXdZq3KsFVPtqFI8JkN2jQHyiLXIOlMAd63GPDjqMFcgf1cWzlhAS2ekP e2L+ZUg/be8ac3IzA/FN6MaogOFhcyiQ= X-Google-Smtp-Source: AGHT+IFdtM4/TLGwP6fe/R2gAZvK0+s/idu1aQn5sBDOWhmpmHH0V56Svb4t3Yx0WsS/OmGQzPbJ4w== X-Received: by 2002:a05:6000:1786:b0:3d0:e221:892e with SMTP id ffacd0b85a97d-3d1df633bedmr8952104f8f.27.1756817168257; Tue, 02 Sep 2025 05:46:08 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cf275d2717sm19589896f8f.15.2025.09.02.05.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 05:46:07 -0700 (PDT) From: James Clark Date: Tue, 02 Sep 2025 13:44:54 +0100 Subject: [PATCH v6 2/7] spi: fsl-dspi: Store status directly in cur_msg->status Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-james-nxp-spi-dma-v6-2-f7aa2c5e56e2@linaro.org> References: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> In-Reply-To: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> To: Vladimir Oltean , Mark Brown , Vladimir Oltean , Arnd Bergmann , Larisa Grigore , Frank Li , Christoph Hellwig Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 This will allow us to return a status from the interrupt handler in a later commit and avoids copying it at the end of dspi_transfer_one_message(). For consistency make polling and DMA modes use the same mechanism. No functional changes intended. Signed-off-by: James Clark Signed-off-by: Vladimir Oltean Reviewed-by: Vladimir Oltean --- drivers/spi/spi-fsl-dspi.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 654905a358e8..48054932d517 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -591,11 +591,10 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi = *dspi) =20 static void dspi_setup_accel(struct fsl_dspi *dspi); =20 -static int dspi_dma_xfer(struct fsl_dspi *dspi) +static void dspi_dma_xfer(struct fsl_dspi *dspi) { struct spi_message *message =3D dspi->cur_msg; struct device *dev =3D &dspi->pdev->dev; - int ret =3D 0; =20 /* * dspi->len gets decremented by dspi_pop_tx_pushr in @@ -612,14 +611,12 @@ static int dspi_dma_xfer(struct fsl_dspi *dspi) message->actual_length +=3D dspi->words_in_flight * dspi->oper_word_size; =20 - ret =3D dspi_next_xfer_dma_submit(dspi); - if (ret) { + message->status =3D dspi_next_xfer_dma_submit(dspi); + if (message->status) { dev_err(dev, "DMA transfer failed\n"); break; } } - - return ret; } =20 static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr) @@ -1005,7 +1002,7 @@ static bool dspi_rxtx(struct fsl_dspi *dspi) return true; } =20 -static int dspi_poll(struct fsl_dspi *dspi) +static void dspi_poll(struct fsl_dspi *dspi) { int tries; int err =3D 0; @@ -1024,7 +1021,7 @@ static int dspi_poll(struct fsl_dspi *dspi) } } while (dspi_rxtx(dspi)); =20 - return err; + dspi->cur_msg->status =3D err; } =20 static irqreturn_t dspi_interrupt(int irq, void *dev_id) @@ -1038,8 +1035,11 @@ static irqreturn_t dspi_interrupt(int irq, void *dev= _id) if (!(spi_sr & SPI_SR_CMDTCF)) return IRQ_NONE; =20 - if (dspi_rxtx(dspi) =3D=3D false) + if (dspi_rxtx(dspi) =3D=3D false) { + if (dspi->cur_msg) + WRITE_ONCE(dspi->cur_msg->status, 0); complete(&dspi->xfer_done); + } =20 return IRQ_HANDLED; } @@ -1069,7 +1069,6 @@ static int dspi_transfer_one_message(struct spi_contr= oller *ctlr, struct spi_device *spi =3D message->spi; struct spi_transfer *transfer; bool cs =3D false; - int status =3D 0; u32 val =3D 0; bool cs_change =3D false; =20 @@ -1129,7 +1128,7 @@ static int dspi_transfer_one_message(struct spi_contr= oller *ctlr, dspi->progress, !dspi->irq); =20 if (dspi->devtype_data->trans_mode =3D=3D DSPI_DMA_MODE) { - status =3D dspi_dma_xfer(dspi); + dspi_dma_xfer(dspi); } else { /* * Reinitialize the completion before transferring data @@ -1143,13 +1142,12 @@ static int dspi_transfer_one_message(struct spi_con= troller *ctlr, =20 dspi_fifo_write(dspi); =20 - if (dspi->irq) { + if (dspi->irq) wait_for_completion(&dspi->xfer_done); - } else { - status =3D dspi_poll(dspi); - } + else + dspi_poll(dspi); } - if (status) + if (READ_ONCE(message->status)) break; =20 spi_transfer_delay_exec(transfer); @@ -1158,7 +1156,8 @@ static int dspi_transfer_one_message(struct spi_contr= oller *ctlr, dspi_deassert_cs(spi, &cs); } =20 - if (status || !cs_change) { + dspi->cur_msg =3D NULL; + if (message->status || !cs_change) { /* Put DSPI in stop mode */ regmap_update_bits(dspi->regmap, SPI_MCR, SPI_MCR_HALT, SPI_MCR_HALT); @@ -1167,10 +1166,9 @@ static int dspi_transfer_one_message(struct spi_cont= roller *ctlr, ; } =20 - message->status =3D status; spi_finalize_current_message(ctlr); =20 - return status; + return message->status; } =20 static int dspi_set_mtf(struct fsl_dspi *dspi) --=20 2.34.1 From nobody Fri Oct 3 10:12:39 2025 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 011C12D3236 for ; Tue, 2 Sep 2025 12:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817172; cv=none; b=LmhWBE16ukJasRcLEdgtD5dzUUoByR4oB4XEPH7P6LPwlEwX4yF9nS9WNklaoknIdq1MwGeAY8SZvulQlI1gnqUvmx7j2tOtDWMHxjWwv0RDqUO6rz8+fwrty7asmTfEqpRYtp5ZgFeOA4rxr3FcJ7w6o3oExirgQZx7ee/lJVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817172; c=relaxed/simple; bh=HlSzFDl3cBqzMzO8EjTfysWzT0vHCTcl2hNct32AEQY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KI2Q3TXuA1kVzESqctMN+Qlw9TeymTSFCFadmNWcbAhrcPupug7Y5Mox4PXH87uiiCYgjgO+a8MmFHiW9uXe99x63tYykB79bg7nFusZDM2bCCPR/Vup25iUMTj3irB8uqyHUJOT1ZJ/1WLp5ZWZL2w5iEtTYtpKmndbTM8ava4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=dyQfY+5P; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dyQfY+5P" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3cf991e8c82so2825612f8f.3 for ; Tue, 02 Sep 2025 05:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756817169; x=1757421969; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8MLNcN+jIwemVKrw3ojUSNaEqKQ1kS6kcZrlQ+5OTVU=; b=dyQfY+5Pf80RXVRk/GSd7DF5u2jROkYXpgyJmwHGsdEBwqXjHmOKWFpzVSFeyhj8vA Q9mjFoTj5vSzqhvuf3javnZ2YTwV/hDMSslfonRzc0LbDv49dRbQp8KrPLIp/GC6Rgsm BwDbj60q6nUaKnvX8Tt1rXWnGuzaEjy2hP4tRuaXnhoR6+Cu0Kz3kEFe4jQ+QkEDCYLc mEBSj6N8n4UeM55AsEXKKdefjmfuYYgwPep5wiT0iEULKM7maOt5Nn6b6PReOwsrMLM9 eaHUzra+mYMGLlfiNqTUIuULIKSgIGjgm6d9ljPcqtwSqfL17pFqLqK1893ZFdtbDxDX /c3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756817169; x=1757421969; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8MLNcN+jIwemVKrw3ojUSNaEqKQ1kS6kcZrlQ+5OTVU=; b=LuRUNbgstj+5paRLHuhCvfXgyAF4d9sQzyOT0hsOb6S59Bzz5Bm6NsX+BhkmVyh90/ lW8QNoD4NwcyBU/Tj6WDNWdVozf1dW0Z6ZYv4NU58LjSrAjsr3A/Lpv43Ve7CdncuuTf ZqYSH9pMP8p7D3RUEB2M8zhB8z/a4R6LjO/Kwt6uugpU8Sc8bqMoqouoDj490vRZ0zRr vK5QtPwGDwgYqyGfcf0v0zUliB1nha/kzSW7Ue6laCt3Y6s6UXasXtfs0cMcWiSGhtG4 X1EP2Ln1ncCJKid1C2DOT3pofpZ8QGeI9wKE4OiHsRgU2WsoiaUSq1DaCtwSCSiN6OYB szcg== X-Forwarded-Encrypted: i=1; AJvYcCXcgmjYbw3SHCLaJ/er/wt89GM2eXkgvdrFL+nZquN/9afCjAIEaRf4xWUOWGRImLRs2HKb5VCaQxGLHzs=@vger.kernel.org X-Gm-Message-State: AOJu0Yyz3uiLK0NdXdQh09ClT0joXbrJW87xvOSJB2SSOoh09X9U+uVp wvrLB3r8e5dbhcn8hyGqp1NCrYCLUONZsLXuIYpwwPsUdRH+rT/XJkGuxyqxlLTqs7k= X-Gm-Gg: ASbGncsJbLf+9dp60lLMRAnm7ctJ87WEXyBAUD07W2KLAztbnc0S1kHU7YitBI8W9YV jjoonICYOXXQ9RbQ9nbjwXPw74yT9LU62WPN+zrN0cSiSBztJjyE0u7FHLpYjThbCErX0TF6jqL sZJ2ormx0PBfJcfhSk6RTs1K2k1VW4+PMc70pmo1ZQ3xtaUli7MBtaU1VF1jvPFNRCuQh8cVmTv BboLaTDsw/nxLY8q7AOAMEub/XNZFK9GZlDTAiwujwsLD/aL+Tiy2T+EddKeOL6S7A1C1kWYT00 IKDBih7GNdpMGuOHbxyznvK1ZUuYkP7G5oJMVOY/yMFbRCPWMMkwsfHXKj04P1qzlUat9fzE/5m 18h4xn2Kc46f/uI25B3JHvuU4Of+IlSk= X-Google-Smtp-Source: AGHT+IHRohpxYfReD2iQh67pxQ7xf/UxQzUzPqez9/ZzutPlA0iGuE6EAUDKZAfe7C8t7lupU0kMpw== X-Received: by 2002:a05:6000:268a:b0:3d4:2f8c:1d37 with SMTP id ffacd0b85a97d-3d42f8c2014mr8211307f8f.26.1756817169281; Tue, 02 Sep 2025 05:46:09 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cf275d2717sm19589896f8f.15.2025.09.02.05.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 05:46:08 -0700 (PDT) From: James Clark Date: Tue, 02 Sep 2025 13:44:55 +0100 Subject: [PATCH v6 3/7] spi: spi-fsl-dspi: Stub out DMA functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-james-nxp-spi-dma-v6-3-f7aa2c5e56e2@linaro.org> References: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> In-Reply-To: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> To: Vladimir Oltean , Mark Brown , Vladimir Oltean , Arnd Bergmann , Larisa Grigore , Frank Li , Christoph Hellwig Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 In a later commit we'll use dma_alloc_noncoherent() which isn't stubbed out for builds without CONFIG_DMA_ENGINE and results in the following build error: spi-fsl-dspi.c:(.text+0x644): undefined reference to `dma_free_pages' m68k-linux-ld: spi-fsl-dspi.c:(.text+0x67a): undefined reference to `dma_= free_pages' To continue to support devices that only need XSPI mode and so that randconfig builds work, stub out DMA functionality in the DSPI driver. Although older parts of the DMA API have their own stubs, it's intentional that newer parts don't follow the same pattern. Therefore individual drivers should not compile in calls unless CONFIG_DMA_ENGINE is set. Link: https://lore.kernel.org/oe-kbuild-all/202506160036.t9VDxF6p-lkp@intel= .com/ Signed-off-by: James Clark Reviewed-by: Vladimir Oltean --- drivers/spi/spi-fsl-dspi.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 48054932d517..0baf7e0608f2 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -373,6 +373,8 @@ struct fsl_dspi { void (*dev_to_host)(struct fsl_dspi *dspi, u32 rxdata); }; =20 +static void dspi_setup_accel(struct fsl_dspi *dspi); + static bool is_s32g_dspi(struct fsl_dspi *data) { return data->devtype_data =3D=3D &devtype_data[S32G] || @@ -468,6 +470,16 @@ static u32 dspi_pop_tx(struct fsl_dspi *dspi) return txdata; } =20 +/* Push one word to the RX buffer from the POPR register (RX FIFO) */ +static void dspi_push_rx(struct fsl_dspi *dspi, u32 rxdata) +{ + if (!dspi->rx) + return; + dspi->dev_to_host(dspi, rxdata); +} + +#if IS_ENABLED(CONFIG_DMA_ENGINE) + /* Prepare one TX FIFO entry (txdata plus cmd) */ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) { @@ -481,14 +493,6 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) return cmd << 16 | data; } =20 -/* Push one word to the RX buffer from the POPR register (RX FIFO) */ -static void dspi_push_rx(struct fsl_dspi *dspi, u32 rxdata) -{ - if (!dspi->rx) - return; - dspi->dev_to_host(dspi, rxdata); -} - static void dspi_tx_dma_callback(void *arg) { struct fsl_dspi *dspi =3D arg; @@ -589,8 +593,6 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *d= spi) return 0; } =20 -static void dspi_setup_accel(struct fsl_dspi *dspi); - static void dspi_dma_xfer(struct fsl_dspi *dspi) { struct spi_message *message =3D dspi->cur_msg; @@ -722,6 +724,18 @@ static void dspi_release_dma(struct fsl_dspi *dspi) dma_release_channel(dma->chan_rx); } } +#else +static void dspi_dma_xfer(struct fsl_dspi *dspi) +{ + dspi->cur_msg->status =3D -EINVAL; +} +static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr) +{ + dev_err(&dspi->pdev->dev, "DMA support not enabled in kernel\n"); + return -EINVAL; +} +static void dspi_release_dma(struct fsl_dspi *dspi) {} +#endif =20 static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, unsigned long clkrate, bool mtf_enabled) --=20 2.34.1 From nobody Fri Oct 3 10:12:39 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 118B117A306 for ; Tue, 2 Sep 2025 12:46:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817174; cv=none; b=IRcgPUhBGMsQxn9u3B/HGsJ7J+sTo2pf+14wuferaB29F1B4LXhybgWS6S/1CF2SmrY2zIJAfhaaAopC1UpSqyOctb/VOxohwFc+hTq7TT+q/JrxvKfMBKlYRkpyPQeZumPEkVkJKz1aCh1MGGSN81IsoUG4szgPJTKyTE8bQ4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817174; c=relaxed/simple; bh=dLXhXmGBVUdjGWO7AanK630sMzav+5Mv4ke+Z75scWY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gwz3epV9TUqmHInRNmHD4sqP/WQbIlfFAGTHg7CL0MjZuheGVJq5Lzqx8E2OaI2RUkODr/30ttpJoB3l4//dmuOBxvMJ/jAxJi9anA8/ucQy3atrMkisGGTVqkPK8PfhkdelMsDfUDFm0MoedSZs91OecxQ+xQs3QyuY0towhsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=bxnWJLCd; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bxnWJLCd" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3d1bf79d75aso1059598f8f.0 for ; Tue, 02 Sep 2025 05:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756817170; x=1757421970; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BsDT6IfRm3W35zg8rWWkO4jVs26qP9v/JAyh479nlAw=; b=bxnWJLCd/QOoTj6TyehjWiDDdYez1E5BGTsF5KROrpkTmqDIHSg8ELJELpDEyaxLo6 tB//SZ241cApKp+F9glGp4MsTU94TlZTIRC/n5AV6uafo1MEera5/qP6R5QrHu//4y15 x+MZWL6BCPifW6GiM5OpUL9xvjlnfx4lTmlO6dYTmgzlutKbKCLOV547vmiXSa3Vwjzq mQea/1RWZ3PGqOZscHbbyusFfBHrydGPEB+EFhld19Lq0tX+IKUwg0lKrMn0HIdOxVyz N+zh87ANdMR01Lai/mTxB7CcTAw1XAKNpqkKwSBA8OWP/NONR9YXbIce09wWMkhrsqpB zZCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756817170; x=1757421970; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BsDT6IfRm3W35zg8rWWkO4jVs26qP9v/JAyh479nlAw=; b=DCc+M9ffDis6w2BtU+XqI6/4b887DbTyaQBp99Gs4GW3Nw3O6Z0v97YxRX3hbjhsol wyxnY/3drSou/1tCDyPDtyCsHVcdFfAk5vUvJ+/C3+TRu9flQkdEIEH3A45MlsWmsk5m aCVC0lClZyX7H4H/k3wicGW5NS1Q5fKExYJHD/WxKbQNuDu2UCt8sw+WXk1IojMWsiJe l+aCT8o7xjJoPGa4SSOvlcoHZXV9xSMci6aCij3IdPKTSf7H3TFMUH5q1dUO2mCZXQ+b lHtckZ48C/5eF5j6aD6FgWIHmdabKTphjsXQRS5FCJahpSdcEOPn0N0Vvuy+YJPijo5H 0vbw== X-Forwarded-Encrypted: i=1; AJvYcCUYfzI1VMIcoP87xkb5uUKNxT230Sbo/fODLszr55quoKxn4MMYA6DTbefyuu8BXpVh3nuODYqbN2nq52U=@vger.kernel.org X-Gm-Message-State: AOJu0YwYylqhkpat2XqThSaG6RCWK31pXmJGZI+rMcnoPOAs4WfSTi8P w8GXsPGBitRMRhzGSoETFos/HaXBewuo/cyv3OhPBYSlBc7JANwKWNB3l5m1ySteA24= X-Gm-Gg: ASbGnctoiBHxnnhqD0FQlkeiD91qNHKOfA84JT96/POOTLk6lrJNWC7cKbHOHIpgDov f8pE8xSi/nlsTVeYDffMAbAmAa8RvKA4Kx6UEsQdEps7p0yZKRwia/oUsvluANfTxH1LRhNGv78 YtDzovykznkgTY8YLeETYbHWWYDdC895+N8E9zcNd4iqXCmYPtcGSXTVnfV/x+qSgFWHqLaTR1G KnGoceLcut7KRxJS94yeKp1MqA5WOanyYe3O2pV3BOZ1hBep1zcqV8L/K38dFSXXGOz8Yhlvuxi xHZvyo/sgq5oFoqy6iJvvcW2Hnm7X10XttOvHMsyP35pB5wzNoXHRkl3Lfz5xXGO0pcloaT/f20 6sF/Zgk63xsavgHBT+HrYhvzoBAqAZWvb8UuJDAlnJg== X-Google-Smtp-Source: AGHT+IEwUKz3nl2krF2wHyMlpvQhNKTtJiOLQm9e9D7oVD/bUvk+dX6eDVCzpUFwJ4wbqE7UxEr79w== X-Received: by 2002:a05:6000:2212:b0:3b9:14f2:7edf with SMTP id ffacd0b85a97d-3d1af84bfd1mr7494714f8f.1.1756817170353; Tue, 02 Sep 2025 05:46:10 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cf275d2717sm19589896f8f.15.2025.09.02.05.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 05:46:09 -0700 (PDT) From: James Clark Date: Tue, 02 Sep 2025 13:44:56 +0100 Subject: [PATCH v6 4/7] spi: spi-fsl-dspi: Use non-coherent memory for DMA Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-james-nxp-spi-dma-v6-4-f7aa2c5e56e2@linaro.org> References: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> In-Reply-To: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> To: Vladimir Oltean , Mark Brown , Vladimir Oltean , Arnd Bergmann , Larisa Grigore , Frank Li , Christoph Hellwig Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, James Clark , Frank Li X-Mailer: b4 0.14.0 Using coherent memory here isn't functionally necessary, we're only either sending data to the device or reading from it. This means explicit synchronizations are only required around those points and the change is fairly trivial. This gives us around a 10% increase in throughput for large DMA transfers and no loss for small transfers. Suggested-by: Arnd Bergmann Reviewed-by: Frank Li Acked-by: Arnd Bergmann Signed-off-by: James Clark Reviewed-by: Vladimir Oltean --- drivers/spi/spi-fsl-dspi.c | 65 +++++++++++++++++++++++++++++-------------= ---- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 0baf7e0608f2..81d1e4470f94 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -493,11 +493,19 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) return cmd << 16 | data; } =20 +static size_t dspi_dma_transfer_size(struct fsl_dspi *dspi) +{ + return dspi->words_in_flight * DMA_SLAVE_BUSWIDTH_4_BYTES; +} + static void dspi_tx_dma_callback(void *arg) { struct fsl_dspi *dspi =3D arg; struct fsl_dspi_dma *dma =3D dspi->dma; + struct device *dev =3D &dspi->pdev->dev; =20 + dma_sync_single_for_cpu(dev, dma->tx_dma_phys, + dspi_dma_transfer_size(dspi), DMA_TO_DEVICE); complete(&dma->cmd_tx_complete); } =20 @@ -505,9 +513,13 @@ static void dspi_rx_dma_callback(void *arg) { struct fsl_dspi *dspi =3D arg; struct fsl_dspi_dma *dma =3D dspi->dma; + struct device *dev =3D &dspi->pdev->dev; int i; =20 if (dspi->rx) { + dma_sync_single_for_cpu(dev, dma->rx_dma_phys, + dspi_dma_transfer_size(dspi), + DMA_FROM_DEVICE); for (i =3D 0; i < dspi->words_in_flight; i++) dspi_push_rx(dspi, dspi->dma->rx_dma_buf[i]); } @@ -517,6 +529,7 @@ static void dspi_rx_dma_callback(void *arg) =20 static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) { + size_t size =3D dspi_dma_transfer_size(dspi); struct device *dev =3D &dspi->pdev->dev; struct fsl_dspi_dma *dma =3D dspi->dma; int time_left; @@ -525,12 +538,12 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi = *dspi) for (i =3D 0; i < dspi->words_in_flight; i++) dspi->dma->tx_dma_buf[i] =3D dspi_pop_tx_pushr(dspi); =20 + dma_sync_single_for_device(dev, dma->tx_dma_phys, size, DMA_TO_DEVICE); dma->tx_desc =3D dmaengine_prep_slave_single(dma->chan_tx, - dma->tx_dma_phys, - dspi->words_in_flight * - DMA_SLAVE_BUSWIDTH_4_BYTES, - DMA_MEM_TO_DEV, - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); + dma->tx_dma_phys, size, + DMA_MEM_TO_DEV, + DMA_PREP_INTERRUPT | + DMA_CTRL_ACK); if (!dma->tx_desc) { dev_err(dev, "Not able to get desc for DMA xfer\n"); return -EIO; @@ -543,12 +556,13 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi = *dspi) return -EINVAL; } =20 + dma_sync_single_for_device(dev, dma->rx_dma_phys, size, + DMA_FROM_DEVICE); dma->rx_desc =3D dmaengine_prep_slave_single(dma->chan_rx, - dma->rx_dma_phys, - dspi->words_in_flight * - DMA_SLAVE_BUSWIDTH_4_BYTES, - DMA_DEV_TO_MEM, - DMA_PREP_INTERRUPT | DMA_CTRL_ACK); + dma->rx_dma_phys, size, + DMA_DEV_TO_MEM, + DMA_PREP_INTERRUPT | + DMA_CTRL_ACK); if (!dma->rx_desc) { dev_err(dev, "Not able to get desc for DMA xfer\n"); return -EIO; @@ -643,17 +657,17 @@ static int dspi_request_dma(struct fsl_dspi *dspi, ph= ys_addr_t phy_addr) goto err_tx_channel; } =20 - dma->tx_dma_buf =3D dma_alloc_coherent(dma->chan_tx->device->dev, - dma_bufsize, &dma->tx_dma_phys, - GFP_KERNEL); + dma->tx_dma_buf =3D dma_alloc_noncoherent(dma->chan_tx->device->dev, + dma_bufsize, &dma->tx_dma_phys, + DMA_TO_DEVICE, GFP_KERNEL); if (!dma->tx_dma_buf) { ret =3D -ENOMEM; goto err_tx_dma_buf; } =20 - dma->rx_dma_buf =3D dma_alloc_coherent(dma->chan_rx->device->dev, - dma_bufsize, &dma->rx_dma_phys, - GFP_KERNEL); + dma->rx_dma_buf =3D dma_alloc_noncoherent(dma->chan_rx->device->dev, + dma_bufsize, &dma->rx_dma_phys, + DMA_FROM_DEVICE, GFP_KERNEL); if (!dma->rx_dma_buf) { ret =3D -ENOMEM; goto err_rx_dma_buf; @@ -688,11 +702,12 @@ static int dspi_request_dma(struct fsl_dspi *dspi, ph= ys_addr_t phy_addr) return 0; =20 err_slave_config: - dma_free_coherent(dma->chan_rx->device->dev, - dma_bufsize, dma->rx_dma_buf, dma->rx_dma_phys); + dma_free_noncoherent(dma->chan_rx->device->dev, dma_bufsize, + dma->rx_dma_buf, dma->rx_dma_phys, + DMA_FROM_DEVICE); err_rx_dma_buf: - dma_free_coherent(dma->chan_tx->device->dev, - dma_bufsize, dma->tx_dma_buf, dma->tx_dma_phys); + dma_free_noncoherent(dma->chan_tx->device->dev, dma_bufsize, + dma->tx_dma_buf, dma->tx_dma_phys, DMA_TO_DEVICE); err_tx_dma_buf: dma_release_channel(dma->chan_tx); err_tx_channel: @@ -713,14 +728,16 @@ static void dspi_release_dma(struct fsl_dspi *dspi) return; =20 if (dma->chan_tx) { - dma_free_coherent(dma->chan_tx->device->dev, dma_bufsize, - dma->tx_dma_buf, dma->tx_dma_phys); + dma_free_noncoherent(dma->chan_tx->device->dev, dma_bufsize, + dma->tx_dma_buf, dma->tx_dma_phys, + DMA_TO_DEVICE); dma_release_channel(dma->chan_tx); } =20 if (dma->chan_rx) { - dma_free_coherent(dma->chan_rx->device->dev, dma_bufsize, - dma->rx_dma_buf, dma->rx_dma_phys); + dma_free_noncoherent(dma->chan_rx->device->dev, dma_bufsize, + dma->rx_dma_buf, dma->rx_dma_phys, + DMA_FROM_DEVICE); dma_release_channel(dma->chan_rx); } } --=20 2.34.1 From nobody Fri Oct 3 10:12:39 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 104922D541E for ; Tue, 2 Sep 2025 12:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817175; cv=none; b=HIxWw8/dOA55JeDAvocpbgw4Z/eE+vNTAamtHOzfIAaumwctxNcrCz3MkccVCrw56auRuKldkBbP0GkUKzrAXloVuLutn1VDecUh+sXX3QYGdfww5hIlO+tKQNI1vgDtaYDbI+yMqdHUtgi8Sqbq1gOXZu9RRdfhb517mEClqto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817175; c=relaxed/simple; bh=v/uxCKJdP+2z/SZsRX7qf7nC3a/OLUNE6hFHvBrITqQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eCDXfYZtiQkCrf0S3r5gNHkKmctoGpekHwugkIFnSpjwbXATGbu/DJyDgRaJ9yvxg2+7douhrtoM4IKWrOFeGw+05Y8w8zEhCo7ZbHjaILDGh6UtlnlIA2DWv6xmHafWOqPk3ZlK4FwDUZYgW2zy9SLcfPuOMrG+yJX+g582iMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=li2BReH+; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="li2BReH+" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3d1bf79d7acso1840386f8f.0 for ; Tue, 02 Sep 2025 05:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756817171; x=1757421971; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=zO3e10lREs9p/eEtCUsOWQlh8TKJIiFbHYmIoKfi80M=; b=li2BReH+E1pcIs3feeQPnCAZZPf7oheRfl3dk3mu+TVex/N1F2jKk6rShlJORpCE9B SqNHigthQZQUik0egBjm6dvW7PxsqFC3bE7UI/xbZaztr8O5W46ZQ4bFCtmHSKiWZwgY aJvZduD9DOwU648ai3mPFbv6u3Dn9/18REZC8WUSwMFYKGHTHdxGp1c8Q8pC6B0KwV4Y NfPK4BCjqIcB0e9qJur1fUXkco0r6ODNxYjJU1KXPX6wn3XAOK9V4iMneXcP54cdpV99 HKTyEpUJoOpWxzJEUIjSYEqmPA3DGIooY2DELf6gQdrJujTAqZ9nbQyzaqCdbnWSUjmC jMpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756817171; x=1757421971; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zO3e10lREs9p/eEtCUsOWQlh8TKJIiFbHYmIoKfi80M=; b=Oi2cLuVQOtKUXmU3Xbn/jrinYmJf8KFeiOayXmxJtel1zi8pwo5immvC9V6d+Xce/A ElxDhjPLCd05mu/1twpOVJPXFbxMVF28VacFyQgbEJF5SJYHsqCu/92e3T+Kbx4OxSMk wZzKIFmPjv35Udax18mFTNMxQHvOXa46I46ujbZxfxQrHFnFDyR840j/n0po1/Sy2ODg cf0Ksz6s3FTCGS2pFHxkZmRKXTHPr9CPgYM7MjIF/xqV7MAmqF2bXuckLaOj3iWDiiAe LTs2/HxlJvJH8JalSurhY9XxF4eem/IBSDItarIpfsgSUfG2Bt8BE2NQ8B3WeQgn+mn6 rBWA== X-Forwarded-Encrypted: i=1; AJvYcCVoxLwUaDnn7fQoXQV/RbSVOKRuAL6SCP/b7zave+aiUKv8aL8XDsQcNNGOQIAfWgbxqAknt8etVSoyOXM=@vger.kernel.org X-Gm-Message-State: AOJu0YwwJdM63dL1WGjoMekM5x867B7cj9ptWNtW1MO3fNwc4myZnDvU FaHSTHz8PfdRXK3DWBK/pkjjFsRVzA+0Hd1YYZSfNpRD+McqztWeKe2JLAWKIunkJfcHBnCalBN AyF1tZKM= X-Gm-Gg: ASbGncu+TCWB0I+0uLt89ylvv+wjLsoZP2KVOmYliOKb9nX+GHvOS0dU8N2xYw31LtW onztcrFQZaUJmYbZlrVAijlG3YiHaH6fwMq1akTVZMwM0noi9EU1qWtWpf/nB4+HfecntDs9Fqk sncnmQ4ugn4W0rGmhvhV4EDPyIQCO2Ay+wIz7Tyxn35hRxdD/oJGcypHjUEj2TE0teuNe3eJv/2 9HrkjVB6wuR7CBDKNhd67RFdTIavMWrdd0zxvYjf0l7poYfgxqmVstId70fAZWme1w/M7Qobp0l X2D+yOjftisqFh4qLm+hlTnmIxJKGxhiEtlED4gsXj9T0piUUTsGcw4NO+4Uh4a/dvzhwIYfggG K5MmRVi/xvAm+53Zm3z9E3epdQRaVHNc8912gj/y9kw== X-Google-Smtp-Source: AGHT+IFBOztEmu3TQb+b78WlUZhWND4Jix1WfelrhLf0L9O3+fhi7YgD88/+Eg01QZasQk34F4HsBA== X-Received: by 2002:a05:6000:2112:b0:3d2:6129:5505 with SMTP id ffacd0b85a97d-3d261295a85mr7852150f8f.36.1756817171365; Tue, 02 Sep 2025 05:46:11 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cf275d2717sm19589896f8f.15.2025.09.02.05.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 05:46:10 -0700 (PDT) From: James Clark Date: Tue, 02 Sep 2025 13:44:57 +0100 Subject: [PATCH v6 5/7] spi: spi-fsl-dspi: Use whole page for DMA buffers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-james-nxp-spi-dma-v6-5-f7aa2c5e56e2@linaro.org> References: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> In-Reply-To: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> To: Vladimir Oltean , Mark Brown , Vladimir Oltean , Arnd Bergmann , Larisa Grigore , Frank Li , Christoph Hellwig Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 dma_alloc_noncoherent() allocations are backed by a full page anyway, so use it all. VF610 devices used to use the full page before commit a957499bd437 ("spi: spi-fsl-dspi: Fix bits-per-word acceleration in DMA mode"), but others still used the FIFO size. After that commit, all devices used the FIFO size. Now all devices use the full page. Signed-off-by: James Clark Reviewed-by: Vladimir Oltean --- drivers/spi/spi-fsl-dspi.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 81d1e4470f94..6bf87ef01c13 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -331,6 +331,8 @@ struct fsl_dspi_dma { dma_addr_t rx_dma_phys; struct completion cmd_rx_complete; struct dma_async_tx_descriptor *rx_desc; + + size_t bufsize; }; =20 struct fsl_dspi { @@ -493,6 +495,24 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) return cmd << 16 | data; } =20 +static size_t dspi_dma_max_datawords(struct fsl_dspi *dspi) +{ + /* + * Transfers look like one of these, so we always use a full DMA word + * regardless of SPI word size: + * + * 31 16 15 0 + * ----------------------------------------- + * | CONTROL WORD | 16-bit DATA | + * ----------------------------------------- + * or + * ----------------------------------------- + * | CONTROL WORD | UNUSED | 8-bit DATA | + * ----------------------------------------- + */ + return dspi->dma->bufsize / DMA_SLAVE_BUSWIDTH_4_BYTES; +} + static size_t dspi_dma_transfer_size(struct fsl_dspi *dspi) { return dspi->words_in_flight * DMA_SLAVE_BUSWIDTH_4_BYTES; @@ -620,9 +640,8 @@ static void dspi_dma_xfer(struct fsl_dspi *dspi) /* Figure out operational bits-per-word for this chunk */ dspi_setup_accel(dspi); =20 - dspi->words_in_flight =3D dspi->len / dspi->oper_word_size; - if (dspi->words_in_flight > dspi->devtype_data->fifo_size) - dspi->words_in_flight =3D dspi->devtype_data->fifo_size; + dspi->words_in_flight =3D min(dspi->len / dspi->oper_word_size, + dspi_dma_max_datawords(dspi)); =20 message->actual_length +=3D dspi->words_in_flight * dspi->oper_word_size; @@ -637,7 +656,6 @@ static void dspi_dma_xfer(struct fsl_dspi *dspi) =20 static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr) { - int dma_bufsize =3D dspi->devtype_data->fifo_size * 2; struct device *dev =3D &dspi->pdev->dev; struct dma_slave_config cfg; struct fsl_dspi_dma *dma; @@ -657,8 +675,10 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phy= s_addr_t phy_addr) goto err_tx_channel; } =20 + dma->bufsize =3D PAGE_SIZE; + dma->tx_dma_buf =3D dma_alloc_noncoherent(dma->chan_tx->device->dev, - dma_bufsize, &dma->tx_dma_phys, + dma->bufsize, &dma->tx_dma_phys, DMA_TO_DEVICE, GFP_KERNEL); if (!dma->tx_dma_buf) { ret =3D -ENOMEM; @@ -666,7 +686,7 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys= _addr_t phy_addr) } =20 dma->rx_dma_buf =3D dma_alloc_noncoherent(dma->chan_rx->device->dev, - dma_bufsize, &dma->rx_dma_phys, + dma->bufsize, &dma->rx_dma_phys, DMA_FROM_DEVICE, GFP_KERNEL); if (!dma->rx_dma_buf) { ret =3D -ENOMEM; @@ -702,11 +722,11 @@ static int dspi_request_dma(struct fsl_dspi *dspi, ph= ys_addr_t phy_addr) return 0; =20 err_slave_config: - dma_free_noncoherent(dma->chan_rx->device->dev, dma_bufsize, + dma_free_noncoherent(dma->chan_rx->device->dev, dma->bufsize, dma->rx_dma_buf, dma->rx_dma_phys, DMA_FROM_DEVICE); err_rx_dma_buf: - dma_free_noncoherent(dma->chan_tx->device->dev, dma_bufsize, + dma_free_noncoherent(dma->chan_tx->device->dev, dma->bufsize, dma->tx_dma_buf, dma->tx_dma_phys, DMA_TO_DEVICE); err_tx_dma_buf: dma_release_channel(dma->chan_tx); @@ -721,21 +741,20 @@ static int dspi_request_dma(struct fsl_dspi *dspi, ph= ys_addr_t phy_addr) =20 static void dspi_release_dma(struct fsl_dspi *dspi) { - int dma_bufsize =3D dspi->devtype_data->fifo_size * 2; struct fsl_dspi_dma *dma =3D dspi->dma; =20 if (!dma) return; =20 if (dma->chan_tx) { - dma_free_noncoherent(dma->chan_tx->device->dev, dma_bufsize, + dma_free_noncoherent(dma->chan_tx->device->dev, dma->bufsize, dma->tx_dma_buf, dma->tx_dma_phys, DMA_TO_DEVICE); dma_release_channel(dma->chan_tx); } =20 if (dma->chan_rx) { - dma_free_noncoherent(dma->chan_rx->device->dev, dma_bufsize, + dma_free_noncoherent(dma->chan_rx->device->dev, dma->bufsize, dma->rx_dma_buf, dma->rx_dma_phys, DMA_FROM_DEVICE); dma_release_channel(dma->chan_rx); --=20 2.34.1 From nobody Fri Oct 3 10:12:39 2025 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B2C42DA755 for ; Tue, 2 Sep 2025 12:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817176; cv=none; b=Nt6/OYAD1LM5ZCnTTB7zkoWONSYwBSnWYo1ZVVLiESqQin9VN77l7C9dtFVqaelt5pzlOiVVcO+UtNpFjDsV2F8MiQNUFAZiiDFu8Q8jwCmiMwQJmZ5H4KKVtZA6CLr1k4s58L+zxjsHcDcfrR+IlPbb6n+VGbkVBmTRyBa8ajI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817176; c=relaxed/simple; bh=xSF+c1quUfEBbfl25vLH7FmwBetOvWPbpnPjJk15kZo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LjNeOF6AxEG6TlnsS1Cx4x1tk8Ro2PrIjPfR+almAAJa29QSiQDOA6U5oWNCg8e7EV3IFGrBjMmNzDPBO6jCNfvedDdN9nh6NZHoANFus2Z9G3NnisWYeQxEM909KTZnPuEGlZBsaNu7iuQpeht3al9KIm38cUrjJWX9Gppu4YQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=zJc6m8TQ; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zJc6m8TQ" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3d3ff4a4d6fso1799418f8f.0 for ; Tue, 02 Sep 2025 05:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756817172; x=1757421972; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jMvtg5Mq6C/ZSIJ0uJaRfjqxGAaFFsi0SLuwvNPDC3w=; b=zJc6m8TQ05bQPU2RlNZ8v+6oQyr3Fbe+cf4F4//H1hlMJ35KyqYVR+cXj5HkTq2fHN aFogATpc33m0oVEc2lOC7rvHx/2GBwP2QURgMGIDnwd0iU7h4HuuTU6BORPpKLa1VG6z LL0g90qAoGibeENia0UQQXVGyxaCTtjBOpzkk273srnbIq1nVCnuTl/Fbe9FCQ5tsVkf sNHq/NfuWbb3sv5TzUPOy6VfzkjDbWqNcHpmN1Z5mm9WD1PYM5kDOsPVOeDpAMtpVEQS kJ0Ucp074yAi6FgjxNH+1EZEKxMRnzlE5rrDXsYH/h0Cn9GJoPDNYCEpHsDeZuF2FmAv d5Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756817172; x=1757421972; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jMvtg5Mq6C/ZSIJ0uJaRfjqxGAaFFsi0SLuwvNPDC3w=; b=pDu9NTtBS/lMPCuehzh/TxRPrf/RqEXasYq9xhvXRzbJkM1qsFXyL3eOGJB7wkknjo 8Kq0POYUH+6uxNXFwzjkusTKKbm5P0ZNaeDombH5rayH0baUJm3audD49799XRSkk8vZ 9Wqy1n5P4QJG2kBMPUzifcPAlvDSL9hegUlhLxBDnxKRljMMRkK+Zrs4GA9PprEQV1RT WAQfrGwX1dCpnBoW1rywDX7rhJDNPSR8g50hWHofv75/ysalzP1XVSMqqsAf33NOjQF+ G9e06Leu4kTCFlz1v5b6MLiTh+tnyEJinRMIncEre00dWVEsro5oK1pDIrtkM1nJtm9B ssIg== X-Forwarded-Encrypted: i=1; AJvYcCUGmR+iz/EKjmqvEju/+MIjGt2V+J3VfbEfMr7/VGGH15YVPPhcAmwZVDHumkRm+epmTHRTsXuKzZ+takQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxXi+OLIyprafJ8n9bjTwWMc3GROjBmawNOOG9Nq7nzqkvexXwV 33yFP0uAxpKLgnfmFy9+C0zqw/E6/LCuVnzNJj45IxP+Bs9YR7nY96joIUsxmzCARDU= X-Gm-Gg: ASbGncsquArT/uRU8HQldQz1JXtRc5UUxMaSjmrtQOkU/7L9kqScBlqu/wYKZi3Q9vn j6vrOD/xrrwv8HycEH5IniAKTLeL/kUhPtxUay/XZDt9e8qsl+Z22FnBk0Hj6wnbuSgvfKtByW2 gaLL3DgAJVAoQ0/nubi0QQ8vQTDjc7r+9C2uDk/BJgP5ZO3dtckyYDGOv8VtKYtiXraYvC0mGnl WLn5X1KKPYAWt/krr60hFTM7rZQmmlqYnJOgfGBAg2l9DWR8gPJR8Gp7irR1kgu+dUmd3NvXBD9 iYwZYMC1eEcwpvZxBZuRREj9VR3sDpWDlhYeew7EH1XzvSrKFOPFRRZw1Noh4wEW6HguF7tLNjH FUUJttuSSc+y6eFKQbQMxdIqF/y6pLrE= X-Google-Smtp-Source: AGHT+IHHnLIfKXefUkGxa5EfKnESKjlVPeyNiNsifBpBQEufQVD811lASeZ0fiPvah3xuHy5ugya8g== X-Received: by 2002:a05:6000:3110:b0:3d0:b3cc:c1ff with SMTP id ffacd0b85a97d-3d1de4bc2e1mr9092247f8f.39.1756817172368; Tue, 02 Sep 2025 05:46:12 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cf275d2717sm19589896f8f.15.2025.09.02.05.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 05:46:11 -0700 (PDT) From: James Clark Date: Tue, 02 Sep 2025 13:44:58 +0100 Subject: [PATCH v6 6/7] spi: spi-fsl-dspi: Increase target mode DMA buffer size Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-james-nxp-spi-dma-v6-6-f7aa2c5e56e2@linaro.org> References: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> In-Reply-To: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> To: Vladimir Oltean , Mark Brown , Vladimir Oltean , Arnd Bergmann , Larisa Grigore , Frank Li , Christoph Hellwig Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 When the device is configured as a target, the host won't stop sending data while we're draining the buffer which leads to FIFO underflows and corruption. Increase the DMA buffer size to the maximum words that edma can transfer once to reduce the chance of this happening. In host mode, the driver is able to split up a transfer into smaller chunks so we don't need to increase the size. While in target mode, the length of the transfer is determined by the remote host and can be larger than whatever default buffer size we pick. Keeping the buffer small in host mode avoids wasting memory, but allocating the largest possible in target mode gives the lowest possible chance of dropping any data from the host. While we could allocate per-transfer using the exact size of the transfer, 128K is quite a large allocation and there is a chance it could fail due to memory fragmentation unless it's allocated once at init time. Signed-off-by: Larisa Grigore Signed-off-by: James Clark Reviewed-by: Vladimir Oltean --- drivers/spi/spi-fsl-dspi.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 6bf87ef01c13..3d29285c772c 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -675,7 +675,18 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phy= s_addr_t phy_addr) goto err_tx_channel; } =20 - dma->bufsize =3D PAGE_SIZE; + if (spi_controller_is_target(dspi->ctlr)) { + /* + * In target mode we have to be ready to receive the maximum + * that can possibly be transferred at once by EDMA without any + * FIFO underflows. + */ + dma->bufsize =3D min(dma_get_max_seg_size(dma->chan_rx->device->dev), + dma_get_max_seg_size(dma->chan_tx->device->dev)) * + DMA_SLAVE_BUSWIDTH_4_BYTES; + } else { + dma->bufsize =3D PAGE_SIZE; + } =20 dma->tx_dma_buf =3D dma_alloc_noncoherent(dma->chan_tx->device->dev, dma->bufsize, &dma->tx_dma_phys, --=20 2.34.1 From nobody Fri Oct 3 10:12:39 2025 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D6742DAFDE for ; Tue, 2 Sep 2025 12:46:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817178; cv=none; b=Tjms6m9vMubwb1a6VEadNqm6et412f2FMIDO2HtaY7bRNv6IUuZZf7PrKAgtbFlvBPYSARHVxerzEGHgonRvtiUBxnMC21mxX3+MskBY2dOSJ4W5+ZxuKiQ9OX8c1Xd86+Wk5IOTSpnRrGoRGLjRze/CCjXfrZVztA5h6EIwoEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756817178; c=relaxed/simple; bh=fDy13d0jadoNgDpWip0eDAJ9ZTQEC7MeqwnmLrMOq3g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GK3gxXgv5vdVT7NYUGRrxRVJxJea+B1ApbCn4rsa1ejAYm+uP9N4wBCAg4vEFUv0ZGD6e8aunqp8ja+4s6YTeqGGtNdaDVRdqYBsNaY8EUOw0nF06De20SuaEmhwcPYJ1hqqkbol1WOyNN1hzY5POEtOBaT1oKbNjUk6IpuiiHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=orTCVXt/; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="orTCVXt/" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-3da9ad0c1f4so439393f8f.3 for ; Tue, 02 Sep 2025 05:46:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756817173; x=1757421973; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=t/upoONcJkK6CJjYHWkLIMw2CILsxwp/wVjDokkLyWs=; b=orTCVXt/bLmQ7sXY0Sj2MNp4u05xO8G1i1fmSxX/nrFZuCcI4eEjzu+RMDpyrK8dyi Sf0wLuaFSkbJOSUV83XCdvhRhOxS0HLspUF/rV8UZEWjbFSh620lSQdnqaiTwpRGXTNC zYwp667oEcsH4D3lly/alGcPCPayxUCd7gJW3EfvUYi3r0F8hdhT8NvVwDbs+7/HHVK3 NaWFUuhvhf4lV6AtQVYVOk2Cpk+m/wK3atEzUlMTgqPM+y4OjxBe57Ldz+hW7OmXJkly fUR4K75lBbKT/WbgiIz7HB16CjJisO2GZvVfDpc/Sr20j7S2MUYO5HicGtc50g3rwqHY VbDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756817173; x=1757421973; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t/upoONcJkK6CJjYHWkLIMw2CILsxwp/wVjDokkLyWs=; b=AlZjV476h+s3k0Yla6jnL6NkK8gpGR9lIS75cHMj3zRyHOLiFMEZENKktN7nsc7LH7 3y5ElYmqCF/bJ+ct3s83O9zXUuMqCsOuIZh4jFSU0zdgZk+CnjPvEmX6naNpQ8aVTe+u FJiuC1Yaz8GF5+pUxn6nAA4JMEo98rhvRIvnCmgMdbrSdzymEOtjLfV/XvEMj6odW14k CAVW6q8ELbzwWAR3N3uu0plv5UvEowqNypMU2EqzErbcc+hqAx9owy/5qRcI9oC9KC17 B/zjUL4aGBB0UQQv5rP8epwfbccHu4xyIZhl3i2ka7uon5R3LShQbJdPri9bEAXfpRJX bPFA== X-Forwarded-Encrypted: i=1; AJvYcCWZGNFJ1pUQXthSTXhzgGyZAYyoAFfWCOfgSr9xj8u33ZYja3AaUvm7xCDHa8y1wWuuEy3449PSBxpHNuY=@vger.kernel.org X-Gm-Message-State: AOJu0YyICHPjLWhi/UfPZuXPrFDplgYmWgRUm5gD4a2oyw/5qGd98DYj OO/4WdxZJwgQtzsXlS7XMvCDcefw/+qfgHPWECTzKO/nke6maIasiQkY5Q7DlnTDgFoczDOAweS Vjw+v1II= X-Gm-Gg: ASbGncsFOuVJnUdF93SzGAmYVYPWyv2/pW+tiPgmh1k9H9LiwV8rEY+gnJ4n0Mkmyjr HMJIwnZQKCyKxJuqfkXHiHPYSCW160IoolDOorbwQBnd/ljFu0RUc6SgrknmLA1s+YD+ZYLFinc I+P88BuhXa2Y846axhLojHOuMzh5/nUf7l9QNHFdvdjd7S0WQi0ytaICH16aW3JixqnZrD400nL zXu5qoniV+Qg9UMW5R60cJ8PAOnOmTeGibOme1DXOxaf9EB8Ytbjn8VgFE0Xtjyd27GXBFBH/fY 2fFcAHXzTmxiUjZC+rT2PhUCtiyZY6zYgQ9SSBbVpik/GV8+70TciNx68SN+Lo3nlUFBLVeJQM4 DFR6w6EE249MUNRg4MV7Qr1ixNTCcMjyr0+x/4YUwvg== X-Google-Smtp-Source: AGHT+IG6jUoitTgiFTXdSrwMTL/OoQio/BlhVxzRStwKd/kUGsgb2XZinkbeZSLm7z/B6IiziT0tBQ== X-Received: by 2002:a05:6000:1883:b0:3c0:7e30:a95f with SMTP id ffacd0b85a97d-3d1e0a94fbfmr9044471f8f.60.1756817173362; Tue, 02 Sep 2025 05:46:13 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cf275d2717sm19589896f8f.15.2025.09.02.05.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 05:46:12 -0700 (PDT) From: James Clark Date: Tue, 02 Sep 2025 13:44:59 +0100 Subject: [PATCH v6 7/7] spi: spi-fsl-dspi: Report FIFO overflows as errors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250902-james-nxp-spi-dma-v6-7-f7aa2c5e56e2@linaro.org> References: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> In-Reply-To: <20250902-james-nxp-spi-dma-v6-0-f7aa2c5e56e2@linaro.org> To: Vladimir Oltean , Mark Brown , Vladimir Oltean , Arnd Bergmann , Larisa Grigore , Frank Li , Christoph Hellwig Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, James Clark X-Mailer: b4 0.14.0 In target mode, the host sending more data than can be consumed would be a common problem for any message exceeding the FIFO or DMA buffer size. Cancel the whole message as soon as this condition is hit as the message will be corrupted. Only do this for target mode in a DMA transfer, it's not likely these flags will be set in host mode so it's not worth adding extra checks. In IRQ and polling modes we use the same transfer functions for hosts and targets so the error flags always get checked. This is slightly inconsistent but it's not worth doing the check conditionally because it may catch some host programming errors in the future. Signed-off-by: James Clark Reviewed-by: Vladimir Oltean --- drivers/spi/spi-fsl-dspi.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 3d29285c772c..83ea296597e9 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -480,6 +480,17 @@ static void dspi_push_rx(struct fsl_dspi *dspi, u32 rx= data) dspi->dev_to_host(dspi, rxdata); } =20 +static int dspi_fifo_error(struct fsl_dspi *dspi, u32 spi_sr) +{ + if (spi_sr & (SPI_SR_TFUF | SPI_SR_RFOF)) { + dev_err_ratelimited(&dspi->pdev->dev, "FIFO errors:%s%s\n", + spi_sr & SPI_SR_TFUF ? " TX underflow," : "", + spi_sr & SPI_SR_RFOF ? " RX overflow," : ""); + return -EIO; + } + return 0; +} + #if IS_ENABLED(CONFIG_DMA_ENGINE) =20 /* Prepare one TX FIFO entry (txdata plus cmd) */ @@ -553,6 +564,7 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *d= spi) struct device *dev =3D &dspi->pdev->dev; struct fsl_dspi_dma *dma =3D dspi->dma; int time_left; + u32 spi_sr; int i; =20 for (i =3D 0; i < dspi->words_in_flight; i++) @@ -603,7 +615,8 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *d= spi) =20 if (spi_controller_is_target(dspi->ctlr)) { wait_for_completion_interruptible(&dspi->dma->cmd_rx_complete); - return 0; + regmap_read(dspi->regmap, SPI_SR, &spi_sr); + return dspi_fifo_error(dspi, spi_sr); } =20 time_left =3D wait_for_completion_timeout(&dspi->dma->cmd_tx_complete, @@ -1073,6 +1086,10 @@ static void dspi_poll(struct fsl_dspi *dspi) for (tries =3D 1000; tries > 0; --tries) { regmap_read(dspi->regmap, SPI_SR, &spi_sr); regmap_write(dspi->regmap, SPI_SR, spi_sr); + + dspi->cur_msg->status =3D dspi_fifo_error(dspi, spi_sr); + if (dspi->cur_msg->status) + return; if (spi_sr & SPI_SR_CMDTCF) break; } @@ -1088,6 +1105,7 @@ static void dspi_poll(struct fsl_dspi *dspi) static irqreturn_t dspi_interrupt(int irq, void *dev_id) { struct fsl_dspi *dspi =3D (struct fsl_dspi *)dev_id; + int status; u32 spi_sr; =20 regmap_read(dspi->regmap, SPI_SR, &spi_sr); @@ -1096,6 +1114,14 @@ static irqreturn_t dspi_interrupt(int irq, void *dev= _id) if (!(spi_sr & SPI_SR_CMDTCF)) return IRQ_NONE; =20 + status =3D dspi_fifo_error(dspi, spi_sr); + if (status) { + if (dspi->cur_msg) + WRITE_ONCE(dspi->cur_msg->status, status); + complete(&dspi->xfer_done); + return IRQ_HANDLED; + } + if (dspi_rxtx(dspi) =3D=3D false) { if (dspi->cur_msg) WRITE_ONCE(dspi->cur_msg->status, 0); --=20 2.34.1