xref: /linux/include/rdma/ib_verbs.h (revision 13abf8130139c2ccd4962a7e5a8902be5e6cb5a7)
1 /*
2  * Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
3  * Copyright (c) 2004 Infinicon Corporation.  All rights reserved.
4  * Copyright (c) 2004 Intel Corporation.  All rights reserved.
5  * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
6  * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
7  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
8  * Copyright (c) 2005 Cisco Systems.  All rights reserved.
9  *
10  * This software is available to you under a choice of one of two
11  * licenses.  You may choose to be licensed under the terms of the GNU
12  * General Public License (GPL) Version 2, available from the file
13  * COPYING in the main directory of this source tree, or the
14  * OpenIB.org BSD license below:
15  *
16  *     Redistribution and use in source and binary forms, with or
17  *     without modification, are permitted provided that the following
18  *     conditions are met:
19  *
20  *      - Redistributions of source code must retain the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer.
23  *
24  *      - Redistributions in binary form must reproduce the above
25  *        copyright notice, this list of conditions and the following
26  *        disclaimer in the documentation and/or other materials
27  *        provided with the distribution.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36  * SOFTWARE.
37  *
38  * $Id: ib_verbs.h 1349 2004-12-16 21:09:43Z roland $
39  */
40 
41 #if !defined(IB_VERBS_H)
42 #define IB_VERBS_H
43 
44 #include <linux/types.h>
45 #include <linux/device.h>
46 
47 #include <asm/atomic.h>
48 #include <asm/scatterlist.h>
49 #include <asm/uaccess.h>
50 
51 union ib_gid {
52 	u8	raw[16];
53 	struct {
54 		__be64	subnet_prefix;
55 		__be64	interface_id;
56 	} global;
57 };
58 
59 enum ib_node_type {
60 	IB_NODE_CA 	= 1,
61 	IB_NODE_SWITCH,
62 	IB_NODE_ROUTER
63 };
64 
65 enum ib_device_cap_flags {
66 	IB_DEVICE_RESIZE_MAX_WR		= 1,
67 	IB_DEVICE_BAD_PKEY_CNTR		= (1<<1),
68 	IB_DEVICE_BAD_QKEY_CNTR		= (1<<2),
69 	IB_DEVICE_RAW_MULTI		= (1<<3),
70 	IB_DEVICE_AUTO_PATH_MIG		= (1<<4),
71 	IB_DEVICE_CHANGE_PHY_PORT	= (1<<5),
72 	IB_DEVICE_UD_AV_PORT_ENFORCE	= (1<<6),
73 	IB_DEVICE_CURR_QP_STATE_MOD	= (1<<7),
74 	IB_DEVICE_SHUTDOWN_PORT		= (1<<8),
75 	IB_DEVICE_INIT_TYPE		= (1<<9),
76 	IB_DEVICE_PORT_ACTIVE_EVENT	= (1<<10),
77 	IB_DEVICE_SYS_IMAGE_GUID	= (1<<11),
78 	IB_DEVICE_RC_RNR_NAK_GEN	= (1<<12),
79 	IB_DEVICE_SRQ_RESIZE		= (1<<13),
80 	IB_DEVICE_N_NOTIFY_CQ		= (1<<14),
81 };
82 
83 enum ib_atomic_cap {
84 	IB_ATOMIC_NONE,
85 	IB_ATOMIC_HCA,
86 	IB_ATOMIC_GLOB
87 };
88 
89 struct ib_device_attr {
90 	u64			fw_ver;
91 	__be64			node_guid;
92 	__be64			sys_image_guid;
93 	u64			max_mr_size;
94 	u64			page_size_cap;
95 	u32			vendor_id;
96 	u32			vendor_part_id;
97 	u32			hw_ver;
98 	int			max_qp;
99 	int			max_qp_wr;
100 	int			device_cap_flags;
101 	int			max_sge;
102 	int			max_sge_rd;
103 	int			max_cq;
104 	int			max_cqe;
105 	int			max_mr;
106 	int			max_pd;
107 	int			max_qp_rd_atom;
108 	int			max_ee_rd_atom;
109 	int			max_res_rd_atom;
110 	int			max_qp_init_rd_atom;
111 	int			max_ee_init_rd_atom;
112 	enum ib_atomic_cap	atomic_cap;
113 	int			max_ee;
114 	int			max_rdd;
115 	int			max_mw;
116 	int			max_raw_ipv6_qp;
117 	int			max_raw_ethy_qp;
118 	int			max_mcast_grp;
119 	int			max_mcast_qp_attach;
120 	int			max_total_mcast_qp_attach;
121 	int			max_ah;
122 	int			max_fmr;
123 	int			max_map_per_fmr;
124 	int			max_srq;
125 	int			max_srq_wr;
126 	int			max_srq_sge;
127 	u16			max_pkeys;
128 	u8			local_ca_ack_delay;
129 };
130 
131 enum ib_mtu {
132 	IB_MTU_256  = 1,
133 	IB_MTU_512  = 2,
134 	IB_MTU_1024 = 3,
135 	IB_MTU_2048 = 4,
136 	IB_MTU_4096 = 5
137 };
138 
139 static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
140 {
141 	switch (mtu) {
142 	case IB_MTU_256:  return  256;
143 	case IB_MTU_512:  return  512;
144 	case IB_MTU_1024: return 1024;
145 	case IB_MTU_2048: return 2048;
146 	case IB_MTU_4096: return 4096;
147 	default: 	  return -1;
148 	}
149 }
150 
151 enum ib_port_state {
152 	IB_PORT_NOP		= 0,
153 	IB_PORT_DOWN		= 1,
154 	IB_PORT_INIT		= 2,
155 	IB_PORT_ARMED		= 3,
156 	IB_PORT_ACTIVE		= 4,
157 	IB_PORT_ACTIVE_DEFER	= 5
158 };
159 
160 enum ib_port_cap_flags {
161 	IB_PORT_SM				= 1 <<  1,
162 	IB_PORT_NOTICE_SUP			= 1 <<  2,
163 	IB_PORT_TRAP_SUP			= 1 <<  3,
164 	IB_PORT_OPT_IPD_SUP                     = 1 <<  4,
165 	IB_PORT_AUTO_MIGR_SUP			= 1 <<  5,
166 	IB_PORT_SL_MAP_SUP			= 1 <<  6,
167 	IB_PORT_MKEY_NVRAM			= 1 <<  7,
168 	IB_PORT_PKEY_NVRAM			= 1 <<  8,
169 	IB_PORT_LED_INFO_SUP			= 1 <<  9,
170 	IB_PORT_SM_DISABLED			= 1 << 10,
171 	IB_PORT_SYS_IMAGE_GUID_SUP		= 1 << 11,
172 	IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP	= 1 << 12,
173 	IB_PORT_CM_SUP				= 1 << 16,
174 	IB_PORT_SNMP_TUNNEL_SUP			= 1 << 17,
175 	IB_PORT_REINIT_SUP			= 1 << 18,
176 	IB_PORT_DEVICE_MGMT_SUP			= 1 << 19,
177 	IB_PORT_VENDOR_CLASS_SUP		= 1 << 20,
178 	IB_PORT_DR_NOTICE_SUP			= 1 << 21,
179 	IB_PORT_CAP_MASK_NOTICE_SUP		= 1 << 22,
180 	IB_PORT_BOOT_MGMT_SUP			= 1 << 23,
181 	IB_PORT_LINK_LATENCY_SUP		= 1 << 24,
182 	IB_PORT_CLIENT_REG_SUP			= 1 << 25
183 };
184 
185 enum ib_port_width {
186 	IB_WIDTH_1X	= 1,
187 	IB_WIDTH_4X	= 2,
188 	IB_WIDTH_8X	= 4,
189 	IB_WIDTH_12X	= 8
190 };
191 
192 static inline int ib_width_enum_to_int(enum ib_port_width width)
193 {
194 	switch (width) {
195 	case IB_WIDTH_1X:  return  1;
196 	case IB_WIDTH_4X:  return  4;
197 	case IB_WIDTH_8X:  return  8;
198 	case IB_WIDTH_12X: return 12;
199 	default: 	  return -1;
200 	}
201 }
202 
203 struct ib_port_attr {
204 	enum ib_port_state	state;
205 	enum ib_mtu		max_mtu;
206 	enum ib_mtu		active_mtu;
207 	int			gid_tbl_len;
208 	u32			port_cap_flags;
209 	u32			max_msg_sz;
210 	u32			bad_pkey_cntr;
211 	u32			qkey_viol_cntr;
212 	u16			pkey_tbl_len;
213 	u16			lid;
214 	u16			sm_lid;
215 	u8			lmc;
216 	u8			max_vl_num;
217 	u8			sm_sl;
218 	u8			subnet_timeout;
219 	u8			init_type_reply;
220 	u8			active_width;
221 	u8			active_speed;
222 	u8                      phys_state;
223 };
224 
225 enum ib_device_modify_flags {
226 	IB_DEVICE_MODIFY_SYS_IMAGE_GUID	= 1
227 };
228 
229 struct ib_device_modify {
230 	u64	sys_image_guid;
231 };
232 
233 enum ib_port_modify_flags {
234 	IB_PORT_SHUTDOWN		= 1,
235 	IB_PORT_INIT_TYPE		= (1<<2),
236 	IB_PORT_RESET_QKEY_CNTR		= (1<<3)
237 };
238 
239 struct ib_port_modify {
240 	u32	set_port_cap_mask;
241 	u32	clr_port_cap_mask;
242 	u8	init_type;
243 };
244 
245 enum ib_event_type {
246 	IB_EVENT_CQ_ERR,
247 	IB_EVENT_QP_FATAL,
248 	IB_EVENT_QP_REQ_ERR,
249 	IB_EVENT_QP_ACCESS_ERR,
250 	IB_EVENT_COMM_EST,
251 	IB_EVENT_SQ_DRAINED,
252 	IB_EVENT_PATH_MIG,
253 	IB_EVENT_PATH_MIG_ERR,
254 	IB_EVENT_DEVICE_FATAL,
255 	IB_EVENT_PORT_ACTIVE,
256 	IB_EVENT_PORT_ERR,
257 	IB_EVENT_LID_CHANGE,
258 	IB_EVENT_PKEY_CHANGE,
259 	IB_EVENT_SM_CHANGE,
260 	IB_EVENT_SRQ_ERR,
261 	IB_EVENT_SRQ_LIMIT_REACHED,
262 	IB_EVENT_QP_LAST_WQE_REACHED
263 };
264 
265 struct ib_event {
266 	struct ib_device	*device;
267 	union {
268 		struct ib_cq	*cq;
269 		struct ib_qp	*qp;
270 		struct ib_srq	*srq;
271 		u8		port_num;
272 	} element;
273 	enum ib_event_type	event;
274 };
275 
276 struct ib_event_handler {
277 	struct ib_device *device;
278 	void            (*handler)(struct ib_event_handler *, struct ib_event *);
279 	struct list_head  list;
280 };
281 
282 #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler)		\
283 	do {							\
284 		(_ptr)->device  = _device;			\
285 		(_ptr)->handler = _handler;			\
286 		INIT_LIST_HEAD(&(_ptr)->list);			\
287 	} while (0)
288 
289 struct ib_global_route {
290 	union ib_gid	dgid;
291 	u32		flow_label;
292 	u8		sgid_index;
293 	u8		hop_limit;
294 	u8		traffic_class;
295 };
296 
297 struct ib_grh {
298 	__be32		version_tclass_flow;
299 	__be16		paylen;
300 	u8		next_hdr;
301 	u8		hop_limit;
302 	union ib_gid	sgid;
303 	union ib_gid	dgid;
304 };
305 
306 enum {
307 	IB_MULTICAST_QPN = 0xffffff
308 };
309 
310 #define IB_LID_PERMISSIVE	__constant_htons(0xFFFF)
311 
312 enum ib_ah_flags {
313 	IB_AH_GRH	= 1
314 };
315 
316 struct ib_ah_attr {
317 	struct ib_global_route	grh;
318 	u16			dlid;
319 	u8			sl;
320 	u8			src_path_bits;
321 	u8			static_rate;
322 	u8			ah_flags;
323 	u8			port_num;
324 };
325 
326 enum ib_wc_status {
327 	IB_WC_SUCCESS,
328 	IB_WC_LOC_LEN_ERR,
329 	IB_WC_LOC_QP_OP_ERR,
330 	IB_WC_LOC_EEC_OP_ERR,
331 	IB_WC_LOC_PROT_ERR,
332 	IB_WC_WR_FLUSH_ERR,
333 	IB_WC_MW_BIND_ERR,
334 	IB_WC_BAD_RESP_ERR,
335 	IB_WC_LOC_ACCESS_ERR,
336 	IB_WC_REM_INV_REQ_ERR,
337 	IB_WC_REM_ACCESS_ERR,
338 	IB_WC_REM_OP_ERR,
339 	IB_WC_RETRY_EXC_ERR,
340 	IB_WC_RNR_RETRY_EXC_ERR,
341 	IB_WC_LOC_RDD_VIOL_ERR,
342 	IB_WC_REM_INV_RD_REQ_ERR,
343 	IB_WC_REM_ABORT_ERR,
344 	IB_WC_INV_EECN_ERR,
345 	IB_WC_INV_EEC_STATE_ERR,
346 	IB_WC_FATAL_ERR,
347 	IB_WC_RESP_TIMEOUT_ERR,
348 	IB_WC_GENERAL_ERR
349 };
350 
351 enum ib_wc_opcode {
352 	IB_WC_SEND,
353 	IB_WC_RDMA_WRITE,
354 	IB_WC_RDMA_READ,
355 	IB_WC_COMP_SWAP,
356 	IB_WC_FETCH_ADD,
357 	IB_WC_BIND_MW,
358 /*
359  * Set value of IB_WC_RECV so consumers can test if a completion is a
360  * receive by testing (opcode & IB_WC_RECV).
361  */
362 	IB_WC_RECV			= 1 << 7,
363 	IB_WC_RECV_RDMA_WITH_IMM
364 };
365 
366 enum ib_wc_flags {
367 	IB_WC_GRH		= 1,
368 	IB_WC_WITH_IMM		= (1<<1)
369 };
370 
371 struct ib_wc {
372 	u64			wr_id;
373 	enum ib_wc_status	status;
374 	enum ib_wc_opcode	opcode;
375 	u32			vendor_err;
376 	u32			byte_len;
377 	__be32			imm_data;
378 	u32			qp_num;
379 	u32			src_qp;
380 	int			wc_flags;
381 	u16			pkey_index;
382 	u16			slid;
383 	u8			sl;
384 	u8			dlid_path_bits;
385 	u8			port_num;	/* valid only for DR SMPs on switches */
386 };
387 
388 enum ib_cq_notify {
389 	IB_CQ_SOLICITED,
390 	IB_CQ_NEXT_COMP
391 };
392 
393 enum ib_srq_attr_mask {
394 	IB_SRQ_MAX_WR	= 1 << 0,
395 	IB_SRQ_LIMIT	= 1 << 1,
396 };
397 
398 struct ib_srq_attr {
399 	u32	max_wr;
400 	u32	max_sge;
401 	u32	srq_limit;
402 };
403 
404 struct ib_srq_init_attr {
405 	void		      (*event_handler)(struct ib_event *, void *);
406 	void		       *srq_context;
407 	struct ib_srq_attr	attr;
408 };
409 
410 struct ib_qp_cap {
411 	u32	max_send_wr;
412 	u32	max_recv_wr;
413 	u32	max_send_sge;
414 	u32	max_recv_sge;
415 	u32	max_inline_data;
416 };
417 
418 enum ib_sig_type {
419 	IB_SIGNAL_ALL_WR,
420 	IB_SIGNAL_REQ_WR
421 };
422 
423 enum ib_qp_type {
424 	/*
425 	 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
426 	 * here (and in that order) since the MAD layer uses them as
427 	 * indices into a 2-entry table.
428 	 */
429 	IB_QPT_SMI,
430 	IB_QPT_GSI,
431 
432 	IB_QPT_RC,
433 	IB_QPT_UC,
434 	IB_QPT_UD,
435 	IB_QPT_RAW_IPV6,
436 	IB_QPT_RAW_ETY
437 };
438 
439 struct ib_qp_init_attr {
440 	void                  (*event_handler)(struct ib_event *, void *);
441 	void		       *qp_context;
442 	struct ib_cq	       *send_cq;
443 	struct ib_cq	       *recv_cq;
444 	struct ib_srq	       *srq;
445 	struct ib_qp_cap	cap;
446 	enum ib_sig_type	sq_sig_type;
447 	enum ib_qp_type		qp_type;
448 	u8			port_num; /* special QP types only */
449 };
450 
451 enum ib_rnr_timeout {
452 	IB_RNR_TIMER_655_36 =  0,
453 	IB_RNR_TIMER_000_01 =  1,
454 	IB_RNR_TIMER_000_02 =  2,
455 	IB_RNR_TIMER_000_03 =  3,
456 	IB_RNR_TIMER_000_04 =  4,
457 	IB_RNR_TIMER_000_06 =  5,
458 	IB_RNR_TIMER_000_08 =  6,
459 	IB_RNR_TIMER_000_12 =  7,
460 	IB_RNR_TIMER_000_16 =  8,
461 	IB_RNR_TIMER_000_24 =  9,
462 	IB_RNR_TIMER_000_32 = 10,
463 	IB_RNR_TIMER_000_48 = 11,
464 	IB_RNR_TIMER_000_64 = 12,
465 	IB_RNR_TIMER_000_96 = 13,
466 	IB_RNR_TIMER_001_28 = 14,
467 	IB_RNR_TIMER_001_92 = 15,
468 	IB_RNR_TIMER_002_56 = 16,
469 	IB_RNR_TIMER_003_84 = 17,
470 	IB_RNR_TIMER_005_12 = 18,
471 	IB_RNR_TIMER_007_68 = 19,
472 	IB_RNR_TIMER_010_24 = 20,
473 	IB_RNR_TIMER_015_36 = 21,
474 	IB_RNR_TIMER_020_48 = 22,
475 	IB_RNR_TIMER_030_72 = 23,
476 	IB_RNR_TIMER_040_96 = 24,
477 	IB_RNR_TIMER_061_44 = 25,
478 	IB_RNR_TIMER_081_92 = 26,
479 	IB_RNR_TIMER_122_88 = 27,
480 	IB_RNR_TIMER_163_84 = 28,
481 	IB_RNR_TIMER_245_76 = 29,
482 	IB_RNR_TIMER_327_68 = 30,
483 	IB_RNR_TIMER_491_52 = 31
484 };
485 
486 enum ib_qp_attr_mask {
487 	IB_QP_STATE			= 1,
488 	IB_QP_CUR_STATE			= (1<<1),
489 	IB_QP_EN_SQD_ASYNC_NOTIFY	= (1<<2),
490 	IB_QP_ACCESS_FLAGS		= (1<<3),
491 	IB_QP_PKEY_INDEX		= (1<<4),
492 	IB_QP_PORT			= (1<<5),
493 	IB_QP_QKEY			= (1<<6),
494 	IB_QP_AV			= (1<<7),
495 	IB_QP_PATH_MTU			= (1<<8),
496 	IB_QP_TIMEOUT			= (1<<9),
497 	IB_QP_RETRY_CNT			= (1<<10),
498 	IB_QP_RNR_RETRY			= (1<<11),
499 	IB_QP_RQ_PSN			= (1<<12),
500 	IB_QP_MAX_QP_RD_ATOMIC		= (1<<13),
501 	IB_QP_ALT_PATH			= (1<<14),
502 	IB_QP_MIN_RNR_TIMER		= (1<<15),
503 	IB_QP_SQ_PSN			= (1<<16),
504 	IB_QP_MAX_DEST_RD_ATOMIC	= (1<<17),
505 	IB_QP_PATH_MIG_STATE		= (1<<18),
506 	IB_QP_CAP			= (1<<19),
507 	IB_QP_DEST_QPN			= (1<<20)
508 };
509 
510 enum ib_qp_state {
511 	IB_QPS_RESET,
512 	IB_QPS_INIT,
513 	IB_QPS_RTR,
514 	IB_QPS_RTS,
515 	IB_QPS_SQD,
516 	IB_QPS_SQE,
517 	IB_QPS_ERR
518 };
519 
520 enum ib_mig_state {
521 	IB_MIG_MIGRATED,
522 	IB_MIG_REARM,
523 	IB_MIG_ARMED
524 };
525 
526 struct ib_qp_attr {
527 	enum ib_qp_state	qp_state;
528 	enum ib_qp_state	cur_qp_state;
529 	enum ib_mtu		path_mtu;
530 	enum ib_mig_state	path_mig_state;
531 	u32			qkey;
532 	u32			rq_psn;
533 	u32			sq_psn;
534 	u32			dest_qp_num;
535 	int			qp_access_flags;
536 	struct ib_qp_cap	cap;
537 	struct ib_ah_attr	ah_attr;
538 	struct ib_ah_attr	alt_ah_attr;
539 	u16			pkey_index;
540 	u16			alt_pkey_index;
541 	u8			en_sqd_async_notify;
542 	u8			sq_draining;
543 	u8			max_rd_atomic;
544 	u8			max_dest_rd_atomic;
545 	u8			min_rnr_timer;
546 	u8			port_num;
547 	u8			timeout;
548 	u8			retry_cnt;
549 	u8			rnr_retry;
550 	u8			alt_port_num;
551 	u8			alt_timeout;
552 };
553 
554 enum ib_wr_opcode {
555 	IB_WR_RDMA_WRITE,
556 	IB_WR_RDMA_WRITE_WITH_IMM,
557 	IB_WR_SEND,
558 	IB_WR_SEND_WITH_IMM,
559 	IB_WR_RDMA_READ,
560 	IB_WR_ATOMIC_CMP_AND_SWP,
561 	IB_WR_ATOMIC_FETCH_AND_ADD
562 };
563 
564 enum ib_send_flags {
565 	IB_SEND_FENCE		= 1,
566 	IB_SEND_SIGNALED	= (1<<1),
567 	IB_SEND_SOLICITED	= (1<<2),
568 	IB_SEND_INLINE		= (1<<3)
569 };
570 
571 struct ib_sge {
572 	u64	addr;
573 	u32	length;
574 	u32	lkey;
575 };
576 
577 struct ib_send_wr {
578 	struct ib_send_wr      *next;
579 	u64			wr_id;
580 	struct ib_sge	       *sg_list;
581 	int			num_sge;
582 	enum ib_wr_opcode	opcode;
583 	int			send_flags;
584 	__be32			imm_data;
585 	union {
586 		struct {
587 			u64	remote_addr;
588 			u32	rkey;
589 		} rdma;
590 		struct {
591 			u64	remote_addr;
592 			u64	compare_add;
593 			u64	swap;
594 			u32	rkey;
595 		} atomic;
596 		struct {
597 			struct ib_ah *ah;
598 			struct ib_mad_hdr *mad_hdr;
599 			u32	remote_qpn;
600 			u32	remote_qkey;
601 			int	timeout_ms; /* valid for MADs only */
602 			int	retries;    /* valid for MADs only */
603 			u16	pkey_index; /* valid for GSI only */
604 			u8	port_num;   /* valid for DR SMPs on switch only */
605 		} ud;
606 	} wr;
607 };
608 
609 struct ib_recv_wr {
610 	struct ib_recv_wr      *next;
611 	u64			wr_id;
612 	struct ib_sge	       *sg_list;
613 	int			num_sge;
614 };
615 
616 enum ib_access_flags {
617 	IB_ACCESS_LOCAL_WRITE	= 1,
618 	IB_ACCESS_REMOTE_WRITE	= (1<<1),
619 	IB_ACCESS_REMOTE_READ	= (1<<2),
620 	IB_ACCESS_REMOTE_ATOMIC	= (1<<3),
621 	IB_ACCESS_MW_BIND	= (1<<4)
622 };
623 
624 struct ib_phys_buf {
625 	u64      addr;
626 	u64      size;
627 };
628 
629 struct ib_mr_attr {
630 	struct ib_pd	*pd;
631 	u64		device_virt_addr;
632 	u64		size;
633 	int		mr_access_flags;
634 	u32		lkey;
635 	u32		rkey;
636 };
637 
638 enum ib_mr_rereg_flags {
639 	IB_MR_REREG_TRANS	= 1,
640 	IB_MR_REREG_PD		= (1<<1),
641 	IB_MR_REREG_ACCESS	= (1<<2)
642 };
643 
644 struct ib_mw_bind {
645 	struct ib_mr   *mr;
646 	u64		wr_id;
647 	u64		addr;
648 	u32		length;
649 	int		send_flags;
650 	int		mw_access_flags;
651 };
652 
653 struct ib_fmr_attr {
654 	int	max_pages;
655 	int	max_maps;
656 	u8	page_size;
657 };
658 
659 struct ib_ucontext {
660 	struct ib_device       *device;
661 	struct list_head	pd_list;
662 	struct list_head	mr_list;
663 	struct list_head	mw_list;
664 	struct list_head	cq_list;
665 	struct list_head	qp_list;
666 	struct list_head	srq_list;
667 	struct list_head	ah_list;
668 	spinlock_t              lock;
669 };
670 
671 struct ib_uobject {
672 	u64			user_handle;	/* handle given to us by userspace */
673 	struct ib_ucontext     *context;	/* associated user context */
674 	struct list_head	list;		/* link to context's list */
675 	u32			id;		/* index into kernel idr */
676 };
677 
678 struct ib_umem {
679 	unsigned long		user_base;
680 	unsigned long		virt_base;
681 	size_t			length;
682 	int			offset;
683 	int			page_size;
684 	int                     writable;
685 	struct list_head	chunk_list;
686 };
687 
688 struct ib_umem_chunk {
689 	struct list_head	list;
690 	int                     nents;
691 	int                     nmap;
692 	struct scatterlist      page_list[0];
693 };
694 
695 struct ib_udata {
696 	void __user *inbuf;
697 	void __user *outbuf;
698 	size_t       inlen;
699 	size_t       outlen;
700 };
701 
702 #define IB_UMEM_MAX_PAGE_CHUNK						\
703 	((PAGE_SIZE - offsetof(struct ib_umem_chunk, page_list)) /	\
704 	 ((void *) &((struct ib_umem_chunk *) 0)->page_list[1] -	\
705 	  (void *) &((struct ib_umem_chunk *) 0)->page_list[0]))
706 
707 struct ib_umem_object {
708 	struct ib_uobject	uobject;
709 	struct ib_umem		umem;
710 };
711 
712 struct ib_pd {
713 	struct ib_device       *device;
714 	struct ib_uobject      *uobject;
715 	atomic_t          	usecnt; /* count all resources */
716 };
717 
718 struct ib_ah {
719 	struct ib_device	*device;
720 	struct ib_pd		*pd;
721 	struct ib_uobject	*uobject;
722 };
723 
724 typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
725 
726 struct ib_cq {
727 	struct ib_device       *device;
728 	struct ib_uobject      *uobject;
729 	ib_comp_handler   	comp_handler;
730 	void                  (*event_handler)(struct ib_event *, void *);
731 	void *            	cq_context;
732 	int               	cqe;
733 	atomic_t          	usecnt; /* count number of work queues */
734 };
735 
736 struct ib_srq {
737 	struct ib_device       *device;
738 	struct ib_pd	       *pd;
739 	struct ib_uobject      *uobject;
740 	void		      (*event_handler)(struct ib_event *, void *);
741 	void		       *srq_context;
742 	atomic_t		usecnt;
743 };
744 
745 struct ib_qp {
746 	struct ib_device       *device;
747 	struct ib_pd	       *pd;
748 	struct ib_cq	       *send_cq;
749 	struct ib_cq	       *recv_cq;
750 	struct ib_srq	       *srq;
751 	struct ib_uobject      *uobject;
752 	void                  (*event_handler)(struct ib_event *, void *);
753 	void		       *qp_context;
754 	u32			qp_num;
755 	enum ib_qp_type		qp_type;
756 };
757 
758 struct ib_mr {
759 	struct ib_device  *device;
760 	struct ib_pd	  *pd;
761 	struct ib_uobject *uobject;
762 	u32		   lkey;
763 	u32		   rkey;
764 	atomic_t	   usecnt; /* count number of MWs */
765 };
766 
767 struct ib_mw {
768 	struct ib_device	*device;
769 	struct ib_pd		*pd;
770 	struct ib_uobject	*uobject;
771 	u32			rkey;
772 };
773 
774 struct ib_fmr {
775 	struct ib_device	*device;
776 	struct ib_pd		*pd;
777 	struct list_head	list;
778 	u32			lkey;
779 	u32			rkey;
780 };
781 
782 struct ib_mad;
783 struct ib_grh;
784 
785 enum ib_process_mad_flags {
786 	IB_MAD_IGNORE_MKEY	= 1,
787 	IB_MAD_IGNORE_BKEY	= 2,
788 	IB_MAD_IGNORE_ALL	= IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
789 };
790 
791 enum ib_mad_result {
792 	IB_MAD_RESULT_FAILURE  = 0,      /* (!SUCCESS is the important flag) */
793 	IB_MAD_RESULT_SUCCESS  = 1 << 0, /* MAD was successfully processed   */
794 	IB_MAD_RESULT_REPLY    = 1 << 1, /* Reply packet needs to be sent    */
795 	IB_MAD_RESULT_CONSUMED = 1 << 2  /* Packet consumed: stop processing */
796 };
797 
798 #define IB_DEVICE_NAME_MAX 64
799 
800 struct ib_cache {
801 	rwlock_t                lock;
802 	struct ib_event_handler event_handler;
803 	struct ib_pkey_cache  **pkey_cache;
804 	struct ib_gid_cache   **gid_cache;
805 };
806 
807 struct ib_device {
808 	struct device                *dma_device;
809 
810 	char                          name[IB_DEVICE_NAME_MAX];
811 
812 	struct list_head              event_handler_list;
813 	spinlock_t                    event_handler_lock;
814 
815 	struct list_head              core_list;
816 	struct list_head              client_data_list;
817 	spinlock_t                    client_data_lock;
818 
819 	struct ib_cache               cache;
820 
821 	u32                           flags;
822 
823 	int		           (*query_device)(struct ib_device *device,
824 						   struct ib_device_attr *device_attr);
825 	int		           (*query_port)(struct ib_device *device,
826 						 u8 port_num,
827 						 struct ib_port_attr *port_attr);
828 	int		           (*query_gid)(struct ib_device *device,
829 						u8 port_num, int index,
830 						union ib_gid *gid);
831 	int		           (*query_pkey)(struct ib_device *device,
832 						 u8 port_num, u16 index, u16 *pkey);
833 	int		           (*modify_device)(struct ib_device *device,
834 						    int device_modify_mask,
835 						    struct ib_device_modify *device_modify);
836 	int		           (*modify_port)(struct ib_device *device,
837 						  u8 port_num, int port_modify_mask,
838 						  struct ib_port_modify *port_modify);
839 	struct ib_ucontext *       (*alloc_ucontext)(struct ib_device *device,
840 						     struct ib_udata *udata);
841 	int                        (*dealloc_ucontext)(struct ib_ucontext *context);
842 	int                        (*mmap)(struct ib_ucontext *context,
843 					   struct vm_area_struct *vma);
844 	struct ib_pd *             (*alloc_pd)(struct ib_device *device,
845 					       struct ib_ucontext *context,
846 					       struct ib_udata *udata);
847 	int                        (*dealloc_pd)(struct ib_pd *pd);
848 	struct ib_ah *             (*create_ah)(struct ib_pd *pd,
849 						struct ib_ah_attr *ah_attr);
850 	int                        (*modify_ah)(struct ib_ah *ah,
851 						struct ib_ah_attr *ah_attr);
852 	int                        (*query_ah)(struct ib_ah *ah,
853 					       struct ib_ah_attr *ah_attr);
854 	int                        (*destroy_ah)(struct ib_ah *ah);
855 	struct ib_srq *            (*create_srq)(struct ib_pd *pd,
856 						 struct ib_srq_init_attr *srq_init_attr,
857 						 struct ib_udata *udata);
858 	int                        (*modify_srq)(struct ib_srq *srq,
859 						 struct ib_srq_attr *srq_attr,
860 						 enum ib_srq_attr_mask srq_attr_mask);
861 	int                        (*query_srq)(struct ib_srq *srq,
862 						struct ib_srq_attr *srq_attr);
863 	int                        (*destroy_srq)(struct ib_srq *srq);
864 	int                        (*post_srq_recv)(struct ib_srq *srq,
865 						    struct ib_recv_wr *recv_wr,
866 						    struct ib_recv_wr **bad_recv_wr);
867 	struct ib_qp *             (*create_qp)(struct ib_pd *pd,
868 						struct ib_qp_init_attr *qp_init_attr,
869 						struct ib_udata *udata);
870 	int                        (*modify_qp)(struct ib_qp *qp,
871 						struct ib_qp_attr *qp_attr,
872 						int qp_attr_mask);
873 	int                        (*query_qp)(struct ib_qp *qp,
874 					       struct ib_qp_attr *qp_attr,
875 					       int qp_attr_mask,
876 					       struct ib_qp_init_attr *qp_init_attr);
877 	int                        (*destroy_qp)(struct ib_qp *qp);
878 	int                        (*post_send)(struct ib_qp *qp,
879 						struct ib_send_wr *send_wr,
880 						struct ib_send_wr **bad_send_wr);
881 	int                        (*post_recv)(struct ib_qp *qp,
882 						struct ib_recv_wr *recv_wr,
883 						struct ib_recv_wr **bad_recv_wr);
884 	struct ib_cq *             (*create_cq)(struct ib_device *device, int cqe,
885 						struct ib_ucontext *context,
886 						struct ib_udata *udata);
887 	int                        (*destroy_cq)(struct ib_cq *cq);
888 	int                        (*resize_cq)(struct ib_cq *cq, int *cqe);
889 	int                        (*poll_cq)(struct ib_cq *cq, int num_entries,
890 					      struct ib_wc *wc);
891 	int                        (*peek_cq)(struct ib_cq *cq, int wc_cnt);
892 	int                        (*req_notify_cq)(struct ib_cq *cq,
893 						    enum ib_cq_notify cq_notify);
894 	int                        (*req_ncomp_notif)(struct ib_cq *cq,
895 						      int wc_cnt);
896 	struct ib_mr *             (*get_dma_mr)(struct ib_pd *pd,
897 						 int mr_access_flags);
898 	struct ib_mr *             (*reg_phys_mr)(struct ib_pd *pd,
899 						  struct ib_phys_buf *phys_buf_array,
900 						  int num_phys_buf,
901 						  int mr_access_flags,
902 						  u64 *iova_start);
903 	struct ib_mr *             (*reg_user_mr)(struct ib_pd *pd,
904 						  struct ib_umem *region,
905 						  int mr_access_flags,
906 						  struct ib_udata *udata);
907 	int                        (*query_mr)(struct ib_mr *mr,
908 					       struct ib_mr_attr *mr_attr);
909 	int                        (*dereg_mr)(struct ib_mr *mr);
910 	int                        (*rereg_phys_mr)(struct ib_mr *mr,
911 						    int mr_rereg_mask,
912 						    struct ib_pd *pd,
913 						    struct ib_phys_buf *phys_buf_array,
914 						    int num_phys_buf,
915 						    int mr_access_flags,
916 						    u64 *iova_start);
917 	struct ib_mw *             (*alloc_mw)(struct ib_pd *pd);
918 	int                        (*bind_mw)(struct ib_qp *qp,
919 					      struct ib_mw *mw,
920 					      struct ib_mw_bind *mw_bind);
921 	int                        (*dealloc_mw)(struct ib_mw *mw);
922 	struct ib_fmr *	           (*alloc_fmr)(struct ib_pd *pd,
923 						int mr_access_flags,
924 						struct ib_fmr_attr *fmr_attr);
925 	int		           (*map_phys_fmr)(struct ib_fmr *fmr,
926 						   u64 *page_list, int list_len,
927 						   u64 iova);
928 	int		           (*unmap_fmr)(struct list_head *fmr_list);
929 	int		           (*dealloc_fmr)(struct ib_fmr *fmr);
930 	int                        (*attach_mcast)(struct ib_qp *qp,
931 						   union ib_gid *gid,
932 						   u16 lid);
933 	int                        (*detach_mcast)(struct ib_qp *qp,
934 						   union ib_gid *gid,
935 						   u16 lid);
936 	int                        (*process_mad)(struct ib_device *device,
937 						  int process_mad_flags,
938 						  u8 port_num,
939 						  struct ib_wc *in_wc,
940 						  struct ib_grh *in_grh,
941 						  struct ib_mad *in_mad,
942 						  struct ib_mad *out_mad);
943 
944 	struct module               *owner;
945 	struct class_device          class_dev;
946 	struct kobject               ports_parent;
947 	struct list_head             port_list;
948 
949 	enum {
950 		IB_DEV_UNINITIALIZED,
951 		IB_DEV_REGISTERED,
952 		IB_DEV_UNREGISTERED
953 	}                            reg_state;
954 
955 	u8                           node_type;
956 	u8                           phys_port_cnt;
957 };
958 
959 struct ib_client {
960 	char  *name;
961 	void (*add)   (struct ib_device *);
962 	void (*remove)(struct ib_device *);
963 
964 	struct list_head list;
965 };
966 
967 struct ib_device *ib_alloc_device(size_t size);
968 void ib_dealloc_device(struct ib_device *device);
969 
970 int ib_register_device   (struct ib_device *device);
971 void ib_unregister_device(struct ib_device *device);
972 
973 int ib_register_client   (struct ib_client *client);
974 void ib_unregister_client(struct ib_client *client);
975 
976 void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
977 void  ib_set_client_data(struct ib_device *device, struct ib_client *client,
978 			 void *data);
979 
980 static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
981 {
982 	return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
983 }
984 
985 static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
986 {
987 	return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
988 }
989 
990 int ib_register_event_handler  (struct ib_event_handler *event_handler);
991 int ib_unregister_event_handler(struct ib_event_handler *event_handler);
992 void ib_dispatch_event(struct ib_event *event);
993 
994 int ib_query_device(struct ib_device *device,
995 		    struct ib_device_attr *device_attr);
996 
997 int ib_query_port(struct ib_device *device,
998 		  u8 port_num, struct ib_port_attr *port_attr);
999 
1000 int ib_query_gid(struct ib_device *device,
1001 		 u8 port_num, int index, union ib_gid *gid);
1002 
1003 int ib_query_pkey(struct ib_device *device,
1004 		  u8 port_num, u16 index, u16 *pkey);
1005 
1006 int ib_modify_device(struct ib_device *device,
1007 		     int device_modify_mask,
1008 		     struct ib_device_modify *device_modify);
1009 
1010 int ib_modify_port(struct ib_device *device,
1011 		   u8 port_num, int port_modify_mask,
1012 		   struct ib_port_modify *port_modify);
1013 
1014 /**
1015  * ib_alloc_pd - Allocates an unused protection domain.
1016  * @device: The device on which to allocate the protection domain.
1017  *
1018  * A protection domain object provides an association between QPs, shared
1019  * receive queues, address handles, memory regions, and memory windows.
1020  */
1021 struct ib_pd *ib_alloc_pd(struct ib_device *device);
1022 
1023 /**
1024  * ib_dealloc_pd - Deallocates a protection domain.
1025  * @pd: The protection domain to deallocate.
1026  */
1027 int ib_dealloc_pd(struct ib_pd *pd);
1028 
1029 /**
1030  * ib_create_ah - Creates an address handle for the given address vector.
1031  * @pd: The protection domain associated with the address handle.
1032  * @ah_attr: The attributes of the address vector.
1033  *
1034  * The address handle is used to reference a local or global destination
1035  * in all UD QP post sends.
1036  */
1037 struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1038 
1039 /**
1040  * ib_create_ah_from_wc - Creates an address handle associated with the
1041  *   sender of the specified work completion.
1042  * @pd: The protection domain associated with the address handle.
1043  * @wc: Work completion information associated with a received message.
1044  * @grh: References the received global route header.  This parameter is
1045  *   ignored unless the work completion indicates that the GRH is valid.
1046  * @port_num: The outbound port number to associate with the address.
1047  *
1048  * The address handle is used to reference a local or global destination
1049  * in all UD QP post sends.
1050  */
1051 struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1052 				   struct ib_grh *grh, u8 port_num);
1053 
1054 /**
1055  * ib_modify_ah - Modifies the address vector associated with an address
1056  *   handle.
1057  * @ah: The address handle to modify.
1058  * @ah_attr: The new address vector attributes to associate with the
1059  *   address handle.
1060  */
1061 int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1062 
1063 /**
1064  * ib_query_ah - Queries the address vector associated with an address
1065  *   handle.
1066  * @ah: The address handle to query.
1067  * @ah_attr: The address vector attributes associated with the address
1068  *   handle.
1069  */
1070 int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1071 
1072 /**
1073  * ib_destroy_ah - Destroys an address handle.
1074  * @ah: The address handle to destroy.
1075  */
1076 int ib_destroy_ah(struct ib_ah *ah);
1077 
1078 /**
1079  * ib_create_srq - Creates a SRQ associated with the specified protection
1080  *   domain.
1081  * @pd: The protection domain associated with the SRQ.
1082  * @srq_init_attr: A list of initial attributes required to create the SRQ.
1083  *
1084  * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1085  * requested size of the SRQ, and set to the actual values allocated
1086  * on return.  If ib_create_srq() succeeds, then max_wr and max_sge
1087  * will always be at least as large as the requested values.
1088  */
1089 struct ib_srq *ib_create_srq(struct ib_pd *pd,
1090 			     struct ib_srq_init_attr *srq_init_attr);
1091 
1092 /**
1093  * ib_modify_srq - Modifies the attributes for the specified SRQ.
1094  * @srq: The SRQ to modify.
1095  * @srq_attr: On input, specifies the SRQ attributes to modify.  On output,
1096  *   the current values of selected SRQ attributes are returned.
1097  * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1098  *   are being modified.
1099  *
1100  * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1101  * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1102  * the number of receives queued drops below the limit.
1103  */
1104 int ib_modify_srq(struct ib_srq *srq,
1105 		  struct ib_srq_attr *srq_attr,
1106 		  enum ib_srq_attr_mask srq_attr_mask);
1107 
1108 /**
1109  * ib_query_srq - Returns the attribute list and current values for the
1110  *   specified SRQ.
1111  * @srq: The SRQ to query.
1112  * @srq_attr: The attributes of the specified SRQ.
1113  */
1114 int ib_query_srq(struct ib_srq *srq,
1115 		 struct ib_srq_attr *srq_attr);
1116 
1117 /**
1118  * ib_destroy_srq - Destroys the specified SRQ.
1119  * @srq: The SRQ to destroy.
1120  */
1121 int ib_destroy_srq(struct ib_srq *srq);
1122 
1123 /**
1124  * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1125  * @srq: The SRQ to post the work request on.
1126  * @recv_wr: A list of work requests to post on the receive queue.
1127  * @bad_recv_wr: On an immediate failure, this parameter will reference
1128  *   the work request that failed to be posted on the QP.
1129  */
1130 static inline int ib_post_srq_recv(struct ib_srq *srq,
1131 				   struct ib_recv_wr *recv_wr,
1132 				   struct ib_recv_wr **bad_recv_wr)
1133 {
1134 	return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1135 }
1136 
1137 /**
1138  * ib_create_qp - Creates a QP associated with the specified protection
1139  *   domain.
1140  * @pd: The protection domain associated with the QP.
1141  * @qp_init_attr: A list of initial attributes required to create the QP.
1142  */
1143 struct ib_qp *ib_create_qp(struct ib_pd *pd,
1144 			   struct ib_qp_init_attr *qp_init_attr);
1145 
1146 /**
1147  * ib_modify_qp - Modifies the attributes for the specified QP and then
1148  *   transitions the QP to the given state.
1149  * @qp: The QP to modify.
1150  * @qp_attr: On input, specifies the QP attributes to modify.  On output,
1151  *   the current values of selected QP attributes are returned.
1152  * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1153  *   are being modified.
1154  */
1155 int ib_modify_qp(struct ib_qp *qp,
1156 		 struct ib_qp_attr *qp_attr,
1157 		 int qp_attr_mask);
1158 
1159 /**
1160  * ib_query_qp - Returns the attribute list and current values for the
1161  *   specified QP.
1162  * @qp: The QP to query.
1163  * @qp_attr: The attributes of the specified QP.
1164  * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1165  * @qp_init_attr: Additional attributes of the selected QP.
1166  *
1167  * The qp_attr_mask may be used to limit the query to gathering only the
1168  * selected attributes.
1169  */
1170 int ib_query_qp(struct ib_qp *qp,
1171 		struct ib_qp_attr *qp_attr,
1172 		int qp_attr_mask,
1173 		struct ib_qp_init_attr *qp_init_attr);
1174 
1175 /**
1176  * ib_destroy_qp - Destroys the specified QP.
1177  * @qp: The QP to destroy.
1178  */
1179 int ib_destroy_qp(struct ib_qp *qp);
1180 
1181 /**
1182  * ib_post_send - Posts a list of work requests to the send queue of
1183  *   the specified QP.
1184  * @qp: The QP to post the work request on.
1185  * @send_wr: A list of work requests to post on the send queue.
1186  * @bad_send_wr: On an immediate failure, this parameter will reference
1187  *   the work request that failed to be posted on the QP.
1188  */
1189 static inline int ib_post_send(struct ib_qp *qp,
1190 			       struct ib_send_wr *send_wr,
1191 			       struct ib_send_wr **bad_send_wr)
1192 {
1193 	return qp->device->post_send(qp, send_wr, bad_send_wr);
1194 }
1195 
1196 /**
1197  * ib_post_recv - Posts a list of work requests to the receive queue of
1198  *   the specified QP.
1199  * @qp: The QP to post the work request on.
1200  * @recv_wr: A list of work requests to post on the receive queue.
1201  * @bad_recv_wr: On an immediate failure, this parameter will reference
1202  *   the work request that failed to be posted on the QP.
1203  */
1204 static inline int ib_post_recv(struct ib_qp *qp,
1205 			       struct ib_recv_wr *recv_wr,
1206 			       struct ib_recv_wr **bad_recv_wr)
1207 {
1208 	return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1209 }
1210 
1211 /**
1212  * ib_create_cq - Creates a CQ on the specified device.
1213  * @device: The device on which to create the CQ.
1214  * @comp_handler: A user-specified callback that is invoked when a
1215  *   completion event occurs on the CQ.
1216  * @event_handler: A user-specified callback that is invoked when an
1217  *   asynchronous event not associated with a completion occurs on the CQ.
1218  * @cq_context: Context associated with the CQ returned to the user via
1219  *   the associated completion and event handlers.
1220  * @cqe: The minimum size of the CQ.
1221  *
1222  * Users can examine the cq structure to determine the actual CQ size.
1223  */
1224 struct ib_cq *ib_create_cq(struct ib_device *device,
1225 			   ib_comp_handler comp_handler,
1226 			   void (*event_handler)(struct ib_event *, void *),
1227 			   void *cq_context, int cqe);
1228 
1229 /**
1230  * ib_resize_cq - Modifies the capacity of the CQ.
1231  * @cq: The CQ to resize.
1232  * @cqe: The minimum size of the CQ.
1233  *
1234  * Users can examine the cq structure to determine the actual CQ size.
1235  */
1236 int ib_resize_cq(struct ib_cq *cq, int cqe);
1237 
1238 /**
1239  * ib_destroy_cq - Destroys the specified CQ.
1240  * @cq: The CQ to destroy.
1241  */
1242 int ib_destroy_cq(struct ib_cq *cq);
1243 
1244 /**
1245  * ib_poll_cq - poll a CQ for completion(s)
1246  * @cq:the CQ being polled
1247  * @num_entries:maximum number of completions to return
1248  * @wc:array of at least @num_entries &struct ib_wc where completions
1249  *   will be returned
1250  *
1251  * Poll a CQ for (possibly multiple) completions.  If the return value
1252  * is < 0, an error occurred.  If the return value is >= 0, it is the
1253  * number of completions returned.  If the return value is
1254  * non-negative and < num_entries, then the CQ was emptied.
1255  */
1256 static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1257 			     struct ib_wc *wc)
1258 {
1259 	return cq->device->poll_cq(cq, num_entries, wc);
1260 }
1261 
1262 /**
1263  * ib_peek_cq - Returns the number of unreaped completions currently
1264  *   on the specified CQ.
1265  * @cq: The CQ to peek.
1266  * @wc_cnt: A minimum number of unreaped completions to check for.
1267  *
1268  * If the number of unreaped completions is greater than or equal to wc_cnt,
1269  * this function returns wc_cnt, otherwise, it returns the actual number of
1270  * unreaped completions.
1271  */
1272 int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1273 
1274 /**
1275  * ib_req_notify_cq - Request completion notification on a CQ.
1276  * @cq: The CQ to generate an event for.
1277  * @cq_notify: If set to %IB_CQ_SOLICITED, completion notification will
1278  *   occur on the next solicited event. If set to %IB_CQ_NEXT_COMP,
1279  *   notification will occur on the next completion.
1280  */
1281 static inline int ib_req_notify_cq(struct ib_cq *cq,
1282 				   enum ib_cq_notify cq_notify)
1283 {
1284 	return cq->device->req_notify_cq(cq, cq_notify);
1285 }
1286 
1287 /**
1288  * ib_req_ncomp_notif - Request completion notification when there are
1289  *   at least the specified number of unreaped completions on the CQ.
1290  * @cq: The CQ to generate an event for.
1291  * @wc_cnt: The number of unreaped completions that should be on the
1292  *   CQ before an event is generated.
1293  */
1294 static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1295 {
1296 	return cq->device->req_ncomp_notif ?
1297 		cq->device->req_ncomp_notif(cq, wc_cnt) :
1298 		-ENOSYS;
1299 }
1300 
1301 /**
1302  * ib_get_dma_mr - Returns a memory region for system memory that is
1303  *   usable for DMA.
1304  * @pd: The protection domain associated with the memory region.
1305  * @mr_access_flags: Specifies the memory access rights.
1306  */
1307 struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1308 
1309 /**
1310  * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
1311  *   by an HCA.
1312  * @pd: The protection domain associated assigned to the registered region.
1313  * @phys_buf_array: Specifies a list of physical buffers to use in the
1314  *   memory region.
1315  * @num_phys_buf: Specifies the size of the phys_buf_array.
1316  * @mr_access_flags: Specifies the memory access rights.
1317  * @iova_start: The offset of the region's starting I/O virtual address.
1318  */
1319 struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
1320 			     struct ib_phys_buf *phys_buf_array,
1321 			     int num_phys_buf,
1322 			     int mr_access_flags,
1323 			     u64 *iova_start);
1324 
1325 /**
1326  * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
1327  *   Conceptually, this call performs the functions deregister memory region
1328  *   followed by register physical memory region.  Where possible,
1329  *   resources are reused instead of deallocated and reallocated.
1330  * @mr: The memory region to modify.
1331  * @mr_rereg_mask: A bit-mask used to indicate which of the following
1332  *   properties of the memory region are being modified.
1333  * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
1334  *   the new protection domain to associated with the memory region,
1335  *   otherwise, this parameter is ignored.
1336  * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1337  *   field specifies a list of physical buffers to use in the new
1338  *   translation, otherwise, this parameter is ignored.
1339  * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1340  *   field specifies the size of the phys_buf_array, otherwise, this
1341  *   parameter is ignored.
1342  * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
1343  *   field specifies the new memory access rights, otherwise, this
1344  *   parameter is ignored.
1345  * @iova_start: The offset of the region's starting I/O virtual address.
1346  */
1347 int ib_rereg_phys_mr(struct ib_mr *mr,
1348 		     int mr_rereg_mask,
1349 		     struct ib_pd *pd,
1350 		     struct ib_phys_buf *phys_buf_array,
1351 		     int num_phys_buf,
1352 		     int mr_access_flags,
1353 		     u64 *iova_start);
1354 
1355 /**
1356  * ib_query_mr - Retrieves information about a specific memory region.
1357  * @mr: The memory region to retrieve information about.
1358  * @mr_attr: The attributes of the specified memory region.
1359  */
1360 int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
1361 
1362 /**
1363  * ib_dereg_mr - Deregisters a memory region and removes it from the
1364  *   HCA translation table.
1365  * @mr: The memory region to deregister.
1366  */
1367 int ib_dereg_mr(struct ib_mr *mr);
1368 
1369 /**
1370  * ib_alloc_mw - Allocates a memory window.
1371  * @pd: The protection domain associated with the memory window.
1372  */
1373 struct ib_mw *ib_alloc_mw(struct ib_pd *pd);
1374 
1375 /**
1376  * ib_bind_mw - Posts a work request to the send queue of the specified
1377  *   QP, which binds the memory window to the given address range and
1378  *   remote access attributes.
1379  * @qp: QP to post the bind work request on.
1380  * @mw: The memory window to bind.
1381  * @mw_bind: Specifies information about the memory window, including
1382  *   its address range, remote access rights, and associated memory region.
1383  */
1384 static inline int ib_bind_mw(struct ib_qp *qp,
1385 			     struct ib_mw *mw,
1386 			     struct ib_mw_bind *mw_bind)
1387 {
1388 	/* XXX reference counting in corresponding MR? */
1389 	return mw->device->bind_mw ?
1390 		mw->device->bind_mw(qp, mw, mw_bind) :
1391 		-ENOSYS;
1392 }
1393 
1394 /**
1395  * ib_dealloc_mw - Deallocates a memory window.
1396  * @mw: The memory window to deallocate.
1397  */
1398 int ib_dealloc_mw(struct ib_mw *mw);
1399 
1400 /**
1401  * ib_alloc_fmr - Allocates a unmapped fast memory region.
1402  * @pd: The protection domain associated with the unmapped region.
1403  * @mr_access_flags: Specifies the memory access rights.
1404  * @fmr_attr: Attributes of the unmapped region.
1405  *
1406  * A fast memory region must be mapped before it can be used as part of
1407  * a work request.
1408  */
1409 struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
1410 			    int mr_access_flags,
1411 			    struct ib_fmr_attr *fmr_attr);
1412 
1413 /**
1414  * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
1415  * @fmr: The fast memory region to associate with the pages.
1416  * @page_list: An array of physical pages to map to the fast memory region.
1417  * @list_len: The number of pages in page_list.
1418  * @iova: The I/O virtual address to use with the mapped region.
1419  */
1420 static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
1421 				  u64 *page_list, int list_len,
1422 				  u64 iova)
1423 {
1424 	return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
1425 }
1426 
1427 /**
1428  * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
1429  * @fmr_list: A linked list of fast memory regions to unmap.
1430  */
1431 int ib_unmap_fmr(struct list_head *fmr_list);
1432 
1433 /**
1434  * ib_dealloc_fmr - Deallocates a fast memory region.
1435  * @fmr: The fast memory region to deallocate.
1436  */
1437 int ib_dealloc_fmr(struct ib_fmr *fmr);
1438 
1439 /**
1440  * ib_attach_mcast - Attaches the specified QP to a multicast group.
1441  * @qp: QP to attach to the multicast group.  The QP must be type
1442  *   IB_QPT_UD.
1443  * @gid: Multicast group GID.
1444  * @lid: Multicast group LID in host byte order.
1445  *
1446  * In order to send and receive multicast packets, subnet
1447  * administration must have created the multicast group and configured
1448  * the fabric appropriately.  The port associated with the specified
1449  * QP must also be a member of the multicast group.
1450  */
1451 int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
1452 
1453 /**
1454  * ib_detach_mcast - Detaches the specified QP from a multicast group.
1455  * @qp: QP to detach from the multicast group.
1456  * @gid: Multicast group GID.
1457  * @lid: Multicast group LID in host byte order.
1458  */
1459 int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
1460 
1461 #endif /* IB_VERBS_H */
1462