aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ia64/sn/io/eeprom.c
blob: 5b190517de6f9fb4fd286e1688b0ddb4ec571051 (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
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
/*
 * 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) 1999-2002 Silicon Graphics, Inc. All rights reserved.
 */

/*
 * WARNING:     There is more than one copy of this file in different isms.
 *              All copies must be kept exactly in sync.
 *              Do not modify this file without also updating the following:
 *
 *              irix/kern/io/eeprom.c
 *              stand/arcs/lib/libsk/ml/eeprom.c
 *		stand/arcs/lib/libkl/io/eeprom.c
 *
 *      (from time to time they might not be in sync but that's due to bringup
 *       activity - this comment is to remind us that they eventually have to
 *       get back together)
 *
 * eeprom.c
 *
 * access to board-mounted EEPROMs via the L1 system controllers
 *
 */

#include <linux/types.h>
#include <linux/config.h>
#include <linux/slab.h>
#include <asm/sn/sgi.h>
#include <asm/sn/io.h>
#include <asm/sn/iograph.h>
#include <asm/sn/invent.h>
#include <asm/sn/hcl.h>
#include <asm/sn/hcl_util.h>
#include <asm/sn/labelcl.h>
#include <asm/sn/eeprom.h>
#include <asm/sn/router.h>
#include <asm/sn/module.h>
#include <asm/sn/ksys/l1.h>
#include <asm/sn/nodepda.h>
#include <asm/sn/clksupport.h>
#include <asm/sn/sn_cpuid.h>
#include <asm/sn/simulator.h>

#if defined(EEPROM_DEBUG)
#define db_printf(x) printk x
#else
#define db_printf(x) printk x
#endif

#define BCOPY(x,y,z)	memcpy(y,x,z)

#define UNDERSCORE	0	/* don't convert underscores to hyphens */
#define HYPHEN		1	/* convert underscores to hyphens */

void		copy_ascii_field( char *to, char *from, int length,
			          int change_underscore );
uint64_t	generate_unique_id( char *sn, int sn_len );
uchar_t		char_to_base36( char c );
int		nicify( char *dst, eeprom_brd_record_t *src );
static void	int64_to_hex_string( char *out, uint64_t val );

// extern int router_lock( net_vec_t, int, int );
// extern int router_unlock( net_vec_t );
#define ROUTER_LOCK(p) 	// router_lock(p, 10000, 3000000)
#define ROUTER_UNLOCK(p) 	// router_unlock(p)

#define IP27LOG_OVNIC           "OverrideNIC"


/* the following function converts an EEPROM record to a close facsimile
 * of the string returned by reading a Dallas Semiconductor NIC (see
 * one of the many incarnations of nic.c for details on that driver)
 */
int nicify( char *dst, eeprom_brd_record_t *src )
{
    int field_len;
    uint64_t unique_id;
    char *cur_dst = dst;
    eeprom_board_ia_t   *board;

    board   = src->board_ia;
    ASSERT( board );  /* there should always be a board info area */

    /* copy part number */
    strcpy( cur_dst, "Part:" );
    cur_dst += strlen( cur_dst );
    ASSERT( (board->part_num_tl & FIELD_FORMAT_MASK)
	    == FIELD_FORMAT_ASCII );
    field_len = board->part_num_tl & FIELD_LENGTH_MASK;
    copy_ascii_field( cur_dst, board->part_num, field_len, HYPHEN );
    cur_dst += field_len;

    /* copy product name */
    strcpy( cur_dst, ";Name:" );
    cur_dst += strlen( cur_dst );
    ASSERT( (board->product_tl & FIELD_FORMAT_MASK) == FIELD_FORMAT_ASCII );
    field_len = board->product_tl & FIELD_LENGTH_MASK;
    copy_ascii_field( cur_dst, board->product, field_len, UNDERSCORE );
    cur_dst += field_len;

    /* copy serial number */
    strcpy( cur_dst, ";Serial:" );
    cur_dst += strlen( cur_dst );
    ASSERT( (board->serial_num_tl & FIELD_FORMAT_MASK)
	    == FIELD_FORMAT_ASCII );
    field_len = board->serial_num_tl & FIELD_LENGTH_MASK;
    copy_ascii_field( cur_dst, board->serial_num, field_len,
		      HYPHEN);

    cur_dst += field_len;

    /* copy revision */
    strcpy( cur_dst, ";Revision:");
    cur_dst += strlen( cur_dst );
    ASSERT( (board->board_rev_tl & FIELD_FORMAT_MASK)
	    == FIELD_FORMAT_ASCII );
    field_len = board->board_rev_tl & FIELD_LENGTH_MASK;
    copy_ascii_field( cur_dst, board->board_rev, field_len, HYPHEN );
    cur_dst += field_len;

    /* EEPROMs don't have equivalents for the Group, Capability and
     * Variety fields, so we pad these with 0's
     */
    strcpy( cur_dst, ";Group:ff;Capability:ffffffff;Variety:ff" );
    cur_dst += strlen( cur_dst );

    /* use the board serial number to "fake" a laser id */
    strcpy( cur_dst, ";Laser:" );
    cur_dst += strlen( cur_dst );
    unique_id = generate_unique_id( board->serial_num,
				    board->serial_num_tl & FIELD_LENGTH_MASK );
    int64_to_hex_string( cur_dst, unique_id );
    strcat( dst, ";" );

    return 1;
}


/* These functions borrow heavily from chars2* in nic.c
 */
void copy_ascii_field( char *to, char *from, int length,
		       int change_underscore )
{
    int i;
    for( i = 0; i < length; i++ ) {

	/* change underscores to hyphens if requested */
	if( from[i] == '_' && change_underscore == HYPHEN )
	    to[i] = '-';

	/* ; and ; are separators, so mustn't appear within
	 * a field */
	else if( from[i] == ':' || from[i] == ';' )
	    to[i] = '?';

	/* I'm not sure why or if ASCII character 0xff would
	 * show up in an EEPROM field, but the NIC parsing
	 * routines wouldn't like it if it did... so we
	 * get rid of it, just in case. */
	else if( (unsigned char)from[i] == (unsigned char)0xff )
	    to[i] = ' ';
	
	/* unprintable characters are replaced with . */
	else if( from[i] < ' ' || from[i] >= 0x7f )
	    to[i] = '.';

	/* otherwise, just copy the character */
	else
	    to[i] = from[i];
    }

    if( i == 0 ) {
	to[i] = ' '; /* return at least a space... */
	i++;
    }
    to[i] = 0;	     /* terminating null */
}

/* Note that int64_to_hex_string currently only has a big-endian
 * implementation.
 */
#ifdef _MIPSEB
static void int64_to_hex_string( char *out, uint64_t val )
{
    int i;
    uchar_t table[] = "0123456789abcdef";
    uchar_t *byte_ptr = (uchar_t *)&val;
    for( i = 0; i < sizeof(uint64_t); i++ ) {
	out[i*2] = table[ ((*byte_ptr) >> 4) & 0x0f ];
	out[i*2+1] = table[ (*byte_ptr) & 0x0f ];
	byte_ptr++;
    }
    out[i*2] = '\0';
}

#else /* little endian */

static void int64_to_hex_string( char *out, uint64_t val )
{


	printk("int64_to_hex_string needs a little-endian implementation.\n");
}
#endif /* _MIPSEB */

/* Convert a standard ASCII serial number to a unique integer
 * id number by treating the serial number string as though
 * it were a base 36 number
 */
uint64_t generate_unique_id( char *sn, int sn_len )
{
    int uid = 0;
    int i;

    #define VALID_BASE36(c)	((c >= '0' && c <='9') \
			    ||   (c >= 'A' && c <='Z') \
			    ||   (c >= 'a' && c <='z'))

    for( i = 0; i < sn_len; i++ ) {
	if( !VALID_BASE36(sn[i]) )
	    continue;
	uid *= 36;
	uid += char_to_base36( sn[i] );
    }

    if( uid == 0 )
	return rtc_time();

    return uid;
}

uchar_t char_to_base36( char c )
{
    uchar_t val;

    if( c >= '0' && c <= '9' )
	val = (c - '0');

    else if( c >= 'A' && c <= 'Z' )
	val = (c - 'A' + 10);

    else if( c >= 'a' && c <= 'z' )
	val = (c - 'a' + 10);

    else val = 0;

    return val;
}


/* given a pointer to the three-byte little-endian EEPROM representation
 * of date-of-manufacture, this function translates to a big-endian
 * integer format
 */
int eeprom_xlate_board_mfr_date( uchar_t *src )
{
    int rval = 0;
    rval += *src; src++;
    rval += ((int)(*src) << 8); src ++;
    rval += ((int)(*src) << 16);
    return rval;
}


int eeprom_str( char *nic_str, nasid_t nasid, int component )
{
    eeprom_brd_record_t eep;
    eeprom_board_ia_t board;
    eeprom_chassis_ia_t chassis;
    int r;

    if( (component & C_DIMM) == C_DIMM ) {
	/* this function isn't applicable to DIMMs */
	return EEP_PARAM;
    }
    else {
	eep.board_ia = &board;
	eep.spd = NULL;
	if( !(component & SUBORD_MASK) )
	    eep.chassis_ia = &chassis;  /* only main boards have a chassis
					 * info area */
	else
	    eep.chassis_ia = NULL;
    }
    
    switch( component & BRICK_MASK ) {
      case C_BRICK:
	r = cbrick_eeprom_read( &eep, nasid, component );
	break;
      case IO_BRICK:
	r = iobrick_eeprom_read( &eep, nasid, component );
	break;
      default:
	return EEP_PARAM;  /* must be an invalid component */
    }
    if( r )
	return r;
    if( !nicify( nic_str, &eep ) )
	return EEP_NICIFY;

    return EEP_OK;
}

int vector_eeprom_str( char *nic_str, nasid_t nasid,
		       int component, net_vec_t path )
{
    eeprom_brd_record_t eep;
    eeprom_board_ia_t board;
    eeprom_chassis_ia_t chassis;
    int r;

    eep.board_ia = &board;
    if( !(component & SUBORD_MASK) )
        eep.chassis_ia = &chassis;  /* only main boards have a chassis
                                     * info area */
    else
        eep.chassis_ia = NULL;

    if( !(component & VECTOR) )
	return EEP_PARAM;

    if( (r = vector_eeprom_read( &eep, nasid, path, component )) )
	return r;

    if( !nicify( nic_str, &eep ) )
        return EEP_NICIFY;

    return EEP_OK;
}


int is_iobrick( int nasid, int widget_num )
{
    uint32_t wid_reg;
    int part_num, mfg_num;

    /* Read the widget's WIDGET_ID register to get
     * its part number and mfg number
     */
    wid_reg = *(volatile int32_t *)
        (NODE_SWIN_BASE( nasid, widget_num ) + WIDGET_ID);

    part_num = (wid_reg & WIDGET_PART_NUM) >> WIDGET_PART_NUM_SHFT;
    mfg_num = (wid_reg & WIDGET_MFG_NUM) >> WIDGET_MFG_NUM_SHFT;

    /* Is this the "xbow part" of an XBridge?  If so, this
     * widget is definitely part of an I/O brick.
     */
    if( part_num == XXBOW_WIDGET_PART_NUM &&
	mfg_num == XXBOW_WIDGET_MFGR_NUM )

	return 1;

    /* Is this a "bridge part" of an XBridge?  If so, once
     * again, we know this widget is part of an I/O brick.
     */
    if( part_num == XBRIDGE_WIDGET_PART_NUM &&
	mfg_num == XBRIDGE_WIDGET_MFGR_NUM )

	return 1;

    return 0;
}


int cbrick_uid_get( nasid_t nasid, uint64_t *uid )
{
#if !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
    return EEP_L1;
#else
    char uid_str[32];
    char msg[BRL1_QSIZE];
    int subch, len;
    l1sc_t sc;
    l1sc_t *scp;
    int local = (nasid == get_nasid());

    if ( IS_RUNNING_ON_SIMULATOR() )
	return EEP_L1;

    /* If the promlog variable pointed to by IP27LOG_OVNIC is set,
     * use that value for the cbrick UID rather than the EEPROM
     * serial number.
     */
#ifdef LOG_GETENV
    if( ip27log_getenv( nasid, IP27LOG_OVNIC, uid_str, NULL, 0 ) >= 0 )
    {
	/* We successfully read IP27LOG_OVNIC, so return it as the UID. */
	db_printf(( "cbrick_uid_get:"
		    "Overriding UID with environment variable %s\n", 
		    IP27LOG_OVNIC ));
	*uid = strtoull( uid_str, NULL, 0 );
	return EEP_OK;
    }
#endif

    /* If this brick is retrieving its own uid, use the local l1sc_t to
     * arbitrate access to the l1; otherwise, set up a new one.
     */
    if( local ) {
	scp = get_l1sc();
    }
    else {
	scp = &sc;
	sc_init( &sc, nasid, BRL1_LOCALHUB_UART );
    }

    /* fill in msg with the opcode & params */
    BZERO( msg, BRL1_QSIZE );
    if( (subch = sc_open( scp, L1_ADDR_LOCAL )) < 0 )
	return EEP_L1;

    if( (len = sc_construct_msg( scp, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_SER_NUM, 0 )) < 0 )
    {
	sc_close( scp, subch );
	return( EEP_L1 );
    }

    /* send the request to the L1 */
    if( sc_command( scp, subch, msg, msg, &len ) ) {
	sc_close( scp, subch );
	return( EEP_L1 );
    }

    /* free up subchannel */
    sc_close(scp, subch);

    /* check response */
    if( sc_interpret_resp( msg, 2, L1_ARG_ASCII, uid_str ) < 0 )
    {
	return( EEP_L1 );
    }

    *uid = generate_unique_id( uid_str, strlen( uid_str ) );

    return EEP_OK;
#endif /* CONFIG_SERIAL_SGI_L1_PROTOCOL */
}


int rbrick_uid_get( nasid_t nasid, net_vec_t path, uint64_t *uid )
{
#if !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
    return EEP_L1;
#else
    char uid_str[32];
    char msg[BRL1_QSIZE];
    int subch, len;
    l1sc_t sc;

    if ( IS_RUNNING_ON_SIMULATOR() )
	return EEP_L1;

#define FAIL								\
    {									\
	*uid = rtc_time();						\
	printk( "rbrick_uid_get failed; using current time as uid\n" );	\
	return EEP_OK;							\
    }

    ROUTER_LOCK(path);
    sc_init( &sc, nasid, path );

    /* fill in msg with the opcode & params */
    BZERO( msg, BRL1_QSIZE );
    if( (subch = sc_open( &sc, L1_ADDR_LOCAL )) < 0 ) {
	ROUTER_UNLOCK(path);
	FAIL;
    }

    if( (len = sc_construct_msg( &sc, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_SER_NUM, 0 )) < 0 )
    {
	ROUTER_UNLOCK(path);
	sc_close( &sc, subch );
	FAIL;
    }

    /* send the request to the L1 */
    if( sc_command( &sc, subch, msg, msg, &len ) ) {
	ROUTER_UNLOCK(path);
	sc_close( &sc, subch );
	FAIL;
    }

    /* free up subchannel */
    ROUTER_UNLOCK(path);
    sc_close(&sc, subch);

    /* check response */
    if( sc_interpret_resp( msg, 2, L1_ARG_ASCII, uid_str ) < 0 )
    {
	FAIL;
    }

    *uid = generate_unique_id( uid_str, strlen( uid_str ) );

    return EEP_OK;
#endif /* CONFIG_SERIAL_SGI_L1_PROTOCOL */
}

int iobrick_uid_get( nasid_t nasid, uint64_t *uid )
{
    eeprom_brd_record_t eep;
    eeprom_board_ia_t board;
    eeprom_chassis_ia_t chassis;
    int r;

    eep.board_ia = &board;
    eep.chassis_ia = &chassis;
    eep.spd = NULL;

    r = iobrick_eeprom_read( &eep, nasid, IO_BRICK );
    if( r != EEP_OK ) {
        *uid = rtc_time();
        return r;
    }

    *uid = generate_unique_id( board.serial_num,
                               board.serial_num_tl & FIELD_LENGTH_MASK );

    return EEP_OK;
}


int ibrick_mac_addr_get( nasid_t nasid, char *eaddr )
{
    eeprom_brd_record_t eep;
    eeprom_board_ia_t board;
    eeprom_chassis_ia_t chassis;
    int r;
    char *tmp;

    eep.board_ia = &board;
    eep.chassis_ia = &chassis;
    eep.spd = NULL;

    r = iobrick_eeprom_read( &eep, nasid, IO_BRICK );
    if( (r != EEP_OK) || (board.mac_addr[0] == '\0') ) {
	db_printf(( "ibrick_mac_addr_get: "
		    "Couldn't read MAC address from EEPROM\n" ));
	return EEP_L1;
    }
    else {
	/* successfully read info area */
	int ix;
	tmp = board.mac_addr;
	for( ix = 0; ix < (board.mac_addr_tl & FIELD_LENGTH_MASK); ix++ )
	{
	    *eaddr++ = *tmp++;
	}
	*eaddr = '\0';
    }

    return EEP_OK;
}


/* 
 * eeprom_vertex_info_set
 *
 * Given a vertex handle, a component designation, a starting nasid
 * and (in the case of a router) a vector path to the component, this
 * function will read the EEPROM and attach the resulting information
 * to the vertex in the same string format as that provided by the
 * Dallas Semiconductor NIC drivers.  If the vertex already has the
 * string, this function just returns the string.
 */

extern char *nic_vertex_info_get( devfs_handle_t );
extern void nic_vmc_check( devfs_handle_t, char * );
/* the following were lifted from nic.c - change later? */
#define MAX_INFO 2048
#define NEWSZ(ptr,sz)   ((ptr) = kern_malloc((sz)))
#define DEL(ptr) (kern_free((ptr)))

char *eeprom_vertex_info_set( int component, int nasid, devfs_handle_t v,
                              net_vec_t path )
{
        char *info_tmp;
        int info_len;
        char *info;

        /* see if this vertex is already marked */
        info_tmp = nic_vertex_info_get(v);
        if (info_tmp) return info_tmp;

        /* get a temporary place for the data */
        NEWSZ(info_tmp, MAX_INFO);
        if (!info_tmp) return NULL;

        /* read the EEPROM */
	if( component & R_BRICK ) {
	    if( RBRICK_EEPROM_STR( info_tmp, nasid, path ) != EEP_OK )
		return NULL;
	}
	else {
            if( eeprom_str( info_tmp, nasid, component ) != EEP_OK )
	        return NULL;
	}

        /* allocate a smaller final place */
        info_len = strlen(info_tmp)+1;
        NEWSZ(info, info_len);
        if (info) {
                strcpy(info, info_tmp);
                DEL(info_tmp);
        } else {
                info = info_tmp;
        }

        /* add info to the vertex */
        hwgraph_info_add_LBL(v, INFO_LBL_NIC,
                             (arbitrary_info_t) info);

        /* see if someone else got there first */
        info_tmp = nic_vertex_info_get(v);
        if (info != info_tmp) {
            DEL(info);
            return info_tmp;
        }

        /* export the data */
        hwgraph_info_export_LBL(v, INFO_LBL_NIC, info_len);

        /* trigger all matching callbacks */
        nic_vmc_check(v, info);

        return info;
}


/*********************************************************************
 *
 * stubs for use until the Bedrock/L1 link is available
 *
 */

#include <asm/sn/nic.h>

/* #define EEPROM_TEST */

/* fake eeprom reading functions (replace when the BR/L1 communication
 * channel is in working order)
 */


/* generate a charater in [0-9A-Z]; if an "extra" character is
 * specified (such as '_'), include it as one of the possibilities.
 */
char random_eeprom_ch( char extra ) 
{
    char ch;
    int modval = 36;
    if( extra )
	modval++;
    
    ch = rtc_time() % modval;

    if( ch < 10 )
        ch += '0';
    else if( ch >= 10 && ch < 36 )
	ch += ('A' - 10);
    else
	ch = extra;

    return ch;
}

/* create a part number of the form xxx-xxxx-xxx.
 * It may be important later to generate different
 * part numbers depending on the component we're
 * supposed to be "reading" from, so the component
 * paramter is provided.
 */
void fake_a_part_number( char *buf, int component )
{
    int i;
    switch( component ) {

    /* insert component-specific routines here */

    case C_BRICK:
	strcpy( buf, "030-1266-001" );
	break;
    default:
        for( i = 0; i < 12; i++ ) {
	    if( i == 3 || i == 8 )
	        buf[i] = '-';
	    else
	        buf[i] = random_eeprom_ch(0);
        }
    }
}


/* create a six-character serial number */
void fake_a_serial_number( char *buf, uint64_t ser )
{
    int i;
    static const char hexchars[] = "0123456789ABCDEF";

    if (ser) {
	for( i = 5; i >=0; i-- ) {
	    buf[i] = hexchars[ser & 0xf];
	    ser >>= 4;
	}
    }
    else {
	for( i = 0; i < 6; i++ )
	    buf[i] = random_eeprom_ch(0);
    }
}


void fake_a_product_name( uchar_t *format, char* buf, int component )
{
    switch( component & BRICK_MASK ) {

    case C_BRICK:
	if( component & SUBORD_MASK ) {
	    strcpy( buf, "C_BRICK_SUB" );
	    *format = 0xCB;
	}
	else {
	    strcpy( buf, "IP35" );
	    *format = 0xC4;
	}
	break;

    case R_BRICK:
        if( component & SUBORD_MASK ) {
            strcpy( buf, "R_BRICK_SUB" );
            *format = 0xCB;
        }
        else {
            strcpy( buf, "R_BRICK" );
            *format = 0xC7;
        }
        break;

    case IO_BRICK:
        if( component & SUBORD_MASK ) {
            strcpy( buf, "IO_BRICK_SUB" );
            *format = 0xCC;
        }
        else {
            strcpy( buf, "IO_BRICK" );
            *format = 0xC8;
        }
        break;

    default:
	strcpy( buf, "UNK_DEVICE" );
	*format = 0xCA;
    }
}



int fake_an_eeprom_record( eeprom_brd_record_t *buf, int component, 
			   uint64_t ser )
{
    eeprom_board_ia_t *board;
    eeprom_chassis_ia_t *chassis;
    int i, cs;

    board = buf->board_ia;
    chassis = buf->chassis_ia;

    if( !(component & SUBORD_MASK) ) {
	if( !chassis )
	    return EEP_PARAM;
	chassis->format = 0;
	chassis->length = 5;
	chassis->type = 0x17;

	chassis->part_num_tl = 0xCC;
	fake_a_part_number( chassis->part_num, component );
	chassis->serial_num_tl = 0xC6;
	fake_a_serial_number( chassis->serial_num, ser );

	cs = chassis->format + chassis->length + chassis->type
	    + chassis->part_num_tl + chassis->serial_num_tl;
	for( i = 0; i < (chassis->part_num_tl & FIELD_LENGTH_MASK); i++ )
	    cs += chassis->part_num[i];
	for( i = 0; i < (chassis->serial_num_tl & FIELD_LENGTH_MASK); i++ )
	    cs += chassis->serial_num[i];
	chassis->checksum = 256 - (cs % 256);
    }

    if( !board )
	return EEP_PARAM;
    board->format = 0;
    board->length = 10;
    board->language = 0;
    board->mfg_date = 1789200; /* noon, 5/26/99 */
    board->manuf_tl = 0xC3;
    strcpy( board->manuf, "SGI" );

    fake_a_product_name( &(board->product_tl), board->product, component );

    board->serial_num_tl = 0xC6;
    fake_a_serial_number( board->serial_num, ser );

    board->part_num_tl = 0xCC;
    fake_a_part_number( board->part_num, component );

    board->board_rev_tl = 0xC2;
    board->board_rev[0] = '0';
    board->board_rev[1] = '1';

    board->eeprom_size_tl = 0x01;
    board->eeprom_size = 1;

    board->temp_waiver_tl = 0xC2;
    board->temp_waiver[0] = '0';
    board->temp_waiver[1] = '1';

    cs = board->format + board->length + board->language
	+ (board->mfg_date & 0xFF)
	+ (board->mfg_date & 0xFF00)
	+ (board->mfg_date & 0xFF0000)
	+ board->manuf_tl + board->product_tl + board->serial_num_tl
	+ board->part_num_tl + board->board_rev_tl
	+ board->board_rev[0] + board->board_rev[1]
	+ board->eeprom_size_tl + board->eeprom_size + board->temp_waiver_tl
	+ board->temp_waiver[0] + board->temp_waiver[1];
    for( i = 0; i < (board->manuf_tl & FIELD_LENGTH_MASK); i++ )
	cs += board->manuf[i];
    for( i = 0; i < (board->product_tl & FIELD_LENGTH_MASK); i++ )
	cs += board->product[i];
    for( i = 0; i < (board->serial_num_tl & FIELD_LENGTH_MASK); i++ )
	cs += board->serial_num[i];
    for( i = 0; i < (board->part_num_tl & FIELD_LENGTH_MASK); i++ )
	cs += board->part_num[i];
    
    board->checksum = 256 - (cs % 256);

    return EEP_OK;
}

#define EEPROM_CHUNKSIZE	64

#if defined(EEPROM_DEBUG)
#define RETURN_ERROR							\
{									\
    printk( "read_ia error return, component 0x%x, line %d"		\
	    ", address 0x%x, ia code 0x%x\n",				\
	    l1_compt, __LINE__, sc->subch[subch].target, ia_code );	\
    return EEP_L1;							\
}

#else
#define RETURN_ERROR	return(EEP_L1)
#endif

int read_ia( l1sc_t *sc, int subch, int l1_compt, 
	     int ia_code, char *eep_record )
{
#if !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
    return EEP_L1;
#else
    char msg[BRL1_QSIZE]; 	   /* message buffer */
    int len;              	   /* number of bytes used in message buffer */
    int ia_len = EEPROM_CHUNKSIZE; /* remaining bytes in info area */
    int offset = 0;                /* current offset into info area */

    if ( IS_RUNNING_ON_SIMULATOR() )
	return EEP_L1;

    BZERO( msg, BRL1_QSIZE );

    /* retrieve EEPROM data in 64-byte chunks
     */

    while( ia_len )
    {
	/* fill in msg with opcode & params */
	if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
				     L1_ADDR_TASK_GENERAL,
				     L1_REQ_EEPROM, 8,
				     L1_ARG_INT, l1_compt,
				     L1_ARG_INT, ia_code,
				     L1_ARG_INT, offset,
				     L1_ARG_INT, ia_len )) < 0 )
	{
	    RETURN_ERROR;
	}

	/* send the request to the L1 */

	if( sc_command( sc, subch, msg, msg, &len ) ) {
	    RETURN_ERROR;
	}

	/* check response */
	if( sc_interpret_resp( msg, 5, 
			       L1_ARG_INT, &ia_len,
			       L1_ARG_UNKNOWN, &len, eep_record ) < 0 )
	{
	    RETURN_ERROR;
	}

	if( ia_len > EEPROM_CHUNKSIZE )
	    ia_len = EEPROM_CHUNKSIZE;

	eep_record += EEPROM_CHUNKSIZE;
	offset += EEPROM_CHUNKSIZE;
    }

    return EEP_OK;
#endif /* CONFIG_SERIAL_SGI_L1_PROTOCOL */
}


int read_spd( l1sc_t *sc, int subch, int l1_compt,
	      eeprom_spd_u *spd )
{
#if !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
    return EEP_L1;
#else
    char msg[BRL1_QSIZE]; 	    /* message buffer */
    int len;              	    /* number of bytes used in message buffer */
    int resp;                       /* l1 response code */
    int spd_len = EEPROM_CHUNKSIZE; /* remaining bytes in spd record */
    int offset = 0;		    /* current offset into spd record */
    char *spd_p = spd->bytes;	    /* "thumb" for writing to spd */

    if ( IS_RUNNING_ON_SIMULATOR() )
	return EEP_L1;

    BZERO( msg, BRL1_QSIZE );

    /* retrieve EEPROM data in 64-byte chunks
     */

    while( spd_len )
    {
	/* fill in msg with opcode & params */
	if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
				     L1_ADDR_TASK_GENERAL,
				     L1_REQ_EEPROM, 8,
				     L1_ARG_INT, l1_compt,
				     L1_ARG_INT, L1_EEP_SPD,
				     L1_ARG_INT, offset,
				     L1_ARG_INT, spd_len )) < 0 )
	{
	    return( EEP_L1 );
	}

	/* send the request to the L1 */
	if( sc_command( sc, subch, msg, msg, &len ) ) {
	    return( EEP_L1 );
	}

	/* check response */
	if( (resp = sc_interpret_resp( msg, 5, 
			       L1_ARG_INT, &spd_len,
			       L1_ARG_UNKNOWN, &len, spd_p )) < 0 )
	{
            /*
             * translate l1 response code to eeprom.c error codes:
             * The L1 response will be L1_RESP_NAVAIL if the spd
             * can't be read (i.e. the spd isn't physically there). It will
             * return L1_RESP_INVAL if the spd exists, but fails the checksum
             * test because the eeprom wasn't programmed, programmed incorrectly,
             * or corrupted. L1_RESP_NAVAIL indicates the eeprom is likely not present,
             * whereas L1_RESP_INVAL indicates the eeprom is present, but the data is
             * invalid.
             */
            if(resp == L1_RESP_INVAL) {
                resp = EEP_BAD_CHECKSUM;
            } else {
                resp = EEP_L1;
            }
            return( resp );
	}

	if( spd_len > EEPROM_CHUNKSIZE )
	    spd_len = EEPROM_CHUNKSIZE;

	spd_p += EEPROM_CHUNKSIZE;
	offset += EEPROM_CHUNKSIZE;
    }
    return EEP_OK;
#endif /* CONFIG_SERIAL_SGI_L1_PROTOCOL */
}


int read_chassis_ia( l1sc_t *sc, int subch, int l1_compt,
		     eeprom_chassis_ia_t *ia )
{
    char eep_record[512];          /* scratch area for building up info area */
    char *eep_rec_p = eep_record;  /* thumb for moving through eep_record */
    int checksum = 0;              /* use to verify eeprom record checksum */
    int i;

    /* Read in info area record from the L1.
     */
    if( read_ia( sc, subch, l1_compt, L1_EEP_CHASSIS, eep_record )
	!= EEP_OK )
    {
	return EEP_L1;
    }

    /* Now we've got the whole info area.  Transfer it to the data structure.
     */

    eep_rec_p = eep_record;
    ia->format = *eep_rec_p++;
    ia->length = *eep_rec_p++;
    if( ia->length == 0 ) {
	/* since we're using 8*ia->length-1 as an array index later, make
	 * sure it's sane.
	 */
	db_printf(( "read_chassis_ia: eeprom length byte of ZERO\n" ));
	return EEP_L1;
    }
    ia->type = *eep_rec_p++;
   
    ia->part_num_tl = *eep_rec_p++;

    (void)BCOPY( eep_rec_p, ia->part_num, (ia->part_num_tl & FIELD_LENGTH_MASK) );
    eep_rec_p += (ia->part_num_tl & FIELD_LENGTH_MASK);

    ia->serial_num_tl = *eep_rec_p++;

    BCOPY( eep_rec_p, ia->serial_num, 
	   (ia->serial_num_tl & FIELD_LENGTH_MASK) );
    eep_rec_p += (ia->serial_num_tl & FIELD_LENGTH_MASK);

    ia->checksum = eep_record[(8 * ia->length) - 1];

    /* verify checksum */
    eep_rec_p = eep_record;
    checksum = 0;
    for( i = 0; i < (8 * ia->length); i++ ) {
	checksum += *eep_rec_p++;
    }

    if( (checksum & 0xff) != 0 )
    {
	db_printf(( "read_chassis_ia: bad checksum\n" ));
	db_printf(( "read_chassis_ia: target 0x%x  uart 0x%lx\n",
			   sc->subch[subch].target, sc->uart ));
	return EEP_BAD_CHECKSUM;
    }

    return EEP_OK;
}


int read_board_ia( l1sc_t *sc, int subch, int l1_compt,
		   eeprom_board_ia_t *ia )
{
    char eep_record[512];          /* scratch area for building up info area */
    char *eep_rec_p = eep_record;  /* thumb for moving through eep_record */
    int checksum = 0;              /* running checksum total */
    int i;

    BZERO( ia, sizeof( eeprom_board_ia_t ) );

    /* Read in info area record from the L1.
     */
    if( read_ia( sc, subch, l1_compt, L1_EEP_BOARD, eep_record )
	!= EEP_OK )
    {
	db_printf(( "read_board_ia: error reading info area from L1\n" ));
	return EEP_L1;
    }

     /* Now we've got the whole info area.  Transfer it to the data structure.
      */

    eep_rec_p = eep_record;
    ia->format = *eep_rec_p++;
    ia->length = *eep_rec_p++;
    if( ia->length == 0 ) {
	/* since we're using 8*ia->length-1 as an array index later, make
	 * sure it's sane.
	 */
	db_printf(( "read_board_ia: eeprom length byte of ZERO\n" ));
	return EEP_L1;
    }
    ia->language = *eep_rec_p++;
    
    ia->mfg_date = eeprom_xlate_board_mfr_date( (uchar_t *)eep_rec_p );
    eep_rec_p += 3;

    ia->manuf_tl = *eep_rec_p++;
    
    BCOPY( eep_rec_p, ia->manuf, (ia->manuf_tl & FIELD_LENGTH_MASK) );
    eep_rec_p += (ia->manuf_tl & FIELD_LENGTH_MASK);

    ia->product_tl = *eep_rec_p++;
    
    BCOPY( eep_rec_p, ia->product, (ia->product_tl & FIELD_LENGTH_MASK) );
    eep_rec_p += (ia->product_tl & FIELD_LENGTH_MASK);

    ia->serial_num_tl = *eep_rec_p++;
    
    BCOPY(eep_rec_p, ia->serial_num, (ia->serial_num_tl & FIELD_LENGTH_MASK));
    eep_rec_p += (ia->serial_num_tl & FIELD_LENGTH_MASK);

    ia->part_num_tl = *eep_rec_p++;

    BCOPY( eep_rec_p, ia->part_num, (ia->part_num_tl & FIELD_LENGTH_MASK) );
    eep_rec_p += (ia->part_num_tl & FIELD_LENGTH_MASK);

    eep_rec_p++; /* we do not use the FRU file id */
    
    ia->board_rev_tl = *eep_rec_p++;
    
    BCOPY( eep_rec_p, ia->board_rev, (ia->board_rev_tl & FIELD_LENGTH_MASK) );
    eep_rec_p += (ia->board_rev_tl & FIELD_LENGTH_MASK);

    ia->eeprom_size_tl = *eep_rec_p++;
    ia->eeprom_size = *eep_rec_p++;

    ia->temp_waiver_tl = *eep_rec_p++;
    
    BCOPY( eep_rec_p, ia->temp_waiver, 
	   (ia->temp_waiver_tl & FIELD_LENGTH_MASK) );
    eep_rec_p += (ia->temp_waiver_tl & FIELD_LENGTH_MASK);

    /* if there's more, we must be reading a main board; get
     * additional fields
     */
    if( ((unsigned char)*eep_rec_p != (unsigned char)EEPROM_EOF) ) {

	ia->ekey_G_tl = *eep_rec_p++;
	BCOPY( eep_rec_p, (char *)&ia->ekey_G, 
	       ia->ekey_G_tl & FIELD_LENGTH_MASK );
	eep_rec_p += (ia->ekey_G_tl & FIELD_LENGTH_MASK);
	
	ia->ekey_P_tl = *eep_rec_p++;
	BCOPY( eep_rec_p, (char *)&ia->ekey_P, 
	       ia->ekey_P_tl & FIELD_LENGTH_MASK );
	eep_rec_p += (ia->ekey_P_tl & FIELD_LENGTH_MASK);
	
	ia->ekey_Y_tl = *eep_rec_p++;
	BCOPY( eep_rec_p, (char *)&ia->ekey_Y, 
	       ia->ekey_Y_tl & FIELD_LENGTH_MASK );
	eep_rec_p += (ia->ekey_Y_tl & FIELD_LENGTH_MASK);
	
	/* 
	 * need to get a couple more fields if this is an I brick 
	 */
	if( ((unsigned char)*eep_rec_p != (unsigned char)EEPROM_EOF) ) {

	    ia->mac_addr_tl = *eep_rec_p++;
	    BCOPY( eep_rec_p, ia->mac_addr, 
		   ia->mac_addr_tl & FIELD_LENGTH_MASK );
	    eep_rec_p += (ia->mac_addr_tl & FIELD_LENGTH_MASK);
	    
	    ia->ieee1394_cfg_tl = *eep_rec_p++;
	    BCOPY( eep_rec_p, ia->ieee1394_cfg,
		   ia->ieee1394_cfg_tl & FIELD_LENGTH_MASK );
	    
	}
    }

    ia->checksum = eep_record[(ia->length * 8) - 1];

    /* verify checksum */
    eep_rec_p = eep_record;
    checksum = 0;
    for( i = 0; i < (8 * ia->length); i++ ) {
	checksum += *eep_rec_p++;
    }

    if( (checksum & 0xff) != 0 )
    {
	db_printf(( "read_board_ia: bad checksum\n" ));
	db_printf(( "read_board_ia: target 0x%x  uart 0x%lx\n",
		    sc->subch[subch].target, sc->uart ));
	return EEP_BAD_CHECKSUM;
    }

    return EEP_OK;
}


int _cbrick_eeprom_read( eeprom_brd_record_t *buf, l1sc_t *scp,
			 int component )
{
#if !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
    return EEP_L1;
#else
    int r;
    uint64_t uid = 0;
#ifdef LOG_GETENV
    char uid_str[32];
#endif
    int l1_compt, subch;

    if ( IS_RUNNING_ON_SIMULATOR() )
	return EEP_L1;

    /* make sure we're targeting a cbrick */
    if( !(component & C_BRICK) )
	return EEP_PARAM;

    /* If the promlog variable pointed to by IP27LOG_OVNIC is set,
     * use that value for the cbrick UID rather than the EEPROM
     * serial number.
     */
#ifdef LOG_GETENV
    if( ip27log_getenv( scp->nasid, IP27LOG_OVNIC, uid_str, "0", 0 ) >= 0 )
    {
	db_printf(( "_cbrick_eeprom_read: "
		    "Overriding UID with environment variable %s\n", 
		    IP27LOG_OVNIC ));
	uid = strtoull( uid_str, NULL, 0 );
    }
#endif

    if( (subch = sc_open( scp, L1_ADDR_LOCAL )) < 0 )
	return EEP_L1;

    if((component & C_DIMM) == C_DIMM) {
        l1_compt = L1_EEP_DIMM(component & COMPT_MASK);
        r = read_spd(scp,subch,l1_compt, buf->spd);
        sc_close(scp,subch);
        return(r);
    }

    switch( component )
    {
      case C_BRICK:
	/* c-brick motherboard */
	l1_compt = L1_EEP_NODE;
	r = read_chassis_ia( scp, subch, l1_compt, buf->chassis_ia );
	if( r != EEP_OK ) {
	    sc_close( scp, subch );
	    db_printf(( "_cbrick_eeprom_read: using a fake eeprom record\n" ));
	    return fake_an_eeprom_record( buf, component, uid );
	}
	if( uid ) {
	    /* If IP27LOG_OVNIC is set, we want to put that value
	     * in as our UID. */
	    fake_a_serial_number( buf->chassis_ia->serial_num, uid );
	    buf->chassis_ia->serial_num_tl = 6;
	}
	break;

      case C_PIMM:
	/* one of the PIMM boards */
	l1_compt = L1_EEP_PIMM( component & COMPT_MASK );
	break;

      default:
	/* unsupported board type */
	sc_close( scp, subch );
	return EEP_PARAM;
    }
	      
    r = read_board_ia( scp, subch, l1_compt, buf->board_ia );
    sc_close( scp, subch );
    if( r != EEP_OK ) 
    {
	db_printf(( "_cbrick_eeprom_read: using a fake eeprom record\n" ));
	return fake_an_eeprom_record( buf, component, uid );
    }
    return EEP_OK;
#endif /* CONFIG_SERIAL_SGI_L1_PROTOCOL */
}


int cbrick_eeprom_read( eeprom_brd_record_t *buf, nasid_t nasid,
    		        int component )
{
#if !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
    return EEP_L1;
#else
    l1sc_t *scp;
    int local = (nasid == get_nasid());

    if ( IS_RUNNING_ON_SIMULATOR() )
	return EEP_L1;

    /* If this brick is retrieving its own uid, use the local l1sc_t to
     * arbitrate access to the l1; otherwise, set up a new one (prom) or
     * use an existing remote l1sc_t (kernel)
     */
    if( local ) {
	scp = get_l1sc();
    }
    else {
	scp = &NODEPDA( NASID_TO_COMPACT_NODEID(nasid) )->module->elsc;
    }

    return _cbrick_eeprom_read( buf, scp, component );
#endif /* CONFIG_SERIAL_SGI_L1_PROTOCOL */
}


int iobrick_eeprom_read( eeprom_brd_record_t *buf, nasid_t nasid,
			 int component )
{
#if !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
    return EEP_L1;
#else
    int r;
    int l1_compt, subch;
    l1sc_t *scp;
    int local = (nasid == get_nasid());

    if ( IS_RUNNING_ON_SIMULATOR() )
	return EEP_L1;

    /* make sure we're talking to an applicable brick */
    if( !(component & IO_BRICK) ) {
	return EEP_PARAM;
    }

    /* If we're talking to this c-brick's attached io brick, use
     * the local l1sc_t; otherwise, set up a new one (prom) or
     * use an existing remote l1sc_t (kernel)
     */
    if( local ) {
	scp = get_l1sc();
    }
    else {
	scp = &NODEPDA( NASID_TO_COMPACT_NODEID(nasid) )->module->elsc;
    }

    if( (subch = sc_open( scp, L1_ADDR_LOCALIO )) < 0 )
	return EEP_L1;


    switch( component )
    {
      case IO_BRICK:
	/* IO brick motherboard */
	l1_compt = L1_EEP_LOGIC;
	r = read_chassis_ia( scp, subch, l1_compt, buf->chassis_ia );

	if( r != EEP_OK ) {
	    sc_close( scp, subch );
	/*
	 * Whenever we no longer need to test on hardware
	 * that does not have EEPROMS, then this can be removed.
	 */
	    r = fake_an_eeprom_record( buf, component, rtc_time() );
	    return r;
	}
	break;

      case IO_POWER:
	/* IO brick power board */
	l1_compt = L1_EEP_POWER;
	break;

      default:
	/* unsupported board type */
	sc_close( scp, subch );
	return EEP_PARAM;
    }

    r = read_board_ia( scp, subch, l1_compt, buf->board_ia );
    sc_close( scp, subch );
    if( r != EEP_OK ) {
	return r;
    }
    return EEP_OK;
#endif /* CONFIG_SERIAL_SGI_L1_PROTOCOL */    
}


int vector_eeprom_read( eeprom_brd_record_t *buf, nasid_t nasid,
			net_vec_t path, int component )
{
#if !defined(CONFIG_SERIAL_SGI_L1_PROTOCOL)
    return EEP_L1;
#else
    int r;
    uint64_t uid = 0;
    int l1_compt, subch;
    l1sc_t sc;

    if ( IS_RUNNING_ON_SIMULATOR() )
	return EEP_L1;

    /* make sure we're targeting an applicable brick */
    if( !(component & VECTOR) )
	return EEP_PARAM;

    switch( component & BRICK_MASK )
    {
      case R_BRICK:
	ROUTER_LOCK( path );
	sc_init( &sc, nasid, path );

	if( (subch = sc_open( &sc, L1_ADDR_LOCAL )) < 0 )
	{
	    db_printf(( "vector_eeprom_read: couldn't open subch\n" ));
	    ROUTER_UNLOCK(path);
	    return EEP_L1;
	}
	switch( component )
	{
	  case R_BRICK:
	    /* r-brick motherboard */
	    l1_compt = L1_EEP_LOGIC;
    	    r = read_chassis_ia( &sc, subch, l1_compt, buf->chassis_ia );
	    if( r != EEP_OK ) {
		sc_close( &sc, subch );
		ROUTER_UNLOCK( path );
		printk( "vector_eeprom_read: couldn't get rbrick eeprom info;"
			" using current time as uid\n" );
		uid = rtc_time();
		db_printf(("vector_eeprom_read: using a fake eeprom record\n"));
		return fake_an_eeprom_record( buf, component, uid );
	    }
	    break;

	  case R_POWER:
	    /* r-brick power board */
	    l1_compt = L1_EEP_POWER;
	    break;

	  default:
	    /* unsupported board type */
	    sc_close( &sc, subch );
	    ROUTER_UNLOCK( path );
	    return EEP_PARAM;
	}
	r = read_board_ia( &sc, subch, l1_compt, buf->board_ia );
	sc_close( &sc, subch );
	ROUTER_UNLOCK( path );
	if( r != EEP_OK ) {
	    db_printf(( "vector_eeprom_read: using a fake eeprom record\n" ));
	    return fake_an_eeprom_record( buf, component, uid );
	}
	return EEP_OK;

      case C_BRICK:
	sc_init( &sc, nasid, path );
	return _cbrick_eeprom_read( buf, &sc, component );

      default:
	/* unsupported brick type */
	return EEP_PARAM;
    }
#endif /* CONFIG_SERIAL_SGI_L1_PROTOCOL */
}