1 /* $Id$
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (c) 1992-1997,2000-2003 Silicon Graphics, Inc. All rights reserved.
8  */
9 
10 #include <linux/types.h>
11 #include <linux/slab.h>
12 #include <asm/sn/sgi.h>
13 #include <asm/sn/io.h>
14 #include <asm/sn/iograph.h>
15 #include <asm/sn/invent.h>
16 #include <asm/sn/hcl.h>
17 #include <asm/sn/hcl_util.h>
18 #include <asm/sn/labelcl.h>
19 #include <asm/sn/router.h>
20 #include <asm/sn/module.h>
21 #include <asm/sn/ksys/l1.h>
22 #include <asm/sn/nodepda.h>
23 #include <asm/sn/clksupport.h>
24 #include <asm/sn/sn_cpuid.h>
25 #include <asm/sn/sn_sal.h>
26 #include <linux/ctype.h>
27 
28 /* elsc_display_line writes up to 12 characters to either the top or bottom
29  * line of the L1 display.  line points to a buffer containing the message
30  * to be displayed.  The zero-based line number is specified by lnum (so
31  * lnum == 0 specifies the top line and lnum == 1 specifies the bottom).
32  * Lines longer than 12 characters, or line numbers not less than
33  * L1_DISPLAY_LINES, cause elsc_display_line to return an error.
34  */
elsc_display_line(nasid_t nasid,char * line,int lnum)35 int elsc_display_line(nasid_t nasid, char *line, int lnum)
36 {
37     return 0;
38 }
39 
40 
41 /*
42  * iobrick routines
43  */
44 
45 /* iobrick_rack_bay_type_get fills in the three int * arguments with the
46  * rack number, bay number and brick type of the L1 being addressed.  Note
47  * that if the L1 operation fails and this function returns an error value,
48  * garbage may be written to brick_type.
49  */
50 
51 
iobrick_rack_bay_type_get(nasid_t nasid,uint * rack,uint * bay,uint * brick_type)52 int iobrick_rack_bay_type_get( nasid_t nasid, uint *rack,
53 			       uint *bay, uint *brick_type )
54 {
55 	int result = 0;
56 
57 	if ( ia64_sn_sysctl_iobrick_module_get(nasid, &result) )
58 		return( ELSC_ERROR_CMD_SEND );
59 
60 	*rack = (result & MODULE_RACK_MASK) >> MODULE_RACK_SHFT;
61 	*bay = (result & MODULE_BPOS_MASK) >> MODULE_BPOS_SHFT;
62 	*brick_type = (result & MODULE_BTYPE_MASK) >> MODULE_BTYPE_SHFT;
63 	return 0;
64 }
65 
66 
iomoduleid_get(nasid_t nasid)67 int iomoduleid_get(nasid_t nasid)
68 {
69 	int result = 0;
70 
71 	if ( ia64_sn_sysctl_iobrick_module_get(nasid, &result) )
72 		return( ELSC_ERROR_CMD_SEND );
73 
74 	return result;
75 }
76 
iobrick_module_get(nasid_t nasid)77 int iobrick_module_get(nasid_t nasid)
78 {
79     uint rnum, rack, bay, brick_type, t;
80     int ret;
81 
82     /* construct module ID from rack and slot info */
83 
84     if ((ret = iobrick_rack_bay_type_get(nasid, &rnum, &bay, &brick_type)) < 0)
85         return ret;
86 
87     if (bay > MODULE_BPOS_MASK >> MODULE_BPOS_SHFT)
88         return ELSC_ERROR_MODULE;
89 
90     /* Build a moduleid_t-compatible rack number */
91 
92     rack = 0;
93     t = rnum / 100;             /* rack class (CPU/IO) */
94     if (t > RACK_CLASS_MASK(rack) >> RACK_CLASS_SHFT(rack))
95         return ELSC_ERROR_MODULE;
96     RACK_ADD_CLASS(rack, t);
97     rnum %= 100;
98 
99     t = rnum / 10;              /* rack group */
100     if (t > RACK_GROUP_MASK(rack) >> RACK_GROUP_SHFT(rack))
101         return ELSC_ERROR_MODULE;
102     RACK_ADD_GROUP(rack, t);
103 
104     t = rnum % 10;              /* rack number (one-based) */
105     if (t-1 > RACK_NUM_MASK(rack) >> RACK_NUM_SHFT(rack))
106         return ELSC_ERROR_MODULE;
107     RACK_ADD_NUM(rack, t);
108 
109     switch( brick_type ) {
110       case L1_BRICKTYPE_IX:
111 	brick_type = MODULE_IXBRICK; break;
112       case L1_BRICKTYPE_PX:
113 	brick_type = MODULE_PXBRICK; break;
114       case L1_BRICKTYPE_OPUS:
115 	brick_type = MODULE_OPUSBRICK; break;
116       case L1_BRICKTYPE_I:
117 	brick_type = MODULE_IBRICK; break;
118       case L1_BRICKTYPE_P:
119 	brick_type = MODULE_PBRICK; break;
120       case L1_BRICKTYPE_X:
121 	brick_type = MODULE_XBRICK; break;
122       case L1_BRICKTYPE_CHI_CG:
123 	brick_type = MODULE_CGBRICK; break;
124     }
125 
126     ret = RBT_TO_MODULE(rack, bay, brick_type);
127 
128     return ret;
129 }
130 
131 /*
132  * iobrick_module_get_nasid() returns a module_id which has the brick
133  * type encoded in bits 15-12, but this is not the true brick type...
134  * The module_id returned by iobrick_module_get_nasid() is modified
135  * to make a PEBRICKs & PXBRICKs look like a PBRICK.  So this routine
136  * iobrick_type_get_nasid() returns the true unmodified brick type.
137  */
138 int
iobrick_type_get_nasid(nasid_t nasid)139 iobrick_type_get_nasid(nasid_t nasid)
140 {
141     uint rack, bay, type;
142     int t, ret;
143     extern char brick_types[];
144 
145     if ((ret = iobrick_rack_bay_type_get(nasid, &rack, &bay, &type)) < 0) {
146         return ret;
147     }
148 
149     /* convert brick_type to lower case */
150     if ((type >= 'A') && (type <= 'Z'))
151         type = type - 'A' + 'a';
152 
153     /* convert to a module.h brick type */
154     for( t = 0; t < MAX_BRICK_TYPES; t++ ) {
155         if( brick_types[t] == type ) {
156             return t;
157 	}
158     }
159 
160     return -1;    /* unknown brick */
161 }
162 
iobrick_module_get_nasid(nasid_t nasid)163 int iobrick_module_get_nasid(nasid_t nasid)
164 {
165     int io_moduleid;
166 
167     io_moduleid = iobrick_module_get(nasid);
168     return io_moduleid;
169 }
170 
171 /*
172  * given a L1 bricktype, return a bricktype string.  This string is the
173  * string that will be used in the hwpath for I/O bricks
174  */
175 char *
iobrick_L1bricktype_to_name(int type)176 iobrick_L1bricktype_to_name(int type)
177 {
178     switch (type)
179     {
180     default:
181         return("Unknown");
182 
183     case L1_BRICKTYPE_X:
184         return(EDGE_LBL_XBRICK);
185 
186     case L1_BRICKTYPE_I:
187         return(EDGE_LBL_IBRICK);
188 
189     case L1_BRICKTYPE_P:
190         return(EDGE_LBL_PBRICK);
191 
192     case L1_BRICKTYPE_PX:
193         return(EDGE_LBL_PXBRICK);
194 
195     case L1_BRICKTYPE_OPUS:
196         return(EDGE_LBL_OPUSBRICK);
197 
198     case L1_BRICKTYPE_IX:
199         return(EDGE_LBL_IXBRICK);
200 
201     case L1_BRICKTYPE_C:
202         return("Cbrick");
203 
204     case L1_BRICKTYPE_R:
205         return("Rbrick");
206 
207     case L1_BRICKTYPE_CHI_CG:
208         return(EDGE_LBL_CGBRICK);
209     }
210 }
211 
212