1 /*
2  * Copyright (c) 2006-2007 The Regents of the University of California.
3  * Copyright (c) 2004-2009 Voltaire Inc.  All rights reserved.
4  * Copyright (c) 2002-2010 Mellanox Technologies LTD. All rights reserved.
5  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6  * Copyright (c) 2009 HNR Consulting. All rights reserved.
7  * Copyright (c) 2012 Lawrence Livermore National Security. All rights reserved.
8  *
9  * This software is available to you under a choice of one of two
10  * licenses.  You may choose to be licensed under the terms of the GNU
11  * General Public License (GPL) Version 2, available from the file
12  * COPYING in the main directory of this source tree, or the
13  * OpenIB.org BSD license below:
14  *
15  *     Redistribution and use in source and binary forms, with or
16  *     without modification, are permitted provided that the following
17  *     conditions are met:
18  *
19  *      - Redistributions of source code must retain the above
20  *        copyright notice, this list of conditions and the following
21  *        disclaimer.
22  *
23  *      - Redistributions in binary form must reproduce the above
24  *        copyright notice, this list of conditions and the following
25  *        disclaimer in the documentation and/or other materials
26  *        provided with the distribution.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35  * SOFTWARE.
36  *
37  */
38 
39 #ifndef _IBDIAG_SA_H_
40 #define _IBDIAG_SA_H_
41 
42 #include <infiniband/mad.h>
43 #include <infiniband/iba/ib_types.h>
44 
45 /* define an SA query structure to be common
46  * This is by no means optimal but it moves the saquery functionality out of
47  * the saquery tool and provides it to other utilities.
48  */
49 struct sa_handle {
50 	int fd, agent;
51 	ib_portid_t dport;
52 	struct ibmad_port *srcport;
53 };
54 
55 struct sa_query_result {
56 	uint32_t status;
57 	unsigned result_cnt;
58 	void *p_result_madw;
59 };
60 
61 /* NOTE: umad_init must be called prior to sa_get_handle */
62 struct sa_handle * sa_get_handle(void);
63 int sa_set_handle(struct sa_handle * handle, int grh_present, ibmad_gid_t *gid);
64 void sa_free_handle(struct sa_handle * h);
65 
66 int sa_query(struct sa_handle *h, uint8_t method,
67 	     uint16_t attr, uint32_t mod, uint64_t comp_mask, uint64_t sm_key,
68 	     void *data, size_t datasz, struct sa_query_result *result);
69 void sa_free_result_mad(struct sa_query_result *result);
70 void *sa_get_query_rec(void *mad, unsigned i);
71 void sa_report_err(int status);
72 
73 /* Macros for setting query values and ComponentMasks */
74 #define cl_hton8(x) (x)
75 #define CHECK_AND_SET_VAL(val, size, comp_with, target, name, mask) \
76 	if ((int##size##_t) val != (int##size##_t) comp_with) { \
77 		target = cl_hton##size((uint##size##_t) val); \
78 		comp_mask |= IB_##name##_COMPMASK_##mask; \
79 	}
80 
81 #define CHECK_AND_SET_GID(val, target, name, mask) \
82 	if (valid_gid(&(val))) { \
83 		memcpy(&(target), &(val), sizeof(val)); \
84 		comp_mask |= IB_##name##_COMPMASK_##mask; \
85 	}
86 
87 #define CHECK_AND_SET_VAL_AND_SEL(val, target, name, mask, sel) \
88 	if (val) { \
89 		target = val; \
90 		comp_mask |= IB_##name##_COMPMASK_##mask##sel; \
91 		comp_mask |= IB_##name##_COMPMASK_##mask; \
92 	}
93 
94 #endif /* _IBDIAG_SA_H_ */
95