Update ia64 patch to 2.5.72-030619
[linux-flexiantxendom0-3.2.10.git] / arch / ia64 / sn / io / sn2 / l1_command.c
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  */
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
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         *brick_type = toupper(*brick_type);
64
65         return 0;
66 }
67
68
69 int iomoduleid_get(nasid_t nasid)
70 {
71         int result = 0;
72
73         if ( ia64_sn_sysctl_iobrick_module_get(nasid, &result) )
74                 return( ELSC_ERROR_CMD_SEND );
75
76         return result;
77 }
78
79 int iobrick_module_get(nasid_t nasid)
80 {
81     uint rnum, rack, bay, brick_type, t;
82     int ret;
83
84     /* construct module ID from rack and slot info */
85
86     if ((ret = iobrick_rack_bay_type_get(nasid, &rnum, &bay, &brick_type)) < 0)
87         return ret;
88
89     if (bay > MODULE_BPOS_MASK >> MODULE_BPOS_SHFT)
90         return ELSC_ERROR_MODULE;
91
92     /* Build a moduleid_t-compatible rack number */
93
94     rack = 0;           
95     t = rnum / 100;             /* rack class (CPU/IO) */
96     if (t > RACK_CLASS_MASK(rack) >> RACK_CLASS_SHFT(rack))
97         return ELSC_ERROR_MODULE;
98     RACK_ADD_CLASS(rack, t);
99     rnum %= 100;
100
101     t = rnum / 10;              /* rack group */
102     if (t > RACK_GROUP_MASK(rack) >> RACK_GROUP_SHFT(rack))
103         return ELSC_ERROR_MODULE;
104     RACK_ADD_GROUP(rack, t);
105
106     t = rnum % 10;              /* rack number (one-based) */
107     if (t-1 > RACK_NUM_MASK(rack) >> RACK_NUM_SHFT(rack))
108         return ELSC_ERROR_MODULE;
109     RACK_ADD_NUM(rack, t);
110
111     switch( brick_type ) {
112       case L1_BRICKTYPE_IX: 
113         brick_type = MODULE_IXBRICK; break;
114       case L1_BRICKTYPE_PX: 
115         brick_type = MODULE_PXBRICK; 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     }
123
124     ret = RBT_TO_MODULE(rack, bay, brick_type);
125
126     return ret;
127 }
128
129 /*
130  * iobrick_module_get_nasid() returns a module_id which has the brick
131  * type encoded in bits 15-12, but this is not the true brick type...
132  * The module_id returned by iobrick_module_get_nasid() is modified
133  * to make a PEBRICKs & PXBRICKs look like a PBRICK.  So this routine
134  * iobrick_type_get_nasid() returns the true unmodified brick type.
135  */
136 int
137 iobrick_type_get_nasid(nasid_t nasid)
138 {
139     uint rack, bay, type;
140     int t, ret;
141     extern char brick_types[];
142
143     if ((ret = iobrick_rack_bay_type_get(nasid, &rack, &bay, &type)) < 0) {
144         return ret;
145     }
146
147     /* convert brick_type to lower case */
148     if ((type >= 'A') && (type <= 'Z'))
149         type = type - 'A' + 'a';
150
151     /* convert to a module.h brick type */
152     for( t = 0; t < MAX_BRICK_TYPES; t++ ) {
153         if( brick_types[t] == type ) {
154             return t;
155         }
156     }
157
158     return -1;    /* unknown brick */
159 }
160
161 int iobrick_module_get_nasid(nasid_t nasid)
162 {
163     int io_moduleid;
164
165     io_moduleid = iobrick_module_get(nasid);
166     return io_moduleid;
167 }
168
169 /*
170  * given a L1 bricktype, return a bricktype string.  This string is the
171  * string that will be used in the hwpath for I/O bricks
172  */
173 char *
174 iobrick_L1bricktype_to_name(int type)
175 {
176     switch (type)
177     {
178     default:
179         return("Unknown");
180
181     case L1_BRICKTYPE_X:
182         return("Xbrick");
183
184     case L1_BRICKTYPE_I:
185         return("Ibrick");
186
187     case L1_BRICKTYPE_P:
188         return("Pbrick");
189
190     case L1_BRICKTYPE_PX:
191         return("PXbrick");
192
193     case L1_BRICKTYPE_IX:
194         return("IXbrick");
195
196     case L1_BRICKTYPE_C:
197         return("Cbrick");
198
199     case L1_BRICKTYPE_R:
200         return("Rbrick");
201     }
202 }
203