]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/rdma/ib_verbs.h
RDMA/core: Add an integrity MR pool support
[mirror_ubuntu-jammy-kernel.git] / include / rdma / ib_verbs.h
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
4 * Copyright (c) 2004 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
2a1d9b7f 7 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
f7c6a7b5 8 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
1da177e4
LT
9 *
10 * This software is available to you under a choice of one of two
11 * licenses. You may choose to be licensed under the terms of the GNU
12 * General Public License (GPL) Version 2, available from the file
13 * COPYING in the main directory of this source tree, or the
14 * OpenIB.org BSD license below:
15 *
16 * Redistribution and use in source and binary forms, with or
17 * without modification, are permitted provided that the following
18 * conditions are met:
19 *
20 * - Redistributions of source code must retain the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer.
23 *
24 * - Redistributions in binary form must reproduce the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer in the documentation and/or other materials
27 * provided with the distribution.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 * SOFTWARE.
1da177e4
LT
37 */
38
39#if !defined(IB_VERBS_H)
40#define IB_VERBS_H
41
42#include <linux/types.h>
43#include <linux/device.h>
9b513090 44#include <linux/dma-mapping.h>
459d6e2a 45#include <linux/kref.h>
bfb3ea12
DB
46#include <linux/list.h>
47#include <linux/rwsem.h>
f0626710 48#include <linux/workqueue.h>
14d3a3b2 49#include <linux/irq_poll.h>
dd5f03be 50#include <uapi/linux/if_ether.h>
c865f246
SK
51#include <net/ipv6.h>
52#include <net/ip.h>
301a721e
MB
53#include <linux/string.h>
54#include <linux/slab.h>
2fc77572 55#include <linux/netdevice.h>
01b67117 56#include <linux/refcount.h>
50174a7f 57#include <linux/if_link.h>
60063497 58#include <linux/atomic.h>
882214e2 59#include <linux/mmu_notifier.h>
7c0f6ba6 60#include <linux/uaccess.h>
43579b5f 61#include <linux/cgroup_rdma.h>
f6316032
LR
62#include <linux/irqflags.h>
63#include <linux/preempt.h>
ea6819e1 64#include <uapi/rdma/ib_user_verbs.h>
02d8883f 65#include <rdma/restrack.h>
36b1e47f 66#include <rdma/signature.h>
0ede73bc 67#include <uapi/rdma/rdma_user_ioctl.h>
2eb9beae 68#include <uapi/rdma/ib_user_ioctl_verbs.h>
1da177e4 69
9abb0d1b
LR
70#define IB_FW_VERSION_NAME_MAX ETHTOOL_FWVERS_LEN
71
b5231b01
JG
72struct ib_umem_odp;
73
f0626710 74extern struct workqueue_struct *ib_wq;
14d3a3b2 75extern struct workqueue_struct *ib_comp_wq;
f794809a 76extern struct workqueue_struct *ib_comp_unbound_wq;
f0626710 77
923abb9d
GP
78__printf(3, 4) __cold
79void ibdev_printk(const char *level, const struct ib_device *ibdev,
80 const char *format, ...);
81__printf(2, 3) __cold
82void ibdev_emerg(const struct ib_device *ibdev, const char *format, ...);
83__printf(2, 3) __cold
84void ibdev_alert(const struct ib_device *ibdev, const char *format, ...);
85__printf(2, 3) __cold
86void ibdev_crit(const struct ib_device *ibdev, const char *format, ...);
87__printf(2, 3) __cold
88void ibdev_err(const struct ib_device *ibdev, const char *format, ...);
89__printf(2, 3) __cold
90void ibdev_warn(const struct ib_device *ibdev, const char *format, ...);
91__printf(2, 3) __cold
92void ibdev_notice(const struct ib_device *ibdev, const char *format, ...);
93__printf(2, 3) __cold
94void ibdev_info(const struct ib_device *ibdev, const char *format, ...);
95
96#if defined(CONFIG_DYNAMIC_DEBUG)
97#define ibdev_dbg(__dev, format, args...) \
98 dynamic_ibdev_dbg(__dev, format, ##args)
99#elif defined(DEBUG)
100#define ibdev_dbg(__dev, format, args...) \
101 ibdev_printk(KERN_DEBUG, __dev, format, ##args)
102#else
103__printf(2, 3) __cold
104static inline
105void ibdev_dbg(const struct ib_device *ibdev, const char *format, ...) {}
106#endif
107
1da177e4
LT
108union ib_gid {
109 u8 raw[16];
110 struct {
97f52eb4
SH
111 __be64 subnet_prefix;
112 __be64 interface_id;
1da177e4
LT
113 } global;
114};
115
e26be1bf
MS
116extern union ib_gid zgid;
117
b39ffa1d
MB
118enum ib_gid_type {
119 /* If link layer is Ethernet, this is RoCE V1 */
120 IB_GID_TYPE_IB = 0,
121 IB_GID_TYPE_ROCE = 0,
7766a99f 122 IB_GID_TYPE_ROCE_UDP_ENCAP = 1,
b39ffa1d
MB
123 IB_GID_TYPE_SIZE
124};
125
7ead4bcb 126#define ROCE_V2_UDP_DPORT 4791
03db3a2d 127struct ib_gid_attr {
943bd984 128 struct net_device __rcu *ndev;
598ff6ba 129 struct ib_device *device;
b150c386 130 union ib_gid gid;
598ff6ba
PP
131 enum ib_gid_type gid_type;
132 u16 index;
133 u8 port_num;
03db3a2d
MB
134};
135
a0c1b2a3
EC
136enum {
137 /* set the local administered indication */
138 IB_SA_WELL_KNOWN_GUID = BIT_ULL(57) | 2,
139};
140
07ebafba
TT
141enum rdma_transport_type {
142 RDMA_TRANSPORT_IB,
180771a3 143 RDMA_TRANSPORT_IWARP,
248567f7 144 RDMA_TRANSPORT_USNIC,
f95be3d2
GP
145 RDMA_TRANSPORT_USNIC_UDP,
146 RDMA_TRANSPORT_UNSPECIFIED,
07ebafba
TT
147};
148
6b90a6d6
MW
149enum rdma_protocol_type {
150 RDMA_PROTOCOL_IB,
151 RDMA_PROTOCOL_IBOE,
152 RDMA_PROTOCOL_IWARP,
153 RDMA_PROTOCOL_USNIC_UDP
154};
155
8385fd84 156__attribute_const__ enum rdma_transport_type
5d60c111 157rdma_node_get_transport(unsigned int node_type);
07ebafba 158
c865f246
SK
159enum rdma_network_type {
160 RDMA_NETWORK_IB,
161 RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB,
162 RDMA_NETWORK_IPV4,
163 RDMA_NETWORK_IPV6
164};
165
166static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
167{
168 if (network_type == RDMA_NETWORK_IPV4 ||
169 network_type == RDMA_NETWORK_IPV6)
170 return IB_GID_TYPE_ROCE_UDP_ENCAP;
171
172 /* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */
173 return IB_GID_TYPE_IB;
174}
175
47ec3866
PP
176static inline enum rdma_network_type
177rdma_gid_attr_network_type(const struct ib_gid_attr *attr)
c865f246 178{
47ec3866 179 if (attr->gid_type == IB_GID_TYPE_IB)
c865f246
SK
180 return RDMA_NETWORK_IB;
181
47ec3866 182 if (ipv6_addr_v4mapped((struct in6_addr *)&attr->gid))
c865f246
SK
183 return RDMA_NETWORK_IPV4;
184 else
185 return RDMA_NETWORK_IPV6;
186}
187
a3f5adaf
EC
188enum rdma_link_layer {
189 IB_LINK_LAYER_UNSPECIFIED,
190 IB_LINK_LAYER_INFINIBAND,
191 IB_LINK_LAYER_ETHERNET,
192};
193
1da177e4 194enum ib_device_cap_flags {
7ca0bc53
LR
195 IB_DEVICE_RESIZE_MAX_WR = (1 << 0),
196 IB_DEVICE_BAD_PKEY_CNTR = (1 << 1),
197 IB_DEVICE_BAD_QKEY_CNTR = (1 << 2),
198 IB_DEVICE_RAW_MULTI = (1 << 3),
199 IB_DEVICE_AUTO_PATH_MIG = (1 << 4),
200 IB_DEVICE_CHANGE_PHY_PORT = (1 << 5),
201 IB_DEVICE_UD_AV_PORT_ENFORCE = (1 << 6),
202 IB_DEVICE_CURR_QP_STATE_MOD = (1 << 7),
203 IB_DEVICE_SHUTDOWN_PORT = (1 << 8),
78b57f95 204 /* Not in use, former INIT_TYPE = (1 << 9),*/
7ca0bc53
LR
205 IB_DEVICE_PORT_ACTIVE_EVENT = (1 << 10),
206 IB_DEVICE_SYS_IMAGE_GUID = (1 << 11),
207 IB_DEVICE_RC_RNR_NAK_GEN = (1 << 12),
208 IB_DEVICE_SRQ_RESIZE = (1 << 13),
209 IB_DEVICE_N_NOTIFY_CQ = (1 << 14),
b1adc714
CH
210
211 /*
212 * This device supports a per-device lkey or stag that can be
213 * used without performing a memory registration for the local
214 * memory. Note that ULPs should never check this flag, but
215 * instead of use the local_dma_lkey flag in the ib_pd structure,
216 * which will always contain a usable lkey.
217 */
7ca0bc53 218 IB_DEVICE_LOCAL_DMA_LKEY = (1 << 15),
78b57f95 219 /* Reserved, old SEND_W_INV = (1 << 16),*/
7ca0bc53 220 IB_DEVICE_MEM_WINDOW = (1 << 17),
e0605d91
EC
221 /*
222 * Devices should set IB_DEVICE_UD_IP_SUM if they support
223 * insertion of UDP and TCP checksum on outgoing UD IPoIB
224 * messages and can verify the validity of checksum for
225 * incoming messages. Setting this flag implies that the
226 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
227 */
7ca0bc53
LR
228 IB_DEVICE_UD_IP_CSUM = (1 << 18),
229 IB_DEVICE_UD_TSO = (1 << 19),
230 IB_DEVICE_XRC = (1 << 20),
b1adc714
CH
231
232 /*
233 * This device supports the IB "base memory management extension",
234 * which includes support for fast registrations (IB_WR_REG_MR,
235 * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs). This flag should
236 * also be set by any iWarp device which must support FRs to comply
237 * to the iWarp verbs spec. iWarp devices also support the
238 * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
239 * stag.
240 */
7ca0bc53
LR
241 IB_DEVICE_MEM_MGT_EXTENSIONS = (1 << 21),
242 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1 << 22),
243 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1 << 23),
244 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1 << 24),
245 IB_DEVICE_RC_IP_CSUM = (1 << 25),
ebaaee25 246 /* Deprecated. Please use IB_RAW_PACKET_CAP_IP_CSUM. */
7ca0bc53 247 IB_DEVICE_RAW_IP_CSUM = (1 << 26),
8a06ce59
LR
248 /*
249 * Devices should set IB_DEVICE_CROSS_CHANNEL if they
250 * support execution of WQEs that involve synchronization
251 * of I/O operations with single completion queue managed
252 * by hardware.
253 */
78b57f95 254 IB_DEVICE_CROSS_CHANNEL = (1 << 27),
7ca0bc53
LR
255 IB_DEVICE_MANAGED_FLOW_STEERING = (1 << 29),
256 IB_DEVICE_SIGNATURE_HANDOVER = (1 << 30),
47355b3c 257 IB_DEVICE_ON_DEMAND_PAGING = (1ULL << 31),
f5aa9159 258 IB_DEVICE_SG_GAPS_REG = (1ULL << 32),
c7e162a4 259 IB_DEVICE_VIRTUAL_FUNCTION = (1ULL << 33),
ebaaee25 260 /* Deprecated. Please use IB_RAW_PACKET_CAP_SCATTER_FCS. */
c7e162a4 261 IB_DEVICE_RAW_SCATTER_FCS = (1ULL << 34),
62e45949 262 IB_DEVICE_RDMA_NETDEV_OPA_VNIC = (1ULL << 35),
e1d2e887
NO
263 /* The device supports padding incoming writes to cacheline. */
264 IB_DEVICE_PCI_WRITE_END_PADDING = (1ULL << 36),
3856ec4b 265 IB_DEVICE_ALLOW_USER_UNREG = (1ULL << 37),
1b01d335
SG
266};
267
1da177e4
LT
268enum ib_atomic_cap {
269 IB_ATOMIC_NONE,
270 IB_ATOMIC_HCA,
271 IB_ATOMIC_GLOB
272};
273
860f10a7 274enum ib_odp_general_cap_bits {
25bf14d6
AK
275 IB_ODP_SUPPORT = 1 << 0,
276 IB_ODP_SUPPORT_IMPLICIT = 1 << 1,
860f10a7
SG
277};
278
279enum ib_odp_transport_cap_bits {
280 IB_ODP_SUPPORT_SEND = 1 << 0,
281 IB_ODP_SUPPORT_RECV = 1 << 1,
282 IB_ODP_SUPPORT_WRITE = 1 << 2,
283 IB_ODP_SUPPORT_READ = 1 << 3,
284 IB_ODP_SUPPORT_ATOMIC = 1 << 4,
da823342 285 IB_ODP_SUPPORT_SRQ_RECV = 1 << 5,
860f10a7
SG
286};
287
288struct ib_odp_caps {
289 uint64_t general_caps;
290 struct {
291 uint32_t rc_odp_caps;
292 uint32_t uc_odp_caps;
293 uint32_t ud_odp_caps;
52a72e2a 294 uint32_t xrc_odp_caps;
860f10a7
SG
295 } per_transport_caps;
296};
297
ccf20562
YH
298struct ib_rss_caps {
299 /* Corresponding bit will be set if qp type from
300 * 'enum ib_qp_type' is supported, e.g.
301 * supported_qpts |= 1 << IB_QPT_UD
302 */
303 u32 supported_qpts;
304 u32 max_rwq_indirection_tables;
305 u32 max_rwq_indirection_table_size;
306};
307
6938fc1e
AK
308enum ib_tm_cap_flags {
309 /* Support tag matching on RC transport */
310 IB_TM_CAP_RC = 1 << 0,
311};
312
78b1beb0 313struct ib_tm_caps {
6938fc1e
AK
314 /* Max size of RNDV header */
315 u32 max_rndv_hdr_size;
316 /* Max number of entries in tag matching list */
317 u32 max_num_tags;
318 /* From enum ib_tm_cap_flags */
319 u32 flags;
320 /* Max number of outstanding list operations */
321 u32 max_ops;
322 /* Max number of SGE in tag matching entry */
323 u32 max_sge;
324};
325
bcf4c1ea
MB
326struct ib_cq_init_attr {
327 unsigned int cqe;
328 int comp_vector;
329 u32 flags;
330};
331
869ddcf8
YC
332enum ib_cq_attr_mask {
333 IB_CQ_MODERATE = 1 << 0,
334};
335
18bd9072
YC
336struct ib_cq_caps {
337 u16 max_cq_moderation_count;
338 u16 max_cq_moderation_period;
339};
340
be934cca
AL
341struct ib_dm_mr_attr {
342 u64 length;
343 u64 offset;
344 u32 access_flags;
345};
346
bee76d7a
AL
347struct ib_dm_alloc_attr {
348 u64 length;
349 u32 alignment;
350 u32 flags;
351};
352
1da177e4
LT
353struct ib_device_attr {
354 u64 fw_ver;
97f52eb4 355 __be64 sys_image_guid;
1da177e4
LT
356 u64 max_mr_size;
357 u64 page_size_cap;
358 u32 vendor_id;
359 u32 vendor_part_id;
360 u32 hw_ver;
361 int max_qp;
362 int max_qp_wr;
fb532d6a 363 u64 device_cap_flags;
33023fb8
SW
364 int max_send_sge;
365 int max_recv_sge;
1da177e4
LT
366 int max_sge_rd;
367 int max_cq;
368 int max_cqe;
369 int max_mr;
370 int max_pd;
371 int max_qp_rd_atom;
372 int max_ee_rd_atom;
373 int max_res_rd_atom;
374 int max_qp_init_rd_atom;
375 int max_ee_init_rd_atom;
376 enum ib_atomic_cap atomic_cap;
5e80ba8f 377 enum ib_atomic_cap masked_atomic_cap;
1da177e4
LT
378 int max_ee;
379 int max_rdd;
380 int max_mw;
381 int max_raw_ipv6_qp;
382 int max_raw_ethy_qp;
383 int max_mcast_grp;
384 int max_mcast_qp_attach;
385 int max_total_mcast_qp_attach;
386 int max_ah;
387 int max_fmr;
388 int max_map_per_fmr;
389 int max_srq;
390 int max_srq_wr;
391 int max_srq_sge;
00f7ec36 392 unsigned int max_fast_reg_page_list_len;
62e3c379 393 unsigned int max_pi_fast_reg_page_list_len;
1da177e4
LT
394 u16 max_pkeys;
395 u8 local_ca_ack_delay;
1b01d335
SG
396 int sig_prot_cap;
397 int sig_guard_cap;
860f10a7 398 struct ib_odp_caps odp_caps;
24306dc6
MB
399 uint64_t timestamp_mask;
400 uint64_t hca_core_clock; /* in KHZ */
ccf20562
YH
401 struct ib_rss_caps rss_caps;
402 u32 max_wq_type_rq;
ebaaee25 403 u32 raw_packet_caps; /* Use ib_raw_packet_caps enum */
78b1beb0 404 struct ib_tm_caps tm_caps;
18bd9072 405 struct ib_cq_caps cq_caps;
1d8eeb9f 406 u64 max_dm_size;
1da177e4
LT
407};
408
409enum ib_mtu {
410 IB_MTU_256 = 1,
411 IB_MTU_512 = 2,
412 IB_MTU_1024 = 3,
413 IB_MTU_2048 = 4,
414 IB_MTU_4096 = 5
415};
416
417static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
418{
419 switch (mtu) {
420 case IB_MTU_256: return 256;
421 case IB_MTU_512: return 512;
422 case IB_MTU_1024: return 1024;
423 case IB_MTU_2048: return 2048;
424 case IB_MTU_4096: return 4096;
425 default: return -1;
426 }
427}
428
d3f4aadd
AR
429static inline enum ib_mtu ib_mtu_int_to_enum(int mtu)
430{
431 if (mtu >= 4096)
432 return IB_MTU_4096;
433 else if (mtu >= 2048)
434 return IB_MTU_2048;
435 else if (mtu >= 1024)
436 return IB_MTU_1024;
437 else if (mtu >= 512)
438 return IB_MTU_512;
439 else
440 return IB_MTU_256;
441}
442
1da177e4
LT
443enum ib_port_state {
444 IB_PORT_NOP = 0,
445 IB_PORT_DOWN = 1,
446 IB_PORT_INIT = 2,
447 IB_PORT_ARMED = 3,
448 IB_PORT_ACTIVE = 4,
449 IB_PORT_ACTIVE_DEFER = 5
450};
451
1da177e4
LT
452enum ib_port_width {
453 IB_WIDTH_1X = 1,
dbabf685 454 IB_WIDTH_2X = 16,
1da177e4
LT
455 IB_WIDTH_4X = 2,
456 IB_WIDTH_8X = 4,
457 IB_WIDTH_12X = 8
458};
459
460static inline int ib_width_enum_to_int(enum ib_port_width width)
461{
462 switch (width) {
463 case IB_WIDTH_1X: return 1;
dbabf685 464 case IB_WIDTH_2X: return 2;
1da177e4
LT
465 case IB_WIDTH_4X: return 4;
466 case IB_WIDTH_8X: return 8;
467 case IB_WIDTH_12X: return 12;
468 default: return -1;
469 }
470}
471
2e96691c
OG
472enum ib_port_speed {
473 IB_SPEED_SDR = 1,
474 IB_SPEED_DDR = 2,
475 IB_SPEED_QDR = 4,
476 IB_SPEED_FDR10 = 8,
477 IB_SPEED_FDR = 16,
12113a35
NO
478 IB_SPEED_EDR = 32,
479 IB_SPEED_HDR = 64
2e96691c
OG
480};
481
b40f4757
CL
482/**
483 * struct rdma_hw_stats
e945130b
MB
484 * @lock - Mutex to protect parallel write access to lifespan and values
485 * of counters, which are 64bits and not guaranteeed to be written
486 * atomicaly on 32bits systems.
b40f4757
CL
487 * @timestamp - Used by the core code to track when the last update was
488 * @lifespan - Used by the core code to determine how old the counters
489 * should be before being updated again. Stored in jiffies, defaults
490 * to 10 milliseconds, drivers can override the default be specifying
491 * their own value during their allocation routine.
492 * @name - Array of pointers to static names used for the counters in
493 * directory.
494 * @num_counters - How many hardware counters there are. If name is
495 * shorter than this number, a kernel oops will result. Driver authors
496 * are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
497 * in their code to prevent this.
498 * @value - Array of u64 counters that are accessed by the sysfs code and
499 * filled in by the drivers get_stats routine
500 */
501struct rdma_hw_stats {
e945130b 502 struct mutex lock; /* Protect lifespan and values[] */
b40f4757
CL
503 unsigned long timestamp;
504 unsigned long lifespan;
505 const char * const *names;
506 int num_counters;
507 u64 value[];
7f624d02
SW
508};
509
b40f4757
CL
510#define RDMA_HW_STATS_DEFAULT_LIFESPAN 10
511/**
512 * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct
513 * for drivers.
514 * @names - Array of static const char *
515 * @num_counters - How many elements in array
516 * @lifespan - How many milliseconds between updates
517 */
518static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
519 const char * const *names, int num_counters,
520 unsigned long lifespan)
521{
522 struct rdma_hw_stats *stats;
523
524 stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
525 GFP_KERNEL);
526 if (!stats)
527 return NULL;
528 stats->names = names;
529 stats->num_counters = num_counters;
530 stats->lifespan = msecs_to_jiffies(lifespan);
531
532 return stats;
533}
534
535
f9b22e35
IW
536/* Define bits for the various functionality this port needs to be supported by
537 * the core.
538 */
539/* Management 0x00000FFF */
540#define RDMA_CORE_CAP_IB_MAD 0x00000001
541#define RDMA_CORE_CAP_IB_SMI 0x00000002
542#define RDMA_CORE_CAP_IB_CM 0x00000004
543#define RDMA_CORE_CAP_IW_CM 0x00000008
544#define RDMA_CORE_CAP_IB_SA 0x00000010
65995fee 545#define RDMA_CORE_CAP_OPA_MAD 0x00000020
f9b22e35
IW
546
547/* Address format 0x000FF000 */
548#define RDMA_CORE_CAP_AF_IB 0x00001000
549#define RDMA_CORE_CAP_ETH_AH 0x00002000
94d595c5 550#define RDMA_CORE_CAP_OPA_AH 0x00004000
b02289b3 551#define RDMA_CORE_CAP_IB_GRH_REQUIRED 0x00008000
f9b22e35
IW
552
553/* Protocol 0xFFF00000 */
554#define RDMA_CORE_CAP_PROT_IB 0x00100000
555#define RDMA_CORE_CAP_PROT_ROCE 0x00200000
556#define RDMA_CORE_CAP_PROT_IWARP 0x00400000
7766a99f 557#define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
aa773bd4 558#define RDMA_CORE_CAP_PROT_RAW_PACKET 0x01000000
ce1e055f 559#define RDMA_CORE_CAP_PROT_USNIC 0x02000000
f9b22e35 560
b02289b3
AK
561#define RDMA_CORE_PORT_IB_GRH_REQUIRED (RDMA_CORE_CAP_IB_GRH_REQUIRED \
562 | RDMA_CORE_CAP_PROT_ROCE \
563 | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP)
564
f9b22e35
IW
565#define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \
566 | RDMA_CORE_CAP_IB_MAD \
567 | RDMA_CORE_CAP_IB_SMI \
568 | RDMA_CORE_CAP_IB_CM \
569 | RDMA_CORE_CAP_IB_SA \
570 | RDMA_CORE_CAP_AF_IB)
571#define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \
572 | RDMA_CORE_CAP_IB_MAD \
573 | RDMA_CORE_CAP_IB_CM \
f9b22e35
IW
574 | RDMA_CORE_CAP_AF_IB \
575 | RDMA_CORE_CAP_ETH_AH)
7766a99f
MB
576#define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \
577 (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
578 | RDMA_CORE_CAP_IB_MAD \
579 | RDMA_CORE_CAP_IB_CM \
580 | RDMA_CORE_CAP_AF_IB \
581 | RDMA_CORE_CAP_ETH_AH)
f9b22e35
IW
582#define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \
583 | RDMA_CORE_CAP_IW_CM)
65995fee
IW
584#define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \
585 | RDMA_CORE_CAP_OPA_MAD)
f9b22e35 586
aa773bd4
OG
587#define RDMA_CORE_PORT_RAW_PACKET (RDMA_CORE_CAP_PROT_RAW_PACKET)
588
ce1e055f
OG
589#define RDMA_CORE_PORT_USNIC (RDMA_CORE_CAP_PROT_USNIC)
590
1da177e4 591struct ib_port_attr {
fad61ad4 592 u64 subnet_prefix;
1da177e4
LT
593 enum ib_port_state state;
594 enum ib_mtu max_mtu;
595 enum ib_mtu active_mtu;
596 int gid_tbl_len;
2f944c0f
JG
597 unsigned int ip_gids:1;
598 /* This is the value from PortInfo CapabilityMask, defined by IBA */
1da177e4
LT
599 u32 port_cap_flags;
600 u32 max_msg_sz;
601 u32 bad_pkey_cntr;
602 u32 qkey_viol_cntr;
603 u16 pkey_tbl_len;
db58540b 604 u32 sm_lid;
582faf31 605 u32 lid;
1da177e4
LT
606 u8 lmc;
607 u8 max_vl_num;
608 u8 sm_sl;
609 u8 subnet_timeout;
610 u8 init_type_reply;
611 u8 active_width;
612 u8 active_speed;
613 u8 phys_state;
1e8f43b7 614 u16 port_cap_flags2;
1da177e4
LT
615};
616
617enum ib_device_modify_flags {
c5bcbbb9
RD
618 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
619 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
1da177e4
LT
620};
621
bd99fdea
YS
622#define IB_DEVICE_NODE_DESC_MAX 64
623
1da177e4
LT
624struct ib_device_modify {
625 u64 sys_image_guid;
bd99fdea 626 char node_desc[IB_DEVICE_NODE_DESC_MAX];
1da177e4
LT
627};
628
629enum ib_port_modify_flags {
630 IB_PORT_SHUTDOWN = 1,
631 IB_PORT_INIT_TYPE = (1<<2),
cb49366f
VN
632 IB_PORT_RESET_QKEY_CNTR = (1<<3),
633 IB_PORT_OPA_MASK_CHG = (1<<4)
1da177e4
LT
634};
635
636struct ib_port_modify {
637 u32 set_port_cap_mask;
638 u32 clr_port_cap_mask;
639 u8 init_type;
640};
641
642enum ib_event_type {
643 IB_EVENT_CQ_ERR,
644 IB_EVENT_QP_FATAL,
645 IB_EVENT_QP_REQ_ERR,
646 IB_EVENT_QP_ACCESS_ERR,
647 IB_EVENT_COMM_EST,
648 IB_EVENT_SQ_DRAINED,
649 IB_EVENT_PATH_MIG,
650 IB_EVENT_PATH_MIG_ERR,
651 IB_EVENT_DEVICE_FATAL,
652 IB_EVENT_PORT_ACTIVE,
653 IB_EVENT_PORT_ERR,
654 IB_EVENT_LID_CHANGE,
655 IB_EVENT_PKEY_CHANGE,
d41fcc67
RD
656 IB_EVENT_SM_CHANGE,
657 IB_EVENT_SRQ_ERR,
658 IB_EVENT_SRQ_LIMIT_REACHED,
63942c9a 659 IB_EVENT_QP_LAST_WQE_REACHED,
761d90ed
OG
660 IB_EVENT_CLIENT_REREGISTER,
661 IB_EVENT_GID_CHANGE,
f213c052 662 IB_EVENT_WQ_FATAL,
1da177e4
LT
663};
664
db7489e0 665const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
2b1b5b60 666
1da177e4
LT
667struct ib_event {
668 struct ib_device *device;
669 union {
670 struct ib_cq *cq;
671 struct ib_qp *qp;
d41fcc67 672 struct ib_srq *srq;
f213c052 673 struct ib_wq *wq;
1da177e4
LT
674 u8 port_num;
675 } element;
676 enum ib_event_type event;
677};
678
679struct ib_event_handler {
680 struct ib_device *device;
681 void (*handler)(struct ib_event_handler *, struct ib_event *);
682 struct list_head list;
683};
684
685#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
686 do { \
687 (_ptr)->device = _device; \
688 (_ptr)->handler = _handler; \
689 INIT_LIST_HEAD(&(_ptr)->list); \
690 } while (0)
691
692struct ib_global_route {
8d9ec9ad 693 const struct ib_gid_attr *sgid_attr;
1da177e4
LT
694 union ib_gid dgid;
695 u32 flow_label;
696 u8 sgid_index;
697 u8 hop_limit;
698 u8 traffic_class;
699};
700
513789ed 701struct ib_grh {
97f52eb4
SH
702 __be32 version_tclass_flow;
703 __be16 paylen;
513789ed
HR
704 u8 next_hdr;
705 u8 hop_limit;
706 union ib_gid sgid;
707 union ib_gid dgid;
708};
709
c865f246
SK
710union rdma_network_hdr {
711 struct ib_grh ibgrh;
712 struct {
713 /* The IB spec states that if it's IPv4, the header
714 * is located in the last 20 bytes of the header.
715 */
716 u8 reserved[20];
717 struct iphdr roce4grh;
718 };
719};
720
7dafbab3
DH
721#define IB_QPN_MASK 0xFFFFFF
722
1da177e4
LT
723enum {
724 IB_MULTICAST_QPN = 0xffffff
725};
726
f3a7c66b 727#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
b4e64397 728#define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000)
97f52eb4 729
1da177e4
LT
730enum ib_ah_flags {
731 IB_AH_GRH = 1
732};
733
bf6a9e31
JM
734enum ib_rate {
735 IB_RATE_PORT_CURRENT = 0,
736 IB_RATE_2_5_GBPS = 2,
737 IB_RATE_5_GBPS = 5,
738 IB_RATE_10_GBPS = 3,
739 IB_RATE_20_GBPS = 6,
740 IB_RATE_30_GBPS = 4,
741 IB_RATE_40_GBPS = 7,
742 IB_RATE_60_GBPS = 8,
743 IB_RATE_80_GBPS = 9,
71eeba16
MA
744 IB_RATE_120_GBPS = 10,
745 IB_RATE_14_GBPS = 11,
746 IB_RATE_56_GBPS = 12,
747 IB_RATE_112_GBPS = 13,
748 IB_RATE_168_GBPS = 14,
749 IB_RATE_25_GBPS = 15,
750 IB_RATE_100_GBPS = 16,
751 IB_RATE_200_GBPS = 17,
a5a5d199
MG
752 IB_RATE_300_GBPS = 18,
753 IB_RATE_28_GBPS = 19,
754 IB_RATE_50_GBPS = 20,
755 IB_RATE_400_GBPS = 21,
756 IB_RATE_600_GBPS = 22,
bf6a9e31
JM
757};
758
759/**
760 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
761 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
762 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
763 * @rate: rate to convert.
764 */
8385fd84 765__attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
bf6a9e31 766
71eeba16
MA
767/**
768 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
769 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
770 * @rate: rate to convert.
771 */
8385fd84 772__attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
71eeba16 773
17cd3a2d
SG
774
775/**
9bee178b
SG
776 * enum ib_mr_type - memory region type
777 * @IB_MR_TYPE_MEM_REG: memory region that is used for
778 * normal registration
779 * @IB_MR_TYPE_SIGNATURE: memory region that is used for
780 * signature operations (data-integrity
781 * capable regions)
f5aa9159
SG
782 * @IB_MR_TYPE_SG_GAPS: memory region that is capable to
783 * register any arbitrary sg lists (without
784 * the normal mr constraints - see
785 * ib_map_mr_sg)
a0bc099a
MG
786 * @IB_MR_TYPE_DM: memory region that is used for device
787 * memory registration
788 * @IB_MR_TYPE_USER: memory region that is used for the user-space
789 * application
790 * @IB_MR_TYPE_DMA: memory region that is used for DMA operations
791 * without address translations (VA=PA)
26bc7eae
IR
792 * @IB_MR_TYPE_INTEGRITY: memory region that is used for
793 * data integrity operations
17cd3a2d 794 */
9bee178b
SG
795enum ib_mr_type {
796 IB_MR_TYPE_MEM_REG,
797 IB_MR_TYPE_SIGNATURE,
f5aa9159 798 IB_MR_TYPE_SG_GAPS,
a0bc099a
MG
799 IB_MR_TYPE_DM,
800 IB_MR_TYPE_USER,
801 IB_MR_TYPE_DMA,
26bc7eae 802 IB_MR_TYPE_INTEGRITY,
17cd3a2d
SG
803};
804
1b01d335
SG
805enum ib_mr_status_check {
806 IB_MR_CHECK_SIG_STATUS = 1,
807};
808
809/**
810 * struct ib_mr_status - Memory region status container
811 *
812 * @fail_status: Bitmask of MR checks status. For each
813 * failed check a corresponding status bit is set.
814 * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
815 * failure.
816 */
817struct ib_mr_status {
818 u32 fail_status;
819 struct ib_sig_err sig_err;
820};
821
bf6a9e31
JM
822/**
823 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
824 * enum.
825 * @mult: multiple to convert.
826 */
8385fd84 827__attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
bf6a9e31 828
44c58487 829enum rdma_ah_attr_type {
87daac68 830 RDMA_AH_ATTR_TYPE_UNDEFINED,
44c58487
DC
831 RDMA_AH_ATTR_TYPE_IB,
832 RDMA_AH_ATTR_TYPE_ROCE,
64b4646e 833 RDMA_AH_ATTR_TYPE_OPA,
44c58487
DC
834};
835
836struct ib_ah_attr {
837 u16 dlid;
838 u8 src_path_bits;
839};
840
841struct roce_ah_attr {
842 u8 dmac[ETH_ALEN];
843};
844
64b4646e
DC
845struct opa_ah_attr {
846 u32 dlid;
847 u8 src_path_bits;
d98bb7f7 848 bool make_grd;
64b4646e
DC
849};
850
90898850 851struct rdma_ah_attr {
1da177e4 852 struct ib_global_route grh;
1da177e4 853 u8 sl;
1da177e4 854 u8 static_rate;
1da177e4 855 u8 port_num;
44c58487
DC
856 u8 ah_flags;
857 enum rdma_ah_attr_type type;
858 union {
859 struct ib_ah_attr ib;
860 struct roce_ah_attr roce;
64b4646e 861 struct opa_ah_attr opa;
44c58487 862 };
1da177e4
LT
863};
864
865enum ib_wc_status {
866 IB_WC_SUCCESS,
867 IB_WC_LOC_LEN_ERR,
868 IB_WC_LOC_QP_OP_ERR,
869 IB_WC_LOC_EEC_OP_ERR,
870 IB_WC_LOC_PROT_ERR,
871 IB_WC_WR_FLUSH_ERR,
872 IB_WC_MW_BIND_ERR,
873 IB_WC_BAD_RESP_ERR,
874 IB_WC_LOC_ACCESS_ERR,
875 IB_WC_REM_INV_REQ_ERR,
876 IB_WC_REM_ACCESS_ERR,
877 IB_WC_REM_OP_ERR,
878 IB_WC_RETRY_EXC_ERR,
879 IB_WC_RNR_RETRY_EXC_ERR,
880 IB_WC_LOC_RDD_VIOL_ERR,
881 IB_WC_REM_INV_RD_REQ_ERR,
882 IB_WC_REM_ABORT_ERR,
883 IB_WC_INV_EECN_ERR,
884 IB_WC_INV_EEC_STATE_ERR,
885 IB_WC_FATAL_ERR,
886 IB_WC_RESP_TIMEOUT_ERR,
887 IB_WC_GENERAL_ERR
888};
889
db7489e0 890const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
2b1b5b60 891
1da177e4
LT
892enum ib_wc_opcode {
893 IB_WC_SEND,
894 IB_WC_RDMA_WRITE,
895 IB_WC_RDMA_READ,
896 IB_WC_COMP_SWAP,
897 IB_WC_FETCH_ADD,
c93570f2 898 IB_WC_LSO,
00f7ec36 899 IB_WC_LOCAL_INV,
4c67e2bf 900 IB_WC_REG_MR,
5e80ba8f
VS
901 IB_WC_MASKED_COMP_SWAP,
902 IB_WC_MASKED_FETCH_ADD,
1da177e4
LT
903/*
904 * Set value of IB_WC_RECV so consumers can test if a completion is a
905 * receive by testing (opcode & IB_WC_RECV).
906 */
907 IB_WC_RECV = 1 << 7,
908 IB_WC_RECV_RDMA_WITH_IMM
909};
910
911enum ib_wc_flags {
912 IB_WC_GRH = 1,
00f7ec36
SW
913 IB_WC_WITH_IMM = (1<<1),
914 IB_WC_WITH_INVALIDATE = (1<<2),
d927d505 915 IB_WC_IP_CSUM_OK = (1<<3),
dd5f03be
MB
916 IB_WC_WITH_SMAC = (1<<4),
917 IB_WC_WITH_VLAN = (1<<5),
c865f246 918 IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6),
1da177e4
LT
919};
920
921struct ib_wc {
14d3a3b2
CH
922 union {
923 u64 wr_id;
924 struct ib_cqe *wr_cqe;
925 };
1da177e4
LT
926 enum ib_wc_status status;
927 enum ib_wc_opcode opcode;
928 u32 vendor_err;
929 u32 byte_len;
062dbb69 930 struct ib_qp *qp;
00f7ec36
SW
931 union {
932 __be32 imm_data;
933 u32 invalidate_rkey;
934 } ex;
1da177e4 935 u32 src_qp;
cd2a6e7d 936 u32 slid;
1da177e4
LT
937 int wc_flags;
938 u16 pkey_index;
1da177e4
LT
939 u8 sl;
940 u8 dlid_path_bits;
941 u8 port_num; /* valid only for DR SMPs on switches */
dd5f03be
MB
942 u8 smac[ETH_ALEN];
943 u16 vlan_id;
c865f246 944 u8 network_hdr_type;
1da177e4
LT
945};
946
ed23a727
RD
947enum ib_cq_notify_flags {
948 IB_CQ_SOLICITED = 1 << 0,
949 IB_CQ_NEXT_COMP = 1 << 1,
950 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
951 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
1da177e4
LT
952};
953
96104eda 954enum ib_srq_type {
418d5130 955 IB_SRQT_BASIC,
9c2c8496
AK
956 IB_SRQT_XRC,
957 IB_SRQT_TM,
96104eda
SH
958};
959
1a56ff6d
AK
960static inline bool ib_srq_has_cq(enum ib_srq_type srq_type)
961{
9c2c8496
AK
962 return srq_type == IB_SRQT_XRC ||
963 srq_type == IB_SRQT_TM;
1a56ff6d
AK
964}
965
d41fcc67
RD
966enum ib_srq_attr_mask {
967 IB_SRQ_MAX_WR = 1 << 0,
968 IB_SRQ_LIMIT = 1 << 1,
969};
970
971struct ib_srq_attr {
972 u32 max_wr;
973 u32 max_sge;
974 u32 srq_limit;
975};
976
977struct ib_srq_init_attr {
978 void (*event_handler)(struct ib_event *, void *);
979 void *srq_context;
980 struct ib_srq_attr attr;
96104eda 981 enum ib_srq_type srq_type;
418d5130 982
1a56ff6d
AK
983 struct {
984 struct ib_cq *cq;
985 union {
986 struct {
987 struct ib_xrcd *xrcd;
988 } xrc;
9c2c8496
AK
989
990 struct {
991 u32 max_num_tags;
992 } tag_matching;
1a56ff6d 993 };
418d5130 994 } ext;
d41fcc67
RD
995};
996
1da177e4
LT
997struct ib_qp_cap {
998 u32 max_send_wr;
999 u32 max_recv_wr;
1000 u32 max_send_sge;
1001 u32 max_recv_sge;
1002 u32 max_inline_data;
a060b562
CH
1003
1004 /*
1005 * Maximum number of rdma_rw_ctx structures in flight at a time.
1006 * ib_create_qp() will calculate the right amount of neededed WRs
1007 * and MRs based on this.
1008 */
1009 u32 max_rdma_ctxs;
1da177e4
LT
1010};
1011
1012enum ib_sig_type {
1013 IB_SIGNAL_ALL_WR,
1014 IB_SIGNAL_REQ_WR
1015};
1016
1017enum ib_qp_type {
1018 /*
1019 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
1020 * here (and in that order) since the MAD layer uses them as
1021 * indices into a 2-entry table.
1022 */
1023 IB_QPT_SMI,
1024 IB_QPT_GSI,
1025
1026 IB_QPT_RC,
1027 IB_QPT_UC,
1028 IB_QPT_UD,
1029 IB_QPT_RAW_IPV6,
b42b63cf 1030 IB_QPT_RAW_ETHERTYPE,
c938a616 1031 IB_QPT_RAW_PACKET = 8,
b42b63cf
SH
1032 IB_QPT_XRC_INI = 9,
1033 IB_QPT_XRC_TGT,
0134f16b 1034 IB_QPT_MAX,
8011c1e3 1035 IB_QPT_DRIVER = 0xFF,
0134f16b
JM
1036 /* Reserve a range for qp types internal to the low level driver.
1037 * These qp types will not be visible at the IB core layer, so the
1038 * IB_QPT_MAX usages should not be affected in the core layer
1039 */
1040 IB_QPT_RESERVED1 = 0x1000,
1041 IB_QPT_RESERVED2,
1042 IB_QPT_RESERVED3,
1043 IB_QPT_RESERVED4,
1044 IB_QPT_RESERVED5,
1045 IB_QPT_RESERVED6,
1046 IB_QPT_RESERVED7,
1047 IB_QPT_RESERVED8,
1048 IB_QPT_RESERVED9,
1049 IB_QPT_RESERVED10,
1da177e4
LT
1050};
1051
b846f25a 1052enum ib_qp_create_flags {
47ee1b9f
RL
1053 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
1054 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
8a06ce59
LR
1055 IB_QP_CREATE_CROSS_CHANNEL = 1 << 2,
1056 IB_QP_CREATE_MANAGED_SEND = 1 << 3,
1057 IB_QP_CREATE_MANAGED_RECV = 1 << 4,
90f1d1b4 1058 IB_QP_CREATE_NETIF_QP = 1 << 5,
1b01d335 1059 IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
7855f584 1060 /* FREE = 1 << 7, */
b531b909 1061 IB_QP_CREATE_SCATTER_FCS = 1 << 8,
9c2b270e 1062 IB_QP_CREATE_CVLAN_STRIPPING = 1 << 9,
02984cc7 1063 IB_QP_CREATE_SOURCE_QPN = 1 << 10,
e1d2e887 1064 IB_QP_CREATE_PCI_WRITE_END_PADDING = 1 << 11,
d2b57063
JM
1065 /* reserve bits 26-31 for low level drivers' internal use */
1066 IB_QP_CREATE_RESERVED_START = 1 << 26,
1067 IB_QP_CREATE_RESERVED_END = 1 << 31,
b846f25a
EC
1068};
1069
73c40c61
YH
1070/*
1071 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
1072 * callback to destroy the passed in QP.
1073 */
1074
1da177e4 1075struct ib_qp_init_attr {
eb93c82e 1076 /* Consumer's event_handler callback must not block */
1da177e4 1077 void (*event_handler)(struct ib_event *, void *);
eb93c82e 1078
1da177e4
LT
1079 void *qp_context;
1080 struct ib_cq *send_cq;
1081 struct ib_cq *recv_cq;
1082 struct ib_srq *srq;
b42b63cf 1083 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
1da177e4
LT
1084 struct ib_qp_cap cap;
1085 enum ib_sig_type sq_sig_type;
1086 enum ib_qp_type qp_type;
b56511c1 1087 u32 create_flags;
a060b562
CH
1088
1089 /*
1090 * Only needed for special QP types, or when using the RW API.
1091 */
1092 u8 port_num;
a9017e23 1093 struct ib_rwq_ind_table *rwq_ind_tbl;
02984cc7 1094 u32 source_qpn;
1da177e4
LT
1095};
1096
0e0ec7e0
SH
1097struct ib_qp_open_attr {
1098 void (*event_handler)(struct ib_event *, void *);
1099 void *qp_context;
1100 u32 qp_num;
1101 enum ib_qp_type qp_type;
1102};
1103
1da177e4
LT
1104enum ib_rnr_timeout {
1105 IB_RNR_TIMER_655_36 = 0,
1106 IB_RNR_TIMER_000_01 = 1,
1107 IB_RNR_TIMER_000_02 = 2,
1108 IB_RNR_TIMER_000_03 = 3,
1109 IB_RNR_TIMER_000_04 = 4,
1110 IB_RNR_TIMER_000_06 = 5,
1111 IB_RNR_TIMER_000_08 = 6,
1112 IB_RNR_TIMER_000_12 = 7,
1113 IB_RNR_TIMER_000_16 = 8,
1114 IB_RNR_TIMER_000_24 = 9,
1115 IB_RNR_TIMER_000_32 = 10,
1116 IB_RNR_TIMER_000_48 = 11,
1117 IB_RNR_TIMER_000_64 = 12,
1118 IB_RNR_TIMER_000_96 = 13,
1119 IB_RNR_TIMER_001_28 = 14,
1120 IB_RNR_TIMER_001_92 = 15,
1121 IB_RNR_TIMER_002_56 = 16,
1122 IB_RNR_TIMER_003_84 = 17,
1123 IB_RNR_TIMER_005_12 = 18,
1124 IB_RNR_TIMER_007_68 = 19,
1125 IB_RNR_TIMER_010_24 = 20,
1126 IB_RNR_TIMER_015_36 = 21,
1127 IB_RNR_TIMER_020_48 = 22,
1128 IB_RNR_TIMER_030_72 = 23,
1129 IB_RNR_TIMER_040_96 = 24,
1130 IB_RNR_TIMER_061_44 = 25,
1131 IB_RNR_TIMER_081_92 = 26,
1132 IB_RNR_TIMER_122_88 = 27,
1133 IB_RNR_TIMER_163_84 = 28,
1134 IB_RNR_TIMER_245_76 = 29,
1135 IB_RNR_TIMER_327_68 = 30,
1136 IB_RNR_TIMER_491_52 = 31
1137};
1138
1139enum ib_qp_attr_mask {
1140 IB_QP_STATE = 1,
1141 IB_QP_CUR_STATE = (1<<1),
1142 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
1143 IB_QP_ACCESS_FLAGS = (1<<3),
1144 IB_QP_PKEY_INDEX = (1<<4),
1145 IB_QP_PORT = (1<<5),
1146 IB_QP_QKEY = (1<<6),
1147 IB_QP_AV = (1<<7),
1148 IB_QP_PATH_MTU = (1<<8),
1149 IB_QP_TIMEOUT = (1<<9),
1150 IB_QP_RETRY_CNT = (1<<10),
1151 IB_QP_RNR_RETRY = (1<<11),
1152 IB_QP_RQ_PSN = (1<<12),
1153 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
1154 IB_QP_ALT_PATH = (1<<14),
1155 IB_QP_MIN_RNR_TIMER = (1<<15),
1156 IB_QP_SQ_PSN = (1<<16),
1157 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
1158 IB_QP_PATH_MIG_STATE = (1<<18),
1159 IB_QP_CAP = (1<<19),
dd5f03be 1160 IB_QP_DEST_QPN = (1<<20),
aa744cc0
MB
1161 IB_QP_RESERVED1 = (1<<21),
1162 IB_QP_RESERVED2 = (1<<22),
1163 IB_QP_RESERVED3 = (1<<23),
1164 IB_QP_RESERVED4 = (1<<24),
528e5a1b 1165 IB_QP_RATE_LIMIT = (1<<25),
1da177e4
LT
1166};
1167
1168enum ib_qp_state {
1169 IB_QPS_RESET,
1170 IB_QPS_INIT,
1171 IB_QPS_RTR,
1172 IB_QPS_RTS,
1173 IB_QPS_SQD,
1174 IB_QPS_SQE,
1175 IB_QPS_ERR
1176};
1177
1178enum ib_mig_state {
1179 IB_MIG_MIGRATED,
1180 IB_MIG_REARM,
1181 IB_MIG_ARMED
1182};
1183
7083e42e
SM
1184enum ib_mw_type {
1185 IB_MW_TYPE_1 = 1,
1186 IB_MW_TYPE_2 = 2
1187};
1188
1da177e4
LT
1189struct ib_qp_attr {
1190 enum ib_qp_state qp_state;
1191 enum ib_qp_state cur_qp_state;
1192 enum ib_mtu path_mtu;
1193 enum ib_mig_state path_mig_state;
1194 u32 qkey;
1195 u32 rq_psn;
1196 u32 sq_psn;
1197 u32 dest_qp_num;
1198 int qp_access_flags;
1199 struct ib_qp_cap cap;
90898850
DC
1200 struct rdma_ah_attr ah_attr;
1201 struct rdma_ah_attr alt_ah_attr;
1da177e4
LT
1202 u16 pkey_index;
1203 u16 alt_pkey_index;
1204 u8 en_sqd_async_notify;
1205 u8 sq_draining;
1206 u8 max_rd_atomic;
1207 u8 max_dest_rd_atomic;
1208 u8 min_rnr_timer;
1209 u8 port_num;
1210 u8 timeout;
1211 u8 retry_cnt;
1212 u8 rnr_retry;
1213 u8 alt_port_num;
1214 u8 alt_timeout;
528e5a1b 1215 u32 rate_limit;
1da177e4
LT
1216};
1217
1218enum ib_wr_opcode {
9a59739b
JG
1219 /* These are shared with userspace */
1220 IB_WR_RDMA_WRITE = IB_UVERBS_WR_RDMA_WRITE,
1221 IB_WR_RDMA_WRITE_WITH_IMM = IB_UVERBS_WR_RDMA_WRITE_WITH_IMM,
1222 IB_WR_SEND = IB_UVERBS_WR_SEND,
1223 IB_WR_SEND_WITH_IMM = IB_UVERBS_WR_SEND_WITH_IMM,
1224 IB_WR_RDMA_READ = IB_UVERBS_WR_RDMA_READ,
1225 IB_WR_ATOMIC_CMP_AND_SWP = IB_UVERBS_WR_ATOMIC_CMP_AND_SWP,
1226 IB_WR_ATOMIC_FETCH_AND_ADD = IB_UVERBS_WR_ATOMIC_FETCH_AND_ADD,
1227 IB_WR_LSO = IB_UVERBS_WR_TSO,
1228 IB_WR_SEND_WITH_INV = IB_UVERBS_WR_SEND_WITH_INV,
1229 IB_WR_RDMA_READ_WITH_INV = IB_UVERBS_WR_RDMA_READ_WITH_INV,
1230 IB_WR_LOCAL_INV = IB_UVERBS_WR_LOCAL_INV,
1231 IB_WR_MASKED_ATOMIC_CMP_AND_SWP =
1232 IB_UVERBS_WR_MASKED_ATOMIC_CMP_AND_SWP,
1233 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD =
1234 IB_UVERBS_WR_MASKED_ATOMIC_FETCH_AND_ADD,
1235
1236 /* These are kernel only and can not be issued by userspace */
1237 IB_WR_REG_MR = 0x20,
1b01d335 1238 IB_WR_REG_SIG_MR,
38ca87c6 1239 IB_WR_REG_MR_INTEGRITY,
9a59739b 1240
0134f16b
JM
1241 /* reserve values for low level drivers' internal use.
1242 * These values will not be used at all in the ib core layer.
1243 */
1244 IB_WR_RESERVED1 = 0xf0,
1245 IB_WR_RESERVED2,
1246 IB_WR_RESERVED3,
1247 IB_WR_RESERVED4,
1248 IB_WR_RESERVED5,
1249 IB_WR_RESERVED6,
1250 IB_WR_RESERVED7,
1251 IB_WR_RESERVED8,
1252 IB_WR_RESERVED9,
1253 IB_WR_RESERVED10,
1da177e4
LT
1254};
1255
1256enum ib_send_flags {
1257 IB_SEND_FENCE = 1,
1258 IB_SEND_SIGNALED = (1<<1),
1259 IB_SEND_SOLICITED = (1<<2),
e0605d91 1260 IB_SEND_INLINE = (1<<3),
0134f16b
JM
1261 IB_SEND_IP_CSUM = (1<<4),
1262
1263 /* reserve bits 26-31 for low level drivers' internal use */
1264 IB_SEND_RESERVED_START = (1 << 26),
1265 IB_SEND_RESERVED_END = (1 << 31),
1da177e4
LT
1266};
1267
1268struct ib_sge {
1269 u64 addr;
1270 u32 length;
1271 u32 lkey;
1272};
1273
14d3a3b2
CH
1274struct ib_cqe {
1275 void (*done)(struct ib_cq *cq, struct ib_wc *wc);
1276};
1277
1da177e4
LT
1278struct ib_send_wr {
1279 struct ib_send_wr *next;
14d3a3b2
CH
1280 union {
1281 u64 wr_id;
1282 struct ib_cqe *wr_cqe;
1283 };
1da177e4
LT
1284 struct ib_sge *sg_list;
1285 int num_sge;
1286 enum ib_wr_opcode opcode;
1287 int send_flags;
0f39cf3d
RD
1288 union {
1289 __be32 imm_data;
1290 u32 invalidate_rkey;
1291 } ex;
1da177e4
LT
1292};
1293
e622f2f4
CH
1294struct ib_rdma_wr {
1295 struct ib_send_wr wr;
1296 u64 remote_addr;
1297 u32 rkey;
1298};
1299
f696bf6d 1300static inline const struct ib_rdma_wr *rdma_wr(const struct ib_send_wr *wr)
e622f2f4
CH
1301{
1302 return container_of(wr, struct ib_rdma_wr, wr);
1303}
1304
1305struct ib_atomic_wr {
1306 struct ib_send_wr wr;
1307 u64 remote_addr;
1308 u64 compare_add;
1309 u64 swap;
1310 u64 compare_add_mask;
1311 u64 swap_mask;
1312 u32 rkey;
1313};
1314
f696bf6d 1315static inline const struct ib_atomic_wr *atomic_wr(const struct ib_send_wr *wr)
e622f2f4
CH
1316{
1317 return container_of(wr, struct ib_atomic_wr, wr);
1318}
1319
1320struct ib_ud_wr {
1321 struct ib_send_wr wr;
1322 struct ib_ah *ah;
1323 void *header;
1324 int hlen;
1325 int mss;
1326 u32 remote_qpn;
1327 u32 remote_qkey;
1328 u16 pkey_index; /* valid for GSI only */
1329 u8 port_num; /* valid for DR SMPs on switch only */
1330};
1331
f696bf6d 1332static inline const struct ib_ud_wr *ud_wr(const struct ib_send_wr *wr)
e622f2f4
CH
1333{
1334 return container_of(wr, struct ib_ud_wr, wr);
1335}
1336
4c67e2bf
SG
1337struct ib_reg_wr {
1338 struct ib_send_wr wr;
1339 struct ib_mr *mr;
1340 u32 key;
1341 int access;
1342};
1343
f696bf6d 1344static inline const struct ib_reg_wr *reg_wr(const struct ib_send_wr *wr)
4c67e2bf
SG
1345{
1346 return container_of(wr, struct ib_reg_wr, wr);
1347}
1348
e622f2f4
CH
1349struct ib_sig_handover_wr {
1350 struct ib_send_wr wr;
1351 struct ib_sig_attrs *sig_attrs;
1352 struct ib_mr *sig_mr;
1353 int access_flags;
1354 struct ib_sge *prot;
1355};
1356
f696bf6d
BVA
1357static inline const struct ib_sig_handover_wr *
1358sig_handover_wr(const struct ib_send_wr *wr)
e622f2f4
CH
1359{
1360 return container_of(wr, struct ib_sig_handover_wr, wr);
1361}
1362
1da177e4
LT
1363struct ib_recv_wr {
1364 struct ib_recv_wr *next;
14d3a3b2
CH
1365 union {
1366 u64 wr_id;
1367 struct ib_cqe *wr_cqe;
1368 };
1da177e4
LT
1369 struct ib_sge *sg_list;
1370 int num_sge;
1371};
1372
1373enum ib_access_flags {
4fca0377
JG
1374 IB_ACCESS_LOCAL_WRITE = IB_UVERBS_ACCESS_LOCAL_WRITE,
1375 IB_ACCESS_REMOTE_WRITE = IB_UVERBS_ACCESS_REMOTE_WRITE,
1376 IB_ACCESS_REMOTE_READ = IB_UVERBS_ACCESS_REMOTE_READ,
1377 IB_ACCESS_REMOTE_ATOMIC = IB_UVERBS_ACCESS_REMOTE_ATOMIC,
1378 IB_ACCESS_MW_BIND = IB_UVERBS_ACCESS_MW_BIND,
1379 IB_ZERO_BASED = IB_UVERBS_ACCESS_ZERO_BASED,
1380 IB_ACCESS_ON_DEMAND = IB_UVERBS_ACCESS_ON_DEMAND,
1381 IB_ACCESS_HUGETLB = IB_UVERBS_ACCESS_HUGETLB,
1382
1383 IB_ACCESS_SUPPORTED = ((IB_ACCESS_HUGETLB << 1) - 1)
1da177e4
LT
1384};
1385
b7d3e0a9
CH
1386/*
1387 * XXX: these are apparently used for ->rereg_user_mr, no idea why they
1388 * are hidden here instead of a uapi header!
1389 */
1da177e4
LT
1390enum ib_mr_rereg_flags {
1391 IB_MR_REREG_TRANS = 1,
1392 IB_MR_REREG_PD = (1<<1),
7e6edb9b
MB
1393 IB_MR_REREG_ACCESS = (1<<2),
1394 IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
1da177e4
LT
1395};
1396
1da177e4
LT
1397struct ib_fmr_attr {
1398 int max_pages;
1399 int max_maps;
d36f34aa 1400 u8 page_shift;
1da177e4
LT
1401};
1402
882214e2
HE
1403struct ib_umem;
1404
38321256 1405enum rdma_remove_reason {
1c77483e
YH
1406 /*
1407 * Userspace requested uobject deletion or initial try
1408 * to remove uobject via cleanup. Call could fail
1409 */
38321256
MB
1410 RDMA_REMOVE_DESTROY,
1411 /* Context deletion. This call should delete the actual object itself */
1412 RDMA_REMOVE_CLOSE,
1413 /* Driver is being hot-unplugged. This call should delete the actual object itself */
1414 RDMA_REMOVE_DRIVER_REMOVE,
87ad80ab
JG
1415 /* uobj is being cleaned-up before being committed */
1416 RDMA_REMOVE_ABORT,
38321256
MB
1417};
1418
43579b5f
PP
1419struct ib_rdmacg_object {
1420#ifdef CONFIG_CGROUP_RDMA
1421 struct rdma_cgroup *cg; /* owner rdma cgroup */
1422#endif
1423};
1424
e2773c06
RD
1425struct ib_ucontext {
1426 struct ib_device *device;
771addf6 1427 struct ib_uverbs_file *ufile;
e951747a
JG
1428 /*
1429 * 'closing' can be read by the driver only during a destroy callback,
1430 * it is set when we are closing the file descriptor and indicates
1431 * that mm_sem may be locked.
1432 */
6ceb6331 1433 bool closing;
8ada2c1c 1434
1c77483e 1435 bool cleanup_retryable;
38321256 1436
b5231b01 1437 void (*invalidate_range)(struct ib_umem_odp *umem_odp,
882214e2 1438 unsigned long start, unsigned long end);
f27a0d50
JG
1439 struct mutex per_mm_list_lock;
1440 struct list_head per_mm_list;
43579b5f
PP
1441
1442 struct ib_rdmacg_object cg_obj;
60615210
LR
1443 /*
1444 * Implementation details of the RDMA core, don't use in drivers:
1445 */
1446 struct rdma_restrack_entry res;
e2773c06
RD
1447};
1448
1449struct ib_uobject {
1450 u64 user_handle; /* handle given to us by userspace */
6a5e9c88
JG
1451 /* ufile & ucontext owning this object */
1452 struct ib_uverbs_file *ufile;
1453 /* FIXME, save memory: ufile->context == context */
e2773c06 1454 struct ib_ucontext *context; /* associated user context */
9ead190b 1455 void *object; /* containing object */
e2773c06 1456 struct list_head list; /* link to context's list */
43579b5f 1457 struct ib_rdmacg_object cg_obj; /* rdmacg object */
b3d636b0 1458 int id; /* index into kernel idr */
9ead190b 1459 struct kref ref;
38321256 1460 atomic_t usecnt; /* protects exclusive access */
d144da8c 1461 struct rcu_head rcu; /* kfree_rcu() overhead */
38321256 1462
6b0d08f4 1463 const struct uverbs_api_object *uapi_object;
e2773c06
RD
1464};
1465
e2773c06 1466struct ib_udata {
309243ec 1467 const void __user *inbuf;
e2773c06
RD
1468 void __user *outbuf;
1469 size_t inlen;
1470 size_t outlen;
1471};
1472
1da177e4 1473struct ib_pd {
96249d70 1474 u32 local_dma_lkey;
ed082d36 1475 u32 flags;
e2773c06
RD
1476 struct ib_device *device;
1477 struct ib_uobject *uobject;
1478 atomic_t usecnt; /* count all resources */
50d46335 1479
ed082d36
CH
1480 u32 unsafe_global_rkey;
1481
50d46335
CH
1482 /*
1483 * Implementation details of the RDMA core, don't use in drivers:
1484 */
1485 struct ib_mr *__internal_mr;
02d8883f 1486 struct rdma_restrack_entry res;
1da177e4
LT
1487};
1488
59991f94
SH
1489struct ib_xrcd {
1490 struct ib_device *device;
d3d72d90 1491 atomic_t usecnt; /* count all exposed resources */
53d0bd1e 1492 struct inode *inode;
d3d72d90
SH
1493
1494 struct mutex tgt_qp_mutex;
1495 struct list_head tgt_qp_list;
59991f94
SH
1496};
1497
1da177e4
LT
1498struct ib_ah {
1499 struct ib_device *device;
1500 struct ib_pd *pd;
e2773c06 1501 struct ib_uobject *uobject;
1a1f460f 1502 const struct ib_gid_attr *sgid_attr;
44c58487 1503 enum rdma_ah_attr_type type;
1da177e4
LT
1504};
1505
1506typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1507
14d3a3b2 1508enum ib_poll_context {
f794809a
JM
1509 IB_POLL_DIRECT, /* caller context, no hw completions */
1510 IB_POLL_SOFTIRQ, /* poll from softirq context */
1511 IB_POLL_WORKQUEUE, /* poll from workqueue */
1512 IB_POLL_UNBOUND_WORKQUEUE, /* poll from unbound workqueue */
14d3a3b2
CH
1513};
1514
1da177e4 1515struct ib_cq {
e2773c06
RD
1516 struct ib_device *device;
1517 struct ib_uobject *uobject;
1518 ib_comp_handler comp_handler;
1519 void (*event_handler)(struct ib_event *, void *);
4deccd6d 1520 void *cq_context;
e2773c06
RD
1521 int cqe;
1522 atomic_t usecnt; /* count number of work queues */
14d3a3b2
CH
1523 enum ib_poll_context poll_ctx;
1524 struct ib_wc *wc;
1525 union {
1526 struct irq_poll iop;
1527 struct work_struct work;
1528 };
f794809a 1529 struct workqueue_struct *comp_wq;
02d8883f
LR
1530 /*
1531 * Implementation details of the RDMA core, don't use in drivers:
1532 */
1533 struct rdma_restrack_entry res;
1da177e4
LT
1534};
1535
1536struct ib_srq {
d41fcc67
RD
1537 struct ib_device *device;
1538 struct ib_pd *pd;
1539 struct ib_uobject *uobject;
1540 void (*event_handler)(struct ib_event *, void *);
1541 void *srq_context;
96104eda 1542 enum ib_srq_type srq_type;
1da177e4 1543 atomic_t usecnt;
418d5130 1544
1a56ff6d
AK
1545 struct {
1546 struct ib_cq *cq;
1547 union {
1548 struct {
1549 struct ib_xrcd *xrcd;
1550 u32 srq_num;
1551 } xrc;
1552 };
418d5130 1553 } ext;
1da177e4
LT
1554};
1555
ebaaee25
NO
1556enum ib_raw_packet_caps {
1557 /* Strip cvlan from incoming packet and report it in the matching work
1558 * completion is supported.
1559 */
1560 IB_RAW_PACKET_CAP_CVLAN_STRIPPING = (1 << 0),
1561 /* Scatter FCS field of an incoming packet to host memory is supported.
1562 */
1563 IB_RAW_PACKET_CAP_SCATTER_FCS = (1 << 1),
1564 /* Checksum offloads are supported (for both send and receive). */
1565 IB_RAW_PACKET_CAP_IP_CSUM = (1 << 2),
7d9336d8
MG
1566 /* When a packet is received for an RQ with no receive WQEs, the
1567 * packet processing is delayed.
1568 */
1569 IB_RAW_PACKET_CAP_DELAY_DROP = (1 << 3),
ebaaee25
NO
1570};
1571
5fd251c8
YH
1572enum ib_wq_type {
1573 IB_WQT_RQ
1574};
1575
1576enum ib_wq_state {
1577 IB_WQS_RESET,
1578 IB_WQS_RDY,
1579 IB_WQS_ERR
1580};
1581
1582struct ib_wq {
1583 struct ib_device *device;
1584 struct ib_uobject *uobject;
1585 void *wq_context;
1586 void (*event_handler)(struct ib_event *, void *);
1587 struct ib_pd *pd;
1588 struct ib_cq *cq;
1589 u32 wq_num;
1590 enum ib_wq_state state;
1591 enum ib_wq_type wq_type;
1592 atomic_t usecnt;
1593};
1594
10bac72b
NO
1595enum ib_wq_flags {
1596 IB_WQ_FLAGS_CVLAN_STRIPPING = 1 << 0,
27b0df11 1597 IB_WQ_FLAGS_SCATTER_FCS = 1 << 1,
7d9336d8 1598 IB_WQ_FLAGS_DELAY_DROP = 1 << 2,
e1d2e887 1599 IB_WQ_FLAGS_PCI_WRITE_END_PADDING = 1 << 3,
10bac72b
NO
1600};
1601
5fd251c8
YH
1602struct ib_wq_init_attr {
1603 void *wq_context;
1604 enum ib_wq_type wq_type;
1605 u32 max_wr;
1606 u32 max_sge;
1607 struct ib_cq *cq;
1608 void (*event_handler)(struct ib_event *, void *);
10bac72b 1609 u32 create_flags; /* Use enum ib_wq_flags */
5fd251c8
YH
1610};
1611
1612enum ib_wq_attr_mask {
10bac72b
NO
1613 IB_WQ_STATE = 1 << 0,
1614 IB_WQ_CUR_STATE = 1 << 1,
1615 IB_WQ_FLAGS = 1 << 2,
5fd251c8
YH
1616};
1617
1618struct ib_wq_attr {
1619 enum ib_wq_state wq_state;
1620 enum ib_wq_state curr_wq_state;
10bac72b
NO
1621 u32 flags; /* Use enum ib_wq_flags */
1622 u32 flags_mask; /* Use enum ib_wq_flags */
5fd251c8
YH
1623};
1624
6d39786b
YH
1625struct ib_rwq_ind_table {
1626 struct ib_device *device;
1627 struct ib_uobject *uobject;
1628 atomic_t usecnt;
1629 u32 ind_tbl_num;
1630 u32 log_ind_tbl_size;
1631 struct ib_wq **ind_tbl;
1632};
1633
1634struct ib_rwq_ind_table_init_attr {
1635 u32 log_ind_tbl_size;
1636 /* Each entry is a pointer to Receive Work Queue */
1637 struct ib_wq **ind_tbl;
1638};
1639
d291f1a6
DJ
1640enum port_pkey_state {
1641 IB_PORT_PKEY_NOT_VALID = 0,
1642 IB_PORT_PKEY_VALID = 1,
1643 IB_PORT_PKEY_LISTED = 2,
1644};
1645
1646struct ib_qp_security;
1647
1648struct ib_port_pkey {
1649 enum port_pkey_state state;
1650 u16 pkey_index;
1651 u8 port_num;
1652 struct list_head qp_list;
1653 struct list_head to_error_list;
1654 struct ib_qp_security *sec;
1655};
1656
1657struct ib_ports_pkeys {
1658 struct ib_port_pkey main;
1659 struct ib_port_pkey alt;
1660};
1661
1662struct ib_qp_security {
1663 struct ib_qp *qp;
1664 struct ib_device *dev;
1665 /* Hold this mutex when changing port and pkey settings. */
1666 struct mutex mutex;
1667 struct ib_ports_pkeys *ports_pkeys;
1668 /* A list of all open shared QP handles. Required to enforce security
1669 * properly for all users of a shared QP.
1670 */
1671 struct list_head shared_qp_list;
1672 void *security;
1673 bool destroying;
1674 atomic_t error_list_count;
1675 struct completion error_complete;
1676 int error_comps_pending;
1677};
1678
632bc3f6
BVA
1679/*
1680 * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
1681 * @max_read_sge: Maximum SGE elements per RDMA READ request.
1682 */
1da177e4
LT
1683struct ib_qp {
1684 struct ib_device *device;
1685 struct ib_pd *pd;
1686 struct ib_cq *send_cq;
1687 struct ib_cq *recv_cq;
fffb0383
CH
1688 spinlock_t mr_lock;
1689 int mrs_used;
a060b562 1690 struct list_head rdma_mrs;
0e353e34 1691 struct list_head sig_mrs;
1da177e4 1692 struct ib_srq *srq;
b42b63cf 1693 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
d3d72d90 1694 struct list_head xrcd_list;
fffb0383 1695
319a441d
HHZ
1696 /* count times opened, mcast attaches, flow attaches */
1697 atomic_t usecnt;
0e0ec7e0
SH
1698 struct list_head open_list;
1699 struct ib_qp *real_qp;
e2773c06 1700 struct ib_uobject *uobject;
1da177e4
LT
1701 void (*event_handler)(struct ib_event *, void *);
1702 void *qp_context;
1a1f460f
JG
1703 /* sgid_attrs associated with the AV's */
1704 const struct ib_gid_attr *av_sgid_attr;
1705 const struct ib_gid_attr *alt_path_sgid_attr;
1da177e4 1706 u32 qp_num;
632bc3f6
BVA
1707 u32 max_write_sge;
1708 u32 max_read_sge;
1da177e4 1709 enum ib_qp_type qp_type;
a9017e23 1710 struct ib_rwq_ind_table *rwq_ind_tbl;
d291f1a6 1711 struct ib_qp_security *qp_sec;
498ca3c8 1712 u8 port;
02d8883f
LR
1713
1714 /*
1715 * Implementation details of the RDMA core, don't use in drivers:
1716 */
1717 struct rdma_restrack_entry res;
1da177e4
LT
1718};
1719
bee76d7a
AL
1720struct ib_dm {
1721 struct ib_device *device;
1722 u32 length;
1723 u32 flags;
1724 struct ib_uobject *uobject;
1725 atomic_t usecnt;
1726};
1727
1da177e4 1728struct ib_mr {
e2773c06
RD
1729 struct ib_device *device;
1730 struct ib_pd *pd;
e2773c06
RD
1731 u32 lkey;
1732 u32 rkey;
4c67e2bf 1733 u64 iova;
edd31551 1734 u64 length;
4c67e2bf 1735 unsigned int page_size;
a0bc099a 1736 enum ib_mr_type type;
d4a85c30 1737 bool need_inval;
fffb0383
CH
1738 union {
1739 struct ib_uobject *uobject; /* user */
1740 struct list_head qp_entry; /* FR */
1741 };
fccec5b8 1742
be934cca 1743 struct ib_dm *dm;
7c717d3a 1744 struct ib_sig_attrs *sig_attrs; /* only for IB_MR_TYPE_INTEGRITY MRs */
fccec5b8
SW
1745 /*
1746 * Implementation details of the RDMA core, don't use in drivers:
1747 */
1748 struct rdma_restrack_entry res;
1da177e4
LT
1749};
1750
1751struct ib_mw {
1752 struct ib_device *device;
1753 struct ib_pd *pd;
e2773c06 1754 struct ib_uobject *uobject;
1da177e4 1755 u32 rkey;
7083e42e 1756 enum ib_mw_type type;
1da177e4
LT
1757};
1758
1759struct ib_fmr {
1760 struct ib_device *device;
1761 struct ib_pd *pd;
1762 struct list_head list;
1763 u32 lkey;
1764 u32 rkey;
1765};
1766
319a441d
HHZ
1767/* Supported steering options */
1768enum ib_flow_attr_type {
1769 /* steering according to rule specifications */
1770 IB_FLOW_ATTR_NORMAL = 0x0,
1771 /* default unicast and multicast rule -
1772 * receive all Eth traffic which isn't steered to any QP
1773 */
1774 IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1775 /* default multicast rule -
1776 * receive all Eth multicast traffic which isn't steered to any QP
1777 */
1778 IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1779 /* sniffer rule - receive all port traffic */
1780 IB_FLOW_ATTR_SNIFFER = 0x3
1781};
1782
1783/* Supported steering header types */
1784enum ib_flow_spec_type {
1785 /* L2 headers*/
76bd23b3
MR
1786 IB_FLOW_SPEC_ETH = 0x20,
1787 IB_FLOW_SPEC_IB = 0x22,
319a441d 1788 /* L3 header*/
76bd23b3
MR
1789 IB_FLOW_SPEC_IPV4 = 0x30,
1790 IB_FLOW_SPEC_IPV6 = 0x31,
56ab0b38 1791 IB_FLOW_SPEC_ESP = 0x34,
319a441d 1792 /* L4 headers*/
76bd23b3
MR
1793 IB_FLOW_SPEC_TCP = 0x40,
1794 IB_FLOW_SPEC_UDP = 0x41,
0dbf3332 1795 IB_FLOW_SPEC_VXLAN_TUNNEL = 0x50,
d90e5e50 1796 IB_FLOW_SPEC_GRE = 0x51,
b04f0f03 1797 IB_FLOW_SPEC_MPLS = 0x60,
fbf46860 1798 IB_FLOW_SPEC_INNER = 0x100,
460d0198
MR
1799 /* Actions */
1800 IB_FLOW_SPEC_ACTION_TAG = 0x1000,
483a3966 1801 IB_FLOW_SPEC_ACTION_DROP = 0x1001,
9b828441 1802 IB_FLOW_SPEC_ACTION_HANDLE = 0x1002,
7eea23a5 1803 IB_FLOW_SPEC_ACTION_COUNT = 0x1003,
319a441d 1804};
240ae00e 1805#define IB_FLOW_SPEC_LAYER_MASK 0xF0
7eea23a5 1806#define IB_FLOW_SPEC_SUPPORT_LAYERS 10
22878dbc 1807
319a441d
HHZ
1808/* Flow steering rule priority is set according to it's domain.
1809 * Lower domain value means higher priority.
1810 */
1811enum ib_flow_domain {
1812 IB_FLOW_DOMAIN_USER,
1813 IB_FLOW_DOMAIN_ETHTOOL,
1814 IB_FLOW_DOMAIN_RFS,
1815 IB_FLOW_DOMAIN_NIC,
1816 IB_FLOW_DOMAIN_NUM /* Must be last */
1817};
1818
a3100a78
MV
1819enum ib_flow_flags {
1820 IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
21e82d3e
BP
1821 IB_FLOW_ATTR_FLAGS_EGRESS = 1UL << 2, /* Egress flow */
1822 IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 3 /* Must be last */
a3100a78
MV
1823};
1824
319a441d
HHZ
1825struct ib_flow_eth_filter {
1826 u8 dst_mac[6];
1827 u8 src_mac[6];
1828 __be16 ether_type;
1829 __be16 vlan_tag;
15dfbd6b
MG
1830 /* Must be last */
1831 u8 real_sz[0];
319a441d
HHZ
1832};
1833
1834struct ib_flow_spec_eth {
fbf46860 1835 u32 type;
319a441d
HHZ
1836 u16 size;
1837 struct ib_flow_eth_filter val;
1838 struct ib_flow_eth_filter mask;
1839};
1840
240ae00e
MB
1841struct ib_flow_ib_filter {
1842 __be16 dlid;
1843 __u8 sl;
15dfbd6b
MG
1844 /* Must be last */
1845 u8 real_sz[0];
240ae00e
MB
1846};
1847
1848struct ib_flow_spec_ib {
fbf46860 1849 u32 type;
240ae00e
MB
1850 u16 size;
1851 struct ib_flow_ib_filter val;
1852 struct ib_flow_ib_filter mask;
1853};
1854
989a3a8f
MG
1855/* IPv4 header flags */
1856enum ib_ipv4_flags {
1857 IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */
1858 IB_IPV4_MORE_FRAG = 0X4 /* For All fragmented packets except the
1859 last have this flag set */
1860};
1861
319a441d
HHZ
1862struct ib_flow_ipv4_filter {
1863 __be32 src_ip;
1864 __be32 dst_ip;
989a3a8f
MG
1865 u8 proto;
1866 u8 tos;
1867 u8 ttl;
1868 u8 flags;
15dfbd6b
MG
1869 /* Must be last */
1870 u8 real_sz[0];
319a441d
HHZ
1871};
1872
1873struct ib_flow_spec_ipv4 {
fbf46860 1874 u32 type;
319a441d
HHZ
1875 u16 size;
1876 struct ib_flow_ipv4_filter val;
1877 struct ib_flow_ipv4_filter mask;
1878};
1879
4c2aae71
MG
1880struct ib_flow_ipv6_filter {
1881 u8 src_ip[16];
1882 u8 dst_ip[16];
a72c6a2b
MG
1883 __be32 flow_label;
1884 u8 next_hdr;
1885 u8 traffic_class;
1886 u8 hop_limit;
15dfbd6b
MG
1887 /* Must be last */
1888 u8 real_sz[0];
4c2aae71
MG
1889};
1890
1891struct ib_flow_spec_ipv6 {
fbf46860 1892 u32 type;
4c2aae71
MG
1893 u16 size;
1894 struct ib_flow_ipv6_filter val;
1895 struct ib_flow_ipv6_filter mask;
1896};
1897
319a441d
HHZ
1898struct ib_flow_tcp_udp_filter {
1899 __be16 dst_port;
1900 __be16 src_port;
15dfbd6b
MG
1901 /* Must be last */
1902 u8 real_sz[0];
319a441d
HHZ
1903};
1904
1905struct ib_flow_spec_tcp_udp {
fbf46860 1906 u32 type;
319a441d
HHZ
1907 u16 size;
1908 struct ib_flow_tcp_udp_filter val;
1909 struct ib_flow_tcp_udp_filter mask;
1910};
1911
0dbf3332
MR
1912struct ib_flow_tunnel_filter {
1913 __be32 tunnel_id;
1914 u8 real_sz[0];
1915};
1916
1917/* ib_flow_spec_tunnel describes the Vxlan tunnel
1918 * the tunnel_id from val has the vni value
1919 */
1920struct ib_flow_spec_tunnel {
fbf46860 1921 u32 type;
0dbf3332
MR
1922 u16 size;
1923 struct ib_flow_tunnel_filter val;
1924 struct ib_flow_tunnel_filter mask;
1925};
1926
56ab0b38
MB
1927struct ib_flow_esp_filter {
1928 __be32 spi;
1929 __be32 seq;
1930 /* Must be last */
1931 u8 real_sz[0];
1932};
1933
1934struct ib_flow_spec_esp {
1935 u32 type;
1936 u16 size;
1937 struct ib_flow_esp_filter val;
1938 struct ib_flow_esp_filter mask;
1939};
1940
d90e5e50
AL
1941struct ib_flow_gre_filter {
1942 __be16 c_ks_res0_ver;
1943 __be16 protocol;
1944 __be32 key;
1945 /* Must be last */
1946 u8 real_sz[0];
1947};
1948
1949struct ib_flow_spec_gre {
1950 u32 type;
1951 u16 size;
1952 struct ib_flow_gre_filter val;
1953 struct ib_flow_gre_filter mask;
1954};
1955
b04f0f03
AL
1956struct ib_flow_mpls_filter {
1957 __be32 tag;
1958 /* Must be last */
1959 u8 real_sz[0];
1960};
1961
1962struct ib_flow_spec_mpls {
1963 u32 type;
1964 u16 size;
1965 struct ib_flow_mpls_filter val;
1966 struct ib_flow_mpls_filter mask;
1967};
1968
460d0198
MR
1969struct ib_flow_spec_action_tag {
1970 enum ib_flow_spec_type type;
1971 u16 size;
1972 u32 tag_id;
1973};
1974
483a3966
SS
1975struct ib_flow_spec_action_drop {
1976 enum ib_flow_spec_type type;
1977 u16 size;
1978};
1979
9b828441
MB
1980struct ib_flow_spec_action_handle {
1981 enum ib_flow_spec_type type;
1982 u16 size;
1983 struct ib_flow_action *act;
1984};
1985
7eea23a5
RS
1986enum ib_counters_description {
1987 IB_COUNTER_PACKETS,
1988 IB_COUNTER_BYTES,
1989};
1990
1991struct ib_flow_spec_action_count {
1992 enum ib_flow_spec_type type;
1993 u16 size;
1994 struct ib_counters *counters;
1995};
1996
319a441d
HHZ
1997union ib_flow_spec {
1998 struct {
fbf46860 1999 u32 type;
319a441d
HHZ
2000 u16 size;
2001 };
2002 struct ib_flow_spec_eth eth;
240ae00e 2003 struct ib_flow_spec_ib ib;
319a441d
HHZ
2004 struct ib_flow_spec_ipv4 ipv4;
2005 struct ib_flow_spec_tcp_udp tcp_udp;
4c2aae71 2006 struct ib_flow_spec_ipv6 ipv6;
0dbf3332 2007 struct ib_flow_spec_tunnel tunnel;
56ab0b38 2008 struct ib_flow_spec_esp esp;
d90e5e50 2009 struct ib_flow_spec_gre gre;
b04f0f03 2010 struct ib_flow_spec_mpls mpls;
460d0198 2011 struct ib_flow_spec_action_tag flow_tag;
483a3966 2012 struct ib_flow_spec_action_drop drop;
9b828441 2013 struct ib_flow_spec_action_handle action;
7eea23a5 2014 struct ib_flow_spec_action_count flow_count;
319a441d
HHZ
2015};
2016
2017struct ib_flow_attr {
2018 enum ib_flow_attr_type type;
2019 u16 size;
2020 u16 priority;
2021 u32 flags;
2022 u8 num_of_specs;
2023 u8 port;
7654cb1b 2024 union ib_flow_spec flows[];
319a441d
HHZ
2025};
2026
2027struct ib_flow {
2028 struct ib_qp *qp;
6cd080a6 2029 struct ib_device *device;
319a441d
HHZ
2030 struct ib_uobject *uobject;
2031};
2032
2eb9beae
MB
2033enum ib_flow_action_type {
2034 IB_FLOW_ACTION_UNSPECIFIED,
2035 IB_FLOW_ACTION_ESP = 1,
2036};
2037
2038struct ib_flow_action_attrs_esp_keymats {
2039 enum ib_uverbs_flow_action_esp_keymat protocol;
2040 union {
2041 struct ib_uverbs_flow_action_esp_keymat_aes_gcm aes_gcm;
2042 } keymat;
2043};
2044
2045struct ib_flow_action_attrs_esp_replays {
2046 enum ib_uverbs_flow_action_esp_replay protocol;
2047 union {
2048 struct ib_uverbs_flow_action_esp_replay_bmp bmp;
2049 } replay;
2050};
2051
2052enum ib_flow_action_attrs_esp_flags {
2053 /* All user-space flags at the top: Use enum ib_uverbs_flow_action_esp_flags
2054 * This is done in order to share the same flags between user-space and
2055 * kernel and spare an unnecessary translation.
2056 */
2057
2058 /* Kernel flags */
2059 IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED = 1ULL << 32,
7d12f8d5 2060 IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS = 1ULL << 33,
2eb9beae
MB
2061};
2062
2063struct ib_flow_spec_list {
2064 struct ib_flow_spec_list *next;
2065 union ib_flow_spec spec;
2066};
2067
2068struct ib_flow_action_attrs_esp {
2069 struct ib_flow_action_attrs_esp_keymats *keymat;
2070 struct ib_flow_action_attrs_esp_replays *replay;
2071 struct ib_flow_spec_list *encap;
2072 /* Used only if IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED is enabled.
2073 * Value of 0 is a valid value.
2074 */
2075 u32 esn;
2076 u32 spi;
2077 u32 seq;
2078 u32 tfc_pad;
2079 /* Use enum ib_flow_action_attrs_esp_flags */
2080 u64 flags;
2081 u64 hard_limit_pkts;
2082};
2083
2084struct ib_flow_action {
2085 struct ib_device *device;
2086 struct ib_uobject *uobject;
2087 enum ib_flow_action_type type;
2088 atomic_t usecnt;
2089};
2090
4cd7c947 2091struct ib_mad_hdr;
1da177e4
LT
2092struct ib_grh;
2093
2094enum ib_process_mad_flags {
2095 IB_MAD_IGNORE_MKEY = 1,
2096 IB_MAD_IGNORE_BKEY = 2,
2097 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
2098};
2099
2100enum ib_mad_result {
2101 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
2102 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
2103 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
2104 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
2105};
2106
21d6454a 2107struct ib_port_cache {
883c71fe 2108 u64 subnet_prefix;
21d6454a
JW
2109 struct ib_pkey_cache *pkey;
2110 struct ib_gid_table *gid;
2111 u8 lmc;
2112 enum ib_port_state port_state;
2113};
2114
1da177e4
LT
2115struct ib_cache {
2116 rwlock_t lock;
2117 struct ib_event_handler event_handler;
1da177e4
LT
2118};
2119
7738613e
IW
2120struct ib_port_immutable {
2121 int pkey_tbl_len;
2122 int gid_tbl_len;
f9b22e35 2123 u32 core_cap_flags;
337877a4 2124 u32 max_mad_size;
7738613e
IW
2125};
2126
8ceb1357 2127struct ib_port_data {
324e227e
JG
2128 struct ib_device *ib_dev;
2129
8ceb1357
JG
2130 struct ib_port_immutable immutable;
2131
2132 spinlock_t pkey_list_lock;
2133 struct list_head pkey_list;
8faea9fd
JG
2134
2135 struct ib_port_cache cache;
c2261dd7
JG
2136
2137 spinlock_t netdev_lock;
324e227e
JG
2138 struct net_device __rcu *netdev;
2139 struct hlist_node ndev_hash_link;
8ceb1357
JG
2140};
2141
2fc77572
VN
2142/* rdma netdev type - specifies protocol type */
2143enum rdma_netdev_t {
f0ad83ac
NV
2144 RDMA_NETDEV_OPA_VNIC,
2145 RDMA_NETDEV_IPOIB,
2fc77572
VN
2146};
2147
2148/**
2149 * struct rdma_netdev - rdma netdev
2150 * For cases where netstack interfacing is required.
2151 */
2152struct rdma_netdev {
2153 void *clnt_priv;
2154 struct ib_device *hca;
2155 u8 port_num;
2156
9f49a5b5
JG
2157 /*
2158 * cleanup function must be specified.
2159 * FIXME: This is only used for OPA_VNIC and that usage should be
2160 * removed too.
2161 */
8e959601
NV
2162 void (*free_rdma_netdev)(struct net_device *netdev);
2163
2fc77572
VN
2164 /* control functions */
2165 void (*set_id)(struct net_device *netdev, int id);
f0ad83ac
NV
2166 /* send packet */
2167 int (*send)(struct net_device *dev, struct sk_buff *skb,
2168 struct ib_ah *address, u32 dqpn);
2169 /* multicast */
2170 int (*attach_mcast)(struct net_device *dev, struct ib_device *hca,
2171 union ib_gid *gid, u16 mlid,
2172 int set_qkey, u32 qkey);
2173 int (*detach_mcast)(struct net_device *dev, struct ib_device *hca,
2174 union ib_gid *gid, u16 mlid);
2fc77572
VN
2175};
2176
f6a8a19b
DD
2177struct rdma_netdev_alloc_params {
2178 size_t sizeof_priv;
2179 unsigned int txqs;
2180 unsigned int rxqs;
2181 void *param;
2182
2183 int (*initialize_rdma_netdev)(struct ib_device *device, u8 port_num,
2184 struct net_device *netdev, void *param);
2185};
2186
fa9b1802
RS
2187struct ib_counters {
2188 struct ib_device *device;
2189 struct ib_uobject *uobject;
2190 /* num of objects attached */
2191 atomic_t usecnt;
2192};
2193
51d7a538
RS
2194struct ib_counters_read_attr {
2195 u64 *counters_buff;
2196 u32 ncounters;
2197 u32 flags; /* use enum ib_read_counters_flags */
2198};
2199
2eb9beae 2200struct uverbs_attr_bundle;
dd05cb82
KH
2201struct iw_cm_id;
2202struct iw_cm_conn_param;
2eb9beae 2203
30471d4b
LR
2204#define INIT_RDMA_OBJ_SIZE(ib_struct, drv_struct, member) \
2205 .size_##ib_struct = \
2206 (sizeof(struct drv_struct) + \
2207 BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) + \
2208 BUILD_BUG_ON_ZERO( \
2209 !__same_type(((struct drv_struct *)NULL)->member, \
2210 struct ib_struct)))
2211
f6316032
LR
2212#define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp) \
2213 ((struct ib_type *)kzalloc(ib_dev->ops.size_##ib_type, gfp))
2214
30471d4b 2215#define rdma_zalloc_drv_obj(ib_dev, ib_type) \
f6316032 2216 rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, GFP_KERNEL)
30471d4b
LR
2217
2218#define DECLARE_RDMA_OBJ_SIZE(ib_struct) size_t size_##ib_struct
2219
521ed0d9
KH
2220/**
2221 * struct ib_device_ops - InfiniBand device operations
2222 * This structure defines all the InfiniBand device operations, providers will
2223 * need to define the supported operations, otherwise they will be set to null.
2224 */
2225struct ib_device_ops {
7a154142 2226 struct module *owner;
b9560a41 2227 enum rdma_driver_id driver_id;
72c6ec18 2228 u32 uverbs_abi_ver;
8f71bb00 2229 unsigned int uverbs_no_driver_id_binding:1;
b9560a41 2230
521ed0d9
KH
2231 int (*post_send)(struct ib_qp *qp, const struct ib_send_wr *send_wr,
2232 const struct ib_send_wr **bad_send_wr);
2233 int (*post_recv)(struct ib_qp *qp, const struct ib_recv_wr *recv_wr,
2234 const struct ib_recv_wr **bad_recv_wr);
2235 void (*drain_rq)(struct ib_qp *qp);
2236 void (*drain_sq)(struct ib_qp *qp);
2237 int (*poll_cq)(struct ib_cq *cq, int num_entries, struct ib_wc *wc);
2238 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
2239 int (*req_notify_cq)(struct ib_cq *cq, enum ib_cq_notify_flags flags);
2240 int (*req_ncomp_notif)(struct ib_cq *cq, int wc_cnt);
2241 int (*post_srq_recv)(struct ib_srq *srq,
2242 const struct ib_recv_wr *recv_wr,
2243 const struct ib_recv_wr **bad_recv_wr);
2244 int (*process_mad)(struct ib_device *device, int process_mad_flags,
2245 u8 port_num, const struct ib_wc *in_wc,
2246 const struct ib_grh *in_grh,
2247 const struct ib_mad_hdr *in_mad, size_t in_mad_size,
2248 struct ib_mad_hdr *out_mad, size_t *out_mad_size,
2249 u16 *out_mad_pkey_index);
2250 int (*query_device)(struct ib_device *device,
2251 struct ib_device_attr *device_attr,
2252 struct ib_udata *udata);
2253 int (*modify_device)(struct ib_device *device, int device_modify_mask,
2254 struct ib_device_modify *device_modify);
2255 void (*get_dev_fw_str)(struct ib_device *device, char *str);
2256 const struct cpumask *(*get_vector_affinity)(struct ib_device *ibdev,
2257 int comp_vector);
2258 int (*query_port)(struct ib_device *device, u8 port_num,
2259 struct ib_port_attr *port_attr);
2260 int (*modify_port)(struct ib_device *device, u8 port_num,
2261 int port_modify_mask,
2262 struct ib_port_modify *port_modify);
2263 /**
2264 * The following mandatory functions are used only at device
2265 * registration. Keep functions such as these at the end of this
2266 * structure to avoid cache line misses when accessing struct ib_device
2267 * in fast paths.
2268 */
2269 int (*get_port_immutable)(struct ib_device *device, u8 port_num,
2270 struct ib_port_immutable *immutable);
2271 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
2272 u8 port_num);
2273 /**
2274 * When calling get_netdev, the HW vendor's driver should return the
2275 * net device of device @device at port @port_num or NULL if such
2276 * a net device doesn't exist. The vendor driver should call dev_hold
2277 * on this net device. The HW vendor's device driver must guarantee
2278 * that this function returns NULL before the net device has finished
2279 * NETDEV_UNREGISTER state.
2280 */
2281 struct net_device *(*get_netdev)(struct ib_device *device, u8 port_num);
2282 /**
2283 * rdma netdev operation
2284 *
2285 * Driver implementing alloc_rdma_netdev or rdma_netdev_get_params
2286 * must return -EOPNOTSUPP if it doesn't support the specified type.
2287 */
2288 struct net_device *(*alloc_rdma_netdev)(
2289 struct ib_device *device, u8 port_num, enum rdma_netdev_t type,
2290 const char *name, unsigned char name_assign_type,
2291 void (*setup)(struct net_device *));
2292
2293 int (*rdma_netdev_get_params)(struct ib_device *device, u8 port_num,
2294 enum rdma_netdev_t type,
2295 struct rdma_netdev_alloc_params *params);
2296 /**
2297 * query_gid should be return GID value for @device, when @port_num
2298 * link layer is either IB or iWarp. It is no-op if @port_num port
2299 * is RoCE link layer.
2300 */
2301 int (*query_gid)(struct ib_device *device, u8 port_num, int index,
2302 union ib_gid *gid);
2303 /**
2304 * When calling add_gid, the HW vendor's driver should add the gid
2305 * of device of port at gid index available at @attr. Meta-info of
2306 * that gid (for example, the network device related to this gid) is
2307 * available at @attr. @context allows the HW vendor driver to store
2308 * extra information together with a GID entry. The HW vendor driver may
2309 * allocate memory to contain this information and store it in @context
2310 * when a new GID entry is written to. Params are consistent until the
2311 * next call of add_gid or delete_gid. The function should return 0 on
2312 * success or error otherwise. The function could be called
2313 * concurrently for different ports. This function is only called when
2314 * roce_gid_table is used.
2315 */
2316 int (*add_gid)(const struct ib_gid_attr *attr, void **context);
2317 /**
2318 * When calling del_gid, the HW vendor's driver should delete the
2319 * gid of device @device at gid index gid_index of port port_num
2320 * available in @attr.
2321 * Upon the deletion of a GID entry, the HW vendor must free any
2322 * allocated memory. The caller will clear @context afterwards.
2323 * This function is only called when roce_gid_table is used.
2324 */
2325 int (*del_gid)(const struct ib_gid_attr *attr, void **context);
2326 int (*query_pkey)(struct ib_device *device, u8 port_num, u16 index,
2327 u16 *pkey);
a2a074ef
LR
2328 int (*alloc_ucontext)(struct ib_ucontext *context,
2329 struct ib_udata *udata);
2330 void (*dealloc_ucontext)(struct ib_ucontext *context);
521ed0d9
KH
2331 int (*mmap)(struct ib_ucontext *context, struct vm_area_struct *vma);
2332 void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
ff23dfa1 2333 int (*alloc_pd)(struct ib_pd *pd, struct ib_udata *udata);
c4367a26 2334 void (*dealloc_pd)(struct ib_pd *pd, struct ib_udata *udata);
d3456914
LR
2335 int (*create_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr,
2336 u32 flags, struct ib_udata *udata);
521ed0d9
KH
2337 int (*modify_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
2338 int (*query_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
d3456914 2339 void (*destroy_ah)(struct ib_ah *ah, u32 flags);
68e326de
LR
2340 int (*create_srq)(struct ib_srq *srq,
2341 struct ib_srq_init_attr *srq_init_attr,
2342 struct ib_udata *udata);
521ed0d9
KH
2343 int (*modify_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr,
2344 enum ib_srq_attr_mask srq_attr_mask,
2345 struct ib_udata *udata);
2346 int (*query_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
68e326de 2347 void (*destroy_srq)(struct ib_srq *srq, struct ib_udata *udata);
521ed0d9
KH
2348 struct ib_qp *(*create_qp)(struct ib_pd *pd,
2349 struct ib_qp_init_attr *qp_init_attr,
2350 struct ib_udata *udata);
2351 int (*modify_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
2352 int qp_attr_mask, struct ib_udata *udata);
2353 int (*query_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
2354 int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr);
c4367a26 2355 int (*destroy_qp)(struct ib_qp *qp, struct ib_udata *udata);
e39afe3d
LR
2356 int (*create_cq)(struct ib_cq *cq, const struct ib_cq_init_attr *attr,
2357 struct ib_udata *udata);
521ed0d9 2358 int (*modify_cq)(struct ib_cq *cq, u16 cq_count, u16 cq_period);
a52c8e24 2359 void (*destroy_cq)(struct ib_cq *cq, struct ib_udata *udata);
521ed0d9
KH
2360 int (*resize_cq)(struct ib_cq *cq, int cqe, struct ib_udata *udata);
2361 struct ib_mr *(*get_dma_mr)(struct ib_pd *pd, int mr_access_flags);
2362 struct ib_mr *(*reg_user_mr)(struct ib_pd *pd, u64 start, u64 length,
2363 u64 virt_addr, int mr_access_flags,
2364 struct ib_udata *udata);
2365 int (*rereg_user_mr)(struct ib_mr *mr, int flags, u64 start, u64 length,
2366 u64 virt_addr, int mr_access_flags,
2367 struct ib_pd *pd, struct ib_udata *udata);
c4367a26 2368 int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata);
521ed0d9 2369 struct ib_mr *(*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type,
c4367a26 2370 u32 max_num_sg, struct ib_udata *udata);
26bc7eae
IR
2371 struct ib_mr *(*alloc_mr_integrity)(struct ib_pd *pd,
2372 u32 max_num_data_sg,
2373 u32 max_num_meta_sg);
ad8a4496
MS
2374 int (*advise_mr)(struct ib_pd *pd,
2375 enum ib_uverbs_advise_mr_advice advice, u32 flags,
2376 struct ib_sge *sg_list, u32 num_sge,
2377 struct uverbs_attr_bundle *attrs);
521ed0d9
KH
2378 int (*map_mr_sg)(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
2379 unsigned int *sg_offset);
2380 int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
2381 struct ib_mr_status *mr_status);
2382 struct ib_mw *(*alloc_mw)(struct ib_pd *pd, enum ib_mw_type type,
2383 struct ib_udata *udata);
2384 int (*dealloc_mw)(struct ib_mw *mw);
2385 struct ib_fmr *(*alloc_fmr)(struct ib_pd *pd, int mr_access_flags,
2386 struct ib_fmr_attr *fmr_attr);
2387 int (*map_phys_fmr)(struct ib_fmr *fmr, u64 *page_list, int list_len,
2388 u64 iova);
2389 int (*unmap_fmr)(struct list_head *fmr_list);
2390 int (*dealloc_fmr)(struct ib_fmr *fmr);
2391 int (*attach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2392 int (*detach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2393 struct ib_xrcd *(*alloc_xrcd)(struct ib_device *device,
521ed0d9 2394 struct ib_udata *udata);
c4367a26 2395 int (*dealloc_xrcd)(struct ib_xrcd *xrcd, struct ib_udata *udata);
521ed0d9
KH
2396 struct ib_flow *(*create_flow)(struct ib_qp *qp,
2397 struct ib_flow_attr *flow_attr,
2398 int domain, struct ib_udata *udata);
2399 int (*destroy_flow)(struct ib_flow *flow_id);
2400 struct ib_flow_action *(*create_flow_action_esp)(
2401 struct ib_device *device,
2402 const struct ib_flow_action_attrs_esp *attr,
2403 struct uverbs_attr_bundle *attrs);
2404 int (*destroy_flow_action)(struct ib_flow_action *action);
2405 int (*modify_flow_action_esp)(
2406 struct ib_flow_action *action,
2407 const struct ib_flow_action_attrs_esp *attr,
2408 struct uverbs_attr_bundle *attrs);
2409 int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
2410 int state);
2411 int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
2412 struct ifla_vf_info *ivf);
2413 int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
2414 struct ifla_vf_stats *stats);
2415 int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
2416 int type);
2417 struct ib_wq *(*create_wq)(struct ib_pd *pd,
2418 struct ib_wq_init_attr *init_attr,
2419 struct ib_udata *udata);
a49b1dc7 2420 void (*destroy_wq)(struct ib_wq *wq, struct ib_udata *udata);
521ed0d9
KH
2421 int (*modify_wq)(struct ib_wq *wq, struct ib_wq_attr *attr,
2422 u32 wq_attr_mask, struct ib_udata *udata);
2423 struct ib_rwq_ind_table *(*create_rwq_ind_table)(
2424 struct ib_device *device,
2425 struct ib_rwq_ind_table_init_attr *init_attr,
2426 struct ib_udata *udata);
2427 int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
2428 struct ib_dm *(*alloc_dm)(struct ib_device *device,
2429 struct ib_ucontext *context,
2430 struct ib_dm_alloc_attr *attr,
2431 struct uverbs_attr_bundle *attrs);
c4367a26 2432 int (*dealloc_dm)(struct ib_dm *dm, struct uverbs_attr_bundle *attrs);
521ed0d9
KH
2433 struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm,
2434 struct ib_dm_mr_attr *attr,
2435 struct uverbs_attr_bundle *attrs);
2436 struct ib_counters *(*create_counters)(
2437 struct ib_device *device, struct uverbs_attr_bundle *attrs);
2438 int (*destroy_counters)(struct ib_counters *counters);
2439 int (*read_counters)(struct ib_counters *counters,
2440 struct ib_counters_read_attr *counters_read_attr,
2441 struct uverbs_attr_bundle *attrs);
2cdfcdd8
MG
2442 int (*map_mr_sg_pi)(struct ib_mr *mr, struct scatterlist *data_sg,
2443 int data_sg_nents, unsigned int *data_sg_offset,
2444 struct scatterlist *meta_sg, int meta_sg_nents,
2445 unsigned int *meta_sg_offset);
2446
521ed0d9
KH
2447 /**
2448 * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
2449 * driver initialized data. The struct is kfree()'ed by the sysfs
2450 * core when the device is removed. A lifespan of -1 in the return
2451 * struct tells the core to set a default lifespan.
2452 */
2453 struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
2454 u8 port_num);
2455 /**
2456 * get_hw_stats - Fill in the counter value(s) in the stats struct.
2457 * @index - The index in the value array we wish to have updated, or
2458 * num_counters if we want all stats updated
2459 * Return codes -
2460 * < 0 - Error, no counters updated
2461 * index - Updated the single counter pointed to by index
2462 * num_counters - Updated all counters (will reset the timestamp
2463 * and prevent further calls for lifespan milliseconds)
2464 * Drivers are allowed to update all counters in leiu of just the
2465 * one given in index at their option
2466 */
2467 int (*get_hw_stats)(struct ib_device *device,
2468 struct rdma_hw_stats *stats, u8 port, int index);
ea4baf7f
PP
2469 /*
2470 * This function is called once for each port when a ib device is
2471 * registered.
2472 */
2473 int (*init_port)(struct ib_device *device, u8 port_num,
2474 struct kobject *port_sysfs);
02da3750
LR
2475 /**
2476 * Allows rdma drivers to add their own restrack attributes.
2477 */
2478 int (*fill_res_entry)(struct sk_buff *msg,
2479 struct rdma_restrack_entry *entry);
21a428a0 2480
d0899892 2481 /* Device lifecycle callbacks */
ca22354b
JG
2482 /*
2483 * Called after the device becomes registered, before clients are
2484 * attached
2485 */
2486 int (*enable_driver)(struct ib_device *dev);
d0899892
JG
2487 /*
2488 * This is called as part of ib_dealloc_device().
2489 */
2490 void (*dealloc_driver)(struct ib_device *dev);
2491
dd05cb82
KH
2492 /* iWarp CM callbacks */
2493 void (*iw_add_ref)(struct ib_qp *qp);
2494 void (*iw_rem_ref)(struct ib_qp *qp);
2495 struct ib_qp *(*iw_get_qp)(struct ib_device *device, int qpn);
2496 int (*iw_connect)(struct iw_cm_id *cm_id,
2497 struct iw_cm_conn_param *conn_param);
2498 int (*iw_accept)(struct iw_cm_id *cm_id,
2499 struct iw_cm_conn_param *conn_param);
2500 int (*iw_reject)(struct iw_cm_id *cm_id, const void *pdata,
2501 u8 pdata_len);
2502 int (*iw_create_listen)(struct iw_cm_id *cm_id, int backlog);
2503 int (*iw_destroy_listen)(struct iw_cm_id *cm_id);
2504
d3456914 2505 DECLARE_RDMA_OBJ_SIZE(ib_ah);
e39afe3d 2506 DECLARE_RDMA_OBJ_SIZE(ib_cq);
21a428a0 2507 DECLARE_RDMA_OBJ_SIZE(ib_pd);
68e326de 2508 DECLARE_RDMA_OBJ_SIZE(ib_srq);
a2a074ef 2509 DECLARE_RDMA_OBJ_SIZE(ib_ucontext);
521ed0d9
KH
2510};
2511
cebe556b
PP
2512struct ib_core_device {
2513 /* device must be the first element in structure until,
2514 * union of ib_core_device and device exists in ib_device.
2515 */
2516 struct device dev;
4e0f7b90 2517 possible_net_t rdma_net;
cebe556b
PP
2518 struct kobject *ports_kobj;
2519 struct list_head port_list;
2520 struct ib_device *owner; /* reach back to owner ib_device */
2521};
41eda65c 2522
cebe556b 2523struct rdma_restrack_root;
1da177e4 2524struct ib_device {
0957c29f
BVA
2525 /* Do not access @dma_device directly from ULP nor from HW drivers. */
2526 struct device *dma_device;
3023a1e9 2527 struct ib_device_ops ops;
1da177e4 2528 char name[IB_DEVICE_NAME_MAX];
324e227e 2529 struct rcu_head rcu_head;
1da177e4
LT
2530
2531 struct list_head event_handler_list;
2532 spinlock_t event_handler_lock;
2533
921eab11 2534 struct rw_semaphore client_data_rwsem;
0df91bb6 2535 struct xarray client_data;
d0899892 2536 struct mutex unregistration_lock;
1da177e4
LT
2537
2538 struct ib_cache cache;
7738613e 2539 /**
8ceb1357 2540 * port_data is indexed by port number
7738613e 2541 */
8ceb1357 2542 struct ib_port_data *port_data;
1da177e4 2543
f4fd0b22
MT
2544 int num_comp_vectors;
2545
cebe556b
PP
2546 union {
2547 struct device dev;
2548 struct ib_core_device coredev;
2549 };
2550
d4122f5a
PP
2551 /* First group for device attributes,
2552 * Second group for driver provided attributes (optional).
2553 * It is NULL terminated array.
2554 */
2555 const struct attribute_group *groups[3];
adee9f3f 2556
17a55f79 2557 u64 uverbs_cmd_mask;
f21519b2 2558 u64 uverbs_ex_cmd_mask;
274c0891 2559
bd99fdea 2560 char node_desc[IB_DEVICE_NODE_DESC_MAX];
cf311cd4 2561 __be64 node_guid;
96f15c03 2562 u32 local_dma_lkey;
4139032b 2563 u16 is_switch:1;
6780c4fa
GP
2564 /* Indicates kernel verbs support, should not be used in drivers */
2565 u16 kverbs_provider:1;
1da177e4
LT
2566 u8 node_type;
2567 u8 phys_port_cnt;
3e153a93 2568 struct ib_device_attr attrs;
b40f4757
CL
2569 struct attribute_group *hw_stats_ag;
2570 struct rdma_hw_stats *hw_stats;
7738613e 2571
43579b5f
PP
2572#ifdef CONFIG_CGROUP_RDMA
2573 struct rdmacg_device cg_device;
2574#endif
2575
ecc82c53 2576 u32 index;
41eda65c 2577 struct rdma_restrack_root *res;
ecc82c53 2578
0cbf432d 2579 const struct uapi_definition *driver_def;
d79af724 2580
01b67117 2581 /*
d79af724
JG
2582 * Positive refcount indicates that the device is currently
2583 * registered and cannot be unregistered.
01b67117
PP
2584 */
2585 refcount_t refcount;
2586 struct completion unreg_completion;
d0899892 2587 struct work_struct unregistration_work;
3856ec4b
SW
2588
2589 const struct rdma_link_ops *link_ops;
4e0f7b90
PP
2590
2591 /* Protects compat_devs xarray modifications */
2592 struct mutex compat_devs_mutex;
2593 /* Maintains compat devices for each net namespace */
2594 struct xarray compat_devs;
dd05cb82
KH
2595
2596 /* Used by iWarp CM */
2597 char iw_ifname[IFNAMSIZ];
2598 u32 iw_driver_flags;
1da177e4
LT
2599};
2600
0e2d00eb 2601struct ib_client_nl_info;
1da177e4 2602struct ib_client {
e59178d8 2603 const char *name;
1da177e4 2604 void (*add) (struct ib_device *);
7c1eb45a 2605 void (*remove)(struct ib_device *, void *client_data);
0e2d00eb
JG
2606 int (*get_nl_info)(struct ib_device *ibdev, void *client_data,
2607 struct ib_client_nl_info *res);
2608 int (*get_global_nl_info)(struct ib_client_nl_info *res);
1da177e4 2609
9268f72d
YK
2610 /* Returns the net_dev belonging to this ib_client and matching the
2611 * given parameters.
2612 * @dev: An RDMA device that the net_dev use for communication.
2613 * @port: A physical port number on the RDMA device.
2614 * @pkey: P_Key that the net_dev uses if applicable.
2615 * @gid: A GID that the net_dev uses to communicate.
2616 * @addr: An IP address the net_dev is configured with.
2617 * @client_data: The device's client data set by ib_set_client_data().
2618 *
2619 * An ib_client that implements a net_dev on top of RDMA devices
2620 * (such as IP over IB) should implement this callback, allowing the
2621 * rdma_cm module to find the right net_dev for a given request.
2622 *
2623 * The caller is responsible for calling dev_put on the returned
2624 * netdev. */
2625 struct net_device *(*get_net_dev_by_params)(
2626 struct ib_device *dev,
2627 u8 port,
2628 u16 pkey,
2629 const union ib_gid *gid,
2630 const struct sockaddr *addr,
2631 void *client_data);
1da177e4 2632 struct list_head list;
e59178d8 2633 u32 client_id;
6780c4fa
GP
2634
2635 /* kverbs are not required by the client */
2636 u8 no_kverbs_req:1;
1da177e4
LT
2637};
2638
a808273a
SS
2639/*
2640 * IB block DMA iterator
2641 *
2642 * Iterates the DMA-mapped SGL in contiguous memory blocks aligned
2643 * to a HW supported page size.
2644 */
2645struct ib_block_iter {
2646 /* internal states */
2647 struct scatterlist *__sg; /* sg holding the current aligned block */
2648 dma_addr_t __dma_addr; /* unaligned DMA address of this block */
2649 unsigned int __sg_nents; /* number of SG entries */
2650 unsigned int __sg_advance; /* number of bytes to advance in sg in next step */
2651 unsigned int __pg_bit; /* alignment of current block */
2652};
2653
459cc69f
LR
2654struct ib_device *_ib_alloc_device(size_t size);
2655#define ib_alloc_device(drv_struct, member) \
2656 container_of(_ib_alloc_device(sizeof(struct drv_struct) + \
2657 BUILD_BUG_ON_ZERO(offsetof( \
2658 struct drv_struct, member))), \
2659 struct drv_struct, member)
2660
1da177e4
LT
2661void ib_dealloc_device(struct ib_device *device);
2662
9abb0d1b 2663void ib_get_device_fw_str(struct ib_device *device, char *str);
5fa76c20 2664
ea4baf7f 2665int ib_register_device(struct ib_device *device, const char *name);
1da177e4 2666void ib_unregister_device(struct ib_device *device);
d0899892
JG
2667void ib_unregister_driver(enum rdma_driver_id driver_id);
2668void ib_unregister_device_and_put(struct ib_device *device);
2669void ib_unregister_device_queued(struct ib_device *ib_dev);
1da177e4
LT
2670
2671int ib_register_client (struct ib_client *client);
2672void ib_unregister_client(struct ib_client *client);
2673
a808273a
SS
2674void __rdma_block_iter_start(struct ib_block_iter *biter,
2675 struct scatterlist *sglist,
2676 unsigned int nents,
2677 unsigned long pgsz);
2678bool __rdma_block_iter_next(struct ib_block_iter *biter);
2679
2680/**
2681 * rdma_block_iter_dma_address - get the aligned dma address of the current
2682 * block held by the block iterator.
2683 * @biter: block iterator holding the memory block
2684 */
2685static inline dma_addr_t
2686rdma_block_iter_dma_address(struct ib_block_iter *biter)
2687{
2688 return biter->__dma_addr & ~(BIT_ULL(biter->__pg_bit) - 1);
2689}
2690
2691/**
2692 * rdma_for_each_block - iterate over contiguous memory blocks of the sg list
2693 * @sglist: sglist to iterate over
2694 * @biter: block iterator holding the memory block
2695 * @nents: maximum number of sg entries to iterate over
2696 * @pgsz: best HW supported page size to use
2697 *
2698 * Callers may use rdma_block_iter_dma_address() to get each
2699 * blocks aligned DMA address.
2700 */
2701#define rdma_for_each_block(sglist, biter, nents, pgsz) \
2702 for (__rdma_block_iter_start(biter, sglist, nents, \
2703 pgsz); \
2704 __rdma_block_iter_next(biter);)
2705
0df91bb6
JG
2706/**
2707 * ib_get_client_data - Get IB client context
2708 * @device:Device to get context for
2709 * @client:Client to get context for
2710 *
2711 * ib_get_client_data() returns the client context data set with
2712 * ib_set_client_data(). This can only be called while the client is
2713 * registered to the device, once the ib_client remove() callback returns this
2714 * cannot be called.
2715 */
2716static inline void *ib_get_client_data(struct ib_device *device,
2717 struct ib_client *client)
2718{
2719 return xa_load(&device->client_data, client->client_id);
2720}
1da177e4
LT
2721void ib_set_client_data(struct ib_device *device, struct ib_client *client,
2722 void *data);
521ed0d9
KH
2723void ib_set_device_ops(struct ib_device *device,
2724 const struct ib_device_ops *ops);
1da177e4 2725
5f9794dc
JG
2726#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
2727int rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma,
2728 unsigned long pfn, unsigned long size, pgprot_t prot);
5f9794dc
JG
2729#else
2730static inline int rdma_user_mmap_io(struct ib_ucontext *ucontext,
2731 struct vm_area_struct *vma,
2732 unsigned long pfn, unsigned long size,
2733 pgprot_t prot)
2734{
2735 return -EINVAL;
2736}
5f9794dc
JG
2737#endif
2738
e2773c06
RD
2739static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
2740{
2741 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
2742}
2743
2744static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
2745{
43c61165 2746 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
e2773c06
RD
2747}
2748
c66db311
MB
2749static inline bool ib_is_buffer_cleared(const void __user *p,
2750 size_t len)
301a721e 2751{
92d27ae6 2752 bool ret;
301a721e
MB
2753 u8 *buf;
2754
2755 if (len > USHRT_MAX)
2756 return false;
2757
92d27ae6
ME
2758 buf = memdup_user(p, len);
2759 if (IS_ERR(buf))
301a721e
MB
2760 return false;
2761
301a721e 2762 ret = !memchr_inv(buf, 0, len);
301a721e
MB
2763 kfree(buf);
2764 return ret;
2765}
2766
c66db311
MB
2767static inline bool ib_is_udata_cleared(struct ib_udata *udata,
2768 size_t offset,
2769 size_t len)
2770{
2771 return ib_is_buffer_cleared(udata->inbuf + offset, len);
2772}
2773
1c77483e
YH
2774/**
2775 * ib_is_destroy_retryable - Check whether the uobject destruction
2776 * is retryable.
2777 * @ret: The initial destruction return code
2778 * @why: remove reason
2779 * @uobj: The uobject that is destroyed
2780 *
2781 * This function is a helper function that IB layer and low-level drivers
2782 * can use to consider whether the destruction of the given uobject is
2783 * retry-able.
2784 * It checks the original return code, if it wasn't success the destruction
2785 * is retryable according to the ucontext state (i.e. cleanup_retryable) and
2786 * the remove reason. (i.e. why).
2787 * Must be called with the object locked for destroy.
2788 */
2789static inline bool ib_is_destroy_retryable(int ret, enum rdma_remove_reason why,
2790 struct ib_uobject *uobj)
2791{
2792 return ret && (why == RDMA_REMOVE_DESTROY ||
2793 uobj->context->cleanup_retryable);
2794}
2795
2796/**
2797 * ib_destroy_usecnt - Called during destruction to check the usecnt
2798 * @usecnt: The usecnt atomic
2799 * @why: remove reason
2800 * @uobj: The uobject that is destroyed
2801 *
2802 * Non-zero usecnts will block destruction unless destruction was triggered by
2803 * a ucontext cleanup.
2804 */
2805static inline int ib_destroy_usecnt(atomic_t *usecnt,
2806 enum rdma_remove_reason why,
2807 struct ib_uobject *uobj)
2808{
2809 if (atomic_read(usecnt) && ib_is_destroy_retryable(-EBUSY, why, uobj))
2810 return -EBUSY;
2811 return 0;
2812}
2813
8a51866f
RD
2814/**
2815 * ib_modify_qp_is_ok - Check that the supplied attribute mask
2816 * contains all required attributes and no attributes not allowed for
2817 * the given QP state transition.
2818 * @cur_state: Current QP state
2819 * @next_state: Next QP state
2820 * @type: QP type
2821 * @mask: Mask of supplied QP attributes
2822 *
2823 * This function is a helper function that a low-level driver's
2824 * modify_qp method can use to validate the consumer's input. It
2825 * checks that cur_state and next_state are valid QP states, that a
2826 * transition from cur_state to next_state is allowed by the IB spec,
2827 * and that the attribute mask supplied is allowed for the transition.
2828 */
19b1f540 2829bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
d31131bb 2830 enum ib_qp_type type, enum ib_qp_attr_mask mask);
8a51866f 2831
dcc9881e
LR
2832void ib_register_event_handler(struct ib_event_handler *event_handler);
2833void ib_unregister_event_handler(struct ib_event_handler *event_handler);
1da177e4
LT
2834void ib_dispatch_event(struct ib_event *event);
2835
1da177e4
LT
2836int ib_query_port(struct ib_device *device,
2837 u8 port_num, struct ib_port_attr *port_attr);
2838
a3f5adaf
EC
2839enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
2840 u8 port_num);
2841
4139032b
HR
2842/**
2843 * rdma_cap_ib_switch - Check if the device is IB switch
2844 * @device: Device to check
2845 *
2846 * Device driver is responsible for setting is_switch bit on
2847 * in ib_device structure at init time.
2848 *
2849 * Return: true if the device is IB switch.
2850 */
2851static inline bool rdma_cap_ib_switch(const struct ib_device *device)
2852{
2853 return device->is_switch;
2854}
2855
0cf18d77
IW
2856/**
2857 * rdma_start_port - Return the first valid port number for the device
2858 * specified
2859 *
2860 * @device: Device to be checked
2861 *
2862 * Return start port number
2863 */
2864static inline u8 rdma_start_port(const struct ib_device *device)
2865{
4139032b 2866 return rdma_cap_ib_switch(device) ? 0 : 1;
0cf18d77
IW
2867}
2868
ea1075ed
JG
2869/**
2870 * rdma_for_each_port - Iterate over all valid port numbers of the IB device
2871 * @device - The struct ib_device * to iterate over
2872 * @iter - The unsigned int to store the port number
2873 */
2874#define rdma_for_each_port(device, iter) \
2875 for (iter = rdma_start_port(device + BUILD_BUG_ON_ZERO(!__same_type( \
2876 unsigned int, iter))); \
2877 iter <= rdma_end_port(device); (iter)++)
2878
0cf18d77
IW
2879/**
2880 * rdma_end_port - Return the last valid port number for the device
2881 * specified
2882 *
2883 * @device: Device to be checked
2884 *
2885 * Return last port number
2886 */
2887static inline u8 rdma_end_port(const struct ib_device *device)
2888{
4139032b 2889 return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
0cf18d77
IW
2890}
2891
24dc831b
YS
2892static inline int rdma_is_port_valid(const struct ib_device *device,
2893 unsigned int port)
2894{
2895 return (port >= rdma_start_port(device) &&
2896 port <= rdma_end_port(device));
2897}
2898
b02289b3
AK
2899static inline bool rdma_is_grh_required(const struct ib_device *device,
2900 u8 port_num)
2901{
8ceb1357
JG
2902 return device->port_data[port_num].immutable.core_cap_flags &
2903 RDMA_CORE_PORT_IB_GRH_REQUIRED;
b02289b3
AK
2904}
2905
5ede9289 2906static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
de66be94 2907{
8ceb1357
JG
2908 return device->port_data[port_num].immutable.core_cap_flags &
2909 RDMA_CORE_CAP_PROT_IB;
de66be94
MW
2910}
2911
5ede9289 2912static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
7766a99f 2913{
8ceb1357
JG
2914 return device->port_data[port_num].immutable.core_cap_flags &
2915 (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
7766a99f
MB
2916}
2917
2918static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
2919{
8ceb1357
JG
2920 return device->port_data[port_num].immutable.core_cap_flags &
2921 RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
7766a99f
MB
2922}
2923
2924static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
de66be94 2925{
8ceb1357
JG
2926 return device->port_data[port_num].immutable.core_cap_flags &
2927 RDMA_CORE_CAP_PROT_ROCE;
de66be94
MW
2928}
2929
5ede9289 2930static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
de66be94 2931{
8ceb1357
JG
2932 return device->port_data[port_num].immutable.core_cap_flags &
2933 RDMA_CORE_CAP_PROT_IWARP;
de66be94
MW
2934}
2935
5ede9289 2936static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
de66be94 2937{
7766a99f
MB
2938 return rdma_protocol_ib(device, port_num) ||
2939 rdma_protocol_roce(device, port_num);
de66be94
MW
2940}
2941
aa773bd4
OG
2942static inline bool rdma_protocol_raw_packet(const struct ib_device *device, u8 port_num)
2943{
8ceb1357
JG
2944 return device->port_data[port_num].immutable.core_cap_flags &
2945 RDMA_CORE_CAP_PROT_RAW_PACKET;
aa773bd4
OG
2946}
2947
ce1e055f
OG
2948static inline bool rdma_protocol_usnic(const struct ib_device *device, u8 port_num)
2949{
8ceb1357
JG
2950 return device->port_data[port_num].immutable.core_cap_flags &
2951 RDMA_CORE_CAP_PROT_USNIC;
ce1e055f
OG
2952}
2953
c757dea8 2954/**
296ec009 2955 * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
c757dea8 2956 * Management Datagrams.
296ec009
MW
2957 * @device: Device to check
2958 * @port_num: Port number to check
c757dea8 2959 *
296ec009
MW
2960 * Management Datagrams (MAD) are a required part of the InfiniBand
2961 * specification and are supported on all InfiniBand devices. A slightly
2962 * extended version are also supported on OPA interfaces.
c757dea8 2963 *
296ec009 2964 * Return: true if the port supports sending/receiving of MAD packets.
c757dea8 2965 */
5ede9289 2966static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
c757dea8 2967{
8ceb1357
JG
2968 return device->port_data[port_num].immutable.core_cap_flags &
2969 RDMA_CORE_CAP_IB_MAD;
c757dea8
MW
2970}
2971
65995fee
IW
2972/**
2973 * rdma_cap_opa_mad - Check if the port of device provides support for OPA
2974 * Management Datagrams.
2975 * @device: Device to check
2976 * @port_num: Port number to check
2977 *
2978 * Intel OmniPath devices extend and/or replace the InfiniBand Management
2979 * datagrams with their own versions. These OPA MADs share many but not all of
2980 * the characteristics of InfiniBand MADs.
2981 *
2982 * OPA MADs differ in the following ways:
2983 *
2984 * 1) MADs are variable size up to 2K
2985 * IBTA defined MADs remain fixed at 256 bytes
2986 * 2) OPA SMPs must carry valid PKeys
2987 * 3) OPA SMP packets are a different format
2988 *
2989 * Return: true if the port supports OPA MAD packet formats.
2990 */
2991static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
2992{
d3243da8
LR
2993 return device->port_data[port_num].immutable.core_cap_flags &
2994 RDMA_CORE_CAP_OPA_MAD;
65995fee
IW
2995}
2996
29541e3a 2997/**
296ec009
MW
2998 * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
2999 * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
3000 * @device: Device to check
3001 * @port_num: Port number to check
29541e3a 3002 *
296ec009
MW
3003 * Each InfiniBand node is required to provide a Subnet Management Agent
3004 * that the subnet manager can access. Prior to the fabric being fully
3005 * configured by the subnet manager, the SMA is accessed via a well known
3006 * interface called the Subnet Management Interface (SMI). This interface
3007 * uses directed route packets to communicate with the SM to get around the
3008 * chicken and egg problem of the SM needing to know what's on the fabric
3009 * in order to configure the fabric, and needing to configure the fabric in
3010 * order to send packets to the devices on the fabric. These directed
3011 * route packets do not need the fabric fully configured in order to reach
3012 * their destination. The SMI is the only method allowed to send
3013 * directed route packets on an InfiniBand fabric.
29541e3a 3014 *
296ec009 3015 * Return: true if the port provides an SMI.
29541e3a 3016 */
5ede9289 3017static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
29541e3a 3018{
8ceb1357
JG
3019 return device->port_data[port_num].immutable.core_cap_flags &
3020 RDMA_CORE_CAP_IB_SMI;
29541e3a
MW
3021}
3022
72219cea
MW
3023/**
3024 * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
3025 * Communication Manager.
296ec009
MW
3026 * @device: Device to check
3027 * @port_num: Port number to check
72219cea 3028 *
296ec009
MW
3029 * The InfiniBand Communication Manager is one of many pre-defined General
3030 * Service Agents (GSA) that are accessed via the General Service
3031 * Interface (GSI). It's role is to facilitate establishment of connections
3032 * between nodes as well as other management related tasks for established
3033 * connections.
72219cea 3034 *
296ec009
MW
3035 * Return: true if the port supports an IB CM (this does not guarantee that
3036 * a CM is actually running however).
72219cea 3037 */
5ede9289 3038static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
72219cea 3039{
8ceb1357
JG
3040 return device->port_data[port_num].immutable.core_cap_flags &
3041 RDMA_CORE_CAP_IB_CM;
72219cea
MW
3042}
3043
04215330
MW
3044/**
3045 * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
3046 * Communication Manager.
296ec009
MW
3047 * @device: Device to check
3048 * @port_num: Port number to check
04215330 3049 *
296ec009
MW
3050 * Similar to above, but specific to iWARP connections which have a different
3051 * managment protocol than InfiniBand.
04215330 3052 *
296ec009
MW
3053 * Return: true if the port supports an iWARP CM (this does not guarantee that
3054 * a CM is actually running however).
04215330 3055 */
5ede9289 3056static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
04215330 3057{
8ceb1357
JG
3058 return device->port_data[port_num].immutable.core_cap_flags &
3059 RDMA_CORE_CAP_IW_CM;
04215330
MW
3060}
3061
fe53ba2f
MW
3062/**
3063 * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
3064 * Subnet Administration.
296ec009
MW
3065 * @device: Device to check
3066 * @port_num: Port number to check
fe53ba2f 3067 *
296ec009
MW
3068 * An InfiniBand Subnet Administration (SA) service is a pre-defined General
3069 * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
3070 * fabrics, devices should resolve routes to other hosts by contacting the
3071 * SA to query the proper route.
fe53ba2f 3072 *
296ec009
MW
3073 * Return: true if the port should act as a client to the fabric Subnet
3074 * Administration interface. This does not imply that the SA service is
3075 * running locally.
fe53ba2f 3076 */
5ede9289 3077static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
fe53ba2f 3078{
8ceb1357
JG
3079 return device->port_data[port_num].immutable.core_cap_flags &
3080 RDMA_CORE_CAP_IB_SA;
fe53ba2f
MW
3081}
3082
a31ad3b0
MW
3083/**
3084 * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
3085 * Multicast.
296ec009
MW
3086 * @device: Device to check
3087 * @port_num: Port number to check
a31ad3b0 3088 *
296ec009
MW
3089 * InfiniBand multicast registration is more complex than normal IPv4 or
3090 * IPv6 multicast registration. Each Host Channel Adapter must register
3091 * with the Subnet Manager when it wishes to join a multicast group. It
3092 * should do so only once regardless of how many queue pairs it subscribes
3093 * to this group. And it should leave the group only after all queue pairs
3094 * attached to the group have been detached.
a31ad3b0 3095 *
296ec009
MW
3096 * Return: true if the port must undertake the additional adminstrative
3097 * overhead of registering/unregistering with the SM and tracking of the
3098 * total number of queue pairs attached to the multicast group.
a31ad3b0 3099 */
5ede9289 3100static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
a31ad3b0
MW
3101{
3102 return rdma_cap_ib_sa(device, port_num);
3103}
3104
30a74ef4
MW
3105/**
3106 * rdma_cap_af_ib - Check if the port of device has the capability
3107 * Native Infiniband Address.
296ec009
MW
3108 * @device: Device to check
3109 * @port_num: Port number to check
30a74ef4 3110 *
296ec009
MW
3111 * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
3112 * GID. RoCE uses a different mechanism, but still generates a GID via
3113 * a prescribed mechanism and port specific data.
30a74ef4 3114 *
296ec009
MW
3115 * Return: true if the port uses a GID address to identify devices on the
3116 * network.
30a74ef4 3117 */
5ede9289 3118static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
30a74ef4 3119{
8ceb1357
JG
3120 return device->port_data[port_num].immutable.core_cap_flags &
3121 RDMA_CORE_CAP_AF_IB;
30a74ef4
MW
3122}
3123
227128fc
MW
3124/**
3125 * rdma_cap_eth_ah - Check if the port of device has the capability
296ec009
MW
3126 * Ethernet Address Handle.
3127 * @device: Device to check
3128 * @port_num: Port number to check
227128fc 3129 *
296ec009
MW
3130 * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
3131 * to fabricate GIDs over Ethernet/IP specific addresses native to the
3132 * port. Normally, packet headers are generated by the sending host
3133 * adapter, but when sending connectionless datagrams, we must manually
3134 * inject the proper headers for the fabric we are communicating over.
227128fc 3135 *
296ec009
MW
3136 * Return: true if we are running as a RoCE port and must force the
3137 * addition of a Global Route Header built from our Ethernet Address
3138 * Handle into our header list for connectionless packets.
227128fc 3139 */
5ede9289 3140static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
227128fc 3141{
8ceb1357
JG
3142 return device->port_data[port_num].immutable.core_cap_flags &
3143 RDMA_CORE_CAP_ETH_AH;
227128fc
MW
3144}
3145
94d595c5
DC
3146/**
3147 * rdma_cap_opa_ah - Check if the port of device supports
3148 * OPA Address handles
3149 * @device: Device to check
3150 * @port_num: Port number to check
3151 *
3152 * Return: true if we are running on an OPA device which supports
3153 * the extended OPA addressing.
3154 */
3155static inline bool rdma_cap_opa_ah(struct ib_device *device, u8 port_num)
3156{
8ceb1357 3157 return (device->port_data[port_num].immutable.core_cap_flags &
94d595c5
DC
3158 RDMA_CORE_CAP_OPA_AH) == RDMA_CORE_CAP_OPA_AH;
3159}
3160
337877a4
IW
3161/**
3162 * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
3163 *
3164 * @device: Device
3165 * @port_num: Port number
3166 *
3167 * This MAD size includes the MAD headers and MAD payload. No other headers
3168 * are included.
3169 *
3170 * Return the max MAD size required by the Port. Will return 0 if the port
3171 * does not support MADs
3172 */
3173static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
3174{
8ceb1357 3175 return device->port_data[port_num].immutable.max_mad_size;
337877a4
IW
3176}
3177
03db3a2d
MB
3178/**
3179 * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
3180 * @device: Device to check
3181 * @port_num: Port number to check
3182 *
3183 * RoCE GID table mechanism manages the various GIDs for a device.
3184 *
3185 * NOTE: if allocating the port's GID table has failed, this call will still
3186 * return true, but any RoCE GID table API will fail.
3187 *
3188 * Return: true if the port uses RoCE GID table mechanism in order to manage
3189 * its GIDs.
3190 */
3191static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
3192 u8 port_num)
3193{
3194 return rdma_protocol_roce(device, port_num) &&
3023a1e9 3195 device->ops.add_gid && device->ops.del_gid;
03db3a2d
MB
3196}
3197
002516ed
CH
3198/*
3199 * Check if the device supports READ W/ INVALIDATE.
3200 */
3201static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
3202{
3203 /*
3204 * iWarp drivers must support READ W/ INVALIDATE. No other protocol
3205 * has support for it yet.
3206 */
3207 return rdma_protocol_iwarp(dev, port_num);
3208}
3209
4a353399
SS
3210/**
3211 * rdma_find_pg_bit - Find page bit given address and HW supported page sizes
3212 *
3213 * @addr: address
3214 * @pgsz_bitmap: bitmap of HW supported page sizes
3215 */
3216static inline unsigned int rdma_find_pg_bit(unsigned long addr,
3217 unsigned long pgsz_bitmap)
3218{
3219 unsigned long align;
3220 unsigned long pgsz;
3221
3222 align = addr & -addr;
3223
3224 /* Find page bit such that addr is aligned to the highest supported
3225 * HW page size
3226 */
3227 pgsz = pgsz_bitmap & ~(-align << 1);
3228 if (!pgsz)
3229 return __ffs(pgsz_bitmap);
3230
3231 return __fls(pgsz);
3232}
3233
50174a7f
EC
3234int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
3235 int state);
3236int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
3237 struct ifla_vf_info *info);
3238int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
3239 struct ifla_vf_stats *stats);
3240int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
3241 int type);
3242
1da177e4
LT
3243int ib_query_pkey(struct ib_device *device,
3244 u8 port_num, u16 index, u16 *pkey);
3245
3246int ib_modify_device(struct ib_device *device,
3247 int device_modify_mask,
3248 struct ib_device_modify *device_modify);
3249
3250int ib_modify_port(struct ib_device *device,
3251 u8 port_num, int port_modify_mask,
3252 struct ib_port_modify *port_modify);
3253
5eb620c8 3254int ib_find_gid(struct ib_device *device, union ib_gid *gid,
b26c4a11 3255 u8 *port_num, u16 *index);
5eb620c8
YE
3256
3257int ib_find_pkey(struct ib_device *device,
3258 u8 port_num, u16 pkey, u16 *index);
3259
ed082d36
CH
3260enum ib_pd_flags {
3261 /*
3262 * Create a memory registration for all memory in the system and place
3263 * the rkey for it into pd->unsafe_global_rkey. This can be used by
3264 * ULPs to avoid the overhead of dynamic MRs.
3265 *
3266 * This flag is generally considered unsafe and must only be used in
3267 * extremly trusted environments. Every use of it will log a warning
3268 * in the kernel log.
3269 */
3270 IB_PD_UNSAFE_GLOBAL_RKEY = 0x01,
3271};
1da177e4 3272
ed082d36
CH
3273struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
3274 const char *caller);
c4367a26 3275
ed082d36 3276#define ib_alloc_pd(device, flags) \
e4496447 3277 __ib_alloc_pd((device), (flags), KBUILD_MODNAME)
c4367a26
SR
3278
3279/**
3280 * ib_dealloc_pd_user - Deallocate kernel/user PD
3281 * @pd: The protection domain
3282 * @udata: Valid user data or NULL for kernel objects
3283 */
3284void ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata);
3285
3286/**
3287 * ib_dealloc_pd - Deallocate kernel PD
3288 * @pd: The protection domain
3289 *
3290 * NOTE: for user PD use ib_dealloc_pd_user with valid udata!
3291 */
3292static inline void ib_dealloc_pd(struct ib_pd *pd)
3293{
3294 ib_dealloc_pd_user(pd, NULL);
3295}
1da177e4 3296
b090c4e3
GP
3297enum rdma_create_ah_flags {
3298 /* In a sleepable context */
3299 RDMA_CREATE_AH_SLEEPABLE = BIT(0),
3300};
3301
1da177e4 3302/**
0a18cfe4 3303 * rdma_create_ah - Creates an address handle for the given address vector.
1da177e4
LT
3304 * @pd: The protection domain associated with the address handle.
3305 * @ah_attr: The attributes of the address vector.
b090c4e3 3306 * @flags: Create address handle flags (see enum rdma_create_ah_flags).
1da177e4
LT
3307 *
3308 * The address handle is used to reference a local or global destination
3309 * in all UD QP post sends.
3310 */
b090c4e3
GP
3311struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
3312 u32 flags);
1da177e4 3313
5cda6587
PP
3314/**
3315 * rdma_create_user_ah - Creates an address handle for the given address vector.
3316 * It resolves destination mac address for ah attribute of RoCE type.
3317 * @pd: The protection domain associated with the address handle.
3318 * @ah_attr: The attributes of the address vector.
3319 * @udata: pointer to user's input output buffer information need by
3320 * provider driver.
3321 *
3322 * It returns 0 on success and returns appropriate error code on error.
3323 * The address handle is used to reference a local or global destination
3324 * in all UD QP post sends.
3325 */
3326struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
3327 struct rdma_ah_attr *ah_attr,
3328 struct ib_udata *udata);
850d8fd7
MS
3329/**
3330 * ib_get_gids_from_rdma_hdr - Get sgid and dgid from GRH or IPv4 header
3331 * work completion.
3332 * @hdr: the L3 header to parse
3333 * @net_type: type of header to parse
3334 * @sgid: place to store source gid
3335 * @dgid: place to store destination gid
3336 */
3337int ib_get_gids_from_rdma_hdr(const union rdma_network_hdr *hdr,
3338 enum rdma_network_type net_type,
3339 union ib_gid *sgid, union ib_gid *dgid);
3340
3341/**
3342 * ib_get_rdma_header_version - Get the header version
3343 * @hdr: the L3 header to parse
3344 */
3345int ib_get_rdma_header_version(const union rdma_network_hdr *hdr);
3346
4e00d694 3347/**
f6bdb142 3348 * ib_init_ah_attr_from_wc - Initializes address handle attributes from a
4e00d694
SH
3349 * work completion.
3350 * @device: Device on which the received message arrived.
3351 * @port_num: Port on which the received message arrived.
3352 * @wc: Work completion associated with the received message.
3353 * @grh: References the received global route header. This parameter is
3354 * ignored unless the work completion indicates that the GRH is valid.
3355 * @ah_attr: Returned attributes that can be used when creating an address
3356 * handle for replying to the message.
b7403217
PP
3357 * When ib_init_ah_attr_from_wc() returns success,
3358 * (a) for IB link layer it optionally contains a reference to SGID attribute
3359 * when GRH is present for IB link layer.
3360 * (b) for RoCE link layer it contains a reference to SGID attribute.
3361 * User must invoke rdma_cleanup_ah_attr_gid_attr() to release reference to SGID
3362 * attributes which are initialized using ib_init_ah_attr_from_wc().
3363 *
4e00d694 3364 */
f6bdb142
PP
3365int ib_init_ah_attr_from_wc(struct ib_device *device, u8 port_num,
3366 const struct ib_wc *wc, const struct ib_grh *grh,
3367 struct rdma_ah_attr *ah_attr);
4e00d694 3368
513789ed
HR
3369/**
3370 * ib_create_ah_from_wc - Creates an address handle associated with the
3371 * sender of the specified work completion.
3372 * @pd: The protection domain associated with the address handle.
3373 * @wc: Work completion information associated with a received message.
3374 * @grh: References the received global route header. This parameter is
3375 * ignored unless the work completion indicates that the GRH is valid.
3376 * @port_num: The outbound port number to associate with the address.
3377 *
3378 * The address handle is used to reference a local or global destination
3379 * in all UD QP post sends.
3380 */
73cdaaee
IW
3381struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
3382 const struct ib_grh *grh, u8 port_num);
513789ed 3383
1da177e4 3384/**
67b985b6 3385 * rdma_modify_ah - Modifies the address vector associated with an address
1da177e4
LT
3386 * handle.
3387 * @ah: The address handle to modify.
3388 * @ah_attr: The new address vector attributes to associate with the
3389 * address handle.
3390 */
67b985b6 3391int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
1da177e4
LT
3392
3393/**
bfbfd661 3394 * rdma_query_ah - Queries the address vector associated with an address
1da177e4
LT
3395 * handle.
3396 * @ah: The address handle to query.
3397 * @ah_attr: The address vector attributes associated with the address
3398 * handle.
3399 */
bfbfd661 3400int rdma_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
1da177e4 3401
2553ba21
GP
3402enum rdma_destroy_ah_flags {
3403 /* In a sleepable context */
3404 RDMA_DESTROY_AH_SLEEPABLE = BIT(0),
3405};
3406
1da177e4 3407/**
c4367a26 3408 * rdma_destroy_ah_user - Destroys an address handle.
1da177e4 3409 * @ah: The address handle to destroy.
2553ba21 3410 * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
c4367a26 3411 * @udata: Valid user data or NULL for kernel objects
1da177e4 3412 */
c4367a26
SR
3413int rdma_destroy_ah_user(struct ib_ah *ah, u32 flags, struct ib_udata *udata);
3414
3415/**
3416 * rdma_destroy_ah - Destroys an kernel address handle.
3417 * @ah: The address handle to destroy.
3418 * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
3419 *
3420 * NOTE: for user ah use rdma_destroy_ah_user with valid udata!
3421 */
3422static inline int rdma_destroy_ah(struct ib_ah *ah, u32 flags)
3423{
3424 return rdma_destroy_ah_user(ah, flags, NULL);
3425}
1da177e4 3426
d41fcc67
RD
3427/**
3428 * ib_create_srq - Creates a SRQ associated with the specified protection
3429 * domain.
3430 * @pd: The protection domain associated with the SRQ.
abb6e9ba
DB
3431 * @srq_init_attr: A list of initial attributes required to create the
3432 * SRQ. If SRQ creation succeeds, then the attributes are updated to
3433 * the actual capabilities of the created SRQ.
d41fcc67
RD
3434 *
3435 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
3436 * requested size of the SRQ, and set to the actual values allocated
3437 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
3438 * will always be at least as large as the requested values.
3439 */
3440struct ib_srq *ib_create_srq(struct ib_pd *pd,
3441 struct ib_srq_init_attr *srq_init_attr);
3442
3443/**
3444 * ib_modify_srq - Modifies the attributes for the specified SRQ.
3445 * @srq: The SRQ to modify.
3446 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
3447 * the current values of selected SRQ attributes are returned.
3448 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
3449 * are being modified.
3450 *
3451 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
3452 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
3453 * the number of receives queued drops below the limit.
3454 */
3455int ib_modify_srq(struct ib_srq *srq,
3456 struct ib_srq_attr *srq_attr,
3457 enum ib_srq_attr_mask srq_attr_mask);
3458
3459/**
3460 * ib_query_srq - Returns the attribute list and current values for the
3461 * specified SRQ.
3462 * @srq: The SRQ to query.
3463 * @srq_attr: The attributes of the specified SRQ.
3464 */
3465int ib_query_srq(struct ib_srq *srq,
3466 struct ib_srq_attr *srq_attr);
3467
3468/**
c4367a26
SR
3469 * ib_destroy_srq_user - Destroys the specified SRQ.
3470 * @srq: The SRQ to destroy.
3471 * @udata: Valid user data or NULL for kernel objects
3472 */
3473int ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata);
3474
3475/**
3476 * ib_destroy_srq - Destroys the specified kernel SRQ.
d41fcc67 3477 * @srq: The SRQ to destroy.
c4367a26
SR
3478 *
3479 * NOTE: for user srq use ib_destroy_srq_user with valid udata!
d41fcc67 3480 */
c4367a26
SR
3481static inline int ib_destroy_srq(struct ib_srq *srq)
3482{
3483 return ib_destroy_srq_user(srq, NULL);
3484}
d41fcc67
RD
3485
3486/**
3487 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
3488 * @srq: The SRQ to post the work request on.
3489 * @recv_wr: A list of work requests to post on the receive queue.
3490 * @bad_recv_wr: On an immediate failure, this parameter will reference
3491 * the work request that failed to be posted on the QP.
3492 */
3493static inline int ib_post_srq_recv(struct ib_srq *srq,
d34ac5cd
BVA
3494 const struct ib_recv_wr *recv_wr,
3495 const struct ib_recv_wr **bad_recv_wr)
d41fcc67 3496{
d34ac5cd 3497 const struct ib_recv_wr *dummy;
bb039a87 3498
3023a1e9
KH
3499 return srq->device->ops.post_srq_recv(srq, recv_wr,
3500 bad_recv_wr ? : &dummy);
d41fcc67
RD
3501}
3502
1da177e4 3503/**
c4367a26 3504 * ib_create_qp_user - Creates a QP associated with the specified protection
1da177e4
LT
3505 * domain.
3506 * @pd: The protection domain associated with the QP.
abb6e9ba
DB
3507 * @qp_init_attr: A list of initial attributes required to create the
3508 * QP. If QP creation succeeds, then the attributes are updated to
3509 * the actual capabilities of the created QP.
c4367a26 3510 * @udata: Valid user data or NULL for kernel objects
1da177e4 3511 */
c4367a26
SR
3512struct ib_qp *ib_create_qp_user(struct ib_pd *pd,
3513 struct ib_qp_init_attr *qp_init_attr,
3514 struct ib_udata *udata);
3515
3516/**
3517 * ib_create_qp - Creates a kernel QP associated with the specified protection
3518 * domain.
3519 * @pd: The protection domain associated with the QP.
3520 * @qp_init_attr: A list of initial attributes required to create the
3521 * QP. If QP creation succeeds, then the attributes are updated to
3522 * the actual capabilities of the created QP.
3523 * @udata: Valid user data or NULL for kernel objects
3524 *
3525 * NOTE: for user qp use ib_create_qp_user with valid udata!
3526 */
3527static inline struct ib_qp *ib_create_qp(struct ib_pd *pd,
3528 struct ib_qp_init_attr *qp_init_attr)
3529{
3530 return ib_create_qp_user(pd, qp_init_attr, NULL);
3531}
1da177e4 3532
a512c2fb
PP
3533/**
3534 * ib_modify_qp_with_udata - Modifies the attributes for the specified QP.
3535 * @qp: The QP to modify.
3536 * @attr: On input, specifies the QP attributes to modify. On output,
3537 * the current values of selected QP attributes are returned.
3538 * @attr_mask: A bit-mask used to specify which attributes of the QP
3539 * are being modified.
3540 * @udata: pointer to user's input output buffer information
3541 * are being modified.
3542 * It returns 0 on success and returns appropriate error code on error.
3543 */
3544int ib_modify_qp_with_udata(struct ib_qp *qp,
3545 struct ib_qp_attr *attr,
3546 int attr_mask,
3547 struct ib_udata *udata);
3548
1da177e4
LT
3549/**
3550 * ib_modify_qp - Modifies the attributes for the specified QP and then
3551 * transitions the QP to the given state.
3552 * @qp: The QP to modify.
3553 * @qp_attr: On input, specifies the QP attributes to modify. On output,
3554 * the current values of selected QP attributes are returned.
3555 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
3556 * are being modified.
3557 */
3558int ib_modify_qp(struct ib_qp *qp,
3559 struct ib_qp_attr *qp_attr,
3560 int qp_attr_mask);
3561
3562/**
3563 * ib_query_qp - Returns the attribute list and current values for the
3564 * specified QP.
3565 * @qp: The QP to query.
3566 * @qp_attr: The attributes of the specified QP.
3567 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
3568 * @qp_init_attr: Additional attributes of the selected QP.
3569 *
3570 * The qp_attr_mask may be used to limit the query to gathering only the
3571 * selected attributes.
3572 */
3573int ib_query_qp(struct ib_qp *qp,
3574 struct ib_qp_attr *qp_attr,
3575 int qp_attr_mask,
3576 struct ib_qp_init_attr *qp_init_attr);
3577
3578/**
3579 * ib_destroy_qp - Destroys the specified QP.
3580 * @qp: The QP to destroy.
c4367a26 3581 * @udata: Valid udata or NULL for kernel objects
1da177e4 3582 */
c4367a26
SR
3583int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata);
3584
3585/**
3586 * ib_destroy_qp - Destroys the specified kernel QP.
3587 * @qp: The QP to destroy.
3588 *
3589 * NOTE: for user qp use ib_destroy_qp_user with valid udata!
3590 */
3591static inline int ib_destroy_qp(struct ib_qp *qp)
3592{
3593 return ib_destroy_qp_user(qp, NULL);
3594}
1da177e4 3595
d3d72d90 3596/**
0e0ec7e0
SH
3597 * ib_open_qp - Obtain a reference to an existing sharable QP.
3598 * @xrcd - XRC domain
3599 * @qp_open_attr: Attributes identifying the QP to open.
3600 *
3601 * Returns a reference to a sharable QP.
3602 */
3603struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
3604 struct ib_qp_open_attr *qp_open_attr);
3605
3606/**
3607 * ib_close_qp - Release an external reference to a QP.
d3d72d90
SH
3608 * @qp: The QP handle to release
3609 *
0e0ec7e0
SH
3610 * The opened QP handle is released by the caller. The underlying
3611 * shared QP is not destroyed until all internal references are released.
d3d72d90 3612 */
0e0ec7e0 3613int ib_close_qp(struct ib_qp *qp);
d3d72d90 3614
1da177e4
LT
3615/**
3616 * ib_post_send - Posts a list of work requests to the send queue of
3617 * the specified QP.
3618 * @qp: The QP to post the work request on.
3619 * @send_wr: A list of work requests to post on the send queue.
3620 * @bad_send_wr: On an immediate failure, this parameter will reference
3621 * the work request that failed to be posted on the QP.
55464d46
BVA
3622 *
3623 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
3624 * error is returned, the QP state shall not be affected,
3625 * ib_post_send() will return an immediate error after queueing any
3626 * earlier work requests in the list.
1da177e4
LT
3627 */
3628static inline int ib_post_send(struct ib_qp *qp,
d34ac5cd
BVA
3629 const struct ib_send_wr *send_wr,
3630 const struct ib_send_wr **bad_send_wr)
1da177e4 3631{
d34ac5cd 3632 const struct ib_send_wr *dummy;
bb039a87 3633
3023a1e9 3634 return qp->device->ops.post_send(qp, send_wr, bad_send_wr ? : &dummy);
1da177e4
LT
3635}
3636
3637/**
3638 * ib_post_recv - Posts a list of work requests to the receive queue of
3639 * the specified QP.
3640 * @qp: The QP to post the work request on.
3641 * @recv_wr: A list of work requests to post on the receive queue.
3642 * @bad_recv_wr: On an immediate failure, this parameter will reference
3643 * the work request that failed to be posted on the QP.
3644 */
3645static inline int ib_post_recv(struct ib_qp *qp,
d34ac5cd
BVA
3646 const struct ib_recv_wr *recv_wr,
3647 const struct ib_recv_wr **bad_recv_wr)
1da177e4 3648{
d34ac5cd 3649 const struct ib_recv_wr *dummy;
bb039a87 3650
3023a1e9 3651 return qp->device->ops.post_recv(qp, recv_wr, bad_recv_wr ? : &dummy);
1da177e4
LT
3652}
3653
c4367a26
SR
3654struct ib_cq *__ib_alloc_cq_user(struct ib_device *dev, void *private,
3655 int nr_cqe, int comp_vector,
3656 enum ib_poll_context poll_ctx,
3657 const char *caller, struct ib_udata *udata);
3658
3659/**
3660 * ib_alloc_cq_user: Allocate kernel/user CQ
3661 * @dev: The IB device
3662 * @private: Private data attached to the CQE
3663 * @nr_cqe: Number of CQEs in the CQ
3664 * @comp_vector: Completion vector used for the IRQs
3665 * @poll_ctx: Context used for polling the CQ
3666 * @udata: Valid user data or NULL for kernel objects
3667 */
3668static inline struct ib_cq *ib_alloc_cq_user(struct ib_device *dev,
3669 void *private, int nr_cqe,
3670 int comp_vector,
3671 enum ib_poll_context poll_ctx,
3672 struct ib_udata *udata)
3673{
3674 return __ib_alloc_cq_user(dev, private, nr_cqe, comp_vector, poll_ctx,
3675 KBUILD_MODNAME, udata);
3676}
3677
3678/**
3679 * ib_alloc_cq: Allocate kernel CQ
3680 * @dev: The IB device
3681 * @private: Private data attached to the CQE
3682 * @nr_cqe: Number of CQEs in the CQ
3683 * @comp_vector: Completion vector used for the IRQs
3684 * @poll_ctx: Context used for polling the CQ
3685 *
3686 * NOTE: for user cq use ib_alloc_cq_user with valid udata!
3687 */
3688static inline struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
3689 int nr_cqe, int comp_vector,
3690 enum ib_poll_context poll_ctx)
3691{
3692 return ib_alloc_cq_user(dev, private, nr_cqe, comp_vector, poll_ctx,
3693 NULL);
3694}
3695
3696/**
3697 * ib_free_cq_user - Free kernel/user CQ
3698 * @cq: The CQ to free
3699 * @udata: Valid user data or NULL for kernel objects
3700 */
3701void ib_free_cq_user(struct ib_cq *cq, struct ib_udata *udata);
3702
3703/**
3704 * ib_free_cq - Free kernel CQ
3705 * @cq: The CQ to free
3706 *
3707 * NOTE: for user cq use ib_free_cq_user with valid udata!
3708 */
3709static inline void ib_free_cq(struct ib_cq *cq)
3710{
3711 ib_free_cq_user(cq, NULL);
3712}
f66c8ba4 3713
14d3a3b2
CH
3714int ib_process_cq_direct(struct ib_cq *cq, int budget);
3715
1da177e4
LT
3716/**
3717 * ib_create_cq - Creates a CQ on the specified device.
3718 * @device: The device on which to create the CQ.
3719 * @comp_handler: A user-specified callback that is invoked when a
3720 * completion event occurs on the CQ.
3721 * @event_handler: A user-specified callback that is invoked when an
3722 * asynchronous event not associated with a completion occurs on the CQ.
3723 * @cq_context: Context associated with the CQ returned to the user via
3724 * the associated completion and event handlers.
8e37210b 3725 * @cq_attr: The attributes the CQ should be created upon.
1da177e4
LT
3726 *
3727 * Users can examine the cq structure to determine the actual CQ size.
3728 */
7350cdd0
BP
3729struct ib_cq *__ib_create_cq(struct ib_device *device,
3730 ib_comp_handler comp_handler,
3731 void (*event_handler)(struct ib_event *, void *),
3732 void *cq_context,
3733 const struct ib_cq_init_attr *cq_attr,
3734 const char *caller);
3735#define ib_create_cq(device, cmp_hndlr, evt_hndlr, cq_ctxt, cq_attr) \
3736 __ib_create_cq((device), (cmp_hndlr), (evt_hndlr), (cq_ctxt), (cq_attr), KBUILD_MODNAME)
1da177e4
LT
3737
3738/**
3739 * ib_resize_cq - Modifies the capacity of the CQ.
3740 * @cq: The CQ to resize.
3741 * @cqe: The minimum size of the CQ.
3742 *
3743 * Users can examine the cq structure to determine the actual CQ size.
3744 */
3745int ib_resize_cq(struct ib_cq *cq, int cqe);
3746
2dd57162 3747/**
4190b4e9 3748 * rdma_set_cq_moderation - Modifies moderation params of the CQ
2dd57162
EC
3749 * @cq: The CQ to modify.
3750 * @cq_count: number of CQEs that will trigger an event
3751 * @cq_period: max period of time in usec before triggering an event
3752 *
3753 */
4190b4e9 3754int rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period);
2dd57162 3755
1da177e4 3756/**
c4367a26 3757 * ib_destroy_cq_user - Destroys the specified CQ.
1da177e4 3758 * @cq: The CQ to destroy.
c4367a26 3759 * @udata: Valid user data or NULL for kernel objects
1da177e4 3760 */
c4367a26
SR
3761int ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata);
3762
3763/**
3764 * ib_destroy_cq - Destroys the specified kernel CQ.
3765 * @cq: The CQ to destroy.
3766 *
3767 * NOTE: for user cq use ib_destroy_cq_user with valid udata!
3768 */
890ac8d9 3769static inline void ib_destroy_cq(struct ib_cq *cq)
c4367a26 3770{
890ac8d9 3771 ib_destroy_cq_user(cq, NULL);
c4367a26 3772}
1da177e4
LT
3773
3774/**
3775 * ib_poll_cq - poll a CQ for completion(s)
3776 * @cq:the CQ being polled
3777 * @num_entries:maximum number of completions to return
3778 * @wc:array of at least @num_entries &struct ib_wc where completions
3779 * will be returned
3780 *
3781 * Poll a CQ for (possibly multiple) completions. If the return value
3782 * is < 0, an error occurred. If the return value is >= 0, it is the
3783 * number of completions returned. If the return value is
3784 * non-negative and < num_entries, then the CQ was emptied.
3785 */
3786static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
3787 struct ib_wc *wc)
3788{
3023a1e9 3789 return cq->device->ops.poll_cq(cq, num_entries, wc);
1da177e4
LT
3790}
3791
1da177e4
LT
3792/**
3793 * ib_req_notify_cq - Request completion notification on a CQ.
3794 * @cq: The CQ to generate an event for.
ed23a727
RD
3795 * @flags:
3796 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
3797 * to request an event on the next solicited event or next work
3798 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
3799 * may also be |ed in to request a hint about missed events, as
3800 * described below.
3801 *
3802 * Return Value:
3803 * < 0 means an error occurred while requesting notification
3804 * == 0 means notification was requested successfully, and if
3805 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
3806 * were missed and it is safe to wait for another event. In
3807 * this case is it guaranteed that any work completions added
3808 * to the CQ since the last CQ poll will trigger a completion
3809 * notification event.
3810 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
3811 * in. It means that the consumer must poll the CQ again to
3812 * make sure it is empty to avoid missing an event because of a
3813 * race between requesting notification and an entry being
3814 * added to the CQ. This return value means it is possible
3815 * (but not guaranteed) that a work completion has been added
3816 * to the CQ since the last poll without triggering a
3817 * completion notification event.
1da177e4
LT
3818 */
3819static inline int ib_req_notify_cq(struct ib_cq *cq,
ed23a727 3820 enum ib_cq_notify_flags flags)
1da177e4 3821{
3023a1e9 3822 return cq->device->ops.req_notify_cq(cq, flags);
1da177e4
LT
3823}
3824
3825/**
3826 * ib_req_ncomp_notif - Request completion notification when there are
3827 * at least the specified number of unreaped completions on the CQ.
3828 * @cq: The CQ to generate an event for.
3829 * @wc_cnt: The number of unreaped completions that should be on the
3830 * CQ before an event is generated.
3831 */
3832static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
3833{
3023a1e9
KH
3834 return cq->device->ops.req_ncomp_notif ?
3835 cq->device->ops.req_ncomp_notif(cq, wc_cnt) :
1da177e4
LT
3836 -ENOSYS;
3837}
3838
9b513090
RC
3839/**
3840 * ib_dma_mapping_error - check a DMA addr for error
3841 * @dev: The device for which the dma_addr was created
3842 * @dma_addr: The DMA address to check
3843 */
3844static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
3845{
0957c29f 3846 return dma_mapping_error(dev->dma_device, dma_addr);
9b513090
RC
3847}
3848
3849/**
3850 * ib_dma_map_single - Map a kernel virtual address to DMA address
3851 * @dev: The device for which the dma_addr is to be created
3852 * @cpu_addr: The kernel virtual address
3853 * @size: The size of the region in bytes
3854 * @direction: The direction of the DMA
3855 */
3856static inline u64 ib_dma_map_single(struct ib_device *dev,
3857 void *cpu_addr, size_t size,
3858 enum dma_data_direction direction)
3859{
0957c29f 3860 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
9b513090
RC
3861}
3862
3863/**
3864 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
3865 * @dev: The device for which the DMA address was created
3866 * @addr: The DMA address
3867 * @size: The size of the region in bytes
3868 * @direction: The direction of the DMA
3869 */
3870static inline void ib_dma_unmap_single(struct ib_device *dev,
3871 u64 addr, size_t size,
3872 enum dma_data_direction direction)
3873{
0957c29f 3874 dma_unmap_single(dev->dma_device, addr, size, direction);
cb9fbc5c
AK
3875}
3876
9b513090
RC
3877/**
3878 * ib_dma_map_page - Map a physical page to DMA address
3879 * @dev: The device for which the dma_addr is to be created
3880 * @page: The page to be mapped
3881 * @offset: The offset within the page
3882 * @size: The size of the region in bytes
3883 * @direction: The direction of the DMA
3884 */
3885static inline u64 ib_dma_map_page(struct ib_device *dev,
3886 struct page *page,
3887 unsigned long offset,
3888 size_t size,
3889 enum dma_data_direction direction)
3890{
0957c29f 3891 return dma_map_page(dev->dma_device, page, offset, size, direction);
9b513090
RC
3892}
3893
3894/**
3895 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
3896 * @dev: The device for which the DMA address was created
3897 * @addr: The DMA address
3898 * @size: The size of the region in bytes
3899 * @direction: The direction of the DMA
3900 */
3901static inline void ib_dma_unmap_page(struct ib_device *dev,
3902 u64 addr, size_t size,
3903 enum dma_data_direction direction)
3904{
0957c29f 3905 dma_unmap_page(dev->dma_device, addr, size, direction);
9b513090
RC
3906}
3907
3908/**
3909 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
3910 * @dev: The device for which the DMA addresses are to be created
3911 * @sg: The array of scatter/gather entries
3912 * @nents: The number of scatter/gather entries
3913 * @direction: The direction of the DMA
3914 */
3915static inline int ib_dma_map_sg(struct ib_device *dev,
3916 struct scatterlist *sg, int nents,
3917 enum dma_data_direction direction)
3918{
0957c29f 3919 return dma_map_sg(dev->dma_device, sg, nents, direction);
9b513090
RC
3920}
3921
3922/**
3923 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
3924 * @dev: The device for which the DMA addresses were created
3925 * @sg: The array of scatter/gather entries
3926 * @nents: The number of scatter/gather entries
3927 * @direction: The direction of the DMA
3928 */
3929static inline void ib_dma_unmap_sg(struct ib_device *dev,
3930 struct scatterlist *sg, int nents,
3931 enum dma_data_direction direction)
3932{
0957c29f 3933 dma_unmap_sg(dev->dma_device, sg, nents, direction);
9b513090
RC
3934}
3935
cb9fbc5c
AK
3936static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
3937 struct scatterlist *sg, int nents,
3938 enum dma_data_direction direction,
00085f1e 3939 unsigned long dma_attrs)
cb9fbc5c 3940{
0957c29f
BVA
3941 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
3942 dma_attrs);
cb9fbc5c
AK
3943}
3944
3945static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
3946 struct scatterlist *sg, int nents,
3947 enum dma_data_direction direction,
00085f1e 3948 unsigned long dma_attrs)
cb9fbc5c 3949{
0957c29f 3950 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, dma_attrs);
cb9fbc5c 3951}
9b513090 3952
0b5cb330
BVA
3953/**
3954 * ib_dma_max_seg_size - Return the size limit of a single DMA transfer
3955 * @dev: The device to query
3956 *
3957 * The returned value represents a size in bytes.
3958 */
3959static inline unsigned int ib_dma_max_seg_size(struct ib_device *dev)
3960{
3961 struct device_dma_parameters *p = dev->dma_device->dma_parms;
3962
3963 return p ? p->max_segment_size : UINT_MAX;
3964}
3965
9b513090
RC
3966/**
3967 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
3968 * @dev: The device for which the DMA address was created
3969 * @addr: The DMA address
3970 * @size: The size of the region in bytes
3971 * @dir: The direction of the DMA
3972 */
3973static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
3974 u64 addr,
3975 size_t size,
3976 enum dma_data_direction dir)
3977{
0957c29f 3978 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
9b513090
RC
3979}
3980
3981/**
3982 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
3983 * @dev: The device for which the DMA address was created
3984 * @addr: The DMA address
3985 * @size: The size of the region in bytes
3986 * @dir: The direction of the DMA
3987 */
3988static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
3989 u64 addr,
3990 size_t size,
3991 enum dma_data_direction dir)
3992{
0957c29f 3993 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
9b513090
RC
3994}
3995
3996/**
3997 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
3998 * @dev: The device for which the DMA address is requested
3999 * @size: The size of the region to allocate in bytes
4000 * @dma_handle: A pointer for returning the DMA address of the region
4001 * @flag: memory allocator flags
4002 */
4003static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
4004 size_t size,
d43dbacf 4005 dma_addr_t *dma_handle,
9b513090
RC
4006 gfp_t flag)
4007{
0957c29f 4008 return dma_alloc_coherent(dev->dma_device, size, dma_handle, flag);
9b513090
RC
4009}
4010
4011/**
4012 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
4013 * @dev: The device for which the DMA addresses were allocated
4014 * @size: The size of the region
4015 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
4016 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
4017 */
4018static inline void ib_dma_free_coherent(struct ib_device *dev,
4019 size_t size, void *cpu_addr,
d43dbacf 4020 dma_addr_t dma_handle)
9b513090 4021{
0957c29f 4022 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
9b513090
RC
4023}
4024
1da177e4 4025/**
c4367a26
SR
4026 * ib_dereg_mr_user - Deregisters a memory region and removes it from the
4027 * HCA translation table.
4028 * @mr: The memory region to deregister.
4029 * @udata: Valid user data or NULL for kernel object
4030 *
4031 * This function can fail, if the memory region has memory windows bound to it.
4032 */
4033int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata);
4034
4035/**
4036 * ib_dereg_mr - Deregisters a kernel memory region and removes it from the
1da177e4
LT
4037 * HCA translation table.
4038 * @mr: The memory region to deregister.
7083e42e
SM
4039 *
4040 * This function can fail, if the memory region has memory windows bound to it.
c4367a26
SR
4041 *
4042 * NOTE: for user mr use ib_dereg_mr_user with valid udata!
1da177e4 4043 */
c4367a26
SR
4044static inline int ib_dereg_mr(struct ib_mr *mr)
4045{
4046 return ib_dereg_mr_user(mr, NULL);
4047}
4048
4049struct ib_mr *ib_alloc_mr_user(struct ib_pd *pd, enum ib_mr_type mr_type,
4050 u32 max_num_sg, struct ib_udata *udata);
1da177e4 4051
c4367a26
SR
4052static inline struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
4053 enum ib_mr_type mr_type, u32 max_num_sg)
4054{
4055 return ib_alloc_mr_user(pd, mr_type, max_num_sg, NULL);
4056}
00f7ec36 4057
26bc7eae
IR
4058struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
4059 u32 max_num_data_sg,
4060 u32 max_num_meta_sg);
4061
00f7ec36
SW
4062/**
4063 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
4064 * R_Key and L_Key.
4065 * @mr - struct ib_mr pointer to be updated.
4066 * @newkey - new key to be used.
4067 */
4068static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
4069{
4070 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
4071 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
4072}
4073
7083e42e
SM
4074/**
4075 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
4076 * for calculating a new rkey for type 2 memory windows.
4077 * @rkey - the rkey to increment.
4078 */
4079static inline u32 ib_inc_rkey(u32 rkey)
4080{
4081 const u32 mask = 0x000000ff;
4082 return ((rkey + 1) & mask) | (rkey & ~mask);
4083}
4084
1da177e4
LT
4085/**
4086 * ib_alloc_fmr - Allocates a unmapped fast memory region.
4087 * @pd: The protection domain associated with the unmapped region.
4088 * @mr_access_flags: Specifies the memory access rights.
4089 * @fmr_attr: Attributes of the unmapped region.
4090 *
4091 * A fast memory region must be mapped before it can be used as part of
4092 * a work request.
4093 */
4094struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
4095 int mr_access_flags,
4096 struct ib_fmr_attr *fmr_attr);
4097
4098/**
4099 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
4100 * @fmr: The fast memory region to associate with the pages.
4101 * @page_list: An array of physical pages to map to the fast memory region.
4102 * @list_len: The number of pages in page_list.
4103 * @iova: The I/O virtual address to use with the mapped region.
4104 */
4105static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
4106 u64 *page_list, int list_len,
4107 u64 iova)
4108{
3023a1e9 4109 return fmr->device->ops.map_phys_fmr(fmr, page_list, list_len, iova);
1da177e4
LT
4110}
4111
4112/**
4113 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
4114 * @fmr_list: A linked list of fast memory regions to unmap.
4115 */
4116int ib_unmap_fmr(struct list_head *fmr_list);
4117
4118/**
4119 * ib_dealloc_fmr - Deallocates a fast memory region.
4120 * @fmr: The fast memory region to deallocate.
4121 */
4122int ib_dealloc_fmr(struct ib_fmr *fmr);
4123
4124/**
4125 * ib_attach_mcast - Attaches the specified QP to a multicast group.
4126 * @qp: QP to attach to the multicast group. The QP must be type
4127 * IB_QPT_UD.
4128 * @gid: Multicast group GID.
4129 * @lid: Multicast group LID in host byte order.
4130 *
4131 * In order to send and receive multicast packets, subnet
4132 * administration must have created the multicast group and configured
4133 * the fabric appropriately. The port associated with the specified
4134 * QP must also be a member of the multicast group.
4135 */
4136int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
4137
4138/**
4139 * ib_detach_mcast - Detaches the specified QP from a multicast group.
4140 * @qp: QP to detach from the multicast group.
4141 * @gid: Multicast group GID.
4142 * @lid: Multicast group LID in host byte order.
4143 */
4144int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
4145
59991f94
SH
4146/**
4147 * ib_alloc_xrcd - Allocates an XRC domain.
4148 * @device: The device on which to allocate the XRC domain.
f66c8ba4 4149 * @caller: Module name for kernel consumers
59991f94 4150 */
f66c8ba4
LR
4151struct ib_xrcd *__ib_alloc_xrcd(struct ib_device *device, const char *caller);
4152#define ib_alloc_xrcd(device) \
4153 __ib_alloc_xrcd((device), KBUILD_MODNAME)
59991f94
SH
4154
4155/**
4156 * ib_dealloc_xrcd - Deallocates an XRC domain.
4157 * @xrcd: The XRC domain to deallocate.
c4367a26 4158 * @udata: Valid user data or NULL for kernel object
59991f94 4159 */
c4367a26 4160int ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
59991f94 4161
1c636f80
EC
4162static inline int ib_check_mr_access(int flags)
4163{
4164 /*
4165 * Local write permission is required if remote write or
4166 * remote atomic permission is also requested.
4167 */
4168 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
4169 !(flags & IB_ACCESS_LOCAL_WRITE))
4170 return -EINVAL;
4171
4172 return 0;
4173}
4174
08bb558a
JM
4175static inline bool ib_access_writable(int access_flags)
4176{
4177 /*
4178 * We have writable memory backing the MR if any of the following
4179 * access flags are set. "Local write" and "remote write" obviously
4180 * require write access. "Remote atomic" can do things like fetch and
4181 * add, which will modify memory, and "MW bind" can change permissions
4182 * by binding a window.
4183 */
4184 return access_flags &
4185 (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE |
4186 IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND);
4187}
4188
1b01d335
SG
4189/**
4190 * ib_check_mr_status: lightweight check of MR status.
4191 * This routine may provide status checks on a selected
4192 * ib_mr. first use is for signature status check.
4193 *
4194 * @mr: A memory region.
4195 * @check_mask: Bitmask of which checks to perform from
4196 * ib_mr_status_check enumeration.
4197 * @mr_status: The container of relevant status checks.
4198 * failed checks will be indicated in the status bitmask
4199 * and the relevant info shall be in the error item.
4200 */
4201int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
4202 struct ib_mr_status *mr_status);
4203
d79af724
JG
4204/**
4205 * ib_device_try_get: Hold a registration lock
4206 * device: The device to lock
4207 *
4208 * A device under an active registration lock cannot become unregistered. It
4209 * is only possible to obtain a registration lock on a device that is fully
4210 * registered, otherwise this function returns false.
4211 *
4212 * The registration lock is only necessary for actions which require the
4213 * device to still be registered. Uses that only require the device pointer to
4214 * be valid should use get_device(&ibdev->dev) to hold the memory.
4215 *
4216 */
4217static inline bool ib_device_try_get(struct ib_device *dev)
4218{
4219 return refcount_inc_not_zero(&dev->refcount);
4220}
4221
4222void ib_device_put(struct ib_device *device);
324e227e
JG
4223struct ib_device *ib_device_get_by_netdev(struct net_device *ndev,
4224 enum rdma_driver_id driver_id);
4225struct ib_device *ib_device_get_by_name(const char *name,
4226 enum rdma_driver_id driver_id);
9268f72d
YK
4227struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
4228 u16 pkey, const union ib_gid *gid,
4229 const struct sockaddr *addr);
c2261dd7
JG
4230int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
4231 unsigned int port);
4232struct net_device *ib_device_netdev(struct ib_device *dev, u8 port);
4233
5fd251c8
YH
4234struct ib_wq *ib_create_wq(struct ib_pd *pd,
4235 struct ib_wq_init_attr *init_attr);
c4367a26 4236int ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata);
5fd251c8
YH
4237int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
4238 u32 wq_attr_mask);
6d39786b
YH
4239struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
4240 struct ib_rwq_ind_table_init_attr*
4241 wq_ind_table_init_attr);
4242int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
9268f72d 4243
ff2ba993 4244int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
9aa8b321 4245 unsigned int *sg_offset, unsigned int page_size);
2cdfcdd8
MG
4246int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg,
4247 int data_sg_nents, unsigned int *data_sg_offset,
4248 struct scatterlist *meta_sg, int meta_sg_nents,
4249 unsigned int *meta_sg_offset, unsigned int page_size);
4c67e2bf
SG
4250
4251static inline int
ff2ba993 4252ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
9aa8b321 4253 unsigned int *sg_offset, unsigned int page_size)
4c67e2bf
SG
4254{
4255 int n;
4256
ff2ba993 4257 n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
4c67e2bf
SG
4258 mr->iova = 0;
4259
4260 return n;
4261}
4262
ff2ba993 4263int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
9aa8b321 4264 unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
4c67e2bf 4265
765d6774
SW
4266void ib_drain_rq(struct ib_qp *qp);
4267void ib_drain_sq(struct ib_qp *qp);
4268void ib_drain_qp(struct ib_qp *qp);
850d8fd7 4269
d4186194 4270int ib_get_eth_speed(struct ib_device *dev, u8 port_num, u8 *speed, u8 *width);
2224c47a
DC
4271
4272static inline u8 *rdma_ah_retrieve_dmac(struct rdma_ah_attr *attr)
4273{
44c58487
DC
4274 if (attr->type == RDMA_AH_ATTR_TYPE_ROCE)
4275 return attr->roce.dmac;
4276 return NULL;
2224c47a
DC
4277}
4278
64b4646e 4279static inline void rdma_ah_set_dlid(struct rdma_ah_attr *attr, u32 dlid)
2224c47a 4280{
44c58487 4281 if (attr->type == RDMA_AH_ATTR_TYPE_IB)
64b4646e
DC
4282 attr->ib.dlid = (u16)dlid;
4283 else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4284 attr->opa.dlid = dlid;
2224c47a
DC
4285}
4286
64b4646e 4287static inline u32 rdma_ah_get_dlid(const struct rdma_ah_attr *attr)
2224c47a 4288{
44c58487
DC
4289 if (attr->type == RDMA_AH_ATTR_TYPE_IB)
4290 return attr->ib.dlid;
64b4646e
DC
4291 else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4292 return attr->opa.dlid;
44c58487 4293 return 0;
2224c47a
DC
4294}
4295
4296static inline void rdma_ah_set_sl(struct rdma_ah_attr *attr, u8 sl)
4297{
4298 attr->sl = sl;
4299}
4300
4301static inline u8 rdma_ah_get_sl(const struct rdma_ah_attr *attr)
4302{
4303 return attr->sl;
4304}
4305
4306static inline void rdma_ah_set_path_bits(struct rdma_ah_attr *attr,
4307 u8 src_path_bits)
4308{
44c58487
DC
4309 if (attr->type == RDMA_AH_ATTR_TYPE_IB)
4310 attr->ib.src_path_bits = src_path_bits;
64b4646e
DC
4311 else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4312 attr->opa.src_path_bits = src_path_bits;
2224c47a
DC
4313}
4314
4315static inline u8 rdma_ah_get_path_bits(const struct rdma_ah_attr *attr)
4316{
44c58487
DC
4317 if (attr->type == RDMA_AH_ATTR_TYPE_IB)
4318 return attr->ib.src_path_bits;
64b4646e
DC
4319 else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4320 return attr->opa.src_path_bits;
44c58487 4321 return 0;
2224c47a
DC
4322}
4323
d98bb7f7
DH
4324static inline void rdma_ah_set_make_grd(struct rdma_ah_attr *attr,
4325 bool make_grd)
4326{
4327 if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4328 attr->opa.make_grd = make_grd;
4329}
4330
4331static inline bool rdma_ah_get_make_grd(const struct rdma_ah_attr *attr)
4332{
4333 if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4334 return attr->opa.make_grd;
4335 return false;
4336}
4337
2224c47a
DC
4338static inline void rdma_ah_set_port_num(struct rdma_ah_attr *attr, u8 port_num)
4339{
4340 attr->port_num = port_num;
4341}
4342
4343static inline u8 rdma_ah_get_port_num(const struct rdma_ah_attr *attr)
4344{
4345 return attr->port_num;
4346}
4347
4348static inline void rdma_ah_set_static_rate(struct rdma_ah_attr *attr,
4349 u8 static_rate)
4350{
4351 attr->static_rate = static_rate;
4352}
4353
4354static inline u8 rdma_ah_get_static_rate(const struct rdma_ah_attr *attr)
4355{
4356 return attr->static_rate;
4357}
4358
4359static inline void rdma_ah_set_ah_flags(struct rdma_ah_attr *attr,
4360 enum ib_ah_flags flag)
4361{
4362 attr->ah_flags = flag;
4363}
4364
4365static inline enum ib_ah_flags
4366 rdma_ah_get_ah_flags(const struct rdma_ah_attr *attr)
4367{
4368 return attr->ah_flags;
4369}
4370
4371static inline const struct ib_global_route
4372 *rdma_ah_read_grh(const struct rdma_ah_attr *attr)
4373{
4374 return &attr->grh;
4375}
4376
4377/*To retrieve and modify the grh */
4378static inline struct ib_global_route
4379 *rdma_ah_retrieve_grh(struct rdma_ah_attr *attr)
4380{
4381 return &attr->grh;
4382}
4383
4384static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr, void *dgid)
4385{
4386 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
4387
4388 memcpy(grh->dgid.raw, dgid, sizeof(grh->dgid));
4389}
4390
4391static inline void rdma_ah_set_subnet_prefix(struct rdma_ah_attr *attr,
4392 __be64 prefix)
4393{
4394 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
4395
4396 grh->dgid.global.subnet_prefix = prefix;
4397}
4398
4399static inline void rdma_ah_set_interface_id(struct rdma_ah_attr *attr,
4400 __be64 if_id)
4401{
4402 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
4403
4404 grh->dgid.global.interface_id = if_id;
4405}
4406
4407static inline void rdma_ah_set_grh(struct rdma_ah_attr *attr,
4408 union ib_gid *dgid, u32 flow_label,
4409 u8 sgid_index, u8 hop_limit,
4410 u8 traffic_class)
4411{
4412 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
4413
4414 attr->ah_flags = IB_AH_GRH;
4415 if (dgid)
4416 grh->dgid = *dgid;
4417 grh->flow_label = flow_label;
4418 grh->sgid_index = sgid_index;
4419 grh->hop_limit = hop_limit;
4420 grh->traffic_class = traffic_class;
8d9ec9ad 4421 grh->sgid_attr = NULL;
2224c47a 4422}
44c58487 4423
8d9ec9ad
JG
4424void rdma_destroy_ah_attr(struct rdma_ah_attr *ah_attr);
4425void rdma_move_grh_sgid_attr(struct rdma_ah_attr *attr, union ib_gid *dgid,
4426 u32 flow_label, u8 hop_limit, u8 traffic_class,
4427 const struct ib_gid_attr *sgid_attr);
d97099fe
JG
4428void rdma_copy_ah_attr(struct rdma_ah_attr *dest,
4429 const struct rdma_ah_attr *src);
4430void rdma_replace_ah_attr(struct rdma_ah_attr *old,
4431 const struct rdma_ah_attr *new);
4432void rdma_move_ah_attr(struct rdma_ah_attr *dest, struct rdma_ah_attr *src);
8d9ec9ad 4433
87daac68
DH
4434/**
4435 * rdma_ah_find_type - Return address handle type.
4436 *
4437 * @dev: Device to be checked
4438 * @port_num: Port number
4439 */
44c58487 4440static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev,
87daac68 4441 u8 port_num)
44c58487 4442{
a6532e71 4443 if (rdma_protocol_roce(dev, port_num))
44c58487 4444 return RDMA_AH_ATTR_TYPE_ROCE;
87daac68
DH
4445 if (rdma_protocol_ib(dev, port_num)) {
4446 if (rdma_cap_opa_ah(dev, port_num))
4447 return RDMA_AH_ATTR_TYPE_OPA;
44c58487 4448 return RDMA_AH_ATTR_TYPE_IB;
87daac68
DH
4449 }
4450
4451 return RDMA_AH_ATTR_TYPE_UNDEFINED;
44c58487 4452}
7db20ecd 4453
62ede777
HD
4454/**
4455 * ib_lid_cpu16 - Return lid in 16bit CPU encoding.
4456 * In the current implementation the only way to get
4457 * get the 32bit lid is from other sources for OPA.
4458 * For IB, lids will always be 16bits so cast the
4459 * value accordingly.
4460 *
4461 * @lid: A 32bit LID
4462 */
4463static inline u16 ib_lid_cpu16(u32 lid)
7db20ecd 4464{
62ede777
HD
4465 WARN_ON_ONCE(lid & 0xFFFF0000);
4466 return (u16)lid;
7db20ecd
HD
4467}
4468
62ede777
HD
4469/**
4470 * ib_lid_be16 - Return lid in 16bit BE encoding.
4471 *
4472 * @lid: A 32bit LID
4473 */
4474static inline __be16 ib_lid_be16(u32 lid)
7db20ecd 4475{
62ede777
HD
4476 WARN_ON_ONCE(lid & 0xFFFF0000);
4477 return cpu_to_be16((u16)lid);
7db20ecd 4478}
32043830 4479
c66cd353
SG
4480/**
4481 * ib_get_vector_affinity - Get the affinity mappings of a given completion
4482 * vector
4483 * @device: the rdma device
4484 * @comp_vector: index of completion vector
4485 *
4486 * Returns NULL on failure, otherwise a corresponding cpu map of the
4487 * completion vector (returns all-cpus map if the device driver doesn't
4488 * implement get_vector_affinity).
4489 */
4490static inline const struct cpumask *
4491ib_get_vector_affinity(struct ib_device *device, int comp_vector)
4492{
4493 if (comp_vector < 0 || comp_vector >= device->num_comp_vectors ||
3023a1e9 4494 !device->ops.get_vector_affinity)
c66cd353
SG
4495 return NULL;
4496
3023a1e9 4497 return device->ops.get_vector_affinity(device, comp_vector);
c66cd353
SG
4498
4499}
4500
32f69e4b
DJ
4501/**
4502 * rdma_roce_rescan_device - Rescan all of the network devices in the system
4503 * and add their gids, as needed, to the relevant RoCE devices.
4504 *
4505 * @device: the rdma device
4506 */
4507void rdma_roce_rescan_device(struct ib_device *ibdev);
4508
8313c10f 4509struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
7dc08dcf 4510
15a1b4be 4511int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs);
f6a8a19b
DD
4512
4513struct net_device *rdma_alloc_netdev(struct ib_device *device, u8 port_num,
4514 enum rdma_netdev_t type, const char *name,
4515 unsigned char name_assign_type,
4516 void (*setup)(struct net_device *));
5d6b0cb3
DD
4517
4518int rdma_init_netdev(struct ib_device *device, u8 port_num,
4519 enum rdma_netdev_t type, const char *name,
4520 unsigned char name_assign_type,
4521 void (*setup)(struct net_device *),
4522 struct net_device *netdev);
4523
d4122f5a
PP
4524/**
4525 * rdma_set_device_sysfs_group - Set device attributes group to have
4526 * driver specific sysfs entries at
4527 * for infiniband class.
4528 *
4529 * @device: device pointer for which attributes to be created
4530 * @group: Pointer to group which should be added when device
4531 * is registered with sysfs.
4532 * rdma_set_device_sysfs_group() allows existing drivers to expose one
4533 * group per device to have sysfs attributes.
4534 *
4535 * NOTE: New drivers should not make use of this API; instead new device
4536 * parameter should be exposed via netlink command. This API and mechanism
4537 * exist only for existing drivers.
4538 */
4539static inline void
4540rdma_set_device_sysfs_group(struct ib_device *dev,
4541 const struct attribute_group *group)
4542{
4543 dev->groups[1] = group;
4544}
4545
54747231
PP
4546/**
4547 * rdma_device_to_ibdev - Get ib_device pointer from device pointer
4548 *
4549 * @device: device pointer for which ib_device pointer to retrieve
4550 *
4551 * rdma_device_to_ibdev() retrieves ib_device pointer from device.
4552 *
4553 */
4554static inline struct ib_device *rdma_device_to_ibdev(struct device *device)
4555{
cebe556b
PP
4556 struct ib_core_device *coredev =
4557 container_of(device, struct ib_core_device, dev);
4558
4559 return coredev->owner;
54747231
PP
4560}
4561
4562/**
4563 * rdma_device_to_drv_device - Helper macro to reach back to driver's
4564 * ib_device holder structure from device pointer.
4565 *
4566 * NOTE: New drivers should not make use of this API; This API is only for
4567 * existing drivers who have exposed sysfs entries using
4568 * rdma_set_device_sysfs_group().
4569 */
4570#define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member) \
4571 container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member)
41c61401
PP
4572
4573bool rdma_dev_access_netns(const struct ib_device *device,
4574 const struct net *net);
1da177e4 4575#endif /* IB_VERBS_H */