xref: /freebsd/contrib/ofed/libibumad/umad_str.c (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 /*
2  * Copyright (c) 2004, 2005, 2010 Intel Corporation.  All rights reserved.
3  * Copyright (c) 2013 Lawrence Livermore National Security. All rights reserved.
4  * Copyright (c) 2014 Mellanox Technologies LTD. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  */
35 
36 #include <stdio.h>
37 #include <infiniband/endian.h>
38 #include <infiniband/umad.h>
39 #include <infiniband/umad_types.h>
40 #include <infiniband/umad_sm.h>
41 #include <infiniband/umad_sa.h>
42 #include <infiniband/umad_cm.h>
43 #include "umad_str.h"
44 
45 const char * umad_class_str(uint8_t mgmt_class)
46 {
47 	switch (mgmt_class) {
48 		case UMAD_CLASS_SUBN_LID_ROUTED:
49 		case UMAD_CLASS_SUBN_DIRECTED_ROUTE:
50 			return("Subn");
51 		case UMAD_CLASS_SUBN_ADM:
52 			return("SubnAdm");
53 		case UMAD_CLASS_PERF_MGMT:
54 			return("Perf");
55 		case UMAD_CLASS_BM:
56 			return("BM");
57 		case UMAD_CLASS_DEVICE_MGMT:
58 			return("DevMgt");
59 		case UMAD_CLASS_CM:
60 			return("ComMgt");
61 		case UMAD_CLASS_SNMP:
62 			return("SNMP");
63 		case UMAD_CLASS_DEVICE_ADM:
64 			return("DevAdm");
65 		case UMAD_CLASS_BOOT_MGMT:
66 			return("BootMgt");
67 		case UMAD_CLASS_BIS:
68 			return("BIS");
69 		case UMAD_CLASS_CONG_MGMT:
70 			return("CongestionManagment");
71 		default:
72 			break;
73 	}
74 
75 	if ((UMAD_CLASS_VENDOR_RANGE1_START <= mgmt_class
76 		&& mgmt_class <= UMAD_CLASS_VENDOR_RANGE1_END)
77 	    || (UMAD_CLASS_VENDOR_RANGE2_START <= mgmt_class
78 		&& mgmt_class <= UMAD_CLASS_VENDOR_RANGE2_END))
79 		return("Vendor");
80 
81 	if (UMAD_CLASS_APPLICATION_START <= mgmt_class
82 	    && mgmt_class <= UMAD_CLASS_APPLICATION_END) {
83 		return("Application");
84 	}
85 	return ("<unknown>");
86 }
87 
88 static const char * umad_common_method_str(uint8_t method)
89 {
90 	switch(method) {
91 		case UMAD_METHOD_GET:
92 			return ("Get");
93 		case UMAD_METHOD_SET:
94 			return ("Set");
95 		case UMAD_METHOD_GET_RESP:
96 			return ("GetResp");
97 		case UMAD_METHOD_SEND:
98 			return ("Send");
99 		case UMAD_METHOD_TRAP:
100 			return ("Trap");
101 		case UMAD_METHOD_REPORT:
102 			return ("Report");
103 		case UMAD_METHOD_REPORT_RESP:
104 			return ("ReportResp");
105 		case UMAD_METHOD_TRAP_REPRESS:
106 			return ("TrapRepress");
107 		default:
108 			return ("<unknown");
109 	}
110 }
111 
112 static const char * umad_sa_method_str(uint8_t method)
113 {
114 	switch(method) {
115 		case UMAD_SA_METHOD_GET_TABLE:
116 			return ("GetTable");
117 		case UMAD_SA_METHOD_GET_TABLE_RESP:
118 			return ("GetTableResp");
119 		case UMAD_SA_METHOD_DELETE:
120 			return ("Delete");
121 		case UMAD_SA_METHOD_DELETE_RESP:
122 			return ("DeleteResp");
123 		case UMAD_SA_METHOD_GET_MULTI:
124 			return ("GetMulti");
125 		case UMAD_SA_METHOD_GET_MULTI_RESP:
126 			return ("GetMultiResp");
127 		case UMAD_SA_METHOD_GET_TRACE_TABLE:
128 			return ("GetTraceTable");
129 		default:
130 			return (umad_common_method_str(method));
131 	}
132 }
133 
134 const char * umad_method_str(uint8_t mgmt_class, uint8_t method)
135 {
136 	if (mgmt_class == UMAD_CLASS_SUBN_ADM)
137 		return(umad_sa_method_str(method));
138 
139 	return (umad_common_method_str(method));
140 }
141 
142 const char * umad_common_mad_status_str(__be16 _status)
143 {
144 	uint16_t status = be16toh(_status);
145 
146 	if (status & UMAD_STATUS_BUSY)
147 		return ("Busy");
148 
149 	if (status & UMAD_STATUS_REDIRECT)
150 		return ("Redirection required");
151 
152 	switch(status & UMAD_STATUS_INVALID_FIELD_MASK) {
153 		case UMAD_STATUS_BAD_VERSION:
154 			return ("Bad Version");
155 		case UMAD_STATUS_METHOD_NOT_SUPPORTED:
156 			return ("Method not supported");
157 		case UMAD_STATUS_ATTR_NOT_SUPPORTED:
158 			return ("Method/Attribute combo not supported");
159 		case UMAD_STATUS_INVALID_ATTR_VALUE:
160 			return ("Invalid attribute/modifier field");
161 	}
162 	return ("Success");
163 }
164 
165 const char * umad_sa_mad_status_str(__be16 _status)
166 {
167 	uint16_t status = be16toh(_status);
168 	switch((status & UMAD_STATUS_CLASS_MASK) >> 8) {
169 		case UMAD_SA_STATUS_SUCCESS:
170 			return ("Success");
171 		case UMAD_SA_STATUS_NO_RESOURCES:
172 			return ("No Resources");
173 		case UMAD_SA_STATUS_REQ_INVALID:
174 			return ("Request Invalid");
175 		case UMAD_SA_STATUS_NO_RECORDS:
176 			return ("No Records");
177 		case UMAD_SA_STATUS_TOO_MANY_RECORDS:
178 			return ("Too Many Records");
179 		case UMAD_SA_STATUS_INVALID_GID:
180 			return ("Invalid GID");
181 		case UMAD_SA_STATUS_INSUF_COMPS:
182 			return ("Insufficient Components");
183 		case UMAD_SA_STATUS_REQ_DENIED:
184 			return ("Request Denied");
185 		case UMAD_SA_STATUS_PRI_SUGGESTED:
186 			return ("Priority Suggested");
187 	}
188 	return ("Undefined Error");
189 }
190 
191 static const char *umad_common_attr_str(__be16 attr_id)
192 {
193 	switch(be16toh(attr_id)) {
194 		case UMAD_ATTR_CLASS_PORT_INFO:
195 			return "Class Port Info";
196 		case UMAD_ATTR_NOTICE:
197 			return "Notice";
198 		case UMAD_ATTR_INFORM_INFO:
199 			return "Inform Info";
200 		default:
201 			return "<unknown>";
202 	}
203 }
204 
205 static const char * umad_sm_attr_str(__be16 attr_id)
206 {
207 	switch(be16toh(attr_id)) {
208 		case UMAD_SM_ATTR_NODE_DESC:
209 			return ("NodeDescription");
210 		case UMAD_SM_ATTR_NODE_INFO:
211 			return ("NodeInfo");
212 		case UMAD_SM_ATTR_SWITCH_INFO:
213 			return ("SwitchInfo");
214 		case UMAD_SM_ATTR_GUID_INFO:
215 			return ("GUIDInfo");
216 		case UMAD_SM_ATTR_PORT_INFO:
217 			return ("PortInfo");
218 		case UMAD_SM_ATTR_PKEY_TABLE:
219 			return ("P_KeyTable");
220 		case UMAD_SM_ATTR_SLVL_TABLE:
221 			return ("SLtoVLMappingTable");
222 		case UMAD_SM_ATTR_VL_ARB_TABLE:
223 			return ("VLArbitrationTable");
224 		case UMAD_SM_ATTR_LINEAR_FT:
225 			return ("LinearForwardingTable");
226 		case UMAD_SM_ATTR_RANDOM_FT:
227 			return ("RandomForwardingTable");
228 		case UMAD_SM_ATTR_MCAST_FT:
229 			return ("MulticastForwardingTable");
230 		case UMAD_SM_ATTR_SM_INFO:
231 			return ("SMInfo");
232 		case UMAD_SM_ATTR_VENDOR_DIAG:
233 			return ("VendorDiag");
234 		case UMAD_SM_ATTR_LED_INFO:
235 			return ("LedInfo");
236 		case UMAD_SM_ATTR_LINK_SPD_WIDTH_TABLE:
237 			return ("LinkSpeedWidthPairsTable");
238 		case UMAD_SM_ATTR_VENDOR_MADS_TABLE:
239 			return ("VendorSpecificMadsTable");
240 		case UMAD_SM_ATTR_HIERARCHY_INFO:
241 			return ("HierarchyInfo");
242 		case UMAD_SM_ATTR_CABLE_INFO:
243 			return ("CableInfo");
244 		case UMAD_SM_ATTR_PORT_INFO_EXT:
245 			return ("PortInfoExtended");
246 		default:
247 			return (umad_common_attr_str(attr_id));
248 	}
249 }
250 
251 static const char * umad_sa_attr_str(__be16 attr_id)
252 {
253 	switch(be16toh(attr_id)) {
254 		case UMAD_SA_ATTR_NODE_REC:
255 			return ("NodeRecord");
256 		case UMAD_SA_ATTR_PORT_INFO_REC:
257 			return ("PortInfoRecord");
258 		case UMAD_SA_ATTR_SLVL_REC:
259 			return ("SLtoVLMappingTableRecord");
260 		case UMAD_SA_ATTR_SWITCH_INFO_REC:
261 			return ("SwitchInfoRecord");
262 		case UMAD_SA_ATTR_LINEAR_FT_REC:
263 			return ("LinearForwardingTableRecord");
264 		case UMAD_SA_ATTR_RANDOM_FT_REC:
265 			return ("RandomForwardingTableRecord");
266 		case UMAD_SA_ATTR_MCAST_FT_REC:
267 			return ("MulticastForwardingTableRecord");
268 		case UMAD_SA_ATTR_SM_INFO_REC:
269 			return ("SMInfoRecord");
270 		case UMAD_SA_ATTR_INFORM_INFO_REC:
271 			return ("InformInfoRecord");
272 		case UMAD_SA_ATTR_LINK_REC:
273 			return ("LinkRecord");
274 		case UMAD_SA_ATTR_GUID_INFO_REC:
275 			return ("GuidInfoRecord");
276 		case UMAD_SA_ATTR_SERVICE_REC:
277 			return ("ServiceRecord");
278 		case UMAD_SA_ATTR_PKEY_TABLE_REC:
279 			return ("P_KeyTableRecord");
280 		case UMAD_SA_ATTR_PATH_REC:
281 			return ("PathRecord");
282 		case UMAD_SA_ATTR_VL_ARB_REC:
283 			return ("VLArbitrationTableRecord");
284 		case UMAD_SA_ATTR_MCMEMBER_REC:
285 			return ("MCMemberRecord");
286 		case UMAD_SA_ATTR_TRACE_REC:
287 			return ("TraceRecord");
288 		case UMAD_SA_ATTR_MULTI_PATH_REC:
289 			return ("MultiPathRecord");
290 		case UMAD_SA_ATTR_SERVICE_ASSOC_REC:
291 			return ("ServiceAssociationRecord");
292 		case UMAD_SA_ATTR_LINK_SPD_WIDTH_TABLE_REC:
293 			return ("LinkSpeedWidthPairsTableRecord");
294 		case UMAD_SA_ATTR_HIERARCHY_INFO_REC:
295 			return ("HierarchyInfoRecord");
296 		case UMAD_SA_ATTR_CABLE_INFO_REC:
297 			return ("CableInfoRecord");
298 		case UMAD_SA_ATTR_PORT_INFO_EXT_REC:
299 			return ("PortInfoExtendedRecord");
300 		default:
301 			return (umad_common_attr_str(attr_id));
302 	}
303 }
304 
305 static const char * umad_cm_attr_str(__be16 attr_id)
306 {
307 	switch(be16toh(attr_id)) {
308 		case UMAD_CM_ATTR_REQ:
309 			return "ConnectRequest";
310 		case UMAD_CM_ATTR_MRA:
311 			return "MsgRcptAck";
312 		case UMAD_CM_ATTR_REJ:
313 			return "ConnectReject";
314 		case UMAD_CM_ATTR_REP:
315 			return "ConnectReply";
316 		case UMAD_CM_ATTR_RTU:
317 			return "ReadyToUse";
318 		case UMAD_CM_ATTR_DREQ:
319 			return "DisconnectRequest";
320 		case UMAD_CM_ATTR_DREP:
321 			return "DisconnectReply";
322 		case UMAD_CM_ATTR_SIDR_REQ:
323 			return "ServiceIDResReq";
324 		case UMAD_CM_ATTR_SIDR_REP:
325 			return "ServiceIDResReqResp";
326 		case UMAD_CM_ATTR_LAP:
327 			return "LoadAlternatePath";
328 		case UMAD_CM_ATTR_APR:
329 			return "AlternatePathResponse";
330 		case UMAD_CM_ATTR_SAP:
331 			return "SuggestAlternatePath";
332 		case UMAD_CM_ATTR_SPR:
333 			return "SuggestPathResponse";
334 		default:
335 			return (umad_common_attr_str(attr_id));
336 	}
337 }
338 
339 const char * umad_attribute_str(uint8_t mgmt_class, __be16 attr_id)
340 {
341 	switch (mgmt_class) {
342 		case UMAD_CLASS_SUBN_LID_ROUTED:
343 		case UMAD_CLASS_SUBN_DIRECTED_ROUTE:
344 			return(umad_sm_attr_str(attr_id));
345 		case UMAD_CLASS_SUBN_ADM:
346 			return(umad_sa_attr_str(attr_id));
347 		case UMAD_CLASS_CM:
348 			return(umad_cm_attr_str(attr_id));
349 	}
350 
351 	return (umad_common_attr_str(attr_id));
352 }
353