blob: b56e37d015937c3a91c1d80afa35a18784ca349c [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
Borislav Petkovf373bd82008-02-02 19:56:36 +010050/* define to see debug info */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define IDEFLOPPY_DEBUG_LOG 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
54#define IDEFLOPPY_DEBUG( fmt, args... )
55
56#if IDEFLOPPY_DEBUG_LOG
Borislav Petkovbcc77d92008-02-02 19:56:34 +010057#define debug_log(fmt, args...) \
58 printk(KERN_INFO "ide-floppy: " fmt, ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#else
60#define debug_log(fmt, args... ) do {} while(0)
61#endif
62
63
64/*
65 * Some drives require a longer irq timeout.
66 */
67#define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
68
69/*
70 * After each failed packet command we issue a request sense command
71 * and retry the packet command IDEFLOPPY_MAX_PC_RETRIES times.
72 */
73#define IDEFLOPPY_MAX_PC_RETRIES 3
74
75/*
76 * With each packet command, we allocate a buffer of
77 * IDEFLOPPY_PC_BUFFER_SIZE bytes.
78 */
79#define IDEFLOPPY_PC_BUFFER_SIZE 256
80
81/*
82 * In various places in the driver, we need to allocate storage
83 * for packet commands and requests, which will remain valid while
84 * we leave the driver to wait for an interrupt or a timeout event.
85 */
86#define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
87
88/*
89 * Our view of a packet command.
90 */
91typedef struct idefloppy_packet_command_s {
92 u8 c[12]; /* Actual packet bytes */
93 int retries; /* On each retry, we increment retries */
94 int error; /* Error code */
95 int request_transfer; /* Bytes to transfer */
96 int actually_transferred; /* Bytes actually transferred */
97 int buffer_size; /* Size of our data buffer */
98 int b_count; /* Missing/Available data on the current buffer */
99 struct request *rq; /* The corresponding request */
100 u8 *buffer; /* Data buffer */
101 u8 *current_position; /* Pointer into the above buffer */
102 void (*callback) (ide_drive_t *); /* Called when this packet command is completed */
103 u8 pc_buffer[IDEFLOPPY_PC_BUFFER_SIZE]; /* Temporary buffer */
104 unsigned long flags; /* Status/Action bit flags: long for set_bit */
105} idefloppy_pc_t;
106
107/*
108 * Packet command flag bits.
109 */
110#define PC_ABORT 0 /* Set when an error is considered normal - We won't retry */
111#define PC_DMA_RECOMMENDED 2 /* 1 when we prefer to use DMA if possible */
112#define PC_DMA_IN_PROGRESS 3 /* 1 while DMA in progress */
113#define PC_DMA_ERROR 4 /* 1 when encountered problem during DMA */
114#define PC_WRITING 5 /* Data direction */
115
116#define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */
117
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100118/* format capacities descriptor codes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#define CAPACITY_INVALID 0x00
120#define CAPACITY_UNFORMATTED 0x01
121#define CAPACITY_CURRENT 0x02
122#define CAPACITY_NO_CARTRIDGE 0x03
123
124/*
125 * Most of our global data which we need to save even as we leave the
126 * driver due to an interrupt or a timer event is stored in a variable
127 * of type idefloppy_floppy_t, defined below.
128 */
129typedef struct ide_floppy_obj {
130 ide_drive_t *drive;
131 ide_driver_t *driver;
132 struct gendisk *disk;
133 struct kref kref;
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +0100134 unsigned int openers; /* protected by BKL for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /* Current packet command */
137 idefloppy_pc_t *pc;
138 /* Last failed packet command */
139 idefloppy_pc_t *failed_pc;
140 /* Packet command stack */
141 idefloppy_pc_t pc_stack[IDEFLOPPY_PC_STACK];
142 /* Next free packet command storage space */
143 int pc_stack_index;
144 struct request rq_stack[IDEFLOPPY_PC_STACK];
145 /* We implement a circular array */
146 int rq_stack_index;
147
148 /*
149 * Last error information
150 */
151 u8 sense_key, asc, ascq;
152 /* delay this long before sending packet command */
153 u8 ticks;
154 int progress_indication;
155
156 /*
157 * Device information
158 */
159 /* Current format */
160 int blocks, block_size, bs_factor;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100161 /* Last format capacity descriptor */
162 u8 cap_desc[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* Copy of the flexible disk page */
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100164 u8 flexible_disk_page[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /* Write protect */
166 int wp;
167 /* Supports format progress report */
168 int srfp;
169 /* Status/Action flags */
170 unsigned long flags;
171} idefloppy_floppy_t;
172
Bartlomiej Zolnierkiewiczc40d3d32005-08-18 22:09:21 +0200173#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175/*
176 * Floppy flag bits values.
177 */
178#define IDEFLOPPY_DRQ_INTERRUPT 0 /* DRQ interrupt device */
179#define IDEFLOPPY_MEDIA_CHANGED 1 /* Media may have changed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#define IDEFLOPPY_FORMAT_IN_PROGRESS 3 /* Format in progress */
181#define IDEFLOPPY_CLIK_DRIVE 4 /* Avoid commands not supported in Clik drive */
182#define IDEFLOPPY_ZIP_DRIVE 5 /* Requires BH algorithm for packets */
183
184/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 * Defines for the mode sense command
186 */
187#define MODE_SENSE_CURRENT 0x00
188#define MODE_SENSE_CHANGEABLE 0x01
189#define MODE_SENSE_DEFAULT 0x02
190#define MODE_SENSE_SAVED 0x03
191
192/*
193 * IOCTLs used in low-level formatting.
194 */
195
196#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
197#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
198#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
199#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/*
202 * Error codes which are returned in rq->errors to the higher part
203 * of the driver.
204 */
205#define IDEFLOPPY_ERROR_GENERAL 101
206
207/*
208 * The following is used to format the general configuration word of
209 * the ATAPI IDENTIFY DEVICE command.
210 */
211struct idefloppy_id_gcw {
212#if defined(__LITTLE_ENDIAN_BITFIELD)
213 unsigned packet_size :2; /* Packet Size */
214 unsigned reserved234 :3; /* Reserved */
215 unsigned drq_type :2; /* Command packet DRQ type */
216 unsigned removable :1; /* Removable media */
217 unsigned device_type :5; /* Device type */
218 unsigned reserved13 :1; /* Reserved */
219 unsigned protocol :2; /* Protocol type */
220#elif defined(__BIG_ENDIAN_BITFIELD)
221 unsigned protocol :2; /* Protocol type */
222 unsigned reserved13 :1; /* Reserved */
223 unsigned device_type :5; /* Device type */
224 unsigned removable :1; /* Removable media */
225 unsigned drq_type :2; /* Command packet DRQ type */
226 unsigned reserved234 :3; /* Reserved */
227 unsigned packet_size :2; /* Packet Size */
228#else
229#error "Bitfield endianness not defined! Check your byteorder.h"
230#endif
231};
232
233/*
Borislav Petkov948391d2008-02-02 19:56:34 +0100234 * Pages of the SELECT SENSE / MODE SENSE packet commands.
235 * See SFF-8070i spec.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 */
237#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
238#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
239
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800240static DEFINE_MUTEX(idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
243
244#define ide_floppy_g(disk) \
245 container_of((disk)->private_data, struct ide_floppy_obj, driver)
246
247static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
248{
249 struct ide_floppy_obj *floppy = NULL;
250
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800251 mutex_lock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 floppy = ide_floppy_g(disk);
253 if (floppy)
254 kref_get(&floppy->kref);
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800255 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 return floppy;
257}
258
Borislav Petkov9a24b632008-02-02 19:56:33 +0100259static void idefloppy_cleanup_obj(struct kref *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261static void ide_floppy_put(struct ide_floppy_obj *floppy)
262{
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800263 mutex_lock(&idefloppy_ref_mutex);
Borislav Petkov9a24b632008-02-02 19:56:33 +0100264 kref_put(&floppy->kref, idefloppy_cleanup_obj);
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800265 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
268/*
269 * Too bad. The drive wants to send us data which we are not ready to accept.
270 * Just throw it away.
271 */
272static void idefloppy_discard_data (ide_drive_t *drive, unsigned int bcount)
273{
274 while (bcount--)
275 (void) HWIF(drive)->INB(IDE_DATA_REG);
276}
277
Borislav Petkov0bf399e2008-02-02 19:56:36 +0100278static void idefloppy_write_zeros(ide_drive_t *drive, unsigned int bcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
280 while (bcount--)
281 HWIF(drive)->OUTB(0, IDE_DATA_REG);
282}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284
285/*
286 * idefloppy_do_end_request is used to finish servicing a request.
287 *
288 * For read/write requests, we will call ide_end_request to pass to the
289 * next buffer.
290 */
291static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs)
292{
293 idefloppy_floppy_t *floppy = drive->driver_data;
294 struct request *rq = HWGROUP(drive)->rq;
295 int error;
296
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100297 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 switch (uptodate) {
300 case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
301 case 1: error = 0; break;
302 default: error = uptodate;
303 }
304 if (error)
305 floppy->failed_pc = NULL;
306 /* Why does this happen? */
307 if (!rq)
308 return 0;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200309 if (!blk_special_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 /* our real local end request function */
311 ide_end_request(drive, uptodate, nsecs);
312 return 0;
313 }
314 rq->errors = error;
315 /* fixme: need to move this local also */
316 ide_end_drive_cmd(drive, 0, 0);
317 return 0;
318}
319
Borislav Petkov32925e12008-02-02 19:56:36 +0100320static void ide_floppy_io_buffers(ide_drive_t *drive, idefloppy_pc_t *pc,
321 unsigned int bcount, int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 struct request *rq = pc->rq;
NeilBrown5705f702007-09-25 12:35:59 +0200324 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 struct bio_vec *bvec;
326 unsigned long flags;
NeilBrown5705f702007-09-25 12:35:59 +0200327 int count, done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 char *data;
329
NeilBrown5705f702007-09-25 12:35:59 +0200330 rq_for_each_segment(bvec, rq, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200331 if (!bcount)
332 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Jens Axboe6c92e692007-08-16 13:43:12 +0200334 count = min(bvec->bv_len, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Jens Axboe6c92e692007-08-16 13:43:12 +0200336 data = bvec_kmap_irq(bvec, &flags);
Borislav Petkov32925e12008-02-02 19:56:36 +0100337 if (direction)
338 drive->hwif->atapi_output_bytes(drive, data, count);
339 else
340 drive->hwif->atapi_input_bytes(drive, data, count);
Jens Axboe6c92e692007-08-16 13:43:12 +0200341 bvec_kunmap_irq(data, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Jens Axboe6c92e692007-08-16 13:43:12 +0200343 bcount -= count;
344 pc->b_count += count;
345 done += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347
348 idefloppy_do_end_request(drive, 1, done >> 9);
349
350 if (bcount) {
Borislav Petkov32925e12008-02-02 19:56:36 +0100351 printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
352 drive->name, __func__, bcount);
353 if (direction)
354 idefloppy_write_zeros(drive, bcount);
355 else
356 idefloppy_discard_data(drive, bcount);
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
359}
360
361static void idefloppy_update_buffers (ide_drive_t *drive, idefloppy_pc_t *pc)
362{
363 struct request *rq = pc->rq;
364 struct bio *bio = rq->bio;
365
366 while ((bio = rq->bio) != NULL)
367 idefloppy_do_end_request(drive, 1, 0);
368}
369
370/*
371 * idefloppy_queue_pc_head generates a new packet command request in front
372 * of the request queue, before the current request, so that it will be
373 * processed immediately, on the next pass through the driver.
374 */
375static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struct request *rq)
376{
377 struct ide_floppy_obj *floppy = drive->driver_data;
378
379 ide_init_drive_cmd(rq);
380 rq->buffer = (char *) pc;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200381 rq->cmd_type = REQ_TYPE_SPECIAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 rq->rq_disk = floppy->disk;
383 (void) ide_do_drive_cmd(drive, rq, ide_preempt);
384}
385
386static idefloppy_pc_t *idefloppy_next_pc_storage (ide_drive_t *drive)
387{
388 idefloppy_floppy_t *floppy = drive->driver_data;
389
390 if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
391 floppy->pc_stack_index=0;
392 return (&floppy->pc_stack[floppy->pc_stack_index++]);
393}
394
395static struct request *idefloppy_next_rq_storage (ide_drive_t *drive)
396{
397 idefloppy_floppy_t *floppy = drive->driver_data;
398
399 if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK)
400 floppy->rq_stack_index = 0;
401 return (&floppy->rq_stack[floppy->rq_stack_index++]);
402}
403
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100404static void idefloppy_request_sense_callback(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
406 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100407 u8 *buf = floppy->pc->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100409 debug_log("Reached %s\n", __func__);
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (!floppy->pc->error) {
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100412 floppy->sense_key = buf[2] & 0x0F;
413 floppy->asc = buf[12];
414 floppy->ascq = buf[13];
415 floppy->progress_indication = buf[15] & 0x80 ?
416 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
417
418 if (floppy->failed_pc)
419 debug_log("pc = %x, sense key = %x, asc = %x,"
420 " ascq = %x\n",
421 floppy->failed_pc->c[0],
422 floppy->sense_key,
423 floppy->asc,
424 floppy->ascq);
425 else
426 debug_log("sense key = %x, asc = %x, ascq = %x\n",
427 floppy->sense_key,
428 floppy->asc,
429 floppy->ascq);
430
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 idefloppy_do_end_request(drive, 1, 0);
433 } else {
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100434 printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting"
435 " request!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 idefloppy_do_end_request(drive, 0, 0);
437 }
438}
439
440/*
441 * General packet command callback function.
442 */
443static void idefloppy_pc_callback (ide_drive_t *drive)
444{
445 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100446
447 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 idefloppy_do_end_request(drive, floppy->pc->error ? 0 : 1, 0);
450}
451
452/*
453 * idefloppy_init_pc initializes a packet command.
454 */
455static void idefloppy_init_pc (idefloppy_pc_t *pc)
456{
457 memset(pc->c, 0, 12);
458 pc->retries = 0;
459 pc->flags = 0;
460 pc->request_transfer = 0;
461 pc->buffer = pc->pc_buffer;
462 pc->buffer_size = IDEFLOPPY_PC_BUFFER_SIZE;
463 pc->callback = &idefloppy_pc_callback;
464}
465
466static void idefloppy_create_request_sense_cmd (idefloppy_pc_t *pc)
467{
Borislav Petkov30d67092008-02-02 19:56:33 +0100468 idefloppy_init_pc(pc);
469 pc->c[0] = GPCMD_REQUEST_SENSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 pc->c[4] = 255;
471 pc->request_transfer = 18;
472 pc->callback = &idefloppy_request_sense_callback;
473}
474
475/*
476 * idefloppy_retry_pc is called when an error was detected during the
477 * last packet command. We queue a request sense packet command in
478 * the head of the request list.
479 */
480static void idefloppy_retry_pc (ide_drive_t *drive)
481{
482 idefloppy_pc_t *pc;
483 struct request *rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100485 (void)drive->hwif->INB(IDE_ERROR_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 pc = idefloppy_next_pc_storage(drive);
487 rq = idefloppy_next_rq_storage(drive);
488 idefloppy_create_request_sense_cmd(pc);
489 idefloppy_queue_pc_head(drive, pc, rq);
490}
491
Borislav Petkov0eea6452008-02-02 19:56:36 +0100492/* The usual interrupt handler called during a packet command. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
494{
495 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100496 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 idefloppy_pc_t *pc = floppy->pc;
498 struct request *rq = pc->rq;
Borislav Petkov0eea6452008-02-02 19:56:36 +0100499 xfer_func_t *xferfunc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 unsigned int temp;
Borislav Petkovd30a7fb2008-02-02 19:56:35 +0100501 int dma_error = 0;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100502 u16 bcount;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100503 u8 stat, ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100505 debug_log("Reached %s interrupt handler\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
Borislav Petkovd30a7fb2008-02-02 19:56:35 +0100508 dma_error = hwif->ide_dma_end(drive);
509 if (dma_error) {
510 printk(KERN_ERR "%s: DMA %s error\n", drive->name,
511 rq_data_dir(rq) ? "write" : "read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 set_bit(PC_DMA_ERROR, &pc->flags);
513 } else {
514 pc->actually_transferred = pc->request_transfer;
515 idefloppy_update_buffers(drive, pc);
516 }
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100517 debug_log("DMA finished\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519
520 /* Clear the interrupt */
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100521 stat = drive->hwif->INB(IDE_STATUS_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100523 if ((stat & DRQ_STAT) == 0) { /* No more interrupts */
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100524 debug_log("Packet command completed, %d bytes transferred\n",
525 pc->actually_transferred);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
527
Ingo Molnar366c7f52006-07-03 00:25:25 -0700528 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100530 if ((stat & ERR_STAT) || test_bit(PC_DMA_ERROR, &pc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* Error detected */
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100532 debug_log("%s: I/O error\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 rq->errors++;
Borislav Petkov30d67092008-02-02 19:56:33 +0100534 if (pc->c[0] == GPCMD_REQUEST_SENSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 printk(KERN_ERR "ide-floppy: I/O error in "
536 "request sense command\n");
537 return ide_do_reset(drive);
538 }
539 /* Retry operation */
540 idefloppy_retry_pc(drive);
541 /* queued, but not started */
542 return ide_stopped;
543 }
544 pc->error = 0;
545 if (floppy->failed_pc == pc)
546 floppy->failed_pc = NULL;
547 /* Command finished - Call the callback function */
548 pc->callback(drive);
549 return ide_stopped;
550 }
551
552 if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
553 printk(KERN_ERR "ide-floppy: The floppy wants to issue "
554 "more interrupts in DMA mode\n");
Bartlomiej Zolnierkiewicz7469aaf2007-02-17 02:40:26 +0100555 ide_dma_off(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 return ide_do_reset(drive);
557 }
558
559 /* Get the number of bytes to transfer */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100560 bcount = (hwif->INB(IDE_BCOUNTH_REG) << 8) |
561 hwif->INB(IDE_BCOUNTL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 /* on this interrupt */
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100563 ireason = hwif->INB(IDE_IREASON_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100565 if (ireason & CD) {
Borislav Petkov0eea6452008-02-02 19:56:36 +0100566 printk(KERN_ERR "ide-floppy: CoD != 0 in %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 return ide_do_reset(drive);
568 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100569 if (((ireason & IO) == IO) == test_bit(PC_WRITING, &pc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 /* Hopefully, we will never get here */
571 printk(KERN_ERR "ide-floppy: We wanted to %s, ",
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100572 (ireason & IO) ? "Write" : "Read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 printk(KERN_ERR "but the floppy wants us to %s !\n",
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100574 (ireason & IO) ? "Read" : "Write");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 return ide_do_reset(drive);
576 }
577 if (!test_bit(PC_WRITING, &pc->flags)) {
578 /* Reading - Check that we have enough space */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100579 temp = pc->actually_transferred + bcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 if (temp > pc->request_transfer) {
581 if (temp > pc->buffer_size) {
582 printk(KERN_ERR "ide-floppy: The floppy wants "
583 "to send us more data than expected "
584 "- discarding data\n");
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100585 idefloppy_discard_data(drive, bcount);
Borislav Petkov0078df22008-02-02 19:56:33 +0100586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 ide_set_handler(drive,
588 &idefloppy_pc_intr,
589 IDEFLOPPY_WAIT_CMD,
590 NULL);
591 return ide_started;
592 }
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100593 debug_log("The floppy wants to send us more data than"
594 " expected - allowing transfer\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
596 }
Borislav Petkov32925e12008-02-02 19:56:36 +0100597 if (test_bit(PC_WRITING, &pc->flags))
Borislav Petkov0eea6452008-02-02 19:56:36 +0100598 xferfunc = hwif->atapi_output_bytes;
Borislav Petkov32925e12008-02-02 19:56:36 +0100599 else
Borislav Petkov0eea6452008-02-02 19:56:36 +0100600 xferfunc = hwif->atapi_input_bytes;
Borislav Petkov0eea6452008-02-02 19:56:36 +0100601
602 if (pc->buffer)
603 xferfunc(drive, pc->current_position, bcount);
604 else
Borislav Petkov32925e12008-02-02 19:56:36 +0100605 ide_floppy_io_buffers(drive, pc, bcount,
606 test_bit(PC_WRITING, &pc->flags));
Borislav Petkov0eea6452008-02-02 19:56:36 +0100607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /* Update the current position */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100609 pc->actually_transferred += bcount;
610 pc->current_position += bcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Borislav Petkov32925e12008-02-02 19:56:36 +0100612 /* And set the interrupt handler again */
613 ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 return ide_started;
615}
616
617/*
618 * This is the original routine that did the packet transfer.
619 * It fails at high speeds on the Iomega ZIP drive, so there's a slower version
620 * for that drive below. The algorithm is chosen based on drive type
621 */
622static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive)
623{
624 ide_startstop_t startstop;
625 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100626 u8 ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
629 printk(KERN_ERR "ide-floppy: Strange, packet command "
630 "initiated yet DRQ isn't asserted\n");
631 return startstop;
632 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100633 ireason = drive->hwif->INB(IDE_IREASON_REG);
634 if ((ireason & CD) == 0 || (ireason & IO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) while "
636 "issuing a packet command\n");
637 return ide_do_reset(drive);
638 }
Borislav Petkov0078df22008-02-02 19:56:33 +0100639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 /* Set the interrupt routine */
641 ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
642 /* Send the actual packet */
643 HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
644 return ide_started;
645}
646
647
648/*
649 * What we have here is a classic case of a top half / bottom half
650 * interrupt service routine. In interrupt mode, the device sends
651 * an interrupt to signal it's ready to receive a packet. However,
652 * we need to delay about 2-3 ticks before issuing the packet or we
653 * gets in trouble.
654 *
655 * So, follow carefully. transfer_pc1 is called as an interrupt (or
656 * directly). In either case, when the device says it's ready for a
657 * packet, we schedule the packet transfer to occur about 2-3 ticks
658 * later in transfer_pc2.
659 */
660static int idefloppy_transfer_pc2 (ide_drive_t *drive)
661{
662 idefloppy_floppy_t *floppy = drive->driver_data;
663
664 /* Send the actual packet */
665 HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
666 /* Timeout for the packet command */
667 return IDEFLOPPY_WAIT_CMD;
668}
669
670static ide_startstop_t idefloppy_transfer_pc1 (ide_drive_t *drive)
671{
672 idefloppy_floppy_t *floppy = drive->driver_data;
673 ide_startstop_t startstop;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100674 u8 ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
677 printk(KERN_ERR "ide-floppy: Strange, packet command "
678 "initiated yet DRQ isn't asserted\n");
679 return startstop;
680 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100681 ireason = drive->hwif->INB(IDE_IREASON_REG);
682 if ((ireason & CD) == 0 || (ireason & IO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) "
684 "while issuing a packet command\n");
685 return ide_do_reset(drive);
686 }
687 /*
688 * The following delay solves a problem with ATAPI Zip 100 drives
689 * where the Busy flag was apparently being deasserted before the
690 * unit was ready to receive data. This was happening on a
691 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
692 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
693 * used until after the packet is moved in about 50 msec.
694 */
Borislav Petkov0078df22008-02-02 19:56:33 +0100695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 ide_set_handler(drive,
697 &idefloppy_pc_intr, /* service routine for packet command */
698 floppy->ticks, /* wait this long before "failing" */
699 &idefloppy_transfer_pc2); /* fail == transfer_pc2 */
700 return ide_started;
701}
702
Borislav Petkovd652c132008-02-02 19:56:35 +0100703static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
704 idefloppy_pc_t *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705{
Borislav Petkovd652c132008-02-02 19:56:35 +0100706 /* supress error messages resulting from Medium not present */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 if (floppy->sense_key == 0x02 &&
708 floppy->asc == 0x3a &&
709 floppy->ascq == 0x00)
Borislav Petkovd652c132008-02-02 19:56:35 +0100710 return;
711
712 printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, "
713 "asc = %2x, ascq = %2x\n",
714 floppy->drive->name, pc->c[0], floppy->sense_key,
715 floppy->asc, floppy->ascq);
716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717}
718
719/*
720 * Issue a packet command
721 */
722static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *pc)
723{
724 idefloppy_floppy_t *floppy = drive->driver_data;
725 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 ide_handler_t *pkt_xfer_routine;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100727 u16 bcount;
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100728 u8 dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 if (floppy->failed_pc == NULL &&
Borislav Petkov30d67092008-02-02 19:56:33 +0100731 pc->c[0] != GPCMD_REQUEST_SENSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 floppy->failed_pc = pc;
733 /* Set the current packet command */
734 floppy->pc = pc;
735
736 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES ||
737 test_bit(PC_ABORT, &pc->flags)) {
738 /*
739 * We will "abort" retrying a packet command in case
740 * a legitimate error code was received.
741 */
742 if (!test_bit(PC_ABORT, &pc->flags)) {
Borislav Petkovd652c132008-02-02 19:56:35 +0100743 if (!test_bit(PC_SUPPRESS_ERROR, &pc->flags))
744 ide_floppy_report_error(floppy, pc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 /* Giving up */
746 pc->error = IDEFLOPPY_ERROR_GENERAL;
747 }
748 floppy->failed_pc = NULL;
749 pc->callback(drive);
750 return ide_stopped;
751 }
752
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100753 debug_log("Retry number - %d\n", pc->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 pc->retries++;
756 /* We haven't transferred any data yet */
757 pc->actually_transferred = 0;
758 pc->current_position = pc->buffer;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100759 bcount = min(pc->request_transfer, 63 * 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Bartlomiej Zolnierkiewicz7469aaf2007-02-17 02:40:26 +0100761 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags))
762 ide_dma_off(drive);
763
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100764 dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100767 dma = !hwif->dma_setup(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Bartlomiej Zolnierkiewicz2fc57382008-01-25 22:17:13 +0100769 ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK |
770 IDE_TFLAG_OUT_DEVICE, bcount, dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100772 if (dma) { /* Begin DMA, if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 set_bit(PC_DMA_IN_PROGRESS, &pc->flags);
774 hwif->dma_start(drive);
775 }
776
777 /* Can we transfer the packet when we get the interrupt or wait? */
778 if (test_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags)) {
779 /* wait */
780 pkt_xfer_routine = &idefloppy_transfer_pc1;
781 } else {
782 /* immediate */
783 pkt_xfer_routine = &idefloppy_transfer_pc;
784 }
785
786 if (test_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags)) {
787 /* Issue the packet command */
788 ide_execute_command(drive, WIN_PACKETCMD,
789 pkt_xfer_routine,
790 IDEFLOPPY_WAIT_CMD,
791 NULL);
792 return ide_started;
793 } else {
794 /* Issue the packet command */
795 HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
796 return (*pkt_xfer_routine) (drive);
797 }
798}
799
800static void idefloppy_rw_callback (ide_drive_t *drive)
801{
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100802 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 idefloppy_do_end_request(drive, 1, 0);
805 return;
806}
807
808static void idefloppy_create_prevent_cmd (idefloppy_pc_t *pc, int prevent)
809{
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100810 debug_log("creating prevent removal command, prevent = %d\n", prevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100813 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 pc->c[4] = prevent;
815}
816
817static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t *pc)
818{
819 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100820 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 pc->c[7] = 255;
822 pc->c[8] = 255;
823 pc->request_transfer = 255;
824}
825
826static void idefloppy_create_format_unit_cmd (idefloppy_pc_t *pc, int b, int l,
827 int flags)
828{
829 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100830 pc->c[0] = GPCMD_FORMAT_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 pc->c[1] = 0x17;
832
833 memset(pc->buffer, 0, 12);
834 pc->buffer[1] = 0xA2;
835 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
836
837 if (flags & 1) /* Verify bit on... */
838 pc->buffer[1] ^= 0x20; /* ... turn off DCRT bit */
839 pc->buffer[3] = 8;
840
Borislav Petkov8f622432008-02-02 19:56:33 +0100841 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buffer[4]));
842 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buffer[8]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 pc->buffer_size=12;
844 set_bit(PC_WRITING, &pc->flags);
845}
846
847/*
848 * A mode sense command is used to "sense" floppy parameters.
849 */
850static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t *pc, u8 page_code, u8 type)
851{
Borislav Petkov24a5d702008-02-02 19:56:34 +0100852 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100855 pc->c[0] = GPCMD_MODE_SENSE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 pc->c[1] = 0;
857 pc->c[2] = page_code + (type << 6);
858
859 switch (page_code) {
860 case IDEFLOPPY_CAPABILITIES_PAGE:
861 length += 12;
862 break;
863 case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
864 length += 32;
865 break;
866 default:
867 printk(KERN_ERR "ide-floppy: unsupported page code "
868 "in create_mode_sense_cmd\n");
869 }
Borislav Petkov8f622432008-02-02 19:56:33 +0100870 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 pc->request_transfer = length;
872}
873
874static void idefloppy_create_start_stop_cmd (idefloppy_pc_t *pc, int start)
875{
876 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100877 pc->c[0] = GPCMD_START_STOP_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 pc->c[4] = start;
879}
880
881static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t *pc)
882{
883 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100884 pc->c[0] = GPCMD_TEST_UNIT_READY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885}
886
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100887static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
888 idefloppy_pc_t *pc, struct request *rq,
889 unsigned long sector)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
891 int block = sector / floppy->bs_factor;
892 int blocks = rq->nr_sectors / floppy->bs_factor;
893 int cmd = rq_data_dir(rq);
894
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100895 debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 block, blocks);
897
898 idefloppy_init_pc(pc);
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100899 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
900 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
Borislav Petkov8f622432008-02-02 19:56:33 +0100901 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 pc->callback = &idefloppy_rw_callback;
904 pc->rq = rq;
905 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200906 if (rq->cmd_flags & REQ_RW)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 set_bit(PC_WRITING, &pc->flags);
908 pc->buffer = NULL;
909 pc->request_transfer = pc->buffer_size = blocks * floppy->block_size;
910 set_bit(PC_DMA_RECOMMENDED, &pc->flags);
911}
912
Jens Axboe3d6392c2007-07-09 12:38:05 +0200913static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq)
915{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 idefloppy_init_pc(pc);
Jens Axboe3d6392c2007-07-09 12:38:05 +0200917 pc->callback = &idefloppy_rw_callback;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 memcpy(pc->c, rq->cmd, sizeof(pc->c));
Jens Axboe3d6392c2007-07-09 12:38:05 +0200919 pc->rq = rq;
920 pc->b_count = rq->data_len;
921 if (rq->data_len && rq_data_dir(rq) == WRITE)
922 set_bit(PC_WRITING, &pc->flags);
923 pc->buffer = rq->data;
924 if (rq->bio)
925 set_bit(PC_DMA_RECOMMENDED, &pc->flags);
926
927 /*
928 * possibly problematic, doesn't look like ide-floppy correctly
929 * handled scattered requests if dma fails...
930 */
931 pc->request_transfer = pc->buffer_size = rq->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
934/*
935 * idefloppy_do_request is our request handling function.
936 */
937static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request *rq, sector_t block_s)
938{
939 idefloppy_floppy_t *floppy = drive->driver_data;
940 idefloppy_pc_t *pc;
941 unsigned long block = (unsigned long)block_s;
942
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100943 debug_log("dev: %s, cmd_type: %x, errors: %d\n",
Randy Dunlap18cddac2006-06-25 05:48:56 -0700944 rq->rq_disk ? rq->rq_disk->disk_name : "?",
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100945 rq->cmd_type, rq->errors);
946 debug_log("sector: %ld, nr_sectors: %ld, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 "current_nr_sectors: %d\n", (long)rq->sector,
948 rq->nr_sectors, rq->current_nr_sectors);
949
950 if (rq->errors >= ERROR_MAX) {
Borislav Petkovd652c132008-02-02 19:56:35 +0100951 if (floppy->failed_pc)
952 ide_floppy_report_error(floppy, floppy->failed_pc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 else
954 printk(KERN_ERR "ide-floppy: %s: I/O error\n",
955 drive->name);
956 idefloppy_do_end_request(drive, 0, 0);
957 return ide_stopped;
958 }
Jens Axboe4aff5e22006-08-10 08:44:47 +0200959 if (blk_fs_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (((long)rq->sector % floppy->bs_factor) ||
961 (rq->nr_sectors % floppy->bs_factor)) {
962 printk("%s: unsupported r/w request size\n",
963 drive->name);
964 idefloppy_do_end_request(drive, 0, 0);
965 return ide_stopped;
966 }
967 pc = idefloppy_next_pc_storage(drive);
968 idefloppy_create_rw_cmd(floppy, pc, rq, block);
Jens Axboe4aff5e22006-08-10 08:44:47 +0200969 } else if (blk_special_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 pc = (idefloppy_pc_t *) rq->buffer;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200971 } else if (blk_pc_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 pc = idefloppy_next_pc_storage(drive);
Jens Axboe3d6392c2007-07-09 12:38:05 +0200973 idefloppy_blockpc_cmd(floppy, pc, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 } else {
975 blk_dump_rq_flags(rq,
976 "ide-floppy: unsupported command in queue");
977 idefloppy_do_end_request(drive, 0, 0);
978 return ide_stopped;
979 }
980
981 pc->rq = rq;
982 return idefloppy_issue_pc(drive, pc);
983}
984
985/*
986 * idefloppy_queue_pc_tail adds a special packet command request to the
987 * tail of the request queue, and waits for it to be serviced.
988 */
989static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc)
990{
991 struct ide_floppy_obj *floppy = drive->driver_data;
992 struct request rq;
993
994 ide_init_drive_cmd (&rq);
995 rq.buffer = (char *) pc;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200996 rq.cmd_type = REQ_TYPE_SPECIAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 rq.rq_disk = floppy->disk;
998
999 return ide_do_drive_cmd(drive, &rq, ide_wait);
1000}
1001
1002/*
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001003 * Look at the flexible disk page parameters. We ignore the CHS capacity
1004 * parameters and use the LBA parameters instead.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 */
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001006static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007{
1008 idefloppy_floppy_t *floppy = drive->driver_data;
1009 idefloppy_pc_t pc;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001010 u8 *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 int capacity, lba_capacity;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001012 u16 transfer_rate, sector_size, cyls, rpm;
1013 u8 heads, sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001015 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE,
1016 MODE_SENSE_CURRENT);
1017
1018 if (idefloppy_queue_pc_tail(drive, &pc)) {
1019 printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
1020 " parameters\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 return 1;
1022 }
Borislav Petkov24a5d702008-02-02 19:56:34 +01001023 floppy->wp = !!(pc.buffer[3] & 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 set_disk_ro(floppy->disk, floppy->wp);
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001025 page = &pc.buffer[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001027 transfer_rate = be16_to_cpu(*(u16 *)&pc.buffer[8 + 2]);
1028 sector_size = be16_to_cpu(*(u16 *)&pc.buffer[8 + 6]);
1029 cyls = be16_to_cpu(*(u16 *)&pc.buffer[8 + 8]);
1030 rpm = be16_to_cpu(*(u16 *)&pc.buffer[8 + 28]);
1031 heads = pc.buffer[8 + 4];
1032 sectors = pc.buffer[8 + 5];
1033
1034 capacity = cyls * heads * sectors * sector_size;
1035
1036 if (memcmp(page, &floppy->flexible_disk_page, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
1038 "%d sector size, %d rpm\n",
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001039 drive->name, capacity / 1024, cyls, heads,
1040 sectors, transfer_rate / 8, sector_size, rpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001042 memcpy(&floppy->flexible_disk_page, page, 32);
1043 drive->bios_cyl = cyls;
1044 drive->bios_head = heads;
1045 drive->bios_sect = sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 lba_capacity = floppy->blocks * floppy->block_size;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 if (capacity < lba_capacity) {
1049 printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
1050 "bytes, but the drive only handles %d\n",
1051 drive->name, lba_capacity, capacity);
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001052 floppy->blocks = floppy->block_size ?
1053 capacity / floppy->block_size : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
1055 return 0;
1056}
1057
Borislav Petkov948391d2008-02-02 19:56:34 +01001058static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059{
1060 idefloppy_floppy_t *floppy = drive->driver_data;
1061 idefloppy_pc_t pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 floppy->srfp = 0;
1064 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
1065 MODE_SENSE_CURRENT);
1066
1067 set_bit(PC_SUPPRESS_ERROR, &pc.flags);
Borislav Petkov948391d2008-02-02 19:56:34 +01001068 if (idefloppy_queue_pc_tail(drive, &pc))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
Borislav Petkov948391d2008-02-02 19:56:34 +01001071 floppy->srfp = pc.buffer[8 + 2] & 0x40;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 return (0);
1073}
1074
1075/*
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001076 * Determine if a media is present in the floppy drive, and if so, its LBA
1077 * capacity.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 */
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001079static int ide_floppy_get_capacity(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
1081 idefloppy_floppy_t *floppy = drive->driver_data;
1082 idefloppy_pc_t pc;
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001083 u8 *cap_desc;
1084 u8 header_len, desc_cnt;
1085 int i, rc = 1, blocks, length;
1086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 drive->bios_cyl = 0;
1088 drive->bios_head = drive->bios_sect = 0;
Alan Coxfdb77da2007-02-17 02:40:20 +01001089 floppy->blocks = 0;
1090 floppy->bs_factor = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 set_capacity(floppy->disk, 0);
1092
1093 idefloppy_create_read_capacity_cmd(&pc);
1094 if (idefloppy_queue_pc_tail(drive, &pc)) {
1095 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
1096 return 1;
1097 }
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001098 header_len = pc.buffer[3];
1099 cap_desc = &pc.buffer[4];
1100 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001102 for (i = 0; i < desc_cnt; i++) {
1103 unsigned int desc_start = 4 + i*8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001105 blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
1106 length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
1107
1108 debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
1109 i, blocks * length / 1024, blocks, length);
1110
1111 if (i)
1112 continue;
1113 /*
1114 * the code below is valid only for the 1st descriptor, ie i=0
1115 */
1116
1117 switch (pc.buffer[desc_start + 4] & 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 /* Clik! drive returns this instead of CAPACITY_CURRENT */
1119 case CAPACITY_UNFORMATTED:
1120 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags))
1121 /*
1122 * If it is not a clik drive, break out
1123 * (maintains previous driver behaviour)
1124 */
1125 break;
1126 case CAPACITY_CURRENT:
1127 /* Normal Zip/LS-120 disks */
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001128 if (memcmp(cap_desc, &floppy->cap_desc, 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 printk(KERN_INFO "%s: %dkB, %d blocks, %d "
1130 "sector size\n", drive->name,
1131 blocks * length / 1024, blocks, length);
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001132 memcpy(&floppy->cap_desc, cap_desc, 8);
1133
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 if (!length || length % 512) {
1135 printk(KERN_NOTICE "%s: %d bytes block size "
1136 "not supported\n", drive->name, length);
1137 } else {
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001138 floppy->blocks = blocks;
1139 floppy->block_size = length;
1140 floppy->bs_factor = length / 512;
1141 if (floppy->bs_factor != 1)
1142 printk(KERN_NOTICE "%s: warning: non "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 "512 bytes block size not "
1144 "fully supported\n",
1145 drive->name);
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001146 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 }
1148 break;
1149 case CAPACITY_NO_CARTRIDGE:
1150 /*
1151 * This is a KERN_ERR so it appears on screen
1152 * for the user to see
1153 */
1154 printk(KERN_ERR "%s: No disk in drive\n", drive->name);
1155 break;
1156 case CAPACITY_INVALID:
1157 printk(KERN_ERR "%s: Invalid capacity for disk "
1158 "in drive\n", drive->name);
1159 break;
1160 }
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001161 debug_log("Descriptor 0 Code: %d\n",
1162 pc.buffer[desc_start + 4] & 0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164
1165 /* Clik! disk does not support get_flexible_disk_page */
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001166 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags))
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001167 (void) ide_floppy_get_flexible_disk_page(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
1170 return rc;
1171}
1172
1173/*
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001174 * Obtain the list of formattable capacities.
1175 * Very similar to ide_floppy_get_capacity, except that we push the capacity
1176 * descriptors to userland, instead of our own structures.
1177 *
1178 * Userland gives us the following structure:
1179 *
1180 * struct idefloppy_format_capacities {
1181 * int nformats;
1182 * struct {
1183 * int nblocks;
1184 * int blocksize;
1185 * } formats[];
1186 * };
1187 *
1188 * userland initializes nformats to the number of allocated formats[] records.
1189 * On exit we set nformats to the number of records we've actually initialized.
1190 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001192static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193{
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001194 idefloppy_pc_t pc;
1195 u8 header_len, desc_cnt;
1196 int i, blocks, length, u_array_size, u_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 int __user *argp;
1198
1199 if (get_user(u_array_size, arg))
1200 return (-EFAULT);
1201
1202 if (u_array_size <= 0)
1203 return (-EINVAL);
1204
1205 idefloppy_create_read_capacity_cmd(&pc);
1206 if (idefloppy_queue_pc_tail(drive, &pc)) {
1207 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001208 return (-EIO);
1209 }
1210 header_len = pc.buffer[3];
1211 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
1213 u_index = 0;
1214 argp = arg + 1;
1215
1216 /*
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001217 * We always skip the first capacity descriptor. That's the current
1218 * capacity. We are interested in the remaining descriptors, the
1219 * formattable capacities.
1220 */
1221 for (i = 1; i < desc_cnt; i++) {
1222 unsigned int desc_start = 4 + i*8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 if (u_index >= u_array_size)
1225 break; /* User-supplied buffer too small */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001227 blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
1228 length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 if (put_user(blocks, argp))
1231 return(-EFAULT);
1232 ++argp;
1233
1234 if (put_user(length, argp))
1235 return (-EFAULT);
1236 ++argp;
1237
1238 ++u_index;
1239 }
1240
1241 if (put_user(u_index, arg))
1242 return (-EFAULT);
1243 return (0);
1244}
1245
1246/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247** Get ATAPI_FORMAT_UNIT progress indication.
1248**
Matt LaPlante0779bf22006-11-30 05:24:39 +01001249** Userland gives a pointer to an int. The int is set to a progress
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250** indicator 0-65536, with 65536=100%.
1251**
1252** If the drive does not support format progress indication, we just check
1253** the dsc bit, and return either 0 or 65536.
1254*/
1255
1256static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
1257{
1258 idefloppy_floppy_t *floppy = drive->driver_data;
1259 idefloppy_pc_t pc;
1260 int progress_indication = 0x10000;
1261
1262 if (floppy->srfp) {
1263 idefloppy_create_request_sense_cmd(&pc);
1264 if (idefloppy_queue_pc_tail(drive, &pc)) {
1265 return (-EIO);
1266 }
1267
1268 if (floppy->sense_key == 2 &&
1269 floppy->asc == 4 &&
1270 floppy->ascq == 4) {
1271 progress_indication = floppy->progress_indication;
1272 }
1273 /* Else assume format_unit has finished, and we're
1274 ** at 0x10000 */
1275 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 unsigned long flags;
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001277 u8 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
1279 local_irq_save(flags);
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001280 stat = drive->hwif->INB(IDE_STATUS_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 local_irq_restore(flags);
1282
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001283 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285 if (put_user(progress_indication, arg))
1286 return (-EFAULT);
1287
1288 return (0);
1289}
1290
1291/*
1292 * Return the current floppy capacity.
1293 */
1294static sector_t idefloppy_capacity (ide_drive_t *drive)
1295{
1296 idefloppy_floppy_t *floppy = drive->driver_data;
1297 unsigned long capacity = floppy->blocks * floppy->bs_factor;
1298
1299 return capacity;
1300}
1301
1302/*
Borislav Petkovf373bd82008-02-02 19:56:36 +01001303 * Check whether we can support a drive, based on the ATAPI IDENTIFY command
1304 * results.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 */
Borislav Petkovf373bd82008-02-02 19:56:36 +01001306static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307{
1308 struct idefloppy_id_gcw gcw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
1310 *((u16 *) &gcw) = id->config;
1311
1312#ifdef CONFIG_PPC
1313 /* kludge for Apple PowerBook internal zip */
1314 if ((gcw.device_type == 5) &&
1315 !strstr(id->model, "CD-ROM") &&
1316 strstr(id->model, "ZIP"))
Borislav Petkovf373bd82008-02-02 19:56:36 +01001317 gcw.device_type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318#endif
1319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 if (gcw.protocol != 2)
Borislav Petkovf373bd82008-02-02 19:56:36 +01001321 printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n",
1322 gcw.protocol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 else if (gcw.device_type != 0)
Borislav Petkovf373bd82008-02-02 19:56:36 +01001324 printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set "
1325 "to floppy\n", gcw.device_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 else if (!gcw.removable)
1327 printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
1328 else if (gcw.drq_type == 3) {
Borislav Petkovf373bd82008-02-02 19:56:36 +01001329 printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not "
1330 "supported\n", gcw.drq_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 } else if (gcw.packet_size != 0) {
Borislav Petkovf373bd82008-02-02 19:56:36 +01001332 printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 "
1333 "bytes long\n", gcw.packet_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 } else
1335 return 1;
1336 return 0;
1337}
1338
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001339#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340static void idefloppy_add_settings(ide_drive_t *drive)
1341{
1342 idefloppy_floppy_t *floppy = drive->driver_data;
1343
1344/*
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +02001345 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 */
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +02001347 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL);
1348 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL);
1349 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL);
1350 ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &floppy->ticks, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351}
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001352#else
1353static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
1354#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
1356/*
1357 * Driver initialization.
1358 */
1359static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy)
1360{
1361 struct idefloppy_id_gcw gcw;
1362
1363 *((u16 *) &gcw) = drive->id->config;
1364 floppy->pc = floppy->pc_stack;
1365 if (gcw.drq_type == 1)
1366 set_bit(IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags);
1367 /*
1368 * We used to check revisions here. At this point however
1369 * I'm giving up. Just assume they are all broken, its easier.
1370 *
1371 * The actual reason for the workarounds was likely
1372 * a driver bug after all rather than a firmware bug,
1373 * and the workaround below used to hide it. It should
1374 * be fixed as of version 1.9, but to be on the safe side
1375 * we'll leave the limitation below for the 2.2.x tree.
1376 */
1377
1378 if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) {
1379 set_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags);
1380 /* This value will be visible in the /proc/ide/hdx/settings */
1381 floppy->ticks = IDEFLOPPY_TICKS_DELAY;
1382 blk_queue_max_sectors(drive->queue, 64);
1383 }
1384
1385 /*
1386 * Guess what? The IOMEGA Clik! drive also needs the
1387 * above fix. It makes nasty clicking noises without
1388 * it, so please don't remove this.
1389 */
1390 if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) {
1391 blk_queue_max_sectors(drive->queue, 64);
1392 set_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags);
1393 }
1394
1395
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001396 (void) ide_floppy_get_capacity(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 idefloppy_add_settings(drive);
1398}
1399
Russell King4031bbe2006-01-06 11:41:00 +00001400static void ide_floppy_remove(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401{
1402 idefloppy_floppy_t *floppy = drive->driver_data;
1403 struct gendisk *g = floppy->disk;
1404
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001405 ide_proc_unregister_driver(drive, floppy->driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
1407 del_gendisk(g);
1408
1409 ide_floppy_put(floppy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410}
1411
Borislav Petkov9a24b632008-02-02 19:56:33 +01001412static void idefloppy_cleanup_obj(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413{
1414 struct ide_floppy_obj *floppy = to_ide_floppy(kref);
1415 ide_drive_t *drive = floppy->drive;
1416 struct gendisk *g = floppy->disk;
1417
1418 drive->driver_data = NULL;
1419 g->private_data = NULL;
1420 put_disk(g);
1421 kfree(floppy);
1422}
1423
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001424#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425static int proc_idefloppy_read_capacity
1426 (char *page, char **start, off_t off, int count, int *eof, void *data)
1427{
1428 ide_drive_t*drive = (ide_drive_t *)data;
1429 int len;
1430
1431 len = sprintf(page,"%llu\n", (long long)idefloppy_capacity(drive));
1432 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
1433}
1434
1435static ide_proc_entry_t idefloppy_proc[] = {
1436 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
1437 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
1438 { NULL, 0, NULL, NULL }
1439};
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001440#endif /* CONFIG_IDE_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Russell King4031bbe2006-01-06 11:41:00 +00001442static int ide_floppy_probe(ide_drive_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444static ide_driver_t idefloppy_driver = {
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001445 .gen_driver = {
Laurent Riffard4ef3b8f2005-11-18 22:15:40 +01001446 .owner = THIS_MODULE,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001447 .name = "ide-floppy",
1448 .bus = &ide_bus_type,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001449 },
Russell King4031bbe2006-01-06 11:41:00 +00001450 .probe = ide_floppy_probe,
1451 .remove = ide_floppy_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 .version = IDEFLOPPY_VERSION,
1453 .media = ide_floppy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 .supports_dsc_overlap = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 .do_request = idefloppy_do_request,
1456 .end_request = idefloppy_do_end_request,
1457 .error = __ide_error,
1458 .abort = __ide_abort,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001459#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 .proc = idefloppy_proc,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001461#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462};
1463
1464static int idefloppy_open(struct inode *inode, struct file *filp)
1465{
1466 struct gendisk *disk = inode->i_bdev->bd_disk;
1467 struct ide_floppy_obj *floppy;
1468 ide_drive_t *drive;
1469 idefloppy_pc_t pc;
1470 int ret = 0;
1471
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001472 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 if (!(floppy = ide_floppy_get(disk)))
1475 return -ENXIO;
1476
1477 drive = floppy->drive;
1478
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001479 floppy->openers++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001481 if (floppy->openers == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1483 /* Just in case */
1484
1485 idefloppy_create_test_unit_ready_cmd(&pc);
1486 if (idefloppy_queue_pc_tail(drive, &pc)) {
1487 idefloppy_create_start_stop_cmd(&pc, 1);
1488 (void) idefloppy_queue_pc_tail(drive, &pc);
1489 }
1490
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001491 if (ide_floppy_get_capacity(drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 && (filp->f_flags & O_NDELAY) == 0
1493 /*
1494 ** Allow O_NDELAY to open a drive without a disk, or with
1495 ** an unreadable disk, so that we can get the format
1496 ** capacity of the drive or begin the format - Sam
1497 */
1498 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 ret = -EIO;
1500 goto out_put_floppy;
1501 }
1502
1503 if (floppy->wp && (filp->f_mode & 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 ret = -EROFS;
1505 goto out_put_floppy;
1506 }
1507 set_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
1508 /* IOMEGA Clik! drives do not support lock/unlock commands */
1509 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1510 idefloppy_create_prevent_cmd(&pc, 1);
1511 (void) idefloppy_queue_pc_tail(drive, &pc);
1512 }
1513 check_disk_change(inode->i_bdev);
1514 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 ret = -EBUSY;
1516 goto out_put_floppy;
1517 }
1518 return 0;
1519
1520out_put_floppy:
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001521 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 ide_floppy_put(floppy);
1523 return ret;
1524}
1525
1526static int idefloppy_release(struct inode *inode, struct file *filp)
1527{
1528 struct gendisk *disk = inode->i_bdev->bd_disk;
1529 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1530 ide_drive_t *drive = floppy->drive;
1531 idefloppy_pc_t pc;
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001532
1533 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001535 if (floppy->openers == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 /* IOMEGA Clik! drives do not support lock/unlock commands */
1537 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1538 idefloppy_create_prevent_cmd(&pc, 0);
1539 (void) idefloppy_queue_pc_tail(drive, &pc);
1540 }
1541
1542 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1543 }
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001544
1545 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
1547 ide_floppy_put(floppy);
1548
1549 return 0;
1550}
1551
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08001552static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1553{
1554 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1555 ide_drive_t *drive = floppy->drive;
1556
1557 geo->heads = drive->bios_head;
1558 geo->sectors = drive->bios_sect;
1559 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
1560 return 0;
1561}
1562
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001563static int ide_floppy_lockdoor(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc,
1564 unsigned long arg, unsigned int cmd)
1565{
1566 if (floppy->openers > 1)
1567 return -EBUSY;
1568
1569 /* The IOMEGA Clik! Drive doesn't support this command -
1570 * no room for an eject mechanism */
1571 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1572 int prevent = arg ? 1 : 0;
1573
1574 if (cmd == CDROMEJECT)
1575 prevent = 0;
1576
1577 idefloppy_create_prevent_cmd(pc, prevent);
1578 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1579 }
1580
1581 if (cmd == CDROMEJECT) {
1582 idefloppy_create_start_stop_cmd(pc, 2);
1583 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1584 }
1585
1586 return 0;
1587}
1588
1589static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
1590 int __user *arg)
1591{
1592 int blocks, length, flags, err = 0;
1593 idefloppy_pc_t pc;
1594
1595 if (floppy->openers > 1) {
1596 /* Don't format if someone is using the disk */
1597 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1598 return -EBUSY;
1599 }
1600
1601 set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1602
1603 /*
1604 * Send ATAPI_FORMAT_UNIT to the drive.
1605 *
1606 * Userland gives us the following structure:
1607 *
1608 * struct idefloppy_format_command {
1609 * int nblocks;
1610 * int blocksize;
1611 * int flags;
1612 * } ;
1613 *
1614 * flags is a bitmask, currently, the only defined flag is:
1615 *
1616 * 0x01 - verify media after format.
1617 */
1618 if (get_user(blocks, arg) ||
1619 get_user(length, arg+1) ||
1620 get_user(flags, arg+2)) {
1621 err = -EFAULT;
1622 goto out;
1623 }
1624
1625 (void) idefloppy_get_sfrp_bit(floppy->drive);
1626 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1627
1628 if (idefloppy_queue_pc_tail(floppy->drive, &pc))
1629 err = -EIO;
1630
1631out:
1632 if (err)
1633 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1634 return err;
1635}
1636
1637
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638static int idefloppy_ioctl(struct inode *inode, struct file *file,
1639 unsigned int cmd, unsigned long arg)
1640{
1641 struct block_device *bdev = inode->i_bdev;
1642 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1643 ide_drive_t *drive = floppy->drive;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001644 idefloppy_pc_t pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 void __user *argp = (void __user *)arg;
Ondrej Zary07203f62005-11-10 00:25:15 +01001646 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648 switch (cmd) {
1649 case CDROMEJECT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 /* fall through */
1651 case CDROM_LOCKDOOR:
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001652 return ide_floppy_lockdoor(floppy, &pc, arg, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
1654 return 0;
1655 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001656 return ide_floppy_get_format_capacities(drive, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 case IDEFLOPPY_IOCTL_FORMAT_START:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 if (!(file->f_mode & 2))
1659 return -EPERM;
1660
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001661 return ide_floppy_format_unit(floppy, (int __user *)arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1663 return idefloppy_get_format_progress(drive, argp);
1664 }
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +02001665
1666 /*
1667 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
1668 * and CDROM_SEND_PACKET (legacy) ioctls
1669 */
1670 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
1671 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
1672 bdev->bd_disk, cmd, argp);
1673 else
1674 err = -ENOTTY;
1675
1676 if (err == -ENOTTY)
1677 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
1678
1679 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680}
1681
1682static int idefloppy_media_changed(struct gendisk *disk)
1683{
1684 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1685 ide_drive_t *drive = floppy->drive;
1686
1687 /* do not scan partitions twice if this is a removable device */
1688 if (drive->attach) {
1689 drive->attach = 0;
1690 return 0;
1691 }
1692 return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
1693}
1694
1695static int idefloppy_revalidate_disk(struct gendisk *disk)
1696{
1697 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1698 set_capacity(disk, idefloppy_capacity(floppy->drive));
1699 return 0;
1700}
1701
1702static struct block_device_operations idefloppy_ops = {
1703 .owner = THIS_MODULE,
1704 .open = idefloppy_open,
1705 .release = idefloppy_release,
1706 .ioctl = idefloppy_ioctl,
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08001707 .getgeo = idefloppy_getgeo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 .media_changed = idefloppy_media_changed,
1709 .revalidate_disk= idefloppy_revalidate_disk
1710};
1711
Russell King4031bbe2006-01-06 11:41:00 +00001712static int ide_floppy_probe(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
1714 idefloppy_floppy_t *floppy;
1715 struct gendisk *g;
1716
1717 if (!strstr("ide-floppy", drive->driver_req))
1718 goto failed;
1719 if (!drive->present)
1720 goto failed;
1721 if (drive->media != ide_floppy)
1722 goto failed;
1723 if (!idefloppy_identify_device (drive, drive->id)) {
1724 printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
1725 goto failed;
1726 }
1727 if (drive->scsi) {
1728 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
1729 goto failed;
1730 }
Robert P. J. Day5cbded52006-12-13 00:35:56 -08001731 if ((floppy = kzalloc(sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name);
1733 goto failed;
1734 }
1735
1736 g = alloc_disk(1 << PARTN_BITS);
1737 if (!g)
1738 goto out_free_floppy;
1739
1740 ide_init_disk(g, drive);
1741
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001742 ide_proc_register_driver(drive, &idefloppy_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 kref_init(&floppy->kref);
1745
1746 floppy->drive = drive;
1747 floppy->driver = &idefloppy_driver;
1748 floppy->disk = g;
1749
1750 g->private_data = &floppy->driver;
1751
1752 drive->driver_data = floppy;
1753
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 idefloppy_setup (drive, floppy);
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001755
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 g->minors = 1 << PARTN_BITS;
1757 g->driverfs_dev = &drive->gendev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
1759 g->fops = &idefloppy_ops;
1760 drive->attach = 1;
1761 add_disk(g);
1762 return 0;
1763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764out_free_floppy:
1765 kfree(floppy);
1766failed:
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001767 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
1770MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
1771
1772static void __exit idefloppy_exit (void)
1773{
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001774 driver_unregister(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
Bartlomiej Zolnierkiewicz17514e82005-11-19 22:24:35 +01001777static int __init idefloppy_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778{
1779 printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001780 return driver_register(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781}
1782
Kay Sievers263756e2005-12-12 18:03:44 +01001783MODULE_ALIAS("ide:*m-floppy*");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784module_init(idefloppy_init);
1785module_exit(idefloppy_exit);
1786MODULE_LICENSE("GPL");