blob: 01701ca95204ec165eba215b33f5d9c139f735d0 [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define PC_DMA_RECOMMENDED 2 /* 1 when we prefer to use DMA if possible */
111#define PC_DMA_IN_PROGRESS 3 /* 1 while DMA in progress */
112#define PC_DMA_ERROR 4 /* 1 when encountered problem during DMA */
113#define PC_WRITING 5 /* Data direction */
114
115#define PC_SUPPRESS_ERROR 6 /* Suppress error reporting */
116
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100117/* format capacities descriptor codes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define CAPACITY_INVALID 0x00
119#define CAPACITY_UNFORMATTED 0x01
120#define CAPACITY_CURRENT 0x02
121#define CAPACITY_NO_CARTRIDGE 0x03
122
123/*
124 * Most of our global data which we need to save even as we leave the
125 * driver due to an interrupt or a timer event is stored in a variable
126 * of type idefloppy_floppy_t, defined below.
127 */
128typedef struct ide_floppy_obj {
129 ide_drive_t *drive;
130 ide_driver_t *driver;
131 struct gendisk *disk;
132 struct kref kref;
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +0100133 unsigned int openers; /* protected by BKL for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 /* Current packet command */
136 idefloppy_pc_t *pc;
137 /* Last failed packet command */
138 idefloppy_pc_t *failed_pc;
139 /* Packet command stack */
140 idefloppy_pc_t pc_stack[IDEFLOPPY_PC_STACK];
141 /* Next free packet command storage space */
142 int pc_stack_index;
143 struct request rq_stack[IDEFLOPPY_PC_STACK];
144 /* We implement a circular array */
145 int rq_stack_index;
146
147 /*
148 * Last error information
149 */
150 u8 sense_key, asc, ascq;
151 /* delay this long before sending packet command */
152 u8 ticks;
153 int progress_indication;
154
155 /*
156 * Device information
157 */
158 /* Current format */
159 int blocks, block_size, bs_factor;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100160 /* Last format capacity descriptor */
161 u8 cap_desc[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /* Copy of the flexible disk page */
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100163 u8 flexible_disk_page[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 /* Write protect */
165 int wp;
166 /* Supports format progress report */
167 int srfp;
168 /* Status/Action flags */
169 unsigned long flags;
170} idefloppy_floppy_t;
171
Bartlomiej Zolnierkiewiczc40d3d32005-08-18 22:09:21 +0200172#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174/*
175 * Floppy flag bits values.
176 */
177#define IDEFLOPPY_DRQ_INTERRUPT 0 /* DRQ interrupt device */
178#define IDEFLOPPY_MEDIA_CHANGED 1 /* Media may have changed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#define IDEFLOPPY_FORMAT_IN_PROGRESS 3 /* Format in progress */
180#define IDEFLOPPY_CLIK_DRIVE 4 /* Avoid commands not supported in Clik drive */
181#define IDEFLOPPY_ZIP_DRIVE 5 /* Requires BH algorithm for packets */
182
183/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 * Defines for the mode sense command
185 */
186#define MODE_SENSE_CURRENT 0x00
187#define MODE_SENSE_CHANGEABLE 0x01
188#define MODE_SENSE_DEFAULT 0x02
189#define MODE_SENSE_SAVED 0x03
190
191/*
192 * IOCTLs used in low-level formatting.
193 */
194
195#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
196#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
197#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
198#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200/*
201 * Error codes which are returned in rq->errors to the higher part
202 * of the driver.
203 */
204#define IDEFLOPPY_ERROR_GENERAL 101
205
206/*
207 * The following is used to format the general configuration word of
208 * the ATAPI IDENTIFY DEVICE command.
209 */
210struct idefloppy_id_gcw {
211#if defined(__LITTLE_ENDIAN_BITFIELD)
212 unsigned packet_size :2; /* Packet Size */
213 unsigned reserved234 :3; /* Reserved */
214 unsigned drq_type :2; /* Command packet DRQ type */
215 unsigned removable :1; /* Removable media */
216 unsigned device_type :5; /* Device type */
217 unsigned reserved13 :1; /* Reserved */
218 unsigned protocol :2; /* Protocol type */
219#elif defined(__BIG_ENDIAN_BITFIELD)
220 unsigned protocol :2; /* Protocol type */
221 unsigned reserved13 :1; /* Reserved */
222 unsigned device_type :5; /* Device type */
223 unsigned removable :1; /* Removable media */
224 unsigned drq_type :2; /* Command packet DRQ type */
225 unsigned reserved234 :3; /* Reserved */
226 unsigned packet_size :2; /* Packet Size */
227#else
228#error "Bitfield endianness not defined! Check your byteorder.h"
229#endif
230};
231
232/*
Borislav Petkov948391d2008-02-02 19:56:34 +0100233 * Pages of the SELECT SENSE / MODE SENSE packet commands.
234 * See SFF-8070i spec.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 */
236#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
237#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
238
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800239static DEFINE_MUTEX(idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
242
243#define ide_floppy_g(disk) \
244 container_of((disk)->private_data, struct ide_floppy_obj, driver)
245
246static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
247{
248 struct ide_floppy_obj *floppy = NULL;
249
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800250 mutex_lock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 floppy = ide_floppy_g(disk);
252 if (floppy)
253 kref_get(&floppy->kref);
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800254 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return floppy;
256}
257
Borislav Petkov9a24b632008-02-02 19:56:33 +0100258static void idefloppy_cleanup_obj(struct kref *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260static void ide_floppy_put(struct ide_floppy_obj *floppy)
261{
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800262 mutex_lock(&idefloppy_ref_mutex);
Borislav Petkov9a24b632008-02-02 19:56:33 +0100263 kref_put(&floppy->kref, idefloppy_cleanup_obj);
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800264 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265}
266
267/*
268 * Too bad. The drive wants to send us data which we are not ready to accept.
269 * Just throw it away.
270 */
271static void idefloppy_discard_data (ide_drive_t *drive, unsigned int bcount)
272{
273 while (bcount--)
274 (void) HWIF(drive)->INB(IDE_DATA_REG);
275}
276
Borislav Petkov0bf399e2008-02-02 19:56:36 +0100277static void idefloppy_write_zeros(ide_drive_t *drive, unsigned int bcount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 while (bcount--)
280 HWIF(drive)->OUTB(0, IDE_DATA_REG);
281}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283
284/*
285 * idefloppy_do_end_request is used to finish servicing a request.
286 *
287 * For read/write requests, we will call ide_end_request to pass to the
288 * next buffer.
289 */
290static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs)
291{
292 idefloppy_floppy_t *floppy = drive->driver_data;
293 struct request *rq = HWGROUP(drive)->rq;
294 int error;
295
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100296 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 switch (uptodate) {
299 case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
300 case 1: error = 0; break;
301 default: error = uptodate;
302 }
303 if (error)
304 floppy->failed_pc = NULL;
305 /* Why does this happen? */
306 if (!rq)
307 return 0;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200308 if (!blk_special_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 /* our real local end request function */
310 ide_end_request(drive, uptodate, nsecs);
311 return 0;
312 }
313 rq->errors = error;
314 /* fixme: need to move this local also */
315 ide_end_drive_cmd(drive, 0, 0);
316 return 0;
317}
318
Borislav Petkov32925e12008-02-02 19:56:36 +0100319static void ide_floppy_io_buffers(ide_drive_t *drive, idefloppy_pc_t *pc,
320 unsigned int bcount, int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 struct request *rq = pc->rq;
NeilBrown5705f702007-09-25 12:35:59 +0200323 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 struct bio_vec *bvec;
325 unsigned long flags;
NeilBrown5705f702007-09-25 12:35:59 +0200326 int count, done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 char *data;
328
NeilBrown5705f702007-09-25 12:35:59 +0200329 rq_for_each_segment(bvec, rq, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200330 if (!bcount)
331 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Jens Axboe6c92e692007-08-16 13:43:12 +0200333 count = min(bvec->bv_len, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Jens Axboe6c92e692007-08-16 13:43:12 +0200335 data = bvec_kmap_irq(bvec, &flags);
Borislav Petkov32925e12008-02-02 19:56:36 +0100336 if (direction)
337 drive->hwif->atapi_output_bytes(drive, data, count);
338 else
339 drive->hwif->atapi_input_bytes(drive, data, count);
Jens Axboe6c92e692007-08-16 13:43:12 +0200340 bvec_kunmap_irq(data, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Jens Axboe6c92e692007-08-16 13:43:12 +0200342 bcount -= count;
343 pc->b_count += count;
344 done += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346
347 idefloppy_do_end_request(drive, 1, done >> 9);
348
349 if (bcount) {
Borislav Petkov32925e12008-02-02 19:56:36 +0100350 printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
351 drive->name, __func__, bcount);
352 if (direction)
353 idefloppy_write_zeros(drive, bcount);
354 else
355 idefloppy_discard_data(drive, bcount);
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
358}
359
360static void idefloppy_update_buffers (ide_drive_t *drive, idefloppy_pc_t *pc)
361{
362 struct request *rq = pc->rq;
363 struct bio *bio = rq->bio;
364
365 while ((bio = rq->bio) != NULL)
366 idefloppy_do_end_request(drive, 1, 0);
367}
368
369/*
370 * idefloppy_queue_pc_head generates a new packet command request in front
371 * of the request queue, before the current request, so that it will be
372 * processed immediately, on the next pass through the driver.
373 */
374static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struct request *rq)
375{
376 struct ide_floppy_obj *floppy = drive->driver_data;
377
378 ide_init_drive_cmd(rq);
379 rq->buffer = (char *) pc;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200380 rq->cmd_type = REQ_TYPE_SPECIAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 rq->rq_disk = floppy->disk;
382 (void) ide_do_drive_cmd(drive, rq, ide_preempt);
383}
384
385static idefloppy_pc_t *idefloppy_next_pc_storage (ide_drive_t *drive)
386{
387 idefloppy_floppy_t *floppy = drive->driver_data;
388
389 if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
390 floppy->pc_stack_index=0;
391 return (&floppy->pc_stack[floppy->pc_stack_index++]);
392}
393
394static struct request *idefloppy_next_rq_storage (ide_drive_t *drive)
395{
396 idefloppy_floppy_t *floppy = drive->driver_data;
397
398 if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK)
399 floppy->rq_stack_index = 0;
400 return (&floppy->rq_stack[floppy->rq_stack_index++]);
401}
402
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100403static void idefloppy_request_sense_callback(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
405 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100406 u8 *buf = floppy->pc->buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100408 debug_log("Reached %s\n", __func__);
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if (!floppy->pc->error) {
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100411 floppy->sense_key = buf[2] & 0x0F;
412 floppy->asc = buf[12];
413 floppy->ascq = buf[13];
414 floppy->progress_indication = buf[15] & 0x80 ?
415 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
416
417 if (floppy->failed_pc)
418 debug_log("pc = %x, sense key = %x, asc = %x,"
419 " ascq = %x\n",
420 floppy->failed_pc->c[0],
421 floppy->sense_key,
422 floppy->asc,
423 floppy->ascq);
424 else
425 debug_log("sense key = %x, asc = %x, ascq = %x\n",
426 floppy->sense_key,
427 floppy->asc,
428 floppy->ascq);
429
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 idefloppy_do_end_request(drive, 1, 0);
432 } else {
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100433 printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting"
434 " request!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 idefloppy_do_end_request(drive, 0, 0);
436 }
437}
438
439/*
440 * General packet command callback function.
441 */
442static void idefloppy_pc_callback (ide_drive_t *drive)
443{
444 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100445
446 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 idefloppy_do_end_request(drive, floppy->pc->error ? 0 : 1, 0);
449}
450
451/*
452 * idefloppy_init_pc initializes a packet command.
453 */
454static void idefloppy_init_pc (idefloppy_pc_t *pc)
455{
456 memset(pc->c, 0, 12);
457 pc->retries = 0;
458 pc->flags = 0;
459 pc->request_transfer = 0;
460 pc->buffer = pc->pc_buffer;
461 pc->buffer_size = IDEFLOPPY_PC_BUFFER_SIZE;
462 pc->callback = &idefloppy_pc_callback;
463}
464
465static void idefloppy_create_request_sense_cmd (idefloppy_pc_t *pc)
466{
Borislav Petkov30d67092008-02-02 19:56:33 +0100467 idefloppy_init_pc(pc);
468 pc->c[0] = GPCMD_REQUEST_SENSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 pc->c[4] = 255;
470 pc->request_transfer = 18;
471 pc->callback = &idefloppy_request_sense_callback;
472}
473
474/*
475 * idefloppy_retry_pc is called when an error was detected during the
476 * last packet command. We queue a request sense packet command in
477 * the head of the request list.
478 */
479static void idefloppy_retry_pc (ide_drive_t *drive)
480{
481 idefloppy_pc_t *pc;
482 struct request *rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100484 (void)drive->hwif->INB(IDE_ERROR_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 pc = idefloppy_next_pc_storage(drive);
486 rq = idefloppy_next_rq_storage(drive);
487 idefloppy_create_request_sense_cmd(pc);
488 idefloppy_queue_pc_head(drive, pc, rq);
489}
490
Borislav Petkov0eea6452008-02-02 19:56:36 +0100491/* The usual interrupt handler called during a packet command. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
493{
494 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100495 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 idefloppy_pc_t *pc = floppy->pc;
497 struct request *rq = pc->rq;
Borislav Petkov0eea6452008-02-02 19:56:36 +0100498 xfer_func_t *xferfunc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 unsigned int temp;
Borislav Petkovd30a7fb2008-02-02 19:56:35 +0100500 int dma_error = 0;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100501 u16 bcount;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100502 u8 stat, ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100504 debug_log("Reached %s interrupt handler\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
Borislav Petkovd30a7fb2008-02-02 19:56:35 +0100507 dma_error = hwif->ide_dma_end(drive);
508 if (dma_error) {
509 printk(KERN_ERR "%s: DMA %s error\n", drive->name,
510 rq_data_dir(rq) ? "write" : "read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 set_bit(PC_DMA_ERROR, &pc->flags);
512 } else {
513 pc->actually_transferred = pc->request_transfer;
514 idefloppy_update_buffers(drive, pc);
515 }
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100516 debug_log("DMA finished\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 }
518
519 /* Clear the interrupt */
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100520 stat = drive->hwif->INB(IDE_STATUS_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100522 if ((stat & DRQ_STAT) == 0) { /* No more interrupts */
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100523 debug_log("Packet command completed, %d bytes transferred\n",
524 pc->actually_transferred);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 clear_bit(PC_DMA_IN_PROGRESS, &pc->flags);
526
Ingo Molnar366c7f52006-07-03 00:25:25 -0700527 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100529 if ((stat & ERR_STAT) || test_bit(PC_DMA_ERROR, &pc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 /* Error detected */
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100531 debug_log("%s: I/O error\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 rq->errors++;
Borislav Petkov30d67092008-02-02 19:56:33 +0100533 if (pc->c[0] == GPCMD_REQUEST_SENSE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 printk(KERN_ERR "ide-floppy: I/O error in "
535 "request sense command\n");
536 return ide_do_reset(drive);
537 }
538 /* Retry operation */
539 idefloppy_retry_pc(drive);
540 /* queued, but not started */
541 return ide_stopped;
542 }
543 pc->error = 0;
544 if (floppy->failed_pc == pc)
545 floppy->failed_pc = NULL;
546 /* Command finished - Call the callback function */
547 pc->callback(drive);
548 return ide_stopped;
549 }
550
551 if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) {
552 printk(KERN_ERR "ide-floppy: The floppy wants to issue "
553 "more interrupts in DMA mode\n");
Bartlomiej Zolnierkiewicz7469aaf2007-02-17 02:40:26 +0100554 ide_dma_off(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return ide_do_reset(drive);
556 }
557
558 /* Get the number of bytes to transfer */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100559 bcount = (hwif->INB(IDE_BCOUNTH_REG) << 8) |
560 hwif->INB(IDE_BCOUNTL_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 /* on this interrupt */
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100562 ireason = hwif->INB(IDE_IREASON_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100564 if (ireason & CD) {
Borislav Petkov0eea6452008-02-02 19:56:36 +0100565 printk(KERN_ERR "ide-floppy: CoD != 0 in %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 return ide_do_reset(drive);
567 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100568 if (((ireason & IO) == IO) == test_bit(PC_WRITING, &pc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 /* Hopefully, we will never get here */
570 printk(KERN_ERR "ide-floppy: We wanted to %s, ",
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100571 (ireason & IO) ? "Write" : "Read");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 printk(KERN_ERR "but the floppy wants us to %s !\n",
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100573 (ireason & IO) ? "Read" : "Write");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return ide_do_reset(drive);
575 }
576 if (!test_bit(PC_WRITING, &pc->flags)) {
577 /* Reading - Check that we have enough space */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100578 temp = pc->actually_transferred + bcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 if (temp > pc->request_transfer) {
580 if (temp > pc->buffer_size) {
581 printk(KERN_ERR "ide-floppy: The floppy wants "
582 "to send us more data than expected "
583 "- discarding data\n");
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100584 idefloppy_discard_data(drive, bcount);
Borislav Petkov0078df22008-02-02 19:56:33 +0100585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 ide_set_handler(drive,
587 &idefloppy_pc_intr,
588 IDEFLOPPY_WAIT_CMD,
589 NULL);
590 return ide_started;
591 }
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100592 debug_log("The floppy wants to send us more data than"
593 " expected - allowing transfer\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
595 }
Borislav Petkov32925e12008-02-02 19:56:36 +0100596 if (test_bit(PC_WRITING, &pc->flags))
Borislav Petkov0eea6452008-02-02 19:56:36 +0100597 xferfunc = hwif->atapi_output_bytes;
Borislav Petkov32925e12008-02-02 19:56:36 +0100598 else
Borislav Petkov0eea6452008-02-02 19:56:36 +0100599 xferfunc = hwif->atapi_input_bytes;
Borislav Petkov0eea6452008-02-02 19:56:36 +0100600
601 if (pc->buffer)
602 xferfunc(drive, pc->current_position, bcount);
603 else
Borislav Petkov32925e12008-02-02 19:56:36 +0100604 ide_floppy_io_buffers(drive, pc, bcount,
605 test_bit(PC_WRITING, &pc->flags));
Borislav Petkov0eea6452008-02-02 19:56:36 +0100606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 /* Update the current position */
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100608 pc->actually_transferred += bcount;
609 pc->current_position += bcount;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Borislav Petkov32925e12008-02-02 19:56:36 +0100611 /* And set the interrupt handler again */
612 ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 return ide_started;
614}
615
616/*
617 * This is the original routine that did the packet transfer.
618 * It fails at high speeds on the Iomega ZIP drive, so there's a slower version
619 * for that drive below. The algorithm is chosen based on drive type
620 */
621static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive)
622{
623 ide_startstop_t startstop;
624 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100625 u8 ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
628 printk(KERN_ERR "ide-floppy: Strange, packet command "
629 "initiated yet DRQ isn't asserted\n");
630 return startstop;
631 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100632 ireason = drive->hwif->INB(IDE_IREASON_REG);
633 if ((ireason & CD) == 0 || (ireason & IO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) while "
635 "issuing a packet command\n");
636 return ide_do_reset(drive);
637 }
Borislav Petkov0078df22008-02-02 19:56:33 +0100638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 /* Set the interrupt routine */
640 ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
641 /* Send the actual packet */
642 HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
643 return ide_started;
644}
645
646
647/*
648 * What we have here is a classic case of a top half / bottom half
649 * interrupt service routine. In interrupt mode, the device sends
650 * an interrupt to signal it's ready to receive a packet. However,
651 * we need to delay about 2-3 ticks before issuing the packet or we
652 * gets in trouble.
653 *
654 * So, follow carefully. transfer_pc1 is called as an interrupt (or
655 * directly). In either case, when the device says it's ready for a
656 * packet, we schedule the packet transfer to occur about 2-3 ticks
657 * later in transfer_pc2.
658 */
659static int idefloppy_transfer_pc2 (ide_drive_t *drive)
660{
661 idefloppy_floppy_t *floppy = drive->driver_data;
662
663 /* Send the actual packet */
664 HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
665 /* Timeout for the packet command */
666 return IDEFLOPPY_WAIT_CMD;
667}
668
669static ide_startstop_t idefloppy_transfer_pc1 (ide_drive_t *drive)
670{
671 idefloppy_floppy_t *floppy = drive->driver_data;
672 ide_startstop_t startstop;
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100673 u8 ireason;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
676 printk(KERN_ERR "ide-floppy: Strange, packet command "
677 "initiated yet DRQ isn't asserted\n");
678 return startstop;
679 }
Bartlomiej Zolnierkiewicz8e7657a2008-01-25 22:17:12 +0100680 ireason = drive->hwif->INB(IDE_IREASON_REG);
681 if ((ireason & CD) == 0 || (ireason & IO)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) "
683 "while issuing a packet command\n");
684 return ide_do_reset(drive);
685 }
686 /*
687 * The following delay solves a problem with ATAPI Zip 100 drives
688 * where the Busy flag was apparently being deasserted before the
689 * unit was ready to receive data. This was happening on a
690 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
691 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
692 * used until after the packet is moved in about 50 msec.
693 */
Borislav Petkov0078df22008-02-02 19:56:33 +0100694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 ide_set_handler(drive,
696 &idefloppy_pc_intr, /* service routine for packet command */
697 floppy->ticks, /* wait this long before "failing" */
698 &idefloppy_transfer_pc2); /* fail == transfer_pc2 */
699 return ide_started;
700}
701
Borislav Petkovd652c132008-02-02 19:56:35 +0100702static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
703 idefloppy_pc_t *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
Borislav Petkovd652c132008-02-02 19:56:35 +0100705 /* supress error messages resulting from Medium not present */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 if (floppy->sense_key == 0x02 &&
707 floppy->asc == 0x3a &&
708 floppy->ascq == 0x00)
Borislav Petkovd652c132008-02-02 19:56:35 +0100709 return;
710
711 printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, "
712 "asc = %2x, ascq = %2x\n",
713 floppy->drive->name, pc->c[0], floppy->sense_key,
714 floppy->asc, floppy->ascq);
715
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}
717
718/*
719 * Issue a packet command
720 */
721static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *pc)
722{
723 idefloppy_floppy_t *floppy = drive->driver_data;
724 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 ide_handler_t *pkt_xfer_routine;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100726 u16 bcount;
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100727 u8 dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 if (floppy->failed_pc == NULL &&
Borislav Petkov30d67092008-02-02 19:56:33 +0100730 pc->c[0] != GPCMD_REQUEST_SENSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 floppy->failed_pc = pc;
732 /* Set the current packet command */
733 floppy->pc = pc;
734
Borislav Petkov757ced82008-02-02 19:56:37 +0100735 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
736 if (!test_bit(PC_SUPPRESS_ERROR, &pc->flags))
737 ide_floppy_report_error(floppy, pc);
738 /* Giving up */
739 pc->error = IDEFLOPPY_ERROR_GENERAL;
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 floppy->failed_pc = NULL;
742 pc->callback(drive);
743 return ide_stopped;
744 }
745
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100746 debug_log("Retry number - %d\n", pc->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 pc->retries++;
749 /* We haven't transferred any data yet */
750 pc->actually_transferred = 0;
751 pc->current_position = pc->buffer;
Bartlomiej Zolnierkiewicz790d1232008-01-25 22:17:12 +0100752 bcount = min(pc->request_transfer, 63 * 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Bartlomiej Zolnierkiewicz7469aaf2007-02-17 02:40:26 +0100754 if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags))
755 ide_dma_off(drive);
756
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100757 dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma)
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100760 dma = !hwif->dma_setup(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Bartlomiej Zolnierkiewicz2fc57382008-01-25 22:17:13 +0100762 ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK |
763 IDE_TFLAG_OUT_DEVICE, bcount, dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Bartlomiej Zolnierkiewicze5f9f5a2008-01-25 22:17:12 +0100765 if (dma) { /* Begin DMA, if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 set_bit(PC_DMA_IN_PROGRESS, &pc->flags);
767 hwif->dma_start(drive);
768 }
769
770 /* Can we transfer the packet when we get the interrupt or wait? */
771 if (test_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags)) {
772 /* wait */
773 pkt_xfer_routine = &idefloppy_transfer_pc1;
774 } else {
775 /* immediate */
776 pkt_xfer_routine = &idefloppy_transfer_pc;
777 }
778
779 if (test_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags)) {
780 /* Issue the packet command */
781 ide_execute_command(drive, WIN_PACKETCMD,
782 pkt_xfer_routine,
783 IDEFLOPPY_WAIT_CMD,
784 NULL);
785 return ide_started;
786 } else {
787 /* Issue the packet command */
788 HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
789 return (*pkt_xfer_routine) (drive);
790 }
791}
792
793static void idefloppy_rw_callback (ide_drive_t *drive)
794{
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100795 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 idefloppy_do_end_request(drive, 1, 0);
798 return;
799}
800
801static void idefloppy_create_prevent_cmd (idefloppy_pc_t *pc, int prevent)
802{
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100803 debug_log("creating prevent removal command, prevent = %d\n", prevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100806 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 pc->c[4] = prevent;
808}
809
810static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t *pc)
811{
812 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100813 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 pc->c[7] = 255;
815 pc->c[8] = 255;
816 pc->request_transfer = 255;
817}
818
819static void idefloppy_create_format_unit_cmd (idefloppy_pc_t *pc, int b, int l,
820 int flags)
821{
822 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100823 pc->c[0] = GPCMD_FORMAT_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 pc->c[1] = 0x17;
825
826 memset(pc->buffer, 0, 12);
827 pc->buffer[1] = 0xA2;
828 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
829
830 if (flags & 1) /* Verify bit on... */
831 pc->buffer[1] ^= 0x20; /* ... turn off DCRT bit */
832 pc->buffer[3] = 8;
833
Borislav Petkov8f622432008-02-02 19:56:33 +0100834 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buffer[4]));
835 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buffer[8]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 pc->buffer_size=12;
837 set_bit(PC_WRITING, &pc->flags);
838}
839
840/*
841 * A mode sense command is used to "sense" floppy parameters.
842 */
843static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t *pc, u8 page_code, u8 type)
844{
Borislav Petkov24a5d702008-02-02 19:56:34 +0100845 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100848 pc->c[0] = GPCMD_MODE_SENSE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 pc->c[1] = 0;
850 pc->c[2] = page_code + (type << 6);
851
852 switch (page_code) {
853 case IDEFLOPPY_CAPABILITIES_PAGE:
854 length += 12;
855 break;
856 case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
857 length += 32;
858 break;
859 default:
860 printk(KERN_ERR "ide-floppy: unsupported page code "
861 "in create_mode_sense_cmd\n");
862 }
Borislav Petkov8f622432008-02-02 19:56:33 +0100863 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 pc->request_transfer = length;
865}
866
867static void idefloppy_create_start_stop_cmd (idefloppy_pc_t *pc, int start)
868{
869 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100870 pc->c[0] = GPCMD_START_STOP_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 pc->c[4] = start;
872}
873
874static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t *pc)
875{
876 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100877 pc->c[0] = GPCMD_TEST_UNIT_READY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
879
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100880static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
881 idefloppy_pc_t *pc, struct request *rq,
882 unsigned long sector)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
884 int block = sector / floppy->bs_factor;
885 int blocks = rq->nr_sectors / floppy->bs_factor;
886 int cmd = rq_data_dir(rq);
887
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100888 debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 block, blocks);
890
891 idefloppy_init_pc(pc);
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100892 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
893 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
Borislav Petkov8f622432008-02-02 19:56:33 +0100894 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 pc->callback = &idefloppy_rw_callback;
897 pc->rq = rq;
898 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200899 if (rq->cmd_flags & REQ_RW)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 set_bit(PC_WRITING, &pc->flags);
901 pc->buffer = NULL;
902 pc->request_transfer = pc->buffer_size = blocks * floppy->block_size;
903 set_bit(PC_DMA_RECOMMENDED, &pc->flags);
904}
905
Jens Axboe3d6392c2007-07-09 12:38:05 +0200906static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq)
908{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 idefloppy_init_pc(pc);
Jens Axboe3d6392c2007-07-09 12:38:05 +0200910 pc->callback = &idefloppy_rw_callback;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 memcpy(pc->c, rq->cmd, sizeof(pc->c));
Jens Axboe3d6392c2007-07-09 12:38:05 +0200912 pc->rq = rq;
913 pc->b_count = rq->data_len;
914 if (rq->data_len && rq_data_dir(rq) == WRITE)
915 set_bit(PC_WRITING, &pc->flags);
916 pc->buffer = rq->data;
917 if (rq->bio)
918 set_bit(PC_DMA_RECOMMENDED, &pc->flags);
919
920 /*
921 * possibly problematic, doesn't look like ide-floppy correctly
922 * handled scattered requests if dma fails...
923 */
924 pc->request_transfer = pc->buffer_size = rq->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925}
926
927/*
928 * idefloppy_do_request is our request handling function.
929 */
930static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request *rq, sector_t block_s)
931{
932 idefloppy_floppy_t *floppy = drive->driver_data;
933 idefloppy_pc_t *pc;
934 unsigned long block = (unsigned long)block_s;
935
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100936 debug_log("dev: %s, cmd_type: %x, errors: %d\n",
Randy Dunlap18cddac2006-06-25 05:48:56 -0700937 rq->rq_disk ? rq->rq_disk->disk_name : "?",
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100938 rq->cmd_type, rq->errors);
939 debug_log("sector: %ld, nr_sectors: %ld, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 "current_nr_sectors: %d\n", (long)rq->sector,
941 rq->nr_sectors, rq->current_nr_sectors);
942
943 if (rq->errors >= ERROR_MAX) {
Borislav Petkovd652c132008-02-02 19:56:35 +0100944 if (floppy->failed_pc)
945 ide_floppy_report_error(floppy, floppy->failed_pc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 else
947 printk(KERN_ERR "ide-floppy: %s: I/O error\n",
948 drive->name);
949 idefloppy_do_end_request(drive, 0, 0);
950 return ide_stopped;
951 }
Jens Axboe4aff5e22006-08-10 08:44:47 +0200952 if (blk_fs_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 if (((long)rq->sector % floppy->bs_factor) ||
954 (rq->nr_sectors % floppy->bs_factor)) {
955 printk("%s: unsupported r/w request size\n",
956 drive->name);
957 idefloppy_do_end_request(drive, 0, 0);
958 return ide_stopped;
959 }
960 pc = idefloppy_next_pc_storage(drive);
961 idefloppy_create_rw_cmd(floppy, pc, rq, block);
Jens Axboe4aff5e22006-08-10 08:44:47 +0200962 } else if (blk_special_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 pc = (idefloppy_pc_t *) rq->buffer;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200964 } else if (blk_pc_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 pc = idefloppy_next_pc_storage(drive);
Jens Axboe3d6392c2007-07-09 12:38:05 +0200966 idefloppy_blockpc_cmd(floppy, pc, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 } else {
968 blk_dump_rq_flags(rq,
969 "ide-floppy: unsupported command in queue");
970 idefloppy_do_end_request(drive, 0, 0);
971 return ide_stopped;
972 }
973
974 pc->rq = rq;
975 return idefloppy_issue_pc(drive, pc);
976}
977
978/*
979 * idefloppy_queue_pc_tail adds a special packet command request to the
980 * tail of the request queue, and waits for it to be serviced.
981 */
982static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc)
983{
984 struct ide_floppy_obj *floppy = drive->driver_data;
985 struct request rq;
986
987 ide_init_drive_cmd (&rq);
988 rq.buffer = (char *) pc;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200989 rq.cmd_type = REQ_TYPE_SPECIAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 rq.rq_disk = floppy->disk;
991
992 return ide_do_drive_cmd(drive, &rq, ide_wait);
993}
994
995/*
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100996 * Look at the flexible disk page parameters. We ignore the CHS capacity
997 * parameters and use the LBA parameters instead.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 */
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100999static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
1001 idefloppy_floppy_t *floppy = drive->driver_data;
1002 idefloppy_pc_t pc;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001003 u8 *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 int capacity, lba_capacity;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001005 u16 transfer_rate, sector_size, cyls, rpm;
1006 u8 heads, sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001008 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE,
1009 MODE_SENSE_CURRENT);
1010
1011 if (idefloppy_queue_pc_tail(drive, &pc)) {
1012 printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
1013 " parameters\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 return 1;
1015 }
Borislav Petkov24a5d702008-02-02 19:56:34 +01001016 floppy->wp = !!(pc.buffer[3] & 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 set_disk_ro(floppy->disk, floppy->wp);
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001018 page = &pc.buffer[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001020 transfer_rate = be16_to_cpu(*(u16 *)&pc.buffer[8 + 2]);
1021 sector_size = be16_to_cpu(*(u16 *)&pc.buffer[8 + 6]);
1022 cyls = be16_to_cpu(*(u16 *)&pc.buffer[8 + 8]);
1023 rpm = be16_to_cpu(*(u16 *)&pc.buffer[8 + 28]);
1024 heads = pc.buffer[8 + 4];
1025 sectors = pc.buffer[8 + 5];
1026
1027 capacity = cyls * heads * sectors * sector_size;
1028
1029 if (memcmp(page, &floppy->flexible_disk_page, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
1031 "%d sector size, %d rpm\n",
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001032 drive->name, capacity / 1024, cyls, heads,
1033 sectors, transfer_rate / 8, sector_size, rpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001035 memcpy(&floppy->flexible_disk_page, page, 32);
1036 drive->bios_cyl = cyls;
1037 drive->bios_head = heads;
1038 drive->bios_sect = sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 lba_capacity = floppy->blocks * floppy->block_size;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (capacity < lba_capacity) {
1042 printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
1043 "bytes, but the drive only handles %d\n",
1044 drive->name, lba_capacity, capacity);
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001045 floppy->blocks = floppy->block_size ?
1046 capacity / floppy->block_size : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 }
1048 return 0;
1049}
1050
Borislav Petkov948391d2008-02-02 19:56:34 +01001051static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
1053 idefloppy_floppy_t *floppy = drive->driver_data;
1054 idefloppy_pc_t pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
1056 floppy->srfp = 0;
1057 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
1058 MODE_SENSE_CURRENT);
1059
1060 set_bit(PC_SUPPRESS_ERROR, &pc.flags);
Borislav Petkov948391d2008-02-02 19:56:34 +01001061 if (idefloppy_queue_pc_tail(drive, &pc))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Borislav Petkov948391d2008-02-02 19:56:34 +01001064 floppy->srfp = pc.buffer[8 + 2] & 0x40;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 return (0);
1066}
1067
1068/*
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001069 * Determine if a media is present in the floppy drive, and if so, its LBA
1070 * capacity.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 */
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001072static int ide_floppy_get_capacity(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
1074 idefloppy_floppy_t *floppy = drive->driver_data;
1075 idefloppy_pc_t pc;
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001076 u8 *cap_desc;
1077 u8 header_len, desc_cnt;
1078 int i, rc = 1, blocks, length;
1079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 drive->bios_cyl = 0;
1081 drive->bios_head = drive->bios_sect = 0;
Alan Coxfdb77da2007-02-17 02:40:20 +01001082 floppy->blocks = 0;
1083 floppy->bs_factor = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 set_capacity(floppy->disk, 0);
1085
1086 idefloppy_create_read_capacity_cmd(&pc);
1087 if (idefloppy_queue_pc_tail(drive, &pc)) {
1088 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
1089 return 1;
1090 }
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001091 header_len = pc.buffer[3];
1092 cap_desc = &pc.buffer[4];
1093 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001095 for (i = 0; i < desc_cnt; i++) {
1096 unsigned int desc_start = 4 + i*8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001098 blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
1099 length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
1100
1101 debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
1102 i, blocks * length / 1024, blocks, length);
1103
1104 if (i)
1105 continue;
1106 /*
1107 * the code below is valid only for the 1st descriptor, ie i=0
1108 */
1109
1110 switch (pc.buffer[desc_start + 4] & 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 /* Clik! drive returns this instead of CAPACITY_CURRENT */
1112 case CAPACITY_UNFORMATTED:
1113 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags))
1114 /*
1115 * If it is not a clik drive, break out
1116 * (maintains previous driver behaviour)
1117 */
1118 break;
1119 case CAPACITY_CURRENT:
1120 /* Normal Zip/LS-120 disks */
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001121 if (memcmp(cap_desc, &floppy->cap_desc, 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 printk(KERN_INFO "%s: %dkB, %d blocks, %d "
1123 "sector size\n", drive->name,
1124 blocks * length / 1024, blocks, length);
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001125 memcpy(&floppy->cap_desc, cap_desc, 8);
1126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 if (!length || length % 512) {
1128 printk(KERN_NOTICE "%s: %d bytes block size "
1129 "not supported\n", drive->name, length);
1130 } else {
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001131 floppy->blocks = blocks;
1132 floppy->block_size = length;
1133 floppy->bs_factor = length / 512;
1134 if (floppy->bs_factor != 1)
1135 printk(KERN_NOTICE "%s: warning: non "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 "512 bytes block size not "
1137 "fully supported\n",
1138 drive->name);
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001139 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141 break;
1142 case CAPACITY_NO_CARTRIDGE:
1143 /*
1144 * This is a KERN_ERR so it appears on screen
1145 * for the user to see
1146 */
1147 printk(KERN_ERR "%s: No disk in drive\n", drive->name);
1148 break;
1149 case CAPACITY_INVALID:
1150 printk(KERN_ERR "%s: Invalid capacity for disk "
1151 "in drive\n", drive->name);
1152 break;
1153 }
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001154 debug_log("Descriptor 0 Code: %d\n",
1155 pc.buffer[desc_start + 4] & 0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
1157
1158 /* Clik! disk does not support get_flexible_disk_page */
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001159 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags))
Borislav Petkov8e81bbb2008-02-02 19:56:35 +01001160 (void) ide_floppy_get_flexible_disk_page(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
1162 set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
1163 return rc;
1164}
1165
1166/*
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001167 * Obtain the list of formattable capacities.
1168 * Very similar to ide_floppy_get_capacity, except that we push the capacity
1169 * descriptors to userland, instead of our own structures.
1170 *
1171 * Userland gives us the following structure:
1172 *
1173 * struct idefloppy_format_capacities {
1174 * int nformats;
1175 * struct {
1176 * int nblocks;
1177 * int blocksize;
1178 * } formats[];
1179 * };
1180 *
1181 * userland initializes nformats to the number of allocated formats[] records.
1182 * On exit we set nformats to the number of records we've actually initialized.
1183 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001185static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001187 idefloppy_pc_t pc;
1188 u8 header_len, desc_cnt;
1189 int i, blocks, length, u_array_size, u_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 int __user *argp;
1191
1192 if (get_user(u_array_size, arg))
1193 return (-EFAULT);
1194
1195 if (u_array_size <= 0)
1196 return (-EINVAL);
1197
1198 idefloppy_create_read_capacity_cmd(&pc);
1199 if (idefloppy_queue_pc_tail(drive, &pc)) {
1200 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001201 return (-EIO);
1202 }
1203 header_len = pc.buffer[3];
1204 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
1206 u_index = 0;
1207 argp = arg + 1;
1208
1209 /*
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001210 * We always skip the first capacity descriptor. That's the current
1211 * capacity. We are interested in the remaining descriptors, the
1212 * formattable capacities.
1213 */
1214 for (i = 1; i < desc_cnt; i++) {
1215 unsigned int desc_start = 4 + i*8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 if (u_index >= u_array_size)
1218 break; /* User-supplied buffer too small */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001220 blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
1221 length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 if (put_user(blocks, argp))
1224 return(-EFAULT);
1225 ++argp;
1226
1227 if (put_user(length, argp))
1228 return (-EFAULT);
1229 ++argp;
1230
1231 ++u_index;
1232 }
1233
1234 if (put_user(u_index, arg))
1235 return (-EFAULT);
1236 return (0);
1237}
1238
1239/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240** Get ATAPI_FORMAT_UNIT progress indication.
1241**
Matt LaPlante0779bf22006-11-30 05:24:39 +01001242** Userland gives a pointer to an int. The int is set to a progress
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243** indicator 0-65536, with 65536=100%.
1244**
1245** If the drive does not support format progress indication, we just check
1246** the dsc bit, and return either 0 or 65536.
1247*/
1248
1249static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
1250{
1251 idefloppy_floppy_t *floppy = drive->driver_data;
1252 idefloppy_pc_t pc;
1253 int progress_indication = 0x10000;
1254
1255 if (floppy->srfp) {
1256 idefloppy_create_request_sense_cmd(&pc);
1257 if (idefloppy_queue_pc_tail(drive, &pc)) {
1258 return (-EIO);
1259 }
1260
1261 if (floppy->sense_key == 2 &&
1262 floppy->asc == 4 &&
1263 floppy->ascq == 4) {
1264 progress_indication = floppy->progress_indication;
1265 }
1266 /* Else assume format_unit has finished, and we're
1267 ** at 0x10000 */
1268 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 unsigned long flags;
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001270 u8 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 local_irq_save(flags);
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001273 stat = drive->hwif->INB(IDE_STATUS_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 local_irq_restore(flags);
1275
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +01001276 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 }
1278 if (put_user(progress_indication, arg))
1279 return (-EFAULT);
1280
1281 return (0);
1282}
1283
1284/*
1285 * Return the current floppy capacity.
1286 */
1287static sector_t idefloppy_capacity (ide_drive_t *drive)
1288{
1289 idefloppy_floppy_t *floppy = drive->driver_data;
1290 unsigned long capacity = floppy->blocks * floppy->bs_factor;
1291
1292 return capacity;
1293}
1294
1295/*
Borislav Petkovf373bd82008-02-02 19:56:36 +01001296 * Check whether we can support a drive, based on the ATAPI IDENTIFY command
1297 * results.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 */
Borislav Petkovf373bd82008-02-02 19:56:36 +01001299static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300{
1301 struct idefloppy_id_gcw gcw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303 *((u16 *) &gcw) = id->config;
1304
1305#ifdef CONFIG_PPC
1306 /* kludge for Apple PowerBook internal zip */
1307 if ((gcw.device_type == 5) &&
1308 !strstr(id->model, "CD-ROM") &&
1309 strstr(id->model, "ZIP"))
Borislav Petkovf373bd82008-02-02 19:56:36 +01001310 gcw.device_type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311#endif
1312
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 if (gcw.protocol != 2)
Borislav Petkovf373bd82008-02-02 19:56:36 +01001314 printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n",
1315 gcw.protocol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 else if (gcw.device_type != 0)
Borislav Petkovf373bd82008-02-02 19:56:36 +01001317 printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set "
1318 "to floppy\n", gcw.device_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 else if (!gcw.removable)
1320 printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
1321 else if (gcw.drq_type == 3) {
Borislav Petkovf373bd82008-02-02 19:56:36 +01001322 printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not "
1323 "supported\n", gcw.drq_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 } else if (gcw.packet_size != 0) {
Borislav Petkovf373bd82008-02-02 19:56:36 +01001325 printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 "
1326 "bytes long\n", gcw.packet_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 } else
1328 return 1;
1329 return 0;
1330}
1331
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001332#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333static void idefloppy_add_settings(ide_drive_t *drive)
1334{
1335 idefloppy_floppy_t *floppy = drive->driver_data;
1336
1337/*
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +02001338 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 */
Bartlomiej Zolnierkiewicz14979432007-05-10 00:01:10 +02001340 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL);
1341 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL);
1342 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL);
1343 ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &floppy->ticks, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001345#else
1346static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
1347#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349/*
1350 * Driver initialization.
1351 */
1352static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy)
1353{
1354 struct idefloppy_id_gcw gcw;
1355
1356 *((u16 *) &gcw) = drive->id->config;
1357 floppy->pc = floppy->pc_stack;
1358 if (gcw.drq_type == 1)
1359 set_bit(IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags);
1360 /*
1361 * We used to check revisions here. At this point however
1362 * I'm giving up. Just assume they are all broken, its easier.
1363 *
1364 * The actual reason for the workarounds was likely
1365 * a driver bug after all rather than a firmware bug,
1366 * and the workaround below used to hide it. It should
1367 * be fixed as of version 1.9, but to be on the safe side
1368 * we'll leave the limitation below for the 2.2.x tree.
1369 */
1370
1371 if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) {
1372 set_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags);
1373 /* This value will be visible in the /proc/ide/hdx/settings */
1374 floppy->ticks = IDEFLOPPY_TICKS_DELAY;
1375 blk_queue_max_sectors(drive->queue, 64);
1376 }
1377
1378 /*
1379 * Guess what? The IOMEGA Clik! drive also needs the
1380 * above fix. It makes nasty clicking noises without
1381 * it, so please don't remove this.
1382 */
1383 if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) {
1384 blk_queue_max_sectors(drive->queue, 64);
1385 set_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags);
1386 }
1387
1388
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001389 (void) ide_floppy_get_capacity(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 idefloppy_add_settings(drive);
1391}
1392
Russell King4031bbe2006-01-06 11:41:00 +00001393static void ide_floppy_remove(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394{
1395 idefloppy_floppy_t *floppy = drive->driver_data;
1396 struct gendisk *g = floppy->disk;
1397
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001398 ide_proc_unregister_driver(drive, floppy->driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
1400 del_gendisk(g);
1401
1402 ide_floppy_put(floppy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
Borislav Petkov9a24b632008-02-02 19:56:33 +01001405static void idefloppy_cleanup_obj(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406{
1407 struct ide_floppy_obj *floppy = to_ide_floppy(kref);
1408 ide_drive_t *drive = floppy->drive;
1409 struct gendisk *g = floppy->disk;
1410
1411 drive->driver_data = NULL;
1412 g->private_data = NULL;
1413 put_disk(g);
1414 kfree(floppy);
1415}
1416
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001417#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418static int proc_idefloppy_read_capacity
1419 (char *page, char **start, off_t off, int count, int *eof, void *data)
1420{
1421 ide_drive_t*drive = (ide_drive_t *)data;
1422 int len;
1423
1424 len = sprintf(page,"%llu\n", (long long)idefloppy_capacity(drive));
1425 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
1426}
1427
1428static ide_proc_entry_t idefloppy_proc[] = {
1429 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
1430 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
1431 { NULL, 0, NULL, NULL }
1432};
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001433#endif /* CONFIG_IDE_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Russell King4031bbe2006-01-06 11:41:00 +00001435static int ide_floppy_probe(ide_drive_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437static ide_driver_t idefloppy_driver = {
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001438 .gen_driver = {
Laurent Riffard4ef3b8f2005-11-18 22:15:40 +01001439 .owner = THIS_MODULE,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001440 .name = "ide-floppy",
1441 .bus = &ide_bus_type,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001442 },
Russell King4031bbe2006-01-06 11:41:00 +00001443 .probe = ide_floppy_probe,
1444 .remove = ide_floppy_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 .version = IDEFLOPPY_VERSION,
1446 .media = ide_floppy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 .supports_dsc_overlap = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .do_request = idefloppy_do_request,
1449 .end_request = idefloppy_do_end_request,
1450 .error = __ide_error,
1451 .abort = __ide_abort,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001452#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 .proc = idefloppy_proc,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001454#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455};
1456
1457static int idefloppy_open(struct inode *inode, struct file *filp)
1458{
1459 struct gendisk *disk = inode->i_bdev->bd_disk;
1460 struct ide_floppy_obj *floppy;
1461 ide_drive_t *drive;
1462 idefloppy_pc_t pc;
1463 int ret = 0;
1464
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001465 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
1467 if (!(floppy = ide_floppy_get(disk)))
1468 return -ENXIO;
1469
1470 drive = floppy->drive;
1471
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001472 floppy->openers++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001474 if (floppy->openers == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1476 /* Just in case */
1477
1478 idefloppy_create_test_unit_ready_cmd(&pc);
1479 if (idefloppy_queue_pc_tail(drive, &pc)) {
1480 idefloppy_create_start_stop_cmd(&pc, 1);
1481 (void) idefloppy_queue_pc_tail(drive, &pc);
1482 }
1483
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001484 if (ide_floppy_get_capacity(drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 && (filp->f_flags & O_NDELAY) == 0
1486 /*
1487 ** Allow O_NDELAY to open a drive without a disk, or with
1488 ** an unreadable disk, so that we can get the format
1489 ** capacity of the drive or begin the format - Sam
1490 */
1491 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 ret = -EIO;
1493 goto out_put_floppy;
1494 }
1495
1496 if (floppy->wp && (filp->f_mode & 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 ret = -EROFS;
1498 goto out_put_floppy;
1499 }
1500 set_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
1501 /* IOMEGA Clik! drives do not support lock/unlock commands */
1502 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1503 idefloppy_create_prevent_cmd(&pc, 1);
1504 (void) idefloppy_queue_pc_tail(drive, &pc);
1505 }
1506 check_disk_change(inode->i_bdev);
1507 } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 ret = -EBUSY;
1509 goto out_put_floppy;
1510 }
1511 return 0;
1512
1513out_put_floppy:
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001514 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 ide_floppy_put(floppy);
1516 return ret;
1517}
1518
1519static int idefloppy_release(struct inode *inode, struct file *filp)
1520{
1521 struct gendisk *disk = inode->i_bdev->bd_disk;
1522 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1523 ide_drive_t *drive = floppy->drive;
1524 idefloppy_pc_t pc;
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001525
1526 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001528 if (floppy->openers == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 /* IOMEGA Clik! drives do not support lock/unlock commands */
1530 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1531 idefloppy_create_prevent_cmd(&pc, 0);
1532 (void) idefloppy_queue_pc_tail(drive, &pc);
1533 }
1534
1535 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1536 }
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001537
1538 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
1540 ide_floppy_put(floppy);
1541
1542 return 0;
1543}
1544
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08001545static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1546{
1547 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1548 ide_drive_t *drive = floppy->drive;
1549
1550 geo->heads = drive->bios_head;
1551 geo->sectors = drive->bios_sect;
1552 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
1553 return 0;
1554}
1555
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001556static int ide_floppy_lockdoor(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc,
1557 unsigned long arg, unsigned int cmd)
1558{
1559 if (floppy->openers > 1)
1560 return -EBUSY;
1561
1562 /* The IOMEGA Clik! Drive doesn't support this command -
1563 * no room for an eject mechanism */
1564 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1565 int prevent = arg ? 1 : 0;
1566
1567 if (cmd == CDROMEJECT)
1568 prevent = 0;
1569
1570 idefloppy_create_prevent_cmd(pc, prevent);
1571 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1572 }
1573
1574 if (cmd == CDROMEJECT) {
1575 idefloppy_create_start_stop_cmd(pc, 2);
1576 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1577 }
1578
1579 return 0;
1580}
1581
1582static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
1583 int __user *arg)
1584{
1585 int blocks, length, flags, err = 0;
1586 idefloppy_pc_t pc;
1587
1588 if (floppy->openers > 1) {
1589 /* Don't format if someone is using the disk */
1590 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1591 return -EBUSY;
1592 }
1593
1594 set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1595
1596 /*
1597 * Send ATAPI_FORMAT_UNIT to the drive.
1598 *
1599 * Userland gives us the following structure:
1600 *
1601 * struct idefloppy_format_command {
1602 * int nblocks;
1603 * int blocksize;
1604 * int flags;
1605 * } ;
1606 *
1607 * flags is a bitmask, currently, the only defined flag is:
1608 *
1609 * 0x01 - verify media after format.
1610 */
1611 if (get_user(blocks, arg) ||
1612 get_user(length, arg+1) ||
1613 get_user(flags, arg+2)) {
1614 err = -EFAULT;
1615 goto out;
1616 }
1617
1618 (void) idefloppy_get_sfrp_bit(floppy->drive);
1619 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1620
1621 if (idefloppy_queue_pc_tail(floppy->drive, &pc))
1622 err = -EIO;
1623
1624out:
1625 if (err)
1626 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1627 return err;
1628}
1629
1630
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631static int idefloppy_ioctl(struct inode *inode, struct file *file,
1632 unsigned int cmd, unsigned long arg)
1633{
1634 struct block_device *bdev = inode->i_bdev;
1635 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1636 ide_drive_t *drive = floppy->drive;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001637 idefloppy_pc_t pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 void __user *argp = (void __user *)arg;
Ondrej Zary07203f62005-11-10 00:25:15 +01001639 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 switch (cmd) {
1642 case CDROMEJECT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 /* fall through */
1644 case CDROM_LOCKDOOR:
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001645 return ide_floppy_lockdoor(floppy, &pc, arg, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
1647 return 0;
1648 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001649 return ide_floppy_get_format_capacities(drive, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 case IDEFLOPPY_IOCTL_FORMAT_START:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 if (!(file->f_mode & 2))
1652 return -EPERM;
1653
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001654 return ide_floppy_format_unit(floppy, (int __user *)arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1656 return idefloppy_get_format_progress(drive, argp);
1657 }
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +02001658
1659 /*
1660 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
1661 * and CDROM_SEND_PACKET (legacy) ioctls
1662 */
1663 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
1664 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
1665 bdev->bd_disk, cmd, argp);
1666 else
1667 err = -ENOTTY;
1668
1669 if (err == -ENOTTY)
1670 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
1671
1672 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
1675static int idefloppy_media_changed(struct gendisk *disk)
1676{
1677 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1678 ide_drive_t *drive = floppy->drive;
1679
1680 /* do not scan partitions twice if this is a removable device */
1681 if (drive->attach) {
1682 drive->attach = 0;
1683 return 0;
1684 }
1685 return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags);
1686}
1687
1688static int idefloppy_revalidate_disk(struct gendisk *disk)
1689{
1690 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1691 set_capacity(disk, idefloppy_capacity(floppy->drive));
1692 return 0;
1693}
1694
1695static struct block_device_operations idefloppy_ops = {
1696 .owner = THIS_MODULE,
1697 .open = idefloppy_open,
1698 .release = idefloppy_release,
1699 .ioctl = idefloppy_ioctl,
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08001700 .getgeo = idefloppy_getgeo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 .media_changed = idefloppy_media_changed,
1702 .revalidate_disk= idefloppy_revalidate_disk
1703};
1704
Russell King4031bbe2006-01-06 11:41:00 +00001705static int ide_floppy_probe(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
1707 idefloppy_floppy_t *floppy;
1708 struct gendisk *g;
1709
1710 if (!strstr("ide-floppy", drive->driver_req))
1711 goto failed;
1712 if (!drive->present)
1713 goto failed;
1714 if (drive->media != ide_floppy)
1715 goto failed;
1716 if (!idefloppy_identify_device (drive, drive->id)) {
1717 printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
1718 goto failed;
1719 }
1720 if (drive->scsi) {
1721 printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
1722 goto failed;
1723 }
Robert P. J. Day5cbded52006-12-13 00:35:56 -08001724 if ((floppy = kzalloc(sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name);
1726 goto failed;
1727 }
1728
1729 g = alloc_disk(1 << PARTN_BITS);
1730 if (!g)
1731 goto out_free_floppy;
1732
1733 ide_init_disk(g, drive);
1734
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001735 ide_proc_register_driver(drive, &idefloppy_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 kref_init(&floppy->kref);
1738
1739 floppy->drive = drive;
1740 floppy->driver = &idefloppy_driver;
1741 floppy->disk = g;
1742
1743 g->private_data = &floppy->driver;
1744
1745 drive->driver_data = floppy;
1746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 idefloppy_setup (drive, floppy);
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001748
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 g->minors = 1 << PARTN_BITS;
1750 g->driverfs_dev = &drive->gendev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
1752 g->fops = &idefloppy_ops;
1753 drive->attach = 1;
1754 add_disk(g);
1755 return 0;
1756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757out_free_floppy:
1758 kfree(floppy);
1759failed:
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001760 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
1763MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
1764
1765static void __exit idefloppy_exit (void)
1766{
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001767 driver_unregister(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
Bartlomiej Zolnierkiewicz17514e82005-11-19 22:24:35 +01001770static int __init idefloppy_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771{
1772 printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001773 return driver_register(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774}
1775
Kay Sievers263756e2005-12-12 18:03:44 +01001776MODULE_ALIAS("ide:*m-floppy*");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777module_init(idefloppy_init);
1778module_exit(idefloppy_exit);
1779MODULE_LICENSE("GPL");