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 (dma_ok ? 1:0,IDETAPE_FEATURES_REG);
1529 OUT_BYTE (bcount.b.high,IDETAPE_BCOUNTH_REG);
1530 OUT_BYTE (bcount.b.low,IDETAPE_BCOUNTL_REG);
1531 OUT_BYTE (drive->select.all,IDETAPE_DRIVESEL_REG);
1532
1533 ide_set_handler (drive,handler,WAIT_CMD);
1534 OUT_BYTE (WIN_PACKETCMD,IDETAPE_ATACOMMAND_REG);
1535 if (ide_wait_stat (drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) {
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545 printk ("ide-tape: Strange, packet command initiated yet DRQ isn't asserted\n");
1546 return;
1547 }
1548
1549 ireason.all=IN_BYTE (IDETAPE_IREASON_REG);
1550 if (!ireason.b.cod || ireason.b.io) {
1551 printk ("ide-tape: (IO,CoD) != (0,1) while issuing a packet command\n");
1552 ide_do_reset (drive);
1553 return;
1554 }
1555
1556 ide_output_data (drive,pc->c,12/4);
1557 #ifdef CONFIG_BLK_DEV_TRITON
1558 if ((pc->dma_in_progress=dma_ok)) {
1559 pc->dma_error=0;
1560 (void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
1561 }
1562 #endif
1563 }
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575 void idetape_pc_intr (ide_drive_t *drive)
1576
1577 {
1578 idetape_tape_t *tape=&(drive->tape);
1579 idetape_status_reg_t status;
1580 idetape_bcount_reg_t bcount;
1581 idetape_ireason_reg_t ireason;
1582 idetape_packet_command_t *pc=tape->pc;
1583 unsigned long temp;
1584
1585 #ifdef CONFIG_BLK_DEV_TRITON
1586 if (pc->dma_in_progress) {
1587 if ((pc->dma_error=HWIF(drive)->dmaproc(ide_dma_status_bad, drive)))
1588
1589
1590
1591
1592 pc->actually_transferred=HWIF(drive)->dmaproc(ide_dma_transferred, drive);
1593 else
1594 pc->actually_transferred=pc->request_transfer;
1595 (void) (HWIF(drive)->dmaproc(ide_dma_abort, drive));
1596 #if IDETAPE_DEBUG_LOG
1597 printk ("ide-tape: DMA finished\n");
1598 #endif
1599 }
1600 #endif
1601
1602 status.all=IN_BYTE (IDETAPE_STATUS_REG);
1603
1604 #if IDETAPE_DEBUG_LOG
1605 printk ("ide-tape: Reached idetape_pc_intr interrupt handler\n");
1606 #endif
1607
1608 if (!status.b.drq) {
1609 #if IDETAPE_DEBUG_LOG
1610 printk ("Packet command completed\n");
1611 printk ("Total bytes transferred: %lu\n",pc->actually_transferred);
1612 #endif
1613 pc->dma_in_progress=0;
1614
1615 sti ();
1616
1617 if (status.b.check || pc->dma_error) {
1618 #if IDETAPE_DEBUG_LOG
1619
1620
1621
1622
1623 printk ("ide-tape: %s: I/O error, ",drive->name);
1624 #endif
1625 if (pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
1626 printk ("ide-tape: I/O error in request sense command\n");
1627 ide_do_reset (drive);
1628 return;
1629 }
1630
1631 idetape_retry_pc (drive);
1632 return;
1633 }
1634 pc->error=0;
1635 if (pc->wait_for_dsc && !status.b.dsc) {
1636 tape->dsc_polling_frequency=IDETAPE_DSC_FAST_MEDIA_ACCESS_FREQUENCY;
1637 idetape_postpone_request (drive);
1638 return;
1639 }
1640 if (tape->failed_pc == pc)
1641 tape->failed_pc=NULL;
1642 #if IDETAPE_DEBUG_BUGS
1643 if (pc->callback==NULL)
1644 printk ("ide-tape: ide-tape bug - Callback function not set !\n");
1645 else
1646 #endif
1647 (*pc->callback)(drive);
1648 return;
1649 }
1650 #ifdef CONFIG_BLK_DEV_TRITON
1651 if (pc->dma_in_progress) {
1652 pc->dma_in_progress=0;
1653 printk ("ide-tape: The tape wants to issue more interrupts in DMA mode\n");
1654 printk ("ide-tape: DMA disabled, reverting to PIO\n");
1655 drive->using_dma=0;
1656 ide_do_reset (drive);
1657 return;
1658 }
1659 #endif
1660 bcount.b.high=IN_BYTE (IDETAPE_BCOUNTH_REG);
1661 bcount.b.low=IN_BYTE (IDETAPE_BCOUNTL_REG);
1662 ireason.all=IN_BYTE (IDETAPE_IREASON_REG);
1663
1664 if (ireason.b.cod) {
1665 printk ("ide-tape: CoD != 0 in idetape_pc_intr\n");
1666 ide_do_reset (drive);
1667 return;
1668 }
1669 if (ireason.b.io != !(pc->writing)) {
1670 printk ("ide-tape: We wanted to %s, ",pc->writing ? "Write":"Read");
1671 printk ("but the tape wants us to %s !\n",ireason.b.io ? "Read":"Write");
1672 ide_do_reset (drive);
1673 return;
1674 }
1675
1676 if (!pc->writing) {
1677 temp=(unsigned long) pc->actually_transferred + bcount.all;
1678 if ( temp > pc->request_transfer) {
1679 printk ("ide-tape: The tape wants to send us more data than requested - ");
1680 if (temp > pc->buffer_size) {
1681 printk ("Discarding data\n");
1682 idetape_discard_data (drive,bcount.all);
1683 ide_set_handler (drive,&idetape_pc_intr,WAIT_CMD);
1684 return;
1685 }
1686 else
1687 printk ("Allowing transfer\n");
1688 }
1689 }
1690 #if IDETAPE_DEBUG_BUGS
1691 if (bcount.all && !pc->buffer) {
1692 printk ("ide-tape: ide-tape.c bug - Buffer not set in idetape_pc_intr. Discarding data.\n");
1693
1694 if (!pc->writing) {
1695 printk ("ide-tape: Discarding data\n");
1696 idetape_discard_data (drive,bcount.all);
1697 ide_set_handler (drive,&idetape_pc_intr,WAIT_CMD);
1698 return;
1699 }
1700 else {
1701 }
1702 }
1703 #endif
1704 if (pc->writing)
1705 idetape_output_data (drive,pc->current_position,bcount.all);
1706 else
1707 idetape_input_data (drive,pc->current_position,bcount.all);
1708 #if IDETAPE_DEBUG_LOG
1709 printk ("ide-tape: %s %d bytes\n",pc->writing ? "Wrote":"Received",bcount.all);
1710 #endif
1711 pc->actually_transferred+=bcount.all;
1712 pc->current_position+=bcount.all;
1713
1714 ide_set_handler (drive,&idetape_pc_intr,WAIT_CMD);
1715 }
1716
1717
1718
1719
1720
1721
1722
1723 void idetape_postpone_request (ide_drive_t *drive)
1724
1725 {
1726 idetape_tape_t *tape=&(drive->tape);
1727 struct request *rq;
1728 idetape_status_reg_t status;
1729
1730 #if IDETAPE_DEBUG_LOG
1731 printk ("Reached idetape_postpone_request\n");
1732 #endif
1733 #if IDETAPE_DEBUG_BUGS
1734 if (tape->postponed_rq != NULL)
1735 printk ("ide-tape.c bug - postponed_rq not NULL in idetape_postpone_request\n");
1736 #endif
1737
1738 tape->dsc_timer.expires=jiffies + tape->dsc_polling_frequency;
1739 tape->dsc_timeout=jiffies+IDETAPE_DSC_TIMEOUT;
1740 tape->dsc_timer.data=(unsigned long) drive;
1741 tape->dsc_timer.function=&idetape_poll_for_dsc;
1742 init_timer (&(tape->dsc_timer));
1743
1744
1745
1746
1747
1748 tape->postponed_rq = rq = HWGROUP(drive)->rq;
1749 rq->rq_status = IDETAPE_RQ_POSTPONED;
1750 blk_dev[MAJOR(rq->rq_dev)].current_request = rq->next;
1751 HWGROUP(drive)->rq = NULL;
1752
1753
1754
1755
1756
1757 status.all=IN_BYTE (IDETAPE_STATUS_REG);
1758 tape->last_status=status.all;
1759 tape->request_status=1;
1760
1761 tape->dsc_polling_start=jiffies;
1762 add_timer(&(tape->dsc_timer));
1763 }
1764
1765
1766
1767
1768
1769
1770
1771 void idetape_poll_for_dsc_direct (unsigned long data)
1772
1773 {
1774 ide_drive_t *drive=(ide_drive_t *) data;
1775 idetape_tape_t *tape=&(drive->tape);
1776 idetape_status_reg_t status;
1777
1778 #if IDETAPE_DEBUG_LOG
1779 printk ("%s: idetape_poll_for_dsc_direct called\n",drive->name);
1780 #endif
1781
1782 OUT_BYTE(drive->select.all,IDE_SELECT_REG);
1783 status.all=IN_BYTE (IDETAPE_STATUS_REG);
1784
1785 if (status.b.dsc) {
1786 tape->dsc_received=1;
1787 del_timer (&(tape->dsc_timer));
1788 idetape_put_back_postponed_request (drive);
1789 return;
1790 }
1791
1792 if (jiffies > tape->dsc_timeout) {
1793 tape->dsc_received=0;
1794 del_timer (&(tape->dsc_timer));
1795
1796 idetape_put_back_postponed_request (drive);
1797 return;
1798 }
1799
1800
1801
1802 if (jiffies - tape->dsc_polling_start > IDETAPE_FAST_SLOW_THRESHOLD)
1803 tape->dsc_timer.expires = jiffies + IDETAPE_DSC_SLOW_MEDIA_ACCESS_FREQUENCY;
1804 else
1805 tape->dsc_timer.expires = jiffies + tape->dsc_polling_frequency;
1806 add_timer(&(tape->dsc_timer));
1807 return;
1808 }
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826 void idetape_poll_for_dsc (unsigned long data)
1827
1828 {
1829 ide_drive_t *drive=(ide_drive_t *) data;
1830 unsigned int major = HWIF(drive)->major;
1831 idetape_tape_t *tape=&(drive->tape);
1832 struct blk_dev_struct *bdev = &blk_dev[major];
1833 struct request *next_rq;
1834 unsigned long flags;
1835 idetape_status_reg_t status;
1836
1837 #if IDETAPE_DEBUG_LOG
1838 printk ("%s: idetape_poll_for_dsc called\n",drive->name);
1839 #endif
1840
1841 save_flags (flags);cli ();
1842
1843
1844
1845
1846
1847
1848 if (HWGROUP (drive)->rq == NULL) {
1849 sti ();
1850 idetape_poll_for_dsc_direct (data);
1851 return;
1852 }
1853
1854
1855
1856
1857
1858
1859 status.all=tape->last_status;
1860
1861 if (status.b.dsc) {
1862 tape->dsc_received=1;
1863 idetape_put_back_postponed_request (drive);
1864 del_timer (&(tape->dsc_timer));
1865 restore_flags (flags);
1866 return;
1867 }
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908 #if IDETAPE_ANTICIPATE_READ_WRITE_DSC
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920 if (tape->postponed_rq->cmd != IDETAPE_PACKET_COMMAND_REQUEST_TYPE1) {
1921
1922
1923
1924
1925
1926
1927 idetape_put_back_postponed_request (drive);
1928 del_timer (&(tape->dsc_timer));
1929 restore_flags (flags);
1930 return;
1931 }
1932 #endif
1933
1934
1935
1936
1937
1938 next_rq=bdev->current_request;
1939 if (next_rq == HWGROUP (drive)->rq)
1940 next_rq=next_rq->next;
1941
1942 if (next_rq == NULL) {
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960 if (tape->postponed_rq->cmd == IDETAPE_PACKET_COMMAND_REQUEST_TYPE1) {
1961
1962
1963
1964
1965
1966
1967
1968
1969 tape->request_status=1;
1970 restore_flags (flags);
1971 tape->dsc_timer.expires = jiffies + tape->dsc_polling_frequency;
1972 add_timer(&(tape->dsc_timer));
1973 return;
1974 }
1975
1976
1977
1978
1979
1980
1981
1982 idetape_put_back_postponed_request (drive);
1983 del_timer (&(tape->dsc_timer));
1984 restore_flags (flags);
1985 return;
1986 }
1987
1988
1989
1990
1991
1992
1993
1994
1995 tape->request_status=1;
1996 restore_flags (flags);
1997
1998 if (jiffies > tape->dsc_timeout) {
1999 tape->dsc_received=0;
2000
2001 idetape_put_back_postponed_request (drive);
2002 del_timer (&(tape->dsc_timer));
2003 restore_flags (flags);
2004 return;
2005 }
2006
2007
2008
2009 if (jiffies - tape->dsc_polling_start > IDETAPE_FAST_SLOW_THRESHOLD)
2010 tape->dsc_timer.expires = jiffies + IDETAPE_DSC_SLOW_MEDIA_ACCESS_FREQUENCY;
2011 else
2012 tape->dsc_timer.expires = jiffies + tape->dsc_polling_frequency;
2013 add_timer(&(tape->dsc_timer));
2014 return;
2015 }
2016
2017
2018
2019
2020
2021
2022 void idetape_put_back_postponed_request (ide_drive_t *drive)
2023
2024 {
2025 idetape_tape_t *tape = &(drive->tape);
2026
2027 #if IDETAPE_DEBUG_LOG
2028 printk ("ide-tape: Putting back postponed request\n");
2029 #endif
2030 #if IDETAPE_DEBUG_BUGS
2031 if (tape->postponed_rq == NULL) {
2032 printk ("tape->postponed_rq is NULL in put_back_postponed_request\n");
2033 return;
2034 }
2035 #endif
2036 (void) ide_do_drive_cmd (drive, tape->postponed_rq, ide_next);
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048 }
2049
2050 void idetape_media_access_finished (ide_drive_t *drive)
2051
2052 {
2053 idetape_tape_t *tape=&(drive->tape);
2054 idetape_status_reg_t status;
2055 idetape_packet_command_t *pc;
2056
2057 pc=tape->pc;
2058
2059 status.all=IN_BYTE (IDETAPE_STATUS_REG);
2060
2061 if (tape->dsc_received) {
2062 #if IDETAPE_DEBUG_LOG
2063 printk ("DSC received\n");
2064 #endif
2065 if (status.b.check) {
2066 printk ("ide-tape: %s: I/O error, ",drive->name);
2067 idetape_retry_pc (drive);
2068 return;
2069 }
2070 pc->error=0;
2071 if (tape->failed_pc == pc)
2072 tape->failed_pc=NULL;
2073 #if IDETAPE_DEBUG_BUGS
2074 if (pc->callback==NULL)
2075 printk ("ide-tape: ide-tape bug - Callback function not set !\n");
2076 else
2077 #endif
2078 (*pc->callback)(drive);
2079
2080 return;
2081 }
2082 else {
2083 printk ("ide-tape: %s: DSC timeout.\n",drive->name);
2084
2085 pc->error=1;
2086 tape->failed_pc=NULL;
2087 #if IDETAPE_DEBUG_BUGS
2088 if (pc->callback==NULL)
2089 printk ("ide-tape: ide-tape bug - Callback function not set !\n");
2090 else
2091 #endif
2092 (*pc->callback)(drive);
2093 return;
2094 }
2095 }
2096
2097
2098
2099
2100
2101
2102
2103
2104 void idetape_retry_pc (ide_drive_t *drive)
2105
2106 {
2107 idetape_packet_command_t *pc;
2108 struct request *new_rq;
2109
2110 idetape_error_reg_t error;
2111 error.all=IN_BYTE (IDETAPE_ERROR_REG);
2112 pc=idetape_next_pc_storage (drive);
2113 new_rq=idetape_next_rq_storage (drive);
2114 idetape_create_request_sense_cmd (pc);
2115 pc->buffer=pc->temp_buffer;
2116 pc->buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
2117 pc->current_position=pc->temp_buffer;
2118 idetape_queue_pc_head (drive,pc,new_rq);
2119 }
2120
2121
2122
2123
2124
2125 void idetape_pc_callback (ide_drive_t *drive)
2126
2127 {
2128 idetape_tape_t *tape;
2129 struct request *rq;
2130
2131 tape=&(drive->tape);
2132 rq=HWGROUP(drive)->rq;
2133
2134 #if IDETAPE_DEBUG_LOG
2135 printk ("ide-tape: Reached idetape_pc_callback\n");
2136 #endif
2137 if (!tape->pc->error) {
2138 #if IDETAPE_DEBUG_LOG
2139 printk ("Request completed\n");
2140 #endif
2141 idetape_end_request (1,HWGROUP (drive));
2142 }
2143 else {
2144 idetape_end_request (0,HWGROUP (drive));
2145 }
2146 return;
2147 }
2148
2149
2150 void idetape_read_callback (ide_drive_t *drive)
2151
2152 {
2153 idetape_tape_t *tape=&(drive->tape);
2154 struct request *rq=HWGROUP(drive)->rq;
2155 int blocks_read=tape->pc->actually_transferred/tape->tape_block_size;
2156
2157 #if IDETAPE_DEBUG_LOG
2158 printk ("ide-tape: Reached idetape_read_callback\n");
2159 #endif
2160
2161 tape->block_address+=blocks_read;
2162 rq->current_nr_sectors-=blocks_read;
2163
2164 if (!tape->pc->error)
2165 idetape_end_request (1,HWGROUP (drive));
2166 else {
2167 rq->errors=tape->pc->error;
2168 switch (rq->errors) {
2169 case IDETAPE_RQ_ERROR_FILEMARK:
2170 case IDETAPE_RQ_ERROR_EOD:
2171 break;
2172 }
2173 idetape_end_request (0,HWGROUP (drive));
2174 }
2175 return;
2176 }
2177
2178 void idetape_write_callback (ide_drive_t *drive)
2179
2180 {
2181 idetape_tape_t *tape=&(drive->tape);
2182 struct request *rq=HWGROUP(drive)->rq;
2183 int blocks_written=tape->pc->actually_transferred/tape->tape_block_size;
2184
2185 #if IDETAPE_DEBUG_LOG
2186 printk ("ide-tape: Reached idetape_write_callback\n");
2187 #endif
2188
2189 tape->block_address+=blocks_written;
2190 rq->current_nr_sectors-=blocks_written;
2191
2192 if (!tape->pc->error)
2193 idetape_end_request (1,HWGROUP (drive));
2194 else {
2195 rq->errors=tape->pc->error;
2196 idetape_end_request (0,HWGROUP (drive));
2197 }
2198 return;
2199 }
2200
2201 void idetape_inquiry_callback (ide_drive_t *drive)
2202
2203 {
2204 idetape_tape_t *tape;
2205
2206 tape=&(drive->tape);
2207
2208 idetape_display_inquiry_result (tape->pc->buffer);
2209 idetape_pc_callback (drive);
2210 return;
2211 }
2212
2213
2214
2215
2216
2217
2218
2219
2220 void idetape_input_data (ide_drive_t *drive,void *buffer, unsigned long bcount)
2221
2222 {
2223 unsigned long wcount;
2224
2225 wcount=bcount >> 2;
2226 bcount -= 4*wcount;
2227
2228 if (wcount)
2229 ide_input_data (drive,buffer,wcount);
2230
2231 if (bcount) {
2232 ((byte *)buffer) += 4*wcount;
2233 insb (IDETAPE_DATA_REG,buffer,bcount);
2234 }
2235 }
2236
2237
2238
2239
2240
2241 void idetape_output_data (ide_drive_t *drive,void *buffer, unsigned long bcount)
2242
2243 {
2244 unsigned long wcount;
2245
2246 wcount=bcount >> 2;
2247 bcount -= 4*wcount;
2248
2249 if (wcount)
2250 ide_output_data (drive,buffer,wcount);
2251
2252 if (bcount) {
2253 ((byte *)buffer) += 4*wcount;
2254 outsb (IDETAPE_DATA_REG,buffer,bcount);
2255 }
2256 }
2257
2258
2259
2260
2261
2262
2263 void idetape_discard_data (ide_drive_t *drive, unsigned long bcount)
2264
2265 {
2266 unsigned long i;
2267
2268 for (i=0;i<bcount;i++)
2269 IN_BYTE (IDETAPE_DATA_REG);
2270 }
2271
2272
2273
2274
2275
2276 void idetape_create_inquiry_cmd (idetape_packet_command_t *pc)
2277
2278 {
2279 #if IDETAPE_DEBUG_LOG
2280 printk ("ide-tape: Creating INQUIRY packet command\n");
2281 #endif
2282 pc->request_transfer=36;
2283 pc->callback=&idetape_inquiry_callback;
2284 pc->writing=0;
2285
2286 idetape_zero_packet_command (pc);
2287 pc->c[0]=IDETAPE_INQUIRY_CMD;
2288 pc->c[4]=255;
2289 }
2290
2291
2292
2293
2294
2295 void idetape_display_inquiry_result (byte *buffer)
2296
2297 {
2298 idetape_inquiry_result_t *result;
2299
2300 result=(idetape_inquiry_result_t *) buffer;
2301 ide_fixstring (result->vendor_id,8,0);
2302 ide_fixstring (result->product_id,16,0);
2303 ide_fixstring (result->revision_level,4,0);
2304
2305 if (result->response_format != 2) {
2306 printk ("The INQUIRY Data Format is unknown to us !\n");
2307 printk ("Assuming QIC-157C format.\n");
2308 }
2309
2310 #if IDETAPE_DEBUG_LOG
2311 printk ("Dumping INQUIRY command results:\n");
2312 printk ("Response Data Format: %d - ",result->response_format);
2313 switch (result->response_format) {
2314 case 2:
2315 printk ("As specified in QIC-157 Revision C\n");
2316 break;
2317 default:
2318 printk ("Unknown\n");
2319 break;
2320 }
2321
2322 printk ("Device Type: %x - ",result->device_type);
2323 switch (result->device_type) {
2324 case 0: printk ("Direct-access Device\n");break;
2325 case 1: printk ("Streaming Tape Device\n");break;
2326 case 2: case 3: case 4: printk ("Reserved\n");break;
2327 case 5: printk ("CD-ROM Device\n");break;
2328 case 6: printk ("Reserved\n");
2329 case 7: printk ("Optical memory Device\n");break;
2330 case 0x1f: printk ("Unknown or no Device type\n");break;
2331 default: printk ("Reserved\n");
2332 }
2333
2334 printk ("Removable Medium: %s",result->rmb ? "Yes\n":"No\n");
2335
2336 printk ("ANSI Version: %d - ",result->ansi_version);
2337 switch (result->ansi_version) {
2338 case 2:
2339 printk ("QIC-157 Revision C\n");
2340 break;
2341 default:
2342 printk ("Unknown\n");
2343 break;
2344 }
2345
2346 printk ("ECMA Version: ");
2347 if (result->ecma_version)
2348 printk ("%d\n",result->ecma_version);
2349 else
2350 printk ("Not supported\n");
2351
2352 printk ("ISO Version: ");
2353 if (result->iso_version)
2354 printk ("%d\n",result->iso_version);
2355 else
2356 printk ("Not supported\n");
2357
2358 printk ("Additional Length: %d\n",result->additional_length);
2359 printk ("Vendor Identification: %s\n",result->vendor_id);
2360 printk ("Product Identification: %s\n",result->product_id);
2361 printk ("Product Revision Level: %s\n",result->revision_level);
2362 #endif
2363
2364 if (result->device_type != 1)
2365 printk ("Device type is not set to tape\n");
2366
2367 if (!result->rmb)
2368 printk ("The removable flag is not set\n");
2369
2370 if (result->ansi_version != 2) {
2371 printk ("The Ansi Version is unknown to us !\n");
2372 printk ("Assuming compliance with QIC-157C specification.\n");
2373 }
2374 }
2375
2376 void idetape_create_request_sense_cmd (idetape_packet_command_t *pc)
2377
2378 {
2379 #if IDETAPE_DEBUG_LOG
2380 printk ("ide-tape: Creating REQUEST SENSE packet command\n");
2381 #endif
2382 pc->request_transfer=18;
2383 pc->callback=&idetape_request_sense_callback;
2384 pc->writing=0;
2385
2386 idetape_zero_packet_command (pc);
2387 pc->c[0]=IDETAPE_REQUEST_SENSE_CMD;
2388 pc->c[4]=255;
2389 }
2390
2391 void idetape_request_sense_callback (ide_drive_t *drive)
2392
2393 {
2394 idetape_tape_t *tape=&(drive->tape);
2395
2396 #if IDETAPE_DEBUG_LOG
2397 printk ("ide-tape: Reached idetape_request_sense_callback\n");
2398 #endif
2399 if (!tape->pc->error) {
2400 #if IDETAPE_DEBUG_LOG
2401 printk ("Request completed\n");
2402 #endif
2403 idetape_analyze_error (drive,(idetape_request_sense_result_t *) tape->pc->buffer);
2404 idetape_end_request (1,HWGROUP (drive));
2405 }
2406 else {
2407 printk ("Error in REQUEST SENSE itself - Aborting request!\n");
2408 idetape_end_request (0,HWGROUP (drive));
2409 }
2410 return;
2411 }
2412
2413
2414
2415
2416
2417
2418
2419 void idetape_analyze_error (ide_drive_t *drive,idetape_request_sense_result_t *result)
2420
2421 {
2422 idetape_tape_t *tape=&(drive->tape);
2423 idetape_packet_command_t *pc=tape->failed_pc;
2424
2425 tape->sense_key=result->sense_key;
2426 tape->asc=result->asc;
2427 tape->ascq=result->ascq;
2428
2429 #if IDETAPE_DEBUG_LOG
2430
2431
2432
2433
2434 printk ("ide-tape: pc = %x, sense key = %x, asc = %x, ascq = %x\n",pc->c[0],result->sense_key,result->asc,result->ascq);
2435 #endif
2436
2437 if (pc->c[0] == IDETAPE_READ_CMD) {
2438 if (result->filemark) {
2439 pc->error=IDETAPE_RQ_ERROR_FILEMARK;
2440 pc->abort=1;
2441 }
2442 }
2443
2444 if (pc->c[0] == IDETAPE_READ_CMD || pc->c[0] == IDETAPE_WRITE_CMD) {
2445 if (result->sense_key == 8) {
2446 pc->error=IDETAPE_RQ_ERROR_EOD;
2447 pc->abort=1;
2448 }
2449 }
2450
2451 #if 1
2452 #ifdef CONFIG_BLK_DEV_TRITON
2453
2454
2455
2456
2457
2458 if (pc->dma_error && pc->abort) {
2459 unsigned long *long_ptr=(unsigned long *) &(result->information1);
2460 pc->actually_transferred=pc->request_transfer-tape->tape_block_size*idetape_swap_long (*long_ptr);
2461 }
2462 #endif
2463 #endif
2464 }
2465
2466 void idetape_create_test_unit_ready_cmd (idetape_packet_command_t *pc)
2467
2468 {
2469 #if IDETAPE_DEBUG_LOG
2470 printk ("ide-tape: Creating TEST UNIT READY packet command\n");
2471 #endif
2472 pc->request_transfer=0;
2473 pc->buffer=NULL;
2474 pc->current_position=NULL;
2475 pc->callback=&idetape_pc_callback;
2476 pc->writing=0;
2477
2478 idetape_zero_packet_command (pc);
2479 pc->c[0]=IDETAPE_TEST_UNIT_READY_CMD;
2480 }
2481
2482 void idetape_create_locate_cmd (idetape_packet_command_t *pc,unsigned long block,byte partition)
2483
2484 {
2485 unsigned long *ptr;
2486
2487 #if IDETAPE_DEBUG_LOG
2488 printk ("ide-tape: Creating LOCATE packet command\n");
2489 #endif
2490 pc->request_transfer=0;
2491 pc->buffer=NULL;
2492 pc->current_position=NULL;
2493 pc->buffer_size=0;
2494 pc->wait_for_dsc=1;
2495 pc->callback=&idetape_pc_callback;
2496 pc->writing=0;
2497
2498 idetape_zero_packet_command (pc);
2499 pc->c [0]=IDETAPE_LOCATE_CMD;
2500 pc->c [1]=2;
2501 ptr=(unsigned long *) &(pc->c[3]);
2502 *ptr=idetape_swap_long (block);
2503 pc->c[8]=partition;
2504 }
2505
2506 void idetape_create_rewind_cmd (idetape_packet_command_t *pc)
2507
2508 {
2509 #if IDETAPE_DEBUG_LOG
2510 printk ("ide-tape: Creating REWIND packet command\n");
2511 #endif
2512 pc->request_transfer=0;
2513 pc->buffer=NULL;
2514 pc->current_position=NULL;
2515 pc->buffer_size=0;
2516 pc->wait_for_dsc=1;
2517 pc->callback=&idetape_pc_callback;
2518 pc->writing=0;
2519
2520 idetape_zero_packet_command (pc);
2521 pc->c [0]=IDETAPE_REWIND_CMD;
2522 }
2523
2524
2525
2526
2527
2528 void idetape_create_mode_sense_cmd (idetape_packet_command_t *pc,byte page_code)
2529
2530 {
2531 #if IDETAPE_DEBUG_LOG
2532 printk ("ide-tape: Creating MODE SENSE packet command - Page %d\n",page_code);
2533 #endif
2534
2535 pc->wait_for_dsc=0;
2536 pc->callback=&idetape_pc_callback;
2537 pc->writing=0;
2538
2539 switch (page_code) {
2540 case IDETAPE_CAPABILITIES_PAGE:
2541 pc->request_transfer=24;
2542 }
2543
2544 idetape_zero_packet_command (pc);
2545 pc->c [0]=IDETAPE_MODE_SENSE_CMD;
2546 pc->c [1]=8;
2547 pc->c [2]=page_code;
2548 pc->c [3]=255;
2549 pc->c [4]=255;
2550 }
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561 void idetape_create_write_filemark_cmd (idetape_packet_command_t *pc,int write_filemark)
2562
2563 {
2564 #if IDETAPE_DEBUG_LOG
2565 printk ("Creating WRITE FILEMARK packet command\n");
2566 if (!write_filemark)
2567 printk ("which will only flush buffered data\n");
2568 #endif
2569 pc->request_transfer=0;
2570 pc->buffer=NULL;
2571 pc->current_position=NULL;
2572 pc->buffer_size=0;
2573 pc->wait_for_dsc=1;
2574 pc->callback=&idetape_pc_callback;
2575 pc->writing=0;
2576
2577 idetape_zero_packet_command (pc);
2578 pc->c [0]=IDETAPE_WRITE_FILEMARK_CMD;
2579 if (write_filemark)
2580 pc->c [4]=1;
2581 }
2582
2583 void idetape_create_load_unload_cmd (idetape_packet_command_t *pc,int cmd)
2584
2585 {
2586 #if IDETAPE_DEBUG_LOG
2587 printk ("Creating LOAD UNLOAD packet command, cmd=%d\n",cmd);
2588 #endif
2589 pc->request_transfer=0;
2590 pc->buffer=NULL;
2591 pc->current_position=NULL;
2592 pc->buffer_size=0;
2593 pc->wait_for_dsc=1;
2594 pc->callback=&idetape_pc_callback;
2595 pc->writing=0;
2596
2597 idetape_zero_packet_command (pc);
2598 pc->c [0]=IDETAPE_LOAD_UNLOAD_CMD;
2599 pc->c [4]=cmd;
2600 }
2601
2602 void idetape_create_erase_cmd (idetape_packet_command_t *pc)
2603
2604 {
2605
2606 #if IDETAPE_DEBUG_LOG
2607 printk ("Creating ERASE command\n");
2608 #endif
2609
2610 pc->request_transfer=0;
2611 pc->buffer=NULL;
2612 pc->current_position=NULL;
2613 pc->buffer_size=0;
2614 pc->wait_for_dsc=1;
2615 pc->callback=&idetape_pc_callback;
2616 pc->writing=0;
2617
2618 idetape_zero_packet_command (pc);
2619 pc->c [0]=IDETAPE_ERASE_CMD;
2620 pc->c [1]=1;
2621 }
2622
2623 void idetape_create_read_cmd (idetape_packet_command_t *pc,unsigned long length)
2624
2625 {
2626 union convert {
2627 unsigned all :32;
2628 struct {
2629 unsigned b1 :8;
2630 unsigned b2 :8;
2631 unsigned b3 :8;
2632 unsigned b4 :8;
2633 } b;
2634 } original;
2635
2636 #if IDETAPE_DEBUG_LOG
2637 printk ("ide-tape: Creating READ packet command\n");
2638 #endif
2639
2640 original.all=length;
2641
2642 pc->wait_for_dsc=0;
2643 pc->callback=&idetape_read_callback;
2644 pc->writing=0;
2645
2646 idetape_zero_packet_command (pc);
2647
2648 pc->c [0]=IDETAPE_READ_CMD;
2649 pc->c [1]=1;
2650 pc->c [4]=original.b.b1;
2651 pc->c [3]=original.b.b2;
2652 pc->c [2]=original.b.b3;
2653
2654 if (length)
2655 pc->dma_recommended=1;
2656
2657 return;
2658 }
2659
2660 void idetape_create_space_cmd (idetape_packet_command_t *pc,long count,byte cmd)
2661
2662 {
2663 union convert {
2664 unsigned all :32;
2665 struct {
2666 unsigned b1 :8;
2667 unsigned b2 :8;
2668 unsigned b3 :8;
2669 unsigned b4 :8;
2670 } b;
2671 } original;
2672
2673 #if IDETAPE_DEBUG_LOG
2674 printk ("ide-tape: Creating SPACE packet command\n");
2675 #endif
2676
2677 original.all=count;
2678
2679 pc->request_transfer=0;
2680 pc->buffer=NULL;
2681 pc->current_position=NULL;
2682 pc->buffer_size=0;
2683 pc->wait_for_dsc=1;
2684 pc->callback=&idetape_pc_callback;
2685 pc->writing=0;
2686
2687 idetape_zero_packet_command (pc);
2688 pc->c [0]=IDETAPE_SPACE_CMD;
2689 pc->c [1]=cmd;
2690 pc->c [4]=original.b.b1;
2691 pc->c [3]=original.b.b2;
2692 pc->c [2]=original.b.b3;
2693
2694 return;
2695 }
2696
2697 void idetape_create_write_cmd (idetape_packet_command_t *pc,unsigned long length)
2698
2699 {
2700 union convert {
2701 unsigned all :32;
2702 struct {
2703 unsigned b1 :8;
2704 unsigned b2 :8;
2705 unsigned b3 :8;
2706 unsigned b4 :8;
2707 } b;
2708 } original;
2709
2710 #if IDETAPE_DEBUG_LOG
2711 printk ("ide-tape: Creating WRITE packet command\n");
2712 #endif
2713
2714 original.all=length;
2715
2716 pc->wait_for_dsc=0;
2717 pc->callback=&idetape_write_callback;
2718 pc->writing=1;
2719
2720 idetape_zero_packet_command (pc);
2721
2722 pc->c [0]=IDETAPE_WRITE_CMD;
2723 pc->c [1]=1;
2724 pc->c [4]=original.b.b1;
2725 pc->c [3]=original.b.b2;
2726 pc->c [2]=original.b.b3;
2727
2728 if (length)
2729 pc->dma_recommended=1;
2730
2731 return;
2732 }
2733
2734 void idetape_create_read_position_cmd (idetape_packet_command_t *pc)
2735
2736 {
2737 #if IDETAPE_DEBUG_LOG
2738 printk ("ide-tape: Creating READ POSITION packet command\n");
2739 #endif
2740
2741 pc->request_transfer=20;
2742 pc->wait_for_dsc=0;
2743 pc->callback=&idetape_read_position_callback;
2744 pc->writing=0;
2745
2746 idetape_zero_packet_command (pc);
2747 pc->c [0]=IDETAPE_READ_POSITION_CMD;
2748 pc->c [1]=0;
2749 }
2750
2751 void idetape_read_position_callback (ide_drive_t *drive)
2752
2753 {
2754 idetape_tape_t *tape;
2755 struct request *rq;
2756 idetape_read_position_result_t *result;
2757
2758 tape=&(drive->tape);
2759
2760 #if IDETAPE_DEBUG_LOG
2761 printk ("ide-tape: Reached idetape_read_position_callback\n");
2762 #endif
2763
2764 rq=HWGROUP(drive)->rq;
2765
2766 if (!tape->pc->error) {
2767 result=(idetape_read_position_result_t *) tape->pc->buffer;
2768 #if IDETAPE_DEBUG_LOG
2769 printk ("Request completed\n");
2770 printk ("Dumping the results of the READ POSITION command\n");
2771 printk ("BOP - %s\n",result->bop ? "Yes":"No");
2772 printk ("EOP - %s\n",result->eop ? "Yes":"No");
2773 #endif
2774 if (result->bpu) {
2775 printk ("ide-tape: Block location is unknown to the tape\n");
2776 printk ("Aborting request\n");
2777 tape->block_address_valid=0;
2778 idetape_end_request (0,HWGROUP (drive));
2779 }
2780 else {
2781 #if IDETAPE_DEBUG_LOG
2782 printk ("Block Location - %lu\n",idetape_swap_long (result->first_block));
2783 #endif
2784 tape->block_address=idetape_swap_long (result->first_block);
2785 tape->block_address_valid=1;
2786 idetape_end_request (1,HWGROUP (drive));
2787 }
2788 }
2789 else {
2790 printk ("Aborting request\n");
2791 idetape_end_request (0,HWGROUP (drive));
2792 }
2793 return;
2794 }
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804 int idetape_blkdev_ioctl (ide_drive_t *drive, struct inode *inode, struct file *file,
2805 unsigned int cmd, unsigned long arg)
2806 {
2807 idetape_packet_command_t pc;
2808
2809 pc.buffer=pc.temp_buffer;
2810 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
2811 pc.current_position=pc.temp_buffer;
2812
2813 #if IDETAPE_DEBUG_LOG
2814 printk ("ide-tape: Reached idetape_blkdev_ioctl\n");
2815 #endif
2816 switch (cmd) {
2817 default:
2818 return -EIO;
2819 }
2820 }
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830 void idetape_end_request (byte uptodate, ide_hwgroup_t *hwgroup)
2831
2832 {
2833 ide_drive_t *drive = hwgroup->drive;
2834 struct request *rq = hwgroup->rq;
2835 idetape_tape_t *tape = &(drive->tape);
2836 unsigned int major = HWIF(drive)->major;
2837 struct blk_dev_struct *bdev = &blk_dev[major];
2838 int error;
2839
2840 #if IDETAPE_DEBUG_LOG
2841 printk ("Reached idetape_end_request\n");
2842 #endif
2843
2844 bdev->current_request=rq;
2845
2846 if (!rq->errors)
2847 rq->errors=!uptodate;
2848 error=rq->errors;
2849
2850 if (tape->active_data_request == rq) {
2851
2852 if (rq->cmd == IDETAPE_READ_REQUEST) {
2853 #if IDETAPE_DEBUG_BUGS
2854 if (tape->active_stage == NULL)
2855 printk ("ide-tape: bug: active_stage is NULL in idetape_end_request\n");
2856 else
2857 #endif
2858 idetape_copy_buffer_to_stage (tape->active_stage,tape->data_buffer);
2859 }
2860
2861 tape->active_stage=NULL;
2862 tape->active_data_request=NULL;
2863
2864 if (rq->cmd == IDETAPE_WRITE_REQUEST) {
2865 if (rq->errors)
2866 tape->error_in_pipeline_stage=rq->errors;
2867 idetape_remove_stage_head (drive);
2868 }
2869
2870 if (tape->next_stage == NULL) {
2871 if (!error)
2872 idetape_increase_max_pipeline_stages (drive);
2873 ide_end_drive_cmd (drive, 0, 0);
2874 return;
2875 }
2876
2877 idetape_active_next_stage (drive);
2878
2879
2880
2881
2882
2883
2884
2885
2886 #if IDETAPE_LOW_TAPE_PRIORITY
2887 (void) ide_do_drive_cmd (drive,tape->active_data_request,ide_end);
2888 #else
2889 (void) ide_do_drive_cmd (drive,tape->active_data_request,ide_next);
2890 #endif
2891 }
2892 ide_end_drive_cmd (drive, 0, 0);
2893 }
2894
2895
2896
2897
2898
2899 void idetape_do_request (ide_drive_t *drive, struct request *rq, unsigned long block)
2900
2901 {
2902 idetape_tape_t *tape=&(drive->tape);
2903 idetape_packet_command_t *pc;
2904 unsigned int major = HWIF(drive)->major;
2905 struct blk_dev_struct *bdev = &blk_dev[major];
2906 idetape_status_reg_t status;
2907
2908 #if IDETAPE_DEBUG_LOG
2909 printk ("Current request:\n");
2910 printk ("rq_status: %d, rq_dev: %u, cmd: %d, errors: %d\n",rq->rq_status,(unsigned int) rq->rq_dev,rq->cmd,rq->errors);
2911 printk ("sector: %ld, nr_sectors: %ld, current_nr_sectors: %ld\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors);
2912 #endif
2913
2914 if (!IDETAPE_REQUEST_CMD (rq->cmd)) {
2915
2916
2917
2918
2919
2920 printk ("ide-tape: Unsupported command in request queue\n");
2921 printk ("ide-tape: The block device interface should not be used for data transfers.\n");
2922 printk ("ide-tape: Use the character device interfaces\n");
2923 printk ("ide-tape: /dev/ht0 and /dev/nht0 instead.\n");
2924 printk ("ide-tape: (Run linux/drivers/block/MAKEDEV.ide to create them)\n");
2925 printk ("ide-tape: Aborting request.\n");
2926
2927 ide_end_request (0,HWGROUP (drive));
2928 return;
2929 }
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951 if (rq->next != NULL && rq->rq_dev != rq->next->rq_dev)
2952 bdev->current_request=rq->next;
2953
2954
2955
2956 if (tape->failed_pc != NULL && tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
2957 idetape_issue_packet_command (drive,tape->failed_pc,&idetape_pc_intr);
2958 return;
2959 }
2960
2961
2962
2963 if (tape->postponed_rq != NULL) {
2964 #if IDETAPE_DEBUG_BUGS
2965 if (tape->postponed_rq->rq_status != RQ_ACTIVE || rq != tape->postponed_rq) {
2966 printk ("ide-tape: ide-tape.c bug - Two DSC requests were queued\n");
2967 idetape_end_request (0,HWGROUP (drive));
2968 return;
2969 }
2970 #endif
2971 if (rq->cmd == IDETAPE_PACKET_COMMAND_REQUEST_TYPE1) {
2972
2973
2974
2975 tape->postponed_rq = NULL;
2976 idetape_media_access_finished (drive);
2977 return;
2978 }
2979
2980
2981
2982
2983
2984
2985
2986 tape->postponed_rq = NULL;
2987 }
2988
2989 status.all=IN_BYTE (IDETAPE_STATUS_REG);
2990
2991
2992
2993
2994
2995
2996
2997 if (tape->reset_issued) {
2998 status.b.dsc=1;
2999 tape->reset_issued=0;
3000 }
3001
3002 switch (rq->cmd) {
3003 case IDETAPE_READ_REQUEST:
3004 if (!status.b.dsc) {
3005 #if IDETAPE_DEBUG_LOG
3006 printk ("ide-tape: DSC != 1 - Postponing read request\n");
3007 #endif
3008 tape->dsc_polling_frequency=tape->best_dsc_rw_frequency;
3009 idetape_postpone_request (drive);
3010 return;
3011 }
3012
3013 pc=idetape_next_pc_storage (drive);
3014
3015 idetape_create_read_cmd (pc,rq->current_nr_sectors);
3016
3017 pc->buffer=rq->buffer;
3018 pc->buffer_size=rq->current_nr_sectors*tape->tape_block_size;
3019 pc->current_position=rq->buffer;
3020 pc->request_transfer=rq->current_nr_sectors*tape->tape_block_size;
3021
3022 idetape_issue_packet_command (drive,pc,&idetape_pc_intr);
3023 return;
3024
3025 case IDETAPE_WRITE_REQUEST:
3026 if (!status.b.dsc) {
3027 #if IDETAPE_DEBUG_LOG
3028 printk ("ide-tape: DSC != 1 - Postponing write request\n");
3029 #endif
3030 tape->dsc_polling_frequency=tape->best_dsc_rw_frequency;
3031 idetape_postpone_request (drive);
3032 return;
3033 }
3034
3035 pc=idetape_next_pc_storage (drive);
3036
3037 idetape_create_write_cmd (pc,rq->current_nr_sectors);
3038
3039 pc->buffer=rq->buffer;
3040 pc->buffer_size=rq->current_nr_sectors*tape->tape_block_size;
3041 pc->current_position=rq->buffer;
3042 pc->request_transfer=rq->current_nr_sectors*tape->tape_block_size;
3043
3044 idetape_issue_packet_command (drive,pc,&idetape_pc_intr);
3045 return;
3046
3047 case IDETAPE_PACKET_COMMAND_REQUEST_TYPE1:
3048 case IDETAPE_PACKET_COMMAND_REQUEST_TYPE2:
3049
3050
3051
3052
3053
3054 if (!status.b.dsc) {
3055 #if IDETAPE_DEBUG_LOG
3056 printk ("ide-tape: DSC != 1 - Postponing packet command request\n");
3057 #endif
3058 rq->cmd=IDETAPE_PACKET_COMMAND_REQUEST_TYPE2;
3059
3060 tape->dsc_polling_frequency=IDETAPE_DSC_READ_WRITE_FALLBACK_FREQUENCY;
3061 idetape_postpone_request (drive);
3062 return;
3063 }
3064 rq->cmd=IDETAPE_PACKET_COMMAND_REQUEST_TYPE1;
3065 pc=(idetape_packet_command_t *) rq->buffer;
3066 idetape_issue_packet_command (drive,pc,&idetape_pc_intr);
3067 return;
3068 #if IDETAPE_DEBUG_BUGS
3069 default:
3070 printk ("ide-tape: bug in IDETAPE_REQUEST_CMD macro\n");
3071 idetape_end_request (0,HWGROUP (drive));
3072 #endif
3073 }
3074 }
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097 int idetape_queue_pc_tail (ide_drive_t *drive,idetape_packet_command_t *pc)
3098 {
3099 struct request rq;
3100
3101 ide_init_drive_cmd (&rq);
3102 rq.buffer = (char *) pc;
3103 rq.cmd = IDETAPE_PACKET_COMMAND_REQUEST_TYPE1;
3104 return ide_do_drive_cmd (drive, &rq, ide_wait);
3105 }
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127 void idetape_queue_pc_head (ide_drive_t *drive,idetape_packet_command_t *pc,struct request *rq)
3128
3129 {
3130 unsigned int major = HWIF(drive)->major;
3131 struct blk_dev_struct *bdev = &blk_dev[major];
3132
3133 bdev->current_request=HWGROUP (drive)->rq;
3134
3135 ide_init_drive_cmd (rq);
3136 rq->buffer = (char *) pc;
3137 rq->cmd = IDETAPE_PACKET_COMMAND_REQUEST_TYPE1;
3138 (void) ide_do_drive_cmd (drive, rq, ide_preempt);
3139 }
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149 void idetape_wait_for_request (struct request *rq)
3150
3151 {
3152 struct semaphore sem = MUTEX_LOCKED;
3153
3154 #if IDETAPE_DEBUG_BUGS
3155 if (rq == NULL || !IDETAPE_REQUEST_CMD (rq->cmd)) {
3156 printk ("ide-tape: bug: Trying to sleep on non-valid request\n");
3157 return;
3158 }
3159 #endif
3160
3161 rq->sem=&sem;
3162 down (&sem);
3163 }
3164
3165
3166
3167
3168
3169
3170 int idetape_queue_rw_tail (ide_drive_t *drive,int cmd,int blocks,char *buffer)
3171
3172 {
3173 idetape_tape_t *tape = &(drive->tape);
3174 struct request rq;
3175
3176 #if IDETAPE_DEBUG_LOG
3177 printk ("idetape_queue_rw_tail: cmd=%d\n",cmd);
3178 #endif
3179 #if IDETAPE_DEBUG_BUGS
3180 if (tape->active_data_request != NULL) {
3181 printk ("ide-tape: bug: the pipeline is active in idetape_queue_rw_tail\n");
3182 return (0);
3183 }
3184 #endif
3185
3186 ide_init_drive_cmd (&rq);
3187 rq.buffer = buffer;
3188 rq.cmd = cmd;
3189 rq.sector = tape->block_address;
3190 rq.nr_sectors = rq.current_nr_sectors = blocks;
3191 (void) ide_do_drive_cmd (drive, &rq, ide_wait);
3192
3193 return (tape->tape_block_size*(blocks-rq.current_nr_sectors));
3194 }
3195
3196
3197
3198
3199
3200
3201 int idetape_add_chrdev_read_request (ide_drive_t *drive,int blocks,char *buffer)
3202
3203 {
3204 idetape_tape_t *tape = &(drive->tape);
3205 idetape_pipeline_stage_t *new_stage;
3206 unsigned long flags;
3207 struct request rq,*rq_ptr;
3208 int bytes_read;
3209
3210 #if IDETAPE_DEBUG_LOG
3211 printk ("Reached idetape_add_chrdev_read_request\n");
3212 #endif
3213
3214 ide_init_drive_cmd (&rq);
3215 rq.cmd = IDETAPE_READ_REQUEST;
3216 rq.sector = tape->block_address;
3217 rq.nr_sectors = rq.current_nr_sectors = blocks;
3218
3219 if (tape->active_data_request != NULL || tape->current_number_of_stages <= 0.25*tape->max_number_of_stages) {
3220 new_stage=idetape_kmalloc_stage (drive);
3221 while (new_stage != NULL) {
3222 new_stage->rq=rq;
3223 save_flags (flags);cli ();
3224 idetape_add_stage_tail (drive,new_stage);
3225 restore_flags (flags);
3226 new_stage=idetape_kmalloc_stage (drive);
3227 }
3228 if (tape->active_data_request == NULL)
3229 idetape_insert_pipeline_into_queue (drive);
3230 }
3231
3232 if (tape->first_stage == NULL) {
3233
3234
3235
3236
3237
3238
3239 return (idetape_queue_rw_tail (drive,IDETAPE_READ_REQUEST,blocks,buffer));
3240 }
3241
3242 save_flags (flags);cli ();
3243 if (tape->active_data_request == &(tape->first_stage->rq))
3244 idetape_wait_for_request (tape->active_data_request);
3245 restore_flags (flags);
3246
3247 rq_ptr=&(tape->first_stage->rq);
3248 bytes_read=tape->tape_block_size*(rq_ptr->nr_sectors-rq_ptr->current_nr_sectors);
3249 rq_ptr->nr_sectors=rq_ptr->current_nr_sectors=0;
3250 idetape_copy_buffer_from_stage (tape->first_stage,buffer);
3251 if (rq_ptr->errors != IDETAPE_RQ_ERROR_FILEMARK)
3252 idetape_remove_stage_head (drive);
3253 #if IDETAPE_DEBUG_BUGS
3254 if (bytes_read > blocks*tape->tape_block_size) {
3255 printk ("ide-tape: bug: trying to return more bytes than requested\n");
3256 bytes_read=blocks*tape->tape_block_size;
3257 }
3258 #endif
3259 return (bytes_read);
3260 }
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274 int idetape_add_chrdev_write_request (ide_drive_t *drive,int blocks,char *buffer)
3275
3276 {
3277 idetape_tape_t *tape = &(drive->tape);
3278 idetape_pipeline_stage_t *new_stage;
3279 unsigned long flags;
3280 struct request *rq;
3281
3282 #if IDETAPE_DEBUG_LOG
3283 printk ("Reached idetape_add_chrdev_write_request\n");
3284 #endif
3285
3286
3287 new_stage=idetape_kmalloc_stage (drive);
3288
3289
3290
3291
3292
3293
3294
3295
3296 while (new_stage == NULL) {
3297 save_flags (flags);cli ();
3298 if (tape->active_data_request != NULL) {
3299 idetape_wait_for_request (tape->active_data_request);
3300 restore_flags (flags);
3301 new_stage=idetape_kmalloc_stage (drive);
3302 }
3303 else {
3304
3305
3306
3307
3308
3309 restore_flags (flags);
3310 return (idetape_queue_rw_tail (drive,IDETAPE_WRITE_REQUEST,blocks,buffer));
3311 }
3312 }
3313
3314 rq=&(new_stage->rq);
3315
3316 ide_init_drive_cmd (rq);
3317 rq->cmd = IDETAPE_WRITE_REQUEST;
3318 rq->sector = tape->block_address;
3319 rq->nr_sectors = blocks;
3320 rq->current_nr_sectors = blocks;
3321
3322 idetape_copy_buffer_to_stage (new_stage,buffer);
3323
3324 save_flags (flags);cli ();
3325 idetape_add_stage_tail (drive,new_stage);
3326 restore_flags (flags);
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337 if (tape->active_data_request == NULL && tape->current_number_of_stages >= 0.75*tape->max_number_of_stages)
3338 idetape_insert_pipeline_into_queue (drive);
3339
3340 if (tape->error_in_pipeline_stage) {
3341 tape->error_in_pipeline_stage=0;
3342 return (-EIO);
3343 }
3344
3345 return (blocks);
3346 }
3347
3348 void idetape_discard_read_pipeline (ide_drive_t *drive)
3349
3350 {
3351 idetape_tape_t *tape = &(drive->tape);
3352 unsigned long flags;
3353
3354 #if IDETAPE_DEBUG_BUGS
3355 if (tape->chrdev_direction != idetape_direction_read) {
3356 printk ("ide-tape: bug: Trying to discard read pipeline, but we are not reading.\n");
3357 return;
3358 }
3359 #endif
3360
3361 tape->merge_buffer_size=tape->merge_buffer_offset=0;
3362 tape->chrdev_direction=idetape_direction_none;
3363
3364 if (tape->first_stage == NULL)
3365 return;
3366
3367 save_flags (flags);cli ();
3368 tape->next_stage=NULL;
3369 if (tape->active_data_request != NULL)
3370 idetape_wait_for_request (tape->active_data_request);
3371 restore_flags (flags);
3372
3373 while (tape->first_stage != NULL)
3374 idetape_remove_stage_head (drive);
3375
3376 #if IDETAPE_PIPELINE
3377 tape->max_number_of_stages=IDETAPE_MIN_PIPELINE_STAGES;
3378 #else
3379 tape->max_number_of_stages=0;
3380 #endif
3381 }
3382
3383
3384
3385
3386
3387
3388 void idetape_wait_for_pipeline (ide_drive_t *drive)
3389
3390 {
3391 idetape_tape_t *tape = &(drive->tape);
3392 unsigned long flags;
3393
3394 if (tape->active_data_request == NULL)
3395 idetape_insert_pipeline_into_queue (drive);
3396
3397 save_flags (flags);cli ();
3398 if (tape->active_data_request == NULL) {
3399 restore_flags (flags);
3400 return;
3401 }
3402
3403 if (tape->last_stage != NULL)
3404 idetape_wait_for_request (&(tape->last_stage->rq));
3405
3406 else if (tape->active_data_request != NULL)
3407 idetape_wait_for_request (tape->active_data_request);
3408 restore_flags (flags);
3409 }
3410
3411 void idetape_empty_write_pipeline (ide_drive_t *drive)
3412
3413 {
3414 idetape_tape_t *tape = &(drive->tape);
3415 int blocks;
3416
3417 #if IDETAPE_DEBUG_BUGS
3418 if (tape->chrdev_direction != idetape_direction_write) {
3419 printk ("ide-tape: bug: Trying to empty write pipeline, but we are not writing.\n");
3420 return;
3421 }
3422 if (tape->merge_buffer_size > tape->data_buffer_size) {
3423 printk ("ide-tape: bug: merge_buffer too big\n");
3424 tape->merge_buffer_size = tape->data_buffer_size;
3425 }
3426 #endif
3427
3428 if (tape->merge_buffer_size) {
3429 blocks=tape->merge_buffer_size/tape->tape_block_size;
3430 if (tape->merge_buffer_size % tape->tape_block_size) {
3431 blocks++;
3432 memset (tape->merge_buffer+tape->merge_buffer_size,0,tape->data_buffer_size-tape->merge_buffer_size);
3433 }
3434 (void) idetape_add_chrdev_write_request (drive,blocks,tape->merge_buffer);
3435 tape->merge_buffer_size=0;
3436 }
3437
3438 idetape_wait_for_pipeline (drive);
3439
3440 tape->error_in_pipeline_stage=0;
3441 tape->chrdev_direction=idetape_direction_none;
3442
3443
3444
3445
3446
3447
3448
3449
3450 #if IDETAPE_PIPELINE
3451 tape->max_number_of_stages=IDETAPE_MIN_PIPELINE_STAGES;
3452 #else
3453 tape->max_number_of_stages=0;
3454 #endif
3455 #if IDETAPE_DEBUG_BUGS
3456 if (tape->first_stage != NULL || tape->next_stage != NULL || tape->last_stage != NULL || tape->current_number_of_stages != 0) {
3457 printk ("ide-tape: ide-tape pipeline bug\n");
3458 }
3459 #endif
3460 }
3461
3462
3463
3464
3465
3466
3467 void idetape_zero_packet_command (idetape_packet_command_t *pc)
3468
3469 {
3470 int i;
3471
3472 for (i=0;i<12;i++)
3473 pc->c[i]=0;
3474 pc->retries=0;
3475 pc->abort=0;
3476 pc->dma_recommended=0;
3477 pc->dma_error=0;
3478 }
3479
3480
3481
3482
3483
3484
3485 unsigned short idetape_swap_short (unsigned short temp)
3486
3487 {
3488 union convert {
3489 unsigned all :16;
3490 struct {
3491 unsigned b1 :8;
3492 unsigned b2 :8;
3493 } b;
3494 } original,converted;
3495
3496 original.all=temp;
3497 converted.b.b1=original.b.b2;
3498 converted.b.b2=original.b.b1;
3499 return (converted.all);
3500 }
3501
3502
3503
3504
3505
3506 unsigned long idetape_swap_long (unsigned long temp)
3507
3508 {
3509 union convert {
3510 unsigned all :32;
3511 struct {
3512 unsigned b1 :8;
3513 unsigned b2 :8;
3514 unsigned b3 :8;
3515 unsigned b4 :8;
3516 } b;
3517 } original,converted;
3518
3519 original.all=temp;
3520 converted.b.b1=original.b.b4;
3521 converted.b.b2=original.b.b3;
3522 converted.b.b3=original.b.b2;
3523 converted.b.b4=original.b.b1;
3524 return (converted.all);
3525 }
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535 idetape_packet_command_t *idetape_next_pc_storage (ide_drive_t *drive)
3536
3537 {
3538 idetape_tape_t *tape;
3539
3540 tape=&(drive->tape);
3541 #if IDETAPE_DEBUG_LOG
3542 printk ("ide-tape: pc_stack_index=%d\n",tape->pc_stack_index);
3543 #endif
3544 if (tape->pc_stack_index==IDETAPE_PC_STACK)
3545 tape->pc_stack_index=0;
3546 return (&(tape->pc_stack [tape->pc_stack_index++]));
3547 }
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562 struct request *idetape_next_rq_storage (ide_drive_t *drive)
3563
3564 {
3565 idetape_tape_t *tape;
3566
3567 tape=&(drive->tape);
3568
3569 #if IDETAPE_DEBUG_LOG
3570 printk ("ide-tape: rq_stack_index=%d\n",tape->rq_stack_index);
3571 #endif
3572 if (tape->rq_stack_index==IDETAPE_PC_STACK)
3573 tape->rq_stack_index=0;
3574 return (&(tape->rq_stack [tape->rq_stack_index++]));
3575 }
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585 int idetape_blkdev_open (struct inode *inode, struct file *filp, ide_drive_t *drive)
3586
3587 {
3588 idetape_tape_t *tape=&(drive->tape);
3589 unsigned long flags;
3590
3591 save_flags (flags);cli ();
3592
3593 #if IDETAPE_DEBUG_LOG
3594 printk ("Reached idetape_blkdev_open\n");
3595 #endif
3596
3597 if (tape->busy) {
3598 restore_flags (flags);
3599 return (-EBUSY);
3600 }
3601
3602 tape->busy=1;
3603 restore_flags (flags);
3604
3605 return (0);
3606 }
3607
3608 void idetape_blkdev_release (struct inode *inode, struct file *filp, ide_drive_t *drive)
3609
3610 {
3611 idetape_tape_t *tape=&(drive->tape);
3612 unsigned long flags;
3613
3614 #if IDETAPE_DEBUG_LOG
3615 printk ("Reached idetape_blkdev_release\n");
3616 #endif
3617
3618 save_flags (flags);cli ();
3619 tape->busy=0;
3620 restore_flags (flags);
3621
3622 return;
3623 }
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 int idetape_chrdev_read (struct inode *inode, struct file *file, char *buf, int count)
3650
3651 {
3652 ide_drive_t *drive=idetape_chrdev.drive;
3653 idetape_tape_t *tape=&(drive->tape);
3654 char *buf_ptr=buf;
3655 int bytes_read,temp,actually_read=0;
3656
3657 #if IDETAPE_DEBUG_LOG
3658 printk ("Reached idetape_chrdev_read\n");
3659 #endif
3660
3661 if (tape->chrdev_direction != idetape_direction_read) {
3662 if (tape->chrdev_direction == idetape_direction_write) {
3663 idetape_empty_write_pipeline (drive);
3664 idetape_flush_tape_buffers (drive);
3665 }
3666
3667
3668
3669
3670
3671
3672
3673 bytes_read=idetape_queue_rw_tail (drive,IDETAPE_READ_REQUEST,0,tape->merge_buffer);
3674 if (bytes_read < 0)
3675 return (bytes_read);
3676
3677 tape->chrdev_direction=idetape_direction_read;
3678 }
3679
3680 if (count==0)
3681 return (0);
3682
3683 if (tape->merge_buffer_size) {
3684 #if IDETAPE_DEBUG_BUGS
3685 if (tape->merge_buffer_offset+tape->merge_buffer_size > tape->data_buffer_size) {
3686 printk ("ide-tape: bug: merge buffer too big\n");
3687 tape->merge_buffer_offset=0;tape->merge_buffer_size=tape->data_buffer_size-1;
3688 }
3689 #endif
3690 actually_read=IDETAPE_MIN (tape->merge_buffer_size,count);
3691 memcpy_tofs (buf_ptr,tape->merge_buffer+tape->merge_buffer_offset,actually_read);
3692 buf_ptr+=actually_read;tape->merge_buffer_size-=actually_read;
3693 count-=actually_read;tape->merge_buffer_offset+=actually_read;
3694 }
3695
3696 while (count >= tape->data_buffer_size) {
3697 bytes_read=idetape_add_chrdev_read_request (drive,tape->capabilities.ctl,tape->merge_buffer);
3698 if (bytes_read <= 0)
3699 return (actually_read);
3700 memcpy_tofs (buf_ptr,tape->merge_buffer,bytes_read);
3701 buf_ptr+=bytes_read;count-=bytes_read;actually_read+=bytes_read;
3702 }
3703
3704 if (count) {
3705 bytes_read=idetape_add_chrdev_read_request (drive,tape->capabilities.ctl,tape->merge_buffer);
3706 if (bytes_read <= 0)
3707 return (actually_read);
3708 temp=IDETAPE_MIN (count,bytes_read);
3709 memcpy_tofs (buf_ptr,tape->merge_buffer,temp);
3710 actually_read+=temp;
3711 tape->merge_buffer_offset=temp;
3712 tape->merge_buffer_size=bytes_read-temp;
3713 }
3714 return (actually_read);
3715 }
3716
3717 int idetape_chrdev_write (struct inode *inode, struct file *file, const char *buf, int count)
3718
3719 {
3720 ide_drive_t *drive=idetape_chrdev.drive;
3721 idetape_tape_t *tape=&(drive->tape);
3722 const char *buf_ptr=buf;
3723 int retval,actually_written=0;
3724
3725 #if IDETAPE_DEBUG_LOG
3726 printk ("Reached idetape_chrdev_write\n");
3727 #endif
3728
3729 if (tape->chrdev_direction != idetape_direction_write) {
3730 if (tape->chrdev_direction == idetape_direction_read)
3731 idetape_discard_read_pipeline (drive);
3732
3733
3734
3735
3736
3737
3738
3739 retval=idetape_queue_rw_tail (drive,IDETAPE_WRITE_REQUEST,0,tape->merge_buffer);
3740 if (retval < 0)
3741 return (retval);
3742
3743 tape->chrdev_direction=idetape_direction_write;
3744 }
3745
3746 if (count==0)
3747 return (0);
3748
3749 if (tape->merge_buffer_size) {
3750 #if IDETAPE_DEBUG_BUGS
3751 if (tape->merge_buffer_size >= tape->data_buffer_size) {
3752 printk ("ide-tape: bug: merge buffer too big\n");
3753 tape->merge_buffer_size=0;
3754 }
3755 #endif
3756
3757 actually_written=IDETAPE_MIN (tape->data_buffer_size-tape->merge_buffer_size,count);
3758 memcpy_fromfs (tape->merge_buffer+tape->merge_buffer_size,buf_ptr,actually_written);
3759 buf_ptr+=actually_written;tape->merge_buffer_size+=actually_written;count-=actually_written;
3760
3761 if (tape->merge_buffer_size == tape->data_buffer_size) {
3762 tape->merge_buffer_size=0;
3763 retval=idetape_add_chrdev_write_request (drive,tape->capabilities.ctl,tape->merge_buffer);
3764 if (retval <= 0)
3765 return (retval);
3766 }
3767 }
3768
3769 while (count >= tape->data_buffer_size) {
3770 memcpy_fromfs (tape->merge_buffer,buf_ptr,tape->data_buffer_size);
3771 buf_ptr+=tape->data_buffer_size;count-=tape->data_buffer_size;
3772 retval=idetape_add_chrdev_write_request (drive,tape->capabilities.ctl,tape->merge_buffer);
3773 actually_written+=tape->data_buffer_size;
3774 if (retval <= 0)
3775 return (retval);
3776 }
3777
3778 if (count) {
3779 actually_written+=count;
3780 memcpy_fromfs (tape->merge_buffer,buf_ptr,count);
3781 tape->merge_buffer_size+=count;
3782 }
3783 return (actually_written);
3784 }
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817 int idetape_chrdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
3818
3819 {
3820 ide_drive_t *drive=idetape_chrdev.drive;
3821 idetape_tape_t *tape=&(drive->tape);
3822 idetape_packet_command_t pc;
3823 struct mtop mtop;
3824 struct mtget mtget;
3825 struct mtpos mtpos;
3826 int retval;
3827
3828 #if IDETAPE_DEBUG_LOG
3829 printk ("Reached idetape_chrdev_ioctl, cmd=%u\n",cmd);
3830 #endif
3831
3832 if (tape->chrdev_direction == idetape_direction_write) {
3833 idetape_empty_write_pipeline (drive);
3834 idetape_flush_tape_buffers (drive);
3835 }
3836
3837 if (tape->chrdev_direction == idetape_direction_read && cmd != MTIOCTOP)
3838 idetape_discard_read_pipeline (drive);
3839
3840 pc.buffer=pc.temp_buffer;
3841 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
3842 pc.current_position=pc.temp_buffer;
3843
3844 switch (cmd) {
3845 case MTIOCTOP:
3846 retval=verify_area (VERIFY_READ,(char *) arg,sizeof (struct mtop));
3847 if (retval) return (retval);
3848 memcpy_fromfs ((char *) &mtop, (char *) arg, sizeof (struct mtop));
3849 return (idetape_mtioctop (drive,mtop.mt_op,mtop.mt_count));
3850 case MTIOCGET:
3851 mtget.mt_dsreg=(tape->data_buffer_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;
3852 retval=verify_area (VERIFY_WRITE,(char *) arg,sizeof (struct mtget));
3853 if (retval) return (retval);
3854 memcpy_tofs ((char *) arg,(char *) &mtget, sizeof (struct mtget));
3855 return (0);
3856 case MTIOCPOS:
3857 idetape_create_read_position_cmd (&pc);
3858 retval=idetape_queue_pc_tail (drive,&pc);
3859 if (retval) return (retval);
3860 mtpos.mt_blkno=tape->block_address;
3861 retval=verify_area (VERIFY_WRITE,(char *) arg,sizeof (struct mtpos));
3862 if (retval) return (retval);
3863 memcpy_tofs ((char *) arg,(char *) &mtpos, sizeof (struct mtpos));
3864 return (0);
3865 default:
3866 return (idetape_blkdev_ioctl (drive,inode,file,cmd,arg));
3867 }
3868 }
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923 int idetape_mtioctop (ide_drive_t *drive,short mt_op,int mt_count)
3924
3925 {
3926 idetape_tape_t *tape=&(drive->tape);
3927 idetape_packet_command_t pc;
3928 int i,retval;
3929
3930 pc.buffer=pc.temp_buffer;
3931 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
3932 pc.current_position=pc.temp_buffer;
3933
3934 #if IDETAPE_DEBUG_LOG
3935 printk ("Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n",mt_op,mt_count);
3936 #endif
3937
3938
3939
3940
3941
3942 switch (mt_op) {
3943 case MTFSF:
3944 case MTFSFM:
3945 case MTBSF:
3946 case MTBSFM:
3947 if (!mt_count)
3948 return (0);
3949 return (idetape_space_over_filemarks (drive,mt_op,mt_count));
3950 default:
3951 break;
3952 }
3953
3954
3955
3956
3957
3958 if (tape->chrdev_direction == idetape_direction_read)
3959 idetape_discard_read_pipeline (drive);
3960
3961 switch (mt_op) {
3962 case MTWEOF:
3963 for (i=0;i<mt_count;i++) {
3964 idetape_create_write_filemark_cmd (&pc,1);
3965 retval=idetape_queue_pc_tail (drive,&pc);
3966 if (retval) return (retval);
3967 }
3968 return (0);
3969 case MTREW:
3970 return (idetape_rewind_tape (drive));
3971 case MTOFFL:
3972 idetape_create_load_unload_cmd (&pc,!IDETAPE_LU_LOAD_MASK);
3973 return (idetape_queue_pc_tail (drive,&pc));
3974 case MTNOP:
3975 return (idetape_flush_tape_buffers (drive));
3976 case MTRETEN:
3977 idetape_create_load_unload_cmd (&pc,IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
3978 return (idetape_queue_pc_tail (drive,&pc));
3979 case MTEOM:
3980 idetape_create_space_cmd (&pc,0,IDETAPE_SPACE_TO_EOD);
3981 return (idetape_queue_pc_tail (drive,&pc));
3982 case MTERASE:
3983 retval=idetape_rewind_tape (drive);
3984 if (retval) return (retval);
3985 idetape_create_erase_cmd (&pc);
3986 return (idetape_queue_pc_tail (drive,&pc));
3987 case MTSEEK:
3988 return (idetape_position_tape (drive,mt_count));
3989 default:
3990 printk ("ide-tape: MTIO operation %d not supported\n",mt_op);
3991 return (-EIO);
3992 }
3993 }
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005 int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_count)
4006
4007 {
4008 idetape_tape_t *tape=&(drive->tape);
4009 idetape_packet_command_t pc;
4010 unsigned long flags;
4011 int retval,count=0,errors;
4012
4013 if (tape->chrdev_direction == idetape_direction_read) {
4014
4015
4016
4017
4018
4019
4020 tape->merge_buffer_size=tape->merge_buffer_offset=0;
4021 while (tape->first_stage != NULL) {
4022
4023
4024
4025
4026
4027
4028 save_flags (flags);cli ();
4029 if (tape->active_data_request == &(tape->first_stage->rq))
4030 idetape_wait_for_request (tape->active_data_request);
4031 restore_flags (flags);
4032
4033 errors=tape->first_stage->rq.errors;
4034 if (errors == IDETAPE_RQ_ERROR_FILEMARK)
4035 count++;
4036
4037 if (count == mt_count) {
4038 switch (mt_op) {
4039 case MTFSF:
4040 idetape_remove_stage_head (drive);
4041 case MTFSFM:
4042 return (0);
4043 }
4044 }
4045 idetape_remove_stage_head (drive);
4046 }
4047 idetape_discard_read_pipeline (drive);
4048 }
4049
4050
4051
4052
4053
4054
4055 pc.buffer=pc.temp_buffer;
4056 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
4057 pc.current_position=pc.temp_buffer;
4058
4059 switch (mt_op) {
4060 case MTFSF:
4061 idetape_create_space_cmd (&pc,mt_count-count,IDETAPE_SPACE_OVER_FILEMARK);
4062 return (idetape_queue_pc_tail (drive,&pc));
4063 case MTFSFM:
4064 if (!tape->capabilities.sprev)
4065 return (-EIO);
4066 retval=idetape_mtioctop (drive,MTFSF,mt_count-count);
4067 if (retval) return (retval);
4068 return (idetape_mtioctop (drive,MTBSF,1));
4069 case MTBSF:
4070 if (!tape->capabilities.sprev)
4071 return (-EIO);
4072 idetape_create_space_cmd (&pc,-(mt_count+count),IDETAPE_SPACE_OVER_FILEMARK);
4073 return (idetape_queue_pc_tail (drive,&pc));
4074 case MTBSFM:
4075 if (!tape->capabilities.sprev)
4076 return (-EIO);
4077 retval=idetape_mtioctop (drive,MTBSF,mt_count+count);
4078 if (retval) return (retval);
4079 return (idetape_mtioctop (drive,MTFSF,1));
4080 default:
4081 printk ("ide-tape: MTIO operation %d not supported\n",mt_op);
4082 return (-EIO);
4083 }
4084 }
4085
4086
4087
4088
4089
4090 int idetape_chrdev_open (struct inode *inode, struct file *filp)
4091
4092 {
4093 ide_drive_t *drive=idetape_chrdev.drive;
4094 idetape_tape_t *tape=&(drive->tape);
4095 unsigned long flags;
4096 unsigned int minor=MINOR (inode->i_rdev),allocation_length;
4097
4098 save_flags (flags);cli ();
4099
4100 #if IDETAPE_DEBUG_LOG
4101 printk ("Reached idetape_chrdev_open\n");
4102 #endif
4103
4104 if (minor!=0 && minor!=128) {
4105 restore_flags (flags);
4106 return (-ENXIO);
4107 }
4108
4109 if (tape->busy) {
4110 restore_flags (flags);
4111 return (-EBUSY);
4112 }
4113
4114 tape->busy=1;
4115 restore_flags (flags);
4116
4117 allocation_length=tape->data_buffer_size;
4118 if (tape->data_buffer_size % IDETAPE_ALLOCATION_BLOCK)
4119 allocation_length+=IDETAPE_ALLOCATION_BLOCK;
4120
4121 #if IDETAPE_MINIMIZE_IDLE_MEMORY_USAGE
4122 if (tape->data_buffer == NULL)
4123 tape->data_buffer=kmalloc (allocation_length,GFP_KERNEL);
4124 if (tape->data_buffer == NULL)
4125 goto sorry;
4126 if (tape->merge_buffer == NULL)
4127 tape->merge_buffer=kmalloc (allocation_length,GFP_KERNEL);
4128 if (tape->merge_buffer == NULL) {
4129 kfree (tape->data_buffer);
4130 sorry:
4131 printk ("ide-tape: FATAL - Can not allocate continuous buffer of %d bytes\n",allocation_length);
4132 tape->busy=0;
4133 return (-EIO);
4134 }
4135 #endif
4136
4137 if (!tape->block_address_valid) {
4138 if (idetape_rewind_tape (drive)) {
4139 printk ("ide-tape: Rewinding tape failed\n");
4140 tape->busy=0;
4141 return (-EIO);
4142 }
4143 }
4144
4145 return (0);
4146 }
4147
4148
4149
4150
4151
4152 void idetape_chrdev_release (struct inode *inode, struct file *filp)
4153
4154 {
4155 ide_drive_t *drive=idetape_chrdev.drive;
4156 idetape_tape_t *tape=&(drive->tape);
4157 unsigned int minor=MINOR (inode->i_rdev);
4158 idetape_packet_command_t pc;
4159 unsigned long flags;
4160
4161 #if IDETAPE_DEBUG_LOG
4162 printk ("Reached idetape_chrdev_release\n");
4163 #endif
4164
4165 if (tape->chrdev_direction == idetape_direction_write) {
4166 idetape_empty_write_pipeline (drive);
4167 idetape_create_write_filemark_cmd (&pc,1);
4168 if (idetape_queue_pc_tail (drive,&pc))
4169 printk ("ide-tape: Couldn't write a filemark\n");
4170 }
4171
4172 if (tape->chrdev_direction == idetape_direction_read) {
4173 if (minor < 128)
4174 idetape_discard_read_pipeline (drive);
4175 else
4176 idetape_wait_for_pipeline (drive);
4177 }
4178
4179 if (minor < 128)
4180 if (idetape_rewind_tape (drive))
4181 printk ("ide-tape: Rewinding tape failed\n");
4182
4183 #if IDETAPE_MINIMIZE_IDLE_MEMORY_USAGE
4184 kfree (tape->data_buffer);
4185 tape->data_buffer=NULL;
4186 if (!tape->merge_buffer_size) {
4187 kfree (tape->merge_buffer);
4188 tape->merge_buffer=NULL;
4189 }
4190 #endif
4191
4192 save_flags (flags);cli ();
4193 tape->busy=0;
4194 restore_flags (flags);
4195
4196 return;
4197 }
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209 int idetape_position_tape (ide_drive_t *drive,unsigned long block)
4210
4211 {
4212 int retval;
4213 idetape_packet_command_t pc;
4214
4215 idetape_create_locate_cmd (&pc,block,0);
4216 retval=idetape_queue_pc_tail (drive,&pc);
4217 if (retval!=0) return (retval);
4218
4219 idetape_create_read_position_cmd (&pc);
4220 pc.buffer=pc.temp_buffer;
4221 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
4222 pc.current_position=pc.temp_buffer;
4223 return (idetape_queue_pc_tail (drive,&pc));
4224 }
4225
4226
4227
4228
4229
4230
4231
4232 int idetape_rewind_tape (ide_drive_t *drive)
4233
4234 {
4235 int retval;
4236 idetape_packet_command_t pc;
4237 #if IDETAPE_DEBUG_LOG
4238 printk ("Reached idetape_rewind_tape\n");
4239 #endif
4240
4241 idetape_create_rewind_cmd (&pc);
4242 retval=idetape_queue_pc_tail (drive,&pc);
4243 if (retval) return (retval);
4244
4245 idetape_create_read_position_cmd (&pc);
4246 pc.buffer=pc.temp_buffer;
4247 pc.buffer_size=IDETAPE_TEMP_BUFFER_SIZE;
4248 pc.current_position=pc.temp_buffer;
4249 return (idetape_queue_pc_tail (drive,&pc));
4250 }
4251
4252 int idetape_flush_tape_buffers (ide_drive_t *drive)
4253
4254 {
4255 idetape_packet_command_t pc;
4256
4257 idetape_create_write_filemark_cmd (&pc,0);
4258 return (idetape_queue_pc_tail (drive,&pc));
4259 }
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279 idetape_pipeline_stage_t *idetape_kmalloc_stage (ide_drive_t *drive)
4280
4281 {
4282 idetape_tape_t *tape=&(drive->tape);
4283 idetape_pipeline_stage_t *new_stage;
4284 idetape_buffer_head_t *prev_bh,*bh;
4285 int buffers_num,i;
4286
4287 #if IDETAPE_DEBUG_LOG
4288 printk ("Reached idetape_kmalloc_stage\n");
4289 #endif
4290
4291 if (tape->current_number_of_stages>=tape->max_number_of_stages) {
4292 return (NULL);
4293 }
4294
4295 new_stage=(idetape_pipeline_stage_t *) kmalloc (sizeof (idetape_pipeline_stage_t),GFP_KERNEL);
4296 if (new_stage==NULL)
4297 return (NULL);
4298
4299 new_stage->next=new_stage->prev=NULL;
4300
4301 buffers_num=tape->data_buffer_size / IDETAPE_ALLOCATION_BLOCK;
4302 if (tape->data_buffer_size % IDETAPE_ALLOCATION_BLOCK)
4303 buffers_num++;
4304
4305 prev_bh=new_stage->bh=(idetape_buffer_head_t *) kmalloc (sizeof (idetape_buffer_head_t),GFP_KERNEL);
4306 if (new_stage->bh==NULL) {
4307 idetape_kfree_stage (new_stage);
4308 return (NULL);
4309 }
4310 new_stage->bh->next=NULL;
4311
4312 new_stage->bh->data=kmalloc (IDETAPE_ALLOCATION_BLOCK,GFP_KERNEL);
4313 if (new_stage->bh->data==NULL) {
4314 idetape_kfree_stage (new_stage);
4315 return (NULL);
4316 }
4317
4318 for (i=1;i<buffers_num;i++) {
4319 bh=(idetape_buffer_head_t *) kmalloc (sizeof (idetape_buffer_head_t),GFP_KERNEL);
4320 if (bh==NULL) {
4321 idetape_kfree_stage (new_stage);
4322 return (NULL);
4323 }
4324 bh->next=NULL;
4325 prev_bh->next=bh;
4326 bh->data=kmalloc (IDETAPE_ALLOCATION_BLOCK,GFP_KERNEL);
4327 if (bh->data == NULL) {
4328 idetape_kfree_stage (new_stage);
4329 return (NULL);
4330 }
4331 prev_bh=bh;
4332 }
4333 return (new_stage);
4334 }
4335
4336
4337
4338
4339
4340
4341 void idetape_kfree_stage (idetape_pipeline_stage_t *stage)
4342
4343 {
4344 idetape_buffer_head_t *prev_bh,*bh;
4345
4346 if (stage == NULL)
4347 return;
4348
4349 #if IDETAPE_DEBUG_LOG
4350 printk ("Reached idetape_kfree_stage\n");
4351 #endif
4352
4353 bh=stage->bh;
4354
4355 while (bh != NULL) {
4356 prev_bh=bh;
4357 if (bh->data != NULL)
4358 kfree (bh->data);
4359 bh=bh->next;
4360 kfree (prev_bh);
4361 }
4362
4363 kfree (stage);
4364 return;
4365 }
4366
4367
4368
4369
4370
4371
4372 void idetape_copy_buffer_from_stage (idetape_pipeline_stage_t *stage,char *buffer)
4373
4374 {
4375 idetape_buffer_head_t *bh;
4376 char *ptr;
4377
4378 #if IDETAPE_DEBUG_LOG
4379 printk ("Reached idetape_copy_buffer_from_stage\n");
4380 #endif
4381 #if IDETAPE_DEBUG_BUGS
4382 if (buffer == NULL) {
4383 printk ("ide-tape: bug: buffer is null in copy_buffer_from_stage\n");
4384 return;
4385 }
4386 #endif
4387
4388 ptr=buffer;
4389 bh=stage->bh;
4390
4391 while (bh != NULL) {
4392 #if IDETAPE_DEBUG_BUGS
4393 if (bh->data == NULL) {
4394 printk ("ide-tape: bug: bh->data is null\n");
4395 return;
4396 }
4397 #endif
4398 memcpy (ptr,bh->data,IDETAPE_ALLOCATION_BLOCK);
4399 bh=bh->next;
4400 ptr=ptr+IDETAPE_ALLOCATION_BLOCK;
4401 }
4402 return;
4403 }
4404
4405
4406
4407
4408
4409
4410 void idetape_copy_buffer_to_stage (idetape_pipeline_stage_t *stage,char *buffer)
4411
4412 {
4413 idetape_buffer_head_t *bh;
4414 char *ptr;
4415
4416 #if IDETAPE_DEBUG_LOG
4417 printk ("Reached idetape_copy_buffer_to_stage\n");
4418 #endif
4419 #if IDETAPE_DEBUG_BUGS
4420 if (buffer == NULL) {
4421 printk ("ide-tape: bug: buffer is null in copy_buffer_to_stage\n");
4422 return;
4423 }
4424 #endif
4425
4426 ptr=buffer;
4427 bh=stage->bh;
4428
4429 while (bh != NULL) {
4430 #if IDETAPE_DEBUG_BUGS
4431 if (bh->data == NULL) {
4432 printk ("ide-tape: bug: bh->data is null\n");
4433 return;
4434 }
4435 #endif
4436 memcpy (bh->data,ptr,IDETAPE_ALLOCATION_BLOCK);
4437 bh=bh->next;
4438 ptr=ptr+IDETAPE_ALLOCATION_BLOCK;
4439 }
4440 return;
4441 }
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451 void idetape_increase_max_pipeline_stages (ide_drive_t *drive)
4452
4453 {
4454 idetape_tape_t *tape=&(drive->tape);
4455
4456 #if IDETAPE_DEBUG_LOG
4457 printk ("Reached idetape_increase_max_pipeline_stages\n");
4458 #endif
4459
4460 tape->max_number_of_stages+=IDETAPE_INCREASE_STAGES_RATE*
4461 (IDETAPE_MAX_PIPELINE_STAGES-IDETAPE_MIN_PIPELINE_STAGES);
4462
4463 if (tape->max_number_of_stages >= IDETAPE_MAX_PIPELINE_STAGES)
4464 tape->max_number_of_stages = IDETAPE_MAX_PIPELINE_STAGES;
4465
4466 #if IDETAPE_DEBUG_LOG
4467 printk ("Maximum number of stages: %d\n",tape->max_number_of_stages);
4468 #endif
4469
4470 return;
4471 }
4472
4473
4474
4475
4476
4477
4478
4479 void idetape_add_stage_tail (ide_drive_t *drive,idetape_pipeline_stage_t *stage)
4480
4481 {
4482 idetape_tape_t *tape=&(drive->tape);
4483
4484 #if IDETAPE_DEBUG_LOG
4485 printk ("Reached idetape_add_stage_tail\n");
4486 #endif
4487
4488 stage->next=NULL;
4489 stage->prev=tape->last_stage;
4490 if (tape->last_stage != NULL)
4491 tape->last_stage->next=stage;
4492 else
4493 tape->first_stage=tape->next_stage=stage;
4494 tape->last_stage=stage;
4495 if (tape->next_stage == NULL)
4496 tape->next_stage=tape->last_stage;
4497 tape->current_number_of_stages++;
4498 }
4499
4500
4501
4502
4503
4504
4505
4506 void idetape_remove_stage_head (ide_drive_t *drive)
4507
4508 {
4509 idetape_tape_t *tape=&(drive->tape);
4510 idetape_pipeline_stage_t *stage;
4511
4512 #if IDETAPE_DEBUG_LOG
4513 printk ("Reached idetape_remove_stage_head\n");
4514 #endif
4515 #if IDETAPE_DEBUG_BUGS
4516 if (tape->first_stage == NULL) {
4517 printk ("ide-tape: bug: tape->first_stage is NULL\n");
4518 return;
4519 }
4520 if (tape->active_stage == tape->first_stage) {
4521 printk ("ide-tape: bug: Trying to free our active pipeline stage\n");
4522 return;
4523 }
4524 #endif
4525 stage=tape->first_stage;
4526 tape->first_stage=stage->next;
4527 idetape_kfree_stage (stage);
4528 tape->current_number_of_stages--;
4529 if (tape->first_stage == NULL) {
4530 tape->last_stage=NULL;
4531 #if IDETAPE_DEBUG_BUGS
4532 if (tape->next_stage != NULL)
4533 printk ("ide-tape: bug: tape->next_stage != NULL\n");
4534 if (tape->current_number_of_stages)
4535 printk ("ide-tape: bug: current_number_of_stages should be 0 now\n");
4536 #endif
4537 }
4538 }
4539
4540
4541
4542
4543
4544
4545 void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
4546
4547 {
4548 idetape_tape_t *tape=&(drive->tape);
4549
4550 if (tape->next_stage == NULL)
4551 return;
4552
4553 if (tape->active_data_request == NULL) {
4554 idetape_active_next_stage (drive);
4555 (void) (ide_do_drive_cmd (drive,tape->active_data_request,ide_end));
4556 return;
4557 }
4558 }
4559
4560
4561
4562
4563
4564 void idetape_active_next_stage (ide_drive_t *drive)
4565
4566 {
4567 idetape_tape_t *tape=&(drive->tape);
4568 idetape_pipeline_stage_t *stage=tape->next_stage;
4569 struct request *rq=&(stage->rq);
4570
4571 #if IDETAPE_DEBUG_LOG
4572 printk ("Reached idetape_active_next_stage\n");
4573 #endif
4574 #if IDETAPE_DEBUG_BUGS
4575 if (stage == NULL) {
4576 printk ("ide-tape: bug: Trying to activate a non existing stage\n");
4577 return;
4578 }
4579 #endif
4580 if (rq->cmd == IDETAPE_WRITE_REQUEST)
4581 idetape_copy_buffer_from_stage (stage,tape->data_buffer);
4582
4583 rq->buffer=tape->data_buffer;
4584 tape->active_data_request=rq;
4585 tape->active_stage=stage;
4586 tape->next_stage=stage->next;
4587 }