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