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