2 * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
3 * Copyright (c) 2014 Intel Corporation. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 #include <arpa/inet.h>
42 #include <sys/endian.h>
43 #include <linux/types.h> /* __be16, __be32 and __be64 */
45 #include <infiniband/endian.h>
46 #include <infiniband/types.h>
50 # define BEGIN_C_DECLS extern "C" {
51 # define END_C_DECLS }
52 #else /* !__cplusplus */
53 # define BEGIN_C_DECLS
55 #endif /* __cplusplus */
59 typedef __be16 __attribute__((deprecated)) be16_t;
60 typedef __be32 __attribute__((deprecated)) be32_t;
61 typedef __be64 __attribute__((deprecated)) be64_t;
64 * A GID data structure that may be used in definitions of on-the-wire data
65 * structures. Do not cast umad_gid pointers to ibv_gid pointers because the
66 * alignment of these two data structures is different.
75 } __attribute__((aligned(4))) __attribute__((packed));
77 #define UMAD_MAX_DEVICES 32
78 #define UMAD_ANY_PORT 0
79 typedef struct ib_mad_addr {
88 uint8_t traffic_class;
90 uint8_t gid[16]; /* network-byte order */
91 union umad_gid ib_gid;
98 typedef struct ib_user_mad {
108 #define IB_UMAD_ABI_VERSION 5
109 #define IB_UMAD_ABI_DIR "/sys/class/infiniband_mad"
110 #define IB_UMAD_ABI_FILE "abi_version"
112 #define IB_IOCTL_MAGIC 0x1b
114 #define IB_USER_MAD_REGISTER_AGENT \
115 _IOWR(IB_IOCTL_MAGIC, 1, uint8_t [28] /* struct ib_user_mad_reg_req */)
116 #define IB_USER_MAD_UNREGISTER_AGENT _IOW(IB_IOCTL_MAGIC, 2, uint32_t)
117 #define IB_USER_MAD_ENABLE_PKEY _IO(IB_IOCTL_MAGIC, 3)
118 #define IB_USER_MAD_REGISTER_AGENT2 \
119 _IOWR(IB_IOCTL_MAGIC, 4, uint8_t [40] /* struct ib_user_mad_reg_req2 */)
121 #define UMAD_CA_NAME_LEN 20
122 #define UMAD_CA_MAX_PORTS 10 /* 0 - 9 */
123 #define UMAD_CA_MAX_AGENTS 32
125 #define SYS_INFINIBAND "/sys/class/infiniband"
127 #define SYS_INFINIBAND_MAD "/sys/class/infiniband_mad"
128 #define SYS_IB_MAD_PORT "port"
129 #define SYS_IB_MAD_DEV "ibdev"
131 #define UMAD_MAX_PORTS 64
133 #define UMAD_DEV_DIR "/dev"
135 #define SYS_CA_PORTS_DIR "ports"
137 #define SYS_NODE_TYPE "node_type"
138 #define SYS_CA_FW_VERS "fw_ver"
139 #define SYS_CA_HW_VERS "hw_rev"
140 #define SYS_CA_TYPE "hca_type"
141 #define SYS_CA_NODE_GUID "node_guid"
142 #define SYS_CA_SYS_GUID "sys_image_guid"
144 #define SYS_PORT_LMC "lid_mask_count"
145 #define SYS_PORT_SMLID "sm_lid"
146 #define SYS_PORT_SMSL "sm_sl"
147 #define SYS_PORT_LID "lid"
148 #define SYS_PORT_STATE "state"
149 #define SYS_PORT_PHY_STATE "phys_state"
150 #define SYS_PORT_CAPMASK "cap_mask"
151 #define SYS_PORT_RATE "rate"
152 #define SYS_PORT_GUID "port_guid"
153 #define SYS_PORT_GID "gids/0"
154 #define SYS_PORT_LINK_LAYER "link_layer"
156 typedef struct umad_port {
157 char ca_name[UMAD_CA_NAME_LEN];
171 char link_layer[UMAD_CA_NAME_LEN];
174 typedef struct umad_ca {
175 char ca_name[UMAD_CA_NAME_LEN];
183 umad_port_t *ports[UMAD_CA_MAX_PORTS];
189 int umad_get_cas_names(char cas[][UMAD_CA_NAME_LEN], int max);
190 int umad_get_ca_portguids(const char *ca_name, __be64 *portguids, int max);
192 int umad_get_ca(const char *ca_name, umad_ca_t * ca);
193 int umad_release_ca(umad_ca_t * ca);
194 int umad_get_port(const char *ca_name, int portnum, umad_port_t * port);
195 int umad_release_port(umad_port_t * port);
197 int umad_get_issm_path(const char *ca_name, int portnum, char path[], int max);
199 int umad_open_port(const char *ca_name, int portnum);
200 int umad_close_port(int portid);
202 void *umad_get_mad(void *umad);
203 size_t umad_size(void);
204 int umad_status(void *umad);
206 ib_mad_addr_t *umad_get_mad_addr(void *umad);
207 int umad_set_grh_net(void *umad, void *mad_addr);
208 int umad_set_grh(void *umad, void *mad_addr);
209 int umad_set_addr_net(void *umad, __be16 dlid, __be32 dqp, int sl, __be32 qkey);
210 int umad_set_addr(void *umad, int dlid, int dqp, int sl, int qkey);
211 int umad_set_pkey(void *umad, int pkey_index);
212 int umad_get_pkey(void *umad);
214 int umad_send(int portid, int agentid, void *umad, int length,
215 int timeout_ms, int retries);
216 int umad_recv(int portid, void *umad, int *length, int timeout_ms);
217 int umad_poll(int portid, int timeout_ms);
218 int umad_get_fd(int portid);
220 int umad_register(int portid, int mgmt_class, int mgmt_version,
221 uint8_t rmpp_version, long method_mask[16 / sizeof(long)]);
222 int umad_register_oui(int portid, int mgmt_class, uint8_t rmpp_version,
223 uint8_t oui[3], long method_mask[16 / sizeof(long)]);
224 int umad_unregister(int portid, int agentid);
227 UMAD_USER_RMPP = (1 << 0)
230 struct umad_reg_attr {
232 uint8_t mgmt_class_version;
234 uint64_t method_mask[2];
236 uint8_t rmpp_version;
239 int umad_register2(int port_fd, struct umad_reg_attr *attr,
242 int umad_debug(int level);
243 void umad_addr_dump(ib_mad_addr_t * addr);
244 void umad_dump(void *umad);
246 static inline void *umad_alloc(int num, size_t size)
247 { /* alloc array of umad buffers */
248 return calloc(num, size);
251 static inline void umad_free(void *umad)
256 /* Users should use the glibc functions directly, not these wrappers */
259 static inline __attribute__((deprecated)) uint64_t ntohll(uint64_t x) { return be64toh(x); }
260 #define ntohll ntohll
264 static inline __attribute__((deprecated)) uint64_t htonll(uint64_t x) { return htobe64(x); }
265 #define htonll htonll