1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1992 - 1997, 2000-2003 Silicon Graphics, Inc. All rights reserved.
7  */
8 #ifndef _ASM_IA64_SN_MODULE_H
9 #define _ASM_IA64_SN_MODULE_H
10 
11 #ifdef	__cplusplus
12 extern "C" {
13 #endif
14 
15 
16 #include <linux/config.h>
17 #include <asm/sn/klconfig.h>
18 #include <asm/sn/ksys/elsc.h>
19 
20 #define MODULE_MAX			128
21 #define MODULE_MAX_NODES		2
22 #define MODULE_HIST_CNT			16
23 #define MAX_MODULE_LEN			16
24 
25 /* Well-known module IDs */
26 #define MODULE_UNKNOWN		(-2) /* initial value of klconfig brd_module */
27 /* #define INVALID_MODULE	(-1) ** generic invalid moduleid_t (arch.h) */
28 #define MODULE_NOT_SET		0    /* module ID not set in sys ctlrs. */
29 
30 /* parameter for format_module_id() */
31 #define MODULE_FORMAT_BRIEF	1
32 #define MODULE_FORMAT_LONG	2
33 
34 /*
35  *	Module id format
36  *
37  *	31-16	Rack ID (encoded class, group, number - 16-bit unsigned int)
38  *	 15-8	Brick type (8-bit ascii character)
39  *	  7-0	Bay (brick position in rack (0-63) - 8-bit unsigned int)
40  *
41  */
42 
43 /*
44  * Macros for getting the brick type
45  */
46 #define MODULE_BTYPE_MASK	0xff00
47 #define MODULE_BTYPE_SHFT	8
48 #define MODULE_GET_BTYPE(_m)	(((_m) & MODULE_BTYPE_MASK) >> MODULE_BTYPE_SHFT)
49 #define MODULE_BT_TO_CHAR(_b)	((char)(_b))
50 #define MODULE_GET_BTCHAR(_m)	(MODULE_BT_TO_CHAR(MODULE_GET_BTYPE(_m)))
51 
52 /*
53  * Macros for getting the rack ID.
54  */
55 #define MODULE_RACK_MASK	0xffff0000
56 #define MODULE_RACK_SHFT	16
57 #define MODULE_GET_RACK(_m)	(((_m) & MODULE_RACK_MASK) >> MODULE_RACK_SHFT)
58 
59 /*
60  * Macros for getting the brick position
61  */
62 #define MODULE_BPOS_MASK	0x00ff
63 #define MODULE_BPOS_SHFT	0
64 #define MODULE_GET_BPOS(_m)	(((_m) & MODULE_BPOS_MASK) >> MODULE_BPOS_SHFT)
65 
66 /*
67  * Macros for constructing moduleid_t's
68  */
69 #define RBT_TO_MODULE(_r, _b, _t) ((_r) << MODULE_RACK_SHFT | \
70 				   (_b) << MODULE_BPOS_SHFT | \
71 				   (_t) << MODULE_BTYPE_SHFT)
72 
73 /*
74  * Macros for encoding and decoding rack IDs
75  * A rack number consists of three parts:
76  *   class (0==CPU/mixed, 1==I/O), group, number
77  *
78  * Rack number is stored just as it is displayed on the screen:
79  * a 3-decimal-digit number.
80  */
81 #define RACK_CLASS_DVDR		100
82 #define RACK_GROUP_DVDR		10
83 #define RACK_NUM_DVDR		1
84 
85 #define RACK_CREATE_RACKID(_c, _g, _n)	((_c) * RACK_CLASS_DVDR +	\
86 	(_g) * RACK_GROUP_DVDR + (_n) * RACK_NUM_DVDR)
87 
88 #define RACK_GET_CLASS(_r)              ((_r) / RACK_CLASS_DVDR)
89 #define RACK_GET_GROUP(_r)              (((_r) - RACK_GET_CLASS(_r) *   \
90             RACK_CLASS_DVDR) / RACK_GROUP_DVDR)
91 #define RACK_GET_NUM(_r)                (((_r) - RACK_GET_CLASS(_r) *   \
92             RACK_CLASS_DVDR - RACK_GET_GROUP(_r) *      \
93             RACK_GROUP_DVDR) / RACK_NUM_DVDR)
94 
95 /*
96  * Macros for encoding and decoding rack IDs
97  * A rack number consists of three parts:
98  *   class	1 bit, 0==CPU/mixed, 1==I/O
99  *   group	2 bits for CPU/mixed, 3 bits for I/O
100  *   number	3 bits for CPU/mixed, 2 bits for I/O (1 based)
101  */
102 #define RACK_GROUP_BITS(_r)	(RACK_GET_CLASS(_r) ? 3 : 2)
103 #define RACK_NUM_BITS(_r)	(RACK_GET_CLASS(_r) ? 2 : 3)
104 
105 #define RACK_CLASS_MASK(_r)	0x20
106 #define RACK_CLASS_SHFT(_r)	5
107 #define RACK_ADD_CLASS(_r, _c)	\
108 	((_r) |= (_c) << RACK_CLASS_SHFT(_r) & RACK_CLASS_MASK(_r))
109 
110 #define RACK_GROUP_SHFT(_r)	RACK_NUM_BITS(_r)
111 #define RACK_GROUP_MASK(_r)	\
112 	( (((unsigned)1<<RACK_GROUP_BITS(_r)) - 1) << RACK_GROUP_SHFT(_r) )
113 #define RACK_ADD_GROUP(_r, _g)	\
114 	((_r) |= (_g) << RACK_GROUP_SHFT(_r) & RACK_GROUP_MASK(_r))
115 
116 #define RACK_NUM_SHFT(_r)	0
117 #define RACK_NUM_MASK(_r)	\
118 	( (((unsigned)1<<RACK_NUM_BITS(_r)) - 1) << RACK_NUM_SHFT(_r) )
119 #define RACK_ADD_NUM(_r, _n)	\
120 	((_r) |= ((_n) - 1) << RACK_NUM_SHFT(_r) & RACK_NUM_MASK(_r))
121 
122 
123 /*
124  * Brick type definitions
125  */
126 #define MAX_BRICK_TYPES         256 /* brick type is stored as uchar */
127 
128 extern char brick_types[];
129 
130 #define MODULE_CBRICK           0
131 #define MODULE_RBRICK           1
132 #define MODULE_IBRICK           2
133 #define MODULE_KBRICK           3
134 #define MODULE_XBRICK           4
135 #define MODULE_DBRICK           5
136 #define MODULE_PBRICK           6
137 #define MODULE_NBRICK           7
138 #define MODULE_PEBRICK          8
139 #define MODULE_PXBRICK          9
140 #define MODULE_IXBRICK          10
141 #define MODULE_CGBRICK		11
142 #define MODULE_OPUSBRICK        12
143 
144 /*
145  * Moduleid_t comparison macros
146  */
147 /* Don't compare the brick type:  only the position is significant */
148 #define MODULE_CMP(_m1, _m2)    (((_m1)&(MODULE_RACK_MASK|MODULE_BPOS_MASK)) -\
149                                  ((_m2)&(MODULE_RACK_MASK|MODULE_BPOS_MASK)))
150 #define MODULE_MATCH(_m1, _m2)  (MODULE_CMP((_m1),(_m2)) == 0)
151 
152 typedef struct module_s module_t;
153 
154 struct module_s {
155     moduleid_t		id;		/* Module ID of this module        */
156 
157     spinlock_t		lock;		/* Lock for this structure	   */
158 
159     /* List of nodes in this module */
160     cnodeid_t		nodes[MAX_SLABS + 1];
161     geoid_t		geoid[MAX_SLABS + 1];
162     struct {
163 		char	 moduleid[8];
164 		uint64_t iobrick_type;
165     } io[MAX_SLABS + 1];
166 
167     /* Fields for Module System Controller */
168     int			mesgpend;	/* Message pending                 */
169     int			shutdown;	/* Shutdown in progress            */
170     struct semaphore	thdcnt;		/* Threads finished counter        */
171     time_t		intrhist[MODULE_HIST_CNT];
172     int			histptr;
173 
174     int			hbt_active;	/* MSC heartbeat monitor active    */
175     uint64_t		hbt_last;	/* RTC when last heartbeat sent    */
176 
177     /* Module serial number info */
178     union {
179 	char		snum_str[MAX_SERIAL_NUM_SIZE];	 /* used by CONFIG_SGI_IP27    */
180 	uint64_t	snum_int;			 /* used by speedo */
181     } snum;
182     int			snum_valid;
183 
184     int			disable_alert;
185     int			count_down;
186 
187     /* System serial number info (used by SN1) */
188     char		sys_snum[MAX_SERIAL_NUM_SIZE];
189     int			sys_snum_valid;
190 };
191 
192 /* module.c */
193 extern module_t	       *modules[MODULE_MAX];	/* Indexed by cmoduleid_t   */
194 extern int		nummodules;
195 
196 extern module_t	       *module_lookup(moduleid_t id);
197 
198 extern int		get_kmod_sys_snum(cmoduleid_t cmod,
199 					  char *snum);
200 
201 extern void		format_module_id(char *buffer, moduleid_t m, int fmt);
202 extern int		parse_module_id(char *buffer);
203 
204 #ifdef	__cplusplus
205 }
206 #endif
207 
208 #endif /* _ASM_IA64_SN_MODULE_H */
209