spi: rk_spi: Fix transfer size overflow
Subsystems (2)
cover spi: rk_spi: Fix transfer size overflow
These two patches are fixing flash read with > 64K size and spi flash read during SPI boot.
Any inputs?
Jagan.
Jagan Teki (2):
Revert "rockchip: spi: fix off-by-one in chunk size computation"
spi: rk_spi: Fix overflow max chunk size
drivers/spi/rk_spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.18.0.321.gffc6fa0e3
A message that is not in the archive (sent off-list or not yet received): 20191211132623.430-1-jagan-dyjBcgdgk7Pe9wHmmfpqLFaTQe2KTcn/@public.gmane.org
PATCH 1/2 Revert "rockchip: spi: fix off-by-one in chunk size computation"
The maximum transfer length (in a single transaction) for the Rockchip SPI controller is 64Kframes (i.e. 0x10000 frames) of 8bit or 16bit frames and is encoded as (num_frames - 1) in CTRLR1.
So the 0x10000 is offset value for 64K but the actual size value would be 'minus 1' from 0x10000.
With the existing code of 0x10000 transfer length leads to read failure when we try to read the flash with > 0x10000 size like,
1. sf read failure when with > 0x10000
2. Boot from SPI flash failed during spi_flash_read call in common/spl/spl_spi.c
Observed and Tested in
- Rockpro64 with Gigadevice flash
- ROC-RK3399-PC with Winbond flash
This reverts commit e647decdd93c7408741329432f26758fbec04c7a.
--- drivers/spi/rk_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/rk_spi.c +1 -1
@@ -451,7 +451,7 @@ static int rockchip_spi_xfer(struct udevice *dev, unsigned int bitlen,/* This is the original 8bit reader/writer code */ while (len >0 ) { -int todo =min (len,0x10000 ); +int todo =min (len,0xffff );rkspi_enable_chip (regs, false);writel (todo -1 , ®s->ctrlr1);
Signature · 1 line
2.18.0.321.gffc6fa0e3
Re: [PATCH 1/2] Revert "rockchip: spi: fix off-by-one in chunk size computation"
Quoted 10 lines · Jagan Teki
The maximum transfer length (in a single transaction) for the Rockchip SPI controller is 64Kframes (i.e.
0x10000frames) of 8bit or 16bit frames and is encoded as (num_frames- 1) in CTRLR1.So the
0x10000is offset value for 64K but the actual size value would be 'minus 1' from0x10000.
NAK. Please see 2 code lines below your change to see that the “minus 1” is applied there… so a todo of 0x10000 will write 0xffff to regs->ctrlr1.
The problem must be somewhere else and this patch will only mask the underlying issue.
Quoted 36 lines
With the existing code of
0x10000transfer length leads to read failure when we try to read the flash with >0x10000size like,1. sf read failure when with >
0x100002. Boot from SPI flash failed during
spi_flash_readcall incommon/spl/spl_spi.cObserved and Tested in
- Rockpro64 with Gigadevice flash
- ROC-RK3399-PC with Winbond flashThis reverts commit
e647decdd93c7408741329432f26758fbec04c7a.Signed-off-by Jagan Teki <[email protected]>---
drivers/spi/rk_spi.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/spi/rk_spi.c +1
-1@@ -451,7 +451,7 @@ static int rockchip_spi_xfer(struct udevice *dev, unsigned int bitlen,/* This is the original 8bit reader/writer code */ while (len >0 ) { -int todo =min (len,0x10000 ); +int todo =min (len,0xffff );rkspi_enable_chip (regs, false);writel (todo -1 , ®s->ctrlr1);Signature · 1 line
2.18.0.321.gffc6fa0e3
Re: [PATCH 1/2] Revert "rockchip: spi: fix off-by-one in chunk size computation"
Quoted 37 lines · Philipp Tomsich,
Quoted 10 lines · Jagan Teki
The maximum transfer length (in a single transaction) for the Rockchip SPI controller is 64Kframes (i.e.
0x10000frames) of 8bit or 16bit frames and is encoded as (num_frames- 1) in CTRLR1.So the
0x10000is offset value for 64K but the actual size value would be 'minus 1' from0x10000.NAK. Please see 2 code lines below your change to see that the “minus 1” is applied there… so a todo of
0x10000will write0xfffftoregs->ctrlr1.The problem must be somewhere else and this patch will only mask the underlying issue.
Quoted 20 lines
With the existing code of
0x10000transfer length leads to read failure when we try to read the flash with >0x10000size like,1. sf read failure when with >
0x100002. Boot from SPI flash failed during
spi_flash_readcall incommon/spl/spl_spi.cObserved and Tested in
- Rockpro64 with Gigadevice flash
- ROC-RK3399-PC with Winbond flashThis reverts commit
e647decdd93c7408741329432f26758fbec04c7a.Signed-off-by Jagan Teki <[email protected]>---
drivers/spi/rk_spi.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 18 lines
drivers/spi/rk_spi.c static int rockchip_spi_xfer(struct udevice *dev,
Quoted 5 lines
drivers/spi/rk_spi.c +0
-0@@ -451,7 +451,7 @@ static int rockchip_spi_xfer(struct udevice *dev,unsigned int bitlen,
Quoted 11 lines
drivers/spi/rk_spi.c +1
-2/* This is the original 8bit reader/writer code */ while (len >0 ) { -int todo =min (len,0x10000 ); +int todo =min (len,0xffff );rkspi_enable_chip (regs, false);writel (todo -1 , ®s->ctrlr1); --2.18.0.321.gffc6fa0e3
I have looked multiple areas but didn't get it so and i belive offset and size values aren't same.
Would you please send me the log of sf read to more than 64K on your
hardware? This would confirm my hardware issue if you succeed.
Quoted 1 line
A message that is not in the archive (sent off-list or not yet received): 1E12E6D7-5401-4EF5-9D74-DFC6F8216799-SN7IsUiht6C/[email protected]
Re: [PATCH 1/2] Revert "rockchip: spi: fix off-by-one in chunk size computation"
Hi Philipp,
Quoted 9 lines · Philipp Tomsich
Quoted 9 lines · Jagan Teki
The maximum transfer length (in a single transaction) for the Rockchip SPI controller is 64Kframes (i.e.
0x10000frames) of 8bit or 16bit frames and is encoded as (num_frames- 1) in CTRLR1.
Quoted 8 lines
Quoted 2 lines
So the
0x10000is offset value for 64K but the actual size value would be 'minus 1' from0x10000.NAK. Please see 2 code lines below your change to see that the “minus 1” is applied there… so a todo of
0x10000will write0xfffftoregs->ctrlr1.The problem must be somewhere else and this patch will only mask the underlying issue.
Please check the below changes. the max transfer size is 64K - 1 which is 0xffff and we need to write -1 of this to cr1.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/spi/spi-rockchip.c?id=5185a81c02d4118b11e6cb7b5fbf6f15ff7aff90
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/spi/spi-rockchip.c?id=04b37d2d02c0a5ae2f4e59326ef6deaff18e0456
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [PATCH 1/2] Revert "rockchip: spi: fix off-by-one in chunk size computation"
Quoted 14 lines · Jagan Teki
Hi Philipp,
Quoted 10 lines · Philipp Tomsich
Quoted 10 lines · Jagan Teki
The maximum transfer length (in a single transaction) for the Rockchip SPI controller is 64Kframes (i.e.
0x10000frames) of 8bit or 16bit frames and is encoded as (num_frames- 1) in CTRLR1.So the
0x10000is offset value for 64K but the actual size value would be 'minus 1' from0x10000.
Quoted 7 lines
Quoted 5 lines
NAK. Please see 2 code lines below your change to see that the “minus 1” is applied there… so a todo of
0x10000will write0xfffftoregs->ctrlr1.The problem must be somewhere else and this patch will only mask the underlying issue.
Please check the below changes. the max transfer size is 64K - 1 which is
0xffffand we need to write -1 of this to cr1.
Yep, the counter is 16bit, and the actual max size will be 0xffff and the max available value in reg should
be 0xffff-1.
Thanks,
- Kever
Quoted 5 lines
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/spi/spi-rockchip.c?id=5185a81c02d4118b11e6cb7b5fbf6f15ff7aff90
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/spi/spi-rockchip.c?id=04b37d2d02c0a5ae2f4e59326ef6deaff18e0456
PATCH 2/2 spi: rk_spi: Fix overflow max chunk size
In reply to a message not in the archiveThe max chunk size (in a single transaction) for the Rockchip SPI controller is 64Kframes (i.e. 0x10000 frames) of 8bit or 16bit frames and is encoded as (num_frames - 1) in CTRLR1.
So the 0x10000 is offset value for 64K but the actual size value would be 'minus 1' from 0x10000.
With the existing code of 0x10000 max chunk size leads to read failure when we try to read the flash with > 0x10000 size like,
1. sf read failure when with > 0x10000
2. Boot from SPI flash failed during spi_flash_read call in common/spl/spl_spi.c
Observed and Tested in
- Rockpro64 with Gigadevice flash
- ROC-RK3399-PC with Winbond flash
--- drivers/spi/rk_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/rk_spi.c +1 -1
@@ -367,7 +367,7 @@ static inline int rockchip_spi_16bit_reader(struct udevice *dev,* represented in CTRLR1. */ if (data && data->master_manages_fifo) - max_chunk_size =0x10000 ; + max_chunk_size =0xffff ;// rockchip_spi_configure(dev, mode, size) rkspi_enable_chip (regs, false);
Signature · 1 line
2.18.0.321.gffc6fa0e3