blob: 3d217f1d7440a359806d5f79590a984eecb350d9 [file] [log] [blame]
Thomas Gleixner09c434b2019-05-19 13:08:20 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * drivers/block/ataflop.c
4 *
5 * Copyright (C) 1993 Greg Harp
6 * Atari Support by Bjoern Brauel, Roman Hodek
7 *
8 * Big cleanup Sep 11..14 1994 Roman Hodek:
9 * - Driver now works interrupt driven
10 * - Support for two drives; should work, but I cannot test that :-(
11 * - Reading is done in whole tracks and buffered to speed up things
12 * - Disk change detection and drive deselecting after motor-off
13 * similar to TOS
14 * - Autodetection of disk format (DD/HD); untested yet, because I
15 * don't have an HD drive :-(
16 *
17 * Fixes Nov 13 1994 Martin Schaller:
18 * - Autodetection works now
19 * - Support for 5 1/4'' disks
20 * - Removed drive type (unknown on atari)
21 * - Do seeks with 8 Mhz
22 *
23 * Changes by Andreas Schwab:
24 * - After errors in multiple read mode try again reading single sectors
25 * (Feb 1995):
26 * - Clean up error handling
27 * - Set blk_size for proper size checking
28 * - Initialize track register when testing presence of floppy
29 * - Implement some ioctl's
30 *
31 * Changes by Torsten Lang:
32 * - When probing the floppies we should add the FDCCMDADD_H flag since
33 * the FDC will otherwise wait forever when no disk is inserted...
34 *
35 * ++ Freddi Aschwanden (fa) 20.9.95 fixes for medusa:
36 * - MFPDELAY() after each FDC access -> atari
37 * - more/other disk formats
38 * - DMA to the block buffer directly if we have a 32bit DMA
39 * - for medusa, the step rate is always 3ms
40 * - on medusa, use only cache_push()
41 * Roman:
42 * - Make disk format numbering independent from minors
43 * - Let user set max. supported drive type (speeds up format
44 * detection, saves buffer space)
45 *
46 * Roman 10/15/95:
47 * - implement some more ioctls
48 * - disk formatting
49 *
50 * Andreas 95/12/12:
51 * - increase gap size at start of track for HD/ED disks
52 *
53 * Michael (MSch) 11/07/96:
54 * - implemented FDSETPRM and FDDEFPRM ioctl
55 *
56 * Andreas (97/03/19):
57 * - implemented missing BLK* ioctls
58 *
59 * Things left to do:
60 * - Formatting
61 * - Maybe a better strategy for disk change detection (does anyone
62 * know one?)
63 */
64
65#include <linux/module.h>
66
67#include <linux/fd.h>
68#include <linux/delay.h>
69#include <linux/init.h>
Omar Sandoval6ec39382018-10-15 09:18:24 -060070#include <linux/blk-mq.h>
Christoph Hellwigb81e0c22021-09-20 14:33:25 +020071#include <linux/major.h>
Arnd Bergmann2a48fc02010-06-02 14:28:52 +020072#include <linux/mutex.h>
Arnd Bergmann7b8a3d22014-02-26 12:01:41 +010073#include <linux/completion.h>
74#include <linux/wait.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include <asm/atariints.h>
77#include <asm/atari_stdma.h>
78#include <asm/atari_stram.h>
79
80#define FD_MAX_UNITS 2
81
82#undef DEBUG
83
Arnd Bergmann2a48fc02010-06-02 14:28:52 +020084static DEFINE_MUTEX(ataflop_mutex);
Tejun Heoa336ca62009-05-08 11:54:03 +090085static struct request *fd_request;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Omar Sandoval3e6b8c3c2018-10-11 12:20:48 -070087/*
88 * WD1772 stuff
89 */
90
91/* register codes */
92
93#define FDCSELREG_STP (0x80) /* command/status register */
94#define FDCSELREG_TRA (0x82) /* track register */
95#define FDCSELREG_SEC (0x84) /* sector register */
96#define FDCSELREG_DTA (0x86) /* data register */
97
98/* register names for FDC_READ/WRITE macros */
99
100#define FDCREG_CMD 0
101#define FDCREG_STATUS 0
102#define FDCREG_TRACK 2
103#define FDCREG_SECTOR 4
104#define FDCREG_DATA 6
105
106/* command opcodes */
107
108#define FDCCMD_RESTORE (0x00) /* - */
109#define FDCCMD_SEEK (0x10) /* | */
110#define FDCCMD_STEP (0x20) /* | TYP 1 Commands */
111#define FDCCMD_STIN (0x40) /* | */
112#define FDCCMD_STOT (0x60) /* - */
113#define FDCCMD_RDSEC (0x80) /* - TYP 2 Commands */
114#define FDCCMD_WRSEC (0xa0) /* - " */
115#define FDCCMD_RDADR (0xc0) /* - */
116#define FDCCMD_RDTRA (0xe0) /* | TYP 3 Commands */
117#define FDCCMD_WRTRA (0xf0) /* - */
118#define FDCCMD_FORCI (0xd0) /* - TYP 4 Command */
119
120/* command modifier bits */
121
122#define FDCCMDADD_SR6 (0x00) /* step rate settings */
123#define FDCCMDADD_SR12 (0x01)
124#define FDCCMDADD_SR2 (0x02)
125#define FDCCMDADD_SR3 (0x03)
126#define FDCCMDADD_V (0x04) /* verify */
127#define FDCCMDADD_H (0x08) /* wait for spin-up */
128#define FDCCMDADD_U (0x10) /* update track register */
129#define FDCCMDADD_M (0x10) /* multiple sector access */
130#define FDCCMDADD_E (0x04) /* head settling flag */
131#define FDCCMDADD_P (0x02) /* precompensation off */
132#define FDCCMDADD_A0 (0x01) /* DAM flag */
133
134/* status register bits */
135
136#define FDCSTAT_MOTORON (0x80) /* motor on */
137#define FDCSTAT_WPROT (0x40) /* write protected (FDCCMD_WR*) */
138#define FDCSTAT_SPINUP (0x20) /* motor speed stable (Type I) */
139#define FDCSTAT_DELDAM (0x20) /* sector has deleted DAM (Type II+III) */
140#define FDCSTAT_RECNF (0x10) /* record not found */
141#define FDCSTAT_CRC (0x08) /* CRC error */
142#define FDCSTAT_TR00 (0x04) /* Track 00 flag (Type I) */
143#define FDCSTAT_LOST (0x04) /* Lost Data (Type II+III) */
144#define FDCSTAT_IDX (0x02) /* Index status (Type I) */
145#define FDCSTAT_DRQ (0x02) /* DRQ status (Type II+III) */
146#define FDCSTAT_BUSY (0x01) /* FDC is busy */
147
148
149/* PSG Port A Bit Nr 0 .. Side Sel .. 0 -> Side 1 1 -> Side 2 */
150#define DSKSIDE (0x01)
151
152#define DSKDRVNONE (0x06)
153#define DSKDRV0 (0x02)
154#define DSKDRV1 (0x04)
155
156/* step rates */
157#define FDCSTEP_6 0x00
158#define FDCSTEP_12 0x01
159#define FDCSTEP_2 0x02
160#define FDCSTEP_3 0x03
161
162struct atari_format_descr {
163 int track; /* to be formatted */
164 int head; /* "" "" */
165 int sect_offset; /* offset of first sector */
166};
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/* Disk types: DD, HD, ED */
169static struct atari_disk_type {
170 const char *name;
171 unsigned spt; /* sectors per track */
172 unsigned blocks; /* total number of blocks */
173 unsigned fdc_speed; /* fdc_speed setting */
174 unsigned stretch; /* track doubling ? */
Geert Uytterhoeven5ceadd22008-02-06 01:38:09 -0800175} atari_disk_type[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 { "d360", 9, 720, 0, 0}, /* 0: 360kB diskette */
177 { "D360", 9, 720, 0, 1}, /* 1: 360kb in 720k or 1.2MB drive */
178 { "D720", 9,1440, 0, 0}, /* 2: 720kb in 720k or 1.2MB drive */
179 { "D820", 10,1640, 0, 0}, /* 3: DD disk with 82 tracks/10 sectors */
180/* formats above are probed for type DD */
181#define MAX_TYPE_DD 3
182 { "h1200",15,2400, 3, 0}, /* 4: 1.2MB diskette */
183 { "H1440",18,2880, 3, 0}, /* 5: 1.4 MB diskette (HD) */
184 { "H1640",20,3280, 3, 0}, /* 6: 1.64MB diskette (fat HD) 82 tr 20 sec */
185/* formats above are probed for types DD and HD */
186#define MAX_TYPE_HD 6
187 { "E2880",36,5760, 3, 0}, /* 7: 2.8 MB diskette (ED) */
188 { "E3280",40,6560, 3, 0}, /* 8: 3.2 MB diskette (fat ED) 82 tr 40 sec */
189/* formats above are probed for types DD, HD and ED */
190#define MAX_TYPE_ED 8
191/* types below are never autoprobed */
192 { "H1680",21,3360, 3, 0}, /* 9: 1.68MB diskette (fat HD) 80 tr 21 sec */
193 { "h410",10,820, 0, 1}, /* 10: 410k diskette 41 tr 10 sec, stretch */
194 { "h1476",18,2952, 3, 0}, /* 11: 1.48MB diskette 82 tr 18 sec */
195 { "H1722",21,3444, 3, 0}, /* 12: 1.72MB diskette 82 tr 21 sec */
196 { "h420",10,840, 0, 1}, /* 13: 420k diskette 42 tr 10 sec, stretch */
197 { "H830",10,1660, 0, 0}, /* 14: 820k diskette 83 tr 10 sec */
198 { "h1494",18,2952, 3, 0}, /* 15: 1.49MB diskette 83 tr 18 sec */
199 { "H1743",21,3486, 3, 0}, /* 16: 1.74MB diskette 83 tr 21 sec */
200 { "h880",11,1760, 0, 0}, /* 17: 880k diskette 80 tr 11 sec */
201 { "D1040",13,2080, 0, 0}, /* 18: 1.04MB diskette 80 tr 13 sec */
202 { "D1120",14,2240, 0, 0}, /* 19: 1.12MB diskette 80 tr 14 sec */
203 { "h1600",20,3200, 3, 0}, /* 20: 1.60MB diskette 80 tr 20 sec */
204 { "H1760",22,3520, 3, 0}, /* 21: 1.76MB diskette 80 tr 22 sec */
205 { "H1920",24,3840, 3, 0}, /* 22: 1.92MB diskette 80 tr 24 sec */
206 { "E3200",40,6400, 3, 0}, /* 23: 3.2MB diskette 80 tr 40 sec */
207 { "E3520",44,7040, 3, 0}, /* 24: 3.52MB diskette 80 tr 44 sec */
208 { "E3840",48,7680, 3, 0}, /* 25: 3.84MB diskette 80 tr 48 sec */
209 { "H1840",23,3680, 3, 0}, /* 26: 1.84MB diskette 80 tr 23 sec */
210 { "D800",10,1600, 0, 0}, /* 27: 800k diskette 80 tr 10 sec */
211};
212
213static int StartDiskType[] = {
214 MAX_TYPE_DD,
215 MAX_TYPE_HD,
216 MAX_TYPE_ED
217};
218
219#define TYPE_DD 0
220#define TYPE_HD 1
221#define TYPE_ED 2
222
223static int DriveType = TYPE_HD;
224
225static DEFINE_SPINLOCK(ataflop_lock);
226
227/* Array for translating minors into disk formats */
228static struct {
229 int index;
230 unsigned drive_types;
231} minor2disktype[] = {
232 { 0, TYPE_DD }, /* 1: d360 */
233 { 4, TYPE_HD }, /* 2: h1200 */
234 { 1, TYPE_DD }, /* 3: D360 */
235 { 2, TYPE_DD }, /* 4: D720 */
236 { 1, TYPE_DD }, /* 5: h360 = D360 */
237 { 2, TYPE_DD }, /* 6: h720 = D720 */
238 { 5, TYPE_HD }, /* 7: H1440 */
239 { 7, TYPE_ED }, /* 8: E2880 */
240/* some PC formats :-) */
241 { 8, TYPE_ED }, /* 9: E3280 <- was "CompaQ" == E2880 for PC */
242 { 5, TYPE_HD }, /* 10: h1440 = H1440 */
243 { 9, TYPE_HD }, /* 11: H1680 */
244 { 10, TYPE_DD }, /* 12: h410 */
245 { 3, TYPE_DD }, /* 13: H820 <- == D820, 82x10 */
246 { 11, TYPE_HD }, /* 14: h1476 */
247 { 12, TYPE_HD }, /* 15: H1722 */
248 { 13, TYPE_DD }, /* 16: h420 */
249 { 14, TYPE_DD }, /* 17: H830 */
250 { 15, TYPE_HD }, /* 18: h1494 */
251 { 16, TYPE_HD }, /* 19: H1743 */
252 { 17, TYPE_DD }, /* 20: h880 */
253 { 18, TYPE_DD }, /* 21: D1040 */
254 { 19, TYPE_DD }, /* 22: D1120 */
255 { 20, TYPE_HD }, /* 23: h1600 */
256 { 21, TYPE_HD }, /* 24: H1760 */
257 { 22, TYPE_HD }, /* 25: H1920 */
258 { 23, TYPE_ED }, /* 26: E3200 */
259 { 24, TYPE_ED }, /* 27: E3520 */
260 { 25, TYPE_ED }, /* 28: E3840 */
261 { 26, TYPE_HD }, /* 29: H1840 */
262 { 27, TYPE_DD }, /* 30: D800 */
263 { 6, TYPE_HD }, /* 31: H1640 <- was H1600 == h1600 for PC */
264};
265
Tobias Klauser945f3902006-01-08 01:05:11 -0800266#define NUM_DISK_MINORS ARRAY_SIZE(minor2disktype)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268/*
269 * Maximum disk size (in kilobytes). This default is used whenever the
270 * current disk size is unknown.
271 */
272#define MAX_DISK_SIZE 3280
273
274/*
275 * MSch: User-provided type information. 'drive' points to
276 * the respective entry of this array. Set by FDSETPRM ioctls.
277 */
278static struct atari_disk_type user_params[FD_MAX_UNITS];
279
280/*
281 * User-provided permanent type information. 'drive' points to
282 * the respective entry of this array. Set by FDDEFPRM ioctls,
283 * restored upon disk change by floppy_revalidate() if valid (as seen by
284 * default_params[].blocks > 0 - a bit in unit[].flags might be used for this?)
285 */
286static struct atari_disk_type default_params[FD_MAX_UNITS];
287
288/* current info on each unit */
289static struct atari_floppy_struct {
290 int connected; /* !=0 : drive is connected */
291 int autoprobe; /* !=0 : do autoprobe */
292
293 struct atari_disk_type *disktype; /* current type of disk */
294
295 int track; /* current head position or -1 if
296 unknown */
297 unsigned int steprate; /* steprate setting */
298 unsigned int wpstat; /* current state of WP signal (for
299 disk change detection) */
300 int flags; /* flags */
Christoph Hellwigbf9c0532020-10-29 15:58:38 +0100301 struct gendisk *disk[NUM_DISK_MINORS];
Luis Chamberlain573effb2021-09-27 15:03:00 -0700302 bool registered[NUM_DISK_MINORS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 int ref;
304 int type;
Omar Sandoval6ec39382018-10-15 09:18:24 -0600305 struct blk_mq_tag_set tag_set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306} unit[FD_MAX_UNITS];
307
308#define UD unit[drive]
309#define UDT unit[drive].disktype
310#define SUD unit[SelectedDrive]
311#define SUDT unit[SelectedDrive].disktype
312
313
314#define FDC_READ(reg) ({ \
315 /* unsigned long __flags; */ \
316 unsigned short __val; \
317 /* local_irq_save(__flags); */ \
318 dma_wd.dma_mode_status = 0x80 | (reg); \
319 udelay(25); \
320 __val = dma_wd.fdc_acces_seccount; \
321 MFPDELAY(); \
322 /* local_irq_restore(__flags); */ \
323 __val & 0xff; \
324})
325
326#define FDC_WRITE(reg,val) \
327 do { \
328 /* unsigned long __flags; */ \
329 /* local_irq_save(__flags); */ \
330 dma_wd.dma_mode_status = 0x80 | (reg); \
331 udelay(25); \
332 dma_wd.fdc_acces_seccount = (val); \
333 MFPDELAY(); \
334 /* local_irq_restore(__flags); */ \
335 } while(0)
336
337
338/* Buffering variables:
339 * First, there is a DMA buffer in ST-RAM that is used for floppy DMA
340 * operations. Second, a track buffer is used to cache a whole track
341 * of the disk to save read operations. These are two separate buffers
342 * because that allows write operations without clearing the track buffer.
343 */
344
345static int MaxSectors[] = {
346 11, 22, 44
347};
348static int BufferSize[] = {
349 15*512, 30*512, 60*512
350};
351
352#define BUFFER_SIZE (BufferSize[DriveType])
353
354unsigned char *DMABuffer; /* buffer for writes */
355static unsigned long PhysDMABuffer; /* physical address */
356
357static int UseTrackbuffer = -1; /* Do track buffering? */
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800358module_param(UseTrackbuffer, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360unsigned char *TrackBuffer; /* buffer for reads */
361static unsigned long PhysTrackBuffer; /* physical address */
362static int BufferDrive, BufferSide, BufferTrack;
363static int read_track; /* non-zero if we are reading whole tracks */
364
365#define SECTOR_BUFFER(sec) (TrackBuffer + ((sec)-1)*512)
366#define IS_BUFFERED(drive,side,track) \
367 (BufferDrive == (drive) && BufferSide == (side) && BufferTrack == (track))
368
369/*
370 * These are global variables, as that's the easiest way to give
371 * information to interrupts. They are the data used for the current
372 * request.
373 */
374static int SelectedDrive = 0;
375static int ReqCmd, ReqBlock;
376static int ReqSide, ReqTrack, ReqSector, ReqCnt;
377static int HeadSettleFlag = 0;
378static unsigned char *ReqData, *ReqBuffer;
379static int MotorOn = 0, MotorOffTrys;
380static int IsFormatting = 0, FormatError;
381
382static int UserSteprate[FD_MAX_UNITS] = { -1, -1 };
Rusty Russell8d3b33f2006-03-25 03:07:05 -0800383module_param_array(UserSteprate, int, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Arnd Bergmann7b8a3d22014-02-26 12:01:41 +0100385static DECLARE_COMPLETION(format_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387static unsigned long changed_floppies = 0xff, fake_change = 0;
388#define CHECK_CHANGE_DELAY HZ/2
389
390#define FD_MOTOR_OFF_DELAY (3*HZ)
391#define FD_MOTOR_OFF_MAXTRY (10*20)
392
393#define FLOPPY_TIMEOUT (6*HZ)
394#define RECALIBRATE_ERRORS 4 /* After this many errors the drive
395 * will be recalibrated. */
396#define MAX_ERRORS 8 /* After this many errors the driver
397 * will give up. */
398
399
400/*
401 * The driver is trying to determine the correct media format
402 * while Probing is set. fd_rwsec_done() clears it after a
403 * successful access.
404 */
405static int Probing = 0;
406
407/* This flag is set when a dummy seek is necessary to make the WP
408 * status bit accessible.
409 */
410static int NeedSeek = 0;
411
412
413#ifdef DEBUG
414#define DPRINT(a) printk a
415#else
416#define DPRINT(a)
417#endif
418
419/***************************** Prototypes *****************************/
420
421static void fd_select_side( int side );
422static void fd_select_drive( int drive );
423static void fd_deselect( void );
Kees Cook24ed9602017-08-28 11:28:21 -0700424static void fd_motor_off_timer(struct timer_list *unused);
425static void check_change(struct timer_list *unused);
David Howells7d12e782006-10-05 14:55:46 +0100426static irqreturn_t floppy_irq (int irq, void *dummy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427static void fd_error( void );
428static int do_format(int drive, int type, struct atari_format_descr *desc);
429static void do_fd_action( int drive );
430static void fd_calibrate( void );
431static void fd_calibrate_done( int status );
432static void fd_seek( void );
433static void fd_seek_done( int status );
434static void fd_rwsec( void );
Kees Cook24ed9602017-08-28 11:28:21 -0700435static void fd_readtrack_check(struct timer_list *unused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436static void fd_rwsec_done( int status );
437static void fd_rwsec_done1(int status);
438static void fd_writetrack( void );
439static void fd_writetrack_done( int status );
Kees Cook24ed9602017-08-28 11:28:21 -0700440static void fd_times_out(struct timer_list *unused);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441static void finish_fdc( void );
442static void finish_fdc_done( int dummy );
443static void setup_req_params( int drive );
Arnd Bergmann8a6cfeb2010-07-08 10:18:46 +0200444static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 cmd, unsigned long param);
446static void fd_probe( int drive );
447static int fd_test_drive_present( int drive );
448static void config_types( void );
Al Viro60ad2342008-03-02 09:23:54 -0500449static int floppy_open(struct block_device *bdev, fmode_t mode);
Al Virodb2a1442013-05-05 21:52:57 -0400450static void floppy_release(struct gendisk *disk, fmode_t mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452/************************* End of Prototypes **************************/
453
Kees Cook1d27e3e2017-10-04 16:27:04 -0700454static DEFINE_TIMER(motor_off_timer, fd_motor_off_timer);
455static DEFINE_TIMER(readtrack_timer, fd_readtrack_check);
456static DEFINE_TIMER(timeout_timer, fd_times_out);
457static DEFINE_TIMER(fd_timer, check_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Christoph Hellwig2a842ac2017-06-03 09:38:04 +0200459static void fd_end_request_cur(blk_status_t err)
Tejun Heoa336ca62009-05-08 11:54:03 +0900460{
Omar Sandoval6ec39382018-10-15 09:18:24 -0600461 if (!blk_update_request(fd_request, err,
462 blk_rq_cur_bytes(fd_request))) {
463 __blk_mq_end_request(fd_request, err);
Tejun Heoa336ca62009-05-08 11:54:03 +0900464 fd_request = NULL;
Omar Sandoval6ec39382018-10-15 09:18:24 -0600465 }
Tejun Heoa336ca62009-05-08 11:54:03 +0900466}
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468static inline void start_motor_off_timer(void)
469{
470 mod_timer(&motor_off_timer, jiffies + FD_MOTOR_OFF_DELAY);
471 MotorOffTrys = 0;
472}
473
474static inline void start_check_change_timer( void )
475{
476 mod_timer(&fd_timer, jiffies + CHECK_CHANGE_DELAY);
477}
478
479static inline void start_timeout(void)
480{
481 mod_timer(&timeout_timer, jiffies + FLOPPY_TIMEOUT);
482}
483
484static inline void stop_timeout(void)
485{
486 del_timer(&timeout_timer);
487}
488
489/* Select the side to use. */
490
491static void fd_select_side( int side )
492{
493 unsigned long flags;
494
495 /* protect against various other ints mucking around with the PSG */
496 local_irq_save(flags);
497
498 sound_ym.rd_data_reg_sel = 14; /* Select PSG Port A */
499 sound_ym.wd_data = (side == 0) ? sound_ym.rd_data_reg_sel | 0x01 :
500 sound_ym.rd_data_reg_sel & 0xfe;
501
502 local_irq_restore(flags);
503}
504
505
506/* Select a drive, update the FDC's track register and set the correct
507 * clock speed for this disk's type.
508 */
509
510static void fd_select_drive( int drive )
511{
512 unsigned long flags;
513 unsigned char tmp;
514
515 if (drive == SelectedDrive)
516 return;
517
518 /* protect against various other ints mucking around with the PSG */
519 local_irq_save(flags);
520 sound_ym.rd_data_reg_sel = 14; /* Select PSG Port A */
521 tmp = sound_ym.rd_data_reg_sel;
522 sound_ym.wd_data = (tmp | DSKDRVNONE) & ~(drive == 0 ? DSKDRV0 : DSKDRV1);
523 atari_dont_touch_floppy_select = 1;
524 local_irq_restore(flags);
525
526 /* restore track register to saved value */
527 FDC_WRITE( FDCREG_TRACK, UD.track );
528 udelay(25);
529
530 /* select 8/16 MHz */
531 if (UDT)
532 if (ATARIHW_PRESENT(FDCSPEED))
533 dma_wd.fdc_speed = UDT->fdc_speed;
534
535 SelectedDrive = drive;
536}
537
538
539/* Deselect both drives. */
540
541static void fd_deselect( void )
542{
543 unsigned long flags;
544
545 /* protect against various other ints mucking around with the PSG */
546 local_irq_save(flags);
547 atari_dont_touch_floppy_select = 0;
548 sound_ym.rd_data_reg_sel=14; /* Select PSG Port A */
549 sound_ym.wd_data = (sound_ym.rd_data_reg_sel |
550 (MACH_IS_FALCON ? 3 : 7)); /* no drives selected */
551 /* On Falcon, the drive B select line is used on the printer port, so
552 * leave it alone... */
553 SelectedDrive = -1;
554 local_irq_restore(flags);
555}
556
557
558/* This timer function deselects the drives when the FDC switched the
559 * motor off. The deselection cannot happen earlier because the FDC
560 * counts the index signals, which arrive only if one drive is selected.
561 */
562
Kees Cook24ed9602017-08-28 11:28:21 -0700563static void fd_motor_off_timer(struct timer_list *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
565 unsigned char status;
566
567 if (SelectedDrive < 0)
568 /* no drive selected, needn't deselect anyone */
569 return;
570
571 if (stdma_islocked())
572 goto retry;
573
574 status = FDC_READ( FDCREG_STATUS );
575
576 if (!(status & 0x80)) {
577 /* motor already turned off by FDC -> deselect drives */
578 MotorOn = 0;
579 fd_deselect();
580 return;
581 }
582 /* not yet off, try again */
583
584 retry:
585 /* Test again later; if tested too often, it seems there is no disk
586 * in the drive and the FDC will leave the motor on forever (or,
587 * at least until a disk is inserted). So we'll test only twice
588 * per second from then on...
589 */
590 mod_timer(&motor_off_timer,
591 jiffies + (MotorOffTrys++ < FD_MOTOR_OFF_MAXTRY ? HZ/20 : HZ/2));
592}
593
594
595/* This function is repeatedly called to detect disk changes (as good
596 * as possible) and keep track of the current state of the write protection.
597 */
598
Kees Cook24ed9602017-08-28 11:28:21 -0700599static void check_change(struct timer_list *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
601 static int drive = 0;
602
603 unsigned long flags;
604 unsigned char old_porta;
605 int stat;
606
607 if (++drive > 1 || !UD.connected)
608 drive = 0;
609
610 /* protect against various other ints mucking around with the PSG */
611 local_irq_save(flags);
612
613 if (!stdma_islocked()) {
614 sound_ym.rd_data_reg_sel = 14;
615 old_porta = sound_ym.rd_data_reg_sel;
616 sound_ym.wd_data = (old_porta | DSKDRVNONE) &
617 ~(drive == 0 ? DSKDRV0 : DSKDRV1);
618 stat = !!(FDC_READ( FDCREG_STATUS ) & FDCSTAT_WPROT);
619 sound_ym.wd_data = old_porta;
620
621 if (stat != UD.wpstat) {
622 DPRINT(( "wpstat[%d] = %d\n", drive, stat ));
623 UD.wpstat = stat;
624 set_bit (drive, &changed_floppies);
625 }
626 }
627 local_irq_restore(flags);
628
629 start_check_change_timer();
630}
631
632
633/* Handling of the Head Settling Flag: This flag should be set after each
634 * seek operation, because we don't use seeks with verify.
635 */
636
637static inline void set_head_settle_flag(void)
638{
639 HeadSettleFlag = FDCCMDADD_E;
640}
641
642static inline int get_head_settle_flag(void)
643{
644 int tmp = HeadSettleFlag;
645 HeadSettleFlag = 0;
646 return( tmp );
647}
648
649static inline void copy_buffer(void *from, void *to)
650{
651 ulong *p1 = (ulong *)from, *p2 = (ulong *)to;
652 int cnt;
653
654 for (cnt = 512/4; cnt; cnt--)
655 *p2++ = *p1++;
656}
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658/* General Interrupt Handling */
659
660static void (*FloppyIRQHandler)( int status ) = NULL;
661
David Howells7d12e782006-10-05 14:55:46 +0100662static irqreturn_t floppy_irq (int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
664 unsigned char status;
665 void (*handler)( int );
666
667 handler = xchg(&FloppyIRQHandler, NULL);
668
669 if (handler) {
670 nop();
671 status = FDC_READ( FDCREG_STATUS );
672 DPRINT(("FDC irq, status = %02x handler = %08lx\n",status,(unsigned long)handler));
673 handler( status );
674 }
675 else {
676 DPRINT(("FDC irq, no handler\n"));
677 }
678 return IRQ_HANDLED;
679}
680
681
682/* Error handling: If some error happened, retry some times, then
683 * recalibrate, then try again, and fail after MAX_ERRORS.
684 */
685
686static void fd_error( void )
687{
688 if (IsFormatting) {
689 IsFormatting = 0;
690 FormatError = 1;
Arnd Bergmann7b8a3d22014-02-26 12:01:41 +0100691 complete(&format_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 return;
693 }
694
Tejun Heoa336ca62009-05-08 11:54:03 +0900695 if (!fd_request)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 return;
697
Christoph Hellwigc8e90782017-04-20 16:03:13 +0200698 fd_request->error_count++;
699 if (fd_request->error_count >= MAX_ERRORS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 printk(KERN_ERR "fd%d: too many errors.\n", SelectedDrive );
Christoph Hellwig2a842ac2017-06-03 09:38:04 +0200701 fd_end_request_cur(BLK_STS_IOERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
Christoph Hellwigc8e90782017-04-20 16:03:13 +0200703 else if (fd_request->error_count == RECALIBRATE_ERRORS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 printk(KERN_WARNING "fd%d: recalibrating\n", SelectedDrive );
705 if (SelectedDrive != -1)
706 SUD.track = -1;
707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
710
711
712#define SET_IRQ_HANDLER(proc) do { FloppyIRQHandler = (proc); } while(0)
713
714
715/* ---------- Formatting ---------- */
716
717#define FILL(n,val) \
718 do { \
719 memset( p, val, n ); \
720 p += n; \
721 } while(0)
722
723static int do_format(int drive, int type, struct atari_format_descr *desc)
724{
Christoph Hellwigbf9c0532020-10-29 15:58:38 +0100725 struct request_queue *q;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 unsigned char *p;
727 int sect, nsect;
728 unsigned long flags;
Omar Sandoval6ec39382018-10-15 09:18:24 -0600729 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Dan Carpenter1ffec382021-04-21 13:18:35 +0300731 if (type) {
Christoph Hellwigbf9c0532020-10-29 15:58:38 +0100732 type--;
Dan Carpenter1ffec382021-04-21 13:18:35 +0300733 if (type >= NUM_DISK_MINORS ||
734 minor2disktype[type].drive_types > DriveType)
735 return -EINVAL;
736 }
Christoph Hellwigbf9c0532020-10-29 15:58:38 +0100737
738 q = unit[drive].disk[type]->queue;
Omar Sandoval6ec39382018-10-15 09:18:24 -0600739 blk_mq_freeze_queue(q);
740 blk_mq_quiesce_queue(q);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 stdma_lock(floppy_irq, NULL);
744 atari_turnon_irq( IRQ_MFP_FDC ); /* should be already, just to be sure */
745 local_irq_restore(flags);
746
747 if (type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 type = minor2disktype[type].index;
Geert Uytterhoeven5ceadd22008-02-06 01:38:09 -0800749 UDT = &atari_disk_type[type];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
751
752 if (!UDT || desc->track >= UDT->blocks/UDT->spt/2 || desc->head >= 2) {
Omar Sandoval6ec39382018-10-15 09:18:24 -0600753 ret = -EINVAL;
754 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756
757 nsect = UDT->spt;
758 p = TrackBuffer;
759 /* The track buffer is used for the raw track data, so its
760 contents become invalid! */
761 BufferDrive = -1;
762 /* stop deselect timer */
763 del_timer( &motor_off_timer );
764
765 FILL( 60 * (nsect / 9), 0x4e );
766 for( sect = 0; sect < nsect; ++sect ) {
767 FILL( 12, 0 );
768 FILL( 3, 0xf5 );
769 *p++ = 0xfe;
770 *p++ = desc->track;
771 *p++ = desc->head;
772 *p++ = (nsect + sect - desc->sect_offset) % nsect + 1;
773 *p++ = 2;
774 *p++ = 0xf7;
775 FILL( 22, 0x4e );
776 FILL( 12, 0 );
777 FILL( 3, 0xf5 );
778 *p++ = 0xfb;
779 FILL( 512, 0xe5 );
780 *p++ = 0xf7;
781 FILL( 40, 0x4e );
782 }
783 FILL( TrackBuffer+BUFFER_SIZE-p, 0x4e );
784
785 IsFormatting = 1;
786 FormatError = 0;
787 ReqTrack = desc->track;
788 ReqSide = desc->head;
789 do_fd_action( drive );
790
Arnd Bergmann7b8a3d22014-02-26 12:01:41 +0100791 wait_for_completion(&format_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
Omar Sandoval6ec39382018-10-15 09:18:24 -0600793 ret = FormatError ? -EIO : 0;
794out:
795 blk_mq_unquiesce_queue(q);
796 blk_mq_unfreeze_queue(q);
797 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
800
801/* do_fd_action() is the general procedure for a fd request: All
802 * required parameter settings (drive select, side select, track
803 * position) are checked and set if needed. For each of these
804 * parameters and the actual reading or writing exist two functions:
805 * one that starts the setting (or skips it if possible) and one
806 * callback for the "done" interrupt. Each done func calls the next
807 * set function to propagate the request down to fd_rwsec_done().
808 */
809
810static void do_fd_action( int drive )
811{
812 DPRINT(("do_fd_action\n"));
813
814 if (UseTrackbuffer && !IsFormatting) {
815 repeat:
816 if (IS_BUFFERED( drive, ReqSide, ReqTrack )) {
817 if (ReqCmd == READ) {
818 copy_buffer( SECTOR_BUFFER(ReqSector), ReqData );
Tejun Heoa336ca62009-05-08 11:54:03 +0900819 if (++ReqCnt < blk_rq_cur_sectors(fd_request)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 /* read next sector */
821 setup_req_params( drive );
822 goto repeat;
823 }
824 else {
825 /* all sectors finished */
Christoph Hellwig2a842ac2017-06-03 09:38:04 +0200826 fd_end_request_cur(BLK_STS_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 return;
828 }
829 }
830 else {
831 /* cmd == WRITE, pay attention to track buffer
832 * consistency! */
833 copy_buffer( ReqData, SECTOR_BUFFER(ReqSector) );
834 }
835 }
836 }
837
838 if (SelectedDrive != drive)
839 fd_select_drive( drive );
840
841 if (UD.track == -1)
842 fd_calibrate();
843 else if (UD.track != ReqTrack << UDT->stretch)
844 fd_seek();
845 else if (IsFormatting)
846 fd_writetrack();
847 else
848 fd_rwsec();
849}
850
851
852/* Seek to track 0 if the current track is unknown */
853
854static void fd_calibrate( void )
855{
856 if (SUD.track >= 0) {
857 fd_calibrate_done( 0 );
858 return;
859 }
860
861 if (ATARIHW_PRESENT(FDCSPEED))
zhengbin9677d642019-11-28 11:09:32 +0800862 dma_wd.fdc_speed = 0; /* always seek with 8 Mhz */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 DPRINT(("fd_calibrate\n"));
864 SET_IRQ_HANDLER( fd_calibrate_done );
865 /* we can't verify, since the speed may be incorrect */
866 FDC_WRITE( FDCREG_CMD, FDCCMD_RESTORE | SUD.steprate );
867
868 NeedSeek = 1;
869 MotorOn = 1;
870 start_timeout();
871 /* wait for IRQ */
872}
873
874
875static void fd_calibrate_done( int status )
876{
877 DPRINT(("fd_calibrate_done()\n"));
878 stop_timeout();
879
880 /* set the correct speed now */
881 if (ATARIHW_PRESENT(FDCSPEED))
882 dma_wd.fdc_speed = SUDT->fdc_speed;
883 if (status & FDCSTAT_RECNF) {
884 printk(KERN_ERR "fd%d: restore failed\n", SelectedDrive );
885 fd_error();
886 }
887 else {
888 SUD.track = 0;
889 fd_seek();
890 }
891}
892
893
894/* Seek the drive to the requested track. The drive must have been
895 * calibrated at some point before this.
896 */
897
898static void fd_seek( void )
899{
900 if (SUD.track == ReqTrack << SUDT->stretch) {
901 fd_seek_done( 0 );
902 return;
903 }
904
905 if (ATARIHW_PRESENT(FDCSPEED)) {
906 dma_wd.fdc_speed = 0; /* always seek witch 8 Mhz */
907 MFPDELAY();
908 }
909
910 DPRINT(("fd_seek() to track %d\n",ReqTrack));
911 FDC_WRITE( FDCREG_DATA, ReqTrack << SUDT->stretch);
912 udelay(25);
913 SET_IRQ_HANDLER( fd_seek_done );
914 FDC_WRITE( FDCREG_CMD, FDCCMD_SEEK | SUD.steprate );
915
916 MotorOn = 1;
917 set_head_settle_flag();
918 start_timeout();
919 /* wait for IRQ */
920}
921
922
923static void fd_seek_done( int status )
924{
925 DPRINT(("fd_seek_done()\n"));
926 stop_timeout();
927
928 /* set the correct speed */
929 if (ATARIHW_PRESENT(FDCSPEED))
930 dma_wd.fdc_speed = SUDT->fdc_speed;
931 if (status & FDCSTAT_RECNF) {
932 printk(KERN_ERR "fd%d: seek error (to track %d)\n",
933 SelectedDrive, ReqTrack );
934 /* we don't know exactly which track we are on now! */
935 SUD.track = -1;
936 fd_error();
937 }
938 else {
939 SUD.track = ReqTrack << SUDT->stretch;
940 NeedSeek = 0;
941 if (IsFormatting)
942 fd_writetrack();
943 else
944 fd_rwsec();
945 }
946}
947
948
949/* This does the actual reading/writing after positioning the head
950 * over the correct track.
951 */
952
953static int MultReadInProgress = 0;
954
955
956static void fd_rwsec( void )
957{
958 unsigned long paddr, flags;
959 unsigned int rwflag, old_motoron;
960 unsigned int track;
961
962 DPRINT(("fd_rwsec(), Sec=%d, Access=%c\n",ReqSector, ReqCmd == WRITE ? 'w' : 'r' ));
963 if (ReqCmd == WRITE) {
964 if (ATARIHW_PRESENT(EXTD_DMA)) {
965 paddr = virt_to_phys(ReqData);
966 }
967 else {
968 copy_buffer( ReqData, DMABuffer );
969 paddr = PhysDMABuffer;
970 }
971 dma_cache_maintenance( paddr, 512, 1 );
972 rwflag = 0x100;
973 }
974 else {
975 if (read_track)
976 paddr = PhysTrackBuffer;
977 else
978 paddr = ATARIHW_PRESENT(EXTD_DMA) ?
979 virt_to_phys(ReqData) : PhysDMABuffer;
980 rwflag = 0;
981 }
982
983 fd_select_side( ReqSide );
984
985 /* Start sector of this operation */
986 FDC_WRITE( FDCREG_SECTOR, read_track ? 1 : ReqSector );
987 MFPDELAY();
988 /* Cheat for track if stretch != 0 */
989 if (SUDT->stretch) {
990 track = FDC_READ( FDCREG_TRACK);
991 MFPDELAY();
992 FDC_WRITE( FDCREG_TRACK, track >> SUDT->stretch);
993 }
994 udelay(25);
995
996 /* Setup DMA */
997 local_irq_save(flags);
998 dma_wd.dma_lo = (unsigned char)paddr;
999 MFPDELAY();
1000 paddr >>= 8;
1001 dma_wd.dma_md = (unsigned char)paddr;
1002 MFPDELAY();
1003 paddr >>= 8;
1004 if (ATARIHW_PRESENT(EXTD_DMA))
1005 st_dma_ext_dmahi = (unsigned short)paddr;
1006 else
1007 dma_wd.dma_hi = (unsigned char)paddr;
1008 MFPDELAY();
1009 local_irq_restore(flags);
1010
1011 /* Clear FIFO and switch DMA to correct mode */
1012 dma_wd.dma_mode_status = 0x90 | rwflag;
1013 MFPDELAY();
1014 dma_wd.dma_mode_status = 0x90 | (rwflag ^ 0x100);
1015 MFPDELAY();
1016 dma_wd.dma_mode_status = 0x90 | rwflag;
1017 MFPDELAY();
1018
1019 /* How many sectors for DMA */
1020 dma_wd.fdc_acces_seccount = read_track ? SUDT->spt : 1;
1021
1022 udelay(25);
1023
1024 /* Start operation */
1025 dma_wd.dma_mode_status = FDCSELREG_STP | rwflag;
1026 udelay(25);
1027 SET_IRQ_HANDLER( fd_rwsec_done );
1028 dma_wd.fdc_acces_seccount =
1029 (get_head_settle_flag() |
1030 (rwflag ? FDCCMD_WRSEC : (FDCCMD_RDSEC | (read_track ? FDCCMDADD_M : 0))));
1031
1032 old_motoron = MotorOn;
1033 MotorOn = 1;
1034 NeedSeek = 1;
1035 /* wait for interrupt */
1036
1037 if (read_track) {
1038 /* If reading a whole track, wait about one disk rotation and
1039 * then check if all sectors are read. The FDC will even
1040 * search for the first non-existent sector and need 1 sec to
1041 * recognise that it isn't present :-(
1042 */
1043 MultReadInProgress = 1;
1044 mod_timer(&readtrack_timer,
1045 /* 1 rot. + 5 rot.s if motor was off */
1046 jiffies + HZ/5 + (old_motoron ? 0 : HZ));
1047 }
1048 start_timeout();
1049}
1050
1051
Kees Cook24ed9602017-08-28 11:28:21 -07001052static void fd_readtrack_check(struct timer_list *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053{
1054 unsigned long flags, addr, addr2;
1055
1056 local_irq_save(flags);
1057
1058 if (!MultReadInProgress) {
1059 /* This prevents a race condition that could arise if the
1060 * interrupt is triggered while the calling of this timer
1061 * callback function takes place. The IRQ function then has
1062 * already cleared 'MultReadInProgress' when flow of control
1063 * gets here.
1064 */
1065 local_irq_restore(flags);
1066 return;
1067 }
1068
1069 /* get the current DMA address */
1070 /* ++ f.a. read twice to avoid being fooled by switcher */
1071 addr = 0;
1072 do {
1073 addr2 = addr;
1074 addr = dma_wd.dma_lo & 0xff;
1075 MFPDELAY();
1076 addr |= (dma_wd.dma_md & 0xff) << 8;
1077 MFPDELAY();
1078 if (ATARIHW_PRESENT( EXTD_DMA ))
1079 addr |= (st_dma_ext_dmahi & 0xffff) << 16;
1080 else
1081 addr |= (dma_wd.dma_hi & 0xff) << 16;
1082 MFPDELAY();
1083 } while(addr != addr2);
1084
1085 if (addr >= PhysTrackBuffer + SUDT->spt*512) {
1086 /* already read enough data, force an FDC interrupt to stop
1087 * the read operation
1088 */
1089 SET_IRQ_HANDLER( NULL );
1090 MultReadInProgress = 0;
1091 local_irq_restore(flags);
1092 DPRINT(("fd_readtrack_check(): done\n"));
1093 FDC_WRITE( FDCREG_CMD, FDCCMD_FORCI );
1094 udelay(25);
1095
1096 /* No error until now -- the FDC would have interrupted
1097 * otherwise!
1098 */
1099 fd_rwsec_done1(0);
1100 }
1101 else {
1102 /* not yet finished, wait another tenth rotation */
1103 local_irq_restore(flags);
1104 DPRINT(("fd_readtrack_check(): not yet finished\n"));
1105 mod_timer(&readtrack_timer, jiffies + HZ/5/10);
1106 }
1107}
1108
1109
1110static void fd_rwsec_done( int status )
1111{
1112 DPRINT(("fd_rwsec_done()\n"));
1113
1114 if (read_track) {
1115 del_timer(&readtrack_timer);
1116 if (!MultReadInProgress)
1117 return;
1118 MultReadInProgress = 0;
1119 }
1120 fd_rwsec_done1(status);
1121}
1122
1123static void fd_rwsec_done1(int status)
1124{
1125 unsigned int track;
1126
1127 stop_timeout();
1128
1129 /* Correct the track if stretch != 0 */
1130 if (SUDT->stretch) {
1131 track = FDC_READ( FDCREG_TRACK);
1132 MFPDELAY();
1133 FDC_WRITE( FDCREG_TRACK, track << SUDT->stretch);
1134 }
1135
1136 if (!UseTrackbuffer) {
1137 dma_wd.dma_mode_status = 0x90;
1138 MFPDELAY();
1139 if (!(dma_wd.dma_mode_status & 0x01)) {
1140 printk(KERN_ERR "fd%d: DMA error\n", SelectedDrive );
1141 goto err_end;
1142 }
1143 }
1144 MFPDELAY();
1145
1146 if (ReqCmd == WRITE && (status & FDCSTAT_WPROT)) {
1147 printk(KERN_NOTICE "fd%d: is write protected\n", SelectedDrive );
1148 goto err_end;
1149 }
1150 if ((status & FDCSTAT_RECNF) &&
1151 /* RECNF is no error after a multiple read when the FDC
1152 searched for a non-existent sector! */
1153 !(read_track && FDC_READ(FDCREG_SECTOR) > SUDT->spt)) {
1154 if (Probing) {
Geert Uytterhoeven5ceadd22008-02-06 01:38:09 -08001155 if (SUDT > atari_disk_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 if (SUDT[-1].blocks > ReqBlock) {
1157 /* try another disk type */
1158 SUDT--;
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001159 set_capacity(unit[SelectedDrive].disk[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 SUDT->blocks);
1161 } else
1162 Probing = 0;
1163 }
1164 else {
1165 if (SUD.flags & FTD_MSG)
1166 printk(KERN_INFO "fd%d: Auto-detected floppy type %s\n",
1167 SelectedDrive, SUDT->name );
1168 Probing=0;
1169 }
1170 } else {
1171/* record not found, but not probing. Maybe stretch wrong ? Restart probing */
1172 if (SUD.autoprobe) {
Geert Uytterhoeven5ceadd22008-02-06 01:38:09 -08001173 SUDT = atari_disk_type + StartDiskType[DriveType];
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001174 set_capacity(unit[SelectedDrive].disk[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 SUDT->blocks);
1176 Probing = 1;
1177 }
1178 }
1179 if (Probing) {
1180 if (ATARIHW_PRESENT(FDCSPEED)) {
1181 dma_wd.fdc_speed = SUDT->fdc_speed;
1182 MFPDELAY();
1183 }
1184 setup_req_params( SelectedDrive );
1185 BufferDrive = -1;
1186 do_fd_action( SelectedDrive );
1187 return;
1188 }
1189
1190 printk(KERN_ERR "fd%d: sector %d not found (side %d, track %d)\n",
1191 SelectedDrive, FDC_READ (FDCREG_SECTOR), ReqSide, ReqTrack );
1192 goto err_end;
1193 }
1194 if (status & FDCSTAT_CRC) {
1195 printk(KERN_ERR "fd%d: CRC error (side %d, track %d, sector %d)\n",
1196 SelectedDrive, ReqSide, ReqTrack, FDC_READ (FDCREG_SECTOR) );
1197 goto err_end;
1198 }
1199 if (status & FDCSTAT_LOST) {
1200 printk(KERN_ERR "fd%d: lost data (side %d, track %d, sector %d)\n",
1201 SelectedDrive, ReqSide, ReqTrack, FDC_READ (FDCREG_SECTOR) );
1202 goto err_end;
1203 }
1204
1205 Probing = 0;
1206
1207 if (ReqCmd == READ) {
1208 if (!read_track) {
1209 void *addr;
1210 addr = ATARIHW_PRESENT( EXTD_DMA ) ? ReqData : DMABuffer;
1211 dma_cache_maintenance( virt_to_phys(addr), 512, 0 );
1212 if (!ATARIHW_PRESENT( EXTD_DMA ))
1213 copy_buffer (addr, ReqData);
1214 } else {
1215 dma_cache_maintenance( PhysTrackBuffer, MaxSectors[DriveType] * 512, 0 );
1216 BufferDrive = SelectedDrive;
1217 BufferSide = ReqSide;
1218 BufferTrack = ReqTrack;
1219 copy_buffer (SECTOR_BUFFER (ReqSector), ReqData);
1220 }
1221 }
1222
Tejun Heoa336ca62009-05-08 11:54:03 +09001223 if (++ReqCnt < blk_rq_cur_sectors(fd_request)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 /* read next sector */
1225 setup_req_params( SelectedDrive );
1226 do_fd_action( SelectedDrive );
1227 }
1228 else {
1229 /* all sectors finished */
Michael Schmitz86d46fd2021-10-19 19:13:21 +13001230 finish_fdc();
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02001231 fd_end_request_cur(BLK_STS_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 }
1233 return;
1234
1235 err_end:
1236 BufferDrive = -1;
1237 fd_error();
1238}
1239
1240
1241static void fd_writetrack( void )
1242{
1243 unsigned long paddr, flags;
1244 unsigned int track;
1245
1246 DPRINT(("fd_writetrack() Tr=%d Si=%d\n", ReqTrack, ReqSide ));
1247
1248 paddr = PhysTrackBuffer;
1249 dma_cache_maintenance( paddr, BUFFER_SIZE, 1 );
1250
1251 fd_select_side( ReqSide );
1252
1253 /* Cheat for track if stretch != 0 */
1254 if (SUDT->stretch) {
1255 track = FDC_READ( FDCREG_TRACK);
1256 MFPDELAY();
1257 FDC_WRITE(FDCREG_TRACK,track >> SUDT->stretch);
1258 }
1259 udelay(40);
1260
1261 /* Setup DMA */
1262 local_irq_save(flags);
1263 dma_wd.dma_lo = (unsigned char)paddr;
1264 MFPDELAY();
1265 paddr >>= 8;
1266 dma_wd.dma_md = (unsigned char)paddr;
1267 MFPDELAY();
1268 paddr >>= 8;
1269 if (ATARIHW_PRESENT( EXTD_DMA ))
1270 st_dma_ext_dmahi = (unsigned short)paddr;
1271 else
1272 dma_wd.dma_hi = (unsigned char)paddr;
1273 MFPDELAY();
1274 local_irq_restore(flags);
1275
1276 /* Clear FIFO and switch DMA to correct mode */
1277 dma_wd.dma_mode_status = 0x190;
1278 MFPDELAY();
1279 dma_wd.dma_mode_status = 0x90;
1280 MFPDELAY();
1281 dma_wd.dma_mode_status = 0x190;
1282 MFPDELAY();
1283
1284 /* How many sectors for DMA */
1285 dma_wd.fdc_acces_seccount = BUFFER_SIZE/512;
1286 udelay(40);
1287
1288 /* Start operation */
1289 dma_wd.dma_mode_status = FDCSELREG_STP | 0x100;
1290 udelay(40);
1291 SET_IRQ_HANDLER( fd_writetrack_done );
1292 dma_wd.fdc_acces_seccount = FDCCMD_WRTRA | get_head_settle_flag();
1293
1294 MotorOn = 1;
1295 start_timeout();
1296 /* wait for interrupt */
1297}
1298
1299
1300static void fd_writetrack_done( int status )
1301{
1302 DPRINT(("fd_writetrack_done()\n"));
1303
1304 stop_timeout();
1305
1306 if (status & FDCSTAT_WPROT) {
1307 printk(KERN_NOTICE "fd%d: is write protected\n", SelectedDrive );
1308 goto err_end;
1309 }
1310 if (status & FDCSTAT_LOST) {
1311 printk(KERN_ERR "fd%d: lost data (side %d, track %d)\n",
1312 SelectedDrive, ReqSide, ReqTrack );
1313 goto err_end;
1314 }
1315
Arnd Bergmann7b8a3d22014-02-26 12:01:41 +01001316 complete(&format_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 return;
1318
1319 err_end:
1320 fd_error();
1321}
1322
Kees Cook24ed9602017-08-28 11:28:21 -07001323static void fd_times_out(struct timer_list *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
1325 atari_disable_irq( IRQ_MFP_FDC );
1326 if (!FloppyIRQHandler) goto end; /* int occurred after timer was fired, but
1327 * before we came here... */
1328
1329 SET_IRQ_HANDLER( NULL );
1330 /* If the timeout occurred while the readtrack_check timer was
1331 * active, we need to cancel it, else bad things will happen */
1332 if (UseTrackbuffer)
1333 del_timer( &readtrack_timer );
1334 FDC_WRITE( FDCREG_CMD, FDCCMD_FORCI );
1335 udelay( 25 );
1336
1337 printk(KERN_ERR "floppy timeout\n" );
1338 fd_error();
1339 end:
1340 atari_enable_irq( IRQ_MFP_FDC );
1341}
1342
1343
1344/* The (noop) seek operation here is needed to make the WP bit in the
1345 * FDC status register accessible for check_change. If the last disk
1346 * operation would have been a RDSEC, this bit would always read as 0
1347 * no matter what :-( To save time, the seek goes to the track we're
1348 * already on.
1349 */
1350
1351static void finish_fdc( void )
1352{
1353 if (!NeedSeek) {
1354 finish_fdc_done( 0 );
1355 }
1356 else {
1357 DPRINT(("finish_fdc: dummy seek started\n"));
1358 FDC_WRITE (FDCREG_DATA, SUD.track);
1359 SET_IRQ_HANDLER( finish_fdc_done );
1360 FDC_WRITE (FDCREG_CMD, FDCCMD_SEEK);
1361 MotorOn = 1;
1362 start_timeout();
1363 /* we must wait for the IRQ here, because the ST-DMA
1364 is released immediately afterwards and the interrupt
1365 may be delivered to the wrong driver. */
1366 }
1367}
1368
1369
1370static void finish_fdc_done( int dummy )
1371{
1372 unsigned long flags;
1373
1374 DPRINT(("finish_fdc_done entered\n"));
1375 stop_timeout();
1376 NeedSeek = 0;
1377
1378 if (timer_pending(&fd_timer) && time_before(fd_timer.expires, jiffies + 5))
1379 /* If the check for a disk change is done too early after this
1380 * last seek command, the WP bit still reads wrong :-((
1381 */
1382 mod_timer(&fd_timer, jiffies + 5);
1383 else
1384 start_check_change_timer();
1385 start_motor_off_timer();
1386
1387 local_irq_save(flags);
1388 stdma_release();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 local_irq_restore(flags);
1390
1391 DPRINT(("finish_fdc() finished\n"));
1392}
1393
1394/* The detection of disk changes is a dark chapter in Atari history :-(
1395 * Because the "Drive ready" signal isn't present in the Atari
1396 * hardware, one has to rely on the "Write Protect". This works fine,
1397 * as long as no write protected disks are used. TOS solves this
1398 * problem by introducing tri-state logic ("maybe changed") and
1399 * looking at the serial number in block 0. This isn't possible for
1400 * Linux, since the floppy driver can't make assumptions about the
1401 * filesystem used on the disk and thus the contents of block 0. I've
1402 * chosen the method to always say "The disk was changed" if it is
1403 * unsure whether it was. This implies that every open or mount
1404 * invalidates the disk buffers if you work with write protected
1405 * disks. But at least this is better than working with incorrect data
1406 * due to unrecognised disk changes.
1407 */
1408
Tejun Heo1a8a74f2011-03-09 19:54:27 +01001409static unsigned int floppy_check_events(struct gendisk *disk,
1410 unsigned int clearing)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
1412 struct atari_floppy_struct *p = disk->private_data;
1413 unsigned int drive = p - unit;
1414 if (test_bit (drive, &fake_change)) {
1415 /* simulated change (e.g. after formatting) */
Tejun Heo1a8a74f2011-03-09 19:54:27 +01001416 return DISK_EVENT_MEDIA_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 }
1418 if (test_bit (drive, &changed_floppies)) {
1419 /* surely changed (the WP signal changed at least once) */
Tejun Heo1a8a74f2011-03-09 19:54:27 +01001420 return DISK_EVENT_MEDIA_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 }
1422 if (UD.wpstat) {
1423 /* WP is on -> could be changed: to be sure, buffers should be
1424 * invalidated...
1425 */
Tejun Heo1a8a74f2011-03-09 19:54:27 +01001426 return DISK_EVENT_MEDIA_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428
1429 return 0;
1430}
1431
1432static int floppy_revalidate(struct gendisk *disk)
1433{
1434 struct atari_floppy_struct *p = disk->private_data;
1435 unsigned int drive = p - unit;
1436
1437 if (test_bit(drive, &changed_floppies) ||
1438 test_bit(drive, &fake_change) ||
1439 p->disktype == 0) {
1440 if (UD.flags & FTD_MSG)
1441 printk(KERN_ERR "floppy: clear format %p!\n", UDT);
1442 BufferDrive = -1;
1443 clear_bit(drive, &fake_change);
1444 clear_bit(drive, &changed_floppies);
1445 /* MSch: clearing geometry makes sense only for autoprobe
1446 formats, for 'permanent user-defined' parameter:
1447 restore default_params[] here if flagged valid! */
1448 if (default_params[drive].blocks == 0)
Al Viro2c7af512006-01-12 01:06:29 -08001449 UDT = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 else
1451 UDT = &default_params[drive];
1452 }
1453 return 0;
1454}
1455
1456
1457/* This sets up the global variables describing the current request. */
1458
1459static void setup_req_params( int drive )
1460{
1461 int block = ReqBlock + ReqCnt;
1462
1463 ReqTrack = block / UDT->spt;
1464 ReqSector = block - ReqTrack * UDT->spt + 1;
1465 ReqSide = ReqTrack & 1;
1466 ReqTrack >>= 1;
1467 ReqData = ReqBuffer + 512 * ReqCnt;
1468
1469 if (UseTrackbuffer)
Christoph Hellwigc8e90782017-04-20 16:03:13 +02001470 read_track = (ReqCmd == READ && fd_request->error_count == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 else
1472 read_track = 0;
1473
1474 DPRINT(("Request params: Si=%d Tr=%d Se=%d Data=%08lx\n",ReqSide,
1475 ReqTrack, ReqSector, (unsigned long)ReqData ));
1476}
1477
Omar Sandoval6ec39382018-10-15 09:18:24 -06001478static blk_status_t ataflop_queue_rq(struct blk_mq_hw_ctx *hctx,
1479 const struct blk_mq_queue_data *bd)
Vivek Goyal639e2f22010-09-24 20:35:45 +02001480{
Omar Sandoval6ec39382018-10-15 09:18:24 -06001481 struct atari_floppy_struct *floppy = bd->rq->rq_disk->private_data;
1482 int drive = floppy - unit;
1483 int type = floppy->type;
Vivek Goyal639e2f22010-09-24 20:35:45 +02001484
Michael Schmitz86d46fd2021-10-19 19:13:21 +13001485 DPRINT(("Queue request: drive %d type %d last %d\n", drive, type, bd->last));
1486
Omar Sandoval6ec39382018-10-15 09:18:24 -06001487 spin_lock_irq(&ataflop_lock);
1488 if (fd_request) {
1489 spin_unlock_irq(&ataflop_lock);
1490 return BLK_STS_DEV_RESOURCE;
1491 }
1492 if (!stdma_try_lock(floppy_irq, NULL)) {
1493 spin_unlock_irq(&ataflop_lock);
1494 return BLK_STS_RESOURCE;
1495 }
1496 fd_request = bd->rq;
1497 blk_mq_start_request(fd_request);
Vivek Goyal639e2f22010-09-24 20:35:45 +02001498
Omar Sandoval6ec39382018-10-15 09:18:24 -06001499 atari_disable_irq( IRQ_MFP_FDC );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
1501 IsFormatting = 0;
1502
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 if (!UD.connected) {
1504 /* drive not connected */
1505 printk(KERN_ERR "Unknown Device: fd%d\n", drive );
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02001506 fd_end_request_cur(BLK_STS_IOERR);
Omar Sandoval6ec39382018-10-15 09:18:24 -06001507 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 }
1509
1510 if (type == 0) {
1511 if (!UDT) {
1512 Probing = 1;
Geert Uytterhoeven5ceadd22008-02-06 01:38:09 -08001513 UDT = atari_disk_type + StartDiskType[DriveType];
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001514 set_capacity(bd->rq->rq_disk, UDT->blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 UD.autoprobe = 1;
1516 }
1517 }
1518 else {
1519 /* user supplied disk type */
1520 if (--type >= NUM_DISK_MINORS) {
1521 printk(KERN_WARNING "fd%d: invalid disk format", drive );
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02001522 fd_end_request_cur(BLK_STS_IOERR);
Omar Sandoval6ec39382018-10-15 09:18:24 -06001523 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 }
1525 if (minor2disktype[type].drive_types > DriveType) {
1526 printk(KERN_WARNING "fd%d: unsupported disk format", drive );
Christoph Hellwig2a842ac2017-06-03 09:38:04 +02001527 fd_end_request_cur(BLK_STS_IOERR);
Omar Sandoval6ec39382018-10-15 09:18:24 -06001528 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 }
1530 type = minor2disktype[type].index;
Geert Uytterhoeven5ceadd22008-02-06 01:38:09 -08001531 UDT = &atari_disk_type[type];
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001532 set_capacity(bd->rq->rq_disk, UDT->blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 UD.autoprobe = 0;
1534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 /* stop deselect timer */
1537 del_timer( &motor_off_timer );
1538
1539 ReqCnt = 0;
Tejun Heoa336ca62009-05-08 11:54:03 +09001540 ReqCmd = rq_data_dir(fd_request);
1541 ReqBlock = blk_rq_pos(fd_request);
Jens Axboeb4f42e22014-04-10 09:46:28 -06001542 ReqBuffer = bio_data(fd_request->bio);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 setup_req_params( drive );
1544 do_fd_action( drive );
1545
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 atari_enable_irq( IRQ_MFP_FDC );
Omar Sandoval6ec39382018-10-15 09:18:24 -06001547
1548out:
1549 spin_unlock_irq(&ataflop_lock);
1550 return BLK_STS_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551}
1552
Arnd Bergmann8a6cfeb2010-07-08 10:18:46 +02001553static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 unsigned int cmd, unsigned long param)
1555{
Al Viro60ad2342008-03-02 09:23:54 -05001556 struct gendisk *disk = bdev->bd_disk;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 struct atari_floppy_struct *floppy = disk->private_data;
1558 int drive = floppy - unit;
1559 int type = floppy->type;
1560 struct atari_format_descr fmt_desc;
1561 struct atari_disk_type *dtp;
1562 struct floppy_struct getprm;
1563 int settype;
1564 struct floppy_struct setprm;
Al Viro2c7af512006-01-12 01:06:29 -08001565 void __user *argp = (void __user *)param;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
1567 switch (cmd) {
1568 case FDGETPRM:
1569 if (type) {
1570 if (--type >= NUM_DISK_MINORS)
1571 return -ENODEV;
1572 if (minor2disktype[type].drive_types > DriveType)
1573 return -ENODEV;
1574 type = minor2disktype[type].index;
Geert Uytterhoeven5ceadd22008-02-06 01:38:09 -08001575 dtp = &atari_disk_type[type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 if (UD.flags & FTD_MSG)
1577 printk (KERN_ERR "floppy%d: found dtp %p name %s!\n",
1578 drive, dtp, dtp->name);
1579 }
1580 else {
1581 if (!UDT)
1582 return -ENXIO;
1583 else
1584 dtp = UDT;
1585 }
1586 memset((void *)&getprm, 0, sizeof(getprm));
1587 getprm.size = dtp->blocks;
1588 getprm.sect = dtp->spt;
1589 getprm.head = 2;
1590 getprm.track = dtp->blocks/dtp->spt/2;
1591 getprm.stretch = dtp->stretch;
Al Viro2c7af512006-01-12 01:06:29 -08001592 if (copy_to_user(argp, &getprm, sizeof(getprm)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 return -EFAULT;
1594 return 0;
1595 }
1596 switch (cmd) {
1597 case FDSETPRM:
1598 case FDDEFPRM:
1599 /*
1600 * MSch 7/96: simple 'set geometry' case: just set the
1601 * 'default' device params (minor == 0).
1602 * Currently, the drive geometry is cleared after each
1603 * disk change and subsequent revalidate()! simple
1604 * implementation of FDDEFPRM: save geometry from a
1605 * FDDEFPRM call and restore it in floppy_revalidate() !
1606 */
1607
1608 /* get the parameters from user space */
1609 if (floppy->ref != 1 && floppy->ref != -1)
1610 return -EBUSY;
Al Viro2c7af512006-01-12 01:06:29 -08001611 if (copy_from_user(&setprm, argp, sizeof(setprm)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 return -EFAULT;
1613 /*
1614 * first of all: check for floppy change and revalidate,
1615 * or the next access will revalidate - and clear UDT :-(
1616 */
1617
Tejun Heo1a8a74f2011-03-09 19:54:27 +01001618 if (floppy_check_events(disk, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 floppy_revalidate(disk);
1620
1621 if (UD.flags & FTD_MSG)
1622 printk (KERN_INFO "floppy%d: setting size %d spt %d str %d!\n",
1623 drive, setprm.size, setprm.sect, setprm.stretch);
1624
1625 /* what if type > 0 here? Overwrite specified entry ? */
1626 if (type) {
1627 /* refuse to re-set a predefined type for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 return -EINVAL;
1629 }
1630
1631 /*
1632 * type == 0: first look for a matching entry in the type list,
1633 * and set the UD.disktype field to use the perdefined entry.
1634 * TODO: add user-defined format to head of autoprobe list ?
1635 * Useful to include the user-type for future autodetection!
1636 */
1637
1638 for (settype = 0; settype < NUM_DISK_MINORS; settype++) {
1639 int setidx = 0;
1640 if (minor2disktype[settype].drive_types > DriveType) {
1641 /* skip this one, invalid for drive ... */
1642 continue;
1643 }
1644 setidx = minor2disktype[settype].index;
Geert Uytterhoeven5ceadd22008-02-06 01:38:09 -08001645 dtp = &atari_disk_type[setidx];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 /* found matching entry ?? */
1648 if ( dtp->blocks == setprm.size
1649 && dtp->spt == setprm.sect
1650 && dtp->stretch == setprm.stretch ) {
1651 if (UD.flags & FTD_MSG)
1652 printk (KERN_INFO "floppy%d: setting %s %p!\n",
1653 drive, dtp->name, dtp);
1654 UDT = dtp;
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001655 set_capacity(disk, UDT->blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657 if (cmd == FDDEFPRM) {
1658 /* save settings as permanent default type */
1659 default_params[drive].name = dtp->name;
1660 default_params[drive].spt = dtp->spt;
1661 default_params[drive].blocks = dtp->blocks;
1662 default_params[drive].fdc_speed = dtp->fdc_speed;
1663 default_params[drive].stretch = dtp->stretch;
1664 }
1665
1666 return 0;
1667 }
1668
1669 }
1670
1671 /* no matching disk type found above - setting user_params */
1672
1673 if (cmd == FDDEFPRM) {
1674 /* set permanent type */
1675 dtp = &default_params[drive];
1676 } else
1677 /* set user type (reset by disk change!) */
1678 dtp = &user_params[drive];
1679
1680 dtp->name = "user format";
1681 dtp->blocks = setprm.size;
1682 dtp->spt = setprm.sect;
1683 if (setprm.sect > 14)
1684 dtp->fdc_speed = 3;
1685 else
1686 dtp->fdc_speed = 0;
1687 dtp->stretch = setprm.stretch;
1688
1689 if (UD.flags & FTD_MSG)
1690 printk (KERN_INFO "floppy%d: blk %d spt %d str %d!\n",
1691 drive, dtp->blocks, dtp->spt, dtp->stretch);
1692
1693 /* sanity check */
Julia Lawall8f474282009-07-13 22:43:41 +02001694 if (setprm.track != dtp->blocks/dtp->spt/2 ||
Omar Sandoval6ec39382018-10-15 09:18:24 -06001695 setprm.head != 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
1698 UDT = dtp;
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001699 set_capacity(disk, UDT->blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
1701 return 0;
1702 case FDMSGON:
1703 UD.flags |= FTD_MSG;
1704 return 0;
1705 case FDMSGOFF:
1706 UD.flags &= ~FTD_MSG;
1707 return 0;
1708 case FDSETEMSGTRESH:
1709 return -EINVAL;
1710 case FDFMTBEG:
1711 return 0;
1712 case FDFMTTRK:
1713 if (floppy->ref != 1 && floppy->ref != -1)
1714 return -EBUSY;
Al Viro2c7af512006-01-12 01:06:29 -08001715 if (copy_from_user(&fmt_desc, argp, sizeof(fmt_desc)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 return -EFAULT;
1717 return do_format(drive, type, &fmt_desc);
1718 case FDCLRPRM:
1719 UDT = NULL;
1720 /* MSch: invalidate default_params */
1721 default_params[drive].blocks = 0;
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001722 set_capacity(disk, MAX_DISK_SIZE * 2);
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001723 fallthrough;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 case FDFMTEND:
1725 case FDFLUSH:
1726 /* invalidate the buffer track to force a reread */
1727 BufferDrive = -1;
1728 set_bit(drive, &fake_change);
Christoph Hellwig22f97162020-09-08 16:53:31 +02001729 if (bdev_check_media_change(bdev))
1730 floppy_revalidate(bdev->bd_disk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 return 0;
1732 default:
1733 return -EINVAL;
1734 }
1735}
1736
Arnd Bergmann8a6cfeb2010-07-08 10:18:46 +02001737static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1738 unsigned int cmd, unsigned long arg)
1739{
1740 int ret;
1741
Arnd Bergmann2a48fc02010-06-02 14:28:52 +02001742 mutex_lock(&ataflop_mutex);
Arnd Bergmann8a6cfeb2010-07-08 10:18:46 +02001743 ret = fd_locked_ioctl(bdev, mode, cmd, arg);
Arnd Bergmann2a48fc02010-06-02 14:28:52 +02001744 mutex_unlock(&ataflop_mutex);
Arnd Bergmann8a6cfeb2010-07-08 10:18:46 +02001745
1746 return ret;
1747}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
1749/* Initialize the 'unit' variable for drive 'drive' */
1750
1751static void __init fd_probe( int drive )
1752{
1753 UD.connected = 0;
1754 UDT = NULL;
1755
1756 if (!fd_test_drive_present( drive ))
1757 return;
1758
1759 UD.connected = 1;
1760 UD.track = 0;
1761 switch( UserSteprate[drive] ) {
1762 case 2:
1763 UD.steprate = FDCSTEP_2;
1764 break;
1765 case 3:
1766 UD.steprate = FDCSTEP_3;
1767 break;
1768 case 6:
1769 UD.steprate = FDCSTEP_6;
1770 break;
1771 case 12:
1772 UD.steprate = FDCSTEP_12;
1773 break;
1774 default: /* should be -1 for "not set by user" */
1775 if (ATARIHW_PRESENT( FDCSPEED ) || MACH_IS_MEDUSA)
1776 UD.steprate = FDCSTEP_3;
1777 else
1778 UD.steprate = FDCSTEP_6;
1779 break;
1780 }
1781 MotorOn = 1; /* from probe restore operation! */
1782}
1783
1784
1785/* This function tests the physical presence of a floppy drive (not
1786 * whether a disk is inserted). This is done by issuing a restore
1787 * command, waiting max. 2 seconds (that should be enough to move the
1788 * head across the whole disk) and looking at the state of the "TR00"
1789 * signal. This should now be raised if there is a drive connected
1790 * (and there is no hardware failure :-) Otherwise, the drive is
1791 * declared absent.
1792 */
1793
1794static int __init fd_test_drive_present( int drive )
1795{
1796 unsigned long timeout;
1797 unsigned char status;
1798 int ok;
1799
1800 if (drive >= (MACH_IS_FALCON ? 1 : 2)) return( 0 );
1801 fd_select_drive( drive );
1802
1803 /* disable interrupt temporarily */
1804 atari_turnoff_irq( IRQ_MFP_FDC );
1805 FDC_WRITE (FDCREG_TRACK, 0xff00);
1806 FDC_WRITE( FDCREG_CMD, FDCCMD_RESTORE | FDCCMDADD_H | FDCSTEP_6 );
1807
1808 timeout = jiffies + 2*HZ+HZ/2;
1809 while (time_before(jiffies, timeout))
Geert Uytterhoeven3d92e8f2009-02-22 09:38:47 +01001810 if (!(st_mfp.par_dt_reg & 0x20))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 break;
1812
1813 status = FDC_READ( FDCREG_STATUS );
1814 ok = (status & FDCSTAT_TR00) != 0;
1815
1816 /* force interrupt to abort restore operation (FDC would try
1817 * about 50 seconds!) */
1818 FDC_WRITE( FDCREG_CMD, FDCCMD_FORCI );
1819 udelay(500);
1820 status = FDC_READ( FDCREG_STATUS );
1821 udelay(20);
1822
1823 if (ok) {
1824 /* dummy seek command to make WP bit accessible */
1825 FDC_WRITE( FDCREG_DATA, 0 );
1826 FDC_WRITE( FDCREG_CMD, FDCCMD_SEEK );
Geert Uytterhoeven3d92e8f2009-02-22 09:38:47 +01001827 while( st_mfp.par_dt_reg & 0x20 )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 ;
1829 status = FDC_READ( FDCREG_STATUS );
1830 }
1831
1832 atari_turnon_irq( IRQ_MFP_FDC );
1833 return( ok );
1834}
1835
1836
1837/* Look how many and which kind of drives are connected. If there are
1838 * floppies, additionally start the disk-change and motor-off timers.
1839 */
1840
1841static void __init config_types( void )
1842{
1843 int drive, cnt = 0;
1844
1845 /* for probing drives, set the FDC speed to 8 MHz */
1846 if (ATARIHW_PRESENT(FDCSPEED))
1847 dma_wd.fdc_speed = 0;
1848
1849 printk(KERN_INFO "Probing floppy drive(s):\n");
1850 for( drive = 0; drive < FD_MAX_UNITS; drive++ ) {
1851 fd_probe( drive );
1852 if (UD.connected) {
1853 printk(KERN_INFO "fd%d\n", drive);
1854 ++cnt;
1855 }
1856 }
1857
1858 if (FDC_READ( FDCREG_STATUS ) & FDCSTAT_BUSY) {
1859 /* If FDC is still busy from probing, give it another FORCI
1860 * command to abort the operation. If this isn't done, the FDC
1861 * will interrupt later and its IRQ line stays low, because
1862 * the status register isn't read. And this will block any
1863 * interrupts on this IRQ line :-(
1864 */
1865 FDC_WRITE( FDCREG_CMD, FDCCMD_FORCI );
1866 udelay(500);
1867 FDC_READ( FDCREG_STATUS );
1868 udelay(20);
1869 }
1870
1871 if (cnt > 0) {
1872 start_motor_off_timer();
1873 if (cnt == 1) fd_select_drive( 0 );
1874 start_check_change_timer();
1875 }
1876}
1877
1878/*
1879 * floppy_open check for aliasing (/dev/fd0 can be the same as
1880 * /dev/PS0 etc), and disallows simultaneous access to the same
1881 * drive with different device numbers.
1882 */
1883
Al Viro60ad2342008-03-02 09:23:54 -05001884static int floppy_open(struct block_device *bdev, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885{
Al Viro60ad2342008-03-02 09:23:54 -05001886 struct atari_floppy_struct *p = bdev->bd_disk->private_data;
1887 int type = MINOR(bdev->bd_dev) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
1889 DPRINT(("fd_open: type=%d\n",type));
1890 if (p->ref && p->type != type)
1891 return -EBUSY;
1892
Al Viro60ad2342008-03-02 09:23:54 -05001893 if (p->ref == -1 || (p->ref && mode & FMODE_EXCL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 return -EBUSY;
1895
Al Viro60ad2342008-03-02 09:23:54 -05001896 if (mode & FMODE_EXCL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 p->ref = -1;
1898 else
1899 p->ref++;
1900
1901 p->type = type;
1902
Al Viro60ad2342008-03-02 09:23:54 -05001903 if (mode & FMODE_NDELAY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 return 0;
1905
Al Viro60ad2342008-03-02 09:23:54 -05001906 if (mode & (FMODE_READ|FMODE_WRITE)) {
Christoph Hellwig22f97162020-09-08 16:53:31 +02001907 if (bdev_check_media_change(bdev))
1908 floppy_revalidate(bdev->bd_disk);
Al Viro60ad2342008-03-02 09:23:54 -05001909 if (mode & FMODE_WRITE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 if (p->wpstat) {
1911 if (p->ref < 0)
1912 p->ref = 0;
1913 else
1914 p->ref--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 return -EROFS;
1916 }
1917 }
1918 }
1919 return 0;
1920}
1921
Arnd Bergmann6e9624b2010-08-07 18:25:34 +02001922static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
1923{
1924 int ret;
1925
Arnd Bergmann2a48fc02010-06-02 14:28:52 +02001926 mutex_lock(&ataflop_mutex);
Arnd Bergmann6e9624b2010-08-07 18:25:34 +02001927 ret = floppy_open(bdev, mode);
Arnd Bergmann2a48fc02010-06-02 14:28:52 +02001928 mutex_unlock(&ataflop_mutex);
Arnd Bergmann6e9624b2010-08-07 18:25:34 +02001929
1930 return ret;
1931}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Al Virodb2a1442013-05-05 21:52:57 -04001933static void floppy_release(struct gendisk *disk, fmode_t mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934{
Al Viro60ad2342008-03-02 09:23:54 -05001935 struct atari_floppy_struct *p = disk->private_data;
Arnd Bergmann2a48fc02010-06-02 14:28:52 +02001936 mutex_lock(&ataflop_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 if (p->ref < 0)
1938 p->ref = 0;
1939 else if (!p->ref--) {
1940 printk(KERN_ERR "floppy_release with fd_ref == 0");
1941 p->ref = 0;
1942 }
Arnd Bergmann2a48fc02010-06-02 14:28:52 +02001943 mutex_unlock(&ataflop_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944}
1945
Alexey Dobriyan83d5cde2009-09-21 17:01:13 -07001946static const struct block_device_operations floppy_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 .owner = THIS_MODULE,
Arnd Bergmann6e9624b2010-08-07 18:25:34 +02001948 .open = floppy_unlocked_open,
Al Viro60ad2342008-03-02 09:23:54 -05001949 .release = floppy_release,
Arnd Bergmann8a6cfeb2010-07-08 10:18:46 +02001950 .ioctl = fd_ioctl,
Tejun Heo1a8a74f2011-03-09 19:54:27 +01001951 .check_events = floppy_check_events,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952};
1953
Omar Sandoval6ec39382018-10-15 09:18:24 -06001954static const struct blk_mq_ops ataflop_mq_ops = {
1955 .queue_rq = ataflop_queue_rq,
1956};
1957
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001958static int ataflop_alloc_disk(unsigned int drive, unsigned int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959{
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001960 struct gendisk *disk;
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001961
Christoph Hellwigfd71c8a2021-06-02 09:53:44 +03001962 disk = blk_mq_alloc_disk(&unit[drive].tag_set, NULL);
1963 if (IS_ERR(disk))
1964 return PTR_ERR(disk);
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001965
1966 disk->major = FLOPPY_MAJOR;
1967 disk->first_minor = drive + (type << 2);
Christoph Hellwigfd71c8a2021-06-02 09:53:44 +03001968 disk->minors = 1;
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001969 sprintf(disk->disk_name, "fd%d", drive);
1970 disk->fops = &floppy_fops;
1971 disk->events = DISK_EVENT_MEDIA_CHANGE;
1972 disk->private_data = &unit[drive];
1973 set_capacity(disk, MAX_DISK_SIZE * 2);
1974
1975 unit[drive].disk[type] = disk;
1976 return 0;
1977}
1978
1979static DEFINE_MUTEX(ataflop_probe_lock);
1980
1981static void ataflop_probe(dev_t dev)
1982{
1983 int drive = MINOR(dev) & 3;
1984 int type = MINOR(dev) >> 2;
1985
Dan Carpenterb777f4c2021-04-21 13:19:45 +03001986 if (type)
1987 type--;
1988
1989 if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS)
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001990 return;
1991 mutex_lock(&ataflop_probe_lock);
1992 if (!unit[drive].disk[type]) {
Luis Chamberlain573effb2021-09-27 15:03:00 -07001993 if (ataflop_alloc_disk(drive, type) == 0) {
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001994 add_disk(unit[drive].disk[type]);
Luis Chamberlain573effb2021-09-27 15:03:00 -07001995 unit[drive].registered[type] = true;
1996 }
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01001997 }
1998 mutex_unlock(&ataflop_probe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999}
2000
Luis Chamberlaindeae1132021-09-27 15:03:01 -07002001static void atari_cleanup_floppy_disk(struct atari_floppy_struct *fs)
2002{
2003 int type;
2004
2005 for (type = 0; type < NUM_DISK_MINORS; type++) {
2006 if (!fs->disk[type])
2007 continue;
2008 if (fs->registered[type])
2009 del_gendisk(fs->disk[type]);
2010 blk_cleanup_disk(fs->disk[type]);
2011 }
2012 blk_mq_free_tag_set(&fs->tag_set);
2013}
2014
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015static int __init atari_floppy_init (void)
2016{
2017 int i;
Omar Sandoval6ec39382018-10-15 09:18:24 -06002018 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
2020 if (!MACH_IS_ATARI)
2021 /* Amiga, Mac, ... don't have Atari-compatible floppy :-) */
Geert Uytterhoevene945b562008-07-17 21:16:10 +02002022 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01002024 mutex_lock(&ataflop_probe_lock);
2025 ret = __register_blkdev(FLOPPY_MAJOR, "fd", ataflop_probe);
2026 if (ret)
2027 goto out_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029 for (i = 0; i < FD_MAX_UNITS; i++) {
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01002030 memset(&unit[i].tag_set, 0, sizeof(unit[i].tag_set));
2031 unit[i].tag_set.ops = &ataflop_mq_ops;
2032 unit[i].tag_set.nr_hw_queues = 1;
2033 unit[i].tag_set.nr_maps = 1;
2034 unit[i].tag_set.queue_depth = 2;
2035 unit[i].tag_set.numa_node = NUMA_NO_NODE;
2036 unit[i].tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
2037 ret = blk_mq_alloc_tag_set(&unit[i].tag_set);
2038 if (ret)
Omar Sandoval6ec39382018-10-15 09:18:24 -06002039 goto err;
Omar Sandoval71327f52018-10-11 12:20:49 -07002040
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01002041 ret = ataflop_alloc_disk(i, 0);
2042 if (ret) {
2043 blk_mq_free_tag_set(&unit[i].tag_set);
Omar Sandoval6ec39382018-10-15 09:18:24 -06002044 goto err;
2045 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 }
2047
2048 if (UseTrackbuffer < 0)
2049 /* not set by user -> use default: for now, we turn
2050 track buffering off for all Medusas, though it
2051 could be used with ones that have a counter
2052 card. But the test is too hard :-( */
2053 UseTrackbuffer = !MACH_IS_MEDUSA;
2054
2055 /* initialize variables */
2056 SelectedDrive = -1;
2057 BufferDrive = -1;
2058
2059 DMABuffer = atari_stram_alloc(BUFFER_SIZE+512, "ataflop");
2060 if (!DMABuffer) {
2061 printk(KERN_ERR "atari_floppy_init: cannot get dma buffer\n");
Omar Sandoval6ec39382018-10-15 09:18:24 -06002062 ret = -ENOMEM;
2063 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 }
2065 TrackBuffer = DMABuffer + 512;
Michael Schmitza4de73f2014-03-31 21:06:07 +13002066 PhysDMABuffer = atari_stram_to_phys(DMABuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 PhysTrackBuffer = virt_to_phys(TrackBuffer);
2068 BufferDrive = BufferSide = BufferTrack = -1;
2069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 for (i = 0; i < FD_MAX_UNITS; i++) {
2071 unit[i].track = -1;
2072 unit[i].flags = 0;
Luis Chamberlain2f151072021-09-27 15:03:02 -07002073 ret = add_disk(unit[i].disk[0]);
2074 if (ret)
2075 goto err_out_dma;
Luis Chamberlain573effb2021-09-27 15:03:00 -07002076 unit[i].registered[0] = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 }
2078
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 printk(KERN_INFO "Atari floppy driver: max. %cD, %strack buffering\n",
2080 DriveType == 0 ? 'D' : DriveType == 1 ? 'H' : 'E',
2081 UseTrackbuffer ? "" : "no ");
2082 config_types();
2083
2084 return 0;
Omar Sandoval6ec39382018-10-15 09:18:24 -06002085
Luis Chamberlain2f151072021-09-27 15:03:02 -07002086err_out_dma:
2087 atari_stram_free(DMABuffer);
Omar Sandoval6ec39382018-10-15 09:18:24 -06002088err:
Luis Chamberlaindeae1132021-09-27 15:03:01 -07002089 while (--i >= 0)
2090 atari_cleanup_floppy_disk(&unit[i]);
Vivek Goyal639e2f22010-09-24 20:35:45 +02002091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 unregister_blkdev(FLOPPY_MAJOR, "fd");
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01002093out_unlock:
2094 mutex_unlock(&ataflop_probe_lock);
Omar Sandoval6ec39382018-10-15 09:18:24 -06002095 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
Al Viro63907432006-01-12 01:06:36 -08002098#ifndef MODULE
2099static int __init atari_floppy_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100{
Al Viro63907432006-01-12 01:06:36 -08002101 int ints[3 + FD_MAX_UNITS];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 int i;
Al Viro63907432006-01-12 01:06:36 -08002103
2104 if (!MACH_IS_ATARI)
2105 return 0;
2106
2107 str = get_options(str, 3 + FD_MAX_UNITS, ints);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109 if (ints[0] < 1) {
2110 printk(KERN_ERR "ataflop_setup: no arguments!\n" );
Al Viro63907432006-01-12 01:06:36 -08002111 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 }
2113 else if (ints[0] > 2+FD_MAX_UNITS) {
2114 printk(KERN_ERR "ataflop_setup: too many arguments\n" );
2115 }
2116
2117 if (ints[1] < 0 || ints[1] > 2)
2118 printk(KERN_ERR "ataflop_setup: bad drive type\n" );
2119 else
2120 DriveType = ints[1];
2121
2122 if (ints[0] >= 2)
2123 UseTrackbuffer = (ints[2] > 0);
2124
2125 for( i = 3; i <= ints[0] && i-3 < FD_MAX_UNITS; ++i ) {
2126 if (ints[i] != 2 && ints[i] != 3 && ints[i] != 6 && ints[i] != 12)
2127 printk(KERN_ERR "ataflop_setup: bad steprate\n" );
2128 else
2129 UserSteprate[i-3] = ints[i];
2130 }
Al Viro63907432006-01-12 01:06:36 -08002131 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132}
2133
Al Viro63907432006-01-12 01:06:36 -08002134__setup("floppy=", atari_floppy_setup);
2135#endif
2136
2137static void __exit atari_floppy_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
Luis Chamberlaindeae1132021-09-27 15:03:01 -07002139 int i;
Christoph Hellwigbf9c0532020-10-29 15:58:38 +01002140
Luis Chamberlaindeae1132021-09-27 15:03:01 -07002141 for (i = 0; i < FD_MAX_UNITS; i++)
2142 atari_cleanup_floppy_disk(&unit[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 unregister_blkdev(FLOPPY_MAJOR, "fd");
2144
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 del_timer_sync(&fd_timer);
2146 atari_stram_free( DMABuffer );
2147}
2148
2149module_init(atari_floppy_init)
2150module_exit(atari_floppy_exit)
2151
2152MODULE_LICENSE("GPL");