ibdiag_sa.h revision 329564
1264391Snwhitehorn/*
2264391Snwhitehorn * Copyright (c) 2006-2007 The Regents of the University of California.
3264925Simp * Copyright (c) 2004-2009 Voltaire Inc.  All rights reserved.
4264391Snwhitehorn * Copyright (c) 2002-2010 Mellanox Technologies LTD. All rights reserved.
5264391Snwhitehorn * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6264391Snwhitehorn * Copyright (c) 2009 HNR Consulting. All rights reserved.
7264391Snwhitehorn * Copyright (c) 2012 Lawrence Livermore National Security. All rights reserved.
8264391Snwhitehorn *
9264391Snwhitehorn * This software is available to you under a choice of one of two
10264391Snwhitehorn * licenses.  You may choose to be licensed under the terms of the GNU
11264391Snwhitehorn * General Public License (GPL) Version 2, available from the file
12264391Snwhitehorn * COPYING in the main directory of this source tree, or the
13264391Snwhitehorn * OpenIB.org BSD license below:
14264391Snwhitehorn *
15264391Snwhitehorn *     Redistribution and use in source and binary forms, with or
16264391Snwhitehorn *     without modification, are permitted provided that the following
17264391Snwhitehorn *     conditions are met:
18264391Snwhitehorn *
19280950Sandrew *      - Redistributions of source code must retain the above
20281524Sandrew *        copyright notice, this list of conditions and the following
21264391Snwhitehorn *        disclaimer.
22264391Snwhitehorn *
23264391Snwhitehorn *      - Redistributions in binary form must reproduce the above
24264403Snwhitehorn *        copyright notice, this list of conditions and the following
25281524Sandrew *        disclaimer in the documentation and/or other materials
26281237Semaste *        provided with the distribution.
27281237Semaste *
28264391Snwhitehorn * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29264391Snwhitehorn * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30264975Snwhitehorn * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31264391Snwhitehorn * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32264391Snwhitehorn * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33281524Sandrew * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34281027Sandrew * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35264391Snwhitehorn * SOFTWARE.
36282474Sandrew *
37282474Sandrew */
38282474Sandrew
39281027Sandrew#ifndef _IBDIAG_SA_H_
40281300Sandrew#define _IBDIAG_SA_H_
41281027Sandrew
42281027Sandrew#include <infiniband/mad.h>
43281027Sandrew#include <infiniband/iba/ib_types.h>
44281238Semaste
45281156Sandrew/* define an SA query structure to be common
46281238Semaste * This is by no means optimal but it moves the saquery functionality out of
47281238Semaste * the saquery tool and provides it to other utilities.
48281156Sandrew */
49281156Sandrewstruct sa_handle {
50281156Sandrew	int fd, agent;
51281156Sandrew	ib_portid_t dport;
52281156Sandrew	struct ibmad_port *srcport;
53264391Snwhitehorn};
54264391Snwhitehorn
55264391Snwhitehornstruct sa_query_result {
56264391Snwhitehorn	uint32_t status;
57264391Snwhitehorn	unsigned result_cnt;
58264391Snwhitehorn	void *p_result_madw;
59264391Snwhitehorn};
60280950Sandrew
61264391Snwhitehorn/* NOTE: umad_init must be called prior to sa_get_handle */
62281156Sandrewstruct sa_handle * sa_get_handle(void);
63281156Sandrewint sa_set_handle(struct sa_handle * handle, int grh_present, ibmad_gid_t *gid);
64264391Snwhitehornvoid sa_free_handle(struct sa_handle * h);
65264391Snwhitehorn
66264391Snwhitehornint sa_query(struct sa_handle *h, uint8_t method,
67264391Snwhitehorn	     uint16_t attr, uint32_t mod, uint64_t comp_mask, uint64_t sm_key,
68264391Snwhitehorn	     void *data, size_t datasz, struct sa_query_result *result);
69264391Snwhitehornvoid sa_free_result_mad(struct sa_query_result *result);
70264391Snwhitehornvoid *sa_get_query_rec(void *mad, unsigned i);
71281156Sandrewvoid sa_report_err(int status);
72264391Snwhitehorn
73264391Snwhitehorn/* Macros for setting query values and ComponentMasks */
74276146Semaste#define cl_hton8(x) (x)
75264391Snwhitehorn#define CHECK_AND_SET_VAL(val, size, comp_with, target, name, mask) \
76264414Snwhitehorn	if ((int##size##_t) val != (int##size##_t) comp_with) { \
77264414Snwhitehorn		target = cl_hton##size((uint##size##_t) val); \
78264975Snwhitehorn		comp_mask |= IB_##name##_COMPMASK_##mask; \
79264975Snwhitehorn	}
80264975Snwhitehorn
81264975Snwhitehorn#define CHECK_AND_SET_GID(val, target, name, mask) \
82264975Snwhitehorn	if (valid_gid(&(val))) { \
83264975Snwhitehorn		memcpy(&(target), &(val), sizeof(val)); \
84264975Snwhitehorn		comp_mask |= IB_##name##_COMPMASK_##mask; \
85281524Sandrew	}
86281524Sandrew
87264975Snwhitehorn#define CHECK_AND_SET_VAL_AND_SEL(val, target, name, mask, sel) \
88264975Snwhitehorn	if (val) { \
89264975Snwhitehorn		target = val; \
90281117Sandrew		comp_mask |= IB_##name##_COMPMASK_##mask##sel; \
91264975Snwhitehorn		comp_mask |= IB_##name##_COMPMASK_##mask; \
92264391Snwhitehorn	}
93264391Snwhitehorn
94264391Snwhitehorn#endif /* _IBDIAG_SA_H_ */
95264391Snwhitehorn