2019-05-19 15:08:20 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* linux/drivers/block/floppy.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
* Copyright (C) 1993, 1994 Alain Knaff
|
|
|
|
* Copyright (C) 1998 Alan Cox
|
|
|
|
*/
|
2007-10-17 10:30:57 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* 02.12.91 - Changed to static variables to indicate need for reset
|
|
|
|
* and recalibrate. This makes some things easier (output_byte reset
|
|
|
|
* checking etc), and means less interrupt jumping in case of errors,
|
|
|
|
* so the code is hopefully easier to understand.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is certainly a mess. I've tried my best to get it working,
|
|
|
|
* but I don't like programming floppies, and I have only one anyway.
|
|
|
|
* Urgel. I should check for more errors, and do more graceful error
|
|
|
|
* recovery. Seems there are problems with several drives. I've tried to
|
|
|
|
* correct them. No promises.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As with hd.c, all routines within this file can (and will) be called
|
|
|
|
* by interrupts, so extreme caution is needed. A hardware interrupt
|
|
|
|
* handler may not sleep, or a kernel panic will happen. Thus I cannot
|
|
|
|
* call "floppy-on" directly, but have to set a special timer interrupt
|
|
|
|
* etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 28.02.92 - made track-buffering routines, based on the routines written
|
|
|
|
* by entropy@wintermute.wpi.edu (Lawrence Foard). Linus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Automatic floppy-detection and formatting written by Werner Almesberger
|
|
|
|
* (almesber@nessie.cs.id.ethz.ch), who also corrected some problems with
|
|
|
|
* the floppy-change signal detection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1992/7/22 -- Hennus Bergman: Added better error reporting, fixed
|
|
|
|
* FDC data overrun bug, added some preliminary stuff for vertical
|
|
|
|
* recording support.
|
|
|
|
*
|
|
|
|
* 1992/9/17: Added DMA allocation & DMA functions. -- hhb.
|
|
|
|
*
|
|
|
|
* TODO: Errors are still not counted properly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 1992/9/20
|
|
|
|
* Modifications for ``Sector Shifting'' by Rob Hooft (hooft@chem.ruu.nl)
|
|
|
|
* modeled after the freeware MS-DOS program fdformat/88 V1.8 by
|
|
|
|
* Christoph H. Hochst\"atter.
|
|
|
|
* I have fixed the shift values to the ones I always use. Maybe a new
|
|
|
|
* ioctl() should be created to be able to modify them.
|
|
|
|
* There is a bug in the driver that makes it impossible to format a
|
|
|
|
* floppy as the first thing after bootup.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1993/4/29 -- Linus -- cleaned up the timer handling in the kernel, and
|
|
|
|
* this helped the floppy driver as well. Much cleaner, and still seems to
|
|
|
|
* work.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 1994/6/24 --bbroad-- added the floppy table entries and made
|
|
|
|
* minor modifications to allow 2.88 floppies to be run.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 1994/7/13 -- Paul Vojta -- modified the probing code to allow three or more
|
|
|
|
* disk types.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1994/8/8 -- Alain Knaff -- Switched to fdpatch driver: Support for bigger
|
|
|
|
* format bug fixes, but unfortunately some new bugs too...
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 1994/9/17 -- Koen Holtman -- added logging of physical floppy write
|
|
|
|
* errors to allow safe writing by specialized programs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 1995/4/24 -- Dan Fandrich -- added support for Commodore 1581 3.5" disks
|
|
|
|
* by defining bit 1 of the "stretch" parameter to mean put sectors on the
|
|
|
|
* opposite side of the disk, leaving the sector IDs alone (i.e. Commodore's
|
|
|
|
* drives are "upside-down").
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1995/8/26 -- Andreas Busse -- added Mips support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1995/10/18 -- Ralf Baechle -- Portability cleanup; move machine dependent
|
|
|
|
* features to asm/floppy.h.
|
|
|
|
*/
|
|
|
|
|
2005-11-08 18:52:12 +03:00
|
|
|
/*
|
|
|
|
* 1998/1/21 -- Richard Gooch <rgooch@atnf.csiro.au> -- devfs support
|
|
|
|
*/
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* 1998/05/07 -- Russell King -- More portability cleanups; moved definition of
|
|
|
|
* interrupt and dma channel to asm/floppy.h. Cleaned up some formatting &
|
|
|
|
* use of '0' for NULL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1998/06/07 -- Alan Cox -- Merged the 2.0.34 fixes for resource allocation
|
|
|
|
* failures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1998/09/20 -- David Weinehall -- Added slow-down code for buggy PS/2-drives.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1999/08/13 -- Paul Slootman -- floppy stopped working on Alpha after 24
|
|
|
|
* days, 6 hours, 32 minutes and 32 seconds (i.e. MAXINT jiffies; ints were
|
|
|
|
* being used to store jiffies, which are unsigned longs).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2000/08/28 -- Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
* - get rid of check_region
|
|
|
|
* - s/suser/capable/
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2001/08/26 -- Paul Gortmaker - fix insmod oops on machines with no
|
|
|
|
* floppy controller (lingering task on list after module is gone... boom.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 2002/02/07 -- Anton Altaparmakov - Fix io ports reservation to correct range
|
|
|
|
* (0x3f2-0x3f5, 0x3f7). This fix is a bit of a hack but the proper fix
|
|
|
|
* requires many non-obvious changes in arch dependent code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 2003/07/28 -- Daniele Bellucci <bellucda@tiscali.it>.
|
|
|
|
* Better audit of register_blkdev.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef FLOPPY_SILENT_DCL_CLEAR
|
|
|
|
|
|
|
|
#define REALLY_SLOW_IO
|
|
|
|
|
|
|
|
#define DEBUGT 2
|
|
|
|
|
2010-03-11 02:21:05 +03:00
|
|
|
#define DPRINT(format, args...) \
|
|
|
|
pr_info("floppy%d: " format, current_drive, ##args)
|
|
|
|
|
|
|
|
#define DCL_DEBUG /* debug disk change line */
|
2010-03-11 02:20:54 +03:00
|
|
|
#ifdef DCL_DEBUG
|
|
|
|
#define debug_dcl(test, fmt, args...) \
|
|
|
|
do { if ((test) & FD_DEBUG) DPRINT(fmt, ##args); } while (0)
|
|
|
|
#else
|
|
|
|
#define debug_dcl(test, fmt, args...) \
|
|
|
|
do { if (0) DPRINT(fmt, ##args); } while (0)
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* do print messages for unexpected interrupts */
|
|
|
|
static int print_unex = 1;
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#define FDPATCHES
|
|
|
|
#include <linux/fdreg.h>
|
|
|
|
#include <linux/fd.h>
|
|
|
|
#include <linux/hdreg.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/string.h>
|
2006-03-28 13:56:44 +04:00
|
|
|
#include <linux/jiffies.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/mc146818rtc.h> /* CMOS defines */
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/init.h>
|
2005-10-29 22:07:23 +04:00
|
|
|
#include <linux/platform_device.h>
|
2009-04-03 03:56:47 +04:00
|
|
|
#include <linux/mod_devicetable.h>
|
2006-03-23 14:00:26 +03:00
|
|
|
#include <linux/mutex.h>
|
2010-03-11 02:20:44 +03:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/uaccess.h>
|
2012-07-03 04:27:04 +04:00
|
|
|
#include <linux/async.h>
|
2017-06-27 22:47:56 +03:00
|
|
|
#include <linux/compat.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PS/2 floppies have much slower step rates than regular floppies.
|
|
|
|
* It's been recommended that take about 1/4 of the default speed
|
|
|
|
* in some more extreme cases.
|
|
|
|
*/
|
2010-06-02 16:28:52 +04:00
|
|
|
static DEFINE_MUTEX(floppy_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
static int slow_floppy;
|
|
|
|
|
|
|
|
#include <asm/dma.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
|
|
|
|
static int FLOPPY_IRQ = 6;
|
|
|
|
static int FLOPPY_DMA = 2;
|
|
|
|
static int can_use_virtual_dma = 2;
|
|
|
|
/* =======
|
|
|
|
* can use virtual DMA:
|
|
|
|
* 0 = use of virtual DMA disallowed by config
|
|
|
|
* 1 = use of virtual DMA prescribed by config
|
|
|
|
* 2 = no virtual DMA preference configured. By default try hard DMA,
|
|
|
|
* but fall back on virtual DMA when not enough memory available
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int use_virtual_dma;
|
|
|
|
/* =======
|
|
|
|
* use virtual DMA
|
|
|
|
* 0 using hard DMA
|
|
|
|
* 1 using virtual DMA
|
|
|
|
* This variable is set to virtual when a DMA mem problem arises, and
|
|
|
|
* reset back in floppy_grab_irq_and_dma.
|
|
|
|
* It is not safe to reset it in other circumstances, because the floppy
|
|
|
|
* driver may have several buffers in use at once, and we do currently not
|
|
|
|
* record each buffers capabilities
|
|
|
|
*/
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(floppy_lock);
|
|
|
|
|
|
|
|
static unsigned short virtual_dma_port = 0x3f0;
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
irqreturn_t floppy_interrupt(int irq, void *dev_id);
|
2005-04-17 02:20:36 +04:00
|
|
|
static int set_dor(int fdc, char mask, char data);
|
|
|
|
|
|
|
|
#define K_64 0x10000 /* 64KB */
|
|
|
|
|
|
|
|
/* the following is the mask of allowed drives. By default units 2 and
|
|
|
|
* 3 of both floppy controllers are disabled, because switching on the
|
|
|
|
* motor of these drives causes system hangs on some PCI computers. drive
|
|
|
|
* 0 is the low bit (0x1), and drive 7 is the high bit (0x80). Bits are on if
|
|
|
|
* a drive is allowed.
|
|
|
|
*
|
|
|
|
* NOTE: This must come before we include the arch floppy header because
|
|
|
|
* some ports reference this variable from there. -DaveM
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int allowed_drive_mask = 0x33;
|
|
|
|
|
|
|
|
#include <asm/floppy.h>
|
|
|
|
|
|
|
|
static int irqdma_allocated;
|
|
|
|
|
2018-10-15 18:21:34 +03:00
|
|
|
#include <linux/blk-mq.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/blkpg.h>
|
|
|
|
#include <linux/cdrom.h> /* for the compatibility eject ioctl */
|
|
|
|
#include <linux/completion.h>
|
|
|
|
|
2018-10-15 18:21:34 +03:00
|
|
|
static LIST_HEAD(floppy_reqs);
|
2005-04-17 02:20:36 +04:00
|
|
|
static struct request *current_req;
|
2010-09-22 11:32:36 +04:00
|
|
|
static int set_next_request(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#ifndef fd_get_dma_residue
|
|
|
|
#define fd_get_dma_residue() get_dma_residue(FLOPPY_DMA)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Dma Memory related stuff */
|
|
|
|
|
|
|
|
#ifndef fd_dma_mem_free
|
|
|
|
#define fd_dma_mem_free(addr, size) free_pages(addr, get_order(size))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef fd_dma_mem_alloc
|
2010-03-11 02:20:45 +03:00
|
|
|
#define fd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL, get_order(size))
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
|
2017-07-13 17:12:05 +03:00
|
|
|
#ifndef fd_cacheflush
|
|
|
|
#define fd_cacheflush(addr, size) /* nothing... */
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static inline void fallback_on_nodma_alloc(char **addr, size_t l)
|
|
|
|
{
|
|
|
|
#ifdef FLOPPY_CAN_FALLBACK_ON_NODMA
|
|
|
|
if (*addr)
|
|
|
|
return; /* we have the memory */
|
|
|
|
if (can_use_virtual_dma != 2)
|
|
|
|
return; /* no fallback allowed */
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("DMA memory shortage. Temporarily falling back on virtual DMA\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
*addr = (char *)nodma_mem_alloc(l);
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End dma memory related stuff */
|
|
|
|
|
|
|
|
static unsigned long fake_change;
|
2010-03-11 02:21:00 +03:00
|
|
|
static bool initialized;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
#define ITYPE(x) (((x) >> 2) & 0x1f)
|
|
|
|
#define TOMINOR(x) ((x & 3) | ((x & 4) << 5))
|
|
|
|
#define UNIT(x) ((x) & 0x03) /* drive on fdc */
|
|
|
|
#define FDC(x) (((x) & 0x04) >> 2) /* fdc of drive */
|
2007-10-17 10:30:57 +04:00
|
|
|
/* reverse mapping from unit and fdc to drive */
|
2005-04-17 02:20:36 +04:00
|
|
|
#define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2))
|
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
#define DRWE (&write_errors[current_drive])
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
#define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2)
|
|
|
|
#define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH)
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* read/write */
|
2010-03-11 02:20:45 +03:00
|
|
|
#define COMMAND (raw_cmd->cmd[0])
|
|
|
|
#define DR_SELECT (raw_cmd->cmd[1])
|
|
|
|
#define TRACK (raw_cmd->cmd[2])
|
|
|
|
#define HEAD (raw_cmd->cmd[3])
|
|
|
|
#define SECTOR (raw_cmd->cmd[4])
|
|
|
|
#define SIZECODE (raw_cmd->cmd[5])
|
|
|
|
#define SECT_PER_TRACK (raw_cmd->cmd[6])
|
|
|
|
#define GAP (raw_cmd->cmd[7])
|
|
|
|
#define SIZECODE2 (raw_cmd->cmd[8])
|
2005-04-17 02:20:36 +04:00
|
|
|
#define NR_RW 9
|
|
|
|
|
|
|
|
/* format */
|
2010-03-11 02:20:45 +03:00
|
|
|
#define F_SIZECODE (raw_cmd->cmd[2])
|
|
|
|
#define F_SECT_PER_TRACK (raw_cmd->cmd[3])
|
|
|
|
#define F_GAP (raw_cmd->cmd[4])
|
|
|
|
#define F_FILL (raw_cmd->cmd[5])
|
2005-04-17 02:20:36 +04:00
|
|
|
#define NR_F 6
|
|
|
|
|
|
|
|
/*
|
2010-03-11 02:20:45 +03:00
|
|
|
* Maximum disk size (in kilobytes).
|
|
|
|
* This default is used whenever the current disk size is unknown.
|
2005-04-17 02:20:36 +04:00
|
|
|
* [Now it is rather a minimum]
|
|
|
|
*/
|
|
|
|
#define MAX_DISK_SIZE 4 /* 3984 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* globals used by 'result()'
|
|
|
|
*/
|
|
|
|
#define MAX_REPLIES 16
|
|
|
|
static unsigned char reply_buffer[MAX_REPLIES];
|
2010-03-11 02:21:05 +03:00
|
|
|
static int inr; /* size of reply buffer, when called from interrupt */
|
2010-03-11 02:20:45 +03:00
|
|
|
#define ST0 (reply_buffer[0])
|
|
|
|
#define ST1 (reply_buffer[1])
|
|
|
|
#define ST2 (reply_buffer[2])
|
|
|
|
#define ST3 (reply_buffer[0]) /* result of GETSTATUS */
|
|
|
|
#define R_TRACK (reply_buffer[3])
|
|
|
|
#define R_HEAD (reply_buffer[4])
|
|
|
|
#define R_SECTOR (reply_buffer[5])
|
|
|
|
#define R_SIZECODE (reply_buffer[6])
|
|
|
|
|
|
|
|
#define SEL_DLY (2 * HZ / 100)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* this struct defines the different floppy drive types.
|
|
|
|
*/
|
|
|
|
static struct {
|
|
|
|
struct floppy_drive_params params;
|
|
|
|
const char *name; /* name printed while booting */
|
|
|
|
} default_drive_params[] = {
|
|
|
|
/* NOTE: the time values in jiffies should be in msec!
|
|
|
|
CMOS drive type
|
|
|
|
| Maximum data rate supported by drive type
|
|
|
|
| | Head load time, msec
|
|
|
|
| | | Head unload time, msec (not used)
|
|
|
|
| | | | Step rate interval, usec
|
|
|
|
| | | | | Time needed for spinup time (jiffies)
|
|
|
|
| | | | | | Timeout for spinning down (jiffies)
|
|
|
|
| | | | | | | Spindown offset (where disk stops)
|
|
|
|
| | | | | | | | Select delay
|
|
|
|
| | | | | | | | | RPS
|
|
|
|
| | | | | | | | | | Max number of tracks
|
|
|
|
| | | | | | | | | | | Interrupt timeout
|
|
|
|
| | | | | | | | | | | | Max nonintlv. sectors
|
|
|
|
| | | | | | | | | | | | | -Max Errors- flags */
|
|
|
|
{{0, 500, 16, 16, 8000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 80, 3*HZ, 20, {3,1,2,0,2}, 0,
|
|
|
|
0, { 7, 4, 8, 2, 1, 5, 3,10}, 3*HZ/2, 0 }, "unknown" },
|
|
|
|
|
|
|
|
{{1, 300, 16, 16, 8000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 40, 3*HZ, 17, {3,1,2,0,2}, 0,
|
|
|
|
0, { 1, 0, 0, 0, 0, 0, 0, 0}, 3*HZ/2, 1 }, "360K PC" }, /*5 1/4 360 KB PC*/
|
|
|
|
|
|
|
|
{{2, 500, 16, 16, 6000, 4*HZ/10, 3*HZ, 14, SEL_DLY, 6, 83, 3*HZ, 17, {3,1,2,0,2}, 0,
|
|
|
|
0, { 2, 5, 6,23,10,20,12, 0}, 3*HZ/2, 2 }, "1.2M" }, /*5 1/4 HD AT*/
|
|
|
|
|
|
|
|
{{3, 250, 16, 16, 3000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 83, 3*HZ, 20, {3,1,2,0,2}, 0,
|
|
|
|
0, { 4,22,21,30, 3, 0, 0, 0}, 3*HZ/2, 4 }, "720k" }, /*3 1/2 DD*/
|
|
|
|
|
|
|
|
{{4, 500, 16, 16, 4000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 20, {3,1,2,0,2}, 0,
|
|
|
|
0, { 7, 4,25,22,31,21,29,11}, 3*HZ/2, 7 }, "1.44M" }, /*3 1/2 HD*/
|
|
|
|
|
|
|
|
{{5, 1000, 15, 8, 3000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 40, {3,1,2,0,2}, 0,
|
|
|
|
0, { 7, 8, 4,25,28,22,31,21}, 3*HZ/2, 8 }, "2.88M AMI BIOS" }, /*3 1/2 ED*/
|
|
|
|
|
|
|
|
{{6, 1000, 15, 8, 3000, 4*HZ/10, 3*HZ, 10, SEL_DLY, 5, 83, 3*HZ, 40, {3,1,2,0,2}, 0,
|
|
|
|
0, { 7, 8, 4,25,28,22,31,21}, 3*HZ/2, 8 }, "2.88M" } /*3 1/2 ED*/
|
|
|
|
/* | --autodetected formats--- | | |
|
|
|
|
* read_track | | Name printed when booting
|
|
|
|
* | Native format
|
|
|
|
* Frequency of disk change checks */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct floppy_drive_params drive_params[N_DRIVE];
|
|
|
|
static struct floppy_drive_struct drive_state[N_DRIVE];
|
|
|
|
static struct floppy_write_errors write_errors[N_DRIVE];
|
|
|
|
static struct timer_list motor_off_timer[N_DRIVE];
|
|
|
|
static struct gendisk *disks[N_DRIVE];
|
2018-10-15 18:21:34 +03:00
|
|
|
static struct blk_mq_tag_set tag_sets[N_DRIVE];
|
2005-04-17 02:20:36 +04:00
|
|
|
static struct block_device *opened_bdev[N_DRIVE];
|
2006-03-23 14:00:26 +03:00
|
|
|
static DEFINE_MUTEX(open_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
static struct floppy_raw_cmd *raw_cmd, default_raw_cmd;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This struct defines the different floppy types.
|
|
|
|
*
|
|
|
|
* Bit 0 of 'stretch' tells if the tracks need to be doubled for some
|
|
|
|
* types (e.g. 360kB diskette in 1.2MB drive, etc.). Bit 1 of 'stretch'
|
|
|
|
* tells if the disk is in Commodore 1581 format, which means side 0 sectors
|
|
|
|
* are located on side 1 of the disk but with a side 0 ID, and vice-versa.
|
|
|
|
* This is the same as the Sharp MZ-80 5.25" CP/M disk format, except that the
|
|
|
|
* 1581's logical side 0 is on physical side 1, whereas the Sharp's logical
|
|
|
|
* side 0 is on physical side 0 (but with the misnamed sector IDs).
|
|
|
|
* 'stretch' should probably be renamed to something more general, like
|
2008-09-23 01:57:17 +04:00
|
|
|
* 'options'.
|
|
|
|
*
|
|
|
|
* Bits 2 through 9 of 'stretch' tell the number of the first sector.
|
|
|
|
* The LSB (bit 2) is flipped. For most disks, the first sector
|
|
|
|
* is 1 (represented by 0x00<<2). For some CP/M and music sampler
|
|
|
|
* disks (such as Ensoniq EPS 16plus) it is 0 (represented as 0x01<<2).
|
|
|
|
* For Amstrad CPC disks it is 0xC1 (represented as 0xC0<<2).
|
|
|
|
*
|
|
|
|
* Other parameters should be self-explanatory (see also setfdprm(8)).
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
Size
|
|
|
|
| Sectors per track
|
|
|
|
| | Head
|
|
|
|
| | | Tracks
|
|
|
|
| | | | Stretch
|
|
|
|
| | | | | Gap 1 size
|
|
|
|
| | | | | | Data rate, | 0x40 for perp
|
|
|
|
| | | | | | | Spec1 (stepping rate, head unload
|
|
|
|
| | | | | | | | /fmt gap (gap2) */
|
|
|
|
static struct floppy_struct floppy_type[32] = {
|
|
|
|
{ 0, 0,0, 0,0,0x00,0x00,0x00,0x00,NULL }, /* 0 no testing */
|
|
|
|
{ 720, 9,2,40,0,0x2A,0x02,0xDF,0x50,"d360" }, /* 1 360KB PC */
|
|
|
|
{ 2400,15,2,80,0,0x1B,0x00,0xDF,0x54,"h1200" }, /* 2 1.2MB AT */
|
|
|
|
{ 720, 9,1,80,0,0x2A,0x02,0xDF,0x50,"D360" }, /* 3 360KB SS 3.5" */
|
|
|
|
{ 1440, 9,2,80,0,0x2A,0x02,0xDF,0x50,"D720" }, /* 4 720KB 3.5" */
|
|
|
|
{ 720, 9,2,40,1,0x23,0x01,0xDF,0x50,"h360" }, /* 5 360KB AT */
|
|
|
|
{ 1440, 9,2,80,0,0x23,0x01,0xDF,0x50,"h720" }, /* 6 720KB AT */
|
|
|
|
{ 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,"H1440" }, /* 7 1.44MB 3.5" */
|
|
|
|
{ 5760,36,2,80,0,0x1B,0x43,0xAF,0x54,"E2880" }, /* 8 2.88MB 3.5" */
|
|
|
|
{ 6240,39,2,80,0,0x1B,0x43,0xAF,0x28,"E3120" }, /* 9 3.12MB 3.5" */
|
|
|
|
|
|
|
|
{ 2880,18,2,80,0,0x25,0x00,0xDF,0x02,"h1440" }, /* 10 1.44MB 5.25" */
|
|
|
|
{ 3360,21,2,80,0,0x1C,0x00,0xCF,0x0C,"H1680" }, /* 11 1.68MB 3.5" */
|
|
|
|
{ 820,10,2,41,1,0x25,0x01,0xDF,0x2E,"h410" }, /* 12 410KB 5.25" */
|
|
|
|
{ 1640,10,2,82,0,0x25,0x02,0xDF,0x2E,"H820" }, /* 13 820KB 3.5" */
|
|
|
|
{ 2952,18,2,82,0,0x25,0x00,0xDF,0x02,"h1476" }, /* 14 1.48MB 5.25" */
|
|
|
|
{ 3444,21,2,82,0,0x25,0x00,0xDF,0x0C,"H1722" }, /* 15 1.72MB 3.5" */
|
|
|
|
{ 840,10,2,42,1,0x25,0x01,0xDF,0x2E,"h420" }, /* 16 420KB 5.25" */
|
|
|
|
{ 1660,10,2,83,0,0x25,0x02,0xDF,0x2E,"H830" }, /* 17 830KB 3.5" */
|
|
|
|
{ 2988,18,2,83,0,0x25,0x00,0xDF,0x02,"h1494" }, /* 18 1.49MB 5.25" */
|
|
|
|
{ 3486,21,2,83,0,0x25,0x00,0xDF,0x0C,"H1743" }, /* 19 1.74 MB 3.5" */
|
|
|
|
|
|
|
|
{ 1760,11,2,80,0,0x1C,0x09,0xCF,0x00,"h880" }, /* 20 880KB 5.25" */
|
|
|
|
{ 2080,13,2,80,0,0x1C,0x01,0xCF,0x00,"D1040" }, /* 21 1.04MB 3.5" */
|
|
|
|
{ 2240,14,2,80,0,0x1C,0x19,0xCF,0x00,"D1120" }, /* 22 1.12MB 3.5" */
|
|
|
|
{ 3200,20,2,80,0,0x1C,0x20,0xCF,0x2C,"h1600" }, /* 23 1.6MB 5.25" */
|
|
|
|
{ 3520,22,2,80,0,0x1C,0x08,0xCF,0x2e,"H1760" }, /* 24 1.76MB 3.5" */
|
|
|
|
{ 3840,24,2,80,0,0x1C,0x20,0xCF,0x00,"H1920" }, /* 25 1.92MB 3.5" */
|
|
|
|
{ 6400,40,2,80,0,0x25,0x5B,0xCF,0x00,"E3200" }, /* 26 3.20MB 3.5" */
|
|
|
|
{ 7040,44,2,80,0,0x25,0x5B,0xCF,0x00,"E3520" }, /* 27 3.52MB 3.5" */
|
|
|
|
{ 7680,48,2,80,0,0x25,0x63,0xCF,0x00,"E3840" }, /* 28 3.84MB 3.5" */
|
|
|
|
{ 3680,23,2,80,0,0x1C,0x10,0xCF,0x00,"H1840" }, /* 29 1.84MB 3.5" */
|
2007-10-17 10:30:57 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
{ 1600,10,2,80,0,0x25,0x02,0xDF,0x2E,"D800" }, /* 30 800KB 3.5" */
|
|
|
|
{ 3200,20,2,80,0,0x1C,0x00,0xCF,0x2C,"H1600" }, /* 31 1.6MB 3.5" */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SECTSIZE (_FD_SECTSIZE(*floppy))
|
|
|
|
|
|
|
|
/* Auto-detection: Disk type used until the next media change occurs. */
|
|
|
|
static struct floppy_struct *current_type[N_DRIVE];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User-provided type information. current_type points to
|
|
|
|
* the respective entry of this array.
|
|
|
|
*/
|
|
|
|
static struct floppy_struct user_params[N_DRIVE];
|
|
|
|
|
|
|
|
static sector_t floppy_sizes[256];
|
|
|
|
|
2005-07-15 12:09:25 +04:00
|
|
|
static char floppy_device_name[] = "floppy";
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* The driver is trying to determine the correct media format
|
|
|
|
* while probing is set. rw_interrupt() clears it after a
|
|
|
|
* successful access.
|
|
|
|
*/
|
|
|
|
static int probing;
|
|
|
|
|
|
|
|
/* Synchronization of FDC access. */
|
2010-03-11 02:20:45 +03:00
|
|
|
#define FD_COMMAND_NONE -1
|
|
|
|
#define FD_COMMAND_ERROR 2
|
|
|
|
#define FD_COMMAND_OKAY 3
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
static volatile int command_status = FD_COMMAND_NONE;
|
|
|
|
static unsigned long fdc_busy;
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(fdc_wait);
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(command_done);
|
|
|
|
|
|
|
|
/* Errors during formatting are counted here. */
|
|
|
|
static int format_errors;
|
|
|
|
|
|
|
|
/* Format request descriptor. */
|
|
|
|
static struct format_descr format_req;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rate is 0 for 500kb/s, 1 for 300kbps, 2 for 250kbps
|
|
|
|
* Spec1 is 0xSH, where S is stepping rate (F=1ms, E=2ms, D=3ms etc),
|
|
|
|
* H is head unload time (1=16ms, 2=32ms, etc)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Track buffer
|
|
|
|
* Because these are written to by the DMA controller, they must
|
|
|
|
* not contain a 64k byte boundary crossing, or data will be
|
|
|
|
* corrupted/lost.
|
|
|
|
*/
|
|
|
|
static char *floppy_track_buffer;
|
|
|
|
static int max_buffer_sectors;
|
|
|
|
|
|
|
|
static int *errors;
|
2007-10-17 10:30:57 +04:00
|
|
|
typedef void (*done_f)(int);
|
2010-07-21 06:09:00 +04:00
|
|
|
static const struct cont_t {
|
2010-03-11 02:20:45 +03:00
|
|
|
void (*interrupt)(void);
|
|
|
|
/* this is called after the interrupt of the
|
|
|
|
* main command */
|
2007-10-17 10:30:57 +04:00
|
|
|
void (*redo)(void); /* this is called to retry the operation */
|
|
|
|
void (*error)(void); /* this is called to tally an error */
|
2005-04-17 02:20:36 +04:00
|
|
|
done_f done; /* this is called to say if the operation has
|
|
|
|
* succeeded/failed */
|
|
|
|
} *cont;
|
|
|
|
|
|
|
|
static void floppy_ready(void);
|
|
|
|
static void floppy_start(void);
|
|
|
|
static void process_fd_request(void);
|
|
|
|
static void recalibrate_floppy(void);
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
static void floppy_shutdown(struct work_struct *);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-02-19 01:48:36 +03:00
|
|
|
static int floppy_request_regions(int);
|
|
|
|
static void floppy_release_regions(int);
|
2005-04-17 02:20:36 +04:00
|
|
|
static int floppy_grab_irq_and_dma(void);
|
|
|
|
static void floppy_release_irq_and_dma(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The "reset" variable should be tested whenever an interrupt is scheduled,
|
|
|
|
* after the commands have been sent. This is to ensure that the driver doesn't
|
|
|
|
* get wedged when the interrupt doesn't come because of a failed command.
|
|
|
|
* reset doesn't need to be tested before sending commands, because
|
|
|
|
* output_byte is automatically disabled when reset is set.
|
|
|
|
*/
|
|
|
|
static void reset_fdc(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are global variables, as that's the easiest way to give
|
|
|
|
* information to interrupts. They are the data used for the current
|
|
|
|
* request.
|
|
|
|
*/
|
2010-03-11 02:20:45 +03:00
|
|
|
#define NO_TRACK -1
|
|
|
|
#define NEED_1_RECAL -2
|
|
|
|
#define NEED_2_RECAL -3
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
static atomic_t usage_count = ATOMIC_INIT(0);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* buffer related variables */
|
|
|
|
static int buffer_track = -1;
|
|
|
|
static int buffer_drive = -1;
|
|
|
|
static int buffer_min = -1;
|
|
|
|
static int buffer_max = -1;
|
|
|
|
|
|
|
|
/* fdc related variables, should end up in a struct */
|
|
|
|
static struct floppy_fdc_state fdc_state[N_FDC];
|
|
|
|
static int fdc; /* current fdc */
|
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
static struct workqueue_struct *floppy_wq;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static struct floppy_struct *_floppy = floppy_type;
|
|
|
|
static unsigned char current_drive;
|
|
|
|
static long current_count_sectors;
|
|
|
|
static unsigned char fsector_t; /* sector in track */
|
|
|
|
static unsigned char in_sector_offset; /* offset within physical sector,
|
|
|
|
* expressed in units of 512 bytes */
|
|
|
|
|
2010-11-08 16:44:34 +03:00
|
|
|
static inline bool drive_no_geom(int drive)
|
|
|
|
{
|
2020-02-25 00:23:46 +03:00
|
|
|
return !current_type[drive] && !ITYPE(drive_state[drive].fd_device);
|
2010-11-08 16:44:34 +03:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifndef fd_eject
|
|
|
|
static inline int fd_eject(int drive)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging
|
|
|
|
* =========
|
|
|
|
*/
|
|
|
|
#ifdef DEBUGT
|
|
|
|
static long unsigned debugtimer;
|
|
|
|
|
|
|
|
static inline void set_debugt(void)
|
|
|
|
{
|
|
|
|
debugtimer = jiffies;
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:21:09 +03:00
|
|
|
static inline void debugt(const char *func, const char *msg)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2020-02-25 00:23:48 +03:00
|
|
|
if (drive_params[current_drive].flags & DEBUGT)
|
2010-03-11 02:21:09 +03:00
|
|
|
pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void set_debugt(void) { }
|
2010-03-11 02:21:09 +03:00
|
|
|
static inline void debugt(const char *func, const char *msg) { }
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif /* DEBUGT */
|
|
|
|
|
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
static DECLARE_DELAYED_WORK(fd_timeout, floppy_shutdown);
|
2005-04-17 02:20:36 +04:00
|
|
|
static const char *timeout_message;
|
|
|
|
|
2010-03-11 02:21:06 +03:00
|
|
|
static void is_alive(const char *func, const char *message)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
/* this routine checks whether the floppy driver is "alive" */
|
2010-03-11 02:20:58 +03:00
|
|
|
if (test_bit(0, &fdc_busy) && command_status < 2 &&
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
!delayed_work_pending(&fd_timeout)) {
|
2010-03-11 02:21:06 +03:00
|
|
|
DPRINT("%s: timeout handler died. %s\n", func, message);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
static void (*do_floppy)(void) = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#define OLOGSIZE 20
|
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
static void (*lasthandler)(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
static unsigned long interruptjiffies;
|
|
|
|
static unsigned long resultjiffies;
|
|
|
|
static int resultsize;
|
|
|
|
static unsigned long lastredo;
|
|
|
|
|
|
|
|
static struct output_log {
|
|
|
|
unsigned char data;
|
|
|
|
unsigned char status;
|
|
|
|
unsigned long jiffies;
|
|
|
|
} output_log[OLOGSIZE];
|
|
|
|
|
|
|
|
static int output_log_pos;
|
|
|
|
|
|
|
|
#define current_reqD -1
|
|
|
|
#define MAXTIMEOUT -2
|
|
|
|
|
2010-03-11 02:21:03 +03:00
|
|
|
static void __reschedule_timeout(int drive, const char *message)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
unsigned long delay;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (drive == current_reqD)
|
|
|
|
drive = current_drive;
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
|
2007-05-24 00:58:15 +04:00
|
|
|
if (drive < 0 || drive >= N_DRIVE) {
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
delay = 20UL * HZ;
|
2005-04-17 02:20:36 +04:00
|
|
|
drive = 0;
|
|
|
|
} else
|
2020-02-25 00:23:45 +03:00
|
|
|
delay = drive_params[drive].timeout;
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
|
2012-08-22 00:18:24 +04:00
|
|
|
mod_delayed_work(floppy_wq, &fd_timeout, delay);
|
2020-02-25 00:23:45 +03:00
|
|
|
if (drive_params[drive].flags & FD_DEBUG)
|
2010-03-11 02:21:03 +03:00
|
|
|
DPRINT("reschedule timeout %s\n", message);
|
2005-04-17 02:20:36 +04:00
|
|
|
timeout_message = message;
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:21:03 +03:00
|
|
|
static void reschedule_timeout(int drive, const char *message)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&floppy_lock, flags);
|
2010-03-11 02:21:03 +03:00
|
|
|
__reschedule_timeout(drive, message);
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock_irqrestore(&floppy_lock, flags);
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
#define INFBOUND(a, b) (a) = max_t(int, a, b)
|
|
|
|
#define SUPBOUND(a, b) (a) = min_t(int, a, b)
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bottom half floppy driver.
|
|
|
|
* ==========================
|
|
|
|
*
|
|
|
|
* This part of the file contains the code talking directly to the hardware,
|
|
|
|
* and also the main service loop (seek-configure-spinup-command)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* disk change.
|
|
|
|
* This routine is responsible for maintaining the FD_DISK_CHANGE flag,
|
|
|
|
* and the last_checked date.
|
|
|
|
*
|
|
|
|
* last_checked is the date of the last check which showed 'no disk change'
|
|
|
|
* FD_DISK_CHANGE is set under two conditions:
|
|
|
|
* 1. The floppy has been changed after some i/o to that floppy already
|
|
|
|
* took place.
|
|
|
|
* 2. No floppy disk is in the drive. This is done in order to ensure that
|
|
|
|
* requests are quickly flushed in case there is no disk in the drive. It
|
|
|
|
* follows that FD_DISK_CHANGE can only be cleared if there is a disk in
|
|
|
|
* the drive.
|
|
|
|
*
|
|
|
|
* For 1., maxblock is observed. Maxblock is 0 if no i/o has taken place yet.
|
|
|
|
* For 2., FD_DISK_NEWCHANGE is watched. FD_DISK_NEWCHANGE is cleared on
|
|
|
|
* each seek. If a disk is present, the disk change line should also be
|
|
|
|
* cleared on each seek. Thus, if FD_DISK_NEWCHANGE is clear, but the disk
|
|
|
|
* change line is set, this means either that no disk is in the drive, or
|
|
|
|
* that it has been removed since the last seek.
|
|
|
|
*
|
|
|
|
* This means that we really have a third possibility too:
|
|
|
|
* The floppy has been changed after the last seek.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int disk_change(int drive)
|
|
|
|
{
|
|
|
|
int fdc = FDC(drive);
|
2007-10-17 10:30:57 +04:00
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
if (time_before(jiffies, drive_state[drive].select_date + drive_params[drive].select_delay))
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("WARNING disk change called early\n");
|
2020-02-25 00:23:43 +03:00
|
|
|
if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))) ||
|
|
|
|
(fdc_state[fdc].dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("probing disk change on unselected drive\n");
|
|
|
|
DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive),
|
2020-02-25 00:23:43 +03:00
|
|
|
(unsigned int)fdc_state[fdc].dor);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:45 +03:00
|
|
|
debug_dcl(drive_params[drive].flags,
|
2010-03-11 02:20:54 +03:00
|
|
|
"checking disk change line for drive %d\n", drive);
|
2020-02-25 00:23:45 +03:00
|
|
|
debug_dcl(drive_params[drive].flags, "jiffies=%lu\n", jiffies);
|
|
|
|
debug_dcl(drive_params[drive].flags, "disk change line=%x\n",
|
|
|
|
fd_inb(FD_DIR) & 0x80);
|
2020-02-25 00:23:46 +03:00
|
|
|
debug_dcl(drive_params[drive].flags, "flags=%lx\n",
|
|
|
|
drive_state[drive].flags);
|
2010-03-11 02:20:54 +03:00
|
|
|
|
2020-02-25 00:23:45 +03:00
|
|
|
if (drive_params[drive].flags & FD_BROKEN_DCL)
|
2020-02-25 00:23:46 +03:00
|
|
|
return test_bit(FD_DISK_CHANGED_BIT,
|
|
|
|
&drive_state[drive].flags);
|
2020-02-25 00:23:45 +03:00
|
|
|
if ((fd_inb(FD_DIR) ^ drive_params[drive].flags) & 0x80) {
|
2020-02-25 00:23:46 +03:00
|
|
|
set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
|
2010-03-11 02:20:55 +03:00
|
|
|
/* verify write protection */
|
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
if (drive_state[drive].maxblock) /* mark it changed */
|
|
|
|
set_bit(FD_DISK_CHANGED_BIT,
|
|
|
|
&drive_state[drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* invalidate its geometry */
|
2020-02-25 00:23:46 +03:00
|
|
|
if (drive_state[drive].keep_data >= 0) {
|
2020-02-25 00:23:45 +03:00
|
|
|
if ((drive_params[drive].flags & FTD_MSG) &&
|
2005-04-17 02:20:36 +04:00
|
|
|
current_type[drive] != NULL)
|
2010-03-11 02:21:05 +03:00
|
|
|
DPRINT("Disk type is undefined after disk change\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
current_type[drive] = NULL;
|
|
|
|
floppy_sizes[TOMINOR(drive)] = MAX_DISK_SIZE << 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
} else {
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].last_checked = jiffies;
|
|
|
|
clear_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_selected(int dor, int unit)
|
|
|
|
{
|
|
|
|
return ((dor & (0x10 << unit)) && (dor & 3) == unit);
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:21:00 +03:00
|
|
|
static bool is_ready_state(int status)
|
|
|
|
{
|
|
|
|
int state = status & (STATUS_READY | STATUS_DIR | STATUS_DMA);
|
|
|
|
return state == STATUS_READY;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static int set_dor(int fdc, char mask, char data)
|
|
|
|
{
|
2007-10-17 10:30:58 +04:00
|
|
|
unsigned char unit;
|
|
|
|
unsigned char drive;
|
|
|
|
unsigned char newdor;
|
|
|
|
unsigned char olddor;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].address == -1)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
olddor = fdc_state[fdc].dor;
|
2005-04-17 02:20:36 +04:00
|
|
|
newdor = (olddor & mask) | data;
|
|
|
|
if (newdor != olddor) {
|
|
|
|
unit = olddor & 0x3;
|
|
|
|
if (is_selected(olddor, unit) && !is_selected(newdor, unit)) {
|
|
|
|
drive = REVDRIVE(fdc, unit);
|
2020-02-25 00:23:45 +03:00
|
|
|
debug_dcl(drive_params[drive].flags,
|
2010-03-11 02:20:54 +03:00
|
|
|
"calling disk change from set_dor\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
disk_change(drive);
|
|
|
|
}
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].dor = newdor;
|
2005-04-17 02:20:36 +04:00
|
|
|
fd_outb(newdor, FD_DOR);
|
|
|
|
|
|
|
|
unit = newdor & 0x3;
|
|
|
|
if (!is_selected(olddor, unit) && is_selected(newdor, unit)) {
|
|
|
|
drive = REVDRIVE(fdc, unit);
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].select_date = jiffies;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return olddor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void twaddle(void)
|
|
|
|
{
|
2020-02-25 00:23:48 +03:00
|
|
|
if (drive_params[current_drive].select_delay)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
2020-02-25 00:23:43 +03:00
|
|
|
fd_outb(fdc_state[fdc].dor & ~(0x10 << UNIT(current_drive)), FD_DOR);
|
|
|
|
fd_outb(fdc_state[fdc].dor, FD_DOR);
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].select_date = jiffies;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-03-11 02:21:00 +03:00
|
|
|
/*
|
|
|
|
* Reset all driver information about the current fdc.
|
|
|
|
* This is needed after a reset, and after a raw command.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
static void reset_fdc_info(int mode)
|
|
|
|
{
|
|
|
|
int drive;
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].spec1 = fdc_state[fdc].spec2 = -1;
|
|
|
|
fdc_state[fdc].need_configure = 1;
|
|
|
|
fdc_state[fdc].perp_mode = 1;
|
|
|
|
fdc_state[fdc].rawcmd = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
for (drive = 0; drive < N_DRIVE; drive++)
|
2020-02-25 00:23:46 +03:00
|
|
|
if (FDC(drive) == fdc && (mode || drive_state[drive].track != NEED_1_RECAL))
|
|
|
|
drive_state[drive].track = NEED_2_RECAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* selects the fdc and drive, and enables the fdc's input/dma. */
|
|
|
|
static void set_fdc(int drive)
|
|
|
|
{
|
floppy: check FDC index for errors before assigning it
Jordy Zomer reported a KASAN out-of-bounds read in the floppy driver in
wait_til_ready().
Which on the face of it can't happen, since as Willy Tarreau points out,
the function does no particular memory access. Except through the FDCS
macro, which just indexes a static allocation through teh current fdc,
which is always checked against N_FDC.
Except the checking happens after we've already assigned the value.
The floppy driver is a disgrace (a lot of it going back to my original
horrd "design"), and has no real maintainer. Nobody has the hardware,
and nobody really cares. But it still gets used in virtual environment
because it's one of those things that everybody supports.
The whole thing should be re-written, or at least parts of it should be
seriously cleaned up. The 'current fdc' index, which is used by the
FDCS macro, and which is often shadowed by a local 'fdc' variable, is a
prime example of how not to write code.
But because nobody has the hardware or the motivation, let's just fix up
the immediate problem with a nasty band-aid: test the fdc index before
actually assigning it to the static 'fdc' variable.
Reported-by: Jordy Zomer <jordy@simplyhacker.com>
Cc: Willy Tarreau <w@1wt.eu>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-02-21 23:43:35 +03:00
|
|
|
unsigned int new_fdc = fdc;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (drive >= 0 && drive < N_DRIVE) {
|
floppy: check FDC index for errors before assigning it
Jordy Zomer reported a KASAN out-of-bounds read in the floppy driver in
wait_til_ready().
Which on the face of it can't happen, since as Willy Tarreau points out,
the function does no particular memory access. Except through the FDCS
macro, which just indexes a static allocation through teh current fdc,
which is always checked against N_FDC.
Except the checking happens after we've already assigned the value.
The floppy driver is a disgrace (a lot of it going back to my original
horrd "design"), and has no real maintainer. Nobody has the hardware,
and nobody really cares. But it still gets used in virtual environment
because it's one of those things that everybody supports.
The whole thing should be re-written, or at least parts of it should be
seriously cleaned up. The 'current fdc' index, which is used by the
FDCS macro, and which is often shadowed by a local 'fdc' variable, is a
prime example of how not to write code.
But because nobody has the hardware or the motivation, let's just fix up
the immediate problem with a nasty band-aid: test the fdc index before
actually assigning it to the static 'fdc' variable.
Reported-by: Jordy Zomer <jordy@simplyhacker.com>
Cc: Willy Tarreau <w@1wt.eu>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-02-21 23:43:35 +03:00
|
|
|
new_fdc = FDC(drive);
|
2005-04-17 02:20:36 +04:00
|
|
|
current_drive = drive;
|
|
|
|
}
|
floppy: check FDC index for errors before assigning it
Jordy Zomer reported a KASAN out-of-bounds read in the floppy driver in
wait_til_ready().
Which on the face of it can't happen, since as Willy Tarreau points out,
the function does no particular memory access. Except through the FDCS
macro, which just indexes a static allocation through teh current fdc,
which is always checked against N_FDC.
Except the checking happens after we've already assigned the value.
The floppy driver is a disgrace (a lot of it going back to my original
horrd "design"), and has no real maintainer. Nobody has the hardware,
and nobody really cares. But it still gets used in virtual environment
because it's one of those things that everybody supports.
The whole thing should be re-written, or at least parts of it should be
seriously cleaned up. The 'current fdc' index, which is used by the
FDCS macro, and which is often shadowed by a local 'fdc' variable, is a
prime example of how not to write code.
But because nobody has the hardware or the motivation, let's just fix up
the immediate problem with a nasty band-aid: test the fdc index before
actually assigning it to the static 'fdc' variable.
Reported-by: Jordy Zomer <jordy@simplyhacker.com>
Cc: Willy Tarreau <w@1wt.eu>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-02-21 23:43:35 +03:00
|
|
|
if (new_fdc >= N_FDC) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("bad fdc value\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
floppy: check FDC index for errors before assigning it
Jordy Zomer reported a KASAN out-of-bounds read in the floppy driver in
wait_til_ready().
Which on the face of it can't happen, since as Willy Tarreau points out,
the function does no particular memory access. Except through the FDCS
macro, which just indexes a static allocation through teh current fdc,
which is always checked against N_FDC.
Except the checking happens after we've already assigned the value.
The floppy driver is a disgrace (a lot of it going back to my original
horrd "design"), and has no real maintainer. Nobody has the hardware,
and nobody really cares. But it still gets used in virtual environment
because it's one of those things that everybody supports.
The whole thing should be re-written, or at least parts of it should be
seriously cleaned up. The 'current fdc' index, which is used by the
FDCS macro, and which is often shadowed by a local 'fdc' variable, is a
prime example of how not to write code.
But because nobody has the hardware or the motivation, let's just fix up
the immediate problem with a nasty band-aid: test the fdc index before
actually assigning it to the static 'fdc' variable.
Reported-by: Jordy Zomer <jordy@simplyhacker.com>
Cc: Willy Tarreau <w@1wt.eu>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-02-21 23:43:35 +03:00
|
|
|
fdc = new_fdc;
|
2005-04-17 02:20:36 +04:00
|
|
|
set_dor(fdc, ~0, 8);
|
|
|
|
#if N_FDC > 1
|
|
|
|
set_dor(1 - fdc, ~8, 0);
|
|
|
|
#endif
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].rawcmd == 2)
|
2005-04-17 02:20:36 +04:00
|
|
|
reset_fdc_info(1);
|
|
|
|
if (fd_inb(FD_STATUS) != STATUS_READY)
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* locks the driver */
|
2016-02-01 13:19:17 +03:00
|
|
|
static int lock_fdc(int drive)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2010-06-15 15:21:11 +04:00
|
|
|
if (WARN(atomic_read(&usage_count) == 0,
|
|
|
|
"Trying to lock fdc while usage count=0\n"))
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
if (wait_event_interruptible(fdc_wait, !test_and_set_bit(0, &fdc_busy)))
|
|
|
|
return -EINTR;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
command_status = FD_COMMAND_NONE;
|
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
reschedule_timeout(drive, "lock fdc");
|
2005-04-17 02:20:36 +04:00
|
|
|
set_fdc(drive);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unlocks the driver */
|
2010-06-15 15:21:11 +04:00
|
|
|
static void unlock_fdc(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
if (!test_bit(0, &fdc_busy))
|
|
|
|
DPRINT("FDC access conflict!\n");
|
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
raw_cmd = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
command_status = FD_COMMAND_NONE;
|
2012-08-22 00:18:24 +04:00
|
|
|
cancel_delayed_work(&fd_timeout);
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
do_floppy = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
cont = NULL;
|
|
|
|
clear_bit(0, &fdc_busy);
|
|
|
|
wake_up(&fdc_wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* switches the motor off after a given timeout */
|
2017-10-05 03:49:29 +03:00
|
|
|
static void motor_off_callback(struct timer_list *t)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2017-10-05 03:49:29 +03:00
|
|
|
unsigned long nr = t - motor_off_timer;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned char mask = ~(0x10 << UNIT(nr));
|
|
|
|
|
2017-10-05 03:49:29 +03:00
|
|
|
if (WARN_ON_ONCE(nr >= N_DRIVE))
|
|
|
|
return;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
set_dor(FDC(nr), mask, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* schedules motor off */
|
|
|
|
static void floppy_off(unsigned int drive)
|
|
|
|
{
|
|
|
|
unsigned long volatile delta;
|
2007-10-17 10:30:58 +04:00
|
|
|
int fdc = FDC(drive);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))))
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
del_timer(motor_off_timer + drive);
|
|
|
|
|
|
|
|
/* make spindle stop in a position which minimizes spinup time
|
|
|
|
* next time */
|
2020-02-25 00:23:45 +03:00
|
|
|
if (drive_params[drive].rps) {
|
2020-02-25 00:23:46 +03:00
|
|
|
delta = jiffies - drive_state[drive].first_read_date + HZ -
|
2020-02-25 00:23:45 +03:00
|
|
|
drive_params[drive].spindown_offset;
|
|
|
|
delta = ((delta * drive_params[drive].rps) % HZ) / drive_params[drive].rps;
|
2005-04-17 02:20:36 +04:00
|
|
|
motor_off_timer[drive].expires =
|
2020-02-25 00:23:45 +03:00
|
|
|
jiffies + drive_params[drive].spindown - delta;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
add_timer(motor_off_timer + drive);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cycle through all N_DRIVE floppy drives, for disk change testing.
|
|
|
|
* stopping at current drive. This is done before any long operation, to
|
|
|
|
* be sure to have up to date disk change information.
|
|
|
|
*/
|
|
|
|
static void scandrives(void)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
int i;
|
|
|
|
int drive;
|
|
|
|
int saved_drive;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:48 +03:00
|
|
|
if (drive_params[current_drive].select_delay)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
saved_drive = current_drive;
|
|
|
|
for (i = 0; i < N_DRIVE; i++) {
|
|
|
|
drive = (saved_drive + i + 1) % N_DRIVE;
|
2020-02-25 00:23:46 +03:00
|
|
|
if (drive_state[drive].fd_ref == 0 || drive_params[drive].select_delay != 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
continue; /* skip closed drives */
|
|
|
|
set_fdc(drive);
|
|
|
|
if (!(set_dor(fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) &
|
|
|
|
(0x10 << UNIT(drive))))
|
|
|
|
/* switch the motor off again, if it was off to
|
|
|
|
* begin with */
|
|
|
|
set_dor(fdc, ~(0x10 << UNIT(drive)), 0);
|
|
|
|
}
|
|
|
|
set_fdc(saved_drive);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void empty(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-07 19:24:48 +04:00
|
|
|
static void (*floppy_work_fn)(void);
|
|
|
|
|
|
|
|
static void floppy_work_workfn(struct work_struct *work)
|
|
|
|
{
|
|
|
|
floppy_work_fn();
|
|
|
|
}
|
|
|
|
|
|
|
|
static DECLARE_WORK(floppy_work, floppy_work_workfn);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
static void schedule_bh(void (*handler)(void))
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
WARN_ON(work_pending(&floppy_work));
|
|
|
|
|
2014-03-07 19:24:48 +04:00
|
|
|
floppy_work_fn = handler;
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
queue_work(floppy_wq, &floppy_work);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-03-07 19:24:48 +04:00
|
|
|
static void (*fd_timer_fn)(void) = NULL;
|
|
|
|
|
|
|
|
static void fd_timer_workfn(struct work_struct *work)
|
|
|
|
{
|
|
|
|
fd_timer_fn();
|
|
|
|
}
|
|
|
|
|
|
|
|
static DECLARE_DELAYED_WORK(fd_timer, fd_timer_workfn);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
static void cancel_activity(void)
|
|
|
|
{
|
|
|
|
do_floppy = NULL;
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
cancel_delayed_work_sync(&fd_timer);
|
|
|
|
cancel_work_sync(&floppy_work);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this function makes sure that the disk stays in the drive during the
|
|
|
|
* transfer */
|
2014-03-07 19:24:48 +04:00
|
|
|
static void fd_watchdog(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
|
|
|
"calling disk change from watchdog\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (disk_change(current_drive)) {
|
|
|
|
DPRINT("disk removed during i/o\n");
|
|
|
|
cancel_activity();
|
|
|
|
cont->done(0);
|
|
|
|
reset_fdc();
|
|
|
|
} else {
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
cancel_delayed_work(&fd_timer);
|
2014-03-07 19:24:48 +04:00
|
|
|
fd_timer_fn = fd_watchdog;
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
queue_delayed_work(floppy_wq, &fd_timer, HZ / 10);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void main_command_interrupt(void)
|
|
|
|
{
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
cancel_delayed_work(&fd_timer);
|
2005-04-17 02:20:36 +04:00
|
|
|
cont->interrupt();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* waits for a delay (spinup or select) to pass */
|
2014-03-07 19:24:48 +04:00
|
|
|
static int fd_wait_for_completion(unsigned long expires,
|
|
|
|
void (*function)(void))
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].reset) {
|
2005-04-17 02:20:36 +04:00
|
|
|
reset_fdc(); /* do the reset during sleep to win time
|
|
|
|
* if we don't need to sleep, it's a good
|
|
|
|
* occasion anyways */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
if (time_before(jiffies, expires)) {
|
|
|
|
cancel_delayed_work(&fd_timer);
|
2014-03-07 19:24:48 +04:00
|
|
|
fd_timer_fn = function;
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
queue_delayed_work(floppy_wq, &fd_timer, expires - jiffies);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setup_DMA(void)
|
|
|
|
{
|
|
|
|
unsigned long f;
|
|
|
|
|
|
|
|
if (raw_cmd->length == 0) {
|
|
|
|
int i;
|
|
|
|
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("zero dma transfer size:");
|
2005-04-17 02:20:36 +04:00
|
|
|
for (i = 0; i < raw_cmd->cmd_count; i++)
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_cont("%x,", raw_cmd->cmd[i]);
|
|
|
|
pr_cont("\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
cont->done(0);
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (((unsigned long)raw_cmd->kernel_data) % 512) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("non aligned address: %p\n", raw_cmd->kernel_data);
|
2005-04-17 02:20:36 +04:00
|
|
|
cont->done(0);
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
f = claim_dma_lock();
|
|
|
|
fd_disable_dma();
|
|
|
|
#ifdef fd_dma_setup
|
|
|
|
if (fd_dma_setup(raw_cmd->kernel_data, raw_cmd->length,
|
|
|
|
(raw_cmd->flags & FD_RAW_READ) ?
|
2020-02-25 00:23:43 +03:00
|
|
|
DMA_MODE_READ : DMA_MODE_WRITE, fdc_state[fdc].address) < 0) {
|
2005-04-17 02:20:36 +04:00
|
|
|
release_dma_lock(f);
|
|
|
|
cont->done(0);
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
release_dma_lock(f);
|
|
|
|
#else
|
|
|
|
fd_clear_dma_ff();
|
|
|
|
fd_cacheflush(raw_cmd->kernel_data, raw_cmd->length);
|
|
|
|
fd_set_dma_mode((raw_cmd->flags & FD_RAW_READ) ?
|
|
|
|
DMA_MODE_READ : DMA_MODE_WRITE);
|
|
|
|
fd_set_dma_addr(raw_cmd->kernel_data);
|
|
|
|
fd_set_dma_count(raw_cmd->length);
|
2020-02-25 00:23:43 +03:00
|
|
|
virtual_dma_port = fdc_state[fdc].address;
|
2005-04-17 02:20:36 +04:00
|
|
|
fd_enable_dma();
|
|
|
|
release_dma_lock(f);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_floppy(void);
|
|
|
|
|
|
|
|
/* waits until the fdc becomes ready */
|
|
|
|
static int wait_til_ready(void)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
int status;
|
|
|
|
int counter;
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].reset)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
for (counter = 0; counter < 10000; counter++) {
|
|
|
|
status = fd_inb(FD_STATUS);
|
|
|
|
if (status & STATUS_READY)
|
|
|
|
return status;
|
|
|
|
}
|
2010-03-11 02:21:00 +03:00
|
|
|
if (initialized) {
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc);
|
|
|
|
show_floppy();
|
|
|
|
}
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sends a command byte to the fdc */
|
|
|
|
static int output_byte(char byte)
|
|
|
|
{
|
2010-03-11 02:20:48 +03:00
|
|
|
int status = wait_til_ready();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:20:48 +03:00
|
|
|
if (status < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
2010-03-11 02:21:00 +03:00
|
|
|
|
|
|
|
if (is_ready_state(status)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
fd_outb(byte, FD_DATA);
|
|
|
|
output_log[output_log_pos].data = byte;
|
|
|
|
output_log[output_log_pos].status = status;
|
|
|
|
output_log[output_log_pos].jiffies = jiffies;
|
|
|
|
output_log_pos = (output_log_pos + 1) % OLOGSIZE;
|
|
|
|
return 0;
|
|
|
|
}
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2010-03-11 02:21:00 +03:00
|
|
|
if (initialized) {
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
|
|
|
|
byte, fdc, status);
|
|
|
|
show_floppy();
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* gets the response from the fdc */
|
|
|
|
static int result(void)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
int i;
|
|
|
|
int status = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_REPLIES; i++) {
|
2010-03-11 02:20:48 +03:00
|
|
|
status = wait_til_ready();
|
|
|
|
if (status < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
status &= STATUS_DIR | STATUS_READY | STATUS_BUSY | STATUS_DMA;
|
|
|
|
if ((status & ~STATUS_BUSY) == STATUS_READY) {
|
|
|
|
resultjiffies = jiffies;
|
|
|
|
resultsize = i;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
|
|
|
|
reply_buffer[i] = fd_inb(FD_DATA);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2010-03-11 02:21:00 +03:00
|
|
|
if (initialized) {
|
|
|
|
DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
|
|
|
|
fdc, status, i);
|
2005-04-17 02:20:36 +04:00
|
|
|
show_floppy();
|
|
|
|
}
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MORE_OUTPUT -2
|
|
|
|
/* does the fdc need more output? */
|
|
|
|
static int need_more_output(void)
|
|
|
|
{
|
2010-03-11 02:20:48 +03:00
|
|
|
int status = wait_til_ready();
|
2007-10-17 10:30:57 +04:00
|
|
|
|
2010-03-11 02:20:48 +03:00
|
|
|
if (status < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
2010-03-11 02:21:00 +03:00
|
|
|
|
|
|
|
if (is_ready_state(status))
|
2005-04-17 02:20:36 +04:00
|
|
|
return MORE_OUTPUT;
|
2010-03-11 02:21:00 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return result();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set perpendicular mode as required, based on data rate, if supported.
|
|
|
|
* 82077 Now tested. 1Mbps data rate only possible with 82077-1.
|
|
|
|
*/
|
2010-06-15 15:21:11 +04:00
|
|
|
static void perpendicular_mode(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned char perp_mode;
|
|
|
|
|
|
|
|
if (raw_cmd->rate & 0x40) {
|
|
|
|
switch (raw_cmd->rate & 3) {
|
|
|
|
case 0:
|
|
|
|
perp_mode = 2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
perp_mode = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DPRINT("Invalid data rate for perpendicular mode!\n");
|
|
|
|
cont->done(0);
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2010-03-11 02:20:50 +03:00
|
|
|
/*
|
|
|
|
* convenient way to return to
|
|
|
|
* redo without too much hassle
|
|
|
|
* (deep stack et al.)
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
perp_mode = 0;
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].perp_mode == perp_mode)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].version >= FDC_82077_ORIG) {
|
2005-04-17 02:20:36 +04:00
|
|
|
output_byte(FD_PERPENDICULAR);
|
|
|
|
output_byte(perp_mode);
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].perp_mode = perp_mode;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else if (perp_mode) {
|
|
|
|
DPRINT("perpendicular mode not supported by this FDC.\n");
|
|
|
|
}
|
|
|
|
} /* perpendicular_mode */
|
|
|
|
|
|
|
|
static int fifo_depth = 0xa;
|
|
|
|
static int no_fifo;
|
|
|
|
|
|
|
|
static int fdc_configure(void)
|
|
|
|
{
|
|
|
|
/* Turn on FIFO */
|
|
|
|
output_byte(FD_CONFIGURE);
|
|
|
|
if (need_more_output() != MORE_OUTPUT)
|
|
|
|
return 0;
|
|
|
|
output_byte(0);
|
|
|
|
output_byte(0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
|
|
|
|
output_byte(0); /* pre-compensation from track
|
|
|
|
0 upwards */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NOMINAL_DTR 500
|
|
|
|
|
|
|
|
/* Issue a "SPECIFY" command to set the step rate time, head unload time,
|
|
|
|
* head load time, and DMA disable flag to values needed by floppy.
|
|
|
|
*
|
|
|
|
* The value "dtr" is the data transfer rate in Kbps. It is needed
|
|
|
|
* to account for the data rate-based scaling done by the 82072 and 82077
|
|
|
|
* FDC types. This parameter is ignored for other types of FDCs (i.e.
|
|
|
|
* 8272a).
|
|
|
|
*
|
|
|
|
* Note that changing the data transfer rate has a (probably deleterious)
|
|
|
|
* effect on the parameters subject to scaling for 82072/82077 FDCs, so
|
|
|
|
* fdc_specify is called again after each data transfer rate
|
|
|
|
* change.
|
|
|
|
*
|
|
|
|
* srt: 1000 to 16000 in microseconds
|
|
|
|
* hut: 16 to 240 milliseconds
|
|
|
|
* hlt: 2 to 254 milliseconds
|
|
|
|
*
|
|
|
|
* These values are rounded up to the next highest available delay time.
|
|
|
|
*/
|
|
|
|
static void fdc_specify(void)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
unsigned char spec1;
|
|
|
|
unsigned char spec2;
|
|
|
|
unsigned long srt;
|
|
|
|
unsigned long hlt;
|
|
|
|
unsigned long hut;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long dtr = NOMINAL_DTR;
|
|
|
|
unsigned long scale_dtr = NOMINAL_DTR;
|
|
|
|
int hlt_max_code = 0x7f;
|
|
|
|
int hut_max_code = 0xf;
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].need_configure && fdc_state[fdc].version >= FDC_82072A) {
|
2005-04-17 02:20:36 +04:00
|
|
|
fdc_configure();
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].need_configure = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (raw_cmd->rate & 0x03) {
|
|
|
|
case 3:
|
|
|
|
dtr = 1000;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
dtr = 300;
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].version >= FDC_82078) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* chose the default rate table, not the one
|
|
|
|
* where 1 = 2 Mbps */
|
|
|
|
output_byte(FD_DRIVESPEC);
|
|
|
|
if (need_more_output() == MORE_OUTPUT) {
|
|
|
|
output_byte(UNIT(current_drive));
|
|
|
|
output_byte(0xc0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
dtr = 250;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].version >= FDC_82072) {
|
2005-04-17 02:20:36 +04:00
|
|
|
scale_dtr = dtr;
|
|
|
|
hlt_max_code = 0x00; /* 0==256msec*dtr0/dtr (not linear!) */
|
|
|
|
hut_max_code = 0x0; /* 0==256msec*dtr0/dtr (not linear!) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert step rate from microseconds to milliseconds and 4 bits */
|
2020-02-25 00:23:48 +03:00
|
|
|
srt = 16 - DIV_ROUND_UP(drive_params[current_drive].srt * scale_dtr / 1000,
|
|
|
|
NOMINAL_DTR);
|
2010-03-11 02:20:46 +03:00
|
|
|
if (slow_floppy)
|
2005-04-17 02:20:36 +04:00
|
|
|
srt = srt / 4;
|
2010-03-11 02:20:46 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
SUPBOUND(srt, 0xf);
|
|
|
|
INFBOUND(srt, 0);
|
|
|
|
|
2020-02-25 00:23:48 +03:00
|
|
|
hlt = DIV_ROUND_UP(drive_params[current_drive].hlt * scale_dtr / 2,
|
|
|
|
NOMINAL_DTR);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (hlt < 0x01)
|
|
|
|
hlt = 0x01;
|
|
|
|
else if (hlt > 0x7f)
|
|
|
|
hlt = hlt_max_code;
|
|
|
|
|
2020-02-25 00:23:48 +03:00
|
|
|
hut = DIV_ROUND_UP(drive_params[current_drive].hut * scale_dtr / 16,
|
|
|
|
NOMINAL_DTR);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (hut < 0x1)
|
|
|
|
hut = 0x1;
|
|
|
|
else if (hut > 0xf)
|
|
|
|
hut = hut_max_code;
|
|
|
|
|
|
|
|
spec1 = (srt << 4) | hut;
|
|
|
|
spec2 = (hlt << 1) | (use_virtual_dma & 1);
|
|
|
|
|
|
|
|
/* If these parameters did not change, just return with success */
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].spec1 != spec1 || fdc_state[fdc].spec2 != spec2) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Go ahead and set spec1 and spec2 */
|
|
|
|
output_byte(FD_SPECIFY);
|
2020-02-25 00:23:43 +03:00
|
|
|
output_byte(fdc_state[fdc].spec1 = spec1);
|
|
|
|
output_byte(fdc_state[fdc].spec2 = spec2);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
} /* fdc_specify */
|
|
|
|
|
|
|
|
/* Set the FDC's data transfer rate on behalf of the specified drive.
|
|
|
|
* NOTE: with 82072/82077 FDCs, changing the data rate requires a reissue
|
|
|
|
* of the specify command (i.e. using the fdc_specify function).
|
|
|
|
*/
|
|
|
|
static int fdc_dtr(void)
|
|
|
|
{
|
|
|
|
/* If data rate not already set to desired value, set it. */
|
2020-02-25 00:23:43 +03:00
|
|
|
if ((raw_cmd->rate & 3) == fdc_state[fdc].dtr)
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Set dtr */
|
|
|
|
fd_outb(raw_cmd->rate & 3, FD_DCR);
|
|
|
|
|
|
|
|
/* TODO: some FDC/drive combinations (C&T 82C711 with TEAC 1.2MB)
|
|
|
|
* need a stabilization period of several milliseconds to be
|
|
|
|
* enforced after data rate changes before R/W operations.
|
|
|
|
* Pause 5 msec to avoid trouble. (Needs to be 2 jiffies)
|
|
|
|
*/
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].dtr = raw_cmd->rate & 3;
|
2014-03-07 19:24:48 +04:00
|
|
|
return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready);
|
2005-04-17 02:20:36 +04:00
|
|
|
} /* fdc_dtr */
|
|
|
|
|
|
|
|
static void tell_sector(void)
|
|
|
|
{
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_cont(": track %d, head %d, sector %d, size %d",
|
|
|
|
R_TRACK, R_HEAD, R_SECTOR, R_SIZECODE);
|
2005-04-17 02:20:36 +04:00
|
|
|
} /* tell_sector */
|
|
|
|
|
2010-03-11 02:20:46 +03:00
|
|
|
static void print_errors(void)
|
|
|
|
{
|
|
|
|
DPRINT("");
|
|
|
|
if (ST0 & ST0_ECE) {
|
|
|
|
pr_cont("Recalibrate failed!");
|
|
|
|
} else if (ST2 & ST2_CRC) {
|
|
|
|
pr_cont("data CRC error");
|
|
|
|
tell_sector();
|
|
|
|
} else if (ST1 & ST1_CRC) {
|
|
|
|
pr_cont("CRC error");
|
|
|
|
tell_sector();
|
|
|
|
} else if ((ST1 & (ST1_MAM | ST1_ND)) ||
|
|
|
|
(ST2 & ST2_MAM)) {
|
|
|
|
if (!probing) {
|
|
|
|
pr_cont("sector not found");
|
|
|
|
tell_sector();
|
|
|
|
} else
|
|
|
|
pr_cont("probe failed...");
|
|
|
|
} else if (ST2 & ST2_WC) { /* seek error */
|
|
|
|
pr_cont("wrong cylinder");
|
|
|
|
} else if (ST2 & ST2_BC) { /* cylinder marked as bad */
|
|
|
|
pr_cont("bad cylinder");
|
|
|
|
} else {
|
|
|
|
pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x",
|
|
|
|
ST0, ST1, ST2);
|
|
|
|
tell_sector();
|
|
|
|
}
|
|
|
|
pr_cont("\n");
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* OK, this error interpreting routine is called after a
|
|
|
|
* DMA read/write has succeeded
|
|
|
|
* or failed, so we check the results, and copy any buffers.
|
|
|
|
* hhb: Added better error reporting.
|
|
|
|
* ak: Made this into a separate routine.
|
|
|
|
*/
|
|
|
|
static int interpret_errors(void)
|
|
|
|
{
|
|
|
|
char bad;
|
|
|
|
|
|
|
|
if (inr != 7) {
|
2010-03-11 02:21:05 +03:00
|
|
|
DPRINT("-- FDC reply error\n");
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check IC to find cause of interrupt */
|
|
|
|
switch (ST0 & ST0_INTR) {
|
|
|
|
case 0x40: /* error occurred during command execution */
|
|
|
|
if (ST1 & ST1_EOC)
|
|
|
|
return 0; /* occurs with pseudo-DMA */
|
|
|
|
bad = 1;
|
|
|
|
if (ST1 & ST1_WP) {
|
|
|
|
DPRINT("Drive is write protected\n");
|
2020-02-25 00:23:49 +03:00
|
|
|
clear_bit(FD_DISK_WRITABLE_BIT,
|
|
|
|
&drive_state[current_drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
cont->done(0);
|
|
|
|
bad = 2;
|
|
|
|
} else if (ST1 & ST1_ND) {
|
2020-02-25 00:23:49 +03:00
|
|
|
set_bit(FD_NEED_TWADDLE_BIT,
|
|
|
|
&drive_state[current_drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
} else if (ST1 & ST1_OR) {
|
2020-02-25 00:23:48 +03:00
|
|
|
if (drive_params[current_drive].flags & FTD_MSG)
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("Over/Underrun - retrying\n");
|
|
|
|
bad = 0;
|
2020-02-25 00:23:48 +03:00
|
|
|
} else if (*errors >= drive_params[current_drive].max_errors.reporting) {
|
2010-03-11 02:20:46 +03:00
|
|
|
print_errors();
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
if (ST2 & ST2_WC || ST2 & ST2_BC)
|
|
|
|
/* wrong cylinder => recal */
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].track = NEED_2_RECAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
return bad;
|
|
|
|
case 0x80: /* invalid command given */
|
|
|
|
DPRINT("Invalid FDC command given!\n");
|
|
|
|
cont->done(0);
|
|
|
|
return 2;
|
|
|
|
case 0xc0:
|
|
|
|
DPRINT("Abnormal termination caused by polling\n");
|
|
|
|
cont->error();
|
|
|
|
return 2;
|
|
|
|
default: /* (0) Normal command termination */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine is called when everything should be correctly set up
|
|
|
|
* for the transfer (i.e. floppy motor is on, the correct floppy is
|
|
|
|
* selected, and the head is sitting on the right track).
|
|
|
|
*/
|
|
|
|
static void setup_rw_floppy(void)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
int i;
|
|
|
|
int r;
|
|
|
|
int flags;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long ready_date;
|
2014-03-07 19:24:48 +04:00
|
|
|
void (*function)(void);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
flags = raw_cmd->flags;
|
|
|
|
if (flags & (FD_RAW_READ | FD_RAW_WRITE))
|
|
|
|
flags |= FD_RAW_INTR;
|
|
|
|
|
|
|
|
if ((flags & FD_RAW_SPIN) && !(flags & FD_RAW_NO_MOTOR)) {
|
2020-02-25 00:23:49 +03:00
|
|
|
ready_date = drive_state[current_drive].spinup_date + drive_params[current_drive].spinup;
|
2005-04-17 02:20:36 +04:00
|
|
|
/* If spinup will take a long time, rerun scandrives
|
|
|
|
* again just before spinup completion. Beware that
|
|
|
|
* after scandrives, we must again wait for selection.
|
|
|
|
*/
|
2020-02-25 00:23:48 +03:00
|
|
|
if (time_after(ready_date, jiffies + drive_params[current_drive].select_delay)) {
|
|
|
|
ready_date -= drive_params[current_drive].select_delay;
|
2014-03-07 19:24:48 +04:00
|
|
|
function = floppy_start;
|
2005-04-17 02:20:36 +04:00
|
|
|
} else
|
2014-03-07 19:24:48 +04:00
|
|
|
function = setup_rw_floppy;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* wait until the floppy is spinning fast enough */
|
|
|
|
if (fd_wait_for_completion(ready_date, function))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((flags & FD_RAW_READ) || (flags & FD_RAW_WRITE))
|
|
|
|
setup_DMA();
|
|
|
|
|
|
|
|
if (flags & FD_RAW_INTR)
|
|
|
|
do_floppy = main_command_interrupt;
|
|
|
|
|
|
|
|
r = 0;
|
|
|
|
for (i = 0; i < raw_cmd->cmd_count; i++)
|
|
|
|
r |= output_byte(raw_cmd->cmd[i]);
|
|
|
|
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "rw_command");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (r) {
|
|
|
|
cont->error();
|
|
|
|
reset_fdc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & FD_RAW_INTR)) {
|
|
|
|
inr = result();
|
|
|
|
cont->interrupt();
|
|
|
|
} else if (flags & FD_RAW_NEED_DISK)
|
2014-03-07 19:24:48 +04:00
|
|
|
fd_watchdog();
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int blind_seek;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the routine called after every seek (or recalibrate) interrupt
|
|
|
|
* from the floppy controller.
|
|
|
|
*/
|
|
|
|
static void seek_interrupt(void)
|
|
|
|
{
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "");
|
2005-04-17 02:20:36 +04:00
|
|
|
if (inr != 2 || (ST0 & 0xF8) != 0x20) {
|
|
|
|
DPRINT("seek failed\n");
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].track = NEED_2_RECAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
cont->error();
|
|
|
|
cont->redo();
|
|
|
|
return;
|
|
|
|
}
|
2020-02-25 00:23:49 +03:00
|
|
|
if (drive_state[current_drive].track >= 0 && drive_state[current_drive].track != ST1 && !blind_seek) {
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
2010-03-11 02:20:54 +03:00
|
|
|
"clearing NEWCHANGE flag because of effective seek\n");
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags, "jiffies=%lu\n",
|
|
|
|
jiffies);
|
2020-02-25 00:23:49 +03:00
|
|
|
clear_bit(FD_DISK_NEWCHANGE_BIT,
|
|
|
|
&drive_state[current_drive].flags);
|
2010-03-11 02:20:55 +03:00
|
|
|
/* effective seek */
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].select_date = jiffies;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].track = ST1;
|
2005-04-17 02:20:36 +04:00
|
|
|
floppy_ready();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_wp(void)
|
|
|
|
{
|
2020-02-25 00:23:49 +03:00
|
|
|
if (test_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags)) {
|
2010-03-11 02:20:55 +03:00
|
|
|
/* check write protection */
|
2005-04-17 02:20:36 +04:00
|
|
|
output_byte(FD_GETSTATUS);
|
|
|
|
output_byte(UNIT(current_drive));
|
|
|
|
if (result() != 1) {
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
2020-02-25 00:23:49 +03:00
|
|
|
clear_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags);
|
|
|
|
clear_bit(FD_NEED_TWADDLE_BIT,
|
|
|
|
&drive_state[current_drive].flags);
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
2010-03-11 02:20:54 +03:00
|
|
|
"checking whether disk is write protected\n");
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags, "wp=%x\n",
|
|
|
|
ST3 & 0x40);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!(ST3 & 0x40))
|
2020-02-25 00:23:49 +03:00
|
|
|
set_bit(FD_DISK_WRITABLE_BIT,
|
|
|
|
&drive_state[current_drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
else
|
2020-02-25 00:23:49 +03:00
|
|
|
clear_bit(FD_DISK_WRITABLE_BIT,
|
|
|
|
&drive_state[current_drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void seek_floppy(void)
|
|
|
|
{
|
|
|
|
int track;
|
|
|
|
|
|
|
|
blind_seek = 0;
|
|
|
|
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
|
|
|
"calling disk change from %s\n", __func__);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:49 +03:00
|
|
|
if (!test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
|
2005-04-17 02:20:36 +04:00
|
|
|
disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) {
|
|
|
|
/* the media changed flag should be cleared after the seek.
|
|
|
|
* If it isn't, this means that there is really no disk in
|
|
|
|
* the drive.
|
|
|
|
*/
|
2020-02-25 00:23:49 +03:00
|
|
|
set_bit(FD_DISK_CHANGED_BIT,
|
|
|
|
&drive_state[current_drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
cont->done(0);
|
|
|
|
cont->redo();
|
|
|
|
return;
|
|
|
|
}
|
2020-02-25 00:23:49 +03:00
|
|
|
if (drive_state[current_drive].track <= NEED_1_RECAL) {
|
2005-04-17 02:20:36 +04:00
|
|
|
recalibrate_floppy();
|
|
|
|
return;
|
2020-02-25 00:23:49 +03:00
|
|
|
} else if (test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
|
2005-04-17 02:20:36 +04:00
|
|
|
(raw_cmd->flags & FD_RAW_NEED_DISK) &&
|
2020-02-25 00:23:49 +03:00
|
|
|
(drive_state[current_drive].track <= NO_TRACK || drive_state[current_drive].track == raw_cmd->track)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* we seek to clear the media-changed condition. Does anybody
|
|
|
|
* know a more elegant way, which works on all drives? */
|
|
|
|
if (raw_cmd->track)
|
|
|
|
track = raw_cmd->track - 1;
|
|
|
|
else {
|
2020-02-25 00:23:48 +03:00
|
|
|
if (drive_params[current_drive].flags & FD_SILENT_DCL_CLEAR) {
|
2005-04-17 02:20:36 +04:00
|
|
|
set_dor(fdc, ~(0x10 << UNIT(current_drive)), 0);
|
|
|
|
blind_seek = 1;
|
|
|
|
raw_cmd->flags |= FD_RAW_NEED_SEEK;
|
|
|
|
}
|
|
|
|
track = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
check_wp();
|
2020-02-25 00:23:49 +03:00
|
|
|
if (raw_cmd->track != drive_state[current_drive].track &&
|
2005-04-17 02:20:36 +04:00
|
|
|
(raw_cmd->flags & FD_RAW_NEED_SEEK))
|
|
|
|
track = raw_cmd->track;
|
|
|
|
else {
|
|
|
|
setup_rw_floppy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
do_floppy = seek_interrupt;
|
|
|
|
output_byte(FD_SEEK);
|
|
|
|
output_byte(UNIT(current_drive));
|
2010-03-11 02:20:49 +03:00
|
|
|
if (output_byte(track) < 0) {
|
|
|
|
reset_fdc();
|
|
|
|
return;
|
|
|
|
}
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "");
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void recal_interrupt(void)
|
|
|
|
{
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "");
|
2005-04-17 02:20:36 +04:00
|
|
|
if (inr != 2)
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
else if (ST0 & ST0_ECE) {
|
2020-02-25 00:23:49 +03:00
|
|
|
switch (drive_state[current_drive].track) {
|
2005-04-17 02:20:36 +04:00
|
|
|
case NEED_1_RECAL:
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "need 1 recal");
|
2005-04-17 02:20:36 +04:00
|
|
|
/* after a second recalibrate, we still haven't
|
|
|
|
* reached track 0. Probably no drive. Raise an
|
|
|
|
* error, as failing immediately might upset
|
|
|
|
* computers possessed by the Devil :-) */
|
|
|
|
cont->error();
|
|
|
|
cont->redo();
|
|
|
|
return;
|
|
|
|
case NEED_2_RECAL:
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "need 2 recal");
|
2005-04-17 02:20:36 +04:00
|
|
|
/* If we already did a recalibrate,
|
|
|
|
* and we are not at track 0, this
|
|
|
|
* means we have moved. (The only way
|
|
|
|
* not to move at recalibration is to
|
|
|
|
* be already at track 0.) Clear the
|
|
|
|
* new change flag */
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
2010-03-11 02:20:54 +03:00
|
|
|
"clearing NEWCHANGE flag because of second recalibrate\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:49 +03:00
|
|
|
clear_bit(FD_DISK_NEWCHANGE_BIT,
|
|
|
|
&drive_state[current_drive].flags);
|
|
|
|
drive_state[current_drive].select_date = jiffies;
|
2005-04-17 02:20:36 +04:00
|
|
|
/* fall through */
|
|
|
|
default:
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "default");
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Recalibrate moves the head by at
|
|
|
|
* most 80 steps. If after one
|
|
|
|
* recalibrate we don't have reached
|
|
|
|
* track 0, this might mean that we
|
|
|
|
* started beyond track 80. Try
|
|
|
|
* again. */
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].track = NEED_1_RECAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].track = ST1;
|
2005-04-17 02:20:36 +04:00
|
|
|
floppy_ready();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_result(char *message, int inr)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DPRINT("%s ", message);
|
|
|
|
if (inr >= 0)
|
|
|
|
for (i = 0; i < inr; i++)
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_cont("repl[%d]=%x ", i, reply_buffer[i]);
|
|
|
|
pr_cont("\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* interrupt handler. Note that this can be called externally on the Sparc */
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
irqreturn_t floppy_interrupt(int irq, void *dev_id)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int do_print;
|
|
|
|
unsigned long f;
|
2007-10-17 10:30:57 +04:00
|
|
|
void (*handler)(void) = do_floppy;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
lasthandler = handler;
|
|
|
|
interruptjiffies = jiffies;
|
|
|
|
|
|
|
|
f = claim_dma_lock();
|
|
|
|
fd_disable_dma();
|
|
|
|
release_dma_lock(f);
|
|
|
|
|
|
|
|
do_floppy = NULL;
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc >= N_FDC || fdc_state[fdc].address == -1) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* we don't even know which FDC is the culprit */
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("DOR0=%x\n", fdc_state[0].dor);
|
|
|
|
pr_info("floppy interrupt on bizarre fdc %d\n", fdc);
|
2019-03-25 22:32:28 +03:00
|
|
|
pr_info("handler=%ps\n", handler);
|
2010-03-11 02:21:06 +03:00
|
|
|
is_alive(__func__, "bizarre fdc");
|
2005-04-17 02:20:36 +04:00
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
/* We have to clear the reset flag here, because apparently on boxes
|
|
|
|
* with level triggered interrupts (PS/2, Sparc, ...), it is needed to
|
2020-02-25 00:23:43 +03:00
|
|
|
* emit SENSEI's to clear the interrupt line. And fdc_state[fdc].reset
|
|
|
|
* blocks the emission of the SENSEI's.
|
2005-04-17 02:20:36 +04:00
|
|
|
* It is OK to emit floppy commands because we are in an interrupt
|
|
|
|
* handler here, and thus we have to fear no interference of other
|
|
|
|
* activity.
|
|
|
|
*/
|
|
|
|
|
2010-03-11 02:21:00 +03:00
|
|
|
do_print = !handler && print_unex && initialized;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
inr = result();
|
|
|
|
if (do_print)
|
|
|
|
print_result("unexpected interrupt", inr);
|
|
|
|
if (inr == 0) {
|
|
|
|
int max_sensei = 4;
|
|
|
|
do {
|
|
|
|
output_byte(FD_SENSEI);
|
|
|
|
inr = result();
|
|
|
|
if (do_print)
|
|
|
|
print_result("sensei", inr);
|
|
|
|
max_sensei--;
|
2010-03-11 02:20:58 +03:00
|
|
|
} while ((ST0 & 0x83) != UNIT(current_drive) &&
|
|
|
|
inr == 2 && max_sensei);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
if (!handler) {
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
schedule_bh(handler);
|
2010-03-11 02:21:06 +03:00
|
|
|
is_alive(__func__, "normal interrupt end");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* FIXME! Was it really for us? */
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void recalibrate_floppy(void)
|
|
|
|
{
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "");
|
2005-04-17 02:20:36 +04:00
|
|
|
do_floppy = recal_interrupt;
|
|
|
|
output_byte(FD_RECALIBRATE);
|
2010-03-11 02:21:01 +03:00
|
|
|
if (output_byte(UNIT(current_drive)) < 0)
|
2010-03-11 02:20:49 +03:00
|
|
|
reset_fdc();
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must do 4 FD_SENSEIs after reset because of ``drive polling''.
|
|
|
|
*/
|
|
|
|
static void reset_interrupt(void)
|
|
|
|
{
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "");
|
2005-04-17 02:20:36 +04:00
|
|
|
result(); /* get the status ready for set_fdc */
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].reset) {
|
2019-03-25 22:32:28 +03:00
|
|
|
pr_info("reset set in interrupt, calling %ps\n", cont->error);
|
2005-04-17 02:20:36 +04:00
|
|
|
cont->error(); /* a reset just after a reset. BAD! */
|
|
|
|
}
|
|
|
|
cont->redo();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reset is done by pulling bit 2 of DOR low for a while (old FDCs),
|
|
|
|
* or by setting the self clearing bit 7 of STATUS (newer FDCs)
|
|
|
|
*/
|
|
|
|
static void reset_fdc(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
do_floppy = reset_interrupt;
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
reset_fdc_info(0);
|
|
|
|
|
|
|
|
/* Pseudo-DMA may intercept 'reset finished' interrupt. */
|
|
|
|
/* Irrelevant for systems with true DMA (i386). */
|
|
|
|
|
|
|
|
flags = claim_dma_lock();
|
|
|
|
fd_disable_dma();
|
|
|
|
release_dma_lock(flags);
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].version >= FDC_82072A)
|
|
|
|
fd_outb(0x80 | (fdc_state[fdc].dtr & 3), FD_STATUS);
|
2005-04-17 02:20:36 +04:00
|
|
|
else {
|
2020-02-25 00:23:43 +03:00
|
|
|
fd_outb(fdc_state[fdc].dor & ~0x04, FD_DOR);
|
2005-04-17 02:20:36 +04:00
|
|
|
udelay(FD_RESET_DELAY);
|
2020-02-25 00:23:43 +03:00
|
|
|
fd_outb(fdc_state[fdc].dor, FD_DOR);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_floppy(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("\n");
|
|
|
|
pr_info("floppy driver state\n");
|
|
|
|
pr_info("-------------------\n");
|
2019-03-25 22:32:28 +03:00
|
|
|
pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%ps\n",
|
2010-03-11 02:20:46 +03:00
|
|
|
jiffies, interruptjiffies, jiffies - interruptjiffies,
|
|
|
|
lasthandler);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("timeout_message=%s\n", timeout_message);
|
|
|
|
pr_info("last output bytes:\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
for (i = 0; i < OLOGSIZE; i++)
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("%2x %2x %lu\n",
|
|
|
|
output_log[(i + output_log_pos) % OLOGSIZE].data,
|
|
|
|
output_log[(i + output_log_pos) % OLOGSIZE].status,
|
|
|
|
output_log[(i + output_log_pos) % OLOGSIZE].jiffies);
|
|
|
|
pr_info("last result at %lu\n", resultjiffies);
|
|
|
|
pr_info("last redo_fd_request at %lu\n", lastredo);
|
|
|
|
print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
|
|
|
|
reply_buffer, resultsize, true);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("status=%x\n", fd_inb(FD_STATUS));
|
|
|
|
pr_info("fdc_busy=%lu\n", fdc_busy);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (do_floppy)
|
2019-03-25 22:32:28 +03:00
|
|
|
pr_info("do_floppy=%ps\n", do_floppy);
|
2006-11-22 17:54:49 +03:00
|
|
|
if (work_pending(&floppy_work))
|
2019-03-25 22:32:28 +03:00
|
|
|
pr_info("floppy_work.func=%ps\n", floppy_work.func);
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
if (delayed_work_pending(&fd_timer))
|
|
|
|
pr_info("delayed work.function=%p expires=%ld\n",
|
|
|
|
fd_timer.work.func,
|
|
|
|
fd_timer.timer.expires - jiffies);
|
|
|
|
if (delayed_work_pending(&fd_timeout))
|
|
|
|
pr_info("timer_function=%p expires=%ld\n",
|
|
|
|
fd_timeout.work.func,
|
|
|
|
fd_timeout.timer.expires - jiffies);
|
|
|
|
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("cont=%p\n", cont);
|
|
|
|
pr_info("current_req=%p\n", current_req);
|
|
|
|
pr_info("command_status=%d\n", command_status);
|
|
|
|
pr_info("\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
static void floppy_shutdown(struct work_struct *arg)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-03-11 02:21:00 +03:00
|
|
|
if (initialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
show_floppy();
|
|
|
|
cancel_activity();
|
|
|
|
|
|
|
|
flags = claim_dma_lock();
|
|
|
|
fd_disable_dma();
|
|
|
|
release_dma_lock(flags);
|
|
|
|
|
|
|
|
/* avoid dma going to a random drive after shutdown */
|
|
|
|
|
2010-03-11 02:21:00 +03:00
|
|
|
if (initialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("floppy timeout called\n");
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (cont) {
|
|
|
|
cont->done(0);
|
|
|
|
cont->redo(); /* this will recall reset when needed */
|
|
|
|
} else {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("no cont in shutdown!\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
process_fd_request();
|
|
|
|
}
|
2010-03-11 02:21:06 +03:00
|
|
|
is_alive(__func__, "");
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* start motor, check media-changed condition and write protection */
|
2007-10-17 10:30:57 +04:00
|
|
|
static int start_motor(void (*function)(void))
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
int mask;
|
|
|
|
int data;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
mask = 0xfc;
|
|
|
|
data = UNIT(current_drive);
|
|
|
|
if (!(raw_cmd->flags & FD_RAW_NO_MOTOR)) {
|
2020-02-25 00:23:43 +03:00
|
|
|
if (!(fdc_state[fdc].dor & (0x10 << UNIT(current_drive)))) {
|
2005-04-17 02:20:36 +04:00
|
|
|
set_debugt();
|
|
|
|
/* no read since this drive is running */
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].first_read_date = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
/* note motor start time if motor is not yet running */
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].spinup_date = jiffies;
|
2005-04-17 02:20:36 +04:00
|
|
|
data |= (0x10 << UNIT(current_drive));
|
|
|
|
}
|
2020-02-25 00:23:43 +03:00
|
|
|
} else if (fdc_state[fdc].dor & (0x10 << UNIT(current_drive)))
|
2005-04-17 02:20:36 +04:00
|
|
|
mask &= ~(0x10 << UNIT(current_drive));
|
|
|
|
|
|
|
|
/* starts motor and selects floppy */
|
|
|
|
del_timer(motor_off_timer + current_drive);
|
|
|
|
set_dor(fdc, mask, data);
|
|
|
|
|
|
|
|
/* wait_for_completion also schedules reset if needed. */
|
2020-02-25 00:23:49 +03:00
|
|
|
return fd_wait_for_completion(drive_state[current_drive].select_date + drive_params[current_drive].select_delay,
|
2014-03-07 19:24:48 +04:00
|
|
|
function);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void floppy_ready(void)
|
|
|
|
{
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].reset) {
|
2010-03-11 02:20:47 +03:00
|
|
|
reset_fdc();
|
|
|
|
return;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
if (start_motor(floppy_ready))
|
|
|
|
return;
|
|
|
|
if (fdc_dtr())
|
|
|
|
return;
|
|
|
|
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
|
|
|
"calling disk change from floppy_ready\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) &&
|
2020-02-25 00:23:48 +03:00
|
|
|
disk_change(current_drive) && !drive_params[current_drive].select_delay)
|
2010-03-11 02:20:50 +03:00
|
|
|
twaddle(); /* this clears the dcl on certain
|
|
|
|
* drive/controller combinations */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#ifdef fd_chose_dma_mode
|
|
|
|
if ((raw_cmd->flags & FD_RAW_READ) || (raw_cmd->flags & FD_RAW_WRITE)) {
|
|
|
|
unsigned long flags = claim_dma_lock();
|
|
|
|
fd_chose_dma_mode(raw_cmd->kernel_data, raw_cmd->length);
|
|
|
|
release_dma_lock(flags);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (raw_cmd->flags & (FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK)) {
|
|
|
|
perpendicular_mode();
|
|
|
|
fdc_specify(); /* must be done here because of hut, hlt ... */
|
|
|
|
seek_floppy();
|
|
|
|
} else {
|
|
|
|
if ((raw_cmd->flags & FD_RAW_READ) ||
|
|
|
|
(raw_cmd->flags & FD_RAW_WRITE))
|
|
|
|
fdc_specify();
|
|
|
|
setup_rw_floppy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void floppy_start(void)
|
|
|
|
{
|
2010-03-11 02:21:03 +03:00
|
|
|
reschedule_timeout(current_reqD, "floppy start");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
scandrives();
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
|
|
|
"setting NEWCHANGE in floppy_start\n");
|
2020-02-25 00:23:49 +03:00
|
|
|
set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
floppy_ready();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ========================================================================
|
|
|
|
* here ends the bottom half. Exported routines are:
|
|
|
|
* floppy_start, floppy_off, floppy_ready, lock_fdc, unlock_fdc, set_fdc,
|
|
|
|
* start_motor, reset_fdc, reset_fdc_info, interpret_errors.
|
|
|
|
* Initialization also uses output_byte, result, set_dor, floppy_interrupt
|
|
|
|
* and set_dor.
|
|
|
|
* ========================================================================
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* General purpose continuations.
|
|
|
|
* ==============================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void do_wakeup(void)
|
|
|
|
{
|
2010-03-11 02:21:03 +03:00
|
|
|
reschedule_timeout(MAXTIMEOUT, "do wakeup");
|
2005-04-17 02:20:36 +04:00
|
|
|
cont = NULL;
|
|
|
|
command_status += 2;
|
|
|
|
wake_up(&command_done);
|
|
|
|
}
|
|
|
|
|
2010-07-21 06:09:00 +04:00
|
|
|
static const struct cont_t wakeup_cont = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.interrupt = empty,
|
|
|
|
.redo = do_wakeup,
|
|
|
|
.error = empty,
|
2007-10-17 10:30:57 +04:00
|
|
|
.done = (done_f)empty
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2010-07-21 06:09:00 +04:00
|
|
|
static const struct cont_t intr_cont = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.interrupt = empty,
|
|
|
|
.redo = process_fd_request,
|
|
|
|
.error = empty,
|
2007-10-17 10:30:57 +04:00
|
|
|
.done = (done_f)empty
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2010-03-11 02:20:58 +03:00
|
|
|
static int wait_til_done(void (*handler)(void), bool interruptible)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
schedule_bh(handler);
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
if (interruptible)
|
|
|
|
wait_event_interruptible(command_done, command_status >= 2);
|
|
|
|
else
|
|
|
|
wait_event(command_done, command_status >= 2);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (command_status < 2) {
|
|
|
|
cancel_activity();
|
|
|
|
cont = &intr_cont;
|
|
|
|
reset_fdc();
|
|
|
|
return -EINTR;
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].reset)
|
2005-04-17 02:20:36 +04:00
|
|
|
command_status = FD_COMMAND_ERROR;
|
|
|
|
if (command_status == FD_COMMAND_OKAY)
|
|
|
|
ret = 0;
|
|
|
|
else
|
|
|
|
ret = -EIO;
|
|
|
|
command_status = FD_COMMAND_NONE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void generic_done(int result)
|
|
|
|
{
|
|
|
|
command_status = result;
|
|
|
|
cont = &wakeup_cont;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void generic_success(void)
|
|
|
|
{
|
|
|
|
cont->done(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void generic_failure(void)
|
|
|
|
{
|
|
|
|
cont->done(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void success_and_wakeup(void)
|
|
|
|
{
|
|
|
|
generic_success();
|
|
|
|
cont->redo();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* formatting and rw support.
|
|
|
|
* ==========================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int next_valid_format(void)
|
|
|
|
{
|
|
|
|
int probed_format;
|
|
|
|
|
2020-02-25 00:23:49 +03:00
|
|
|
probed_format = drive_state[current_drive].probed_format;
|
2005-04-17 02:20:36 +04:00
|
|
|
while (1) {
|
2020-02-25 00:23:48 +03:00
|
|
|
if (probed_format >= 8 || !drive_params[current_drive].autodetect[probed_format]) {
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].probed_format = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2020-02-25 00:23:48 +03:00
|
|
|
if (floppy_type[drive_params[current_drive].autodetect[probed_format]].sect) {
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].probed_format = probed_format;
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
probed_format++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bad_flp_intr(void)
|
|
|
|
{
|
|
|
|
int err_count;
|
|
|
|
|
|
|
|
if (probing) {
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].probed_format++;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!next_valid_format())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
err_count = ++(*errors);
|
|
|
|
INFBOUND(DRWE->badness, err_count);
|
2020-02-25 00:23:48 +03:00
|
|
|
if (err_count > drive_params[current_drive].max_errors.abort)
|
2005-04-17 02:20:36 +04:00
|
|
|
cont->done(0);
|
2020-02-25 00:23:48 +03:00
|
|
|
if (err_count > drive_params[current_drive].max_errors.reset)
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
2020-02-25 00:23:48 +03:00
|
|
|
else if (err_count > drive_params[current_drive].max_errors.recal)
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].track = NEED_2_RECAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_floppy(int drive)
|
|
|
|
{
|
2020-02-25 00:23:46 +03:00
|
|
|
int type = ITYPE(drive_state[drive].fd_device);
|
2007-10-17 10:30:57 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (type)
|
|
|
|
_floppy = floppy_type + type;
|
|
|
|
else
|
|
|
|
_floppy = current_type[drive];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* formatting support.
|
|
|
|
* ===================
|
|
|
|
*/
|
|
|
|
static void format_interrupt(void)
|
|
|
|
{
|
|
|
|
switch (interpret_errors()) {
|
|
|
|
case 1:
|
|
|
|
cont->error();
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
cont->done(1);
|
|
|
|
}
|
|
|
|
cont->redo();
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
#define FM_MODE(x, y) ((y) & ~(((x)->rate & 0x80) >> 1))
|
2005-04-17 02:20:36 +04:00
|
|
|
#define CT(x) ((x) | 0xc0)
|
2010-03-11 02:20:45 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static void setup_format_params(int track)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
int n;
|
|
|
|
int il;
|
|
|
|
int count;
|
|
|
|
int head_shift;
|
|
|
|
int track_shift;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct fparm {
|
|
|
|
unsigned char track, head, sect, size;
|
|
|
|
} *here = (struct fparm *)floppy_track_buffer;
|
|
|
|
|
|
|
|
raw_cmd = &default_raw_cmd;
|
|
|
|
raw_cmd->track = track;
|
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
raw_cmd->flags = (FD_RAW_WRITE | FD_RAW_INTR | FD_RAW_SPIN |
|
|
|
|
FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK);
|
2005-04-17 02:20:36 +04:00
|
|
|
raw_cmd->rate = _floppy->rate & 0x43;
|
|
|
|
raw_cmd->cmd_count = NR_F;
|
|
|
|
COMMAND = FM_MODE(_floppy, FD_FORMAT);
|
|
|
|
DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head);
|
|
|
|
F_SIZECODE = FD_SIZECODE(_floppy);
|
|
|
|
F_SECT_PER_TRACK = _floppy->sect << 2 >> F_SIZECODE;
|
|
|
|
F_GAP = _floppy->fmt_gap;
|
|
|
|
F_FILL = FD_FILL_BYTE;
|
|
|
|
|
|
|
|
raw_cmd->kernel_data = floppy_track_buffer;
|
|
|
|
raw_cmd->length = 4 * F_SECT_PER_TRACK;
|
|
|
|
|
2019-07-12 21:55:20 +03:00
|
|
|
if (!F_SECT_PER_TRACK)
|
|
|
|
return;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* allow for about 30ms for data transport per track */
|
|
|
|
head_shift = (F_SECT_PER_TRACK + 5) / 6;
|
|
|
|
|
|
|
|
/* a ``cylinder'' is two tracks plus a little stepping time */
|
|
|
|
track_shift = 2 * head_shift + 3;
|
|
|
|
|
|
|
|
/* position of logical sector 1 on this track */
|
|
|
|
n = (track_shift * format_req.track + head_shift * format_req.head)
|
|
|
|
% F_SECT_PER_TRACK;
|
|
|
|
|
|
|
|
/* determine interleave */
|
|
|
|
il = 1;
|
|
|
|
if (_floppy->fmt_gap < 0x22)
|
|
|
|
il++;
|
|
|
|
|
|
|
|
/* initialize field */
|
|
|
|
for (count = 0; count < F_SECT_PER_TRACK; ++count) {
|
|
|
|
here[count].track = format_req.track;
|
|
|
|
here[count].head = format_req.head;
|
|
|
|
here[count].sect = 0;
|
|
|
|
here[count].size = F_SIZECODE;
|
|
|
|
}
|
|
|
|
/* place logical sectors */
|
|
|
|
for (count = 1; count <= F_SECT_PER_TRACK; ++count) {
|
|
|
|
here[n].sect = count;
|
|
|
|
n = (n + il) % F_SECT_PER_TRACK;
|
|
|
|
if (here[n].sect) { /* sector busy, find next free sector */
|
|
|
|
++n;
|
|
|
|
if (n >= F_SECT_PER_TRACK) {
|
|
|
|
n -= F_SECT_PER_TRACK;
|
|
|
|
while (here[n].sect)
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-23 01:57:17 +04:00
|
|
|
if (_floppy->stretch & FD_SECTBASEMASK) {
|
2005-04-17 02:20:36 +04:00
|
|
|
for (count = 0; count < F_SECT_PER_TRACK; count++)
|
2008-09-23 01:57:17 +04:00
|
|
|
here[count].sect += FD_SECTBASE(_floppy) - 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void redo_format(void)
|
|
|
|
{
|
|
|
|
buffer_track = -1;
|
|
|
|
setup_format_params(format_req.track << STRETCH(_floppy));
|
|
|
|
floppy_start();
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "queue format request");
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-07-21 06:09:00 +04:00
|
|
|
static const struct cont_t format_cont = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.interrupt = format_interrupt,
|
|
|
|
.redo = redo_format,
|
|
|
|
.error = bad_flp_intr,
|
|
|
|
.done = generic_done
|
|
|
|
};
|
|
|
|
|
|
|
|
static int do_format(int drive, struct format_descr *tmp_format_req)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
set_floppy(drive);
|
|
|
|
if (!_floppy ||
|
2020-02-25 00:23:48 +03:00
|
|
|
_floppy->track > drive_params[current_drive].tracks ||
|
2005-04-17 02:20:36 +04:00
|
|
|
tmp_format_req->track >= _floppy->track ||
|
|
|
|
tmp_format_req->head >= _floppy->head ||
|
|
|
|
(_floppy->sect << 2) % (1 << FD_SIZECODE(_floppy)) ||
|
|
|
|
!_floppy->fmt_gap) {
|
|
|
|
process_fd_request();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
format_req = *tmp_format_req;
|
|
|
|
format_errors = 0;
|
|
|
|
cont = &format_cont;
|
|
|
|
errors = &format_errors;
|
2010-03-11 02:20:58 +03:00
|
|
|
ret = wait_til_done(redo_format, true);
|
2010-03-11 02:20:57 +03:00
|
|
|
if (ret == -EINTR)
|
|
|
|
return -EINTR;
|
2005-04-17 02:20:36 +04:00
|
|
|
process_fd_request();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Buffer read/write and support
|
|
|
|
* =============================
|
|
|
|
*/
|
|
|
|
|
2017-06-03 10:38:04 +03:00
|
|
|
static void floppy_end_request(struct request *req, blk_status_t error)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int nr_sectors = current_count_sectors;
|
2008-01-28 12:36:21 +03:00
|
|
|
unsigned int drive = (unsigned long)req->rq_disk->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* current_count_sectors can be zero if transfer failed */
|
2008-01-28 12:36:21 +03:00
|
|
|
if (error)
|
2009-05-07 17:24:39 +04:00
|
|
|
nr_sectors = blk_rq_cur_sectors(req);
|
2018-10-15 18:21:34 +03:00
|
|
|
if (blk_update_request(req, error, nr_sectors << 9))
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
2018-10-15 18:21:34 +03:00
|
|
|
__blk_mq_end_request(req, error);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* We're done with the request */
|
2008-01-28 12:36:21 +03:00
|
|
|
floppy_off(drive);
|
2005-04-17 02:20:36 +04:00
|
|
|
current_req = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* new request_done. Can handle physical sectors which are smaller than a
|
|
|
|
* logical buffer */
|
|
|
|
static void request_done(int uptodate)
|
|
|
|
{
|
|
|
|
struct request *req = current_req;
|
|
|
|
int block;
|
2010-03-11 02:21:03 +03:00
|
|
|
char msg[sizeof("request done ") + sizeof(int) * 3];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
probing = 0;
|
2010-03-11 02:21:03 +03:00
|
|
|
snprintf(msg, sizeof(msg), "request done %d", uptodate);
|
|
|
|
reschedule_timeout(MAXTIMEOUT, msg);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!req) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("floppy.c: no request in request_done\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uptodate) {
|
|
|
|
/* maintain values for invalidation on geometry
|
|
|
|
* change */
|
2009-05-07 17:24:39 +04:00
|
|
|
block = current_count_sectors + blk_rq_pos(req);
|
2020-02-25 00:23:49 +03:00
|
|
|
INFBOUND(drive_state[current_drive].maxblock, block);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (block > _floppy->sect)
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].maxtrack = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-01-28 12:36:21 +03:00
|
|
|
floppy_end_request(req, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
if (rq_data_dir(req) == WRITE) {
|
|
|
|
/* record write error information */
|
|
|
|
DRWE->write_errors++;
|
|
|
|
if (DRWE->write_errors == 1) {
|
2009-05-07 17:24:39 +04:00
|
|
|
DRWE->first_error_sector = blk_rq_pos(req);
|
2020-02-25 00:23:49 +03:00
|
|
|
DRWE->first_error_generation = drive_state[current_drive].generation;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2009-05-07 17:24:39 +04:00
|
|
|
DRWE->last_error_sector = blk_rq_pos(req);
|
2020-02-25 00:23:49 +03:00
|
|
|
DRWE->last_error_generation = drive_state[current_drive].generation;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2017-06-03 10:38:04 +03:00
|
|
|
floppy_end_request(req, BLK_STS_IOERR);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interrupt handler evaluating the result of the r/w operation */
|
|
|
|
static void rw_interrupt(void)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
int eoc;
|
|
|
|
int ssize;
|
|
|
|
int heads;
|
|
|
|
int nr_sectors;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (R_HEAD >= 2) {
|
|
|
|
/* some Toshiba floppy controllers occasionnally seem to
|
|
|
|
* return bogus interrupts after read/write operations, which
|
|
|
|
* can be recognized by a bad head number (>= 2) */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:49 +03:00
|
|
|
if (!drive_state[current_drive].first_read_date)
|
|
|
|
drive_state[current_drive].first_read_date = jiffies;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
nr_sectors = 0;
|
2010-03-11 02:21:10 +03:00
|
|
|
ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (ST1 & ST1_EOC)
|
|
|
|
eoc = 1;
|
|
|
|
else
|
|
|
|
eoc = 0;
|
|
|
|
|
|
|
|
if (COMMAND & 0x80)
|
|
|
|
heads = 2;
|
|
|
|
else
|
|
|
|
heads = 1;
|
|
|
|
|
|
|
|
nr_sectors = (((R_TRACK - TRACK) * heads +
|
|
|
|
R_HEAD - HEAD) * SECT_PER_TRACK +
|
|
|
|
R_SECTOR - SECTOR + eoc) << SIZECODE >> 2;
|
|
|
|
|
|
|
|
if (nr_sectors / ssize >
|
2008-09-23 01:57:16 +04:00
|
|
|
DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("long rw: %x instead of %lx\n",
|
|
|
|
nr_sectors, current_count_sectors);
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("rs=%d s=%d\n", R_SECTOR, SECTOR);
|
|
|
|
pr_info("rh=%d h=%d\n", R_HEAD, HEAD);
|
|
|
|
pr_info("rt=%d t=%d\n", R_TRACK, TRACK);
|
|
|
|
pr_info("heads=%d eoc=%d\n", heads, eoc);
|
|
|
|
pr_info("spt=%d st=%d ss=%d\n",
|
|
|
|
SECT_PER_TRACK, fsector_t, ssize);
|
|
|
|
pr_info("in_sector_offset=%d\n", in_sector_offset);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nr_sectors -= in_sector_offset;
|
|
|
|
INFBOUND(nr_sectors, 0);
|
|
|
|
SUPBOUND(current_count_sectors, nr_sectors);
|
|
|
|
|
|
|
|
switch (interpret_errors()) {
|
|
|
|
case 2:
|
|
|
|
cont->redo();
|
|
|
|
return;
|
|
|
|
case 1:
|
|
|
|
if (!current_count_sectors) {
|
|
|
|
cont->error();
|
|
|
|
cont->redo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (!current_count_sectors) {
|
|
|
|
cont->redo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
current_type[current_drive] = _floppy;
|
|
|
|
floppy_sizes[TOMINOR(current_drive)] = _floppy->size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (probing) {
|
2020-02-25 00:23:48 +03:00
|
|
|
if (drive_params[current_drive].flags & FTD_MSG)
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("Auto-detected floppy type %s in fd%d\n",
|
|
|
|
_floppy->name, current_drive);
|
|
|
|
current_type[current_drive] = _floppy;
|
|
|
|
floppy_sizes[TOMINOR(current_drive)] = _floppy->size;
|
|
|
|
probing = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CT(COMMAND) != FD_READ ||
|
2014-04-10 19:46:28 +04:00
|
|
|
raw_cmd->kernel_data == bio_data(current_req->bio)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* transfer directly from buffer */
|
|
|
|
cont->done(1);
|
|
|
|
} else if (CT(COMMAND) == FD_READ) {
|
|
|
|
buffer_track = raw_cmd->track;
|
|
|
|
buffer_drive = current_drive;
|
|
|
|
INFBOUND(buffer_max, nr_sectors + fsector_t);
|
|
|
|
}
|
|
|
|
cont->redo();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute maximal contiguous buffer size. */
|
|
|
|
static int buffer_chain_size(void)
|
|
|
|
{
|
2013-11-24 05:19:00 +04:00
|
|
|
struct bio_vec bv;
|
2007-09-25 14:35:59 +04:00
|
|
|
int size;
|
|
|
|
struct req_iterator iter;
|
2005-04-17 02:20:36 +04:00
|
|
|
char *base;
|
|
|
|
|
|
|
|
base = bio_data(current_req->bio);
|
|
|
|
size = 0;
|
|
|
|
|
2007-09-25 14:35:59 +04:00
|
|
|
rq_for_each_segment(bv, current_req, iter) {
|
2013-11-24 05:19:00 +04:00
|
|
|
if (page_address(bv.bv_page) + bv.bv_offset != base + size)
|
2007-09-25 14:35:59 +04:00
|
|
|
break;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-11-24 05:19:00 +04:00
|
|
|
size += bv.bv_len;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return size >> 9;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the maximal transfer size */
|
|
|
|
static int transfer_size(int ssize, int max_sector, int max_size)
|
|
|
|
{
|
|
|
|
SUPBOUND(max_sector, fsector_t + max_size);
|
|
|
|
|
|
|
|
/* alignment */
|
|
|
|
max_sector -= (max_sector % _floppy->sect) % ssize;
|
|
|
|
|
|
|
|
/* transfer size, beginning not aligned */
|
|
|
|
current_count_sectors = max_sector - fsector_t;
|
|
|
|
|
|
|
|
return max_sector;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move data from/to the track buffer to/from the buffer cache.
|
|
|
|
*/
|
|
|
|
static void copy_buffer(int ssize, int max_sector, int max_sector_2)
|
|
|
|
{
|
|
|
|
int remaining; /* number of transferred 512-byte sectors */
|
2013-11-24 05:19:00 +04:00
|
|
|
struct bio_vec bv;
|
2007-10-17 10:30:57 +04:00
|
|
|
char *buffer;
|
|
|
|
char *dma_buffer;
|
2007-09-25 14:35:59 +04:00
|
|
|
int size;
|
|
|
|
struct req_iterator iter;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
max_sector = transfer_size(ssize,
|
|
|
|
min(max_sector, max_sector_2),
|
2009-05-07 17:24:39 +04:00
|
|
|
blk_rq_sectors(current_req));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE &&
|
2009-05-07 17:24:39 +04:00
|
|
|
buffer_max > fsector_t + blk_rq_sectors(current_req))
|
2005-04-17 02:20:36 +04:00
|
|
|
current_count_sectors = min_t(int, buffer_max - fsector_t,
|
2009-05-07 17:24:39 +04:00
|
|
|
blk_rq_sectors(current_req));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
remaining = current_count_sectors << 9;
|
2009-05-07 17:24:45 +04:00
|
|
|
if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) {
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("in copy buffer\n");
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("current_count_sectors=%ld\n", current_count_sectors);
|
|
|
|
pr_info("remaining=%d\n", remaining >> 9);
|
|
|
|
pr_info("current_req->nr_sectors=%u\n",
|
|
|
|
blk_rq_sectors(current_req));
|
|
|
|
pr_info("current_req->current_nr_sectors=%u\n",
|
|
|
|
blk_rq_cur_sectors(current_req));
|
|
|
|
pr_info("max_sector=%d\n", max_sector);
|
|
|
|
pr_info("ssize=%d\n", ssize);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
buffer_max = max(max_sector, buffer_max);
|
|
|
|
|
|
|
|
dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9);
|
|
|
|
|
2009-05-07 17:24:45 +04:00
|
|
|
size = blk_rq_cur_bytes(current_req);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-09-25 14:35:59 +04:00
|
|
|
rq_for_each_segment(bv, current_req, iter) {
|
|
|
|
if (!remaining)
|
|
|
|
break;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-11-24 05:19:00 +04:00
|
|
|
size = bv.bv_len;
|
2007-09-25 14:35:59 +04:00
|
|
|
SUPBOUND(size, remaining);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-11-24 05:19:00 +04:00
|
|
|
buffer = page_address(bv.bv_page) + bv.bv_offset;
|
2007-09-25 14:35:59 +04:00
|
|
|
if (dma_buffer + size >
|
|
|
|
floppy_track_buffer + (max_buffer_sectors << 10) ||
|
|
|
|
dma_buffer < floppy_track_buffer) {
|
|
|
|
DPRINT("buffer overrun in copy buffer %d\n",
|
2010-03-11 02:20:46 +03:00
|
|
|
(int)((floppy_track_buffer - dma_buffer) >> 9));
|
|
|
|
pr_info("fsector_t=%d buffer_min=%d\n",
|
|
|
|
fsector_t, buffer_min);
|
|
|
|
pr_info("current_count_sectors=%ld\n",
|
|
|
|
current_count_sectors);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (CT(COMMAND) == FD_READ)
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("read\n");
|
2007-09-25 14:35:59 +04:00
|
|
|
if (CT(COMMAND) == FD_WRITE)
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("write\n");
|
2007-09-25 14:35:59 +04:00
|
|
|
break;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2007-09-25 14:35:59 +04:00
|
|
|
if (((unsigned long)buffer) % 512)
|
|
|
|
DPRINT("%p buffer not aligned\n", buffer);
|
2010-03-11 02:21:04 +03:00
|
|
|
|
2007-09-25 14:35:59 +04:00
|
|
|
if (CT(COMMAND) == FD_READ)
|
|
|
|
memcpy(buffer, dma_buffer, size);
|
|
|
|
else
|
|
|
|
memcpy(dma_buffer, buffer, size);
|
|
|
|
|
|
|
|
remaining -= size;
|
|
|
|
dma_buffer += size;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
if (remaining) {
|
|
|
|
if (remaining > 0)
|
|
|
|
max_sector -= remaining >> 9;
|
|
|
|
DPRINT("weirdness: remaining %d\n", remaining >> 9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* work around a bug in pseudo DMA
|
|
|
|
* (on some FDCs) pseudo DMA does not stop when the CPU stops
|
|
|
|
* sending data. Hence we need a different way to signal the
|
|
|
|
* transfer length: We use SECT_PER_TRACK. Unfortunately, this
|
|
|
|
* does not work with MT, hence we can only transfer one head at
|
|
|
|
* a time
|
|
|
|
*/
|
|
|
|
static void virtualdmabug_workaround(void)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
int hard_sectors;
|
|
|
|
int end_sector;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (CT(COMMAND) == FD_WRITE) {
|
|
|
|
COMMAND &= ~0x80; /* switch off multiple track mode */
|
|
|
|
|
|
|
|
hard_sectors = raw_cmd->length >> (7 + SIZECODE);
|
|
|
|
end_sector = SECTOR + hard_sectors - 1;
|
|
|
|
if (end_sector > SECT_PER_TRACK) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("too many sectors %d > %d\n",
|
|
|
|
end_sector, SECT_PER_TRACK);
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-03-11 02:20:45 +03:00
|
|
|
SECT_PER_TRACK = end_sector;
|
|
|
|
/* make sure SECT_PER_TRACK
|
|
|
|
* points to end of transfer */
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Formulate a read/write request.
|
|
|
|
* this routine decides where to load the data (directly to buffer, or to
|
|
|
|
* tmp floppy area), how much data to load (the size of the buffer, the whole
|
|
|
|
* track, or a single sector)
|
|
|
|
* All floppy_track_buffer handling goes in here. If we ever add track buffer
|
|
|
|
* allocation on the fly, it should be done here. No other part should need
|
|
|
|
* modification.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int make_raw_rw_request(void)
|
|
|
|
{
|
|
|
|
int aligned_sector_t;
|
2007-10-17 10:30:57 +04:00
|
|
|
int max_sector;
|
|
|
|
int max_size;
|
|
|
|
int tracksize;
|
|
|
|
int ssize;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
if (WARN(max_buffer_sectors == 0, "VFS: Block I/O scheduled on unopened device\n"))
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
set_fdc((long)current_req->rq_disk->private_data);
|
|
|
|
|
|
|
|
raw_cmd = &default_raw_cmd;
|
2012-07-28 15:45:59 +04:00
|
|
|
raw_cmd->flags = FD_RAW_SPIN | FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK;
|
2005-04-17 02:20:36 +04:00
|
|
|
raw_cmd->cmd_count = NR_RW;
|
|
|
|
if (rq_data_dir(current_req) == READ) {
|
|
|
|
raw_cmd->flags |= FD_RAW_READ;
|
|
|
|
COMMAND = FM_MODE(_floppy, FD_READ);
|
|
|
|
} else if (rq_data_dir(current_req) == WRITE) {
|
|
|
|
raw_cmd->flags |= FD_RAW_WRITE;
|
|
|
|
COMMAND = FM_MODE(_floppy, FD_WRITE);
|
|
|
|
} else {
|
2010-03-11 02:21:06 +03:00
|
|
|
DPRINT("%s: unknown command\n", __func__);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_sector = _floppy->sect * _floppy->head;
|
|
|
|
|
2009-05-07 17:24:39 +04:00
|
|
|
TRACK = (int)blk_rq_pos(current_req) / max_sector;
|
|
|
|
fsector_t = (int)blk_rq_pos(current_req) % max_sector;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (_floppy->track && TRACK >= _floppy->track) {
|
2009-05-07 17:24:39 +04:00
|
|
|
if (blk_rq_cur_sectors(current_req) & 1) {
|
2005-04-17 02:20:36 +04:00
|
|
|
current_count_sectors = 1;
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
HEAD = fsector_t / _floppy->sect;
|
|
|
|
|
2008-09-23 01:57:17 +04:00
|
|
|
if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) ||
|
2020-02-25 00:23:49 +03:00
|
|
|
test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) &&
|
2010-03-11 02:20:55 +03:00
|
|
|
fsector_t < _floppy->sect)
|
2005-04-17 02:20:36 +04:00
|
|
|
max_sector = _floppy->sect;
|
|
|
|
|
|
|
|
/* 2M disks have phantom sectors on the first track */
|
|
|
|
if ((_floppy->rate & FD_2M) && (!TRACK) && (!HEAD)) {
|
|
|
|
max_sector = 2 * _floppy->sect / 3;
|
|
|
|
if (fsector_t >= max_sector) {
|
|
|
|
current_count_sectors =
|
|
|
|
min_t(int, _floppy->sect - fsector_t,
|
2009-05-07 17:24:39 +04:00
|
|
|
blk_rq_sectors(current_req));
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
SIZECODE = 2;
|
|
|
|
} else
|
|
|
|
SIZECODE = FD_SIZECODE(_floppy);
|
|
|
|
raw_cmd->rate = _floppy->rate & 0x43;
|
|
|
|
if ((_floppy->rate & FD_2M) && (TRACK || HEAD) && raw_cmd->rate == 2)
|
|
|
|
raw_cmd->rate = 1;
|
|
|
|
|
|
|
|
if (SIZECODE)
|
|
|
|
SIZECODE2 = 0xff;
|
|
|
|
else
|
|
|
|
SIZECODE2 = 0x80;
|
|
|
|
raw_cmd->track = TRACK << STRETCH(_floppy);
|
|
|
|
DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, HEAD);
|
|
|
|
GAP = _floppy->gap;
|
2010-03-11 02:21:10 +03:00
|
|
|
ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
|
2005-04-17 02:20:36 +04:00
|
|
|
SECT_PER_TRACK = _floppy->sect << 2 >> SIZECODE;
|
|
|
|
SECTOR = ((fsector_t % _floppy->sect) << 2 >> SIZECODE) +
|
2008-09-23 01:57:17 +04:00
|
|
|
FD_SECTBASE(_floppy);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* tracksize describes the size which can be filled up with sectors
|
|
|
|
* of size ssize.
|
|
|
|
*/
|
|
|
|
tracksize = _floppy->sect - _floppy->sect % ssize;
|
|
|
|
if (tracksize < _floppy->sect) {
|
|
|
|
SECT_PER_TRACK++;
|
|
|
|
if (tracksize <= fsector_t % _floppy->sect)
|
|
|
|
SECTOR--;
|
|
|
|
|
|
|
|
/* if we are beyond tracksize, fill up using smaller sectors */
|
|
|
|
while (tracksize <= fsector_t % _floppy->sect) {
|
|
|
|
while (tracksize + ssize > _floppy->sect) {
|
|
|
|
SIZECODE--;
|
|
|
|
ssize >>= 1;
|
|
|
|
}
|
|
|
|
SECTOR++;
|
|
|
|
SECT_PER_TRACK++;
|
|
|
|
tracksize += ssize;
|
|
|
|
}
|
|
|
|
max_sector = HEAD * _floppy->sect + tracksize;
|
|
|
|
} else if (!TRACK && !HEAD && !(_floppy->rate & FD_2M) && probing) {
|
|
|
|
max_sector = _floppy->sect;
|
|
|
|
} else if (!HEAD && CT(COMMAND) == FD_WRITE) {
|
|
|
|
/* for virtual DMA bug workaround */
|
|
|
|
max_sector = _floppy->sect;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_sector_offset = (fsector_t % _floppy->sect) % ssize;
|
|
|
|
aligned_sector_t = fsector_t - in_sector_offset;
|
2009-05-07 17:24:39 +04:00
|
|
|
max_size = blk_rq_sectors(current_req);
|
2005-04-17 02:20:36 +04:00
|
|
|
if ((raw_cmd->track == buffer_track) &&
|
|
|
|
(current_drive == buffer_drive) &&
|
|
|
|
(fsector_t >= buffer_min) && (fsector_t < buffer_max)) {
|
|
|
|
/* data already in track buffer */
|
|
|
|
if (CT(COMMAND) == FD_READ) {
|
|
|
|
copy_buffer(1, max_sector, buffer_max);
|
|
|
|
return 1;
|
|
|
|
}
|
2009-05-07 17:24:39 +04:00
|
|
|
} else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) {
|
2005-04-17 02:20:36 +04:00
|
|
|
if (CT(COMMAND) == FD_WRITE) {
|
2010-03-11 02:20:48 +03:00
|
|
|
unsigned int sectors;
|
|
|
|
|
|
|
|
sectors = fsector_t + blk_rq_sectors(current_req);
|
|
|
|
if (sectors > ssize && sectors < ssize + ssize)
|
2005-04-17 02:20:36 +04:00
|
|
|
max_size = ssize + ssize;
|
|
|
|
else
|
|
|
|
max_size = ssize;
|
|
|
|
}
|
|
|
|
raw_cmd->flags &= ~FD_RAW_WRITE;
|
|
|
|
raw_cmd->flags |= FD_RAW_READ;
|
|
|
|
COMMAND = FM_MODE(_floppy, FD_READ);
|
2014-04-10 19:46:28 +04:00
|
|
|
} else if ((unsigned long)bio_data(current_req->bio) < MAX_DMA_ADDRESS) {
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long dma_limit;
|
|
|
|
int direct, indirect;
|
|
|
|
|
|
|
|
indirect =
|
|
|
|
transfer_size(ssize, max_sector,
|
|
|
|
max_buffer_sectors * 2) - fsector_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do NOT use minimum() here---MAX_DMA_ADDRESS is 64 bits wide
|
|
|
|
* on a 64 bit machine!
|
|
|
|
*/
|
|
|
|
max_size = buffer_chain_size();
|
2010-03-11 02:20:48 +03:00
|
|
|
dma_limit = (MAX_DMA_ADDRESS -
|
2014-04-10 19:46:28 +04:00
|
|
|
((unsigned long)bio_data(current_req->bio))) >> 9;
|
2010-03-11 02:20:46 +03:00
|
|
|
if ((unsigned long)max_size > dma_limit)
|
2005-04-17 02:20:36 +04:00
|
|
|
max_size = dma_limit;
|
|
|
|
/* 64 kb boundaries */
|
2014-04-10 19:46:28 +04:00
|
|
|
if (CROSS_64KB(bio_data(current_req->bio), max_size << 9))
|
2005-04-17 02:20:36 +04:00
|
|
|
max_size = (K_64 -
|
2014-04-10 19:46:28 +04:00
|
|
|
((unsigned long)bio_data(current_req->bio)) %
|
2005-04-17 02:20:36 +04:00
|
|
|
K_64) >> 9;
|
|
|
|
direct = transfer_size(ssize, max_sector, max_size) - fsector_t;
|
|
|
|
/*
|
|
|
|
* We try to read tracks, but if we get too many errors, we
|
|
|
|
* go back to reading just one sector at a time.
|
|
|
|
*
|
|
|
|
* This means we should be able to read a sector even if there
|
|
|
|
* are other bad sectors on this track.
|
|
|
|
*/
|
|
|
|
if (!direct ||
|
|
|
|
(indirect * 2 > direct * 3 &&
|
2020-02-25 00:23:48 +03:00
|
|
|
*errors < drive_params[current_drive].max_errors.read_track &&
|
2010-03-11 02:20:48 +03:00
|
|
|
((!probing ||
|
2020-02-25 00:23:49 +03:00
|
|
|
(drive_params[current_drive].read_track & (1 << drive_state[current_drive].probed_format)))))) {
|
2009-05-07 17:24:39 +04:00
|
|
|
max_size = blk_rq_sectors(current_req);
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
2014-04-10 19:46:28 +04:00
|
|
|
raw_cmd->kernel_data = bio_data(current_req->bio);
|
2005-04-17 02:20:36 +04:00
|
|
|
raw_cmd->length = current_count_sectors << 9;
|
|
|
|
if (raw_cmd->length == 0) {
|
2010-03-11 02:21:06 +03:00
|
|
|
DPRINT("%s: zero dma transfer attempted\n", __func__);
|
2010-03-11 02:20:48 +03:00
|
|
|
DPRINT("indirect=%d direct=%d fsector_t=%d\n",
|
2005-04-17 02:20:36 +04:00
|
|
|
indirect, direct, fsector_t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
virtualdmabug_workaround();
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CT(COMMAND) == FD_READ)
|
|
|
|
max_size = max_sector; /* unbounded */
|
|
|
|
|
|
|
|
/* claim buffer track if needed */
|
|
|
|
if (buffer_track != raw_cmd->track || /* bad track */
|
|
|
|
buffer_drive != current_drive || /* bad drive */
|
|
|
|
fsector_t > buffer_max ||
|
|
|
|
fsector_t < buffer_min ||
|
|
|
|
((CT(COMMAND) == FD_READ ||
|
2009-05-07 17:24:39 +04:00
|
|
|
(!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) &&
|
2005-04-17 02:20:36 +04:00
|
|
|
max_sector > 2 * max_buffer_sectors + buffer_min &&
|
2010-03-11 02:20:50 +03:00
|
|
|
max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)) {
|
|
|
|
/* not enough space */
|
2005-04-17 02:20:36 +04:00
|
|
|
buffer_track = -1;
|
|
|
|
buffer_drive = current_drive;
|
|
|
|
buffer_max = buffer_min = aligned_sector_t;
|
|
|
|
}
|
|
|
|
raw_cmd->kernel_data = floppy_track_buffer +
|
2010-03-11 02:20:50 +03:00
|
|
|
((aligned_sector_t - buffer_min) << 9);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (CT(COMMAND) == FD_WRITE) {
|
|
|
|
/* copy write buffer to track buffer.
|
|
|
|
* if we get here, we know that the write
|
|
|
|
* is either aligned or the data already in the buffer
|
|
|
|
* (buffer will be overwritten) */
|
|
|
|
if (in_sector_offset && buffer_track == -1)
|
|
|
|
DPRINT("internal error offset !=0 on write\n");
|
|
|
|
buffer_track = raw_cmd->track;
|
|
|
|
buffer_drive = current_drive;
|
|
|
|
copy_buffer(ssize, max_sector,
|
|
|
|
2 * max_buffer_sectors + buffer_min);
|
|
|
|
} else
|
|
|
|
transfer_size(ssize, max_sector,
|
|
|
|
2 * max_buffer_sectors + buffer_min -
|
|
|
|
aligned_sector_t);
|
|
|
|
|
|
|
|
/* round up current_count_sectors to get dma xfer size */
|
|
|
|
raw_cmd->length = in_sector_offset + current_count_sectors;
|
|
|
|
raw_cmd->length = ((raw_cmd->length - 1) | (ssize - 1)) + 1;
|
|
|
|
raw_cmd->length <<= 9;
|
|
|
|
if ((raw_cmd->length < current_count_sectors << 9) ||
|
2014-04-10 19:46:28 +04:00
|
|
|
(raw_cmd->kernel_data != bio_data(current_req->bio) &&
|
2005-04-17 02:20:36 +04:00
|
|
|
CT(COMMAND) == FD_WRITE &&
|
|
|
|
(aligned_sector_t + (raw_cmd->length >> 9) > buffer_max ||
|
|
|
|
aligned_sector_t < buffer_min)) ||
|
|
|
|
raw_cmd->length % (128 << SIZECODE) ||
|
|
|
|
raw_cmd->length <= 0 || current_count_sectors <= 0) {
|
|
|
|
DPRINT("fractionary current count b=%lx s=%lx\n",
|
|
|
|
raw_cmd->length, current_count_sectors);
|
2014-04-10 19:46:28 +04:00
|
|
|
if (raw_cmd->kernel_data != bio_data(current_req->bio))
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("addr=%d, length=%ld\n",
|
|
|
|
(int)((raw_cmd->kernel_data -
|
|
|
|
floppy_track_buffer) >> 9),
|
|
|
|
current_count_sectors);
|
|
|
|
pr_info("st=%d ast=%d mse=%d msi=%d\n",
|
|
|
|
fsector_t, aligned_sector_t, max_sector, max_size);
|
|
|
|
pr_info("ssize=%x SIZECODE=%d\n", ssize, SIZECODE);
|
|
|
|
pr_info("command=%x SECTOR=%d HEAD=%d, TRACK=%d\n",
|
|
|
|
COMMAND, SECTOR, HEAD, TRACK);
|
|
|
|
pr_info("buffer drive=%d\n", buffer_drive);
|
|
|
|
pr_info("buffer track=%d\n", buffer_track);
|
|
|
|
pr_info("buffer_min=%d\n", buffer_min);
|
|
|
|
pr_info("buffer_max=%d\n", buffer_max);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-10 19:46:28 +04:00
|
|
|
if (raw_cmd->kernel_data != bio_data(current_req->bio)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
if (raw_cmd->kernel_data < floppy_track_buffer ||
|
|
|
|
current_count_sectors < 0 ||
|
|
|
|
raw_cmd->length < 0 ||
|
|
|
|
raw_cmd->kernel_data + raw_cmd->length >
|
|
|
|
floppy_track_buffer + (max_buffer_sectors << 10)) {
|
|
|
|
DPRINT("buffer overrun in schedule dma\n");
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("fsector_t=%d buffer_min=%d current_count=%ld\n",
|
|
|
|
fsector_t, buffer_min, raw_cmd->length >> 9);
|
|
|
|
pr_info("current_count_sectors=%ld\n",
|
|
|
|
current_count_sectors);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (CT(COMMAND) == FD_READ)
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("read\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
if (CT(COMMAND) == FD_WRITE)
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("write\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-07 17:24:45 +04:00
|
|
|
} else if (raw_cmd->length > blk_rq_bytes(current_req) ||
|
2009-05-07 17:24:39 +04:00
|
|
|
current_count_sectors > blk_rq_sectors(current_req)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("buffer overrun in direct transfer\n");
|
|
|
|
return 0;
|
|
|
|
} else if (raw_cmd->length < current_count_sectors << 9) {
|
|
|
|
DPRINT("more sectors than bytes\n");
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("bytes=%ld\n", raw_cmd->length >> 9);
|
|
|
|
pr_info("sectors=%ld\n", current_count_sectors);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
if (raw_cmd->length == 0) {
|
|
|
|
DPRINT("zero dma transfer attempted from make_raw_request\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtualdmabug_workaround();
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2010-09-22 11:32:36 +04:00
|
|
|
static int set_next_request(void)
|
|
|
|
{
|
2018-10-15 18:21:34 +03:00
|
|
|
current_req = list_first_entry_or_null(&floppy_reqs, struct request,
|
|
|
|
queuelist);
|
|
|
|
if (current_req) {
|
|
|
|
current_req->error_count = 0;
|
|
|
|
list_del_init(¤t_req->queuelist);
|
|
|
|
}
|
2010-09-22 11:32:36 +04:00
|
|
|
return current_req != NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static void redo_fd_request(void)
|
|
|
|
{
|
|
|
|
int drive;
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
lastredo = jiffies;
|
|
|
|
if (current_drive < N_DRIVE)
|
|
|
|
floppy_off(current_drive);
|
|
|
|
|
2010-03-11 02:21:03 +03:00
|
|
|
do_request:
|
|
|
|
if (!current_req) {
|
2010-09-22 11:32:36 +04:00
|
|
|
int pending;
|
|
|
|
|
|
|
|
spin_lock_irq(&floppy_lock);
|
|
|
|
pending = set_next_request();
|
|
|
|
spin_unlock_irq(&floppy_lock);
|
|
|
|
if (!pending) {
|
2010-03-11 02:21:03 +03:00
|
|
|
do_floppy = NULL;
|
|
|
|
unlock_fdc();
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-03-11 02:21:03 +03:00
|
|
|
}
|
|
|
|
drive = (long)current_req->rq_disk->private_data;
|
|
|
|
set_fdc(drive);
|
2010-03-11 02:21:03 +03:00
|
|
|
reschedule_timeout(current_reqD, "redo fd request");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:21:03 +03:00
|
|
|
set_floppy(drive);
|
|
|
|
raw_cmd = &default_raw_cmd;
|
|
|
|
raw_cmd->flags = 0;
|
|
|
|
if (start_motor(redo_fd_request))
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
2010-03-11 02:21:03 +03:00
|
|
|
|
|
|
|
disk_change(current_drive);
|
|
|
|
if (test_bit(current_drive, &fake_change) ||
|
2020-02-25 00:23:49 +03:00
|
|
|
test_bit(FD_DISK_CHANGED_BIT, &drive_state[current_drive].flags)) {
|
2010-03-11 02:21:03 +03:00
|
|
|
DPRINT("disk absent or changed during operation\n");
|
|
|
|
request_done(0);
|
|
|
|
goto do_request;
|
|
|
|
}
|
|
|
|
if (!_floppy) { /* Autodetection */
|
|
|
|
if (!probing) {
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].probed_format = 0;
|
2010-03-11 02:21:03 +03:00
|
|
|
if (next_valid_format()) {
|
|
|
|
DPRINT("no autodetectable formats\n");
|
|
|
|
_floppy = NULL;
|
|
|
|
request_done(0);
|
|
|
|
goto do_request;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
probing = 1;
|
2020-02-25 00:23:49 +03:00
|
|
|
_floppy = floppy_type + drive_params[current_drive].autodetect[drive_state[current_drive].probed_format];
|
2010-03-11 02:21:03 +03:00
|
|
|
} else
|
|
|
|
probing = 0;
|
2017-04-20 17:03:12 +03:00
|
|
|
errors = &(current_req->error_count);
|
2010-03-11 02:21:03 +03:00
|
|
|
tmp = make_raw_rw_request();
|
|
|
|
if (tmp < 2) {
|
|
|
|
request_done(tmp);
|
|
|
|
goto do_request;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-03-11 02:21:03 +03:00
|
|
|
|
2020-02-25 00:23:49 +03:00
|
|
|
if (test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags))
|
2010-03-11 02:21:03 +03:00
|
|
|
twaddle();
|
|
|
|
schedule_bh(floppy_start);
|
2010-03-11 02:21:09 +03:00
|
|
|
debugt(__func__, "queue fd request");
|
2010-03-11 02:21:03 +03:00
|
|
|
return;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-07-21 06:09:00 +04:00
|
|
|
static const struct cont_t rw_cont = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.interrupt = rw_interrupt,
|
|
|
|
.redo = redo_fd_request,
|
|
|
|
.error = bad_flp_intr,
|
|
|
|
.done = request_done
|
|
|
|
};
|
|
|
|
|
|
|
|
static void process_fd_request(void)
|
|
|
|
{
|
|
|
|
cont = &rw_cont;
|
|
|
|
schedule_bh(redo_fd_request);
|
|
|
|
}
|
|
|
|
|
2018-10-15 18:21:34 +03:00
|
|
|
static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx,
|
|
|
|
const struct blk_mq_queue_data *bd)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-10-15 18:21:34 +03:00
|
|
|
blk_mq_start_request(bd->rq);
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
if (WARN(max_buffer_sectors == 0,
|
|
|
|
"VFS: %s called on non-open device\n", __func__))
|
2018-10-15 18:21:34 +03:00
|
|
|
return BLK_STS_IOERR;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
if (WARN(atomic_read(&usage_count) == 0,
|
2017-01-31 18:57:31 +03:00
|
|
|
"warning: usage count=0, current_req=%p sect=%ld flags=%llx\n",
|
|
|
|
current_req, (long)blk_rq_pos(current_req),
|
2013-05-23 14:25:08 +04:00
|
|
|
(unsigned long long) current_req->cmd_flags))
|
2018-10-15 18:21:34 +03:00
|
|
|
return BLK_STS_IOERR;
|
|
|
|
|
|
|
|
spin_lock_irq(&floppy_lock);
|
|
|
|
list_add_tail(&bd->rq->queuelist, &floppy_reqs);
|
|
|
|
spin_unlock_irq(&floppy_lock);
|
2010-06-15 15:21:11 +04:00
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
if (test_and_set_bit(0, &fdc_busy)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* fdc busy, this new request will be treated when the
|
|
|
|
current one is done */
|
2010-03-11 02:21:06 +03:00
|
|
|
is_alive(__func__, "old request running");
|
2018-10-15 18:21:34 +03:00
|
|
|
return BLK_STS_OK;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2018-10-15 18:21:34 +03:00
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
command_status = FD_COMMAND_NONE;
|
|
|
|
__reschedule_timeout(MAXTIMEOUT, "fd_request");
|
|
|
|
set_fdc(0);
|
2005-04-17 02:20:36 +04:00
|
|
|
process_fd_request();
|
2010-03-11 02:21:06 +03:00
|
|
|
is_alive(__func__, "");
|
2018-10-15 18:21:34 +03:00
|
|
|
return BLK_STS_OK;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-07-21 06:09:00 +04:00
|
|
|
static const struct cont_t poll_cont = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.interrupt = success_and_wakeup,
|
|
|
|
.redo = floppy_ready,
|
|
|
|
.error = generic_failure,
|
|
|
|
.done = generic_done
|
|
|
|
};
|
|
|
|
|
2010-03-11 02:20:58 +03:00
|
|
|
static int poll_drive(bool interruptible, int flag)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
/* no auto-sense, just clear dcl */
|
|
|
|
raw_cmd = &default_raw_cmd;
|
|
|
|
raw_cmd->flags = flag;
|
|
|
|
raw_cmd->track = 0;
|
|
|
|
raw_cmd->cmd_count = 0;
|
|
|
|
cont = &poll_cont;
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
|
|
|
"setting NEWCHANGE in poll_drive\n");
|
2020-02-25 00:23:49 +03:00
|
|
|
set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
|
2010-03-11 02:20:57 +03:00
|
|
|
|
|
|
|
return wait_til_done(floppy_ready, interruptible);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* User triggered reset
|
|
|
|
* ====================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void reset_intr(void)
|
|
|
|
{
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("weird, reset interrupt called\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-07-21 06:09:00 +04:00
|
|
|
static const struct cont_t reset_cont = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.interrupt = reset_intr,
|
|
|
|
.redo = success_and_wakeup,
|
|
|
|
.error = generic_failure,
|
|
|
|
.done = generic_done
|
|
|
|
};
|
|
|
|
|
2010-03-11 02:20:58 +03:00
|
|
|
static int user_reset_fdc(int drive, int arg, bool interruptible)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (arg == FD_RESET_ALWAYS)
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].reset = 1;
|
|
|
|
if (fdc_state[fdc].reset) {
|
2005-04-17 02:20:36 +04:00
|
|
|
cont = &reset_cont;
|
2010-03-11 02:20:57 +03:00
|
|
|
ret = wait_til_done(reset_fdc, interruptible);
|
|
|
|
if (ret == -EINTR)
|
|
|
|
return -EINTR;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
process_fd_request();
|
2010-03-11 02:20:53 +03:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Misc Ioctl's and support
|
|
|
|
* ========================
|
|
|
|
*/
|
|
|
|
static inline int fd_copyout(void __user *param, const void *address,
|
|
|
|
unsigned long size)
|
|
|
|
{
|
|
|
|
return copy_to_user(param, address, size) ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:20:45 +03:00
|
|
|
static inline int fd_copyin(void __user *param, void *address,
|
|
|
|
unsigned long size)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
return copy_from_user(address, param, size) ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
static const char *drive_name(int type, int drive)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct floppy_struct *floppy;
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
floppy = floppy_type + type;
|
|
|
|
else {
|
2020-02-25 00:23:45 +03:00
|
|
|
if (drive_params[drive].native_format)
|
|
|
|
floppy = floppy_type + drive_params[drive].native_format;
|
2005-04-17 02:20:36 +04:00
|
|
|
else
|
|
|
|
return "(null)";
|
|
|
|
}
|
|
|
|
if (floppy->name)
|
|
|
|
return floppy->name;
|
|
|
|
else
|
|
|
|
return "(null)";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* raw commands */
|
|
|
|
static void raw_cmd_done(int flag)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!flag) {
|
|
|
|
raw_cmd->flags |= FD_RAW_FAILURE;
|
|
|
|
raw_cmd->flags |= FD_RAW_HARDFAILURE;
|
|
|
|
} else {
|
|
|
|
raw_cmd->reply_count = inr;
|
|
|
|
if (raw_cmd->reply_count > MAX_REPLIES)
|
|
|
|
raw_cmd->reply_count = 0;
|
|
|
|
for (i = 0; i < raw_cmd->reply_count; i++)
|
|
|
|
raw_cmd->reply[i] = reply_buffer[i];
|
|
|
|
|
|
|
|
if (raw_cmd->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
|
|
|
|
unsigned long flags;
|
|
|
|
flags = claim_dma_lock();
|
|
|
|
raw_cmd->length = fd_get_dma_residue();
|
|
|
|
release_dma_lock(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((raw_cmd->flags & FD_RAW_SOFTFAILURE) &&
|
|
|
|
(!raw_cmd->reply_count || (raw_cmd->reply[0] & 0xc0)))
|
|
|
|
raw_cmd->flags |= FD_RAW_FAILURE;
|
|
|
|
|
|
|
|
if (disk_change(current_drive))
|
|
|
|
raw_cmd->flags |= FD_RAW_DISK_CHANGE;
|
|
|
|
else
|
|
|
|
raw_cmd->flags &= ~FD_RAW_DISK_CHANGE;
|
|
|
|
if (raw_cmd->flags & FD_RAW_NO_MOTOR_AFTER)
|
2017-10-05 03:49:29 +03:00
|
|
|
motor_off_callback(&motor_off_timer[current_drive]);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (raw_cmd->next &&
|
|
|
|
(!(raw_cmd->flags & FD_RAW_FAILURE) ||
|
|
|
|
!(raw_cmd->flags & FD_RAW_STOP_IF_FAILURE)) &&
|
|
|
|
((raw_cmd->flags & FD_RAW_FAILURE) ||
|
|
|
|
!(raw_cmd->flags & FD_RAW_STOP_IF_SUCCESS))) {
|
|
|
|
raw_cmd = raw_cmd->next;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
generic_done(flag);
|
|
|
|
}
|
|
|
|
|
2010-07-21 06:09:00 +04:00
|
|
|
static const struct cont_t raw_cmd_cont = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.interrupt = success_and_wakeup,
|
|
|
|
.redo = floppy_start,
|
|
|
|
.error = generic_failure,
|
|
|
|
.done = raw_cmd_done
|
|
|
|
};
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
static int raw_cmd_copyout(int cmd, void __user *param,
|
2005-04-17 02:20:36 +04:00
|
|
|
struct floppy_raw_cmd *ptr)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
while (ptr) {
|
2014-04-28 11:05:21 +04:00
|
|
|
struct floppy_raw_cmd cmd = *ptr;
|
|
|
|
cmd.next = NULL;
|
|
|
|
cmd.kernel_data = NULL;
|
|
|
|
ret = copy_to_user(param, &cmd, sizeof(cmd));
|
2010-03-11 02:20:56 +03:00
|
|
|
if (ret)
|
|
|
|
return -EFAULT;
|
2005-04-17 02:20:36 +04:00
|
|
|
param += sizeof(struct floppy_raw_cmd);
|
|
|
|
if ((ptr->flags & FD_RAW_READ) && ptr->buffer_length) {
|
2010-03-11 02:20:50 +03:00
|
|
|
if (ptr->length >= 0 &&
|
|
|
|
ptr->length <= ptr->buffer_length) {
|
|
|
|
long length = ptr->buffer_length - ptr->length;
|
2010-03-11 02:20:55 +03:00
|
|
|
ret = fd_copyout(ptr->data, ptr->kernel_data,
|
|
|
|
length);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-03-11 02:20:50 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
2010-03-11 02:21:08 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void raw_cmd_free(struct floppy_raw_cmd **ptr)
|
|
|
|
{
|
2007-10-17 10:30:57 +04:00
|
|
|
struct floppy_raw_cmd *next;
|
|
|
|
struct floppy_raw_cmd *this;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
this = *ptr;
|
|
|
|
*ptr = NULL;
|
|
|
|
while (this) {
|
|
|
|
if (this->buffer_length) {
|
|
|
|
fd_dma_mem_free((unsigned long)this->kernel_data,
|
|
|
|
this->buffer_length);
|
|
|
|
this->buffer_length = 0;
|
|
|
|
}
|
|
|
|
next = this->next;
|
|
|
|
kfree(this);
|
|
|
|
this = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
static int raw_cmd_copyin(int cmd, void __user *param,
|
2005-04-17 02:20:36 +04:00
|
|
|
struct floppy_raw_cmd **rcmd)
|
|
|
|
{
|
|
|
|
struct floppy_raw_cmd *ptr;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*rcmd = NULL;
|
2010-03-11 02:21:08 +03:00
|
|
|
|
|
|
|
loop:
|
2017-01-04 13:19:31 +03:00
|
|
|
ptr = kmalloc(sizeof(struct floppy_raw_cmd), GFP_KERNEL);
|
2010-03-11 02:21:08 +03:00
|
|
|
if (!ptr)
|
|
|
|
return -ENOMEM;
|
|
|
|
*rcmd = ptr;
|
|
|
|
ret = copy_from_user(ptr, param, sizeof(*ptr));
|
|
|
|
ptr->next = NULL;
|
|
|
|
ptr->buffer_length = 0;
|
2014-04-28 11:05:20 +04:00
|
|
|
ptr->kernel_data = NULL;
|
|
|
|
if (ret)
|
|
|
|
return -EFAULT;
|
2010-03-11 02:21:08 +03:00
|
|
|
param += sizeof(struct floppy_raw_cmd);
|
|
|
|
if (ptr->cmd_count > 33)
|
2005-04-17 02:20:36 +04:00
|
|
|
/* the command may now also take up the space
|
|
|
|
* initially intended for the reply & the
|
|
|
|
* reply count. Needed for long 82078 commands
|
|
|
|
* such as RESTORE, which takes ... 17 command
|
|
|
|
* bytes. Murphy's law #137: When you reserve
|
|
|
|
* 16 bytes for a structure, you'll one day
|
|
|
|
* discover that you really need 17...
|
|
|
|
*/
|
2010-03-11 02:21:08 +03:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
ptr->reply[i] = 0;
|
|
|
|
ptr->resultcode = 0;
|
|
|
|
|
|
|
|
if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) {
|
|
|
|
if (ptr->length <= 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
2010-03-11 02:21:08 +03:00
|
|
|
ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length);
|
|
|
|
fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length);
|
|
|
|
if (!ptr->kernel_data)
|
|
|
|
return -ENOMEM;
|
|
|
|
ptr->buffer_length = ptr->length;
|
|
|
|
}
|
|
|
|
if (ptr->flags & FD_RAW_WRITE) {
|
|
|
|
ret = fd_copyin(ptr->data, ptr->kernel_data, ptr->length);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:21:08 +03:00
|
|
|
if (ptr->flags & FD_RAW_MORE) {
|
2005-04-17 02:20:36 +04:00
|
|
|
rcmd = &(ptr->next);
|
|
|
|
ptr->rate &= 0x43;
|
2010-03-11 02:21:08 +03:00
|
|
|
goto loop;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-03-11 02:21:08 +03:00
|
|
|
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int raw_cmd_ioctl(int cmd, void __user *param)
|
|
|
|
{
|
|
|
|
struct floppy_raw_cmd *my_raw_cmd;
|
2007-10-17 10:30:57 +04:00
|
|
|
int drive;
|
|
|
|
int ret2;
|
|
|
|
int ret;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].rawcmd <= 1)
|
|
|
|
fdc_state[fdc].rawcmd = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
for (drive = 0; drive < N_DRIVE; drive++) {
|
|
|
|
if (FDC(drive) != fdc)
|
|
|
|
continue;
|
|
|
|
if (drive == current_drive) {
|
2020-02-25 00:23:46 +03:00
|
|
|
if (drive_state[drive].fd_ref > 1) {
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].rawcmd = 2;
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
}
|
2020-02-25 00:23:46 +03:00
|
|
|
} else if (drive_state[drive].fd_ref) {
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].rawcmd = 2;
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].reset)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
ret = raw_cmd_copyin(cmd, param, &my_raw_cmd);
|
|
|
|
if (ret) {
|
|
|
|
raw_cmd_free(&my_raw_cmd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
raw_cmd = my_raw_cmd;
|
|
|
|
cont = &raw_cmd_cont;
|
2010-03-11 02:20:58 +03:00
|
|
|
ret = wait_til_done(floppy_start, true);
|
2020-02-25 00:23:48 +03:00
|
|
|
debug_dcl(drive_params[current_drive].flags,
|
|
|
|
"calling disk change from raw_cmd ioctl\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:43 +03:00
|
|
|
if (ret != -EINTR && fdc_state[fdc].reset)
|
2005-04-17 02:20:36 +04:00
|
|
|
ret = -EIO;
|
|
|
|
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].track = NO_TRACK;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
ret2 = raw_cmd_copyout(cmd, param, my_raw_cmd);
|
|
|
|
if (!ret)
|
|
|
|
ret = ret2;
|
|
|
|
raw_cmd_free(&my_raw_cmd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int invalidate_drive(struct block_device *bdev)
|
|
|
|
{
|
|
|
|
/* invalidate the buffer track to force a reread */
|
|
|
|
set_bit((long)bdev->bd_disk->private_data, &fake_change);
|
|
|
|
process_fd_request();
|
|
|
|
check_disk_change(bdev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
static int set_geometry(unsigned int cmd, struct floppy_struct *g,
|
2005-04-17 02:20:36 +04:00
|
|
|
int drive, int type, struct block_device *bdev)
|
|
|
|
{
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
/* sanity checking for parameters. */
|
2019-07-12 21:55:23 +03:00
|
|
|
if ((int)g->sect <= 0 ||
|
|
|
|
(int)g->head <= 0 ||
|
|
|
|
/* check for overflow in max_sector */
|
|
|
|
(int)(g->sect * g->head) <= 0 ||
|
2019-07-12 21:55:20 +03:00
|
|
|
/* check for zero in F_SECT_PER_TRACK */
|
|
|
|
(unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
|
2020-02-25 00:23:45 +03:00
|
|
|
g->track <= 0 || g->track > drive_params[drive].tracks >> STRETCH(g) ||
|
2005-04-17 02:20:36 +04:00
|
|
|
/* check if reserved bits are set */
|
2008-09-23 01:57:17 +04:00
|
|
|
(g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
|
|
|
if (type) {
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
2006-03-23 14:00:26 +03:00
|
|
|
mutex_lock(&open_lock);
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive)) {
|
2009-06-30 22:41:44 +04:00
|
|
|
mutex_unlock(&open_lock);
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
floppy_type[type] = *g;
|
|
|
|
floppy_type[type].name = "user format";
|
|
|
|
for (cnt = type << 2; cnt < (type << 2) + 4; cnt++)
|
|
|
|
floppy_sizes[cnt] = floppy_sizes[cnt + 0x80] =
|
|
|
|
floppy_type[type].size + 1;
|
|
|
|
process_fd_request();
|
|
|
|
for (cnt = 0; cnt < N_DRIVE; cnt++) {
|
|
|
|
struct block_device *bdev = opened_bdev[cnt];
|
|
|
|
if (!bdev || ITYPE(drive_state[cnt].fd_device) != type)
|
|
|
|
continue;
|
2011-02-24 09:25:47 +03:00
|
|
|
__invalidate_device(bdev, true);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2006-03-23 14:00:26 +03:00
|
|
|
mutex_unlock(&open_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
int oldStretch;
|
2010-03-11 02:20:53 +03:00
|
|
|
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:55 +03:00
|
|
|
if (cmd != FDDEFPRM) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* notice a disk change immediately, else
|
|
|
|
* we lose our settings immediately*/
|
2010-03-11 02:20:58 +03:00
|
|
|
if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
|
2010-03-11 02:20:55 +03:00
|
|
|
return -EINTR;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
oldStretch = g->stretch;
|
|
|
|
user_params[drive] = *g;
|
|
|
|
if (buffer_drive == drive)
|
|
|
|
SUPBOUND(buffer_max, user_params[drive].sect);
|
|
|
|
current_type[drive] = &user_params[drive];
|
|
|
|
floppy_sizes[drive] = user_params[drive].size;
|
|
|
|
if (cmd == FDDEFPRM)
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].keep_data = -1;
|
2005-04-17 02:20:36 +04:00
|
|
|
else
|
2020-02-25 00:23:49 +03:00
|
|
|
drive_state[current_drive].keep_data = 1;
|
2005-04-17 02:20:36 +04:00
|
|
|
/* invalidation. Invalidate only when needed, i.e.
|
|
|
|
* when there are already sectors in the buffer cache
|
|
|
|
* whose number will change. This is useful, because
|
|
|
|
* mtools often changes the geometry of the disk after
|
|
|
|
* looking at the boot block */
|
2020-02-25 00:23:49 +03:00
|
|
|
if (drive_state[current_drive].maxblock > user_params[drive].sect ||
|
|
|
|
drive_state[current_drive].maxtrack ||
|
2005-04-17 02:20:36 +04:00
|
|
|
((user_params[drive].sect ^ oldStretch) &
|
2008-09-23 01:57:17 +04:00
|
|
|
(FD_SWAPSIDES | FD_SECTBASEMASK)))
|
2005-04-17 02:20:36 +04:00
|
|
|
invalidate_drive(bdev);
|
|
|
|
else
|
|
|
|
process_fd_request();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle obsolete ioctl's */
|
2010-06-15 15:21:11 +04:00
|
|
|
static unsigned int ioctl_table[] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
FDCLRPRM,
|
|
|
|
FDSETPRM,
|
|
|
|
FDDEFPRM,
|
|
|
|
FDGETPRM,
|
|
|
|
FDMSGON,
|
|
|
|
FDMSGOFF,
|
|
|
|
FDFMTBEG,
|
|
|
|
FDFMTTRK,
|
|
|
|
FDFMTEND,
|
|
|
|
FDSETEMSGTRESH,
|
|
|
|
FDFLUSH,
|
|
|
|
FDSETMAXERRS,
|
|
|
|
FDGETMAXERRS,
|
|
|
|
FDGETDRVTYP,
|
|
|
|
FDSETDRVPRM,
|
|
|
|
FDGETDRVPRM,
|
|
|
|
FDGETDRVSTAT,
|
|
|
|
FDPOLLDRVSTAT,
|
|
|
|
FDRESET,
|
|
|
|
FDGETFDCSTAT,
|
|
|
|
FDWERRORCLR,
|
|
|
|
FDWERRORGET,
|
|
|
|
FDRAWCMD,
|
|
|
|
FDEJECT,
|
|
|
|
FDTWADDLE
|
|
|
|
};
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
static int normalize_ioctl(unsigned int *cmd, int *size)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ioctl_table); i++) {
|
|
|
|
if ((*cmd & 0xffff) == (ioctl_table[i] & 0xffff)) {
|
|
|
|
*size = _IOC_SIZE(*cmd);
|
|
|
|
*cmd = ioctl_table[i];
|
|
|
|
if (*size > _IOC_SIZE(*cmd)) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("ioctl not yet supported\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_floppy_geometry(int drive, int type, struct floppy_struct **g)
|
|
|
|
{
|
|
|
|
if (type)
|
|
|
|
*g = &floppy_type[type];
|
|
|
|
else {
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:58 +03:00
|
|
|
if (poll_drive(false, 0) == -EINTR)
|
2010-03-11 02:20:55 +03:00
|
|
|
return -EINTR;
|
2005-04-17 02:20:36 +04:00
|
|
|
process_fd_request();
|
|
|
|
*g = current_type[drive];
|
|
|
|
}
|
|
|
|
if (!*g)
|
|
|
|
return -ENODEV;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-08 12:02:50 +03:00
|
|
|
static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
|
|
|
|
{
|
|
|
|
int drive = (long)bdev->bd_disk->private_data;
|
|
|
|
int type = ITYPE(drive_state[drive].fd_device);
|
|
|
|
struct floppy_struct *g;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = get_floppy_geometry(drive, type, &g);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
geo->heads = g->head;
|
|
|
|
geo->sectors = g->sect;
|
|
|
|
geo->cylinders = g->track;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-12 21:55:22 +03:00
|
|
|
static bool valid_floppy_drive_params(const short autodetect[8],
|
|
|
|
int native_format)
|
2019-07-12 21:55:21 +03:00
|
|
|
{
|
|
|
|
size_t floppy_type_size = ARRAY_SIZE(floppy_type);
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
if (autodetect[i] < 0 ||
|
|
|
|
autodetect[i] >= floppy_type_size)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-12 21:55:22 +03:00
|
|
|
if (native_format < 0 || native_format >= floppy_type_size)
|
|
|
|
return false;
|
|
|
|
|
2019-07-12 21:55:21 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-08 12:18:46 +04:00
|
|
|
static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long param)
|
|
|
|
{
|
2008-03-02 17:27:55 +03:00
|
|
|
int drive = (long)bdev->bd_disk->private_data;
|
2020-02-25 00:23:46 +03:00
|
|
|
int type = ITYPE(drive_state[drive].fd_device);
|
2007-10-17 10:30:57 +04:00
|
|
|
int i;
|
2005-04-17 02:20:36 +04:00
|
|
|
int ret;
|
|
|
|
int size;
|
|
|
|
union inparam {
|
|
|
|
struct floppy_struct g; /* geometry */
|
|
|
|
struct format_descr f;
|
|
|
|
struct floppy_max_errors max_errors;
|
|
|
|
struct floppy_drive_params dp;
|
|
|
|
} inparam; /* parameters coming from user space */
|
2010-03-11 02:21:11 +03:00
|
|
|
const void *outparam; /* parameters passed back to user space */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* convert compatibility eject ioctls into floppy eject ioctl.
|
|
|
|
* We do this in order to provide a means to eject floppy disks before
|
|
|
|
* installing the new fdutils package */
|
|
|
|
if (cmd == CDROMEJECT || /* CD-ROM eject */
|
2010-03-11 02:20:46 +03:00
|
|
|
cmd == 0x6470) { /* SunOS floppy eject */
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("obsolete eject ioctl\n");
|
|
|
|
DPRINT("please use floppycontrol --eject\n");
|
|
|
|
cmd = FDEJECT;
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:20:46 +03:00
|
|
|
if (!((cmd & 0xff00) == 0x0200))
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
|
|
|
|
2010-03-11 02:20:46 +03:00
|
|
|
/* convert the old style command into a new style command */
|
2010-03-11 02:20:55 +03:00
|
|
|
ret = normalize_ioctl(&cmd, &size);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-03-11 02:20:46 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* permission checks */
|
2010-03-11 02:21:10 +03:00
|
|
|
if (((cmd & 0x40) && !(mode & (FMODE_WRITE | FMODE_WRITE_IOCTL))) ||
|
2005-04-17 02:20:36 +04:00
|
|
|
((cmd & 0x80) && !capable(CAP_SYS_ADMIN)))
|
|
|
|
return -EPERM;
|
|
|
|
|
2009-12-15 05:00:11 +03:00
|
|
|
if (WARN_ON(size < 0 || size > sizeof(inparam)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* copyin */
|
2010-03-11 02:20:50 +03:00
|
|
|
memset(&inparam, 0, sizeof(inparam));
|
2010-03-11 02:20:55 +03:00
|
|
|
if (_IOC_DIR(cmd) & _IOC_WRITE) {
|
|
|
|
ret = fd_copyin((void __user *)param, &inparam, size);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:20:52 +03:00
|
|
|
switch (cmd) {
|
|
|
|
case FDEJECT:
|
2020-02-25 00:23:46 +03:00
|
|
|
if (drive_state[drive].fd_ref != 1)
|
2010-03-11 02:20:52 +03:00
|
|
|
/* somebody else has this drive open */
|
|
|
|
return -EBUSY;
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-03-11 02:20:52 +03:00
|
|
|
/* do the actual eject. Fails on
|
|
|
|
* non-Sparc architectures */
|
|
|
|
ret = fd_eject(UNIT(drive));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
|
|
|
|
set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
|
2010-03-11 02:20:52 +03:00
|
|
|
process_fd_request();
|
|
|
|
return ret;
|
|
|
|
case FDCLRPRM:
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:52 +03:00
|
|
|
current_type[drive] = NULL;
|
|
|
|
floppy_sizes[drive] = MAX_DISK_SIZE << 1;
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].keep_data = 0;
|
2010-03-11 02:20:52 +03:00
|
|
|
return invalidate_drive(bdev);
|
|
|
|
case FDSETPRM:
|
|
|
|
case FDDEFPRM:
|
|
|
|
return set_geometry(cmd, &inparam.g, drive, type, bdev);
|
|
|
|
case FDGETPRM:
|
2010-03-11 02:20:55 +03:00
|
|
|
ret = get_floppy_geometry(drive, type,
|
2010-03-11 02:21:11 +03:00
|
|
|
(struct floppy_struct **)&outparam);
|
2010-03-11 02:20:55 +03:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-09-20 18:09:48 +03:00
|
|
|
memcpy(&inparam.g, outparam,
|
|
|
|
offsetof(struct floppy_struct, name));
|
|
|
|
outparam = &inparam.g;
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDMSGON:
|
2020-02-25 00:23:45 +03:00
|
|
|
drive_params[drive].flags |= FTD_MSG;
|
2010-03-11 02:20:52 +03:00
|
|
|
return 0;
|
|
|
|
case FDMSGOFF:
|
2020-02-25 00:23:45 +03:00
|
|
|
drive_params[drive].flags &= ~FTD_MSG;
|
2010-03-11 02:20:52 +03:00
|
|
|
return 0;
|
|
|
|
case FDFMTBEG:
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:58 +03:00
|
|
|
if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
|
2010-03-11 02:20:55 +03:00
|
|
|
return -EINTR;
|
2020-02-25 00:23:46 +03:00
|
|
|
ret = drive_state[drive].flags;
|
2010-03-11 02:20:52 +03:00
|
|
|
process_fd_request();
|
|
|
|
if (ret & FD_VERIFY)
|
|
|
|
return -ENODEV;
|
|
|
|
if (!(ret & FD_DISK_WRITABLE))
|
|
|
|
return -EROFS;
|
|
|
|
return 0;
|
|
|
|
case FDFMTTRK:
|
2020-02-25 00:23:46 +03:00
|
|
|
if (drive_state[drive].fd_ref != 1)
|
2010-03-11 02:20:52 +03:00
|
|
|
return -EBUSY;
|
|
|
|
return do_format(drive, &inparam.f);
|
|
|
|
case FDFMTEND:
|
|
|
|
case FDFLUSH:
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:52 +03:00
|
|
|
return invalidate_drive(bdev);
|
|
|
|
case FDSETEMSGTRESH:
|
2020-02-25 00:23:45 +03:00
|
|
|
drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f);
|
2010-03-11 02:20:52 +03:00
|
|
|
return 0;
|
|
|
|
case FDGETMAXERRS:
|
2020-02-25 00:23:45 +03:00
|
|
|
outparam = &drive_params[drive].max_errors;
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDSETMAXERRS:
|
2020-02-25 00:23:45 +03:00
|
|
|
drive_params[drive].max_errors = inparam.max_errors;
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDGETDRVTYP:
|
|
|
|
outparam = drive_name(type, drive);
|
2010-03-11 02:21:11 +03:00
|
|
|
SUPBOUND(size, strlen((const char *)outparam) + 1);
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDSETDRVPRM:
|
2019-07-12 21:55:22 +03:00
|
|
|
if (!valid_floppy_drive_params(inparam.dp.autodetect,
|
|
|
|
inparam.dp.native_format))
|
2019-07-12 21:55:21 +03:00
|
|
|
return -EINVAL;
|
2020-02-25 00:23:45 +03:00
|
|
|
drive_params[drive] = inparam.dp;
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDGETDRVPRM:
|
2020-02-25 00:23:45 +03:00
|
|
|
outparam = &drive_params[drive];
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDPOLLDRVSTAT:
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:58 +03:00
|
|
|
if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
|
2010-03-11 02:20:55 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:52 +03:00
|
|
|
process_fd_request();
|
|
|
|
/* fall through */
|
|
|
|
case FDGETDRVSTAT:
|
2020-02-25 00:23:46 +03:00
|
|
|
outparam = &drive_state[drive];
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDRESET:
|
2010-03-11 02:20:58 +03:00
|
|
|
return user_reset_fdc(drive, (int)param, true);
|
2010-03-11 02:20:52 +03:00
|
|
|
case FDGETFDCSTAT:
|
2020-02-25 00:23:44 +03:00
|
|
|
outparam = &fdc_state[FDC(drive)];
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDWERRORCLR:
|
2020-02-25 00:23:47 +03:00
|
|
|
memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
|
2010-03-11 02:20:52 +03:00
|
|
|
return 0;
|
|
|
|
case FDWERRORGET:
|
2020-02-25 00:23:47 +03:00
|
|
|
outparam = &write_errors[drive];
|
2010-03-11 02:20:52 +03:00
|
|
|
break;
|
|
|
|
case FDRAWCMD:
|
|
|
|
if (type)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:52 +03:00
|
|
|
set_floppy(drive);
|
2010-03-11 02:20:55 +03:00
|
|
|
i = raw_cmd_ioctl(cmd, (void __user *)param);
|
|
|
|
if (i == -EINTR)
|
|
|
|
return -EINTR;
|
2010-03-11 02:20:52 +03:00
|
|
|
process_fd_request();
|
|
|
|
return i;
|
|
|
|
case FDTWADDLE:
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2010-03-11 02:20:53 +03:00
|
|
|
return -EINTR;
|
2010-03-11 02:20:52 +03:00
|
|
|
twaddle();
|
|
|
|
process_fd_request();
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (_IOC_DIR(cmd) & _IOC_READ)
|
|
|
|
return fd_copyout((void __user *)param, outparam, size);
|
2010-03-11 02:20:52 +03:00
|
|
|
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-07-08 12:18:46 +04:00
|
|
|
static int fd_ioctl(struct block_device *bdev, fmode_t mode,
|
|
|
|
unsigned int cmd, unsigned long param)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_lock(&floppy_mutex);
|
2010-07-08 12:18:46 +04:00
|
|
|
ret = fd_locked_ioctl(bdev, mode, cmd, param);
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&floppy_mutex);
|
2010-07-08 12:18:46 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-27 22:47:56 +03:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
|
|
|
|
struct compat_floppy_drive_params {
|
|
|
|
char cmos;
|
|
|
|
compat_ulong_t max_dtr;
|
|
|
|
compat_ulong_t hlt;
|
|
|
|
compat_ulong_t hut;
|
|
|
|
compat_ulong_t srt;
|
|
|
|
compat_ulong_t spinup;
|
|
|
|
compat_ulong_t spindown;
|
|
|
|
unsigned char spindown_offset;
|
|
|
|
unsigned char select_delay;
|
|
|
|
unsigned char rps;
|
|
|
|
unsigned char tracks;
|
|
|
|
compat_ulong_t timeout;
|
|
|
|
unsigned char interleave_sect;
|
|
|
|
struct floppy_max_errors max_errors;
|
|
|
|
char flags;
|
|
|
|
char read_track;
|
|
|
|
short autodetect[8];
|
|
|
|
compat_int_t checkfreq;
|
|
|
|
compat_int_t native_format;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_floppy_drive_struct {
|
|
|
|
signed char flags;
|
|
|
|
compat_ulong_t spinup_date;
|
|
|
|
compat_ulong_t select_date;
|
|
|
|
compat_ulong_t first_read_date;
|
|
|
|
short probed_format;
|
|
|
|
short track;
|
|
|
|
short maxblock;
|
|
|
|
short maxtrack;
|
|
|
|
compat_int_t generation;
|
|
|
|
compat_int_t keep_data;
|
|
|
|
compat_int_t fd_ref;
|
|
|
|
compat_int_t fd_device;
|
|
|
|
compat_int_t last_checked;
|
|
|
|
compat_caddr_t dmabuf;
|
|
|
|
compat_int_t bufblocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_floppy_fdc_state {
|
|
|
|
compat_int_t spec1;
|
|
|
|
compat_int_t spec2;
|
|
|
|
compat_int_t dtr;
|
|
|
|
unsigned char version;
|
|
|
|
unsigned char dor;
|
|
|
|
compat_ulong_t address;
|
|
|
|
unsigned int rawcmd:2;
|
|
|
|
unsigned int reset:1;
|
|
|
|
unsigned int need_configure:1;
|
|
|
|
unsigned int perp_mode:2;
|
|
|
|
unsigned int has_fifo:1;
|
|
|
|
unsigned int driver_version;
|
|
|
|
unsigned char track[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compat_floppy_write_errors {
|
|
|
|
unsigned int write_errors;
|
|
|
|
compat_ulong_t first_error_sector;
|
|
|
|
compat_int_t first_error_generation;
|
|
|
|
compat_ulong_t last_error_sector;
|
|
|
|
compat_int_t last_error_generation;
|
|
|
|
compat_uint_t badness;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FDSETPRM32 _IOW(2, 0x42, struct compat_floppy_struct)
|
|
|
|
#define FDDEFPRM32 _IOW(2, 0x43, struct compat_floppy_struct)
|
|
|
|
#define FDSETDRVPRM32 _IOW(2, 0x90, struct compat_floppy_drive_params)
|
|
|
|
#define FDGETDRVPRM32 _IOR(2, 0x11, struct compat_floppy_drive_params)
|
|
|
|
#define FDGETDRVSTAT32 _IOR(2, 0x12, struct compat_floppy_drive_struct)
|
|
|
|
#define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct compat_floppy_drive_struct)
|
|
|
|
#define FDGETFDCSTAT32 _IOR(2, 0x15, struct compat_floppy_fdc_state)
|
|
|
|
#define FDWERRORGET32 _IOR(2, 0x17, struct compat_floppy_write_errors)
|
|
|
|
|
|
|
|
static int compat_set_geometry(struct block_device *bdev, fmode_t mode, unsigned int cmd,
|
|
|
|
struct compat_floppy_struct __user *arg)
|
|
|
|
{
|
|
|
|
struct floppy_struct v;
|
|
|
|
int drive, type;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(offsetof(struct floppy_struct, name) !=
|
|
|
|
offsetof(struct compat_floppy_struct, name));
|
|
|
|
|
|
|
|
if (!(mode & (FMODE_WRITE | FMODE_WRITE_IOCTL)))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
memset(&v, 0, sizeof(struct floppy_struct));
|
|
|
|
if (copy_from_user(&v, arg, offsetof(struct floppy_struct, name)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
mutex_lock(&floppy_mutex);
|
|
|
|
drive = (long)bdev->bd_disk->private_data;
|
2020-02-25 00:23:46 +03:00
|
|
|
type = ITYPE(drive_state[drive].fd_device);
|
2017-06-27 22:47:56 +03:00
|
|
|
err = set_geometry(cmd == FDSETPRM32 ? FDSETPRM : FDDEFPRM,
|
|
|
|
&v, drive, type, bdev);
|
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compat_get_prm(int drive,
|
|
|
|
struct compat_floppy_struct __user *arg)
|
|
|
|
{
|
|
|
|
struct compat_floppy_struct v;
|
|
|
|
struct floppy_struct *p;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
memset(&v, 0, sizeof(v));
|
|
|
|
mutex_lock(&floppy_mutex);
|
2020-02-25 00:23:46 +03:00
|
|
|
err = get_floppy_geometry(drive, ITYPE(drive_state[drive].fd_device),
|
|
|
|
&p);
|
2017-06-27 22:47:56 +03:00
|
|
|
if (err) {
|
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
memcpy(&v, p, offsetof(struct floppy_struct, name));
|
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
if (copy_to_user(arg, &v, sizeof(struct compat_floppy_struct)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compat_setdrvprm(int drive,
|
|
|
|
struct compat_floppy_drive_params __user *arg)
|
|
|
|
{
|
|
|
|
struct compat_floppy_drive_params v;
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
if (copy_from_user(&v, arg, sizeof(struct compat_floppy_drive_params)))
|
|
|
|
return -EFAULT;
|
2019-07-12 21:55:22 +03:00
|
|
|
if (!valid_floppy_drive_params(v.autodetect, v.native_format))
|
2019-07-12 21:55:21 +03:00
|
|
|
return -EINVAL;
|
2017-06-27 22:47:56 +03:00
|
|
|
mutex_lock(&floppy_mutex);
|
2020-02-25 00:23:45 +03:00
|
|
|
drive_params[drive].cmos = v.cmos;
|
|
|
|
drive_params[drive].max_dtr = v.max_dtr;
|
|
|
|
drive_params[drive].hlt = v.hlt;
|
|
|
|
drive_params[drive].hut = v.hut;
|
|
|
|
drive_params[drive].srt = v.srt;
|
|
|
|
drive_params[drive].spinup = v.spinup;
|
|
|
|
drive_params[drive].spindown = v.spindown;
|
|
|
|
drive_params[drive].spindown_offset = v.spindown_offset;
|
|
|
|
drive_params[drive].select_delay = v.select_delay;
|
|
|
|
drive_params[drive].rps = v.rps;
|
|
|
|
drive_params[drive].tracks = v.tracks;
|
|
|
|
drive_params[drive].timeout = v.timeout;
|
|
|
|
drive_params[drive].interleave_sect = v.interleave_sect;
|
|
|
|
drive_params[drive].max_errors = v.max_errors;
|
|
|
|
drive_params[drive].flags = v.flags;
|
|
|
|
drive_params[drive].read_track = v.read_track;
|
|
|
|
memcpy(drive_params[drive].autodetect, v.autodetect,
|
|
|
|
sizeof(v.autodetect));
|
|
|
|
drive_params[drive].checkfreq = v.checkfreq;
|
|
|
|
drive_params[drive].native_format = v.native_format;
|
2017-06-27 22:47:56 +03:00
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compat_getdrvprm(int drive,
|
|
|
|
struct compat_floppy_drive_params __user *arg)
|
|
|
|
{
|
|
|
|
struct compat_floppy_drive_params v;
|
|
|
|
|
|
|
|
memset(&v, 0, sizeof(struct compat_floppy_drive_params));
|
|
|
|
mutex_lock(&floppy_mutex);
|
2020-02-25 00:23:45 +03:00
|
|
|
v.cmos = drive_params[drive].cmos;
|
|
|
|
v.max_dtr = drive_params[drive].max_dtr;
|
|
|
|
v.hlt = drive_params[drive].hlt;
|
|
|
|
v.hut = drive_params[drive].hut;
|
|
|
|
v.srt = drive_params[drive].srt;
|
|
|
|
v.spinup = drive_params[drive].spinup;
|
|
|
|
v.spindown = drive_params[drive].spindown;
|
|
|
|
v.spindown_offset = drive_params[drive].spindown_offset;
|
|
|
|
v.select_delay = drive_params[drive].select_delay;
|
|
|
|
v.rps = drive_params[drive].rps;
|
|
|
|
v.tracks = drive_params[drive].tracks;
|
|
|
|
v.timeout = drive_params[drive].timeout;
|
|
|
|
v.interleave_sect = drive_params[drive].interleave_sect;
|
|
|
|
v.max_errors = drive_params[drive].max_errors;
|
|
|
|
v.flags = drive_params[drive].flags;
|
|
|
|
v.read_track = drive_params[drive].read_track;
|
|
|
|
memcpy(v.autodetect, drive_params[drive].autodetect,
|
|
|
|
sizeof(v.autodetect));
|
|
|
|
v.checkfreq = drive_params[drive].checkfreq;
|
|
|
|
v.native_format = drive_params[drive].native_format;
|
2017-06-27 22:47:56 +03:00
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
|
2019-03-27 01:03:48 +03:00
|
|
|
if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_params)))
|
2017-06-27 22:47:56 +03:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compat_getdrvstat(int drive, bool poll,
|
|
|
|
struct compat_floppy_drive_struct __user *arg)
|
|
|
|
{
|
|
|
|
struct compat_floppy_drive_struct v;
|
|
|
|
|
|
|
|
memset(&v, 0, sizeof(struct compat_floppy_drive_struct));
|
|
|
|
mutex_lock(&floppy_mutex);
|
|
|
|
|
|
|
|
if (poll) {
|
|
|
|
if (lock_fdc(drive))
|
|
|
|
goto Eintr;
|
|
|
|
if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
|
|
|
|
goto Eintr;
|
|
|
|
process_fd_request();
|
|
|
|
}
|
2020-02-25 00:23:46 +03:00
|
|
|
v.spinup_date = drive_state[drive].spinup_date;
|
|
|
|
v.select_date = drive_state[drive].select_date;
|
|
|
|
v.first_read_date = drive_state[drive].first_read_date;
|
|
|
|
v.probed_format = drive_state[drive].probed_format;
|
|
|
|
v.track = drive_state[drive].track;
|
|
|
|
v.maxblock = drive_state[drive].maxblock;
|
|
|
|
v.maxtrack = drive_state[drive].maxtrack;
|
|
|
|
v.generation = drive_state[drive].generation;
|
|
|
|
v.keep_data = drive_state[drive].keep_data;
|
|
|
|
v.fd_ref = drive_state[drive].fd_ref;
|
|
|
|
v.fd_device = drive_state[drive].fd_device;
|
|
|
|
v.last_checked = drive_state[drive].last_checked;
|
|
|
|
v.dmabuf = (uintptr_t) drive_state[drive].dmabuf;
|
|
|
|
v.bufblocks = drive_state[drive].bufblocks;
|
2017-06-27 22:47:56 +03:00
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
|
2019-03-27 01:03:48 +03:00
|
|
|
if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_struct)))
|
2017-06-27 22:47:56 +03:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
Eintr:
|
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
return -EINTR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compat_getfdcstat(int drive,
|
|
|
|
struct compat_floppy_fdc_state __user *arg)
|
|
|
|
{
|
|
|
|
struct compat_floppy_fdc_state v32;
|
|
|
|
struct floppy_fdc_state v;
|
|
|
|
|
|
|
|
mutex_lock(&floppy_mutex);
|
2020-02-25 00:23:44 +03:00
|
|
|
v = fdc_state[FDC(drive)];
|
2017-06-27 22:47:56 +03:00
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
|
|
|
|
memset(&v32, 0, sizeof(struct compat_floppy_fdc_state));
|
|
|
|
v32.spec1 = v.spec1;
|
|
|
|
v32.spec2 = v.spec2;
|
|
|
|
v32.dtr = v.dtr;
|
|
|
|
v32.version = v.version;
|
|
|
|
v32.dor = v.dor;
|
|
|
|
v32.address = v.address;
|
|
|
|
v32.rawcmd = v.rawcmd;
|
|
|
|
v32.reset = v.reset;
|
|
|
|
v32.need_configure = v.need_configure;
|
|
|
|
v32.perp_mode = v.perp_mode;
|
|
|
|
v32.has_fifo = v.has_fifo;
|
|
|
|
v32.driver_version = v.driver_version;
|
|
|
|
memcpy(v32.track, v.track, 4);
|
|
|
|
if (copy_to_user(arg, &v32, sizeof(struct compat_floppy_fdc_state)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compat_werrorget(int drive,
|
|
|
|
struct compat_floppy_write_errors __user *arg)
|
|
|
|
{
|
|
|
|
struct compat_floppy_write_errors v32;
|
|
|
|
struct floppy_write_errors v;
|
|
|
|
|
|
|
|
memset(&v32, 0, sizeof(struct compat_floppy_write_errors));
|
|
|
|
mutex_lock(&floppy_mutex);
|
2020-02-25 00:23:47 +03:00
|
|
|
v = write_errors[drive];
|
2017-06-27 22:47:56 +03:00
|
|
|
mutex_unlock(&floppy_mutex);
|
|
|
|
v32.write_errors = v.write_errors;
|
|
|
|
v32.first_error_sector = v.first_error_sector;
|
|
|
|
v32.first_error_generation = v.first_error_generation;
|
|
|
|
v32.last_error_sector = v.last_error_sector;
|
|
|
|
v32.last_error_generation = v.last_error_generation;
|
|
|
|
v32.badness = v.badness;
|
|
|
|
if (copy_to_user(arg, &v32, sizeof(struct compat_floppy_write_errors)))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fd_compat_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
|
|
|
|
unsigned long param)
|
|
|
|
{
|
|
|
|
int drive = (long)bdev->bd_disk->private_data;
|
|
|
|
switch (cmd) {
|
2019-11-28 17:48:10 +03:00
|
|
|
case CDROMEJECT: /* CD-ROM eject */
|
|
|
|
case 0x6470: /* SunOS floppy eject */
|
|
|
|
|
2017-06-27 22:47:56 +03:00
|
|
|
case FDMSGON:
|
|
|
|
case FDMSGOFF:
|
|
|
|
case FDSETEMSGTRESH:
|
|
|
|
case FDFLUSH:
|
|
|
|
case FDWERRORCLR:
|
|
|
|
case FDEJECT:
|
|
|
|
case FDCLRPRM:
|
|
|
|
case FDFMTBEG:
|
|
|
|
case FDRESET:
|
|
|
|
case FDTWADDLE:
|
|
|
|
return fd_ioctl(bdev, mode, cmd, param);
|
|
|
|
case FDSETMAXERRS:
|
|
|
|
case FDGETMAXERRS:
|
|
|
|
case FDGETDRVTYP:
|
|
|
|
case FDFMTEND:
|
|
|
|
case FDFMTTRK:
|
|
|
|
case FDRAWCMD:
|
|
|
|
return fd_ioctl(bdev, mode, cmd,
|
|
|
|
(unsigned long)compat_ptr(param));
|
|
|
|
case FDSETPRM32:
|
|
|
|
case FDDEFPRM32:
|
|
|
|
return compat_set_geometry(bdev, mode, cmd, compat_ptr(param));
|
|
|
|
case FDGETPRM32:
|
|
|
|
return compat_get_prm(drive, compat_ptr(param));
|
|
|
|
case FDSETDRVPRM32:
|
|
|
|
return compat_setdrvprm(drive, compat_ptr(param));
|
|
|
|
case FDGETDRVPRM32:
|
|
|
|
return compat_getdrvprm(drive, compat_ptr(param));
|
|
|
|
case FDPOLLDRVSTAT32:
|
|
|
|
return compat_getdrvstat(drive, true, compat_ptr(param));
|
|
|
|
case FDGETDRVSTAT32:
|
|
|
|
return compat_getdrvstat(drive, false, compat_ptr(param));
|
|
|
|
case FDGETFDCSTAT32:
|
|
|
|
return compat_getfdcstat(drive, compat_ptr(param));
|
|
|
|
case FDWERRORGET32:
|
|
|
|
return compat_werrorget(drive, compat_ptr(param));
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static void __init config_types(void)
|
|
|
|
{
|
2010-03-11 02:20:46 +03:00
|
|
|
bool has_drive = false;
|
2005-04-17 02:20:36 +04:00
|
|
|
int drive;
|
|
|
|
|
|
|
|
/* read drive info out of physical CMOS */
|
|
|
|
drive = 0;
|
2020-02-25 00:23:45 +03:00
|
|
|
if (!drive_params[drive].cmos)
|
|
|
|
drive_params[drive].cmos = FLOPPY0_TYPE;
|
2005-04-17 02:20:36 +04:00
|
|
|
drive = 1;
|
2020-02-25 00:23:45 +03:00
|
|
|
if (!drive_params[drive].cmos)
|
|
|
|
drive_params[drive].cmos = FLOPPY1_TYPE;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-10-17 10:30:57 +04:00
|
|
|
/* FIXME: additional physical CMOS drive detection should go here */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
for (drive = 0; drive < N_DRIVE; drive++) {
|
2020-02-25 00:23:45 +03:00
|
|
|
unsigned int type = drive_params[drive].cmos;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct floppy_drive_params *params;
|
|
|
|
const char *name = NULL;
|
2015-12-01 17:54:01 +03:00
|
|
|
char temparea[32];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-01-08 12:05:11 +03:00
|
|
|
if (type < ARRAY_SIZE(default_drive_params)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
params = &default_drive_params[type].params;
|
|
|
|
if (type) {
|
|
|
|
name = default_drive_params[type].name;
|
|
|
|
allowed_drive_mask |= 1 << drive;
|
|
|
|
} else
|
|
|
|
allowed_drive_mask &= ~(1 << drive);
|
|
|
|
} else {
|
|
|
|
params = &default_drive_params[0].params;
|
2015-12-01 17:54:01 +03:00
|
|
|
snprintf(temparea, sizeof(temparea),
|
|
|
|
"unknown type %d (usb?)", type);
|
2005-04-17 02:20:36 +04:00
|
|
|
name = temparea;
|
|
|
|
}
|
|
|
|
if (name) {
|
2010-03-11 02:20:46 +03:00
|
|
|
const char *prepend;
|
|
|
|
if (!has_drive) {
|
|
|
|
prepend = "";
|
|
|
|
has_drive = true;
|
|
|
|
pr_info("Floppy drive(s):");
|
|
|
|
} else {
|
|
|
|
prepend = ",";
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-03-11 02:20:46 +03:00
|
|
|
|
|
|
|
pr_cont("%s fd%d is %s", prepend, drive, name);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2020-02-25 00:23:45 +03:00
|
|
|
drive_params[drive] = *params;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-03-11 02:20:46 +03:00
|
|
|
|
|
|
|
if (has_drive)
|
|
|
|
pr_cont("\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2013-05-06 05:52:57 +04:00
|
|
|
static void floppy_release(struct gendisk *disk, fmode_t mode)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-03-02 17:27:55 +03:00
|
|
|
int drive = (long)disk->private_data;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_lock(&floppy_mutex);
|
2006-03-23 14:00:26 +03:00
|
|
|
mutex_lock(&open_lock);
|
2020-02-25 00:23:46 +03:00
|
|
|
if (!drive_state[drive].fd_ref--) {
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("floppy_release with fd_ref == 0");
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].fd_ref = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2020-02-25 00:23:46 +03:00
|
|
|
if (!drive_state[drive].fd_ref)
|
2005-04-17 02:20:36 +04:00
|
|
|
opened_bdev[drive] = NULL;
|
2006-03-23 14:00:26 +03:00
|
|
|
mutex_unlock(&open_lock);
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&floppy_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* floppy_open check for aliasing (/dev/fd0 can be the same as
|
|
|
|
* /dev/PS0 etc), and disallows simultaneous access to the same
|
|
|
|
* drive with different device numbers.
|
|
|
|
*/
|
2008-03-02 17:27:55 +03:00
|
|
|
static int floppy_open(struct block_device *bdev, fmode_t mode)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2008-03-02 17:27:55 +03:00
|
|
|
int drive = (long)bdev->bd_disk->private_data;
|
|
|
|
int old_dev, new_dev;
|
2005-04-17 02:20:36 +04:00
|
|
|
int try;
|
|
|
|
int res = -EBUSY;
|
|
|
|
char *tmp;
|
|
|
|
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_lock(&floppy_mutex);
|
2006-03-23 14:00:26 +03:00
|
|
|
mutex_lock(&open_lock);
|
2020-02-25 00:23:46 +03:00
|
|
|
old_dev = drive_state[drive].fd_device;
|
2008-03-02 17:27:55 +03:00
|
|
|
if (opened_bdev[drive] && opened_bdev[drive] != bdev)
|
2005-04-17 02:20:36 +04:00
|
|
|
goto out2;
|
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
if (!drive_state[drive].fd_ref && (drive_params[drive].flags & FD_BROKEN_DCL)) {
|
|
|
|
set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
|
|
|
|
set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].fd_ref++;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-03-02 17:27:55 +03:00
|
|
|
opened_bdev[drive] = bdev;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
res = -ENXIO;
|
|
|
|
|
|
|
|
if (!floppy_track_buffer) {
|
|
|
|
/* if opening an ED drive, reserve a big buffer,
|
|
|
|
* else reserve a small one */
|
2020-02-25 00:23:45 +03:00
|
|
|
if ((drive_params[drive].cmos == 6) || (drive_params[drive].cmos == 5))
|
2005-04-17 02:20:36 +04:00
|
|
|
try = 64; /* Only 48 actually useful */
|
|
|
|
else
|
|
|
|
try = 32; /* Only 24 actually useful */
|
|
|
|
|
|
|
|
tmp = (char *)fd_dma_mem_alloc(1024 * try);
|
|
|
|
if (!tmp && !floppy_track_buffer) {
|
|
|
|
try >>= 1; /* buffer only one side */
|
|
|
|
INFBOUND(try, 16);
|
|
|
|
tmp = (char *)fd_dma_mem_alloc(1024 * try);
|
|
|
|
}
|
2010-03-11 02:20:46 +03:00
|
|
|
if (!tmp && !floppy_track_buffer)
|
2005-04-17 02:20:36 +04:00
|
|
|
fallback_on_nodma_alloc(&tmp, 2048 * try);
|
|
|
|
if (!tmp && !floppy_track_buffer) {
|
|
|
|
DPRINT("Unable to allocate DMA memory\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (floppy_track_buffer) {
|
|
|
|
if (tmp)
|
|
|
|
fd_dma_mem_free((unsigned long)tmp, try * 1024);
|
|
|
|
} else {
|
|
|
|
buffer_min = buffer_max = -1;
|
|
|
|
floppy_track_buffer = tmp;
|
|
|
|
max_buffer_sectors = try;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-02 17:27:55 +03:00
|
|
|
new_dev = MINOR(bdev->bd_dev);
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].fd_device = new_dev;
|
2008-03-02 17:27:55 +03:00
|
|
|
set_capacity(disks[drive], floppy_sizes[new_dev]);
|
|
|
|
if (old_dev != -1 && old_dev != new_dev) {
|
2005-04-17 02:20:36 +04:00
|
|
|
if (buffer_drive == drive)
|
|
|
|
buffer_track = -1;
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:44 +03:00
|
|
|
if (fdc_state[FDC(drive)].rawcmd == 1)
|
|
|
|
fdc_state[FDC(drive)].rawcmd = 2;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2016-08-25 17:56:51 +03:00
|
|
|
if (!(mode & FMODE_NDELAY)) {
|
|
|
|
if (mode & (FMODE_READ|FMODE_WRITE)) {
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].last_checked = 0;
|
|
|
|
clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
|
|
|
|
&drive_state[drive].flags);
|
2016-08-25 17:56:51 +03:00
|
|
|
check_disk_change(bdev);
|
2020-02-25 00:23:46 +03:00
|
|
|
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
|
2016-08-25 17:56:51 +03:00
|
|
|
goto out;
|
2020-02-25 00:23:46 +03:00
|
|
|
if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
|
2016-08-25 17:56:51 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
res = -EROFS;
|
|
|
|
if ((mode & FMODE_WRITE) &&
|
2020-02-25 00:23:46 +03:00
|
|
|
!test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
|
2016-08-25 17:56:51 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2006-03-23 14:00:26 +03:00
|
|
|
mutex_unlock(&open_lock);
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&floppy_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
out:
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].fd_ref--;
|
2012-05-18 15:50:28 +04:00
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
if (!drive_state[drive].fd_ref)
|
2005-04-17 02:20:36 +04:00
|
|
|
opened_bdev[drive] = NULL;
|
|
|
|
out2:
|
2006-03-23 14:00:26 +03:00
|
|
|
mutex_unlock(&open_lock);
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&floppy_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the disk has been changed or if a change has been faked.
|
|
|
|
*/
|
2011-03-09 21:54:27 +03:00
|
|
|
static unsigned int floppy_check_events(struct gendisk *disk,
|
|
|
|
unsigned int clearing)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int drive = (long)disk->private_data;
|
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
|
|
|
|
test_bit(FD_VERIFY_BIT, &drive_state[drive].flags))
|
2011-03-09 21:54:27 +03:00
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
if (time_after(jiffies, drive_state[drive].last_checked + drive_params[drive].checkfreq)) {
|
2016-02-01 13:19:17 +03:00
|
|
|
if (lock_fdc(drive))
|
2019-01-29 11:34:04 +03:00
|
|
|
return 0;
|
2010-03-11 02:20:58 +03:00
|
|
|
poll_drive(false, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
process_fd_request();
|
|
|
|
}
|
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
|
|
|
|
test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
|
2005-04-17 02:20:36 +04:00
|
|
|
test_bit(drive, &fake_change) ||
|
2010-11-08 16:44:34 +03:00
|
|
|
drive_no_geom(drive))
|
2011-03-09 21:54:27 +03:00
|
|
|
return DISK_EVENT_MEDIA_CHANGE;
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This implements "read block 0" for floppy_revalidate().
|
|
|
|
* Needed for format autodetection, checking whether there is
|
|
|
|
* a disk in the drive, and whether that disk is writable.
|
|
|
|
*/
|
|
|
|
|
2014-01-10 05:08:13 +04:00
|
|
|
struct rb0_cbdata {
|
|
|
|
int drive;
|
|
|
|
struct completion complete;
|
|
|
|
};
|
|
|
|
|
2015-07-20 16:29:37 +03:00
|
|
|
static void floppy_rb0_cb(struct bio *bio)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2014-01-10 05:08:13 +04:00
|
|
|
struct rb0_cbdata *cbdata = (struct rb0_cbdata *)bio->bi_private;
|
|
|
|
int drive = cbdata->drive;
|
|
|
|
|
2017-06-03 10:38:06 +03:00
|
|
|
if (bio->bi_status) {
|
2015-07-20 16:29:37 +03:00
|
|
|
pr_info("floppy: error %d while reading block 0\n",
|
2017-06-03 10:38:06 +03:00
|
|
|
bio->bi_status);
|
2020-02-25 00:23:46 +03:00
|
|
|
set_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags);
|
2014-01-10 05:08:13 +04:00
|
|
|
}
|
|
|
|
complete(&cbdata->complete);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2014-01-10 05:08:13 +04:00
|
|
|
static int __floppy_read_block_0(struct block_device *bdev, int drive)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct bio bio;
|
|
|
|
struct bio_vec bio_vec;
|
|
|
|
struct page *page;
|
2014-01-10 05:08:13 +04:00
|
|
|
struct rb0_cbdata cbdata;
|
2005-04-17 02:20:36 +04:00
|
|
|
size_t size;
|
|
|
|
|
|
|
|
page = alloc_page(GFP_NOIO);
|
|
|
|
if (!page) {
|
|
|
|
process_fd_request();
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = bdev->bd_block_size;
|
|
|
|
if (!size)
|
|
|
|
size = 1024;
|
|
|
|
|
2014-01-10 05:08:13 +04:00
|
|
|
cbdata.drive = drive;
|
|
|
|
|
2016-11-22 18:57:21 +03:00
|
|
|
bio_init(&bio, &bio_vec, 1);
|
2017-08-23 20:10:32 +03:00
|
|
|
bio_set_dev(&bio, bdev);
|
2016-11-11 15:05:31 +03:00
|
|
|
bio_add_page(&bio, page, size, 0);
|
|
|
|
|
2013-10-12 02:44:27 +04:00
|
|
|
bio.bi_iter.bi_sector = 0;
|
2014-05-28 13:55:23 +04:00
|
|
|
bio.bi_flags |= (1 << BIO_QUIET);
|
2014-01-10 05:08:13 +04:00
|
|
|
bio.bi_private = &cbdata;
|
|
|
|
bio.bi_end_io = floppy_rb0_cb;
|
2016-06-05 22:31:48 +03:00
|
|
|
bio_set_op_attrs(&bio, REQ_OP_READ, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-11-10 01:58:40 +03:00
|
|
|
init_completion(&cbdata.complete);
|
|
|
|
|
2016-06-05 22:31:41 +03:00
|
|
|
submit_bio(&bio);
|
2005-04-17 02:20:36 +04:00
|
|
|
process_fd_request();
|
2014-01-10 05:08:13 +04:00
|
|
|
|
|
|
|
wait_for_completion(&cbdata.complete);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
__free_page(page);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* revalidate the floppy disk, i.e. trigger format autodetection by reading
|
|
|
|
* the bootblock (block 0). "Autodetection" is also needed to check whether
|
|
|
|
* there is a disk in the drive at all... Thus we also do it for fixed
|
|
|
|
* geometry formats */
|
|
|
|
static int floppy_revalidate(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
int drive = (long)disk->private_data;
|
|
|
|
int cf;
|
|
|
|
int res = 0;
|
|
|
|
|
2020-02-25 00:23:46 +03:00
|
|
|
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
|
|
|
|
test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
|
2010-11-08 16:44:34 +03:00
|
|
|
test_bit(drive, &fake_change) ||
|
|
|
|
drive_no_geom(drive)) {
|
2010-06-15 15:21:11 +04:00
|
|
|
if (WARN(atomic_read(&usage_count) == 0,
|
|
|
|
"VFS: revalidate called on non-open device.\n"))
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EFAULT;
|
2010-06-15 15:21:11 +04:00
|
|
|
|
2016-02-01 13:19:17 +03:00
|
|
|
res = lock_fdc(drive);
|
|
|
|
if (res)
|
|
|
|
return res;
|
2020-02-25 00:23:46 +03:00
|
|
|
cf = (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
|
|
|
|
test_bit(FD_VERIFY_BIT, &drive_state[drive].flags));
|
2010-11-08 16:44:34 +03:00
|
|
|
if (!(cf || test_bit(drive, &fake_change) || drive_no_geom(drive))) {
|
2005-04-17 02:20:36 +04:00
|
|
|
process_fd_request(); /*already done by another thread */
|
|
|
|
return 0;
|
|
|
|
}
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].maxblock = 0;
|
|
|
|
drive_state[drive].maxtrack = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (buffer_drive == drive)
|
|
|
|
buffer_track = -1;
|
|
|
|
clear_bit(drive, &fake_change);
|
2020-02-25 00:23:46 +03:00
|
|
|
clear_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (cf)
|
2020-02-25 00:23:46 +03:00
|
|
|
drive_state[drive].generation++;
|
2010-11-08 16:44:34 +03:00
|
|
|
if (drive_no_geom(drive)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* auto-sensing */
|
2014-01-10 05:08:13 +04:00
|
|
|
res = __floppy_read_block_0(opened_bdev[drive], drive);
|
2005-04-17 02:20:36 +04:00
|
|
|
} else {
|
|
|
|
if (cf)
|
2010-03-11 02:20:58 +03:00
|
|
|
poll_drive(false, FD_RAW_NEED_DISK);
|
2005-04-17 02:20:36 +04:00
|
|
|
process_fd_request();
|
|
|
|
}
|
|
|
|
}
|
2020-02-25 00:23:46 +03:00
|
|
|
set_capacity(disk, floppy_sizes[drive_state[drive].fd_device]);
|
2005-04-17 02:20:36 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-09-22 04:01:13 +04:00
|
|
|
static const struct block_device_operations floppy_fops = {
|
2007-10-17 10:30:57 +04:00
|
|
|
.owner = THIS_MODULE,
|
2008-03-02 17:27:55 +03:00
|
|
|
.open = floppy_open,
|
|
|
|
.release = floppy_release,
|
2010-07-08 12:18:46 +04:00
|
|
|
.ioctl = fd_ioctl,
|
2007-10-17 10:30:57 +04:00
|
|
|
.getgeo = fd_getgeo,
|
2011-03-09 21:54:27 +03:00
|
|
|
.check_events = floppy_check_events,
|
2007-10-17 10:30:57 +04:00
|
|
|
.revalidate_disk = floppy_revalidate,
|
2017-06-27 22:47:56 +03:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = fd_compat_ioctl,
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Floppy Driver initialization
|
|
|
|
* =============================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Determine the floppy disk controller type */
|
|
|
|
/* This routine was written by David C. Niemi */
|
|
|
|
static char __init get_fdc_version(void)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
output_byte(FD_DUMPREGS); /* 82072 and better know DUMPREGS */
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].reset)
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_NONE;
|
2010-03-11 02:20:48 +03:00
|
|
|
r = result();
|
|
|
|
if (r <= 0x00)
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_NONE; /* No FDC present ??? */
|
|
|
|
if ((r == 1) && (reply_buffer[0] == 0x80)) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is an 8272A\n", fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_8272A; /* 8272a/765 don't know DUMPREGS */
|
|
|
|
}
|
|
|
|
if (r != 10) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d init: DUMPREGS: unexpected return of %d bytes.\n",
|
|
|
|
fdc, r);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fdc_configure()) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is an 82072\n", fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_82072; /* 82072 doesn't know CONFIGURE */
|
|
|
|
}
|
|
|
|
|
|
|
|
output_byte(FD_PERPENDICULAR);
|
|
|
|
if (need_more_output() == MORE_OUTPUT) {
|
|
|
|
output_byte(0);
|
|
|
|
} else {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is an 82072A\n", fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_82072A; /* 82072A as found on Sparcs. */
|
|
|
|
}
|
|
|
|
|
|
|
|
output_byte(FD_UNLOCK);
|
|
|
|
r = result();
|
|
|
|
if ((r == 1) && (reply_buffer[0] == 0x80)) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is a pre-1991 82077\n", fdc);
|
2010-03-11 02:20:48 +03:00
|
|
|
return FDC_82077_ORIG; /* Pre-1991 82077, doesn't know
|
2005-04-17 02:20:36 +04:00
|
|
|
* LOCK/UNLOCK */
|
|
|
|
}
|
|
|
|
if ((r != 1) || (reply_buffer[0] != 0x00)) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d init: UNLOCK: unexpected return of %d bytes.\n",
|
|
|
|
fdc, r);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_UNKNOWN;
|
|
|
|
}
|
|
|
|
output_byte(FD_PARTID);
|
|
|
|
r = result();
|
|
|
|
if (r != 1) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n",
|
|
|
|
fdc, r);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_UNKNOWN;
|
|
|
|
}
|
|
|
|
if (reply_buffer[0] == 0x80) {
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is a post-1991 82077\n", fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_82077; /* Revised 82077AA passes all the tests */
|
|
|
|
}
|
|
|
|
switch (reply_buffer[0] >> 5) {
|
|
|
|
case 0x0:
|
|
|
|
/* Either a 82078-1 or a 82078SL running at 5Volt */
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is an 82078.\n", fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_82078;
|
|
|
|
case 0x1:
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is a 44pin 82078\n", fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_82078;
|
|
|
|
case 0x2:
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is a S82078B\n", fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_S82078B;
|
|
|
|
case 0x3:
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d is a National Semiconductor PC87306\n", fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_87306;
|
|
|
|
default:
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("FDC %d init: 82078 variant with unknown PARTID=%d.\n",
|
|
|
|
fdc, reply_buffer[0] >> 5);
|
2005-04-17 02:20:36 +04:00
|
|
|
return FDC_82078_UNKN;
|
|
|
|
}
|
|
|
|
} /* get_fdc_version */
|
|
|
|
|
|
|
|
/* lilo configuration */
|
|
|
|
|
|
|
|
static void __init floppy_set_flags(int *ints, int param, int param2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(default_drive_params); i++) {
|
|
|
|
if (param)
|
|
|
|
default_drive_params[i].params.flags |= param2;
|
|
|
|
else
|
|
|
|
default_drive_params[i].params.flags &= ~param2;
|
|
|
|
}
|
|
|
|
DPRINT("%s flag 0x%x\n", param2 ? "Setting" : "Clearing", param);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init daring(int *ints, int param, int param2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(default_drive_params); i++) {
|
|
|
|
if (param) {
|
|
|
|
default_drive_params[i].params.select_delay = 0;
|
|
|
|
default_drive_params[i].params.flags |=
|
|
|
|
FD_SILENT_DCL_CLEAR;
|
|
|
|
} else {
|
|
|
|
default_drive_params[i].params.select_delay =
|
|
|
|
2 * HZ / 100;
|
|
|
|
default_drive_params[i].params.flags &=
|
|
|
|
~FD_SILENT_DCL_CLEAR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DPRINT("Assuming %s floppy hardware\n", param ? "standard" : "broken");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init set_cmos(int *ints, int dummy, int dummy2)
|
|
|
|
{
|
|
|
|
int current_drive = 0;
|
|
|
|
|
|
|
|
if (ints[0] != 2) {
|
|
|
|
DPRINT("wrong number of parameters for CMOS\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
current_drive = ints[1];
|
|
|
|
if (current_drive < 0 || current_drive >= 8) {
|
|
|
|
DPRINT("bad drive for set_cmos\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if N_FDC > 1
|
|
|
|
if (current_drive >= 4 && !FDC2)
|
|
|
|
FDC2 = 0x370;
|
|
|
|
#endif
|
2020-02-25 00:23:48 +03:00
|
|
|
drive_params[current_drive].cmos = ints[2];
|
2005-04-17 02:20:36 +04:00
|
|
|
DPRINT("setting CMOS code to %d\n", ints[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct param_table {
|
|
|
|
const char *name;
|
|
|
|
void (*fn) (int *ints, int param, int param2);
|
|
|
|
int *var;
|
|
|
|
int def_param;
|
|
|
|
int param2;
|
|
|
|
} config_params[] __initdata = {
|
|
|
|
{"allowed_drive_mask", NULL, &allowed_drive_mask, 0xff, 0}, /* obsolete */
|
|
|
|
{"all_drives", NULL, &allowed_drive_mask, 0xff, 0}, /* obsolete */
|
|
|
|
{"asus_pci", NULL, &allowed_drive_mask, 0x33, 0},
|
|
|
|
{"irq", NULL, &FLOPPY_IRQ, 6, 0},
|
|
|
|
{"dma", NULL, &FLOPPY_DMA, 2, 0},
|
|
|
|
{"daring", daring, NULL, 1, 0},
|
|
|
|
#if N_FDC > 1
|
|
|
|
{"two_fdc", NULL, &FDC2, 0x370, 0},
|
|
|
|
{"one_fdc", NULL, &FDC2, 0, 0},
|
|
|
|
#endif
|
|
|
|
{"thinkpad", floppy_set_flags, NULL, 1, FD_INVERTED_DCL},
|
|
|
|
{"broken_dcl", floppy_set_flags, NULL, 1, FD_BROKEN_DCL},
|
|
|
|
{"messages", floppy_set_flags, NULL, 1, FTD_MSG},
|
|
|
|
{"silent_dcl_clear", floppy_set_flags, NULL, 1, FD_SILENT_DCL_CLEAR},
|
|
|
|
{"debug", floppy_set_flags, NULL, 1, FD_DEBUG},
|
|
|
|
{"nodma", NULL, &can_use_virtual_dma, 1, 0},
|
|
|
|
{"omnibook", NULL, &can_use_virtual_dma, 1, 0},
|
|
|
|
{"yesdma", NULL, &can_use_virtual_dma, 0, 0},
|
|
|
|
{"fifo_depth", NULL, &fifo_depth, 0xa, 0},
|
|
|
|
{"nofifo", NULL, &no_fifo, 0x20, 0},
|
|
|
|
{"usefifo", NULL, &no_fifo, 0, 0},
|
|
|
|
{"cmos", set_cmos, NULL, 0, 0},
|
|
|
|
{"slow", NULL, &slow_floppy, 1, 0},
|
|
|
|
{"unexpected_interrupts", NULL, &print_unex, 1, 0},
|
|
|
|
{"no_unexpected_interrupts", NULL, &print_unex, 0, 0},
|
|
|
|
{"L40SX", NULL, &print_unex, 0, 0}
|
|
|
|
|
|
|
|
EXTRA_FLOPPY_PARAMS
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init floppy_setup(char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int param;
|
|
|
|
int ints[11];
|
|
|
|
|
|
|
|
str = get_options(str, ARRAY_SIZE(ints), ints);
|
|
|
|
if (str) {
|
|
|
|
for (i = 0; i < ARRAY_SIZE(config_params); i++) {
|
|
|
|
if (strcmp(str, config_params[i].name) == 0) {
|
|
|
|
if (ints[0])
|
|
|
|
param = ints[1];
|
|
|
|
else
|
|
|
|
param = config_params[i].def_param;
|
|
|
|
if (config_params[i].fn)
|
2010-03-11 02:20:50 +03:00
|
|
|
config_params[i].fn(ints, param,
|
|
|
|
config_params[i].
|
|
|
|
param2);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (config_params[i].var) {
|
|
|
|
DPRINT("%s=%d\n", str, param);
|
|
|
|
*config_params[i].var = param;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (str) {
|
|
|
|
DPRINT("unknown floppy option [%s]\n", str);
|
|
|
|
|
|
|
|
DPRINT("allowed options are:");
|
|
|
|
for (i = 0; i < ARRAY_SIZE(config_params); i++)
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_cont(" %s", config_params[i].name);
|
|
|
|
pr_cont("\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
} else
|
|
|
|
DPRINT("botched floppy option\n");
|
2019-06-18 17:47:10 +03:00
|
|
|
DPRINT("Read Documentation/admin-guide/blockdev/floppy.rst\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int have_no_fdc = -ENODEV;
|
|
|
|
|
2005-07-28 04:37:34 +04:00
|
|
|
static ssize_t floppy_cmos_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2005-07-15 12:09:25 +04:00
|
|
|
{
|
2009-01-31 17:47:44 +03:00
|
|
|
struct platform_device *p = to_platform_device(dev);
|
2005-07-28 04:37:34 +04:00
|
|
|
int drive;
|
2005-07-15 12:09:25 +04:00
|
|
|
|
2005-07-28 04:37:34 +04:00
|
|
|
drive = p->id;
|
2020-02-25 00:23:45 +03:00
|
|
|
return sprintf(buf, "%X\n", drive_params[drive].cmos);
|
2005-07-15 12:09:25 +04:00
|
|
|
}
|
2010-03-11 02:20:45 +03:00
|
|
|
|
2018-05-24 22:38:59 +03:00
|
|
|
static DEVICE_ATTR(cmos, 0444, floppy_cmos_show, NULL);
|
2005-07-15 12:09:25 +04:00
|
|
|
|
2015-02-02 19:08:45 +03:00
|
|
|
static struct attribute *floppy_dev_attrs[] = {
|
|
|
|
&dev_attr_cmos.attr,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
ATTRIBUTE_GROUPS(floppy_dev);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static void floppy_device_release(struct device *dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-07-26 00:24:54 +04:00
|
|
|
static int floppy_resume(struct device *dev)
|
2009-06-10 23:57:09 +04:00
|
|
|
{
|
|
|
|
int fdc;
|
|
|
|
|
|
|
|
for (fdc = 0; fdc < N_FDC; fdc++)
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].address != -1)
|
2010-03-11 02:20:58 +03:00
|
|
|
user_reset_fdc(-1, FD_RESET_ALWAYS, false);
|
2009-06-10 23:57:09 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-15 05:00:08 +03:00
|
|
|
static const struct dev_pm_ops floppy_pm_ops = {
|
2009-06-10 23:57:09 +04:00
|
|
|
.resume = floppy_resume,
|
2009-07-26 00:24:54 +04:00
|
|
|
.restore = floppy_resume,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver floppy_driver = {
|
2009-06-10 23:57:09 +04:00
|
|
|
.driver = {
|
2010-03-11 02:20:50 +03:00
|
|
|
.name = "floppy",
|
|
|
|
.pm = &floppy_pm_ops,
|
2009-06-10 23:57:09 +04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-10-15 18:21:34 +03:00
|
|
|
static const struct blk_mq_ops floppy_mq_ops = {
|
|
|
|
.queue_rq = floppy_queue_rq,
|
|
|
|
};
|
|
|
|
|
2005-07-15 12:09:25 +04:00
|
|
|
static struct platform_device floppy_device[N_DRIVE];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-08-28 03:56:55 +04:00
|
|
|
static bool floppy_available(int drive)
|
|
|
|
{
|
|
|
|
if (!(allowed_drive_mask & (1 << drive)))
|
|
|
|
return false;
|
|
|
|
if (fdc_state[FDC(drive)].version == FDC_NONE)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static struct kobject *floppy_find(dev_t dev, int *part, void *data)
|
|
|
|
{
|
|
|
|
int drive = (*part & 3) | ((*part & 0x80) >> 5);
|
2012-08-28 03:56:55 +04:00
|
|
|
if (drive >= N_DRIVE || !floppy_available(drive))
|
2005-04-17 02:20:36 +04:00
|
|
|
return NULL;
|
2006-01-08 12:05:11 +03:00
|
|
|
if (((*part >> 2) & 0x1f) >= ARRAY_SIZE(floppy_type))
|
2005-04-17 02:20:36 +04:00
|
|
|
return NULL;
|
|
|
|
*part = 0;
|
2018-02-26 15:01:38 +03:00
|
|
|
return get_disk_and_module(disks[drive]);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2012-07-03 04:27:04 +04:00
|
|
|
static int __init do_floppy_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2012-10-30 11:36:07 +04:00
|
|
|
int i, unit, drive, err;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
set_debugt();
|
|
|
|
interruptjiffies = resultjiffies = jiffies;
|
|
|
|
|
2008-09-23 01:41:31 +04:00
|
|
|
#if defined(CONFIG_PPC)
|
2006-09-01 08:27:41 +04:00
|
|
|
if (check_legacy_ioport(FDC1))
|
|
|
|
return -ENODEV;
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
raw_cmd = NULL;
|
|
|
|
|
2012-08-28 03:56:51 +04:00
|
|
|
floppy_wq = alloc_ordered_workqueue("floppy", 0);
|
|
|
|
if (!floppy_wq)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-10-30 11:36:07 +04:00
|
|
|
for (drive = 0; drive < N_DRIVE; drive++) {
|
|
|
|
disks[drive] = alloc_disk(1);
|
|
|
|
if (!disks[drive]) {
|
2005-04-17 02:20:36 +04:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto out_put_disk;
|
|
|
|
}
|
|
|
|
|
2018-10-15 18:21:34 +03:00
|
|
|
disks[drive]->queue = blk_mq_init_sq_queue(&tag_sets[drive],
|
|
|
|
&floppy_mq_ops, 2,
|
|
|
|
BLK_MQ_F_SHOULD_MERGE);
|
|
|
|
if (IS_ERR(disks[drive]->queue)) {
|
|
|
|
err = PTR_ERR(disks[drive]->queue);
|
|
|
|
disks[drive]->queue = NULL;
|
2012-08-28 03:56:51 +04:00
|
|
|
goto out_put_disk;
|
2010-09-22 11:32:36 +04:00
|
|
|
}
|
|
|
|
|
2017-06-19 10:26:26 +03:00
|
|
|
blk_queue_bounce_limit(disks[drive]->queue, BLK_BOUNCE_HIGH);
|
2012-10-30 11:36:07 +04:00
|
|
|
blk_queue_max_hw_sectors(disks[drive]->queue, 64);
|
|
|
|
disks[drive]->major = FLOPPY_MAJOR;
|
|
|
|
disks[drive]->first_minor = TOMINOR(drive);
|
|
|
|
disks[drive]->fops = &floppy_fops;
|
2019-03-27 16:51:04 +03:00
|
|
|
disks[drive]->events = DISK_EVENT_MEDIA_CHANGE;
|
2012-10-30 11:36:07 +04:00
|
|
|
sprintf(disks[drive]->disk_name, "fd%d", drive);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2017-10-05 03:49:29 +03:00
|
|
|
timer_setup(&motor_off_timer[drive], motor_off_callback, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = register_blkdev(FLOPPY_MAJOR, "fd");
|
|
|
|
if (err)
|
2005-06-21 08:15:16 +04:00
|
|
|
goto out_put_disk;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-06-10 23:57:09 +04:00
|
|
|
err = platform_driver_register(&floppy_driver);
|
|
|
|
if (err)
|
|
|
|
goto out_unreg_blkdev;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
blk_register_region(MKDEV(FLOPPY_MAJOR, 0), 256, THIS_MODULE,
|
|
|
|
floppy_find, NULL, NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
if (ITYPE(i))
|
|
|
|
floppy_sizes[i] = floppy_type[ITYPE(i)].size;
|
|
|
|
else
|
|
|
|
floppy_sizes[i] = MAX_DISK_SIZE << 1;
|
|
|
|
|
2010-03-11 02:21:03 +03:00
|
|
|
reschedule_timeout(MAXTIMEOUT, "floppy init");
|
2005-04-17 02:20:36 +04:00
|
|
|
config_types();
|
|
|
|
|
|
|
|
for (i = 0; i < N_FDC; i++) {
|
|
|
|
fdc = i;
|
2020-02-25 00:23:43 +03:00
|
|
|
memset(&fdc_state[fdc], 0, sizeof(*fdc_state));
|
|
|
|
fdc_state[fdc].dtr = -1;
|
|
|
|
fdc_state[fdc].dor = 0x4;
|
2005-04-17 02:20:36 +04:00
|
|
|
#if defined(__sparc__) || defined(__mc68000__)
|
2010-03-11 02:20:51 +03:00
|
|
|
/*sparcs/sun3x don't have a DOR reset which we can fall back on to */
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef __mc68000__
|
|
|
|
if (MACH_IS_SUN3X)
|
|
|
|
#endif
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].version = FDC_82072A;
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
use_virtual_dma = can_use_virtual_dma & 1;
|
|
|
|
fdc_state[0].address = FDC1;
|
|
|
|
if (fdc_state[0].address == -1) {
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
cancel_delayed_work(&fd_timeout);
|
2005-04-17 02:20:36 +04:00
|
|
|
err = -ENODEV;
|
|
|
|
goto out_unreg_region;
|
|
|
|
}
|
|
|
|
#if N_FDC > 1
|
|
|
|
fdc_state[1].address = FDC2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fdc = 0; /* reset fdc in case of unexpected interrupt */
|
|
|
|
err = floppy_grab_irq_and_dma();
|
|
|
|
if (err) {
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
cancel_delayed_work(&fd_timeout);
|
2005-04-17 02:20:36 +04:00
|
|
|
err = -EBUSY;
|
|
|
|
goto out_unreg_region;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialise drive state */
|
|
|
|
for (drive = 0; drive < N_DRIVE; drive++) {
|
2020-02-25 00:23:46 +03:00
|
|
|
memset(&drive_state[drive], 0, sizeof(drive_state[drive]));
|
2020-02-25 00:23:47 +03:00
|
|
|
memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
|
2020-02-25 00:23:46 +03:00
|
|
|
set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
|
|
|
|
set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
|
|
|
|
set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
|
|
|
|
drive_state[drive].fd_device = -1;
|
2005-04-17 02:20:36 +04:00
|
|
|
floppy_track_buffer = NULL;
|
|
|
|
max_buffer_sectors = 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Small 10 msec delay to let through any interrupt that
|
|
|
|
* initialization might have triggered, to not
|
|
|
|
* confuse detection:
|
|
|
|
*/
|
|
|
|
msleep(10);
|
|
|
|
|
|
|
|
for (i = 0; i < N_FDC; i++) {
|
|
|
|
fdc = i;
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].driver_version = FD_DRIVER_VERSION;
|
2005-04-17 02:20:36 +04:00
|
|
|
for (unit = 0; unit < 4; unit++)
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].track[unit] = 0;
|
|
|
|
if (fdc_state[fdc].address == -1)
|
2005-04-17 02:20:36 +04:00
|
|
|
continue;
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].rawcmd = 2;
|
2010-03-11 02:20:58 +03:00
|
|
|
if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* free ioports reserved by floppy_grab_irq_and_dma() */
|
2009-02-19 01:48:36 +03:00
|
|
|
floppy_release_regions(fdc);
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].address = -1;
|
|
|
|
fdc_state[fdc].version = FDC_NONE;
|
2005-04-17 02:20:36 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Try to determine the floppy controller type */
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].version = get_fdc_version();
|
|
|
|
if (fdc_state[fdc].version == FDC_NONE) {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* free ioports reserved by floppy_grab_irq_and_dma() */
|
2009-02-19 01:48:36 +03:00
|
|
|
floppy_release_regions(fdc);
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].address = -1;
|
2005-04-17 02:20:36 +04:00
|
|
|
continue;
|
|
|
|
}
|
2020-02-25 00:23:43 +03:00
|
|
|
if (can_use_virtual_dma == 2 && fdc_state[fdc].version < FDC_82072A)
|
2005-04-17 02:20:36 +04:00
|
|
|
can_use_virtual_dma = 0;
|
|
|
|
|
|
|
|
have_no_fdc = 0;
|
|
|
|
/* Not all FDCs seem to be able to handle the version command
|
|
|
|
* properly, so force a reset for the standard FDC clones,
|
|
|
|
* to avoid interrupt garbage.
|
|
|
|
*/
|
2010-03-11 02:20:58 +03:00
|
|
|
user_reset_fdc(-1, FD_RESET_ALWAYS, false);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
fdc = 0;
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
cancel_delayed_work(&fd_timeout);
|
2005-04-17 02:20:36 +04:00
|
|
|
current_drive = 0;
|
2010-03-11 02:21:00 +03:00
|
|
|
initialized = true;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (have_no_fdc) {
|
|
|
|
DPRINT("no floppy controllers found\n");
|
|
|
|
err = have_no_fdc;
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
goto out_release_dma;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (drive = 0; drive < N_DRIVE; drive++) {
|
2012-08-28 03:56:55 +04:00
|
|
|
if (!floppy_available(drive))
|
2005-04-17 02:20:36 +04:00
|
|
|
continue;
|
2005-07-15 12:09:25 +04:00
|
|
|
|
|
|
|
floppy_device[drive].name = floppy_device_name;
|
|
|
|
floppy_device[drive].id = drive;
|
|
|
|
floppy_device[drive].dev.release = floppy_device_release;
|
2015-02-02 19:08:45 +03:00
|
|
|
floppy_device[drive].dev.groups = floppy_dev_groups;
|
2005-07-15 12:09:25 +04:00
|
|
|
|
|
|
|
err = platform_device_register(&floppy_device[drive]);
|
|
|
|
if (err)
|
2012-08-28 03:56:54 +04:00
|
|
|
goto out_remove_drives;
|
2005-07-15 12:09:25 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* to be cleaned up... */
|
|
|
|
disks[drive]->private_data = (void *)(long)drive;
|
|
|
|
disks[drive]->flags |= GENHD_FL_REMOVABLE;
|
2018-09-28 09:17:19 +03:00
|
|
|
device_add_disk(&floppy_device[drive].dev, disks[drive], NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2012-08-28 03:56:54 +04:00
|
|
|
out_remove_drives:
|
|
|
|
while (drive--) {
|
2012-08-28 03:56:55 +04:00
|
|
|
if (floppy_available(drive)) {
|
2012-08-28 03:56:54 +04:00
|
|
|
del_gendisk(disks[drive]);
|
|
|
|
platform_device_unregister(&floppy_device[drive]);
|
|
|
|
}
|
|
|
|
}
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
out_release_dma:
|
2010-06-15 15:21:11 +04:00
|
|
|
if (atomic_read(&usage_count))
|
2005-04-17 02:20:36 +04:00
|
|
|
floppy_release_irq_and_dma();
|
|
|
|
out_unreg_region:
|
|
|
|
blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
|
2009-06-10 23:57:09 +04:00
|
|
|
platform_driver_unregister(&floppy_driver);
|
2005-04-17 02:20:36 +04:00
|
|
|
out_unreg_blkdev:
|
|
|
|
unregister_blkdev(FLOPPY_MAJOR, "fd");
|
|
|
|
out_put_disk:
|
2012-11-06 14:47:13 +04:00
|
|
|
destroy_workqueue(floppy_wq);
|
2012-10-30 11:36:07 +04:00
|
|
|
for (drive = 0; drive < N_DRIVE; drive++) {
|
|
|
|
if (!disks[drive])
|
|
|
|
break;
|
|
|
|
if (disks[drive]->queue) {
|
|
|
|
del_timer_sync(&motor_off_timer[drive]);
|
|
|
|
blk_cleanup_queue(disks[drive]->queue);
|
|
|
|
disks[drive]->queue = NULL;
|
2018-10-15 18:21:34 +03:00
|
|
|
blk_mq_free_tag_set(&tag_sets[drive]);
|
2012-02-08 23:03:38 +04:00
|
|
|
}
|
2012-10-30 11:36:07 +04:00
|
|
|
put_disk(disks[drive]);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-07-03 04:27:04 +04:00
|
|
|
#ifndef MODULE
|
|
|
|
static __init void floppy_async_init(void *data, async_cookie_t cookie)
|
|
|
|
{
|
|
|
|
do_floppy_init();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int __init floppy_init(void)
|
|
|
|
{
|
|
|
|
#ifdef MODULE
|
|
|
|
return do_floppy_init();
|
|
|
|
#else
|
|
|
|
/* Don't hold up the bootup by the floppy initialization */
|
|
|
|
async_schedule(floppy_async_init, NULL);
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-19 01:48:36 +03:00
|
|
|
static const struct io_region {
|
|
|
|
int offset;
|
|
|
|
int size;
|
|
|
|
} io_regions[] = {
|
|
|
|
{ 2, 1 },
|
|
|
|
/* address + 3 is sometimes reserved by pnp bios for motherboard */
|
|
|
|
{ 4, 2 },
|
|
|
|
/* address + 6 is reserved, and may be taken by IDE.
|
|
|
|
* Unfortunately, Adaptec doesn't know this :-(, */
|
|
|
|
{ 7, 1 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void floppy_release_allocated_regions(int fdc, const struct io_region *p)
|
|
|
|
{
|
|
|
|
while (p != io_regions) {
|
|
|
|
p--;
|
2020-02-25 00:23:43 +03:00
|
|
|
release_region(fdc_state[fdc].address + p->offset, p->size);
|
2009-02-19 01:48:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ARRAY_END(X) (&((X)[ARRAY_SIZE(X)]))
|
|
|
|
|
|
|
|
static int floppy_request_regions(int fdc)
|
|
|
|
{
|
|
|
|
const struct io_region *p;
|
|
|
|
|
|
|
|
for (p = io_regions; p < ARRAY_END(io_regions); p++) {
|
2020-02-25 00:23:43 +03:00
|
|
|
if (!request_region(fdc_state[fdc].address + p->offset,
|
2010-03-11 02:20:50 +03:00
|
|
|
p->size, "floppy")) {
|
|
|
|
DPRINT("Floppy io-port 0x%04lx in use\n",
|
2020-02-25 00:23:43 +03:00
|
|
|
fdc_state[fdc].address + p->offset);
|
2009-02-19 01:48:36 +03:00
|
|
|
floppy_release_allocated_regions(fdc, p);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void floppy_release_regions(int fdc)
|
|
|
|
{
|
|
|
|
floppy_release_allocated_regions(fdc, ARRAY_END(io_regions));
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
static int floppy_grab_irq_and_dma(void)
|
|
|
|
{
|
2010-06-15 15:21:11 +04:00
|
|
|
if (atomic_inc_return(&usage_count) > 1)
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
2006-03-26 13:36:54 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We might have scheduled a free_irq(), wait it to
|
|
|
|
* drain first:
|
|
|
|
*/
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
flush_workqueue(floppy_wq);
|
2006-03-26 13:36:54 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (fd_request_irq()) {
|
|
|
|
DPRINT("Unable to grab IRQ%d for the floppy driver\n",
|
|
|
|
FLOPPY_IRQ);
|
2010-06-15 15:21:11 +04:00
|
|
|
atomic_dec(&usage_count);
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (fd_request_dma()) {
|
|
|
|
DPRINT("Unable to grab DMA%d for the floppy driver\n",
|
|
|
|
FLOPPY_DMA);
|
2007-10-17 10:27:32 +04:00
|
|
|
if (can_use_virtual_dma & 2)
|
|
|
|
use_virtual_dma = can_use_virtual_dma = 1;
|
|
|
|
if (!(can_use_virtual_dma & 1)) {
|
|
|
|
fd_free_irq();
|
2010-06-15 15:21:11 +04:00
|
|
|
atomic_dec(&usage_count);
|
2007-10-17 10:27:32 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (fdc = 0; fdc < N_FDC; fdc++) {
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].address != -1) {
|
2009-02-19 01:48:36 +03:00
|
|
|
if (floppy_request_regions(fdc))
|
|
|
|
goto cleanup;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (fdc = 0; fdc < N_FDC; fdc++) {
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].address != -1) {
|
2005-04-17 02:20:36 +04:00
|
|
|
reset_fdc_info(1);
|
2020-02-25 00:23:43 +03:00
|
|
|
fd_outb(fdc_state[fdc].dor, FD_DOR);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fdc = 0;
|
|
|
|
set_dor(0, ~0, 8); /* avoid immediate interrupt */
|
|
|
|
|
|
|
|
for (fdc = 0; fdc < N_FDC; fdc++)
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].address != -1)
|
|
|
|
fd_outb(fdc_state[fdc].dor, FD_DOR);
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2007-10-17 10:30:57 +04:00
|
|
|
* The driver will try and free resources and relies on us
|
|
|
|
* to know if they were allocated or not.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
|
|
|
fdc = 0;
|
|
|
|
irqdma_allocated = 1;
|
|
|
|
return 0;
|
2009-02-19 01:48:36 +03:00
|
|
|
cleanup:
|
2005-04-17 02:20:36 +04:00
|
|
|
fd_free_irq();
|
|
|
|
fd_free_dma();
|
2009-02-19 01:48:36 +03:00
|
|
|
while (--fdc >= 0)
|
|
|
|
floppy_release_regions(fdc);
|
2010-06-15 15:21:11 +04:00
|
|
|
atomic_dec(&usage_count);
|
2005-04-17 02:20:36 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void floppy_release_irq_and_dma(void)
|
|
|
|
{
|
|
|
|
int old_fdc;
|
|
|
|
#ifndef __sparc__
|
|
|
|
int drive;
|
|
|
|
#endif
|
|
|
|
long tmpsize;
|
|
|
|
unsigned long tmpaddr;
|
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
if (!atomic_dec_and_test(&usage_count))
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
2010-06-15 15:21:11 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (irqdma_allocated) {
|
|
|
|
fd_disable_dma();
|
|
|
|
fd_free_dma();
|
2006-07-03 11:24:23 +04:00
|
|
|
fd_free_irq();
|
2005-04-17 02:20:36 +04:00
|
|
|
irqdma_allocated = 0;
|
|
|
|
}
|
|
|
|
set_dor(0, ~0, 8);
|
|
|
|
#if N_FDC > 1
|
|
|
|
set_dor(1, ~8, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (floppy_track_buffer && max_buffer_sectors) {
|
|
|
|
tmpsize = max_buffer_sectors * 1024;
|
|
|
|
tmpaddr = (unsigned long)floppy_track_buffer;
|
|
|
|
floppy_track_buffer = NULL;
|
|
|
|
max_buffer_sectors = 0;
|
|
|
|
buffer_min = buffer_max = -1;
|
|
|
|
fd_dma_mem_free(tmpaddr, tmpsize);
|
|
|
|
}
|
|
|
|
#ifndef __sparc__
|
|
|
|
for (drive = 0; drive < N_FDC * 4; drive++)
|
|
|
|
if (timer_pending(motor_off_timer + drive))
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("motor off timer %d still active\n", drive);
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
if (delayed_work_pending(&fd_timeout))
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("floppy timer still active:%s\n", timeout_message);
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
if (delayed_work_pending(&fd_timer))
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("auxiliary floppy timer still active\n");
|
2006-11-22 17:54:49 +03:00
|
|
|
if (work_pending(&floppy_work))
|
2010-03-11 02:20:46 +03:00
|
|
|
pr_info("work still pending\n");
|
2005-04-17 02:20:36 +04:00
|
|
|
old_fdc = fdc;
|
|
|
|
for (fdc = 0; fdc < N_FDC; fdc++)
|
2020-02-25 00:23:43 +03:00
|
|
|
if (fdc_state[fdc].address != -1)
|
2009-02-19 01:48:36 +03:00
|
|
|
floppy_release_regions(fdc);
|
2005-04-17 02:20:36 +04:00
|
|
|
fdc = old_fdc;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MODULE
|
|
|
|
|
|
|
|
static char *floppy;
|
|
|
|
|
|
|
|
static void __init parse_floppy_cfg_string(char *cfg)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
while (*cfg) {
|
2010-03-11 02:20:50 +03:00
|
|
|
ptr = cfg;
|
|
|
|
while (*cfg && *cfg != ' ' && *cfg != '\t')
|
|
|
|
cfg++;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (*cfg) {
|
|
|
|
*cfg = '\0';
|
|
|
|
cfg++;
|
|
|
|
}
|
|
|
|
if (*ptr)
|
|
|
|
floppy_setup(ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-29 11:59:21 +04:00
|
|
|
static int __init floppy_module_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
if (floppy)
|
|
|
|
parse_floppy_cfg_string(floppy);
|
|
|
|
return floppy_init();
|
|
|
|
}
|
2008-04-29 11:59:21 +04:00
|
|
|
module_init(floppy_module_init);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-04-29 11:59:21 +04:00
|
|
|
static void __exit floppy_module_exit(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int drive;
|
|
|
|
|
|
|
|
blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
|
|
|
|
unregister_blkdev(FLOPPY_MAJOR, "fd");
|
2009-06-10 23:57:09 +04:00
|
|
|
platform_driver_unregister(&floppy_driver);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-11-06 14:47:13 +04:00
|
|
|
destroy_workqueue(floppy_wq);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
for (drive = 0; drive < N_DRIVE; drive++) {
|
|
|
|
del_timer_sync(&motor_off_timer[drive]);
|
|
|
|
|
2012-08-28 03:56:55 +04:00
|
|
|
if (floppy_available(drive)) {
|
2005-04-17 02:20:36 +04:00
|
|
|
del_gendisk(disks[drive]);
|
2005-07-15 12:09:25 +04:00
|
|
|
platform_device_unregister(&floppy_device[drive]);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2010-09-22 11:32:36 +04:00
|
|
|
blk_cleanup_queue(disks[drive]->queue);
|
2018-10-15 18:21:34 +03:00
|
|
|
blk_mq_free_tag_set(&tag_sets[drive]);
|
2012-02-08 23:03:39 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These disks have not called add_disk(). Don't put down
|
|
|
|
* queue reference in put_disk().
|
|
|
|
*/
|
|
|
|
if (!(allowed_drive_mask & (1 << drive)) ||
|
|
|
|
fdc_state[FDC(drive)].version == FDC_NONE)
|
|
|
|
disks[drive]->queue = NULL;
|
|
|
|
|
2010-11-06 15:16:05 +03:00
|
|
|
put_disk(disks[drive]);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
floppy: convert to delayed work and single-thread wq
There are several races in floppy driver between bottom half
(scheduled_work) and timers (fd_timeout, fd_timer). Due to slowness
of the actual floppy devices, those races are never (at least to my
knowledge) triggered on a bare floppy metal. However on virtualized
(emulated) floppy drives, which are of course magnitudes faster
than the real ones, these races trigger reliably. They usually exhibit
themselves as NULL pointer dereferences during DMA setup, such as
BUG: unable to handle kernel NULL pointer dereference at 0000000a
[ ... snip ... ]
EIP: 0060:[<c02053d5>] EFLAGS: 00010293 CPU: 0
EAX: ffffe000 EBX: 0000000a ECX: 00000000 EDX: 0000000a
ESI: c05d2718 EDI: 00000000 EBP: 00000000 ESP: f540fe44
DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068
Process swapper (pid: 0, ti=f540e000 task=c082d5a0 task.ti=c0826000)
Stack:
ffffe000 00001ffc 00000000 00000000 00000000 c05d2718 c0708b40 f540fe80
c020470f c05d2718 c0708b40 00000000 f540fe80 0000000a f540fee4 00000000
c0708b40 f540fee4 00000000 00000000 c020526b 00000000 c05d2718 c0708b40
Call Trace:
[<c020470f>] dump_trace+0xaf/0x110
[<c020526b>] show_trace_log_lvl+0x4b/0x60
[<c0205298>] show_trace+0x18/0x20
[<c05c5811>] dump_stack+0x6d/0x72
[<c0248527>] warn_slowpath_common+0x77/0xb0
[<c02485f3>] warn_slowpath_fmt+0x33/0x40
[<f7ec593c>] setup_DMA+0x14c/0x210 [floppy]
[<f7ecaa95>] setup_rw_floppy+0x105/0x190 [floppy]
[<c0256d08>] run_timer_softirq+0x168/0x2a0
[<c024e762>] __do_softirq+0xc2/0x1c0
[<c02042ed>] do_softirq+0x7d/0xb0
[<f54d8a00>] 0xf54d89ff
but other instances can be easily seen as well. This can be observed at least under
VMWare, VirtualBox and KVM.
This patch converts all the timers and bottom halfs to be processed in a single
workqueue. This aproach has been already discussed back in 2010 if I remember
correctly, and Acked by Linus [1], but it then never made it to the tree.
This all is based on original idea and code of Stephen Hemminger. I have
ported original Stepen's code to the current state of the floppy driver, and
performed quite some testing (on real hardware), which didn't reveal any issues
(this includes not only writing and reading data, but also formatting
(unfortunately I didn't find any Double-Density disks any more)). Ability to
handle errors properly (supplying known bad floppies) has also been verified.
[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/6/11/4582092
Based-on-patch-by: Stephen Hemminger <shemminger@vyatta.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-05-18 15:50:25 +04:00
|
|
|
cancel_delayed_work_sync(&fd_timeout);
|
|
|
|
cancel_delayed_work_sync(&fd_timer);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-06-15 15:21:11 +04:00
|
|
|
if (atomic_read(&usage_count))
|
2005-04-17 02:20:36 +04:00
|
|
|
floppy_release_irq_and_dma();
|
|
|
|
|
|
|
|
/* eject disk, if any */
|
|
|
|
fd_eject(0);
|
|
|
|
}
|
2010-03-11 02:20:45 +03:00
|
|
|
|
2008-04-29 11:59:21 +04:00
|
|
|
module_exit(floppy_module_exit);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
module_param(floppy, charp, 0);
|
|
|
|
module_param(FLOPPY_IRQ, int, 0);
|
|
|
|
module_param(FLOPPY_DMA, int, 0);
|
|
|
|
MODULE_AUTHOR("Alain L. Knaff");
|
|
|
|
MODULE_SUPPORTED_DEVICE("fd");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2009-04-03 03:56:47 +04:00
|
|
|
/* This doesn't actually get used other than for module information */
|
|
|
|
static const struct pnp_device_id floppy_pnpids[] = {
|
2010-03-11 02:20:45 +03:00
|
|
|
{"PNP0700", 0},
|
|
|
|
{}
|
2009-04-03 03:56:47 +04:00
|
|
|
};
|
2010-03-11 02:20:45 +03:00
|
|
|
|
2009-04-03 03:56:47 +04:00
|
|
|
MODULE_DEVICE_TABLE(pnp, floppy_pnpids);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
__setup("floppy=", floppy_setup);
|
|
|
|
module_init(floppy_init)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MODULE_ALIAS_BLOCKDEV_MAJOR(FLOPPY_MAJOR);
|