aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-floppy.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/ide-floppy.c')
-rw-r--r--drivers/ide/ide-floppy.c668
1 files changed, 109 insertions, 559 deletions
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index e9034c0125f3..d36f155470a4 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -15,6 +15,8 @@
15 * Documentation/ide/ChangeLog.ide-floppy.1996-2002 15 * Documentation/ide/ChangeLog.ide-floppy.1996-2002
16 */ 16 */
17 17
18#define DRV_NAME "ide-floppy"
19
18#define IDEFLOPPY_VERSION "1.00" 20#define IDEFLOPPY_VERSION "1.00"
19 21
20#include <linux/module.h> 22#include <linux/module.h>
@@ -31,8 +33,10 @@
31#include <linux/slab.h> 33#include <linux/slab.h>
32#include <linux/cdrom.h> 34#include <linux/cdrom.h>
33#include <linux/ide.h> 35#include <linux/ide.h>
36#include <linux/hdreg.h>
34#include <linux/bitops.h> 37#include <linux/bitops.h>
35#include <linux/mutex.h> 38#include <linux/mutex.h>
39#include <linux/scatterlist.h>
36 40
37#include <scsi/scsi_ioctl.h> 41#include <scsi/scsi_ioctl.h>
38 42
@@ -42,6 +46,8 @@
42#include <linux/io.h> 46#include <linux/io.h>
43#include <asm/unaligned.h> 47#include <asm/unaligned.h>
44 48
49#include "ide-floppy.h"
50
45/* define to see debug info */ 51/* define to see debug info */
46#define IDEFLOPPY_DEBUG_LOG 0 52#define IDEFLOPPY_DEBUG_LOG 0
47 53
@@ -55,102 +61,23 @@
55#define debug_log(fmt, args...) do {} while (0) 61#define debug_log(fmt, args...) do {} while (0)
56#endif 62#endif
57 63
58
59/* Some drives require a longer irq timeout. */
60#define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
61
62/* 64/*
63 * After each failed packet command we issue a request sense command and retry 65 * After each failed packet command we issue a request sense command and retry
64 * the packet command IDEFLOPPY_MAX_PC_RETRIES times. 66 * the packet command IDEFLOPPY_MAX_PC_RETRIES times.
65 */ 67 */
66#define IDEFLOPPY_MAX_PC_RETRIES 3 68#define IDEFLOPPY_MAX_PC_RETRIES 3
67 69
68/*
69 * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
70 * bytes.
71 */
72#define IDEFLOPPY_PC_BUFFER_SIZE 256
73
74/*
75 * In various places in the driver, we need to allocate storage for packet
76 * commands and requests, which will remain valid while we leave the driver to
77 * wait for an interrupt or a timeout event.
78 */
79#define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
80
81/* format capacities descriptor codes */ 70/* format capacities descriptor codes */
82#define CAPACITY_INVALID 0x00 71#define CAPACITY_INVALID 0x00
83#define CAPACITY_UNFORMATTED 0x01 72#define CAPACITY_UNFORMATTED 0x01
84#define CAPACITY_CURRENT 0x02 73#define CAPACITY_CURRENT 0x02
85#define CAPACITY_NO_CARTRIDGE 0x03 74#define CAPACITY_NO_CARTRIDGE 0x03
86 75
87/*
88 * Most of our global data which we need to save even as we leave the driver
89 * due to an interrupt or a timer event is stored in a variable of type
90 * idefloppy_floppy_t, defined below.
91 */
92typedef struct ide_floppy_obj {
93 ide_drive_t *drive;
94 ide_driver_t *driver;
95 struct gendisk *disk;
96 struct kref kref;
97 unsigned int openers; /* protected by BKL for now */
98
99 /* Current packet command */
100 struct ide_atapi_pc *pc;
101 /* Last failed packet command */
102 struct ide_atapi_pc *failed_pc;
103 /* Packet command stack */
104 struct ide_atapi_pc pc_stack[IDEFLOPPY_PC_STACK];
105 /* Next free packet command storage space */
106 int pc_stack_index;
107 struct request rq_stack[IDEFLOPPY_PC_STACK];
108 /* We implement a circular array */
109 int rq_stack_index;
110
111 /* Last error information */
112 u8 sense_key, asc, ascq;
113 /* delay this long before sending packet command */
114 u8 ticks;
115 int progress_indication;
116
117 /* Device information */
118 /* Current format */
119 int blocks, block_size, bs_factor;
120 /* Last format capacity descriptor */
121 u8 cap_desc[8];
122 /* Copy of the flexible disk page */
123 u8 flexible_disk_page[32];
124 /* Write protect */
125 int wp;
126 /* Supports format progress report */
127 int srfp;
128} idefloppy_floppy_t;
129
130#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */ 76#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
131 77
132/* Defines for the MODE SENSE command */
133#define MODE_SENSE_CURRENT 0x00
134#define MODE_SENSE_CHANGEABLE 0x01
135#define MODE_SENSE_DEFAULT 0x02
136#define MODE_SENSE_SAVED 0x03
137
138/* IOCTLs used in low-level formatting. */
139#define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
140#define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
141#define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
142#define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
143
144/* Error code returned in rq->errors to the higher part of the driver. */ 78/* Error code returned in rq->errors to the higher part of the driver. */
145#define IDEFLOPPY_ERROR_GENERAL 101 79#define IDEFLOPPY_ERROR_GENERAL 101
146 80
147/*
148 * Pages of the SELECT SENSE / MODE SENSE packet commands.
149 * See SFF-8070i spec.
150 */
151#define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
152#define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
153
154static DEFINE_MUTEX(idefloppy_ref_mutex); 81static DEFINE_MUTEX(idefloppy_ref_mutex);
155 82
156#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref) 83#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
@@ -219,44 +146,6 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
219 return 0; 146 return 0;
220} 147}
221 148
222static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
223 unsigned int bcount, int direction)
224{
225 ide_hwif_t *hwif = drive->hwif;
226 struct request *rq = pc->rq;
227 struct req_iterator iter;
228 struct bio_vec *bvec;
229 unsigned long flags;
230 int count, done = 0;
231 char *data;
232
233 rq_for_each_segment(bvec, rq, iter) {
234 if (!bcount)
235 break;
236
237 count = min(bvec->bv_len, bcount);
238
239 data = bvec_kmap_irq(bvec, &flags);
240 if (direction)
241 hwif->tp_ops->output_data(drive, NULL, data, count);
242 else
243 hwif->tp_ops->input_data(drive, NULL, data, count);
244 bvec_kunmap_irq(data, &flags);
245
246 bcount -= count;
247 pc->b_count += count;
248 done += count;
249 }
250
251 idefloppy_end_request(drive, 1, done >> 9);
252
253 if (bcount) {
254 printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
255 drive->name, __func__, bcount);
256 ide_pad_transfer(drive, direction, bcount);
257 }
258}
259
260static void idefloppy_update_buffers(ide_drive_t *drive, 149static void idefloppy_update_buffers(ide_drive_t *drive,
261 struct ide_atapi_pc *pc) 150 struct ide_atapi_pc *pc)
262{ 151{
@@ -267,43 +156,6 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
267 idefloppy_end_request(drive, 1, 0); 156 idefloppy_end_request(drive, 1, 0);
268} 157}
269 158
270/*
271 * Generate a new packet command request in front of the request queue, before
272 * the current request so that it will be processed immediately, on the next
273 * pass through the driver.
274 */
275static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
276 struct request *rq)
277{
278 struct ide_floppy_obj *floppy = drive->driver_data;
279
280 blk_rq_init(NULL, rq);
281 rq->buffer = (char *) pc;
282 rq->cmd_type = REQ_TYPE_SPECIAL;
283 rq->cmd_flags |= REQ_PREEMPT;
284 rq->rq_disk = floppy->disk;
285 memcpy(rq->cmd, pc->c, 12);
286 ide_do_drive_cmd(drive, rq);
287}
288
289static struct ide_atapi_pc *idefloppy_next_pc_storage(ide_drive_t *drive)
290{
291 idefloppy_floppy_t *floppy = drive->driver_data;
292
293 if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
294 floppy->pc_stack_index = 0;
295 return (&floppy->pc_stack[floppy->pc_stack_index++]);
296}
297
298static struct request *idefloppy_next_rq_storage(ide_drive_t *drive)
299{
300 idefloppy_floppy_t *floppy = drive->driver_data;
301
302 if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK)
303 floppy->rq_stack_index = 0;
304 return (&floppy->rq_stack[floppy->rq_stack_index++]);
305}
306
307static void ide_floppy_callback(ide_drive_t *drive) 159static void ide_floppy_callback(ide_drive_t *drive)
308{ 160{
309 idefloppy_floppy_t *floppy = drive->driver_data; 161 idefloppy_floppy_t *floppy = drive->driver_data;
@@ -341,16 +193,9 @@ static void ide_floppy_callback(ide_drive_t *drive)
341 idefloppy_end_request(drive, uptodate, 0); 193 idefloppy_end_request(drive, uptodate, 0);
342} 194}
343 195
344static void idefloppy_init_pc(struct ide_atapi_pc *pc) 196void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
345{
346 memset(pc, 0, sizeof(*pc));
347 pc->buf = pc->pc_buf;
348 pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE;
349}
350
351static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
352{ 197{
353 idefloppy_init_pc(pc); 198 ide_init_pc(pc);
354 pc->c[0] = GPCMD_REQUEST_SENSE; 199 pc->c[0] = GPCMD_REQUEST_SENSE;
355 pc->c[4] = 255; 200 pc->c[4] = 255;
356 pc->req_xfer = 18; 201 pc->req_xfer = 18;
@@ -362,14 +207,13 @@ static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
362 */ 207 */
363static void idefloppy_retry_pc(ide_drive_t *drive) 208static void idefloppy_retry_pc(ide_drive_t *drive)
364{ 209{
365 struct ide_atapi_pc *pc; 210 struct ide_floppy_obj *floppy = drive->driver_data;
366 struct request *rq; 211 struct request *rq = &floppy->request_sense_rq;
212 struct ide_atapi_pc *pc = &floppy->request_sense_pc;
367 213
368 (void)ide_read_error(drive); 214 (void)ide_read_error(drive);
369 pc = idefloppy_next_pc_storage(drive); 215 ide_floppy_create_request_sense_cmd(pc);
370 rq = idefloppy_next_rq_storage(drive); 216 ide_queue_pc_head(drive, floppy->disk, pc, rq);
371 idefloppy_create_request_sense_cmd(pc);
372 idefloppy_queue_pc_head(drive, pc, rq);
373} 217}
374 218
375/* The usual interrupt handler called during a packet command. */ 219/* The usual interrupt handler called during a packet command. */
@@ -378,8 +222,8 @@ static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
378 idefloppy_floppy_t *floppy = drive->driver_data; 222 idefloppy_floppy_t *floppy = drive->driver_data;
379 223
380 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr, 224 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
381 IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers, 225 WAIT_FLOPPY_CMD, NULL, idefloppy_update_buffers,
382 idefloppy_retry_pc, NULL, ide_floppy_io_buffers); 226 idefloppy_retry_pc, NULL, ide_io_buffers);
383} 227}
384 228
385/* 229/*
@@ -396,10 +240,9 @@ static int idefloppy_transfer_pc(ide_drive_t *drive)
396 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12); 240 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
397 241
398 /* Timeout for the packet command */ 242 /* Timeout for the packet command */
399 return IDEFLOPPY_WAIT_CMD; 243 return WAIT_FLOPPY_CMD;
400} 244}
401 245
402
403/* 246/*
404 * Called as an interrupt (or directly). When the device says it's ready for a 247 * Called as an interrupt (or directly). When the device says it's ready for a
405 * packet, we schedule the packet transfer to occur about 2-3 ticks later in 248 * packet, we schedule the packet transfer to occur about 2-3 ticks later in
@@ -424,7 +267,7 @@ static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
424 timeout = floppy->ticks; 267 timeout = floppy->ticks;
425 expiry = &idefloppy_transfer_pc; 268 expiry = &idefloppy_transfer_pc;
426 } else { 269 } else {
427 timeout = IDEFLOPPY_WAIT_CMD; 270 timeout = WAIT_FLOPPY_CMD;
428 expiry = NULL; 271 expiry = NULL;
429 } 272 }
430 273
@@ -474,58 +317,27 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
474 pc->retries++; 317 pc->retries++;
475 318
476 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer, 319 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer,
477 IDEFLOPPY_WAIT_CMD, NULL); 320 WAIT_FLOPPY_CMD, NULL);
478}
479
480static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent)
481{
482 debug_log("creating prevent removal command, prevent = %d\n", prevent);
483
484 idefloppy_init_pc(pc);
485 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
486 pc->c[4] = prevent;
487} 321}
488 322
489static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) 323void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
490{ 324{
491 idefloppy_init_pc(pc); 325 ide_init_pc(pc);
492 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES; 326 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
493 pc->c[7] = 255; 327 pc->c[7] = 255;
494 pc->c[8] = 255; 328 pc->c[8] = 255;
495 pc->req_xfer = 255; 329 pc->req_xfer = 255;
496} 330}
497 331
498static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
499 int l, int flags)
500{
501 idefloppy_init_pc(pc);
502 pc->c[0] = GPCMD_FORMAT_UNIT;
503 pc->c[1] = 0x17;
504
505 memset(pc->buf, 0, 12);
506 pc->buf[1] = 0xA2;
507 /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
508
509 if (flags & 1) /* Verify bit on... */
510 pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */
511 pc->buf[3] = 8;
512
513 put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4]));
514 put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8]));
515 pc->buf_size = 12;
516 pc->flags |= PC_FLAG_WRITING;
517}
518
519/* A mode sense command is used to "sense" floppy parameters. */ 332/* A mode sense command is used to "sense" floppy parameters. */
520static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, 333void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
521 u8 page_code, u8 type)
522{ 334{
523 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */ 335 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
524 336
525 idefloppy_init_pc(pc); 337 ide_init_pc(pc);
526 pc->c[0] = GPCMD_MODE_SENSE_10; 338 pc->c[0] = GPCMD_MODE_SENSE_10;
527 pc->c[1] = 0; 339 pc->c[1] = 0;
528 pc->c[2] = page_code + (type << 6); 340 pc->c[2] = page_code;
529 341
530 switch (page_code) { 342 switch (page_code) {
531 case IDEFLOPPY_CAPABILITIES_PAGE: 343 case IDEFLOPPY_CAPABILITIES_PAGE:
@@ -542,13 +354,6 @@ static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
542 pc->req_xfer = length; 354 pc->req_xfer = length;
543} 355}
544 356
545static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start)
546{
547 idefloppy_init_pc(pc);
548 pc->c[0] = GPCMD_START_STOP_UNIT;
549 pc->c[4] = start;
550}
551
552static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, 357static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
553 struct ide_atapi_pc *pc, struct request *rq, 358 struct ide_atapi_pc *pc, struct request *rq,
554 unsigned long sector) 359 unsigned long sector)
@@ -560,7 +365,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
560 debug_log("create_rw10_cmd: block == %d, blocks == %d\n", 365 debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
561 block, blocks); 366 block, blocks);
562 367
563 idefloppy_init_pc(pc); 368 ide_init_pc(pc);
564 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; 369 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
565 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]); 370 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
566 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]); 371 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
@@ -568,7 +373,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
568 memcpy(rq->cmd, pc->c, 12); 373 memcpy(rq->cmd, pc->c, 12);
569 374
570 pc->rq = rq; 375 pc->rq = rq;
571 pc->b_count = cmd == READ ? 0 : rq->bio->bi_size; 376 pc->b_count = 0;
572 if (rq->cmd_flags & REQ_RW) 377 if (rq->cmd_flags & REQ_RW)
573 pc->flags |= PC_FLAG_WRITING; 378 pc->flags |= PC_FLAG_WRITING;
574 pc->buf = NULL; 379 pc->buf = NULL;
@@ -579,10 +384,10 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
579static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, 384static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
580 struct ide_atapi_pc *pc, struct request *rq) 385 struct ide_atapi_pc *pc, struct request *rq)
581{ 386{
582 idefloppy_init_pc(pc); 387 ide_init_pc(pc);
583 memcpy(pc->c, rq->cmd, sizeof(pc->c)); 388 memcpy(pc->c, rq->cmd, sizeof(pc->c));
584 pc->rq = rq; 389 pc->rq = rq;
585 pc->b_count = rq->data_len; 390 pc->b_count = 0;
586 if (rq->data_len && rq_data_dir(rq) == WRITE) 391 if (rq->data_len && rq_data_dir(rq) == WRITE)
587 pc->flags |= PC_FLAG_WRITING; 392 pc->flags |= PC_FLAG_WRITING;
588 pc->buf = rq->data; 393 pc->buf = rq->data;
@@ -599,15 +404,17 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
599 struct request *rq, sector_t block_s) 404 struct request *rq, sector_t block_s)
600{ 405{
601 idefloppy_floppy_t *floppy = drive->driver_data; 406 idefloppy_floppy_t *floppy = drive->driver_data;
407 ide_hwif_t *hwif = drive->hwif;
602 struct ide_atapi_pc *pc; 408 struct ide_atapi_pc *pc;
603 unsigned long block = (unsigned long)block_s; 409 unsigned long block = (unsigned long)block_s;
604 410
605 debug_log("dev: %s, cmd_type: %x, errors: %d\n", 411 debug_log("%s: dev: %s, cmd: 0x%x, cmd_type: %x, errors: %d\n",
606 rq->rq_disk ? rq->rq_disk->disk_name : "?", 412 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
607 rq->cmd_type, rq->errors); 413 rq->cmd[0], rq->cmd_type, rq->errors);
608 debug_log("sector: %ld, nr_sectors: %ld, " 414
609 "current_nr_sectors: %d\n", (long)rq->sector, 415 debug_log("%s: sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",
610 rq->nr_sectors, rq->current_nr_sectors); 416 __func__, (long)rq->sector, rq->nr_sectors,
417 rq->current_nr_sectors);
611 418
612 if (rq->errors >= ERROR_MAX) { 419 if (rq->errors >= ERROR_MAX) {
613 if (floppy->failed_pc) 420 if (floppy->failed_pc)
@@ -626,12 +433,12 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
626 idefloppy_end_request(drive, 0, 0); 433 idefloppy_end_request(drive, 0, 0);
627 return ide_stopped; 434 return ide_stopped;
628 } 435 }
629 pc = idefloppy_next_pc_storage(drive); 436 pc = &floppy->queued_pc;
630 idefloppy_create_rw_cmd(floppy, pc, rq, block); 437 idefloppy_create_rw_cmd(floppy, pc, rq, block);
631 } else if (blk_special_request(rq)) { 438 } else if (blk_special_request(rq)) {
632 pc = (struct ide_atapi_pc *) rq->buffer; 439 pc = (struct ide_atapi_pc *) rq->buffer;
633 } else if (blk_pc_request(rq)) { 440 } else if (blk_pc_request(rq)) {
634 pc = idefloppy_next_pc_storage(drive); 441 pc = &floppy->queued_pc;
635 idefloppy_blockpc_cmd(floppy, pc, rq); 442 idefloppy_blockpc_cmd(floppy, pc, rq);
636 } else { 443 } else {
637 blk_dump_rq_flags(rq, 444 blk_dump_rq_flags(rq,
@@ -640,29 +447,15 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
640 return ide_stopped; 447 return ide_stopped;
641 } 448 }
642 449
643 pc->rq = rq; 450 ide_init_sg_cmd(drive, rq);
451 ide_map_sg(drive, rq);
644 452
645 return idefloppy_issue_pc(drive, pc); 453 pc->sg = hwif->sg_table;
646} 454 pc->sg_cnt = hwif->sg_nents;
647 455
648/* 456 pc->rq = rq;
649 * Add a special packet command request to the tail of the request queue,
650 * and wait for it to be serviced.
651 */
652static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
653{
654 struct ide_floppy_obj *floppy = drive->driver_data;
655 struct request *rq;
656 int error;
657
658 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
659 rq->buffer = (char *) pc;
660 rq->cmd_type = REQ_TYPE_SPECIAL;
661 memcpy(rq->cmd, pc->c, 12);
662 error = blk_execute_rq(drive->queue, floppy->disk, rq, 0);
663 blk_put_request(rq);
664 457
665 return error; 458 return idefloppy_issue_pc(drive, pc);
666} 459}
667 460
668/* 461/*
@@ -672,22 +465,28 @@ static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
672static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive) 465static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
673{ 466{
674 idefloppy_floppy_t *floppy = drive->driver_data; 467 idefloppy_floppy_t *floppy = drive->driver_data;
468 struct gendisk *disk = floppy->disk;
675 struct ide_atapi_pc pc; 469 struct ide_atapi_pc pc;
676 u8 *page; 470 u8 *page;
677 int capacity, lba_capacity; 471 int capacity, lba_capacity;
678 u16 transfer_rate, sector_size, cyls, rpm; 472 u16 transfer_rate, sector_size, cyls, rpm;
679 u8 heads, sectors; 473 u8 heads, sectors;
680 474
681 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, 475 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
682 MODE_SENSE_CURRENT);
683 476
684 if (idefloppy_queue_pc_tail(drive, &pc)) { 477 if (ide_queue_pc_tail(drive, disk, &pc)) {
685 printk(KERN_ERR "ide-floppy: Can't get flexible disk page" 478 printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
686 " parameters\n"); 479 " parameters\n");
687 return 1; 480 return 1;
688 } 481 }
689 floppy->wp = !!(pc.buf[3] & 0x80); 482
690 set_disk_ro(floppy->disk, floppy->wp); 483 if (pc.buf[3] & 0x80)
484 drive->atapi_flags |= IDE_AFLAG_WP;
485 else
486 drive->atapi_flags &= ~IDE_AFLAG_WP;
487
488 set_disk_ro(disk, !!(drive->atapi_flags & IDE_AFLAG_WP));
489
691 page = &pc.buf[8]; 490 page = &pc.buf[8];
692 491
693 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]); 492 transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]);
@@ -721,23 +520,6 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
721 return 0; 520 return 0;
722} 521}
723 522
724static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
725{
726 idefloppy_floppy_t *floppy = drive->driver_data;
727 struct ide_atapi_pc pc;
728
729 floppy->srfp = 0;
730 idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
731 MODE_SENSE_CURRENT);
732
733 pc.flags |= PC_FLAG_SUPPRESS_ERROR;
734 if (idefloppy_queue_pc_tail(drive, &pc))
735 return 1;
736
737 floppy->srfp = pc.buf[8 + 2] & 0x40;
738 return (0);
739}
740
741/* 523/*
742 * Determine if a media is present in the floppy drive, and if so, its LBA 524 * Determine if a media is present in the floppy drive, and if so, its LBA
743 * capacity. 525 * capacity.
@@ -745,6 +527,7 @@ static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
745static int ide_floppy_get_capacity(ide_drive_t *drive) 527static int ide_floppy_get_capacity(ide_drive_t *drive)
746{ 528{
747 idefloppy_floppy_t *floppy = drive->driver_data; 529 idefloppy_floppy_t *floppy = drive->driver_data;
530 struct gendisk *disk = floppy->disk;
748 struct ide_atapi_pc pc; 531 struct ide_atapi_pc pc;
749 u8 *cap_desc; 532 u8 *cap_desc;
750 u8 header_len, desc_cnt; 533 u8 header_len, desc_cnt;
@@ -756,8 +539,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
756 floppy->bs_factor = 1; 539 floppy->bs_factor = 1;
757 set_capacity(floppy->disk, 0); 540 set_capacity(floppy->disk, 0);
758 541
759 idefloppy_create_read_capacity_cmd(&pc); 542 ide_floppy_create_read_capacity_cmd(&pc);
760 if (idefloppy_queue_pc_tail(drive, &pc)) { 543 if (ide_queue_pc_tail(drive, disk, &pc)) {
761 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); 544 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
762 return 1; 545 return 1;
763 } 546 }
@@ -832,202 +615,55 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
832 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) 615 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
833 (void) ide_floppy_get_flexible_disk_page(drive); 616 (void) ide_floppy_get_flexible_disk_page(drive);
834 617
835 set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); 618 set_capacity(disk, floppy->blocks * floppy->bs_factor);
619
836 return rc; 620 return rc;
837} 621}
838 622
839/* 623static sector_t idefloppy_capacity(ide_drive_t *drive)
840 * Obtain the list of formattable capacities.
841 * Very similar to ide_floppy_get_capacity, except that we push the capacity
842 * descriptors to userland, instead of our own structures.
843 *
844 * Userland gives us the following structure:
845 *
846 * struct idefloppy_format_capacities {
847 * int nformats;
848 * struct {
849 * int nblocks;
850 * int blocksize;
851 * } formats[];
852 * };
853 *
854 * userland initializes nformats to the number of allocated formats[] records.
855 * On exit we set nformats to the number of records we've actually initialized.
856 */
857
858static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
859{ 624{
860 struct ide_atapi_pc pc; 625 idefloppy_floppy_t *floppy = drive->driver_data;
861 u8 header_len, desc_cnt; 626 unsigned long capacity = floppy->blocks * floppy->bs_factor;
862 int i, blocks, length, u_array_size, u_index;
863 int __user *argp;
864
865 if (get_user(u_array_size, arg))
866 return (-EFAULT);
867
868 if (u_array_size <= 0)
869 return (-EINVAL);
870
871 idefloppy_create_read_capacity_cmd(&pc);
872 if (idefloppy_queue_pc_tail(drive, &pc)) {
873 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
874 return (-EIO);
875 }
876 header_len = pc.buf[3];
877 desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
878
879 u_index = 0;
880 argp = arg + 1;
881
882 /*
883 * We always skip the first capacity descriptor. That's the current
884 * capacity. We are interested in the remaining descriptors, the
885 * formattable capacities.
886 */
887 for (i = 1; i < desc_cnt; i++) {
888 unsigned int desc_start = 4 + i*8;
889
890 if (u_index >= u_array_size)
891 break; /* User-supplied buffer too small */
892
893 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
894 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
895
896 if (put_user(blocks, argp))
897 return(-EFAULT);
898 ++argp;
899
900 if (put_user(length, argp))
901 return (-EFAULT);
902 ++argp;
903
904 ++u_index;
905 }
906 627
907 if (put_user(u_index, arg)) 628 return capacity;
908 return (-EFAULT);
909 return (0);
910} 629}
911 630
912/* 631#ifdef CONFIG_IDE_PROC_FS
913 * Get ATAPI_FORMAT_UNIT progress indication. 632ide_devset_rw_field(bios_cyl, bios_cyl);
914 * 633ide_devset_rw_field(bios_head, bios_head);
915 * Userland gives a pointer to an int. The int is set to a progress 634ide_devset_rw_field(bios_sect, bios_sect);
916 * indicator 0-65536, with 65536=100%.
917 *
918 * If the drive does not support format progress indication, we just check
919 * the dsc bit, and return either 0 or 65536.
920 */
921 635
922static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg) 636static int get_ticks(ide_drive_t *drive)
923{ 637{
924 idefloppy_floppy_t *floppy = drive->driver_data; 638 idefloppy_floppy_t *floppy = drive->driver_data;
925 struct ide_atapi_pc pc; 639 return floppy->ticks;
926 int progress_indication = 0x10000;
927
928 if (floppy->srfp) {
929 idefloppy_create_request_sense_cmd(&pc);
930 if (idefloppy_queue_pc_tail(drive, &pc))
931 return (-EIO);
932
933 if (floppy->sense_key == 2 &&
934 floppy->asc == 4 &&
935 floppy->ascq == 4)
936 progress_indication = floppy->progress_indication;
937
938 /* Else assume format_unit has finished, and we're at 0x10000 */
939 } else {
940 ide_hwif_t *hwif = drive->hwif;
941 unsigned long flags;
942 u8 stat;
943
944 local_irq_save(flags);
945 stat = hwif->tp_ops->read_status(hwif);
946 local_irq_restore(flags);
947
948 progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
949 }
950 if (put_user(progress_indication, arg))
951 return (-EFAULT);
952
953 return (0);
954} 640}
955 641
956static sector_t idefloppy_capacity(ide_drive_t *drive) 642static int set_ticks(ide_drive_t *drive, int arg)
957{ 643{
958 idefloppy_floppy_t *floppy = drive->driver_data; 644 idefloppy_floppy_t *floppy = drive->driver_data;
959 unsigned long capacity = floppy->blocks * floppy->bs_factor; 645 floppy->ticks = arg;
960
961 return capacity;
962}
963
964/*
965 * Check whether we can support a drive, based on the ATAPI IDENTIFY command
966 * results.
967 */
968static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id)
969{
970 u8 gcw[2];
971 u8 device_type, protocol, removable, drq_type, packet_size;
972
973 *((u16 *) &gcw) = id->config;
974
975 device_type = gcw[1] & 0x1F;
976 removable = (gcw[0] & 0x80) >> 7;
977 protocol = (gcw[1] & 0xC0) >> 6;
978 drq_type = (gcw[0] & 0x60) >> 5;
979 packet_size = gcw[0] & 0x03;
980
981#ifdef CONFIG_PPC
982 /* kludge for Apple PowerBook internal zip */
983 if (device_type == 5 &&
984 !strstr(id->model, "CD-ROM") && strstr(id->model, "ZIP"))
985 device_type = 0;
986#endif
987
988 if (protocol != 2)
989 printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n",
990 protocol);
991 else if (device_type != 0)
992 printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set "
993 "to floppy\n", device_type);
994 else if (!removable)
995 printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
996 else if (drq_type == 3)
997 printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not "
998 "supported\n", drq_type);
999 else if (packet_size != 0)
1000 printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 "
1001 "bytes\n", packet_size);
1002 else
1003 return 1;
1004 return 0; 646 return 0;
1005} 647}
1006 648
1007#ifdef CONFIG_IDE_PROC_FS 649IDE_DEVSET(ticks, DS_SYNC, get_ticks, set_ticks);
1008static void idefloppy_add_settings(ide_drive_t *drive)
1009{
1010 idefloppy_floppy_t *floppy = drive->driver_data;
1011 650
1012 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, 651static const struct ide_proc_devset idefloppy_settings[] = {
1013 &drive->bios_cyl, NULL); 652 IDE_PROC_DEVSET(bios_cyl, 0, 1023),
1014 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, 653 IDE_PROC_DEVSET(bios_head, 0, 255),
1015 &drive->bios_head, NULL); 654 IDE_PROC_DEVSET(bios_sect, 0, 63),
1016 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, 655 IDE_PROC_DEVSET(ticks, 0, 255),
1017 &drive->bios_sect, NULL); 656 { 0 },
1018 ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, 657};
1019 &floppy->ticks, NULL);
1020}
1021#else
1022static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
1023#endif 658#endif
1024 659
1025static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy) 660static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1026{ 661{
662 u16 *id = drive->id;
1027 u8 gcw[2]; 663 u8 gcw[2];
1028 664
1029 *((u16 *) &gcw) = drive->id->config; 665 *((u16 *)&gcw) = id[ATA_ID_CONFIG];
1030 floppy->pc = floppy->pc_stack; 666
1031 drive->pc_callback = ide_floppy_callback; 667 drive->pc_callback = ide_floppy_callback;
1032 668
1033 if (((gcw[0] & 0x60) >> 5) == 1) 669 if (((gcw[0] & 0x60) >> 5) == 1)
@@ -1041,7 +677,7 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1041 * it. It should be fixed as of version 1.9, but to be on the safe side 677 * it. It should be fixed as of version 1.9, but to be on the safe side
1042 * we'll leave the limitation below for the 2.2.x tree. 678 * we'll leave the limitation below for the 2.2.x tree.
1043 */ 679 */
1044 if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) { 680 if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) {
1045 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE; 681 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
1046 /* This value will be visible in the /proc/ide/hdx/settings */ 682 /* This value will be visible in the /proc/ide/hdx/settings */
1047 floppy->ticks = IDEFLOPPY_TICKS_DELAY; 683 floppy->ticks = IDEFLOPPY_TICKS_DELAY;
@@ -1052,13 +688,16 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
1052 * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes 688 * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes
1053 * nasty clicking noises without it, so please don't remove this. 689 * nasty clicking noises without it, so please don't remove this.
1054 */ 690 */
1055 if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) { 691 if (strncmp((char *)&id[ATA_ID_PROD], "IOMEGA Clik!", 11) == 0) {
1056 blk_queue_max_sectors(drive->queue, 64); 692 blk_queue_max_sectors(drive->queue, 64);
1057 drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE; 693 drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
694 /* IOMEGA Clik! drives do not support lock/unlock commands */
695 drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK;
1058 } 696 }
1059 697
1060 (void) ide_floppy_get_capacity(drive); 698 (void) ide_floppy_get_capacity(drive);
1061 idefloppy_add_settings(drive); 699
700 ide_proc_register_driver(drive, floppy->driver);
1062} 701}
1063 702
1064static void ide_floppy_remove(ide_drive_t *drive) 703static void ide_floppy_remove(ide_drive_t *drive)
@@ -1115,12 +754,12 @@ static ide_driver_t idefloppy_driver = {
1115 .remove = ide_floppy_remove, 754 .remove = ide_floppy_remove,
1116 .version = IDEFLOPPY_VERSION, 755 .version = IDEFLOPPY_VERSION,
1117 .media = ide_floppy, 756 .media = ide_floppy,
1118 .supports_dsc_overlap = 0,
1119 .do_request = idefloppy_do_request, 757 .do_request = idefloppy_do_request,
1120 .end_request = idefloppy_end_request, 758 .end_request = idefloppy_end_request,
1121 .error = __ide_error, 759 .error = __ide_error,
1122#ifdef CONFIG_IDE_PROC_FS 760#ifdef CONFIG_IDE_PROC_FS
1123 .proc = idefloppy_proc, 761 .proc = idefloppy_proc,
762 .settings = idefloppy_settings,
1124#endif 763#endif
1125}; 764};
1126 765
@@ -1129,7 +768,6 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1129 struct gendisk *disk = inode->i_bdev->bd_disk; 768 struct gendisk *disk = inode->i_bdev->bd_disk;
1130 struct ide_floppy_obj *floppy; 769 struct ide_floppy_obj *floppy;
1131 ide_drive_t *drive; 770 ide_drive_t *drive;
1132 struct ide_atapi_pc pc;
1133 int ret = 0; 771 int ret = 0;
1134 772
1135 debug_log("Reached %s\n", __func__); 773 debug_log("Reached %s\n", __func__);
@@ -1146,13 +784,8 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1146 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; 784 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1147 /* Just in case */ 785 /* Just in case */
1148 786
1149 idefloppy_init_pc(&pc); 787 if (ide_do_test_unit_ready(drive, disk))
1150 pc.c[0] = GPCMD_TEST_UNIT_READY; 788 ide_do_start_stop(drive, disk, 1);
1151
1152 if (idefloppy_queue_pc_tail(drive, &pc)) {
1153 idefloppy_create_start_stop_cmd(&pc, 1);
1154 (void) idefloppy_queue_pc_tail(drive, &pc);
1155 }
1156 789
1157 if (ide_floppy_get_capacity(drive) 790 if (ide_floppy_get_capacity(drive)
1158 && (filp->f_flags & O_NDELAY) == 0 791 && (filp->f_flags & O_NDELAY) == 0
@@ -1166,16 +799,13 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1166 goto out_put_floppy; 799 goto out_put_floppy;
1167 } 800 }
1168 801
1169 if (floppy->wp && (filp->f_mode & 2)) { 802 if ((drive->atapi_flags & IDE_AFLAG_WP) && (filp->f_mode & 2)) {
1170 ret = -EROFS; 803 ret = -EROFS;
1171 goto out_put_floppy; 804 goto out_put_floppy;
1172 } 805 }
806
1173 drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED; 807 drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
1174 /* IOMEGA Clik! drives do not support lock/unlock commands */ 808 ide_set_media_lock(drive, disk, 1);
1175 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1176 idefloppy_create_prevent_cmd(&pc, 1);
1177 (void) idefloppy_queue_pc_tail(drive, &pc);
1178 }
1179 check_disk_change(inode->i_bdev); 809 check_disk_change(inode->i_bdev);
1180 } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) { 810 } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
1181 ret = -EBUSY; 811 ret = -EBUSY;
@@ -1194,17 +824,11 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
1194 struct gendisk *disk = inode->i_bdev->bd_disk; 824 struct gendisk *disk = inode->i_bdev->bd_disk;
1195 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 825 struct ide_floppy_obj *floppy = ide_floppy_g(disk);
1196 ide_drive_t *drive = floppy->drive; 826 ide_drive_t *drive = floppy->drive;
1197 struct ide_atapi_pc pc;
1198 827
1199 debug_log("Reached %s\n", __func__); 828 debug_log("Reached %s\n", __func__);
1200 829
1201 if (floppy->openers == 1) { 830 if (floppy->openers == 1) {
1202 /* IOMEGA Clik! drives do not support lock/unlock commands */ 831 ide_set_media_lock(drive, disk, 0);
1203 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1204 idefloppy_create_prevent_cmd(&pc, 0);
1205 (void) idefloppy_queue_pc_tail(drive, &pc);
1206 }
1207
1208 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; 832 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1209 } 833 }
1210 834
@@ -1230,80 +854,20 @@ static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
1230 unsigned long arg, unsigned int cmd) 854 unsigned long arg, unsigned int cmd)
1231{ 855{
1232 idefloppy_floppy_t *floppy = drive->driver_data; 856 idefloppy_floppy_t *floppy = drive->driver_data;
857 struct gendisk *disk = floppy->disk;
858 int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
1233 859
1234 if (floppy->openers > 1) 860 if (floppy->openers > 1)
1235 return -EBUSY; 861 return -EBUSY;
1236 862
1237 /* The IOMEGA Clik! Drive doesn't support this command - 863 ide_set_media_lock(drive, disk, prevent);
1238 * no room for an eject mechanism */
1239 if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
1240 int prevent = arg ? 1 : 0;
1241
1242 if (cmd == CDROMEJECT)
1243 prevent = 0;
1244 864
1245 idefloppy_create_prevent_cmd(pc, prevent); 865 if (cmd == CDROMEJECT)
1246 (void) idefloppy_queue_pc_tail(floppy->drive, pc); 866 ide_do_start_stop(drive, disk, 2);
1247 }
1248
1249 if (cmd == CDROMEJECT) {
1250 idefloppy_create_start_stop_cmd(pc, 2);
1251 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1252 }
1253 867
1254 return 0; 868 return 0;
1255} 869}
1256 870
1257static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
1258 int __user *arg)
1259{
1260 struct ide_atapi_pc pc;
1261 ide_drive_t *drive = floppy->drive;
1262 int blocks, length, flags, err = 0;
1263
1264 if (floppy->openers > 1) {
1265 /* Don't format if someone is using the disk */
1266 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1267 return -EBUSY;
1268 }
1269
1270 drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS;
1271
1272 /*
1273 * Send ATAPI_FORMAT_UNIT to the drive.
1274 *
1275 * Userland gives us the following structure:
1276 *
1277 * struct idefloppy_format_command {
1278 * int nblocks;
1279 * int blocksize;
1280 * int flags;
1281 * } ;
1282 *
1283 * flags is a bitmask, currently, the only defined flag is:
1284 *
1285 * 0x01 - verify media after format.
1286 */
1287 if (get_user(blocks, arg) ||
1288 get_user(length, arg+1) ||
1289 get_user(flags, arg+2)) {
1290 err = -EFAULT;
1291 goto out;
1292 }
1293
1294 (void) idefloppy_get_sfrp_bit(drive);
1295 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1296
1297 if (idefloppy_queue_pc_tail(drive, &pc))
1298 err = -EIO;
1299
1300out:
1301 if (err)
1302 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1303 return err;
1304}
1305
1306
1307static int idefloppy_ioctl(struct inode *inode, struct file *file, 871static int idefloppy_ioctl(struct inode *inode, struct file *file,
1308 unsigned int cmd, unsigned long arg) 872 unsigned int cmd, unsigned long arg)
1309{ 873{
@@ -1314,23 +878,12 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
1314 void __user *argp = (void __user *)arg; 878 void __user *argp = (void __user *)arg;
1315 int err; 879 int err;
1316 880
1317 switch (cmd) { 881 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
1318 case CDROMEJECT:
1319 /* fall through */
1320 case CDROM_LOCKDOOR:
1321 return ide_floppy_lockdoor(drive, &pc, arg, cmd); 882 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
1322 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: 883
1323 return 0; 884 err = ide_floppy_format_ioctl(drive, file, cmd, argp);
1324 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: 885 if (err != -ENOTTY)
1325 return ide_floppy_get_format_capacities(drive, argp); 886 return err;
1326 case IDEFLOPPY_IOCTL_FORMAT_START:
1327 if (!(file->f_mode & 2))
1328 return -EPERM;
1329
1330 return ide_floppy_format_unit(floppy, (int __user *)arg);
1331 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1332 return idefloppy_get_format_progress(drive, argp);
1333 }
1334 887
1335 /* 888 /*
1336 * skip SCSI_IOCTL_SEND_COMMAND (deprecated) 889 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
@@ -1339,8 +892,6 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
1339 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) 892 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
1340 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue, 893 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
1341 bdev->bd_disk, cmd, argp); 894 bdev->bd_disk, cmd, argp);
1342 else
1343 err = -ENOTTY;
1344 895
1345 if (err == -ENOTTY) 896 if (err == -ENOTTY)
1346 err = generic_ide_ioctl(drive, file, bdev, cmd, arg); 897 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
@@ -1388,11 +939,11 @@ static int ide_floppy_probe(ide_drive_t *drive)
1388 939
1389 if (!strstr("ide-floppy", drive->driver_req)) 940 if (!strstr("ide-floppy", drive->driver_req))
1390 goto failed; 941 goto failed;
1391 if (!drive->present) 942
1392 goto failed;
1393 if (drive->media != ide_floppy) 943 if (drive->media != ide_floppy)
1394 goto failed; 944 goto failed;
1395 if (!idefloppy_identify_device(drive, drive->id)) { 945
946 if (!ide_check_atapi_device(drive, DRV_NAME)) {
1396 printk(KERN_ERR "ide-floppy: %s: not supported by this version" 947 printk(KERN_ERR "ide-floppy: %s: not supported by this version"
1397 " of ide-floppy\n", drive->name); 948 " of ide-floppy\n", drive->name);
1398 goto failed; 949 goto failed;
@@ -1410,8 +961,6 @@ static int ide_floppy_probe(ide_drive_t *drive)
1410 961
1411 ide_init_disk(g, drive); 962 ide_init_disk(g, drive);
1412 963
1413 ide_proc_register_driver(drive, &idefloppy_driver);
1414
1415 kref_init(&floppy->kref); 964 kref_init(&floppy->kref);
1416 965
1417 floppy->drive = drive; 966 floppy->drive = drive;
@@ -1450,6 +999,7 @@ static int __init idefloppy_init(void)
1450} 999}
1451 1000
1452MODULE_ALIAS("ide:*m-floppy*"); 1001MODULE_ALIAS("ide:*m-floppy*");
1002MODULE_ALIAS("ide-floppy");
1453module_init(idefloppy_init); 1003module_init(idefloppy_init);
1454module_exit(idefloppy_exit); 1004module_exit(idefloppy_exit);
1455MODULE_LICENSE("GPL"); 1005MODULE_LICENSE("GPL");