/
tapeccws.c
4392 lines (3729 loc) · 167 KB
/
tapeccws.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* TAPECCWS.C (c) Copyright Roger Bowler, 1999-2012 */
/* (c) Copyright TurboHercules, SAS 2011 */
/* Hercules Tape Device Handler CCW Processing */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
/*-------------------------------------------------------------------*/
/* This module contains the CCW handling functions for tape devices. */
/* The subroutines in this module are called by the general tape */
/* device handler (tapedev.c) when the tape format is AWSTAPE. */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Reference information: */
/* SG24-2506 IBM 3590 Tape Subsystem Technical Guide */
/* GA32-0331 IBM 3590 Hardware Reference */
/* GA32-0329 IBM 3590 Introduction and Planning Guide */
/* SG24-2594 IBM 3590 Multiplatform Implementation */
/* ANSI INCITS 131-1994 (R1999) SCSI-2 Reference */
/* GA32-0127 IBM 3490E Hardware Reference */
/* GC35-0152 EREP Release 3.5.0 Reference */
/* SA22-7204 ESA/390 Common I/O-Device Commands */
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
#include "hercules.h" /* need Hercules control blocks */
#include "tapedev.h" /* Main tape handler header file */
//#define ENABLE_TRACING_STMTS 1 // (Fish: DEBUGGING)
//#include "dbgtrace.h" // (Fish: DEBUGGING)
/*-------------------------------------------------------------------*/
/* (forward declarations needed by below tables) */
/*-------------------------------------------------------------------*/
extern BYTE TapeCommands3410 [];
extern BYTE TapeCommands3420 [];
extern BYTE TapeCommands3422 [];
extern BYTE TapeCommands3430 [];
extern BYTE TapeCommands3480 [];
extern BYTE TapeCommands3490 [];
extern BYTE TapeCommands3590 [];
extern BYTE TapeCommands9347 [];
extern TapeSenseFunc build_sense_3410;
extern TapeSenseFunc build_sense_3420;
#define build_sense_3422 build_sense_3420
#define build_sense_3430 build_sense_3420
extern TapeSenseFunc build_sense_3480_etal;
extern TapeSenseFunc build_sense_3490;
extern TapeSenseFunc build_sense_3590;
extern TapeSenseFunc build_sense_Streaming;
/*-------------------------------------------------------------------*/
/* TapeDevtypeList */
/* Format: */
/* */
/* A: Supported Device Type, */
/* B: Command table index, (TapeCommandTable) */
/* C: UC on RewUnld, (1/0 = true/false) */
/* D: CUE on RewUnld, (1/0 = true/false) */
/* E: Sense Build Function table index (TapeSenseTable) */
/* */
/*-------------------------------------------------------------------*/
int TapeDevtypeList [] =
{
/* A B C D E */
0x3410, 0, 1, 0, 0,
0x3411, 0, 1, 0, 0,
0x3420, 1, 1, 1, 1,
0x3422, 2, 0, 0, 2,
0x3430, 3, 0, 0, 3,
0x3480, 4, 0, 0, 4,
0x3490, 5, 0, 0, 5,
0x3590, 6, 0, 0, 6,
0x9347, 7, 0, 0, 7,
0x9348, 7, 0, 0, 7,
0x8809, 7, 0, 0, 7,
0x0000, 0, 0, 0, 0 /* (end of table marker) */
};
/*-------------------------------------------------------------------*/
/* TapeCommandTable */
/* */
/* Specific supported CCW codes for each device type. Index is */
/* fetched by TapeCommandIsValid from "TapeDevtypeList[ n+1 ]". */
/* */
/*-------------------------------------------------------------------*/
BYTE* TapeCommandTable [] =
{
TapeCommands3410, /* 0 3410/3411 */
TapeCommands3420, /* 1 3420 */
TapeCommands3422, /* 2 3422 */
TapeCommands3430, /* 3 3430 */
TapeCommands3480, /* 4 3480 (Maybe all 38K Tapes) */
TapeCommands3490, /* 5 3490 */
TapeCommands3590, /* 6 3590 */
TapeCommands9347, /* 7 9347 (Maybe all streaming tapes) */
NULL
};
/*-------------------------------------------------------------------*/
/* TapeSenseTable */
/* */
/* SENSE function routing table. Index is fetched by 'build_senseX' */
/* function from table entry "TapeDevtypeList[ i+4 ]". */
/*-------------------------------------------------------------------*/
TapeSenseFunc* TapeSenseTable [] =
{
build_sense_3410, /* 0 3410/3411 */
build_sense_3420, /* 1 3420 */
build_sense_3422, /* 2 3422 */
build_sense_3430, /* 3 3430 */
build_sense_3480_etal, /* 4 3480 (Maybe all 38K Tapes) */
build_sense_3490, /* 5 3490 */
build_sense_3590, /* 6 3590 */
build_sense_Streaming, /* 7 9347 (Maybe all streaming tapes) */
NULL
};
/*-------------------------------------------------------------------*/
/* CCW opcode Validity Tables by Device Type */
/*-------------------------------------------------------------------*/
/* */
/* The below tables are used by 'TapeCommandIsValid' to determine */
/* if a CCW code is initially valid or not for the given device. */
/* */
/* 0: Command is NOT valid */
/* * 1: Command is Valid, Tape MUST be loaded */
/* * 2: Command is Valid, Tape NEED NOT be loaded */
/* 3: Command is Valid, But is a NO-OP (return CE+DE now) */
/* 4: Command is Valid, But is a NO-OP (for virtual tapes) */
/* * 5: Command is Valid, Tape MUST be loaded (add DE to status) */
/* */
/* * Note that CCWs codes marked as valid might still get rejected */
/* upon more stringent validity testing done by the actual CCW */
/* processing function itself. */
/* */
/* SOURCES: */
/* */
/* GX20-1850-2 "S/370 Reference Summary" (3410/3411/3420) */
/* GX20-0157-1 "370/XA Reference Summary" (3420/3422/3430/3480) */
/* GA33-1510-0 "S/370 Model 115 FC" (3410/3411) */
/* */
/* Ivan Warren, 2003-02-24 */
/*-------------------------------------------------------------------*/
BYTE TapeCommands3410 [256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
0,1,1,1,2,0,0,5,0,0,0,0,1,0,0,5, /* 00 */
0,0,0,4,0,0,0,1,0,0,0,1,0,0,0,1, /* 10 */
0,0,0,4,0,0,0,1,0,0,0,4,0,0,0,1, /* 20 */
0,0,0,4,0,0,0,1,0,0,0,4,0,0,0,1, /* 30 */
0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0, /* 40 */
0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0, /* 50 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* 60 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* 70 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 80 */
0,0,0,4,0,0,0,1,0,0,0,0,0,0,0,0, /* 90 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* A0 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* B0 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* C0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* D0 */
0,0,0,0,2,0,0,0,0,0,0,3,0,0,0,0, /* E0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* F0 */
};
BYTE TapeCommands3420 [256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
0,1,1,1,2,0,0,5,0,0,0,2,1,0,0,5, /* 00 */
0,0,0,4,0,0,0,1,0,0,0,1,0,0,0,1, /* 10 */
0,0,0,4,0,0,0,1,0,0,0,4,0,0,0,1, /* 20 */
0,0,0,4,0,0,0,1,0,0,0,4,0,0,0,1, /* 30 */
0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0, /* 40 */
0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0, /* 50 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* 60 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* 70 */
0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0, /* 80 */
0,0,0,4,0,0,0,1,0,0,0,0,0,0,0,0, /* 90 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* A0 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* B0 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* C0 */
0,0,0,4,4,0,0,0,0,0,0,0,0,0,0,0, /* D0 */
0,0,0,0,2,0,0,0,0,0,0,3,0,0,0,0, /* E0 */
0,0,0,2,4,0,0,0,0,0,0,0,0,2,0,0 /* F0 */
};
BYTE TapeCommands3422 [256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
0,1,1,1,2,0,0,5,0,0,0,2,1,0,0,5, /* 00 */
0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1, /* 10 */
0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1, /* 20 */
0,0,0,0,0,0,0,1,0,0,0,0,0,0,0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,0,0,0, /* C0 */
0,0,0,4,4,0,0,0,0,0,0,0,0,0,0,0, /* D0 */
0,0,0,0,2,0,0,0,0,0,0,3,0,0,0,0, /* E0 */
0,0,0,2,4,0,0,0,0,0,0,0,0,2,0,0 /* F0 */
};
BYTE TapeCommands3480 [256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
3,1,1,1,2,0,0,5,0,0,0,0,1,0,0,5, /* 00 */
0,0,1,3,0,0,0,1,0,0,0,0,0,0,0,1, /* 10 */
0,0,1,3,2,0,0,1,0,0,0,3,0,0,0,1, /* 20 */
0,0,0,3,2,0,0,1,0,0,0,3,0,0,0,1, /* 30 */
0,0,0,1,0,0,0,0,0,0,0,2,0,0,0,1, /* 40 */
0,0,0,3,0,0,0,0,0,0,0,3,0,0,0,0, /* 50 */
0,0,0,3,2,0,0,0,0,0,0,3,0,0,0,0, /* 60 */
0,0,0,3,0,0,0,2,0,0,0,3,0,0,0,0, /* 70 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 80 */
0,0,0,3,0,0,0,1,0,0,0,0,0,0,0,2, /* 90 */
0,0,0,3,0,0,0,0,0,0,0,3,0,0,0,2, /* A0 */
0,0,0,3,0,0,0,2,0,0,0,3,0,0,0,0, /* B0 */
0,0,0,2,0,0,0,2,0,0,0,3,0,0,0,0, /* C0 */
0,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0, /* D0 */
0,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0, /* E0 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* F0 */
};
BYTE TapeCommands3490 [256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
3,1,1,1,2,0,0,5,0,0,0,0,1,0,0,5, /* 00 */
0,0,1,3,0,0,0,1,0,0,0,0,0,0,0,1, /* 10 */
0,0,1,3,2,0,0,1,0,0,0,3,0,0,0,1, /* 20 */
0,0,0,3,2,0,0,1,0,0,0,3,0,0,2,1, /* 30 */
0,0,0,1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,0,3,0,0,0,0,0,0,0,2,0,0,0,0, /* D0 */
0,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0, /* E0 */
0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0 /* F0 */
};
BYTE TapeCommands9347 [256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
0,1,1,1,2,0,0,5,0,0,0,2,1,0,0,5, /* 00 */
0,0,0,4,0,0,0,1,0,0,0,1,0,0,0,1, /* 10 */
0,0,0,4,0,0,0,1,0,0,0,4,0,0,0,1, /* 20 */
0,0,0,4,0,0,0,1,0,0,0,4,0,0,0,1, /* 30 */
0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0, /* 40 */
0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0, /* 50 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* 60 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* 70 */
0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0, /* 80 */
0,0,0,4,0,0,0,1,0,0,0,0,0,0,0,0, /* 90 */
0,0,0,4,2,0,0,0,0,0,0,4,0,0,0,0, /* A0 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* B0 */
0,0,0,4,0,0,0,0,0,0,0,4,0,0,0,0, /* C0 */
0,0,0,4,4,0,0,0,0,0,0,0,0,0,0,0, /* D0 */
0,0,0,0,2,0,0,0,0,0,0,3,0,0,0,0, /* E0 */
0,0,0,2,4,0,0,0,0,0,0,0,0,2,0,0 /* F0 */
};
/*-------------------------------------------------------------------*/
/* Ivan Warren 20040227 */
/* */
/* This table is used by channel.c to determine if a CCW code */
/* is an immediate command or not. */
/* */
/* The table is addressed in the DEVHND structure as 'DEVIMM immed' */
/* */
/* 0: ("false") Command is *NOT* an immediate command */
/* 1: ("true") Command *IS* an immediate command */
/* */
/* Note: An immediate command is defined as a command which returns */
/* CE (channel end) during initialization (that is, no data is */
/* actually transfered). In this case, IL is not indicated for a */
/* Format 0 or Format 1 CCW when IL Suppression Mode is in effect. */
/* */
/*-------------------------------------------------------------------*/
BYTE TapeImmedCommands [256] =
{
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1, /* 00 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1, /* 10 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1, /* 20 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1, /* 30 */
0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0, /* 40 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1, /* 50 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1, /* 60 */
0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1, /* 70 */ /* Adrian Trenkwalder - 77 was 1 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1, /* 80 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0, /* 90 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0, /* A0 */
0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1, /* B0 */
0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1, /* C0 */
0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1, /* D0 */
0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1, /* E0 */
0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1 /* F0 */
};
/*-------------------------------------------------------------------*/
/* TapeCommandIsValid (Ivan Warren 20030224) */
/*-------------------------------------------------------------------*/
/* */
/* Determine if a CCW code is valid for the Device */
/* */
/* rc 0: is *NOT* valid */
/* rc 1: is Valid, tape MUST be loaded */
/* rc 2: is Valid, tape NEED NOT be loaded */
/* rc 3: is Valid, But is a NO-OP (Return CE+DE now) */
/* rc 4: is Valid, But is a NO-OP for virtual tapes */
/* rc 5: is Valid, Tape Must be loaded - Add DE to status */
/* rc 6: is Valid, Tape load attempted - but not an error */
/* (used for sense and no contingency allegiance exists) */
/* */
/*-------------------------------------------------------------------*/
int TapeCommandIsValid (BYTE code, U16 devtype, BYTE *rustat)
{
int i, rc, tix = 0, devtfound = 0;
/*
** Find the D/T in the table
** If not found, treat as invalid CCW code
*/
*rustat = 0;
for (i = 0; TapeDevtypeList[i] != 0; i += TAPEDEVTYPELIST_ENTRYSIZE)
{
if (TapeDevtypeList[i] == devtype)
{
devtfound = 1;
tix = TapeDevtypeList[i+1];
if (TapeDevtypeList[i+2])
{
*rustat |= CSW_UC;
}
if (TapeDevtypeList[i+3])
{
*rustat |= CSW_CUE;
}
break;
}
}
if (!devtfound)
return 0;
rc = TapeCommandTable[tix][code];
return rc;
} /* end function TapeCommandIsValid */
/*********************************************************************/
/*********************************************************************/
/** **/
/** MAIN TAPE CCW PROCESSING FUNCTION **/
/** **/
/*********************************************************************/
/*********************************************************************/
static TAMDIR* findtamdir( int rej, int minlen, const char* pszDir );
void tapedev_execute_ccw (DEVBLK *dev, BYTE code, BYTE flags,
BYTE chained, U32 count, BYTE prevcode, int ccwseq,
BYTE *iobuf, BYTE *more, BYTE *unitstat, U32 *residual)
{
int rc; /* Return code */
U32 len; /*(see NOTE below)*/ /* Length of data block */
U32 num; /*(see NOTE below)*/ /* Number of bytes to read */
int drc; /* code disposition */
BYTE rustat; /* Addl CSW stat on RewUnld */
UNREFERENCED( ccwseq );
/* PROGRAMMING NOTE: len, num, count, *residual and *more are
used and updated automatically by the RESIDUAL_CALC macro */
/* Reset flags at start of CCW chain */
if (dev->ccwseq == 0)
{
dev->supvr_inhibit = 0; /* (reset to default mode) */
dev->write_immed = 0; /* (reset to default mode) */
dev->tapssdlen = 0; /* (clear all subsys data) */
}
/* If this is a data-chained READ, then return any data remaining
in the buffer which was not used by the previous CCW */
if (chained & CCW_FLAGS_CD)
{
/* Calculate number of bytes to read and residual byte count */
RESIDUAL_CALC (dev->curblkrem);
if (IS_CCW_RDBACK(code))
{
/* We don't need to move anything in this case - just set length */
}
else
{
memcpy (iobuf, dev->buf + dev->curbufoff, num);
}
/* Save size and offset of data not used by this CCW */
dev->curblkrem -= num;
dev->curbufoff += num;
*unitstat = CSW_CE | CSW_DE;
return;
}
/* Command reject if data chaining and command is not a read type */
if ((flags & CCW_FLAGS_CD) &&
!(IS_CCW_READ(code) || IS_CCW_RDBACK(code)))
{
WRMSG(HHC00212, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, TTYPSTR(dev->tapedevt), code);
build_senseX(TAPE_BSENSE_BADCOMMAND,dev,unitstat,code);
return;
}
/* Command reject if command is not Read Subsystem Data command
if the previous one was a Perform Subsystem Function command
that prepared some subsystem data for subsequent reading
*/
if (0x77 == prevcode && dev->tapssdlen && 0x3E != code)
{
build_senseX (TAPE_BSENSE_BADCOMMAND, dev, unitstat, code);
return;
}
/* Early determination of CCW validity via TapeCommandTable lookup... */
drc = TapeCommandIsValid (code, dev->devtype, &rustat);
switch (drc)
{
default: /* Should NOT occur! */
ASSERT(0); // (fall thru to case 0 = unsupported)
case 0: /* Unsupported CCW code for given device-type */
build_senseX (TAPE_BSENSE_BADCOMMAND, dev, unitstat, code);
return;
case 1: /* Valid - Tape MUST be loaded */
break;
case 2: /* Valid - Tape NEED NOT be loaded */
break;
case 3: /* Valid - But is a NO-OP (return CE+DE now) */
/* Command reject if the volume is currently fenced */
if (dev->fenced)
{
build_senseX (TAPE_BSENSE_FENCED, dev, unitstat, code);
return;
}
build_senseX (TAPE_BSENSE_STATUSONLY, dev, unitstat, code);
return;
case 4: /* Valid, But is a NO-OP (for virtual tapes) */
/* Command reject if the volume is currently fenced */
if (dev->fenced)
{
build_senseX (TAPE_BSENSE_FENCED, dev, unitstat, code);
return;
}
/* If non-virtual (SCSI) then further processing required */
if (dev->tapedevt == TAPEDEVT_SCSITAPE)
break;
build_senseX (TAPE_BSENSE_STATUSONLY, dev, unitstat, code);
return;
case 5: /* Valid - Tape MUST be loaded (add DE to status) */
break;
}
// end switch (drc)
/* Verify a tape is loaded if that is required for this CCW... */
if ((1 == drc || 5 == drc) && // (tape MUST be loaded?)
(dev->fd < 0 || TAPEDEVT_SCSITAPE == dev->tapedevt)) // (no tape loaded or non-virtual?)
{
*residual = count;
/* Error if tape unloaded */
if (!strcmp (dev->filename, TAPE_UNLOADED))
{
build_senseX (TAPE_BSENSE_TAPEUNLOADED, dev, unitstat, code);
return;
}
/* Open the device file if necessary */
if (dev->fd < 0)
{
rc = dev->tmh->open( dev, unitstat, code );
if (rc < 0) /* Did open fail? */
{
return; /* Yes, exit with unit status */
}
}
/* Error if tape is not loaded */
if (!dev->tmh->tapeloaded( dev, unitstat, code ))
{
build_senseX (TAPE_BSENSE_TAPEUNLOADED, dev, unitstat, code);
return;
}
}
/* Process depending on CCW opcode */
switch (code) {
/*---------------------------------------------------------------*/
/* MODE SET (pre-3480 and earlier drives) */
/*---------------------------------------------------------------*/
/* Patch to no-op modeset 1 (7-track) commands - */
/* causes VM problems */
/* Andy Norrie 2002/10/06 */
case 0x13:
case 0x23:
case 0x33:
case 0x3B:
case 0x53:
case 0x63:
case 0x6B:
// case 0x73: // Mode Set (7-track 556/Odd/Normal) for 3420-3/5/7
// with 7-track feature installed, No-op for 3420-2/4/6
// and 3480, Invalid for 3422/3430, "Set Interface
// Identifier" for 3490 and later. NOTE: 3480 and earlier
// interpretation handled by command-table; 3490 and
// and later handled further below.
case 0x7B:
case 0x93:
case 0xA3:
case 0xAB:
case 0xB3:
case 0xBB:
// case 0xC3: // Mode Set (9-track 1600 bpi) for models earlier than
// 3480, "Set Tape-Write-Immediate" for 3480 and later.
// NOTE: handled by command-table for all models earlier
// than 3480; 3480 and later handled further below.
case 0xCB: /* 9-track 800 bpi */
case 0xD3: /* 9-track 6250 bpi */
case 0xEB: /* invalid mode set issued by DOS/VS */
{
build_senseX(TAPE_BSENSE_STATUSONLY,dev,unitstat,code);
break;
}
/*---------------------------------------------------------------*/
/* WRITE */
/*---------------------------------------------------------------*/
case 0x01:
{
/* Command reject if the volume is currently fenced */
if (dev->fenced)
{
build_senseX (TAPE_BSENSE_FENCED, dev, unitstat, code);
break;
}
/* Unit check if tape is write-protected */
if (dev->readonly || dev->tdparms.logical_readonly)
{
build_senseX (TAPE_BSENSE_WRITEPROTECT, dev, unitstat, code);
break;
}
/* Update matrix display if needed */
if ( TAPEDISPTYP_WAITACT == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_IDLE;
UpdateDisplay( dev );
}
/* Assign a unique Message Id for this I/O if needed */
INCREMENT_MESSAGEID(dev);
/* Write a block to the tape according to device type */
if ((rc = dev->tmh->write( dev, iobuf, count, unitstat, code)) < 0)
break; // (error)
*residual = 0;
/* Perform flush/sync and/or set normal completion status */
if (0
|| !dev->write_immed
|| (rc = dev->tmh->sync( dev, unitstat, code )) == 0
)
build_senseX( TAPE_BSENSE_STATUSONLY, dev, unitstat, code );
break;
}
/*---------------------------------------------------------------*/
/* READ FORWARD (3590 only) */
/*---------------------------------------------------------------*/
case 0x06:
{
/* SG24-2506 IBM 3590 Tape Subsystem Technical Guide
5.2.1 Separate Channel Commands for IPL Read and Normal Read
On IBM 3480/3490 tape devices there is only one Read Forward
CCW, the X'02' command code. This CCW is used to perform
not only normal read operations but also an IPL Read from
tape, for example, DFSMSdss Stand-Alone Restore. When the
CCW is used as an IPL Read, it is not subject to resetting
event notification, by definition. Because there is only
one Read Forward CCW, it cannot be subject to resetting event
notification on IBM 3480 and 3490 devices.
To differentiate between an IPL Read and a normal read
forward operation, the X'02' command code has been redefined
to be the IPL Read CCW, and a new X'06' command code has been
defined to be the Read Forward CCW. The new Read Forward
CCW, X'06', is subject to resetting event notification, as
should be the case for normal read CCWs issued by applications
or other host software.
*/
// PROGRAMMING NOTE: I'm not sure what they mean by "resetting
// event notification" above, but for now we'll just FALL THROUGH
// to the below IPL READ logic...
}
// (purposely FALL THROUGH to below IPL READ logic for now)
/*---------------------------------------------------------------*/
/* IPL READ (non-3590) */
/*---------------------------------------------------------------*/
case 0x02:
{
/* Command reject if the volume is currently fenced */
if (dev->fenced)
{
build_senseX (TAPE_BSENSE_FENCED, dev, unitstat, code);
break;
}
/* Update matrix display if needed */
if ( TAPEDISPTYP_WAITACT == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_IDLE;
UpdateDisplay( dev );
}
/* Assign a unique Message Id for this I/O if needed */
INCREMENT_MESSAGEID(dev);
/* Read a block from the tape according to device type */
/* Exit with unit check status if read error condition */
if ((S32)(len = dev->tmh->read( dev, dev->buf, unitstat, code)) < 0)
break; // (error)
/* Calculate number of bytes to read and residual byte count */
RESIDUAL_CALC (len);
/* Copy data to I/O buffer */
memcpy (iobuf, dev->buf, num);
/* Save size and offset of data not used by this CCW */
dev->curblkrem = len - num;
dev->curbufoff = num;
dev->buflen = len;
/* Exit with unit exception status if tapemark was read */
if (len == 0)
build_senseX (TAPE_BSENSE_READTM, dev, unitstat, code);
else
build_senseX (TAPE_BSENSE_STATUSONLY, dev, unitstat, code);
break;
}
/*---------------------------------------------------------------*/
/* CONTROL NO-OPERATION */
/*---------------------------------------------------------------*/
case 0x03:
{
/* Command reject if the volume is currently fenced */
if (dev->fenced)
{
build_senseX (TAPE_BSENSE_FENCED, dev, unitstat, code);
break;
}
build_senseX (TAPE_BSENSE_STATUSONLY, dev, unitstat, code);
break;
}
/*---------------------------------------------------------------*/
/* SENSE */
/*---------------------------------------------------------------*/
case 0x04:
{
/* Calculate residual byte count */
RESIDUAL_CALC (dev->numsense);
/* If we don't already have some sense already pre-built
and ready and waiting, then we'll have to build it fresh
for this call... Otherwise, we use whatever we already
have waiting for them pre-built from a previous call...
*/
if (!dev->sns_pending)
build_senseX (TAPE_BSENSE_UNSOLICITED, dev, unitstat, code);
*unitstat = CSW_CE|CSW_DE; /* Need to do this ourselves as */
/* we might not have gone thru */
/* build_senseX... */
/* Copy device sense bytes to channel I/O buffer, clear
them for the next time, and then finally, reset the
Contengent Allegiance condition... */
memcpy (iobuf, dev->sense, num);
memset (dev->sense, 0, sizeof(dev->sense));
dev->sns_pending = 0;
break;
}
/*---------------------------------------------------------------*/
/* READ FORWARD (3590 only) */
/*---------------------------------------------------------------*/
// case 0x06:
// {
// (handled by case 0x02: IPL READ)
// }
/*---------------------------------------------------------------*/
/* REWIND */
/*---------------------------------------------------------------*/
case 0x07:
{
/* Update matrix display if needed */
if ( TAPEDISPTYP_IDLE == dev->tapedisptype ||
TAPEDISPTYP_WAITACT == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_REWINDING;
UpdateDisplay( dev );
}
/* Assign a unique Message Id for this I/O if needed */
INCREMENT_MESSAGEID(dev);
/* Do the rewind */
rc = dev->tmh->rewind( dev, unitstat, code);
/* Update matrix display if needed */
if ( TAPEDISPTYP_REWINDING == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_IDLE;
UpdateDisplay( dev );
}
/* Check for error */
if (rc < 0)
{
dev->fenced = 1;
break;
}
dev->eotwarning = 0;
dev->fenced = 0;
build_senseX (TAPE_BSENSE_STATUSONLY, dev, unitstat, code);
break;
}
/*---------------------------------------------------------------*/
/* READ PREVIOUS (3590) */
/*---------------------------------------------------------------*/
case 0x0A:
{
/* SG24-2506 IBM 3590 Tape Subsystem Technical Guide
5.2.2 Read Previous to Replace Read Backward:
The ESCON-attached Magstar tape drive does not support the
Read Backward CCW (command code, X'0C'). It supports a new
Read Previous CCW that allows processing of an IBM 3590 High
Performance Tape Cartridge in the backward direction without
the performance penalties that exist with the Read Backward
CCW. IBM 3480 and 3490 devices had to reread the physical
block from the medium for each request of a logical block.
The Magstar tape drive retains the physical block in the
device buffer and satisfies any subsequent Read Previous from
the buffer, similar to how Read Forward operates. The Read
Previous CCW operates somewhat like the Read Backward CCW
in that it can be used to process the volumes in the backward
direction. It is different from the Read Backward, however,
because the data is transferred to the host in the same order
in which it was written, rather than in reverse order like
Read Backward.
*/
/* SG24-2594 IBM 3590 Multiplatform Implementation
5.1.2 New and Changed Read Channel Commands
[...] That is, the Read Backward command's data address
will point to the end of the storage area, while a Read
Previous command points to the beginning of the storage
area...
*/
// PROGRAMMING NOTE: luckily, channel.c's buffer handling
// causes transparent handling of Read Backward/Reverse,
// so the above buffer alignment and data transfer order
// is not a concern for us here.
// PROGRAMMING NOTE: until we can add support to Hercules
// allowing direct SCSI i/o (so that we can issue the 'Read
// Reverse' command directly to the SCSI device), we will
// simply FALL THROUGH to our existing "Read Backward" logic.
}
// (purposely FALL THROUGH to the 'READ BACKWARD' logic below)
/*---------------------------------------------------------------*/
/* READ BACKWARD */
/*---------------------------------------------------------------*/
case 0x0C:
{
/* Update matrix display if needed */
if ( TAPEDISPTYP_WAITACT == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_IDLE;
UpdateDisplay( dev );
}
/* Backspace to previous block according to device type */
/* Exit with unit check status if error condition */
if ((rc = dev->tmh->bsb( dev, unitstat, code )) < 0)
break; // (error)
/* Exit with unit exception status if tapemark was sensed */
if (rc == 0)
{
*residual = 0;
build_senseX (TAPE_BSENSE_READTM, dev, unitstat, code);
break;
}
/* Assign a unique Message Id for this I/O if needed */
INCREMENT_MESSAGEID(dev);
/* Now read in a forward direction the actual data block
we just backspaced over, and exit with unit check status
on any read error condition
*/
if ((S32)(len = dev->tmh->read( dev, dev->buf, unitstat, code )) < 0)
break; // (error)
/* Calculate number of bytes to read and residual byte count */
RESIDUAL_CALC (len);
/* Copy data to I/O buffer */
memcpy (iobuf, dev->buf, num);
/* Save size and offset of data not used by this CCW */
dev->curblkrem = len - num;
dev->curbufoff = num;
dev->buflen = len;
/* Backspace to previous block according to device type,
and exit with unit check status if error condition */
if ((rc = dev->tmh->bsb( dev, unitstat, code )) < 0)
break; // (error)
/* Set normal status */
build_senseX (TAPE_BSENSE_STATUSONLY, dev, unitstat, code);
break;
} /* End case 0x0C: READ BACKWARD */
/*---------------------------------------------------------------*/
/* REWIND UNLOAD */
/*---------------------------------------------------------------*/
case 0x0F:
{
/* Update matrix display if needed */
if ( dev->tdparms.displayfeat )
{
if ( TAPEDISPTYP_UMOUNTMOUNT == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_MOUNT;
dev->tapedispflags |= TAPEDISPFLG_REQAUTOMNT;
strlcpy( dev->tapemsg1, dev->tapemsg2, sizeof(dev->tapemsg1) );
}
else if ( TAPEDISPTYP_UNMOUNT == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_IDLE;
}
}
if ( TAPEDISPTYP_IDLE == dev->tapedisptype ||
TAPEDISPTYP_WAITACT == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_UNLOADING;
UpdateDisplay( dev );
}
/* Assign a unique Message Id for this I/O if needed */
INCREMENT_MESSAGEID(dev);
/* Do the Rewind-Unload */
#if defined(OPTION_SCSI_TAPE)
if ( TAPEDEVT_SCSITAPE == dev->tapedevt )
int_scsi_rewind_unload( dev, unitstat, code );
else
#endif
{
dev->tmh->close(dev);
*unitstat=0;
}
/* Update matrix display if needed */
if ( TAPEDISPTYP_UNLOADING == dev->tapedisptype )
{
dev->tapedisptype = TAPEDISPTYP_IDLE;
UpdateDisplay( dev );
}
if ((*unitstat & CSW_UC) != 0) // (did it work?)
break; // (no it didn't)
dev->curfilen = 1;
dev->nxtblkpos = 0;
dev->prvblkpos = -1;
dev->eotwarning = 0;