blob: e9034c0125f3e32440d2d0d2a9de9fd067eada09 [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
Borislav Petkov0571c7a2008-02-02 19:56:38 +01007 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * This driver supports the following IDE floppy drives:
9 *
10 * LS-120/240 SuperDisk
11 * Iomega Zip 100/250
12 * Iomega PC Card Clik!/PocketZip
13 *
Borislav Petkovd3f20842008-02-01 23:09:33 +010014 * For a historical changelog see
15 * Documentation/ide/ChangeLog.ide-floppy.1996-2002
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 */
17
Borislav Petkovfc6c5bc2008-02-02 19:56:38 +010018#define IDEFLOPPY_VERSION "1.00"
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/string.h>
23#include <linux/kernel.h>
24#include <linux/delay.h>
25#include <linux/timer.h>
26#include <linux/mm.h>
27#include <linux/interrupt.h>
28#include <linux/major.h>
29#include <linux/errno.h>
30#include <linux/genhd.h>
31#include <linux/slab.h>
32#include <linux/cdrom.h>
33#include <linux/ide.h>
34#include <linux/bitops.h>
Arjan van de Vencf8b8972006-03-23 03:00:45 -080035#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +020037#include <scsi/scsi_ioctl.h>
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/byteorder.h>
Borislav Petkov7e8b1632008-02-02 19:56:34 +010040#include <linux/irq.h>
41#include <linux/uaccess.h>
42#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/unaligned.h>
44
Borislav Petkovf373bd82008-02-02 19:56:36 +010045/* define to see debug info */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define IDEFLOPPY_DEBUG_LOG 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
Borislav Petkov0571c7a2008-02-02 19:56:38 +010049#define IDEFLOPPY_DEBUG(fmt, args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#if IDEFLOPPY_DEBUG_LOG
Borislav Petkovbcc77d92008-02-02 19:56:34 +010052#define debug_log(fmt, args...) \
53 printk(KERN_INFO "ide-floppy: " fmt, ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#else
Borislav Petkov0571c7a2008-02-02 19:56:38 +010055#define debug_log(fmt, args...) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#endif
57
58
Borislav Petkov0571c7a2008-02-02 19:56:38 +010059/* Some drives require a longer irq timeout. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
61
62/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +010063 * After each failed packet command we issue a request sense command and retry
64 * the packet command IDEFLOPPY_MAX_PC_RETRIES times.
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 */
66#define IDEFLOPPY_MAX_PC_RETRIES 3
67
68/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +010069 * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
70 * bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 */
72#define IDEFLOPPY_PC_BUFFER_SIZE 256
73
74/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +010075 * In various places in the driver, we need to allocate storage for packet
76 * commands and requests, which will remain valid while we leave the driver to
77 * wait for an interrupt or a timeout event.
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 */
79#define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
80
Borislav Petkov194ec0c2008-02-02 19:56:35 +010081/* format capacities descriptor codes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#define CAPACITY_INVALID 0x00
83#define CAPACITY_UNFORMATTED 0x01
84#define CAPACITY_CURRENT 0x02
85#define CAPACITY_NO_CARTRIDGE 0x03
86
87/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +010088 * Most of our global data which we need to save even as we leave the driver
89 * due to an interrupt or a timer event is stored in a variable of type
90 * idefloppy_floppy_t, defined below.
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 */
92typedef struct ide_floppy_obj {
93 ide_drive_t *drive;
94 ide_driver_t *driver;
95 struct gendisk *disk;
96 struct kref kref;
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +010097 unsigned int openers; /* protected by BKL for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 /* Current packet command */
Borislav Petkov8e555122008-04-18 00:46:27 +0200100 struct ide_atapi_pc *pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 /* Last failed packet command */
Borislav Petkov8e555122008-04-18 00:46:27 +0200102 struct ide_atapi_pc *failed_pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 /* Packet command stack */
Borislav Petkov8e555122008-04-18 00:46:27 +0200104 struct ide_atapi_pc pc_stack[IDEFLOPPY_PC_STACK];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* Next free packet command storage space */
106 int pc_stack_index;
107 struct request rq_stack[IDEFLOPPY_PC_STACK];
108 /* We implement a circular array */
109 int rq_stack_index;
110
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100111 /* Last error information */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 u8 sense_key, asc, ascq;
113 /* delay this long before sending packet command */
114 u8 ticks;
115 int progress_indication;
116
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100117 /* Device information */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 /* Current format */
119 int blocks, block_size, bs_factor;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100120 /* Last format capacity descriptor */
121 u8 cap_desc[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 /* Copy of the flexible disk page */
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100123 u8 flexible_disk_page[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /* Write protect */
125 int wp;
126 /* Supports format progress report */
127 int srfp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128} idefloppy_floppy_t;
129
Bartlomiej Zolnierkiewiczc40d3d32005-08-18 22:09:21 +0200130#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100132/* Defines for the MODE SENSE command */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#define MODE_SENSE_CURRENT 0x00
134#define MODE_SENSE_CHANGEABLE 0x01
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100135#define MODE_SENSE_DEFAULT 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#define MODE_SENSE_SAVED 0x03
137
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100138/* IOCTLs used in low-level formatting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
140#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
141#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
142#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
143
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100144/* Error code returned in rq->errors to the higher part of the driver. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define IDEFLOPPY_ERROR_GENERAL 101
146
147/*
Borislav Petkov948391d2008-02-02 19:56:34 +0100148 * Pages of the SELECT SENSE / MODE SENSE packet commands.
149 * See SFF-8070i spec.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 */
151#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
152#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
153
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800154static DEFINE_MUTEX(idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
157
158#define ide_floppy_g(disk) \
159 container_of((disk)->private_data, struct ide_floppy_obj, driver)
160
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200161static void idefloppy_cleanup_obj(struct kref *);
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
164{
165 struct ide_floppy_obj *floppy = NULL;
166
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800167 mutex_lock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 floppy = ide_floppy_g(disk);
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200169 if (floppy) {
Bartlomiej Zolnierkiewiczd3e33ff2008-08-05 18:16:59 +0200170 if (ide_device_get(floppy->drive))
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200171 floppy = NULL;
Bartlomiej Zolnierkiewiczd3e33ff2008-08-05 18:16:59 +0200172 else
173 kref_get(&floppy->kref);
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200174 }
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800175 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return floppy;
177}
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static void ide_floppy_put(struct ide_floppy_obj *floppy)
180{
Bartlomiej Zolnierkiewiczd3e33ff2008-08-05 18:16:59 +0200181 ide_drive_t *drive = floppy->drive;
182
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800183 mutex_lock(&idefloppy_ref_mutex);
Borislav Petkov9a24b632008-02-02 19:56:33 +0100184 kref_put(&floppy->kref, idefloppy_cleanup_obj);
Bartlomiej Zolnierkiewiczd3e33ff2008-08-05 18:16:59 +0200185 ide_device_put(drive);
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800186 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
189/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100190 * Used to finish servicing a request. For read/write requests, we will call
191 * ide_end_request to pass to the next buffer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 */
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200193static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
195 idefloppy_floppy_t *floppy = drive->driver_data;
196 struct request *rq = HWGROUP(drive)->rq;
197 int error;
198
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100199 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 switch (uptodate) {
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100202 case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
203 case 1: error = 0; break;
204 default: error = uptodate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206 if (error)
207 floppy->failed_pc = NULL;
208 /* Why does this happen? */
209 if (!rq)
210 return 0;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200211 if (!blk_special_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 /* our real local end request function */
213 ide_end_request(drive, uptodate, nsecs);
214 return 0;
215 }
216 rq->errors = error;
217 /* fixme: need to move this local also */
218 ide_end_drive_cmd(drive, 0, 0);
219 return 0;
220}
221
Borislav Petkov8e555122008-04-18 00:46:27 +0200222static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
Borislav Petkov32925e12008-02-02 19:56:36 +0100223 unsigned int bcount, int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Bartlomiej Zolnierkiewicz9567b342008-04-28 23:44:36 +0200225 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 struct request *rq = pc->rq;
NeilBrown5705f702007-09-25 12:35:59 +0200227 struct req_iterator iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 struct bio_vec *bvec;
229 unsigned long flags;
NeilBrown5705f702007-09-25 12:35:59 +0200230 int count, done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 char *data;
232
NeilBrown5705f702007-09-25 12:35:59 +0200233 rq_for_each_segment(bvec, rq, iter) {
Jens Axboe6c92e692007-08-16 13:43:12 +0200234 if (!bcount)
235 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Jens Axboe6c92e692007-08-16 13:43:12 +0200237 count = min(bvec->bv_len, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Jens Axboe6c92e692007-08-16 13:43:12 +0200239 data = bvec_kmap_irq(bvec, &flags);
Borislav Petkov32925e12008-02-02 19:56:36 +0100240 if (direction)
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200241 hwif->tp_ops->output_data(drive, NULL, data, count);
Borislav Petkov32925e12008-02-02 19:56:36 +0100242 else
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200243 hwif->tp_ops->input_data(drive, NULL, data, count);
Jens Axboe6c92e692007-08-16 13:43:12 +0200244 bvec_kunmap_irq(data, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Jens Axboe6c92e692007-08-16 13:43:12 +0200246 bcount -= count;
247 pc->b_count += count;
248 done += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200251 idefloppy_end_request(drive, 1, done >> 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 if (bcount) {
Borislav Petkov32925e12008-02-02 19:56:36 +0100254 printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
255 drive->name, __func__, bcount);
Bartlomiej Zolnierkiewicz9f87abe2008-04-28 23:44:41 +0200256 ide_pad_transfer(drive, direction, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258}
259
Borislav Petkov8e555122008-04-18 00:46:27 +0200260static void idefloppy_update_buffers(ide_drive_t *drive,
261 struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
263 struct request *rq = pc->rq;
264 struct bio *bio = rq->bio;
265
266 while ((bio = rq->bio) != NULL)
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200267 idefloppy_end_request(drive, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
269
270/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100271 * Generate a new packet command request in front of the request queue, before
272 * the current request so that it will be processed immediately, on the next
273 * pass through the driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 */
Borislav Petkov8e555122008-04-18 00:46:27 +0200275static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100276 struct request *rq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
278 struct ide_floppy_obj *floppy = drive->driver_data;
279
FUJITA Tomonori124cafc2008-07-15 21:21:44 +0200280 blk_rq_init(NULL, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 rq->buffer = (char *) pc;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200282 rq->cmd_type = REQ_TYPE_SPECIAL;
Bartlomiej Zolnierkiewicze8a96aa2008-07-15 21:21:41 +0200283 rq->cmd_flags |= REQ_PREEMPT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 rq->rq_disk = floppy->disk;
Borislav Petkov20cd93be672008-07-23 19:56:00 +0200285 memcpy(rq->cmd, pc->c, 12);
FUJITA Tomonori63f5abb2008-07-15 21:21:51 +0200286 ide_do_drive_cmd(drive, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
Borislav Petkov8e555122008-04-18 00:46:27 +0200289static struct ide_atapi_pc *idefloppy_next_pc_storage(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 idefloppy_floppy_t *floppy = drive->driver_data;
292
293 if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100294 floppy->pc_stack_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return (&floppy->pc_stack[floppy->pc_stack_index++]);
296}
297
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100298static struct request *idefloppy_next_rq_storage(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 idefloppy_floppy_t *floppy = drive->driver_data;
301
302 if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK)
303 floppy->rq_stack_index = 0;
304 return (&floppy->rq_stack[floppy->rq_stack_index++]);
305}
306
Borislav Petkov81f49382008-07-15 21:21:56 +0200307static void ide_floppy_callback(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
309 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov81f49382008-07-15 21:21:56 +0200310 struct ide_atapi_pc *pc = floppy->pc;
311 int uptodate = pc->error ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100313 debug_log("Reached %s\n", __func__);
314
Bartlomiej Zolnierkiewiczdd2e9a02008-07-15 21:22:01 +0200315 if (floppy->failed_pc == pc)
316 floppy->failed_pc = NULL;
317
Borislav Petkov81f49382008-07-15 21:21:56 +0200318 if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 ||
319 (pc->rq && blk_pc_request(pc->rq)))
320 uptodate = 1; /* FIXME */
321 else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
322 u8 *buf = floppy->pc->buf;
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100323
Borislav Petkov81f49382008-07-15 21:21:56 +0200324 if (!pc->error) {
325 floppy->sense_key = buf[2] & 0x0F;
326 floppy->asc = buf[12];
327 floppy->ascq = buf[13];
328 floppy->progress_indication = buf[15] & 0x80 ?
329 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
330
331 if (floppy->failed_pc)
332 debug_log("pc = %x, ", floppy->failed_pc->c[0]);
333
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100334 debug_log("sense key = %x, asc = %x, ascq = %x\n",
Borislav Petkov81f49382008-07-15 21:21:56 +0200335 floppy->sense_key, floppy->asc, floppy->ascq);
336 } else
337 printk(KERN_ERR "Error in REQUEST SENSE itself - "
338 "Aborting request!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Borislav Petkov81f49382008-07-15 21:21:56 +0200341 idefloppy_end_request(drive, uptodate, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
Borislav Petkov8e555122008-04-18 00:46:27 +0200344static void idefloppy_init_pc(struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Borislav Petkov68dc3572008-07-16 20:33:47 +0200346 memset(pc, 0, sizeof(*pc));
Borislav Petkov8e555122008-04-18 00:46:27 +0200347 pc->buf = pc->pc_buf;
348 pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Borislav Petkov8e555122008-04-18 00:46:27 +0200351static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Borislav Petkov30d67092008-02-02 19:56:33 +0100353 idefloppy_init_pc(pc);
354 pc->c[0] = GPCMD_REQUEST_SENSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 pc->c[4] = 255;
Borislav Petkov8e555122008-04-18 00:46:27 +0200356 pc->req_xfer = 18;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
359/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100360 * Called when an error was detected during the last packet command. We queue a
361 * request sense packet command in the head of the request list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 */
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100363static void idefloppy_retry_pc(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Borislav Petkov8e555122008-04-18 00:46:27 +0200365 struct ide_atapi_pc *pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 struct request *rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Bartlomiej Zolnierkiewicz64a57fe2008-02-06 02:57:51 +0100368 (void)ide_read_error(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 pc = idefloppy_next_pc_storage(drive);
370 rq = idefloppy_next_rq_storage(drive);
371 idefloppy_create_request_sense_cmd(pc);
372 idefloppy_queue_pc_head(drive, pc, rq);
373}
374
Borislav Petkov0eea6452008-02-02 19:56:36 +0100375/* The usual interrupt handler called during a packet command. */
Paolo Ciarrocchi52d3ccf2008-04-26 17:36:41 +0200376static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
378 idefloppy_floppy_t *floppy = drive->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Bartlomiej Zolnierkiewicz646c0cb2008-07-15 21:22:03 +0200380 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
381 IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers,
382 idefloppy_retry_pc, NULL, ide_floppy_io_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383}
384
385/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100386 * What we have here is a classic case of a top half / bottom half interrupt
387 * service routine. In interrupt mode, the device sends an interrupt to signal
388 * that it is ready to receive a packet. However, we need to delay about 2-3
389 * ticks before issuing the packet or we gets in trouble.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 */
Borislav Petkovcbbc4e82008-07-15 21:22:03 +0200391static int idefloppy_transfer_pc(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
393 idefloppy_floppy_t *floppy = drive->driver_data;
394
395 /* Send the actual packet */
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200396 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
Bartlomiej Zolnierkiewicz9567b342008-04-28 23:44:36 +0200397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 /* Timeout for the packet command */
399 return IDEFLOPPY_WAIT_CMD;
400}
401
Borislav Petkovcbbc4e82008-07-15 21:22:03 +0200402
403/*
404 * Called as an interrupt (or directly). When the device says it's ready for a
405 * packet, we schedule the packet transfer to occur about 2-3 ticks later in
406 * transfer_pc.
407 */
408static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
410 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz6ffb66412008-07-15 21:21:56 +0200411 struct ide_atapi_pc *pc = floppy->pc;
Bartlomiej Zolnierkiewicz0b2eea42008-07-15 21:21:54 +0200412 ide_expiry_t *expiry;
413 unsigned int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100415 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 * The following delay solves a problem with ATAPI Zip 100 drives
417 * where the Busy flag was apparently being deasserted before the
418 * unit was ready to receive data. This was happening on a
419 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
420 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
421 * used until after the packet is moved in about 50 msec.
422 */
Borislav Petkovea68d272008-07-23 19:56:01 +0200423 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
Bartlomiej Zolnierkiewicz0b2eea42008-07-15 21:21:54 +0200424 timeout = floppy->ticks;
Borislav Petkovcbbc4e82008-07-15 21:22:03 +0200425 expiry = &idefloppy_transfer_pc;
Bartlomiej Zolnierkiewicz0b2eea42008-07-15 21:21:54 +0200426 } else {
427 timeout = IDEFLOPPY_WAIT_CMD;
428 expiry = NULL;
429 }
Borislav Petkov0078df22008-02-02 19:56:33 +0100430
Bartlomiej Zolnierkiewicz594c16d2008-07-15 21:21:58 +0200431 return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
Borislav Petkovd652c132008-02-02 19:56:35 +0100434static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
Borislav Petkov8e555122008-04-18 00:46:27 +0200435 struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Borislav Petkovd652c132008-02-02 19:56:35 +0100437 /* supress error messages resulting from Medium not present */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 if (floppy->sense_key == 0x02 &&
439 floppy->asc == 0x3a &&
440 floppy->ascq == 0x00)
Borislav Petkovd652c132008-02-02 19:56:35 +0100441 return;
442
443 printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, "
444 "asc = %2x, ascq = %2x\n",
445 floppy->drive->name, pc->c[0], floppy->sense_key,
446 floppy->asc, floppy->ascq);
447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448}
449
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100450static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
Borislav Petkov8e555122008-04-18 00:46:27 +0200451 struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
453 idefloppy_floppy_t *floppy = drive->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 if (floppy->failed_pc == NULL &&
Borislav Petkov30d67092008-02-02 19:56:33 +0100456 pc->c[0] != GPCMD_REQUEST_SENSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 floppy->failed_pc = pc;
458 /* Set the current packet command */
459 floppy->pc = pc;
460
Borislav Petkov757ced82008-02-02 19:56:37 +0100461 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100462 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
Borislav Petkov757ced82008-02-02 19:56:37 +0100463 ide_floppy_report_error(floppy, pc);
464 /* Giving up */
465 pc->error = IDEFLOPPY_ERROR_GENERAL;
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 floppy->failed_pc = NULL;
Borislav Petkov2207fa52008-07-23 19:55:59 +0200468 drive->pc_callback(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 return ide_stopped;
470 }
471
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100472 debug_log("Retry number - %d\n", pc->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 pc->retries++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Borislav Petkovcbbc4e82008-07-15 21:22:03 +0200476 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer,
Bartlomiej Zolnierkiewicz6bf16412008-07-15 21:22:00 +0200477 IDEFLOPPY_WAIT_CMD, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
Borislav Petkov8e555122008-04-18 00:46:27 +0200480static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100482 debug_log("creating prevent removal command, prevent = %d\n", prevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100485 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 pc->c[4] = prevent;
487}
488
Borislav Petkov8e555122008-04-18 00:46:27 +0200489static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
491 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100492 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 pc->c[7] = 255;
494 pc->c[8] = 255;
Borislav Petkov8e555122008-04-18 00:46:27 +0200495 pc->req_xfer = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
Borislav Petkov8e555122008-04-18 00:46:27 +0200498static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
499 int l, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
501 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100502 pc->c[0] = GPCMD_FORMAT_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 pc->c[1] = 0x17;
504
Borislav Petkov8e555122008-04-18 00:46:27 +0200505 memset(pc->buf, 0, 12);
506 pc->buf[1] = 0xA2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
508
509 if (flags & 1) /* Verify bit on... */
Borislav Petkov8e555122008-04-18 00:46:27 +0200510 pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */
511 pc->buf[3] = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Borislav Petkov8e555122008-04-18 00:46:27 +0200513 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4]));
514 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8]));
515 pc->buf_size = 12;
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100516 pc->flags |= PC_FLAG_WRITING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100519/* A mode sense command is used to "sense" floppy parameters. */
Borislav Petkov8e555122008-04-18 00:46:27 +0200520static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
521 u8 page_code, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
Borislav Petkov24a5d702008-02-02 19:56:34 +0100523 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100526 pc->c[0] = GPCMD_MODE_SENSE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 pc->c[1] = 0;
528 pc->c[2] = page_code + (type << 6);
529
530 switch (page_code) {
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100531 case IDEFLOPPY_CAPABILITIES_PAGE:
532 length += 12;
533 break;
534 case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
535 length += 32;
536 break;
537 default:
538 printk(KERN_ERR "ide-floppy: unsupported page code "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 "in create_mode_sense_cmd\n");
540 }
Borislav Petkov8f622432008-02-02 19:56:33 +0100541 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
Borislav Petkov8e555122008-04-18 00:46:27 +0200542 pc->req_xfer = length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
Borislav Petkov8e555122008-04-18 00:46:27 +0200545static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
547 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100548 pc->c[0] = GPCMD_START_STOP_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 pc->c[4] = start;
550}
551
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100552static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
Borislav Petkov8e555122008-04-18 00:46:27 +0200553 struct ide_atapi_pc *pc, struct request *rq,
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100554 unsigned long sector)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
556 int block = sector / floppy->bs_factor;
557 int blocks = rq->nr_sectors / floppy->bs_factor;
558 int cmd = rq_data_dir(rq);
559
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100560 debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 block, blocks);
562
563 idefloppy_init_pc(pc);
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100564 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
565 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
Borislav Petkov8f622432008-02-02 19:56:33 +0100566 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100567
Borislav Petkov20cd93be672008-07-23 19:56:00 +0200568 memcpy(rq->cmd, pc->c, 12);
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 pc->rq = rq;
571 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200572 if (rq->cmd_flags & REQ_RW)
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100573 pc->flags |= PC_FLAG_WRITING;
Borislav Petkov8e555122008-04-18 00:46:27 +0200574 pc->buf = NULL;
575 pc->req_xfer = pc->buf_size = blocks * floppy->block_size;
Bartlomiej Zolnierkiewicz5e331092008-07-15 21:21:56 +0200576 pc->flags |= PC_FLAG_DMA_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100579static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
Borislav Petkov8e555122008-04-18 00:46:27 +0200580 struct ide_atapi_pc *pc, struct request *rq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 idefloppy_init_pc(pc);
583 memcpy(pc->c, rq->cmd, sizeof(pc->c));
Jens Axboe3d6392c2007-07-09 12:38:05 +0200584 pc->rq = rq;
585 pc->b_count = rq->data_len;
586 if (rq->data_len && rq_data_dir(rq) == WRITE)
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100587 pc->flags |= PC_FLAG_WRITING;
Borislav Petkov8e555122008-04-18 00:46:27 +0200588 pc->buf = rq->data;
Jens Axboe3d6392c2007-07-09 12:38:05 +0200589 if (rq->bio)
Bartlomiej Zolnierkiewicz5e331092008-07-15 21:21:56 +0200590 pc->flags |= PC_FLAG_DMA_OK;
Jens Axboe3d6392c2007-07-09 12:38:05 +0200591 /*
592 * possibly problematic, doesn't look like ide-floppy correctly
593 * handled scattered requests if dma fails...
594 */
Borislav Petkov8e555122008-04-18 00:46:27 +0200595 pc->req_xfer = pc->buf_size = rq->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100598static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
599 struct request *rq, sector_t block_s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
601 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200602 struct ide_atapi_pc *pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 unsigned long block = (unsigned long)block_s;
604
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100605 debug_log("dev: %s, cmd_type: %x, errors: %d\n",
Randy Dunlap18cddac2006-06-25 05:48:56 -0700606 rq->rq_disk ? rq->rq_disk->disk_name : "?",
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100607 rq->cmd_type, rq->errors);
608 debug_log("sector: %ld, nr_sectors: %ld, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 "current_nr_sectors: %d\n", (long)rq->sector,
610 rq->nr_sectors, rq->current_nr_sectors);
611
612 if (rq->errors >= ERROR_MAX) {
Borislav Petkovd652c132008-02-02 19:56:35 +0100613 if (floppy->failed_pc)
614 ide_floppy_report_error(floppy, floppy->failed_pc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 else
616 printk(KERN_ERR "ide-floppy: %s: I/O error\n",
617 drive->name);
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200618 idefloppy_end_request(drive, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 return ide_stopped;
620 }
Jens Axboe4aff5e22006-08-10 08:44:47 +0200621 if (blk_fs_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 if (((long)rq->sector % floppy->bs_factor) ||
623 (rq->nr_sectors % floppy->bs_factor)) {
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100624 printk(KERN_ERR "%s: unsupported r/w request size\n",
625 drive->name);
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200626 idefloppy_end_request(drive, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return ide_stopped;
628 }
629 pc = idefloppy_next_pc_storage(drive);
630 idefloppy_create_rw_cmd(floppy, pc, rq, block);
Jens Axboe4aff5e22006-08-10 08:44:47 +0200631 } else if (blk_special_request(rq)) {
Borislav Petkov8e555122008-04-18 00:46:27 +0200632 pc = (struct ide_atapi_pc *) rq->buffer;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200633 } else if (blk_pc_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 pc = idefloppy_next_pc_storage(drive);
Jens Axboe3d6392c2007-07-09 12:38:05 +0200635 idefloppy_blockpc_cmd(floppy, pc, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 } else {
637 blk_dump_rq_flags(rq,
638 "ide-floppy: unsupported command in queue");
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200639 idefloppy_end_request(drive, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 return ide_stopped;
641 }
642
643 pc->rq = rq;
Bartlomiej Zolnierkiewicz5d418932008-07-15 21:21:57 +0200644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return idefloppy_issue_pc(drive, pc);
646}
647
648/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100649 * Add a special packet command request to the tail of the request queue,
650 * and wait for it to be serviced.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 */
Borislav Petkov8e555122008-04-18 00:46:27 +0200652static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
654 struct ide_floppy_obj *floppy = drive->driver_data;
FUJITA Tomonori6fe16232008-07-15 21:21:43 +0200655 struct request *rq;
656 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
FUJITA Tomonori6fe16232008-07-15 21:21:43 +0200658 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
659 rq->buffer = (char *) pc;
660 rq->cmd_type = REQ_TYPE_SPECIAL;
Borislav Petkov20cd93be672008-07-23 19:56:00 +0200661 memcpy(rq->cmd, pc->c, 12);
FUJITA Tomonori6fe16232008-07-15 21:21:43 +0200662 error = blk_execute_rq(drive->queue, floppy->disk, rq, 0);
663 blk_put_request(rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
FUJITA Tomonori6fe16232008-07-15 21:21:43 +0200665 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
668/*
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100669 * Look at the flexible disk page parameters. We ignore the CHS capacity
670 * parameters and use the LBA parameters instead.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 */
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100672static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
674 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200675 struct ide_atapi_pc pc;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100676 u8 *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 int capacity, lba_capacity;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100678 u16 transfer_rate, sector_size, cyls, rpm;
679 u8 heads, sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100681 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE,
682 MODE_SENSE_CURRENT);
683
684 if (idefloppy_queue_pc_tail(drive, &pc)) {
685 printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
686 " parameters\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 return 1;
688 }
Borislav Petkov8e555122008-04-18 00:46:27 +0200689 floppy->wp = !!(pc.buf[3] & 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 set_disk_ro(floppy->disk, floppy->wp);
Borislav Petkov8e555122008-04-18 00:46:27 +0200691 page = &pc.buf[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Harvey Harrison85ae98a32008-07-16 20:33:47 +0200693 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]);
694 sector_size = be16_to_cpup((__be16 *)&pc.buf[8 + 6]);
695 cyls = be16_to_cpup((__be16 *)&pc.buf[8 + 8]);
696 rpm = be16_to_cpup((__be16 *)&pc.buf[8 + 28]);
Borislav Petkov8e555122008-04-18 00:46:27 +0200697 heads = pc.buf[8 + 4];
698 sectors = pc.buf[8 + 5];
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100699
700 capacity = cyls * heads * sectors * sector_size;
701
702 if (memcmp(page, &floppy->flexible_disk_page, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
704 "%d sector size, %d rpm\n",
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100705 drive->name, capacity / 1024, cyls, heads,
706 sectors, transfer_rate / 8, sector_size, rpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100708 memcpy(&floppy->flexible_disk_page, page, 32);
709 drive->bios_cyl = cyls;
710 drive->bios_head = heads;
711 drive->bios_sect = sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 lba_capacity = floppy->blocks * floppy->block_size;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 if (capacity < lba_capacity) {
715 printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
716 "bytes, but the drive only handles %d\n",
717 drive->name, lba_capacity, capacity);
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100718 floppy->blocks = floppy->block_size ?
719 capacity / floppy->block_size : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721 return 0;
722}
723
Borislav Petkov948391d2008-02-02 19:56:34 +0100724static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
726 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200727 struct ide_atapi_pc pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729 floppy->srfp = 0;
730 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
731 MODE_SENSE_CURRENT);
732
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100733 pc.flags |= PC_FLAG_SUPPRESS_ERROR;
Borislav Petkov948391d2008-02-02 19:56:34 +0100734 if (idefloppy_queue_pc_tail(drive, &pc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Borislav Petkov8e555122008-04-18 00:46:27 +0200737 floppy->srfp = pc.buf[8 + 2] & 0x40;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 return (0);
739}
740
741/*
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100742 * Determine if a media is present in the floppy drive, and if so, its LBA
743 * capacity.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 */
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100745static int ide_floppy_get_capacity(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
747 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200748 struct ide_atapi_pc pc;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100749 u8 *cap_desc;
750 u8 header_len, desc_cnt;
751 int i, rc = 1, blocks, length;
752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 drive->bios_cyl = 0;
754 drive->bios_head = drive->bios_sect = 0;
Alan Coxfdb77da2007-02-17 02:40:20 +0100755 floppy->blocks = 0;
756 floppy->bs_factor = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 set_capacity(floppy->disk, 0);
758
759 idefloppy_create_read_capacity_cmd(&pc);
760 if (idefloppy_queue_pc_tail(drive, &pc)) {
761 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
762 return 1;
763 }
Borislav Petkov8e555122008-04-18 00:46:27 +0200764 header_len = pc.buf[3];
765 cap_desc = &pc.buf[4];
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100766 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100768 for (i = 0; i < desc_cnt; i++) {
769 unsigned int desc_start = 4 + i*8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Harvey Harrison85ae98a32008-07-16 20:33:47 +0200771 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
772 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100773
774 debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
775 i, blocks * length / 1024, blocks, length);
776
777 if (i)
778 continue;
779 /*
780 * the code below is valid only for the 1st descriptor, ie i=0
781 */
782
Borislav Petkov8e555122008-04-18 00:46:27 +0200783 switch (pc.buf[desc_start + 4] & 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 /* Clik! drive returns this instead of CAPACITY_CURRENT */
785 case CAPACITY_UNFORMATTED:
Borislav Petkovea68d272008-07-23 19:56:01 +0200786 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100787 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 * If it is not a clik drive, break out
789 * (maintains previous driver behaviour)
790 */
791 break;
792 case CAPACITY_CURRENT:
793 /* Normal Zip/LS-120 disks */
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100794 if (memcmp(cap_desc, &floppy->cap_desc, 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 printk(KERN_INFO "%s: %dkB, %d blocks, %d "
796 "sector size\n", drive->name,
797 blocks * length / 1024, blocks, length);
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100798 memcpy(&floppy->cap_desc, cap_desc, 8);
799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 if (!length || length % 512) {
801 printk(KERN_NOTICE "%s: %d bytes block size "
802 "not supported\n", drive->name, length);
803 } else {
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100804 floppy->blocks = blocks;
805 floppy->block_size = length;
806 floppy->bs_factor = length / 512;
807 if (floppy->bs_factor != 1)
808 printk(KERN_NOTICE "%s: warning: non "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 "512 bytes block size not "
810 "fully supported\n",
811 drive->name);
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100812 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
814 break;
815 case CAPACITY_NO_CARTRIDGE:
816 /*
817 * This is a KERN_ERR so it appears on screen
818 * for the user to see
819 */
820 printk(KERN_ERR "%s: No disk in drive\n", drive->name);
821 break;
822 case CAPACITY_INVALID:
823 printk(KERN_ERR "%s: Invalid capacity for disk "
824 "in drive\n", drive->name);
825 break;
826 }
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100827 debug_log("Descriptor 0 Code: %d\n",
Borislav Petkov8e555122008-04-18 00:46:27 +0200828 pc.buf[desc_start + 4] & 0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 }
830
831 /* Clik! disk does not support get_flexible_disk_page */
Borislav Petkovea68d272008-07-23 19:56:01 +0200832 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100833 (void) ide_floppy_get_flexible_disk_page(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
836 return rc;
837}
838
839/*
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100840 * Obtain the list of formattable capacities.
841 * Very similar to ide_floppy_get_capacity, except that we push the capacity
842 * descriptors to userland, instead of our own structures.
843 *
844 * Userland gives us the following structure:
845 *
846 * struct idefloppy_format_capacities {
847 * int nformats;
848 * struct {
849 * int nblocks;
850 * int blocksize;
851 * } formats[];
852 * };
853 *
854 * userland initializes nformats to the number of allocated formats[] records.
855 * On exit we set nformats to the number of records we've actually initialized.
856 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100858static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Borislav Petkov8e555122008-04-18 00:46:27 +0200860 struct ide_atapi_pc pc;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100861 u8 header_len, desc_cnt;
862 int i, blocks, length, u_array_size, u_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 int __user *argp;
864
865 if (get_user(u_array_size, arg))
866 return (-EFAULT);
867
868 if (u_array_size <= 0)
869 return (-EINVAL);
870
871 idefloppy_create_read_capacity_cmd(&pc);
872 if (idefloppy_queue_pc_tail(drive, &pc)) {
873 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100874 return (-EIO);
875 }
Borislav Petkov8e555122008-04-18 00:46:27 +0200876 header_len = pc.buf[3];
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100877 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 u_index = 0;
880 argp = arg + 1;
881
882 /*
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100883 * We always skip the first capacity descriptor. That's the current
884 * capacity. We are interested in the remaining descriptors, the
885 * formattable capacities.
886 */
887 for (i = 1; i < desc_cnt; i++) {
888 unsigned int desc_start = 4 + i*8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 if (u_index >= u_array_size)
891 break; /* User-supplied buffer too small */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Harvey Harrison85ae98a32008-07-16 20:33:47 +0200893 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
894 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 if (put_user(blocks, argp))
897 return(-EFAULT);
898 ++argp;
899
900 if (put_user(length, argp))
901 return (-EFAULT);
902 ++argp;
903
904 ++u_index;
905 }
906
907 if (put_user(u_index, arg))
908 return (-EFAULT);
909 return (0);
910}
911
912/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100913 * Get ATAPI_FORMAT_UNIT progress indication.
914 *
915 * Userland gives a pointer to an int. The int is set to a progress
916 * indicator 0-65536, with 65536=100%.
917 *
918 * If the drive does not support format progress indication, we just check
919 * the dsc bit, and return either 0 or 65536.
920 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
923{
924 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200925 struct ide_atapi_pc pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 int progress_indication = 0x10000;
927
928 if (floppy->srfp) {
929 idefloppy_create_request_sense_cmd(&pc);
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100930 if (idefloppy_queue_pc_tail(drive, &pc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 return (-EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933 if (floppy->sense_key == 2 &&
934 floppy->asc == 4 &&
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100935 floppy->ascq == 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 progress_indication = floppy->progress_indication;
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100937
938 /* Else assume format_unit has finished, and we're at 0x10000 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 } else {
Bartlomiej Zolnierkiewiczb73c7ee2008-07-23 19:55:52 +0200940 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 unsigned long flags;
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100942 u8 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 local_irq_save(flags);
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200945 stat = hwif->tp_ops->read_status(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 local_irq_restore(flags);
947
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100948 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950 if (put_user(progress_indication, arg))
951 return (-EFAULT);
952
953 return (0);
954}
955
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100956static sector_t idefloppy_capacity(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
958 idefloppy_floppy_t *floppy = drive->driver_data;
959 unsigned long capacity = floppy->blocks * floppy->bs_factor;
960
961 return capacity;
962}
963
964/*
Borislav Petkovf373bd82008-02-02 19:56:36 +0100965 * Check whether we can support a drive, based on the ATAPI IDENTIFY command
966 * results.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 */
Borislav Petkovf373bd82008-02-02 19:56:36 +0100968static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Borislav Petkov3ad67762008-04-18 00:46:25 +0200970 u8 gcw[2];
971 u8 device_type, protocol, removable, drq_type, packet_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 *((u16 *) &gcw) = id->config;
974
Borislav Petkov3ad67762008-04-18 00:46:25 +0200975 device_type = gcw[1] & 0x1F;
976 removable = (gcw[0] & 0x80) >> 7;
977 protocol = (gcw[1] & 0xC0) >> 6;
978 drq_type = (gcw[0] & 0x60) >> 5;
979 packet_size = gcw[0] & 0x03;
980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981#ifdef CONFIG_PPC
982 /* kludge for Apple PowerBook internal zip */
Borislav Petkov3ad67762008-04-18 00:46:25 +0200983 if (device_type == 5 &&
984 !strstr(id->model, "CD-ROM") && strstr(id->model, "ZIP"))
985 device_type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986#endif
987
Borislav Petkov3ad67762008-04-18 00:46:25 +0200988 if (protocol != 2)
Borislav Petkovf373bd82008-02-02 19:56:36 +0100989 printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n",
Borislav Petkov3ad67762008-04-18 00:46:25 +0200990 protocol);
991 else if (device_type != 0)
Borislav Petkovf373bd82008-02-02 19:56:36 +0100992 printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set "
Borislav Petkov3ad67762008-04-18 00:46:25 +0200993 "to floppy\n", device_type);
994 else if (!removable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
Borislav Petkov3ad67762008-04-18 00:46:25 +0200996 else if (drq_type == 3)
Borislav Petkovf373bd82008-02-02 19:56:36 +0100997 printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not "
Borislav Petkov3ad67762008-04-18 00:46:25 +0200998 "supported\n", drq_type);
999 else if (packet_size != 0)
Borislav Petkovf373bd82008-02-02 19:56:36 +01001000 printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 "
Borislav Petkov3ad67762008-04-18 00:46:25 +02001001 "bytes\n", packet_size);
1002 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 return 1;
1004 return 0;
1005}
1006
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001007#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008static void idefloppy_add_settings(ide_drive_t *drive)
1009{
1010 idefloppy_floppy_t *floppy = drive->driver_data;
1011
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001012 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1,
1013 &drive->bios_cyl, NULL);
1014 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
1015 &drive->bios_head, NULL);
1016 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1,
1017 &drive->bios_sect, NULL);
1018 ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
1019 &floppy->ticks, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020}
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001021#else
1022static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
1023#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001025static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026{
Borislav Petkov3ad67762008-04-18 00:46:25 +02001027 u8 gcw[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029 *((u16 *) &gcw) = drive->id->config;
1030 floppy->pc = floppy->pc_stack;
Borislav Petkov2207fa52008-07-23 19:55:59 +02001031 drive->pc_callback = ide_floppy_callback;
Borislav Petkov3ad67762008-04-18 00:46:25 +02001032
1033 if (((gcw[0] & 0x60) >> 5) == 1)
Borislav Petkovea68d272008-07-23 19:56:01 +02001034 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 /*
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001036 * We used to check revisions here. At this point however I'm giving up.
1037 * Just assume they are all broken, its easier.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 *
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001039 * The actual reason for the workarounds was likely a driver bug after
1040 * all rather than a firmware bug, and the workaround below used to hide
1041 * it. It should be fixed as of version 1.9, but to be on the safe side
1042 * we'll leave the limitation below for the 2.2.x tree.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) {
Borislav Petkovea68d272008-07-23 19:56:01 +02001045 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 /* This value will be visible in the /proc/ide/hdx/settings */
1047 floppy->ticks = IDEFLOPPY_TICKS_DELAY;
1048 blk_queue_max_sectors(drive->queue, 64);
1049 }
1050
1051 /*
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001052 * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes
1053 * nasty clicking noises without it, so please don't remove this.
1054 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) {
1056 blk_queue_max_sectors(drive->queue, 64);
Borislav Petkovea68d272008-07-23 19:56:01 +02001057 drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 }
1059
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001060 (void) ide_floppy_get_capacity(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 idefloppy_add_settings(drive);
1062}
1063
Russell King4031bbe2006-01-06 11:41:00 +00001064static void ide_floppy_remove(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065{
1066 idefloppy_floppy_t *floppy = drive->driver_data;
1067 struct gendisk *g = floppy->disk;
1068
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001069 ide_proc_unregister_driver(drive, floppy->driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 del_gendisk(g);
1072
1073 ide_floppy_put(floppy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074}
1075
Borislav Petkov9a24b632008-02-02 19:56:33 +01001076static void idefloppy_cleanup_obj(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077{
1078 struct ide_floppy_obj *floppy = to_ide_floppy(kref);
1079 ide_drive_t *drive = floppy->drive;
1080 struct gendisk *g = floppy->disk;
1081
1082 drive->driver_data = NULL;
1083 g->private_data = NULL;
1084 put_disk(g);
1085 kfree(floppy);
1086}
1087
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001088#ifdef CONFIG_IDE_PROC_FS
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001089static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
1090 int count, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
1092 ide_drive_t*drive = (ide_drive_t *)data;
1093 int len;
1094
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001095 len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive));
1096 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097}
1098
1099static ide_proc_entry_t idefloppy_proc[] = {
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001100 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
1101 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 { NULL, 0, NULL, NULL }
1103};
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001104#endif /* CONFIG_IDE_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Russell King4031bbe2006-01-06 11:41:00 +00001106static int ide_floppy_probe(ide_drive_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108static ide_driver_t idefloppy_driver = {
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001109 .gen_driver = {
Laurent Riffard4ef3b8f2005-11-18 22:15:40 +01001110 .owner = THIS_MODULE,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001111 .name = "ide-floppy",
1112 .bus = &ide_bus_type,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001113 },
Russell King4031bbe2006-01-06 11:41:00 +00001114 .probe = ide_floppy_probe,
1115 .remove = ide_floppy_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 .version = IDEFLOPPY_VERSION,
1117 .media = ide_floppy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 .supports_dsc_overlap = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 .do_request = idefloppy_do_request,
Borislav Petkovc2b2b292008-04-18 00:46:27 +02001120 .end_request = idefloppy_end_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 .error = __ide_error,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001122#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 .proc = idefloppy_proc,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001124#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125};
1126
1127static int idefloppy_open(struct inode *inode, struct file *filp)
1128{
1129 struct gendisk *disk = inode->i_bdev->bd_disk;
1130 struct ide_floppy_obj *floppy;
1131 ide_drive_t *drive;
Borislav Petkov8e555122008-04-18 00:46:27 +02001132 struct ide_atapi_pc pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 int ret = 0;
1134
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001135 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001137 floppy = ide_floppy_get(disk);
1138 if (!floppy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 return -ENXIO;
1140
1141 drive = floppy->drive;
1142
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001143 floppy->openers++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001145 if (floppy->openers == 1) {
Borislav Petkovea68d272008-07-23 19:56:01 +02001146 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 /* Just in case */
1148
Borislav Petkovc96a7df2008-07-16 20:33:46 +02001149 idefloppy_init_pc(&pc);
1150 pc.c[0] = GPCMD_TEST_UNIT_READY;
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 if (idefloppy_queue_pc_tail(drive, &pc)) {
1153 idefloppy_create_start_stop_cmd(&pc, 1);
1154 (void) idefloppy_queue_pc_tail(drive, &pc);
1155 }
1156
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001157 if (ide_floppy_get_capacity(drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 && (filp->f_flags & O_NDELAY) == 0
1159 /*
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001160 * Allow O_NDELAY to open a drive without a disk, or with an
1161 * unreadable disk, so that we can get the format capacity
1162 * of the drive or begin the format - Sam
1163 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 ret = -EIO;
1166 goto out_put_floppy;
1167 }
1168
1169 if (floppy->wp && (filp->f_mode & 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 ret = -EROFS;
1171 goto out_put_floppy;
1172 }
Borislav Petkovea68d272008-07-23 19:56:01 +02001173 drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 /* IOMEGA Clik! drives do not support lock/unlock commands */
Borislav Petkovea68d272008-07-23 19:56:01 +02001175 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 idefloppy_create_prevent_cmd(&pc, 1);
1177 (void) idefloppy_queue_pc_tail(drive, &pc);
1178 }
1179 check_disk_change(inode->i_bdev);
Borislav Petkovea68d272008-07-23 19:56:01 +02001180 } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 ret = -EBUSY;
1182 goto out_put_floppy;
1183 }
1184 return 0;
1185
1186out_put_floppy:
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001187 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 ide_floppy_put(floppy);
1189 return ret;
1190}
1191
1192static int idefloppy_release(struct inode *inode, struct file *filp)
1193{
1194 struct gendisk *disk = inode->i_bdev->bd_disk;
1195 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1196 ide_drive_t *drive = floppy->drive;
Borislav Petkov8e555122008-04-18 00:46:27 +02001197 struct ide_atapi_pc pc;
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001198
1199 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001201 if (floppy->openers == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 /* IOMEGA Clik! drives do not support lock/unlock commands */
Borislav Petkovea68d272008-07-23 19:56:01 +02001203 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 idefloppy_create_prevent_cmd(&pc, 0);
1205 (void) idefloppy_queue_pc_tail(drive, &pc);
1206 }
1207
Borislav Petkovea68d272008-07-23 19:56:01 +02001208 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 }
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001210
1211 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
1213 ide_floppy_put(floppy);
1214
1215 return 0;
1216}
1217
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08001218static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1219{
1220 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1221 ide_drive_t *drive = floppy->drive;
1222
1223 geo->heads = drive->bios_head;
1224 geo->sectors = drive->bios_sect;
1225 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
1226 return 0;
1227}
1228
Borislav Petkovea68d272008-07-23 19:56:01 +02001229static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
1230 unsigned long arg, unsigned int cmd)
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001231{
Borislav Petkovea68d272008-07-23 19:56:01 +02001232 idefloppy_floppy_t *floppy = drive->driver_data;
1233
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001234 if (floppy->openers > 1)
1235 return -EBUSY;
1236
1237 /* The IOMEGA Clik! Drive doesn't support this command -
1238 * no room for an eject mechanism */
Borislav Petkovea68d272008-07-23 19:56:01 +02001239 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001240 int prevent = arg ? 1 : 0;
1241
1242 if (cmd == CDROMEJECT)
1243 prevent = 0;
1244
1245 idefloppy_create_prevent_cmd(pc, prevent);
1246 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1247 }
1248
1249 if (cmd == CDROMEJECT) {
1250 idefloppy_create_start_stop_cmd(pc, 2);
1251 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1252 }
1253
1254 return 0;
1255}
1256
1257static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
1258 int __user *arg)
1259{
Borislav Petkov8e555122008-04-18 00:46:27 +02001260 struct ide_atapi_pc pc;
Borislav Petkovea68d272008-07-23 19:56:01 +02001261 ide_drive_t *drive = floppy->drive;
1262 int blocks, length, flags, err = 0;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001263
1264 if (floppy->openers > 1) {
1265 /* Don't format if someone is using the disk */
Borislav Petkovea68d272008-07-23 19:56:01 +02001266 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001267 return -EBUSY;
1268 }
1269
Borislav Petkovea68d272008-07-23 19:56:01 +02001270 drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001271
1272 /*
1273 * Send ATAPI_FORMAT_UNIT to the drive.
1274 *
1275 * Userland gives us the following structure:
1276 *
1277 * struct idefloppy_format_command {
1278 * int nblocks;
1279 * int blocksize;
1280 * int flags;
1281 * } ;
1282 *
1283 * flags is a bitmask, currently, the only defined flag is:
1284 *
1285 * 0x01 - verify media after format.
1286 */
1287 if (get_user(blocks, arg) ||
1288 get_user(length, arg+1) ||
1289 get_user(flags, arg+2)) {
1290 err = -EFAULT;
1291 goto out;
1292 }
1293
Borislav Petkovea68d272008-07-23 19:56:01 +02001294 (void) idefloppy_get_sfrp_bit(drive);
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001295 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1296
Borislav Petkovea68d272008-07-23 19:56:01 +02001297 if (idefloppy_queue_pc_tail(drive, &pc))
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001298 err = -EIO;
1299
1300out:
1301 if (err)
Borislav Petkovea68d272008-07-23 19:56:01 +02001302 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001303 return err;
1304}
1305
1306
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307static int idefloppy_ioctl(struct inode *inode, struct file *file,
1308 unsigned int cmd, unsigned long arg)
1309{
1310 struct block_device *bdev = inode->i_bdev;
1311 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1312 ide_drive_t *drive = floppy->drive;
Borislav Petkov8e555122008-04-18 00:46:27 +02001313 struct ide_atapi_pc pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 void __user *argp = (void __user *)arg;
Ondrej Zary07203f62005-11-10 00:25:15 +01001315 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
1317 switch (cmd) {
1318 case CDROMEJECT:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 /* fall through */
1320 case CDROM_LOCKDOOR:
Borislav Petkovea68d272008-07-23 19:56:01 +02001321 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
1323 return 0;
1324 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001325 return ide_floppy_get_format_capacities(drive, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 case IDEFLOPPY_IOCTL_FORMAT_START:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 if (!(file->f_mode & 2))
1328 return -EPERM;
1329
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001330 return ide_floppy_format_unit(floppy, (int __user *)arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1332 return idefloppy_get_format_progress(drive, argp);
1333 }
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +02001334
1335 /*
1336 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
1337 * and CDROM_SEND_PACKET (legacy) ioctls
1338 */
1339 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
1340 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
1341 bdev->bd_disk, cmd, argp);
1342 else
1343 err = -ENOTTY;
1344
1345 if (err == -ENOTTY)
1346 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
1347
1348 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349}
1350
1351static int idefloppy_media_changed(struct gendisk *disk)
1352{
1353 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1354 ide_drive_t *drive = floppy->drive;
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +01001355 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357 /* do not scan partitions twice if this is a removable device */
1358 if (drive->attach) {
1359 drive->attach = 0;
1360 return 0;
1361 }
Borislav Petkovea68d272008-07-23 19:56:01 +02001362 ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED);
1363 drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED;
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +01001364 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
1367static int idefloppy_revalidate_disk(struct gendisk *disk)
1368{
1369 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1370 set_capacity(disk, idefloppy_capacity(floppy->drive));
1371 return 0;
1372}
1373
1374static struct block_device_operations idefloppy_ops = {
Paolo Ciarrocchi52d3ccf2008-04-26 17:36:41 +02001375 .owner = THIS_MODULE,
1376 .open = idefloppy_open,
1377 .release = idefloppy_release,
1378 .ioctl = idefloppy_ioctl,
1379 .getgeo = idefloppy_getgeo,
1380 .media_changed = idefloppy_media_changed,
1381 .revalidate_disk = idefloppy_revalidate_disk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382};
1383
Russell King4031bbe2006-01-06 11:41:00 +00001384static int ide_floppy_probe(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385{
1386 idefloppy_floppy_t *floppy;
1387 struct gendisk *g;
1388
1389 if (!strstr("ide-floppy", drive->driver_req))
1390 goto failed;
1391 if (!drive->present)
1392 goto failed;
1393 if (drive->media != ide_floppy)
1394 goto failed;
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001395 if (!idefloppy_identify_device(drive, drive->id)) {
1396 printk(KERN_ERR "ide-floppy: %s: not supported by this version"
1397 " of ide-floppy\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 goto failed;
1399 }
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001400 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
1401 if (!floppy) {
1402 printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy"
1403 " structure\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 goto failed;
1405 }
1406
1407 g = alloc_disk(1 << PARTN_BITS);
1408 if (!g)
1409 goto out_free_floppy;
1410
1411 ide_init_disk(g, drive);
1412
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001413 ide_proc_register_driver(drive, &idefloppy_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 kref_init(&floppy->kref);
1416
1417 floppy->drive = drive;
1418 floppy->driver = &idefloppy_driver;
1419 floppy->disk = g;
1420
1421 g->private_data = &floppy->driver;
1422
1423 drive->driver_data = floppy;
1424
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001425 idefloppy_setup(drive, floppy);
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 g->minors = 1 << PARTN_BITS;
1428 g->driverfs_dev = &drive->gendev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
1430 g->fops = &idefloppy_ops;
1431 drive->attach = 1;
1432 add_disk(g);
1433 return 0;
1434
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435out_free_floppy:
1436 kfree(floppy);
1437failed:
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001438 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439}
1440
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001441static void __exit idefloppy_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001443 driver_unregister(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
Bartlomiej Zolnierkiewicz17514e82005-11-19 22:24:35 +01001446static int __init idefloppy_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447{
1448 printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001449 return driver_register(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450}
1451
Kay Sievers263756e2005-12-12 18:03:44 +01001452MODULE_ALIAS("ide:*m-floppy*");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453module_init(idefloppy_init);
1454module_exit(idefloppy_exit);
1455MODULE_LICENSE("GPL");
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001456MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
1457