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