scsi: Replace SYNC_CACHE with FUA for scsi write
v3 cover scsi: Replace SYNC_CACHE with FUA for scsi write
This series replaces the SYNC_CACHE approach with FUA (Force Unit Access) to prevent data loss during board resets while avoiding system hangs during large sparse image flashing operations.
The previous SYNC_CACHE implementation caused timeouts and hangs when flashing large sparse images because it issued cache sync commands after every write operation. The FUA approach achieves the same data integrity goal by setting the FUA bit in WRITE10 commands.
---
Changes in v3:
- Changed commit description strcture and added SoB
- Link to v2: https://lore.kernel.org/u-boot/[email protected]/
Changes in v2:
- Reverted "scsi: sync cache on write" commit and then set the FUA bit
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/
---
Aswin Murugan (1):
scsi: Enable FUA bit in WRITE10 commands
Balaji Selvanathan (1):
Revert "scsi: sync cache on write"
drivers/scsi/scsi.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-)
---
base-commit: 70fd0c3bb7c26d42f24d10145dd5f3168ac92eac
change-id: 20260416-enable_fua-67b6aadc2cad
Best regards,
Signature · 1 line
Balaji Selvanathan <[email protected]>
PATCH v3 1/2 Revert "scsi: sync cache on write"
While the SYNC_CACHE approach prevents data loss during board resets, it causes system hangs during large sparse image flashing operations. This will be replaced with a FUA (Force Unit Access) approach in future commit, which achieves the same data integrity goal more efficiently.
This reverts commit ffe4e6ab42d2534302be825e49a2d085acf80f30.
---
Changes in v3:
- Changed commit description's structure.
--- drivers/scsi/scsi.c | 22 ---------------------- 1 file changed, 22 deletions(-)
drivers/scsi/scsi.c +0 -22
@@ -82,23 +82,6 @@ static void scsi_setup_inquiry(struct scsi_cmd *pccb) pccb->msgout[0 ] =SCSI_IDENTIFY ;/* NOT USED */ } -static void scsi_setup_sync_cache (struct scsi_cmd *pccb,lbaint_t start, -lbaint_t blocks) -{ - pccb->cmd[0 ] =SCSI_SYNC_CACHE ; - pccb->cmd[1 ] =0 ; - pccb->cmd[2 ] = (unsigned char )(start >>24 ) &0xff ; - pccb->cmd[3 ] = (unsigned char )(start >>16 ) &0xff ; - pccb->cmd[4 ] = (unsigned char )(start >>8 ) &0xff ; - pccb->cmd[5 ] = (unsigned char )start &0xff ; - pccb->cmd[6 ] =0 ; - pccb->cmd[7 ] = (unsigned char )(blocks >>8 ) &0xff ; - pccb->cmd[8 ] = (unsigned char )blocks &0xff ; - pccb->cmd[9 ] =0 ; - pccb->cmdlen =10 ; - pccb->msgout[0 ] =SCSI_IDENTIFY ;/* NOT USED */ -} -static void scsi_setup_read_ext (struct scsi_cmd *pccb,lbaint_t start,lbaint_t blocks) {
@@ -301,11 +284,6 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, buf_addr += pccb->datalen; }while (blks !=0 ); -/* Flush the SCSI cache so we don't lose data on board reset. */ -scsi_setup_sync_cache (pccb,0 ,0 ); -if (scsi_exec (bdev, pccb)) -scsi_print_error (pccb); -debug ("%s: end startblk " LBAF ", blccnt " LBAF " buffer %lX\n" , __func__, start, blocks, buf_addr);return blkcnt;
Signature · 1 line
2.34.1
Re: [PATCH v3 1/2] Revert "scsi: sync cache on write"
Quoted 7 lines · Balaji Selvanathan
Revert "scsi: sync cache on write"
While the
SYNC_CACHEapproach prevents data loss during board resets, it causes system hangs during large sparse image flashing operations. This will be replaced with a FUA (Force Unit Access) approach in future commit, which achieves the same data integrity goal more efficiently.
Quoted 6 lines
This reverts commit
ffe4e6ab42d2534302be825e49a2d085acf80f30.Signed-off-by Balaji Selvanathan <[email protected]>
drivers/scsi/scsi.c| 22 ----------------------1 file changed, 22 deletions(-)
PATCH v3 2/2 scsi: Enable FUA bit in WRITE10 commands
In reply to Balaji SelvanathanFrom: Aswin Murugan <[email protected]>
Enable the Force Unit Access (FUA) bit in SCSI WRITE10 commands to ensure writes bypass the device's volatile cache and go directly to non-volatile storage. This provides write-through behavior that prevents data loss during board resets.
---
Changes in v3:
- Added SoB in commit description.
--- drivers/scsi/scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi.c +1 -1
@@ -107,7 +107,7 @@ static void scsi_setup_write_ext(struct scsi_cmd *pccb, lbaint_t start, lbaint_t blocks) { pccb->cmd[0 ] =SCSI_WRITE10 ; - pccb->cmd[1 ] =0 ; + pccb->cmd[1 ] =0x08 ;/* Set FUA bit to bypass write cache */ pccb->cmd[2 ] = (unsigned char )(start >>24 ) &0xff ; pccb->cmd[3 ] = (unsigned char )(start >>16 ) &0xff ; pccb->cmd[4 ] = (unsigned char )(start >>8 ) &0xff ;
Signature · 1 line
2.34.1
Re: [PATCH v3 2/2] scsi: Enable FUA bit in WRITE10 commands
Quoted 7 lines · Balaji Selvanathan
scsi: Enable FUA bit in WRITE10 commands
Enable the Force Unit Access (FUA) bit in SCSI WRITE10 commands to ensure writes bypass the device's volatile cache and go directly to non-volatile storage. This provides write-through behavior that prevents data loss during board resets.
Quoted 6 lines
Reviewed-by Varadarajan Narayanan <[email protected]>Signed-off-by Aswin Murugan <[email protected]>Signed-off-by Balaji Selvanathan <[email protected]>
drivers/scsi/scsi.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 11 lines · Balaji Selvanathan
This series replaces the
SYNC_CACHEapproach with FUA (Force Unit Access) to prevent data loss during board resets while avoiding system hangs during large sparse image flashing operations.The previous
SYNC_CACHEimplementation caused timeouts and hangs when flashing large sparse images because it issued cache sync commands after every write operation. The FUA approach achieves the same data integrity goal by setting the FUA bit in WRITE10 commands.[...]
Applied to u-boot/master, thanks!
[1/2] Revert "scsi: sync cache on write"
commit: 34a44dad743b557542edf5b48f789e6bb6442628
[2/2] scsi: Enable FUA bit in WRITE10 commands
commit: 4b42c59a34bb9364bd2228fd2fead0c5750e7abfSignature · 1 line
Tom