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 ("Manufacturer\'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 supported 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 run_task_queue(&tq_disk);
3158 rq->sem=&sem;
3159 down (&sem);
3160 }
3161
3162
3163
3164
3165
3166
3167 int idetape_queue_rw_tail (ide_drive_t *drive,int cmd,int blocks,char *buffer)
3168
3169 {
3170 idetape_tape_t *tape = &(drive->tape);
3171 struct request rq;
3172
3173 #if IDETAPE_DEBUG_LOG
3174 printk ("idetape_queue_rw_tail: cmd=%d\n",cmd);
3175 #endif
3176 #if IDETAPE_DEBUG_BUGS
3177 if (tape->active_data_request != NULL) {
3178 printk ("ide-tape: bug: the pipeline is active in idetape_queue_rw_tail\n");
3179 return (0);
3180 }
3181 #endif
3182
3183 ide_init_drive_cmd (&rq);
3184 rq.buffer = buffer;
3185 rq.cmd = cmd;
3186 rq.sector = tape->block_address;
3187 rq.nr_sectors = rq.current_nr_sectors = blocks;
3188 (void) ide_do_drive_cmd (drive, &rq, ide_wait);
3189
3190 return (tape->tape_block_size*(blocks-rq.current_nr_sectors));
3191 }
3192
3193
3194
3195
3196
3197
3198 int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks,char *buffer)
3199
3200 {
3201 idetape_tape_t *tape = &(drive->tape);
3202 idetape_pipeline_stage_t *new_stage;
3203 unsigned long flags;
3204 struct request rq,*rq_ptr;
3205 int bytes_read;
3206
3207 #if IDETAPE_DEBUG_LOG
3208 printk ("Reached idetape_add_chrdev_read_request\n");
3209 #endif
3210
3211 ide_init_drive_cmd (&rq);
3212 rq.cmd = IDETAPE_READ_REQUEST;
3213 rq.sector = tape->block_address;
3214 rq.nr_sectors = rq.current_nr_sectors = blocks;
3215
3216 if (tape->current_number_of_stages < 0.5*tape->max_number_of_stages) {
3217 new_stage=idetape_kmalloc_stage (drive);
3218 while (new_stage != NULL) {
3219 new_stage->rq=rq;
3220 save_flags (flags);cli ();
3221 idetape_add_stage_tail (drive,new_stage);
3222 restore_flags (flags);
3223 new_stage=idetape_kmalloc_stage (drive);
3224 }
3225 if (tape->active_data_request == NULL)
3226 idetape_insert_pipeline_into_queue (drive);
3227 }
3228
3229 if (tape->first_stage == NULL) {
3230
3231
3232
3233
3234
3235
3236 return (idetape_queue_rw_tail (drive,IDETAPE_READ_REQUEST,blocks,buffer));
3237 }
3238
3239 save_flags (flags);cli ();
3240 if (tape->active_data_request == &(tape->first_stage->rq))
3241 idetape_wait_for_request (tape->active_data_request);
3242 restore_flags (flags);
3243
3244 rq_ptr=&(tape->first_stage->rq);
3245 bytes_read=tape->tape_block_size*(rq_ptr->nr_sectors-rq_ptr->current_nr_sectors);
3246 rq_ptr->nr_sectors=rq_ptr->current_nr_sectors=0;
3247 idetape_copy_buffer_from_stage (tape->first_stage,buffer);
3248 if (rq_ptr->errors != IDETAPE_RQ_ERROR_FILEMARK)
3249 idetape_remove_stage_head (drive);
3250 #if IDETAPE_DEBUG_BUGS
3251 if (bytes_read > blocks*tape->tape_block_size) {
3252 printk ("ide-tape: bug: trying to return more bytes than requested\n");
3253 bytes_read=blocks*tape->tape_block_size;
3254 }
3255 #endif
3256 return (bytes_read);
3257 }
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271 int idetape_add_chrdev_write_request (ide_drive_t *drive,int blocks,char *buffer)
3272
3273 {
3274 idetape_tape_t *tape = &(drive->tape);
3275 idetape_pipeline_stage_t *new_stage;
3276 unsigned long flags;
3277 struct request *rq;
3278
3279 #if IDETAPE_DEBUG_LOG
3280 printk ("Reached idetape_add_chrdev_write_request\n");
3281 #endif
3282
3283
3284 new_stage=idetape_kmalloc_stage (drive);
3285
3286
3287
3288
3289
3290
3291
3292
3293 while (new_stage == NULL) {
3294 save_flags (flags);cli ();
3295 if (tape->active_data_request != NULL) {
3296 idetape_wait_for_request (tape->active_data_request);
3297 restore_flags (flags);
3298 new_stage=idetape_kmalloc_stage (drive);
3299 }
3300 else {
3301
3302
3303
3304
3305
3306 restore_flags (flags);
3307 return (idetape_queue_rw_tail (drive,IDETAPE_WRITE_REQUEST,blocks,buffer));
3308 }
3309 }
3310
3311 rq=&(new_stage->rq);
3312
3313 ide_init_drive_cmd (rq);
3314 rq->cmd = IDETAPE_WRITE_REQUEST;
3315 rq->sector = tape->block_address;
3316 rq->nr_sectors = blocks;
3317 rq->current_nr_sectors = blocks;
3318
3319 idetape_copy_buffer_to_stage (new_stage,buffer);
3320
3321 save_flags (flags);cli ();
3322 idetape_add_stage_tail (drive,new_stage);
3323 restore_flags (flags);
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334 if (tape->active_data_request == NULL && tape->current_number_of_stages >= 0.75*tape->max_number_of_stages)
3335 idetape_insert_pipeline_into_queue (drive);
3336
3337 if (tape->error_in_pipeline_stage) {
3338 tape->error_in_pipeline_stage=0;
3339 return (-EIO);
3340 }
3341
3342 return (blocks);
3343 }
3344
3345 void idetape_discard_read_pipeline (ide_drive_t *drive)
3346
3347 {
3348 idetape_tape_t *tape = &(drive->tape);
3349 unsigned long flags;
3350
3351 #if IDETAPE_DEBUG_BUGS
3352 if (tape->chrdev_direction != idetape_direction_read) {
3353 printk ("ide-tape: bug: Trying to discard read pipeline, but we are not reading.\n");
3354 return;
3355 }
3356 #endif
3357
3358 tape->merge_buffer_size=tape->merge_buffer_offset=0;
3359 tape->chrdev_direction=idetape_direction_none;
3360
3361 if (tape->first_stage == NULL)
3362 return;
3363
3364 save_flags (flags);cli ();
3365 tape->next_stage=NULL;
3366 if (tape->active_data_request != NULL)
3367 idetape_wait_for_request (tape->active_data_request);
3368 restore_flags (flags);
3369
3370 while (tape->first_stage != NULL)
3371 idetape_remove_stage_head (drive);
3372
3373 #if IDETAPE_PIPELINE
3374 tape->max_number_of_stages=IDETAPE_MIN_PIPELINE_STAGES;
3375 #else
3376 tape->max_number_of_stages=0;
3377 #endif
3378 }
3379
3380
3381
3382
3383
3384
3385 void idetape_wait_for_pipeline (ide_drive_t *drive)
3386
3387 {
3388 idetape_tape_t *tape = &(drive->tape);
3389 unsigned long flags;
3390
3391 if (tape->active_data_request == NULL)
3392 idetape_insert_pipeline_into_queue (drive);
3393
3394 save_flags (flags);cli ();
3395 if (tape->active_data_request == NULL) {
3396 restore_flags (flags);
3397 return;
3398 }
3399
3400 if (tape->last_stage != NULL)
3401 idetape_wait_for_request (&(tape->last_stage->rq));
3402
3403 else if (tape->active_data_request != NULL)
3404 idetape_wait_for_request (tape->active_data_request);
3405 restore_flags (flags);
3406 }
3407
3408 void idetape_empty_write_pipeline (ide_drive_t *drive)
3409
3410 {
3411 idetape_tape_t *tape = &(drive->tape);
3412 int blocks;
3413
3414 #if IDETAPE_DEBUG_BUGS
3415 if (tape->chrdev_direction != idetape_direction_write) {
3416 printk ("ide-tape: bug: Trying to empty write pipeline, but we are not writing.\n");
3417 return;
3418 }
3419 if (tape->merge_buffer_size > tape->data_buffer_size) {
3420 printk ("ide-tape: bug: merge_buffer too big\n");
3421 tape->merge_buffer_size = tape->data_buffer_size;
3422 }
3423 #endif
3424
3425 if (tape->merge_buffer_size) {
3426 blocks=tape->merge_buffer_size/tape->tape_block_size;
3427 if (tape->merge_buffer_size % tape->tape_block_size) {
3428 blocks++;
3429 memset (tape->merge_buffer+tape->merge_buffer_size,0,tape->data_buffer_size-tape->merge_buffer_size);
3430 }
3431 (void) idetape_add_chrdev_write_request (drive,blocks,tape->merge_buffer);
3432 tape->merge_buffer_size=0;
3433 }
3434
3435 idetape_wait_for_pipeline (drive);
3436
3437 tape->error_in_pipeline_stage=0;
3438 tape->chrdev_direction=idetape_direction_none;
3439
3440
3441
3442
3443
3444
3445
3446
3447 #if IDETAPE_PIPELINE
3448 tape->max_number_of_stages=IDETAPE_MIN_PIPELINE_STAGES;
3449 #else
3450 tape->max_number_of_stages=0;
3451 #endif
3452 #if IDETAPE_DEBUG_BUGS
3453 if (tape->first_stage != NULL || tape->next_stage != NULL || tape->last_stage != NULL || tape->current_number_of_stages != 0) {
3454 printk ("ide-tape: ide-tape pipeline bug\n");
3455 }
3456 #endif
3457 }
3458
3459
3460
3461
3462
3463
3464 void idetape_zero_packet_command (idetape_packet_command_t *pc)
3465
3466 {
3467 int i;
3468
3469 for (i=0;i<12;i++)
3470 pc->c[i]=0;
3471 pc->retries=0;
3472 pc->abort=0;
3473 pc->dma_recommended=0;
3474 pc->dma_error=0;
3475 }
3476
3477
3478
3479
3480
3481
3482 unsigned short idetape_swap_short (unsigned short temp)
3483
3484 {
3485 union convert {
3486 unsigned all :16;
3487 struct {
3488 unsigned b1 :8;
3489 unsigned b2 :8;
3490 } b;
3491 } original,converted;
3492
3493 original.all=temp;
3494 converted.b.b1=original.b.b2;
3495 converted.b.b2=original.b.b1;
3496 return (converted.all);
3497 }
3498
3499
3500
3501
3502
3503 unsigned long idetape_swap_long (unsigned long temp)
3504
3505 {
3506 union convert {
3507 unsigned all :32;
3508 struct {
3509 unsigned b1 :8;
3510 unsigned b2 :8;
3511 unsigned b3 :8;
3512 unsigned b4 :8;
3513 } b;
3514 } original,converted;
3515
3516 original.all=temp;
3517 converted.b.b1=original.b.b4;
3518 converted.b.b2=original.b.b3;
3519 converted.b.b3=original.b.b2;
3520 converted.b.b4=original.b.b1;
3521 return (converted.all);
3522 }
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532 idetape_packet_command_t *idetape_next_pc_storage (ide_drive_t *drive)
3533
3534 {
3535 idetape_tape_t *tape;
3536
3537 tape=&(drive->tape);
3538 #if IDETAPE_DEBUG_LOG
3539 printk ("ide-tape: pc_stack_index=%d\n",tape->pc_stack_index);
3540 #endif
3541 if (tape->pc_stack_index==IDETAPE_PC_STACK)
3542 tape->pc_stack_index=0;
3543 return (&(tape->pc_stack [tape->pc_stack_index++]));
3544 }
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559 struct request *idetape_next_rq_storage (ide_drive_t *drive)
3560
3561 {
3562 idetape_tape_t *tape;
3563
3564 tape=&(drive->tape);
3565
3566 #if IDETAPE_DEBUG_LOG
3567 printk ("ide-tape: rq_stack_index=%d\n",tape->rq_stack_index);
3568 #endif
3569 if (tape->rq_stack_index==IDETAPE_PC_STACK)
3570 tape->rq_stack_index=0;
3571 return (&(tape->rq_stack [tape->rq_stack_index++]));
3572 }
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582 int idetape_blkdev_open (struct inode *inode, struct file *filp, ide_drive_t *drive)
3583
3584 {
3585 idetape_tape_t *tape=&(drive->tape);
3586 unsigned long flags;
3587
3588 save_flags (flags);cli ();
3589
3590 #if IDETAPE_DEBUG_LOG
3591 printk ("Reached idetape_blkdev_open\n");
3592 #endif
3593
3594 if (tape->busy) {
3595 restore_flags (flags);
3596 return (-EBUSY);
3597 }
3598
3599 tape->busy=1;
3600 restore_flags (flags);
3601
3602 return (0);
3603 }
3604
3605 void idetape_blkdev_release (struct inode *inode, struct file *filp, ide_drive_t *drive)
3606
3607 {
3608 idetape_tape_t *tape=&(drive->tape);
3609 unsigned long flags;
3610
3611 #if IDETAPE_DEBUG_LOG
3612 printk ("Reached idetape_blkdev_release\n");
3613 #endif
3614
3615 save_flags (flags);cli ();
3616 tape->busy=0;
3617 restore_flags (flags);
3618
3619 return;
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
3646 int idetape_chrdev_read (struct inode *inode, struct file *file, char *buf, int count)
3647
3648 {
3649 ide_drive_t *drive=idetape_chrdev.drive;
3650 idetape_tape_t *tape=&(drive->tape);
3651 char *buf_ptr=buf;
3652 int bytes_read,temp,actually_read=0;
3653
3654 #if IDETAPE_DEBUG_LOG
3655 printk ("Reached idetape_chrdev_read\n");
3656 #endif
3657
3658 if (tape->chrdev_direction != idetape_direction_read) {
3659 if (tape->chrdev_direction == idetape_direction_write) {
3660 idetape_empty_write_pipeline (drive);
3661 idetape_flush_tape_buffers (drive);
3662 }
3663
3664
3665
3666
3667
3668
3669
3670 bytes_read=idetape_queue_rw_tail (drive,IDETAPE_READ_REQUEST,0,tape->merge_buffer);
3671 if (bytes_read < 0)
3672 return (bytes_read);
3673
3674 tape->chrdev_direction=idetape_direction_read;
3675 }
3676
3677 if (count==0)
3678 return (0);
3679
3680 if (tape->merge_buffer_size) {
3681 #if IDETAPE_DEBUG_BUGS
3682 if (tape->merge_buffer_offset+tape->merge_buffer_size > tape->data_buffer_size) {
3683 printk ("ide-tape: bug: merge buffer too big\n");
3684 tape->merge_buffer_offset=0;tape->merge_buffer_size=tape->data_buffer_size-1;
3685 }
3686 #endif
3687 actually_read=IDETAPE_MIN (tape->merge_buffer_size,count);
3688 memcpy_tofs (buf_ptr,tape->merge_buffer+tape->merge_buffer_offset,actually_read);
3689 buf_ptr+=actually_read;tape->merge_buffer_size-=actually_read;
3690 count-=actually_read;tape->merge_buffer_offset+=actually_read;
3691 }
3692
3693 while (count >= tape->data_buffer_size) {
3694 bytes_read=idetape_add_chrdev_read_request (drive,tape->capabilities.ctl,tape->merge_buffer);
3695 if (bytes_read <= 0)
3696 return (actually_read);
3697 memcpy_tofs (buf_ptr,tape->merge_buffer,bytes_read);
3698 buf_ptr+=bytes_read;count-=bytes_read;actually_read+=bytes_read;
3699 }
3700
3701 if (count) {
3702 bytes_read=idetape_add_chrdev_read_request (drive,tape->capabilities.ctl,tape->merge_buffer);
3703 if (bytes_read <= 0)
3704 return (actually_read);
3705 temp=IDETAPE_MIN (count,bytes_read);
3706 memcpy_tofs (buf_ptr,tape->merge_buffer,temp);
3707 actually_read+=temp;
3708 tape->merge_buffer_offset=temp;
3709 tape->merge_buffer_size=bytes_read-temp;
3710 }
3711 return (actually_read);
3712 }
3713
3714 int idetape_chrdev_write (struct inode *inode, struct file *file, const char *buf, int count)
3715
3716 {
3717 ide_drive_t *drive=idetape_chrdev.drive;
3718 idetape_tape_t *tape=&(drive->tape);
3719 const char *buf_ptr=buf;
3720 int retval,actually_written=0;
3721
3722 #if IDETAPE_DEBUG_LOG
3723 printk ("Reached idetape_chrdev_write\n");
3724 #endif
3725
3726 if (tape->chrdev_direction != idetape_direction_write) {
3727 if (tape->chrdev_direction == idetape_direction_read)
3728 idetape_discard_read_pipeline (drive);
3729
3730
3731
3732
3733
3734
3735
3736 retval=idetape_queue_rw_tail (drive,IDETAPE_WRITE_REQUEST,0,tape->merge_buffer);
3737 if (retval < 0)
3738 return (retval);
3739
3740 tape->chrdev_direction=idetape_direction_write;
3741 }
3742
3743 if (count==0)
3744 return (0);
3745
3746 if (tape->merge_buffer_size) {
3747 #if IDETAPE_DEBUG_BUGS
3748 if (tape->merge_buffer_size >= tape->data_buffer_size) {
3749 printk ("ide-tape: bug: merge buffer too big\n");
3750 tape->merge_buffer_size=0;
3751 }
3752 #endif
3753
3754 actually_written=IDETAPE_MIN (tape->data_buffer_size-tape->merge_buffer_size,count);
3755 memcpy_fromfs (tape->merge_buffer+tape->merge_buffer_size,buf_ptr,actually_written);
3756 buf_ptr+=actually_written;tape->merge_buffer_size+=actually_written;count-=actually_written;
3757
3758 if (tape->merge_buffer_size == tape->data_buffer_size) {
3759 tape->merge_buffer_size=0;
3760 retval=idetape_add_chrdev_write_request (drive,tape->capabilities.ctl,tape->merge_buffer);
3761 if (retval <= 0)
3762 return (retval);
3763 }
3764 }
3765
3766 while (count >= tape->data_buffer_size) {
3767 memcpy_fromfs (tape->merge_buffer,buf_ptr,tape->data_buffer_size);
3768 buf_ptr+=tape->data_buffer_size;count-=tape->data_buffer_size;
3769 retval=idetape_add_chrdev_write_request (drive,tape->capabilities.ctl,tape->merge_buffer);
3770 actually_written+=tape->data_buffer_size;
3771 if (retval <= 0)
3772 return (retval);
3773 }
3774
3775 if (count) {
3776 actually_written+=count;
3777 memcpy_fromfs (tape->merge_buffer,buf_ptr,count);
3778 tape->merge_buffer_size+=count;
3779 }
3780 return (actually_written);
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
3814 int idetape_chrdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
3815
3816 {
3817 ide_drive_t *drive=idetape_chrdev.drive;
3818 idetape_tape_t *tape=&(drive->tape);
3819 idetape_packet_command_t pc;
3820 struct mtop mtop;
3821 struct mtget mtget;
3822 struct mtpos mtpos;
3823 int retval;
3824
3825 #if IDETAPE_DEBUG_LOG
3826 printk ("Reached idetape_chrdev_ioctl, cmd=%u\n",cmd);
3827 #endif
3828
3829 if (tape->chrdev_direction == idetape_direction_write) {
3830 idetape_empty_write_pipeline (drive);
3831 idetape_flush_tape_buffers (drive);
3832 }
3833
3834 if (tape->chrdev_direction == idetape_direction_read && cmd != MTIOCTOP)
3835 idetape_discard_read_pipeline (drive);
3836
3837 pc.buffer=pc.temp_buffer;
3838 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
3839 pc.current_position=pc.temp_buffer;
3840
3841 switch (cmd) {
3842 case MTIOCTOP:
3843 retval=verify_area (VERIFY_READ,(char *) arg,sizeof (struct mtop));
3844 if (retval) return (retval);
3845 memcpy_fromfs ((char *) &mtop, (char *) arg, sizeof (struct mtop));
3846 return (idetape_mtioctop (drive,mtop.mt_op,mtop.mt_count));
3847 case MTIOCGET:
3848 mtget.mt_dsreg=(tape->data_buffer_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;
3849 retval=verify_area (VERIFY_WRITE,(char *) arg,sizeof (struct mtget));
3850 if (retval) return (retval);
3851 memcpy_tofs ((char *) arg,(char *) &mtget, sizeof (struct mtget));
3852 return (0);
3853 case MTIOCPOS:
3854 idetape_create_read_position_cmd (&pc);
3855 retval=idetape_queue_pc_tail (drive,&pc);
3856 if (retval) return (retval);
3857 mtpos.mt_blkno=tape->block_address;
3858 retval=verify_area (VERIFY_WRITE,(char *) arg,sizeof (struct mtpos));
3859 if (retval) return (retval);
3860 memcpy_tofs ((char *) arg,(char *) &mtpos, sizeof (struct mtpos));
3861 return (0);
3862 default:
3863 return (idetape_blkdev_ioctl (drive,inode,file,cmd,arg));
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
3920 int idetape_mtioctop (ide_drive_t *drive,short mt_op,int mt_count)
3921
3922 {
3923 idetape_tape_t *tape=&(drive->tape);
3924 idetape_packet_command_t pc;
3925 int i,retval;
3926
3927 pc.buffer=pc.temp_buffer;
3928 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
3929 pc.current_position=pc.temp_buffer;
3930
3931 #if IDETAPE_DEBUG_LOG
3932 printk ("Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n",mt_op,mt_count);
3933 #endif
3934
3935
3936
3937
3938
3939 switch (mt_op) {
3940 case MTFSF:
3941 case MTFSFM:
3942 case MTBSF:
3943 case MTBSFM:
3944 if (!mt_count)
3945 return (0);
3946 return (idetape_space_over_filemarks (drive,mt_op,mt_count));
3947 default:
3948 break;
3949 }
3950
3951
3952
3953
3954
3955 if (tape->chrdev_direction == idetape_direction_read)
3956 idetape_discard_read_pipeline (drive);
3957
3958 switch (mt_op) {
3959 case MTWEOF:
3960 for (i=0;i<mt_count;i++) {
3961 idetape_create_write_filemark_cmd (&pc,1);
3962 retval=idetape_queue_pc_tail (drive,&pc);
3963 if (retval) return (retval);
3964 }
3965 return (0);
3966 case MTREW:
3967 return (idetape_rewind_tape (drive));
3968 case MTOFFL:
3969 idetape_create_load_unload_cmd (&pc,!IDETAPE_LU_LOAD_MASK);
3970 return (idetape_queue_pc_tail (drive,&pc));
3971 case MTNOP:
3972 return (idetape_flush_tape_buffers (drive));
3973 case MTRETEN:
3974 idetape_create_load_unload_cmd (&pc,IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
3975 return (idetape_queue_pc_tail (drive,&pc));
3976 case MTEOM:
3977 idetape_create_space_cmd (&pc,0,IDETAPE_SPACE_TO_EOD);
3978 return (idetape_queue_pc_tail (drive,&pc));
3979 case MTERASE:
3980 retval=idetape_rewind_tape (drive);
3981 if (retval) return (retval);
3982 idetape_create_erase_cmd (&pc);
3983 return (idetape_queue_pc_tail (drive,&pc));
3984 case MTSEEK:
3985 return (idetape_position_tape (drive,mt_count));
3986 default:
3987 printk ("ide-tape: MTIO operation %d not supported\n",mt_op);
3988 return (-EIO);
3989 }
3990 }
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002 int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_count)
4003
4004 {
4005 idetape_tape_t *tape=&(drive->tape);
4006 idetape_packet_command_t pc;
4007 unsigned long flags;
4008 int retval,count=0,errors;
4009
4010 if (tape->chrdev_direction == idetape_direction_read) {
4011
4012
4013
4014
4015
4016
4017 tape->merge_buffer_size=tape->merge_buffer_offset=0;
4018 while (tape->first_stage != NULL) {
4019
4020
4021
4022
4023
4024
4025 save_flags (flags);cli ();
4026 if (tape->active_data_request == &(tape->first_stage->rq))
4027 idetape_wait_for_request (tape->active_data_request);
4028 restore_flags (flags);
4029
4030 errors=tape->first_stage->rq.errors;
4031 if (errors == IDETAPE_RQ_ERROR_FILEMARK)
4032 count++;
4033
4034 if (count == mt_count) {
4035 switch (mt_op) {
4036 case MTFSF:
4037 idetape_remove_stage_head (drive);
4038 case MTFSFM:
4039 return (0);
4040 }
4041 }
4042 idetape_remove_stage_head (drive);
4043 }
4044 idetape_discard_read_pipeline (drive);
4045 }
4046
4047
4048
4049
4050
4051
4052 pc.buffer=pc.temp_buffer;
4053 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
4054 pc.current_position=pc.temp_buffer;
4055
4056 switch (mt_op) {
4057 case MTFSF:
4058 idetape_create_space_cmd (&pc,mt_count-count,IDETAPE_SPACE_OVER_FILEMARK);
4059 return (idetape_queue_pc_tail (drive,&pc));
4060 case MTFSFM:
4061 if (!tape->capabilities.sprev)
4062 return (-EIO);
4063 retval=idetape_mtioctop (drive,MTFSF,mt_count-count);
4064 if (retval) return (retval);
4065 return (idetape_mtioctop (drive,MTBSF,1));
4066 case MTBSF:
4067 if (!tape->capabilities.sprev)
4068 return (-EIO);
4069 idetape_create_space_cmd (&pc,-(mt_count+count),IDETAPE_SPACE_OVER_FILEMARK);
4070 return (idetape_queue_pc_tail (drive,&pc));
4071 case MTBSFM:
4072 if (!tape->capabilities.sprev)
4073 return (-EIO);
4074 retval=idetape_mtioctop (drive,MTBSF,mt_count+count);
4075 if (retval) return (retval);
4076 return (idetape_mtioctop (drive,MTFSF,1));
4077 default:
4078 printk ("ide-tape: MTIO operation %d not supported\n",mt_op);
4079 return (-EIO);
4080 }
4081 }
4082
4083
4084
4085
4086
4087 int idetape_chrdev_open (struct inode *inode, struct file *filp)
4088
4089 {
4090 ide_drive_t *drive=idetape_chrdev.drive;
4091 idetape_tape_t *tape=&(drive->tape);
4092 unsigned long flags;
4093 unsigned int minor=MINOR (inode->i_rdev),allocation_length;
4094
4095 save_flags (flags);cli ();
4096
4097 #if IDETAPE_DEBUG_LOG
4098 printk ("Reached idetape_chrdev_open\n");
4099 #endif
4100
4101 if (minor!=0 && minor!=128) {
4102 restore_flags (flags);
4103 return (-ENXIO);
4104 }
4105
4106 if (tape->busy) {
4107 restore_flags (flags);
4108 return (-EBUSY);
4109 }
4110
4111 tape->busy=1;
4112 restore_flags (flags);
4113
4114 allocation_length=tape->data_buffer_size;
4115 if (tape->data_buffer_size % IDETAPE_ALLOCATION_BLOCK)
4116 allocation_length+=IDETAPE_ALLOCATION_BLOCK;
4117
4118 #if IDETAPE_MINIMIZE_IDLE_MEMORY_USAGE
4119 if (tape->data_buffer == NULL)
4120 tape->data_buffer=kmalloc (allocation_length,GFP_KERNEL);
4121 if (tape->data_buffer == NULL)
4122 goto sorry;
4123 if (tape->merge_buffer == NULL)
4124 tape->merge_buffer=kmalloc (allocation_length,GFP_KERNEL);
4125 if (tape->merge_buffer == NULL) {
4126 kfree (tape->data_buffer);
4127 sorry:
4128 printk ("ide-tape: FATAL - Can not allocate continuous buffer of %d bytes\n",allocation_length);
4129 tape->busy=0;
4130 return (-EIO);
4131 }
4132 #endif
4133
4134 if (!tape->block_address_valid) {
4135 if (idetape_rewind_tape (drive)) {
4136 printk ("ide-tape: Rewinding tape failed\n");
4137 tape->busy=0;
4138 return (-EIO);
4139 }
4140 }
4141
4142 return (0);
4143 }
4144
4145
4146
4147
4148
4149 void idetape_chrdev_release (struct inode *inode, struct file *filp)
4150
4151 {
4152 ide_drive_t *drive=idetape_chrdev.drive;
4153 idetape_tape_t *tape=&(drive->tape);
4154 unsigned int minor=MINOR (inode->i_rdev);
4155 idetape_packet_command_t pc;
4156 unsigned long flags;
4157
4158 #if IDETAPE_DEBUG_LOG
4159 printk ("Reached idetape_chrdev_release\n");
4160 #endif
4161
4162 if (tape->chrdev_direction == idetape_direction_write) {
4163 idetape_empty_write_pipeline (drive);
4164 idetape_create_write_filemark_cmd (&pc,1);
4165 if (idetape_queue_pc_tail (drive,&pc))
4166 printk ("ide-tape: Couldn't write a filemark\n");
4167 }
4168
4169 if (tape->chrdev_direction == idetape_direction_read) {
4170 if (minor < 128)
4171 idetape_discard_read_pipeline (drive);
4172 else
4173 idetape_wait_for_pipeline (drive);
4174 }
4175
4176 if (minor < 128)
4177 if (idetape_rewind_tape (drive))
4178 printk ("ide-tape: Rewinding tape failed\n");
4179
4180 #if IDETAPE_MINIMIZE_IDLE_MEMORY_USAGE
4181 kfree (tape->data_buffer);
4182 tape->data_buffer=NULL;
4183 if (!tape->merge_buffer_size) {
4184 kfree (tape->merge_buffer);
4185 tape->merge_buffer=NULL;
4186 }
4187 #endif
4188
4189 save_flags (flags);cli ();
4190 tape->busy=0;
4191 restore_flags (flags);
4192
4193 return;
4194 }
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206 int idetape_position_tape (ide_drive_t *drive,unsigned long block)
4207
4208 {
4209 int retval;
4210 idetape_packet_command_t pc;
4211
4212 idetape_create_locate_cmd (&pc,block,0);
4213 retval=idetape_queue_pc_tail (drive,&pc);
4214 if (retval!=0) return (retval);
4215
4216 idetape_create_read_position_cmd (&pc);
4217 pc.buffer=pc.temp_buffer;
4218 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
4219 pc.current_position=pc.temp_buffer;
4220 return (idetape_queue_pc_tail (drive,&pc));
4221 }
4222
4223
4224
4225
4226
4227
4228
4229 int idetape_rewind_tape (ide_drive_t *drive)
4230
4231 {
4232 int retval;
4233 idetape_packet_command_t pc;
4234 #if IDETAPE_DEBUG_LOG
4235 printk ("Reached idetape_rewind_tape\n");
4236 #endif
4237
4238 idetape_create_rewind_cmd (&pc);
4239 retval=idetape_queue_pc_tail (drive,&pc);
4240 if (retval) return (retval);
4241
4242 idetape_create_read_position_cmd (&pc);
4243 pc.buffer=pc.temp_buffer;
4244 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
4245 pc.current_position=pc.temp_buffer;
4246 return (idetape_queue_pc_tail (drive,&pc));
4247 }
4248
4249 int idetape_flush_tape_buffers (ide_drive_t *drive)
4250
4251 {
4252 idetape_packet_command_t pc;
4253
4254 idetape_create_write_filemark_cmd (&pc,0);
4255 return (idetape_queue_pc_tail (drive,&pc));
4256 }
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276 idetape_pipeline_stage_t *idetape_kmalloc_stage (ide_drive_t *drive)
4277
4278 {
4279 idetape_tape_t *tape=&(drive->tape);
4280 idetape_pipeline_stage_t *new_stage;
4281 idetape_buffer_head_t *prev_bh,*bh;
4282 int buffers_num,i;
4283
4284 #if IDETAPE_DEBUG_LOG
4285 printk ("Reached idetape_kmalloc_stage\n");
4286 #endif
4287
4288 if (tape->current_number_of_stages>=tape->max_number_of_stages) {
4289 return (NULL);
4290 }
4291
4292 new_stage=(idetape_pipeline_stage_t *) kmalloc (sizeof (idetape_pipeline_stage_t),GFP_KERNEL);
4293 if (new_stage==NULL)
4294 return (NULL);
4295
4296 new_stage->next=new_stage->prev=NULL;
4297
4298 buffers_num=tape->data_buffer_size / IDETAPE_ALLOCATION_BLOCK;
4299 if (tape->data_buffer_size % IDETAPE_ALLOCATION_BLOCK)
4300 buffers_num++;
4301
4302 prev_bh=new_stage->bh=(idetape_buffer_head_t *) kmalloc (sizeof (idetape_buffer_head_t),GFP_KERNEL);
4303 if (new_stage->bh==NULL) {
4304 idetape_kfree_stage (new_stage);
4305 return (NULL);
4306 }
4307 new_stage->bh->next=NULL;
4308
4309 new_stage->bh->data=kmalloc (IDETAPE_ALLOCATION_BLOCK,GFP_KERNEL);
4310 if (new_stage->bh->data==NULL) {
4311 idetape_kfree_stage (new_stage);
4312 return (NULL);
4313 }
4314
4315 for (i=1;i<buffers_num;i++) {
4316 bh=(idetape_buffer_head_t *) kmalloc (sizeof (idetape_buffer_head_t),GFP_KERNEL);
4317 if (bh==NULL) {
4318 idetape_kfree_stage (new_stage);
4319 return (NULL);
4320 }
4321 bh->next=NULL;
4322 prev_bh->next=bh;
4323 bh->data=kmalloc (IDETAPE_ALLOCATION_BLOCK,GFP_KERNEL);
4324 if (bh->data == NULL) {
4325 idetape_kfree_stage (new_stage);
4326 return (NULL);
4327 }
4328 prev_bh=bh;
4329 }
4330 return (new_stage);
4331 }
4332
4333
4334
4335
4336
4337
4338 void idetape_kfree_stage (idetape_pipeline_stage_t *stage)
4339
4340 {
4341 idetape_buffer_head_t *prev_bh,*bh;
4342
4343 if (stage == NULL)
4344 return;
4345
4346 #if IDETAPE_DEBUG_LOG
4347 printk ("Reached idetape_kfree_stage\n");
4348 #endif
4349
4350 bh=stage->bh;
4351
4352 while (bh != NULL) {
4353 prev_bh=bh;
4354 if (bh->data != NULL)
4355 kfree (bh->data);
4356 bh=bh->next;
4357 kfree (prev_bh);
4358 }
4359
4360 kfree (stage);
4361 return;
4362 }
4363
4364
4365
4366
4367
4368
4369 void idetape_copy_buffer_from_stage (idetape_pipeline_stage_t *stage,char *buffer)
4370
4371 {
4372 idetape_buffer_head_t *bh;
4373 char *ptr;
4374
4375 #if IDETAPE_DEBUG_LOG
4376 printk ("Reached idetape_copy_buffer_from_stage\n");
4377 #endif
4378 #if IDETAPE_DEBUG_BUGS
4379 if (buffer == NULL) {
4380 printk ("ide-tape: bug: buffer is null in copy_buffer_from_stage\n");
4381 return;
4382 }
4383 #endif
4384
4385 ptr=buffer;
4386 bh=stage->bh;
4387
4388 while (bh != NULL) {
4389 #if IDETAPE_DEBUG_BUGS
4390 if (bh->data == NULL) {
4391 printk ("ide-tape: bug: bh->data is null\n");
4392 return;
4393 }
4394 #endif
4395 memcpy (ptr,bh->data,IDETAPE_ALLOCATION_BLOCK);
4396 bh=bh->next;
4397 ptr=ptr+IDETAPE_ALLOCATION_BLOCK;
4398 }
4399 return;
4400 }
4401
4402
4403
4404
4405
4406
4407 void idetape_copy_buffer_to_stage (idetape_pipeline_stage_t *stage,char *buffer)
4408
4409 {
4410 idetape_buffer_head_t *bh;
4411 char *ptr;
4412
4413 #if IDETAPE_DEBUG_LOG
4414 printk ("Reached idetape_copy_buffer_to_stage\n");
4415 #endif
4416 #if IDETAPE_DEBUG_BUGS
4417 if (buffer == NULL) {
4418 printk ("ide-tape: bug: buffer is null in copy_buffer_to_stage\n");
4419 return;
4420 }
4421 #endif
4422
4423 ptr=buffer;
4424 bh=stage->bh;
4425
4426 while (bh != NULL) {
4427 #if IDETAPE_DEBUG_BUGS
4428 if (bh->data == NULL) {
4429 printk ("ide-tape: bug: bh->data is null\n");
4430 return;
4431 }
4432 #endif
4433 memcpy (bh->data,ptr,IDETAPE_ALLOCATION_BLOCK);
4434 bh=bh->next;
4435 ptr=ptr+IDETAPE_ALLOCATION_BLOCK;
4436 }
4437 return;
4438 }
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448 void idetape_increase_max_pipeline_stages (ide_drive_t *drive)
4449
4450 {
4451 idetape_tape_t *tape=&(drive->tape);
4452
4453 #if IDETAPE_DEBUG_LOG
4454 printk ("Reached idetape_increase_max_pipeline_stages\n");
4455 #endif
4456
4457 tape->max_number_of_stages+=IDETAPE_INCREASE_STAGES_RATE*
4458 (IDETAPE_MAX_PIPELINE_STAGES-IDETAPE_MIN_PIPELINE_STAGES);
4459
4460 if (tape->max_number_of_stages >= IDETAPE_MAX_PIPELINE_STAGES)
4461 tape->max_number_of_stages = IDETAPE_MAX_PIPELINE_STAGES;
4462
4463 #if IDETAPE_DEBUG_LOG
4464 printk ("Maximum number of stages: %d\n",tape->max_number_of_stages);
4465 #endif
4466
4467 return;
4468 }
4469
4470
4471
4472
4473
4474
4475
4476 void idetape_add_stage_tail (ide_drive_t *drive,idetape_pipeline_stage_t *stage)
4477
4478 {
4479 idetape_tape_t *tape=&(drive->tape);
4480
4481 #if IDETAPE_DEBUG_LOG
4482 printk ("Reached idetape_add_stage_tail\n");
4483 #endif
4484
4485 stage->next=NULL;
4486 stage->prev=tape->last_stage;
4487 if (tape->last_stage != NULL)
4488 tape->last_stage->next=stage;
4489 else
4490 tape->first_stage=tape->next_stage=stage;
4491 tape->last_stage=stage;
4492 if (tape->next_stage == NULL)
4493 tape->next_stage=tape->last_stage;
4494 tape->current_number_of_stages++;
4495 }
4496
4497
4498
4499
4500
4501
4502
4503 void idetape_remove_stage_head (ide_drive_t *drive)
4504
4505 {
4506 idetape_tape_t *tape=&(drive->tape);
4507 idetape_pipeline_stage_t *stage;
4508
4509 #if IDETAPE_DEBUG_LOG
4510 printk ("Reached idetape_remove_stage_head\n");
4511 #endif
4512 #if IDETAPE_DEBUG_BUGS
4513 if (tape->first_stage == NULL) {
4514 printk ("ide-tape: bug: tape->first_stage is NULL\n");
4515 return;
4516 }
4517 if (tape->active_stage == tape->first_stage) {
4518 printk ("ide-tape: bug: Trying to free our active pipeline stage\n");
4519 return;
4520 }
4521 #endif
4522 stage=tape->first_stage;
4523 tape->first_stage=stage->next;
4524 idetape_kfree_stage (stage);
4525 tape->current_number_of_stages--;
4526 if (tape->first_stage == NULL) {
4527 tape->last_stage=NULL;
4528 #if IDETAPE_DEBUG_BUGS
4529 if (tape->next_stage != NULL)
4530 printk ("ide-tape: bug: tape->next_stage != NULL\n");
4531 if (tape->current_number_of_stages)
4532 printk ("ide-tape: bug: current_number_of_stages should be 0 now\n");
4533 #endif
4534 }
4535 }
4536
4537
4538
4539
4540
4541
4542 void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
4543
4544 {
4545 idetape_tape_t *tape=&(drive->tape);
4546
4547 if (tape->next_stage == NULL)
4548 return;
4549
4550 if (tape->active_data_request == NULL) {
4551 idetape_active_next_stage (drive);
4552 (void) (ide_do_drive_cmd (drive,tape->active_data_request,ide_end));
4553 return;
4554 }
4555 }
4556
4557
4558
4559
4560
4561 void idetape_active_next_stage (ide_drive_t *drive)
4562
4563 {
4564 idetape_tape_t *tape=&(drive->tape);
4565 idetape_pipeline_stage_t *stage=tape->next_stage;
4566 struct request *rq=&(stage->rq);
4567
4568 #if IDETAPE_DEBUG_LOG
4569 printk ("Reached idetape_active_next_stage\n");
4570 #endif
4571 #if IDETAPE_DEBUG_BUGS
4572 if (stage == NULL) {
4573 printk ("ide-tape: bug: Trying to activate a non existing stage\n");
4574 return;
4575 }
4576 #endif
4577 if (rq->cmd == IDETAPE_WRITE_REQUEST)
4578 idetape_copy_buffer_from_stage (stage,tape->data_buffer);
4579
4580 rq->buffer=tape->data_buffer;
4581 tape->active_data_request=rq;
4582 tape->active_stage=stage;
4583 tape->next_stage=stage->next;
4584 }