From patchwork Fri May 31 09:44:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13681473 Received: from fgw22-7.mail.saunalahti.fi (fgw22-7.mail.saunalahti.fi [62.142.5.83]) (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 811BD7C6EB for ; Fri, 31 May 2024 09:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.83 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717148830; cv=none; b=r9CaDk1/tszdrWUFwajd26DJWxnq/jmbj3IvGxzvQ3e07Y9QfmlLFPa9p8nKVl2N2FAsv6faDHApqMmsY3roo3Su8bWS3JceQXRyN7zU2B3C1F3wA6ZGCNNJw9HjRIG+N4EXMVm6CR4Rn+JxcNxLfF+BWRlUM/pDFTm0KcIlcsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717148830; c=relaxed/simple; bh=/99r5c/7PncboE8HWq5Nz4/RRTHU8owjFX7NP8sLQo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oCSMC27lRdQA4304vKCwkWKblpVEEFG7IeskFNfT9ovgoZPrhoXu+CGUGPOjxMxlV3lXBkVQ3swZHfomKnNMz5WNmD0Axql4l5sbl5NZ5WrPLbinII7m5pSmM9eZ7B4Nqs3Zs5F9Yut8HWwREieeGysC69pbAthX6JCGH8A4IZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; arc=none smtp.client-ip=62.142.5.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=gmail.com Received: from localhost (88-113-26-230.elisa-laajakaista.fi [88.113.26.230]) by fgw22.mail.saunalahti.fi (Halon) with ESMTP id ba26c4d2-1f32-11ef-8e32-005056bdf889; Fri, 31 May 2024 12:47:00 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Neil Armstrong , Andy Shevchenko Subject: [PATCH v1 1/2] spi: Revert "Check if transfer is mapped before calling DMA sync APIs" Date: Fri, 31 May 2024 12:44:32 +0300 Message-ID: <20240531094658.1598969-2-andy.shevchenko@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531094658.1598969-1-andy.shevchenko@gmail.com> References: <20240531094658.1598969-1-andy.shevchenko@gmail.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This reverts commit da560097c05612f8d360f86528f6213629b9c395. It makes no difference as it was mistakenly thought that it fixes a bug while another unnoticed change have been preserved in the tester's repositorory. Signed-off-by: Andy Shevchenko --- drivers/spi/spi.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 9bc9fd10d538..43cd3e5bccbe 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1320,7 +1320,7 @@ static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg) return 0; } -static void spi_dma_sync_for_device(struct spi_controller *ctlr, struct spi_message *msg, +static void spi_dma_sync_for_device(struct spi_controller *ctlr, struct spi_transfer *xfer) { struct device *rx_dev = ctlr->cur_rx_dma_dev; @@ -1329,14 +1329,11 @@ static void spi_dma_sync_for_device(struct spi_controller *ctlr, struct spi_mess if (!ctlr->cur_msg_mapped) return; - if (!ctlr->can_dma(ctlr, msg->spi, xfer)) - return; - dma_sync_sgtable_for_device(tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); dma_sync_sgtable_for_device(rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); } -static void spi_dma_sync_for_cpu(struct spi_controller *ctlr, struct spi_message *msg, +static void spi_dma_sync_for_cpu(struct spi_controller *ctlr, struct spi_transfer *xfer) { struct device *rx_dev = ctlr->cur_rx_dma_dev; @@ -1345,9 +1342,6 @@ static void spi_dma_sync_for_cpu(struct spi_controller *ctlr, struct spi_message if (!ctlr->cur_msg_mapped) return; - if (!ctlr->can_dma(ctlr, msg->spi, xfer)) - return; - dma_sync_sgtable_for_cpu(rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); dma_sync_sgtable_for_cpu(tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); } @@ -1365,13 +1359,11 @@ static inline int __spi_unmap_msg(struct spi_controller *ctlr, } static void spi_dma_sync_for_device(struct spi_controller *ctrl, - struct spi_message *msg, struct spi_transfer *xfer) { } static void spi_dma_sync_for_cpu(struct spi_controller *ctrl, - struct spi_message *msg, struct spi_transfer *xfer) { } @@ -1643,10 +1635,10 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, reinit_completion(&ctlr->xfer_completion); fallback_pio: - spi_dma_sync_for_device(ctlr, msg, xfer); + spi_dma_sync_for_device(ctlr, xfer); ret = ctlr->transfer_one(ctlr, msg->spi, xfer); if (ret < 0) { - spi_dma_sync_for_cpu(ctlr, msg, xfer); + spi_dma_sync_for_cpu(ctlr, xfer); if (ctlr->cur_msg_mapped && (xfer->error & SPI_TRANS_FAIL_NO_START)) { @@ -1671,7 +1663,7 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, msg->status = ret; } - spi_dma_sync_for_cpu(ctlr, msg, xfer); + spi_dma_sync_for_cpu(ctlr, xfer); } else { if (xfer->len) dev_err(&msg->spi->dev, From patchwork Fri May 31 09:44:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13681472 Received: from fgw20-7.mail.saunalahti.fi (fgw20-7.mail.saunalahti.fi [62.142.5.81]) (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 5AB0078C69 for ; Fri, 31 May 2024 09:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717148829; cv=none; b=Z2rL7dyE4ufQ2XqIhJgmKZ9pJPUF5BCpz7BqZpYbmbsVLVbSbC22k20rQwxuwYUM0ckvU+SD3MdRtJkhG0Rk/DEbN0dZ8O7BGJN2y85EhO8hmPUyRxOjFcOPZUddxCK/gd8f4Y36c+dhqo2nIuBnbcMCM7EvLnX+7vDQEySnWF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717148829; c=relaxed/simple; bh=SC275hQjH9VkQy1y5Rrs3/LU4ycdUMdkK1Iho1g3uNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bp9KBShqczUhT3PTlNOUftIuIGQSwg1ZO9DnqeCoO1cpnREMj5pi5WJ9rAlUJHXZ8KxR/gYtSaiZ41hTYhH8sk7J/vwQCcerBIFzsQqcgNG61CsVnc0A030xqZdECvmOQaTtd4pb4tcoThSZU+2e9kNER6vB6+MRk7PqzRBz4IQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; arc=none smtp.client-ip=62.142.5.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=gmail.com Received: from localhost (88-113-26-230.elisa-laajakaista.fi [88.113.26.230]) by fgw21.mail.saunalahti.fi (Halon) with ESMTP id ba956cf2-1f32-11ef-aafc-005056bdd08f; Fri, 31 May 2024 12:47:01 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Neil Armstrong , Andy Shevchenko Subject: [PATCH v1 2/2] spi: Do not rely on the SG table and respective API implementations Date: Fri, 31 May 2024 12:44:33 +0300 Message-ID: <20240531094658.1598969-3-andy.shevchenko@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531094658.1598969-1-andy.shevchenko@gmail.com> References: <20240531094658.1598969-1-andy.shevchenko@gmail.com> Precedence: bulk X-Mailing-List: linux-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently we use global non-constant SG list to cover DMA unmmaped part of unidirection transfer. This is heavily relies on the internal implementation of the SG table and respective APIs. Instead, and to be pair with the DMA mapped part of the transfer, use SG table allocation for a single entry without any mapping done on top. This also will be symmetrical to the respective sg_free_table() call. Signed-off-by: Andy Shevchenko --- drivers/spi/spi.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 43cd3e5bccbe..da978ee262d8 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1220,11 +1220,6 @@ void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev, spi_unmap_buf_attrs(ctlr, dev, sgt, dir, 0); } -/* Dummy SG for unidirect transfers */ -static struct scatterlist dummy_sg = { - .page_link = SG_END, -}; - static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) { struct device *tx_dev, *rx_dev; @@ -1261,25 +1256,26 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) (void *)xfer->tx_buf, xfer->len, DMA_TO_DEVICE, attrs); - if (ret != 0) - return ret; } else { - xfer->tx_sg.sgl = &dummy_sg; + /* Allocate dummy SG table for unidirect transfers */ + ret = sg_alloc_table(&xfer->tx_sg, 1, GFP_KERNEL); } + if (ret) + return ret; if (xfer->rx_buf != NULL) { ret = spi_map_buf_attrs(ctlr, rx_dev, &xfer->rx_sg, xfer->rx_buf, xfer->len, DMA_FROM_DEVICE, attrs); - if (ret != 0) { - spi_unmap_buf_attrs(ctlr, tx_dev, - &xfer->tx_sg, DMA_TO_DEVICE, - attrs); - - return ret; - } } else { - xfer->rx_sg.sgl = &dummy_sg; + /* Allocate dummy SG table for unidirect transfers */ + ret = sg_alloc_table(&xfer->rx_sg, 1, GFP_KERNEL); + } + if (ret) { + spi_unmap_buf_attrs(ctlr, tx_dev, &xfer->tx_sg, + DMA_TO_DEVICE, attrs); + + return ret; } } /* No transfer has been mapped, bail out with success */