aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/floppy.c
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2010-03-10 18:20:45 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-12 18:52:29 -0500
commit48c8cee61f22fe5a2ea00488222b3415378469ad (patch)
treeb1f16062ea0f0fe23505d3a1c7b99049c210041b /drivers/block/floppy.c
parentd49375434ec011dabcc8bfa5091f5327284e42ce (diff)
drivers/block/floppy.c: #define space and column neatening
Signed-off-by: Joe Perches <joe@perches.com> Cc: Stephen Hemminger <shemminger@vyatta.com> Cc: Jens Axboe <jens.axboe@oracle.com> Cc: Marcin Slusarz <marcin.slusarz@gmail.com> Cc: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/block/floppy.c')
-rw-r--r--drivers/block/floppy.c180
1 files changed, 97 insertions, 83 deletions
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 65e2443b207..652668d76a8 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -150,7 +150,7 @@
150#define REALLY_SLOW_IO 150#define REALLY_SLOW_IO
151 151
152#define DEBUGT 2 152#define DEBUGT 2
153#define DCL_DEBUG /* debug disk change line */ 153#define DCL_DEBUG /* debug disk change line */
154 154
155/* do print messages for unexpected interrupts */ 155/* do print messages for unexpected interrupts */
156static int print_unex = 1; 156static int print_unex = 1;
@@ -250,7 +250,7 @@ static int irqdma_allocated;
250 250
251static struct request *current_req; 251static struct request *current_req;
252static struct request_queue *floppy_queue; 252static struct request_queue *floppy_queue;
253static void do_fd_request(struct request_queue * q); 253static void do_fd_request(struct request_queue *q);
254 254
255#ifndef fd_get_dma_residue 255#ifndef fd_get_dma_residue
256#define fd_get_dma_residue() get_dma_residue(FLOPPY_DMA) 256#define fd_get_dma_residue() get_dma_residue(FLOPPY_DMA)
@@ -263,7 +263,7 @@ static void do_fd_request(struct request_queue * q);
263#endif 263#endif
264 264
265#ifndef fd_dma_mem_alloc 265#ifndef fd_dma_mem_alloc
266#define fd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL,get_order(size)) 266#define fd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL, get_order(size))
267#endif 267#endif
268 268
269static inline void fallback_on_nodma_alloc(char **addr, size_t l) 269static inline void fallback_on_nodma_alloc(char **addr, size_t l)
@@ -285,57 +285,59 @@ static inline void fallback_on_nodma_alloc(char **addr, size_t l)
285static unsigned long fake_change; 285static unsigned long fake_change;
286static int initialising = 1; 286static int initialising = 1;
287 287
288#define ITYPE(x) (((x)>>2) & 0x1f) 288#define ITYPE(x) (((x) >> 2) & 0x1f)
289#define TOMINOR(x) ((x & 3) | ((x & 4) << 5)) 289#define TOMINOR(x) ((x & 3) | ((x & 4) << 5))
290#define UNIT(x) ((x) & 0x03) /* drive on fdc */ 290#define UNIT(x) ((x) & 0x03) /* drive on fdc */
291#define FDC(x) (((x) & 0x04) >> 2) /* fdc of drive */ 291#define FDC(x) (((x) & 0x04) >> 2) /* fdc of drive */
292 /* reverse mapping from unit and fdc to drive */ 292 /* reverse mapping from unit and fdc to drive */
293#define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2)) 293#define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2))
294#define DP (&drive_params[current_drive])
295#define DRS (&drive_state[current_drive])
296#define DRWE (&write_errors[current_drive])
297#define FDCS (&fdc_state[fdc])
298#define CLEARF(x) clear_bit(x##_BIT, &DRS->flags)
299#define SETF(x) set_bit(x##_BIT, &DRS->flags)
300#define TESTF(x) test_bit(x##_BIT, &DRS->flags)
301 294
302#define UDP (&drive_params[drive]) 295#define DP (&drive_params[current_drive])
303#define UDRS (&drive_state[drive]) 296#define DRS (&drive_state[current_drive])
304#define UDRWE (&write_errors[drive]) 297#define DRWE (&write_errors[current_drive])
305#define UFDCS (&fdc_state[FDC(drive)]) 298#define FDCS (&fdc_state[fdc])
306#define UCLEARF(x) clear_bit(x##_BIT, &UDRS->flags) 299#define CLEARF(x) clear_bit(x##_BIT, &DRS->flags)
307#define USETF(x) set_bit(x##_BIT, &UDRS->flags) 300#define SETF(x) set_bit(x##_BIT, &DRS->flags)
308#define UTESTF(x) test_bit(x##_BIT, &UDRS->flags) 301#define TESTF(x) test_bit(x##_BIT, &DRS->flags)
309 302
310#define DPRINT(format, args...) printk(DEVICE_NAME "%d: " format, current_drive , ## args) 303#define UDP (&drive_params[drive])
304#define UDRS (&drive_state[drive])
305#define UDRWE (&write_errors[drive])
306#define UFDCS (&fdc_state[FDC(drive)])
307#define UCLEARF(x) clear_bit(x##_BIT, &UDRS->flags)
308#define USETF(x) set_bit(x##_BIT, &UDRS->flags)
309#define UTESTF(x) test_bit(x##_BIT, &UDRS->flags)
311 310
312#define PH_HEAD(floppy,head) (((((floppy)->stretch & 2) >>1) ^ head) << 2) 311#define DPRINT(format, args...) \
313#define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH) 312 printk(DEVICE_NAME "%d: " format, current_drive, ##args)
314 313
315#define CLEARSTRUCT(x) memset((x), 0, sizeof(*(x))) 314#define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2)
315#define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH)
316
317#define CLEARSTRUCT(x) memset((x), 0, sizeof(*(x)))
316 318
317/* read/write */ 319/* read/write */
318#define COMMAND raw_cmd->cmd[0] 320#define COMMAND (raw_cmd->cmd[0])
319#define DR_SELECT raw_cmd->cmd[1] 321#define DR_SELECT (raw_cmd->cmd[1])
320#define TRACK raw_cmd->cmd[2] 322#define TRACK (raw_cmd->cmd[2])
321#define HEAD raw_cmd->cmd[3] 323#define HEAD (raw_cmd->cmd[3])
322#define SECTOR raw_cmd->cmd[4] 324#define SECTOR (raw_cmd->cmd[4])
323#define SIZECODE raw_cmd->cmd[5] 325#define SIZECODE (raw_cmd->cmd[5])
324#define SECT_PER_TRACK raw_cmd->cmd[6] 326#define SECT_PER_TRACK (raw_cmd->cmd[6])
325#define GAP raw_cmd->cmd[7] 327#define GAP (raw_cmd->cmd[7])
326#define SIZECODE2 raw_cmd->cmd[8] 328#define SIZECODE2 (raw_cmd->cmd[8])
327#define NR_RW 9 329#define NR_RW 9
328 330
329/* format */ 331/* format */
330#define F_SIZECODE raw_cmd->cmd[2] 332#define F_SIZECODE (raw_cmd->cmd[2])
331#define F_SECT_PER_TRACK raw_cmd->cmd[3] 333#define F_SECT_PER_TRACK (raw_cmd->cmd[3])
332#define F_GAP raw_cmd->cmd[4] 334#define F_GAP (raw_cmd->cmd[4])
333#define F_FILL raw_cmd->cmd[5] 335#define F_FILL (raw_cmd->cmd[5])
334#define NR_F 6 336#define NR_F 6
335 337
336/* 338/*
337 * Maximum disk size (in kilobytes). This default is used whenever the 339 * Maximum disk size (in kilobytes).
338 * current disk size is unknown. 340 * This default is used whenever the current disk size is unknown.
339 * [Now it is rather a minimum] 341 * [Now it is rather a minimum]
340 */ 342 */
341#define MAX_DISK_SIZE 4 /* 3984 */ 343#define MAX_DISK_SIZE 4 /* 3984 */
@@ -346,15 +348,16 @@ static int initialising = 1;
346#define MAX_REPLIES 16 348#define MAX_REPLIES 16
347static unsigned char reply_buffer[MAX_REPLIES]; 349static unsigned char reply_buffer[MAX_REPLIES];
348static int inr; /* size of reply buffer, when called from interrupt */ 350static int inr; /* size of reply buffer, when called from interrupt */
349#define ST0 (reply_buffer[0]) 351#define ST0 (reply_buffer[0])
350#define ST1 (reply_buffer[1]) 352#define ST1 (reply_buffer[1])
351#define ST2 (reply_buffer[2]) 353#define ST2 (reply_buffer[2])
352#define ST3 (reply_buffer[0]) /* result of GETSTATUS */ 354#define ST3 (reply_buffer[0]) /* result of GETSTATUS */
353#define R_TRACK (reply_buffer[3]) 355#define R_TRACK (reply_buffer[3])
354#define R_HEAD (reply_buffer[4]) 356#define R_HEAD (reply_buffer[4])
355#define R_SECTOR (reply_buffer[5]) 357#define R_SECTOR (reply_buffer[5])
356#define R_SIZECODE (reply_buffer[6]) 358#define R_SIZECODE (reply_buffer[6])
357#define SEL_DLY (2*HZ/100) 359
360#define SEL_DLY (2 * HZ / 100)
358 361
359/* 362/*
360 * this struct defines the different floppy drive types. 363 * this struct defines the different floppy drive types.
@@ -505,9 +508,9 @@ static char floppy_device_name[] = "floppy";
505static int probing; 508static int probing;
506 509
507/* Synchronization of FDC access. */ 510/* Synchronization of FDC access. */
508#define FD_COMMAND_NONE -1 511#define FD_COMMAND_NONE -1
509#define FD_COMMAND_ERROR 2 512#define FD_COMMAND_ERROR 2
510#define FD_COMMAND_OKAY 3 513#define FD_COMMAND_OKAY 3
511 514
512static volatile int command_status = FD_COMMAND_NONE; 515static volatile int command_status = FD_COMMAND_NONE;
513static unsigned long fdc_busy; 516static unsigned long fdc_busy;
@@ -515,11 +518,11 @@ static DECLARE_WAIT_QUEUE_HEAD(fdc_wait);
515static DECLARE_WAIT_QUEUE_HEAD(command_done); 518static DECLARE_WAIT_QUEUE_HEAD(command_done);
516 519
517#define NO_SIGNAL (!interruptible || !signal_pending(current)) 520#define NO_SIGNAL (!interruptible || !signal_pending(current))
518#define CALL(x) if ((x) == -EINTR) return -EINTR 521#define CALL(x) if ((x) == -EINTR) return -EINTR
519#define ECALL(x) if ((ret = (x))) return ret; 522#define ECALL(x) if ((ret = (x))) return ret;
520#define _WAIT(x,i) CALL(ret=wait_til_done((x),i)) 523#define _WAIT(x,i) CALL(ret=wait_til_done((x),i))
521#define WAIT(x) _WAIT((x),interruptible) 524#define WAIT(x) _WAIT((x),interruptible)
522#define IWAIT(x) _WAIT((x),1) 525#define IWAIT(x) _WAIT((x),1)
523 526
524/* Errors during formatting are counted here. */ 527/* Errors during formatting are counted here. */
525static int format_errors; 528static int format_errors;
@@ -545,8 +548,9 @@ static int max_buffer_sectors;
545static int *errors; 548static int *errors;
546typedef void (*done_f)(int); 549typedef void (*done_f)(int);
547static struct cont_t { 550static struct cont_t {
548 void (*interrupt)(void); /* this is called after the interrupt of the 551 void (*interrupt)(void);
549 * main command */ 552 /* this is called after the interrupt of the
553 * main command */
550 void (*redo)(void); /* this is called to retry the operation */ 554 void (*redo)(void); /* this is called to retry the operation */
551 void (*error)(void); /* this is called to tally an error */ 555 void (*error)(void); /* this is called to tally an error */
552 done_f done; /* this is called to say if the operation has 556 done_f done; /* this is called to say if the operation has
@@ -579,9 +583,9 @@ static void reset_fdc(void);
579 * information to interrupts. They are the data used for the current 583 * information to interrupts. They are the data used for the current
580 * request. 584 * request.
581 */ 585 */
582#define NO_TRACK -1 586#define NO_TRACK -1
583#define NEED_1_RECAL -2 587#define NEED_1_RECAL -2
584#define NEED_2_RECAL -3 588#define NEED_2_RECAL -3
585 589
586static int usage_count; 590static int usage_count;
587 591
@@ -647,13 +651,13 @@ static void is_alive(const char *message)
647} 651}
648#endif 652#endif
649 653
650static void (*do_floppy) (void) = NULL; 654static void (*do_floppy)(void) = NULL;
651 655
652#ifdef FLOPPY_SANITY_CHECK 656#ifdef FLOPPY_SANITY_CHECK
653 657
654#define OLOGSIZE 20 658#define OLOGSIZE 20
655 659
656static void (*lasthandler) (void); 660static void (*lasthandler)(void);
657static unsigned long interruptjiffies; 661static unsigned long interruptjiffies;
658static unsigned long resultjiffies; 662static unsigned long resultjiffies;
659static int resultsize; 663static int resultsize;
@@ -699,8 +703,8 @@ static void reschedule_timeout(int drive, const char *message, int marg)
699 spin_unlock_irqrestore(&floppy_lock, flags); 703 spin_unlock_irqrestore(&floppy_lock, flags);
700} 704}
701 705
702#define INFBOUND(a,b) (a)=max_t(int, a, b) 706#define INFBOUND(a, b) (a) = max_t(int, a, b)
703#define SUPBOUND(a,b) (a)=min_t(int, a, b) 707#define SUPBOUND(a, b) (a) = min_t(int, a, b)
704 708
705/* 709/*
706 * Bottom half floppy driver. 710 * Bottom half floppy driver.
@@ -909,10 +913,12 @@ static int _lock_fdc(int drive, int interruptible, int line)
909 return 0; 913 return 0;
910} 914}
911 915
912#define lock_fdc(drive,interruptible) _lock_fdc(drive,interruptible, __LINE__) 916#define lock_fdc(drive, interruptible) \
917 _lock_fdc(drive, interruptible, __LINE__)
913 918
914#define LOCK_FDC(drive,interruptible) \ 919#define LOCK_FDC(drive, interruptible) \
915if (lock_fdc(drive,interruptible)) return -EINTR; 920 if (lock_fdc(drive, interruptible)) \
921 return -EINTR;
916 922
917/* unlocks the driver */ 923/* unlocks the driver */
918static inline void unlock_fdc(void) 924static inline void unlock_fdc(void)
@@ -1003,7 +1009,7 @@ static void empty(void)
1003 1009
1004static DECLARE_WORK(floppy_work, NULL); 1010static DECLARE_WORK(floppy_work, NULL);
1005 1011
1006static void schedule_bh(void (*handler) (void)) 1012static void schedule_bh(void (*handler)(void))
1007{ 1013{
1008 PREPARE_WORK(&floppy_work, (work_func_t)handler); 1014 PREPARE_WORK(&floppy_work, (work_func_t)handler);
1009 schedule_work(&floppy_work); 1015 schedule_work(&floppy_work);
@@ -2181,8 +2187,9 @@ static void format_interrupt(void)
2181} 2187}
2182 2188
2183#define CODE2SIZE (ssize = ((1 << SIZECODE) + 3) >> 2) 2189#define CODE2SIZE (ssize = ((1 << SIZECODE) + 3) >> 2)
2184#define FM_MODE(x,y) ((y) & ~(((x)->rate & 0x80) >>1)) 2190#define FM_MODE(x, y) ((y) & ~(((x)->rate & 0x80) >> 1))
2185#define CT(x) ((x) | 0xc0) 2191#define CT(x) ((x) | 0xc0)
2192
2186static void setup_format_params(int track) 2193static void setup_format_params(int track)
2187{ 2194{
2188 int n; 2195 int n;
@@ -2197,8 +2204,8 @@ static void setup_format_params(int track)
2197 raw_cmd = &default_raw_cmd; 2204 raw_cmd = &default_raw_cmd;
2198 raw_cmd->track = track; 2205 raw_cmd->track = track;
2199 2206
2200 raw_cmd->flags = FD_RAW_WRITE | FD_RAW_INTR | FD_RAW_SPIN | 2207 raw_cmd->flags = (FD_RAW_WRITE | FD_RAW_INTR | FD_RAW_SPIN |
2201 FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK; 2208 FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK);
2202 raw_cmd->rate = _floppy->rate & 0x43; 2209 raw_cmd->rate = _floppy->rate & 0x43;
2203 raw_cmd->cmd_count = NR_F; 2210 raw_cmd->cmd_count = NR_F;
2204 COMMAND = FM_MODE(_floppy, FD_FORMAT); 2211 COMMAND = FM_MODE(_floppy, FD_FORMAT);
@@ -2600,8 +2607,9 @@ static void virtualdmabug_workaround(void)
2600 return; 2607 return;
2601 } 2608 }
2602#endif 2609#endif
2603 SECT_PER_TRACK = end_sector; /* make sure SECT_PER_TRACK points 2610 SECT_PER_TRACK = end_sector;
2604 * to end of transfer */ 2611 /* make sure SECT_PER_TRACK
2612 * points to end of transfer */
2605 } 2613 }
2606} 2614}
2607 2615
@@ -3075,16 +3083,19 @@ static inline int fd_copyout(void __user *param, const void *address,
3075 return copy_to_user(param, address, size) ? -EFAULT : 0; 3083 return copy_to_user(param, address, size) ? -EFAULT : 0;
3076} 3084}
3077 3085
3078static inline int fd_copyin(void __user *param, void *address, unsigned long size) 3086static inline int fd_copyin(void __user *param, void *address,
3087 unsigned long size)
3079{ 3088{
3080 return copy_from_user(address, param, size) ? -EFAULT : 0; 3089 return copy_from_user(address, param, size) ? -EFAULT : 0;
3081} 3090}
3082 3091
3083#define _COPYOUT(x) (copy_to_user((void __user *)param, &(x), sizeof(x)) ? -EFAULT : 0) 3092#define _COPYOUT(x) (copy_to_user((void __user *)param, &(x), sizeof(x)) \
3084#define _COPYIN(x) (copy_from_user(&(x), (void __user *)param, sizeof(x)) ? -EFAULT : 0) 3093 ? -EFAULT : 0)
3094#define _COPYIN(x) (copy_from_user(&(x), (void __user *)param, sizeof(x)) \
3095 ? -EFAULT : 0)
3085 3096
3086#define COPYOUT(x) ECALL(_COPYOUT(x)) 3097#define COPYOUT(x) ECALL(_COPYOUT(x))
3087#define COPYIN(x) ECALL(_COPYIN(x)) 3098#define COPYIN(x) ECALL(_COPYIN(x))
3088 3099
3089static inline const char *drive_name(int type, int drive) 3100static inline const char *drive_name(int type, int drive)
3090{ 3101{
@@ -4148,7 +4159,8 @@ static ssize_t floppy_cmos_show(struct device *dev,
4148 drive = p->id; 4159 drive = p->id;
4149 return sprintf(buf, "%X\n", UDP->cmos); 4160 return sprintf(buf, "%X\n", UDP->cmos);
4150} 4161}
4151DEVICE_ATTR(cmos,S_IRUGO,floppy_cmos_show,NULL); 4162
4163DEVICE_ATTR(cmos, S_IRUGO, floppy_cmos_show, NULL);
4152 4164
4153static void floppy_device_release(struct device *dev) 4165static void floppy_device_release(struct device *dev)
4154{ 4166{
@@ -4625,6 +4637,7 @@ static void __exit floppy_module_exit(void)
4625 /* eject disk, if any */ 4637 /* eject disk, if any */
4626 fd_eject(0); 4638 fd_eject(0);
4627} 4639}
4640
4628module_exit(floppy_module_exit); 4641module_exit(floppy_module_exit);
4629 4642
4630module_param(floppy, charp, 0); 4643module_param(floppy, charp, 0);
@@ -4636,9 +4649,10 @@ MODULE_LICENSE("GPL");
4636 4649
4637/* This doesn't actually get used other than for module information */ 4650/* This doesn't actually get used other than for module information */
4638static const struct pnp_device_id floppy_pnpids[] = { 4651static const struct pnp_device_id floppy_pnpids[] = {
4639 { "PNP0700", 0 }, 4652 {"PNP0700", 0},
4640 { } 4653 {}
4641}; 4654};
4655
4642MODULE_DEVICE_TABLE(pnp, floppy_pnpids); 4656MODULE_DEVICE_TABLE(pnp, floppy_pnpids);
4643 4657
4644#else 4658#else