-
Notifications
You must be signed in to change notification settings - Fork 41
/
config.c
1368 lines (1193 loc) · 41.4 KB
/
config.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
/* CONFIG.C (c) Copyright Jan Jaeger, 2000-2009 */
/* Device configuration functions */
/*-------------------------------------------------------------------*/
/* The original configuration builder is now called bldcfg.c */
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
#define _CONFIG_C_
#define _HENGINE_DLL_
#include "hercules.h"
#include "opcode.h"
#if !defined(_GEN_ARCH)
#if defined(_ARCHMODE3)
#define _GEN_ARCH _ARCHMODE3
#include "config.c"
#undef _GEN_ARCH
#endif
#if defined(_ARCHMODE2)
#define _GEN_ARCH _ARCHMODE2
#include "config.c"
#undef _GEN_ARCH
#endif
#if defined(OPTION_FISHIO)
#include "w32chan.h"
#endif // defined(OPTION_FISHIO)
/*-------------------------------------------------------------------*/
/* Function to terminate all CPUs and devices */
/*-------------------------------------------------------------------*/
void release_config()
{
DEVBLK *dev;
int cpu;
/* Deconfigure all CPU's */
OBTAIN_INTLOCK(NULL);
for (cpu = 0; cpu < MAX_CPU_ENGINES; cpu++)
if(IS_CPU_ONLINE(cpu))
deconfigure_cpu(cpu);
RELEASE_INTLOCK(NULL);
#if defined(OPTION_SHARED_DEVICES)
/* Terminate the shared device listener thread */
if (sysblk.shrdtid)
signal_thread (sysblk.shrdtid, SIGUSR2);
#endif
/* Detach all devices */
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
if (dev->allocated)
detach_subchan(SSID_TO_LCSS(dev->ssid), dev->subchan);
#if !defined(OPTION_FISHIO)
/* Terminate device threads */
obtain_lock (&sysblk.ioqlock);
sysblk.devtwait=0;
broadcast_condition (&sysblk.ioqcond);
release_lock (&sysblk.ioqlock);
#endif
} /* end function release_config */
/*-------------------------------------------------------------------*/
/* Function to start a new CPU thread */
/* Caller MUST own the intlock */
/*-------------------------------------------------------------------*/
int configure_cpu(int cpu)
{
int i;
char thread_name[16];
if(IS_CPU_ONLINE(cpu))
return -1;
snprintf(thread_name,sizeof(thread_name),"cpu%d thread",cpu);
thread_name[sizeof(thread_name)-1]=0;
if ( create_thread (&sysblk.cputid[cpu], DETACHED, cpu_thread,
&cpu, thread_name)
)
{
logmsg(_("HHCCF040E Cannot create CPU%4.4X thread: %s\n"),
cpu, strerror(errno));
return -1;
}
/* Find out if we are a cpu thread */
for (i = 0; i < MAX_CPU_ENGINES; i++)
if (sysblk.cputid[i] == thread_id())
break;
if (i < MAX_CPU_ENGINES)
sysblk.regs[i]->intwait = 1;
/* Wait for CPU thread to initialize */
wait_condition (&sysblk.cpucond, &sysblk.intlock);
if (i < MAX_CPU_ENGINES)
sysblk.regs[i]->intwait = 0;
return 0;
} /* end function configure_cpu */
/*-------------------------------------------------------------------*/
/* Function to remove a CPU from the configuration */
/* This routine MUST be called with the intlock held */
/*-------------------------------------------------------------------*/
int deconfigure_cpu(int cpu)
{
int i;
/* Find out if we are a cpu thread */
for (i = 0; i < MAX_CPU_ENGINES; i++)
if (sysblk.cputid[i] == thread_id())
break;
/* If we're NOT trying to deconfigure ourselves */
if (cpu != i)
{
if (!IS_CPU_ONLINE(cpu))
return -1;
/* Deconfigure CPU */
sysblk.regs[cpu]->configured = 0;
sysblk.regs[cpu]->cpustate = CPUSTATE_STOPPING;
ON_IC_INTERRUPT(sysblk.regs[cpu]);
/* Wake up CPU as it may be waiting */
WAKEUP_CPU (sysblk.regs[cpu]);
/* (if we're a cpu thread) */
if (i < MAX_CPU_ENGINES)
sysblk.regs[i]->intwait = 1;
/* Wait for CPU thread to terminate */
wait_condition (&sysblk.cpucond, &sysblk.intlock);
/* (if we're a cpu thread) */
if (i < MAX_CPU_ENGINES)
sysblk.regs[i]->intwait = 0;
join_thread (sysblk.cputid[cpu], NULL);
detach_thread( sysblk.cputid[cpu] );
}
else
{
/* Else we ARE trying to deconfigure ourselves */
sysblk.regs[cpu]->configured = 0;
sysblk.regs[cpu]->cpustate = CPUSTATE_STOPPING;
ON_IC_INTERRUPT(sysblk.regs[cpu]);
}
sysblk.cputid[cpu] = 0;
return 0;
} /* end function deconfigure_cpu */
/* 4 next functions used for fast device lookup cache management */
#if defined(OPTION_FAST_DEVLOOKUP)
static void AddDevnumFastLookup(DEVBLK *dev,U16 lcss,U16 devnum)
{
unsigned int Channel;
if(sysblk.devnum_fl==NULL)
{
sysblk.devnum_fl=(DEVBLK ***)malloc(sizeof(DEVBLK **)*256*FEATURE_LCSS_MAX);
memset(sysblk.devnum_fl,0,sizeof(DEVBLK **)*256*FEATURE_LCSS_MAX);
}
Channel=(devnum & 0xff00)>>8 | ((lcss & (FEATURE_LCSS_MAX-1))<<8);
if(sysblk.devnum_fl[Channel]==NULL)
{
sysblk.devnum_fl[Channel]=(DEVBLK **)malloc(sizeof(DEVBLK *)*256);
memset(sysblk.devnum_fl[Channel],0,sizeof(DEVBLK *)*256);
}
sysblk.devnum_fl[Channel][devnum & 0xff]=dev;
}
static void AddSubchanFastLookup(DEVBLK *dev,U16 ssid, U16 subchan)
{
unsigned int schw;
#if 0
logmsg(D_("DEBUG : ASFL Adding %d\n"),subchan);
#endif
if(sysblk.subchan_fl==NULL)
{
sysblk.subchan_fl=(DEVBLK ***)malloc(sizeof(DEVBLK **)*256*FEATURE_LCSS_MAX);
memset(sysblk.subchan_fl,0,sizeof(DEVBLK **)*256*FEATURE_LCSS_MAX);
}
schw=((subchan & 0xff00)>>8)|(SSID_TO_LCSS(ssid)<<8);
if(sysblk.subchan_fl[schw]==NULL)
{
sysblk.subchan_fl[schw]=(DEVBLK **)malloc(sizeof(DEVBLK *)*256);
memset(sysblk.subchan_fl[schw],0,sizeof(DEVBLK *)*256);
}
sysblk.subchan_fl[schw][subchan & 0xff]=dev;
}
static void DelDevnumFastLookup(U16 lcss,U16 devnum)
{
unsigned int Channel;
if(sysblk.devnum_fl==NULL)
{
return;
}
Channel=(devnum & 0xff00)>>8 | ((lcss & (FEATURE_LCSS_MAX-1))<<8);
if(sysblk.devnum_fl[Channel]==NULL)
{
return;
}
sysblk.devnum_fl[Channel][devnum & 0xff]=NULL;
}
static void DelSubchanFastLookup(U16 ssid, U16 subchan)
{
unsigned int schw;
#if 0
logmsg(D_("DEBUG : DSFL Removing %d\n"),subchan);
#endif
if(sysblk.subchan_fl==NULL)
{
return;
}
schw=((subchan & 0xff00)>>8)|(SSID_TO_LCSS(ssid) << 8);
if(sysblk.subchan_fl[schw]==NULL)
{
return;
}
sysblk.subchan_fl[schw][subchan & 0xff]=NULL;
}
#endif
DEVBLK *get_devblk(U16 lcss, U16 devnum)
{
DEVBLK *dev;
DEVBLK**dvpp;
if(lcss >= FEATURE_LCSS_MAX)
lcss = 0;
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
if (!(dev->allocated) && dev->ssid == LCSS_TO_SSID(lcss)) break;
if(!dev)
{
if (!(dev = (DEVBLK*)malloc(sizeof(DEVBLK))))
{
logmsg (_("HHCCF043E Cannot obtain device block\n"),
strerror(errno));
return NULL;
}
memset (dev, 0, sizeof(DEVBLK));
/* Initialize the device lock and conditions */
initialize_lock (&dev->lock);
initialize_condition (&dev->resumecond);
initialize_condition (&dev->iocond);
#if defined(OPTION_SCSI_TAPE)
initialize_condition (&dev->stape_sstat_cond);
InitializeListLink (&dev->stape_statrq.link);
InitializeListLink (&dev->stape_mntdrq.link);
dev->stape_statrq.dev = dev;
dev->stape_mntdrq.dev = dev;
dev->sstat = GMT_DR_OPEN(-1);
#endif
/* Search for the last device block on the chain */
for (dvpp = &(sysblk.firstdev); *dvpp != NULL;
dvpp = &((*dvpp)->nextdev));
/* Add the new device block to the end of the chain */
*dvpp = dev;
dev->ssid = LCSS_TO_SSID(lcss);
dev->subchan = sysblk.highsubchan[lcss]++;
}
/* Initialize the device block */
obtain_lock (&dev->lock);
dev->group = NULL;
dev->member = 0;
dev->cpuprio = sysblk.cpuprio;
dev->devprio = sysblk.devprio;
dev->hnd = NULL;
dev->devnum = devnum;
dev->chanset = lcss;
dev->fd = -1;
dev->syncio = 0;
dev->ioint.dev = dev;
dev->ioint.pending = 1;
dev->pciioint.dev = dev;
dev->pciioint.pcipending = 1;
dev->attnioint.dev = dev;
dev->attnioint.attnpending = 1;
dev->oslinux = sysblk.pgminttr == OS_LINUX;
/* Initialize storage view */
dev->mainstor = sysblk.mainstor;
dev->storkeys = sysblk.storkeys;
dev->mainlim = sysblk.mainsize - 1;
/* Initialize the path management control word */
memset (&dev->pmcw, 0, sizeof(PMCW));
dev->pmcw.devnum[0] = dev->devnum >> 8;
dev->pmcw.devnum[1] = dev->devnum & 0xFF;
dev->pmcw.lpm = 0x80;
dev->pmcw.pim = 0x80;
dev->pmcw.pom = 0xFF;
dev->pmcw.pam = 0x80;
dev->pmcw.chpid[0] = dev->devnum >> 8;
#if defined(OPTION_SHARED_DEVICES)
dev->shrdwait = -1;
#endif /*defined(OPTION_SHARED_DEVICES)*/
#ifdef _FEATURE_CHANNEL_SUBSYSTEM
/* Indicate a CRW is pending for this device */
#if defined(_370)
if (sysblk.arch_mode != ARCH_370)
#endif /*defined(_370)*/
dev->crwpending = 1;
#endif /*_FEATURE_CHANNEL_SUBSYSTEM*/
#ifdef EXTERNALGUI
if ( !dev->pGUIStat )
{
dev->pGUIStat = malloc( sizeof(GUISTAT) );
dev->pGUIStat->pszOldStatStr = dev->pGUIStat->szStatStrBuff1;
dev->pGUIStat->pszNewStatStr = dev->pGUIStat->szStatStrBuff2;
*dev->pGUIStat->pszOldStatStr = 0;
*dev->pGUIStat->pszNewStatStr = 0;
}
#endif /*EXTERNALGUI*/
/* Mark device valid */
dev->pmcw.flag5 |= PMCW5_V;
dev->allocated = 1;
return dev;
}
void ret_devblk(DEVBLK *dev)
{
/* Mark device invalid */
dev->allocated = 0;
dev->pmcw.flag5 &= ~PMCW5_V; // compat ZZ deprecated
release_lock(&dev->lock);
}
/*-------------------------------------------------------------------*/
/* Function to build a device configuration block */
/*-------------------------------------------------------------------*/
int attach_device (U16 lcss, U16 devnum, const char *type,
int addargc, char *addargv[])
{
DEVBLK *dev; /* -> Device block */
int rc; /* Return code */
int i; /* Loop index */
/* Check whether device number has already been defined */
if (find_device_by_devnum(lcss,devnum) != NULL)
{
logmsg (_("HHCCF041E Device %d:%4.4X already exists\n"), lcss,devnum);
return 1;
}
/* obtain device block */
dev = get_devblk(lcss,devnum);
if(!(dev->hnd = hdl_ghnd(type)))
{
logmsg (_("HHCCF042E Device type %s not recognized\n"), type);
ret_devblk(dev);
return 1;
}
dev->typname = strdup(type);
/* Copy the arguments */
dev->argc = addargc;
if (addargc)
{
dev->argv = malloc ( addargc * sizeof(BYTE *) );
for (i = 0; i < addargc; i++)
if (addargv[i])
dev->argv[i] = strdup(addargv[i]);
else
dev->argv[i] = NULL;
}
else
dev->argv = NULL;
/* Call the device handler initialization function */
rc = (dev->hnd->init)(dev, addargc, addargv);
if (rc < 0)
{
logmsg (_("HHCCF044E Initialization failed for device %4.4X\n"),
devnum);
for (i = 0; i < dev->argc; i++)
if (dev->argv[i])
free(dev->argv[i]);
if (dev->argv)
free(dev->argv);
free(dev->typname);
ret_devblk(dev);
return 1;
}
/* Obtain device data buffer */
if (dev->bufsize != 0)
{
dev->buf = malloc (dev->bufsize);
if (dev->buf == NULL)
{
logmsg (_("HHCCF045E Cannot obtain buffer "
"for device %4.4X: %s\n"),
dev->devnum, strerror(errno));
for (i = 0; i < dev->argc; i++)
if (dev->argv[i])
free(dev->argv[i]);
if (dev->argv)
free(dev->argv);
free(dev->typname);
ret_devblk(dev);
return 1;
}
}
/* Release device lock */
release_lock(&dev->lock);
#ifdef _FEATURE_CHANNEL_SUBSYSTEM
/* Signal machine check */
#if defined(_370)
if (sysblk.arch_mode != ARCH_370)
#endif
machine_check_crwpend();
#endif /*_FEATURE_CHANNEL_SUBSYSTEM*/
/*
if(lcss!=0 && sysblk.arch_mode==ARCH_370)
{
logmsg(_("HHCCF078W %d:%4.4X : Only devices on CSS 0 are usable in S/370 mode\n"),lcss,devnum);
}
*/
return 0;
} /* end function attach_device */
/*-------------------------------------------------------------------*/
/* Function to delete a device configuration block */
/*-------------------------------------------------------------------*/
static int detach_devblk (DEVBLK *dev)
{
int i; /* Loop index */
/* Obtain the device lock */
obtain_lock(&dev->lock);
#if defined(OPTION_FAST_DEVLOOKUP)
DelSubchanFastLookup(dev->ssid, dev->subchan);
if(dev->pmcw.flag5 & PMCW5_V)
DelDevnumFastLookup(SSID_TO_LCSS(dev->ssid),dev->devnum);
#endif
/* Close file or socket */
if ((dev->fd > 2) || dev->console)
/* Call the device close handler */
(dev->hnd->close)(dev);
for (i = 0; i < dev->argc; i++)
if (dev->argv[i])
free(dev->argv[i]);
if (dev->argv)
free(dev->argv);
free(dev->typname);
#ifdef _FEATURE_CHANNEL_SUBSYSTEM
/* Indicate a CRW is pending for this device */
#if defined(_370)
if (sysblk.arch_mode != ARCH_370)
#endif /*defined(_370)*/
dev->crwpending = 1;
#endif /*_FEATURE_CHANNEL_SUBSYSTEM*/
// detach all devices in group
if(dev->group)
{
int i;
dev->group->memdev[dev->member] = NULL;
if(dev->group->members)
{
dev->group->members = 0;
for(i = 0; i < dev->group->acount; i++)
{
if(dev->group->memdev[i] && dev->group->memdev[i]->allocated)
{
detach_devblk(dev->group->memdev[i]);
}
}
free(dev->group);
}
dev->group = NULL;
}
ret_devblk(dev);
/* Zeroize the PMCW */
memset (&dev->pmcw, 0, sizeof(PMCW));
#ifdef _FEATURE_CHANNEL_SUBSYSTEM
/* Signal machine check */
#if defined(_370)
if (sysblk.arch_mode != ARCH_370)
#endif
machine_check_crwpend();
#endif /*_FEATURE_CHANNEL_SUBSYSTEM*/
return 0;
} /* end function detach_devblk */
/*-------------------------------------------------------------------*/
/* Function to delete a device configuration block by subchannel */
/*-------------------------------------------------------------------*/
int detach_subchan (U16 lcss, U16 subchan)
{
DEVBLK *dev; /* -> Device block */
int rc;
/* Find the device block */
dev = find_device_by_subchan ((LCSS_TO_SSID(lcss)<<16)|subchan);
if (dev == NULL)
{
logmsg (_("HHCCF046E Subchannel %d:%4.4X does not exist\n"), lcss, subchan);
return 1;
}
rc = detach_devblk( dev );
if(!rc)
logmsg (_("HHCCF047I Subchannel %d:%4.4X detached\n"), lcss, subchan);
return rc;
}
/*-------------------------------------------------------------------*/
/* Function to delete a device configuration block by device number */
/*-------------------------------------------------------------------*/
int detach_device (U16 lcss,U16 devnum)
{
DEVBLK *dev; /* -> Device block */
int rc;
/* Find the device block */
dev = find_device_by_devnum (lcss,devnum);
if (dev == NULL)
{
logmsg (_("HHCCF046E Device %d:%4.4X does not exist\n"), lcss, devnum);
return 1;
}
rc = detach_devblk( dev );
if(!rc)
logmsg (_("HHCCF047I Device %4.4X detached\n"), devnum);
return rc;
}
/*-------------------------------------------------------------------*/
/* Function to rename a device configuration block */
/*-------------------------------------------------------------------*/
int define_device (U16 lcss, U16 olddevn,U16 newdevn)
{
DEVBLK *dev; /* -> Device block */
/* Find the device block */
dev = find_device_by_devnum (lcss, olddevn);
if (dev == NULL)
{
logmsg (_("HHCCF048E Device %d:%4.4X does not exist\n"), lcss, olddevn);
return 1;
}
/* Check that new device number does not already exist */
if (find_device_by_devnum(lcss, newdevn) != NULL)
{
logmsg (_("HHCCF049E Device %d:%4.4X already exists\n"), lcss, newdevn);
return 1;
}
/* Obtain the device lock */
obtain_lock(&dev->lock);
/* Update the device number in the DEVBLK */
dev->devnum = newdevn;
/* Update the device number in the PMCW */
dev->pmcw.devnum[0] = newdevn >> 8;
dev->pmcw.devnum[1] = newdevn & 0xFF;
/* Disable the device */
dev->pmcw.flag5 &= ~PMCW5_E;
#if defined(OPTION_FAST_DEVLOOKUP)
DelDevnumFastLookup(lcss,olddevn);
DelDevnumFastLookup(lcss,newdevn);
#endif
#ifdef _FEATURE_CHANNEL_SUBSYSTEM
/* Indicate a CRW is pending for this device */
#if defined(_370)
if (sysblk.arch_mode != ARCH_370)
#endif /*defined(_370)*/
dev->crwpending = 1;
#endif /*_FEATURE_CHANNEL_SUBSYSTEM*/
/* Release device lock */
release_lock(&dev->lock);
#ifdef _FEATURE_CHANNEL_SUBSYSTEM
/* Signal machine check */
#if defined(_370)
if (sysblk.arch_mode != ARCH_370)
#endif
machine_check_crwpend();
#endif /*_FEATURE_CHANNEL_SUBSYSTEM*/
// logmsg (_("HHCCF050I Device %4.4X defined as %4.4X\n"),
// olddevn, newdevn);
return 0;
} /* end function define_device */
/*-------------------------------------------------------------------*/
/* Function to group devblk's belonging to one device (eg OSA, LCS) */
/* */
/* group_device is intended to be called from within a device */
/* initialisation routine to group 1 or more devices to a logical */
/* device group. */
/* */
/* group_device will return true for the device that completes */
/* the device group. (ie the last device to join the group) */
/* */
/* when no group exists, and device group is called with a device */
/* count of zero, then no group will be created. Otherwise */
/* a new group will be created and the currently attaching device */
/* will be the first in the group. */
/* */
/* when a device in a group is detached, all devices in the group */
/* will be detached. The first device to be detached will enter */
/* its close routine with the group intact. Subsequent devices */
/* being detached will no longer have access to previously detached */
/* devices. */
/* */
/* Example of a fixed count device group: */
/* */
/* device_init(dev) */
/* { */
/* if( !device_group(dev, 2) ) */
/* return 0; */
/* */
/* ... all devices in the group have been attached, */
/* ... group initialisation may proceed. */
/* */
/* } */
/* */
/* */
/* Variable device group example: */
/* */
/* device_init(dev) */
/* { */
/* if( !group_device(dev, 0) && dev->group ) */
/* return 0; */
/* */
/* if( !device->group ) */
/* { */
/* ... process parameters to determine number of devices */
/* */
/* // Create group */
/* if( !group_device(dev, variable_count) ) */
/* return 0; */
/* } */
/* */
/* ... all devices in the group have been attached, */
/* ... group initialisation may proceed. */
/* } */
/* */
/* */
/* dev->group : pointer to DEVGRP structure or NULL */
/* dev->member : index into memdev array in DEVGRP structure for */
/* : current DEVBLK */
/* group->members : number of members in group */
/* group->acount : number active members in group */
/* group->memdev[] : array of DEVBLK pointers of member devices */
/* */
/* */
/* members will be equal to acount for a complete group */
/* */
/* */
/* Always: (for grouped devices) */
/* dev->group->memdev[dev->member] == dev */
/* */
/* */
/* Jan Jaeger, 23 Apr 2004 */
/*-------------------------------------------------------------------*/
DLL_EXPORT int group_device(DEVBLK *dev, int members)
{
DEVBLK *tmp;
// Find a compatible group that is incomplete
for (tmp = sysblk.firstdev;
tmp != NULL
&& (!tmp->allocated // not allocated
|| !tmp->group // not a group device
|| strcmp(tmp->typname,dev->typname) // unequal type
|| (tmp->group->members == tmp->group->acount) ); // complete
tmp = tmp->nextdev) ;
if(tmp)
{
// Join Group
dev->group = tmp->group;
dev->member = dev->group->acount++;
dev->group->memdev[dev->member] = dev;
}
else if(members)
{
// Allocate a new Group when requested
dev->group = malloc(sizeof(DEVGRP) + members * sizeof(DEVBLK *));
dev->group->members = members;
dev->group->acount = 1;
dev->group->memdev[0] = dev;
dev->member = 0;
}
return (dev->group && (dev->group->members == dev->group->acount));
}
/*-------------------------------------------------------------------*/
/* Function to find a device block given the device number */
/*-------------------------------------------------------------------*/
DLL_EXPORT DEVBLK *find_device_by_devnum (U16 lcss,U16 devnum)
{
DEVBLK *dev;
#if defined(OPTION_FAST_DEVLOOKUP)
DEVBLK **devtab;
int Chan;
Chan=(devnum & 0xff00)>>8 | ((lcss & (FEATURE_LCSS_MAX-1))<<8);
if(sysblk.devnum_fl!=NULL)
{
devtab=sysblk.devnum_fl[Chan];
if(devtab!=NULL)
{
dev=devtab[devnum & 0xff];
if(dev && dev->allocated && dev->pmcw.flag5 & PMCW5_V && dev->devnum==devnum)
{
return dev;
}
else
{
DelDevnumFastLookup(lcss,devnum);
}
}
}
#endif
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
if (dev->allocated && dev->devnum == devnum && lcss==SSID_TO_LCSS(dev->ssid) && dev->pmcw.flag5 & PMCW5_V) break;
#if defined(OPTION_FAST_DEVLOOKUP)
if(dev)
{
AddDevnumFastLookup(dev,lcss,devnum);
}
#endif
return dev;
} /* end function find_device_by_devnum */
/*-------------------------------------------------------------------*/
/* Function to find a device block given the subchannel number */
/*-------------------------------------------------------------------*/
DEVBLK *find_device_by_subchan (U32 ioid)
{
U16 subchan = ioid & 0xFFFF;
DEVBLK *dev;
#if defined(OPTION_FAST_DEVLOOKUP)
unsigned int schw = ((subchan & 0xff00)>>8)|(IOID_TO_LCSS(ioid)<<8);
#if 0
logmsg(D_("DEBUG : FDBS FL Looking for %d\n"),subchan);
#endif
if(sysblk.subchan_fl && sysblk.subchan_fl[schw] && sysblk.subchan_fl[schw][subchan & 0xff])
return sysblk.subchan_fl[schw][subchan & 0xff];
#endif
#if 0
logmsg(D_("DEBUG : FDBS SL Looking for %8.8x\n"),ioid);
#endif
for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
if (dev->ssid == IOID_TO_SSID(ioid) && dev->subchan == subchan) break;
#if defined(OPTION_FAST_DEVLOOKUP)
if(dev)
{
AddSubchanFastLookup(dev, IOID_TO_SSID(ioid), subchan);
}
else
{
DelSubchanFastLookup(IOID_TO_SSID(ioid), subchan);
}
#endif
return dev;
} /* end function find_device_by_subchan */
/*-------------------------------------------------------------------*/
/* Returns a CPU register context for the device, or else NULL */
/*-------------------------------------------------------------------*/
REGS *devregs(DEVBLK *dev)
{
/* If a register context already exists then use it */
if (dev->regs)
return dev->regs;
/* Otherwise attempt to determine what it should be */
{
int i;
TID tid = thread_id(); /* Our own thread id */
for (i=0; i < MAX_CPU; i++)
if (tid == sysblk.cputid[i]) /* Are we a cpu thread? */
return sysblk.regs[i]; /* yes, use its context */
}
return NULL; /* Not CPU thread. Return NULL register context */
}
/*-------------------------------------------------------------------*/
/* Internal device parsing structures */
/*-------------------------------------------------------------------*/
typedef struct _DEVARRAY
{
U16 cuu1;
U16 cuu2;
} DEVARRAY;
typedef struct _DEVNUMSDESC
{
BYTE lcss;
DEVARRAY *da;
} DEVNUMSDESC;
/*-------------------------------------------------------------------*/
/* Function to Parse a LCSS specification in a device number spec */
/* Syntax : [lcss:]Anything... */
/* Function args : */
/* const char * spec : Parsed string */
/* char **rest : Rest of string (or original str) */
/* Returns : */
/* int : 0 if not specified, 0<=n<FEATURE_LCSS_MAX */
/* -1 Spec error */
/* */
/* If the function returns a positive value, then *rest should */
/* be freed by the caller. */
/*-------------------------------------------------------------------*/
static int
parse_lcss(const char *spec,
char **rest,int verbose)
{
int lcssid;
char *wrk;
char *lcss;
char *r;
char *strptr;
char *garbage;
wrk=malloc(strlen(spec)+1);
strcpy(wrk,spec);
lcss=strtok(wrk,":");
if(lcss==NULL)
{
if(verbose)
{
logmsg(_("HHCCF074E Unspecified error occured while parsing Logical Channel Subsystem Identification\n"));
}
free(wrk);
return(-1);
}
r=strtok(NULL,":");
if(r==NULL)
{
*rest=wrk;
return 0;
}
garbage=strtok(NULL,":");
if(garbage!=NULL)
{
if(verbose)
{
logmsg(_("HHCCF075E No more than 1 Logical Channel Subsystem Identification may be specified\n"));
}
free(wrk);
return(-1);
}
lcssid=strtoul(lcss,&strptr,10);
if(*strptr!=0)
{
if(verbose)
{
logmsg(_("HHCCF076E Non numeric Logical Channel Subsystem Identification %s\n"),lcss);
}
free(wrk);
return -1;
}
if(lcssid>FEATURE_LCSS_MAX)
{
if(verbose)
{
logmsg(_("HHCCF077E Logical Channel Subsystem Identification %d exceeds maximum of %d\n"),lcssid,FEATURE_LCSS_MAX-1);
}
free(wrk);
return -1;
}
*rest=malloc(strlen(r)+1);
strcpy(*rest,r);
free(wrk);
return lcssid;
}
static int
parse_single_devnum__INTERNAL(const char *spec,
U16 *p_lcss,
U16 *p_devnum,
int verbose)
{
int rc;
U16 lcss;
char *r;
char *strptr;
rc=parse_lcss(spec,&r,verbose);
if(rc<0)
{
return -1;
}
lcss=rc;
rc=strtoul(r,&strptr,16);
if(rc<0 || rc>0xffff || *strptr!=0)
{
if(verbose)
{
logmsg(_("HHCCF055E Incorrect device address specification near character %c\n"),*strptr);
}
free(r);
return -1;
}