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