From nobody Fri Oct 3 15:36:57 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 0CED6314A80 for ; Fri, 29 Aug 2025 11:47:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756468052; cv=none; b=WKArUVLeliSMtFI1U+0tw+ZXUMnM03rYoC2hMR2rX5f3TX9eFZdWLAfvpBBIFHinT36Sgae+Wm4dHZPyjkVb67DKva8ZAS8gMSLhe/4l+1igzQdsgqSCzRpsf79Q5mMFqBndkQ6qQRqhWVTMS8u9TWrXqz/Hg8hkWFZUg249nQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756468052; c=relaxed/simple; bh=Y91ohFlywuuOqzu3Tlam2ze85WKTB7vkK2PK+gGBXyk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g9M6RZUp7XCh6WSIgNqQC4V61Wvn7mKlQoz4CvLzkn9w3aI2MlV1LMfy1k6o67xjrljHgvAr+E9UYVG6tgzJgVLXapx1mJA8Bv++GVTcZUJ4NPSK0tFSmP8zcYKBAxiGvCY7y+kjpzpTZHhHcx8zqWiLffneFhnxuYf4d/C6aMs= 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=yVrZWCa8; arc=none smtp.client-ip=209.85.128.46 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="yVrZWCa8" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-45b83ae1734so222965e9.0 for ; Fri, 29 Aug 2025 04:47:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756468048; x=1757072848; 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=eQp6NWY2QTc4ozrR/xRG6ASSI6SHhnIsdKywX21k0ZQ=; b=yVrZWCa8p8zZK60/VO1a/xbFWFpKqXs41UpjRNcxrAS0VbuXYhhXZ/oIap+essmCsY btYbxRWmg3vunHlhcLRxvA/lIzLjqRqZ+8DkBkYr6Pf4VyFoO4HErfwIhnm8iJ0ZBOf8 aa0kTKVtiJGMAY5bMPFvNGi+knPUp1Pj5MPoDzrY3j4p5kEhmErMrFCePvtcpkoqZinO 8nuSkYZ7B9lbG0liIvGPQHop8FC2vYufem7SdLfXZHuZKlhk5H6sKR0begy83lA+HQlu Zz6ckWqGoK/D8gUxUyYXnCadKat5ygFCzW6KAsu3PQmkTtE95xTGEMt8MMKFcLk0awTI Ql+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756468048; x=1757072848; 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=eQp6NWY2QTc4ozrR/xRG6ASSI6SHhnIsdKywX21k0ZQ=; b=XNBBhDB8qiPyvsOypO2C438n6HXA1MdHqXAxFQAgoxivP96sbyTTYbcnCEEwAYxDlG pYsEKeUInjFmaU4JEhE/QHOBakBq67jqQ2uT6LdH/BSKAayCw9huDBo7mXNIujYqFH/d M2MjjZ38v676OCu7QQVUfIkzoPIF9b7w0sdhKiW+/s3hdUqD0iU/qeJH39dsyUs8QbQH OJGh0Gw/Wc1joco5ayezcUSD0LT++SfA4MB+sJlQY9cXGqfPZOnwR8o342A7CfXZNjk8 R6fng1zRiD0DAXvkYjJKwLf6PszpR51L1UhRy8g1kfuSBKp9Kv0IrqbDzvGUaWboY9HZ jsrQ== X-Forwarded-Encrypted: i=1; AJvYcCVfX/Xe7J1eVgrJ2VX+h3ObcICCwz+rjthN39N3jxVw90OS0sewwD75Wal7g1CZgs7i6+FoZFc0NSBuUic=@vger.kernel.org X-Gm-Message-State: AOJu0YwOeAxx80ZW4uUnk1RI5EBQ3SJw7+gODaEEC9s3eJGt3eIkahSf ASkrvoHlhNI9PoeDqsSfVc0UXHugrq6juji5wO7MVO4ln4HLMTLJGUq65KCe6Lz5kVY= X-Gm-Gg: ASbGncvqJEQ7O4VyXqz2EjlhIGwqE8pJOL3uNsmPLHIQt9wM4YaMTYS9fKG25mQGOTy e/CW3gGurZA3l3EIE2o/A05g9djZv8X3dvugJCqQmIjGUjPbK8N9lMtFEoonlpBKfrIcJyoLojy vYcCO/SkZPUV8y7dvBS4yV88ORkQc/dhcmIY06Ti6jx82+vD1xlwSVHZgXwP+GoizYrRJGiOjAK Tz8nmBgKdG8dQ8zQKaaeKWjztcToTGT0mICQH3lb3whbTuAcr4BJKJl5w9RQ9HcjS//oUzSinVV 2bLwGYP+7qUmURtGZM2V0149rZgrN3+UrTXWUUsCYeWJ1Zwnbx4qJHee0QTTUeFT1zPgGcktgrk dCvw9+gq6zXTuP6Vhl671Hc7r3DfTdt9Ecwc9Sub/wg== X-Google-Smtp-Source: AGHT+IH8KwfZBQ4nBA66UTh9TpCQ7FkF2eS86H/0NZMW3Kuh37xGLb484Nqj8yF/tw4ZGsIRDLeCUA== X-Received: by 2002:a05:600c:19cd:b0:458:be62:dcd3 with SMTP id 5b1f17b1804b1-45b517c2fc0mr284031215e9.17.1756468048262; Fri, 29 Aug 2025 04:47:28 -0700 (PDT) Received: from ho-tower-lan.lan ([185.48.76.109]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b7c461edasm29873255e9.9.2025.08.29.04.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 04:47:27 -0700 (PDT) From: James Clark Date: Fri, 29 Aug 2025 12:46:46 +0100 Subject: [PATCH v5 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: <20250829-james-nxp-spi-dma-v5-4-3246957a6ea9@linaro.org> References: <20250829-james-nxp-spi-dma-v5-0-3246957a6ea9@linaro.org> In-Reply-To: <20250829-james-nxp-spi-dma-v5-0-3246957a6ea9@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 --- drivers/spi/spi-fsl-dspi.c | 55 +++++++++++++++++++++++++++++-------------= ---- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 0baf7e0608f2..17a29fde5f2d 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,10 +538,9 @@ 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->tx_dma_phys, size, DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); if (!dma->tx_desc) { @@ -543,10 +555,10 @@ 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->rx_dma_phys, size, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); if (!dma->rx_desc) { @@ -643,17 +655,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 +700,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 +726,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