Make HZ_TO_STD macro name lowercase.
[linux-2.6/linux-mips.git] / drivers / ide / ide-floppy.c
blob1130bd3d5dbf9db78c6309391d6ff1cfbb8f8a0a
1 /*
2 * linux/drivers/ide/ide-floppy.c Version 0.9 Jul 4, 1999
4 * Copyright (C) 1996 - 1999 Gadi Oxman <gadio@netvision.net.il>
5 */
7 /*
8 * IDE ATAPI floppy driver.
10 * The driver currently doesn't have any fancy features, just the bare
11 * minimum read/write support.
13 * Many thanks to Lode Leroy <Lode.Leroy@www.ibase.be>, who tested so many
14 * ALPHA patches to this driver on an EASYSTOR LS-120 ATAPI floppy drive.
16 * Ver 0.1 Oct 17 96 Initial test version, mostly based on ide-tape.c.
17 * Ver 0.2 Oct 31 96 Minor changes.
18 * Ver 0.3 Dec 2 96 Fixed error recovery bug.
19 * Ver 0.4 Jan 26 97 Add support for the HDIO_GETGEO ioctl.
20 * Ver 0.5 Feb 21 97 Add partitions support.
21 * Use the minimum of the LBA and CHS capacities.
22 * Avoid hwgroup->rq == NULL on the last irq.
23 * Fix potential null dereferencing with DEBUG_LOG.
24 * Ver 0.8 Dec 7 97 Increase irq timeout from 10 to 50 seconds.
25 * Add media write-protect detection.
26 * Issue START command only if TEST UNIT READY fails.
27 * Add work-around for IOMEGA ZIP revision 21.D.
28 * Remove idefloppy_get_capabilities().
29 * Ver 0.9 Jul 4 99 Fix a bug which might have caused the number of
30 * bytes requested on each interrupt to be zero.
31 * Thanks to <shanos@es.co.nz> for pointing this out.
34 #define IDEFLOPPY_VERSION "0.9"
36 #include <linux/config.h>
37 #include <linux/module.h>
38 #include <linux/types.h>
39 #include <linux/string.h>
40 #include <linux/kernel.h>
41 #include <linux/delay.h>
42 #include <linux/timer.h>
43 #include <linux/mm.h>
44 #include <linux/interrupt.h>
45 #include <linux/major.h>
46 #include <linux/errno.h>
47 #include <linux/genhd.h>
48 #include <linux/malloc.h>
49 #include <linux/cdrom.h>
50 #include <linux/ide.h>
52 #include <asm/byteorder.h>
53 #include <asm/irq.h>
54 #include <asm/uaccess.h>
55 #include <asm/io.h>
56 #include <asm/unaligned.h>
57 #include <asm/bitops.h>
60 * The following are used to debug the driver.
62 #define IDEFLOPPY_DEBUG_LOG 0
63 #define IDEFLOPPY_DEBUG_INFO 0
64 #define IDEFLOPPY_DEBUG_BUGS 1
67 * Some drives require a longer irq timeout.
69 #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
72 * After each failed packet command we issue a request sense command
73 * and retry the packet command IDEFLOPPY_MAX_PC_RETRIES times.
75 #define IDEFLOPPY_MAX_PC_RETRIES 3
78 * With each packet command, we allocate a buffer of
79 * IDEFLOPPY_PC_BUFFER_SIZE bytes.
81 #define IDEFLOPPY_PC_BUFFER_SIZE 256
84 * In various places in the driver, we need to allocate storage
85 * for packet commands and requests, which will remain valid while
86 * we leave the driver to wait for an interrupt or a timeout event.
88 #define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
91 * Our view of a packet command.
93 typedef struct idefloppy_packet_command_s {
94 u8 c[12]; /* Actual packet bytes */
95 int retries; /* On each retry, we increment retries */
96 int error; /* Error code */
97 int request_transfer; /* Bytes to transfer */
98 int actually_transferred; /* Bytes actually transferred */
99 int buffer_size; /* Size of our data buffer */
100 char *b_data; /* Pointer which runs on the buffers */
101 int b_count; /* Missing/Available data on the current buffer */
102 struct request *rq; /* The corresponding request */
103 byte *buffer; /* Data buffer */
104 byte *current_position; /* Pointer into the above buffer */
105 void (*callback) (ide_drive_t *); /* Called when this packet command is completed */
106 byte pc_buffer[IDEFLOPPY_PC_BUFFER_SIZE]; /* Temporary buffer */
107 unsigned int flags; /* Status/Action bit flags */
108 } idefloppy_pc_t;
111 * Packet command flag bits.
113 #define PC_ABORT 0 /* Set when an error is considered normal - We won't retry */
114 #define PC_DMA_RECOMMENDED 2 /* 1 when we prefer to use DMA if possible */
115 #define PC_DMA_IN_PROGRESS 3 /* 1 while DMA in progress */
116 #define PC_DMA_ERROR 4 /* 1 when encountered problem during DMA */
117 #define PC_WRITING 5 /* Data direction */
120 * Removable Block Access Capabilities Page
122 typedef struct {
123 #if defined(__LITTLE_ENDIAN_BITFIELD)
124 unsigned page_code :6; /* Page code - Should be 0x1b */
125 unsigned reserved1_6 :1; /* Reserved */
126 unsigned ps :1; /* Should be 0 */
127 #elif defined(__BIG_ENDIAN_BITFIELD)
128 unsigned ps :1; /* Should be 0 */
129 unsigned reserved1_6 :1; /* Reserved */
130 unsigned page_code :6; /* Page code - Should be 0x1b */
131 #else
132 #error "Bitfield endianness not defined! Check your byteorder.h"
133 #endif
134 u8 page_length; /* Page Length - Should be 0xa */
135 #if defined(__LITTLE_ENDIAN_BITFIELD)
136 unsigned reserved2 :6;
137 unsigned srfp :1; /* Supports reporting progress of format */
138 unsigned sflp :1; /* System floppy type device */
139 unsigned tlun :3; /* Total logical units supported by the device */
140 unsigned reserved3 :3;
141 unsigned sml :1; /* Single / Multiple lun supported */
142 unsigned ncd :1; /* Non cd optical device */
143 #elif defined(__BIG_ENDIAN_BITFIELD)
144 unsigned sflp :1; /* System floppy type device */
145 unsigned srfp :1; /* Supports reporting progress of format */
146 unsigned reserved2 :6;
147 unsigned ncd :1; /* Non cd optical device */
148 unsigned sml :1; /* Single / Multiple lun supported */
149 unsigned reserved3 :3;
150 unsigned tlun :3; /* Total logical units supported by the device */
151 #else
152 #error "Bitfield endianness not defined! Check your byteorder.h"
153 #endif
154 u8 reserved[8];
155 } idefloppy_capabilities_page_t;
158 * Flexible disk page.
160 typedef struct {
161 #if defined(__LITTLE_ENDIAN_BITFIELD)
162 unsigned page_code :6; /* Page code - Should be 0x5 */
163 unsigned reserved1_6 :1; /* Reserved */
164 unsigned ps :1; /* The device is capable of saving the page */
165 #elif defined(__BIG_ENDIAN_BITFIELD)
166 unsigned ps :1; /* The device is capable of saving the page */
167 unsigned reserved1_6 :1; /* Reserved */
168 unsigned page_code :6; /* Page code - Should be 0x5 */
169 #else
170 #error "Bitfield endianness not defined! Check your byteorder.h"
171 #endif
172 u8 page_length; /* Page Length - Should be 0x1e */
173 u16 transfer_rate; /* In kilobits per second */
174 u8 heads, sectors; /* Number of heads, Number of sectors per track */
175 u16 sector_size; /* Byes per sector */
176 u16 cyls; /* Number of cylinders */
177 u8 reserved10[10];
178 u8 motor_delay; /* Motor off delay */
179 u8 reserved21[7];
180 u16 rpm; /* Rotations per minute */
181 u8 reserved30[2];
182 } idefloppy_flexible_disk_page_t;
185 * Format capacity
187 typedef struct {
188 u8 reserved[3];
189 u8 length; /* Length of the following descriptors in bytes */
190 } idefloppy_capacity_header_t;
192 typedef struct {
193 u32 blocks; /* Number of blocks */
194 #if defined(__LITTLE_ENDIAN_BITFIELD)
195 unsigned dc :2; /* Descriptor Code */
196 unsigned reserved :6;
197 #elif defined(__BIG_ENDIAN_BITFIELD)
198 unsigned reserved :6;
199 unsigned dc :2; /* Descriptor Code */
200 #else
201 #error "Bitfield endianness not defined! Check your byteorder.h"
202 #endif
203 u8 length_msb; /* Block Length (MSB)*/
204 u16 length; /* Block Length */
205 } idefloppy_capacity_descriptor_t;
207 #define CAPACITY_INVALID 0x00
208 #define CAPACITY_UNFORMATTED 0x01
209 #define CAPACITY_CURRENT 0x02
210 #define CAPACITY_NO_CARTRIDGE 0x03
213 * Most of our global data which we need to save even as we leave the
214 * driver due to an interrupt or a timer event is stored in a variable
215 * of type idefloppy_floppy_t, defined below.
217 typedef struct {
218 ide_drive_t *drive;
220 idefloppy_pc_t *pc; /* Current packet command */
221 idefloppy_pc_t *failed_pc; /* Last failed packet command */
222 idefloppy_pc_t pc_stack[IDEFLOPPY_PC_STACK];/* Packet command stack */
223 int pc_stack_index; /* Next free packet command storage space */
224 struct request rq_stack[IDEFLOPPY_PC_STACK];
225 int rq_stack_index; /* We implement a circular array */
228 * Last error information
230 byte sense_key, asc, ascq;
233 * Device information
235 int blocks, block_size, bs_factor; /* Current format */
236 idefloppy_capacity_descriptor_t capacity; /* Last format capacity */
237 idefloppy_flexible_disk_page_t flexible_disk_page; /* Copy of the flexible disk page */
238 int wp; /* Write protect */
240 unsigned int flags; /* Status/Action flags */
241 } idefloppy_floppy_t;
244 * Floppy flag bits values.
246 #define IDEFLOPPY_DRQ_INTERRUPT 0 /* DRQ interrupt device */
247 #define IDEFLOPPY_MEDIA_CHANGED 1 /* Media may have changed */
248 #define IDEFLOPPY_USE_READ12 2 /* Use READ12/WRITE12 or READ10/WRITE10 */
251 * ATAPI floppy drive packet commands
253 #define IDEFLOPPY_FORMAT_UNIT_CMD 0x04
254 #define IDEFLOPPY_INQUIRY_CMD 0x12
255 #define IDEFLOPPY_MODE_SELECT_CMD 0x55
256 #define IDEFLOPPY_MODE_SENSE_CMD 0x5a
257 #define IDEFLOPPY_READ10_CMD 0x28
258 #define IDEFLOPPY_READ12_CMD 0xa8
259 #define IDEFLOPPY_READ_CAPACITY_CMD 0x23
260 #define IDEFLOPPY_REQUEST_SENSE_CMD 0x03
261 #define IDEFLOPPY_PREVENT_REMOVAL_CMD 0x1e
262 #define IDEFLOPPY_SEEK_CMD 0x2b
263 #define IDEFLOPPY_START_STOP_CMD 0x1b
264 #define IDEFLOPPY_TEST_UNIT_READY_CMD 0x00
265 #define IDEFLOPPY_VERIFY_CMD 0x2f
266 #define IDEFLOPPY_WRITE10_CMD 0x2a
267 #define IDEFLOPPY_WRITE12_CMD 0xaa
268 #define IDEFLOPPY_WRITE_VERIFY_CMD 0x2e
271 * Defines for the mode sense command
273 #define MODE_SENSE_CURRENT 0x00
274 #define MODE_SENSE_CHANGEABLE 0x01
275 #define MODE_SENSE_DEFAULT 0x02
276 #define MODE_SENSE_SAVED 0x03
279 * Special requests for our block device strategy routine.
281 #define IDEFLOPPY_FIRST_RQ 90
284 * IDEFLOPPY_PC_RQ is used to queue a packet command in the request queue.
286 #define IDEFLOPPY_PC_RQ 90
288 #define IDEFLOPPY_LAST_RQ 90
291 * A macro which can be used to check if a given request command
292 * originated in the driver or in the buffer cache layer.
294 #define IDEFLOPPY_RQ_CMD(cmd) ((cmd >= IDEFLOPPY_FIRST_RQ) && (cmd <= IDEFLOPPY_LAST_RQ))
297 * Error codes which are returned in rq->errors to the higher part
298 * of the driver.
300 #define IDEFLOPPY_ERROR_GENERAL 101
303 * The ATAPI Status Register.
305 typedef union {
306 unsigned all :8;
307 struct {
308 #if defined(__LITTLE_ENDIAN_BITFIELD)
309 unsigned check :1; /* Error occurred */
310 unsigned idx :1; /* Reserved */
311 unsigned corr :1; /* Correctable error occurred */
312 unsigned drq :1; /* Data is request by the device */
313 unsigned dsc :1; /* Media access command finished */
314 unsigned reserved5 :1; /* Reserved */
315 unsigned drdy :1; /* Ignored for ATAPI commands (ready to accept ATA command) */
316 unsigned bsy :1; /* The device has access to the command block */
317 #elif defined(__BIG_ENDIAN_BITFIELD)
318 unsigned bsy :1; /* The device has access to the command block */
319 unsigned drdy :1; /* Ignored for ATAPI commands (ready to accept ATA command) */
320 unsigned reserved5 :1; /* Reserved */
321 unsigned dsc :1; /* Media access command finished */
322 unsigned drq :1; /* Data is request by the device */
323 unsigned corr :1; /* Correctable error occurred */
324 unsigned idx :1; /* Reserved */
325 unsigned check :1; /* Error occurred */
326 #else
327 #error "Bitfield endianness not defined! Check your byteorder.h"
328 #endif
329 } b;
330 } idefloppy_status_reg_t;
333 * The ATAPI error register.
335 typedef union {
336 unsigned all :8;
337 struct {
338 #if defined(__LITTLE_ENDIAN_BITFIELD)
339 unsigned ili :1; /* Illegal Length Indication */
340 unsigned eom :1; /* End Of Media Detected */
341 unsigned abrt :1; /* Aborted command - As defined by ATA */
342 unsigned mcr :1; /* Media Change Requested - As defined by ATA */
343 unsigned sense_key :4; /* Sense key of the last failed packet command */
344 #elif defined(__BIG_ENDIAN_BITFIELD)
345 unsigned sense_key :4; /* Sense key of the last failed packet command */
346 unsigned mcr :1; /* Media Change Requested - As defined by ATA */
347 unsigned abrt :1; /* Aborted command - As defined by ATA */
348 unsigned eom :1; /* End Of Media Detected */
349 unsigned ili :1; /* Illegal Length Indication */
350 #else
351 #error "Bitfield endianness not defined! Check your byteorder.h"
352 #endif
353 } b;
354 } idefloppy_error_reg_t;
357 * ATAPI Feature Register
359 typedef union {
360 unsigned all :8;
361 struct {
362 #if defined(__LITTLE_ENDIAN_BITFIELD)
363 unsigned dma :1; /* Using DMA or PIO */
364 unsigned reserved321 :3; /* Reserved */
365 unsigned reserved654 :3; /* Reserved (Tag Type) */
366 unsigned reserved7 :1; /* Reserved */
367 #elif defined(__BIG_ENDIAN_BITFIELD)
368 unsigned reserved7 :1; /* Reserved */
369 unsigned reserved654 :3; /* Reserved (Tag Type) */
370 unsigned reserved321 :3; /* Reserved */
371 unsigned dma :1; /* Using DMA or PIO */
372 #else
373 #error "Bitfield endianness not defined! Check your byteorder.h"
374 #endif
375 } b;
376 } idefloppy_feature_reg_t;
379 * ATAPI Byte Count Register.
381 typedef union {
382 unsigned all :16;
383 struct {
384 #if defined(__LITTLE_ENDIAN_BITFIELD)
385 unsigned low :8; /* LSB */
386 unsigned high :8; /* MSB */
387 #elif defined(__BIG_ENDIAN_BITFIELD)
388 unsigned high :8; /* MSB */
389 unsigned low :8; /* LSB */
390 #else
391 #error "Bitfield endianness not defined! Check your byteorder.h"
392 #endif
393 } b;
394 } idefloppy_bcount_reg_t;
397 * ATAPI Interrupt Reason Register.
399 typedef union {
400 unsigned all :8;
401 struct {
402 #if defined(__LITTLE_ENDIAN_BITFIELD)
403 unsigned cod :1; /* Information transferred is command (1) or data (0) */
404 unsigned io :1; /* The device requests us to read (1) or write (0) */
405 unsigned reserved :6; /* Reserved */
406 #elif defined(__BIG_ENDIAN_BITFIELD)
407 unsigned reserved :6; /* Reserved */
408 unsigned io :1; /* The device requests us to read (1) or write (0) */
409 unsigned cod :1; /* Information transferred is command (1) or data (0) */
410 #else
411 #error "Bitfield endianness not defined! Check your byteorder.h"
412 #endif
413 } b;
414 } idefloppy_ireason_reg_t;
417 * ATAPI floppy Drive Select Register
419 typedef union {
420 unsigned all :8;
421 struct {
422 #if defined(__LITTLE_ENDIAN_BITFIELD)
423 unsigned sam_lun :3; /* Logical unit number */
424 unsigned reserved3 :1; /* Reserved */
425 unsigned drv :1; /* The responding drive will be drive 0 (0) or drive 1 (1) */
426 unsigned one5 :1; /* Should be set to 1 */
427 unsigned reserved6 :1; /* Reserved */
428 unsigned one7 :1; /* Should be set to 1 */
429 #elif defined(__BIG_ENDIAN_BITFIELD)
430 unsigned one7 :1; /* Should be set to 1 */
431 unsigned reserved6 :1; /* Reserved */
432 unsigned one5 :1; /* Should be set to 1 */
433 unsigned drv :1; /* The responding drive will be drive 0 (0) or drive 1 (1) */
434 unsigned reserved3 :1; /* Reserved */
435 unsigned sam_lun :3; /* Logical unit number */
436 #else
437 #error "Bitfield endianness not defined! Check your byteorder.h"
438 #endif
439 } b;
440 } idefloppy_drivesel_reg_t;
443 * ATAPI Device Control Register
445 typedef union {
446 unsigned all :8;
447 struct {
448 #if defined(__LITTLE_ENDIAN_BITFIELD)
449 unsigned zero0 :1; /* Should be set to zero */
450 unsigned nien :1; /* Device interrupt is disabled (1) or enabled (0) */
451 unsigned srst :1; /* ATA software reset. ATAPI devices should use the new ATAPI srst. */
452 unsigned one3 :1; /* Should be set to 1 */
453 unsigned reserved4567 :4; /* Reserved */
454 #elif defined(__BIG_ENDIAN_BITFIELD)
455 unsigned reserved4567 :4; /* Reserved */
456 unsigned one3 :1; /* Should be set to 1 */
457 unsigned srst :1; /* ATA software reset. ATAPI devices should use the new ATAPI srst. */
458 unsigned nien :1; /* Device interrupt is disabled (1) or enabled (0) */
459 unsigned zero0 :1; /* Should be set to zero */
460 #else
461 #error "Bitfield endianness not defined! Check your byteorder.h"
462 #endif
463 } b;
464 } idefloppy_control_reg_t;
467 * The following is used to format the general configuration word of
468 * the ATAPI IDENTIFY DEVICE command.
470 struct idefloppy_id_gcw {
471 #if defined(__LITTLE_ENDIAN_BITFIELD)
472 unsigned packet_size :2; /* Packet Size */
473 unsigned reserved234 :3; /* Reserved */
474 unsigned drq_type :2; /* Command packet DRQ type */
475 unsigned removable :1; /* Removable media */
476 unsigned device_type :5; /* Device type */
477 unsigned reserved13 :1; /* Reserved */
478 unsigned protocol :2; /* Protocol type */
479 #elif defined(__BIG_ENDIAN_BITFIELD)
480 unsigned protocol :2; /* Protocol type */
481 unsigned reserved13 :1; /* Reserved */
482 unsigned device_type :5; /* Device type */
483 unsigned removable :1; /* Removable media */
484 unsigned drq_type :2; /* Command packet DRQ type */
485 unsigned reserved234 :3; /* Reserved */
486 unsigned packet_size :2; /* Packet Size */
487 #else
488 #error "Bitfield endianness not defined! Check your byteorder.h"
489 #endif
493 * INQUIRY packet command - Data Format
495 typedef struct {
496 #if defined(__LITTLE_ENDIAN_BITFIELD)
497 unsigned device_type :5; /* Peripheral Device Type */
498 unsigned reserved0_765 :3; /* Peripheral Qualifier - Reserved */
499 unsigned reserved1_6t0 :7; /* Reserved */
500 unsigned rmb :1; /* Removable Medium Bit */
501 unsigned ansi_version :3; /* ANSI Version */
502 unsigned ecma_version :3; /* ECMA Version */
503 unsigned iso_version :2; /* ISO Version */
504 unsigned response_format :4; /* Response Data Format */
505 unsigned reserved3_45 :2; /* Reserved */
506 unsigned reserved3_6 :1; /* TrmIOP - Reserved */
507 unsigned reserved3_7 :1; /* AENC - Reserved */
508 #elif defined(__BIG_ENDIAN_BITFIELD)
509 unsigned reserved0_765 :3; /* Peripheral Qualifier - Reserved */
510 unsigned device_type :5; /* Peripheral Device Type */
511 unsigned rmb :1; /* Removable Medium Bit */
512 unsigned reserved1_6t0 :7; /* Reserved */
513 unsigned iso_version :2; /* ISO Version */
514 unsigned ecma_version :3; /* ECMA Version */
515 unsigned ansi_version :3; /* ANSI Version */
516 unsigned reserved3_7 :1; /* AENC - Reserved */
517 unsigned reserved3_6 :1; /* TrmIOP - Reserved */
518 unsigned reserved3_45 :2; /* Reserved */
519 unsigned response_format :4; /* Response Data Format */
520 #else
521 #error "Bitfield endianness not defined! Check your byteorder.h"
522 #endif
523 u8 additional_length; /* Additional Length (total_length-4) */
524 u8 rsv5, rsv6, rsv7; /* Reserved */
525 u8 vendor_id[8]; /* Vendor Identification */
526 u8 product_id[16]; /* Product Identification */
527 u8 revision_level[4]; /* Revision Level */
528 u8 vendor_specific[20]; /* Vendor Specific - Optional */
529 u8 reserved56t95[40]; /* Reserved - Optional */
530 /* Additional information may be returned */
531 } idefloppy_inquiry_result_t;
534 * REQUEST SENSE packet command result - Data Format.
536 typedef struct {
537 #if defined(__LITTLE_ENDIAN_BITFIELD)
538 unsigned error_code :7; /* Current error (0x70) */
539 unsigned valid :1; /* The information field conforms to SFF-8070i */
540 u8 reserved1 :8; /* Reserved */
541 unsigned sense_key :4; /* Sense Key */
542 unsigned reserved2_4 :1; /* Reserved */
543 unsigned ili :1; /* Incorrect Length Indicator */
544 unsigned reserved2_67 :2;
545 #elif defined(__BIG_ENDIAN_BITFIELD)
546 unsigned valid :1; /* The information field conforms to SFF-8070i */
547 unsigned error_code :7; /* Current error (0x70) */
548 u8 reserved1 :8; /* Reserved */
549 unsigned reserved2_67 :2;
550 unsigned ili :1; /* Incorrect Length Indicator */
551 unsigned reserved2_4 :1; /* Reserved */
552 unsigned sense_key :4; /* Sense Key */
553 #else
554 #error "Bitfield endianness not defined! Check your byteorder.h"
555 #endif
556 u32 information __attribute__ ((packed));
557 u8 asl; /* Additional sense length (n-7) */
558 u32 command_specific; /* Additional command specific information */
559 u8 asc; /* Additional Sense Code */
560 u8 ascq; /* Additional Sense Code Qualifier */
561 u8 replaceable_unit_code; /* Field Replaceable Unit Code */
562 u8 reserved[3];
563 u8 pad[2]; /* Padding to 20 bytes */
564 } idefloppy_request_sense_result_t;
567 * Pages of the SELECT SENSE / MODE SENSE packet commands.
569 #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
570 #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
573 * Mode Parameter Header for the MODE SENSE packet command
575 typedef struct {
576 u16 mode_data_length; /* Length of the following data transfer */
577 u8 medium_type; /* Medium Type */
578 #if defined(__LITTLE_ENDIAN_BITFIELD)
579 unsigned reserved3 :7;
580 unsigned wp :1; /* Write protect */
581 #elif defined(__BIG_ENDIAN_BITFIELD)
582 unsigned wp :1; /* Write protect */
583 unsigned reserved3 :7;
584 #else
585 #error "Bitfield endianness not defined! Check your byteorder.h"
586 #endif
587 u8 reserved[4];
588 } idefloppy_mode_parameter_header_t;
590 #define IDEFLOPPY_MIN(a,b) ((a)<(b) ? (a):(b))
591 #define IDEFLOPPY_MAX(a,b) ((a)>(b) ? (a):(b))
594 * Too bad. The drive wants to send us data which we are not ready to accept.
595 * Just throw it away.
597 static void idefloppy_discard_data (ide_drive_t *drive, unsigned int bcount)
599 while (bcount--)
600 IN_BYTE (IDE_DATA_REG);
603 #if IDEFLOPPY_DEBUG_BUGS
604 static void idefloppy_write_zeros (ide_drive_t *drive, unsigned int bcount)
606 while (bcount--)
607 OUT_BYTE (0, IDE_DATA_REG);
609 #endif /* IDEFLOPPY_DEBUG_BUGS */
612 * idefloppy_end_request is used to finish servicing a request.
614 * For read/write requests, we will call ide_end_request to pass to the
615 * next buffer.
617 static void idefloppy_end_request (byte uptodate, ide_hwgroup_t *hwgroup)
619 ide_drive_t *drive = hwgroup->drive;
620 idefloppy_floppy_t *floppy = drive->driver_data;
621 struct request *rq = hwgroup->rq;
622 int error;
624 #if IDEFLOPPY_DEBUG_LOG
625 printk (KERN_INFO "Reached idefloppy_end_request\n");
626 #endif /* IDEFLOPPY_DEBUG_LOG */
628 switch (uptodate) {
629 case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
630 case 1: error = 0; break;
631 default: error = uptodate;
633 if (error)
634 floppy->failed_pc = NULL;
635 /* Why does this happen? */
636 if (!rq)
637 return;
638 if (!IDEFLOPPY_RQ_CMD (rq->cmd)) {
639 ide_end_request (uptodate, hwgroup);
640 return;
642 rq->errors = error;
643 ide_end_drive_cmd (drive, 0, 0);
646 static void idefloppy_input_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount)
648 struct request *rq = pc->rq;
649 struct buffer_head *bh = rq->bh;
650 int count;
652 while (bcount) {
653 if (pc->b_count == bh->b_size) {
654 rq->sector += rq->current_nr_sectors;
655 rq->nr_sectors -= rq->current_nr_sectors;
656 idefloppy_end_request (1, HWGROUP(drive));
657 if ((bh = rq->bh) != NULL)
658 pc->b_count = 0;
660 if (bh == NULL) {
661 printk (KERN_ERR "%s: bh == NULL in idefloppy_input_buffers, bcount == %d\n", drive->name, bcount);
662 idefloppy_discard_data (drive, bcount);
663 return;
665 count = IDEFLOPPY_MIN (bh->b_size - pc->b_count, bcount);
666 atapi_input_bytes (drive, bh->b_data + pc->b_count, count);
667 bcount -= count; pc->b_count += count;
671 static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount)
673 struct request *rq = pc->rq;
674 struct buffer_head *bh = rq->bh;
675 int count;
677 while (bcount) {
678 if (!pc->b_count) {
679 rq->sector += rq->current_nr_sectors;
680 rq->nr_sectors -= rq->current_nr_sectors;
681 idefloppy_end_request (1, HWGROUP(drive));
682 if ((bh = rq->bh) != NULL) {
683 pc->b_data = bh->b_data;
684 pc->b_count = bh->b_size;
687 if (bh == NULL) {
688 printk (KERN_ERR "%s: bh == NULL in idefloppy_output_buffers, bcount == %d\n", drive->name, bcount);
689 idefloppy_write_zeros (drive, bcount);
690 return;
692 count = IDEFLOPPY_MIN (pc->b_count, bcount);
693 atapi_output_bytes (drive, pc->b_data, count);
694 bcount -= count; pc->b_data += count; pc->b_count -= count;
698 #ifdef CONFIG_BLK_DEV_IDEDMA
699 static void idefloppy_update_buffers (ide_drive_t *drive, idefloppy_pc_t *pc)
701 struct request *rq = pc->rq;
702 struct buffer_head *bh = rq->bh;
704 while ((bh = rq->bh) != NULL)
705 idefloppy_end_request (1, HWGROUP(drive));
707 #endif /* CONFIG_BLK_DEV_IDEDMA */
710 * idefloppy_queue_pc_head generates a new packet command request in front
711 * of the request queue, before the current request, so that it will be
712 * processed immediately, on the next pass through the driver.
714 static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struct request *rq)
716 ide_init_drive_cmd (rq);
717 rq->buffer = (char *) pc;
718 rq->cmd = IDEFLOPPY_PC_RQ;
719 (void) ide_do_drive_cmd (drive, rq, ide_preempt);
722 static idefloppy_pc_t *idefloppy_next_pc_storage (ide_drive_t *drive)
724 idefloppy_floppy_t *floppy = drive->driver_data;
726 if (floppy->pc_stack_index==IDEFLOPPY_PC_STACK)
727 floppy->pc_stack_index=0;
728 return (&floppy->pc_stack[floppy->pc_stack_index++]);
731 static struct request *idefloppy_next_rq_storage (ide_drive_t *drive)
733 idefloppy_floppy_t *floppy = drive->driver_data;
735 if (floppy->rq_stack_index==IDEFLOPPY_PC_STACK)
736 floppy->rq_stack_index=0;
737 return (&floppy->rq_stack[floppy->rq_stack_index++]);
741 * idefloppy_analyze_error is called on each failed packet command retry
742 * to analyze the request sense.
744 static void idefloppy_analyze_error (ide_drive_t *drive,idefloppy_request_sense_result_t *result)
746 idefloppy_floppy_t *floppy = drive->driver_data;
748 floppy->sense_key = result->sense_key; floppy->asc = result->asc; floppy->ascq = result->ascq;
749 #if IDEFLOPPY_DEBUG_LOG
750 if (floppy->failed_pc)
751 printk (KERN_INFO "ide-floppy: pc = %x, sense key = %x, asc = %x, ascq = %x\n",floppy->failed_pc->c[0],result->sense_key,result->asc,result->ascq);
752 else
753 printk (KERN_INFO "ide-floppy: sense key = %x, asc = %x, ascq = %x\n",result->sense_key,result->asc,result->ascq);
754 #endif /* IDEFLOPPY_DEBUG_LOG */
757 static void idefloppy_request_sense_callback (ide_drive_t *drive)
759 idefloppy_floppy_t *floppy = drive->driver_data;
761 #if IDEFLOPPY_DEBUG_LOG
762 printk (KERN_INFO "ide-floppy: Reached idefloppy_request_sense_callback\n");
763 #endif /* IDEFLOPPY_DEBUG_LOG */
764 if (!floppy->pc->error) {
765 idefloppy_analyze_error (drive,(idefloppy_request_sense_result_t *) floppy->pc->buffer);
766 idefloppy_end_request (1,HWGROUP (drive));
767 } else {
768 printk (KERN_ERR "Error in REQUEST SENSE itself - Aborting request!\n");
769 idefloppy_end_request (0,HWGROUP (drive));
774 * General packet command callback function.
776 static void idefloppy_pc_callback (ide_drive_t *drive)
778 idefloppy_floppy_t *floppy = drive->driver_data;
780 #if IDEFLOPPY_DEBUG_LOG
781 printk (KERN_INFO "ide-floppy: Reached idefloppy_pc_callback\n");
782 #endif /* IDEFLOPPY_DEBUG_LOG */
784 idefloppy_end_request (floppy->pc->error ? 0:1, HWGROUP(drive));
788 * idefloppy_init_pc initializes a packet command.
790 static void idefloppy_init_pc (idefloppy_pc_t *pc)
792 memset (pc->c, 0, 12);
793 pc->retries = 0;
794 pc->flags = 0;
795 pc->request_transfer = 0;
796 pc->buffer = pc->pc_buffer;
797 pc->buffer_size = IDEFLOPPY_PC_BUFFER_SIZE;
798 pc->b_data = NULL;
799 pc->callback = &idefloppy_pc_callback;
802 static void idefloppy_create_request_sense_cmd (idefloppy_pc_t *pc)
804 idefloppy_init_pc (pc);
805 pc->c[0] = IDEFLOPPY_REQUEST_SENSE_CMD;
806 pc->c[4] = 255;
807 pc->request_transfer = 18;
808 pc->callback = &idefloppy_request_sense_callback;
812 * idefloppy_retry_pc is called when an error was detected during the
813 * last packet command. We queue a request sense packet command in
814 * the head of the request list.
816 static void idefloppy_retry_pc (ide_drive_t *drive)
818 idefloppy_pc_t *pc;
819 struct request *rq;
820 idefloppy_error_reg_t error;
822 error.all = IN_BYTE (IDE_ERROR_REG);
823 pc = idefloppy_next_pc_storage (drive);
824 rq = idefloppy_next_rq_storage (drive);
825 idefloppy_create_request_sense_cmd (pc);
826 idefloppy_queue_pc_head (drive, pc, rq);
830 * idefloppy_pc_intr is the usual interrupt handler which will be called
831 * during a packet command.
833 static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
835 idefloppy_floppy_t *floppy = drive->driver_data;
836 idefloppy_status_reg_t status;
837 idefloppy_bcount_reg_t bcount;
838 idefloppy_ireason_reg_t ireason;
839 idefloppy_pc_t *pc=floppy->pc;
840 struct request *rq = pc->rq;
841 unsigned int temp;
843 #if IDEFLOPPY_DEBUG_LOG
844 printk (KERN_INFO "ide-floppy: Reached idefloppy_pc_intr interrupt handler\n");
845 #endif /* IDEFLOPPY_DEBUG_LOG */
847 #ifdef CONFIG_BLK_DEV_IDEDMA
848 if (test_bit (PC_DMA_IN_PROGRESS, &pc->flags)) {
849 if (HWIF(drive)->dmaproc(ide_dma_end, drive)) {
850 set_bit (PC_DMA_ERROR, &pc->flags);
851 } else {
852 pc->actually_transferred=pc->request_transfer;
853 idefloppy_update_buffers (drive, pc);
855 #if IDEFLOPPY_DEBUG_LOG
856 printk (KERN_INFO "ide-floppy: DMA finished\n");
857 #endif /* IDEFLOPPY_DEBUG_LOG */
859 #endif /* CONFIG_BLK_DEV_IDEDMA */
861 status.all = GET_STAT(); /* Clear the interrupt */
863 if (!status.b.drq) { /* No more interrupts */
864 #if IDEFLOPPY_DEBUG_LOG
865 printk (KERN_INFO "Packet command completed, %d bytes transferred\n", pc->actually_transferred);
866 #endif /* IDEFLOPPY_DEBUG_LOG */
867 clear_bit (PC_DMA_IN_PROGRESS, &pc->flags);
869 ide__sti(); /* local CPU only */
871 if (status.b.check || test_bit (PC_DMA_ERROR, &pc->flags)) { /* Error detected */
872 #if IDEFLOPPY_DEBUG_LOG
873 printk (KERN_INFO "ide-floppy: %s: I/O error\n",drive->name);
874 #endif /* IDEFLOPPY_DEBUG_LOG */
875 rq->errors++;
876 if (pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD) {
877 printk (KERN_ERR "ide-floppy: I/O error in request sense command\n");
878 return ide_do_reset (drive);
880 idefloppy_retry_pc (drive); /* Retry operation */
881 return ide_stopped; /* queued, but not started */
883 pc->error = 0;
884 if (floppy->failed_pc == pc)
885 floppy->failed_pc=NULL;
886 pc->callback(drive); /* Command finished - Call the callback function */
887 return ide_stopped;
889 #ifdef CONFIG_BLK_DEV_IDEDMA
890 if (test_and_clear_bit (PC_DMA_IN_PROGRESS, &pc->flags)) {
891 printk (KERN_ERR "ide-floppy: The floppy wants to issue more interrupts in DMA mode\n");
892 (void) HWIF(drive)->dmaproc(ide_dma_off, drive);
893 return ide_do_reset (drive);
895 #endif /* CONFIG_BLK_DEV_IDEDMA */
896 bcount.b.high=IN_BYTE (IDE_BCOUNTH_REG); /* Get the number of bytes to transfer */
897 bcount.b.low=IN_BYTE (IDE_BCOUNTL_REG); /* on this interrupt */
898 ireason.all=IN_BYTE (IDE_IREASON_REG);
900 if (ireason.b.cod) {
901 printk (KERN_ERR "ide-floppy: CoD != 0 in idefloppy_pc_intr\n");
902 return ide_do_reset (drive);
904 if (ireason.b.io == test_bit (PC_WRITING, &pc->flags)) { /* Hopefully, we will never get here */
905 printk (KERN_ERR "ide-floppy: We wanted to %s, ", ireason.b.io ? "Write":"Read");
906 printk (KERN_ERR "but the floppy wants us to %s !\n",ireason.b.io ? "Read":"Write");
907 return ide_do_reset (drive);
909 if (!test_bit (PC_WRITING, &pc->flags)) { /* Reading - Check that we have enough space */
910 temp = pc->actually_transferred + bcount.all;
911 if ( temp > pc->request_transfer) {
912 if (temp > pc->buffer_size) {
913 printk (KERN_ERR "ide-floppy: The floppy wants to send us more data than expected - discarding data\n");
914 idefloppy_discard_data (drive,bcount.all);
915 ide_set_handler (drive,&idefloppy_pc_intr,IDEFLOPPY_WAIT_CMD, NULL);
916 return ide_started;
918 #if IDEFLOPPY_DEBUG_LOG
919 printk (KERN_NOTICE "ide-floppy: The floppy wants to send us more data than expected - allowing transfer\n");
920 #endif /* IDEFLOPPY_DEBUG_LOG */
923 if (test_bit (PC_WRITING, &pc->flags)) {
924 if (pc->buffer != NULL)
925 atapi_output_bytes (drive,pc->current_position,bcount.all); /* Write the current buffer */
926 else
927 idefloppy_output_buffers (drive, pc, bcount.all);
928 } else {
929 if (pc->buffer != NULL)
930 atapi_input_bytes (drive,pc->current_position,bcount.all); /* Read the current buffer */
931 else
932 idefloppy_input_buffers (drive, pc, bcount.all);
934 pc->actually_transferred+=bcount.all; /* Update the current position */
935 pc->current_position+=bcount.all;
937 ide_set_handler (drive,&idefloppy_pc_intr,IDEFLOPPY_WAIT_CMD, NULL); /* And set the interrupt handler again */
938 return ide_started;
941 static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive)
943 ide_startstop_t startstop;
944 idefloppy_floppy_t *floppy = drive->driver_data;
945 idefloppy_ireason_reg_t ireason;
947 if (ide_wait_stat (&startstop,drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) {
948 printk (KERN_ERR "ide-floppy: Strange, packet command initiated yet DRQ isn't asserted\n");
949 return startstop;
951 ireason.all=IN_BYTE (IDE_IREASON_REG);
952 if (!ireason.b.cod || ireason.b.io) {
953 printk (KERN_ERR "ide-floppy: (IO,CoD) != (0,1) while issuing a packet command\n");
954 return ide_do_reset (drive);
956 ide_set_handler (drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); /* Set the interrupt routine */
957 atapi_output_bytes (drive, floppy->pc->c, 12); /* Send the actual packet */
958 return ide_started;
962 * Issue a packet command
964 static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *pc)
966 idefloppy_floppy_t *floppy = drive->driver_data;
967 idefloppy_bcount_reg_t bcount;
968 int dma_ok = 0;
970 #if IDEFLOPPY_DEBUG_BUGS
971 if (floppy->pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD && pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD) {
972 printk (KERN_ERR "ide-floppy: possible ide-floppy.c bug - Two request sense in serial were issued\n");
974 #endif /* IDEFLOPPY_DEBUG_BUGS */
976 if (floppy->failed_pc == NULL && pc->c[0] != IDEFLOPPY_REQUEST_SENSE_CMD)
977 floppy->failed_pc=pc;
978 floppy->pc=pc; /* Set the current packet command */
980 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES || test_bit (PC_ABORT, &pc->flags)) {
982 * We will "abort" retrying a packet command in case
983 * a legitimate error code was received.
985 if (!test_bit (PC_ABORT, &pc->flags)) {
986 printk (KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, asc = %2x, ascq = %2x\n",
987 drive->name, pc->c[0], floppy->sense_key, floppy->asc, floppy->ascq);
988 pc->error = IDEFLOPPY_ERROR_GENERAL; /* Giving up */
990 floppy->failed_pc=NULL;
991 pc->callback(drive);
992 return ide_stopped;
994 #if IDEFLOPPY_DEBUG_LOG
995 printk (KERN_INFO "Retry number - %d\n",pc->retries);
996 #endif /* IDEFLOPPY_DEBUG_LOG */
998 pc->retries++;
999 pc->actually_transferred=0; /* We haven't transferred any data yet */
1000 pc->current_position=pc->buffer;
1001 bcount.all = IDE_MIN(pc->request_transfer, 63 * 1024);
1003 #ifdef CONFIG_BLK_DEV_IDEDMA
1004 if (test_and_clear_bit (PC_DMA_ERROR, &pc->flags)) {
1005 (void) HWIF(drive)->dmaproc(ide_dma_off, drive);
1007 if (test_bit (PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
1008 dma_ok=!HWIF(drive)->dmaproc(test_bit (PC_WRITING, &pc->flags) ? ide_dma_write : ide_dma_read, drive);
1009 #endif /* CONFIG_BLK_DEV_IDEDMA */
1011 if (IDE_CONTROL_REG)
1012 OUT_BYTE (drive->ctl,IDE_CONTROL_REG);
1013 OUT_BYTE (dma_ok ? 1:0,IDE_FEATURE_REG); /* Use PIO/DMA */
1014 OUT_BYTE (bcount.b.high,IDE_BCOUNTH_REG);
1015 OUT_BYTE (bcount.b.low,IDE_BCOUNTL_REG);
1016 OUT_BYTE (drive->select.all,IDE_SELECT_REG);
1018 #ifdef CONFIG_BLK_DEV_IDEDMA
1019 if (dma_ok) { /* Begin DMA, if necessary */
1020 set_bit (PC_DMA_IN_PROGRESS, &pc->flags);
1021 (void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
1023 #endif /* CONFIG_BLK_DEV_IDEDMA */
1025 if (test_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags)) {
1026 ide_set_handler (drive, &idefloppy_transfer_pc, IDEFLOPPY_WAIT_CMD, NULL);
1027 OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* Issue the packet command */
1028 return ide_started;
1029 } else {
1030 OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG);
1031 return idefloppy_transfer_pc (drive);
1035 static void idefloppy_rw_callback (ide_drive_t *drive)
1037 #if IDEFLOPPY_DEBUG_LOG
1038 printk (KERN_INFO "ide-floppy: Reached idefloppy_rw_callback\n");
1039 #endif /* IDEFLOPPY_DEBUG_LOG */
1041 idefloppy_end_request(1, HWGROUP(drive));
1042 return;
1045 static void idefloppy_create_prevent_cmd (idefloppy_pc_t *pc, int prevent)
1047 #if IDEFLOPPY_DEBUG_LOG
1048 printk (KERN_INFO "ide-floppy: creating prevent removal command, prevent = %d\n", prevent);
1049 #endif /* IDEFLOPPY_DEBUG_LOG */
1051 idefloppy_init_pc (pc);
1052 pc->c[0] = IDEFLOPPY_PREVENT_REMOVAL_CMD;
1053 pc->c[4] = prevent;
1056 static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t *pc)
1058 idefloppy_init_pc (pc);
1059 pc->c[0] = IDEFLOPPY_READ_CAPACITY_CMD;
1060 pc->c[7] = 255;
1061 pc->c[8] = 255;
1062 pc->request_transfer = 255;
1066 * A mode sense command is used to "sense" floppy parameters.
1068 static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t *pc, byte page_code, byte type)
1070 unsigned short length = sizeof (idefloppy_mode_parameter_header_t);
1072 idefloppy_init_pc (pc);
1073 pc->c[0] = IDEFLOPPY_MODE_SENSE_CMD;
1074 pc->c[1] = 0;
1075 pc->c[2] = page_code + (type << 6);
1077 switch (page_code) {
1078 case IDEFLOPPY_CAPABILITIES_PAGE:
1079 length += 12;
1080 break;
1081 case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
1082 length += 32;
1083 break;
1084 default:
1085 printk (KERN_ERR "ide-floppy: unsupported page code in create_mode_sense_cmd\n");
1087 put_unaligned (htons (length), (unsigned short *) &pc->c[7]);
1088 pc->request_transfer = length;
1091 static void idefloppy_create_start_stop_cmd (idefloppy_pc_t *pc, int start)
1093 idefloppy_init_pc (pc);
1094 pc->c[0] = IDEFLOPPY_START_STOP_CMD;
1095 pc->c[4] = start;
1098 static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t *pc)
1100 idefloppy_init_pc(pc);
1101 pc->c[0] = IDEFLOPPY_TEST_UNIT_READY_CMD;
1104 static void idefloppy_create_rw_cmd (idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq, unsigned long sector)
1106 int block = sector / floppy->bs_factor;
1107 int blocks = rq->nr_sectors / floppy->bs_factor;
1109 #if IDEFLOPPY_DEBUG_LOG
1110 printk ("create_rw1%d_cmd: block == %d, blocks == %d\n",
1111 2 * test_bit (IDEFLOPPY_USE_READ12, &floppy->flags), block, blocks);
1112 #endif /* IDEFLOPPY_DEBUG_LOG */
1114 idefloppy_init_pc (pc);
1115 if (test_bit (IDEFLOPPY_USE_READ12, &floppy->flags)) {
1116 pc->c[0] = rq->cmd == READ ? IDEFLOPPY_READ12_CMD : IDEFLOPPY_WRITE12_CMD;
1117 put_unaligned (htonl (blocks), (unsigned int *) &pc->c[6]);
1118 } else {
1119 pc->c[0] = rq->cmd == READ ? IDEFLOPPY_READ10_CMD : IDEFLOPPY_WRITE10_CMD;
1120 put_unaligned (htons (blocks), (unsigned short *) &pc->c[7]);
1122 put_unaligned (htonl (block), (unsigned int *) &pc->c[2]);
1123 pc->callback = &idefloppy_rw_callback;
1124 pc->rq = rq;
1125 pc->b_data = rq->buffer;
1126 pc->b_count = rq->cmd == READ ? 0 : rq->bh->b_size;
1127 if (rq->cmd == WRITE)
1128 set_bit (PC_WRITING, &pc->flags);
1129 pc->buffer = NULL;
1130 pc->request_transfer = pc->buffer_size = blocks * floppy->block_size;
1131 set_bit (PC_DMA_RECOMMENDED, &pc->flags);
1135 * idefloppy_do_request is our request handling function.
1137 static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request *rq, unsigned long block)
1139 idefloppy_floppy_t *floppy = drive->driver_data;
1140 idefloppy_pc_t *pc;
1142 #if IDEFLOPPY_DEBUG_LOG
1143 printk (KERN_INFO "rq_status: %d, rq_dev: %u, cmd: %d, errors: %d\n",rq->rq_status,(unsigned int) rq->rq_dev,rq->cmd,rq->errors);
1144 printk (KERN_INFO "sector: %ld, nr_sectors: %ld, current_nr_sectors: %ld\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors);
1145 #endif /* IDEFLOPPY_DEBUG_LOG */
1147 if (rq->errors >= ERROR_MAX) {
1148 if (floppy->failed_pc != NULL)
1149 printk (KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, asc = %2x, ascq = %2x\n",
1150 drive->name, floppy->failed_pc->c[0], floppy->sense_key, floppy->asc, floppy->ascq);
1151 else
1152 printk (KERN_ERR "ide-floppy: %s: I/O error\n", drive->name);
1153 idefloppy_end_request (0, HWGROUP(drive));
1154 return ide_stopped;
1156 switch (rq->cmd) {
1157 case READ:
1158 case WRITE:
1159 if (rq->sector % floppy->bs_factor || rq->nr_sectors % floppy->bs_factor) {
1160 printk ("%s: unsupported r/w request size\n", drive->name);
1161 idefloppy_end_request (0, HWGROUP(drive));
1162 return ide_stopped;
1164 pc = idefloppy_next_pc_storage (drive);
1165 idefloppy_create_rw_cmd (floppy, pc, rq, block);
1166 break;
1167 case IDEFLOPPY_PC_RQ:
1168 pc = (idefloppy_pc_t *) rq->buffer;
1169 break;
1170 default:
1171 printk (KERN_ERR "ide-floppy: unsupported command %x in request queue\n", rq->cmd);
1172 idefloppy_end_request (0,HWGROUP (drive));
1173 return ide_stopped;
1175 pc->rq = rq;
1176 return idefloppy_issue_pc (drive, pc);
1180 * idefloppy_queue_pc_tail adds a special packet command request to the
1181 * tail of the request queue, and waits for it to be serviced.
1183 static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc)
1185 struct request rq;
1187 ide_init_drive_cmd (&rq);
1188 rq.buffer = (char *) pc;
1189 rq.cmd = IDEFLOPPY_PC_RQ;
1190 return ide_do_drive_cmd (drive, &rq, ide_wait);
1194 * Look at the flexible disk page parameters. We will ignore the CHS
1195 * capacity parameters and use the LBA parameters instead.
1197 static int idefloppy_get_flexible_disk_page (ide_drive_t *drive)
1199 idefloppy_floppy_t *floppy = drive->driver_data;
1200 idefloppy_pc_t pc;
1201 idefloppy_mode_parameter_header_t *header;
1202 idefloppy_flexible_disk_page_t *page;
1203 int capacity, lba_capacity;
1205 idefloppy_create_mode_sense_cmd (&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, MODE_SENSE_CURRENT);
1206 if (idefloppy_queue_pc_tail (drive,&pc)) {
1207 printk (KERN_ERR "ide-floppy: Can't get flexible disk page parameters\n");
1208 return 1;
1210 header = (idefloppy_mode_parameter_header_t *) pc.buffer;
1211 floppy->wp = header->wp;
1212 page = (idefloppy_flexible_disk_page_t *) (header + 1);
1214 page->transfer_rate = ntohs (page->transfer_rate);
1215 page->sector_size = ntohs (page->sector_size);
1216 page->cyls = ntohs (page->cyls);
1217 page->rpm = ntohs (page->rpm);
1218 capacity = page->cyls * page->heads * page->sectors * page->sector_size;
1219 if (memcmp (page, &floppy->flexible_disk_page, sizeof (idefloppy_flexible_disk_page_t)))
1220 printk (KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, %d sector size, %d rpm\n",
1221 drive->name, capacity / 1024, page->cyls, page->heads, page->sectors,
1222 page->transfer_rate / 8, page->sector_size, page->rpm);
1224 floppy->flexible_disk_page = *page;
1225 drive->bios_cyl = page->cyls;
1226 drive->bios_head = page->heads;
1227 drive->bios_sect = page->sectors;
1228 lba_capacity = floppy->blocks * floppy->block_size;
1229 if (capacity < lba_capacity) {
1230 printk (KERN_NOTICE "%s: The disk reports a capacity of %d bytes, "
1231 "but the drive only handles %d\n",
1232 drive->name, lba_capacity, capacity);
1233 floppy->blocks = floppy->block_size ? capacity / floppy->block_size : 0;
1235 return 0;
1239 * Determine if a media is present in the floppy drive, and if so,
1240 * its LBA capacity.
1242 static int idefloppy_get_capacity (ide_drive_t *drive)
1244 idefloppy_floppy_t *floppy = drive->driver_data;
1245 idefloppy_pc_t pc;
1246 idefloppy_capacity_header_t *header;
1247 idefloppy_capacity_descriptor_t *descriptor;
1248 int i, descriptors, rc = 1, blocks, length;
1250 drive->bios_cyl = 0;
1251 drive->bios_head = drive->bios_sect = 0;
1252 floppy->blocks = floppy->bs_factor = 0;
1253 drive->part[0].nr_sects = 0;
1255 idefloppy_create_read_capacity_cmd (&pc);
1256 if (idefloppy_queue_pc_tail (drive, &pc)) {
1257 printk (KERN_ERR "ide-floppy: Can't get floppy parameters\n");
1258 return 1;
1260 header = (idefloppy_capacity_header_t *) pc.buffer;
1261 descriptors = header->length / sizeof (idefloppy_capacity_descriptor_t);
1262 descriptor = (idefloppy_capacity_descriptor_t *) (header + 1);
1263 for (i = 0; i < descriptors; i++, descriptor++) {
1264 blocks = descriptor->blocks = ntohl (descriptor->blocks);
1265 length = descriptor->length = ntohs (descriptor->length);
1266 if (!i && descriptor->dc == CAPACITY_CURRENT) {
1267 if (memcmp (descriptor, &floppy->capacity, sizeof (idefloppy_capacity_descriptor_t))) {
1268 printk (KERN_INFO "%s: %dkB, %d blocks, %d sector size, %s \n",
1269 drive->name, blocks * length / 1024, blocks, length,
1270 drive->using_dma ? ", DMA":"");
1272 floppy->capacity = *descriptor;
1273 if (!length || length % 512)
1274 printk (KERN_ERR "%s: %d bytes block size not supported\n", drive->name, length);
1275 else {
1276 floppy->blocks = blocks;
1277 floppy->block_size = length;
1278 if ((floppy->bs_factor = length / 512) != 1)
1279 printk (KERN_NOTICE "%s: warning: non 512 bytes block size not fully supported\n", drive->name);
1280 rc = 0;
1283 #if IDEFLOPPY_DEBUG_INFO
1284 if (!i) printk (KERN_INFO "Descriptor 0 Code: %d\n", descriptor->dc);
1285 printk (KERN_INFO "Descriptor %d: %dkB, %d blocks, %d sector size\n", i, blocks * length / 1024, blocks, length);
1286 #endif /* IDEFLOPPY_DEBUG_INFO */
1288 (void) idefloppy_get_flexible_disk_page (drive);
1289 drive->part[0].nr_sects = floppy->blocks * floppy->bs_factor;
1290 return rc;
1294 * Our special ide-floppy ioctl's.
1296 * Currently there aren't any ioctl's.
1298 static int idefloppy_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file,
1299 unsigned int cmd, unsigned long arg)
1301 idefloppy_pc_t pc;
1303 if (cmd == CDROMEJECT) {
1304 if (drive->usage > 1)
1305 return -EBUSY;
1306 idefloppy_create_prevent_cmd (&pc, 0);
1307 (void) idefloppy_queue_pc_tail (drive, &pc);
1308 idefloppy_create_start_stop_cmd (&pc, 2);
1309 (void) idefloppy_queue_pc_tail (drive, &pc);
1310 return 0;
1312 return -EIO;
1316 * Our open/release functions
1318 static int idefloppy_open (struct inode *inode, struct file *filp, ide_drive_t *drive)
1320 idefloppy_floppy_t *floppy = drive->driver_data;
1321 idefloppy_pc_t pc;
1323 #if IDEFLOPPY_DEBUG_LOG
1324 printk (KERN_INFO "Reached idefloppy_open\n");
1325 #endif /* IDEFLOPPY_DEBUG_LOG */
1327 MOD_INC_USE_COUNT;
1328 if (drive->usage == 1) {
1329 idefloppy_create_test_unit_ready_cmd(&pc);
1330 if (idefloppy_queue_pc_tail(drive, &pc)) {
1331 idefloppy_create_start_stop_cmd (&pc, 1);
1332 (void) idefloppy_queue_pc_tail (drive, &pc);
1334 if (idefloppy_get_capacity (drive)) {
1335 drive->usage--;
1336 MOD_DEC_USE_COUNT;
1337 return -EIO;
1339 if (floppy->wp && (filp->f_mode & 2)) {
1340 drive->usage--;
1341 MOD_DEC_USE_COUNT;
1342 return -EROFS;
1344 set_bit (IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
1345 idefloppy_create_prevent_cmd (&pc, 1);
1346 (void) idefloppy_queue_pc_tail (drive, &pc);
1347 check_disk_change(inode->i_rdev);
1349 return 0;
1352 static void idefloppy_release (struct inode *inode, struct file *filp, ide_drive_t *drive)
1354 idefloppy_pc_t pc;
1356 #if IDEFLOPPY_DEBUG_LOG
1357 printk (KERN_INFO "Reached idefloppy_release\n");
1358 #endif /* IDEFLOPPY_DEBUG_LOG */
1360 if (!drive->usage) {
1361 invalidate_buffers (inode->i_rdev);
1362 idefloppy_create_prevent_cmd (&pc, 0);
1363 (void) idefloppy_queue_pc_tail (drive, &pc);
1365 MOD_DEC_USE_COUNT;
1369 * Check media change. Use a simple algorithm for now.
1371 static int idefloppy_media_change (ide_drive_t *drive)
1373 idefloppy_floppy_t *floppy = drive->driver_data;
1375 return test_and_clear_bit (IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
1379 * Revalidate the new media. Should set blk_size[]
1381 static void idefloppy_revalidate (ide_drive_t *drive)
1383 grok_partitions(HWIF(drive)->gd, drive->select.b.unit,
1384 1<<PARTN_BITS,
1385 current_capacity(drive));
1389 * Return the current floppy capacity to ide.c.
1391 static unsigned long idefloppy_capacity (ide_drive_t *drive)
1393 idefloppy_floppy_t *floppy = drive->driver_data;
1394 unsigned long capacity = floppy->blocks * floppy->bs_factor;
1396 return capacity;
1400 * idefloppy_identify_device checks if we can support a drive,
1401 * based on the ATAPI IDENTIFY command results.
1403 static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id)
1405 struct idefloppy_id_gcw gcw;
1406 #if IDEFLOPPY_DEBUG_INFO
1407 unsigned short mask,i;
1408 char buffer[80];
1409 #endif /* IDEFLOPPY_DEBUG_INFO */
1411 *((unsigned short *) &gcw) = id->config;
1413 #ifdef CONFIG_PPC
1414 /* kludge for Apple PowerBook internal zip */
1415 if ((gcw.device_type == 5) && !strstr(id->model, "CD-ROM")
1416 && strstr(id->model, "ZIP"))
1417 gcw.device_type = 0;
1418 #endif
1420 #if IDEFLOPPY_DEBUG_INFO
1421 printk (KERN_INFO "Dumping ATAPI Identify Device floppy parameters\n");
1422 switch (gcw.protocol) {
1423 case 0: case 1: sprintf (buffer, "ATA");break;
1424 case 2: sprintf (buffer, "ATAPI");break;
1425 case 3: sprintf (buffer, "Reserved (Unknown to ide-floppy)");break;
1427 printk (KERN_INFO "Protocol Type: %s\n", buffer);
1428 switch (gcw.device_type) {
1429 case 0: sprintf (buffer, "Direct-access Device");break;
1430 case 1: sprintf (buffer, "Streaming Tape Device");break;
1431 case 2: case 3: case 4: sprintf (buffer, "Reserved");break;
1432 case 5: sprintf (buffer, "CD-ROM Device");break;
1433 case 6: sprintf (buffer, "Reserved");
1434 case 7: sprintf (buffer, "Optical memory Device");break;
1435 case 0x1f: sprintf (buffer, "Unknown or no Device type");break;
1436 default: sprintf (buffer, "Reserved");
1438 printk (KERN_INFO "Device Type: %x - %s\n", gcw.device_type, buffer);
1439 printk (KERN_INFO "Removable: %s\n",gcw.removable ? "Yes":"No");
1440 switch (gcw.drq_type) {
1441 case 0: sprintf (buffer, "Microprocessor DRQ");break;
1442 case 1: sprintf (buffer, "Interrupt DRQ");break;
1443 case 2: sprintf (buffer, "Accelerated DRQ");break;
1444 case 3: sprintf (buffer, "Reserved");break;
1446 printk (KERN_INFO "Command Packet DRQ Type: %s\n", buffer);
1447 switch (gcw.packet_size) {
1448 case 0: sprintf (buffer, "12 bytes");break;
1449 case 1: sprintf (buffer, "16 bytes");break;
1450 default: sprintf (buffer, "Reserved");break;
1452 printk (KERN_INFO "Command Packet Size: %s\n", buffer);
1453 printk (KERN_INFO "Model: %.40s\n",id->model);
1454 printk (KERN_INFO "Firmware Revision: %.8s\n",id->fw_rev);
1455 printk (KERN_INFO "Serial Number: %.20s\n",id->serial_no);
1456 printk (KERN_INFO "Write buffer size(?): %d bytes\n",id->buf_size*512);
1457 printk (KERN_INFO "DMA: %s",id->capability & 0x01 ? "Yes\n":"No\n");
1458 printk (KERN_INFO "LBA: %s",id->capability & 0x02 ? "Yes\n":"No\n");
1459 printk (KERN_INFO "IORDY can be disabled: %s",id->capability & 0x04 ? "Yes\n":"No\n");
1460 printk (KERN_INFO "IORDY supported: %s",id->capability & 0x08 ? "Yes\n":"Unknown\n");
1461 printk (KERN_INFO "ATAPI overlap supported: %s",id->capability & 0x20 ? "Yes\n":"No\n");
1462 printk (KERN_INFO "PIO Cycle Timing Category: %d\n",id->tPIO);
1463 printk (KERN_INFO "DMA Cycle Timing Category: %d\n",id->tDMA);
1464 printk (KERN_INFO "Single Word DMA supported modes:\n");
1465 for (i=0,mask=1;i<8;i++,mask=mask << 1) {
1466 if (id->dma_1word & mask)
1467 printk (KERN_INFO " Mode %d%s\n", i, (id->dma_1word & (mask << 8)) ? " (active)" : "");
1469 printk (KERN_INFO "Multi Word DMA supported modes:\n");
1470 for (i=0,mask=1;i<8;i++,mask=mask << 1) {
1471 if (id->dma_mword & mask)
1472 printk (KERN_INFO " Mode %d%s\n", i, (id->dma_mword & (mask << 8)) ? " (active)" : "");
1474 if (id->field_valid & 0x0002) {
1475 printk (KERN_INFO "Enhanced PIO Modes: %s\n",id->eide_pio_modes & 1 ? "Mode 3":"None");
1476 if (id->eide_dma_min == 0)
1477 sprintf (buffer, "Not supported");
1478 else
1479 sprintf (buffer, "%d ns",id->eide_dma_min);
1480 printk (KERN_INFO "Minimum Multi-word DMA cycle per word: %s\n", buffer);
1481 if (id->eide_dma_time == 0)
1482 sprintf (buffer, "Not supported");
1483 else
1484 sprintf (buffer, "%d ns",id->eide_dma_time);
1485 printk (KERN_INFO "Manufacturer\'s Recommended Multi-word cycle: %s\n", buffer);
1486 if (id->eide_pio == 0)
1487 sprintf (buffer, "Not supported");
1488 else
1489 sprintf (buffer, "%d ns",id->eide_pio);
1490 printk (KERN_INFO "Minimum PIO cycle without IORDY: %s\n", buffer);
1491 if (id->eide_pio_iordy == 0)
1492 sprintf (buffer, "Not supported");
1493 else
1494 sprintf (buffer, "%d ns",id->eide_pio_iordy);
1495 printk (KERN_INFO "Minimum PIO cycle with IORDY: %s\n", buffer);
1496 } else
1497 printk (KERN_INFO "According to the device, fields 64-70 are not valid.\n");
1498 #endif /* IDEFLOPPY_DEBUG_INFO */
1500 if (gcw.protocol != 2)
1501 printk (KERN_ERR "ide-floppy: Protocol is not ATAPI\n");
1502 else if (gcw.device_type != 0)
1503 printk (KERN_ERR "ide-floppy: Device type is not set to floppy\n");
1504 else if (!gcw.removable)
1505 printk (KERN_ERR "ide-floppy: The removable flag is not set\n");
1506 else if (gcw.drq_type == 3) {
1507 printk (KERN_ERR "ide-floppy: Sorry, DRQ type %d not supported\n", gcw.drq_type);
1508 } else if (gcw.packet_size != 0) {
1509 printk (KERN_ERR "ide-floppy: Packet size is not 12 bytes long\n");
1510 } else
1511 return 1;
1512 return 0;
1515 static void idefloppy_add_settings(ide_drive_t *drive)
1517 int major = HWIF(drive)->major;
1518 int minor = drive->select.b.unit << PARTN_BITS;
1520 ide_add_setting(drive, "bios_cyl", SETTING_RW, -1, -1, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL);
1521 ide_add_setting(drive, "bios_head", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL);
1522 ide_add_setting(drive, "bios_sect", SETTING_RW, -1, -1, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL);
1523 ide_add_setting(drive, "breada_readahead", SETTING_RW, BLKRAGET, BLKRASET, TYPE_INT, 0, 255, 1, 2, &read_ahead[major], NULL);
1524 ide_add_setting(drive, "file_readahead", SETTING_RW, BLKFRAGET, BLKFRASET, TYPE_INTA, 0, INT_MAX, 1, 1024, &max_readahead[major][minor], NULL);
1525 ide_add_setting(drive, "max_kb_per_request", SETTING_RW, BLKSECTGET, BLKSECTSET, TYPE_INTA, 1, 255, 1, 2, &max_sectors[major][minor], NULL);
1530 * Driver initialization.
1532 static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy)
1534 struct idefloppy_id_gcw gcw;
1535 int major = HWIF(drive)->major, i;
1536 int minor = drive->select.b.unit << PARTN_BITS;
1538 *((unsigned short *) &gcw) = drive->id->config;
1539 drive->driver_data = floppy;
1540 drive->ready_stat = 0;
1541 memset (floppy, 0, sizeof (idefloppy_floppy_t));
1542 floppy->drive = drive;
1543 floppy->pc = floppy->pc_stack;
1544 if (gcw.drq_type == 1)
1545 set_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags);
1547 * We used to check revisions here. At this point however
1548 * I'm giving up. Just assume they are all broken, its easier.
1550 * The actual reason for the workarounds was likely
1551 * a driver bug after all rather than a firmware bug,
1552 * and the workaround below used to hide it. It should
1553 * be fixed as of version 1.9, but to be on the safe side
1554 * we'll leave the limitation below for the 2.2.x tree.
1557 if (strcmp(drive->id->model, "IOMEGA ZIP 100 ATAPI") == 0)
1559 for (i = 0; i < 1 << PARTN_BITS; i++)
1560 max_sectors[major][minor + i] = 64;
1563 (void) idefloppy_get_capacity (drive);
1564 idefloppy_add_settings(drive);
1565 for (i = 0; i < MAX_DRIVES; ++i) {
1566 ide_hwif_t *hwif = HWIF(drive);
1568 if (drive != &hwif->drives[i]) continue;
1569 hwif->gd->de_arr[i] = drive->de;
1570 if (drive->removable)
1571 hwif->gd->flags[i] |= GENHD_FL_REMOVABLE;
1572 break;
1576 static int idefloppy_cleanup (ide_drive_t *drive)
1578 idefloppy_floppy_t *floppy = drive->driver_data;
1580 if (ide_unregister_subdriver (drive))
1581 return 1;
1582 drive->driver_data = NULL;
1583 kfree (floppy);
1584 return 0;
1587 #ifdef CONFIG_PROC_FS
1589 static ide_proc_entry_t idefloppy_proc[] = {
1590 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
1591 { NULL, 0, NULL, NULL }
1594 #else
1596 #define idefloppy_proc NULL
1598 #endif /* CONFIG_PROC_FS */
1601 * IDE subdriver functions, registered with ide.c
1603 static ide_driver_t idefloppy_driver = {
1604 "ide-floppy", /* name */
1605 IDEFLOPPY_VERSION, /* version */
1606 ide_floppy, /* media */
1607 0, /* busy */
1608 1, /* supports_dma */
1609 0, /* supports_dsc_overlap */
1610 idefloppy_cleanup, /* cleanup */
1611 idefloppy_do_request, /* do_request */
1612 idefloppy_end_request, /* end_request */
1613 idefloppy_ioctl, /* ioctl */
1614 idefloppy_open, /* open */
1615 idefloppy_release, /* release */
1616 idefloppy_media_change, /* media_change */
1617 idefloppy_revalidate, /* media_change */
1618 NULL, /* pre_reset */
1619 idefloppy_capacity, /* capacity */
1620 NULL, /* special */
1621 idefloppy_proc /* proc */
1624 int idefloppy_init (void);
1625 static ide_module_t idefloppy_module = {
1626 IDE_DRIVER_MODULE,
1627 idefloppy_init,
1628 &idefloppy_driver,
1629 NULL
1633 * idefloppy_init will register the driver for each floppy.
1635 int idefloppy_init (void)
1637 ide_drive_t *drive;
1638 idefloppy_floppy_t *floppy;
1639 int failed = 0;
1641 MOD_INC_USE_COUNT;
1642 while ((drive = ide_scan_devices (ide_floppy, idefloppy_driver.name, NULL, failed++)) != NULL) {
1643 if (!idefloppy_identify_device (drive, drive->id)) {
1644 printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
1645 continue;
1647 if (drive->scsi) {
1648 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
1649 continue;
1651 if ((floppy = (idefloppy_floppy_t *) kmalloc (sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) {
1652 printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name);
1653 continue;
1655 if (ide_register_subdriver (drive, &idefloppy_driver, IDE_SUBDRIVER_VERSION)) {
1656 printk (KERN_ERR "ide-floppy: %s: Failed to register the driver with ide.c\n", drive->name);
1657 kfree (floppy);
1658 continue;
1660 idefloppy_setup (drive, floppy);
1661 failed--;
1663 ide_register_module(&idefloppy_module);
1664 MOD_DEC_USE_COUNT;
1665 return 0;
1668 #ifdef MODULE
1669 int init_module (void)
1671 return idefloppy_init ();
1674 void cleanup_module (void)
1676 ide_drive_t *drive;
1677 int failed = 0;
1679 while ((drive = ide_scan_devices (ide_floppy, idefloppy_driver.name, &idefloppy_driver, failed)) != NULL) {
1680 if (idefloppy_cleanup (drive)) {
1681 printk ("%s: cleanup_module() called while still busy\n", drive->name);
1682 failed++;
1684 /* We must remove proc entries defined in this module.
1685 Otherwise we oops while accessing these entries */
1686 if (drive->proc)
1687 ide_remove_proc_entries(drive->proc, idefloppy_proc);
1689 ide_unregister_module(&idefloppy_module);
1691 #endif /* MODULE */