xref: /freebsd-13.1/sys/ofed/include/rdma/ib_verbs.h (revision 36b2d16b)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3  *
4  * Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
5  * Copyright (c) 2004 Infinicon Corporation.  All rights reserved.
6  * Copyright (c) 2004 Intel Corporation.  All rights reserved.
7  * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
8  * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
9  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
10  * Copyright (c) 2005, 2006, 2007 Cisco Systems.  All rights reserved.
11  *
12  * This software is available to you under a choice of one of two
13  * licenses.  You may choose to be licensed under the terms of the GNU
14  * General Public License (GPL) Version 2, available from the file
15  * COPYING in the main directory of this source tree, or the
16  * OpenIB.org BSD license below:
17  *
18  *     Redistribution and use in source and binary forms, with or
19  *     without modification, are permitted provided that the following
20  *     conditions are met:
21  *
22  *      - Redistributions of source code must retain the above
23  *        copyright notice, this list of conditions and the following
24  *        disclaimer.
25  *
26  *      - Redistributions in binary form must reproduce the above
27  *        copyright notice, this list of conditions and the following
28  *        disclaimer in the documentation and/or other materials
29  *        provided with the distribution.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
35  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
36  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
37  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38  * SOFTWARE.
39  *
40  * $FreeBSD$
41  */
42 
43 #if !defined(IB_VERBS_H)
44 #define IB_VERBS_H
45 
46 #include <linux/types.h>
47 #include <linux/device.h>
48 #include <linux/mm.h>
49 #include <linux/dma-mapping.h>
50 #include <linux/kref.h>
51 #include <linux/list.h>
52 #include <linux/rwsem.h>
53 #include <linux/scatterlist.h>
54 #include <linux/workqueue.h>
55 #include <linux/socket.h>
56 #include <linux/if_ether.h>
57 #include <net/ipv6.h>
58 #include <net/ip.h>
59 #include <linux/string.h>
60 #include <linux/slab.h>
61 #include <linux/rcupdate.h>
62 #include <linux/netdevice.h>
63 #include <netinet/ip.h>
64 
65 #include <asm/atomic.h>
66 #include <asm/uaccess.h>
67 
68 struct ifla_vf_info;
69 struct ifla_vf_stats;
70 struct ib_uverbs_file;
71 
72 extern struct workqueue_struct *ib_wq;
73 extern struct workqueue_struct *ib_comp_wq;
74 
75 union ib_gid {
76 	u8	raw[16];
77 	struct {
78 		__be64	subnet_prefix;
79 		__be64	interface_id;
80 	} global;
81 };
82 
83 extern union ib_gid zgid;
84 
85 enum ib_gid_type {
86 	/* If link layer is Ethernet, this is RoCE V1 */
87 	IB_GID_TYPE_IB        = 0,
88 	IB_GID_TYPE_ROCE      = 0,
89 	IB_GID_TYPE_ROCE_UDP_ENCAP = 1,
90 	IB_GID_TYPE_SIZE
91 };
92 
93 #define ROCE_V2_UDP_DPORT      4791
94 struct ib_gid_attr {
95 	enum ib_gid_type	gid_type;
96 	struct ifnet	*ndev;
97 };
98 
99 enum rdma_node_type {
100 	/* IB values map to NodeInfo:NodeType. */
101 	RDMA_NODE_IB_CA 	= 1,
102 	RDMA_NODE_IB_SWITCH,
103 	RDMA_NODE_IB_ROUTER,
104 	RDMA_NODE_RNIC,
105 	RDMA_NODE_USNIC,
106 	RDMA_NODE_USNIC_UDP,
107 };
108 
109 enum {
110 	/* set the local administered indication */
111 	IB_SA_WELL_KNOWN_GUID	= BIT_ULL(57) | 2,
112 };
113 
114 enum rdma_transport_type {
115 	RDMA_TRANSPORT_IB,
116 	RDMA_TRANSPORT_IWARP,
117 	RDMA_TRANSPORT_USNIC,
118 	RDMA_TRANSPORT_USNIC_UDP
119 };
120 
121 enum rdma_protocol_type {
122 	RDMA_PROTOCOL_IB,
123 	RDMA_PROTOCOL_IBOE,
124 	RDMA_PROTOCOL_IWARP,
125 	RDMA_PROTOCOL_USNIC_UDP
126 };
127 
128 __attribute_const__ enum rdma_transport_type
129 rdma_node_get_transport(enum rdma_node_type node_type);
130 
131 enum rdma_network_type {
132 	RDMA_NETWORK_IB,
133 	RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB,
134 	RDMA_NETWORK_IPV4,
135 	RDMA_NETWORK_IPV6
136 };
137 
ib_network_to_gid_type(enum rdma_network_type network_type)138 static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
139 {
140 	if (network_type == RDMA_NETWORK_IPV4 ||
141 	    network_type == RDMA_NETWORK_IPV6)
142 		return IB_GID_TYPE_ROCE_UDP_ENCAP;
143 
144 	/* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */
145 	return IB_GID_TYPE_IB;
146 }
147 
ib_gid_to_network_type(enum ib_gid_type gid_type,union ib_gid * gid)148 static inline enum rdma_network_type ib_gid_to_network_type(enum ib_gid_type gid_type,
149 							    union ib_gid *gid)
150 {
151 	if (gid_type == IB_GID_TYPE_IB)
152 		return RDMA_NETWORK_IB;
153 
154 	if (ipv6_addr_v4mapped((struct in6_addr *)gid))
155 		return RDMA_NETWORK_IPV4;
156 	else
157 		return RDMA_NETWORK_IPV6;
158 }
159 
160 enum rdma_link_layer {
161 	IB_LINK_LAYER_UNSPECIFIED,
162 	IB_LINK_LAYER_INFINIBAND,
163 	IB_LINK_LAYER_ETHERNET,
164 };
165 
166 enum ib_device_cap_flags {
167 	IB_DEVICE_RESIZE_MAX_WR			= (1 << 0),
168 	IB_DEVICE_BAD_PKEY_CNTR			= (1 << 1),
169 	IB_DEVICE_BAD_QKEY_CNTR			= (1 << 2),
170 	IB_DEVICE_RAW_MULTI			= (1 << 3),
171 	IB_DEVICE_AUTO_PATH_MIG			= (1 << 4),
172 	IB_DEVICE_CHANGE_PHY_PORT		= (1 << 5),
173 	IB_DEVICE_UD_AV_PORT_ENFORCE		= (1 << 6),
174 	IB_DEVICE_CURR_QP_STATE_MOD		= (1 << 7),
175 	IB_DEVICE_SHUTDOWN_PORT			= (1 << 8),
176 	IB_DEVICE_INIT_TYPE			= (1 << 9),
177 	IB_DEVICE_PORT_ACTIVE_EVENT		= (1 << 10),
178 	IB_DEVICE_SYS_IMAGE_GUID		= (1 << 11),
179 	IB_DEVICE_RC_RNR_NAK_GEN		= (1 << 12),
180 	IB_DEVICE_SRQ_RESIZE			= (1 << 13),
181 	IB_DEVICE_N_NOTIFY_CQ			= (1 << 14),
182 
183 	/*
184 	 * This device supports a per-device lkey or stag that can be
185 	 * used without performing a memory registration for the local
186 	 * memory.  Note that ULPs should never check this flag, but
187 	 * instead of use the local_dma_lkey flag in the ib_pd structure,
188 	 * which will always contain a usable lkey.
189 	 */
190 	IB_DEVICE_LOCAL_DMA_LKEY		= (1 << 15),
191 	IB_DEVICE_RESERVED /* old SEND_W_INV */	= (1 << 16),
192 	IB_DEVICE_MEM_WINDOW			= (1 << 17),
193 	/*
194 	 * Devices should set IB_DEVICE_UD_IP_SUM if they support
195 	 * insertion of UDP and TCP checksum on outgoing UD IPoIB
196 	 * messages and can verify the validity of checksum for
197 	 * incoming messages.  Setting this flag implies that the
198 	 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
199 	 */
200 	IB_DEVICE_UD_IP_CSUM			= (1 << 18),
201 	IB_DEVICE_UD_TSO			= (1 << 19),
202 	IB_DEVICE_XRC				= (1 << 20),
203 
204 	/*
205 	 * This device supports the IB "base memory management extension",
206 	 * which includes support for fast registrations (IB_WR_REG_MR,
207 	 * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs).  This flag should
208 	 * also be set by any iWarp device which must support FRs to comply
209 	 * to the iWarp verbs spec.  iWarp devices also support the
210 	 * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
211 	 * stag.
212 	 */
213 	IB_DEVICE_MEM_MGT_EXTENSIONS		= (1 << 21),
214 	IB_DEVICE_BLOCK_MULTICAST_LOOPBACK	= (1 << 22),
215 	IB_DEVICE_MEM_WINDOW_TYPE_2A		= (1 << 23),
216 	IB_DEVICE_MEM_WINDOW_TYPE_2B		= (1 << 24),
217 	IB_DEVICE_RC_IP_CSUM			= (1 << 25),
218 	IB_DEVICE_RAW_IP_CSUM			= (1 << 26),
219 	/*
220 	 * Devices should set IB_DEVICE_CROSS_CHANNEL if they
221 	 * support execution of WQEs that involve synchronization
222 	 * of I/O operations with single completion queue managed
223 	 * by hardware.
224 	 */
225 	IB_DEVICE_CROSS_CHANNEL		= (1 << 27),
226 	IB_DEVICE_MANAGED_FLOW_STEERING		= (1 << 29),
227 	IB_DEVICE_SIGNATURE_HANDOVER		= (1 << 30),
228 	IB_DEVICE_ON_DEMAND_PAGING		= (1ULL << 31),
229 	IB_DEVICE_SG_GAPS_REG			= (1ULL << 32),
230 	IB_DEVICE_VIRTUAL_FUNCTION		= (1ULL << 33),
231 	IB_DEVICE_RAW_SCATTER_FCS		= (1ULL << 34),
232 };
233 
234 enum ib_signature_prot_cap {
235 	IB_PROT_T10DIF_TYPE_1 = 1,
236 	IB_PROT_T10DIF_TYPE_2 = 1 << 1,
237 	IB_PROT_T10DIF_TYPE_3 = 1 << 2,
238 };
239 
240 enum ib_signature_guard_cap {
241 	IB_GUARD_T10DIF_CRC	= 1,
242 	IB_GUARD_T10DIF_CSUM	= 1 << 1,
243 };
244 
245 enum ib_atomic_cap {
246 	IB_ATOMIC_NONE,
247 	IB_ATOMIC_HCA,
248 	IB_ATOMIC_GLOB
249 };
250 
251 enum ib_odp_general_cap_bits {
252 	IB_ODP_SUPPORT = 1 << 0,
253 };
254 
255 enum ib_odp_transport_cap_bits {
256 	IB_ODP_SUPPORT_SEND	= 1 << 0,
257 	IB_ODP_SUPPORT_RECV	= 1 << 1,
258 	IB_ODP_SUPPORT_WRITE	= 1 << 2,
259 	IB_ODP_SUPPORT_READ	= 1 << 3,
260 	IB_ODP_SUPPORT_ATOMIC	= 1 << 4,
261 };
262 
263 struct ib_odp_caps {
264 	uint64_t general_caps;
265 	struct {
266 		uint32_t  rc_odp_caps;
267 		uint32_t  uc_odp_caps;
268 		uint32_t  ud_odp_caps;
269 	} per_transport_caps;
270 };
271 
272 struct ib_rss_caps {
273 	/* Corresponding bit will be set if qp type from
274 	 * 'enum ib_qp_type' is supported, e.g.
275 	 * supported_qpts |= 1 << IB_QPT_UD
276 	 */
277 	u32 supported_qpts;
278 	u32 max_rwq_indirection_tables;
279 	u32 max_rwq_indirection_table_size;
280 };
281 
282 enum ib_cq_creation_flags {
283 	IB_CQ_FLAGS_TIMESTAMP_COMPLETION   = 1 << 0,
284 	IB_CQ_FLAGS_IGNORE_OVERRUN	   = 1 << 1,
285 };
286 
287 struct ib_cq_init_attr {
288 	unsigned int	cqe;
289 	u32		comp_vector;
290 	u32		flags;
291 };
292 
293 struct ib_device_attr {
294 	u64			fw_ver;
295 	__be64			sys_image_guid;
296 	u64			max_mr_size;
297 	u64			page_size_cap;
298 	u32			vendor_id;
299 	u32			vendor_part_id;
300 	u32			hw_ver;
301 	int			max_qp;
302 	int			max_qp_wr;
303 	u64			device_cap_flags;
304 	int			max_sge;
305 	int			max_sge_rd;
306 	int			max_cq;
307 	int			max_cqe;
308 	int			max_mr;
309 	int			max_pd;
310 	int			max_qp_rd_atom;
311 	int			max_ee_rd_atom;
312 	int			max_res_rd_atom;
313 	int			max_qp_init_rd_atom;
314 	int			max_ee_init_rd_atom;
315 	enum ib_atomic_cap	atomic_cap;
316 	enum ib_atomic_cap	masked_atomic_cap;
317 	int			max_ee;
318 	int			max_rdd;
319 	int			max_mw;
320 	int			max_raw_ipv6_qp;
321 	int			max_raw_ethy_qp;
322 	int			max_mcast_grp;
323 	int			max_mcast_qp_attach;
324 	int			max_total_mcast_qp_attach;
325 	int			max_ah;
326 	int			max_fmr;
327 	int			max_map_per_fmr;
328 	int			max_srq;
329 	int			max_srq_wr;
330 	int			max_srq_sge;
331 	unsigned int		max_fast_reg_page_list_len;
332 	u16			max_pkeys;
333 	u8			local_ca_ack_delay;
334 	int			sig_prot_cap;
335 	int			sig_guard_cap;
336 	struct ib_odp_caps	odp_caps;
337 	uint64_t		timestamp_mask;
338 	uint64_t		hca_core_clock; /* in KHZ */
339 	struct ib_rss_caps	rss_caps;
340 	u32			max_wq_type_rq;
341 };
342 
343 enum ib_mtu {
344 	IB_MTU_256  = 1,
345 	IB_MTU_512  = 2,
346 	IB_MTU_1024 = 3,
347 	IB_MTU_2048 = 4,
348 	IB_MTU_4096 = 5
349 };
350 
ib_mtu_enum_to_int(enum ib_mtu mtu)351 static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
352 {
353 	switch (mtu) {
354 	case IB_MTU_256:  return  256;
355 	case IB_MTU_512:  return  512;
356 	case IB_MTU_1024: return 1024;
357 	case IB_MTU_2048: return 2048;
358 	case IB_MTU_4096: return 4096;
359 	default: 	  return -1;
360 	}
361 }
362 
363 enum ib_port_state {
364 	IB_PORT_NOP		= 0,
365 	IB_PORT_DOWN		= 1,
366 	IB_PORT_INIT		= 2,
367 	IB_PORT_ARMED		= 3,
368 	IB_PORT_ACTIVE		= 4,
369 	IB_PORT_ACTIVE_DEFER	= 5,
370 	IB_PORT_DUMMY		= -1,	/* force enum signed */
371 };
372 
373 enum ib_port_cap_flags {
374 	IB_PORT_SM				= 1 <<  1,
375 	IB_PORT_NOTICE_SUP			= 1 <<  2,
376 	IB_PORT_TRAP_SUP			= 1 <<  3,
377 	IB_PORT_OPT_IPD_SUP                     = 1 <<  4,
378 	IB_PORT_AUTO_MIGR_SUP			= 1 <<  5,
379 	IB_PORT_SL_MAP_SUP			= 1 <<  6,
380 	IB_PORT_MKEY_NVRAM			= 1 <<  7,
381 	IB_PORT_PKEY_NVRAM			= 1 <<  8,
382 	IB_PORT_LED_INFO_SUP			= 1 <<  9,
383 	IB_PORT_SM_DISABLED			= 1 << 10,
384 	IB_PORT_SYS_IMAGE_GUID_SUP		= 1 << 11,
385 	IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP	= 1 << 12,
386 	IB_PORT_EXTENDED_SPEEDS_SUP             = 1 << 14,
387 	IB_PORT_CM_SUP				= 1 << 16,
388 	IB_PORT_SNMP_TUNNEL_SUP			= 1 << 17,
389 	IB_PORT_REINIT_SUP			= 1 << 18,
390 	IB_PORT_DEVICE_MGMT_SUP			= 1 << 19,
391 	IB_PORT_VENDOR_CLASS_SUP		= 1 << 20,
392 	IB_PORT_DR_NOTICE_SUP			= 1 << 21,
393 	IB_PORT_CAP_MASK_NOTICE_SUP		= 1 << 22,
394 	IB_PORT_BOOT_MGMT_SUP			= 1 << 23,
395 	IB_PORT_LINK_LATENCY_SUP		= 1 << 24,
396 	IB_PORT_CLIENT_REG_SUP			= 1 << 25,
397 	IB_PORT_IP_BASED_GIDS			= 1 << 26,
398 };
399 
400 enum ib_port_phys_state {
401 	IB_PORT_PHYS_STATE_SLEEP = 1,
402 	IB_PORT_PHYS_STATE_POLLING = 2,
403 	IB_PORT_PHYS_STATE_DISABLED = 3,
404 	IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING = 4,
405 	IB_PORT_PHYS_STATE_LINK_UP = 5,
406 	IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY = 6,
407 	IB_PORT_PHYS_STATE_PHY_TEST = 7,
408 };
409 
410 enum ib_port_width {
411 	IB_WIDTH_1X	= 1,
412 	IB_WIDTH_2X	= 16,
413 	IB_WIDTH_4X	= 2,
414 	IB_WIDTH_8X	= 4,
415 	IB_WIDTH_12X	= 8
416 };
417 
ib_width_enum_to_int(enum ib_port_width width)418 static inline int ib_width_enum_to_int(enum ib_port_width width)
419 {
420 	switch (width) {
421 	case IB_WIDTH_1X:  return  1;
422 	case IB_WIDTH_2X:  return  2;
423 	case IB_WIDTH_4X:  return  4;
424 	case IB_WIDTH_8X:  return  8;
425 	case IB_WIDTH_12X: return 12;
426 	default: 	  return -1;
427 	}
428 }
429 
430 enum ib_port_speed {
431 	IB_SPEED_SDR	= 1,
432 	IB_SPEED_DDR	= 2,
433 	IB_SPEED_QDR	= 4,
434 	IB_SPEED_FDR10	= 8,
435 	IB_SPEED_FDR	= 16,
436 	IB_SPEED_EDR	= 32,
437 	IB_SPEED_HDR	= 64,
438 	IB_SPEED_NDR	= 128
439 };
440 
441 /**
442  * struct rdma_hw_stats
443  * @lock - Mutex to protect parallel write access to lifespan and values
444  *    of counters, which are 64bits and not guaranteeed to be written
445  *    atomicaly on 32bits systems.
446  * @timestamp - Used by the core code to track when the last update was
447  * @lifespan - Used by the core code to determine how old the counters
448  *   should be before being updated again.  Stored in jiffies, defaults
449  *   to 10 milliseconds, drivers can override the default be specifying
450  *   their own value during their allocation routine.
451  * @name - Array of pointers to static names used for the counters in
452  *   directory.
453  * @num_counters - How many hardware counters there are.  If name is
454  *   shorter than this number, a kernel oops will result.  Driver authors
455  *   are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
456  *   in their code to prevent this.
457  * @value - Array of u64 counters that are accessed by the sysfs code and
458  *   filled in by the drivers get_stats routine
459  */
460 struct rdma_hw_stats {
461 	struct mutex	lock; /* Protect lifespan and values[] */
462 	unsigned long	timestamp;
463 	unsigned long	lifespan;
464 	const char * const *names;
465 	int		num_counters;
466 	u64		value[];
467 };
468 
469 #define RDMA_HW_STATS_DEFAULT_LIFESPAN 10
470 /**
471  * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct
472  *   for drivers.
473  * @names - Array of static const char *
474  * @num_counters - How many elements in array
475  * @lifespan - How many milliseconds between updates
476  */
rdma_alloc_hw_stats_struct(const char * const * names,int num_counters,unsigned long lifespan)477 static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
478 		const char * const *names, int num_counters,
479 		unsigned long lifespan)
480 {
481 	struct rdma_hw_stats *stats;
482 
483 	stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
484 			GFP_KERNEL);
485 	if (!stats)
486 		return NULL;
487 	stats->names = names;
488 	stats->num_counters = num_counters;
489 	stats->lifespan = msecs_to_jiffies(lifespan);
490 
491 	return stats;
492 }
493 
494 
495 /* Define bits for the various functionality this port needs to be supported by
496  * the core.
497  */
498 /* Management                           0x00000FFF */
499 #define RDMA_CORE_CAP_IB_MAD            0x00000001
500 #define RDMA_CORE_CAP_IB_SMI            0x00000002
501 #define RDMA_CORE_CAP_IB_CM             0x00000004
502 #define RDMA_CORE_CAP_IW_CM             0x00000008
503 #define RDMA_CORE_CAP_IB_SA             0x00000010
504 #define RDMA_CORE_CAP_OPA_MAD           0x00000020
505 
506 /* Address format                       0x000FF000 */
507 #define RDMA_CORE_CAP_AF_IB             0x00001000
508 #define RDMA_CORE_CAP_ETH_AH            0x00002000
509 
510 /* Protocol                             0xFFF00000 */
511 #define RDMA_CORE_CAP_PROT_IB           0x00100000
512 #define RDMA_CORE_CAP_PROT_ROCE         0x00200000
513 #define RDMA_CORE_CAP_PROT_IWARP        0x00400000
514 #define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
515 
516 #define RDMA_CORE_PORT_IBA_IB          (RDMA_CORE_CAP_PROT_IB  \
517 					| RDMA_CORE_CAP_IB_MAD \
518 					| RDMA_CORE_CAP_IB_SMI \
519 					| RDMA_CORE_CAP_IB_CM  \
520 					| RDMA_CORE_CAP_IB_SA  \
521 					| RDMA_CORE_CAP_AF_IB)
522 #define RDMA_CORE_PORT_IBA_ROCE        (RDMA_CORE_CAP_PROT_ROCE \
523 					| RDMA_CORE_CAP_IB_MAD  \
524 					| RDMA_CORE_CAP_IB_CM   \
525 					| RDMA_CORE_CAP_AF_IB   \
526 					| RDMA_CORE_CAP_ETH_AH)
527 #define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP			\
528 					(RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
529 					| RDMA_CORE_CAP_IB_MAD  \
530 					| RDMA_CORE_CAP_IB_CM   \
531 					| RDMA_CORE_CAP_AF_IB   \
532 					| RDMA_CORE_CAP_ETH_AH)
533 #define RDMA_CORE_PORT_IWARP           (RDMA_CORE_CAP_PROT_IWARP \
534 					| RDMA_CORE_CAP_IW_CM)
535 #define RDMA_CORE_PORT_INTEL_OPA       (RDMA_CORE_PORT_IBA_IB  \
536 					| RDMA_CORE_CAP_OPA_MAD)
537 
538 struct ib_port_attr {
539 	u64			subnet_prefix;
540 	enum ib_port_state	state;
541 	enum ib_mtu		max_mtu;
542 	enum ib_mtu		active_mtu;
543 	int			gid_tbl_len;
544 	u32			port_cap_flags;
545 	u32			max_msg_sz;
546 	u32			bad_pkey_cntr;
547 	u32			qkey_viol_cntr;
548 	u16			pkey_tbl_len;
549 	u16			lid;
550 	u16			sm_lid;
551 	u8			lmc;
552 	u8			max_vl_num;
553 	u8			sm_sl;
554 	u8			subnet_timeout;
555 	u8			init_type_reply;
556 	u8			active_width;
557 	u8			active_speed;
558 	u8                      phys_state;
559 	bool			grh_required;
560 };
561 
562 enum ib_device_modify_flags {
563 	IB_DEVICE_MODIFY_SYS_IMAGE_GUID	= 1 << 0,
564 	IB_DEVICE_MODIFY_NODE_DESC	= 1 << 1
565 };
566 
567 #define IB_DEVICE_NODE_DESC_MAX 64
568 
569 struct ib_device_modify {
570 	u64	sys_image_guid;
571 	char	node_desc[IB_DEVICE_NODE_DESC_MAX];
572 };
573 
574 enum ib_port_modify_flags {
575 	IB_PORT_SHUTDOWN		= 1,
576 	IB_PORT_INIT_TYPE		= (1<<2),
577 	IB_PORT_RESET_QKEY_CNTR		= (1<<3)
578 };
579 
580 struct ib_port_modify {
581 	u32	set_port_cap_mask;
582 	u32	clr_port_cap_mask;
583 	u8	init_type;
584 };
585 
586 enum ib_event_type {
587 	IB_EVENT_CQ_ERR,
588 	IB_EVENT_QP_FATAL,
589 	IB_EVENT_QP_REQ_ERR,
590 	IB_EVENT_QP_ACCESS_ERR,
591 	IB_EVENT_COMM_EST,
592 	IB_EVENT_SQ_DRAINED,
593 	IB_EVENT_PATH_MIG,
594 	IB_EVENT_PATH_MIG_ERR,
595 	IB_EVENT_DEVICE_FATAL,
596 	IB_EVENT_PORT_ACTIVE,
597 	IB_EVENT_PORT_ERR,
598 	IB_EVENT_LID_CHANGE,
599 	IB_EVENT_PKEY_CHANGE,
600 	IB_EVENT_SM_CHANGE,
601 	IB_EVENT_SRQ_ERR,
602 	IB_EVENT_SRQ_LIMIT_REACHED,
603 	IB_EVENT_QP_LAST_WQE_REACHED,
604 	IB_EVENT_CLIENT_REREGISTER,
605 	IB_EVENT_GID_CHANGE,
606 	IB_EVENT_WQ_FATAL,
607 };
608 
609 const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
610 
611 struct ib_event {
612 	struct ib_device	*device;
613 	union {
614 		struct ib_cq	*cq;
615 		struct ib_qp	*qp;
616 		struct ib_srq	*srq;
617 		struct ib_wq	*wq;
618 		u8		port_num;
619 	} element;
620 	enum ib_event_type	event;
621 };
622 
623 struct ib_event_handler {
624 	struct ib_device *device;
625 	void            (*handler)(struct ib_event_handler *, struct ib_event *);
626 	struct list_head  list;
627 };
628 
629 #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler)		\
630 	do {							\
631 		(_ptr)->device  = _device;			\
632 		(_ptr)->handler = _handler;			\
633 		INIT_LIST_HEAD(&(_ptr)->list);			\
634 	} while (0)
635 
636 struct ib_global_route {
637 	union ib_gid	dgid;
638 	u32		flow_label;
639 	u8		sgid_index;
640 	u8		hop_limit;
641 	u8		traffic_class;
642 };
643 
644 struct ib_grh {
645 	__be32		version_tclass_flow;
646 	__be16		paylen;
647 	u8		next_hdr;
648 	u8		hop_limit;
649 	union ib_gid	sgid;
650 	union ib_gid	dgid;
651 };
652 
653 union rdma_network_hdr {
654 	struct ib_grh ibgrh;
655 	struct {
656 		/* The IB spec states that if it's IPv4, the header
657 		 * is located in the last 20 bytes of the header.
658 		 */
659 		u8		reserved[20];
660 		struct ip	roce4grh;
661 	};
662 };
663 
664 enum {
665 	IB_MULTICAST_QPN = 0xffffff
666 };
667 
668 #define IB_LID_PERMISSIVE	cpu_to_be16(0xFFFF)
669 #define IB_MULTICAST_LID_BASE	cpu_to_be16(0xC000)
670 
671 enum ib_ah_flags {
672 	IB_AH_GRH	= 1
673 };
674 
675 enum ib_rate {
676 	IB_RATE_PORT_CURRENT = 0,
677 	IB_RATE_2_5_GBPS = 2,
678 	IB_RATE_5_GBPS   = 5,
679 	IB_RATE_10_GBPS  = 3,
680 	IB_RATE_20_GBPS  = 6,
681 	IB_RATE_30_GBPS  = 4,
682 	IB_RATE_40_GBPS  = 7,
683 	IB_RATE_60_GBPS  = 8,
684 	IB_RATE_80_GBPS  = 9,
685 	IB_RATE_120_GBPS = 10,
686 	IB_RATE_14_GBPS  = 11,
687 	IB_RATE_56_GBPS  = 12,
688 	IB_RATE_112_GBPS = 13,
689 	IB_RATE_168_GBPS = 14,
690 	IB_RATE_25_GBPS  = 15,
691 	IB_RATE_100_GBPS = 16,
692 	IB_RATE_200_GBPS = 17,
693 	IB_RATE_300_GBPS = 18,
694 	IB_RATE_28_GBPS  = 19,
695 	IB_RATE_50_GBPS  = 20,
696 	IB_RATE_400_GBPS = 21,
697 	IB_RATE_600_GBPS = 22,
698 };
699 
700 /**
701  * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
702  * base rate of 2.5 Gbit/sec.  For example, IB_RATE_5_GBPS will be
703  * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
704  * @rate: rate to convert.
705  */
706 __attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
707 
708 /**
709  * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
710  * For example, IB_RATE_2_5_GBPS will be converted to 2500.
711  * @rate: rate to convert.
712  */
713 __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
714 
715 
716 /**
717  * enum ib_mr_type - memory region type
718  * @IB_MR_TYPE_MEM_REG:       memory region that is used for
719  *                            normal registration
720  * @IB_MR_TYPE_SIGNATURE:     memory region that is used for
721  *                            signature operations (data-integrity
722  *                            capable regions)
723  * @IB_MR_TYPE_SG_GAPS:       memory region that is capable to
724  *                            register any arbitrary sg lists (without
725  *                            the normal mr constraints - see
726  *                            ib_map_mr_sg)
727  */
728 enum ib_mr_type {
729 	IB_MR_TYPE_MEM_REG,
730 	IB_MR_TYPE_SIGNATURE,
731 	IB_MR_TYPE_SG_GAPS,
732 };
733 
734 /**
735  * Signature types
736  * IB_SIG_TYPE_NONE: Unprotected.
737  * IB_SIG_TYPE_T10_DIF: Type T10-DIF
738  */
739 enum ib_signature_type {
740 	IB_SIG_TYPE_NONE,
741 	IB_SIG_TYPE_T10_DIF,
742 };
743 
744 /**
745  * Signature T10-DIF block-guard types
746  * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
747  * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
748  */
749 enum ib_t10_dif_bg_type {
750 	IB_T10DIF_CRC,
751 	IB_T10DIF_CSUM
752 };
753 
754 /**
755  * struct ib_t10_dif_domain - Parameters specific for T10-DIF
756  *     domain.
757  * @bg_type: T10-DIF block guard type (CRC|CSUM)
758  * @pi_interval: protection information interval.
759  * @bg: seed of guard computation.
760  * @app_tag: application tag of guard block
761  * @ref_tag: initial guard block reference tag.
762  * @ref_remap: Indicate wethear the reftag increments each block
763  * @app_escape: Indicate to skip block check if apptag=0xffff
764  * @ref_escape: Indicate to skip block check if reftag=0xffffffff
765  * @apptag_check_mask: check bitmask of application tag.
766  */
767 struct ib_t10_dif_domain {
768 	enum ib_t10_dif_bg_type bg_type;
769 	u16			pi_interval;
770 	u16			bg;
771 	u16			app_tag;
772 	u32			ref_tag;
773 	bool			ref_remap;
774 	bool			app_escape;
775 	bool			ref_escape;
776 	u16			apptag_check_mask;
777 };
778 
779 /**
780  * struct ib_sig_domain - Parameters for signature domain
781  * @sig_type: specific signauture type
782  * @sig: union of all signature domain attributes that may
783  *     be used to set domain layout.
784  */
785 struct ib_sig_domain {
786 	enum ib_signature_type sig_type;
787 	union {
788 		struct ib_t10_dif_domain dif;
789 	} sig;
790 };
791 
792 /**
793  * struct ib_sig_attrs - Parameters for signature handover operation
794  * @check_mask: bitmask for signature byte check (8 bytes)
795  * @mem: memory domain layout desciptor.
796  * @wire: wire domain layout desciptor.
797  */
798 struct ib_sig_attrs {
799 	u8			check_mask;
800 	struct ib_sig_domain	mem;
801 	struct ib_sig_domain	wire;
802 };
803 
804 enum ib_sig_err_type {
805 	IB_SIG_BAD_GUARD,
806 	IB_SIG_BAD_REFTAG,
807 	IB_SIG_BAD_APPTAG,
808 };
809 
810 /**
811  * struct ib_sig_err - signature error descriptor
812  */
813 struct ib_sig_err {
814 	enum ib_sig_err_type	err_type;
815 	u32			expected;
816 	u32			actual;
817 	u64			sig_err_offset;
818 	u32			key;
819 };
820 
821 enum ib_mr_status_check {
822 	IB_MR_CHECK_SIG_STATUS = 1,
823 };
824 
825 /**
826  * struct ib_mr_status - Memory region status container
827  *
828  * @fail_status: Bitmask of MR checks status. For each
829  *     failed check a corresponding status bit is set.
830  * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
831  *     failure.
832  */
833 struct ib_mr_status {
834 	u32		    fail_status;
835 	struct ib_sig_err   sig_err;
836 };
837 
838 /**
839  * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
840  * enum.
841  * @mult: multiple to convert.
842  */
843 __attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
844 
845 struct ib_ah_attr {
846 	struct ib_global_route	grh;
847 	u16			dlid;
848 	u8			sl;
849 	u8			src_path_bits;
850 	u8			static_rate;
851 	u8			ah_flags;
852 	u8			port_num;
853 	u8			dmac[ETH_ALEN];
854 };
855 
856 enum ib_wc_status {
857 	IB_WC_SUCCESS,
858 	IB_WC_LOC_LEN_ERR,
859 	IB_WC_LOC_QP_OP_ERR,
860 	IB_WC_LOC_EEC_OP_ERR,
861 	IB_WC_LOC_PROT_ERR,
862 	IB_WC_WR_FLUSH_ERR,
863 	IB_WC_MW_BIND_ERR,
864 	IB_WC_BAD_RESP_ERR,
865 	IB_WC_LOC_ACCESS_ERR,
866 	IB_WC_REM_INV_REQ_ERR,
867 	IB_WC_REM_ACCESS_ERR,
868 	IB_WC_REM_OP_ERR,
869 	IB_WC_RETRY_EXC_ERR,
870 	IB_WC_RNR_RETRY_EXC_ERR,
871 	IB_WC_LOC_RDD_VIOL_ERR,
872 	IB_WC_REM_INV_RD_REQ_ERR,
873 	IB_WC_REM_ABORT_ERR,
874 	IB_WC_INV_EECN_ERR,
875 	IB_WC_INV_EEC_STATE_ERR,
876 	IB_WC_FATAL_ERR,
877 	IB_WC_RESP_TIMEOUT_ERR,
878 	IB_WC_GENERAL_ERR
879 };
880 
881 const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
882 
883 enum ib_wc_opcode {
884 	IB_WC_SEND,
885 	IB_WC_RDMA_WRITE,
886 	IB_WC_RDMA_READ,
887 	IB_WC_COMP_SWAP,
888 	IB_WC_FETCH_ADD,
889 	IB_WC_LSO,
890 	IB_WC_LOCAL_INV,
891 	IB_WC_REG_MR,
892 	IB_WC_MASKED_COMP_SWAP,
893 	IB_WC_MASKED_FETCH_ADD,
894 /*
895  * Set value of IB_WC_RECV so consumers can test if a completion is a
896  * receive by testing (opcode & IB_WC_RECV).
897  */
898 	IB_WC_RECV			= 1 << 7,
899 	IB_WC_RECV_RDMA_WITH_IMM,
900 	IB_WC_DUMMY = -1,	/* force enum signed */
901 };
902 
903 enum ib_wc_flags {
904 	IB_WC_GRH		= 1,
905 	IB_WC_WITH_IMM		= (1<<1),
906 	IB_WC_WITH_INVALIDATE	= (1<<2),
907 	IB_WC_IP_CSUM_OK	= (1<<3),
908 	IB_WC_WITH_SMAC		= (1<<4),
909 	IB_WC_WITH_VLAN		= (1<<5),
910 	IB_WC_WITH_NETWORK_HDR_TYPE	= (1<<6),
911 };
912 
913 struct ib_wc {
914 	union {
915 		u64		wr_id;
916 		struct ib_cqe	*wr_cqe;
917 	};
918 	enum ib_wc_status	status;
919 	enum ib_wc_opcode	opcode;
920 	u32			vendor_err;
921 	u32			byte_len;
922 	struct ib_qp	       *qp;
923 	union {
924 		__be32		imm_data;
925 		u32		invalidate_rkey;
926 	} ex;
927 	u32			src_qp;
928 	int			wc_flags;
929 	u16			pkey_index;
930 	u16			slid;
931 	u8			sl;
932 	u8			dlid_path_bits;
933 	u8			port_num;	/* valid only for DR SMPs on switches */
934 	u8			smac[ETH_ALEN];
935 	u16			vlan_id;
936 	u8			network_hdr_type;
937 };
938 
939 enum ib_cq_notify_flags {
940 	IB_CQ_SOLICITED			= 1 << 0,
941 	IB_CQ_NEXT_COMP			= 1 << 1,
942 	IB_CQ_SOLICITED_MASK		= IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
943 	IB_CQ_REPORT_MISSED_EVENTS	= 1 << 2,
944 };
945 
946 enum ib_srq_type {
947 	IB_SRQT_BASIC,
948 	IB_SRQT_XRC
949 };
950 
951 enum ib_srq_attr_mask {
952 	IB_SRQ_MAX_WR	= 1 << 0,
953 	IB_SRQ_LIMIT	= 1 << 1,
954 };
955 
956 struct ib_srq_attr {
957 	u32	max_wr;
958 	u32	max_sge;
959 	u32	srq_limit;
960 };
961 
962 struct ib_srq_init_attr {
963 	void		      (*event_handler)(struct ib_event *, void *);
964 	void		       *srq_context;
965 	struct ib_srq_attr	attr;
966 	enum ib_srq_type	srq_type;
967 
968 	union {
969 		struct {
970 			struct ib_xrcd *xrcd;
971 			struct ib_cq   *cq;
972 		} xrc;
973 	} ext;
974 };
975 
976 struct ib_qp_cap {
977 	u32	max_send_wr;
978 	u32	max_recv_wr;
979 	u32	max_send_sge;
980 	u32	max_recv_sge;
981 	u32	max_inline_data;
982 
983 	/*
984 	 * Maximum number of rdma_rw_ctx structures in flight at a time.
985 	 * ib_create_qp() will calculate the right amount of neededed WRs
986 	 * and MRs based on this.
987 	 */
988 	u32	max_rdma_ctxs;
989 };
990 
991 enum ib_sig_type {
992 	IB_SIGNAL_ALL_WR,
993 	IB_SIGNAL_REQ_WR
994 };
995 
996 enum ib_qp_type {
997 	/*
998 	 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
999 	 * here (and in that order) since the MAD layer uses them as
1000 	 * indices into a 2-entry table.
1001 	 */
1002 	IB_QPT_SMI,
1003 	IB_QPT_GSI,
1004 
1005 	IB_QPT_RC,
1006 	IB_QPT_UC,
1007 	IB_QPT_UD,
1008 	IB_QPT_RAW_IPV6,
1009 	IB_QPT_RAW_ETHERTYPE,
1010 	IB_QPT_RAW_PACKET = 8,
1011 	IB_QPT_XRC_INI = 9,
1012 	IB_QPT_XRC_TGT,
1013 	IB_QPT_MAX,
1014 	/* Reserve a range for qp types internal to the low level driver.
1015 	 * These qp types will not be visible at the IB core layer, so the
1016 	 * IB_QPT_MAX usages should not be affected in the core layer
1017 	 */
1018 	IB_QPT_RESERVED1 = 0x1000,
1019 	IB_QPT_RESERVED2,
1020 	IB_QPT_RESERVED3,
1021 	IB_QPT_RESERVED4,
1022 	IB_QPT_RESERVED5,
1023 	IB_QPT_RESERVED6,
1024 	IB_QPT_RESERVED7,
1025 	IB_QPT_RESERVED8,
1026 	IB_QPT_RESERVED9,
1027 	IB_QPT_RESERVED10,
1028 };
1029 
1030 enum ib_qp_create_flags {
1031 	IB_QP_CREATE_IPOIB_UD_LSO		= 1 << 0,
1032 	IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK	= 1 << 1,
1033 	IB_QP_CREATE_CROSS_CHANNEL              = 1 << 2,
1034 	IB_QP_CREATE_MANAGED_SEND               = 1 << 3,
1035 	IB_QP_CREATE_MANAGED_RECV               = 1 << 4,
1036 	IB_QP_CREATE_NETIF_QP			= 1 << 5,
1037 	IB_QP_CREATE_SIGNATURE_EN		= 1 << 6,
1038 	IB_QP_CREATE_USE_GFP_NOIO		= 1 << 7,
1039 	IB_QP_CREATE_SCATTER_FCS		= 1 << 8,
1040 	/* reserve bits 26-31 for low level drivers' internal use */
1041 	IB_QP_CREATE_RESERVED_START		= 1 << 26,
1042 	IB_QP_CREATE_RESERVED_END		= 1 << 31,
1043 };
1044 
1045 /*
1046  * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
1047  * callback to destroy the passed in QP.
1048  */
1049 
1050 struct ib_qp_init_attr {
1051 	void                  (*event_handler)(struct ib_event *, void *);
1052 	void		       *qp_context;
1053 	struct ib_cq	       *send_cq;
1054 	struct ib_cq	       *recv_cq;
1055 	struct ib_srq	       *srq;
1056 	struct ib_xrcd	       *xrcd;     /* XRC TGT QPs only */
1057 	struct ib_qp_cap	cap;
1058 	enum ib_sig_type	sq_sig_type;
1059 	enum ib_qp_type		qp_type;
1060 	enum ib_qp_create_flags	create_flags;
1061 
1062 	/*
1063 	 * Only needed for special QP types, or when using the RW API.
1064 	 */
1065 	u8			port_num;
1066 	struct ib_rwq_ind_table *rwq_ind_tbl;
1067 };
1068 
1069 struct ib_qp_open_attr {
1070 	void                  (*event_handler)(struct ib_event *, void *);
1071 	void		       *qp_context;
1072 	u32			qp_num;
1073 	enum ib_qp_type		qp_type;
1074 };
1075 
1076 enum ib_rnr_timeout {
1077 	IB_RNR_TIMER_655_36 =  0,
1078 	IB_RNR_TIMER_000_01 =  1,
1079 	IB_RNR_TIMER_000_02 =  2,
1080 	IB_RNR_TIMER_000_03 =  3,
1081 	IB_RNR_TIMER_000_04 =  4,
1082 	IB_RNR_TIMER_000_06 =  5,
1083 	IB_RNR_TIMER_000_08 =  6,
1084 	IB_RNR_TIMER_000_12 =  7,
1085 	IB_RNR_TIMER_000_16 =  8,
1086 	IB_RNR_TIMER_000_24 =  9,
1087 	IB_RNR_TIMER_000_32 = 10,
1088 	IB_RNR_TIMER_000_48 = 11,
1089 	IB_RNR_TIMER_000_64 = 12,
1090 	IB_RNR_TIMER_000_96 = 13,
1091 	IB_RNR_TIMER_001_28 = 14,
1092 	IB_RNR_TIMER_001_92 = 15,
1093 	IB_RNR_TIMER_002_56 = 16,
1094 	IB_RNR_TIMER_003_84 = 17,
1095 	IB_RNR_TIMER_005_12 = 18,
1096 	IB_RNR_TIMER_007_68 = 19,
1097 	IB_RNR_TIMER_010_24 = 20,
1098 	IB_RNR_TIMER_015_36 = 21,
1099 	IB_RNR_TIMER_020_48 = 22,
1100 	IB_RNR_TIMER_030_72 = 23,
1101 	IB_RNR_TIMER_040_96 = 24,
1102 	IB_RNR_TIMER_061_44 = 25,
1103 	IB_RNR_TIMER_081_92 = 26,
1104 	IB_RNR_TIMER_122_88 = 27,
1105 	IB_RNR_TIMER_163_84 = 28,
1106 	IB_RNR_TIMER_245_76 = 29,
1107 	IB_RNR_TIMER_327_68 = 30,
1108 	IB_RNR_TIMER_491_52 = 31
1109 };
1110 
1111 enum ib_qp_attr_mask {
1112 	IB_QP_STATE			= 1,
1113 	IB_QP_CUR_STATE			= (1<<1),
1114 	IB_QP_EN_SQD_ASYNC_NOTIFY	= (1<<2),
1115 	IB_QP_ACCESS_FLAGS		= (1<<3),
1116 	IB_QP_PKEY_INDEX		= (1<<4),
1117 	IB_QP_PORT			= (1<<5),
1118 	IB_QP_QKEY			= (1<<6),
1119 	IB_QP_AV			= (1<<7),
1120 	IB_QP_PATH_MTU			= (1<<8),
1121 	IB_QP_TIMEOUT			= (1<<9),
1122 	IB_QP_RETRY_CNT			= (1<<10),
1123 	IB_QP_RNR_RETRY			= (1<<11),
1124 	IB_QP_RQ_PSN			= (1<<12),
1125 	IB_QP_MAX_QP_RD_ATOMIC		= (1<<13),
1126 	IB_QP_ALT_PATH			= (1<<14),
1127 	IB_QP_MIN_RNR_TIMER		= (1<<15),
1128 	IB_QP_SQ_PSN			= (1<<16),
1129 	IB_QP_MAX_DEST_RD_ATOMIC	= (1<<17),
1130 	IB_QP_PATH_MIG_STATE		= (1<<18),
1131 	IB_QP_CAP			= (1<<19),
1132 	IB_QP_DEST_QPN			= (1<<20),
1133 	IB_QP_RESERVED1			= (1<<21),
1134 	IB_QP_RESERVED2			= (1<<22),
1135 	IB_QP_RESERVED3			= (1<<23),
1136 	IB_QP_RESERVED4			= (1<<24),
1137 	IB_QP_RATE_LIMIT		= (1<<25),
1138 };
1139 
1140 enum ib_qp_state {
1141 	IB_QPS_RESET,
1142 	IB_QPS_INIT,
1143 	IB_QPS_RTR,
1144 	IB_QPS_RTS,
1145 	IB_QPS_SQD,
1146 	IB_QPS_SQE,
1147 	IB_QPS_ERR,
1148 	IB_QPS_DUMMY = -1,	/* force enum signed */
1149 };
1150 
1151 enum ib_mig_state {
1152 	IB_MIG_MIGRATED,
1153 	IB_MIG_REARM,
1154 	IB_MIG_ARMED
1155 };
1156 
1157 enum ib_mw_type {
1158 	IB_MW_TYPE_1 = 1,
1159 	IB_MW_TYPE_2 = 2
1160 };
1161 
1162 struct ib_qp_attr {
1163 	enum ib_qp_state	qp_state;
1164 	enum ib_qp_state	cur_qp_state;
1165 	enum ib_mtu		path_mtu;
1166 	enum ib_mig_state	path_mig_state;
1167 	u32			qkey;
1168 	u32			rq_psn;
1169 	u32			sq_psn;
1170 	u32			dest_qp_num;
1171 	int			qp_access_flags;
1172 	struct ib_qp_cap	cap;
1173 	struct ib_ah_attr	ah_attr;
1174 	struct ib_ah_attr	alt_ah_attr;
1175 	u16			pkey_index;
1176 	u16			alt_pkey_index;
1177 	u8			en_sqd_async_notify;
1178 	u8			sq_draining;
1179 	u8			max_rd_atomic;
1180 	u8			max_dest_rd_atomic;
1181 	u8			min_rnr_timer;
1182 	u8			port_num;
1183 	u8			timeout;
1184 	u8			retry_cnt;
1185 	u8			rnr_retry;
1186 	u8			alt_port_num;
1187 	u8			alt_timeout;
1188 	u32			rate_limit;
1189 };
1190 
1191 enum ib_wr_opcode {
1192 	IB_WR_RDMA_WRITE,
1193 	IB_WR_RDMA_WRITE_WITH_IMM,
1194 	IB_WR_SEND,
1195 	IB_WR_SEND_WITH_IMM,
1196 	IB_WR_RDMA_READ,
1197 	IB_WR_ATOMIC_CMP_AND_SWP,
1198 	IB_WR_ATOMIC_FETCH_AND_ADD,
1199 	IB_WR_LSO,
1200 	IB_WR_SEND_WITH_INV,
1201 	IB_WR_RDMA_READ_WITH_INV,
1202 	IB_WR_LOCAL_INV,
1203 	IB_WR_REG_MR,
1204 	IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
1205 	IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
1206 	IB_WR_REG_SIG_MR,
1207 	/* reserve values for low level drivers' internal use.
1208 	 * These values will not be used at all in the ib core layer.
1209 	 */
1210 	IB_WR_RESERVED1 = 0xf0,
1211 	IB_WR_RESERVED2,
1212 	IB_WR_RESERVED3,
1213 	IB_WR_RESERVED4,
1214 	IB_WR_RESERVED5,
1215 	IB_WR_RESERVED6,
1216 	IB_WR_RESERVED7,
1217 	IB_WR_RESERVED8,
1218 	IB_WR_RESERVED9,
1219 	IB_WR_RESERVED10,
1220 	IB_WR_DUMMY = -1,	/* force enum signed */
1221 };
1222 
1223 enum ib_send_flags {
1224 	IB_SEND_FENCE		= 1,
1225 	IB_SEND_SIGNALED	= (1<<1),
1226 	IB_SEND_SOLICITED	= (1<<2),
1227 	IB_SEND_INLINE		= (1<<3),
1228 	IB_SEND_IP_CSUM		= (1<<4),
1229 
1230 	/* reserve bits 26-31 for low level drivers' internal use */
1231 	IB_SEND_RESERVED_START	= (1 << 26),
1232 	IB_SEND_RESERVED_END	= (1 << 31),
1233 };
1234 
1235 struct ib_sge {
1236 	u64	addr;
1237 	u32	length;
1238 	u32	lkey;
1239 };
1240 
1241 struct ib_cqe {
1242 	void (*done)(struct ib_cq *cq, struct ib_wc *wc);
1243 };
1244 
1245 struct ib_send_wr {
1246 	struct ib_send_wr      *next;
1247 	union {
1248 		u64		wr_id;
1249 		struct ib_cqe	*wr_cqe;
1250 	};
1251 	struct ib_sge	       *sg_list;
1252 	int			num_sge;
1253 	enum ib_wr_opcode	opcode;
1254 	int			send_flags;
1255 	union {
1256 		__be32		imm_data;
1257 		u32		invalidate_rkey;
1258 	} ex;
1259 };
1260 
1261 struct ib_rdma_wr {
1262 	struct ib_send_wr	wr;
1263 	u64			remote_addr;
1264 	u32			rkey;
1265 };
1266 
rdma_wr(const struct ib_send_wr * wr)1267 static inline const struct ib_rdma_wr *rdma_wr(const struct ib_send_wr *wr)
1268 {
1269 	return container_of(wr, struct ib_rdma_wr, wr);
1270 }
1271 
1272 struct ib_atomic_wr {
1273 	struct ib_send_wr	wr;
1274 	u64			remote_addr;
1275 	u64			compare_add;
1276 	u64			swap;
1277 	u64			compare_add_mask;
1278 	u64			swap_mask;
1279 	u32			rkey;
1280 };
1281 
atomic_wr(const struct ib_send_wr * wr)1282 static inline const struct ib_atomic_wr *atomic_wr(const struct ib_send_wr *wr)
1283 {
1284 	return container_of(wr, struct ib_atomic_wr, wr);
1285 }
1286 
1287 struct ib_ud_wr {
1288 	struct ib_send_wr	wr;
1289 	struct ib_ah		*ah;
1290 	void			*header;
1291 	int			hlen;
1292 	int			mss;
1293 	u32			remote_qpn;
1294 	u32			remote_qkey;
1295 	u16			pkey_index; /* valid for GSI only */
1296 	u8			port_num;   /* valid for DR SMPs on switch only */
1297 };
1298 
ud_wr(const struct ib_send_wr * wr)1299 static inline const struct ib_ud_wr *ud_wr(const struct ib_send_wr *wr)
1300 {
1301 	return container_of(wr, struct ib_ud_wr, wr);
1302 }
1303 
1304 struct ib_reg_wr {
1305 	struct ib_send_wr	wr;
1306 	struct ib_mr		*mr;
1307 	u32			key;
1308 	int			access;
1309 };
1310 
reg_wr(const struct ib_send_wr * wr)1311 static inline const struct ib_reg_wr *reg_wr(const struct ib_send_wr *wr)
1312 {
1313 	return container_of(wr, struct ib_reg_wr, wr);
1314 }
1315 
1316 struct ib_sig_handover_wr {
1317 	struct ib_send_wr	wr;
1318 	struct ib_sig_attrs    *sig_attrs;
1319 	struct ib_mr	       *sig_mr;
1320 	int			access_flags;
1321 	struct ib_sge	       *prot;
1322 };
1323 
sig_handover_wr(const struct ib_send_wr * wr)1324 static inline const struct ib_sig_handover_wr *sig_handover_wr(const struct ib_send_wr *wr)
1325 {
1326 	return container_of(wr, struct ib_sig_handover_wr, wr);
1327 }
1328 
1329 struct ib_recv_wr {
1330 	struct ib_recv_wr      *next;
1331 	union {
1332 		u64		wr_id;
1333 		struct ib_cqe	*wr_cqe;
1334 	};
1335 	struct ib_sge	       *sg_list;
1336 	int			num_sge;
1337 };
1338 
1339 enum ib_access_flags {
1340 	IB_ACCESS_LOCAL_WRITE	= 1,
1341 	IB_ACCESS_REMOTE_WRITE	= (1<<1),
1342 	IB_ACCESS_REMOTE_READ	= (1<<2),
1343 	IB_ACCESS_REMOTE_ATOMIC	= (1<<3),
1344 	IB_ACCESS_MW_BIND	= (1<<4),
1345 	IB_ZERO_BASED		= (1<<5),
1346 	IB_ACCESS_ON_DEMAND     = (1<<6),
1347 };
1348 
1349 /*
1350  * XXX: these are apparently used for ->rereg_user_mr, no idea why they
1351  * are hidden here instead of a uapi header!
1352  */
1353 enum ib_mr_rereg_flags {
1354 	IB_MR_REREG_TRANS	= 1,
1355 	IB_MR_REREG_PD		= (1<<1),
1356 	IB_MR_REREG_ACCESS	= (1<<2),
1357 	IB_MR_REREG_SUPPORTED	= ((IB_MR_REREG_ACCESS << 1) - 1)
1358 };
1359 
1360 struct ib_fmr_attr {
1361 	int	max_pages;
1362 	int	max_maps;
1363 	u8	page_shift;
1364 };
1365 
1366 struct ib_umem;
1367 
1368 enum rdma_remove_reason {
1369 	/*
1370 	 * Userspace requested uobject deletion or initial try
1371 	 * to remove uobject via cleanup. Call could fail
1372 	 */
1373 	RDMA_REMOVE_DESTROY,
1374 	/* Context deletion. This call should delete the actual object itself */
1375 	RDMA_REMOVE_CLOSE,
1376 	/* Driver is being hot-unplugged. This call should delete the actual object itself */
1377 	RDMA_REMOVE_DRIVER_REMOVE,
1378 	/* uobj is being cleaned-up before being committed */
1379 	RDMA_REMOVE_ABORT,
1380 };
1381 
1382 struct ib_ucontext {
1383 	struct ib_device       *device;
1384 	struct list_head	pd_list;
1385 	struct list_head	mr_list;
1386 	struct list_head	mw_list;
1387 	struct list_head	cq_list;
1388 	struct list_head	qp_list;
1389 	struct list_head	srq_list;
1390 	struct list_head	ah_list;
1391 	struct list_head	xrcd_list;
1392 	struct list_head	rule_list;
1393 	struct list_head	wq_list;
1394 	struct list_head	rwq_ind_tbl_list;
1395 	int			closing;
1396 
1397 	bool cleanup_retryable;
1398 
1399 	pid_t			tgid;
1400 #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
1401 	struct rb_root      umem_tree;
1402 	/*
1403 	 * Protects .umem_rbroot and tree, as well as odp_mrs_count and
1404 	 * mmu notifiers registration.
1405 	 */
1406 	struct rw_semaphore	umem_rwsem;
1407 	void (*invalidate_range)(struct ib_umem *umem,
1408 				 unsigned long start, unsigned long end);
1409 
1410 	struct mmu_notifier	mn;
1411 	atomic_t		notifier_count;
1412 	/* A list of umems that don't have private mmu notifier counters yet. */
1413 	struct list_head	no_private_counters;
1414 	int                     odp_mrs_count;
1415 #endif
1416 };
1417 
1418 struct ib_uobject {
1419 	u64			user_handle;	/* handle given to us by userspace */
1420 	struct ib_ucontext     *context;	/* associated user context */
1421 	void		       *object;		/* containing object */
1422 	struct list_head	list;		/* link to context's list */
1423 	int			id;		/* index into kernel idr */
1424 	struct kref		ref;
1425 	struct rw_semaphore	mutex;		/* protects .live */
1426 	struct rcu_head		rcu;		/* kfree_rcu() overhead */
1427 	int			live;
1428 };
1429 
1430 struct ib_udata {
1431 	const void __user *inbuf;
1432 	void __user *outbuf;
1433 	size_t       inlen;
1434 	size_t       outlen;
1435 };
1436 
1437 struct ib_pd {
1438 	u32			local_dma_lkey;
1439 	u32			flags;
1440 	struct ib_device       *device;
1441 	struct ib_uobject      *uobject;
1442 	atomic_t          	usecnt; /* count all resources */
1443 
1444 	u32			unsafe_global_rkey;
1445 
1446 	/*
1447 	 * Implementation details of the RDMA core, don't use in drivers:
1448 	 */
1449 	struct ib_mr	       *__internal_mr;
1450 };
1451 
1452 struct ib_xrcd {
1453 	struct ib_device       *device;
1454 	atomic_t		usecnt; /* count all exposed resources */
1455 	struct inode	       *inode;
1456 
1457 	struct mutex		tgt_qp_mutex;
1458 	struct list_head	tgt_qp_list;
1459 };
1460 
1461 struct ib_ah {
1462 	struct ib_device	*device;
1463 	struct ib_pd		*pd;
1464 	struct ib_uobject	*uobject;
1465 };
1466 
1467 typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1468 
1469 enum ib_poll_context {
1470 	IB_POLL_DIRECT,		/* caller context, no hw completions */
1471 	IB_POLL_SOFTIRQ,	/* poll from softirq context */
1472 	IB_POLL_WORKQUEUE,	/* poll from workqueue */
1473 };
1474 
1475 struct ib_cq {
1476 	struct ib_device       *device;
1477 	struct ib_uobject      *uobject;
1478 	ib_comp_handler   	comp_handler;
1479 	void                  (*event_handler)(struct ib_event *, void *);
1480 	void                   *cq_context;
1481 	int               	cqe;
1482 	atomic_t          	usecnt; /* count number of work queues */
1483 	enum ib_poll_context	poll_ctx;
1484 	struct work_struct	work;
1485 };
1486 
1487 struct ib_srq {
1488 	struct ib_device       *device;
1489 	struct ib_pd	       *pd;
1490 	struct ib_uobject      *uobject;
1491 	void		      (*event_handler)(struct ib_event *, void *);
1492 	void		       *srq_context;
1493 	enum ib_srq_type	srq_type;
1494 	atomic_t		usecnt;
1495 
1496 	union {
1497 		struct {
1498 			struct ib_xrcd *xrcd;
1499 			struct ib_cq   *cq;
1500 			u32		srq_num;
1501 		} xrc;
1502 	} ext;
1503 };
1504 
1505 enum ib_wq_type {
1506 	IB_WQT_RQ
1507 };
1508 
1509 enum ib_wq_state {
1510 	IB_WQS_RESET,
1511 	IB_WQS_RDY,
1512 	IB_WQS_ERR
1513 };
1514 
1515 struct ib_wq {
1516 	struct ib_device       *device;
1517 	struct ib_uobject      *uobject;
1518 	void		    *wq_context;
1519 	void		    (*event_handler)(struct ib_event *, void *);
1520 	struct ib_pd	       *pd;
1521 	struct ib_cq	       *cq;
1522 	u32		wq_num;
1523 	enum ib_wq_state       state;
1524 	enum ib_wq_type	wq_type;
1525 	atomic_t		usecnt;
1526 };
1527 
1528 struct ib_wq_init_attr {
1529 	void		       *wq_context;
1530 	enum ib_wq_type	wq_type;
1531 	u32		max_wr;
1532 	u32		max_sge;
1533 	struct	ib_cq	       *cq;
1534 	void		    (*event_handler)(struct ib_event *, void *);
1535 };
1536 
1537 enum ib_wq_attr_mask {
1538 	IB_WQ_STATE	= 1 << 0,
1539 	IB_WQ_CUR_STATE	= 1 << 1,
1540 };
1541 
1542 struct ib_wq_attr {
1543 	enum	ib_wq_state	wq_state;
1544 	enum	ib_wq_state	curr_wq_state;
1545 };
1546 
1547 struct ib_rwq_ind_table {
1548 	struct ib_device	*device;
1549 	struct ib_uobject      *uobject;
1550 	atomic_t		usecnt;
1551 	u32		ind_tbl_num;
1552 	u32		log_ind_tbl_size;
1553 	struct ib_wq	**ind_tbl;
1554 };
1555 
1556 struct ib_rwq_ind_table_init_attr {
1557 	u32		log_ind_tbl_size;
1558 	/* Each entry is a pointer to Receive Work Queue */
1559 	struct ib_wq	**ind_tbl;
1560 };
1561 
1562 /*
1563  * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
1564  * @max_read_sge:  Maximum SGE elements per RDMA READ request.
1565  */
1566 struct ib_qp {
1567 	struct ib_device       *device;
1568 	struct ib_pd	       *pd;
1569 	struct ib_cq	       *send_cq;
1570 	struct ib_cq	       *recv_cq;
1571 	spinlock_t		mr_lock;
1572 	struct ib_srq	       *srq;
1573 	struct ib_xrcd	       *xrcd; /* XRC TGT QPs only */
1574 	struct list_head	xrcd_list;
1575 
1576 	/* count times opened, mcast attaches, flow attaches */
1577 	atomic_t		usecnt;
1578 	struct list_head	open_list;
1579 	struct ib_qp           *real_qp;
1580 	struct ib_uobject      *uobject;
1581 	void                  (*event_handler)(struct ib_event *, void *);
1582 	void		       *qp_context;
1583 	u32			qp_num;
1584 	u32			max_write_sge;
1585 	u32			max_read_sge;
1586 	enum ib_qp_type		qp_type;
1587 	struct ib_rwq_ind_table *rwq_ind_tbl;
1588 };
1589 
1590 struct ib_mr {
1591 	struct ib_device  *device;
1592 	struct ib_pd	  *pd;
1593 	u32		   lkey;
1594 	u32		   rkey;
1595 	u64		   iova;
1596 	u64		   length;
1597 	unsigned int	   page_size;
1598 	bool		   need_inval;
1599 	union {
1600 		struct ib_uobject	*uobject;	/* user */
1601 		struct list_head	qp_entry;	/* FR */
1602 	};
1603 };
1604 
1605 struct ib_mw {
1606 	struct ib_device	*device;
1607 	struct ib_pd		*pd;
1608 	struct ib_uobject	*uobject;
1609 	u32			rkey;
1610 	enum ib_mw_type         type;
1611 };
1612 
1613 struct ib_fmr {
1614 	struct ib_device	*device;
1615 	struct ib_pd		*pd;
1616 	struct list_head	list;
1617 	u32			lkey;
1618 	u32			rkey;
1619 };
1620 
1621 /* Supported steering options */
1622 enum ib_flow_attr_type {
1623 	/* steering according to rule specifications */
1624 	IB_FLOW_ATTR_NORMAL		= 0x0,
1625 	/* default unicast and multicast rule -
1626 	 * receive all Eth traffic which isn't steered to any QP
1627 	 */
1628 	IB_FLOW_ATTR_ALL_DEFAULT	= 0x1,
1629 	/* default multicast rule -
1630 	 * receive all Eth multicast traffic which isn't steered to any QP
1631 	 */
1632 	IB_FLOW_ATTR_MC_DEFAULT		= 0x2,
1633 	/* sniffer rule - receive all port traffic */
1634 	IB_FLOW_ATTR_SNIFFER		= 0x3
1635 };
1636 
1637 /* Supported steering header types */
1638 enum ib_flow_spec_type {
1639 	/* L2 headers*/
1640 	IB_FLOW_SPEC_ETH	= 0x20,
1641 	IB_FLOW_SPEC_IB		= 0x22,
1642 	/* L3 header*/
1643 	IB_FLOW_SPEC_IPV4	= 0x30,
1644 	IB_FLOW_SPEC_IPV6	= 0x31,
1645 	/* L4 headers*/
1646 	IB_FLOW_SPEC_TCP	= 0x40,
1647 	IB_FLOW_SPEC_UDP	= 0x41
1648 };
1649 #define IB_FLOW_SPEC_LAYER_MASK	0xF0
1650 #define IB_FLOW_SPEC_SUPPORT_LAYERS 4
1651 
1652 /* Flow steering rule priority is set according to it's domain.
1653  * Lower domain value means higher priority.
1654  */
1655 enum ib_flow_domain {
1656 	IB_FLOW_DOMAIN_USER,
1657 	IB_FLOW_DOMAIN_ETHTOOL,
1658 	IB_FLOW_DOMAIN_RFS,
1659 	IB_FLOW_DOMAIN_NIC,
1660 	IB_FLOW_DOMAIN_NUM /* Must be last */
1661 };
1662 
1663 enum ib_flow_flags {
1664 	IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
1665 	IB_FLOW_ATTR_FLAGS_RESERVED  = 1UL << 2  /* Must be last */
1666 };
1667 
1668 struct ib_flow_eth_filter {
1669 	u8	dst_mac[6];
1670 	u8	src_mac[6];
1671 	__be16	ether_type;
1672 	__be16	vlan_tag;
1673 	/* Must be last */
1674 	u8	real_sz[0];
1675 };
1676 
1677 struct ib_flow_spec_eth {
1678 	enum ib_flow_spec_type	  type;
1679 	u16			  size;
1680 	struct ib_flow_eth_filter val;
1681 	struct ib_flow_eth_filter mask;
1682 };
1683 
1684 struct ib_flow_ib_filter {
1685 	__be16 dlid;
1686 	__u8   sl;
1687 	/* Must be last */
1688 	u8	real_sz[0];
1689 };
1690 
1691 struct ib_flow_spec_ib {
1692 	enum ib_flow_spec_type	 type;
1693 	u16			 size;
1694 	struct ib_flow_ib_filter val;
1695 	struct ib_flow_ib_filter mask;
1696 };
1697 
1698 /* IPv4 header flags */
1699 enum ib_ipv4_flags {
1700 	IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */
1701 	IB_IPV4_MORE_FRAG = 0X4  /* For All fragmented packets except the
1702 				    last have this flag set */
1703 };
1704 
1705 struct ib_flow_ipv4_filter {
1706 	__be32	src_ip;
1707 	__be32	dst_ip;
1708 	u8	proto;
1709 	u8	tos;
1710 	u8	ttl;
1711 	u8	flags;
1712 	/* Must be last */
1713 	u8	real_sz[0];
1714 };
1715 
1716 struct ib_flow_spec_ipv4 {
1717 	enum ib_flow_spec_type	   type;
1718 	u16			   size;
1719 	struct ib_flow_ipv4_filter val;
1720 	struct ib_flow_ipv4_filter mask;
1721 };
1722 
1723 struct ib_flow_ipv6_filter {
1724 	u8	src_ip[16];
1725 	u8	dst_ip[16];
1726 	__be32	flow_label;
1727 	u8	next_hdr;
1728 	u8	traffic_class;
1729 	u8	hop_limit;
1730 	/* Must be last */
1731 	u8	real_sz[0];
1732 };
1733 
1734 struct ib_flow_spec_ipv6 {
1735 	enum ib_flow_spec_type	   type;
1736 	u16			   size;
1737 	struct ib_flow_ipv6_filter val;
1738 	struct ib_flow_ipv6_filter mask;
1739 };
1740 
1741 struct ib_flow_tcp_udp_filter {
1742 	__be16	dst_port;
1743 	__be16	src_port;
1744 	/* Must be last */
1745 	u8	real_sz[0];
1746 };
1747 
1748 struct ib_flow_spec_tcp_udp {
1749 	enum ib_flow_spec_type	      type;
1750 	u16			      size;
1751 	struct ib_flow_tcp_udp_filter val;
1752 	struct ib_flow_tcp_udp_filter mask;
1753 };
1754 
1755 union ib_flow_spec {
1756 	struct {
1757 		enum ib_flow_spec_type	type;
1758 		u16			size;
1759 	};
1760 	struct ib_flow_spec_eth		eth;
1761 	struct ib_flow_spec_ib		ib;
1762 	struct ib_flow_spec_ipv4        ipv4;
1763 	struct ib_flow_spec_tcp_udp	tcp_udp;
1764 	struct ib_flow_spec_ipv6        ipv6;
1765 };
1766 
1767 struct ib_flow_attr {
1768 	enum ib_flow_attr_type type;
1769 	u16	     size;
1770 	u16	     priority;
1771 	u32	     flags;
1772 	u8	     num_of_specs;
1773 	u8	     port;
1774 	/* Following are the optional layers according to user request
1775 	 * struct ib_flow_spec_xxx
1776 	 * struct ib_flow_spec_yyy
1777 	 */
1778 };
1779 
1780 struct ib_flow {
1781 	struct ib_qp		*qp;
1782 	struct ib_uobject	*uobject;
1783 };
1784 
1785 struct ib_mad_hdr;
1786 struct ib_grh;
1787 
1788 enum ib_process_mad_flags {
1789 	IB_MAD_IGNORE_MKEY	= 1,
1790 	IB_MAD_IGNORE_BKEY	= 2,
1791 	IB_MAD_IGNORE_ALL	= IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1792 };
1793 
1794 enum ib_mad_result {
1795 	IB_MAD_RESULT_FAILURE  = 0,      /* (!SUCCESS is the important flag) */
1796 	IB_MAD_RESULT_SUCCESS  = 1 << 0, /* MAD was successfully processed   */
1797 	IB_MAD_RESULT_REPLY    = 1 << 1, /* Reply packet needs to be sent    */
1798 	IB_MAD_RESULT_CONSUMED = 1 << 2  /* Packet consumed: stop processing */
1799 };
1800 
1801 #define IB_DEVICE_NAME_MAX 64
1802 
1803 struct ib_cache {
1804 	rwlock_t                lock;
1805 	struct ib_event_handler event_handler;
1806 	struct ib_pkey_cache  **pkey_cache;
1807 	struct ib_gid_table   **gid_cache;
1808 	u8                     *lmc_cache;
1809 };
1810 
1811 struct ib_dma_mapping_ops {
1812 	int		(*mapping_error)(struct ib_device *dev,
1813 					 u64 dma_addr);
1814 	u64		(*map_single)(struct ib_device *dev,
1815 				      void *ptr, size_t size,
1816 				      enum dma_data_direction direction);
1817 	void		(*unmap_single)(struct ib_device *dev,
1818 					u64 addr, size_t size,
1819 					enum dma_data_direction direction);
1820 	u64		(*map_page)(struct ib_device *dev,
1821 				    struct page *page, unsigned long offset,
1822 				    size_t size,
1823 				    enum dma_data_direction direction);
1824 	void		(*unmap_page)(struct ib_device *dev,
1825 				      u64 addr, size_t size,
1826 				      enum dma_data_direction direction);
1827 	int		(*map_sg)(struct ib_device *dev,
1828 				  struct scatterlist *sg, int nents,
1829 				  enum dma_data_direction direction);
1830 	void		(*unmap_sg)(struct ib_device *dev,
1831 				    struct scatterlist *sg, int nents,
1832 				    enum dma_data_direction direction);
1833 	int		(*map_sg_attrs)(struct ib_device *dev,
1834 					struct scatterlist *sg, int nents,
1835 					enum dma_data_direction direction,
1836 					struct dma_attrs *attrs);
1837 	void		(*unmap_sg_attrs)(struct ib_device *dev,
1838 					  struct scatterlist *sg, int nents,
1839 					  enum dma_data_direction direction,
1840 					  struct dma_attrs *attrs);
1841 	void		(*sync_single_for_cpu)(struct ib_device *dev,
1842 					       u64 dma_handle,
1843 					       size_t size,
1844 					       enum dma_data_direction dir);
1845 	void		(*sync_single_for_device)(struct ib_device *dev,
1846 						  u64 dma_handle,
1847 						  size_t size,
1848 						  enum dma_data_direction dir);
1849 	void		*(*alloc_coherent)(struct ib_device *dev,
1850 					   size_t size,
1851 					   u64 *dma_handle,
1852 					   gfp_t flag);
1853 	void		(*free_coherent)(struct ib_device *dev,
1854 					 size_t size, void *cpu_addr,
1855 					 u64 dma_handle);
1856 };
1857 
1858 struct iw_cm_verbs;
1859 
1860 struct ib_port_immutable {
1861 	int                           pkey_tbl_len;
1862 	int                           gid_tbl_len;
1863 	u32                           core_cap_flags;
1864 	u32                           max_mad_size;
1865 };
1866 
1867 struct ib_device {
1868 	struct device                *dma_device;
1869 
1870 	char                          name[IB_DEVICE_NAME_MAX];
1871 
1872 	struct list_head              event_handler_list;
1873 	spinlock_t                    event_handler_lock;
1874 
1875 	spinlock_t                    client_data_lock;
1876 	struct list_head              core_list;
1877 	/* Access to the client_data_list is protected by the client_data_lock
1878 	 * spinlock and the lists_rwsem read-write semaphore */
1879 	struct list_head              client_data_list;
1880 
1881 	struct ib_cache               cache;
1882 	/**
1883 	 * port_immutable is indexed by port number
1884 	 */
1885 	struct ib_port_immutable     *port_immutable;
1886 
1887 	int			      num_comp_vectors;
1888 
1889 	struct iw_cm_verbs	     *iwcm;
1890 
1891 	/**
1892 	 * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
1893 	 *   driver initialized data.  The struct is kfree()'ed by the sysfs
1894 	 *   core when the device is removed.  A lifespan of -1 in the return
1895 	 *   struct tells the core to set a default lifespan.
1896 	 */
1897 	struct rdma_hw_stats      *(*alloc_hw_stats)(struct ib_device *device,
1898 						     u8 port_num);
1899 	/**
1900 	 * get_hw_stats - Fill in the counter value(s) in the stats struct.
1901 	 * @index - The index in the value array we wish to have updated, or
1902 	 *   num_counters if we want all stats updated
1903 	 * Return codes -
1904 	 *   < 0 - Error, no counters updated
1905 	 *   index - Updated the single counter pointed to by index
1906 	 *   num_counters - Updated all counters (will reset the timestamp
1907 	 *     and prevent further calls for lifespan milliseconds)
1908 	 * Drivers are allowed to update all counters in leiu of just the
1909 	 *   one given in index at their option
1910 	 */
1911 	int		           (*get_hw_stats)(struct ib_device *device,
1912 						   struct rdma_hw_stats *stats,
1913 						   u8 port, int index);
1914 	int		           (*query_device)(struct ib_device *device,
1915 						   struct ib_device_attr *device_attr,
1916 						   struct ib_udata *udata);
1917 	int		           (*query_port)(struct ib_device *device,
1918 						 u8 port_num,
1919 						 struct ib_port_attr *port_attr);
1920 	enum rdma_link_layer	   (*get_link_layer)(struct ib_device *device,
1921 						     u8 port_num);
1922 	/* When calling get_netdev, the HW vendor's driver should return the
1923 	 * net device of device @device at port @port_num or NULL if such
1924 	 * a net device doesn't exist. The vendor driver should call dev_hold
1925 	 * on this net device. The HW vendor's device driver must guarantee
1926 	 * that this function returns NULL before the net device reaches
1927 	 * NETDEV_UNREGISTER_FINAL state.
1928 	 */
1929 	struct ifnet		  *(*get_netdev)(struct ib_device *device,
1930 						 u8 port_num);
1931 	int		           (*query_gid)(struct ib_device *device,
1932 						u8 port_num, int index,
1933 						union ib_gid *gid);
1934 	/* When calling add_gid, the HW vendor's driver should
1935 	 * add the gid of device @device at gid index @index of
1936 	 * port @port_num to be @gid. Meta-info of that gid (for example,
1937 	 * the network device related to this gid is available
1938 	 * at @attr. @context allows the HW vendor driver to store extra
1939 	 * information together with a GID entry. The HW vendor may allocate
1940 	 * memory to contain this information and store it in @context when a
1941 	 * new GID entry is written to. Params are consistent until the next
1942 	 * call of add_gid or delete_gid. The function should return 0 on
1943 	 * success or error otherwise. The function could be called
1944 	 * concurrently for different ports. This function is only called
1945 	 * when roce_gid_table is used.
1946 	 */
1947 	int		           (*add_gid)(struct ib_device *device,
1948 					      u8 port_num,
1949 					      unsigned int index,
1950 					      const union ib_gid *gid,
1951 					      const struct ib_gid_attr *attr,
1952 					      void **context);
1953 	/* When calling del_gid, the HW vendor's driver should delete the
1954 	 * gid of device @device at gid index @index of port @port_num.
1955 	 * Upon the deletion of a GID entry, the HW vendor must free any
1956 	 * allocated memory. The caller will clear @context afterwards.
1957 	 * This function is only called when roce_gid_table is used.
1958 	 */
1959 	int		           (*del_gid)(struct ib_device *device,
1960 					      u8 port_num,
1961 					      unsigned int index,
1962 					      void **context);
1963 	int		           (*query_pkey)(struct ib_device *device,
1964 						 u8 port_num, u16 index, u16 *pkey);
1965 	int		           (*modify_device)(struct ib_device *device,
1966 						    int device_modify_mask,
1967 						    struct ib_device_modify *device_modify);
1968 	int		           (*modify_port)(struct ib_device *device,
1969 						  u8 port_num, int port_modify_mask,
1970 						  struct ib_port_modify *port_modify);
1971 	struct ib_ucontext *       (*alloc_ucontext)(struct ib_device *device,
1972 						     struct ib_udata *udata);
1973 	int                        (*dealloc_ucontext)(struct ib_ucontext *context);
1974 	int                        (*mmap)(struct ib_ucontext *context,
1975 					   struct vm_area_struct *vma);
1976 	struct ib_pd *             (*alloc_pd)(struct ib_device *device,
1977 					       struct ib_ucontext *context,
1978 					       struct ib_udata *udata);
1979 	int                        (*dealloc_pd)(struct ib_pd *pd);
1980 	struct ib_ah *             (*create_ah)(struct ib_pd *pd,
1981 						struct ib_ah_attr *ah_attr,
1982 						struct ib_udata *udata);
1983 	int                        (*modify_ah)(struct ib_ah *ah,
1984 						struct ib_ah_attr *ah_attr);
1985 	int                        (*query_ah)(struct ib_ah *ah,
1986 					       struct ib_ah_attr *ah_attr);
1987 	int                        (*destroy_ah)(struct ib_ah *ah);
1988 	struct ib_srq *            (*create_srq)(struct ib_pd *pd,
1989 						 struct ib_srq_init_attr *srq_init_attr,
1990 						 struct ib_udata *udata);
1991 	int                        (*modify_srq)(struct ib_srq *srq,
1992 						 struct ib_srq_attr *srq_attr,
1993 						 enum ib_srq_attr_mask srq_attr_mask,
1994 						 struct ib_udata *udata);
1995 	int                        (*query_srq)(struct ib_srq *srq,
1996 						struct ib_srq_attr *srq_attr);
1997 	int                        (*destroy_srq)(struct ib_srq *srq);
1998 	int                        (*post_srq_recv)(struct ib_srq *srq,
1999 						    const struct ib_recv_wr *recv_wr,
2000 						    const struct ib_recv_wr **bad_recv_wr);
2001 	struct ib_qp *             (*create_qp)(struct ib_pd *pd,
2002 						struct ib_qp_init_attr *qp_init_attr,
2003 						struct ib_udata *udata);
2004 	int                        (*modify_qp)(struct ib_qp *qp,
2005 						struct ib_qp_attr *qp_attr,
2006 						int qp_attr_mask,
2007 						struct ib_udata *udata);
2008 	int                        (*query_qp)(struct ib_qp *qp,
2009 					       struct ib_qp_attr *qp_attr,
2010 					       int qp_attr_mask,
2011 					       struct ib_qp_init_attr *qp_init_attr);
2012 	int                        (*destroy_qp)(struct ib_qp *qp);
2013 	int                        (*post_send)(struct ib_qp *qp,
2014 						const struct ib_send_wr *send_wr,
2015 						const struct ib_send_wr **bad_send_wr);
2016 	int                        (*post_recv)(struct ib_qp *qp,
2017 						const struct ib_recv_wr *recv_wr,
2018 						const struct ib_recv_wr **bad_recv_wr);
2019 	struct ib_cq *             (*create_cq)(struct ib_device *device,
2020 						const struct ib_cq_init_attr *attr,
2021 						struct ib_ucontext *context,
2022 						struct ib_udata *udata);
2023 	int                        (*modify_cq)(struct ib_cq *cq, u16 cq_count,
2024 						u16 cq_period);
2025 	int                        (*destroy_cq)(struct ib_cq *cq);
2026 	int                        (*resize_cq)(struct ib_cq *cq, int cqe,
2027 						struct ib_udata *udata);
2028 	int                        (*poll_cq)(struct ib_cq *cq, int num_entries,
2029 					      struct ib_wc *wc);
2030 	int                        (*peek_cq)(struct ib_cq *cq, int wc_cnt);
2031 	int                        (*req_notify_cq)(struct ib_cq *cq,
2032 						    enum ib_cq_notify_flags flags);
2033 	int                        (*req_ncomp_notif)(struct ib_cq *cq,
2034 						      int wc_cnt);
2035 	struct ib_mr *             (*get_dma_mr)(struct ib_pd *pd,
2036 						 int mr_access_flags);
2037 	struct ib_mr *             (*reg_user_mr)(struct ib_pd *pd,
2038 						  u64 start, u64 length,
2039 						  u64 virt_addr,
2040 						  int mr_access_flags,
2041 						  struct ib_udata *udata);
2042 	int			   (*rereg_user_mr)(struct ib_mr *mr,
2043 						    int flags,
2044 						    u64 start, u64 length,
2045 						    u64 virt_addr,
2046 						    int mr_access_flags,
2047 						    struct ib_pd *pd,
2048 						    struct ib_udata *udata);
2049 	int                        (*dereg_mr)(struct ib_mr *mr);
2050 	struct ib_mr *		   (*alloc_mr)(struct ib_pd *pd,
2051 					       enum ib_mr_type mr_type,
2052 					       u32 max_num_sg);
2053 	int                        (*map_mr_sg)(struct ib_mr *mr,
2054 						struct scatterlist *sg,
2055 						int sg_nents,
2056 						unsigned int *sg_offset);
2057 	struct ib_mw *             (*alloc_mw)(struct ib_pd *pd,
2058 					       enum ib_mw_type type,
2059 					       struct ib_udata *udata);
2060 	int                        (*dealloc_mw)(struct ib_mw *mw);
2061 	struct ib_fmr *	           (*alloc_fmr)(struct ib_pd *pd,
2062 						int mr_access_flags,
2063 						struct ib_fmr_attr *fmr_attr);
2064 	int		           (*map_phys_fmr)(struct ib_fmr *fmr,
2065 						   u64 *page_list, int list_len,
2066 						   u64 iova);
2067 	int		           (*unmap_fmr)(struct list_head *fmr_list);
2068 	int		           (*dealloc_fmr)(struct ib_fmr *fmr);
2069 	int                        (*attach_mcast)(struct ib_qp *qp,
2070 						   union ib_gid *gid,
2071 						   u16 lid);
2072 	int                        (*detach_mcast)(struct ib_qp *qp,
2073 						   union ib_gid *gid,
2074 						   u16 lid);
2075 	int                        (*process_mad)(struct ib_device *device,
2076 						  int process_mad_flags,
2077 						  u8 port_num,
2078 						  const struct ib_wc *in_wc,
2079 						  const struct ib_grh *in_grh,
2080 						  const struct ib_mad_hdr *in_mad,
2081 						  size_t in_mad_size,
2082 						  struct ib_mad_hdr *out_mad,
2083 						  size_t *out_mad_size,
2084 						  u16 *out_mad_pkey_index);
2085 	struct ib_xrcd *	   (*alloc_xrcd)(struct ib_device *device,
2086 						 struct ib_ucontext *ucontext,
2087 						 struct ib_udata *udata);
2088 	int			   (*dealloc_xrcd)(struct ib_xrcd *xrcd);
2089 	struct ib_flow *	   (*create_flow)(struct ib_qp *qp,
2090 						  struct ib_flow_attr
2091 						  *flow_attr,
2092 						  int domain);
2093 	int			   (*destroy_flow)(struct ib_flow *flow_id);
2094 	int			   (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
2095 						      struct ib_mr_status *mr_status);
2096 	void			   (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
2097 	void			   (*drain_rq)(struct ib_qp *qp);
2098 	void			   (*drain_sq)(struct ib_qp *qp);
2099 	int			   (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
2100 							int state);
2101 	int			   (*get_vf_config)(struct ib_device *device, int vf, u8 port,
2102 						   struct ifla_vf_info *ivf);
2103 	int			   (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
2104 						   struct ifla_vf_stats *stats);
2105 	int			   (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
2106 						  int type);
2107 	struct ib_wq *		   (*create_wq)(struct ib_pd *pd,
2108 						struct ib_wq_init_attr *init_attr,
2109 						struct ib_udata *udata);
2110 	int			   (*destroy_wq)(struct ib_wq *wq);
2111 	int			   (*modify_wq)(struct ib_wq *wq,
2112 						struct ib_wq_attr *attr,
2113 						u32 wq_attr_mask,
2114 						struct ib_udata *udata);
2115 	struct ib_rwq_ind_table *  (*create_rwq_ind_table)(struct ib_device *device,
2116 							   struct ib_rwq_ind_table_init_attr *init_attr,
2117 							   struct ib_udata *udata);
2118 	int                        (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
2119 	struct ib_dma_mapping_ops   *dma_ops;
2120 
2121 	struct module               *owner;
2122 	struct device                dev;
2123 	struct kobject               *ports_parent;
2124 	struct list_head             port_list;
2125 
2126 	enum {
2127 		IB_DEV_UNINITIALIZED,
2128 		IB_DEV_REGISTERED,
2129 		IB_DEV_UNREGISTERED
2130 	}                            reg_state;
2131 
2132 	int			     uverbs_abi_ver;
2133 	u64			     uverbs_cmd_mask;
2134 	u64			     uverbs_ex_cmd_mask;
2135 
2136 	char			     node_desc[IB_DEVICE_NODE_DESC_MAX];
2137 	__be64			     node_guid;
2138 	u32			     local_dma_lkey;
2139 	u16                          is_switch:1;
2140 	u8                           node_type;
2141 	u8                           phys_port_cnt;
2142 	struct ib_device_attr        attrs;
2143 	struct attribute_group	     *hw_stats_ag;
2144 	struct rdma_hw_stats         *hw_stats;
2145 
2146 	/**
2147 	 * The following mandatory functions are used only at device
2148 	 * registration.  Keep functions such as these at the end of this
2149 	 * structure to avoid cache line misses when accessing struct ib_device
2150 	 * in fast paths.
2151 	 */
2152 	int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
2153 	void (*get_dev_fw_str)(struct ib_device *, char *str, size_t str_len);
2154 };
2155 
2156 struct ib_client {
2157 	char  *name;
2158 	void (*add)   (struct ib_device *);
2159 	void (*remove)(struct ib_device *, void *client_data);
2160 
2161 	/* Returns the net_dev belonging to this ib_client and matching the
2162 	 * given parameters.
2163 	 * @dev:	 An RDMA device that the net_dev use for communication.
2164 	 * @port:	 A physical port number on the RDMA device.
2165 	 * @pkey:	 P_Key that the net_dev uses if applicable.
2166 	 * @gid:	 A GID that the net_dev uses to communicate.
2167 	 * @addr:	 An IP address the net_dev is configured with.
2168 	 * @client_data: The device's client data set by ib_set_client_data().
2169 	 *
2170 	 * An ib_client that implements a net_dev on top of RDMA devices
2171 	 * (such as IP over IB) should implement this callback, allowing the
2172 	 * rdma_cm module to find the right net_dev for a given request.
2173 	 *
2174 	 * The caller is responsible for calling dev_put on the returned
2175 	 * netdev. */
2176 	struct ifnet *(*get_net_dev_by_params)(
2177 			struct ib_device *dev,
2178 			u8 port,
2179 			u16 pkey,
2180 			const union ib_gid *gid,
2181 			const struct sockaddr *addr,
2182 			void *client_data);
2183 	struct list_head list;
2184 };
2185 
2186 struct ib_device *ib_alloc_device(size_t size);
2187 void ib_dealloc_device(struct ib_device *device);
2188 
2189 void ib_get_device_fw_str(struct ib_device *device, char *str, size_t str_len);
2190 
2191 int ib_register_device(struct ib_device *device,
2192 		       int (*port_callback)(struct ib_device *,
2193 					    u8, struct kobject *));
2194 void ib_unregister_device(struct ib_device *device);
2195 
2196 int ib_register_client   (struct ib_client *client);
2197 void ib_unregister_client(struct ib_client *client);
2198 
2199 void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
2200 void  ib_set_client_data(struct ib_device *device, struct ib_client *client,
2201 			 void *data);
2202 
ib_copy_from_udata(void * dest,struct ib_udata * udata,size_t len)2203 static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
2204 {
2205 	return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
2206 }
2207 
ib_copy_to_udata(struct ib_udata * udata,void * src,size_t len)2208 static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
2209 {
2210 	return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
2211 }
2212 
ib_is_udata_cleared(struct ib_udata * udata,size_t offset,size_t len)2213 static inline bool ib_is_udata_cleared(struct ib_udata *udata,
2214 				       size_t offset,
2215 				       size_t len)
2216 {
2217 	const void __user *p = (const char __user *)udata->inbuf + offset;
2218 	bool ret;
2219 	u8 *buf;
2220 
2221 	if (len > USHRT_MAX)
2222 		return false;
2223 
2224 	buf = memdup_user(p, len);
2225 	if (IS_ERR(buf))
2226 		return false;
2227 
2228 	ret = !memchr_inv(buf, 0, len);
2229 	kfree(buf);
2230 	return ret;
2231 }
2232 
2233 /**
2234  * ib_is_destroy_retryable - Check whether the uobject destruction
2235  * is retryable.
2236  * @ret: The initial destruction return code
2237  * @why: remove reason
2238  * @uobj: The uobject that is destroyed
2239  *
2240  * This function is a helper function that IB layer and low-level drivers
2241  * can use to consider whether the destruction of the given uobject is
2242  * retry-able.
2243  * It checks the original return code, if it wasn't success the destruction
2244  * is retryable according to the ucontext state (i.e. cleanup_retryable) and
2245  * the remove reason. (i.e. why).
2246  * Must be called with the object locked for destroy.
2247  */
ib_is_destroy_retryable(int ret,enum rdma_remove_reason why,struct ib_uobject * uobj)2248 static inline bool ib_is_destroy_retryable(int ret, enum rdma_remove_reason why,
2249 					   struct ib_uobject *uobj)
2250 {
2251 	return ret && (why == RDMA_REMOVE_DESTROY ||
2252 		       uobj->context->cleanup_retryable);
2253 }
2254 
2255 /**
2256  * ib_destroy_usecnt - Called during destruction to check the usecnt
2257  * @usecnt: The usecnt atomic
2258  * @why: remove reason
2259  * @uobj: The uobject that is destroyed
2260  *
2261  * Non-zero usecnts will block destruction unless destruction was triggered by
2262  * a ucontext cleanup.
2263  */
ib_destroy_usecnt(atomic_t * usecnt,enum rdma_remove_reason why,struct ib_uobject * uobj)2264 static inline int ib_destroy_usecnt(atomic_t *usecnt,
2265 				    enum rdma_remove_reason why,
2266 				    struct ib_uobject *uobj)
2267 {
2268 	if (atomic_read(usecnt) && ib_is_destroy_retryable(-EBUSY, why, uobj))
2269 		return -EBUSY;
2270 	return 0;
2271 }
2272 
2273 /**
2274  * ib_modify_qp_is_ok - Check that the supplied attribute mask
2275  * contains all required attributes and no attributes not allowed for
2276  * the given QP state transition.
2277  * @cur_state: Current QP state
2278  * @next_state: Next QP state
2279  * @type: QP type
2280  * @mask: Mask of supplied QP attributes
2281  *
2282  * This function is a helper function that a low-level driver's
2283  * modify_qp method can use to validate the consumer's input.  It
2284  * checks that cur_state and next_state are valid QP states, that a
2285  * transition from cur_state to next_state is allowed by the IB spec,
2286  * and that the attribute mask supplied is allowed for the transition.
2287  */
2288 bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
2289 			enum ib_qp_type type, enum ib_qp_attr_mask mask);
2290 
2291 int ib_register_event_handler  (struct ib_event_handler *event_handler);
2292 int ib_unregister_event_handler(struct ib_event_handler *event_handler);
2293 void ib_dispatch_event(struct ib_event *event);
2294 
2295 int ib_query_port(struct ib_device *device,
2296 		  u8 port_num, struct ib_port_attr *port_attr);
2297 
2298 enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
2299 					       u8 port_num);
2300 
2301 /**
2302  * rdma_cap_ib_switch - Check if the device is IB switch
2303  * @device: Device to check
2304  *
2305  * Device driver is responsible for setting is_switch bit on
2306  * in ib_device structure at init time.
2307  *
2308  * Return: true if the device is IB switch.
2309  */
rdma_cap_ib_switch(const struct ib_device * device)2310 static inline bool rdma_cap_ib_switch(const struct ib_device *device)
2311 {
2312 	return device->is_switch;
2313 }
2314 
2315 /**
2316  * rdma_start_port - Return the first valid port number for the device
2317  * specified
2318  *
2319  * @device: Device to be checked
2320  *
2321  * Return start port number
2322  */
rdma_start_port(const struct ib_device * device)2323 static inline u8 rdma_start_port(const struct ib_device *device)
2324 {
2325 	return rdma_cap_ib_switch(device) ? 0 : 1;
2326 }
2327 
2328 /**
2329  * rdma_end_port - Return the last valid port number for the device
2330  * specified
2331  *
2332  * @device: Device to be checked
2333  *
2334  * Return last port number
2335  */
rdma_end_port(const struct ib_device * device)2336 static inline u8 rdma_end_port(const struct ib_device *device)
2337 {
2338 	return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
2339 }
2340 
rdma_is_port_valid(const struct ib_device * device,unsigned int port)2341 static inline int rdma_is_port_valid(const struct ib_device *device,
2342 				     unsigned int port)
2343 {
2344 	return (port >= rdma_start_port(device) &&
2345 		port <= rdma_end_port(device));
2346 }
2347 
rdma_protocol_ib(const struct ib_device * device,u8 port_num)2348 static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
2349 {
2350 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
2351 }
2352 
rdma_protocol_roce(const struct ib_device * device,u8 port_num)2353 static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
2354 {
2355 	return device->port_immutable[port_num].core_cap_flags &
2356 		(RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
2357 }
2358 
rdma_protocol_roce_udp_encap(const struct ib_device * device,u8 port_num)2359 static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
2360 {
2361 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
2362 }
2363 
rdma_protocol_roce_eth_encap(const struct ib_device * device,u8 port_num)2364 static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
2365 {
2366 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
2367 }
2368 
rdma_protocol_iwarp(const struct ib_device * device,u8 port_num)2369 static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
2370 {
2371 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
2372 }
2373 
rdma_ib_or_roce(const struct ib_device * device,u8 port_num)2374 static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
2375 {
2376 	return rdma_protocol_ib(device, port_num) ||
2377 		rdma_protocol_roce(device, port_num);
2378 }
2379 
2380 /**
2381  * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
2382  * Management Datagrams.
2383  * @device: Device to check
2384  * @port_num: Port number to check
2385  *
2386  * Management Datagrams (MAD) are a required part of the InfiniBand
2387  * specification and are supported on all InfiniBand devices.  A slightly
2388  * extended version are also supported on OPA interfaces.
2389  *
2390  * Return: true if the port supports sending/receiving of MAD packets.
2391  */
rdma_cap_ib_mad(const struct ib_device * device,u8 port_num)2392 static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
2393 {
2394 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
2395 }
2396 
2397 /**
2398  * rdma_cap_opa_mad - Check if the port of device provides support for OPA
2399  * Management Datagrams.
2400  * @device: Device to check
2401  * @port_num: Port number to check
2402  *
2403  * Intel OmniPath devices extend and/or replace the InfiniBand Management
2404  * datagrams with their own versions.  These OPA MADs share many but not all of
2405  * the characteristics of InfiniBand MADs.
2406  *
2407  * OPA MADs differ in the following ways:
2408  *
2409  *    1) MADs are variable size up to 2K
2410  *       IBTA defined MADs remain fixed at 256 bytes
2411  *    2) OPA SMPs must carry valid PKeys
2412  *    3) OPA SMP packets are a different format
2413  *
2414  * Return: true if the port supports OPA MAD packet formats.
2415  */
rdma_cap_opa_mad(struct ib_device * device,u8 port_num)2416 static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
2417 {
2418 	return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD)
2419 		== RDMA_CORE_CAP_OPA_MAD;
2420 }
2421 
2422 /**
2423  * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
2424  * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
2425  * @device: Device to check
2426  * @port_num: Port number to check
2427  *
2428  * Each InfiniBand node is required to provide a Subnet Management Agent
2429  * that the subnet manager can access.  Prior to the fabric being fully
2430  * configured by the subnet manager, the SMA is accessed via a well known
2431  * interface called the Subnet Management Interface (SMI).  This interface
2432  * uses directed route packets to communicate with the SM to get around the
2433  * chicken and egg problem of the SM needing to know what's on the fabric
2434  * in order to configure the fabric, and needing to configure the fabric in
2435  * order to send packets to the devices on the fabric.  These directed
2436  * route packets do not need the fabric fully configured in order to reach
2437  * their destination.  The SMI is the only method allowed to send
2438  * directed route packets on an InfiniBand fabric.
2439  *
2440  * Return: true if the port provides an SMI.
2441  */
rdma_cap_ib_smi(const struct ib_device * device,u8 port_num)2442 static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
2443 {
2444 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
2445 }
2446 
2447 /**
2448  * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
2449  * Communication Manager.
2450  * @device: Device to check
2451  * @port_num: Port number to check
2452  *
2453  * The InfiniBand Communication Manager is one of many pre-defined General
2454  * Service Agents (GSA) that are accessed via the General Service
2455  * Interface (GSI).  It's role is to facilitate establishment of connections
2456  * between nodes as well as other management related tasks for established
2457  * connections.
2458  *
2459  * Return: true if the port supports an IB CM (this does not guarantee that
2460  * a CM is actually running however).
2461  */
rdma_cap_ib_cm(const struct ib_device * device,u8 port_num)2462 static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
2463 {
2464 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
2465 }
2466 
2467 /**
2468  * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
2469  * Communication Manager.
2470  * @device: Device to check
2471  * @port_num: Port number to check
2472  *
2473  * Similar to above, but specific to iWARP connections which have a different
2474  * managment protocol than InfiniBand.
2475  *
2476  * Return: true if the port supports an iWARP CM (this does not guarantee that
2477  * a CM is actually running however).
2478  */
rdma_cap_iw_cm(const struct ib_device * device,u8 port_num)2479 static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
2480 {
2481 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
2482 }
2483 
2484 /**
2485  * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
2486  * Subnet Administration.
2487  * @device: Device to check
2488  * @port_num: Port number to check
2489  *
2490  * An InfiniBand Subnet Administration (SA) service is a pre-defined General
2491  * Service Agent (GSA) provided by the Subnet Manager (SM).  On InfiniBand
2492  * fabrics, devices should resolve routes to other hosts by contacting the
2493  * SA to query the proper route.
2494  *
2495  * Return: true if the port should act as a client to the fabric Subnet
2496  * Administration interface.  This does not imply that the SA service is
2497  * running locally.
2498  */
rdma_cap_ib_sa(const struct ib_device * device,u8 port_num)2499 static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
2500 {
2501 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
2502 }
2503 
2504 /**
2505  * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
2506  * Multicast.
2507  * @device: Device to check
2508  * @port_num: Port number to check
2509  *
2510  * InfiniBand multicast registration is more complex than normal IPv4 or
2511  * IPv6 multicast registration.  Each Host Channel Adapter must register
2512  * with the Subnet Manager when it wishes to join a multicast group.  It
2513  * should do so only once regardless of how many queue pairs it subscribes
2514  * to this group.  And it should leave the group only after all queue pairs
2515  * attached to the group have been detached.
2516  *
2517  * Return: true if the port must undertake the additional adminstrative
2518  * overhead of registering/unregistering with the SM and tracking of the
2519  * total number of queue pairs attached to the multicast group.
2520  */
rdma_cap_ib_mcast(const struct ib_device * device,u8 port_num)2521 static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
2522 {
2523 	return rdma_cap_ib_sa(device, port_num);
2524 }
2525 
2526 /**
2527  * rdma_cap_af_ib - Check if the port of device has the capability
2528  * Native Infiniband Address.
2529  * @device: Device to check
2530  * @port_num: Port number to check
2531  *
2532  * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
2533  * GID.  RoCE uses a different mechanism, but still generates a GID via
2534  * a prescribed mechanism and port specific data.
2535  *
2536  * Return: true if the port uses a GID address to identify devices on the
2537  * network.
2538  */
rdma_cap_af_ib(const struct ib_device * device,u8 port_num)2539 static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
2540 {
2541 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
2542 }
2543 
2544 /**
2545  * rdma_cap_eth_ah - Check if the port of device has the capability
2546  * Ethernet Address Handle.
2547  * @device: Device to check
2548  * @port_num: Port number to check
2549  *
2550  * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
2551  * to fabricate GIDs over Ethernet/IP specific addresses native to the
2552  * port.  Normally, packet headers are generated by the sending host
2553  * adapter, but when sending connectionless datagrams, we must manually
2554  * inject the proper headers for the fabric we are communicating over.
2555  *
2556  * Return: true if we are running as a RoCE port and must force the
2557  * addition of a Global Route Header built from our Ethernet Address
2558  * Handle into our header list for connectionless packets.
2559  */
rdma_cap_eth_ah(const struct ib_device * device,u8 port_num)2560 static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
2561 {
2562 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
2563 }
2564 
2565 /**
2566  * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
2567  *
2568  * @device: Device
2569  * @port_num: Port number
2570  *
2571  * This MAD size includes the MAD headers and MAD payload.  No other headers
2572  * are included.
2573  *
2574  * Return the max MAD size required by the Port.  Will return 0 if the port
2575  * does not support MADs
2576  */
rdma_max_mad_size(const struct ib_device * device,u8 port_num)2577 static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
2578 {
2579 	return device->port_immutable[port_num].max_mad_size;
2580 }
2581 
2582 /**
2583  * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
2584  * @device: Device to check
2585  * @port_num: Port number to check
2586  *
2587  * RoCE GID table mechanism manages the various GIDs for a device.
2588  *
2589  * NOTE: if allocating the port's GID table has failed, this call will still
2590  * return true, but any RoCE GID table API will fail.
2591  *
2592  * Return: true if the port uses RoCE GID table mechanism in order to manage
2593  * its GIDs.
2594  */
rdma_cap_roce_gid_table(const struct ib_device * device,u8 port_num)2595 static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
2596 					   u8 port_num)
2597 {
2598 	return rdma_protocol_roce(device, port_num) &&
2599 		device->add_gid && device->del_gid;
2600 }
2601 
2602 /*
2603  * Check if the device supports READ W/ INVALIDATE.
2604  */
rdma_cap_read_inv(struct ib_device * dev,u32 port_num)2605 static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
2606 {
2607 	/*
2608 	 * iWarp drivers must support READ W/ INVALIDATE.  No other protocol
2609 	 * has support for it yet.
2610 	 */
2611 	return rdma_protocol_iwarp(dev, port_num);
2612 }
2613 
2614 int ib_query_gid(struct ib_device *device,
2615 		 u8 port_num, int index, union ib_gid *gid,
2616 		 struct ib_gid_attr *attr);
2617 
2618 int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
2619 			 int state);
2620 int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
2621 		     struct ifla_vf_info *info);
2622 int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
2623 		    struct ifla_vf_stats *stats);
2624 int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
2625 		   int type);
2626 
2627 int ib_query_pkey(struct ib_device *device,
2628 		  u8 port_num, u16 index, u16 *pkey);
2629 
2630 int ib_modify_device(struct ib_device *device,
2631 		     int device_modify_mask,
2632 		     struct ib_device_modify *device_modify);
2633 
2634 int ib_modify_port(struct ib_device *device,
2635 		   u8 port_num, int port_modify_mask,
2636 		   struct ib_port_modify *port_modify);
2637 
2638 int ib_find_gid(struct ib_device *device, union ib_gid *gid,
2639 		enum ib_gid_type gid_type, struct ifnet *ndev,
2640 		u8 *port_num, u16 *index);
2641 
2642 int ib_find_pkey(struct ib_device *device,
2643 		 u8 port_num, u16 pkey, u16 *index);
2644 
2645 enum ib_pd_flags {
2646 	/*
2647 	 * Create a memory registration for all memory in the system and place
2648 	 * the rkey for it into pd->unsafe_global_rkey.  This can be used by
2649 	 * ULPs to avoid the overhead of dynamic MRs.
2650 	 *
2651 	 * This flag is generally considered unsafe and must only be used in
2652 	 * extremly trusted environments.  Every use of it will log a warning
2653 	 * in the kernel log.
2654 	 */
2655 	IB_PD_UNSAFE_GLOBAL_RKEY	= 0x01,
2656 };
2657 
2658 struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
2659 		const char *caller);
2660 #define ib_alloc_pd(device, flags) \
2661 	__ib_alloc_pd((device), (flags), __func__)
2662 void ib_dealloc_pd(struct ib_pd *pd);
2663 
2664 /**
2665  * ib_create_ah - Creates an address handle for the given address vector.
2666  * @pd: The protection domain associated with the address handle.
2667  * @ah_attr: The attributes of the address vector.
2668  *
2669  * The address handle is used to reference a local or global destination
2670  * in all UD QP post sends.
2671  */
2672 struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
2673 
2674 /**
2675  * ib_init_ah_from_wc - Initializes address handle attributes from a
2676  *   work completion.
2677  * @device: Device on which the received message arrived.
2678  * @port_num: Port on which the received message arrived.
2679  * @wc: Work completion associated with the received message.
2680  * @grh: References the received global route header.  This parameter is
2681  *   ignored unless the work completion indicates that the GRH is valid.
2682  * @ah_attr: Returned attributes that can be used when creating an address
2683  *   handle for replying to the message.
2684  */
2685 int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
2686 		       const struct ib_wc *wc, const struct ib_grh *grh,
2687 		       struct ib_ah_attr *ah_attr);
2688 
2689 /**
2690  * ib_create_ah_from_wc - Creates an address handle associated with the
2691  *   sender of the specified work completion.
2692  * @pd: The protection domain associated with the address handle.
2693  * @wc: Work completion information associated with a received message.
2694  * @grh: References the received global route header.  This parameter is
2695  *   ignored unless the work completion indicates that the GRH is valid.
2696  * @port_num: The outbound port number to associate with the address.
2697  *
2698  * The address handle is used to reference a local or global destination
2699  * in all UD QP post sends.
2700  */
2701 struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
2702 				   const struct ib_grh *grh, u8 port_num);
2703 
2704 /**
2705  * ib_modify_ah - Modifies the address vector associated with an address
2706  *   handle.
2707  * @ah: The address handle to modify.
2708  * @ah_attr: The new address vector attributes to associate with the
2709  *   address handle.
2710  */
2711 int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2712 
2713 /**
2714  * ib_query_ah - Queries the address vector associated with an address
2715  *   handle.
2716  * @ah: The address handle to query.
2717  * @ah_attr: The address vector attributes associated with the address
2718  *   handle.
2719  */
2720 int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2721 
2722 /**
2723  * ib_destroy_ah - Destroys an address handle.
2724  * @ah: The address handle to destroy.
2725  */
2726 int ib_destroy_ah(struct ib_ah *ah);
2727 
2728 /**
2729  * ib_create_srq - Creates a SRQ associated with the specified protection
2730  *   domain.
2731  * @pd: The protection domain associated with the SRQ.
2732  * @srq_init_attr: A list of initial attributes required to create the
2733  *   SRQ.  If SRQ creation succeeds, then the attributes are updated to
2734  *   the actual capabilities of the created SRQ.
2735  *
2736  * srq_attr->max_wr and srq_attr->max_sge are read the determine the
2737  * requested size of the SRQ, and set to the actual values allocated
2738  * on return.  If ib_create_srq() succeeds, then max_wr and max_sge
2739  * will always be at least as large as the requested values.
2740  */
2741 struct ib_srq *ib_create_srq(struct ib_pd *pd,
2742 			     struct ib_srq_init_attr *srq_init_attr);
2743 
2744 /**
2745  * ib_modify_srq - Modifies the attributes for the specified SRQ.
2746  * @srq: The SRQ to modify.
2747  * @srq_attr: On input, specifies the SRQ attributes to modify.  On output,
2748  *   the current values of selected SRQ attributes are returned.
2749  * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
2750  *   are being modified.
2751  *
2752  * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
2753  * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
2754  * the number of receives queued drops below the limit.
2755  */
2756 int ib_modify_srq(struct ib_srq *srq,
2757 		  struct ib_srq_attr *srq_attr,
2758 		  enum ib_srq_attr_mask srq_attr_mask);
2759 
2760 /**
2761  * ib_query_srq - Returns the attribute list and current values for the
2762  *   specified SRQ.
2763  * @srq: The SRQ to query.
2764  * @srq_attr: The attributes of the specified SRQ.
2765  */
2766 int ib_query_srq(struct ib_srq *srq,
2767 		 struct ib_srq_attr *srq_attr);
2768 
2769 /**
2770  * ib_destroy_srq - Destroys the specified SRQ.
2771  * @srq: The SRQ to destroy.
2772  */
2773 int ib_destroy_srq(struct ib_srq *srq);
2774 
2775 /**
2776  * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
2777  * @srq: The SRQ to post the work request on.
2778  * @recv_wr: A list of work requests to post on the receive queue.
2779  * @bad_recv_wr: On an immediate failure, this parameter will reference
2780  *   the work request that failed to be posted on the QP.
2781  */
ib_post_srq_recv(struct ib_srq * srq,const struct ib_recv_wr * recv_wr,const struct ib_recv_wr ** bad_recv_wr)2782 static inline int ib_post_srq_recv(struct ib_srq *srq,
2783 				   const struct ib_recv_wr *recv_wr,
2784 				   const struct ib_recv_wr **bad_recv_wr)
2785 {
2786 	return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
2787 }
2788 
2789 /**
2790  * ib_create_qp - Creates a QP associated with the specified protection
2791  *   domain.
2792  * @pd: The protection domain associated with the QP.
2793  * @qp_init_attr: A list of initial attributes required to create the
2794  *   QP.  If QP creation succeeds, then the attributes are updated to
2795  *   the actual capabilities of the created QP.
2796  */
2797 struct ib_qp *ib_create_qp(struct ib_pd *pd,
2798 			   struct ib_qp_init_attr *qp_init_attr);
2799 
2800 /**
2801  * ib_modify_qp - Modifies the attributes for the specified QP and then
2802  *   transitions the QP to the given state.
2803  * @qp: The QP to modify.
2804  * @qp_attr: On input, specifies the QP attributes to modify.  On output,
2805  *   the current values of selected QP attributes are returned.
2806  * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
2807  *   are being modified.
2808  */
2809 int ib_modify_qp(struct ib_qp *qp,
2810 		 struct ib_qp_attr *qp_attr,
2811 		 int qp_attr_mask);
2812 
2813 /**
2814  * ib_query_qp - Returns the attribute list and current values for the
2815  *   specified QP.
2816  * @qp: The QP to query.
2817  * @qp_attr: The attributes of the specified QP.
2818  * @qp_attr_mask: A bit-mask used to select specific attributes to query.
2819  * @qp_init_attr: Additional attributes of the selected QP.
2820  *
2821  * The qp_attr_mask may be used to limit the query to gathering only the
2822  * selected attributes.
2823  */
2824 int ib_query_qp(struct ib_qp *qp,
2825 		struct ib_qp_attr *qp_attr,
2826 		int qp_attr_mask,
2827 		struct ib_qp_init_attr *qp_init_attr);
2828 
2829 /**
2830  * ib_destroy_qp - Destroys the specified QP.
2831  * @qp: The QP to destroy.
2832  */
2833 int ib_destroy_qp(struct ib_qp *qp);
2834 
2835 /**
2836  * ib_open_qp - Obtain a reference to an existing sharable QP.
2837  * @xrcd - XRC domain
2838  * @qp_open_attr: Attributes identifying the QP to open.
2839  *
2840  * Returns a reference to a sharable QP.
2841  */
2842 struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
2843 			 struct ib_qp_open_attr *qp_open_attr);
2844 
2845 /**
2846  * ib_close_qp - Release an external reference to a QP.
2847  * @qp: The QP handle to release
2848  *
2849  * The opened QP handle is released by the caller.  The underlying
2850  * shared QP is not destroyed until all internal references are released.
2851  */
2852 int ib_close_qp(struct ib_qp *qp);
2853 
2854 /**
2855  * ib_post_send - Posts a list of work requests to the send queue of
2856  *   the specified QP.
2857  * @qp: The QP to post the work request on.
2858  * @send_wr: A list of work requests to post on the send queue.
2859  * @bad_send_wr: On an immediate failure, this parameter will reference
2860  *   the work request that failed to be posted on the QP.
2861  *
2862  * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
2863  * error is returned, the QP state shall not be affected,
2864  * ib_post_send() will return an immediate error after queueing any
2865  * earlier work requests in the list.
2866  */
ib_post_send(struct ib_qp * qp,const struct ib_send_wr * send_wr,const struct ib_send_wr ** bad_send_wr)2867 static inline int ib_post_send(struct ib_qp *qp,
2868 			       const struct ib_send_wr *send_wr,
2869 			       const struct ib_send_wr **bad_send_wr)
2870 {
2871 	return qp->device->post_send(qp, send_wr, bad_send_wr);
2872 }
2873 
2874 /**
2875  * ib_post_recv - Posts a list of work requests to the receive queue of
2876  *   the specified QP.
2877  * @qp: The QP to post the work request on.
2878  * @recv_wr: A list of work requests to post on the receive queue.
2879  * @bad_recv_wr: On an immediate failure, this parameter will reference
2880  *   the work request that failed to be posted on the QP.
2881  */
ib_post_recv(struct ib_qp * qp,const struct ib_recv_wr * recv_wr,const struct ib_recv_wr ** bad_recv_wr)2882 static inline int ib_post_recv(struct ib_qp *qp,
2883 			       const struct ib_recv_wr *recv_wr,
2884 			       const struct ib_recv_wr **bad_recv_wr)
2885 {
2886 	return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
2887 }
2888 
2889 struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
2890 		int nr_cqe, int comp_vector, enum ib_poll_context poll_ctx);
2891 void ib_free_cq(struct ib_cq *cq);
2892 
2893 /**
2894  * ib_create_cq - Creates a CQ on the specified device.
2895  * @device: The device on which to create the CQ.
2896  * @comp_handler: A user-specified callback that is invoked when a
2897  *   completion event occurs on the CQ.
2898  * @event_handler: A user-specified callback that is invoked when an
2899  *   asynchronous event not associated with a completion occurs on the CQ.
2900  * @cq_context: Context associated with the CQ returned to the user via
2901  *   the associated completion and event handlers.
2902  * @cq_attr: The attributes the CQ should be created upon.
2903  *
2904  * Users can examine the cq structure to determine the actual CQ size.
2905  */
2906 struct ib_cq *ib_create_cq(struct ib_device *device,
2907 			   ib_comp_handler comp_handler,
2908 			   void (*event_handler)(struct ib_event *, void *),
2909 			   void *cq_context,
2910 			   const struct ib_cq_init_attr *cq_attr);
2911 
2912 /**
2913  * ib_resize_cq - Modifies the capacity of the CQ.
2914  * @cq: The CQ to resize.
2915  * @cqe: The minimum size of the CQ.
2916  *
2917  * Users can examine the cq structure to determine the actual CQ size.
2918  */
2919 int ib_resize_cq(struct ib_cq *cq, int cqe);
2920 
2921 /**
2922  * ib_modify_cq - Modifies moderation params of the CQ
2923  * @cq: The CQ to modify.
2924  * @cq_count: number of CQEs that will trigger an event
2925  * @cq_period: max period of time in usec before triggering an event
2926  *
2927  */
2928 int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
2929 
2930 /**
2931  * ib_destroy_cq - Destroys the specified CQ.
2932  * @cq: The CQ to destroy.
2933  */
2934 int ib_destroy_cq(struct ib_cq *cq);
2935 
2936 /**
2937  * ib_poll_cq - poll a CQ for completion(s)
2938  * @cq:the CQ being polled
2939  * @num_entries:maximum number of completions to return
2940  * @wc:array of at least @num_entries &struct ib_wc where completions
2941  *   will be returned
2942  *
2943  * Poll a CQ for (possibly multiple) completions.  If the return value
2944  * is < 0, an error occurred.  If the return value is >= 0, it is the
2945  * number of completions returned.  If the return value is
2946  * non-negative and < num_entries, then the CQ was emptied.
2947  */
ib_poll_cq(struct ib_cq * cq,int num_entries,struct ib_wc * wc)2948 static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
2949 			     struct ib_wc *wc)
2950 {
2951 	return cq->device->poll_cq(cq, num_entries, wc);
2952 }
2953 
2954 /**
2955  * ib_peek_cq - Returns the number of unreaped completions currently
2956  *   on the specified CQ.
2957  * @cq: The CQ to peek.
2958  * @wc_cnt: A minimum number of unreaped completions to check for.
2959  *
2960  * If the number of unreaped completions is greater than or equal to wc_cnt,
2961  * this function returns wc_cnt, otherwise, it returns the actual number of
2962  * unreaped completions.
2963  */
2964 int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
2965 
2966 /**
2967  * ib_req_notify_cq - Request completion notification on a CQ.
2968  * @cq: The CQ to generate an event for.
2969  * @flags:
2970  *   Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
2971  *   to request an event on the next solicited event or next work
2972  *   completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
2973  *   may also be |ed in to request a hint about missed events, as
2974  *   described below.
2975  *
2976  * Return Value:
2977  *    < 0 means an error occurred while requesting notification
2978  *   == 0 means notification was requested successfully, and if
2979  *        IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
2980  *        were missed and it is safe to wait for another event.  In
2981  *        this case is it guaranteed that any work completions added
2982  *        to the CQ since the last CQ poll will trigger a completion
2983  *        notification event.
2984  *    > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
2985  *        in.  It means that the consumer must poll the CQ again to
2986  *        make sure it is empty to avoid missing an event because of a
2987  *        race between requesting notification and an entry being
2988  *        added to the CQ.  This return value means it is possible
2989  *        (but not guaranteed) that a work completion has been added
2990  *        to the CQ since the last poll without triggering a
2991  *        completion notification event.
2992  */
ib_req_notify_cq(struct ib_cq * cq,enum ib_cq_notify_flags flags)2993 static inline int ib_req_notify_cq(struct ib_cq *cq,
2994 				   enum ib_cq_notify_flags flags)
2995 {
2996 	return cq->device->req_notify_cq(cq, flags);
2997 }
2998 
2999 /**
3000  * ib_req_ncomp_notif - Request completion notification when there are
3001  *   at least the specified number of unreaped completions on the CQ.
3002  * @cq: The CQ to generate an event for.
3003  * @wc_cnt: The number of unreaped completions that should be on the
3004  *   CQ before an event is generated.
3005  */
ib_req_ncomp_notif(struct ib_cq * cq,int wc_cnt)3006 static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
3007 {
3008 	return cq->device->req_ncomp_notif ?
3009 		cq->device->req_ncomp_notif(cq, wc_cnt) :
3010 		-ENOSYS;
3011 }
3012 
3013 /**
3014  * ib_dma_mapping_error - check a DMA addr for error
3015  * @dev: The device for which the dma_addr was created
3016  * @dma_addr: The DMA address to check
3017  */
ib_dma_mapping_error(struct ib_device * dev,u64 dma_addr)3018 static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
3019 {
3020 	if (dev->dma_ops)
3021 		return dev->dma_ops->mapping_error(dev, dma_addr);
3022 	return dma_mapping_error(dev->dma_device, dma_addr);
3023 }
3024 
3025 /**
3026  * ib_dma_map_single - Map a kernel virtual address to DMA address
3027  * @dev: The device for which the dma_addr is to be created
3028  * @cpu_addr: The kernel virtual address
3029  * @size: The size of the region in bytes
3030  * @direction: The direction of the DMA
3031  */
ib_dma_map_single(struct ib_device * dev,void * cpu_addr,size_t size,enum dma_data_direction direction)3032 static inline u64 ib_dma_map_single(struct ib_device *dev,
3033 				    void *cpu_addr, size_t size,
3034 				    enum dma_data_direction direction)
3035 {
3036 	if (dev->dma_ops)
3037 		return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
3038 	return dma_map_single(dev->dma_device, cpu_addr, size, direction);
3039 }
3040 
3041 /**
3042  * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
3043  * @dev: The device for which the DMA address was created
3044  * @addr: The DMA address
3045  * @size: The size of the region in bytes
3046  * @direction: The direction of the DMA
3047  */
ib_dma_unmap_single(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction direction)3048 static inline void ib_dma_unmap_single(struct ib_device *dev,
3049 				       u64 addr, size_t size,
3050 				       enum dma_data_direction direction)
3051 {
3052 	if (dev->dma_ops)
3053 		dev->dma_ops->unmap_single(dev, addr, size, direction);
3054 	else
3055 		dma_unmap_single(dev->dma_device, addr, size, direction);
3056 }
3057 
ib_dma_map_single_attrs(struct ib_device * dev,void * cpu_addr,size_t size,enum dma_data_direction direction,struct dma_attrs * dma_attrs)3058 static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
3059 					  void *cpu_addr, size_t size,
3060 					  enum dma_data_direction direction,
3061 					  struct dma_attrs *dma_attrs)
3062 {
3063 	return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
3064 				    direction, dma_attrs);
3065 }
3066 
ib_dma_unmap_single_attrs(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction direction,struct dma_attrs * dma_attrs)3067 static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
3068 					     u64 addr, size_t size,
3069 					     enum dma_data_direction direction,
3070 					     struct dma_attrs *dma_attrs)
3071 {
3072 	return dma_unmap_single_attrs(dev->dma_device, addr, size,
3073 				      direction, dma_attrs);
3074 }
3075 
3076 /**
3077  * ib_dma_map_page - Map a physical page to DMA address
3078  * @dev: The device for which the dma_addr is to be created
3079  * @page: The page to be mapped
3080  * @offset: The offset within the page
3081  * @size: The size of the region in bytes
3082  * @direction: The direction of the DMA
3083  */
ib_dma_map_page(struct ib_device * dev,struct page * page,unsigned long offset,size_t size,enum dma_data_direction direction)3084 static inline u64 ib_dma_map_page(struct ib_device *dev,
3085 				  struct page *page,
3086 				  unsigned long offset,
3087 				  size_t size,
3088 					 enum dma_data_direction direction)
3089 {
3090 	if (dev->dma_ops)
3091 		return dev->dma_ops->map_page(dev, page, offset, size, direction);
3092 	return dma_map_page(dev->dma_device, page, offset, size, direction);
3093 }
3094 
3095 /**
3096  * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
3097  * @dev: The device for which the DMA address was created
3098  * @addr: The DMA address
3099  * @size: The size of the region in bytes
3100  * @direction: The direction of the DMA
3101  */
ib_dma_unmap_page(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction direction)3102 static inline void ib_dma_unmap_page(struct ib_device *dev,
3103 				     u64 addr, size_t size,
3104 				     enum dma_data_direction direction)
3105 {
3106 	if (dev->dma_ops)
3107 		dev->dma_ops->unmap_page(dev, addr, size, direction);
3108 	else
3109 		dma_unmap_page(dev->dma_device, addr, size, direction);
3110 }
3111 
3112 /**
3113  * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
3114  * @dev: The device for which the DMA addresses are to be created
3115  * @sg: The array of scatter/gather entries
3116  * @nents: The number of scatter/gather entries
3117  * @direction: The direction of the DMA
3118  */
ib_dma_map_sg(struct ib_device * dev,struct scatterlist * sg,int nents,enum dma_data_direction direction)3119 static inline int ib_dma_map_sg(struct ib_device *dev,
3120 				struct scatterlist *sg, int nents,
3121 				enum dma_data_direction direction)
3122 {
3123 	if (dev->dma_ops)
3124 		return dev->dma_ops->map_sg(dev, sg, nents, direction);
3125 	return dma_map_sg(dev->dma_device, sg, nents, direction);
3126 }
3127 
3128 /**
3129  * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
3130  * @dev: The device for which the DMA addresses were created
3131  * @sg: The array of scatter/gather entries
3132  * @nents: The number of scatter/gather entries
3133  * @direction: The direction of the DMA
3134  */
ib_dma_unmap_sg(struct ib_device * dev,struct scatterlist * sg,int nents,enum dma_data_direction direction)3135 static inline void ib_dma_unmap_sg(struct ib_device *dev,
3136 				   struct scatterlist *sg, int nents,
3137 				   enum dma_data_direction direction)
3138 {
3139 	if (dev->dma_ops)
3140 		dev->dma_ops->unmap_sg(dev, sg, nents, direction);
3141 	else
3142 		dma_unmap_sg(dev->dma_device, sg, nents, direction);
3143 }
3144 
ib_dma_map_sg_attrs(struct ib_device * dev,struct scatterlist * sg,int nents,enum dma_data_direction direction,struct dma_attrs * dma_attrs)3145 static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
3146 				      struct scatterlist *sg, int nents,
3147 				      enum dma_data_direction direction,
3148 				      struct dma_attrs *dma_attrs)
3149 {
3150 	if (dev->dma_ops)
3151 		return dev->dma_ops->map_sg_attrs(dev, sg, nents, direction,
3152 						  dma_attrs);
3153 	else
3154 		return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
3155 					dma_attrs);
3156 }
3157 
ib_dma_unmap_sg_attrs(struct ib_device * dev,struct scatterlist * sg,int nents,enum dma_data_direction direction,struct dma_attrs * dma_attrs)3158 static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
3159 					 struct scatterlist *sg, int nents,
3160 					 enum dma_data_direction direction,
3161 					 struct dma_attrs *dma_attrs)
3162 {
3163 	if (dev->dma_ops)
3164 		return dev->dma_ops->unmap_sg_attrs(dev, sg, nents, direction,
3165 						  dma_attrs);
3166 	else
3167 		dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction,
3168 				   dma_attrs);
3169 }
3170 /**
3171  * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
3172  * @dev: The device for which the DMA addresses were created
3173  * @sg: The scatter/gather entry
3174  *
3175  * Note: this function is obsolete. To do: change all occurrences of
3176  * ib_sg_dma_address() into sg_dma_address().
3177  */
ib_sg_dma_address(struct ib_device * dev,struct scatterlist * sg)3178 static inline u64 ib_sg_dma_address(struct ib_device *dev,
3179 				    struct scatterlist *sg)
3180 {
3181 	return sg_dma_address(sg);
3182 }
3183 
3184 /**
3185  * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
3186  * @dev: The device for which the DMA addresses were created
3187  * @sg: The scatter/gather entry
3188  *
3189  * Note: this function is obsolete. To do: change all occurrences of
3190  * ib_sg_dma_len() into sg_dma_len().
3191  */
ib_sg_dma_len(struct ib_device * dev,struct scatterlist * sg)3192 static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
3193 					 struct scatterlist *sg)
3194 {
3195 	return sg_dma_len(sg);
3196 }
3197 
3198 /**
3199  * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
3200  * @dev: The device for which the DMA address was created
3201  * @addr: The DMA address
3202  * @size: The size of the region in bytes
3203  * @dir: The direction of the DMA
3204  */
ib_dma_sync_single_for_cpu(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction dir)3205 static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
3206 					      u64 addr,
3207 					      size_t size,
3208 					      enum dma_data_direction dir)
3209 {
3210 	if (dev->dma_ops)
3211 		dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
3212 	else
3213 		dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
3214 }
3215 
3216 /**
3217  * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
3218  * @dev: The device for which the DMA address was created
3219  * @addr: The DMA address
3220  * @size: The size of the region in bytes
3221  * @dir: The direction of the DMA
3222  */
ib_dma_sync_single_for_device(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction dir)3223 static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
3224 						 u64 addr,
3225 						 size_t size,
3226 						 enum dma_data_direction dir)
3227 {
3228 	if (dev->dma_ops)
3229 		dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
3230 	else
3231 		dma_sync_single_for_device(dev->dma_device, addr, size, dir);
3232 }
3233 
3234 /**
3235  * ib_dma_alloc_coherent - Allocate memory and map it for DMA
3236  * @dev: The device for which the DMA address is requested
3237  * @size: The size of the region to allocate in bytes
3238  * @dma_handle: A pointer for returning the DMA address of the region
3239  * @flag: memory allocator flags
3240  */
ib_dma_alloc_coherent(struct ib_device * dev,size_t size,u64 * dma_handle,gfp_t flag)3241 static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
3242 					   size_t size,
3243 					   u64 *dma_handle,
3244 					   gfp_t flag)
3245 {
3246 	if (dev->dma_ops)
3247 		return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
3248 	else {
3249 		dma_addr_t handle;
3250 		void *ret;
3251 
3252 		ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
3253 		*dma_handle = handle;
3254 		return ret;
3255 	}
3256 }
3257 
3258 /**
3259  * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
3260  * @dev: The device for which the DMA addresses were allocated
3261  * @size: The size of the region
3262  * @cpu_addr: the address returned by ib_dma_alloc_coherent()
3263  * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
3264  */
ib_dma_free_coherent(struct ib_device * dev,size_t size,void * cpu_addr,u64 dma_handle)3265 static inline void ib_dma_free_coherent(struct ib_device *dev,
3266 					size_t size, void *cpu_addr,
3267 					u64 dma_handle)
3268 {
3269 	if (dev->dma_ops)
3270 		dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
3271 	else
3272 		dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
3273 }
3274 
3275 /**
3276  * ib_dereg_mr - Deregisters a memory region and removes it from the
3277  *   HCA translation table.
3278  * @mr: The memory region to deregister.
3279  *
3280  * This function can fail, if the memory region has memory windows bound to it.
3281  */
3282 int ib_dereg_mr(struct ib_mr *mr);
3283 
3284 struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
3285 			  enum ib_mr_type mr_type,
3286 			  u32 max_num_sg);
3287 
3288 /**
3289  * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
3290  *   R_Key and L_Key.
3291  * @mr - struct ib_mr pointer to be updated.
3292  * @newkey - new key to be used.
3293  */
ib_update_fast_reg_key(struct ib_mr * mr,u8 newkey)3294 static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
3295 {
3296 	mr->lkey = (mr->lkey & 0xffffff00) | newkey;
3297 	mr->rkey = (mr->rkey & 0xffffff00) | newkey;
3298 }
3299 
3300 /**
3301  * ib_inc_rkey - increments the key portion of the given rkey. Can be used
3302  * for calculating a new rkey for type 2 memory windows.
3303  * @rkey - the rkey to increment.
3304  */
ib_inc_rkey(u32 rkey)3305 static inline u32 ib_inc_rkey(u32 rkey)
3306 {
3307 	const u32 mask = 0x000000ff;
3308 	return ((rkey + 1) & mask) | (rkey & ~mask);
3309 }
3310 
3311 /**
3312  * ib_alloc_fmr - Allocates a unmapped fast memory region.
3313  * @pd: The protection domain associated with the unmapped region.
3314  * @mr_access_flags: Specifies the memory access rights.
3315  * @fmr_attr: Attributes of the unmapped region.
3316  *
3317  * A fast memory region must be mapped before it can be used as part of
3318  * a work request.
3319  */
3320 struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
3321 			    int mr_access_flags,
3322 			    struct ib_fmr_attr *fmr_attr);
3323 
3324 /**
3325  * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
3326  * @fmr: The fast memory region to associate with the pages.
3327  * @page_list: An array of physical pages to map to the fast memory region.
3328  * @list_len: The number of pages in page_list.
3329  * @iova: The I/O virtual address to use with the mapped region.
3330  */
ib_map_phys_fmr(struct ib_fmr * fmr,u64 * page_list,int list_len,u64 iova)3331 static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
3332 				  u64 *page_list, int list_len,
3333 				  u64 iova)
3334 {
3335 	return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
3336 }
3337 
3338 /**
3339  * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
3340  * @fmr_list: A linked list of fast memory regions to unmap.
3341  */
3342 int ib_unmap_fmr(struct list_head *fmr_list);
3343 
3344 /**
3345  * ib_dealloc_fmr - Deallocates a fast memory region.
3346  * @fmr: The fast memory region to deallocate.
3347  */
3348 int ib_dealloc_fmr(struct ib_fmr *fmr);
3349 
3350 /**
3351  * ib_attach_mcast - Attaches the specified QP to a multicast group.
3352  * @qp: QP to attach to the multicast group.  The QP must be type
3353  *   IB_QPT_UD.
3354  * @gid: Multicast group GID.
3355  * @lid: Multicast group LID in host byte order.
3356  *
3357  * In order to send and receive multicast packets, subnet
3358  * administration must have created the multicast group and configured
3359  * the fabric appropriately.  The port associated with the specified
3360  * QP must also be a member of the multicast group.
3361  */
3362 int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
3363 
3364 /**
3365  * ib_detach_mcast - Detaches the specified QP from a multicast group.
3366  * @qp: QP to detach from the multicast group.
3367  * @gid: Multicast group GID.
3368  * @lid: Multicast group LID in host byte order.
3369  */
3370 int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
3371 
3372 /**
3373  * ib_alloc_xrcd - Allocates an XRC domain.
3374  * @device: The device on which to allocate the XRC domain.
3375  */
3376 struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
3377 
3378 /**
3379  * ib_dealloc_xrcd - Deallocates an XRC domain.
3380  * @xrcd: The XRC domain to deallocate.
3381  */
3382 int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
3383 
3384 struct ib_flow *ib_create_flow(struct ib_qp *qp,
3385 			       struct ib_flow_attr *flow_attr, int domain);
3386 int ib_destroy_flow(struct ib_flow *flow_id);
3387 
ib_check_mr_access(int flags)3388 static inline int ib_check_mr_access(int flags)
3389 {
3390 	/*
3391 	 * Local write permission is required if remote write or
3392 	 * remote atomic permission is also requested.
3393 	 */
3394 	if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
3395 	    !(flags & IB_ACCESS_LOCAL_WRITE))
3396 		return -EINVAL;
3397 
3398 	return 0;
3399 }
3400 
3401 /**
3402  * ib_check_mr_status: lightweight check of MR status.
3403  *     This routine may provide status checks on a selected
3404  *     ib_mr. first use is for signature status check.
3405  *
3406  * @mr: A memory region.
3407  * @check_mask: Bitmask of which checks to perform from
3408  *     ib_mr_status_check enumeration.
3409  * @mr_status: The container of relevant status checks.
3410  *     failed checks will be indicated in the status bitmask
3411  *     and the relevant info shall be in the error item.
3412  */
3413 int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
3414 		       struct ib_mr_status *mr_status);
3415 
3416 struct ifnet *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
3417 					    u16 pkey, const union ib_gid *gid,
3418 					    const struct sockaddr *addr);
3419 struct ib_wq *ib_create_wq(struct ib_pd *pd,
3420 			   struct ib_wq_init_attr *init_attr);
3421 int ib_destroy_wq(struct ib_wq *wq);
3422 int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
3423 		 u32 wq_attr_mask);
3424 struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
3425 						 struct ib_rwq_ind_table_init_attr*
3426 						 wq_ind_table_init_attr);
3427 int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
3428 
3429 int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
3430 		 unsigned int *sg_offset, unsigned int page_size);
3431 
3432 static inline int
ib_map_mr_sg_zbva(struct ib_mr * mr,struct scatterlist * sg,int sg_nents,unsigned int * sg_offset,unsigned int page_size)3433 ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
3434 		  unsigned int *sg_offset, unsigned int page_size)
3435 {
3436 	int n;
3437 
3438 	n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
3439 	mr->iova = 0;
3440 
3441 	return n;
3442 }
3443 
3444 int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
3445 		unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
3446 
3447 void ib_drain_rq(struct ib_qp *qp);
3448 void ib_drain_sq(struct ib_qp *qp);
3449 void ib_drain_qp(struct ib_qp *qp);
3450 
3451 struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
3452 
3453 int ib_resolve_eth_dmac(struct ib_device *device,
3454 			struct ib_ah_attr *ah_attr);
3455 #endif /* IB_VERBS_H */
3456