3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 1992 - 1997, 2000-2003 Silicon Graphics, Inc. All rights reserved.
10 #include <linux/types.h>
11 #include <linux/slab.h>
12 #include <asm/sn/sgi.h>
13 #include <asm/sn/sn_sal.h>
14 #include <asm/sn/io.h>
15 #include <asm/sn/invent.h>
16 #include <asm/sn/hcl.h>
17 #include <asm/sn/labelcl.h>
18 #include <asm/sn/xtalk/xbow.h>
19 #include <asm/sn/pci/bridge.h>
20 #include <asm/sn/klconfig.h>
21 #include <asm/sn/module.h>
22 #include <asm/sn/pci/pcibr.h>
23 #include <asm/sn/xtalk/xswitch.h>
24 #include <asm/sn/nodepda.h>
25 #include <asm/sn/sn_cpuid.h>
28 /* #define LDEBUG 1 */
31 #define DPRINTF printk
37 module_t *modules[MODULE_MAX];
40 #define SN00_SERIAL_FUDGE 0x3b1af409d513c2
41 #define SN0_SERIAL_FUDGE 0x6e
44 encode_int_serial(uint64_t src,uint64_t *dest)
49 val = src + SN00_SERIAL_FUDGE;
52 for (i = 0; i < sizeof(long long); i++) {
54 ((char*)&val)[sizeof(long long)/2 +
55 ((i%2) ? ((i/2 * -1) - 1) : (i/2))];
61 decode_int_serial(uint64_t src, uint64_t *dest)
66 for (i = 0; i < sizeof(long long); i++) {
67 ((char*)&val)[sizeof(long long)/2 +
68 ((i%2) ? ((i/2 * -1) - 1) : (i/2))] =
72 *dest = val - SN00_SERIAL_FUDGE;
77 encode_str_serial(const char *src, char *dest)
81 for (i = 0; i < MAX_SERIAL_NUM_SIZE; i++) {
83 dest[i] = src[MAX_SERIAL_NUM_SIZE/2 +
84 ((i%2) ? ((i/2 * -1) - 1) : (i/2))] +
90 decode_str_serial(const char *src, char *dest)
94 for (i = 0; i < MAX_SERIAL_NUM_SIZE; i++) {
95 dest[MAX_SERIAL_NUM_SIZE/2 +
96 ((i%2) ? ((i/2 * -1) - 1) : (i/2))] = src[i] -
102 module_t *module_lookup(moduleid_t id)
106 for (i = 0; i < nummodules; i++)
107 if (modules[i]->id == id) {
108 DPRINTF("module_lookup: found m=0x%p\n", modules[i]);
118 * The first time a new module number is seen, a module structure is
119 * inserted into the module list in order sorted by module number
120 * and the structure is initialized.
122 * The node number is added to the list of nodes in the module.
125 module_t *module_add_node(geoid_t geoid, cnodeid_t cnodeid)
131 slabid_t slab_number;
133 memset(buffer, 0, 16);
134 moduleid = geo_module(geoid);
135 format_module_id(buffer, moduleid, MODULE_FORMAT_BRIEF);
136 DPRINTF("module_add_node: moduleid=%s node=%d ", buffer, cnodeid);
138 if ((m = module_lookup(moduleid)) == 0) {
139 m = kmalloc(sizeof (module_t), GFP_KERNEL);
141 memset(m, 0 , sizeof(module_t));
143 for (slab_number = 0; slab_number <= MAX_SLABS; slab_number++) {
144 m->nodes[slab_number] = -1;
148 spin_lock_init(&m->lock);
150 init_MUTEX_LOCKED(&m->thdcnt);
152 /* Insert in sorted order by module number */
154 for (i = nummodules; i > 0 && modules[i - 1]->id > moduleid; i--)
155 modules[i] = modules[i - 1];
162 * Save this information in the correct slab number of the node in the
165 slab_number = geo_slab(geoid);
166 DPRINTF("slab number added 0x%x\n", slab_number);
168 if (m->nodes[slab_number] != -1)
169 panic("module_add_node .. slab previously found\n");
171 m->nodes[slab_number] = cnodeid;
172 m->geoid[slab_number] = geoid;
177 int module_probe_snum(module_t *m, nasid_t host_nasid, nasid_t nasid)
180 klmod_serial_num_t *comp;
181 char * bcopy(const char * src, char * dest, int count);
182 char serial_number[16];
185 * record brick serial number
187 board = find_lboard((lboard_t *) KL_CONFIG_INFO(host_nasid), KLTYPE_SNIA);
189 if (! board || KL_CONFIG_DUPLICATE_BOARD(board))
192 printf ("module_probe_snum: no IP35 board found!\n");
197 board_serial_number_get( board, serial_number );
198 if( serial_number[0] != '\0' ) {
199 encode_str_serial( serial_number, m->snum.snum_str );
204 printf("module_probe_snum: brick serial number is null!\n");
206 printf("module_probe_snum: brick serial number == %s\n", serial_number);
209 board = find_lboard((lboard_t *) KL_CONFIG_INFO(nasid),
210 KLTYPE_IOBRICK_XBOW);
212 if (! board || KL_CONFIG_DUPLICATE_BOARD(board))
215 comp = GET_SNUM_COMP(board);
221 printf("********found module with id %x and string", m->id);
223 for (i = 0; i < MAX_SERIAL_NUM_SIZE; i++)
224 printf(" %x ", comp->snum.snum_str[i]);
226 printf("\n"); /* Fudged string is not ASCII */
229 if (comp->snum.snum_str[0] != '\0') {
230 bcopy(comp->snum.snum_str,
232 MAX_SERIAL_NUM_SIZE);
233 m->sys_snum_valid = 1;
237 if (m->sys_snum_valid)
240 DPRINTF("Invalid serial number for module %d, "
241 "possible missing or invalid NIC.", m->id);
255 DPRINTF("*******module_init\n");
260 * First pass just scan for compute node boards KLTYPE_SNIA.
261 * We do not support memoryless compute nodes.
263 for (node = 0; node < numnodes; node++) {
264 nasid = COMPACT_TO_NASID_NODEID(node);
265 board = find_lboard((lboard_t *) KL_CONFIG_INFO(nasid), KLTYPE_SNIA);
268 HWGRAPH_DEBUG((__FILE__, __FUNCTION__, __LINE__, NULL, NULL, "Found Shub lboard 0x%lx nasid 0x%x cnode 0x%x \n", (unsigned long)board, (int)nasid, (int)node));
270 m = module_add_node(board->brd_geoid, node);
271 if (! m->snum_valid && module_probe_snum(m, nasid, nasid))
276 * Second scan, look for TIO's board hosted by compute nodes.
278 for (node = numnodes; node < numionodes; node++) {
281 char serial_number[16];
283 tio_nasid = COMPACT_TO_NASID_NODEID(node);
284 board = find_lboard((lboard_t *) KL_CONFIG_INFO(tio_nasid), KLTYPE_TIO);
286 tio_node = NASID_TO_COMPACT_NODEID(tio_nasid);
288 HWGRAPH_DEBUG((__FILE__, __FUNCTION__, __LINE__, NULL, NULL, "Found TIO lboard 0x%lx tio nasid %d tio cnode %d\n", (unsigned long)board, (int)tio_nasid, (int)tio_node));
290 m = module_add_node(board->brd_geoid, tio_node);
293 * Get and initialize the serial number of TIO.
295 board_serial_number_get( board, serial_number );
296 if( serial_number[0] != '\0' ) {
297 encode_str_serial( serial_number, m->snum.snum_str );