spi: Rework DMA mapped flag
Subsystems (4)
Andy Shevchenko
reviewercover spi: Rework DMA mapped flag
The first part of the series (patches 1 to 7) is an introduction of a new helper followed by the user conversion.
This consolidates the same code and also makes patch 8 (last one) be localised to the SPI core part.
The last patch is the main rework to get rid of a recently introduced hack with a dummy SG list and move to the transfer-based DMA mapped flag.
That said, the patches 1 to 7 may be applied right away since they have no functional change intended, while the last one needs more testing and reviewing.
Andy Shevchenko (8):
spi: Introduce internal spi_xfer_is_dma_mapped() helper
spi: dw: Use new spi_xfer_is_dma_mapped() helper
spi: ingenic: Use new spi_xfer_is_dma_mapped() helper
spi: omap2-mcspi: Use new spi_xfer_is_dma_mapped() helper
spi: pxa2xx: Use new spi_xfer_is_dma_mapped() helper
spi: pci1xxxx: Use new spi_xfer_is_dma_mapped() helper
spi: qup: Use new spi_xfer_is_dma_mapped() helper
spi: Rework per message DMA mapped flag to be per transfer
drivers/spi/internals.h | 8 ++++ drivers/spi/spi-dw-core.c | 4 +- drivers/spi/spi-ingenic.c | 4 +- drivers/spi/spi-omap2-mcspi.c | 8 ++-- drivers/spi/spi-pci1xxxx.c | 5 ++- drivers/spi/spi-pxa2xx.c | 6 +-- drivers/spi/spi-qup.c | 9 ++--- drivers/spi/spi.c | 73 +++++++++++++---------------------- include/linux/spi/spi.h | 11 ++++-- 9 files changed, 59 insertions(+), 69 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Andy Shevchenko
reviewerPATCH 1/8 spi: Introduce internal spi_xfer_is_dma_mapped() helper
There are few drivers that use the same pattern to check if the transfer is DMA mapped or not. Provide a helper.
--- drivers/spi/internals.h | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/spi/internals.h +8 -0
@@ -40,4 +40,12 @@ static inline void spi_unmap_buf(struct spi_controller *ctlr, }#endif /* CONFIG_HAS_DMA */ +static inline bool spi_xfer_is_dma_mapped (struct spi_controller *ctlr, +struct spi_device *spi, +struct spi_transfer *xfer) +{ +return ctlr->can_dma && ctlr->can_dma (ctlr, spi, xfer) && + ctlr->cur_msg_mapped; +} +#endif /* __LINUX_SPI_INTERNALS_H */
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Re: [PATCH v1 1/8] spi: Introduce internal spi_xfer_is_dma_mapped() helper
Quoted 15 lines · Andy Shevchenko
There are few drivers that use the same pattern to check if the transfer is DMA mapped or not. Provide a helper.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/spi/internals.h | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/spi/internals.h +0
-0@@ -40,4 +40,12 @@ static inline void spi_unmap_buf(struct spi_controller *ctlr, }#endif /* CONFIG_HAS_DMA */
drivers/spi/internals.h static inline void spi_unmap_buf(struct spi_controller *ctlr, · line 51
Quoted 10 lines
drivers/spi/internals.h +8
-0+static inline bool spi_xfer_is_dma_mapped (struct spi_controller *ctlr, +struct spi_device *spi, +struct spi_transfer *xfer) +{ +return ctlr->can_dma && ctlr->can_dma (ctlr, spi, xfer) && + ctlr->cur_msg_mapped; +} +#endif /* __LINUX_SPI_INTERNALS_H */
Andy Shevchenko
reviewerPATCH 2/8 spi: dw: Use new spi_xfer_is_dma_mapped() helper
In reply to Andy ShevchenkoReplace a few lines of code by calling a spi_xfer_is_dma_mapped() helper.
--- drivers/spi/spi-dw-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-dw-core.c +2 -2
@@ -19,6 +19,7 @@#include <linux/string.h> #include <linux/of.h> +#include "internals.h" #include "spi-dw.h" #ifdef CONFIG_DEBUG_FS
@@ -438,8 +439,7 @@ static int dw_spi_transfer_one(struct spi_controller *host, transfer->effective_speed_hz = dws->current_freq;/* Check if current transfer is a DMA transaction */ -if (host->can_dma && host->can_dma (host, spi, transfer)) - dws->dma_mapped = host->cur_msg_mapped; + dws->dma_mapped =spi_xfer_is_dma_mapped (host, spi, transfer);/* For poll mode just disable all interrupts */ dw_spi_mask_intr (dws,0xff );
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Re: [PATCH v1 2/8] spi: dw: Use new spi_xfer_is_dma_mapped() helper
Quoted 3 lines · Andy Shevchenko
Replace a few lines of code by calling a
spi_xfer_is_dma_mapped()helper.Signed-off-by Andy Shevchenko <[email protected]>
Nice cleanup. Thanks!
-Serge(y)
Quoted 29 lines
--- drivers/spi/spi-dw-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/spi/spi-dw-core.c +2
-2@@ -19,6 +19,7 @@#include <linux/string.h> #include <linux/of.h> +#include "internals.h" #include "spi-dw.h" #ifdef CONFIG_DEBUG_FS @@ -438,8 +439,7 @@ static int dw_spi_transfer_one(struct spi_controller *host, transfer->effective_speed_hz = dws->current_freq;/* Check if current transfer is a DMA transaction */ -if (host->can_dma && host->can_dma (host, spi, transfer)) - dws->dma_mapped = host->cur_msg_mapped; + dws->dma_mapped =spi_xfer_is_dma_mapped (host, spi, transfer);/* For poll mode just disable all interrupts */ dw_spi_mask_intr (dws,0xff );Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Andy Shevchenko
reviewerPATCH 3/8 spi: ingenic: Use new spi_xfer_is_dma_mapped() helper
In reply to Andy ShevchenkoReplace a few lines of code by calling a spi_xfer_is_dma_mapped() helper.
--- drivers/spi/spi-ingenic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-ingenic.c +2 -2
@@ -16,6 +16,7 @@#include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/spi/spi.h> +#include "internals.h" #define REG_SSIDR 0x0#define REG_SSICR0 0x4
@@ -242,11 +243,10 @@ static int spi_ingenic_transfer_one(struct spi_controller *ctlr, {struct ingenic_spi *priv =spi_controller_get_devdata (ctlr);unsigned int bits = xfer->bits_per_word ?: spi->bits_per_word; -bool can_dma = ctlr->can_dma && ctlr->can_dma (ctlr, spi, xfer);spi_ingenic_prepare_transfer (priv, spi, xfer); -if (ctlr->cur_msg_mapped && can_dma) +if (spi_xfer_is_dma_mapped (ctlr, spi, xfer))return spi_ingenic_dma_tx (ctlr, xfer, bits);if (bits >16 )
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Andy Shevchenko
reviewerPATCH 4/8 spi: omap2-mcspi: Use new spi_xfer_is_dma_mapped() helper
In reply to Andy ShevchenkoReplace a few lines of code by calling a spi_xfer_is_dma_mapped() helper.
--- drivers/spi/spi-omap2-mcspi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/spi/spi-omap2-mcspi.c +4 -4
@@ -27,6 +27,8 @@#include <linux/spi/spi.h> +#include "internals.h" +#include <linux/platform_data/spi-omap2-mcspi.h> #define OMAP2_MCSPI_MAX_FREQ 48000000
@@ -1208,8 +1210,7 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr,unsigned count;if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && - ctlr->cur_msg_mapped && - ctlr->can_dma (ctlr, spi, t)) +spi_xfer_is_dma_mapped (ctlr, spi, t))omap2_mcspi_set_fifo (spi, t,1 );omap2_mcspi_set_enable (spi,1 );
@@ -1220,8 +1221,7 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr, + OMAP2_MCSPI_TX0);if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && - ctlr->cur_msg_mapped && - ctlr->can_dma (ctlr, spi, t)) +spi_xfer_is_dma_mapped (ctlr, spi, t)) count =omap2_mcspi_txrx_dma (spi, t);else count =omap2_mcspi_txrx_pio (spi, t);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Andy Shevchenko
reviewerPATCH 5/8 spi: pxa2xx: Use new spi_xfer_is_dma_mapped() helper
In reply to Andy ShevchenkoReplace a few lines of code by calling a spi_xfer_is_dma_mapped() helper.
--- drivers/spi/spi-pxa2xx.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/spi/spi-pxa2xx.c +2 -4
@@ -26,6 +26,7 @@#include <linux/spi/spi.h> +#include "internals.h" #include "spi-pxa2xx.h" #define TIMOUT_DFLT 1000
@@ -993,11 +994,8 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, } dma_thresh =SSCR1_RxTresh (RX_THRESH_DFLT ) |SSCR1_TxTresh (TX_THRESH_DFLT ); - dma_mapped = controller->can_dma && - controller->can_dma (controller, spi, transfer) && - controller->cur_msg_mapped; + dma_mapped =spi_xfer_is_dma_mapped (controller, spi, transfer);if (dma_mapped) { -/* Ensure we have the correct interrupt handler */ drv_data->transfer_handler = pxa2xx_spi_dma_transfer;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Andy Shevchenko
reviewerRe: [PATCH v1 5/8] spi: pxa2xx: Use new spi_xfer_is_dma_mapped() helper
Quoted 1 line · Andy Shevchenko
Replace a few lines of code by calling a
spi_xfer_is_dma_mapped()helper.
It appears that this patch is based on the cleanup series against the driver that had been sent earlier. Namely this:
[v2] spi: pxa2xx: Get rid of an additional layer in PCI driver
https://lore.kernel.org/linux-spi/[email protected]/T/#t
And as others already said, this series is pure cleanup, no need to be backported.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerRe: [PATCH v1 5/8] spi: pxa2xx: Use new spi_xfer_is_dma_mapped() helper
Quoted 8 lines · Andy Shevchenko
Quoted 1 line · Andy Shevchenko
Replace a few lines of code by calling a
spi_xfer_is_dma_mapped()helper.It appears that this patch is based on the cleanup series against the driver that had been sent earlier. Namely this:
[v2] spi: pxa2xx: Get rid of an additional layer in PCI driver
Okay, now it should cleanly apply to spi/for-next (and indeed, it does, I just checked locally).
Quoted 1 line
And as others already said, this series is pure cleanup, no need to be backported.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerPATCH 6/8 spi: pci1xxxx: Use new spi_xfer_is_dma_mapped() helper
In reply to Andy ShevchenkoReplace a few lines of code by calling a spi_xfer_is_dma_mapped() helper.
--- drivers/spi/spi-pci1xxxx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/spi/spi-pci1xxxx.c +3 -2
@@ -6,6 +6,7 @@#include <linux/bitfield.h> +#include <linux/delay.h> #include <linux/dma-mapping.h> #include <linux/iopoll.h> #include <linux/irq.h>
@@ -15,7 +16,7 @@#include <linux/pci.h> #include <linux/spinlock.h> #include <linux/spi/spi.h> -#include <linux/delay.h> +#include "internals.h" #define DRV_NAME "spi-pci1xxxx"
@@ -567,7 +568,7 @@ static int pci1xxxx_spi_transfer_with_dma(struct spi_controller *spi_ctlr,static int pci1xxxx_spi_transfer_one (struct spi_controller *spi_ctlr,struct spi_device *spi,struct spi_transfer *xfer) { -if (spi_ctlr->can_dma (spi_ctlr, spi, xfer) && spi_ctlr->cur_msg_mapped) +if (spi_xfer_is_dma_mapped (spi_ctlr, spi, xfer))return pci1xxxx_spi_transfer_with_dma (spi_ctlr, spi, xfer);else return pci1xxxx_spi_transfer_with_io (spi_ctlr, spi, xfer);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Andy Shevchenko
reviewerPATCH 7/8 spi: qup: Use new spi_xfer_is_dma_mapped() helper
In reply to Andy ShevchenkoReplace a few lines of code by calling a spi_xfer_is_dma_mapped() helper.
--- drivers/spi/spi-qup.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/spi/spi-qup.c +4 -5
@@ -5,6 +5,8 @@#include <linux/clk.h> #include <linux/delay.h> +#include <linux/dma-mapping.h> +#include <linux/dmaengine.h> #include <linux/err.h> #include <linux/interconnect.h> #include <linux/interrupt.h>
@@ -16,8 +18,7 @@#include <linux/pm_opp.h> #include <linux/pm_runtime.h> #include <linux/spi/spi.h> -#include <linux/dmaengine.h> -#include <linux/dma-mapping.h> +#include "internals.h" #define QUP_CONFIG 0x0000#define QUP_STATE 0x0004
@@ -709,9 +710,7 @@ static int spi_qup_io_prep(struct spi_device *spi, struct spi_transfer *xfer)if (controller->n_words <= (controller->in_fifo_sz /sizeof (u32))) controller->mode =QUP_IO_M_MODE_FIFO ; -else if (spi->controller->can_dma && - spi->controller->can_dma (spi->controller, spi, xfer) && - spi->controller->cur_msg_mapped) +else if (spi_xfer_is_dma_mapped (spi->controller, spi, xfer)) controller->mode =QUP_IO_M_MODE_BAM ;else controller->mode =QUP_IO_M_MODE_BLOCK ;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Re: [PATCH v1 7/8] spi: qup: Use new spi_xfer_is_dma_mapped() helper
Quoted 31 lines · Andy Shevchenko
Replace a few lines of code by calling a
spi_xfer_is_dma_mapped()helper.Signed-off-by Andy Shevchenko <[email protected]>--- drivers/spi/spi-qup.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/spi/spi-qup.c +3
-2@@ -5,6 +5,8 @@#include <linux/clk.h> #include <linux/delay.h> +#include <linux/dma-mapping.h> +#include <linux/dmaengine.h> #include <linux/err.h> #include <linux/interconnect.h> #include <linux/interrupt.h> @@ -16,8 +18,7 @@#include <linux/pm_opp.h> #include <linux/pm_runtime.h> #include <linux/spi/spi.h> -#include <linux/dmaengine.h> -#include <linux/dma-mapping.h> +#include "internals.h" #define QUP_CONFIG 0x0000#define QUP_STATE 0x0004
drivers/spi/spi-qup.c static int spi_qup_io_prep(struct spi_device *spi, struct spi_transfer *xfer) · line 716
Quoted 10 lines
drivers/spi/spi-qup.c +1
-3@@ -709,9 +710,7 @@ static int spi_qup_io_prep(struct spi_device *spi, struct spi_transfer *xfer)if (controller->n_words <= (controller->in_fifo_sz /sizeof (u32))) controller->mode =QUP_IO_M_MODE_FIFO ; -else if (spi->controller->can_dma && - spi->controller->can_dma (spi->controller, spi, xfer) && - spi->controller->cur_msg_mapped) +else if (spi_xfer_is_dma_mapped (spi->controller, spi, xfer)) controller->mode =QUP_IO_M_MODE_BAM ;else controller->mode =QUP_IO_M_MODE_BLOCK ;
Andy Shevchenko
reviewerPATCH 8/8 spi: Rework per message DMA mapped flag to be per transfer
In reply to Andy ShevchenkoThe granularity of DMA mappings is transfer and moreover, the direction is also important as it can be unidirect.
The current cur_msg_mapped flag doesn't fit well the DMA mapping and syncing calls and we have tons of checks around on top of it. So, instead of doing that rework the code to use per transfer per direction flag to show if it's DMA mapped or not.
--- drivers/spi/internals.h | 2 +- drivers/spi/spi.c | 73 +++++++++++++++-------------------------- include/linux/spi/spi.h | 11 ++++--- 3 files changed, 35 insertions(+), 51 deletions(-)
drivers/spi/internals.h +1 -1
@@ -45,7 +45,7 @@ static inline bool spi_xfer_is_dma_mapped(struct spi_controller *ctlr, struct spi_transfer *xfer) {return ctlr->can_dma && ctlr->can_dma (ctlr, spi, xfer) && - ctlr->cur_msg_mapped; + (xfer->tx_sg_mapped || xfer->rx_sg_mapped); }#endif /* __LINUX_SPI_INTERNALS_H */
drivers/spi/spi.c +27 -46
151 lines not on this page · raw message
include/linux/spi/spi.h +7 -4
@@ -448,7 +448,6 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch* @cur_msg_need_completion: Flag used internally to opportunistically skip * the @cur_msg_completion. This flag is used to signal the context that * is running spi_finalize_current_message() that it needs to complete() -* @cur_msg_mapped: message has been mapped for DMA * @fallback: fallback to PIO if DMA transfer return failure with * SPI_TRANS_FAIL_NO_START. * @last_cs_mode_high: was (mode & SPI_CS_HIGH) true on the last call to set_cs.
@@ -709,7 +708,6 @@ struct spi_controller {bool running;bool rt;bool auto_runtime_pm; -bool cur_msg_mapped;bool fallback;bool last_cs_mode_high;s8 last_cs[SPI_CS_CNT_MAX ];
@@ -982,6 +980,8 @@ struct spi_res {* transfer this transfer. Set to 0 if the SPI bus driver does * not support it. * @transfer_list: transfers are sequenced through @spi_message.transfers +* @tx_sg_mapped: If true, the @tx_sg is mapped for DMA +* @rx_sg_mapped: If true, the @rx_sg is mapped for DMA * @tx_sg: Scatterlist for transmit, currently not for client use * @rx_sg: Scatterlist for receive, currently not for client use * @ptp_sts_word_pre: The word (subject to bits_per_word semantics) offset
@@ -1078,10 +1078,13 @@ struct spi_transfer {#define SPI_TRANS_FAIL_IO BIT(1)u16 error; -dma_addr_t tx_dma; -dma_addr_t rx_dma; +bool tx_sg_mapped; +bool rx_sg_mapped; +struct sg_table tx_sg;struct sg_table rx_sg; +dma_addr_t tx_dma; +dma_addr_t rx_dma; unsigned dummy_data:1; unsigned cs_off:1;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Quoted 24 lines · Andy Shevchenko
The first part of the series (patches 1 to 7) is an introduction of a new helper followed by the user conversion.
This consolidates the same code and also makes patch 8 (last one) be localised to the SPI core part.
The last patch is the main rework to get rid of a recently introduced hack with a dummy SG list and move to the transfer-based DMA mapped flag.
That said, the patches 1 to 7 may be applied right away since they have no functional change intended, while the last one needs more testing and reviewing.
Andy Shevchenko (8):
spi: Introduce internalspi_xfer_is_dma_mapped()helper
spi: dw: Use newspi_xfer_is_dma_mapped()helper
spi: ingenic: Use newspi_xfer_is_dma_mapped()helper
spi: omap2-mcspi: Use newspi_xfer_is_dma_mapped()helper
spi: pxa2xx: Use newspi_xfer_is_dma_mapped()helper
spi: pci1xxxx: Use newspi_xfer_is_dma_mapped()helper
spi: qup: Use newspi_xfer_is_dma_mapped()helper
spi: Rework per message DMA mapped flag to be per transfer
Quoted 11 lines
drivers/spi/internals.h | 8 ++++ drivers/spi/spi-dw-core.c | 4 +- drivers/spi/spi-ingenic.c | 4 +- drivers/spi/spi-omap2-mcspi.c | 8 ++-- drivers/spi/spi-pci1xxxx.c | 5 ++- drivers/spi/spi-pxa2xx.c | 6 +-- drivers/spi/spi-qup.c | 9 ++--- drivers/spi/spi.c | 73 +++++++++++++---------------------- include/linux/spi/spi.h | 11 ++++-- 9 files changed, 59 insertions(+), 69 deletions(-)
I applied the serie on next-20240603, it worked fine:
Thanks,
Neil
Andy Shevchenko
reviewerQuoted 1 line · Neil Armstrong
On 31/05/2024 21:42, Andy Shevchenko wrote:
...
Quoted 3 lines
I applied the serie on next-20240603, it worked fine:
Thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 14 lines · Andy Shevchenko
The first part of the series (patches 1 to 7) is an introduction of a new helper followed by the user conversion.
This consolidates the same code and also makes patch 8 (last one) be localised to the SPI core part.
The last patch is the main rework to get rid of a recently introduced hack with a dummy SG list and move to the transfer-based DMA mapped flag.
That said, the patches 1 to 7 may be applied right away since they have no functional change intended, while the last one needs more testing and reviewing.
Quoted 9 lines
Andy Shevchenko (8):
spi: Introduce internalspi_xfer_is_dma_mapped()helper
spi: dw: Use newspi_xfer_is_dma_mapped()helper
spi: ingenic: Use newspi_xfer_is_dma_mapped()helper
spi: omap2-mcspi: Use newspi_xfer_is_dma_mapped()helper
spi: pxa2xx: Use newspi_xfer_is_dma_mapped()helper
spi: pci1xxxx: Use newspi_xfer_is_dma_mapped()helper
spi: qup: Use newspi_xfer_is_dma_mapped()helper
spi: Rework per message DMA mapped flag to be per transfer
Tested on next-20240603. No issue noticed on sc7180-trogdor-kingoftown and sc7180-trogdor-lazor-limozeen. So,
Although patch 5 (pxa2xx) didn't apply, so I skipped it (but it's not used on my platforms).
Thanks,
Nícolas
Andy Shevchenko
reviewerQuoted 1 line · Nícolas F. R. A. Prado
On Fri, May 31, 2024 at 10:42:32PM +0300, Andy Shevchenko wrote:
...
Quoted 4 lines
Tested on next-20240603. No issue noticed on sc7180-trogdor-kingoftown and sc7180-trogdor-lazor-limozeen. So,
Thank you!
Quoted 2 lines
Although patch 5 (pxa2xx) didn't apply, so I skipped it (but it's not used on my platforms).
Yeah, I just commented on that, it appears that I have based this on the previous driver cleanups (it was published a week ago).
Signature · 2 lines
With Best Regards, Andy Shevchenko