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