1 /* HSTRUCTS.H   (c) Copyright Roger Bowler, 1999-2009                */
2 /*              Hercules Structure Definitions                       */
3 
4 #ifndef _HSTRUCTS_H
5 #define _HSTRUCTS_H
6 
7 #include "hercules.h"
8 #include "opcode.h"
9 
10 /*-------------------------------------------------------------------*/
11 /* Typedefs for CPU bitmap fields                                    */
12 /*                                                                   */
13 /* A CPU bitmap contains one bit for each processing engine.         */
14 /* The width of the bitmap depends on the maximum number of          */
15 /* processing engines which was selected at build time.              */
16 /*-------------------------------------------------------------------*/
17 #if MAX_CPU_ENGINES <= 32
18     typedef U32                 CPU_BITMAP;
19     #define F_CPU_BITMAP        "%8.8"I32_FMT"X"
20 #elif MAX_CPU_ENGINES <= 64
21     typedef U64                 CPU_BITMAP;
22     #define F_CPU_BITMAP        "%16.16"I64_FMT"X"
23 #elif MAX_CPU_ENGINES <= 128
24  #if defined(_MSVC_)
25    #error MAX_CPU_ENGINES > 64 not supported in Windows
26  #endif
27  #if SIZEOF_SIZE_T == 4
28    #error MAX_CPU_ENGINES > 64 only supported on 64 bit platforms
29  #endif
30     typedef __uint128_t         CPU_BITMAP;
31 // ZZ FIXME: No printf format support for __int128 yet, so we will incorrectly display...
32     #define F_CPU_BITMAP        "%16.16"I64_FMT"X"
33 #else
34  #error MAX_CPU_ENGINES cannot exceed 128
35 #endif
36 
37 /*-------------------------------------------------------------------*/
38 /* Structure definition for CPU register context                     */
39 /*-------------------------------------------------------------------*/
40 struct REGS {                           /* Processor registers       */
41 #define HDL_VERS_REGS   "3.08"          /* Internal Version Number   */
42 #define HDL_SIZE_REGS   sizeof(REGS)
43 
44         int     arch_mode;              /* Architectural mode        */
45 
46         DW      px;                     /* Prefix register           */
47         PSW     psw;                    /* Program status word       */
48         BYTE   *ip;                     /* Mainstor inst address     */
49 
50      /* AIA - Instruction fetch accelerator                          */
51         BYTE   *aip;                    /* Mainstor page address     */
52         uintptr_t aim;                  /* Mainstor xor address      */
53         BYTE   *aie;                    /* Mainstor page end address */
54         DW      aiv;                    /* Virtual page address      */
55 
56         U64     bear;                   /* Breaking event address reg*/
57         BYTE   *bear_ip;                /* Breaking event inst ptr   */
58 
59         DW      gr[16];                 /* General registers         */
60 
61         DW      cr[16+16+1];            /* 16 Control registers      */
62 #define CR_ALB_OFFSET   16              /* 16 Accesslist lookaside   */
63 #define CR_ASD_REAL     32              /*  1 Real asd register      */
64 
65         U32     ar[16];                 /* Access registers          */
66         U32     fpr[32];                /* Floating point registers  */
67         U32     fpc;                    /* IEEE Floating Point
68                                                     Control Register */
69         U32     dxc;                    /* Data exception code       */
70         DW      mc;                     /* Monitor Code              */
71         DW      ea;                     /* Exception address         */
72         DW      et;                     /* Execute Target address    */
73 
74         unsigned int                    /* Flags (cpu thread only)   */
75                 execflag:1,             /* 1=EXecuted instruction    */
76                 exrl:1,                 /* 1=EXRL, 0=EX instruction  */
77                 permode:1,              /* 1=PER active              */
78                 instinvalid:1,          /* 1=Inst field is invalid   */
79                 opinterv:1,             /* 1=Operator intervening    */
80                 checkstop:1,            /* 1=CPU is checkstop-ed     */
81                 hostint:1,              /* 1=Host generated interrupt*/
82                 host:1,                 /* REGS are hostregs         */
83                 guest:1;                /* REGS are guestregs        */
84         unsigned int                    /* Flags (intlock serialized)*/
85                 dummy:1,                /* 1=Dummy regs structure    */
86                 configured:1,           /* 1=CPU is online           */
87                 loadstate:1,            /* 1=CPU is in load state    */
88                 ghostregs:1,            /* 1=Ghost registers (panel) */
89                 invalidate:1,           /* 1=Do AIA/AEA invalidation */
90                 tracing:1,              /* 1=Trace is active         */
91                 stepwait:1,             /* 1=Wait in inst stepping   */
92                 sigpreset:1,            /* 1=SIGP cpu reset received */
93                 sigpireset:1;           /* 1=SIGP initial cpu reset  */
94 
95         S64     cpu_timer;              /* CPU timer epoch           */
96         S64     int_timer;              /* S/370 Interval timer      */
97         S32     old_timer;              /* S/370 Interval timer int  */
98         U64     clkc;                   /* 0-7=Clock comparator epoch,
99                                            8-63=Comparator bits 0-55 */
100         S64     tod_epoch;              /* TOD epoch for this CPU    */
101         S64     ecps_vtimer;            /* ECPS Virtual Int. timer   */
102         S32     ecps_oldtmr;            /* ECPS Virtual Int. tmr int */
103         BYTE   *ecps_vtmrpt;            /* Pointer to VTMR or zero   */
104         U32     instcount;              /* Instruction counter       */
105         U64     prevcount;              /* Previous instruction count*/
106         U32     mipsrate;               /* Instructions per second   */
107         U32     siocount;               /* SIO/SSCH counter          */
108         U32     siosrate;               /* IOs per second            */
109         U64     siototal;               /* Total SIO/SSCH count      */
110         int     cpupct;                 /* Percent CPU busy          */
111         U64     waittod;                /* Time of day last wait (us)*/
112         U64     waittime;               /* Wait time (us) in interval*/
113         DAT     dat;                    /* Fields for DAT use        */
114 
115 #define GR_G(_r) gr[(_r)].D
116 #define GR_H(_r) gr[(_r)].F.H.F          /* Fullword bits 0-31       */
117 #define GR_HHH(_r) gr[(_r)].F.H.H.H.H    /* Halfword bits 0-15       */
118 #define GR_HHL(_r) gr[(_r)].F.H.H.L.H    /* Halfword low, bits 16-31 */
119 #define GR_HHLCL(_r) gr[(_r)].F.H.H.L.B.L   /* Character, bits 24-31 */
120 #define GR_L(_r) gr[(_r)].F.L.F          /* Fullword low, bits 32-63 */
121 #define GR_LHH(_r) gr[(_r)].F.L.H.H.H    /* Halfword bits 32-47      */
122 #define GR_LHL(_r) gr[(_r)].F.L.H.L.H    /* Halfword low, bits 48-63 */
123 #define GR_LHHCH(_r) gr[(_r)].F.L.H.H.B.H   /* Character, bits 32-39 */
124 #define GR_LA24(_r) gr[(_r)].F.L.A.A     /* 24 bit addr, bits 40-63  */
125 #define GR_LA8(_r) gr[(_r)].F.L.A.B      /* 24 bit addr, unused bits */
126 #define GR_LHLCL(_r) gr[(_r)].F.L.H.L.B.L   /* Character, bits 56-63 */
127 #define GR_LHLCH(_r) gr[(_r)].F.L.H.L.B.H   /* Character, bits 48-55 */
128 #define CR_G(_r)   cr[(_r)].D            /* Bits 0-63                */
129 #define CR_H(_r)   cr[(_r)].F.H.F        /* Fullword bits 0-31       */
130 #define CR_HHH(_r) cr[(_r)].F.H.H.H.H    /* Halfword bits 0-15       */
131 #define CR_HHL(_r) cr[(_r)].F.H.H.L.H    /* Halfword low, bits 16-31 */
132 #define CR_L(_r)   cr[(_r)].F.L.F        /* Fullword low, bits 32-63 */
133 #define CR_LHH(_r) cr[(_r)].F.L.H.H.H    /* Halfword bits 32-47      */
134 #define CR_LHHCH(_r) cr[(_r)].F.L.H.H.B.H   /* Character, bits 32-39 */
135 #define CR_LHL(_r) cr[(_r)].F.L.H.L.H    /* Halfword low, bits 48-63 */
136 #define MC_G      mc.D
137 #define MC_L      mc.F.L.F
138 #define EA_G      ea.D
139 #define EA_L      ea.F.L.F
140 #define ET_G      et.D
141 #define ET_L      et.F.L.F
142 #define PX_G      px.D
143 #define PX_L      px.F.L.F
144 #define AIV_G     aiv.D
145 #define AIV_L     aiv.F.L.F
146 #define AR(_r)    ar[(_r)]
147 
148         U16     chanset;                /* Connected channel set     */
149         U32     todpr;                  /* TOD programmable register */
150         U16     monclass;               /* Monitor event class       */
151         U16     cpuad;                  /* CPU address for STAP      */
152         BYTE    excarid;                /* Exception access register */
153         BYTE    opndrid;                /* Operand access register   */
154         BYTE    exinst[8];              /* Target of Execute (EX)    */
155         BYTE   *mainstor;               /* -> Main storage           */
156         BYTE   *storkeys;               /* -> Main storage key array */
157         RADR    mainlim;                /* Central Storage limit or  */
158                                         /* guest storage limit (SIE) */
159         PSA_3XX *psa;                   /* -> PSA for this CPU       */
160 
161      /*
162       * The fields hostregs and guestregs have been move outside the
163       * scope of _FEATURE_SIE to reduce conditional code.
164       *
165       *   sysblk.regs[i] always points to the host regs
166       *   flag `host' is always 1 for the host regs
167       *   flag `guest' is always 1 for the guest regs
168       *   `hostregs' is always equal to sysblk.regs[i] (in both
169       *       hostregs and guestregs)
170       *   `guestregs' is always equal to sysblk.regs[i]->guestregs
171       *       (in both hostregs and guestregs).
172       *       sysblk.regs[i]->guestregs is NULL until the first SIE
173       *       instruction is executed on that CPU.
174       *   `sie_active' is 1 in hostregs if SIE is executing
175       *       and the current register context is `guestregs'
176       *   `sie_mode' is 1 in guestregs always
177       *   `sie_state' has the real address of the SIEBK
178       *   `siebk' has the mainstor address of the SIEBK
179       */
180         REGS   *hostregs;               /* Pointer to the hypervisor
181                                            register context          */
182         REGS   *guestregs;              /* Pointer to the guest
183                                            register context          */
184         SYSBLK *sysblk;                 /* Pointer to sysblk         */
185 
186 #if defined(_FEATURE_SIE)
187         RADR    sie_state;              /* Address of the SIE state
188                                            descriptor block or 0 when
189                                            not running under SIE     */
190         SIEBK  *siebk;                  /* Sie State Desc structure  */
191         RADR    sie_px;                 /* Host address of guest px  */
192         RADR    sie_mso;                /* Main Storage Origin       */
193         RADR    sie_xso;                /* eXpanded Storage Origin   */
194         RADR    sie_xsl;                /* eXpanded Storage Limit    */
195         RADR    sie_rcpo;               /* Ref and Change Preserv.   */
196         RADR    sie_scao;               /* System Contol Area        */
197         S64     sie_epoch;              /* TOD offset in state desc. */
198 #endif /*defined(_FEATURE_SIE)*/
199         unsigned int
200                 sie_active:1,           /* SIE active (host only)    */
201                 sie_mode:1,             /* Running under SIE (guest) */
202                 sie_pref:1;             /* Preferred-storage mode    */
203 
204 // #if defined(FEATURE_PER)
205         U16     perc;                   /* PER code                  */
206         RADR    peradr;                 /* PER address               */
207         BYTE    peraid;                 /* PER access id             */
208 // #endif /*defined(FEATURE_PER)*/
209 
210         CPU_BITMAP cpubit;              /* Only this CPU's bit is 1  */
211         U32     ints_state;             /* CPU Interrupts Status     */
212         U32     ints_mask;              /* Respective Interrupts Mask*/
213      /*
214       * Making the following flags 'stand-alone' (instead of bit-
215       * flags like they were) addresses a compiler bit-flag serial-
216       * ization issue that occurs with the 'SYNCHRONIZE_CPUS' macro
217       * used during synchronize broadcast (cpu<->cpu communication)
218       */
219         int     intwait;                /* 1=Waiting on intlock      */
220         int     syncio;                 /* 1=Synchronous i/o active  */
221 
222         BYTE    cpustate;               /* CPU stopped/started state */
223         BYTE    malfcpu                 /* Malfuction alert flags    */
224                     [MAX_CPU_ENGINES];  /* for each CPU (1=pending)  */
225         BYTE    emercpu                 /* Emergency signal flags    */
226                     [MAX_CPU_ENGINES];  /* for each CPU (1=pending)  */
227         U16     extccpu;                /* CPU causing external call */
228         BYTE    inst[8];                /* Fetched instruction when
229                                            instruction crosses a page
230                                            boundary                  */
231         BYTE    *invalidate_main;       /* Mainstor addr to invalidat*/
232         PSW     captured_zpsw;          /* Captured-z/Arch PSW reg   */
233 #if defined(_FEATURE_VECTOR_FACILITY)
234         VFREGS *vf;                     /* Vector Facility           */
235 #endif /*defined(_FEATURE_VECTOR_FACILITY)*/
236 
237         jmp_buf progjmp;                /* longjmp destination for
238                                            program check return      */
239         jmp_buf archjmp;                /* longjmp destination to
240                                            switch architecture mode  */
241         jmp_buf exitjmp;                /* longjmp destination for
242                                            CPU thread exit           */
243         COND    intcond;                /* CPU interrupt condition   */
244         LOCK    *cpulock;               /* CPU lock for this CPU     */
245 
246      /* Mainstor address lookup accelerator                          */
247 
248         BYTE    aea_mode;               /* aea addressing mode       */
249 
250         int     aea_ar[16+5];           /* arn to cr number          */
251                                         /* 5 Special registers       */
252 
253         BYTE    aea_common[16+16+1];    /* 1=asd is not private      */
254                                         /* 16 Accesslist lookaside   */
255                                         /*  1 Real asd register      */
256 
257         BYTE    aea_aleprot[16];        /* ale protected             */
258 
259      /* Function pointers */
260         pi_func program_interrupt;
261         func    trace_br;
262 
263      /* ------------------------------------------------------------ */
264         U64     regs_copy_end;          /* Copy regs to here         */
265      /* ------------------------------------------------------------ */
266 
267      /* Opcode table pointers                                        */
268 
269         FUNC    s370_opcode_table[256];
270         FUNC   *s370_opcode_a4xx,
271                *s370_opcode_a5xx,
272                *s370_opcode_a6xx,
273  #if defined(MULTI_BYTE_ASSIST)
274                 s370_opcode_a7xx[256],
275                 s370_opcode_b2xx[256],
276                 s370_opcode_b9xx[256],
277                 s370_opcode_c0xx[256],                          /*@N3*/
278                 s370_opcode_e3xx[256],                          /*@N3*/
279                 s370_opcode_ebxx[256],
280  #else
281                *s370_opcode_a7xx,
282                *s370_opcode_b2xx,
283                *s370_opcode_b9xx,
284                *s370_opcode_c0xx,                               /*@N3*/
285                *s370_opcode_e3xx,                               /*@N3*/
286                *s370_opcode_ebxx,
287  #endif
288                *s370_opcode_b3xx,                               /*FPE*/
289                *s370_opcode_c2xx,                               /*208*/
290                *s370_opcode_c4xx,                               /*208*/
291                *s370_opcode_c6xx,                               /*208*/
292                *s370_opcode_e4xx,
293                *s370_opcode_e5xx,
294                *s370_opcode_e6xx,
295                *s370_opcode_ecxx,                               /*@N3*/
296                *s370_opcode_edxx;
297 
298         FUNC    s390_opcode_table[256];
299         FUNC   *s390_opcode_01xx,
300                *s390_opcode_a4xx,
301                *s390_opcode_a5xx,
302                *s390_opcode_a6xx,
303  #if defined(MULTI_BYTE_ASSIST)
304                 s390_opcode_a7xx[256],
305                 s390_opcode_b2xx[256],
306                 s390_opcode_b9xx[256],
307                 s390_opcode_c0xx[256],
308                 s390_opcode_e3xx[256],
309                 s390_opcode_ebxx[256],
310  #else
311                *s390_opcode_a7xx,
312                *s390_opcode_b2xx,
313                *s390_opcode_b9xx,
314                *s390_opcode_c0xx,
315                *s390_opcode_e3xx,
316                *s390_opcode_ebxx,
317  #endif
318                *s390_opcode_b3xx,
319                *s390_opcode_c2xx,
320                *s390_opcode_c4xx,                               /*208*/
321                *s390_opcode_c6xx,                               /*208*/
322                *s390_opcode_e4xx,
323                *s390_opcode_e5xx,
324                *s390_opcode_ecxx,
325                *s390_opcode_edxx;
326 
327         FUNC    z900_opcode_table[256];
328         FUNC   *z900_opcode_01xx,
329                *z900_opcode_a5xx,
330  #if defined(MULTI_BYTE_ASSIST)
331                 z900_opcode_a7xx[256],
332                 z900_opcode_b2xx[256],
333                 z900_opcode_b9xx[256],
334                 z900_opcode_c0xx[256],
335                 z900_opcode_e3xx[256],
336                 z900_opcode_ebxx[256],
337  #else
338                *z900_opcode_a7xx,
339                *z900_opcode_b2xx,
340                *z900_opcode_b9xx,
341                *z900_opcode_c0xx,
342                *z900_opcode_e3xx,
343                *z900_opcode_ebxx,
344  #endif
345                *z900_opcode_b3xx,
346                *z900_opcode_c2xx,
347                *z900_opcode_c4xx,                               /*208*/
348                *z900_opcode_c6xx,                               /*208*/
349                *z900_opcode_c8xx,
350                *z900_opcode_ccxx,                               /*810*/
351                *z900_opcode_e5xx,
352                *z900_opcode_ecxx,
353                *z900_opcode_edxx;
354 
355      /* TLB - Translation lookaside buffer                           */
356 
357         unsigned int tlbID;             /* Validation identifier     */
358         TLB     tlb;                    /* Translation lookaside buf */
359 
360 };
361 
362 /*-------------------------------------------------------------------*/
363 /* Structure definition for the Vector Facility                      */
364 /*-------------------------------------------------------------------*/
365 #if defined(_FEATURE_VECTOR_FACILITY)
366 struct VFREGS {                          /* Vector Facility Registers*/
367         unsigned int
368                 online:1;               /* 1=VF is online            */
369         U64     vsr;                    /* Vector Status Register    */
370         U64     vac;                    /* Vector Activity Count     */
371         BYTE    vmr[VECTOR_SECTION_SIZE/8];  /* Vector Mask Register */
372         U32     vr[16][VECTOR_SECTION_SIZE]; /* Vector Registers     */
373 };
374 #endif /*defined(_FEATURE_VECTOR_FACILITY)*/
375 
376 // #if defined(FEATURE_REGION_RELOCATE)
377 /*-------------------------------------------------------------------*/
378 /* Zone Parameter Block                                              */
379 /*-------------------------------------------------------------------*/
380 struct ZPBLK {
381         RADR mso;                      /* Main Storage Origin        */
382         RADR msl;                      /* Main Storage Length        */
383         RADR eso;                      /* Expanded Storage Origin    */
384         RADR esl;                      /* Expanded Storage Length    */
385         RADR mbo;                      /* Measurement block origin   */
386         BYTE mbk;                      /* Measurement block key      */
387         int  mbm;                      /* Measurement block mode     */
388         int  mbd;                      /* Device connect time mode   */
389 };
390 // #endif /*defined(FEATURE_REGION_RELOCATE)*/
391 
392 /*-------------------------------------------------------------------*/
393 /* System configuration block                                        */
394 /*-------------------------------------------------------------------*/
395 struct SYSBLK {
396 #define HDL_VERS_SYSBLK   "3.06"        /* Internal Version Number   */
397 #define HDL_SIZE_SYSBLK   sizeof(SYSBLK)
398         time_t  impltime;               /* TOD system was IMPL'ed    */
399         int     arch_mode;              /* Architecturual mode       */
400                                         /* 0 == S/370   (ARCH_370)   */
401                                         /* 1 == ESA/390 (ARCH_390)   */
402                                         /* 2 == ESAME   (ARCH_900)   */
403         int     arch_z900;              /* 1 == ESAME supported      */
404         RADR    mainsize;               /* Main storage size (bytes) */
405         BYTE   *mainstor;               /* -> Main storage           */
406         BYTE   *storkeys;               /* -> Main storage key array */
407         U32     xpndsize;               /* Expanded size (4K pages)  */
408         BYTE   *xpndstor;               /* -> Expanded storage       */
409         U64     todstart;               /* Time of initialisation    */
410         U64     cpuid;                  /* CPU identifier for STIDP  */
411         TID     impltid;                /* Thread-id for main progr. */
412         TID     wdtid;                  /* Thread-id for watchdog    */
413         U16     lparnuml;               /* #digits (0-2) in lparnum  */
414         U16     lparnum;                /* LPAR identification number*/
415         U16     ipldev;                 /* IPL device                */
416         int     iplcpu;                 /* IPL cpu                   */
417         int     ipllcss;                /* IPL lcss                  */
418         int     numcpu;                 /* Number of CPUs installed  */
419         int     numvec;                 /* Number vector processors  */
420         int     maxcpu;                 /* Max number of CPUs        */
421         int     cpus;                   /* Number CPUs configured    */
422         int     hicpu;                  /* Hi cpu + 1 configured     */
423         int     sysepoch;               /* TOD clk epoch (1900/1960) */
424         int     topology;               /* Configuration topology... */
425 #define TOPOLOGY_HORIZ  0               /* ...horizontal polarization*/
426 #define TOPOLOGY_VERT   1               /* ...vertical polarization  */
427         int     topchnge;               /* 1 = Topology Change Report
428                                            pending (CPU cfg on/off)  */
429         COND    cpucond;                /* CPU config/deconfig cond  */
430         LOCK    cpulock[MAX_CPU_ENGINES];  /* CPU lock               */
431         TID     cputid[MAX_CPU_ENGINES];   /* CPU thread identifiers */
432         BYTE    ptyp[MAX_CPU_ENGINES];  /* SCCB ptyp for each engine */
433         LOCK    todlock;                /* TOD clock update lock     */
434         TID     todtid;                 /* Thread-id for TOD update  */
435         REGS   *regs[MAX_CPU_ENGINES+1];   /* Registers for each CPU */
436 
437 #if defined(_FEATURE_MESSAGE_SECURITY_ASSIST)
438         LOCK    wklock;                 /* Update lock               */
439         BYTE    wkaes_reg[32];          /* Wrapping-key registers    */
440         BYTE    wkdea_reg[24];
441         BYTE    wkvpaes_reg[32];        /* Wrapping-key Verification */
442         BYTE    wkvpdea_reg[24];        /* Pattern registers         */
443 #endif /*defined(_FEATURE_MESSAGE_SECURITY_ASSIST)*/
444 
445      /* CPU Measurement Counter facility
446         CPU Measurement Sampling facility
447         Load Program Parameter facility */
448         U64     program_parameter;      /* Program Parameter Register*/
449 
450 #if defined(_FEATURE_VECTOR_FACILITY)
451         VFREGS  vf[MAX_CPU_ENGINES];    /* Vector Facility           */
452 #endif /*defined(_FEATURE_VECTOR_FACILITY)*/
453 #if defined(_FEATURE_SIE)
454         ZPBLK   zpb[FEATURE_SIE_MAXZONES];  /* SIE Zone Parameter Blk*/
455 #endif /*defined(_FEATURE_SIE)*/
456 #if defined(OPTION_FOOTPRINT_BUFFER)
457         REGS    footprregs[MAX_CPU_ENGINES][OPTION_FOOTPRINT_BUFFER];
458         U32     footprptr[MAX_CPU_ENGINES];
459 #endif
460 
461 #define LOCK_OWNER_NONE  0xFFFF
462 #define LOCK_OWNER_OTHER 0xFFFE
463         U16     mainowner;              /* Mainlock owner            */
464         U16     intowner;               /* Intlock owner             */
465 
466         LOCK    mainlock;               /* Main storage lock         */
467         LOCK    intlock;                /* Interrupt lock            */
468         LOCK    iointqlk;               /* I/O Interrupt Queue lock  */
469         LOCK    sigplock;               /* Signal processor lock     */
470         ATTR    detattr;                /* Detached thread attribute */
471         ATTR    joinattr;               /* Joinable thread attribute */
472 #define  DETACHED  &sysblk.detattr      /* (helper macro)            */
473 #define  JOINABLE  &sysblk.joinattr     /* (helper macro)            */
474         TID     cnsltid;                /* Thread-id for console     */
475         TID     socktid;                /* Thread-id for sockdev     */
476                                         /* 3270 Console Keep-Alive:  */
477         int     kaidle;                 /* Keepalive idle seconds    */
478         int     kaintv;                 /* Keepalive probe interval  */
479         int     kacnt;                  /* Keepalive probe count     */
480 #if defined( OPTION_WAKEUP_SELECT_VIA_PIPE )
481         LOCK    cnslpipe_lock;          /* signaled flag access lock */
482         int     cnslpipe_flag;          /* 1 == already signaled     */
483         int     cnslwpipe;              /* fd for sending signal     */
484         int     cnslrpipe;              /* fd for receiving signal   */
485         LOCK    sockpipe_lock;          /* signaled flag access lock */
486         int     sockpipe_flag;          /* 1 == already signaled     */
487         int     sockwpipe;              /* Sockdev signaling pipe Wr */
488         int     sockrpipe;              /* Sockdev signaling pipe Rd */
489 #endif // defined( OPTION_WAKEUP_SELECT_VIA_PIPE )
490         RADR    mbo;                    /* Measurement block origin  */
491         BYTE    mbk;                    /* Measurement block key     */
492         int     mbm;                    /* Measurement block mode    */
493         int     mbd;                    /* Device connect time mode  */
494         int     diag8cmd;               /* Allow diagnose 8 commands */
495 #define DIAG8CMD_ECHO     0x80          /* Echo command to console   */
496 #define DIAG8CMD_ENABLE   0x01          /* Enable DIAG8 interface    */
497         BYTE    shcmdopt;               /* 'sh'ell command option    */
498 #define SHCMDOPT_DISABLE  0x80          /* Globally disable 'sh' cmd */
499 #define SHCMDOPT_NODIAG8  0x40          /* Disallow only for DIAG8   */
500         int     panrate;                /* Panel refresh rate        */
501         int     timerint;               /* microsecs timer interval  */
502         char   *pantitle;               /* Alt console panel title   */
503 #if defined(OPTION_HAO)
504         TID     haotid;                 /* Herc Auto-Oper thread-id  */
505 #endif /* defined(OPTION_HAO) */
506 #if defined(OPTION_SCSI_TAPE)
507         /* Access to all SCSI fields controlled by sysblk.stape_lock */
508         LOCK    stape_lock;             /* LOCK for all SCSI fields  */
509         int     auto_scsi_mount_secs;   /* Check for SCSI tape mount
510                                            frequency; 0 == disabled  */
511 #define DEFAULT_AUTO_SCSI_MOUNT_SECS  (5)
512         TID     stape_getstat_tid;      /* Tape-status worker thread */
513         TID     stape_mountmon_tid;     /* Tape-mount  worker thread */
514         COND    stape_getstat_cond;     /* Tape-status thread COND   */
515         u_int   stape_getstat_busy:1;   /* 1=Status thread is busy   */
516         LIST_ENTRY  stape_status_link;  /* get status request chain  */
517         LIST_ENTRY  stape_mount_link;   /* scsimount  request chain  */
518         struct  timeval
519                 stape_query_status_tod; /* TOD of last status query  */
520 #endif /* defined(OPTION_SCSI_TAPE) */
521         DEVBLK *firstdev;               /* -> First device block     */
522         DEVBLK *sysgdev;                /* -> devblk for SYSG console*/
523 #if defined(OPTION_FAST_DEVLOOKUP)
524         DEVBLK ***devnum_fl;            /* 1st level table for fast  */
525                                         /* devnum lookup             */
526         DEVBLK ***subchan_fl;           /* Subchannel table fast     */
527                                         /* lookup table              */
528 #endif  /* FAST_DEVICE_LOOKUP */
529         U16     highsubchan[FEATURE_LCSS_MAX];  /* Highest subchan+1 */
530         U32     chp_reset[8];           /* Channel path reset masks  */
531         IOINT  *iointq;                 /* I/O interrupt queue       */
532 #if !defined(OPTION_FISHIO)
533         DEVBLK *ioq;                    /* I/O queue                 */
534         LOCK    ioqlock;                /* I/O queue lock            */
535         COND    ioqcond;                /* I/O queue condition       */
536         int     devtwait;               /* Device threads waiting    */
537         int     devtnbr;                /* Number of device threads  */
538         int     devtmax;                /* Max device threads        */
539         int     devthwm;                /* High water mark           */
540         int     devtunavail;            /* Count thread unavailable  */
541 #endif // !defined(OPTION_FISHIO)
542         RADR    addrlimval;             /* Address limit value (SAL) */
543 #if defined(FEATURE_VM_BLOCKIO)
544         U16     servcode;               /* External interrupt code   */
545         BYTE    biosubcd;               /* Block I/O sub int. code   */
546         BYTE    biostat;                /* Block I/O status          */
547         U64     bioparm;                /* Block I/O interrupt parm  */
548         DEVBLK  *biodev;                /* Block I/O device          */
549         /* Note: biodev is only used to detect BIO interrupt tracing */
550 #endif /* defined(FEATURE_VM_BLOCKIO) */
551         U32     servparm;               /* Service signal parameter  */
552         unsigned int                    /* Flags                     */
553                 daemon_mode:1,          /* Daemon mode active        */
554                 panel_init:1,           /* Panel display initialized */
555                 npquiet:1,              /* New Panel quiet indicator */
556                 sigintreq:1,            /* 1 = SIGINT request pending*/
557                 insttrace:1,            /* 1 = Instruction trace     */
558                 inststep:1,             /* 1 = Instruction step      */
559                 shutdown:1,             /* 1 = shutdown requested    */
560                 shutfini:1,             /* 1 = shutdown complete     */
561 #if defined( _MSVC_ )
562                 shutimmed:1,            /* 1 = shutdown req immed    */
563 #endif // defined( _MSVC_ )
564                 main_clear:1,           /* 1 = mainstor is cleared   */
565                 xpnd_clear:1,           /* 1 = xpndstor is cleared   */
566                 showregsfirst:1,        /* 1 = show regs before inst */
567                 showregsnone:1,         /* 1 = show no registers     */
568                 nomountedtapereinit:1,  /* 1 = disallow tape devinit
569                                              if tape already mounted */
570                 legacysenseid:1,        /* ena/disa senseid on       */
571                                         /*   legacy devices          */
572 #if defined(OPTION_IPLPARM)
573                 haveiplparm:1,          /* IPL PARM a la VM          */
574 #endif
575                 logoptnotime:1;         /* 1 = don't timestamp log   */
576         U32     ints_state;             /* Common Interrupts Status  */
577         CPU_BITMAP config_mask;         /* Configured CPUs           */
578         CPU_BITMAP started_mask;        /* Started CPUs              */
579         CPU_BITMAP waiting_mask;        /* Waiting CPUs              */
580         U64     traceaddr[2];           /* Tracing address range     */
581         U64     stepaddr[2];            /* Stepping address range    */
582 #if defined(OPTION_IPLPARM)
583         BYTE    iplparmstring[64];      /* 64 bytes loadable at IPL  */
584 #endif
585 #ifdef FEATURE_ECPSVM
586 //
587         /* ECPS:VM */
588         struct {
589             u_int level:16;
590             u_int debug:1;
591             u_int available:1;
592         } ecpsvm;                       /* ECPS:VM structure         */
593 //
594 #endif
595         U64     pgminttr;               /* Program int trace mask    */
596         int     pcpu;                   /* Tgt CPU panel cmd & displ */
597         int     hercprio;               /* Hercules process priority */
598         int     todprio;                /* TOD Clock thread priority */
599         int     cpuprio;                /* CPU thread priority       */
600         int     devprio;                /* Device thread priority    */
601         TID     httptid;                /* HTTP listener thread id   */
602         U16     httpport;               /* HTTP port number or zero  */
603         int     httpauth;               /* HTTP auth required flag   */
604         char   *httpuser;               /* HTTP userid               */
605         char   *httppass;               /* HTTP password             */
606         char   *httproot;               /* HTTP root                 */
607 #if defined( OPTION_TAPE_AUTOMOUNT )
608         TAMDIR *tamdir;                 /* Acc/Rej AUTOMOUNT dir ctl */
609         char   *defdir;                 /* Default AUTOMOUNT dir     */
610 #endif
611      /* Fields used by SYNCHRONIZE_CPUS */
612         int     syncing;                /* 1=Sync in progress        */
613         CPU_BITMAP sync_mask;           /* CPU mask for syncing CPUs */
614         COND    sync_cond;              /* COND for syncing CPU      */
615         COND    sync_bc_cond;           /* COND for other CPUs       */
616 #if defined(_FEATURE_ASN_AND_LX_REUSE)
617         int     asnandlxreuse;          /* ASN And LX Reuse enable   */
618 #endif
619 #if defined(OPTION_SHARED_DEVICES)
620         TID     shrdtid;                /* Shared device listener    */
621         U16     shrdport;               /* Shared device server port */
622         U32     shrdcount;              /* IO count                  */
623         SHRD_TRACE  *shrdtrace;         /* Internal trace table      */
624         SHRD_TRACE  *shrdtracep;        /* Current pointer           */
625         SHRD_TRACE  *shrdtracex;        /* End of trace table        */
626         int          shrdtracen;        /* Number of entries         */
627 #endif
628 #ifdef OPTION_IODELAY_KLUDGE
629         int     iodelay;                /* I/O delay kludge for linux*/
630 #endif /*OPTION_IODELAY_KLUDGE*/
631 #if defined( HTTP_SERVER_CONNECT_KLUDGE )
632         int     http_server_kludge_msecs;
633 #endif // defined( HTTP_SERVER_CONNECT_KLUDGE )
634 #if !defined(NO_SETUID)
635         uid_t   ruid, euid, suid;
636         gid_t   rgid, egid, sgid;
637 #endif /*!defined(NO_SETUID)*/
638 
639 #if defined(OPTION_COUNTING)
640         long long count[OPTION_COUNTING];
641 #define COUNT(n) sysblk.count[(n)]++
642 #else
643 #define COUNT(n)
644 #endif
645 
646 #if defined(OPTION_INSTRUCTION_COUNTING)
647         LOCK  icount_lock;
648 #define IMAP_FIRST sysblk.imap01
649         U64 imap01[256];
650         U64 imapa4[256];
651         U64 imapa5[16];
652         U64 imapa6[256];
653         U64 imapa7[16];
654         U64 imapb2[256];
655         U64 imapb3[256];
656         U64 imapb9[256];
657         U64 imapc0[16];
658         U64 imapc2[16];                                         /*@Z9*/
659         U64 imapc4[16];                                         /*208*/
660         U64 imapc6[16];                                         /*208*/
661         U64 imapc8[16];
662         U64 imape3[256];
663         U64 imape4[256];
664         U64 imape5[256];
665         U64 imapeb[256];
666         U64 imapec[256];
667         U64 imaped[256];
668         U64 imapxx[256];
669 #define IMAP_SIZE \
670             ( sizeof(sysblk.imap01) \
671             + sizeof(sysblk.imapa4) \
672             + sizeof(sysblk.imapa5) \
673             + sizeof(sysblk.imapa6) \
674             + sizeof(sysblk.imapa7) \
675             + sizeof(sysblk.imapb2) \
676             + sizeof(sysblk.imapb3) \
677             + sizeof(sysblk.imapb9) \
678             + sizeof(sysblk.imapc0) \
679             + sizeof(sysblk.imapc2) /*@Z9*/ \
680             + sizeof(sysblk.imapc4) /*208*/ \
681             + sizeof(sysblk.imapc6) /*208*/ \
682             + sizeof(sysblk.imapc8) \
683             + sizeof(sysblk.imape3) \
684             + sizeof(sysblk.imape4) \
685             + sizeof(sysblk.imape5) \
686             + sizeof(sysblk.imapeb) \
687             + sizeof(sysblk.imapec) \
688             + sizeof(sysblk.imaped) \
689             + sizeof(sysblk.imapxx) )
690 #endif
691 
692         char    *logofile;              /* Fancy 3270 logo box       */
693         char    **herclogo;             /* 3270 Logo data            */
694         size_t  logolines;              /* Number of lines in logo   */
695 #if defined(OPTION_MIPS_COUNTING)
696         /* Merged Counters for all CPUs                              */
697         U64     instcount;              /* Instruction counter       */
698         U32     mipsrate;               /* Instructions per second   */
699         U32     siosrate;               /* IOs per second            */
700 #endif /*defined(OPTION_MIPS_COUNTING)*/
701 
702 #ifdef OPTION_CMDTGT
703         int     cmdtgt;                 /* 0=herc,1=scp,2=!scp       */
704 #endif // OPTION_CMDTGT
705 
706         int     regs_copy_len;          /* Length to copy for REGS   */
707 
708         REGS    dummyregs;              /* Regs for unconfigured CPU */
709 
710 #ifdef OPTION_MSGHLD
711         int     keep_timeout_secs;      /* Message hold time         */
712 #endif
713 
714 };
715 
716 /*-------------------------------------------------------------------*/
717 /* I/O interrupt queue entry                                         */
718 /*-------------------------------------------------------------------*/
719 
720 struct IOINT {                          /* I/O interrupt queue entry */
721         IOINT  *next;                   /* -> next interrupt entry   */
722         DEVBLK *dev;                    /* -> Device block           */
723         int     priority;               /* Device priority           */
724         unsigned int
725                 pending:1,              /* 1=Normal interrupt        */
726                 pcipending:1,           /* 1=PCI interrupt           */
727                 attnpending:1;          /* 1=ATTN interrupt          */
728 };
729 
730 /*-------------------------------------------------------------------*/
731 /* SCSI support threads request structures...   (i.e. work items)    */
732 /*-------------------------------------------------------------------*/
733 
734 #if defined(OPTION_SCSI_TAPE)
735 
736   struct STSTATRQ                       /* Status Update Request     */
737   {
738       LIST_ENTRY   link;                /* just a link in the chain  */
739       DEVBLK*      dev;                 /* ptr to device block       */
740   };
741   typedef struct STSTATRQ  STSTATRQ;
742 
743   struct STMNTDRQ                       /* Automatic Mount Request   */
744   {
745       LIST_ENTRY   link;                /* just a link in the chain  */
746       DEVBLK*      dev;                 /* ptr to device block       */
747   };
748   typedef struct STMNTDRQ  STMNTDRQ;
749 
750 #endif /* defined(OPTION_SCSI_TAPE) */
751 
752 /*-------------------------------------------------------------------*/
753 /* Device configuration block                                        */
754 /*-------------------------------------------------------------------*/
755 struct DEVBLK {                         /* Device configuration block*/
756 #define HDL_VERS_DEVBLK   "3.08"        /* Internal Version Number   */
757 #define HDL_SIZE_DEVBLK   sizeof(DEVBLK)
758         DEVBLK *nextdev;                /* -> next device block      */
759         REGS   *regs;                   /* -> REGS if syncio         */
760         LOCK    lock;                   /* Device block lock         */
761         int     allocated;              /* Device block free/in use  */
762 
763         /*  device identification                                    */
764 
765         U16     ssid;                   /* Subsystem ID incl. lcssid */
766         U16     subchan;                /* Subchannel number         */
767         U16     devnum;                 /* Device number             */
768         U16     devtype;                /* Device type               */
769         U16     chanset;                /* Channel Set to which this
770                                            device is connected S/370 */
771         char    *typname;               /* Device type name          */
772 
773         int    member;                  /* Group member number       */
774         DEVGRP *group;                  /* Device Group              */
775 
776         int     argc;                   /* Init number arguments     */
777         char    **argv;                 /* Init arguments            */
778 
779         /*  Storage accessible by device                             */
780 
781         BYTE   *mainstor;               /* -> Main storage           */
782         BYTE   *storkeys;               /* -> Main storage key array */
783         RADR    mainlim;                /* Central Storage limit or  */
784                                         /* guest storage limit (SIE) */
785         char    filename[PATH_MAX+1];   /* filename (plus poss "|")  */
786 
787         /*  device i/o fields...                                     */
788 
789         int     fd;                     /* File desc / socket number */
790         FILE   *fh;                     /* associated File handle    */
791         bind_struct* bs;                /* -> bind_struct if socket-
792                                            device, NULL otherwise    */
793 
794         /*  device buffer management fields                          */
795 
796         int     bufcur;                 /* Buffer data identifier    */
797         BYTE   *buf;                    /* -> Device data buffer     */
798         int     bufsize;                /* Device data buffer size   */
799         int     buflen;                 /* Device buffer length used */
800         int     bufoff;                 /* Offset into data buffer   */
801         int     bufres;                 /* buffer residual length    */
802         int     bufoffhi;               /* Highest offset allowed    */
803         int     bufupdlo;               /* Lowest offset updated     */
804         int     bufupdhi;               /* Highest offset updated    */
805         U32     bufupd;                 /* 1=Buffer updated          */
806 
807         /*  device cache management fields                           */
808 
809         int     cache;                  /* Current cache index       */
810         int     cachehits;              /* Cache hits                */
811         int     cachemisses;            /* Cache misses              */
812         int     cachewaits;             /* Cache waits               */
813 
814         /*  device compression support                               */
815 
816         int     comps;                  /* Acceptable compressions   */
817         int     comp;                   /* Compression used          */
818         int     compoff;                /* Offset to compressed data */
819 
820         /*  device i/o scheduling fields...                          */
821 
822         TID     tid;                    /* Thread-id executing CCW   */
823         int     priority;               /* I/O q scehduling priority */
824         DEVBLK *nextioq;                /* -> next device in I/O q   */
825         IOINT   ioint;                  /* Normal i/o interrupt
826                                                queue entry           */
827         IOINT   pciioint;               /* PCI i/o interrupt
828                                                queue entry           */
829         IOINT   attnioint;              /* ATTN i/o interrupt
830                                                queue entry           */
831         int     cpuprio;                /* CPU thread priority       */
832         int     devprio;                /* Device thread priority    */
833 
834         /*  fields used during ccw execution...                      */
835         BYTE    chained;                /* Command chain and data chain
836                                            bits from previous CCW    */
837         BYTE    prev_chained;           /* Chaining flags from CCW
838                                            preceding the data chain  */
839         BYTE    code;                   /* Current CCW opcode        */
840         BYTE    prevcode;               /* Previous CCW opcode       */
841         int     ccwseq;                 /* CCW sequence number       */
842 
843         U32     ccwaddr;
844         U16     idapmask;
845         BYTE    idawfmt;
846         BYTE    ccwfmt;
847         BYTE    ccwkey;
848 
849         /*  device handler function pointers...                      */
850 
851         DEVHND *hnd;                    /* -> Device handlers        */
852         /* Supplemental handler functions - Set by init handler @ISW */
853         /* Function invoked during HDV/HIO & HSCH instructions  @ISW */
854         /* processing occurs in channel.c in haltio et al.      @ISW */
855         /* when the device is busy, but the channel subsystem   @ISW */
856         /* does not know how to perform the halt itself but has @ISW */
857         /* to rely on the handler to perform the halt           @ISW */
858         void ( *halt_device)(DEVBLK *);                      /* @ISW */
859 
860         DEVIM   *immed;                 /* Model Specific IM codes   */
861                                         /* (overrides devhnd immed)  */
862         int     is_immed;               /* Last command is Immediate */
863 
864         /*  emulated architecture fields...   (MUST be aligned!)     */
865 
866         int     reserved1;              /* ---(ensure alignment)---- */
867         ORB     orb;                    /* Operation request blk @IWZ*/
868         PMCW    pmcw;                   /* Path management ctl word  */
869         SCSW    scsw;                   /* Subchannel status word(XA)*/
870         SCSW    pciscsw;                /* PCI subchannel status word*/
871         SCSW    attnscsw;               /* ATTNsubchannel status word*/
872         BYTE    csw[8];                 /* Channel status word(S/370)*/
873         BYTE    pcicsw[8];              /* PCI channel status word   */
874         BYTE    attncsw[8];             /* ATTN channel status word  */
875         ESW     esw;                    /* Extended status word      */
876         BYTE    ecw[32];                /* Extended control word     */
877         U32     numsense;               /* Number of sense bytes     */
878         BYTE    sense[256];             /* Sense bytes 3480+ 64 bytes*/
879         U32     numdevid;               /* Number of device id bytes */
880         BYTE    devid[256];             /* Device identifier bytes   */
881         U32     numdevchar;             /* Number of devchar bytes   */
882         BYTE    devchar[64];            /* Device characteristics    */
883         BYTE    pgstat;                 /* Path Group Status         */
884         BYTE    pgid[11];               /* Path Group ID             */
885         BYTE    reserved2[4];           /* (pad/align/unused/avail)  */
886         COND    resumecond;             /* Resume condition          */
887         COND    iocond;                 /* I/O active condition      */
888         int     iowaiters;              /* Number of I/O waiters     */
889         int     ioactive;               /* System Id active on device*/
890 #define DEV_SYS_NONE    0               /* No active system on device*/
891 #define DEV_SYS_LOCAL   0xffff          /* Local system active on dev*/
892         BYTE    drvpwd[11];             /* Password for drive        */
893         BYTE    reserved3;              /* (pad/align/unused/avail)  */
894 
895         /*  control flags...                                         */
896 
897         unsigned int                    /* Flags                     */
898 #ifdef OPTION_CKD_KEY_TRACING
899                 ckdkeytrace:1,          /* 1=Log CKD_KEY_TRACE       */
900 #endif /*OPTION_CKD_KEY_TRACING*/
901                 syncio:2,               /* 1=Synchronous I/Os allowed*/
902                 shared:1,               /* 1=Device is shareable     */
903                 console:1,              /* 1=Console device          */
904                 connected:1,            /* 1=Console client connected*/
905                 readpending:2,          /* 1=Console read pending    */
906                 connecting:1,           /* 1=Connecting to remote    */
907                 localhost:1,            /* 1=Remote is local         */
908                 batch:1,                /* 1=Called by dasdutil      */
909                 dasdcopy:1,             /* 1=Called by dasdcopy      */
910                 oslinux:1,              /* 1=Linux                   */
911                 ccwtrace:1,             /* 1=CCW trace               */
912                 ccwstep:1,              /* 1=CCW single step         */
913                 cdwmerge:1;             /* 1=Channel will merge data
914                                              chained write CCWs      */
915 
916         unsigned int                    /* Device state - serialized
917                                             by dev->lock             */
918                 busy:1,                 /* 1=Device is busy          */
919                 reserved:1,             /* 1=Device is reserved      */
920                 suspended:1,            /* 1=Channel pgm suspended   */
921                 pending:1,              /* 1=I/O interrupt pending   */
922                 pcipending:1,           /* 1=PCI interrupt pending   */
923                 attnpending:1,          /* 1=ATTN interrupt pending  */
924                 startpending:1,         /* 1=startio pending         */
925                 resumesuspended:1;      /* 1=Hresuming suspended dev */
926 #define IOPENDING(_dev) ((_dev)->pending || (_dev)->pcipending || (_dev)->attnpending)
927 #define INITIAL_POWERON_370() \
928     ( dev->crwpending && ARCH_370 == sysblk.arch_mode )
929         int     crwpending;             /* 1=CRW pending             */
930         int     syncio_active;          /* 1=Synchronous I/O active  */
931         int     syncio_retry;           /* 1=Retry I/O asynchronously*/
932 
933         /*  Synchronous I/O                                          */
934 
935         U32     syncio_addr;            /* Synchronous i/o ccw addr  */
936         U64     syncios;                /* Number synchronous I/Os   */
937         U64     asyncios;               /* Number asynchronous I/Os  */
938 
939         /*  Device dependent data (generic)                          */
940         void    *dev_data;
941 
942 #ifdef EXTERNALGUI
943         /*  External GUI fields                                      */
944         GUISTAT* pGUIStat;              /* EXTERNALGUI Dev Stat Ctl  */
945 #endif
946 
947 #if defined(FEATURE_VM_BLOCKIO)
948         /* VM DIAGNOSE X'250' Emulation Environment                  */
949         struct VMBIOENV *vmd250env;     /* Established environment   */
950 #endif /* defined(FEATURE_VM_BLOCKIO) */
951 
952         /*  Fields for remote devices                                */
953 
954         struct in_addr rmtaddr;         /* Remote address            */
955         U16     rmtport;                /* Remote port number        */
956         U16     rmtnum;                 /* Remote device number      */
957         int     rmtid;                  /* Remote Id                 */
958         int     rmtrel;                 /* Remote release level      */
959         DBLWRD  rmthdr;                 /* Remote header             */
960         int     rmtcomp;                /* Remote compression parm   */
961         int     rmtcomps;               /* Supported compressions    */
962         int     rmtpurgen;              /* Remote purge count        */
963         FWORD  *rmtpurge;               /* Remote purge list         */
964 
965 #ifdef OPTION_SHARED_DEVICES
966         /*  Fields for device sharing                                */
967         TID     shrdtid;                /* Device thread id          */
968         int     shrdid;                 /* Id for next client        */
969         int     shrdconn;               /* Number connected clients  */
970         int     shrdwait;               /* Signal indicator          */
971         SHRD   *shrd[SHARED_MAX_SYS];   /* ->SHRD block              */
972 #endif
973 
974         /*  Device dependent fields for console                      */
975 
976         struct in_addr ipaddr;          /* Client IP address         */
977         in_addr_t  acc_ipaddr;          /* Allowable clients IP addr */
978         in_addr_t  acc_ipmask;          /* Allowable clients IP mask */
979         U32     rlen3270;               /* Length of data in buffer  */
980         int     pos3270;                /* Current screen position   */
981         int     keybdrem;               /* Number of bytes remaining
982                                            in keyboard read buffer   */
983         u_int   eab3270:1;              /* 1=Extended attributes     */
984         u_int   ewa3270:1;              /* 1=Last erase was EWA      */
985         u_int   prompt1052:1;           /* 1=Prompt for linemode i/p */
986         BYTE    aid3270;                /* Current input AID value   */
987         BYTE    mod3270;                /* 3270 model number         */
988 
989         /*  Device dependent fields for cardrdr                      */
990 
991         char    **more_files;           /* for more that one file in
992                                            reader */
993         char    **current_file;         /* counts how many additional
994                                            reader files are avail    */
995         int     cardpos;                /* Offset of next byte to be
996                                            read from data buffer     */
997         int     cardrem;                /* Number of bytes remaining
998                                            in data buffer            */
999         u_int   multifile:1;            /* 1=auto-open next i/p file */
1000         u_int   rdreof:1;               /* 1=Unit exception at EOF   */
1001         u_int   ebcdic:1;               /* 1=Card deck is EBCDIC     */
1002         u_int   ascii:1;                /* 1=Convert ASCII to EBCDIC */
1003         u_int   trunc:1;                /* Truncate overlength record*/
1004         u_int   autopad:1;              /* 1=Pad incomplete last rec
1005                                            to 80 bytes if EBCDIC     */
1006 
1007         /*  Device dependent fields for ctcadpt                      */
1008 
1009         DEVBLK *ctcpair;                /* -> Paired device block    */
1010         int     ctcpos;                 /* next byte offset          */
1011         int     ctcrem;                 /* bytes remaining in buffer */
1012         int     ctclastpos;             /* last packet read          */
1013         int     ctclastrem;             /* last packet read          */
1014         u_int   ctcxmode:1;             /* 1=Extended, 0=Basic mode  */
1015         BYTE    ctctype;                /* CTC_xxx device type       */
1016         BYTE    netdevname[IFNAMSIZ];   /* network device name       */
1017 
1018         /*  Device dependent fields for ctcadpt : Enhanced CTC  @PJJ */
1019 
1020         U16     ctcePktSeq;             /* CTCE Packet Sequence @PJJ */
1021                                         /*      # in debug msgs @PJJ */
1022         int     ctceSndSml;             /* CTCE Send Small size @PJJ */
1023         BYTE    ctcexState;             /* CTCE State   x-side  @PJJ */
1024         BYTE    ctcexCmd;               /* CTCE Command x-side  @PJJ */
1025         BYTE    ctceyState;             /* CTCE State   y-side  @PJJ */
1026         BYTE    ctceyCmd;               /* CTCE Command y-side  @PJJ */
1027         BYTE    ctceyCmdSCB;            /* CTCE Cmd SCB source  @PJJ */
1028         BYTE    ctce_UnitStat;          /* CTCE final UnitStat  @PJJ */
1029         int     ctcefd;                 /* CTCE RecvThread File @PJJ */
1030                                         /*      Desc / socket # @PJJ */
1031         LOCK    ctceEventLock;          /* CTCE Condition LOCK  @PJJ */
1032         COND    ctceEvent;              /* CTCE Recvd Condition @PJJ */
1033         int     ctce_lport;             /* CTCE Local  port #   @PJJ */
1034         int     ctce_rport;             /* CTCE Remote port #   @PJJ */
1035         struct in_addr ctce_ipaddr;     /* CTCE Dest IP addr    @PJJ */
1036         u_int   ctce_contention_loser:1;/* CTCE cmd collision   @PJJ */
1037         u_int   ctce_ccw_flags_cc:1;    /* CTCE ccw in progres  @PJJ */
1038 
1039         /*  Device dependent fields for printer                      */
1040 
1041         int     printpos;               /* Number of bytes already
1042                                            placed in print buffer    */
1043         int     printrem;               /* Number of bytes remaining
1044                                            in print buffer           */
1045         pid_t   ptpcpid;                /* print-to-pipe child pid   */
1046         u_int   crlf:1;                 /* 1=CRLF delimiters, 0=LF   */
1047         u_int   diaggate:1;             /* 1=Diagnostic gate command */
1048         u_int   fold:1;                 /* 1=Fold to upper case      */
1049         u_int   ispiped:1;              /* 1=Piped device            */
1050         u_int   stopprt:1;              /* 1=stopped; 0=started      */
1051         u_int   notrunc:1;              /* 1=do not truncate at open */
1052 
1053         u_int   fcbsupp:1;              /* fcb support flag          */
1054         u_int   cc:1;                   /* emit line controls        */
1055         u_int   rawcc:1;                /* emit just cc(hex) and data*/
1056         u_int   fcbcheck:1;             /* signal FCB errors         */
1057         u_int   nofcbcheck:1;           /* ignore FCB errors         */
1058         u_int   ccpend:1;               /* cc process pending        */
1059         u_int   chskip:1;               /* cc process pending        */
1060 
1061         int     print;                  /* optimize for print   0    */
1062         int     browse;                 /* optimize for browse  1    */
1063 
1064         int     lpi;                    /* lines per inch 6/8        */
1065         int     index;                  /* 3211 indexing             */
1066         int     lpp;                    /* lines per page            */
1067         int     ffchan ;                /* ff when skip here         */
1068 #define FCBSIZE 256
1069         int     fcb[FCBSIZE+1];         /* FCB image                 */
1070         int     fcbisdef;               /* FCB is default            */
1071 
1072         int     prevline;               /* previous line number      */
1073         int     currline;               /* curr line number          */
1074         int     destline;               /* destination  line number  */
1075 
1076         /*  Device dependent fields for tapedev                      */
1077 
1078         void   *omadesc;                /* -> OMA descriptor array   */
1079         U16     omafiles;               /* Number of OMA tape files  */
1080         U16     curfilen;               /* Current file number       */
1081         U32     blockid;                /* Current device block ID   */
1082         off_t   nxtblkpos;              /* Offset from start of file
1083                                            to next block             */
1084         off_t   prvblkpos;              /* Offset from start of file
1085                                            to previous block         */
1086         U16     curblkrem;              /* Number of bytes unread
1087                                            from current block        */
1088         U16     curbufoff;              /* Offset into buffer of data
1089                                            for next data chained CCW */
1090         U16     tapssdlen;              /* #of bytes of data prepared
1091                                            for Read Subsystem Data   */
1092         HETB   *hetb;                   /* HET control block         */
1093 
1094         struct                          /* HET device parms          */
1095         {
1096           u_int compress:1;             /* 1=Compression enabled     */
1097           u_int method:3;               /* Compression method        */
1098           u_int level:4;                /* Compression level         */
1099           u_int strictsize:1;           /* Strictly enforce MAXSIZE  */
1100           u_int displayfeat:1;          /* Device has a display      */
1101                                         /* feature installed         */
1102           u_int deonirq:1;              /* DE on IRQ on tape motion  */
1103                                         /* MVS 3.8j workaround       */
1104           u_int logical_readonly:1;     /* Tape is forced READ ONLY  */
1105           U16   chksize;                /* Chunk size                */
1106           off_t maxsize;                /* Maximum allowed TAPE file
1107                                            size                      */
1108         }       tdparms;                /* HET device parms          */
1109 
1110         off_t   eotmargin;              /* Amount of space left before
1111                                            reporting EOT (in bytes)  */
1112         u_int   fenced:1;               /* 1=Pos err; volume fenced  */
1113         u_int   readonly:1;             /* 1=Tape is write-protected */
1114         u_int   sns_pending:1;          /* Contingency Allegiance    */
1115                                         /* - means : don't build a   */
1116                                         /* sense on X'04' : it's     */
1117                                         /* aleady there              */
1118                                         /* NOTE : flag cleared by    */
1119                                         /*        sense command only */
1120                                         /*        or a device init   */
1121         u_int   SIC_supported:1;        /* 1=Spec Intcpt Cond support*/
1122         u_int   SIC_active:1;           /* 1=SIC active              */
1123         u_int   forced_logging:1;       /* 1=Forced Error Logging    */
1124         u_int   eotwarning:1;           /* 1=EOT warning area reached*/
1125 #if defined( OPTION_TAPE_AUTOMOUNT )
1126         u_int   noautomount:1;          /* 1=AUTOMOUNT disabled      */
1127 #endif
1128         u_int   supvr_inhibit:1;        /* 1=Supvr-Inhibit mode      */
1129         u_int   write_immed:1;          /* 1=Write-Immediate mode    */
1130 #if defined(OPTION_SCSI_TAPE)
1131         struct mtget mtget;             /* SCSI tape status struct   */
1132 #define sstat  mtget.mt_gstat           /* Generic SCSI tape device-
1133                                            independent status field;
1134                                            (struct mtget->mt_gstat)  */
1135         u_int   stape_close_rewinds:1;  /* 1=Rewind at close         */
1136         u_int   stape_blkid_32:1;       /* 1=block-ids are 32 bits   */
1137         u_int   stape_no_erg:1;         /* 1=ignore Erase Gap CCWs   */
1138         /* Access to SCSI fields controlled via sysblk.stape_lock    */
1139         COND      stape_sstat_cond;     /* Tape-status updated COND  */
1140         STSTATRQ  stape_statrq;         /* Status request structure  */
1141         STMNTDRQ  stape_mntdrq;         /* Mounted request structure */
1142 #endif /* defined(OPTION_SCSI_TAPE) */
1143         U32     msgid;                  /* Message Id of async. i/o  */
1144         BYTE    tapedevt;               /* Hercules tape device type */
1145         TAPEMEDIA_HANDLER *tmh;         /* Tape Media Handling       */
1146                                         /* dispatcher                */
1147 
1148         /* ---------- Autoloader feature --------------------------- */
1149         TAPEAUTOLOADENTRY *als;          /* Autoloader stack         */
1150         int     alss;                    /* Autoloader stack size    */
1151         int     alsix;                   /* Current Autoloader index */
1152         char  **al_argv;                 /* ARGV in autoloader       */
1153         int     al_argc;                 /* ARGC in autoloader       */
1154         /* ---------- end Autoloader feature ----------------------- */
1155 
1156         /* 3480/3490/3590 Message display */
1157 
1158         char    tapemsg1[9];            /* 1st Host Message          */
1159         char    tapemsg2[9];            /* 2nd Host Message          */
1160         char    tapesysmsg[32];         /*     Unit Message     (SYS)*/
1161         char   *prev_tapemsg;           /* Previously displayed msg  */
1162 
1163         BYTE    tapedisptype;           /* Type of message display   */
1164         BYTE    tapedispflags;          /* How the msg is displayed  */
1165 
1166 #define TAPEDISPTYP_IDLE           0    /* "READY" "NT RDY" etc (SYS)*/
1167 #define TAPEDISPTYP_LOCATING       1    /* Locate in progress   (SYS)*/
1168 #define TAPEDISPTYP_ERASING        2    /* DSE in progress      (SYS)*/
1169 #define TAPEDISPTYP_REWINDING      3    /* Rewind in progress   (SYS)*/
1170 #define TAPEDISPTYP_UNLOADING      4    /* Unload in progress   (SYS)*/
1171 #define TAPEDISPTYP_CLEAN          5    /* Clean recommended    (SYS)*/
1172 #define TAPEDISPTYP_MOUNT          6    /* Display Until Mounted     */
1173 #define TAPEDISPTYP_UNMOUNT        7    /* Display Until Unmounted   */
1174 #define TAPEDISPTYP_UMOUNTMOUNT    8    /* Display #1 Until Unmounted,
1175                                               then #2 Until Mounted  */
1176 #define TAPEDISPTYP_WAITACT        9    /* Display until motion      */
1177 
1178 #define IS_TAPEDISPTYP_SYSMSG( dev ) \
1179     (0 \
1180      || TAPEDISPTYP_IDLE      == (dev)->tapedisptype \
1181      || TAPEDISPTYP_LOCATING  == (dev)->tapedisptype \
1182      || TAPEDISPTYP_ERASING   == (dev)->tapedisptype \
1183      || TAPEDISPTYP_REWINDING == (dev)->tapedisptype \
1184      || TAPEDISPTYP_UNLOADING == (dev)->tapedisptype \
1185      || TAPEDISPTYP_CLEAN     == (dev)->tapedisptype \
1186     )
1187 
1188 #define TAPEDISPFLG_ALTERNATE   0x80    /* Alternate msgs 1 & 2      */
1189 #define TAPEDISPFLG_BLINKING    0x40    /* Selected msg blinks       */
1190 #define TAPEDISPFLG_MESSAGE2    0x20    /* Display msg 2 instead of 1*/
1191 #define TAPEDISPFLG_AUTOLOADER  0x10    /* Autoloader request        */
1192 #define TAPEDISPFLG_REQAUTOMNT  0x08    /* ReqAutoMount has work     */
1193 
1194        /* Device dependent fields for Comm Line                      */
1195         COMMADPT *commadpt;             /* Single structure pointer  */
1196 
1197         /*  Device dependent fields for dasd (fba and ckd)           */
1198 
1199         char   *dasdsfn;                /* Shadow file name          */
1200         char   *dasdsfx;                /* Pointer to suffix char    */
1201 
1202 
1203         /*  Device dependent fields for fbadasd                      */
1204 
1205         FBADEV *fbatab;                 /* Device table entry        */
1206         int     fbanumblk;              /* Number of blocks in device*/
1207         int     fbablksiz;              /* Physical block size       */
1208         off_t   fbaorigin;              /* Device origin block number*/
1209         off_t   fbarba;                 /* Relative byte offset      */
1210         off_t   fbaend;                 /* Last RBA in file          */
1211         /* Values from define extent */
1212         u_int   fbaxtdef:1;             /* 1=Extent defined          */
1213         BYTE    fbamask;                /* Define extent file mask   */
1214         U32     fbaxblkn;               /* Offset from start of device
1215                                            to first block of extent  */
1216         U32     fbaxfirst;              /* Block number within dataset
1217                                            of first block of extent  */
1218         U32     fbaxlast;               /* Block number within dataset
1219                                            of last block of extent   */
1220         /* Values from locate */
1221         BYTE    fbaoper;                /* Locate operation byte     */
1222         U16     fbalcnum;               /* Block count for locate    */
1223         U32     fbalcblk;               /* Block number within dataset
1224                                            of first block for locate */
1225 
1226         /*  Device dependent fields for ckddasd                      */
1227 
1228         int     ckdnumfd;               /* Number of CKD image files */
1229         int     ckdfd[CKD_MAXFILES];    /* CKD image file descriptors*/
1230         int     ckdhitrk[CKD_MAXFILES]; /* Highest track number
1231                                            in each CKD image file    */
1232         CKDDEV *ckdtab;                 /* Device table entry        */
1233         CKDCU  *ckdcu;                  /* Control unit entry        */
1234         off_t   ckdtrkoff;              /* Track image file offset   */
1235         int     ckdcyls;                /* Number of cylinders       */
1236         int     ckdtrks;                /* Number of tracks          */
1237         int     ckdheads;               /* #of heads per cylinder    */
1238         int     ckdtrksz;               /* Track size                */
1239         int     ckdcurcyl;              /* Current cylinder          */
1240         int     ckdcurhead;             /* Current head              */
1241         int     ckdcurrec;              /* Current record id         */
1242         int     ckdcurkl;               /* Current record key length */
1243         int     ckdorient;              /* Current orientation       */
1244         int     ckdcuroper;             /* Curr op: read=6, write=5  */
1245         U16     ckdcurdl;               /* Current record data length*/
1246         U16     ckdrem;                 /* #of bytes from current
1247                                            position to end of field  */
1248         U16     ckdpos;                 /* Offset into buffer of data
1249                                            for next data chained CCW */
1250         U16     ckdxblksz;              /* Define extent block size  */
1251         U16     ckdxbcyl;               /* Define extent begin cyl   */
1252         U16     ckdxbhead;              /* Define extent begin head  */
1253         U16     ckdxecyl;               /* Define extent end cyl     */
1254         U16     ckdxehead;              /* Define extent end head    */
1255         BYTE    ckdfmask;               /* Define extent file mask   */
1256         BYTE    ckdxgattr;              /* Define extent global attr */
1257         U16     ckdltranlf;             /* Locate record transfer
1258                                            length factor             */
1259         U16     ckdlmask;               /* Locate record mask        */
1260         BYTE    ckdloper;               /* Locate record operation   */
1261         BYTE    ckdlaux;                /* Locate record aux byte    */
1262         BYTE    ckdlcount;              /* Locate record count       */
1263         BYTE    ckdreserved1;           /* Alignment                 */
1264         void   *cckd_ext;               /* -> Compressed ckddasd
1265                                            extension otherwise NULL  */
1266         u_int   ckd3990:1;              /* 1=Control unit is 3990    */
1267         u_int   ckdxtdef:1;             /* 1=Define Extent processed */
1268         u_int   ckdsetfm:1;             /* 1=Set File Mask processed */
1269         u_int   ckdlocat:1;             /* 1=Locate Record processed */
1270         u_int   ckdspcnt:1;             /* 1=Space Count processed   */
1271         u_int   ckdseek:1;              /* 1=Seek command processed  */
1272         u_int   ckdskcyl:1;             /* 1=Seek cylinder processed */
1273         u_int   ckdrecal:1;             /* 1=Recalibrate processed   */
1274         u_int   ckdrdipl:1;             /* 1=Read IPL processed      */
1275         u_int   ckdxmark:1;             /* 1=End of track mark found */
1276         u_int   ckdhaeq:1;              /* 1=Search Home Addr Equal  */
1277         u_int   ckdideq:1;              /* 1=Search ID Equal         */
1278         u_int   ckdkyeq:1;              /* 1=Search Key Equal        */
1279         u_int   ckdwckd:1;              /* 1=Write R0 or Write CKD   */
1280         u_int   ckdtrkof:1;             /* 1=Track ovfl on this blk  */
1281         u_int   ckdssi:1;               /* 1=Set Special Intercept   */
1282         u_int   ckdnolazywr:1;          /* 1=Perform updates now     */
1283         u_int   ckdrdonly:1;            /* 1=Open read only          */
1284         u_int   ckdwrha:1;              /* 1=Write Home Address      */
1285                                         /* Line above ISW20030819-1  */
1286         u_int   ckdfakewr:1;            /* 1=Fake successful write
1287                                              for read only file      */
1288         U16     ckdssdlen;              /* #of bytes of data prepared
1289                                            for Read Subsystem Data   */
1290 };
1291 
1292 
1293 /*-------------------------------------------------------------------*/
1294 /* Device Group Structure     (just a group of related devices)      */
1295 /*-------------------------------------------------------------------*/
1296 struct DEVGRP {                         /* Device Group Structure    */
1297         int     members;                /* #of member devices in grp */
1298         int     acount;                 /* #allocated members in grp */
1299         void   *grp_data;               /* Group dep data (generic)  */
1300         DEVBLK *memdev[FLEXIBLE_ARRAY]; /* Member devices            */
1301 };
1302 
1303 
1304 /*-------------------------------------------------------------------*/
1305 /* Structure definitions for CKD headers                             */
1306 /*-------------------------------------------------------------------*/
1307 struct CKDDASD_DEVHDR {                 /* Device header             */
1308         BYTE    devid[8];               /* Device identifier         */
1309         FWORD   heads;                  /* #of heads per cylinder
1310                                            (bytes in reverse order)  */
1311         FWORD   trksize;                /* Track size (reverse order)*/
1312         BYTE    devtype;                /* Last 2 digits of device type
1313                                            (0x80=3380, 0x90=3390)    */
1314         BYTE    fileseq;                /* CKD image file sequence no.
1315                                            (0x00=only file, 0x01=first
1316                                            file of multiple files)   */
1317         HWORD   highcyl;                /* Highest cylinder number on
1318                                            this file, or zero if this
1319                                            is the last or only file
1320                                            (bytes in reverse order)  */
1321         BYTE    resv[492];              /* Reserved                  */
1322 };
1323 
1324 struct CKDDASD_TRKHDR {                 /* Track header              */
1325         BYTE    bin;                    /* Bin number                */
1326         HWORD   cyl;                    /* Cylinder number           */
1327         HWORD   head;                   /* Head number               */
1328 };
1329 
1330 struct CKDDASD_RECHDR {                 /* Record header             */
1331         HWORD   cyl;                    /* Cylinder number           */
1332         HWORD   head;                   /* Head number               */
1333         BYTE    rec;                    /* Record number             */
1334         BYTE    klen;                   /* Key length                */
1335         HWORD   dlen;                   /* Data length               */
1336 };
1337 
1338 #define CKDDASD_DEVHDR_SIZE     ((ssize_t)sizeof(CKDDASD_DEVHDR))
1339 #define CKDDASD_TRKHDR_SIZE     ((ssize_t)sizeof(CKDDASD_TRKHDR))
1340 #define CKDDASD_RECHDR_SIZE     ((ssize_t)sizeof(CKDDASD_RECHDR))
1341 
1342 /* Null track formats */
1343 #define CKDDASD_NULLTRK_FMT0       0    /* ha r0 r1 eot              */
1344 #define CKDDASD_NULLTRK_FMT1       1    /* ha r0 eot                 */
1345 #define CKDDASD_NULLTRK_FMT2       2    /* linux (3390 only)         */
1346 #define CKDDASD_NULLTRK_FMTMAX     CKDDASD_NULLTRK_FMT2
1347 
1348 #define CKDDASD_NULLTRK_SIZE0      (5 + 8 + 8 + 8 + 8)
1349 #define CKDDASD_NULLTRK_SIZE1      (5 + 8 + 8 + 8)
1350 #define CKDDASD_NULLTRK_SIZE2      (5 + 8 + 8 + (12 * (8 + 4096)) + 8)
1351 
1352 /*-------------------------------------------------------------------*/
1353 /* Structure definitions for Compressed CKD devices                  */
1354 /*-------------------------------------------------------------------*/
1355 struct CCKDDASD_DEVHDR {                /* Compress device header    */
1356 /*  0 */BYTE             vrm[3];        /* Version Release Modifier  */
1357 /*  3 */BYTE             options;       /* Options byte              */
1358 /*  4 */S32              numl1tab;      /* Size of lvl 1 table       */
1359 /*  8 */S32              numl2tab;      /* Size of lvl 2 tables      */
1360 /* 12 */U32              size;          /* File size                 */
1361 /* 16 */U32              used;          /* File used                 */
1362 /* 20 */U32              free;          /* Position to free space    */
1363 /* 24 */U32              free_total;    /* Total free space          */
1364 /* 28 */U32              free_largest;  /* Largest free space        */
1365 /* 32 */S32              free_number;   /* Number free spaces        */
1366 /* 36 */U32              free_imbed;    /* Imbedded free space       */
1367 /* 40 */FWORD            cyls;          /* Cylinders on device       */
1368 /* 44 */BYTE             nullfmt;       /* Null track format         */
1369 /* 45 */BYTE             compress;      /* Compression algorithm     */
1370 /* 46 */S16              compress_parm; /* Compression parameter     */
1371 /* 48 */BYTE             resv2[464];    /* Reserved                  */
1372 };
1373 #define CCKD_DEVHDR      CCKDDASD_DEVHDR
1374 
1375 #define CCKD_VERSION           0
1376 #define CCKD_RELEASE           3
1377 #define CCKD_MODLVL            1
1378 
1379 #define CCKD_NOFUDGE           1         /* [deprecated]             */
1380 #define CCKD_BIGENDIAN         2
1381 #define CCKD_SPERRS            32        /* Space errors detected    */
1382 #define CCKD_ORDWR             64        /* Opened read/write since
1383                                             last chkdsk              */
1384 #define CCKD_OPENED            128
1385 
1386 #define CCKD_COMPRESS_NONE     0x00
1387 #define CCKD_COMPRESS_ZLIB     0x01
1388 #define CCKD_COMPRESS_BZIP2    0x02
1389 #define CCKD_COMPRESS_MASK     0x03
1390 
1391 #define CCKD_STRESS_MINLEN     4096
1392 #if defined(HAVE_LIBZ)
1393 #define CCKD_STRESS_COMP       CCKD_COMPRESS_ZLIB
1394 #else
1395 #define CCKD_STRESS_COMP       CCKD_COMPRESS_NONE
1396 #endif
1397 #define CCKD_STRESS_PARM1      4
1398 #define CCKD_STRESS_PARM2      2
1399 
1400 struct CCKD_L2ENT {                     /* Level 2 table entry       */
1401         U32              pos;           /* Track offset              */
1402         U16              len;           /* Track length              */
1403         U16              size;          /* Track size  (size >= len) */
1404 };
1405 
1406 struct CCKD_FREEBLK {                   /* Free block (file)         */
1407         U32              pos;           /* Position next free blk    */
1408         U32              len;           /* Length this free blk      */
1409 };
1410 
1411 struct CCKD_IFREEBLK {                  /* Free block (internal)     */
1412         U32              pos;           /* Position next free blk    */
1413         U32              len;           /* Length this free blk      */
1414         int              prev;          /* Index to prev free blk    */
1415         int              next;          /* Index to next free blk    */
1416         int              pending;       /* 1=Free pending (don't use)*/
1417 };
1418 
1419 struct CCKD_RA {                        /* Readahead queue entry     */
1420         DEVBLK          *dev;           /* Readahead device          */
1421         int              trk;           /* Readahead track           */
1422         int              prev;          /* Index to prev entry       */
1423         int              next;          /* Index to next entry       */
1424 };
1425 
1426 typedef  U32          CCKD_L1ENT;       /* Level 1 table entry       */
1427 typedef  CCKD_L1ENT   CCKD_L1TAB[];     /* Level 1 table             */
1428 typedef  CCKD_L2ENT   CCKD_L2TAB[256];  /* Level 2 table             */
1429 typedef  char         CCKD_TRACE[128];  /* Trace table entry         */
1430 
1431 #define CCKDDASD_DEVHDR_SIZE   ((ssize_t)sizeof(CCKDDASD_DEVHDR))
1432 #define CCKD_DEVHDR_SIZE       CCKDDASD_DEVHDR_SIZE
1433 #define CCKD_DEVHDR_POS        CKDDASD_DEVHDR_SIZE
1434 #define CCKD_L1ENT_SIZE        ((ssize_t)sizeof(CCKD_L1ENT))
1435 #define CCKD_L1TAB_POS         ((CCKD_DEVHDR_POS)+(CCKD_DEVHDR_SIZE))
1436 #define CCKD_L2ENT_SIZE        ((ssize_t)sizeof(CCKD_L2ENT))
1437 #define CCKD_L2TAB_SIZE        ((ssize_t)sizeof(CCKD_L2TAB))
1438 #define CCKD_FREEBLK_SIZE      ((ssize_t)sizeof(CCKD_FREEBLK))
1439 #define CCKD_FREEBLK_ISIZE     ((ssize_t)sizeof(CCKD_IFREEBLK))
1440 #define CCKD_IFREEBLK_SIZE     (CCKD_FREEBLK_ISIZE)
1441 
1442 /* Flag bits */
1443 #define CCKD_SIZE_EXACT         0x01    /* Space obtained is exact   */
1444 #define CCKD_SIZE_ANY           0x02    /* Space can be any size     */
1445 #define CCKD_L2SPACE            0x04    /* Space for a l2 table      */
1446 
1447 /* adjustable values */
1448 
1449 #define CCKD_FREE_MIN_SIZE     96       /* Minimum free space size   */
1450 #define CCKD_FREE_MIN_INCR     32       /* Added for each 1024 spaces*/
1451 #define CCKD_COMPRESS_MIN      512      /* Track images smaller than
1452                                            this won't be compressed  */
1453 #define CCKD_MAX_SF            8        /* Maximum number of shadow
1454                                            files: 0 to 9 [0 disables
1455                                            shadow file support]      */
1456 #define CCKD_MAX_READAHEADS    16       /* Max readahead trks        */
1457 #define CCKD_MAX_RA_SIZE       16       /* Readahead queue size      */
1458 #define CCKD_MAX_RA            9        /* Max readahead threads     */
1459 #define CCKD_MAX_WRITER        9        /* Max writer threads        */
1460 #define CCKD_MAX_GCOL          1        /* Max garbage collectors    */
1461 #define CCKD_MAX_TRACE         200000   /* Max nbr trace entries     */
1462 #define CCKD_MAX_FREEPEND      4        /* Max free pending cycles   */
1463 
1464 #define CCKD_MIN_READAHEADS    0        /* Min readahead trks        */
1465 #define CCKD_MIN_RA            0        /* Min readahead threads     */
1466 #define CCKD_MIN_WRITER        1        /* Min writer threads        */
1467 #define CCKD_MIN_GCOL          0        /* Min garbage collectors    */
1468 
1469 #define CCKD_DEFAULT_RA_SIZE   4        /* Readahead queue size      */
1470 #define CCKD_DEFAULT_RA        2        /* Default number readaheads */
1471 #define CCKD_DEFAULT_WRITER    2        /* Default number writers    */
1472 #define CCKD_DEFAULT_GCOL      1        /* Default number garbage
1473                                               collectors             */
1474 #define CCKD_DEFAULT_GCOLWAIT  10       /* Default wait (seconds)    */
1475 #define CCKD_DEFAULT_GCOLPARM  0        /* Default adjustment parm   */
1476 #define CCKD_DEFAULT_READAHEADS 2       /* Default nbr to read ahead */
1477 #define CCKD_DEFAULT_FREEPEND  -1       /* Default freepend cycles   */
1478 
1479 #define CFBA_BLOCK_NUM         120      /* Number fba blocks / group */
1480 #define CFBA_BLOCK_SIZE        61440    /* Size of a block group 60k */
1481                                         /* Number of bytes in an fba
1482                                            block group.  Probably
1483                                            should be a multiple of 512
1484                                            but has to be < 64K       */
1485 
1486 struct CCKDBLK {                        /* Global cckd dasd block    */
1487         BYTE             id[8];         /* "CCKDBLK "                */
1488         DEVBLK          *dev1st;        /* 1st device in cckd queue  */
1489         unsigned int     batch:1,       /* 1=called in batch mode    */
1490                          sfmerge:1,     /* 1=sf-* merge              */
1491                          sfforce:1;     /* 1=sf-* force              */
1492         int              sflevel;       /* sfk xxxx level            */
1493 
1494         BYTE             comps;         /* Supported compressions    */
1495         BYTE             comp;          /* Override compression      */
1496         int              compparm;      /* Override compression parm */
1497 
1498         LOCK             gclock;        /* Garbage collector lock    */
1499         COND             gccond;        /* Garbage collector cond    */
1500         int              gcs;           /* Number garbage collectors */
1501         int              gcmax;         /* Max garbage collectors    */
1502         int              gcwait;        /* Wait time in seconds      */
1503         int              gcparm;        /* Adjustment parm           */
1504 
1505         LOCK             wrlock;        /* I/O lock                  */
1506         COND             wrcond;        /* I/O condition             */
1507         int              wrpending;     /* Number writes pending     */
1508         int              wrwaiting;     /* Number writers waiting    */
1509         int              wrs;           /* Number writer threads     */
1510         int              wrmax;         /* Max writer threads        */
1511         int              wrprio;        /* Writer thread priority    */
1512 
1513         LOCK             ralock;        /* Readahead lock            */
1514         COND             racond;        /* Readahead condition       */
1515         int              ras;           /* Number readahead threads  */
1516         int              ramax;         /* Max readahead threads     */
1517         int              rawaiting;     /* Number threads waiting    */
1518         int              ranbr;         /* Readahead queue size      */
1519         int              readaheads;    /* Nbr tracks to read ahead  */
1520         CCKD_RA          ra[CCKD_MAX_RA_SIZE];    /* Readahead queue */
1521         int              ra1st;         /* First readahead entry     */
1522         int              ralast;        /* Last readahead entry      */
1523         int              rafree;        /* Free readahead entry      */
1524 
1525         LOCK             devlock;       /* Device chain lock         */
1526         COND             devcond;       /* Device chain condition    */
1527         int              devusers;      /* Number shared users       */
1528         int              devwaiters;    /* Number of waiters         */
1529 
1530         int              freepend;      /* Number freepend cycles    */
1531         int              nostress;      /* 1=No stress writes        */
1532         int              linuxnull;     /* 1=Always check nulltrk    */
1533         int              fsync;         /* 1=Perform fsync()         */
1534         COND             termcond;      /* Termination condition     */
1535 
1536         U64              stats_switches;       /* Switches           */
1537         U64              stats_cachehits;      /* Cache hits         */
1538         U64              stats_cachemisses;    /* Cache misses       */
1539         U64              stats_readaheads;     /* Readaheads         */
1540         U64              stats_readaheadmisses;/* Readahead misses   */
1541         U64              stats_syncios;        /* Synchronous i/os   */
1542         U64              stats_synciomisses;   /* Missed syncios     */
1543         U64              stats_iowaits;        /* Waits for i/o      */
1544         U64              stats_cachewaits;     /* Waits for cache    */
1545         U64              stats_stresswrites;   /* Writes under stress*/
1546         U64              stats_l2cachehits;    /* L2 cache hits      */
1547         U64              stats_l2cachemisses;  /* L2 cache misses    */
1548         U64              stats_l2reads;        /* L2 reads           */
1549         U64              stats_reads;          /* Number reads       */
1550         U64              stats_readbytes;      /* Bytes read         */
1551         U64              stats_writes;         /* Number writes      */
1552         U64              stats_writebytes;     /* Bytes written      */
1553         U64              stats_gcolmoves;      /* Spaces moved       */
1554         U64              stats_gcolbytes;      /* Bytes moved        */
1555 
1556         CCKD_TRACE      *itrace;        /* Internal trace table      */
1557         CCKD_TRACE      *itracep;       /* Current pointer           */
1558         CCKD_TRACE      *itracex;       /* End of trace table        */
1559         int              itracen;       /* Number of entries         */
1560 
1561         int              bytemsgs;      /* Limit for `byte 0' msgs   */
1562 };
1563 
1564 struct CCKDDASD_EXT {                   /* Ext for compressed ckd    */
1565         DEVBLK          *devnext;       /* cckd device queue         */
1566         unsigned int     ckddasd:1,     /* 1=CKD dasd                */
1567                          fbadasd:1,     /* 1=FBA dasd                */
1568                          ioactive:1,    /* 1=Channel program active  */
1569                          bufused:1,     /* 1=newbuf was used         */
1570                          updated:1,     /* 1=Update occurred         */
1571                          merging:1,     /* 1=File merge in progress  */
1572                          stopping:1,    /* 1=Device is closing       */
1573                          notnull:1,     /* 1=Device has track images */
1574                          l2ok:1,        /* 1=All l2s below bounds    */
1575                          sfmerge:1,     /* 1=sf-xxxx merge           */
1576                          sfforce:1;     /* 1=sf-xxxx force           */
1577         int              sflevel;       /* sfk xxxx level            */
1578         LOCK             filelock;      /* File lock                 */
1579         LOCK             iolock;        /* I/O lock                  */
1580         COND             iocond;        /* I/O condition             */
1581         long long        maxsize;       /* Maximum file size         */
1582         int              iowaiters;     /* Number I/O waiters        */
1583         int              wrpending;     /* Number writes pending     */
1584         int              ras;           /* Number readaheads active  */
1585         int              sfn;           /* Number active shadow files*/
1586         int              sfx;           /* Active level 2 file index */
1587         int              l1x;           /* Active level 2 table index*/
1588         CCKD_L2ENT      *l2;            /* Active level 2 table      */
1589         int              l2active;      /* Active level 2 cache entry*/
1590         off_t            l2bounds;      /* L2 tables boundary        */
1591         int              active;        /* Active cache entry        */
1592         BYTE            *newbuf;        /* Uncompressed buffer       */
1593         unsigned int     freemin;       /* Minimum free space size   */
1594         CCKD_IFREEBLK   *free;          /* Internal free space chain */
1595         int              freenbr;       /* Number free space entries */
1596         int              free1st;       /* Index of 1st entry        */
1597         int              freelast;      /* Index of last entry       */
1598         int              freeavail;     /* Index of available entry  */
1599         int              lastsync;      /* Time of last sync         */
1600         int              ralkup[CCKD_MAX_RA_SIZE];/* Lookup table    */
1601         int              ratrk;         /* Track to readahead        */
1602         unsigned int     totreads;      /* Total nbr trk reads       */
1603         unsigned int     totwrites;     /* Total nbr trk writes      */
1604         unsigned int     totl2reads;    /* Total nbr l2 reads        */
1605         unsigned int     cachehits;     /* Cache hits                */
1606         unsigned int     readaheads;    /* Number trks read ahead    */
1607         unsigned int     switches;      /* Number trk switches       */
1608         unsigned int     misses;        /* Number readahead misses   */
1609         int              fd[CCKD_MAX_SF+1];      /* File descriptors */
1610         BYTE             swapend[CCKD_MAX_SF+1]; /* Swap endian flag */
1611         BYTE             open[CCKD_MAX_SF+1];    /* Open flag        */
1612         int              reads[CCKD_MAX_SF+1];   /* Nbr track reads  */
1613         int              l2reads[CCKD_MAX_SF+1]; /* Nbr l2 reads     */
1614         int              writes[CCKD_MAX_SF+1];  /* Nbr track writes */
1615         CCKD_L1ENT      *l1[CCKD_MAX_SF+1];      /* Level 1 tables   */
1616         CCKDDASD_DEVHDR  cdevhdr[CCKD_MAX_SF+1]; /* cckd device hdr  */
1617 };
1618 
1619 #define CCKD_OPEN_NONE         0
1620 #define CCKD_OPEN_RO           1
1621 #define CCKD_OPEN_RD           2
1622 #define CCKD_OPEN_RW           3
1623 
1624 #ifdef EXTERNALGUI
1625 struct GUISTAT
1626 {
1627     char*   pszOldStatStr;
1628     char*   pszNewStatStr;
1629 #define     GUI_STATSTR_BUFSIZ    256
1630     char    szStatStrBuff1[GUI_STATSTR_BUFSIZ];
1631     char    szStatStrBuff2[GUI_STATSTR_BUFSIZ];
1632 };
1633 #endif // EXTERNALGUI
1634 
1635 
1636 #endif // _HSTRUCTS_H
1637