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 return ("<unknown>"); 250 } 251 252 static const char * umad_sa_attr_str(__be16 attr_id) 253 { 254 switch(be16toh(attr_id)) { 255 case UMAD_SA_ATTR_NODE_REC: 256 return ("NodeRecord"); 257 case UMAD_SA_ATTR_PORT_INFO_REC: 258 return ("PortInfoRecord"); 259 case UMAD_SA_ATTR_SLVL_REC: 260 return ("SLtoVLMappingTableRecord"); 261 case UMAD_SA_ATTR_SWITCH_INFO_REC: 262 return ("SwitchInfoRecord"); 263 case UMAD_SA_ATTR_LINEAR_FT_REC: 264 return ("LinearForwardingTableRecord"); 265 case UMAD_SA_ATTR_RANDOM_FT_REC: 266 return ("RandomForwardingTableRecord"); 267 case UMAD_SA_ATTR_MCAST_FT_REC: 268 return ("MulticastForwardingTableRecord"); 269 case UMAD_SA_ATTR_SM_INFO_REC: 270 return ("SMInfoRecord"); 271 case UMAD_SA_ATTR_INFORM_INFO_REC: 272 return ("InformInfoRecord"); 273 case UMAD_SA_ATTR_LINK_REC: 274 return ("LinkRecord"); 275 case UMAD_SA_ATTR_GUID_INFO_REC: 276 return ("GuidInfoRecord"); 277 case UMAD_SA_ATTR_SERVICE_REC: 278 return ("ServiceRecord"); 279 case UMAD_SA_ATTR_PKEY_TABLE_REC: 280 return ("P_KeyTableRecord"); 281 case UMAD_SA_ATTR_PATH_REC: 282 return ("PathRecord"); 283 case UMAD_SA_ATTR_VL_ARB_REC: 284 return ("VLArbitrationTableRecord"); 285 case UMAD_SA_ATTR_MCMEMBER_REC: 286 return ("MCMemberRecord"); 287 case UMAD_SA_ATTR_TRACE_REC: 288 return ("TraceRecord"); 289 case UMAD_SA_ATTR_MULTI_PATH_REC: 290 return ("MultiPathRecord"); 291 case UMAD_SA_ATTR_SERVICE_ASSOC_REC: 292 return ("ServiceAssociationRecord"); 293 case UMAD_SA_ATTR_LINK_SPD_WIDTH_TABLE_REC: 294 return ("LinkSpeedWidthPairsTableRecord"); 295 case UMAD_SA_ATTR_HIERARCHY_INFO_REC: 296 return ("HierarchyInfoRecord"); 297 case UMAD_SA_ATTR_CABLE_INFO_REC: 298 return ("CableInfoRecord"); 299 case UMAD_SA_ATTR_PORT_INFO_EXT_REC: 300 return ("PortInfoExtendedRecord"); 301 default: 302 return (umad_common_attr_str(attr_id)); 303 } 304 return ("<unknown>"); 305 } 306 307 static const char * umad_cm_attr_str(__be16 attr_id) 308 { 309 switch(be16toh(attr_id)) { 310 case UMAD_CM_ATTR_REQ: 311 return "ConnectRequest"; 312 case UMAD_CM_ATTR_MRA: 313 return "MsgRcptAck"; 314 case UMAD_CM_ATTR_REJ: 315 return "ConnectReject"; 316 case UMAD_CM_ATTR_REP: 317 return "ConnectReply"; 318 case UMAD_CM_ATTR_RTU: 319 return "ReadyToUse"; 320 case UMAD_CM_ATTR_DREQ: 321 return "DisconnectRequest"; 322 case UMAD_CM_ATTR_DREP: 323 return "DisconnectReply"; 324 case UMAD_CM_ATTR_SIDR_REQ: 325 return "ServiceIDResReq"; 326 case UMAD_CM_ATTR_SIDR_REP: 327 return "ServiceIDResReqResp"; 328 case UMAD_CM_ATTR_LAP: 329 return "LoadAlternatePath"; 330 case UMAD_CM_ATTR_APR: 331 return "AlternatePathResponse"; 332 case UMAD_CM_ATTR_SAP: 333 return "SuggestAlternatePath"; 334 case UMAD_CM_ATTR_SPR: 335 return "SuggestPathResponse"; 336 default: 337 return (umad_common_attr_str(attr_id)); 338 } 339 return ("<unknown>"); 340 } 341 342 const char * umad_attribute_str(uint8_t mgmt_class, __be16 attr_id) 343 { 344 switch (mgmt_class) { 345 case UMAD_CLASS_SUBN_LID_ROUTED: 346 case UMAD_CLASS_SUBN_DIRECTED_ROUTE: 347 return(umad_sm_attr_str(attr_id)); 348 case UMAD_CLASS_SUBN_ADM: 349 return(umad_sa_attr_str(attr_id)); 350 case UMAD_CLASS_CM: 351 return(umad_cm_attr_str(attr_id)); 352 } 353 354 return (umad_common_attr_str(attr_id)); 355 } 356