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