^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/drivers/block/floppy.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1993, 1994 Alain Knaff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1998 Alan Cox
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * 02.12.91 - Changed to static variables to indicate need for reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * and recalibrate. This makes some things easier (output_byte reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * checking etc), and means less interrupt jumping in case of errors,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * so the code is hopefully easier to understand.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * This file is certainly a mess. I've tried my best to get it working,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * but I don't like programming floppies, and I have only one anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Urgel. I should check for more errors, and do more graceful error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * recovery. Seems there are problems with several drives. I've tried to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * correct them. No promises.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * As with hd.c, all routines within this file can (and will) be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * by interrupts, so extreme caution is needed. A hardware interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * handler may not sleep, or a kernel panic will happen. Thus I cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * call "floppy-on" directly, but have to set a special timer interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * 28.02.92 - made track-buffering routines, based on the routines written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * by entropy@wintermute.wpi.edu (Lawrence Foard). Linus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Automatic floppy-detection and formatting written by Werner Almesberger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * (almesber@nessie.cs.id.ethz.ch), who also corrected some problems with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * the floppy-change signal detection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * 1992/7/22 -- Hennus Bergman: Added better error reporting, fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * FDC data overrun bug, added some preliminary stuff for vertical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * recording support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * 1992/9/17: Added DMA allocation & DMA functions. -- hhb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * TODO: Errors are still not counted properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* 1992/9/20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * Modifications for ``Sector Shifting'' by Rob Hooft (hooft@chem.ruu.nl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * modeled after the freeware MS-DOS program fdformat/88 V1.8 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Christoph H. Hochst\"atter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * I have fixed the shift values to the ones I always use. Maybe a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * ioctl() should be created to be able to modify them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * There is a bug in the driver that makes it impossible to format a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * floppy as the first thing after bootup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * 1993/4/29 -- Linus -- cleaned up the timer handling in the kernel, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * this helped the floppy driver as well. Much cleaner, and still seems to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* 1994/6/24 --bbroad-- added the floppy table entries and made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * minor modifications to allow 2.88 floppies to be run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* 1994/7/13 -- Paul Vojta -- modified the probing code to allow three or more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * disk types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * 1994/8/8 -- Alain Knaff -- Switched to fdpatch driver: Support for bigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * format bug fixes, but unfortunately some new bugs too...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* 1994/9/17 -- Koen Holtman -- added logging of physical floppy write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * errors to allow safe writing by specialized programs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* 1995/4/24 -- Dan Fandrich -- added support for Commodore 1581 3.5" disks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * by defining bit 1 of the "stretch" parameter to mean put sectors on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * opposite side of the disk, leaving the sector IDs alone (i.e. Commodore's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * drives are "upside-down").
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * 1995/8/26 -- Andreas Busse -- added Mips support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * 1995/10/18 -- Ralf Baechle -- Portability cleanup; move machine dependent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * features to asm/floppy.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * 1998/1/21 -- Richard Gooch <rgooch@atnf.csiro.au> -- devfs support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * 1998/05/07 -- Russell King -- More portability cleanups; moved definition of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * interrupt and dma channel to asm/floppy.h. Cleaned up some formatting &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * use of '0' for NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * 1998/06/07 -- Alan Cox -- Merged the 2.0.34 fixes for resource allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * failures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * 1998/09/20 -- David Weinehall -- Added slow-down code for buggy PS/2-drives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * 1999/08/13 -- Paul Slootman -- floppy stopped working on Alpha after 24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * days, 6 hours, 32 minutes and 32 seconds (i.e. MAXINT jiffies; ints were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * being used to store jiffies, which are unsigned longs).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * 2000/08/28 -- Arnaldo Carvalho de Melo <acme@conectiva.com.br>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * - get rid of check_region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * - s/suser/capable/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * 2001/08/26 -- Paul Gortmaker - fix insmod oops on machines with no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * floppy controller (lingering task on list after module is gone... boom.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * 2002/02/07 -- Anton Altaparmakov - Fix io ports reservation to correct range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * (0x3f2-0x3f5, 0x3f7). This fix is a bit of a hack but the proper fix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * requires many non-obvious changes in arch dependent code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* 2003/07/28 -- Daniele Bellucci <bellucda@tiscali.it>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Better audit of register_blkdev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #undef FLOPPY_SILENT_DCL_CLEAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #define REALLY_SLOW_IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define DEBUGT 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define DPRINT(format, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) pr_info("floppy%d: " format, current_drive, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define DCL_DEBUG /* debug disk change line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #ifdef DCL_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #define debug_dcl(test, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) do { if ((test) & FD_DEBUG) DPRINT(fmt, ##args); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #define debug_dcl(test, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) do { if (0) DPRINT(fmt, ##args); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* do print messages for unexpected interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int print_unex = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #include <linux/fdreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #include <linux/fd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #include <linux/hdreg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #include <linux/mc146818rtc.h> /* CMOS defines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #include <linux/mod_devicetable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #include <linux/async.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * PS/2 floppies have much slower step rates than regular floppies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * It's been recommended that take about 1/4 of the default speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * in some more extreme cases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static DEFINE_MUTEX(floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int slow_floppy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int FLOPPY_IRQ = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int FLOPPY_DMA = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static int can_use_virtual_dma = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* =======
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * can use virtual DMA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * 0 = use of virtual DMA disallowed by config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * 1 = use of virtual DMA prescribed by config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * 2 = no virtual DMA preference configured. By default try hard DMA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * but fall back on virtual DMA when not enough memory available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int use_virtual_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* =======
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * use virtual DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * 0 using hard DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * 1 using virtual DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * This variable is set to virtual when a DMA mem problem arises, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * reset back in floppy_grab_irq_and_dma.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * It is not safe to reset it in other circumstances, because the floppy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * driver may have several buffers in use at once, and we do currently not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * record each buffers capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static DEFINE_SPINLOCK(floppy_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static unsigned short virtual_dma_port = 0x3f0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) irqreturn_t floppy_interrupt(int irq, void *dev_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int set_dor(int fdc, char mask, char data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define K_64 0x10000 /* 64KB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* the following is the mask of allowed drives. By default units 2 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * 3 of both floppy controllers are disabled, because switching on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * motor of these drives causes system hangs on some PCI computers. drive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * 0 is the low bit (0x1), and drive 7 is the high bit (0x80). Bits are on if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * a drive is allowed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * NOTE: This must come before we include the arch floppy header because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * some ports reference this variable from there. -DaveM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int allowed_drive_mask = 0x33;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #include <asm/floppy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int irqdma_allocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #include <linux/blk-mq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #include <linux/blkpg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #include <linux/cdrom.h> /* for the compatibility eject ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static LIST_HEAD(floppy_reqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static struct request *current_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static int set_next_request(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #ifndef fd_get_dma_residue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #define fd_get_dma_residue() get_dma_residue(FLOPPY_DMA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Dma Memory related stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #ifndef fd_dma_mem_free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #define fd_dma_mem_free(addr, size) free_pages(addr, get_order(size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) #ifndef fd_dma_mem_alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #define fd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL, get_order(size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #ifndef fd_cacheflush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define fd_cacheflush(addr, size) /* nothing... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static inline void fallback_on_nodma_alloc(char **addr, size_t l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #ifdef FLOPPY_CAN_FALLBACK_ON_NODMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (*addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return; /* we have the memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (can_use_virtual_dma != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return; /* no fallback allowed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) pr_info("DMA memory shortage. Temporarily falling back on virtual DMA\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) *addr = (char *)nodma_mem_alloc(l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* End dma memory related stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static unsigned long fake_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static bool initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #define ITYPE(x) (((x) >> 2) & 0x1f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #define TOMINOR(x) ((x & 3) | ((x & 4) << 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #define UNIT(x) ((x) & 0x03) /* drive on fdc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #define FDC(x) (((x) & 0x04) >> 2) /* fdc of drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* reverse mapping from unit and fdc to drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* read/write commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #define COMMAND 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) #define DR_SELECT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #define TRACK 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #define HEAD 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) #define SECTOR 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #define SIZECODE 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #define SECT_PER_TRACK 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #define GAP 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #define SIZECODE2 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define NR_RW 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /* format commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #define F_SIZECODE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #define F_SECT_PER_TRACK 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #define F_GAP 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #define F_FILL 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #define NR_F 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * Maximum disk size (in kilobytes).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * This default is used whenever the current disk size is unknown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * [Now it is rather a minimum]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) #define MAX_DISK_SIZE 4 /* 3984 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * globals used by 'result()'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static unsigned char reply_buffer[FD_RAW_REPLY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int inr; /* size of reply buffer, when called from interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #define ST0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #define ST1 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) #define ST2 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #define ST3 0 /* result of GETSTATUS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) #define R_TRACK 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #define R_HEAD 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #define R_SECTOR 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #define R_SIZECODE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) #define SEL_DLY (2 * HZ / 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * this struct defines the different floppy drive types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct floppy_drive_params params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) const char *name; /* name printed while booting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) } default_drive_params[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /* NOTE: the time values in jiffies should be in msec!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) CMOS drive type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) | Maximum data rate supported by drive type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) | | Head load time, msec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) | | | Head unload time, msec (not used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) | | | | Step rate interval, usec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) | | | | | Time needed for spinup time (jiffies)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) | | | | | | Timeout for spinning down (jiffies)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) | | | | | | | Spindown offset (where disk stops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) | | | | | | | | Select delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) | | | | | | | | | RPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) | | | | | | | | | | Max number of tracks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) | | | | | | | | | | | Interrupt timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) | | | | | | | | | | | | Max nonintlv. sectors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) | | | | | | | | | | | | | -Max Errors- flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {{0, 500, 16, 16, 8000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 80, 3*HZ, 20, {3,1,2,0,2}, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 0, { 7, 4, 8, 2, 1, 5, 3,10}, 3*HZ/2, 0 }, "unknown" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {{1, 300, 16, 16, 8000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 40, 3*HZ, 17, {3,1,2,0,2}, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 0, { 1, 0, 0, 0, 0, 0, 0, 0}, 3*HZ/2, 1 }, "360K PC" }, /*5 1/4 360 KB PC*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {{2, 500, 16, 16, 6000, 4*HZ/10, 3*HZ, 14, SEL_DLY, 6, 83, 3*HZ, 17, {3,1,2,0,2}, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 0, { 2, 5, 6,23,10,20,12, 0}, 3*HZ/2, 2 }, "1.2M" }, /*5 1/4 HD AT*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {{3, 250, 16, 16, 3000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 83, 3*HZ, 20, {3,1,2,0,2}, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 0, { 4,22,21,30, 3, 0, 0, 0}, 3*HZ/2, 4 }, "720k" }, /*3 1/2 DD*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {{4, 500, 16, 16, 4000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 20, {3,1,2,0,2}, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 0, { 7, 4,25,22,31,21,29,11}, 3*HZ/2, 7 }, "1.44M" }, /*3 1/2 HD*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {{5, 1000, 15, 8, 3000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 40, {3,1,2,0,2}, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 0, { 7, 8, 4,25,28,22,31,21}, 3*HZ/2, 8 }, "2.88M AMI BIOS" }, /*3 1/2 ED*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {{6, 1000, 15, 8, 3000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 40, {3,1,2,0,2}, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 0, { 7, 8, 4,25,28,22,31,21}, 3*HZ/2, 8 }, "2.88M" } /*3 1/2 ED*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /* | --autodetected formats--- | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * read_track | | Name printed when booting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * | Native format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * Frequency of disk change checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static struct floppy_drive_params drive_params[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static struct floppy_drive_struct drive_state[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static struct floppy_write_errors write_errors[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static struct timer_list motor_off_timer[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static struct gendisk *disks[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static struct blk_mq_tag_set tag_sets[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static struct block_device *opened_bdev[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static DEFINE_MUTEX(open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static struct floppy_raw_cmd *raw_cmd, default_raw_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * This struct defines the different floppy types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * Bit 0 of 'stretch' tells if the tracks need to be doubled for some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * types (e.g. 360kB diskette in 1.2MB drive, etc.). Bit 1 of 'stretch'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * tells if the disk is in Commodore 1581 format, which means side 0 sectors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * are located on side 1 of the disk but with a side 0 ID, and vice-versa.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * This is the same as the Sharp MZ-80 5.25" CP/M disk format, except that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * 1581's logical side 0 is on physical side 1, whereas the Sharp's logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * side 0 is on physical side 0 (but with the misnamed sector IDs).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * 'stretch' should probably be renamed to something more general, like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * 'options'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * Bits 2 through 9 of 'stretch' tell the number of the first sector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * The LSB (bit 2) is flipped. For most disks, the first sector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * is 1 (represented by 0x00<<2). For some CP/M and music sampler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * disks (such as Ensoniq EPS 16plus) it is 0 (represented as 0x01<<2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * For Amstrad CPC disks it is 0xC1 (represented as 0xC0<<2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * Other parameters should be self-explanatory (see also setfdprm(8)).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) Size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) | Sectors per track
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) | | Head
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) | | | Tracks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) | | | | Stretch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) | | | | | Gap 1 size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) | | | | | | Data rate, | 0x40 for perp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) | | | | | | | Spec1 (stepping rate, head unload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) | | | | | | | | /fmt gap (gap2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static struct floppy_struct floppy_type[32] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) { 0, 0,0, 0,0,0x00,0x00,0x00,0x00,NULL }, /* 0 no testing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) { 720, 9,2,40,0,0x2A,0x02,0xDF,0x50,"d360" }, /* 1 360KB PC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) { 2400,15,2,80,0,0x1B,0x00,0xDF,0x54,"h1200" }, /* 2 1.2MB AT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) { 720, 9,1,80,0,0x2A,0x02,0xDF,0x50,"D360" }, /* 3 360KB SS 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) { 1440, 9,2,80,0,0x2A,0x02,0xDF,0x50,"D720" }, /* 4 720KB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) { 720, 9,2,40,1,0x23,0x01,0xDF,0x50,"h360" }, /* 5 360KB AT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) { 1440, 9,2,80,0,0x23,0x01,0xDF,0x50,"h720" }, /* 6 720KB AT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,"H1440" }, /* 7 1.44MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) { 5760,36,2,80,0,0x1B,0x43,0xAF,0x54,"E2880" }, /* 8 2.88MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) { 6240,39,2,80,0,0x1B,0x43,0xAF,0x28,"E3120" }, /* 9 3.12MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) { 2880,18,2,80,0,0x25,0x00,0xDF,0x02,"h1440" }, /* 10 1.44MB 5.25" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) { 3360,21,2,80,0,0x1C,0x00,0xCF,0x0C,"H1680" }, /* 11 1.68MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) { 820,10,2,41,1,0x25,0x01,0xDF,0x2E,"h410" }, /* 12 410KB 5.25" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) { 1640,10,2,82,0,0x25,0x02,0xDF,0x2E,"H820" }, /* 13 820KB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) { 2952,18,2,82,0,0x25,0x00,0xDF,0x02,"h1476" }, /* 14 1.48MB 5.25" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) { 3444,21,2,82,0,0x25,0x00,0xDF,0x0C,"H1722" }, /* 15 1.72MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) { 840,10,2,42,1,0x25,0x01,0xDF,0x2E,"h420" }, /* 16 420KB 5.25" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) { 1660,10,2,83,0,0x25,0x02,0xDF,0x2E,"H830" }, /* 17 830KB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) { 2988,18,2,83,0,0x25,0x00,0xDF,0x02,"h1494" }, /* 18 1.49MB 5.25" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) { 3486,21,2,83,0,0x25,0x00,0xDF,0x0C,"H1743" }, /* 19 1.74 MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) { 1760,11,2,80,0,0x1C,0x09,0xCF,0x00,"h880" }, /* 20 880KB 5.25" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) { 2080,13,2,80,0,0x1C,0x01,0xCF,0x00,"D1040" }, /* 21 1.04MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) { 2240,14,2,80,0,0x1C,0x19,0xCF,0x00,"D1120" }, /* 22 1.12MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) { 3200,20,2,80,0,0x1C,0x20,0xCF,0x2C,"h1600" }, /* 23 1.6MB 5.25" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) { 3520,22,2,80,0,0x1C,0x08,0xCF,0x2e,"H1760" }, /* 24 1.76MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) { 3840,24,2,80,0,0x1C,0x20,0xCF,0x00,"H1920" }, /* 25 1.92MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) { 6400,40,2,80,0,0x25,0x5B,0xCF,0x00,"E3200" }, /* 26 3.20MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) { 7040,44,2,80,0,0x25,0x5B,0xCF,0x00,"E3520" }, /* 27 3.52MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) { 7680,48,2,80,0,0x25,0x63,0xCF,0x00,"E3840" }, /* 28 3.84MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) { 3680,23,2,80,0,0x1C,0x10,0xCF,0x00,"H1840" }, /* 29 1.84MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) { 1600,10,2,80,0,0x25,0x02,0xDF,0x2E,"D800" }, /* 30 800KB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) { 3200,20,2,80,0,0x1C,0x00,0xCF,0x2C,"H1600" }, /* 31 1.6MB 3.5" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) #define SECTSIZE (_FD_SECTSIZE(*floppy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /* Auto-detection: Disk type used until the next media change occurs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static struct floppy_struct *current_type[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * User-provided type information. current_type points to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) * the respective entry of this array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static struct floppy_struct user_params[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static sector_t floppy_sizes[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static char floppy_device_name[] = "floppy";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * The driver is trying to determine the correct media format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * while probing is set. rw_interrupt() clears it after a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * successful access.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static int probing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /* Synchronization of FDC access. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) #define FD_COMMAND_NONE -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) #define FD_COMMAND_ERROR 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) #define FD_COMMAND_OKAY 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static volatile int command_status = FD_COMMAND_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static unsigned long fdc_busy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static DECLARE_WAIT_QUEUE_HEAD(fdc_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static DECLARE_WAIT_QUEUE_HEAD(command_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) /* Errors during formatting are counted here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static int format_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /* Format request descriptor. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static struct format_descr format_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * Rate is 0 for 500kb/s, 1 for 300kbps, 2 for 250kbps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * Spec1 is 0xSH, where S is stepping rate (F=1ms, E=2ms, D=3ms etc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * H is head unload time (1=16ms, 2=32ms, etc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * Track buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * Because these are written to by the DMA controller, they must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) * not contain a 64k byte boundary crossing, or data will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) * corrupted/lost.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) static char *floppy_track_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static int max_buffer_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static int *errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) typedef void (*done_f)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) static const struct cont_t {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) void (*interrupt)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /* this is called after the interrupt of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * main command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) void (*redo)(void); /* this is called to retry the operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) void (*error)(void); /* this is called to tally an error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) done_f done; /* this is called to say if the operation has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) * succeeded/failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) } *cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static void floppy_ready(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) static void floppy_start(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static void process_fd_request(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) static void recalibrate_floppy(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static void floppy_shutdown(struct work_struct *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static int floppy_request_regions(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static void floppy_release_regions(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) static int floppy_grab_irq_and_dma(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static void floppy_release_irq_and_dma(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * The "reset" variable should be tested whenever an interrupt is scheduled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * after the commands have been sent. This is to ensure that the driver doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * get wedged when the interrupt doesn't come because of a failed command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) * reset doesn't need to be tested before sending commands, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * output_byte is automatically disabled when reset is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) static void reset_fdc(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static int floppy_revalidate(struct gendisk *disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * These are global variables, as that's the easiest way to give
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * information to interrupts. They are the data used for the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) #define NO_TRACK -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) #define NEED_1_RECAL -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) #define NEED_2_RECAL -3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static atomic_t usage_count = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /* buffer related variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static int buffer_track = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static int buffer_drive = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static int buffer_min = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static int buffer_max = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* fdc related variables, should end up in a struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) static struct floppy_fdc_state fdc_state[N_FDC];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) static int current_fdc; /* current fdc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static struct workqueue_struct *floppy_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static struct floppy_struct *_floppy = floppy_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static unsigned char current_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static long current_count_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) static unsigned char fsector_t; /* sector in track */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static unsigned char in_sector_offset; /* offset within physical sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * expressed in units of 512 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static inline unsigned char fdc_inb(int fdc, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return fd_inb(fdc_state[fdc].address, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) static inline void fdc_outb(unsigned char value, int fdc, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) fd_outb(value, fdc_state[fdc].address, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static inline bool drive_no_geom(int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return !current_type[drive] && !ITYPE(drive_state[drive].fd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) #ifndef fd_eject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) static inline int fd_eject(int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * Debugging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) #ifdef DEBUGT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static long unsigned debugtimer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) static inline void set_debugt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) debugtimer = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) static inline void debugt(const char *func, const char *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (drive_params[current_drive].flags & DEBUGT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) static inline void set_debugt(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static inline void debugt(const char *func, const char *msg) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) #endif /* DEBUGT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static DECLARE_DELAYED_WORK(fd_timeout, floppy_shutdown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) static const char *timeout_message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static void is_alive(const char *func, const char *message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /* this routine checks whether the floppy driver is "alive" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (test_bit(0, &fdc_busy) && command_status < 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) !delayed_work_pending(&fd_timeout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) DPRINT("%s: timeout handler died. %s\n", func, message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static void (*do_floppy)(void) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) #define OLOGSIZE 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static void (*lasthandler)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static unsigned long interruptjiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) static unsigned long resultjiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) static int resultsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) static unsigned long lastredo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static struct output_log {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) unsigned char data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) unsigned long jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) } output_log[OLOGSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int output_log_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) #define MAXTIMEOUT -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) static void __reschedule_timeout(int drive, const char *message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (drive < 0 || drive >= N_DRIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) delay = 20UL * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) drive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) delay = drive_params[drive].timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) mod_delayed_work(floppy_wq, &fd_timeout, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (drive_params[drive].flags & FD_DEBUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) DPRINT("reschedule timeout %s\n", message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) timeout_message = message;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) static void reschedule_timeout(int drive, const char *message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) spin_lock_irqsave(&floppy_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) __reschedule_timeout(drive, message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) spin_unlock_irqrestore(&floppy_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) #define INFBOUND(a, b) (a) = max_t(int, a, b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) #define SUPBOUND(a, b) (a) = min_t(int, a, b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * Bottom half floppy driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * ==========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * This part of the file contains the code talking directly to the hardware,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * and also the main service loop (seek-configure-spinup-command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * disk change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) * This routine is responsible for maintaining the FD_DISK_CHANGE flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * and the last_checked date.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) * last_checked is the date of the last check which showed 'no disk change'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) * FD_DISK_CHANGE is set under two conditions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) * 1. The floppy has been changed after some i/o to that floppy already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) * took place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) * 2. No floppy disk is in the drive. This is done in order to ensure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) * requests are quickly flushed in case there is no disk in the drive. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) * follows that FD_DISK_CHANGE can only be cleared if there is a disk in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) * the drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * For 1., maxblock is observed. Maxblock is 0 if no i/o has taken place yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) * For 2., FD_DISK_NEWCHANGE is watched. FD_DISK_NEWCHANGE is cleared on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * each seek. If a disk is present, the disk change line should also be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) * cleared on each seek. Thus, if FD_DISK_NEWCHANGE is clear, but the disk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * change line is set, this means either that no disk is in the drive, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) * that it has been removed since the last seek.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * This means that we really have a third possibility too:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * The floppy has been changed after the last seek.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) static int disk_change(int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) int fdc = FDC(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (time_before(jiffies, drive_state[drive].select_date + drive_params[drive].select_delay))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) DPRINT("WARNING disk change called early\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) (fdc_state[fdc].dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) DPRINT("probing disk change on unselected drive\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) (unsigned int)fdc_state[fdc].dor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) debug_dcl(drive_params[drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) "checking disk change line for drive %d\n", drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) debug_dcl(drive_params[drive].flags, "jiffies=%lu\n", jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) debug_dcl(drive_params[drive].flags, "disk change line=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) fdc_inb(fdc, FD_DIR) & 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) debug_dcl(drive_params[drive].flags, "flags=%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) if (drive_params[drive].flags & FD_BROKEN_DCL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) return test_bit(FD_DISK_CHANGED_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) if ((fdc_inb(fdc, FD_DIR) ^ drive_params[drive].flags) & 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /* verify write protection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (drive_state[drive].maxblock) /* mark it changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) set_bit(FD_DISK_CHANGED_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /* invalidate its geometry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (drive_state[drive].keep_data >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if ((drive_params[drive].flags & FTD_MSG) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) current_type[drive] != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) DPRINT("Disk type is undefined after disk change\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) current_type[drive] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) floppy_sizes[TOMINOR(drive)] = MAX_DISK_SIZE << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) drive_state[drive].last_checked = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) clear_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) static inline int is_selected(int dor, int unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) return ((dor & (0x10 << unit)) && (dor & 3) == unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) static bool is_ready_state(int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) int state = status & (STATUS_READY | STATUS_DIR | STATUS_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) return state == STATUS_READY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) static int set_dor(int fdc, char mask, char data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) unsigned char unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) unsigned char drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) unsigned char newdor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) unsigned char olddor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (fdc_state[fdc].address == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) olddor = fdc_state[fdc].dor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) newdor = (olddor & mask) | data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) if (newdor != olddor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) unit = olddor & 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) if (is_selected(olddor, unit) && !is_selected(newdor, unit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) drive = REVDRIVE(fdc, unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) debug_dcl(drive_params[drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) "calling disk change from set_dor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) disk_change(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) fdc_state[fdc].dor = newdor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) fdc_outb(newdor, fdc, FD_DOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) unit = newdor & 0x3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (!is_selected(olddor, unit) && is_selected(newdor, unit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) drive = REVDRIVE(fdc, unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) drive_state[drive].select_date = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) return olddor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) static void twaddle(int fdc, int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (drive_params[drive].select_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) fdc_outb(fdc_state[fdc].dor & ~(0x10 << UNIT(drive)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) fdc, FD_DOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) drive_state[drive].select_date = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) * Reset all driver information about the specified fdc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) * This is needed after a reset, and after a raw command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) static void reset_fdc_info(int fdc, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) fdc_state[fdc].spec1 = fdc_state[fdc].spec2 = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) fdc_state[fdc].need_configure = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) fdc_state[fdc].perp_mode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) fdc_state[fdc].rawcmd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) for (drive = 0; drive < N_DRIVE; drive++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (FDC(drive) == fdc &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) (mode || drive_state[drive].track != NEED_1_RECAL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) drive_state[drive].track = NEED_2_RECAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * selects the fdc and drive, and enables the fdc's input/dma.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * Both current_drive and current_fdc are changed to match the new drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) static void set_fdc(int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) unsigned int fdc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) if (drive < 0 || drive >= N_DRIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) pr_info("bad drive value %d\n", drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) fdc = FDC(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (fdc >= N_FDC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) pr_info("bad fdc value\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) set_dor(fdc, ~0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) #if N_FDC > 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) set_dor(1 - fdc, ~8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) if (fdc_state[fdc].rawcmd == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) reset_fdc_info(fdc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (fdc_inb(fdc, FD_STATUS) != STATUS_READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) fdc_state[fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) current_drive = drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) current_fdc = fdc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) * locks the driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) * Both current_drive and current_fdc are changed to match the new drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) static int lock_fdc(int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (WARN(atomic_read(&usage_count) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) "Trying to lock fdc while usage count=0\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (wait_event_interruptible(fdc_wait, !test_and_set_bit(0, &fdc_busy)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) command_status = FD_COMMAND_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) reschedule_timeout(drive, "lock fdc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) set_fdc(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) /* unlocks the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) static void unlock_fdc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) if (!test_bit(0, &fdc_busy))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) DPRINT("FDC access conflict!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) raw_cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) command_status = FD_COMMAND_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) cancel_delayed_work(&fd_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) do_floppy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) cont = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) clear_bit(0, &fdc_busy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) wake_up(&fdc_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) /* switches the motor off after a given timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) static void motor_off_callback(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) unsigned long nr = t - motor_off_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) unsigned char mask = ~(0x10 << UNIT(nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (WARN_ON_ONCE(nr >= N_DRIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) set_dor(FDC(nr), mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) /* schedules motor off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) static void floppy_off(unsigned int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) unsigned long volatile delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) int fdc = FDC(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) del_timer(motor_off_timer + drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) /* make spindle stop in a position which minimizes spinup time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) * next time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (drive_params[drive].rps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) delta = jiffies - drive_state[drive].first_read_date + HZ -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) drive_params[drive].spindown_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) delta = ((delta * drive_params[drive].rps) % HZ) / drive_params[drive].rps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) motor_off_timer[drive].expires =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) jiffies + drive_params[drive].spindown - delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) add_timer(motor_off_timer + drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) * cycle through all N_DRIVE floppy drives, for disk change testing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) * stopping at current drive. This is done before any long operation, to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) * be sure to have up to date disk change information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) static void scandrives(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) int saved_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (drive_params[current_drive].select_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) saved_drive = current_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) for (i = 0; i < N_DRIVE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) drive = (saved_drive + i + 1) % N_DRIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) if (drive_state[drive].fd_ref == 0 || drive_params[drive].select_delay != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) continue; /* skip closed drives */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) set_fdc(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) if (!(set_dor(current_fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) (0x10 << UNIT(drive))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) /* switch the motor off again, if it was off to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) * begin with */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) set_dor(current_fdc, ~(0x10 << UNIT(drive)), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) set_fdc(saved_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) static void empty(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) static void (*floppy_work_fn)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) static void floppy_work_workfn(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) floppy_work_fn();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) static DECLARE_WORK(floppy_work, floppy_work_workfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) static void schedule_bh(void (*handler)(void))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) WARN_ON(work_pending(&floppy_work));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) floppy_work_fn = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) queue_work(floppy_wq, &floppy_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) static void (*fd_timer_fn)(void) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) static void fd_timer_workfn(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) fd_timer_fn();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) static DECLARE_DELAYED_WORK(fd_timer, fd_timer_workfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) static void cancel_activity(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) do_floppy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) cancel_delayed_work(&fd_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) cancel_work_sync(&floppy_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) /* this function makes sure that the disk stays in the drive during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) * transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) static void fd_watchdog(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) debug_dcl(drive_params[current_drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) "calling disk change from watchdog\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) if (disk_change(current_drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) DPRINT("disk removed during i/o\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) cancel_activity();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) reset_fdc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) cancel_delayed_work(&fd_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) fd_timer_fn = fd_watchdog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) queue_delayed_work(floppy_wq, &fd_timer, HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) static void main_command_interrupt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) cancel_delayed_work(&fd_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) cont->interrupt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) /* waits for a delay (spinup or select) to pass */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) static int fd_wait_for_completion(unsigned long expires,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) void (*function)(void))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) if (fdc_state[current_fdc].reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) reset_fdc(); /* do the reset during sleep to win time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) * if we don't need to sleep, it's a good
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) * occasion anyways */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) if (time_before(jiffies, expires)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) cancel_delayed_work(&fd_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) fd_timer_fn = function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) queue_delayed_work(floppy_wq, &fd_timer, expires - jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) static void setup_DMA(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) unsigned long f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) if (raw_cmd->length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) print_hex_dump(KERN_INFO, "zero dma transfer size: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) DUMP_PREFIX_NONE, 16, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) raw_cmd->fullcmd, raw_cmd->cmd_count, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if (((unsigned long)raw_cmd->kernel_data) % 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) pr_info("non aligned address: %p\n", raw_cmd->kernel_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) f = claim_dma_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) fd_disable_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) #ifdef fd_dma_setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (fd_dma_setup(raw_cmd->kernel_data, raw_cmd->length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) (raw_cmd->flags & FD_RAW_READ) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) DMA_MODE_READ : DMA_MODE_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) fdc_state[current_fdc].address) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) release_dma_lock(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) release_dma_lock(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) fd_clear_dma_ff();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) fd_cacheflush(raw_cmd->kernel_data, raw_cmd->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) fd_set_dma_mode((raw_cmd->flags & FD_RAW_READ) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) DMA_MODE_READ : DMA_MODE_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) fd_set_dma_addr(raw_cmd->kernel_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) fd_set_dma_count(raw_cmd->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) virtual_dma_port = fdc_state[current_fdc].address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) fd_enable_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) release_dma_lock(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) static void show_floppy(int fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) /* waits until the fdc becomes ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) static int wait_til_ready(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) int counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) if (fdc_state[fdc].reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) for (counter = 0; counter < 10000; counter++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) status = fdc_inb(fdc, FD_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) if (status & STATUS_READY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if (initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) show_floppy(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) fdc_state[fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) /* sends a command byte to the fdc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) static int output_byte(int fdc, char byte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) int status = wait_til_ready(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) if (is_ready_state(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) fdc_outb(byte, fdc, FD_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) output_log[output_log_pos].data = byte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) output_log[output_log_pos].status = status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) output_log[output_log_pos].jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) output_log_pos = (output_log_pos + 1) % OLOGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) fdc_state[fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) byte, fdc, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) show_floppy(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) /* gets the response from the fdc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) static int result(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) for (i = 0; i < FD_RAW_REPLY_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) status = wait_til_ready(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) status &= STATUS_DIR | STATUS_READY | STATUS_BUSY | STATUS_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if ((status & ~STATUS_BUSY) == STATUS_READY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) resultjiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) resultsize = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) reply_buffer[i] = fdc_inb(fdc, FD_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) if (initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) fdc, status, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) show_floppy(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) fdc_state[fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) #define MORE_OUTPUT -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) /* does the fdc need more output? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) static int need_more_output(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) int status = wait_til_ready(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) if (is_ready_state(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) return MORE_OUTPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) return result(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) /* Set perpendicular mode as required, based on data rate, if supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) * 82077 Now tested. 1Mbps data rate only possible with 82077-1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) static void perpendicular_mode(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) unsigned char perp_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (raw_cmd->rate & 0x40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) switch (raw_cmd->rate & 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) perp_mode = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) perp_mode = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) DPRINT("Invalid data rate for perpendicular mode!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) fdc_state[fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) * convenient way to return to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) * redo without too much hassle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) * (deep stack et al.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) perp_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) if (fdc_state[fdc].perp_mode == perp_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (fdc_state[fdc].version >= FDC_82077_ORIG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) output_byte(fdc, FD_PERPENDICULAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) output_byte(fdc, perp_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) fdc_state[fdc].perp_mode = perp_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) } else if (perp_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) DPRINT("perpendicular mode not supported by this FDC.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) } /* perpendicular_mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) static int fifo_depth = 0xa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) static int no_fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) static int fdc_configure(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) /* Turn on FIFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) output_byte(fdc, FD_CONFIGURE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (need_more_output(fdc) != MORE_OUTPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) output_byte(fdc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) output_byte(fdc, 0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) output_byte(fdc, 0); /* pre-compensation from track 0 upwards */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) #define NOMINAL_DTR 500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) /* Issue a "SPECIFY" command to set the step rate time, head unload time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) * head load time, and DMA disable flag to values needed by floppy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) * The value "dtr" is the data transfer rate in Kbps. It is needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) * to account for the data rate-based scaling done by the 82072 and 82077
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) * FDC types. This parameter is ignored for other types of FDCs (i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) * 8272a).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) * Note that changing the data transfer rate has a (probably deleterious)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) * effect on the parameters subject to scaling for 82072/82077 FDCs, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) * fdc_specify is called again after each data transfer rate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * srt: 1000 to 16000 in microseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) * hut: 16 to 240 milliseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) * hlt: 2 to 254 milliseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) * These values are rounded up to the next highest available delay time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) static void fdc_specify(int fdc, int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) unsigned char spec1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) unsigned char spec2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) unsigned long srt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) unsigned long hlt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) unsigned long hut;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) unsigned long dtr = NOMINAL_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) unsigned long scale_dtr = NOMINAL_DTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) int hlt_max_code = 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) int hut_max_code = 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) if (fdc_state[fdc].need_configure &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) fdc_state[fdc].version >= FDC_82072A) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) fdc_configure(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) fdc_state[fdc].need_configure = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) switch (raw_cmd->rate & 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) case 3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) dtr = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) dtr = 300;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (fdc_state[fdc].version >= FDC_82078) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) /* chose the default rate table, not the one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) * where 1 = 2 Mbps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) output_byte(fdc, FD_DRIVESPEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) if (need_more_output(fdc) == MORE_OUTPUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) output_byte(fdc, UNIT(drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) output_byte(fdc, 0xc0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) dtr = 250;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) if (fdc_state[fdc].version >= FDC_82072) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) scale_dtr = dtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) hlt_max_code = 0x00; /* 0==256msec*dtr0/dtr (not linear!) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) hut_max_code = 0x0; /* 0==256msec*dtr0/dtr (not linear!) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) /* Convert step rate from microseconds to milliseconds and 4 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) srt = 16 - DIV_ROUND_UP(drive_params[drive].srt * scale_dtr / 1000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) NOMINAL_DTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) if (slow_floppy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) srt = srt / 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) SUPBOUND(srt, 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) INFBOUND(srt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) hlt = DIV_ROUND_UP(drive_params[drive].hlt * scale_dtr / 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) NOMINAL_DTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) if (hlt < 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) hlt = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) else if (hlt > 0x7f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) hlt = hlt_max_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) hut = DIV_ROUND_UP(drive_params[drive].hut * scale_dtr / 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) NOMINAL_DTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) if (hut < 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) hut = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) else if (hut > 0xf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) hut = hut_max_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) spec1 = (srt << 4) | hut;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) spec2 = (hlt << 1) | (use_virtual_dma & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) /* If these parameters did not change, just return with success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) if (fdc_state[fdc].spec1 != spec1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) fdc_state[fdc].spec2 != spec2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) /* Go ahead and set spec1 and spec2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) output_byte(fdc, FD_SPECIFY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) output_byte(fdc, fdc_state[fdc].spec1 = spec1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) output_byte(fdc, fdc_state[fdc].spec2 = spec2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) } /* fdc_specify */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) /* Set the FDC's data transfer rate on behalf of the specified drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) * NOTE: with 82072/82077 FDCs, changing the data rate requires a reissue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) * of the specify command (i.e. using the fdc_specify function).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) static int fdc_dtr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) /* If data rate not already set to desired value, set it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) if ((raw_cmd->rate & 3) == fdc_state[current_fdc].dtr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) /* Set dtr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) fdc_outb(raw_cmd->rate & 3, current_fdc, FD_DCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) /* TODO: some FDC/drive combinations (C&T 82C711 with TEAC 1.2MB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) * need a stabilization period of several milliseconds to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) * enforced after data rate changes before R/W operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) fdc_state[current_fdc].dtr = raw_cmd->rate & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) } /* fdc_dtr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) static void tell_sector(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) pr_cont(": track %d, head %d, sector %d, size %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) reply_buffer[R_TRACK], reply_buffer[R_HEAD],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) reply_buffer[R_SECTOR],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) reply_buffer[R_SIZECODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) } /* tell_sector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) static void print_errors(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) DPRINT("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) if (reply_buffer[ST0] & ST0_ECE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) pr_cont("Recalibrate failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) } else if (reply_buffer[ST2] & ST2_CRC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) pr_cont("data CRC error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) tell_sector();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) } else if (reply_buffer[ST1] & ST1_CRC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) pr_cont("CRC error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) tell_sector();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) } else if ((reply_buffer[ST1] & (ST1_MAM | ST1_ND)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) (reply_buffer[ST2] & ST2_MAM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) if (!probing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) pr_cont("sector not found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) tell_sector();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) pr_cont("probe failed...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) } else if (reply_buffer[ST2] & ST2_WC) { /* seek error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) pr_cont("wrong cylinder");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) } else if (reply_buffer[ST2] & ST2_BC) { /* cylinder marked as bad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) pr_cont("bad cylinder");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) reply_buffer[ST0], reply_buffer[ST1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) reply_buffer[ST2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) tell_sector();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) * OK, this error interpreting routine is called after a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) * DMA read/write has succeeded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) * or failed, so we check the results, and copy any buffers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) * hhb: Added better error reporting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) * ak: Made this into a separate routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) static int interpret_errors(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) char bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) if (inr != 7) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) DPRINT("-- FDC reply error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) /* check IC to find cause of interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) switch (reply_buffer[ST0] & ST0_INTR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) case 0x40: /* error occurred during command execution */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) if (reply_buffer[ST1] & ST1_EOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) return 0; /* occurs with pseudo-DMA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) bad = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) if (reply_buffer[ST1] & ST1_WP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) DPRINT("Drive is write protected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) clear_bit(FD_DISK_WRITABLE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) &drive_state[current_drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) bad = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) } else if (reply_buffer[ST1] & ST1_ND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) set_bit(FD_NEED_TWADDLE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) &drive_state[current_drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) } else if (reply_buffer[ST1] & ST1_OR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) if (drive_params[current_drive].flags & FTD_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) DPRINT("Over/Underrun - retrying\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) bad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) } else if (*errors >= drive_params[current_drive].max_errors.reporting) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) print_errors();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) if (reply_buffer[ST2] & ST2_WC || reply_buffer[ST2] & ST2_BC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) /* wrong cylinder => recal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) drive_state[current_drive].track = NEED_2_RECAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) return bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) case 0x80: /* invalid command given */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) DPRINT("Invalid FDC command given!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) case 0xc0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) DPRINT("Abnormal termination caused by polling\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) cont->error();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) default: /* (0) Normal command termination */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) * This routine is called when everything should be correctly set up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) * for the transfer (i.e. floppy motor is on, the correct floppy is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) * selected, and the head is sitting on the right track).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) static void setup_rw_floppy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) unsigned long ready_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) void (*function)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) flags = raw_cmd->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) if (flags & (FD_RAW_READ | FD_RAW_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) flags |= FD_RAW_INTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) if ((flags & FD_RAW_SPIN) && !(flags & FD_RAW_NO_MOTOR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) ready_date = drive_state[current_drive].spinup_date + drive_params[current_drive].spinup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) /* If spinup will take a long time, rerun scandrives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) * again just before spinup completion. Beware that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) * after scandrives, we must again wait for selection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) if (time_after(ready_date, jiffies + drive_params[current_drive].select_delay)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) ready_date -= drive_params[current_drive].select_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) function = floppy_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) function = setup_rw_floppy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) /* wait until the floppy is spinning fast enough */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) if (fd_wait_for_completion(ready_date, function))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) if ((flags & FD_RAW_READ) || (flags & FD_RAW_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) setup_DMA();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) if (flags & FD_RAW_INTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) do_floppy = main_command_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) for (i = 0; i < raw_cmd->cmd_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) r |= output_byte(current_fdc, raw_cmd->fullcmd[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) debugt(__func__, "rw_command");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) cont->error();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) reset_fdc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) if (!(flags & FD_RAW_INTR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) inr = result(current_fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) cont->interrupt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) } else if (flags & FD_RAW_NEED_DISK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) fd_watchdog();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) static int blind_seek;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) * This is the routine called after every seek (or recalibrate) interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) * from the floppy controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) static void seek_interrupt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) debugt(__func__, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) if (inr != 2 || (reply_buffer[ST0] & 0xF8) != 0x20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) DPRINT("seek failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) drive_state[current_drive].track = NEED_2_RECAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) cont->error();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) if (drive_state[current_drive].track >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) drive_state[current_drive].track != reply_buffer[ST1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) !blind_seek) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) debug_dcl(drive_params[current_drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) "clearing NEWCHANGE flag because of effective seek\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) debug_dcl(drive_params[current_drive].flags, "jiffies=%lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) clear_bit(FD_DISK_NEWCHANGE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) &drive_state[current_drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) /* effective seek */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) drive_state[current_drive].select_date = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) drive_state[current_drive].track = reply_buffer[ST1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) floppy_ready();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) static void check_wp(int fdc, int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) if (test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) /* check write protection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) output_byte(fdc, FD_GETSTATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) output_byte(fdc, UNIT(drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) if (result(fdc) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) fdc_state[fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) clear_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) clear_bit(FD_NEED_TWADDLE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) debug_dcl(drive_params[drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) "checking whether disk is write protected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) debug_dcl(drive_params[drive].flags, "wp=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) reply_buffer[ST3] & 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) if (!(reply_buffer[ST3] & 0x40))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) set_bit(FD_DISK_WRITABLE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) clear_bit(FD_DISK_WRITABLE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) static void seek_floppy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) int track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) blind_seek = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) debug_dcl(drive_params[current_drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) "calling disk change from %s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) if (!test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) /* the media changed flag should be cleared after the seek.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) * If it isn't, this means that there is really no disk in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) * the drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) set_bit(FD_DISK_CHANGED_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) &drive_state[current_drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) if (drive_state[current_drive].track <= NEED_1_RECAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) recalibrate_floppy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) (raw_cmd->flags & FD_RAW_NEED_DISK) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) (drive_state[current_drive].track <= NO_TRACK || drive_state[current_drive].track == raw_cmd->track)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) /* we seek to clear the media-changed condition. Does anybody
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) * know a more elegant way, which works on all drives? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) if (raw_cmd->track)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) track = raw_cmd->track - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) if (drive_params[current_drive].flags & FD_SILENT_DCL_CLEAR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) set_dor(current_fdc, ~(0x10 << UNIT(current_drive)), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) blind_seek = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) raw_cmd->flags |= FD_RAW_NEED_SEEK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) track = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) check_wp(current_fdc, current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) if (raw_cmd->track != drive_state[current_drive].track &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) (raw_cmd->flags & FD_RAW_NEED_SEEK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) track = raw_cmd->track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) setup_rw_floppy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) do_floppy = seek_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) output_byte(current_fdc, FD_SEEK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) output_byte(current_fdc, UNIT(current_drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) if (output_byte(current_fdc, track) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) reset_fdc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) debugt(__func__, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) static void recal_interrupt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) debugt(__func__, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) if (inr != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) else if (reply_buffer[ST0] & ST0_ECE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) switch (drive_state[current_drive].track) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) case NEED_1_RECAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) debugt(__func__, "need 1 recal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) /* after a second recalibrate, we still haven't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) * reached track 0. Probably no drive. Raise an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) * error, as failing immediately might upset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) * computers possessed by the Devil :-) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) cont->error();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) case NEED_2_RECAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) debugt(__func__, "need 2 recal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) /* If we already did a recalibrate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) * and we are not at track 0, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) * means we have moved. (The only way
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) * not to move at recalibration is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) * be already at track 0.) Clear the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) * new change flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) debug_dcl(drive_params[current_drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) "clearing NEWCHANGE flag because of second recalibrate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) clear_bit(FD_DISK_NEWCHANGE_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) &drive_state[current_drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) drive_state[current_drive].select_date = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) debugt(__func__, "default");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) /* Recalibrate moves the head by at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) * most 80 steps. If after one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) * recalibrate we don't have reached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) * track 0, this might mean that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) * started beyond track 80. Try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) * again. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) drive_state[current_drive].track = NEED_1_RECAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) drive_state[current_drive].track = reply_buffer[ST1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) floppy_ready();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) static void print_result(char *message, int inr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) DPRINT("%s ", message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) if (inr >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) for (i = 0; i < inr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) pr_cont("repl[%d]=%x ", i, reply_buffer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) /* interrupt handler. Note that this can be called externally on the Sparc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) irqreturn_t floppy_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) int do_print;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) unsigned long f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) void (*handler)(void) = do_floppy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) lasthandler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) interruptjiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) f = claim_dma_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) fd_disable_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) release_dma_lock(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) do_floppy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) if (current_fdc >= N_FDC || fdc_state[current_fdc].address == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) /* we don't even know which FDC is the culprit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) pr_info("DOR0=%x\n", fdc_state[0].dor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) pr_info("floppy interrupt on bizarre fdc %d\n", current_fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) pr_info("handler=%ps\n", handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) is_alive(__func__, "bizarre fdc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) fdc_state[current_fdc].reset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) /* We have to clear the reset flag here, because apparently on boxes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) * with level triggered interrupts (PS/2, Sparc, ...), it is needed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) * emit SENSEI's to clear the interrupt line. And fdc_state[fdc].reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) * blocks the emission of the SENSEI's.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) * It is OK to emit floppy commands because we are in an interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) * handler here, and thus we have to fear no interference of other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) * activity.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) do_print = !handler && print_unex && initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) inr = result(current_fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) if (do_print)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) print_result("unexpected interrupt", inr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) if (inr == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) int max_sensei = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) output_byte(current_fdc, FD_SENSEI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) inr = result(current_fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) if (do_print)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) print_result("sensei", inr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) max_sensei--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) } while ((reply_buffer[ST0] & 0x83) != UNIT(current_drive) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) inr == 2 && max_sensei);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) if (!handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) schedule_bh(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) is_alive(__func__, "normal interrupt end");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) /* FIXME! Was it really for us? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) static void recalibrate_floppy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) debugt(__func__, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) do_floppy = recal_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) output_byte(current_fdc, FD_RECALIBRATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) if (output_byte(current_fdc, UNIT(current_drive)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) reset_fdc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) * Must do 4 FD_SENSEIs after reset because of ``drive polling''.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) static void reset_interrupt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) debugt(__func__, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) result(current_fdc); /* get the status ready for set_fdc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) if (fdc_state[current_fdc].reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) pr_info("reset set in interrupt, calling %ps\n", cont->error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) cont->error(); /* a reset just after a reset. BAD! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) * reset is done by pulling bit 2 of DOR low for a while (old FDCs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) * or by setting the self clearing bit 7 of STATUS (newer FDCs).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) * This WILL trigger an interrupt, causing the handlers in the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) * cont's ->redo() to be called via reset_interrupt().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) static void reset_fdc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) do_floppy = reset_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) fdc_state[current_fdc].reset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) reset_fdc_info(current_fdc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) /* Pseudo-DMA may intercept 'reset finished' interrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) /* Irrelevant for systems with true DMA (i386). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) flags = claim_dma_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) fd_disable_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) release_dma_lock(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) if (fdc_state[current_fdc].version >= FDC_82072A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) fdc_outb(0x80 | (fdc_state[current_fdc].dtr & 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) current_fdc, FD_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) fdc_outb(fdc_state[current_fdc].dor & ~0x04, current_fdc, FD_DOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) udelay(FD_RESET_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) static void show_floppy(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) pr_info("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) pr_info("floppy driver state\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) pr_info("-------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%ps\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) jiffies, interruptjiffies, jiffies - interruptjiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) lasthandler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) pr_info("timeout_message=%s\n", timeout_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) pr_info("last output bytes:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) for (i = 0; i < OLOGSIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) pr_info("%2x %2x %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) output_log[(i + output_log_pos) % OLOGSIZE].data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) output_log[(i + output_log_pos) % OLOGSIZE].status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) output_log[(i + output_log_pos) % OLOGSIZE].jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) pr_info("last result at %lu\n", resultjiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) pr_info("last redo_fd_request at %lu\n", lastredo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) reply_buffer, resultsize, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) pr_info("status=%x\n", fdc_inb(fdc, FD_STATUS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) pr_info("fdc_busy=%lu\n", fdc_busy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) if (do_floppy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) pr_info("do_floppy=%ps\n", do_floppy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) if (work_pending(&floppy_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) pr_info("floppy_work.func=%ps\n", floppy_work.func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) if (delayed_work_pending(&fd_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) pr_info("delayed work.function=%p expires=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) fd_timer.work.func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) fd_timer.timer.expires - jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) if (delayed_work_pending(&fd_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) pr_info("timer_function=%p expires=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) fd_timeout.work.func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) fd_timeout.timer.expires - jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) pr_info("cont=%p\n", cont);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) pr_info("current_req=%p\n", current_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) pr_info("command_status=%d\n", command_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) pr_info("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) static void floppy_shutdown(struct work_struct *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) if (initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) show_floppy(current_fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) cancel_activity();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) flags = claim_dma_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) fd_disable_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) release_dma_lock(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) /* avoid dma going to a random drive after shutdown */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) if (initialized)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) DPRINT("floppy timeout called\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) if (cont) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) cont->redo(); /* this will recall reset when needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) pr_info("no cont in shutdown!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) is_alive(__func__, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) /* start motor, check media-changed condition and write protection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) static int start_motor(void (*function)(void))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) int data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) mask = 0xfc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) data = UNIT(current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) if (!(raw_cmd->flags & FD_RAW_NO_MOTOR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) if (!(fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) set_debugt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) /* no read since this drive is running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) drive_state[current_drive].first_read_date = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) /* note motor start time if motor is not yet running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) drive_state[current_drive].spinup_date = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) data |= (0x10 << UNIT(current_drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) } else if (fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) mask &= ~(0x10 << UNIT(current_drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) /* starts motor and selects floppy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) del_timer(motor_off_timer + current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) set_dor(current_fdc, mask, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) /* wait_for_completion also schedules reset if needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) return fd_wait_for_completion(drive_state[current_drive].select_date + drive_params[current_drive].select_delay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) function);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) static void floppy_ready(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) if (fdc_state[current_fdc].reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) reset_fdc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) if (start_motor(floppy_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) if (fdc_dtr())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) debug_dcl(drive_params[current_drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) "calling disk change from floppy_ready\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) disk_change(current_drive) && !drive_params[current_drive].select_delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) twaddle(current_fdc, current_drive); /* this clears the dcl on certain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) * drive/controller combinations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) #ifdef fd_chose_dma_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) if ((raw_cmd->flags & FD_RAW_READ) || (raw_cmd->flags & FD_RAW_WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) unsigned long flags = claim_dma_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) fd_chose_dma_mode(raw_cmd->kernel_data, raw_cmd->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) release_dma_lock(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) if (raw_cmd->flags & (FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) perpendicular_mode(current_fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) fdc_specify(current_fdc, current_drive); /* must be done here because of hut, hlt ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) seek_floppy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) if ((raw_cmd->flags & FD_RAW_READ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) (raw_cmd->flags & FD_RAW_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) fdc_specify(current_fdc, current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) setup_rw_floppy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) static void floppy_start(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) reschedule_timeout(current_drive, "floppy start");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) scandrives();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) debug_dcl(drive_params[current_drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) "setting NEWCHANGE in floppy_start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) floppy_ready();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) * ========================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) * here ends the bottom half. Exported routines are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) * floppy_start, floppy_off, floppy_ready, lock_fdc, unlock_fdc, set_fdc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) * start_motor, reset_fdc, reset_fdc_info, interpret_errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) * Initialization also uses output_byte, result, set_dor, floppy_interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) * and set_dor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) * ========================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) * General purpose continuations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) * ==============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) static void do_wakeup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) reschedule_timeout(MAXTIMEOUT, "do wakeup");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) cont = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) command_status += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) wake_up(&command_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) static const struct cont_t wakeup_cont = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) .interrupt = empty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) .redo = do_wakeup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) .error = empty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) .done = (done_f)empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) static const struct cont_t intr_cont = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) .interrupt = empty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) .redo = process_fd_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) .error = empty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) .done = (done_f)empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) /* schedules handler, waiting for completion. May be interrupted, will then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) * return -EINTR, in which case the driver will automatically be unlocked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) static int wait_til_done(void (*handler)(void), bool interruptible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) schedule_bh(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) if (interruptible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) wait_event_interruptible(command_done, command_status >= 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) wait_event(command_done, command_status >= 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) if (command_status < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) cancel_activity();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) cont = &intr_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) reset_fdc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) if (fdc_state[current_fdc].reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) command_status = FD_COMMAND_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) if (command_status == FD_COMMAND_OKAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) command_status = FD_COMMAND_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) static void generic_done(int result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) command_status = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) cont = &wakeup_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) static void generic_success(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) cont->done(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) static void generic_failure(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) static void success_and_wakeup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) generic_success();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) * formatting and rw support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) * ==========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) static int next_valid_format(int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) int probed_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) probed_format = drive_state[drive].probed_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) if (probed_format >= FD_AUTODETECT_SIZE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) !drive_params[drive].autodetect[probed_format]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) drive_state[drive].probed_format = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (floppy_type[drive_params[drive].autodetect[probed_format]].sect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) drive_state[drive].probed_format = probed_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) probed_format++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) static void bad_flp_intr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) int err_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) if (probing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) drive_state[current_drive].probed_format++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) if (!next_valid_format(current_drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) err_count = ++(*errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) INFBOUND(write_errors[current_drive].badness, err_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) if (err_count > drive_params[current_drive].max_errors.abort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) cont->done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) if (err_count > drive_params[current_drive].max_errors.reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) else if (err_count > drive_params[current_drive].max_errors.recal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) drive_state[current_drive].track = NEED_2_RECAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) static void set_floppy(int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) int type = ITYPE(drive_state[drive].fd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) if (type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) _floppy = floppy_type + type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) _floppy = current_type[drive];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) * formatting support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) * ===================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) static void format_interrupt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) switch (interpret_errors()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) cont->error();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) cont->done(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) #define FM_MODE(x, y) ((y) & ~(((x)->rate & 0x80) >> 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) #define CT(x) ((x) | 0xc0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) static void setup_format_params(int track)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) int il;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) int head_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) int track_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) struct fparm {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) unsigned char track, head, sect, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) } *here = (struct fparm *)floppy_track_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) raw_cmd = &default_raw_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) raw_cmd->track = track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) raw_cmd->flags = (FD_RAW_WRITE | FD_RAW_INTR | FD_RAW_SPIN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) raw_cmd->rate = _floppy->rate & 0x43;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) raw_cmd->cmd_count = NR_F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_FORMAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) raw_cmd->cmd[F_SIZECODE] = FD_SIZECODE(_floppy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) raw_cmd->cmd[F_SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[F_SIZECODE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) raw_cmd->cmd[F_GAP] = _floppy->fmt_gap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) raw_cmd->cmd[F_FILL] = FD_FILL_BYTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) raw_cmd->kernel_data = floppy_track_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) raw_cmd->length = 4 * raw_cmd->cmd[F_SECT_PER_TRACK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) if (!raw_cmd->cmd[F_SECT_PER_TRACK])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) /* allow for about 30ms for data transport per track */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) head_shift = (raw_cmd->cmd[F_SECT_PER_TRACK] + 5) / 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) /* a ``cylinder'' is two tracks plus a little stepping time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) track_shift = 2 * head_shift + 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) /* position of logical sector 1 on this track */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) n = (track_shift * format_req.track + head_shift * format_req.head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) % raw_cmd->cmd[F_SECT_PER_TRACK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) /* determine interleave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) il = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) if (_floppy->fmt_gap < 0x22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) il++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) /* initialize field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) here[count].track = format_req.track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) here[count].head = format_req.head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) here[count].sect = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) here[count].size = raw_cmd->cmd[F_SIZECODE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) /* place logical sectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) for (count = 1; count <= raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) here[n].sect = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) n = (n + il) % raw_cmd->cmd[F_SECT_PER_TRACK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) if (here[n].sect) { /* sector busy, find next free sector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) ++n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) if (n >= raw_cmd->cmd[F_SECT_PER_TRACK]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) n -= raw_cmd->cmd[F_SECT_PER_TRACK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) while (here[n].sect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) ++n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) if (_floppy->stretch & FD_SECTBASEMASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) here[count].sect += FD_SECTBASE(_floppy) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) static void redo_format(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) buffer_track = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) setup_format_params(format_req.track << STRETCH(_floppy));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) floppy_start();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) debugt(__func__, "queue format request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) static const struct cont_t format_cont = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) .interrupt = format_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) .redo = redo_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) .error = bad_flp_intr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) .done = generic_done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) static int do_format(int drive, struct format_descr *tmp_format_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) set_floppy(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) if (!_floppy ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) _floppy->track > drive_params[current_drive].tracks ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) tmp_format_req->track >= _floppy->track ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) tmp_format_req->head >= _floppy->head ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) (_floppy->sect << 2) % (1 << FD_SIZECODE(_floppy)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) !_floppy->fmt_gap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) format_req = *tmp_format_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) format_errors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) cont = &format_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) errors = &format_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) ret = wait_til_done(redo_format, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) if (ret == -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) * Buffer read/write and support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) * =============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) static void floppy_end_request(struct request *req, blk_status_t error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) unsigned int nr_sectors = current_count_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) unsigned int drive = (unsigned long)req->rq_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) /* current_count_sectors can be zero if transfer failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) nr_sectors = blk_rq_cur_sectors(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) if (blk_update_request(req, error, nr_sectors << 9))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) __blk_mq_end_request(req, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) /* We're done with the request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) floppy_off(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) current_req = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) /* new request_done. Can handle physical sectors which are smaller than a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) * logical buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) static void request_done(int uptodate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) struct request *req = current_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) int block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) char msg[sizeof("request done ") + sizeof(int) * 3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) probing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) snprintf(msg, sizeof(msg), "request done %d", uptodate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) reschedule_timeout(MAXTIMEOUT, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) pr_info("floppy.c: no request in request_done\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) if (uptodate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) /* maintain values for invalidation on geometry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) * change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) block = current_count_sectors + blk_rq_pos(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) INFBOUND(drive_state[current_drive].maxblock, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) if (block > _floppy->sect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) drive_state[current_drive].maxtrack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) floppy_end_request(req, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) if (rq_data_dir(req) == WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) /* record write error information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) write_errors[current_drive].write_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) if (write_errors[current_drive].write_errors == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) write_errors[current_drive].first_error_sector = blk_rq_pos(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) write_errors[current_drive].first_error_generation = drive_state[current_drive].generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) write_errors[current_drive].last_error_sector = blk_rq_pos(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) write_errors[current_drive].last_error_generation = drive_state[current_drive].generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) floppy_end_request(req, BLK_STS_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) /* Interrupt handler evaluating the result of the r/w operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) static void rw_interrupt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) int eoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) int ssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) int heads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) int nr_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) if (reply_buffer[R_HEAD] >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) /* some Toshiba floppy controllers occasionnally seem to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) * return bogus interrupts after read/write operations, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) * can be recognized by a bad head number (>= 2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) if (!drive_state[current_drive].first_read_date)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) drive_state[current_drive].first_read_date = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) nr_sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) if (reply_buffer[ST1] & ST1_EOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) eoc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) eoc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) if (raw_cmd->cmd[COMMAND] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) heads = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) heads = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) nr_sectors = (((reply_buffer[R_TRACK] - raw_cmd->cmd[TRACK]) * heads +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) reply_buffer[R_HEAD] - raw_cmd->cmd[HEAD]) * raw_cmd->cmd[SECT_PER_TRACK] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) reply_buffer[R_SECTOR] - raw_cmd->cmd[SECTOR] + eoc) << raw_cmd->cmd[SIZECODE] >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) if (nr_sectors / ssize >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) DPRINT("long rw: %x instead of %lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) nr_sectors, current_count_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) pr_info("rs=%d s=%d\n", reply_buffer[R_SECTOR],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) raw_cmd->cmd[SECTOR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) pr_info("rh=%d h=%d\n", reply_buffer[R_HEAD],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) raw_cmd->cmd[HEAD]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) pr_info("rt=%d t=%d\n", reply_buffer[R_TRACK],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) raw_cmd->cmd[TRACK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) pr_info("heads=%d eoc=%d\n", heads, eoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) pr_info("spt=%d st=%d ss=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) raw_cmd->cmd[SECT_PER_TRACK], fsector_t, ssize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) pr_info("in_sector_offset=%d\n", in_sector_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) nr_sectors -= in_sector_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) INFBOUND(nr_sectors, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) SUPBOUND(current_count_sectors, nr_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) switch (interpret_errors()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) if (!current_count_sectors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) cont->error();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) if (!current_count_sectors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) current_type[current_drive] = _floppy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) floppy_sizes[TOMINOR(current_drive)] = _floppy->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) if (probing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) if (drive_params[current_drive].flags & FTD_MSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) DPRINT("Auto-detected floppy type %s in fd%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) _floppy->name, current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) current_type[current_drive] = _floppy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) floppy_sizes[TOMINOR(current_drive)] = _floppy->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) probing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) if (CT(raw_cmd->cmd[COMMAND]) != FD_READ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) raw_cmd->kernel_data == bio_data(current_req->bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) /* transfer directly from buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) cont->done(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) } else if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) buffer_track = raw_cmd->track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) buffer_drive = current_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) INFBOUND(buffer_max, nr_sectors + fsector_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) cont->redo();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) /* Compute maximal contiguous buffer size. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) static int buffer_chain_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) struct bio_vec bv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) struct req_iterator iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) char *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) base = bio_data(current_req->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) rq_for_each_segment(bv, current_req, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) if (page_address(bv.bv_page) + bv.bv_offset != base + size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) size += bv.bv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) return size >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) /* Compute the maximal transfer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) static int transfer_size(int ssize, int max_sector, int max_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) SUPBOUND(max_sector, fsector_t + max_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) /* alignment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) max_sector -= (max_sector % _floppy->sect) % ssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) /* transfer size, beginning not aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) current_count_sectors = max_sector - fsector_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) return max_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) * Move data from/to the track buffer to/from the buffer cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) static void copy_buffer(int ssize, int max_sector, int max_sector_2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) int remaining; /* number of transferred 512-byte sectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) struct bio_vec bv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) char *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) char *dma_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) struct req_iterator iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) max_sector = transfer_size(ssize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) min(max_sector, max_sector_2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) blk_rq_sectors(current_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) if (current_count_sectors <= 0 && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) buffer_max > fsector_t + blk_rq_sectors(current_req))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) current_count_sectors = min_t(int, buffer_max - fsector_t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) blk_rq_sectors(current_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) remaining = current_count_sectors << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) if (remaining > blk_rq_bytes(current_req) && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) DPRINT("in copy buffer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) pr_info("current_count_sectors=%ld\n", current_count_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) pr_info("remaining=%d\n", remaining >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) pr_info("current_req->nr_sectors=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) blk_rq_sectors(current_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) pr_info("current_req->current_nr_sectors=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) blk_rq_cur_sectors(current_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) pr_info("max_sector=%d\n", max_sector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) pr_info("ssize=%d\n", ssize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) buffer_max = max(max_sector, buffer_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) size = blk_rq_cur_bytes(current_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) rq_for_each_segment(bv, current_req, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) if (!remaining)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) size = bv.bv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) SUPBOUND(size, remaining);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) buffer = page_address(bv.bv_page) + bv.bv_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) if (dma_buffer + size >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) floppy_track_buffer + (max_buffer_sectors << 10) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) dma_buffer < floppy_track_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) DPRINT("buffer overrun in copy buffer %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) (int)((floppy_track_buffer - dma_buffer) >> 9));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) pr_info("fsector_t=%d buffer_min=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) fsector_t, buffer_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) pr_info("current_count_sectors=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) current_count_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) pr_info("read\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) pr_info("write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) if (((unsigned long)buffer) % 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) DPRINT("%p buffer not aligned\n", buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) memcpy(buffer, dma_buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) memcpy(dma_buffer, buffer, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) remaining -= size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) dma_buffer += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) if (remaining) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) if (remaining > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) max_sector -= remaining >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) DPRINT("weirdness: remaining %d\n", remaining >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) /* work around a bug in pseudo DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) * (on some FDCs) pseudo DMA does not stop when the CPU stops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) * sending data. Hence we need a different way to signal the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) * transfer length: We use raw_cmd->cmd[SECT_PER_TRACK]. Unfortunately, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) * does not work with MT, hence we can only transfer one head at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) * a time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) static void virtualdmabug_workaround(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) int hard_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) int end_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) raw_cmd->cmd[COMMAND] &= ~0x80; /* switch off multiple track mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) hard_sectors = raw_cmd->length >> (7 + raw_cmd->cmd[SIZECODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) end_sector = raw_cmd->cmd[SECTOR] + hard_sectors - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) if (end_sector > raw_cmd->cmd[SECT_PER_TRACK]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) pr_info("too many sectors %d > %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) end_sector, raw_cmd->cmd[SECT_PER_TRACK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) raw_cmd->cmd[SECT_PER_TRACK] = end_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) /* make sure raw_cmd->cmd[SECT_PER_TRACK]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) * points to end of transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) * Formulate a read/write request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) * this routine decides where to load the data (directly to buffer, or to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) * tmp floppy area), how much data to load (the size of the buffer, the whole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) * track, or a single sector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) * All floppy_track_buffer handling goes in here. If we ever add track buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) * allocation on the fly, it should be done here. No other part should need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) * modification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) static int make_raw_rw_request(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) int aligned_sector_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) int max_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) int max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) int tracksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) int ssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) if (WARN(max_buffer_sectors == 0, "VFS: Block I/O scheduled on unopened device\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) set_fdc((long)current_req->rq_disk->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) raw_cmd = &default_raw_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) raw_cmd->flags = FD_RAW_SPIN | FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) raw_cmd->cmd_count = NR_RW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) if (rq_data_dir(current_req) == READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) raw_cmd->flags |= FD_RAW_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) } else if (rq_data_dir(current_req) == WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) raw_cmd->flags |= FD_RAW_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) DPRINT("%s: unknown command\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) max_sector = _floppy->sect * _floppy->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) raw_cmd->cmd[TRACK] = (int)blk_rq_pos(current_req) / max_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) fsector_t = (int)blk_rq_pos(current_req) % max_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) if (_floppy->track && raw_cmd->cmd[TRACK] >= _floppy->track) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) if (blk_rq_cur_sectors(current_req) & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) current_count_sectors = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) raw_cmd->cmd[HEAD] = fsector_t / _floppy->sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) fsector_t < _floppy->sect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) max_sector = _floppy->sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) /* 2M disks have phantom sectors on the first track */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) if ((_floppy->rate & FD_2M) && (!raw_cmd->cmd[TRACK]) && (!raw_cmd->cmd[HEAD])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) max_sector = 2 * _floppy->sect / 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) if (fsector_t >= max_sector) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) current_count_sectors =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) min_t(int, _floppy->sect - fsector_t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) blk_rq_sectors(current_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) raw_cmd->cmd[SIZECODE] = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) raw_cmd->cmd[SIZECODE] = FD_SIZECODE(_floppy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) raw_cmd->rate = _floppy->rate & 0x43;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) if ((_floppy->rate & FD_2M) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) (raw_cmd->cmd[TRACK] || raw_cmd->cmd[HEAD]) && raw_cmd->rate == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) raw_cmd->rate = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) if (raw_cmd->cmd[SIZECODE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) raw_cmd->cmd[SIZECODE2] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) raw_cmd->cmd[SIZECODE2] = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) raw_cmd->track = raw_cmd->cmd[TRACK] << STRETCH(_floppy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, raw_cmd->cmd[HEAD]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) raw_cmd->cmd[GAP] = _floppy->gap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) raw_cmd->cmd[SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[SIZECODE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) raw_cmd->cmd[SECTOR] = ((fsector_t % _floppy->sect) << 2 >> raw_cmd->cmd[SIZECODE]) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) FD_SECTBASE(_floppy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) /* tracksize describes the size which can be filled up with sectors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) * of size ssize.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) tracksize = _floppy->sect - _floppy->sect % ssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) if (tracksize < _floppy->sect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) raw_cmd->cmd[SECT_PER_TRACK]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) if (tracksize <= fsector_t % _floppy->sect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) raw_cmd->cmd[SECTOR]--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) /* if we are beyond tracksize, fill up using smaller sectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) while (tracksize <= fsector_t % _floppy->sect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) while (tracksize + ssize > _floppy->sect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) raw_cmd->cmd[SIZECODE]--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) ssize >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) raw_cmd->cmd[SECTOR]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) raw_cmd->cmd[SECT_PER_TRACK]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) tracksize += ssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) max_sector = raw_cmd->cmd[HEAD] * _floppy->sect + tracksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) } else if (!raw_cmd->cmd[TRACK] && !raw_cmd->cmd[HEAD] && !(_floppy->rate & FD_2M) && probing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) max_sector = _floppy->sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) } else if (!raw_cmd->cmd[HEAD] && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) /* for virtual DMA bug workaround */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) max_sector = _floppy->sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) in_sector_offset = (fsector_t % _floppy->sect) % ssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) aligned_sector_t = fsector_t - in_sector_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) max_size = blk_rq_sectors(current_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) if ((raw_cmd->track == buffer_track) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) (current_drive == buffer_drive) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) (fsector_t >= buffer_min) && (fsector_t < buffer_max)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) /* data already in track buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) copy_buffer(1, max_sector, buffer_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) unsigned int sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) sectors = fsector_t + blk_rq_sectors(current_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) if (sectors > ssize && sectors < ssize + ssize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) max_size = ssize + ssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) max_size = ssize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) raw_cmd->flags &= ~FD_RAW_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) raw_cmd->flags |= FD_RAW_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) } else if ((unsigned long)bio_data(current_req->bio) < MAX_DMA_ADDRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) unsigned long dma_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) int direct, indirect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) indirect =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) transfer_size(ssize, max_sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) max_buffer_sectors * 2) - fsector_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) * Do NOT use minimum() here---MAX_DMA_ADDRESS is 64 bits wide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) * on a 64 bit machine!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) max_size = buffer_chain_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) dma_limit = (MAX_DMA_ADDRESS -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) ((unsigned long)bio_data(current_req->bio))) >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) if ((unsigned long)max_size > dma_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) max_size = dma_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) /* 64 kb boundaries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) if (CROSS_64KB(bio_data(current_req->bio), max_size << 9))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) max_size = (K_64 -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) ((unsigned long)bio_data(current_req->bio)) %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) K_64) >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) direct = transfer_size(ssize, max_sector, max_size) - fsector_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) * We try to read tracks, but if we get too many errors, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) * go back to reading just one sector at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) * This means we should be able to read a sector even if there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) * are other bad sectors on this track.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) if (!direct ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) (indirect * 2 > direct * 3 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) *errors < drive_params[current_drive].max_errors.read_track &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) ((!probing ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) (drive_params[current_drive].read_track & (1 << drive_state[current_drive].probed_format)))))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) max_size = blk_rq_sectors(current_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) raw_cmd->kernel_data = bio_data(current_req->bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) raw_cmd->length = current_count_sectors << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) if (raw_cmd->length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) DPRINT("%s: zero dma transfer attempted\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) DPRINT("indirect=%d direct=%d fsector_t=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) indirect, direct, fsector_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) virtualdmabug_workaround();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) max_size = max_sector; /* unbounded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) /* claim buffer track if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) if (buffer_track != raw_cmd->track || /* bad track */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) buffer_drive != current_drive || /* bad drive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) fsector_t > buffer_max ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) fsector_t < buffer_min ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) ((CT(raw_cmd->cmd[COMMAND]) == FD_READ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) max_sector > 2 * max_buffer_sectors + buffer_min &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) /* not enough space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) buffer_track = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) buffer_drive = current_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) buffer_max = buffer_min = aligned_sector_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) raw_cmd->kernel_data = floppy_track_buffer +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) ((aligned_sector_t - buffer_min) << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) /* copy write buffer to track buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) * if we get here, we know that the write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) * is either aligned or the data already in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) * (buffer will be overwritten) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) if (in_sector_offset && buffer_track == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) DPRINT("internal error offset !=0 on write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) buffer_track = raw_cmd->track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) buffer_drive = current_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) copy_buffer(ssize, max_sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 2 * max_buffer_sectors + buffer_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) transfer_size(ssize, max_sector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 2 * max_buffer_sectors + buffer_min -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) aligned_sector_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) /* round up current_count_sectors to get dma xfer size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) raw_cmd->length = in_sector_offset + current_count_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) raw_cmd->length = ((raw_cmd->length - 1) | (ssize - 1)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) raw_cmd->length <<= 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) if ((raw_cmd->length < current_count_sectors << 9) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) (raw_cmd->kernel_data != bio_data(current_req->bio) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) CT(raw_cmd->cmd[COMMAND]) == FD_WRITE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) (aligned_sector_t + (raw_cmd->length >> 9) > buffer_max ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) aligned_sector_t < buffer_min)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) raw_cmd->length % (128 << raw_cmd->cmd[SIZECODE]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) raw_cmd->length <= 0 || current_count_sectors <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) DPRINT("fractionary current count b=%lx s=%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) raw_cmd->length, current_count_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) if (raw_cmd->kernel_data != bio_data(current_req->bio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) pr_info("addr=%d, length=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) (int)((raw_cmd->kernel_data -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) floppy_track_buffer) >> 9),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) current_count_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) pr_info("st=%d ast=%d mse=%d msi=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) fsector_t, aligned_sector_t, max_sector, max_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) pr_info("ssize=%x SIZECODE=%d\n", ssize, raw_cmd->cmd[SIZECODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) pr_info("command=%x SECTOR=%d HEAD=%d, TRACK=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) raw_cmd->cmd[COMMAND], raw_cmd->cmd[SECTOR],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) raw_cmd->cmd[HEAD], raw_cmd->cmd[TRACK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) pr_info("buffer drive=%d\n", buffer_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) pr_info("buffer track=%d\n", buffer_track);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) pr_info("buffer_min=%d\n", buffer_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) pr_info("buffer_max=%d\n", buffer_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) if (raw_cmd->kernel_data != bio_data(current_req->bio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) if (raw_cmd->kernel_data < floppy_track_buffer ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) current_count_sectors < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) raw_cmd->length < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) raw_cmd->kernel_data + raw_cmd->length >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) floppy_track_buffer + (max_buffer_sectors << 10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) DPRINT("buffer overrun in schedule dma\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) pr_info("fsector_t=%d buffer_min=%d current_count=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) fsector_t, buffer_min, raw_cmd->length >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) pr_info("current_count_sectors=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) current_count_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) pr_info("read\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) pr_info("write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) } else if (raw_cmd->length > blk_rq_bytes(current_req) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) current_count_sectors > blk_rq_sectors(current_req)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) DPRINT("buffer overrun in direct transfer\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) } else if (raw_cmd->length < current_count_sectors << 9) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) DPRINT("more sectors than bytes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) pr_info("bytes=%ld\n", raw_cmd->length >> 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) pr_info("sectors=%ld\n", current_count_sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) if (raw_cmd->length == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) DPRINT("zero dma transfer attempted from make_raw_request\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) virtualdmabug_workaround();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) static int set_next_request(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) current_req = list_first_entry_or_null(&floppy_reqs, struct request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) if (current_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) current_req->error_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) list_del_init(¤t_req->queuelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) return current_req != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) /* Starts or continues processing request. Will automatically unlock the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) * driver at end of request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) static void redo_fd_request(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) lastredo = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) if (current_drive < N_DRIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) floppy_off(current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) do_request:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) if (!current_req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) int pending;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) spin_lock_irq(&floppy_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) pending = set_next_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) spin_unlock_irq(&floppy_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) if (!pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) do_floppy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) unlock_fdc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) drive = (long)current_req->rq_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) set_fdc(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) reschedule_timeout(current_drive, "redo fd request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) set_floppy(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) raw_cmd = &default_raw_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) raw_cmd->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) if (start_motor(redo_fd_request))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) disk_change(current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) if (test_bit(current_drive, &fake_change) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) test_bit(FD_DISK_CHANGED_BIT, &drive_state[current_drive].flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) DPRINT("disk absent or changed during operation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) request_done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) goto do_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) if (!_floppy) { /* Autodetection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) if (!probing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) drive_state[current_drive].probed_format = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) if (next_valid_format(current_drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) DPRINT("no autodetectable formats\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) _floppy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) request_done(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) goto do_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) probing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) _floppy = floppy_type + drive_params[current_drive].autodetect[drive_state[current_drive].probed_format];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) probing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) errors = &(current_req->error_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) tmp = make_raw_rw_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) if (tmp < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) request_done(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) goto do_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) if (test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) twaddle(current_fdc, current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) schedule_bh(floppy_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) debugt(__func__, "queue fd request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) static const struct cont_t rw_cont = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) .interrupt = rw_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) .redo = redo_fd_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) .error = bad_flp_intr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) .done = request_done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) /* schedule the request and automatically unlock the driver on completion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) static void process_fd_request(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) cont = &rw_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) schedule_bh(redo_fd_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) const struct blk_mq_queue_data *bd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) blk_mq_start_request(bd->rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) if (WARN(max_buffer_sectors == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) "VFS: %s called on non-open device\n", __func__))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) return BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) if (WARN(atomic_read(&usage_count) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) "warning: usage count=0, current_req=%p sect=%ld flags=%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) current_req, (long)blk_rq_pos(current_req),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) (unsigned long long) current_req->cmd_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) return BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) if (test_and_set_bit(0, &fdc_busy)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) /* fdc busy, this new request will be treated when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) current one is done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) is_alive(__func__, "old request running");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) return BLK_STS_RESOURCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) spin_lock_irq(&floppy_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) list_add_tail(&bd->rq->queuelist, &floppy_reqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) spin_unlock_irq(&floppy_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) command_status = FD_COMMAND_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) __reschedule_timeout(MAXTIMEOUT, "fd_request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) set_fdc(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) is_alive(__func__, "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) return BLK_STS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) static const struct cont_t poll_cont = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) .interrupt = success_and_wakeup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) .redo = floppy_ready,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) .error = generic_failure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) .done = generic_done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) static int poll_drive(bool interruptible, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) /* no auto-sense, just clear dcl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) raw_cmd = &default_raw_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) raw_cmd->flags = flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) raw_cmd->track = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) raw_cmd->cmd_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) cont = &poll_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) debug_dcl(drive_params[current_drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) "setting NEWCHANGE in poll_drive\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) return wait_til_done(floppy_ready, interruptible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) * User triggered reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) * ====================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) static void reset_intr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) pr_info("weird, reset interrupt called\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) static const struct cont_t reset_cont = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) .interrupt = reset_intr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) .redo = success_and_wakeup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) .error = generic_failure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) .done = generic_done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) * Resets the FDC connected to drive <drive>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) * Both current_drive and current_fdc are changed to match the new drive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) static int user_reset_fdc(int drive, int arg, bool interruptible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) if (arg == FD_RESET_ALWAYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) fdc_state[current_fdc].reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) if (fdc_state[current_fdc].reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) /* note: reset_fdc will take care of unlocking the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) * on completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) cont = &reset_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) ret = wait_til_done(reset_fdc, interruptible);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) if (ret == -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) * Misc Ioctl's and support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) * ========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) static inline int fd_copyout(void __user *param, const void *address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) return copy_to_user(param, address, size) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) static inline int fd_copyin(void __user *param, void *address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) return copy_from_user(address, param, size) ? -EFAULT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) static const char *drive_name(int type, int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) struct floppy_struct *floppy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) if (type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) floppy = floppy_type + type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) if (drive_params[drive].native_format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) floppy = floppy_type + drive_params[drive].native_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) return "(null)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) if (floppy->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) return floppy->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) return "(null)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) /* raw commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) static void raw_cmd_done(int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) if (!flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) raw_cmd->flags |= FD_RAW_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) raw_cmd->flags |= FD_RAW_HARDFAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) raw_cmd->reply_count = inr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) if (raw_cmd->reply_count > FD_RAW_REPLY_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) raw_cmd->reply_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) for (i = 0; i < raw_cmd->reply_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) raw_cmd->reply[i] = reply_buffer[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) if (raw_cmd->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) flags = claim_dma_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) raw_cmd->length = fd_get_dma_residue();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) release_dma_lock(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) if ((raw_cmd->flags & FD_RAW_SOFTFAILURE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) (!raw_cmd->reply_count || (raw_cmd->reply[0] & 0xc0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) raw_cmd->flags |= FD_RAW_FAILURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) if (disk_change(current_drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) raw_cmd->flags |= FD_RAW_DISK_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) raw_cmd->flags &= ~FD_RAW_DISK_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) if (raw_cmd->flags & FD_RAW_NO_MOTOR_AFTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) motor_off_callback(&motor_off_timer[current_drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) if (raw_cmd->next &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) (!(raw_cmd->flags & FD_RAW_FAILURE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) !(raw_cmd->flags & FD_RAW_STOP_IF_FAILURE)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) ((raw_cmd->flags & FD_RAW_FAILURE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) !(raw_cmd->flags & FD_RAW_STOP_IF_SUCCESS))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) raw_cmd = raw_cmd->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) generic_done(flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) static const struct cont_t raw_cmd_cont = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) .interrupt = success_and_wakeup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) .redo = floppy_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) .error = generic_failure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) .done = raw_cmd_done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) static int raw_cmd_copyout(int cmd, void __user *param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) struct floppy_raw_cmd *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) while (ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) struct floppy_raw_cmd cmd = *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) cmd.next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) cmd.kernel_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) ret = copy_to_user(param, &cmd, sizeof(cmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) param += sizeof(struct floppy_raw_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) if ((ptr->flags & FD_RAW_READ) && ptr->buffer_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) if (ptr->length >= 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) ptr->length <= ptr->buffer_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) long length = ptr->buffer_length - ptr->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) ret = fd_copyout(ptr->data, ptr->kernel_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) ptr = ptr->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) static void raw_cmd_free(struct floppy_raw_cmd **ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) struct floppy_raw_cmd *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) struct floppy_raw_cmd *this;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) this = *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) *ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) while (this) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) if (this->buffer_length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) fd_dma_mem_free((unsigned long)this->kernel_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) this->buffer_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) this->buffer_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) next = this->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) kfree(this);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) this = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) #define MAX_LEN (1UL << MAX_ORDER << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) static int raw_cmd_copyin(int cmd, void __user *param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) struct floppy_raw_cmd **rcmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) struct floppy_raw_cmd *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) *rcmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) loop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) ptr = kmalloc(sizeof(struct floppy_raw_cmd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) if (!ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) *rcmd = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) ret = copy_from_user(ptr, param, sizeof(*ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) ptr->next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) ptr->buffer_length = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) ptr->kernel_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) param += sizeof(struct floppy_raw_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) if (ptr->cmd_count > FD_RAW_CMD_FULLSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) for (i = 0; i < FD_RAW_REPLY_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) ptr->reply[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) ptr->resultcode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) if (ptr->length <= 0 || ptr->length >= MAX_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) if (!ptr->kernel_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) ptr->buffer_length = ptr->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) if (ptr->flags & FD_RAW_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) ret = fd_copyin(ptr->data, ptr->kernel_data, ptr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) if (ptr->flags & FD_RAW_MORE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) rcmd = &(ptr->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) ptr->rate &= 0x43;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) goto loop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) static int raw_cmd_ioctl(int cmd, void __user *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) struct floppy_raw_cmd *my_raw_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) int ret2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) if (fdc_state[current_fdc].rawcmd <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) fdc_state[current_fdc].rawcmd = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) for (drive = 0; drive < N_DRIVE; drive++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) if (FDC(drive) != current_fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) if (drive == current_drive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) if (drive_state[drive].fd_ref > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) fdc_state[current_fdc].rawcmd = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) } else if (drive_state[drive].fd_ref) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) fdc_state[current_fdc].rawcmd = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) if (fdc_state[current_fdc].reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) ret = raw_cmd_copyin(cmd, param, &my_raw_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) raw_cmd_free(&my_raw_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) raw_cmd = my_raw_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) cont = &raw_cmd_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) ret = wait_til_done(floppy_start, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) debug_dcl(drive_params[current_drive].flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) "calling disk change from raw_cmd ioctl\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) if (ret != -EINTR && fdc_state[current_fdc].reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) drive_state[current_drive].track = NO_TRACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) ret2 = raw_cmd_copyout(cmd, param, my_raw_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) ret = ret2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) raw_cmd_free(&my_raw_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) static int invalidate_drive(struct block_device *bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) /* invalidate the buffer track to force a reread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) set_bit((long)bdev->bd_disk->private_data, &fake_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) if (bdev_check_media_change(bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) floppy_revalidate(bdev->bd_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) static int set_geometry(unsigned int cmd, struct floppy_struct *g,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) int drive, int type, struct block_device *bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) /* sanity checking for parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) if ((int)g->sect <= 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) (int)g->head <= 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) /* check for overflow in max_sector */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) (int)(g->sect * g->head) <= 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) /* check for zero in raw_cmd->cmd[F_SECT_PER_TRACK] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) g->track <= 0 || g->track > drive_params[drive].tracks >> STRETCH(g) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) /* check if reserved bits are set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) if (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) mutex_lock(&open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) if (lock_fdc(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) mutex_unlock(&open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) floppy_type[type] = *g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) floppy_type[type].name = "user format";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) for (cnt = type << 2; cnt < (type << 2) + 4; cnt++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) floppy_sizes[cnt] = floppy_sizes[cnt + 0x80] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) floppy_type[type].size + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) for (cnt = 0; cnt < N_DRIVE; cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) struct block_device *bdev = opened_bdev[cnt];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) if (!bdev || ITYPE(drive_state[cnt].fd_device) != type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) __invalidate_device(bdev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) mutex_unlock(&open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) int oldStretch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) if (cmd != FDDEFPRM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) /* notice a disk change immediately, else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) * we lose our settings immediately*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) oldStretch = g->stretch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) user_params[drive] = *g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) if (buffer_drive == drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) SUPBOUND(buffer_max, user_params[drive].sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) current_type[drive] = &user_params[drive];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) floppy_sizes[drive] = user_params[drive].size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) if (cmd == FDDEFPRM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) drive_state[current_drive].keep_data = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) drive_state[current_drive].keep_data = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) /* invalidation. Invalidate only when needed, i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) * when there are already sectors in the buffer cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) * whose number will change. This is useful, because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) * mtools often changes the geometry of the disk after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) * looking at the boot block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) if (drive_state[current_drive].maxblock > user_params[drive].sect ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) drive_state[current_drive].maxtrack ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) ((user_params[drive].sect ^ oldStretch) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) (FD_SWAPSIDES | FD_SECTBASEMASK)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) invalidate_drive(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) /* handle obsolete ioctl's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) static unsigned int ioctl_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) FDCLRPRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) FDSETPRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) FDDEFPRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) FDGETPRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) FDMSGON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) FDMSGOFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) FDFMTBEG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) FDFMTTRK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) FDFMTEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) FDSETEMSGTRESH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) FDFLUSH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) FDSETMAXERRS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) FDGETMAXERRS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) FDGETDRVTYP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) FDSETDRVPRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) FDGETDRVPRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) FDGETDRVSTAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) FDPOLLDRVSTAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) FDRESET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) FDGETFDCSTAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) FDWERRORCLR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) FDWERRORGET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) FDRAWCMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) FDEJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) FDTWADDLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) static int normalize_ioctl(unsigned int *cmd, int *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) for (i = 0; i < ARRAY_SIZE(ioctl_table); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) if ((*cmd & 0xffff) == (ioctl_table[i] & 0xffff)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) *size = _IOC_SIZE(*cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) *cmd = ioctl_table[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) if (*size > _IOC_SIZE(*cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) pr_info("ioctl not yet supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) static int get_floppy_geometry(int drive, int type, struct floppy_struct **g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) if (type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) *g = &floppy_type[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) if (poll_drive(false, 0) == -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) *g = current_type[drive];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) if (!*g)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) int drive = (long)bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) int type = ITYPE(drive_state[drive].fd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) struct floppy_struct *g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) ret = get_floppy_geometry(drive, type, &g);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) geo->heads = g->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) geo->sectors = g->sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) geo->cylinders = g->track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) static bool valid_floppy_drive_params(const short autodetect[FD_AUTODETECT_SIZE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) int native_format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) size_t floppy_type_size = ARRAY_SIZE(floppy_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) size_t i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) for (i = 0; i < FD_AUTODETECT_SIZE; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) if (autodetect[i] < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) autodetect[i] >= floppy_type_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) if (native_format < 0 || native_format >= floppy_type_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) unsigned long param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) int drive = (long)bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) int type = ITYPE(drive_state[drive].fd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) union inparam {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) struct floppy_struct g; /* geometry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) struct format_descr f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) struct floppy_max_errors max_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) struct floppy_drive_params dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) } inparam; /* parameters coming from user space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) const void *outparam; /* parameters passed back to user space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) /* convert compatibility eject ioctls into floppy eject ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) * We do this in order to provide a means to eject floppy disks before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) * installing the new fdutils package */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) if (cmd == CDROMEJECT || /* CD-ROM eject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) cmd == 0x6470) { /* SunOS floppy eject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) DPRINT("obsolete eject ioctl\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) DPRINT("please use floppycontrol --eject\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) cmd = FDEJECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) if (!((cmd & 0xff00) == 0x0200))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) /* convert the old style command into a new style command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) ret = normalize_ioctl(&cmd, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) /* permission checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) if (((cmd & 0x40) && !(mode & (FMODE_WRITE | FMODE_WRITE_IOCTL))) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) ((cmd & 0x80) && !capable(CAP_SYS_ADMIN)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) if (WARN_ON(size < 0 || size > sizeof(inparam)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) /* copyin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) memset(&inparam, 0, sizeof(inparam));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) if (_IOC_DIR(cmd) & _IOC_WRITE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) ret = fd_copyin((void __user *)param, &inparam, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) case FDEJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) if (drive_state[drive].fd_ref != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) /* somebody else has this drive open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) /* do the actual eject. Fails on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) * non-Sparc architectures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) ret = fd_eject(UNIT(drive));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) case FDCLRPRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) current_type[drive] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) floppy_sizes[drive] = MAX_DISK_SIZE << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) drive_state[drive].keep_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) return invalidate_drive(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) case FDSETPRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) case FDDEFPRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) return set_geometry(cmd, &inparam.g, drive, type, bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) case FDGETPRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) ret = get_floppy_geometry(drive, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) (struct floppy_struct **)&outparam);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) memcpy(&inparam.g, outparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) offsetof(struct floppy_struct, name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) outparam = &inparam.g;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) case FDMSGON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) drive_params[drive].flags |= FTD_MSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) case FDMSGOFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) drive_params[drive].flags &= ~FTD_MSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) case FDFMTBEG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) ret = drive_state[drive].flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) if (ret & FD_VERIFY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) if (!(ret & FD_DISK_WRITABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) case FDFMTTRK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) if (drive_state[drive].fd_ref != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) return do_format(drive, &inparam.f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) case FDFMTEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) case FDFLUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) return invalidate_drive(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) case FDSETEMSGTRESH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) case FDGETMAXERRS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) outparam = &drive_params[drive].max_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) case FDSETMAXERRS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) drive_params[drive].max_errors = inparam.max_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) case FDGETDRVTYP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) outparam = drive_name(type, drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) SUPBOUND(size, strlen((const char *)outparam) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) case FDSETDRVPRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) if (!valid_floppy_drive_params(inparam.dp.autodetect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) inparam.dp.native_format))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) drive_params[drive] = inparam.dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) case FDGETDRVPRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) outparam = &drive_params[drive];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) case FDPOLLDRVSTAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) case FDGETDRVSTAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) outparam = &drive_state[drive];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) case FDRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) return user_reset_fdc(drive, (int)param, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) case FDGETFDCSTAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) outparam = &fdc_state[FDC(drive)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) case FDWERRORCLR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) case FDWERRORGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) outparam = &write_errors[drive];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) case FDRAWCMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) if (type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) set_floppy(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) i = raw_cmd_ioctl(cmd, (void __user *)param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) if (i == -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) case FDTWADDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) twaddle(current_fdc, current_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) if (_IOC_DIR(cmd) & _IOC_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) return fd_copyout((void __user *)param, outparam, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) static int fd_ioctl(struct block_device *bdev, fmode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) unsigned int cmd, unsigned long param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) ret = fd_locked_ioctl(bdev, mode, cmd, param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) struct compat_floppy_drive_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) char cmos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) compat_ulong_t max_dtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) compat_ulong_t hlt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) compat_ulong_t hut;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) compat_ulong_t srt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) compat_ulong_t spinup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) compat_ulong_t spindown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) unsigned char spindown_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) unsigned char select_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) unsigned char rps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) unsigned char tracks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) compat_ulong_t timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) unsigned char interleave_sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) struct floppy_max_errors max_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) char flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) char read_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) short autodetect[FD_AUTODETECT_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) compat_int_t checkfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) compat_int_t native_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) struct compat_floppy_drive_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) signed char flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) compat_ulong_t spinup_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) compat_ulong_t select_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) compat_ulong_t first_read_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) short probed_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) short track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) short maxblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) short maxtrack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) compat_int_t generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) compat_int_t keep_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) compat_int_t fd_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) compat_int_t fd_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) compat_int_t last_checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) compat_caddr_t dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) compat_int_t bufblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) struct compat_floppy_fdc_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) compat_int_t spec1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) compat_int_t spec2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) compat_int_t dtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) unsigned char version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) unsigned char dor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) compat_ulong_t address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) unsigned int rawcmd:2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) unsigned int reset:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) unsigned int need_configure:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) unsigned int perp_mode:2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) unsigned int has_fifo:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) unsigned int driver_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) unsigned char track[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) struct compat_floppy_write_errors {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) unsigned int write_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) compat_ulong_t first_error_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) compat_int_t first_error_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) compat_ulong_t last_error_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) compat_int_t last_error_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) compat_uint_t badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) #define FDSETPRM32 _IOW(2, 0x42, struct compat_floppy_struct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) #define FDDEFPRM32 _IOW(2, 0x43, struct compat_floppy_struct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) #define FDSETDRVPRM32 _IOW(2, 0x90, struct compat_floppy_drive_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) #define FDGETDRVPRM32 _IOR(2, 0x11, struct compat_floppy_drive_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) #define FDGETDRVSTAT32 _IOR(2, 0x12, struct compat_floppy_drive_struct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) #define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct compat_floppy_drive_struct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) #define FDGETFDCSTAT32 _IOR(2, 0x15, struct compat_floppy_fdc_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) #define FDWERRORGET32 _IOR(2, 0x17, struct compat_floppy_write_errors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) static int compat_set_geometry(struct block_device *bdev, fmode_t mode, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) struct compat_floppy_struct __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) struct floppy_struct v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) int drive, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) BUILD_BUG_ON(offsetof(struct floppy_struct, name) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) offsetof(struct compat_floppy_struct, name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) if (!(mode & (FMODE_WRITE | FMODE_WRITE_IOCTL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) memset(&v, 0, sizeof(struct floppy_struct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) if (copy_from_user(&v, arg, offsetof(struct floppy_struct, name)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) drive = (long)bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) type = ITYPE(drive_state[drive].fd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) err = set_geometry(cmd == FDSETPRM32 ? FDSETPRM : FDDEFPRM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) &v, drive, type, bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) static int compat_get_prm(int drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) struct compat_floppy_struct __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) struct compat_floppy_struct v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) struct floppy_struct *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) memset(&v, 0, sizeof(v));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) err = get_floppy_geometry(drive, ITYPE(drive_state[drive].fd_device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) memcpy(&v, p, offsetof(struct floppy_struct, name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) if (copy_to_user(arg, &v, sizeof(struct compat_floppy_struct)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) static int compat_setdrvprm(int drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) struct compat_floppy_drive_params __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) struct compat_floppy_drive_params v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) if (copy_from_user(&v, arg, sizeof(struct compat_floppy_drive_params)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) if (!valid_floppy_drive_params(v.autodetect, v.native_format))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) drive_params[drive].cmos = v.cmos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) drive_params[drive].max_dtr = v.max_dtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) drive_params[drive].hlt = v.hlt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) drive_params[drive].hut = v.hut;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) drive_params[drive].srt = v.srt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) drive_params[drive].spinup = v.spinup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) drive_params[drive].spindown = v.spindown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) drive_params[drive].spindown_offset = v.spindown_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) drive_params[drive].select_delay = v.select_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) drive_params[drive].rps = v.rps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) drive_params[drive].tracks = v.tracks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) drive_params[drive].timeout = v.timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) drive_params[drive].interleave_sect = v.interleave_sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) drive_params[drive].max_errors = v.max_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) drive_params[drive].flags = v.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) drive_params[drive].read_track = v.read_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) memcpy(drive_params[drive].autodetect, v.autodetect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) sizeof(v.autodetect));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) drive_params[drive].checkfreq = v.checkfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) drive_params[drive].native_format = v.native_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) static int compat_getdrvprm(int drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) struct compat_floppy_drive_params __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) struct compat_floppy_drive_params v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) memset(&v, 0, sizeof(struct compat_floppy_drive_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) v.cmos = drive_params[drive].cmos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) v.max_dtr = drive_params[drive].max_dtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) v.hlt = drive_params[drive].hlt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) v.hut = drive_params[drive].hut;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) v.srt = drive_params[drive].srt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) v.spinup = drive_params[drive].spinup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) v.spindown = drive_params[drive].spindown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) v.spindown_offset = drive_params[drive].spindown_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) v.select_delay = drive_params[drive].select_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) v.rps = drive_params[drive].rps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) v.tracks = drive_params[drive].tracks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) v.timeout = drive_params[drive].timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) v.interleave_sect = drive_params[drive].interleave_sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) v.max_errors = drive_params[drive].max_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) v.flags = drive_params[drive].flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) v.read_track = drive_params[drive].read_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) memcpy(v.autodetect, drive_params[drive].autodetect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) sizeof(v.autodetect));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) v.checkfreq = drive_params[drive].checkfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) v.native_format = drive_params[drive].native_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_params)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) static int compat_getdrvstat(int drive, bool poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) struct compat_floppy_drive_struct __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) struct compat_floppy_drive_struct v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) memset(&v, 0, sizeof(struct compat_floppy_drive_struct));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) if (poll) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) goto Eintr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) goto Eintr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) v.spinup_date = drive_state[drive].spinup_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) v.select_date = drive_state[drive].select_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) v.first_read_date = drive_state[drive].first_read_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) v.probed_format = drive_state[drive].probed_format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) v.track = drive_state[drive].track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) v.maxblock = drive_state[drive].maxblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) v.maxtrack = drive_state[drive].maxtrack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) v.generation = drive_state[drive].generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) v.keep_data = drive_state[drive].keep_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) v.fd_ref = drive_state[drive].fd_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) v.fd_device = drive_state[drive].fd_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) v.last_checked = drive_state[drive].last_checked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) v.dmabuf = (uintptr_t) drive_state[drive].dmabuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) v.bufblocks = drive_state[drive].bufblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_struct)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) Eintr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) static int compat_getfdcstat(int drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) struct compat_floppy_fdc_state __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) struct compat_floppy_fdc_state v32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) struct floppy_fdc_state v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) v = fdc_state[FDC(drive)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) memset(&v32, 0, sizeof(struct compat_floppy_fdc_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) v32.spec1 = v.spec1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) v32.spec2 = v.spec2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) v32.dtr = v.dtr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) v32.version = v.version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) v32.dor = v.dor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) v32.address = v.address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) v32.rawcmd = v.rawcmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) v32.reset = v.reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) v32.need_configure = v.need_configure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) v32.perp_mode = v.perp_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) v32.has_fifo = v.has_fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) v32.driver_version = v.driver_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) memcpy(v32.track, v.track, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) if (copy_to_user(arg, &v32, sizeof(struct compat_floppy_fdc_state)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) static int compat_werrorget(int drive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) struct compat_floppy_write_errors __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) struct compat_floppy_write_errors v32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) struct floppy_write_errors v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) memset(&v32, 0, sizeof(struct compat_floppy_write_errors));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) v = write_errors[drive];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) v32.write_errors = v.write_errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) v32.first_error_sector = v.first_error_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) v32.first_error_generation = v.first_error_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) v32.last_error_sector = v.last_error_sector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) v32.last_error_generation = v.last_error_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) v32.badness = v.badness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) if (copy_to_user(arg, &v32, sizeof(struct compat_floppy_write_errors)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) static int fd_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) unsigned long param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) int drive = (long)bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) case CDROMEJECT: /* CD-ROM eject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) case 0x6470: /* SunOS floppy eject */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) case FDMSGON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) case FDMSGOFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) case FDSETEMSGTRESH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) case FDFLUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) case FDWERRORCLR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) case FDEJECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) case FDCLRPRM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) case FDFMTBEG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) case FDRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) case FDTWADDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) return fd_ioctl(bdev, mode, cmd, param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) case FDSETMAXERRS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) case FDGETMAXERRS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) case FDGETDRVTYP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) case FDFMTEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) case FDFMTTRK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) case FDRAWCMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) return fd_ioctl(bdev, mode, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) (unsigned long)compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) case FDSETPRM32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) case FDDEFPRM32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) return compat_set_geometry(bdev, mode, cmd, compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) case FDGETPRM32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) return compat_get_prm(drive, compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) case FDSETDRVPRM32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) return compat_setdrvprm(drive, compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) case FDGETDRVPRM32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) return compat_getdrvprm(drive, compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) case FDPOLLDRVSTAT32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) return compat_getdrvstat(drive, true, compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) case FDGETDRVSTAT32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) return compat_getdrvstat(drive, false, compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) case FDGETFDCSTAT32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) return compat_getfdcstat(drive, compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) case FDWERRORGET32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) return compat_werrorget(drive, compat_ptr(param));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) static void __init config_types(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) bool has_drive = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) /* read drive info out of physical CMOS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) drive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) if (!drive_params[drive].cmos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) drive_params[drive].cmos = FLOPPY0_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) drive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) if (!drive_params[drive].cmos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) drive_params[drive].cmos = FLOPPY1_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) /* FIXME: additional physical CMOS drive detection should go here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) for (drive = 0; drive < N_DRIVE; drive++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) unsigned int type = drive_params[drive].cmos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) struct floppy_drive_params *params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) const char *name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) char temparea[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) if (type < ARRAY_SIZE(default_drive_params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) params = &default_drive_params[type].params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) if (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) name = default_drive_params[type].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) allowed_drive_mask |= 1 << drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) allowed_drive_mask &= ~(1 << drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) params = &default_drive_params[0].params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) snprintf(temparea, sizeof(temparea),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) "unknown type %d (usb?)", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) name = temparea;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) if (name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) const char *prepend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) if (!has_drive) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) prepend = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) has_drive = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) pr_info("Floppy drive(s):");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) prepend = ",";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) pr_cont("%s fd%d is %s", prepend, drive, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) drive_params[drive] = *params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) if (has_drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) static void floppy_release(struct gendisk *disk, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) int drive = (long)disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) mutex_lock(&open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) if (!drive_state[drive].fd_ref--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) DPRINT("floppy_release with fd_ref == 0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) drive_state[drive].fd_ref = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) if (!drive_state[drive].fd_ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) opened_bdev[drive] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) mutex_unlock(&open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) * floppy_open check for aliasing (/dev/fd0 can be the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) * /dev/PS0 etc), and disallows simultaneous access to the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) * drive with different device numbers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) static int floppy_open(struct block_device *bdev, fmode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) int drive = (long)bdev->bd_disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) int old_dev, new_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) int try;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) int res = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) char *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) mutex_lock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) mutex_lock(&open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) old_dev = drive_state[drive].fd_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) if (opened_bdev[drive] && opened_bdev[drive] != bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) if (!drive_state[drive].fd_ref && (drive_params[drive].flags & FD_BROKEN_DCL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) drive_state[drive].fd_ref++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) opened_bdev[drive] = bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) res = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) if (!floppy_track_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) /* if opening an ED drive, reserve a big buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) * else reserve a small one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) if ((drive_params[drive].cmos == 6) || (drive_params[drive].cmos == 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) try = 64; /* Only 48 actually useful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) try = 32; /* Only 24 actually useful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) tmp = (char *)fd_dma_mem_alloc(1024 * try);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) if (!tmp && !floppy_track_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) try >>= 1; /* buffer only one side */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) INFBOUND(try, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) tmp = (char *)fd_dma_mem_alloc(1024 * try);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) if (!tmp && !floppy_track_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) fallback_on_nodma_alloc(&tmp, 2048 * try);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) if (!tmp && !floppy_track_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) DPRINT("Unable to allocate DMA memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) if (floppy_track_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) if (tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) fd_dma_mem_free((unsigned long)tmp, try * 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) buffer_min = buffer_max = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) floppy_track_buffer = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) max_buffer_sectors = try;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) new_dev = MINOR(bdev->bd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) drive_state[drive].fd_device = new_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) set_capacity(disks[drive], floppy_sizes[new_dev]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) if (old_dev != -1 && old_dev != new_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) if (buffer_drive == drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) buffer_track = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) if (fdc_state[FDC(drive)].rawcmd == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) fdc_state[FDC(drive)].rawcmd = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) if (!(mode & FMODE_NDELAY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) if (mode & (FMODE_READ|FMODE_WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) drive_state[drive].last_checked = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) if (bdev_check_media_change(bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) floppy_revalidate(bdev->bd_disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) res = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) if ((mode & FMODE_WRITE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) !test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) mutex_unlock(&open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) drive_state[drive].fd_ref--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) if (!drive_state[drive].fd_ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) opened_bdev[drive] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) mutex_unlock(&open_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) mutex_unlock(&floppy_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) * Check if the disk has been changed or if a change has been faked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) static unsigned int floppy_check_events(struct gendisk *disk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) unsigned int clearing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) int drive = (long)disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) test_bit(FD_VERIFY_BIT, &drive_state[drive].flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) return DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) if (time_after(jiffies, drive_state[drive].last_checked + drive_params[drive].checkfreq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) if (lock_fdc(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) poll_drive(false, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) test_bit(drive, &fake_change) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) drive_no_geom(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) return DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) * This implements "read block 0" for floppy_revalidate().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) * Needed for format autodetection, checking whether there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) * a disk in the drive, and whether that disk is writable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) struct rb0_cbdata {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) struct completion complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) static void floppy_rb0_cb(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) struct rb0_cbdata *cbdata = (struct rb0_cbdata *)bio->bi_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) int drive = cbdata->drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) if (bio->bi_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) pr_info("floppy: error %d while reading block 0\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) bio->bi_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) set_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) complete(&cbdata->complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) static int __floppy_read_block_0(struct block_device *bdev, int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) struct bio bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) struct bio_vec bio_vec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) struct rb0_cbdata cbdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) page = alloc_page(GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) cbdata.drive = drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) bio_init(&bio, &bio_vec, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) bio_set_dev(&bio, bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) bio_add_page(&bio, page, block_size(bdev), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) bio.bi_iter.bi_sector = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) bio.bi_flags |= (1 << BIO_QUIET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) bio.bi_private = &cbdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) bio.bi_end_io = floppy_rb0_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) bio_set_op_attrs(&bio, REQ_OP_READ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) init_completion(&cbdata.complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) submit_bio(&bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) wait_for_completion(&cbdata.complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) __free_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) /* revalidate the floppy disk, i.e. trigger format autodetection by reading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) * the bootblock (block 0). "Autodetection" is also needed to check whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) * there is a disk in the drive at all... Thus we also do it for fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) * geometry formats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) static int floppy_revalidate(struct gendisk *disk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) int drive = (long)disk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) int cf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) test_bit(drive, &fake_change) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) drive_no_geom(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) if (WARN(atomic_read(&usage_count) == 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) "VFS: revalidate called on non-open device.\n"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) res = lock_fdc(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) cf = (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) test_bit(FD_VERIFY_BIT, &drive_state[drive].flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) if (!(cf || test_bit(drive, &fake_change) || drive_no_geom(drive))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) process_fd_request(); /*already done by another thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) drive_state[drive].maxblock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) drive_state[drive].maxtrack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) if (buffer_drive == drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) buffer_track = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) clear_bit(drive, &fake_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) clear_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) if (cf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) drive_state[drive].generation++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) if (drive_no_geom(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) /* auto-sensing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) res = __floppy_read_block_0(opened_bdev[drive], drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) if (cf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) poll_drive(false, FD_RAW_NEED_DISK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) process_fd_request();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) set_capacity(disk, floppy_sizes[drive_state[drive].fd_device]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) static const struct block_device_operations floppy_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) .open = floppy_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) .release = floppy_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) .ioctl = fd_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) .getgeo = fd_getgeo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) .check_events = floppy_check_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) .compat_ioctl = fd_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) * Floppy Driver initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) * =============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) /* Determine the floppy disk controller type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) /* This routine was written by David C. Niemi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) static char __init get_fdc_version(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) output_byte(fdc, FD_DUMPREGS); /* 82072 and better know DUMPREGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) if (fdc_state[fdc].reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) return FDC_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) r = result(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) if (r <= 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) return FDC_NONE; /* No FDC present ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) if ((r == 1) && (reply_buffer[0] == 0x80)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) pr_info("FDC %d is an 8272A\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) return FDC_8272A; /* 8272a/765 don't know DUMPREGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) if (r != 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) pr_info("FDC %d init: DUMPREGS: unexpected return of %d bytes.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) fdc, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) return FDC_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) if (!fdc_configure(fdc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) pr_info("FDC %d is an 82072\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) return FDC_82072; /* 82072 doesn't know CONFIGURE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) output_byte(fdc, FD_PERPENDICULAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) if (need_more_output(fdc) == MORE_OUTPUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) output_byte(fdc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) pr_info("FDC %d is an 82072A\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) return FDC_82072A; /* 82072A as found on Sparcs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) output_byte(fdc, FD_UNLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) r = result(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) if ((r == 1) && (reply_buffer[0] == 0x80)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) pr_info("FDC %d is a pre-1991 82077\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) return FDC_82077_ORIG; /* Pre-1991 82077, doesn't know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) * LOCK/UNLOCK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) if ((r != 1) || (reply_buffer[0] != 0x00)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) pr_info("FDC %d init: UNLOCK: unexpected return of %d bytes.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) fdc, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) return FDC_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) output_byte(fdc, FD_PARTID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) r = result(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) if (r != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) fdc, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) return FDC_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) if (reply_buffer[0] == 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) pr_info("FDC %d is a post-1991 82077\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) return FDC_82077; /* Revised 82077AA passes all the tests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) switch (reply_buffer[0] >> 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) case 0x0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) /* Either a 82078-1 or a 82078SL running at 5Volt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) pr_info("FDC %d is an 82078.\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) return FDC_82078;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) case 0x1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) pr_info("FDC %d is a 44pin 82078\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) return FDC_82078;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) case 0x2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) pr_info("FDC %d is a S82078B\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) return FDC_S82078B;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) case 0x3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) pr_info("FDC %d is a National Semiconductor PC87306\n", fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) return FDC_87306;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) pr_info("FDC %d init: 82078 variant with unknown PARTID=%d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) fdc, reply_buffer[0] >> 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) return FDC_82078_UNKN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) } /* get_fdc_version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) /* lilo configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) static void __init floppy_set_flags(int *ints, int param, int param2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) for (i = 0; i < ARRAY_SIZE(default_drive_params); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) if (param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) default_drive_params[i].params.flags |= param2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) default_drive_params[i].params.flags &= ~param2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) DPRINT("%s flag 0x%x\n", param2 ? "Setting" : "Clearing", param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) static void __init daring(int *ints, int param, int param2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) for (i = 0; i < ARRAY_SIZE(default_drive_params); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) if (param) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) default_drive_params[i].params.select_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) default_drive_params[i].params.flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) FD_SILENT_DCL_CLEAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) default_drive_params[i].params.select_delay =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 2 * HZ / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) default_drive_params[i].params.flags &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) ~FD_SILENT_DCL_CLEAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) DPRINT("Assuming %s floppy hardware\n", param ? "standard" : "broken");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) static void __init set_cmos(int *ints, int dummy, int dummy2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) int current_drive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) if (ints[0] != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) DPRINT("wrong number of parameters for CMOS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) current_drive = ints[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) if (current_drive < 0 || current_drive >= 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) DPRINT("bad drive for set_cmos\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) #if N_FDC > 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) if (current_drive >= 4 && !FDC2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) FDC2 = 0x370;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) drive_params[current_drive].cmos = ints[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) DPRINT("setting CMOS code to %d\n", ints[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) static struct param_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) void (*fn) (int *ints, int param, int param2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) int *var;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) int def_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) int param2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) } config_params[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) {"allowed_drive_mask", NULL, &allowed_drive_mask, 0xff, 0}, /* obsolete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) {"all_drives", NULL, &allowed_drive_mask, 0xff, 0}, /* obsolete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) {"asus_pci", NULL, &allowed_drive_mask, 0x33, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) {"irq", NULL, &FLOPPY_IRQ, 6, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) {"dma", NULL, &FLOPPY_DMA, 2, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) {"daring", daring, NULL, 1, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) #if N_FDC > 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) {"two_fdc", NULL, &FDC2, 0x370, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) {"one_fdc", NULL, &FDC2, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) {"thinkpad", floppy_set_flags, NULL, 1, FD_INVERTED_DCL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) {"broken_dcl", floppy_set_flags, NULL, 1, FD_BROKEN_DCL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) {"messages", floppy_set_flags, NULL, 1, FTD_MSG},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) {"silent_dcl_clear", floppy_set_flags, NULL, 1, FD_SILENT_DCL_CLEAR},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) {"debug", floppy_set_flags, NULL, 1, FD_DEBUG},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) {"nodma", NULL, &can_use_virtual_dma, 1, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) {"omnibook", NULL, &can_use_virtual_dma, 1, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) {"yesdma", NULL, &can_use_virtual_dma, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) {"fifo_depth", NULL, &fifo_depth, 0xa, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) {"nofifo", NULL, &no_fifo, 0x20, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) {"usefifo", NULL, &no_fifo, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) {"cmos", set_cmos, NULL, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) {"slow", NULL, &slow_floppy, 1, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) {"unexpected_interrupts", NULL, &print_unex, 1, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474) {"no_unexpected_interrupts", NULL, &print_unex, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) {"L40SX", NULL, &print_unex, 0, 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) EXTRA_FLOPPY_PARAMS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) static int __init floppy_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) int param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) int ints[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) str = get_options(str, ARRAY_SIZE(ints), ints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) if (str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) for (i = 0; i < ARRAY_SIZE(config_params); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) if (strcmp(str, config_params[i].name) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) if (ints[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) param = ints[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) param = config_params[i].def_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) if (config_params[i].fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) config_params[i].fn(ints, param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) config_params[i].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) param2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) if (config_params[i].var) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) DPRINT("%s=%d\n", str, param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) *config_params[i].var = param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) if (str) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) DPRINT("unknown floppy option [%s]\n", str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) DPRINT("allowed options are:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) for (i = 0; i < ARRAY_SIZE(config_params); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) pr_cont(" %s", config_params[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) DPRINT("botched floppy option\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) DPRINT("Read Documentation/admin-guide/blockdev/floppy.rst\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) static int have_no_fdc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) static ssize_t floppy_cmos_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) struct platform_device *p = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) drive = p->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528) return sprintf(buf, "%X\n", drive_params[drive].cmos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) static DEVICE_ATTR(cmos, 0444, floppy_cmos_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) static struct attribute *floppy_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) &dev_attr_cmos.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) ATTRIBUTE_GROUPS(floppy_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) static void floppy_device_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) static int floppy_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) int fdc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) int saved_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) saved_drive = current_drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) for (fdc = 0; fdc < N_FDC; fdc++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) if (fdc_state[fdc].address != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) user_reset_fdc(REVDRIVE(fdc, 0), FD_RESET_ALWAYS, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) set_fdc(saved_drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) static const struct dev_pm_ops floppy_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) .resume = floppy_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) .restore = floppy_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) static struct platform_driver floppy_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) .name = "floppy",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) .pm = &floppy_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) static const struct blk_mq_ops floppy_mq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) .queue_rq = floppy_queue_rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) static struct platform_device floppy_device[N_DRIVE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) static bool floppy_available(int drive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) if (!(allowed_drive_mask & (1 << drive)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) if (fdc_state[FDC(drive)].version == FDC_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) static struct kobject *floppy_find(dev_t dev, int *part, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) int drive = (*part & 3) | ((*part & 0x80) >> 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) if (drive >= N_DRIVE || !floppy_available(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) *part = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) return get_disk_and_module(disks[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) static int __init do_floppy_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) int i, unit, drive, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) set_debugt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) interruptjiffies = resultjiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) #if defined(CONFIG_PPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) if (check_legacy_ioport(FDC1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) raw_cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) floppy_wq = alloc_ordered_workqueue("floppy", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) if (!floppy_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) for (drive = 0; drive < N_DRIVE; drive++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) disks[drive] = alloc_disk(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) if (!disks[drive]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) goto out_put_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) disks[drive]->queue = blk_mq_init_sq_queue(&tag_sets[drive],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) &floppy_mq_ops, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) BLK_MQ_F_SHOULD_MERGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) if (IS_ERR(disks[drive]->queue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) err = PTR_ERR(disks[drive]->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) disks[drive]->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) goto out_put_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) blk_queue_bounce_limit(disks[drive]->queue, BLK_BOUNCE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) blk_queue_max_hw_sectors(disks[drive]->queue, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) disks[drive]->major = FLOPPY_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) disks[drive]->first_minor = TOMINOR(drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) disks[drive]->fops = &floppy_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) disks[drive]->events = DISK_EVENT_MEDIA_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) sprintf(disks[drive]->disk_name, "fd%d", drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) timer_setup(&motor_off_timer[drive], motor_off_callback, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) err = register_blkdev(FLOPPY_MAJOR, "fd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) goto out_put_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) err = platform_driver_register(&floppy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) goto out_unreg_blkdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) blk_register_region(MKDEV(FLOPPY_MAJOR, 0), 256, THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) floppy_find, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) for (i = 0; i < 256; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) if (ITYPE(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) floppy_sizes[i] = floppy_type[ITYPE(i)].size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) floppy_sizes[i] = MAX_DISK_SIZE << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) reschedule_timeout(MAXTIMEOUT, "floppy init");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) config_types();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) for (i = 0; i < N_FDC; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) memset(&fdc_state[i], 0, sizeof(*fdc_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) fdc_state[i].dtr = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) fdc_state[i].dor = 0x4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) #if defined(__sparc__) || defined(__mc68000__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) /*sparcs/sun3x don't have a DOR reset which we can fall back on to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) #ifdef __mc68000__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) if (MACH_IS_SUN3X)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) fdc_state[i].version = FDC_82072A;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) use_virtual_dma = can_use_virtual_dma & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) fdc_state[0].address = FDC1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) if (fdc_state[0].address == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) cancel_delayed_work(&fd_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) goto out_unreg_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) #if N_FDC > 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) fdc_state[1].address = FDC2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) current_fdc = 0; /* reset fdc in case of unexpected interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) err = floppy_grab_irq_and_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) cancel_delayed_work(&fd_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) goto out_unreg_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) /* initialise drive state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) for (drive = 0; drive < N_DRIVE; drive++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) memset(&drive_state[drive], 0, sizeof(drive_state[drive]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) drive_state[drive].fd_device = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) floppy_track_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) max_buffer_sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) * Small 10 msec delay to let through any interrupt that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) * initialization might have triggered, to not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) * confuse detection:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) for (i = 0; i < N_FDC; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) fdc_state[i].driver_version = FD_DRIVER_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) for (unit = 0; unit < 4; unit++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) fdc_state[i].track[unit] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) if (fdc_state[i].address == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) fdc_state[i].rawcmd = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) if (user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) /* free ioports reserved by floppy_grab_irq_and_dma() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) floppy_release_regions(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) fdc_state[i].address = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) fdc_state[i].version = FDC_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) /* Try to determine the floppy controller type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) fdc_state[i].version = get_fdc_version(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) if (fdc_state[i].version == FDC_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) /* free ioports reserved by floppy_grab_irq_and_dma() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) floppy_release_regions(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) fdc_state[i].address = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) if (can_use_virtual_dma == 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) fdc_state[i].version < FDC_82072A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) can_use_virtual_dma = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) have_no_fdc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) /* Not all FDCs seem to be able to handle the version command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) * properly, so force a reset for the standard FDC clones,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) * to avoid interrupt garbage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) current_fdc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) cancel_delayed_work(&fd_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) current_drive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) initialized = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) if (have_no_fdc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) DPRINT("no floppy controllers found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) err = have_no_fdc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) goto out_release_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) for (drive = 0; drive < N_DRIVE; drive++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) if (!floppy_available(drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) floppy_device[drive].name = floppy_device_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) floppy_device[drive].id = drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) floppy_device[drive].dev.release = floppy_device_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) floppy_device[drive].dev.groups = floppy_dev_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) err = platform_device_register(&floppy_device[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) goto out_remove_drives;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) /* to be cleaned up... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) disks[drive]->private_data = (void *)(long)drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) disks[drive]->flags |= GENHD_FL_REMOVABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) device_add_disk(&floppy_device[drive].dev, disks[drive], NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) out_remove_drives:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) while (drive--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) if (floppy_available(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) del_gendisk(disks[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) platform_device_unregister(&floppy_device[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) out_release_dma:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) if (atomic_read(&usage_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) floppy_release_irq_and_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) out_unreg_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) platform_driver_unregister(&floppy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) out_unreg_blkdev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) unregister_blkdev(FLOPPY_MAJOR, "fd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) out_put_disk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) destroy_workqueue(floppy_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) for (drive = 0; drive < N_DRIVE; drive++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) if (!disks[drive])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794) if (disks[drive]->queue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) del_timer_sync(&motor_off_timer[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) blk_cleanup_queue(disks[drive]->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) disks[drive]->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) blk_mq_free_tag_set(&tag_sets[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) put_disk(disks[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) #ifndef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) static __init void floppy_async_init(void *data, async_cookie_t cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) do_floppy_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) static int __init floppy_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) #ifdef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) return do_floppy_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) /* Don't hold up the bootup by the floppy initialization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) async_schedule(floppy_async_init, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) static const struct io_region {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) } io_regions[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) { 2, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) /* address + 3 is sometimes reserved by pnp bios for motherboard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) { 4, 2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) /* address + 6 is reserved, and may be taken by IDE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) * Unfortunately, Adaptec doesn't know this :-(, */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) { 7, 1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) static void floppy_release_allocated_regions(int fdc, const struct io_region *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) while (p != io_regions) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) p--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839) release_region(fdc_state[fdc].address + p->offset, p->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) #define ARRAY_END(X) (&((X)[ARRAY_SIZE(X)]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) static int floppy_request_regions(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) const struct io_region *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) for (p = io_regions; p < ARRAY_END(io_regions); p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) if (!request_region(fdc_state[fdc].address + p->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) p->size, "floppy")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) DPRINT("Floppy io-port 0x%04lx in use\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) fdc_state[fdc].address + p->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) floppy_release_allocated_regions(fdc, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) static void floppy_release_regions(int fdc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) floppy_release_allocated_regions(fdc, ARRAY_END(io_regions));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) static int floppy_grab_irq_and_dma(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) int fdc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) if (atomic_inc_return(&usage_count) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) * We might have scheduled a free_irq(), wait it to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) * drain first:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) flush_workqueue(floppy_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) if (fd_request_irq()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) DPRINT("Unable to grab IRQ%d for the floppy driver\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) FLOPPY_IRQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) atomic_dec(&usage_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) if (fd_request_dma()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) DPRINT("Unable to grab DMA%d for the floppy driver\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) FLOPPY_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) if (can_use_virtual_dma & 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) use_virtual_dma = can_use_virtual_dma = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) if (!(can_use_virtual_dma & 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) fd_free_irq();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) atomic_dec(&usage_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) for (fdc = 0; fdc < N_FDC; fdc++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) if (fdc_state[fdc].address != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) if (floppy_request_regions(fdc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) for (fdc = 0; fdc < N_FDC; fdc++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) if (fdc_state[fdc].address != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) reset_fdc_info(fdc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) set_dor(0, ~0, 8); /* avoid immediate interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) for (fdc = 0; fdc < N_FDC; fdc++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) if (fdc_state[fdc].address != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) * The driver will try and free resources and relies on us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) * to know if they were allocated or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) current_fdc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) irqdma_allocated = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) fd_free_irq();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) fd_free_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) while (--fdc >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) floppy_release_regions(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) current_fdc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) atomic_dec(&usage_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) static void floppy_release_irq_and_dma(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) int fdc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) #ifndef __sparc__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) long tmpsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) unsigned long tmpaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) if (!atomic_dec_and_test(&usage_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) if (irqdma_allocated) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) fd_disable_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) fd_free_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) fd_free_irq();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) irqdma_allocated = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) set_dor(0, ~0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) #if N_FDC > 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) set_dor(1, ~8, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) if (floppy_track_buffer && max_buffer_sectors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) tmpsize = max_buffer_sectors * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) tmpaddr = (unsigned long)floppy_track_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) floppy_track_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) max_buffer_sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) buffer_min = buffer_max = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) fd_dma_mem_free(tmpaddr, tmpsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) #ifndef __sparc__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964) for (drive = 0; drive < N_FDC * 4; drive++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) if (timer_pending(motor_off_timer + drive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) pr_info("motor off timer %d still active\n", drive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) if (delayed_work_pending(&fd_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) pr_info("floppy timer still active:%s\n", timeout_message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) if (delayed_work_pending(&fd_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) pr_info("auxiliary floppy timer still active\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) if (work_pending(&floppy_work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) pr_info("work still pending\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) for (fdc = 0; fdc < N_FDC; fdc++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) if (fdc_state[fdc].address != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) floppy_release_regions(fdc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) #ifdef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) static char *floppy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) static void __init parse_floppy_cfg_string(char *cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) char *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) while (*cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) ptr = cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) while (*cfg && *cfg != ' ' && *cfg != '\t')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) cfg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) if (*cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) *cfg = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) cfg++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) if (*ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) floppy_setup(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) static int __init floppy_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) if (floppy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) parse_floppy_cfg_string(floppy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) return floppy_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) module_init(floppy_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) static void __exit floppy_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) int drive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) unregister_blkdev(FLOPPY_MAJOR, "fd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) platform_driver_unregister(&floppy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) destroy_workqueue(floppy_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) for (drive = 0; drive < N_DRIVE; drive++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) del_timer_sync(&motor_off_timer[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) if (floppy_available(drive)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) del_gendisk(disks[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) platform_device_unregister(&floppy_device[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) blk_cleanup_queue(disks[drive]->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) blk_mq_free_tag_set(&tag_sets[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) * These disks have not called add_disk(). Don't put down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) * queue reference in put_disk().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) if (!(allowed_drive_mask & (1 << drive)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) fdc_state[FDC(drive)].version == FDC_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) disks[drive]->queue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) put_disk(disks[drive]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) cancel_delayed_work_sync(&fd_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) cancel_delayed_work_sync(&fd_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) if (atomic_read(&usage_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) floppy_release_irq_and_dma();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) /* eject disk, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) fd_eject(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) module_exit(floppy_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) module_param(floppy, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) module_param(FLOPPY_IRQ, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) module_param(FLOPPY_DMA, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) MODULE_AUTHOR("Alain L. Knaff");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) MODULE_SUPPORTED_DEVICE("fd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) /* This doesn't actually get used other than for module information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) static const struct pnp_device_id floppy_pnpids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) {"PNP0700", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) MODULE_DEVICE_TABLE(pnp, floppy_pnpids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) __setup("floppy=", floppy_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) module_init(floppy_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) MODULE_ALIAS_BLOCKDEV_MAJOR(FLOPPY_MAJOR);