aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ia64/sn/io/klconflib.c
blob: 8b9feb29a2b16c841f8c63e7be272b6a80b5a794 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
/* $Id$
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
 */


#include <linux/types.h>
#include <linux/config.h>
#include <linux/ctype.h>
#include <asm/sn/sgi.h>
#include <asm/sn/sn_sal.h>
#include <asm/sn/io.h>
#include <asm/sn/sn_cpuid.h>
#include <asm/sn/iograph.h>
#include <asm/sn/invent.h>
#include <asm/sn/hcl.h>
#include <asm/sn/labelcl.h>
#include <asm/sn/klconfig.h>
#include <asm/sn/nodepda.h>
#include <asm/sn/module.h>
#include <asm/sn/router.h>
#include <asm/sn/xtalk/xbow.h>

#define printf printk
int hasmetarouter;

#define LDEBUG 0
#define NIC_UNKNOWN ((nic_t) -1)

#undef DEBUG_KLGRAPH
#ifdef DEBUG_KLGRAPH
#define DBG(x...) printk(x)
#else
#define DBG(x...)
#endif /* DEBUG_KLGRAPH */

static void sort_nic_names(lboard_t *) ;

u64 klgraph_addr[MAX_COMPACT_NODES];

lboard_t *
find_lboard(lboard_t *start, unsigned char brd_type)
{
	/* Search all boards stored on this node. */
	while (start) {
		if (start->brd_type == brd_type)
			return start;
		start = KLCF_NEXT(start);
	}

	/* Didn't find it. */
	return (lboard_t *)NULL;
}

lboard_t *
find_lboard_class(lboard_t *start, unsigned char brd_type)
{
	/* Search all boards stored on this node. */
	while (start) {
		if (KLCLASS(start->brd_type) == KLCLASS(brd_type))
			return start;
		start = KLCF_NEXT(start);
	}

	/* Didn't find it. */
	return (lboard_t *)NULL;
}

klinfo_t *
find_component(lboard_t *brd, klinfo_t *kli, unsigned char struct_type)
{
	int index, j;

	if (kli == (klinfo_t *)NULL) {
		index = 0;
	} else {
		for (j = 0; j < KLCF_NUM_COMPS(brd); j++) {
			if (kli == KLCF_COMP(brd, j))
				break;
		}
		index = j;
		if (index == KLCF_NUM_COMPS(brd)) {
			DBG("find_component: Bad pointer: 0x%p\n", kli);
			return (klinfo_t *)NULL;
		}
		index++;	/* next component */
	}
	
	for (; index < KLCF_NUM_COMPS(brd); index++) {		
		kli = KLCF_COMP(brd, index);
		DBG("find_component: brd %p kli %p  request type = 0x%x kli type 0x%x\n", brd, kli, kli->struct_type, KLCF_COMP_TYPE(kli));
		if (KLCF_COMP_TYPE(kli) == struct_type)
			return kli;
	}

	/* Didn't find it. */
	return (klinfo_t *)NULL;
}

klinfo_t *
find_first_component(lboard_t *brd, unsigned char struct_type)
{
	return find_component(brd, (klinfo_t *)NULL, struct_type);
}

lboard_t *
find_lboard_modslot(lboard_t *start, moduleid_t mod, slotid_t slot)
{
	/* Search all boards stored on this node. */
	while (start) {
		if (MODULE_MATCH(start->brd_module, mod) &&
		    (start->brd_slot == slot))
			return start;
		start = KLCF_NEXT(start);
	}

	/* Didn't find it. */
	return (lboard_t *)NULL;
}

lboard_t *
find_lboard_module(lboard_t *start, moduleid_t mod)
{
        /* Search all boards stored on this node. */
        while (start) {
                if (MODULE_MATCH(start->brd_module, mod))
                        return start;
                start = KLCF_NEXT(start);
        }

        /* Didn't find it. */
        return (lboard_t *)NULL;
}

lboard_t *
find_lboard_module_class(lboard_t *start, moduleid_t mod,
                                                unsigned char brd_type)
{
	while (start) {

		DBG("find_lboard_module_class: lboard 0x%p, start->brd_module 0x%x, mod 0x%x, start->brd_type 0x%x, brd_type 0x%x\n", start, start->brd_module, mod, start->brd_type, brd_type);

		if (MODULE_MATCH(start->brd_module, mod) &&
			(KLCLASS(start->brd_type) == KLCLASS(brd_type)))
			return start;
		start = KLCF_NEXT(start);
	}

	/* Didn't find it. */
	return (lboard_t *)NULL;
}


/*
 * Convert a NIC name to a name for use in the hardware graph.
 */
void
nic_name_convert(char *old_name, char *new_name)
{
        int i;
        char c;
        char *compare_ptr;

	if ((old_name[0] == '\0') || (old_name[1] == '\0')) {
                strcpy(new_name, EDGE_LBL_XWIDGET);
        } else {
                for (i = 0; i < strlen(old_name); i++) {
                        c = old_name[i];

                        if (isalpha(c))
                                new_name[i] = tolower(c);
                        else if (isdigit(c))
                                new_name[i] = c;
                        else
                                new_name[i] = '_';
                }
                new_name[i] = '\0';
        }

        /* XXX -
         * Since a bunch of boards made it out with weird names like
         * IO6-fibbbed and IO6P2, we need to look for IO6 in a name and
         * replace it with "baseio" to avoid confusion in the field.
	 * We also have to make sure we don't report media_io instead of
	 * baseio.
         */

        /* Skip underscores at the beginning of the name */
        for (compare_ptr = new_name; (*compare_ptr) == '_'; compare_ptr++)
                ;

	/*
	 * Check for some names we need to replace.  Early boards
	 * had junk following the name so check only the first
	 * characters.
	 */
        if (!strncmp(new_name, "io6", 3) || 
            !strncmp(new_name, "mio", 3) || 
	    !strncmp(new_name, "media_io", 8))
		strcpy(new_name, "baseio");
	else if (!strncmp(new_name, "divo", 4))
		strcpy(new_name, "divo") ;

}

/* Check if the given board corresponds to the global 
 * master io6
 */
int
is_master_baseio(nasid_t nasid,moduleid_t module,slotid_t slot)
{
	lboard_t	*board;

#if defined(CONFIG_IA64_SGI_SN1) || defined(CONFIG_IA64_GENERIC)
/* If this works then look for callers of is_master_baseio()
 * (e.g. iograph.c) and let them pass in a slot if they want
 */
	board = find_lboard_module((lboard_t *)KL_CONFIG_INFO(nasid), module);
#else
	board = find_lboard_modslot((lboard_t *)KL_CONFIG_INFO(nasid), module, slot);
#endif

#ifndef _STANDALONE
	{
		cnodeid_t cnode = NASID_TO_COMPACT_NODEID(nasid);

		if (!board && (NODEPDA(cnode)->xbow_peer != INVALID_NASID))
#if defined(CONFIG_IA64_SGI_SN1) || defined(CONFIG_IA64_GENERIC)
			board = find_lboard_module((lboard_t *)
				    KL_CONFIG_INFO(NODEPDA(cnode)->xbow_peer),
				    module);
#else
			board = find_lboard_modslot((lboard_t *)
				    KL_CONFIG_INFO(NODEPDA(cnode)->xbow_peer),
				    module, slot);
#endif
	}
#endif
	if (!board)
		return(0);
	return(board->brd_flags & GLOBAL_MASTER_IO6);
}
/*
 * Find the lboard structure and get the board name.
 * If we can't find the structure or it's too low a revision,
 * use default name.
 */
lboard_t *
get_board_name(nasid_t nasid, moduleid_t mod, slotid_t slot, char *name)
{
	lboard_t *brd;

	brd = find_lboard_modslot((lboard_t *)KL_CONFIG_INFO(nasid),
				  mod, slot);

#ifndef _STANDALONE
	{
		cnodeid_t cnode = NASID_TO_COMPACT_NODEID(nasid);

		if (!brd && (NODEPDA(cnode)->xbow_peer != INVALID_NASID))
			brd = find_lboard_modslot((lboard_t *)
				KL_CONFIG_INFO(NODEPDA(cnode)->xbow_peer),
				mod, slot);
	}
#endif

	if (!brd || (brd->brd_sversion < 2)) {
		strcpy(name, EDGE_LBL_XWIDGET);
	} else {
		nic_name_convert(brd->brd_name, name);
	}

	/*
 	 * PV # 540860
	 * If the name is not 'baseio' 
	 * get the lowest of all the names in the nic string.
	 * This is needed for boards like divo, which can have
	 * a bunch of daughter cards, but would like to be called
	 * divo. We could do this for baseio 
 	 * but it has some special case names that we would not
 	 * like to disturb at this point.
	 */

	/* gfx boards don't need any of this name scrambling */
	if (brd && (KLCLASS(brd->brd_type) == KLCLASS_GFX)) {
		return(brd);
	}

	if (!(!strcmp(name, "baseio") )) {
		if (brd) {
			sort_nic_names(brd) ;
			/* Convert to small case, '-' to '_' etc */
			nic_name_convert(brd->brd_name, name) ;
		}
	}

	return(brd);
}

/*
 * get_actual_nasid
 *
 *	Completely disabled brds have their klconfig on 
 *	some other nasid as they have no memory. But their
 *	actual nasid is hidden in the klconfig. Use this
 *	routine to get it. Works for normal boards too.
 */
nasid_t
get_actual_nasid(lboard_t *brd)
{
	klhub_t	*hub ;

	if (!brd)
		return INVALID_NASID ;

	/* find out if we are a completely disabled brd. */

        hub  = (klhub_t *)find_first_component(brd, KLSTRUCT_HUB);
	if (!hub)
                return INVALID_NASID ;
	if (!(hub->hub_info.flags & KLINFO_ENABLE))	/* disabled node brd */
		return hub->hub_info.physid ;
	else
		return brd->brd_nasid ;
}

int
xbow_port_io_enabled(nasid_t nasid, int link)
{
	lboard_t *brd;
	klxbow_t *xbow_p;

	/*
	 * look for boards that might contain an xbow or xbridge
	 */
	brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IOBRICK_XBOW);
	if (brd == NULL) return 0;
		
	if ((xbow_p = (klxbow_t *)find_component(brd, NULL, KLSTRUCT_XBOW))
	    == NULL)
	    return 0;

	if (!XBOW_PORT_TYPE_IO(xbow_p, link) || !XBOW_PORT_IS_ENABLED(xbow_p, link))
	    return 0;

	DBG("xbow_port_io_enabled:  brd 0x%p xbow_p 0x%p \n", brd, xbow_p);

	return 1;
}

void
board_to_path(lboard_t *brd, char *path)
{
	moduleid_t modnum;
	char *board_name;

	ASSERT(brd);

	switch (KLCLASS(brd->brd_type)) {

		case KLCLASS_NODE:
			board_name = EDGE_LBL_NODE;
			break;
		case KLCLASS_ROUTER:
			if (brd->brd_type == KLTYPE_META_ROUTER) {
				board_name = EDGE_LBL_META_ROUTER;
				hasmetarouter++;
			} else if (brd->brd_type == KLTYPE_REPEATER_ROUTER) {
				board_name = EDGE_LBL_REPEATER_ROUTER;
				hasmetarouter++;
			} else
				board_name = EDGE_LBL_ROUTER;
			break;
		case KLCLASS_MIDPLANE:
			board_name = EDGE_LBL_MIDPLANE;
			break;
		case KLCLASS_IO:
			board_name = EDGE_LBL_IO;
			break;
		case KLCLASS_IOBRICK:
			if (brd->brd_type == KLTYPE_PBRICK)
				board_name = EDGE_LBL_PBRICK;
			else if (brd->brd_type == KLTYPE_IBRICK)
				board_name = EDGE_LBL_IBRICK;
			else if (brd->brd_type == KLTYPE_XBRICK)
				board_name = EDGE_LBL_XBRICK;
			else
				board_name = EDGE_LBL_IOBRICK;
			break;
		default:
			board_name = EDGE_LBL_UNKNOWN;
	}
			
	modnum = brd->brd_module;

	ASSERT(modnum != MODULE_UNKNOWN && modnum != INVALID_MODULE);
#ifdef __ia64
	{
		char	buffer[16];
		memset(buffer, 0, 16);
		format_module_id(buffer, modnum, MODULE_FORMAT_BRIEF);
		sprintf(path, EDGE_LBL_MODULE "/%s/%s", buffer, board_name);
	}
#else
	sprintf(path, "%H/%s", modnum, board_name);
#endif
}

/*
 * Get the module number for a NASID.
 */
moduleid_t
get_module_id(nasid_t nasid)
{
	lboard_t *brd;

	brd = find_lboard((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_SNIA);

	if (!brd)
		return INVALID_MODULE;
	else
		return brd->brd_module;
}


#define MHZ	1000000


/* Get the canonical hardware graph name for the given pci component
 * on the given io board.
 */
void
device_component_canonical_name_get(lboard_t 	*brd,
				    klinfo_t 	*component,
				    char 	*name)
{
	moduleid_t 	modnum;
	slotid_t 	slot;
	char 		board_name[20];

	ASSERT(brd);

	/* Get the module number of this board */
	modnum = brd->brd_module;

	/* Convert the [ CLASS | TYPE ] kind of slotid
	 * into a string 
	 */
	slot = brd->brd_slot;
	ASSERT(modnum != MODULE_UNKNOWN && modnum != INVALID_MODULE);

	/* Get the io board name  */
	if (!brd || (brd->brd_sversion < 2)) {
		strcpy(name, EDGE_LBL_XWIDGET);
	} else {
		nic_name_convert(brd->brd_name, board_name);
	}

	/* Give out the canonical  name of the pci device*/
	sprintf(name, 
		"/dev/hw/"EDGE_LBL_MODULE "/%x/"EDGE_LBL_SLOT"/%s/"
		EDGE_LBL_PCI"/%d", 
		modnum, board_name,KLCF_BRIDGE_W_ID(component));
}

/*
 * Get the serial number of the main  component of a board
 * Returns 0 if a valid serial number is found
 * 1 otherwise.
 * Assumptions: Nic manufacturing string  has the following format
 *			*Serial:<serial_number>;*
 */
static int
component_serial_number_get(lboard_t 		*board,
			    klconf_off_t 	mfg_nic_offset,
			    char		*serial_number,
			    char		*key_pattern)
{

	char	*mfg_nic_string;
	char	*serial_string,*str;
	int	i;
	char	*serial_pattern = "Serial:";

	/* We have an error on a null mfg nic offset */
	if (!mfg_nic_offset)
		return(1);
	/* Get the hub's manufacturing nic information
	 * which is in the form of a pre-formatted string
	 */
	mfg_nic_string = 
		(char *)NODE_OFFSET_TO_K0(NASID_GET(board),
					  mfg_nic_offset);
	/* There is no manufacturing nic info */
	if (!mfg_nic_string)
		return(1);

	str = mfg_nic_string;
	/* Look for the key pattern first (if it is  specified)
	 * and then print the serial number corresponding to that.
	 */
	if (strcmp(key_pattern,"") && 
	    !(str = strstr(mfg_nic_string,key_pattern)))
		return(1);

	/* There is no serial number info in the manufacturing
	 * nic info
	 */
	if (!(serial_string = strstr(str,serial_pattern)))
		return(1);

	serial_string = serial_string + strlen(serial_pattern);
	/*  Copy the serial number information from the klconfig */
	i = 0;
	while (serial_string[i] != ';') {
		serial_number[i] = serial_string[i];
		i++;
	}
	serial_number[i] = 0;
	
	return(0);
}
/*
 * Get the serial number of a board
 * Returns 0 if a valid serial number is found
 * 1 otherwise.
 */

int
board_serial_number_get(lboard_t *board,char *serial_number)
{
	ASSERT(board && serial_number);
	if (!board || !serial_number)
		return(1);

	strcpy(serial_number,"");
	switch(KLCLASS(board->brd_type)) {
	case KLCLASS_CPU: {	/* Node board */
		klhub_t	*hub;
		
		/* Get the hub component information */
		hub = (klhub_t *)find_first_component(board,
						      KLSTRUCT_HUB);
		/* If we don't have a hub component on an IP27
		 * then we have a weird klconfig.
		 */
		if (!hub)
			return(1);
		/* Get the serial number information from
		 * the hub's manufacturing nic info
		 */
		if (component_serial_number_get(board,
						hub->hub_mfg_nic,
						serial_number,
#if defined(CONFIG_IA64_SGI_SN1) || defined(CONFIG_IA64_GENERIC)
						"IP37"))
#else
						"IP27"))
			/* Try with IP31 key if IP27 key fails */
			if (component_serial_number_get(board,
							hub->hub_mfg_nic,
							serial_number,
							"IP31"))
#endif /* CONFIG_IA64_SGI_SN1 */
				return(1);
		break;
	}
	case KLCLASS_IO: {	/* IO board */
		if (KLTYPE(board->brd_type) == KLTYPE_TPU) {
		/* Special case for TPU boards */
			kltpu_t *tpu;	
		
			/* Get the tpu component information */
			tpu = (kltpu_t *)find_first_component(board,
						      KLSTRUCT_TPU);
			/* If we don't have a tpu component on a tpu board
			 * then we have a weird klconfig.
			 */
			if (!tpu)
				return(1);
			/* Get the serial number information from
			 * the tpu's manufacturing nic info
			 */
			if (component_serial_number_get(board,
						tpu->tpu_mfg_nic,
						serial_number,
						""))
				return(1);
			break;
		} else  if ((KLTYPE(board->brd_type) == KLTYPE_GSN_A) ||
		            (KLTYPE(board->brd_type) == KLTYPE_GSN_B)) {
		/* Special case for GSN boards */
			klgsn_t *gsn;	
		
			/* Get the gsn component information */
			gsn = (klgsn_t *)find_first_component(board,
			      ((KLTYPE(board->brd_type) == KLTYPE_GSN_A) ?
					KLSTRUCT_GSN_A : KLSTRUCT_GSN_B));
			/* If we don't have a gsn component on a gsn board
			 * then we have a weird klconfig.
			 */
			if (!gsn)
				return(1);
			/* Get the serial number information from
			 * the gsn's manufacturing nic info
			 */
			if (component_serial_number_get(board,
						gsn->gsn_mfg_nic,
						serial_number,
						""))
				return(1);
			break;
		} else {
		     	klbri_t	*bridge;
		
			/* Get the bridge component information */
			bridge = (klbri_t *)find_first_component(board,
							 KLSTRUCT_BRI);
			/* If we don't have a bridge component on an IO board
			 * then we have a weird klconfig.
			 */
			if (!bridge)
				return(1);
			/* Get the serial number information from
		 	 * the bridge's manufacturing nic info
			 */
			if (component_serial_number_get(board,
						bridge->bri_mfg_nic,
						serial_number,
						""))
				return(1);
			break;
		}
	}
	case KLCLASS_ROUTER: {	/* Router board */
		klrou_t *router;	
		
		/* Get the router component information */
		router = (klrou_t *)find_first_component(board,
							 KLSTRUCT_ROU);
		/* If we don't have a router component on a router board
		 * then we have a weird klconfig.
		 */
		if (!router)
			return(1);
		/* Get the serial number information from
		 * the router's manufacturing nic info
		 */
		if (component_serial_number_get(board,
						router->rou_mfg_nic,
						serial_number,
						""))
			return(1);
		break;
	}
	case KLCLASS_GFX: {	/* Gfx board */
		klgfx_t *graphics;
		
		/* Get the graphics component information */
		graphics = (klgfx_t *)find_first_component(board, KLSTRUCT_GFX);
		/* If we don't have a gfx component on a gfx board
		 * then we have a weird klconfig.
		 */
		if (!graphics)
			return(1);
		/* Get the serial number information from
		 * the graphics's manufacturing nic info
		 */
		if (component_serial_number_get(board,
						graphics->gfx_mfg_nic,
						serial_number,
						""))
			return(1);
		break;
	}
	default:
		strcpy(serial_number,"");
		break;
	}
	return(0);
}

#include "asm/sn/sn_private.h"

xwidgetnum_t
nodevertex_widgetnum_get(devfs_handle_t node_vtx)
{
	hubinfo_t hubinfo_p;

	hwgraph_info_get_LBL(node_vtx, INFO_LBL_NODE_INFO, 
			     (arbitrary_info_t *) &hubinfo_p);
	return(hubinfo_p->h_widgetid);
}

devfs_handle_t
nodevertex_xbow_peer_get(devfs_handle_t node_vtx)
{
	hubinfo_t hubinfo_p;
	nasid_t xbow_peer_nasid;
	cnodeid_t xbow_peer;

	hwgraph_info_get_LBL(node_vtx, INFO_LBL_NODE_INFO,
				     (arbitrary_info_t *) &hubinfo_p);
	xbow_peer_nasid = hubinfo_p->h_nodepda->xbow_peer;
	if(xbow_peer_nasid == INVALID_NASID) 
			return ( (devfs_handle_t)-1);
	xbow_peer = NASID_TO_COMPACT_NODEID(xbow_peer_nasid);
	return(NODEPDA(xbow_peer)->node_vertex);
}

/* NIC Sorting Support */

#define MAX_NICS_PER_STRING 	32
#define MAX_NIC_NAME_LEN	32

static char *
get_nic_string(lboard_t *lb)
{
        int         	i;
        klinfo_t    	*k = NULL ;
    	klconf_off_t    mfg_off = 0 ;
    	char            *mfg_nic = NULL ;

        for (i = 0; i < KLCF_NUM_COMPS(lb); i++) {
                k = KLCF_COMP(lb, i) ;
                switch(k->struct_type) {
                        case KLSTRUCT_BRI:
            			mfg_off = ((klbri_t *)k)->bri_mfg_nic ;
				break ;

                        case KLSTRUCT_HUB:
            			mfg_off = ((klhub_t *)k)->hub_mfg_nic ;
				break ;

                        case KLSTRUCT_ROU:
            			mfg_off = ((klrou_t *)k)->rou_mfg_nic ;
				break ;

                        case KLSTRUCT_GFX:
            			mfg_off = ((klgfx_t *)k)->gfx_mfg_nic ;
				break ;

                        case KLSTRUCT_TPU:
            			mfg_off = ((kltpu_t *)k)->tpu_mfg_nic ;
				break ;

                        case KLSTRUCT_GSN_A:
                        case KLSTRUCT_GSN_B:
            			mfg_off = ((klgsn_t *)k)->gsn_mfg_nic ;
				break ;

                        case KLSTRUCT_XTHD:
                                mfg_off = ((klxthd_t *)k)->xthd_mfg_nic ;
                                break;

			default:
				mfg_off = 0 ;
                                break ;
                }
		if (mfg_off)
			break ;
        }

	if ((mfg_off) && (k))
		mfg_nic = (char *)NODE_OFFSET_TO_K0(k->nasid, mfg_off) ;

        return mfg_nic ;
}

char *
get_first_string(char **ptrs, int n)
{
        int     i ;
        char    *tmpptr ;

        if ((ptrs == NULL) || (n == 0))
                return NULL ;

        tmpptr = ptrs[0] ;

        if (n == 1)
                return tmpptr ;

        for (i = 0 ; i < n ; i++) {
                if (strcmp(tmpptr, ptrs[i]) > 0)
                        tmpptr = ptrs[i] ;
        }

        return tmpptr ;
}

int
get_ptrs(char *idata, char **ptrs, int n, char *label)
{
        int     i = 0 ;
        char    *tmp = idata ;

        if ((ptrs == NULL) || (idata == NULL) || (label == NULL) || (n == 0))
                return 0 ;

        while  ( (tmp = strstr(tmp, label)) ){
                tmp += strlen(label) ;
                /* check for empty name field, and last NULL ptr */
                if ((i < (n-1)) && (*tmp != ';')) {
                        ptrs[i++] = tmp ;
                }
        }

        ptrs[i] = NULL ;

        return i ;
}

/*
 * sort_nic_names
 *
 * 	Does not really do sorting. Find the alphabetically lowest
 *	name among all the nic names found in a nic string.
 *
 * Return:
 *	Nothing
 *
 * Side Effects:
 *
 *	lb->brd_name gets the new name found
 */

static void
sort_nic_names(lboard_t *lb)
{
	char 	*nic_str ;
        char    *ptrs[MAX_NICS_PER_STRING] ;
        char    name[MAX_NIC_NAME_LEN] ;
        char    *tmp, *tmp1 ;

	*name = 0 ;

	/* Get the nic pointer from the lb */

	if ((nic_str = get_nic_string(lb)) == NULL)
		return ;

        tmp = get_first_string(ptrs,
                        get_ptrs(nic_str, ptrs, MAX_NICS_PER_STRING, "Name:")) ;

        if (tmp == NULL)
		return ;

        if  ( (tmp1 = strchr(tmp, ';')) ){
                strncpy(name, tmp, tmp1-tmp) ;
                name[tmp1-tmp] = 0 ;
        } else {
                strncpy(name, tmp, (sizeof(name) -1)) ;
                name[sizeof(name)-1] = 0 ;
        }

	strcpy(lb->brd_name, name) ;
}



char brick_types[MAX_BRICK_TYPES + 1] = "crikxdp789012345";

#if defined(CONFIG_IA64_SGI_SN1) || defined(CONFIG_IA64_GENERIC)

/*
 * Format a module id for printing.
 */
void
format_module_id(char *buffer, moduleid_t m, int fmt)
{
	int rack, position;
	char brickchar;

	rack = MODULE_GET_RACK(m);
	ASSERT(MODULE_GET_BTYPE(m) < MAX_BRICK_TYPES);
	brickchar = MODULE_GET_BTCHAR(m);
	position = MODULE_GET_BPOS(m);

	if (fmt == MODULE_FORMAT_BRIEF) {
	    /* Brief module number format, eg. 002c15 */

	    /* Decompress the rack number */
	    *buffer++ = '0' + RACK_GET_CLASS(rack);
	    *buffer++ = '0' + RACK_GET_GROUP(rack);
	    *buffer++ = '0' + RACK_GET_NUM(rack);

	    /* Add the brick type */
	    *buffer++ = brickchar;
	}
	else if (fmt == MODULE_FORMAT_LONG) {
	    /* Fuller hwgraph format, eg. rack/002/bay/15 */

	    strcpy(buffer, EDGE_LBL_RACK "/");  buffer += strlen(buffer);

	    *buffer++ = '0' + RACK_GET_CLASS(rack);
	    *buffer++ = '0' + RACK_GET_GROUP(rack);
	    *buffer++ = '0' + RACK_GET_NUM(rack);

	    strcpy(buffer, "/" EDGE_LBL_RPOS "/");  buffer += strlen(buffer);
	}

	/* Add the bay position, using at least two digits */
	if (position < 10)
	    *buffer++ = '0';
	sprintf(buffer, "%d", position);

}

/*
 * Parse a module id, in either brief or long form.
 * Returns < 0 on error.
 * The long form does not include a brick type, so it defaults to 0 (CBrick)
 */
int
parse_module_id(char *buffer)
{
	unsigned int	v, rack, bay, type, form;
	moduleid_t	m;
	char 		c;

	if (strstr(buffer, EDGE_LBL_RACK "/") == buffer) {
		form = MODULE_FORMAT_LONG;
		buffer += strlen(EDGE_LBL_RACK "/");

		/* A long module ID must be exactly 5 non-template chars. */
		if (strlen(buffer) != strlen("/" EDGE_LBL_RPOS "/") + 5)
			return -1;
	}
	else {
		form = MODULE_FORMAT_BRIEF;

		/* A brief module id must be exactly 6 characters */
		if (strlen(buffer) != 6)
			return -2;
	}

	/* The rack number must be exactly 3 digits */
	if (!(isdigit(buffer[0]) && isdigit(buffer[1]) && isdigit(buffer[2])))
		return -3;

	rack = 0;
	v = *buffer++ - '0';
	if (v > RACK_CLASS_MASK(rack) >> RACK_CLASS_SHFT(rack))
		return -4;
	RACK_ADD_CLASS(rack, v);

	v = *buffer++ - '0';
	if (v > RACK_GROUP_MASK(rack) >> RACK_GROUP_SHFT(rack))
		return -5;
	RACK_ADD_GROUP(rack, v);

	v = *buffer++ - '0';
	/* rack numbers are 1-based */
	if (v-1 > RACK_NUM_MASK(rack) >> RACK_NUM_SHFT(rack))
		return -6;
	RACK_ADD_NUM(rack, v);

	if (form == MODULE_FORMAT_BRIEF) {
		/* Next should be a module type character.  Accept ucase or lcase. */
		c = *buffer++;
		if (!isalpha(c))
			return -7;

		/* strchr() returns a pointer into brick_types[], or NULL */
		type = (unsigned int)(strchr(brick_types, tolower(c)) - brick_types);
		if (type > MODULE_BTYPE_MASK >> MODULE_BTYPE_SHFT)
			return -8;
	}
	else {
		/* Hardcode the module type, and skip over the boilerplate */
		type = MODULE_CBRICK;

		if (strstr(buffer, "/" EDGE_LBL_RPOS "/") != buffer)
			return -9;

		buffer += strlen("/" EDGE_LBL_RPOS "/");
	}
		
	/* The bay number is last.  Make sure it's exactly two digits */

	if (!(isdigit(buffer[0]) && isdigit(buffer[1]) && !buffer[2]))
		return -10;

	bay = 10 * (buffer[0] - '0') + (buffer[1] - '0');

	if (bay > MODULE_BPOS_MASK >> MODULE_BPOS_SHFT)
		return -11;

	m = RBT_TO_MODULE(rack, bay, type);

	/* avoid sign extending the moduleid_t */
	return (int)(unsigned short)m;
}

#else /* CONFIG_IA64_SGI_SN1 */

/*
 * Format a module id for printing.
 */
void
format_module_id(char *buffer, moduleid_t m, int fmt)
{
    if (fmt == MODULE_FORMAT_BRIEF) {
		sprintf(buffer, "%d", m);
    }
    else if (fmt == MODULE_FORMAT_LONG) {
		sprintf(buffer, EDGE_LBL_MODULE "/%d", m);
    }
}

/*
 * Parse a module id, in either brief or long form.
 * Returns < 0 on error.
 */
int
parse_module_id(char *buffer)
{
    moduleid_t m;
    char c;

    if (strstr(buffer, EDGE_LBL_MODULE "/") == buffer)
	buffer += strlen(EDGE_LBL_MODULE "/");

    for (m = 0; *buffer; buffer++) {
	c = *buffer;
	if (!isdigit(c))
	    return -1;
	m = 10 * m + (c - '0');
    }

    /* avoid sign extending the moduleid_t */
    return (int)(unsigned short)m;
}

#endif /* CONFIG_IA64_SGI_SN1 */