]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ofed/management/libibumad/include/infiniband/umad.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ofed / management / libibumad / include / infiniband / umad.h
1 /*
2  * Copyright (c) 2004-2008 Voltaire Inc.  All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  *
32  */
33 #ifndef _UMAD_H
34 #define _UMAD_H
35
36 #include <stdint.h>
37 #include <infiniband/common.h>
38
39 #ifdef __cplusplus
40 #  define BEGIN_C_DECLS extern "C" {
41 #  define END_C_DECLS   }
42 #else /* !__cplusplus */
43 #  define BEGIN_C_DECLS
44 #  define END_C_DECLS
45 #endif /* __cplusplus */
46
47 BEGIN_C_DECLS
48
49 #define UMAD_MAX_DEVICES 20
50 #define UMAD_ANY_PORT   0
51
52 typedef struct ib_mad_addr {
53         uint32_t qpn;
54         uint32_t qkey;
55         uint16_t lid;
56         uint8_t  sl;
57         uint8_t  path_bits;
58         uint8_t  grh_present;
59         uint8_t  gid_index;
60         uint8_t  hop_limit;
61         uint8_t  traffic_class;
62         uint8_t  gid[16];
63         uint32_t flow_label;
64         uint16_t pkey_index;
65         uint8_t  reserved[6];
66 } ib_mad_addr_t;
67
68 typedef struct ib_user_mad {
69         uint32_t agent_id;
70         uint32_t status;
71         uint32_t timeout_ms;
72         uint32_t retries;
73         uint32_t length;
74         ib_mad_addr_t addr;
75         uint8_t  data[0];
76 } ib_user_mad_t;
77
78 #define IB_UMAD_ABI_VERSION     5
79 #define IB_UMAD_ABI_DIR         "/sys/class/infiniband_mad"
80 #define IB_UMAD_ABI_FILE        "abi_version"
81
82 #define IB_IOCTL_MAGIC          0x1b
83
84 #define IB_USER_MAD_REGISTER_AGENT      _IO(IB_IOCTL_MAGIC, 1)
85 #define IB_USER_MAD_UNREGISTER_AGENT    _IO(IB_IOCTL_MAGIC, 2)
86 #define IB_USER_MAD_ENABLE_PKEY         _IO(IB_IOCTL_MAGIC, 3)
87
88 #define UMAD_CA_NAME_LEN        20
89 #define UMAD_CA_MAX_PORTS       10      /* 0 - 9 */
90 #define UMAD_CA_MAX_AGENTS      32
91
92 #define SYS_INFINIBAND          "/sys/class/infiniband"
93
94 #define SYS_INFINIBAND_MAD      "/sys/class/infiniband_mad"
95 #define SYS_IB_MAD_PORT         "port"
96 #define SYS_IB_MAD_DEV          "ibdev"
97
98 #define UMAD_MAX_PORTS          64
99
100 #define UMAD_DEV_DIR            "/dev"
101
102 #define SYS_CA_PORTS_DIR        "ports"
103
104 #define SYS_NODE_TYPE           "node_type"
105 #define SYS_CA_FW_VERS          "fw_ver"
106 #define SYS_CA_HW_VERS          "hw_rev"
107 #define SYS_CA_TYPE             "hca_type"
108 #define SYS_CA_NODE_GUID        "node_guid"
109 #define SYS_CA_SYS_GUID         "sys_image_guid"
110
111 #define SYS_PORT_LMC            "lid_mask_count"
112 #define SYS_PORT_SMLID          "sm_lid"
113 #define SYS_PORT_SMSL           "sm_sl"
114 #define SYS_PORT_LID            "lid"
115 #define SYS_PORT_STATE          "state"
116 #define SYS_PORT_PHY_STATE      "phys_state"
117 #define SYS_PORT_CAPMASK        "cap_mask"
118 #define SYS_PORT_RATE           "rate"
119 #define SYS_PORT_GUID           "port_guid"
120 #define SYS_PORT_GID            "gids/0"
121
122 typedef struct umad_port {
123         char ca_name[UMAD_CA_NAME_LEN];
124         int portnum;
125         unsigned base_lid;
126         unsigned lmc;
127         unsigned sm_lid;
128         unsigned sm_sl;
129         unsigned state;
130         unsigned phys_state;
131         unsigned rate;
132         uint64_t capmask;
133         uint64_t gid_prefix;
134         uint64_t port_guid;
135         unsigned pkeys_size;
136         uint16_t *pkeys;
137 } umad_port_t;
138
139 typedef struct umad_ca {
140         char ca_name[UMAD_CA_NAME_LEN];
141         unsigned node_type;
142         int numports;
143         char fw_ver[20];
144         char ca_type[40];
145         char hw_ver[20];
146         uint64_t node_guid;
147         uint64_t system_guid;
148         umad_port_t *ports[UMAD_CA_MAX_PORTS];
149 } umad_ca_t;
150
151 int     umad_init(void);
152 int     umad_done(void);
153
154 int     umad_get_cas_names(char cas[][UMAD_CA_NAME_LEN], int max);
155 int     umad_get_ca_portguids(char *ca_name, uint64_t *portguids, int max);
156
157 int     umad_get_ca(char *ca_name, umad_ca_t *ca);
158 int     umad_release_ca(umad_ca_t *ca);
159 int     umad_get_port(char *ca_name, int portnum, umad_port_t *port);
160 int     umad_release_port(umad_port_t *port);
161
162 int     umad_get_issm_path(char *ca_name, int portnum, char path[], int max);
163
164 int     umad_open_port(char *ca_name, int portnum);
165 int     umad_close_port(int portid);
166
167 void *  umad_get_mad(void *umad);
168 size_t  umad_size(void);
169 int     umad_status(void *umad);
170
171 ib_mad_addr_t   *umad_get_mad_addr(void *umad);
172 int     umad_set_grh_net(void *umad, void *mad_addr);
173 int     umad_set_grh(void *umad, void *mad_addr);
174 int     umad_set_addr_net(void *umad, int dlid, int dqp, int sl, int qkey);
175 int     umad_set_addr(void *umad, int dlid, int dqp, int sl, int qkey);
176 int     umad_set_pkey(void *umad, int pkey_index);
177 int     umad_get_pkey(void *umad);
178
179 int     umad_send(int portid, int agentid, void *umad, int length,
180                   int timeout_ms, int retries);
181 int     umad_recv(int portid, void *umad, int *length, int timeout_ms);
182 int     umad_poll(int portid, int timeout_ms);
183 int     umad_get_fd(int portid);
184
185 int     umad_register(int portid, int mgmt_class, int mgmt_version,
186                       uint8_t rmpp_version, long method_mask[16/sizeof(long)]);
187 int     umad_register_oui(int portid, int mgmt_class, uint8_t rmpp_version,
188                           uint8_t oui[3], long method_mask[16/sizeof(long)]);
189 int     umad_unregister(int portid, int agentid);
190
191 int     umad_debug(int level);
192 void    umad_addr_dump(ib_mad_addr_t *addr);
193 void    umad_dump(void *umad);
194
195 #include <stdlib.h>
196
197 static inline void *
198 umad_alloc(int num, size_t size)        /* alloc array of umad buffers */
199 {
200         return calloc(num, size);
201 }
202
203 static inline void
204 umad_free(void *umad)
205 {
206         free(umad);
207 }
208
209 END_C_DECLS
210
211 #endif /* _UMAD_H */