Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
d3f20848 BP |
2 | * IDE ATAPI floppy driver. |
3 | * | |
59bca8cc BZ |
4 | * 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 | |
0571c7a4 | 7 | * |
1da177e4 LT |
8 | * 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 | * | |
d3f20848 BP |
14 | * For a historical changelog see |
15 | * Documentation/ide/ChangeLog.ide-floppy.1996-2002 | |
1da177e4 LT |
16 | */ |
17 | ||
51509eec BZ |
18 | #define DRV_NAME "ide-floppy" |
19 | ||
fc6c5bc7 | 20 | #define IDEFLOPPY_VERSION "1.00" |
1da177e4 | 21 | |
1da177e4 LT |
22 | #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> | |
3ceca727 | 36 | #include <linux/hdreg.h> |
1da177e4 | 37 | #include <linux/bitops.h> |
cf8b8975 | 38 | #include <linux/mutex.h> |
1da177e4 | 39 | |
89636af2 BZ |
40 | #include <scsi/scsi_ioctl.h> |
41 | ||
1da177e4 | 42 | #include <asm/byteorder.h> |
7e8b163b BP |
43 | #include <linux/irq.h> |
44 | #include <linux/uaccess.h> | |
45 | #include <linux/io.h> | |
1da177e4 LT |
46 | #include <asm/unaligned.h> |
47 | ||
f373bd82 | 48 | /* define to see debug info */ |
1da177e4 | 49 | #define IDEFLOPPY_DEBUG_LOG 0 |
1da177e4 LT |
50 | |
51 | /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */ | |
0571c7a4 | 52 | #define IDEFLOPPY_DEBUG(fmt, args...) |
1da177e4 LT |
53 | |
54 | #if IDEFLOPPY_DEBUG_LOG | |
bcc77d9c BP |
55 | #define debug_log(fmt, args...) \ |
56 | printk(KERN_INFO "ide-floppy: " fmt, ## args) | |
1da177e4 | 57 | #else |
0571c7a4 | 58 | #define debug_log(fmt, args...) do {} while (0) |
1da177e4 LT |
59 | #endif |
60 | ||
61 | ||
0571c7a4 | 62 | /* Some drives require a longer irq timeout. */ |
1da177e4 LT |
63 | #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD) |
64 | ||
65 | /* | |
0571c7a4 BP |
66 | * After each failed packet command we issue a request sense command and retry |
67 | * the packet command IDEFLOPPY_MAX_PC_RETRIES times. | |
1da177e4 LT |
68 | */ |
69 | #define IDEFLOPPY_MAX_PC_RETRIES 3 | |
70 | ||
71 | /* | |
0571c7a4 BP |
72 | * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE |
73 | * bytes. | |
1da177e4 LT |
74 | */ |
75 | #define IDEFLOPPY_PC_BUFFER_SIZE 256 | |
76 | ||
77 | /* | |
0571c7a4 BP |
78 | * In various places in the driver, we need to allocate storage for packet |
79 | * commands and requests, which will remain valid while we leave the driver to | |
80 | * wait for an interrupt or a timeout event. | |
1da177e4 LT |
81 | */ |
82 | #define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES) | |
83 | ||
194ec0c0 | 84 | /* format capacities descriptor codes */ |
1da177e4 LT |
85 | #define CAPACITY_INVALID 0x00 |
86 | #define CAPACITY_UNFORMATTED 0x01 | |
87 | #define CAPACITY_CURRENT 0x02 | |
88 | #define CAPACITY_NO_CARTRIDGE 0x03 | |
89 | ||
90 | /* | |
0571c7a4 BP |
91 | * Most of our global data which we need to save even as we leave the driver |
92 | * due to an interrupt or a timer event is stored in a variable of type | |
93 | * idefloppy_floppy_t, defined below. | |
1da177e4 LT |
94 | */ |
95 | typedef struct ide_floppy_obj { | |
96 | ide_drive_t *drive; | |
97 | ide_driver_t *driver; | |
98 | struct gendisk *disk; | |
99 | struct kref kref; | |
c94964a4 | 100 | unsigned int openers; /* protected by BKL for now */ |
1da177e4 LT |
101 | |
102 | /* Current packet command */ | |
8e555123 | 103 | struct ide_atapi_pc *pc; |
1da177e4 | 104 | /* Last failed packet command */ |
8e555123 | 105 | struct ide_atapi_pc *failed_pc; |
1da177e4 | 106 | /* Packet command stack */ |
8e555123 | 107 | struct ide_atapi_pc pc_stack[IDEFLOPPY_PC_STACK]; |
1da177e4 LT |
108 | /* Next free packet command storage space */ |
109 | int pc_stack_index; | |
110 | struct request rq_stack[IDEFLOPPY_PC_STACK]; | |
111 | /* We implement a circular array */ | |
112 | int rq_stack_index; | |
113 | ||
0571c7a4 | 114 | /* Last error information */ |
1da177e4 LT |
115 | u8 sense_key, asc, ascq; |
116 | /* delay this long before sending packet command */ | |
117 | u8 ticks; | |
118 | int progress_indication; | |
119 | ||
0571c7a4 | 120 | /* Device information */ |
1da177e4 LT |
121 | /* Current format */ |
122 | int blocks, block_size, bs_factor; | |
194ec0c0 BP |
123 | /* Last format capacity descriptor */ |
124 | u8 cap_desc[8]; | |
1da177e4 | 125 | /* Copy of the flexible disk page */ |
8e81bbba | 126 | u8 flexible_disk_page[32]; |
1da177e4 LT |
127 | /* Write protect */ |
128 | int wp; | |
129 | /* Supports format progress report */ | |
130 | int srfp; | |
1da177e4 LT |
131 | } idefloppy_floppy_t; |
132 | ||
c40d3d38 | 133 | #define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */ |
1da177e4 | 134 | |
0571c7a4 | 135 | /* Defines for the MODE SENSE command */ |
1da177e4 LT |
136 | #define MODE_SENSE_CURRENT 0x00 |
137 | #define MODE_SENSE_CHANGEABLE 0x01 | |
0571c7a4 | 138 | #define MODE_SENSE_DEFAULT 0x02 |
1da177e4 LT |
139 | #define MODE_SENSE_SAVED 0x03 |
140 | ||
0571c7a4 | 141 | /* IOCTLs used in low-level formatting. */ |
1da177e4 LT |
142 | #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 | ||
0571c7a4 | 147 | /* Error code returned in rq->errors to the higher part of the driver. */ |
1da177e4 LT |
148 | #define IDEFLOPPY_ERROR_GENERAL 101 |
149 | ||
1da177e4 | 150 | /* |
948391d1 BP |
151 | * Pages of the SELECT SENSE / MODE SENSE packet commands. |
152 | * See SFF-8070i spec. | |
1da177e4 LT |
153 | */ |
154 | #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b | |
155 | #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05 | |
156 | ||
cf8b8975 | 157 | static DEFINE_MUTEX(idefloppy_ref_mutex); |
1da177e4 LT |
158 | |
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 | ||
08da591e BZ |
164 | static void idefloppy_cleanup_obj(struct kref *); |
165 | ||
1da177e4 LT |
166 | static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) |
167 | { | |
168 | struct ide_floppy_obj *floppy = NULL; | |
169 | ||
cf8b8975 | 170 | mutex_lock(&idefloppy_ref_mutex); |
1da177e4 | 171 | floppy = ide_floppy_g(disk); |
08da591e | 172 | if (floppy) { |
d3e33ff5 | 173 | if (ide_device_get(floppy->drive)) |
08da591e | 174 | floppy = NULL; |
d3e33ff5 BZ |
175 | else |
176 | kref_get(&floppy->kref); | |
08da591e | 177 | } |
cf8b8975 | 178 | mutex_unlock(&idefloppy_ref_mutex); |
1da177e4 LT |
179 | return floppy; |
180 | } | |
181 | ||
1da177e4 LT |
182 | static void ide_floppy_put(struct ide_floppy_obj *floppy) |
183 | { | |
d3e33ff5 BZ |
184 | ide_drive_t *drive = floppy->drive; |
185 | ||
cf8b8975 | 186 | mutex_lock(&idefloppy_ref_mutex); |
9a24b63d | 187 | kref_put(&floppy->kref, idefloppy_cleanup_obj); |
d3e33ff5 | 188 | ide_device_put(drive); |
cf8b8975 | 189 | mutex_unlock(&idefloppy_ref_mutex); |
1da177e4 LT |
190 | } |
191 | ||
1da177e4 | 192 | /* |
0571c7a4 BP |
193 | * Used to finish servicing a request. For read/write requests, we will call |
194 | * ide_end_request to pass to the next buffer. | |
1da177e4 | 195 | */ |
c2b2b293 | 196 | static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs) |
1da177e4 LT |
197 | { |
198 | idefloppy_floppy_t *floppy = drive->driver_data; | |
199 | struct request *rq = HWGROUP(drive)->rq; | |
200 | int error; | |
201 | ||
bcc77d9c | 202 | debug_log("Reached %s\n", __func__); |
1da177e4 LT |
203 | |
204 | switch (uptodate) { | |
0571c7a4 BP |
205 | case 0: error = IDEFLOPPY_ERROR_GENERAL; break; |
206 | case 1: error = 0; break; | |
207 | default: error = uptodate; | |
1da177e4 LT |
208 | } |
209 | if (error) | |
210 | floppy->failed_pc = NULL; | |
211 | /* Why does this happen? */ | |
212 | if (!rq) | |
213 | return 0; | |
4aff5e23 | 214 | if (!blk_special_request(rq)) { |
1da177e4 LT |
215 | /* 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 | ||
8e555123 | 225 | static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, |
32925e1a | 226 | unsigned int bcount, int direction) |
1da177e4 | 227 | { |
9567b349 | 228 | ide_hwif_t *hwif = drive->hwif; |
1da177e4 | 229 | struct request *rq = pc->rq; |
5705f702 | 230 | struct req_iterator iter; |
1da177e4 LT |
231 | struct bio_vec *bvec; |
232 | unsigned long flags; | |
5705f702 | 233 | int count, done = 0; |
1da177e4 LT |
234 | char *data; |
235 | ||
5705f702 | 236 | rq_for_each_segment(bvec, rq, iter) { |
6c92e699 JA |
237 | if (!bcount) |
238 | break; | |
1da177e4 | 239 | |
6c92e699 | 240 | count = min(bvec->bv_len, bcount); |
1da177e4 | 241 | |
6c92e699 | 242 | data = bvec_kmap_irq(bvec, &flags); |
32925e1a | 243 | if (direction) |
374e042c | 244 | hwif->tp_ops->output_data(drive, NULL, data, count); |
32925e1a | 245 | else |
374e042c | 246 | hwif->tp_ops->input_data(drive, NULL, data, count); |
6c92e699 | 247 | bvec_kunmap_irq(data, &flags); |
1da177e4 | 248 | |
6c92e699 JA |
249 | bcount -= count; |
250 | pc->b_count += count; | |
251 | done += count; | |
1da177e4 LT |
252 | } |
253 | ||
c2b2b293 | 254 | idefloppy_end_request(drive, 1, done >> 9); |
1da177e4 LT |
255 | |
256 | if (bcount) { | |
32925e1a BP |
257 | printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n", |
258 | drive->name, __func__, bcount); | |
9f87abe8 | 259 | ide_pad_transfer(drive, direction, bcount); |
1da177e4 LT |
260 | } |
261 | } | |
262 | ||
8e555123 BP |
263 | static void idefloppy_update_buffers(ide_drive_t *drive, |
264 | struct ide_atapi_pc *pc) | |
1da177e4 LT |
265 | { |
266 | struct request *rq = pc->rq; | |
267 | struct bio *bio = rq->bio; | |
268 | ||
269 | while ((bio = rq->bio) != NULL) | |
c2b2b293 | 270 | idefloppy_end_request(drive, 1, 0); |
1da177e4 LT |
271 | } |
272 | ||
273 | /* | |
0571c7a4 BP |
274 | * Generate a new packet command request in front of the request queue, before |
275 | * the current request so that it will be processed immediately, on the next | |
276 | * pass through the driver. | |
1da177e4 | 277 | */ |
8e555123 | 278 | static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc, |
0571c7a4 | 279 | struct request *rq) |
1da177e4 LT |
280 | { |
281 | struct ide_floppy_obj *floppy = drive->driver_data; | |
282 | ||
124cafc5 | 283 | blk_rq_init(NULL, rq); |
1da177e4 | 284 | rq->buffer = (char *) pc; |
4aff5e23 | 285 | rq->cmd_type = REQ_TYPE_SPECIAL; |
e8a96aa7 | 286 | rq->cmd_flags |= REQ_PREEMPT; |
1da177e4 | 287 | rq->rq_disk = floppy->disk; |
20cd93be | 288 | memcpy(rq->cmd, pc->c, 12); |
63f5abb0 | 289 | ide_do_drive_cmd(drive, rq); |
1da177e4 LT |
290 | } |
291 | ||
8e555123 | 292 | static struct ide_atapi_pc *idefloppy_next_pc_storage(ide_drive_t *drive) |
1da177e4 LT |
293 | { |
294 | idefloppy_floppy_t *floppy = drive->driver_data; | |
295 | ||
296 | if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK) | |
0571c7a4 | 297 | floppy->pc_stack_index = 0; |
1da177e4 LT |
298 | return (&floppy->pc_stack[floppy->pc_stack_index++]); |
299 | } | |
300 | ||
0571c7a4 | 301 | static struct request *idefloppy_next_rq_storage(ide_drive_t *drive) |
1da177e4 LT |
302 | { |
303 | idefloppy_floppy_t *floppy = drive->driver_data; | |
304 | ||
305 | if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK) | |
306 | floppy->rq_stack_index = 0; | |
307 | return (&floppy->rq_stack[floppy->rq_stack_index++]); | |
308 | } | |
309 | ||
81f49382 | 310 | static void ide_floppy_callback(ide_drive_t *drive) |
1da177e4 LT |
311 | { |
312 | idefloppy_floppy_t *floppy = drive->driver_data; | |
81f49382 BP |
313 | struct ide_atapi_pc *pc = floppy->pc; |
314 | int uptodate = pc->error ? 0 : 1; | |
1da177e4 | 315 | |
bcc77d9c BP |
316 | debug_log("Reached %s\n", __func__); |
317 | ||
dd2e9a03 BZ |
318 | if (floppy->failed_pc == pc) |
319 | floppy->failed_pc = NULL; | |
320 | ||
81f49382 BP |
321 | if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 || |
322 | (pc->rq && blk_pc_request(pc->rq))) | |
323 | uptodate = 1; /* FIXME */ | |
324 | else if (pc->c[0] == GPCMD_REQUEST_SENSE) { | |
325 | u8 *buf = floppy->pc->buf; | |
a6ff2d3b | 326 | |
81f49382 BP |
327 | if (!pc->error) { |
328 | floppy->sense_key = buf[2] & 0x0F; | |
329 | floppy->asc = buf[12]; | |
330 | floppy->ascq = buf[13]; | |
331 | floppy->progress_indication = buf[15] & 0x80 ? | |
332 | (u16)get_unaligned((u16 *)&buf[16]) : 0x10000; | |
a6ff2d3b | 333 | |
81f49382 BP |
334 | if (floppy->failed_pc) |
335 | debug_log("pc = %x, ", floppy->failed_pc->c[0]); | |
bcc77d9c | 336 | |
81f49382 BP |
337 | debug_log("sense key = %x, asc = %x, ascq = %x\n", |
338 | floppy->sense_key, floppy->asc, floppy->ascq); | |
339 | } else | |
340 | printk(KERN_ERR "Error in REQUEST SENSE itself - " | |
341 | "Aborting request!\n"); | |
342 | } | |
1da177e4 | 343 | |
81f49382 | 344 | idefloppy_end_request(drive, uptodate, 0); |
1da177e4 LT |
345 | } |
346 | ||
8e555123 | 347 | static void idefloppy_init_pc(struct ide_atapi_pc *pc) |
1da177e4 | 348 | { |
68dc3575 | 349 | memset(pc, 0, sizeof(*pc)); |
8e555123 BP |
350 | pc->buf = pc->pc_buf; |
351 | pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE; | |
1da177e4 LT |
352 | } |
353 | ||
8e555123 | 354 | static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc) |
1da177e4 | 355 | { |
30d67099 BP |
356 | idefloppy_init_pc(pc); |
357 | pc->c[0] = GPCMD_REQUEST_SENSE; | |
1da177e4 | 358 | pc->c[4] = 255; |
8e555123 | 359 | pc->req_xfer = 18; |
1da177e4 LT |
360 | } |
361 | ||
362 | /* | |
0571c7a4 BP |
363 | * Called when an error was detected during the last packet command. We queue a |
364 | * request sense packet command in the head of the request list. | |
1da177e4 | 365 | */ |
0571c7a4 | 366 | static void idefloppy_retry_pc(ide_drive_t *drive) |
1da177e4 | 367 | { |
8e555123 | 368 | struct ide_atapi_pc *pc; |
1da177e4 | 369 | struct request *rq; |
1da177e4 | 370 | |
64a57fe4 | 371 | (void)ide_read_error(drive); |
1da177e4 LT |
372 | pc = idefloppy_next_pc_storage(drive); |
373 | rq = idefloppy_next_rq_storage(drive); | |
374 | idefloppy_create_request_sense_cmd(pc); | |
375 | idefloppy_queue_pc_head(drive, pc, rq); | |
376 | } | |
377 | ||
0eea6458 | 378 | /* The usual interrupt handler called during a packet command. */ |
52d3ccf7 | 379 | static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive) |
1da177e4 LT |
380 | { |
381 | idefloppy_floppy_t *floppy = drive->driver_data; | |
1da177e4 | 382 | |
646c0cb6 BZ |
383 | return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr, |
384 | IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers, | |
385 | idefloppy_retry_pc, NULL, ide_floppy_io_buffers); | |
1da177e4 LT |
386 | } |
387 | ||
1da177e4 | 388 | /* |
0571c7a4 BP |
389 | * What we have here is a classic case of a top half / bottom half interrupt |
390 | * service routine. In interrupt mode, the device sends an interrupt to signal | |
391 | * that it is ready to receive a packet. However, we need to delay about 2-3 | |
392 | * ticks before issuing the packet or we gets in trouble. | |
1da177e4 | 393 | */ |
cbbc4e81 | 394 | static int idefloppy_transfer_pc(ide_drive_t *drive) |
1da177e4 LT |
395 | { |
396 | idefloppy_floppy_t *floppy = drive->driver_data; | |
397 | ||
398 | /* Send the actual packet */ | |
374e042c | 399 | drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12); |
9567b349 | 400 | |
1da177e4 LT |
401 | /* Timeout for the packet command */ |
402 | return IDEFLOPPY_WAIT_CMD; | |
403 | } | |
404 | ||
cbbc4e81 BP |
405 | |
406 | /* | |
407 | * Called as an interrupt (or directly). When the device says it's ready for a | |
408 | * packet, we schedule the packet transfer to occur about 2-3 ticks later in | |
409 | * transfer_pc. | |
410 | */ | |
411 | static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive) | |
1da177e4 LT |
412 | { |
413 | idefloppy_floppy_t *floppy = drive->driver_data; | |
6ffb6641 | 414 | struct ide_atapi_pc *pc = floppy->pc; |
0b2eea4c BZ |
415 | ide_expiry_t *expiry; |
416 | unsigned int timeout; | |
1da177e4 | 417 | |
0571c7a4 | 418 | /* |
1da177e4 LT |
419 | * The following delay solves a problem with ATAPI Zip 100 drives |
420 | * where the Busy flag was apparently being deasserted before the | |
421 | * unit was ready to receive data. This was happening on a | |
422 | * 1200 MHz Athlon system. 10/26/01 25msec is too short, | |
423 | * 40 and 50msec work well. idefloppy_pc_intr will not be actually | |
424 | * used until after the packet is moved in about 50 msec. | |
425 | */ | |
ea68d270 | 426 | if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) { |
0b2eea4c | 427 | timeout = floppy->ticks; |
cbbc4e81 | 428 | expiry = &idefloppy_transfer_pc; |
0b2eea4c BZ |
429 | } else { |
430 | timeout = IDEFLOPPY_WAIT_CMD; | |
431 | expiry = NULL; | |
432 | } | |
433 | ||
594c16d8 | 434 | return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry); |
1da177e4 LT |
435 | } |
436 | ||
d652c138 | 437 | static void ide_floppy_report_error(idefloppy_floppy_t *floppy, |
8e555123 | 438 | struct ide_atapi_pc *pc) |
1da177e4 | 439 | { |
d652c138 | 440 | /* supress error messages resulting from Medium not present */ |
1da177e4 LT |
441 | if (floppy->sense_key == 0x02 && |
442 | floppy->asc == 0x3a && | |
443 | floppy->ascq == 0x00) | |
d652c138 BP |
444 | return; |
445 | ||
446 | printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, " | |
447 | "asc = %2x, ascq = %2x\n", | |
448 | floppy->drive->name, pc->c[0], floppy->sense_key, | |
449 | floppy->asc, floppy->ascq); | |
450 | ||
1da177e4 LT |
451 | } |
452 | ||
0571c7a4 | 453 | static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive, |
8e555123 | 454 | struct ide_atapi_pc *pc) |
1da177e4 LT |
455 | { |
456 | idefloppy_floppy_t *floppy = drive->driver_data; | |
1da177e4 | 457 | |
1da177e4 | 458 | if (floppy->failed_pc == NULL && |
30d67099 | 459 | pc->c[0] != GPCMD_REQUEST_SENSE) |
1da177e4 LT |
460 | floppy->failed_pc = pc; |
461 | /* Set the current packet command */ | |
462 | floppy->pc = pc; | |
463 | ||
757ced89 | 464 | if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) { |
6e5fa7b8 | 465 | if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) |
757ced89 BP |
466 | ide_floppy_report_error(floppy, pc); |
467 | /* Giving up */ | |
468 | pc->error = IDEFLOPPY_ERROR_GENERAL; | |
469 | ||
1da177e4 | 470 | floppy->failed_pc = NULL; |
2207fa5a | 471 | drive->pc_callback(drive); |
1da177e4 LT |
472 | return ide_stopped; |
473 | } | |
474 | ||
bcc77d9c | 475 | debug_log("Retry number - %d\n", pc->retries); |
1da177e4 LT |
476 | |
477 | pc->retries++; | |
1da177e4 | 478 | |
cbbc4e81 | 479 | return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer, |
6bf1641c | 480 | IDEFLOPPY_WAIT_CMD, NULL); |
1da177e4 LT |
481 | } |
482 | ||
8e555123 | 483 | static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent) |
1da177e4 | 484 | { |
bcc77d9c | 485 | debug_log("creating prevent removal command, prevent = %d\n", prevent); |
1da177e4 LT |
486 | |
487 | idefloppy_init_pc(pc); | |
30d67099 | 488 | pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL; |
1da177e4 LT |
489 | pc->c[4] = prevent; |
490 | } | |
491 | ||
8e555123 | 492 | static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) |
1da177e4 LT |
493 | { |
494 | idefloppy_init_pc(pc); | |
30d67099 | 495 | pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES; |
1da177e4 LT |
496 | pc->c[7] = 255; |
497 | pc->c[8] = 255; | |
8e555123 | 498 | pc->req_xfer = 255; |
1da177e4 LT |
499 | } |
500 | ||
8e555123 BP |
501 | static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b, |
502 | int l, int flags) | |
1da177e4 LT |
503 | { |
504 | idefloppy_init_pc(pc); | |
30d67099 | 505 | pc->c[0] = GPCMD_FORMAT_UNIT; |
1da177e4 LT |
506 | pc->c[1] = 0x17; |
507 | ||
8e555123 BP |
508 | memset(pc->buf, 0, 12); |
509 | pc->buf[1] = 0xA2; | |
1da177e4 LT |
510 | /* Default format list header, u8 1: FOV/DCRT/IMM bits set */ |
511 | ||
512 | if (flags & 1) /* Verify bit on... */ | |
8e555123 BP |
513 | pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */ |
514 | pc->buf[3] = 8; | |
1da177e4 | 515 | |
8e555123 BP |
516 | put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4])); |
517 | put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8])); | |
518 | pc->buf_size = 12; | |
6e5fa7b8 | 519 | pc->flags |= PC_FLAG_WRITING; |
1da177e4 LT |
520 | } |
521 | ||
0571c7a4 | 522 | /* A mode sense command is used to "sense" floppy parameters. */ |
8e555123 BP |
523 | static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, |
524 | u8 page_code, u8 type) | |
1da177e4 | 525 | { |
24a5d703 | 526 | u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */ |
0571c7a4 | 527 | |
1da177e4 | 528 | idefloppy_init_pc(pc); |
30d67099 | 529 | pc->c[0] = GPCMD_MODE_SENSE_10; |
1da177e4 LT |
530 | pc->c[1] = 0; |
531 | pc->c[2] = page_code + (type << 6); | |
532 | ||
533 | switch (page_code) { | |
0571c7a4 BP |
534 | case IDEFLOPPY_CAPABILITIES_PAGE: |
535 | length += 12; | |
536 | break; | |
537 | case IDEFLOPPY_FLEXIBLE_DISK_PAGE: | |
538 | length += 32; | |
539 | break; | |
540 | default: | |
541 | printk(KERN_ERR "ide-floppy: unsupported page code " | |
1da177e4 LT |
542 | "in create_mode_sense_cmd\n"); |
543 | } | |
8f622430 | 544 | put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]); |
8e555123 | 545 | pc->req_xfer = length; |
1da177e4 LT |
546 | } |
547 | ||
8e555123 | 548 | static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start) |
1da177e4 LT |
549 | { |
550 | idefloppy_init_pc(pc); | |
30d67099 | 551 | pc->c[0] = GPCMD_START_STOP_UNIT; |
1da177e4 LT |
552 | pc->c[4] = start; |
553 | } | |
554 | ||
ae7e8ddc | 555 | static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, |
8e555123 | 556 | struct ide_atapi_pc *pc, struct request *rq, |
ae7e8ddc | 557 | unsigned long sector) |
1da177e4 LT |
558 | { |
559 | int block = sector / floppy->bs_factor; | |
560 | int blocks = rq->nr_sectors / floppy->bs_factor; | |
561 | int cmd = rq_data_dir(rq); | |
562 | ||
ae7e8ddc | 563 | debug_log("create_rw10_cmd: block == %d, blocks == %d\n", |
1da177e4 LT |
564 | block, blocks); |
565 | ||
566 | idefloppy_init_pc(pc); | |
ae7e8ddc BP |
567 | pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; |
568 | put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]); | |
8f622430 | 569 | put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]); |
ae7e8ddc | 570 | |
20cd93be BP |
571 | memcpy(rq->cmd, pc->c, 12); |
572 | ||
1da177e4 LT |
573 | pc->rq = rq; |
574 | pc->b_count = cmd == READ ? 0 : rq->bio->bi_size; | |
4aff5e23 | 575 | if (rq->cmd_flags & REQ_RW) |
6e5fa7b8 | 576 | pc->flags |= PC_FLAG_WRITING; |
8e555123 BP |
577 | pc->buf = NULL; |
578 | pc->req_xfer = pc->buf_size = blocks * floppy->block_size; | |
5e331095 | 579 | pc->flags |= PC_FLAG_DMA_OK; |
1da177e4 LT |
580 | } |
581 | ||
0571c7a4 | 582 | static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, |
8e555123 | 583 | struct ide_atapi_pc *pc, struct request *rq) |
1da177e4 | 584 | { |
1da177e4 LT |
585 | idefloppy_init_pc(pc); |
586 | memcpy(pc->c, rq->cmd, sizeof(pc->c)); | |
3d6392cf JA |
587 | pc->rq = rq; |
588 | pc->b_count = rq->data_len; | |
589 | if (rq->data_len && rq_data_dir(rq) == WRITE) | |
6e5fa7b8 | 590 | pc->flags |= PC_FLAG_WRITING; |
8e555123 | 591 | pc->buf = rq->data; |
3d6392cf | 592 | if (rq->bio) |
5e331095 | 593 | pc->flags |= PC_FLAG_DMA_OK; |
3d6392cf JA |
594 | /* |
595 | * possibly problematic, doesn't look like ide-floppy correctly | |
596 | * handled scattered requests if dma fails... | |
597 | */ | |
8e555123 | 598 | pc->req_xfer = pc->buf_size = rq->data_len; |
1da177e4 LT |
599 | } |
600 | ||
0571c7a4 BP |
601 | static ide_startstop_t idefloppy_do_request(ide_drive_t *drive, |
602 | struct request *rq, sector_t block_s) | |
1da177e4 LT |
603 | { |
604 | idefloppy_floppy_t *floppy = drive->driver_data; | |
8e555123 | 605 | struct ide_atapi_pc *pc; |
1da177e4 LT |
606 | unsigned long block = (unsigned long)block_s; |
607 | ||
bcc77d9c | 608 | debug_log("dev: %s, cmd_type: %x, errors: %d\n", |
18cddac3 | 609 | rq->rq_disk ? rq->rq_disk->disk_name : "?", |
bcc77d9c BP |
610 | rq->cmd_type, rq->errors); |
611 | debug_log("sector: %ld, nr_sectors: %ld, " | |
1da177e4 LT |
612 | "current_nr_sectors: %d\n", (long)rq->sector, |
613 | rq->nr_sectors, rq->current_nr_sectors); | |
614 | ||
615 | if (rq->errors >= ERROR_MAX) { | |
d652c138 BP |
616 | if (floppy->failed_pc) |
617 | ide_floppy_report_error(floppy, floppy->failed_pc); | |
1da177e4 LT |
618 | else |
619 | printk(KERN_ERR "ide-floppy: %s: I/O error\n", | |
620 | drive->name); | |
c2b2b293 | 621 | idefloppy_end_request(drive, 0, 0); |
1da177e4 LT |
622 | return ide_stopped; |
623 | } | |
4aff5e23 | 624 | if (blk_fs_request(rq)) { |
1da177e4 LT |
625 | if (((long)rq->sector % floppy->bs_factor) || |
626 | (rq->nr_sectors % floppy->bs_factor)) { | |
0571c7a4 BP |
627 | printk(KERN_ERR "%s: unsupported r/w request size\n", |
628 | drive->name); | |
c2b2b293 | 629 | idefloppy_end_request(drive, 0, 0); |
1da177e4 LT |
630 | return ide_stopped; |
631 | } | |
632 | pc = idefloppy_next_pc_storage(drive); | |
633 | idefloppy_create_rw_cmd(floppy, pc, rq, block); | |
4aff5e23 | 634 | } else if (blk_special_request(rq)) { |
8e555123 | 635 | pc = (struct ide_atapi_pc *) rq->buffer; |
4aff5e23 | 636 | } else if (blk_pc_request(rq)) { |
1da177e4 | 637 | pc = idefloppy_next_pc_storage(drive); |
3d6392cf | 638 | idefloppy_blockpc_cmd(floppy, pc, rq); |
1da177e4 LT |
639 | } else { |
640 | blk_dump_rq_flags(rq, | |
641 | "ide-floppy: unsupported command in queue"); | |
c2b2b293 | 642 | idefloppy_end_request(drive, 0, 0); |
1da177e4 LT |
643 | return ide_stopped; |
644 | } | |
645 | ||
646 | pc->rq = rq; | |
5d41893c | 647 | |
1da177e4 LT |
648 | return idefloppy_issue_pc(drive, pc); |
649 | } | |
650 | ||
651 | /* | |
0571c7a4 BP |
652 | * Add a special packet command request to the tail of the request queue, |
653 | * and wait for it to be serviced. | |
1da177e4 | 654 | */ |
8e555123 | 655 | static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc) |
1da177e4 LT |
656 | { |
657 | struct ide_floppy_obj *floppy = drive->driver_data; | |
6fe16238 FT |
658 | struct request *rq; |
659 | int error; | |
1da177e4 | 660 | |
6fe16238 FT |
661 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
662 | rq->buffer = (char *) pc; | |
663 | rq->cmd_type = REQ_TYPE_SPECIAL; | |
20cd93be | 664 | memcpy(rq->cmd, pc->c, 12); |
6fe16238 FT |
665 | error = blk_execute_rq(drive->queue, floppy->disk, rq, 0); |
666 | blk_put_request(rq); | |
1da177e4 | 667 | |
6fe16238 | 668 | return error; |
1da177e4 LT |
669 | } |
670 | ||
671 | /* | |
8e81bbba BP |
672 | * Look at the flexible disk page parameters. We ignore the CHS capacity |
673 | * parameters and use the LBA parameters instead. | |
1da177e4 | 674 | */ |
8e81bbba | 675 | static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive) |
1da177e4 LT |
676 | { |
677 | idefloppy_floppy_t *floppy = drive->driver_data; | |
8e555123 | 678 | struct ide_atapi_pc pc; |
8e81bbba | 679 | u8 *page; |
1da177e4 | 680 | int capacity, lba_capacity; |
8e81bbba BP |
681 | u16 transfer_rate, sector_size, cyls, rpm; |
682 | u8 heads, sectors; | |
1da177e4 | 683 | |
8e81bbba BP |
684 | idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, |
685 | MODE_SENSE_CURRENT); | |
686 | ||
687 | if (idefloppy_queue_pc_tail(drive, &pc)) { | |
688 | printk(KERN_ERR "ide-floppy: Can't get flexible disk page" | |
689 | " parameters\n"); | |
1da177e4 LT |
690 | return 1; |
691 | } | |
8e555123 | 692 | floppy->wp = !!(pc.buf[3] & 0x80); |
1da177e4 | 693 | set_disk_ro(floppy->disk, floppy->wp); |
8e555123 | 694 | page = &pc.buf[8]; |
8e81bbba | 695 | |
85ae98a3 HH |
696 | transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]); |
697 | sector_size = be16_to_cpup((__be16 *)&pc.buf[8 + 6]); | |
698 | cyls = be16_to_cpup((__be16 *)&pc.buf[8 + 8]); | |
699 | rpm = be16_to_cpup((__be16 *)&pc.buf[8 + 28]); | |
8e555123 BP |
700 | heads = pc.buf[8 + 4]; |
701 | sectors = pc.buf[8 + 5]; | |
8e81bbba BP |
702 | |
703 | capacity = cyls * heads * sectors * sector_size; | |
704 | ||
705 | if (memcmp(page, &floppy->flexible_disk_page, 32)) | |
1da177e4 LT |
706 | printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, " |
707 | "%d sector size, %d rpm\n", | |
8e81bbba BP |
708 | drive->name, capacity / 1024, cyls, heads, |
709 | sectors, transfer_rate / 8, sector_size, rpm); | |
710 | ||
711 | memcpy(&floppy->flexible_disk_page, page, 32); | |
712 | drive->bios_cyl = cyls; | |
713 | drive->bios_head = heads; | |
714 | drive->bios_sect = sectors; | |
1da177e4 | 715 | lba_capacity = floppy->blocks * floppy->block_size; |
8e81bbba | 716 | |
1da177e4 LT |
717 | if (capacity < lba_capacity) { |
718 | printk(KERN_NOTICE "%s: The disk reports a capacity of %d " | |
719 | "bytes, but the drive only handles %d\n", | |
720 | drive->name, lba_capacity, capacity); | |
8e81bbba BP |
721 | floppy->blocks = floppy->block_size ? |
722 | capacity / floppy->block_size : 0; | |
1da177e4 LT |
723 | } |
724 | return 0; | |
725 | } | |
726 | ||
948391d1 | 727 | static int idefloppy_get_sfrp_bit(ide_drive_t *drive) |
1da177e4 LT |
728 | { |
729 | idefloppy_floppy_t *floppy = drive->driver_data; | |
8e555123 | 730 | struct ide_atapi_pc pc; |
1da177e4 LT |
731 | |
732 | floppy->srfp = 0; | |
733 | idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE, | |
734 | MODE_SENSE_CURRENT); | |
735 | ||
6e5fa7b8 | 736 | pc.flags |= PC_FLAG_SUPPRESS_ERROR; |
948391d1 | 737 | if (idefloppy_queue_pc_tail(drive, &pc)) |
1da177e4 | 738 | return 1; |
1da177e4 | 739 | |
8e555123 | 740 | floppy->srfp = pc.buf[8 + 2] & 0x40; |
1da177e4 LT |
741 | return (0); |
742 | } | |
743 | ||
744 | /* | |
194ec0c0 BP |
745 | * Determine if a media is present in the floppy drive, and if so, its LBA |
746 | * capacity. | |
1da177e4 | 747 | */ |
194ec0c0 | 748 | static int ide_floppy_get_capacity(ide_drive_t *drive) |
1da177e4 LT |
749 | { |
750 | idefloppy_floppy_t *floppy = drive->driver_data; | |
8e555123 | 751 | struct ide_atapi_pc pc; |
194ec0c0 BP |
752 | u8 *cap_desc; |
753 | u8 header_len, desc_cnt; | |
754 | int i, rc = 1, blocks, length; | |
755 | ||
1da177e4 LT |
756 | drive->bios_cyl = 0; |
757 | drive->bios_head = drive->bios_sect = 0; | |
fdb77da4 AC |
758 | floppy->blocks = 0; |
759 | floppy->bs_factor = 1; | |
1da177e4 LT |
760 | set_capacity(floppy->disk, 0); |
761 | ||
762 | idefloppy_create_read_capacity_cmd(&pc); | |
763 | if (idefloppy_queue_pc_tail(drive, &pc)) { | |
764 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); | |
765 | return 1; | |
766 | } | |
8e555123 BP |
767 | header_len = pc.buf[3]; |
768 | cap_desc = &pc.buf[4]; | |
194ec0c0 BP |
769 | desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ |
770 | ||
771 | for (i = 0; i < desc_cnt; i++) { | |
772 | unsigned int desc_start = 4 + i*8; | |
773 | ||
85ae98a3 HH |
774 | blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); |
775 | length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); | |
194ec0c0 BP |
776 | |
777 | debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", | |
778 | i, blocks * length / 1024, blocks, length); | |
1da177e4 | 779 | |
194ec0c0 BP |
780 | if (i) |
781 | continue; | |
782 | /* | |
783 | * the code below is valid only for the 1st descriptor, ie i=0 | |
784 | */ | |
1da177e4 | 785 | |
8e555123 | 786 | switch (pc.buf[desc_start + 4] & 0x03) { |
1da177e4 LT |
787 | /* Clik! drive returns this instead of CAPACITY_CURRENT */ |
788 | case CAPACITY_UNFORMATTED: | |
ea68d270 | 789 | if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) |
0571c7a4 | 790 | /* |
1da177e4 LT |
791 | * If it is not a clik drive, break out |
792 | * (maintains previous driver behaviour) | |
793 | */ | |
794 | break; | |
795 | case CAPACITY_CURRENT: | |
796 | /* Normal Zip/LS-120 disks */ | |
194ec0c0 | 797 | if (memcmp(cap_desc, &floppy->cap_desc, 8)) |
1da177e4 LT |
798 | printk(KERN_INFO "%s: %dkB, %d blocks, %d " |
799 | "sector size\n", drive->name, | |
800 | blocks * length / 1024, blocks, length); | |
194ec0c0 BP |
801 | memcpy(&floppy->cap_desc, cap_desc, 8); |
802 | ||
1da177e4 LT |
803 | if (!length || length % 512) { |
804 | printk(KERN_NOTICE "%s: %d bytes block size " | |
805 | "not supported\n", drive->name, length); | |
806 | } else { | |
194ec0c0 BP |
807 | floppy->blocks = blocks; |
808 | floppy->block_size = length; | |
809 | floppy->bs_factor = length / 512; | |
810 | if (floppy->bs_factor != 1) | |
811 | printk(KERN_NOTICE "%s: warning: non " | |
1da177e4 LT |
812 | "512 bytes block size not " |
813 | "fully supported\n", | |
814 | drive->name); | |
194ec0c0 | 815 | rc = 0; |
1da177e4 LT |
816 | } |
817 | break; | |
818 | case CAPACITY_NO_CARTRIDGE: | |
819 | /* | |
820 | * This is a KERN_ERR so it appears on screen | |
821 | * for the user to see | |
822 | */ | |
823 | printk(KERN_ERR "%s: No disk in drive\n", drive->name); | |
824 | break; | |
825 | case CAPACITY_INVALID: | |
826 | printk(KERN_ERR "%s: Invalid capacity for disk " | |
827 | "in drive\n", drive->name); | |
828 | break; | |
829 | } | |
194ec0c0 | 830 | debug_log("Descriptor 0 Code: %d\n", |
8e555123 | 831 | pc.buf[desc_start + 4] & 0x03); |
1da177e4 LT |
832 | } |
833 | ||
834 | /* Clik! disk does not support get_flexible_disk_page */ | |
ea68d270 | 835 | if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) |
8e81bbba | 836 | (void) ide_floppy_get_flexible_disk_page(drive); |
1da177e4 LT |
837 | |
838 | set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); | |
839 | return rc; | |
840 | } | |
841 | ||
842 | /* | |
194ec0c0 BP |
843 | * Obtain the list of formattable capacities. |
844 | * Very similar to ide_floppy_get_capacity, except that we push the capacity | |
845 | * descriptors to userland, instead of our own structures. | |
846 | * | |
847 | * Userland gives us the following structure: | |
848 | * | |
849 | * struct idefloppy_format_capacities { | |
850 | * int nformats; | |
851 | * struct { | |
852 | * int nblocks; | |
853 | * int blocksize; | |
854 | * } formats[]; | |
855 | * }; | |
856 | * | |
857 | * userland initializes nformats to the number of allocated formats[] records. | |
858 | * On exit we set nformats to the number of records we've actually initialized. | |
859 | */ | |
1da177e4 | 860 | |
194ec0c0 | 861 | static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg) |
1da177e4 | 862 | { |
8e555123 | 863 | struct ide_atapi_pc pc; |
194ec0c0 BP |
864 | u8 header_len, desc_cnt; |
865 | int i, blocks, length, u_array_size, u_index; | |
1da177e4 LT |
866 | int __user *argp; |
867 | ||
868 | if (get_user(u_array_size, arg)) | |
869 | return (-EFAULT); | |
870 | ||
871 | if (u_array_size <= 0) | |
872 | return (-EINVAL); | |
873 | ||
874 | idefloppy_create_read_capacity_cmd(&pc); | |
875 | if (idefloppy_queue_pc_tail(drive, &pc)) { | |
876 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); | |
194ec0c0 BP |
877 | return (-EIO); |
878 | } | |
8e555123 | 879 | header_len = pc.buf[3]; |
194ec0c0 | 880 | desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ |
1da177e4 LT |
881 | |
882 | u_index = 0; | |
883 | argp = arg + 1; | |
884 | ||
885 | /* | |
194ec0c0 BP |
886 | * We always skip the first capacity descriptor. That's the current |
887 | * capacity. We are interested in the remaining descriptors, the | |
888 | * formattable capacities. | |
889 | */ | |
890 | for (i = 1; i < desc_cnt; i++) { | |
891 | unsigned int desc_start = 4 + i*8; | |
1da177e4 | 892 | |
1da177e4 LT |
893 | if (u_index >= u_array_size) |
894 | break; /* User-supplied buffer too small */ | |
1da177e4 | 895 | |
85ae98a3 HH |
896 | blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); |
897 | length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); | |
1da177e4 LT |
898 | |
899 | if (put_user(blocks, argp)) | |
900 | return(-EFAULT); | |
901 | ++argp; | |
902 | ||
903 | if (put_user(length, argp)) | |
904 | return (-EFAULT); | |
905 | ++argp; | |
906 | ||
907 | ++u_index; | |
908 | } | |
909 | ||
910 | if (put_user(u_index, arg)) | |
911 | return (-EFAULT); | |
912 | return (0); | |
913 | } | |
914 | ||
1da177e4 | 915 | /* |
0571c7a4 BP |
916 | * Get ATAPI_FORMAT_UNIT progress indication. |
917 | * | |
918 | * Userland gives a pointer to an int. The int is set to a progress | |
919 | * indicator 0-65536, with 65536=100%. | |
920 | * | |
921 | * If the drive does not support format progress indication, we just check | |
922 | * the dsc bit, and return either 0 or 65536. | |
923 | */ | |
1da177e4 LT |
924 | |
925 | static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg) | |
926 | { | |
927 | idefloppy_floppy_t *floppy = drive->driver_data; | |
8e555123 | 928 | struct ide_atapi_pc pc; |
1da177e4 LT |
929 | int progress_indication = 0x10000; |
930 | ||
931 | if (floppy->srfp) { | |
932 | idefloppy_create_request_sense_cmd(&pc); | |
0571c7a4 | 933 | if (idefloppy_queue_pc_tail(drive, &pc)) |
1da177e4 | 934 | return (-EIO); |
1da177e4 LT |
935 | |
936 | if (floppy->sense_key == 2 && | |
937 | floppy->asc == 4 && | |
0571c7a4 | 938 | floppy->ascq == 4) |
1da177e4 | 939 | progress_indication = floppy->progress_indication; |
0571c7a4 BP |
940 | |
941 | /* Else assume format_unit has finished, and we're at 0x10000 */ | |
1da177e4 | 942 | } else { |
b73c7ee2 | 943 | ide_hwif_t *hwif = drive->hwif; |
1da177e4 | 944 | unsigned long flags; |
22c525b9 | 945 | u8 stat; |
1da177e4 LT |
946 | |
947 | local_irq_save(flags); | |
374e042c | 948 | stat = hwif->tp_ops->read_status(hwif); |
1da177e4 LT |
949 | local_irq_restore(flags); |
950 | ||
3a7d2484 | 951 | progress_indication = ((stat & ATA_DSC) == 0) ? 0 : 0x10000; |
1da177e4 LT |
952 | } |
953 | if (put_user(progress_indication, arg)) | |
954 | return (-EFAULT); | |
955 | ||
956 | return (0); | |
957 | } | |
958 | ||
0571c7a4 | 959 | static sector_t idefloppy_capacity(ide_drive_t *drive) |
1da177e4 LT |
960 | { |
961 | idefloppy_floppy_t *floppy = drive->driver_data; | |
962 | unsigned long capacity = floppy->blocks * floppy->bs_factor; | |
963 | ||
964 | return capacity; | |
965 | } | |
966 | ||
7662d046 | 967 | #ifdef CONFIG_IDE_PROC_FS |
8185d5aa BZ |
968 | ide_devset_rw(bios_cyl, 0, 1023, bios_cyl); |
969 | ide_devset_rw(bios_head, 0, 255, bios_head); | |
970 | ide_devset_rw(bios_sect, 0, 63, bios_sect); | |
971 | ||
972 | static int get_ticks(ide_drive_t *drive) | |
1da177e4 LT |
973 | { |
974 | idefloppy_floppy_t *floppy = drive->driver_data; | |
8185d5aa BZ |
975 | return floppy->ticks; |
976 | } | |
1da177e4 | 977 | |
8185d5aa BZ |
978 | static int set_ticks(ide_drive_t *drive, int arg) |
979 | { | |
980 | idefloppy_floppy_t *floppy = drive->driver_data; | |
981 | floppy->ticks = arg; | |
982 | return 0; | |
1da177e4 | 983 | } |
8185d5aa BZ |
984 | |
985 | IDE_DEVSET(ticks, S_RW, 0, 255, get_ticks, set_ticks); | |
986 | ||
987 | static const struct ide_devset *idefloppy_settings[] = { | |
988 | &ide_devset_bios_cyl, | |
989 | &ide_devset_bios_head, | |
990 | &ide_devset_bios_sect, | |
991 | &ide_devset_ticks, | |
992 | NULL | |
993 | }; | |
7662d046 | 994 | #endif |
1da177e4 | 995 | |
0571c7a4 | 996 | static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy) |
1da177e4 | 997 | { |
4dde4492 | 998 | u16 *id = drive->id; |
3ad6776c | 999 | u8 gcw[2]; |
1da177e4 | 1000 | |
4dde4492 | 1001 | *((u16 *)&gcw) = id[ATA_ID_CONFIG]; |
1da177e4 | 1002 | floppy->pc = floppy->pc_stack; |
2207fa5a | 1003 | drive->pc_callback = ide_floppy_callback; |
3ad6776c BP |
1004 | |
1005 | if (((gcw[0] & 0x60) >> 5) == 1) | |
ea68d270 | 1006 | drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT; |
1da177e4 | 1007 | /* |
0571c7a4 BP |
1008 | * We used to check revisions here. At this point however I'm giving up. |
1009 | * Just assume they are all broken, its easier. | |
1da177e4 | 1010 | * |
0571c7a4 BP |
1011 | * The actual reason for the workarounds was likely a driver bug after |
1012 | * all rather than a firmware bug, and the workaround below used to hide | |
1013 | * it. It should be fixed as of version 1.9, but to be on the safe side | |
1014 | * we'll leave the limitation below for the 2.2.x tree. | |
1da177e4 | 1015 | */ |
4dde4492 | 1016 | if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) { |
ea68d270 | 1017 | drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE; |
1da177e4 LT |
1018 | /* This value will be visible in the /proc/ide/hdx/settings */ |
1019 | floppy->ticks = IDEFLOPPY_TICKS_DELAY; | |
1020 | blk_queue_max_sectors(drive->queue, 64); | |
1021 | } | |
1022 | ||
1023 | /* | |
0571c7a4 BP |
1024 | * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes |
1025 | * nasty clicking noises without it, so please don't remove this. | |
1026 | */ | |
4dde4492 | 1027 | if (strncmp((char *)&id[ATA_ID_PROD], "IOMEGA Clik!", 11) == 0) { |
1da177e4 | 1028 | blk_queue_max_sectors(drive->queue, 64); |
ea68d270 | 1029 | drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE; |
1da177e4 LT |
1030 | } |
1031 | ||
194ec0c0 | 1032 | (void) ide_floppy_get_capacity(drive); |
1e874f44 BZ |
1033 | |
1034 | ide_proc_register_driver(drive, floppy->driver); | |
1da177e4 LT |
1035 | } |
1036 | ||
4031bbe4 | 1037 | static void ide_floppy_remove(ide_drive_t *drive) |
1da177e4 LT |
1038 | { |
1039 | idefloppy_floppy_t *floppy = drive->driver_data; | |
1040 | struct gendisk *g = floppy->disk; | |
1041 | ||
7662d046 | 1042 | ide_proc_unregister_driver(drive, floppy->driver); |
1da177e4 LT |
1043 | |
1044 | del_gendisk(g); | |
1045 | ||
1046 | ide_floppy_put(floppy); | |
1da177e4 LT |
1047 | } |
1048 | ||
9a24b63d | 1049 | static void idefloppy_cleanup_obj(struct kref *kref) |
1da177e4 LT |
1050 | { |
1051 | struct ide_floppy_obj *floppy = to_ide_floppy(kref); | |
1052 | ide_drive_t *drive = floppy->drive; | |
1053 | struct gendisk *g = floppy->disk; | |
1054 | ||
1055 | drive->driver_data = NULL; | |
1056 | g->private_data = NULL; | |
1057 | put_disk(g); | |
1058 | kfree(floppy); | |
1059 | } | |
1060 | ||
ecfd80e4 | 1061 | #ifdef CONFIG_IDE_PROC_FS |
0571c7a4 BP |
1062 | static int proc_idefloppy_read_capacity(char *page, char **start, off_t off, |
1063 | int count, int *eof, void *data) | |
1da177e4 LT |
1064 | { |
1065 | ide_drive_t*drive = (ide_drive_t *)data; | |
1066 | int len; | |
1067 | ||
0571c7a4 BP |
1068 | len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive)); |
1069 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | |
1da177e4 LT |
1070 | } |
1071 | ||
1072 | static ide_proc_entry_t idefloppy_proc[] = { | |
0571c7a4 BP |
1073 | { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL }, |
1074 | { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, | |
1da177e4 LT |
1075 | { NULL, 0, NULL, NULL } |
1076 | }; | |
ecfd80e4 | 1077 | #endif /* CONFIG_IDE_PROC_FS */ |
1da177e4 | 1078 | |
4031bbe4 | 1079 | static int ide_floppy_probe(ide_drive_t *); |
1da177e4 | 1080 | |
1da177e4 | 1081 | static ide_driver_t idefloppy_driver = { |
8604affd | 1082 | .gen_driver = { |
4ef3b8f4 | 1083 | .owner = THIS_MODULE, |
8604affd BZ |
1084 | .name = "ide-floppy", |
1085 | .bus = &ide_bus_type, | |
8604affd | 1086 | }, |
4031bbe4 RK |
1087 | .probe = ide_floppy_probe, |
1088 | .remove = ide_floppy_remove, | |
1da177e4 LT |
1089 | .version = IDEFLOPPY_VERSION, |
1090 | .media = ide_floppy, | |
1da177e4 | 1091 | .do_request = idefloppy_do_request, |
c2b2b293 | 1092 | .end_request = idefloppy_end_request, |
1da177e4 | 1093 | .error = __ide_error, |
7662d046 | 1094 | #ifdef CONFIG_IDE_PROC_FS |
1da177e4 | 1095 | .proc = idefloppy_proc, |
8185d5aa | 1096 | .settings = idefloppy_settings, |
7662d046 | 1097 | #endif |
1da177e4 LT |
1098 | }; |
1099 | ||
1100 | static int idefloppy_open(struct inode *inode, struct file *filp) | |
1101 | { | |
1102 | struct gendisk *disk = inode->i_bdev->bd_disk; | |
1103 | struct ide_floppy_obj *floppy; | |
1104 | ide_drive_t *drive; | |
8e555123 | 1105 | struct ide_atapi_pc pc; |
1da177e4 LT |
1106 | int ret = 0; |
1107 | ||
bcc77d9c | 1108 | debug_log("Reached %s\n", __func__); |
1da177e4 | 1109 | |
0571c7a4 BP |
1110 | floppy = ide_floppy_get(disk); |
1111 | if (!floppy) | |
1da177e4 LT |
1112 | return -ENXIO; |
1113 | ||
1114 | drive = floppy->drive; | |
1115 | ||
c94964a4 | 1116 | floppy->openers++; |
1da177e4 | 1117 | |
c94964a4 | 1118 | if (floppy->openers == 1) { |
ea68d270 | 1119 | drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; |
1da177e4 LT |
1120 | /* Just in case */ |
1121 | ||
c96a7df8 BP |
1122 | idefloppy_init_pc(&pc); |
1123 | pc.c[0] = GPCMD_TEST_UNIT_READY; | |
1124 | ||
1da177e4 LT |
1125 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
1126 | idefloppy_create_start_stop_cmd(&pc, 1); | |
1127 | (void) idefloppy_queue_pc_tail(drive, &pc); | |
1128 | } | |
1129 | ||
194ec0c0 | 1130 | if (ide_floppy_get_capacity(drive) |
1da177e4 LT |
1131 | && (filp->f_flags & O_NDELAY) == 0 |
1132 | /* | |
0571c7a4 BP |
1133 | * Allow O_NDELAY to open a drive without a disk, or with an |
1134 | * unreadable disk, so that we can get the format capacity | |
1135 | * of the drive or begin the format - Sam | |
1136 | */ | |
1da177e4 | 1137 | ) { |
1da177e4 LT |
1138 | ret = -EIO; |
1139 | goto out_put_floppy; | |
1140 | } | |
1141 | ||
1142 | if (floppy->wp && (filp->f_mode & 2)) { | |
1da177e4 LT |
1143 | ret = -EROFS; |
1144 | goto out_put_floppy; | |
1145 | } | |
ea68d270 | 1146 | drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED; |
1da177e4 | 1147 | /* IOMEGA Clik! drives do not support lock/unlock commands */ |
ea68d270 | 1148 | if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) { |
1da177e4 LT |
1149 | idefloppy_create_prevent_cmd(&pc, 1); |
1150 | (void) idefloppy_queue_pc_tail(drive, &pc); | |
1151 | } | |
1152 | check_disk_change(inode->i_bdev); | |
ea68d270 | 1153 | } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) { |
1da177e4 LT |
1154 | ret = -EBUSY; |
1155 | goto out_put_floppy; | |
1156 | } | |
1157 | return 0; | |
1158 | ||
1159 | out_put_floppy: | |
c94964a4 | 1160 | floppy->openers--; |
1da177e4 LT |
1161 | ide_floppy_put(floppy); |
1162 | return ret; | |
1163 | } | |
1164 | ||
1165 | static int idefloppy_release(struct inode *inode, struct file *filp) | |
1166 | { | |
1167 | struct gendisk *disk = inode->i_bdev->bd_disk; | |
1168 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); | |
1169 | ide_drive_t *drive = floppy->drive; | |
8e555123 | 1170 | struct ide_atapi_pc pc; |
bcc77d9c BP |
1171 | |
1172 | debug_log("Reached %s\n", __func__); | |
1da177e4 | 1173 | |
c94964a4 | 1174 | if (floppy->openers == 1) { |
1da177e4 | 1175 | /* IOMEGA Clik! drives do not support lock/unlock commands */ |
ea68d270 | 1176 | if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) { |
1da177e4 LT |
1177 | idefloppy_create_prevent_cmd(&pc, 0); |
1178 | (void) idefloppy_queue_pc_tail(drive, &pc); | |
1179 | } | |
1180 | ||
ea68d270 | 1181 | drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; |
1da177e4 | 1182 | } |
c94964a4 BZ |
1183 | |
1184 | floppy->openers--; | |
1da177e4 LT |
1185 | |
1186 | ide_floppy_put(floppy); | |
1187 | ||
1188 | return 0; | |
1189 | } | |
1190 | ||
a885c8c4 CH |
1191 | static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
1192 | { | |
1193 | struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); | |
1194 | ide_drive_t *drive = floppy->drive; | |
1195 | ||
1196 | geo->heads = drive->bios_head; | |
1197 | geo->sectors = drive->bios_sect; | |
1198 | geo->cylinders = (u16)drive->bios_cyl; /* truncate */ | |
1199 | return 0; | |
1200 | } | |
1201 | ||
ea68d270 BP |
1202 | static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc, |
1203 | unsigned long arg, unsigned int cmd) | |
20bf7bda | 1204 | { |
ea68d270 BP |
1205 | idefloppy_floppy_t *floppy = drive->driver_data; |
1206 | ||
20bf7bda BP |
1207 | if (floppy->openers > 1) |
1208 | return -EBUSY; | |
1209 | ||
1210 | /* The IOMEGA Clik! Drive doesn't support this command - | |
1211 | * no room for an eject mechanism */ | |
ea68d270 | 1212 | if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) { |
20bf7bda BP |
1213 | int prevent = arg ? 1 : 0; |
1214 | ||
1215 | if (cmd == CDROMEJECT) | |
1216 | prevent = 0; | |
1217 | ||
1218 | idefloppy_create_prevent_cmd(pc, prevent); | |
1219 | (void) idefloppy_queue_pc_tail(floppy->drive, pc); | |
1220 | } | |
1221 | ||
1222 | if (cmd == CDROMEJECT) { | |
1223 | idefloppy_create_start_stop_cmd(pc, 2); | |
1224 | (void) idefloppy_queue_pc_tail(floppy->drive, pc); | |
1225 | } | |
1226 | ||
1227 | return 0; | |
1228 | } | |
1229 | ||
1230 | static int ide_floppy_format_unit(idefloppy_floppy_t *floppy, | |
1231 | int __user *arg) | |
1232 | { | |
8e555123 | 1233 | struct ide_atapi_pc pc; |
ea68d270 BP |
1234 | ide_drive_t *drive = floppy->drive; |
1235 | int blocks, length, flags, err = 0; | |
20bf7bda BP |
1236 | |
1237 | if (floppy->openers > 1) { | |
1238 | /* Don't format if someone is using the disk */ | |
ea68d270 | 1239 | drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; |
20bf7bda BP |
1240 | return -EBUSY; |
1241 | } | |
1242 | ||
ea68d270 | 1243 | drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS; |
20bf7bda BP |
1244 | |
1245 | /* | |
1246 | * Send ATAPI_FORMAT_UNIT to the drive. | |
1247 | * | |
1248 | * Userland gives us the following structure: | |
1249 | * | |
1250 | * struct idefloppy_format_command { | |
1251 | * int nblocks; | |
1252 | * int blocksize; | |
1253 | * int flags; | |
1254 | * } ; | |
1255 | * | |
1256 | * flags is a bitmask, currently, the only defined flag is: | |
1257 | * | |
1258 | * 0x01 - verify media after format. | |
1259 | */ | |
1260 | if (get_user(blocks, arg) || | |
1261 | get_user(length, arg+1) || | |
1262 | get_user(flags, arg+2)) { | |
1263 | err = -EFAULT; | |
1264 | goto out; | |
1265 | } | |
1266 | ||
ea68d270 | 1267 | (void) idefloppy_get_sfrp_bit(drive); |
20bf7bda BP |
1268 | idefloppy_create_format_unit_cmd(&pc, blocks, length, flags); |
1269 | ||
ea68d270 | 1270 | if (idefloppy_queue_pc_tail(drive, &pc)) |
20bf7bda BP |
1271 | err = -EIO; |
1272 | ||
1273 | out: | |
1274 | if (err) | |
ea68d270 | 1275 | drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; |
20bf7bda BP |
1276 | return err; |
1277 | } | |
1278 | ||
1279 | ||
1da177e4 LT |
1280 | static int idefloppy_ioctl(struct inode *inode, struct file *file, |
1281 | unsigned int cmd, unsigned long arg) | |
1282 | { | |
1283 | struct block_device *bdev = inode->i_bdev; | |
1284 | struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); | |
1285 | ide_drive_t *drive = floppy->drive; | |
8e555123 | 1286 | struct ide_atapi_pc pc; |
1da177e4 | 1287 | void __user *argp = (void __user *)arg; |
07203f64 | 1288 | int err; |
1da177e4 LT |
1289 | |
1290 | switch (cmd) { | |
1291 | case CDROMEJECT: | |
1da177e4 LT |
1292 | /* fall through */ |
1293 | case CDROM_LOCKDOOR: | |
ea68d270 | 1294 | return ide_floppy_lockdoor(drive, &pc, arg, cmd); |
1da177e4 LT |
1295 | case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: |
1296 | return 0; | |
1297 | case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: | |
194ec0c0 | 1298 | return ide_floppy_get_format_capacities(drive, argp); |
1da177e4 | 1299 | case IDEFLOPPY_IOCTL_FORMAT_START: |
1da177e4 LT |
1300 | if (!(file->f_mode & 2)) |
1301 | return -EPERM; | |
1302 | ||
20bf7bda | 1303 | return ide_floppy_format_unit(floppy, (int __user *)arg); |
1da177e4 LT |
1304 | case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: |
1305 | return idefloppy_get_format_progress(drive, argp); | |
1306 | } | |
89636af2 BZ |
1307 | |
1308 | /* | |
1309 | * skip SCSI_IOCTL_SEND_COMMAND (deprecated) | |
1310 | * and CDROM_SEND_PACKET (legacy) ioctls | |
1311 | */ | |
1312 | if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) | |
1313 | err = scsi_cmd_ioctl(file, bdev->bd_disk->queue, | |
1314 | bdev->bd_disk, cmd, argp); | |
1315 | else | |
1316 | err = -ENOTTY; | |
1317 | ||
1318 | if (err == -ENOTTY) | |
1319 | err = generic_ide_ioctl(drive, file, bdev, cmd, arg); | |
1320 | ||
1321 | return err; | |
1da177e4 LT |
1322 | } |
1323 | ||
1324 | static int idefloppy_media_changed(struct gendisk *disk) | |
1325 | { | |
1326 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); | |
1327 | ide_drive_t *drive = floppy->drive; | |
6e5fa7b8 | 1328 | int ret; |
1da177e4 LT |
1329 | |
1330 | /* do not scan partitions twice if this is a removable device */ | |
1331 | if (drive->attach) { | |
1332 | drive->attach = 0; | |
1333 | return 0; | |
1334 | } | |
ea68d270 BP |
1335 | ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED); |
1336 | drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED; | |
6e5fa7b8 | 1337 | return ret; |
1da177e4 LT |
1338 | } |
1339 | ||
1340 | static int idefloppy_revalidate_disk(struct gendisk *disk) | |
1341 | { | |
1342 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); | |
1343 | set_capacity(disk, idefloppy_capacity(floppy->drive)); | |
1344 | return 0; | |
1345 | } | |
1346 | ||
1347 | static struct block_device_operations idefloppy_ops = { | |
52d3ccf7 PC |
1348 | .owner = THIS_MODULE, |
1349 | .open = idefloppy_open, | |
1350 | .release = idefloppy_release, | |
1351 | .ioctl = idefloppy_ioctl, | |
1352 | .getgeo = idefloppy_getgeo, | |
1353 | .media_changed = idefloppy_media_changed, | |
1354 | .revalidate_disk = idefloppy_revalidate_disk | |
1da177e4 LT |
1355 | }; |
1356 | ||
4031bbe4 | 1357 | static int ide_floppy_probe(ide_drive_t *drive) |
1da177e4 LT |
1358 | { |
1359 | idefloppy_floppy_t *floppy; | |
1360 | struct gendisk *g; | |
1361 | ||
1362 | if (!strstr("ide-floppy", drive->driver_req)) | |
1363 | goto failed; | |
2a924662 | 1364 | |
1da177e4 LT |
1365 | if (drive->media != ide_floppy) |
1366 | goto failed; | |
2a924662 | 1367 | |
51509eec | 1368 | if (!ide_check_atapi_device(drive, DRV_NAME)) { |
0571c7a4 BP |
1369 | printk(KERN_ERR "ide-floppy: %s: not supported by this version" |
1370 | " of ide-floppy\n", drive->name); | |
1da177e4 LT |
1371 | goto failed; |
1372 | } | |
0571c7a4 BP |
1373 | floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL); |
1374 | if (!floppy) { | |
1375 | printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy" | |
1376 | " structure\n", drive->name); | |
1da177e4 LT |
1377 | goto failed; |
1378 | } | |
1379 | ||
1380 | g = alloc_disk(1 << PARTN_BITS); | |
1381 | if (!g) | |
1382 | goto out_free_floppy; | |
1383 | ||
1384 | ide_init_disk(g, drive); | |
1385 | ||
1da177e4 LT |
1386 | kref_init(&floppy->kref); |
1387 | ||
1388 | floppy->drive = drive; | |
1389 | floppy->driver = &idefloppy_driver; | |
1390 | floppy->disk = g; | |
1391 | ||
1392 | g->private_data = &floppy->driver; | |
1393 | ||
1394 | drive->driver_data = floppy; | |
1395 | ||
0571c7a4 | 1396 | idefloppy_setup(drive, floppy); |
8604affd | 1397 | |
1da177e4 LT |
1398 | g->minors = 1 << PARTN_BITS; |
1399 | g->driverfs_dev = &drive->gendev; | |
1da177e4 LT |
1400 | g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; |
1401 | g->fops = &idefloppy_ops; | |
1402 | drive->attach = 1; | |
1403 | add_disk(g); | |
1404 | return 0; | |
1405 | ||
1da177e4 LT |
1406 | out_free_floppy: |
1407 | kfree(floppy); | |
1408 | failed: | |
8604affd | 1409 | return -ENODEV; |
1da177e4 LT |
1410 | } |
1411 | ||
0571c7a4 | 1412 | static void __exit idefloppy_exit(void) |
1da177e4 | 1413 | { |
8604affd | 1414 | driver_unregister(&idefloppy_driver.gen_driver); |
1da177e4 LT |
1415 | } |
1416 | ||
17514e8a | 1417 | static int __init idefloppy_init(void) |
1da177e4 LT |
1418 | { |
1419 | printk("ide-floppy driver " IDEFLOPPY_VERSION "\n"); | |
8604affd | 1420 | return driver_register(&idefloppy_driver.gen_driver); |
1da177e4 LT |
1421 | } |
1422 | ||
263756ec | 1423 | MODULE_ALIAS("ide:*m-floppy*"); |
1da177e4 LT |
1424 | module_init(idefloppy_init); |
1425 | module_exit(idefloppy_exit); | |
1426 | MODULE_LICENSE("GPL"); | |
0571c7a4 BP |
1427 | MODULE_DESCRIPTION("ATAPI FLOPPY Driver"); |
1428 |