xref: /freebsd/contrib/ofed/infiniband-diags/src/ibdiag_common.h (revision 87181516ef48be852d5e5fee53c6e0dbfc62f21e)
1*d6b92ffaSHans Petter Selasky /*
2*d6b92ffaSHans Petter Selasky  * Copyright (c) 2006-2007 The Regents of the University of California.
3*d6b92ffaSHans Petter Selasky  * Copyright (c) 2004-2009 Voltaire Inc.  All rights reserved.
4*d6b92ffaSHans Petter Selasky  * Copyright (c) 2002-2010 Mellanox Technologies LTD. All rights reserved.
5*d6b92ffaSHans Petter Selasky  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6*d6b92ffaSHans Petter Selasky  * Copyright (c) 2009 HNR Consulting. All rights reserved.
7*d6b92ffaSHans Petter Selasky  * Copyright (c) 2011 Lawrence Livermore National Security. All rights reserved.
8*d6b92ffaSHans Petter Selasky  *
9*d6b92ffaSHans Petter Selasky  * This software is available to you under a choice of one of two
10*d6b92ffaSHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
11*d6b92ffaSHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
12*d6b92ffaSHans Petter Selasky  * COPYING in the main directory of this source tree, or the
13*d6b92ffaSHans Petter Selasky  * OpenIB.org BSD license below:
14*d6b92ffaSHans Petter Selasky  *
15*d6b92ffaSHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
16*d6b92ffaSHans Petter Selasky  *     without modification, are permitted provided that the following
17*d6b92ffaSHans Petter Selasky  *     conditions are met:
18*d6b92ffaSHans Petter Selasky  *
19*d6b92ffaSHans Petter Selasky  *      - Redistributions of source code must retain the above
20*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
21*d6b92ffaSHans Petter Selasky  *        disclaimer.
22*d6b92ffaSHans Petter Selasky  *
23*d6b92ffaSHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
24*d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
25*d6b92ffaSHans Petter Selasky  *        disclaimer in the documentation and/or other materials
26*d6b92ffaSHans Petter Selasky  *        provided with the distribution.
27*d6b92ffaSHans Petter Selasky  *
28*d6b92ffaSHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29*d6b92ffaSHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30*d6b92ffaSHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31*d6b92ffaSHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32*d6b92ffaSHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33*d6b92ffaSHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34*d6b92ffaSHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35*d6b92ffaSHans Petter Selasky  * SOFTWARE.
36*d6b92ffaSHans Petter Selasky  *
37*d6b92ffaSHans Petter Selasky  */
38*d6b92ffaSHans Petter Selasky 
39*d6b92ffaSHans Petter Selasky #ifndef _IBDIAG_COMMON_H_
40*d6b92ffaSHans Petter Selasky #define _IBDIAG_COMMON_H_
41*d6b92ffaSHans Petter Selasky 
42*d6b92ffaSHans Petter Selasky #include <stdarg.h>
43*d6b92ffaSHans Petter Selasky #include <infiniband/mad.h>
44*d6b92ffaSHans Petter Selasky #include <infiniband/iba/ib_types.h>
45*d6b92ffaSHans Petter Selasky #include <infiniband/ibnetdisc.h>
46*d6b92ffaSHans Petter Selasky 
47*d6b92ffaSHans Petter Selasky extern int ibverbose;
48*d6b92ffaSHans Petter Selasky extern char *ibd_ca;
49*d6b92ffaSHans Petter Selasky extern int ibd_ca_port;
50*d6b92ffaSHans Petter Selasky extern enum MAD_DEST ibd_dest_type;
51*d6b92ffaSHans Petter Selasky extern ib_portid_t *ibd_sm_id;
52*d6b92ffaSHans Petter Selasky extern int ibd_timeout;
53*d6b92ffaSHans Petter Selasky extern uint32_t ibd_ibnetdisc_flags;
54*d6b92ffaSHans Petter Selasky extern uint64_t ibd_mkey;
55*d6b92ffaSHans Petter Selasky extern uint64_t ibd_sakey;
56*d6b92ffaSHans Petter Selasky extern int show_keys;
57*d6b92ffaSHans Petter Selasky extern char *ibd_nd_format;
58*d6b92ffaSHans Petter Selasky 
59*d6b92ffaSHans Petter Selasky /*========================================================*/
60*d6b92ffaSHans Petter Selasky /*                External interface                      */
61*d6b92ffaSHans Petter Selasky /*========================================================*/
62*d6b92ffaSHans Petter Selasky 
63*d6b92ffaSHans Petter Selasky #undef DEBUG
64*d6b92ffaSHans Petter Selasky #define DEBUG(fmt, ...) do { \
65*d6b92ffaSHans Petter Selasky 	if (ibdebug) IBDEBUG(fmt, ## __VA_ARGS__); \
66*d6b92ffaSHans Petter Selasky } while (0)
67*d6b92ffaSHans Petter Selasky #define VERBOSE(fmt, ...) do { \
68*d6b92ffaSHans Petter Selasky 	if (ibverbose) IBVERBOSE(fmt, ## __VA_ARGS__); \
69*d6b92ffaSHans Petter Selasky } while (0)
70*d6b92ffaSHans Petter Selasky #define IBEXIT(fmt, ...) ibexit(__FUNCTION__, fmt, ## __VA_ARGS__)
71*d6b92ffaSHans Petter Selasky 
72*d6b92ffaSHans Petter Selasky #define NOT_DISPLAYED_STR "<not displayed>"
73*d6b92ffaSHans Petter Selasky 
74*d6b92ffaSHans Petter Selasky /* not all versions of ib_types.h will have this define */
75*d6b92ffaSHans Petter Selasky #ifndef IB_PM_PC_XMIT_WAIT_SUP
76*d6b92ffaSHans Petter Selasky #define IB_PM_PC_XMIT_WAIT_SUP (CL_HTON16(((uint16_t)1)<<12))
77*d6b92ffaSHans Petter Selasky #endif
78*d6b92ffaSHans Petter Selasky 
79*d6b92ffaSHans Petter Selasky /* PM ClassPortInfo CapabilityMask Bits */
80*d6b92ffaSHans Petter Selasky #ifndef IS_PM_RSFEC_COUNTERS_SUP
81*d6b92ffaSHans Petter Selasky #define IS_PM_RSFEC_COUNTERS_SUP (CL_HTON16(((uint16_t)1)<<14))
82*d6b92ffaSHans Petter Selasky #endif
83*d6b92ffaSHans Petter Selasky 
84*d6b92ffaSHans Petter Selasky #ifndef IB_PM_IS_QP1_DROP_SUP
85*d6b92ffaSHans Petter Selasky #define IB_PM_IS_QP1_DROP_SUP (CL_HTON16(((uint16_t)1)<<15))
86*d6b92ffaSHans Petter Selasky #endif
87*d6b92ffaSHans Petter Selasky 
88*d6b92ffaSHans Petter Selasky /* PM ClassPortInfo CapabilityMask2 Bits */
89*d6b92ffaSHans Petter Selasky #ifndef IB_PM_IS_ADDL_PORT_CTRS_EXT_SUP
90*d6b92ffaSHans Petter Selasky #define IB_PM_IS_ADDL_PORT_CTRS_EXT_SUP (CL_HTON32(((uint32_t)1)<<1))
91*d6b92ffaSHans Petter Selasky #endif
92*d6b92ffaSHans Petter Selasky 
93*d6b92ffaSHans Petter Selasky /* SM PortInfo CapabilityMask2 Bits */
94*d6b92ffaSHans Petter Selasky #ifndef IB_PORT_CAP2_IS_PORT_INFO_EXT_SUPPORTED
95*d6b92ffaSHans Petter Selasky #define IB_PORT_CAP2_IS_PORT_INFO_EXT_SUPPORTED (CL_HTON16(0x0002))
96*d6b92ffaSHans Petter Selasky #endif
97*d6b92ffaSHans Petter Selasky 
98*d6b92ffaSHans Petter Selasky /* SM PortInfoExtended Fec Mode Bits */
99*d6b92ffaSHans Petter Selasky #ifndef IB_PORT_EXT_NO_FEC_MODE_ACTIVE
100*d6b92ffaSHans Petter Selasky #define IB_PORT_EXT_NO_FEC_MODE_ACTIVE 0
101*d6b92ffaSHans Petter Selasky #endif
102*d6b92ffaSHans Petter Selasky 
103*d6b92ffaSHans Petter Selasky #ifndef IB_PORT_EXT_FIRE_CODE_FEC_MODE_ACTIVE
104*d6b92ffaSHans Petter Selasky #define IB_PORT_EXT_FIRE_CODE_FEC_MODE_ACTIVE (CL_HTON16(0x0001))
105*d6b92ffaSHans Petter Selasky #endif
106*d6b92ffaSHans Petter Selasky 
107*d6b92ffaSHans Petter Selasky #ifndef IB_PORT_EXT_RS_FEC_MODE_ACTIVE
108*d6b92ffaSHans Petter Selasky #define IB_PORT_EXT_RS_FEC_MODE_ACTIVE (CL_HTON16(0x0002))
109*d6b92ffaSHans Petter Selasky #endif
110*d6b92ffaSHans Petter Selasky 
111*d6b92ffaSHans Petter Selasky #ifndef IB_PORT_EXT_LOW_LATENCY_RS_FEC_MODE_ACTIVE
112*d6b92ffaSHans Petter Selasky #define IB_PORT_EXT_LOW_LATENCY_RS_FEC_MODE_ACTIVE (CL_HTON16(0x0003))
113*d6b92ffaSHans Petter Selasky #endif
114*d6b92ffaSHans Petter Selasky 
115*d6b92ffaSHans Petter Selasky /* SM PortInfoExtended CapabilityMask Bits */
116*d6b92ffaSHans Petter Selasky #ifndef IB_PORT_EXT_CAP_IS_FEC_MODE_SUPPORTED
117*d6b92ffaSHans Petter Selasky #define IB_PORT_EXT_CAP_IS_FEC_MODE_SUPPORTED (CL_HTON32(0x00000001))
118*d6b92ffaSHans Petter Selasky #endif
119*d6b92ffaSHans Petter Selasky 
120*d6b92ffaSHans Petter Selasky struct ibdiag_opt {
121*d6b92ffaSHans Petter Selasky 	const char *name;
122*d6b92ffaSHans Petter Selasky 	char letter;
123*d6b92ffaSHans Petter Selasky 	unsigned has_arg;
124*d6b92ffaSHans Petter Selasky 	const char *arg_tmpl;
125*d6b92ffaSHans Petter Selasky 	const char *description;
126*d6b92ffaSHans Petter Selasky };
127*d6b92ffaSHans Petter Selasky 
128*d6b92ffaSHans Petter Selasky extern int ibdiag_process_opts(int argc, char *const argv[], void *context,
129*d6b92ffaSHans Petter Selasky 			       const char *exclude_common_str,
130*d6b92ffaSHans Petter Selasky 			       const struct ibdiag_opt custom_opts[],
131*d6b92ffaSHans Petter Selasky 			       int (*custom_handler) (void *cxt, int val,
132*d6b92ffaSHans Petter Selasky 						      char *optarg),
133*d6b92ffaSHans Petter Selasky 			       const char *usage_args,
134*d6b92ffaSHans Petter Selasky 			       const char *usage_examples[]);
135*d6b92ffaSHans Petter Selasky extern void ibdiag_show_usage();
136*d6b92ffaSHans Petter Selasky extern void ibexit(const char *fn, char *msg, ...);
137*d6b92ffaSHans Petter Selasky 
138*d6b92ffaSHans Petter Selasky /* convert counter values to a float with a unit specifier returned (using
139*d6b92ffaSHans Petter Selasky  * binary prefix)
140*d6b92ffaSHans Petter Selasky  * "data" is a flag indicating this counter is a byte counter multiplied by 4
141*d6b92ffaSHans Petter Selasky  * as per PortCounters[Extended]
142*d6b92ffaSHans Petter Selasky  */
143*d6b92ffaSHans Petter Selasky extern char *conv_cnt_human_readable(uint64_t val64, float *val, int data);
144*d6b92ffaSHans Petter Selasky 
145*d6b92ffaSHans Petter Selasky int is_mlnx_ext_port_info_supported(uint32_t vendorid, uint16_t devid);
146*d6b92ffaSHans Petter Selasky 
147*d6b92ffaSHans Petter Selasky int is_port_info_extended_supported(ib_portid_t * dest, int port,
148*d6b92ffaSHans Petter Selasky 				    struct ibmad_port *srcport);
149*d6b92ffaSHans Petter Selasky void get_max_msg(char *width_msg, char *speed_msg, int msg_size,
150*d6b92ffaSHans Petter Selasky 		 ibnd_port_t * port);
151*d6b92ffaSHans Petter Selasky 
152*d6b92ffaSHans Petter Selasky int resolve_sm_portid(char *ca_name, uint8_t portnum, ib_portid_t *sm_id);
153*d6b92ffaSHans Petter Selasky int resolve_self(char *ca_name, uint8_t ca_port, ib_portid_t *portid,
154*d6b92ffaSHans Petter Selasky                  int *port, ibmad_gid_t *gid);
155*d6b92ffaSHans Petter Selasky int resolve_portid_str(char *ca_name, uint8_t ca_port, ib_portid_t * portid,
156*d6b92ffaSHans Petter Selasky 		       char *addr_str, enum MAD_DEST dest_type,
157*d6b92ffaSHans Petter Selasky 		       ib_portid_t *sm_id, const struct ibmad_port *srcport);
158*d6b92ffaSHans Petter Selasky int vsnprint_field(char *buf, size_t n, enum MAD_FIELDS f, int spacing,
159*d6b92ffaSHans Petter Selasky 		   const char *format, va_list va_args);
160*d6b92ffaSHans Petter Selasky int snprint_field(char *buf, size_t n, enum MAD_FIELDS f, int spacing,
161*d6b92ffaSHans Petter Selasky 		  const char *format, ...);
162*d6b92ffaSHans Petter Selasky void dump_portinfo(void *pi, int tabs);
163*d6b92ffaSHans Petter Selasky 
164*d6b92ffaSHans Petter Selasky /**
165*d6b92ffaSHans Petter Selasky  * Some common command line parsing
166*d6b92ffaSHans Petter Selasky  */
167*d6b92ffaSHans Petter Selasky typedef char *(op_fn_t) (ib_portid_t * dest, char **argv, int argc);
168*d6b92ffaSHans Petter Selasky 
169*d6b92ffaSHans Petter Selasky typedef struct match_rec {
170*d6b92ffaSHans Petter Selasky 	const char *name, *alias;
171*d6b92ffaSHans Petter Selasky 	op_fn_t *fn;
172*d6b92ffaSHans Petter Selasky 	unsigned opt_portnum;
173*d6b92ffaSHans Petter Selasky 	char *ops_extra;
174*d6b92ffaSHans Petter Selasky } match_rec_t;
175*d6b92ffaSHans Petter Selasky 
176*d6b92ffaSHans Petter Selasky op_fn_t *match_op(const match_rec_t match_tbl[], char *name);
177*d6b92ffaSHans Petter Selasky 
178*d6b92ffaSHans Petter Selasky #endif				/* _IBDIAG_COMMON_H_ */
179