blob: 41bb61037da2b82aa4ebe0e7e62bc5c6ed9f3e57 [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
Bartlomiej Zolnierkiewicz51509ee2008-10-10 22:39:34 +020018#define DRV_NAME "ide-floppy"
19
Borislav Petkovfc6c5bc2008-02-02 19:56:38 +010020#define IDEFLOPPY_VERSION "1.00"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
23#include <linux/types.h>
24#include <linux/string.h>
25#include <linux/kernel.h>
26#include <linux/delay.h>
27#include <linux/timer.h>
28#include <linux/mm.h>
29#include <linux/interrupt.h>
30#include <linux/major.h>
31#include <linux/errno.h>
32#include <linux/genhd.h>
33#include <linux/slab.h>
34#include <linux/cdrom.h>
35#include <linux/ide.h>
Bartlomiej Zolnierkiewicz3ceca722008-10-10 22:39:27 +020036#include <linux/hdreg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/bitops.h>
Arjan van de Vencf8b8972006-03-23 03:00:45 -080038#include <linux/mutex.h>
Borislav Petkovb98b3402008-10-10 22:39:35 +020039#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +020041#include <scsi/scsi_ioctl.h>
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/byteorder.h>
Borislav Petkov7e8b1632008-02-02 19:56:34 +010044#include <linux/irq.h>
45#include <linux/uaccess.h>
46#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/unaligned.h>
48
Borislav Petkovf373bd82008-02-02 19:56:36 +010049/* define to see debug info */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define IDEFLOPPY_DEBUG_LOG 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
Borislav Petkov0571c7a2008-02-02 19:56:38 +010053#define IDEFLOPPY_DEBUG(fmt, args...)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#if IDEFLOPPY_DEBUG_LOG
Borislav Petkovbcc77d92008-02-02 19:56:34 +010056#define debug_log(fmt, args...) \
57 printk(KERN_INFO "ide-floppy: " fmt, ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#else
Borislav Petkov0571c7a2008-02-02 19:56:38 +010059#define debug_log(fmt, args...) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#endif
61
62
Borislav Petkov0571c7a2008-02-02 19:56:38 +010063/* Some drives require a longer irq timeout. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
65
66/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +010067 * After each failed packet command we issue a request sense command and retry
68 * the packet command IDEFLOPPY_MAX_PC_RETRIES times.
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 */
70#define IDEFLOPPY_MAX_PC_RETRIES 3
71
72/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +010073 * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
74 * bytes.
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 */
76#define IDEFLOPPY_PC_BUFFER_SIZE 256
77
78/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +010079 * In various places in the driver, we need to allocate storage for packet
Bartlomiej Zolnierkiewicz394a4c22008-10-10 22:39:35 +020080 * commands, which will remain valid while we leave the driver to wait for
81 * an interrupt or a timeout event.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
83#define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
84
Borislav Petkov194ec0c2008-02-02 19:56:35 +010085/* format capacities descriptor codes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define CAPACITY_INVALID 0x00
87#define CAPACITY_UNFORMATTED 0x01
88#define CAPACITY_CURRENT 0x02
89#define CAPACITY_NO_CARTRIDGE 0x03
90
91/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +010092 * Most of our global data which we need to save even as we leave the driver
93 * due to an interrupt or a timer event is stored in a variable of type
94 * idefloppy_floppy_t, defined below.
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 */
96typedef struct ide_floppy_obj {
97 ide_drive_t *drive;
98 ide_driver_t *driver;
99 struct gendisk *disk;
100 struct kref kref;
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +0100101 unsigned int openers; /* protected by BKL for now */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 /* Current packet command */
Borislav Petkov8e555122008-04-18 00:46:27 +0200104 struct ide_atapi_pc *pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* Last failed packet command */
Borislav Petkov8e555122008-04-18 00:46:27 +0200106 struct ide_atapi_pc *failed_pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /* Packet command stack */
Borislav Petkov8e555122008-04-18 00:46:27 +0200108 struct ide_atapi_pc pc_stack[IDEFLOPPY_PC_STACK];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 /* Next free packet command storage space */
110 int pc_stack_index;
Bartlomiej Zolnierkiewicz394a4c22008-10-10 22:39:35 +0200111
112 struct request request_sense_rq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100114 /* Last error information */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 u8 sense_key, asc, ascq;
116 /* delay this long before sending packet command */
117 u8 ticks;
118 int progress_indication;
119
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100120 /* Device information */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 /* Current format */
122 int blocks, block_size, bs_factor;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100123 /* Last format capacity descriptor */
124 u8 cap_desc[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 /* Copy of the flexible disk page */
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100126 u8 flexible_disk_page[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 /* Write protect */
128 int wp;
129 /* Supports format progress report */
130 int srfp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131} idefloppy_floppy_t;
132
Bartlomiej Zolnierkiewiczc40d3d32005-08-18 22:09:21 +0200133#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100135/* Defines for the MODE SENSE command */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#define MODE_SENSE_CURRENT 0x00
137#define MODE_SENSE_CHANGEABLE 0x01
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100138#define MODE_SENSE_DEFAULT 0x02
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define MODE_SENSE_SAVED 0x03
140
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100141/* IOCTLs used in low-level formatting. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
143#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
144#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
145#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
146
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100147/* Error code returned in rq->errors to the higher part of the driver. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define IDEFLOPPY_ERROR_GENERAL 101
149
150/*
Borislav Petkov948391d2008-02-02 19:56:34 +0100151 * Pages of the SELECT SENSE / MODE SENSE packet commands.
152 * See SFF-8070i spec.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 */
154#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
155#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
156
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800157static DEFINE_MUTEX(idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
160
161#define ide_floppy_g(disk) \
162 container_of((disk)->private_data, struct ide_floppy_obj, driver)
163
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200164static void idefloppy_cleanup_obj(struct kref *);
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
167{
168 struct ide_floppy_obj *floppy = NULL;
169
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800170 mutex_lock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 floppy = ide_floppy_g(disk);
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200172 if (floppy) {
Bartlomiej Zolnierkiewiczd3e33ff2008-08-05 18:16:59 +0200173 if (ide_device_get(floppy->drive))
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200174 floppy = NULL;
Bartlomiej Zolnierkiewiczd3e33ff2008-08-05 18:16:59 +0200175 else
176 kref_get(&floppy->kref);
Bartlomiej Zolnierkiewicz08da5912008-07-24 22:53:15 +0200177 }
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800178 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 return floppy;
180}
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static void ide_floppy_put(struct ide_floppy_obj *floppy)
183{
Bartlomiej Zolnierkiewiczd3e33ff2008-08-05 18:16:59 +0200184 ide_drive_t *drive = floppy->drive;
185
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800186 mutex_lock(&idefloppy_ref_mutex);
Borislav Petkov9a24b632008-02-02 19:56:33 +0100187 kref_put(&floppy->kref, idefloppy_cleanup_obj);
Bartlomiej Zolnierkiewiczd3e33ff2008-08-05 18:16:59 +0200188 ide_device_put(drive);
Arjan van de Vencf8b8972006-03-23 03:00:45 -0800189 mutex_unlock(&idefloppy_ref_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
192/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100193 * Used to finish servicing a request. For read/write requests, we will call
194 * ide_end_request to pass to the next buffer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 */
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200196static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198 idefloppy_floppy_t *floppy = drive->driver_data;
199 struct request *rq = HWGROUP(drive)->rq;
200 int error;
201
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100202 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 switch (uptodate) {
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100205 case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
206 case 1: error = 0; break;
207 default: error = uptodate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 }
209 if (error)
210 floppy->failed_pc = NULL;
211 /* Why does this happen? */
212 if (!rq)
213 return 0;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200214 if (!blk_special_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 /* our real local end request function */
216 ide_end_request(drive, uptodate, nsecs);
217 return 0;
218 }
219 rq->errors = error;
220 /* fixme: need to move this local also */
221 ide_end_drive_cmd(drive, 0, 0);
222 return 0;
223}
224
Borislav Petkov8e555122008-04-18 00:46:27 +0200225static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
Borislav Petkov32925e12008-02-02 19:56:36 +0100226 unsigned int bcount, int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Bartlomiej Zolnierkiewicz9567b342008-04-28 23:44:36 +0200228 ide_hwif_t *hwif = drive->hwif;
Borislav Petkovb98b3402008-10-10 22:39:35 +0200229 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
230 xfer_func_t *xf = direction ? tp_ops->output_data : tp_ops->input_data;
231 struct scatterlist *sg = pc->sg;
232 char *buf;
NeilBrown5705f702007-09-25 12:35:59 +0200233 int count, done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Borislav Petkovb98b3402008-10-10 22:39:35 +0200235 while (bcount) {
236 count = min(sg->length - pc->b_count, bcount);
237 if (PageHighMem(sg_page(sg))) {
238 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Borislav Petkovb98b3402008-10-10 22:39:35 +0200240 local_irq_save(flags);
241 buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
242 xf(drive, NULL, buf + pc->b_count, count);
243 kunmap_atomic(buf - sg->offset, KM_IRQ0);
244 local_irq_restore(flags);
245 } else {
246 buf = sg_virt(sg);
247 xf(drive, NULL, buf + pc->b_count, count);
248 }
Jens Axboe6c92e692007-08-16 13:43:12 +0200249 bcount -= count;
250 pc->b_count += count;
251 done += count;
Borislav Petkovb98b3402008-10-10 22:39:35 +0200252
253 if (pc->b_count == sg->length) {
254 if (!--pc->sg_cnt)
255 break;
256 pc->sg = sg = sg_next(sg);
257 pc->b_count = 0;
258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 }
260
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200261 idefloppy_end_request(drive, 1, done >> 9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 if (bcount) {
Borislav Petkov32925e12008-02-02 19:56:36 +0100264 printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
265 drive->name, __func__, bcount);
Bartlomiej Zolnierkiewicz9f87abe2008-04-28 23:44:41 +0200266 ide_pad_transfer(drive, direction, bcount);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268}
269
Borislav Petkov8e555122008-04-18 00:46:27 +0200270static void idefloppy_update_buffers(ide_drive_t *drive,
271 struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
273 struct request *rq = pc->rq;
274 struct bio *bio = rq->bio;
275
276 while ((bio = rq->bio) != NULL)
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200277 idefloppy_end_request(drive, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
280/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100281 * Generate a new packet command request in front of the request queue, before
282 * the current request so that it will be processed immediately, on the next
283 * pass through the driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 */
Borislav Petkov8e555122008-04-18 00:46:27 +0200285static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100286 struct request *rq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct ide_floppy_obj *floppy = drive->driver_data;
289
FUJITA Tomonori124cafc2008-07-15 21:21:44 +0200290 blk_rq_init(NULL, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 rq->buffer = (char *) pc;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200292 rq->cmd_type = REQ_TYPE_SPECIAL;
Bartlomiej Zolnierkiewicze8a96aa2008-07-15 21:21:41 +0200293 rq->cmd_flags |= REQ_PREEMPT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 rq->rq_disk = floppy->disk;
Borislav Petkov20cd93be672008-07-23 19:56:00 +0200295 memcpy(rq->cmd, pc->c, 12);
FUJITA Tomonori63f5abb2008-07-15 21:21:51 +0200296 ide_do_drive_cmd(drive, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
Borislav Petkov8e555122008-04-18 00:46:27 +0200299static struct ide_atapi_pc *idefloppy_next_pc_storage(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
301 idefloppy_floppy_t *floppy = drive->driver_data;
302
303 if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100304 floppy->pc_stack_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return (&floppy->pc_stack[floppy->pc_stack_index++]);
306}
307
Borislav Petkov81f49382008-07-15 21:21:56 +0200308static void ide_floppy_callback(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov81f49382008-07-15 21:21:56 +0200311 struct ide_atapi_pc *pc = floppy->pc;
312 int uptodate = pc->error ? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100314 debug_log("Reached %s\n", __func__);
315
Bartlomiej Zolnierkiewiczdd2e9a02008-07-15 21:22:01 +0200316 if (floppy->failed_pc == pc)
317 floppy->failed_pc = NULL;
318
Borislav Petkov81f49382008-07-15 21:21:56 +0200319 if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 ||
320 (pc->rq && blk_pc_request(pc->rq)))
321 uptodate = 1; /* FIXME */
322 else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
323 u8 *buf = floppy->pc->buf;
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100324
Borislav Petkov81f49382008-07-15 21:21:56 +0200325 if (!pc->error) {
326 floppy->sense_key = buf[2] & 0x0F;
327 floppy->asc = buf[12];
328 floppy->ascq = buf[13];
329 floppy->progress_indication = buf[15] & 0x80 ?
330 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
331
332 if (floppy->failed_pc)
333 debug_log("pc = %x, ", floppy->failed_pc->c[0]);
334
Borislav Petkova6ff2d32008-02-02 19:56:34 +0100335 debug_log("sense key = %x, asc = %x, ascq = %x\n",
Borislav Petkov81f49382008-07-15 21:21:56 +0200336 floppy->sense_key, floppy->asc, floppy->ascq);
337 } else
338 printk(KERN_ERR "Error in REQUEST SENSE itself - "
339 "Aborting request!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Borislav Petkov81f49382008-07-15 21:21:56 +0200342 idefloppy_end_request(drive, uptodate, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
Borislav Petkov8e555122008-04-18 00:46:27 +0200345static void idefloppy_init_pc(struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Borislav Petkov68dc3572008-07-16 20:33:47 +0200347 memset(pc, 0, sizeof(*pc));
Borislav Petkov8e555122008-04-18 00:46:27 +0200348 pc->buf = pc->pc_buf;
349 pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Borislav Petkov8e555122008-04-18 00:46:27 +0200352static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Borislav Petkov30d67092008-02-02 19:56:33 +0100354 idefloppy_init_pc(pc);
355 pc->c[0] = GPCMD_REQUEST_SENSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 pc->c[4] = 255;
Borislav Petkov8e555122008-04-18 00:46:27 +0200357 pc->req_xfer = 18;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
360/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100361 * Called when an error was detected during the last packet command. We queue a
362 * request sense packet command in the head of the request list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 */
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100364static void idefloppy_retry_pc(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
Bartlomiej Zolnierkiewicz394a4c22008-10-10 22:39:35 +0200366 struct ide_floppy_obj *floppy = drive->driver_data;
367 struct request *rq = &floppy->request_sense_rq;
Borislav Petkov8e555122008-04-18 00:46:27 +0200368 struct ide_atapi_pc *pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Bartlomiej Zolnierkiewicz64a57fe2008-02-06 02:57:51 +0100370 (void)ide_read_error(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 pc = idefloppy_next_pc_storage(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 idefloppy_create_request_sense_cmd(pc);
373 idefloppy_queue_pc_head(drive, pc, rq);
374}
375
Borislav Petkov0eea6452008-02-02 19:56:36 +0100376/* The usual interrupt handler called during a packet command. */
Paolo Ciarrocchi52d3ccf2008-04-26 17:36:41 +0200377static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 idefloppy_floppy_t *floppy = drive->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Bartlomiej Zolnierkiewicz646c0cb2008-07-15 21:22:03 +0200381 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
382 IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers,
383 idefloppy_retry_pc, NULL, ide_floppy_io_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
386/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100387 * What we have here is a classic case of a top half / bottom half interrupt
388 * service routine. In interrupt mode, the device sends an interrupt to signal
389 * that it is ready to receive a packet. However, we need to delay about 2-3
390 * ticks before issuing the packet or we gets in trouble.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 */
Borislav Petkovcbbc4e82008-07-15 21:22:03 +0200392static int idefloppy_transfer_pc(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
394 idefloppy_floppy_t *floppy = drive->driver_data;
395
396 /* Send the actual packet */
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200397 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
Bartlomiej Zolnierkiewicz9567b342008-04-28 23:44:36 +0200398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 /* Timeout for the packet command */
400 return IDEFLOPPY_WAIT_CMD;
401}
402
Borislav Petkovcbbc4e82008-07-15 21:22:03 +0200403
404/*
405 * Called as an interrupt (or directly). When the device says it's ready for a
406 * packet, we schedule the packet transfer to occur about 2-3 ticks later in
407 * transfer_pc.
408 */
409static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
411 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz6ffb66412008-07-15 21:21:56 +0200412 struct ide_atapi_pc *pc = floppy->pc;
Bartlomiej Zolnierkiewicz0b2eea42008-07-15 21:21:54 +0200413 ide_expiry_t *expiry;
414 unsigned int timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100416 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 * The following delay solves a problem with ATAPI Zip 100 drives
418 * where the Busy flag was apparently being deasserted before the
419 * unit was ready to receive data. This was happening on a
420 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
421 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
422 * used until after the packet is moved in about 50 msec.
423 */
Borislav Petkovea68d272008-07-23 19:56:01 +0200424 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
Bartlomiej Zolnierkiewicz0b2eea42008-07-15 21:21:54 +0200425 timeout = floppy->ticks;
Borislav Petkovcbbc4e82008-07-15 21:22:03 +0200426 expiry = &idefloppy_transfer_pc;
Bartlomiej Zolnierkiewicz0b2eea42008-07-15 21:21:54 +0200427 } else {
428 timeout = IDEFLOPPY_WAIT_CMD;
429 expiry = NULL;
430 }
Borislav Petkov0078df22008-02-02 19:56:33 +0100431
Bartlomiej Zolnierkiewicz594c16d2008-07-15 21:21:58 +0200432 return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
Borislav Petkovd652c132008-02-02 19:56:35 +0100435static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
Borislav Petkov8e555122008-04-18 00:46:27 +0200436 struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Borislav Petkovd652c132008-02-02 19:56:35 +0100438 /* supress error messages resulting from Medium not present */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (floppy->sense_key == 0x02 &&
440 floppy->asc == 0x3a &&
441 floppy->ascq == 0x00)
Borislav Petkovd652c132008-02-02 19:56:35 +0100442 return;
443
444 printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, "
445 "asc = %2x, ascq = %2x\n",
446 floppy->drive->name, pc->c[0], floppy->sense_key,
447 floppy->asc, floppy->ascq);
448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449}
450
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100451static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
Borislav Petkov8e555122008-04-18 00:46:27 +0200452 struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
454 idefloppy_floppy_t *floppy = drive->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 if (floppy->failed_pc == NULL &&
Borislav Petkov30d67092008-02-02 19:56:33 +0100457 pc->c[0] != GPCMD_REQUEST_SENSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 floppy->failed_pc = pc;
459 /* Set the current packet command */
460 floppy->pc = pc;
461
Borislav Petkov757ced82008-02-02 19:56:37 +0100462 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100463 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
Borislav Petkov757ced82008-02-02 19:56:37 +0100464 ide_floppy_report_error(floppy, pc);
465 /* Giving up */
466 pc->error = IDEFLOPPY_ERROR_GENERAL;
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 floppy->failed_pc = NULL;
Borislav Petkov2207fa52008-07-23 19:55:59 +0200469 drive->pc_callback(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return ide_stopped;
471 }
472
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100473 debug_log("Retry number - %d\n", pc->retries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 pc->retries++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Borislav Petkovcbbc4e82008-07-15 21:22:03 +0200477 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer,
Bartlomiej Zolnierkiewicz6bf16412008-07-15 21:22:00 +0200478 IDEFLOPPY_WAIT_CMD, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
Borislav Petkov8e555122008-04-18 00:46:27 +0200481static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
Borislav Petkovbcc77d92008-02-02 19:56:34 +0100483 debug_log("creating prevent removal command, prevent = %d\n", prevent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100486 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 pc->c[4] = prevent;
488}
489
Borislav Petkov8e555122008-04-18 00:46:27 +0200490static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100493 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 pc->c[7] = 255;
495 pc->c[8] = 255;
Borislav Petkov8e555122008-04-18 00:46:27 +0200496 pc->req_xfer = 255;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
Borislav Petkov8e555122008-04-18 00:46:27 +0200499static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
500 int l, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100503 pc->c[0] = GPCMD_FORMAT_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 pc->c[1] = 0x17;
505
Borislav Petkov8e555122008-04-18 00:46:27 +0200506 memset(pc->buf, 0, 12);
507 pc->buf[1] = 0xA2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
509
510 if (flags & 1) /* Verify bit on... */
Borislav Petkov8e555122008-04-18 00:46:27 +0200511 pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */
512 pc->buf[3] = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Borislav Petkov8e555122008-04-18 00:46:27 +0200514 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4]));
515 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8]));
516 pc->buf_size = 12;
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100517 pc->flags |= PC_FLAG_WRITING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518}
519
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100520/* A mode sense command is used to "sense" floppy parameters. */
Borislav Petkov8e555122008-04-18 00:46:27 +0200521static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
522 u8 page_code, u8 type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
Borislav Petkov24a5d702008-02-02 19:56:34 +0100524 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100527 pc->c[0] = GPCMD_MODE_SENSE_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 pc->c[1] = 0;
529 pc->c[2] = page_code + (type << 6);
530
531 switch (page_code) {
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100532 case IDEFLOPPY_CAPABILITIES_PAGE:
533 length += 12;
534 break;
535 case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
536 length += 32;
537 break;
538 default:
539 printk(KERN_ERR "ide-floppy: unsupported page code "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 "in create_mode_sense_cmd\n");
541 }
Borislav Petkov8f622432008-02-02 19:56:33 +0100542 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
Borislav Petkov8e555122008-04-18 00:46:27 +0200543 pc->req_xfer = length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544}
545
Borislav Petkov8e555122008-04-18 00:46:27 +0200546static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547{
548 idefloppy_init_pc(pc);
Borislav Petkov30d67092008-02-02 19:56:33 +0100549 pc->c[0] = GPCMD_START_STOP_UNIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 pc->c[4] = start;
551}
552
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100553static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
Borislav Petkov8e555122008-04-18 00:46:27 +0200554 struct ide_atapi_pc *pc, struct request *rq,
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100555 unsigned long sector)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
557 int block = sector / floppy->bs_factor;
558 int blocks = rq->nr_sectors / floppy->bs_factor;
559 int cmd = rq_data_dir(rq);
560
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100561 debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 block, blocks);
563
564 idefloppy_init_pc(pc);
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100565 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
566 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
Borislav Petkov8f622432008-02-02 19:56:33 +0100567 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
Borislav Petkovae7e8dd2008-02-02 19:56:36 +0100568
Borislav Petkov20cd93be672008-07-23 19:56:00 +0200569 memcpy(rq->cmd, pc->c, 12);
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 pc->rq = rq;
Borislav Petkovb98b3402008-10-10 22:39:35 +0200572 pc->b_count = 0;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200573 if (rq->cmd_flags & REQ_RW)
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100574 pc->flags |= PC_FLAG_WRITING;
Borislav Petkov8e555122008-04-18 00:46:27 +0200575 pc->buf = NULL;
576 pc->req_xfer = pc->buf_size = blocks * floppy->block_size;
Bartlomiej Zolnierkiewicz5e331092008-07-15 21:21:56 +0200577 pc->flags |= PC_FLAG_DMA_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578}
579
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100580static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
Borislav Petkov8e555122008-04-18 00:46:27 +0200581 struct ide_atapi_pc *pc, struct request *rq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 idefloppy_init_pc(pc);
584 memcpy(pc->c, rq->cmd, sizeof(pc->c));
Jens Axboe3d6392c2007-07-09 12:38:05 +0200585 pc->rq = rq;
Borislav Petkovb98b3402008-10-10 22:39:35 +0200586 pc->b_count = 0;
Jens Axboe3d6392c2007-07-09 12:38:05 +0200587 if (rq->data_len && rq_data_dir(rq) == WRITE)
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100588 pc->flags |= PC_FLAG_WRITING;
Borislav Petkov8e555122008-04-18 00:46:27 +0200589 pc->buf = rq->data;
Jens Axboe3d6392c2007-07-09 12:38:05 +0200590 if (rq->bio)
Bartlomiej Zolnierkiewicz5e331092008-07-15 21:21:56 +0200591 pc->flags |= PC_FLAG_DMA_OK;
Jens Axboe3d6392c2007-07-09 12:38:05 +0200592 /*
593 * possibly problematic, doesn't look like ide-floppy correctly
594 * handled scattered requests if dma fails...
595 */
Borislav Petkov8e555122008-04-18 00:46:27 +0200596 pc->req_xfer = pc->buf_size = rq->data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100599static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
600 struct request *rq, sector_t block_s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
602 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkovb98b3402008-10-10 22:39:35 +0200603 ide_hwif_t *hwif = drive->hwif;
Borislav Petkov8e555122008-04-18 00:46:27 +0200604 struct ide_atapi_pc *pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 unsigned long block = (unsigned long)block_s;
606
Borislav Petkovb98b3402008-10-10 22:39:35 +0200607 debug_log("%s: dev: %s, cmd: 0x%x, cmd_type: %x, errors: %d\n",
608 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
609 rq->cmd[0], rq->cmd_type, rq->errors);
610
611 debug_log("%s: sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",
612 __func__, (long)rq->sector, rq->nr_sectors,
613 rq->current_nr_sectors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 if (rq->errors >= ERROR_MAX) {
Borislav Petkovd652c132008-02-02 19:56:35 +0100616 if (floppy->failed_pc)
617 ide_floppy_report_error(floppy, floppy->failed_pc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 else
619 printk(KERN_ERR "ide-floppy: %s: I/O error\n",
620 drive->name);
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200621 idefloppy_end_request(drive, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 return ide_stopped;
623 }
Jens Axboe4aff5e22006-08-10 08:44:47 +0200624 if (blk_fs_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 if (((long)rq->sector % floppy->bs_factor) ||
626 (rq->nr_sectors % floppy->bs_factor)) {
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100627 printk(KERN_ERR "%s: unsupported r/w request size\n",
628 drive->name);
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200629 idefloppy_end_request(drive, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return ide_stopped;
631 }
632 pc = idefloppy_next_pc_storage(drive);
633 idefloppy_create_rw_cmd(floppy, pc, rq, block);
Jens Axboe4aff5e22006-08-10 08:44:47 +0200634 } else if (blk_special_request(rq)) {
Borislav Petkov8e555122008-04-18 00:46:27 +0200635 pc = (struct ide_atapi_pc *) rq->buffer;
Jens Axboe4aff5e22006-08-10 08:44:47 +0200636 } else if (blk_pc_request(rq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 pc = idefloppy_next_pc_storage(drive);
Jens Axboe3d6392c2007-07-09 12:38:05 +0200638 idefloppy_blockpc_cmd(floppy, pc, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 } else {
640 blk_dump_rq_flags(rq,
641 "ide-floppy: unsupported command in queue");
Borislav Petkovc2b2b292008-04-18 00:46:27 +0200642 idefloppy_end_request(drive, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return ide_stopped;
644 }
645
Borislav Petkovb98b3402008-10-10 22:39:35 +0200646 ide_init_sg_cmd(drive, rq);
647 ide_map_sg(drive, rq);
648
649 pc->sg = hwif->sg_table;
650 pc->sg_cnt = hwif->sg_nents;
651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 pc->rq = rq;
Bartlomiej Zolnierkiewicz5d418932008-07-15 21:21:57 +0200653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return idefloppy_issue_pc(drive, pc);
655}
656
657/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100658 * Add a special packet command request to the tail of the request queue,
659 * and wait for it to be serviced.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 */
Borislav Petkov8e555122008-04-18 00:46:27 +0200661static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
663 struct ide_floppy_obj *floppy = drive->driver_data;
FUJITA Tomonori6fe16232008-07-15 21:21:43 +0200664 struct request *rq;
665 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
FUJITA Tomonori6fe16232008-07-15 21:21:43 +0200667 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
668 rq->buffer = (char *) pc;
669 rq->cmd_type = REQ_TYPE_SPECIAL;
Borislav Petkov20cd93be672008-07-23 19:56:00 +0200670 memcpy(rq->cmd, pc->c, 12);
FUJITA Tomonori6fe16232008-07-15 21:21:43 +0200671 error = blk_execute_rq(drive->queue, floppy->disk, rq, 0);
672 blk_put_request(rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
FUJITA Tomonori6fe16232008-07-15 21:21:43 +0200674 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675}
676
677/*
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100678 * Look at the flexible disk page parameters. We ignore the CHS capacity
679 * parameters and use the LBA parameters instead.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 */
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100681static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
683 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200684 struct ide_atapi_pc pc;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100685 u8 *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 int capacity, lba_capacity;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100687 u16 transfer_rate, sector_size, cyls, rpm;
688 u8 heads, sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100690 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE,
691 MODE_SENSE_CURRENT);
692
693 if (idefloppy_queue_pc_tail(drive, &pc)) {
694 printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
695 " parameters\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 return 1;
697 }
Borislav Petkov8e555122008-04-18 00:46:27 +0200698 floppy->wp = !!(pc.buf[3] & 0x80);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 set_disk_ro(floppy->disk, floppy->wp);
Borislav Petkov8e555122008-04-18 00:46:27 +0200700 page = &pc.buf[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Harvey Harrison85ae98a32008-07-16 20:33:47 +0200702 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]);
703 sector_size = be16_to_cpup((__be16 *)&pc.buf[8 + 6]);
704 cyls = be16_to_cpup((__be16 *)&pc.buf[8 + 8]);
705 rpm = be16_to_cpup((__be16 *)&pc.buf[8 + 28]);
Borislav Petkov8e555122008-04-18 00:46:27 +0200706 heads = pc.buf[8 + 4];
707 sectors = pc.buf[8 + 5];
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100708
709 capacity = cyls * heads * sectors * sector_size;
710
711 if (memcmp(page, &floppy->flexible_disk_page, 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
713 "%d sector size, %d rpm\n",
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100714 drive->name, capacity / 1024, cyls, heads,
715 sectors, transfer_rate / 8, sector_size, rpm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100717 memcpy(&floppy->flexible_disk_page, page, 32);
718 drive->bios_cyl = cyls;
719 drive->bios_head = heads;
720 drive->bios_sect = sectors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 lba_capacity = floppy->blocks * floppy->block_size;
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100722
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 if (capacity < lba_capacity) {
724 printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
725 "bytes, but the drive only handles %d\n",
726 drive->name, lba_capacity, capacity);
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100727 floppy->blocks = floppy->block_size ?
728 capacity / floppy->block_size : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 }
730 return 0;
731}
732
Borislav Petkov948391d2008-02-02 19:56:34 +0100733static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734{
735 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200736 struct ide_atapi_pc pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 floppy->srfp = 0;
739 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
740 MODE_SENSE_CURRENT);
741
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +0100742 pc.flags |= PC_FLAG_SUPPRESS_ERROR;
Borislav Petkov948391d2008-02-02 19:56:34 +0100743 if (idefloppy_queue_pc_tail(drive, &pc))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Borislav Petkov8e555122008-04-18 00:46:27 +0200746 floppy->srfp = pc.buf[8 + 2] & 0x40;
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200747 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}
749
750/*
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100751 * Determine if a media is present in the floppy drive, and if so, its LBA
752 * capacity.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 */
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100754static int ide_floppy_get_capacity(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
756 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200757 struct ide_atapi_pc pc;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100758 u8 *cap_desc;
759 u8 header_len, desc_cnt;
760 int i, rc = 1, blocks, length;
761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 drive->bios_cyl = 0;
763 drive->bios_head = drive->bios_sect = 0;
Alan Coxfdb77da2007-02-17 02:40:20 +0100764 floppy->blocks = 0;
765 floppy->bs_factor = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 set_capacity(floppy->disk, 0);
767
768 idefloppy_create_read_capacity_cmd(&pc);
769 if (idefloppy_queue_pc_tail(drive, &pc)) {
770 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
771 return 1;
772 }
Borislav Petkov8e555122008-04-18 00:46:27 +0200773 header_len = pc.buf[3];
774 cap_desc = &pc.buf[4];
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100775 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100777 for (i = 0; i < desc_cnt; i++) {
778 unsigned int desc_start = 4 + i*8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Harvey Harrison85ae98a32008-07-16 20:33:47 +0200780 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
781 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100782
783 debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
784 i, blocks * length / 1024, blocks, length);
785
786 if (i)
787 continue;
788 /*
789 * the code below is valid only for the 1st descriptor, ie i=0
790 */
791
Borislav Petkov8e555122008-04-18 00:46:27 +0200792 switch (pc.buf[desc_start + 4] & 0x03) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 /* Clik! drive returns this instead of CAPACITY_CURRENT */
794 case CAPACITY_UNFORMATTED:
Borislav Petkovea68d272008-07-23 19:56:01 +0200795 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100796 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 * If it is not a clik drive, break out
798 * (maintains previous driver behaviour)
799 */
800 break;
801 case CAPACITY_CURRENT:
802 /* Normal Zip/LS-120 disks */
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100803 if (memcmp(cap_desc, &floppy->cap_desc, 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 printk(KERN_INFO "%s: %dkB, %d blocks, %d "
805 "sector size\n", drive->name,
806 blocks * length / 1024, blocks, length);
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100807 memcpy(&floppy->cap_desc, cap_desc, 8);
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 if (!length || length % 512) {
810 printk(KERN_NOTICE "%s: %d bytes block size "
811 "not supported\n", drive->name, length);
812 } else {
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100813 floppy->blocks = blocks;
814 floppy->block_size = length;
815 floppy->bs_factor = length / 512;
816 if (floppy->bs_factor != 1)
817 printk(KERN_NOTICE "%s: warning: non "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 "512 bytes block size not "
819 "fully supported\n",
820 drive->name);
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100821 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 }
823 break;
824 case CAPACITY_NO_CARTRIDGE:
825 /*
826 * This is a KERN_ERR so it appears on screen
827 * for the user to see
828 */
829 printk(KERN_ERR "%s: No disk in drive\n", drive->name);
830 break;
831 case CAPACITY_INVALID:
832 printk(KERN_ERR "%s: Invalid capacity for disk "
833 "in drive\n", drive->name);
834 break;
835 }
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100836 debug_log("Descriptor 0 Code: %d\n",
Borislav Petkov8e555122008-04-18 00:46:27 +0200837 pc.buf[desc_start + 4] & 0x03);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 }
839
840 /* Clik! disk does not support get_flexible_disk_page */
Borislav Petkovea68d272008-07-23 19:56:01 +0200841 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
Borislav Petkov8e81bbb2008-02-02 19:56:35 +0100842 (void) ide_floppy_get_flexible_disk_page(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
844 set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
845 return rc;
846}
847
848/*
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100849 * Obtain the list of formattable capacities.
850 * Very similar to ide_floppy_get_capacity, except that we push the capacity
851 * descriptors to userland, instead of our own structures.
852 *
853 * Userland gives us the following structure:
854 *
855 * struct idefloppy_format_capacities {
856 * int nformats;
857 * struct {
858 * int nblocks;
859 * int blocksize;
860 * } formats[];
861 * };
862 *
863 * userland initializes nformats to the number of allocated formats[] records.
864 * On exit we set nformats to the number of records we've actually initialized.
865 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100867static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
Borislav Petkov8e555122008-04-18 00:46:27 +0200869 struct ide_atapi_pc pc;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100870 u8 header_len, desc_cnt;
871 int i, blocks, length, u_array_size, u_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 int __user *argp;
873
874 if (get_user(u_array_size, arg))
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200875 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 if (u_array_size <= 0)
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200878 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 idefloppy_create_read_capacity_cmd(&pc);
881 if (idefloppy_queue_pc_tail(drive, &pc)) {
882 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200883 return -EIO;
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100884 }
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200885
Borislav Petkov8e555122008-04-18 00:46:27 +0200886 header_len = pc.buf[3];
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100887 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889 u_index = 0;
890 argp = arg + 1;
891
892 /*
Borislav Petkov194ec0c2008-02-02 19:56:35 +0100893 * We always skip the first capacity descriptor. That's the current
894 * capacity. We are interested in the remaining descriptors, the
895 * formattable capacities.
896 */
897 for (i = 1; i < desc_cnt; i++) {
898 unsigned int desc_start = 4 + i*8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 if (u_index >= u_array_size)
901 break; /* User-supplied buffer too small */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Harvey Harrison85ae98a32008-07-16 20:33:47 +0200903 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
904 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 if (put_user(blocks, argp))
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200907 return -EFAULT;
908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 ++argp;
910
911 if (put_user(length, argp))
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200912 return -EFAULT;
913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 ++argp;
915
916 ++u_index;
917 }
918
919 if (put_user(u_index, arg))
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200920 return -EFAULT;
921
922 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923}
924
925/*
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100926 * Get ATAPI_FORMAT_UNIT progress indication.
927 *
928 * Userland gives a pointer to an int. The int is set to a progress
929 * indicator 0-65536, with 65536=100%.
930 *
931 * If the drive does not support format progress indication, we just check
932 * the dsc bit, and return either 0 or 65536.
933 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Bartlomiej Zolnierkiewiczd56c99e2008-10-10 22:39:34 +0200935static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936{
937 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +0200938 struct ide_atapi_pc pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 int progress_indication = 0x10000;
940
941 if (floppy->srfp) {
942 idefloppy_create_request_sense_cmd(&pc);
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100943 if (idefloppy_queue_pc_tail(drive, &pc))
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200944 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 if (floppy->sense_key == 2 &&
947 floppy->asc == 4 &&
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100948 floppy->ascq == 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 progress_indication = floppy->progress_indication;
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100950
951 /* Else assume format_unit has finished, and we're at 0x10000 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 } else {
Bartlomiej Zolnierkiewiczb73c7ee2008-07-23 19:55:52 +0200953 ide_hwif_t *hwif = drive->hwif;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 unsigned long flags;
Bartlomiej Zolnierkiewicz22c525b2008-01-25 22:17:11 +0100955 u8 stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 local_irq_save(flags);
Bartlomiej Zolnierkiewicz374e0422008-07-23 19:55:56 +0200958 stat = hwif->tp_ops->read_status(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 local_irq_restore(flags);
960
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200961 progress_indication = ((stat & ATA_DSC) == 0) ? 0 : 0x10000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Bartlomiej Zolnierkiewicze3faa242008-10-10 22:39:34 +0200964 if (put_user(progress_indication, arg))
965 return -EFAULT;
966
967 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968}
969
Borislav Petkov0571c7a2008-02-02 19:56:38 +0100970static sector_t idefloppy_capacity(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
972 idefloppy_floppy_t *floppy = drive->driver_data;
973 unsigned long capacity = floppy->blocks * floppy->bs_factor;
974
975 return capacity;
976}
977
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +0200978#ifdef CONFIG_IDE_PROC_FS
Bartlomiej Zolnierkiewicz8185d5a2008-10-10 22:39:28 +0200979ide_devset_rw(bios_cyl, 0, 1023, bios_cyl);
980ide_devset_rw(bios_head, 0, 255, bios_head);
981ide_devset_rw(bios_sect, 0, 63, bios_sect);
982
983static int get_ticks(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984{
985 idefloppy_floppy_t *floppy = drive->driver_data;
Bartlomiej Zolnierkiewicz8185d5a2008-10-10 22:39:28 +0200986 return floppy->ticks;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987}
Bartlomiej Zolnierkiewicz8185d5a2008-10-10 22:39:28 +0200988
989static int set_ticks(ide_drive_t *drive, int arg)
990{
991 idefloppy_floppy_t *floppy = drive->driver_data;
992 floppy->ticks = arg;
993 return 0;
994}
995
996IDE_DEVSET(ticks, S_RW, 0, 255, get_ticks, set_ticks);
997
998static const struct ide_devset *idefloppy_settings[] = {
999 &ide_devset_bios_cyl,
1000 &ide_devset_bios_head,
1001 &ide_devset_bios_sect,
1002 &ide_devset_ticks,
1003 NULL
1004};
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001005#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001007static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008{
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +02001009 u16 *id = drive->id;
Borislav Petkov3ad67762008-04-18 00:46:25 +02001010 u8 gcw[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +02001012 *((u16 *)&gcw) = id[ATA_ID_CONFIG];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 floppy->pc = floppy->pc_stack;
Borislav Petkov2207fa52008-07-23 19:55:59 +02001014 drive->pc_callback = ide_floppy_callback;
Borislav Petkov3ad67762008-04-18 00:46:25 +02001015
1016 if (((gcw[0] & 0x60) >> 5) == 1)
Borislav Petkovea68d272008-07-23 19:56:01 +02001017 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 /*
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001019 * We used to check revisions here. At this point however I'm giving up.
1020 * Just assume they are all broken, its easier.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 *
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001022 * The actual reason for the workarounds was likely a driver bug after
1023 * all rather than a firmware bug, and the workaround below used to hide
1024 * it. It should be fixed as of version 1.9, but to be on the safe side
1025 * we'll leave the limitation below for the 2.2.x tree.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 */
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +02001027 if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) {
Borislav Petkovea68d272008-07-23 19:56:01 +02001028 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 /* This value will be visible in the /proc/ide/hdx/settings */
1030 floppy->ticks = IDEFLOPPY_TICKS_DELAY;
1031 blk_queue_max_sectors(drive->queue, 64);
1032 }
1033
1034 /*
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001035 * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes
1036 * nasty clicking noises without it, so please don't remove this.
1037 */
Bartlomiej Zolnierkiewicz4dde4492008-10-10 22:39:19 +02001038 if (strncmp((char *)&id[ATA_ID_PROD], "IOMEGA Clik!", 11) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 blk_queue_max_sectors(drive->queue, 64);
Borislav Petkovea68d272008-07-23 19:56:01 +02001040 drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001043 (void) ide_floppy_get_capacity(drive);
Bartlomiej Zolnierkiewicz1e874f42008-10-10 22:39:27 +02001044
1045 ide_proc_register_driver(drive, floppy->driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046}
1047
Russell King4031bbe2006-01-06 11:41:00 +00001048static void ide_floppy_remove(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049{
1050 idefloppy_floppy_t *floppy = drive->driver_data;
1051 struct gendisk *g = floppy->disk;
1052
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001053 ide_proc_unregister_driver(drive, floppy->driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 del_gendisk(g);
1056
1057 ide_floppy_put(floppy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058}
1059
Borislav Petkov9a24b632008-02-02 19:56:33 +01001060static void idefloppy_cleanup_obj(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 struct ide_floppy_obj *floppy = to_ide_floppy(kref);
1063 ide_drive_t *drive = floppy->drive;
1064 struct gendisk *g = floppy->disk;
1065
1066 drive->driver_data = NULL;
1067 g->private_data = NULL;
1068 put_disk(g);
1069 kfree(floppy);
1070}
1071
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001072#ifdef CONFIG_IDE_PROC_FS
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001073static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
1074 int count, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075{
1076 ide_drive_t*drive = (ide_drive_t *)data;
1077 int len;
1078
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001079 len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive));
1080 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081}
1082
1083static ide_proc_entry_t idefloppy_proc[] = {
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001084 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
1085 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 { NULL, 0, NULL, NULL }
1087};
Bartlomiej Zolnierkiewiczecfd80e2007-05-10 00:01:09 +02001088#endif /* CONFIG_IDE_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Russell King4031bbe2006-01-06 11:41:00 +00001090static int ide_floppy_probe(ide_drive_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092static ide_driver_t idefloppy_driver = {
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001093 .gen_driver = {
Laurent Riffard4ef3b8f2005-11-18 22:15:40 +01001094 .owner = THIS_MODULE,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001095 .name = "ide-floppy",
1096 .bus = &ide_bus_type,
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001097 },
Russell King4031bbe2006-01-06 11:41:00 +00001098 .probe = ide_floppy_probe,
1099 .remove = ide_floppy_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 .version = IDEFLOPPY_VERSION,
1101 .media = ide_floppy,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 .do_request = idefloppy_do_request,
Borislav Petkovc2b2b292008-04-18 00:46:27 +02001103 .end_request = idefloppy_end_request,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 .error = __ide_error,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001105#ifdef CONFIG_IDE_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 .proc = idefloppy_proc,
Bartlomiej Zolnierkiewicz8185d5a2008-10-10 22:39:28 +02001107 .settings = idefloppy_settings,
Bartlomiej Zolnierkiewicz7662d042007-05-10 00:01:10 +02001108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109};
1110
1111static int idefloppy_open(struct inode *inode, struct file *filp)
1112{
1113 struct gendisk *disk = inode->i_bdev->bd_disk;
1114 struct ide_floppy_obj *floppy;
1115 ide_drive_t *drive;
Borislav Petkov8e555122008-04-18 00:46:27 +02001116 struct ide_atapi_pc pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 int ret = 0;
1118
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001119 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001121 floppy = ide_floppy_get(disk);
1122 if (!floppy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 return -ENXIO;
1124
1125 drive = floppy->drive;
1126
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001127 floppy->openers++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001129 if (floppy->openers == 1) {
Borislav Petkovea68d272008-07-23 19:56:01 +02001130 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 /* Just in case */
1132
Borislav Petkovc96a7df2008-07-16 20:33:46 +02001133 idefloppy_init_pc(&pc);
1134 pc.c[0] = GPCMD_TEST_UNIT_READY;
1135
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 if (idefloppy_queue_pc_tail(drive, &pc)) {
1137 idefloppy_create_start_stop_cmd(&pc, 1);
1138 (void) idefloppy_queue_pc_tail(drive, &pc);
1139 }
1140
Borislav Petkov194ec0c2008-02-02 19:56:35 +01001141 if (ide_floppy_get_capacity(drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 && (filp->f_flags & O_NDELAY) == 0
1143 /*
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001144 * Allow O_NDELAY to open a drive without a disk, or with an
1145 * unreadable disk, so that we can get the format capacity
1146 * of the drive or begin the format - Sam
1147 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 ret = -EIO;
1150 goto out_put_floppy;
1151 }
1152
1153 if (floppy->wp && (filp->f_mode & 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 ret = -EROFS;
1155 goto out_put_floppy;
1156 }
Borislav Petkovea68d272008-07-23 19:56:01 +02001157 drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 /* IOMEGA Clik! drives do not support lock/unlock commands */
Borislav Petkovea68d272008-07-23 19:56:01 +02001159 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 idefloppy_create_prevent_cmd(&pc, 1);
1161 (void) idefloppy_queue_pc_tail(drive, &pc);
1162 }
1163 check_disk_change(inode->i_bdev);
Borislav Petkovea68d272008-07-23 19:56:01 +02001164 } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 ret = -EBUSY;
1166 goto out_put_floppy;
1167 }
1168 return 0;
1169
1170out_put_floppy:
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001171 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 ide_floppy_put(floppy);
1173 return ret;
1174}
1175
1176static int idefloppy_release(struct inode *inode, struct file *filp)
1177{
1178 struct gendisk *disk = inode->i_bdev->bd_disk;
1179 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1180 ide_drive_t *drive = floppy->drive;
Borislav Petkov8e555122008-04-18 00:46:27 +02001181 struct ide_atapi_pc pc;
Borislav Petkovbcc77d92008-02-02 19:56:34 +01001182
1183 debug_log("Reached %s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001185 if (floppy->openers == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 /* IOMEGA Clik! drives do not support lock/unlock commands */
Borislav Petkovea68d272008-07-23 19:56:01 +02001187 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 idefloppy_create_prevent_cmd(&pc, 0);
1189 (void) idefloppy_queue_pc_tail(drive, &pc);
1190 }
1191
Borislav Petkovea68d272008-07-23 19:56:01 +02001192 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 }
Bartlomiej Zolnierkiewiczc94964a2007-02-17 02:40:24 +01001194
1195 floppy->openers--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
1197 ide_floppy_put(floppy);
1198
1199 return 0;
1200}
1201
Christoph Hellwiga885c8c2006-01-08 01:02:50 -08001202static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1203{
1204 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1205 ide_drive_t *drive = floppy->drive;
1206
1207 geo->heads = drive->bios_head;
1208 geo->sectors = drive->bios_sect;
1209 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
1210 return 0;
1211}
1212
Borislav Petkovea68d272008-07-23 19:56:01 +02001213static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
1214 unsigned long arg, unsigned int cmd)
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001215{
Borislav Petkovea68d272008-07-23 19:56:01 +02001216 idefloppy_floppy_t *floppy = drive->driver_data;
1217
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001218 if (floppy->openers > 1)
1219 return -EBUSY;
1220
1221 /* The IOMEGA Clik! Drive doesn't support this command -
1222 * no room for an eject mechanism */
Borislav Petkovea68d272008-07-23 19:56:01 +02001223 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001224 int prevent = arg ? 1 : 0;
1225
1226 if (cmd == CDROMEJECT)
1227 prevent = 0;
1228
1229 idefloppy_create_prevent_cmd(pc, prevent);
1230 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1231 }
1232
1233 if (cmd == CDROMEJECT) {
1234 idefloppy_create_start_stop_cmd(pc, 2);
1235 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1236 }
1237
1238 return 0;
1239}
1240
Bartlomiej Zolnierkiewiczd56c99e2008-10-10 22:39:34 +02001241static int ide_floppy_format_unit(ide_drive_t *drive, int __user *arg)
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001242{
Bartlomiej Zolnierkiewiczd56c99e2008-10-10 22:39:34 +02001243 idefloppy_floppy_t *floppy = drive->driver_data;
Borislav Petkov8e555122008-04-18 00:46:27 +02001244 struct ide_atapi_pc pc;
Borislav Petkovea68d272008-07-23 19:56:01 +02001245 int blocks, length, flags, err = 0;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001246
1247 if (floppy->openers > 1) {
1248 /* Don't format if someone is using the disk */
Borislav Petkovea68d272008-07-23 19:56:01 +02001249 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001250 return -EBUSY;
1251 }
1252
Borislav Petkovea68d272008-07-23 19:56:01 +02001253 drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001254
1255 /*
1256 * Send ATAPI_FORMAT_UNIT to the drive.
1257 *
1258 * Userland gives us the following structure:
1259 *
1260 * struct idefloppy_format_command {
1261 * int nblocks;
1262 * int blocksize;
1263 * int flags;
1264 * } ;
1265 *
1266 * flags is a bitmask, currently, the only defined flag is:
1267 *
1268 * 0x01 - verify media after format.
1269 */
1270 if (get_user(blocks, arg) ||
1271 get_user(length, arg+1) ||
1272 get_user(flags, arg+2)) {
1273 err = -EFAULT;
1274 goto out;
1275 }
1276
Borislav Petkovea68d272008-07-23 19:56:01 +02001277 (void) idefloppy_get_sfrp_bit(drive);
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001278 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1279
Borislav Petkovea68d272008-07-23 19:56:01 +02001280 if (idefloppy_queue_pc_tail(drive, &pc))
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001281 err = -EIO;
1282
1283out:
1284 if (err)
Borislav Petkovea68d272008-07-23 19:56:01 +02001285 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001286 return err;
1287}
1288
Bartlomiej Zolnierkiewiczd56c99e2008-10-10 22:39:34 +02001289static int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
1290 unsigned int cmd, void __user *argp)
1291{
1292 switch (cmd) {
1293 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
1294 return 0;
1295 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
1296 return ide_floppy_get_format_capacities(drive, argp);
1297 case IDEFLOPPY_IOCTL_FORMAT_START:
1298 if (!(file->f_mode & 2))
1299 return -EPERM;
1300 return ide_floppy_format_unit(drive, (int __user *)argp);
1301 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1302 return ide_floppy_get_format_progress(drive, argp);
1303 default:
1304 return -ENOTTY;
1305 }
1306}
Borislav Petkov20bf7bd2008-02-02 19:56:35 +01001307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308static int idefloppy_ioctl(struct inode *inode, struct file *file,
1309 unsigned int cmd, unsigned long arg)
1310{
1311 struct block_device *bdev = inode->i_bdev;
1312 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1313 ide_drive_t *drive = floppy->drive;
Borislav Petkov8e555122008-04-18 00:46:27 +02001314 struct ide_atapi_pc pc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 void __user *argp = (void __user *)arg;
Ondrej Zary07203f62005-11-10 00:25:15 +01001316 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Bartlomiej Zolnierkiewiczd56c99e2008-10-10 22:39:34 +02001318 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
Borislav Petkovea68d272008-07-23 19:56:01 +02001319 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Bartlomiej Zolnierkiewiczd56c99e2008-10-10 22:39:34 +02001321 err = ide_floppy_format_ioctl(drive, file, cmd, argp);
1322 if (err != -ENOTTY)
1323 return err;
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +02001324
1325 /*
1326 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
1327 * and CDROM_SEND_PACKET (legacy) ioctls
1328 */
1329 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
1330 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
1331 bdev->bd_disk, cmd, argp);
Bartlomiej Zolnierkiewicz89636af2007-07-20 01:11:59 +02001332
1333 if (err == -ENOTTY)
1334 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
1335
1336 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337}
1338
1339static int idefloppy_media_changed(struct gendisk *disk)
1340{
1341 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1342 ide_drive_t *drive = floppy->drive;
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +01001343 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 /* do not scan partitions twice if this is a removable device */
1346 if (drive->attach) {
1347 drive->attach = 0;
1348 return 0;
1349 }
Borislav Petkovea68d272008-07-23 19:56:01 +02001350 ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED);
1351 drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED;
Borislav Petkov6e5fa7b2008-02-02 19:56:37 +01001352 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353}
1354
1355static int idefloppy_revalidate_disk(struct gendisk *disk)
1356{
1357 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1358 set_capacity(disk, idefloppy_capacity(floppy->drive));
1359 return 0;
1360}
1361
1362static struct block_device_operations idefloppy_ops = {
Paolo Ciarrocchi52d3ccf2008-04-26 17:36:41 +02001363 .owner = THIS_MODULE,
1364 .open = idefloppy_open,
1365 .release = idefloppy_release,
1366 .ioctl = idefloppy_ioctl,
1367 .getgeo = idefloppy_getgeo,
1368 .media_changed = idefloppy_media_changed,
1369 .revalidate_disk = idefloppy_revalidate_disk
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370};
1371
Russell King4031bbe2006-01-06 11:41:00 +00001372static int ide_floppy_probe(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373{
1374 idefloppy_floppy_t *floppy;
1375 struct gendisk *g;
1376
1377 if (!strstr("ide-floppy", drive->driver_req))
1378 goto failed;
Bartlomiej Zolnierkiewicz2a924662008-10-10 22:39:24 +02001379
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (drive->media != ide_floppy)
1381 goto failed;
Bartlomiej Zolnierkiewicz2a924662008-10-10 22:39:24 +02001382
Bartlomiej Zolnierkiewicz51509ee2008-10-10 22:39:34 +02001383 if (!ide_check_atapi_device(drive, DRV_NAME)) {
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001384 printk(KERN_ERR "ide-floppy: %s: not supported by this version"
1385 " of ide-floppy\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 goto failed;
1387 }
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001388 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
1389 if (!floppy) {
1390 printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy"
1391 " structure\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 goto failed;
1393 }
1394
1395 g = alloc_disk(1 << PARTN_BITS);
1396 if (!g)
1397 goto out_free_floppy;
1398
1399 ide_init_disk(g, drive);
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 kref_init(&floppy->kref);
1402
1403 floppy->drive = drive;
1404 floppy->driver = &idefloppy_driver;
1405 floppy->disk = g;
1406
1407 g->private_data = &floppy->driver;
1408
1409 drive->driver_data = floppy;
1410
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001411 idefloppy_setup(drive, floppy);
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001412
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 g->minors = 1 << PARTN_BITS;
1414 g->driverfs_dev = &drive->gendev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
1416 g->fops = &idefloppy_ops;
1417 drive->attach = 1;
1418 add_disk(g);
1419 return 0;
1420
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421out_free_floppy:
1422 kfree(floppy);
1423failed:
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001424 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001427static void __exit idefloppy_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001429 driver_unregister(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430}
1431
Bartlomiej Zolnierkiewicz17514e82005-11-19 22:24:35 +01001432static int __init idefloppy_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
1434 printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
Bartlomiej Zolnierkiewicz8604aff2005-05-26 14:55:34 +02001435 return driver_register(&idefloppy_driver.gen_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436}
1437
Kay Sievers263756e2005-12-12 18:03:44 +01001438MODULE_ALIAS("ide:*m-floppy*");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439module_init(idefloppy_init);
1440module_exit(idefloppy_exit);
1441MODULE_LICENSE("GPL");
Borislav Petkov0571c7a2008-02-02 19:56:38 +01001442MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
1443