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