2 * linux/drivers/ide/ide-floppy.c Version 0.99 Feb 24 2002
4 * Copyright (C) 1996 - 1999 Gadi Oxman <gadio@netvision.net.il>
5 * Copyright (C) 2000 - 2002 Paul Bristow <paul@paulbristow.net>
9 * IDE ATAPI floppy driver.
11 * The driver currently doesn't have any fancy features, just the bare
12 * minimum read/write support.
14 * This driver supports the following IDE floppy drives:
16 * LS-120/240 SuperDisk
18 * Iomega PC Card Clik!/PocketZip
20 * Many thanks to Lode Leroy <Lode.Leroy@www.ibase.be>, who tested so many
21 * ALPHA patches to this driver on an EASYSTOR LS-120 ATAPI floppy drive.
23 * Ver 0.1 Oct 17 96 Initial test version, mostly based on ide-tape.c.
24 * Ver 0.2 Oct 31 96 Minor changes.
25 * Ver 0.3 Dec 2 96 Fixed error recovery bug.
26 * Ver 0.4 Jan 26 97 Add support for the HDIO_GETGEO ioctl.
27 * Ver 0.5 Feb 21 97 Add partitions support.
28 * Use the minimum of the LBA and CHS capacities.
29 * Avoid hwgroup->rq == NULL on the last irq.
30 * Fix potential null dereferencing with DEBUG_LOG.
31 * Ver 0.8 Dec 7 97 Increase irq timeout from 10 to 50 seconds.
32 * Add media write-protect detection.
33 * Issue START command only if TEST UNIT READY fails.
34 * Add work-around for IOMEGA ZIP revision 21.D.
35 * Remove idefloppy_get_capabilities().
36 * Ver 0.9 Jul 4 99 Fix a bug which might have caused the number of
37 * bytes requested on each interrupt to be zero.
38 * Thanks to <shanos@es.co.nz> for pointing this out.
39 * Ver 0.9.sv Jan 6 01 Sam Varshavchik <mrsam@courier-mta.com>
40 * Implement low level formatting. Reimplemented
41 * IDEFLOPPY_CAPABILITIES_PAGE, since we need the srfp
42 * bit. My LS-120 drive barfs on
43 * IDEFLOPPY_CAPABILITIES_PAGE, but maybe it's just me.
44 * Compromise by not reporting a failure to get this
45 * mode page. Implemented four IOCTLs in order to
46 * implement formatting. IOCTls begin with 0x4600,
47 * 0x46 is 'F' as in Format.
48 * Jan 9 01 Userland option to select format verify.
49 * Added PC_SUPPRESS_ERROR flag - some idefloppy drives
50 * do not implement IDEFLOPPY_CAPABILITIES_PAGE, and
51 * return a sense error. Suppress error reporting in
52 * this particular case in order to avoid spurious
53 * errors in syslog. The culprit is
54 * idefloppy_get_capability_page(), so move it to
55 * idefloppy_begin_format() so that it's not used
56 * unless absolutely necessary.
57 * If drive does not support format progress indication
58 * monitor the dsc bit in the status register.
59 * Also, O_NDELAY on open will allow the device to be
60 * opened without a disk available. This can be used to
61 * open an unformatted disk, or get the device capacity.
62 * Ver 0.91 Dec 11 99 Added IOMEGA Clik! drive support by
63 * <paul@paulbristow.net>
64 * Ver 0.92 Oct 22 00 Paul Bristow became official maintainer for this
65 * driver. Included Powerbook internal zip kludge.
66 * Ver 0.93 Oct 24 00 Fixed bugs for Clik! drive
67 * no disk on insert and disk change now works
68 * Ver 0.94 Oct 27 00 Tidied up to remove strstr(Clik) everywhere
69 * Ver 0.95 Nov 7 00 Brought across to kernel 2.4
70 * Ver 0.96 Jan 7 01 Actually in line with release version of 2.4.0
71 * including set_bit patch from Rusty Russell
72 * Ver 0.97 Jul 22 01 Merge 0.91-0.96 onto 0.9.sv for ac series
73 * Ver 0.97.sv Aug 3 01 Backported from 2.4.7-ac3
74 * Ver 0.98 Oct 26 01 Split idefloppy_transfer_pc into two pieces to
75 * fix a lost interrupt problem. It appears the busy
76 * bit was being deasserted by my IOMEGA ATAPI ZIP 100
77 * drive before the drive was actually ready.
78 * Ver 0.98a Oct 29 01 Expose delay value so we can play.
79 * Ver 0.99 Feb 24 02 Remove duplicate code, modify clik! detection code
80 * to support new PocketZip drives
83 #define IDEFLOPPY_VERSION "0.99.newide"
85 #include <linux/module.h>
86 #include <linux/types.h>
87 #include <linux/string.h>
88 #include <linux/kernel.h>
89 #include <linux/delay.h>
90 #include <linux/timer.h>
92 #include <linux/interrupt.h>
93 #include <linux/major.h>
94 #include <linux/errno.h>
95 #include <linux/genhd.h>
96 #include <linux/slab.h>
97 #include <linux/cdrom.h>
98 #include <linux/ide.h>
99 #include <linux/bitops.h>
100 #include <linux/mutex.h>
102 #include <scsi/scsi_ioctl.h>
104 #include <asm/byteorder.h>
106 #include <asm/uaccess.h>
108 #include <asm/unaligned.h>
111 * The following are used to debug the driver.
113 #define IDEFLOPPY_DEBUG_LOG 0
114 #define IDEFLOPPY_DEBUG_INFO 0
115 #define IDEFLOPPY_DEBUG_BUGS 1
117 /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
118 #define IDEFLOPPY_DEBUG( fmt, args... )
120 #if IDEFLOPPY_DEBUG_LOG
121 #define debug_log printk
123 #define debug_log(fmt, args... ) do {} while(0)
128 * Some drives require a longer irq timeout.
130 #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
133 * After each failed packet command we issue a request sense command
134 * and retry the packet command IDEFLOPPY_MAX_PC_RETRIES times.
136 #define IDEFLOPPY_MAX_PC_RETRIES 3
139 * With each packet command, we allocate a buffer of
140 * IDEFLOPPY_PC_BUFFER_SIZE bytes.
142 #define IDEFLOPPY_PC_BUFFER_SIZE 256
145 * In various places in the driver, we need to allocate storage
146 * for packet commands and requests, which will remain valid while
147 * we leave the driver to wait for an interrupt or a timeout event.
149 #define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
152 * Our view of a packet command.
154 typedef struct idefloppy_packet_command_s
{
155 u8 c
[12]; /* Actual packet bytes */
156 int retries
; /* On each retry, we increment retries */
157 int error
; /* Error code */
158 int request_transfer
; /* Bytes to transfer */
159 int actually_transferred
; /* Bytes actually transferred */
160 int buffer_size
; /* Size of our data buffer */
161 int b_count
; /* Missing/Available data on the current buffer */
162 struct request
*rq
; /* The corresponding request */
163 u8
*buffer
; /* Data buffer */
164 u8
*current_position
; /* Pointer into the above buffer */
165 void (*callback
) (ide_drive_t
*); /* Called when this packet command is completed */
166 u8 pc_buffer
[IDEFLOPPY_PC_BUFFER_SIZE
]; /* Temporary buffer */
167 unsigned long flags
; /* Status/Action bit flags: long for set_bit */
171 * Packet command flag bits.
173 #define PC_ABORT 0 /* Set when an error is considered normal - We won't retry */
174 #define PC_DMA_RECOMMENDED 2 /* 1 when we prefer to use DMA if possible */
175 #define PC_DMA_IN_PROGRESS 3 /* 1 while DMA in progress */
176 #define PC_DMA_ERROR 4 /* 1 when encountered problem during DMA */
177 #define PC_WRITING 5 /* Data direction */
179 #define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */
182 * Removable Block Access Capabilities Page
185 #if defined(__LITTLE_ENDIAN_BITFIELD)
186 unsigned page_code
:6; /* Page code - Should be 0x1b */
187 unsigned reserved1_6
:1; /* Reserved */
188 unsigned ps
:1; /* Should be 0 */
189 #elif defined(__BIG_ENDIAN_BITFIELD)
190 unsigned ps
:1; /* Should be 0 */
191 unsigned reserved1_6
:1; /* Reserved */
192 unsigned page_code
:6; /* Page code - Should be 0x1b */
194 #error "Bitfield endianness not defined! Check your byteorder.h"
196 u8 page_length
; /* Page Length - Should be 0xa */
197 #if defined(__LITTLE_ENDIAN_BITFIELD)
198 unsigned reserved2
:6;
199 unsigned srfp
:1; /* Supports reporting progress of format */
200 unsigned sflp
:1; /* System floppy type device */
201 unsigned tlun
:3; /* Total logical units supported by the device */
202 unsigned reserved3
:3;
203 unsigned sml
:1; /* Single / Multiple lun supported */
204 unsigned ncd
:1; /* Non cd optical device */
205 #elif defined(__BIG_ENDIAN_BITFIELD)
206 unsigned sflp
:1; /* System floppy type device */
207 unsigned srfp
:1; /* Supports reporting progress of format */
208 unsigned reserved2
:6;
209 unsigned ncd
:1; /* Non cd optical device */
210 unsigned sml
:1; /* Single / Multiple lun supported */
211 unsigned reserved3
:3;
212 unsigned tlun
:3; /* Total logical units supported by the device */
214 #error "Bitfield endianness not defined! Check your byteorder.h"
217 } idefloppy_capabilities_page_t
;
220 * Flexible disk page.
223 #if defined(__LITTLE_ENDIAN_BITFIELD)
224 unsigned page_code
:6; /* Page code - Should be 0x5 */
225 unsigned reserved1_6
:1; /* Reserved */
226 unsigned ps
:1; /* The device is capable of saving the page */
227 #elif defined(__BIG_ENDIAN_BITFIELD)
228 unsigned ps
:1; /* The device is capable of saving the page */
229 unsigned reserved1_6
:1; /* Reserved */
230 unsigned page_code
:6; /* Page code - Should be 0x5 */
232 #error "Bitfield endianness not defined! Check your byteorder.h"
234 u8 page_length
; /* Page Length - Should be 0x1e */
235 u16 transfer_rate
; /* In kilobits per second */
236 u8 heads
, sectors
; /* Number of heads, Number of sectors per track */
237 u16 sector_size
; /* Byes per sector */
238 u16 cyls
; /* Number of cylinders */
240 u8 motor_delay
; /* Motor off delay */
242 u16 rpm
; /* Rotations per minute */
244 } idefloppy_flexible_disk_page_t
;
251 u8 length
; /* Length of the following descriptors in bytes */
252 } idefloppy_capacity_header_t
;
255 u32 blocks
; /* Number of blocks */
256 #if defined(__LITTLE_ENDIAN_BITFIELD)
257 unsigned dc
:2; /* Descriptor Code */
258 unsigned reserved
:6;
259 #elif defined(__BIG_ENDIAN_BITFIELD)
260 unsigned reserved
:6;
261 unsigned dc
:2; /* Descriptor Code */
263 #error "Bitfield endianness not defined! Check your byteorder.h"
265 u8 length_msb
; /* Block Length (MSB)*/
266 u16 length
; /* Block Length */
267 } idefloppy_capacity_descriptor_t
;
269 #define CAPACITY_INVALID 0x00
270 #define CAPACITY_UNFORMATTED 0x01
271 #define CAPACITY_CURRENT 0x02
272 #define CAPACITY_NO_CARTRIDGE 0x03
275 * Most of our global data which we need to save even as we leave the
276 * driver due to an interrupt or a timer event is stored in a variable
277 * of type idefloppy_floppy_t, defined below.
279 typedef struct ide_floppy_obj
{
281 ide_driver_t
*driver
;
282 struct gendisk
*disk
;
284 unsigned int openers
; /* protected by BKL for now */
286 /* Current packet command */
288 /* Last failed packet command */
289 idefloppy_pc_t
*failed_pc
;
290 /* Packet command stack */
291 idefloppy_pc_t pc_stack
[IDEFLOPPY_PC_STACK
];
292 /* Next free packet command storage space */
294 struct request rq_stack
[IDEFLOPPY_PC_STACK
];
295 /* We implement a circular array */
299 * Last error information
301 u8 sense_key
, asc
, ascq
;
302 /* delay this long before sending packet command */
304 int progress_indication
;
310 int blocks
, block_size
, bs_factor
;
311 /* Last format capacity */
312 idefloppy_capacity_descriptor_t capacity
;
313 /* Copy of the flexible disk page */
314 idefloppy_flexible_disk_page_t flexible_disk_page
;
317 /* Supports format progress report */
319 /* Status/Action flags */
321 } idefloppy_floppy_t
;
323 #define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
326 * Floppy flag bits values.
328 #define IDEFLOPPY_DRQ_INTERRUPT 0 /* DRQ interrupt device */
329 #define IDEFLOPPY_MEDIA_CHANGED 1 /* Media may have changed */
330 #define IDEFLOPPY_USE_READ12 2 /* Use READ12/WRITE12 or READ10/WRITE10 */
331 #define IDEFLOPPY_FORMAT_IN_PROGRESS 3 /* Format in progress */
332 #define IDEFLOPPY_CLIK_DRIVE 4 /* Avoid commands not supported in Clik drive */
333 #define IDEFLOPPY_ZIP_DRIVE 5 /* Requires BH algorithm for packets */
336 * ATAPI floppy drive packet commands
338 #define IDEFLOPPY_FORMAT_UNIT_CMD 0x04
339 #define IDEFLOPPY_INQUIRY_CMD 0x12
340 #define IDEFLOPPY_MODE_SELECT_CMD 0x55
341 #define IDEFLOPPY_MODE_SENSE_CMD 0x5a
342 #define IDEFLOPPY_READ10_CMD 0x28
343 #define IDEFLOPPY_READ12_CMD 0xa8
344 #define IDEFLOPPY_READ_CAPACITY_CMD 0x23
345 #define IDEFLOPPY_REQUEST_SENSE_CMD 0x03
346 #define IDEFLOPPY_PREVENT_REMOVAL_CMD 0x1e
347 #define IDEFLOPPY_SEEK_CMD 0x2b
348 #define IDEFLOPPY_START_STOP_CMD 0x1b
349 #define IDEFLOPPY_TEST_UNIT_READY_CMD 0x00
350 #define IDEFLOPPY_VERIFY_CMD 0x2f
351 #define IDEFLOPPY_WRITE10_CMD 0x2a
352 #define IDEFLOPPY_WRITE12_CMD 0xaa
353 #define IDEFLOPPY_WRITE_VERIFY_CMD 0x2e
356 * Defines for the mode sense command
358 #define MODE_SENSE_CURRENT 0x00
359 #define MODE_SENSE_CHANGEABLE 0x01
360 #define MODE_SENSE_DEFAULT 0x02
361 #define MODE_SENSE_SAVED 0x03
364 * IOCTLs used in low-level formatting.
367 #define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
368 #define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
369 #define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
370 #define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
373 * Error codes which are returned in rq->errors to the higher part
376 #define IDEFLOPPY_ERROR_GENERAL 101
379 * The following is used to format the general configuration word of
380 * the ATAPI IDENTIFY DEVICE command.
382 struct idefloppy_id_gcw
{
383 #if defined(__LITTLE_ENDIAN_BITFIELD)
384 unsigned packet_size
:2; /* Packet Size */
385 unsigned reserved234
:3; /* Reserved */
386 unsigned drq_type
:2; /* Command packet DRQ type */
387 unsigned removable
:1; /* Removable media */
388 unsigned device_type
:5; /* Device type */
389 unsigned reserved13
:1; /* Reserved */
390 unsigned protocol
:2; /* Protocol type */
391 #elif defined(__BIG_ENDIAN_BITFIELD)
392 unsigned protocol
:2; /* Protocol type */
393 unsigned reserved13
:1; /* Reserved */
394 unsigned device_type
:5; /* Device type */
395 unsigned removable
:1; /* Removable media */
396 unsigned drq_type
:2; /* Command packet DRQ type */
397 unsigned reserved234
:3; /* Reserved */
398 unsigned packet_size
:2; /* Packet Size */
400 #error "Bitfield endianness not defined! Check your byteorder.h"
405 * INQUIRY packet command - Data Format
408 #if defined(__LITTLE_ENDIAN_BITFIELD)
409 unsigned device_type
:5; /* Peripheral Device Type */
410 unsigned reserved0_765
:3; /* Peripheral Qualifier - Reserved */
411 unsigned reserved1_6t0
:7; /* Reserved */
412 unsigned rmb
:1; /* Removable Medium Bit */
413 unsigned ansi_version
:3; /* ANSI Version */
414 unsigned ecma_version
:3; /* ECMA Version */
415 unsigned iso_version
:2; /* ISO Version */
416 unsigned response_format
:4; /* Response Data Format */
417 unsigned reserved3_45
:2; /* Reserved */
418 unsigned reserved3_6
:1; /* TrmIOP - Reserved */
419 unsigned reserved3_7
:1; /* AENC - Reserved */
420 #elif defined(__BIG_ENDIAN_BITFIELD)
421 unsigned reserved0_765
:3; /* Peripheral Qualifier - Reserved */
422 unsigned device_type
:5; /* Peripheral Device Type */
423 unsigned rmb
:1; /* Removable Medium Bit */
424 unsigned reserved1_6t0
:7; /* Reserved */
425 unsigned iso_version
:2; /* ISO Version */
426 unsigned ecma_version
:3; /* ECMA Version */
427 unsigned ansi_version
:3; /* ANSI Version */
428 unsigned reserved3_7
:1; /* AENC - Reserved */
429 unsigned reserved3_6
:1; /* TrmIOP - Reserved */
430 unsigned reserved3_45
:2; /* Reserved */
431 unsigned response_format
:4; /* Response Data Format */
433 #error "Bitfield endianness not defined! Check your byteorder.h"
435 u8 additional_length
; /* Additional Length (total_length-4) */
436 u8 rsv5
, rsv6
, rsv7
; /* Reserved */
437 u8 vendor_id
[8]; /* Vendor Identification */
438 u8 product_id
[16]; /* Product Identification */
439 u8 revision_level
[4]; /* Revision Level */
440 u8 vendor_specific
[20]; /* Vendor Specific - Optional */
441 u8 reserved56t95
[40]; /* Reserved - Optional */
442 /* Additional information may be returned */
443 } idefloppy_inquiry_result_t
;
446 * REQUEST SENSE packet command result - Data Format.
449 #if defined(__LITTLE_ENDIAN_BITFIELD)
450 unsigned error_code
:7; /* Current error (0x70) */
451 unsigned valid
:1; /* The information field conforms to SFF-8070i */
452 u8 reserved1
:8; /* Reserved */
453 unsigned sense_key
:4; /* Sense Key */
454 unsigned reserved2_4
:1; /* Reserved */
455 unsigned ili
:1; /* Incorrect Length Indicator */
456 unsigned reserved2_67
:2;
457 #elif defined(__BIG_ENDIAN_BITFIELD)
458 unsigned valid
:1; /* The information field conforms to SFF-8070i */
459 unsigned error_code
:7; /* Current error (0x70) */
460 u8 reserved1
:8; /* Reserved */
461 unsigned reserved2_67
:2;
462 unsigned ili
:1; /* Incorrect Length Indicator */
463 unsigned reserved2_4
:1; /* Reserved */
464 unsigned sense_key
:4; /* Sense Key */
466 #error "Bitfield endianness not defined! Check your byteorder.h"
468 u32 information
__attribute__ ((packed
));
469 u8 asl
; /* Additional sense length (n-7) */
470 u32 command_specific
; /* Additional command specific information */
471 u8 asc
; /* Additional Sense Code */
472 u8 ascq
; /* Additional Sense Code Qualifier */
473 u8 replaceable_unit_code
; /* Field Replaceable Unit Code */
475 u8 pad
[2]; /* Padding to 20 bytes */
476 } idefloppy_request_sense_result_t
;
479 * Pages of the SELECT SENSE / MODE SENSE packet commands.
481 #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
482 #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
485 * Mode Parameter Header for the MODE SENSE packet command
488 u16 mode_data_length
; /* Length of the following data transfer */
489 u8 medium_type
; /* Medium Type */
490 #if defined(__LITTLE_ENDIAN_BITFIELD)
491 unsigned reserved3
:7;
492 unsigned wp
:1; /* Write protect */
493 #elif defined(__BIG_ENDIAN_BITFIELD)
494 unsigned wp
:1; /* Write protect */
495 unsigned reserved3
:7;
497 #error "Bitfield endianness not defined! Check your byteorder.h"
500 } idefloppy_mode_parameter_header_t
;
502 static DEFINE_MUTEX(idefloppy_ref_mutex
);
504 #define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
506 #define ide_floppy_g(disk) \
507 container_of((disk)->private_data, struct ide_floppy_obj, driver)
509 static struct ide_floppy_obj
*ide_floppy_get(struct gendisk
*disk
)
511 struct ide_floppy_obj
*floppy
= NULL
;
513 mutex_lock(&idefloppy_ref_mutex
);
514 floppy
= ide_floppy_g(disk
);
516 kref_get(&floppy
->kref
);
517 mutex_unlock(&idefloppy_ref_mutex
);
521 static void ide_floppy_release(struct kref
*);
523 static void ide_floppy_put(struct ide_floppy_obj
*floppy
)
525 mutex_lock(&idefloppy_ref_mutex
);
526 kref_put(&floppy
->kref
, ide_floppy_release
);
527 mutex_unlock(&idefloppy_ref_mutex
);
531 * Too bad. The drive wants to send us data which we are not ready to accept.
532 * Just throw it away.
534 static void idefloppy_discard_data (ide_drive_t
*drive
, unsigned int bcount
)
537 (void) HWIF(drive
)->INB(IDE_DATA_REG
);
540 #if IDEFLOPPY_DEBUG_BUGS
541 static void idefloppy_write_zeros (ide_drive_t
*drive
, unsigned int bcount
)
544 HWIF(drive
)->OUTB(0, IDE_DATA_REG
);
546 #endif /* IDEFLOPPY_DEBUG_BUGS */
550 * idefloppy_do_end_request is used to finish servicing a request.
552 * For read/write requests, we will call ide_end_request to pass to the
555 static int idefloppy_do_end_request(ide_drive_t
*drive
, int uptodate
, int nsecs
)
557 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
558 struct request
*rq
= HWGROUP(drive
)->rq
;
561 debug_log(KERN_INFO
"Reached idefloppy_end_request\n");
564 case 0: error
= IDEFLOPPY_ERROR_GENERAL
; break;
565 case 1: error
= 0; break;
566 default: error
= uptodate
;
569 floppy
->failed_pc
= NULL
;
570 /* Why does this happen? */
573 if (!blk_special_request(rq
)) {
574 /* our real local end request function */
575 ide_end_request(drive
, uptodate
, nsecs
);
579 /* fixme: need to move this local also */
580 ide_end_drive_cmd(drive
, 0, 0);
584 static void idefloppy_input_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
, unsigned int bcount
)
586 struct request
*rq
= pc
->rq
;
587 struct bio_vec
*bvec
;
588 struct req_iterator iter
;
593 rq_for_each_segment(bvec
, rq
, iter
) {
597 count
= min(bvec
->bv_len
, bcount
);
599 data
= bvec_kmap_irq(bvec
, &flags
);
600 drive
->hwif
->atapi_input_bytes(drive
, data
, count
);
601 bvec_kunmap_irq(data
, &flags
);
604 pc
->b_count
+= count
;
608 idefloppy_do_end_request(drive
, 1, done
>> 9);
611 printk(KERN_ERR
"%s: leftover data in idefloppy_input_buffers, bcount == %d\n", drive
->name
, bcount
);
612 idefloppy_discard_data(drive
, bcount
);
616 static void idefloppy_output_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
, unsigned int bcount
)
618 struct request
*rq
= pc
->rq
;
619 struct req_iterator iter
;
620 struct bio_vec
*bvec
;
625 rq_for_each_segment(bvec
, rq
, iter
) {
629 count
= min(bvec
->bv_len
, bcount
);
631 data
= bvec_kmap_irq(bvec
, &flags
);
632 drive
->hwif
->atapi_output_bytes(drive
, data
, count
);
633 bvec_kunmap_irq(data
, &flags
);
636 pc
->b_count
+= count
;
640 idefloppy_do_end_request(drive
, 1, done
>> 9);
642 #if IDEFLOPPY_DEBUG_BUGS
644 printk(KERN_ERR
"%s: leftover data in idefloppy_output_buffers, bcount == %d\n", drive
->name
, bcount
);
645 idefloppy_write_zeros(drive
, bcount
);
650 static void idefloppy_update_buffers (ide_drive_t
*drive
, idefloppy_pc_t
*pc
)
652 struct request
*rq
= pc
->rq
;
653 struct bio
*bio
= rq
->bio
;
655 while ((bio
= rq
->bio
) != NULL
)
656 idefloppy_do_end_request(drive
, 1, 0);
660 * idefloppy_queue_pc_head generates a new packet command request in front
661 * of the request queue, before the current request, so that it will be
662 * processed immediately, on the next pass through the driver.
664 static void idefloppy_queue_pc_head (ide_drive_t
*drive
,idefloppy_pc_t
*pc
,struct request
*rq
)
666 struct ide_floppy_obj
*floppy
= drive
->driver_data
;
668 ide_init_drive_cmd(rq
);
669 rq
->buffer
= (char *) pc
;
670 rq
->cmd_type
= REQ_TYPE_SPECIAL
;
671 rq
->rq_disk
= floppy
->disk
;
672 (void) ide_do_drive_cmd(drive
, rq
, ide_preempt
);
675 static idefloppy_pc_t
*idefloppy_next_pc_storage (ide_drive_t
*drive
)
677 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
679 if (floppy
->pc_stack_index
== IDEFLOPPY_PC_STACK
)
680 floppy
->pc_stack_index
=0;
681 return (&floppy
->pc_stack
[floppy
->pc_stack_index
++]);
684 static struct request
*idefloppy_next_rq_storage (ide_drive_t
*drive
)
686 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
688 if (floppy
->rq_stack_index
== IDEFLOPPY_PC_STACK
)
689 floppy
->rq_stack_index
= 0;
690 return (&floppy
->rq_stack
[floppy
->rq_stack_index
++]);
694 * idefloppy_analyze_error is called on each failed packet command retry
695 * to analyze the request sense.
697 static void idefloppy_analyze_error (ide_drive_t
*drive
,idefloppy_request_sense_result_t
*result
)
699 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
701 floppy
->sense_key
= result
->sense_key
;
702 floppy
->asc
= result
->asc
;
703 floppy
->ascq
= result
->ascq
;
704 floppy
->progress_indication
= result
->sksv
[0] & 0x80 ?
705 (u16
)get_unaligned((u16
*)(result
->sksv
+1)):0x10000;
706 if (floppy
->failed_pc
)
707 debug_log(KERN_INFO
"ide-floppy: pc = %x, sense key = %x, "
708 "asc = %x, ascq = %x\n", floppy
->failed_pc
->c
[0],
709 result
->sense_key
, result
->asc
, result
->ascq
);
711 debug_log(KERN_INFO
"ide-floppy: sense key = %x, asc = %x, "
712 "ascq = %x\n", result
->sense_key
,
713 result
->asc
, result
->ascq
);
716 static void idefloppy_request_sense_callback (ide_drive_t
*drive
)
718 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
720 debug_log(KERN_INFO
"ide-floppy: Reached %s\n", __FUNCTION__
);
722 if (!floppy
->pc
->error
) {
723 idefloppy_analyze_error(drive
,(idefloppy_request_sense_result_t
*) floppy
->pc
->buffer
);
724 idefloppy_do_end_request(drive
, 1, 0);
726 printk(KERN_ERR
"Error in REQUEST SENSE itself - Aborting request!\n");
727 idefloppy_do_end_request(drive
, 0, 0);
732 * General packet command callback function.
734 static void idefloppy_pc_callback (ide_drive_t
*drive
)
736 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
738 debug_log(KERN_INFO
"ide-floppy: Reached %s\n", __FUNCTION__
);
740 idefloppy_do_end_request(drive
, floppy
->pc
->error
? 0 : 1, 0);
744 * idefloppy_init_pc initializes a packet command.
746 static void idefloppy_init_pc (idefloppy_pc_t
*pc
)
748 memset(pc
->c
, 0, 12);
751 pc
->request_transfer
= 0;
752 pc
->buffer
= pc
->pc_buffer
;
753 pc
->buffer_size
= IDEFLOPPY_PC_BUFFER_SIZE
;
754 pc
->callback
= &idefloppy_pc_callback
;
757 static void idefloppy_create_request_sense_cmd (idefloppy_pc_t
*pc
)
759 idefloppy_init_pc(pc
);
760 pc
->c
[0] = IDEFLOPPY_REQUEST_SENSE_CMD
;
762 pc
->request_transfer
= 18;
763 pc
->callback
= &idefloppy_request_sense_callback
;
767 * idefloppy_retry_pc is called when an error was detected during the
768 * last packet command. We queue a request sense packet command in
769 * the head of the request list.
771 static void idefloppy_retry_pc (ide_drive_t
*drive
)
776 (void)drive
->hwif
->INB(IDE_ERROR_REG
);
777 pc
= idefloppy_next_pc_storage(drive
);
778 rq
= idefloppy_next_rq_storage(drive
);
779 idefloppy_create_request_sense_cmd(pc
);
780 idefloppy_queue_pc_head(drive
, pc
, rq
);
784 * idefloppy_pc_intr is the usual interrupt handler which will be called
785 * during a packet command.
787 static ide_startstop_t
idefloppy_pc_intr (ide_drive_t
*drive
)
789 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
790 ide_hwif_t
*hwif
= drive
->hwif
;
791 idefloppy_pc_t
*pc
= floppy
->pc
;
792 struct request
*rq
= pc
->rq
;
797 debug_log(KERN_INFO
"ide-floppy: Reached %s interrupt handler\n",
800 if (test_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
)) {
801 if (HWIF(drive
)->ide_dma_end(drive
)) {
802 set_bit(PC_DMA_ERROR
, &pc
->flags
);
804 pc
->actually_transferred
= pc
->request_transfer
;
805 idefloppy_update_buffers(drive
, pc
);
807 debug_log(KERN_INFO
"ide-floppy: DMA finished\n");
810 /* Clear the interrupt */
811 stat
= drive
->hwif
->INB(IDE_STATUS_REG
);
813 if ((stat
& DRQ_STAT
) == 0) { /* No more interrupts */
814 debug_log(KERN_INFO
"Packet command completed, %d bytes "
815 "transferred\n", pc
->actually_transferred
);
816 clear_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
);
818 local_irq_enable_in_hardirq();
820 if ((stat
& ERR_STAT
) || test_bit(PC_DMA_ERROR
, &pc
->flags
)) {
822 debug_log(KERN_INFO
"ide-floppy: %s: I/O error\n",
825 if (pc
->c
[0] == IDEFLOPPY_REQUEST_SENSE_CMD
) {
826 printk(KERN_ERR
"ide-floppy: I/O error in "
827 "request sense command\n");
828 return ide_do_reset(drive
);
830 /* Retry operation */
831 idefloppy_retry_pc(drive
);
832 /* queued, but not started */
836 if (floppy
->failed_pc
== pc
)
837 floppy
->failed_pc
= NULL
;
838 /* Command finished - Call the callback function */
843 if (test_and_clear_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
)) {
844 printk(KERN_ERR
"ide-floppy: The floppy wants to issue "
845 "more interrupts in DMA mode\n");
847 return ide_do_reset(drive
);
850 /* Get the number of bytes to transfer */
851 bcount
= (hwif
->INB(IDE_BCOUNTH_REG
) << 8) |
852 hwif
->INB(IDE_BCOUNTL_REG
);
853 /* on this interrupt */
854 ireason
= hwif
->INB(IDE_IREASON_REG
);
857 printk(KERN_ERR
"ide-floppy: CoD != 0 in idefloppy_pc_intr\n");
858 return ide_do_reset(drive
);
860 if (((ireason
& IO
) == IO
) == test_bit(PC_WRITING
, &pc
->flags
)) {
861 /* Hopefully, we will never get here */
862 printk(KERN_ERR
"ide-floppy: We wanted to %s, ",
863 (ireason
& IO
) ? "Write" : "Read");
864 printk(KERN_ERR
"but the floppy wants us to %s !\n",
865 (ireason
& IO
) ? "Read" : "Write");
866 return ide_do_reset(drive
);
868 if (!test_bit(PC_WRITING
, &pc
->flags
)) {
869 /* Reading - Check that we have enough space */
870 temp
= pc
->actually_transferred
+ bcount
;
871 if (temp
> pc
->request_transfer
) {
872 if (temp
> pc
->buffer_size
) {
873 printk(KERN_ERR
"ide-floppy: The floppy wants "
874 "to send us more data than expected "
875 "- discarding data\n");
876 idefloppy_discard_data(drive
, bcount
);
877 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
878 ide_set_handler(drive
,
884 debug_log(KERN_NOTICE
"ide-floppy: The floppy wants to "
885 "send us more data than expected - "
886 "allowing transfer\n");
889 if (test_bit(PC_WRITING
, &pc
->flags
)) {
890 if (pc
->buffer
!= NULL
)
891 /* Write the current buffer */
892 hwif
->atapi_output_bytes(drive
, pc
->current_position
,
895 idefloppy_output_buffers(drive
, pc
, bcount
);
897 if (pc
->buffer
!= NULL
)
898 /* Read the current buffer */
899 hwif
->atapi_input_bytes(drive
, pc
->current_position
,
902 idefloppy_input_buffers(drive
, pc
, bcount
);
904 /* Update the current position */
905 pc
->actually_transferred
+= bcount
;
906 pc
->current_position
+= bcount
;
908 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
909 ide_set_handler(drive
, &idefloppy_pc_intr
, IDEFLOPPY_WAIT_CMD
, NULL
); /* And set the interrupt handler again */
914 * This is the original routine that did the packet transfer.
915 * It fails at high speeds on the Iomega ZIP drive, so there's a slower version
916 * for that drive below. The algorithm is chosen based on drive type
918 static ide_startstop_t
idefloppy_transfer_pc (ide_drive_t
*drive
)
920 ide_startstop_t startstop
;
921 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
924 if (ide_wait_stat(&startstop
, drive
, DRQ_STAT
, BUSY_STAT
, WAIT_READY
)) {
925 printk(KERN_ERR
"ide-floppy: Strange, packet command "
926 "initiated yet DRQ isn't asserted\n");
929 ireason
= drive
->hwif
->INB(IDE_IREASON_REG
);
930 if ((ireason
& CD
) == 0 || (ireason
& IO
)) {
931 printk(KERN_ERR
"ide-floppy: (IO,CoD) != (0,1) while "
932 "issuing a packet command\n");
933 return ide_do_reset(drive
);
935 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
936 /* Set the interrupt routine */
937 ide_set_handler(drive
, &idefloppy_pc_intr
, IDEFLOPPY_WAIT_CMD
, NULL
);
938 /* Send the actual packet */
939 HWIF(drive
)->atapi_output_bytes(drive
, floppy
->pc
->c
, 12);
945 * What we have here is a classic case of a top half / bottom half
946 * interrupt service routine. In interrupt mode, the device sends
947 * an interrupt to signal it's ready to receive a packet. However,
948 * we need to delay about 2-3 ticks before issuing the packet or we
951 * So, follow carefully. transfer_pc1 is called as an interrupt (or
952 * directly). In either case, when the device says it's ready for a
953 * packet, we schedule the packet transfer to occur about 2-3 ticks
954 * later in transfer_pc2.
956 static int idefloppy_transfer_pc2 (ide_drive_t
*drive
)
958 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
960 /* Send the actual packet */
961 HWIF(drive
)->atapi_output_bytes(drive
, floppy
->pc
->c
, 12);
962 /* Timeout for the packet command */
963 return IDEFLOPPY_WAIT_CMD
;
966 static ide_startstop_t
idefloppy_transfer_pc1 (ide_drive_t
*drive
)
968 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
969 ide_startstop_t startstop
;
972 if (ide_wait_stat(&startstop
, drive
, DRQ_STAT
, BUSY_STAT
, WAIT_READY
)) {
973 printk(KERN_ERR
"ide-floppy: Strange, packet command "
974 "initiated yet DRQ isn't asserted\n");
977 ireason
= drive
->hwif
->INB(IDE_IREASON_REG
);
978 if ((ireason
& CD
) == 0 || (ireason
& IO
)) {
979 printk(KERN_ERR
"ide-floppy: (IO,CoD) != (0,1) "
980 "while issuing a packet command\n");
981 return ide_do_reset(drive
);
984 * The following delay solves a problem with ATAPI Zip 100 drives
985 * where the Busy flag was apparently being deasserted before the
986 * unit was ready to receive data. This was happening on a
987 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
988 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
989 * used until after the packet is moved in about 50 msec.
991 BUG_ON(HWGROUP(drive
)->handler
!= NULL
);
992 ide_set_handler(drive
,
993 &idefloppy_pc_intr
, /* service routine for packet command */
994 floppy
->ticks
, /* wait this long before "failing" */
995 &idefloppy_transfer_pc2
); /* fail == transfer_pc2 */
1000 * idefloppy_should_report_error()
1002 * Supresses error messages resulting from Medium not present
1004 static inline int idefloppy_should_report_error(idefloppy_floppy_t
*floppy
)
1006 if (floppy
->sense_key
== 0x02 &&
1007 floppy
->asc
== 0x3a &&
1008 floppy
->ascq
== 0x00)
1014 * Issue a packet command
1016 static ide_startstop_t
idefloppy_issue_pc (ide_drive_t
*drive
, idefloppy_pc_t
*pc
)
1018 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1019 ide_hwif_t
*hwif
= drive
->hwif
;
1020 ide_handler_t
*pkt_xfer_routine
;
1024 if (floppy
->failed_pc
== NULL
&&
1025 pc
->c
[0] != IDEFLOPPY_REQUEST_SENSE_CMD
)
1026 floppy
->failed_pc
= pc
;
1027 /* Set the current packet command */
1030 if (pc
->retries
> IDEFLOPPY_MAX_PC_RETRIES
||
1031 test_bit(PC_ABORT
, &pc
->flags
)) {
1033 * We will "abort" retrying a packet command in case
1034 * a legitimate error code was received.
1036 if (!test_bit(PC_ABORT
, &pc
->flags
)) {
1037 if (!test_bit(PC_SUPPRESS_ERROR
, &pc
->flags
)) {
1038 if (idefloppy_should_report_error(floppy
))
1039 printk(KERN_ERR
"ide-floppy: %s: I/O error, "
1040 "pc = %2x, key = %2x, "
1041 "asc = %2x, ascq = %2x\n",
1042 drive
->name
, pc
->c
[0],
1044 floppy
->asc
, floppy
->ascq
);
1047 pc
->error
= IDEFLOPPY_ERROR_GENERAL
;
1049 floppy
->failed_pc
= NULL
;
1050 pc
->callback(drive
);
1054 debug_log(KERN_INFO
"Retry number - %d\n",pc
->retries
);
1057 /* We haven't transferred any data yet */
1058 pc
->actually_transferred
= 0;
1059 pc
->current_position
= pc
->buffer
;
1060 bcount
= min(pc
->request_transfer
, 63 * 1024);
1062 if (test_and_clear_bit(PC_DMA_ERROR
, &pc
->flags
))
1067 if (test_bit(PC_DMA_RECOMMENDED
, &pc
->flags
) && drive
->using_dma
)
1068 dma
= !hwif
->dma_setup(drive
);
1070 ide_pktcmd_tf_load(drive
, IDE_TFLAG_NO_SELECT_MASK
|
1071 IDE_TFLAG_OUT_DEVICE
, bcount
, dma
);
1073 if (dma
) { /* Begin DMA, if necessary */
1074 set_bit(PC_DMA_IN_PROGRESS
, &pc
->flags
);
1075 hwif
->dma_start(drive
);
1078 /* Can we transfer the packet when we get the interrupt or wait? */
1079 if (test_bit(IDEFLOPPY_ZIP_DRIVE
, &floppy
->flags
)) {
1081 pkt_xfer_routine
= &idefloppy_transfer_pc1
;
1084 pkt_xfer_routine
= &idefloppy_transfer_pc
;
1087 if (test_bit (IDEFLOPPY_DRQ_INTERRUPT
, &floppy
->flags
)) {
1088 /* Issue the packet command */
1089 ide_execute_command(drive
, WIN_PACKETCMD
,
1095 /* Issue the packet command */
1096 HWIF(drive
)->OUTB(WIN_PACKETCMD
, IDE_COMMAND_REG
);
1097 return (*pkt_xfer_routine
) (drive
);
1101 static void idefloppy_rw_callback (ide_drive_t
*drive
)
1103 debug_log(KERN_INFO
"ide-floppy: Reached idefloppy_rw_callback\n");
1105 idefloppy_do_end_request(drive
, 1, 0);
1109 static void idefloppy_create_prevent_cmd (idefloppy_pc_t
*pc
, int prevent
)
1111 debug_log(KERN_INFO
"ide-floppy: creating prevent removal command, "
1112 "prevent = %d\n", prevent
);
1114 idefloppy_init_pc(pc
);
1115 pc
->c
[0] = IDEFLOPPY_PREVENT_REMOVAL_CMD
;
1119 static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t
*pc
)
1121 idefloppy_init_pc(pc
);
1122 pc
->c
[0] = IDEFLOPPY_READ_CAPACITY_CMD
;
1125 pc
->request_transfer
= 255;
1128 static void idefloppy_create_format_unit_cmd (idefloppy_pc_t
*pc
, int b
, int l
,
1131 idefloppy_init_pc(pc
);
1132 pc
->c
[0] = IDEFLOPPY_FORMAT_UNIT_CMD
;
1135 memset(pc
->buffer
, 0, 12);
1136 pc
->buffer
[1] = 0xA2;
1137 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
1139 if (flags
& 1) /* Verify bit on... */
1140 pc
->buffer
[1] ^= 0x20; /* ... turn off DCRT bit */
1143 put_unaligned(htonl(b
), (unsigned int *)(&pc
->buffer
[4]));
1144 put_unaligned(htonl(l
), (unsigned int *)(&pc
->buffer
[8]));
1146 set_bit(PC_WRITING
, &pc
->flags
);
1150 * A mode sense command is used to "sense" floppy parameters.
1152 static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t
*pc
, u8 page_code
, u8 type
)
1154 u16 length
= sizeof(idefloppy_mode_parameter_header_t
);
1156 idefloppy_init_pc(pc
);
1157 pc
->c
[0] = IDEFLOPPY_MODE_SENSE_CMD
;
1159 pc
->c
[2] = page_code
+ (type
<< 6);
1161 switch (page_code
) {
1162 case IDEFLOPPY_CAPABILITIES_PAGE
:
1165 case IDEFLOPPY_FLEXIBLE_DISK_PAGE
:
1169 printk(KERN_ERR
"ide-floppy: unsupported page code "
1170 "in create_mode_sense_cmd\n");
1172 put_unaligned(htons(length
), (u16
*) &pc
->c
[7]);
1173 pc
->request_transfer
= length
;
1176 static void idefloppy_create_start_stop_cmd (idefloppy_pc_t
*pc
, int start
)
1178 idefloppy_init_pc(pc
);
1179 pc
->c
[0] = IDEFLOPPY_START_STOP_CMD
;
1183 static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t
*pc
)
1185 idefloppy_init_pc(pc
);
1186 pc
->c
[0] = IDEFLOPPY_TEST_UNIT_READY_CMD
;
1189 static void idefloppy_create_rw_cmd (idefloppy_floppy_t
*floppy
, idefloppy_pc_t
*pc
, struct request
*rq
, unsigned long sector
)
1191 int block
= sector
/ floppy
->bs_factor
;
1192 int blocks
= rq
->nr_sectors
/ floppy
->bs_factor
;
1193 int cmd
= rq_data_dir(rq
);
1195 debug_log("create_rw1%d_cmd: block == %d, blocks == %d\n",
1196 2 * test_bit (IDEFLOPPY_USE_READ12
, &floppy
->flags
),
1199 idefloppy_init_pc(pc
);
1200 if (test_bit(IDEFLOPPY_USE_READ12
, &floppy
->flags
)) {
1201 pc
->c
[0] = cmd
== READ
? IDEFLOPPY_READ12_CMD
: IDEFLOPPY_WRITE12_CMD
;
1202 put_unaligned(htonl(blocks
), (unsigned int *) &pc
->c
[6]);
1204 pc
->c
[0] = cmd
== READ
? IDEFLOPPY_READ10_CMD
: IDEFLOPPY_WRITE10_CMD
;
1205 put_unaligned(htons(blocks
), (unsigned short *) &pc
->c
[7]);
1207 put_unaligned(htonl(block
), (unsigned int *) &pc
->c
[2]);
1208 pc
->callback
= &idefloppy_rw_callback
;
1210 pc
->b_count
= cmd
== READ
? 0 : rq
->bio
->bi_size
;
1211 if (rq
->cmd_flags
& REQ_RW
)
1212 set_bit(PC_WRITING
, &pc
->flags
);
1214 pc
->request_transfer
= pc
->buffer_size
= blocks
* floppy
->block_size
;
1215 set_bit(PC_DMA_RECOMMENDED
, &pc
->flags
);
1219 idefloppy_blockpc_cmd(idefloppy_floppy_t
*floppy
, idefloppy_pc_t
*pc
, struct request
*rq
)
1221 idefloppy_init_pc(pc
);
1222 pc
->callback
= &idefloppy_rw_callback
;
1223 memcpy(pc
->c
, rq
->cmd
, sizeof(pc
->c
));
1225 pc
->b_count
= rq
->data_len
;
1226 if (rq
->data_len
&& rq_data_dir(rq
) == WRITE
)
1227 set_bit(PC_WRITING
, &pc
->flags
);
1228 pc
->buffer
= rq
->data
;
1230 set_bit(PC_DMA_RECOMMENDED
, &pc
->flags
);
1233 * possibly problematic, doesn't look like ide-floppy correctly
1234 * handled scattered requests if dma fails...
1236 pc
->request_transfer
= pc
->buffer_size
= rq
->data_len
;
1240 * idefloppy_do_request is our request handling function.
1242 static ide_startstop_t
idefloppy_do_request (ide_drive_t
*drive
, struct request
*rq
, sector_t block_s
)
1244 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1246 unsigned long block
= (unsigned long)block_s
;
1248 debug_log(KERN_INFO
"dev: %s, flags: %lx, errors: %d\n",
1249 rq
->rq_disk
? rq
->rq_disk
->disk_name
: "?",
1250 rq
->flags
, rq
->errors
);
1251 debug_log(KERN_INFO
"sector: %ld, nr_sectors: %ld, "
1252 "current_nr_sectors: %d\n", (long)rq
->sector
,
1253 rq
->nr_sectors
, rq
->current_nr_sectors
);
1255 if (rq
->errors
>= ERROR_MAX
) {
1256 if (floppy
->failed_pc
!= NULL
) {
1257 if (idefloppy_should_report_error(floppy
))
1258 printk(KERN_ERR
"ide-floppy: %s: I/O error, pc = %2x,"
1259 " key = %2x, asc = %2x, ascq = %2x\n",
1260 drive
->name
, floppy
->failed_pc
->c
[0],
1261 floppy
->sense_key
, floppy
->asc
, floppy
->ascq
);
1264 printk(KERN_ERR
"ide-floppy: %s: I/O error\n",
1266 idefloppy_do_end_request(drive
, 0, 0);
1269 if (blk_fs_request(rq
)) {
1270 if (((long)rq
->sector
% floppy
->bs_factor
) ||
1271 (rq
->nr_sectors
% floppy
->bs_factor
)) {
1272 printk("%s: unsupported r/w request size\n",
1274 idefloppy_do_end_request(drive
, 0, 0);
1277 pc
= idefloppy_next_pc_storage(drive
);
1278 idefloppy_create_rw_cmd(floppy
, pc
, rq
, block
);
1279 } else if (blk_special_request(rq
)) {
1280 pc
= (idefloppy_pc_t
*) rq
->buffer
;
1281 } else if (blk_pc_request(rq
)) {
1282 pc
= idefloppy_next_pc_storage(drive
);
1283 idefloppy_blockpc_cmd(floppy
, pc
, rq
);
1285 blk_dump_rq_flags(rq
,
1286 "ide-floppy: unsupported command in queue");
1287 idefloppy_do_end_request(drive
, 0, 0);
1292 return idefloppy_issue_pc(drive
, pc
);
1296 * idefloppy_queue_pc_tail adds a special packet command request to the
1297 * tail of the request queue, and waits for it to be serviced.
1299 static int idefloppy_queue_pc_tail (ide_drive_t
*drive
,idefloppy_pc_t
*pc
)
1301 struct ide_floppy_obj
*floppy
= drive
->driver_data
;
1304 ide_init_drive_cmd (&rq
);
1305 rq
.buffer
= (char *) pc
;
1306 rq
.cmd_type
= REQ_TYPE_SPECIAL
;
1307 rq
.rq_disk
= floppy
->disk
;
1309 return ide_do_drive_cmd(drive
, &rq
, ide_wait
);
1313 * Look at the flexible disk page parameters. We will ignore the CHS
1314 * capacity parameters and use the LBA parameters instead.
1316 static int idefloppy_get_flexible_disk_page (ide_drive_t
*drive
)
1318 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1320 idefloppy_mode_parameter_header_t
*header
;
1321 idefloppy_flexible_disk_page_t
*page
;
1322 int capacity
, lba_capacity
;
1324 idefloppy_create_mode_sense_cmd(&pc
, IDEFLOPPY_FLEXIBLE_DISK_PAGE
, MODE_SENSE_CURRENT
);
1325 if (idefloppy_queue_pc_tail(drive
,&pc
)) {
1326 printk(KERN_ERR
"ide-floppy: Can't get flexible disk "
1327 "page parameters\n");
1330 header
= (idefloppy_mode_parameter_header_t
*) pc
.buffer
;
1331 floppy
->wp
= header
->wp
;
1332 set_disk_ro(floppy
->disk
, floppy
->wp
);
1333 page
= (idefloppy_flexible_disk_page_t
*) (header
+ 1);
1335 page
->transfer_rate
= ntohs(page
->transfer_rate
);
1336 page
->sector_size
= ntohs(page
->sector_size
);
1337 page
->cyls
= ntohs(page
->cyls
);
1338 page
->rpm
= ntohs(page
->rpm
);
1339 capacity
= page
->cyls
* page
->heads
* page
->sectors
* page
->sector_size
;
1340 if (memcmp (page
, &floppy
->flexible_disk_page
, sizeof (idefloppy_flexible_disk_page_t
)))
1341 printk(KERN_INFO
"%s: %dkB, %d/%d/%d CHS, %d kBps, "
1342 "%d sector size, %d rpm\n",
1343 drive
->name
, capacity
/ 1024, page
->cyls
,
1344 page
->heads
, page
->sectors
,
1345 page
->transfer_rate
/ 8, page
->sector_size
, page
->rpm
);
1347 floppy
->flexible_disk_page
= *page
;
1348 drive
->bios_cyl
= page
->cyls
;
1349 drive
->bios_head
= page
->heads
;
1350 drive
->bios_sect
= page
->sectors
;
1351 lba_capacity
= floppy
->blocks
* floppy
->block_size
;
1352 if (capacity
< lba_capacity
) {
1353 printk(KERN_NOTICE
"%s: The disk reports a capacity of %d "
1354 "bytes, but the drive only handles %d\n",
1355 drive
->name
, lba_capacity
, capacity
);
1356 floppy
->blocks
= floppy
->block_size
? capacity
/ floppy
->block_size
: 0;
1361 static int idefloppy_get_capability_page(ide_drive_t
*drive
)
1363 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1365 idefloppy_mode_parameter_header_t
*header
;
1366 idefloppy_capabilities_page_t
*page
;
1369 idefloppy_create_mode_sense_cmd(&pc
, IDEFLOPPY_CAPABILITIES_PAGE
,
1370 MODE_SENSE_CURRENT
);
1372 set_bit(PC_SUPPRESS_ERROR
, &pc
.flags
);
1373 if (idefloppy_queue_pc_tail(drive
,&pc
)) {
1377 header
= (idefloppy_mode_parameter_header_t
*) pc
.buffer
;
1378 page
= (idefloppy_capabilities_page_t
*)(header
+1);
1379 floppy
->srfp
= page
->srfp
;
1384 * Determine if a media is present in the floppy drive, and if so,
1387 static int idefloppy_get_capacity (ide_drive_t
*drive
)
1389 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1391 idefloppy_capacity_header_t
*header
;
1392 idefloppy_capacity_descriptor_t
*descriptor
;
1393 int i
, descriptors
, rc
= 1, blocks
, length
;
1395 drive
->bios_cyl
= 0;
1396 drive
->bios_head
= drive
->bios_sect
= 0;
1398 floppy
->bs_factor
= 1;
1399 set_capacity(floppy
->disk
, 0);
1401 idefloppy_create_read_capacity_cmd(&pc
);
1402 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1403 printk(KERN_ERR
"ide-floppy: Can't get floppy parameters\n");
1406 header
= (idefloppy_capacity_header_t
*) pc
.buffer
;
1407 descriptors
= header
->length
/ sizeof(idefloppy_capacity_descriptor_t
);
1408 descriptor
= (idefloppy_capacity_descriptor_t
*) (header
+ 1);
1410 for (i
= 0; i
< descriptors
; i
++, descriptor
++) {
1411 blocks
= descriptor
->blocks
= ntohl(descriptor
->blocks
);
1412 length
= descriptor
->length
= ntohs(descriptor
->length
);
1416 switch (descriptor
->dc
) {
1417 /* Clik! drive returns this instead of CAPACITY_CURRENT */
1418 case CAPACITY_UNFORMATTED
:
1419 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
))
1421 * If it is not a clik drive, break out
1422 * (maintains previous driver behaviour)
1425 case CAPACITY_CURRENT
:
1426 /* Normal Zip/LS-120 disks */
1427 if (memcmp(descriptor
, &floppy
->capacity
, sizeof (idefloppy_capacity_descriptor_t
)))
1428 printk(KERN_INFO
"%s: %dkB, %d blocks, %d "
1429 "sector size\n", drive
->name
,
1430 blocks
* length
/ 1024, blocks
, length
);
1431 floppy
->capacity
= *descriptor
;
1432 if (!length
|| length
% 512) {
1433 printk(KERN_NOTICE
"%s: %d bytes block size "
1434 "not supported\n", drive
->name
, length
);
1436 floppy
->blocks
= blocks
;
1437 floppy
->block_size
= length
;
1438 if ((floppy
->bs_factor
= length
/ 512) != 1)
1439 printk(KERN_NOTICE
"%s: warning: non "
1440 "512 bytes block size not "
1441 "fully supported\n",
1446 case CAPACITY_NO_CARTRIDGE
:
1448 * This is a KERN_ERR so it appears on screen
1449 * for the user to see
1451 printk(KERN_ERR
"%s: No disk in drive\n", drive
->name
);
1453 case CAPACITY_INVALID
:
1454 printk(KERN_ERR
"%s: Invalid capacity for disk "
1455 "in drive\n", drive
->name
);
1460 debug_log( "Descriptor 0 Code: %d\n",
1463 debug_log( "Descriptor %d: %dkB, %d blocks, %d "
1464 "sector size\n", i
, blocks
* length
/ 1024, blocks
,
1468 /* Clik! disk does not support get_flexible_disk_page */
1469 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1470 (void) idefloppy_get_flexible_disk_page(drive
);
1473 set_capacity(floppy
->disk
, floppy
->blocks
* floppy
->bs_factor
);
1478 ** Obtain the list of formattable capacities.
1479 ** Very similar to idefloppy_get_capacity, except that we push the capacity
1480 ** descriptors to userland, instead of our own structures.
1482 ** Userland gives us the following structure:
1484 ** struct idefloppy_format_capacities {
1492 ** userland initializes nformats to the number of allocated formats[]
1493 ** records. On exit we set nformats to the number of records we've
1494 ** actually initialized.
1498 static int idefloppy_get_format_capacities(ide_drive_t
*drive
, int __user
*arg
)
1501 idefloppy_capacity_header_t
*header
;
1502 idefloppy_capacity_descriptor_t
*descriptor
;
1503 int i
, descriptors
, blocks
, length
;
1508 if (get_user(u_array_size
, arg
))
1511 if (u_array_size
<= 0)
1514 idefloppy_create_read_capacity_cmd(&pc
);
1515 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1516 printk(KERN_ERR
"ide-floppy: Can't get floppy parameters\n");
1519 header
= (idefloppy_capacity_header_t
*) pc
.buffer
;
1520 descriptors
= header
->length
/
1521 sizeof(idefloppy_capacity_descriptor_t
);
1522 descriptor
= (idefloppy_capacity_descriptor_t
*) (header
+ 1);
1528 ** We always skip the first capacity descriptor. That's the
1529 ** current capacity. We are interested in the remaining descriptors,
1530 ** the formattable capacities.
1533 for (i
=0; i
<descriptors
; i
++, descriptor
++) {
1534 if (u_index
>= u_array_size
)
1535 break; /* User-supplied buffer too small */
1537 continue; /* Skip the first descriptor */
1539 blocks
= ntohl(descriptor
->blocks
);
1540 length
= ntohs(descriptor
->length
);
1542 if (put_user(blocks
, argp
))
1546 if (put_user(length
, argp
))
1553 if (put_user(u_index
, arg
))
1559 ** Send ATAPI_FORMAT_UNIT to the drive.
1561 ** Userland gives us the following structure:
1563 ** struct idefloppy_format_command {
1569 ** flags is a bitmask, currently, the only defined flag is:
1571 ** 0x01 - verify media after format.
1574 static int idefloppy_begin_format(ide_drive_t
*drive
, int __user
*arg
)
1581 if (get_user(blocks
, arg
) ||
1582 get_user(length
, arg
+1) ||
1583 get_user(flags
, arg
+2)) {
1587 /* Get the SFRP bit */
1588 (void) idefloppy_get_capability_page(drive
);
1589 idefloppy_create_format_unit_cmd(&pc
, blocks
, length
, flags
);
1590 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1598 ** Get ATAPI_FORMAT_UNIT progress indication.
1600 ** Userland gives a pointer to an int. The int is set to a progress
1601 ** indicator 0-65536, with 65536=100%.
1603 ** If the drive does not support format progress indication, we just check
1604 ** the dsc bit, and return either 0 or 65536.
1607 static int idefloppy_get_format_progress(ide_drive_t
*drive
, int __user
*arg
)
1609 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1611 int progress_indication
= 0x10000;
1614 idefloppy_create_request_sense_cmd(&pc
);
1615 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1619 if (floppy
->sense_key
== 2 &&
1621 floppy
->ascq
== 4) {
1622 progress_indication
= floppy
->progress_indication
;
1624 /* Else assume format_unit has finished, and we're
1627 unsigned long flags
;
1630 local_irq_save(flags
);
1631 stat
= drive
->hwif
->INB(IDE_STATUS_REG
);
1632 local_irq_restore(flags
);
1634 progress_indication
= ((stat
& SEEK_STAT
) == 0) ? 0 : 0x10000;
1636 if (put_user(progress_indication
, arg
))
1643 * Return the current floppy capacity.
1645 static sector_t
idefloppy_capacity (ide_drive_t
*drive
)
1647 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1648 unsigned long capacity
= floppy
->blocks
* floppy
->bs_factor
;
1654 * idefloppy_identify_device checks if we can support a drive,
1655 * based on the ATAPI IDENTIFY command results.
1657 static int idefloppy_identify_device (ide_drive_t
*drive
,struct hd_driveid
*id
)
1659 struct idefloppy_id_gcw gcw
;
1660 #if IDEFLOPPY_DEBUG_INFO
1663 #endif /* IDEFLOPPY_DEBUG_INFO */
1665 *((u16
*) &gcw
) = id
->config
;
1668 /* kludge for Apple PowerBook internal zip */
1669 if ((gcw
.device_type
== 5) &&
1670 !strstr(id
->model
, "CD-ROM") &&
1671 strstr(id
->model
, "ZIP"))
1672 gcw
.device_type
= 0;
1675 #if IDEFLOPPY_DEBUG_INFO
1676 printk(KERN_INFO
"Dumping ATAPI Identify Device floppy parameters\n");
1677 switch (gcw
.protocol
) {
1678 case 0: case 1: sprintf(buffer
, "ATA");break;
1679 case 2: sprintf(buffer
, "ATAPI");break;
1680 case 3: sprintf(buffer
, "Reserved (Unknown to ide-floppy)");break;
1682 printk(KERN_INFO
"Protocol Type: %s\n", buffer
);
1683 switch (gcw
.device_type
) {
1684 case 0: sprintf(buffer
, "Direct-access Device");break;
1685 case 1: sprintf(buffer
, "Streaming Tape Device");break;
1686 case 2: case 3: case 4: sprintf (buffer
, "Reserved");break;
1687 case 5: sprintf(buffer
, "CD-ROM Device");break;
1688 case 6: sprintf(buffer
, "Reserved");
1689 case 7: sprintf(buffer
, "Optical memory Device");break;
1690 case 0x1f: sprintf(buffer
, "Unknown or no Device type");break;
1691 default: sprintf(buffer
, "Reserved");
1693 printk(KERN_INFO
"Device Type: %x - %s\n", gcw
.device_type
, buffer
);
1694 printk(KERN_INFO
"Removable: %s\n",gcw
.removable
? "Yes":"No");
1695 switch (gcw
.drq_type
) {
1696 case 0: sprintf(buffer
, "Microprocessor DRQ");break;
1697 case 1: sprintf(buffer
, "Interrupt DRQ");break;
1698 case 2: sprintf(buffer
, "Accelerated DRQ");break;
1699 case 3: sprintf(buffer
, "Reserved");break;
1701 printk(KERN_INFO
"Command Packet DRQ Type: %s\n", buffer
);
1702 switch (gcw
.packet_size
) {
1703 case 0: sprintf(buffer
, "12 bytes");break;
1704 case 1: sprintf(buffer
, "16 bytes");break;
1705 default: sprintf(buffer
, "Reserved");break;
1707 printk(KERN_INFO
"Command Packet Size: %s\n", buffer
);
1708 printk(KERN_INFO
"Model: %.40s\n",id
->model
);
1709 printk(KERN_INFO
"Firmware Revision: %.8s\n",id
->fw_rev
);
1710 printk(KERN_INFO
"Serial Number: %.20s\n",id
->serial_no
);
1711 printk(KERN_INFO
"Write buffer size(?): %d bytes\n",id
->buf_size
*512);
1712 printk(KERN_INFO
"DMA: %s",id
->capability
& 0x01 ? "Yes\n":"No\n");
1713 printk(KERN_INFO
"LBA: %s",id
->capability
& 0x02 ? "Yes\n":"No\n");
1714 printk(KERN_INFO
"IORDY can be disabled: %s",id
->capability
& 0x04 ? "Yes\n":"No\n");
1715 printk(KERN_INFO
"IORDY supported: %s",id
->capability
& 0x08 ? "Yes\n":"Unknown\n");
1716 printk(KERN_INFO
"ATAPI overlap supported: %s",id
->capability
& 0x20 ? "Yes\n":"No\n");
1717 printk(KERN_INFO
"PIO Cycle Timing Category: %d\n",id
->tPIO
);
1718 printk(KERN_INFO
"DMA Cycle Timing Category: %d\n",id
->tDMA
);
1719 printk(KERN_INFO
"Single Word DMA supported modes:\n");
1720 for (i
=0,mask
=1;i
<8;i
++,mask
=mask
<< 1) {
1721 if (id
->dma_1word
& mask
)
1722 printk(KERN_INFO
" Mode %d%s\n", i
,
1723 (id
->dma_1word
& (mask
<< 8)) ? " (active)" : "");
1725 printk(KERN_INFO
"Multi Word DMA supported modes:\n");
1726 for (i
=0,mask
=1;i
<8;i
++,mask
=mask
<< 1) {
1727 if (id
->dma_mword
& mask
)
1728 printk(KERN_INFO
" Mode %d%s\n", i
,
1729 (id
->dma_mword
& (mask
<< 8)) ? " (active)" : "");
1731 if (id
->field_valid
& 0x0002) {
1732 printk(KERN_INFO
"Enhanced PIO Modes: %s\n",
1733 id
->eide_pio_modes
& 1 ? "Mode 3":"None");
1734 if (id
->eide_dma_min
== 0)
1735 sprintf(buffer
, "Not supported");
1737 sprintf(buffer
, "%d ns",id
->eide_dma_min
);
1738 printk(KERN_INFO
"Minimum Multi-word DMA cycle per word: %s\n", buffer
);
1739 if (id
->eide_dma_time
== 0)
1740 sprintf(buffer
, "Not supported");
1742 sprintf(buffer
, "%d ns",id
->eide_dma_time
);
1743 printk(KERN_INFO
"Manufacturer\'s Recommended Multi-word cycle: %s\n", buffer
);
1744 if (id
->eide_pio
== 0)
1745 sprintf(buffer
, "Not supported");
1747 sprintf(buffer
, "%d ns",id
->eide_pio
);
1748 printk(KERN_INFO
"Minimum PIO cycle without IORDY: %s\n",
1750 if (id
->eide_pio_iordy
== 0)
1751 sprintf(buffer
, "Not supported");
1753 sprintf(buffer
, "%d ns",id
->eide_pio_iordy
);
1754 printk(KERN_INFO
"Minimum PIO cycle with IORDY: %s\n", buffer
);
1756 printk(KERN_INFO
"According to the device, fields 64-70 are not valid.\n");
1757 #endif /* IDEFLOPPY_DEBUG_INFO */
1759 if (gcw
.protocol
!= 2)
1760 printk(KERN_ERR
"ide-floppy: Protocol is not ATAPI\n");
1761 else if (gcw
.device_type
!= 0)
1762 printk(KERN_ERR
"ide-floppy: Device type is not set to floppy\n");
1763 else if (!gcw
.removable
)
1764 printk(KERN_ERR
"ide-floppy: The removable flag is not set\n");
1765 else if (gcw
.drq_type
== 3) {
1766 printk(KERN_ERR
"ide-floppy: Sorry, DRQ type %d not supported\n", gcw
.drq_type
);
1767 } else if (gcw
.packet_size
!= 0) {
1768 printk(KERN_ERR
"ide-floppy: Packet size is not 12 bytes long\n");
1774 #ifdef CONFIG_IDE_PROC_FS
1775 static void idefloppy_add_settings(ide_drive_t
*drive
)
1777 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1780 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
1782 ide_add_setting(drive
, "bios_cyl", SETTING_RW
, TYPE_INT
, 0, 1023, 1, 1, &drive
->bios_cyl
, NULL
);
1783 ide_add_setting(drive
, "bios_head", SETTING_RW
, TYPE_BYTE
, 0, 255, 1, 1, &drive
->bios_head
, NULL
);
1784 ide_add_setting(drive
, "bios_sect", SETTING_RW
, TYPE_BYTE
, 0, 63, 1, 1, &drive
->bios_sect
, NULL
);
1785 ide_add_setting(drive
, "ticks", SETTING_RW
, TYPE_BYTE
, 0, 255, 1, 1, &floppy
->ticks
, NULL
);
1788 static inline void idefloppy_add_settings(ide_drive_t
*drive
) { ; }
1792 * Driver initialization.
1794 static void idefloppy_setup (ide_drive_t
*drive
, idefloppy_floppy_t
*floppy
)
1796 struct idefloppy_id_gcw gcw
;
1798 *((u16
*) &gcw
) = drive
->id
->config
;
1799 floppy
->pc
= floppy
->pc_stack
;
1800 if (gcw
.drq_type
== 1)
1801 set_bit(IDEFLOPPY_DRQ_INTERRUPT
, &floppy
->flags
);
1803 * We used to check revisions here. At this point however
1804 * I'm giving up. Just assume they are all broken, its easier.
1806 * The actual reason for the workarounds was likely
1807 * a driver bug after all rather than a firmware bug,
1808 * and the workaround below used to hide it. It should
1809 * be fixed as of version 1.9, but to be on the safe side
1810 * we'll leave the limitation below for the 2.2.x tree.
1813 if (!strncmp(drive
->id
->model
, "IOMEGA ZIP 100 ATAPI", 20)) {
1814 set_bit(IDEFLOPPY_ZIP_DRIVE
, &floppy
->flags
);
1815 /* This value will be visible in the /proc/ide/hdx/settings */
1816 floppy
->ticks
= IDEFLOPPY_TICKS_DELAY
;
1817 blk_queue_max_sectors(drive
->queue
, 64);
1821 * Guess what? The IOMEGA Clik! drive also needs the
1822 * above fix. It makes nasty clicking noises without
1823 * it, so please don't remove this.
1825 if (strncmp(drive
->id
->model
, "IOMEGA Clik!", 11) == 0) {
1826 blk_queue_max_sectors(drive
->queue
, 64);
1827 set_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
);
1831 (void) idefloppy_get_capacity(drive
);
1832 idefloppy_add_settings(drive
);
1835 static void ide_floppy_remove(ide_drive_t
*drive
)
1837 idefloppy_floppy_t
*floppy
= drive
->driver_data
;
1838 struct gendisk
*g
= floppy
->disk
;
1840 ide_proc_unregister_driver(drive
, floppy
->driver
);
1844 ide_floppy_put(floppy
);
1847 static void ide_floppy_release(struct kref
*kref
)
1849 struct ide_floppy_obj
*floppy
= to_ide_floppy(kref
);
1850 ide_drive_t
*drive
= floppy
->drive
;
1851 struct gendisk
*g
= floppy
->disk
;
1853 drive
->driver_data
= NULL
;
1854 g
->private_data
= NULL
;
1859 #ifdef CONFIG_IDE_PROC_FS
1860 static int proc_idefloppy_read_capacity
1861 (char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
1863 ide_drive_t
*drive
= (ide_drive_t
*)data
;
1866 len
= sprintf(page
,"%llu\n", (long long)idefloppy_capacity(drive
));
1867 PROC_IDE_READ_RETURN(page
,start
,off
,count
,eof
,len
);
1870 static ide_proc_entry_t idefloppy_proc
[] = {
1871 { "capacity", S_IFREG
|S_IRUGO
, proc_idefloppy_read_capacity
, NULL
},
1872 { "geometry", S_IFREG
|S_IRUGO
, proc_ide_read_geometry
, NULL
},
1873 { NULL
, 0, NULL
, NULL
}
1875 #endif /* CONFIG_IDE_PROC_FS */
1877 static int ide_floppy_probe(ide_drive_t
*);
1879 static ide_driver_t idefloppy_driver
= {
1881 .owner
= THIS_MODULE
,
1882 .name
= "ide-floppy",
1883 .bus
= &ide_bus_type
,
1885 .probe
= ide_floppy_probe
,
1886 .remove
= ide_floppy_remove
,
1887 .version
= IDEFLOPPY_VERSION
,
1888 .media
= ide_floppy
,
1889 .supports_dsc_overlap
= 0,
1890 .do_request
= idefloppy_do_request
,
1891 .end_request
= idefloppy_do_end_request
,
1892 .error
= __ide_error
,
1893 .abort
= __ide_abort
,
1894 #ifdef CONFIG_IDE_PROC_FS
1895 .proc
= idefloppy_proc
,
1899 static int idefloppy_open(struct inode
*inode
, struct file
*filp
)
1901 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1902 struct ide_floppy_obj
*floppy
;
1907 debug_log(KERN_INFO
"Reached idefloppy_open\n");
1909 if (!(floppy
= ide_floppy_get(disk
)))
1912 drive
= floppy
->drive
;
1916 if (floppy
->openers
== 1) {
1917 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1920 idefloppy_create_test_unit_ready_cmd(&pc
);
1921 if (idefloppy_queue_pc_tail(drive
, &pc
)) {
1922 idefloppy_create_start_stop_cmd(&pc
, 1);
1923 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1926 if (idefloppy_get_capacity (drive
)
1927 && (filp
->f_flags
& O_NDELAY
) == 0
1929 ** Allow O_NDELAY to open a drive without a disk, or with
1930 ** an unreadable disk, so that we can get the format
1931 ** capacity of the drive or begin the format - Sam
1935 goto out_put_floppy
;
1938 if (floppy
->wp
&& (filp
->f_mode
& 2)) {
1940 goto out_put_floppy
;
1942 set_bit(IDEFLOPPY_MEDIA_CHANGED
, &floppy
->flags
);
1943 /* IOMEGA Clik! drives do not support lock/unlock commands */
1944 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1945 idefloppy_create_prevent_cmd(&pc
, 1);
1946 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1948 check_disk_change(inode
->i_bdev
);
1949 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
)) {
1951 goto out_put_floppy
;
1957 ide_floppy_put(floppy
);
1961 static int idefloppy_release(struct inode
*inode
, struct file
*filp
)
1963 struct gendisk
*disk
= inode
->i_bdev
->bd_disk
;
1964 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
1965 ide_drive_t
*drive
= floppy
->drive
;
1968 debug_log(KERN_INFO
"Reached idefloppy_release\n");
1970 if (floppy
->openers
== 1) {
1971 /* IOMEGA Clik! drives do not support lock/unlock commands */
1972 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
1973 idefloppy_create_prevent_cmd(&pc
, 0);
1974 (void) idefloppy_queue_pc_tail(drive
, &pc
);
1977 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
1982 ide_floppy_put(floppy
);
1987 static int idefloppy_getgeo(struct block_device
*bdev
, struct hd_geometry
*geo
)
1989 struct ide_floppy_obj
*floppy
= ide_floppy_g(bdev
->bd_disk
);
1990 ide_drive_t
*drive
= floppy
->drive
;
1992 geo
->heads
= drive
->bios_head
;
1993 geo
->sectors
= drive
->bios_sect
;
1994 geo
->cylinders
= (u16
)drive
->bios_cyl
; /* truncate */
1998 static int idefloppy_ioctl(struct inode
*inode
, struct file
*file
,
1999 unsigned int cmd
, unsigned long arg
)
2001 struct block_device
*bdev
= inode
->i_bdev
;
2002 struct ide_floppy_obj
*floppy
= ide_floppy_g(bdev
->bd_disk
);
2003 ide_drive_t
*drive
= floppy
->drive
;
2004 void __user
*argp
= (void __user
*)arg
;
2006 int prevent
= (arg
) ? 1 : 0;
2013 case CDROM_LOCKDOOR
:
2014 if (floppy
->openers
> 1)
2017 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */
2018 if (!test_bit(IDEFLOPPY_CLIK_DRIVE
, &floppy
->flags
)) {
2019 idefloppy_create_prevent_cmd(&pc
, prevent
);
2020 (void) idefloppy_queue_pc_tail(drive
, &pc
);
2022 if (cmd
== CDROMEJECT
) {
2023 idefloppy_create_start_stop_cmd(&pc
, 2);
2024 (void) idefloppy_queue_pc_tail(drive
, &pc
);
2027 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED
:
2029 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY
:
2030 return idefloppy_get_format_capacities(drive
, argp
);
2031 case IDEFLOPPY_IOCTL_FORMAT_START
:
2033 if (!(file
->f_mode
& 2))
2036 if (floppy
->openers
> 1) {
2037 /* Don't format if someone is using the disk */
2039 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
,
2044 set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
2046 err
= idefloppy_begin_format(drive
, argp
);
2048 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS
, &floppy
->flags
);
2051 ** Note, the bit will be cleared when the device is
2052 ** closed. This is the cleanest way to handle the
2053 ** situation where the drive does not support
2054 ** format progress reporting.
2056 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS
:
2057 return idefloppy_get_format_progress(drive
, argp
);
2061 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
2062 * and CDROM_SEND_PACKET (legacy) ioctls
2064 if (cmd
!= CDROM_SEND_PACKET
&& cmd
!= SCSI_IOCTL_SEND_COMMAND
)
2065 err
= scsi_cmd_ioctl(file
, bdev
->bd_disk
->queue
,
2066 bdev
->bd_disk
, cmd
, argp
);
2071 err
= generic_ide_ioctl(drive
, file
, bdev
, cmd
, arg
);
2076 static int idefloppy_media_changed(struct gendisk
*disk
)
2078 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
2079 ide_drive_t
*drive
= floppy
->drive
;
2081 /* do not scan partitions twice if this is a removable device */
2082 if (drive
->attach
) {
2086 return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED
, &floppy
->flags
);
2089 static int idefloppy_revalidate_disk(struct gendisk
*disk
)
2091 struct ide_floppy_obj
*floppy
= ide_floppy_g(disk
);
2092 set_capacity(disk
, idefloppy_capacity(floppy
->drive
));
2096 static struct block_device_operations idefloppy_ops
= {
2097 .owner
= THIS_MODULE
,
2098 .open
= idefloppy_open
,
2099 .release
= idefloppy_release
,
2100 .ioctl
= idefloppy_ioctl
,
2101 .getgeo
= idefloppy_getgeo
,
2102 .media_changed
= idefloppy_media_changed
,
2103 .revalidate_disk
= idefloppy_revalidate_disk
2106 static int ide_floppy_probe(ide_drive_t
*drive
)
2108 idefloppy_floppy_t
*floppy
;
2111 if (!strstr("ide-floppy", drive
->driver_req
))
2113 if (!drive
->present
)
2115 if (drive
->media
!= ide_floppy
)
2117 if (!idefloppy_identify_device (drive
, drive
->id
)) {
2118 printk (KERN_ERR
"ide-floppy: %s: not supported by this version of ide-floppy\n", drive
->name
);
2122 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive
->name
);
2125 if ((floppy
= kzalloc(sizeof (idefloppy_floppy_t
), GFP_KERNEL
)) == NULL
) {
2126 printk (KERN_ERR
"ide-floppy: %s: Can't allocate a floppy structure\n", drive
->name
);
2130 g
= alloc_disk(1 << PARTN_BITS
);
2132 goto out_free_floppy
;
2134 ide_init_disk(g
, drive
);
2136 ide_proc_register_driver(drive
, &idefloppy_driver
);
2138 kref_init(&floppy
->kref
);
2140 floppy
->drive
= drive
;
2141 floppy
->driver
= &idefloppy_driver
;
2144 g
->private_data
= &floppy
->driver
;
2146 drive
->driver_data
= floppy
;
2148 idefloppy_setup (drive
, floppy
);
2150 g
->minors
= 1 << PARTN_BITS
;
2151 g
->driverfs_dev
= &drive
->gendev
;
2152 g
->flags
= drive
->removable
? GENHD_FL_REMOVABLE
: 0;
2153 g
->fops
= &idefloppy_ops
;
2164 MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
2166 static void __exit
idefloppy_exit (void)
2168 driver_unregister(&idefloppy_driver
.gen_driver
);
2171 static int __init
idefloppy_init(void)
2173 printk("ide-floppy driver " IDEFLOPPY_VERSION
"\n");
2174 return driver_register(&idefloppy_driver
.gen_driver
);
2177 MODULE_ALIAS("ide:*m-floppy*");
2178 module_init(idefloppy_init
);
2179 module_exit(idefloppy_exit
);
2180 MODULE_LICENSE("GPL");