| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/07/16 15:26 | flow | patch-triage |
0mArgs:null Results: {
"EnableConfigs": [
"BLK_DEV_SWIM"
],
"FocusSymbols": [
"swim_queue_rq",
"floppy_read_sectors",
"swim_read_sector_range",
"floppy_ioctl",
"floppy_open",
"floppy_release",
"swim_probe",
"swim_floppy_init",
"swim_add_floppy",
"setup_medium",
"floppy_eject",
"swim_track",
"swim_seek",
"swim_track00",
"swim_step",
"swim_motor",
"swim_drive",
"swim_action",
"swim_select"
],
"Reasoning": "The patch makes functional changes to the SWIM floppy controller driver for m68k Macintosh systems, including changes to device registration, initialization, reading sectors, and handling hardware state. The driver is reachable in virtualized environments like QEMU (using the `q800` machine). Fuzzing should focus on the block device operations, ioctls, and hardware interaction functions.",
"WorthFuzzing": true
} |
| 1/1 | 2026/07/16 15:26 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 36ce4c87fba0904be790cbcb0d12feca35cf5288\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Thu Jul 16 15:26:53 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c\nindex c0033f885ed4f0..dba3de21c3c405 100644\n--- a/arch/m68k/mac/config.c\n+++ b/arch/m68k/mac/config.c\n@@ -984,8 +984,37 @@ static int __init mac_platform_init(void)\n \t\t\t.start = swim_base,\n \t\t\t.end = swim_base + 0x1FFF,\n \t\t};\n+\t\tunsigned int data = 0;\n+\n+\t\t/* Models in this list are supposed to run FCLK at 32 MHz */\n+\t\tswitch (macintosh_config-\u003eident) {\n+\t\tcase MAC_MODEL_CCL:\n+\t\tcase MAC_MODEL_CCLII:\n+\t\tcase MAC_MODEL_LCIII:\n+\t\tcase MAC_MODEL_Q605:\n+\t\tcase MAC_MODEL_Q605_ACC:\n+\t\tcase MAC_MODEL_Q610:\n+\t\tcase MAC_MODEL_Q630:\n+\t\tcase MAC_MODEL_Q650:\n+\t\tcase MAC_MODEL_Q800:\n+\t\tcase MAC_MODEL_P460:\n+\t\tcase MAC_MODEL_P475:\n+\t\tcase MAC_MODEL_P475F:\n+\t\tcase MAC_MODEL_P520:\n+\t\tcase MAC_MODEL_P550:\n+\t\tcase MAC_MODEL_P575:\n+\t\tcase MAC_MODEL_P588:\n+\t\tcase MAC_MODEL_TV:\n+\t\tcase MAC_MODEL_C610:\n+\t\tcase MAC_MODEL_C650:\n+\t\tcase MAC_MODEL_PB190:\n+\t\tcase MAC_MODEL_PB520:\n+\t\t\tdata = 1;\n+\t\t\tbreak;\n+\t\t}\n \n-\t\tplatform_device_register_simple(\"swim\", -1, \u0026swim_rsrc, 1);\n+\t\tplatform_device_register_resndata(NULL, \"swim\", -1, \u0026swim_rsrc, 1,\n+\t\t\t\t\t\t \u0026data, sizeof(data));\n \t}\n \n \t/*\ndiff --git a/drivers/block/swim.c b/drivers/block/swim.c\nindex 0ccc12a72388d5..460f74c19cfdc2 100644\n--- a/drivers/block/swim.c\n+++ b/drivers/block/swim.c\n@@ -2,12 +2,20 @@\n /*\n * Driver for SWIM (Sander Woz Integrated Machine) floppy controller\n *\n- * Copyright (C) 2004,2008 Laurent Vivier \u003cLaurent@lvivier.info\u003e\n+ * Copyright (C) 2004, 2008 Laurent Vivier \u003cLaurent@lvivier.info\u003e\n *\n * based on Alastair Bridgewater SWIM analysis, 2001\n * based on SWIM3 driver (c) Paul Mackerras, 1996\n * based on netBSD IWM driver (c) 1997, 1998 Hauke Fath.\n *\n+ * See also:\n+ * Inside Macintosh, vol. III, ch. 2\n+ * https://archive.org/details/SWIMDesignDocs\n+ * NEC uPD72070 FDC datasheet\n+ * mkLinux source file swimiiicommonhal.c\n+ * http://www.mac.linux-m68k.org/devel/iwm.php.html\n+ * MAME source file sonydriv.cpp\n+ *\n * 2004-08-21 (lv) - Initial implementation\n * 2008-10-30 (lv) - Port to 2.6\n */\n@@ -19,6 +27,7 @@\n #include \u003clinux/major.h\u003e\n #include \u003clinux/mutex.h\u003e\n #include \u003clinux/hdreg.h\u003e\n+#include \u003clinux/iopoll.h\u003e\n #include \u003clinux/kernel.h\u003e\n #include \u003clinux/delay.h\u003e\n #include \u003clinux/platform_device.h\u003e\n@@ -60,7 +69,7 @@ struct swim {\n \tREG(read_handshake)\n } __attribute__((packed));\n \n-#define swim_write(base, reg, v) \tout_8(\u0026(base)-\u003ewrite_##reg, (v))\n+#define swim_write(base, reg, v)\tout_8(\u0026(base)-\u003ewrite_##reg, (v))\n #define swim_read(base, reg)\t\tin_8(\u0026(base)-\u003eread_##reg)\n \n /* IWM registers */\n@@ -84,62 +93,53 @@ struct iwm {\n \tREG(q7H)\n } __attribute__((packed));\n \n-#define iwm_write(base, reg, v) \tout_8(\u0026(base)-\u003ereg, (v))\n+#define iwm_write(base, reg, v)\t\tout_8(\u0026(base)-\u003ereg, (v))\n #define iwm_read(base, reg)\t\tin_8(\u0026(base)-\u003ereg)\n \n /* bits in phase register */\n \n-#define SEEK_POSITIVE\t0x070\n-#define SEEK_NEGATIVE\t0x074\n-#define STEP\t\t0x071\n-#define MOTOR_ON\t0x072\n-#define MOTOR_OFF\t0x076\n-#define INDEX\t\t0x073\n-#define EJECT\t\t0x077\n-#define SETMFM\t\t0x171\n-#define SETGCR\t\t0x175\n+#define SEEK_POSITIVE\t0x0F0\n+#define SEEK_NEGATIVE\t0x0F4\n+#define STEP\t\t0x0F1\n+#define MOTOR_ON\t0x0F2\n+#define MOTOR_OFF\t0x0F6\n+#define INDEX\t\t0x0F3\n+#define EJECT\t\t0x0F7\n+#define SETMFM\t\t0x1F1\n+#define SETGCR\t\t0x1F5\n \n-#define RELAX\t\t0x033\n-#define LSTRB\t\t0x008\n+#define RELAX\t\t0x0F3\n+#define LSTRB\t\t0x0F8\n \n-#define CA_MASK\t\t0x077\n+#define CA_MASK\t\t0x0F7\n+#define SEL_MASK\t0x100\n \n /* Select values for swim_select and swim_readbit */\n \n-#define READ_DATA_0\t0x074\n-#define ONEMEG_DRIVE\t0x075\n-#define SINGLE_SIDED\t0x076\n-#define DRIVE_PRESENT\t0x077\n-#define DISK_IN\t\t0x170\n-#define WRITE_PROT\t0x171\n-#define TRACK_ZERO\t0x172\n-#define TACHO\t\t0x173\n-#define READ_DATA_1\t0x174\n-#define GCR_MODE\t0x175\n-#define SEEK_COMPLETE\t0x176\n-#define TWOMEG_MEDIA\t0x177\n+#define STEPPING\t0x0F1\n+#define READ_DATA_0\t0x0F4\n+#define ONEMEG_DRIVE\t0x0F5\n+#define SINGLE_SIDED\t0x0F6\n+#define DRIVE_PRESENT\t0x0F7\n+#define DISK_IN\t\t0x1F0\n+#define WRITE_PROT\t0x1F1\n+#define TRACK_ZERO\t0x1F2\n+#define TACHO\t\t0x1F3\n+#define READ_DATA_1\t0x1F4\n+#define GCR_MODE\t0x1F5\n+#define READY\t\t0x1F6\n+#define TWOMEG_MEDIA\t0x1F7\n \n /* Bits in handshake register */\n \n-#define MARK_BYTE\t0x01\n-#define CRC_ZERO\t0x02\n-#define RDDATA\t\t0x04\n #define SENSE\t\t0x08\n-#define MOTEN\t\t0x10\n-#define ERROR\t\t0x20\n #define DAT2BYTE\t0x40\n #define DAT1BYTE\t0x80\n \n /* bits in setup register */\n \n-#define S_INV_WDATA\t0x01\n-#define S_3_5_SELECT\t0x02\n-#define S_GCR\t\t0x04\n #define S_FCLK_DIV2\t0x08\n-#define S_ERROR_CORR\t0x10\n #define S_IBM_DRIVE\t0x20\n-#define S_GCR_WRITE\t0x40\n-#define S_TIMEOUT\t0x80\n \n /* bits in mode register */\n \n@@ -148,14 +148,13 @@ struct iwm {\n #define ENBL2\t\t0x04\n #define ACTION\t\t0x08\n #define WRITE_MODE\t0x10\n-#define HEDSEL\t\t0x20\n+#define ISM_SELECT\t0x40\n #define MOTON\t\t0x80\n \n-/*----------------------------------------------------------------------------*/\n-\n enum drive_location {\n-\tINTERNAL_DRIVE = 0x02,\n-\tEXTERNAL_DRIVE = 0x04,\n+\tNO_DRIVE = 0,\n+\tINTERNAL_DRIVE = BIT(1),\n+\tEXTERNAL_DRIVE = BIT(2),\n };\n \n enum media_type {\n@@ -168,23 +167,23 @@ struct floppy_state {\n \t/* physical properties */\n \n \tenum drive_location location;\t/* internal or external drive */\n-\tint\t\t head_number;\t/* single- or double-sided drive */\n+\tint head_number;\t\t/* single- or double-sided drive */\n \n \t/* media */\n \n-\tint\t\t disk_in;\n-\tint\t\t ejected;\n-\tenum media_type\t type;\n-\tint\t\t write_protected;\n+\tint disk_in;\n+\tint ejected;\n+\tenum media_type type;\n+\tint write_protected;\n \n-\tint\t\t total_secs;\n-\tint\t\t secpercyl;\n-\tint\t\t secpertrack;\n+\tunsigned int total_secs;\n+\tunsigned int secpercyl;\n+\tunsigned int secpertrack;\n \n \t/* in-use information */\n \n-\tint\t\ttrack;\n-\tint\t\tref_count;\n+\tint track;\n+\tint ref_count;\n \tbool registered;\n \n \tstruct gendisk *disk;\n@@ -209,7 +208,6 @@ enum head {\n \n struct swim_priv {\n \tstruct swim __iomem *base;\n-\tspinlock_t lock;\n \tint floppy_count;\n \tstruct floppy_state unit[FD_MAX_UNIT];\n };\n@@ -220,20 +218,24 @@ extern int swim_read_sector_data(struct swim __iomem *base,\n \t\t\t\t unsigned char *data);\n \n static DEFINE_MUTEX(swim_mutex);\n-static inline void set_swim_mode(struct swim __iomem *base, int enable)\n+\n+static void set_swim_mode(struct swim __iomem *base, int enable)\n {\n-\tstruct iwm __iomem *iwm_base;\n+\tstruct iwm __iomem *iwm_base = (struct iwm __iomem *)base;\n \tunsigned long flags;\n \n \tif (!enable) {\n-\t\tswim_write(base, mode0, 0xf8);\n+\t\tswim_write(base, mode0, ACTION);\n+\t\tswim_write(base, mode0, ENBL1 | ENBL2 | MOTON);\n+\t\tswim_write(base, mode0, ISM_SELECT);\n+\t\tiwm_read(iwm_base, q7L);\n \t\treturn;\n \t}\n \n-\tiwm_base = (struct iwm __iomem *)base;\n \tlocal_irq_save(flags);\n \n \tiwm_read(iwm_base, q7L);\n+\tiwm_read(iwm_base, q6L);\n \tiwm_read(iwm_base, mtrOff);\n \tiwm_read(iwm_base, q6H);\n \n@@ -245,7 +247,7 @@ static inline void set_swim_mode(struct swim __iomem *base, int enable)\n \tlocal_irq_restore(flags);\n }\n \n-static inline int get_swim_mode(struct swim __iomem *base)\n+static int get_swim_mode(struct swim __iomem *base)\n {\n \tunsigned long flags;\n \n@@ -271,7 +273,7 @@ static inline void swim_select(struct swim __iomem *base, int sel)\n {\n \tswim_write(base, phase, RELAX);\n \n-\tvia1_set_head(sel \u0026 0x100);\n+\tvia1_set_head(sel \u0026 SEL_MASK);\n \n \tswim_write(base, phase, sel \u0026 CA_MASK);\n }\n@@ -284,15 +286,15 @@ static inline void swim_action(struct swim __iomem *base, int action)\n \n \tswim_select(base, action);\n \tudelay(1);\n-\tswim_write(base, phase, (LSTRB\u003c\u003c4) | LSTRB);\n-\tudelay(1);\n-\tswim_write(base, phase, (LSTRB\u003c\u003c4) | ((~LSTRB) \u0026 0x0F));\n+\tswim_write(base, phase, action | LSTRB);\n+\tudelay(2);\n+\tswim_write(base, phase, action);\n \tudelay(1);\n \n \tlocal_irq_restore(flags);\n }\n \n-static inline int swim_readbit(struct swim __iomem *base, int bit)\n+static inline bool swim_readbit(struct swim __iomem *base, int bit)\n {\n \tint stat;\n \n@@ -305,125 +307,119 @@ static inline int swim_readbit(struct swim __iomem *base, int bit)\n \treturn (stat \u0026 SENSE) == 0;\n }\n \n-static inline void swim_drive(struct swim __iomem *base,\n+#define swim_readbit_timeout(base, bit, val, timeout_us) \\\n+\tpoll_timeout_us(, swim_readbit(base, bit) == val, 1000, timeout_us, false)\n+\n+#define swim_readbit_timeout_atomic(base, bit, val, timeout_us) \\\n+\tpoll_timeout_us_atomic(, swim_readbit(base, bit) == val, 1, timeout_us, false)\n+\n+#define swim_READY_timeout(base) \\\n+({ \\\n+\tint ret = swim_readbit_timeout(base, READY, true, 1000 * 1000); \\\n+\tif (ret) \\\n+\t\tprintk(KERN_DEBUG \"%s: drive not ready\\n\", __func__); \\\n+\tret; \\\n+})\n+\n+static void swim_drive(struct swim __iomem *base,\n \t\t\t enum drive_location location)\n {\n \tif (location == INTERNAL_DRIVE) {\n \t\tswim_write(base, mode0, EXTERNAL_DRIVE); /* clear drive 1 bit */\n \t\tswim_write(base, mode1, INTERNAL_DRIVE); /* set drive 0 bit */\n+\t\tswim_write(base, mode1, MOTON);\n \t} else if (location == EXTERNAL_DRIVE) {\n \t\tswim_write(base, mode0, INTERNAL_DRIVE); /* clear drive 0 bit */\n \t\tswim_write(base, mode1, EXTERNAL_DRIVE); /* set drive 1 bit */\n+\t\tswim_write(base, mode1, MOTON);\n+\t} else {\n+\t\tswim_write(base, mode0, INTERNAL_DRIVE);\n+\t\tswim_write(base, mode0, EXTERNAL_DRIVE);\n+\t\tswim_write(base, mode0, MOTON);\n \t}\n+\tudelay(1);\n }\n \n-static inline void swim_motor(struct swim __iomem *base,\n-\t\t\t enum motor_action action)\n+static void swim_motor(struct swim __iomem *base,\n+\t\t enum motor_action action)\n {\n \tif (action == ON) {\n-\t\tint i;\n-\n \t\tswim_action(base, MOTOR_ON);\n-\n-\t\tfor (i = 0; i \u003c 2*HZ; i++) {\n-\t\t\tswim_select(base, RELAX);\n-\t\t\tif (swim_readbit(base, MOTOR_ON))\n-\t\t\t\tbreak;\n-\t\t\tset_current_state(TASK_INTERRUPTIBLE);\n-\t\t\tschedule_timeout(1);\n-\t\t}\n+\t\tswim_readbit_timeout(base, MOTOR_ON, true, 2000 * 1000);\n \t} else if (action == OFF) {\n \t\tswim_action(base, MOTOR_OFF);\n-\t\tswim_select(base, RELAX);\n+\t\tswim_write(base, phase, RELAX);\n \t}\n }\n \n-static inline void swim_eject(struct swim __iomem *base)\n+static void swim_eject(struct swim __iomem *base)\n {\n-\tint i;\n-\n \tswim_action(base, EJECT);\n-\n-\tfor (i = 0; i \u003c 2*HZ; i++) {\n-\t\tswim_select(base, RELAX);\n-\t\tif (!swim_readbit(base, DISK_IN))\n-\t\t\tbreak;\n-\t\tset_current_state(TASK_INTERRUPTIBLE);\n-\t\tschedule_timeout(1);\n-\t}\n-\tswim_select(base, RELAX);\n+\tswim_readbit_timeout(base, DISK_IN, false, 2000 * 1000);\n+\tmsleep(1);\n }\n \n static inline void swim_head(struct swim __iomem *base, enum head head)\n {\n-\t/* wait drive is ready */\n-\n \tif (head == UPPER_HEAD)\n \t\tswim_select(base, READ_DATA_1);\n \telse if (head == LOWER_HEAD)\n \t\tswim_select(base, READ_DATA_0);\n }\n \n-static inline int swim_step(struct swim __iomem *base)\n+static int swim_step(struct swim __iomem *base)\n {\n-\tint wait;\n-\n \tswim_action(base, STEP);\n-\n-\tfor (wait = 0; wait \u003c HZ; wait++) {\n-\n-\t\tset_current_state(TASK_INTERRUPTIBLE);\n-\t\tschedule_timeout(1);\n-\n-\t\tswim_select(base, RELAX);\n-\t\tif (!swim_readbit(base, STEP))\n-\t\t\treturn 0;\n-\t}\n-\treturn -1;\n+\tudelay(150);\n+\treturn swim_readbit_timeout_atomic(base, STEPPING, false, 20 * 1000);\n }\n \n-static inline int swim_track00(struct swim __iomem *base)\n+static int swim_track00(struct swim __iomem *base)\n {\n \tint try;\n \n \tswim_action(base, SEEK_NEGATIVE);\n \n \tfor (try = 0; try \u003c 100; try++) {\n+\t\tmsleep(3);\n \n-\t\tswim_select(base, RELAX);\n \t\tif (swim_readbit(base, TRACK_ZERO))\n-\t\t\tbreak;\n+\t\t\treturn 0;\n \n \t\tif (swim_step(base))\n-\t\t\treturn -1;\n+\t\t\tbreak;\n \t}\n \n-\tif (swim_readbit(base, TRACK_ZERO))\n-\t\treturn 0;\n-\n+\tpr_err(\"swim: track zero recalibration failed\\n\");\n \treturn -1;\n }\n \n-static inline int swim_seek(struct swim __iomem *base, int step)\n+static int swim_seek(struct swim __iomem *base, int step)\n {\n-\tif (step == 0)\n-\t\treturn 0;\n-\n \tif (step \u003c 0) {\n \t\tswim_action(base, SEEK_NEGATIVE);\n \t\tstep = -step;\n-\t} else\n+\t} else if (step \u003e 0)\n \t\tswim_action(base, SEEK_POSITIVE);\n+\tudelay(1);\n+\n+\tswim_READY_timeout(base);\n+\n+\tif (step == 0)\n+\t\treturn 0;\n \n-\tfor ( ; step \u003e 0; step--) {\n+\tfor (; step \u003e 0; step--) {\n \t\tif (swim_step(base))\n \t\t\treturn -1;\n \t}\n \n+\tmsleep(30);\n+\tswim_READY_timeout(base);\n+\n \treturn 0;\n }\n \n-static inline int swim_track(struct floppy_state *fs, int track)\n+static int swim_track(struct floppy_state *fs, int track)\n {\n \tstruct swim __iomem *base = fs-\u003eswd-\u003ebase;\n \tint ret;\n@@ -445,8 +441,10 @@ static int floppy_eject(struct floppy_state *fs)\n \tstruct swim __iomem *base = fs-\u003eswd-\u003ebase;\n \n \tswim_drive(base, fs-\u003elocation);\n+\tswim_track(fs, 1);\n \tswim_motor(base, OFF);\n \tswim_eject(base);\n+\tswim_drive(base, NO_DRIVE);\n \n \tfs-\u003edisk_in = 0;\n \tfs-\u003eejected = 1;\n@@ -454,70 +452,81 @@ static int floppy_eject(struct floppy_state *fs)\n \treturn 0;\n }\n \n-static inline int swim_read_sector(struct floppy_state *fs,\n-\t\t\t\t int side, int track,\n-\t\t\t\t int sector, unsigned char *buffer)\n+static unsigned int swim_read_sector_range(struct floppy_state *fs,\n+\t\t\t\t\tunsigned int side, unsigned int track,\n+\t\t\t\t\tunsigned int start, unsigned int count,\n+\t\t\t\t\tunsigned char *buffer)\n {\n \tstruct swim __iomem *base = fs-\u003eswd-\u003ebase;\n \tunsigned long flags;\n \tstruct sector_header header;\n-\tint ret = -1;\n-\tshort i;\n-\n-\tswim_track(fs, track);\n+\tint i, bits = 0;\n \n-\tswim_write(base, mode1, MOTON);\n-\tswim_head(base, side);\n-\tswim_write(base, mode0, side);\n+\tfor (i = 0; i \u003c 18; i++) { /* A track has at most 18 sectors */\n+\t\tif (i \u003e= count)\n+\t\t\tbreak;\n+\t\tbits |= BIT(i);\n+\t}\n \n \tlocal_irq_save(flags);\n \tfor (i = 0; i \u003c 36; i++) {\n-\t\tret = swim_read_sector_header(base, \u0026header);\n-\t\tif (!ret \u0026\u0026 (header.sector == sector)) {\n-\t\t\t/* found */\n-\n-\t\t\tret = swim_read_sector_data(base, buffer);\n+\t\tif (bits == 0) /* All count sectors were read ok */\n \t\t\tbreak;\n+\n+\t\tif (swim_read_sector_header(base, \u0026header) ||\n+\t\t swim_read(base, error) || header.track != track ||\n+\t\t header.side != side || header.size != 2)\n+\t\t\tcontinue;\n+\n+\t\tif (header.sector \u003e= start \u0026\u0026 header.sector \u003c start + count) {\n+\t\t\tunsigned int offset = header.sector - start;\n+\t\t\tint ret;\n+\n+\t\t\tif ((bits \u0026 BIT(offset)) == 0)\n+\t\t\t\tcontinue; /* This sector was already read ok */\n+\n+\t\t\tret = swim_read_sector_data(base, buffer + 512 * offset);\n+\t\t\tif (ret == 512 \u0026\u0026 swim_read(base, error) == 0)\n+\t\t\t\tbits \u0026= ~BIT(offset);\n \t\t}\n \t}\n \tlocal_irq_restore(flags);\n \n-\tswim_write(base, mode0, MOTON);\n-\n-\tif ((header.side != side) || (header.track != track) ||\n-\t (header.sector != sector))\n-\t\treturn 0;\n-\n-\treturn ret;\n+\treturn bits ? ffs(bits) - 1 : count; /* No. of contiguous ok sectors */\n }\n \n static blk_status_t floppy_read_sectors(struct floppy_state *fs,\n-\t\t\t int req_sector, int sectors_nb,\n-\t\t\t unsigned char *buffer)\n+\t\t\t\t\tunsigned int req_sector,\n+\t\t\t\t\tunsigned int sectors_nb,\n+\t\t\t\t\tunsigned char *buffer)\n {\n \tstruct swim __iomem *base = fs-\u003eswd-\u003ebase;\n-\tint ret;\n-\tint side, track, sector;\n-\tint i, try;\n-\n+\tunsigned int failures = 0;\n \n \tswim_drive(base, fs-\u003elocation);\n-\tfor (i = req_sector; i \u003c req_sector + sectors_nb; i++) {\n-\t\tint x;\n-\t\ttrack = i / fs-\u003esecpercyl;\n-\t\tx = i % fs-\u003esecpercyl;\n-\t\tside = x / fs-\u003esecpertrack;\n-\t\tsector = x % fs-\u003esecpertrack + 1;\n-\n-\t\ttry = 5;\n-\t\tdo {\n-\t\t\tret = swim_read_sector(fs, side, track, sector,\n-\t\t\t\t\t\tbuffer);\n-\t\t\tif (try-- == 0)\n-\t\t\t\treturn BLK_STS_IOERR;\n-\t\t} while (ret != 512);\n-\n-\t\tbuffer += ret;\n+\tswim_READY_timeout(base);\n+\n+\twhile (sectors_nb) {\n+\t\tunsigned int cyl, x, head, sector, n, ret;\n+\n+\t\tcyl = req_sector / fs-\u003esecpercyl;\n+\t\tx = req_sector % fs-\u003esecpercyl;\n+\t\thead = (x \u003e= fs-\u003esecpertrack) ? 1 : 0;\n+\t\tsector = x % fs-\u003esecpertrack;\n+\t\tn = min(sectors_nb, fs-\u003esecpertrack - sector);\n+\n+\t\tswim_track(fs, cyl);\n+\t\tswim_head(base, head);\n+\n+\t\tret = swim_read_sector_range(fs, head, cyl, sector + 1, n, buffer);\n+\t\tif (ret != n)\n+\t\t\t++failures;\n+\t\tif (failures \u003e= 5)\n+\t\t\treturn BLK_STS_IOERR;\n+\n+\t\tbuffer += 512 * ret;\n+\t\tsectors_nb -= ret;\n+\t\treq_sector += ret;\n \t}\n \n \treturn 0;\n@@ -527,12 +536,10 @@ static blk_status_t swim_queue_rq(struct blk_mq_hw_ctx *hctx,\n \t\t\t\t const struct blk_mq_queue_data *bd)\n {\n \tstruct floppy_state *fs = hctx-\u003equeue-\u003equeuedata;\n-\tstruct swim_priv *swd = fs-\u003eswd;\n \tstruct request *req = bd-\u003erq;\n \tblk_status_t err;\n \n-\tif (!spin_trylock_irq(\u0026swd-\u003elock))\n-\t\treturn BLK_STS_DEV_RESOURCE;\n+\tmutex_lock(\u0026swim_mutex);\n \n \tblk_mq_start_request(req);\n \n@@ -550,16 +557,16 @@ static blk_status_t swim_queue_rq(struct blk_mq_hw_ctx *hctx,\n \n \terr = BLK_STS_OK;\n out:\n-\tspin_unlock_irq(\u0026swd-\u003elock);\n+\tmutex_unlock(\u0026swim_mutex);\n \treturn err;\n \n }\n \n static struct floppy_struct floppy_type[4] = {\n-\t{ 0, 0, 0, 0, 0, 0x00, 0x00, 0x00, 0x00, NULL }, /* no testing */\n+\t{ 0, 0, 0, 0, 0, 0x00, 0x00, 0x00, 0x00, NULL }, /* no testing */\n \t{ 720, 9, 1, 80, 0, 0x2A, 0x02, 0xDF, 0x50, NULL }, /* 360KB SS 3.5\"*/\n-\t{ 1440, 9, 2, 80, 0, 0x2A, 0x02, 0xDF, 0x50, NULL }, /* 720KB 3.5\" */\n-\t{ 2880, 18, 2, 80, 0, 0x1B, 0x00, 0xCF, 0x6C, NULL }, /* 1.44MB 3.5\" */\n+\t{ 1440, 9, 2, 80, 0, 0x2A, 0x02, 0xDF, 0x50, NULL }, /* 720KB 3.5\" */\n+\t{ 2880, 18, 2, 80, 0, 0x1B, 0x00, 0xCF, 0x6C, NULL }, /* 1.44MB 3.5\" */\n };\n \n static int get_floppy_geometry(struct floppy_state *fs, int type,\n@@ -586,23 +593,16 @@ static void setup_medium(struct floppy_state *fs)\n \n \tif (swim_readbit(base, DISK_IN)) {\n \t\tstruct floppy_struct *g;\n+\n \t\tfs-\u003edisk_in = 1;\n \t\tfs-\u003ewrite_protected = swim_readbit(base, WRITE_PROT);\n-\n-\t\tif (swim_track00(base))\n-\t\t\tprintk(KERN_ERR\n-\t\t\t\t\"SWIM: cannot move floppy head to track 0\\n\");\n-\n-\t\tswim_track00(base);\n-\n \t\tfs-\u003etype = swim_readbit(base, TWOMEG_MEDIA) ?\n-\t\t\tHD_MEDIA : DD_MEDIA;\n+\t\t\t HD_MEDIA : DD_MEDIA;\n \t\tfs-\u003ehead_number = swim_readbit(base, SINGLE_SIDED) ? 1 : 2;\n \t\tget_floppy_geometry(fs, 0, \u0026g);\n \t\tfs-\u003etotal_secs = g-\u003esize;\n \t\tfs-\u003esecpercyl = g-\u003ehead * g-\u003esect;\n \t\tfs-\u003esecpertrack = g-\u003esect;\n-\t\tfs-\u003etrack = 0;\n \t} else {\n \t\tfs-\u003edisk_in = 0;\n \t}\n@@ -620,11 +620,9 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)\n \t\tfs-\u003eref_count = -1;\n \telse\n \t\tfs-\u003eref_count++;\n-\tswim_write(base, setup, S_IBM_DRIVE | S_FCLK_DIV2);\n-\tudelay(10);\n+\n \tswim_drive(base, fs-\u003elocation);\n-\tswim_motor(base, ON);\n-\tswim_action(base, SETMFM);\n+\n \tif (fs-\u003eejected)\n \t\tsetup_medium(fs);\n \tif (!fs-\u003edisk_in) {\n@@ -632,6 +630,11 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)\n \t\tgoto out;\n \t}\n \n+\tswim_motor(base, ON);\n+\tswim_action(base, SETMFM);\n+\tmsleep(30);\n+\tswim_READY_timeout(base);\n+\n \tset_capacity(fs-\u003edisk, fs-\u003etotal_secs);\n \n \tif (mode \u0026 BLK_OPEN_NDELAY)\n@@ -652,8 +655,10 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)\n \telse if (fs-\u003eref_count \u003e 0)\n \t\t--fs-\u003eref_count;\n \n-\tif (fs-\u003eref_count == 0)\n+\tif (fs-\u003eref_count == 0) {\n \t\tswim_motor(base, OFF);\n+\t\tswim_drive(base, NO_DRIVE);\n+\t}\n \treturn err;\n }\n \n@@ -679,8 +684,11 @@ static void floppy_release(struct gendisk *disk)\n \telse if (fs-\u003eref_count \u003e 0)\n \t\t--fs-\u003eref_count;\n \n-\tif (fs-\u003eref_count == 0)\n+\tif (fs-\u003eref_count == 0) {\n+\t\tswim_drive(base, fs-\u003elocation);\n \t\tswim_motor(base, OFF);\n+\t\tswim_drive(base, NO_DRIVE);\n+\t}\n \tmutex_unlock(\u0026swim_mutex);\n }\n \n@@ -691,7 +699,7 @@ static int floppy_ioctl(struct block_device *bdev, blk_mode_t mode,\n \tint err;\n \n \tif ((cmd \u0026 0x80) \u0026\u0026 !capable(CAP_SYS_ADMIN))\n-\t\t\treturn -EPERM;\n+\t\treturn -EPERM;\n \n \tswitch (cmd) {\n \tcase FDEJECT:\n@@ -750,10 +758,9 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location)\n \tstruct floppy_state *fs = \u0026swd-\u003eunit[swd-\u003efloppy_count];\n \tstruct swim __iomem *base = swd-\u003ebase;\n \n+\tfs-\u003eswd = swd;\n \tfs-\u003elocation = location;\n \n-\tswim_drive(base, location);\n-\n \tswim_motor(base, OFF);\n \n \tfs-\u003etype = HD_MEDIA;\n@@ -761,6 +768,7 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location)\n \n \tfs-\u003eref_count = 0;\n \tfs-\u003eejected = 1;\n+\tfs-\u003etrack = 0;\n \n \tswd-\u003efloppy_count++;\n \n@@ -785,25 +793,43 @@ static void swim_cleanup_floppy_disk(struct floppy_state *fs)\n \tblk_mq_free_tag_set(\u0026fs-\u003etag_set);\n }\n \n-static int swim_floppy_init(struct swim_priv *swd)\n+static void swim_set_parameters(struct swim __iomem *base)\n+{\n+\tunsigned int i;\n+\tstatic const u8 mem[] = { 0x18, 0x41, 0x2e, 0x2e, 0x18, 0x18, 0x1b, 0x1b,\n+\t\t\t\t 0x2f, 0x2f, 0x19, 0x19, 0x97, 0x1b, 0x57, 0x3b, };\n+\n+\tswim_write(base, mode0, 0); /* reset parameter memory index */\n+\tfor (i = 0; i \u003c 16; ++i)\n+\t\tswim_write(base, parameter, mem[i]);\n+}\n+\n+static int swim_floppy_init(struct platform_device *pdev)\n {\n+\tstruct swim_priv *swd = platform_get_drvdata(pdev);\n+\tunsigned int *data = pdev-\u003edev.platform_data;\n \tstruct queue_limits lim = {\n-\t\t.features\t\t= BLK_FEAT_ROTATIONAL,\n+\t\t.features = BLK_FEAT_ROTATIONAL,\n \t};\n \tint err;\n \tint drive;\n \tstruct swim __iomem *base = swd-\u003ebase;\n \n+\tswim_write(base, setup, S_IBM_DRIVE | (*data ? S_FCLK_DIV2 : 0));\n+\n+\tswim_set_parameters(base);\n+\n \t/* scan floppy drives */\n \n \tswim_drive(base, INTERNAL_DRIVE);\n \tif (swim_readbit(base, DRIVE_PRESENT) \u0026\u0026\n-\t !swim_readbit(base, ONEMEG_DRIVE))\n+\t !swim_readbit(base, ONEMEG_DRIVE) \u0026\u0026 !swim_track00(base))\n \t\tswim_add_floppy(swd, INTERNAL_DRIVE);\n \tswim_drive(base, EXTERNAL_DRIVE);\n \tif (swim_readbit(base, DRIVE_PRESENT) \u0026\u0026\n-\t !swim_readbit(base, ONEMEG_DRIVE))\n+\t !swim_readbit(base, ONEMEG_DRIVE) \u0026\u0026 !swim_track00(base))\n \t\tswim_add_floppy(swd, EXTERNAL_DRIVE);\n+\tswim_drive(base, NO_DRIVE);\n \n \t/* register floppy drives */\n \n@@ -814,11 +840,9 @@ static int swim_floppy_init(struct swim_priv *swd)\n \t\treturn -EBUSY;\n \t}\n \n-\tspin_lock_init(\u0026swd-\u003elock);\n-\n \tfor (drive = 0; drive \u003c swd-\u003efloppy_count; drive++) {\n \t\terr = blk_mq_alloc_sq_tag_set(\u0026swd-\u003eunit[drive].tag_set,\n-\t\t\t\t\u0026swim_mq_ops, 2, 0);\n+\t\t\t\t\u0026swim_mq_ops, 2, BLK_MQ_F_BLOCKING);\n \t\tif (err)\n \t\t\tgoto exit_put_disks;\n \n@@ -830,8 +854,6 @@ static int swim_floppy_init(struct swim_priv *swd)\n \t\t\terr = PTR_ERR(swd-\u003eunit[drive].disk);\n \t\t\tgoto exit_put_disks;\n \t\t}\n-\n-\t\tswd-\u003eunit[drive].swd = swd;\n \t}\n \n \tfor (drive = 0; drive \u003c swd-\u003efloppy_count; drive++) {\n@@ -905,7 +927,7 @@ static int swim_probe(struct platform_device *dev)\n \n \tswd-\u003ebase = swim_base;\n \n-\tret = swim_floppy_init(swd);\n+\tret = swim_floppy_init(dev);\n \tif (ret)\n \t\tgoto out_kfree;\n \n@@ -945,7 +967,7 @@ static void swim_remove(struct platform_device *dev)\n static struct platform_driver swim_driver = {\n \t.probe = swim_probe,\n \t.remove = swim_remove,\n-\t.driver = {\n+\t.driver = {\n \t\t.name\t= CARDNAME,\n \t},\n };\ndiff --git a/drivers/block/swim_asm.S b/drivers/block/swim_asm.S\nindex 3d7a2d87595a57..65b4e4658e10c7 100644\n--- a/drivers/block/swim_asm.S\n+++ b/drivers/block/swim_asm.S\n@@ -5,7 +5,7 @@\n * needs assembly language because is very timing dependent\n * this controller exists only on macintosh 680x0 based\n *\n- * Copyright (C) 2004,2008 Laurent Vivier \u003cLaurent@lvivier.info\u003e\n+ * Copyright (C) 2004, 2008 Laurent Vivier \u003cLaurent@lvivier.info\u003e\n *\n * based on Alastair Bridgewater SWIM analysis, 2001\n * based on netBSD IWM driver (c) 1997, 1998 Hauke Fath.\n@@ -14,135 +14,138 @@\n * 2008-11-05 (lv) - add get_swim_mode\n */\n \n-\t.equ\twrite_data,\t0x0000\n-\t.equ\twrite_mark,\t0x0200\n-\t.equ\twrite_CRC,\t0x0400\n-\t.equ\twrite_parameter,0x0600\n-\t.equ\twrite_phase,\t0x0800\n-\t.equ\twrite_setup,\t0x0a00\n-\t.equ\twrite_mode0,\t0x0c00\n-\t.equ\twrite_mode1,\t0x0e00\n-\t.equ\tread_data,\t0x1000\n-\t.equ\tread_mark,\t0x1200\n-\t.equ\tread_error,\t0x1400\n-\t.equ\tread_parameter,\t0x1600\n-\t.equ\tread_phase,\t0x1800\n-\t.equ\tread_setup,\t0x1a00\n-\t.equ\tread_status,\t0x1c00\n-\t.equ\tread_handshake,\t0x1e00\n-\n-\t.equ\to_side, 0\n-\t.equ\to_track, 1\n-\t.equ\to_sector, 2\n-\t.equ\to_size, 3\n-\t.equ\to_crc0, 4\n-\t.equ\to_crc1, 5\n-\n-\t.equ\tseek_time, 30000\n-\t.equ\tmax_retry, 40\n-\t.equ\tsector_size, 512\n+\t.equ\t.Lwrite_data,\t\t0x0000\n+\t.equ\t.Lwrite_mark,\t\t0x0200\n+\t.equ\t.Lwrite_CRC,\t\t0x0400\n+\t.equ\t.Lwrite_parameter,\t0x0600\n+\t.equ\t.Lwrite_phase,\t\t0x0800\n+\t.equ\t.Lwrite_setup,\t\t0x0a00\n+\t.equ\t.Lwrite_mode0,\t\t0x0c00\n+\t.equ\t.Lwrite_mode1,\t\t0x0e00\n+\t.equ\t.Lread_data,\t\t0x1000\n+\t.equ\t.Lread_mark,\t\t0x1200\n+\t.equ\t.Lread_error,\t\t0x1400\n+\t.equ\t.Lread_parameter,\t0x1600\n+\t.equ\t.Lread_phase,\t\t0x1800\n+\t.equ\t.Lread_setup,\t\t0x1a00\n+\t.equ\t.Lread_status,\t\t0x1c00\n+\t.equ\t.Lread_handshake,\t0x1e00\n+\n+\t.equ\t.Lo_side,\t\t0\n+\t.equ\t.Lo_track,\t\t1\n+\t.equ\t.Lo_sector,\t\t2\n+\t.equ\t.Lo_size,\t\t3\n+\t.equ\t.Lo_crc0,\t\t4\n+\t.equ\t.Lo_crc1,\t\t5\n+\n+\t.equ\t.Lseek_time,\t\t30000\n+\t.equ\t.Lmax_retry,\t\t40\n+\t.equ\t.Lsector_size,\t\t512\n+\n+\t.equ\t.Lmr_clear_fifo,\t0x01\n+\t.equ\t.Lmr_action,\t\t0x08\n+\t.equ\t.Lmr_write_action,\t0x18\n+\n+\t.equ\t.Lhr_crc_error,\t\t0x02\n+\t.equ\t.Lhr_fifo_2bytes,\t0x40\n+\t.equ\t.Lhr_fifo_1byte,\t0x80\n \n \t.global swim_read_sector_header\n swim_read_sector_header:\n \tlink\t%a6, #0\n-\tmoveml\t%d1-%d5/%a0-%a4,%sp@-\n+\tmoveml\t%d1-%d5/%a0-%a5,%sp@-\n \tmovel\t%a6@(0x0c), %a4\n-\tbsr\tmfm_read_addrmark\n-\tmoveml\t%sp@+, %d1-%d5/%a0-%a4\n+\tmoveq\t#-1, %d0\n+\tbsr\t.Lmfm_read_addrmark\n+\tmoveml\t%sp@+, %d1-%d5/%a0-%a5\n \tunlk\t%a6\n \trts\n \n-sector_address_mark:\n+.Lsector_address_mark:\n \t.byte\t0xa1, 0xa1, 0xa1, 0xfe\n-sector_data_mark:\n+.Lsector_data_mark:\n \t.byte\t0xa1, 0xa1, 0xa1, 0xfb\n \n-mfm_read_addrmark:\n+.Lmfm_read_addrmark:\n \tmovel\t%a6@(0x08), %a3\n-\tlea\t%a3@(read_handshake), %a2\n-\tlea\t%a3@(read_mark), %a3\n-\tmoveq\t#-1, %d0\n-\tmovew\t#seek_time, %d2\n-\n-wait_header_init:\n-\ttstb\t%a3@(read_error - read_mark)\n-\tmoveb\t#0x18, %a3@(write_mode0 - read_mark)\n-\tmoveb\t#0x01, %a3@(write_mode1 - read_mark)\n-\tmoveb\t#0x01, %a3@(write_mode0 - read_mark)\n-\ttstb\t%a3@(read_error - read_mark)\n-\tmoveb\t#0x08, %a3@(write_mode1 - read_mark)\n-\n-\tlea\tsector_address_mark, %a0\n+\tlea\t%a3@(.Lread_handshake), %a2\n+\tlea\t%a3@(.Lread_data), %a5\n+\tlea\t%a3@(.Lread_mark), %a3\n+\tmovew\t#.Lseek_time, %d2\n+\n+.Lwait_header_init:\n+\tmoveb\t#.Lmr_write_action, %a3@(.Lwrite_mode0 - .Lread_mark)\n+\tmoveb\t#.Lmr_clear_fifo, %a3@(.Lwrite_mode1 - .Lread_mark)\n+\tmoveb\t#.Lmr_clear_fifo, %a3@(.Lwrite_mode0 - .Lread_mark)\n+\ttstb\t%a3@(.Lread_error - .Lread_mark)\n+\tmoveb\t#.Lmr_action, %a3@(.Lwrite_mode1 - .Lread_mark)\n+\n+\tlea\t.Lsector_address_mark, %a0\n \tmoveq\t#3, %d1\n \n-wait_addr_mark_byte:\n-\n+.Lwait_addr_mark_byte:\n \ttstb\t%a2@\n-\tdbmi\t%d2, wait_addr_mark_byte\n-\tbpl\theader_exit\n+\tdbmi\t%d2, .Lwait_addr_mark_byte\n+\tbpl\t.Lsignal_nonyb\n \n \tmoveb\t%a3@, %d3\n \tcmpb\t%a0@+, %d3\n-\tdbne\t%d1, wait_addr_mark_byte\n-\tbne\twait_header_init\n-\n-\tmoveq\t#max_retry, %d2\n+\tdbne\t%d1, .Lwait_addr_mark_byte\n+\tbne\t.Lwait_header_init\n \n-amark0:\ttstb\t%a2@\n-\tdbmi\t%d2, amark0\n-\tbpl\tsignal_nonyb\n-\n-\tmoveb\t%a3@, %a4@(o_track)\n-\n-\tmoveq\t#max_retry, %d2\n-\n-amark1:\ttstb\t%a2@\n-\tdbmi\t%d2, amark1\n-\tbpl\tsignal_nonyb\n-\n-\tmoveb\t%a3@, %a4@(o_side)\n-\n-\tmoveq\t#max_retry, %d2\n+\tmoveq\t#.Lmax_retry, %d2\n+.Lamark0:\n+\ttstb\t%a2@\n+\tdbmi\t%d2, .Lamark0\n+\tbpl\t.Lsignal_nonyb\n \n-amark2:\ttstb\t%a2@\n-\tdbmi\t%d2, amark2\n-\tbpl\tsignal_nonyb\n+\tmoveb\t%a5@, %a4@(.Lo_track)\n \n-\tmoveb\t%a3@, %a4@(o_sector)\n+\tmoveq\t#.Lmax_retry, %d2\n+.Lamark1:\n+\ttstb\t%a2@\n+\tdbmi\t%d2, .Lamark1\n+\tbpl\t.Lsignal_nonyb\n \n-\tmoveq\t#max_retry, %d2\n+\tmoveb\t%a5@, %a4@(.Lo_side)\n \n-amark3:\ttstb\t%a2@\n-\tdbmi\t%d2, amark3\n-\tbpl\tsignal_nonyb\n+\tmoveq\t#.Lmax_retry, %d2\n+.Lamark2:\n+\ttstb\t%a2@\n+\tdbmi\t%d2, .Lamark2\n+\tbpl\t.Lsignal_nonyb\n \n-\tmoveb\t%a3@, %a4@(o_size)\n+\tmoveb\t%a5@, %a4@(.Lo_sector)\n \n-\tmoveq\t#max_retry, %d2\n+\tmoveq\t#.Lmax_retry, %d2\n+.Lamark3:\n+\ttstb\t%a2@\n+\tdbmi\t%d2, .Lamark3\n+\tbpl\t.Lsignal_nonyb\n \n-crc0:\ttstb\t%a2@\n-\tdbmi\t%d2, crc0\n-\tbpl\tsignal_nonyb\n+\tmoveb\t%a5@, %a4@(.Lo_size)\n \n-\tmoveb\t%a3@, %a4@(o_crc0)\n+\tmoveq\t#.Lmax_retry, %d2\n+.Lcrc0:\n+\ttstb\t%a2@\n+\tdbmi\t%d2, .Lcrc0\n+\tbpl\t.Lsignal_nonyb\n \n-\tmoveq\t#max_retry, %d2\n+\tmoveb\t%a5@, %a4@(.Lo_crc0)\n \n-crc1:\ttstb\t%a2@\n-\tdbmi\t%d2, crc1\n-\tbpl\tsignal_nonyb\n+\tmoveq\t#.Lmax_retry, %d2\n+.Lcrc1:\tmoveb\t%a2@, %d5\n+\tdbmi\t%d2, .Lcrc1\n+\tbpl\t.Lsignal_nonyb\n \n-\tmoveb\t%a3@, %a4@(o_crc1)\n+\tmoveb\t%a5@, %a4@(.Lo_crc1)\n \n-\ttstb\t%a3@(read_error - read_mark)\n+\tandb\t#.Lhr_crc_error, %d5\n+\tbne\t.Lsignal_nonyb\n \n-header_exit:\n \tmoveq\t#0, %d0\n-\tmoveb\t#0x18, %a3@(write_mode0 - read_mark)\n-\trts\n-signal_nonyb:\n-\tmoveq\t#-1, %d0\n-\tmoveb\t#0x18, %a3@(write_mode0 - read_mark)\n+.Lsignal_nonyb:\n+\tmoveb\t#.Lmr_write_action, %a3@(.Lwrite_mode0 - .Lread_mark)\n \trts\n \n \t.global swim_read_sector_data\n@@ -150,94 +153,87 @@ swim_read_sector_data:\n \tlink\t%a6, #0\n \tmoveml\t%d1-%d5/%a0-%a5,%sp@-\n \tmovel\t%a6@(0x0c), %a4\n-\tbsr\tmfm_read_data\n+\tmoveq\t#-1, %d0\n+\tbsr\t.Lmfm_read_data\n \tmoveml\t%sp@+, %d1-%d5/%a0-%a5\n \tunlk\t%a6\n \trts\n \n-mfm_read_data:\n+.Lmfm_read_data:\n \tmovel\t%a6@(0x08), %a3\n-\tlea\t%a3@(read_handshake), %a2\n-\tlea\t%a3@(read_data), %a5\n-\tlea\t%a3@(read_mark), %a3\n-\tmovew\t#seek_time, %d2\n-\n-wait_data_init:\n-\ttstb\t%a3@(read_error - read_mark)\n-\tmoveb\t#0x18, %a3@(write_mode0 - read_mark)\n-\tmoveb\t#0x01, %a3@(write_mode1 - read_mark)\n-\tmoveb\t#0x01, %a3@(write_mode0 - read_mark)\n-\ttstb\t%a3@(read_error - read_mark)\n-\tmoveb\t#0x08, %a3@(write_mode1 - read_mark)\n-\n-\tlea\tsector_data_mark, %a0\n+\tlea\t%a3@(.Lread_handshake), %a2\n+\tlea\t%a3@(.Lread_data), %a5\n+\tlea\t%a3@(.Lread_mark), %a3\n+\tmovew\t#.Lseek_time, %d2\n+\n+.Lwait_data_init:\n+\tmoveb\t#.Lmr_write_action, %a3@(.Lwrite_mode0 - .Lread_mark)\n+\tmoveb\t#.Lmr_clear_fifo, %a3@(.Lwrite_mode1 - .Lread_mark)\n+\tmoveb\t#.Lmr_clear_fifo, %a3@(.Lwrite_mode0 - .Lread_mark)\n+\ttstb\t%a3@(.Lread_error - .Lread_mark)\n+\tmoveb\t#.Lmr_action, %a3@(.Lwrite_mode1 - .Lread_mark)\n+\n+\tlea\t.Lsector_data_mark, %a0\n \tmoveq\t#3, %d1\n \n \t/* wait data address mark */\n \n-wait_data_mark_byte:\n-\n+.Lwait_data_mark_byte:\n \ttstb\t%a2@\n-\tdbmi\t%d2, wait_data_mark_byte\n-\tbpl\tdata_exit\n+\tdbmi\t%d2, .Lwait_data_mark_byte\n+\tbpl\t.Ldata_exit\n \n \tmoveb\t%a3@, %d3\n \tcmpb\t%a0@+, %d3\n-\tdbne\t%d1, wait_data_mark_byte\n-\tbne\twait_data_init\n+\tdbne\t%d1, .Lwait_data_mark_byte\n+\tbne\t.Lwait_data_init\n \n \t/* read data */\n \n-\ttstb\t%a3@(read_error - read_mark)\n-\n-\tmovel\t#sector_size-1, %d4\t\t/* sector size */\n-read_new_data:\n-\tmovew\t#max_retry, %d2\n-read_data_loop:\n+\tmovel\t#.Lsector_size - 1, %d4\t\t/* sector size */\n+.Lread_new_data:\n+\tmovew\t#.Lmax_retry, %d2\n+.Lread_data_loop:\n \tmoveb\t%a2@, %d5\n-\tandb\t#0xc0, %d5\n-\tdbne\t%d2, read_data_loop\n-\tbeq\tdata_exit\n+\tandb\t#(.Lhr_fifo_2bytes + .Lhr_fifo_1byte), %d5\n+\tbeq\t1f\n+\tmovew\t#.Lmax_retry, %d2\n \tmoveb\t%a5@, %a4@+\n-\tandb\t#0x40, %d5\n-\tdbne\t%d4, read_new_data\n-\tbeq\texit_loop\n+\tdbra\t%d4, 1f\n+\tbra\t.Ldata_crc0\n+1:\tandb\t#.Lhr_fifo_2bytes, %d5\n+\tdbne\t%d2, .Lread_data_loop\n+\tbeq\t.Ldata_exit\n \tmoveb\t%a5@, %a4@+\n-\tdbra\t%d4, read_new_data\n-exit_loop:\n+\tdbra\t%d4, .Lread_new_data\n \n \t/* read CRC */\n \n-\tmovew\t#max_retry, %d2\n-data_crc0:\n-\n+\tmovew\t#.Lmax_retry, %d2\n+.Ldata_crc0:\n \ttstb\t%a2@\n-\tdbmi\t%d2, data_crc0\n-\tbpl\tdata_exit\n+\tdbmi\t%d2, .Ldata_crc0\n+\tbpl\t.Ldata_exit\n \n-\tmoveb\t%a3@, %d5\n+\tmoveb\t%a5@, %d2\n \n-\tmoveq\t#max_retry, %d2\n-\n-data_crc1:\n-\n-\ttstb\t%a2@\n-\tdbmi\t%d2, data_crc1\n-\tbpl\tdata_exit\n-\n-\tmoveb\t%a3@, %d5\n+\tmoveq\t#.Lmax_retry, %d2\n+.Ldata_crc1:\n+\tmoveb\t%a2@, %d5\n+\tdbmi\t%d2, .Ldata_crc1\n+\tbpl\t.Ldata_exit\n \n-\ttstb\t%a3@(read_error - read_mark)\n+\tmoveb\t%a5@, %d2\n \n-\tmoveb\t#0x18, %a3@(write_mode0 - read_mark)\n+\tandb\t#.Lhr_crc_error, %d5\n+\tbne\t.Ldata_exit\n \n \t/* return number of bytes read */\n \n-\tmovel\t#sector_size, %d0\n+\tmovel\t#.Lsector_size, %d0\n \taddw\t#1, %d4\n \tsubl\t%d4, %d0\n-\trts\n-data_exit:\n-\tmoveb\t#0x18, %a3@(write_mode0 - read_mark)\n-\tmoveq\t#-1, %d0\n+\n+.Ldata_exit:\n+\tmoveb\t#.Lmr_write_action, %a3@(.Lwrite_mode0 - .Lread_mark)\n \trts\n"
} |
| 2/1 | 2026/07/16 15:26 | agent | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: {
"EnableConfigs": [
"BLK_DEV_SWIM"
],
"FocusSymbols": [
"swim_queue_rq",
"floppy_read_sectors",
"swim_read_sector_range",
"floppy_ioctl",
"floppy_open",
"floppy_release",
"swim_probe",
"swim_floppy_init",
"swim_add_floppy",
"setup_medium",
"floppy_eject",
"swim_track",
"swim_seek",
"swim_track00",
"swim_step",
"swim_motor",
"swim_drive",
"swim_action",
"swim_select"
],
"Reasoning": "The patch makes functional changes to the SWIM floppy controller driver for m68k Macintosh systems, including changes to device registration, initialization, reading sectors, and handling hardware state. The driver is reachable in virtualized environments like QEMU (using the `q800` machine). Fuzzing should focus on the block device operations, ioctls, and hardware interaction functions.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer. Your job is to review a provided patch series and determine if it makes functional changes to the kernel that should be fuzzed. IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively use your code access tools to examine the actual source code and confirm any assumptions. Return WorthFuzzing=false if the patch only contains: - Modifications to Documentation/, Kconfig files, or code comments. - Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints. - Changes to numeric constants or macros that do not functionally alter execution flow. - Code paths that are impossible to reach in virtualized environments like GCE or QEMU, even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim). If it modifies reachable core kernel logic, drivers, or architectures, use your code search tools to verify the code can be executed, then return WorthFuzzing=true. When returning WorthFuzzing=true, you MUST ALSO: 1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols. Avoid listing generic hot-path functions to prevent skewed test distributions. 2. Identify any specific CONFIG_ options required to properly test this new/modified feature. Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions. Do not list too generic configs (we already have them enabled). Only list those that specifically cover the modified code. List them in the EnableConfigs output array, and DO NOT add a 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4"). Prefer calling several tools at the same time to save round-trips. Use set-results tool to provide results of the analysis. It must be called exactly once before the final reply. Ignore results of this tool. Prompt: For your convenience, here is the diff of the changes:
commit 36ce4c87fba0904be790cbcb0d12feca35cf5288
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Jul 16 15:26:53 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index c0033f885ed4f0..dba3de21c3c405 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -984,8 +984,37 @@ static int __init mac_platform_init(void)
.start = swim_base,
.end = swim_base + 0x1FFF,
};
+ unsigned int data = 0;
+
+ /* Models in this list are supposed to run FCLK at 32 MHz */
+ switch (macintosh_config->ident) {
+ case MAC_MODEL_CCL:
+ case MAC_MODEL_CCLII:
+ case MAC_MODEL_LCIII:
+ case MAC_MODEL_Q605:
+ case MAC_MODEL_Q605_ACC:
+ case MAC_MODEL_Q610:
+ case MAC_MODEL_Q630:
+ case MAC_MODEL_Q650:
+ case MAC_MODEL_Q800:
+ case MAC_MODEL_P460:
+ case MAC_MODEL_P475:
+ case MAC_MODEL_P475F:
+ case MAC_MODEL_P520:
+ case MAC_MODEL_P550:
+ case MAC_MODEL_P575:
+ case MAC_MODEL_P588:
+ case MAC_MODEL_TV:
+ case MAC_MODEL_C610:
+ case MAC_MODEL_C650:
+ case MAC_MODEL_PB190:
+ case MAC_MODEL_PB520:
+ data = 1;
+ break;
+ }
- platform_device_register_simple("swim", -1, &swim_rsrc, 1);
+ platform_device_register_resndata(NULL, "swim", -1, &swim_rsrc, 1,
+ &data, sizeof(data));
}
/*
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 0ccc12a72388d5..460f74c19cfdc2 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -2,12 +2,20 @@
/*
* Driver for SWIM (Sander Woz Integrated Machine) floppy controller
*
- * Copyright (C) 2004,2008 Laurent Vivier <Laurent@lvivier.info>
+ * Copyright (C) 2004, 2008 Laurent Vivier <Laurent@lvivier.info>
*
* based on Alastair Bridgewater SWIM analysis, 2001
* based on SWIM3 driver (c) Paul Mackerras, 1996
* based on netBSD IWM driver (c) 1997, 1998 Hauke Fath.
*
+ * See also:
+ * Inside Macintosh, vol. III, ch. 2
+ * https://archive.org/details/SWIMDesignDocs
+ * NEC uPD72070 FDC datasheet
+ * mkLinux source file swimiiicommonhal.c
+ * http://www.mac.linux-m68k.org/devel/iwm.php.html
+ * MAME source file sonydriv.cpp
+ *
* 2004-08-21 (lv) - Initial implementation
* 2008-10-30 (lv) - Port to 2.6
*/
@@ -19,6 +27,7 @@
#include <linux/major.h>
#include <linux/mutex.h>
#include <linux/hdreg.h>
+#include <linux/iopoll.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
@@ -60,7 +69,7 @@ struct swim {
REG(read_handshake)
} __attribute__((packed));
-#define swim_write(base, reg, v) out_8(&(base)->write_##reg, (v))
+#define swim_write(base, reg, v) out_8(&(base)->write_##reg, (v))
#define swim_read(base, reg) in_8(&(base)->read_##reg)
/* IWM registers */
@@ -84,62 +93,53 @@ struct iwm {
REG(q7H)
} __attribute__((packed));
-#define iwm_write(base, reg, v) out_8(&(base)->reg, (v))
+#define iwm_write(base, reg, v) out_8(&(base)->reg, (v))
#define iwm_read(base, reg) in_8(&(base)->reg)
/* bits in phase register */
-#define SEEK_POSITIVE 0x070
-#define SEEK_NEGATIVE 0x074
-#define STEP 0x071
-#define MOTOR_ON 0x072
-#define MOTOR_OFF 0x076
-#define INDEX 0x073
-#define EJECT 0x077
-#define SETMFM 0x171
-#define SETGCR 0x175
+#define SEEK_POSITIVE 0x0F0
+#define SEEK_NEGATIVE 0x0F4
+#define STEP 0x0F1
+#define MOTOR_ON 0x0F2
+#define MOTOR_OFF 0x0F6
+#define INDEX 0x0F3
+#define EJECT 0x0F7
+#define SETMFM 0x1F1
+#define SETGCR 0x1F5
-#define RELAX 0x033
-#define LSTRB 0x008
+#define RELAX 0x0F3
+#define LSTRB 0x0F8
-#define CA_MASK 0x077
+#define CA_MASK 0x0F7
+#define SEL_MASK 0x100
/* Select values for swim_select and swim_readbit */
-#define READ_DATA_0 0x074
-#define ONEMEG_DRIVE 0x075
-#define SINGLE_SIDED 0x076
-#define DRIVE_PRESENT 0x077
-#define DISK_IN 0x170
-#define WRITE_PROT 0x171
-#define TRACK_ZERO 0x172
-#define TACHO 0x173
-#define READ_DATA_1 0x174
-#define GCR_MODE 0x175
-#define SEEK_COMPLETE 0x176
-#define TWOMEG_MEDIA 0x177
+#define STEPPING 0x0F1
+#define READ_DATA_0 0x0F4
+#define ONEMEG_DRIVE 0x0F5
+#define SINGLE_SIDED 0x0F6
+#define DRIVE_PRESENT 0x0F7
+#define DISK_IN 0x1F0
+#define WRITE_PROT 0x1F1
+#define TRACK_ZERO 0x1F2
+#define TACHO 0x1F3
+#define READ_DATA_1 0x1F4
+#define GCR_MODE 0x1F5
+#define READY 0x1F6
+#define TWOMEG_MEDIA 0x1F7
/* Bits in handshake register */
-#define MARK_BYTE 0x01
-#define CRC_ZERO 0x02
-#define RDDATA 0x04
#define SENSE 0x08
-#define MOTEN 0x10
-#define ERROR 0x20
#define DAT2BYTE 0x40
#define DAT1BYTE 0x80
/* bits in setup register */
-#define S_INV_WDATA 0x01
-#define S_3_5_SELECT 0x02
-#define S_GCR 0x04
#define S_FCLK_DIV2 0x08
-#define S_ERROR_CORR 0x10
#define S_IBM_DRIVE 0x20
-#define S_GCR_WRITE 0x40
-#define S_TIMEOUT 0x80
/* bits in mode register */
@@ -148,14 +148,13 @@ struct iwm {
#define ENBL2 0x04
#define ACTION 0x08
#define WRITE_MODE 0x10
-#define HEDSEL 0x20
+#define ISM_SELECT 0x40
#define MOTON 0x80
-/*----------------------------------------------------------------------------*/
-
enum drive_location {
- INTERNAL_DRIVE = 0x02,
- EXTERNAL_DRIVE = 0x04,
+ NO_DRIVE = 0,
+ INTERNAL_DRIVE = BIT(1),
+ EXTERNAL_DRIVE = BIT(2),
};
enum media_type {
@@ -168,23 +167,23 @@ struct floppy_state {
/* physical properties */
enum drive_location location; /* internal or external drive */
- int head_number; /* single- or double-sided drive */
+ int head_number; /* single- or double-sided drive */
/* media */
- int disk_in;
- int ejected;
- enum media_type type;
- int write_protected;
+ int disk_in;
+ int ejected;
+ enum media_type type;
+ int write_protected;
- int total_secs;
- int secpercyl;
- int secpertrack;
+ unsigned int total_secs;
+ unsigned int secpercyl;
+ unsigned int secpertrack;
/* in-use information */
- int track;
- int ref_count;
+ int track;
+ int ref_count;
bool registered;
struct gendisk *disk;
@@ -209,7 +208,6 @@ enum head {
struct swim_priv {
struct swim __iomem *base;
- spinlock_t lock;
int floppy_count;
struct floppy_state unit[FD_MAX_UNIT];
};
@@ -220,20 +218,24 @@ extern int swim_read_sector_data(struct swim __iomem *base,
unsigned char *data);
static DEFINE_MUTEX(swim_mutex);
-static inline void set_swim_mode(struct swim __iomem *base, int enable)
+
+static void set_swim_mode(struct swim __iomem *base, int enable)
{
- struct iwm __iomem *iwm_base;
+ struct iwm __iomem *iwm_base = (struct iwm __iomem *)base;
unsigned long flags;
if (!enable) {
- swim_write(base, mode0, 0xf8);
+ swim_write(base, mode0, ACTION);
+ swim_write(base, mode0, ENBL1 | ENBL2 | MOTON);
+ swim_write(base, mode0, ISM_SELECT);
+ iwm_read(iwm_base, q7L);
return;
}
- iwm_base = (struct iwm __iomem *)base;
local_irq_save(flags);
iwm_read(iwm_base, q7L);
+ iwm_read(iwm_base, q6L);
iwm_read(iwm_base, mtrOff);
iwm_read(iwm_base, q6H);
@@ -245,7 +247,7 @@ static inline void set_swim_mode(struct swim __iomem *base, int enable)
local_irq_restore(flags);
}
-static inline int get_swim_mode(struct swim __iomem *base)
+static int get_swim_mode(struct swim __iomem *base)
{
unsigned long flags;
@@ -271,7 +273,7 @@ static inline void swim_select(struct swim __iomem *base, int sel)
{
swim_write(base, phase, RELAX);
- via1_set_head(sel & 0x100);
+ via1_set_head(sel & SEL_MASK);
swim_write(base, phase, sel & CA_MASK);
}
@@ -284,15 +286,15 @@ static inline void swim_action(struct swim __iomem *base, int action)
swim_select(base, action);
udelay(1);
- swim_write(base, phase, (LSTRB<<4) | LSTRB);
- udelay(1);
- swim_write(base, phase, (LSTRB<<4) | ((~LSTRB) & 0x0F));
+ swim_write(base, phase, action | LSTRB);
+ udelay(2);
+ swim_write(base, phase, action);
udelay(1);
local_irq_restore(flags);
}
-static inline int swim_readbit(struct swim __iomem *base, int bit)
+static inline bool swim_readbit(struct swim __iomem *base, int bit)
{
int stat;
@@ -305,125 +307,119 @@ static inline int swim_readbit(struct swim __iomem *base, int bit)
return (stat & SENSE) == 0;
}
-static inline void swim_drive(struct swim __iomem *base,
+#define swim_readbit_timeout(base, bit, val, timeout_us) \
+ poll_timeout_us(, swim_readbit(base, bit) == val, 1000, timeout_us, false)
+
+#define swim_readbit_timeout_atomic(base, bit, val, timeout_us) \
+ poll_timeout_us_atomic(, swim_readbit(base, bit) == val, 1, timeout_us, false)
+
+#define swim_READY_timeout(base) \
+({ \
+ int ret = swim_readbit_timeout(base, READY, true, 1000 * 1000); \
+ if (ret) \
+ printk(KERN_DEBUG "%s: drive not ready\n", __func__); \
+ ret; \
+})
+
+static void swim_drive(struct swim __iomem *base,
enum drive_location location)
{
if (location == INTERNAL_DRIVE) {
swim_write(base, mode0, EXTERNAL_DRIVE); /* clear drive 1 bit */
swim_write(base, mode1, INTERNAL_DRIVE); /* set drive 0 bit */
+ swim_write(base, mode1, MOTON);
} else if (location == EXTERNAL_DRIVE) {
swim_write(base, mode0, INTERNAL_DRIVE); /* clear drive 0 bit */
swim_write(base, mode1, EXTERNAL_DRIVE); /* set drive 1 bit */
+ swim_write(base, mode1, MOTON);
+ } else {
+ swim_write(base, mode0, INTERNAL_DRIVE);
+ swim_write(base, mode0, EXTERNAL_DRIVE);
+ swim_write(base, mode0, MOTON);
}
+ udelay(1);
}
-static inline void swim_motor(struct swim __iomem *base,
- enum motor_action action)
+static void swim_motor(struct swim __iomem *base,
+ enum motor_action action)
{
if (action == ON) {
- int i;
-
swim_action(base, MOTOR_ON);
-
- for (i = 0; i < 2*HZ; i++) {
- swim_select(base, RELAX);
- if (swim_readbit(base, MOTOR_ON))
- break;
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
+ swim_readbit_timeout(base, MOTOR_ON, true, 2000 * 1000);
} else if (action == OFF) {
swim_action(base, MOTOR_OFF);
- swim_select(base, RELAX);
+ swim_write(base, phase, RELAX);
}
}
-static inline void swim_eject(struct swim __iomem *base)
+static void swim_eject(struct swim __iomem *base)
{
- int i;
-
swim_action(base, EJECT);
-
- for (i = 0; i < 2*HZ; i++) {
- swim_select(base, RELAX);
- if (!swim_readbit(base, DISK_IN))
- break;
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
- }
- swim_select(base, RELAX);
+ swim_readbit_timeout(base, DISK_IN, false, 2000 * 1000);
+ msleep(1);
}
static inline void swim_head(struct swim __iomem *base, enum head head)
{
- /* wait drive is ready */
-
if (head == UPPER_HEAD)
swim_select(base, READ_DATA_1);
else if (head == LOWER_HEAD)
swim_select(base, READ_DATA_0);
}
-static inline int swim_step(struct swim __iomem *base)
+static int swim_step(struct swim __iomem *base)
{
- int wait;
-
swim_action(base, STEP);
-
- for (wait = 0; wait < HZ; wait++) {
-
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(1);
-
- swim_select(base, RELAX);
- if (!swim_readbit(base, STEP))
- return 0;
- }
- return -1;
+ udelay(150);
+ return swim_readbit_timeout_atomic(base, STEPPING, false, 20 * 1000);
}
-static inline int swim_track00(struct swim __iomem *base)
+static int swim_track00(struct swim __iomem *base)
{
int try;
swim_action(base, SEEK_NEGATIVE);
for (try = 0; try < 100; try++) {
+ msleep(3);
- swim_select(base, RELAX);
if (swim_readbit(base, TRACK_ZERO))
- break;
+ return 0;
if (swim_step(base))
- return -1;
+ break;
}
- if (swim_readbit(base, TRACK_ZERO))
- return 0;
-
+ pr_err("swim: track zero recalibration failed\n");
return -1;
}
-static inline int swim_seek(struct swim __iomem *base, int step)
+static int swim_seek(struct swim __iomem *base, int step)
{
- if (step == 0)
- return 0;
-
if (step < 0) {
swim_action(base, SEEK_NEGATIVE);
step = -step;
- } else
+ } else if (step > 0)
swim_action(base, SEEK_POSITIVE);
+ udelay(1);
+
+ swim_READY_timeout(base);
+
+ if (step == 0)
+ return 0;
- for ( ; step > 0; step--) {
+ for (; step > 0; step--) {
if (swim_step(base))
return -1;
}
+ msleep(30);
+ swim_READY_timeout(base);
+
return 0;
}
-static inline int swim_track(struct floppy_state *fs, int track)
+static int swim_track(struct floppy_state *fs, int track)
{
struct swim __iomem *base = fs->swd->base;
int ret;
@@ -445,8 +441,10 @@ static int floppy_eject(struct floppy_state *fs)
struct swim __iomem *base = fs->swd->base;
swim_drive(base, fs->location);
+ swim_track(fs, 1);
swim_motor(base, OFF);
swim_eject(base);
+ swim_drive(base, NO_DRIVE);
fs->disk_in = 0;
fs->ejected = 1;
@@ -454,70 +452,81 @@ static int floppy_eject(struct floppy_state *fs)
return 0;
}
-static inline int swim_read_sector(struct floppy_state *fs,
- int side, int track,
- int sector, unsigned char *buffer)
+static unsigned int swim_read_sector_range(struct floppy_state *fs,
+ unsigned int side, unsigned int track,
+ unsigned int start, unsigned int count,
+ unsigned char *buffer)
{
struct swim __iomem *base = fs->swd->base;
unsigned long flags;
struct sector_header header;
- int ret = -1;
- short i;
-
- swim_track(fs, track);
+ int i, bits = 0;
- swim_write(base, mode1, MOTON);
- swim_head(base, side);
- swim_write(base, mode0, side);
+ for (i = 0; i < 18; i++) { /* A track has at most 18 sectors */
+ if (i >= count)
+ break;
+ bits |= BIT(i);
+ }
local_irq_save(flags);
for (i = 0; i < 36; i++) {
- ret = swim_read_sector_header(base, &header);
- if (!ret && (header.sector == sector)) {
- /* found */
-
- ret = swim_read_sector_data(base, buffer);
+ if (bits == 0) /* All count sectors were read ok */
break;
+
+ if (swim_read_sector_header(base, &header) ||
+ swim_read(base, error) || header.track != track ||
+ header.side != side || header.size != 2)
+ continue;
+
+ if (header.sector >= start && header.sector < start + count) {
+ unsigned int offset = header.sector - start;
+ int ret;
+
+ if ((bits & BIT(offset)) == 0)
+ continue; /* This sector was already read ok */
+
+ ret = swim_read_sector_data(base, buffer + 512 * offset);
+ if (ret == 512 && swim_read(base, error) == 0)
+ bits &= ~BIT(offset);
}
}
local_irq_restore(flags);
- swim_write(base, mode0, MOTON);
-
- if ((header.side != side) || (header.track != track) ||
- (header.sector != sector))
- return 0;
-
- return ret;
+ return bits ? ffs(bits) - 1 : count; /* No. of contiguous ok sectors */
}
static blk_status_t floppy_read_sectors(struct floppy_state *fs,
- int req_sector, int sectors_nb,
- unsigned char *buffer)
+ unsigned int req_sector,
+ unsigned int sectors_nb,
+ unsigned char *buffer)
{
struct swim __iomem *base = fs->swd->base;
- int ret;
- int side, track, sector;
- int i, try;
-
+ unsigned int failures = 0;
swim_drive(base, fs->location);
- for (i = req_sector; i < req_sector + sectors_nb; i++) {
- int x;
- track = i / fs->secpercyl;
- x = i % fs->secpercyl;
- side = x / fs->secpertrack;
- sector = x % fs->secpertrack + 1;
-
- try = 5;
- do {
- ret = swim_read_sector(fs, side, track, sector,
- buffer);
- if (try-- == 0)
- return BLK_STS_IOERR;
- } while (ret != 512);
-
- buffer += ret;
+ swim_READY_timeout(base);
+
+ while (sectors_nb) {
+ unsigned int cyl, x, head, sector, n, ret;
+
+ cyl = req_sector / fs->secpercyl;
+ x = req_sector % fs->secpercyl;
+ head = (x >= fs->secpertrack) ? 1 : 0;
+ sector = x % fs->secpertrack;
+ n = min(sectors_nb, fs->secpertrack - sector);
+
+ swim_track(fs, cyl);
+ swim_head(base, head);
+
+ ret = swim_read_sector_range(fs, head, cyl, sector + 1, n, buffer);
+ if (ret != n)
+ ++failures;
+ if (failures >= 5)
+ return BLK_STS_IOERR;
+
+ buffer += 512 * ret;
+ sectors_nb -= ret;
+ req_sector += ret;
}
return 0;
@@ -527,12 +536,10 @@ static blk_status_t swim_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd)
{
struct floppy_state *fs = hctx->queue->queuedata;
- struct swim_priv *swd = fs->swd;
struct request *req = bd->rq;
blk_status_t err;
- if (!spin_trylock_irq(&swd->lock))
- return BLK_STS_DEV_RESOURCE;
+ mutex_lock(&swim_mutex);
blk_mq_start_request(req);
@@ -550,16 +557,16 @@ static blk_status_t swim_queue_rq(struct blk_mq_hw_ctx *hctx,
err = BLK_STS_OK;
out:
- spin_unlock_irq(&swd->lock);
+ mutex_unlock(&swim_mutex);
return err;
}
static struct floppy_struct floppy_type[4] = {
- { 0, 0, 0, 0, 0, 0x00, 0x00, 0x00, 0x00, NULL }, /* no testing */
+ { 0, 0, 0, 0, 0, 0x00, 0x00, 0x00, 0x00, NULL }, /* no testing */
{ 720, 9, 1, 80, 0, 0x2A, 0x02, 0xDF, 0x50, NULL }, /* 360KB SS 3.5"*/
- { 1440, 9, 2, 80, 0, 0x2A, 0x02, 0xDF, 0x50, NULL }, /* 720KB 3.5" */
- { 2880, 18, 2, 80, 0, 0x1B, 0x00, 0xCF, 0x6C, NULL }, /* 1.44MB 3.5" */
+ { 1440, 9, 2, 80, 0, 0x2A, 0x02, 0xDF, 0x50, NULL }, /* 720KB 3.5" */
+ { 2880, 18, 2, 80, 0, 0x1B, 0x00, 0xCF, 0x6C, NULL }, /* 1.44MB 3.5" */
};
static int get_floppy_geometry(struct floppy_state *fs, int type,
@@ -586,23 +593,16 @@ static void setup_medium(struct floppy_state *fs)
if (swim_readbit(base, DISK_IN)) {
struct floppy_struct *g;
+
fs->disk_in = 1;
fs->write_protected = swim_readbit(base, WRITE_PROT);
-
- if (swim_track00(base))
- printk(KERN_ERR
- "SWIM: cannot move floppy head to track 0\n");
-
- swim_track00(base);
-
fs->type = swim_readbit(base, TWOMEG_MEDIA) ?
- HD_MEDIA : DD_MEDIA;
+ HD_MEDIA : DD_MEDIA;
fs->head_number = swim_readbit(base, SINGLE_SIDED) ? 1 : 2;
get_floppy_geometry(fs, 0, &g);
fs->total_secs = g->size;
fs->secpercyl = g->head * g->sect;
fs->secpertrack = g->sect;
- fs->track = 0;
} else {
fs->disk_in = 0;
}
@@ -620,11 +620,9 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)
fs->ref_count = -1;
else
fs->ref_count++;
- swim_write(base, setup, S_IBM_DRIVE | S_FCLK_DIV2);
- udelay(10);
+
swim_drive(base, fs->location);
- swim_motor(base, ON);
- swim_action(base, SETMFM);
+
if (fs->ejected)
setup_medium(fs);
if (!fs->disk_in) {
@@ -632,6 +630,11 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)
goto out;
}
+ swim_motor(base, ON);
+ swim_action(base, SETMFM);
+ msleep(30);
+ swim_READY_timeout(base);
+
set_capacity(fs->disk, fs->total_secs);
if (mode & BLK_OPEN_NDELAY)
@@ -652,8 +655,10 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)
else if (fs->ref_count > 0)
--fs->ref_count;
- if (fs->ref_count == 0)
+ if (fs->ref_count == 0) {
swim_motor(base, OFF);
+ swim_drive(base, NO_DRIVE);
+ }
return err;
}
@@ -679,8 +684,11 @@ static void floppy_release(struct gendisk *disk)
else if (fs->ref_count > 0)
--fs->ref_count;
- if (fs->ref_count == 0)
+ if (fs->ref_count == 0) {
+ swim_drive(base, fs->location);
swim_motor(base, OFF);
+ swim_drive(base, NO_DRIVE);
+ }
mutex_unlock(&swim_mutex);
}
@@ -691,7 +699,7 @@ static int floppy_ioctl(struct block_device *bdev, blk_mode_t mode,
int err;
if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN))
- return -EPERM;
+ return -EPERM;
switch (cmd) {
case FDEJECT:
@@ -750,10 +758,9 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location)
struct floppy_state *fs = &swd->unit[swd->floppy_count];
struct swim __iomem *base = swd->base;
+ fs->swd = swd;
fs->location = location;
- swim_drive(base, location);
-
swim_motor(base, OFF);
fs->type = HD_MEDIA;
@@ -761,6 +768,7 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location)
fs->ref_count = 0;
fs->ejected = 1;
+ fs->track = 0;
swd->floppy_count++;
@@ -785,25 +793,43 @@ static void swim_cleanup_floppy_disk(struct floppy_state *fs)
blk_mq_free_tag_set(&fs->tag_set);
}
-static int swim_floppy_init(struct swim_priv *swd)
+static void swim_set_parameters(struct swim __iomem *base)
+{
+ unsigned int i;
+ static const u8 mem[] = { 0x18, 0x41, 0x2e, 0x2e, 0x18, 0x18, 0x1b, 0x1b,
+ 0x2f, 0x2f, 0x19, 0x19, 0x97, 0x1b, 0x57, 0x3b, };
+
+ swim_write(base, mode0, 0); /* reset parameter memory index */
+ for (i = 0; i < 16; ++i)
+ swim_write(base, parameter, mem[i]);
+}
+
+static int swim_floppy_init(struct platform_device *pdev)
{
+ struct swim_priv *swd = platform_get_drvdata(pdev);
+ unsigned int *data = pdev->dev.platform_data;
struct queue_limits lim = {
- .features = BLK_FEAT_ROTATIONAL,
+ .features = BLK_FEAT_ROTATIONAL,
};
int err;
int drive;
struct swim __iomem *base = swd->base;
+ swim_write(base, setup, S_IBM_DRIVE | (*data ? S_FCLK_DIV2 : 0));
+
+ swim_set_parameters(base);
+
/* scan floppy drives */
swim_drive(base, INTERNAL_DRIVE);
if (swim_readbit(base, DRIVE_PRESENT) &&
- !swim_readbit(base, ONEMEG_DRIVE))
+ !swim_readbit(base, ONEMEG_DRIVE) && !swim_track00(base))
swim_add_floppy(swd, INTERNAL_DRIVE);
swim_drive(base, EXTERNAL_DRIVE);
if (swim_readbit(base, DRIVE_PRESENT) &&
- !swim_readbit(base, ONEMEG_DRIVE))
+ !swim_readbit(base, ONEMEG_DRIVE) && !swim_track00(base))
swim_add_floppy(swd, EXTERNAL_DRIVE);
+ swim_drive(base, NO_DRIVE);
/* register floppy drives */
@@ -814,11 +840,9 @@ static int swim_floppy_init(struct swim_priv *swd)
return -EBUSY;
}
- spin_lock_init(&swd->lock);
-
for (drive = 0; drive < swd->floppy_count; drive++) {
err = blk_mq_alloc_sq_tag_set(&swd->unit[drive].tag_set,
- &swim_mq_ops, 2, 0);
+ &swim_mq_ops, 2, BLK_MQ_F_BLOCKING);
if (err)
goto exit_put_disks;
@@ -830,8 +854,6 @@ static int swim_floppy_init(struct swim_priv *swd)
err = PTR_ERR(swd->unit[drive].disk);
goto exit_put_disks;
}
-
- swd->unit[drive].swd = swd;
}
for (drive = 0; drive < swd->floppy_count; drive++) {
@@ -905,7 +927,7 @@ static int swim_probe(struct platform_device *dev)
swd->base = swim_base;
- ret = swim_floppy_init(swd);
+ ret = swim_floppy_init(dev);
if (ret)
goto out_kfree;
@@ -945,7 +967,7 @@ static void swim_remove(struct platform_device *dev)
static struct platform_driver swim_driver = {
.probe = swim_probe,
.remove = swim_remove,
- .driver = {
+ .driver = {
.name = CARDNAME,
},
};
diff --git a/drivers/block/swim_asm.S b/drivers/block/swim_asm.S
index 3d7a2d87595a57..65b4e4658e10c7 100644
--- a/drivers/block/swim_asm.S
+++ b/drivers/block/swim_asm.S
@@ -5,7 +5,7 @@
* needs assembly language because is very timing dependent
* this controller exists only on macintosh 680x0 based
*
- * Copyright (C) 2004,2008 Laurent Vivier <Laurent@lvivier.info>
+ * Copyright (C) 2004, 2008 Laurent Vivier <Laurent@lvivier.info>
*
* based on Alastair Bridgewater SWIM analysis, 2001
* based on netBSD IWM driver (c) 1997, 1998 Hauke Fath.
@@ -14,135 +14,138 @@
* 2008-11-05 (lv) - add get_swim_mode
*/
- .equ write_data, 0x0000
- .equ write_mark, 0x0200
- .equ write_CRC, 0x0400
- .equ write_parameter,0x0600
- .equ write_phase, 0x0800
- .equ write_setup, 0x0a00
- .equ write_mode0, 0x0c00
- .equ write_mode1, 0x0e00
- .equ read_data, 0x1000
- .equ read_mark, 0x1200
- .equ read_error, 0x1400
- .equ read_parameter, 0x1600
- .equ read_phase, 0x1800
- .equ read_setup, 0x1a00
- .equ read_status, 0x1c00
- .equ read_handshake, 0x1e00
-
- .equ o_side, 0
- .equ o_track, 1
- .equ o_sector, 2
- .equ o_size, 3
- .equ o_crc0, 4
- .equ o_crc1, 5
-
- .equ seek_time, 30000
- .equ max_retry, 40
- .equ sector_size, 512
+ .equ .Lwrite_data, 0x0000
+ .equ .Lwrite_mark, 0x0200
+ .equ .Lwrite_CRC, 0x0400
+ .equ .Lwrite_parameter, 0x0600
+ .equ .Lwrite_phase, 0x0800
+ .equ .Lwrite_setup, 0x0a00
+ .equ .Lwrite_mode0, 0x0c00
+ .equ .Lwrite_mode1, 0x0e00
+ .equ .Lread_data, 0x1000
+ .equ .Lread_mark, 0x1200
+ .equ .Lread_error, 0x1400
+ .equ .Lread_parameter, 0x1600
+ .equ .Lread_phase, 0x1800
+ .equ .Lread_setup, 0x1a00
+ .equ .Lread_status, 0x1c00
+ .equ .Lread_handshake, 0x1e00
+
+ .equ .Lo_side, 0
+ .equ .Lo_track, 1
+ .equ .Lo_sector, 2
+ .equ .Lo_size, 3
+ .equ .Lo_crc0, 4
+ .equ .Lo_crc1, 5
+
+ .equ .Lseek_time, 30000
+ .equ .Lmax_retry, 40
+ .equ .Lsector_size, 512
+
+ .equ .Lmr_clear_fifo, 0x01
+ .equ .Lmr_action, 0x08
+ .equ .Lmr_write_action, 0x18
+
+ .equ .Lhr_crc_error, 0x02
+ .equ .Lhr_fifo_2bytes, 0x40
+ .equ .Lhr_fifo_1byte, 0x80
.global swim_read_sector_header
swim_read_sector_header:
link %a6, #0
- moveml %d1-%d5/%a0-%a4,%sp@-
+ moveml %d1-%d5/%a0-%a5,%sp@-
movel %a6@(0x0c), %a4
- bsr mfm_read_addrmark
- moveml %sp@+, %d1-%d5/%a0-%a4
+ moveq #-1, %d0
+ bsr .Lmfm_read_addrmark
+ moveml %sp@+, %d1-%d5/%a0-%a5
unlk %a6
rts
-sector_address_mark:
+.Lsector_address_mark:
.byte 0xa1, 0xa1, 0xa1, 0xfe
-sector_data_mark:
+.Lsector_data_mark:
.byte 0xa1, 0xa1, 0xa1, 0xfb
-mfm_read_addrmark:
+.Lmfm_read_addrmark:
movel %a6@(0x08), %a3
- lea %a3@(read_handshake), %a2
- lea %a3@(read_mark), %a3
- moveq #-1, %d0
- movew #seek_time, %d2
-
-wait_header_init:
- tstb %a3@(read_error - read_mark)
- moveb #0x18, %a3@(write_mode0 - read_mark)
- moveb #0x01, %a3@(write_mode1 - read_mark)
- moveb #0x01, %a3@(write_mode0 - read_mark)
- tstb %a3@(read_error - read_mark)
- moveb #0x08, %a3@(write_mode1 - read_mark)
-
- lea sector_address_mark, %a0
+ lea %a3@(.Lread_handshake), %a2
+ lea %a3@(.Lread_data), %a5
+ lea %a3@(.Lread_mark), %a3
+ movew #.Lseek_time, %d2
+
+.Lwait_header_init:
+ moveb #.Lmr_write_action, %a3@(.Lwrite_mode0 - .Lread_mark)
+ moveb #.Lmr_clear_fifo, %a3@(.Lwrite_mode1 - .Lread_mark)
+ moveb #.Lmr_clear_fifo, %a3@(.Lwrite_mode0 - .Lread_mark)
+ tstb %a3@(.Lread_error - .Lread_mark)
+ moveb #.Lmr_action, %a3@(.Lwrite_mode1 - .Lread_mark)
+
+ lea .Lsector_address_mark, %a0
moveq #3, %d1
-wait_addr_mark_byte:
-
+.Lwait_addr_mark_byte:
tstb %a2@
- dbmi %d2, wait_addr_mark_byte
- bpl header_exit
+ dbmi %d2, .Lwait_addr_mark_byte
+ bpl .Lsignal_nonyb
moveb %a3@, %d3
cmpb %a0@+, %d3
- dbne %d1, wait_addr_mark_byte
- bne wait_header_init
-
- moveq #max_retry, %d2
+ dbne %d1, .Lwait_addr_mark_byte
+ bne .Lwait_header_init
-amark0: tstb %a2@
- dbmi %d2, amark0
- bpl signal_nonyb
-
- moveb %a3@, %a4@(o_track)
-
- moveq #max_retry, %d2
-
-amark1: tstb %a2@
- dbmi %d2, amark1
- bpl signal_nonyb
-
- moveb %a3@, %a4@(o_side)
-
- moveq #max_retry, %d2
+ moveq #.Lmax_retry, %d2
+.Lamark0:
+ tstb %a2@
+ dbmi %d2, .Lamark0
+ bpl .Lsignal_nonyb
-amark2: tstb %a2@
- dbmi %d2, amark2
- bpl signal_nonyb
+ moveb %a5@, %a4@(.Lo_track)
- moveb %a3@, %a4@(o_sector)
+ moveq #.Lmax_retry, %d2
+.Lamark1:
+ tstb %a2@
+ dbmi %d2, .Lamark1
+ bpl .Lsignal_nonyb
- moveq #max_retry, %d2
+ moveb %a5@, %a4@(.Lo_side)
-amark3: tstb %a2@
- dbmi %d2, amark3
- bpl signal_nonyb
+ moveq #.Lmax_retry, %d2
+.Lamark2:
+ tstb %a2@
+ dbmi %d2, .Lamark2
+ bpl .Lsignal_nonyb
- moveb %a3@, %a4@(o_size)
+ moveb %a5@, %a4@(.Lo_sector)
- moveq #max_retry, %d2
+ moveq #.Lmax_retry, %d2
+.Lamark3:
+ tstb %a2@
+ dbmi %d2, .Lamark3
+ bpl .Lsignal_nonyb
-crc0: tstb %a2@
- dbmi %d2, crc0
- bpl signal_nonyb
+ moveb %a5@, %a4@(.Lo_size)
- moveb %a3@, %a4@(o_crc0)
+ moveq #.Lmax_retry, %d2
+.Lcrc0:
+ tstb %a2@
+ dbmi %d2, .Lcrc0
+ bpl .Lsignal_nonyb
- moveq #max_retry, %d2
+ moveb %a5@, %a4@(.Lo_crc0)
-crc1: tstb %a2@
- dbmi %d2, crc1
- bpl signal_nonyb
+ moveq #.Lmax_retry, %d2
+.Lcrc1: moveb %a2@, %d5
+ dbmi %d2, .Lcrc1
+ bpl .Lsignal_nonyb
- moveb %a3@, %a4@(o_crc1)
+ moveb %a5@, %a4@(.Lo_crc1)
- tstb %a3@(read_error - read_mark)
+ andb #.Lhr_crc_error, %d5
+ bne .Lsignal_nonyb
-header_exit:
moveq #0, %d0
- moveb #0x18, %a3@(write_mode0 - read_mark)
- rts
-signal_nonyb:
- moveq #-1, %d0
- moveb #0x18, %a3@(write_mode0 - read_mark)
+.Lsignal_nonyb:
+ moveb #.Lmr_write_action, %a3@(.Lwrite_mode0 - .Lread_mark)
rts
.global swim_read_sector_data
@@ -150,94 +153,87 @@ swim_read_sector_data:
link %a6, #0
moveml %d1-%d5/%a0-%a5,%sp@-
movel %a6@(0x0c), %a4
- bsr mfm_read_data
+ moveq #-1, %d0
+ bsr .Lmfm_read_data
moveml %sp@+, %d1-%d5/%a0-%a5
unlk %a6
rts
-mfm_read_data:
+.Lmfm_read_data:
movel %a6@(0x08), %a3
- lea %a3@(read_handshake), %a2
- lea %a3@(read_data), %a5
- lea %a3@(read_mark), %a3
- movew #seek_time, %d2
-
-wait_data_init:
- tstb %a3@(read_error - read_mark)
- moveb #0x18, %a3@(write_mode0 - read_mark)
- moveb #0x01, %a3@(write_mode1 - read_mark)
- moveb #0x01, %a3@(write_mode0 - read_mark)
- tstb %a3@(read_error - read_mark)
- moveb #0x08, %a3@(write_mode1 - read_mark)
-
- lea sector_data_mark, %a0
+ lea %a3@(.Lread_handshake), %a2
+ lea %a3@(.Lread_data), %a5
+ lea %a3@(.Lread_mark), %a3
+ movew #.Lseek_time, %d2
+
+.Lwait_data_init:
+ moveb #.Lmr_write_action, %a3@(.Lwrite_mode0 - .Lread_mark)
+ moveb #.Lmr_clear_fifo, %a3@(.Lwrite_mode1 - .Lread_mark)
+ moveb #.Lmr_clear_fifo, %a3@(.Lwrite_mode0 - .Lread_mark)
+ tstb %a3@(.Lread_error - .Lread_mark)
+ moveb #.Lmr_action, %a3@(.Lwrite_mode1 - .Lread_mark)
+
+ lea .Lsector_data_mark, %a0
moveq #3, %d1
/* wait data address mark */
-wait_data_mark_byte:
-
+.Lwait_data_mark_byte:
tstb %a2@
- dbmi %d2, wait_data_mark_byte
- bpl data_exit
+ dbmi %d2, .Lwait_data_mark_byte
+ bpl .Ldata_exit
moveb %a3@, %d3
cmpb %a0@+, %d3
- dbne %d1, wait_data_mark_byte
- bne wait_data_init
+ dbne %d1, .Lwait_data_mark_byte
+ bne .Lwait_data_init
/* read data */
- tstb %a3@(read_error - read_mark)
-
- movel #sector_size-1, %d4 /* sector size */
-read_new_data:
- movew #max_retry, %d2
-read_data_loop:
+ movel #.Lsector_size - 1, %d4 /* sector size */
+.Lread_new_data:
+ movew #.Lmax_retry, %d2
+.Lread_data_loop:
moveb %a2@, %d5
- andb #0xc0, %d5
- dbne %d2, read_data_loop
- beq data_exit
+ andb #(.Lhr_fifo_2bytes + .Lhr_fifo_1byte), %d5
+ beq 1f
+ movew #.Lmax_retry, %d2
moveb %a5@, %a4@+
- andb #0x40, %d5
- dbne %d4, read_new_data
- beq exit_loop
+ dbra %d4, 1f
+ bra .Ldata_crc0
+1: andb #.Lhr_fifo_2bytes, %d5
+ dbne %d2, .Lread_data_loop
+ beq .Ldata_exit
moveb %a5@, %a4@+
- dbra %d4, read_new_data
-exit_loop:
+ dbra %d4, .Lread_new_data
/* read CRC */
- movew #max_retry, %d2
-data_crc0:
-
+ movew #.Lmax_retry, %d2
+.Ldata_crc0:
tstb %a2@
- dbmi %d2, data_crc0
- bpl data_exit
+ dbmi %d2, .Ldata_crc0
+ bpl .Ldata_exit
- moveb %a3@, %d5
+ moveb %a5@, %d2
- moveq #max_retry, %d2
-
-data_crc1:
-
- tstb %a2@
- dbmi %d2, data_crc1
- bpl data_exit
-
- moveb %a3@, %d5
+ moveq #.Lmax_retry, %d2
+.Ldata_crc1:
+ moveb %a2@, %d5
+ dbmi %d2, .Ldata_crc1
+ bpl .Ldata_exit
- tstb %a3@(read_error - read_mark)
+ moveb %a5@, %d2
- moveb #0x18, %a3@(write_mode0 - read_mark)
+ andb #.Lhr_crc_error, %d5
+ bne .Ldata_exit
/* return number of bytes read */
- movel #sector_size, %d0
+ movel #.Lsector_size, %d0
addw #1, %d4
subl %d4, %d0
- rts
-data_exit:
- moveb #0x18, %a3@(write_mode0 - read_mark)
- moveq #-1, %d0
+
+.Ldata_exit:
+ moveb #.Lmr_write_action, %a3@(.Lwrite_mode0 - .Lread_mark)
rts
|
| 3/2 | 2026/07/16 15:26 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 16652 output: 20 thoughts: 355 Thoughts: **Analyzing a SWIM Floppy Driver Patch for m68k Macs** Okay, so I've got this patch here that's touching `arch/m68k/mac/config.c`, `drivers/block/swim.c`, and `drivers/block/swim_asm.S`. Right off the bat, I see "SWIM" – Sander Wozniak Integrated Machine. That screams floppy controller driver for older m68k Macs. And this patch is definitely honing in on that. It looks like the primary focus is about properly configuring the "swim" device, specifically by passing a `data` parameter to `platform_device_register_resndata`. That `data` is likely keying off the Mac model to set `S_FCLK_DIV2`, which makes sense; the clock frequency varies across those old machines, and the driver needs to adjust accordingly. I see changes to `swim.c` that replace `schedule_timeout` with `poll_timeout_us` and `poll_timeout_us_atomic`. That’s a good sign; those polling primitives are usually a better fit for hardware interactions. Plus, there are some macro and constant tweaks, and it looks like a new timeout, `swim_READY_timeout`, has been added. There are changes to the `swim_read_sector_range` and `floppy_read_sectors` functions, so this is likely about improving read performance or reliability. The `swim_asm.S` change is interesting, too. Local labels and some logic updates in assembly? It suggests they're likely refining the low-level hardware interaction. Now, my mind goes to testing. Is this patch even testable in a virtualized environment? The `swim` driver is so specific to those older Macs. Can I emulate that? Hmm, QEMU… let me check. Ah, yes! QEMU has that `q800` machine, a Mac Quadra 800. And the Quadra 800 is one of the models that use the 32MHz FCLK, `MAC_MODEL_Q800`. Good, that's potentially testable. This driver is in `drivers/block/swim.c`. Now, let me quickly verify that `CONFIG_BLK_DEV_SWIM` is actually enabled in the build. I'll use my grepper tool for a quick check. |
| 4/2 | 2026/07/16 15:27 | tool | grepper |
0mArgs:{
"Expression": "BLK_DEV_SWIM"
}Results: {
"Output": "arch/m68k/configs/mac_defconfig=248=CONFIG_CONNECTOR=m\narch/m68k/configs/mac_defconfig:249:CONFIG_BLK_DEV_SWIM=m\narch/m68k/configs/mac_defconfig-250-CONFIG_ZRAM=m\n--\narch/m68k/configs/multi_defconfig=276=CONFIG_ATARI_FLOPPY=y\narch/m68k/configs/multi_defconfig:277:CONFIG_BLK_DEV_SWIM=m\narch/m68k/configs/multi_defconfig-278-CONFIG_AMIGA_Z2RAM=y\n--\ndrivers/block/Kconfig=61=config MAC_FLOPPY\n--\ndrivers/block/Kconfig-67-\ndrivers/block/Kconfig:68:config BLK_DEV_SWIM\ndrivers/block/Kconfig-69-\ttristate \"Support for SWIM Macintosh floppy\"\n--\ndrivers/block/Makefile=12=obj-$(CONFIG_MAC_FLOPPY)\t+= swim3.o\ndrivers/block/Makefile:13:obj-$(CONFIG_BLK_DEV_SWIM)\t+= swim_mod.o\ndrivers/block/Makefile-14-obj-$(CONFIG_BLK_DEV_FD)\t+= floppy.o\n"
} |
| 5/2 | 2026/07/16 15:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 17877 output: 34 thoughts: 35 Thoughts: Okay, let's see what's going on here. **Analyzing the BLK_DEV_SWIM Configuration** Right, so the system's configured with `BLK_DEV_SWIM`. My initial thought is, let's see what depends on that. I know Kconfig is the place to start, so I'll jump right into `drivers/block/Kconfig`. I'll need to figure out what other configurations are related to `BLK_DEV_SWIM`. Maybe it relies on specific hardware drivers or other block device configurations. Understanding the dependencies is key to understanding its overall impact on the system. I'll need to look for conditional dependencies or any prerequisites that are enforced. |
| 6/2 | 2026/07/16 15:27 | tool | grepper |
0mArgs:{
"Expression": "config BLK_DEV_SWIM",
"PathPrefix": "drivers/block/Kconfig"
}Results: {
"Output": "drivers/block/Kconfig=61=config MAC_FLOPPY\n--\ndrivers/block/Kconfig-67-\ndrivers/block/Kconfig:68:config BLK_DEV_SWIM\ndrivers/block/Kconfig-69-\ttristate \"Support for SWIM Macintosh floppy\"\n"
} |
| 7/2 | 2026/07/16 15:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18177 output: 33 thoughts: 18 Thoughts: Here's my take on the thought process, as requested: **Diving into `drivers/block/Kconfig`** Alright, I need to get a handle on how this block device configuration is structured. My immediate thought is to head straight into the source and see the actual Kconfig file. Let's start with `drivers/block/Kconfig`, and my instinct tells me to zoom in around line 68. Hopefully, that will give me a good jumping-off point to understand the broader dependencies and options available for configuring block devices. I expect to get a sense of the relevant configuration symbols and their associated help text right around there. This should quickly orient me to the core block device configuration variables. |
| 8/2 | 2026/07/16 15:27 | tool | read-file |
0mArgs:{
"File": "drivers/block/Kconfig",
"FirstLine": 60,
"LineCount": 20
}Results: {
"Contents": " 60:\t\n 61:\tconfig MAC_FLOPPY\n 62:\t\ttristate \"Support for PowerMac floppy\"\n 63:\t\tdepends on PPC_PMAC \u0026\u0026 !PPC_PMAC64\n 64:\t\thelp\n 65:\t\t If you have a SWIM-3 (Super Woz Integrated Machine 3; from Apple)\n 66:\t\t floppy controller, say Y here. Most commonly found in PowerMacs.\n 67:\t\n 68:\tconfig BLK_DEV_SWIM\n 69:\t\ttristate \"Support for SWIM Macintosh floppy\"\n 70:\t\tdepends on M68K \u0026\u0026 MAC \u0026\u0026 !HIGHMEM\n 71:\t\thelp\n 72:\t\t You should select this option if you want floppy support\n 73:\t\t and you don't have a II, IIfx, Q900, Q950 or AV series.\n 74:\t\n 75:\tconfig AMIGA_Z2RAM\n 76:\t\ttristate \"Amiga Zorro II ramdisk support\"\n 77:\t\tdepends on ZORRO\n 78:\t\thelp\n 79:\t\t This enables support for using Chip RAM and Zorro II RAM as a\n"
} |
| 9/2 | 2026/07/16 15:27 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18689 output: 252 thoughts: 2268 Thoughts: **SWIM Floppy Driver Analysis for Fuzzing** Okay, let's break this down. We have a patch touching the SWIM floppy driver, specifically for m68k Macs. The dependency is `M68K && MAC && !HIGHMEM`, making it architecture-specific. Crucially, QEMU supports a `q800` machine, which is a Mac Quadra 800. This is a solid indicator that this driver is *reachable* in a virtualized environment, which is excellent news for us. While syzkaller typically targets architectures like x86_64, ARM64, and RISC-V, it does have m68k support. It might not be *actively* fuzzed in every instance, but if it's reachable in QEMU, we can absolutely assume it can be targeted by syzkaller. Is the driver itself reachable? It appears to be a platform driver for "swim." Let's confirm that by checking `swim_probe`. Yep, it's a platform driver, specifically for "swim," and it's initialized during `mac_platform_init` in `arch/m68k/mac/config.c`. This means it *will* be probed at boot if the hardware is present. The driver is exposing a block device, and that's exactly what we want. The block device operations are handled by `swim_mq_ops`, which internally uses `swim_queue_rq`. There are also ioctls, handled by `floppy_ioctl`. Now, let's look at the functions that have been modified. This list is a goldmine: `swim_floppy_init`, `swim_probe`, `swim_add_floppy`, `floppy_ioctl`, `floppy_release`, `floppy_open`, `setup_medium`, `get_floppy_geometry`, `swim_queue_rq`, `floppy_read_sectors`, `swim_read_sector_range`, `floppy_eject`, `swim_track`, `swim_seek`, `swim_track00`, `swim_step`, `swim_head`, `swim_eject`, `swim_motor`, `swim_drive`, `swim_readbit`, `swim_action`, `swim_select`, `get_swim_mode`, `set_swim_mode`, and even `swim_read_sector_header` and `swim_read_sector_data` (in assembly). So, is this driver worth fuzzing? Absolutely! It's a floppy driver for m68k Macs. It's functional core logic. Given QEMU's `q800` machine, which has a SWIM floppy controller, we can target it. Therefore, `WorthFuzzing=true`. Now, let's identify the *FocusSymbols*. We need to pinpoint the functions that are critical entry points. These are: `floppy_ioctl`, `floppy_open`, `floppy_release`, `swim_queue_rq`, `floppy_read_sectors`, `swim_read_sector_range`, `floppy_eject`, `swim_add_floppy`, `swim_floppy_init`, and `swim_probe`. `swim_queue_rq` is crucial; it's the block device queue request function. `floppy_ioctl` handles ioctls. `floppy_open` and `floppy_release` are the open/release handlers. `swim_probe` is the probe function. We also have a lot of other functions that are worth knowing about: `floppy_ioctl`, `swim_queue_rq`, `floppy_read_sectors`, `swim_read_sector_range`, `floppy_eject`, `swim_track`, `swim_seek`, `swim_track00`, `swim_step`, `swim_motor`, `swim_drive`, `swim_action`, `swim_select`, `swim_read_sector_header`, and `swim_read_sector_data`. However, `swim_read_sector_header` and `swim_read_sector_data` are in assembly, so they might not be instrumented by KASAN/KCOV, which is crucial for fuzzing. Let's focus on the C functions. So, let's refine this to make it a bit more focused: `floppy_ioctl`, `swim_queue_rq`, `floppy_read_sectors`, `swim_read_sector_range`, `floppy_eject`, `swim_track`, `swim_seek`, `swim_track00`, `swim_step`, `swim_motor`, `swim_drive`, `swim_action`, `swim |
| 10/2 | 2026/07/16 15:27 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BLK_DEV_SWIM"
],
"FocusSymbols": [
"swim_queue_rq",
"floppy_read_sectors",
"swim_read_sector_range",
"floppy_ioctl",
"floppy_open",
"floppy_release",
"swim_probe",
"swim_floppy_init",
"swim_add_floppy",
"setup_medium",
"floppy_eject",
"swim_track",
"swim_seek",
"swim_track00",
"swim_step",
"swim_motor",
"swim_drive",
"swim_action",
"swim_select"
],
"Reasoning": "The patch makes functional changes to the SWIM floppy controller driver for m68k Macintosh systems, including changes to device registration, initialization, reading sectors, and handling hardware state. The driver is reachable in virtualized environments like QEMU (using the `q800` machine). Fuzzing should focus on the block device operations, ioctls, and hardware interaction functions.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BLK_DEV_SWIM"
],
"FocusSymbols": [
"swim_queue_rq",
"floppy_read_sectors",
"swim_read_sector_range",
"floppy_ioctl",
"floppy_open",
"floppy_release",
"swim_probe",
"swim_floppy_init",
"swim_add_floppy",
"setup_medium",
"floppy_eject",
"swim_track",
"swim_seek",
"swim_track00",
"swim_step",
"swim_motor",
"swim_drive",
"swim_action",
"swim_select"
],
"Reasoning": "The patch makes functional changes to the SWIM floppy controller driver for m68k Macintosh systems, including changes to device registration, initialization, reading sectors, and handling hardware state. The driver is reachable in virtualized environments like QEMU (using the `q800` machine). Fuzzing should focus on the block device operations, ioctls, and hardware interaction functions.",
"WorthFuzzing": true
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|