xref: /freebsd/contrib/ofed/libibverbs/verbs.h (revision 644f8990e2c2203de649b80c82a2a56bacbd98a9)
1 /*
2  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
3  * Copyright (c) 2004, 2011-2012 Intel Corporation.  All rights reserved.
4  * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc.  All rights reserved.
5  * Copyright (c) 2005 PathScale, Inc.  All rights reserved.
6  *
7  * This software is available to you under a choice of one of two
8  * licenses.  You may choose to be licensed under the terms of the GNU
9  * General Public License (GPL) Version 2, available from the file
10  * COPYING in the main directory of this source tree, or the
11  * OpenIB.org BSD license below:
12  *
13  *     Redistribution and use in source and binary forms, with or
14  *     without modification, are permitted provided that the following
15  *     conditions are met:
16  *
17  *      - Redistributions of source code must retain the above
18  *        copyright notice, this list of conditions and the following
19  *        disclaimer.
20  *
21  *      - Redistributions in binary form must reproduce the above
22  *        copyright notice, this list of conditions and the following
23  *        disclaimer in the documentation and/or other materials
24  *        provided with the distribution.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33  * SOFTWARE.
34  */
35 
36 #ifndef INFINIBAND_VERBS_H
37 #define INFINIBAND_VERBS_H
38 
39 #include <stdint.h>
40 #include <pthread.h>
41 #include <stddef.h>
42 #include <errno.h>
43 #include <string.h>
44 #include <infiniband/types.h>
45 
46 #ifdef __cplusplus
47 #  define BEGIN_C_DECLS extern "C" {
48 #  define END_C_DECLS   }
49 #else /* !__cplusplus */
50 #  define BEGIN_C_DECLS
51 #  define END_C_DECLS
52 #endif /* __cplusplus */
53 
54 #if __GNUC__ >= 3
55 #  define __attribute_const __attribute__((const))
56 #else
57 #  define __attribute_const
58 #endif
59 
60 BEGIN_C_DECLS
61 
62 union ibv_gid {
63 	uint8_t			raw[16];
64 	struct {
65 		__be64	subnet_prefix;
66 		__be64	interface_id;
67 	} global;
68 };
69 
70 #ifndef container_of
71 /**
72   * container_of - cast a member of a structure out to the containing structure
73   * @ptr:        the pointer to the member.
74   * @type:       the type of the container struct this is embedded in.
75   * @member:     the name of the member within the struct.
76   *
77  */
78 #define container_of(ptr, type, member) \
79 	((type *) ((uint8_t *)(ptr) - offsetof(type, member)))
80 #endif
81 
82 #define vext_field_avail(type, fld, sz) (offsetof(type, fld) < (sz))
83 
84 static void *__VERBS_ABI_IS_EXTENDED = ((uint8_t *) NULL) - 1;
85 
86 enum ibv_node_type {
87 	IBV_NODE_UNKNOWN	= -1,
88 	IBV_NODE_CA 		= 1,
89 	IBV_NODE_SWITCH,
90 	IBV_NODE_ROUTER,
91 	IBV_NODE_RNIC,
92 	IBV_NODE_USNIC,
93 	IBV_NODE_USNIC_UDP,
94 };
95 
96 enum ibv_transport_type {
97 	IBV_TRANSPORT_UNKNOWN	= -1,
98 	IBV_TRANSPORT_IB	= 0,
99 	IBV_TRANSPORT_IWARP,
100 	IBV_TRANSPORT_USNIC,
101 	IBV_TRANSPORT_USNIC_UDP,
102 };
103 
104 enum ibv_device_cap_flags {
105 	IBV_DEVICE_RESIZE_MAX_WR	= 1,
106 	IBV_DEVICE_BAD_PKEY_CNTR	= 1 <<  1,
107 	IBV_DEVICE_BAD_QKEY_CNTR	= 1 <<  2,
108 	IBV_DEVICE_RAW_MULTI		= 1 <<  3,
109 	IBV_DEVICE_AUTO_PATH_MIG	= 1 <<  4,
110 	IBV_DEVICE_CHANGE_PHY_PORT	= 1 <<  5,
111 	IBV_DEVICE_UD_AV_PORT_ENFORCE	= 1 <<  6,
112 	IBV_DEVICE_CURR_QP_STATE_MOD	= 1 <<  7,
113 	IBV_DEVICE_SHUTDOWN_PORT	= 1 <<  8,
114 	IBV_DEVICE_INIT_TYPE		= 1 <<  9,
115 	IBV_DEVICE_PORT_ACTIVE_EVENT	= 1 << 10,
116 	IBV_DEVICE_SYS_IMAGE_GUID	= 1 << 11,
117 	IBV_DEVICE_RC_RNR_NAK_GEN	= 1 << 12,
118 	IBV_DEVICE_SRQ_RESIZE		= 1 << 13,
119 	IBV_DEVICE_N_NOTIFY_CQ		= 1 << 14,
120 	IBV_DEVICE_MEM_WINDOW           = 1 << 17,
121 	IBV_DEVICE_UD_IP_CSUM		= 1 << 18,
122 	IBV_DEVICE_XRC			= 1 << 20,
123 	IBV_DEVICE_MEM_MGT_EXTENSIONS	= 1 << 21,
124 	IBV_DEVICE_MEM_WINDOW_TYPE_2A	= 1 << 23,
125 	IBV_DEVICE_MEM_WINDOW_TYPE_2B	= 1 << 24,
126 	IBV_DEVICE_RC_IP_CSUM		= 1 << 25,
127 	IBV_DEVICE_RAW_IP_CSUM		= 1 << 26,
128 	IBV_DEVICE_MANAGED_FLOW_STEERING = 1 << 29
129 };
130 
131 /*
132  * Can't extended above ibv_device_cap_flags enum as in some systems/compilers
133  * enum range is limited to 4 bytes.
134  */
135 #define IBV_DEVICE_RAW_SCATTER_FCS (1ULL << 34)
136 
137 enum ibv_atomic_cap {
138 	IBV_ATOMIC_NONE,
139 	IBV_ATOMIC_HCA,
140 	IBV_ATOMIC_GLOB
141 };
142 
143 struct ibv_device_attr {
144 	char			fw_ver[64];
145 	__be64			node_guid;
146 	__be64			sys_image_guid;
147 	uint64_t		max_mr_size;
148 	uint64_t		page_size_cap;
149 	uint32_t		vendor_id;
150 	uint32_t		vendor_part_id;
151 	uint32_t		hw_ver;
152 	int			max_qp;
153 	int			max_qp_wr;
154 	int			device_cap_flags;
155 	int			max_sge;
156 	int			max_sge_rd;
157 	int			max_cq;
158 	int			max_cqe;
159 	int			max_mr;
160 	int			max_pd;
161 	int			max_qp_rd_atom;
162 	int			max_ee_rd_atom;
163 	int			max_res_rd_atom;
164 	int			max_qp_init_rd_atom;
165 	int			max_ee_init_rd_atom;
166 	enum ibv_atomic_cap	atomic_cap;
167 	int			max_ee;
168 	int			max_rdd;
169 	int			max_mw;
170 	int			max_raw_ipv6_qp;
171 	int			max_raw_ethy_qp;
172 	int			max_mcast_grp;
173 	int			max_mcast_qp_attach;
174 	int			max_total_mcast_qp_attach;
175 	int			max_ah;
176 	int			max_fmr;
177 	int			max_map_per_fmr;
178 	int			max_srq;
179 	int			max_srq_wr;
180 	int			max_srq_sge;
181 	uint16_t		max_pkeys;
182 	uint8_t			local_ca_ack_delay;
183 	uint8_t			phys_port_cnt;
184 };
185 
186 /* An extensible input struct for possible future extensions of the
187  * ibv_query_device_ex verb. */
188 struct ibv_query_device_ex_input {
189 	uint32_t		comp_mask;
190 };
191 
192 enum ibv_odp_transport_cap_bits {
193 	IBV_ODP_SUPPORT_SEND     = 1 << 0,
194 	IBV_ODP_SUPPORT_RECV     = 1 << 1,
195 	IBV_ODP_SUPPORT_WRITE    = 1 << 2,
196 	IBV_ODP_SUPPORT_READ     = 1 << 3,
197 	IBV_ODP_SUPPORT_ATOMIC   = 1 << 4,
198 };
199 
200 struct ibv_odp_caps {
201 	uint64_t general_caps;
202 	struct {
203 		uint32_t rc_odp_caps;
204 		uint32_t uc_odp_caps;
205 		uint32_t ud_odp_caps;
206 	} per_transport_caps;
207 };
208 
209 enum ibv_odp_general_caps {
210 	IBV_ODP_SUPPORT = 1 << 0,
211 };
212 
213 struct ibv_tso_caps {
214 	uint32_t max_tso;
215 	uint32_t supported_qpts;
216 };
217 
218 /* RX Hash function flags */
219 enum ibv_rx_hash_function_flags {
220 	IBV_RX_HASH_FUNC_TOEPLITZ	= 1 << 0,
221 };
222 
223 /*
224  * RX Hash fields enable to set which incoming packet's field should
225  * participates in RX Hash. Each flag represent certain packet's field,
226  * when the flag is set the field that is represented by the flag will
227  * participate in RX Hash calculation.
228  * Note: *IPV4 and *IPV6 flags can't be enabled together on the same QP
229  * and *TCP and *UDP flags can't be enabled together on the same QP.
230 */
231 enum ibv_rx_hash_fields {
232 	IBV_RX_HASH_SRC_IPV4	= 1 << 0,
233 	IBV_RX_HASH_DST_IPV4	= 1 << 1,
234 	IBV_RX_HASH_SRC_IPV6	= 1 << 2,
235 	IBV_RX_HASH_DST_IPV6	= 1 << 3,
236 	IBV_RX_HASH_SRC_PORT_TCP	= 1 << 4,
237 	IBV_RX_HASH_DST_PORT_TCP	= 1 << 5,
238 	IBV_RX_HASH_SRC_PORT_UDP	= 1 << 6,
239 	IBV_RX_HASH_DST_PORT_UDP	= 1 << 7,
240 	IBV_RX_HASH_INNER		= (1UL << 31),
241 };
242 
243 struct ibv_rss_caps {
244 	uint32_t supported_qpts;
245 	uint32_t max_rwq_indirection_tables;
246 	uint32_t max_rwq_indirection_table_size;
247 	uint64_t rx_hash_fields_mask; /* enum ibv_rx_hash_fields */
248 	uint8_t  rx_hash_function; /* enum ibv_rx_hash_function_flags */
249 };
250 
251 struct ibv_packet_pacing_caps {
252 	uint32_t qp_rate_limit_min;
253 	uint32_t qp_rate_limit_max; /* In kbps */
254 	uint32_t supported_qpts;
255 };
256 
257 enum ibv_raw_packet_caps {
258 	IBV_RAW_PACKET_CAP_CVLAN_STRIPPING	= 1 << 0,
259 	IBV_RAW_PACKET_CAP_SCATTER_FCS		= 1 << 1,
260 	IBV_RAW_PACKET_CAP_IP_CSUM		= 1 << 2,
261 };
262 
263 enum ibv_tm_cap_flags {
264 	IBV_TM_CAP_RC		    = 1 << 0,
265 };
266 
267 struct ibv_tm_caps {
268 	/* Max size of rendezvous request header */
269 	uint32_t max_rndv_hdr_size;
270 	/* Max number of tagged buffers in a TM-SRQ matching list */
271 	uint32_t max_num_tags;
272 	/* From enum ibv_tm_cap_flags */
273 	uint32_t flags;
274 	/* Max number of outstanding list operations */
275 	uint32_t max_ops;
276 	/* Max number of SGEs in a tagged buffer */
277 	uint32_t max_sge;
278 };
279 
280 struct ibv_device_attr_ex {
281 	struct ibv_device_attr	orig_attr;
282 	uint32_t		comp_mask;
283 	struct ibv_odp_caps	odp_caps;
284 	uint64_t		completion_timestamp_mask;
285 	uint64_t		hca_core_clock;
286 	uint64_t		device_cap_flags_ex;
287 	struct ibv_tso_caps	tso_caps;
288 	struct ibv_rss_caps     rss_caps;
289 	uint32_t		max_wq_type_rq;
290 	struct ibv_packet_pacing_caps packet_pacing_caps;
291 	uint32_t		raw_packet_caps; /* Use ibv_raw_packet_caps */
292 	struct ibv_tm_caps	tm_caps;
293 };
294 
295 enum ibv_mtu {
296 	IBV_MTU_256  = 1,
297 	IBV_MTU_512  = 2,
298 	IBV_MTU_1024 = 3,
299 	IBV_MTU_2048 = 4,
300 	IBV_MTU_4096 = 5
301 };
302 
303 enum ibv_port_state {
304 	IBV_PORT_NOP		= 0,
305 	IBV_PORT_DOWN		= 1,
306 	IBV_PORT_INIT		= 2,
307 	IBV_PORT_ARMED		= 3,
308 	IBV_PORT_ACTIVE		= 4,
309 	IBV_PORT_ACTIVE_DEFER	= 5
310 };
311 
312 enum {
313 	IBV_LINK_LAYER_UNSPECIFIED,
314 	IBV_LINK_LAYER_INFINIBAND,
315 	IBV_LINK_LAYER_ETHERNET,
316 };
317 
318 enum ibv_port_cap_flags {
319 	IBV_PORT_SM				= 1 <<  1,
320 	IBV_PORT_NOTICE_SUP			= 1 <<  2,
321 	IBV_PORT_TRAP_SUP			= 1 <<  3,
322 	IBV_PORT_OPT_IPD_SUP			= 1 <<  4,
323 	IBV_PORT_AUTO_MIGR_SUP			= 1 <<  5,
324 	IBV_PORT_SL_MAP_SUP			= 1 <<  6,
325 	IBV_PORT_MKEY_NVRAM			= 1 <<  7,
326 	IBV_PORT_PKEY_NVRAM			= 1 <<  8,
327 	IBV_PORT_LED_INFO_SUP			= 1 <<  9,
328 	IBV_PORT_SYS_IMAGE_GUID_SUP		= 1 << 11,
329 	IBV_PORT_PKEY_SW_EXT_PORT_TRAP_SUP	= 1 << 12,
330 	IBV_PORT_EXTENDED_SPEEDS_SUP		= 1 << 14,
331 	IBV_PORT_CM_SUP				= 1 << 16,
332 	IBV_PORT_SNMP_TUNNEL_SUP		= 1 << 17,
333 	IBV_PORT_REINIT_SUP			= 1 << 18,
334 	IBV_PORT_DEVICE_MGMT_SUP		= 1 << 19,
335 	IBV_PORT_VENDOR_CLASS_SUP		= 1 << 20,
336 	IBV_PORT_DR_NOTICE_SUP			= 1 << 21,
337 	IBV_PORT_CAP_MASK_NOTICE_SUP		= 1 << 22,
338 	IBV_PORT_BOOT_MGMT_SUP			= 1 << 23,
339 	IBV_PORT_LINK_LATENCY_SUP		= 1 << 24,
340 	IBV_PORT_CLIENT_REG_SUP			= 1 << 25,
341 	IBV_PORT_IP_BASED_GIDS			= 1 << 26
342 };
343 
344 struct ibv_port_attr {
345 	enum ibv_port_state	state;
346 	enum ibv_mtu		max_mtu;
347 	enum ibv_mtu		active_mtu;
348 	int			gid_tbl_len;
349 	uint32_t		port_cap_flags;
350 	uint32_t		max_msg_sz;
351 	uint32_t		bad_pkey_cntr;
352 	uint32_t		qkey_viol_cntr;
353 	uint16_t		pkey_tbl_len;
354 	uint16_t		lid;
355 	uint16_t		sm_lid;
356 	uint8_t			lmc;
357 	uint8_t			max_vl_num;
358 	uint8_t			sm_sl;
359 	uint8_t			subnet_timeout;
360 	uint8_t			init_type_reply;
361 	uint8_t			active_width;
362 	uint8_t			active_speed;
363 	uint8_t			phys_state;
364 	uint8_t			link_layer;
365 	uint8_t			reserved;
366 };
367 
368 enum ibv_event_type {
369 	IBV_EVENT_CQ_ERR,
370 	IBV_EVENT_QP_FATAL,
371 	IBV_EVENT_QP_REQ_ERR,
372 	IBV_EVENT_QP_ACCESS_ERR,
373 	IBV_EVENT_COMM_EST,
374 	IBV_EVENT_SQ_DRAINED,
375 	IBV_EVENT_PATH_MIG,
376 	IBV_EVENT_PATH_MIG_ERR,
377 	IBV_EVENT_DEVICE_FATAL,
378 	IBV_EVENT_PORT_ACTIVE,
379 	IBV_EVENT_PORT_ERR,
380 	IBV_EVENT_LID_CHANGE,
381 	IBV_EVENT_PKEY_CHANGE,
382 	IBV_EVENT_SM_CHANGE,
383 	IBV_EVENT_SRQ_ERR,
384 	IBV_EVENT_SRQ_LIMIT_REACHED,
385 	IBV_EVENT_QP_LAST_WQE_REACHED,
386 	IBV_EVENT_CLIENT_REREGISTER,
387 	IBV_EVENT_GID_CHANGE,
388 	IBV_EVENT_WQ_FATAL,
389 };
390 
391 struct ibv_async_event {
392 	union {
393 		struct ibv_cq  *cq;
394 		struct ibv_qp  *qp;
395 		struct ibv_srq *srq;
396 		struct ibv_wq  *wq;
397 		int		port_num;
398 	} element;
399 	enum ibv_event_type	event_type;
400 };
401 
402 enum ibv_wc_status {
403 	IBV_WC_SUCCESS,
404 	IBV_WC_LOC_LEN_ERR,
405 	IBV_WC_LOC_QP_OP_ERR,
406 	IBV_WC_LOC_EEC_OP_ERR,
407 	IBV_WC_LOC_PROT_ERR,
408 	IBV_WC_WR_FLUSH_ERR,
409 	IBV_WC_MW_BIND_ERR,
410 	IBV_WC_BAD_RESP_ERR,
411 	IBV_WC_LOC_ACCESS_ERR,
412 	IBV_WC_REM_INV_REQ_ERR,
413 	IBV_WC_REM_ACCESS_ERR,
414 	IBV_WC_REM_OP_ERR,
415 	IBV_WC_RETRY_EXC_ERR,
416 	IBV_WC_RNR_RETRY_EXC_ERR,
417 	IBV_WC_LOC_RDD_VIOL_ERR,
418 	IBV_WC_REM_INV_RD_REQ_ERR,
419 	IBV_WC_REM_ABORT_ERR,
420 	IBV_WC_INV_EECN_ERR,
421 	IBV_WC_INV_EEC_STATE_ERR,
422 	IBV_WC_FATAL_ERR,
423 	IBV_WC_RESP_TIMEOUT_ERR,
424 	IBV_WC_GENERAL_ERR
425 };
426 const char *ibv_wc_status_str(enum ibv_wc_status status);
427 
428 enum ibv_wc_opcode {
429 	IBV_WC_SEND,
430 	IBV_WC_RDMA_WRITE,
431 	IBV_WC_RDMA_READ,
432 	IBV_WC_COMP_SWAP,
433 	IBV_WC_FETCH_ADD,
434 	IBV_WC_BIND_MW,
435 	IBV_WC_LOCAL_INV,
436 	IBV_WC_TSO,
437 /*
438  * Set value of IBV_WC_RECV so consumers can test if a completion is a
439  * receive by testing (opcode & IBV_WC_RECV).
440  */
441 	IBV_WC_RECV			= 1 << 7,
442 	IBV_WC_RECV_RDMA_WITH_IMM
443 };
444 
445 enum {
446 	IBV_WC_IP_CSUM_OK_SHIFT	= 2
447 };
448 
449 enum ibv_create_cq_wc_flags {
450 	IBV_WC_EX_WITH_BYTE_LEN		= 1 << 0,
451 	IBV_WC_EX_WITH_IMM		= 1 << 1,
452 	IBV_WC_EX_WITH_QP_NUM		= 1 << 2,
453 	IBV_WC_EX_WITH_SRC_QP		= 1 << 3,
454 	IBV_WC_EX_WITH_SLID		= 1 << 4,
455 	IBV_WC_EX_WITH_SL		= 1 << 5,
456 	IBV_WC_EX_WITH_DLID_PATH_BITS	= 1 << 6,
457 	IBV_WC_EX_WITH_COMPLETION_TIMESTAMP	= 1 << 7,
458 	IBV_WC_EX_WITH_CVLAN		= 1 << 8,
459 	IBV_WC_EX_WITH_FLOW_TAG		= 1 << 9,
460 };
461 
462 enum {
463 	IBV_WC_STANDARD_FLAGS = IBV_WC_EX_WITH_BYTE_LEN		|
464 				 IBV_WC_EX_WITH_IMM		|
465 				 IBV_WC_EX_WITH_QP_NUM		|
466 				 IBV_WC_EX_WITH_SRC_QP		|
467 				 IBV_WC_EX_WITH_SLID		|
468 				 IBV_WC_EX_WITH_SL		|
469 				 IBV_WC_EX_WITH_DLID_PATH_BITS
470 };
471 
472 enum {
473 	IBV_CREATE_CQ_SUP_WC_FLAGS = IBV_WC_STANDARD_FLAGS |
474 				IBV_WC_EX_WITH_COMPLETION_TIMESTAMP |
475 				IBV_WC_EX_WITH_CVLAN |
476 				IBV_WC_EX_WITH_FLOW_TAG
477 };
478 
479 enum ibv_wc_flags {
480 	IBV_WC_GRH		= 1 << 0,
481 	IBV_WC_WITH_IMM		= 1 << 1,
482 	IBV_WC_IP_CSUM_OK	= 1 << IBV_WC_IP_CSUM_OK_SHIFT,
483 	IBV_WC_WITH_INV         = 1 << 3
484 };
485 
486 struct ibv_wc {
487 	uint64_t		wr_id;
488 	enum ibv_wc_status	status;
489 	enum ibv_wc_opcode	opcode;
490 	uint32_t		vendor_err;
491 	uint32_t		byte_len;
492 	/* When (wc_flags & IBV_WC_WITH_IMM): Immediate data in network byte order.
493 	 * When (wc_flags & IBV_WC_WITH_INV): Stores the invalidated rkey.
494 	 */
495 	union {
496 		__be32		imm_data;
497 		uint32_t	invalidated_rkey;
498 	};
499 	uint32_t		qp_num;
500 	uint32_t		src_qp;
501 	int			wc_flags;
502 	uint16_t		pkey_index;
503 	uint16_t		slid;
504 	uint8_t			sl;
505 	uint8_t			dlid_path_bits;
506 };
507 
508 enum ibv_access_flags {
509 	IBV_ACCESS_LOCAL_WRITE		= 1,
510 	IBV_ACCESS_REMOTE_WRITE		= (1<<1),
511 	IBV_ACCESS_REMOTE_READ		= (1<<2),
512 	IBV_ACCESS_REMOTE_ATOMIC	= (1<<3),
513 	IBV_ACCESS_MW_BIND		= (1<<4),
514 	IBV_ACCESS_ZERO_BASED		= (1<<5),
515 	IBV_ACCESS_ON_DEMAND		= (1<<6),
516 };
517 
518 struct ibv_mw_bind_info {
519 	struct ibv_mr	*mr;
520 	uint64_t	 addr;
521 	uint64_t	 length;
522 	int		 mw_access_flags; /* use ibv_access_flags */
523 };
524 
525 struct ibv_pd {
526 	struct ibv_context     *context;
527 	uint32_t		handle;
528 };
529 
530 enum ibv_xrcd_init_attr_mask {
531 	IBV_XRCD_INIT_ATTR_FD	    = 1 << 0,
532 	IBV_XRCD_INIT_ATTR_OFLAGS   = 1 << 1,
533 	IBV_XRCD_INIT_ATTR_RESERVED = 1 << 2
534 };
535 
536 struct ibv_xrcd_init_attr {
537 	uint32_t comp_mask;
538 	int	 fd;
539 	int	 oflags;
540 };
541 
542 struct ibv_xrcd {
543 	struct ibv_context     *context;
544 };
545 
546 enum ibv_rereg_mr_flags {
547 	IBV_REREG_MR_CHANGE_TRANSLATION	= (1 << 0),
548 	IBV_REREG_MR_CHANGE_PD		= (1 << 1),
549 	IBV_REREG_MR_CHANGE_ACCESS	= (1 << 2),
550 	IBV_REREG_MR_KEEP_VALID		= (1 << 3),
551 	IBV_REREG_MR_FLAGS_SUPPORTED	= ((IBV_REREG_MR_KEEP_VALID << 1) - 1)
552 };
553 
554 struct ibv_mr {
555 	struct ibv_context     *context;
556 	struct ibv_pd	       *pd;
557 	void		       *addr;
558 	size_t			length;
559 	uint32_t		handle;
560 	uint32_t		lkey;
561 	uint32_t		rkey;
562 };
563 
564 enum ibv_mw_type {
565 	IBV_MW_TYPE_1			= 1,
566 	IBV_MW_TYPE_2			= 2
567 };
568 
569 struct ibv_mw {
570 	struct ibv_context     *context;
571 	struct ibv_pd	       *pd;
572 	uint32_t		rkey;
573 	uint32_t		handle;
574 	enum ibv_mw_type	type;
575 };
576 
577 struct ibv_global_route {
578 	union ibv_gid		dgid;
579 	uint32_t		flow_label;
580 	uint8_t			sgid_index;
581 	uint8_t			hop_limit;
582 	uint8_t			traffic_class;
583 };
584 
585 struct ibv_grh {
586 	__be32			version_tclass_flow;
587 	__be16			paylen;
588 	uint8_t			next_hdr;
589 	uint8_t			hop_limit;
590 	union ibv_gid		sgid;
591 	union ibv_gid		dgid;
592 };
593 
594 enum ibv_rate {
595 	IBV_RATE_MAX      = 0,
596 	IBV_RATE_2_5_GBPS = 2,
597 	IBV_RATE_5_GBPS   = 5,
598 	IBV_RATE_10_GBPS  = 3,
599 	IBV_RATE_20_GBPS  = 6,
600 	IBV_RATE_30_GBPS  = 4,
601 	IBV_RATE_40_GBPS  = 7,
602 	IBV_RATE_60_GBPS  = 8,
603 	IBV_RATE_80_GBPS  = 9,
604 	IBV_RATE_120_GBPS = 10,
605 	IBV_RATE_14_GBPS  = 11,
606 	IBV_RATE_56_GBPS  = 12,
607 	IBV_RATE_112_GBPS = 13,
608 	IBV_RATE_168_GBPS = 14,
609 	IBV_RATE_25_GBPS  = 15,
610 	IBV_RATE_100_GBPS = 16,
611 	IBV_RATE_200_GBPS = 17,
612 	IBV_RATE_300_GBPS = 18,
613 	IBV_RATE_28_GBPS  = 19,
614 	IBV_RATE_50_GBPS  = 20,
615 	IBV_RATE_400_GBPS = 21,
616 	IBV_RATE_600_GBPS = 22,
617 	IBV_RATE_800_GBPS = 23,
618 	IBV_RATE_1200_GBPS = 24,
619 };
620 
621 /**
622  * ibv_rate_to_mult - Convert the IB rate enum to a multiple of the
623  * base rate of 2.5 Gbit/sec.  For example, IBV_RATE_5_GBPS will be
624  * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
625  * @rate: rate to convert.
626  */
627 int  __attribute_const ibv_rate_to_mult(enum ibv_rate rate);
628 
629 /**
630  * mult_to_ibv_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate enum.
631  * @mult: multiple to convert.
632  */
633 enum ibv_rate __attribute_const mult_to_ibv_rate(int mult);
634 
635 /**
636  * ibv_rate_to_mbps - Convert the IB rate enum to Mbit/sec.
637  * For example, IBV_RATE_5_GBPS will return the value 5000.
638  * @rate: rate to convert.
639  */
640 int __attribute_const ibv_rate_to_mbps(enum ibv_rate rate);
641 
642 /**
643  * mbps_to_ibv_rate - Convert a Mbit/sec value to an IB rate enum.
644  * @mbps: value to convert.
645  */
646 enum ibv_rate __attribute_const mbps_to_ibv_rate(int mbps) __attribute_const;
647 
648 struct ibv_ah_attr {
649 	struct ibv_global_route	grh;
650 	uint16_t		dlid;
651 	uint8_t			sl;
652 	uint8_t			src_path_bits;
653 	uint8_t			static_rate;
654 	uint8_t			is_global;
655 	uint8_t			port_num;
656 };
657 
658 enum ibv_srq_attr_mask {
659 	IBV_SRQ_MAX_WR	= 1 << 0,
660 	IBV_SRQ_LIMIT	= 1 << 1
661 };
662 
663 struct ibv_srq_attr {
664 	uint32_t		max_wr;
665 	uint32_t		max_sge;
666 	uint32_t		srq_limit;
667 };
668 
669 struct ibv_srq_init_attr {
670 	void		       *srq_context;
671 	struct ibv_srq_attr	attr;
672 };
673 
674 enum ibv_srq_type {
675 	IBV_SRQT_BASIC,
676 	IBV_SRQT_XRC,
677 	IBV_SRQT_TM,
678 };
679 
680 enum ibv_srq_init_attr_mask {
681 	IBV_SRQ_INIT_ATTR_TYPE		= 1 << 0,
682 	IBV_SRQ_INIT_ATTR_PD		= 1 << 1,
683 	IBV_SRQ_INIT_ATTR_XRCD		= 1 << 2,
684 	IBV_SRQ_INIT_ATTR_CQ		= 1 << 3,
685 	IBV_SRQ_INIT_ATTR_TM		= 1 << 4,
686 	IBV_SRQ_INIT_ATTR_RESERVED	= 1 << 5,
687 };
688 
689 struct ibv_tm_cap {
690 	uint32_t		max_num_tags;
691 	uint32_t		max_ops;
692 };
693 
694 struct ibv_srq_init_attr_ex {
695 	void		       *srq_context;
696 	struct ibv_srq_attr	attr;
697 
698 	uint32_t		comp_mask;
699 	enum ibv_srq_type	srq_type;
700 	struct ibv_pd	       *pd;
701 	struct ibv_xrcd	       *xrcd;
702 	struct ibv_cq	       *cq;
703 	struct ibv_tm_cap	tm_cap;
704 };
705 
706 enum ibv_wq_type {
707 	IBV_WQT_RQ
708 };
709 
710 enum ibv_wq_init_attr_mask {
711 	IBV_WQ_INIT_ATTR_FLAGS		= 1 << 0,
712 	IBV_WQ_INIT_ATTR_RESERVED	= 1 << 1,
713 };
714 
715 enum ibv_wq_flags {
716 	IBV_WQ_FLAGS_CVLAN_STRIPPING		= 1 << 0,
717 	IBV_WQ_FLAGS_SCATTER_FCS		= 1 << 1,
718 	IBV_WQ_FLAGS_RESERVED			= 1 << 2,
719 };
720 
721 struct ibv_wq_init_attr {
722 	void		       *wq_context;
723 	enum ibv_wq_type	wq_type;
724 	uint32_t		max_wr;
725 	uint32_t		max_sge;
726 	struct	ibv_pd	       *pd;
727 	struct	ibv_cq	       *cq;
728 	uint32_t		comp_mask; /* Use ibv_wq_init_attr_mask */
729 	uint32_t		create_flags; /* use ibv_wq_flags */
730 };
731 
732 enum ibv_wq_state {
733 	IBV_WQS_RESET,
734 	IBV_WQS_RDY,
735 	IBV_WQS_ERR,
736 	IBV_WQS_UNKNOWN
737 };
738 
739 enum ibv_wq_attr_mask {
740 	IBV_WQ_ATTR_STATE	= 1 << 0,
741 	IBV_WQ_ATTR_CURR_STATE	= 1 << 1,
742 	IBV_WQ_ATTR_FLAGS	= 1 << 2,
743 	IBV_WQ_ATTR_RESERVED	= 1 << 3,
744 };
745 
746 struct ibv_wq_attr {
747 	/* enum ibv_wq_attr_mask */
748 	uint32_t		attr_mask;
749 	/* Move the WQ to this state */
750 	enum	ibv_wq_state	wq_state;
751 	/* Assume this is the current WQ state */
752 	enum	ibv_wq_state	curr_wq_state;
753 	uint32_t		flags; /* Use ibv_wq_flags */
754 	uint32_t		flags_mask; /* Use ibv_wq_flags */
755 };
756 
757 /*
758  * Receive Work Queue Indirection Table.
759  * It's used in order to distribute incoming packets between different
760  * Receive Work Queues. Associating Receive WQs with different CPU cores
761  * allows to workload the traffic between different CPU cores.
762  * The Indirection Table can contain only WQs of type IBV_WQT_RQ.
763 */
764 struct ibv_rwq_ind_table {
765 	struct ibv_context *context;
766 	int ind_tbl_handle;
767 	int ind_tbl_num;
768 	uint32_t comp_mask;
769 };
770 
771 enum ibv_ind_table_init_attr_mask {
772 	IBV_CREATE_IND_TABLE_RESERVED = (1 << 0)
773 };
774 
775 /*
776  * Receive Work Queue Indirection Table attributes
777  */
778 struct ibv_rwq_ind_table_init_attr {
779 	uint32_t log_ind_tbl_size;
780 	/* Each entry is a pointer to a Receive Work Queue */
781 	struct ibv_wq **ind_tbl;
782 	uint32_t comp_mask;
783 };
784 
785 enum ibv_qp_type {
786 	IBV_QPT_RC = 2,
787 	IBV_QPT_UC,
788 	IBV_QPT_UD,
789 	IBV_QPT_RAW_PACKET = 8,
790 	IBV_QPT_XRC_SEND = 9,
791 	IBV_QPT_XRC_RECV
792 };
793 
794 struct ibv_qp_cap {
795 	uint32_t		max_send_wr;
796 	uint32_t		max_recv_wr;
797 	uint32_t		max_send_sge;
798 	uint32_t		max_recv_sge;
799 	uint32_t		max_inline_data;
800 };
801 
802 struct ibv_qp_init_attr {
803 	void		       *qp_context;
804 	struct ibv_cq	       *send_cq;
805 	struct ibv_cq	       *recv_cq;
806 	struct ibv_srq	       *srq;
807 	struct ibv_qp_cap	cap;
808 	enum ibv_qp_type	qp_type;
809 	int			sq_sig_all;
810 };
811 
812 enum ibv_qp_init_attr_mask {
813 	IBV_QP_INIT_ATTR_PD		= 1 << 0,
814 	IBV_QP_INIT_ATTR_XRCD		= 1 << 1,
815 	IBV_QP_INIT_ATTR_CREATE_FLAGS	= 1 << 2,
816 	IBV_QP_INIT_ATTR_MAX_TSO_HEADER = 1 << 3,
817 	IBV_QP_INIT_ATTR_IND_TABLE	= 1 << 4,
818 	IBV_QP_INIT_ATTR_RX_HASH	= 1 << 5,
819 	IBV_QP_INIT_ATTR_RESERVED	= 1 << 6
820 };
821 
822 enum ibv_qp_create_flags {
823 	IBV_QP_CREATE_BLOCK_SELF_MCAST_LB	= 1 << 1,
824 	IBV_QP_CREATE_SCATTER_FCS		= 1 << 8,
825 	IBV_QP_CREATE_CVLAN_STRIPPING		= 1 << 9,
826 };
827 
828 struct ibv_rx_hash_conf {
829 	/* enum ibv_rx_hash_function_flags */
830 	uint8_t	rx_hash_function;
831 	uint8_t	rx_hash_key_len;
832 	uint8_t	*rx_hash_key;
833 	/* enum ibv_rx_hash_fields */
834 	uint64_t	rx_hash_fields_mask;
835 };
836 
837 struct ibv_qp_init_attr_ex {
838 	void		       *qp_context;
839 	struct ibv_cq	       *send_cq;
840 	struct ibv_cq	       *recv_cq;
841 	struct ibv_srq	       *srq;
842 	struct ibv_qp_cap	cap;
843 	enum ibv_qp_type	qp_type;
844 	int			sq_sig_all;
845 
846 	uint32_t		comp_mask;
847 	struct ibv_pd	       *pd;
848 	struct ibv_xrcd	       *xrcd;
849 	uint32_t                create_flags;
850 	uint16_t		max_tso_header;
851 	struct ibv_rwq_ind_table       *rwq_ind_tbl;
852 	struct ibv_rx_hash_conf	rx_hash_conf;
853 };
854 
855 enum ibv_qp_open_attr_mask {
856 	IBV_QP_OPEN_ATTR_NUM		= 1 << 0,
857 	IBV_QP_OPEN_ATTR_XRCD	        = 1 << 1,
858 	IBV_QP_OPEN_ATTR_CONTEXT	= 1 << 2,
859 	IBV_QP_OPEN_ATTR_TYPE		= 1 << 3,
860 	IBV_QP_OPEN_ATTR_RESERVED	= 1 << 4
861 };
862 
863 struct ibv_qp_open_attr {
864 	uint32_t		comp_mask;
865 	uint32_t		qp_num;
866 	struct ibv_xrcd        *xrcd;
867 	void		       *qp_context;
868 	enum ibv_qp_type	qp_type;
869 };
870 
871 enum ibv_qp_attr_mask {
872 	IBV_QP_STATE			= 1 << 	0,
873 	IBV_QP_CUR_STATE		= 1 << 	1,
874 	IBV_QP_EN_SQD_ASYNC_NOTIFY	= 1 << 	2,
875 	IBV_QP_ACCESS_FLAGS		= 1 << 	3,
876 	IBV_QP_PKEY_INDEX		= 1 << 	4,
877 	IBV_QP_PORT			= 1 << 	5,
878 	IBV_QP_QKEY			= 1 << 	6,
879 	IBV_QP_AV			= 1 << 	7,
880 	IBV_QP_PATH_MTU			= 1 << 	8,
881 	IBV_QP_TIMEOUT			= 1 << 	9,
882 	IBV_QP_RETRY_CNT		= 1 << 10,
883 	IBV_QP_RNR_RETRY		= 1 << 11,
884 	IBV_QP_RQ_PSN			= 1 << 12,
885 	IBV_QP_MAX_QP_RD_ATOMIC		= 1 << 13,
886 	IBV_QP_ALT_PATH			= 1 << 14,
887 	IBV_QP_MIN_RNR_TIMER		= 1 << 15,
888 	IBV_QP_SQ_PSN			= 1 << 16,
889 	IBV_QP_MAX_DEST_RD_ATOMIC	= 1 << 17,
890 	IBV_QP_PATH_MIG_STATE		= 1 << 18,
891 	IBV_QP_CAP			= 1 << 19,
892 	IBV_QP_DEST_QPN			= 1 << 20,
893 	IBV_QP_RATE_LIMIT		= 1 << 25,
894 };
895 
896 enum ibv_qp_state {
897 	IBV_QPS_RESET,
898 	IBV_QPS_INIT,
899 	IBV_QPS_RTR,
900 	IBV_QPS_RTS,
901 	IBV_QPS_SQD,
902 	IBV_QPS_SQE,
903 	IBV_QPS_ERR,
904 	IBV_QPS_UNKNOWN
905 };
906 
907 enum ibv_mig_state {
908 	IBV_MIG_MIGRATED,
909 	IBV_MIG_REARM,
910 	IBV_MIG_ARMED
911 };
912 
913 struct ibv_qp_attr {
914 	enum ibv_qp_state	qp_state;
915 	enum ibv_qp_state	cur_qp_state;
916 	enum ibv_mtu		path_mtu;
917 	enum ibv_mig_state	path_mig_state;
918 	uint32_t		qkey;
919 	uint32_t		rq_psn;
920 	uint32_t		sq_psn;
921 	uint32_t		dest_qp_num;
922 	int			qp_access_flags;
923 	struct ibv_qp_cap	cap;
924 	struct ibv_ah_attr	ah_attr;
925 	struct ibv_ah_attr	alt_ah_attr;
926 	uint16_t		pkey_index;
927 	uint16_t		alt_pkey_index;
928 	uint8_t			en_sqd_async_notify;
929 	uint8_t			sq_draining;
930 	uint8_t			max_rd_atomic;
931 	uint8_t			max_dest_rd_atomic;
932 	uint8_t			min_rnr_timer;
933 	uint8_t			port_num;
934 	uint8_t			timeout;
935 	uint8_t			retry_cnt;
936 	uint8_t			rnr_retry;
937 	uint8_t			alt_port_num;
938 	uint8_t			alt_timeout;
939 	uint32_t		rate_limit;
940 };
941 
942 enum ibv_wr_opcode {
943 	IBV_WR_RDMA_WRITE,
944 	IBV_WR_RDMA_WRITE_WITH_IMM,
945 	IBV_WR_SEND,
946 	IBV_WR_SEND_WITH_IMM,
947 	IBV_WR_RDMA_READ,
948 	IBV_WR_ATOMIC_CMP_AND_SWP,
949 	IBV_WR_ATOMIC_FETCH_AND_ADD,
950 	IBV_WR_LOCAL_INV,
951 	IBV_WR_BIND_MW,
952 	IBV_WR_SEND_WITH_INV,
953 	IBV_WR_TSO,
954 };
955 
956 enum ibv_send_flags {
957 	IBV_SEND_FENCE		= 1 << 0,
958 	IBV_SEND_SIGNALED	= 1 << 1,
959 	IBV_SEND_SOLICITED	= 1 << 2,
960 	IBV_SEND_INLINE		= 1 << 3,
961 	IBV_SEND_IP_CSUM	= 1 << 4
962 };
963 
964 struct ibv_sge {
965 	uint64_t		addr;
966 	uint32_t		length;
967 	uint32_t		lkey;
968 };
969 
970 struct ibv_send_wr {
971 	uint64_t		wr_id;
972 	struct ibv_send_wr     *next;
973 	struct ibv_sge	       *sg_list;
974 	int			num_sge;
975 	enum ibv_wr_opcode	opcode;
976 	int			send_flags;
977 	/* When opcode is *_WITH_IMM: Immediate data in network byte order.
978 	 * When opcode is *_INV: Stores the rkey to invalidate
979 	 */
980 	union {
981 		__be32			imm_data;
982 		uint32_t		invalidate_rkey;
983 	};
984 	union {
985 		struct {
986 			uint64_t	remote_addr;
987 			uint32_t	rkey;
988 		} rdma;
989 		struct {
990 			uint64_t	remote_addr;
991 			uint64_t	compare_add;
992 			uint64_t	swap;
993 			uint32_t	rkey;
994 		} atomic;
995 		struct {
996 			struct ibv_ah  *ah;
997 			uint32_t	remote_qpn;
998 			uint32_t	remote_qkey;
999 		} ud;
1000 	} wr;
1001 	union {
1002 		struct {
1003 			uint32_t    remote_srqn;
1004 		} xrc;
1005 	} qp_type;
1006 	union {
1007 		struct {
1008 			struct ibv_mw	*mw;
1009 			uint32_t		rkey;
1010 			struct ibv_mw_bind_info	bind_info;
1011 		} bind_mw;
1012 		struct {
1013 			void		       *hdr;
1014 			uint16_t		hdr_sz;
1015 			uint16_t		mss;
1016 		} tso;
1017 	};
1018 };
1019 
1020 struct ibv_recv_wr {
1021 	uint64_t		wr_id;
1022 	struct ibv_recv_wr     *next;
1023 	struct ibv_sge	       *sg_list;
1024 	int			num_sge;
1025 };
1026 
1027 struct ibv_mw_bind {
1028 	uint64_t		wr_id;
1029 	int			send_flags;
1030 	struct ibv_mw_bind_info bind_info;
1031 };
1032 
1033 struct ibv_srq {
1034 	struct ibv_context     *context;
1035 	void		       *srq_context;
1036 	struct ibv_pd	       *pd;
1037 	uint32_t		handle;
1038 
1039 	pthread_mutex_t		mutex;
1040 	pthread_cond_t		cond;
1041 	uint32_t		events_completed;
1042 };
1043 
1044 /*
1045  * Work Queue. QP can be created without internal WQs "packaged" inside it,
1046  * this QP can be configured to use "external" WQ object as its
1047  * receive/send queue.
1048  * WQ associated (many to one) with Completion Queue it owns WQ properties
1049  * (PD, WQ size etc).
1050  * WQ of type IBV_WQT_RQ:
1051  * - Contains receive WQEs, in this case its PD serves as scatter as well.
1052  * - Exposes post receive function to be used to post a list of work
1053  *   requests (WRs) to its receive queue.
1054  */
1055 struct ibv_wq {
1056 	struct ibv_context     *context;
1057 	void		       *wq_context;
1058 	struct	ibv_pd	       *pd;
1059 	struct	ibv_cq	       *cq;
1060 	uint32_t		wq_num;
1061 	uint32_t		handle;
1062 	enum ibv_wq_state       state;
1063 	enum ibv_wq_type	wq_type;
1064 	int (*post_recv)(struct ibv_wq *current,
1065 			 struct ibv_recv_wr *recv_wr,
1066 			 struct ibv_recv_wr **bad_recv_wr);
1067 	pthread_mutex_t		mutex;
1068 	pthread_cond_t		cond;
1069 	uint32_t		events_completed;
1070 	uint32_t		comp_mask;
1071 };
1072 
1073 struct ibv_qp {
1074 	struct ibv_context     *context;
1075 	void		       *qp_context;
1076 	struct ibv_pd	       *pd;
1077 	struct ibv_cq	       *send_cq;
1078 	struct ibv_cq	       *recv_cq;
1079 	struct ibv_srq	       *srq;
1080 	uint32_t		handle;
1081 	uint32_t		qp_num;
1082 	enum ibv_qp_state       state;
1083 	enum ibv_qp_type	qp_type;
1084 
1085 	pthread_mutex_t		mutex;
1086 	pthread_cond_t		cond;
1087 	uint32_t		events_completed;
1088 };
1089 
1090 struct ibv_comp_channel {
1091 	struct ibv_context     *context;
1092 	int			fd;
1093 	int			refcnt;
1094 };
1095 
1096 struct ibv_cq {
1097 	struct ibv_context     *context;
1098 	struct ibv_comp_channel *channel;
1099 	void		       *cq_context;
1100 	uint32_t		handle;
1101 	int			cqe;
1102 
1103 	pthread_mutex_t		mutex;
1104 	pthread_cond_t		cond;
1105 	uint32_t		comp_events_completed;
1106 	uint32_t		async_events_completed;
1107 };
1108 
1109 struct ibv_poll_cq_attr {
1110 	uint32_t comp_mask;
1111 };
1112 
1113 struct ibv_cq_ex {
1114 	struct ibv_context     *context;
1115 	struct ibv_comp_channel *channel;
1116 	void		       *cq_context;
1117 	uint32_t		handle;
1118 	int			cqe;
1119 
1120 	pthread_mutex_t		mutex;
1121 	pthread_cond_t		cond;
1122 	uint32_t		comp_events_completed;
1123 	uint32_t		async_events_completed;
1124 
1125 	uint32_t		comp_mask;
1126 	enum ibv_wc_status status;
1127 	uint64_t wr_id;
1128 	int (*start_poll)(struct ibv_cq_ex *current,
1129 			     struct ibv_poll_cq_attr *attr);
1130 	int (*next_poll)(struct ibv_cq_ex *current);
1131 	void (*end_poll)(struct ibv_cq_ex *current);
1132 	enum ibv_wc_opcode (*read_opcode)(struct ibv_cq_ex *current);
1133 	uint32_t (*read_vendor_err)(struct ibv_cq_ex *current);
1134 	uint32_t (*read_byte_len)(struct ibv_cq_ex *current);
1135 	__be32 (*read_imm_data)(struct ibv_cq_ex *current);
1136 	uint32_t (*read_qp_num)(struct ibv_cq_ex *current);
1137 	uint32_t (*read_src_qp)(struct ibv_cq_ex *current);
1138 	int (*read_wc_flags)(struct ibv_cq_ex *current);
1139 	uint32_t (*read_slid)(struct ibv_cq_ex *current);
1140 	uint8_t (*read_sl)(struct ibv_cq_ex *current);
1141 	uint8_t (*read_dlid_path_bits)(struct ibv_cq_ex *current);
1142 	uint64_t (*read_completion_ts)(struct ibv_cq_ex *current);
1143 	uint16_t (*read_cvlan)(struct ibv_cq_ex *current);
1144 	uint32_t (*read_flow_tag)(struct ibv_cq_ex *current);
1145 };
1146 
ibv_cq_ex_to_cq(struct ibv_cq_ex * cq)1147 static inline struct ibv_cq *ibv_cq_ex_to_cq(struct ibv_cq_ex *cq)
1148 {
1149 	return (struct ibv_cq *)cq;
1150 }
1151 
ibv_start_poll(struct ibv_cq_ex * cq,struct ibv_poll_cq_attr * attr)1152 static inline int ibv_start_poll(struct ibv_cq_ex *cq,
1153 				    struct ibv_poll_cq_attr *attr)
1154 {
1155 	return cq->start_poll(cq, attr);
1156 }
1157 
ibv_next_poll(struct ibv_cq_ex * cq)1158 static inline int ibv_next_poll(struct ibv_cq_ex *cq)
1159 {
1160 	return cq->next_poll(cq);
1161 }
1162 
ibv_end_poll(struct ibv_cq_ex * cq)1163 static inline void ibv_end_poll(struct ibv_cq_ex *cq)
1164 {
1165 	cq->end_poll(cq);
1166 }
1167 
ibv_wc_read_opcode(struct ibv_cq_ex * cq)1168 static inline enum ibv_wc_opcode ibv_wc_read_opcode(struct ibv_cq_ex *cq)
1169 {
1170 	return cq->read_opcode(cq);
1171 }
1172 
ibv_wc_read_vendor_err(struct ibv_cq_ex * cq)1173 static inline uint32_t ibv_wc_read_vendor_err(struct ibv_cq_ex *cq)
1174 {
1175 	return cq->read_vendor_err(cq);
1176 }
1177 
ibv_wc_read_byte_len(struct ibv_cq_ex * cq)1178 static inline uint32_t ibv_wc_read_byte_len(struct ibv_cq_ex *cq)
1179 {
1180 	return cq->read_byte_len(cq);
1181 }
1182 
ibv_wc_read_imm_data(struct ibv_cq_ex * cq)1183 static inline __be32 ibv_wc_read_imm_data(struct ibv_cq_ex *cq)
1184 {
1185 	return cq->read_imm_data(cq);
1186 }
1187 
ibv_wc_read_invalidated_rkey(struct ibv_cq_ex * cq)1188 static inline uint32_t ibv_wc_read_invalidated_rkey(struct ibv_cq_ex *cq)
1189 {
1190 #ifdef __CHECKER__
1191 	return (__attribute__((force)) uint32_t)cq->read_imm_data(cq);
1192 #else
1193 	return cq->read_imm_data(cq);
1194 #endif
1195 }
1196 
ibv_wc_read_qp_num(struct ibv_cq_ex * cq)1197 static inline uint32_t ibv_wc_read_qp_num(struct ibv_cq_ex *cq)
1198 {
1199 	return cq->read_qp_num(cq);
1200 }
1201 
ibv_wc_read_src_qp(struct ibv_cq_ex * cq)1202 static inline uint32_t ibv_wc_read_src_qp(struct ibv_cq_ex *cq)
1203 {
1204 	return cq->read_src_qp(cq);
1205 }
1206 
ibv_wc_read_wc_flags(struct ibv_cq_ex * cq)1207 static inline int ibv_wc_read_wc_flags(struct ibv_cq_ex *cq)
1208 {
1209 	return cq->read_wc_flags(cq);
1210 }
1211 
ibv_wc_read_slid(struct ibv_cq_ex * cq)1212 static inline uint32_t ibv_wc_read_slid(struct ibv_cq_ex *cq)
1213 {
1214 	return cq->read_slid(cq);
1215 }
1216 
ibv_wc_read_sl(struct ibv_cq_ex * cq)1217 static inline uint8_t ibv_wc_read_sl(struct ibv_cq_ex *cq)
1218 {
1219 	return cq->read_sl(cq);
1220 }
1221 
ibv_wc_read_dlid_path_bits(struct ibv_cq_ex * cq)1222 static inline uint8_t ibv_wc_read_dlid_path_bits(struct ibv_cq_ex *cq)
1223 {
1224 	return cq->read_dlid_path_bits(cq);
1225 }
1226 
ibv_wc_read_completion_ts(struct ibv_cq_ex * cq)1227 static inline uint64_t ibv_wc_read_completion_ts(struct ibv_cq_ex *cq)
1228 {
1229 	return cq->read_completion_ts(cq);
1230 }
1231 
ibv_wc_read_cvlan(struct ibv_cq_ex * cq)1232 static inline uint16_t ibv_wc_read_cvlan(struct ibv_cq_ex *cq)
1233 {
1234 	return cq->read_cvlan(cq);
1235 }
1236 
ibv_wc_read_flow_tag(struct ibv_cq_ex * cq)1237 static inline uint32_t ibv_wc_read_flow_tag(struct ibv_cq_ex *cq)
1238 {
1239 	return cq->read_flow_tag(cq);
1240 }
1241 
ibv_post_wq_recv(struct ibv_wq * wq,struct ibv_recv_wr * recv_wr,struct ibv_recv_wr ** bad_recv_wr)1242 static inline int ibv_post_wq_recv(struct ibv_wq *wq,
1243 				   struct ibv_recv_wr *recv_wr,
1244 				   struct ibv_recv_wr **bad_recv_wr)
1245 {
1246 	return wq->post_recv(wq, recv_wr, bad_recv_wr);
1247 }
1248 
1249 struct ibv_ah {
1250 	struct ibv_context     *context;
1251 	struct ibv_pd	       *pd;
1252 	uint32_t		handle;
1253 };
1254 
1255 enum ibv_flow_flags {
1256 	IBV_FLOW_ATTR_FLAGS_ALLOW_LOOP_BACK = 1 << 0,
1257 	IBV_FLOW_ATTR_FLAGS_DONT_TRAP = 1 << 1,
1258 };
1259 
1260 enum ibv_flow_attr_type {
1261 	/* steering according to rule specifications */
1262 	IBV_FLOW_ATTR_NORMAL		= 0x0,
1263 	/* default unicast and multicast rule -
1264 	 * receive all Eth traffic which isn't steered to any QP
1265 	 */
1266 	IBV_FLOW_ATTR_ALL_DEFAULT	= 0x1,
1267 	/* default multicast rule -
1268 	 * receive all Eth multicast traffic which isn't steered to any QP
1269 	 */
1270 	IBV_FLOW_ATTR_MC_DEFAULT	= 0x2,
1271 	/* sniffer rule - receive all port traffic */
1272 	IBV_FLOW_ATTR_SNIFFER		= 0x3,
1273 };
1274 
1275 enum ibv_flow_spec_type {
1276 	IBV_FLOW_SPEC_ETH		= 0x20,
1277 	IBV_FLOW_SPEC_IPV4		= 0x30,
1278 	IBV_FLOW_SPEC_IPV6		= 0x31,
1279 	IBV_FLOW_SPEC_IPV4_EXT		= 0x32,
1280 	IBV_FLOW_SPEC_TCP		= 0x40,
1281 	IBV_FLOW_SPEC_UDP		= 0x41,
1282 	IBV_FLOW_SPEC_VXLAN_TUNNEL	= 0x50,
1283 	IBV_FLOW_SPEC_GRE		= 0x51,
1284 	IBV_FLOW_SPEC_MPLS		= 0x60,
1285 	IBV_FLOW_SPEC_INNER		= 0x100,
1286 	IBV_FLOW_SPEC_ACTION_TAG	= 0x1000,
1287 	IBV_FLOW_SPEC_ACTION_DROP	= 0x1001,
1288 };
1289 
1290 struct ibv_flow_eth_filter {
1291 	uint8_t		dst_mac[6];
1292 	uint8_t		src_mac[6];
1293 	uint16_t	ether_type;
1294 	/*
1295 	 * same layout as 802.1q: prio 3, cfi 1, vlan id 12
1296 	 */
1297 	uint16_t	vlan_tag;
1298 };
1299 
1300 struct ibv_flow_spec_eth {
1301 	enum ibv_flow_spec_type  type;
1302 	uint16_t  size;
1303 	struct ibv_flow_eth_filter val;
1304 	struct ibv_flow_eth_filter mask;
1305 };
1306 
1307 struct ibv_flow_ipv4_filter {
1308 	uint32_t src_ip;
1309 	uint32_t dst_ip;
1310 };
1311 
1312 struct ibv_flow_spec_ipv4 {
1313 	enum ibv_flow_spec_type  type;
1314 	uint16_t  size;
1315 	struct ibv_flow_ipv4_filter val;
1316 	struct ibv_flow_ipv4_filter mask;
1317 };
1318 
1319 struct ibv_flow_ipv4_ext_filter {
1320 	uint32_t src_ip;
1321 	uint32_t dst_ip;
1322 	uint8_t  proto;
1323 	uint8_t  tos;
1324 	uint8_t  ttl;
1325 	uint8_t  flags;
1326 };
1327 
1328 struct ibv_flow_spec_ipv4_ext {
1329 	enum ibv_flow_spec_type  type;
1330 	uint16_t  size;
1331 	struct ibv_flow_ipv4_ext_filter val;
1332 	struct ibv_flow_ipv4_ext_filter mask;
1333 };
1334 
1335 struct ibv_flow_ipv6_filter {
1336 	uint8_t  src_ip[16];
1337 	uint8_t  dst_ip[16];
1338 	uint32_t flow_label;
1339 	uint8_t  next_hdr;
1340 	uint8_t  traffic_class;
1341 	uint8_t  hop_limit;
1342 };
1343 
1344 struct ibv_flow_spec_ipv6 {
1345 	enum ibv_flow_spec_type  type;
1346 	uint16_t  size;
1347 	struct ibv_flow_ipv6_filter val;
1348 	struct ibv_flow_ipv6_filter mask;
1349 };
1350 
1351 struct ibv_flow_tcp_udp_filter {
1352 	uint16_t dst_port;
1353 	uint16_t src_port;
1354 };
1355 
1356 struct ibv_flow_spec_tcp_udp {
1357 	enum ibv_flow_spec_type  type;
1358 	uint16_t  size;
1359 	struct ibv_flow_tcp_udp_filter val;
1360 	struct ibv_flow_tcp_udp_filter mask;
1361 };
1362 
1363 struct ibv_flow_gre_filter {
1364 	/* c_ks_res0_ver field is bits 0-15 in offset 0 of a standard GRE header:
1365 	 * bit 0 - checksum present bit.
1366 	 * bit 1 - reserved. set to 0.
1367 	 * bit 2 - key present bit.
1368 	 * bit 3 - sequence number present bit.
1369 	 * bits 4:12 - reserved. set to 0.
1370 	 * bits 13:15 - GRE version.
1371 	 */
1372 	uint16_t c_ks_res0_ver;
1373 	uint16_t protocol;
1374 	uint32_t key;
1375 };
1376 
1377 struct ibv_flow_spec_gre {
1378 	enum ibv_flow_spec_type  type;
1379 	uint16_t  size;
1380 	struct ibv_flow_gre_filter val;
1381 	struct ibv_flow_gre_filter mask;
1382 };
1383 
1384 struct ibv_flow_mpls_filter {
1385 	/* The field includes the entire MPLS label:
1386 	 * bits 0:19 - label value field.
1387 	 * bits 20:22 - traffic class field.
1388 	 * bits 23 - bottom of stack bit.
1389 	 * bits 24:31 - ttl field.
1390 	 */
1391 	uint32_t label;
1392 };
1393 
1394 struct ibv_flow_spec_mpls {
1395 	enum ibv_flow_spec_type  type;
1396 	uint16_t  size;
1397 	struct ibv_flow_mpls_filter val;
1398 	struct ibv_flow_mpls_filter mask;
1399 };
1400 
1401 struct ibv_flow_tunnel_filter {
1402 	uint32_t tunnel_id;
1403 };
1404 
1405 struct ibv_flow_spec_tunnel {
1406 	enum ibv_flow_spec_type  type;
1407 	uint16_t  size;
1408 	struct ibv_flow_tunnel_filter val;
1409 	struct ibv_flow_tunnel_filter mask;
1410 };
1411 
1412 struct ibv_flow_spec_action_tag {
1413 	enum ibv_flow_spec_type  type;
1414 	uint16_t  size;
1415 	uint32_t  tag_id;
1416 };
1417 
1418 struct ibv_flow_spec_action_drop {
1419 	enum ibv_flow_spec_type  type;
1420 	uint16_t  size;
1421 };
1422 
1423 struct ibv_flow_spec {
1424 	union {
1425 		struct {
1426 			enum ibv_flow_spec_type	type;
1427 			uint16_t		size;
1428 		} hdr;
1429 		struct ibv_flow_spec_eth eth;
1430 		struct ibv_flow_spec_ipv4 ipv4;
1431 		struct ibv_flow_spec_tcp_udp tcp_udp;
1432 		struct ibv_flow_spec_ipv4_ext ipv4_ext;
1433 		struct ibv_flow_spec_ipv6 ipv6;
1434 		struct ibv_flow_spec_tunnel tunnel;
1435 		struct ibv_flow_spec_gre gre;
1436 		struct ibv_flow_spec_mpls mpls;
1437 		struct ibv_flow_spec_action_tag flow_tag;
1438 		struct ibv_flow_spec_action_drop drop;
1439 	};
1440 };
1441 
1442 struct ibv_flow_attr {
1443 	uint32_t comp_mask;
1444 	enum ibv_flow_attr_type type;
1445 	uint16_t size;
1446 	uint16_t priority;
1447 	uint8_t num_of_specs;
1448 	uint8_t port;
1449 	uint32_t flags;
1450 	/* Following are the optional layers according to user request
1451 	 * struct ibv_flow_spec_xxx [L2]
1452 	 * struct ibv_flow_spec_yyy [L3/L4]
1453 	 */
1454 };
1455 
1456 struct ibv_flow {
1457 	uint32_t	   comp_mask;
1458 	struct ibv_context *context;
1459 	uint32_t	   handle;
1460 };
1461 
1462 struct ibv_device;
1463 struct ibv_context;
1464 
1465 /* Obsolete, never used, do not touch */
1466 struct _ibv_device_ops {
1467 	struct ibv_context *	(*_dummy1)(struct ibv_device *device, int cmd_fd);
1468 	void			(*_dummy2)(struct ibv_context *context);
1469 };
1470 
1471 enum {
1472 	IBV_SYSFS_NAME_MAX	= 64,
1473 	IBV_SYSFS_PATH_MAX	= 256
1474 };
1475 
1476 struct ibv_device {
1477 	struct _ibv_device_ops	_ops;
1478 	enum ibv_node_type	node_type;
1479 	enum ibv_transport_type	transport_type;
1480 	/* Name of underlying kernel IB device, eg "mthca0" */
1481 	char			name[IBV_SYSFS_NAME_MAX];
1482 	/* Name of uverbs device, eg "uverbs0" */
1483 	char			dev_name[IBV_SYSFS_NAME_MAX];
1484 	/* Path to infiniband_verbs class device in sysfs */
1485 	char			dev_path[IBV_SYSFS_PATH_MAX];
1486 	/* Path to infiniband class device in sysfs */
1487 	char			ibdev_path[IBV_SYSFS_PATH_MAX];
1488 };
1489 
1490 struct ibv_context_ops {
1491 	int			(*query_device)(struct ibv_context *context,
1492 					      struct ibv_device_attr *device_attr);
1493 	int			(*query_port)(struct ibv_context *context, uint8_t port_num,
1494 					      struct ibv_port_attr *port_attr);
1495 	struct ibv_pd *		(*alloc_pd)(struct ibv_context *context);
1496 	int			(*dealloc_pd)(struct ibv_pd *pd);
1497 	struct ibv_mr *		(*reg_mr)(struct ibv_pd *pd, void *addr, size_t length,
1498 					  int access);
1499 	int			(*rereg_mr)(struct ibv_mr *mr,
1500 					    int flags,
1501 					    struct ibv_pd *pd, void *addr,
1502 					    size_t length,
1503 					    int access);
1504 	int			(*dereg_mr)(struct ibv_mr *mr);
1505 	struct ibv_mw *		(*alloc_mw)(struct ibv_pd *pd, enum ibv_mw_type type);
1506 	int			(*bind_mw)(struct ibv_qp *qp, struct ibv_mw *mw,
1507 					   struct ibv_mw_bind *mw_bind);
1508 	int			(*dealloc_mw)(struct ibv_mw *mw);
1509 	struct ibv_cq *		(*create_cq)(struct ibv_context *context, int cqe,
1510 					     struct ibv_comp_channel *channel,
1511 					     int comp_vector);
1512 	int			(*poll_cq)(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc);
1513 	int			(*req_notify_cq)(struct ibv_cq *cq, int solicited_only);
1514 	void			(*cq_event)(struct ibv_cq *cq);
1515 	int			(*resize_cq)(struct ibv_cq *cq, int cqe);
1516 	int			(*destroy_cq)(struct ibv_cq *cq);
1517 	struct ibv_srq *	(*create_srq)(struct ibv_pd *pd,
1518 					      struct ibv_srq_init_attr *srq_init_attr);
1519 	int			(*modify_srq)(struct ibv_srq *srq,
1520 					      struct ibv_srq_attr *srq_attr,
1521 					      int srq_attr_mask);
1522 	int			(*query_srq)(struct ibv_srq *srq,
1523 					     struct ibv_srq_attr *srq_attr);
1524 	int			(*destroy_srq)(struct ibv_srq *srq);
1525 	int			(*post_srq_recv)(struct ibv_srq *srq,
1526 						 struct ibv_recv_wr *recv_wr,
1527 						 struct ibv_recv_wr **bad_recv_wr);
1528 	struct ibv_qp *		(*create_qp)(struct ibv_pd *pd, struct ibv_qp_init_attr *attr);
1529 	int			(*query_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
1530 					    int attr_mask,
1531 					    struct ibv_qp_init_attr *init_attr);
1532 	int			(*modify_qp)(struct ibv_qp *qp, struct ibv_qp_attr *attr,
1533 					     int attr_mask);
1534 	int			(*destroy_qp)(struct ibv_qp *qp);
1535 	int			(*post_send)(struct ibv_qp *qp, struct ibv_send_wr *wr,
1536 					     struct ibv_send_wr **bad_wr);
1537 	int			(*post_recv)(struct ibv_qp *qp, struct ibv_recv_wr *wr,
1538 					     struct ibv_recv_wr **bad_wr);
1539 	struct ibv_ah *		(*create_ah)(struct ibv_pd *pd, struct ibv_ah_attr *attr);
1540 	int			(*destroy_ah)(struct ibv_ah *ah);
1541 	int			(*attach_mcast)(struct ibv_qp *qp, const union ibv_gid *gid,
1542 						uint16_t lid);
1543 	int			(*detach_mcast)(struct ibv_qp *qp, const union ibv_gid *gid,
1544 						uint16_t lid);
1545 	void			(*async_event)(struct ibv_async_event *event);
1546 };
1547 
1548 struct ibv_context {
1549 	struct ibv_device      *device;
1550 	struct ibv_context_ops	ops;
1551 	int			cmd_fd;
1552 	int			async_fd;
1553 	int			num_comp_vectors;
1554 	pthread_mutex_t		mutex;
1555 	void		       *abi_compat;
1556 };
1557 
1558 enum ibv_cq_init_attr_mask {
1559 	IBV_CQ_INIT_ATTR_MASK_FLAGS	= 1 << 0,
1560 	IBV_CQ_INIT_ATTR_MASK_RESERVED	= 1 << 1
1561 };
1562 
1563 enum ibv_create_cq_attr_flags {
1564 	IBV_CREATE_CQ_ATTR_SINGLE_THREADED = 1 << 0,
1565 	IBV_CREATE_CQ_ATTR_RESERVED = 1 << 1,
1566 };
1567 
1568 struct ibv_cq_init_attr_ex {
1569 	/* Minimum number of entries required for CQ */
1570 	uint32_t			cqe;
1571 	/* Consumer-supplied context returned for completion events */
1572 	void			*cq_context;
1573 	/* Completion channel where completion events will be queued.
1574 	 * May be NULL if completion events will not be used.
1575 	 */
1576 	struct ibv_comp_channel *channel;
1577 	/* Completion vector used to signal completion events.
1578 	 *  Must be < context->num_comp_vectors.
1579 	 */
1580 	uint32_t			comp_vector;
1581 	 /* Or'ed bit of enum ibv_create_cq_wc_flags. */
1582 	uint64_t		wc_flags;
1583 	/* compatibility mask (extended verb). Or'd flags of
1584 	 * enum ibv_cq_init_attr_mask
1585 	 */
1586 	uint32_t		comp_mask;
1587 	/* create cq attr flags - one or more flags from
1588 	 * enum ibv_create_cq_attr_flags
1589 	 */
1590 	uint32_t		flags;
1591 };
1592 
1593 enum ibv_values_mask {
1594 	IBV_VALUES_MASK_RAW_CLOCK	= 1 << 0,
1595 	IBV_VALUES_MASK_RESERVED	= 1 << 1
1596 };
1597 
1598 struct ibv_values_ex {
1599 	uint32_t	comp_mask;
1600 	struct timespec raw_clock;
1601 };
1602 
1603 enum verbs_context_mask {
1604 	VERBS_CONTEXT_XRCD	= 1 << 0,
1605 	VERBS_CONTEXT_SRQ	= 1 << 1,
1606 	VERBS_CONTEXT_QP	= 1 << 2,
1607 	VERBS_CONTEXT_CREATE_FLOW = 1 << 3,
1608 	VERBS_CONTEXT_DESTROY_FLOW = 1 << 4,
1609 	VERBS_CONTEXT_RESERVED	= 1 << 5
1610 };
1611 
1612 struct verbs_context {
1613 	/*  "grows up" - new fields go here */
1614 	int (*destroy_rwq_ind_table)(struct ibv_rwq_ind_table *rwq_ind_table);
1615 	struct ibv_rwq_ind_table *(*create_rwq_ind_table)(struct ibv_context *context,
1616 							  struct ibv_rwq_ind_table_init_attr *init_attr);
1617 	int (*destroy_wq)(struct ibv_wq *wq);
1618 	int (*modify_wq)(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr);
1619 	struct ibv_wq * (*create_wq)(struct ibv_context *context,
1620 				     struct ibv_wq_init_attr *wq_init_attr);
1621 	int (*query_rt_values)(struct ibv_context *context,
1622 			       struct ibv_values_ex *values);
1623 	struct ibv_cq_ex *(*create_cq_ex)(struct ibv_context *context,
1624 					  struct ibv_cq_init_attr_ex *init_attr);
1625 	struct verbs_ex_private *priv;
1626 	int (*query_device_ex)(struct ibv_context *context,
1627 			       const struct ibv_query_device_ex_input *input,
1628 			       struct ibv_device_attr_ex *attr,
1629 			       size_t attr_size);
1630 	int (*ibv_destroy_flow) (struct ibv_flow *flow);
1631 	void (*ABI_placeholder2) (void); /* DO NOT COPY THIS GARBAGE */
1632 	struct ibv_flow * (*ibv_create_flow) (struct ibv_qp *qp,
1633 					      struct ibv_flow_attr *flow_attr);
1634 	void (*ABI_placeholder1) (void); /* DO NOT COPY THIS GARBAGE */
1635 	struct ibv_qp *(*open_qp)(struct ibv_context *context,
1636 			struct ibv_qp_open_attr *attr);
1637 	struct ibv_qp *(*create_qp_ex)(struct ibv_context *context,
1638 			struct ibv_qp_init_attr_ex *qp_init_attr_ex);
1639 	int (*get_srq_num)(struct ibv_srq *srq, uint32_t *srq_num);
1640 	struct ibv_srq *	(*create_srq_ex)(struct ibv_context *context,
1641 						 struct ibv_srq_init_attr_ex *srq_init_attr_ex);
1642 	struct ibv_xrcd *	(*open_xrcd)(struct ibv_context *context,
1643 					     struct ibv_xrcd_init_attr *xrcd_init_attr);
1644 	int			(*close_xrcd)(struct ibv_xrcd *xrcd);
1645 	uint64_t has_comp_mask;
1646 	size_t   sz;			/* Must be immediately before struct ibv_context */
1647 	struct ibv_context context;	/* Must be last field in the struct */
1648 };
1649 
verbs_get_ctx(struct ibv_context * ctx)1650 static inline struct verbs_context *verbs_get_ctx(struct ibv_context *ctx)
1651 {
1652 	return (ctx->abi_compat != __VERBS_ABI_IS_EXTENDED) ?
1653 		NULL : container_of(ctx, struct verbs_context, context);
1654 }
1655 
1656 #define verbs_get_ctx_op(ctx, op) ({ \
1657 	struct verbs_context *__vctx = verbs_get_ctx(ctx); \
1658 	(!__vctx || (__vctx->sz < sizeof(*__vctx) - offsetof(struct verbs_context, op)) || \
1659 	 !__vctx->op) ? NULL : __vctx; })
1660 
1661 #define verbs_set_ctx_op(_vctx, op, ptr) ({ \
1662 	struct verbs_context *vctx = _vctx; \
1663 	if (vctx && (vctx->sz >= sizeof(*vctx) - offsetof(struct verbs_context, op))) \
1664 		vctx->op = ptr; })
1665 
1666 /**
1667  * ibv_get_device_list - Get list of IB devices currently available
1668  * @num_devices: optional.  if non-NULL, set to the number of devices
1669  * returned in the array.
1670  *
1671  * Return a NULL-terminated array of IB devices.  The array can be
1672  * released with ibv_free_device_list().
1673  */
1674 struct ibv_device **ibv_get_device_list(int *num_devices);
1675 
1676 /**
1677  * ibv_free_device_list - Free list from ibv_get_device_list()
1678  *
1679  * Free an array of devices returned from ibv_get_device_list().  Once
1680  * the array is freed, pointers to devices that were not opened with
1681  * ibv_open_device() are no longer valid.  Client code must open all
1682  * devices it intends to use before calling ibv_free_device_list().
1683  */
1684 void ibv_free_device_list(struct ibv_device **list);
1685 
1686 /**
1687  * ibv_get_device_name - Return kernel device name
1688  */
1689 const char *ibv_get_device_name(struct ibv_device *device);
1690 
1691 /**
1692  * ibv_get_device_guid - Return device's node GUID
1693  */
1694 __be64 ibv_get_device_guid(struct ibv_device *device);
1695 
1696 /**
1697  * ibv_open_device - Initialize device for use
1698  */
1699 struct ibv_context *ibv_open_device(struct ibv_device *device);
1700 
1701 /**
1702  * ibv_close_device - Release device
1703  */
1704 int ibv_close_device(struct ibv_context *context);
1705 
1706 /**
1707  * ibv_get_async_event - Get next async event
1708  * @event: Pointer to use to return async event
1709  *
1710  * All async events returned by ibv_get_async_event() must eventually
1711  * be acknowledged with ibv_ack_async_event().
1712  */
1713 int ibv_get_async_event(struct ibv_context *context,
1714 			struct ibv_async_event *event);
1715 
1716 /**
1717  * ibv_ack_async_event - Acknowledge an async event
1718  * @event: Event to be acknowledged.
1719  *
1720  * All async events which are returned by ibv_get_async_event() must
1721  * be acknowledged.  To avoid races, destroying an object (CQ, SRQ or
1722  * QP) will wait for all affiliated events to be acknowledged, so
1723  * there should be a one-to-one correspondence between acks and
1724  * successful gets.
1725  */
1726 void ibv_ack_async_event(struct ibv_async_event *event);
1727 
1728 /**
1729  * ibv_query_device - Get device properties
1730  */
1731 int ibv_query_device(struct ibv_context *context,
1732 		     struct ibv_device_attr *device_attr);
1733 
1734 /**
1735  * ibv_query_port - Get port properties
1736  */
1737 int ibv_query_port(struct ibv_context *context, uint8_t port_num,
1738 		   struct ibv_port_attr *port_attr);
1739 
___ibv_query_port(struct ibv_context * context,uint8_t port_num,struct ibv_port_attr * port_attr)1740 static inline int ___ibv_query_port(struct ibv_context *context,
1741 				    uint8_t port_num,
1742 				    struct ibv_port_attr *port_attr)
1743 {
1744 	/* For compatibility when running with old libibverbs */
1745 	port_attr->link_layer = IBV_LINK_LAYER_UNSPECIFIED;
1746 	port_attr->reserved   = 0;
1747 
1748 	return ibv_query_port(context, port_num, port_attr);
1749 }
1750 
1751 #define ibv_query_port(context, port_num, port_attr) \
1752 	___ibv_query_port(context, port_num, port_attr)
1753 
1754 /**
1755  * ibv_query_gid - Get a GID table entry
1756  */
1757 int ibv_query_gid(struct ibv_context *context, uint8_t port_num,
1758 		  int index, union ibv_gid *gid);
1759 
1760 /**
1761  * ibv_query_pkey - Get a P_Key table entry
1762  */
1763 int ibv_query_pkey(struct ibv_context *context, uint8_t port_num,
1764 		   int index, __be16 *pkey);
1765 
1766 /**
1767  * ibv_alloc_pd - Allocate a protection domain
1768  */
1769 struct ibv_pd *ibv_alloc_pd(struct ibv_context *context);
1770 
1771 /**
1772  * ibv_dealloc_pd - Free a protection domain
1773  */
1774 int ibv_dealloc_pd(struct ibv_pd *pd);
1775 
ibv_create_flow(struct ibv_qp * qp,struct ibv_flow_attr * flow)1776 static inline struct ibv_flow *ibv_create_flow(struct ibv_qp *qp,
1777 					       struct ibv_flow_attr *flow)
1778 {
1779 	struct verbs_context *vctx = verbs_get_ctx_op(qp->context,
1780 						      ibv_create_flow);
1781 	if (!vctx || !vctx->ibv_create_flow) {
1782 		errno = ENOSYS;
1783 		return NULL;
1784 	}
1785 
1786 	return vctx->ibv_create_flow(qp, flow);
1787 }
1788 
ibv_destroy_flow(struct ibv_flow * flow_id)1789 static inline int ibv_destroy_flow(struct ibv_flow *flow_id)
1790 {
1791 	struct verbs_context *vctx = verbs_get_ctx_op(flow_id->context,
1792 						      ibv_destroy_flow);
1793 	if (!vctx || !vctx->ibv_destroy_flow)
1794 		return -ENOSYS;
1795 	return vctx->ibv_destroy_flow(flow_id);
1796 }
1797 
1798 /**
1799  * ibv_open_xrcd - Open an extended connection domain
1800  */
1801 static inline struct ibv_xrcd *
ibv_open_xrcd(struct ibv_context * context,struct ibv_xrcd_init_attr * xrcd_init_attr)1802 ibv_open_xrcd(struct ibv_context *context, struct ibv_xrcd_init_attr *xrcd_init_attr)
1803 {
1804 	struct verbs_context *vctx = verbs_get_ctx_op(context, open_xrcd);
1805 	if (!vctx) {
1806 		errno = ENOSYS;
1807 		return NULL;
1808 	}
1809 	return vctx->open_xrcd(context, xrcd_init_attr);
1810 }
1811 
1812 /**
1813  * ibv_close_xrcd - Close an extended connection domain
1814  */
ibv_close_xrcd(struct ibv_xrcd * xrcd)1815 static inline int ibv_close_xrcd(struct ibv_xrcd *xrcd)
1816 {
1817 	struct verbs_context *vctx = verbs_get_ctx(xrcd->context);
1818 	return vctx->close_xrcd(xrcd);
1819 }
1820 
1821 /**
1822  * ibv_reg_mr - Register a memory region
1823  */
1824 struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, void *addr,
1825 			  size_t length, int access);
1826 
1827 
1828 enum ibv_rereg_mr_err_code {
1829 	/* Old MR is valid, invalid input */
1830 	IBV_REREG_MR_ERR_INPUT = -1,
1831 	/* Old MR is valid, failed via don't fork on new address range */
1832 	IBV_REREG_MR_ERR_DONT_FORK_NEW = -2,
1833 	/* New MR is valid, failed via do fork on old address range */
1834 	IBV_REREG_MR_ERR_DO_FORK_OLD = -3,
1835 	/* MR shouldn't be used, command error */
1836 	IBV_REREG_MR_ERR_CMD = -4,
1837 	/* MR shouldn't be used, command error, invalid fork state on new address range */
1838 	IBV_REREG_MR_ERR_CMD_AND_DO_FORK_NEW = -5,
1839 };
1840 
1841 /**
1842  * ibv_rereg_mr - Re-Register a memory region
1843  */
1844 int ibv_rereg_mr(struct ibv_mr *mr, int flags,
1845 		 struct ibv_pd *pd, void *addr,
1846 		 size_t length, int access);
1847 /**
1848  * ibv_dereg_mr - Deregister a memory region
1849  */
1850 int ibv_dereg_mr(struct ibv_mr *mr);
1851 
1852 /**
1853  * ibv_alloc_mw - Allocate a memory window
1854  */
ibv_alloc_mw(struct ibv_pd * pd,enum ibv_mw_type type)1855 static inline struct ibv_mw *ibv_alloc_mw(struct ibv_pd *pd,
1856 					  enum ibv_mw_type type)
1857 {
1858 	struct ibv_mw *mw;
1859 
1860 	if (!pd->context->ops.alloc_mw) {
1861 		errno = ENOSYS;
1862 		return NULL;
1863 	}
1864 
1865 	mw = pd->context->ops.alloc_mw(pd, type);
1866 	return mw;
1867 }
1868 
1869 /**
1870  * ibv_dealloc_mw - Free a memory window
1871  */
ibv_dealloc_mw(struct ibv_mw * mw)1872 static inline int ibv_dealloc_mw(struct ibv_mw *mw)
1873 {
1874 	return mw->context->ops.dealloc_mw(mw);
1875 }
1876 
1877 /**
1878  * ibv_inc_rkey - Increase the 8 lsb in the given rkey
1879  */
ibv_inc_rkey(uint32_t rkey)1880 static inline uint32_t ibv_inc_rkey(uint32_t rkey)
1881 {
1882 	const uint32_t mask = 0x000000ff;
1883 	uint8_t newtag = (uint8_t)((rkey + 1) & mask);
1884 
1885 	return (rkey & ~mask) | newtag;
1886 }
1887 
1888 /**
1889  * ibv_bind_mw - Bind a memory window to a region
1890  */
ibv_bind_mw(struct ibv_qp * qp,struct ibv_mw * mw,struct ibv_mw_bind * mw_bind)1891 static inline int ibv_bind_mw(struct ibv_qp *qp, struct ibv_mw *mw,
1892 			      struct ibv_mw_bind *mw_bind)
1893 {
1894 	if (mw->type != IBV_MW_TYPE_1)
1895 		return EINVAL;
1896 
1897 	return mw->context->ops.bind_mw(qp, mw, mw_bind);
1898 }
1899 
1900 /**
1901  * ibv_create_comp_channel - Create a completion event channel
1902  */
1903 struct ibv_comp_channel *ibv_create_comp_channel(struct ibv_context *context);
1904 
1905 /**
1906  * ibv_destroy_comp_channel - Destroy a completion event channel
1907  */
1908 int ibv_destroy_comp_channel(struct ibv_comp_channel *channel);
1909 
1910 /**
1911  * ibv_create_cq - Create a completion queue
1912  * @context - Context CQ will be attached to
1913  * @cqe - Minimum number of entries required for CQ
1914  * @cq_context - Consumer-supplied context returned for completion events
1915  * @channel - Completion channel where completion events will be queued.
1916  *     May be NULL if completion events will not be used.
1917  * @comp_vector - Completion vector used to signal completion events.
1918  *     Must be >= 0 and < context->num_comp_vectors.
1919  */
1920 struct ibv_cq *ibv_create_cq(struct ibv_context *context, int cqe,
1921 			     void *cq_context,
1922 			     struct ibv_comp_channel *channel,
1923 			     int comp_vector);
1924 
1925 /**
1926  * ibv_create_cq_ex - Create a completion queue
1927  * @context - Context CQ will be attached to
1928  * @cq_attr - Attributes to create the CQ with
1929  */
1930 static inline
ibv_create_cq_ex(struct ibv_context * context,struct ibv_cq_init_attr_ex * cq_attr)1931 struct ibv_cq_ex *ibv_create_cq_ex(struct ibv_context *context,
1932 				   struct ibv_cq_init_attr_ex *cq_attr)
1933 {
1934 	struct verbs_context *vctx = verbs_get_ctx_op(context, create_cq_ex);
1935 
1936 	if (!vctx) {
1937 		errno = ENOSYS;
1938 		return NULL;
1939 	}
1940 
1941 	if (cq_attr->comp_mask & ~(IBV_CQ_INIT_ATTR_MASK_RESERVED - 1)) {
1942 		errno = EINVAL;
1943 		return NULL;
1944 	}
1945 
1946 	return vctx->create_cq_ex(context, cq_attr);
1947 }
1948 
1949 /**
1950  * ibv_resize_cq - Modifies the capacity of the CQ.
1951  * @cq: The CQ to resize.
1952  * @cqe: The minimum size of the CQ.
1953  *
1954  * Users can examine the cq structure to determine the actual CQ size.
1955  */
1956 int ibv_resize_cq(struct ibv_cq *cq, int cqe);
1957 
1958 /**
1959  * ibv_destroy_cq - Destroy a completion queue
1960  */
1961 int ibv_destroy_cq(struct ibv_cq *cq);
1962 
1963 /**
1964  * ibv_get_cq_event - Read next CQ event
1965  * @channel: Channel to get next event from.
1966  * @cq: Used to return pointer to CQ.
1967  * @cq_context: Used to return consumer-supplied CQ context.
1968  *
1969  * All completion events returned by ibv_get_cq_event() must
1970  * eventually be acknowledged with ibv_ack_cq_events().
1971  */
1972 int ibv_get_cq_event(struct ibv_comp_channel *channel,
1973 		     struct ibv_cq **cq, void **cq_context);
1974 
1975 /**
1976  * ibv_ack_cq_events - Acknowledge CQ completion events
1977  * @cq: CQ to acknowledge events for
1978  * @nevents: Number of events to acknowledge.
1979  *
1980  * All completion events which are returned by ibv_get_cq_event() must
1981  * be acknowledged.  To avoid races, ibv_destroy_cq() will wait for
1982  * all completion events to be acknowledged, so there should be a
1983  * one-to-one correspondence between acks and successful gets.  An
1984  * application may accumulate multiple completion events and
1985  * acknowledge them in a single call to ibv_ack_cq_events() by passing
1986  * the number of events to ack in @nevents.
1987  */
1988 void ibv_ack_cq_events(struct ibv_cq *cq, unsigned int nevents);
1989 
1990 /**
1991  * ibv_poll_cq - Poll a CQ for work completions
1992  * @cq:the CQ being polled
1993  * @num_entries:maximum number of completions to return
1994  * @wc:array of at least @num_entries of &struct ibv_wc where completions
1995  *   will be returned
1996  *
1997  * Poll a CQ for (possibly multiple) completions.  If the return value
1998  * is < 0, an error occurred.  If the return value is >= 0, it is the
1999  * number of completions returned.  If the return value is
2000  * non-negative and strictly less than num_entries, then the CQ was
2001  * emptied.
2002  */
ibv_poll_cq(struct ibv_cq * cq,int num_entries,struct ibv_wc * wc)2003 static inline int ibv_poll_cq(struct ibv_cq *cq, int num_entries, struct ibv_wc *wc)
2004 {
2005 	return cq->context->ops.poll_cq(cq, num_entries, wc);
2006 }
2007 
2008 /**
2009  * ibv_req_notify_cq - Request completion notification on a CQ.  An
2010  *   event will be added to the completion channel associated with the
2011  *   CQ when an entry is added to the CQ.
2012  * @cq: The completion queue to request notification for.
2013  * @solicited_only: If non-zero, an event will be generated only for
2014  *   the next solicited CQ entry.  If zero, any CQ entry, solicited or
2015  *   not, will generate an event.
2016  */
ibv_req_notify_cq(struct ibv_cq * cq,int solicited_only)2017 static inline int ibv_req_notify_cq(struct ibv_cq *cq, int solicited_only)
2018 {
2019 	return cq->context->ops.req_notify_cq(cq, solicited_only);
2020 }
2021 
2022 /**
2023  * ibv_create_srq - Creates a SRQ associated with the specified protection
2024  *   domain.
2025  * @pd: The protection domain associated with the SRQ.
2026  * @srq_init_attr: A list of initial attributes required to create the SRQ.
2027  *
2028  * srq_attr->max_wr and srq_attr->max_sge are read the determine the
2029  * requested size of the SRQ, and set to the actual values allocated
2030  * on return.  If ibv_create_srq() succeeds, then max_wr and max_sge
2031  * will always be at least as large as the requested values.
2032  */
2033 struct ibv_srq *ibv_create_srq(struct ibv_pd *pd,
2034 			       struct ibv_srq_init_attr *srq_init_attr);
2035 
2036 static inline struct ibv_srq *
ibv_create_srq_ex(struct ibv_context * context,struct ibv_srq_init_attr_ex * srq_init_attr_ex)2037 ibv_create_srq_ex(struct ibv_context *context,
2038 		  struct ibv_srq_init_attr_ex *srq_init_attr_ex)
2039 {
2040 	struct verbs_context *vctx;
2041 	uint32_t mask = srq_init_attr_ex->comp_mask;
2042 
2043 	if (!(mask & ~(IBV_SRQ_INIT_ATTR_PD | IBV_SRQ_INIT_ATTR_TYPE)) &&
2044 	    (mask & IBV_SRQ_INIT_ATTR_PD) &&
2045 	    (!(mask & IBV_SRQ_INIT_ATTR_TYPE) ||
2046 	     (srq_init_attr_ex->srq_type == IBV_SRQT_BASIC)))
2047 		return ibv_create_srq(srq_init_attr_ex->pd,
2048 				      (struct ibv_srq_init_attr *)srq_init_attr_ex);
2049 
2050 	vctx = verbs_get_ctx_op(context, create_srq_ex);
2051 	if (!vctx) {
2052 		errno = ENOSYS;
2053 		return NULL;
2054 	}
2055 	return vctx->create_srq_ex(context, srq_init_attr_ex);
2056 }
2057 
2058 /**
2059  * ibv_modify_srq - Modifies the attributes for the specified SRQ.
2060  * @srq: The SRQ to modify.
2061  * @srq_attr: On input, specifies the SRQ attributes to modify.  On output,
2062  *   the current values of selected SRQ attributes are returned.
2063  * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
2064  *   are being modified.
2065  *
2066  * The mask may contain IBV_SRQ_MAX_WR to resize the SRQ and/or
2067  * IBV_SRQ_LIMIT to set the SRQ's limit and request notification when
2068  * the number of receives queued drops below the limit.
2069  */
2070 int ibv_modify_srq(struct ibv_srq *srq,
2071 		   struct ibv_srq_attr *srq_attr,
2072 		   int srq_attr_mask);
2073 
2074 /**
2075  * ibv_query_srq - Returns the attribute list and current values for the
2076  *   specified SRQ.
2077  * @srq: The SRQ to query.
2078  * @srq_attr: The attributes of the specified SRQ.
2079  */
2080 int ibv_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr);
2081 
ibv_get_srq_num(struct ibv_srq * srq,uint32_t * srq_num)2082 static inline int ibv_get_srq_num(struct ibv_srq *srq, uint32_t *srq_num)
2083 {
2084 	struct verbs_context *vctx = verbs_get_ctx_op(srq->context, get_srq_num);
2085 
2086 	if (!vctx)
2087 		return ENOSYS;
2088 
2089 	return vctx->get_srq_num(srq, srq_num);
2090 }
2091 
2092 /**
2093  * ibv_destroy_srq - Destroys the specified SRQ.
2094  * @srq: The SRQ to destroy.
2095  */
2096 int ibv_destroy_srq(struct ibv_srq *srq);
2097 
2098 /**
2099  * ibv_post_srq_recv - Posts a list of work requests to the specified SRQ.
2100  * @srq: The SRQ to post the work request on.
2101  * @recv_wr: A list of work requests to post on the receive queue.
2102  * @bad_recv_wr: On an immediate failure, this parameter will reference
2103  *   the work request that failed to be posted on the QP.
2104  */
ibv_post_srq_recv(struct ibv_srq * srq,struct ibv_recv_wr * recv_wr,struct ibv_recv_wr ** bad_recv_wr)2105 static inline int ibv_post_srq_recv(struct ibv_srq *srq,
2106 				    struct ibv_recv_wr *recv_wr,
2107 				    struct ibv_recv_wr **bad_recv_wr)
2108 {
2109 	return srq->context->ops.post_srq_recv(srq, recv_wr, bad_recv_wr);
2110 }
2111 
2112 /**
2113  * ibv_create_qp - Create a queue pair.
2114  */
2115 struct ibv_qp *ibv_create_qp(struct ibv_pd *pd,
2116 			     struct ibv_qp_init_attr *qp_init_attr);
2117 
2118 static inline struct ibv_qp *
ibv_create_qp_ex(struct ibv_context * context,struct ibv_qp_init_attr_ex * qp_init_attr_ex)2119 ibv_create_qp_ex(struct ibv_context *context, struct ibv_qp_init_attr_ex *qp_init_attr_ex)
2120 {
2121 	struct verbs_context *vctx;
2122 	uint32_t mask = qp_init_attr_ex->comp_mask;
2123 
2124 	if (mask == IBV_QP_INIT_ATTR_PD)
2125 		return ibv_create_qp(qp_init_attr_ex->pd,
2126 				     (struct ibv_qp_init_attr *)qp_init_attr_ex);
2127 
2128 	vctx = verbs_get_ctx_op(context, create_qp_ex);
2129 	if (!vctx) {
2130 		errno = ENOSYS;
2131 		return NULL;
2132 	}
2133 	return vctx->create_qp_ex(context, qp_init_attr_ex);
2134 }
2135 
2136 /**
2137  * ibv_query_rt_values_ex - Get current real time @values of a device.
2138  * @values - in/out - defines the attributes we need to query/queried.
2139  * (Or's bits of enum ibv_values_mask on values->comp_mask field)
2140  */
2141 static inline int
ibv_query_rt_values_ex(struct ibv_context * context,struct ibv_values_ex * values)2142 ibv_query_rt_values_ex(struct ibv_context *context,
2143 		       struct ibv_values_ex *values)
2144 {
2145 	struct verbs_context *vctx;
2146 
2147 	vctx = verbs_get_ctx_op(context, query_rt_values);
2148 	if (!vctx)
2149 		return ENOSYS;
2150 
2151 	if (values->comp_mask & ~(IBV_VALUES_MASK_RESERVED - 1))
2152 		return EINVAL;
2153 
2154 	return vctx->query_rt_values(context, values);
2155 }
2156 
2157 /**
2158  * ibv_query_device_ex - Get extended device properties
2159  */
2160 static inline int
ibv_query_device_ex(struct ibv_context * context,const struct ibv_query_device_ex_input * input,struct ibv_device_attr_ex * attr)2161 ibv_query_device_ex(struct ibv_context *context,
2162 		    const struct ibv_query_device_ex_input *input,
2163 		    struct ibv_device_attr_ex *attr)
2164 {
2165 	struct verbs_context *vctx;
2166 	int ret;
2167 
2168 	vctx = verbs_get_ctx_op(context, query_device_ex);
2169 	if (!vctx)
2170 		goto legacy;
2171 
2172 	ret = vctx->query_device_ex(context, input, attr, sizeof(*attr));
2173 	if (ret == ENOSYS)
2174 		goto legacy;
2175 
2176 	return ret;
2177 
2178 legacy:
2179 	memset(attr, 0, sizeof(*attr));
2180 	ret = ibv_query_device(context, &attr->orig_attr);
2181 
2182 	return ret;
2183 }
2184 
2185 /**
2186  * ibv_open_qp - Open a shareable queue pair.
2187  */
2188 static inline struct ibv_qp *
ibv_open_qp(struct ibv_context * context,struct ibv_qp_open_attr * qp_open_attr)2189 ibv_open_qp(struct ibv_context *context, struct ibv_qp_open_attr *qp_open_attr)
2190 {
2191 	struct verbs_context *vctx = verbs_get_ctx_op(context, open_qp);
2192 	if (!vctx) {
2193 		errno = ENOSYS;
2194 		return NULL;
2195 	}
2196 	return vctx->open_qp(context, qp_open_attr);
2197 }
2198 
2199 /**
2200  * ibv_modify_qp - Modify a queue pair.
2201  */
2202 int ibv_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
2203 		  int attr_mask);
2204 
2205 /**
2206  * ibv_query_qp - Returns the attribute list and current values for the
2207  *   specified QP.
2208  * @qp: The QP to query.
2209  * @attr: The attributes of the specified QP.
2210  * @attr_mask: A bit-mask used to select specific attributes to query.
2211  * @init_attr: Additional attributes of the selected QP.
2212  *
2213  * The qp_attr_mask may be used to limit the query to gathering only the
2214  * selected attributes.
2215  */
2216 int ibv_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
2217 		 int attr_mask,
2218 		 struct ibv_qp_init_attr *init_attr);
2219 
2220 /**
2221  * ibv_destroy_qp - Destroy a queue pair.
2222  */
2223 int ibv_destroy_qp(struct ibv_qp *qp);
2224 
2225 /*
2226  * ibv_create_wq - Creates a WQ associated with the specified protection
2227  * domain.
2228  * @context: ibv_context.
2229  * @wq_init_attr: A list of initial attributes required to create the
2230  * WQ. If WQ creation succeeds, then the attributes are updated to
2231  * the actual capabilities of the created WQ.
2232  *
2233  * wq_init_attr->max_wr and wq_init_attr->max_sge determine
2234  * the requested size of the WQ, and set to the actual values allocated
2235  * on return.
2236  * If ibv_create_wq() succeeds, then max_wr and max_sge will always be
2237  * at least as large as the requested values.
2238  *
2239  * Return Value
2240  * ibv_create_wq() returns a pointer to the created WQ, or NULL if the request
2241  * fails.
2242  */
ibv_create_wq(struct ibv_context * context,struct ibv_wq_init_attr * wq_init_attr)2243 static inline struct ibv_wq *ibv_create_wq(struct ibv_context *context,
2244 					   struct ibv_wq_init_attr *wq_init_attr)
2245 {
2246 	struct verbs_context *vctx = verbs_get_ctx_op(context, create_wq);
2247 	struct ibv_wq *wq;
2248 
2249 	if (!vctx) {
2250 		errno = ENOSYS;
2251 		return NULL;
2252 	}
2253 
2254 	wq = vctx->create_wq(context, wq_init_attr);
2255 	if (wq)
2256 		wq->events_completed = 0;
2257 
2258 	return wq;
2259 }
2260 
2261 /*
2262  * ibv_modify_wq - Modifies the attributes for the specified WQ.
2263  * @wq: The WQ to modify.
2264  * @wq_attr: On input, specifies the WQ attributes to modify.
2265  *    wq_attr->attr_mask: A bit-mask used to specify which attributes of the WQ
2266  *    are being modified.
2267  * On output, the current values of selected WQ attributes are returned.
2268  *
2269  * Return Value
2270  * ibv_modify_wq() returns 0 on success, or the value of errno
2271  * on failure (which indicates the failure reason).
2272  *
2273 */
ibv_modify_wq(struct ibv_wq * wq,struct ibv_wq_attr * wq_attr)2274 static inline int ibv_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *wq_attr)
2275 {
2276 	struct verbs_context *vctx = verbs_get_ctx_op(wq->context, modify_wq);
2277 
2278 	if (!vctx)
2279 		return ENOSYS;
2280 
2281 	return vctx->modify_wq(wq, wq_attr);
2282 }
2283 
2284 /*
2285  * ibv_destroy_wq - Destroys the specified WQ.
2286  * @ibv_wq: The WQ to destroy.
2287  * Return Value
2288  * ibv_destroy_wq() returns 0 on success, or the value of errno
2289  * on failure (which indicates the failure reason).
2290 */
ibv_destroy_wq(struct ibv_wq * wq)2291 static inline int ibv_destroy_wq(struct ibv_wq *wq)
2292 {
2293 	struct verbs_context *vctx;
2294 
2295 	vctx = verbs_get_ctx_op(wq->context, destroy_wq);
2296 	if (!vctx)
2297 		return ENOSYS;
2298 
2299 	return vctx->destroy_wq(wq);
2300 }
2301 
2302 /*
2303  * ibv_create_rwq_ind_table - Creates a receive work queue Indirection Table
2304  * @context: ibv_context.
2305  * @init_attr: A list of initial attributes required to create the Indirection Table.
2306  * Return Value
2307  * ibv_create_rwq_ind_table returns a pointer to the created
2308  * Indirection Table, or NULL if the request fails.
2309  */
ibv_create_rwq_ind_table(struct ibv_context * context,struct ibv_rwq_ind_table_init_attr * init_attr)2310 static inline struct ibv_rwq_ind_table *ibv_create_rwq_ind_table(struct ibv_context *context,
2311 								 struct ibv_rwq_ind_table_init_attr *init_attr)
2312 {
2313 	struct verbs_context *vctx;
2314 
2315 	vctx = verbs_get_ctx_op(context, create_rwq_ind_table);
2316 	if (!vctx) {
2317 		errno = ENOSYS;
2318 		return NULL;
2319 	}
2320 
2321 	return vctx->create_rwq_ind_table(context, init_attr);
2322 }
2323 
2324 /*
2325  * ibv_destroy_rwq_ind_table - Destroys the specified Indirection Table.
2326  * @rwq_ind_table: The Indirection Table to destroy.
2327  * Return Value
2328  * ibv_destroy_rwq_ind_table() returns 0 on success, or the value of errno
2329  * on failure (which indicates the failure reason).
2330 */
ibv_destroy_rwq_ind_table(struct ibv_rwq_ind_table * rwq_ind_table)2331 static inline int ibv_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table)
2332 {
2333 	struct verbs_context *vctx;
2334 
2335 	vctx = verbs_get_ctx_op(rwq_ind_table->context, destroy_rwq_ind_table);
2336 	if (!vctx)
2337 		return ENOSYS;
2338 
2339 	return vctx->destroy_rwq_ind_table(rwq_ind_table);
2340 }
2341 
2342 /**
2343  * ibv_post_send - Post a list of work requests to a send queue.
2344  *
2345  * If IBV_SEND_INLINE flag is set, the data buffers can be reused
2346  * immediately after the call returns.
2347  */
ibv_post_send(struct ibv_qp * qp,struct ibv_send_wr * wr,struct ibv_send_wr ** bad_wr)2348 static inline int ibv_post_send(struct ibv_qp *qp, struct ibv_send_wr *wr,
2349 				struct ibv_send_wr **bad_wr)
2350 {
2351 	return qp->context->ops.post_send(qp, wr, bad_wr);
2352 }
2353 
2354 /**
2355  * ibv_post_recv - Post a list of work requests to a receive queue.
2356  */
ibv_post_recv(struct ibv_qp * qp,struct ibv_recv_wr * wr,struct ibv_recv_wr ** bad_wr)2357 static inline int ibv_post_recv(struct ibv_qp *qp, struct ibv_recv_wr *wr,
2358 				struct ibv_recv_wr **bad_wr)
2359 {
2360 	return qp->context->ops.post_recv(qp, wr, bad_wr);
2361 }
2362 
2363 /**
2364  * ibv_create_ah - Create an address handle.
2365  */
2366 struct ibv_ah *ibv_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr);
2367 
2368 /**
2369  * ibv_init_ah_from_wc - Initializes address handle attributes from a
2370  *   work completion.
2371  * @context: Device context on which the received message arrived.
2372  * @port_num: Port on which the received message arrived.
2373  * @wc: Work completion associated with the received message.
2374  * @grh: References the received global route header.  This parameter is
2375  *   ignored unless the work completion indicates that the GRH is valid.
2376  * @ah_attr: Returned attributes that can be used when creating an address
2377  *   handle for replying to the message.
2378  */
2379 int ibv_init_ah_from_wc(struct ibv_context *context, uint8_t port_num,
2380 			struct ibv_wc *wc, struct ibv_grh *grh,
2381 			struct ibv_ah_attr *ah_attr);
2382 
2383 /**
2384  * ibv_create_ah_from_wc - Creates an address handle associated with the
2385  *   sender of the specified work completion.
2386  * @pd: The protection domain associated with the address handle.
2387  * @wc: Work completion information associated with a received message.
2388  * @grh: References the received global route header.  This parameter is
2389  *   ignored unless the work completion indicates that the GRH is valid.
2390  * @port_num: The outbound port number to associate with the address.
2391  *
2392  * The address handle is used to reference a local or global destination
2393  * in all UD QP post sends.
2394  */
2395 struct ibv_ah *ibv_create_ah_from_wc(struct ibv_pd *pd, struct ibv_wc *wc,
2396 				     struct ibv_grh *grh, uint8_t port_num);
2397 
2398 /**
2399  * ibv_destroy_ah - Destroy an address handle.
2400  */
2401 int ibv_destroy_ah(struct ibv_ah *ah);
2402 
2403 /**
2404  * ibv_attach_mcast - Attaches the specified QP to a multicast group.
2405  * @qp: QP to attach to the multicast group.  The QP must be a UD QP.
2406  * @gid: Multicast group GID.
2407  * @lid: Multicast group LID in host byte order.
2408  *
2409  * In order to route multicast packets correctly, subnet
2410  * administration must have created the multicast group and configured
2411  * the fabric appropriately.  The port associated with the specified
2412  * QP must also be a member of the multicast group.
2413  */
2414 int ibv_attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid);
2415 
2416 /**
2417  * ibv_detach_mcast - Detaches the specified QP from a multicast group.
2418  * @qp: QP to detach from the multicast group.
2419  * @gid: Multicast group GID.
2420  * @lid: Multicast group LID in host byte order.
2421  */
2422 int ibv_detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid);
2423 
2424 /**
2425  * ibv_fork_init - Prepare data structures so that fork() may be used
2426  * safely.  If this function is not called or returns a non-zero
2427  * status, then libibverbs data structures are not fork()-safe and the
2428  * effect of an application calling fork() is undefined.
2429  */
2430 int ibv_fork_init(void);
2431 
2432 /**
2433  * ibv_node_type_str - Return string describing node_type enum value
2434  */
2435 const char *ibv_node_type_str(enum ibv_node_type node_type);
2436 
2437 /**
2438  * ibv_port_state_str - Return string describing port_state enum value
2439  */
2440 const char *ibv_port_state_str(enum ibv_port_state port_state);
2441 
2442 /**
2443  * ibv_event_type_str - Return string describing event_type enum value
2444  */
2445 const char *ibv_event_type_str(enum ibv_event_type event);
2446 
2447 #define ETHERNET_LL_SIZE 6
2448 int ibv_resolve_eth_l2_from_gid(struct ibv_context *context,
2449 				struct ibv_ah_attr *attr,
2450 				uint8_t eth_mac[ETHERNET_LL_SIZE],
2451 				uint16_t *vid);
2452 
ibv_is_qpt_supported(uint32_t caps,enum ibv_qp_type qpt)2453 static inline int ibv_is_qpt_supported(uint32_t caps, enum ibv_qp_type qpt)
2454 {
2455 	return !!(caps & (1 << qpt));
2456 }
2457 
2458 END_C_DECLS
2459 
2460 #  undef __attribute_const
2461 
2462 
2463 #endif /* INFINIBAND_VERBS_H */
2464