1d6b92ffaSHans Petter Selasky /*
2d6b92ffaSHans Petter Selasky * Copyright (c) 2004-2009 Voltaire Inc. All rights reserved.
3d6b92ffaSHans Petter Selasky * Copyright (c) 2014 Intel Corporation. All rights reserved.
4d6b92ffaSHans Petter Selasky *
5d6b92ffaSHans Petter Selasky * This software is available to you under a choice of one of two
6d6b92ffaSHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU
7d6b92ffaSHans Petter Selasky * General Public License (GPL) Version 2, available from the file
8d6b92ffaSHans Petter Selasky * COPYING in the main directory of this source tree, or the
9d6b92ffaSHans Petter Selasky * OpenIB.org BSD license below:
10d6b92ffaSHans Petter Selasky *
11d6b92ffaSHans Petter Selasky * Redistribution and use in source and binary forms, with or
12d6b92ffaSHans Petter Selasky * without modification, are permitted provided that the following
13d6b92ffaSHans Petter Selasky * conditions are met:
14d6b92ffaSHans Petter Selasky *
15d6b92ffaSHans Petter Selasky * - Redistributions of source code must retain the above
16d6b92ffaSHans Petter Selasky * copyright notice, this list of conditions and the following
17d6b92ffaSHans Petter Selasky * disclaimer.
18d6b92ffaSHans Petter Selasky *
19d6b92ffaSHans Petter Selasky * - Redistributions in binary form must reproduce the above
20d6b92ffaSHans Petter Selasky * copyright notice, this list of conditions and the following
21d6b92ffaSHans Petter Selasky * disclaimer in the documentation and/or other materials
22d6b92ffaSHans Petter Selasky * provided with the distribution.
23d6b92ffaSHans Petter Selasky *
24d6b92ffaSHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25d6b92ffaSHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26d6b92ffaSHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27d6b92ffaSHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28d6b92ffaSHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29d6b92ffaSHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30d6b92ffaSHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31d6b92ffaSHans Petter Selasky * SOFTWARE.
32d6b92ffaSHans Petter Selasky *
33d6b92ffaSHans Petter Selasky */
34d6b92ffaSHans Petter Selasky #ifndef _UMAD_H
35d6b92ffaSHans Petter Selasky #define _UMAD_H
36d6b92ffaSHans Petter Selasky
37d6b92ffaSHans Petter Selasky #include <stdint.h>
38d6b92ffaSHans Petter Selasky #include <stdlib.h>
39d6b92ffaSHans Petter Selasky #include <arpa/inet.h>
40d6b92ffaSHans Petter Selasky
41d6b92ffaSHans Petter Selasky #ifdef _KERNEL
42d6b92ffaSHans Petter Selasky #include <sys/endian.h>
43d6b92ffaSHans Petter Selasky #include <linux/types.h> /* __be16, __be32 and __be64 */
44d6b92ffaSHans Petter Selasky #else
45d6b92ffaSHans Petter Selasky #include <infiniband/endian.h>
46d6b92ffaSHans Petter Selasky #include <infiniband/types.h>
47d6b92ffaSHans Petter Selasky #endif
48d6b92ffaSHans Petter Selasky
49d6b92ffaSHans Petter Selasky #ifdef __cplusplus
50d6b92ffaSHans Petter Selasky # define BEGIN_C_DECLS extern "C" {
51d6b92ffaSHans Petter Selasky # define END_C_DECLS }
52d6b92ffaSHans Petter Selasky #else /* !__cplusplus */
53d6b92ffaSHans Petter Selasky # define BEGIN_C_DECLS
54d6b92ffaSHans Petter Selasky # define END_C_DECLS
55d6b92ffaSHans Petter Selasky #endif /* __cplusplus */
56d6b92ffaSHans Petter Selasky
57d6b92ffaSHans Petter Selasky BEGIN_C_DECLS
58d6b92ffaSHans Petter Selasky
59d6b92ffaSHans Petter Selasky typedef __be16 __attribute__((deprecated)) be16_t;
60d6b92ffaSHans Petter Selasky typedef __be32 __attribute__((deprecated)) be32_t;
61d6b92ffaSHans Petter Selasky typedef __be64 __attribute__((deprecated)) be64_t;
62d6b92ffaSHans Petter Selasky
63d6b92ffaSHans Petter Selasky /*
64d6b92ffaSHans Petter Selasky * A GID data structure that may be used in definitions of on-the-wire data
65d6b92ffaSHans Petter Selasky * structures. Do not cast umad_gid pointers to ibv_gid pointers because the
66d6b92ffaSHans Petter Selasky * alignment of these two data structures is different.
67d6b92ffaSHans Petter Selasky */
68d6b92ffaSHans Petter Selasky union umad_gid {
69d6b92ffaSHans Petter Selasky uint8_t raw[16];
70d6b92ffaSHans Petter Selasky __be16 raw_be16[8];
71d6b92ffaSHans Petter Selasky struct {
72d6b92ffaSHans Petter Selasky __be64 subnet_prefix;
73d6b92ffaSHans Petter Selasky __be64 interface_id;
74d6b92ffaSHans Petter Selasky } global;
75d6b92ffaSHans Petter Selasky } __attribute__((aligned(4))) __attribute__((packed));
76d6b92ffaSHans Petter Selasky
77d6b92ffaSHans Petter Selasky #define UMAD_MAX_DEVICES 32
78d6b92ffaSHans Petter Selasky #define UMAD_ANY_PORT 0
79d6b92ffaSHans Petter Selasky typedef struct ib_mad_addr {
80d6b92ffaSHans Petter Selasky __be32 qpn;
81d6b92ffaSHans Petter Selasky __be32 qkey;
82d6b92ffaSHans Petter Selasky __be16 lid;
83d6b92ffaSHans Petter Selasky uint8_t sl;
84d6b92ffaSHans Petter Selasky uint8_t path_bits;
85d6b92ffaSHans Petter Selasky uint8_t grh_present;
86d6b92ffaSHans Petter Selasky uint8_t gid_index;
87d6b92ffaSHans Petter Selasky uint8_t hop_limit;
88d6b92ffaSHans Petter Selasky uint8_t traffic_class;
89d6b92ffaSHans Petter Selasky union {
90d6b92ffaSHans Petter Selasky uint8_t gid[16]; /* network-byte order */
91d6b92ffaSHans Petter Selasky union umad_gid ib_gid;
92d6b92ffaSHans Petter Selasky };
93d6b92ffaSHans Petter Selasky __be32 flow_label;
94d6b92ffaSHans Petter Selasky uint16_t pkey_index;
95d6b92ffaSHans Petter Selasky uint8_t reserved[6];
96d6b92ffaSHans Petter Selasky } ib_mad_addr_t;
97d6b92ffaSHans Petter Selasky
98d6b92ffaSHans Petter Selasky typedef struct ib_user_mad {
99d6b92ffaSHans Petter Selasky uint32_t agent_id;
100d6b92ffaSHans Petter Selasky uint32_t status;
101d6b92ffaSHans Petter Selasky uint32_t timeout_ms;
102d6b92ffaSHans Petter Selasky uint32_t retries;
103d6b92ffaSHans Petter Selasky uint32_t length;
104d6b92ffaSHans Petter Selasky ib_mad_addr_t addr;
105d6b92ffaSHans Petter Selasky uint8_t data[0];
106d6b92ffaSHans Petter Selasky } ib_user_mad_t;
107d6b92ffaSHans Petter Selasky
108d6b92ffaSHans Petter Selasky #define IB_UMAD_ABI_VERSION 5
109d6b92ffaSHans Petter Selasky #define IB_UMAD_ABI_DIR "/sys/class/infiniband_mad"
110d6b92ffaSHans Petter Selasky #define IB_UMAD_ABI_FILE "abi_version"
111d6b92ffaSHans Petter Selasky
112d6b92ffaSHans Petter Selasky #define IB_IOCTL_MAGIC 0x1b
113d6b92ffaSHans Petter Selasky
114*7093892cSHans Petter Selasky #define IB_USER_MAD_REGISTER_AGENT \
115*7093892cSHans Petter Selasky _IOWR(IB_IOCTL_MAGIC, 1, uint8_t [28] /* struct ib_user_mad_reg_req */)
116d6b92ffaSHans Petter Selasky #define IB_USER_MAD_UNREGISTER_AGENT _IOW(IB_IOCTL_MAGIC, 2, uint32_t)
117d6b92ffaSHans Petter Selasky #define IB_USER_MAD_ENABLE_PKEY _IO(IB_IOCTL_MAGIC, 3)
118*7093892cSHans Petter Selasky #define IB_USER_MAD_REGISTER_AGENT2 \
119*7093892cSHans Petter Selasky _IOWR(IB_IOCTL_MAGIC, 4, uint8_t [40] /* struct ib_user_mad_reg_req2 */)
120d6b92ffaSHans Petter Selasky
121d6b92ffaSHans Petter Selasky #define UMAD_CA_NAME_LEN 20
122d6b92ffaSHans Petter Selasky #define UMAD_CA_MAX_PORTS 10 /* 0 - 9 */
123d6b92ffaSHans Petter Selasky #define UMAD_CA_MAX_AGENTS 32
124d6b92ffaSHans Petter Selasky
125d6b92ffaSHans Petter Selasky #define SYS_INFINIBAND "/sys/class/infiniband"
126d6b92ffaSHans Petter Selasky
127d6b92ffaSHans Petter Selasky #define SYS_INFINIBAND_MAD "/sys/class/infiniband_mad"
128d6b92ffaSHans Petter Selasky #define SYS_IB_MAD_PORT "port"
129d6b92ffaSHans Petter Selasky #define SYS_IB_MAD_DEV "ibdev"
130d6b92ffaSHans Petter Selasky
131d6b92ffaSHans Petter Selasky #define UMAD_MAX_PORTS 64
132d6b92ffaSHans Petter Selasky
133d6b92ffaSHans Petter Selasky #define UMAD_DEV_DIR "/dev"
134d6b92ffaSHans Petter Selasky
135d6b92ffaSHans Petter Selasky #define SYS_CA_PORTS_DIR "ports"
136d6b92ffaSHans Petter Selasky
137d6b92ffaSHans Petter Selasky #define SYS_NODE_TYPE "node_type"
138d6b92ffaSHans Petter Selasky #define SYS_CA_FW_VERS "fw_ver"
139d6b92ffaSHans Petter Selasky #define SYS_CA_HW_VERS "hw_rev"
140d6b92ffaSHans Petter Selasky #define SYS_CA_TYPE "hca_type"
141d6b92ffaSHans Petter Selasky #define SYS_CA_NODE_GUID "node_guid"
142d6b92ffaSHans Petter Selasky #define SYS_CA_SYS_GUID "sys_image_guid"
143d6b92ffaSHans Petter Selasky
144d6b92ffaSHans Petter Selasky #define SYS_PORT_LMC "lid_mask_count"
145d6b92ffaSHans Petter Selasky #define SYS_PORT_SMLID "sm_lid"
146d6b92ffaSHans Petter Selasky #define SYS_PORT_SMSL "sm_sl"
147d6b92ffaSHans Petter Selasky #define SYS_PORT_LID "lid"
148d6b92ffaSHans Petter Selasky #define SYS_PORT_STATE "state"
149d6b92ffaSHans Petter Selasky #define SYS_PORT_PHY_STATE "phys_state"
150d6b92ffaSHans Petter Selasky #define SYS_PORT_CAPMASK "cap_mask"
151d6b92ffaSHans Petter Selasky #define SYS_PORT_RATE "rate"
152d6b92ffaSHans Petter Selasky #define SYS_PORT_GUID "port_guid"
153d6b92ffaSHans Petter Selasky #define SYS_PORT_GID "gids/0"
154d6b92ffaSHans Petter Selasky #define SYS_PORT_LINK_LAYER "link_layer"
155d6b92ffaSHans Petter Selasky
156d6b92ffaSHans Petter Selasky typedef struct umad_port {
157d6b92ffaSHans Petter Selasky char ca_name[UMAD_CA_NAME_LEN];
158d6b92ffaSHans Petter Selasky int portnum;
159d6b92ffaSHans Petter Selasky unsigned base_lid;
160d6b92ffaSHans Petter Selasky unsigned lmc;
161d6b92ffaSHans Petter Selasky unsigned sm_lid;
162d6b92ffaSHans Petter Selasky unsigned sm_sl;
163d6b92ffaSHans Petter Selasky unsigned state;
164d6b92ffaSHans Petter Selasky unsigned phys_state;
165d6b92ffaSHans Petter Selasky unsigned rate;
166d6b92ffaSHans Petter Selasky __be32 capmask;
167d6b92ffaSHans Petter Selasky __be64 gid_prefix;
168d6b92ffaSHans Petter Selasky __be64 port_guid;
169d6b92ffaSHans Petter Selasky unsigned pkeys_size;
170d6b92ffaSHans Petter Selasky uint16_t *pkeys;
171d6b92ffaSHans Petter Selasky char link_layer[UMAD_CA_NAME_LEN];
172d6b92ffaSHans Petter Selasky } umad_port_t;
173d6b92ffaSHans Petter Selasky
174d6b92ffaSHans Petter Selasky typedef struct umad_ca {
175d6b92ffaSHans Petter Selasky char ca_name[UMAD_CA_NAME_LEN];
176d6b92ffaSHans Petter Selasky unsigned node_type;
177d6b92ffaSHans Petter Selasky int numports;
178d6b92ffaSHans Petter Selasky char fw_ver[20];
179d6b92ffaSHans Petter Selasky char ca_type[40];
180d6b92ffaSHans Petter Selasky char hw_ver[20];
181d6b92ffaSHans Petter Selasky __be64 node_guid;
182d6b92ffaSHans Petter Selasky __be64 system_guid;
183d6b92ffaSHans Petter Selasky umad_port_t *ports[UMAD_CA_MAX_PORTS];
184d6b92ffaSHans Petter Selasky } umad_ca_t;
185d6b92ffaSHans Petter Selasky
186d6b92ffaSHans Petter Selasky int umad_init(void);
187d6b92ffaSHans Petter Selasky int umad_done(void);
188d6b92ffaSHans Petter Selasky
189d6b92ffaSHans Petter Selasky int umad_get_cas_names(char cas[][UMAD_CA_NAME_LEN], int max);
190d6b92ffaSHans Petter Selasky int umad_get_ca_portguids(const char *ca_name, __be64 *portguids, int max);
191d6b92ffaSHans Petter Selasky
192d6b92ffaSHans Petter Selasky int umad_get_ca(const char *ca_name, umad_ca_t * ca);
193d6b92ffaSHans Petter Selasky int umad_release_ca(umad_ca_t * ca);
194d6b92ffaSHans Petter Selasky int umad_get_port(const char *ca_name, int portnum, umad_port_t * port);
195d6b92ffaSHans Petter Selasky int umad_release_port(umad_port_t * port);
196d6b92ffaSHans Petter Selasky
197d6b92ffaSHans Petter Selasky int umad_get_issm_path(const char *ca_name, int portnum, char path[], int max);
198d6b92ffaSHans Petter Selasky
199d6b92ffaSHans Petter Selasky int umad_open_port(const char *ca_name, int portnum);
200d6b92ffaSHans Petter Selasky int umad_close_port(int portid);
201d6b92ffaSHans Petter Selasky
202d6b92ffaSHans Petter Selasky void *umad_get_mad(void *umad);
203d6b92ffaSHans Petter Selasky size_t umad_size(void);
204d6b92ffaSHans Petter Selasky int umad_status(void *umad);
205d6b92ffaSHans Petter Selasky
206d6b92ffaSHans Petter Selasky ib_mad_addr_t *umad_get_mad_addr(void *umad);
207d6b92ffaSHans Petter Selasky int umad_set_grh_net(void *umad, void *mad_addr);
208d6b92ffaSHans Petter Selasky int umad_set_grh(void *umad, void *mad_addr);
209d6b92ffaSHans Petter Selasky int umad_set_addr_net(void *umad, __be16 dlid, __be32 dqp, int sl, __be32 qkey);
210d6b92ffaSHans Petter Selasky int umad_set_addr(void *umad, int dlid, int dqp, int sl, int qkey);
211d6b92ffaSHans Petter Selasky int umad_set_pkey(void *umad, int pkey_index);
212d6b92ffaSHans Petter Selasky int umad_get_pkey(void *umad);
213d6b92ffaSHans Petter Selasky
214d6b92ffaSHans Petter Selasky int umad_send(int portid, int agentid, void *umad, int length,
215d6b92ffaSHans Petter Selasky int timeout_ms, int retries);
216d6b92ffaSHans Petter Selasky int umad_recv(int portid, void *umad, int *length, int timeout_ms);
217d6b92ffaSHans Petter Selasky int umad_poll(int portid, int timeout_ms);
218d6b92ffaSHans Petter Selasky int umad_get_fd(int portid);
219d6b92ffaSHans Petter Selasky
220d6b92ffaSHans Petter Selasky int umad_register(int portid, int mgmt_class, int mgmt_version,
221d6b92ffaSHans Petter Selasky uint8_t rmpp_version, long method_mask[16 / sizeof(long)]);
222d6b92ffaSHans Petter Selasky int umad_register_oui(int portid, int mgmt_class, uint8_t rmpp_version,
223d6b92ffaSHans Petter Selasky uint8_t oui[3], long method_mask[16 / sizeof(long)]);
224d6b92ffaSHans Petter Selasky int umad_unregister(int portid, int agentid);
225d6b92ffaSHans Petter Selasky
226d6b92ffaSHans Petter Selasky enum {
227d6b92ffaSHans Petter Selasky UMAD_USER_RMPP = (1 << 0)
228d6b92ffaSHans Petter Selasky };
229d6b92ffaSHans Petter Selasky
230d6b92ffaSHans Petter Selasky struct umad_reg_attr {
231d6b92ffaSHans Petter Selasky uint8_t mgmt_class;
232d6b92ffaSHans Petter Selasky uint8_t mgmt_class_version;
233d6b92ffaSHans Petter Selasky uint32_t flags;
234d6b92ffaSHans Petter Selasky uint64_t method_mask[2];
235d6b92ffaSHans Petter Selasky uint32_t oui;
236d6b92ffaSHans Petter Selasky uint8_t rmpp_version;
237d6b92ffaSHans Petter Selasky };
238d6b92ffaSHans Petter Selasky
239d6b92ffaSHans Petter Selasky int umad_register2(int port_fd, struct umad_reg_attr *attr,
240d6b92ffaSHans Petter Selasky uint32_t *agent_id);
241d6b92ffaSHans Petter Selasky
242d6b92ffaSHans Petter Selasky int umad_debug(int level);
243d6b92ffaSHans Petter Selasky void umad_addr_dump(ib_mad_addr_t * addr);
244d6b92ffaSHans Petter Selasky void umad_dump(void *umad);
245d6b92ffaSHans Petter Selasky
umad_alloc(int num,size_t size)246d6b92ffaSHans Petter Selasky static inline void *umad_alloc(int num, size_t size)
247d6b92ffaSHans Petter Selasky { /* alloc array of umad buffers */
248d6b92ffaSHans Petter Selasky return calloc(num, size);
249d6b92ffaSHans Petter Selasky }
250d6b92ffaSHans Petter Selasky
umad_free(void * umad)251d6b92ffaSHans Petter Selasky static inline void umad_free(void *umad)
252d6b92ffaSHans Petter Selasky {
253d6b92ffaSHans Petter Selasky free(umad);
254d6b92ffaSHans Petter Selasky }
255d6b92ffaSHans Petter Selasky
256d6b92ffaSHans Petter Selasky /* Users should use the glibc functions directly, not these wrappers */
257d6b92ffaSHans Petter Selasky #ifndef ntohll
258d6b92ffaSHans Petter Selasky #undef ntohll
ntohll(uint64_t x)259d6b92ffaSHans Petter Selasky static inline __attribute__((deprecated)) uint64_t ntohll(uint64_t x) { return be64toh(x); }
260d6b92ffaSHans Petter Selasky #define ntohll ntohll
261d6b92ffaSHans Petter Selasky #endif
262d6b92ffaSHans Petter Selasky #ifndef htonll
263d6b92ffaSHans Petter Selasky #undef htonll
htonll(uint64_t x)264d6b92ffaSHans Petter Selasky static inline __attribute__((deprecated)) uint64_t htonll(uint64_t x) { return htobe64(x); }
265d6b92ffaSHans Petter Selasky #define htonll htonll
266d6b92ffaSHans Petter Selasky #endif
267d6b92ffaSHans Petter Selasky
268d6b92ffaSHans Petter Selasky END_C_DECLS
269d6b92ffaSHans Petter Selasky #endif /* _UMAD_H */
270