ibdiag_sa.h revision 321936
1249259Sdim/* 2249259Sdim * Copyright (c) 2006-2007 The Regents of the University of California. 3249259Sdim * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved. 4249259Sdim * Copyright (c) 2002-2010 Mellanox Technologies LTD. All rights reserved. 5249259Sdim * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 6249259Sdim * Copyright (c) 2009 HNR Consulting. All rights reserved. 7249259Sdim * Copyright (c) 2012 Lawrence Livermore National Security. All rights reserved. 8249259Sdim * 9249259Sdim * This software is available to you under a choice of one of two 10249259Sdim * licenses. You may choose to be licensed under the terms of the GNU 11249259Sdim * General Public License (GPL) Version 2, available from the file 12249259Sdim * COPYING in the main directory of this source tree, or the 13249259Sdim * OpenIB.org BSD license below: 14249259Sdim * 15249259Sdim * Redistribution and use in source and binary forms, with or 16249259Sdim * without modification, are permitted provided that the following 17249259Sdim * conditions are met: 18263508Sdim * 19249259Sdim * - Redistributions of source code must retain the above 20249259Sdim * copyright notice, this list of conditions and the following 21249259Sdim * disclaimer. 22249259Sdim * 23249259Sdim * - Redistributions in binary form must reproduce the above 24249259Sdim * copyright notice, this list of conditions and the following 25249259Sdim * disclaimer in the documentation and/or other materials 26249259Sdim * provided with the distribution. 27249259Sdim * 28249259Sdim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 29249259Sdim * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 30249259Sdim * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 31249259Sdim * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 32249259Sdim * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 33249259Sdim * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 34249259Sdim * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 35249259Sdim * SOFTWARE. 36249259Sdim * 37249259Sdim */ 38249259Sdim 39249259Sdim#ifndef _IBDIAG_SA_H_ 40249259Sdim#define _IBDIAG_SA_H_ 41249259Sdim 42249259Sdim#include <infiniband/mad.h> 43249259Sdim#include <infiniband/iba/ib_types.h> 44263508Sdim 45263508Sdim/* define an SA query structure to be common 46263508Sdim * This is by no means optimal but it moves the saquery functionality out of 47263508Sdim * the saquery tool and provides it to other utilities. 48263508Sdim */ 49249259Sdimstruct sa_handle { 50249259Sdim int fd, agent; 51263508Sdim ib_portid_t dport; 52263508Sdim struct ibmad_port *srcport; 53249259Sdim}; 54249259Sdim 55249259Sdimstruct sa_query_result { 56249259Sdim uint32_t status; 57249259Sdim unsigned result_cnt; 58249259Sdim void *p_result_madw; 59249259Sdim}; 60249259Sdim 61249259Sdim/* NOTE: umad_init must be called prior to sa_get_handle */ 62249259Sdimstruct sa_handle * sa_get_handle(void); 63263508Sdimint sa_set_handle(struct sa_handle * handle, int grh_present, ibmad_gid_t *gid); 64263508Sdimvoid sa_free_handle(struct sa_handle * h); 65263508Sdim 66263508Sdimint sa_query(struct sa_handle *h, uint8_t method, 67249259Sdim uint16_t attr, uint32_t mod, uint64_t comp_mask, uint64_t sm_key, 68263508Sdim void *data, size_t datasz, struct sa_query_result *result); 69249259Sdimvoid sa_free_result_mad(struct sa_query_result *result); 70249259Sdimvoid *sa_get_query_rec(void *mad, unsigned i); 71249259Sdimvoid sa_report_err(int status); 72249259Sdim 73249259Sdim/* Macros for setting query values and ComponentMasks */ 74249259Sdim#define cl_hton8(x) (x) 75263508Sdim#define CHECK_AND_SET_VAL(val, size, comp_with, target, name, mask) \ 76263508Sdim if ((int##size##_t) val != (int##size##_t) comp_with) { \ 77263508Sdim target = cl_hton##size((uint##size##_t) val); \ 78263508Sdim comp_mask |= IB_##name##_COMPMASK_##mask; \ 79263508Sdim } 80263508Sdim 81249259Sdim#define CHECK_AND_SET_GID(val, target, name, mask) \ 82249259Sdim if (valid_gid(&(val))) { \ 83249259Sdim memcpy(&(target), &(val), sizeof(val)); \ 84249259Sdim comp_mask |= IB_##name##_COMPMASK_##mask; \ 85249259Sdim } 86249259Sdim 87249259Sdim#define CHECK_AND_SET_VAL_AND_SEL(val, target, name, mask, sel) \ 88249259Sdim if (val) { \ 89249259Sdim target = val; \ 90249259Sdim comp_mask |= IB_##name##_COMPMASK_##mask##sel; \ 91249259Sdim comp_mask |= IB_##name##_COMPMASK_##mask; \ 92249259Sdim } 93249259Sdim 94249259Sdim#endif /* _IBDIAG_SA_H_ */ 95249259Sdim