[PATCH v3 14/33] swim: Check for CRC errors

From: Finn Thain

Date: Fri Sep 04 2026 - 06:03:32 EST


After reading either the sector header or sector data, examine that flag
in the handshake register which holds the result of the CRC calculation.
CRC validation has to take place with the last byte still in the FIFO.
This flag can't be checked by the caller because by then all bytes will
have been retrieved from the FIFO. Return an error code when appropriate.

Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support")
Signed-off-by: Finn Thain <fthain@xxxxxxxxxxxxxx>
---
Changed since v1:
- Load handshake register a second time because that's what MacOS does.

Changed since v2:
- Tidied up some hasty changes which appeared in v2.
- Dropped reviewed-by tag due to unreviewed changes made since v1.
---
drivers/block/swim_asm.S | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/block/swim_asm.S b/drivers/block/swim_asm.S
index 31fc63b074dc..81c824923336 100644
--- a/drivers/block/swim_asm.S
+++ b/drivers/block/swim_asm.S
@@ -42,6 +42,8 @@
.equ max_retry, 40
.equ sector_size, 512

+ .equ .Lhr_crc_error, 0x02
+
.global swim_read_sector_header
swim_read_sector_header:
link %a6, #0
@@ -134,6 +136,10 @@ crc1: tstb %a2@

moveb %a3@, %a4@(o_crc1)

+ moveb %a2@, %d5
+ andb #.Lhr_crc_error, %d5
+ bne signal_nonyb
+
tstb %a3@(read_error - read_mark)

moveq #0, %d0
@@ -224,6 +230,10 @@ data_crc1:

moveb %a3@, %d5

+ moveb %a2@, %d5
+ andb #.Lhr_crc_error, %d5
+ bne data_exit
+
tstb %a3@(read_error - read_mark)

/* return number of bytes read */
--
2.52.0