Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/block/floppy.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * Copyright (C) 1993, 1994 Alain Knaff |
| 6 | * Copyright (C) 1998 Alan Cox |
| 7 | */ |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | /* |
| 10 | * 02.12.91 - Changed to static variables to indicate need for reset |
| 11 | * and recalibrate. This makes some things easier (output_byte reset |
| 12 | * checking etc), and means less interrupt jumping in case of errors, |
| 13 | * so the code is hopefully easier to understand. |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * This file is certainly a mess. I've tried my best to get it working, |
| 18 | * but I don't like programming floppies, and I have only one anyway. |
| 19 | * Urgel. I should check for more errors, and do more graceful error |
| 20 | * recovery. Seems there are problems with several drives. I've tried to |
| 21 | * correct them. No promises. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * As with hd.c, all routines within this file can (and will) be called |
| 26 | * by interrupts, so extreme caution is needed. A hardware interrupt |
| 27 | * handler may not sleep, or a kernel panic will happen. Thus I cannot |
| 28 | * call "floppy-on" directly, but have to set a special timer interrupt |
| 29 | * etc. |
| 30 | */ |
| 31 | |
| 32 | /* |
| 33 | * 28.02.92 - made track-buffering routines, based on the routines written |
| 34 | * by entropy@wintermute.wpi.edu (Lawrence Foard). Linus. |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * Automatic floppy-detection and formatting written by Werner Almesberger |
| 39 | * (almesber@nessie.cs.id.ethz.ch), who also corrected some problems with |
| 40 | * the floppy-change signal detection. |
| 41 | */ |
| 42 | |
| 43 | /* |
| 44 | * 1992/7/22 -- Hennus Bergman: Added better error reporting, fixed |
| 45 | * FDC data overrun bug, added some preliminary stuff for vertical |
| 46 | * recording support. |
| 47 | * |
| 48 | * 1992/9/17: Added DMA allocation & DMA functions. -- hhb. |
| 49 | * |
| 50 | * TODO: Errors are still not counted properly. |
| 51 | */ |
| 52 | |
| 53 | /* 1992/9/20 |
| 54 | * Modifications for ``Sector Shifting'' by Rob Hooft (hooft@chem.ruu.nl) |
| 55 | * modeled after the freeware MS-DOS program fdformat/88 V1.8 by |
| 56 | * Christoph H. Hochst\"atter. |
| 57 | * I have fixed the shift values to the ones I always use. Maybe a new |
| 58 | * ioctl() should be created to be able to modify them. |
| 59 | * There is a bug in the driver that makes it impossible to format a |
| 60 | * floppy as the first thing after bootup. |
| 61 | */ |
| 62 | |
| 63 | /* |
| 64 | * 1993/4/29 -- Linus -- cleaned up the timer handling in the kernel, and |
| 65 | * this helped the floppy driver as well. Much cleaner, and still seems to |
| 66 | * work. |
| 67 | */ |
| 68 | |
| 69 | /* 1994/6/24 --bbroad-- added the floppy table entries and made |
| 70 | * minor modifications to allow 2.88 floppies to be run. |
| 71 | */ |
| 72 | |
| 73 | /* 1994/7/13 -- Paul Vojta -- modified the probing code to allow three or more |
| 74 | * disk types. |
| 75 | */ |
| 76 | |
| 77 | /* |
| 78 | * 1994/8/8 -- Alain Knaff -- Switched to fdpatch driver: Support for bigger |
| 79 | * format bug fixes, but unfortunately some new bugs too... |
| 80 | */ |
| 81 | |
| 82 | /* 1994/9/17 -- Koen Holtman -- added logging of physical floppy write |
| 83 | * errors to allow safe writing by specialized programs. |
| 84 | */ |
| 85 | |
| 86 | /* 1995/4/24 -- Dan Fandrich -- added support for Commodore 1581 3.5" disks |
| 87 | * by defining bit 1 of the "stretch" parameter to mean put sectors on the |
| 88 | * opposite side of the disk, leaving the sector IDs alone (i.e. Commodore's |
| 89 | * drives are "upside-down"). |
| 90 | */ |
| 91 | |
| 92 | /* |
| 93 | * 1995/8/26 -- Andreas Busse -- added Mips support. |
| 94 | */ |
| 95 | |
| 96 | /* |
| 97 | * 1995/10/18 -- Ralf Baechle -- Portability cleanup; move machine dependent |
| 98 | * features to asm/floppy.h. |
| 99 | */ |
| 100 | |
| 101 | /* |
James Nelson | b88b098 | 2005-11-08 16:52:12 +0100 | [diff] [blame] | 102 | * 1998/1/21 -- Richard Gooch <rgooch@atnf.csiro.au> -- devfs support |
| 103 | */ |
| 104 | |
| 105 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | * 1998/05/07 -- Russell King -- More portability cleanups; moved definition of |
| 107 | * interrupt and dma channel to asm/floppy.h. Cleaned up some formatting & |
| 108 | * use of '0' for NULL. |
| 109 | */ |
| 110 | |
| 111 | /* |
| 112 | * 1998/06/07 -- Alan Cox -- Merged the 2.0.34 fixes for resource allocation |
| 113 | * failures. |
| 114 | */ |
| 115 | |
| 116 | /* |
| 117 | * 1998/09/20 -- David Weinehall -- Added slow-down code for buggy PS/2-drives. |
| 118 | */ |
| 119 | |
| 120 | /* |
| 121 | * 1999/08/13 -- Paul Slootman -- floppy stopped working on Alpha after 24 |
| 122 | * days, 6 hours, 32 minutes and 32 seconds (i.e. MAXINT jiffies; ints were |
| 123 | * being used to store jiffies, which are unsigned longs). |
| 124 | */ |
| 125 | |
| 126 | /* |
| 127 | * 2000/08/28 -- Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 128 | * - get rid of check_region |
| 129 | * - s/suser/capable/ |
| 130 | */ |
| 131 | |
| 132 | /* |
| 133 | * 2001/08/26 -- Paul Gortmaker - fix insmod oops on machines with no |
| 134 | * floppy controller (lingering task on list after module is gone... boom.) |
| 135 | */ |
| 136 | |
| 137 | /* |
| 138 | * 2002/02/07 -- Anton Altaparmakov - Fix io ports reservation to correct range |
| 139 | * (0x3f2-0x3f5, 0x3f7). This fix is a bit of a hack but the proper fix |
| 140 | * requires many non-obvious changes in arch dependent code. |
| 141 | */ |
| 142 | |
| 143 | /* 2003/07/28 -- Daniele Bellucci <bellucda@tiscali.it>. |
| 144 | * Better audit of register_blkdev. |
| 145 | */ |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #undef FLOPPY_SILENT_DCL_CLEAR |
| 148 | |
| 149 | #define REALLY_SLOW_IO |
| 150 | |
| 151 | #define DEBUGT 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Joe Perches | 891eda8 | 2010-03-10 15:21:05 -0800 | [diff] [blame] | 153 | #define DPRINT(format, args...) \ |
| 154 | pr_info("floppy%d: " format, current_drive, ##args) |
| 155 | |
| 156 | #define DCL_DEBUG /* debug disk change line */ |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 157 | #ifdef DCL_DEBUG |
| 158 | #define debug_dcl(test, fmt, args...) \ |
| 159 | do { if ((test) & FD_DEBUG) DPRINT(fmt, ##args); } while (0) |
| 160 | #else |
| 161 | #define debug_dcl(test, fmt, args...) \ |
| 162 | do { if (0) DPRINT(fmt, ##args); } while (0) |
| 163 | #endif |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /* do print messages for unexpected interrupts */ |
| 166 | static int print_unex = 1; |
| 167 | #include <linux/module.h> |
| 168 | #include <linux/sched.h> |
| 169 | #include <linux/fs.h> |
| 170 | #include <linux/kernel.h> |
| 171 | #include <linux/timer.h> |
| 172 | #include <linux/workqueue.h> |
| 173 | #define FDPATCHES |
| 174 | #include <linux/fdreg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | #include <linux/fd.h> |
| 176 | #include <linux/hdreg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | #include <linux/errno.h> |
| 178 | #include <linux/slab.h> |
| 179 | #include <linux/mm.h> |
| 180 | #include <linux/bio.h> |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 181 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | #include <linux/string.h> |
Marcelo Feitoza Parisi | 50297cb | 2006-03-28 01:56:44 -0800 | [diff] [blame] | 183 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | #include <linux/fcntl.h> |
| 185 | #include <linux/delay.h> |
| 186 | #include <linux/mc146818rtc.h> /* CMOS defines */ |
| 187 | #include <linux/ioport.h> |
| 188 | #include <linux/interrupt.h> |
| 189 | #include <linux/init.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 190 | #include <linux/platform_device.h> |
Scott James Remnant | 83f9ef4 | 2009-04-02 16:56:47 -0700 | [diff] [blame] | 191 | #include <linux/mod_devicetable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | #include <linux/buffer_head.h> /* for invalidate_buffers() */ |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 193 | #include <linux/mutex.h> |
Joe Perches | d493754 | 2010-03-10 15:20:44 -0800 | [diff] [blame] | 194 | #include <linux/io.h> |
| 195 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | /* |
| 198 | * PS/2 floppies have much slower step rates than regular floppies. |
| 199 | * It's been recommended that take about 1/4 of the default speed |
| 200 | * in some more extreme cases. |
| 201 | */ |
| 202 | static int slow_floppy; |
| 203 | |
| 204 | #include <asm/dma.h> |
| 205 | #include <asm/irq.h> |
| 206 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | static int FLOPPY_IRQ = 6; |
| 209 | static int FLOPPY_DMA = 2; |
| 210 | static int can_use_virtual_dma = 2; |
| 211 | /* ======= |
| 212 | * can use virtual DMA: |
| 213 | * 0 = use of virtual DMA disallowed by config |
| 214 | * 1 = use of virtual DMA prescribed by config |
| 215 | * 2 = no virtual DMA preference configured. By default try hard DMA, |
| 216 | * but fall back on virtual DMA when not enough memory available |
| 217 | */ |
| 218 | |
| 219 | static int use_virtual_dma; |
| 220 | /* ======= |
| 221 | * use virtual DMA |
| 222 | * 0 using hard DMA |
| 223 | * 1 using virtual DMA |
| 224 | * This variable is set to virtual when a DMA mem problem arises, and |
| 225 | * reset back in floppy_grab_irq_and_dma. |
| 226 | * It is not safe to reset it in other circumstances, because the floppy |
| 227 | * driver may have several buffers in use at once, and we do currently not |
| 228 | * record each buffers capabilities |
| 229 | */ |
| 230 | |
| 231 | static DEFINE_SPINLOCK(floppy_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | static unsigned short virtual_dma_port = 0x3f0; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 234 | irqreturn_t floppy_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | static int set_dor(int fdc, char mask, char data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | #define K_64 0x10000 /* 64KB */ |
| 238 | |
| 239 | /* the following is the mask of allowed drives. By default units 2 and |
| 240 | * 3 of both floppy controllers are disabled, because switching on the |
| 241 | * motor of these drives causes system hangs on some PCI computers. drive |
| 242 | * 0 is the low bit (0x1), and drive 7 is the high bit (0x80). Bits are on if |
| 243 | * a drive is allowed. |
| 244 | * |
| 245 | * NOTE: This must come before we include the arch floppy header because |
| 246 | * some ports reference this variable from there. -DaveM |
| 247 | */ |
| 248 | |
| 249 | static int allowed_drive_mask = 0x33; |
| 250 | |
| 251 | #include <asm/floppy.h> |
| 252 | |
| 253 | static int irqdma_allocated; |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | #include <linux/blkdev.h> |
| 256 | #include <linux/blkpg.h> |
| 257 | #include <linux/cdrom.h> /* for the compatibility eject ioctl */ |
| 258 | #include <linux/completion.h> |
| 259 | |
| 260 | static struct request *current_req; |
| 261 | static struct request_queue *floppy_queue; |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 262 | static void do_fd_request(struct request_queue *q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | #ifndef fd_get_dma_residue |
| 265 | #define fd_get_dma_residue() get_dma_residue(FLOPPY_DMA) |
| 266 | #endif |
| 267 | |
| 268 | /* Dma Memory related stuff */ |
| 269 | |
| 270 | #ifndef fd_dma_mem_free |
| 271 | #define fd_dma_mem_free(addr, size) free_pages(addr, get_order(size)) |
| 272 | #endif |
| 273 | |
| 274 | #ifndef fd_dma_mem_alloc |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 275 | #define fd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL, get_order(size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | #endif |
| 277 | |
| 278 | static inline void fallback_on_nodma_alloc(char **addr, size_t l) |
| 279 | { |
| 280 | #ifdef FLOPPY_CAN_FALLBACK_ON_NODMA |
| 281 | if (*addr) |
| 282 | return; /* we have the memory */ |
| 283 | if (can_use_virtual_dma != 2) |
| 284 | return; /* no fallback allowed */ |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 285 | pr_info("DMA memory shortage. Temporarily falling back on virtual DMA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | *addr = (char *)nodma_mem_alloc(l); |
| 287 | #else |
| 288 | return; |
| 289 | #endif |
| 290 | } |
| 291 | |
| 292 | /* End dma memory related stuff */ |
| 293 | |
| 294 | static unsigned long fake_change; |
Joe Perches | 29f1c78 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 295 | static bool initialized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 297 | #define ITYPE(x) (((x) >> 2) & 0x1f) |
| 298 | #define TOMINOR(x) ((x & 3) | ((x & 4) << 5)) |
| 299 | #define UNIT(x) ((x) & 0x03) /* drive on fdc */ |
| 300 | #define FDC(x) (((x) & 0x04) >> 2) /* fdc of drive */ |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 301 | /* reverse mapping from unit and fdc to drive */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | #define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 304 | #define DP (&drive_params[current_drive]) |
| 305 | #define DRS (&drive_state[current_drive]) |
| 306 | #define DRWE (&write_errors[current_drive]) |
| 307 | #define FDCS (&fdc_state[fdc]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 309 | #define UDP (&drive_params[drive]) |
| 310 | #define UDRS (&drive_state[drive]) |
| 311 | #define UDRWE (&write_errors[drive]) |
| 312 | #define UFDCS (&fdc_state[FDC(drive)]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 314 | #define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2) |
| 315 | #define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH) |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | /* read/write */ |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 318 | #define COMMAND (raw_cmd->cmd[0]) |
| 319 | #define DR_SELECT (raw_cmd->cmd[1]) |
| 320 | #define TRACK (raw_cmd->cmd[2]) |
| 321 | #define HEAD (raw_cmd->cmd[3]) |
| 322 | #define SECTOR (raw_cmd->cmd[4]) |
| 323 | #define SIZECODE (raw_cmd->cmd[5]) |
| 324 | #define SECT_PER_TRACK (raw_cmd->cmd[6]) |
| 325 | #define GAP (raw_cmd->cmd[7]) |
| 326 | #define SIZECODE2 (raw_cmd->cmd[8]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | #define NR_RW 9 |
| 328 | |
| 329 | /* format */ |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 330 | #define F_SIZECODE (raw_cmd->cmd[2]) |
| 331 | #define F_SECT_PER_TRACK (raw_cmd->cmd[3]) |
| 332 | #define F_GAP (raw_cmd->cmd[4]) |
| 333 | #define F_FILL (raw_cmd->cmd[5]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | #define NR_F 6 |
| 335 | |
| 336 | /* |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 337 | * Maximum disk size (in kilobytes). |
| 338 | * This default is used whenever the current disk size is unknown. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | * [Now it is rather a minimum] |
| 340 | */ |
| 341 | #define MAX_DISK_SIZE 4 /* 3984 */ |
| 342 | |
| 343 | /* |
| 344 | * globals used by 'result()' |
| 345 | */ |
| 346 | #define MAX_REPLIES 16 |
| 347 | static unsigned char reply_buffer[MAX_REPLIES]; |
Joe Perches | 891eda8 | 2010-03-10 15:21:05 -0800 | [diff] [blame] | 348 | static int inr; /* size of reply buffer, when called from interrupt */ |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 349 | #define ST0 (reply_buffer[0]) |
| 350 | #define ST1 (reply_buffer[1]) |
| 351 | #define ST2 (reply_buffer[2]) |
| 352 | #define ST3 (reply_buffer[0]) /* result of GETSTATUS */ |
| 353 | #define R_TRACK (reply_buffer[3]) |
| 354 | #define R_HEAD (reply_buffer[4]) |
| 355 | #define R_SECTOR (reply_buffer[5]) |
| 356 | #define R_SIZECODE (reply_buffer[6]) |
| 357 | |
| 358 | #define SEL_DLY (2 * HZ / 100) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | /* |
| 361 | * this struct defines the different floppy drive types. |
| 362 | */ |
| 363 | static struct { |
| 364 | struct floppy_drive_params params; |
| 365 | const char *name; /* name printed while booting */ |
| 366 | } default_drive_params[] = { |
| 367 | /* NOTE: the time values in jiffies should be in msec! |
| 368 | CMOS drive type |
| 369 | | Maximum data rate supported by drive type |
| 370 | | | Head load time, msec |
| 371 | | | | Head unload time, msec (not used) |
| 372 | | | | | Step rate interval, usec |
| 373 | | | | | | Time needed for spinup time (jiffies) |
| 374 | | | | | | | Timeout for spinning down (jiffies) |
| 375 | | | | | | | | Spindown offset (where disk stops) |
| 376 | | | | | | | | | Select delay |
| 377 | | | | | | | | | | RPS |
| 378 | | | | | | | | | | | Max number of tracks |
| 379 | | | | | | | | | | | | Interrupt timeout |
| 380 | | | | | | | | | | | | | Max nonintlv. sectors |
| 381 | | | | | | | | | | | | | | -Max Errors- flags */ |
| 382 | {{0, 500, 16, 16, 8000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 80, 3*HZ, 20, {3,1,2,0,2}, 0, |
| 383 | 0, { 7, 4, 8, 2, 1, 5, 3,10}, 3*HZ/2, 0 }, "unknown" }, |
| 384 | |
| 385 | {{1, 300, 16, 16, 8000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 40, 3*HZ, 17, {3,1,2,0,2}, 0, |
| 386 | 0, { 1, 0, 0, 0, 0, 0, 0, 0}, 3*HZ/2, 1 }, "360K PC" }, /*5 1/4 360 KB PC*/ |
| 387 | |
| 388 | {{2, 500, 16, 16, 6000, 4*HZ/10, 3*HZ, 14, SEL_DLY, 6, 83, 3*HZ, 17, {3,1,2,0,2}, 0, |
| 389 | 0, { 2, 5, 6,23,10,20,12, 0}, 3*HZ/2, 2 }, "1.2M" }, /*5 1/4 HD AT*/ |
| 390 | |
| 391 | {{3, 250, 16, 16, 3000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 83, 3*HZ, 20, {3,1,2,0,2}, 0, |
| 392 | 0, { 4,22,21,30, 3, 0, 0, 0}, 3*HZ/2, 4 }, "720k" }, /*3 1/2 DD*/ |
| 393 | |
| 394 | {{4, 500, 16, 16, 4000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 20, {3,1,2,0,2}, 0, |
| 395 | 0, { 7, 4,25,22,31,21,29,11}, 3*HZ/2, 7 }, "1.44M" }, /*3 1/2 HD*/ |
| 396 | |
| 397 | {{5, 1000, 15, 8, 3000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 40, {3,1,2,0,2}, 0, |
| 398 | 0, { 7, 8, 4,25,28,22,31,21}, 3*HZ/2, 8 }, "2.88M AMI BIOS" }, /*3 1/2 ED*/ |
| 399 | |
| 400 | {{6, 1000, 15, 8, 3000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 40, {3,1,2,0,2}, 0, |
| 401 | 0, { 7, 8, 4,25,28,22,31,21}, 3*HZ/2, 8 }, "2.88M" } /*3 1/2 ED*/ |
| 402 | /* | --autodetected formats--- | | | |
| 403 | * read_track | | Name printed when booting |
| 404 | * | Native format |
| 405 | * Frequency of disk change checks */ |
| 406 | }; |
| 407 | |
| 408 | static struct floppy_drive_params drive_params[N_DRIVE]; |
| 409 | static struct floppy_drive_struct drive_state[N_DRIVE]; |
| 410 | static struct floppy_write_errors write_errors[N_DRIVE]; |
| 411 | static struct timer_list motor_off_timer[N_DRIVE]; |
| 412 | static struct gendisk *disks[N_DRIVE]; |
| 413 | static struct block_device *opened_bdev[N_DRIVE]; |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 414 | static DEFINE_MUTEX(open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | static struct floppy_raw_cmd *raw_cmd, default_raw_cmd; |
| 416 | |
| 417 | /* |
| 418 | * This struct defines the different floppy types. |
| 419 | * |
| 420 | * Bit 0 of 'stretch' tells if the tracks need to be doubled for some |
| 421 | * types (e.g. 360kB diskette in 1.2MB drive, etc.). Bit 1 of 'stretch' |
| 422 | * tells if the disk is in Commodore 1581 format, which means side 0 sectors |
| 423 | * are located on side 1 of the disk but with a side 0 ID, and vice-versa. |
| 424 | * This is the same as the Sharp MZ-80 5.25" CP/M disk format, except that the |
| 425 | * 1581's logical side 0 is on physical side 1, whereas the Sharp's logical |
| 426 | * side 0 is on physical side 0 (but with the misnamed sector IDs). |
| 427 | * 'stretch' should probably be renamed to something more general, like |
Keith Wansbrough | 9e49184 | 2008-09-22 14:57:17 -0700 | [diff] [blame] | 428 | * 'options'. |
| 429 | * |
| 430 | * Bits 2 through 9 of 'stretch' tell the number of the first sector. |
| 431 | * The LSB (bit 2) is flipped. For most disks, the first sector |
| 432 | * is 1 (represented by 0x00<<2). For some CP/M and music sampler |
| 433 | * disks (such as Ensoniq EPS 16plus) it is 0 (represented as 0x01<<2). |
| 434 | * For Amstrad CPC disks it is 0xC1 (represented as 0xC0<<2). |
| 435 | * |
| 436 | * Other parameters should be self-explanatory (see also setfdprm(8)). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | */ |
| 438 | /* |
| 439 | Size |
| 440 | | Sectors per track |
| 441 | | | Head |
| 442 | | | | Tracks |
| 443 | | | | | Stretch |
| 444 | | | | | | Gap 1 size |
| 445 | | | | | | | Data rate, | 0x40 for perp |
| 446 | | | | | | | | Spec1 (stepping rate, head unload |
| 447 | | | | | | | | | /fmt gap (gap2) */ |
| 448 | static struct floppy_struct floppy_type[32] = { |
| 449 | { 0, 0,0, 0,0,0x00,0x00,0x00,0x00,NULL }, /* 0 no testing */ |
| 450 | { 720, 9,2,40,0,0x2A,0x02,0xDF,0x50,"d360" }, /* 1 360KB PC */ |
| 451 | { 2400,15,2,80,0,0x1B,0x00,0xDF,0x54,"h1200" }, /* 2 1.2MB AT */ |
| 452 | { 720, 9,1,80,0,0x2A,0x02,0xDF,0x50,"D360" }, /* 3 360KB SS 3.5" */ |
| 453 | { 1440, 9,2,80,0,0x2A,0x02,0xDF,0x50,"D720" }, /* 4 720KB 3.5" */ |
| 454 | { 720, 9,2,40,1,0x23,0x01,0xDF,0x50,"h360" }, /* 5 360KB AT */ |
| 455 | { 1440, 9,2,80,0,0x23,0x01,0xDF,0x50,"h720" }, /* 6 720KB AT */ |
| 456 | { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,"H1440" }, /* 7 1.44MB 3.5" */ |
| 457 | { 5760,36,2,80,0,0x1B,0x43,0xAF,0x54,"E2880" }, /* 8 2.88MB 3.5" */ |
| 458 | { 6240,39,2,80,0,0x1B,0x43,0xAF,0x28,"E3120" }, /* 9 3.12MB 3.5" */ |
| 459 | |
| 460 | { 2880,18,2,80,0,0x25,0x00,0xDF,0x02,"h1440" }, /* 10 1.44MB 5.25" */ |
| 461 | { 3360,21,2,80,0,0x1C,0x00,0xCF,0x0C,"H1680" }, /* 11 1.68MB 3.5" */ |
| 462 | { 820,10,2,41,1,0x25,0x01,0xDF,0x2E,"h410" }, /* 12 410KB 5.25" */ |
| 463 | { 1640,10,2,82,0,0x25,0x02,0xDF,0x2E,"H820" }, /* 13 820KB 3.5" */ |
| 464 | { 2952,18,2,82,0,0x25,0x00,0xDF,0x02,"h1476" }, /* 14 1.48MB 5.25" */ |
| 465 | { 3444,21,2,82,0,0x25,0x00,0xDF,0x0C,"H1722" }, /* 15 1.72MB 3.5" */ |
| 466 | { 840,10,2,42,1,0x25,0x01,0xDF,0x2E,"h420" }, /* 16 420KB 5.25" */ |
| 467 | { 1660,10,2,83,0,0x25,0x02,0xDF,0x2E,"H830" }, /* 17 830KB 3.5" */ |
| 468 | { 2988,18,2,83,0,0x25,0x00,0xDF,0x02,"h1494" }, /* 18 1.49MB 5.25" */ |
| 469 | { 3486,21,2,83,0,0x25,0x00,0xDF,0x0C,"H1743" }, /* 19 1.74 MB 3.5" */ |
| 470 | |
| 471 | { 1760,11,2,80,0,0x1C,0x09,0xCF,0x00,"h880" }, /* 20 880KB 5.25" */ |
| 472 | { 2080,13,2,80,0,0x1C,0x01,0xCF,0x00,"D1040" }, /* 21 1.04MB 3.5" */ |
| 473 | { 2240,14,2,80,0,0x1C,0x19,0xCF,0x00,"D1120" }, /* 22 1.12MB 3.5" */ |
| 474 | { 3200,20,2,80,0,0x1C,0x20,0xCF,0x2C,"h1600" }, /* 23 1.6MB 5.25" */ |
| 475 | { 3520,22,2,80,0,0x1C,0x08,0xCF,0x2e,"H1760" }, /* 24 1.76MB 3.5" */ |
| 476 | { 3840,24,2,80,0,0x1C,0x20,0xCF,0x00,"H1920" }, /* 25 1.92MB 3.5" */ |
| 477 | { 6400,40,2,80,0,0x25,0x5B,0xCF,0x00,"E3200" }, /* 26 3.20MB 3.5" */ |
| 478 | { 7040,44,2,80,0,0x25,0x5B,0xCF,0x00,"E3520" }, /* 27 3.52MB 3.5" */ |
| 479 | { 7680,48,2,80,0,0x25,0x63,0xCF,0x00,"E3840" }, /* 28 3.84MB 3.5" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { 3680,23,2,80,0,0x1C,0x10,0xCF,0x00,"H1840" }, /* 29 1.84MB 3.5" */ |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { 1600,10,2,80,0,0x25,0x02,0xDF,0x2E,"D800" }, /* 30 800KB 3.5" */ |
| 483 | { 3200,20,2,80,0,0x1C,0x00,0xCF,0x2C,"H1600" }, /* 31 1.6MB 3.5" */ |
| 484 | }; |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | #define SECTSIZE (_FD_SECTSIZE(*floppy)) |
| 487 | |
| 488 | /* Auto-detection: Disk type used until the next media change occurs. */ |
| 489 | static struct floppy_struct *current_type[N_DRIVE]; |
| 490 | |
| 491 | /* |
| 492 | * User-provided type information. current_type points to |
| 493 | * the respective entry of this array. |
| 494 | */ |
| 495 | static struct floppy_struct user_params[N_DRIVE]; |
| 496 | |
| 497 | static sector_t floppy_sizes[256]; |
| 498 | |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 499 | static char floppy_device_name[] = "floppy"; |
| 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | /* |
| 502 | * The driver is trying to determine the correct media format |
| 503 | * while probing is set. rw_interrupt() clears it after a |
| 504 | * successful access. |
| 505 | */ |
| 506 | static int probing; |
| 507 | |
| 508 | /* Synchronization of FDC access. */ |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 509 | #define FD_COMMAND_NONE -1 |
| 510 | #define FD_COMMAND_ERROR 2 |
| 511 | #define FD_COMMAND_OKAY 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | static volatile int command_status = FD_COMMAND_NONE; |
| 514 | static unsigned long fdc_busy; |
| 515 | static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); |
| 516 | static DECLARE_WAIT_QUEUE_HEAD(command_done); |
| 517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | /* Errors during formatting are counted here. */ |
| 519 | static int format_errors; |
| 520 | |
| 521 | /* Format request descriptor. */ |
| 522 | static struct format_descr format_req; |
| 523 | |
| 524 | /* |
| 525 | * Rate is 0 for 500kb/s, 1 for 300kbps, 2 for 250kbps |
| 526 | * Spec1 is 0xSH, where S is stepping rate (F=1ms, E=2ms, D=3ms etc), |
| 527 | * H is head unload time (1=16ms, 2=32ms, etc) |
| 528 | */ |
| 529 | |
| 530 | /* |
| 531 | * Track buffer |
| 532 | * Because these are written to by the DMA controller, they must |
| 533 | * not contain a 64k byte boundary crossing, or data will be |
| 534 | * corrupted/lost. |
| 535 | */ |
| 536 | static char *floppy_track_buffer; |
| 537 | static int max_buffer_sectors; |
| 538 | |
| 539 | static int *errors; |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 540 | typedef void (*done_f)(int); |
Stephen Hemminger | 3b06c21 | 2010-07-20 20:09:00 -0600 | [diff] [blame] | 541 | static const struct cont_t { |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 542 | void (*interrupt)(void); |
| 543 | /* this is called after the interrupt of the |
| 544 | * main command */ |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 545 | void (*redo)(void); /* this is called to retry the operation */ |
| 546 | void (*error)(void); /* this is called to tally an error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | done_f done; /* this is called to say if the operation has |
| 548 | * succeeded/failed */ |
| 549 | } *cont; |
| 550 | |
| 551 | static void floppy_ready(void); |
| 552 | static void floppy_start(void); |
| 553 | static void process_fd_request(void); |
| 554 | static void recalibrate_floppy(void); |
| 555 | static void floppy_shutdown(unsigned long); |
| 556 | |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 557 | static int floppy_request_regions(int); |
| 558 | static void floppy_release_regions(int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | static int floppy_grab_irq_and_dma(void); |
| 560 | static void floppy_release_irq_and_dma(void); |
| 561 | |
| 562 | /* |
| 563 | * The "reset" variable should be tested whenever an interrupt is scheduled, |
| 564 | * after the commands have been sent. This is to ensure that the driver doesn't |
| 565 | * get wedged when the interrupt doesn't come because of a failed command. |
| 566 | * reset doesn't need to be tested before sending commands, because |
| 567 | * output_byte is automatically disabled when reset is set. |
| 568 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | static void reset_fdc(void); |
| 570 | |
| 571 | /* |
| 572 | * These are global variables, as that's the easiest way to give |
| 573 | * information to interrupts. They are the data used for the current |
| 574 | * request. |
| 575 | */ |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 576 | #define NO_TRACK -1 |
| 577 | #define NEED_1_RECAL -2 |
| 578 | #define NEED_2_RECAL -3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 580 | static atomic_t usage_count = ATOMIC_INIT(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | /* buffer related variables */ |
| 583 | static int buffer_track = -1; |
| 584 | static int buffer_drive = -1; |
| 585 | static int buffer_min = -1; |
| 586 | static int buffer_max = -1; |
| 587 | |
| 588 | /* fdc related variables, should end up in a struct */ |
| 589 | static struct floppy_fdc_state fdc_state[N_FDC]; |
| 590 | static int fdc; /* current fdc */ |
| 591 | |
| 592 | static struct floppy_struct *_floppy = floppy_type; |
| 593 | static unsigned char current_drive; |
| 594 | static long current_count_sectors; |
| 595 | static unsigned char fsector_t; /* sector in track */ |
| 596 | static unsigned char in_sector_offset; /* offset within physical sector, |
| 597 | * expressed in units of 512 bytes */ |
| 598 | |
| 599 | #ifndef fd_eject |
| 600 | static inline int fd_eject(int drive) |
| 601 | { |
| 602 | return -EINVAL; |
| 603 | } |
| 604 | #endif |
| 605 | |
| 606 | /* |
| 607 | * Debugging |
| 608 | * ========= |
| 609 | */ |
| 610 | #ifdef DEBUGT |
| 611 | static long unsigned debugtimer; |
| 612 | |
| 613 | static inline void set_debugt(void) |
| 614 | { |
| 615 | debugtimer = jiffies; |
| 616 | } |
| 617 | |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 618 | static inline void debugt(const char *func, const char *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
| 620 | if (DP->flags & DEBUGT) |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 621 | pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | #else |
| 624 | static inline void set_debugt(void) { } |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 625 | static inline void debugt(const char *func, const char *msg) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | #endif /* DEBUGT */ |
| 627 | |
Joe Perches | a0a52d6 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 628 | typedef void (*timeout_fn)(unsigned long); |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 629 | static DEFINE_TIMER(fd_timeout, floppy_shutdown, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | |
| 631 | static const char *timeout_message; |
| 632 | |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 633 | static void is_alive(const char *func, const char *message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
| 635 | /* this routine checks whether the floppy driver is "alive" */ |
Joe Perches | c529730 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 636 | if (test_bit(0, &fdc_busy) && command_status < 2 && |
| 637 | !timer_pending(&fd_timeout)) { |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 638 | DPRINT("%s: timeout handler died. %s\n", func, message); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 642 | static void (*do_floppy)(void) = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | #define OLOGSIZE 20 |
| 645 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 646 | static void (*lasthandler)(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | static unsigned long interruptjiffies; |
| 648 | static unsigned long resultjiffies; |
| 649 | static int resultsize; |
| 650 | static unsigned long lastredo; |
| 651 | |
| 652 | static struct output_log { |
| 653 | unsigned char data; |
| 654 | unsigned char status; |
| 655 | unsigned long jiffies; |
| 656 | } output_log[OLOGSIZE]; |
| 657 | |
| 658 | static int output_log_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | #define current_reqD -1 |
| 661 | #define MAXTIMEOUT -2 |
| 662 | |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 663 | static void __reschedule_timeout(int drive, const char *message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { |
| 665 | if (drive == current_reqD) |
| 666 | drive = current_drive; |
| 667 | del_timer(&fd_timeout); |
Eric Sesterhenn / Snakebyte | 4acb3e2 | 2007-05-23 13:58:15 -0700 | [diff] [blame] | 668 | if (drive < 0 || drive >= N_DRIVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | fd_timeout.expires = jiffies + 20UL * HZ; |
| 670 | drive = 0; |
| 671 | } else |
| 672 | fd_timeout.expires = jiffies + UDP->timeout; |
| 673 | add_timer(&fd_timeout); |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 674 | if (UDP->flags & FD_DEBUG) |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 675 | DPRINT("reschedule timeout %s\n", message); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | timeout_message = message; |
| 677 | } |
| 678 | |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 679 | static void reschedule_timeout(int drive, const char *message) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
| 681 | unsigned long flags; |
| 682 | |
| 683 | spin_lock_irqsave(&floppy_lock, flags); |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 684 | __reschedule_timeout(drive, message); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | spin_unlock_irqrestore(&floppy_lock, flags); |
| 686 | } |
| 687 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 688 | #define INFBOUND(a, b) (a) = max_t(int, a, b) |
| 689 | #define SUPBOUND(a, b) (a) = min_t(int, a, b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
| 691 | /* |
| 692 | * Bottom half floppy driver. |
| 693 | * ========================== |
| 694 | * |
| 695 | * This part of the file contains the code talking directly to the hardware, |
| 696 | * and also the main service loop (seek-configure-spinup-command) |
| 697 | */ |
| 698 | |
| 699 | /* |
| 700 | * disk change. |
| 701 | * This routine is responsible for maintaining the FD_DISK_CHANGE flag, |
| 702 | * and the last_checked date. |
| 703 | * |
| 704 | * last_checked is the date of the last check which showed 'no disk change' |
| 705 | * FD_DISK_CHANGE is set under two conditions: |
| 706 | * 1. The floppy has been changed after some i/o to that floppy already |
| 707 | * took place. |
| 708 | * 2. No floppy disk is in the drive. This is done in order to ensure that |
| 709 | * requests are quickly flushed in case there is no disk in the drive. It |
| 710 | * follows that FD_DISK_CHANGE can only be cleared if there is a disk in |
| 711 | * the drive. |
| 712 | * |
| 713 | * For 1., maxblock is observed. Maxblock is 0 if no i/o has taken place yet. |
| 714 | * For 2., FD_DISK_NEWCHANGE is watched. FD_DISK_NEWCHANGE is cleared on |
| 715 | * each seek. If a disk is present, the disk change line should also be |
| 716 | * cleared on each seek. Thus, if FD_DISK_NEWCHANGE is clear, but the disk |
| 717 | * change line is set, this means either that no disk is in the drive, or |
| 718 | * that it has been removed since the last seek. |
| 719 | * |
| 720 | * This means that we really have a third possibility too: |
| 721 | * The floppy has been changed after the last seek. |
| 722 | */ |
| 723 | |
| 724 | static int disk_change(int drive) |
| 725 | { |
| 726 | int fdc = FDC(drive); |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 727 | |
Marcelo Feitoza Parisi | 50297cb | 2006-03-28 01:56:44 -0800 | [diff] [blame] | 728 | if (time_before(jiffies, UDRS->select_date + UDP->select_delay)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | DPRINT("WARNING disk change called early\n"); |
| 730 | if (!(FDCS->dor & (0x10 << UNIT(drive))) || |
| 731 | (FDCS->dor & 3) != UNIT(drive) || fdc != FDC(drive)) { |
| 732 | DPRINT("probing disk change on unselected drive\n"); |
| 733 | DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive), |
| 734 | (unsigned int)FDCS->dor); |
| 735 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 737 | debug_dcl(UDP->flags, |
| 738 | "checking disk change line for drive %d\n", drive); |
| 739 | debug_dcl(UDP->flags, "jiffies=%lu\n", jiffies); |
| 740 | debug_dcl(UDP->flags, "disk change line=%x\n", fd_inb(FD_DIR) & 0x80); |
| 741 | debug_dcl(UDP->flags, "flags=%lx\n", UDRS->flags); |
| 742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | if (UDP->flags & FD_BROKEN_DCL) |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 744 | return test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | if ((fd_inb(FD_DIR) ^ UDP->flags) & 0x80) { |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 746 | set_bit(FD_VERIFY_BIT, &UDRS->flags); |
| 747 | /* verify write protection */ |
| 748 | |
| 749 | if (UDRS->maxblock) /* mark it changed */ |
| 750 | set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
| 752 | /* invalidate its geometry */ |
| 753 | if (UDRS->keep_data >= 0) { |
| 754 | if ((UDP->flags & FTD_MSG) && |
| 755 | current_type[drive] != NULL) |
Joe Perches | 891eda8 | 2010-03-10 15:21:05 -0800 | [diff] [blame] | 756 | DPRINT("Disk type is undefined after disk change\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | current_type[drive] = NULL; |
| 758 | floppy_sizes[TOMINOR(drive)] = MAX_DISK_SIZE << 1; |
| 759 | } |
| 760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | return 1; |
| 762 | } else { |
| 763 | UDRS->last_checked = jiffies; |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 764 | clear_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | static inline int is_selected(int dor, int unit) |
| 770 | { |
| 771 | return ((dor & (0x10 << unit)) && (dor & 3) == unit); |
| 772 | } |
| 773 | |
Joe Perches | 57584c5 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 774 | static bool is_ready_state(int status) |
| 775 | { |
| 776 | int state = status & (STATUS_READY | STATUS_DIR | STATUS_DMA); |
| 777 | return state == STATUS_READY; |
| 778 | } |
| 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | static int set_dor(int fdc, char mask, char data) |
| 781 | { |
Jesper Juhl | fdc1ca8 | 2007-10-16 23:30:58 -0700 | [diff] [blame] | 782 | unsigned char unit; |
| 783 | unsigned char drive; |
| 784 | unsigned char newdor; |
| 785 | unsigned char olddor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | if (FDCS->address == -1) |
| 788 | return -1; |
| 789 | |
| 790 | olddor = FDCS->dor; |
| 791 | newdor = (olddor & mask) | data; |
| 792 | if (newdor != olddor) { |
| 793 | unit = olddor & 0x3; |
| 794 | if (is_selected(olddor, unit) && !is_selected(newdor, unit)) { |
| 795 | drive = REVDRIVE(fdc, unit); |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 796 | debug_dcl(UDP->flags, |
| 797 | "calling disk change from set_dor\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | disk_change(drive); |
| 799 | } |
| 800 | FDCS->dor = newdor; |
| 801 | fd_outb(newdor, FD_DOR); |
| 802 | |
| 803 | unit = newdor & 0x3; |
| 804 | if (!is_selected(olddor, unit) && is_selected(newdor, unit)) { |
| 805 | drive = REVDRIVE(fdc, unit); |
| 806 | UDRS->select_date = jiffies; |
| 807 | } |
| 808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | return olddor; |
| 810 | } |
| 811 | |
| 812 | static void twaddle(void) |
| 813 | { |
| 814 | if (DP->select_delay) |
| 815 | return; |
| 816 | fd_outb(FDCS->dor & ~(0x10 << UNIT(current_drive)), FD_DOR); |
| 817 | fd_outb(FDCS->dor, FD_DOR); |
| 818 | DRS->select_date = jiffies; |
| 819 | } |
| 820 | |
Joe Perches | 57584c5 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 821 | /* |
| 822 | * Reset all driver information about the current fdc. |
| 823 | * This is needed after a reset, and after a raw command. |
| 824 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | static void reset_fdc_info(int mode) |
| 826 | { |
| 827 | int drive; |
| 828 | |
| 829 | FDCS->spec1 = FDCS->spec2 = -1; |
| 830 | FDCS->need_configure = 1; |
| 831 | FDCS->perp_mode = 1; |
| 832 | FDCS->rawcmd = 0; |
| 833 | for (drive = 0; drive < N_DRIVE; drive++) |
| 834 | if (FDC(drive) == fdc && (mode || UDRS->track != NEED_1_RECAL)) |
| 835 | UDRS->track = NEED_2_RECAL; |
| 836 | } |
| 837 | |
| 838 | /* selects the fdc and drive, and enables the fdc's input/dma. */ |
| 839 | static void set_fdc(int drive) |
| 840 | { |
| 841 | if (drive >= 0 && drive < N_DRIVE) { |
| 842 | fdc = FDC(drive); |
| 843 | current_drive = drive; |
| 844 | } |
| 845 | if (fdc != 1 && fdc != 0) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 846 | pr_info("bad fdc value\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | return; |
| 848 | } |
| 849 | set_dor(fdc, ~0, 8); |
| 850 | #if N_FDC > 1 |
| 851 | set_dor(1 - fdc, ~8, 0); |
| 852 | #endif |
| 853 | if (FDCS->rawcmd == 2) |
| 854 | reset_fdc_info(1); |
| 855 | if (fd_inb(FD_STATUS) != STATUS_READY) |
| 856 | FDCS->reset = 1; |
| 857 | } |
| 858 | |
| 859 | /* locks the driver */ |
Stephen Hemminger | b862f26 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 860 | static int lock_fdc(int drive, bool interruptible) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | { |
Stephen Hemminger | b862f26 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 862 | if (WARN(atomic_read(&usage_count) == 0, |
| 863 | "Trying to lock fdc while usage count=0\n")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
Stephen Hemminger | b862f26 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 866 | if (wait_event_interruptible(fdc_wait, !test_and_set_bit(0, &fdc_busy))) |
| 867 | return -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | command_status = FD_COMMAND_NONE; |
| 870 | |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 871 | __reschedule_timeout(drive, "lock fdc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | set_fdc(drive); |
| 873 | return 0; |
| 874 | } |
| 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | /* unlocks the driver */ |
Stephen Hemminger | be7a12b | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 877 | static void unlock_fdc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { |
| 879 | unsigned long flags; |
| 880 | |
| 881 | raw_cmd = NULL; |
| 882 | if (!test_bit(0, &fdc_busy)) |
| 883 | DPRINT("FDC access conflict!\n"); |
| 884 | |
| 885 | if (do_floppy) |
Joe Perches | 1ebddd8 | 2010-03-10 15:21:07 -0800 | [diff] [blame] | 886 | DPRINT("device interrupt still active at FDC release: %pf!\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | do_floppy); |
| 888 | command_status = FD_COMMAND_NONE; |
| 889 | spin_lock_irqsave(&floppy_lock, flags); |
| 890 | del_timer(&fd_timeout); |
| 891 | cont = NULL; |
| 892 | clear_bit(0, &fdc_busy); |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 893 | if (current_req || blk_peek_request(floppy_queue)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | do_fd_request(floppy_queue); |
| 895 | spin_unlock_irqrestore(&floppy_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | wake_up(&fdc_wait); |
| 897 | } |
| 898 | |
| 899 | /* switches the motor off after a given timeout */ |
| 900 | static void motor_off_callback(unsigned long nr) |
| 901 | { |
| 902 | unsigned char mask = ~(0x10 << UNIT(nr)); |
| 903 | |
| 904 | set_dor(FDC(nr), mask, 0); |
| 905 | } |
| 906 | |
| 907 | /* schedules motor off */ |
| 908 | static void floppy_off(unsigned int drive) |
| 909 | { |
| 910 | unsigned long volatile delta; |
Jesper Juhl | fdc1ca8 | 2007-10-16 23:30:58 -0700 | [diff] [blame] | 911 | int fdc = FDC(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | if (!(FDCS->dor & (0x10 << UNIT(drive)))) |
| 914 | return; |
| 915 | |
| 916 | del_timer(motor_off_timer + drive); |
| 917 | |
| 918 | /* make spindle stop in a position which minimizes spinup time |
| 919 | * next time */ |
| 920 | if (UDP->rps) { |
| 921 | delta = jiffies - UDRS->first_read_date + HZ - |
| 922 | UDP->spindown_offset; |
| 923 | delta = ((delta * UDP->rps) % HZ) / UDP->rps; |
| 924 | motor_off_timer[drive].expires = |
| 925 | jiffies + UDP->spindown - delta; |
| 926 | } |
| 927 | add_timer(motor_off_timer + drive); |
| 928 | } |
| 929 | |
| 930 | /* |
| 931 | * cycle through all N_DRIVE floppy drives, for disk change testing. |
| 932 | * stopping at current drive. This is done before any long operation, to |
| 933 | * be sure to have up to date disk change information. |
| 934 | */ |
| 935 | static void scandrives(void) |
| 936 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 937 | int i; |
| 938 | int drive; |
| 939 | int saved_drive; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
| 941 | if (DP->select_delay) |
| 942 | return; |
| 943 | |
| 944 | saved_drive = current_drive; |
| 945 | for (i = 0; i < N_DRIVE; i++) { |
| 946 | drive = (saved_drive + i + 1) % N_DRIVE; |
| 947 | if (UDRS->fd_ref == 0 || UDP->select_delay != 0) |
| 948 | continue; /* skip closed drives */ |
| 949 | set_fdc(drive); |
| 950 | if (!(set_dor(fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) & |
| 951 | (0x10 << UNIT(drive)))) |
| 952 | /* switch the motor off again, if it was off to |
| 953 | * begin with */ |
| 954 | set_dor(fdc, ~(0x10 << UNIT(drive)), 0); |
| 955 | } |
| 956 | set_fdc(saved_drive); |
| 957 | } |
| 958 | |
| 959 | static void empty(void) |
| 960 | { |
| 961 | } |
| 962 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 963 | static DECLARE_WORK(floppy_work, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 965 | static void schedule_bh(void (*handler)(void)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 967 | PREPARE_WORK(&floppy_work, (work_func_t)handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | schedule_work(&floppy_work); |
| 969 | } |
| 970 | |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 971 | static DEFINE_TIMER(fd_timer, NULL, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
| 973 | static void cancel_activity(void) |
| 974 | { |
| 975 | unsigned long flags; |
| 976 | |
| 977 | spin_lock_irqsave(&floppy_lock, flags); |
| 978 | do_floppy = NULL; |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 979 | PREPARE_WORK(&floppy_work, (work_func_t)empty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | del_timer(&fd_timer); |
| 981 | spin_unlock_irqrestore(&floppy_lock, flags); |
| 982 | } |
| 983 | |
| 984 | /* this function makes sure that the disk stays in the drive during the |
| 985 | * transfer */ |
| 986 | static void fd_watchdog(void) |
| 987 | { |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 988 | debug_dcl(DP->flags, "calling disk change from watchdog\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | if (disk_change(current_drive)) { |
| 991 | DPRINT("disk removed during i/o\n"); |
| 992 | cancel_activity(); |
| 993 | cont->done(0); |
| 994 | reset_fdc(); |
| 995 | } else { |
| 996 | del_timer(&fd_timer); |
Joe Perches | a0a52d6 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 997 | fd_timer.function = (timeout_fn)fd_watchdog; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | fd_timer.expires = jiffies + HZ / 10; |
| 999 | add_timer(&fd_timer); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | static void main_command_interrupt(void) |
| 1004 | { |
| 1005 | del_timer(&fd_timer); |
| 1006 | cont->interrupt(); |
| 1007 | } |
| 1008 | |
| 1009 | /* waits for a delay (spinup or select) to pass */ |
| 1010 | static int fd_wait_for_completion(unsigned long delay, timeout_fn function) |
| 1011 | { |
| 1012 | if (FDCS->reset) { |
| 1013 | reset_fdc(); /* do the reset during sleep to win time |
| 1014 | * if we don't need to sleep, it's a good |
| 1015 | * occasion anyways */ |
| 1016 | return 1; |
| 1017 | } |
| 1018 | |
Marcelo Feitoza Parisi | 50297cb | 2006-03-28 01:56:44 -0800 | [diff] [blame] | 1019 | if (time_before(jiffies, delay)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | del_timer(&fd_timer); |
| 1021 | fd_timer.function = function; |
| 1022 | fd_timer.expires = delay; |
| 1023 | add_timer(&fd_timer); |
| 1024 | return 1; |
| 1025 | } |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | static DEFINE_SPINLOCK(floppy_hlt_lock); |
| 1030 | static int hlt_disabled; |
| 1031 | static void floppy_disable_hlt(void) |
| 1032 | { |
| 1033 | unsigned long flags; |
| 1034 | |
| 1035 | spin_lock_irqsave(&floppy_hlt_lock, flags); |
| 1036 | if (!hlt_disabled) { |
| 1037 | hlt_disabled = 1; |
| 1038 | #ifdef HAVE_DISABLE_HLT |
| 1039 | disable_hlt(); |
| 1040 | #endif |
| 1041 | } |
| 1042 | spin_unlock_irqrestore(&floppy_hlt_lock, flags); |
| 1043 | } |
| 1044 | |
| 1045 | static void floppy_enable_hlt(void) |
| 1046 | { |
| 1047 | unsigned long flags; |
| 1048 | |
| 1049 | spin_lock_irqsave(&floppy_hlt_lock, flags); |
| 1050 | if (hlt_disabled) { |
| 1051 | hlt_disabled = 0; |
| 1052 | #ifdef HAVE_DISABLE_HLT |
| 1053 | enable_hlt(); |
| 1054 | #endif |
| 1055 | } |
| 1056 | spin_unlock_irqrestore(&floppy_hlt_lock, flags); |
| 1057 | } |
| 1058 | |
| 1059 | static void setup_DMA(void) |
| 1060 | { |
| 1061 | unsigned long f; |
| 1062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | if (raw_cmd->length == 0) { |
| 1064 | int i; |
| 1065 | |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1066 | pr_info("zero dma transfer size:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | for (i = 0; i < raw_cmd->cmd_count; i++) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1068 | pr_cont("%x,", raw_cmd->cmd[i]); |
| 1069 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | cont->done(0); |
| 1071 | FDCS->reset = 1; |
| 1072 | return; |
| 1073 | } |
| 1074 | if (((unsigned long)raw_cmd->kernel_data) % 512) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1075 | pr_info("non aligned address: %p\n", raw_cmd->kernel_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | cont->done(0); |
| 1077 | FDCS->reset = 1; |
| 1078 | return; |
| 1079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | f = claim_dma_lock(); |
| 1081 | fd_disable_dma(); |
| 1082 | #ifdef fd_dma_setup |
| 1083 | if (fd_dma_setup(raw_cmd->kernel_data, raw_cmd->length, |
| 1084 | (raw_cmd->flags & FD_RAW_READ) ? |
| 1085 | DMA_MODE_READ : DMA_MODE_WRITE, FDCS->address) < 0) { |
| 1086 | release_dma_lock(f); |
| 1087 | cont->done(0); |
| 1088 | FDCS->reset = 1; |
| 1089 | return; |
| 1090 | } |
| 1091 | release_dma_lock(f); |
| 1092 | #else |
| 1093 | fd_clear_dma_ff(); |
| 1094 | fd_cacheflush(raw_cmd->kernel_data, raw_cmd->length); |
| 1095 | fd_set_dma_mode((raw_cmd->flags & FD_RAW_READ) ? |
| 1096 | DMA_MODE_READ : DMA_MODE_WRITE); |
| 1097 | fd_set_dma_addr(raw_cmd->kernel_data); |
| 1098 | fd_set_dma_count(raw_cmd->length); |
| 1099 | virtual_dma_port = FDCS->address; |
| 1100 | fd_enable_dma(); |
| 1101 | release_dma_lock(f); |
| 1102 | #endif |
| 1103 | floppy_disable_hlt(); |
| 1104 | } |
| 1105 | |
| 1106 | static void show_floppy(void); |
| 1107 | |
| 1108 | /* waits until the fdc becomes ready */ |
| 1109 | static int wait_til_ready(void) |
| 1110 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1111 | int status; |
| 1112 | int counter; |
| 1113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | if (FDCS->reset) |
| 1115 | return -1; |
| 1116 | for (counter = 0; counter < 10000; counter++) { |
| 1117 | status = fd_inb(FD_STATUS); |
| 1118 | if (status & STATUS_READY) |
| 1119 | return status; |
| 1120 | } |
Joe Perches | 29f1c78 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1121 | if (initialized) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc); |
| 1123 | show_floppy(); |
| 1124 | } |
| 1125 | FDCS->reset = 1; |
| 1126 | return -1; |
| 1127 | } |
| 1128 | |
| 1129 | /* sends a command byte to the fdc */ |
| 1130 | static int output_byte(char byte) |
| 1131 | { |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 1132 | int status = wait_til_ready(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 1134 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | return -1; |
Joe Perches | 57584c5 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1136 | |
| 1137 | if (is_ready_state(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | fd_outb(byte, FD_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | output_log[output_log_pos].data = byte; |
| 1140 | output_log[output_log_pos].status = status; |
| 1141 | output_log[output_log_pos].jiffies = jiffies; |
| 1142 | output_log_pos = (output_log_pos + 1) % OLOGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | return 0; |
| 1144 | } |
| 1145 | FDCS->reset = 1; |
Joe Perches | 29f1c78 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1146 | if (initialized) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n", |
| 1148 | byte, fdc, status); |
| 1149 | show_floppy(); |
| 1150 | } |
| 1151 | return -1; |
| 1152 | } |
| 1153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | /* gets the response from the fdc */ |
| 1155 | static int result(void) |
| 1156 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1157 | int i; |
| 1158 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
| 1160 | for (i = 0; i < MAX_REPLIES; i++) { |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 1161 | status = wait_til_ready(); |
| 1162 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | break; |
| 1164 | status &= STATUS_DIR | STATUS_READY | STATUS_BUSY | STATUS_DMA; |
| 1165 | if ((status & ~STATUS_BUSY) == STATUS_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | resultjiffies = jiffies; |
| 1167 | resultsize = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | return i; |
| 1169 | } |
| 1170 | if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY)) |
| 1171 | reply_buffer[i] = fd_inb(FD_DATA); |
| 1172 | else |
| 1173 | break; |
| 1174 | } |
Joe Perches | 29f1c78 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1175 | if (initialized) { |
| 1176 | DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n", |
| 1177 | fdc, status, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | show_floppy(); |
| 1179 | } |
| 1180 | FDCS->reset = 1; |
| 1181 | return -1; |
| 1182 | } |
| 1183 | |
| 1184 | #define MORE_OUTPUT -2 |
| 1185 | /* does the fdc need more output? */ |
| 1186 | static int need_more_output(void) |
| 1187 | { |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 1188 | int status = wait_til_ready(); |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1189 | |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 1190 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | return -1; |
Joe Perches | 57584c5 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1192 | |
| 1193 | if (is_ready_state(status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | return MORE_OUTPUT; |
Joe Perches | 57584c5 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | return result(); |
| 1197 | } |
| 1198 | |
| 1199 | /* Set perpendicular mode as required, based on data rate, if supported. |
| 1200 | * 82077 Now tested. 1Mbps data rate only possible with 82077-1. |
| 1201 | */ |
Stephen Hemminger | be7a12b | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 1202 | static void perpendicular_mode(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | { |
| 1204 | unsigned char perp_mode; |
| 1205 | |
| 1206 | if (raw_cmd->rate & 0x40) { |
| 1207 | switch (raw_cmd->rate & 3) { |
| 1208 | case 0: |
| 1209 | perp_mode = 2; |
| 1210 | break; |
| 1211 | case 3: |
| 1212 | perp_mode = 3; |
| 1213 | break; |
| 1214 | default: |
| 1215 | DPRINT("Invalid data rate for perpendicular mode!\n"); |
| 1216 | cont->done(0); |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 1217 | FDCS->reset = 1; |
| 1218 | /* |
| 1219 | * convenient way to return to |
| 1220 | * redo without too much hassle |
| 1221 | * (deep stack et al.) |
| 1222 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | return; |
| 1224 | } |
| 1225 | } else |
| 1226 | perp_mode = 0; |
| 1227 | |
| 1228 | if (FDCS->perp_mode == perp_mode) |
| 1229 | return; |
| 1230 | if (FDCS->version >= FDC_82077_ORIG) { |
| 1231 | output_byte(FD_PERPENDICULAR); |
| 1232 | output_byte(perp_mode); |
| 1233 | FDCS->perp_mode = perp_mode; |
| 1234 | } else if (perp_mode) { |
| 1235 | DPRINT("perpendicular mode not supported by this FDC.\n"); |
| 1236 | } |
| 1237 | } /* perpendicular_mode */ |
| 1238 | |
| 1239 | static int fifo_depth = 0xa; |
| 1240 | static int no_fifo; |
| 1241 | |
| 1242 | static int fdc_configure(void) |
| 1243 | { |
| 1244 | /* Turn on FIFO */ |
| 1245 | output_byte(FD_CONFIGURE); |
| 1246 | if (need_more_output() != MORE_OUTPUT) |
| 1247 | return 0; |
| 1248 | output_byte(0); |
| 1249 | output_byte(0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf)); |
| 1250 | output_byte(0); /* pre-compensation from track |
| 1251 | 0 upwards */ |
| 1252 | return 1; |
| 1253 | } |
| 1254 | |
| 1255 | #define NOMINAL_DTR 500 |
| 1256 | |
| 1257 | /* Issue a "SPECIFY" command to set the step rate time, head unload time, |
| 1258 | * head load time, and DMA disable flag to values needed by floppy. |
| 1259 | * |
| 1260 | * The value "dtr" is the data transfer rate in Kbps. It is needed |
| 1261 | * to account for the data rate-based scaling done by the 82072 and 82077 |
| 1262 | * FDC types. This parameter is ignored for other types of FDCs (i.e. |
| 1263 | * 8272a). |
| 1264 | * |
| 1265 | * Note that changing the data transfer rate has a (probably deleterious) |
| 1266 | * effect on the parameters subject to scaling for 82072/82077 FDCs, so |
| 1267 | * fdc_specify is called again after each data transfer rate |
| 1268 | * change. |
| 1269 | * |
| 1270 | * srt: 1000 to 16000 in microseconds |
| 1271 | * hut: 16 to 240 milliseconds |
| 1272 | * hlt: 2 to 254 milliseconds |
| 1273 | * |
| 1274 | * These values are rounded up to the next highest available delay time. |
| 1275 | */ |
| 1276 | static void fdc_specify(void) |
| 1277 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1278 | unsigned char spec1; |
| 1279 | unsigned char spec2; |
| 1280 | unsigned long srt; |
| 1281 | unsigned long hlt; |
| 1282 | unsigned long hut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | unsigned long dtr = NOMINAL_DTR; |
| 1284 | unsigned long scale_dtr = NOMINAL_DTR; |
| 1285 | int hlt_max_code = 0x7f; |
| 1286 | int hut_max_code = 0xf; |
| 1287 | |
| 1288 | if (FDCS->need_configure && FDCS->version >= FDC_82072A) { |
| 1289 | fdc_configure(); |
| 1290 | FDCS->need_configure = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | switch (raw_cmd->rate & 0x03) { |
| 1294 | case 3: |
| 1295 | dtr = 1000; |
| 1296 | break; |
| 1297 | case 1: |
| 1298 | dtr = 300; |
| 1299 | if (FDCS->version >= FDC_82078) { |
| 1300 | /* chose the default rate table, not the one |
| 1301 | * where 1 = 2 Mbps */ |
| 1302 | output_byte(FD_DRIVESPEC); |
| 1303 | if (need_more_output() == MORE_OUTPUT) { |
| 1304 | output_byte(UNIT(current_drive)); |
| 1305 | output_byte(0xc0); |
| 1306 | } |
| 1307 | } |
| 1308 | break; |
| 1309 | case 2: |
| 1310 | dtr = 250; |
| 1311 | break; |
| 1312 | } |
| 1313 | |
| 1314 | if (FDCS->version >= FDC_82072) { |
| 1315 | scale_dtr = dtr; |
| 1316 | hlt_max_code = 0x00; /* 0==256msec*dtr0/dtr (not linear!) */ |
| 1317 | hut_max_code = 0x0; /* 0==256msec*dtr0/dtr (not linear!) */ |
| 1318 | } |
| 1319 | |
| 1320 | /* Convert step rate from microseconds to milliseconds and 4 bits */ |
Julia Lawall | 061837b | 2008-09-22 14:57:16 -0700 | [diff] [blame] | 1321 | srt = 16 - DIV_ROUND_UP(DP->srt * scale_dtr / 1000, NOMINAL_DTR); |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1322 | if (slow_floppy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | srt = srt / 4; |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | SUPBOUND(srt, 0xf); |
| 1326 | INFBOUND(srt, 0); |
| 1327 | |
Julia Lawall | 061837b | 2008-09-22 14:57:16 -0700 | [diff] [blame] | 1328 | hlt = DIV_ROUND_UP(DP->hlt * scale_dtr / 2, NOMINAL_DTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | if (hlt < 0x01) |
| 1330 | hlt = 0x01; |
| 1331 | else if (hlt > 0x7f) |
| 1332 | hlt = hlt_max_code; |
| 1333 | |
Julia Lawall | 061837b | 2008-09-22 14:57:16 -0700 | [diff] [blame] | 1334 | hut = DIV_ROUND_UP(DP->hut * scale_dtr / 16, NOMINAL_DTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | if (hut < 0x1) |
| 1336 | hut = 0x1; |
| 1337 | else if (hut > 0xf) |
| 1338 | hut = hut_max_code; |
| 1339 | |
| 1340 | spec1 = (srt << 4) | hut; |
| 1341 | spec2 = (hlt << 1) | (use_virtual_dma & 1); |
| 1342 | |
| 1343 | /* If these parameters did not change, just return with success */ |
| 1344 | if (FDCS->spec1 != spec1 || FDCS->spec2 != spec2) { |
| 1345 | /* Go ahead and set spec1 and spec2 */ |
| 1346 | output_byte(FD_SPECIFY); |
| 1347 | output_byte(FDCS->spec1 = spec1); |
| 1348 | output_byte(FDCS->spec2 = spec2); |
| 1349 | } |
| 1350 | } /* fdc_specify */ |
| 1351 | |
| 1352 | /* Set the FDC's data transfer rate on behalf of the specified drive. |
| 1353 | * NOTE: with 82072/82077 FDCs, changing the data rate requires a reissue |
| 1354 | * of the specify command (i.e. using the fdc_specify function). |
| 1355 | */ |
| 1356 | static int fdc_dtr(void) |
| 1357 | { |
| 1358 | /* If data rate not already set to desired value, set it. */ |
| 1359 | if ((raw_cmd->rate & 3) == FDCS->dtr) |
| 1360 | return 0; |
| 1361 | |
| 1362 | /* Set dtr */ |
| 1363 | fd_outb(raw_cmd->rate & 3, FD_DCR); |
| 1364 | |
| 1365 | /* TODO: some FDC/drive combinations (C&T 82C711 with TEAC 1.2MB) |
| 1366 | * need a stabilization period of several milliseconds to be |
| 1367 | * enforced after data rate changes before R/W operations. |
| 1368 | * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies) |
| 1369 | */ |
| 1370 | FDCS->dtr = raw_cmd->rate & 3; |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 1371 | return fd_wait_for_completion(jiffies + 2UL * HZ / 100, |
| 1372 | (timeout_fn)floppy_ready); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | } /* fdc_dtr */ |
| 1374 | |
| 1375 | static void tell_sector(void) |
| 1376 | { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1377 | pr_cont(": track %d, head %d, sector %d, size %d", |
| 1378 | R_TRACK, R_HEAD, R_SECTOR, R_SIZECODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } /* tell_sector */ |
| 1380 | |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1381 | static void print_errors(void) |
| 1382 | { |
| 1383 | DPRINT(""); |
| 1384 | if (ST0 & ST0_ECE) { |
| 1385 | pr_cont("Recalibrate failed!"); |
| 1386 | } else if (ST2 & ST2_CRC) { |
| 1387 | pr_cont("data CRC error"); |
| 1388 | tell_sector(); |
| 1389 | } else if (ST1 & ST1_CRC) { |
| 1390 | pr_cont("CRC error"); |
| 1391 | tell_sector(); |
| 1392 | } else if ((ST1 & (ST1_MAM | ST1_ND)) || |
| 1393 | (ST2 & ST2_MAM)) { |
| 1394 | if (!probing) { |
| 1395 | pr_cont("sector not found"); |
| 1396 | tell_sector(); |
| 1397 | } else |
| 1398 | pr_cont("probe failed..."); |
| 1399 | } else if (ST2 & ST2_WC) { /* seek error */ |
| 1400 | pr_cont("wrong cylinder"); |
| 1401 | } else if (ST2 & ST2_BC) { /* cylinder marked as bad */ |
| 1402 | pr_cont("bad cylinder"); |
| 1403 | } else { |
| 1404 | pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x", |
| 1405 | ST0, ST1, ST2); |
| 1406 | tell_sector(); |
| 1407 | } |
| 1408 | pr_cont("\n"); |
| 1409 | } |
| 1410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | /* |
| 1412 | * OK, this error interpreting routine is called after a |
| 1413 | * DMA read/write has succeeded |
| 1414 | * or failed, so we check the results, and copy any buffers. |
| 1415 | * hhb: Added better error reporting. |
| 1416 | * ak: Made this into a separate routine. |
| 1417 | */ |
| 1418 | static int interpret_errors(void) |
| 1419 | { |
| 1420 | char bad; |
| 1421 | |
| 1422 | if (inr != 7) { |
Joe Perches | 891eda8 | 2010-03-10 15:21:05 -0800 | [diff] [blame] | 1423 | DPRINT("-- FDC reply error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | FDCS->reset = 1; |
| 1425 | return 1; |
| 1426 | } |
| 1427 | |
| 1428 | /* check IC to find cause of interrupt */ |
| 1429 | switch (ST0 & ST0_INTR) { |
| 1430 | case 0x40: /* error occurred during command execution */ |
| 1431 | if (ST1 & ST1_EOC) |
| 1432 | return 0; /* occurs with pseudo-DMA */ |
| 1433 | bad = 1; |
| 1434 | if (ST1 & ST1_WP) { |
| 1435 | DPRINT("Drive is write protected\n"); |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1436 | clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | cont->done(0); |
| 1438 | bad = 2; |
| 1439 | } else if (ST1 & ST1_ND) { |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1440 | set_bit(FD_NEED_TWADDLE_BIT, &DRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | } else if (ST1 & ST1_OR) { |
| 1442 | if (DP->flags & FTD_MSG) |
| 1443 | DPRINT("Over/Underrun - retrying\n"); |
| 1444 | bad = 0; |
| 1445 | } else if (*errors >= DP->max_errors.reporting) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1446 | print_errors(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | } |
| 1448 | if (ST2 & ST2_WC || ST2 & ST2_BC) |
| 1449 | /* wrong cylinder => recal */ |
| 1450 | DRS->track = NEED_2_RECAL; |
| 1451 | return bad; |
| 1452 | case 0x80: /* invalid command given */ |
| 1453 | DPRINT("Invalid FDC command given!\n"); |
| 1454 | cont->done(0); |
| 1455 | return 2; |
| 1456 | case 0xc0: |
| 1457 | DPRINT("Abnormal termination caused by polling\n"); |
| 1458 | cont->error(); |
| 1459 | return 2; |
| 1460 | default: /* (0) Normal command termination */ |
| 1461 | return 0; |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | /* |
| 1466 | * This routine is called when everything should be correctly set up |
| 1467 | * for the transfer (i.e. floppy motor is on, the correct floppy is |
| 1468 | * selected, and the head is sitting on the right track). |
| 1469 | */ |
| 1470 | static void setup_rw_floppy(void) |
| 1471 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1472 | int i; |
| 1473 | int r; |
| 1474 | int flags; |
| 1475 | int dflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | unsigned long ready_date; |
| 1477 | timeout_fn function; |
| 1478 | |
| 1479 | flags = raw_cmd->flags; |
| 1480 | if (flags & (FD_RAW_READ | FD_RAW_WRITE)) |
| 1481 | flags |= FD_RAW_INTR; |
| 1482 | |
| 1483 | if ((flags & FD_RAW_SPIN) && !(flags & FD_RAW_NO_MOTOR)) { |
| 1484 | ready_date = DRS->spinup_date + DP->spinup; |
| 1485 | /* If spinup will take a long time, rerun scandrives |
| 1486 | * again just before spinup completion. Beware that |
| 1487 | * after scandrives, we must again wait for selection. |
| 1488 | */ |
Marcelo Feitoza Parisi | 50297cb | 2006-03-28 01:56:44 -0800 | [diff] [blame] | 1489 | if (time_after(ready_date, jiffies + DP->select_delay)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | ready_date -= DP->select_delay; |
Joe Perches | a0a52d6 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 1491 | function = (timeout_fn)floppy_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } else |
Joe Perches | a0a52d6 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 1493 | function = (timeout_fn)setup_rw_floppy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
| 1495 | /* wait until the floppy is spinning fast enough */ |
| 1496 | if (fd_wait_for_completion(ready_date, function)) |
| 1497 | return; |
| 1498 | } |
| 1499 | dflags = DRS->flags; |
| 1500 | |
| 1501 | if ((flags & FD_RAW_READ) || (flags & FD_RAW_WRITE)) |
| 1502 | setup_DMA(); |
| 1503 | |
| 1504 | if (flags & FD_RAW_INTR) |
| 1505 | do_floppy = main_command_interrupt; |
| 1506 | |
| 1507 | r = 0; |
| 1508 | for (i = 0; i < raw_cmd->cmd_count; i++) |
| 1509 | r |= output_byte(raw_cmd->cmd[i]); |
| 1510 | |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1511 | debugt(__func__, "rw_command"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | |
| 1513 | if (r) { |
| 1514 | cont->error(); |
| 1515 | reset_fdc(); |
| 1516 | return; |
| 1517 | } |
| 1518 | |
| 1519 | if (!(flags & FD_RAW_INTR)) { |
| 1520 | inr = result(); |
| 1521 | cont->interrupt(); |
| 1522 | } else if (flags & FD_RAW_NEED_DISK) |
| 1523 | fd_watchdog(); |
| 1524 | } |
| 1525 | |
| 1526 | static int blind_seek; |
| 1527 | |
| 1528 | /* |
| 1529 | * This is the routine called after every seek (or recalibrate) interrupt |
| 1530 | * from the floppy controller. |
| 1531 | */ |
| 1532 | static void seek_interrupt(void) |
| 1533 | { |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1534 | debugt(__func__, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | if (inr != 2 || (ST0 & 0xF8) != 0x20) { |
| 1536 | DPRINT("seek failed\n"); |
| 1537 | DRS->track = NEED_2_RECAL; |
| 1538 | cont->error(); |
| 1539 | cont->redo(); |
| 1540 | return; |
| 1541 | } |
| 1542 | if (DRS->track >= 0 && DRS->track != ST1 && !blind_seek) { |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 1543 | debug_dcl(DP->flags, |
| 1544 | "clearing NEWCHANGE flag because of effective seek\n"); |
| 1545 | debug_dcl(DP->flags, "jiffies=%lu\n", jiffies); |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1546 | clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); |
| 1547 | /* effective seek */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | DRS->select_date = jiffies; |
| 1549 | } |
| 1550 | DRS->track = ST1; |
| 1551 | floppy_ready(); |
| 1552 | } |
| 1553 | |
| 1554 | static void check_wp(void) |
| 1555 | { |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1556 | if (test_bit(FD_VERIFY_BIT, &DRS->flags)) { |
| 1557 | /* check write protection */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | output_byte(FD_GETSTATUS); |
| 1559 | output_byte(UNIT(current_drive)); |
| 1560 | if (result() != 1) { |
| 1561 | FDCS->reset = 1; |
| 1562 | return; |
| 1563 | } |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1564 | clear_bit(FD_VERIFY_BIT, &DRS->flags); |
| 1565 | clear_bit(FD_NEED_TWADDLE_BIT, &DRS->flags); |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 1566 | debug_dcl(DP->flags, |
| 1567 | "checking whether disk is write protected\n"); |
| 1568 | debug_dcl(DP->flags, "wp=%x\n", ST3 & 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | if (!(ST3 & 0x40)) |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1570 | set_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | else |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1572 | clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | static void seek_floppy(void) |
| 1577 | { |
| 1578 | int track; |
| 1579 | |
| 1580 | blind_seek = 0; |
| 1581 | |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1582 | debug_dcl(DP->flags, "calling disk change from %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1584 | if (!test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) { |
| 1586 | /* the media changed flag should be cleared after the seek. |
| 1587 | * If it isn't, this means that there is really no disk in |
| 1588 | * the drive. |
| 1589 | */ |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1590 | set_bit(FD_DISK_CHANGED_BIT, &DRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | cont->done(0); |
| 1592 | cont->redo(); |
| 1593 | return; |
| 1594 | } |
| 1595 | if (DRS->track <= NEED_1_RECAL) { |
| 1596 | recalibrate_floppy(); |
| 1597 | return; |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1598 | } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | (raw_cmd->flags & FD_RAW_NEED_DISK) && |
| 1600 | (DRS->track <= NO_TRACK || DRS->track == raw_cmd->track)) { |
| 1601 | /* we seek to clear the media-changed condition. Does anybody |
| 1602 | * know a more elegant way, which works on all drives? */ |
| 1603 | if (raw_cmd->track) |
| 1604 | track = raw_cmd->track - 1; |
| 1605 | else { |
| 1606 | if (DP->flags & FD_SILENT_DCL_CLEAR) { |
| 1607 | set_dor(fdc, ~(0x10 << UNIT(current_drive)), 0); |
| 1608 | blind_seek = 1; |
| 1609 | raw_cmd->flags |= FD_RAW_NEED_SEEK; |
| 1610 | } |
| 1611 | track = 1; |
| 1612 | } |
| 1613 | } else { |
| 1614 | check_wp(); |
| 1615 | if (raw_cmd->track != DRS->track && |
| 1616 | (raw_cmd->flags & FD_RAW_NEED_SEEK)) |
| 1617 | track = raw_cmd->track; |
| 1618 | else { |
| 1619 | setup_rw_floppy(); |
| 1620 | return; |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | do_floppy = seek_interrupt; |
| 1625 | output_byte(FD_SEEK); |
| 1626 | output_byte(UNIT(current_drive)); |
Joe Perches | 2300f90 | 2010-03-10 15:20:49 -0800 | [diff] [blame] | 1627 | if (output_byte(track) < 0) { |
| 1628 | reset_fdc(); |
| 1629 | return; |
| 1630 | } |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1631 | debugt(__func__, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | static void recal_interrupt(void) |
| 1635 | { |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1636 | debugt(__func__, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | if (inr != 2) |
| 1638 | FDCS->reset = 1; |
| 1639 | else if (ST0 & ST0_ECE) { |
| 1640 | switch (DRS->track) { |
| 1641 | case NEED_1_RECAL: |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1642 | debugt(__func__, "need 1 recal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | /* after a second recalibrate, we still haven't |
| 1644 | * reached track 0. Probably no drive. Raise an |
| 1645 | * error, as failing immediately might upset |
| 1646 | * computers possessed by the Devil :-) */ |
| 1647 | cont->error(); |
| 1648 | cont->redo(); |
| 1649 | return; |
| 1650 | case NEED_2_RECAL: |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1651 | debugt(__func__, "need 2 recal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | /* If we already did a recalibrate, |
| 1653 | * and we are not at track 0, this |
| 1654 | * means we have moved. (The only way |
| 1655 | * not to move at recalibration is to |
| 1656 | * be already at track 0.) Clear the |
| 1657 | * new change flag */ |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 1658 | debug_dcl(DP->flags, |
| 1659 | "clearing NEWCHANGE flag because of second recalibrate\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1661 | clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | DRS->select_date = jiffies; |
| 1663 | /* fall through */ |
| 1664 | default: |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1665 | debugt(__func__, "default"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | /* Recalibrate moves the head by at |
| 1667 | * most 80 steps. If after one |
| 1668 | * recalibrate we don't have reached |
| 1669 | * track 0, this might mean that we |
| 1670 | * started beyond track 80. Try |
| 1671 | * again. */ |
| 1672 | DRS->track = NEED_1_RECAL; |
| 1673 | break; |
| 1674 | } |
| 1675 | } else |
| 1676 | DRS->track = ST1; |
| 1677 | floppy_ready(); |
| 1678 | } |
| 1679 | |
| 1680 | static void print_result(char *message, int inr) |
| 1681 | { |
| 1682 | int i; |
| 1683 | |
| 1684 | DPRINT("%s ", message); |
| 1685 | if (inr >= 0) |
| 1686 | for (i = 0; i < inr; i++) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1687 | pr_cont("repl[%d]=%x ", i, reply_buffer[i]); |
| 1688 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | /* interrupt handler. Note that this can be called externally on the Sparc */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1692 | irqreturn_t floppy_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | int do_print; |
| 1695 | unsigned long f; |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1696 | void (*handler)(void) = do_floppy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
| 1698 | lasthandler = handler; |
| 1699 | interruptjiffies = jiffies; |
| 1700 | |
| 1701 | f = claim_dma_lock(); |
| 1702 | fd_disable_dma(); |
| 1703 | release_dma_lock(f); |
| 1704 | |
| 1705 | floppy_enable_hlt(); |
| 1706 | do_floppy = NULL; |
| 1707 | if (fdc >= N_FDC || FDCS->address == -1) { |
| 1708 | /* we don't even know which FDC is the culprit */ |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1709 | pr_info("DOR0=%x\n", fdc_state[0].dor); |
| 1710 | pr_info("floppy interrupt on bizarre fdc %d\n", fdc); |
Joe Perches | 1ebddd8 | 2010-03-10 15:21:07 -0800 | [diff] [blame] | 1711 | pr_info("handler=%pf\n", handler); |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 1712 | is_alive(__func__, "bizarre fdc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | return IRQ_NONE; |
| 1714 | } |
| 1715 | |
| 1716 | FDCS->reset = 0; |
| 1717 | /* We have to clear the reset flag here, because apparently on boxes |
| 1718 | * with level triggered interrupts (PS/2, Sparc, ...), it is needed to |
| 1719 | * emit SENSEI's to clear the interrupt line. And FDCS->reset blocks the |
| 1720 | * emission of the SENSEI's. |
| 1721 | * It is OK to emit floppy commands because we are in an interrupt |
| 1722 | * handler here, and thus we have to fear no interference of other |
| 1723 | * activity. |
| 1724 | */ |
| 1725 | |
Joe Perches | 29f1c78 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1726 | do_print = !handler && print_unex && initialized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | |
| 1728 | inr = result(); |
| 1729 | if (do_print) |
| 1730 | print_result("unexpected interrupt", inr); |
| 1731 | if (inr == 0) { |
| 1732 | int max_sensei = 4; |
| 1733 | do { |
| 1734 | output_byte(FD_SENSEI); |
| 1735 | inr = result(); |
| 1736 | if (do_print) |
| 1737 | print_result("sensei", inr); |
| 1738 | max_sensei--; |
Joe Perches | c529730 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 1739 | } while ((ST0 & 0x83) != UNIT(current_drive) && |
| 1740 | inr == 2 && max_sensei); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | } |
| 1742 | if (!handler) { |
| 1743 | FDCS->reset = 1; |
| 1744 | return IRQ_NONE; |
| 1745 | } |
| 1746 | schedule_bh(handler); |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 1747 | is_alive(__func__, "normal interrupt end"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | |
| 1749 | /* FIXME! Was it really for us? */ |
| 1750 | return IRQ_HANDLED; |
| 1751 | } |
| 1752 | |
| 1753 | static void recalibrate_floppy(void) |
| 1754 | { |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1755 | debugt(__func__, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | do_floppy = recal_interrupt; |
| 1757 | output_byte(FD_RECALIBRATE); |
Joe Perches | 15b2630 | 2010-03-10 15:21:01 -0800 | [diff] [blame] | 1758 | if (output_byte(UNIT(current_drive)) < 0) |
Joe Perches | 2300f90 | 2010-03-10 15:20:49 -0800 | [diff] [blame] | 1759 | reset_fdc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | /* |
| 1763 | * Must do 4 FD_SENSEIs after reset because of ``drive polling''. |
| 1764 | */ |
| 1765 | static void reset_interrupt(void) |
| 1766 | { |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 1767 | debugt(__func__, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | result(); /* get the status ready for set_fdc */ |
| 1769 | if (FDCS->reset) { |
Joe Perches | 1ebddd8 | 2010-03-10 15:21:07 -0800 | [diff] [blame] | 1770 | pr_info("reset set in interrupt, calling %pf\n", cont->error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | cont->error(); /* a reset just after a reset. BAD! */ |
| 1772 | } |
| 1773 | cont->redo(); |
| 1774 | } |
| 1775 | |
| 1776 | /* |
| 1777 | * reset is done by pulling bit 2 of DOR low for a while (old FDCs), |
| 1778 | * or by setting the self clearing bit 7 of STATUS (newer FDCs) |
| 1779 | */ |
| 1780 | static void reset_fdc(void) |
| 1781 | { |
| 1782 | unsigned long flags; |
| 1783 | |
| 1784 | do_floppy = reset_interrupt; |
| 1785 | FDCS->reset = 0; |
| 1786 | reset_fdc_info(0); |
| 1787 | |
| 1788 | /* Pseudo-DMA may intercept 'reset finished' interrupt. */ |
| 1789 | /* Irrelevant for systems with true DMA (i386). */ |
| 1790 | |
| 1791 | flags = claim_dma_lock(); |
| 1792 | fd_disable_dma(); |
| 1793 | release_dma_lock(flags); |
| 1794 | |
| 1795 | if (FDCS->version >= FDC_82072A) |
| 1796 | fd_outb(0x80 | (FDCS->dtr & 3), FD_STATUS); |
| 1797 | else { |
| 1798 | fd_outb(FDCS->dor & ~0x04, FD_DOR); |
| 1799 | udelay(FD_RESET_DELAY); |
| 1800 | fd_outb(FDCS->dor, FD_DOR); |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | static void show_floppy(void) |
| 1805 | { |
| 1806 | int i; |
| 1807 | |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1808 | pr_info("\n"); |
| 1809 | pr_info("floppy driver state\n"); |
| 1810 | pr_info("-------------------\n"); |
Joe Perches | 1ebddd8 | 2010-03-10 15:21:07 -0800 | [diff] [blame] | 1811 | pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%pf\n", |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1812 | jiffies, interruptjiffies, jiffies - interruptjiffies, |
| 1813 | lasthandler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1815 | pr_info("timeout_message=%s\n", timeout_message); |
| 1816 | pr_info("last output bytes:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | for (i = 0; i < OLOGSIZE; i++) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1818 | pr_info("%2x %2x %lu\n", |
| 1819 | output_log[(i + output_log_pos) % OLOGSIZE].data, |
| 1820 | output_log[(i + output_log_pos) % OLOGSIZE].status, |
| 1821 | output_log[(i + output_log_pos) % OLOGSIZE].jiffies); |
| 1822 | pr_info("last result at %lu\n", resultjiffies); |
| 1823 | pr_info("last redo_fd_request at %lu\n", lastredo); |
| 1824 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1, |
| 1825 | reply_buffer, resultsize, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1827 | pr_info("status=%x\n", fd_inb(FD_STATUS)); |
| 1828 | pr_info("fdc_busy=%lu\n", fdc_busy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | if (do_floppy) |
Joe Perches | 1ebddd8 | 2010-03-10 15:21:07 -0800 | [diff] [blame] | 1830 | pr_info("do_floppy=%pf\n", do_floppy); |
David Howells | 365970a | 2006-11-22 14:54:49 +0000 | [diff] [blame] | 1831 | if (work_pending(&floppy_work)) |
Joe Perches | 1ebddd8 | 2010-03-10 15:21:07 -0800 | [diff] [blame] | 1832 | pr_info("floppy_work.func=%pf\n", floppy_work.func); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | if (timer_pending(&fd_timer)) |
Joe Perches | 1ebddd8 | 2010-03-10 15:21:07 -0800 | [diff] [blame] | 1834 | pr_info("fd_timer.function=%pf\n", fd_timer.function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | if (timer_pending(&fd_timeout)) { |
Joe Perches | 1ebddd8 | 2010-03-10 15:21:07 -0800 | [diff] [blame] | 1836 | pr_info("timer_function=%pf\n", fd_timeout.function); |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1837 | pr_info("expires=%lu\n", fd_timeout.expires - jiffies); |
| 1838 | pr_info("now=%lu\n", jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | } |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1840 | pr_info("cont=%p\n", cont); |
| 1841 | pr_info("current_req=%p\n", current_req); |
| 1842 | pr_info("command_status=%d\n", command_status); |
| 1843 | pr_info("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | static void floppy_shutdown(unsigned long data) |
| 1847 | { |
| 1848 | unsigned long flags; |
| 1849 | |
Joe Perches | 29f1c78 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1850 | if (initialized) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | show_floppy(); |
| 1852 | cancel_activity(); |
| 1853 | |
| 1854 | floppy_enable_hlt(); |
| 1855 | |
| 1856 | flags = claim_dma_lock(); |
| 1857 | fd_disable_dma(); |
| 1858 | release_dma_lock(flags); |
| 1859 | |
| 1860 | /* avoid dma going to a random drive after shutdown */ |
| 1861 | |
Joe Perches | 29f1c78 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 1862 | if (initialized) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | DPRINT("floppy timeout called\n"); |
| 1864 | FDCS->reset = 1; |
| 1865 | if (cont) { |
| 1866 | cont->done(0); |
| 1867 | cont->redo(); /* this will recall reset when needed */ |
| 1868 | } else { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 1869 | pr_info("no cont in shutdown!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | process_fd_request(); |
| 1871 | } |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 1872 | is_alive(__func__, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | /* start motor, check media-changed condition and write protection */ |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1876 | static int start_motor(void (*function)(void)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1878 | int mask; |
| 1879 | int data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | |
| 1881 | mask = 0xfc; |
| 1882 | data = UNIT(current_drive); |
| 1883 | if (!(raw_cmd->flags & FD_RAW_NO_MOTOR)) { |
| 1884 | if (!(FDCS->dor & (0x10 << UNIT(current_drive)))) { |
| 1885 | set_debugt(); |
| 1886 | /* no read since this drive is running */ |
| 1887 | DRS->first_read_date = 0; |
| 1888 | /* note motor start time if motor is not yet running */ |
| 1889 | DRS->spinup_date = jiffies; |
| 1890 | data |= (0x10 << UNIT(current_drive)); |
| 1891 | } |
| 1892 | } else if (FDCS->dor & (0x10 << UNIT(current_drive))) |
| 1893 | mask &= ~(0x10 << UNIT(current_drive)); |
| 1894 | |
| 1895 | /* starts motor and selects floppy */ |
| 1896 | del_timer(motor_off_timer + current_drive); |
| 1897 | set_dor(fdc, mask, data); |
| 1898 | |
| 1899 | /* wait_for_completion also schedules reset if needed. */ |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 1900 | return fd_wait_for_completion(DRS->select_date + DP->select_delay, |
| 1901 | (timeout_fn)function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | static void floppy_ready(void) |
| 1905 | { |
Joe Perches | 045f983 | 2010-03-10 15:20:47 -0800 | [diff] [blame] | 1906 | if (FDCS->reset) { |
| 1907 | reset_fdc(); |
| 1908 | return; |
| 1909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | if (start_motor(floppy_ready)) |
| 1911 | return; |
| 1912 | if (fdc_dtr()) |
| 1913 | return; |
| 1914 | |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 1915 | debug_dcl(DP->flags, "calling disk change from floppy_ready\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) && |
| 1917 | disk_change(current_drive) && !DP->select_delay) |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 1918 | twaddle(); /* this clears the dcl on certain |
| 1919 | * drive/controller combinations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
| 1921 | #ifdef fd_chose_dma_mode |
| 1922 | if ((raw_cmd->flags & FD_RAW_READ) || (raw_cmd->flags & FD_RAW_WRITE)) { |
| 1923 | unsigned long flags = claim_dma_lock(); |
| 1924 | fd_chose_dma_mode(raw_cmd->kernel_data, raw_cmd->length); |
| 1925 | release_dma_lock(flags); |
| 1926 | } |
| 1927 | #endif |
| 1928 | |
| 1929 | if (raw_cmd->flags & (FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK)) { |
| 1930 | perpendicular_mode(); |
| 1931 | fdc_specify(); /* must be done here because of hut, hlt ... */ |
| 1932 | seek_floppy(); |
| 1933 | } else { |
| 1934 | if ((raw_cmd->flags & FD_RAW_READ) || |
| 1935 | (raw_cmd->flags & FD_RAW_WRITE)) |
| 1936 | fdc_specify(); |
| 1937 | setup_rw_floppy(); |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | static void floppy_start(void) |
| 1942 | { |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 1943 | reschedule_timeout(current_reqD, "floppy start"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | |
| 1945 | scandrives(); |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 1946 | debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n"); |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 1947 | set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | floppy_ready(); |
| 1949 | } |
| 1950 | |
| 1951 | /* |
| 1952 | * ======================================================================== |
| 1953 | * here ends the bottom half. Exported routines are: |
| 1954 | * floppy_start, floppy_off, floppy_ready, lock_fdc, unlock_fdc, set_fdc, |
| 1955 | * start_motor, reset_fdc, reset_fdc_info, interpret_errors. |
| 1956 | * Initialization also uses output_byte, result, set_dor, floppy_interrupt |
| 1957 | * and set_dor. |
| 1958 | * ======================================================================== |
| 1959 | */ |
| 1960 | /* |
| 1961 | * General purpose continuations. |
| 1962 | * ============================== |
| 1963 | */ |
| 1964 | |
| 1965 | static void do_wakeup(void) |
| 1966 | { |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 1967 | reschedule_timeout(MAXTIMEOUT, "do wakeup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | cont = NULL; |
| 1969 | command_status += 2; |
| 1970 | wake_up(&command_done); |
| 1971 | } |
| 1972 | |
Stephen Hemminger | 3b06c21 | 2010-07-20 20:09:00 -0600 | [diff] [blame] | 1973 | static const struct cont_t wakeup_cont = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | .interrupt = empty, |
| 1975 | .redo = do_wakeup, |
| 1976 | .error = empty, |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1977 | .done = (done_f)empty |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | }; |
| 1979 | |
Stephen Hemminger | 3b06c21 | 2010-07-20 20:09:00 -0600 | [diff] [blame] | 1980 | static const struct cont_t intr_cont = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | .interrupt = empty, |
| 1982 | .redo = process_fd_request, |
| 1983 | .error = empty, |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 1984 | .done = (done_f)empty |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | }; |
| 1986 | |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 1987 | static int wait_til_done(void (*handler)(void), bool interruptible) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | { |
| 1989 | int ret; |
| 1990 | |
| 1991 | schedule_bh(handler); |
| 1992 | |
Stephen Hemminger | b862f26 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 1993 | if (interruptible) |
| 1994 | wait_event_interruptible(command_done, command_status >= 2); |
| 1995 | else |
| 1996 | wait_event(command_done, command_status >= 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | |
| 1998 | if (command_status < 2) { |
| 1999 | cancel_activity(); |
| 2000 | cont = &intr_cont; |
| 2001 | reset_fdc(); |
| 2002 | return -EINTR; |
| 2003 | } |
| 2004 | |
| 2005 | if (FDCS->reset) |
| 2006 | command_status = FD_COMMAND_ERROR; |
| 2007 | if (command_status == FD_COMMAND_OKAY) |
| 2008 | ret = 0; |
| 2009 | else |
| 2010 | ret = -EIO; |
| 2011 | command_status = FD_COMMAND_NONE; |
| 2012 | return ret; |
| 2013 | } |
| 2014 | |
| 2015 | static void generic_done(int result) |
| 2016 | { |
| 2017 | command_status = result; |
| 2018 | cont = &wakeup_cont; |
| 2019 | } |
| 2020 | |
| 2021 | static void generic_success(void) |
| 2022 | { |
| 2023 | cont->done(1); |
| 2024 | } |
| 2025 | |
| 2026 | static void generic_failure(void) |
| 2027 | { |
| 2028 | cont->done(0); |
| 2029 | } |
| 2030 | |
| 2031 | static void success_and_wakeup(void) |
| 2032 | { |
| 2033 | generic_success(); |
| 2034 | cont->redo(); |
| 2035 | } |
| 2036 | |
| 2037 | /* |
| 2038 | * formatting and rw support. |
| 2039 | * ========================== |
| 2040 | */ |
| 2041 | |
| 2042 | static int next_valid_format(void) |
| 2043 | { |
| 2044 | int probed_format; |
| 2045 | |
| 2046 | probed_format = DRS->probed_format; |
| 2047 | while (1) { |
| 2048 | if (probed_format >= 8 || !DP->autodetect[probed_format]) { |
| 2049 | DRS->probed_format = 0; |
| 2050 | return 1; |
| 2051 | } |
| 2052 | if (floppy_type[DP->autodetect[probed_format]].sect) { |
| 2053 | DRS->probed_format = probed_format; |
| 2054 | return 0; |
| 2055 | } |
| 2056 | probed_format++; |
| 2057 | } |
| 2058 | } |
| 2059 | |
| 2060 | static void bad_flp_intr(void) |
| 2061 | { |
| 2062 | int err_count; |
| 2063 | |
| 2064 | if (probing) { |
| 2065 | DRS->probed_format++; |
| 2066 | if (!next_valid_format()) |
| 2067 | return; |
| 2068 | } |
| 2069 | err_count = ++(*errors); |
| 2070 | INFBOUND(DRWE->badness, err_count); |
| 2071 | if (err_count > DP->max_errors.abort) |
| 2072 | cont->done(0); |
| 2073 | if (err_count > DP->max_errors.reset) |
| 2074 | FDCS->reset = 1; |
| 2075 | else if (err_count > DP->max_errors.recal) |
| 2076 | DRS->track = NEED_2_RECAL; |
| 2077 | } |
| 2078 | |
| 2079 | static void set_floppy(int drive) |
| 2080 | { |
| 2081 | int type = ITYPE(UDRS->fd_device); |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 2082 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | if (type) |
| 2084 | _floppy = floppy_type + type; |
| 2085 | else |
| 2086 | _floppy = current_type[drive]; |
| 2087 | } |
| 2088 | |
| 2089 | /* |
| 2090 | * formatting support. |
| 2091 | * =================== |
| 2092 | */ |
| 2093 | static void format_interrupt(void) |
| 2094 | { |
| 2095 | switch (interpret_errors()) { |
| 2096 | case 1: |
| 2097 | cont->error(); |
| 2098 | case 2: |
| 2099 | break; |
| 2100 | case 0: |
| 2101 | cont->done(1); |
| 2102 | } |
| 2103 | cont->redo(); |
| 2104 | } |
| 2105 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 2106 | #define FM_MODE(x, y) ((y) & ~(((x)->rate & 0x80) >> 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | #define CT(x) ((x) | 0xc0) |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 2108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | static void setup_format_params(int track) |
| 2110 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 2111 | int n; |
| 2112 | int il; |
| 2113 | int count; |
| 2114 | int head_shift; |
| 2115 | int track_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | struct fparm { |
| 2117 | unsigned char track, head, sect, size; |
| 2118 | } *here = (struct fparm *)floppy_track_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | |
| 2120 | raw_cmd = &default_raw_cmd; |
| 2121 | raw_cmd->track = track; |
| 2122 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 2123 | raw_cmd->flags = (FD_RAW_WRITE | FD_RAW_INTR | FD_RAW_SPIN | |
| 2124 | FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | raw_cmd->rate = _floppy->rate & 0x43; |
| 2126 | raw_cmd->cmd_count = NR_F; |
| 2127 | COMMAND = FM_MODE(_floppy, FD_FORMAT); |
| 2128 | DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head); |
| 2129 | F_SIZECODE = FD_SIZECODE(_floppy); |
| 2130 | F_SECT_PER_TRACK = _floppy->sect << 2 >> F_SIZECODE; |
| 2131 | F_GAP = _floppy->fmt_gap; |
| 2132 | F_FILL = FD_FILL_BYTE; |
| 2133 | |
| 2134 | raw_cmd->kernel_data = floppy_track_buffer; |
| 2135 | raw_cmd->length = 4 * F_SECT_PER_TRACK; |
| 2136 | |
| 2137 | /* allow for about 30ms for data transport per track */ |
| 2138 | head_shift = (F_SECT_PER_TRACK + 5) / 6; |
| 2139 | |
| 2140 | /* a ``cylinder'' is two tracks plus a little stepping time */ |
| 2141 | track_shift = 2 * head_shift + 3; |
| 2142 | |
| 2143 | /* position of logical sector 1 on this track */ |
| 2144 | n = (track_shift * format_req.track + head_shift * format_req.head) |
| 2145 | % F_SECT_PER_TRACK; |
| 2146 | |
| 2147 | /* determine interleave */ |
| 2148 | il = 1; |
| 2149 | if (_floppy->fmt_gap < 0x22) |
| 2150 | il++; |
| 2151 | |
| 2152 | /* initialize field */ |
| 2153 | for (count = 0; count < F_SECT_PER_TRACK; ++count) { |
| 2154 | here[count].track = format_req.track; |
| 2155 | here[count].head = format_req.head; |
| 2156 | here[count].sect = 0; |
| 2157 | here[count].size = F_SIZECODE; |
| 2158 | } |
| 2159 | /* place logical sectors */ |
| 2160 | for (count = 1; count <= F_SECT_PER_TRACK; ++count) { |
| 2161 | here[n].sect = count; |
| 2162 | n = (n + il) % F_SECT_PER_TRACK; |
| 2163 | if (here[n].sect) { /* sector busy, find next free sector */ |
| 2164 | ++n; |
| 2165 | if (n >= F_SECT_PER_TRACK) { |
| 2166 | n -= F_SECT_PER_TRACK; |
| 2167 | while (here[n].sect) |
| 2168 | ++n; |
| 2169 | } |
| 2170 | } |
| 2171 | } |
Keith Wansbrough | 9e49184 | 2008-09-22 14:57:17 -0700 | [diff] [blame] | 2172 | if (_floppy->stretch & FD_SECTBASEMASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | for (count = 0; count < F_SECT_PER_TRACK; count++) |
Keith Wansbrough | 9e49184 | 2008-09-22 14:57:17 -0700 | [diff] [blame] | 2174 | here[count].sect += FD_SECTBASE(_floppy) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | static void redo_format(void) |
| 2179 | { |
| 2180 | buffer_track = -1; |
| 2181 | setup_format_params(format_req.track << STRETCH(_floppy)); |
| 2182 | floppy_start(); |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 2183 | debugt(__func__, "queue format request"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
Stephen Hemminger | 3b06c21 | 2010-07-20 20:09:00 -0600 | [diff] [blame] | 2186 | static const struct cont_t format_cont = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | .interrupt = format_interrupt, |
| 2188 | .redo = redo_format, |
| 2189 | .error = bad_flp_intr, |
| 2190 | .done = generic_done |
| 2191 | }; |
| 2192 | |
| 2193 | static int do_format(int drive, struct format_descr *tmp_format_req) |
| 2194 | { |
| 2195 | int ret; |
| 2196 | |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 2197 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 2198 | return -EINTR; |
| 2199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | set_floppy(drive); |
| 2201 | if (!_floppy || |
| 2202 | _floppy->track > DP->tracks || |
| 2203 | tmp_format_req->track >= _floppy->track || |
| 2204 | tmp_format_req->head >= _floppy->head || |
| 2205 | (_floppy->sect << 2) % (1 << FD_SIZECODE(_floppy)) || |
| 2206 | !_floppy->fmt_gap) { |
| 2207 | process_fd_request(); |
| 2208 | return -EINVAL; |
| 2209 | } |
| 2210 | format_req = *tmp_format_req; |
| 2211 | format_errors = 0; |
| 2212 | cont = &format_cont; |
| 2213 | errors = &format_errors; |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 2214 | ret = wait_til_done(redo_format, true); |
Joe Perches | 55eee80 | 2010-03-10 15:20:57 -0800 | [diff] [blame] | 2215 | if (ret == -EINTR) |
| 2216 | return -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | process_fd_request(); |
| 2218 | return ret; |
| 2219 | } |
| 2220 | |
| 2221 | /* |
| 2222 | * Buffer read/write and support |
| 2223 | * ============================= |
| 2224 | */ |
| 2225 | |
Kiyoshi Ueda | 1c5093b | 2008-01-28 10:36:21 +0100 | [diff] [blame] | 2226 | static void floppy_end_request(struct request *req, int error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | { |
| 2228 | unsigned int nr_sectors = current_count_sectors; |
Kiyoshi Ueda | 1c5093b | 2008-01-28 10:36:21 +0100 | [diff] [blame] | 2229 | unsigned int drive = (unsigned long)req->rq_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | |
| 2231 | /* current_count_sectors can be zero if transfer failed */ |
Kiyoshi Ueda | 1c5093b | 2008-01-28 10:36:21 +0100 | [diff] [blame] | 2232 | if (error) |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2233 | nr_sectors = blk_rq_cur_sectors(req); |
Kiyoshi Ueda | 1c5093b | 2008-01-28 10:36:21 +0100 | [diff] [blame] | 2234 | if (__blk_end_request(req, error, nr_sectors << 9)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | |
| 2237 | /* We're done with the request */ |
Kiyoshi Ueda | 1c5093b | 2008-01-28 10:36:21 +0100 | [diff] [blame] | 2238 | floppy_off(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | current_req = NULL; |
| 2240 | } |
| 2241 | |
| 2242 | /* new request_done. Can handle physical sectors which are smaller than a |
| 2243 | * logical buffer */ |
| 2244 | static void request_done(int uptodate) |
| 2245 | { |
| 2246 | struct request_queue *q = floppy_queue; |
| 2247 | struct request *req = current_req; |
| 2248 | unsigned long flags; |
| 2249 | int block; |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2250 | char msg[sizeof("request done ") + sizeof(int) * 3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | |
| 2252 | probing = 0; |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2253 | snprintf(msg, sizeof(msg), "request done %d", uptodate); |
| 2254 | reschedule_timeout(MAXTIMEOUT, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | |
| 2256 | if (!req) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2257 | pr_info("floppy.c: no request in request_done\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | return; |
| 2259 | } |
| 2260 | |
| 2261 | if (uptodate) { |
| 2262 | /* maintain values for invalidation on geometry |
| 2263 | * change */ |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2264 | block = current_count_sectors + blk_rq_pos(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | INFBOUND(DRS->maxblock, block); |
| 2266 | if (block > _floppy->sect) |
| 2267 | DRS->maxtrack = 1; |
| 2268 | |
| 2269 | /* unlock chained buffers */ |
| 2270 | spin_lock_irqsave(q->queue_lock, flags); |
Kiyoshi Ueda | 1c5093b | 2008-01-28 10:36:21 +0100 | [diff] [blame] | 2271 | floppy_end_request(req, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 2273 | } else { |
| 2274 | if (rq_data_dir(req) == WRITE) { |
| 2275 | /* record write error information */ |
| 2276 | DRWE->write_errors++; |
| 2277 | if (DRWE->write_errors == 1) { |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2278 | DRWE->first_error_sector = blk_rq_pos(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | DRWE->first_error_generation = DRS->generation; |
| 2280 | } |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2281 | DRWE->last_error_sector = blk_rq_pos(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | DRWE->last_error_generation = DRS->generation; |
| 2283 | } |
| 2284 | spin_lock_irqsave(q->queue_lock, flags); |
Kiyoshi Ueda | 1c5093b | 2008-01-28 10:36:21 +0100 | [diff] [blame] | 2285 | floppy_end_request(req, -EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | spin_unlock_irqrestore(q->queue_lock, flags); |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | /* Interrupt handler evaluating the result of the r/w operation */ |
| 2291 | static void rw_interrupt(void) |
| 2292 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 2293 | int eoc; |
| 2294 | int ssize; |
| 2295 | int heads; |
| 2296 | int nr_sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | |
| 2298 | if (R_HEAD >= 2) { |
| 2299 | /* some Toshiba floppy controllers occasionnally seem to |
| 2300 | * return bogus interrupts after read/write operations, which |
| 2301 | * can be recognized by a bad head number (>= 2) */ |
| 2302 | return; |
| 2303 | } |
| 2304 | |
| 2305 | if (!DRS->first_read_date) |
| 2306 | DRS->first_read_date = jiffies; |
| 2307 | |
| 2308 | nr_sectors = 0; |
Joe Perches | 712e1de | 2010-03-10 15:21:10 -0800 | [diff] [blame] | 2309 | ssize = DIV_ROUND_UP(1 << SIZECODE, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | |
| 2311 | if (ST1 & ST1_EOC) |
| 2312 | eoc = 1; |
| 2313 | else |
| 2314 | eoc = 0; |
| 2315 | |
| 2316 | if (COMMAND & 0x80) |
| 2317 | heads = 2; |
| 2318 | else |
| 2319 | heads = 1; |
| 2320 | |
| 2321 | nr_sectors = (((R_TRACK - TRACK) * heads + |
| 2322 | R_HEAD - HEAD) * SECT_PER_TRACK + |
| 2323 | R_SECTOR - SECTOR + eoc) << SIZECODE >> 2; |
| 2324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | if (nr_sectors / ssize > |
Julia Lawall | 061837b | 2008-09-22 14:57:16 -0700 | [diff] [blame] | 2326 | DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | DPRINT("long rw: %x instead of %lx\n", |
| 2328 | nr_sectors, current_count_sectors); |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2329 | pr_info("rs=%d s=%d\n", R_SECTOR, SECTOR); |
| 2330 | pr_info("rh=%d h=%d\n", R_HEAD, HEAD); |
| 2331 | pr_info("rt=%d t=%d\n", R_TRACK, TRACK); |
| 2332 | pr_info("heads=%d eoc=%d\n", heads, eoc); |
| 2333 | pr_info("spt=%d st=%d ss=%d\n", |
| 2334 | SECT_PER_TRACK, fsector_t, ssize); |
| 2335 | pr_info("in_sector_offset=%d\n", in_sector_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | |
| 2338 | nr_sectors -= in_sector_offset; |
| 2339 | INFBOUND(nr_sectors, 0); |
| 2340 | SUPBOUND(current_count_sectors, nr_sectors); |
| 2341 | |
| 2342 | switch (interpret_errors()) { |
| 2343 | case 2: |
| 2344 | cont->redo(); |
| 2345 | return; |
| 2346 | case 1: |
| 2347 | if (!current_count_sectors) { |
| 2348 | cont->error(); |
| 2349 | cont->redo(); |
| 2350 | return; |
| 2351 | } |
| 2352 | break; |
| 2353 | case 0: |
| 2354 | if (!current_count_sectors) { |
| 2355 | cont->redo(); |
| 2356 | return; |
| 2357 | } |
| 2358 | current_type[current_drive] = _floppy; |
| 2359 | floppy_sizes[TOMINOR(current_drive)] = _floppy->size; |
| 2360 | break; |
| 2361 | } |
| 2362 | |
| 2363 | if (probing) { |
| 2364 | if (DP->flags & FTD_MSG) |
| 2365 | DPRINT("Auto-detected floppy type %s in fd%d\n", |
| 2366 | _floppy->name, current_drive); |
| 2367 | current_type[current_drive] = _floppy; |
| 2368 | floppy_sizes[TOMINOR(current_drive)] = _floppy->size; |
| 2369 | probing = 0; |
| 2370 | } |
| 2371 | |
| 2372 | if (CT(COMMAND) != FD_READ || |
| 2373 | raw_cmd->kernel_data == current_req->buffer) { |
| 2374 | /* transfer directly from buffer */ |
| 2375 | cont->done(1); |
| 2376 | } else if (CT(COMMAND) == FD_READ) { |
| 2377 | buffer_track = raw_cmd->track; |
| 2378 | buffer_drive = current_drive; |
| 2379 | INFBOUND(buffer_max, nr_sectors + fsector_t); |
| 2380 | } |
| 2381 | cont->redo(); |
| 2382 | } |
| 2383 | |
| 2384 | /* Compute maximal contiguous buffer size. */ |
| 2385 | static int buffer_chain_size(void) |
| 2386 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | struct bio_vec *bv; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2388 | int size; |
| 2389 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | char *base; |
| 2391 | |
| 2392 | base = bio_data(current_req->bio); |
| 2393 | size = 0; |
| 2394 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2395 | rq_for_each_segment(bv, current_req, iter) { |
| 2396 | if (page_address(bv->bv_page) + bv->bv_offset != base + size) |
| 2397 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2399 | size += bv->bv_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | return size >> 9; |
| 2403 | } |
| 2404 | |
| 2405 | /* Compute the maximal transfer size */ |
| 2406 | static int transfer_size(int ssize, int max_sector, int max_size) |
| 2407 | { |
| 2408 | SUPBOUND(max_sector, fsector_t + max_size); |
| 2409 | |
| 2410 | /* alignment */ |
| 2411 | max_sector -= (max_sector % _floppy->sect) % ssize; |
| 2412 | |
| 2413 | /* transfer size, beginning not aligned */ |
| 2414 | current_count_sectors = max_sector - fsector_t; |
| 2415 | |
| 2416 | return max_sector; |
| 2417 | } |
| 2418 | |
| 2419 | /* |
| 2420 | * Move data from/to the track buffer to/from the buffer cache. |
| 2421 | */ |
| 2422 | static void copy_buffer(int ssize, int max_sector, int max_sector_2) |
| 2423 | { |
| 2424 | int remaining; /* number of transferred 512-byte sectors */ |
| 2425 | struct bio_vec *bv; |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 2426 | char *buffer; |
| 2427 | char *dma_buffer; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2428 | int size; |
| 2429 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | |
| 2431 | max_sector = transfer_size(ssize, |
| 2432 | min(max_sector, max_sector_2), |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2433 | blk_rq_sectors(current_req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | |
| 2435 | if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE && |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2436 | buffer_max > fsector_t + blk_rq_sectors(current_req)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | current_count_sectors = min_t(int, buffer_max - fsector_t, |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2438 | blk_rq_sectors(current_req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | |
| 2440 | remaining = current_count_sectors << 9; |
Tejun Heo | 1011c1b | 2009-05-07 22:24:45 +0900 | [diff] [blame] | 2441 | if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | DPRINT("in copy buffer\n"); |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2443 | pr_info("current_count_sectors=%ld\n", current_count_sectors); |
| 2444 | pr_info("remaining=%d\n", remaining >> 9); |
| 2445 | pr_info("current_req->nr_sectors=%u\n", |
| 2446 | blk_rq_sectors(current_req)); |
| 2447 | pr_info("current_req->current_nr_sectors=%u\n", |
| 2448 | blk_rq_cur_sectors(current_req)); |
| 2449 | pr_info("max_sector=%d\n", max_sector); |
| 2450 | pr_info("ssize=%d\n", ssize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | |
| 2453 | buffer_max = max(max_sector, buffer_max); |
| 2454 | |
| 2455 | dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9); |
| 2456 | |
Tejun Heo | 1011c1b | 2009-05-07 22:24:45 +0900 | [diff] [blame] | 2457 | size = blk_rq_cur_bytes(current_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2459 | rq_for_each_segment(bv, current_req, iter) { |
| 2460 | if (!remaining) |
| 2461 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2463 | size = bv->bv_len; |
| 2464 | SUPBOUND(size, remaining); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2466 | buffer = page_address(bv->bv_page) + bv->bv_offset; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2467 | if (dma_buffer + size > |
| 2468 | floppy_track_buffer + (max_buffer_sectors << 10) || |
| 2469 | dma_buffer < floppy_track_buffer) { |
| 2470 | DPRINT("buffer overrun in copy buffer %d\n", |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2471 | (int)((floppy_track_buffer - dma_buffer) >> 9)); |
| 2472 | pr_info("fsector_t=%d buffer_min=%d\n", |
| 2473 | fsector_t, buffer_min); |
| 2474 | pr_info("current_count_sectors=%ld\n", |
| 2475 | current_count_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2476 | if (CT(COMMAND) == FD_READ) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2477 | pr_info("read\n"); |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2478 | if (CT(COMMAND) == FD_WRITE) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2479 | pr_info("write\n"); |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2480 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | } |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2482 | if (((unsigned long)buffer) % 512) |
| 2483 | DPRINT("%p buffer not aligned\n", buffer); |
Joe Perches | 1a23d13 | 2010-03-10 15:21:04 -0800 | [diff] [blame] | 2484 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 2485 | if (CT(COMMAND) == FD_READ) |
| 2486 | memcpy(buffer, dma_buffer, size); |
| 2487 | else |
| 2488 | memcpy(dma_buffer, buffer, size); |
| 2489 | |
| 2490 | remaining -= size; |
| 2491 | dma_buffer += size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | if (remaining) { |
| 2494 | if (remaining > 0) |
| 2495 | max_sector -= remaining >> 9; |
| 2496 | DPRINT("weirdness: remaining %d\n", remaining >> 9); |
| 2497 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | /* work around a bug in pseudo DMA |
| 2501 | * (on some FDCs) pseudo DMA does not stop when the CPU stops |
| 2502 | * sending data. Hence we need a different way to signal the |
| 2503 | * transfer length: We use SECT_PER_TRACK. Unfortunately, this |
| 2504 | * does not work with MT, hence we can only transfer one head at |
| 2505 | * a time |
| 2506 | */ |
| 2507 | static void virtualdmabug_workaround(void) |
| 2508 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 2509 | int hard_sectors; |
| 2510 | int end_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | |
| 2512 | if (CT(COMMAND) == FD_WRITE) { |
| 2513 | COMMAND &= ~0x80; /* switch off multiple track mode */ |
| 2514 | |
| 2515 | hard_sectors = raw_cmd->length >> (7 + SIZECODE); |
| 2516 | end_sector = SECTOR + hard_sectors - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | if (end_sector > SECT_PER_TRACK) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2518 | pr_info("too many sectors %d > %d\n", |
| 2519 | end_sector, SECT_PER_TRACK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | return; |
| 2521 | } |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 2522 | SECT_PER_TRACK = end_sector; |
| 2523 | /* make sure SECT_PER_TRACK |
| 2524 | * points to end of transfer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | /* |
| 2529 | * Formulate a read/write request. |
| 2530 | * this routine decides where to load the data (directly to buffer, or to |
| 2531 | * tmp floppy area), how much data to load (the size of the buffer, the whole |
| 2532 | * track, or a single sector) |
| 2533 | * All floppy_track_buffer handling goes in here. If we ever add track buffer |
| 2534 | * allocation on the fly, it should be done here. No other part should need |
| 2535 | * modification. |
| 2536 | */ |
| 2537 | |
| 2538 | static int make_raw_rw_request(void) |
| 2539 | { |
| 2540 | int aligned_sector_t; |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 2541 | int max_sector; |
| 2542 | int max_size; |
| 2543 | int tracksize; |
| 2544 | int ssize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | |
Stephen Hemminger | 01b6b67 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 2546 | if (WARN(max_buffer_sectors == 0, "VFS: Block I/O scheduled on unopened device\n")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | |
| 2549 | set_fdc((long)current_req->rq_disk->private_data); |
| 2550 | |
| 2551 | raw_cmd = &default_raw_cmd; |
| 2552 | raw_cmd->flags = FD_RAW_SPIN | FD_RAW_NEED_DISK | FD_RAW_NEED_DISK | |
| 2553 | FD_RAW_NEED_SEEK; |
| 2554 | raw_cmd->cmd_count = NR_RW; |
| 2555 | if (rq_data_dir(current_req) == READ) { |
| 2556 | raw_cmd->flags |= FD_RAW_READ; |
| 2557 | COMMAND = FM_MODE(_floppy, FD_READ); |
| 2558 | } else if (rq_data_dir(current_req) == WRITE) { |
| 2559 | raw_cmd->flags |= FD_RAW_WRITE; |
| 2560 | COMMAND = FM_MODE(_floppy, FD_WRITE); |
| 2561 | } else { |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 2562 | DPRINT("%s: unknown command\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2563 | return 0; |
| 2564 | } |
| 2565 | |
| 2566 | max_sector = _floppy->sect * _floppy->head; |
| 2567 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2568 | TRACK = (int)blk_rq_pos(current_req) / max_sector; |
| 2569 | fsector_t = (int)blk_rq_pos(current_req) % max_sector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | if (_floppy->track && TRACK >= _floppy->track) { |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2571 | if (blk_rq_cur_sectors(current_req) & 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | current_count_sectors = 1; |
| 2573 | return 1; |
| 2574 | } else |
| 2575 | return 0; |
| 2576 | } |
| 2577 | HEAD = fsector_t / _floppy->sect; |
| 2578 | |
Keith Wansbrough | 9e49184 | 2008-09-22 14:57:17 -0700 | [diff] [blame] | 2579 | if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) || |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 2580 | test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) && |
| 2581 | fsector_t < _floppy->sect) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | max_sector = _floppy->sect; |
| 2583 | |
| 2584 | /* 2M disks have phantom sectors on the first track */ |
| 2585 | if ((_floppy->rate & FD_2M) && (!TRACK) && (!HEAD)) { |
| 2586 | max_sector = 2 * _floppy->sect / 3; |
| 2587 | if (fsector_t >= max_sector) { |
| 2588 | current_count_sectors = |
| 2589 | min_t(int, _floppy->sect - fsector_t, |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2590 | blk_rq_sectors(current_req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | return 1; |
| 2592 | } |
| 2593 | SIZECODE = 2; |
| 2594 | } else |
| 2595 | SIZECODE = FD_SIZECODE(_floppy); |
| 2596 | raw_cmd->rate = _floppy->rate & 0x43; |
| 2597 | if ((_floppy->rate & FD_2M) && (TRACK || HEAD) && raw_cmd->rate == 2) |
| 2598 | raw_cmd->rate = 1; |
| 2599 | |
| 2600 | if (SIZECODE) |
| 2601 | SIZECODE2 = 0xff; |
| 2602 | else |
| 2603 | SIZECODE2 = 0x80; |
| 2604 | raw_cmd->track = TRACK << STRETCH(_floppy); |
| 2605 | DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, HEAD); |
| 2606 | GAP = _floppy->gap; |
Joe Perches | 712e1de | 2010-03-10 15:21:10 -0800 | [diff] [blame] | 2607 | ssize = DIV_ROUND_UP(1 << SIZECODE, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | SECT_PER_TRACK = _floppy->sect << 2 >> SIZECODE; |
| 2609 | SECTOR = ((fsector_t % _floppy->sect) << 2 >> SIZECODE) + |
Keith Wansbrough | 9e49184 | 2008-09-22 14:57:17 -0700 | [diff] [blame] | 2610 | FD_SECTBASE(_floppy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | |
| 2612 | /* tracksize describes the size which can be filled up with sectors |
| 2613 | * of size ssize. |
| 2614 | */ |
| 2615 | tracksize = _floppy->sect - _floppy->sect % ssize; |
| 2616 | if (tracksize < _floppy->sect) { |
| 2617 | SECT_PER_TRACK++; |
| 2618 | if (tracksize <= fsector_t % _floppy->sect) |
| 2619 | SECTOR--; |
| 2620 | |
| 2621 | /* if we are beyond tracksize, fill up using smaller sectors */ |
| 2622 | while (tracksize <= fsector_t % _floppy->sect) { |
| 2623 | while (tracksize + ssize > _floppy->sect) { |
| 2624 | SIZECODE--; |
| 2625 | ssize >>= 1; |
| 2626 | } |
| 2627 | SECTOR++; |
| 2628 | SECT_PER_TRACK++; |
| 2629 | tracksize += ssize; |
| 2630 | } |
| 2631 | max_sector = HEAD * _floppy->sect + tracksize; |
| 2632 | } else if (!TRACK && !HEAD && !(_floppy->rate & FD_2M) && probing) { |
| 2633 | max_sector = _floppy->sect; |
| 2634 | } else if (!HEAD && CT(COMMAND) == FD_WRITE) { |
| 2635 | /* for virtual DMA bug workaround */ |
| 2636 | max_sector = _floppy->sect; |
| 2637 | } |
| 2638 | |
| 2639 | in_sector_offset = (fsector_t % _floppy->sect) % ssize; |
| 2640 | aligned_sector_t = fsector_t - in_sector_offset; |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2641 | max_size = blk_rq_sectors(current_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | if ((raw_cmd->track == buffer_track) && |
| 2643 | (current_drive == buffer_drive) && |
| 2644 | (fsector_t >= buffer_min) && (fsector_t < buffer_max)) { |
| 2645 | /* data already in track buffer */ |
| 2646 | if (CT(COMMAND) == FD_READ) { |
| 2647 | copy_buffer(1, max_sector, buffer_max); |
| 2648 | return 1; |
| 2649 | } |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2650 | } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | if (CT(COMMAND) == FD_WRITE) { |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 2652 | unsigned int sectors; |
| 2653 | |
| 2654 | sectors = fsector_t + blk_rq_sectors(current_req); |
| 2655 | if (sectors > ssize && sectors < ssize + ssize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | max_size = ssize + ssize; |
| 2657 | else |
| 2658 | max_size = ssize; |
| 2659 | } |
| 2660 | raw_cmd->flags &= ~FD_RAW_WRITE; |
| 2661 | raw_cmd->flags |= FD_RAW_READ; |
| 2662 | COMMAND = FM_MODE(_floppy, FD_READ); |
| 2663 | } else if ((unsigned long)current_req->buffer < MAX_DMA_ADDRESS) { |
| 2664 | unsigned long dma_limit; |
| 2665 | int direct, indirect; |
| 2666 | |
| 2667 | indirect = |
| 2668 | transfer_size(ssize, max_sector, |
| 2669 | max_buffer_sectors * 2) - fsector_t; |
| 2670 | |
| 2671 | /* |
| 2672 | * Do NOT use minimum() here---MAX_DMA_ADDRESS is 64 bits wide |
| 2673 | * on a 64 bit machine! |
| 2674 | */ |
| 2675 | max_size = buffer_chain_size(); |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 2676 | dma_limit = (MAX_DMA_ADDRESS - |
| 2677 | ((unsigned long)current_req->buffer)) >> 9; |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2678 | if ((unsigned long)max_size > dma_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2679 | max_size = dma_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | /* 64 kb boundaries */ |
| 2681 | if (CROSS_64KB(current_req->buffer, max_size << 9)) |
| 2682 | max_size = (K_64 - |
| 2683 | ((unsigned long)current_req->buffer) % |
| 2684 | K_64) >> 9; |
| 2685 | direct = transfer_size(ssize, max_sector, max_size) - fsector_t; |
| 2686 | /* |
| 2687 | * We try to read tracks, but if we get too many errors, we |
| 2688 | * go back to reading just one sector at a time. |
| 2689 | * |
| 2690 | * This means we should be able to read a sector even if there |
| 2691 | * are other bad sectors on this track. |
| 2692 | */ |
| 2693 | if (!direct || |
| 2694 | (indirect * 2 > direct * 3 && |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 2695 | *errors < DP->max_errors.read_track && |
| 2696 | ((!probing || |
| 2697 | (DP->read_track & (1 << DRS->probed_format)))))) { |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2698 | max_size = blk_rq_sectors(current_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | } else { |
| 2700 | raw_cmd->kernel_data = current_req->buffer; |
| 2701 | raw_cmd->length = current_count_sectors << 9; |
| 2702 | if (raw_cmd->length == 0) { |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 2703 | DPRINT("%s: zero dma transfer attempted\n", __func__); |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 2704 | DPRINT("indirect=%d direct=%d fsector_t=%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | indirect, direct, fsector_t); |
| 2706 | return 0; |
| 2707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | virtualdmabug_workaround(); |
| 2709 | return 2; |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | if (CT(COMMAND) == FD_READ) |
| 2714 | max_size = max_sector; /* unbounded */ |
| 2715 | |
| 2716 | /* claim buffer track if needed */ |
| 2717 | if (buffer_track != raw_cmd->track || /* bad track */ |
| 2718 | buffer_drive != current_drive || /* bad drive */ |
| 2719 | fsector_t > buffer_max || |
| 2720 | fsector_t < buffer_min || |
| 2721 | ((CT(COMMAND) == FD_READ || |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2722 | (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | max_sector > 2 * max_buffer_sectors + buffer_min && |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 2724 | max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)) { |
| 2725 | /* not enough space */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | buffer_track = -1; |
| 2727 | buffer_drive = current_drive; |
| 2728 | buffer_max = buffer_min = aligned_sector_t; |
| 2729 | } |
| 2730 | raw_cmd->kernel_data = floppy_track_buffer + |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 2731 | ((aligned_sector_t - buffer_min) << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
| 2733 | if (CT(COMMAND) == FD_WRITE) { |
| 2734 | /* copy write buffer to track buffer. |
| 2735 | * if we get here, we know that the write |
| 2736 | * is either aligned or the data already in the buffer |
| 2737 | * (buffer will be overwritten) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | if (in_sector_offset && buffer_track == -1) |
| 2739 | DPRINT("internal error offset !=0 on write\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | buffer_track = raw_cmd->track; |
| 2741 | buffer_drive = current_drive; |
| 2742 | copy_buffer(ssize, max_sector, |
| 2743 | 2 * max_buffer_sectors + buffer_min); |
| 2744 | } else |
| 2745 | transfer_size(ssize, max_sector, |
| 2746 | 2 * max_buffer_sectors + buffer_min - |
| 2747 | aligned_sector_t); |
| 2748 | |
| 2749 | /* round up current_count_sectors to get dma xfer size */ |
| 2750 | raw_cmd->length = in_sector_offset + current_count_sectors; |
| 2751 | raw_cmd->length = ((raw_cmd->length - 1) | (ssize - 1)) + 1; |
| 2752 | raw_cmd->length <<= 9; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | if ((raw_cmd->length < current_count_sectors << 9) || |
| 2754 | (raw_cmd->kernel_data != current_req->buffer && |
| 2755 | CT(COMMAND) == FD_WRITE && |
| 2756 | (aligned_sector_t + (raw_cmd->length >> 9) > buffer_max || |
| 2757 | aligned_sector_t < buffer_min)) || |
| 2758 | raw_cmd->length % (128 << SIZECODE) || |
| 2759 | raw_cmd->length <= 0 || current_count_sectors <= 0) { |
| 2760 | DPRINT("fractionary current count b=%lx s=%lx\n", |
| 2761 | raw_cmd->length, current_count_sectors); |
| 2762 | if (raw_cmd->kernel_data != current_req->buffer) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2763 | pr_info("addr=%d, length=%ld\n", |
| 2764 | (int)((raw_cmd->kernel_data - |
| 2765 | floppy_track_buffer) >> 9), |
| 2766 | current_count_sectors); |
| 2767 | pr_info("st=%d ast=%d mse=%d msi=%d\n", |
| 2768 | fsector_t, aligned_sector_t, max_sector, max_size); |
| 2769 | pr_info("ssize=%x SIZECODE=%d\n", ssize, SIZECODE); |
| 2770 | pr_info("command=%x SECTOR=%d HEAD=%d, TRACK=%d\n", |
| 2771 | COMMAND, SECTOR, HEAD, TRACK); |
| 2772 | pr_info("buffer drive=%d\n", buffer_drive); |
| 2773 | pr_info("buffer track=%d\n", buffer_track); |
| 2774 | pr_info("buffer_min=%d\n", buffer_min); |
| 2775 | pr_info("buffer_max=%d\n", buffer_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | return 0; |
| 2777 | } |
| 2778 | |
| 2779 | if (raw_cmd->kernel_data != current_req->buffer) { |
| 2780 | if (raw_cmd->kernel_data < floppy_track_buffer || |
| 2781 | current_count_sectors < 0 || |
| 2782 | raw_cmd->length < 0 || |
| 2783 | raw_cmd->kernel_data + raw_cmd->length > |
| 2784 | floppy_track_buffer + (max_buffer_sectors << 10)) { |
| 2785 | DPRINT("buffer overrun in schedule dma\n"); |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2786 | pr_info("fsector_t=%d buffer_min=%d current_count=%ld\n", |
| 2787 | fsector_t, buffer_min, raw_cmd->length >> 9); |
| 2788 | pr_info("current_count_sectors=%ld\n", |
| 2789 | current_count_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | if (CT(COMMAND) == FD_READ) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2791 | pr_info("read\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | if (CT(COMMAND) == FD_WRITE) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2793 | pr_info("write\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | return 0; |
| 2795 | } |
Tejun Heo | 1011c1b | 2009-05-07 22:24:45 +0900 | [diff] [blame] | 2796 | } else if (raw_cmd->length > blk_rq_bytes(current_req) || |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2797 | current_count_sectors > blk_rq_sectors(current_req)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | DPRINT("buffer overrun in direct transfer\n"); |
| 2799 | return 0; |
| 2800 | } else if (raw_cmd->length < current_count_sectors << 9) { |
| 2801 | DPRINT("more sectors than bytes\n"); |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2802 | pr_info("bytes=%ld\n", raw_cmd->length >> 9); |
| 2803 | pr_info("sectors=%ld\n", current_count_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | } |
| 2805 | if (raw_cmd->length == 0) { |
| 2806 | DPRINT("zero dma transfer attempted from make_raw_request\n"); |
| 2807 | return 0; |
| 2808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | |
| 2810 | virtualdmabug_workaround(); |
| 2811 | return 2; |
| 2812 | } |
| 2813 | |
| 2814 | static void redo_fd_request(void) |
| 2815 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | int drive; |
| 2817 | int tmp; |
| 2818 | |
| 2819 | lastredo = jiffies; |
| 2820 | if (current_drive < N_DRIVE) |
| 2821 | floppy_off(current_drive); |
| 2822 | |
Joe Perches | 0da3132 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2823 | do_request: |
| 2824 | if (!current_req) { |
| 2825 | struct request *req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | |
Joe Perches | 0da3132 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2827 | spin_lock_irq(floppy_queue->queue_lock); |
| 2828 | req = blk_fetch_request(floppy_queue); |
| 2829 | spin_unlock_irq(floppy_queue->queue_lock); |
| 2830 | if (!req) { |
| 2831 | do_floppy = NULL; |
| 2832 | unlock_fdc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | } |
Joe Perches | 0da3132 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2835 | current_req = req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | } |
Joe Perches | 0da3132 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2837 | drive = (long)current_req->rq_disk->private_data; |
| 2838 | set_fdc(drive); |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2839 | reschedule_timeout(current_reqD, "redo fd request"); |
Joe Perches | 0da3132 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2840 | |
| 2841 | set_floppy(drive); |
| 2842 | raw_cmd = &default_raw_cmd; |
| 2843 | raw_cmd->flags = 0; |
| 2844 | if (start_motor(redo_fd_request)) |
| 2845 | return; |
| 2846 | |
| 2847 | disk_change(current_drive); |
| 2848 | if (test_bit(current_drive, &fake_change) || |
| 2849 | test_bit(FD_DISK_CHANGED_BIT, &DRS->flags)) { |
| 2850 | DPRINT("disk absent or changed during operation\n"); |
| 2851 | request_done(0); |
| 2852 | goto do_request; |
| 2853 | } |
| 2854 | if (!_floppy) { /* Autodetection */ |
| 2855 | if (!probing) { |
| 2856 | DRS->probed_format = 0; |
| 2857 | if (next_valid_format()) { |
| 2858 | DPRINT("no autodetectable formats\n"); |
| 2859 | _floppy = NULL; |
| 2860 | request_done(0); |
| 2861 | goto do_request; |
| 2862 | } |
| 2863 | } |
| 2864 | probing = 1; |
| 2865 | _floppy = floppy_type + DP->autodetect[DRS->probed_format]; |
| 2866 | } else |
| 2867 | probing = 0; |
| 2868 | errors = &(current_req->errors); |
| 2869 | tmp = make_raw_rw_request(); |
| 2870 | if (tmp < 2) { |
| 2871 | request_done(tmp); |
| 2872 | goto do_request; |
| 2873 | } |
| 2874 | |
| 2875 | if (test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) |
| 2876 | twaddle(); |
| 2877 | schedule_bh(floppy_start); |
Joe Perches | ded2863 | 2010-03-10 15:21:09 -0800 | [diff] [blame] | 2878 | debugt(__func__, "queue fd request"); |
Joe Perches | 0da3132 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 2879 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | } |
| 2881 | |
Stephen Hemminger | 3b06c21 | 2010-07-20 20:09:00 -0600 | [diff] [blame] | 2882 | static const struct cont_t rw_cont = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | .interrupt = rw_interrupt, |
| 2884 | .redo = redo_fd_request, |
| 2885 | .error = bad_flp_intr, |
| 2886 | .done = request_done |
| 2887 | }; |
| 2888 | |
| 2889 | static void process_fd_request(void) |
| 2890 | { |
| 2891 | cont = &rw_cont; |
| 2892 | schedule_bh(redo_fd_request); |
| 2893 | } |
| 2894 | |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 2895 | static void do_fd_request(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | { |
Stephen Hemminger | 01b6b67 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 2897 | if (WARN(max_buffer_sectors == 0, |
| 2898 | "VFS: %s called on non-open device\n", __func__)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | |
Stephen Hemminger | 01b6b67 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 2901 | if (WARN(atomic_read(&usage_count) == 0, |
| 2902 | "warning: usage count=0, current_req=%p sect=%ld type=%x flags=%x\n", |
| 2903 | current_req, (long)blk_rq_pos(current_req), current_req->cmd_type, |
| 2904 | current_req->cmd_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | return; |
Stephen Hemminger | 01b6b67 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 2906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | if (test_bit(0, &fdc_busy)) { |
| 2908 | /* fdc busy, this new request will be treated when the |
| 2909 | current one is done */ |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 2910 | is_alive(__func__, "old request running"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | return; |
| 2912 | } |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 2913 | lock_fdc(MAXTIMEOUT, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | process_fd_request(); |
Joe Perches | 275176b | 2010-03-10 15:21:06 -0800 | [diff] [blame] | 2915 | is_alive(__func__, ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
Stephen Hemminger | 3b06c21 | 2010-07-20 20:09:00 -0600 | [diff] [blame] | 2918 | static const struct cont_t poll_cont = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | .interrupt = success_and_wakeup, |
| 2920 | .redo = floppy_ready, |
| 2921 | .error = generic_failure, |
| 2922 | .done = generic_done |
| 2923 | }; |
| 2924 | |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 2925 | static int poll_drive(bool interruptible, int flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | /* no auto-sense, just clear dcl */ |
| 2928 | raw_cmd = &default_raw_cmd; |
| 2929 | raw_cmd->flags = flag; |
| 2930 | raw_cmd->track = 0; |
| 2931 | raw_cmd->cmd_count = 0; |
| 2932 | cont = &poll_cont; |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 2933 | debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n"); |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 2934 | set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags); |
Joe Perches | 55eee80 | 2010-03-10 15:20:57 -0800 | [diff] [blame] | 2935 | |
| 2936 | return wait_til_done(floppy_ready, interruptible); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | /* |
| 2940 | * User triggered reset |
| 2941 | * ==================== |
| 2942 | */ |
| 2943 | |
| 2944 | static void reset_intr(void) |
| 2945 | { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 2946 | pr_info("weird, reset interrupt called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
Stephen Hemminger | 3b06c21 | 2010-07-20 20:09:00 -0600 | [diff] [blame] | 2949 | static const struct cont_t reset_cont = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | .interrupt = reset_intr, |
| 2951 | .redo = success_and_wakeup, |
| 2952 | .error = generic_failure, |
| 2953 | .done = generic_done |
| 2954 | }; |
| 2955 | |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 2956 | static int user_reset_fdc(int drive, int arg, bool interruptible) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | { |
| 2958 | int ret; |
| 2959 | |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 2960 | if (lock_fdc(drive, interruptible)) |
| 2961 | return -EINTR; |
| 2962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | if (arg == FD_RESET_ALWAYS) |
| 2964 | FDCS->reset = 1; |
| 2965 | if (FDCS->reset) { |
| 2966 | cont = &reset_cont; |
Joe Perches | 55eee80 | 2010-03-10 15:20:57 -0800 | [diff] [blame] | 2967 | ret = wait_til_done(reset_fdc, interruptible); |
| 2968 | if (ret == -EINTR) |
| 2969 | return -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | } |
| 2971 | process_fd_request(); |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 2972 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | /* |
| 2976 | * Misc Ioctl's and support |
| 2977 | * ======================== |
| 2978 | */ |
| 2979 | static inline int fd_copyout(void __user *param, const void *address, |
| 2980 | unsigned long size) |
| 2981 | { |
| 2982 | return copy_to_user(param, address, size) ? -EFAULT : 0; |
| 2983 | } |
| 2984 | |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 2985 | static inline int fd_copyin(void __user *param, void *address, |
| 2986 | unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | { |
| 2988 | return copy_from_user(address, param, size) ? -EFAULT : 0; |
| 2989 | } |
| 2990 | |
Stephen Hemminger | be7a12b | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 2991 | static const char *drive_name(int type, int drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2992 | { |
| 2993 | struct floppy_struct *floppy; |
| 2994 | |
| 2995 | if (type) |
| 2996 | floppy = floppy_type + type; |
| 2997 | else { |
| 2998 | if (UDP->native_format) |
| 2999 | floppy = floppy_type + UDP->native_format; |
| 3000 | else |
| 3001 | return "(null)"; |
| 3002 | } |
| 3003 | if (floppy->name) |
| 3004 | return floppy->name; |
| 3005 | else |
| 3006 | return "(null)"; |
| 3007 | } |
| 3008 | |
| 3009 | /* raw commands */ |
| 3010 | static void raw_cmd_done(int flag) |
| 3011 | { |
| 3012 | int i; |
| 3013 | |
| 3014 | if (!flag) { |
| 3015 | raw_cmd->flags |= FD_RAW_FAILURE; |
| 3016 | raw_cmd->flags |= FD_RAW_HARDFAILURE; |
| 3017 | } else { |
| 3018 | raw_cmd->reply_count = inr; |
| 3019 | if (raw_cmd->reply_count > MAX_REPLIES) |
| 3020 | raw_cmd->reply_count = 0; |
| 3021 | for (i = 0; i < raw_cmd->reply_count; i++) |
| 3022 | raw_cmd->reply[i] = reply_buffer[i]; |
| 3023 | |
| 3024 | if (raw_cmd->flags & (FD_RAW_READ | FD_RAW_WRITE)) { |
| 3025 | unsigned long flags; |
| 3026 | flags = claim_dma_lock(); |
| 3027 | raw_cmd->length = fd_get_dma_residue(); |
| 3028 | release_dma_lock(flags); |
| 3029 | } |
| 3030 | |
| 3031 | if ((raw_cmd->flags & FD_RAW_SOFTFAILURE) && |
| 3032 | (!raw_cmd->reply_count || (raw_cmd->reply[0] & 0xc0))) |
| 3033 | raw_cmd->flags |= FD_RAW_FAILURE; |
| 3034 | |
| 3035 | if (disk_change(current_drive)) |
| 3036 | raw_cmd->flags |= FD_RAW_DISK_CHANGE; |
| 3037 | else |
| 3038 | raw_cmd->flags &= ~FD_RAW_DISK_CHANGE; |
| 3039 | if (raw_cmd->flags & FD_RAW_NO_MOTOR_AFTER) |
| 3040 | motor_off_callback(current_drive); |
| 3041 | |
| 3042 | if (raw_cmd->next && |
| 3043 | (!(raw_cmd->flags & FD_RAW_FAILURE) || |
| 3044 | !(raw_cmd->flags & FD_RAW_STOP_IF_FAILURE)) && |
| 3045 | ((raw_cmd->flags & FD_RAW_FAILURE) || |
| 3046 | !(raw_cmd->flags & FD_RAW_STOP_IF_SUCCESS))) { |
| 3047 | raw_cmd = raw_cmd->next; |
| 3048 | return; |
| 3049 | } |
| 3050 | } |
| 3051 | generic_done(flag); |
| 3052 | } |
| 3053 | |
Stephen Hemminger | 3b06c21 | 2010-07-20 20:09:00 -0600 | [diff] [blame] | 3054 | static const struct cont_t raw_cmd_cont = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | .interrupt = success_and_wakeup, |
| 3056 | .redo = floppy_start, |
| 3057 | .error = generic_failure, |
| 3058 | .done = raw_cmd_done |
| 3059 | }; |
| 3060 | |
Stephen Hemminger | be7a12b | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 3061 | static int raw_cmd_copyout(int cmd, void __user *param, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | struct floppy_raw_cmd *ptr) |
| 3063 | { |
| 3064 | int ret; |
| 3065 | |
| 3066 | while (ptr) { |
Joe Perches | ce2f11f | 2010-03-10 15:21:08 -0800 | [diff] [blame] | 3067 | ret = copy_to_user(param, ptr, sizeof(*ptr)); |
Joe Perches | 86b12b4 | 2010-03-10 15:20:56 -0800 | [diff] [blame] | 3068 | if (ret) |
| 3069 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | param += sizeof(struct floppy_raw_cmd); |
| 3071 | if ((ptr->flags & FD_RAW_READ) && ptr->buffer_length) { |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 3072 | if (ptr->length >= 0 && |
| 3073 | ptr->length <= ptr->buffer_length) { |
| 3074 | long length = ptr->buffer_length - ptr->length; |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3075 | ret = fd_copyout(ptr->data, ptr->kernel_data, |
| 3076 | length); |
| 3077 | if (ret) |
| 3078 | return ret; |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 3079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | } |
| 3081 | ptr = ptr->next; |
| 3082 | } |
Joe Perches | 7f25271 | 2010-03-10 15:21:08 -0800 | [diff] [blame] | 3083 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | return 0; |
| 3085 | } |
| 3086 | |
| 3087 | static void raw_cmd_free(struct floppy_raw_cmd **ptr) |
| 3088 | { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 3089 | struct floppy_raw_cmd *next; |
| 3090 | struct floppy_raw_cmd *this; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | |
| 3092 | this = *ptr; |
| 3093 | *ptr = NULL; |
| 3094 | while (this) { |
| 3095 | if (this->buffer_length) { |
| 3096 | fd_dma_mem_free((unsigned long)this->kernel_data, |
| 3097 | this->buffer_length); |
| 3098 | this->buffer_length = 0; |
| 3099 | } |
| 3100 | next = this->next; |
| 3101 | kfree(this); |
| 3102 | this = next; |
| 3103 | } |
| 3104 | } |
| 3105 | |
Stephen Hemminger | be7a12b | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 3106 | static int raw_cmd_copyin(int cmd, void __user *param, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | struct floppy_raw_cmd **rcmd) |
| 3108 | { |
| 3109 | struct floppy_raw_cmd *ptr; |
| 3110 | int ret; |
| 3111 | int i; |
| 3112 | |
| 3113 | *rcmd = NULL; |
Joe Perches | 7f25271 | 2010-03-10 15:21:08 -0800 | [diff] [blame] | 3114 | |
| 3115 | loop: |
| 3116 | ptr = kmalloc(sizeof(struct floppy_raw_cmd), GFP_USER); |
| 3117 | if (!ptr) |
| 3118 | return -ENOMEM; |
| 3119 | *rcmd = ptr; |
| 3120 | ret = copy_from_user(ptr, param, sizeof(*ptr)); |
| 3121 | if (ret) |
| 3122 | return -EFAULT; |
| 3123 | ptr->next = NULL; |
| 3124 | ptr->buffer_length = 0; |
| 3125 | param += sizeof(struct floppy_raw_cmd); |
| 3126 | if (ptr->cmd_count > 33) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | /* the command may now also take up the space |
| 3128 | * initially intended for the reply & the |
| 3129 | * reply count. Needed for long 82078 commands |
| 3130 | * such as RESTORE, which takes ... 17 command |
| 3131 | * bytes. Murphy's law #137: When you reserve |
| 3132 | * 16 bytes for a structure, you'll one day |
| 3133 | * discover that you really need 17... |
| 3134 | */ |
Joe Perches | 7f25271 | 2010-03-10 15:21:08 -0800 | [diff] [blame] | 3135 | return -EINVAL; |
| 3136 | |
| 3137 | for (i = 0; i < 16; i++) |
| 3138 | ptr->reply[i] = 0; |
| 3139 | ptr->resultcode = 0; |
| 3140 | ptr->kernel_data = NULL; |
| 3141 | |
| 3142 | if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) { |
| 3143 | if (ptr->length <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | return -EINVAL; |
Joe Perches | 7f25271 | 2010-03-10 15:21:08 -0800 | [diff] [blame] | 3145 | ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length); |
| 3146 | fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length); |
| 3147 | if (!ptr->kernel_data) |
| 3148 | return -ENOMEM; |
| 3149 | ptr->buffer_length = ptr->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | } |
Joe Perches | 7f25271 | 2010-03-10 15:21:08 -0800 | [diff] [blame] | 3151 | if (ptr->flags & FD_RAW_WRITE) { |
| 3152 | ret = fd_copyin(ptr->data, ptr->kernel_data, ptr->length); |
| 3153 | if (ret) |
| 3154 | return ret; |
| 3155 | } |
| 3156 | |
| 3157 | if (ptr->flags & FD_RAW_MORE) { |
| 3158 | rcmd = &(ptr->next); |
| 3159 | ptr->rate &= 0x43; |
| 3160 | goto loop; |
| 3161 | } |
| 3162 | |
| 3163 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
| 3166 | static int raw_cmd_ioctl(int cmd, void __user *param) |
| 3167 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | struct floppy_raw_cmd *my_raw_cmd; |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 3169 | int drive; |
| 3170 | int ret2; |
| 3171 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | |
| 3173 | if (FDCS->rawcmd <= 1) |
| 3174 | FDCS->rawcmd = 1; |
| 3175 | for (drive = 0; drive < N_DRIVE; drive++) { |
| 3176 | if (FDC(drive) != fdc) |
| 3177 | continue; |
| 3178 | if (drive == current_drive) { |
| 3179 | if (UDRS->fd_ref > 1) { |
| 3180 | FDCS->rawcmd = 2; |
| 3181 | break; |
| 3182 | } |
| 3183 | } else if (UDRS->fd_ref) { |
| 3184 | FDCS->rawcmd = 2; |
| 3185 | break; |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | if (FDCS->reset) |
| 3190 | return -EIO; |
| 3191 | |
| 3192 | ret = raw_cmd_copyin(cmd, param, &my_raw_cmd); |
| 3193 | if (ret) { |
| 3194 | raw_cmd_free(&my_raw_cmd); |
| 3195 | return ret; |
| 3196 | } |
| 3197 | |
| 3198 | raw_cmd = my_raw_cmd; |
| 3199 | cont = &raw_cmd_cont; |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3200 | ret = wait_til_done(floppy_start, true); |
Joe Perches | 87f530d | 2010-03-10 15:20:54 -0800 | [diff] [blame] | 3201 | debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | |
| 3203 | if (ret != -EINTR && FDCS->reset) |
| 3204 | ret = -EIO; |
| 3205 | |
| 3206 | DRS->track = NO_TRACK; |
| 3207 | |
| 3208 | ret2 = raw_cmd_copyout(cmd, param, my_raw_cmd); |
| 3209 | if (!ret) |
| 3210 | ret = ret2; |
| 3211 | raw_cmd_free(&my_raw_cmd); |
| 3212 | return ret; |
| 3213 | } |
| 3214 | |
| 3215 | static int invalidate_drive(struct block_device *bdev) |
| 3216 | { |
| 3217 | /* invalidate the buffer track to force a reread */ |
| 3218 | set_bit((long)bdev->bd_disk->private_data, &fake_change); |
| 3219 | process_fd_request(); |
| 3220 | check_disk_change(bdev); |
| 3221 | return 0; |
| 3222 | } |
| 3223 | |
Stephen Hemminger | be7a12b | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 3224 | static int set_geometry(unsigned int cmd, struct floppy_struct *g, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | int drive, int type, struct block_device *bdev) |
| 3226 | { |
| 3227 | int cnt; |
| 3228 | |
| 3229 | /* sanity checking for parameters. */ |
| 3230 | if (g->sect <= 0 || |
| 3231 | g->head <= 0 || |
| 3232 | g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) || |
| 3233 | /* check if reserved bits are set */ |
Keith Wansbrough | 9e49184 | 2008-09-22 14:57:17 -0700 | [diff] [blame] | 3234 | (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | return -EINVAL; |
| 3236 | if (type) { |
| 3237 | if (!capable(CAP_SYS_ADMIN)) |
| 3238 | return -EPERM; |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 3239 | mutex_lock(&open_lock); |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3240 | if (lock_fdc(drive, true)) { |
Jiri Slaby | 8516a50 | 2009-06-30 11:41:44 -0700 | [diff] [blame] | 3241 | mutex_unlock(&open_lock); |
| 3242 | return -EINTR; |
| 3243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | floppy_type[type] = *g; |
| 3245 | floppy_type[type].name = "user format"; |
| 3246 | for (cnt = type << 2; cnt < (type << 2) + 4; cnt++) |
| 3247 | floppy_sizes[cnt] = floppy_sizes[cnt + 0x80] = |
| 3248 | floppy_type[type].size + 1; |
| 3249 | process_fd_request(); |
| 3250 | for (cnt = 0; cnt < N_DRIVE; cnt++) { |
| 3251 | struct block_device *bdev = opened_bdev[cnt]; |
| 3252 | if (!bdev || ITYPE(drive_state[cnt].fd_device) != type) |
| 3253 | continue; |
Christoph Hellwig | 2ef4163 | 2005-05-05 16:15:59 -0700 | [diff] [blame] | 3254 | __invalidate_device(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | } |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 3256 | mutex_unlock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | } else { |
| 3258 | int oldStretch; |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3259 | |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3260 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3261 | return -EINTR; |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3262 | if (cmd != FDDEFPRM) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | /* notice a disk change immediately, else |
| 3264 | * we lose our settings immediately*/ |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3265 | if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR) |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3266 | return -EINTR; |
| 3267 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | oldStretch = g->stretch; |
| 3269 | user_params[drive] = *g; |
| 3270 | if (buffer_drive == drive) |
| 3271 | SUPBOUND(buffer_max, user_params[drive].sect); |
| 3272 | current_type[drive] = &user_params[drive]; |
| 3273 | floppy_sizes[drive] = user_params[drive].size; |
| 3274 | if (cmd == FDDEFPRM) |
| 3275 | DRS->keep_data = -1; |
| 3276 | else |
| 3277 | DRS->keep_data = 1; |
| 3278 | /* invalidation. Invalidate only when needed, i.e. |
| 3279 | * when there are already sectors in the buffer cache |
| 3280 | * whose number will change. This is useful, because |
| 3281 | * mtools often changes the geometry of the disk after |
| 3282 | * looking at the boot block */ |
| 3283 | if (DRS->maxblock > user_params[drive].sect || |
| 3284 | DRS->maxtrack || |
| 3285 | ((user_params[drive].sect ^ oldStretch) & |
Keith Wansbrough | 9e49184 | 2008-09-22 14:57:17 -0700 | [diff] [blame] | 3286 | (FD_SWAPSIDES | FD_SECTBASEMASK))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | invalidate_drive(bdev); |
| 3288 | else |
| 3289 | process_fd_request(); |
| 3290 | } |
| 3291 | return 0; |
| 3292 | } |
| 3293 | |
| 3294 | /* handle obsolete ioctl's */ |
Stephen Hemminger | 21af544 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 3295 | static unsigned int ioctl_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | FDCLRPRM, |
| 3297 | FDSETPRM, |
| 3298 | FDDEFPRM, |
| 3299 | FDGETPRM, |
| 3300 | FDMSGON, |
| 3301 | FDMSGOFF, |
| 3302 | FDFMTBEG, |
| 3303 | FDFMTTRK, |
| 3304 | FDFMTEND, |
| 3305 | FDSETEMSGTRESH, |
| 3306 | FDFLUSH, |
| 3307 | FDSETMAXERRS, |
| 3308 | FDGETMAXERRS, |
| 3309 | FDGETDRVTYP, |
| 3310 | FDSETDRVPRM, |
| 3311 | FDGETDRVPRM, |
| 3312 | FDGETDRVSTAT, |
| 3313 | FDPOLLDRVSTAT, |
| 3314 | FDRESET, |
| 3315 | FDGETFDCSTAT, |
| 3316 | FDWERRORCLR, |
| 3317 | FDWERRORGET, |
| 3318 | FDRAWCMD, |
| 3319 | FDEJECT, |
| 3320 | FDTWADDLE |
| 3321 | }; |
| 3322 | |
Stephen Hemminger | 21af544 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 3323 | static int normalize_ioctl(unsigned int *cmd, int *size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3324 | { |
| 3325 | int i; |
| 3326 | |
| 3327 | for (i = 0; i < ARRAY_SIZE(ioctl_table); i++) { |
| 3328 | if ((*cmd & 0xffff) == (ioctl_table[i] & 0xffff)) { |
| 3329 | *size = _IOC_SIZE(*cmd); |
| 3330 | *cmd = ioctl_table[i]; |
| 3331 | if (*size > _IOC_SIZE(*cmd)) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3332 | pr_info("ioctl not yet supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | return -EFAULT; |
| 3334 | } |
| 3335 | return 0; |
| 3336 | } |
| 3337 | } |
| 3338 | return -EINVAL; |
| 3339 | } |
| 3340 | |
| 3341 | static int get_floppy_geometry(int drive, int type, struct floppy_struct **g) |
| 3342 | { |
| 3343 | if (type) |
| 3344 | *g = &floppy_type[type]; |
| 3345 | else { |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3346 | if (lock_fdc(drive, false)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3347 | return -EINTR; |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3348 | if (poll_drive(false, 0) == -EINTR) |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3349 | return -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | process_fd_request(); |
| 3351 | *g = current_type[drive]; |
| 3352 | } |
| 3353 | if (!*g) |
| 3354 | return -ENODEV; |
| 3355 | return 0; |
| 3356 | } |
| 3357 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 3358 | static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 3359 | { |
| 3360 | int drive = (long)bdev->bd_disk->private_data; |
| 3361 | int type = ITYPE(drive_state[drive].fd_device); |
| 3362 | struct floppy_struct *g; |
| 3363 | int ret; |
| 3364 | |
| 3365 | ret = get_floppy_geometry(drive, type, &g); |
| 3366 | if (ret) |
| 3367 | return ret; |
| 3368 | |
| 3369 | geo->heads = g->head; |
| 3370 | geo->sectors = g->sect; |
| 3371 | geo->cylinders = g->track; |
| 3372 | return 0; |
| 3373 | } |
| 3374 | |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 3375 | static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | unsigned long param) |
| 3377 | { |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3378 | int drive = (long)bdev->bd_disk->private_data; |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 3379 | int type = ITYPE(UDRS->fd_device); |
| 3380 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | int ret; |
| 3382 | int size; |
| 3383 | union inparam { |
| 3384 | struct floppy_struct g; /* geometry */ |
| 3385 | struct format_descr f; |
| 3386 | struct floppy_max_errors max_errors; |
| 3387 | struct floppy_drive_params dp; |
| 3388 | } inparam; /* parameters coming from user space */ |
Joe Perches | 724ee62 | 2010-03-10 15:21:11 -0800 | [diff] [blame] | 3389 | const void *outparam; /* parameters passed back to user space */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | |
| 3391 | /* convert compatibility eject ioctls into floppy eject ioctl. |
| 3392 | * We do this in order to provide a means to eject floppy disks before |
| 3393 | * installing the new fdutils package */ |
| 3394 | if (cmd == CDROMEJECT || /* CD-ROM eject */ |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3395 | cmd == 0x6470) { /* SunOS floppy eject */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | DPRINT("obsolete eject ioctl\n"); |
| 3397 | DPRINT("please use floppycontrol --eject\n"); |
| 3398 | cmd = FDEJECT; |
| 3399 | } |
| 3400 | |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3401 | if (!((cmd & 0xff00) == 0x0200)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | return -EINVAL; |
| 3403 | |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3404 | /* convert the old style command into a new style command */ |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3405 | ret = normalize_ioctl(&cmd, &size); |
| 3406 | if (ret) |
| 3407 | return ret; |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | /* permission checks */ |
Joe Perches | 0aad92c | 2010-03-10 15:21:10 -0800 | [diff] [blame] | 3410 | if (((cmd & 0x40) && !(mode & (FMODE_WRITE | FMODE_WRITE_IOCTL))) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | ((cmd & 0x80) && !capable(CAP_SYS_ADMIN))) |
| 3412 | return -EPERM; |
| 3413 | |
Arjan van de Ven | 2886a8b | 2009-12-14 18:00:11 -0800 | [diff] [blame] | 3414 | if (WARN_ON(size < 0 || size > sizeof(inparam))) |
| 3415 | return -EINVAL; |
| 3416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | /* copyin */ |
Joe Perches | b87c9e0 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 3418 | memset(&inparam, 0, sizeof(inparam)); |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3419 | if (_IOC_DIR(cmd) & _IOC_WRITE) { |
| 3420 | ret = fd_copyin((void __user *)param, &inparam, size); |
| 3421 | if (ret) |
| 3422 | return ret; |
| 3423 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3425 | switch (cmd) { |
| 3426 | case FDEJECT: |
| 3427 | if (UDRS->fd_ref != 1) |
| 3428 | /* somebody else has this drive open */ |
| 3429 | return -EBUSY; |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3430 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3431 | return -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3433 | /* do the actual eject. Fails on |
| 3434 | * non-Sparc architectures */ |
| 3435 | ret = fd_eject(UNIT(drive)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3436 | |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3437 | set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
| 3438 | set_bit(FD_VERIFY_BIT, &UDRS->flags); |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3439 | process_fd_request(); |
| 3440 | return ret; |
| 3441 | case FDCLRPRM: |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3442 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3443 | return -EINTR; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3444 | current_type[drive] = NULL; |
| 3445 | floppy_sizes[drive] = MAX_DISK_SIZE << 1; |
| 3446 | UDRS->keep_data = 0; |
| 3447 | return invalidate_drive(bdev); |
| 3448 | case FDSETPRM: |
| 3449 | case FDDEFPRM: |
| 3450 | return set_geometry(cmd, &inparam.g, drive, type, bdev); |
| 3451 | case FDGETPRM: |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3452 | ret = get_floppy_geometry(drive, type, |
Joe Perches | 724ee62 | 2010-03-10 15:21:11 -0800 | [diff] [blame] | 3453 | (struct floppy_struct **)&outparam); |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3454 | if (ret) |
| 3455 | return ret; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3456 | break; |
| 3457 | case FDMSGON: |
| 3458 | UDP->flags |= FTD_MSG; |
| 3459 | return 0; |
| 3460 | case FDMSGOFF: |
| 3461 | UDP->flags &= ~FTD_MSG; |
| 3462 | return 0; |
| 3463 | case FDFMTBEG: |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3464 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3465 | return -EINTR; |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3466 | if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR) |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3467 | return -EINTR; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3468 | ret = UDRS->flags; |
| 3469 | process_fd_request(); |
| 3470 | if (ret & FD_VERIFY) |
| 3471 | return -ENODEV; |
| 3472 | if (!(ret & FD_DISK_WRITABLE)) |
| 3473 | return -EROFS; |
| 3474 | return 0; |
| 3475 | case FDFMTTRK: |
| 3476 | if (UDRS->fd_ref != 1) |
| 3477 | return -EBUSY; |
| 3478 | return do_format(drive, &inparam.f); |
| 3479 | case FDFMTEND: |
| 3480 | case FDFLUSH: |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3481 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3482 | return -EINTR; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3483 | return invalidate_drive(bdev); |
| 3484 | case FDSETEMSGTRESH: |
| 3485 | UDP->max_errors.reporting = (unsigned short)(param & 0x0f); |
| 3486 | return 0; |
| 3487 | case FDGETMAXERRS: |
Joe Perches | 724ee62 | 2010-03-10 15:21:11 -0800 | [diff] [blame] | 3488 | outparam = &UDP->max_errors; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3489 | break; |
| 3490 | case FDSETMAXERRS: |
| 3491 | UDP->max_errors = inparam.max_errors; |
| 3492 | break; |
| 3493 | case FDGETDRVTYP: |
| 3494 | outparam = drive_name(type, drive); |
Joe Perches | 724ee62 | 2010-03-10 15:21:11 -0800 | [diff] [blame] | 3495 | SUPBOUND(size, strlen((const char *)outparam) + 1); |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3496 | break; |
| 3497 | case FDSETDRVPRM: |
| 3498 | *UDP = inparam.dp; |
| 3499 | break; |
| 3500 | case FDGETDRVPRM: |
Joe Perches | 724ee62 | 2010-03-10 15:21:11 -0800 | [diff] [blame] | 3501 | outparam = UDP; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3502 | break; |
| 3503 | case FDPOLLDRVSTAT: |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3504 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3505 | return -EINTR; |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3506 | if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR) |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3507 | return -EINTR; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3508 | process_fd_request(); |
| 3509 | /* fall through */ |
| 3510 | case FDGETDRVSTAT: |
Joe Perches | 724ee62 | 2010-03-10 15:21:11 -0800 | [diff] [blame] | 3511 | outparam = UDRS; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3512 | break; |
| 3513 | case FDRESET: |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3514 | return user_reset_fdc(drive, (int)param, true); |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3515 | case FDGETFDCSTAT: |
Joe Perches | 724ee62 | 2010-03-10 15:21:11 -0800 | [diff] [blame] | 3516 | outparam = UFDCS; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3517 | break; |
| 3518 | case FDWERRORCLR: |
| 3519 | memset(UDRWE, 0, sizeof(*UDRWE)); |
| 3520 | return 0; |
| 3521 | case FDWERRORGET: |
Joe Perches | 724ee62 | 2010-03-10 15:21:11 -0800 | [diff] [blame] | 3522 | outparam = UDRWE; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3523 | break; |
| 3524 | case FDRAWCMD: |
| 3525 | if (type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | return -EINVAL; |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3527 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3528 | return -EINTR; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3529 | set_floppy(drive); |
Joe Perches | 4575b55 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3530 | i = raw_cmd_ioctl(cmd, (void __user *)param); |
| 3531 | if (i == -EINTR) |
| 3532 | return -EINTR; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3533 | process_fd_request(); |
| 3534 | return i; |
| 3535 | case FDTWADDLE: |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3536 | if (lock_fdc(drive, true)) |
Joe Perches | 52a0d61 | 2010-03-10 15:20:53 -0800 | [diff] [blame] | 3537 | return -EINTR; |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3538 | twaddle(); |
| 3539 | process_fd_request(); |
| 3540 | return 0; |
| 3541 | default: |
| 3542 | return -EINVAL; |
| 3543 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3544 | |
| 3545 | if (_IOC_DIR(cmd) & _IOC_READ) |
| 3546 | return fd_copyout((void __user *)param, outparam, size); |
Joe Perches | da27365 | 2010-03-10 15:20:52 -0800 | [diff] [blame] | 3547 | |
| 3548 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 3551 | static int fd_ioctl(struct block_device *bdev, fmode_t mode, |
| 3552 | unsigned int cmd, unsigned long param) |
| 3553 | { |
| 3554 | int ret; |
| 3555 | |
| 3556 | lock_kernel(); |
| 3557 | ret = fd_locked_ioctl(bdev, mode, cmd, param); |
| 3558 | unlock_kernel(); |
| 3559 | |
| 3560 | return ret; |
| 3561 | } |
| 3562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | static void __init config_types(void) |
| 3564 | { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3565 | bool has_drive = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | int drive; |
| 3567 | |
| 3568 | /* read drive info out of physical CMOS */ |
| 3569 | drive = 0; |
| 3570 | if (!UDP->cmos) |
| 3571 | UDP->cmos = FLOPPY0_TYPE; |
| 3572 | drive = 1; |
| 3573 | if (!UDP->cmos && FLOPPY1_TYPE) |
| 3574 | UDP->cmos = FLOPPY1_TYPE; |
| 3575 | |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 3576 | /* FIXME: additional physical CMOS drive detection should go here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | |
| 3578 | for (drive = 0; drive < N_DRIVE; drive++) { |
| 3579 | unsigned int type = UDP->cmos; |
| 3580 | struct floppy_drive_params *params; |
| 3581 | const char *name = NULL; |
| 3582 | static char temparea[32]; |
| 3583 | |
Tobias Klauser | 945f390 | 2006-01-08 01:05:11 -0800 | [diff] [blame] | 3584 | if (type < ARRAY_SIZE(default_drive_params)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | params = &default_drive_params[type].params; |
| 3586 | if (type) { |
| 3587 | name = default_drive_params[type].name; |
| 3588 | allowed_drive_mask |= 1 << drive; |
| 3589 | } else |
| 3590 | allowed_drive_mask &= ~(1 << drive); |
| 3591 | } else { |
| 3592 | params = &default_drive_params[0].params; |
| 3593 | sprintf(temparea, "unknown type %d (usb?)", type); |
| 3594 | name = temparea; |
| 3595 | } |
| 3596 | if (name) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3597 | const char *prepend; |
| 3598 | if (!has_drive) { |
| 3599 | prepend = ""; |
| 3600 | has_drive = true; |
| 3601 | pr_info("Floppy drive(s):"); |
| 3602 | } else { |
| 3603 | prepend = ","; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | } |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3605 | |
| 3606 | pr_cont("%s fd%d is %s", prepend, drive, name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | } |
| 3608 | *UDP = *params; |
| 3609 | } |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3610 | |
| 3611 | if (has_drive) |
| 3612 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | } |
| 3614 | |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3615 | static int floppy_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | { |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3617 | int drive = (long)disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 3619 | lock_kernel(); |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 3620 | mutex_lock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | if (UDRS->fd_ref < 0) |
| 3622 | UDRS->fd_ref = 0; |
| 3623 | else if (!UDRS->fd_ref--) { |
| 3624 | DPRINT("floppy_release with fd_ref == 0"); |
| 3625 | UDRS->fd_ref = 0; |
| 3626 | } |
| 3627 | if (!UDRS->fd_ref) |
| 3628 | opened_bdev[drive] = NULL; |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 3629 | mutex_unlock(&open_lock); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 3630 | unlock_kernel(); |
Ingo Molnar | 3e541a4 | 2006-07-03 00:24:23 -0700 | [diff] [blame] | 3631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | return 0; |
| 3633 | } |
| 3634 | |
| 3635 | /* |
| 3636 | * floppy_open check for aliasing (/dev/fd0 can be the same as |
| 3637 | * /dev/PS0 etc), and disallows simultaneous access to the same |
| 3638 | * drive with different device numbers. |
| 3639 | */ |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3640 | static int floppy_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | { |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3642 | int drive = (long)bdev->bd_disk->private_data; |
| 3643 | int old_dev, new_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | int try; |
| 3645 | int res = -EBUSY; |
| 3646 | char *tmp; |
| 3647 | |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 3648 | lock_kernel(); |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 3649 | mutex_lock(&open_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | old_dev = UDRS->fd_device; |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3651 | if (opened_bdev[drive] && opened_bdev[drive] != bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | goto out2; |
| 3653 | |
| 3654 | if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) { |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3655 | set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
| 3656 | set_bit(FD_VERIFY_BIT, &UDRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3659 | if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (mode & FMODE_EXCL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | goto out2; |
| 3661 | |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3662 | if (mode & FMODE_EXCL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | UDRS->fd_ref = -1; |
| 3664 | else |
| 3665 | UDRS->fd_ref++; |
| 3666 | |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3667 | opened_bdev[drive] = bdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | |
| 3669 | res = -ENXIO; |
| 3670 | |
| 3671 | if (!floppy_track_buffer) { |
| 3672 | /* if opening an ED drive, reserve a big buffer, |
| 3673 | * else reserve a small one */ |
| 3674 | if ((UDP->cmos == 6) || (UDP->cmos == 5)) |
| 3675 | try = 64; /* Only 48 actually useful */ |
| 3676 | else |
| 3677 | try = 32; /* Only 24 actually useful */ |
| 3678 | |
| 3679 | tmp = (char *)fd_dma_mem_alloc(1024 * try); |
| 3680 | if (!tmp && !floppy_track_buffer) { |
| 3681 | try >>= 1; /* buffer only one side */ |
| 3682 | INFBOUND(try, 16); |
| 3683 | tmp = (char *)fd_dma_mem_alloc(1024 * try); |
| 3684 | } |
Joe Perches | a81ee54 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3685 | if (!tmp && !floppy_track_buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | fallback_on_nodma_alloc(&tmp, 2048 * try); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | if (!tmp && !floppy_track_buffer) { |
| 3688 | DPRINT("Unable to allocate DMA memory\n"); |
| 3689 | goto out; |
| 3690 | } |
| 3691 | if (floppy_track_buffer) { |
| 3692 | if (tmp) |
| 3693 | fd_dma_mem_free((unsigned long)tmp, try * 1024); |
| 3694 | } else { |
| 3695 | buffer_min = buffer_max = -1; |
| 3696 | floppy_track_buffer = tmp; |
| 3697 | max_buffer_sectors = try; |
| 3698 | } |
| 3699 | } |
| 3700 | |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3701 | new_dev = MINOR(bdev->bd_dev); |
| 3702 | UDRS->fd_device = new_dev; |
| 3703 | set_capacity(disks[drive], floppy_sizes[new_dev]); |
| 3704 | if (old_dev != -1 && old_dev != new_dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | if (buffer_drive == drive) |
| 3706 | buffer_track = -1; |
| 3707 | } |
| 3708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | if (UFDCS->rawcmd == 1) |
| 3710 | UFDCS->rawcmd = 2; |
| 3711 | |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3712 | if (!(mode & FMODE_NDELAY)) { |
| 3713 | if (mode & (FMODE_READ|FMODE_WRITE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | UDRS->last_checked = 0; |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3715 | check_disk_change(bdev); |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3716 | if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | goto out; |
| 3718 | } |
| 3719 | res = -EROFS; |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3720 | if ((mode & FMODE_WRITE) && |
| 3721 | !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | goto out; |
| 3723 | } |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 3724 | mutex_unlock(&open_lock); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 3725 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3726 | return 0; |
| 3727 | out: |
| 3728 | if (UDRS->fd_ref < 0) |
| 3729 | UDRS->fd_ref = 0; |
| 3730 | else |
| 3731 | UDRS->fd_ref--; |
| 3732 | if (!UDRS->fd_ref) |
| 3733 | opened_bdev[drive] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | out2: |
Jes Sorensen | b1c82b5 | 2006-03-23 03:00:26 -0800 | [diff] [blame] | 3735 | mutex_unlock(&open_lock); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 3736 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | return res; |
| 3738 | } |
| 3739 | |
| 3740 | /* |
| 3741 | * Check if the disk has been changed or if a change has been faked. |
| 3742 | */ |
| 3743 | static int check_floppy_change(struct gendisk *disk) |
| 3744 | { |
| 3745 | int drive = (long)disk->private_data; |
| 3746 | |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3747 | if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
| 3748 | test_bit(FD_VERIFY_BIT, &UDRS->flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | return 1; |
| 3750 | |
Marcelo Feitoza Parisi | 50297cb | 2006-03-28 01:56:44 -0800 | [diff] [blame] | 3751 | if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) { |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3752 | lock_fdc(drive, false); |
| 3753 | poll_drive(false, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | process_fd_request(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3757 | if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
| 3758 | test_bit(FD_VERIFY_BIT, &UDRS->flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | test_bit(drive, &fake_change) || |
| 3760 | (!ITYPE(UDRS->fd_device) && !current_type[drive])) |
| 3761 | return 1; |
| 3762 | return 0; |
| 3763 | } |
| 3764 | |
| 3765 | /* |
| 3766 | * This implements "read block 0" for floppy_revalidate(). |
| 3767 | * Needed for format autodetection, checking whether there is |
| 3768 | * a disk in the drive, and whether that disk is writable. |
| 3769 | */ |
| 3770 | |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 3771 | static void floppy_rb0_complete(struct bio *bio, int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | complete((struct completion *)bio->bi_private); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | static int __floppy_read_block_0(struct block_device *bdev) |
| 3777 | { |
| 3778 | struct bio bio; |
| 3779 | struct bio_vec bio_vec; |
| 3780 | struct completion complete; |
| 3781 | struct page *page; |
| 3782 | size_t size; |
| 3783 | |
| 3784 | page = alloc_page(GFP_NOIO); |
| 3785 | if (!page) { |
| 3786 | process_fd_request(); |
| 3787 | return -ENOMEM; |
| 3788 | } |
| 3789 | |
| 3790 | size = bdev->bd_block_size; |
| 3791 | if (!size) |
| 3792 | size = 1024; |
| 3793 | |
| 3794 | bio_init(&bio); |
| 3795 | bio.bi_io_vec = &bio_vec; |
| 3796 | bio_vec.bv_page = page; |
| 3797 | bio_vec.bv_len = size; |
| 3798 | bio_vec.bv_offset = 0; |
| 3799 | bio.bi_vcnt = 1; |
| 3800 | bio.bi_idx = 0; |
| 3801 | bio.bi_size = size; |
| 3802 | bio.bi_bdev = bdev; |
| 3803 | bio.bi_sector = 0; |
Stephen Hemminger | 41a55b4 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 3804 | bio.bi_flags = BIO_QUIET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | init_completion(&complete); |
| 3806 | bio.bi_private = &complete; |
| 3807 | bio.bi_end_io = floppy_rb0_complete; |
| 3808 | |
| 3809 | submit_bio(READ, &bio); |
| 3810 | generic_unplug_device(bdev_get_queue(bdev)); |
| 3811 | process_fd_request(); |
| 3812 | wait_for_completion(&complete); |
| 3813 | |
| 3814 | __free_page(page); |
| 3815 | |
| 3816 | return 0; |
| 3817 | } |
| 3818 | |
| 3819 | /* revalidate the floppy disk, i.e. trigger format autodetection by reading |
| 3820 | * the bootblock (block 0). "Autodetection" is also needed to check whether |
| 3821 | * there is a disk in the drive at all... Thus we also do it for fixed |
| 3822 | * geometry formats */ |
| 3823 | static int floppy_revalidate(struct gendisk *disk) |
| 3824 | { |
| 3825 | int drive = (long)disk->private_data; |
| 3826 | #define NO_GEOM (!current_type[drive] && !ITYPE(UDRS->fd_device)) |
| 3827 | int cf; |
| 3828 | int res = 0; |
| 3829 | |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3830 | if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
| 3831 | test_bit(FD_VERIFY_BIT, &UDRS->flags) || |
| 3832 | test_bit(drive, &fake_change) || NO_GEOM) { |
Stephen Hemminger | 01b6b67 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 3833 | if (WARN(atomic_read(&usage_count) == 0, |
| 3834 | "VFS: revalidate called on non-open device.\n")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | return -EFAULT; |
Stephen Hemminger | 01b6b67 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 3836 | |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3837 | lock_fdc(drive, false); |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3838 | cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) || |
| 3839 | test_bit(FD_VERIFY_BIT, &UDRS->flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | if (!(cf || test_bit(drive, &fake_change) || NO_GEOM)) { |
| 3841 | process_fd_request(); /*already done by another thread */ |
| 3842 | return 0; |
| 3843 | } |
| 3844 | UDRS->maxblock = 0; |
| 3845 | UDRS->maxtrack = 0; |
| 3846 | if (buffer_drive == drive) |
| 3847 | buffer_track = -1; |
| 3848 | clear_bit(drive, &fake_change); |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 3849 | clear_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | if (cf) |
| 3851 | UDRS->generation++; |
| 3852 | if (NO_GEOM) { |
| 3853 | /* auto-sensing */ |
| 3854 | res = __floppy_read_block_0(opened_bdev[drive]); |
| 3855 | } else { |
| 3856 | if (cf) |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 3857 | poll_drive(false, FD_RAW_NEED_DISK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | process_fd_request(); |
| 3859 | } |
| 3860 | } |
| 3861 | set_capacity(disk, floppy_sizes[UDRS->fd_device]); |
| 3862 | return res; |
| 3863 | } |
| 3864 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 3865 | static const struct block_device_operations floppy_fops = { |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 3866 | .owner = THIS_MODULE, |
Al Viro | a4af9b4 | 2008-03-02 09:27:55 -0500 | [diff] [blame] | 3867 | .open = floppy_open, |
| 3868 | .release = floppy_release, |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 3869 | .ioctl = fd_ioctl, |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 3870 | .getgeo = fd_getgeo, |
| 3871 | .media_changed = check_floppy_change, |
| 3872 | .revalidate_disk = floppy_revalidate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | /* |
| 3876 | * Floppy Driver initialization |
| 3877 | * ============================= |
| 3878 | */ |
| 3879 | |
| 3880 | /* Determine the floppy disk controller type */ |
| 3881 | /* This routine was written by David C. Niemi */ |
| 3882 | static char __init get_fdc_version(void) |
| 3883 | { |
| 3884 | int r; |
| 3885 | |
| 3886 | output_byte(FD_DUMPREGS); /* 82072 and better know DUMPREGS */ |
| 3887 | if (FDCS->reset) |
| 3888 | return FDC_NONE; |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 3889 | r = result(); |
| 3890 | if (r <= 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | return FDC_NONE; /* No FDC present ??? */ |
| 3892 | if ((r == 1) && (reply_buffer[0] == 0x80)) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3893 | pr_info("FDC %d is an 8272A\n", fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3894 | return FDC_8272A; /* 8272a/765 don't know DUMPREGS */ |
| 3895 | } |
| 3896 | if (r != 10) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3897 | pr_info("FDC %d init: DUMPREGS: unexpected return of %d bytes.\n", |
| 3898 | fdc, r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | return FDC_UNKNOWN; |
| 3900 | } |
| 3901 | |
| 3902 | if (!fdc_configure()) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3903 | pr_info("FDC %d is an 82072\n", fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | return FDC_82072; /* 82072 doesn't know CONFIGURE */ |
| 3905 | } |
| 3906 | |
| 3907 | output_byte(FD_PERPENDICULAR); |
| 3908 | if (need_more_output() == MORE_OUTPUT) { |
| 3909 | output_byte(0); |
| 3910 | } else { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3911 | pr_info("FDC %d is an 82072A\n", fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | return FDC_82072A; /* 82072A as found on Sparcs. */ |
| 3913 | } |
| 3914 | |
| 3915 | output_byte(FD_UNLOCK); |
| 3916 | r = result(); |
| 3917 | if ((r == 1) && (reply_buffer[0] == 0x80)) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3918 | pr_info("FDC %d is a pre-1991 82077\n", fdc); |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 3919 | return FDC_82077_ORIG; /* Pre-1991 82077, doesn't know |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | * LOCK/UNLOCK */ |
| 3921 | } |
| 3922 | if ((r != 1) || (reply_buffer[0] != 0x00)) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3923 | pr_info("FDC %d init: UNLOCK: unexpected return of %d bytes.\n", |
| 3924 | fdc, r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | return FDC_UNKNOWN; |
| 3926 | } |
| 3927 | output_byte(FD_PARTID); |
| 3928 | r = result(); |
| 3929 | if (r != 1) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3930 | pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n", |
| 3931 | fdc, r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | return FDC_UNKNOWN; |
| 3933 | } |
| 3934 | if (reply_buffer[0] == 0x80) { |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3935 | pr_info("FDC %d is a post-1991 82077\n", fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | return FDC_82077; /* Revised 82077AA passes all the tests */ |
| 3937 | } |
| 3938 | switch (reply_buffer[0] >> 5) { |
| 3939 | case 0x0: |
| 3940 | /* Either a 82078-1 or a 82078SL running at 5Volt */ |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3941 | pr_info("FDC %d is an 82078.\n", fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | return FDC_82078; |
| 3943 | case 0x1: |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3944 | pr_info("FDC %d is a 44pin 82078\n", fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | return FDC_82078; |
| 3946 | case 0x2: |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3947 | pr_info("FDC %d is a S82078B\n", fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | return FDC_S82078B; |
| 3949 | case 0x3: |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3950 | pr_info("FDC %d is a National Semiconductor PC87306\n", fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | return FDC_87306; |
| 3952 | default: |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 3953 | pr_info("FDC %d init: 82078 variant with unknown PARTID=%d.\n", |
| 3954 | fdc, reply_buffer[0] >> 5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | return FDC_82078_UNKN; |
| 3956 | } |
| 3957 | } /* get_fdc_version */ |
| 3958 | |
| 3959 | /* lilo configuration */ |
| 3960 | |
| 3961 | static void __init floppy_set_flags(int *ints, int param, int param2) |
| 3962 | { |
| 3963 | int i; |
| 3964 | |
| 3965 | for (i = 0; i < ARRAY_SIZE(default_drive_params); i++) { |
| 3966 | if (param) |
| 3967 | default_drive_params[i].params.flags |= param2; |
| 3968 | else |
| 3969 | default_drive_params[i].params.flags &= ~param2; |
| 3970 | } |
| 3971 | DPRINT("%s flag 0x%x\n", param2 ? "Setting" : "Clearing", param); |
| 3972 | } |
| 3973 | |
| 3974 | static void __init daring(int *ints, int param, int param2) |
| 3975 | { |
| 3976 | int i; |
| 3977 | |
| 3978 | for (i = 0; i < ARRAY_SIZE(default_drive_params); i++) { |
| 3979 | if (param) { |
| 3980 | default_drive_params[i].params.select_delay = 0; |
| 3981 | default_drive_params[i].params.flags |= |
| 3982 | FD_SILENT_DCL_CLEAR; |
| 3983 | } else { |
| 3984 | default_drive_params[i].params.select_delay = |
| 3985 | 2 * HZ / 100; |
| 3986 | default_drive_params[i].params.flags &= |
| 3987 | ~FD_SILENT_DCL_CLEAR; |
| 3988 | } |
| 3989 | } |
| 3990 | DPRINT("Assuming %s floppy hardware\n", param ? "standard" : "broken"); |
| 3991 | } |
| 3992 | |
| 3993 | static void __init set_cmos(int *ints, int dummy, int dummy2) |
| 3994 | { |
| 3995 | int current_drive = 0; |
| 3996 | |
| 3997 | if (ints[0] != 2) { |
| 3998 | DPRINT("wrong number of parameters for CMOS\n"); |
| 3999 | return; |
| 4000 | } |
| 4001 | current_drive = ints[1]; |
| 4002 | if (current_drive < 0 || current_drive >= 8) { |
| 4003 | DPRINT("bad drive for set_cmos\n"); |
| 4004 | return; |
| 4005 | } |
| 4006 | #if N_FDC > 1 |
| 4007 | if (current_drive >= 4 && !FDC2) |
| 4008 | FDC2 = 0x370; |
| 4009 | #endif |
| 4010 | DP->cmos = ints[2]; |
| 4011 | DPRINT("setting CMOS code to %d\n", ints[2]); |
| 4012 | } |
| 4013 | |
| 4014 | static struct param_table { |
| 4015 | const char *name; |
| 4016 | void (*fn) (int *ints, int param, int param2); |
| 4017 | int *var; |
| 4018 | int def_param; |
| 4019 | int param2; |
| 4020 | } config_params[] __initdata = { |
| 4021 | {"allowed_drive_mask", NULL, &allowed_drive_mask, 0xff, 0}, /* obsolete */ |
| 4022 | {"all_drives", NULL, &allowed_drive_mask, 0xff, 0}, /* obsolete */ |
| 4023 | {"asus_pci", NULL, &allowed_drive_mask, 0x33, 0}, |
| 4024 | {"irq", NULL, &FLOPPY_IRQ, 6, 0}, |
| 4025 | {"dma", NULL, &FLOPPY_DMA, 2, 0}, |
| 4026 | {"daring", daring, NULL, 1, 0}, |
| 4027 | #if N_FDC > 1 |
| 4028 | {"two_fdc", NULL, &FDC2, 0x370, 0}, |
| 4029 | {"one_fdc", NULL, &FDC2, 0, 0}, |
| 4030 | #endif |
| 4031 | {"thinkpad", floppy_set_flags, NULL, 1, FD_INVERTED_DCL}, |
| 4032 | {"broken_dcl", floppy_set_flags, NULL, 1, FD_BROKEN_DCL}, |
| 4033 | {"messages", floppy_set_flags, NULL, 1, FTD_MSG}, |
| 4034 | {"silent_dcl_clear", floppy_set_flags, NULL, 1, FD_SILENT_DCL_CLEAR}, |
| 4035 | {"debug", floppy_set_flags, NULL, 1, FD_DEBUG}, |
| 4036 | {"nodma", NULL, &can_use_virtual_dma, 1, 0}, |
| 4037 | {"omnibook", NULL, &can_use_virtual_dma, 1, 0}, |
| 4038 | {"yesdma", NULL, &can_use_virtual_dma, 0, 0}, |
| 4039 | {"fifo_depth", NULL, &fifo_depth, 0xa, 0}, |
| 4040 | {"nofifo", NULL, &no_fifo, 0x20, 0}, |
| 4041 | {"usefifo", NULL, &no_fifo, 0, 0}, |
| 4042 | {"cmos", set_cmos, NULL, 0, 0}, |
| 4043 | {"slow", NULL, &slow_floppy, 1, 0}, |
| 4044 | {"unexpected_interrupts", NULL, &print_unex, 1, 0}, |
| 4045 | {"no_unexpected_interrupts", NULL, &print_unex, 0, 0}, |
| 4046 | {"L40SX", NULL, &print_unex, 0, 0} |
| 4047 | |
| 4048 | EXTRA_FLOPPY_PARAMS |
| 4049 | }; |
| 4050 | |
| 4051 | static int __init floppy_setup(char *str) |
| 4052 | { |
| 4053 | int i; |
| 4054 | int param; |
| 4055 | int ints[11]; |
| 4056 | |
| 4057 | str = get_options(str, ARRAY_SIZE(ints), ints); |
| 4058 | if (str) { |
| 4059 | for (i = 0; i < ARRAY_SIZE(config_params); i++) { |
| 4060 | if (strcmp(str, config_params[i].name) == 0) { |
| 4061 | if (ints[0]) |
| 4062 | param = ints[1]; |
| 4063 | else |
| 4064 | param = config_params[i].def_param; |
| 4065 | if (config_params[i].fn) |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 4066 | config_params[i].fn(ints, param, |
| 4067 | config_params[i]. |
| 4068 | param2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | if (config_params[i].var) { |
| 4070 | DPRINT("%s=%d\n", str, param); |
| 4071 | *config_params[i].var = param; |
| 4072 | } |
| 4073 | return 1; |
| 4074 | } |
| 4075 | } |
| 4076 | } |
| 4077 | if (str) { |
| 4078 | DPRINT("unknown floppy option [%s]\n", str); |
| 4079 | |
| 4080 | DPRINT("allowed options are:"); |
| 4081 | for (i = 0; i < ARRAY_SIZE(config_params); i++) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 4082 | pr_cont(" %s", config_params[i].name); |
| 4083 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | } else |
| 4085 | DPRINT("botched floppy option\n"); |
Randy Dunlap | 31c00fc | 2008-11-13 21:33:24 +0000 | [diff] [blame] | 4086 | DPRINT("Read Documentation/blockdev/floppy.txt\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | return 0; |
| 4088 | } |
| 4089 | |
| 4090 | static int have_no_fdc = -ENODEV; |
| 4091 | |
Andrew Morton | 9a8af6b | 2005-07-27 17:37:34 -0700 | [diff] [blame] | 4092 | static ssize_t floppy_cmos_show(struct device *dev, |
| 4093 | struct device_attribute *attr, char *buf) |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 4094 | { |
Eric Miao | 71b3e0c | 2009-01-31 22:47:44 +0800 | [diff] [blame] | 4095 | struct platform_device *p = to_platform_device(dev); |
Andrew Morton | 9a8af6b | 2005-07-27 17:37:34 -0700 | [diff] [blame] | 4096 | int drive; |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 4097 | |
Andrew Morton | 9a8af6b | 2005-07-27 17:37:34 -0700 | [diff] [blame] | 4098 | drive = p->id; |
| 4099 | return sprintf(buf, "%X\n", UDP->cmos); |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 4100 | } |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 4101 | |
Stephen Hemminger | be1c0fb | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4102 | static DEVICE_ATTR(cmos, S_IRUGO, floppy_cmos_show, NULL); |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 4103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | static void floppy_device_release(struct device *dev) |
| 4105 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
Frans Pop | c90cd33 | 2009-07-25 22:24:54 +0200 | [diff] [blame] | 4108 | static int floppy_resume(struct device *dev) |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4109 | { |
| 4110 | int fdc; |
| 4111 | |
| 4112 | for (fdc = 0; fdc < N_FDC; fdc++) |
| 4113 | if (FDCS->address != -1) |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 4114 | user_reset_fdc(-1, FD_RESET_ALWAYS, false); |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4115 | |
| 4116 | return 0; |
| 4117 | } |
| 4118 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 4119 | static const struct dev_pm_ops floppy_pm_ops = { |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4120 | .resume = floppy_resume, |
Frans Pop | c90cd33 | 2009-07-25 22:24:54 +0200 | [diff] [blame] | 4121 | .restore = floppy_resume, |
| 4122 | }; |
| 4123 | |
| 4124 | static struct platform_driver floppy_driver = { |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4125 | .driver = { |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 4126 | .name = "floppy", |
| 4127 | .pm = &floppy_pm_ops, |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4128 | }, |
| 4129 | }; |
| 4130 | |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 4131 | static struct platform_device floppy_device[N_DRIVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | |
| 4133 | static struct kobject *floppy_find(dev_t dev, int *part, void *data) |
| 4134 | { |
| 4135 | int drive = (*part & 3) | ((*part & 0x80) >> 5); |
| 4136 | if (drive >= N_DRIVE || |
| 4137 | !(allowed_drive_mask & (1 << drive)) || |
| 4138 | fdc_state[FDC(drive)].version == FDC_NONE) |
| 4139 | return NULL; |
Tobias Klauser | 945f390 | 2006-01-08 01:05:11 -0800 | [diff] [blame] | 4140 | if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | return NULL; |
| 4142 | *part = 0; |
| 4143 | return get_disk(disks[drive]); |
| 4144 | } |
| 4145 | |
| 4146 | static int __init floppy_init(void) |
| 4147 | { |
| 4148 | int i, unit, drive; |
| 4149 | int err, dr; |
| 4150 | |
Stephen Hemminger | 285203c | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4151 | set_debugt(); |
| 4152 | interruptjiffies = resultjiffies = jiffies; |
| 4153 | |
Kumar Gala | 68e1ee6 | 2008-09-22 14:41:31 -0700 | [diff] [blame] | 4154 | #if defined(CONFIG_PPC) |
Olaf Hering | ef16b51 | 2006-08-31 21:27:41 -0700 | [diff] [blame] | 4155 | if (check_legacy_ioport(FDC1)) |
| 4156 | return -ENODEV; |
| 4157 | #endif |
| 4158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | raw_cmd = NULL; |
| 4160 | |
| 4161 | for (dr = 0; dr < N_DRIVE; dr++) { |
| 4162 | disks[dr] = alloc_disk(1); |
| 4163 | if (!disks[dr]) { |
| 4164 | err = -ENOMEM; |
| 4165 | goto out_put_disk; |
| 4166 | } |
| 4167 | |
| 4168 | disks[dr]->major = FLOPPY_MAJOR; |
| 4169 | disks[dr]->first_minor = TOMINOR(dr); |
| 4170 | disks[dr]->fops = &floppy_fops; |
| 4171 | sprintf(disks[dr]->disk_name, "fd%d", dr); |
| 4172 | |
| 4173 | init_timer(&motor_off_timer[dr]); |
| 4174 | motor_off_timer[dr].data = dr; |
| 4175 | motor_off_timer[dr].function = motor_off_callback; |
| 4176 | } |
| 4177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | err = register_blkdev(FLOPPY_MAJOR, "fd"); |
| 4179 | if (err) |
Greg Kroah-Hartman | 8ab5e4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 4180 | goto out_put_disk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4182 | err = platform_driver_register(&floppy_driver); |
| 4183 | if (err) |
| 4184 | goto out_unreg_blkdev; |
| 4185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | floppy_queue = blk_init_queue(do_fd_request, &floppy_lock); |
| 4187 | if (!floppy_queue) { |
| 4188 | err = -ENOMEM; |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4189 | goto out_unreg_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | } |
Martin K. Petersen | 086fa5f | 2010-02-26 00:20:38 -0500 | [diff] [blame] | 4191 | blk_queue_max_hw_sectors(floppy_queue, 64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | |
| 4193 | blk_register_region(MKDEV(FLOPPY_MAJOR, 0), 256, THIS_MODULE, |
| 4194 | floppy_find, NULL, NULL); |
| 4195 | |
| 4196 | for (i = 0; i < 256; i++) |
| 4197 | if (ITYPE(i)) |
| 4198 | floppy_sizes[i] = floppy_type[ITYPE(i)].size; |
| 4199 | else |
| 4200 | floppy_sizes[i] = MAX_DISK_SIZE << 1; |
| 4201 | |
Joe Perches | 73507e6 | 2010-03-10 15:21:03 -0800 | [diff] [blame] | 4202 | reschedule_timeout(MAXTIMEOUT, "floppy init"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | config_types(); |
| 4204 | |
| 4205 | for (i = 0; i < N_FDC; i++) { |
| 4206 | fdc = i; |
Joe Perches | b87c9e0 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 4207 | memset(FDCS, 0, sizeof(*FDCS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4208 | FDCS->dtr = -1; |
| 4209 | FDCS->dor = 0x4; |
| 4210 | #if defined(__sparc__) || defined(__mc68000__) |
Joe Perches | 96534f1 | 2010-03-10 15:20:51 -0800 | [diff] [blame] | 4211 | /*sparcs/sun3x don't have a DOR reset which we can fall back on to */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | #ifdef __mc68000__ |
| 4213 | if (MACH_IS_SUN3X) |
| 4214 | #endif |
| 4215 | FDCS->version = FDC_82072A; |
| 4216 | #endif |
| 4217 | } |
| 4218 | |
| 4219 | use_virtual_dma = can_use_virtual_dma & 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | fdc_state[0].address = FDC1; |
| 4221 | if (fdc_state[0].address == -1) { |
| 4222 | del_timer(&fd_timeout); |
| 4223 | err = -ENODEV; |
| 4224 | goto out_unreg_region; |
| 4225 | } |
| 4226 | #if N_FDC > 1 |
| 4227 | fdc_state[1].address = FDC2; |
| 4228 | #endif |
| 4229 | |
| 4230 | fdc = 0; /* reset fdc in case of unexpected interrupt */ |
| 4231 | err = floppy_grab_irq_and_dma(); |
| 4232 | if (err) { |
| 4233 | del_timer(&fd_timeout); |
| 4234 | err = -EBUSY; |
| 4235 | goto out_unreg_region; |
| 4236 | } |
| 4237 | |
| 4238 | /* initialise drive state */ |
| 4239 | for (drive = 0; drive < N_DRIVE; drive++) { |
Joe Perches | b87c9e0 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 4240 | memset(UDRS, 0, sizeof(*UDRS)); |
| 4241 | memset(UDRWE, 0, sizeof(*UDRWE)); |
Joe Perches | e029853 | 2010-03-10 15:20:55 -0800 | [diff] [blame] | 4242 | set_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags); |
| 4243 | set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags); |
| 4244 | set_bit(FD_VERIFY_BIT, &UDRS->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | UDRS->fd_device = -1; |
| 4246 | floppy_track_buffer = NULL; |
| 4247 | max_buffer_sectors = 0; |
| 4248 | } |
| 4249 | /* |
| 4250 | * Small 10 msec delay to let through any interrupt that |
| 4251 | * initialization might have triggered, to not |
| 4252 | * confuse detection: |
| 4253 | */ |
| 4254 | msleep(10); |
| 4255 | |
| 4256 | for (i = 0; i < N_FDC; i++) { |
| 4257 | fdc = i; |
| 4258 | FDCS->driver_version = FD_DRIVER_VERSION; |
| 4259 | for (unit = 0; unit < 4; unit++) |
| 4260 | FDCS->track[unit] = 0; |
| 4261 | if (FDCS->address == -1) |
| 4262 | continue; |
| 4263 | FDCS->rawcmd = 2; |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 4264 | if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | /* free ioports reserved by floppy_grab_irq_and_dma() */ |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 4266 | floppy_release_regions(fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | FDCS->address = -1; |
| 4268 | FDCS->version = FDC_NONE; |
| 4269 | continue; |
| 4270 | } |
| 4271 | /* Try to determine the floppy controller type */ |
| 4272 | FDCS->version = get_fdc_version(); |
| 4273 | if (FDCS->version == FDC_NONE) { |
| 4274 | /* free ioports reserved by floppy_grab_irq_and_dma() */ |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 4275 | floppy_release_regions(fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | FDCS->address = -1; |
| 4277 | continue; |
| 4278 | } |
| 4279 | if (can_use_virtual_dma == 2 && FDCS->version < FDC_82072A) |
| 4280 | can_use_virtual_dma = 0; |
| 4281 | |
| 4282 | have_no_fdc = 0; |
| 4283 | /* Not all FDCs seem to be able to handle the version command |
| 4284 | * properly, so force a reset for the standard FDC clones, |
| 4285 | * to avoid interrupt garbage. |
| 4286 | */ |
Joe Perches | 74f63f4 | 2010-03-10 15:20:58 -0800 | [diff] [blame] | 4287 | user_reset_fdc(-1, FD_RESET_ALWAYS, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | } |
| 4289 | fdc = 0; |
| 4290 | del_timer(&fd_timeout); |
| 4291 | current_drive = 0; |
Joe Perches | 29f1c78 | 2010-03-10 15:21:00 -0800 | [diff] [blame] | 4292 | initialized = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | if (have_no_fdc) { |
| 4294 | DPRINT("no floppy controllers found\n"); |
| 4295 | err = have_no_fdc; |
| 4296 | goto out_flush_work; |
| 4297 | } |
| 4298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | for (drive = 0; drive < N_DRIVE; drive++) { |
| 4300 | if (!(allowed_drive_mask & (1 << drive))) |
| 4301 | continue; |
| 4302 | if (fdc_state[FDC(drive)].version == FDC_NONE) |
| 4303 | continue; |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 4304 | |
| 4305 | floppy_device[drive].name = floppy_device_name; |
| 4306 | floppy_device[drive].id = drive; |
| 4307 | floppy_device[drive].dev.release = floppy_device_release; |
| 4308 | |
| 4309 | err = platform_device_register(&floppy_device[drive]); |
| 4310 | if (err) |
| 4311 | goto out_flush_work; |
| 4312 | |
Joe Perches | d7b2b2e | 2010-03-10 15:20:48 -0800 | [diff] [blame] | 4313 | err = device_create_file(&floppy_device[drive].dev, |
| 4314 | &dev_attr_cmos); |
Dmitriy Monakhov | 4ea1b0f | 2007-05-08 00:25:58 -0700 | [diff] [blame] | 4315 | if (err) |
| 4316 | goto out_unreg_platform_dev; |
| 4317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | /* to be cleaned up... */ |
| 4319 | disks[drive]->private_data = (void *)(long)drive; |
| 4320 | disks[drive]->queue = floppy_queue; |
| 4321 | disks[drive]->flags |= GENHD_FL_REMOVABLE; |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 4322 | disks[drive]->driverfs_dev = &floppy_device[drive].dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | add_disk(disks[drive]); |
| 4324 | } |
| 4325 | |
| 4326 | return 0; |
| 4327 | |
Dmitriy Monakhov | 4ea1b0f | 2007-05-08 00:25:58 -0700 | [diff] [blame] | 4328 | out_unreg_platform_dev: |
| 4329 | platform_device_unregister(&floppy_device[drive]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | out_flush_work: |
| 4331 | flush_scheduled_work(); |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4332 | if (atomic_read(&usage_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | floppy_release_irq_and_dma(); |
| 4334 | out_unreg_region: |
| 4335 | blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); |
| 4336 | blk_cleanup_queue(floppy_queue); |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4337 | out_unreg_driver: |
| 4338 | platform_driver_unregister(&floppy_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | out_unreg_blkdev: |
| 4340 | unregister_blkdev(FLOPPY_MAJOR, "fd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | out_put_disk: |
| 4342 | while (dr--) { |
| 4343 | del_timer(&motor_off_timer[dr]); |
| 4344 | put_disk(disks[dr]); |
| 4345 | } |
| 4346 | return err; |
| 4347 | } |
| 4348 | |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 4349 | static const struct io_region { |
| 4350 | int offset; |
| 4351 | int size; |
| 4352 | } io_regions[] = { |
| 4353 | { 2, 1 }, |
| 4354 | /* address + 3 is sometimes reserved by pnp bios for motherboard */ |
| 4355 | { 4, 2 }, |
| 4356 | /* address + 6 is reserved, and may be taken by IDE. |
| 4357 | * Unfortunately, Adaptec doesn't know this :-(, */ |
| 4358 | { 7, 1 }, |
| 4359 | }; |
| 4360 | |
| 4361 | static void floppy_release_allocated_regions(int fdc, const struct io_region *p) |
| 4362 | { |
| 4363 | while (p != io_regions) { |
| 4364 | p--; |
| 4365 | release_region(FDCS->address + p->offset, p->size); |
| 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | #define ARRAY_END(X) (&((X)[ARRAY_SIZE(X)])) |
| 4370 | |
| 4371 | static int floppy_request_regions(int fdc) |
| 4372 | { |
| 4373 | const struct io_region *p; |
| 4374 | |
| 4375 | for (p = io_regions; p < ARRAY_END(io_regions); p++) { |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 4376 | if (!request_region(FDCS->address + p->offset, |
| 4377 | p->size, "floppy")) { |
| 4378 | DPRINT("Floppy io-port 0x%04lx in use\n", |
| 4379 | FDCS->address + p->offset); |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 4380 | floppy_release_allocated_regions(fdc, p); |
| 4381 | return -EBUSY; |
| 4382 | } |
| 4383 | } |
| 4384 | return 0; |
| 4385 | } |
| 4386 | |
| 4387 | static void floppy_release_regions(int fdc) |
| 4388 | { |
| 4389 | floppy_release_allocated_regions(fdc, ARRAY_END(io_regions)); |
| 4390 | } |
| 4391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | static int floppy_grab_irq_and_dma(void) |
| 4393 | { |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4394 | if (atomic_inc_return(&usage_count) > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4395 | return 0; |
Ingo Molnar | 6dc659d | 2006-03-26 01:36:54 -0800 | [diff] [blame] | 4396 | |
| 4397 | /* |
| 4398 | * We might have scheduled a free_irq(), wait it to |
| 4399 | * drain first: |
| 4400 | */ |
| 4401 | flush_scheduled_work(); |
| 4402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | if (fd_request_irq()) { |
| 4404 | DPRINT("Unable to grab IRQ%d for the floppy driver\n", |
| 4405 | FLOPPY_IRQ); |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4406 | atomic_dec(&usage_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | return -1; |
| 4408 | } |
| 4409 | if (fd_request_dma()) { |
| 4410 | DPRINT("Unable to grab DMA%d for the floppy driver\n", |
| 4411 | FLOPPY_DMA); |
Jan Beulich | 2e9c47c | 2007-10-16 23:27:32 -0700 | [diff] [blame] | 4412 | if (can_use_virtual_dma & 2) |
| 4413 | use_virtual_dma = can_use_virtual_dma = 1; |
| 4414 | if (!(can_use_virtual_dma & 1)) { |
| 4415 | fd_free_irq(); |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4416 | atomic_dec(&usage_count); |
Jan Beulich | 2e9c47c | 2007-10-16 23:27:32 -0700 | [diff] [blame] | 4417 | return -1; |
| 4418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | for (fdc = 0; fdc < N_FDC; fdc++) { |
| 4422 | if (FDCS->address != -1) { |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 4423 | if (floppy_request_regions(fdc)) |
| 4424 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | } |
| 4426 | } |
| 4427 | for (fdc = 0; fdc < N_FDC; fdc++) { |
| 4428 | if (FDCS->address != -1) { |
| 4429 | reset_fdc_info(1); |
| 4430 | fd_outb(FDCS->dor, FD_DOR); |
| 4431 | } |
| 4432 | } |
| 4433 | fdc = 0; |
| 4434 | set_dor(0, ~0, 8); /* avoid immediate interrupt */ |
| 4435 | |
| 4436 | for (fdc = 0; fdc < N_FDC; fdc++) |
| 4437 | if (FDCS->address != -1) |
| 4438 | fd_outb(FDCS->dor, FD_DOR); |
| 4439 | /* |
Jesper Juhl | 06f748c | 2007-10-16 23:30:57 -0700 | [diff] [blame] | 4440 | * The driver will try and free resources and relies on us |
| 4441 | * to know if they were allocated or not. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4442 | */ |
| 4443 | fdc = 0; |
| 4444 | irqdma_allocated = 1; |
| 4445 | return 0; |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 4446 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | fd_free_irq(); |
| 4448 | fd_free_dma(); |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 4449 | while (--fdc >= 0) |
| 4450 | floppy_release_regions(fdc); |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4451 | atomic_dec(&usage_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | return -1; |
| 4453 | } |
| 4454 | |
| 4455 | static void floppy_release_irq_and_dma(void) |
| 4456 | { |
| 4457 | int old_fdc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | #ifndef __sparc__ |
| 4459 | int drive; |
| 4460 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | long tmpsize; |
| 4462 | unsigned long tmpaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4464 | if (!atomic_dec_and_test(&usage_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | return; |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | if (irqdma_allocated) { |
| 4468 | fd_disable_dma(); |
| 4469 | fd_free_dma(); |
Ingo Molnar | 3e541a4 | 2006-07-03 00:24:23 -0700 | [diff] [blame] | 4470 | fd_free_irq(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | irqdma_allocated = 0; |
| 4472 | } |
| 4473 | set_dor(0, ~0, 8); |
| 4474 | #if N_FDC > 1 |
| 4475 | set_dor(1, ~8, 0); |
| 4476 | #endif |
| 4477 | floppy_enable_hlt(); |
| 4478 | |
| 4479 | if (floppy_track_buffer && max_buffer_sectors) { |
| 4480 | tmpsize = max_buffer_sectors * 1024; |
| 4481 | tmpaddr = (unsigned long)floppy_track_buffer; |
| 4482 | floppy_track_buffer = NULL; |
| 4483 | max_buffer_sectors = 0; |
| 4484 | buffer_min = buffer_max = -1; |
| 4485 | fd_dma_mem_free(tmpaddr, tmpsize); |
| 4486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | #ifndef __sparc__ |
| 4488 | for (drive = 0; drive < N_FDC * 4; drive++) |
| 4489 | if (timer_pending(motor_off_timer + drive)) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 4490 | pr_info("motor off timer %d still active\n", drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4491 | #endif |
| 4492 | |
| 4493 | if (timer_pending(&fd_timeout)) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 4494 | pr_info("floppy timer still active:%s\n", timeout_message); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | if (timer_pending(&fd_timer)) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 4496 | pr_info("auxiliary floppy timer still active\n"); |
David Howells | 365970a | 2006-11-22 14:54:49 +0000 | [diff] [blame] | 4497 | if (work_pending(&floppy_work)) |
Joe Perches | b46df35 | 2010-03-10 15:20:46 -0800 | [diff] [blame] | 4498 | pr_info("work still pending\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | old_fdc = fdc; |
| 4500 | for (fdc = 0; fdc < N_FDC; fdc++) |
Philippe De Muyter | 5a74db0 | 2009-02-18 14:48:36 -0800 | [diff] [blame] | 4501 | if (FDCS->address != -1) |
| 4502 | floppy_release_regions(fdc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | fdc = old_fdc; |
| 4504 | } |
| 4505 | |
| 4506 | #ifdef MODULE |
| 4507 | |
| 4508 | static char *floppy; |
| 4509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | static void __init parse_floppy_cfg_string(char *cfg) |
| 4511 | { |
| 4512 | char *ptr; |
| 4513 | |
| 4514 | while (*cfg) { |
Joe Perches | bb57f0c6 | 2010-03-10 15:20:50 -0800 | [diff] [blame] | 4515 | ptr = cfg; |
| 4516 | while (*cfg && *cfg != ' ' && *cfg != '\t') |
| 4517 | cfg++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | if (*cfg) { |
| 4519 | *cfg = '\0'; |
| 4520 | cfg++; |
| 4521 | } |
| 4522 | if (*ptr) |
| 4523 | floppy_setup(ptr); |
| 4524 | } |
| 4525 | } |
| 4526 | |
Jon Schindler | 7afea3b | 2008-04-29 00:59:21 -0700 | [diff] [blame] | 4527 | static int __init floppy_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | { |
| 4529 | if (floppy) |
| 4530 | parse_floppy_cfg_string(floppy); |
| 4531 | return floppy_init(); |
| 4532 | } |
Jon Schindler | 7afea3b | 2008-04-29 00:59:21 -0700 | [diff] [blame] | 4533 | module_init(floppy_module_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | |
Jon Schindler | 7afea3b | 2008-04-29 00:59:21 -0700 | [diff] [blame] | 4535 | static void __exit floppy_module_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | { |
| 4537 | int drive; |
| 4538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4539 | blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); |
| 4540 | unregister_blkdev(FLOPPY_MAJOR, "fd"); |
Ondrej Zary | 5e50b9e | 2009-06-10 12:57:09 -0700 | [diff] [blame] | 4541 | platform_driver_unregister(&floppy_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | |
| 4543 | for (drive = 0; drive < N_DRIVE; drive++) { |
| 4544 | del_timer_sync(&motor_off_timer[drive]); |
| 4545 | |
| 4546 | if ((allowed_drive_mask & (1 << drive)) && |
| 4547 | fdc_state[FDC(drive)].version != FDC_NONE) { |
| 4548 | del_gendisk(disks[drive]); |
Hannes Reinecke | 94fd0db | 2005-07-15 10:09:25 +0200 | [diff] [blame] | 4549 | device_remove_file(&floppy_device[drive].dev, &dev_attr_cmos); |
| 4550 | platform_device_unregister(&floppy_device[drive]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | } |
| 4552 | put_disk(disks[drive]); |
| 4553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | |
| 4555 | del_timer_sync(&fd_timeout); |
| 4556 | del_timer_sync(&fd_timer); |
| 4557 | blk_cleanup_queue(floppy_queue); |
| 4558 | |
Stephen Hemminger | 575cfc6 | 2010-06-15 13:21:11 +0200 | [diff] [blame] | 4559 | if (atomic_read(&usage_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | floppy_release_irq_and_dma(); |
| 4561 | |
| 4562 | /* eject disk, if any */ |
| 4563 | fd_eject(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | } |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 4565 | |
Jon Schindler | 7afea3b | 2008-04-29 00:59:21 -0700 | [diff] [blame] | 4566 | module_exit(floppy_module_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | |
| 4568 | module_param(floppy, charp, 0); |
| 4569 | module_param(FLOPPY_IRQ, int, 0); |
| 4570 | module_param(FLOPPY_DMA, int, 0); |
| 4571 | MODULE_AUTHOR("Alain L. Knaff"); |
| 4572 | MODULE_SUPPORTED_DEVICE("fd"); |
| 4573 | MODULE_LICENSE("GPL"); |
| 4574 | |
Scott James Remnant | 83f9ef4 | 2009-04-02 16:56:47 -0700 | [diff] [blame] | 4575 | /* This doesn't actually get used other than for module information */ |
| 4576 | static const struct pnp_device_id floppy_pnpids[] = { |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 4577 | {"PNP0700", 0}, |
| 4578 | {} |
Scott James Remnant | 83f9ef4 | 2009-04-02 16:56:47 -0700 | [diff] [blame] | 4579 | }; |
Joe Perches | 48c8cee | 2010-03-10 15:20:45 -0800 | [diff] [blame] | 4580 | |
Scott James Remnant | 83f9ef4 | 2009-04-02 16:56:47 -0700 | [diff] [blame] | 4581 | MODULE_DEVICE_TABLE(pnp, floppy_pnpids); |
| 4582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4583 | #else |
| 4584 | |
| 4585 | __setup("floppy=", floppy_setup); |
| 4586 | module_init(floppy_init) |
| 4587 | #endif |
| 4588 | |
| 4589 | MODULE_ALIAS_BLOCKDEV_MAJOR(FLOPPY_MAJOR); |