aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ide-scsi.c
diff options
context:
space:
mode:
authorBorislav Petkov <petkovbb@googlemail.com>2008-04-17 18:46:27 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-04-17 18:46:27 -0400
commit1c065787c0359fc3b438c1c0aa2fcfd514fef07a (patch)
tree0b06acf2d947099286baa9e23d2a752143f15b4a /drivers/scsi/ide-scsi.c
parent8e555123911cc912427bd25b52ebfb7b6c08e39a (diff)
ide-scsi: convert driver to using generic ide_atapi_pc
Signed-off-by: Borislav Petkov <petkovbb@gmail.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/scsi/ide-scsi.c')
-rw-r--r--drivers/scsi/ide-scsi.c133
1 files changed, 62 insertions, 71 deletions
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 7fea769cf291..5ec421c988d4 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -60,23 +60,6 @@
60 60
61#define IDESCSI_DEBUG_LOG 0 61#define IDESCSI_DEBUG_LOG 0
62 62
63typedef struct idescsi_pc_s {
64 u8 c[12]; /* Actual packet bytes */
65 int request_transfer; /* Bytes to transfer */
66 int actually_transferred; /* Bytes actually transferred */
67 int buffer_size; /* Size of our data buffer */
68 struct request *rq; /* The corresponding request */
69 u8 *buffer; /* Data buffer */
70 u8 *current_position; /* Pointer into the above buffer */
71 struct scatterlist *sg; /* Scatter gather table */
72 unsigned int sg_cnt; /* Number of entries in sg */
73 int b_count; /* Bytes transferred from current entry */
74 struct scsi_cmnd *scsi_cmd; /* SCSI command */
75 void (*done)(struct scsi_cmnd *); /* Scsi completion routine */
76 unsigned long flags; /* Status/Action flags */
77 unsigned long timeout; /* Command timeout */
78} idescsi_pc_t;
79
80/* 63/*
81 * Packet command status bits. 64 * Packet command status bits.
82 */ 65 */
@@ -101,14 +84,15 @@ typedef struct ide_scsi_obj {
101 struct gendisk *disk; 84 struct gendisk *disk;
102 struct Scsi_Host *host; 85 struct Scsi_Host *host;
103 86
104 idescsi_pc_t *pc; /* Current packet command */ 87 struct ide_atapi_pc *pc; /* Current packet command */
105 unsigned long flags; /* Status/Action flags */ 88 unsigned long flags; /* Status/Action flags */
106 unsigned long transform; /* SCSI cmd translation layer */ 89 unsigned long transform; /* SCSI cmd translation layer */
107 unsigned long log; /* log flags */ 90 unsigned long log; /* log flags */
108} idescsi_scsi_t; 91} idescsi_scsi_t;
109 92
110static DEFINE_MUTEX(idescsi_ref_mutex); 93static DEFINE_MUTEX(idescsi_ref_mutex);
111static int idescsi_nocd; /* Set by module param to skip cd */ 94/* Set by module param to skip cd */
95static int idescsi_nocd;
112 96
113#define ide_scsi_g(disk) \ 97#define ide_scsi_g(disk) \
114 container_of((disk)->private_data, struct ide_scsi_obj, driver) 98 container_of((disk)->private_data, struct ide_scsi_obj, driver)
@@ -155,7 +139,8 @@ static inline idescsi_scsi_t *drive_to_idescsi(ide_drive_t *ide_drive)
155/* 139/*
156 * PIO data transfer routines using the scatter gather table. 140 * PIO data transfer routines using the scatter gather table.
157 */ 141 */
158static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigned int bcount) 142static void idescsi_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
143 unsigned int bcount)
159{ 144{
160 int count; 145 int count;
161 char *buf; 146 char *buf;
@@ -192,7 +177,8 @@ static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigne
192 } 177 }
193} 178}
194 179
195static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigned int bcount) 180static void idescsi_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
181 unsigned int bcount)
196{ 182{
197 int count; 183 int count;
198 char *buf; 184 char *buf;
@@ -234,15 +220,16 @@ static void ide_scsi_hex_dump(u8 *data, int len)
234 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0); 220 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0);
235} 221}
236 222
237static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_command) 223static int idescsi_check_condition(ide_drive_t *drive,
224 struct request *failed_cmd)
238{ 225{
239 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 226 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
240 idescsi_pc_t *pc; 227 struct ide_atapi_pc *pc;
241 struct request *rq; 228 struct request *rq;
242 u8 *buf; 229 u8 *buf;
243 230
244 /* stuff a sense request in front of our current request */ 231 /* stuff a sense request in front of our current request */
245 pc = kzalloc(sizeof(idescsi_pc_t), GFP_ATOMIC); 232 pc = kzalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
246 rq = kmalloc(sizeof(struct request), GFP_ATOMIC); 233 rq = kmalloc(sizeof(struct request), GFP_ATOMIC);
247 buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC); 234 buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
248 if (!pc || !rq || !buf) { 235 if (!pc || !rq || !buf) {
@@ -254,14 +241,14 @@ static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_co
254 ide_init_drive_cmd(rq); 241 ide_init_drive_cmd(rq);
255 rq->special = (char *) pc; 242 rq->special = (char *) pc;
256 pc->rq = rq; 243 pc->rq = rq;
257 pc->buffer = buf; 244 pc->buf = buf;
258 pc->c[0] = REQUEST_SENSE; 245 pc->c[0] = REQUEST_SENSE;
259 pc->c[4] = pc->request_transfer = pc->buffer_size = SCSI_SENSE_BUFFERSIZE; 246 pc->c[4] = pc->req_xfer = pc->buf_size = SCSI_SENSE_BUFFERSIZE;
260 rq->cmd_type = REQ_TYPE_SENSE; 247 rq->cmd_type = REQ_TYPE_SENSE;
261 pc->timeout = jiffies + WAIT_READY; 248 pc->timeout = jiffies + WAIT_READY;
262 /* NOTE! Save the failed packet command in "rq->buffer" */ 249 /* NOTE! Save the failed packet command in "rq->buffer" */
263 rq->buffer = (void *) failed_command->special; 250 rq->buffer = (void *) failed_cmd->special;
264 pc->scsi_cmd = ((idescsi_pc_t *) failed_command->special)->scsi_cmd; 251 pc->scsi_cmd = ((struct ide_atapi_pc *) failed_cmd->special)->scsi_cmd;
265 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) { 252 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
266 printk ("ide-scsi: %s: queue cmd = ", drive->name); 253 printk ("ide-scsi: %s: queue cmd = ", drive->name);
267 ide_scsi_hex_dump(pc->c, 6); 254 ide_scsi_hex_dump(pc->c, 6);
@@ -294,7 +281,7 @@ idescsi_atapi_abort(ide_drive_t *drive, struct request *rq)
294{ 281{
295#if IDESCSI_DEBUG_LOG 282#if IDESCSI_DEBUG_LOG
296 printk(KERN_WARNING "idescsi_atapi_abort called for %lu\n", 283 printk(KERN_WARNING "idescsi_atapi_abort called for %lu\n",
297 ((idescsi_pc_t *) rq->special)->scsi_cmd->serial_number); 284 ((struct ide_atapi_pc *) rq->special)->scsi_cmd->serial_number);
298#endif 285#endif
299 rq->errors |= ERROR_MAX; 286 rq->errors |= ERROR_MAX;
300 287
@@ -307,7 +294,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
307{ 294{
308 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 295 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
309 struct request *rq = HWGROUP(drive)->rq; 296 struct request *rq = HWGROUP(drive)->rq;
310 idescsi_pc_t *pc = (idescsi_pc_t *) rq->special; 297 struct ide_atapi_pc *pc = (struct ide_atapi_pc *) rq->special;
311 int log = test_bit(IDESCSI_LOG_CMD, &scsi->log); 298 int log = test_bit(IDESCSI_LOG_CMD, &scsi->log);
312 struct Scsi_Host *host; 299 struct Scsi_Host *host;
313 int errors = rq->errors; 300 int errors = rq->errors;
@@ -319,13 +306,14 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
319 } 306 }
320 ide_end_drive_cmd (drive, 0, 0); 307 ide_end_drive_cmd (drive, 0, 0);
321 if (blk_sense_request(rq)) { 308 if (blk_sense_request(rq)) {
322 idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer; 309 struct ide_atapi_pc *opc = (struct ide_atapi_pc *) rq->buffer;
323 if (log) { 310 if (log) {
324 printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number); 311 printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number);
325 ide_scsi_hex_dump(pc->buffer, 16); 312 ide_scsi_hex_dump(pc->buf, 16);
326 } 313 }
327 memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buffer, SCSI_SENSE_BUFFERSIZE); 314 memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buf,
328 kfree(pc->buffer); 315 SCSI_SENSE_BUFFERSIZE);
316 kfree(pc->buf);
329 kfree(pc); 317 kfree(pc);
330 kfree(rq); 318 kfree(rq);
331 pc = opc; 319 pc = opc;
@@ -361,7 +349,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
361 return 0; 349 return 0;
362} 350}
363 351
364static inline unsigned long get_timeout(idescsi_pc_t *pc) 352static inline unsigned long get_timeout(struct ide_atapi_pc *pc)
365{ 353{
366 return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies); 354 return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies);
367} 355}
@@ -369,7 +357,7 @@ static inline unsigned long get_timeout(idescsi_pc_t *pc)
369static int idescsi_expiry(ide_drive_t *drive) 357static int idescsi_expiry(ide_drive_t *drive)
370{ 358{
371 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 359 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
372 idescsi_pc_t *pc = scsi->pc; 360 struct ide_atapi_pc *pc = scsi->pc;
373 361
374#if IDESCSI_DEBUG_LOG 362#if IDESCSI_DEBUG_LOG
375 printk(KERN_WARNING "idescsi_expiry called for %lu at %lu\n", pc->scsi_cmd->serial_number, jiffies); 363 printk(KERN_WARNING "idescsi_expiry called for %lu at %lu\n", pc->scsi_cmd->serial_number, jiffies);
@@ -386,7 +374,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
386{ 374{
387 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 375 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
388 ide_hwif_t *hwif = drive->hwif; 376 ide_hwif_t *hwif = drive->hwif;
389 idescsi_pc_t *pc = scsi->pc; 377 struct ide_atapi_pc *pc = scsi->pc;
390 struct request *rq = pc->rq; 378 struct request *rq = pc->rq;
391 unsigned int temp; 379 unsigned int temp;
392 u16 bcount; 380 u16 bcount;
@@ -409,7 +397,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
409#if IDESCSI_DEBUG_LOG 397#if IDESCSI_DEBUG_LOG
410 printk ("ide-scsi: %s: DMA complete\n", drive->name); 398 printk ("ide-scsi: %s: DMA complete\n", drive->name);
411#endif /* IDESCSI_DEBUG_LOG */ 399#endif /* IDESCSI_DEBUG_LOG */
412 pc->actually_transferred=pc->request_transfer; 400 pc->xferred = pc->req_xfer;
413 (void) HWIF(drive)->ide_dma_end(drive); 401 (void) HWIF(drive)->ide_dma_end(drive);
414 } 402 }
415 403
@@ -419,7 +407,8 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
419 if ((stat & DRQ_STAT) == 0) { 407 if ((stat & DRQ_STAT) == 0) {
420 /* No more interrupts */ 408 /* No more interrupts */
421 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) 409 if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
422 printk (KERN_INFO "Packet command completed, %d bytes transferred\n", pc->actually_transferred); 410 printk(KERN_INFO "Packet command completed, %d bytes"
411 " transferred\n", pc->xferred);
423 local_irq_enable_in_hardirq(); 412 local_irq_enable_in_hardirq();
424 if (stat & ERR_STAT) 413 if (stat & ERR_STAT)
425 rq->errors++; 414 rq->errors++;
@@ -435,25 +424,26 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
435 return ide_do_reset (drive); 424 return ide_do_reset (drive);
436 } 425 }
437 if (ireason & IO) { 426 if (ireason & IO) {
438 temp = pc->actually_transferred + bcount; 427 temp = pc->xferred + bcount;
439 if (temp > pc->request_transfer) { 428 if (temp > pc->req_xfer) {
440 if (temp > pc->buffer_size) { 429 if (temp > pc->buf_size) {
441 printk(KERN_ERR "ide-scsi: The scsi wants to " 430 printk(KERN_ERR "ide-scsi: The scsi wants to "
442 "send us more data than expected " 431 "send us more data than expected "
443 "- discarding data\n"); 432 "- discarding data\n");
444 temp = pc->buffer_size - pc->actually_transferred; 433 temp = pc->buf_size - pc->xferred;
445 if (temp) { 434 if (temp) {
446 clear_bit(PC_WRITING, &pc->flags); 435 clear_bit(PC_WRITING, &pc->flags);
447 if (pc->sg) 436 if (pc->sg)
448 idescsi_input_buffers(drive, pc, temp); 437 idescsi_input_buffers(drive, pc,
438 temp);
449 else 439 else
450 drive->hwif->atapi_input_bytes(drive, pc->current_position, temp); 440 drive->hwif->atapi_input_bytes(drive, pc->cur_pos, temp);
451 printk(KERN_ERR "ide-scsi: transferred" 441 printk(KERN_ERR "ide-scsi: transferred"
452 " %d of %d bytes\n", 442 " %d of %d bytes\n",
453 temp, bcount); 443 temp, bcount);
454 } 444 }
455 pc->actually_transferred += temp; 445 pc->xferred += temp;
456 pc->current_position += temp; 446 pc->cur_pos += temp;
457 ide_atapi_discard_data(drive, bcount - temp); 447 ide_atapi_discard_data(drive, bcount - temp);
458 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry); 448 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
459 return ide_started; 449 return ide_started;
@@ -468,19 +458,19 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
468 if (pc->sg) 458 if (pc->sg)
469 idescsi_input_buffers(drive, pc, bcount); 459 idescsi_input_buffers(drive, pc, bcount);
470 else 460 else
471 hwif->atapi_input_bytes(drive, pc->current_position, 461 hwif->atapi_input_bytes(drive, pc->cur_pos,
472 bcount); 462 bcount);
473 } else { 463 } else {
474 set_bit(PC_WRITING, &pc->flags); 464 set_bit(PC_WRITING, &pc->flags);
475 if (pc->sg) 465 if (pc->sg)
476 idescsi_output_buffers(drive, pc, bcount); 466 idescsi_output_buffers(drive, pc, bcount);
477 else 467 else
478 hwif->atapi_output_bytes(drive, pc->current_position, 468 hwif->atapi_output_bytes(drive, pc->cur_pos,
479 bcount); 469 bcount);
480 } 470 }
481 /* Update the current position */ 471 /* Update the current position */
482 pc->actually_transferred += bcount; 472 pc->xferred += bcount;
483 pc->current_position += bcount; 473 pc->cur_pos += bcount;
484 474
485 /* And set the interrupt handler again */ 475 /* And set the interrupt handler again */
486 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry); 476 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
@@ -491,7 +481,7 @@ static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
491{ 481{
492 ide_hwif_t *hwif = drive->hwif; 482 ide_hwif_t *hwif = drive->hwif;
493 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 483 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
494 idescsi_pc_t *pc = scsi->pc; 484 struct ide_atapi_pc *pc = scsi->pc;
495 ide_startstop_t startstop; 485 ide_startstop_t startstop;
496 u8 ireason; 486 u8 ireason;
497 487
@@ -518,7 +508,7 @@ static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
518 return ide_started; 508 return ide_started;
519} 509}
520 510
521static inline int idescsi_set_direction(idescsi_pc_t *pc) 511static inline int idescsi_set_direction(struct ide_atapi_pc *pc)
522{ 512{
523 switch (pc->c[0]) { 513 switch (pc->c[0]) {
524 case READ_6: case READ_10: case READ_12: 514 case READ_6: case READ_10: case READ_12:
@@ -532,13 +522,13 @@ static inline int idescsi_set_direction(idescsi_pc_t *pc)
532 } 522 }
533} 523}
534 524
535static int idescsi_map_sg(ide_drive_t *drive, idescsi_pc_t *pc) 525static int idescsi_map_sg(ide_drive_t *drive, struct ide_atapi_pc *pc)
536{ 526{
537 ide_hwif_t *hwif = drive->hwif; 527 ide_hwif_t *hwif = drive->hwif;
538 struct scatterlist *sg, *scsi_sg; 528 struct scatterlist *sg, *scsi_sg;
539 int segments; 529 int segments;
540 530
541 if (!pc->request_transfer || pc->request_transfer % 1024) 531 if (!pc->req_xfer || pc->req_xfer % 1024)
542 return 1; 532 return 1;
543 533
544 if (idescsi_set_direction(pc)) 534 if (idescsi_set_direction(pc))
@@ -557,21 +547,21 @@ static int idescsi_map_sg(ide_drive_t *drive, idescsi_pc_t *pc)
557 return 0; 547 return 0;
558} 548}
559 549
560/* 550static ide_startstop_t idescsi_issue_pc(ide_drive_t *drive,
561 * Issue a packet command 551 struct ide_atapi_pc *pc)
562 */
563static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
564{ 552{
565 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 553 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
566 ide_hwif_t *hwif = drive->hwif; 554 ide_hwif_t *hwif = drive->hwif;
567 u16 bcount; 555 u16 bcount;
568 u8 dma = 0; 556 u8 dma = 0;
569 557
570 scsi->pc=pc; /* Set the current packet command */ 558 /* Set the current packet command */
571 pc->actually_transferred=0; /* We haven't transferred any data yet */ 559 scsi->pc = pc;
572 pc->current_position=pc->buffer; 560 /* We haven't transferred any data yet */
561 pc->xferred = 0;
562 pc->cur_pos = pc->buf;
573 /* Request to transfer the entire buffer at once */ 563 /* Request to transfer the entire buffer at once */
574 bcount = min(pc->request_transfer, 63 * 1024); 564 bcount = min(pc->req_xfer, 63 * 1024);
575 565
576 if (drive->using_dma && !idescsi_map_sg(drive, pc)) { 566 if (drive->using_dma && !idescsi_map_sg(drive, pc)) {
577 hwif->sg_mapped = 1; 567 hwif->sg_mapped = 1;
@@ -606,7 +596,8 @@ static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *r
606#endif /* IDESCSI_DEBUG_LOG */ 596#endif /* IDESCSI_DEBUG_LOG */
607 597
608 if (blk_sense_request(rq) || blk_special_request(rq)) { 598 if (blk_sense_request(rq) || blk_special_request(rq)) {
609 return idescsi_issue_pc (drive, (idescsi_pc_t *) rq->special); 599 return idescsi_issue_pc(drive,
600 (struct ide_atapi_pc *) rq->special);
610 } 601 }
611 blk_dump_rq_flags(rq, "ide-scsi: unsup command"); 602 blk_dump_rq_flags(rq, "ide-scsi: unsup command");
612 idescsi_end_request (drive, 0, 0); 603 idescsi_end_request (drive, 0, 0);
@@ -764,15 +755,15 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
764 idescsi_scsi_t *scsi = scsihost_to_idescsi(host); 755 idescsi_scsi_t *scsi = scsihost_to_idescsi(host);
765 ide_drive_t *drive = scsi->drive; 756 ide_drive_t *drive = scsi->drive;
766 struct request *rq = NULL; 757 struct request *rq = NULL;
767 idescsi_pc_t *pc = NULL; 758 struct ide_atapi_pc *pc = NULL;
768 759
769 if (!drive) { 760 if (!drive) {
770 scmd_printk (KERN_ERR, cmd, "drive not present\n"); 761 scmd_printk (KERN_ERR, cmd, "drive not present\n");
771 goto abort; 762 goto abort;
772 } 763 }
773 scsi = drive_to_idescsi(drive); 764 scsi = drive_to_idescsi(drive);
774 pc = kmalloc (sizeof (idescsi_pc_t), GFP_ATOMIC); 765 pc = kmalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
775 rq = kmalloc (sizeof (struct request), GFP_ATOMIC); 766 rq = kmalloc(sizeof(struct request), GFP_ATOMIC);
776 if (rq == NULL || pc == NULL) { 767 if (rq == NULL || pc == NULL) {
777 printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name); 768 printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name);
778 goto abort; 769 goto abort;
@@ -782,11 +773,11 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
782 pc->flags = 0; 773 pc->flags = 0;
783 pc->rq = rq; 774 pc->rq = rq;
784 memcpy (pc->c, cmd->cmnd, cmd->cmd_len); 775 memcpy (pc->c, cmd->cmnd, cmd->cmd_len);
785 pc->buffer = NULL; 776 pc->buf = NULL;
786 pc->sg = scsi_sglist(cmd); 777 pc->sg = scsi_sglist(cmd);
787 pc->sg_cnt = scsi_sg_count(cmd); 778 pc->sg_cnt = scsi_sg_count(cmd);
788 pc->b_count = 0; 779 pc->b_count = 0;
789 pc->request_transfer = pc->buffer_size = scsi_bufflen(cmd); 780 pc->req_xfer = pc->buf_size = scsi_bufflen(cmd);
790 pc->scsi_cmd = cmd; 781 pc->scsi_cmd = cmd;
791 pc->done = done; 782 pc->done = done;
792 pc->timeout = jiffies + cmd->timeout_per_command; 783 pc->timeout = jiffies + cmd->timeout_per_command;
@@ -857,7 +848,7 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
857 printk (KERN_ERR "ide-scsi: cmd aborted!\n"); 848 printk (KERN_ERR "ide-scsi: cmd aborted!\n");
858 849
859 if (blk_sense_request(scsi->pc->rq)) 850 if (blk_sense_request(scsi->pc->rq))
860 kfree(scsi->pc->buffer); 851 kfree(scsi->pc->buf);
861 kfree(scsi->pc->rq); 852 kfree(scsi->pc->rq);
862 kfree(scsi->pc); 853 kfree(scsi->pc);
863 scsi->pc = NULL; 854 scsi->pc = NULL;
@@ -907,7 +898,7 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
907 if (__blk_end_request(req, -EIO, 0)) 898 if (__blk_end_request(req, -EIO, 0))
908 BUG(); 899 BUG();
909 if (blk_sense_request(req)) 900 if (blk_sense_request(req))
910 kfree(scsi->pc->buffer); 901 kfree(scsi->pc->buf);
911 kfree(scsi->pc); 902 kfree(scsi->pc);
912 scsi->pc = NULL; 903 scsi->pc = NULL;
913 kfree(req); 904 kfree(req);
ass="hl num">1: error = 0; break; default: error = uptodate; } if (error) floppy->failed_pc = NULL; /* Why does this happen? */ if (!rq) return 0; if (!(rq->flags & REQ_SPECIAL)) { //if (!IDEFLOPPY_RQ_CMD (rq->cmd)) { /* our real local end request function */ ide_end_request(drive, uptodate, nsecs); return 0; } rq->errors = error; /* fixme: need to move this local also */ ide_end_drive_cmd(drive, 0, 0); return 0; } static void idefloppy_input_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount) { struct request *rq = pc->rq; struct bio_vec *bvec; struct bio *bio; unsigned long flags; char *data; int count, i, done = 0; rq_for_each_bio(bio, rq) { bio_for_each_segment(bvec, bio, i) { if (!bcount) break; count = min(bvec->bv_len, bcount); data = bvec_kmap_irq(bvec, &flags); drive->hwif->atapi_input_bytes(drive, data, count); bvec_kunmap_irq(data, &flags); bcount -= count; pc->b_count += count; done += count; } } idefloppy_do_end_request(drive, 1, done >> 9); if (bcount) { printk(KERN_ERR "%s: leftover data in idefloppy_input_buffers, bcount == %d\n", drive->name, bcount); idefloppy_discard_data(drive, bcount); } } static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount) { struct request *rq = pc->rq; struct bio *bio; struct bio_vec *bvec; unsigned long flags; int count, i, done = 0; char *data; rq_for_each_bio(bio, rq) { bio_for_each_segment(bvec, bio, i) { if (!bcount) break; count = min(bvec->bv_len, bcount); data = bvec_kmap_irq(bvec, &flags); drive->hwif->atapi_output_bytes(drive, data, count); bvec_kunmap_irq(data, &flags); bcount -= count; pc->b_count += count; done += count; } } idefloppy_do_end_request(drive, 1, done >> 9); #if IDEFLOPPY_DEBUG_BUGS if (bcount) { printk(KERN_ERR "%s: leftover data in idefloppy_output_buffers, bcount == %d\n", drive->name, bcount); idefloppy_write_zeros(drive, bcount); } #endif } static void idefloppy_update_buffers (ide_drive_t *drive, idefloppy_pc_t *pc) { struct request *rq = pc->rq; struct bio *bio = rq->bio; while ((bio = rq->bio) != NULL) idefloppy_do_end_request(drive, 1, 0); } /* * idefloppy_queue_pc_head generates a new packet command request in front * of the request queue, before the current request, so that it will be * processed immediately, on the next pass through the driver. */ static void idefloppy_queue_pc_head (ide_drive_t *drive,idefloppy_pc_t *pc,struct request *rq) { struct ide_floppy_obj *floppy = drive->driver_data; ide_init_drive_cmd(rq); rq->buffer = (char *) pc; rq->flags = REQ_SPECIAL; //rq->cmd = IDEFLOPPY_PC_RQ; rq->rq_disk = floppy->disk; (void) ide_do_drive_cmd(drive, rq, ide_preempt); } static idefloppy_pc_t *idefloppy_next_pc_storage (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK) floppy->pc_stack_index=0; return (&floppy->pc_stack[floppy->pc_stack_index++]); } static struct request *idefloppy_next_rq_storage (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK) floppy->rq_stack_index = 0; return (&floppy->rq_stack[floppy->rq_stack_index++]); } /* * idefloppy_analyze_error is called on each failed packet command retry * to analyze the request sense. */ static void idefloppy_analyze_error (ide_drive_t *drive,idefloppy_request_sense_result_t *result) { idefloppy_floppy_t *floppy = drive->driver_data; floppy->sense_key = result->sense_key; floppy->asc = result->asc; floppy->ascq = result->ascq; floppy->progress_indication = result->sksv[0] & 0x80 ? (u16)get_unaligned((u16 *)(result->sksv+1)):0x10000; if (floppy->failed_pc) debug_log(KERN_INFO "ide-floppy: pc = %x, sense key = %x, " "asc = %x, ascq = %x\n", floppy->failed_pc->c[0], result->sense_key, result->asc, result->ascq); else debug_log(KERN_INFO "ide-floppy: sense key = %x, asc = %x, " "ascq = %x\n", result->sense_key, result->asc, result->ascq); } static void idefloppy_request_sense_callback (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; debug_log(KERN_INFO "ide-floppy: Reached %s\n", __FUNCTION__); if (!floppy->pc->error) { idefloppy_analyze_error(drive,(idefloppy_request_sense_result_t *) floppy->pc->buffer); idefloppy_do_end_request(drive, 1, 0); } else { printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting request!\n"); idefloppy_do_end_request(drive, 0, 0); } } /* * General packet command callback function. */ static void idefloppy_pc_callback (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; debug_log(KERN_INFO "ide-floppy: Reached %s\n", __FUNCTION__); idefloppy_do_end_request(drive, floppy->pc->error ? 0 : 1, 0); } /* * idefloppy_init_pc initializes a packet command. */ static void idefloppy_init_pc (idefloppy_pc_t *pc) { memset(pc->c, 0, 12); pc->retries = 0; pc->flags = 0; pc->request_transfer = 0; pc->buffer = pc->pc_buffer; pc->buffer_size = IDEFLOPPY_PC_BUFFER_SIZE; pc->callback = &idefloppy_pc_callback; } static void idefloppy_create_request_sense_cmd (idefloppy_pc_t *pc) { idefloppy_init_pc(pc); pc->c[0] = IDEFLOPPY_REQUEST_SENSE_CMD; pc->c[4] = 255; pc->request_transfer = 18; pc->callback = &idefloppy_request_sense_callback; } /* * idefloppy_retry_pc is called when an error was detected during the * last packet command. We queue a request sense packet command in * the head of the request list. */ static void idefloppy_retry_pc (ide_drive_t *drive) { idefloppy_pc_t *pc; struct request *rq; atapi_error_t error; error.all = HWIF(drive)->INB(IDE_ERROR_REG); pc = idefloppy_next_pc_storage(drive); rq = idefloppy_next_rq_storage(drive); idefloppy_create_request_sense_cmd(pc); idefloppy_queue_pc_head(drive, pc, rq); } /* * idefloppy_pc_intr is the usual interrupt handler which will be called * during a packet command. */ static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; atapi_status_t status; atapi_bcount_t bcount; atapi_ireason_t ireason; idefloppy_pc_t *pc = floppy->pc; struct request *rq = pc->rq; unsigned int temp; debug_log(KERN_INFO "ide-floppy: Reached %s interrupt handler\n", __FUNCTION__); if (test_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { if (HWIF(drive)->ide_dma_end(drive)) { set_bit(PC_DMA_ERROR, &pc->flags); } else { pc->actually_transferred = pc->request_transfer; idefloppy_update_buffers(drive, pc); } debug_log(KERN_INFO "ide-floppy: DMA finished\n"); } /* Clear the interrupt */ status.all = HWIF(drive)->INB(IDE_STATUS_REG); if (!status.b.drq) { /* No more interrupts */ debug_log(KERN_INFO "Packet command completed, %d bytes " "transferred\n", pc->actually_transferred); clear_bit(PC_DMA_IN_PROGRESS, &pc->flags); local_irq_enable(); if (status.b.check || test_bit(PC_DMA_ERROR, &pc->flags)) { /* Error detected */ debug_log(KERN_INFO "ide-floppy: %s: I/O error\n", drive->name); rq->errors++; if (pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD) { printk(KERN_ERR "ide-floppy: I/O error in " "request sense command\n"); return ide_do_reset(drive); } /* Retry operation */ idefloppy_retry_pc(drive); /* queued, but not started */ return ide_stopped; } pc->error = 0; if (floppy->failed_pc == pc) floppy->failed_pc = NULL; /* Command finished - Call the callback function */ pc->callback(drive); return ide_stopped; } if (test_and_clear_bit(PC_DMA_IN_PROGRESS, &pc->flags)) { printk(KERN_ERR "ide-floppy: The floppy wants to issue " "more interrupts in DMA mode\n"); (void)__ide_dma_off(drive); return ide_do_reset(drive); } /* Get the number of bytes to transfer */ bcount.b.high = HWIF(drive)->INB(IDE_BCOUNTH_REG); bcount.b.low = HWIF(drive)->INB(IDE_BCOUNTL_REG); /* on this interrupt */ ireason.all = HWIF(drive)->INB(IDE_IREASON_REG); if (ireason.b.cod) { printk(KERN_ERR "ide-floppy: CoD != 0 in idefloppy_pc_intr\n"); return ide_do_reset(drive); } if (ireason.b.io == test_bit(PC_WRITING, &pc->flags)) { /* Hopefully, we will never get here */ printk(KERN_ERR "ide-floppy: We wanted to %s, ", ireason.b.io ? "Write":"Read"); printk(KERN_ERR "but the floppy wants us to %s !\n", ireason.b.io ? "Read":"Write"); return ide_do_reset(drive); } if (!test_bit(PC_WRITING, &pc->flags)) { /* Reading - Check that we have enough space */ temp = pc->actually_transferred + bcount.all; if (temp > pc->request_transfer) { if (temp > pc->buffer_size) { printk(KERN_ERR "ide-floppy: The floppy wants " "to send us more data than expected " "- discarding data\n"); idefloppy_discard_data(drive,bcount.all); if (HWGROUP(drive)->handler != NULL) BUG(); ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); return ide_started; } debug_log(KERN_NOTICE "ide-floppy: The floppy wants to " "send us more data than expected - " "allowing transfer\n"); } } if (test_bit(PC_WRITING, &pc->flags)) { if (pc->buffer != NULL) /* Write the current buffer */ HWIF(drive)->atapi_output_bytes(drive, pc->current_position, bcount.all); else idefloppy_output_buffers(drive, pc, bcount.all); } else { if (pc->buffer != NULL) /* Read the current buffer */ HWIF(drive)->atapi_input_bytes(drive, pc->current_position, bcount.all); else idefloppy_input_buffers(drive, pc, bcount.all); } /* Update the current position */ pc->actually_transferred += bcount.all; pc->current_position += bcount.all; if (HWGROUP(drive)->handler != NULL) BUG(); ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); /* And set the interrupt handler again */ return ide_started; } /* * This is the original routine that did the packet transfer. * It fails at high speeds on the Iomega ZIP drive, so there's a slower version * for that drive below. The algorithm is chosen based on drive type */ static ide_startstop_t idefloppy_transfer_pc (ide_drive_t *drive) { ide_startstop_t startstop; idefloppy_floppy_t *floppy = drive->driver_data; atapi_ireason_t ireason; if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { printk(KERN_ERR "ide-floppy: Strange, packet command " "initiated yet DRQ isn't asserted\n"); return startstop; } ireason.all = HWIF(drive)->INB(IDE_IREASON_REG); if (!ireason.b.cod || ireason.b.io) { printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) while " "issuing a packet command\n"); return ide_do_reset(drive); } if (HWGROUP(drive)->handler != NULL) BUG(); /* Set the interrupt routine */ ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); /* Send the actual packet */ HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12); return ide_started; } /* * What we have here is a classic case of a top half / bottom half * interrupt service routine. In interrupt mode, the device sends * an interrupt to signal it's ready to receive a packet. However, * we need to delay about 2-3 ticks before issuing the packet or we * gets in trouble. * * So, follow carefully. transfer_pc1 is called as an interrupt (or * directly). In either case, when the device says it's ready for a * packet, we schedule the packet transfer to occur about 2-3 ticks * later in transfer_pc2. */ static int idefloppy_transfer_pc2 (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; /* Send the actual packet */ HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12); /* Timeout for the packet command */ return IDEFLOPPY_WAIT_CMD; } static ide_startstop_t idefloppy_transfer_pc1 (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; ide_startstop_t startstop; atapi_ireason_t ireason; if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { printk(KERN_ERR "ide-floppy: Strange, packet command " "initiated yet DRQ isn't asserted\n"); return startstop; } ireason.all = HWIF(drive)->INB(IDE_IREASON_REG); if (!ireason.b.cod || ireason.b.io) { printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) " "while issuing a packet command\n"); return ide_do_reset(drive); } /* * The following delay solves a problem with ATAPI Zip 100 drives * where the Busy flag was apparently being deasserted before the * unit was ready to receive data. This was happening on a * 1200 MHz Athlon system. 10/26/01 25msec is too short, * 40 and 50msec work well. idefloppy_pc_intr will not be actually * used until after the packet is moved in about 50 msec. */ if (HWGROUP(drive)->handler != NULL) BUG(); ide_set_handler(drive, &idefloppy_pc_intr, /* service routine for packet command */ floppy->ticks, /* wait this long before "failing" */ &idefloppy_transfer_pc2); /* fail == transfer_pc2 */ return ide_started; } /** * idefloppy_should_report_error() * * Supresses error messages resulting from Medium not present */ static inline int idefloppy_should_report_error(idefloppy_floppy_t *floppy) { if (floppy->sense_key == 0x02 && floppy->asc == 0x3a && floppy->ascq == 0x00) return 0; return 1; } /* * Issue a packet command */ static ide_startstop_t idefloppy_issue_pc (ide_drive_t *drive, idefloppy_pc_t *pc) { idefloppy_floppy_t *floppy = drive->driver_data; ide_hwif_t *hwif = drive->hwif; atapi_feature_t feature; atapi_bcount_t bcount; ide_handler_t *pkt_xfer_routine; #if 0 /* Accessing floppy->pc is not valid here, the previous pc may be gone and have lived on another thread's stack; that stack may have become unmapped meanwhile (CONFIG_DEBUG_PAGEALLOC). */ #if IDEFLOPPY_DEBUG_BUGS if (floppy->pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD && pc->c[0] == IDEFLOPPY_REQUEST_SENSE_CMD) { printk(KERN_ERR "ide-floppy: possible ide-floppy.c bug - " "Two request sense in serial were issued\n"); } #endif /* IDEFLOPPY_DEBUG_BUGS */ #endif if (floppy->failed_pc == NULL && pc->c[0] != IDEFLOPPY_REQUEST_SENSE_CMD) floppy->failed_pc = pc; /* Set the current packet command */ floppy->pc = pc; if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES || test_bit(PC_ABORT, &pc->flags)) { /* * We will "abort" retrying a packet command in case * a legitimate error code was received. */ if (!test_bit(PC_ABORT, &pc->flags)) { if (!test_bit(PC_SUPPRESS_ERROR, &pc->flags)) { if (idefloppy_should_report_error(floppy)) printk(KERN_ERR "ide-floppy: %s: I/O error, " "pc = %2x, key = %2x, " "asc = %2x, ascq = %2x\n", drive->name, pc->c[0], floppy->sense_key, floppy->asc, floppy->ascq); } /* Giving up */ pc->error = IDEFLOPPY_ERROR_GENERAL; } floppy->failed_pc = NULL; pc->callback(drive); return ide_stopped; } debug_log(KERN_INFO "Retry number - %d\n",pc->retries); pc->retries++; /* We haven't transferred any data yet */ pc->actually_transferred = 0; pc->current_position = pc->buffer; bcount.all = min(pc->request_transfer, 63 * 1024); if (test_and_clear_bit(PC_DMA_ERROR, &pc->flags)) { (void)__ide_dma_off(drive); } feature.all = 0; if (test_bit(PC_DMA_RECOMMENDED, &pc->flags) && drive->using_dma) feature.b.dma = !hwif->dma_setup(drive); if (IDE_CONTROL_REG) HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG); /* Use PIO/DMA */ HWIF(drive)->OUTB(feature.all, IDE_FEATURE_REG); HWIF(drive)->OUTB(bcount.b.high, IDE_BCOUNTH_REG); HWIF(drive)->OUTB(bcount.b.low, IDE_BCOUNTL_REG); HWIF(drive)->OUTB(drive->select.all, IDE_SELECT_REG); if (feature.b.dma) { /* Begin DMA, if necessary */ set_bit(PC_DMA_IN_PROGRESS, &pc->flags); hwif->dma_start(drive); } /* Can we transfer the packet when we get the interrupt or wait? */ if (test_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags)) { /* wait */ pkt_xfer_routine = &idefloppy_transfer_pc1; } else { /* immediate */ pkt_xfer_routine = &idefloppy_transfer_pc; } if (test_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags)) { /* Issue the packet command */ ide_execute_command(drive, WIN_PACKETCMD, pkt_xfer_routine, IDEFLOPPY_WAIT_CMD, NULL); return ide_started; } else { /* Issue the packet command */ HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG); return (*pkt_xfer_routine) (drive); } } static void idefloppy_rw_callback (ide_drive_t *drive) { debug_log(KERN_INFO "ide-floppy: Reached idefloppy_rw_callback\n"); idefloppy_do_end_request(drive, 1, 0); return; } static void idefloppy_create_prevent_cmd (idefloppy_pc_t *pc, int prevent) { debug_log(KERN_INFO "ide-floppy: creating prevent removal command, " "prevent = %d\n", prevent); idefloppy_init_pc(pc); pc->c[0] = IDEFLOPPY_PREVENT_REMOVAL_CMD; pc->c[4] = prevent; } static void idefloppy_create_read_capacity_cmd (idefloppy_pc_t *pc) { idefloppy_init_pc(pc); pc->c[0] = IDEFLOPPY_READ_CAPACITY_CMD; pc->c[7] = 255; pc->c[8] = 255; pc->request_transfer = 255; } static void idefloppy_create_format_unit_cmd (idefloppy_pc_t *pc, int b, int l, int flags) { idefloppy_init_pc(pc); pc->c[0] = IDEFLOPPY_FORMAT_UNIT_CMD; pc->c[1] = 0x17; memset(pc->buffer, 0, 12); pc->buffer[1] = 0xA2; /* Default format list header, u8 1: FOV/DCRT/IMM bits set */ if (flags & 1) /* Verify bit on... */ pc->buffer[1] ^= 0x20; /* ... turn off DCRT bit */ pc->buffer[3] = 8; put_unaligned(htonl(b), (unsigned int *)(&pc->buffer[4])); put_unaligned(htonl(l), (unsigned int *)(&pc->buffer[8])); pc->buffer_size=12; set_bit(PC_WRITING, &pc->flags); } /* * A mode sense command is used to "sense" floppy parameters. */ static void idefloppy_create_mode_sense_cmd (idefloppy_pc_t *pc, u8 page_code, u8 type) { u16 length = sizeof(idefloppy_mode_parameter_header_t); idefloppy_init_pc(pc); pc->c[0] = IDEFLOPPY_MODE_SENSE_CMD; pc->c[1] = 0; pc->c[2] = page_code + (type << 6); switch (page_code) { case IDEFLOPPY_CAPABILITIES_PAGE: length += 12; break; case IDEFLOPPY_FLEXIBLE_DISK_PAGE: length += 32; break; default: printk(KERN_ERR "ide-floppy: unsupported page code " "in create_mode_sense_cmd\n"); } put_unaligned(htons(length), (u16 *) &pc->c[7]); pc->request_transfer = length; } static void idefloppy_create_start_stop_cmd (idefloppy_pc_t *pc, int start) { idefloppy_init_pc(pc); pc->c[0] = IDEFLOPPY_START_STOP_CMD; pc->c[4] = start; } static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t *pc) { idefloppy_init_pc(pc); pc->c[0] = IDEFLOPPY_TEST_UNIT_READY_CMD; } static void idefloppy_create_rw_cmd (idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq, unsigned long sector) { int block = sector / floppy->bs_factor; int blocks = rq->nr_sectors / floppy->bs_factor; int cmd = rq_data_dir(rq); debug_log("create_rw1%d_cmd: block == %d, blocks == %d\n", 2 * test_bit (IDEFLOPPY_USE_READ12, &floppy->flags), block, blocks); idefloppy_init_pc(pc); if (test_bit(IDEFLOPPY_USE_READ12, &floppy->flags)) { pc->c[0] = cmd == READ ? IDEFLOPPY_READ12_CMD : IDEFLOPPY_WRITE12_CMD; put_unaligned(htonl(blocks), (unsigned int *) &pc->c[6]); } else { pc->c[0] = cmd == READ ? IDEFLOPPY_READ10_CMD : IDEFLOPPY_WRITE10_CMD; put_unaligned(htons(blocks), (unsigned short *) &pc->c[7]); } put_unaligned(htonl(block), (unsigned int *) &pc->c[2]); pc->callback = &idefloppy_rw_callback; pc->rq = rq; pc->b_count = cmd == READ ? 0 : rq->bio->bi_size; if (rq->flags & REQ_RW) set_bit(PC_WRITING, &pc->flags); pc->buffer = NULL; pc->request_transfer = pc->buffer_size = blocks * floppy->block_size; set_bit(PC_DMA_RECOMMENDED, &pc->flags); } static int idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc, struct request *rq) { /* * just support eject for now, it would not be hard to make the * REQ_BLOCK_PC support fully-featured */ if (rq->cmd[0] != IDEFLOPPY_START_STOP_CMD) return 1; idefloppy_init_pc(pc); memcpy(pc->c, rq->cmd, sizeof(pc->c)); return 0; } /* * idefloppy_do_request is our request handling function. */ static ide_startstop_t idefloppy_do_request (ide_drive_t *drive, struct request *rq, sector_t block_s) { idefloppy_floppy_t *floppy = drive->driver_data; idefloppy_pc_t *pc; unsigned long block = (unsigned long)block_s; debug_log(KERN_INFO "rq_status: %d, dev: %s, flags: %lx, errors: %d\n", rq->rq_status, rq->rq_disk ? rq->rq_disk->disk_name ? "?", rq->flags, rq->errors); debug_log(KERN_INFO "sector: %ld, nr_sectors: %ld, " "current_nr_sectors: %d\n", (long)rq->sector, rq->nr_sectors, rq->current_nr_sectors); if (rq->errors >= ERROR_MAX) { if (floppy->failed_pc != NULL) { if (idefloppy_should_report_error(floppy)) printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x," " key = %2x, asc = %2x, ascq = %2x\n", drive->name, floppy->failed_pc->c[0], floppy->sense_key, floppy->asc, floppy->ascq); } else printk(KERN_ERR "ide-floppy: %s: I/O error\n", drive->name); idefloppy_do_end_request(drive, 0, 0); return ide_stopped; } if (rq->flags & REQ_CMD) { if (((long)rq->sector % floppy->bs_factor) || (rq->nr_sectors % floppy->bs_factor)) { printk("%s: unsupported r/w request size\n", drive->name); idefloppy_do_end_request(drive, 0, 0); return ide_stopped; } pc = idefloppy_next_pc_storage(drive); idefloppy_create_rw_cmd(floppy, pc, rq, block); } else if (rq->flags & REQ_SPECIAL) { pc = (idefloppy_pc_t *) rq->buffer; } else if (rq->flags & REQ_BLOCK_PC) { pc = idefloppy_next_pc_storage(drive); if (idefloppy_blockpc_cmd(floppy, pc, rq)) { idefloppy_do_end_request(drive, 0, 0); return ide_stopped; } } else { blk_dump_rq_flags(rq, "ide-floppy: unsupported command in queue"); idefloppy_do_end_request(drive, 0, 0); return ide_stopped; } pc->rq = rq; return idefloppy_issue_pc(drive, pc); } /* * idefloppy_queue_pc_tail adds a special packet command request to the * tail of the request queue, and waits for it to be serviced. */ static int idefloppy_queue_pc_tail (ide_drive_t *drive,idefloppy_pc_t *pc) { struct ide_floppy_obj *floppy = drive->driver_data; struct request rq; ide_init_drive_cmd (&rq); rq.buffer = (char *) pc; rq.flags = REQ_SPECIAL; // rq.cmd = IDEFLOPPY_PC_RQ; rq.rq_disk = floppy->disk; return ide_do_drive_cmd(drive, &rq, ide_wait); } /* * Look at the flexible disk page parameters. We will ignore the CHS * capacity parameters and use the LBA parameters instead. */ static int idefloppy_get_flexible_disk_page (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; idefloppy_pc_t pc; idefloppy_mode_parameter_header_t *header; idefloppy_flexible_disk_page_t *page; int capacity, lba_capacity; idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, MODE_SENSE_CURRENT); if (idefloppy_queue_pc_tail(drive,&pc)) { printk(KERN_ERR "ide-floppy: Can't get flexible disk " "page parameters\n"); return 1; } header = (idefloppy_mode_parameter_header_t *) pc.buffer; floppy->wp = header->wp; set_disk_ro(floppy->disk, floppy->wp); page = (idefloppy_flexible_disk_page_t *) (header + 1); page->transfer_rate = ntohs(page->transfer_rate); page->sector_size = ntohs(page->sector_size); page->cyls = ntohs(page->cyls); page->rpm = ntohs(page->rpm); capacity = page->cyls * page->heads * page->sectors * page->sector_size; if (memcmp (page, &floppy->flexible_disk_page, sizeof (idefloppy_flexible_disk_page_t))) printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, " "%d sector size, %d rpm\n", drive->name, capacity / 1024, page->cyls, page->heads, page->sectors, page->transfer_rate / 8, page->sector_size, page->rpm); floppy->flexible_disk_page = *page; drive->bios_cyl = page->cyls; drive->bios_head = page->heads; drive->bios_sect = page->sectors; lba_capacity = floppy->blocks * floppy->block_size; if (capacity < lba_capacity) { printk(KERN_NOTICE "%s: The disk reports a capacity of %d " "bytes, but the drive only handles %d\n", drive->name, lba_capacity, capacity); floppy->blocks = floppy->block_size ? capacity / floppy->block_size : 0; } return 0; } static int idefloppy_get_capability_page(ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; idefloppy_pc_t pc; idefloppy_mode_parameter_header_t *header; idefloppy_capabilities_page_t *page; floppy->srfp = 0; idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE, MODE_SENSE_CURRENT); set_bit(PC_SUPPRESS_ERROR, &pc.flags); if (idefloppy_queue_pc_tail(drive,&pc)) { return 1; } header = (idefloppy_mode_parameter_header_t *) pc.buffer; page= (idefloppy_capabilities_page_t *)(header+1); floppy->srfp = page->srfp; return (0); } /* * Determine if a media is present in the floppy drive, and if so, * its LBA capacity. */ static int idefloppy_get_capacity (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; idefloppy_pc_t pc; idefloppy_capacity_header_t *header; idefloppy_capacity_descriptor_t *descriptor; int i, descriptors, rc = 1, blocks, length; drive->bios_cyl = 0; drive->bios_head = drive->bios_sect = 0; floppy->blocks = floppy->bs_factor = 0; set_capacity(floppy->disk, 0); idefloppy_create_read_capacity_cmd(&pc); if (idefloppy_queue_pc_tail(drive, &pc)) { printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); return 1; } header = (idefloppy_capacity_header_t *) pc.buffer; descriptors = header->length / sizeof(idefloppy_capacity_descriptor_t); descriptor = (idefloppy_capacity_descriptor_t *) (header + 1); for (i = 0; i < descriptors; i++, descriptor++) { blocks = descriptor->blocks = ntohl(descriptor->blocks); length = descriptor->length = ntohs(descriptor->length); if (!i) { switch (descriptor->dc) { /* Clik! drive returns this instead of CAPACITY_CURRENT */ case CAPACITY_UNFORMATTED: if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) /* * If it is not a clik drive, break out * (maintains previous driver behaviour) */ break; case CAPACITY_CURRENT: /* Normal Zip/LS-120 disks */ if (memcmp(descriptor, &floppy->capacity, sizeof (idefloppy_capacity_descriptor_t))) printk(KERN_INFO "%s: %dkB, %d blocks, %d " "sector size\n", drive->name, blocks * length / 1024, blocks, length); floppy->capacity = *descriptor; if (!length || length % 512) { printk(KERN_NOTICE "%s: %d bytes block size " "not supported\n", drive->name, length); } else { floppy->blocks = blocks; floppy->block_size = length; if ((floppy->bs_factor = length / 512) != 1) printk(KERN_NOTICE "%s: warning: non " "512 bytes block size not " "fully supported\n", drive->name); rc = 0; } break; case CAPACITY_NO_CARTRIDGE: /* * This is a KERN_ERR so it appears on screen * for the user to see */ printk(KERN_ERR "%s: No disk in drive\n", drive->name); break; case CAPACITY_INVALID: printk(KERN_ERR "%s: Invalid capacity for disk " "in drive\n", drive->name); break; } } if (!i) { debug_log( "Descriptor 0 Code: %d\n", descriptor->dc); } debug_log( "Descriptor %d: %dkB, %d blocks, %d " "sector size\n", i, blocks * length / 1024, blocks, length); } /* Clik! disk does not support get_flexible_disk_page */ if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { (void) idefloppy_get_flexible_disk_page(drive); } set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); return rc; } /* ** Obtain the list of formattable capacities. ** Very similar to idefloppy_get_capacity, except that we push the capacity ** descriptors to userland, instead of our own structures. ** ** Userland gives us the following structure: ** ** struct idefloppy_format_capacities { ** int nformats; ** struct { ** int nblocks; ** int blocksize; ** } formats[]; ** } ; ** ** userland initializes nformats to the number of allocated formats[] ** records. On exit we set nformats to the number of records we've ** actually initialized. ** */ static int idefloppy_get_format_capacities(ide_drive_t *drive, int __user *arg) { idefloppy_pc_t pc; idefloppy_capacity_header_t *header; idefloppy_capacity_descriptor_t *descriptor; int i, descriptors, blocks, length; int u_array_size; int u_index; int __user *argp; if (get_user(u_array_size, arg)) return (-EFAULT); if (u_array_size <= 0) return (-EINVAL); idefloppy_create_read_capacity_cmd(&pc); if (idefloppy_queue_pc_tail(drive, &pc)) { printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); return (-EIO); } header = (idefloppy_capacity_header_t *) pc.buffer; descriptors = header->length / sizeof(idefloppy_capacity_descriptor_t); descriptor = (idefloppy_capacity_descriptor_t *) (header + 1); u_index = 0; argp = arg + 1; /* ** We always skip the first capacity descriptor. That's the ** current capacity. We are interested in the remaining descriptors, ** the formattable capacities. */ for (i=0; i<descriptors; i++, descriptor++) { if (u_index >= u_array_size) break; /* User-supplied buffer too small */ if (i == 0) continue; /* Skip the first descriptor */ blocks = ntohl(descriptor->blocks); length = ntohs(descriptor->length); if (put_user(blocks, argp)) return(-EFAULT); ++argp; if (put_user(length, argp)) return (-EFAULT); ++argp; ++u_index; } if (put_user(u_index, arg)) return (-EFAULT); return (0); } /* ** Send ATAPI_FORMAT_UNIT to the drive. ** ** Userland gives us the following structure: ** ** struct idefloppy_format_command { ** int nblocks; ** int blocksize; ** int flags; ** } ; ** ** flags is a bitmask, currently, the only defined flag is: ** ** 0x01 - verify media after format. */ static int idefloppy_begin_format(ide_drive_t *drive, int __user *arg) { int blocks; int length; int flags; idefloppy_pc_t pc; if (get_user(blocks, arg) || get_user(length, arg+1) || get_user(flags, arg+2)) { return (-EFAULT); } /* Get the SFRP bit */ (void) idefloppy_get_capability_page(drive); idefloppy_create_format_unit_cmd(&pc, blocks, length, flags); if (idefloppy_queue_pc_tail(drive, &pc)) { return (-EIO); } return (0); } /* ** Get ATAPI_FORMAT_UNIT progress indication. ** ** Userland gives a pointer to an int. The int is set to a progresss ** indicator 0-65536, with 65536=100%. ** ** If the drive does not support format progress indication, we just check ** the dsc bit, and return either 0 or 65536. */ static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg) { idefloppy_floppy_t *floppy = drive->driver_data; idefloppy_pc_t pc; int progress_indication = 0x10000; if (floppy->srfp) { idefloppy_create_request_sense_cmd(&pc); if (idefloppy_queue_pc_tail(drive, &pc)) { return (-EIO); } if (floppy->sense_key == 2 && floppy->asc == 4 && floppy->ascq == 4) { progress_indication = floppy->progress_indication; } /* Else assume format_unit has finished, and we're ** at 0x10000 */ } else { atapi_status_t status; unsigned long flags; local_irq_save(flags); status.all = HWIF(drive)->INB(IDE_STATUS_REG); local_irq_restore(flags); progress_indication = !status.b.dsc ? 0 : 0x10000; } if (put_user(progress_indication, arg)) return (-EFAULT); return (0); } /* * Return the current floppy capacity. */ static sector_t idefloppy_capacity (ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; unsigned long capacity = floppy->blocks * floppy->bs_factor; return capacity; } /* * idefloppy_identify_device checks if we can support a drive, * based on the ATAPI IDENTIFY command results. */ static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id) { struct idefloppy_id_gcw gcw; #if IDEFLOPPY_DEBUG_INFO u16 mask,i; char buffer[80]; #endif /* IDEFLOPPY_DEBUG_INFO */ *((u16 *) &gcw) = id->config; #ifdef CONFIG_PPC /* kludge for Apple PowerBook internal zip */ if ((gcw.device_type == 5) && !strstr(id->model, "CD-ROM") && strstr(id->model, "ZIP")) gcw.device_type = 0; #endif #if IDEFLOPPY_DEBUG_INFO printk(KERN_INFO "Dumping ATAPI Identify Device floppy parameters\n"); switch (gcw.protocol) { case 0: case 1: sprintf(buffer, "ATA");break; case 2: sprintf(buffer, "ATAPI");break; case 3: sprintf(buffer, "Reserved (Unknown to ide-floppy)");break; } printk(KERN_INFO "Protocol Type: %s\n", buffer); switch (gcw.device_type) { case 0: sprintf(buffer, "Direct-access Device");break; case 1: sprintf(buffer, "Streaming Tape Device");break; case 2: case 3: case 4: sprintf (buffer, "Reserved");break; case 5: sprintf(buffer, "CD-ROM Device");break; case 6: sprintf(buffer, "Reserved"); case 7: sprintf(buffer, "Optical memory Device");break; case 0x1f: sprintf(buffer, "Unknown or no Device type");break; default: sprintf(buffer, "Reserved"); } printk(KERN_INFO "Device Type: %x - %s\n", gcw.device_type, buffer); printk(KERN_INFO "Removable: %s\n",gcw.removable ? "Yes":"No"); switch (gcw.drq_type) { case 0: sprintf(buffer, "Microprocessor DRQ");break; case 1: sprintf(buffer, "Interrupt DRQ");break; case 2: sprintf(buffer, "Accelerated DRQ");break; case 3: sprintf(buffer, "Reserved");break; } printk(KERN_INFO "Command Packet DRQ Type: %s\n", buffer); switch (gcw.packet_size) { case 0: sprintf(buffer, "12 bytes");break; case 1: sprintf(buffer, "16 bytes");break; default: sprintf(buffer, "Reserved");break; } printk(KERN_INFO "Command Packet Size: %s\n", buffer); printk(KERN_INFO "Model: %.40s\n",id->model); printk(KERN_INFO "Firmware Revision: %.8s\n",id->fw_rev); printk(KERN_INFO "Serial Number: %.20s\n",id->serial_no); printk(KERN_INFO "Write buffer size(?): %d bytes\n",id->buf_size*512); printk(KERN_INFO "DMA: %s",id->capability & 0x01 ? "Yes\n":"No\n"); printk(KERN_INFO "LBA: %s",id->capability & 0x02 ? "Yes\n":"No\n"); printk(KERN_INFO "IORDY can be disabled: %s",id->capability & 0x04 ? "Yes\n":"No\n"); printk(KERN_INFO "IORDY supported: %s",id->capability & 0x08 ? "Yes\n":"Unknown\n"); printk(KERN_INFO "ATAPI overlap supported: %s",id->capability & 0x20 ? "Yes\n":"No\n"); printk(KERN_INFO "PIO Cycle Timing Category: %d\n",id->tPIO); printk(KERN_INFO "DMA Cycle Timing Category: %d\n",id->tDMA); printk(KERN_INFO "Single Word DMA supported modes:\n"); for (i=0,mask=1;i<8;i++,mask=mask << 1) { if (id->dma_1word & mask) printk(KERN_INFO " Mode %d%s\n", i, (id->dma_1word & (mask << 8)) ? " (active)" : ""); } printk(KERN_INFO "Multi Word DMA supported modes:\n"); for (i=0,mask=1;i<8;i++,mask=mask << 1) { if (id->dma_mword & mask) printk(KERN_INFO " Mode %d%s\n", i, (id->dma_mword & (mask << 8)) ? " (active)" : ""); } if (id->field_valid & 0x0002) { printk(KERN_INFO "Enhanced PIO Modes: %s\n", id->eide_pio_modes & 1 ? "Mode 3":"None"); if (id->eide_dma_min == 0) sprintf(buffer, "Not supported"); else sprintf(buffer, "%d ns",id->eide_dma_min); printk(KERN_INFO "Minimum Multi-word DMA cycle per word: %s\n", buffer); if (id->eide_dma_time == 0) sprintf(buffer, "Not supported"); else sprintf(buffer, "%d ns",id->eide_dma_time); printk(KERN_INFO "Manufacturer\'s Recommended Multi-word cycle: %s\n", buffer); if (id->eide_pio == 0) sprintf(buffer, "Not supported"); else sprintf(buffer, "%d ns",id->eide_pio); printk(KERN_INFO "Minimum PIO cycle without IORDY: %s\n", buffer); if (id->eide_pio_iordy == 0) sprintf(buffer, "Not supported"); else sprintf(buffer, "%d ns",id->eide_pio_iordy); printk(KERN_INFO "Minimum PIO cycle with IORDY: %s\n", buffer); } else printk(KERN_INFO "According to the device, fields 64-70 are not valid.\n"); #endif /* IDEFLOPPY_DEBUG_INFO */ if (gcw.protocol != 2) printk(KERN_ERR "ide-floppy: Protocol is not ATAPI\n"); else if (gcw.device_type != 0) printk(KERN_ERR "ide-floppy: Device type is not set to floppy\n"); else if (!gcw.removable) printk(KERN_ERR "ide-floppy: The removable flag is not set\n"); else if (gcw.drq_type == 3) { printk(KERN_ERR "ide-floppy: Sorry, DRQ type %d not supported\n", gcw.drq_type); } else if (gcw.packet_size != 0) { printk(KERN_ERR "ide-floppy: Packet size is not 12 bytes long\n"); } else return 1; return 0; } static void idefloppy_add_settings(ide_drive_t *drive) { idefloppy_floppy_t *floppy = drive->driver_data; /* * drive setting name read/write ioctl ioctl data type min max mul_factor div_factor data pointer set function */ ide_add_setting(drive, "bios_cyl", SETTING_RW, -1, -1, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL); ide_add_setting(drive, "bios_head", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL); ide_add_setting(drive, "bios_sect", SETTING_RW, -1, -1, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL); ide_add_setting(drive, "ticks", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &floppy->ticks, NULL); } /* * Driver initialization. */ static void idefloppy_setup (ide_drive_t *drive, idefloppy_floppy_t *floppy) { struct idefloppy_id_gcw gcw; *((u16 *) &gcw) = drive->id->config; floppy->pc = floppy->pc_stack; if (gcw.drq_type == 1) set_bit(IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags); /* * We used to check revisions here. At this point however * I'm giving up. Just assume they are all broken, its easier. * * The actual reason for the workarounds was likely * a driver bug after all rather than a firmware bug, * and the workaround below used to hide it. It should * be fixed as of version 1.9, but to be on the safe side * we'll leave the limitation below for the 2.2.x tree. */ if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) { set_bit(IDEFLOPPY_ZIP_DRIVE, &floppy->flags); /* This value will be visible in the /proc/ide/hdx/settings */ floppy->ticks = IDEFLOPPY_TICKS_DELAY; blk_queue_max_sectors(drive->queue, 64); } /* * Guess what? The IOMEGA Clik! drive also needs the * above fix. It makes nasty clicking noises without * it, so please don't remove this. */ if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) { blk_queue_max_sectors(drive->queue, 64); set_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags); } (void) idefloppy_get_capacity(drive); idefloppy_add_settings(drive); } static int ide_floppy_remove(struct device *dev) { ide_drive_t *drive = to_ide_device(dev); idefloppy_floppy_t *floppy = drive->driver_data; struct gendisk *g = floppy->disk; ide_unregister_subdriver(drive, floppy->driver); del_gendisk(g); ide_floppy_put(floppy); return 0; } static void ide_floppy_release(struct kref *kref) { struct ide_floppy_obj *floppy = to_ide_floppy(kref); ide_drive_t *drive = floppy->drive; struct gendisk *g = floppy->disk; drive->driver_data = NULL; g->private_data = NULL; put_disk(g); kfree(floppy); } #ifdef CONFIG_PROC_FS static int proc_idefloppy_read_capacity (char *page, char **start, off_t off, int count, int *eof, void *data) { ide_drive_t*drive = (ide_drive_t *)data; int len; len = sprintf(page,"%llu\n", (long long)idefloppy_capacity(drive)); PROC_IDE_READ_RETURN(page,start,off,count,eof,len); } static ide_proc_entry_t idefloppy_proc[] = { { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL }, { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, { NULL, 0, NULL, NULL } }; #else #define idefloppy_proc NULL #endif /* CONFIG_PROC_FS */ static int ide_floppy_probe(struct device *); static ide_driver_t idefloppy_driver = { .gen_driver = { .owner = THIS_MODULE, .name = "ide-floppy", .bus = &ide_bus_type, .probe = ide_floppy_probe, .remove = ide_floppy_remove, }, .version = IDEFLOPPY_VERSION, .media = ide_floppy, .supports_dsc_overlap = 0, .do_request = idefloppy_do_request, .end_request = idefloppy_do_end_request, .error = __ide_error, .abort = __ide_abort, .proc = idefloppy_proc, }; static int idefloppy_open(struct inode *inode, struct file *filp) { struct gendisk *disk = inode->i_bdev->bd_disk; struct ide_floppy_obj *floppy; ide_drive_t *drive; idefloppy_pc_t pc; int ret = 0; debug_log(KERN_INFO "Reached idefloppy_open\n"); if (!(floppy = ide_floppy_get(disk))) return -ENXIO; drive = floppy->drive; drive->usage++; if (drive->usage == 1) { clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); /* Just in case */ idefloppy_create_test_unit_ready_cmd(&pc); if (idefloppy_queue_pc_tail(drive, &pc)) { idefloppy_create_start_stop_cmd(&pc, 1); (void) idefloppy_queue_pc_tail(drive, &pc); } if (idefloppy_get_capacity (drive) && (filp->f_flags & O_NDELAY) == 0 /* ** Allow O_NDELAY to open a drive without a disk, or with ** an unreadable disk, so that we can get the format ** capacity of the drive or begin the format - Sam */ ) { drive->usage--; ret = -EIO; goto out_put_floppy; } if (floppy->wp && (filp->f_mode & 2)) { drive->usage--; ret = -EROFS; goto out_put_floppy; } set_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags); /* IOMEGA Clik! drives do not support lock/unlock commands */ if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { idefloppy_create_prevent_cmd(&pc, 1); (void) idefloppy_queue_pc_tail(drive, &pc); } check_disk_change(inode->i_bdev); } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) { drive->usage--; ret = -EBUSY; goto out_put_floppy; } return 0; out_put_floppy: ide_floppy_put(floppy); return ret; } static int idefloppy_release(struct inode *inode, struct file *filp) { struct gendisk *disk = inode->i_bdev->bd_disk; struct ide_floppy_obj *floppy = ide_floppy_g(disk); ide_drive_t *drive = floppy->drive; idefloppy_pc_t pc; debug_log(KERN_INFO "Reached idefloppy_release\n"); if (drive->usage == 1) { /* IOMEGA Clik! drives do not support lock/unlock commands */ if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { idefloppy_create_prevent_cmd(&pc, 0); (void) idefloppy_queue_pc_tail(drive, &pc); } clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); } drive->usage--; ide_floppy_put(floppy); return 0; } static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo) { struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); ide_drive_t *drive = floppy->drive; geo->heads = drive->bios_head; geo->sectors = drive->bios_sect; geo->cylinders = (u16)drive->bios_cyl; /* truncate */ return 0; } static int idefloppy_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { struct block_device *bdev = inode->i_bdev; struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); ide_drive_t *drive = floppy->drive; void __user *argp = (void __user *)arg; int err; int prevent = (arg) ? 1 : 0; idefloppy_pc_t pc; switch (cmd) { case CDROMEJECT: prevent = 0; /* fall through */ case CDROM_LOCKDOOR: if (drive->usage > 1) return -EBUSY; /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */ if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { idefloppy_create_prevent_cmd(&pc, prevent); (void) idefloppy_queue_pc_tail(drive, &pc); } if (cmd == CDROMEJECT) { idefloppy_create_start_stop_cmd(&pc, 2); (void) idefloppy_queue_pc_tail(drive, &pc); } return 0; case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: return 0; case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: return idefloppy_get_format_capacities(drive, argp); case IDEFLOPPY_IOCTL_FORMAT_START: if (!(file->f_mode & 2)) return -EPERM; if (drive->usage > 1) { /* Don't format if someone is using the disk */ clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); return -EBUSY; } set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); err = idefloppy_begin_format(drive, argp); if (err) clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); return err; /* ** Note, the bit will be cleared when the device is ** closed. This is the cleanest way to handle the ** situation where the drive does not support ** format progress reporting. */ case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: return idefloppy_get_format_progress(drive, argp); } return generic_ide_ioctl(drive, file, bdev, cmd, arg); } static int idefloppy_media_changed(struct gendisk *disk) { struct ide_floppy_obj *floppy = ide_floppy_g(disk); ide_drive_t *drive = floppy->drive; /* do not scan partitions twice if this is a removable device */ if (drive->attach) { drive->attach = 0; return 0; } return test_and_clear_bit(IDEFLOPPY_MEDIA_CHANGED, &floppy->flags); } static int idefloppy_revalidate_disk(struct gendisk *disk) { struct ide_floppy_obj *floppy = ide_floppy_g(disk); set_capacity(disk, idefloppy_capacity(floppy->drive)); return 0; } static struct block_device_operations idefloppy_ops = { .owner = THIS_MODULE, .open = idefloppy_open, .release = idefloppy_release, .ioctl = idefloppy_ioctl, .getgeo = idefloppy_getgeo, .media_changed = idefloppy_media_changed, .revalidate_disk= idefloppy_revalidate_disk }; static int ide_floppy_probe(struct device *dev) { ide_drive_t *drive = to_ide_device(dev); idefloppy_floppy_t *floppy; struct gendisk *g; if (!strstr("ide-floppy", drive->driver_req)) goto failed; if (!drive->present) goto failed; if (drive->media != ide_floppy) goto failed; if (!idefloppy_identify_device (drive, drive->id)) { printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name); goto failed; }