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