forked from PDP-10/klh10
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvtm03.c
2475 lines (2139 loc) · 74.5 KB
/
dvtm03.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
/* DVTM03.C - Emulates TM03 tape controller under RH20 for KL10
*/
/* $Id: dvtm03.c,v 2.8 2002/05/21 09:40:26 klh Exp $
*/
/* Copyright © 1993, 2001 Kenneth L. Harrenstien
** All Rights Reserved
**
** This file is part of the KLH10 Distribution. Use, modification, and
** re-distribution is permitted subject to the terms in the file
** named "LICENSE", which contains the full text of the legal notices
** and should always accompany this Distribution.
**
** This software is provided "AS IS" with NO WARRANTY OF ANY KIND.
**
** This notice (including the copyright and warranty disclaimer)
** must be included in all copies or derivations of this software.
*/
/*
* $Log: dvtm03.c,v $
* Revision 2.8 2002/05/21 09:40:26 klh
* Fix duplicate path check - only applies if using subprocs
*
* Revision 2.7 2002/04/24 07:50:06 klh
* Turn max rec-space cmd into a file-space cmd
* Add blocking wait on DP when booting, to avoid DEC boot races
*
* Revision 2.6 2002/04/10 16:06:20 klh
* Fix spurious complaint about duplicate paths.
*
* Revision 2.5 2002/03/28 16:50:30 klh
* Uniquize tape device serial numbers (just as for disks)
*
* Revision 2.4 2002/03/13 12:36:17 klh
* Changed to allow NOP to be executed while rewinding without sticking
* in CSR (ITS depends on this).
*
* Revision 2.3 2001/11/10 21:28:59 klh
* Final 2.0 distribution checkin
*
*/
#include "klh10.h"
#if !KLH10_DEV_TM03 && CENV_SYS_DECOSF
/* Stupid gubbish needed to prevent OSF/1 AXP compiler from
** halting merely because compiled file is empty!
*/
static int decosfcclossage;
#endif
#if KLH10_DEV_TM03 /* Moby conditional for entire file */
#include <errno.h>
#include <string.h>
#include <stdlib.h> /* For malloc */
#include <stdio.h>
#include "kn10def.h"
#include "kn10dev.h"
#include "dvuba.h"
#include "dvtm03.h"
#include "prmstr.h"
#if KLH10_DEV_DPTM03
# include "dpsup.h" /* Using device subproc! */
# include "dptm03.h" /* Define stuff shared with subproc */
#else
# include "wfio.h" /* For word-based file i/o */
# include "vmtape.h" /* For virtual magtape facilities */
#endif
#ifdef RCSID
RCSID(dvtm03_c,"$Id: dvtm03.c,v 2.8 2002/05/21 09:40:26 klh Exp $")
#endif
/* Some notes on TM03 support:
From the viewpoint of a RH11 or RH20 controller, the TM02/3 is a "drive";
however, by itself it's known as a "formatter" which can control up to 8
"slave" transport units -- sort of like a subcontroller.
The best documentation on the TM02/3 is the DEC Technical
Manual titled "TM03 Magnetic Tape Formatter", part EK-0TM03-TM-003.
The last known edition was Dec 1983. Having the prints also would
be nice...
Some notes on PDP-10 expectations:
---------------------------------
ITS driver: nmtape >
T10 driver: tm2kon.mac
T20 driver: phym2.mac
Tapemark status:
The TM03 tech doc is clear that status bit 04 (Tape Mark Detected)
is set whenever passing over a tapemark in the forward direction.
It is not as clear whether this applies to the reverse direction, or
if a tapemark was just written.
All 3 systems DO expect to see this bit when moving back
over a tapemark, and rely on it.
Regarding setting if just written: the hardware appears to be set up
so that anything written will immediately pass under the read head.
This implies that a written tapemark will be immediately detected.
The TOPS-10 driver (tm2kon.mac) does expect to see EOF set when it just
wrote one - this is used to help maintain tape position information -
although it avoids passing the flag (as RB.STM) to the user program
TAPUUO in that case.
The other 2 drivers don't have similarly explicit comments and it
doesn't appear to matter to them.
CONCLUSION: try to set the EOF/TM flag in all those situations.
Frame Count:
ITS never reads the frame count register except when reading
a data record. Even then, it checks the tape status reg for
EOF/tapemark before looking at the frame count to see how much
data it grabbed.
T10 similarly pays no attention to FC except when reading.
T20 does check the result on tape movement, but the exact value
seems not to matter. If FC is 0 then it is assumed the operation
succeeded; if it's non-zero then the other bits are checked to
make sure it stopped early for a good reason (BOT,EOT,TM).
CONCLUSION: Must maintain an accurate frame count for reading,
but otherwise it's OK to settle for just ensuring it's
0 on full success and non-zero on partial completion.
*/
#ifndef DVTM_NSUP
# define DVTM_NSUP (8*8)
#endif
#ifndef DVTM_MAXPATH /* Length of pathname for tapefile */
# define DVTM_MAXPATH 127
#endif
#ifndef DVTM_MAXRECSIZ
# ifdef DPTM_MAXRECSIZ
# define DVTM_MAXRECSIZ DPTM_MAXRECSIZ
# else
# define DVTM_MAXRECSIZ (1L<<16) /* 16 bits worth of record length */
# endif
#endif
#if 0
#define DVDEBUG(d) ((d)->tm_dv.dv_debug)
#define DVDBF(d) ((d)->tm_dv.dv_dbf)
#endif
struct tmdev {
struct device tm_dv;
/* Drive(formatter)-specific stuff */
unsigned int tm_reg[040]; /* Formatter registers (16 bits each) */
int tm_typ; /* Drive type (TM02/TM03 bit in DT) */
int tm_bit; /* Attention bit */
int tm_wc; /* I/O current word count */
vmptr_t tm_vp; /* I/O current word pointer into phys mem */
int tm_slv; /* Current selected slave (only 0 used) */
/* Stuff for slave 0 */
int tm_styp; /* Slave device type (RH_DTxx value) */
int tm_sfmt; /* Slave format select */
int tm_sfpw; /* Frames per word of selected format */
int tm_sden; /* Slave density select */
int tm_srew; /* TRUE if slave is rewinding */
int tm_scmd; /* Command being executed, with GO bit */
unsigned char *tm_buff; /* Start ptr into buffer (local or shared) */
size_t tm_bchs; /* # bytes used in buffer */
#if KLH10_DEV_DPTM03
char *tm_dpname; /* Pathname of executable subproc */
struct dp_s tm_dp; /* Handle on dev subprocess */
struct dptm03_s *tm_sdptm; /* Ptr to shared memory segment */
int tm_state;
# define TM03_ST_OFF 0 /* Turned off - no subproc */
# define TM03_ST_READY 1 /* On and ready for command */
# define TM03_ST_BUSY 2 /* Executing some command */
/* Note "on" doesn't imply tape mounted! */
int tm_dpdbg; /* Initial DP debug val */
char tm_spath[DVTM_MAXPATH+1];
#else
unsigned char *tm_bufp; /* Handle on malloced buffer */
struct vmtape tm_vmt;
#endif
};
#define TMREG(d,r) ((d)->tm_reg[r])
static int ntms = 0;
struct tmdev /* External for easier debug */
*dvtm03[DVTM_NSUP]; /* Table of pointers, for easier debug */
static struct tmdev dvtm; /* First one static for easier debug */
/* Handy macros to eliminate some conditionals */
#if KLH10_DEV_DPTM03
# define TM03_FRMS(tm) ((tm)->tm_sdptm->dptm_frms)
# define TM03_ERRS(tm) ((tm)->tm_sdptm->dptm_err)
#else
# define TM03_FRMS(tm) (vmt_framecnt(&(tm)->tm_vmt))
# define TM03_ERRS(tm) (vmt_errors(&(tm)->tm_vmt))
#endif
/* Internal variables and defs */
static int tm03_conf(FILE *f, char *s, struct tmdev *tm);
static int tm03_init(struct device *d, FILE *of);
static int tm03_readin(struct device *d, FILE *of, w10_t, w10_t *, int);
static int tm03_mount(struct device *d, FILE *f, char *path, char *argstr);
static void tm03_powoff(struct device *d);
static void tm03_reset(struct device *d);
static uint32 tm03_rdreg(struct device *d, int reg);
static int tm03_wrreg(struct device *d, int reg, unsigned int val);
#if KLH10_DEV_DPTM03
static void tm03_run(struct tmdev *tm);
static void tm03_evhsdon(struct device *d, struct dvevent_s *evp);
static void tm03_evhrwak(struct device *d, struct dvevent_s *evp);
#endif
static void tm_clear(struct tmdev *tm);
static void tm_cmdxct(struct tmdev *tm, int cmd);
static void tm_cmddon(struct tmdev *tm);
static void tm_nxfn(struct tmdev *tm);
static void tm_attn(struct tmdev *tm);
static void tm_ssint(struct tmdev *tm);
static void tm_space(struct tmdev *tm, int revf);
static int tm_io(struct tmdev *tm, int dirf);
static void tm_ssel(struct tmdev *tm);
static void tm_ssta(struct tmdev *tm);
static int tm_filbuf(struct tmdev *tm);
static int tm_flsbuf(struct tmdev *tm, int revf);
static void tm_showbuf(struct tmdev *tm,
unsigned char *ucp, vmptr_t vp, int wc, int revf);
static unsigned char *wdstofcd(unsigned char *ucp, vmptr_t vp, int wc);
static unsigned char *wdstofic(unsigned char *ucp, vmptr_t vp, int wc);
static void fcdtowds(vmptr_t vp, unsigned char *ucp, int wc);
static void fictowds(vmptr_t vp, unsigned char *ucp, int wc);
static void revfcdtowds(vmptr_t vp, unsigned char *ucp, int wc, int revf);
static void revfictowds(vmptr_t vp, unsigned char *ucp, int wc, int revf);
/* Configuration Parameters */
#define DVTM03_PARAMS \
prmdef(TMP_DBG, "debug"), /* Initial debug value */\
prmdef(TMP_FMTR,"fmtr"), /* Formatter type (eg TM03) */\
prmdef(TMP_TYP, "type"), /* Slave type (eg TU45) */\
prmdef(TMP_PATH,"path"), /* Initial mount path of file or raw device */\
prmdef(TMP_SN, "sn"), /* Formatter Serial number */\
prmdef(TMP_DPDBG,"dpdebug"), /* Initial DP debug value */\
prmdef(TMP_DP, "dppath") /* Device subproc pathname */
enum {
# define prmdef(i,s) i
DVTM03_PARAMS
# undef prmdef
};
static char *tmprmtab[] = {
# define prmdef(i,s) s
DVTM03_PARAMS
# undef prmdef
, NULL
};
static int partyp(char *cp, int *atyp); /* Local parsing routines */
static int parfmtr(char *cp, int *afmtr);
/* TM03_CONF - Parse configuration string and set defaults.
** At this point, device has just been created, but not yet bound
** or initialized.
** NOTE that some strings are dynamically allocated! Someday may want
** to clean them up nicely if config fails or device is uncreated.
*/
static int
tm03_conf(FILE *f, char *s, struct tmdev *tm)
{
int i, ret = TRUE;
struct prmstate_s prm;
char buff[200];
long lval;
/* First set defaults for all configurable parameters */
DVDEBUG(tm) = FALSE;
tm->tm_typ = TM_DTTM03; /* Say formatter is TM03 for now */
tm->tm_styp = TM_DT45; /* Say slave is TU45 for now */
TMREG(tm, RHR_SN) = /* Serial Number register (BCD) */
(((9900 / 1000)%10) << 12)
| (((9900 / 100)%10) << 8)
| (((ntms / 10)%10) << 4)
| (((ntms )%10) );
#if KLH10_DEV_DPTM03
tm->tm_dpname = "dptm03"; /* Subproc executable */
tm->tm_spath[0] = '\0'; /* Nothing mounted yet */
tm->tm_dpdbg = FALSE;
#endif
prm_init(&prm, buff, sizeof(buff),
s, strlen(s),
tmprmtab, sizeof(tmprmtab[0]));
while ((i = prm_next(&prm)) != PRMK_DONE) {
switch (i) {
case PRMK_NONE:
fprintf(f, "Unknown TM03 parameter \"%s\"\n", prm.prm_name);
ret = FALSE;
continue;
case PRMK_AMBI:
fprintf(f, "Ambiguous TM03 parameter \"%s\"\n", prm.prm_name);
ret = FALSE;
continue;
default: /* Handle matches not supported */
fprintf(f, "Unsupported TM03 parameter \"%s\"\n", prm.prm_name);
ret = FALSE;
continue;
case TMP_DBG: /* Parse as true/false boolean or number */
if (!prm.prm_val) /* No arg => default to 1 */
DVDEBUG(tm) = 1;
else if (!s_tobool(prm.prm_val, &DVDEBUG(tm)))
break;
continue;
case TMP_TYP: /* Parse as slave type */
if (!prm.prm_val)
break;
if (!partyp(prm.prm_val, &tm->tm_styp))
break;
continue;
case TMP_FMTR: /* Parse as formatter type */
if (!prm.prm_val)
break;
if (!parfmtr(prm.prm_val, &tm->tm_typ))
break;
continue;
case TMP_SN: /* Parse as decimal number */
if (!prm.prm_val || !s_todnum(prm.prm_val, &lval))
break;
if (lval < 0) {
fprintf(f, "TM03 SN must be >= 0\n");
ret = FALSE;
} else
/* Turn last 4 digits into BCD */
TMREG(tm, RHR_SN) =
(((lval / 1000)%10) << 12)
| (((lval / 100)%10) << 8)
| (((lval / 10)%10) << 4)
| (((lval )%10) );
continue;
case TMP_PATH: /* Parse as simple string */
#if KLH10_DEV_DPTM03
if (!prm.prm_val)
break;
if (strlen(prm.prm_val) > DVTM_MAXPATH) {
fprintf(f, "TM03 path too long (max %d)\n", DVTM_MAXPATH);
ret = FALSE;
} else
strcpy(tm->tm_spath, prm.prm_val);
#endif
continue;
case TMP_DPDBG: /* Parse as true/false boolean or number */
#if KLH10_DEV_DPTM03
if (!prm.prm_val) /* No arg => default to 1 */
tm->tm_dpdbg = 1;
else if (!s_tobool(prm.prm_val, &(tm->tm_dpdbg)))
break;
#endif
continue;
case TMP_DP: /* Parse as simple string */
#if KLH10_DEV_DPTM03
if (!prm.prm_val)
break;
tm->tm_dpname = s_dup(prm.prm_val);
#endif
continue;
}
ret = FALSE;
fprintf(f, "TM03 param \"%s\": ", prm.prm_name);
if (prm.prm_val)
fprintf(f, "bad value syntax: \"%s\"\n", prm.prm_val);
else
fprintf(f, "missing value\n");
}
/* Param string all done, do followup checks or cleanup */
/* Helpful checks to avoid shooting self in foot. */
/* Ensure the drive serial # isn't duplicated, otherwise TOPS-10/20
will think it's a dual-ported drive and get very confused.
Do similar check for hard-mount device path as well.
*/
for (i = 0; i < ntms; ++i) { /* Step thru all known TM devs */
struct tmdev *cktm;
if (!(cktm = dvtm03[i]) || (cktm == tm))
continue;
if (TMREG(cktm, RHR_SN) == TMREG(tm, RHR_SN)) {
fprintf(f, "TM03 serial num duplicated! %d%d%d%d\n",
(TMREG(tm, RHR_SN) >> 12) & 017,
(TMREG(tm, RHR_SN) >> 8) & 017,
(TMREG(tm, RHR_SN) >> 4) & 017,
(TMREG(tm, RHR_SN) ) & 017);
ret = FALSE;
break;
}
#if KLH10_DEV_DPTM03
if (tm->tm_spath[0] && (strcmp(cktm->tm_spath, tm->tm_spath) == 0)) {
fprintf(f, "TM03 path duplicated! \"%s\"\n", tm->tm_spath);
ret = FALSE;
break;
}
#endif /* KLH10_DEV_DPTM03 */
}
return ret;
}
static int
partyp(char *cp, int *atyp)
{
if (s_match(cp, "TU45") == 2) *atyp = TM_DT45;
else if (s_match(cp, "TE16") == 2) *atyp = TM_DT16;
else if (s_match(cp, "TU77") == 2) *atyp = TM_DT77;
else
return FALSE;
return TRUE;
}
/* Parse formatter type
*/
static int
parfmtr(char *cp, int *afmtr)
{
if (s_match(cp, "TM03") == 2) *afmtr = TM_DTTM03;
else if (s_match(cp, "TM02") == 2) *afmtr = TM_DTTM02;
else
return FALSE;
return TRUE;
}
struct device *
dvtm03_create(FILE *f, char *s)
{
register struct tmdev *tm;
/* Allocate an TM device structure */
if (ntms >= DVTM_NSUP) {
fprintf(f, "Too many TMs, max: %d\n", DVTM_NSUP);
return NULL;
}
if (ntms == 0) /* Special-case first TM */
tm = &dvtm;
else {
if (!(tm = (struct tmdev *)malloc(sizeof(struct tmdev)))) {
fprintf(f, "Cannot allocate TM device! (out of memory)\n");
return NULL;
}
}
dvtm03[ntms++] = tm;
/* Various initialization stuff */
memset((char *)tm, 0, sizeof(*tm));
iodv_setnull(&tm->tm_dv); /* Set up as null device */
tm->tm_dv.dv_dflags = DVFL_CTLIO | DVFL_NBA | DVFL_TAPE;
tm->tm_dv.dv_init = tm03_init;
tm->tm_dv.dv_readin = tm03_readin;
tm->tm_dv.dv_reset = tm03_reset;
tm->tm_dv.dv_rdreg = tm03_rdreg;
tm->tm_dv.dv_wrreg = tm03_wrreg;
tm->tm_dv.dv_powoff = tm03_powoff;
tm->tm_dv.dv_mount = tm03_mount;
/* TM-specific stuff */
/* Configure drive from parsed string.
*/
if (!tm03_conf(f, s, tm))
return NULL;
return &tm->tm_dv;
}
static int
tm03_init(struct device *d, FILE *of)
{
register struct tmdev *tm = (struct tmdev *)d;
tm->tm_bit = 1 << tm->tm_dv.dv_num; /* Set attention bit mask */
/* Set up stuff for slave 0 */
TMREG(tm, RHR_DT) = TM_DTNS | TM_DTTA /* Not sector, and tape */
| TM_DTSS /* Slave 0 always there */
| tm->tm_typ | tm->tm_styp; /* Formatter & slave type */
tm->tm_sfmt = 0 /* TM_FCD */; /* PDP-10 Core-Dump format */
tm->tm_sfpw = 5;
tm->tm_sden = 0 /* TM_D02 */; /* 200bpi */
tm->tm_srew = FALSE; /* Not rewinding */
tm->tm_scmd = 0; /* No command */
#if KLH10_DEV_DPTM03
{
register struct dptm03_s *dptm;
struct dvevent_s ev;
tm->tm_state = TM03_ST_OFF;
if (!dp_init(&tm->tm_dp, sizeof(struct dptm03_s),
DP_XT_MSIG, SIGUSR1, 0, /* in fr dp */
DP_XT_MSIG, SIGUSR1, (size_t)DPTM_MAXRECSIZ)) { /* out to dp */
if (of) fprintf(of, "TM03 subproc init failed!\n");
return FALSE;
}
tm->tm_buff = dp_xsbuff(&(tm->tm_dp.dp_adr->dpc_todp), (size_t *)NULL);
memset(tm->tm_buff - 4, 0, 4); /* Clear prefix padding */
/* See dptm_revpad and tm_flsbuf */
/* Set up TM03-specific part of shared DP memory */
dptm = (struct dptm03_s *) tm->tm_dp.dp_adr;
tm->tm_sdptm = dptm;
tm->tm_dv.dv_dpp = &(tm->tm_dp); /* Tell CPU where our DP struct is */
dptm->dptm_dpc.dpc_debug = tm->tm_dpdbg; /* Init debug flag */
if (cpu.mm_locked) /* Lock DP mem if CPU is */
dptm->dptm_dpc.dpc_flags |= DPCF_MEMLOCK;
dptm->dptm_blkopen = 10; /* Use retry of 10 for now */
/* Register ourselves with main KLH10 loop for DP events */
ev.dvev_type = DVEV_DPSIG; /* Event = Device Proc signal */
ev.dvev_arg.eva_int = SIGUSR1;
ev.dvev_arg2.eva_ip = &(tm->tm_dp.dp_adr->dpc_todp.dpx_donflg);
if (!(*tm->tm_dv.dv_evreg)((struct device *)tm, tm03_evhsdon, &ev)) {
if (of) fprintf(of, "TM03 event reg failed!\n");
return FALSE;
}
ev.dvev_type = DVEV_DPSIG; /* Event = Device Proc signal */
ev.dvev_arg.eva_int = SIGUSR1;
ev.dvev_arg2.eva_ip = &(tm->tm_dp.dp_adr->dpc_frdp.dpx_wakflg);
if (!(*tm->tm_dv.dv_evreg)((struct device *)tm, tm03_evhrwak, &ev)) {
if (of) fprintf(of, "TM03 event reg failed!\n");
return FALSE;
}
/* Mount hard device here if specified as init arg? */
if (tm->tm_spath[0]) {
if (!tm03_mount((struct device *)tm,
of, tm->tm_spath, "hard")) { /* Assume hard, R/W */
if (of) fprintf(of, "TM03 initial mount of \"%s\" failed!\n",
tm->tm_spath);
return FALSE;
}
}
}
#else
/* Note following buffer allocation includes extra "revpad" bytes
at the start to handle read-reverse transfers; see tm_flsbuf().
*/
tm->tm_bufp = (unsigned char *)malloc(sizeof(double)+
DVTM_MAXRECSIZ);
memset(tm->tm_bufp, 0, sizeof(double));
tm->tm_buff = tm->tm_bufp + sizeof(double);
tm->tm_bchs = 0;
vmt_init(&(tm->tm_vmt), "TM03");
#endif
tm_clear(tm);
return TRUE;
}
/* TM03_POWOFF - Handle "power-off" which usually means the KLH10 is
** being shut down. This is important if using a dev subproc!
*/
static void
tm03_powoff(struct device *d)
{
register struct tmdev *tm = (struct tmdev *)d;
/* Later could add stuff to pretend controller/slave is off, but for
** now it suffices just to clean up.
*/
#if KLH10_DEV_DPTM03
(*tm->tm_dv.dv_evreg)( /* Flush all event handlers for device */
(struct device *)tm,
NULL, /* Null handler to flush */
(struct dvevent_s *)NULL);
dp_term(&(tm->tm_dp), 0); /* Flush all subproc overhead */
tm->tm_state = TM03_ST_OFF;
tm->tm_sdptm = NULL; /* Clear pointers no longer meaningful */
tm->tm_buff = NULL;
#endif
}
#if KLH10_DEV_DPTM03
static int
tm_cmdwait(register struct tmdev *tm,
FILE *f,
register struct dpx_s *dpx,
int secs)
{
int cnt;
osstm_t stm;
OS_STM_SET(stm, secs);
cnt = secs - 2;
while (!dp_xstest(dpx)) {
if (os_msleep(&stm) <= 0)
return 0;
dev_evcheck(); /* See if got any device completion ints */
/* Every other sec print progress */
if (OS_STM_SEC(stm) < cnt) {
if (f) fprintf(f, "[TM03 busy, waiting...]\n");
cnt = OS_STM_SEC(stm) - 2;
}
}
if (f) fprintf(f, "[TM03 ready]\n");
return 1;
}
static int
tm_blkcmd(register struct tmdev *tm,
FILE *f,
int cmd, size_t arg)
{
register struct dpx_s *dpx = &(tm->tm_dp.dp_adr->dpc_todp);
if (!tm_cmdwait(tm, f, dpx, 10)) {
if (f) fprintf(f, "[TM03 still busy, giving up before cmd %o]\n", cmd);
return FALSE; /* Barf if not ready in time */
}
dp_xsend(dpx, cmd, arg); /* Send command! */
if (!tm_cmdwait(tm, f, dpx, 10)) {
if (f) fprintf(f, "[TM03 still busy, giving up after cmd %o]\n", cmd);
return FALSE; /* Barf if not ready in time */
}
return TRUE;
}
#endif /* KLH10_DEV_DPTM03 */
/* TM03_READIN - do special readin for boot code
** Requires special hackery as we are bypassing all of the
** normal I/O procedures, which assume an initialized controller.
*/
static int
tm03_readin(struct device *d,
FILE *f,
w10_t blka, /* Interpreted as file #, 0 = first */
w10_t *wp, int wc)
{
register struct tmdev *tm = (struct tmdev *)d;
register size_t frmc = wc * 5; /* Assume core-dump format */
size_t fskip = W10_U32(blka);
if (frmc > DVTM_MAXRECSIZ)
frmc = DVTM_MAXRECSIZ;
/* If DP, may want to try waiting for response at this point. */
tm_clear(tm);
if (!(TMREG(tm, RHR_STS) & TM_SMOL)) { /* Ensure medium on-line */
if (f) fprintf(f, "[tm03_readin: tape off-line]\n");
return 0; /* Tape not mounted or not ready */
}
/* Space forward by given # of files, then read 1 record */
#if KLH10_DEV_DPTM03
if (fskip) {
if (f) fprintf(f, "[tm03_readin: skipping %ld]\n", (long)fskip);
if (!tm_blkcmd(tm, f, DPTM_SFF, fskip))
return 0;
}
if (!tm_blkcmd(tm, f, DPTM_RDF, frmc)) {
return 0;
}
#else
if (fskip && !vmt_fspace(&(tm->tm_vmt), 0, (long)fskip)) {
return 0;
}
(void) vmt_rget(&(tm->tm_vmt), tm->tm_buff, (long)frmc);
#endif
frmc = TM03_FRMS(tm); /* Get # frames in record */
wc = frmc / 5; /* Find # whole words */
if (wc) {
fcdtowds(wp, tm->tm_buff, wc);
}
return wc;
}
#if KLH10_DEV_DPTM03
/* TM03_RUN - Not sure if this one makes sense.
*/
static void
tm03_run(register struct tmdev *tm)
{
}
/* TM_DPCMD - Carry out an asynchronous command
*/
static void
tm_dpcmd(register struct tmdev *tm, int cmd, size_t arg)
{
register struct dpx_s *dpx = &(tm->tm_dp.dp_adr->dpc_todp);
if (DVDEBUG(tm))
fprintf(DVDBF(tm), "[tm_dpcmd: DP %d, %ld]\r\n", cmd, (long)arg);
/* First, double-check to be sure it's OK to send a command */
if (tm->tm_state != TM03_ST_READY) {
/* Says not ready -- check DP to see if true */
if (!(tm->tm_state == TM03_ST_BUSY) || !dp_xstest(dpx)) {
/* Yep, really can't send command now.
** This shouldn't happen; what to do?
*/
fprintf(DVDBF(tm),
"[TM03 %s internal error: dpcmd %d blocked, state %d]\r\n",
tm->tm_dv.dv_name, cmd, tm->tm_state);
/* Try to keep going by ignoring this command */
return;
}
/* Hmmm, state is BUSY but dp_xstest thinks we're OK, so go ahead */
}
tm->tm_state = TM03_ST_BUSY;
dp_xsend(dpx, cmd, arg); /* Send command! */
/* CROCK to get around race problem with DEC boot code (both KL and KS).
* If PI not turned on, assume we're in boot code, and block here
* (thus blocking KN10) until tape drive is ready again.
*/
if (!cpu.pi.pisys_on) {
/* 15 sec should be plenty! Any more and probably a real error */
if (!tm_cmdwait(tm, (DVDEBUG(tm) ? DVDBF(tm) : NULL), dpx, 15)) {
if (DVDEBUG(tm))
fprintf(DVDBF(tm), "[tm_dpcmd: boot-mode wait timed out]\r\n");
}
}
}
/* TM03_EVHSDON - Invoked by INSBRK event handling when
** signal detected from DP saying "done" in response to something
** we sent it.
** Basically this means the DP should be ready to accept another
** command.
*/
static void
tm03_evhsdon(struct device *d,
register struct dvevent_s *evp)
{
register struct tmdev *tm = (struct tmdev *)d;
if (DVDEBUG(tm))
fprintf(DVDBF(tm), "[tm03_evhsdon: %d]",
(int)dp_xstest(&(tm->tm_dp.dp_adr->dpc_todp)));
tm->tm_state = TM03_ST_READY; /* Say ready for cmd again */
tm_cmddon(tm);
}
/* TM03_EVHRWAK - Invoked by INSBRK event handling when
** signal detected from DP saying "wake up"; the DP is sending
** us something.
** The TM03 will use this to receive notice of unexpected manual events,
** specifically tape being mounted or unmounted.
*/
static void
tm03_evhrwak(struct device *d,
register struct dvevent_s *evp)
{
register struct tmdev *tm = (struct tmdev *)d;
register struct dpx_s *dpx = &(tm->tm_dp.dp_adr->dpc_frdp);
if (DVDEBUG(tm))
fprintf(DVDBF(tm), "[tm03_evhrwak: %d]", (int)dp_xrtest(dpx));
if (dp_xrtest(dpx)) { /* Verify there's a message for us */
switch (dp_xrcmd(dpx)) {
case DPTM_MOUNT:
if (DVDEBUG(tm))
fprintf(DVDBF(tm), "[tm03_evhrwak: Tape Online!]\r\n");
if (tm->tm_slv == 0) { /* If still right slave */
tm_ssta(tm); /* update all status */
}
TMREG(tm, RHR_STS) |= TM_SSSC; /* Set Slave Status Change */
tm_attn(tm);
break;
default:
break;
}
dp_xrdone(dpx); /* just ACK it */
}
}
static int
tm03_start(register struct tmdev *tm)
{
if (tm->tm_state != TM03_ST_OFF) {
fprintf(DVDBF(tm), "[tm03_start: Already running?]\r\n");
return FALSE;
}
if (DVDEBUG(tm))
fprintf(DVDBF(tm), "[tm03_start: Starting DP \"%s\"...",
tm->tm_dpname);
if (!dp_start(&tm->tm_dp, tm->tm_dpname)) {
if (DVDEBUG(tm))
fprintf(DVDBF(tm), " failed!]\r\n");
else
fprintf(DVDBF(tm), "[tm03_start: Start of DP \"%s\" failed!]\r\n",
tm->tm_dpname);
return FALSE;
}
if (DVDEBUG(tm))
fprintf(DVDBF(tm), " started!]\r\n");
tm->tm_state = TM03_ST_READY;
return TRUE;
}
#endif /* KLH10_DEV_DPTM03 */
/* TM03_MOUNT - Mount or dismount a tape.
** If path is NULL, wants to dismount; argstr is ignored.
** If path is "", just wants status report.
** Else mounting tape; argstr if present has keyword params which
** are parsed by vmt_attrparse(), e.g.:
** "hard", "8mm", etc - indicate hardware device or type
** "ro" - Read-Only
** "rw" - Create then Read/Write (default)
** Returns:
** 0 - error. Error message already output to stream, if one.
** 1 - action succeeded.
*/
static int
tm03_mount(struct device *d, FILE *f, char *path, char *argstr)
{
register struct tmdev *tm = (struct tmdev *)d;
int err = FALSE;
char *opath;
#if KLH10_DEV_DPTM03
register size_t cnt;
opath = tm->tm_spath[0] ? tm->tm_spath : NULL;
#else
int prevmount = vmt_ismounted(&(tm->tm_vmt)); /* Get state */
opath = (prevmount ? vmt_tapepath(&(tm->tm_vmt)) : NULL);
#endif
if (path && !*path) {
/* Just wants mount status report */
if (!f) /* If no output stream, can't report */
return TRUE;
if (!opath) {
fprintf(f, "No tape mounted.\n");
return TRUE;
}
fprintf(f, "Current tape pathname is \"%s\", status", opath);
#if KLH10_DEV_DPTM03
switch (tm->tm_state) {
case TM03_ST_OFF:
fprintf(f, " OFF\n");
return TRUE;
case TM03_ST_BUSY:
fprintf(f, " BUSY");
break;
case TM03_ST_READY:
fprintf(f, " READY");
break;
default:
fprintf(f, " <\?\?%d\?\?>", tm->tm_state);
break;
}
if (tm->tm_sdptm->dptm_mol)
fprintf(f, " ONLINE");
if (tm->tm_sdptm->dptm_wrl)
fprintf(f, " WRITELOCKED");
#else
if (prevmount) {
fprintf(f, " ONLINE");
if (!vmt_iswritable(&(tm->tm_vmt)))
fprintf(f, " WRITELOCKED");
} else
fprintf(f, " OFFLINE");
#endif
fprintf(f, "\n");
return TRUE;
}
/* Unmount any existing tape, and mount new tape if one provided */
#if KLH10_DEV_DPTM03
/* Should this kill the subproc, or wait its turn to send a command?
** Don't want to hang waiting for rewind to complete!
*/
/* For now, return error if busy (sigh)
*/
if (tm->tm_state == TM03_ST_BUSY) {
fprintf(f, "Cannot %smount: slave busy\n", (path ? "" : "un"));
return FALSE;
}
if (tm->tm_state == TM03_ST_OFF) {
/* Subproc not running. If call is just unmounting, that's all,
** else must start it up so it can handle the mount.
*/
if (!path) {
tm->tm_spath[0] = '\0'; /* Make sure no current tapefile */
fprintf(f, "No tape mounted.\n");
return TRUE; /* OK, no tape mounted */
}
if (!tm03_start(tm)) /* Fire up the subproc! */
return FALSE;
}
/* At this point, state should be READY... */
if (!path) { /* Just unmounting current tape? */
cnt = 0; /* Tell DP to unmount */
tm->tm_sdptm->dptm_pathx = 0;
tm->tm_sdptm->dptm_argsx = 0;
tm->tm_buff[0] = '\0';
} else {
register unsigned char *cp = tm->tm_buff;
register size_t acnt;
cnt = strlen(path);
if (cnt > DVTM_MAXPATH-1)
cnt = DVTM_MAXPATH-1;
memcpy(tm->tm_spath, path, cnt); /* Remember pathname */
tm->tm_spath[cnt] = '\0';
acnt = argstr ? strlen(argstr) : 0;
if ((1+cnt+1+acnt+1) > DVTM_MAXRECSIZ) { /* Buff overflow chk */
fprintf(f, "Mount path & args too long! %ld?\n",
(long)DVTM_MAXRECSIZ);
return FALSE;
}
/* Copy path and args into DP comm buffer, including terminators */
*cp++ = '\0';
memcpy(cp, path, cnt);
cp += cnt;
*cp++ = '\0';
if (acnt) {
memcpy(cp, argstr, acnt);
}
cp[acnt] = '\0';
tm->tm_sdptm->dptm_pathx = 1;
tm->tm_sdptm->dptm_argsx = 1+cnt+1;
cnt = 1+cnt+1+acnt+1;
}
/* Do command! And hope for the best... */
if (!path)
fprintf(f, "Unmount requested\n");
else
fprintf(f, "Mount requested: \"%s\"\n", path);
tm->tm_scmd = TM_NOP; /* Conspire with tm_cmddon */
tm_dpcmd(tm, DPTM_MOUNT, (size_t)cnt);