xref: /freebsd/contrib/ofed/opensm/opensm/osm_helper.c (revision 9f44a47fd07924afc035991af15d84e6585dea4f)
1 /*
2  * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
3  * Copyright (c) 2002-2015 Mellanox Technologies LTD. All rights reserved.
4  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5  * Copyright (c) 2009 HNR Consulting. All rights reserved.
6  * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
7  *
8  * This software is available to you under a choice of one of two
9  * licenses.  You may choose to be licensed under the terms of the GNU
10  * General Public License (GPL) Version 2, available from the file
11  * COPYING in the main directory of this source tree, or the
12  * OpenIB.org BSD license below:
13  *
14  *     Redistribution and use in source and binary forms, with or
15  *     without modification, are permitted provided that the following
16  *     conditions are met:
17  *
18  *      - Redistributions of source code must retain the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer.
21  *
22  *      - Redistributions in binary form must reproduce the above
23  *        copyright notice, this list of conditions and the following
24  *        disclaimer in the documentation and/or other materials
25  *        provided with the distribution.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34  * SOFTWARE.
35  *
36  */
37 
38 /*
39  * Abstract:
40  *    Implementation of opensm helper functions.
41  */
42 
43 #if HAVE_CONFIG_H
44 #  include <config.h>
45 #endif				/* HAVE_CONFIG_H */
46 
47 #include <stdlib.h>
48 #include <stdio.h>
49 #include <string.h>
50 #include <arpa/inet.h>
51 #include <sys/socket.h>
52 #include <complib/cl_debug.h>
53 #include <iba/ib_types.h>
54 #include <opensm/osm_file_ids.h>
55 #define FILE_ID OSM_FILE_HELPER_C
56 #include <opensm/osm_helper.h>
57 #include <opensm/osm_log.h>
58 
59 #define LINE_LENGTH 256
60 
61 #define ARR_SIZE(a) (sizeof(a)/sizeof((a)[0]))
62 
63 /* we use two tables - one for queries and one for responses */
64 static const char *ib_sa_method_str[] = {
65 	"RESERVED",		/* 0 */
66 	"SubnAdmGet",		/* 1 */
67 	"SubnAdmSet",		/* 2 */
68 	"RESERVED",		/* 3 */
69 	"RESERVED",		/* 4 */
70 	"RESERVED",		/* 5 */
71 	"SubnAdmReport",	/* 6 */
72 	"RESERVED",		/* 7 */
73 	"RESERVED",		/* 8 */
74 	"RESERVED",		/* 9 */
75 	"RESERVED",		/* A */
76 	"RESERVED",		/* B */
77 	"RESERVED",		/* C */
78 	"RESERVED",		/* D */
79 	"RESERVED",		/* E */
80 	"RESERVED",		/* F */
81 	"RESERVED",		/* 10 */
82 	"RESERVED",		/* 11 */
83 	"SubnAdmGetTable",	/* 12 */
84 	"SubnAdmGetTraceTable",	/* 13 */
85 	"SubnAdmGetMulti",	/* 14 */
86 	"SubnAdmDelete",	/* 15 */
87 	"UNKNOWN"		/* 16 */
88 };
89 
90 #define OSM_SA_METHOD_STR_UNKNOWN_VAL (ARR_SIZE(ib_sa_method_str) - 1)
91 
92 static const char *ib_sa_resp_method_str[] = {
93 	"RESERVED",		/* 80 */
94 	"SubnAdmGetResp",	/* 81 */
95 	"RESERVED (SetResp?)",	/* 82 */
96 	"RESERVED",		/* 83 */
97 	"RESERVED",		/* 84 */
98 	"RESERVED",		/* 85 */
99 	"SubnAdmReportResp",	/* 86 */
100 	"RESERVED",		/* 87 */
101 	"RESERVED",		/* 88 */
102 	"RESERVED",		/* 89 */
103 	"RESERVED",		/* 8A */
104 	"RESERVED",		/* 8B */
105 	"RESERVED",		/* 8C */
106 	"RESERVED",		/* 8D */
107 	"RESERVED",		/* 8E */
108 	"RESERVED",		/* 8F */
109 	"RESERVED",		/* 90 */
110 	"RESERVED",		/* 91 */
111 	"SubnAdmGetTableResp",	/* 92 */
112 	"RESERVED",		/* 93 */
113 	"SubnAdmGetMultiResp",	/* 94 */
114 	"SubnAdmDeleteResp",	/* 95 */
115 	"UNKNOWN"
116 };
117 
118 static const char *ib_sm_method_str[] = {
119 	"RESERVED0",		/* 0 */
120 	"SubnGet",		/* 1 */
121 	"SubnSet",		/* 2 */
122 	"RESERVED3",		/* 3 */
123 	"RESERVED4",		/* 4 */
124 	"SubnTrap",		/* 5 */
125 	"RESERVED6",		/* 6 */
126 	"SubnTrapRepress",	/* 7 */
127 	"RESERVED8",		/* 8 */
128 	"RESERVED9",		/* 9 */
129 	"RESERVEDA",		/* A */
130 	"RESERVEDB",		/* B */
131 	"RESERVEDC",		/* C */
132 	"RESERVEDD",		/* D */
133 	"RESERVEDE",		/* E */
134 	"RESERVEDF",		/* F */
135 	"RESERVED10",		/* 10 */
136 	"SubnGetResp",		/* 11 */
137 	"RESERVED12",		/* 12 */
138 	"RESERVED13",		/* 13 */
139 	"RESERVED14",		/* 14 */
140 	"RESERVED15",		/* 15 */
141 	"RESERVED16",		/* 16 */
142 	"RESERVED17",		/* 17 */
143 	"RESERVED18",		/* 18 */
144 	"RESERVED19",		/* 19 */
145 	"RESERVED1A",		/* 1A */
146 	"RESERVED1B",		/* 1B */
147 	"RESERVED1C",		/* 1C */
148 	"RESERVED1D",		/* 1D */
149 	"RESERVED1E",		/* 1E */
150 	"RESERVED1F",		/* 1F */
151 	"UNKNOWN"		/* 20 */
152 };
153 
154 #define OSM_SM_METHOD_STR_UNKNOWN_VAL (ARR_SIZE(ib_sm_method_str) - 1)
155 
156 static const char *ib_sm_attr_str[] = {
157 	"RESERVED",		/* 0 */
158 	"ClassPortInfo",	/* 1 */
159 	"Notice",		/* 2 */
160 	"InformInfo",		/* 3 */
161 	"RESERVED",		/* 4 */
162 	"RESERVED",		/* 5 */
163 	"RESERVED",		/* 6 */
164 	"RESERVED",		/* 7 */
165 	"RESERVED",		/* 8 */
166 	"RESERVED",		/* 9 */
167 	"RESERVED",		/* A */
168 	"RESERVED",		/* B */
169 	"RESERVED",		/* C */
170 	"RESERVED",		/* D */
171 	"RESERVED",		/* E */
172 	"RESERVED",		/* F */
173 	"NodeDescription",	/* 10 */
174 	"NodeInfo",		/* 11 */
175 	"SwitchInfo",		/* 12 */
176 	"UNKNOWN",		/* 13 */
177 	"GUIDInfo",		/* 14 */
178 	"PortInfo",		/* 15 */
179 	"P_KeyTable",		/* 16 */
180 	"SLtoVLMappingTable",	/* 17 */
181 	"VLArbitrationTable",	/* 18 */
182 	"LinearForwardingTable",	/* 19 */
183 	"RandomForwardingTable",	/* 1A */
184 	"MulticastForwardingTable",	/* 1B */
185 	"UNKNOWN",		/* 1C */
186 	"UNKNOWN",		/* 1D */
187 	"UNKNOWN",		/* 1E */
188 	"UNKNOWN",		/* 1F */
189 	"SMInfo",		/* 20 */
190 	"UNKNOWN"		/* 21 - always highest value */
191 };
192 
193 #define OSM_SM_ATTR_STR_UNKNOWN_VAL (ARR_SIZE(ib_sm_attr_str) - 1)
194 
195 static const char *ib_sa_attr_str[] = {
196 	"RESERVED",		/* 0 */
197 	"ClassPortInfo",	/* 1 */
198 	"Notice",		/* 2 */
199 	"InformInfo",		/* 3 */
200 	"RESERVED",		/* 4 */
201 	"RESERVED",		/* 5 */
202 	"RESERVED",		/* 6 */
203 	"RESERVED",		/* 7 */
204 	"RESERVED",		/* 8 */
205 	"RESERVED",		/* 9 */
206 	"RESERVED",		/* A */
207 	"RESERVED",		/* B */
208 	"RESERVED",		/* C */
209 	"RESERVED",		/* D */
210 	"RESERVED",		/* E */
211 	"RESERVED",		/* F */
212 	"RESERVED",		/* 10 */
213 	"NodeRecord",		/* 11 */
214 	"PortInfoRecord",	/* 12 */
215 	"SLtoVLMappingTableRecord",	/* 13 */
216 	"SwitchInfoRecord",	/* 14 */
217 	"LinearForwardingTableRecord",	/* 15 */
218 	"RandomForwardingTableRecord",	/* 16 */
219 	"MulticastForwardingTableRecord",	/* 17 */
220 	"SMInfoRecord",		/* 18 */
221 	"RESERVED",		/* 19 */
222 	"RandomForwardingTable",	/* 1A */
223 	"MulticastForwardingTable",	/* 1B */
224 	"UNKNOWN",		/* 1C */
225 	"UNKNOWN",		/* 1D */
226 	"UNKNOWN",		/* 1E */
227 	"UNKNOWN",		/* 1F */
228 	"LinkRecord",		/* 20 */
229 	"UNKNOWN",		/* 21 */
230 	"UNKNOWN",		/* 22 */
231 	"UNKNOWN",		/* 23 */
232 	"UNKNOWN",		/* 24 */
233 	"UNKNOWN",		/* 25 */
234 	"UNKNOWN",		/* 26 */
235 	"UNKNOWN",		/* 27 */
236 	"UNKNOWN",		/* 28 */
237 	"UNKNOWN",		/* 29 */
238 	"UNKNOWN",		/* 2A */
239 	"UNKNOWN",		/* 2B */
240 	"UNKNOWN",		/* 2C */
241 	"UNKNOWN",		/* 2D */
242 	"UNKNOWN",		/* 2E */
243 	"UNKNOWN",		/* 2F */
244 	"GuidInfoRecord",	/* 30 */
245 	"ServiceRecord",	/* 31 */
246 	"UNKNOWN",		/* 32 */
247 	"P_KeyTableRecord",	/* 33 */
248 	"UNKNOWN",		/* 34 */
249 	"PathRecord",		/* 35 */
250 	"VLArbitrationTableRecord",	/* 36 */
251 	"UNKNOWN",		/* 37 */
252 	"MCMemberRecord",	/* 38 */
253 	"TraceRecord",		/* 39 */
254 	"MultiPathRecord",	/* 3A */
255 	"ServiceAssociationRecord",	/* 3B */
256 	"UNKNOWN",		/* 3C */
257 	"UNKNOWN",		/* 3D */
258 	"UNKNOWN",		/* 3E */
259 	"UNKNOWN",		/* 3F */
260 	"UNKNOWN",		/* 40 */
261 	"UNKNOWN",		/* 41 */
262 	"UNKNOWN",		/* 42 */
263 	"UNKNOWN",		/* 43 */
264 	"UNKNOWN",		/* 44 */
265 	"UNKNOWN",		/* 45 */
266 	"UNKNOWN",		/* 46 */
267 	"UNKNOWN",		/* 47 */
268 	"UNKNOWN",		/* 48 */
269 	"UNKNOWN",		/* 49 */
270 	"UNKNOWN",		/* 4A */
271 	"UNKNOWN",		/* 4B */
272 	"UNKNOWN",		/* 4C */
273 	"UNKNOWN",		/* 4D */
274 	"UNKNOWN",		/* 4E */
275 	"UNKNOWN",		/* 4F */
276 	"UNKNOWN",		/* 50 */
277 	"UNKNOWN",		/* 51 */
278 	"UNKNOWN",		/* 52 */
279 	"UNKNOWN",		/* 53 */
280 	"UNKNOWN",		/* 54 */
281 	"UNKNOWN",		/* 55 */
282 	"UNKNOWN",		/* 56 */
283 	"UNKNOWN",		/* 57 */
284 	"UNKNOWN",		/* 58 */
285 	"UNKNOWN",		/* 59 */
286 	"UNKNOWN",		/* 5A */
287 	"UNKNOWN",		/* 5B */
288 	"UNKNOWN",		/* 5C */
289 	"UNKNOWN",		/* 5D */
290 	"UNKNOWN",		/* 5E */
291 	"UNKNOWN",		/* 5F */
292 	"UNKNOWN",		/* 60 */
293 	"UNKNOWN",		/* 61 */
294 	"UNKNOWN",		/* 62 */
295 	"UNKNOWN",		/* 63 */
296 	"UNKNOWN",		/* 64 */
297 	"UNKNOWN",		/* 65 */
298 	"UNKNOWN",		/* 66 */
299 	"UNKNOWN",		/* 67 */
300 	"UNKNOWN",		/* 68 */
301 	"UNKNOWN",		/* 69 */
302 	"UNKNOWN",		/* 6A */
303 	"UNKNOWN",		/* 6B */
304 	"UNKNOWN",		/* 6C */
305 	"UNKNOWN",		/* 6D */
306 	"UNKNOWN",		/* 6E */
307 	"UNKNOWN",		/* 6F */
308 	"UNKNOWN",		/* 70 */
309 	"UNKNOWN",		/* 71 */
310 	"UNKNOWN",		/* 72 */
311 	"UNKNOWN",		/* 73 */
312 	"UNKNOWN",		/* 74 */
313 	"UNKNOWN",		/* 75 */
314 	"UNKNOWN",		/* 76 */
315 	"UNKNOWN",		/* 77 */
316 	"UNKNOWN",		/* 78 */
317 	"UNKNOWN",		/* 79 */
318 	"UNKNOWN",		/* 7A */
319 	"UNKNOWN",		/* 7B */
320 	"UNKNOWN",		/* 7C */
321 	"UNKNOWN",		/* 7D */
322 	"UNKNOWN",		/* 7E */
323 	"UNKNOWN",		/* 7F */
324 	"UNKNOWN",		/* 80 */
325 	"UNKNOWN",		/* 81 */
326 	"UNKNOWN",		/* 82 */
327 	"UNKNOWN",		/* 83 */
328 	"UNKNOWN",		/* 84 */
329 	"UNKNOWN",		/* 85 */
330 	"UNKNOWN",		/* 86 */
331 	"UNKNOWN",		/* 87 */
332 	"UNKNOWN",		/* 88 */
333 	"UNKNOWN",		/* 89 */
334 	"UNKNOWN",		/* 8A */
335 	"UNKNOWN",		/* 8B */
336 	"UNKNOWN",		/* 8C */
337 	"UNKNOWN",		/* 8D */
338 	"UNKNOWN",		/* 8E */
339 	"UNKNOWN",		/* 8F */
340 	"UNKNOWN",		/* 90 */
341 	"UNKNOWN",		/* 91 */
342 	"UNKNOWN",		/* 92 */
343 	"UNKNOWN",		/* 93 */
344 	"UNKNOWN",		/* 94 */
345 	"UNKNOWN",		/* 95 */
346 	"UNKNOWN",		/* 96 */
347 	"UNKNOWN",		/* 97 */
348 	"UNKNOWN",		/* 98 */
349 	"UNKNOWN",		/* 99 */
350 	"UNKNOWN",		/* 9A */
351 	"UNKNOWN",		/* 9B */
352 	"UNKNOWN",		/* 9C */
353 	"UNKNOWN",		/* 9D */
354 	"UNKNOWN",		/* 9E */
355 	"UNKNOWN",		/* 9F */
356 	"UNKNOWN",		/* A0 */
357 	"UNKNOWN",		/* A1 */
358 	"UNKNOWN",		/* A2 */
359 	"UNKNOWN",		/* A3 */
360 	"UNKNOWN",		/* A4 */
361 	"UNKNOWN",		/* A5 */
362 	"UNKNOWN",		/* A6 */
363 	"UNKNOWN",		/* A7 */
364 	"UNKNOWN",		/* A8 */
365 	"UNKNOWN",		/* A9 */
366 	"UNKNOWN",		/* AA */
367 	"UNKNOWN",		/* AB */
368 	"UNKNOWN",		/* AC */
369 	"UNKNOWN",		/* AD */
370 	"UNKNOWN",		/* AE */
371 	"UNKNOWN",		/* AF */
372 	"UNKNOWN",		/* B0 */
373 	"UNKNOWN",		/* B1 */
374 	"UNKNOWN",		/* B2 */
375 	"UNKNOWN",		/* B3 */
376 	"UNKNOWN",		/* B4 */
377 	"UNKNOWN",		/* B5 */
378 	"UNKNOWN",		/* B6 */
379 	"UNKNOWN",		/* B7 */
380 	"UNKNOWN",		/* B8 */
381 	"UNKNOWN",		/* B9 */
382 	"UNKNOWN",		/* BA */
383 	"UNKNOWN",		/* BB */
384 	"UNKNOWN",		/* BC */
385 	"UNKNOWN",		/* BD */
386 	"UNKNOWN",		/* BE */
387 	"UNKNOWN",		/* BF */
388 	"UNKNOWN",		/* C0 */
389 	"UNKNOWN",		/* C1 */
390 	"UNKNOWN",		/* C2 */
391 	"UNKNOWN",		/* C3 */
392 	"UNKNOWN",		/* C4 */
393 	"UNKNOWN",		/* C5 */
394 	"UNKNOWN",		/* C6 */
395 	"UNKNOWN",		/* C7 */
396 	"UNKNOWN",		/* C8 */
397 	"UNKNOWN",		/* C9 */
398 	"UNKNOWN",		/* CA */
399 	"UNKNOWN",		/* CB */
400 	"UNKNOWN",		/* CC */
401 	"UNKNOWN",		/* CD */
402 	"UNKNOWN",		/* CE */
403 	"UNKNOWN",		/* CF */
404 	"UNKNOWN",		/* D0 */
405 	"UNKNOWN",		/* D1 */
406 	"UNKNOWN",		/* D2 */
407 	"UNKNOWN",		/* D3 */
408 	"UNKNOWN",		/* D4 */
409 	"UNKNOWN",		/* D5 */
410 	"UNKNOWN",		/* D6 */
411 	"UNKNOWN",		/* D7 */
412 	"UNKNOWN",		/* D8 */
413 	"UNKNOWN",		/* D9 */
414 	"UNKNOWN",		/* DA */
415 	"UNKNOWN",		/* DB */
416 	"UNKNOWN",		/* DC */
417 	"UNKNOWN",		/* DD */
418 	"UNKNOWN",		/* DE */
419 	"UNKNOWN",		/* DF */
420 	"UNKNOWN",		/* E0 */
421 	"UNKNOWN",		/* E1 */
422 	"UNKNOWN",		/* E2 */
423 	"UNKNOWN",		/* E3 */
424 	"UNKNOWN",		/* E4 */
425 	"UNKNOWN",		/* E5 */
426 	"UNKNOWN",		/* E6 */
427 	"UNKNOWN",		/* E7 */
428 	"UNKNOWN",		/* E8 */
429 	"UNKNOWN",		/* E9 */
430 	"UNKNOWN",		/* EA */
431 	"UNKNOWN",		/* EB */
432 	"UNKNOWN",		/* EC */
433 	"UNKNOWN",		/* ED */
434 	"UNKNOWN",		/* EE */
435 	"UNKNOWN",		/* EF */
436 	"UNKNOWN",		/* F0 */
437 	"UNKNOWN",		/* F1 */
438 	"UNKNOWN",		/* F2 */
439 	"InformInfoRecord",	/* F3 */
440 	"UNKNOWN"		/* F4 - always highest value */
441 };
442 
443 #define OSM_SA_ATTR_STR_UNKNOWN_VAL (ARR_SIZE(ib_sa_attr_str) - 1)
444 
445 static int ordered_rates[] = {
446 	0, 0,	/*  0, 1 - reserved */
447 	1,	/*  2 - 2.5 Gbps */
448 	3,	/*  3 - 10  Gbps */
449 	6,	/*  4 - 30  Gbps */
450 	2,	/*  5 - 5   Gbps */
451 	5,	/*  6 - 20  Gbps */
452 	9,	/*  7 - 40  Gbps */
453 	10,	/*  8 - 60  Gbps */
454 	13,	/*  9 - 80  Gbps */
455 	14,	/* 10 - 120 Gbps */
456 	4,	/* 11 -  14 Gbps (17 Gbps equiv) */
457 	12,	/* 12 -  56 Gbps (68 Gbps equiv) */
458 	16,	/* 13 - 112 Gbps (136 Gbps equiv) */
459 	17,	/* 14 - 168 Gbps (204 Gbps equiv) */
460 	7,	/* 15 -  25 Gbps (31.25 Gbps equiv) */
461 	15,	/* 16 - 100 Gbps (125 Gbps equiv) */
462 	18,	/* 17 - 200 Gbps (250 Gbps equiv) */
463 	19,	/* 18 - 300 Gbps (375 Gbps equiv) */
464 	8,	/* 19 -  28 Gbps (35 Gbps equiv) */
465 	11,	/* 20 -  50 Gbps (62.5 Gbps equiv) */
466 };
467 
468 int sprint_uint8_arr(char *buf, size_t size,
469 		     const uint8_t * arr, size_t len)
470 {
471 	int n;
472 	unsigned int i;
473 	for (i = 0, n = 0; i < len; i++) {
474 		n += snprintf(buf + n, size - n, "%s%u", i == 0 ? "" : ",",
475 			      arr[i]);
476 		if (n >= size)
477 			break;
478 	}
479 	return n;
480 }
481 
482 const char *ib_get_sa_method_str(IN uint8_t method)
483 {
484 	if (method & 0x80) {
485 		method = method & 0x7f;
486 		if (method > OSM_SA_METHOD_STR_UNKNOWN_VAL)
487 			method = OSM_SA_METHOD_STR_UNKNOWN_VAL;
488 		/* it is a response - use the response table */
489 		return ib_sa_resp_method_str[method];
490 	} else {
491 		if (method > OSM_SA_METHOD_STR_UNKNOWN_VAL)
492 			method = OSM_SA_METHOD_STR_UNKNOWN_VAL;
493 		return ib_sa_method_str[method];
494 	}
495 }
496 
497 const char *ib_get_sm_method_str(IN uint8_t method)
498 {
499 	if (method & 0x80)
500 		method = (method & 0x0F) | 0x10;
501 	if (method > OSM_SM_METHOD_STR_UNKNOWN_VAL)
502 		method = OSM_SM_METHOD_STR_UNKNOWN_VAL;
503 	return ib_sm_method_str[method];
504 }
505 
506 const char *ib_get_sm_attr_str(IN ib_net16_t attr)
507 {
508 	uint16_t host_attr = cl_ntoh16(attr);
509 
510 	if (attr == IB_MAD_ATTR_MLNX_EXTENDED_PORT_INFO)
511 		return "MLNXExtendedPortInfo";
512 
513 	if (host_attr > OSM_SM_ATTR_STR_UNKNOWN_VAL)
514 		host_attr = OSM_SM_ATTR_STR_UNKNOWN_VAL;
515 
516 	return ib_sm_attr_str[host_attr];
517 }
518 
519 const char *ib_get_sa_attr_str(IN ib_net16_t attr)
520 {
521 	uint16_t host_attr = cl_ntoh16(attr);
522 
523 	if (host_attr > OSM_SA_ATTR_STR_UNKNOWN_VAL)
524 		host_attr = OSM_SA_ATTR_STR_UNKNOWN_VAL;
525 
526 	return ib_sa_attr_str[host_attr];
527 }
528 
529 const char *ib_get_trap_str(ib_net16_t trap_num)
530 {
531 	switch (cl_ntoh16(trap_num)) {
532 	case SM_GID_IN_SERVICE_TRAP:	/* 64 */
533 		return "GID in service";
534 	case SM_GID_OUT_OF_SERVICE_TRAP: /* 65 */
535 		return "GID out of service";
536 	case SM_MGID_CREATED_TRAP:	/* 66 */
537 		return "New mcast group created";
538 	case SM_MGID_DESTROYED_TRAP:	/* 67 */
539 		return "Mcast group deleted";
540 	case SM_UNPATH_TRAP:		/* 68 */
541 		return "UnPath, Path no longer valid";
542 	case SM_REPATH_TRAP:		/* 69 */
543 		return "RePath, Path recomputed";
544 	case SM_LINK_STATE_CHANGED_TRAP: /* 128 */
545 		return "Link state change";
546 	case SM_LINK_INTEGRITY_THRESHOLD_TRAP: /* 129 */
547 		return "Local Link integrity threshold reached";
548 	case SM_BUFFER_OVERRUN_THRESHOLD_TRAP: /* 130 */
549 		return "Excessive Buffer Overrun Threshold reached";
550 	case SM_WATCHDOG_TIMER_EXPIRED_TRAP:   /* 131 */
551 		return "Flow Control Update watchdog timer expired";
552 	case SM_LOCAL_CHANGES_TRAP:	/* 144 */
553 		return
554 		    "CapabilityMask, NodeDescription, Link [Width|Speed] Enabled, SM priority changed";
555 	case SM_SYS_IMG_GUID_CHANGED_TRAP: /* 145 */
556 		return "System Image GUID changed";
557 	case SM_BAD_MKEY_TRAP:		/* 256 */
558 		return "Bad M_Key";
559 	case SM_BAD_PKEY_TRAP:		/* 257 */
560 		return "Bad P_Key";
561 	case SM_BAD_QKEY_TRAP:		/* 258 */
562 		return "Bad Q_Key";
563 	case SM_BAD_SWITCH_PKEY_TRAP:	/* 259 */
564 		return "Bad P_Key (switch external port)";
565 	default:
566 		break;
567 	}
568 	return "Unknown";
569 }
570 
571 const ib_gid_t ib_zero_gid = { {0} };
572 
573 static ib_api_status_t dbg_do_line(IN char **pp_local, IN uint32_t buf_size,
574 				   IN const char *p_prefix_str,
575 				   IN const char *p_new_str,
576 				   IN uint32_t * p_total_len)
577 {
578 	char line[LINE_LENGTH];
579 	uint32_t len;
580 
581 	sprintf(line, "%s%s", p_prefix_str, p_new_str);
582 	len = (uint32_t) strlen(line);
583 	*p_total_len += len;
584 	if (*p_total_len + sizeof('\0') > buf_size)
585 		return IB_INSUFFICIENT_MEMORY;
586 
587 	strcpy(*pp_local, line);
588 	*pp_local += len;
589 	return IB_SUCCESS;
590 }
591 
592 static void dbg_get_capabilities_str(IN char *p_buf, IN uint32_t buf_size,
593 				     IN const char *p_prefix_str,
594 				     IN const ib_port_info_t * p_pi)
595 {
596 	uint32_t total_len = 0;
597 	char *p_local = p_buf;
598 
599 	strcpy(p_local, "Capability Mask:\n");
600 	p_local += strlen(p_local);
601 
602 	if (p_pi->capability_mask & IB_PORT_CAP_RESV0) {
603 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
604 				"IB_PORT_CAP_RESV0\n",
605 				&total_len) != IB_SUCCESS)
606 			return;
607 	}
608 	if (p_pi->capability_mask & IB_PORT_CAP_IS_SM) {
609 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
610 				"IB_PORT_CAP_IS_SM\n",
611 				&total_len) != IB_SUCCESS)
612 			return;
613 	}
614 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_NOTICE) {
615 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
616 				"IB_PORT_CAP_HAS_NOTICE\n",
617 				&total_len) != IB_SUCCESS)
618 			return;
619 	}
620 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_TRAP) {
621 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
622 				"IB_PORT_CAP_HAS_TRAP\n",
623 				&total_len) != IB_SUCCESS)
624 			return;
625 	}
626 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_IPD) {
627 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
628 				"IB_PORT_CAP_HAS_IPD\n",
629 				&total_len) != IB_SUCCESS)
630 			return;
631 	}
632 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_AUTO_MIG) {
633 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
634 				"IB_PORT_CAP_HAS_AUTO_MIG\n",
635 				&total_len) != IB_SUCCESS)
636 			return;
637 	}
638 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_SL_MAP) {
639 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
640 				"IB_PORT_CAP_HAS_SL_MAP\n",
641 				&total_len) != IB_SUCCESS)
642 			return;
643 	}
644 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_NV_MKEY) {
645 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
646 				"IB_PORT_CAP_HAS_NV_MKEY\n",
647 				&total_len) != IB_SUCCESS)
648 			return;
649 	}
650 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_NV_PKEY) {
651 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
652 				"IB_PORT_CAP_HAS_NV_PKEY\n",
653 				&total_len) != IB_SUCCESS)
654 			return;
655 	}
656 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_LED_INFO) {
657 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
658 				"IB_PORT_CAP_HAS_LED_INFO\n",
659 				&total_len) != IB_SUCCESS)
660 			return;
661 	}
662 	if (p_pi->capability_mask & IB_PORT_CAP_SM_DISAB) {
663 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
664 				"IB_PORT_CAP_SM_DISAB\n",
665 				&total_len) != IB_SUCCESS)
666 			return;
667 	}
668 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_SYS_IMG_GUID) {
669 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
670 				"IB_PORT_CAP_HAS_SYS_IMG_GUID\n",
671 				&total_len) != IB_SUCCESS)
672 			return;
673 	}
674 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_PKEY_SW_EXT_PORT_TRAP) {
675 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
676 				"IB_PORT_CAP_PKEY_SW_EXT_PORT_TRAP\n",
677 				&total_len) != IB_SUCCESS)
678 			return;
679 	}
680 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_CABLE_INFO) {
681 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
682 				"IB_PORT_CAP_HAS_CABLE_INFO\n",
683 				&total_len) != IB_SUCCESS)
684 			return;
685 	}
686 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_EXT_SPEEDS) {
687 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
688 				"IB_PORT_CAP_HAS_EXT_SPEEDS\n",
689 				&total_len) != IB_SUCCESS)
690 			return;
691 	}
692 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_CAP_MASK2) {
693 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
694 				"IB_PORT_CAP_HAS_CAP_MASK2\n",
695 				&total_len) != IB_SUCCESS)
696 			return;
697 	}
698 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_COM_MGT) {
699 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
700 				"IB_PORT_CAP_HAS_COM_MGT\n",
701 				&total_len) != IB_SUCCESS)
702 			return;
703 	}
704 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_SNMP) {
705 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
706 				"IB_PORT_CAP_HAS_SNMP\n",
707 				&total_len) != IB_SUCCESS)
708 			return;
709 	}
710 	if (p_pi->capability_mask & IB_PORT_CAP_REINIT) {
711 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
712 				"IB_PORT_CAP_REINIT\n",
713 				&total_len) != IB_SUCCESS)
714 			return;
715 	}
716 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_DEV_MGT) {
717 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
718 				"IB_PORT_CAP_HAS_DEV_MGT\n",
719 				&total_len) != IB_SUCCESS)
720 			return;
721 	}
722 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_VEND_CLS) {
723 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
724 				"IB_PORT_CAP_HAS_VEND_CLS\n",
725 				&total_len) != IB_SUCCESS)
726 			return;
727 	}
728 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_DR_NTC) {
729 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
730 				"IB_PORT_CAP_HAS_DR_NTC\n",
731 				&total_len) != IB_SUCCESS)
732 			return;
733 	}
734 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_CAP_NTC) {
735 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
736 				"IB_PORT_CAP_HAS_CAP_NTC\n",
737 				&total_len) != IB_SUCCESS)
738 			return;
739 	}
740 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_BM) {
741 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
742 				"IB_PORT_CAP_HAS_BM\n",
743 				&total_len) != IB_SUCCESS)
744 			return;
745 	}
746 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_LINK_RT_LATENCY) {
747 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
748 				"IB_PORT_CAP_HAS_LINK_RT_LATENCY\n",
749 				&total_len) != IB_SUCCESS)
750 			return;
751 	}
752 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_CLIENT_REREG) {
753 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
754 				"IB_PORT_CAP_HAS_CLIENT_REREG\n",
755 				&total_len) != IB_SUCCESS)
756 			return;
757 	}
758 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_OTHER_LOCAL_CHANGES_NTC) {
759 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
760 				"IB_PORT_CAP_HAS_OTHER_LOCAL_CHANGES_NTC\n",
761 				&total_len) != IB_SUCCESS)
762 			return;
763 	}
764 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_LINK_SPEED_WIDTH_PAIRS_TBL) {
765 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
766 				"IB_PORT_CAP_HAS_LINK_SPEED_WIDTH_PAIRS_TBL\n",
767 				&total_len) != IB_SUCCESS)
768 			return;
769 	}
770 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_VEND_MADS) {
771 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
772 				"IB_PORT_CAP_HAS_VEND_MADS\n",
773 				&total_len) != IB_SUCCESS)
774 			return;
775 	}
776 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_MCAST_PKEY_TRAP_SUPPRESS) {
777 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
778 				"IB_PORT_CAP_HAS_MCAST_PKEY_TRAP_SUPPRESS\n",
779 				&total_len) != IB_SUCCESS)
780 			return;
781 	}
782 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_MCAST_FDB_TOP) {
783 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
784 				"IB_PORT_CAP_HAS_MCAST_FDB_TOP\n",
785 				&total_len) != IB_SUCCESS)
786 			return;
787 	}
788 	if (p_pi->capability_mask & IB_PORT_CAP_HAS_HIER_INFO) {
789 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
790 				"IB_PORT_CAP_HAS_HIER_INFO\n",
791 				&total_len) != IB_SUCCESS)
792 			return;
793 	}
794 }
795 
796 static void dbg_get_capabilities2_str(IN char *p_buf, IN uint32_t buf_size,
797 				      IN const char *p_prefix_str,
798 				      IN const ib_port_info_t * p_pi)
799 {
800 	uint32_t total_len = 0;
801 	char *p_local = p_buf;
802 
803 	strcpy(p_local, "Capability Mask2:\n");
804 	p_local += strlen(p_local);
805 
806 	if (p_pi->capability_mask2 & IB_PORT_CAP2_IS_SET_NODE_DESC_SUPPORTED) {
807 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
808 				"IB_PORT_CAP2_IS_SET_NODE_DESC_SUPPORTED\n",
809 				&total_len) != IB_SUCCESS)
810 			return;
811 	}
812 	if (p_pi->capability_mask2 & IB_PORT_CAP2_IS_PORT_INFO_EXT_SUPPORTED) {
813 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
814 				"IB_PORT_CAP2_IS_PORT_INFO_EXT_SUPPORTED\n",
815 				&total_len) != IB_SUCCESS)
816 			return;
817 	}
818 	if (p_pi->capability_mask2 & IB_PORT_CAP2_IS_VIRT_SUPPORTED) {
819 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
820 				"IB_PORT_CAP2_IS_VIRT_SUPPORTED\n",
821 				&total_len) != IB_SUCCESS)
822 			return;
823 	}
824 	if (p_pi->capability_mask2 & IB_PORT_CAP2_IS_SWITCH_PORT_STATE_TBL_SUPP) {
825 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
826 				"IB_PORT_CAP2_IS_SWITCH_PORT_STATE_TBL_SUPP\n",
827 				&total_len) != IB_SUCCESS)
828 			return;
829 	}
830 	if (p_pi->capability_mask2 & IB_PORT_CAP2_IS_LINK_WIDTH_2X_SUPPORTED) {
831 		if (dbg_do_line(&p_local, buf_size, p_prefix_str,
832 				"IB_PORT_CAP2_IS_LINK_WIDTH_2X_SUPPORTED\n",
833 				&total_len) != IB_SUCCESS)
834 			return;
835 	}
836 }
837 
838 static void osm_dump_port_info_to_buf(IN ib_net64_t node_guid,
839 				      IN ib_net64_t port_guid,
840 				      IN uint8_t port_num,
841 				      IN const ib_port_info_t * p_pi,
842 				      OUT char * buf)
843 {
844 	if (!buf || !p_pi)
845 		return;
846 	else {
847 		sprintf(buf,
848 			"PortInfo dump:\n"
849 			"\t\t\t\tport number..............%u\n"
850 			"\t\t\t\tnode_guid................0x%016" PRIx64 "\n"
851 			"\t\t\t\tport_guid................0x%016" PRIx64 "\n"
852 			"\t\t\t\tm_key....................0x%016" PRIx64 "\n"
853 			"\t\t\t\tsubnet_prefix............0x%016" PRIx64 "\n"
854 			"\t\t\t\tbase_lid.................%u\n"
855 			"\t\t\t\tmaster_sm_base_lid.......%u\n"
856 			"\t\t\t\tcapability_mask..........0x%X\n"
857 			"\t\t\t\tdiag_code................0x%X\n"
858 			"\t\t\t\tm_key_lease_period.......0x%X\n"
859 			"\t\t\t\tlocal_port_num...........%u\n"
860 			"\t\t\t\tlink_width_enabled.......0x%X\n"
861 			"\t\t\t\tlink_width_supported.....0x%X\n"
862 			"\t\t\t\tlink_width_active........0x%X\n"
863 			"\t\t\t\tlink_speed_supported.....0x%X\n"
864 			"\t\t\t\tport_state...............%s\n"
865 			"\t\t\t\tstate_info2..............0x%X\n"
866 			"\t\t\t\tm_key_protect_bits.......0x%X\n"
867 			"\t\t\t\tlmc......................0x%X\n"
868 			"\t\t\t\tlink_speed...............0x%X\n"
869 			"\t\t\t\tmtu_smsl.................0x%X\n"
870 			"\t\t\t\tvl_cap_init_type.........0x%X\n"
871 			"\t\t\t\tvl_high_limit............0x%X\n"
872 			"\t\t\t\tvl_arb_high_cap..........0x%X\n"
873 			"\t\t\t\tvl_arb_low_cap...........0x%X\n"
874 			"\t\t\t\tinit_rep_mtu_cap.........0x%X\n"
875 			"\t\t\t\tvl_stall_life............0x%X\n"
876 			"\t\t\t\tvl_enforce...............0x%X\n"
877 			"\t\t\t\tm_key_violations.........0x%X\n"
878 			"\t\t\t\tp_key_violations.........0x%X\n"
879 			"\t\t\t\tq_key_violations.........0x%X\n"
880 			"\t\t\t\tguid_cap.................0x%X\n"
881 			"\t\t\t\tclient_reregister........0x%X\n"
882 			"\t\t\t\tmcast_pkey_trap_suppr....0x%X\n"
883 			"\t\t\t\tsubnet_timeout...........0x%X\n"
884 			"\t\t\t\tresp_time_value..........0x%X\n"
885 			"\t\t\t\terror_threshold..........0x%X\n"
886 			"\t\t\t\tmax_credit_hint..........0x%X\n"
887 			"\t\t\t\tlink_round_trip_latency..0x%X\n"
888 			"\t\t\t\tcapability_mask2.........0x%X\n"
889 			"\t\t\t\tlink_speed_ext_active....0x%X\n"
890 			"\t\t\t\tlink_speed_ext_supported.0x%X\n"
891 			"\t\t\t\tlink_speed_ext_enabled...0x%X\n",
892 			port_num, cl_ntoh64(node_guid), cl_ntoh64(port_guid),
893 			cl_ntoh64(p_pi->m_key), cl_ntoh64(p_pi->subnet_prefix),
894 			cl_ntoh16(p_pi->base_lid),
895 			cl_ntoh16(p_pi->master_sm_base_lid),
896 			cl_ntoh32(p_pi->capability_mask),
897 			cl_ntoh16(p_pi->diag_code),
898 			cl_ntoh16(p_pi->m_key_lease_period),
899 			p_pi->local_port_num, p_pi->link_width_enabled,
900 			p_pi->link_width_supported, p_pi->link_width_active,
901 			ib_port_info_get_link_speed_sup(p_pi),
902 			ib_get_port_state_str(ib_port_info_get_port_state
903 					      (p_pi)), p_pi->state_info2,
904 			ib_port_info_get_mpb(p_pi), ib_port_info_get_lmc(p_pi),
905 			p_pi->link_speed, p_pi->mtu_smsl, p_pi->vl_cap,
906 			p_pi->vl_high_limit, p_pi->vl_arb_high_cap,
907 			p_pi->vl_arb_low_cap, p_pi->mtu_cap,
908 			p_pi->vl_stall_life, p_pi->vl_enforce,
909 			cl_ntoh16(p_pi->m_key_violations),
910 			cl_ntoh16(p_pi->p_key_violations),
911 			cl_ntoh16(p_pi->q_key_violations), p_pi->guid_cap,
912 			ib_port_info_get_client_rereg(p_pi),
913 			ib_port_info_get_mcast_pkey_trap_suppress(p_pi),
914 			ib_port_info_get_timeout(p_pi),
915 			ib_port_info_get_resp_time_value(p_pi),
916 			p_pi->error_threshold, cl_ntoh16(p_pi->max_credit_hint),
917 			cl_ntoh32(p_pi->link_rt_latency),
918 			cl_ntoh16(p_pi->capability_mask2),
919 			ib_port_info_get_link_speed_ext_active(p_pi),
920 			ib_port_info_get_link_speed_ext_sup(p_pi),
921 			p_pi->link_speed_ext_enabled);
922 	}
923 }
924 
925 void osm_dump_port_info(IN osm_log_t * p_log, IN ib_net64_t node_guid,
926 			IN ib_net64_t port_guid, IN uint8_t port_num,
927 			IN const ib_port_info_t * p_pi,
928 			IN osm_log_level_t log_level)
929 {
930 	if (osm_log_is_active(p_log, log_level)) {
931 		char buf[BUF_SIZE];
932 
933 		osm_dump_port_info_to_buf(node_guid, port_guid,
934 					  port_num, p_pi, buf);
935 
936 		osm_log(p_log, log_level, "%s", buf);
937 
938 		/*  show the capabilities masks */
939 		if (p_pi->capability_mask) {
940 			dbg_get_capabilities_str(buf, BUF_SIZE, "\t\t\t\t",
941 						 p_pi);
942 			osm_log(p_log, log_level, "%s", buf);
943 		}
944 		if ((p_pi->capability_mask & IB_PORT_CAP_HAS_CAP_MASK2) &&
945 		    p_pi->capability_mask2) {
946 			dbg_get_capabilities2_str(buf, BUF_SIZE, "\t\t\t\t",
947 						  p_pi);
948 			osm_log(p_log, log_level, "%s", buf);
949 		}
950 	}
951 }
952 
953 void osm_dump_port_info_v2(IN osm_log_t * p_log, IN ib_net64_t node_guid,
954 			   IN ib_net64_t port_guid, IN uint8_t port_num,
955 			   IN const ib_port_info_t * p_pi, IN const int file_id,
956 			   IN osm_log_level_t log_level)
957 {
958 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
959 		char buf[BUF_SIZE];
960 
961 		osm_dump_port_info_to_buf(node_guid, port_guid,
962 					  port_num, p_pi, buf);
963 
964 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
965 
966 		/*  show the capabilities masks */
967 		if (p_pi->capability_mask) {
968 			dbg_get_capabilities_str(buf, BUF_SIZE, "\t\t\t\t",
969 						 p_pi);
970 			osm_log_v2(p_log, log_level, file_id, "%s", buf);
971 		}
972 		if ((p_pi->capability_mask & IB_PORT_CAP_HAS_CAP_MASK2) &&
973 		    p_pi->capability_mask2) {
974 			dbg_get_capabilities2_str(buf, BUF_SIZE, "\t\t\t\t",
975 						  p_pi);
976 			osm_log(p_log, log_level, "%s", buf);
977 		}
978 	}
979 }
980 
981 static void osm_dump_mlnx_ext_port_info_to_buf(IN ib_net64_t node_guid,
982 					       IN ib_net64_t port_guid, IN uint8_t port_num,
983 					       IN const ib_mlnx_ext_port_info_t * p_pi,
984 					       OUT char * buf)
985 {
986 	if (!buf || !p_pi)
987 		return;
988 	else {
989 		sprintf(buf,
990                         "MLNX ExtendedPortInfo dump:\n"
991                         "\t\t\t\tport number..............%u\n"
992                         "\t\t\t\tnode_guid................0x%016" PRIx64 "\n"
993                         "\t\t\t\tport_guid................0x%016" PRIx64 "\n"
994                         "\t\t\t\tStateChangeEnable........0x%X\n"
995                         "\t\t\t\tLinkSpeedSupported.......0x%X\n"
996                         "\t\t\t\tLinkSpeedEnabled.........0x%X\n"
997                         "\t\t\t\tLinkSpeedActive..........0x%X\n",
998                         port_num, cl_ntoh64(node_guid), cl_ntoh64(port_guid),
999                         p_pi->state_change_enable, p_pi->link_speed_supported,
1000                         p_pi->link_speed_enabled, p_pi->link_speed_active);
1001 	}
1002 }
1003 
1004 void osm_dump_mlnx_ext_port_info(IN osm_log_t * p_log, IN ib_net64_t node_guid,
1005 				 IN ib_net64_t port_guid, IN uint8_t port_num,
1006 				 IN const ib_mlnx_ext_port_info_t * p_pi,
1007 				 IN osm_log_level_t log_level)
1008 {
1009 	if (osm_log_is_active(p_log, log_level)) {
1010 		char buf[BUF_SIZE];
1011 
1012 		osm_dump_mlnx_ext_port_info_to_buf(node_guid, port_guid,
1013 						   port_num, p_pi, buf);
1014 
1015 		osm_log(p_log, log_level, "%s", buf);
1016 	}
1017 }
1018 
1019 void osm_dump_mlnx_ext_port_info_v2(IN osm_log_t * p_log, IN ib_net64_t node_guid,
1020 				    IN ib_net64_t port_guid, IN uint8_t port_num,
1021 				    IN const ib_mlnx_ext_port_info_t * p_pi,
1022 				    IN const int file_id, IN osm_log_level_t log_level)
1023 {
1024         if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1025                 char buf[BUF_SIZE];
1026 
1027 		osm_dump_mlnx_ext_port_info_to_buf(node_guid, port_guid,
1028 						   port_num, p_pi, buf);
1029 
1030 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1031         }
1032 }
1033 
1034 static void osm_dump_portinfo_record_to_buf(IN const ib_portinfo_record_t * p_pir,
1035 					    OUT char * buf)
1036 {
1037 	if (!buf || !p_pir)
1038 		return;
1039 	else {
1040 		const ib_port_info_t *p_pi = &p_pir->port_info;
1041 
1042 		sprintf(buf,
1043 			"PortInfo Record dump:\n"
1044 			"\t\t\t\tRID\n"
1045 			"\t\t\t\tEndPortLid...............%u\n"
1046 			"\t\t\t\tPortNum..................%u\n"
1047 			"\t\t\t\tOptions..................0x%X\n"
1048 			"\t\t\t\tPortInfo dump:\n"
1049 			"\t\t\t\tm_key....................0x%016" PRIx64 "\n"
1050 			"\t\t\t\tsubnet_prefix............0x%016" PRIx64 "\n"
1051 			"\t\t\t\tbase_lid.................%u\n"
1052 			"\t\t\t\tmaster_sm_base_lid.......%u\n"
1053 			"\t\t\t\tcapability_mask..........0x%X\n"
1054 			"\t\t\t\tdiag_code................0x%X\n"
1055 			"\t\t\t\tm_key_lease_period.......0x%X\n"
1056 			"\t\t\t\tlocal_port_num...........%u\n"
1057 			"\t\t\t\tlink_width_enabled.......0x%X\n"
1058 			"\t\t\t\tlink_width_supported.....0x%X\n"
1059 			"\t\t\t\tlink_width_active........0x%X\n"
1060 			"\t\t\t\tlink_speed_supported.....0x%X\n"
1061 			"\t\t\t\tport_state...............%s\n"
1062 			"\t\t\t\tstate_info2..............0x%X\n"
1063 			"\t\t\t\tm_key_protect_bits.......0x%X\n"
1064 			"\t\t\t\tlmc......................0x%X\n"
1065 			"\t\t\t\tlink_speed...............0x%X\n"
1066 			"\t\t\t\tmtu_smsl.................0x%X\n"
1067 			"\t\t\t\tvl_cap_init_type.........0x%X\n"
1068 			"\t\t\t\tvl_high_limit............0x%X\n"
1069 			"\t\t\t\tvl_arb_high_cap..........0x%X\n"
1070 			"\t\t\t\tvl_arb_low_cap...........0x%X\n"
1071 			"\t\t\t\tinit_rep_mtu_cap.........0x%X\n"
1072 			"\t\t\t\tvl_stall_life............0x%X\n"
1073 			"\t\t\t\tvl_enforce...............0x%X\n"
1074 			"\t\t\t\tm_key_violations.........0x%X\n"
1075 			"\t\t\t\tp_key_violations.........0x%X\n"
1076 			"\t\t\t\tq_key_violations.........0x%X\n"
1077 			"\t\t\t\tguid_cap.................0x%X\n"
1078 			"\t\t\t\tclient_reregister........0x%X\n"
1079 			"\t\t\t\tmcast_pkey_trap_suppr....0x%X\n"
1080 			"\t\t\t\tsubnet_timeout...........0x%X\n"
1081 			"\t\t\t\tresp_time_value..........0x%X\n"
1082 			"\t\t\t\terror_threshold..........0x%X\n"
1083 			"\t\t\t\tmax_credit_hint..........0x%X\n"
1084 			"\t\t\t\tlink_round_trip_latency..0x%X\n"
1085 			"\t\t\t\tcapability_mask2.........0x%X\n"
1086 			"\t\t\t\tlink_speed_ext_active....0x%X\n"
1087 			"\t\t\t\tlink_speed_ext_supported.0x%X\n"
1088 			"\t\t\t\tlink_speed_ext_enabled...0x%X\n",
1089 			cl_ntoh16(p_pir->lid), p_pir->port_num, p_pir->options,
1090 			cl_ntoh64(p_pi->m_key), cl_ntoh64(p_pi->subnet_prefix),
1091 			cl_ntoh16(p_pi->base_lid),
1092 			cl_ntoh16(p_pi->master_sm_base_lid),
1093 			cl_ntoh32(p_pi->capability_mask),
1094 			cl_ntoh16(p_pi->diag_code),
1095 			cl_ntoh16(p_pi->m_key_lease_period),
1096 			p_pi->local_port_num, p_pi->link_width_enabled,
1097 			p_pi->link_width_supported, p_pi->link_width_active,
1098 			ib_port_info_get_link_speed_sup(p_pi),
1099 			ib_get_port_state_str(ib_port_info_get_port_state
1100 					      (p_pi)), p_pi->state_info2,
1101 			ib_port_info_get_mpb(p_pi), ib_port_info_get_lmc(p_pi),
1102 			p_pi->link_speed, p_pi->mtu_smsl, p_pi->vl_cap,
1103 			p_pi->vl_high_limit, p_pi->vl_arb_high_cap,
1104 			p_pi->vl_arb_low_cap, p_pi->mtu_cap,
1105 			p_pi->vl_stall_life, p_pi->vl_enforce,
1106 			cl_ntoh16(p_pi->m_key_violations),
1107 			cl_ntoh16(p_pi->p_key_violations),
1108 			cl_ntoh16(p_pi->q_key_violations), p_pi->guid_cap,
1109 			ib_port_info_get_client_rereg(p_pi),
1110 			ib_port_info_get_mcast_pkey_trap_suppress(p_pi),
1111 			ib_port_info_get_timeout(p_pi),
1112 			ib_port_info_get_resp_time_value(p_pi),
1113 			p_pi->error_threshold, cl_ntoh16(p_pi->max_credit_hint),
1114 			cl_ntoh32(p_pi->link_rt_latency),
1115 			cl_ntoh16(p_pi->capability_mask2),
1116 			ib_port_info_get_link_speed_ext_active(p_pi),
1117 			ib_port_info_get_link_speed_ext_sup(p_pi),
1118 			p_pi->link_speed_ext_enabled);
1119 	}
1120 }
1121 
1122 void osm_dump_portinfo_record(IN osm_log_t * p_log,
1123 			      IN const ib_portinfo_record_t * p_pir,
1124 			      IN osm_log_level_t log_level)
1125 {
1126 	if (osm_log_is_active(p_log, log_level)) {
1127 		char buf[BUF_SIZE];
1128 		const ib_port_info_t *p_pi = &p_pir->port_info;
1129 
1130 		osm_dump_portinfo_record_to_buf(p_pir, buf);
1131 
1132 		osm_log(p_log, log_level, "%s", buf);
1133 
1134 		/*  show the capabilities masks */
1135 		if (p_pi->capability_mask) {
1136 			dbg_get_capabilities_str(buf, BUF_SIZE, "\t\t\t\t",
1137 						 p_pi);
1138 			osm_log(p_log, log_level, "%s", buf);
1139 		}
1140 		if ((p_pi->capability_mask & IB_PORT_CAP_HAS_CAP_MASK2) &&
1141 		    p_pi->capability_mask2) {
1142 			dbg_get_capabilities2_str(buf, BUF_SIZE, "\t\t\t\t",
1143 						  p_pi);
1144 			osm_log(p_log, log_level, "%s", buf);
1145 		}
1146 	}
1147 }
1148 
1149 void osm_dump_portinfo_record_v2(IN osm_log_t * p_log,
1150 				 IN const ib_portinfo_record_t * p_pir,
1151 				 IN const int file_id,
1152 				 IN osm_log_level_t log_level)
1153 {
1154 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1155 		char buf[BUF_SIZE];
1156 		const ib_port_info_t *p_pi = &p_pir->port_info;
1157 
1158 		osm_dump_portinfo_record_to_buf(p_pir, buf);
1159 
1160 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1161 
1162 		/*  show the capabilities masks */
1163 		if (p_pi->capability_mask) {
1164 			dbg_get_capabilities_str(buf, BUF_SIZE, "\t\t\t\t",
1165 						 p_pi);
1166 			osm_log_v2(p_log, log_level, file_id, "%s", buf);
1167 		}
1168 		if ((p_pi->capability_mask & IB_PORT_CAP_HAS_CAP_MASK2) &&
1169 		    p_pi->capability_mask2) {
1170 			dbg_get_capabilities2_str(buf, BUF_SIZE, "\t\t\t\t",
1171 						  p_pi);
1172 			osm_log(p_log, log_level, "%s", buf);
1173 		}
1174 	}
1175 }
1176 
1177 static void osm_dump_guid_info_to_buf(IN ib_net64_t node_guid,
1178 				      IN ib_net64_t port_guid,
1179 				      IN uint8_t block_num,
1180 				      IN const ib_guid_info_t * p_gi,
1181 				      OUT char * buf)
1182 {
1183 	if (!buf || !p_gi)
1184 		return;
1185 	else {
1186 		sprintf(buf,
1187 			"GUIDInfo dump:\n"
1188 			"\t\t\t\tblock number............%u\n"
1189 			"\t\t\t\tnode_guid...............0x%016" PRIx64 "\n"
1190 			"\t\t\t\tport_guid...............0x%016" PRIx64 "\n"
1191 			"\t\t\t\tGUID 0..................0x%016" PRIx64 "\n"
1192 			"\t\t\t\tGUID 1..................0x%016" PRIx64 "\n"
1193 			"\t\t\t\tGUID 2..................0x%016" PRIx64 "\n"
1194 			"\t\t\t\tGUID 3..................0x%016" PRIx64 "\n"
1195 			"\t\t\t\tGUID 4..................0x%016" PRIx64 "\n"
1196 			"\t\t\t\tGUID 5..................0x%016" PRIx64 "\n"
1197 			"\t\t\t\tGUID 6..................0x%016" PRIx64 "\n"
1198 			"\t\t\t\tGUID 7..................0x%016" PRIx64 "\n",
1199 			block_num, cl_ntoh64(node_guid), cl_ntoh64(port_guid),
1200 			cl_ntoh64(p_gi->guid[0]), cl_ntoh64(p_gi->guid[1]),
1201 			cl_ntoh64(p_gi->guid[2]), cl_ntoh64(p_gi->guid[3]),
1202 			cl_ntoh64(p_gi->guid[4]), cl_ntoh64(p_gi->guid[5]),
1203 			cl_ntoh64(p_gi->guid[6]), cl_ntoh64(p_gi->guid[7]));
1204 	}
1205 }
1206 
1207 void osm_dump_guid_info(IN osm_log_t * p_log, IN ib_net64_t node_guid,
1208 			IN ib_net64_t port_guid, IN uint8_t block_num,
1209 			IN const ib_guid_info_t * p_gi,
1210 			IN osm_log_level_t log_level)
1211 {
1212 	if (osm_log_is_active(p_log, log_level)) {
1213 		char buf[BUF_SIZE];
1214 
1215 		osm_dump_guid_info_to_buf(node_guid, port_guid,
1216 					  block_num, p_gi, buf);
1217 
1218 		osm_log(p_log, log_level, "%s", buf);
1219 	}
1220 }
1221 
1222 void osm_dump_guid_info_v2(IN osm_log_t * p_log, IN ib_net64_t node_guid,
1223 			   IN ib_net64_t port_guid, IN uint8_t block_num,
1224 			   IN const ib_guid_info_t * p_gi,
1225 			   IN const int file_id,
1226 			   IN osm_log_level_t log_level)
1227 {
1228 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1229 		char buf[BUF_SIZE];
1230 
1231 		osm_dump_guid_info_to_buf(node_guid, port_guid,
1232 					  block_num, p_gi, buf);
1233 
1234 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1235 	}
1236 }
1237 
1238 static void osm_dump_guidinfo_record_to_buf(IN const ib_guidinfo_record_t * p_gir,
1239 					    OUT char * buf)
1240 {
1241 	if (!buf || !p_gir)
1242 		return;
1243 	else {
1244 		const ib_guid_info_t *p_gi = &p_gir->guid_info;
1245 
1246 		sprintf(buf,
1247 			"GUIDInfo Record dump:\n"
1248 			"\t\t\t\tRID\n"
1249 			"\t\t\t\tLid.....................%u\n"
1250 			"\t\t\t\tBlockNum................0x%X\n"
1251 			"\t\t\t\tReserved................0x%X\n"
1252 			"\t\t\t\tGUIDInfo dump:\n"
1253 			"\t\t\t\tReserved................0x%X\n"
1254 			"\t\t\t\tGUID 0..................0x%016" PRIx64 "\n"
1255 			"\t\t\t\tGUID 1..................0x%016" PRIx64 "\n"
1256 			"\t\t\t\tGUID 2..................0x%016" PRIx64 "\n"
1257 			"\t\t\t\tGUID 3..................0x%016" PRIx64 "\n"
1258 			"\t\t\t\tGUID 4..................0x%016" PRIx64 "\n"
1259 			"\t\t\t\tGUID 5..................0x%016" PRIx64 "\n"
1260 			"\t\t\t\tGUID 6..................0x%016" PRIx64 "\n"
1261 			"\t\t\t\tGUID 7..................0x%016" PRIx64 "\n",
1262 			cl_ntoh16(p_gir->lid), p_gir->block_num, p_gir->resv,
1263 			cl_ntoh32(p_gir->reserved),
1264 			cl_ntoh64(p_gi->guid[0]), cl_ntoh64(p_gi->guid[1]),
1265 			cl_ntoh64(p_gi->guid[2]), cl_ntoh64(p_gi->guid[3]),
1266 			cl_ntoh64(p_gi->guid[4]), cl_ntoh64(p_gi->guid[5]),
1267 			cl_ntoh64(p_gi->guid[6]), cl_ntoh64(p_gi->guid[7]));
1268 	}
1269 }
1270 void osm_dump_guidinfo_record(IN osm_log_t * p_log,
1271 			      IN const ib_guidinfo_record_t * p_gir,
1272 			      IN osm_log_level_t log_level)
1273 {
1274 	if (osm_log_is_active(p_log, log_level)) {
1275 		char buf[BUF_SIZE];
1276 
1277 		osm_dump_guidinfo_record_to_buf(p_gir, buf);
1278 
1279 		osm_log(p_log, log_level, "%s", buf);
1280 	}
1281 }
1282 
1283 void osm_dump_guidinfo_record_v2(IN osm_log_t * p_log,
1284 				 IN const ib_guidinfo_record_t * p_gir,
1285 				 IN const int file_id,
1286 				 IN osm_log_level_t log_level)
1287 {
1288 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1289 		char buf[BUF_SIZE];
1290 
1291 		osm_dump_guidinfo_record_to_buf(p_gir, buf);
1292 
1293 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1294 	}
1295 }
1296 
1297 static void osm_dump_node_info_to_buf(IN const ib_node_info_t * p_ni,
1298 				      OUT char * buf)
1299 {
1300 	if (!buf || !p_ni)
1301 		return;
1302 	else {
1303 		sprintf(buf,
1304 			"NodeInfo dump:\n"
1305 			"\t\t\t\tbase_version............0x%X\n"
1306 			"\t\t\t\tclass_version...........0x%X\n"
1307 			"\t\t\t\tnode_type...............%s\n"
1308 			"\t\t\t\tnum_ports...............%u\n"
1309 			"\t\t\t\tsys_guid................0x%016" PRIx64 "\n"
1310 			"\t\t\t\tnode_guid...............0x%016" PRIx64 "\n"
1311 			"\t\t\t\tport_guid...............0x%016" PRIx64 "\n"
1312 			"\t\t\t\tpartition_cap...........0x%X\n"
1313 			"\t\t\t\tdevice_id...............0x%X\n"
1314 			"\t\t\t\trevision................0x%X\n"
1315 			"\t\t\t\tport_num................%u\n"
1316 			"\t\t\t\tvendor_id...............0x%X\n",
1317 			p_ni->base_version, p_ni->class_version,
1318 			ib_get_node_type_str(p_ni->node_type), p_ni->num_ports,
1319 			cl_ntoh64(p_ni->sys_guid), cl_ntoh64(p_ni->node_guid),
1320 			cl_ntoh64(p_ni->port_guid),
1321 			cl_ntoh16(p_ni->partition_cap),
1322 			cl_ntoh16(p_ni->device_id), cl_ntoh32(p_ni->revision),
1323 			ib_node_info_get_local_port_num(p_ni),
1324 			cl_ntoh32(ib_node_info_get_vendor_id(p_ni)));
1325 	}
1326 }
1327 
1328 void osm_dump_node_info(IN osm_log_t * p_log, IN const ib_node_info_t * p_ni,
1329 			IN osm_log_level_t log_level)
1330 {
1331 	if (osm_log_is_active(p_log, log_level)) {
1332 		char buf[BUF_SIZE];
1333 
1334 		osm_dump_node_info_to_buf(p_ni, buf);
1335 
1336 		osm_log(p_log, log_level, "%s", buf);
1337 	}
1338 }
1339 
1340 void osm_dump_node_info_v2(IN osm_log_t * p_log, IN const ib_node_info_t * p_ni,
1341 			   IN const int file_id, IN osm_log_level_t log_level)
1342 {
1343 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1344 		char buf[BUF_SIZE];
1345 
1346 		osm_dump_node_info_to_buf(p_ni, buf);
1347 
1348 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1349 	}
1350 }
1351 
1352 static void osm_dump_node_record_to_buf(IN const ib_node_record_t * p_nr,
1353 					OUT char * buf)
1354 {
1355 	if (!buf || !p_nr)
1356 		return;
1357 	else {
1358 		char desc[sizeof(p_nr->node_desc.description) + 1];
1359 		const ib_node_info_t *p_ni = &p_nr->node_info;
1360 
1361 		memcpy(desc, p_nr->node_desc.description,
1362 		       sizeof(p_nr->node_desc.description));
1363 		desc[sizeof(desc) - 1] = '\0';
1364 		sprintf(buf,
1365 			"Node Record dump:\n"
1366 			"\t\t\t\tRID\n"
1367 			"\t\t\t\tLid.....................%u\n"
1368 			"\t\t\t\tReserved................0x%X\n"
1369 			"\t\t\t\tNodeInfo dump:\n"
1370 			"\t\t\t\tbase_version............0x%X\n"
1371 			"\t\t\t\tclass_version...........0x%X\n"
1372 			"\t\t\t\tnode_type...............%s\n"
1373 			"\t\t\t\tnum_ports...............%u\n"
1374 			"\t\t\t\tsys_guid................0x%016" PRIx64 "\n"
1375 			"\t\t\t\tnode_guid...............0x%016" PRIx64 "\n"
1376 			"\t\t\t\tport_guid...............0x%016" PRIx64 "\n"
1377 			"\t\t\t\tpartition_cap...........0x%X\n"
1378 			"\t\t\t\tdevice_id...............0x%X\n"
1379 			"\t\t\t\trevision................0x%X\n"
1380 			"\t\t\t\tport_num................%u\n"
1381 			"\t\t\t\tvendor_id...............0x%X\n"
1382 			"\t\t\t\tNodeDescription\n"
1383 			"\t\t\t\t%s\n",
1384 			cl_ntoh16(p_nr->lid), cl_ntoh16(p_nr->resv),
1385 			p_ni->base_version, p_ni->class_version,
1386 			ib_get_node_type_str(p_ni->node_type), p_ni->num_ports,
1387 			cl_ntoh64(p_ni->sys_guid), cl_ntoh64(p_ni->node_guid),
1388 			cl_ntoh64(p_ni->port_guid),
1389 			cl_ntoh16(p_ni->partition_cap),
1390 			cl_ntoh16(p_ni->device_id), cl_ntoh32(p_ni->revision),
1391 			ib_node_info_get_local_port_num(p_ni),
1392 			cl_ntoh32(ib_node_info_get_vendor_id(p_ni)), desc);
1393 	}
1394 }
1395 
1396 void osm_dump_node_record(IN osm_log_t * p_log,
1397 			  IN const ib_node_record_t * p_nr,
1398 			  IN osm_log_level_t log_level)
1399 {
1400 	if (osm_log_is_active(p_log, log_level)) {
1401 		char buf[BUF_SIZE];
1402 
1403 		osm_dump_node_record_to_buf(p_nr, buf);
1404 
1405 		osm_log(p_log, log_level, "%s", buf);
1406 	}
1407 }
1408 
1409 void osm_dump_node_record_v2(IN osm_log_t * p_log,
1410 			     IN const ib_node_record_t * p_nr,
1411 			     IN const int file_id,
1412 			     IN osm_log_level_t log_level)
1413 {
1414 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1415 		char buf[BUF_SIZE];
1416 
1417 		osm_dump_node_record_to_buf(p_nr, buf);
1418 
1419 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1420 	}
1421 }
1422 
1423 static void osm_dump_path_record_to_buf(IN const ib_path_rec_t * p_pr,
1424 					OUT char * buf)
1425 {
1426 	if (!buf || !p_pr)
1427 		return;
1428 	else {
1429 		char gid_str[INET6_ADDRSTRLEN];
1430 		char gid_str2[INET6_ADDRSTRLEN];
1431 
1432 		sprintf(buf,
1433 			"PathRecord dump:\n"
1434 			"\t\t\t\tservice_id..............0x%016" PRIx64 "\n"
1435 			"\t\t\t\tdgid....................%s\n"
1436 			"\t\t\t\tsgid....................%s\n"
1437 			"\t\t\t\tdlid....................%u\n"
1438 			"\t\t\t\tslid....................%u\n"
1439 			"\t\t\t\thop_flow_raw............0x%X\n"
1440 			"\t\t\t\ttclass..................0x%X\n"
1441 			"\t\t\t\tnum_path_revers.........0x%X\n"
1442 			"\t\t\t\tpkey....................0x%X\n"
1443 			"\t\t\t\tqos_class...............0x%X\n"
1444 			"\t\t\t\tsl......................0x%X\n"
1445 			"\t\t\t\tmtu.....................0x%X\n"
1446 			"\t\t\t\trate....................0x%X\n"
1447 			"\t\t\t\tpkt_life................0x%X\n"
1448 			"\t\t\t\tpreference..............0x%X\n"
1449 			"\t\t\t\tresv2...................0x%02X%02X%02X%02X%02X%02X\n",
1450 			cl_ntoh64(p_pr->service_id),
1451 			inet_ntop(AF_INET6, p_pr->dgid.raw, gid_str,
1452 				  sizeof gid_str),
1453 			inet_ntop(AF_INET6, p_pr->sgid.raw, gid_str2,
1454 				  sizeof gid_str2),
1455 			cl_ntoh16(p_pr->dlid), cl_ntoh16(p_pr->slid),
1456 			cl_ntoh32(p_pr->hop_flow_raw), p_pr->tclass,
1457 			p_pr->num_path, cl_ntoh16(p_pr->pkey),
1458 			ib_path_rec_qos_class(p_pr), ib_path_rec_sl(p_pr),
1459 			p_pr->mtu, p_pr->rate, p_pr->pkt_life, p_pr->preference,
1460 			p_pr->resv2[0], p_pr->resv2[1], p_pr->resv2[2],
1461 			p_pr->resv2[3], p_pr->resv2[4], p_pr->resv2[5]);
1462 	}
1463 }
1464 
1465 void osm_dump_path_record(IN osm_log_t * p_log, IN const ib_path_rec_t * p_pr,
1466 			  IN osm_log_level_t log_level)
1467 {
1468 	if (osm_log_is_active(p_log, log_level)) {
1469 		char buf[BUF_SIZE];
1470 
1471 		osm_dump_path_record_to_buf(p_pr, buf);
1472 
1473 		osm_log(p_log, log_level, "%s", buf);
1474 	}
1475 }
1476 
1477 void osm_dump_path_record_v2(IN osm_log_t * p_log, IN const ib_path_rec_t * p_pr,
1478 			     IN const int file_id, IN osm_log_level_t log_level)
1479 {
1480 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1481 		char buf[BUF_SIZE];
1482 
1483 		osm_dump_path_record_to_buf(p_pr, buf);
1484 
1485 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1486 	}
1487 }
1488 
1489 static void osm_dump_multipath_record_to_buf(IN const ib_multipath_rec_t * p_mpr,
1490 					     OUT char * buf)
1491 {
1492 	if (!buf || !p_mpr)
1493 		return;
1494 	else {
1495 		char gid_str[INET6_ADDRSTRLEN];
1496 		char buf_line[1024];
1497 		ib_gid_t const *p_gid = p_mpr->gids;
1498 		int i, n = 0;
1499 
1500 		if (p_mpr->sgid_count) {
1501 			for (i = 0; i < p_mpr->sgid_count; i++) {
1502 				n += sprintf(buf_line + n,
1503 					     "\t\t\t\tsgid%02d.................."
1504 					     "%s\n", i + 1,
1505 					     inet_ntop(AF_INET6, p_gid->raw,
1506 						       gid_str,
1507 						       sizeof gid_str));
1508 				p_gid++;
1509 			}
1510 		}
1511 		if (p_mpr->dgid_count) {
1512 			for (i = 0; i < p_mpr->dgid_count; i++) {
1513 				n += sprintf(buf_line + n,
1514 					     "\t\t\t\tdgid%02d.................."
1515 					     "%s\n", i + 1,
1516 					     inet_ntop(AF_INET6, p_gid->raw,
1517 						       gid_str,
1518 						       sizeof gid_str));
1519 				p_gid++;
1520 			}
1521 		}
1522 		sprintf(buf,
1523 			"MultiPath Record dump:\n"
1524 			"\t\t\t\thop_flow_raw............0x%X\n"
1525 			"\t\t\t\ttclass..................0x%X\n"
1526 			"\t\t\t\tnum_path_revers.........0x%X\n"
1527 			"\t\t\t\tpkey....................0x%X\n"
1528 			"\t\t\t\tqos_class...............0x%X\n"
1529 			"\t\t\t\tsl......................0x%X\n"
1530 			"\t\t\t\tmtu.....................0x%X\n"
1531 			"\t\t\t\trate....................0x%X\n"
1532 			"\t\t\t\tpkt_life................0x%X\n"
1533 			"\t\t\t\tindependence............0x%X\n"
1534 			"\t\t\t\tsgid_count..............0x%X\n"
1535 			"\t\t\t\tdgid_count..............0x%X\n"
1536 			"\t\t\t\tservice_id..............0x%016" PRIx64 "\n"
1537 			"%s\n",
1538 			cl_ntoh32(p_mpr->hop_flow_raw), p_mpr->tclass,
1539 			p_mpr->num_path, cl_ntoh16(p_mpr->pkey),
1540 			ib_multipath_rec_qos_class(p_mpr),
1541 			ib_multipath_rec_sl(p_mpr), p_mpr->mtu, p_mpr->rate,
1542 			p_mpr->pkt_life, p_mpr->independence,
1543 			p_mpr->sgid_count, p_mpr->dgid_count,
1544 			cl_ntoh64(ib_multipath_rec_service_id(p_mpr)),
1545 			buf_line);
1546 	}
1547 }
1548 
1549 void osm_dump_multipath_record(IN osm_log_t * p_log,
1550 			       IN const ib_multipath_rec_t * p_mpr,
1551 			       IN osm_log_level_t log_level)
1552 {
1553 	if (osm_log_is_active(p_log, log_level)) {
1554 		char buf[BUF_SIZE];
1555 
1556 		osm_dump_multipath_record_to_buf(p_mpr, buf);
1557 
1558 		osm_log(p_log, log_level, "%s", buf);
1559 	}
1560 }
1561 
1562 void osm_dump_multipath_record_v2(IN osm_log_t * p_log,
1563 				  IN const ib_multipath_rec_t * p_mpr,
1564 				  IN const int file_id,
1565 				  IN osm_log_level_t log_level)
1566 {
1567 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1568 		char buf[BUF_SIZE];
1569 
1570 		osm_dump_multipath_record_to_buf(p_mpr, buf);
1571 
1572 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1573 	}
1574 }
1575 
1576 static void osm_dump_mc_record_to_buf(IN const ib_member_rec_t * p_mcmr,
1577 				      OUT char * buf)
1578 {
1579 	if(!buf || !p_mcmr)
1580 		return;
1581 	else {
1582 		char gid_str[INET6_ADDRSTRLEN];
1583 		char gid_str2[INET6_ADDRSTRLEN];
1584 
1585 		sprintf(buf,
1586 			"MCMember Record dump:\n"
1587 			"\t\t\t\tMGID....................%s\n"
1588 			"\t\t\t\tPortGid.................%s\n"
1589 			"\t\t\t\tqkey....................0x%X\n"
1590 			"\t\t\t\tmlid....................0x%X\n"
1591 			"\t\t\t\tmtu.....................0x%X\n"
1592 			"\t\t\t\tTClass..................0x%X\n"
1593 			"\t\t\t\tpkey....................0x%X\n"
1594 			"\t\t\t\trate....................0x%X\n"
1595 			"\t\t\t\tpkt_life................0x%X\n"
1596 			"\t\t\t\tSLFlowLabelHopLimit.....0x%X\n"
1597 			"\t\t\t\tScopeState..............0x%X\n"
1598 			"\t\t\t\tProxyJoin...............0x%X\n",
1599 			inet_ntop(AF_INET6, p_mcmr->mgid.raw, gid_str,
1600 				  sizeof gid_str),
1601 			inet_ntop(AF_INET6, p_mcmr->port_gid.raw, gid_str2,
1602 				  sizeof gid_str2),
1603 			cl_ntoh32(p_mcmr->qkey), cl_ntoh16(p_mcmr->mlid),
1604 			p_mcmr->mtu, p_mcmr->tclass, cl_ntoh16(p_mcmr->pkey),
1605 			p_mcmr->rate, p_mcmr->pkt_life,
1606 			cl_ntoh32(p_mcmr->sl_flow_hop),
1607 			p_mcmr->scope_state, p_mcmr->proxy_join);
1608 	}
1609 }
1610 
1611 void osm_dump_mc_record(IN osm_log_t * p_log, IN const ib_member_rec_t * p_mcmr,
1612 			IN osm_log_level_t log_level)
1613 {
1614 	if (osm_log_is_active(p_log, log_level)) {
1615 		char buf[BUF_SIZE];
1616 
1617 		osm_dump_mc_record_to_buf(p_mcmr, buf);
1618 
1619 		osm_log(p_log, log_level, "%s", buf);
1620 	}
1621 }
1622 
1623 void osm_dump_mc_record_v2(IN osm_log_t * p_log, IN const ib_member_rec_t * p_mcmr,
1624 			   IN const int file_id, IN osm_log_level_t log_level)
1625 {
1626 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1627 		char buf[BUF_SIZE];
1628 
1629 		osm_dump_mc_record_to_buf(p_mcmr, buf);
1630 
1631 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1632 	}
1633 }
1634 
1635 static void osm_dump_service_record_to_buf(IN const ib_service_record_t * p_sr,
1636 					   OUT char * buf)
1637 {
1638 	if (!buf || !p_sr)
1639 		return;
1640 	else {
1641 		char gid_str[INET6_ADDRSTRLEN];
1642 		char buf_service_key[35];
1643 		char buf_service_name[65];
1644 
1645 		sprintf(buf_service_key,
1646 			"0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
1647 			p_sr->service_key[0], p_sr->service_key[1],
1648 			p_sr->service_key[2], p_sr->service_key[3],
1649 			p_sr->service_key[4], p_sr->service_key[5],
1650 			p_sr->service_key[6], p_sr->service_key[7],
1651 			p_sr->service_key[8], p_sr->service_key[9],
1652 			p_sr->service_key[10], p_sr->service_key[11],
1653 			p_sr->service_key[12], p_sr->service_key[13],
1654 			p_sr->service_key[14], p_sr->service_key[15]);
1655 		strncpy(buf_service_name, (char *)p_sr->service_name, 64);
1656 		buf_service_name[64] = '\0';
1657 
1658 		sprintf(buf,
1659 			"Service Record dump:\n"
1660 			"\t\t\t\tServiceID...............0x%016" PRIx64 "\n"
1661 			"\t\t\t\tServiceGID..............%s\n"
1662 			"\t\t\t\tServiceP_Key............0x%X\n"
1663 			"\t\t\t\tServiceLease............0x%X\n"
1664 			"\t\t\t\tServiceKey..............%s\n"
1665 			"\t\t\t\tServiceName.............%s\n"
1666 			"\t\t\t\tServiceData8.1..........0x%X\n"
1667 			"\t\t\t\tServiceData8.2..........0x%X\n"
1668 			"\t\t\t\tServiceData8.3..........0x%X\n"
1669 			"\t\t\t\tServiceData8.4..........0x%X\n"
1670 			"\t\t\t\tServiceData8.5..........0x%X\n"
1671 			"\t\t\t\tServiceData8.6..........0x%X\n"
1672 			"\t\t\t\tServiceData8.7..........0x%X\n"
1673 			"\t\t\t\tServiceData8.8..........0x%X\n"
1674 			"\t\t\t\tServiceData8.9..........0x%X\n"
1675 			"\t\t\t\tServiceData8.10.........0x%X\n"
1676 			"\t\t\t\tServiceData8.11.........0x%X\n"
1677 			"\t\t\t\tServiceData8.12.........0x%X\n"
1678 			"\t\t\t\tServiceData8.13.........0x%X\n"
1679 			"\t\t\t\tServiceData8.14.........0x%X\n"
1680 			"\t\t\t\tServiceData8.15.........0x%X\n"
1681 			"\t\t\t\tServiceData8.16.........0x%X\n"
1682 			"\t\t\t\tServiceData16.1.........0x%X\n"
1683 			"\t\t\t\tServiceData16.2.........0x%X\n"
1684 			"\t\t\t\tServiceData16.3.........0x%X\n"
1685 			"\t\t\t\tServiceData16.4.........0x%X\n"
1686 			"\t\t\t\tServiceData16.5.........0x%X\n"
1687 			"\t\t\t\tServiceData16.6.........0x%X\n"
1688 			"\t\t\t\tServiceData16.7.........0x%X\n"
1689 			"\t\t\t\tServiceData16.8.........0x%X\n"
1690 			"\t\t\t\tServiceData32.1.........0x%X\n"
1691 			"\t\t\t\tServiceData32.2.........0x%X\n"
1692 			"\t\t\t\tServiceData32.3.........0x%X\n"
1693 			"\t\t\t\tServiceData32.4.........0x%X\n"
1694 			"\t\t\t\tServiceData64.1.........0x%016" PRIx64 "\n"
1695 			"\t\t\t\tServiceData64.2.........0x%016" PRIx64 "\n",
1696 			cl_ntoh64(p_sr->service_id),
1697 			inet_ntop(AF_INET6, p_sr->service_gid.raw, gid_str,
1698 				  sizeof gid_str),
1699 			cl_ntoh16(p_sr->service_pkey),
1700 			cl_ntoh32(p_sr->service_lease),
1701 			buf_service_key, buf_service_name,
1702 			p_sr->service_data8[0], p_sr->service_data8[1],
1703 			p_sr->service_data8[2], p_sr->service_data8[3],
1704 			p_sr->service_data8[4], p_sr->service_data8[5],
1705 			p_sr->service_data8[6], p_sr->service_data8[7],
1706 			p_sr->service_data8[8], p_sr->service_data8[9],
1707 			p_sr->service_data8[10], p_sr->service_data8[11],
1708 			p_sr->service_data8[12], p_sr->service_data8[13],
1709 			p_sr->service_data8[14], p_sr->service_data8[15],
1710 			cl_ntoh16(p_sr->service_data16[0]),
1711 			cl_ntoh16(p_sr->service_data16[1]),
1712 			cl_ntoh16(p_sr->service_data16[2]),
1713 			cl_ntoh16(p_sr->service_data16[3]),
1714 			cl_ntoh16(p_sr->service_data16[4]),
1715 			cl_ntoh16(p_sr->service_data16[5]),
1716 			cl_ntoh16(p_sr->service_data16[6]),
1717 			cl_ntoh16(p_sr->service_data16[7]),
1718 			cl_ntoh32(p_sr->service_data32[0]),
1719 			cl_ntoh32(p_sr->service_data32[1]),
1720 			cl_ntoh32(p_sr->service_data32[2]),
1721 			cl_ntoh32(p_sr->service_data32[3]),
1722 			cl_ntoh64(p_sr->service_data64[0]),
1723 			cl_ntoh64(p_sr->service_data64[1]));
1724 	}
1725 }
1726 
1727 void osm_dump_service_record(IN osm_log_t * p_log,
1728 			     IN const ib_service_record_t * p_sr,
1729 			     IN osm_log_level_t log_level)
1730 {
1731 	if (osm_log_is_active(p_log, log_level)) {
1732 		char buf[BUF_SIZE];
1733 
1734 		osm_dump_service_record_to_buf(p_sr, buf);
1735 
1736 		osm_log(p_log, log_level, "%s", buf);
1737 	}
1738 }
1739 
1740 void osm_dump_service_record_v2(IN osm_log_t * p_log,
1741 				IN const ib_service_record_t * p_sr,
1742 				IN const int file_id,
1743 				IN osm_log_level_t log_level)
1744 {
1745 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1746 		char buf[BUF_SIZE];
1747 
1748 		osm_dump_service_record_to_buf(p_sr, buf);
1749 
1750 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1751 	}
1752 }
1753 
1754 static void osm_dump_inform_info_to_buf_generic(IN const ib_inform_info_t * p_ii,
1755 						OUT char * buf)
1756 {
1757 	if (!buf || !p_ii)
1758 		return;
1759 	else {
1760 		uint32_t qpn;
1761 		uint8_t resp_time_val;
1762 		char gid_str[INET6_ADDRSTRLEN];
1763 
1764 		ib_inform_info_get_qpn_resp_time(p_ii->g_or_v.generic.
1765 						 qpn_resp_time_val, &qpn,
1766 						 &resp_time_val);
1767 		sprintf(buf,
1768 			"InformInfo dump:\n"
1769 			"\t\t\t\tgid.....................%s\n"
1770 			"\t\t\t\tlid_range_begin.........%u\n"
1771 			"\t\t\t\tlid_range_end...........%u\n"
1772 			"\t\t\t\tis_generic..............0x%X\n"
1773 			"\t\t\t\tsubscribe...............0x%X\n"
1774 			"\t\t\t\ttrap_type...............0x%X\n"
1775 			"\t\t\t\ttrap_num................%u\n"
1776 			"\t\t\t\tqpn.....................0x%06X\n"
1777 			"\t\t\t\tresp_time_val...........0x%X\n"
1778 			"\t\t\t\tnode_type...............0x%06X\n" "",
1779 			inet_ntop(AF_INET6, p_ii->gid.raw, gid_str,
1780 				  sizeof gid_str),
1781 			cl_ntoh16(p_ii->lid_range_begin),
1782 			cl_ntoh16(p_ii->lid_range_end),
1783 			p_ii->is_generic, p_ii->subscribe,
1784 			cl_ntoh16(p_ii->trap_type),
1785 			cl_ntoh16(p_ii->g_or_v.generic.trap_num),
1786 			cl_ntoh32(qpn), resp_time_val,
1787 			cl_ntoh32(ib_inform_info_get_prod_type(p_ii)));
1788 	}
1789 }
1790 
1791 static void osm_dump_inform_info_to_buf(IN const ib_inform_info_t * p_ii,
1792 					OUT char * buf)
1793 {
1794 	if (!buf || !p_ii)
1795 		return;
1796 	else {
1797 		uint32_t qpn;
1798 		uint8_t resp_time_val;
1799 		char gid_str[INET6_ADDRSTRLEN];
1800 
1801 		ib_inform_info_get_qpn_resp_time(p_ii->g_or_v.generic.
1802 						 qpn_resp_time_val, &qpn,
1803 						 &resp_time_val);
1804 		sprintf(buf,
1805 			"InformInfo dump:\n"
1806 			"\t\t\t\tgid.....................%s\n"
1807 			"\t\t\t\tlid_range_begin.........%u\n"
1808 			"\t\t\t\tlid_range_end...........%u\n"
1809 			"\t\t\t\tis_generic..............0x%X\n"
1810 			"\t\t\t\tsubscribe...............0x%X\n"
1811 			"\t\t\t\ttrap_type...............0x%X\n"
1812 			"\t\t\t\tdev_id..................0x%X\n"
1813 			"\t\t\t\tqpn.....................0x%06X\n"
1814 			"\t\t\t\tresp_time_val...........0x%X\n"
1815 			"\t\t\t\tvendor_id...............0x%06X\n" "",
1816 			inet_ntop(AF_INET6, p_ii->gid.raw, gid_str,
1817 				  sizeof gid_str),
1818 			cl_ntoh16(p_ii->lid_range_begin),
1819 			cl_ntoh16(p_ii->lid_range_end),
1820 			p_ii->is_generic, p_ii->subscribe,
1821 			cl_ntoh16(p_ii->trap_type),
1822 			cl_ntoh16(p_ii->g_or_v.vend.dev_id),
1823 			cl_ntoh32(qpn), resp_time_val,
1824 			cl_ntoh32(ib_inform_info_get_prod_type(p_ii)));
1825 	}
1826 }
1827 
1828 void osm_dump_inform_info(IN osm_log_t * p_log,
1829 			  IN const ib_inform_info_t * p_ii,
1830 			  IN osm_log_level_t log_level)
1831 {
1832 	if (osm_log_is_active(p_log, log_level)) {
1833 		char buf[BUF_SIZE];
1834 
1835 		if (p_ii->is_generic)
1836 			osm_dump_inform_info_to_buf_generic(p_ii, buf);
1837 		else
1838 			osm_dump_inform_info_to_buf(p_ii, buf);
1839 
1840 		osm_log(p_log, log_level, "%s", buf);
1841 	}
1842 }
1843 
1844 void osm_dump_inform_info_v2(IN osm_log_t * p_log,
1845 			     IN const ib_inform_info_t * p_ii,
1846 			     IN const int file_id,
1847 			     IN osm_log_level_t log_level)
1848 {
1849 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1850 		char buf[BUF_SIZE];
1851 
1852 		if (p_ii->is_generic)
1853 			osm_dump_inform_info_to_buf_generic(p_ii, buf);
1854 		else
1855 			osm_dump_inform_info_to_buf(p_ii, buf);
1856 
1857 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1858 	}
1859 }
1860 
1861 static void osm_dump_inform_info_record_to_buf_generic(IN const ib_inform_info_record_t * p_iir,
1862 						       OUT char * buf)
1863 {
1864 	if (!buf || p_iir)
1865 		return;
1866 	else {
1867 		char gid_str[INET6_ADDRSTRLEN];
1868 		char gid_str2[INET6_ADDRSTRLEN];
1869 		uint32_t qpn;
1870 		uint8_t resp_time_val;
1871 
1872 		ib_inform_info_get_qpn_resp_time(p_iir->inform_info.g_or_v.
1873 						 generic.qpn_resp_time_val,
1874 						 &qpn, &resp_time_val);
1875 		sprintf(buf,
1876 			"InformInfo Record dump:\n"
1877 			"\t\t\t\tRID\n"
1878 			"\t\t\t\tSubscriberGID...........%s\n"
1879 			"\t\t\t\tSubscriberEnum..........0x%X\n"
1880 			"\t\t\t\tInformInfo dump:\n"
1881 			"\t\t\t\tgid.....................%s\n"
1882 			"\t\t\t\tlid_range_begin.........%u\n"
1883 			"\t\t\t\tlid_range_end...........%u\n"
1884 			"\t\t\t\tis_generic..............0x%X\n"
1885 			"\t\t\t\tsubscribe...............0x%X\n"
1886 			"\t\t\t\ttrap_type...............0x%X\n"
1887 			"\t\t\t\ttrap_num................%u\n"
1888 			"\t\t\t\tqpn.....................0x%06X\n"
1889 			"\t\t\t\tresp_time_val...........0x%X\n"
1890 			"\t\t\t\tnode_type...............0x%06X\n" "",
1891 			inet_ntop(AF_INET6, p_iir->subscriber_gid.raw,
1892 				  gid_str, sizeof gid_str),
1893 			cl_ntoh16(p_iir->subscriber_enum),
1894 			inet_ntop(AF_INET6, p_iir->inform_info.gid.raw,
1895 				  gid_str2, sizeof gid_str2),
1896 			cl_ntoh16(p_iir->inform_info.lid_range_begin),
1897 			cl_ntoh16(p_iir->inform_info.lid_range_end),
1898 			p_iir->inform_info.is_generic,
1899 			p_iir->inform_info.subscribe,
1900 			cl_ntoh16(p_iir->inform_info.trap_type),
1901 			cl_ntoh16(p_iir->inform_info.g_or_v.generic.
1902 				  trap_num), cl_ntoh32(qpn),
1903 			resp_time_val,
1904 			cl_ntoh32(ib_inform_info_get_prod_type
1905 				  (&p_iir->inform_info)));
1906 	}
1907 }
1908 
1909 static void osm_dump_inform_info_record_to_buf(IN const ib_inform_info_record_t * p_iir,
1910 					       OUT char * buf)
1911 {
1912 	if(!buf || p_iir)
1913 		return;
1914 	else {
1915 		char gid_str[INET6_ADDRSTRLEN];
1916 		char gid_str2[INET6_ADDRSTRLEN];
1917 		uint32_t qpn;
1918 		uint8_t resp_time_val;
1919 
1920 		ib_inform_info_get_qpn_resp_time(p_iir->inform_info.g_or_v.
1921 						 generic.qpn_resp_time_val,
1922 						 &qpn, &resp_time_val);
1923 		sprintf(buf,
1924 			"InformInfo Record dump:\n"
1925 			"\t\t\t\tRID\n"
1926 			"\t\t\t\tSubscriberGID...........%s\n"
1927 			"\t\t\t\tSubscriberEnum..........0x%X\n"
1928 			"\t\t\t\tInformInfo dump:\n"
1929 			"\t\t\t\tgid.....................%s\n"
1930 			"\t\t\t\tlid_range_begin.........%u\n"
1931 			"\t\t\t\tlid_range_end...........%u\n"
1932 			"\t\t\t\tis_generic..............0x%X\n"
1933 			"\t\t\t\tsubscribe...............0x%X\n"
1934 			"\t\t\t\ttrap_type...............0x%X\n"
1935 			"\t\t\t\tdev_id..................0x%X\n"
1936 			"\t\t\t\tqpn.....................0x%06X\n"
1937 			"\t\t\t\tresp_time_val...........0x%X\n"
1938 			"\t\t\t\tvendor_id...............0x%06X\n" "",
1939 			inet_ntop(AF_INET6, p_iir->subscriber_gid.raw,
1940 				  gid_str, sizeof gid_str),
1941 			cl_ntoh16(p_iir->subscriber_enum),
1942 			inet_ntop(AF_INET6, p_iir->inform_info.gid.raw,
1943 				  gid_str2, sizeof gid_str2),
1944 			cl_ntoh16(p_iir->inform_info.lid_range_begin),
1945 			cl_ntoh16(p_iir->inform_info.lid_range_end),
1946 			p_iir->inform_info.is_generic,
1947 			p_iir->inform_info.subscribe,
1948 			cl_ntoh16(p_iir->inform_info.trap_type),
1949 			cl_ntoh16(p_iir->inform_info.g_or_v.vend.
1950 				  dev_id), cl_ntoh32(qpn),
1951 			resp_time_val,
1952 			cl_ntoh32(ib_inform_info_get_prod_type
1953 				  (&p_iir->inform_info)));
1954 	}
1955 }
1956 
1957 void osm_dump_inform_info_record(IN osm_log_t * p_log,
1958 				 IN const ib_inform_info_record_t * p_iir,
1959 				 IN osm_log_level_t log_level)
1960 {
1961 	if (osm_log_is_active(p_log, log_level)) {
1962 		char buf[BUF_SIZE];
1963 
1964 		if (p_iir->inform_info.is_generic)
1965 			osm_dump_inform_info_record_to_buf_generic(p_iir, buf);
1966 		else
1967 			osm_dump_inform_info_record_to_buf(p_iir, buf);
1968 
1969 		osm_log(p_log, log_level, "%s", buf);
1970 	}
1971 }
1972 
1973 void osm_dump_inform_info_record_v2(IN osm_log_t * p_log,
1974 				    IN const ib_inform_info_record_t * p_iir,
1975 				    IN const int file_id,
1976 				    IN osm_log_level_t log_level)
1977 {
1978 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
1979 		char buf[BUF_SIZE];
1980 
1981 		if (p_iir->inform_info.is_generic)
1982 			osm_dump_inform_info_record_to_buf_generic(p_iir, buf);
1983 		else
1984 			osm_dump_inform_info_record_to_buf(p_iir, buf);
1985 
1986 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
1987 	}
1988 }
1989 
1990 static void osm_dump_link_record_to_buf(IN const ib_link_record_t * p_lr,
1991 					OUT char * buf)
1992 {
1993 	if (!buf || !p_lr)
1994 		return;
1995 	else {
1996 		sprintf(buf,
1997 			"Link Record dump:\n"
1998 			"\t\t\t\tfrom_lid................%u\n"
1999 			"\t\t\t\tfrom_port_num...........%u\n"
2000 			"\t\t\t\tto_port_num.............%u\n"
2001 			"\t\t\t\tto_lid..................%u\n",
2002 			cl_ntoh16(p_lr->from_lid),
2003 			p_lr->from_port_num,
2004 			p_lr->to_port_num, cl_ntoh16(p_lr->to_lid));
2005 	}
2006 }
2007 
2008 void osm_dump_link_record(IN osm_log_t * p_log,
2009 			  IN const ib_link_record_t * p_lr,
2010 			  IN osm_log_level_t log_level)
2011 {
2012 	if (osm_log_is_active(p_log, log_level)) {
2013 		char buf[BUF_SIZE];
2014 
2015 		osm_dump_link_record_to_buf(p_lr, buf);
2016 
2017 		osm_log(p_log, log_level, "%s", buf);
2018 	}
2019 }
2020 
2021 void osm_dump_link_record_v2(IN osm_log_t * p_log,
2022 			     IN const ib_link_record_t * p_lr,
2023 			     IN const int file_id,
2024 			     IN osm_log_level_t log_level)
2025 {
2026 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2027 		char buf[BUF_SIZE];
2028 
2029 		osm_dump_link_record_to_buf(p_lr, buf);
2030 
2031 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
2032 	}
2033 }
2034 
2035 static void osm_dump_switch_info_to_buf(IN const ib_switch_info_t * p_si,
2036 					OUT char * buf)
2037 {
2038 	if (!buf || !p_si)
2039 		return;
2040 	else {
2041 		sprintf(buf,
2042 			"SwitchInfo dump:\n"
2043 			"\t\t\t\tlin_cap.................0x%X\n"
2044 			"\t\t\t\trand_cap................0x%X\n"
2045 			"\t\t\t\tmcast_cap...............0x%X\n"
2046 			"\t\t\t\tlin_top.................0x%X\n"
2047 			"\t\t\t\tdef_port................%u\n"
2048 			"\t\t\t\tdef_mcast_pri_port......%u\n"
2049 			"\t\t\t\tdef_mcast_not_port......%u\n"
2050 			"\t\t\t\tlife_state..............0x%X\n"
2051 			"\t\t\t\tlids_per_port...........%u\n"
2052 			"\t\t\t\tpartition_enf_cap.......0x%X\n"
2053 			"\t\t\t\tflags...................0x%X\n"
2054 			"\t\t\t\tmcast_top...............0x%X\n",
2055 			cl_ntoh16(p_si->lin_cap), cl_ntoh16(p_si->rand_cap),
2056 			cl_ntoh16(p_si->mcast_cap), cl_ntoh16(p_si->lin_top),
2057 			p_si->def_port, p_si->def_mcast_pri_port,
2058 			p_si->def_mcast_not_port, p_si->life_state,
2059 			cl_ntoh16(p_si->lids_per_port),
2060 			cl_ntoh16(p_si->enforce_cap), p_si->flags,
2061 			cl_ntoh16(p_si->mcast_top));
2062 	}
2063 }
2064 
2065 void osm_dump_switch_info(IN osm_log_t * p_log,
2066 			  IN const ib_switch_info_t * p_si,
2067 			  IN osm_log_level_t log_level)
2068 {
2069 	if (osm_log_is_active(p_log, log_level)) {
2070 		char buf[BUF_SIZE];
2071 
2072 		osm_dump_switch_info_to_buf(p_si, buf);
2073 
2074 		osm_log(p_log, OSM_LOG_VERBOSE, "%s", buf);
2075 	}
2076 }
2077 
2078 void osm_dump_switch_info_v2(IN osm_log_t * p_log,
2079 			     IN const ib_switch_info_t * p_si,
2080 			     IN const int file_id,
2081 			     IN osm_log_level_t log_level)
2082 {
2083 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2084 		char buf[BUF_SIZE];
2085 
2086 		osm_dump_switch_info_to_buf(p_si, buf);
2087 
2088 		osm_log_v2(p_log, OSM_LOG_VERBOSE, file_id, "%s", buf);
2089 	}
2090 }
2091 
2092 static void osm_dump_switch_info_record_to_buf(IN const ib_switch_info_record_t * p_sir,
2093 					       OUT char * buf)
2094 {
2095 	if (!buf || !p_sir)
2096 		return;
2097 	else {
2098 		sprintf(buf,
2099 			"SwitchInfo Record dump:\n"
2100 			"\t\t\t\tRID\n"
2101 			"\t\t\t\tlid.....................%u\n"
2102 			"\t\t\t\tSwitchInfo dump:\n"
2103 			"\t\t\t\tlin_cap.................0x%X\n"
2104 			"\t\t\t\trand_cap................0x%X\n"
2105 			"\t\t\t\tmcast_cap...............0x%X\n"
2106 			"\t\t\t\tlin_top.................0x%X\n"
2107 			"\t\t\t\tdef_port................%u\n"
2108 			"\t\t\t\tdef_mcast_pri_port......%u\n"
2109 			"\t\t\t\tdef_mcast_not_port......%u\n"
2110 			"\t\t\t\tlife_state..............0x%X\n"
2111 			"\t\t\t\tlids_per_port...........%u\n"
2112 			"\t\t\t\tpartition_enf_cap.......0x%X\n"
2113 			"\t\t\t\tflags...................0x%X\n",
2114 			cl_ntoh16(p_sir->lid),
2115 			cl_ntoh16(p_sir->switch_info.lin_cap),
2116 			cl_ntoh16(p_sir->switch_info.rand_cap),
2117 			cl_ntoh16(p_sir->switch_info.mcast_cap),
2118 			cl_ntoh16(p_sir->switch_info.lin_top),
2119 			p_sir->switch_info.def_port,
2120 			p_sir->switch_info.def_mcast_pri_port,
2121 			p_sir->switch_info.def_mcast_not_port,
2122 			p_sir->switch_info.life_state,
2123 			cl_ntoh16(p_sir->switch_info.lids_per_port),
2124 			cl_ntoh16(p_sir->switch_info.enforce_cap),
2125 			p_sir->switch_info.flags);
2126 	}
2127 }
2128 
2129 void osm_dump_switch_info_record(IN osm_log_t * p_log,
2130 				 IN const ib_switch_info_record_t * p_sir,
2131 				 IN osm_log_level_t log_level)
2132 {
2133 	if (osm_log_is_active(p_log, log_level)) {
2134 		char buf[BUF_SIZE];
2135 
2136 		osm_dump_switch_info_record_to_buf(p_sir, buf);
2137 
2138 		osm_log(p_log, log_level, "%s", buf);
2139 	}
2140 }
2141 
2142 void osm_dump_switch_info_record_v2(IN osm_log_t * p_log,
2143 				    IN const ib_switch_info_record_t * p_sir,
2144 				    IN const int file_id,
2145 				    IN osm_log_level_t log_level)
2146 {
2147 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2148 		char buf[BUF_SIZE];
2149 
2150 		osm_dump_switch_info_record_to_buf(p_sir, buf);
2151 
2152 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
2153 	}
2154 }
2155 
2156 static void osm_dump_pkey_block_to_buf(IN uint64_t port_guid,
2157 				       IN uint16_t block_num,
2158 				       IN uint8_t port_num,
2159 				       IN const ib_pkey_table_t * p_pkey_tbl,
2160 				       OUT char * buf)
2161 {
2162 	if (!buf || !p_pkey_tbl)
2163 		return;
2164 	else {
2165 		char buf_line[1024];
2166 		int i, n;
2167 
2168 		for (i = 0, n = 0; i < 32; i++)
2169 			n += sprintf(buf_line + n, " 0x%04x |",
2170 				     cl_ntoh16(p_pkey_tbl->pkey_entry[i]));
2171 
2172 		sprintf(buf,
2173 			"P_Key table dump:\n"
2174 			"\t\t\tport_guid...........0x%016" PRIx64 "\n"
2175 			"\t\t\tblock_num...........0x%X\n"
2176 			"\t\t\tport_num............%u\n\tP_Key Table: %s\n",
2177 			cl_ntoh64(port_guid), block_num, port_num, buf_line);
2178 	}
2179 }
2180 
2181 void osm_dump_pkey_block(IN osm_log_t * p_log, IN uint64_t port_guid,
2182 			 IN uint16_t block_num, IN uint8_t port_num,
2183 			 IN const ib_pkey_table_t * p_pkey_tbl,
2184 			 IN osm_log_level_t log_level)
2185 {
2186 	if (osm_log_is_active(p_log, log_level)) {
2187 		char buf[BUF_SIZE];
2188 
2189 		osm_dump_pkey_block_to_buf(port_guid, block_num, port_num,
2190 					   p_pkey_tbl, buf);
2191 
2192 		osm_log(p_log, log_level, "%s", buf);
2193 	}
2194 }
2195 
2196 void osm_dump_pkey_block_v2(IN osm_log_t * p_log, IN uint64_t port_guid,
2197 			    IN uint16_t block_num, IN uint8_t port_num,
2198 			    IN const ib_pkey_table_t * p_pkey_tbl,
2199 			    IN const int file_id,
2200 			    IN osm_log_level_t log_level)
2201 {
2202 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2203 		char buf[BUF_SIZE];
2204 
2205 		osm_dump_pkey_block_to_buf(port_guid, block_num,
2206 					   port_num, p_pkey_tbl, buf);
2207 
2208 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
2209 	}
2210 }
2211 
2212 static void osm_dump_slvl_map_table_to_buf(IN uint64_t port_guid,
2213 					   IN uint8_t in_port_num,
2214 					   IN uint8_t out_port_num,
2215 					   IN const ib_slvl_table_t * p_slvl_tbl,
2216 					   OUT char * buf)
2217 {
2218 	if (!buf || !p_slvl_tbl)
2219 		return;
2220 	else {
2221 		char buf_line1[1024], buf_line2[1024];
2222 		int n;
2223 		uint8_t i;
2224 
2225 		for (i = 0, n = 0; i < 16; i++)
2226 			n += sprintf(buf_line1 + n, " %-2u |", i);
2227 		for (i = 0, n = 0; i < 16; i++)
2228 			n += sprintf(buf_line2 + n, "0x%01X |",
2229 				     ib_slvl_table_get(p_slvl_tbl, i));
2230 		sprintf(buf,
2231 			"SLtoVL dump:\n"
2232 			"\t\t\tport_guid............0x%016" PRIx64 "\n"
2233 			"\t\t\tin_port_num..........%u\n"
2234 			"\t\t\tout_port_num.........%u\n\tSL: | %s\n\tVL: | %s\n",
2235 			cl_ntoh64(port_guid), in_port_num, out_port_num,
2236 			buf_line1, buf_line2);
2237 	}
2238 }
2239 
2240 void osm_dump_slvl_map_table(IN osm_log_t * p_log, IN uint64_t port_guid,
2241 			     IN uint8_t in_port_num, IN uint8_t out_port_num,
2242 			     IN const ib_slvl_table_t * p_slvl_tbl,
2243 			     IN osm_log_level_t log_level)
2244 {
2245 	if (osm_log_is_active(p_log, log_level)) {
2246 		char buf[BUF_SIZE];
2247 
2248 		osm_dump_slvl_map_table_to_buf(port_guid, in_port_num,
2249 					       out_port_num, p_slvl_tbl, buf);
2250 
2251 		osm_log(p_log, log_level, "%s", buf);
2252 	}
2253 }
2254 
2255 void osm_dump_slvl_map_table_v2(IN osm_log_t * p_log, IN uint64_t port_guid,
2256 				IN uint8_t in_port_num, IN uint8_t out_port_num,
2257 				IN const ib_slvl_table_t * p_slvl_tbl,
2258 				IN const int file_id,
2259 				IN osm_log_level_t log_level)
2260 {
2261 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2262 		char buf[BUF_SIZE];
2263 
2264 		osm_dump_slvl_map_table_to_buf(port_guid, in_port_num,
2265 					       out_port_num, p_slvl_tbl, buf);
2266 
2267 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
2268 	}
2269 }
2270 
2271 static void osm_dump_vl_arb_table_to_buf(IN uint64_t port_guid,
2272 					 IN uint8_t block_num,
2273 					 IN uint8_t port_num,
2274 					 IN const ib_vl_arb_table_t * p_vla_tbl,
2275 					 OUT char * buf)
2276 {
2277 	if (!buf || !p_vla_tbl)
2278 		return;
2279 	else {
2280 		char buf_line1[1024], buf_line2[1024];
2281 		int i, n;
2282 
2283 		for (i = 0, n = 0; i < 32; i++)
2284 			n += sprintf(buf_line1 + n, " 0x%01X |",
2285 				     p_vla_tbl->vl_entry[i].vl);
2286 		for (i = 0, n = 0; i < 32; i++)
2287 			n += sprintf(buf_line2 + n, " 0x%01X |",
2288 				     p_vla_tbl->vl_entry[i].weight);
2289 		sprintf(buf,
2290 			"VLArb dump:\n" "\t\t\tport_guid...........0x%016"
2291 			PRIx64 "\n" "\t\t\tblock_num...........0x%X\n"
2292 			"\t\t\tport_num............%u\n\tVL    : | %s\n\tWEIGHT:| %s\n",
2293 			cl_ntoh64(port_guid), block_num, port_num, buf_line1,
2294 			buf_line2);
2295 	}
2296 }
2297 
2298 void osm_dump_vl_arb_table(IN osm_log_t * p_log, IN uint64_t port_guid,
2299 			   IN uint8_t block_num, IN uint8_t port_num,
2300 			   IN const ib_vl_arb_table_t * p_vla_tbl,
2301 			   IN osm_log_level_t log_level)
2302 {
2303 	if (osm_log_is_active(p_log, log_level)) {
2304 		char buf[BUF_SIZE];
2305 
2306 		osm_dump_vl_arb_table_to_buf(port_guid, block_num,
2307 					     port_num, p_vla_tbl, buf);
2308 
2309 		osm_log(p_log, log_level, "%s", buf);
2310 	}
2311 }
2312 
2313 void osm_dump_vl_arb_table_v2(IN osm_log_t * p_log, IN uint64_t port_guid,
2314 			      IN uint8_t block_num, IN uint8_t port_num,
2315 			      IN const ib_vl_arb_table_t * p_vla_tbl,
2316 			      IN const int file_id,
2317 			      IN osm_log_level_t log_level)
2318 {
2319 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2320 		char buf[BUF_SIZE];
2321 
2322 		osm_dump_vl_arb_table_to_buf(port_guid, block_num,
2323 					     port_num, p_vla_tbl, buf);
2324 
2325 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
2326 	}
2327 }
2328 
2329 static void osm_dump_sm_info_to_buf(IN const ib_sm_info_t * p_smi,
2330 				    OUT char * buf)
2331 {
2332 	if (!buf || !p_smi)
2333 		return;
2334 	else {
2335 		sprintf(buf,
2336 			"SMInfo dump:\n"
2337 			"\t\t\t\tguid....................0x%016" PRIx64 "\n"
2338 			"\t\t\t\tsm_key..................0x%016" PRIx64 "\n"
2339 			"\t\t\t\tact_count...............%u\n"
2340 			"\t\t\t\tpriority................%u\n"
2341 			"\t\t\t\tsm_state................%u\n",
2342 			cl_ntoh64(p_smi->guid), cl_ntoh64(p_smi->sm_key),
2343 			cl_ntoh32(p_smi->act_count),
2344 			ib_sminfo_get_priority(p_smi),
2345 			ib_sminfo_get_state(p_smi));
2346 	}
2347 }
2348 
2349 void osm_dump_sm_info(IN osm_log_t * p_log, IN const ib_sm_info_t * p_smi,
2350 		      IN osm_log_level_t log_level)
2351 {
2352 	if (osm_log_is_active(p_log, log_level)) {
2353 		char buf[BUF_SIZE];
2354 
2355 		osm_dump_sm_info_to_buf(p_smi, buf);
2356 
2357 		osm_log(p_log, OSM_LOG_DEBUG, "%s", buf);
2358 	}
2359 }
2360 
2361 void osm_dump_sm_info_v2(IN osm_log_t * p_log, IN const ib_sm_info_t * p_smi,
2362 			 IN const int file_id, IN osm_log_level_t log_level)
2363 {
2364 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2365 		char buf[BUF_SIZE];
2366 
2367 		osm_dump_sm_info_to_buf(p_smi, buf);
2368 
2369 		osm_log_v2(p_log, OSM_LOG_DEBUG, file_id, "%s", buf);
2370 	}
2371 }
2372 
2373 static void osm_dump_sm_info_record_to_buf(IN const ib_sminfo_record_t * p_smir,
2374 					   OUT char * buf)
2375 {
2376 	if (!buf || !p_smir)
2377 		return;
2378 	else {
2379 		sprintf(buf,
2380 			"SMInfo Record dump:\n"
2381 			"\t\t\t\tRID\n"
2382 			"\t\t\t\tLid.....................%u\n"
2383 			"\t\t\t\tReserved................0x%X\n"
2384 			"\t\t\t\tSMInfo dump:\n"
2385 			"\t\t\t\tguid....................0x%016" PRIx64 "\n"
2386 			"\t\t\t\tsm_key..................0x%016" PRIx64 "\n"
2387 			"\t\t\t\tact_count...............%u\n"
2388 			"\t\t\t\tpriority................%u\n"
2389 			"\t\t\t\tsm_state................%u\n",
2390 			cl_ntoh16(p_smir->lid), cl_ntoh16(p_smir->resv0),
2391 			cl_ntoh64(p_smir->sm_info.guid),
2392 			cl_ntoh64(p_smir->sm_info.sm_key),
2393 			cl_ntoh32(p_smir->sm_info.act_count),
2394 			ib_sminfo_get_priority(&p_smir->sm_info),
2395 			ib_sminfo_get_state(&p_smir->sm_info));
2396 	}
2397 }
2398 
2399 void osm_dump_sm_info_record(IN osm_log_t * p_log,
2400 			     IN const ib_sminfo_record_t * p_smir,
2401 			     IN osm_log_level_t log_level)
2402 {
2403 	if (osm_log_is_active(p_log, log_level)) {
2404 		char buf[BUF_SIZE];
2405 
2406 		osm_dump_sm_info_record_to_buf(p_smir, buf);
2407 
2408 		osm_log(p_log, OSM_LOG_DEBUG, "%s", buf);
2409 	}
2410 }
2411 
2412 void osm_dump_sm_info_record_v2(IN osm_log_t * p_log,
2413 				IN const ib_sminfo_record_t * p_smir,
2414 				IN const int file_id,
2415 				IN osm_log_level_t log_level)
2416 {
2417 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2418 		char buf[BUF_SIZE];
2419 
2420 		osm_dump_sm_info_record_to_buf(p_smir, buf);
2421 
2422 		osm_log_v2(p_log, OSM_LOG_DEBUG, file_id, "%s", buf);
2423 	}
2424 }
2425 
2426 static void osm_dump_notice_to_buf_generic(IN const ib_mad_notice_attr_t * p_ntci,
2427 					   OUT char * log_buf)
2428 {
2429 	if (!log_buf || !p_ntci)
2430 		return;
2431 	else {
2432 		char gid_str[INET6_ADDRSTRLEN];
2433 		char gid_str2[INET6_ADDRSTRLEN];
2434 		char buff[1024];
2435 		int n;
2436 
2437 		buff[0] = '\0';
2438 
2439 		/* immediate data based on the trap */
2440 		switch (cl_ntoh16(p_ntci->g_or_v.generic.trap_num)) {
2441 		case SM_GID_IN_SERVICE_TRAP:	/* 64 */
2442 		case SM_GID_OUT_OF_SERVICE_TRAP: /* 65 */
2443 		case SM_MGID_CREATED_TRAP:	/* 66 */
2444 		case SM_MGID_DESTROYED_TRAP:	/* 67 */
2445 			sprintf(buff,
2446 				"\t\t\t\tsrc_gid..................%s\n",
2447 				inet_ntop(AF_INET6, p_ntci->data_details.
2448 					  ntc_64_67.gid.raw, gid_str,
2449 					  sizeof gid_str));
2450 			break;
2451 		case SM_LINK_STATE_CHANGED_TRAP: /* 128 */
2452 			sprintf(buff,
2453 				"\t\t\t\tsw_lid...................%u\n",
2454 				cl_ntoh16(p_ntci->data_details.ntc_128.sw_lid));
2455 			break;
2456 		case SM_LINK_INTEGRITY_THRESHOLD_TRAP: /* 129 */
2457 		case SM_BUFFER_OVERRUN_THRESHOLD_TRAP: /* 130 */
2458 		case SM_WATCHDOG_TIMER_EXPIRED_TRAP:   /* 131 */
2459 			sprintf(buff,
2460 				"\t\t\t\tlid......................%u\n"
2461 				"\t\t\t\tport_num.................%u\n",
2462 				cl_ntoh16(p_ntci->data_details.
2463 					  ntc_129_131.lid),
2464 				p_ntci->data_details.ntc_129_131.port_num);
2465 			break;
2466 		case SM_LOCAL_CHANGES_TRAP:	/* 144 */
2467 			sprintf(buff,
2468 				"\t\t\t\tlid......................%u\n"
2469 				"\t\t\t\tlocal_changes............%u\n"
2470 				"\t\t\t\tnew_cap_mask.............0x%08x\n"
2471 				"\t\t\t\tchange_flags.............0x%x\n"
2472 				"\t\t\t\tcap_mask2................0x%x\n",
2473 				cl_ntoh16(p_ntci->data_details.ntc_144.lid),
2474 				p_ntci->data_details.ntc_144.local_changes,
2475 				cl_ntoh32(p_ntci->data_details.ntc_144.
2476 					  new_cap_mask),
2477 				cl_ntoh16(p_ntci->data_details.ntc_144.
2478 					  change_flgs),
2479 				cl_ntoh16(p_ntci->data_details.ntc_144.
2480 					  cap_mask2));
2481 			break;
2482 		case SM_SYS_IMG_GUID_CHANGED_TRAP: /* 145 */
2483 			sprintf(buff,
2484 				"\t\t\t\tlid......................%u\n"
2485 				"\t\t\t\tnew_sys_guid.............0x%016"
2486 				PRIx64 "\n",
2487 				cl_ntoh16(p_ntci->data_details.ntc_145.
2488 					  lid),
2489 				cl_ntoh64(p_ntci->data_details.ntc_145.
2490 					  new_sys_guid));
2491 			break;
2492 		case SM_BAD_MKEY_TRAP:	/* 256 */
2493 			n = sprintf(buff,
2494 				    "\t\t\t\tlid......................%u\n"
2495 				    "\t\t\t\tdrslid...................%u\n"
2496 				    "\t\t\t\tmethod...................0x%x\n"
2497 				    "\t\t\t\tattr_id..................0x%x\n"
2498 				    "\t\t\t\tattr_mod.................0x%x\n"
2499 				    "\t\t\t\tm_key....................0x%016"
2500 				    PRIx64 "\n"
2501 				    "\t\t\t\tdr_notice................%d\n"
2502 				    "\t\t\t\tdr_path_truncated........%d\n"
2503 				    "\t\t\t\tdr_hop_count.............%u\n",
2504 				    cl_ntoh16(p_ntci->data_details.ntc_256.lid),
2505 				    cl_ntoh16(p_ntci->data_details.ntc_256.
2506 					      dr_slid),
2507 				    p_ntci->data_details.ntc_256.method,
2508 				    cl_ntoh16(p_ntci->data_details.ntc_256.
2509 					      attr_id),
2510 				    cl_ntoh32(p_ntci->data_details.ntc_256.
2511 					      attr_mod),
2512 				    cl_ntoh64(p_ntci->data_details.ntc_256.
2513 					      mkey),
2514 				    p_ntci->data_details.ntc_256.
2515 				    dr_trunc_hop >> 7,
2516 				    p_ntci->data_details.ntc_256.
2517 				    dr_trunc_hop >> 6,
2518 				    p_ntci->data_details.ntc_256.
2519 				    dr_trunc_hop & 0x3f);
2520 			n += snprintf(buff + n, sizeof(buff) - n,
2521 				      "Directed Path Dump of %u hop path:"
2522 				      "\n\t\t\t\tPath = ",
2523 				      p_ntci->data_details.ntc_256.
2524 				      dr_trunc_hop & 0x3f);
2525 			n += sprint_uint8_arr(buff + n, sizeof(buff) - n,
2526 					      p_ntci->data_details.ntc_256.
2527 					      dr_rtn_path,
2528 					      (p_ntci->data_details.ntc_256.
2529 					       dr_trunc_hop & 0x3f) + 1);
2530 			if (n >= sizeof(buff)) {
2531 				n = sizeof(buff) - 2;
2532 				break;
2533 			}
2534 			snprintf(buff + n, sizeof(buff) - n, "\n");
2535 			break;
2536 		case SM_BAD_PKEY_TRAP:	/* 257 */
2537 		case SM_BAD_QKEY_TRAP:	/* 258 */
2538 			sprintf(buff,
2539 				"\t\t\t\tlid1.....................%u\n"
2540 				"\t\t\t\tlid2.....................%u\n"
2541 				"\t\t\t\tkey......................0x%x\n"
2542 				"\t\t\t\tsl.......................%d\n"
2543 				"\t\t\t\tqp1......................0x%x\n"
2544 				"\t\t\t\tqp2......................0x%x\n"
2545 				"\t\t\t\tgid1.....................%s\n"
2546 				"\t\t\t\tgid2.....................%s\n",
2547 				cl_ntoh16(p_ntci->data_details.ntc_257_258.
2548 					  lid1),
2549 				cl_ntoh16(p_ntci->data_details.ntc_257_258.
2550 					  lid2),
2551 				cl_ntoh32(p_ntci->data_details.ntc_257_258.key),
2552 				cl_ntoh32(p_ntci->data_details.ntc_257_258.
2553 					  qp1) >> 28,
2554 				cl_ntoh32(p_ntci->data_details.ntc_257_258.
2555 					  qp1) & 0xffffff,
2556 				cl_ntoh32(p_ntci->data_details.ntc_257_258.
2557 					  qp2) & 0xffffff,
2558 				inet_ntop(AF_INET6, p_ntci->data_details.
2559 					  ntc_257_258.gid1.raw, gid_str,
2560 					  sizeof gid_str),
2561 				inet_ntop(AF_INET6, p_ntci->data_details.
2562 					  ntc_257_258.gid2.raw, gid_str2,
2563 					  sizeof gid_str2));
2564 			break;
2565 		case SM_BAD_SWITCH_PKEY_TRAP:	/* 259 */
2566 			sprintf(buff,
2567 				"\t\t\t\tdata_valid...............0x%x\n"
2568 				"\t\t\t\tlid1.....................%u\n"
2569 				"\t\t\t\tlid2.....................%u\n"
2570 				"\t\t\t\tpkey.....................0x%x\n"
2571 				"\t\t\t\tsl.......................%d\n"
2572 				"\t\t\t\tqp1......................0x%x\n"
2573 				"\t\t\t\tqp2......................0x%x\n"
2574 				"\t\t\t\tgid1.....................%s\n"
2575 				"\t\t\t\tgid2.....................%s\n"
2576 				"\t\t\t\tsw_lid...................%u\n"
2577 				"\t\t\t\tport_no..................%u\n",
2578 				cl_ntoh16(p_ntci->data_details.ntc_259.
2579 					  data_valid),
2580 				cl_ntoh16(p_ntci->data_details.ntc_259.lid1),
2581 				cl_ntoh16(p_ntci->data_details.ntc_259.lid2),
2582 				cl_ntoh16(p_ntci->data_details.ntc_259.pkey),
2583 				cl_ntoh32(p_ntci->data_details.ntc_259.
2584 					  sl_qp1) >> 24,
2585 				cl_ntoh32(p_ntci->data_details.ntc_259.
2586 					  sl_qp1) & 0xffffff,
2587 				cl_ntoh32(p_ntci->data_details.ntc_259.qp2),
2588 				inet_ntop(AF_INET6, p_ntci->data_details.
2589 					  ntc_259.gid1.raw, gid_str,
2590 					  sizeof gid_str),
2591 				inet_ntop(AF_INET6, p_ntci->data_details.
2592 					  ntc_259.gid2.raw, gid_str2,
2593 					  sizeof gid_str2),
2594 				cl_ntoh16(p_ntci->data_details.ntc_259.sw_lid),
2595 				p_ntci->data_details.ntc_259.port_no);
2596 			break;
2597 		}
2598 
2599 		sprintf(log_buf,
2600 			"Generic Notice dump:\n"
2601 			"\t\t\t\ttype.....................%u\n"
2602 			"\t\t\t\tprod_type................%u (%s)\n"
2603 			"\t\t\t\ttrap_num.................%u\n%s",
2604 			ib_notice_get_type(p_ntci),
2605 			cl_ntoh32(ib_notice_get_prod_type(p_ntci)),
2606 			ib_get_producer_type_str(ib_notice_get_prod_type
2607 						 (p_ntci)),
2608 			cl_ntoh16(p_ntci->g_or_v.generic.trap_num), buff);
2609 	}
2610 }
2611 
2612 static void osm_dump_notice_to_buf(IN const ib_mad_notice_attr_t * p_ntci,
2613 				   OUT char * buf)
2614 {
2615 	if (!buf || !p_ntci)
2616 		return;
2617 	else {
2618 		sprintf(buf,
2619 			"Vendor Notice dump:\n"
2620 			"\t\t\t\ttype.....................%u\n"
2621 			"\t\t\t\tvendor...................%u\n"
2622 			"\t\t\t\tdevice_id................%u\n",
2623 			cl_ntoh16(ib_notice_get_type(p_ntci)),
2624 			cl_ntoh32(ib_notice_get_vend_id(p_ntci)),
2625 			cl_ntoh16(p_ntci->g_or_v.vend.dev_id));
2626 	}
2627 }
2628 
2629 void osm_dump_notice(IN osm_log_t * p_log,
2630 		     IN const ib_mad_notice_attr_t * p_ntci,
2631 		     IN osm_log_level_t log_level)
2632 {
2633 	if (osm_log_is_active(p_log, log_level)) {
2634 		char buf[BUF_SIZE];
2635 
2636 		if (ib_notice_is_generic(p_ntci))
2637 			osm_dump_notice_to_buf_generic(p_ntci, buf);
2638 		else
2639 			osm_dump_notice_to_buf(p_ntci, buf);
2640 
2641 		osm_log(p_log, log_level, "%s", buf);
2642 	}
2643 }
2644 
2645 void osm_dump_notice_v2(IN osm_log_t * p_log,
2646 			IN const ib_mad_notice_attr_t * p_ntci,
2647 			IN const int file_id, IN osm_log_level_t log_level)
2648 {
2649 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2650 		char buf[BUF_SIZE];
2651 
2652 		if (ib_notice_is_generic(p_ntci))
2653 			osm_dump_notice_to_buf_generic(p_ntci, buf);
2654 		else
2655 			osm_dump_notice_to_buf(p_ntci, buf);
2656 
2657 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
2658 	}
2659 }
2660 
2661 static void osm_dump_dr_smp_to_buf(IN const ib_smp_t * p_smp, OUT char * buf,
2662 				   IN size_t buf_size)
2663 {
2664 	if (!buf || !p_smp)
2665 		return;
2666 	else {
2667 		unsigned n;
2668 
2669 		n = sprintf(buf,
2670 			    "SMP dump:\n"
2671 			    "\t\t\t\tbase_ver................0x%X\n"
2672 			    "\t\t\t\tmgmt_class..............0x%X\n"
2673 			    "\t\t\t\tclass_ver...............0x%X\n"
2674 			    "\t\t\t\tmethod..................0x%X (%s)\n",
2675 			    p_smp->base_ver, p_smp->mgmt_class,
2676 			    p_smp->class_ver, p_smp->method,
2677 			    ib_get_sm_method_str(p_smp->method));
2678 
2679 		if (p_smp->mgmt_class == IB_MCLASS_SUBN_DIR) {
2680 			n += snprintf(buf + n, buf_size - n,
2681 				      "\t\t\t\tD bit...................0x%X\n"
2682 				      "\t\t\t\tstatus..................0x%X\n",
2683 				      ib_smp_is_d(p_smp),
2684 				      cl_ntoh16(ib_smp_get_status(p_smp)));
2685 		} else {
2686 			n += snprintf(buf + n, buf_size - n,
2687 				      "\t\t\t\tstatus..................0x%X\n",
2688 				      cl_ntoh16(p_smp->status));
2689 		}
2690 
2691 		n += snprintf(buf + n, buf_size - n,
2692 			      "\t\t\t\thop_ptr.................0x%X\n"
2693 			      "\t\t\t\thop_count...............0x%X\n"
2694 			      "\t\t\t\ttrans_id................0x%" PRIx64 "\n"
2695 			      "\t\t\t\tattr_id.................0x%X (%s)\n"
2696 			      "\t\t\t\tresv....................0x%X\n"
2697 			      "\t\t\t\tattr_mod................0x%X\n"
2698 			      "\t\t\t\tm_key...................0x%016" PRIx64
2699 			      "\n", p_smp->hop_ptr, p_smp->hop_count,
2700 			      cl_ntoh64(p_smp->trans_id),
2701 			      cl_ntoh16(p_smp->attr_id),
2702 			      ib_get_sm_attr_str(p_smp->attr_id),
2703 			      cl_ntoh16(p_smp->resv),
2704 			      cl_ntoh32(p_smp->attr_mod),
2705 			      cl_ntoh64(p_smp->m_key));
2706 
2707 		if (p_smp->mgmt_class == IB_MCLASS_SUBN_DIR) {
2708 			uint32_t i;
2709 			n += snprintf(buf + n, buf_size - n,
2710 				      "\t\t\t\tdr_slid.................%u\n"
2711 				      "\t\t\t\tdr_dlid.................%u\n",
2712 				      cl_ntoh16(p_smp->dr_slid),
2713 				      cl_ntoh16(p_smp->dr_dlid));
2714 
2715 			n += snprintf(buf + n, buf_size - n,
2716 				      "\n\t\t\t\tInitial path: ");
2717 			n += sprint_uint8_arr(buf + n, buf_size - n,
2718 					      p_smp->initial_path,
2719 					      p_smp->hop_count + 1);
2720 
2721 			n += snprintf(buf + n, buf_size - n,
2722 				      "\n\t\t\t\tReturn path:  ");
2723 			n += sprint_uint8_arr(buf + n, buf_size - n,
2724 					      p_smp->return_path,
2725 					      p_smp->hop_count + 1);
2726 
2727 			n += snprintf(buf + n, buf_size - n,
2728 				      "\n\t\t\t\tReserved:     ");
2729 			for (i = 0; i < 7; i++) {
2730 				n += snprintf(buf + n, buf_size - n,
2731 					      "[%0X]", p_smp->resv1[i]);
2732 			}
2733 			n += snprintf(buf + n, buf_size - n, "\n");
2734 
2735 			for (i = 0; i < 64; i += 16) {
2736 				n += snprintf(buf + n, buf_size - n,
2737 					      "\n\t\t\t\t%02X %02X %02X %02X "
2738 					      "%02X %02X %02X %02X"
2739 					      "   %02X %02X %02X %02X %02X %02X %02X %02X\n",
2740 					      p_smp->data[i],
2741 					      p_smp->data[i + 1],
2742 					      p_smp->data[i + 2],
2743 					      p_smp->data[i + 3],
2744 					      p_smp->data[i + 4],
2745 					      p_smp->data[i + 5],
2746 					      p_smp->data[i + 6],
2747 					      p_smp->data[i + 7],
2748 					      p_smp->data[i + 8],
2749 					      p_smp->data[i + 9],
2750 					      p_smp->data[i + 10],
2751 					      p_smp->data[i + 11],
2752 					      p_smp->data[i + 12],
2753 					      p_smp->data[i + 13],
2754 					      p_smp->data[i + 14],
2755 					      p_smp->data[i + 15]);
2756 			}
2757 		} else {
2758 			/* not a Direct Route so provide source and destination lids */
2759 			n += snprintf(buf + n, buf_size - n,
2760 				      "\t\t\t\tMAD IS LID ROUTED\n");
2761 		}
2762 	}
2763 }
2764 
2765 void osm_dump_dr_smp(IN osm_log_t * p_log, IN const ib_smp_t * p_smp,
2766 		     IN osm_log_level_t log_level)
2767 {
2768 	if (osm_log_is_active(p_log, log_level)) {
2769 		char buf[BUF_SIZE];
2770 
2771 		osm_dump_dr_smp_to_buf(p_smp, buf, BUF_SIZE);
2772 
2773 		osm_log(p_log, log_level, "%s", buf);
2774 	}
2775 }
2776 
2777 void osm_dump_dr_smp_v2(IN osm_log_t * p_log, IN const ib_smp_t * p_smp,
2778 			IN const int file_id, IN osm_log_level_t log_level)
2779 {
2780 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2781 		char buf[BUF_SIZE];
2782 
2783 		osm_dump_dr_smp_to_buf(p_smp, buf, BUF_SIZE);
2784 
2785 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
2786 	}
2787 }
2788 
2789 static void osm_dump_sa_mad_to_buf(IN const ib_sa_mad_t * p_mad, OUT char * buf)
2790 {
2791 	if (!buf || !p_mad)
2792 		return;
2793 	else {
2794 		/* make sure the mad is valid */
2795 		if (p_mad == NULL) {
2796 			sprintf(buf, "NULL MAD POINTER\n");
2797 			return;
2798 		}
2799 
2800 		sprintf(buf,
2801 			"SA MAD dump:\n"
2802 			"\t\t\t\tbase_ver................0x%X\n"
2803 			"\t\t\t\tmgmt_class..............0x%X\n"
2804 			"\t\t\t\tclass_ver...............0x%X\n"
2805 			"\t\t\t\tmethod..................0x%X (%s)\n"
2806 			"\t\t\t\tstatus..................0x%X\n"
2807 			"\t\t\t\tresv....................0x%X\n"
2808 			"\t\t\t\ttrans_id................0x%" PRIx64 "\n"
2809 			"\t\t\t\tattr_id.................0x%X (%s)\n"
2810 			"\t\t\t\tresv1...................0x%X\n"
2811 			"\t\t\t\tattr_mod................0x%X\n"
2812 			"\t\t\t\trmpp_version............0x%X\n"
2813 			"\t\t\t\trmpp_type...............0x%X\n"
2814 			"\t\t\t\trmpp_flags..............0x%X\n"
2815 			"\t\t\t\trmpp_status.............0x%X\n"
2816 			"\t\t\t\tseg_num.................0x%X\n"
2817 			"\t\t\t\tpayload_len/new_win.....0x%X\n"
2818 			"\t\t\t\tsm_key..................0x%016" PRIx64 "\n"
2819 			"\t\t\t\tattr_offset.............0x%X\n"
2820 			"\t\t\t\tresv2...................0x%X\n"
2821 			"\t\t\t\tcomp_mask...............0x%016" PRIx64 "\n",
2822 			p_mad->base_ver, p_mad->mgmt_class, p_mad->class_ver,
2823 			p_mad->method, ib_get_sa_method_str(p_mad->method),
2824 			cl_ntoh16(p_mad->status), cl_ntoh16(p_mad->resv),
2825 			cl_ntoh64(p_mad->trans_id), cl_ntoh16(p_mad->attr_id),
2826 			ib_get_sa_attr_str(p_mad->attr_id),
2827 			cl_ntoh16(p_mad->resv1), cl_ntoh32(p_mad->attr_mod),
2828 			p_mad->rmpp_version, p_mad->rmpp_type,
2829 			p_mad->rmpp_flags, p_mad->rmpp_status,
2830 			cl_ntoh32(p_mad->seg_num),
2831 			cl_ntoh32(p_mad->paylen_newwin),
2832 			cl_ntoh64(p_mad->sm_key), cl_ntoh16(p_mad->attr_offset),
2833 			cl_ntoh16(p_mad->resv3), cl_ntoh64(p_mad->comp_mask));
2834 
2835 		strcat(buf, "\n");
2836 	}
2837 }
2838 
2839 void osm_dump_sa_mad(IN osm_log_t * p_log, IN const ib_sa_mad_t * p_mad,
2840 		     IN osm_log_level_t log_level)
2841 {
2842 	if (osm_log_is_active(p_log, log_level)) {
2843 		char buf[BUF_SIZE];
2844 
2845 		osm_dump_sa_mad_to_buf(p_mad, buf);
2846 
2847 		osm_log(p_log, log_level, "%s\n", buf);
2848 	}
2849 }
2850 
2851 void osm_dump_sa_mad_v2(IN osm_log_t * p_log, IN const ib_sa_mad_t * p_mad,
2852 			IN const int file_id, IN osm_log_level_t log_level)
2853 {
2854 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2855 		char buf[BUF_SIZE];
2856 
2857 		osm_dump_sa_mad_to_buf(p_mad, buf);
2858 
2859 		osm_log_v2(p_log, log_level, file_id, "%s", buf);
2860 	}
2861 }
2862 
2863 static void osm_dump_dr_path_to_buf(IN const osm_dr_path_t * p_path,
2864 				    OUT char * buf, IN size_t buf_size)
2865 {
2866 	if (!buf || !p_path)
2867 		return;
2868 	else {
2869 		unsigned n = 0;
2870 
2871 		n = sprintf(buf, "Directed Path Dump of %u hop path: "
2872 			    "Path = ", p_path->hop_count);
2873 
2874 		sprint_uint8_arr(buf + n, buf_size - n, p_path->path,
2875 				 p_path->hop_count + 1);
2876 	}
2877 }
2878 
2879 void osm_dump_dr_path(IN osm_log_t * p_log, IN const osm_dr_path_t * p_path,
2880 		      IN osm_log_level_t log_level)
2881 {
2882 	if (osm_log_is_active(p_log, log_level)) {
2883 		char buf[BUF_SIZE];
2884 
2885 		osm_dump_dr_path_to_buf(p_path, buf, BUF_SIZE);
2886 
2887 		osm_log(p_log, log_level, "%s\n", buf);
2888 	}
2889 }
2890 
2891 void osm_dump_dr_path_v2(IN osm_log_t * p_log, IN const osm_dr_path_t * p_path,
2892 			 IN const int file_id, IN osm_log_level_t log_level)
2893 {
2894 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2895 		char buf[BUF_SIZE];
2896 
2897 		osm_dump_dr_path_to_buf(p_path, buf, BUF_SIZE);
2898 
2899 		osm_log_v2(p_log, log_level, file_id, "%s\n", buf);
2900 	}
2901 }
2902 
2903 static void osm_dump_smp_dr_path_to_buf(IN const ib_smp_t * p_smp,
2904 					OUT char * buf, IN size_t buf_size)
2905 {
2906 	if (!buf || !p_smp)
2907 		return;
2908 	else {
2909 		unsigned n;
2910 
2911 		n = sprintf(buf, "Received SMP on a %u hop path: "
2912 			    "Initial path = ", p_smp->hop_count);
2913 		n += sprint_uint8_arr(buf + n, buf_size - n,
2914 				      p_smp->initial_path,
2915 				      p_smp->hop_count + 1);
2916 
2917 		n += snprintf(buf + n, buf_size - n, ", Return path  = ");
2918 		n += sprint_uint8_arr(buf + n, buf_size - n,
2919 				      p_smp->return_path, p_smp->hop_count + 1);
2920 	}
2921 }
2922 
2923 void osm_dump_smp_dr_path(IN osm_log_t * p_log, IN const ib_smp_t * p_smp,
2924 			  IN osm_log_level_t log_level)
2925 {
2926 	if (osm_log_is_active(p_log, log_level)) {
2927 		char buf[BUF_SIZE];
2928 
2929 		osm_dump_smp_dr_path_to_buf(p_smp, buf, BUF_SIZE);
2930 
2931 		osm_log(p_log, log_level, "%s\n", buf);
2932 	}
2933 }
2934 
2935 void osm_dump_smp_dr_path_v2(IN osm_log_t * p_log, IN const ib_smp_t * p_smp,
2936 			     IN const int file_id, IN osm_log_level_t log_level)
2937 {
2938 	if (osm_log_is_active_v2(p_log, log_level, file_id)) {
2939 		char buf[BUF_SIZE];
2940 
2941 		osm_dump_smp_dr_path_to_buf(p_smp, buf, BUF_SIZE);
2942 
2943 		osm_log_v2(p_log, log_level, file_id, "%s\n", buf);
2944 	}
2945 }
2946 
2947 void osm_dump_dr_path_as_buf(IN size_t max_len,
2948 			     IN const osm_dr_path_t * p_path,
2949 			     OUT char* buf)
2950 {
2951 	sprint_uint8_arr(buf, max_len, p_path->path, p_path->hop_count + 1);
2952 }
2953 
2954 static const char *sm_signal_str[] = {
2955 	"OSM_SIGNAL_NONE",	/* 0 */
2956 	"OSM_SIGNAL_SWEEP",	/* 1 */
2957 	"OSM_SIGNAL_IDLE_TIME_PROCESS_REQUEST",	/* 2 */
2958 	"OSM_SIGNAL_PERFMGR_SWEEP",	/* 3 */
2959 	"OSM_SIGNAL_GUID_PROCESS_REQUEST",	/* 4 */
2960 	"UNKNOWN SIGNAL!!"	/* 5 */
2961 };
2962 
2963 const char *osm_get_sm_signal_str(IN osm_signal_t signal)
2964 {
2965 	if (signal > OSM_SIGNAL_MAX)
2966 		signal = OSM_SIGNAL_MAX;
2967 	return sm_signal_str[signal];
2968 }
2969 
2970 static const char *disp_msg_str[] = {
2971 	"OSM_MSG_NONE",
2972 	"OSM_MSG_MAD_NODE_INFO",
2973 	"OSM_MSG_MAD_PORT_INFO",
2974 	"OSM_MSG_MAD_SWITCH_INFO",
2975 	"OSM_MSG_MAD_GUID_INFO",
2976 	"OSM_MSG_MAD_NODE_DESC",
2977 	"OSM_MSG_MAD_NODE_RECORD",
2978 	"OSM_MSG_MAD_PORTINFO_RECORD",
2979 	"OSM_MSG_MAD_SERVICE_RECORD",
2980 	"OSM_MSG_MAD_PATH_RECORD",
2981 	"OSM_MSG_MAD_MCMEMBER_RECORD",
2982 	"OSM_MSG_MAD_LINK_RECORD",
2983 	"OSM_MSG_MAD_SMINFO_RECORD",
2984 	"OSM_MSG_MAD_CLASS_PORT_INFO",
2985 	"OSM_MSG_MAD_INFORM_INFO",
2986 	"OSM_MSG_MAD_LFT_RECORD",
2987 	"OSM_MSG_MAD_LFT",
2988 	"OSM_MSG_MAD_SM_INFO",
2989 	"OSM_MSG_MAD_NOTICE",
2990 	"OSM_MSG_LIGHT_SWEEP_FAIL",
2991 	"OSM_MSG_MAD_MFT",
2992 	"OSM_MSG_MAD_PKEY_TBL_RECORD",
2993 	"OSM_MSG_MAD_VL_ARB_RECORD",
2994 	"OSM_MSG_MAD_SLVL_TBL_RECORD",
2995 	"OSM_MSG_MAD_PKEY",
2996 	"OSM_MSG_MAD_VL_ARB",
2997 	"OSM_MSG_MAD_SLVL",
2998 	"OSM_MSG_MAD_GUIDINFO_RECORD",
2999 	"OSM_MSG_MAD_INFORM_INFO_RECORD",
3000 	"OSM_MSG_MAD_SWITCH_INFO_RECORD",
3001 	"OSM_MSG_MAD_MFT_RECORD",
3002 #if defined (VENDOR_RMPP_SUPPORT) && defined (DUAL_SIDED_RMPP)
3003 	"OSM_MSG_MAD_MULTIPATH_RECORD",
3004 #endif
3005 	"OSM_MSG_MAD_PORT_COUNTERS",
3006 	"OSM_MSG_MAD_MLNX_EXT_PORT_INFO",
3007 	"UNKNOWN!!"
3008 };
3009 
3010 const char *osm_get_disp_msg_str(IN cl_disp_msgid_t msg)
3011 {
3012 	if (msg >= OSM_MSG_MAX)
3013 		msg = OSM_MSG_MAX-1;
3014 	return disp_msg_str[msg];
3015 }
3016 
3017 static const char *port_state_str_fixed_width[] = {
3018 	"NOC",
3019 	"DWN",
3020 	"INI",
3021 	"ARM",
3022 	"ACT",
3023 	"???"
3024 };
3025 
3026 const char *osm_get_port_state_str_fixed_width(IN uint8_t port_state)
3027 {
3028 	if (port_state > IB_LINK_ACTIVE)
3029 		port_state = IB_LINK_ACTIVE + 1;
3030 	return port_state_str_fixed_width[port_state];
3031 }
3032 
3033 static const char *node_type_str_fixed_width[] = {
3034 	"??",
3035 	"CA",
3036 	"SW",
3037 	"RT",
3038 };
3039 
3040 const char *osm_get_node_type_str_fixed_width(IN uint8_t node_type)
3041 {
3042 	if (node_type > IB_NODE_TYPE_ROUTER)
3043 		node_type = 0;
3044 	return node_type_str_fixed_width[node_type];
3045 }
3046 
3047 const char *osm_get_manufacturer_str(IN uint64_t guid_ho)
3048 {
3049 	/* note that the max vendor string length is 11 */
3050 	static const char *intel_str = "Intel";
3051 	static const char *mellanox_str = "Mellanox";
3052 	static const char *redswitch_str = "Redswitch";
3053 	static const char *silverstorm_str = "SilverStorm";
3054 	static const char *topspin_str = "Topspin";
3055 	static const char *fujitsu_str = "Fujitsu";
3056 	static const char *voltaire_str = "Voltaire";
3057 	static const char *yotta_str = "YottaYotta";
3058 	static const char *pathscale_str = "PathScale";
3059 	static const char *ibm_str = "IBM";
3060 	static const char *divergenet_str = "DivergeNet";
3061 	static const char *flextronics_str = "Flextronics";
3062 	static const char *agilent_str = "Agilent";
3063 	static const char *obsidian_str = "Obsidian";
3064 	static const char *baymicro_str = "BayMicro";
3065 	static const char *lsilogic_str = "LSILogic";
3066 	static const char *ddn_str = "DataDirect";
3067 	static const char *panta_str = "Panta";
3068 	static const char *hp_str = "HP";
3069 	static const char *rioworks_str = "Rioworks";
3070 	static const char *sun_str = "Sun";
3071 	static const char *leafntwks_str = "3LeafNtwks";
3072 	static const char *xsigo_str = "Xsigo";
3073 	static const char *dell_str = "Dell";
3074 	static const char *supermicro_str = "SuperMicro";
3075 	static const char *openib_str = "OpenIB";
3076 	static const char *unknown_str = "Unknown";
3077 	static const char *bull_str = "Bull";
3078 
3079 	switch ((uint32_t) (guid_ho >> (5 * 8))) {
3080 	case OSM_VENDOR_ID_INTEL:
3081 		return intel_str;
3082 	case OSM_VENDOR_ID_MELLANOX:
3083 	case OSM_VENDOR_ID_MELLANOX2:
3084 	case OSM_VENDOR_ID_MELLANOX3:
3085 	case OSM_VENDOR_ID_MELLANOX4:
3086 	case OSM_VENDOR_ID_MELLANOX5:
3087 		return mellanox_str;
3088 	case OSM_VENDOR_ID_REDSWITCH:
3089 		return redswitch_str;
3090 	case OSM_VENDOR_ID_SILVERSTORM:
3091 		return silverstorm_str;
3092 	case OSM_VENDOR_ID_TOPSPIN:
3093 		return topspin_str;
3094 	case OSM_VENDOR_ID_FUJITSU:
3095 	case OSM_VENDOR_ID_FUJITSU2:
3096 		return fujitsu_str;
3097 	case OSM_VENDOR_ID_VOLTAIRE:
3098 		return voltaire_str;
3099 	case OSM_VENDOR_ID_YOTTAYOTTA:
3100 		return yotta_str;
3101 	case OSM_VENDOR_ID_PATHSCALE:
3102 		return pathscale_str;
3103 	case OSM_VENDOR_ID_IBM:
3104 	case OSM_VENDOR_ID_IBM2:
3105 		return ibm_str;
3106 	case OSM_VENDOR_ID_DIVERGENET:
3107 		return divergenet_str;
3108 	case OSM_VENDOR_ID_FLEXTRONICS:
3109 		return flextronics_str;
3110 	case OSM_VENDOR_ID_AGILENT:
3111 		return agilent_str;
3112 	case OSM_VENDOR_ID_OBSIDIAN:
3113 		return obsidian_str;
3114 	case OSM_VENDOR_ID_BAYMICRO:
3115 		return baymicro_str;
3116 	case OSM_VENDOR_ID_LSILOGIC:
3117 		return lsilogic_str;
3118 	case OSM_VENDOR_ID_DDN:
3119 		return ddn_str;
3120 	case OSM_VENDOR_ID_PANTA:
3121 		return panta_str;
3122 	case OSM_VENDOR_ID_HP:
3123 	case OSM_VENDOR_ID_HP2:
3124 	case OSM_VENDOR_ID_HP3:
3125 	case OSM_VENDOR_ID_HP4:
3126 		return hp_str;
3127 	case OSM_VENDOR_ID_RIOWORKS:
3128 		return rioworks_str;
3129 	case OSM_VENDOR_ID_SUN:
3130 	case OSM_VENDOR_ID_SUN2:
3131 		return sun_str;
3132 	case OSM_VENDOR_ID_3LEAFNTWKS:
3133 		return leafntwks_str;
3134 	case OSM_VENDOR_ID_XSIGO:
3135 		return xsigo_str;
3136 	case OSM_VENDOR_ID_DELL:
3137 		return dell_str;
3138 	case OSM_VENDOR_ID_SUPERMICRO:
3139 		return supermicro_str;
3140 	case OSM_VENDOR_ID_OPENIB:
3141 		return openib_str;
3142 	case OSM_VENDOR_ID_BULL:
3143 		return bull_str;
3144 	default:
3145 		return unknown_str;
3146 	}
3147 }
3148 
3149 static const char *mtu_str_fixed_width[] = {
3150 	"??? ",
3151 	"256 ",
3152 	"512 ",
3153 	"1024",
3154 	"2048",
3155 	"4096"
3156 };
3157 
3158 const char *osm_get_mtu_str(IN uint8_t mtu)
3159 {
3160 	if (mtu > IB_MTU_LEN_4096)
3161 		return mtu_str_fixed_width[0];
3162 	else
3163 		return mtu_str_fixed_width[mtu];
3164 }
3165 
3166 static const char *lwa_str_fixed_width[] = {
3167 	"???",
3168 	"1x ",
3169 	"4x ",
3170 	"???",
3171 	"8x ",
3172 	"???",
3173 	"???",
3174 	"???",
3175 	"12x",
3176 	"???",
3177 	"???",
3178 	"???",
3179 	"???",
3180 	"???",
3181 	"???",
3182 	"???",
3183 	"2x "
3184 };
3185 
3186 const char *osm_get_lwa_str(IN uint8_t lwa)
3187 {
3188 	if (lwa > 16)
3189 		return lwa_str_fixed_width[0];
3190 	else
3191 		return lwa_str_fixed_width[lwa];
3192 }
3193 
3194 static const char *lsa_str_fixed_width[] = {
3195 	"Ext ",
3196 	"2.5 ",
3197 	"5   ",
3198 	"????",
3199 	"10  "
3200 };
3201 
3202 static const char *lsea_str_fixed_width[] = {
3203 	"Std ",
3204 	"14  ",
3205 	"25  "
3206 };
3207 
3208 const char *osm_get_lsa_str(IN uint8_t lsa, IN uint8_t lsea, IN uint8_t state,
3209 			    IN uint8_t fdr10)
3210 {
3211 	if (lsa > IB_LINK_SPEED_ACTIVE_10 || state == IB_LINK_DOWN)
3212 		return lsa_str_fixed_width[3];
3213 	if (lsea == IB_LINK_SPEED_EXT_ACTIVE_NONE) {
3214 		if (fdr10)
3215 			return "FDR10";
3216 		else
3217 			return lsa_str_fixed_width[lsa];
3218 	}
3219 	if (lsea > IB_LINK_SPEED_EXT_ACTIVE_25)
3220 		return lsa_str_fixed_width[3];
3221 	return lsea_str_fixed_width[lsea];
3222 }
3223 
3224 static const char *sm_mgr_signal_str[] = {
3225 	"OSM_SM_SIGNAL_NONE",	/* 0 */
3226 	"OSM_SM_SIGNAL_DISCOVERY_COMPLETED",	/* 1 */
3227 	"OSM_SM_SIGNAL_POLLING_TIMEOUT",	/* 2 */
3228 	"OSM_SM_SIGNAL_DISCOVER",	/* 3 */
3229 	"OSM_SM_SIGNAL_DISABLE",	/* 4 */
3230 	"OSM_SM_SIGNAL_HANDOVER",	/* 5 */
3231 	"OSM_SM_SIGNAL_HANDOVER_SENT",	/* 6 */
3232 	"OSM_SM_SIGNAL_ACKNOWLEDGE",	/* 7 */
3233 	"OSM_SM_SIGNAL_STANDBY",	/* 8 */
3234 	"OSM_SM_SIGNAL_MASTER_OR_HIGHER_SM_DETECTED",	/* 9 */
3235 	"OSM_SM_SIGNAL_WAIT_FOR_HANDOVER",	/* 10 */
3236 	"UNKNOWN STATE!!"	/* 11 */
3237 };
3238 
3239 const char *osm_get_sm_mgr_signal_str(IN osm_sm_signal_t signal)
3240 {
3241 	if (signal > OSM_SM_SIGNAL_MAX)
3242 		signal = OSM_SM_SIGNAL_MAX;
3243 	return sm_mgr_signal_str[signal];
3244 }
3245 
3246 static const char *sm_mgr_state_str[] = {
3247 	"NOTACTIVE",		/* 0 */
3248 	"DISCOVERING",		/* 1 */
3249 	"STANDBY",		/* 2 */
3250 	"MASTER",		/* 3 */
3251 	"UNKNOWN STATE!!"	/* 4 */
3252 };
3253 
3254 const char *osm_get_sm_mgr_state_str(IN uint16_t state)
3255 {
3256 	return state < ARR_SIZE(sm_mgr_state_str) ?
3257 	    sm_mgr_state_str[state] :
3258 	    sm_mgr_state_str[ARR_SIZE(sm_mgr_state_str) - 1];
3259 }
3260 
3261 int ib_mtu_is_valid(IN const int mtu)
3262 {
3263 	if (mtu < IB_MIN_MTU || mtu > IB_MAX_MTU)
3264 		return 0;
3265 	return 1;
3266 }
3267 
3268 int ib_rate_is_valid(IN const int rate)
3269 {
3270 	if (rate < IB_MIN_RATE || rate > IB_MAX_RATE)
3271 		return 0;
3272 	return 1;
3273 }
3274 
3275 int ib_path_compare_rates(IN const int rate1, IN const int rate2)
3276 {
3277 	int orate1 = 0, orate2 = 0;
3278 
3279 	CL_ASSERT(rate1 >= IB_MIN_RATE && rate1 <= IB_MAX_RATE);
3280 	CL_ASSERT(rate2 >= IB_MIN_RATE && rate2 <= IB_MAX_RATE);
3281 
3282 	if (rate1 <= IB_MAX_RATE)
3283 		orate1 = ordered_rates[rate1];
3284 	if (rate2 <= IB_MAX_RATE)
3285 		orate2 = ordered_rates[rate2];
3286 	if (orate1 < orate2)
3287 		return -1;
3288 	if (orate1 == orate2)
3289 		return 0;
3290 	return 1;
3291 }
3292 
3293 static int find_ordered_rate(IN const int rate)
3294 {
3295 	int i;
3296 
3297 	for (i = IB_MIN_RATE; i <= IB_MAX_RATE; i++) {
3298 		if (ordered_rates[i] == rate)
3299 			return i;
3300 	}
3301 	return 0;
3302 }
3303 
3304 int ib_path_rate_get_prev(IN const int rate)
3305 {
3306 	int orate;
3307 
3308 	CL_ASSERT(rate >= IB_MIN_RATE && rate <= IB_MAX_RATE);
3309 
3310 	if (rate <= IB_MIN_RATE)
3311 		return 0;
3312 	if (rate > IB_MAX_RATE)
3313 		return 0;
3314 	orate = ordered_rates[rate];
3315 	orate--;
3316 	return find_ordered_rate(orate);
3317 }
3318 
3319 int ib_path_rate_get_next(IN const int rate)
3320 {
3321 	int orate;
3322 
3323 	CL_ASSERT(rate >= IB_MIN_RATE && rate <= IB_MAX_RATE);
3324 
3325 	if (rate < IB_MIN_RATE)
3326 		return 0;
3327 	if (rate >= IB_MAX_RATE)
3328 		return 0;
3329 	orate = ordered_rates[rate];
3330 	orate++;
3331 	return find_ordered_rate(orate);
3332 }
3333