aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-tape.c
diff options
context:
space:
mode:
authorAnton Vorontsov <cbouatmailru@gmail.com>2008-07-29 18:05:23 -0400
committerAnton Vorontsov <cbouatmailru@gmail.com>2008-07-29 18:05:23 -0400
commit9fec6060d9e48ed7db0dac0e16d0f0f0e615b7f6 (patch)
tree74b41f31a08f6500ff3dfcf64ba21e2d9a8e87e5 /drivers/ide/ide-tape.c
parentfece418418f51e92dd7e67e17c5e3fe5a28d3279 (diff)
parent6e86841d05f371b5b9b86ce76c02aaee83352298 (diff)
Merge branch 'master' of /home/cbou/linux-2.6
Conflicts: drivers/power/Kconfig drivers/power/Makefile
Diffstat (limited to 'drivers/ide/ide-tape.c')
-rw-r--r--drivers/ide/ide-tape.c698
1 files changed, 224 insertions, 474 deletions
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 1e1f26331a24..82c2afe4d28a 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -144,9 +144,6 @@ enum {
144 144
145/*************************** End of tunable parameters ***********************/ 145/*************************** End of tunable parameters ***********************/
146 146
147/* Read/Write error simulation */
148#define SIMULATE_ERRORS 0
149
150/* tape directions */ 147/* tape directions */
151enum { 148enum {
152 IDETAPE_DIR_NONE = (1 << 0), 149 IDETAPE_DIR_NONE = (1 << 0),
@@ -198,23 +195,6 @@ enum {
198#define IDETAPE_BLOCK_DESCRIPTOR 0 195#define IDETAPE_BLOCK_DESCRIPTOR 0
199#define IDETAPE_CAPABILITIES_PAGE 0x2a 196#define IDETAPE_CAPABILITIES_PAGE 0x2a
200 197
201/* Tape flag bits values. */
202enum {
203 IDETAPE_FLAG_IGNORE_DSC = (1 << 0),
204 /* 0 When the tape position is unknown */
205 IDETAPE_FLAG_ADDRESS_VALID = (1 << 1),
206 /* Device already opened */
207 IDETAPE_FLAG_BUSY = (1 << 2),
208 /* Attempt to auto-detect the current user block size */
209 IDETAPE_FLAG_DETECT_BS = (1 << 3),
210 /* Currently on a filemark */
211 IDETAPE_FLAG_FILEMARK = (1 << 4),
212 /* DRQ interrupt device */
213 IDETAPE_FLAG_DRQ_INTERRUPT = (1 << 5),
214 /* 0 = no tape is loaded, so we don't rewind after ejecting */
215 IDETAPE_FLAG_MEDIUM_PRESENT = (1 << 6),
216};
217
218/* 198/*
219 * Most of our global data which we need to save even as we leave the driver due 199 * Most of our global data which we need to save even as we leave the driver due
220 * to an interrupt or a timer event is stored in the struct defined below. 200 * to an interrupt or a timer event is stored in the struct defined below.
@@ -315,8 +295,6 @@ typedef struct ide_tape_obj {
315 /* Wasted space in each stage */ 295 /* Wasted space in each stage */
316 int excess_bh_size; 296 int excess_bh_size;
317 297
318 /* Status/Action flags: long for set_bit */
319 unsigned long flags;
320 /* protects the ide-tape queue */ 298 /* protects the ide-tape queue */
321 spinlock_t lock; 299 spinlock_t lock;
322 300
@@ -344,23 +322,29 @@ static struct class *idetape_sysfs_class;
344#define ide_tape_g(disk) \ 322#define ide_tape_g(disk) \
345 container_of((disk)->private_data, struct ide_tape_obj, driver) 323 container_of((disk)->private_data, struct ide_tape_obj, driver)
346 324
325static void ide_tape_release(struct kref *);
326
347static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) 327static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
348{ 328{
349 struct ide_tape_obj *tape = NULL; 329 struct ide_tape_obj *tape = NULL;
350 330
351 mutex_lock(&idetape_ref_mutex); 331 mutex_lock(&idetape_ref_mutex);
352 tape = ide_tape_g(disk); 332 tape = ide_tape_g(disk);
353 if (tape) 333 if (tape) {
354 kref_get(&tape->kref); 334 kref_get(&tape->kref);
335 if (ide_device_get(tape->drive)) {
336 kref_put(&tape->kref, ide_tape_release);
337 tape = NULL;
338 }
339 }
355 mutex_unlock(&idetape_ref_mutex); 340 mutex_unlock(&idetape_ref_mutex);
356 return tape; 341 return tape;
357} 342}
358 343
359static void ide_tape_release(struct kref *);
360
361static void ide_tape_put(struct ide_tape_obj *tape) 344static void ide_tape_put(struct ide_tape_obj *tape)
362{ 345{
363 mutex_lock(&idetape_ref_mutex); 346 mutex_lock(&idetape_ref_mutex);
347 ide_device_put(tape->drive);
364 kref_put(&tape->kref, ide_tape_release); 348 kref_put(&tape->kref, ide_tape_release);
365 mutex_unlock(&idetape_ref_mutex); 349 mutex_unlock(&idetape_ref_mutex);
366} 350}
@@ -401,7 +385,7 @@ static void idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
401 count = min( 385 count = min(
402 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)), 386 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
403 bcount); 387 bcount);
404 drive->hwif->input_data(drive, NULL, bh->b_data + 388 drive->hwif->tp_ops->input_data(drive, NULL, bh->b_data +
405 atomic_read(&bh->b_count), count); 389 atomic_read(&bh->b_count), count);
406 bcount -= count; 390 bcount -= count;
407 atomic_add(count, &bh->b_count); 391 atomic_add(count, &bh->b_count);
@@ -427,7 +411,7 @@ static void idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
427 return; 411 return;
428 } 412 }
429 count = min((unsigned int)pc->b_count, (unsigned int)bcount); 413 count = min((unsigned int)pc->b_count, (unsigned int)bcount);
430 drive->hwif->output_data(drive, NULL, pc->b_data, count); 414 drive->hwif->tp_ops->output_data(drive, NULL, pc->b_data, count);
431 bcount -= count; 415 bcount -= count;
432 pc->b_data += count; 416 pc->b_data += count;
433 pc->b_count -= count; 417 pc->b_count -= count;
@@ -442,7 +426,7 @@ static void idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
442 } 426 }
443} 427}
444 428
445static void idetape_update_buffers(struct ide_atapi_pc *pc) 429static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
446{ 430{
447 struct idetape_bh *bh = pc->bh; 431 struct idetape_bh *bh = pc->bh;
448 int count; 432 int count;
@@ -506,18 +490,6 @@ static struct request *idetape_next_rq_storage(ide_drive_t *drive)
506 return (&tape->rq_stack[tape->rq_stack_index++]); 490 return (&tape->rq_stack[tape->rq_stack_index++]);
507} 491}
508 492
509static void idetape_init_pc(struct ide_atapi_pc *pc)
510{
511 memset(pc->c, 0, 12);
512 pc->retries = 0;
513 pc->flags = 0;
514 pc->req_xfer = 0;
515 pc->buf = pc->pc_buf;
516 pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
517 pc->bh = NULL;
518 pc->b_data = NULL;
519}
520
521/* 493/*
522 * called on each failed packet command retry to analyze the request sense. We 494 * called on each failed packet command retry to analyze the request sense. We
523 * currently do not utilize this information. 495 * currently do not utilize this information.
@@ -538,8 +510,8 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
538 if (pc->flags & PC_FLAG_DMA_ERROR) { 510 if (pc->flags & PC_FLAG_DMA_ERROR) {
539 pc->xferred = pc->req_xfer - 511 pc->xferred = pc->req_xfer -
540 tape->blk_size * 512 tape->blk_size *
541 be32_to_cpu(get_unaligned((u32 *)&sense[3])); 513 get_unaligned_be32(&sense[3]);
542 idetape_update_buffers(pc); 514 idetape_update_buffers(drive, pc);
543 } 515 }
544 516
545 /* 517 /*
@@ -600,7 +572,6 @@ static void ide_tape_kfree_buffer(idetape_tape_t *tape)
600 bh = bh->b_reqnext; 572 bh = bh->b_reqnext;
601 kfree(prev_bh); 573 kfree(prev_bh);
602 } 574 }
603 kfree(tape->merge_bh);
604} 575}
605 576
606static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) 577static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
@@ -634,21 +605,77 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
634 return 0; 605 return 0;
635} 606}
636 607
637static ide_startstop_t idetape_request_sense_callback(ide_drive_t *drive) 608static void ide_tape_callback(ide_drive_t *drive)
638{ 609{
639 idetape_tape_t *tape = drive->driver_data; 610 idetape_tape_t *tape = drive->driver_data;
611 struct ide_atapi_pc *pc = tape->pc;
612 int uptodate = pc->error ? 0 : 1;
640 613
641 debug_log(DBG_PROCS, "Enter %s\n", __func__); 614 debug_log(DBG_PROCS, "Enter %s\n", __func__);
642 615
643 if (!tape->pc->error) { 616 if (tape->failed_pc == pc)
644 idetape_analyze_error(drive, tape->pc->buf); 617 tape->failed_pc = NULL;
645 idetape_end_request(drive, 1, 0); 618
646 } else { 619 if (pc->c[0] == REQUEST_SENSE) {
647 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - " 620 if (uptodate)
648 "Aborting request!\n"); 621 idetape_analyze_error(drive, pc->buf);
649 idetape_end_request(drive, 0, 0); 622 else
623 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
624 "itself - Aborting request!\n");
625 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
626 struct request *rq = drive->hwif->hwgroup->rq;
627 int blocks = pc->xferred / tape->blk_size;
628
629 tape->avg_size += blocks * tape->blk_size;
630
631 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
632 tape->avg_speed = tape->avg_size * HZ /
633 (jiffies - tape->avg_time) / 1024;
634 tape->avg_size = 0;
635 tape->avg_time = jiffies;
636 }
637
638 tape->first_frame += blocks;
639 rq->current_nr_sectors -= blocks;
640
641 if (pc->error)
642 uptodate = pc->error;
643 } else if (pc->c[0] == READ_POSITION && uptodate) {
644 u8 *readpos = tape->pc->buf;
645
646 debug_log(DBG_SENSE, "BOP - %s\n",
647 (readpos[0] & 0x80) ? "Yes" : "No");
648 debug_log(DBG_SENSE, "EOP - %s\n",
649 (readpos[0] & 0x40) ? "Yes" : "No");
650
651 if (readpos[0] & 0x4) {
652 printk(KERN_INFO "ide-tape: Block location is unknown"
653 "to the tape\n");
654 clear_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
655 uptodate = 0;
656 } else {
657 debug_log(DBG_SENSE, "Block Location - %u\n",
658 be32_to_cpup((__be32 *)&readpos[4]));
659
660 tape->partition = readpos[1];
661 tape->first_frame = be32_to_cpup((__be32 *)&readpos[4]);
662 set_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
663 }
650 } 664 }
651 return ide_stopped; 665
666 idetape_end_request(drive, uptodate, 0);
667}
668
669static void idetape_init_pc(struct ide_atapi_pc *pc)
670{
671 memset(pc->c, 0, 12);
672 pc->retries = 0;
673 pc->flags = 0;
674 pc->req_xfer = 0;
675 pc->buf = pc->pc_buf;
676 pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
677 pc->bh = NULL;
678 pc->b_data = NULL;
652} 679}
653 680
654static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc) 681static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
@@ -657,14 +684,13 @@ static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
657 pc->c[0] = REQUEST_SENSE; 684 pc->c[0] = REQUEST_SENSE;
658 pc->c[4] = 20; 685 pc->c[4] = 20;
659 pc->req_xfer = 20; 686 pc->req_xfer = 20;
660 pc->idetape_callback = &idetape_request_sense_callback;
661} 687}
662 688
663static void idetape_init_rq(struct request *rq, u8 cmd) 689static void idetape_init_rq(struct request *rq, u8 cmd)
664{ 690{
665 blk_rq_init(NULL, rq); 691 blk_rq_init(NULL, rq);
666 rq->cmd_type = REQ_TYPE_SPECIAL; 692 rq->cmd_type = REQ_TYPE_SPECIAL;
667 rq->cmd[0] = cmd; 693 rq->cmd[13] = cmd;
668} 694}
669 695
670/* 696/*
@@ -688,9 +714,11 @@ static void idetape_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
688 struct ide_tape_obj *tape = drive->driver_data; 714 struct ide_tape_obj *tape = drive->driver_data;
689 715
690 idetape_init_rq(rq, REQ_IDETAPE_PC1); 716 idetape_init_rq(rq, REQ_IDETAPE_PC1);
717 rq->cmd_flags |= REQ_PREEMPT;
691 rq->buffer = (char *) pc; 718 rq->buffer = (char *) pc;
692 rq->rq_disk = tape->disk; 719 rq->rq_disk = tape->disk;
693 (void) ide_do_drive_cmd(drive, rq, ide_preempt); 720 memcpy(rq->cmd, pc->c, 12);
721 ide_do_drive_cmd(drive, rq);
694} 722}
695 723
696/* 724/*
@@ -698,9 +726,8 @@ static void idetape_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
698 * last packet command. We queue a request sense packet command in 726 * last packet command. We queue a request sense packet command in
699 * the head of the request list. 727 * the head of the request list.
700 */ 728 */
701static ide_startstop_t idetape_retry_pc (ide_drive_t *drive) 729static void idetape_retry_pc(ide_drive_t *drive)
702{ 730{
703 idetape_tape_t *tape = drive->driver_data;
704 struct ide_atapi_pc *pc; 731 struct ide_atapi_pc *pc;
705 struct request *rq; 732 struct request *rq;
706 733
@@ -708,9 +735,8 @@ static ide_startstop_t idetape_retry_pc (ide_drive_t *drive)
708 pc = idetape_next_pc_storage(drive); 735 pc = idetape_next_pc_storage(drive);
709 rq = idetape_next_rq_storage(drive); 736 rq = idetape_next_rq_storage(drive);
710 idetape_create_request_sense_cmd(pc); 737 idetape_create_request_sense_cmd(pc);
711 set_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags); 738 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
712 idetape_queue_pc_head(drive, pc, rq); 739 idetape_queue_pc_head(drive, pc, rq);
713 return ide_stopped;
714} 740}
715 741
716/* 742/*
@@ -727,7 +753,26 @@ static void idetape_postpone_request(ide_drive_t *drive)
727 ide_stall_queue(drive, tape->dsc_poll_freq); 753 ide_stall_queue(drive, tape->dsc_poll_freq);
728} 754}
729 755
730typedef void idetape_io_buf(ide_drive_t *, struct ide_atapi_pc *, unsigned int); 756static void ide_tape_handle_dsc(ide_drive_t *drive)
757{
758 idetape_tape_t *tape = drive->driver_data;
759
760 /* Media access command */
761 tape->dsc_polling_start = jiffies;
762 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
763 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
764 /* Allow ide.c to handle other requests */
765 idetape_postpone_request(drive);
766}
767
768static void ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
769 unsigned int bcount, int write)
770{
771 if (write)
772 idetape_output_buffers(drive, pc, bcount);
773 else
774 idetape_input_buffers(drive, pc, bcount);
775}
731 776
732/* 777/*
733 * This is the usual interrupt handler which will be called during a packet 778 * This is the usual interrupt handler which will be called during a packet
@@ -738,169 +783,11 @@ typedef void idetape_io_buf(ide_drive_t *, struct ide_atapi_pc *, unsigned int);
738 */ 783 */
739static ide_startstop_t idetape_pc_intr(ide_drive_t *drive) 784static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
740{ 785{
741 ide_hwif_t *hwif = drive->hwif;
742 idetape_tape_t *tape = drive->driver_data; 786 idetape_tape_t *tape = drive->driver_data;
743 struct ide_atapi_pc *pc = tape->pc;
744 xfer_func_t *xferfunc;
745 idetape_io_buf *iobuf;
746 unsigned int temp;
747#if SIMULATE_ERRORS
748 static int error_sim_count;
749#endif
750 u16 bcount;
751 u8 stat, ireason;
752
753 debug_log(DBG_PROCS, "Enter %s - interrupt handler\n", __func__);
754
755 /* Clear the interrupt */
756 stat = ide_read_status(drive);
757
758 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
759 if (hwif->dma_ops->dma_end(drive) || (stat & ERR_STAT)) {
760 /*
761 * A DMA error is sometimes expected. For example,
762 * if the tape is crossing a filemark during a
763 * READ command, it will issue an irq and position
764 * itself before the filemark, so that only a partial
765 * data transfer will occur (which causes the DMA
766 * error). In that case, we will later ask the tape
767 * how much bytes of the original request were
768 * actually transferred (we can't receive that
769 * information from the DMA engine on most chipsets).
770 */
771
772 /*
773 * On the contrary, a DMA error is never expected;
774 * it usually indicates a hardware error or abort.
775 * If the tape crosses a filemark during a READ
776 * command, it will issue an irq and position itself
777 * after the filemark (not before). Only a partial
778 * data transfer will occur, but no DMA error.
779 * (AS, 19 Apr 2001)
780 */
781 pc->flags |= PC_FLAG_DMA_ERROR;
782 } else {
783 pc->xferred = pc->req_xfer;
784 idetape_update_buffers(pc);
785 }
786 debug_log(DBG_PROCS, "DMA finished\n");
787
788 }
789
790 /* No more interrupts */
791 if ((stat & DRQ_STAT) == 0) {
792 debug_log(DBG_SENSE, "Packet command completed, %d bytes"
793 " transferred\n", pc->xferred);
794
795 pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
796 local_irq_enable();
797
798#if SIMULATE_ERRORS
799 if ((pc->c[0] == WRITE_6 || pc->c[0] == READ_6) &&
800 (++error_sim_count % 100) == 0) {
801 printk(KERN_INFO "ide-tape: %s: simulating error\n",
802 tape->name);
803 stat |= ERR_STAT;
804 }
805#endif
806 if ((stat & ERR_STAT) && pc->c[0] == REQUEST_SENSE)
807 stat &= ~ERR_STAT;
808 if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR)) {
809 /* Error detected */
810 debug_log(DBG_ERR, "%s: I/O error\n", tape->name);
811
812 if (pc->c[0] == REQUEST_SENSE) {
813 printk(KERN_ERR "ide-tape: I/O error in request"
814 " sense command\n");
815 return ide_do_reset(drive);
816 }
817 debug_log(DBG_ERR, "[cmd %x]: check condition\n",
818 pc->c[0]);
819
820 /* Retry operation */
821 return idetape_retry_pc(drive);
822 }
823 pc->error = 0;
824 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) &&
825 (stat & SEEK_STAT) == 0) {
826 /* Media access command */
827 tape->dsc_polling_start = jiffies;
828 tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
829 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
830 /* Allow ide.c to handle other requests */
831 idetape_postpone_request(drive);
832 return ide_stopped;
833 }
834 if (tape->failed_pc == pc)
835 tape->failed_pc = NULL;
836 /* Command finished - Call the callback function */
837 return pc->idetape_callback(drive);
838 }
839
840 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
841 pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
842 printk(KERN_ERR "ide-tape: The tape wants to issue more "
843 "interrupts in DMA mode\n");
844 printk(KERN_ERR "ide-tape: DMA disabled, reverting to PIO\n");
845 ide_dma_off(drive);
846 return ide_do_reset(drive);
847 }
848 /* Get the number of bytes to transfer on this interrupt. */
849 bcount = (hwif->INB(hwif->io_ports.lbah_addr) << 8) |
850 hwif->INB(hwif->io_ports.lbam_addr);
851
852 ireason = hwif->INB(hwif->io_ports.nsect_addr);
853
854 if (ireason & CD) {
855 printk(KERN_ERR "ide-tape: CoD != 0 in %s\n", __func__);
856 return ide_do_reset(drive);
857 }
858 if (((ireason & IO) == IO) == !!(pc->flags & PC_FLAG_WRITING)) {
859 /* Hopefully, we will never get here */
860 printk(KERN_ERR "ide-tape: We wanted to %s, ",
861 (ireason & IO) ? "Write" : "Read");
862 printk(KERN_ERR "ide-tape: but the tape wants us to %s !\n",
863 (ireason & IO) ? "Read" : "Write");
864 return ide_do_reset(drive);
865 }
866 if (!(pc->flags & PC_FLAG_WRITING)) {
867 /* Reading - Check that we have enough space */
868 temp = pc->xferred + bcount;
869 if (temp > pc->req_xfer) {
870 if (temp > pc->buf_size) {
871 printk(KERN_ERR "ide-tape: The tape wants to "
872 "send us more data than expected "
873 "- discarding data\n");
874 ide_pad_transfer(drive, 0, bcount);
875 ide_set_handler(drive, &idetape_pc_intr,
876 IDETAPE_WAIT_CMD, NULL);
877 return ide_started;
878 }
879 debug_log(DBG_SENSE, "The tape wants to send us more "
880 "data than expected - allowing transfer\n");
881 }
882 iobuf = &idetape_input_buffers;
883 xferfunc = hwif->input_data;
884 } else {
885 iobuf = &idetape_output_buffers;
886 xferfunc = hwif->output_data;
887 }
888
889 if (pc->bh)
890 iobuf(drive, pc, bcount);
891 else
892 xferfunc(drive, NULL, pc->cur_pos, bcount);
893
894 /* Update the current position */
895 pc->xferred += bcount;
896 pc->cur_pos += bcount;
897 787
898 debug_log(DBG_SENSE, "[cmd %x] transferred %d bytes on that intr.\n", 788 return ide_pc_intr(drive, tape->pc, idetape_pc_intr, IDETAPE_WAIT_CMD,
899 pc->c[0], bcount); 789 NULL, idetape_update_buffers, idetape_retry_pc,
900 790 ide_tape_handle_dsc, ide_tape_io_buffers);
901 /* And set the interrupt handler again */
902 ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL);
903 return ide_started;
904} 791}
905 792
906/* 793/*
@@ -941,56 +828,16 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
941 */ 828 */
942static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive) 829static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
943{ 830{
944 ide_hwif_t *hwif = drive->hwif;
945 idetape_tape_t *tape = drive->driver_data; 831 idetape_tape_t *tape = drive->driver_data;
946 struct ide_atapi_pc *pc = tape->pc;
947 int retries = 100;
948 ide_startstop_t startstop;
949 u8 ireason;
950
951 if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
952 printk(KERN_ERR "ide-tape: Strange, packet command initiated "
953 "yet DRQ isn't asserted\n");
954 return startstop;
955 }
956 ireason = hwif->INB(hwif->io_ports.nsect_addr);
957 while (retries-- && ((ireason & CD) == 0 || (ireason & IO))) {
958 printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while issuing "
959 "a packet command, retrying\n");
960 udelay(100);
961 ireason = hwif->INB(hwif->io_ports.nsect_addr);
962 if (retries == 0) {
963 printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while "
964 "issuing a packet command, ignoring\n");
965 ireason |= CD;
966 ireason &= ~IO;
967 }
968 }
969 if ((ireason & CD) == 0 || (ireason & IO)) {
970 printk(KERN_ERR "ide-tape: (IO,CoD) != (0,1) while issuing "
971 "a packet command\n");
972 return ide_do_reset(drive);
973 }
974 /* Set the interrupt routine */
975 ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD, NULL);
976#ifdef CONFIG_BLK_DEV_IDEDMA
977 /* Begin DMA, if necessary */
978 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS)
979 hwif->dma_ops->dma_start(drive);
980#endif
981 /* Send the actual packet */
982 hwif->output_data(drive, NULL, pc->c, 12);
983 832
984 return ide_started; 833 return ide_transfer_pc(drive, tape->pc, idetape_pc_intr,
834 IDETAPE_WAIT_CMD, NULL);
985} 835}
986 836
987static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, 837static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
988 struct ide_atapi_pc *pc) 838 struct ide_atapi_pc *pc)
989{ 839{
990 ide_hwif_t *hwif = drive->hwif;
991 idetape_tape_t *tape = drive->driver_data; 840 idetape_tape_t *tape = drive->driver_data;
992 int dma_ok = 0;
993 u16 bcount;
994 841
995 if (tape->pc->c[0] == REQUEST_SENSE && 842 if (tape->pc->c[0] == REQUEST_SENSE &&
996 pc->c[0] == REQUEST_SENSE) { 843 pc->c[0] == REQUEST_SENSE) {
@@ -1025,50 +872,15 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
1025 pc->error = IDETAPE_ERROR_GENERAL; 872 pc->error = IDETAPE_ERROR_GENERAL;
1026 } 873 }
1027 tape->failed_pc = NULL; 874 tape->failed_pc = NULL;
1028 return pc->idetape_callback(drive); 875 drive->pc_callback(drive);
876 return ide_stopped;
1029 } 877 }
1030 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); 878 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
1031 879
1032 pc->retries++; 880 pc->retries++;
1033 /* We haven't transferred any data yet */
1034 pc->xferred = 0;
1035 pc->cur_pos = pc->buf;
1036 /* Request to transfer the entire buffer at once */
1037 bcount = pc->req_xfer;
1038 881
1039 if (pc->flags & PC_FLAG_DMA_ERROR) { 882 return ide_issue_pc(drive, pc, idetape_transfer_pc,
1040 pc->flags &= ~PC_FLAG_DMA_ERROR; 883 IDETAPE_WAIT_CMD, NULL);
1041 printk(KERN_WARNING "ide-tape: DMA disabled, "
1042 "reverting to PIO\n");
1043 ide_dma_off(drive);
1044 }
1045 if ((pc->flags & PC_FLAG_DMA_RECOMMENDED) && drive->using_dma)
1046 dma_ok = !hwif->dma_ops->dma_setup(drive);
1047
1048 ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK |
1049 IDE_TFLAG_OUT_DEVICE, bcount, dma_ok);
1050
1051 if (dma_ok)
1052 /* Will begin DMA later */
1053 pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
1054 if (test_bit(IDETAPE_FLAG_DRQ_INTERRUPT, &tape->flags)) {
1055 ide_execute_command(drive, WIN_PACKETCMD, &idetape_transfer_pc,
1056 IDETAPE_WAIT_CMD, NULL);
1057 return ide_started;
1058 } else {
1059 ide_execute_pkt_cmd(drive);
1060 return idetape_transfer_pc(drive);
1061 }
1062}
1063
1064static ide_startstop_t idetape_pc_callback(ide_drive_t *drive)
1065{
1066 idetape_tape_t *tape = drive->driver_data;
1067
1068 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1069
1070 idetape_end_request(drive, tape->pc->error ? 0 : 1, 0);
1071 return ide_stopped;
1072} 884}
1073 885
1074/* A mode sense command is used to "sense" tape parameters. */ 886/* A mode sense command is used to "sense" tape parameters. */
@@ -1096,16 +908,16 @@ static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
1096 pc->req_xfer = 24; 908 pc->req_xfer = 24;
1097 else 909 else
1098 pc->req_xfer = 50; 910 pc->req_xfer = 50;
1099 pc->idetape_callback = &idetape_pc_callback;
1100} 911}
1101 912
1102static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive) 913static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
1103{ 914{
915 ide_hwif_t *hwif = drive->hwif;
1104 idetape_tape_t *tape = drive->driver_data; 916 idetape_tape_t *tape = drive->driver_data;
1105 struct ide_atapi_pc *pc = tape->pc; 917 struct ide_atapi_pc *pc = tape->pc;
1106 u8 stat; 918 u8 stat;
1107 919
1108 stat = ide_read_status(drive); 920 stat = hwif->tp_ops->read_status(hwif);
1109 921
1110 if (stat & SEEK_STAT) { 922 if (stat & SEEK_STAT) {
1111 if (stat & ERR_STAT) { 923 if (stat & ERR_STAT) {
@@ -1114,85 +926,52 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
1114 printk(KERN_ERR "ide-tape: %s: I/O error, ", 926 printk(KERN_ERR "ide-tape: %s: I/O error, ",
1115 tape->name); 927 tape->name);
1116 /* Retry operation */ 928 /* Retry operation */
1117 return idetape_retry_pc(drive); 929 idetape_retry_pc(drive);
930 return ide_stopped;
1118 } 931 }
1119 pc->error = 0; 932 pc->error = 0;
1120 if (tape->failed_pc == pc)
1121 tape->failed_pc = NULL;
1122 } else { 933 } else {
1123 pc->error = IDETAPE_ERROR_GENERAL; 934 pc->error = IDETAPE_ERROR_GENERAL;
1124 tape->failed_pc = NULL; 935 tape->failed_pc = NULL;
1125 } 936 }
1126 return pc->idetape_callback(drive); 937 drive->pc_callback(drive);
1127}
1128
1129static ide_startstop_t idetape_rw_callback(ide_drive_t *drive)
1130{
1131 idetape_tape_t *tape = drive->driver_data;
1132 struct request *rq = HWGROUP(drive)->rq;
1133 int blocks = tape->pc->xferred / tape->blk_size;
1134
1135 tape->avg_size += blocks * tape->blk_size;
1136
1137 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
1138 tape->avg_speed = tape->avg_size * HZ /
1139 (jiffies - tape->avg_time) / 1024;
1140 tape->avg_size = 0;
1141 tape->avg_time = jiffies;
1142 }
1143 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1144
1145 tape->first_frame += blocks;
1146 rq->current_nr_sectors -= blocks;
1147
1148 if (!tape->pc->error)
1149 idetape_end_request(drive, 1, 0);
1150 else
1151 idetape_end_request(drive, tape->pc->error, 0);
1152 return ide_stopped; 938 return ide_stopped;
1153} 939}
1154 940
1155static void idetape_create_read_cmd(idetape_tape_t *tape, 941static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
1156 struct ide_atapi_pc *pc, 942 struct ide_atapi_pc *pc, struct request *rq,
1157 unsigned int length, struct idetape_bh *bh) 943 u8 opcode)
1158{ 944{
1159 idetape_init_pc(pc); 945 struct idetape_bh *bh = (struct idetape_bh *)rq->special;
1160 pc->c[0] = READ_6; 946 unsigned int length = rq->current_nr_sectors;
1161 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
1162 pc->c[1] = 1;
1163 pc->idetape_callback = &idetape_rw_callback;
1164 pc->bh = bh;
1165 atomic_set(&bh->b_count, 0);
1166 pc->buf = NULL;
1167 pc->buf_size = length * tape->blk_size;
1168 pc->req_xfer = pc->buf_size;
1169 if (pc->req_xfer == tape->buffer_size)
1170 pc->flags |= PC_FLAG_DMA_RECOMMENDED;
1171}
1172 947
1173static void idetape_create_write_cmd(idetape_tape_t *tape,
1174 struct ide_atapi_pc *pc,
1175 unsigned int length, struct idetape_bh *bh)
1176{
1177 idetape_init_pc(pc); 948 idetape_init_pc(pc);
1178 pc->c[0] = WRITE_6;
1179 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 949 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
1180 pc->c[1] = 1; 950 pc->c[1] = 1;
1181 pc->idetape_callback = &idetape_rw_callback;
1182 pc->flags |= PC_FLAG_WRITING;
1183 pc->bh = bh; 951 pc->bh = bh;
1184 pc->b_data = bh->b_data;
1185 pc->b_count = atomic_read(&bh->b_count);
1186 pc->buf = NULL; 952 pc->buf = NULL;
1187 pc->buf_size = length * tape->blk_size; 953 pc->buf_size = length * tape->blk_size;
1188 pc->req_xfer = pc->buf_size; 954 pc->req_xfer = pc->buf_size;
1189 if (pc->req_xfer == tape->buffer_size) 955 if (pc->req_xfer == tape->buffer_size)
1190 pc->flags |= PC_FLAG_DMA_RECOMMENDED; 956 pc->flags |= PC_FLAG_DMA_OK;
957
958 if (opcode == READ_6) {
959 pc->c[0] = READ_6;
960 atomic_set(&bh->b_count, 0);
961 } else if (opcode == WRITE_6) {
962 pc->c[0] = WRITE_6;
963 pc->flags |= PC_FLAG_WRITING;
964 pc->b_data = bh->b_data;
965 pc->b_count = atomic_read(&bh->b_count);
966 }
967
968 memcpy(rq->cmd, pc->c, 12);
1191} 969}
1192 970
1193static ide_startstop_t idetape_do_request(ide_drive_t *drive, 971static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1194 struct request *rq, sector_t block) 972 struct request *rq, sector_t block)
1195{ 973{
974 ide_hwif_t *hwif = drive->hwif;
1196 idetape_tape_t *tape = drive->driver_data; 975 idetape_tape_t *tape = drive->driver_data;
1197 struct ide_atapi_pc *pc = NULL; 976 struct ide_atapi_pc *pc = NULL;
1198 struct request *postponed_rq = tape->postponed_rq; 977 struct request *postponed_rq = tape->postponed_rq;
@@ -1211,8 +990,10 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1211 } 990 }
1212 991
1213 /* Retry a failed packet command */ 992 /* Retry a failed packet command */
1214 if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE) 993 if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE) {
1215 return idetape_issue_pc(drive, tape->failed_pc); 994 pc = tape->failed_pc;
995 goto out;
996 }
1216 997
1217 if (postponed_rq != NULL) 998 if (postponed_rq != NULL)
1218 if (rq != postponed_rq) { 999 if (rq != postponed_rq) {
@@ -1228,17 +1009,17 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1228 * If the tape is still busy, postpone our request and service 1009 * If the tape is still busy, postpone our request and service
1229 * the other device meanwhile. 1010 * the other device meanwhile.
1230 */ 1011 */
1231 stat = ide_read_status(drive); 1012 stat = hwif->tp_ops->read_status(hwif);
1232 1013
1233 if (!drive->dsc_overlap && !(rq->cmd[0] & REQ_IDETAPE_PC2)) 1014 if (!drive->dsc_overlap && !(rq->cmd[13] & REQ_IDETAPE_PC2))
1234 set_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags); 1015 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
1235 1016
1236 if (drive->post_reset == 1) { 1017 if (drive->post_reset == 1) {
1237 set_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags); 1018 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
1238 drive->post_reset = 0; 1019 drive->post_reset = 0;
1239 } 1020 }
1240 1021
1241 if (!test_and_clear_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags) && 1022 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
1242 (stat & SEEK_STAT) == 0) { 1023 (stat & SEEK_STAT) == 0) {
1243 if (postponed_rq == NULL) { 1024 if (postponed_rq == NULL) {
1244 tape->dsc_polling_start = jiffies; 1025 tape->dsc_polling_start = jiffies;
@@ -1247,7 +1028,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1247 } else if (time_after(jiffies, tape->dsc_timeout)) { 1028 } else if (time_after(jiffies, tape->dsc_timeout)) {
1248 printk(KERN_ERR "ide-tape: %s: DSC timeout\n", 1029 printk(KERN_ERR "ide-tape: %s: DSC timeout\n",
1249 tape->name); 1030 tape->name);
1250 if (rq->cmd[0] & REQ_IDETAPE_PC2) { 1031 if (rq->cmd[13] & REQ_IDETAPE_PC2) {
1251 idetape_media_access_finished(drive); 1032 idetape_media_access_finished(drive);
1252 return ide_stopped; 1033 return ide_stopped;
1253 } else { 1034 } else {
@@ -1260,29 +1041,28 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1260 idetape_postpone_request(drive); 1041 idetape_postpone_request(drive);
1261 return ide_stopped; 1042 return ide_stopped;
1262 } 1043 }
1263 if (rq->cmd[0] & REQ_IDETAPE_READ) { 1044 if (rq->cmd[13] & REQ_IDETAPE_READ) {
1264 pc = idetape_next_pc_storage(drive); 1045 pc = idetape_next_pc_storage(drive);
1265 idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, 1046 ide_tape_create_rw_cmd(tape, pc, rq, READ_6);
1266 (struct idetape_bh *)rq->special);
1267 goto out; 1047 goto out;
1268 } 1048 }
1269 if (rq->cmd[0] & REQ_IDETAPE_WRITE) { 1049 if (rq->cmd[13] & REQ_IDETAPE_WRITE) {
1270 pc = idetape_next_pc_storage(drive); 1050 pc = idetape_next_pc_storage(drive);
1271 idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, 1051 ide_tape_create_rw_cmd(tape, pc, rq, WRITE_6);
1272 (struct idetape_bh *)rq->special);
1273 goto out; 1052 goto out;
1274 } 1053 }
1275 if (rq->cmd[0] & REQ_IDETAPE_PC1) { 1054 if (rq->cmd[13] & REQ_IDETAPE_PC1) {
1276 pc = (struct ide_atapi_pc *) rq->buffer; 1055 pc = (struct ide_atapi_pc *) rq->buffer;
1277 rq->cmd[0] &= ~(REQ_IDETAPE_PC1); 1056 rq->cmd[13] &= ~(REQ_IDETAPE_PC1);
1278 rq->cmd[0] |= REQ_IDETAPE_PC2; 1057 rq->cmd[13] |= REQ_IDETAPE_PC2;
1279 goto out; 1058 goto out;
1280 } 1059 }
1281 if (rq->cmd[0] & REQ_IDETAPE_PC2) { 1060 if (rq->cmd[13] & REQ_IDETAPE_PC2) {
1282 idetape_media_access_finished(drive); 1061 idetape_media_access_finished(drive);
1283 return ide_stopped; 1062 return ide_stopped;
1284 } 1063 }
1285 BUG(); 1064 BUG();
1065
1286out: 1066out:
1287 return idetape_issue_pc(drive, pc); 1067 return idetape_issue_pc(drive, pc);
1288} 1068}
@@ -1447,40 +1227,6 @@ static void idetape_init_merge_buffer(idetape_tape_t *tape)
1447 } 1227 }
1448} 1228}
1449 1229
1450static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive)
1451{
1452 idetape_tape_t *tape = drive->driver_data;
1453 u8 *readpos = tape->pc->buf;
1454
1455 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1456
1457 if (!tape->pc->error) {
1458 debug_log(DBG_SENSE, "BOP - %s\n",
1459 (readpos[0] & 0x80) ? "Yes" : "No");
1460 debug_log(DBG_SENSE, "EOP - %s\n",
1461 (readpos[0] & 0x40) ? "Yes" : "No");
1462
1463 if (readpos[0] & 0x4) {
1464 printk(KERN_INFO "ide-tape: Block location is unknown"
1465 "to the tape\n");
1466 clear_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
1467 idetape_end_request(drive, 0, 0);
1468 } else {
1469 debug_log(DBG_SENSE, "Block Location - %u\n",
1470 be32_to_cpu(*(u32 *)&readpos[4]));
1471
1472 tape->partition = readpos[1];
1473 tape->first_frame =
1474 be32_to_cpu(*(u32 *)&readpos[4]);
1475 set_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
1476 idetape_end_request(drive, 1, 0);
1477 }
1478 } else {
1479 idetape_end_request(drive, 0, 0);
1480 }
1481 return ide_stopped;
1482}
1483
1484/* 1230/*
1485 * Write a filemark if write_filemark=1. Flush the device buffers without 1231 * Write a filemark if write_filemark=1. Flush the device buffers without
1486 * writing a filemark otherwise. 1232 * writing a filemark otherwise.
@@ -1492,14 +1238,12 @@ static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
1492 pc->c[0] = WRITE_FILEMARKS; 1238 pc->c[0] = WRITE_FILEMARKS;
1493 pc->c[4] = write_filemark; 1239 pc->c[4] = write_filemark;
1494 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1240 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1495 pc->idetape_callback = &idetape_pc_callback;
1496} 1241}
1497 1242
1498static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc) 1243static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc)
1499{ 1244{
1500 idetape_init_pc(pc); 1245 idetape_init_pc(pc);
1501 pc->c[0] = TEST_UNIT_READY; 1246 pc->c[0] = TEST_UNIT_READY;
1502 pc->idetape_callback = &idetape_pc_callback;
1503} 1247}
1504 1248
1505/* 1249/*
@@ -1518,12 +1262,17 @@ static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc)
1518static int idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc) 1262static int idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
1519{ 1263{
1520 struct ide_tape_obj *tape = drive->driver_data; 1264 struct ide_tape_obj *tape = drive->driver_data;
1521 struct request rq; 1265 struct request *rq;
1266 int error;
1522 1267
1523 idetape_init_rq(&rq, REQ_IDETAPE_PC1); 1268 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
1524 rq.buffer = (char *) pc; 1269 rq->cmd_type = REQ_TYPE_SPECIAL;
1525 rq.rq_disk = tape->disk; 1270 rq->cmd[13] = REQ_IDETAPE_PC1;
1526 return ide_do_drive_cmd(drive, &rq, ide_wait); 1271 rq->buffer = (char *)pc;
1272 memcpy(rq->cmd, pc->c, 12);
1273 error = blk_execute_rq(drive->queue, tape->disk, rq, 0);
1274 blk_put_request(rq);
1275 return error;
1527} 1276}
1528 1277
1529static void idetape_create_load_unload_cmd(ide_drive_t *drive, 1278static void idetape_create_load_unload_cmd(ide_drive_t *drive,
@@ -1533,7 +1282,6 @@ static void idetape_create_load_unload_cmd(ide_drive_t *drive,
1533 pc->c[0] = START_STOP; 1282 pc->c[0] = START_STOP;
1534 pc->c[4] = cmd; 1283 pc->c[4] = cmd;
1535 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1284 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1536 pc->idetape_callback = &idetape_pc_callback;
1537} 1285}
1538 1286
1539static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) 1287static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
@@ -1543,7 +1291,7 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
1543 int load_attempted = 0; 1291 int load_attempted = 0;
1544 1292
1545 /* Wait for the tape to become ready */ 1293 /* Wait for the tape to become ready */
1546 set_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags); 1294 set_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
1547 timeout += jiffies; 1295 timeout += jiffies;
1548 while (time_before(jiffies, timeout)) { 1296 while (time_before(jiffies, timeout)) {
1549 idetape_create_test_unit_ready_cmd(&pc); 1297 idetape_create_test_unit_ready_cmd(&pc);
@@ -1585,7 +1333,6 @@ static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
1585 idetape_init_pc(pc); 1333 idetape_init_pc(pc);
1586 pc->c[0] = READ_POSITION; 1334 pc->c[0] = READ_POSITION;
1587 pc->req_xfer = 20; 1335 pc->req_xfer = 20;
1588 pc->idetape_callback = &idetape_read_position_callback;
1589} 1336}
1590 1337
1591static int idetape_read_position(ide_drive_t *drive) 1338static int idetape_read_position(ide_drive_t *drive)
@@ -1613,7 +1360,6 @@ static void idetape_create_locate_cmd(ide_drive_t *drive,
1613 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); 1360 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
1614 pc->c[8] = partition; 1361 pc->c[8] = partition;
1615 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1362 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1616 pc->idetape_callback = &idetape_pc_callback;
1617} 1363}
1618 1364
1619static int idetape_create_prevent_cmd(ide_drive_t *drive, 1365static int idetape_create_prevent_cmd(ide_drive_t *drive,
@@ -1628,7 +1374,6 @@ static int idetape_create_prevent_cmd(ide_drive_t *drive,
1628 idetape_init_pc(pc); 1374 idetape_init_pc(pc);
1629 pc->c[0] = ALLOW_MEDIUM_REMOVAL; 1375 pc->c[0] = ALLOW_MEDIUM_REMOVAL;
1630 pc->c[4] = prevent; 1376 pc->c[4] = prevent;
1631 pc->idetape_callback = &idetape_pc_callback;
1632 return 1; 1377 return 1;
1633} 1378}
1634 1379
@@ -1639,7 +1384,7 @@ static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
1639 if (tape->chrdev_dir != IDETAPE_DIR_READ) 1384 if (tape->chrdev_dir != IDETAPE_DIR_READ)
1640 return; 1385 return;
1641 1386
1642 clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags); 1387 clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags);
1643 tape->merge_bh_size = 0; 1388 tape->merge_bh_size = 0;
1644 if (tape->merge_bh != NULL) { 1389 if (tape->merge_bh != NULL) {
1645 ide_tape_kfree_buffer(tape); 1390 ide_tape_kfree_buffer(tape);
@@ -1700,26 +1445,33 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
1700 struct idetape_bh *bh) 1445 struct idetape_bh *bh)
1701{ 1446{
1702 idetape_tape_t *tape = drive->driver_data; 1447 idetape_tape_t *tape = drive->driver_data;
1703 struct request rq; 1448 struct request *rq;
1449 int ret, errors;
1704 1450
1705 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd); 1451 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
1706 1452
1707 idetape_init_rq(&rq, cmd); 1453 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
1708 rq.rq_disk = tape->disk; 1454 rq->cmd_type = REQ_TYPE_SPECIAL;
1709 rq.special = (void *)bh; 1455 rq->cmd[13] = cmd;
1710 rq.sector = tape->first_frame; 1456 rq->rq_disk = tape->disk;
1711 rq.nr_sectors = blocks; 1457 rq->special = (void *)bh;
1712 rq.current_nr_sectors = blocks; 1458 rq->sector = tape->first_frame;
1713 (void) ide_do_drive_cmd(drive, &rq, ide_wait); 1459 rq->nr_sectors = blocks;
1460 rq->current_nr_sectors = blocks;
1461 blk_execute_rq(drive->queue, tape->disk, rq, 0);
1462
1463 errors = rq->errors;
1464 ret = tape->blk_size * (blocks - rq->current_nr_sectors);
1465 blk_put_request(rq);
1714 1466
1715 if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) 1467 if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0)
1716 return 0; 1468 return 0;
1717 1469
1718 if (tape->merge_bh) 1470 if (tape->merge_bh)
1719 idetape_init_merge_buffer(tape); 1471 idetape_init_merge_buffer(tape);
1720 if (rq.errors == IDETAPE_ERROR_GENERAL) 1472 if (errors == IDETAPE_ERROR_GENERAL)
1721 return -EIO; 1473 return -EIO;
1722 return (tape->blk_size * (blocks-rq.current_nr_sectors)); 1474 return ret;
1723} 1475}
1724 1476
1725static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) 1477static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
@@ -1728,7 +1480,6 @@ static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1728 pc->c[0] = INQUIRY; 1480 pc->c[0] = INQUIRY;
1729 pc->c[4] = 254; 1481 pc->c[4] = 254;
1730 pc->req_xfer = 254; 1482 pc->req_xfer = 254;
1731 pc->idetape_callback = &idetape_pc_callback;
1732} 1483}
1733 1484
1734static void idetape_create_rewind_cmd(ide_drive_t *drive, 1485static void idetape_create_rewind_cmd(ide_drive_t *drive,
@@ -1737,7 +1488,6 @@ static void idetape_create_rewind_cmd(ide_drive_t *drive,
1737 idetape_init_pc(pc); 1488 idetape_init_pc(pc);
1738 pc->c[0] = REZERO_UNIT; 1489 pc->c[0] = REZERO_UNIT;
1739 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1490 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1740 pc->idetape_callback = &idetape_pc_callback;
1741} 1491}
1742 1492
1743static void idetape_create_erase_cmd(struct ide_atapi_pc *pc) 1493static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
@@ -1746,7 +1496,6 @@ static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1746 pc->c[0] = ERASE; 1496 pc->c[0] = ERASE;
1747 pc->c[1] = 1; 1497 pc->c[1] = 1;
1748 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1498 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1749 pc->idetape_callback = &idetape_pc_callback;
1750} 1499}
1751 1500
1752static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd) 1501static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
@@ -1756,7 +1505,6 @@ static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1756 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); 1505 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
1757 pc->c[1] = cmd; 1506 pc->c[1] = cmd;
1758 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1507 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1759 pc->idetape_callback = &idetape_pc_callback;
1760} 1508}
1761 1509
1762/* Queue up a character device originated write request. */ 1510/* Queue up a character device originated write request. */
@@ -1875,7 +1623,7 @@ static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks)
1875 debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks); 1623 debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks);
1876 1624
1877 /* If we are at a filemark, return a read length of 0 */ 1625 /* If we are at a filemark, return a read length of 0 */
1878 if (test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) 1626 if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
1879 return 0; 1627 return 0;
1880 1628
1881 idetape_init_read(drive); 1629 idetape_init_read(drive);
@@ -1985,7 +1733,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1985 1733
1986 if (tape->chrdev_dir == IDETAPE_DIR_READ) { 1734 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
1987 tape->merge_bh_size = 0; 1735 tape->merge_bh_size = 0;
1988 if (test_and_clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) 1736 if (test_and_clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
1989 ++count; 1737 ++count;
1990 ide_tape_discard_merge_buffer(drive, 0); 1738 ide_tape_discard_merge_buffer(drive, 0);
1991 } 1739 }
@@ -2040,7 +1788,7 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
2040 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); 1788 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
2041 1789
2042 if (tape->chrdev_dir != IDETAPE_DIR_READ) { 1790 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
2043 if (test_bit(IDETAPE_FLAG_DETECT_BS, &tape->flags)) 1791 if (test_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags))
2044 if (count > tape->blk_size && 1792 if (count > tape->blk_size &&
2045 (count % tape->blk_size) == 0) 1793 (count % tape->blk_size) == 0)
2046 tape->user_bs_factor = count / tape->blk_size; 1794 tape->user_bs_factor = count / tape->blk_size;
@@ -2080,7 +1828,7 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
2080 tape->merge_bh_size = bytes_read-temp; 1828 tape->merge_bh_size = bytes_read-temp;
2081 } 1829 }
2082finish: 1830finish:
2083 if (!actually_read && test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) { 1831 if (!actually_read && test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) {
2084 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name); 1832 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);
2085 1833
2086 idetape_space_over_filemarks(drive, MTFSF, 1); 1834 idetape_space_over_filemarks(drive, MTFSF, 1);
@@ -2266,7 +2014,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2266 !IDETAPE_LU_LOAD_MASK); 2014 !IDETAPE_LU_LOAD_MASK);
2267 retval = idetape_queue_pc_tail(drive, &pc); 2015 retval = idetape_queue_pc_tail(drive, &pc);
2268 if (!retval) 2016 if (!retval)
2269 clear_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags); 2017 clear_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
2270 return retval; 2018 return retval;
2271 case MTNOP: 2019 case MTNOP:
2272 ide_tape_discard_merge_buffer(drive, 0); 2020 ide_tape_discard_merge_buffer(drive, 0);
@@ -2289,9 +2037,9 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
2289 mt_count % tape->blk_size) 2037 mt_count % tape->blk_size)
2290 return -EIO; 2038 return -EIO;
2291 tape->user_bs_factor = mt_count / tape->blk_size; 2039 tape->user_bs_factor = mt_count / tape->blk_size;
2292 clear_bit(IDETAPE_FLAG_DETECT_BS, &tape->flags); 2040 clear_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags);
2293 } else 2041 } else
2294 set_bit(IDETAPE_FLAG_DETECT_BS, &tape->flags); 2042 set_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags);
2295 return 0; 2043 return 0;
2296 case MTSEEK: 2044 case MTSEEK:
2297 ide_tape_discard_merge_buffer(drive, 0); 2045 ide_tape_discard_merge_buffer(drive, 0);
@@ -2421,9 +2169,12 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2421 if (i >= MAX_HWIFS * MAX_DRIVES) 2169 if (i >= MAX_HWIFS * MAX_DRIVES)
2422 return -ENXIO; 2170 return -ENXIO;
2423 2171
2172 lock_kernel();
2424 tape = ide_tape_chrdev_get(i); 2173 tape = ide_tape_chrdev_get(i);
2425 if (!tape) 2174 if (!tape) {
2175 unlock_kernel();
2426 return -ENXIO; 2176 return -ENXIO;
2177 }
2427 2178
2428 debug_log(DBG_CHRDEV, "Enter %s\n", __func__); 2179 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
2429 2180
@@ -2438,20 +2189,20 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2438 2189
2439 filp->private_data = tape; 2190 filp->private_data = tape;
2440 2191
2441 if (test_and_set_bit(IDETAPE_FLAG_BUSY, &tape->flags)) { 2192 if (test_and_set_bit(IDE_AFLAG_BUSY, &drive->atapi_flags)) {
2442 retval = -EBUSY; 2193 retval = -EBUSY;
2443 goto out_put_tape; 2194 goto out_put_tape;
2444 } 2195 }
2445 2196
2446 retval = idetape_wait_ready(drive, 60 * HZ); 2197 retval = idetape_wait_ready(drive, 60 * HZ);
2447 if (retval) { 2198 if (retval) {
2448 clear_bit(IDETAPE_FLAG_BUSY, &tape->flags); 2199 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
2449 printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name); 2200 printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name);
2450 goto out_put_tape; 2201 goto out_put_tape;
2451 } 2202 }
2452 2203
2453 idetape_read_position(drive); 2204 idetape_read_position(drive);
2454 if (!test_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags)) 2205 if (!test_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags))
2455 (void)idetape_rewind_tape(drive); 2206 (void)idetape_rewind_tape(drive);
2456 2207
2457 /* Read block size and write protect status from drive. */ 2208 /* Read block size and write protect status from drive. */
@@ -2467,7 +2218,7 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2467 if (tape->write_prot) { 2218 if (tape->write_prot) {
2468 if ((filp->f_flags & O_ACCMODE) == O_WRONLY || 2219 if ((filp->f_flags & O_ACCMODE) == O_WRONLY ||
2469 (filp->f_flags & O_ACCMODE) == O_RDWR) { 2220 (filp->f_flags & O_ACCMODE) == O_RDWR) {
2470 clear_bit(IDETAPE_FLAG_BUSY, &tape->flags); 2221 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
2471 retval = -EROFS; 2222 retval = -EROFS;
2472 goto out_put_tape; 2223 goto out_put_tape;
2473 } 2224 }
@@ -2482,10 +2233,12 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
2482 } 2233 }
2483 } 2234 }
2484 } 2235 }
2236 unlock_kernel();
2485 return 0; 2237 return 0;
2486 2238
2487out_put_tape: 2239out_put_tape:
2488 ide_tape_put(tape); 2240 ide_tape_put(tape);
2241 unlock_kernel();
2489 return retval; 2242 return retval;
2490} 2243}
2491 2244
@@ -2525,7 +2278,7 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2525 ide_tape_discard_merge_buffer(drive, 1); 2278 ide_tape_discard_merge_buffer(drive, 1);
2526 } 2279 }
2527 2280
2528 if (minor < 128 && test_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags)) 2281 if (minor < 128 && test_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags))
2529 (void) idetape_rewind_tape(drive); 2282 (void) idetape_rewind_tape(drive);
2530 if (tape->chrdev_dir == IDETAPE_DIR_NONE) { 2283 if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
2531 if (tape->door_locked == DOOR_LOCKED) { 2284 if (tape->door_locked == DOOR_LOCKED) {
@@ -2535,7 +2288,7 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2535 } 2288 }
2536 } 2289 }
2537 } 2290 }
2538 clear_bit(IDETAPE_FLAG_BUSY, &tape->flags); 2291 clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
2539 ide_tape_put(tape); 2292 ide_tape_put(tape);
2540 unlock_kernel(); 2293 unlock_kernel();
2541 return 0; 2294 return 0;
@@ -2628,23 +2381,23 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
2628 caps = pc.buf + 4 + pc.buf[3]; 2381 caps = pc.buf + 4 + pc.buf[3];
2629 2382
2630 /* convert to host order and save for later use */ 2383 /* convert to host order and save for later use */
2631 speed = be16_to_cpu(*(u16 *)&caps[14]); 2384 speed = be16_to_cpup((__be16 *)&caps[14]);
2632 max_speed = be16_to_cpu(*(u16 *)&caps[8]); 2385 max_speed = be16_to_cpup((__be16 *)&caps[8]);
2633 2386
2634 put_unaligned(max_speed, (u16 *)&caps[8]); 2387 *(u16 *)&caps[8] = max_speed;
2635 put_unaligned(be16_to_cpu(*(u16 *)&caps[12]), (u16 *)&caps[12]); 2388 *(u16 *)&caps[12] = be16_to_cpup((__be16 *)&caps[12]);
2636 put_unaligned(speed, (u16 *)&caps[14]); 2389 *(u16 *)&caps[14] = speed;
2637 put_unaligned(be16_to_cpu(*(u16 *)&caps[16]), (u16 *)&caps[16]); 2390 *(u16 *)&caps[16] = be16_to_cpup((__be16 *)&caps[16]);
2638 2391
2639 if (!speed) { 2392 if (!speed) {
2640 printk(KERN_INFO "ide-tape: %s: invalid tape speed " 2393 printk(KERN_INFO "ide-tape: %s: invalid tape speed "
2641 "(assuming 650KB/sec)\n", drive->name); 2394 "(assuming 650KB/sec)\n", drive->name);
2642 put_unaligned(650, (u16 *)&caps[14]); 2395 *(u16 *)&caps[14] = 650;
2643 } 2396 }
2644 if (!max_speed) { 2397 if (!max_speed) {
2645 printk(KERN_INFO "ide-tape: %s: invalid max_speed " 2398 printk(KERN_INFO "ide-tape: %s: invalid max_speed "
2646 "(assuming 650KB/sec)\n", drive->name); 2399 "(assuming 650KB/sec)\n", drive->name);
2647 put_unaligned(650, (u16 *)&caps[8]); 2400 *(u16 *)&caps[8] = 650;
2648 } 2401 }
2649 2402
2650 memcpy(&tape->caps, caps, 20); 2403 memcpy(&tape->caps, caps, 20);
@@ -2698,6 +2451,8 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2698 u8 gcw[2]; 2451 u8 gcw[2];
2699 u16 *ctl = (u16 *)&tape->caps[12]; 2452 u16 *ctl = (u16 *)&tape->caps[12];
2700 2453
2454 drive->pc_callback = ide_tape_callback;
2455
2701 spin_lock_init(&tape->lock); 2456 spin_lock_init(&tape->lock);
2702 drive->dsc_overlap = 1; 2457 drive->dsc_overlap = 1;
2703 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { 2458 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
@@ -2718,7 +2473,7 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2718 2473
2719 /* Command packet DRQ type */ 2474 /* Command packet DRQ type */
2720 if (((gcw[0] & 0x60) >> 5) == 1) 2475 if (((gcw[0] & 0x60) >> 5) == 1)
2721 set_bit(IDETAPE_FLAG_DRQ_INTERRUPT, &tape->flags); 2476 set_bit(IDE_AFLAG_DRQ_INTERRUPT, &drive->atapi_flags);
2722 2477
2723 idetape_get_inquiry_results(drive); 2478 idetape_get_inquiry_results(drive);
2724 idetape_get_mode_sense_results(drive); 2479 idetape_get_mode_sense_results(drive);
@@ -2746,9 +2501,8 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2746 * Ensure that the number we got makes sense; limit it within 2501 * Ensure that the number we got makes sense; limit it within
2747 * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX. 2502 * IDETAPE_DSC_RW_MIN and IDETAPE_DSC_RW_MAX.
2748 */ 2503 */
2749 tape->best_dsc_rw_freq = max_t(unsigned long, 2504 tape->best_dsc_rw_freq = clamp_t(unsigned long, t, IDETAPE_DSC_RW_MIN,
2750 min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), 2505 IDETAPE_DSC_RW_MAX);
2751 IDETAPE_DSC_RW_MIN);
2752 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " 2506 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
2753 "%lums tDSC%s\n", 2507 "%lums tDSC%s\n",
2754 drive->name, tape->name, *(u16 *)&tape->caps[14], 2508 drive->name, tape->name, *(u16 *)&tape->caps[14],
@@ -2826,7 +2580,6 @@ static ide_driver_t idetape_driver = {
2826 .do_request = idetape_do_request, 2580 .do_request = idetape_do_request,
2827 .end_request = idetape_end_request, 2581 .end_request = idetape_end_request,
2828 .error = __ide_error, 2582 .error = __ide_error,
2829 .abort = __ide_abort,
2830#ifdef CONFIG_IDE_PROC_FS 2583#ifdef CONFIG_IDE_PROC_FS
2831 .proc = idetape_proc, 2584 .proc = idetape_proc,
2832#endif 2585#endif
@@ -2900,11 +2653,6 @@ static int ide_tape_probe(ide_drive_t *drive)
2900 " the driver\n", drive->name); 2653 " the driver\n", drive->name);
2901 goto failed; 2654 goto failed;
2902 } 2655 }
2903 if (drive->scsi) {
2904 printk(KERN_INFO "ide-tape: passing drive %s to ide-scsi"
2905 " emulation.\n", drive->name);
2906 goto failed;
2907 }
2908 tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL); 2656 tape = kzalloc(sizeof(idetape_tape_t), GFP_KERNEL);
2909 if (tape == NULL) { 2657 if (tape == NULL) {
2910 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n", 2658 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape struct\n",
@@ -2938,10 +2686,12 @@ static int ide_tape_probe(ide_drive_t *drive)
2938 2686
2939 idetape_setup(drive, tape, minor); 2687 idetape_setup(drive, tape, minor);
2940 2688
2941 device_create(idetape_sysfs_class, &drive->gendev, 2689 device_create_drvdata(idetape_sysfs_class, &drive->gendev,
2942 MKDEV(IDETAPE_MAJOR, minor), "%s", tape->name); 2690 MKDEV(IDETAPE_MAJOR, minor), NULL,
2943 device_create(idetape_sysfs_class, &drive->gendev, 2691 "%s", tape->name);
2944 MKDEV(IDETAPE_MAJOR, minor + 128), "n%s", tape->name); 2692 device_create_drvdata(idetape_sysfs_class, &drive->gendev,
2693 MKDEV(IDETAPE_MAJOR, minor + 128), NULL,
2694 "n%s", tape->name);
2945 2695
2946 g->fops = &idetape_block_ops; 2696 g->fops = &idetape_block_ops;
2947 ide_register_region(g); 2697 ide_register_region(g);