2 * Copyright (C) 1996 - 1999 Gadi Oxman <gadio@netvision.net.il>
3 * Copyright (C) 2000 - 2002 Paul Bristow <paul@paulbristow.net>
7 * IDE ATAPI floppy driver.
9 * The driver currently doesn't have any fancy features, just the bare
10 * minimum read/write support.
12 * This driver supports the following IDE floppy drives:
14 * LS-120/240 SuperDisk
16 * Iomega PC Card Clik!/PocketZip
18 * Many thanks to Lode Leroy <Lode.Leroy@www.ibase.be>, who tested so many
19 * ALPHA patches to this driver on an EASYSTOR LS-120 ATAPI floppy drive.
21 * Ver 0.1 Oct 17 96 Initial test version, mostly based on ide-tape.c.
22 * Ver 0.2 Oct 31 96 Minor changes.
23 * Ver 0.3 Dec 2 96 Fixed error recovery bug.
24 * Ver 0.4 Jan 26 97 Add support for the HDIO_GETGEO ioctl.
25 * Ver 0.5 Feb 21 97 Add partitions support.
26 * Use the minimum of the LBA and CHS capacities.
27 * Avoid hwgroup->rq == NULL on the last irq.
28 * Fix potential null dereferencing with DEBUG_LOG.
29 * Ver 0.8 Dec 7 97 Increase irq timeout from 10 to 50 seconds.
30 * Add media write-protect detection.
31 * Issue START command only if TEST UNIT READY fails.
32 * Add work-around for IOMEGA ZIP revision 21.D.
33 * Remove idefloppy_get_capabilities().
34 * Ver 0.9 Jul 4 99 Fix a bug which might have caused the number of
35 * bytes requested on each interrupt to be zero.
36 * Thanks to <shanos@es.co.nz> for pointing this out.
37 * Ver 0.9.sv Jan 6 01 Sam Varshavchik <mrsam@courier-mta.com>
38 * Implement low level formatting. Reimplemented
39 * IDEFLOPPY_CAPABILITIES_PAGE, since we need the srfp
40 * bit. My LS-120 drive barfs on
41 * IDEFLOPPY_CAPABILITIES_PAGE, but maybe it's just me.
42 * Compromise by not reporting a failure to get this
43 * mode page. Implemented four IOCTLs in order to
44 * implement formatting. IOCTls begin with 0x4600,
45 * 0x46 is 'F' as in Format.
46 * Jan 9 01 Userland option to select format verify.
47 * Added PC_SUPPRESS_ERROR flag - some idefloppy drives
48 * do not implement IDEFLOPPY_CAPABILITIES_PAGE, and
49 * return a sense error. Suppress error reporting in
50 * this particular case in order to avoid spurious
51 * errors in syslog. The culprit is
52 * idefloppy_get_capability_page(), so move it to
53 * idefloppy_begin_format() so that it's not used
54 * unless absolutely necessary.
55 * If drive does not support format progress indication
56 * monitor the dsc bit in the status register.
57 * Also, O_NDELAY on open will allow the device to be
58 * opened without a disk available. This can be used to
59 * open an unformatted disk, or get the device capacity.
60 * Ver 0.91 Dec 11 99 Added IOMEGA Clik! drive support by
61 * <paul@paulbristow.net>
62 * Ver 0.92 Oct 22 00 Paul Bristow became official maintainer for this
63 * driver. Included Powerbook internal zip kludge.
64 * Ver 0.93 Oct 24 00 Fixed bugs for Clik! drive
65 * no disk on insert and disk change now works
66 * Ver 0.94 Oct 27 00 Tidied up to remove strstr(Clik) everywhere
67 * Ver 0.95 Nov 7 00 Brought across to kernel 2.4
68 * Ver 0.96 Jan 7 01 Actually in line with release version of 2.4.0
69 * including set_bit patch from Rusty Russell
70 * Ver 0.97 Jul 22 01 Merge 0.91-0.96 onto 0.9.sv for ac series
71 * Ver 0.97.sv Aug 3 01 Backported from 2.4.7-ac3
72 * Ver 0.98 Oct 26 01 Split idefloppy_transfer_pc into two pieces to
73 * fix a lost interrupt problem. It appears the busy
74 * bit was being deasserted by my IOMEGA ATAPI ZIP 100
75 * drive before the drive was actually ready.
76 * Ver 0.98a Oct 29 01 Expose delay value so we can play.
77 * Ver 0.99 Feb 24 02 Remove duplicate code, modify clik! detection code
78 * to support new PocketZip drives
81 #define IDEFLOPPY_VERSION "0.99.newide"
83 #include <linux/module.h>
84 #include <linux/types.h>
85 #include <linux/string.h>
86 #include <linux/kernel.h>
87 #include <linux/delay.h>
88 #include <linux/timer.h>
90 #include <linux/interrupt.h>
91 #include <linux/major.h>
92 #include <linux/errno.h>
93 #include <linux/genhd.h>
94 #include <linux/slab.h>
95 #include <linux/cdrom.h>
96 #include <linux/ide.h>
97 #include <linux/bitops.h>
98 #include <linux/mutex.h>
100 #include <scsi/scsi_ioctl.h>
102 #include <asm/byteorder.h>
104 #include <asm/uaccess.h>
106 #include <asm/unaligned.h>
109 * The following are used to debug the driver.
111 #define IDEFLOPPY_DEBUG_LOG 0
112 #define IDEFLOPPY_DEBUG_INFO 0
113 #define IDEFLOPPY_DEBUG_BUGS 1
115 /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
116 #define IDEFLOPPY_DEBUG( fmt, args... )
118 #if IDEFLOPPY_DEBUG_LOG
119 #define debug_log printk
121 #define debug_log(fmt, args... ) do {} while(0)
126 * Some drives require a longer irq timeout.
128 #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
131 * After each failed packet command we issue a request sense command
132 * and retry the packet command IDEFLOPPY_MAX_PC_RETRIES times.
134 #define IDEFLOPPY_MAX_PC_RETRIES 3
137 * With each packet command, we allocate a buffer of
138 * IDEFLOPPY_PC_BUFFER_SIZE bytes.
140 #define IDEFLOPPY_PC_BUFFER_SIZE 256
143 * In various places in the driver, we need to allocate storage
144 * for packet commands and requests, which will remain valid while
145 * we leave the driver to wait for an interrupt or a timeout event.
147 #define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
150 * Our view of a packet command.
152 typedef struct idefloppy_packet_command_s
{
153 u8 c
[12]; /* Actual packet bytes */
154 int retries
; /* On each retry, we increment retries */
155 int error
; /* Error code */
156 int request_transfer
; /* Bytes to transfer */
157 int actually_transferred
; /* Bytes actually transferred */
158 int buffer_size
; /* Size of our data buffer */
159 int b_count
; /* Missing/Available data on the current buffer */
160 struct request
*rq
; /* The corresponding request */
161 u8
*buffer
; /* Data buffer */
162 u8
*current_position
; /* Pointer into the above buffer */
163 void (*callback
) (ide_drive_t
*); /* Called when this packet command is completed */
164 u8 pc_buffer
[IDEFLOPPY_PC_BUFFER_SIZE
]; /* Temporary buffer */
165 unsigned long flags
; /* Status/Action bit flags: long for set_bit */
169 * Packet command flag bits.
171 #define PC_ABORT 0 /* Set when an error is considered normal - We won't retry */
172 #define PC_DMA_RECOMMENDED 2 /* 1 when we prefer to use DMA if possible */
173 #define PC_DMA_IN_PROGRESS 3 /* 1 while DMA in progress */
174 #define PC_DMA_ERROR 4 /* 1 when encountered problem during DMA */
175 #define PC_WRITING 5 /* Data direction */
177 #define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */
180 * Removable Block Access Capabilities Page
183 #if defined(__LITTLE_ENDIAN_BITFIELD)
184 unsigned page_code
:6; /* Page code - Should be 0x1b */
185 unsigned reserved1_6
:1; /* Reserved */
186 unsigned ps
:1; /* Should be 0 */
187 #elif defined(__BIG_ENDIAN_BITFIELD)
188 unsigned ps
:1; /* Should be 0 */
189 unsigned reserved1_6
:1; /* Reserved */
190 unsigned page_code
:6; /* Page code - Should be 0x1b */
192 #error "Bitfield endianness not defined! Check your byteorder.h"
194 u8 page_length
; /* Page Length - Should be 0xa */
195 #if defined(__LITTLE_ENDIAN_BITFIELD)
196 unsigned reserved2
:6;
197 unsigned srfp
:1; /* Supports reporting progress of format */
198 unsigned sflp
:1; /* System floppy type device */
199 unsigned tlun
:3; /* Total logical units supported by the device */
200 unsigned reserved3
:3;
201 unsigned sml
:1; /* Single / Multiple lun supported */
202 unsigned ncd
:1; /* Non cd optical device */
203 #elif defined(__BIG_ENDIAN_BITFIELD)
204 unsigned sflp
:1; /* System floppy type device */
205 unsigned srfp
:1; /* Supports reporting progress of format */
206 unsigned reserved2
:6;
207 unsigned ncd
:1; /* Non cd optical device */
208 unsigned sml
:1; /* Single / Multiple lun supported */
209 unsigned reserved3
:3;
210 unsigned tlun
:3; /* Total logical units supported by the device */
212 #error "Bitfield endianness not defined! Check your byteorder.h"
215 } idefloppy_capabilities_page_t
;
218 * Flexible disk page.
221 #if defined(__LITTLE_ENDIAN_BITFIELD)
222 unsigned page_code
:6; /* Page code - Should be 0x5 */
223 unsigned reserved1_6
:1; /* Reserved */
224 unsigned ps
:1; /* The device is capable of saving the page */
225 #elif defined(__BIG_ENDIAN_BITFIELD)
226 unsigned ps
:1; /* The device is capable of saving the page */
227 unsigned reserved1_6
:1; /* Reserved */
228 unsigned page_code
:6; /* Page code - Should be 0x5 */
230 #error "Bitfield endianness not defined! Check your byteorder.h"
232 u8 page_length
; /* Page Length - Should be 0x1e */
233 u16 transfer_rate
; /* In kilobits per second */
234 u8 heads
, sectors
; /* Number of heads, Number of sectors per track */
235 u16 sector_size
; /* Byes per sector */
236 u16 cyls
; /* Number of cylinders */
238 u8 motor_delay
; /* Motor off delay */
240 u16 rpm
; /* Rotations per minute */
242 } idefloppy_flexible_disk_page_t
;
249 u8 length
; /* Length of the following descriptors in bytes */
250 } idefloppy_capacity_header_t
;
253 u32 blocks
; /* Number of blocks */
254 #if defined(__LITTLE_ENDIAN_BITFIELD)
255 unsigned dc
:2; /* Descriptor Code */
256 unsigned reserved
:6;
257 #elif defined(__BIG_ENDIAN_BITFIELD)
258 unsigned reserved
:6;
259 unsigned dc
:2; /* Descriptor Code */
261 #error "Bitfield endianness not defined! Check your byteorder.h"
263 u8 length_msb
; /* Block Length (MSB)*/
264 u16 length
; /* Block Length */
265 } idefloppy_capacity_descriptor_t
;
267 #define CAPACITY_INVALID 0x00
268 #define CAPACITY_UNFORMATTED 0x01
269 #define CAPACITY_CURRENT 0x02
270 #define CAPACITY_NO_CARTRIDGE 0x03
273 * Most of our global data which we need to save even as we leave the
274 * driver due to an interrupt or a timer event is stored in a variable
275 * of type idefloppy_floppy_t, defined below.
277 typedef struct ide_floppy_obj
{
279 ide_driver_t
*driver
;
280 struct gendisk
*disk
;
282 unsigned int openers
; /* protected by BKL for now */
284 /* Current packet command */
286 /* Last failed packet command */
287 idefloppy_pc_t
*failed_pc
;
288 /* Packet command stack */
289 idefloppy_pc_t pc_stack
[IDEFLOPPY_PC_STACK
];
290 /* Next free packet command storage space */
292 struct request rq_stack
[IDEFLOPPY_PC_STACK
];
293 /* We implement a circular array */
297 * Last error information
299 u8 sense_key
, asc
, ascq
;
300 /* delay this long before sending packet command */
302 int progress_indication
;
308 int blocks
, block_size
, bs_factor
;
309 /* Last format capacity */
310 idefloppy_capacity_descriptor_t capacity
;
311 /* Copy of the flexible disk page */
312 idefloppy_flexible_disk_page_t flexible_disk_page
;
315 /* Supports format progress report */
317 /* Status/Action flags */
319 } idefloppy_floppy_t
;
321 #define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
324 * Floppy flag bits values.
326 #define IDEFLOPPY_DRQ_INTERRUPT 0 /* DRQ interrupt device */
327 #define IDEFLOPPY_MEDIA_CHANGED 1 /* Media may have changed */
328 #define IDEFLOPPY_USE_READ12 2 /* Use READ12/WRITE12 or READ10/WRITE10 */
329 #define IDEFLOPPY_FORMAT_IN_PROGRESS 3 /* Format in progress */
330 #define IDEFLOPPY_CLIK_DRIVE 4 /* Avoid commands not supported in Clik drive */
331 #define IDEFLOPPY_ZIP_DRIVE 5 /* Requires BH algorithm for packets */
334 * ATAPI floppy drive packet commands
336 #define IDEFLOPPY_FORMAT_UNIT_CMD 0x04
337 #define IDEFLOPPY_INQUIRY_CMD 0x12
338 #define IDEFLOPPY_MODE_SELECT_CMD 0x55
339 #define IDEFLOPPY_MODE_SENSE_CMD 0x5a
340 #define IDEFLOPPY_READ10_CMD 0x28
341 #define IDEFLOPPY_READ12_CMD 0xa8
342 #define IDEFLOPPY_READ_CAPACITY_CMD 0x23
343 #define IDEFLOPPY_REQUEST_SENSE_CMD 0x03
344 #define IDEFLOPPY_PREVENT_REMOVAL_CMD 0x1e
345 #define IDEFLOPPY_SEEK_CMD 0x2b
346 #define IDEFLOPPY_START_STOP_CMD 0x1b
347 #define IDEFLOPPY_TEST_UNIT_READY_CMD 0x00
348 #define IDEFLOPPY_VERIFY_CMD 0x2f
349 #define IDEFLOPPY_WRITE10_CMD 0x2a
350 #define IDEFLOPPY_WRITE12_CMD 0xaa
351 #define IDEFLOPPY_WRITE_VERIFY_CMD 0x2e
354 * Defines for the mode sense command
356 #define MODE_SENSE_CURRENT 0x00
357 #define MODE_SENSE_CHANGEABLE 0x01
358 #define MODE_SENSE_DEFAULT 0x02
359 #define MODE_SENSE_SAVED 0x03
362 * IOCTLs used in low-level formatting.
365 #define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
366 #define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
367 #define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
368 #define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
371 * Error codes which are returned in rq->errors to the higher part
374 #define IDEFLOPPY_ERROR_GENERAL 101
377 * The following is used to format the general configuration word of
378 * the ATAPI IDENTIFY DEVICE command.
380 struct idefloppy_id_gcw
{
381 #if defined(__LITTLE_ENDIAN_BITFIELD)
382 unsigned packet_size
:2; /* Packet Size */
383 unsigned reserved234
:3; /* Reserved */
384 unsigned drq_type
:2; /* Command packet DRQ type */
385 unsigned removable
:1; /* Removable media */
386 unsigned device_type
:5; /* Device type */
387 unsigned reserved13
:1; /* Reserved */
388 unsigned protocol
:2; /* Protocol type */
389 #elif defined(__BIG_ENDIAN_BITFIELD)
390 unsigned protocol
:2; /* Protocol type */
391 unsigned reserved13
:1; /* Reserved */
392 unsigned device_type
:5; /* Device type */
393 unsigned removable
:1; /* Removable media */
394 unsigned drq_type
:2; /* Command packet DRQ type */
395 unsigned reserved234
:3; /* Reserved */
396 unsigned packet_size
:2; /* Packet Size */
398 #error "Bitfield endianness not defined! Check your byteorder.h"
403 * INQUIRY packet command - Data Format
406 #if defined(__LITTLE_ENDIAN_BITFIELD)
407 unsigned device_type
:5; /* Peripheral Device Type */
408 unsigned reserved0_765
:3; /* Peripheral Qualifier - Reserved */
409 unsigned reserved1_6t0
:7; /* Reserved */
410 unsigned rmb
:1; /* Removable Medium Bit */
411 unsigned ansi_version
:3; /* ANSI Version */
412 unsigned ecma_version
:3; /* ECMA Version */
413 unsigned iso_version
:2; /* ISO Version */
414 unsigned response_format
:4; /* Response Data Format */
415 unsigned reserved3_45
:2; /* Reserved */
416 unsigned reserved3_6
:1; /* TrmIOP - Reserved */
417 unsigned reserved3_7
:1; /* AENC - Reserved */
418 #elif defined(__BIG_ENDIAN_BITFIELD)
419 unsigned reserved0_765
:3; /* Peripheral Qualifier - Reserved */
420 unsigned device_type
:5; /* Peripheral Device Type */
421 unsigned rmb
:1; /* Removable Medium Bit */
422 unsigned reserved1_6t0
:7; /* Reserved */
423 unsigned iso_version
:2; /* ISO Version */
424 unsigned ecma_version
:3; /* ECMA Version */
425 unsigned ansi_version
:3; /* ANSI Version */
426 unsigned reserved3_7
:1; /* AENC - Reserved */
427 unsigned reserved3_6
:1; /* TrmIOP - Reserved */
428 unsigned reserved3_45
:2; /* Reserved */
429 unsigned response_format
:4; /* Response Data Format */
431 #error "Bitfield endianness not defined! Check your byteorder.h"
433 u8 additional_length
; /* Additional Length (total_length-4) */
434 u8 rsv5
, rsv6
, rsv7
; /* Reserved */
435 u8 vendor_id
[8]; /* Vendor Identification */
436 u8 product_id
[16]; /* Product Identification */
437 u8 revision_level
[4]; /* Revision Level */
438 u8 vendor_specific
[20]; /* Vendor Specific - Optional */
439 u8 reserved56t95
[40]; /* Reserved - Optional */
440 /* Additional information may be returned */
441 } idefloppy_inquiry_result_t
;
444 * REQUEST SENSE packet command result - Data Format.
447 #if defined(__LITTLE_ENDIAN_BITFIELD)
448 unsigned error_code
:7; /* Current error (0x70) */
449 unsigned valid
:1; /* The information field conforms to SFF-8070i */
450 u8 reserved1
:8; /* Reserved */
451 unsigned sense_key
:4; /* Sense Key */
452 unsigned reserved2_4
:1; /* Reserved */
453 unsigned ili
:1; /* Incorrect Length Indicator */
454 unsigned reserved2_67
:2;
455 #elif defined(__BIG_ENDIAN_BITFIELD)
456 unsigned valid
:1; /* The information field conforms to SFF-8070i */
457 unsigned error_code
:7; /* Current error (0x70) */
458 u8 reserved1
:8; /* Reserved */
459 unsigned reserved2_67
:2;
460 unsigned ili
:1; /* Incorrect Length Indicator */
461 unsigned reserved2_4
:1; /* Reserved */
462 unsigned sense_key
:4; /* Sense Key */
464 #error "Bitfield endianness not defined! Check your byteorder.h"
466 u32 information
__attribute__ ((packed
));
467 u8 asl
; /* Additional sense length (n-7) */
468 u32 command_specific
; /* Additional command specific information */
469 u8 asc
; /* Additional Sense Code */
470 u8 ascq
; /* Additional Sense Code Qualifier */
471 u8 replaceable_unit_code
; /* Field Replaceable Unit Code */
473 u8 pad
[2]; /* Padding to 20 bytes */
474 } idefloppy_request_sense_result_t
;
477 * Pages of the SELECT SENSE / MODE SENSE packet commands.
479 #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
480 #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
483 * Mode Parameter Header for the MODE SENSE packet command
486 u16 mode_data_length
; /* Length of the following data transfer */
487 u8 medium_type
; /* Medium Type */
488 #if defined(__LITTLE_ENDIAN_BITFIELD)
489 unsigned reserved3
:7;
490 unsigned wp
:1; /* Write protect */
491 #elif defined(__BIG_ENDIAN_BITFIELD)
492 unsigned wp
:1; /* Write protect */
493 unsigned reserved3
:7;
495 #error "Bitfield endianness not defined! Check your byteorder.h"
498 } idefloppy_mode_parameter_header_t
;
500 static DEFINE_MUTEX(idefloppy_ref_mutex
);
502 #define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
504 #define ide_floppy_g(disk) \
505 container_of((disk)->private_data, struct ide_floppy_obj, driver)
507 static struct ide_floppy_obj
*ide_floppy_get(struct gendisk
*disk
)
509 struct ide_floppy_obj
*floppy
= NULL
;
511 mutex_lock(&idefloppy_ref_mutex
);
512 floppy
= ide_floppy_g(disk
);
514 kref_get(&floppy
->kref
);
515 mutex_unlock(&idefloppy_ref_mutex
);
519 static void ide_floppy_release(struct kref
*);
521 static void ide_floppy_put(struct ide_floppy_obj
*floppy
)
523 mutex_lock(&idefloppy_ref_mutex
);
524 kref_put(&floppy
->kref
, ide_floppy_release
);
525 mutex_unlock(&idefloppy_ref_mutex
);
529 * Too bad. The drive wants to send us data which we are not ready to accept.
530 * Just throw it away.
532 static void idefloppy_discard_data (ide_drive_t
*drive
, unsigned int bcount
)
535 (void) HWIF(drive
)->INB(IDE_DATA_REG
);
538 #if IDEFLOPPY_DEBUG_BUGS
539 static void idefloppy_write_zeros (ide_drive_t
*drive
, unsigned int bcount
)
542 HWIF(drive
)->OUTB(0, IDE_DATA_REG
);
544 #endif /* IDEFLOPPY_DEBUG_BUGS */
548 * idefloppy_do_end_request is used to finish servicing a request.
550 * For read/write requests, we will call ide_end_request to pass to the
553 static int idefloppy_do_end_request(ide_drive_t
*drive
, int uptodate
, int nsecs
)
555 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
556 struct request
*rq
= HWGROUP(drive
)->rq
;
559 debug_log(KERN_INFO
"Reached idefloppy_end_request\n");
562 case 0: error
= IDEFLOPPY_ERROR_GENERAL
; break;
563 case 1: error
= 0; break;
564 default: error
= uptodate
;
567 floppy
->failed_pc
= NULL
;
568 /* Why does this happen? */
571 if (!blk_special_request(rq
)) {
572 /* our real local end request function */
573 ide_end_request(drive
, uptodate
, nsecs
);
577 /* fixme: need to move this local also */
578 ide_end_drive_cmd(drive
, 0, 0);
582 static void idefloppy_input_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
, unsigned int bcount
)
584 struct request
*rq
= pc
->rq
;
585 struct bio_vec
*bvec
;
586 struct req_iterator iter
;
591 rq_for_each_segment(bvec
, rq
, iter
) {
595 count
= min(bvec
->bv_len
, bcount
);
597 data
= bvec_kmap_irq(bvec
, &flags
);
598 drive
->hwif
->atapi_input_bytes(drive
, data
, count
);
599 bvec_kunmap_irq(data
, &flags
);
602 pc
->b_count
+= count
;
606 idefloppy_do_end_request(drive
, 1, done
>> 9);
609 printk(KERN_ERR
"%s: leftover data in idefloppy_input_buffers, bcount == %d\n", drive
->name
, bcount
);
610 idefloppy_discard_data(drive
, bcount
);
614 static void idefloppy_output_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
, unsigned int bcount
)
616 struct request
*rq
= pc
->rq
;
617 struct req_iterator iter
;
618 struct bio_vec
*bvec
;
623 rq_for_each_segment(bvec
, rq
, iter
) {
627 count
= min(bvec
->bv_len
, bcount
);
629 data
= bvec_kmap_irq(bvec
, &flags
);
630 drive
->hwif
->atapi_output_bytes(drive
, data
, count
);
631 bvec_kunmap_irq(data
, &flags
);
634 pc
->b_count
+= count
;
638 idefloppy_do_end_request(drive
, 1, done
>> 9);
640 #if IDEFLOPPY_DEBUG_BUGS
642 printk(KERN_ERR
"%s: leftover data in idefloppy_output_buffers, bcount == %d\n", drive
->name
, bcount
);
643 idefloppy_write_zeros(drive
, bcount
);
648 static void idefloppy_update_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
)
650 struct request
*rq
= pc
->rq
;
651 struct bio
*bio
= rq
->bio
;
653 while ((bio
= rq
->bio
) != NULL
)
654 idefloppy_do_end_request(drive
, 1, 0);
658 * idefloppy_queue_pc_head generates a new packet command request in front
659 * of the request queue, before the current request, so that it will be
660 * processed immediately, on the next pass through the driver.
662 static void idefloppy_queue_pc_head (ide_drive_t
*drive
,idefloppy_pc_t
*pc
,struct request
*rq
)
664 struct ide_floppy_obj
*floppy
= drive
->driver_data
;
666 ide_init_drive_cmd(rq
);
667 rq
->buffer
= (char *) pc
;
668 rq
->cmd_type
= REQ_TYPE_SPECIAL
;
669 rq
->rq_disk
= floppy
->disk
;
670 (void) ide_do_drive_cmd(drive
, rq
, ide_preempt
);
673 static idefloppy_pc_t
*idefloppy_next_pc_storage (ide_drive_t
*drive
)
675 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
677 if (floppy
->pc_stack_index
== IDEFLOPPY_PC_STACK
)
678 floppy
->pc_stack_index
=0;
679 return (&floppy
->pc_stack
[floppy
->pc_stack_index
++]);
682 static struct request
*idefloppy_next_rq_storage (ide_drive_t
*drive
)
684 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
686 if (floppy
->rq_stack_index
== IDEFLOPPY_PC_STACK
)
687 floppy
->rq_stack_index
= 0;
688 return (&floppy
->rq_stack
[floppy
->rq_stack_index
++]);
692 * idefloppy_analyze_error is called on each failed packet command retry
693 * to analyze the request sense.
695 static void idefloppy_analyze_error (ide_drive_t
*drive
,idefloppy_request_sense_result_t
*result
)
697 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
699 floppy
->sense_key
= result
->sense_key
;
700 floppy
->asc
= result
->asc
;
701 floppy
->ascq
= result
->ascq
;
702 floppy
->progress_indication
= result
->sksv
[0] & 0x80 ?
703 (u16
)get_unaligned((u16
*)(result
->sksv
+1)):0x10000;
704 if (floppy
->failed_pc
)
705 debug_log(KERN_INFO
"ide-floppy: pc = %x, sense key = %x, "
706 "asc = %x, ascq = %x\n", floppy
->failed_pc
->c
[0],
707 result
->sense_key
, result
->asc
, result
->ascq
);
709 debug_log(KERN_INFO
"ide-floppy: sense key = %x, asc = %x, "
710 "ascq = %x\n", result
->sense_key
,
711 result
->asc
, result
->ascq
);
714 static void idefloppy_request_sense_callback (ide_drive_t
*drive
)
716 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
718 debug_log(KERN_INFO
"ide-floppy: Reached %s\n", __FUNCTION__
);
720 if (!floppy
->pc
->error
) {
721 idefloppy_analyze_error(drive
,(idefloppy_request_sense_result_t
*) floppy
->pc
->buffer
);
722 idefloppy_do_end_request(drive
, 1, 0);
724 printk(KERN_ERR
"Error in REQUEST SENSE itself - Aborting request!\n");
725 idefloppy_do_end_request(drive
, 0, 0);
730 * General packet command callback function.
732 static void idefloppy_pc_callback (ide_drive_t
*drive
)
734 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
736 debug_log(KERN_INFO
"ide-floppy: Reached %s\n", __FUNCTION__
);
738 idefloppy_do_end_request(drive
, floppy
->pc
->error
? 0 : 1, 0);
742 * idefloppy_init_pc initializes a packet command.
744 static void idefloppy_init_pc (idefloppy_pc_t
*pc
)
746 memset(pc
->c
, 0, 12);
749 pc
->request_transfer
= 0;
750 pc
->buffer
= pc
->pc_buffer
;
751 pc
->buffer_size
= IDEFLOPPY_PC_BUFFER_SIZE
;
752 pc
->callback
= &idefloppy_pc_callback
;
755 static void idefloppy_create_request_sense_cmd (idefloppy_pc_t
*pc
)
757 idefloppy_init_pc(pc
);
758 pc
->c
[0] = IDEFLOPPY_REQUEST_SENSE_CMD
;
760 pc
->request_transfer
= 18;
761 pc
->callback
= &idefloppy_request_sense_callback
;
765 * idefloppy_retry_pc is called when an error was detected during the
766 * last packet command. We queue a request sense packet command in
767 * the head of the request list.
769 static void idefloppy_retry_pc (ide_drive_t
*drive
)
774 (void)drive
->hwif
->INB(IDE_ERROR_REG
);
775 pc
= idefloppy_next_pc_storage(drive
);
776 rq
= idefloppy_next_rq_storage(drive
);
777 idefloppy_create_request_sense_cmd(pc
);
778 idefloppy_queue_pc_head(drive
, pc
, rq
);
782 * idefloppy_pc_intr is the usual interrupt handler which will be called
783 * during a packet command.
785 static ide_startstop_t
idefloppy_pc_intr (ide_drive_t
*drive
)
787 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
788 ide_hwif_t
*hwif
= drive
->hwif
;
789 idefloppy_pc_t
*pc
= floppy
->pc
;
790 struct request
*rq
= pc
->rq
;
795 debug_log(KERN_INFO
"ide-floppy: Reached %s interrupt handler\n",
798 if (test_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
)) {
799 if (HWIF(drive
)->ide_dma_end(drive
)) {
800 set_bit(PC_DMA_ERROR
, &pc
->flags
);
802 pc
->actually_transferred
= pc
->request_transfer
;
803 idefloppy_update_buffers(drive
, pc
);
805 debug_log(KERN_INFO
"ide-floppy: DMA finished\n");
808 /* Clear the interrupt */
809 stat
= drive
->hwif
->INB(IDE_STATUS_REG
);
811 if ((stat
& DRQ_STAT
) == 0) { /* No more interrupts */
812 debug_log(KERN_INFO
"Packet command completed, %d bytes "
813 "transferred\n", pc
->actually_transferred
);
814 clear_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
);
816 local_irq_enable_in_hardirq();
818 if ((stat
& ERR_STAT
) || test_bit(PC_DMA_ERROR
, &pc
->flags
)) {
820 debug_log(KERN_INFO
"ide-floppy: %s: I/O error\n",
823 if (pc
->c
[0] == IDEFLOPPY_REQUEST_SENSE_CMD
) {
824 printk(KERN_ERR
"ide-floppy: I/O error in "
825 "request sense command\n");
826 return ide_do_reset(drive
);
828 /* Retry operation */
829 idefloppy_retry_pc(drive
);
830 /* queued, but not started */
834 if (floppy
->failed_pc
== pc
)
835 floppy
->failed_pc
= NULL
;
836 /* Command finished - Call the callback function */
841 if (test_and_clear_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
)) {
842 printk(KERN_ERR
"ide-floppy: The floppy wants to issue "
843 "more interrupts in DMA mode\n");
845 return ide_do_reset(drive
);
848 /* Get the number of bytes to transfer */
849 bcount
= (hwif
->INB(IDE_BCOUNTH_REG
) << 8) |
850 hwif
->INB(IDE_BCOUNTL_REG
);
851 /* on this interrupt */
852 ireason
= hwif
->INB(IDE_IREASON_REG
);
855 printk(KERN_ERR
"ide-floppy: CoD != 0 in idefloppy_pc_intr\n");
856 return ide_do_reset(drive
);
858 if (((ireason
& IO
) == IO
) == test_bit(PC_WRITING
, &pc
->flags
)) {
859 /* Hopefully, we will never get here */
860 printk(KERN_ERR
"ide-floppy: We wanted to %s, ",
861 (ireason
& IO
) ? "Write" : "Read");
862 printk(KERN_ERR
"but the floppy wants us to %s !\n",
863 (ireason
& IO
) ? "Read" : "Write");
864 return ide_do_reset(drive
);
866 if (!test_bit(PC_WRITING
, &pc
->flags
)) {
867 /* Reading - Check that we have enough space */
868 temp
= pc
->actually_transferred
+ bcount
;
869 if (temp
> pc
->request_transfer
) {
870 if (temp
> pc
->buffer_size
) {
871 printk(KERN_ERR
"ide-floppy: The floppy wants "
872 "to send us more data than expected "
873 "- discarding data\n");
874 idefloppy_discard_data(drive
, bcount
);
875 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
876 ide_set_handler(drive
,
882 debug_log(KERN_NOTICE
"ide-floppy: The floppy wants to "
883 "send us more data than expected - "
884 "allowing transfer\n");
887 if (test_bit(PC_WRITING
, &pc
->flags
)) {
888 if (pc
->buffer
!= NULL
)
889 /* Write the current buffer */
890 hwif
->atapi_output_bytes(drive
, pc
->current_position
,
893 idefloppy_output_buffers(drive
, pc
, bcount
);
895 if (pc
->buffer
!= NULL
)
896 /* Read the current buffer */
897 hwif
->atapi_input_bytes(drive
, pc
->current_position
,
900 idefloppy_input_buffers(drive
, pc
, bcount
);
902 /* Update the current position */
903 pc
->actually_transferred
+= bcount
;
904 pc
->current_position
+= bcount
;
906 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
907 ide_set_handler(drive
, &idefloppy_pc_intr
, IDEFLOPPY_WAIT_CMD
, NULL
); /* And set the interrupt handler again */
912 * This is the original routine that did the packet transfer.
913 * It fails at high speeds on the Iomega ZIP drive, so there's a slower version
914 * for that drive below. The algorithm is chosen based on drive type
916 static ide_startstop_t
idefloppy_transfer_pc (ide_drive_t
*drive
)
918 ide_startstop_t startstop
;
919 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
922 if (ide_wait_stat(&startstop
, drive
, DRQ_STAT
, BUSY_STAT
, WAIT_READY
)) {
923 printk(KERN_ERR
"ide-floppy: Strange, packet command "
924 "initiated yet DRQ isn't asserted\n");
927 ireason
= drive
->hwif
->INB(IDE_IREASON_REG
);
928 if ((ireason
& CD
) == 0 || (ireason
& IO
)) {
929 printk(KERN_ERR
"ide-floppy: (IO,CoD) != (0,1) while "
930 "issuing a packet command\n");
931 return ide_do_reset(drive
);
933 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
934 /* Set the interrupt routine */
935 ide_set_handler(drive
, &idefloppy_pc_intr
, IDEFLOPPY_WAIT_CMD
, NULL
);
936 /* Send the actual packet */
937 HWIF(drive
)->atapi_output_bytes(drive
, floppy
->pc
->c
, 12);
943 * What we have here is a classic case of a top half / bottom half
944 * interrupt service routine. In interrupt mode, the device sends
945 * an interrupt to signal it's ready to receive a packet. However,
946 * we need to delay about 2-3 ticks before issuing the packet or we
949 * So, follow carefully. transfer_pc1 is called as an interrupt (or
950 * directly). In either case, when the device says it's ready for a
951 * packet, we schedule the packet transfer to occur about 2-3 ticks
952 * later in transfer_pc2.
954 static int idefloppy_transfer_pc2 (ide_drive_t
*drive
)
956 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
958 /* Send the actual packet */
959 HWIF(drive
)->atapi_output_bytes(drive
, floppy
->pc
->c
, 12);
960 /* Timeout for the packet command */
961 return IDEFLOPPY_WAIT_CMD
;
964 static ide_startstop_t
idefloppy_transfer_pc1 (ide_drive_t
*drive
)
966 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
967 ide_startstop_t startstop
;
970 if (ide_wait_stat(&startstop
, drive
, DRQ_STAT
, BUSY_STAT
, WAIT_READY
)) {
971 printk(KERN_ERR
"ide-floppy: Strange, packet command "
972 "initiated yet DRQ isn't asserted\n");
975 ireason
= drive
->hwif
->INB(IDE_IREASON_REG
);
976 if ((ireason
& CD
) == 0 || (ireason
& IO
)) {
977 printk(KERN_ERR
"ide-floppy: (IO,CoD) != (0,1) "
978 "while issuing a packet command\n");
979 return ide_do_reset(drive
);
982 * The following delay solves a problem with ATAPI Zip 100 drives
983 * where the Busy flag was apparently being deasserted before the
984 * unit was ready to receive data. This was happening on a
985 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
986 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
987 * used until after the packet is moved in about 50 msec.
989 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
990 ide_set_handler(drive
,
991 &idefloppy_pc_intr
, /* service routine for packet command */
992 floppy
->ticks
, /* wait this long before "failing" */
993 &idefloppy_transfer_pc2
); /* fail == transfer_pc2 */
998 * idefloppy_should_report_error()
1000 * Supresses error messages resulting from Medium not present
1002 static inline int idefloppy_should_report_error(idefloppy_floppy_t
*floppy
)
1004 if (floppy
->sense_key
== 0x02 &&
1005 floppy
->asc
== 0x3a &&
1006 floppy
->ascq
== 0x00)
1012 * Issue a packet command
1014 static ide_startstop_t
idefloppy_issue_pc (ide_drive_t
*drive
, idefloppy_pc_t
*pc
)
1016 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1017 ide_hwif_t
*hwif
= drive
->hwif
;
1018 ide_handler_t
*pkt_xfer_routine
;
1022 if (floppy
->failed_pc
== NULL
&&
1023 pc
->c
[0] != IDEFLOPPY_REQUEST_SENSE_CMD
)
1024 floppy
->failed_pc
= pc
;
1025 /* Set the current packet command */
1028 if (pc
->retries
> IDEFLOPPY_MAX_PC_RETRIES
||
1029 test_bit(PC_ABORT
, &pc
->flags
)) {
1031 * We will "abort" retrying a packet command in case
1032 * a legitimate error code was received.
1034 if (!test_bit(PC_ABORT
, &pc
->flags
)) {
1035 if (!test_bit(PC_SUPPRESS_ERROR
, &pc
->flags
)) {
1036 if (idefloppy_should_report_error(floppy
))
1037 printk(KERN_ERR
"ide-floppy: %s: I/O error, "
1038 "pc = %2x, key = %2x, "
1039 "asc = %2x, ascq = %2x\n",
1040 drive
->name
, pc
->c
[0],
1042 floppy
->asc
, floppy
->ascq
);
1045 pc
->error
= IDEFLOPPY_ERROR_GENERAL
;
1047 floppy
->failed_pc
= NULL
;
1048 pc
->callback(drive
);
1052 debug_log(KERN_INFO
"Retry number - %d\n",pc
->retries
);
1055 /* We haven't transferred any data yet */
1056 pc
->actually_transferred
= 0;
1057 pc
->current_position
= pc
->buffer
;
1058 bcount
= min(pc
->request_transfer
, 63 * 1024);
1060 if (test_and_clear_bit(PC_DMA_ERROR
, &pc
->flags
))
1065 if (test_bit(PC_DMA_RECOMMENDED
, &pc
->flags
) && drive
->using_dma
)
1066 dma
= !hwif
->dma_setup(drive
);
1068 ide_pktcmd_tf_load(drive
, IDE_TFLAG_NO_SELECT_MASK
|
1069 IDE_TFLAG_OUT_DEVICE
, bcount
, dma
);
1071 if (dma
) { /* Begin DMA, if necessary */
1072 set_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
);
1073 hwif
->dma_start(drive
);
1076 /* Can we transfer the packet when we get the interrupt or wait? */
1077 if (test_bit(IDEFLOPPY_ZIP_DRIVE
, &floppy
->flags
)) {
1079 pkt_xfer_routine
= &idefloppy_transfer_pc1
;
1082 pkt_xfer_routine
= &idefloppy_transfer_pc
;
1085 if (test_bit (IDEFLOPPY_DRQ_INTERRUPT
, &floppy
->flags
)) {
1086 /* Issue the packet command */
1087 ide_execute_command(drive
, WIN_PACKETCMD
,
1093 /* Issue the packet command */
1094 HWIF(drive
)->OUTB(WIN_PACKETCMD
, IDE_COMMAND_REG
);
1095 return (*pkt_xfer_routine
) (drive
);
1099 static void idefloppy_rw_callback (ide_drive_t
*drive
)
1101 debug_log(KERN_INFO
"ide-floppy: Reached idefloppy_rw_callback\n");
1103 idefloppy_do_end_request(drive
, 1, 0);
1107 static void idefloppy_create_prevent_cmd (idefloppy_pc_t
*pc
, int prevent
)
1109 debug_log(KERN_INFO
"ide-floppy: creating prevent removal command, "
1110 "prevent = %d\n", prevent
);
1112 idefloppy_init_pc(pc
);
1113 pc
->c
[0] = IDEFLOPPY_PREVENT_REMOVAL_CMD
;
1117 static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t
*pc
)
1119 idefloppy_init_pc(pc
);
1120 pc
->c
[0] = IDEFLOPPY_READ_CAPACITY_CMD
;
1123 pc
->request_transfer
= 255;
1126 static void idefloppy_create_format_unit_cmd (idefloppy_pc_t
*pc
, int b
, int l
,
1129 idefloppy_init_pc(pc
);
1130 pc
->c
[0] = IDEFLOPPY_FORMAT_UNIT_CMD
;
1133 memset(pc
->buffer
, 0, 12);
1134 pc
->buffer
[1] = 0xA2;
1135 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
1137 if (flags
& 1) /* Verify bit on... */
1138 pc
->buffer
[1] ^= 0x20; /* ... turn off DCRT bit */
1141 put_unaligned(htonl(b
), (unsigned int *)(&pc
->buffer
[4]));
1142 put_unaligned(htonl(l
), (unsigned int *)(&pc
->buffer
[8]));
1144 set_bit(PC_WRITING
, &pc
->flags
);
1148 * A mode sense command is used to "sense" floppy parameters.
1150 static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t
*pc
, u8 page_code
, u8 type
)
1152 u16 length
= sizeof(idefloppy_mode_parameter_header_t
);
1154 idefloppy_init_pc(pc
);
1155 pc
->c
[0] = IDEFLOPPY_MODE_SENSE_CMD
;
1157 pc
->c
[2] = page_code
+ (type
<< 6);
1159 switch (page_code
) {
1160 case IDEFLOPPY_CAPABILITIES_PAGE
:
1163 case IDEFLOPPY_FLEXIBLE_DISK_PAGE
:
1167 printk(KERN_ERR
"ide-floppy: unsupported page code "
1168 "in create_mode_sense_cmd\n");
1170 put_unaligned(htons(length
), (u16
*) &pc
->c
[7]);
1171 pc
->request_transfer
= length
;
1174 static void idefloppy_create_start_stop_cmd (idefloppy_pc_t
*pc
, int start
)
1176 idefloppy_init_pc(pc
);
1177 pc
->c
[0] = IDEFLOPPY_START_STOP_CMD
;
1181 static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t
*pc
)
1183 idefloppy_init_pc(pc
);
1184 pc
->c
[0] = IDEFLOPPY_TEST_UNIT_READY_CMD
;
1187 static void idefloppy_create_rw_cmd (idefloppy_floppy_t
*floppy
, idefloppy_pc_t
*pc
, struct request
*rq
, unsigned long sector
)
1189 int block
= sector
/ floppy
->bs_factor
;
1190 int blocks
= rq
->nr_sectors
/ floppy
->bs_factor
;
1191 int cmd
= rq_data_dir(rq
);
1193 debug_log("create_rw1%d_cmd: block == %d, blocks == %d\n",
1194 2 * test_bit (IDEFLOPPY_USE_READ12
, &floppy
->flags
),
1197 idefloppy_init_pc(pc
);
1198 if (test_bit(IDEFLOPPY_USE_READ12
, &floppy
->flags
)) {
1199 pc
->c
[0] = cmd
== READ
? IDEFLOPPY_READ12_CMD
: IDEFLOPPY_WRITE12_CMD
;
1200 put_unaligned(htonl(blocks
), (unsigned int *) &pc
->c
[6]);
1202 pc
->c
[0] = cmd
== READ
? IDEFLOPPY_READ10_CMD
: IDEFLOPPY_WRITE10_CMD
;
1203 put_unaligned(htons(blocks
), (unsigned short *) &pc
->c
[7]);
1205 put_unaligned(htonl(block
), (unsigned int *) &pc
->c
[2]);
1206 pc
->callback
= &idefloppy_rw_callback
;
1208 pc
->b_count
= cmd
== READ
? 0 : rq
->bio
->bi_size
;
1209 if (rq
->cmd_flags
& REQ_RW
)
1210 set_bit(PC_WRITING
, &pc
->flags
);
1212 pc
->request_transfer
= pc
->buffer_size
= blocks
* floppy
->block_size
;
1213 set_bit(PC_DMA_RECOMMENDED
, &pc
->flags
);
1217 idefloppy_blockpc_cmd(idefloppy_floppy_t
*floppy
, idefloppy_pc_t
*pc
, struct request
*rq
)
1219 idefloppy_init_pc(pc
);
1220 pc
->callback
= &idefloppy_rw_callback
;
1221 memcpy(pc
->c
, rq
->cmd
, sizeof(pc
->c
));
1223 pc
->b_count
= rq
->data_len
;
1224 if (rq
->data_len
&& rq_data_dir(rq
) == WRITE
)
1225 set_bit(PC_WRITING
, &pc
->flags
);
1226 pc
->buffer
= rq
->data
;
1228 set_bit(PC_DMA_RECOMMENDED
, &pc
->flags
);
1231 * possibly problematic, doesn't look like ide-floppy correctly
1232 * handled scattered requests if dma fails...
1234 pc
->request_transfer
= pc
->buffer_size
= rq
->data_len
;
1238 * idefloppy_do_request is our request handling function.
1240 static ide_startstop_t
idefloppy_do_request (ide_drive_t
*drive
, struct request
*rq
, sector_t block_s
)
1242 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1244 unsigned long block
= (unsigned long)block_s
;
1246 debug_log(KERN_INFO
"dev: %s, flags: %lx, errors: %d\n",
1247 rq
->rq_disk
? rq
->rq_disk
->disk_name
: "?",
1248 rq
->flags
, rq
->errors
);
1249 debug_log(KERN_INFO
"sector: %ld, nr_sectors: %ld, "
1250 "current_nr_sectors: %d\n", (long)rq
->sector
,
1251 rq
->nr_sectors
, rq
->current_nr_sectors
);
1253 if (rq
->errors
>= ERROR_MAX
) {
1254 if (floppy
->failed_pc
!= NULL
) {
1255 if (idefloppy_should_report_error(floppy
))
1256 printk(KERN_ERR
"ide-floppy: %s: I/O error, pc = %2x,"
1257 " key = %2x, asc = %2x, ascq = %2x\n",
1258 drive
->name
, floppy
->failed_pc
->c
[0],
1259 floppy
->sense_key
, floppy
->asc
, floppy
->ascq
);
1262 printk(KERN_ERR
"ide-floppy: %s: I/O error\n",
1264 idefloppy_do_end_request(drive
, 0, 0);
1267 if (blk_fs_request(rq
)) {
1268 if (((long)rq
->sector
% floppy
->bs_factor
) ||
1269 (rq
->nr_sectors
% floppy
->bs_factor
)) {
1270 printk("%s: unsupported r/w request size\n",
1272 idefloppy_do_end_request(drive
, 0, 0);
1275 pc
= idefloppy_next_pc_storage(drive
);
1276 idefloppy_create_rw_cmd(floppy
, pc
, rq
, block
);
1277 } else if (blk_special_request(rq
)) {
1278 pc
= (idefloppy_pc_t
*) rq
->buffer
;
1279 } else if (blk_pc_request(rq
)) {
1280 pc
= idefloppy_next_pc_storage(drive
);
1281 idefloppy_blockpc_cmd(floppy
, pc
, rq
);
1283 blk_dump_rq_flags(rq
,
1284 "ide-floppy: unsupported command in queue");
1285 idefloppy_do_end_request(drive
, 0, 0);
1290 return idefloppy_issue_pc(drive
, pc
);
1294 * idefloppy_queue_pc_tail adds a special packet command request to the
1295 * tail of the request queue, and waits for it to be serviced.
1297 static int idefloppy_queue_pc_tail (ide_drive_t
*drive
,idefloppy_pc_t
*pc
)
1299 struct ide_floppy_obj
*floppy
= drive
->driver_data
;
1302 ide_init_drive_cmd (&rq
);
1303 rq
.buffer
= (char *) pc
;
1304 rq
.cmd_type
= REQ_TYPE_SPECIAL
;
1305 rq
.rq_disk
= floppy
->disk
;
1307 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
1311 * Look at the flexible disk page parameters. We will ignore the CHS
1312 * capacity parameters and use the LBA parameters instead.
1314 static int idefloppy_get_flexible_disk_page (ide_drive_t
*drive
)
1316 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1318 idefloppy_mode_parameter_header_t
*header
;
1319 idefloppy_flexible_disk_page_t
*page
;
1320 int capacity
, lba_capacity
;
1322 idefloppy_create_mode_sense_cmd(&pc
, IDEFLOPPY_FLEXIBLE_DISK_PAGE
, MODE_SENSE_CURRENT
);
1323 if (idefloppy_queue_pc_tail(drive
,&pc
)) {
1324 printk(KERN_ERR
"ide-floppy: Can't get flexible disk "
1325 "page parameters\n");
1328 header
= (idefloppy_mode_parameter_header_t
*) pc
.buffer
;
1329 floppy
->wp
= header
->wp
;
1330 set_disk_ro(floppy
->disk
, floppy
->wp
);
1331 page
= (idefloppy_flexible_disk_page_t
*) (header
+ 1);
1333 page
->transfer_rate
= ntohs(page
->transfer_rate
);
1334 page
->sector_size
= ntohs(page
->sector_size
);
1335 page
->cyls
= ntohs(page
->cyls
);
1336 page
->rpm
= ntohs(page
->rpm
);
1337 capacity
= page
->cyls
* page
->heads
* page
->sectors
* page
->sector_size
;
1338 if (memcmp (page
, &floppy
->flexible_disk_page
, sizeof (idefloppy_flexible_disk_page_t
)))
1339 printk(KERN_INFO
"%s: %dkB, %d/%d/%d CHS, %d kBps, "
1340 "%d sector size, %d rpm\n",
1341 drive
->name
, capacity
/ 1024, page
->cyls
,
1342 page
->heads
, page
->sectors
,
1343 page
->transfer_rate
/ 8, page
->sector_size
, page
->rpm
);
1345 floppy
->flexible_disk_page
= *page
;
1346 drive
->bios_cyl
= page
->cyls
;
1347 drive
->bios_head
= page
->heads
;
1348 drive
->bios_sect
= page
->sectors
;
1349 lba_capacity
= floppy
->blocks
* floppy
->block_size
;
1350 if (capacity
< lba_capacity
) {
1351 printk(KERN_NOTICE
"%s: The disk reports a capacity of %d "
1352 "bytes, but the drive only handles %d\n",
1353 drive
->name
, lba_capacity
, capacity
);
1354 floppy
->blocks
= floppy
->block_size
? capacity
/ floppy
->block_size
: 0;
1359 static int idefloppy_get_capability_page(ide_drive_t
*drive
)
1361 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1363 idefloppy_mode_parameter_header_t
*header
;
1364 idefloppy_capabilities_page_t
*page
;
1367 idefloppy_create_mode_sense_cmd(&pc
, IDEFLOPPY_CAPABILITIES_PAGE
,
1368 MODE_SENSE_CURRENT
);
1370 set_bit(PC_SUPPRESS_ERROR
, &pc
.flags
);
1371 if (idefloppy_queue_pc_tail(drive
,&pc
)) {
1375 header
= (idefloppy_mode_parameter_header_t
*) pc
.buffer
;
1376 page
= (idefloppy_capabilities_page_t
*)(header
+1);
1377 floppy
->srfp
= page
->srfp
;
1382 * Determine if a media is present in the floppy drive, and if so,
1385 static int idefloppy_get_capacity (ide_drive_t
*drive
)
1387 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1389 idefloppy_capacity_header_t
*header
;
1390 idefloppy_capacity_descriptor_t
*descriptor
;
1391 int i
, descriptors
, rc
= 1, blocks
, length
;
1393 drive
->bios_cyl
= 0;
1394 drive
->bios_head
= drive
->bios_sect
= 0;
1396 floppy
->bs_factor
= 1;
1397 set_capacity(floppy
->disk
, 0);
1399 idefloppy_create_read_capacity_cmd(&pc
);
1400 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1401 printk(KERN_ERR
"ide-floppy: Can't get floppy parameters\n");
1404 header
= (idefloppy_capacity_header_t
*) pc
.buffer
;
1405 descriptors
= header
->length
/ sizeof(idefloppy_capacity_descriptor_t
);
1406 descriptor
= (idefloppy_capacity_descriptor_t
*) (header
+ 1);
1408 for (i
= 0; i
< descriptors
; i
++, descriptor
++) {
1409 blocks
= descriptor
->blocks
= ntohl(descriptor
->blocks
);
1410 length
= descriptor
->length
= ntohs(descriptor
->length
);
1414 switch (descriptor
->dc
) {
1415 /* Clik! drive returns this instead of CAPACITY_CURRENT */
1416 case CAPACITY_UNFORMATTED
:
1417 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
))
1419 * If it is not a clik drive, break out
1420 * (maintains previous driver behaviour)
1423 case CAPACITY_CURRENT
:
1424 /* Normal Zip/LS-120 disks */
1425 if (memcmp(descriptor
, &floppy
->capacity
, sizeof (idefloppy_capacity_descriptor_t
)))
1426 printk(KERN_INFO
"%s: %dkB, %d blocks, %d "
1427 "sector size\n", drive
->name
,
1428 blocks
* length
/ 1024, blocks
, length
);
1429 floppy
->capacity
= *descriptor
;
1430 if (!length
|| length
% 512) {
1431 printk(KERN_NOTICE
"%s: %d bytes block size "
1432 "not supported\n", drive
->name
, length
);
1434 floppy
->blocks
= blocks
;
1435 floppy
->block_size
= length
;
1436 if ((floppy
->bs_factor
= length
/ 512) != 1)
1437 printk(KERN_NOTICE
"%s: warning: non "
1438 "512 bytes block size not "
1439 "fully supported\n",
1444 case CAPACITY_NO_CARTRIDGE
:
1446 * This is a KERN_ERR so it appears on screen
1447 * for the user to see
1449 printk(KERN_ERR
"%s: No disk in drive\n", drive
->name
);
1451 case CAPACITY_INVALID
:
1452 printk(KERN_ERR
"%s: Invalid capacity for disk "
1453 "in drive\n", drive
->name
);
1458 debug_log( "Descriptor 0 Code: %d\n",
1461 debug_log( "Descriptor %d: %dkB, %d blocks, %d "
1462 "sector size\n", i
, blocks
* length
/ 1024, blocks
,
1466 /* Clik! disk does not support get_flexible_disk_page */
1467 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1468 (void) idefloppy_get_flexible_disk_page(drive
);
1471 set_capacity(floppy
->disk
, floppy
->blocks
* floppy
->bs_factor
);
1476 ** Obtain the list of formattable capacities.
1477 ** Very similar to idefloppy_get_capacity, except that we push the capacity
1478 ** descriptors to userland, instead of our own structures.
1480 ** Userland gives us the following structure:
1482 ** struct idefloppy_format_capacities {
1490 ** userland initializes nformats to the number of allocated formats[]
1491 ** records. On exit we set nformats to the number of records we've
1492 ** actually initialized.
1496 static int idefloppy_get_format_capacities(ide_drive_t
*drive
, int __user
*arg
)
1499 idefloppy_capacity_header_t
*header
;
1500 idefloppy_capacity_descriptor_t
*descriptor
;
1501 int i
, descriptors
, blocks
, length
;
1506 if (get_user(u_array_size
, arg
))
1509 if (u_array_size
<= 0)
1512 idefloppy_create_read_capacity_cmd(&pc
);
1513 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1514 printk(KERN_ERR
"ide-floppy: Can't get floppy parameters\n");
1517 header
= (idefloppy_capacity_header_t
*) pc
.buffer
;
1518 descriptors
= header
->length
/
1519 sizeof(idefloppy_capacity_descriptor_t
);
1520 descriptor
= (idefloppy_capacity_descriptor_t
*) (header
+ 1);
1526 ** We always skip the first capacity descriptor. That's the
1527 ** current capacity. We are interested in the remaining descriptors,
1528 ** the formattable capacities.
1531 for (i
=0; i
<descriptors
; i
++, descriptor
++) {
1532 if (u_index
>= u_array_size
)
1533 break; /* User-supplied buffer too small */
1535 continue; /* Skip the first descriptor */
1537 blocks
= ntohl(descriptor
->blocks
);
1538 length
= ntohs(descriptor
->length
);
1540 if (put_user(blocks
, argp
))
1544 if (put_user(length
, argp
))
1551 if (put_user(u_index
, arg
))
1557 ** Send ATAPI_FORMAT_UNIT to the drive.
1559 ** Userland gives us the following structure:
1561 ** struct idefloppy_format_command {
1567 ** flags is a bitmask, currently, the only defined flag is:
1569 ** 0x01 - verify media after format.
1572 static int idefloppy_begin_format(ide_drive_t
*drive
, int __user
*arg
)
1579 if (get_user(blocks
, arg
) ||
1580 get_user(length
, arg
+1) ||
1581 get_user(flags
, arg
+2)) {
1585 /* Get the SFRP bit */
1586 (void) idefloppy_get_capability_page(drive
);
1587 idefloppy_create_format_unit_cmd(&pc
, blocks
, length
, flags
);
1588 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1596 ** Get ATAPI_FORMAT_UNIT progress indication.
1598 ** Userland gives a pointer to an int. The int is set to a progress
1599 ** indicator 0-65536, with 65536=100%.
1601 ** If the drive does not support format progress indication, we just check
1602 ** the dsc bit, and return either 0 or 65536.
1605 static int idefloppy_get_format_progress(ide_drive_t
*drive
, int __user
*arg
)
1607 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1609 int progress_indication
= 0x10000;
1612 idefloppy_create_request_sense_cmd(&pc
);
1613 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1617 if (floppy
->sense_key
== 2 &&
1619 floppy
->ascq
== 4) {
1620 progress_indication
= floppy
->progress_indication
;
1622 /* Else assume format_unit has finished, and we're
1625 unsigned long flags
;
1628 local_irq_save(flags
);
1629 stat
= drive
->hwif
->INB(IDE_STATUS_REG
);
1630 local_irq_restore(flags
);
1632 progress_indication
= ((stat
& SEEK_STAT
) == 0) ? 0 : 0x10000;
1634 if (put_user(progress_indication
, arg
))
1641 * Return the current floppy capacity.
1643 static sector_t
idefloppy_capacity (ide_drive_t
*drive
)
1645 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1646 unsigned long capacity
= floppy
->blocks
* floppy
->bs_factor
;
1652 * idefloppy_identify_device checks if we can support a drive,
1653 * based on the ATAPI IDENTIFY command results.
1655 static int idefloppy_identify_device (ide_drive_t
*drive
,struct hd_driveid
*id
)
1657 struct idefloppy_id_gcw gcw
;
1658 #if IDEFLOPPY_DEBUG_INFO
1660 #endif /* IDEFLOPPY_DEBUG_INFO */
1662 *((u16
*) &gcw
) = id
->config
;
1665 /* kludge for Apple PowerBook internal zip */
1666 if ((gcw
.device_type
== 5) &&
1667 !strstr(id
->model
, "CD-ROM") &&
1668 strstr(id
->model
, "ZIP"))
1669 gcw
.device_type
= 0;
1672 #if IDEFLOPPY_DEBUG_INFO
1673 printk(KERN_INFO
"Dumping ATAPI Identify Device floppy parameters\n");
1674 switch (gcw
.protocol
) {
1675 case 0: case 1: sprintf(buffer
, "ATA");break;
1676 case 2: sprintf(buffer
, "ATAPI");break;
1677 case 3: sprintf(buffer
, "Reserved (Unknown to ide-floppy)");break;
1679 printk(KERN_INFO
"Protocol Type: %s\n", buffer
);
1680 switch (gcw
.device_type
) {
1681 case 0: sprintf(buffer
, "Direct-access Device");break;
1682 case 1: sprintf(buffer
, "Streaming Tape Device");break;
1683 case 2: case 3: case 4: sprintf (buffer
, "Reserved");break;
1684 case 5: sprintf(buffer
, "CD-ROM Device");break;
1685 case 6: sprintf(buffer
, "Reserved");
1686 case 7: sprintf(buffer
, "Optical memory Device");break;
1687 case 0x1f: sprintf(buffer
, "Unknown or no Device type");break;
1688 default: sprintf(buffer
, "Reserved");
1690 printk(KERN_INFO
"Device Type: %x - %s\n", gcw
.device_type
, buffer
);
1691 printk(KERN_INFO
"Removable: %s\n",gcw
.removable
? "Yes":"No");
1692 switch (gcw
.drq_type
) {
1693 case 0: sprintf(buffer
, "Microprocessor DRQ");break;
1694 case 1: sprintf(buffer
, "Interrupt DRQ");break;
1695 case 2: sprintf(buffer
, "Accelerated DRQ");break;
1696 case 3: sprintf(buffer
, "Reserved");break;
1698 printk(KERN_INFO
"Command Packet DRQ Type: %s\n", buffer
);
1699 switch (gcw
.packet_size
) {
1700 case 0: sprintf(buffer
, "12 bytes");break;
1701 case 1: sprintf(buffer
, "16 bytes");break;
1702 default: sprintf(buffer
, "Reserved");break;
1704 printk(KERN_INFO
"Command Packet Size: %s\n", buffer
);
1705 #endif /* IDEFLOPPY_DEBUG_INFO */
1707 if (gcw
.protocol
!= 2)
1708 printk(KERN_ERR
"ide-floppy: Protocol is not ATAPI\n");
1709 else if (gcw
.device_type
!= 0)
1710 printk(KERN_ERR
"ide-floppy: Device type is not set to floppy\n");
1711 else if (!gcw
.removable
)
1712 printk(KERN_ERR
"ide-floppy: The removable flag is not set\n");
1713 else if (gcw
.drq_type
== 3) {
1714 printk(KERN_ERR
"ide-floppy: Sorry, DRQ type %d not supported\n", gcw
.drq_type
);
1715 } else if (gcw
.packet_size
!= 0) {
1716 printk(KERN_ERR
"ide-floppy: Packet size is not 12 bytes long\n");
1722 #ifdef CONFIG_IDE_PROC_FS
1723 static void idefloppy_add_settings(ide_drive_t
*drive
)
1725 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1728 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
1730 ide_add_setting(drive
, "bios_cyl", SETTING_RW
, TYPE_INT
, 0, 1023, 1, 1, &drive
->bios_cyl
, NULL
);
1731 ide_add_setting(drive
, "bios_head", SETTING_RW
, TYPE_BYTE
, 0, 255, 1, 1, &drive
->bios_head
, NULL
);
1732 ide_add_setting(drive
, "bios_sect", SETTING_RW
, TYPE_BYTE
, 0, 63, 1, 1, &drive
->bios_sect
, NULL
);
1733 ide_add_setting(drive
, "ticks", SETTING_RW
, TYPE_BYTE
, 0, 255, 1, 1, &floppy
->ticks
, NULL
);
1736 static inline void idefloppy_add_settings(ide_drive_t
*drive
) { ; }
1740 * Driver initialization.
1742 static void idefloppy_setup (ide_drive_t
*drive
, idefloppy_floppy_t
*floppy
)
1744 struct idefloppy_id_gcw gcw
;
1746 *((u16
*) &gcw
) = drive
->id
->config
;
1747 floppy
->pc
= floppy
->pc_stack
;
1748 if (gcw
.drq_type
== 1)
1749 set_bit(IDEFLOPPY_DRQ_INTERRUPT
, &floppy
->flags
);
1751 * We used to check revisions here. At this point however
1752 * I'm giving up. Just assume they are all broken, its easier.
1754 * The actual reason for the workarounds was likely
1755 * a driver bug after all rather than a firmware bug,
1756 * and the workaround below used to hide it. It should
1757 * be fixed as of version 1.9, but to be on the safe side
1758 * we'll leave the limitation below for the 2.2.x tree.
1761 if (!strncmp(drive
->id
->model
, "IOMEGA ZIP 100 ATAPI", 20)) {
1762 set_bit(IDEFLOPPY_ZIP_DRIVE
, &floppy
->flags
);
1763 /* This value will be visible in the /proc/ide/hdx/settings */
1764 floppy
->ticks
= IDEFLOPPY_TICKS_DELAY
;
1765 blk_queue_max_sectors(drive
->queue
, 64);
1769 * Guess what? The IOMEGA Clik! drive also needs the
1770 * above fix. It makes nasty clicking noises without
1771 * it, so please don't remove this.
1773 if (strncmp(drive
->id
->model
, "IOMEGA Clik!", 11) == 0) {
1774 blk_queue_max_sectors(drive
->queue
, 64);
1775 set_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
);
1779 (void) idefloppy_get_capacity(drive
);
1780 idefloppy_add_settings(drive
);
1783 static void ide_floppy_remove(ide_drive_t
*drive
)
1785 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1786 struct gendisk
*g
= floppy
->disk
;
1788 ide_proc_unregister_driver(drive
, floppy
->driver
);
1792 ide_floppy_put(floppy
);
1795 static void ide_floppy_release(struct kref
*kref
)
1797 struct ide_floppy_obj
*floppy
= to_ide_floppy(kref
);
1798 ide_drive_t
*drive
= floppy
->drive
;
1799 struct gendisk
*g
= floppy
->disk
;
1801 drive
->driver_data
= NULL
;
1802 g
->private_data
= NULL
;
1807 #ifdef CONFIG_IDE_PROC_FS
1808 static int proc_idefloppy_read_capacity
1809 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
1811 ide_drive_t
*drive
= (ide_drive_t
*)data
;
1814 len
= sprintf(page
,"%llu\n", (long long)idefloppy_capacity(drive
));
1815 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
1818 static ide_proc_entry_t idefloppy_proc
[] = {
1819 { "capacity", S_IFREG
|S_IRUGO
, proc_idefloppy_read_capacity
, NULL
},
1820 { "geometry", S_IFREG
|S_IRUGO
, proc_ide_read_geometry
, NULL
},
1821 { NULL
, 0, NULL
, NULL
}
1823 #endif /* CONFIG_IDE_PROC_FS */
1825 static int ide_floppy_probe(ide_drive_t
*);
1827 static ide_driver_t idefloppy_driver
= {
1829 .owner
= THIS_MODULE
,
1830 .name
= "ide-floppy",
1831 .bus
= &ide_bus_type
,
1833 .probe
= ide_floppy_probe
,
1834 .remove
= ide_floppy_remove
,
1835 .version
= IDEFLOPPY_VERSION
,
1836 .media
= ide_floppy
,
1837 .supports_dsc_overlap
= 0,
1838 .do_request
= idefloppy_do_request
,
1839 .end_request
= idefloppy_do_end_request
,
1840 .error
= __ide_error
,
1841 .abort
= __ide_abort
,
1842 #ifdef CONFIG_IDE_PROC_FS
1843 .proc
= idefloppy_proc
,
1847 static int idefloppy_open(struct inode
*inode
, struct file
*filp
)
1849 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1850 struct ide_floppy_obj
*floppy
;
1855 debug_log(KERN_INFO
"Reached idefloppy_open\n");
1857 if (!(floppy
= ide_floppy_get(disk
)))
1860 drive
= floppy
->drive
;
1864 if (floppy
->openers
== 1) {
1865 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1868 idefloppy_create_test_unit_ready_cmd(&pc
);
1869 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1870 idefloppy_create_start_stop_cmd(&pc
, 1);
1871 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1874 if (idefloppy_get_capacity (drive
)
1875 && (filp
->f_flags
& O_NDELAY
) == 0
1877 ** Allow O_NDELAY to open a drive without a disk, or with
1878 ** an unreadable disk, so that we can get the format
1879 ** capacity of the drive or begin the format - Sam
1883 goto out_put_floppy
;
1886 if (floppy
->wp
&& (filp
->f_mode
& 2)) {
1888 goto out_put_floppy
;
1890 set_bit(IDEFLOPPY_MEDIA_CHANGED
, &floppy
->flags
);
1891 /* IOMEGA Clik! drives do not support lock/unlock commands */
1892 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1893 idefloppy_create_prevent_cmd(&pc
, 1);
1894 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1896 check_disk_change(inode
->i_bdev
);
1897 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
)) {
1899 goto out_put_floppy
;
1905 ide_floppy_put(floppy
);
1909 static int idefloppy_release(struct inode
*inode
, struct file
*filp
)
1911 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1912 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
1913 ide_drive_t
*drive
= floppy
->drive
;
1916 debug_log(KERN_INFO
"Reached idefloppy_release\n");
1918 if (floppy
->openers
== 1) {
1919 /* IOMEGA Clik! drives do not support lock/unlock commands */
1920 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1921 idefloppy_create_prevent_cmd(&pc
, 0);
1922 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1925 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1930 ide_floppy_put(floppy
);
1935 static int idefloppy_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
1937 struct ide_floppy_obj
*floppy
= ide_floppy_g(bdev
->bd_disk
);
1938 ide_drive_t
*drive
= floppy
->drive
;
1940 geo
->heads
= drive
->bios_head
;
1941 geo
->sectors
= drive
->bios_sect
;
1942 geo
->cylinders
= (u16
)drive
->bios_cyl
; /* truncate */
1946 static int idefloppy_ioctl(struct inode
*inode
, struct file
*file
,
1947 unsigned int cmd
, unsigned long arg
)
1949 struct block_device
*bdev
= inode
->i_bdev
;
1950 struct ide_floppy_obj
*floppy
= ide_floppy_g(bdev
->bd_disk
);
1951 ide_drive_t
*drive
= floppy
->drive
;
1952 void __user
*argp
= (void __user
*)arg
;
1954 int prevent
= (arg
) ? 1 : 0;
1961 case CDROM_LOCKDOOR
:
1962 if (floppy
->openers
> 1)
1965 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */
1966 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1967 idefloppy_create_prevent_cmd(&pc
, prevent
);
1968 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1970 if (cmd
== CDROMEJECT
) {
1971 idefloppy_create_start_stop_cmd(&pc
, 2);
1972 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1975 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED
:
1977 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY
:
1978 return idefloppy_get_format_capacities(drive
, argp
);
1979 case IDEFLOPPY_IOCTL_FORMAT_START
:
1981 if (!(file
->f_mode
& 2))
1984 if (floppy
->openers
> 1) {
1985 /* Don't format if someone is using the disk */
1987 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
,
1992 set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1994 err
= idefloppy_begin_format(drive
, argp
);
1996 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1999 ** Note, the bit will be cleared when the device is
2000 ** closed. This is the cleanest way to handle the
2001 ** situation where the drive does not support
2002 ** format progress reporting.
2004 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS
:
2005 return idefloppy_get_format_progress(drive
, argp
);
2009 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
2010 * and CDROM_SEND_PACKET (legacy) ioctls
2012 if (cmd
!= CDROM_SEND_PACKET
&& cmd
!= SCSI_IOCTL_SEND_COMMAND
)
2013 err
= scsi_cmd_ioctl(file
, bdev
->bd_disk
->queue
,
2014 bdev
->bd_disk
, cmd
, argp
);
2019 err
= generic_ide_ioctl(drive
, file
, bdev
, cmd
, arg
);
2024 static int idefloppy_media_changed(struct gendisk
*disk
)
2026 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
2027 ide_drive_t
*drive
= floppy
->drive
;
2029 /* do not scan partitions twice if this is a removable device */
2030 if (drive
->attach
) {
2034 return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED
, &floppy
->flags
);
2037 static int idefloppy_revalidate_disk(struct gendisk
*disk
)
2039 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
2040 set_capacity(disk
, idefloppy_capacity(floppy
->drive
));
2044 static struct block_device_operations idefloppy_ops
= {
2045 .owner
= THIS_MODULE
,
2046 .open
= idefloppy_open
,
2047 .release
= idefloppy_release
,
2048 .ioctl
= idefloppy_ioctl
,
2049 .getgeo
= idefloppy_getgeo
,
2050 .media_changed
= idefloppy_media_changed
,
2051 .revalidate_disk
= idefloppy_revalidate_disk
2054 static int ide_floppy_probe(ide_drive_t
*drive
)
2056 idefloppy_floppy_t
*floppy
;
2059 if (!strstr("ide-floppy", drive
->driver_req
))
2061 if (!drive
->present
)
2063 if (drive
->media
!= ide_floppy
)
2065 if (!idefloppy_identify_device (drive
, drive
->id
)) {
2066 printk (KERN_ERR
"ide-floppy: %s: not supported by this version of ide-floppy\n", drive
->name
);
2070 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive
->name
);
2073 if ((floppy
= kzalloc(sizeof (idefloppy_floppy_t
), GFP_KERNEL
)) == NULL
) {
2074 printk (KERN_ERR
"ide-floppy: %s: Can't allocate a floppy structure\n", drive
->name
);
2078 g
= alloc_disk(1 << PARTN_BITS
);
2080 goto out_free_floppy
;
2082 ide_init_disk(g
, drive
);
2084 ide_proc_register_driver(drive
, &idefloppy_driver
);
2086 kref_init(&floppy
->kref
);
2088 floppy
->drive
= drive
;
2089 floppy
->driver
= &idefloppy_driver
;
2092 g
->private_data
= &floppy
->driver
;
2094 drive
->driver_data
= floppy
;
2096 idefloppy_setup (drive
, floppy
);
2098 g
->minors
= 1 << PARTN_BITS
;
2099 g
->driverfs_dev
= &drive
->gendev
;
2100 g
->flags
= drive
->removable
? GENHD_FL_REMOVABLE
: 0;
2101 g
->fops
= &idefloppy_ops
;
2112 MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
2114 static void __exit
idefloppy_exit (void)
2116 driver_unregister(&idefloppy_driver
.gen_driver
);
2119 static int __init
idefloppy_init(void)
2121 printk("ide-floppy driver " IDEFLOPPY_VERSION
"\n");
2122 return driver_register(&idefloppy_driver
.gen_driver
);
2125 MODULE_ALIAS("ide:*m-floppy*");
2126 module_init(idefloppy_init
);
2127 module_exit(idefloppy_exit
);
2128 MODULE_LICENSE("GPL");