aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ia64/sn/io/l1_command.c
blob: 3da21f1d7da233fddb797d58bff6e91a0ce9593b (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
/* $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 - 2001 Silicon Graphics, Inc.
 * All rights reserved.
 */ 

#include <linux/types.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>

#define ELSC_TIMEOUT	1000000		/* ELSC response timeout (usec) */
#define LOCK_TIMEOUT	5000000		/* Hub lock timeout (usec) */

#define LD(x)		(*(volatile uint64_t *)(x))
#define SD(x, v)	(LD(x) = (uint64_t) (v))

#define hub_cpu_get()	0

#define LBYTE(caddr)	(*(char *) caddr)

extern char *bcopy(const char * src, char * dest, int count);

#define LDEBUG		0

/*
 * ELSC data is in NVRAM page 7 at the following offsets.
 */

#define NVRAM_MAGIC_AD	0x700		/* magic number used for init */
#define NVRAM_PASS_WD	0x701		/* password (4 bytes in length) */
#define NVRAM_DBG1	0x705		/* virtual XOR debug switches */
#define NVRAM_DBG2	0x706		/* physical XOR debug switches */
#define NVRAM_CFG	0x707		/* ELSC Configuration info */
#define NVRAM_MODULE	0x708		/* system module number */
#define NVRAM_BIST_FLG	0x709		/* BIST flags (2 bits per nodeboard) */
#define NVRAM_PARTITION 0x70a		/* module's partition id */
#define	NVRAM_DOMAIN	0x70b		/* module's domain id */
#define	NVRAM_CLUSTER	0x70c		/* module's cluster id */
#define	NVRAM_CELL	0x70d		/* module's cellid */

#define NVRAM_MAGIC_NO	0x37		/* value of magic number */
#define NVRAM_SIZE	16		/* 16 bytes in nvram */

/*
 * Declare a static ELSC NVRAM buffer to hold all data read from
 * and written to NVRAM.  This nvram "cache" will be used only during the
 * IP27prom execution.
 */
static char elsc_nvram_buffer[NVRAM_SIZE];

#define SC_COMMAND sc_command

/*
 * elsc_init
 *
 *   Initialize ELSC structure
 */

void elsc_init(elsc_t *e, nasid_t nasid)
{
    sc_init((l1sc_t *)e, nasid, BRL1_LOCALHUB_UART);
}


/*
 * elsc_errmsg
 *
 *   Given a negative error code,
 *   returns a corresponding static error string.
 */

char *elsc_errmsg(int code)
{
    switch (code) {
    case ELSC_ERROR_CMD_SEND:
	return "Command send error";
    case ELSC_ERROR_CMD_CHECKSUM:
	return "Command packet checksum error";
    case ELSC_ERROR_CMD_UNKNOWN:
	return "Unknown command";
    case ELSC_ERROR_CMD_ARGS:
	return "Invalid command argument(s)";
    case ELSC_ERROR_CMD_PERM:
	return "Permission denied";
    case ELSC_ERROR_RESP_TIMEOUT:
	return "System controller response timeout";
    case ELSC_ERROR_RESP_CHECKSUM:
	return "Response packet checksum error";
    case ELSC_ERROR_RESP_FORMAT:
	return "Response format error";
    case ELSC_ERROR_RESP_DIR:
	return "Response direction error";
    case ELSC_ERROR_MSG_LOST:
	return "Message lost because queue is full";
    case ELSC_ERROR_LOCK_TIMEOUT:
	return "Timed out getting ELSC lock";
    case ELSC_ERROR_DATA_SEND:
	return "Error sending data";
    case ELSC_ERROR_NIC:
	return "NIC protocol error";
    case ELSC_ERROR_NVMAGIC:
	return "Bad magic number in NVRAM";
    case ELSC_ERROR_MODULE:
	return "Module location protocol error";
    default:
	return "Unknown error";
    }
}

/*
 * elsc_nvram_init
 *
 *   Initializes reads and writes to NVRAM.  This will perform a single
 *   read to NVRAM, getting all data at once.  When the PROM tries to
 *   read NVRAM, it returns the data from the buffer being read.  If the
 *   PROM tries to write out to NVRAM, the write is done, and the internal
 *   buffer is updated.
 */

void elsc_nvram_init(nasid_t nasid, uchar_t *elsc_nvram_data)
{
    /* This might require implementation of multiple-packet request/responses
     * if it's to provide the same behavior that was available in SN0.
     */
    nasid = nasid;
    elsc_nvram_data = elsc_nvram_data;
}

/*
 * elsc_nvram_copy
 *
 *   Copies the content of a buffer into the static buffer in this library.
 */

void elsc_nvram_copy(uchar_t *elsc_nvram_data)
{
    memcpy(elsc_nvram_buffer, elsc_nvram_data, NVRAM_SIZE);
}

/*
 * elsc_nvram_write
 *
 *   Copies bytes from 'buf' into NVRAM, starting at NVRAM address
 *   'addr' which must be between 0 and 2047.
 *
 *   If 'len' is non-negative, the routine copies 'len' bytes.
 *
 *   If 'len' is negative, the routine treats the data as a string and
 *   copies bytes up to and including a NUL-terminating zero, but not
 *   to exceed '-len' bytes.
 */

int elsc_nvram_write(elsc_t *e, int addr, char *buf, int len)
{
    /* Here again, we might need to work out the details of a
     * multiple-packet protocol.
     */

    /* For now, pretend it worked. */
    e = e;
    addr = addr;
    buf = buf;
    return (len < 0 ? -len : len);
}

/*
 * elsc_nvram_read
 *
 *   Copies bytes from NVRAM into 'buf', starting at NVRAM address
 *   'addr' which must be between 0 and 2047.
 *
 *   If 'len' is non-negative, the routine copies 'len' bytes.
 *
 *   If 'len' is negative, the routine treats the data as a string and
 *   copies bytes up to and including a NUL-terminating zero, but not
 *   to exceed '-len' bytes.  NOTE:  This method is no longer supported.
 *   It was never used in the first place.
 */

int elsc_nvram_read(elsc_t *e, int addr, char *buf, int len)
{
    /* multiple packets? */
    e = e;
    addr = addr;
    buf = buf;
    len = len;
    return -1;
}


/*
 * Command Set
 */

int elsc_version(elsc_t *e, char *result)
{
    char	msg[BRL1_QSIZE];
    int		len;    /* length of message being sent */
    int		subch;  /* system controller subchannel used */
    int		major,  /* major rev number */
	        minor,  /* minor rev number */
                bugfix; /* bugfix rev number */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    subch = sc_open( (l1sc_t *)e, L1_ADDR_LOCAL );

    if( (len = sc_construct_msg( (l1sc_t *)e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_FW_REV, 0 )) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

    /* send the request to the L1 */
    if( SC_COMMAND( (l1sc_t *)e, subch, msg, msg, &len ) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_SEND );
    }

    /* free up subchannel */
    sc_close( (l1sc_t *)e, subch );

    /* check response */
    if( sc_interpret_resp( msg, 6, L1_ARG_INT, &major,
			   L1_ARG_INT, &minor, L1_ARG_INT, &bugfix )
	< 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    sprintf( result, "%d.%d.%d", major, minor, bugfix );

    return 0;
}

int elsc_debug_set(elsc_t *e, u_char byte1, u_char byte2)
{
    /* shush compiler */
    e = e;
    byte1 = byte1;
    byte2 = byte2;

    /* fill in a buffer with the opcode & params; call sc_command */

    return 0;
}

int elsc_debug_get(elsc_t *e, u_char *byte1, u_char *byte2)
{
    char	msg[BRL1_QSIZE];
    int		subch;  /* system controller subchannel used */
    int		dbg_sw; /* holds debug switch settings */
    int		len;	/* number of msg buffer bytes used */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    if( (subch = sc_open( (l1sc_t *)e, L1_ADDR_LOCAL )) < 0 ) {
	return( ELSC_ERROR_CMD_SEND );
    }

    if( (len = sc_construct_msg( (l1sc_t *)e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_RDBG, 0 ) ) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

    /* send the request to the L1 */
    if( sc_command( (l1sc_t *)e, subch, msg, msg, &len ) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_SEND );
    }

    /* free up subchannel */
    sc_close( (l1sc_t *)e, subch );

    /* check response */
    if( sc_interpret_resp( msg, 2, L1_ARG_INT, &dbg_sw ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    /* copy out debug switch settings (last two bytes of the
     * integer response)
     */
    *byte1 = ((dbg_sw >> 8) & 0xFF);
    *byte2 = (dbg_sw & 0xFF);

    return 0;
}


/*
 * elsc_rack_bay_get fills in the two int * arguments with the
 * rack number and bay number of the L1 being addressed
 */
int elsc_rack_bay_get(elsc_t *e, uint *rack, uint *bay)
{
    char msg[BRL1_QSIZE];	/* L1 request/response info */
    int subch;			/* system controller subchannel used */
    int len;			/* length of message */
    uint32_t	buf32;		/* used to copy 32-bit rack/bay out of msg */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    if( (subch = sc_open( (l1sc_t *)e, L1_ADDR_LOCAL )) < 0 ) {
	return( ELSC_ERROR_CMD_SEND );
    }

    if( (len = sc_construct_msg( (l1sc_t *)e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_RRACK, 0 )) < 0 ) 
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }


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

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

    /* check response */
    if( sc_interpret_resp( msg, 2, L1_ARG_INT, &buf32 ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    /* extract rack/bay info
     *
     * note that the 32-bit value returned by the L1 actually
     * only uses the low-order sixteen bits for rack and bay
     * information.  A "normal" L1 address puts rack and bay
     * information in bit positions 12 through 28.  So if
     * we initially shift the value returned 12 bits to the left,
     * we can use the L1 addressing #define's to extract the
     * values we need (see ksys/l1.h for a complete list of the
     * various fields of an L1 address).
     */
    buf32 <<= L1_ADDR_BAY_SHFT;

    *rack = (buf32 & L1_ADDR_RACK_MASK) >> L1_ADDR_RACK_SHFT;
    *bay = (buf32 & L1_ADDR_BAY_MASK) >> L1_ADDR_BAY_SHFT;

    return 0;
}


/* elsc_rack_bay_type_get fills in the three int * arguments with the
 * rack number, bay number and brick type of the L1 being addressed.  Note
 * that if the L1 operation fails and this function returns an error value, 
 * garbage may be written to brick_type.
 */
int elsc_rack_bay_type_get( l1sc_t *sc, uint *rack, 
			       uint *bay, uint *brick_type )
{
    char msg[BRL1_QSIZE];       /* L1 request/response info */
    int subch;                  /* system controller subchannel used */
    int len;                    /* length of message */
    uint32_t buf32;	        /* used to copy 32-bit rack & bay out of msg */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    if( (subch = sc_open( sc, L1_ADDR_LOCAL )) < 0 ) {
	return ELSC_ERROR_CMD_SEND;
    }

    if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_RRBT, 0 )) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

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

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

    /* check response */
    if( sc_interpret_resp( msg, 4, L1_ARG_INT, &buf32, 
			           L1_ARG_INT, brick_type ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    /* extract rack/bay info
     *
     * note that the 32-bit value returned by the L1 actually
     * only uses the low-order sixteen bits for rack and bay
     * information.  A "normal" L1 address puts rack and bay
     * information in bit positions 12 through 28.  So if
     * we initially shift the value returned 12 bits to the left,
     * we can use the L1 addressing #define's to extract the
     * values we need (see ksys/l1.h for a complete list of the
     * various fields of an L1 address).
     */
    buf32 <<= L1_ADDR_BAY_SHFT;

    *rack = (buf32 & L1_ADDR_RACK_MASK) >> L1_ADDR_RACK_SHFT;
    *bay = (buf32 & L1_ADDR_BAY_MASK) >> L1_ADDR_BAY_SHFT;

    /* convert brick_type to lower case */
    *brick_type = *brick_type - 'A' + 'a';

    return 0;
}


int elsc_module_get(elsc_t *e)
{
    extern char brick_types[];
    uint rnum, rack, bay, bricktype, t;
    int ret;

    /* construct module ID from rack and slot info */

    if ((ret = elsc_rack_bay_type_get(e, &rnum, &bay, &bricktype)) < 0) {
	return ret;
    }

    /* report unset location info. with a special, otherwise invalid modid */
    if (rnum == 0 && bay == 0)
	return MODULE_NOT_SET;

    if (bay > MODULE_BPOS_MASK >> MODULE_BPOS_SHFT)
	return ELSC_ERROR_MODULE;

    /* Build a moduleid_t-compatible rack number */

    rack = 0;		
    t = rnum / 100;		/* rack class (CPU/IO) */
    if (t > RACK_CLASS_MASK(rack) >> RACK_CLASS_SHFT(rack))
	return ELSC_ERROR_MODULE;
    RACK_ADD_CLASS(rack, t);
    rnum %= 100;

    t = rnum / 10;		/* rack group */
    if (t > RACK_GROUP_MASK(rack) >> RACK_GROUP_SHFT(rack))
	return ELSC_ERROR_MODULE;
    RACK_ADD_GROUP(rack, t);

    t = rnum % 10;		/* rack number (one-based) */
    if (t-1 > RACK_NUM_MASK(rack) >> RACK_NUM_SHFT(rack))
	return ELSC_ERROR_MODULE;
    RACK_ADD_NUM(rack, t);

    for( t = 0; t < MAX_BRICK_TYPES; t++ ) {
	if( brick_types[t] == bricktype )
	    return RBT_TO_MODULE(rack, bay, t);
    }
    
    return ELSC_ERROR_MODULE;
}

int elsc_partition_set(elsc_t *e, int partition)
{
    char msg[BRL1_QSIZE];       /* L1 request/response info */
    int subch;                  /* system controller subchannel used */
    int len;                    /* length of message */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    if( (subch = sc_open( e, L1_ADDR_LOCAL )) < 0 ) {
	return ELSC_ERROR_CMD_SEND;
    }

    if( (len = sc_construct_msg( e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_PARTITION_SET, 2,
				 L1_ARG_INT, partition )) < 0 )
    {
	
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

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

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

    /* check response */
    if( sc_interpret_resp( msg, 0 ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }
    
    return( 0 );
}

int elsc_partition_get(elsc_t *e)
{
    char msg[BRL1_QSIZE];       /* L1 request/response info */
    int subch;                  /* system controller subchannel used */
    int len;                    /* length of message */
    uint32_t partition_id;    /* used to copy partition id out of msg */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    if( (subch = sc_open( e, L1_ADDR_LOCAL )) < 0 ) {
	return ELSC_ERROR_CMD_SEND;
    }

    if( (len = sc_construct_msg( e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_PARTITION_GET, 0 )) < 0 )

    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

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

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

    /* check response */
    if( sc_interpret_resp( msg, 2, L1_ARG_INT, &partition_id ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }
    
    return( partition_id );
}


/*
 * elsc_cons_subch selects the "active" console subchannel for this node
 * (i.e., the one that will currently receive input)
 */
int elsc_cons_subch(elsc_t *e, uint ch)
{
    char msg[BRL1_QSIZE];       /* L1 request/response info */
    int subch;                  /* system controller subchannel used */
    int len;                    /* length of message */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    subch = sc_open( e, L1_ADDR_LOCAL );
    
    if( (len = sc_construct_msg( e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_CONS_SUBCH, 2,
				 L1_ARG_INT, ch)) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

    /* send the request to the L1 */
    if( SC_COMMAND( e, subch, msg, msg, &len ) ) {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_SEND );
    }

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

    /* check response */
    if( sc_interpret_resp( msg, 0 ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    return 0;
}


/*
 * elsc_cons_node should only be executed by one node.  It declares to
 * the system controller that the node from which it is called will be
 * the owner of the system console.
 */
int elsc_cons_node(elsc_t *e)
{
    char msg[BRL1_QSIZE];       /* L1 request/response info */
    int subch;                  /* system controller subchannel used */
    int len;                    /* length of message */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    subch = sc_open( e, L1_ADDR_LOCAL );
    
    if( (len = sc_construct_msg( e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_CONS_NODE, 0 )) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

    /* send the request to the L1 */
    if( SC_COMMAND( e, subch, msg, msg, &len ) ) {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_SEND );
    }

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

    /* check response */
    if( sc_interpret_resp( msg, 0 ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    return 0;
}
    

/* elsc_display_line writes up to 12 characters to either the top or bottom
 * line of the L1 display.  line points to a buffer containing the message
 * to be displayed.  The zero-based line number is specified by lnum (so
 * lnum == 0 specifies the top line and lnum == 1 specifies the bottom).
 * Lines longer than 12 characters, or line numbers not less than
 * L1_DISPLAY_LINES, cause elsc_display_line to return an error.
 */
int elsc_display_line(elsc_t *e, char *line, int lnum)
{
    char	msg[BRL1_QSIZE];
    int		subch;  /* system controller subchannel used */
    int		len;	/* number of msg buffer bytes used */

    /* argument sanity checking */
    if( !(lnum < L1_DISPLAY_LINES) )
	return( ELSC_ERROR_CMD_ARGS );
    if( !(strlen( line ) <= L1_DISPLAY_LINE_LENGTH) )
	return( ELSC_ERROR_CMD_ARGS );

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    subch = sc_open( (l1sc_t *)e, L1_ADDR_LOCAL );

    if( (len = sc_construct_msg( (l1sc_t *)e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 (L1_REQ_DISP1+lnum), 2,
				 L1_ARG_ASCII, line )) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

    /* send the request to the L1 */
    if( SC_COMMAND( (l1sc_t *)e, subch, msg, msg, &len ) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_SEND );
    }

    /* free up subchannel */
    sc_close( (l1sc_t *)e, subch );

    /* check response */
    if( sc_interpret_resp( msg, 0 ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    return 0;
}


/* elsc_display_mesg silently drops message characters beyond the 12th.
 */
int elsc_display_mesg(elsc_t *e, char *chr)
{

    char line[L1_DISPLAY_LINE_LENGTH+1];
    int numlines, i;
    int result;

    numlines = (strlen( chr ) + L1_DISPLAY_LINE_LENGTH - 1) /
	L1_DISPLAY_LINE_LENGTH;

    if( numlines > L1_DISPLAY_LINES )
	numlines = L1_DISPLAY_LINES;

    for( i = 0; i < numlines; i++ )
    {
	strncpy( line, chr, L1_DISPLAY_LINE_LENGTH );
	line[L1_DISPLAY_LINE_LENGTH] = '\0';

	/* generally we want to leave the first line of the L1 display
	 * alone (so the L1 can manipulate it).  If you need to be able
	 * to display to both lines (for debugging purposes), define
	 * L1_DISP_2LINES in irix/kern/ksys/l1.h, or add -DL1_DISP_2LINES
	 * to your 'defs file.
	 */
#if defined(L1_DISP_2LINES)
	if( (result = elsc_display_line( e, line, i )) < 0 )
#else
	if( (result = elsc_display_line( e, line, i+1 )) < 0 )
#endif

	    return result;

	chr += L1_DISPLAY_LINE_LENGTH;
    }
    
    return 0;
}


int elsc_password_set(elsc_t *e, char *password)
{
    /* shush compiler */
    e = e;
    password = password;

    /* fill in buffer with the opcode & params; call elsc_command */

    return 0;
}

int elsc_password_get(elsc_t *e, char *password)
{
    /* shush compiler */
    e = e;
    password = password;

    /* fill in buffer with the opcode & params; call elsc_command */

    return 0;
}


/*
 * sc_portspeed_get
 *
 * retrieve the current portspeed setting for the bedrock II
 */
int sc_portspeed_get(l1sc_t *sc)
{
    char	msg[BRL1_QSIZE];
    int         len;    /* length of message being sent */
    int         subch;  /* system controller subchannel used */
    int		portspeed_a, portspeed_b;
			/* ioport clock rates */

    bzero( msg, BRL1_QSIZE );
    subch = sc_open( sc, L1_ADDR_LOCAL );

    if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
                                 L1_ADDR_TASK_GENERAL,
				 L1_REQ_PORTSPEED,
				 0 )) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }
    
    /* send the request to the L1 */
    if( sc_command( sc, subch, msg, msg, &len ) < 0 )
    {
        sc_close( sc, subch );
        return( ELSC_ERROR_CMD_SEND );
    }

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

    /* check response */
    if( sc_interpret_resp( msg, 4, 
			   L1_ARG_INT, &portspeed_a,
			   L1_ARG_INT, &portspeed_b ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    /* for the c-brick, we ignore the portspeed_b value */
    return (portspeed_a ? 600 : 400);
}

/*
 * elsc_power_query
 *
 *   To be used after system reset, this command returns 1 if the reset
 *   was the result of a power-on, 0 otherwise.
 *
 *   The power query status is cleared to 0 after it is read.
 */

int elsc_power_query(elsc_t *e)
{
    e = e; /* shush the compiler */

    /* fill in buffer with the opcode & params; call elsc_command */

    return 1;
}

int elsc_rpwr_query(elsc_t *e, int is_master)
{
    /* shush the compiler */
    e = e;
    is_master = is_master;

    /* fill in buffer with the opcode & params; call elsc_command */

    return 0;
} 

/*
 * elsc_power_down
 *
 *   Sets up system to shut down in "sec" seconds (or modifies the
 *   shutdown time if one is already in effect).  Use 0 to power
 *   down immediately.
 */

int elsc_power_down(elsc_t *e, int sec)
{
    /* shush compiler */
    e = e;
    sec = sec;

    /* fill in buffer with the opcode & params; call elsc_command */

    return 0;
}


int elsc_system_reset(elsc_t *e)
{
    char	msg[BRL1_QSIZE];
    int		subch;  /* system controller subchannel used */
    int		len;	/* number of msg buffer bytes used */
    int		result;

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    if( (subch = sc_open( e, L1_ADDR_LOCAL )) < 0 ) {
	return ELSC_ERROR_CMD_SEND;
    }

    if( (len = sc_construct_msg( e, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_RESET, 0 )) < 0 )
    {
	sc_close( e, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

    /* send the request to the L1 */
    if( (result = sc_command( e, subch, msg, msg, &len )) ) {
	sc_close( e, subch );
	if( result == SC_NMSG ) {
	    /* timeout is OK.  We've sent the reset.  Now it's just
	     * a matter of time...
	     */
	    return( 0 );
	}
	return( ELSC_ERROR_CMD_SEND );
    }

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

    /* check response */
    if( sc_interpret_resp( msg, 0 ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    return 0;
}


int elsc_power_cycle(elsc_t *e)
{
    /* shush compiler */
    e = e;

    /* fill in buffer with the opcode & params; call sc_command */

    return 0;
}


/*
 * L1 Support for reading 
 * cbrick uid.
 */

int elsc_nic_get(elsc_t *e, uint64_t *nic, int verbose)
{
    /* this parameter included only for SN0 compatibility */
    verbose = verbose;

    /* We don't go straight to the bedrock/L1 protocol on this one, but let
     * the eeprom layer prepare the eeprom data as we would like it to
     * appear to the caller
     */
    return cbrick_uid_get( e->nasid, nic );
}


int _elsc_hbt(elsc_t *e, int ival, int rdly)
{
    e = e;
    ival = ival;
    rdly = rdly;

    /* fill in buffer with the opcode & params; call elsc_command */

    return 0;
}


/* send a command string to an L1 */
int sc_command_interp( l1sc_t *sc, l1addr_t compt, l1addr_t rack, l1addr_t bay,
		       char *cmd )
{
    char        msg[BRL1_QSIZE];
    int         len;    /* length of message being sent */
    int         subch;  /* system controller subchannel used */
    l1addr_t	target; /* target system controller for command */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );

    L1_BUILD_ADDR( &target, compt, rack, bay, 0 );
    subch = sc_open( sc, target );

    if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_CMD, L1_REQ_EXEC_CMD, 2,
				 L1_ARG_ASCII, cmd )) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }
		   
    /* send the request to the L1 */
    if( SC_COMMAND( sc, subch, msg, msg, &len ) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_SEND );
    }

    /* free up subchannel */
    sc_close( sc, subch );
    
    /* check response */
    if( sc_interpret_resp( msg, 0 ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    return 0;
}

/*
 * sc_power_down
 *
 * Shuts down the c-brick associated with sc, and any attached I/O bricks
 * or other c-bricks (won't go through r-bricks).
 */

int sc_power_down(l1sc_t *sc)
{
    return sc_command_interp( sc, L1_ADDR_TYPE_L1, L1_ADDR_RACK_LOCAL, 
			      L1_ADDR_BAY_LOCAL, "* pwr d" );
}


/*
 * sc_power_down_all
 *
 * Works similarly to sc_power_down, except that the request is sent to the
 * closest L2 and EVERYBODY gets turned off.
 */

int sc_power_down_all(l1sc_t *sc)
{
    if( nodepda->num_routers > 0 ) {
	return sc_command_interp( sc, L1_ADDR_TYPE_L2, L1_ADDR_RACK_LOCAL, 
				  L1_ADDR_BAY_LOCAL, "* pwr d" );
    }
    else {
	return sc_power_down( sc );
    }
}


/*
 * Routines for reading the R-brick's L1
 */

int router_module_get( nasid_t nasid, net_vec_t path )
{
    uint rnum, rack, bay, t;
    int ret;
    l1sc_t sc;

    /* prepare l1sc_t struct */
    sc_init( &sc, nasid, path );

    /* construct module ID from rack and slot info */

    if ((ret = elsc_rack_bay_get(&sc, &rnum, &bay)) < 0)
	return ret;

    /* report unset location info. with a special, otherwise invalid modid */
    if (rnum == 0 && bay == 0)
	return MODULE_NOT_SET;

    if (bay > MODULE_BPOS_MASK >> MODULE_BPOS_SHFT)
	return ELSC_ERROR_MODULE;

    /* Build a moduleid_t-compatible rack number */

    rack = 0;		
    t = rnum / 100;		/* rack class (CPU/IO) */
    if (t > RACK_CLASS_MASK(rack) >> RACK_CLASS_SHFT(rack))
	return ELSC_ERROR_MODULE;
    RACK_ADD_CLASS(rack, t);
    rnum %= 100;

    t = rnum / 10;		/* rack group */
    if (t > RACK_GROUP_MASK(rack) >> RACK_GROUP_SHFT(rack))
	return ELSC_ERROR_MODULE;
    RACK_ADD_GROUP(rack, t);

    t = rnum % 10;		/* rack number (one-based) */
    if (t-1 > RACK_NUM_MASK(rack) >> RACK_NUM_SHFT(rack))
	return ELSC_ERROR_MODULE;
    RACK_ADD_NUM(rack, t);

    ret = RBT_TO_MODULE(rack, bay, MODULE_RBRICK);
    return ret;
}
    

/*
 * iobrick routines
 */

/* iobrick_rack_bay_type_get fills in the three int * arguments with the
 * rack number, bay number and brick type of the L1 being addressed.  Note
 * that if the L1 operation fails and this function returns an error value, 
 * garbage may be written to brick_type.
 */
int iobrick_rack_bay_type_get( l1sc_t *sc, uint *rack, 
			       uint *bay, uint *brick_type )
{
    char msg[BRL1_QSIZE];       /* L1 request/response info */
    int subch;                  /* system controller subchannel used */
    int len;                    /* length of message */
    uint32_t buf32;	        /* used to copy 32-bit rack & bay out of msg */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    if( (subch = sc_open( sc, L1_ADDR_LOCALIO )) < 0 ) {
	return( ELSC_ERROR_CMD_SEND );
    }

    if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_RRBT, 0 )) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

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

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

    /* check response */
    if( sc_interpret_resp( msg, 4, L1_ARG_INT, &buf32, 
			           L1_ARG_INT, brick_type ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    /* extract rack/bay info
     *
     * note that the 32-bit value returned by the L1 actually
     * only uses the low-order sixteen bits for rack and bay
     * information.  A "normal" L1 address puts rack and bay
     * information in bit positions 12 through 28.  So if
     * we initially shift the value returned 12 bits to the left,
     * we can use the L1 addressing #define's to extract the
     * values we need (see ksys/l1.h for a complete list of the
     * various fields of an L1 address).
     */
    buf32 <<= L1_ADDR_BAY_SHFT;

    *rack = (buf32 & L1_ADDR_RACK_MASK) >> L1_ADDR_RACK_SHFT;
    *bay = (buf32 & L1_ADDR_BAY_MASK) >> L1_ADDR_BAY_SHFT;

    return 0;
}


int iobrick_module_get(l1sc_t *sc)
{
    uint rnum, rack, bay, brick_type, t;
    int ret;

    /* construct module ID from rack and slot info */

    if ((ret = iobrick_rack_bay_type_get(sc, &rnum, &bay, &brick_type)) < 0)
        return ret;

    if (bay > MODULE_BPOS_MASK >> MODULE_BPOS_SHFT)
        return ELSC_ERROR_MODULE;

    /* Build a moduleid_t-compatible rack number */

    rack = 0;           
    t = rnum / 100;             /* rack class (CPU/IO) */
    if (t > RACK_CLASS_MASK(rack) >> RACK_CLASS_SHFT(rack))
        return ELSC_ERROR_MODULE;
    RACK_ADD_CLASS(rack, t);
    rnum %= 100;

    t = rnum / 10;              /* rack group */
    if (t > RACK_GROUP_MASK(rack) >> RACK_GROUP_SHFT(rack))
        return ELSC_ERROR_MODULE;
    RACK_ADD_GROUP(rack, t);

    t = rnum % 10;              /* rack number (one-based) */
    if (t-1 > RACK_NUM_MASK(rack) >> RACK_NUM_SHFT(rack))
        return ELSC_ERROR_MODULE;
    RACK_ADD_NUM(rack, t);

    switch( brick_type ) {
      case 'I': 
	brick_type = MODULE_IBRICK; break;
      case 'P':
	brick_type = MODULE_PBRICK; break;
      case 'X':
	brick_type = MODULE_XBRICK; break;
    }

    ret = RBT_TO_MODULE(rack, bay, brick_type);

    return ret;
}

/* iobrick_get_sys_snum asks the attached iobrick for the system
 * serial number.  This function will only be relevant to the master
 * cbrick (the one attached to the bootmaster ibrick); other nodes
 * may call the function, but the value returned to the master node
 * will be the one used as the system serial number by the kernel.
 */

int
iobrick_get_sys_snum( l1sc_t *sc, char *snum_str )
{
    char msg[BRL1_QSIZE];       /* L1 request/response info */
    int subch;                  /* system controller subchannel used */
    int len;                    /* length of message */
    
    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    if( (subch = sc_open( sc, L1_ADDR_LOCALIO )) < 0 ) {
	return( ELSC_ERROR_CMD_SEND );
    }

    if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_SYS_SERIAL, 0 )) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

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

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

    /* check response */
    return( sc_interpret_resp( msg, 2, L1_ARG_ASCII, snum_str ) );
}


/*
 * The following functions apply (or cut off) power to the specified
 * pci bus or slot.
 */

int
iobrick_pci_pwr( l1sc_t *sc, int bus, int slot, int req_code )
{
#if 0 /* The "bedrock request" method of performing this function
       * seems to be broken in the L1, so for now use the command-
       * interpreter method
       */

    char	msg[BRL1_QSIZE];
    int		len;    /* length of message being sent */
    int		subch;  /* system controller subchannel used */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    subch = sc_open( sc, L1_ADDR_LOCALIO );

    if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 req_code, 4,
				 L1_ARG_INT, bus,
				 L1_ARG_INT, slot )) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

    /* send the request to the L1 */
    if( SC_COMMAND(sc, subch, msg, msg, &len ) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_SEND );
    }

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

    /* check response */
    if( sc_interpret_resp( msg, 0 ) < 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    return 0;

#else
    char cmd[64];
    char *fxn;

    switch( req_code )
    {
    case L1_REQ_PCI_UP:
	fxn = "u";
	break;
    case L1_REQ_PCI_DOWN:
	fxn = "d";
	break;
    case L1_REQ_PCI_RESET:
	fxn = "rst";
	break;
    default:
	return( ELSC_ERROR_CMD_ARGS );
    }

    if( slot == -1 ) 
	sprintf( cmd, "pci %d %s", bus, fxn );
    else
        sprintf( cmd, "pci %d %d %s", bus, slot, fxn );
	
    return sc_command_interp( sc, L1_ADDR_TYPE_IOBRICK,
	L1_ADDR_RACK_LOCAL, L1_ADDR_BAY_LOCAL, cmd );
#endif
}
				 
int
iobrick_pci_slot_pwr( l1sc_t *sc, int bus, int slot, int up )
{
    return iobrick_pci_pwr( sc, bus, slot, up );
}

int
iobrick_pci_bus_pwr( l1sc_t *sc, int bus, int up )
{
    return iobrick_pci_pwr( sc, bus, -1, up );
}


int
iobrick_pci_slot_rst( l1sc_t *sc, int bus, int slot )
{
    return iobrick_pci_pwr( sc, bus, slot, L1_REQ_PCI_RESET );
}

int
iobrick_pci_bus_rst( l1sc_t *sc, int bus )
{
    return iobrick_pci_pwr( sc, bus, -1, L1_REQ_PCI_RESET );
}


/* get the L1 firmware version for an iobrick */
int
iobrick_sc_version( l1sc_t *sc, char *result )
{
    char	msg[BRL1_QSIZE];
    int		len;    /* length of message being sent */
    int		subch;  /* system controller subchannel used */
    int		major,  /* major rev number */
	        minor,  /* minor rev number */
                bugfix; /* bugfix rev number */

    /* fill in msg with the opcode & params */
    bzero( msg, BRL1_QSIZE );
    subch = sc_open( sc, L1_ADDR_LOCALIO );

    if( (len = sc_construct_msg( sc, subch, msg, BRL1_QSIZE,
				 L1_ADDR_TASK_GENERAL,
				 L1_REQ_FW_REV, 0 )) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_ARGS );
    }

    /* send the request to the L1 */
    if( SC_COMMAND(sc, subch, msg, msg, &len ) < 0 )
    {
	sc_close( sc, subch );
	return( ELSC_ERROR_CMD_SEND );
    }

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

    /* check response */
    if( sc_interpret_resp( msg, 6, L1_ARG_INT, &major,
			   L1_ARG_INT, &minor, L1_ARG_INT, &bugfix )
	< 0 )
    {
	return( ELSC_ERROR_RESP_FORMAT );
    }

    sprintf( result, "%d.%d.%d", major, minor, bugfix );

    return 0;
}