提交 06f748c4 编写于 作者: J Jesper Juhl 提交者: Linus Torvalds

floppy: do a very minimal style cleanup of the floppy driver

Yes, some of this will likely be replaced in later patches, but I do not see
anyone else coming out of the woodwork with any patches for this driver, so
I'll ignore comments about churn.  I want to get this driver cleaned up, and
if I'm going to do so I want to start with this basic style cleanup to reduce
the reading pain a bit.
Signed-off-by: NJesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 d2da272a
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Copyright (C) 1993, 1994 Alain Knaff * Copyright (C) 1993, 1994 Alain Knaff
* Copyright (C) 1998 Alan Cox * Copyright (C) 1998 Alan Cox
*/ */
/* /*
* 02.12.91 - Changed to static variables to indicate need for reset * 02.12.91 - Changed to static variables to indicate need for reset
* and recalibrate. This makes some things easier (output_byte reset * and recalibrate. This makes some things easier (output_byte reset
...@@ -149,7 +150,7 @@ ...@@ -149,7 +150,7 @@
#define REALLY_SLOW_IO #define REALLY_SLOW_IO
#define DEBUGT 2 #define DEBUGT 2
#define DCL_DEBUG /* debug disk change line */ #define DCL_DEBUG /* debug disk change line */
/* do print messages for unexpected interrupts */ /* do print messages for unexpected interrupts */
static int print_unex = 1; static int print_unex = 1;
...@@ -161,10 +162,8 @@ static int print_unex = 1; ...@@ -161,10 +162,8 @@ static int print_unex = 1;
#include <linux/workqueue.h> #include <linux/workqueue.h>
#define FDPATCHES #define FDPATCHES
#include <linux/fdreg.h> #include <linux/fdreg.h>
#include <linux/fd.h> #include <linux/fd.h>
#include <linux/hdreg.h> #include <linux/hdreg.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/mm.h> #include <linux/mm.h>
...@@ -274,8 +273,7 @@ static inline void fallback_on_nodma_alloc(char **addr, size_t l) ...@@ -274,8 +273,7 @@ static inline void fallback_on_nodma_alloc(char **addr, size_t l)
return; /* we have the memory */ return; /* we have the memory */
if (can_use_virtual_dma != 2) if (can_use_virtual_dma != 2)
return; /* no fallback allowed */ return; /* no fallback allowed */
printk printk("DMA memory shortage. Temporarily falling back on virtual DMA\n");
("DMA memory shortage. Temporarily falling back on virtual DMA\n");
*addr = (char *)nodma_mem_alloc(l); *addr = (char *)nodma_mem_alloc(l);
#else #else
return; return;
...@@ -291,8 +289,8 @@ static int initialising = 1; ...@@ -291,8 +289,8 @@ static int initialising = 1;
#define TOMINOR(x) ((x & 3) | ((x & 4) << 5)) #define TOMINOR(x) ((x & 3) | ((x & 4) << 5))
#define UNIT(x) ((x) & 0x03) /* drive on fdc */ #define UNIT(x) ((x) & 0x03) /* drive on fdc */
#define FDC(x) (((x) & 0x04) >> 2) /* fdc of drive */ #define FDC(x) (((x) & 0x04) >> 2) /* fdc of drive */
/* reverse mapping from unit and fdc to drive */
#define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2)) #define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2))
/* reverse mapping from unit and fdc to drive */
#define DP (&drive_params[current_drive]) #define DP (&drive_params[current_drive])
#define DRS (&drive_state[current_drive]) #define DRS (&drive_state[current_drive])
#define DRWE (&write_errors[current_drive]) #define DRWE (&write_errors[current_drive])
...@@ -356,7 +354,6 @@ static int inr; /* size of reply buffer, when called from interrupt */ ...@@ -356,7 +354,6 @@ static int inr; /* size of reply buffer, when called from interrupt */
#define R_HEAD (reply_buffer[4]) #define R_HEAD (reply_buffer[4])
#define R_SECTOR (reply_buffer[5]) #define R_SECTOR (reply_buffer[5])
#define R_SIZECODE (reply_buffer[6]) #define R_SIZECODE (reply_buffer[6])
#define SEL_DLY (2*HZ/100) #define SEL_DLY (2*HZ/100)
/* /*
...@@ -472,8 +469,8 @@ static struct floppy_struct floppy_type[32] = { ...@@ -472,8 +469,8 @@ static struct floppy_struct floppy_type[32] = {
{ 6400,40,2,80,0,0x25,0x5B,0xCF,0x00,"E3200" }, /* 26 3.20MB 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" */ { 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" */ { 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" */ { 3680,23,2,80,0,0x1C,0x10,0xCF,0x00,"H1840" }, /* 29 1.84MB 3.5" */
{ 1600,10,2,80,0,0x25,0x02,0xDF,0x2E,"D800" }, /* 30 800KB 3.5" */ { 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" */ { 3200,20,2,80,0,0x1C,0x00,0xCF,0x2C,"H1600" }, /* 31 1.6MB 3.5" */
}; };
...@@ -539,12 +536,12 @@ static char *floppy_track_buffer; ...@@ -539,12 +536,12 @@ static char *floppy_track_buffer;
static int max_buffer_sectors; static int max_buffer_sectors;
static int *errors; static int *errors;
typedef void (*done_f) (int); typedef void (*done_f)(int);
static struct cont_t { static struct cont_t {
void (*interrupt) (void); /* this is called after the interrupt of the void (*interrupt)(void); /* this is called after the interrupt of the
* main command */ * main command */
void (*redo) (void); /* this is called to retry the operation */ void (*redo)(void); /* this is called to retry the operation */
void (*error) (void); /* this is called to tally an error */ void (*error)(void); /* this is called to tally an error */
done_f done; /* this is called to say if the operation has done_f done; /* this is called to say if the operation has
* succeeded/failed */ * succeeded/failed */
} *cont; } *cont;
...@@ -694,7 +691,6 @@ static void reschedule_timeout(int drive, const char *message, int marg) ...@@ -694,7 +691,6 @@ static void reschedule_timeout(int drive, const char *message, int marg)
} }
#define INFBOUND(a,b) (a)=max_t(int, a, b) #define INFBOUND(a,b) (a)=max_t(int, a, b)
#define SUPBOUND(a,b) (a)=min_t(int, a, b) #define SUPBOUND(a,b) (a)=min_t(int, a, b)
/* /*
...@@ -733,6 +729,7 @@ static void reschedule_timeout(int drive, const char *message, int marg) ...@@ -733,6 +729,7 @@ static void reschedule_timeout(int drive, const char *message, int marg)
static int disk_change(int drive) static int disk_change(int drive)
{ {
int fdc = FDC(drive); int fdc = FDC(drive);
#ifdef FLOPPY_SANITY_CHECK #ifdef FLOPPY_SANITY_CHECK
if (time_before(jiffies, UDRS->select_date + UDP->select_delay)) if (time_before(jiffies, UDRS->select_date + UDP->select_delay))
DPRINT("WARNING disk change called early\n"); DPRINT("WARNING disk change called early\n");
...@@ -892,7 +889,6 @@ static int _lock_fdc(int drive, int interruptible, int line) ...@@ -892,7 +889,6 @@ static int _lock_fdc(int drive, int interruptible, int line)
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
remove_wait_queue(&fdc_wait, &wait); remove_wait_queue(&fdc_wait, &wait);
flush_scheduled_work(); flush_scheduled_work();
} }
command_status = FD_COMMAND_NONE; command_status = FD_COMMAND_NONE;
...@@ -968,7 +964,9 @@ static void floppy_off(unsigned int drive) ...@@ -968,7 +964,9 @@ static void floppy_off(unsigned int drive)
*/ */
static void scandrives(void) static void scandrives(void)
{ {
int i, drive, saved_drive; int i;
int drive;
int saved_drive;
if (DP->select_delay) if (DP->select_delay)
return; return;
...@@ -1146,7 +1144,9 @@ static void show_floppy(void); ...@@ -1146,7 +1144,9 @@ static void show_floppy(void);
/* waits until the fdc becomes ready */ /* waits until the fdc becomes ready */
static int wait_til_ready(void) static int wait_til_ready(void)
{ {
int counter, status; int status;
int counter;
if (FDCS->reset) if (FDCS->reset)
return -1; return -1;
for (counter = 0; counter < 10000; counter++) { for (counter = 0; counter < 10000; counter++) {
...@@ -1193,7 +1193,8 @@ static int output_byte(char byte) ...@@ -1193,7 +1193,8 @@ static int output_byte(char byte)
/* gets the response from the fdc */ /* gets the response from the fdc */
static int result(void) static int result(void)
{ {
int i, status = 0; int i;
int status = 0;
for (i = 0; i < MAX_REPLIES; i++) { for (i = 0; i < MAX_REPLIES; i++) {
if ((status = wait_til_ready()) < 0) if ((status = wait_til_ready()) < 0)
...@@ -1226,6 +1227,7 @@ static int result(void) ...@@ -1226,6 +1227,7 @@ static int result(void)
static int need_more_output(void) static int need_more_output(void)
{ {
int status; int status;
if ((status = wait_til_ready()) < 0) if ((status = wait_til_ready()) < 0)
return -1; return -1;
if ((status & (STATUS_READY | STATUS_DIR | STATUS_DMA)) == STATUS_READY) if ((status & (STATUS_READY | STATUS_DIR | STATUS_DMA)) == STATUS_READY)
...@@ -1309,8 +1311,11 @@ static int fdc_configure(void) ...@@ -1309,8 +1311,11 @@ static int fdc_configure(void)
*/ */
static void fdc_specify(void) static void fdc_specify(void)
{ {
unsigned char spec1, spec2; unsigned char spec1;
unsigned long srt, hlt, hut; unsigned char spec2;
unsigned long srt;
unsigned long hlt;
unsigned long hut;
unsigned long dtr = NOMINAL_DTR; unsigned long dtr = NOMINAL_DTR;
unsigned long scale_dtr = NOMINAL_DTR; unsigned long scale_dtr = NOMINAL_DTR;
int hlt_max_code = 0x7f; int hlt_max_code = 0x7f;
...@@ -1472,7 +1477,6 @@ static int interpret_errors(void) ...@@ -1472,7 +1477,6 @@ static int interpret_errors(void)
tell_sector(); tell_sector();
} }
printk("\n"); printk("\n");
} }
if (ST2 & ST2_WC || ST2 & ST2_BC) if (ST2 & ST2_WC || ST2 & ST2_BC)
/* wrong cylinder => recal */ /* wrong cylinder => recal */
...@@ -1498,7 +1502,10 @@ static int interpret_errors(void) ...@@ -1498,7 +1502,10 @@ static int interpret_errors(void)
*/ */
static void setup_rw_floppy(void) static void setup_rw_floppy(void)
{ {
int i, r, flags, dflags; int i;
int r;
int flags;
int dflags;
unsigned long ready_date; unsigned long ready_date;
timeout_fn function; timeout_fn function;
...@@ -1728,9 +1735,9 @@ static void print_result(char *message, int inr) ...@@ -1728,9 +1735,9 @@ static void print_result(char *message, int inr)
/* interrupt handler. Note that this can be called externally on the Sparc */ /* interrupt handler. Note that this can be called externally on the Sparc */
irqreturn_t floppy_interrupt(int irq, void *dev_id) irqreturn_t floppy_interrupt(int irq, void *dev_id)
{ {
void (*handler) (void) = do_floppy;
int do_print; int do_print;
unsigned long f; unsigned long f;
void (*handler)(void) = do_floppy;
lasthandler = handler; lasthandler = handler;
interruptjiffies = jiffies; interruptjiffies = jiffies;
...@@ -1915,9 +1922,10 @@ static void floppy_shutdown(unsigned long data) ...@@ -1915,9 +1922,10 @@ static void floppy_shutdown(unsigned long data)
/*typedef void (*timeout_fn)(unsigned long);*/ /*typedef void (*timeout_fn)(unsigned long);*/
/* start motor, check media-changed condition and write protection */ /* start motor, check media-changed condition and write protection */
static int start_motor(void (*function) (void)) static int start_motor(void (*function)(void))
{ {
int mask, data; int mask;
int data;
mask = 0xfc; mask = 0xfc;
data = UNIT(current_drive); data = UNIT(current_drive);
...@@ -2020,17 +2028,17 @@ static struct cont_t wakeup_cont = { ...@@ -2020,17 +2028,17 @@ static struct cont_t wakeup_cont = {
.interrupt = empty, .interrupt = empty,
.redo = do_wakeup, .redo = do_wakeup,
.error = empty, .error = empty,
.done = (done_f) empty .done = (done_f)empty
}; };
static struct cont_t intr_cont = { static struct cont_t intr_cont = {
.interrupt = empty, .interrupt = empty,
.redo = process_fd_request, .redo = process_fd_request,
.error = empty, .error = empty,
.done = (done_f) empty .done = (done_f)empty
}; };
static int wait_til_done(void (*handler) (void), int interruptible) static int wait_til_done(void (*handler)(void), int interruptible)
{ {
int ret; int ret;
...@@ -2049,7 +2057,6 @@ static int wait_til_done(void (*handler) (void), int interruptible) ...@@ -2049,7 +2057,6 @@ static int wait_til_done(void (*handler) (void), int interruptible)
break; break;
is_alive("wait_til_done"); is_alive("wait_til_done");
schedule(); schedule();
} }
...@@ -2141,6 +2148,7 @@ static void bad_flp_intr(void) ...@@ -2141,6 +2148,7 @@ static void bad_flp_intr(void)
static void set_floppy(int drive) static void set_floppy(int drive)
{ {
int type = ITYPE(UDRS->fd_device); int type = ITYPE(UDRS->fd_device);
if (type) if (type)
_floppy = floppy_type + type; _floppy = floppy_type + type;
else else
...@@ -2169,11 +2177,14 @@ static void format_interrupt(void) ...@@ -2169,11 +2177,14 @@ static void format_interrupt(void)
#define CT(x) ((x) | 0xc0) #define CT(x) ((x) | 0xc0)
static void setup_format_params(int track) static void setup_format_params(int track)
{ {
int n;
int il;
int count;
int head_shift;
int track_shift;
struct fparm { struct fparm {
unsigned char track, head, sect, size; unsigned char track, head, sect, size;
} *here = (struct fparm *)floppy_track_buffer; } *here = (struct fparm *)floppy_track_buffer;
int il, n;
int count, head_shift, track_shift;
raw_cmd = &default_raw_cmd; raw_cmd = &default_raw_cmd;
raw_cmd->track = track; raw_cmd->track = track;
...@@ -2344,7 +2355,10 @@ static void request_done(int uptodate) ...@@ -2344,7 +2355,10 @@ static void request_done(int uptodate)
/* Interrupt handler evaluating the result of the r/w operation */ /* Interrupt handler evaluating the result of the r/w operation */
static void rw_interrupt(void) static void rw_interrupt(void)
{ {
int nr_sectors, ssize, eoc, heads; int eoc;
int ssize;
int heads;
int nr_sectors;
if (R_HEAD >= 2) { if (R_HEAD >= 2) {
/* some Toshiba floppy controllers occasionnally seem to /* some Toshiba floppy controllers occasionnally seem to
...@@ -2476,7 +2490,8 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2) ...@@ -2476,7 +2490,8 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
{ {
int remaining; /* number of transferred 512-byte sectors */ int remaining; /* number of transferred 512-byte sectors */
struct bio_vec *bv; struct bio_vec *bv;
char *buffer, *dma_buffer; char *buffer;
char *dma_buffer;
int size; int size;
struct req_iterator iter; struct req_iterator iter;
...@@ -2578,7 +2593,8 @@ static inline int check_dma_crossing(char *start, ...@@ -2578,7 +2593,8 @@ static inline int check_dma_crossing(char *start,
*/ */
static void virtualdmabug_workaround(void) static void virtualdmabug_workaround(void)
{ {
int hard_sectors, end_sector; int hard_sectors;
int end_sector;
if (CT(COMMAND) == FD_WRITE) { if (CT(COMMAND) == FD_WRITE) {
COMMAND &= ~0x80; /* switch off multiple track mode */ COMMAND &= ~0x80; /* switch off multiple track mode */
...@@ -2610,7 +2626,10 @@ static void virtualdmabug_workaround(void) ...@@ -2610,7 +2626,10 @@ static void virtualdmabug_workaround(void)
static int make_raw_rw_request(void) static int make_raw_rw_request(void)
{ {
int aligned_sector_t; int aligned_sector_t;
int max_sector, max_size, tracksize, ssize; int max_sector;
int max_size;
int tracksize;
int ssize;
if (max_buffer_sectors == 0) { if (max_buffer_sectors == 0) {
printk("VFS: Block I/O scheduled on unopened device\n"); printk("VFS: Block I/O scheduled on unopened device\n");
...@@ -2777,8 +2796,8 @@ static int make_raw_rw_request(void) ...@@ -2777,8 +2796,8 @@ static int make_raw_rw_request(void)
indirect, direct, fsector_t); indirect, direct, fsector_t);
return 0; return 0;
} }
/* check_dma_crossing(raw_cmd->kernel_data, /* check_dma_crossing(raw_cmd->kernel_data,
raw_cmd->length, raw_cmd->length,
"end of make_raw_request [1]");*/ "end of make_raw_request [1]");*/
virtualdmabug_workaround(); virtualdmabug_workaround();
...@@ -3011,6 +3030,7 @@ static struct cont_t poll_cont = { ...@@ -3011,6 +3030,7 @@ static struct cont_t poll_cont = {
static int poll_drive(int interruptible, int flag) static int poll_drive(int interruptible, int flag)
{ {
int ret; int ret;
/* no auto-sense, just clear dcl */ /* no auto-sense, just clear dcl */
raw_cmd = &default_raw_cmd; raw_cmd = &default_raw_cmd;
raw_cmd->flags = flag; raw_cmd->flags = flag;
...@@ -3173,7 +3193,8 @@ static inline int raw_cmd_copyout(int cmd, char __user *param, ...@@ -3173,7 +3193,8 @@ static inline int raw_cmd_copyout(int cmd, char __user *param,
static void raw_cmd_free(struct floppy_raw_cmd **ptr) static void raw_cmd_free(struct floppy_raw_cmd **ptr)
{ {
struct floppy_raw_cmd *next, *this; struct floppy_raw_cmd *next;
struct floppy_raw_cmd *this;
this = *ptr; this = *ptr;
*ptr = NULL; *ptr = NULL;
...@@ -3245,8 +3266,10 @@ static inline int raw_cmd_copyin(int cmd, char __user *param, ...@@ -3245,8 +3266,10 @@ static inline int raw_cmd_copyin(int cmd, char __user *param,
static int raw_cmd_ioctl(int cmd, void __user *param) static int raw_cmd_ioctl(int cmd, void __user *param)
{ {
int drive, ret, ret2;
struct floppy_raw_cmd *my_raw_cmd; struct floppy_raw_cmd *my_raw_cmd;
int drive;
int ret2;
int ret;
if (FDCS->rawcmd <= 1) if (FDCS->rawcmd <= 1)
FDCS->rawcmd = 1; FDCS->rawcmd = 1;
...@@ -3453,7 +3476,8 @@ static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, ...@@ -3453,7 +3476,8 @@ static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
#define IN(c,x,tag) case c: *(x) = inparam. tag ; return 0 #define IN(c,x,tag) case c: *(x) = inparam. tag ; return 0
int drive = (long)inode->i_bdev->bd_disk->private_data; int drive = (long)inode->i_bdev->bd_disk->private_data;
int i, type = ITYPE(UDRS->fd_device); int type = ITYPE(UDRS->fd_device);
int i;
int ret; int ret;
int size; int size;
union inparam { union inparam {
...@@ -3619,8 +3643,7 @@ static void __init config_types(void) ...@@ -3619,8 +3643,7 @@ static void __init config_types(void)
if (!UDP->cmos && FLOPPY1_TYPE) if (!UDP->cmos && FLOPPY1_TYPE)
UDP->cmos = FLOPPY1_TYPE; UDP->cmos = FLOPPY1_TYPE;
/* XXX */ /* FIXME: additional physical CMOS drive detection should go here */
/* additional physical CMOS drive detection should go here */
for (drive = 0; drive < N_DRIVE; drive++) { for (drive = 0; drive < N_DRIVE; drive++) {
unsigned int type = UDP->cmos; unsigned int type = UDP->cmos;
...@@ -3903,13 +3926,13 @@ static int floppy_revalidate(struct gendisk *disk) ...@@ -3903,13 +3926,13 @@ static int floppy_revalidate(struct gendisk *disk)
} }
static struct block_device_operations floppy_fops = { static struct block_device_operations floppy_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = floppy_open, .open = floppy_open,
.release = floppy_release, .release = floppy_release,
.ioctl = fd_ioctl, .ioctl = fd_ioctl,
.getgeo = fd_getgeo, .getgeo = fd_getgeo,
.media_changed = check_floppy_change, .media_changed = check_floppy_change,
.revalidate_disk = floppy_revalidate, .revalidate_disk = floppy_revalidate,
}; };
/* /*
...@@ -4428,8 +4451,8 @@ static int floppy_grab_irq_and_dma(void) ...@@ -4428,8 +4451,8 @@ static int floppy_grab_irq_and_dma(void)
if (FDCS->address != -1) if (FDCS->address != -1)
fd_outb(FDCS->dor, FD_DOR); fd_outb(FDCS->dor, FD_DOR);
/* /*
* The driver will try and free resources and relies on us * The driver will try and free resources and relies on us
* to know if they were allocated or not. * to know if they were allocated or not.
*/ */
fdc = 0; fdc = 0;
irqdma_allocated = 1; irqdma_allocated = 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册