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