blob: e9d11faec9bd3792624ecc271276e8b8485d0b26 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Borislav Petkovd3f20842008-02-01 23:09:33 +01002 * IDE ATAPI floppy driver.
3 *
Bartlomiej Zolnierkiewicz59bca8c2008-02-01 23:09:33 +01004 * Copyright (C) 1996-1999 Gadi Oxman <gadio@netvision.net.il>
5 * Copyright (C) 2000-2002 Paul Bristow <paul@paulbristow.net>
6 * Copyright (C) 2005 Bartlomiej Zolnierkiewicz
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * The driver currently doesn't have any fancy features, just the bare
11 * minimum read/write support.
12 *
13 * This driver supports the following IDE floppy drives:
14 *
15 * LS-120/240 SuperDisk
16 * Iomega Zip 100/250
17 * Iomega PC Card Clik!/PocketZip
18 *
Borislav Petkovd3f20842008-02-01 23:09:33 +010019 * For a historical changelog see
20 * Documentation/ide/ChangeLog.ide-floppy.1996-2002
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 */
22
23#define IDEFLOPPY_VERSION "0.99.newide"
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/module.h>
26#include <linux/types.h>
27#include <linux/string.h>
28#include <linux/kernel.h>
29#include <linux/delay.h>
30#include <linux/timer.h>
31#include <linux/mm.h>
32#include <linux/interrupt.h>
33#include <linux/major.h>
34#include <linux/errno.h>
35#include <linux/genhd.h>
36#include <linux/slab.h>
37#include <linux/cdrom.h>
38#include <linux/ide.h>
39#include <linux/bitops.h>
Arjan van de Vencf8b8972006-03-23 03:00:45 -080040#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +020042#include <scsi/scsi_ioctl.h>
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/byteorder.h>
Borislav Petkov7e8b1632008-02-02 19:56:34 +010045#include <linux/irq.h>
46#include <linux/uaccess.h>
47#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <asm/unaligned.h>
49
50/*
51 * The following are used to debug the driver.
52 */
53#define IDEFLOPPY_DEBUG_LOG 0
54#define IDEFLOPPY_DEBUG_INFO 0
55#define IDEFLOPPY_DEBUG_BUGS 1
56
57/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
58#define IDEFLOPPY_DEBUG( fmt, args... )
59
60#if IDEFLOPPY_DEBUG_LOG
Borislav Petkovbcc77d92008-02-02 19:56:34 +010061#define debug_log(fmt, args...) \
62 printk(KERN_INFO "ide-floppy: " fmt, ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#else
64#define debug_log(fmt, args... ) do {} while(0)
65#endif
66
67
68/*
69 * Some drives require a longer irq timeout.
70 */
71#define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
72
73/*
74 * After each failed packet command we issue a request sense command
75 * and retry the packet command IDEFLOPPY_MAX_PC_RETRIES times.
76 */
77#define IDEFLOPPY_MAX_PC_RETRIES 3
78
79/*
80 * With each packet command, we allocate a buffer of
81 * IDEFLOPPY_PC_BUFFER_SIZE bytes.
82 */
83#define IDEFLOPPY_PC_BUFFER_SIZE 256
84
85/*
86 * In various places in the driver, we need to allocate storage
87 * for packet commands and requests, which will remain valid while
88 * we leave the driver to wait for an interrupt or a timeout event.
89 */
90#define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
91
92/*
93 * Our view of a packet command.
94 */
95typedef struct idefloppy_packet_command_s {
96 u8 c[12]; /* Actual packet bytes */
97 int retries; /* On each retry, we increment retries */
98 int error; /* Error code */
99 int request_transfer; /* Bytes to transfer */
100 int actually_transferred; /* Bytes actually transferred */
101 int buffer_size; /* Size of our data buffer */
102 int b_count; /* Missing/Available data on the current buffer */
103 struct request *rq; /* The corresponding request */
104 u8 *buffer; /* Data buffer */
105 u8 *current_position; /* Pointer into the above buffer */
106 void (*callback) (ide_drive_t *); /* Called when this packet command is completed */
107 u8 pc_buffer[IDEFLOPPY_PC_BUFFER_SIZE]; /* Temporary buffer */
108 unsigned long flags; /* Status/Action bit flags: long for set_bit */
109} idefloppy_pc_t;
110
111/*
112 * Packet command flag bits.
113 */
114#define PC_ABORT 0 /* Set when an error is considered normal - We won't retry */
115#define PC_DMA_RECOMMENDED 2 /* 1 when we prefer to use DMA if possible */
116#define PC_DMA_IN_PROGRESS 3 /* 1 while DMA in progress */
117#define PC_DMA_ERROR 4 /* 1 when encountered problem during DMA */
118#define PC_WRITING 5 /* Data direction */
119
120#define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */
121
122/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 * Flexible disk page.
124 */
125typedef struct {
126#if defined(__LITTLE_ENDIAN_BITFIELD)
127 unsigned page_code :6; /* Page code - Should be 0x5 */
128 unsigned reserved1_6 :1; /* Reserved */
129 unsigned ps :1; /* The device is capable of saving the page */
130#elif defined(__BIG_ENDIAN_BITFIELD)
131 unsigned ps :1; /* The device is capable of saving the page */
132 unsigned reserved1_6 :1; /* Reserved */
133 unsigned page_code :6; /* Page code - Should be 0x5 */
134#else
135#error "Bitfield endianness not defined! Check your byteorder.h"
136#endif
137 u8 page_length; /* Page Length - Should be 0x1e */
138 u16 transfer_rate; /* In kilobits per second */
139 u8 heads, sectors; /* Number of heads, Number of sectors per track */
140 u16 sector_size; /* Byes per sector */
141 u16 cyls; /* Number of cylinders */
142 u8 reserved10[10];
143 u8 motor_delay; /* Motor off delay */
144 u8 reserved21[7];
145 u16 rpm; /* Rotations per minute */
146 u8 reserved30[2];
147} idefloppy_flexible_disk_page_t;
148
149/*
150 * Format capacity
151 */
152typedef struct {
153 u8 reserved[3];
154 u8 length; /* Length of the following descriptors in bytes */
155} idefloppy_capacity_header_t;
156
157typedef struct {
158 u32 blocks; /* Number of blocks */
159#if defined(__LITTLE_ENDIAN_BITFIELD)
160 unsigned dc :2; /* Descriptor Code */
161 unsigned reserved :6;
162#elif defined(__BIG_ENDIAN_BITFIELD)
163 unsigned reserved :6;
164 unsigned dc :2; /* Descriptor Code */
165#else
166#error "Bitfield endianness not defined! Check your byteorder.h"
167#endif
168 u8 length_msb; /* Block Length (MSB)*/
169 u16 length; /* Block Length */
170} idefloppy_capacity_descriptor_t;
171
172#define CAPACITY_INVALID 0x00
173#define CAPACITY_UNFORMATTED 0x01
174#define CAPACITY_CURRENT 0x02
175#define CAPACITY_NO_CARTRIDGE 0x03
176
177/*
178 * Most of our global data which we need to save even as we leave the
179 * driver due to an interrupt or a timer event is stored in a variable
180 * of type idefloppy_floppy_t, defined below.
181 */
182typedef struct ide_floppy_obj {
183 ide_drive_t *drive;
184 ide_driver_t *driver;
185 struct gendisk *disk;
186 struct kref kref;
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +0100187 unsigned int openers; /* protected by BKL for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 /* Current packet command */
190 idefloppy_pc_t *pc;
191 /* Last failed packet command */
192 idefloppy_pc_t *failed_pc;
193 /* Packet command stack */
194 idefloppy_pc_t pc_stack[IDEFLOPPY_PC_STACK];
195 /* Next free packet command storage space */
196 int pc_stack_index;
197 struct request rq_stack[IDEFLOPPY_PC_STACK];
198 /* We implement a circular array */
199 int rq_stack_index;
200
201 /*
202 * Last error information
203 */
204 u8 sense_key, asc, ascq;
205 /* delay this long before sending packet command */
206 u8 ticks;
207 int progress_indication;
208
209 /*
210 * Device information
211 */
212 /* Current format */
213 int blocks, block_size, bs_factor;
214 /* Last format capacity */
215 idefloppy_capacity_descriptor_t capacity;
216 /* Copy of the flexible disk page */
217 idefloppy_flexible_disk_page_t flexible_disk_page;
218 /* Write protect */
219 int wp;
220 /* Supports format progress report */
221 int srfp;
222 /* Status/Action flags */
223 unsigned long flags;
224} idefloppy_floppy_t;
225
Bartlomiej Zolnierkiewiczc40d3d32005-08-18 22:09:21 +0200226#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228/*
229 * Floppy flag bits values.
230 */
231#define IDEFLOPPY_DRQ_INTERRUPT 0 /* DRQ interrupt device */
232#define IDEFLOPPY_MEDIA_CHANGED 1 /* Media may have changed */
233#define IDEFLOPPY_USE_READ12 2 /* Use READ12/WRITE12 or READ10/WRITE10 */
234#define IDEFLOPPY_FORMAT_IN_PROGRESS 3 /* Format in progress */
235#define IDEFLOPPY_CLIK_DRIVE 4 /* Avoid commands not supported in Clik drive */
236#define IDEFLOPPY_ZIP_DRIVE 5 /* Requires BH algorithm for packets */
237
238/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 * Defines for the mode sense command
240 */
241#define MODE_SENSE_CURRENT 0x00
242#define MODE_SENSE_CHANGEABLE 0x01
243#define MODE_SENSE_DEFAULT 0x02
244#define MODE_SENSE_SAVED 0x03
245
246/*
247 * IOCTLs used in low-level formatting.
248 */
249
250#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
251#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
252#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
253#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255/*
256 * Error codes which are returned in rq->errors to the higher part
257 * of the driver.
258 */
259#define IDEFLOPPY_ERROR_GENERAL 101
260
261/*
262 * The following is used to format the general configuration word of
263 * the ATAPI IDENTIFY DEVICE command.
264 */
265struct idefloppy_id_gcw {
266#if defined(__LITTLE_ENDIAN_BITFIELD)
267 unsigned packet_size :2; /* Packet Size */
268 unsigned reserved234 :3; /* Reserved */
269 unsigned drq_type :2; /* Command packet DRQ type */
270 unsigned removable :1; /* Removable media */
271 unsigned device_type :5; /* Device type */
272 unsigned reserved13 :1; /* Reserved */
273 unsigned protocol :2; /* Protocol type */
274#elif defined(__BIG_ENDIAN_BITFIELD)
275 unsigned protocol :2; /* Protocol type */
276 unsigned reserved13 :1; /* Reserved */
277 unsigned device_type :5; /* Device type */
278 unsigned removable :1; /* Removable media */
279 unsigned drq_type :2; /* Command packet DRQ type */
280 unsigned reserved234 :3; /* Reserved */
281 unsigned packet_size :2; /* Packet Size */
282#else
283#error "Bitfield endianness not defined! Check your byteorder.h"
284#endif
285};
286
287/*
Borislav Petkov948391d2008-02-02 19:56:34 +0100288 * Pages of the SELECT SENSE / MODE SENSE packet commands.
289 * See SFF-8070i spec.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 */
291#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
292#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
293
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800294static DEFINE_MUTEX(idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
297
298#define ide_floppy_g(disk) \
299 container_of((disk)->private_data, struct ide_floppy_obj, driver)
300
301static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
302{
303 struct ide_floppy_obj *floppy = NULL;
304
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800305 mutex_lock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 floppy = ide_floppy_g(disk);
307 if (floppy)
308 kref_get(&floppy->kref);
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800309 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return floppy;
311}
312
Borislav Petkov9a24b632008-02-02 19:56:33 +0100313static void idefloppy_cleanup_obj(struct kref *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315static void ide_floppy_put(struct ide_floppy_obj *floppy)
316{
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800317 mutex_lock(&idefloppy_ref_mutex);
Borislav Petkov9a24b632008-02-02 19:56:33 +0100318 kref_put(&floppy->kref, idefloppy_cleanup_obj);
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800319 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320}
321
322/*
323 * Too bad. The drive wants to send us data which we are not ready to accept.
324 * Just throw it away.
325 */
326static void idefloppy_discard_data (ide_drive_t *drive, unsigned int bcount)
327{
328 while (bcount--)
329 (void) HWIF(drive)->INB(IDE_DATA_REG);
330}
331
332#if IDEFLOPPY_DEBUG_BUGS
333static void idefloppy_write_zeros (ide_drive_t *drive, unsigned int bcount)
334{
335 while (bcount--)
336 HWIF(drive)->OUTB(0, IDE_DATA_REG);
337}
338#endif /* IDEFLOPPY_DEBUG_BUGS */
339
340
341/*
342 * idefloppy_do_end_request is used to finish servicing a request.
343 *
344 * For read/write requests, we will call ide_end_request to pass to the
345 * next buffer.
346 */
347static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs)
348{
349 idefloppy_floppy_t *floppy = drive->driver_data;
350 struct request *rq = HWGROUP(drive)->rq;
351 int error;
352
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100353 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 switch (uptodate) {
356 case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
357 case 1: error = 0; break;
358 default: error = uptodate;
359 }
360 if (error)
361 floppy->failed_pc = NULL;
362 /* Why does this happen? */
363 if (!rq)
364 return 0;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200365 if (!blk_special_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 /* our real local end request function */
367 ide_end_request(drive, uptodate, nsecs);
368 return 0;
369 }
370 rq->errors = error;
371 /* fixme: need to move this local also */
372 ide_end_drive_cmd(drive, 0, 0);
373 return 0;
374}
375
376static void idefloppy_input_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount)
377{
378 struct request *rq = pc->rq;
379 struct bio_vec *bvec;
NeilBrown5705f702007-09-25 12:35:59 +0200380 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 unsigned long flags;
382 char *data;
NeilBrown5705f702007-09-25 12:35:59 +0200383 int count, done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
NeilBrown5705f702007-09-25 12:35:59 +0200385 rq_for_each_segment(bvec, rq, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200386 if (!bcount)
387 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Jens Axboe6c92e692007-08-16 13:43:12 +0200389 count = min(bvec->bv_len, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Jens Axboe6c92e692007-08-16 13:43:12 +0200391 data = bvec_kmap_irq(bvec, &flags);
392 drive->hwif->atapi_input_bytes(drive, data, count);
393 bvec_kunmap_irq(data, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Jens Axboe6c92e692007-08-16 13:43:12 +0200395 bcount -= count;
396 pc->b_count += count;
397 done += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 }
399
400 idefloppy_do_end_request(drive, 1, done >> 9);
401
402 if (bcount) {
403 printk(KERN_ERR "%s: leftover data in idefloppy_input_buffers, bcount == %d\n", drive->name, bcount);
404 idefloppy_discard_data(drive, bcount);
405 }
406}
407
408static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount)
409{
410 struct request *rq = pc->rq;
NeilBrown5705f702007-09-25 12:35:59 +0200411 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 struct bio_vec *bvec;
413 unsigned long flags;
NeilBrown5705f702007-09-25 12:35:59 +0200414 int count, done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 char *data;
416
NeilBrown5705f702007-09-25 12:35:59 +0200417 rq_for_each_segment(bvec, rq, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200418 if (!bcount)
419 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Jens Axboe6c92e692007-08-16 13:43:12 +0200421 count = min(bvec->bv_len, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Jens Axboe6c92e692007-08-16 13:43:12 +0200423 data = bvec_kmap_irq(bvec, &flags);
424 drive->hwif->atapi_output_bytes(drive, data, count);
425 bvec_kunmap_irq(data, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Jens Axboe6c92e692007-08-16 13:43:12 +0200427 bcount -= count;
428 pc->b_count += count;
429 done += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
431
432 idefloppy_do_end_request(drive, 1, done >> 9);
433
Jan Beulichc7ea4b32005-06-23 00:09:59 -0700434#if IDEFLOPPY_DEBUG_BUGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 if (bcount) {
436 printk(KERN_ERR "%s: leftover data in idefloppy_output_buffers, bcount == %d\n", drive->name, bcount);
437 idefloppy_write_zeros(drive, bcount);
438 }
Jan Beulichc7ea4b32005-06-23 00:09:59 -0700439#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442static void idefloppy_update_buffers (ide_drive_t *drive, idefloppy_pc_t *pc)
443{
444 struct request *rq = pc->rq;
445 struct bio *bio = rq->bio;
446
447 while ((bio = rq->bio) != NULL)
448 idefloppy_do_end_request(drive, 1, 0);
449}
450
451/*
452 * idefloppy_queue_pc_head generates a new packet command request in front
453 * of the request queue, before the current request, so that it will be
454 * processed immediately, on the next pass through the driver.
455 */
456static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struct request *rq)
457{
458 struct ide_floppy_obj *floppy = drive->driver_data;
459
460 ide_init_drive_cmd(rq);
461 rq->buffer = (char *) pc;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200462 rq->cmd_type = REQ_TYPE_SPECIAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 rq->rq_disk = floppy->disk;
464 (void) ide_do_drive_cmd(drive, rq, ide_preempt);
465}
466
467static idefloppy_pc_t *idefloppy_next_pc_storage (ide_drive_t *drive)
468{
469 idefloppy_floppy_t *floppy = drive->driver_data;
470
471 if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
472 floppy->pc_stack_index=0;
473 return (&floppy->pc_stack[floppy->pc_stack_index++]);
474}
475
476static struct request *idefloppy_next_rq_storage (ide_drive_t *drive)
477{
478 idefloppy_floppy_t *floppy = drive->driver_data;
479
480 if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK)
481 floppy->rq_stack_index = 0;
482 return (&floppy->rq_stack[floppy->rq_stack_index++]);
483}
484
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100485static void idefloppy_request_sense_callback(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
487 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100488 u8 *buf = floppy->pc->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100490 debug_log("Reached %s\n", __func__);
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (!floppy->pc->error) {
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100493 floppy->sense_key = buf[2] & 0x0F;
494 floppy->asc = buf[12];
495 floppy->ascq = buf[13];
496 floppy->progress_indication = buf[15] & 0x80 ?
497 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
498
499 if (floppy->failed_pc)
500 debug_log("pc = %x, sense key = %x, asc = %x,"
501 " ascq = %x\n",
502 floppy->failed_pc->c[0],
503 floppy->sense_key,
504 floppy->asc,
505 floppy->ascq);
506 else
507 debug_log("sense key = %x, asc = %x, ascq = %x\n",
508 floppy->sense_key,
509 floppy->asc,
510 floppy->ascq);
511
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 idefloppy_do_end_request(drive, 1, 0);
514 } else {
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100515 printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting"
516 " request!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 idefloppy_do_end_request(drive, 0, 0);
518 }
519}
520
521/*
522 * General packet command callback function.
523 */
524static void idefloppy_pc_callback (ide_drive_t *drive)
525{
526 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100527
528 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 idefloppy_do_end_request(drive, floppy->pc->error ? 0 : 1, 0);
531}
532
533/*
534 * idefloppy_init_pc initializes a packet command.
535 */
536static void idefloppy_init_pc (idefloppy_pc_t *pc)
537{
538 memset(pc->c, 0, 12);
539 pc->retries = 0;
540 pc->flags = 0;
541 pc->request_transfer = 0;
542 pc->buffer = pc->pc_buffer;
543 pc->buffer_size = IDEFLOPPY_PC_BUFFER_SIZE;
544 pc->callback = &idefloppy_pc_callback;
545}
546
547static void idefloppy_create_request_sense_cmd (idefloppy_pc_t *pc)
548{
Borislav Petkov30d67092008-02-02 19:56:33 +0100549 idefloppy_init_pc(pc);
550 pc->c[0] = GPCMD_REQUEST_SENSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 pc->c[4] = 255;
552 pc->request_transfer = 18;
553 pc->callback = &idefloppy_request_sense_callback;
554}
555
556/*
557 * idefloppy_retry_pc is called when an error was detected during the
558 * last packet command. We queue a request sense packet command in
559 * the head of the request list.
560 */
561static void idefloppy_retry_pc (ide_drive_t *drive)
562{
563 idefloppy_pc_t *pc;
564 struct request *rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100566 (void)drive->hwif->INB(IDE_ERROR_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 pc = idefloppy_next_pc_storage(drive);
568 rq = idefloppy_next_rq_storage(drive);
569 idefloppy_create_request_sense_cmd(pc);
570 idefloppy_queue_pc_head(drive, pc, rq);
571}
572
573/*
574 * idefloppy_pc_intr is the usual interrupt handler which will be called
575 * during a packet command.
576 */
577static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
578{
579 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100580 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 idefloppy_pc_t *pc = floppy->pc;
582 struct request *rq = pc->rq;
583 unsigned int temp;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100584 u16 bcount;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100585 u8 stat, ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100587 debug_log("Reached %s interrupt handler\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
590 if (HWIF(drive)->ide_dma_end(drive)) {
591 set_bit(PC_DMA_ERROR, &pc->flags);
592 } else {
593 pc->actually_transferred = pc->request_transfer;
594 idefloppy_update_buffers(drive, pc);
595 }
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100596 debug_log("DMA finished\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
598
599 /* Clear the interrupt */
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100600 stat = drive->hwif->INB(IDE_STATUS_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100602 if ((stat & DRQ_STAT) == 0) { /* No more interrupts */
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100603 debug_log("Packet command completed, %d bytes transferred\n",
604 pc->actually_transferred);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
606
Ingo Molnar366c7f52006-07-03 00:25:25 -0700607 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100609 if ((stat & ERR_STAT) || test_bit(PC_DMA_ERROR, &pc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 /* Error detected */
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100611 debug_log("%s: I/O error\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 rq->errors++;
Borislav Petkov30d67092008-02-02 19:56:33 +0100613 if (pc->c[0] == GPCMD_REQUEST_SENSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 printk(KERN_ERR "ide-floppy: I/O error in "
615 "request sense command\n");
616 return ide_do_reset(drive);
617 }
618 /* Retry operation */
619 idefloppy_retry_pc(drive);
620 /* queued, but not started */
621 return ide_stopped;
622 }
623 pc->error = 0;
624 if (floppy->failed_pc == pc)
625 floppy->failed_pc = NULL;
626 /* Command finished - Call the callback function */
627 pc->callback(drive);
628 return ide_stopped;
629 }
630
631 if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
632 printk(KERN_ERR "ide-floppy: The floppy wants to issue "
633 "more interrupts in DMA mode\n");
Bartlomiej Zolnierkiewicz7469aaf2007-02-17 02:40:26 +0100634 ide_dma_off(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 return ide_do_reset(drive);
636 }
637
638 /* Get the number of bytes to transfer */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100639 bcount = (hwif->INB(IDE_BCOUNTH_REG) << 8) |
640 hwif->INB(IDE_BCOUNTL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /* on this interrupt */
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100642 ireason = hwif->INB(IDE_IREASON_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100644 if (ireason & CD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 printk(KERN_ERR "ide-floppy: CoD != 0 in idefloppy_pc_intr\n");
646 return ide_do_reset(drive);
647 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100648 if (((ireason & IO) == IO) == test_bit(PC_WRITING, &pc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 /* Hopefully, we will never get here */
650 printk(KERN_ERR "ide-floppy: We wanted to %s, ",
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100651 (ireason & IO) ? "Write" : "Read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 printk(KERN_ERR "but the floppy wants us to %s !\n",
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100653 (ireason & IO) ? "Read" : "Write");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return ide_do_reset(drive);
655 }
656 if (!test_bit(PC_WRITING, &pc->flags)) {
657 /* Reading - Check that we have enough space */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100658 temp = pc->actually_transferred + bcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 if (temp > pc->request_transfer) {
660 if (temp > pc->buffer_size) {
661 printk(KERN_ERR "ide-floppy: The floppy wants "
662 "to send us more data than expected "
663 "- discarding data\n");
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100664 idefloppy_discard_data(drive, bcount);
Borislav Petkov0078df22008-02-02 19:56:33 +0100665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 ide_set_handler(drive,
667 &idefloppy_pc_intr,
668 IDEFLOPPY_WAIT_CMD,
669 NULL);
670 return ide_started;
671 }
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100672 debug_log("The floppy wants to send us more data than"
673 " expected - allowing transfer\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 }
675 }
676 if (test_bit(PC_WRITING, &pc->flags)) {
677 if (pc->buffer != NULL)
678 /* Write the current buffer */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100679 hwif->atapi_output_bytes(drive, pc->current_position,
680 bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 else
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100682 idefloppy_output_buffers(drive, pc, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 } else {
684 if (pc->buffer != NULL)
685 /* Read the current buffer */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100686 hwif->atapi_input_bytes(drive, pc->current_position,
687 bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 else
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100689 idefloppy_input_buffers(drive, pc, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 }
691 /* Update the current position */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100692 pc->actually_transferred += bcount;
693 pc->current_position += bcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); /* And set the interrupt handler again */
696 return ide_started;
697}
698
699/*
700 * This is the original routine that did the packet transfer.
701 * It fails at high speeds on the Iomega ZIP drive, so there's a slower version
702 * for that drive below. The algorithm is chosen based on drive type
703 */
704static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive)
705{
706 ide_startstop_t startstop;
707 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100708 u8 ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
711 printk(KERN_ERR "ide-floppy: Strange, packet command "
712 "initiated yet DRQ isn't asserted\n");
713 return startstop;
714 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100715 ireason = drive->hwif->INB(IDE_IREASON_REG);
716 if ((ireason & CD) == 0 || (ireason & IO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) while "
718 "issuing a packet command\n");
719 return ide_do_reset(drive);
720 }
Borislav Petkov0078df22008-02-02 19:56:33 +0100721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 /* Set the interrupt routine */
723 ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
724 /* Send the actual packet */
725 HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
726 return ide_started;
727}
728
729
730/*
731 * What we have here is a classic case of a top half / bottom half
732 * interrupt service routine. In interrupt mode, the device sends
733 * an interrupt to signal it's ready to receive a packet. However,
734 * we need to delay about 2-3 ticks before issuing the packet or we
735 * gets in trouble.
736 *
737 * So, follow carefully. transfer_pc1 is called as an interrupt (or
738 * directly). In either case, when the device says it's ready for a
739 * packet, we schedule the packet transfer to occur about 2-3 ticks
740 * later in transfer_pc2.
741 */
742static int idefloppy_transfer_pc2 (ide_drive_t *drive)
743{
744 idefloppy_floppy_t *floppy = drive->driver_data;
745
746 /* Send the actual packet */
747 HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
748 /* Timeout for the packet command */
749 return IDEFLOPPY_WAIT_CMD;
750}
751
752static ide_startstop_t idefloppy_transfer_pc1 (ide_drive_t *drive)
753{
754 idefloppy_floppy_t *floppy = drive->driver_data;
755 ide_startstop_t startstop;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100756 u8 ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
759 printk(KERN_ERR "ide-floppy: Strange, packet command "
760 "initiated yet DRQ isn't asserted\n");
761 return startstop;
762 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100763 ireason = drive->hwif->INB(IDE_IREASON_REG);
764 if ((ireason & CD) == 0 || (ireason & IO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) "
766 "while issuing a packet command\n");
767 return ide_do_reset(drive);
768 }
769 /*
770 * The following delay solves a problem with ATAPI Zip 100 drives
771 * where the Busy flag was apparently being deasserted before the
772 * unit was ready to receive data. This was happening on a
773 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
774 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
775 * used until after the packet is moved in about 50 msec.
776 */
Borislav Petkov0078df22008-02-02 19:56:33 +0100777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 ide_set_handler(drive,
779 &idefloppy_pc_intr, /* service routine for packet command */
780 floppy->ticks, /* wait this long before "failing" */
781 &idefloppy_transfer_pc2); /* fail == transfer_pc2 */
782 return ide_started;
783}
784
785/**
786 * idefloppy_should_report_error()
787 *
788 * Supresses error messages resulting from Medium not present
789 */
790static inline int idefloppy_should_report_error(idefloppy_floppy_t *floppy)
791{
792 if (floppy->sense_key == 0x02 &&
793 floppy->asc == 0x3a &&
794 floppy->ascq == 0x00)
795 return 0;
796 return 1;
797}
798
799/*
800 * Issue a packet command
801 */
802static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *pc)
803{
804 idefloppy_floppy_t *floppy = drive->driver_data;
805 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 ide_handler_t *pkt_xfer_routine;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100807 u16 bcount;
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100808 u8 dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 if (floppy->failed_pc == NULL &&
Borislav Petkov30d67092008-02-02 19:56:33 +0100811 pc->c[0] != GPCMD_REQUEST_SENSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 floppy->failed_pc = pc;
813 /* Set the current packet command */
814 floppy->pc = pc;
815
816 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES ||
817 test_bit(PC_ABORT, &pc->flags)) {
818 /*
819 * We will "abort" retrying a packet command in case
820 * a legitimate error code was received.
821 */
822 if (!test_bit(PC_ABORT, &pc->flags)) {
823 if (!test_bit(PC_SUPPRESS_ERROR, &pc->flags)) {
824 if (idefloppy_should_report_error(floppy))
825 printk(KERN_ERR "ide-floppy: %s: I/O error, "
826 "pc = %2x, key = %2x, "
827 "asc = %2x, ascq = %2x\n",
828 drive->name, pc->c[0],
829 floppy->sense_key,
830 floppy->asc, floppy->ascq);
831 }
832 /* Giving up */
833 pc->error = IDEFLOPPY_ERROR_GENERAL;
834 }
835 floppy->failed_pc = NULL;
836 pc->callback(drive);
837 return ide_stopped;
838 }
839
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100840 debug_log("Retry number - %d\n", pc->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842 pc->retries++;
843 /* We haven't transferred any data yet */
844 pc->actually_transferred = 0;
845 pc->current_position = pc->buffer;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100846 bcount = min(pc->request_transfer, 63 * 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Bartlomiej Zolnierkiewicz7469aaf2007-02-17 02:40:26 +0100848 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags))
849 ide_dma_off(drive);
850
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100851 dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100854 dma = !hwif->dma_setup(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Bartlomiej Zolnierkiewicz2fc57382008-01-25 22:17:13 +0100856 ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK |
857 IDE_TFLAG_OUT_DEVICE, bcount, dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100859 if (dma) { /* Begin DMA, if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 set_bit(PC_DMA_IN_PROGRESS, &pc->flags);
861 hwif->dma_start(drive);
862 }
863
864 /* Can we transfer the packet when we get the interrupt or wait? */
865 if (test_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags)) {
866 /* wait */
867 pkt_xfer_routine = &idefloppy_transfer_pc1;
868 } else {
869 /* immediate */
870 pkt_xfer_routine = &idefloppy_transfer_pc;
871 }
872
873 if (test_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags)) {
874 /* Issue the packet command */
875 ide_execute_command(drive, WIN_PACKETCMD,
876 pkt_xfer_routine,
877 IDEFLOPPY_WAIT_CMD,
878 NULL);
879 return ide_started;
880 } else {
881 /* Issue the packet command */
882 HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
883 return (*pkt_xfer_routine) (drive);
884 }
885}
886
887static void idefloppy_rw_callback (ide_drive_t *drive)
888{
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100889 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 idefloppy_do_end_request(drive, 1, 0);
892 return;
893}
894
895static void idefloppy_create_prevent_cmd (idefloppy_pc_t *pc, int prevent)
896{
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100897 debug_log("creating prevent removal command, prevent = %d\n", prevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100900 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 pc->c[4] = prevent;
902}
903
904static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t *pc)
905{
906 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100907 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 pc->c[7] = 255;
909 pc->c[8] = 255;
910 pc->request_transfer = 255;
911}
912
913static void idefloppy_create_format_unit_cmd (idefloppy_pc_t *pc, int b, int l,
914 int flags)
915{
916 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100917 pc->c[0] = GPCMD_FORMAT_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 pc->c[1] = 0x17;
919
920 memset(pc->buffer, 0, 12);
921 pc->buffer[1] = 0xA2;
922 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
923
924 if (flags & 1) /* Verify bit on... */
925 pc->buffer[1] ^= 0x20; /* ... turn off DCRT bit */
926 pc->buffer[3] = 8;
927
Borislav Petkov8f622432008-02-02 19:56:33 +0100928 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buffer[4]));
929 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buffer[8]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 pc->buffer_size=12;
931 set_bit(PC_WRITING, &pc->flags);
932}
933
934/*
935 * A mode sense command is used to "sense" floppy parameters.
936 */
937static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t *pc, u8 page_code, u8 type)
938{
Borislav Petkov24a5d702008-02-02 19:56:34 +0100939 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100942 pc->c[0] = GPCMD_MODE_SENSE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 pc->c[1] = 0;
944 pc->c[2] = page_code + (type << 6);
945
946 switch (page_code) {
947 case IDEFLOPPY_CAPABILITIES_PAGE:
948 length += 12;
949 break;
950 case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
951 length += 32;
952 break;
953 default:
954 printk(KERN_ERR "ide-floppy: unsupported page code "
955 "in create_mode_sense_cmd\n");
956 }
Borislav Petkov8f622432008-02-02 19:56:33 +0100957 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 pc->request_transfer = length;
959}
960
961static void idefloppy_create_start_stop_cmd (idefloppy_pc_t *pc, int start)
962{
963 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100964 pc->c[0] = GPCMD_START_STOP_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 pc->c[4] = start;
966}
967
968static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t *pc)
969{
970 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100971 pc->c[0] = GPCMD_TEST_UNIT_READY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972}
973
974static void idefloppy_create_rw_cmd (idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq, unsigned long sector)
975{
976 int block = sector / floppy->bs_factor;
977 int blocks = rq->nr_sectors / floppy->bs_factor;
978 int cmd = rq_data_dir(rq);
979
980 debug_log("create_rw1%d_cmd: block == %d, blocks == %d\n",
981 2 * test_bit (IDEFLOPPY_USE_READ12, &floppy->flags),
982 block, blocks);
983
984 idefloppy_init_pc(pc);
985 if (test_bit(IDEFLOPPY_USE_READ12, &floppy->flags)) {
Borislav Petkov30d67092008-02-02 19:56:33 +0100986 pc->c[0] = cmd == READ ? GPCMD_READ_12 : GPCMD_WRITE_12;
Borislav Petkov8f622432008-02-02 19:56:33 +0100987 put_unaligned(cpu_to_be32(blocks), (unsigned int *) &pc->c[6]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 } else {
Borislav Petkov30d67092008-02-02 19:56:33 +0100989 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
Borislav Petkov8f622432008-02-02 19:56:33 +0100990 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
Borislav Petkov8f622432008-02-02 19:56:33 +0100992 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 pc->callback = &idefloppy_rw_callback;
994 pc->rq = rq;
995 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200996 if (rq->cmd_flags & REQ_RW)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 set_bit(PC_WRITING, &pc->flags);
998 pc->buffer = NULL;
999 pc->request_transfer = pc->buffer_size = blocks * floppy->block_size;
1000 set_bit(PC_DMA_RECOMMENDED, &pc->flags);
1001}
1002
Jens Axboe3d6392c2007-07-09 12:38:05 +02001003static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq)
1005{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 idefloppy_init_pc(pc);
Jens Axboe3d6392c2007-07-09 12:38:05 +02001007 pc->callback = &idefloppy_rw_callback;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 memcpy(pc->c, rq->cmd, sizeof(pc->c));
Jens Axboe3d6392c2007-07-09 12:38:05 +02001009 pc->rq = rq;
1010 pc->b_count = rq->data_len;
1011 if (rq->data_len && rq_data_dir(rq) == WRITE)
1012 set_bit(PC_WRITING, &pc->flags);
1013 pc->buffer = rq->data;
1014 if (rq->bio)
1015 set_bit(PC_DMA_RECOMMENDED, &pc->flags);
1016
1017 /*
1018 * possibly problematic, doesn't look like ide-floppy correctly
1019 * handled scattered requests if dma fails...
1020 */
1021 pc->request_transfer = pc->buffer_size = rq->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022}
1023
1024/*
1025 * idefloppy_do_request is our request handling function.
1026 */
1027static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request *rq, sector_t block_s)
1028{
1029 idefloppy_floppy_t *floppy = drive->driver_data;
1030 idefloppy_pc_t *pc;
1031 unsigned long block = (unsigned long)block_s;
1032
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001033 debug_log("dev: %s, cmd_type: %x, errors: %d\n",
Randy Dunlap18cddac2006-06-25 05:48:56 -07001034 rq->rq_disk ? rq->rq_disk->disk_name : "?",
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001035 rq->cmd_type, rq->errors);
1036 debug_log("sector: %ld, nr_sectors: %ld, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 "current_nr_sectors: %d\n", (long)rq->sector,
1038 rq->nr_sectors, rq->current_nr_sectors);
1039
1040 if (rq->errors >= ERROR_MAX) {
1041 if (floppy->failed_pc != NULL) {
1042 if (idefloppy_should_report_error(floppy))
1043 printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x,"
1044 " key = %2x, asc = %2x, ascq = %2x\n",
1045 drive->name, floppy->failed_pc->c[0],
1046 floppy->sense_key, floppy->asc, floppy->ascq);
1047 }
1048 else
1049 printk(KERN_ERR "ide-floppy: %s: I/O error\n",
1050 drive->name);
1051 idefloppy_do_end_request(drive, 0, 0);
1052 return ide_stopped;
1053 }
Jens Axboe4aff5e22006-08-10 08:44:47 +02001054 if (blk_fs_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if (((long)rq->sector % floppy->bs_factor) ||
1056 (rq->nr_sectors % floppy->bs_factor)) {
1057 printk("%s: unsupported r/w request size\n",
1058 drive->name);
1059 idefloppy_do_end_request(drive, 0, 0);
1060 return ide_stopped;
1061 }
1062 pc = idefloppy_next_pc_storage(drive);
1063 idefloppy_create_rw_cmd(floppy, pc, rq, block);
Jens Axboe4aff5e22006-08-10 08:44:47 +02001064 } else if (blk_special_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 pc = (idefloppy_pc_t *) rq->buffer;
Jens Axboe4aff5e22006-08-10 08:44:47 +02001066 } else if (blk_pc_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 pc = idefloppy_next_pc_storage(drive);
Jens Axboe3d6392c2007-07-09 12:38:05 +02001068 idefloppy_blockpc_cmd(floppy, pc, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 } else {
1070 blk_dump_rq_flags(rq,
1071 "ide-floppy: unsupported command in queue");
1072 idefloppy_do_end_request(drive, 0, 0);
1073 return ide_stopped;
1074 }
1075
1076 pc->rq = rq;
1077 return idefloppy_issue_pc(drive, pc);
1078}
1079
1080/*
1081 * idefloppy_queue_pc_tail adds a special packet command request to the
1082 * tail of the request queue, and waits for it to be serviced.
1083 */
1084static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc)
1085{
1086 struct ide_floppy_obj *floppy = drive->driver_data;
1087 struct request rq;
1088
1089 ide_init_drive_cmd (&rq);
1090 rq.buffer = (char *) pc;
Jens Axboe4aff5e22006-08-10 08:44:47 +02001091 rq.cmd_type = REQ_TYPE_SPECIAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 rq.rq_disk = floppy->disk;
1093
1094 return ide_do_drive_cmd(drive, &rq, ide_wait);
1095}
1096
1097/*
1098 * Look at the flexible disk page parameters. We will ignore the CHS
1099 * capacity parameters and use the LBA parameters instead.
1100 */
1101static int idefloppy_get_flexible_disk_page (ide_drive_t *drive)
1102{
1103 idefloppy_floppy_t *floppy = drive->driver_data;
1104 idefloppy_pc_t pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 idefloppy_flexible_disk_page_t *page;
1106 int capacity, lba_capacity;
1107
1108 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, MODE_SENSE_CURRENT);
1109 if (idefloppy_queue_pc_tail(drive,&pc)) {
1110 printk(KERN_ERR "ide-floppy: Can't get flexible disk "
1111 "page parameters\n");
1112 return 1;
1113 }
Borislav Petkov24a5d702008-02-02 19:56:34 +01001114 floppy->wp = !!(pc.buffer[3] & 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 set_disk_ro(floppy->disk, floppy->wp);
Borislav Petkov24a5d702008-02-02 19:56:34 +01001116 page = (idefloppy_flexible_disk_page_t *) &pc.buffer[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Borislav Petkov8f622432008-02-02 19:56:33 +01001118 page->transfer_rate = be16_to_cpu(page->transfer_rate);
1119 page->sector_size = be16_to_cpu(page->sector_size);
1120 page->cyls = be16_to_cpu(page->cyls);
1121 page->rpm = be16_to_cpu(page->rpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 capacity = page->cyls * page->heads * page->sectors * page->sector_size;
1123 if (memcmp (page, &floppy->flexible_disk_page, sizeof (idefloppy_flexible_disk_page_t)))
1124 printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
1125 "%d sector size, %d rpm\n",
1126 drive->name, capacity / 1024, page->cyls,
1127 page->heads, page->sectors,
1128 page->transfer_rate / 8, page->sector_size, page->rpm);
1129
1130 floppy->flexible_disk_page = *page;
1131 drive->bios_cyl = page->cyls;
1132 drive->bios_head = page->heads;
1133 drive->bios_sect = page->sectors;
1134 lba_capacity = floppy->blocks * floppy->block_size;
1135 if (capacity < lba_capacity) {
1136 printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
1137 "bytes, but the drive only handles %d\n",
1138 drive->name, lba_capacity, capacity);
1139 floppy->blocks = floppy->block_size ? capacity / floppy->block_size : 0;
1140 }
1141 return 0;
1142}
1143
Borislav Petkov948391d2008-02-02 19:56:34 +01001144static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
1146 idefloppy_floppy_t *floppy = drive->driver_data;
1147 idefloppy_pc_t pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 floppy->srfp = 0;
1150 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
1151 MODE_SENSE_CURRENT);
1152
1153 set_bit(PC_SUPPRESS_ERROR, &pc.flags);
Borislav Petkov948391d2008-02-02 19:56:34 +01001154 if (idefloppy_queue_pc_tail(drive, &pc))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Borislav Petkov948391d2008-02-02 19:56:34 +01001157 floppy->srfp = pc.buffer[8 + 2] & 0x40;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 return (0);
1159}
1160
1161/*
1162 * Determine if a media is present in the floppy drive, and if so,
1163 * its LBA capacity.
1164 */
1165static int idefloppy_get_capacity (ide_drive_t *drive)
1166{
1167 idefloppy_floppy_t *floppy = drive->driver_data;
1168 idefloppy_pc_t pc;
1169 idefloppy_capacity_header_t *header;
1170 idefloppy_capacity_descriptor_t *descriptor;
1171 int i, descriptors, rc = 1, blocks, length;
1172
1173 drive->bios_cyl = 0;
1174 drive->bios_head = drive->bios_sect = 0;
Alan Coxfdb77da2007-02-17 02:40:20 +01001175 floppy->blocks = 0;
1176 floppy->bs_factor = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 set_capacity(floppy->disk, 0);
1178
1179 idefloppy_create_read_capacity_cmd(&pc);
1180 if (idefloppy_queue_pc_tail(drive, &pc)) {
1181 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
1182 return 1;
1183 }
1184 header = (idefloppy_capacity_header_t *) pc.buffer;
1185 descriptors = header->length / sizeof(idefloppy_capacity_descriptor_t);
1186 descriptor = (idefloppy_capacity_descriptor_t *) (header + 1);
1187
1188 for (i = 0; i < descriptors; i++, descriptor++) {
Borislav Petkov8f622432008-02-02 19:56:33 +01001189 blocks = descriptor->blocks = be32_to_cpu(descriptor->blocks);
1190 length = descriptor->length = be16_to_cpu(descriptor->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
1192 if (!i)
1193 {
1194 switch (descriptor->dc) {
1195 /* Clik! drive returns this instead of CAPACITY_CURRENT */
1196 case CAPACITY_UNFORMATTED:
1197 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags))
1198 /*
1199 * If it is not a clik drive, break out
1200 * (maintains previous driver behaviour)
1201 */
1202 break;
1203 case CAPACITY_CURRENT:
1204 /* Normal Zip/LS-120 disks */
1205 if (memcmp(descriptor, &floppy->capacity, sizeof (idefloppy_capacity_descriptor_t)))
1206 printk(KERN_INFO "%s: %dkB, %d blocks, %d "
1207 "sector size\n", drive->name,
1208 blocks * length / 1024, blocks, length);
1209 floppy->capacity = *descriptor;
1210 if (!length || length % 512) {
1211 printk(KERN_NOTICE "%s: %d bytes block size "
1212 "not supported\n", drive->name, length);
1213 } else {
1214 floppy->blocks = blocks;
1215 floppy->block_size = length;
1216 if ((floppy->bs_factor = length / 512) != 1)
1217 printk(KERN_NOTICE "%s: warning: non "
1218 "512 bytes block size not "
1219 "fully supported\n",
1220 drive->name);
1221 rc = 0;
1222 }
1223 break;
1224 case CAPACITY_NO_CARTRIDGE:
1225 /*
1226 * This is a KERN_ERR so it appears on screen
1227 * for the user to see
1228 */
1229 printk(KERN_ERR "%s: No disk in drive\n", drive->name);
1230 break;
1231 case CAPACITY_INVALID:
1232 printk(KERN_ERR "%s: Invalid capacity for disk "
1233 "in drive\n", drive->name);
1234 break;
1235 }
1236 }
1237 if (!i) {
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001238 debug_log("Descriptor 0 Code: %d\n", descriptor->dc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 }
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001240 debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
1241 i, blocks * length / 1024, blocks, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 }
1243
1244 /* Clik! disk does not support get_flexible_disk_page */
1245 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1246 (void) idefloppy_get_flexible_disk_page(drive);
1247 }
1248
1249 set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
1250 return rc;
1251}
1252
1253/*
1254** Obtain the list of formattable capacities.
1255** Very similar to idefloppy_get_capacity, except that we push the capacity
1256** descriptors to userland, instead of our own structures.
1257**
1258** Userland gives us the following structure:
1259**
1260** struct idefloppy_format_capacities {
1261** int nformats;
1262** struct {
1263** int nblocks;
1264** int blocksize;
1265** } formats[];
1266** } ;
1267**
1268** userland initializes nformats to the number of allocated formats[]
1269** records. On exit we set nformats to the number of records we've
1270** actually initialized.
1271**
1272*/
1273
1274static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
1275{
1276 idefloppy_pc_t pc;
1277 idefloppy_capacity_header_t *header;
1278 idefloppy_capacity_descriptor_t *descriptor;
1279 int i, descriptors, blocks, length;
1280 int u_array_size;
1281 int u_index;
1282 int __user *argp;
1283
1284 if (get_user(u_array_size, arg))
1285 return (-EFAULT);
1286
1287 if (u_array_size <= 0)
1288 return (-EINVAL);
1289
1290 idefloppy_create_read_capacity_cmd(&pc);
1291 if (idefloppy_queue_pc_tail(drive, &pc)) {
1292 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
1293 return (-EIO);
1294 }
1295 header = (idefloppy_capacity_header_t *) pc.buffer;
1296 descriptors = header->length /
1297 sizeof(idefloppy_capacity_descriptor_t);
1298 descriptor = (idefloppy_capacity_descriptor_t *) (header + 1);
1299
1300 u_index = 0;
1301 argp = arg + 1;
1302
1303 /*
1304 ** We always skip the first capacity descriptor. That's the
1305 ** current capacity. We are interested in the remaining descriptors,
1306 ** the formattable capacities.
1307 */
1308
1309 for (i=0; i<descriptors; i++, descriptor++) {
1310 if (u_index >= u_array_size)
1311 break; /* User-supplied buffer too small */
1312 if (i == 0)
1313 continue; /* Skip the first descriptor */
1314
Borislav Petkov8f622432008-02-02 19:56:33 +01001315 blocks = be32_to_cpu(descriptor->blocks);
1316 length = be16_to_cpu(descriptor->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 if (put_user(blocks, argp))
1319 return(-EFAULT);
1320 ++argp;
1321
1322 if (put_user(length, argp))
1323 return (-EFAULT);
1324 ++argp;
1325
1326 ++u_index;
1327 }
1328
1329 if (put_user(u_index, arg))
1330 return (-EFAULT);
1331 return (0);
1332}
1333
1334/*
1335** Send ATAPI_FORMAT_UNIT to the drive.
1336**
1337** Userland gives us the following structure:
1338**
1339** struct idefloppy_format_command {
1340** int nblocks;
1341** int blocksize;
1342** int flags;
1343** } ;
1344**
1345** flags is a bitmask, currently, the only defined flag is:
1346**
1347** 0x01 - verify media after format.
1348*/
1349
1350static int idefloppy_begin_format(ide_drive_t *drive, int __user *arg)
1351{
1352 int blocks;
1353 int length;
1354 int flags;
1355 idefloppy_pc_t pc;
1356
1357 if (get_user(blocks, arg) ||
1358 get_user(length, arg+1) ||
1359 get_user(flags, arg+2)) {
1360 return (-EFAULT);
1361 }
1362
Borislav Petkov948391d2008-02-02 19:56:34 +01001363 (void) idefloppy_get_sfrp_bit(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1365 if (idefloppy_queue_pc_tail(drive, &pc)) {
1366 return (-EIO);
1367 }
1368
1369 return (0);
1370}
1371
1372/*
1373** Get ATAPI_FORMAT_UNIT progress indication.
1374**
Matt LaPlante0779bf22006-11-30 05:24:39 +01001375** Userland gives a pointer to an int. The int is set to a progress
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376** indicator 0-65536, with 65536=100%.
1377**
1378** If the drive does not support format progress indication, we just check
1379** the dsc bit, and return either 0 or 65536.
1380*/
1381
1382static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
1383{
1384 idefloppy_floppy_t *floppy = drive->driver_data;
1385 idefloppy_pc_t pc;
1386 int progress_indication = 0x10000;
1387
1388 if (floppy->srfp) {
1389 idefloppy_create_request_sense_cmd(&pc);
1390 if (idefloppy_queue_pc_tail(drive, &pc)) {
1391 return (-EIO);
1392 }
1393
1394 if (floppy->sense_key == 2 &&
1395 floppy->asc == 4 &&
1396 floppy->ascq == 4) {
1397 progress_indication = floppy->progress_indication;
1398 }
1399 /* Else assume format_unit has finished, and we're
1400 ** at 0x10000 */
1401 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 unsigned long flags;
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001403 u8 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405 local_irq_save(flags);
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001406 stat = drive->hwif->INB(IDE_STATUS_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 local_irq_restore(flags);
1408
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001409 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 }
1411 if (put_user(progress_indication, arg))
1412 return (-EFAULT);
1413
1414 return (0);
1415}
1416
1417/*
1418 * Return the current floppy capacity.
1419 */
1420static sector_t idefloppy_capacity (ide_drive_t *drive)
1421{
1422 idefloppy_floppy_t *floppy = drive->driver_data;
1423 unsigned long capacity = floppy->blocks * floppy->bs_factor;
1424
1425 return capacity;
1426}
1427
1428/*
1429 * idefloppy_identify_device checks if we can support a drive,
1430 * based on the ATAPI IDENTIFY command results.
1431 */
1432static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id)
1433{
1434 struct idefloppy_id_gcw gcw;
1435#if IDEFLOPPY_DEBUG_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 char buffer[80];
1437#endif /* IDEFLOPPY_DEBUG_INFO */
1438
1439 *((u16 *) &gcw) = id->config;
1440
1441#ifdef CONFIG_PPC
1442 /* kludge for Apple PowerBook internal zip */
1443 if ((gcw.device_type == 5) &&
1444 !strstr(id->model, "CD-ROM") &&
1445 strstr(id->model, "ZIP"))
1446 gcw.device_type = 0;
1447#endif
1448
1449#if IDEFLOPPY_DEBUG_INFO
1450 printk(KERN_INFO "Dumping ATAPI Identify Device floppy parameters\n");
1451 switch (gcw.protocol) {
1452 case 0: case 1: sprintf(buffer, "ATA");break;
1453 case 2: sprintf(buffer, "ATAPI");break;
1454 case 3: sprintf(buffer, "Reserved (Unknown to ide-floppy)");break;
1455 }
1456 printk(KERN_INFO "Protocol Type: %s\n", buffer);
1457 switch (gcw.device_type) {
1458 case 0: sprintf(buffer, "Direct-access Device");break;
1459 case 1: sprintf(buffer, "Streaming Tape Device");break;
1460 case 2: case 3: case 4: sprintf (buffer, "Reserved");break;
1461 case 5: sprintf(buffer, "CD-ROM Device");break;
1462 case 6: sprintf(buffer, "Reserved");
1463 case 7: sprintf(buffer, "Optical memory Device");break;
1464 case 0x1f: sprintf(buffer, "Unknown or no Device type");break;
1465 default: sprintf(buffer, "Reserved");
1466 }
1467 printk(KERN_INFO "Device Type: %x - %s\n", gcw.device_type, buffer);
1468 printk(KERN_INFO "Removable: %s\n",gcw.removable ? "Yes":"No");
1469 switch (gcw.drq_type) {
1470 case 0: sprintf(buffer, "Microprocessor DRQ");break;
1471 case 1: sprintf(buffer, "Interrupt DRQ");break;
1472 case 2: sprintf(buffer, "Accelerated DRQ");break;
1473 case 3: sprintf(buffer, "Reserved");break;
1474 }
1475 printk(KERN_INFO "Command Packet DRQ Type: %s\n", buffer);
1476 switch (gcw.packet_size) {
1477 case 0: sprintf(buffer, "12 bytes");break;
1478 case 1: sprintf(buffer, "16 bytes");break;
1479 default: sprintf(buffer, "Reserved");break;
1480 }
1481 printk(KERN_INFO "Command Packet Size: %s\n", buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482#endif /* IDEFLOPPY_DEBUG_INFO */
1483
1484 if (gcw.protocol != 2)
1485 printk(KERN_ERR "ide-floppy: Protocol is not ATAPI\n");
1486 else if (gcw.device_type != 0)
1487 printk(KERN_ERR "ide-floppy: Device type is not set to floppy\n");
1488 else if (!gcw.removable)
1489 printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
1490 else if (gcw.drq_type == 3) {
1491 printk(KERN_ERR "ide-floppy: Sorry, DRQ type %d not supported\n", gcw.drq_type);
1492 } else if (gcw.packet_size != 0) {
1493 printk(KERN_ERR "ide-floppy: Packet size is not 12 bytes long\n");
1494 } else
1495 return 1;
1496 return 0;
1497}
1498
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001499#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500static void idefloppy_add_settings(ide_drive_t *drive)
1501{
1502 idefloppy_floppy_t *floppy = drive->driver_data;
1503
1504/*
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +02001505 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 */
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +02001507 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL);
1508 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL);
1509 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL);
1510 ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &floppy->ticks, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511}
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001512#else
1513static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
1514#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
1516/*
1517 * Driver initialization.
1518 */
1519static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy)
1520{
1521 struct idefloppy_id_gcw gcw;
1522
1523 *((u16 *) &gcw) = drive->id->config;
1524 floppy->pc = floppy->pc_stack;
1525 if (gcw.drq_type == 1)
1526 set_bit(IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags);
1527 /*
1528 * We used to check revisions here. At this point however
1529 * I'm giving up. Just assume they are all broken, its easier.
1530 *
1531 * The actual reason for the workarounds was likely
1532 * a driver bug after all rather than a firmware bug,
1533 * and the workaround below used to hide it. It should
1534 * be fixed as of version 1.9, but to be on the safe side
1535 * we'll leave the limitation below for the 2.2.x tree.
1536 */
1537
1538 if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) {
1539 set_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags);
1540 /* This value will be visible in the /proc/ide/hdx/settings */
1541 floppy->ticks = IDEFLOPPY_TICKS_DELAY;
1542 blk_queue_max_sectors(drive->queue, 64);
1543 }
1544
1545 /*
1546 * Guess what? The IOMEGA Clik! drive also needs the
1547 * above fix. It makes nasty clicking noises without
1548 * it, so please don't remove this.
1549 */
1550 if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) {
1551 blk_queue_max_sectors(drive->queue, 64);
1552 set_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags);
1553 }
1554
1555
1556 (void) idefloppy_get_capacity(drive);
1557 idefloppy_add_settings(drive);
1558}
1559
Russell King4031bbe2006-01-06 11:41:00 +00001560static void ide_floppy_remove(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
1562 idefloppy_floppy_t *floppy = drive->driver_data;
1563 struct gendisk *g = floppy->disk;
1564
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001565 ide_proc_unregister_driver(drive, floppy->driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
1567 del_gendisk(g);
1568
1569 ide_floppy_put(floppy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570}
1571
Borislav Petkov9a24b632008-02-02 19:56:33 +01001572static void idefloppy_cleanup_obj(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573{
1574 struct ide_floppy_obj *floppy = to_ide_floppy(kref);
1575 ide_drive_t *drive = floppy->drive;
1576 struct gendisk *g = floppy->disk;
1577
1578 drive->driver_data = NULL;
1579 g->private_data = NULL;
1580 put_disk(g);
1581 kfree(floppy);
1582}
1583
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001584#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585static int proc_idefloppy_read_capacity
1586 (char *page, char **start, off_t off, int count, int *eof, void *data)
1587{
1588 ide_drive_t*drive = (ide_drive_t *)data;
1589 int len;
1590
1591 len = sprintf(page,"%llu\n", (long long)idefloppy_capacity(drive));
1592 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
1593}
1594
1595static ide_proc_entry_t idefloppy_proc[] = {
1596 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
1597 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
1598 { NULL, 0, NULL, NULL }
1599};
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001600#endif /* CONFIG_IDE_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Russell King4031bbe2006-01-06 11:41:00 +00001602static int ide_floppy_probe(ide_drive_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604static ide_driver_t idefloppy_driver = {
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001605 .gen_driver = {
Laurent Riffard4ef3b8f2005-11-18 22:15:40 +01001606 .owner = THIS_MODULE,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001607 .name = "ide-floppy",
1608 .bus = &ide_bus_type,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001609 },
Russell King4031bbe2006-01-06 11:41:00 +00001610 .probe = ide_floppy_probe,
1611 .remove = ide_floppy_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 .version = IDEFLOPPY_VERSION,
1613 .media = ide_floppy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 .supports_dsc_overlap = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 .do_request = idefloppy_do_request,
1616 .end_request = idefloppy_do_end_request,
1617 .error = __ide_error,
1618 .abort = __ide_abort,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001619#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 .proc = idefloppy_proc,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001621#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622};
1623
1624static int idefloppy_open(struct inode *inode, struct file *filp)
1625{
1626 struct gendisk *disk = inode->i_bdev->bd_disk;
1627 struct ide_floppy_obj *floppy;
1628 ide_drive_t *drive;
1629 idefloppy_pc_t pc;
1630 int ret = 0;
1631
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001632 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
1634 if (!(floppy = ide_floppy_get(disk)))
1635 return -ENXIO;
1636
1637 drive = floppy->drive;
1638
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001639 floppy->openers++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001641 if (floppy->openers == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1643 /* Just in case */
1644
1645 idefloppy_create_test_unit_ready_cmd(&pc);
1646 if (idefloppy_queue_pc_tail(drive, &pc)) {
1647 idefloppy_create_start_stop_cmd(&pc, 1);
1648 (void) idefloppy_queue_pc_tail(drive, &pc);
1649 }
1650
1651 if (idefloppy_get_capacity (drive)
1652 && (filp->f_flags & O_NDELAY) == 0
1653 /*
1654 ** Allow O_NDELAY to open a drive without a disk, or with
1655 ** an unreadable disk, so that we can get the format
1656 ** capacity of the drive or begin the format - Sam
1657 */
1658 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 ret = -EIO;
1660 goto out_put_floppy;
1661 }
1662
1663 if (floppy->wp && (filp->f_mode & 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 ret = -EROFS;
1665 goto out_put_floppy;
1666 }
1667 set_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
1668 /* IOMEGA Clik! drives do not support lock/unlock commands */
1669 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1670 idefloppy_create_prevent_cmd(&pc, 1);
1671 (void) idefloppy_queue_pc_tail(drive, &pc);
1672 }
1673 check_disk_change(inode->i_bdev);
1674 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 ret = -EBUSY;
1676 goto out_put_floppy;
1677 }
1678 return 0;
1679
1680out_put_floppy:
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001681 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 ide_floppy_put(floppy);
1683 return ret;
1684}
1685
1686static int idefloppy_release(struct inode *inode, struct file *filp)
1687{
1688 struct gendisk *disk = inode->i_bdev->bd_disk;
1689 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1690 ide_drive_t *drive = floppy->drive;
1691 idefloppy_pc_t pc;
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001692
1693 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001695 if (floppy->openers == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 /* IOMEGA Clik! drives do not support lock/unlock commands */
1697 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1698 idefloppy_create_prevent_cmd(&pc, 0);
1699 (void) idefloppy_queue_pc_tail(drive, &pc);
1700 }
1701
1702 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1703 }
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001704
1705 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 ide_floppy_put(floppy);
1708
1709 return 0;
1710}
1711
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08001712static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1713{
1714 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1715 ide_drive_t *drive = floppy->drive;
1716
1717 geo->heads = drive->bios_head;
1718 geo->sectors = drive->bios_sect;
1719 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
1720 return 0;
1721}
1722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723static int idefloppy_ioctl(struct inode *inode, struct file *file,
1724 unsigned int cmd, unsigned long arg)
1725{
1726 struct block_device *bdev = inode->i_bdev;
1727 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1728 ide_drive_t *drive = floppy->drive;
1729 void __user *argp = (void __user *)arg;
Ondrej Zary07203f62005-11-10 00:25:15 +01001730 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 int prevent = (arg) ? 1 : 0;
1732 idefloppy_pc_t pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 switch (cmd) {
1735 case CDROMEJECT:
1736 prevent = 0;
1737 /* fall through */
1738 case CDROM_LOCKDOOR:
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001739 if (floppy->openers > 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 return -EBUSY;
1741
1742 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */
1743 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1744 idefloppy_create_prevent_cmd(&pc, prevent);
1745 (void) idefloppy_queue_pc_tail(drive, &pc);
1746 }
1747 if (cmd == CDROMEJECT) {
1748 idefloppy_create_start_stop_cmd(&pc, 2);
1749 (void) idefloppy_queue_pc_tail(drive, &pc);
1750 }
1751 return 0;
1752 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
1753 return 0;
1754 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
1755 return idefloppy_get_format_capacities(drive, argp);
1756 case IDEFLOPPY_IOCTL_FORMAT_START:
1757
1758 if (!(file->f_mode & 2))
1759 return -EPERM;
1760
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001761 if (floppy->openers > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 /* Don't format if someone is using the disk */
1763
1764 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS,
1765 &floppy->flags);
1766 return -EBUSY;
1767 }
1768
1769 set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1770
1771 err = idefloppy_begin_format(drive, argp);
1772 if (err)
1773 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1774 return err;
1775 /*
1776 ** Note, the bit will be cleared when the device is
1777 ** closed. This is the cleanest way to handle the
1778 ** situation where the drive does not support
1779 ** format progress reporting.
1780 */
1781 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1782 return idefloppy_get_format_progress(drive, argp);
1783 }
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +02001784
1785 /*
1786 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
1787 * and CDROM_SEND_PACKET (legacy) ioctls
1788 */
1789 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
1790 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
1791 bdev->bd_disk, cmd, argp);
1792 else
1793 err = -ENOTTY;
1794
1795 if (err == -ENOTTY)
1796 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
1797
1798 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
1801static int idefloppy_media_changed(struct gendisk *disk)
1802{
1803 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1804 ide_drive_t *drive = floppy->drive;
1805
1806 /* do not scan partitions twice if this is a removable device */
1807 if (drive->attach) {
1808 drive->attach = 0;
1809 return 0;
1810 }
1811 return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
1812}
1813
1814static int idefloppy_revalidate_disk(struct gendisk *disk)
1815{
1816 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1817 set_capacity(disk, idefloppy_capacity(floppy->drive));
1818 return 0;
1819}
1820
1821static struct block_device_operations idefloppy_ops = {
1822 .owner = THIS_MODULE,
1823 .open = idefloppy_open,
1824 .release = idefloppy_release,
1825 .ioctl = idefloppy_ioctl,
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08001826 .getgeo = idefloppy_getgeo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 .media_changed = idefloppy_media_changed,
1828 .revalidate_disk= idefloppy_revalidate_disk
1829};
1830
Russell King4031bbe2006-01-06 11:41:00 +00001831static int ide_floppy_probe(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
1833 idefloppy_floppy_t *floppy;
1834 struct gendisk *g;
1835
1836 if (!strstr("ide-floppy", drive->driver_req))
1837 goto failed;
1838 if (!drive->present)
1839 goto failed;
1840 if (drive->media != ide_floppy)
1841 goto failed;
1842 if (!idefloppy_identify_device (drive, drive->id)) {
1843 printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
1844 goto failed;
1845 }
1846 if (drive->scsi) {
1847 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
1848 goto failed;
1849 }
Robert P. J. Day5cbded52006-12-13 00:35:56 -08001850 if ((floppy = kzalloc(sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name);
1852 goto failed;
1853 }
1854
1855 g = alloc_disk(1 << PARTN_BITS);
1856 if (!g)
1857 goto out_free_floppy;
1858
1859 ide_init_disk(g, drive);
1860
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001861 ide_proc_register_driver(drive, &idefloppy_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 kref_init(&floppy->kref);
1864
1865 floppy->drive = drive;
1866 floppy->driver = &idefloppy_driver;
1867 floppy->disk = g;
1868
1869 g->private_data = &floppy->driver;
1870
1871 drive->driver_data = floppy;
1872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 idefloppy_setup (drive, floppy);
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001874
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 g->minors = 1 << PARTN_BITS;
1876 g->driverfs_dev = &drive->gendev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
1878 g->fops = &idefloppy_ops;
1879 drive->attach = 1;
1880 add_disk(g);
1881 return 0;
1882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883out_free_floppy:
1884 kfree(floppy);
1885failed:
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001886 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887}
1888
1889MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
1890
1891static void __exit idefloppy_exit (void)
1892{
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001893 driver_unregister(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894}
1895
Bartlomiej Zolnierkiewicz17514e82005-11-19 22:24:35 +01001896static int __init idefloppy_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897{
1898 printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001899 return driver_register(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900}
1901
Kay Sievers263756e2005-12-12 18:03:44 +01001902MODULE_ALIAS("ide:*m-floppy*");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903module_init(idefloppy_init);
1904module_exit(idefloppy_exit);
1905MODULE_LICENSE("GPL");