spi: Increase imx51 ecspi burst length based on transfer length
Subsystems (2)
PATCH 1/1 spi: Increase imx51 ecspi burst length based on transfer length
IMX51 supports 4096 bit burst lengths. Using the spi transfer length instead of bits_per_word increases performance significantly.
--- drivers/spi/spi-imx.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/spi/spi-imx.c +8 -3
@@ -644,9 +644,13 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,if (spi_imx->slave_mode &&is_imx53_ecspi (spi_imx)) ctrl |= (spi_imx->slave_burst *8 -1 ) <<MX51_ECSPI_CTRL_BL_OFFSET ; -else - ctrl |= (spi_imx->bits_per_word -1 ) - <<MX51_ECSPI_CTRL_BL_OFFSET ; +else { +if (spi_imx->count >=512 ) + ctrl |=0xFFF <<MX51_ECSPI_CTRL_BL_OFFSET ; +else + ctrl |= (spi_imx->count*8 -1 ) + <<MX51_ECSPI_CTRL_BL_OFFSET ; + }/* set clock speed */ ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET |
@@ -1243,6 +1247,7 @@ static int spi_imx_setupxfer(struct spi_device *spi, spi_imx->spi_bus_clk = t->speed_hz; spi_imx->bits_per_word = t->bits_per_word; + spi_imx->count = t->len;/* * Initialize the functions for transfer. To transfer non byte-aligned
Signature · 7 lines
2.34.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Fabio Estevam
reviewerHi Stefan,
Quoted 3 lines · Stefan Moring
IMX51 supports 4096 bit burst lengths. Using the spi transfer length instead of
bits_per_wordincreases performance significantly.
Could you please share the performance increase after this change?
Thanks
Hi Fabio,
In our application we send ~80kB at 10MHz. The total transfer time went from ~80ms to 67ms, so that would be a reduction of 15%. I tested it on an IMX8MM platform.
Kind regards,
Stefan Moring
Op wo 28 jun 2023 om 15:16 schreef Fabio Estevam <[email protected]>:
Quoted 12 lines
Hi Stefan,
Quoted 3 lines · Stefan Moring
IMX51 supports 4096 bit burst lengths. Using the spi transfer length instead of
bits_per_wordincreases performance significantly.Could you please share the performance increase after this change?
Thanks
Hi Stefan,
Quoted 3 lines · Stefan Moring
In our application we send ~80kB at 10MHz. The total transfer time went from ~80ms to 67ms, so that would be a reduction of 15%. I tested it on an IMX8MM platform.
I'm currently debugging a problem with spi-imx, HW CS and SPI_CS_WORD on torvalds/master. The breakage goes back this patch.
I'm wondering what is your setup you have optimized with this patch?
- Are you using HW or GPIO CS?
- What are bits_per_word?
- What's the length of the spi_transfer?
I'm asking because with a 8, 16 or 32 bit-per-word setting, the driver should use dynamic_burst on the imx8mm, which will overwrite the burst length in spi_imx_push().
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Quoted 10 lines · Marc Kleine-Budde
Hi Stefan,
Quoted 3 lines · Stefan Moring
In our application we send ~80kB at 10MHz. The total transfer time went from ~80ms to 67ms, so that would be a reduction of 15%. I tested it on an IMX8MM platform.
I'm currently debugging a problem with spi-imx, HW CS and
SPI_CS_WORDon torvalds/master. The breakage goes back this patch.
Quoted 8 lines
I'm wondering what is your setup you have optimized with this patch?
- Are you using HW or GPIO CS?
- What arebits_per_word?
- What's the length of thespi_transfer?I'm asking because with a 8, 16 or 32 bit-per-word setting, the driver should use
dynamic_burston the imx8mm, which will overwrite the burst length inspi_imx_push().
This patch, even with all the fixes on top of it (torvalds/master) breaks the HW CS + SPI_CS_WORD support which was added in 6e95b23a5b2d ("spi: imx: Implement support for CS_WORD").
I think this also breaks the support for bits-per-word != multiple of 8 bits. For these transfers the in-memory wordsizes are powers of two bytes (e.g. 20 bit samples use 32 bits) [1] and via the burst length configuration only the bits-per-word number of bits are shifted out.
[1] https://elixir.bootlin.com/linux/v6.9/source/include/linux/spi/spi.h#L144
| if (spi_imx->target_mode && is_imx53_ecspi(spi_imx))
| ctrl |= (spi_imx->target_burst * 8 - 1)
| << MX51_ECSPI_CTRL_BL_OFFSET;
| else {
| if (spi_imx->usedma) {
| ctrl |= (spi_imx->bits_per_word - 1)
| << MX51_ECSPI_CTRL_BL_OFFSET;
| } else {
| if (spi_imx->count >= MX51_ECSPI_CTRL_MAX_BURST)
| ctrl |= (MX51_ECSPI_CTRL_MAX_BURST * BITS_PER_BYTE - 1)
| << MX51_ECSPI_CTRL_BL_OFFSET;
| else
| ctrl |= (spi_imx->count / DIV_ROUND_UP(spi_imx->bits_per_word,
| BITS_PER_BYTE) * spi_imx->bits_per_word - 1)
| << MX51_ECSPI_CTRL_BL_OFFSET;
| }
| }Consider a message with bits-per-word = 9 consisting of 4 words. It uses 4 word x 2 bytes/word = 8 bytes of memory. This boils down to a burst length of 36 bits. Which means the spi-imx sends the first 36 bits from the 64 bits of memory, this is clearly wrong.
This patch (15a6af94a277 ("spi: Increase imx51 ecspi burst length based on transfer length")) is wrong and the 4 fixes on top of it don't finally fix it. I can send a series of 5 reverts, or a manually revert the burst length calculation to the original value in one patch.
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Mark Brown
maintainerQuoted 4 lines · Marc Kleine-Budde
This patch (
15a6af94a277("spi: Increase imx51 ecspi burst length based on transfer length")) is wrong and the 4 fixes on top of it don't finally fix it. I can send a series of 5 reverts, or a manually revert the burst length calculation to the original value in one patch.
A single revert should be fine and is probably clearer.
Hey Mark,
Quoted 8 lines · Mark Brown
Quoted 4 lines · Marc Kleine-Budde
This patch (
15a6af94a277("spi: Increase imx51 ecspi burst length based on transfer length")) is wrong and the 4 fixes on top of it don't finally fix it. I can send a series of 5 reverts, or a manually revert the burst length calculation to the original value in one patch.A single revert should be fine and is probably clearer.
thanks for your quick answer. What about the Fixes-tag? Just the original patch?
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
Mark Brown
maintainerQuoted 8 lines · Marc Kleine-Budde
Quoted 1 line · Mark Brown
A single revert should be fine and is probably clearer.
thanks for your quick answer. What about the Fixes-tag? Just the original patch?
Fixes 15a6af94a277 ("spi: Increase imx51 ecspi burst length based on transfer length")
Either way should be fine there, so long as the original patch is mentioned. It shouldn't do any harm to mention the others too though.
Mark Brown
maintainerQuoted 4 lines · Stefan Moring
IMX51 supports 4096 bit burst lengths. Using the spi transfer length instead of
bits_per_wordincreases performance significantly.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: Increase imx51 ecspi burst length based on transfer length
commit: 15a6af94a2779d5dfb42ee4bfac858ea8e964a3f
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Hi,
Quoted 5 lines · Stefan Moring
IMX51 supports 4096 bit burst lengths. Using the spi transfer length instead of
bits_per_wordincreases performance significantly.Signed-off-by Stefan Moring <[email protected]>---
I have an i.MX6ULL system with "inanbo,t28cp45tn89-v17" panel, which breaks due to this change. Reverting this patch results in working panel. Note, that the panel driver [0] does 'spi->bits_per_word = 9;'.
[0] drivers/gpu/drm/panel/panel-sitronix-st7789v.c
-- Sebastian
Quoted 35 lines
drivers/spi/spi-imx.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/spi/spi-imx.c +8
-3@@ -644,9 +644,13 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,if (spi_imx->slave_mode &&is_imx53_ecspi (spi_imx)) ctrl |= (spi_imx->slave_burst *8 -1 ) <<MX51_ECSPI_CTRL_BL_OFFSET ; -else - ctrl |= (spi_imx->bits_per_word -1 ) - <<MX51_ECSPI_CTRL_BL_OFFSET ; +else { +if (spi_imx->count >=512 ) + ctrl |=0xFFF <<MX51_ECSPI_CTRL_BL_OFFSET ; +else + ctrl |= (spi_imx->count*8 -1 ) + <<MX51_ECSPI_CTRL_BL_OFFSET ; + }/* set clock speed */ ctrl &= ~(0xf << MX51_ECSPI_CTRL_POSTDIV_OFFSET |@@ -1243,6 +1247,7 @@ static int spi_imx_setupxfer(struct spi_device *spi, spi_imx->spi_bus_clk = t->speed_hz; spi_imx->bits_per_word = t->bits_per_word; + spi_imx->count = t->len;/* * Initialize the functions for transfer. To transfer non byte-aligned Signature · 1 line
2.34.1
A message that is not in the archive (sent off-list or not yet received): CAB3BuKAEFewb6W5K=Z2ZX9Xx0gA+RW+XKY-Mkn-PfBOfq3eb+A@mail.gmail.com
Hi,
Quoted 8 lines · Stefan Moring
Op vr 15 sep 2023 om 00:47 schreef Sebastian Reichel <[email protected]>:
Quoted 7 lines · Stefan Moring
Quoted 5 lines
IMX51 supports 4096 bit burst lengths. Using the spi transfer length instead of
bits_per_wordincreases performance significantly.Signed-off-by Stefan Moring <[email protected]>---
Quoted 8 lines
Quoted 5 lines
I have an i.MX6ULL system with "inanbo,t28cp45tn89-v17" panel, which breaks due to this change. Reverting this patch results in working panel. Note, that the panel driver [0] does '
spi->bits_per_word= 9;'.[0]
drivers/gpu/drm/panel/panel-sitronix-st7789v.cWould changing line 665 to ctrl |= (
spi_imx->count*spi_imx->bits_per_word
- 1) fix the issue?
drivers/spi/spi-imx.c +1 -1
@@ -662,7 +662,7 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,if (spi_imx->count >=512 ) ctrl |=0xFFF <<MX51_ECSPI_CTRL_BL_OFFSET ;else - ctrl |= (spi_imx->count*8 -1 ) + ctrl |= (spi_imx->count*spi_imx->bits_per_word -1 ) <<MX51_ECSPI_CTRL_BL_OFFSET ; }
on top of 6.6-rc1 fixes the problem. Will you send a proper patch with
or should I do it?
Greetings,
-- Sebastian
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel