This source file includes following definitions.
- idetape_identify_device
- idetape_register_chrdev
- idetape_setup
- idetape_get_mode_sense_results
- idetape_issue_packet_command
- idetape_pc_intr
- idetape_postpone_request
- idetape_poll_for_dsc_direct
- idetape_poll_for_dsc
- idetape_put_back_postponed_request
- idetape_media_access_finished
- idetape_retry_pc
- idetape_pc_callback
- idetape_read_callback
- idetape_write_callback
- idetape_inquiry_callback
- idetape_input_data
- idetape_output_data
- idetape_discard_data
- idetape_create_inquiry_cmd
- idetape_display_inquiry_result
- idetape_create_request_sense_cmd
- idetape_request_sense_callback
- idetape_analyze_error
- idetape_create_test_unit_ready_cmd
- idetape_create_locate_cmd
- idetape_create_rewind_cmd
- idetape_create_mode_sense_cmd
- idetape_create_write_filemark_cmd
- idetape_create_erase_cmd
- idetape_create_read_cmd
- idetape_create_space_cmd
- idetape_create_write_cmd
- idetape_create_read_position_cmd
- idetape_read_position_callback
- idetape_blkdev_ioctl
- idetape_end_request
- idetape_do_request
- idetape_queue_pc_tail
- idetape_queue_pc_head
- idetape_wait_for_request
- idetape_queue_rw_tail
- idetape_add_chrdev_write_request
- idetape_empty_pipeline
- idetape_zero_packet_command
- idetape_swap_short
- idetape_swap_long
- idetape_next_pc_storage
- idetape_next_rq_storage
- idetape_blkdev_open
- idetape_blkdev_release
- idetape_chrdev_lseek
- idetape_chrdev_read
- idetape_chrdev_read_remainder
- idetape_chrdev_write
- idetape_chrdev_write_remainder
- idetape_chrdev_ioctl
- idetape_mtioctop
- idetape_chrdev_open
- idetape_chrdev_release
- idetape_position_tape
- idetape_rewind_tape
- idetape_kmalloc_stage
- idetape_kfree_stage
- idetape_copy_buffer_from_stage
- idetape_copy_buffer_to_stage
- idetape_increase_max_pipeline_stages
- idetape_add_stage_tail
- idetape_insert_pipeline_into_queue
- idetape_active_next_stage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221 #include <linux/hdreg.h>
222 #include <linux/types.h>
223 #include <linux/string.h>
224 #include <linux/kernel.h>
225 #include <linux/delay.h>
226 #include <linux/timer.h>
227 #include <linux/mm.h>
228 #include <linux/ioport.h>
229 #include <linux/interrupt.h>
230 #include <linux/major.h>
231 #include <linux/blkdev.h>
232 #include <linux/errno.h>
233 #include <linux/hdreg.h>
234 #include <linux/genhd.h>
235 #include <linux/malloc.h>
236
237 #include <asm/byteorder.h>
238 #include <asm/irq.h>
239 #include <asm/segment.h>
240 #include <asm/io.h>
241
242 #define _IDE_TAPE_C
243
244
245
246
247
248
249
250 #include "ide.h"
251
252
253
254
255
256 #define IDETAPE_TEST_UNIT_READY_CMD 0x00
257 #define IDETAPE_REWIND_CMD 0x01
258 #define IDETAPE_REQUEST_SENSE_CMD 0x03
259 #define IDETAPE_READ_CMD 0x08
260 #define IDETAPE_WRITE_CMD 0x0a
261 #define IDETAPE_WRITE_FILEMARK_CMD 0x10
262 #define IDETAPE_SPACE_CMD 0x11
263 #define IDETAPE_INQUIRY_CMD 0x12
264 #define IDETAPE_ERASE_CMD 0x19
265 #define IDETAPE_MODE_SENSE_CMD 0x1a
266 #define IDETAPE_LOCATE_CMD 0x2b
267 #define IDETAPE_READ_POSITION_CMD 0x34
268
269
270
271
272
273
274
275 #define IDETAPE_SPACE_OVER_FILEMARK 1
276 #define IDETAPE_SPACE_TO_EOD 3
277
278
279
280
281
282
283
284
285
286 #define IDETAPE_INQUIRY_IOCTL 0x0341
287 #define IDETAPE_LOCATE_IOCTL 0x0342
288
289 #define IDETAPE_RESET_IOCTL 0x0350
290
291
292
293
294
295
296
297
298
299
300 #define IDETAPE_FIRST_REQUEST 90
301
302
303
304
305
306
307
308
309
310 #define IDETAPE_PACKET_COMMAND_REQUEST_TYPE1 90
311 #define IDETAPE_PACKET_COMMAND_REQUEST_TYPE2 91
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327 #define IDETAPE_READ_REQUEST 92
328 #define IDETAPE_WRITE_REQUEST 93
329
330 #define IDETAPE_LAST_REQUEST 93
331
332
333
334
335
336
337 #define IDETAPE_REQUEST_CMD(cmd) ((cmd >= IDETAPE_FIRST_REQUEST) && (cmd <= IDETAPE_LAST_REQUEST))
338
339
340
341
342
343
344
345 #define IDETAPE_RQ_POSTPONED 0x1234
346
347
348
349
350
351
352
353
354
355 #define IDETAPE_DATA_OFFSET (0)
356 #define IDETAPE_ERROR_OFFSET (1)
357 #define IDETAPE_IREASON_OFFSET (2)
358 #define IDETAPE_RESERVED3_OFFSET (3)
359 #define IDETAPE_BCOUNTL_OFFSET (4)
360 #define IDETAPE_BCOUNTH_OFFSET (5)
361 #define IDETAPE_DRIVESEL_OFFSET (6)
362 #define IDETAPE_STATUS_OFFSET (7)
363
364 #define IDETAPE_DATA_REG (HWIF(drive)->io_base+IDETAPE_DATA_OFFSET)
365 #define IDETAPE_ERROR_REG (HWIF(drive)->io_base+IDETAPE_ERROR_OFFSET)
366 #define IDETAPE_IREASON_REG (HWIF(drive)->io_base+IDETAPE_IREASON_OFFSET)
367 #define IDETAPE_RESERVED3_REG (HWIF(drive)->io_base+IDETAPE_RESERVED3_OFFSET)
368 #define IDETAPE_BCOUNTL_REG (HWIF(drive)->io_base+IDETAPE_BCOUNTL_OFFSET)
369 #define IDETAPE_BCOUNTH_REG (HWIF(drive)->io_base+IDETAPE_BCOUNTH_OFFSET)
370 #define IDETAPE_DRIVESEL_REG (HWIF(drive)->io_base+IDETAPE_DRIVESEL_OFFSET)
371 #define IDETAPE_STATUS_REG (HWIF(drive)->io_base+IDETAPE_STATUS_OFFSET)
372
373
374
375 #define IDETAPE_FEATURES_OFFSET (1)
376 #define IDETAPE_ATACOMMAND_OFFSET (7)
377
378 #define IDETAPE_FEATURES_REG (HWIF(drive)->io_base+IDETAPE_FEATURES_OFFSET)
379 #define IDETAPE_ATACOMMAND_REG (HWIF(drive)->io_base+IDETAPE_ATACOMMAND_OFFSET)
380 #define IDETAPE_CONTROL_REG (HWIF(drive)->ctl_port)
381
382
383
384
385
386
387
388
389
390
391 typedef union {
392 unsigned all :8;
393 struct {
394 unsigned check :1;
395 unsigned idx :1;
396 unsigned corr :1;
397 unsigned drq :1;
398 unsigned dsc :1;
399
400 unsigned reserved5 :1;
401 unsigned drdy :1;
402
403 unsigned bsy :1;
404 } b;
405 } idetape_status_reg_t;
406
407
408
409
410
411 typedef union {
412 unsigned all :8;
413 struct {
414 unsigned ili :1;
415 unsigned eom :1;
416 unsigned abrt :1;
417 unsigned mcr :1;
418 unsigned sense_key :4;
419 } b;
420 } idetape_error_reg_t;
421
422
423
424
425
426 typedef union {
427 unsigned all :8;
428 struct {
429 unsigned dma :1;
430 unsigned reserved321 :3;
431 unsigned reserved654 :3;
432 unsigned reserved7 :1;
433 } b;
434 } idetape_feature_reg_t;
435
436
437
438
439
440 typedef union {
441 unsigned all :16;
442 struct {
443 unsigned low :8;
444 unsigned high :8;
445 } b;
446 } idetape_bcount_reg_t;
447
448
449
450
451
452 typedef union {
453 unsigned all :8;
454 struct {
455 unsigned cod :1;
456 unsigned io :1;
457 unsigned reserved :6;
458 } b;
459 } idetape_ireason_reg_t;
460
461
462
463
464
465 typedef union {
466 unsigned all :8;
467 struct {
468 unsigned sam_lun :4;
469 unsigned drv :1;
470 unsigned one5 :1;
471 unsigned reserved6 :1;
472 unsigned one7 :1;
473 } b;
474 } idetape_drivesel_reg_t;
475
476
477
478
479
480 typedef union {
481 unsigned all :8;
482 struct {
483 unsigned zero0 :1;
484 unsigned nien :1;
485 unsigned srst :1;
486 unsigned one3 :1;
487 unsigned reserved4567 :4;
488 } b;
489 } idetape_control_reg_t;
490
491
492
493
494
495
496
497
498
499
500 typedef struct {
501 ide_drive_t *drive;
502 int major,minor;
503 char name[4];
504 } idetape_chrdev_t;
505
506
507
508
509
510
511 struct idetape_id_gcw {
512
513 unsigned packet_size :2;
514 unsigned reserved2 :1;
515 unsigned reserved3 :1;
516 unsigned reserved4 :1;
517 unsigned drq_type :2;
518 unsigned removable :1;
519 unsigned device_type :5;
520 unsigned reserved13 :1;
521 unsigned protocol :2;
522 };
523
524
525
526
527
528 typedef struct {
529 unsigned device_type :5;
530 unsigned reserved0_765 :3;
531 unsigned reserved1_6t0 :7;
532 unsigned rmb :1;
533 unsigned ansi_version :3;
534 unsigned ecma_version :3;
535 unsigned iso_version :2;
536 unsigned response_format :4;
537 unsigned reserved3_45 :2;
538 unsigned reserved3_6 :1;
539 unsigned reserved3_7 :1;
540 byte additional_length;
541 byte reserved_5;
542 byte reserved_6;
543 unsigned reserved7_0 :1;
544 unsigned reserved7_1 :1;
545 unsigned reserved7_2 :1;
546 unsigned reserved7_3 :1;
547 unsigned reserved7_4 :1;
548 unsigned reserved7_5 :1;
549 unsigned reserved7_6 :1;
550 unsigned reserved7_7 :1;
551 byte vendor_id [8];
552 byte product_id [16];
553 byte revision_level [4];
554 byte vendor_specific [20];
555 byte reserved56t95 [40];
556
557
558 } idetape_inquiry_result_t;
559
560
561
562
563
564 typedef struct {
565 unsigned reserved0_10 :2;
566 unsigned bpu :1;
567 unsigned reserved0_543 :3;
568 unsigned eop :1;
569 unsigned bop :1;
570 byte partition_num;
571 byte reserved_2;
572 byte reserved_3;
573 unsigned long first_block;
574 unsigned long last_block;
575 byte reserved_12;
576 byte blocks_in_buffer_2;
577 byte blocks_in_buffer_1;
578 byte blocks_in_buffer_0;
579 unsigned long bytes_in_buffer;
580 } idetape_read_position_result_t;
581
582
583
584
585
586 typedef struct {
587 unsigned error_code :7;
588 unsigned valid :1;
589 byte reserved_1;
590 unsigned sense_key :4;
591 unsigned reserved2_4 :1;
592 unsigned ili :1;
593 unsigned eom :1;
594 unsigned filemark :1;
595 unsigned long information;
596 byte asl;
597 unsigned long command_specific;
598 byte asc;
599 byte ascq;
600 byte replaceable_unit_code;
601 unsigned sk_specific1 :7;
602 unsigned sksv :1;
603 byte sk_specific2;
604 byte sk_specific3;
605 } idetape_request_sense_result_t;
606
607
608
609
610
611
612
613 #define IDETAPE_CAPABILITIES_PAGE 0x2a
614
615
616
617
618
619 typedef struct {
620 byte mode_data_length;
621
622 byte medium_type;
623 byte dsp;
624 byte bdl;
625 } idetape_mode_parameter_header_t;
626
627
628
629
630
631
632
633 typedef struct {
634 byte density_code;
635 byte blocks1;
636 byte blocks2;
637 byte blocks3;
638 byte reserved4;
639 byte length1;
640 byte length2;
641 byte length3;
642 } idetape_parameter_block_descriptor_t;
643
644
645
646
647
648 typedef struct {
649 unsigned page_code :6;
650 unsigned reserved :1;
651 unsigned ps :1;
652 byte page_length;
653 unsigned reserved2 :6;
654 unsigned dcc :1;
655 unsigned dce :1;
656 unsigned reserved3 :5;
657 unsigned red :2;
658 unsigned dde :1;
659 unsigned long ca;
660 unsigned long da;
661 byte reserved_12;
662 byte reserved_13;
663 byte reserved_14;
664 byte reserved_15;
665 } idetape_data_compression_page_t;
666
667
668
669
670
671 typedef struct {
672 unsigned page_code :6;
673 unsigned reserved1_6 :1;
674 unsigned ps :1;
675 byte page_length;
676 byte map;
677 byte apd;
678 unsigned reserved4_012 :3;
679 unsigned psum :2;
680 unsigned idp :1;
681 unsigned sdp :1;
682 unsigned fdp :1;
683 byte mfr;
684 byte reserved6;
685 byte reserved7;
686 } idetape_medium_partition_page_t;
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708 void idetape_input_data (ide_drive_t *drive,void *buffer, unsigned long bcount);
709 void idetape_output_data (ide_drive_t *drive,void *buffer, unsigned long bcount);
710 void idetape_discard_data (ide_drive_t *drive, unsigned long bcount);
711
712
713
714
715
716
717 void idetape_issue_packet_command (ide_drive_t *drive,idetape_packet_command_t *pc,ide_handler_t *handler);
718 void idetape_pc_intr (ide_drive_t *drive);
719
720
721
722
723
724 void idetape_postpone_request (ide_drive_t *drive);
725 void idetape_poll_for_dsc (unsigned long data);
726 void idetape_poll_for_dsc_direct (unsigned long data);
727 void idetape_media_access_finished (ide_drive_t *drive);
728
729
730
731
732
733 void idetape_pc_callback (ide_drive_t *drive);
734 void idetape_retry_pc (ide_drive_t *drive);
735 void idetape_zero_packet_command (idetape_packet_command_t *pc);
736 void idetape_queue_pc_head (ide_drive_t *drive,idetape_packet_command_t *pc,struct request *rq);
737
738 idetape_packet_command_t *idetape_next_pc_storage (ide_drive_t *drive);
739 struct request *idetape_next_rq_storage (ide_drive_t *drive);
740
741 void idetape_end_request (byte uptodate, ide_hwgroup_t *hwgroup);
742
743
744
745
746
747 void idetape_create_inquiry_cmd (idetape_packet_command_t *pc);
748 void idetape_inquiry_callback (ide_drive_t *drive);
749 void idetape_create_locate_cmd (idetape_packet_command_t *pc,unsigned long block,byte partition);
750 void idetape_create_rewind_cmd (idetape_packet_command_t *pc);
751 void idetape_create_write_filemark_cmd (idetape_packet_command_t *pc,int write_filemark);
752 void idetape_create_space_cmd (idetape_packet_command_t *pc,long count,byte cmd);
753 void idetape_create_erase_cmd (idetape_packet_command_t *pc);
754 void idetape_create_test_unit_ready_cmd (idetape_packet_command_t *pc);
755 void idetape_create_read_position_cmd (idetape_packet_command_t *pc);
756 void idetape_read_position_callback (ide_drive_t *drive);
757 void idetape_create_read_cmd (idetape_packet_command_t *pc,unsigned long length);
758 void idetape_read_callback (ide_drive_t *drive);
759 void idetape_create_write_cmd (idetape_packet_command_t *pc,unsigned long length);
760 void idetape_write_callback (ide_drive_t *drive);
761 void idetape_create_request_sense_cmd (idetape_packet_command_t *pc);
762 void idetape_create_mode_sense_cmd (idetape_packet_command_t *pc,byte page_code);
763 void idetape_request_sense_callback (ide_drive_t *drive);
764
765 void idetape_display_inquiry_result (byte *buffer);
766 void idetape_analyze_error (ide_drive_t *drive,idetape_request_sense_result_t *result);
767
768
769
770
771
772
773
774
775
776 int idetape_chrdev_read (struct inode *inode, struct file *file, char *buf, int count);
777 int idetape_chrdev_read_remainder (struct inode *inode, struct file *file, char *buf, int count);
778 int idetape_chrdev_write (struct inode *inode, struct file *file, const char *buf, int count);
779 int idetape_chrdev_write_remainder (struct inode *inode, struct file *file, const char *buf, int count);
780 int idetape_chrdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);
781 int idetape_chrdev_open (struct inode *inode, struct file *file);
782 void idetape_chrdev_release (struct inode *inode,struct file *file);
783
784
785
786
787
788
789
790
791 int idetape_mtioctop (ide_drive_t *drive,short mt_op,int mt_count);
792
793
794
795
796
797
798 int idetape_add_chrdev_write_request (ide_drive_t *drive,int cmd,int blocks,char *buffer);
799
800
801
802
803
804
805
806 int idetape_queue_rw_tail (ide_drive_t *drive,int cmd,int blocks,char *buffer);
807
808
809
810
811
812
813 int idetape_queue_pc_tail (ide_drive_t *drive,idetape_packet_command_t *pc);
814
815 int idetape_position_tape (ide_drive_t *drive,unsigned long block);
816 int idetape_rewind_tape (ide_drive_t *drive);
817
818
819
820
821
822 void idetape_get_mode_sense_results (ide_drive_t *drive);
823
824
825
826
827
828 unsigned long idetape_swap_long (unsigned long temp);
829 unsigned short idetape_swap_short (unsigned short temp);
830
831
832
833
834
835 idetape_pipeline_stage_t *idetape_kmalloc_stage (ide_drive_t *drive);
836 void idetape_kfree_stage (idetape_pipeline_stage_t *stage);
837 void idetape_copy_buffer_from_stage (idetape_pipeline_stage_t *stage,char *buffer);
838 void idetape_copy_buffer_to_stage (idetape_pipeline_stage_t *stage,char *buffer);
839 void idetape_increase_max_pipeline_stages (ide_drive_t *drive);
840 void idetape_add_stage_tail (ide_drive_t *drive,idetape_pipeline_stage_t *stage);
841 void idetape_active_next_stage (ide_drive_t *drive);
842 void idetape_empty_pipeline (ide_drive_t *drive);
843 void idetape_insert_pipeline_into_queue (ide_drive_t *drive);
844
845
846
847
848
849 #include <linux/mtio.h>
850
851
852
853
854
855
856
857
858
859 idetape_chrdev_t idetape_chrdev;
860 byte idetape_drive_already_found=0;
861
862
863
864
865
866 static struct file_operations idetape_fops = {
867 NULL,
868 idetape_chrdev_read,
869 idetape_chrdev_write,
870 NULL,
871 NULL,
872 idetape_chrdev_ioctl,
873 NULL,
874 idetape_chrdev_open,
875 idetape_chrdev_release,
876 NULL,
877 NULL,
878 NULL,
879 NULL
880 };
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898 int idetape_identify_device (ide_drive_t *drive,struct hd_driveid *id)
899
900 {
901 struct idetape_id_gcw gcw;
902 unsigned short *ptr;
903 int support=1;
904 #if IDETAPE_DEBUG
905 unsigned short mask,i;
906 #endif
907
908 ptr=(unsigned short *) &gcw;
909 *ptr=id->config;
910
911 #if IDETAPE_DEBUG
912 printk ("Dumping ATAPI Identify Device tape parameters\n");
913
914 printk ("Protocol Type: ");
915 switch (gcw.protocol) {
916 case 0: case 1: printk ("ATA\n");break;
917 case 2: printk ("ATAPI\n");break;
918 case 3: printk ("Reserved (Unknown to ide-tape)\n");break;
919 }
920
921 printk ("Device Type: %x - ",gcw.device_type);
922 switch (gcw.device_type) {
923 case 0: printk ("Direct-access Device\n");break;
924 case 1: printk ("Streaming Tape Device\n");break;
925 case 2: case 3: case 4: printk ("Reserved\n");break;
926 case 5: printk ("CD-ROM Device\n");break;
927 case 6: printk ("Reserved\n");
928 case 7: printk ("Optical memory Device\n");break;
929 case 0x1f: printk ("Unknown or no Device type\n");break;
930 default: printk ("Reserved\n");
931 }
932 printk ("Removable: %s",gcw.removable ? "Yes\n":"No\n");
933
934 printk ("Command Packet DRQ Type: ");
935 switch (gcw.drq_type) {
936 case 0: printk ("Microprocessor DRQ\n");break;
937 case 1: printk ("Interrupt DRQ\n");break;
938 case 2: printk ("Accelerated DRQ\n");break;
939 case 3: printk ("Reserved\n");break;
940 }
941
942 printk ("Command Packet Size: ");
943 switch (gcw.packet_size) {
944 case 0: printk ("12 bytes\n");break;
945 case 1: printk ("16 bytes\n");break;
946 default: printk ("Reserved\n");break;
947 }
948 printk ("Model: %s\n",id->model);
949 printk ("Firmware Revision: %s\n",id->fw_rev);
950 printk ("Serial Number: %s\n",id->serial_no);
951 printk ("Write buffer size: %d bytes\n",id->buf_size*512);
952 printk ("DMA: %s",id->capability & 0x01 ? "Yes\n":"No\n");
953 printk ("LBA: %s",id->capability & 0x02 ? "Yes\n":"No\n");
954 printk ("IORDY can be disabled: %s",id->capability & 0x04 ? "Yes\n":"No\n");
955 printk ("IORDY supported: %s",id->capability & 0x08 ? "Yes\n":"Unknown\n");
956 printk ("PIO Cycle Timing Category: %d\n",id->tPIO);
957 printk ("DMA Cycle Timing Category: %d\n",id->tDMA);
958 printk ("Single Word DMA supported modes: ");
959 for (i=0,mask=1;i<8;i++,mask=mask << 1) {
960 if (id->dma_1word & mask)
961 printk ("%d ",i);
962 if (id->dma_1word & (mask << 8))
963 printk ("(active) ");
964 }
965 printk ("\n");
966
967 printk ("Multi Word DMA supported modes: ");
968 for (i=0,mask=1;i<8;i++,mask=mask << 1) {
969 if (id->dma_mword & mask)
970 printk ("%d ",i);
971 if (id->dma_mword & (mask << 8))
972 printk ("(active) ");
973 }
974 printk ("\n");
975
976 if (id->field_valid & 0x0002) {
977 printk ("Enhanced PIO Modes: %s\n",id->eide_pio_modes & 1 ? "Mode 3":"None");
978 printk ("Minimum Multi-word DMA cycle per word: ");
979 if (id->eide_dma_min == 0)
980 printk ("Not supported\n");
981 else
982 printk ("%d ns\n",id->eide_dma_min);
983
984 printk ("Manafactuer\'s Recommended Multi-word cycle: ");
985 if (id->eide_dma_time == 0)
986 printk ("Not supported\n");
987 else
988 printk ("%d ns\n",id->eide_dma_time);
989
990 printk ("Minimum PIO cycle without IORDY: ");
991 if (id->eide_pio == 0)
992 printk ("Not supported\n");
993 else
994 printk ("%d ns\n",id->eide_pio);
995
996 printk ("Minimum PIO cycle with IORDY: ");
997 if (id->eide_pio_iordy == 0)
998 printk ("Not supported\n");
999 else
1000 printk ("%d ns\n",id->eide_pio_iordy);
1001
1002 }
1003
1004 else {
1005 printk ("According to the device, fields 64-70 are not valid.\n");
1006 }
1007 #endif
1008
1009
1010
1011 if (gcw.protocol !=2 ) {
1012 printk ("ide-tape: Protocol is not ATAPI\n");support=0;
1013 }
1014
1015 if (gcw.device_type != 1) {
1016 printk ("ide-tape: Device type is not set to tape\n");support=0;
1017 }
1018
1019 if (!gcw.removable) {
1020 printk ("ide-tape: The removable flag is not set\n");support=0;
1021 }
1022
1023 if (gcw.drq_type != 2) {
1024 printk ("ide-tape: Sorry, DRQ types other than Accelerated DRQ\n");
1025 printk ("ide-tape: are still not supproted by the driver\n");support=0;
1026 }
1027
1028 if (gcw.packet_size != 0) {
1029 printk ("ide-tape: Packet size is not 12 bytes long\n");
1030 if (gcw.packet_size == 1)
1031 printk ("ide-tape: Sorry, padding to 16 bytes is still not supported\n");
1032 support=0;
1033 }
1034
1035 if (idetape_drive_already_found) {
1036 printk ("ide-tape: Sorry, only one ide tape drive is supported by the driver\n");
1037 support=0;
1038 }
1039 else {
1040 idetape_drive_already_found=1;
1041 idetape_chrdev.drive=drive;
1042 idetape_chrdev.major=IDETAPE_MAJOR;
1043 idetape_chrdev.minor=0;
1044 idetape_chrdev.name[0]='h';
1045 idetape_chrdev.name[1]='t';
1046 idetape_chrdev.name[2]='0';
1047 idetape_chrdev.name[3]=0;
1048 }
1049
1050 return (support);
1051 }
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061 void idetape_register_chrdev (void)
1062
1063 {
1064 int major,minor;
1065 ide_drive_t *drive;
1066
1067 if (!idetape_drive_already_found)
1068 return;
1069
1070 drive=idetape_chrdev.drive;
1071 major=idetape_chrdev.major;
1072 minor=idetape_chrdev.minor;
1073
1074 if (register_chrdev (major,idetape_chrdev.name,&idetape_fops)) {
1075 printk ("Unable to register character device interface !\n");
1076
1077 }
1078 else {
1079 printk ("ide-tape: %s <-> %s : Character device interface on major = %d\n",
1080 drive->name,idetape_chrdev.name,major);
1081 }
1082 }
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098 void idetape_setup (ide_drive_t *drive)
1099
1100 {
1101 idetape_tape_t *tape=&(drive->tape);
1102 unsigned int allocation_length;
1103
1104 #if IDETAPE_DEBUG
1105 printk ("ide-tape: Reached idetape_setup\n");
1106 #endif
1107
1108 drive->ready_stat = 0;
1109
1110 HWIF(drive)->tape_drive=drive;
1111
1112 tape->block_address=0;
1113 tape->block_address_valid=0;
1114 tape->pc_stack_index=0;
1115 tape->failed_pc=NULL;
1116 tape->postponed_rq=NULL;
1117 tape->busy=0;
1118 tape->active_data_request=NULL;
1119 tape->current_number_of_stages=0;
1120 tape->first_stage=tape->last_stage=NULL;
1121 tape->pipeline_was_full_once=0;
1122 tape->error_in_pipeline_stage=0;
1123 tape->pipeline_locked=0;
1124
1125 tape->request_status=0;
1126 tape->request_dsc_callback=0;
1127
1128 #if IDETAPE_PIPELINE
1129 tape->max_number_of_stages=IDETAPE_MIN_PIPELINE_STAGES;
1130 printk ("ide-tape: Operating in pipelined (fast and tricky) write mode.\n");
1131 #else
1132 tape->max_number_of_stages=0;
1133 printk ("ide-tape: Operating in non-pipelined (slow and safe) write mode.\n");
1134 #endif
1135 printk ("ide-tape: Operating in non-pipelined (slow and safe) read mode.\n");
1136
1137 idetape_get_mode_sense_results (drive);
1138
1139 tape->data_buffer_size=tape->capabilities.ctl*tape->tape_block_size;
1140
1141 allocation_length=tape->data_buffer_size;
1142 if (tape->data_buffer_size % IDETAPE_ALLOCATION_BLOCK)
1143 allocation_length+=IDETAPE_ALLOCATION_BLOCK;
1144
1145 tape->data_buffer=kmalloc (allocation_length,GFP_KERNEL);
1146 tape->temp_data_buffer=kmalloc (allocation_length,GFP_KERNEL);
1147 if (tape->data_buffer == NULL || tape->temp_data_buffer == NULL) {
1148 printk ("ide-tape: FATAL - Can not allocate 2 buffers of %d bytes each\n",allocation_length);
1149 printk ("ide-tape: Aborting character device installation\n");
1150 idetape_drive_already_found=0;
1151 unregister_chrdev (idetape_chrdev.major,idetape_chrdev.name);
1152 return;
1153 }
1154
1155 printk ("ide-tape: Tape speed - %d KBps. Recommended transfer unit - %d bytes.\n",tape->capabilities.speed,tape->data_buffer_size);
1156
1157 return;
1158 }
1159
1160
1161
1162
1163
1164
1165
1166 void idetape_get_mode_sense_results (ide_drive_t *drive)
1167
1168 {
1169 int retval;
1170 idetape_tape_t *tape=&(drive->tape);
1171 idetape_mode_parameter_header_t *header;
1172 idetape_capabilities_page_t *capabilities;
1173 idetape_packet_command_t pc;
1174
1175 idetape_create_mode_sense_cmd (&pc,IDETAPE_CAPABILITIES_PAGE);
1176 pc.buffer=pc.temp_buffer;
1177 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
1178 pc.current_position=pc.temp_buffer;
1179 retval=idetape_queue_pc_tail (drive,&pc);
1180
1181 header=(idetape_mode_parameter_header_t *) pc.buffer;
1182 capabilities=(idetape_capabilities_page_t *) (pc.buffer+sizeof (idetape_mode_parameter_header_t));
1183
1184 capabilities->max_speed=idetape_swap_short (capabilities->max_speed);
1185 capabilities->ctl=idetape_swap_short (capabilities->ctl);
1186 capabilities->speed=idetape_swap_short (capabilities->speed);
1187 capabilities->buffer_size=idetape_swap_short (capabilities->buffer_size);
1188
1189 tape->capabilities=*capabilities;
1190 tape->tape_block_size=capabilities->blk512 ? 512:1024;
1191
1192 if (retval) {
1193 printk ("ide-tape: Can't get tape parameters\n");
1194 printk ("ide-tape: Assuming some default parameters\n");
1195 tape->tape_block_size=512;
1196 tape->capabilities.ctl=26*1024;
1197 return;
1198 }
1199
1200 #if IDETAPE_DEBUG
1201 printk ("Dumping the results of the MODE SENSE packet command\n");
1202 printk ("Mode Parameter Header:\n");
1203 printk ("Mode Data Length - %d\n",header->mode_data_length);
1204 printk ("Medium Type - %d\n",header->medium_type);
1205 printk ("Device Specific Parameter - %d\n",header->dsp);
1206 printk ("Block Descriptor Length - %d\n",header->bdl);
1207
1208 printk ("Capabilities and Mechanical Status Page:\n");
1209 printk ("Page code - %d\n",capabilities->page_code);
1210 printk ("Page length - %d\n",capabilities->page_length);
1211 printk ("Read only - %s\n",capabilities->ro ? "Yes":"No");
1212 printk ("Supports reverse space - %s\n",capabilities->sprev ? "Yes":"No");
1213 printk ("Supports erase initiated formatting - %s\n",capabilities->efmt ? "Yes":"No");
1214 printk ("Supports QFA two Partition format - %s\n",capabilities->qfa ? "Yes":"No");
1215 printk ("Supports locking the medium - %s\n",capabilities->lock ? "Yes":"No");
1216 printk ("The volume is currently locked - %s\n",capabilities->locked ? "Yes":"No");
1217 printk ("The device defaults in the prevent state - %s\n",capabilities->prevent ? "Yes":"No");
1218 printk ("Supports ejecting the medium - %s\n",capabilities->eject ? "Yes":"No");
1219 printk ("Supports error correction - %s\n",capabilities->ecc ? "Yes":"No");
1220 printk ("Supports data compression - %s\n",capabilities->cmprs ? "Yes":"No");
1221 printk ("Supports 512 bytes block size - %s\n",capabilities->blk512 ? "Yes":"No");
1222 printk ("Supports 1024 bytes block size - %s\n",capabilities->blk1024 ? "Yes":"No");
1223 printk ("Restricted byte count for PIO transfers - %s\n",capabilities->slowb ? "Yes":"No");
1224 printk ("Maximum supported speed in KBps - %d\n",capabilities->max_speed);
1225 printk ("Continuous transfer limits in blocks - %d\n",capabilities->ctl);
1226 printk ("Current speed in KBps - %d\n",capabilities->speed);
1227 printk ("Buffer size - %d\n",capabilities->buffer_size*512);
1228 #endif
1229 }
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274 void idetape_issue_packet_command (ide_drive_t *drive,idetape_packet_command_t *pc,ide_handler_t *handler)
1275
1276 {
1277 idetape_tape_t *tape;
1278 idetape_bcount_reg_t bcount;
1279 idetape_ireason_reg_t ireason;
1280
1281 tape=&(drive->tape);
1282
1283 #if IDETAPE_DEBUG
1284 if (tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD && pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
1285 printk ("ide-tape: ide-tape.c bug - Two request sense in serial were issued\n");
1286
1287 }
1288 #endif
1289
1290 if (tape->failed_pc == NULL && pc->c[0] != IDETAPE_REQUEST_SENSE_CMD)
1291 tape->failed_pc=pc;
1292 tape->pc=pc;
1293
1294 if (pc->retries > IDETAPE_MAX_PC_RETRIES) {
1295 printk ("ide-tape: %s: I/O error, ",drive->name);
1296 printk ("pc = %x, key = %x, asc = %x, ascq = %x\n",pc->c[0],tape->sense_key,tape->asc,tape->ascq);
1297 printk ("ide-tape: Maximum retries reached - Giving up\n");
1298 pc->error=1;
1299 pc->active=0;
1300 tape->failed_pc=NULL;
1301 #if IDETAPE_DEBUG
1302 if (pc->callback==NULL)
1303 printk ("ide-tape: ide-tape bug - Callback function not set !\n");
1304 else
1305 #endif
1306 (*pc->callback)(drive);
1307 return;
1308 }
1309
1310 #if IDETAPE_DEBUG
1311 printk ("Retry number - %d\n",pc->retries);
1312 #endif
1313
1314 pc->retries++;
1315
1316
1317
1318
1319
1320
1321 pc->actually_transferred=0;
1322 pc->active=1;
1323 bcount.all=pc->request_transfer;
1324
1325
1326 OUT_BYTE (0,IDETAPE_FEATURES_REG);
1327 OUT_BYTE (bcount.b.high,IDETAPE_BCOUNTH_REG);
1328 OUT_BYTE (bcount.b.low,IDETAPE_BCOUNTL_REG);
1329 OUT_BYTE (drive->select.all,IDETAPE_DRIVESEL_REG);
1330
1331 ide_set_handler (drive,handler,WAIT_CMD);
1332 OUT_BYTE (WIN_PACKETCMD,IDETAPE_ATACOMMAND_REG);
1333 if (ide_wait_stat (drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) {
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343 printk ("ide-tape: Strange, packet command initiated yet DRQ isn't asserted\n");
1344 return;
1345 }
1346
1347 ireason.all=IN_BYTE (IDETAPE_IREASON_REG);
1348 if (!ireason.b.cod || ireason.b.io) {
1349 printk ("ide-tape: (IO,CoD) != (0,1) while issuing a packet command\n");
1350
1351 }
1352
1353 ide_output_data (drive,pc->c,12/4);
1354 }
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366 void idetape_pc_intr (ide_drive_t *drive)
1367
1368 {
1369 idetape_tape_t *tape;
1370 idetape_status_reg_t status;
1371 idetape_bcount_reg_t bcount;
1372 idetape_ireason_reg_t ireason;
1373 idetape_packet_command_t *pc;
1374
1375 unsigned long temp;
1376
1377 tape=&(drive->tape);
1378
1379 status.all=IN_BYTE (IDETAPE_STATUS_REG);
1380
1381 #if IDETAPE_DEBUG
1382 printk ("ide-tape: Reached idetape_pc_intr interrupt handler\n");
1383 #endif
1384
1385 pc=tape->pc;
1386
1387 if (!status.b.drq) {
1388 #if IDETAPE_DEBUG
1389 printk ("Packet command completed\n");
1390 printk ("Total bytes transferred: %lu\n",pc->actually_transferred);
1391 #endif
1392 if (status.b.check) {
1393 #if IDETAPE_DEBUG
1394
1395
1396
1397
1398 printk ("ide-tape: %s: I/O error, ",drive->name);
1399 #endif
1400 idetape_retry_pc (drive);
1401 return;
1402 }
1403 pc->error=0;
1404 if (pc->wait_for_dsc && !status.b.dsc) {
1405 tape->dsc_polling_frequency=IDETAPE_DSC_FAST_MEDIA_ACCESS_FREQUENCY;
1406 idetape_postpone_request (drive);
1407 return;
1408 }
1409 pc->active=0;
1410 if (tape->failed_pc == pc)
1411 tape->failed_pc=NULL;
1412 #if IDETAPE_DEBUG
1413 if (pc->callback==NULL)
1414 printk ("ide-tape: ide-tape bug - Callback function not set !\n");
1415 else
1416 #endif
1417 (*pc->callback)(drive);
1418 return;
1419 }
1420
1421 bcount.b.high=IN_BYTE (IDETAPE_BCOUNTH_REG);
1422 bcount.b.low=IN_BYTE (IDETAPE_BCOUNTL_REG);
1423 ireason.all=IN_BYTE (IDETAPE_IREASON_REG);
1424
1425 if (ireason.b.cod) {
1426 printk ("ide-tape: CoD != 0 in idetape_pc_intr\n");
1427
1428 }
1429 if (ireason.b.io != !(pc->writing)) {
1430 printk ("ide-tape: We wanted to %s, ",pc->writing ? "Write":"Read");
1431 printk ("but the tape wants us to %s !\n",ireason.b.io ? "Read":"Write");
1432
1433 }
1434
1435 if (!pc->writing) {
1436 temp=(unsigned long) pc->actually_transferred + bcount.all;
1437 if ( temp > pc->request_transfer) {
1438 printk ("ide-tape: The tape wants to send us more data than requested - ");
1439 if (temp > pc->buffer_size) {
1440 printk ("Discarding data\n");
1441 idetape_discard_data (drive,bcount.all);
1442 ide_set_handler (drive,&idetape_pc_intr,WAIT_CMD);
1443 return;
1444 }
1445 else
1446 printk ("Allowing transfer\n");
1447 }
1448 }
1449 #if IDETAPE_DEBUG
1450 if (bcount.all && !pc->buffer) {
1451 printk ("ide-tape: ide-tape.c bug - Buffer not set in idetape_pc_intr. Discarding data.\n");
1452
1453 if (!pc->writing) {
1454 printk ("ide-tape: Discarding data\n");
1455 idetape_discard_data (drive,bcount.all);
1456 ide_set_handler (drive,&idetape_pc_intr,WAIT_CMD);
1457 return;
1458 }
1459 else {
1460 }
1461 }
1462 #endif
1463 if (pc->writing)
1464 idetape_output_data (drive,pc->current_position,bcount.all);
1465 else
1466 idetape_input_data (drive,pc->current_position,bcount.all);
1467 #if IDETAPE_DEBUG
1468 printk ("ide-tape: %s %d bytes\n",pc->writing ? "Wrote":"Received",bcount.all);
1469 #endif
1470 pc->actually_transferred+=bcount.all;
1471 pc->current_position+=bcount.all;
1472
1473 ide_set_handler (drive,&idetape_pc_intr,WAIT_CMD);
1474 }
1475
1476
1477
1478
1479
1480
1481
1482 void idetape_postpone_request (ide_drive_t *drive)
1483
1484 {
1485 idetape_tape_t *tape;
1486 unsigned long flags;
1487 struct request *rq;
1488 idetape_status_reg_t status;
1489
1490 tape=&(drive->tape);
1491 status.all=IN_BYTE (IDETAPE_STATUS_REG);
1492
1493 sti ();
1494
1495 #if IDETAPE_DEBUG
1496 printk ("Reached idetape_postpone_request\n");
1497 if (tape->postponed_rq != NULL)
1498 printk ("ide-tape.c bug - postponed_rq not NULL in idetape_postpone_request\n");
1499 #endif
1500
1501 tape->dsc_timer.expires=jiffies + tape->dsc_polling_frequency;
1502 tape->dsc_timeout=jiffies+IDETAPE_DSC_TIMEOUT;
1503 tape->dsc_timer.data=(unsigned long) drive;
1504 tape->dsc_timer.function=&idetape_poll_for_dsc;
1505 init_timer (&(tape->dsc_timer));
1506
1507
1508
1509
1510
1511 tape->postponed_rq = rq = HWGROUP(drive)->rq;
1512 rq->rq_status = IDETAPE_RQ_POSTPONED;
1513 save_flags(flags);cli ();
1514 blk_dev[MAJOR(rq->rq_dev)].current_request = rq->next;
1515 HWGROUP(drive)->rq = NULL;
1516 restore_flags(flags);
1517
1518 tape->request_status=0;
1519 tape->request_dsc_callback=0;
1520 tape->last_status=status.all;
1521
1522 tape->dsc_polling_start=jiffies;
1523 add_timer(&(tape->dsc_timer));
1524 }
1525
1526
1527
1528
1529
1530
1531
1532 void idetape_poll_for_dsc_direct (unsigned long data)
1533
1534 {
1535 ide_drive_t *drive=(ide_drive_t *) data;
1536 ide_hwgroup_t *hwgroup=HWGROUP (drive);
1537 idetape_tape_t *tape=&(drive->tape);
1538 idetape_status_reg_t status;
1539 unsigned long flags;
1540
1541 #if IDETAPE_DEBUG
1542 printk ("%s: idetape_poll_for_dsc_direct called\n",drive->name);
1543 #endif
1544
1545 save_flags (flags);cli ();
1546 OUT_BYTE(drive->select.all,IDE_SELECT_REG);
1547 status.all=IN_BYTE (IDETAPE_STATUS_REG);
1548 if (hwgroup->drive != NULL)
1549 OUT_BYTE (hwgroup->drive->select.all,IDE_SELECT_REG);
1550 restore_flags (flags);
1551
1552 if (status.b.dsc) {
1553 tape->dsc_received=1;
1554 del_timer (&(tape->dsc_timer));
1555 idetape_put_back_postponed_request (drive);
1556 return;
1557 }
1558
1559 if (jiffies > tape->dsc_timeout) {
1560 tape->dsc_received=0;
1561 del_timer (&(tape->dsc_timer));
1562
1563 idetape_put_back_postponed_request (drive);
1564 return;
1565 }
1566
1567
1568
1569 if (jiffies - tape->dsc_polling_start > IDETAPE_FAST_SLOW_THRESHOLD)
1570 tape->dsc_timer.expires = jiffies + IDETAPE_DSC_SLOW_MEDIA_ACCESS_FREQUENCY;
1571 else
1572 tape->dsc_timer.expires = jiffies + tape->dsc_polling_frequency;
1573 add_timer(&(tape->dsc_timer));
1574 return;
1575 }
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595 void idetape_poll_for_dsc (unsigned long data)
1596
1597 {
1598 ide_drive_t *drive=(ide_drive_t *) data;
1599 unsigned int major = HWIF(drive)->major;
1600 idetape_tape_t *tape=&(drive->tape);
1601 struct blk_dev_struct *bdev = &blk_dev[major];
1602 unsigned long flags;
1603
1604 idetape_status_reg_t status;
1605
1606 save_flags (flags);cli ();
1607
1608 #if IDETAPE_DEBUG
1609 printk ("%s: idetape_poll_for_dsc called\n",drive->name);
1610 #endif
1611
1612
1613
1614
1615
1616
1617 if (bdev->current_request == NULL) {
1618 restore_flags (flags);
1619 idetape_poll_for_dsc_direct (data);
1620 return;
1621 }
1622
1623 if (bdev->current_request->next == NULL) {
1624
1625
1626
1627
1628
1629
1630
1631 restore_flags (flags);
1632 tape->dsc_timer.expires = jiffies + tape->dsc_polling_frequency/2;
1633 add_timer(&(tape->dsc_timer));
1634 return;
1635 }
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648 status.all=tape->last_status;
1649
1650 if (status.b.dsc) {
1651 tape->dsc_received=1;
1652 del_timer (&(tape->dsc_timer));
1653 tape->request_dsc_callback=1;
1654 restore_flags (flags);
1655 return;
1656 }
1657
1658 if (jiffies > tape->dsc_timeout) {
1659 tape->dsc_received=1;
1660 del_timer (&(tape->dsc_timer));
1661
1662 tape->request_dsc_callback=1;
1663 restore_flags (flags);
1664 return;
1665 }
1666
1667
1668
1669
1670
1671
1672 tape->request_status=1;
1673 restore_flags (flags);
1674
1675
1676
1677 if (jiffies - tape->dsc_polling_start > IDETAPE_FAST_SLOW_THRESHOLD)
1678 tape->dsc_timer.expires = jiffies + IDETAPE_DSC_SLOW_MEDIA_ACCESS_FREQUENCY;
1679 else
1680 tape->dsc_timer.expires = jiffies + tape->dsc_polling_frequency;
1681 add_timer(&(tape->dsc_timer));
1682 return;
1683 }
1684
1685
1686
1687
1688
1689
1690
1691 void idetape_put_back_postponed_request (ide_drive_t *drive)
1692
1693 {
1694 idetape_tape_t *tape = &(drive->tape);
1695
1696 #if IDETAPE_DEBUG
1697 printk ("ide-tape: Putting back postponed request\n");
1698 #endif
1699
1700 (void) ide_do_drive_cmd (drive, tape->postponed_rq, ide_next);
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712 }
1713
1714 void idetape_media_access_finished (ide_drive_t *drive)
1715
1716 {
1717 idetape_tape_t *tape=&(drive->tape);
1718 idetape_status_reg_t status;
1719 idetape_packet_command_t *pc;
1720
1721 pc=tape->pc;
1722
1723 status.all=IN_BYTE (IDETAPE_STATUS_REG);
1724
1725 if (tape->dsc_received) {
1726 #if IDETAPE_DEBUG
1727 printk ("DSC received\n");
1728 #endif
1729 pc->active=0;
1730 if (status.b.check) {
1731 printk ("ide-tape: %s: I/O error, ",drive->name);
1732 idetape_retry_pc (drive);
1733 return;
1734 }
1735 pc->error=0;
1736 if (tape->failed_pc == pc)
1737 tape->failed_pc=NULL;
1738 #if IDETAPE_DEBUG
1739 if (pc->callback==NULL)
1740 printk ("ide-tape: ide-tape bug - Callback function not set !\n");
1741 else
1742 #endif
1743 (*pc->callback)(drive);
1744
1745 return;
1746 }
1747 else {
1748 pc->active=0;
1749 printk ("ide-tape: %s: DSC timeout.\n",drive->name);
1750
1751 pc->error=1;
1752 tape->failed_pc=NULL;
1753 #if IDETAPE_DEBUG
1754 if (pc->callback==NULL)
1755 printk ("ide-tape: ide-tape bug - Callback function not set !\n");
1756 else
1757 #endif
1758 (*pc->callback)(drive);
1759 return;
1760 }
1761 }
1762
1763
1764
1765
1766
1767
1768
1769
1770 void idetape_retry_pc (ide_drive_t *drive)
1771
1772 {
1773 idetape_packet_command_t *pc;
1774 struct request *new_rq;
1775
1776 idetape_error_reg_t error;
1777 error.all=IN_BYTE (IDETAPE_ERROR_REG);
1778 pc=idetape_next_pc_storage (drive);
1779 new_rq=idetape_next_rq_storage (drive);
1780 idetape_create_request_sense_cmd (pc);
1781 pc->buffer=pc->temp_buffer;
1782 pc->buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
1783 pc->current_position=pc->temp_buffer;
1784 idetape_queue_pc_head (drive,pc,new_rq);
1785 }
1786
1787
1788
1789
1790
1791 void idetape_pc_callback (ide_drive_t *drive)
1792
1793 {
1794 idetape_tape_t *tape;
1795 struct request *rq;
1796
1797 tape=&(drive->tape);
1798 rq=HWGROUP(drive)->rq;
1799
1800 #if IDETAPE_DEBUG
1801 printk ("ide-tape: Reached idetape_pc_callback\n");
1802 #endif
1803 if (!tape->pc->error) {
1804 #if IDETAPE_DEBUG
1805 printk ("Request completed\n");
1806 #endif
1807 idetape_end_request (1,HWGROUP (drive));
1808 }
1809 else {
1810 printk ("Aborting request\n");
1811 idetape_end_request (0,HWGROUP (drive));
1812 }
1813 return;
1814 }
1815
1816
1817 void idetape_read_callback (ide_drive_t *drive)
1818
1819 {
1820 idetape_tape_t *tape;
1821 struct request *rq;
1822
1823 tape=&(drive->tape);
1824 rq=HWGROUP(drive)->rq;
1825 #if IDETAPE_DEBUG
1826 printk ("ide-tape: Reached idetape_read_callback\n");
1827 #endif
1828 tape->block_address+=tape->pc->actually_transferred/tape->tape_block_size;
1829 if (!tape->pc->error) {
1830 #if IDETAPE_DEBUG
1831 printk ("Request completed\n");
1832 #endif
1833 rq->sector+=rq->current_nr_sectors;
1834 rq->nr_sectors-=rq->current_nr_sectors;
1835 rq->current_nr_sectors=0;
1836 idetape_end_request (1,HWGROUP (drive));
1837 }
1838 else {
1839 printk ("Aborting request\n");
1840 idetape_end_request (0,HWGROUP (drive));
1841 }
1842 return;
1843 }
1844
1845 void idetape_write_callback (ide_drive_t *drive)
1846
1847 {
1848 idetape_tape_t *tape;
1849 struct request *rq;
1850
1851 tape=&(drive->tape);
1852 rq=HWGROUP(drive)->rq;
1853 #if IDETAPE_DEBUG
1854 printk ("ide-tape: Reached idetape_write_callback\n");
1855 #endif
1856 tape->block_address+=tape->pc->actually_transferred/tape->tape_block_size;
1857 if (!tape->pc->error) {
1858 #if IDETAPE_DEBUG
1859 printk ("Request completed\n");
1860 #endif
1861 rq->sector+=rq->current_nr_sectors;
1862 rq->nr_sectors-=rq->current_nr_sectors;
1863 rq->current_nr_sectors=0;
1864 idetape_end_request (1,HWGROUP (drive));
1865 }
1866 else {
1867 printk ("Aborting request\n");
1868 idetape_end_request (0,HWGROUP (drive));
1869 }
1870 return;
1871 }
1872
1873 void idetape_inquiry_callback (ide_drive_t *drive)
1874
1875 {
1876 idetape_tape_t *tape;
1877
1878 tape=&(drive->tape);
1879
1880 idetape_display_inquiry_result (tape->pc->buffer);
1881 idetape_pc_callback (drive);
1882 return;
1883 }
1884
1885
1886
1887
1888
1889
1890
1891
1892 void idetape_input_data (ide_drive_t *drive,void *buffer, unsigned long bcount)
1893
1894 {
1895 unsigned long wcount;
1896
1897 wcount=bcount >> 2;
1898 bcount -= 4*wcount;
1899
1900 if (wcount)
1901 ide_input_data (drive,buffer,wcount);
1902
1903 if (bcount) {
1904 ((byte *)buffer) += 4*wcount;
1905 insb (IDETAPE_DATA_REG,buffer,bcount);
1906 }
1907 }
1908
1909
1910
1911
1912
1913 void idetape_output_data (ide_drive_t *drive,void *buffer, unsigned long bcount)
1914
1915 {
1916 unsigned long wcount;
1917
1918 wcount=bcount >> 2;
1919 bcount -= 4*wcount;
1920
1921 if (wcount)
1922 ide_output_data (drive,buffer,wcount);
1923
1924 if (bcount) {
1925 ((byte *)buffer) += 4*wcount;
1926 outsb (IDETAPE_DATA_REG,buffer,bcount);
1927 }
1928 }
1929
1930
1931
1932
1933
1934
1935 void idetape_discard_data (ide_drive_t *drive, unsigned long bcount)
1936
1937 {
1938 unsigned long i;
1939
1940 for (i=0;i<bcount;i++)
1941 IN_BYTE (IDETAPE_DATA_REG);
1942 }
1943
1944
1945
1946
1947
1948 void idetape_create_inquiry_cmd (idetape_packet_command_t *pc)
1949
1950 {
1951 #if IDETAPE_DEBUG
1952 printk ("ide-tape: Creating INQUIRY packet command\n");
1953 #endif
1954 pc->request_transfer=36;
1955 pc->callback=&idetape_inquiry_callback;
1956 pc->writing=0;
1957
1958 idetape_zero_packet_command (pc);
1959 pc->c[0]=IDETAPE_INQUIRY_CMD;
1960 pc->c[4]=255;
1961 }
1962
1963
1964
1965
1966
1967 void idetape_display_inquiry_result (byte *buffer)
1968
1969 {
1970 idetape_inquiry_result_t *result;
1971
1972 result=(idetape_inquiry_result_t *) buffer;
1973 ide_fixstring (result->vendor_id,8,0);
1974 ide_fixstring (result->product_id,16,0);
1975 ide_fixstring (result->revision_level,4,0);
1976
1977 if (result->response_format != 2) {
1978 printk ("The INQUIRY Data Format is unknown to us !\n");
1979 printk ("Assuming QIC-157C format.\n");
1980 }
1981
1982 #if IDETAPE_DEBUG
1983 printk ("Dumping INQUIRY command results:\n");
1984 printk ("Response Data Format: %d - ",result->response_format);
1985 switch (result->response_format) {
1986 case 2:
1987 printk ("As specified in QIC-157 Revision C\n");
1988 break;
1989 default:
1990 printk ("Unknown\n");
1991 break;
1992 }
1993
1994 printk ("Device Type: %x - ",result->device_type);
1995 switch (result->device_type) {
1996 case 0: printk ("Direct-access Device\n");break;
1997 case 1: printk ("Streaming Tape Device\n");break;
1998 case 2: case 3: case 4: printk ("Reserved\n");break;
1999 case 5: printk ("CD-ROM Device\n");break;
2000 case 6: printk ("Reserved\n");
2001 case 7: printk ("Optical memory Device\n");break;
2002 case 0x1f: printk ("Unknown or no Device type\n");break;
2003 default: printk ("Reserved\n");
2004 }
2005
2006 printk ("Removable Medium: %s",result->rmb ? "Yes\n":"No\n");
2007
2008 printk ("ANSI Version: %d - ",result->ansi_version);
2009 switch (result->ansi_version) {
2010 case 2:
2011 printk ("QIC-157 Revision C\n");
2012 break;
2013 default:
2014 printk ("Unknown\n");
2015 break;
2016 }
2017
2018 printk ("ECMA Version: ");
2019 if (result->ecma_version)
2020 printk ("%d\n",result->ecma_version);
2021 else
2022 printk ("Not supported\n");
2023
2024 printk ("ISO Version: ");
2025 if (result->iso_version)
2026 printk ("%d\n",result->iso_version);
2027 else
2028 printk ("Not supported\n");
2029
2030 printk ("Additional Length: %d\n",result->additional_length);
2031 printk ("Vendor Identification: %s\n",result->vendor_id);
2032 printk ("Product Identification: %s\n",result->product_id);
2033 printk ("Product Revision Level: %s\n",result->revision_level);
2034 #endif
2035
2036 if (result->device_type != 1)
2037 printk ("Device type is not set to tape\n");
2038
2039 if (!result->rmb)
2040 printk ("The removable flag is not set\n");
2041
2042 if (result->ansi_version != 2) {
2043 printk ("The Ansi Version is unknown to us !\n");
2044 printk ("Assuming compliance with QIC-157C specification.\n");
2045 }
2046 }
2047
2048 void idetape_create_request_sense_cmd (idetape_packet_command_t *pc)
2049
2050 {
2051 #if IDETAPE_DEBUG
2052 printk ("ide-tape: Creating REQUEST SENSE packet command\n");
2053 #endif
2054 pc->request_transfer=18;
2055 pc->callback=&idetape_request_sense_callback;
2056 pc->writing=0;
2057
2058 idetape_zero_packet_command (pc);
2059 pc->c[0]=IDETAPE_REQUEST_SENSE_CMD;
2060 pc->c[4]=255;
2061 }
2062
2063 void idetape_request_sense_callback (ide_drive_t *drive)
2064
2065 {
2066 idetape_tape_t *tape;
2067 struct request *rq;
2068
2069 tape=&(drive->tape);
2070 rq=HWGROUP(drive)->rq;
2071
2072 #if IDETAPE_DEBUG
2073 printk ("ide-tape: Reached idetape_request_sense_callback\n");
2074 #endif
2075 if (!tape->pc->error) {
2076 #if IDETAPE_DEBUG
2077 printk ("Request completed\n");
2078 #endif
2079 idetape_analyze_error (drive,(idetape_request_sense_result_t *) tape->pc->buffer);
2080 idetape_end_request (1,HWGROUP (drive));
2081 }
2082 else {
2083 printk ("Error in REQUEST SENSE itself - Aborting request!\n");
2084 idetape_end_request (0,HWGROUP (drive));
2085 }
2086 return;
2087 }
2088
2089
2090
2091
2092
2093
2094
2095 void idetape_analyze_error (ide_drive_t *drive,idetape_request_sense_result_t *result)
2096
2097 {
2098 idetape_tape_t *tape;
2099
2100 tape=&(drive->tape);
2101 tape->sense_key=result->sense_key;
2102 tape->asc=result->asc;
2103 tape->ascq=result->ascq;
2104 #if IDETAPE_DEBUG
2105
2106
2107
2108
2109 printk ("ide-tape: sense key = %x, asc = %x, ascq = %x\n",result->sense_key,result->asc,result->ascq);
2110 #endif
2111 return;
2112 }
2113
2114 void idetape_create_test_unit_ready_cmd (idetape_packet_command_t *pc)
2115
2116 {
2117 #if IDETAPE_DEBUG
2118 printk ("ide-tape: Creating TEST UNIT READY packet command\n");
2119 #endif
2120 pc->request_transfer=0;
2121 pc->buffer=NULL;
2122 pc->current_position=NULL;
2123 pc->callback=&idetape_pc_callback;
2124 pc->writing=0;
2125
2126 idetape_zero_packet_command (pc);
2127 pc->c[0]=IDETAPE_TEST_UNIT_READY_CMD;
2128 }
2129
2130 void idetape_create_locate_cmd (idetape_packet_command_t *pc,unsigned long block,byte partition)
2131
2132 {
2133 unsigned long *ptr;
2134
2135 #if IDETAPE_DEBUG
2136 printk ("ide-tape: Creating LOCATE packet command\n");
2137 #endif
2138 pc->request_transfer=0;
2139 pc->buffer=NULL;
2140 pc->current_position=NULL;
2141 pc->buffer_size=0;
2142 pc->wait_for_dsc=1;
2143 pc->callback=&idetape_pc_callback;
2144 pc->writing=0;
2145
2146 idetape_zero_packet_command (pc);
2147 pc->c [0]=IDETAPE_LOCATE_CMD;
2148 pc->c [1]=2;
2149 ptr=(unsigned long *) &(pc->c[3]);
2150 *ptr=idetape_swap_long (block);
2151 pc->c[8]=partition;
2152 }
2153
2154 void idetape_create_rewind_cmd (idetape_packet_command_t *pc)
2155
2156 {
2157 #if IDETAPE_DEBUG
2158 printk ("ide-tape: Creating REWIND packet command\n");
2159 #endif
2160 pc->request_transfer=0;
2161 pc->buffer=NULL;
2162 pc->current_position=NULL;
2163 pc->buffer_size=0;
2164 pc->wait_for_dsc=1;
2165 pc->callback=&idetape_pc_callback;
2166 pc->writing=0;
2167
2168 idetape_zero_packet_command (pc);
2169 pc->c [0]=IDETAPE_REWIND_CMD;
2170 }
2171
2172
2173
2174
2175
2176 void idetape_create_mode_sense_cmd (idetape_packet_command_t *pc,byte page_code)
2177
2178 {
2179 #if IDETAPE_DEBUG
2180 printk ("ide-tape: Creating MODE SENSE packet command - Page %d\n",page_code);
2181 #endif
2182
2183 pc->wait_for_dsc=0;
2184 pc->callback=&idetape_pc_callback;
2185 pc->writing=0;
2186
2187 switch (page_code) {
2188 case IDETAPE_CAPABILITIES_PAGE:
2189 pc->request_transfer=24;
2190 }
2191
2192 idetape_zero_packet_command (pc);
2193 pc->c [0]=IDETAPE_MODE_SENSE_CMD;
2194 pc->c [1]=8;
2195 pc->c [2]=page_code;
2196 pc->c [3]=255;
2197 pc->c [4]=255;
2198 }
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209 void idetape_create_write_filemark_cmd (idetape_packet_command_t *pc,int write_filemark)
2210
2211 {
2212 #if IDETAPE_DEBUG
2213 printk ("Creating WRITE FILEMARK packet command\n");
2214 if (!write_filemark)
2215 printk ("which will only flush buffered data\n");
2216 #endif
2217 pc->request_transfer=0;
2218 pc->buffer=NULL;
2219 pc->current_position=NULL;
2220 pc->buffer_size=0;
2221 pc->wait_for_dsc=1;
2222 pc->callback=&idetape_pc_callback;
2223 pc->writing=0;
2224
2225 idetape_zero_packet_command (pc);
2226 pc->c [0]=IDETAPE_WRITE_FILEMARK_CMD;
2227 if (write_filemark)
2228 pc->c [4]=1;
2229 }
2230
2231 void idetape_create_erase_cmd (idetape_packet_command_t *pc)
2232
2233 {
2234
2235 #if IDETAPE_DEBUG
2236 printk ("Creating ERASE command\n");
2237 #endif
2238
2239 pc->request_transfer=0;
2240 pc->buffer=NULL;
2241 pc->current_position=NULL;
2242 pc->buffer_size=0;
2243 pc->wait_for_dsc=1;
2244 pc->callback=&idetape_pc_callback;
2245 pc->writing=0;
2246
2247 idetape_zero_packet_command (pc);
2248 pc->c [0]=IDETAPE_ERASE_CMD;
2249 pc->c [1]=1;
2250 }
2251
2252 void idetape_create_read_cmd (idetape_packet_command_t *pc,unsigned long length)
2253
2254 {
2255 union convert {
2256 unsigned all :32;
2257 struct {
2258 unsigned b1 :8;
2259 unsigned b2 :8;
2260 unsigned b3 :8;
2261 unsigned b4 :8;
2262 } b;
2263 } original;
2264
2265 #if IDETAPE_DEBUG
2266 printk ("ide-tape: Creating READ packet command\n");
2267 #endif
2268
2269 original.all=length;
2270
2271 pc->wait_for_dsc=0;
2272 pc->callback=&idetape_read_callback;
2273 pc->writing=0;
2274
2275 idetape_zero_packet_command (pc);
2276 pc->c [0]=IDETAPE_READ_CMD;
2277 pc->c [1]=1;
2278 pc->c [4]=original.b.b1;
2279 pc->c [3]=original.b.b2;
2280 pc->c [2]=original.b.b3;
2281
2282 return;
2283 }
2284
2285 void idetape_create_space_cmd (idetape_packet_command_t *pc,long count,byte cmd)
2286
2287 {
2288 union convert {
2289 unsigned all :32;
2290 struct {
2291 unsigned b1 :8;
2292 unsigned b2 :8;
2293 unsigned b3 :8;
2294 unsigned b4 :8;
2295 } b;
2296 } original;
2297
2298 #if IDETAPE_DEBUG
2299 printk ("ide-tape: Creating SPACE packet command\n");
2300 #endif
2301
2302 original.all=count;
2303
2304 pc->request_transfer=0;
2305 pc->buffer=NULL;
2306 pc->current_position=NULL;
2307 pc->buffer_size=0;
2308 pc->wait_for_dsc=1;
2309 pc->callback=&idetape_pc_callback;
2310 pc->writing=0;
2311
2312 idetape_zero_packet_command (pc);
2313 pc->c [0]=IDETAPE_SPACE_CMD;
2314 pc->c [1]=cmd;
2315 pc->c [4]=original.b.b1;
2316 pc->c [3]=original.b.b2;
2317 pc->c [2]=original.b.b3;
2318
2319 return;
2320 }
2321
2322 void idetape_create_write_cmd (idetape_packet_command_t *pc,unsigned long length)
2323
2324 {
2325 union convert {
2326 unsigned all :32;
2327 struct {
2328 unsigned b1 :8;
2329 unsigned b2 :8;
2330 unsigned b3 :8;
2331 unsigned b4 :8;
2332 } b;
2333 } original;
2334
2335 #if IDETAPE_DEBUG
2336 printk ("ide-tape: Creating WRITE packet command\n");
2337 #endif
2338
2339 original.all=length;
2340
2341 pc->wait_for_dsc=0;
2342 pc->callback=&idetape_write_callback;
2343 pc->writing=1;
2344
2345 idetape_zero_packet_command (pc);
2346 pc->c [0]=IDETAPE_WRITE_CMD;
2347 pc->c [1]=1;
2348 pc->c [4]=original.b.b1;
2349 pc->c [3]=original.b.b2;
2350 pc->c [2]=original.b.b3;
2351
2352 return;
2353 }
2354
2355 void idetape_create_read_position_cmd (idetape_packet_command_t *pc)
2356
2357 {
2358 #if IDETAPE_DEBUG
2359 printk ("ide-tape: Creating READ POSITION packet command\n");
2360 #endif
2361
2362 pc->request_transfer=20;
2363 pc->wait_for_dsc=0;
2364 pc->callback=&idetape_read_position_callback;
2365 pc->writing=0;
2366
2367 idetape_zero_packet_command (pc);
2368 pc->c [0]=IDETAPE_READ_POSITION_CMD;
2369 pc->c [1]=0;
2370 }
2371
2372 void idetape_read_position_callback (ide_drive_t *drive)
2373
2374 {
2375 idetape_tape_t *tape;
2376 struct request *rq;
2377 idetape_read_position_result_t *result;
2378
2379 tape=&(drive->tape);
2380
2381 #if IDETAPE_DEBUG
2382 printk ("ide-tape: Reached idetape_read_position_callback\n");
2383 #endif
2384
2385 rq=HWGROUP(drive)->rq;
2386
2387 if (!tape->pc->error) {
2388 result=(idetape_read_position_result_t *) tape->pc->buffer;
2389 #if IDETAPE_DEBUG
2390 printk ("Request completed\n");
2391 printk ("Dumping the results of the READ POSITION command\n");
2392 printk ("BOP - %s\n",result->bop ? "Yes":"No");
2393 printk ("EOP - %s\n",result->eop ? "Yes":"No");
2394 #endif
2395 if (result->bpu) {
2396 printk ("ide-tape: Block location is unknown to the tape\n");
2397 printk ("Aborting request\n");
2398 tape->block_address_valid=0;
2399 idetape_end_request (0,HWGROUP (drive));
2400 }
2401 else {
2402 #if IDETAPE_DEBUG
2403 printk ("Block Location - %lu\n",idetape_swap_long (result->first_block));
2404 #endif
2405 tape->block_address=idetape_swap_long (result->first_block);
2406 tape->block_address_valid=1;
2407 idetape_end_request (1,HWGROUP (drive));
2408 }
2409 }
2410 else {
2411 printk ("Aborting request\n");
2412 idetape_end_request (0,HWGROUP (drive));
2413 }
2414 return;
2415 }
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425 int idetape_blkdev_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file,
2426 unsigned int cmd, unsigned long arg)
2427 {
2428 idetape_packet_command_t pc;
2429 int retval;
2430
2431 pc.buffer=pc.temp_buffer;
2432 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
2433 pc.current_position=pc.temp_buffer;
2434
2435 #if IDETAPE_DEBUG
2436 printk ("ide-tape: Reached idetape_blkdev_ioctl\n");
2437 #endif
2438 switch (cmd) {
2439 case IDETAPE_INQUIRY_IOCTL:
2440 #if IDETAPE_DEBUG
2441 printk ("Adding INQUIRY packet command to the tail of the request queue\n");
2442 #endif
2443 idetape_create_inquiry_cmd (&pc);
2444 pc.buffer=pc.temp_buffer;
2445 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
2446 pc.current_position=pc.temp_buffer;
2447 return (idetape_queue_pc_tail (drive,&pc));
2448 case IDETAPE_LOCATE_IOCTL:
2449 #if IDETAPE_DEBUG
2450 printk ("Adding LOCATE packet command to the tail of the request queue\n");
2451 #endif
2452 idetape_create_locate_cmd (&pc,arg,0);
2453 retval=idetape_queue_pc_tail (drive,&pc);
2454 if (retval!=0) return (retval);
2455
2456 idetape_create_read_position_cmd (&pc);
2457 pc.buffer=pc.temp_buffer;
2458 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
2459 pc.current_position=pc.temp_buffer;
2460 return (idetape_queue_pc_tail (drive,&pc));
2461
2462
2463
2464
2465
2466 default:
2467 return -EIO;
2468 }
2469 }
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483 void idetape_end_request (byte uptodate, ide_hwgroup_t *hwgroup)
2484
2485 {
2486 ide_drive_t *drive = hwgroup->drive;
2487 struct request *rq = hwgroup->rq;
2488 idetape_tape_t *tape = &(drive->tape);
2489
2490
2491 rq->errors=!uptodate;
2492
2493 if (tape->active_data_request == rq) {
2494 #if IDETAPE_DEBUG
2495 if (!tape->max_number_of_stages)
2496 printk ("ide-tape: non pipelined mode bug\n");
2497 printk ("Finished our active data request\n");
2498 printk ("Requests in pipeline: %d\n",tape->current_number_of_stages);
2499 #endif
2500 if (rq->errors)
2501 tape->error_in_pipeline_stage=1;
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512 tape->pipeline_locked=1;
2513 tape->active_data_request = NULL;
2514 if (tape->first_stage == NULL) {
2515 tape->pipeline_locked=0;
2516 idetape_increase_max_pipeline_stages (drive);
2517 return;
2518 }
2519 idetape_active_next_stage (drive);
2520 tape->pipeline_locked=0;
2521 #if IDETAPE_DEBUG
2522 printk ("Using ide_end\n");
2523 #endif
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533 ide_do_drive_cmd (drive,tape->active_data_request,ide_end);
2534 }
2535 ide_end_drive_cmd (drive, 0, 0);
2536 }
2537
2538
2539
2540
2541
2542 void idetape_do_request (ide_drive_t *drive, struct request *rq, unsigned long block)
2543
2544 {
2545 idetape_tape_t *tape=&(drive->tape);
2546 idetape_packet_command_t *pc;
2547 idetape_status_reg_t status;
2548
2549 #if IDETAPE_DEBUG
2550 printk ("Current request:\n");
2551 printk ("rq_status: %d, rq_dev: %u, cmd: %d, errors: %d\n",rq->rq_status,(unsigned int) rq->rq_dev,rq->cmd,rq->errors);
2552 printk ("sector: %ld, nr_sectors: %ld, current_nr_sectors: %ld\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors);
2553 #endif
2554
2555 if (!IDETAPE_REQUEST_CMD (rq->cmd)) {
2556
2557
2558
2559
2560
2561 printk ("ide-tape: Unsupported command in request queue\n");
2562 printk ("ide-tape: The block device interface should not be used for data transfers.\n");
2563 printk ("ide-tape: Use the character device interfaces\n");
2564 printk ("ide-tape: /dev/ht0 and /dev/nht0 instead.\n");
2565 printk ("ide-tape: (Run linux/drivers/block/MAKEDEV.ide to create them)\n");
2566 printk ("ide-tape: Aborting request.\n");
2567
2568 ide_end_request (0,HWGROUP (drive));
2569 return;
2570 }
2571
2572
2573
2574 if (tape->failed_pc != NULL && tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
2575 idetape_issue_packet_command (drive,tape->failed_pc,&idetape_pc_intr);
2576 return;
2577 }
2578
2579
2580
2581 if (tape->postponed_rq != NULL) {
2582 #if IDETAPE_DEBUG
2583 if (tape->postponed_rq->rq_status != RQ_ACTIVE || rq != tape->postponed_rq) {
2584 printk ("ide-tape: ide-tape.c bug - Two DSC requests were queued\n");
2585 idetape_end_request (0,HWGROUP (drive));
2586 return;
2587 }
2588 #endif
2589 if (rq->cmd == IDETAPE_PACKET_COMMAND_REQUEST_TYPE1) {
2590
2591
2592
2593 tape->postponed_rq = NULL;
2594 idetape_media_access_finished (drive);
2595 return;
2596 }
2597
2598
2599
2600
2601
2602
2603
2604 tape->postponed_rq = NULL;
2605 }
2606
2607 switch (rq->cmd) {
2608 case IDETAPE_READ_REQUEST:
2609 #if IDETAPE_DEBUG
2610 printk ("ide-tape: Handling our own (not buffer cache originated) READ request\n");
2611 #endif
2612 status.all=IN_BYTE (IDETAPE_STATUS_REG);
2613 if (!status.b.dsc) {
2614 #if IDETAPE_DEBUG
2615 printk ("ide-tape: DSC != 1 - Postponing read request\n");
2616 #endif
2617 tape->dsc_polling_frequency=IDETAPE_DSC_READ_WRITE_FREQUENCY;
2618 idetape_postpone_request (drive);
2619 return;
2620 }
2621
2622 pc=idetape_next_pc_storage (drive);
2623
2624 idetape_create_read_cmd (pc,rq->current_nr_sectors);
2625
2626 pc->buffer=rq->buffer;
2627 pc->buffer_size=rq->current_nr_sectors*tape->tape_block_size;
2628 pc->current_position=rq->buffer;
2629 pc->request_transfer=rq->current_nr_sectors*tape->tape_block_size;
2630
2631 idetape_issue_packet_command (drive,pc,&idetape_pc_intr);
2632 return;
2633
2634 case IDETAPE_WRITE_REQUEST:
2635 #if IDETAPE_DEBUG
2636 printk ("ide-tape: Handling our own (not buffer cache originated) WRITE request\n");
2637 #endif
2638
2639 status.all=IN_BYTE (IDETAPE_STATUS_REG);
2640 if (!status.b.dsc) {
2641 #if IDETAPE_DEBUG
2642 printk ("ide-tape: DSC != 1 - Postponing write request\n");
2643 #endif
2644 tape->dsc_polling_frequency=IDETAPE_DSC_READ_WRITE_FREQUENCY;
2645 idetape_postpone_request (drive);
2646 return;
2647 }
2648
2649 pc=idetape_next_pc_storage (drive);
2650
2651 idetape_create_write_cmd (pc,rq->current_nr_sectors);
2652
2653 pc->buffer=rq->buffer;
2654 pc->buffer_size=rq->current_nr_sectors*tape->tape_block_size;
2655 pc->current_position=rq->buffer;
2656 pc->request_transfer=rq->current_nr_sectors*tape->tape_block_size;
2657
2658 idetape_issue_packet_command (drive,pc,&idetape_pc_intr);
2659 return;
2660
2661 case IDETAPE_PACKET_COMMAND_REQUEST_TYPE1:
2662 case IDETAPE_PACKET_COMMAND_REQUEST_TYPE2:
2663
2664
2665
2666
2667
2668 status.all=IN_BYTE (IDETAPE_STATUS_REG);
2669 if (!status.b.dsc) {
2670 #if IDETAPE_DEBUG
2671 printk ("ide-tape: DSC != 1 - Postponing packet command request\n");
2672 #endif
2673 rq->cmd=IDETAPE_PACKET_COMMAND_REQUEST_TYPE2;
2674
2675 tape->dsc_polling_frequency=IDETAPE_DSC_READ_WRITE_FREQUENCY;
2676 idetape_postpone_request (drive);
2677 return;
2678 }
2679 rq->cmd=IDETAPE_PACKET_COMMAND_REQUEST_TYPE1;
2680 pc=(idetape_packet_command_t *) rq->buffer;
2681 idetape_issue_packet_command (drive,pc,&idetape_pc_intr);
2682 return;
2683 #if IDETAPE_DEBUG
2684 default:
2685 printk ("ide-tape: bug in IDETAPE_REQUEST_CMD macro\n");
2686 idetape_end_request (0,HWGROUP (drive));
2687 #endif
2688 }
2689 }
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712 int idetape_queue_pc_tail (ide_drive_t *drive,idetape_packet_command_t *pc)
2713 {
2714 struct request rq;
2715
2716 ide_init_drive_cmd (&rq);
2717 rq.buffer = (char *) pc;
2718 rq.cmd = IDETAPE_PACKET_COMMAND_REQUEST_TYPE1;
2719 return ide_do_drive_cmd (drive, &rq, ide_wait);
2720 }
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742 void idetape_queue_pc_head (ide_drive_t *drive,idetape_packet_command_t *pc,struct request *rq)
2743
2744 {
2745 ide_init_drive_cmd (rq);
2746 rq->buffer = (char *) pc;
2747 rq->cmd = IDETAPE_PACKET_COMMAND_REQUEST_TYPE1;
2748 (void) ide_do_drive_cmd (drive, rq, ide_preempt);
2749 }
2750
2751 void idetape_wait_for_request (struct request *rq)
2752
2753 {
2754 unsigned long flags;
2755 struct semaphore sem = MUTEX_LOCKED;
2756
2757 save_flags (flags);cli ();
2758 rq->sem=&sem;
2759 restore_flags (flags);
2760
2761 down (&sem);
2762 }
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774 int idetape_queue_rw_tail (ide_drive_t *drive,int cmd,int blocks,char *buffer)
2775
2776 {
2777 idetape_tape_t *tape = &(drive->tape);
2778 struct request rq;
2779
2780 #if IDETAPE_DEBUG
2781 printk ("idetape_queue_rw_tail: cmd=%d\n",cmd);
2782 #endif
2783
2784
2785 ide_init_drive_cmd (&rq);
2786 rq.buffer = buffer;
2787 rq.cmd = cmd;
2788 rq.sector = tape->block_address;
2789 rq.nr_sectors = blocks;
2790 rq.current_nr_sectors = blocks;
2791 tape->active_data_request=NULL;
2792 #if IDETAPE_DEBUG
2793 printk ("Using ide_tail\n");
2794 #endif
2795 return ide_do_drive_cmd (drive, &rq, ide_wait);
2796 }
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810 int idetape_add_chrdev_write_request (ide_drive_t *drive,int cmd,int blocks,char *buffer)
2811
2812 {
2813 idetape_tape_t *tape = &(drive->tape);
2814 idetape_pipeline_stage_t *new_stage;
2815 struct request *rq;
2816
2817 #if IDETAPE_DEBUG
2818 printk ("Reached idetape_add_chrdev_write_request\n");
2819 printk ("Trying to allocate stage - ");
2820 #endif
2821
2822 if (tape->error_in_pipeline_stage)
2823 return (-EIO);
2824
2825 new_stage=idetape_kmalloc_stage (drive);
2826
2827
2828
2829
2830
2831
2832
2833
2834 while (new_stage == NULL) {
2835
2836
2837
2838
2839
2840
2841 while (tape->pipeline_locked);
2842
2843 if (tape->first_stage != NULL) {
2844 idetape_wait_for_request (&(tape->first_stage->rq));
2845 new_stage=idetape_kmalloc_stage (drive);
2846 }
2847 else
2848 break;
2849 }
2850
2851
2852
2853
2854
2855
2856 if (new_stage == NULL) {
2857 if (tape->active_data_request != NULL)
2858 idetape_wait_for_request (tape->active_data_request);
2859 return (idetape_queue_rw_tail (drive,cmd,blocks,buffer));
2860 }
2861
2862 rq=&(new_stage->rq);
2863
2864 ide_init_drive_cmd (rq);
2865 rq->buffer = NULL;
2866 rq->cmd = cmd;
2867 rq->sector = tape->block_address;
2868 rq->nr_sectors = blocks;
2869 rq->current_nr_sectors = blocks;
2870
2871 idetape_copy_buffer_to_stage (new_stage,buffer);
2872 idetape_add_stage_tail (drive,new_stage);
2873
2874 return (0);
2875 }
2876
2877 void idetape_empty_pipeline (ide_drive_t *drive)
2878
2879 {
2880 idetape_tape_t *tape = &(drive->tape);
2881
2882 tape->pipeline_was_full_once=0;
2883
2884 while (tape->pipeline_locked);
2885
2886 if (tape->active_data_request == NULL)
2887 idetape_insert_pipeline_into_queue (drive);
2888
2889 if (tape->last_stage != NULL)
2890 idetape_wait_for_request (&(tape->last_stage->rq));
2891
2892 else if (tape->active_data_request != NULL)
2893 idetape_wait_for_request (tape->active_data_request);
2894
2895 tape->error_in_pipeline_stage=0;
2896
2897
2898
2899
2900
2901
2902
2903
2904 #if IDETAPE_PIPELINE
2905 tape->max_number_of_stages=IDETAPE_MIN_PIPELINE_STAGES;
2906 #else
2907 tape->max_number_of_stages=0;
2908 #endif
2909
2910 #if IDETAPE_DEBUG
2911 if (tape->first_stage != NULL || tape->last_stage != NULL || tape->current_number_of_stages != 0) {
2912 printk ("ide-tape: ide-tape pipeline bug\n");
2913 }
2914 #endif
2915 }
2916
2917
2918
2919
2920
2921
2922
2923 void idetape_zero_packet_command (idetape_packet_command_t *pc)
2924
2925 {
2926 int i;
2927
2928 for (i=0;i<12;i++)
2929 pc->c[i]=0;
2930 pc->retries=0;
2931 }
2932
2933
2934
2935
2936
2937
2938 unsigned short idetape_swap_short (unsigned short temp)
2939
2940 {
2941 union convert {
2942 unsigned all :16;
2943 struct {
2944 unsigned b1 :8;
2945 unsigned b2 :8;
2946 } b;
2947 } original,converted;
2948
2949 original.all=temp;
2950 converted.b.b1=original.b.b2;
2951 converted.b.b2=original.b.b1;
2952 return (converted.all);
2953 }
2954
2955
2956
2957
2958
2959 unsigned long idetape_swap_long (unsigned long temp)
2960
2961 {
2962 union convert {
2963 unsigned all :32;
2964 struct {
2965 unsigned b1 :8;
2966 unsigned b2 :8;
2967 unsigned b3 :8;
2968 unsigned b4 :8;
2969 } b;
2970 } original,converted;
2971
2972 original.all=temp;
2973 converted.b.b1=original.b.b4;
2974 converted.b.b2=original.b.b3;
2975 converted.b.b3=original.b.b2;
2976 converted.b.b4=original.b.b1;
2977 return (converted.all);
2978 }
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988 idetape_packet_command_t *idetape_next_pc_storage (ide_drive_t *drive)
2989
2990 {
2991 idetape_tape_t *tape;
2992
2993 tape=&(drive->tape);
2994 #if IDETAPE_DEBUG
2995 printk ("ide-tape: pc_stack_index=%d\n",tape->pc_stack_index);
2996 #endif
2997 if (tape->pc_stack_index==IDETAPE_PC_STACK)
2998 tape->pc_stack_index=0;
2999 return (&(tape->pc_stack [tape->pc_stack_index++]));
3000 }
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015 struct request *idetape_next_rq_storage (ide_drive_t *drive)
3016
3017 {
3018 idetape_tape_t *tape;
3019
3020 tape=&(drive->tape);
3021
3022 #if IDETAPE_DEBUG
3023 printk ("ide-tape: rq_stack_index=%d\n",tape->rq_stack_index);
3024 #endif
3025 if (tape->rq_stack_index==IDETAPE_PC_STACK)
3026 tape->rq_stack_index=0;
3027 return (&(tape->rq_stack [tape->rq_stack_index++]));
3028 }
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038 int idetape_blkdev_open (struct inode *inode, struct file *filp, ide_drive_t *drive)
3039
3040 {
3041 idetape_tape_t *tape=&(drive->tape);
3042 unsigned long flags;
3043
3044 save_flags (flags);cli();
3045
3046 #if IDETAPE_DEBUG
3047 printk ("Reached idetape_blkdev_open\n");
3048 #endif
3049
3050 if (tape->busy) {
3051 restore_flags (flags);
3052 return (-EBUSY);
3053 }
3054
3055 tape->busy=1;
3056 restore_flags (flags);
3057
3058 return (0);
3059 }
3060
3061 void idetape_blkdev_release (struct inode *inode, struct file *filp, ide_drive_t *drive)
3062
3063 {
3064 idetape_tape_t *tape=&(drive->tape);
3065 unsigned long flags;
3066
3067 #if IDETAPE_DEBUG
3068 printk ("Reached idetape_blkdev_release\n");
3069 #endif
3070
3071 save_flags (flags);cli();
3072 tape->busy=0;
3073 restore_flags (flags);
3074
3075 return;
3076 }
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086 int idetape_chrdev_lseek (struct inode *inode, struct file *file, off_t offset, int origin)
3087
3088 {
3089 ide_drive_t *drive;
3090
3091 #if IDETAPE_DEBUG
3092 printk ("Reached idetape_chrdev_lseek\n");
3093 #endif
3094
3095 drive=idetape_chrdev.drive;
3096 if (idetape_position_tape (drive,offset) != 0) {
3097 printk ("ide-tape: Rewinding tape failed\n");
3098 return (-1);
3099 }
3100
3101 return (0);
3102 }
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131 int idetape_chrdev_read (struct inode *inode, struct file *file, char *buf, int count)
3132
3133 {
3134 ide_drive_t *drive;
3135 idetape_tape_t *tape;
3136 int blocks,remainder,retval,ctl_bytes;
3137 char *buf_ptr;
3138 unsigned long previous_block_address,actually_read;
3139
3140 #if IDETAPE_DEBUG
3141 printk ("Reached idetape_chrdev_read\n");
3142 #endif
3143
3144 drive=idetape_chrdev.drive;
3145 tape=&(drive->tape);
3146 tape->last_dt_was_write=0;
3147
3148 if (count==0)
3149 return (0);
3150
3151 actually_read=0;
3152 buf_ptr=buf;
3153 ctl_bytes=tape->capabilities.ctl*tape->tape_block_size;
3154 blocks=count/ctl_bytes;
3155 remainder=count%ctl_bytes;
3156
3157 while (blocks) {
3158 #if IDETAPE_DEBUG
3159 printk ("Adding a READ request to the block device request queue\n");
3160 #endif
3161 previous_block_address=tape->block_address;
3162 retval=idetape_queue_rw_tail (drive,IDETAPE_READ_REQUEST,tape->capabilities.ctl,tape->data_buffer);
3163 actually_read+=tape->tape_block_size*(tape->block_address-previous_block_address);
3164
3165 if (retval) {
3166 printk ("ide-tape: Error occured while reading\n");
3167 return (actually_read);
3168 }
3169 #if IDETAPE_DEBUG
3170 printk ("Copying %d bytes to the user space memory\n",ctl_bytes);
3171 #endif
3172
3173 memcpy_tofs (buf_ptr,tape->data_buffer,ctl_bytes);
3174 buf_ptr+=ctl_bytes;
3175 blocks--;
3176 }
3177 if (remainder)
3178 return (actually_read+idetape_chrdev_read_remainder (inode,file,buf_ptr,remainder));
3179 else
3180 return (actually_read);
3181 }
3182
3183 int idetape_chrdev_read_remainder (struct inode *inode, struct file *file, char *buf, int count)
3184
3185 {
3186 ide_drive_t *drive;
3187 idetape_tape_t *tape;
3188 int blocks,remainder,retval;
3189 unsigned long previous_block_address,actually_read;
3190
3191 #if IDETAPE_DEBUG
3192 printk ("Reached idetape_chrdev_read_remainder\n");
3193 #endif
3194
3195 drive=idetape_chrdev.drive;
3196 tape=&(drive->tape);
3197
3198 tape->last_dt_was_write=0;
3199
3200 if (count==0)
3201 return (0);
3202
3203 blocks=count/tape->tape_block_size;
3204 remainder=count%tape->tape_block_size;
3205 if (remainder) {
3206 #if IDETAPE_DEBUG
3207 printk ("ide-tape: Padding read to block boundary\n");
3208 #endif
3209 blocks++;
3210 }
3211 #if IDETAPE_DEBUG
3212 printk ("Adding a READ request to the block device request queue\n");
3213 #endif
3214 previous_block_address=tape->block_address;
3215 retval=idetape_queue_rw_tail (drive,IDETAPE_READ_REQUEST,blocks,tape->data_buffer);
3216 if (retval) {
3217 printk ("ide-tape: Error occured while reading\n");
3218 actually_read=tape->tape_block_size*(tape->block_address-previous_block_address);
3219 if (actually_read > count)
3220 actually_read=count;
3221 if (actually_read != 0)
3222 memcpy_tofs (buf,tape->data_buffer,actually_read);
3223 return (actually_read);
3224 }
3225 #if IDETAPE_DEBUG
3226 printk ("Copying %d bytes to the user space memory\n",count);
3227 #endif
3228 memcpy_tofs (buf,tape->data_buffer,count);
3229 return (count);
3230 }
3231
3232 int idetape_chrdev_write (struct inode *inode, struct file *file, const char *buf, int count)
3233
3234 {
3235 ide_drive_t *drive;
3236 idetape_tape_t *tape;
3237 int blocks,remainder,retval;
3238 const char *buf_ptr;
3239 unsigned long previous_block_address,actually_written;
3240
3241 #if IDETAPE_DEBUG
3242 printk ("Reached idetape_chrdev_write\n");
3243 #endif
3244
3245 drive=idetape_chrdev.drive;
3246 tape=&(drive->tape);
3247
3248 tape->last_dt_was_write=1;
3249
3250 if (count==0)
3251 return (0);
3252
3253 actually_written=0;
3254 buf_ptr=buf;
3255 blocks=count/tape->data_buffer_size;
3256 remainder=count%tape->data_buffer_size;
3257
3258 while (blocks) {
3259 memcpy_fromfs (tape->temp_data_buffer,buf_ptr,tape->data_buffer_size);
3260 buf_ptr+=tape->data_buffer_size;
3261 previous_block_address=tape->block_address;
3262 retval=idetape_add_chrdev_write_request (drive,IDETAPE_WRITE_REQUEST,tape->capabilities.ctl,tape->temp_data_buffer);
3263 if (tape->max_number_of_stages)
3264 actually_written+=tape->data_buffer_size;
3265 else
3266 actually_written+=tape->tape_block_size*(tape->block_address-previous_block_address);
3267
3268 if (retval) {
3269 printk ("ide-tape: Error occured while writing\n");
3270 if (tape->max_number_of_stages)
3271 return (0);
3272 else
3273 return (actually_written);
3274 }
3275 blocks--;
3276 }
3277 if (remainder)
3278 return (actually_written+idetape_chrdev_write_remainder (inode,file,buf_ptr,remainder));
3279 else
3280 return (actually_written);
3281 }
3282
3283 int idetape_chrdev_write_remainder (struct inode *inode, struct file *file, const char *buf, int count)
3284
3285 {
3286 ide_drive_t *drive;
3287 idetape_tape_t *tape;
3288 int blocks,remainder,retval;
3289 char *ptr;
3290 unsigned long previous_block_address,actually_written;
3291
3292 #if IDETAPE_DEBUG
3293 printk ("Reached idetape_chrdev_write_remainder\n");
3294 #endif
3295
3296 drive=idetape_chrdev.drive;
3297 tape=&(drive->tape);
3298
3299 blocks=count/tape->tape_block_size;
3300 remainder=count%tape->tape_block_size;
3301 if (remainder)
3302 blocks++;
3303 #if IDETAPE_DEBUG
3304 printk ("Copying %d bytes from the user space memory\n",count);
3305 #endif
3306
3307 memcpy_fromfs (tape->temp_data_buffer,buf,count);
3308 if (remainder) {
3309 #if IDETAPE_DEBUG
3310 printk ("ide-tape: Padding written data to block boundary\n");
3311 #endif
3312 ptr=tape->temp_data_buffer+(blocks-1)*tape->tape_block_size;
3313 memset (ptr,0,remainder);
3314 }
3315 #if IDETAPE_DEBUG
3316 printk ("Adding a WRITE request to the block device request queue\n");
3317 #endif
3318
3319 previous_block_address=tape->block_address;
3320 retval=idetape_add_chrdev_write_request (drive,IDETAPE_WRITE_REQUEST,blocks,tape->temp_data_buffer);
3321 if (retval) {
3322 printk ("ide-tape: Error occured while writing\n");
3323 if (tape->max_number_of_stages)
3324 actually_written=0;
3325 else
3326 actually_written=tape->tape_block_size*(tape->block_address-previous_block_address);
3327 if (actually_written > count)
3328 actually_written=count;
3329 return (actually_written);
3330 }
3331 return (count);
3332 }
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343 int idetape_chrdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
3344
3345 {
3346 struct mtop mtop;
3347 ide_drive_t *drive;
3348 int retval;
3349
3350 #if IDETAPE_DEBUG
3351 printk ("Reached idetape_chrdev_ioctl, cmd=%u\n",cmd);
3352 #endif
3353
3354 drive=idetape_chrdev.drive;
3355
3356 switch (cmd) {
3357 case MTIOCTOP:
3358 retval=verify_area (VERIFY_READ,(char *) arg,sizeof (struct mtop));
3359 if (retval) return (retval);
3360 memcpy_fromfs ((char *) &mtop, (char *) arg, sizeof (struct mtop));
3361 return (idetape_mtioctop (drive,mtop.mt_op,mtop.mt_count));
3362 default:
3363 return (idetape_blkdev_ioctl (drive,inode,file,cmd,arg));
3364 }
3365 }
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401 int idetape_mtioctop (ide_drive_t *drive,short mt_op,int mt_count)
3402
3403 {
3404 int i,retval;
3405
3406 idetape_packet_command_t pc;
3407
3408 pc.buffer=pc.temp_buffer;
3409 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
3410 pc.current_position=pc.temp_buffer;
3411
3412 idetape_create_write_filemark_cmd (&pc,0);
3413 retval=idetape_queue_pc_tail (drive,&pc);
3414 if (retval) return (retval);
3415
3416 switch (mt_op) {
3417 case MTFSF:
3418 #if IDETAPE_DEBUG
3419 printk ("Handling MTFSF command\n");
3420 #endif
3421 idetape_create_space_cmd (&pc,mt_count,IDETAPE_SPACE_OVER_FILEMARK);
3422 return (idetape_queue_pc_tail (drive,&pc));
3423 case MTFSFM:
3424 #if IDETAPE_DEBUG
3425 printk ("Handling MTFSFM command\n");
3426 #endif
3427 retval=idetape_mtioctop (drive,MTFSF,mt_count);
3428 if (retval) return (retval);
3429 return (idetape_mtioctop (drive,MTBSF,1));
3430 case MTBSF:
3431 #if IDETAPE_DEBUG
3432 printk ("Handling MTBSF command\n");
3433 #endif
3434 idetape_create_space_cmd (&pc,-mt_count,IDETAPE_SPACE_OVER_FILEMARK);
3435 return (idetape_queue_pc_tail (drive,&pc));
3436 case MTBSFM:
3437 #if IDETAPE_DEBUG
3438 printk ("Handling MTBSFM command\n");
3439 #endif
3440 retval=idetape_mtioctop (drive,MTBSF,mt_count);
3441 if (retval) return (retval);
3442 return (idetape_mtioctop (drive,MTFSF,1));
3443 case MTWEOF:
3444 #if IDETAPE_DEBUG
3445 printk ("Handling MTWEOF command\n");
3446 #endif
3447
3448 for (i=0;i<mt_count;i++) {
3449 idetape_create_write_filemark_cmd (&pc,1);
3450 retval=idetape_queue_pc_tail (drive,&pc);
3451 if (retval) return (retval);
3452 }
3453 return (0);
3454 case MTREW:
3455 #if IDETAPE_DEBUG
3456 printk ("Handling MTREW command\n");
3457 #endif
3458 return (idetape_rewind_tape (drive));
3459 case MTNOP:
3460 #if IDETAPE_DEBUG
3461 printk ("Handling MTNOP command\n");
3462 #endif
3463 idetape_create_write_filemark_cmd (&pc,0);
3464 return (idetape_queue_pc_tail (drive,&pc));
3465 case MTEOM:
3466 #if IDETAPE_DEBUG
3467 printk ("Handling MTEOM command\n");
3468 #endif
3469
3470 idetape_create_space_cmd (&pc,0,IDETAPE_SPACE_TO_EOD);
3471 return (idetape_queue_pc_tail (drive,&pc));
3472 case MTERASE:
3473 #if IDETAPE_DEBUG
3474 printk ("Handling MTERASE command\n");
3475 #endif
3476 retval=idetape_position_tape (drive,0);
3477 if (retval) return (retval);
3478 idetape_create_erase_cmd (&pc);
3479 return (idetape_queue_pc_tail (drive,&pc));
3480 default:
3481 printk ("ide-tape: MTIO operation %d not supported\n",mt_op);
3482 return (-EIO);
3483 }
3484 }
3485
3486
3487
3488
3489
3490 int idetape_chrdev_open (struct inode *inode, struct file *filp)
3491
3492 {
3493 ide_drive_t *drive;
3494 idetape_tape_t *tape;
3495 unsigned long flags;
3496 unsigned int minor;
3497
3498 save_flags (flags);cli();
3499
3500 #if IDETAPE_DEBUG
3501 printk ("Reached idetape_chrdev_open\n");
3502 #endif
3503
3504
3505 drive=idetape_chrdev.drive;
3506 tape=&(drive->tape);
3507 minor=MINOR (inode->i_rdev);
3508
3509 if (minor!=0 && minor!=128) {
3510 restore_flags (flags);
3511 return (-ENXIO);
3512 }
3513
3514 if (tape->busy) {
3515 restore_flags (flags);
3516 return (-EBUSY);
3517 }
3518
3519 tape->busy=1;
3520 restore_flags (flags);
3521
3522 if (!tape->block_address_valid) {
3523 if (idetape_rewind_tape (drive)) {
3524 printk ("ide-tape: Rewinding tape failed\n");
3525 tape->busy=0;
3526 return (-EIO);
3527 }
3528 }
3529
3530 tape->last_dt_was_write=0;
3531
3532 return (0);
3533 }
3534
3535
3536
3537
3538
3539 void idetape_chrdev_release (struct inode *inode, struct file *filp)
3540
3541 {
3542 ide_drive_t *drive;
3543 idetape_tape_t *tape;
3544
3545 unsigned int minor;
3546 idetape_packet_command_t pc;
3547 unsigned long flags;
3548
3549 #if IDETAPE_DEBUG
3550 printk ("Reached idetape_chrdev_release\n");
3551 #endif
3552
3553 drive=idetape_chrdev.drive;
3554 tape=&(drive->tape);
3555 minor=MINOR (inode->i_rdev);
3556
3557 idetape_empty_pipeline (drive);
3558
3559 if (tape->last_dt_was_write) {
3560 idetape_create_write_filemark_cmd (&pc,1);
3561 if (idetape_queue_pc_tail (drive,&pc)) {
3562 printk ("ide-tape: Couldn't write a filemark\n");
3563
3564 }
3565 }
3566 else {
3567 idetape_create_write_filemark_cmd (&pc,0);
3568 if (idetape_queue_pc_tail (drive,&pc)) {
3569 printk ("ide-tape: Couldn't flush buffers\n");
3570
3571 }
3572 }
3573
3574 if (minor < 128) {
3575 if (idetape_rewind_tape (drive)) {
3576 printk ("ide-tape: Rewinding tape failed\n");
3577
3578 }
3579 }
3580
3581 save_flags (flags);cli();
3582 tape->busy=0;
3583 restore_flags (flags);
3584
3585 return;
3586 }
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598 int idetape_position_tape (ide_drive_t *drive,unsigned long block)
3599
3600 {
3601 int retval;
3602 idetape_packet_command_t pc;
3603
3604 idetape_create_locate_cmd (&pc,block,0);
3605 retval=idetape_queue_pc_tail (drive,&pc);
3606 if (retval!=0) return (retval);
3607
3608 idetape_create_read_position_cmd (&pc);
3609 pc.buffer=pc.temp_buffer;
3610 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
3611 pc.current_position=pc.temp_buffer;
3612 return (idetape_queue_pc_tail (drive,&pc));
3613 }
3614
3615
3616
3617
3618
3619
3620
3621 int idetape_rewind_tape (ide_drive_t *drive)
3622
3623 {
3624 int retval;
3625 idetape_packet_command_t pc;
3626 #if IDETAPE_DEBUG
3627 printk ("Reached idetape_rewind_tape\n");
3628 #endif
3629
3630 idetape_create_write_filemark_cmd (&pc,0);
3631 retval=idetape_queue_pc_tail (drive,&pc);
3632 if (retval) return (retval);
3633
3634 idetape_create_rewind_cmd (&pc);
3635 retval=idetape_queue_pc_tail (drive,&pc);
3636 if (retval) return (retval);
3637
3638 idetape_create_read_position_cmd (&pc);
3639 pc.buffer=pc.temp_buffer;
3640 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
3641 pc.current_position=pc.temp_buffer;
3642 return (idetape_queue_pc_tail (drive,&pc));
3643 }
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663 idetape_pipeline_stage_t *idetape_kmalloc_stage (ide_drive_t *drive)
3664
3665 {
3666 idetape_tape_t *tape=&(drive->tape);
3667 idetape_pipeline_stage_t *new_stage;
3668 idetape_buffer_head_t *prev_bh,*bh;
3669 int buffers_num,i;
3670
3671 #if IDETAPE_DEBUG
3672 printk ("Reached idetape_kmalloc_stage\n");
3673 #endif
3674
3675 if (tape->current_number_of_stages==tape->max_number_of_stages) {
3676 tape->pipeline_was_full_once=1;
3677 return (NULL);
3678 }
3679
3680 new_stage=(idetape_pipeline_stage_t *) kmalloc (sizeof (idetape_pipeline_stage_t),GFP_KERNEL);
3681 if (new_stage==NULL)
3682 return (NULL);
3683
3684 new_stage->next=new_stage->prev=NULL;
3685
3686 buffers_num=tape->data_buffer_size / IDETAPE_ALLOCATION_BLOCK;
3687 if (tape->data_buffer_size % IDETAPE_ALLOCATION_BLOCK)
3688 buffers_num++;
3689
3690 prev_bh=new_stage->bh=(idetape_buffer_head_t *) kmalloc (sizeof (idetape_buffer_head_t),GFP_KERNEL);
3691 if (new_stage->bh==NULL) {
3692 idetape_kfree_stage (new_stage);
3693 return (NULL);
3694 }
3695 new_stage->bh->next=NULL;
3696
3697 new_stage->bh->data=kmalloc (IDETAPE_ALLOCATION_BLOCK,GFP_KERNEL);
3698 if (new_stage->bh->data==NULL) {
3699 idetape_kfree_stage (new_stage);
3700 return (NULL);
3701 }
3702
3703 for (i=1;i<buffers_num;i++) {
3704 bh=(idetape_buffer_head_t *) kmalloc (sizeof (idetape_buffer_head_t),GFP_KERNEL);
3705 if (bh==NULL) {
3706 idetape_kfree_stage (new_stage);
3707 return (NULL);
3708 }
3709 bh->next=NULL;
3710 prev_bh->next=bh;
3711 bh->data=kmalloc (IDETAPE_ALLOCATION_BLOCK,GFP_KERNEL);
3712 if (bh->data == NULL) {
3713 idetape_kfree_stage (new_stage);
3714 return (NULL);
3715 }
3716 prev_bh=bh;
3717 }
3718 return (new_stage);
3719 }
3720
3721
3722
3723
3724
3725
3726 void idetape_kfree_stage (idetape_pipeline_stage_t *stage)
3727
3728 {
3729 idetape_buffer_head_t *prev_bh,*bh;
3730
3731 if (stage == NULL)
3732 return;
3733
3734 #if IDETAPE_DEBUG
3735 printk ("Reached idetape_kfree_stage\n");
3736 #endif
3737
3738 bh=stage->bh;
3739
3740 while (bh != NULL) {
3741 prev_bh=bh;
3742 if (bh->data != NULL)
3743 kfree (bh->data);
3744 bh=bh->next;
3745 kfree (prev_bh);
3746 }
3747
3748 kfree (stage);
3749 return;
3750 }
3751
3752
3753
3754
3755
3756
3757 void idetape_copy_buffer_from_stage (idetape_pipeline_stage_t *stage,char *buffer)
3758
3759 {
3760 idetape_buffer_head_t *bh;
3761 char *ptr;
3762
3763 #if IDETAPE_DEBUG
3764 printk ("Reached idetape_copy_buffer_from_stage\n");
3765 #endif
3766
3767 ptr=buffer;
3768 bh=stage->bh;
3769
3770 while (bh != NULL) {
3771 memcpy (ptr,bh->data,IDETAPE_ALLOCATION_BLOCK);
3772 bh=bh->next;
3773 ptr=ptr+IDETAPE_ALLOCATION_BLOCK;
3774 }
3775 return;
3776 }
3777
3778
3779
3780
3781
3782
3783 void idetape_copy_buffer_to_stage (idetape_pipeline_stage_t *stage,char *buffer)
3784
3785 {
3786 idetape_buffer_head_t *bh;
3787 char *ptr;
3788
3789 #if IDETAPE_DEBUG
3790 printk ("Reached idetape_copy_buffer_to_stage\n");
3791 #endif
3792
3793 ptr=buffer;
3794 bh=stage->bh;
3795
3796 while (bh != NULL) {
3797 memcpy (bh->data,ptr,IDETAPE_ALLOCATION_BLOCK);
3798 bh=bh->next;
3799 ptr=ptr+IDETAPE_ALLOCATION_BLOCK;
3800 }
3801 return;
3802 }
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812 void idetape_increase_max_pipeline_stages (ide_drive_t *drive)
3813
3814 {
3815 idetape_tape_t *tape=&(drive->tape);
3816
3817 #if IDETAPE_DEBUG
3818 printk ("Reached idetape_increase_max_pipeline_stages\n");
3819 #endif
3820
3821 if (!tape->pipeline_was_full_once)
3822 return;
3823
3824 tape->max_number_of_stages+=IDETAPE_INCREASE_STAGES_RATE*
3825 (IDETAPE_MAX_PIPELINE_STAGES-IDETAPE_MIN_PIPELINE_STAGES);
3826
3827 if (tape->max_number_of_stages >= IDETAPE_MAX_PIPELINE_STAGES)
3828 tape->max_number_of_stages = IDETAPE_MAX_PIPELINE_STAGES;
3829
3830 #if IDETAPE_DEBUG
3831 printk ("Maximum number of stages: %d\n",tape->max_number_of_stages);
3832 #endif
3833
3834 return;
3835 }
3836
3837
3838
3839
3840
3841 void idetape_add_stage_tail (ide_drive_t *drive,idetape_pipeline_stage_t *stage)
3842
3843 {
3844 idetape_tape_t *tape=&(drive->tape);
3845 unsigned long flags;
3846
3847 #if IDETAPE_DEBUG
3848 printk ("Reached idetape_add_stage_tail\n");
3849 #endif
3850
3851 stage->next=NULL;
3852
3853 #if IDETAPE_DEBUG
3854 printk ("Adding to the tail of the pipeline\n");
3855 #endif
3856
3857
3858
3859
3860
3861
3862
3863 while (tape->pipeline_locked);
3864
3865 save_flags (flags);cli ();
3866 stage->prev=tape->last_stage;
3867 if (tape->first_stage != NULL)
3868 tape->last_stage->next=stage;
3869 else
3870 tape->first_stage=stage;
3871 tape->last_stage=stage;
3872 tape->current_number_of_stages++;
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883 if (tape->active_data_request == NULL &&
3884 tape->current_number_of_stages >= 0.75*tape->max_number_of_stages) {
3885
3886 restore_flags (flags);
3887 idetape_insert_pipeline_into_queue (drive);
3888 }
3889 else
3890 restore_flags (flags);
3891 }
3892
3893
3894
3895
3896
3897
3898 void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
3899
3900 {
3901 idetape_tape_t *tape=&(drive->tape);
3902
3903 if (tape->first_stage == NULL)
3904 return;
3905
3906 if (tape->active_data_request == NULL) {
3907 idetape_active_next_stage (drive);
3908 #if IDETAPE_DEBUG
3909 printk ("Using ide_end\n");
3910 #endif
3911 (void) (ide_do_drive_cmd (drive,tape->active_data_request,ide_end));
3912 return;
3913 }
3914 }
3915
3916
3917
3918
3919
3920
3921
3922 void idetape_active_next_stage (ide_drive_t *drive)
3923
3924 {
3925 idetape_tape_t *tape=&(drive->tape);
3926 idetape_pipeline_stage_t *stage;
3927 struct request *rq;
3928 unsigned long flags;
3929
3930 #if IDETAPE_DEBUG
3931 printk ("Reached idetape_active_next_stage\n");
3932 if (tape->first_stage == NULL) {
3933 printk ("ide-tape: ide-tape.c bug - tape->first_stage is NULL\n");
3934 return;
3935 }
3936 #endif
3937
3938 stage=tape->first_stage;
3939
3940 idetape_copy_buffer_from_stage (stage,tape->data_buffer);
3941 rq=idetape_next_rq_storage (drive);
3942 *rq=stage->rq;
3943 rq->buffer=tape->data_buffer;
3944
3945 save_flags (flags);cli ();
3946 tape->first_stage=stage->next;
3947 if (tape->first_stage == NULL)
3948 tape->last_stage=NULL;
3949 tape->current_number_of_stages--;
3950 tape->active_data_request=rq;
3951 restore_flags (flags);
3952
3953 idetape_kfree_stage (stage);
3954 }