2 * IDE ATAPI floppy driver.
4 * Copyright (C) 1996-1999 Gadi Oxman <gadio@netvision.net.il>
5 * Copyright (C) 2000-2002 Paul Bristow <paul@paulbristow.net>
6 * Copyright (C) 2005 Bartlomiej Zolnierkiewicz
10 * The driver currently doesn't have any fancy features, just the bare
11 * minimum read/write support.
13 * This driver supports the following IDE floppy drives:
15 * LS-120/240 SuperDisk
17 * Iomega PC Card Clik!/PocketZip
19 * For a historical changelog see
20 * Documentation/ide/ChangeLog.ide-floppy.1996-2002
23 #define IDEFLOPPY_VERSION "0.99.newide"
25 #include <linux/module.h>
26 #include <linux/types.h>
27 #include <linux/string.h>
28 #include <linux/kernel.h>
29 #include <linux/delay.h>
30 #include <linux/timer.h>
32 #include <linux/interrupt.h>
33 #include <linux/major.h>
34 #include <linux/errno.h>
35 #include <linux/genhd.h>
36 #include <linux/slab.h>
37 #include <linux/cdrom.h>
38 #include <linux/ide.h>
39 #include <linux/bitops.h>
40 #include <linux/mutex.h>
42 #include <scsi/scsi_ioctl.h>
44 #include <asm/byteorder.h>
46 #include <asm/uaccess.h>
48 #include <asm/unaligned.h>
51 * The following are used to debug the driver.
53 #define IDEFLOPPY_DEBUG_LOG 0
54 #define IDEFLOPPY_DEBUG_INFO 0
55 #define IDEFLOPPY_DEBUG_BUGS 1
57 /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
58 #define IDEFLOPPY_DEBUG( fmt, args... )
60 #if IDEFLOPPY_DEBUG_LOG
61 #define debug_log printk
63 #define debug_log(fmt, args... ) do {} while(0)
68 * Some drives require a longer irq timeout.
70 #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
73 * After each failed packet command we issue a request sense command
74 * and retry the packet command IDEFLOPPY_MAX_PC_RETRIES times.
76 #define IDEFLOPPY_MAX_PC_RETRIES 3
79 * With each packet command, we allocate a buffer of
80 * IDEFLOPPY_PC_BUFFER_SIZE bytes.
82 #define IDEFLOPPY_PC_BUFFER_SIZE 256
85 * In various places in the driver, we need to allocate storage
86 * for packet commands and requests, which will remain valid while
87 * we leave the driver to wait for an interrupt or a timeout event.
89 #define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
92 * Our view of a packet command.
94 typedef struct idefloppy_packet_command_s
{
95 u8 c
[12]; /* Actual packet bytes */
96 int retries
; /* On each retry, we increment retries */
97 int error
; /* Error code */
98 int request_transfer
; /* Bytes to transfer */
99 int actually_transferred
; /* Bytes actually transferred */
100 int buffer_size
; /* Size of our data buffer */
101 int b_count
; /* Missing/Available data on the current buffer */
102 struct request
*rq
; /* The corresponding request */
103 u8
*buffer
; /* Data buffer */
104 u8
*current_position
; /* Pointer into the above buffer */
105 void (*callback
) (ide_drive_t
*); /* Called when this packet command is completed */
106 u8 pc_buffer
[IDEFLOPPY_PC_BUFFER_SIZE
]; /* Temporary buffer */
107 unsigned long flags
; /* Status/Action bit flags: long for set_bit */
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 */
119 #define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */
122 * Removable Block Access Capabilities Page
125 #if defined(__LITTLE_ENDIAN_BITFIELD)
126 unsigned page_code
:6; /* Page code - Should be 0x1b */
127 unsigned reserved1_6
:1; /* Reserved */
128 unsigned ps
:1; /* Should be 0 */
129 #elif defined(__BIG_ENDIAN_BITFIELD)
130 unsigned ps
:1; /* Should be 0 */
131 unsigned reserved1_6
:1; /* Reserved */
132 unsigned page_code
:6; /* Page code - Should be 0x1b */
134 #error "Bitfield endianness not defined! Check your byteorder.h"
136 u8 page_length
; /* Page Length - Should be 0xa */
137 #if defined(__LITTLE_ENDIAN_BITFIELD)
138 unsigned reserved2
:6;
139 unsigned srfp
:1; /* Supports reporting progress of format */
140 unsigned sflp
:1; /* System floppy type device */
141 unsigned tlun
:3; /* Total logical units supported by the device */
142 unsigned reserved3
:3;
143 unsigned sml
:1; /* Single / Multiple lun supported */
144 unsigned ncd
:1; /* Non cd optical device */
145 #elif defined(__BIG_ENDIAN_BITFIELD)
146 unsigned sflp
:1; /* System floppy type device */
147 unsigned srfp
:1; /* Supports reporting progress of format */
148 unsigned reserved2
:6;
149 unsigned ncd
:1; /* Non cd optical device */
150 unsigned sml
:1; /* Single / Multiple lun supported */
151 unsigned reserved3
:3;
152 unsigned tlun
:3; /* Total logical units supported by the device */
154 #error "Bitfield endianness not defined! Check your byteorder.h"
157 } idefloppy_capabilities_page_t
;
160 * Flexible disk page.
163 #if defined(__LITTLE_ENDIAN_BITFIELD)
164 unsigned page_code
:6; /* Page code - Should be 0x5 */
165 unsigned reserved1_6
:1; /* Reserved */
166 unsigned ps
:1; /* The device is capable of saving the page */
167 #elif defined(__BIG_ENDIAN_BITFIELD)
168 unsigned ps
:1; /* The device is capable of saving the page */
169 unsigned reserved1_6
:1; /* Reserved */
170 unsigned page_code
:6; /* Page code - Should be 0x5 */
172 #error "Bitfield endianness not defined! Check your byteorder.h"
174 u8 page_length
; /* Page Length - Should be 0x1e */
175 u16 transfer_rate
; /* In kilobits per second */
176 u8 heads
, sectors
; /* Number of heads, Number of sectors per track */
177 u16 sector_size
; /* Byes per sector */
178 u16 cyls
; /* Number of cylinders */
180 u8 motor_delay
; /* Motor off delay */
182 u16 rpm
; /* Rotations per minute */
184 } idefloppy_flexible_disk_page_t
;
191 u8 length
; /* Length of the following descriptors in bytes */
192 } idefloppy_capacity_header_t
;
195 u32 blocks
; /* Number of blocks */
196 #if defined(__LITTLE_ENDIAN_BITFIELD)
197 unsigned dc
:2; /* Descriptor Code */
198 unsigned reserved
:6;
199 #elif defined(__BIG_ENDIAN_BITFIELD)
200 unsigned reserved
:6;
201 unsigned dc
:2; /* Descriptor Code */
203 #error "Bitfield endianness not defined! Check your byteorder.h"
205 u8 length_msb
; /* Block Length (MSB)*/
206 u16 length
; /* Block Length */
207 } idefloppy_capacity_descriptor_t
;
209 #define CAPACITY_INVALID 0x00
210 #define CAPACITY_UNFORMATTED 0x01
211 #define CAPACITY_CURRENT 0x02
212 #define CAPACITY_NO_CARTRIDGE 0x03
215 * Most of our global data which we need to save even as we leave the
216 * driver due to an interrupt or a timer event is stored in a variable
217 * of type idefloppy_floppy_t, defined below.
219 typedef struct ide_floppy_obj
{
221 ide_driver_t
*driver
;
222 struct gendisk
*disk
;
224 unsigned int openers
; /* protected by BKL for now */
226 /* Current packet command */
228 /* Last failed packet command */
229 idefloppy_pc_t
*failed_pc
;
230 /* Packet command stack */
231 idefloppy_pc_t pc_stack
[IDEFLOPPY_PC_STACK
];
232 /* Next free packet command storage space */
234 struct request rq_stack
[IDEFLOPPY_PC_STACK
];
235 /* We implement a circular array */
239 * Last error information
241 u8 sense_key
, asc
, ascq
;
242 /* delay this long before sending packet command */
244 int progress_indication
;
250 int blocks
, block_size
, bs_factor
;
251 /* Last format capacity */
252 idefloppy_capacity_descriptor_t capacity
;
253 /* Copy of the flexible disk page */
254 idefloppy_flexible_disk_page_t flexible_disk_page
;
257 /* Supports format progress report */
259 /* Status/Action flags */
261 } idefloppy_floppy_t
;
263 #define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
266 * Floppy flag bits values.
268 #define IDEFLOPPY_DRQ_INTERRUPT 0 /* DRQ interrupt device */
269 #define IDEFLOPPY_MEDIA_CHANGED 1 /* Media may have changed */
270 #define IDEFLOPPY_USE_READ12 2 /* Use READ12/WRITE12 or READ10/WRITE10 */
271 #define IDEFLOPPY_FORMAT_IN_PROGRESS 3 /* Format in progress */
272 #define IDEFLOPPY_CLIK_DRIVE 4 /* Avoid commands not supported in Clik drive */
273 #define IDEFLOPPY_ZIP_DRIVE 5 /* Requires BH algorithm for packets */
276 * Defines for the mode sense command
278 #define MODE_SENSE_CURRENT 0x00
279 #define MODE_SENSE_CHANGEABLE 0x01
280 #define MODE_SENSE_DEFAULT 0x02
281 #define MODE_SENSE_SAVED 0x03
284 * IOCTLs used in low-level formatting.
287 #define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
288 #define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
289 #define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
290 #define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
293 * Error codes which are returned in rq->errors to the higher part
296 #define IDEFLOPPY_ERROR_GENERAL 101
299 * The following is used to format the general configuration word of
300 * the ATAPI IDENTIFY DEVICE command.
302 struct idefloppy_id_gcw
{
303 #if defined(__LITTLE_ENDIAN_BITFIELD)
304 unsigned packet_size
:2; /* Packet Size */
305 unsigned reserved234
:3; /* Reserved */
306 unsigned drq_type
:2; /* Command packet DRQ type */
307 unsigned removable
:1; /* Removable media */
308 unsigned device_type
:5; /* Device type */
309 unsigned reserved13
:1; /* Reserved */
310 unsigned protocol
:2; /* Protocol type */
311 #elif defined(__BIG_ENDIAN_BITFIELD)
312 unsigned protocol
:2; /* Protocol type */
313 unsigned reserved13
:1; /* Reserved */
314 unsigned device_type
:5; /* Device type */
315 unsigned removable
:1; /* Removable media */
316 unsigned drq_type
:2; /* Command packet DRQ type */
317 unsigned reserved234
:3; /* Reserved */
318 unsigned packet_size
:2; /* Packet Size */
320 #error "Bitfield endianness not defined! Check your byteorder.h"
325 * INQUIRY packet command - Data Format
328 #if defined(__LITTLE_ENDIAN_BITFIELD)
329 unsigned device_type
:5; /* Peripheral Device Type */
330 unsigned reserved0_765
:3; /* Peripheral Qualifier - Reserved */
331 unsigned reserved1_6t0
:7; /* Reserved */
332 unsigned rmb
:1; /* Removable Medium Bit */
333 unsigned ansi_version
:3; /* ANSI Version */
334 unsigned ecma_version
:3; /* ECMA Version */
335 unsigned iso_version
:2; /* ISO Version */
336 unsigned response_format
:4; /* Response Data Format */
337 unsigned reserved3_45
:2; /* Reserved */
338 unsigned reserved3_6
:1; /* TrmIOP - Reserved */
339 unsigned reserved3_7
:1; /* AENC - Reserved */
340 #elif defined(__BIG_ENDIAN_BITFIELD)
341 unsigned reserved0_765
:3; /* Peripheral Qualifier - Reserved */
342 unsigned device_type
:5; /* Peripheral Device Type */
343 unsigned rmb
:1; /* Removable Medium Bit */
344 unsigned reserved1_6t0
:7; /* Reserved */
345 unsigned iso_version
:2; /* ISO Version */
346 unsigned ecma_version
:3; /* ECMA Version */
347 unsigned ansi_version
:3; /* ANSI Version */
348 unsigned reserved3_7
:1; /* AENC - Reserved */
349 unsigned reserved3_6
:1; /* TrmIOP - Reserved */
350 unsigned reserved3_45
:2; /* Reserved */
351 unsigned response_format
:4; /* Response Data Format */
353 #error "Bitfield endianness not defined! Check your byteorder.h"
355 u8 additional_length
; /* Additional Length (total_length-4) */
356 u8 rsv5
, rsv6
, rsv7
; /* Reserved */
357 u8 vendor_id
[8]; /* Vendor Identification */
358 u8 product_id
[16]; /* Product Identification */
359 u8 revision_level
[4]; /* Revision Level */
360 u8 vendor_specific
[20]; /* Vendor Specific - Optional */
361 u8 reserved56t95
[40]; /* Reserved - Optional */
362 /* Additional information may be returned */
363 } idefloppy_inquiry_result_t
;
366 * REQUEST SENSE packet command result - Data Format.
369 #if defined(__LITTLE_ENDIAN_BITFIELD)
370 unsigned error_code
:7; /* Current error (0x70) */
371 unsigned valid
:1; /* The information field conforms to SFF-8070i */
372 u8 reserved1
:8; /* Reserved */
373 unsigned sense_key
:4; /* Sense Key */
374 unsigned reserved2_4
:1; /* Reserved */
375 unsigned ili
:1; /* Incorrect Length Indicator */
376 unsigned reserved2_67
:2;
377 #elif defined(__BIG_ENDIAN_BITFIELD)
378 unsigned valid
:1; /* The information field conforms to SFF-8070i */
379 unsigned error_code
:7; /* Current error (0x70) */
380 u8 reserved1
:8; /* Reserved */
381 unsigned reserved2_67
:2;
382 unsigned ili
:1; /* Incorrect Length Indicator */
383 unsigned reserved2_4
:1; /* Reserved */
384 unsigned sense_key
:4; /* Sense Key */
386 #error "Bitfield endianness not defined! Check your byteorder.h"
388 u32 information
__attribute__ ((packed
));
389 u8 asl
; /* Additional sense length (n-7) */
390 u32 command_specific
; /* Additional command specific information */
391 u8 asc
; /* Additional Sense Code */
392 u8 ascq
; /* Additional Sense Code Qualifier */
393 u8 replaceable_unit_code
; /* Field Replaceable Unit Code */
395 u8 pad
[2]; /* Padding to 20 bytes */
396 } idefloppy_request_sense_result_t
;
399 * Pages of the SELECT SENSE / MODE SENSE packet commands.
401 #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
402 #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
405 * Mode Parameter Header for the MODE SENSE packet command
408 u16 mode_data_length
; /* Length of the following data transfer */
409 u8 medium_type
; /* Medium Type */
410 #if defined(__LITTLE_ENDIAN_BITFIELD)
411 unsigned reserved3
:7;
412 unsigned wp
:1; /* Write protect */
413 #elif defined(__BIG_ENDIAN_BITFIELD)
414 unsigned wp
:1; /* Write protect */
415 unsigned reserved3
:7;
417 #error "Bitfield endianness not defined! Check your byteorder.h"
420 } idefloppy_mode_parameter_header_t
;
422 static DEFINE_MUTEX(idefloppy_ref_mutex
);
424 #define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
426 #define ide_floppy_g(disk) \
427 container_of((disk)->private_data, struct ide_floppy_obj, driver)
429 static struct ide_floppy_obj
*ide_floppy_get(struct gendisk
*disk
)
431 struct ide_floppy_obj
*floppy
= NULL
;
433 mutex_lock(&idefloppy_ref_mutex
);
434 floppy
= ide_floppy_g(disk
);
436 kref_get(&floppy
->kref
);
437 mutex_unlock(&idefloppy_ref_mutex
);
441 static void ide_floppy_release(struct kref
*);
443 static void ide_floppy_put(struct ide_floppy_obj
*floppy
)
445 mutex_lock(&idefloppy_ref_mutex
);
446 kref_put(&floppy
->kref
, ide_floppy_release
);
447 mutex_unlock(&idefloppy_ref_mutex
);
451 * Too bad. The drive wants to send us data which we are not ready to accept.
452 * Just throw it away.
454 static void idefloppy_discard_data (ide_drive_t
*drive
, unsigned int bcount
)
457 (void) HWIF(drive
)->INB(IDE_DATA_REG
);
460 #if IDEFLOPPY_DEBUG_BUGS
461 static void idefloppy_write_zeros (ide_drive_t
*drive
, unsigned int bcount
)
464 HWIF(drive
)->OUTB(0, IDE_DATA_REG
);
466 #endif /* IDEFLOPPY_DEBUG_BUGS */
470 * idefloppy_do_end_request is used to finish servicing a request.
472 * For read/write requests, we will call ide_end_request to pass to the
475 static int idefloppy_do_end_request(ide_drive_t
*drive
, int uptodate
, int nsecs
)
477 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
478 struct request
*rq
= HWGROUP(drive
)->rq
;
481 debug_log(KERN_INFO
"Reached idefloppy_end_request\n");
484 case 0: error
= IDEFLOPPY_ERROR_GENERAL
; break;
485 case 1: error
= 0; break;
486 default: error
= uptodate
;
489 floppy
->failed_pc
= NULL
;
490 /* Why does this happen? */
493 if (!blk_special_request(rq
)) {
494 /* our real local end request function */
495 ide_end_request(drive
, uptodate
, nsecs
);
499 /* fixme: need to move this local also */
500 ide_end_drive_cmd(drive
, 0, 0);
504 static void idefloppy_input_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
, unsigned int bcount
)
506 struct request
*rq
= pc
->rq
;
507 struct bio_vec
*bvec
;
508 struct req_iterator iter
;
513 rq_for_each_segment(bvec
, rq
, iter
) {
517 count
= min(bvec
->bv_len
, bcount
);
519 data
= bvec_kmap_irq(bvec
, &flags
);
520 drive
->hwif
->atapi_input_bytes(drive
, data
, count
);
521 bvec_kunmap_irq(data
, &flags
);
524 pc
->b_count
+= count
;
528 idefloppy_do_end_request(drive
, 1, done
>> 9);
531 printk(KERN_ERR
"%s: leftover data in idefloppy_input_buffers, bcount == %d\n", drive
->name
, bcount
);
532 idefloppy_discard_data(drive
, bcount
);
536 static void idefloppy_output_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
, unsigned int bcount
)
538 struct request
*rq
= pc
->rq
;
539 struct req_iterator iter
;
540 struct bio_vec
*bvec
;
545 rq_for_each_segment(bvec
, rq
, iter
) {
549 count
= min(bvec
->bv_len
, bcount
);
551 data
= bvec_kmap_irq(bvec
, &flags
);
552 drive
->hwif
->atapi_output_bytes(drive
, data
, count
);
553 bvec_kunmap_irq(data
, &flags
);
556 pc
->b_count
+= count
;
560 idefloppy_do_end_request(drive
, 1, done
>> 9);
562 #if IDEFLOPPY_DEBUG_BUGS
564 printk(KERN_ERR
"%s: leftover data in idefloppy_output_buffers, bcount == %d\n", drive
->name
, bcount
);
565 idefloppy_write_zeros(drive
, bcount
);
570 static void idefloppy_update_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
)
572 struct request
*rq
= pc
->rq
;
573 struct bio
*bio
= rq
->bio
;
575 while ((bio
= rq
->bio
) != NULL
)
576 idefloppy_do_end_request(drive
, 1, 0);
580 * idefloppy_queue_pc_head generates a new packet command request in front
581 * of the request queue, before the current request, so that it will be
582 * processed immediately, on the next pass through the driver.
584 static void idefloppy_queue_pc_head (ide_drive_t
*drive
,idefloppy_pc_t
*pc
,struct request
*rq
)
586 struct ide_floppy_obj
*floppy
= drive
->driver_data
;
588 ide_init_drive_cmd(rq
);
589 rq
->buffer
= (char *) pc
;
590 rq
->cmd_type
= REQ_TYPE_SPECIAL
;
591 rq
->rq_disk
= floppy
->disk
;
592 (void) ide_do_drive_cmd(drive
, rq
, ide_preempt
);
595 static idefloppy_pc_t
*idefloppy_next_pc_storage (ide_drive_t
*drive
)
597 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
599 if (floppy
->pc_stack_index
== IDEFLOPPY_PC_STACK
)
600 floppy
->pc_stack_index
=0;
601 return (&floppy
->pc_stack
[floppy
->pc_stack_index
++]);
604 static struct request
*idefloppy_next_rq_storage (ide_drive_t
*drive
)
606 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
608 if (floppy
->rq_stack_index
== IDEFLOPPY_PC_STACK
)
609 floppy
->rq_stack_index
= 0;
610 return (&floppy
->rq_stack
[floppy
->rq_stack_index
++]);
614 * idefloppy_analyze_error is called on each failed packet command retry
615 * to analyze the request sense.
617 static void idefloppy_analyze_error (ide_drive_t
*drive
,idefloppy_request_sense_result_t
*result
)
619 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
621 floppy
->sense_key
= result
->sense_key
;
622 floppy
->asc
= result
->asc
;
623 floppy
->ascq
= result
->ascq
;
624 floppy
->progress_indication
= result
->sksv
[0] & 0x80 ?
625 (u16
)get_unaligned((u16
*)(result
->sksv
+1)):0x10000;
626 if (floppy
->failed_pc
)
627 debug_log(KERN_INFO
"ide-floppy: pc = %x, sense key = %x, "
628 "asc = %x, ascq = %x\n", floppy
->failed_pc
->c
[0],
629 result
->sense_key
, result
->asc
, result
->ascq
);
631 debug_log(KERN_INFO
"ide-floppy: sense key = %x, asc = %x, "
632 "ascq = %x\n", result
->sense_key
,
633 result
->asc
, result
->ascq
);
636 static void idefloppy_request_sense_callback (ide_drive_t
*drive
)
638 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
640 debug_log(KERN_INFO
"ide-floppy: Reached %s\n", __FUNCTION__
);
642 if (!floppy
->pc
->error
) {
643 idefloppy_analyze_error(drive
,(idefloppy_request_sense_result_t
*) floppy
->pc
->buffer
);
644 idefloppy_do_end_request(drive
, 1, 0);
646 printk(KERN_ERR
"Error in REQUEST SENSE itself - Aborting request!\n");
647 idefloppy_do_end_request(drive
, 0, 0);
652 * General packet command callback function.
654 static void idefloppy_pc_callback (ide_drive_t
*drive
)
656 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
658 debug_log(KERN_INFO
"ide-floppy: Reached %s\n", __FUNCTION__
);
660 idefloppy_do_end_request(drive
, floppy
->pc
->error
? 0 : 1, 0);
664 * idefloppy_init_pc initializes a packet command.
666 static void idefloppy_init_pc (idefloppy_pc_t
*pc
)
668 memset(pc
->c
, 0, 12);
671 pc
->request_transfer
= 0;
672 pc
->buffer
= pc
->pc_buffer
;
673 pc
->buffer_size
= IDEFLOPPY_PC_BUFFER_SIZE
;
674 pc
->callback
= &idefloppy_pc_callback
;
677 static void idefloppy_create_request_sense_cmd (idefloppy_pc_t
*pc
)
679 idefloppy_init_pc(pc
);
680 pc
->c
[0] = GPCMD_REQUEST_SENSE
;
682 pc
->request_transfer
= 18;
683 pc
->callback
= &idefloppy_request_sense_callback
;
687 * idefloppy_retry_pc is called when an error was detected during the
688 * last packet command. We queue a request sense packet command in
689 * the head of the request list.
691 static void idefloppy_retry_pc (ide_drive_t
*drive
)
696 (void)drive
->hwif
->INB(IDE_ERROR_REG
);
697 pc
= idefloppy_next_pc_storage(drive
);
698 rq
= idefloppy_next_rq_storage(drive
);
699 idefloppy_create_request_sense_cmd(pc
);
700 idefloppy_queue_pc_head(drive
, pc
, rq
);
704 * idefloppy_pc_intr is the usual interrupt handler which will be called
705 * during a packet command.
707 static ide_startstop_t
idefloppy_pc_intr (ide_drive_t
*drive
)
709 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
710 ide_hwif_t
*hwif
= drive
->hwif
;
711 idefloppy_pc_t
*pc
= floppy
->pc
;
712 struct request
*rq
= pc
->rq
;
717 debug_log(KERN_INFO
"ide-floppy: Reached %s interrupt handler\n",
720 if (test_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
)) {
721 if (HWIF(drive
)->ide_dma_end(drive
)) {
722 set_bit(PC_DMA_ERROR
, &pc
->flags
);
724 pc
->actually_transferred
= pc
->request_transfer
;
725 idefloppy_update_buffers(drive
, pc
);
727 debug_log(KERN_INFO
"ide-floppy: DMA finished\n");
730 /* Clear the interrupt */
731 stat
= drive
->hwif
->INB(IDE_STATUS_REG
);
733 if ((stat
& DRQ_STAT
) == 0) { /* No more interrupts */
734 debug_log(KERN_INFO
"Packet command completed, %d bytes "
735 "transferred\n", pc
->actually_transferred
);
736 clear_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
);
738 local_irq_enable_in_hardirq();
740 if ((stat
& ERR_STAT
) || test_bit(PC_DMA_ERROR
, &pc
->flags
)) {
742 debug_log(KERN_INFO
"ide-floppy: %s: I/O error\n",
745 if (pc
->c
[0] == GPCMD_REQUEST_SENSE
) {
746 printk(KERN_ERR
"ide-floppy: I/O error in "
747 "request sense command\n");
748 return ide_do_reset(drive
);
750 /* Retry operation */
751 idefloppy_retry_pc(drive
);
752 /* queued, but not started */
756 if (floppy
->failed_pc
== pc
)
757 floppy
->failed_pc
= NULL
;
758 /* Command finished - Call the callback function */
763 if (test_and_clear_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
)) {
764 printk(KERN_ERR
"ide-floppy: The floppy wants to issue "
765 "more interrupts in DMA mode\n");
767 return ide_do_reset(drive
);
770 /* Get the number of bytes to transfer */
771 bcount
= (hwif
->INB(IDE_BCOUNTH_REG
) << 8) |
772 hwif
->INB(IDE_BCOUNTL_REG
);
773 /* on this interrupt */
774 ireason
= hwif
->INB(IDE_IREASON_REG
);
777 printk(KERN_ERR
"ide-floppy: CoD != 0 in idefloppy_pc_intr\n");
778 return ide_do_reset(drive
);
780 if (((ireason
& IO
) == IO
) == test_bit(PC_WRITING
, &pc
->flags
)) {
781 /* Hopefully, we will never get here */
782 printk(KERN_ERR
"ide-floppy: We wanted to %s, ",
783 (ireason
& IO
) ? "Write" : "Read");
784 printk(KERN_ERR
"but the floppy wants us to %s !\n",
785 (ireason
& IO
) ? "Read" : "Write");
786 return ide_do_reset(drive
);
788 if (!test_bit(PC_WRITING
, &pc
->flags
)) {
789 /* Reading - Check that we have enough space */
790 temp
= pc
->actually_transferred
+ bcount
;
791 if (temp
> pc
->request_transfer
) {
792 if (temp
> pc
->buffer_size
) {
793 printk(KERN_ERR
"ide-floppy: The floppy wants "
794 "to send us more data than expected "
795 "- discarding data\n");
796 idefloppy_discard_data(drive
, bcount
);
797 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
798 ide_set_handler(drive
,
804 debug_log(KERN_NOTICE
"ide-floppy: The floppy wants to "
805 "send us more data than expected - "
806 "allowing transfer\n");
809 if (test_bit(PC_WRITING
, &pc
->flags
)) {
810 if (pc
->buffer
!= NULL
)
811 /* Write the current buffer */
812 hwif
->atapi_output_bytes(drive
, pc
->current_position
,
815 idefloppy_output_buffers(drive
, pc
, bcount
);
817 if (pc
->buffer
!= NULL
)
818 /* Read the current buffer */
819 hwif
->atapi_input_bytes(drive
, pc
->current_position
,
822 idefloppy_input_buffers(drive
, pc
, bcount
);
824 /* Update the current position */
825 pc
->actually_transferred
+= bcount
;
826 pc
->current_position
+= bcount
;
828 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
829 ide_set_handler(drive
, &idefloppy_pc_intr
, IDEFLOPPY_WAIT_CMD
, NULL
); /* And set the interrupt handler again */
834 * This is the original routine that did the packet transfer.
835 * It fails at high speeds on the Iomega ZIP drive, so there's a slower version
836 * for that drive below. The algorithm is chosen based on drive type
838 static ide_startstop_t
idefloppy_transfer_pc (ide_drive_t
*drive
)
840 ide_startstop_t startstop
;
841 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
844 if (ide_wait_stat(&startstop
, drive
, DRQ_STAT
, BUSY_STAT
, WAIT_READY
)) {
845 printk(KERN_ERR
"ide-floppy: Strange, packet command "
846 "initiated yet DRQ isn't asserted\n");
849 ireason
= drive
->hwif
->INB(IDE_IREASON_REG
);
850 if ((ireason
& CD
) == 0 || (ireason
& IO
)) {
851 printk(KERN_ERR
"ide-floppy: (IO,CoD) != (0,1) while "
852 "issuing a packet command\n");
853 return ide_do_reset(drive
);
855 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
856 /* Set the interrupt routine */
857 ide_set_handler(drive
, &idefloppy_pc_intr
, IDEFLOPPY_WAIT_CMD
, NULL
);
858 /* Send the actual packet */
859 HWIF(drive
)->atapi_output_bytes(drive
, floppy
->pc
->c
, 12);
865 * What we have here is a classic case of a top half / bottom half
866 * interrupt service routine. In interrupt mode, the device sends
867 * an interrupt to signal it's ready to receive a packet. However,
868 * we need to delay about 2-3 ticks before issuing the packet or we
871 * So, follow carefully. transfer_pc1 is called as an interrupt (or
872 * directly). In either case, when the device says it's ready for a
873 * packet, we schedule the packet transfer to occur about 2-3 ticks
874 * later in transfer_pc2.
876 static int idefloppy_transfer_pc2 (ide_drive_t
*drive
)
878 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
880 /* Send the actual packet */
881 HWIF(drive
)->atapi_output_bytes(drive
, floppy
->pc
->c
, 12);
882 /* Timeout for the packet command */
883 return IDEFLOPPY_WAIT_CMD
;
886 static ide_startstop_t
idefloppy_transfer_pc1 (ide_drive_t
*drive
)
888 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
889 ide_startstop_t startstop
;
892 if (ide_wait_stat(&startstop
, drive
, DRQ_STAT
, BUSY_STAT
, WAIT_READY
)) {
893 printk(KERN_ERR
"ide-floppy: Strange, packet command "
894 "initiated yet DRQ isn't asserted\n");
897 ireason
= drive
->hwif
->INB(IDE_IREASON_REG
);
898 if ((ireason
& CD
) == 0 || (ireason
& IO
)) {
899 printk(KERN_ERR
"ide-floppy: (IO,CoD) != (0,1) "
900 "while issuing a packet command\n");
901 return ide_do_reset(drive
);
904 * The following delay solves a problem with ATAPI Zip 100 drives
905 * where the Busy flag was apparently being deasserted before the
906 * unit was ready to receive data. This was happening on a
907 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
908 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
909 * used until after the packet is moved in about 50 msec.
911 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
912 ide_set_handler(drive
,
913 &idefloppy_pc_intr
, /* service routine for packet command */
914 floppy
->ticks
, /* wait this long before "failing" */
915 &idefloppy_transfer_pc2
); /* fail == transfer_pc2 */
920 * idefloppy_should_report_error()
922 * Supresses error messages resulting from Medium not present
924 static inline int idefloppy_should_report_error(idefloppy_floppy_t
*floppy
)
926 if (floppy
->sense_key
== 0x02 &&
927 floppy
->asc
== 0x3a &&
928 floppy
->ascq
== 0x00)
934 * Issue a packet command
936 static ide_startstop_t
idefloppy_issue_pc (ide_drive_t
*drive
, idefloppy_pc_t
*pc
)
938 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
939 ide_hwif_t
*hwif
= drive
->hwif
;
940 ide_handler_t
*pkt_xfer_routine
;
944 if (floppy
->failed_pc
== NULL
&&
945 pc
->c
[0] != GPCMD_REQUEST_SENSE
)
946 floppy
->failed_pc
= pc
;
947 /* Set the current packet command */
950 if (pc
->retries
> IDEFLOPPY_MAX_PC_RETRIES
||
951 test_bit(PC_ABORT
, &pc
->flags
)) {
953 * We will "abort" retrying a packet command in case
954 * a legitimate error code was received.
956 if (!test_bit(PC_ABORT
, &pc
->flags
)) {
957 if (!test_bit(PC_SUPPRESS_ERROR
, &pc
->flags
)) {
958 if (idefloppy_should_report_error(floppy
))
959 printk(KERN_ERR
"ide-floppy: %s: I/O error, "
960 "pc = %2x, key = %2x, "
961 "asc = %2x, ascq = %2x\n",
962 drive
->name
, pc
->c
[0],
964 floppy
->asc
, floppy
->ascq
);
967 pc
->error
= IDEFLOPPY_ERROR_GENERAL
;
969 floppy
->failed_pc
= NULL
;
974 debug_log(KERN_INFO
"Retry number - %d\n",pc
->retries
);
977 /* We haven't transferred any data yet */
978 pc
->actually_transferred
= 0;
979 pc
->current_position
= pc
->buffer
;
980 bcount
= min(pc
->request_transfer
, 63 * 1024);
982 if (test_and_clear_bit(PC_DMA_ERROR
, &pc
->flags
))
987 if (test_bit(PC_DMA_RECOMMENDED
, &pc
->flags
) && drive
->using_dma
)
988 dma
= !hwif
->dma_setup(drive
);
990 ide_pktcmd_tf_load(drive
, IDE_TFLAG_NO_SELECT_MASK
|
991 IDE_TFLAG_OUT_DEVICE
, bcount
, dma
);
993 if (dma
) { /* Begin DMA, if necessary */
994 set_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
);
995 hwif
->dma_start(drive
);
998 /* Can we transfer the packet when we get the interrupt or wait? */
999 if (test_bit(IDEFLOPPY_ZIP_DRIVE
, &floppy
->flags
)) {
1001 pkt_xfer_routine
= &idefloppy_transfer_pc1
;
1004 pkt_xfer_routine
= &idefloppy_transfer_pc
;
1007 if (test_bit (IDEFLOPPY_DRQ_INTERRUPT
, &floppy
->flags
)) {
1008 /* Issue the packet command */
1009 ide_execute_command(drive
, WIN_PACKETCMD
,
1015 /* Issue the packet command */
1016 HWIF(drive
)->OUTB(WIN_PACKETCMD
, IDE_COMMAND_REG
);
1017 return (*pkt_xfer_routine
) (drive
);
1021 static void idefloppy_rw_callback (ide_drive_t
*drive
)
1023 debug_log(KERN_INFO
"ide-floppy: Reached idefloppy_rw_callback\n");
1025 idefloppy_do_end_request(drive
, 1, 0);
1029 static void idefloppy_create_prevent_cmd (idefloppy_pc_t
*pc
, int prevent
)
1031 debug_log(KERN_INFO
"ide-floppy: creating prevent removal command, "
1032 "prevent = %d\n", prevent
);
1034 idefloppy_init_pc(pc
);
1035 pc
->c
[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL
;
1039 static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t
*pc
)
1041 idefloppy_init_pc(pc
);
1042 pc
->c
[0] = GPCMD_READ_FORMAT_CAPACITIES
;
1045 pc
->request_transfer
= 255;
1048 static void idefloppy_create_format_unit_cmd (idefloppy_pc_t
*pc
, int b
, int l
,
1051 idefloppy_init_pc(pc
);
1052 pc
->c
[0] = GPCMD_FORMAT_UNIT
;
1055 memset(pc
->buffer
, 0, 12);
1056 pc
->buffer
[1] = 0xA2;
1057 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
1059 if (flags
& 1) /* Verify bit on... */
1060 pc
->buffer
[1] ^= 0x20; /* ... turn off DCRT bit */
1063 put_unaligned(cpu_to_be32(b
), (unsigned int *)(&pc
->buffer
[4]));
1064 put_unaligned(cpu_to_be32(l
), (unsigned int *)(&pc
->buffer
[8]));
1066 set_bit(PC_WRITING
, &pc
->flags
);
1070 * A mode sense command is used to "sense" floppy parameters.
1072 static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t
*pc
, u8 page_code
, u8 type
)
1074 u16 length
= sizeof(idefloppy_mode_parameter_header_t
);
1076 idefloppy_init_pc(pc
);
1077 pc
->c
[0] = GPCMD_MODE_SENSE_10
;
1079 pc
->c
[2] = page_code
+ (type
<< 6);
1081 switch (page_code
) {
1082 case IDEFLOPPY_CAPABILITIES_PAGE
:
1085 case IDEFLOPPY_FLEXIBLE_DISK_PAGE
:
1089 printk(KERN_ERR
"ide-floppy: unsupported page code "
1090 "in create_mode_sense_cmd\n");
1092 put_unaligned(cpu_to_be16(length
), (u16
*) &pc
->c
[7]);
1093 pc
->request_transfer
= length
;
1096 static void idefloppy_create_start_stop_cmd (idefloppy_pc_t
*pc
, int start
)
1098 idefloppy_init_pc(pc
);
1099 pc
->c
[0] = GPCMD_START_STOP_UNIT
;
1103 static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t
*pc
)
1105 idefloppy_init_pc(pc
);
1106 pc
->c
[0] = GPCMD_TEST_UNIT_READY
;
1109 static void idefloppy_create_rw_cmd (idefloppy_floppy_t
*floppy
, idefloppy_pc_t
*pc
, struct request
*rq
, unsigned long sector
)
1111 int block
= sector
/ floppy
->bs_factor
;
1112 int blocks
= rq
->nr_sectors
/ floppy
->bs_factor
;
1113 int cmd
= rq_data_dir(rq
);
1115 debug_log("create_rw1%d_cmd: block == %d, blocks == %d\n",
1116 2 * test_bit (IDEFLOPPY_USE_READ12
, &floppy
->flags
),
1119 idefloppy_init_pc(pc
);
1120 if (test_bit(IDEFLOPPY_USE_READ12
, &floppy
->flags
)) {
1121 pc
->c
[0] = cmd
== READ
? GPCMD_READ_12
: GPCMD_WRITE_12
;
1122 put_unaligned(cpu_to_be32(blocks
), (unsigned int *) &pc
->c
[6]);
1124 pc
->c
[0] = cmd
== READ
? GPCMD_READ_10
: GPCMD_WRITE_10
;
1125 put_unaligned(cpu_to_be16(blocks
), (unsigned short *)&pc
->c
[7]);
1127 put_unaligned(cpu_to_be32(block
), (unsigned int *) &pc
->c
[2]);
1128 pc
->callback
= &idefloppy_rw_callback
;
1130 pc
->b_count
= cmd
== READ
? 0 : rq
->bio
->bi_size
;
1131 if (rq
->cmd_flags
& REQ_RW
)
1132 set_bit(PC_WRITING
, &pc
->flags
);
1134 pc
->request_transfer
= pc
->buffer_size
= blocks
* floppy
->block_size
;
1135 set_bit(PC_DMA_RECOMMENDED
, &pc
->flags
);
1139 idefloppy_blockpc_cmd(idefloppy_floppy_t
*floppy
, idefloppy_pc_t
*pc
, struct request
*rq
)
1141 idefloppy_init_pc(pc
);
1142 pc
->callback
= &idefloppy_rw_callback
;
1143 memcpy(pc
->c
, rq
->cmd
, sizeof(pc
->c
));
1145 pc
->b_count
= rq
->data_len
;
1146 if (rq
->data_len
&& rq_data_dir(rq
) == WRITE
)
1147 set_bit(PC_WRITING
, &pc
->flags
);
1148 pc
->buffer
= rq
->data
;
1150 set_bit(PC_DMA_RECOMMENDED
, &pc
->flags
);
1153 * possibly problematic, doesn't look like ide-floppy correctly
1154 * handled scattered requests if dma fails...
1156 pc
->request_transfer
= pc
->buffer_size
= rq
->data_len
;
1160 * idefloppy_do_request is our request handling function.
1162 static ide_startstop_t
idefloppy_do_request (ide_drive_t
*drive
, struct request
*rq
, sector_t block_s
)
1164 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1166 unsigned long block
= (unsigned long)block_s
;
1168 debug_log(KERN_INFO
"dev: %s, flags: %lx, errors: %d\n",
1169 rq
->rq_disk
? rq
->rq_disk
->disk_name
: "?",
1170 rq
->flags
, rq
->errors
);
1171 debug_log(KERN_INFO
"sector: %ld, nr_sectors: %ld, "
1172 "current_nr_sectors: %d\n", (long)rq
->sector
,
1173 rq
->nr_sectors
, rq
->current_nr_sectors
);
1175 if (rq
->errors
>= ERROR_MAX
) {
1176 if (floppy
->failed_pc
!= NULL
) {
1177 if (idefloppy_should_report_error(floppy
))
1178 printk(KERN_ERR
"ide-floppy: %s: I/O error, pc = %2x,"
1179 " key = %2x, asc = %2x, ascq = %2x\n",
1180 drive
->name
, floppy
->failed_pc
->c
[0],
1181 floppy
->sense_key
, floppy
->asc
, floppy
->ascq
);
1184 printk(KERN_ERR
"ide-floppy: %s: I/O error\n",
1186 idefloppy_do_end_request(drive
, 0, 0);
1189 if (blk_fs_request(rq
)) {
1190 if (((long)rq
->sector
% floppy
->bs_factor
) ||
1191 (rq
->nr_sectors
% floppy
->bs_factor
)) {
1192 printk("%s: unsupported r/w request size\n",
1194 idefloppy_do_end_request(drive
, 0, 0);
1197 pc
= idefloppy_next_pc_storage(drive
);
1198 idefloppy_create_rw_cmd(floppy
, pc
, rq
, block
);
1199 } else if (blk_special_request(rq
)) {
1200 pc
= (idefloppy_pc_t
*) rq
->buffer
;
1201 } else if (blk_pc_request(rq
)) {
1202 pc
= idefloppy_next_pc_storage(drive
);
1203 idefloppy_blockpc_cmd(floppy
, pc
, rq
);
1205 blk_dump_rq_flags(rq
,
1206 "ide-floppy: unsupported command in queue");
1207 idefloppy_do_end_request(drive
, 0, 0);
1212 return idefloppy_issue_pc(drive
, pc
);
1216 * idefloppy_queue_pc_tail adds a special packet command request to the
1217 * tail of the request queue, and waits for it to be serviced.
1219 static int idefloppy_queue_pc_tail (ide_drive_t
*drive
,idefloppy_pc_t
*pc
)
1221 struct ide_floppy_obj
*floppy
= drive
->driver_data
;
1224 ide_init_drive_cmd (&rq
);
1225 rq
.buffer
= (char *) pc
;
1226 rq
.cmd_type
= REQ_TYPE_SPECIAL
;
1227 rq
.rq_disk
= floppy
->disk
;
1229 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
1233 * Look at the flexible disk page parameters. We will ignore the CHS
1234 * capacity parameters and use the LBA parameters instead.
1236 static int idefloppy_get_flexible_disk_page (ide_drive_t
*drive
)
1238 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1240 idefloppy_mode_parameter_header_t
*header
;
1241 idefloppy_flexible_disk_page_t
*page
;
1242 int capacity
, lba_capacity
;
1244 idefloppy_create_mode_sense_cmd(&pc
, IDEFLOPPY_FLEXIBLE_DISK_PAGE
, MODE_SENSE_CURRENT
);
1245 if (idefloppy_queue_pc_tail(drive
,&pc
)) {
1246 printk(KERN_ERR
"ide-floppy: Can't get flexible disk "
1247 "page parameters\n");
1250 header
= (idefloppy_mode_parameter_header_t
*) pc
.buffer
;
1251 floppy
->wp
= header
->wp
;
1252 set_disk_ro(floppy
->disk
, floppy
->wp
);
1253 page
= (idefloppy_flexible_disk_page_t
*) (header
+ 1);
1255 page
->transfer_rate
= be16_to_cpu(page
->transfer_rate
);
1256 page
->sector_size
= be16_to_cpu(page
->sector_size
);
1257 page
->cyls
= be16_to_cpu(page
->cyls
);
1258 page
->rpm
= be16_to_cpu(page
->rpm
);
1259 capacity
= page
->cyls
* page
->heads
* page
->sectors
* page
->sector_size
;
1260 if (memcmp (page
, &floppy
->flexible_disk_page
, sizeof (idefloppy_flexible_disk_page_t
)))
1261 printk(KERN_INFO
"%s: %dkB, %d/%d/%d CHS, %d kBps, "
1262 "%d sector size, %d rpm\n",
1263 drive
->name
, capacity
/ 1024, page
->cyls
,
1264 page
->heads
, page
->sectors
,
1265 page
->transfer_rate
/ 8, page
->sector_size
, page
->rpm
);
1267 floppy
->flexible_disk_page
= *page
;
1268 drive
->bios_cyl
= page
->cyls
;
1269 drive
->bios_head
= page
->heads
;
1270 drive
->bios_sect
= page
->sectors
;
1271 lba_capacity
= floppy
->blocks
* floppy
->block_size
;
1272 if (capacity
< lba_capacity
) {
1273 printk(KERN_NOTICE
"%s: The disk reports a capacity of %d "
1274 "bytes, but the drive only handles %d\n",
1275 drive
->name
, lba_capacity
, capacity
);
1276 floppy
->blocks
= floppy
->block_size
? capacity
/ floppy
->block_size
: 0;
1281 static int idefloppy_get_capability_page(ide_drive_t
*drive
)
1283 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1285 idefloppy_mode_parameter_header_t
*header
;
1286 idefloppy_capabilities_page_t
*page
;
1289 idefloppy_create_mode_sense_cmd(&pc
, IDEFLOPPY_CAPABILITIES_PAGE
,
1290 MODE_SENSE_CURRENT
);
1292 set_bit(PC_SUPPRESS_ERROR
, &pc
.flags
);
1293 if (idefloppy_queue_pc_tail(drive
,&pc
)) {
1297 header
= (idefloppy_mode_parameter_header_t
*) pc
.buffer
;
1298 page
= (idefloppy_capabilities_page_t
*)(header
+1);
1299 floppy
->srfp
= page
->srfp
;
1304 * Determine if a media is present in the floppy drive, and if so,
1307 static int idefloppy_get_capacity (ide_drive_t
*drive
)
1309 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1311 idefloppy_capacity_header_t
*header
;
1312 idefloppy_capacity_descriptor_t
*descriptor
;
1313 int i
, descriptors
, rc
= 1, blocks
, length
;
1315 drive
->bios_cyl
= 0;
1316 drive
->bios_head
= drive
->bios_sect
= 0;
1318 floppy
->bs_factor
= 1;
1319 set_capacity(floppy
->disk
, 0);
1321 idefloppy_create_read_capacity_cmd(&pc
);
1322 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1323 printk(KERN_ERR
"ide-floppy: Can't get floppy parameters\n");
1326 header
= (idefloppy_capacity_header_t
*) pc
.buffer
;
1327 descriptors
= header
->length
/ sizeof(idefloppy_capacity_descriptor_t
);
1328 descriptor
= (idefloppy_capacity_descriptor_t
*) (header
+ 1);
1330 for (i
= 0; i
< descriptors
; i
++, descriptor
++) {
1331 blocks
= descriptor
->blocks
= be32_to_cpu(descriptor
->blocks
);
1332 length
= descriptor
->length
= be16_to_cpu(descriptor
->length
);
1336 switch (descriptor
->dc
) {
1337 /* Clik! drive returns this instead of CAPACITY_CURRENT */
1338 case CAPACITY_UNFORMATTED
:
1339 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
))
1341 * If it is not a clik drive, break out
1342 * (maintains previous driver behaviour)
1345 case CAPACITY_CURRENT
:
1346 /* Normal Zip/LS-120 disks */
1347 if (memcmp(descriptor
, &floppy
->capacity
, sizeof (idefloppy_capacity_descriptor_t
)))
1348 printk(KERN_INFO
"%s: %dkB, %d blocks, %d "
1349 "sector size\n", drive
->name
,
1350 blocks
* length
/ 1024, blocks
, length
);
1351 floppy
->capacity
= *descriptor
;
1352 if (!length
|| length
% 512) {
1353 printk(KERN_NOTICE
"%s: %d bytes block size "
1354 "not supported\n", drive
->name
, length
);
1356 floppy
->blocks
= blocks
;
1357 floppy
->block_size
= length
;
1358 if ((floppy
->bs_factor
= length
/ 512) != 1)
1359 printk(KERN_NOTICE
"%s: warning: non "
1360 "512 bytes block size not "
1361 "fully supported\n",
1366 case CAPACITY_NO_CARTRIDGE
:
1368 * This is a KERN_ERR so it appears on screen
1369 * for the user to see
1371 printk(KERN_ERR
"%s: No disk in drive\n", drive
->name
);
1373 case CAPACITY_INVALID
:
1374 printk(KERN_ERR
"%s: Invalid capacity for disk "
1375 "in drive\n", drive
->name
);
1380 debug_log( "Descriptor 0 Code: %d\n",
1383 debug_log( "Descriptor %d: %dkB, %d blocks, %d "
1384 "sector size\n", i
, blocks
* length
/ 1024, blocks
,
1388 /* Clik! disk does not support get_flexible_disk_page */
1389 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1390 (void) idefloppy_get_flexible_disk_page(drive
);
1393 set_capacity(floppy
->disk
, floppy
->blocks
* floppy
->bs_factor
);
1398 ** Obtain the list of formattable capacities.
1399 ** Very similar to idefloppy_get_capacity, except that we push the capacity
1400 ** descriptors to userland, instead of our own structures.
1402 ** Userland gives us the following structure:
1404 ** struct idefloppy_format_capacities {
1412 ** userland initializes nformats to the number of allocated formats[]
1413 ** records. On exit we set nformats to the number of records we've
1414 ** actually initialized.
1418 static int idefloppy_get_format_capacities(ide_drive_t
*drive
, int __user
*arg
)
1421 idefloppy_capacity_header_t
*header
;
1422 idefloppy_capacity_descriptor_t
*descriptor
;
1423 int i
, descriptors
, blocks
, length
;
1428 if (get_user(u_array_size
, arg
))
1431 if (u_array_size
<= 0)
1434 idefloppy_create_read_capacity_cmd(&pc
);
1435 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1436 printk(KERN_ERR
"ide-floppy: Can't get floppy parameters\n");
1439 header
= (idefloppy_capacity_header_t
*) pc
.buffer
;
1440 descriptors
= header
->length
/
1441 sizeof(idefloppy_capacity_descriptor_t
);
1442 descriptor
= (idefloppy_capacity_descriptor_t
*) (header
+ 1);
1448 ** We always skip the first capacity descriptor. That's the
1449 ** current capacity. We are interested in the remaining descriptors,
1450 ** the formattable capacities.
1453 for (i
=0; i
<descriptors
; i
++, descriptor
++) {
1454 if (u_index
>= u_array_size
)
1455 break; /* User-supplied buffer too small */
1457 continue; /* Skip the first descriptor */
1459 blocks
= be32_to_cpu(descriptor
->blocks
);
1460 length
= be16_to_cpu(descriptor
->length
);
1462 if (put_user(blocks
, argp
))
1466 if (put_user(length
, argp
))
1473 if (put_user(u_index
, arg
))
1479 ** Send ATAPI_FORMAT_UNIT to the drive.
1481 ** Userland gives us the following structure:
1483 ** struct idefloppy_format_command {
1489 ** flags is a bitmask, currently, the only defined flag is:
1491 ** 0x01 - verify media after format.
1494 static int idefloppy_begin_format(ide_drive_t
*drive
, int __user
*arg
)
1501 if (get_user(blocks
, arg
) ||
1502 get_user(length
, arg
+1) ||
1503 get_user(flags
, arg
+2)) {
1507 /* Get the SFRP bit */
1508 (void) idefloppy_get_capability_page(drive
);
1509 idefloppy_create_format_unit_cmd(&pc
, blocks
, length
, flags
);
1510 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1518 ** Get ATAPI_FORMAT_UNIT progress indication.
1520 ** Userland gives a pointer to an int. The int is set to a progress
1521 ** indicator 0-65536, with 65536=100%.
1523 ** If the drive does not support format progress indication, we just check
1524 ** the dsc bit, and return either 0 or 65536.
1527 static int idefloppy_get_format_progress(ide_drive_t
*drive
, int __user
*arg
)
1529 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1531 int progress_indication
= 0x10000;
1534 idefloppy_create_request_sense_cmd(&pc
);
1535 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1539 if (floppy
->sense_key
== 2 &&
1541 floppy
->ascq
== 4) {
1542 progress_indication
= floppy
->progress_indication
;
1544 /* Else assume format_unit has finished, and we're
1547 unsigned long flags
;
1550 local_irq_save(flags
);
1551 stat
= drive
->hwif
->INB(IDE_STATUS_REG
);
1552 local_irq_restore(flags
);
1554 progress_indication
= ((stat
& SEEK_STAT
) == 0) ? 0 : 0x10000;
1556 if (put_user(progress_indication
, arg
))
1563 * Return the current floppy capacity.
1565 static sector_t
idefloppy_capacity (ide_drive_t
*drive
)
1567 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1568 unsigned long capacity
= floppy
->blocks
* floppy
->bs_factor
;
1574 * idefloppy_identify_device checks if we can support a drive,
1575 * based on the ATAPI IDENTIFY command results.
1577 static int idefloppy_identify_device (ide_drive_t
*drive
,struct hd_driveid
*id
)
1579 struct idefloppy_id_gcw gcw
;
1580 #if IDEFLOPPY_DEBUG_INFO
1582 #endif /* IDEFLOPPY_DEBUG_INFO */
1584 *((u16
*) &gcw
) = id
->config
;
1587 /* kludge for Apple PowerBook internal zip */
1588 if ((gcw
.device_type
== 5) &&
1589 !strstr(id
->model
, "CD-ROM") &&
1590 strstr(id
->model
, "ZIP"))
1591 gcw
.device_type
= 0;
1594 #if IDEFLOPPY_DEBUG_INFO
1595 printk(KERN_INFO
"Dumping ATAPI Identify Device floppy parameters\n");
1596 switch (gcw
.protocol
) {
1597 case 0: case 1: sprintf(buffer
, "ATA");break;
1598 case 2: sprintf(buffer
, "ATAPI");break;
1599 case 3: sprintf(buffer
, "Reserved (Unknown to ide-floppy)");break;
1601 printk(KERN_INFO
"Protocol Type: %s\n", buffer
);
1602 switch (gcw
.device_type
) {
1603 case 0: sprintf(buffer
, "Direct-access Device");break;
1604 case 1: sprintf(buffer
, "Streaming Tape Device");break;
1605 case 2: case 3: case 4: sprintf (buffer
, "Reserved");break;
1606 case 5: sprintf(buffer
, "CD-ROM Device");break;
1607 case 6: sprintf(buffer
, "Reserved");
1608 case 7: sprintf(buffer
, "Optical memory Device");break;
1609 case 0x1f: sprintf(buffer
, "Unknown or no Device type");break;
1610 default: sprintf(buffer
, "Reserved");
1612 printk(KERN_INFO
"Device Type: %x - %s\n", gcw
.device_type
, buffer
);
1613 printk(KERN_INFO
"Removable: %s\n",gcw
.removable
? "Yes":"No");
1614 switch (gcw
.drq_type
) {
1615 case 0: sprintf(buffer
, "Microprocessor DRQ");break;
1616 case 1: sprintf(buffer
, "Interrupt DRQ");break;
1617 case 2: sprintf(buffer
, "Accelerated DRQ");break;
1618 case 3: sprintf(buffer
, "Reserved");break;
1620 printk(KERN_INFO
"Command Packet DRQ Type: %s\n", buffer
);
1621 switch (gcw
.packet_size
) {
1622 case 0: sprintf(buffer
, "12 bytes");break;
1623 case 1: sprintf(buffer
, "16 bytes");break;
1624 default: sprintf(buffer
, "Reserved");break;
1626 printk(KERN_INFO
"Command Packet Size: %s\n", buffer
);
1627 #endif /* IDEFLOPPY_DEBUG_INFO */
1629 if (gcw
.protocol
!= 2)
1630 printk(KERN_ERR
"ide-floppy: Protocol is not ATAPI\n");
1631 else if (gcw
.device_type
!= 0)
1632 printk(KERN_ERR
"ide-floppy: Device type is not set to floppy\n");
1633 else if (!gcw
.removable
)
1634 printk(KERN_ERR
"ide-floppy: The removable flag is not set\n");
1635 else if (gcw
.drq_type
== 3) {
1636 printk(KERN_ERR
"ide-floppy: Sorry, DRQ type %d not supported\n", gcw
.drq_type
);
1637 } else if (gcw
.packet_size
!= 0) {
1638 printk(KERN_ERR
"ide-floppy: Packet size is not 12 bytes long\n");
1644 #ifdef CONFIG_IDE_PROC_FS
1645 static void idefloppy_add_settings(ide_drive_t
*drive
)
1647 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1650 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
1652 ide_add_setting(drive
, "bios_cyl", SETTING_RW
, TYPE_INT
, 0, 1023, 1, 1, &drive
->bios_cyl
, NULL
);
1653 ide_add_setting(drive
, "bios_head", SETTING_RW
, TYPE_BYTE
, 0, 255, 1, 1, &drive
->bios_head
, NULL
);
1654 ide_add_setting(drive
, "bios_sect", SETTING_RW
, TYPE_BYTE
, 0, 63, 1, 1, &drive
->bios_sect
, NULL
);
1655 ide_add_setting(drive
, "ticks", SETTING_RW
, TYPE_BYTE
, 0, 255, 1, 1, &floppy
->ticks
, NULL
);
1658 static inline void idefloppy_add_settings(ide_drive_t
*drive
) { ; }
1662 * Driver initialization.
1664 static void idefloppy_setup (ide_drive_t
*drive
, idefloppy_floppy_t
*floppy
)
1666 struct idefloppy_id_gcw gcw
;
1668 *((u16
*) &gcw
) = drive
->id
->config
;
1669 floppy
->pc
= floppy
->pc_stack
;
1670 if (gcw
.drq_type
== 1)
1671 set_bit(IDEFLOPPY_DRQ_INTERRUPT
, &floppy
->flags
);
1673 * We used to check revisions here. At this point however
1674 * I'm giving up. Just assume they are all broken, its easier.
1676 * The actual reason for the workarounds was likely
1677 * a driver bug after all rather than a firmware bug,
1678 * and the workaround below used to hide it. It should
1679 * be fixed as of version 1.9, but to be on the safe side
1680 * we'll leave the limitation below for the 2.2.x tree.
1683 if (!strncmp(drive
->id
->model
, "IOMEGA ZIP 100 ATAPI", 20)) {
1684 set_bit(IDEFLOPPY_ZIP_DRIVE
, &floppy
->flags
);
1685 /* This value will be visible in the /proc/ide/hdx/settings */
1686 floppy
->ticks
= IDEFLOPPY_TICKS_DELAY
;
1687 blk_queue_max_sectors(drive
->queue
, 64);
1691 * Guess what? The IOMEGA Clik! drive also needs the
1692 * above fix. It makes nasty clicking noises without
1693 * it, so please don't remove this.
1695 if (strncmp(drive
->id
->model
, "IOMEGA Clik!", 11) == 0) {
1696 blk_queue_max_sectors(drive
->queue
, 64);
1697 set_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
);
1701 (void) idefloppy_get_capacity(drive
);
1702 idefloppy_add_settings(drive
);
1705 static void ide_floppy_remove(ide_drive_t
*drive
)
1707 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1708 struct gendisk
*g
= floppy
->disk
;
1710 ide_proc_unregister_driver(drive
, floppy
->driver
);
1714 ide_floppy_put(floppy
);
1717 static void ide_floppy_release(struct kref
*kref
)
1719 struct ide_floppy_obj
*floppy
= to_ide_floppy(kref
);
1720 ide_drive_t
*drive
= floppy
->drive
;
1721 struct gendisk
*g
= floppy
->disk
;
1723 drive
->driver_data
= NULL
;
1724 g
->private_data
= NULL
;
1729 #ifdef CONFIG_IDE_PROC_FS
1730 static int proc_idefloppy_read_capacity
1731 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
1733 ide_drive_t
*drive
= (ide_drive_t
*)data
;
1736 len
= sprintf(page
,"%llu\n", (long long)idefloppy_capacity(drive
));
1737 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
1740 static ide_proc_entry_t idefloppy_proc
[] = {
1741 { "capacity", S_IFREG
|S_IRUGO
, proc_idefloppy_read_capacity
, NULL
},
1742 { "geometry", S_IFREG
|S_IRUGO
, proc_ide_read_geometry
, NULL
},
1743 { NULL
, 0, NULL
, NULL
}
1745 #endif /* CONFIG_IDE_PROC_FS */
1747 static int ide_floppy_probe(ide_drive_t
*);
1749 static ide_driver_t idefloppy_driver
= {
1751 .owner
= THIS_MODULE
,
1752 .name
= "ide-floppy",
1753 .bus
= &ide_bus_type
,
1755 .probe
= ide_floppy_probe
,
1756 .remove
= ide_floppy_remove
,
1757 .version
= IDEFLOPPY_VERSION
,
1758 .media
= ide_floppy
,
1759 .supports_dsc_overlap
= 0,
1760 .do_request
= idefloppy_do_request
,
1761 .end_request
= idefloppy_do_end_request
,
1762 .error
= __ide_error
,
1763 .abort
= __ide_abort
,
1764 #ifdef CONFIG_IDE_PROC_FS
1765 .proc
= idefloppy_proc
,
1769 static int idefloppy_open(struct inode
*inode
, struct file
*filp
)
1771 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1772 struct ide_floppy_obj
*floppy
;
1777 debug_log(KERN_INFO
"Reached idefloppy_open\n");
1779 if (!(floppy
= ide_floppy_get(disk
)))
1782 drive
= floppy
->drive
;
1786 if (floppy
->openers
== 1) {
1787 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1790 idefloppy_create_test_unit_ready_cmd(&pc
);
1791 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1792 idefloppy_create_start_stop_cmd(&pc
, 1);
1793 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1796 if (idefloppy_get_capacity (drive
)
1797 && (filp
->f_flags
& O_NDELAY
) == 0
1799 ** Allow O_NDELAY to open a drive without a disk, or with
1800 ** an unreadable disk, so that we can get the format
1801 ** capacity of the drive or begin the format - Sam
1805 goto out_put_floppy
;
1808 if (floppy
->wp
&& (filp
->f_mode
& 2)) {
1810 goto out_put_floppy
;
1812 set_bit(IDEFLOPPY_MEDIA_CHANGED
, &floppy
->flags
);
1813 /* IOMEGA Clik! drives do not support lock/unlock commands */
1814 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1815 idefloppy_create_prevent_cmd(&pc
, 1);
1816 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1818 check_disk_change(inode
->i_bdev
);
1819 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
)) {
1821 goto out_put_floppy
;
1827 ide_floppy_put(floppy
);
1831 static int idefloppy_release(struct inode
*inode
, struct file
*filp
)
1833 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1834 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
1835 ide_drive_t
*drive
= floppy
->drive
;
1838 debug_log(KERN_INFO
"Reached idefloppy_release\n");
1840 if (floppy
->openers
== 1) {
1841 /* IOMEGA Clik! drives do not support lock/unlock commands */
1842 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1843 idefloppy_create_prevent_cmd(&pc
, 0);
1844 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1847 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1852 ide_floppy_put(floppy
);
1857 static int idefloppy_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
1859 struct ide_floppy_obj
*floppy
= ide_floppy_g(bdev
->bd_disk
);
1860 ide_drive_t
*drive
= floppy
->drive
;
1862 geo
->heads
= drive
->bios_head
;
1863 geo
->sectors
= drive
->bios_sect
;
1864 geo
->cylinders
= (u16
)drive
->bios_cyl
; /* truncate */
1868 static int idefloppy_ioctl(struct inode
*inode
, struct file
*file
,
1869 unsigned int cmd
, unsigned long arg
)
1871 struct block_device
*bdev
= inode
->i_bdev
;
1872 struct ide_floppy_obj
*floppy
= ide_floppy_g(bdev
->bd_disk
);
1873 ide_drive_t
*drive
= floppy
->drive
;
1874 void __user
*argp
= (void __user
*)arg
;
1876 int prevent
= (arg
) ? 1 : 0;
1883 case CDROM_LOCKDOOR
:
1884 if (floppy
->openers
> 1)
1887 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */
1888 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1889 idefloppy_create_prevent_cmd(&pc
, prevent
);
1890 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1892 if (cmd
== CDROMEJECT
) {
1893 idefloppy_create_start_stop_cmd(&pc
, 2);
1894 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1897 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED
:
1899 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY
:
1900 return idefloppy_get_format_capacities(drive
, argp
);
1901 case IDEFLOPPY_IOCTL_FORMAT_START
:
1903 if (!(file
->f_mode
& 2))
1906 if (floppy
->openers
> 1) {
1907 /* Don't format if someone is using the disk */
1909 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
,
1914 set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1916 err
= idefloppy_begin_format(drive
, argp
);
1918 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1921 ** Note, the bit will be cleared when the device is
1922 ** closed. This is the cleanest way to handle the
1923 ** situation where the drive does not support
1924 ** format progress reporting.
1926 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS
:
1927 return idefloppy_get_format_progress(drive
, argp
);
1931 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
1932 * and CDROM_SEND_PACKET (legacy) ioctls
1934 if (cmd
!= CDROM_SEND_PACKET
&& cmd
!= SCSI_IOCTL_SEND_COMMAND
)
1935 err
= scsi_cmd_ioctl(file
, bdev
->bd_disk
->queue
,
1936 bdev
->bd_disk
, cmd
, argp
);
1941 err
= generic_ide_ioctl(drive
, file
, bdev
, cmd
, arg
);
1946 static int idefloppy_media_changed(struct gendisk
*disk
)
1948 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
1949 ide_drive_t
*drive
= floppy
->drive
;
1951 /* do not scan partitions twice if this is a removable device */
1952 if (drive
->attach
) {
1956 return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED
, &floppy
->flags
);
1959 static int idefloppy_revalidate_disk(struct gendisk
*disk
)
1961 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
1962 set_capacity(disk
, idefloppy_capacity(floppy
->drive
));
1966 static struct block_device_operations idefloppy_ops
= {
1967 .owner
= THIS_MODULE
,
1968 .open
= idefloppy_open
,
1969 .release
= idefloppy_release
,
1970 .ioctl
= idefloppy_ioctl
,
1971 .getgeo
= idefloppy_getgeo
,
1972 .media_changed
= idefloppy_media_changed
,
1973 .revalidate_disk
= idefloppy_revalidate_disk
1976 static int ide_floppy_probe(ide_drive_t
*drive
)
1978 idefloppy_floppy_t
*floppy
;
1981 if (!strstr("ide-floppy", drive
->driver_req
))
1983 if (!drive
->present
)
1985 if (drive
->media
!= ide_floppy
)
1987 if (!idefloppy_identify_device (drive
, drive
->id
)) {
1988 printk (KERN_ERR
"ide-floppy: %s: not supported by this version of ide-floppy\n", drive
->name
);
1992 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive
->name
);
1995 if ((floppy
= kzalloc(sizeof (idefloppy_floppy_t
), GFP_KERNEL
)) == NULL
) {
1996 printk (KERN_ERR
"ide-floppy: %s: Can't allocate a floppy structure\n", drive
->name
);
2000 g
= alloc_disk(1 << PARTN_BITS
);
2002 goto out_free_floppy
;
2004 ide_init_disk(g
, drive
);
2006 ide_proc_register_driver(drive
, &idefloppy_driver
);
2008 kref_init(&floppy
->kref
);
2010 floppy
->drive
= drive
;
2011 floppy
->driver
= &idefloppy_driver
;
2014 g
->private_data
= &floppy
->driver
;
2016 drive
->driver_data
= floppy
;
2018 idefloppy_setup (drive
, floppy
);
2020 g
->minors
= 1 << PARTN_BITS
;
2021 g
->driverfs_dev
= &drive
->gendev
;
2022 g
->flags
= drive
->removable
? GENHD_FL_REMOVABLE
: 0;
2023 g
->fops
= &idefloppy_ops
;
2034 MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
2036 static void __exit
idefloppy_exit (void)
2038 driver_unregister(&idefloppy_driver
.gen_driver
);
2041 static int __init
idefloppy_init(void)
2043 printk("ide-floppy driver " IDEFLOPPY_VERSION
"\n");
2044 return driver_register(&idefloppy_driver
.gen_driver
);
2047 MODULE_ALIAS("ide:*m-floppy*");
2048 module_init(idefloppy_init
);
2049 module_exit(idefloppy_exit
);
2050 MODULE_LICENSE("GPL");