blob: 73d1b1000785b26056396d8c8d70eb4889cab64b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
4 * Copyright (c) 2004 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
Roland Dreier2a1d9b72005-08-10 23:03:10 -07007 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08008 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * This software is available to you under a choice of one of two
11 * licenses. You may choose to be licensed under the terms of the GNU
12 * General Public License (GPL) Version 2, available from the file
13 * COPYING in the main directory of this source tree, or the
14 * OpenIB.org BSD license below:
15 *
16 * Redistribution and use in source and binary forms, with or
17 * without modification, are permitted provided that the following
18 * conditions are met:
19 *
20 * - Redistributions of source code must retain the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer.
23 *
24 * - Redistributions in binary form must reproduce the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer in the documentation and/or other materials
27 * provided with the distribution.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 * SOFTWARE.
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 */
38
39#if !defined(IB_VERBS_H)
40#define IB_VERBS_H
41
42#include <linux/types.h>
43#include <linux/device.h>
Ralph Campbell9b513092006-12-12 14:27:41 -080044#include <linux/mm.h>
45#include <linux/dma-mapping.h>
Michael S. Tsirkin459d6e22007-02-04 14:11:55 -080046#include <linux/kref.h>
Dotan Barakbfb3ea12007-07-31 16:49:15 +030047#include <linux/list.h>
48#include <linux/rwsem.h>
Adrian Bunk87ae9af2007-10-30 10:35:04 +010049#include <linux/scatterlist.h>
Tejun Heof0626712010-10-19 15:24:36 +000050#include <linux/workqueue.h>
Matan Barakdd5f03b2013-12-12 18:03:11 +020051#include <uapi/linux/if_ether.h>
Roland Dreiere2773c02005-07-07 17:57:10 -070052
Arun Sharma600634972011-07-26 16:09:06 -070053#include <linux/atomic.h>
Haggai Eran882214e2014-12-11 17:04:18 +020054#include <linux/mmu_notifier.h>
Roland Dreiere2773c02005-07-07 17:57:10 -070055#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Tejun Heof0626712010-10-19 15:24:36 +000057extern struct workqueue_struct *ib_wq;
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059union ib_gid {
60 u8 raw[16];
61 struct {
Sean Hefty97f52eb2005-08-13 21:05:57 -070062 __be64 subnet_prefix;
63 __be64 interface_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 } global;
65};
66
Tom Tucker07ebafb2006-08-03 16:02:42 -050067enum rdma_node_type {
68 /* IB values map to NodeInfo:NodeType. */
69 RDMA_NODE_IB_CA = 1,
70 RDMA_NODE_IB_SWITCH,
71 RDMA_NODE_IB_ROUTER,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000072 RDMA_NODE_RNIC,
73 RDMA_NODE_USNIC,
Upinder Malhi5db57652014-01-15 17:02:36 -080074 RDMA_NODE_USNIC_UDP,
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Tom Tucker07ebafb2006-08-03 16:02:42 -050077enum rdma_transport_type {
78 RDMA_TRANSPORT_IB,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000079 RDMA_TRANSPORT_IWARP,
Upinder Malhi248567f2014-01-09 14:48:19 -080080 RDMA_TRANSPORT_USNIC,
81 RDMA_TRANSPORT_USNIC_UDP
Tom Tucker07ebafb2006-08-03 16:02:42 -050082};
83
Michael Wang6b90a6d2015-05-05 14:50:18 +020084enum rdma_protocol_type {
85 RDMA_PROTOCOL_IB,
86 RDMA_PROTOCOL_IBOE,
87 RDMA_PROTOCOL_IWARP,
88 RDMA_PROTOCOL_USNIC_UDP
89};
90
Roland Dreier8385fd82014-06-04 10:00:16 -070091__attribute_const__ enum rdma_transport_type
92rdma_node_get_transport(enum rdma_node_type node_type);
Tom Tucker07ebafb2006-08-03 16:02:42 -050093
Eli Cohena3f5ada2010-09-27 17:51:10 -070094enum rdma_link_layer {
95 IB_LINK_LAYER_UNSPECIFIED,
96 IB_LINK_LAYER_INFINIBAND,
97 IB_LINK_LAYER_ETHERNET,
98};
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100enum ib_device_cap_flags {
101 IB_DEVICE_RESIZE_MAX_WR = 1,
102 IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
103 IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
104 IB_DEVICE_RAW_MULTI = (1<<3),
105 IB_DEVICE_AUTO_PATH_MIG = (1<<4),
106 IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
107 IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
108 IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
109 IB_DEVICE_SHUTDOWN_PORT = (1<<8),
110 IB_DEVICE_INIT_TYPE = (1<<9),
111 IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
112 IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
113 IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
114 IB_DEVICE_SRQ_RESIZE = (1<<13),
115 IB_DEVICE_N_NOTIFY_CQ = (1<<14),
Steve Wise96f15c02008-07-14 23:48:53 -0700116 IB_DEVICE_LOCAL_DMA_LKEY = (1<<15),
Roland Dreier0f39cf32008-04-16 21:09:32 -0700117 IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
Eli Cohene0605d92008-01-30 18:30:57 +0200118 IB_DEVICE_MEM_WINDOW = (1<<17),
119 /*
120 * Devices should set IB_DEVICE_UD_IP_SUM if they support
121 * insertion of UDP and TCP checksum on outgoing UD IPoIB
122 * messages and can verify the validity of checksum for
123 * incoming messages. Setting this flag implies that the
124 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
125 */
126 IB_DEVICE_UD_IP_CSUM = (1<<18),
Eli Cohenc93570f2008-04-16 21:09:27 -0700127 IB_DEVICE_UD_TSO = (1<<19),
Sean Hefty59991f92011-05-23 17:52:46 -0700128 IB_DEVICE_XRC = (1<<20),
Steve Wise00f7ec32008-07-14 23:48:45 -0700129 IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21),
Ron Livne47ee1b92008-07-14 23:48:48 -0700130 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
Shani Michaeli7083e422013-02-06 16:19:12 +0000131 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1<<23),
Hadar Hen Zion319a4412013-08-07 14:01:59 +0300132 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1<<24),
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200133 IB_DEVICE_MANAGED_FLOW_STEERING = (1<<29),
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200134 IB_DEVICE_SIGNATURE_HANDOVER = (1<<30),
135 IB_DEVICE_ON_DEMAND_PAGING = (1<<31),
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200136};
137
138enum ib_signature_prot_cap {
139 IB_PROT_T10DIF_TYPE_1 = 1,
140 IB_PROT_T10DIF_TYPE_2 = 1 << 1,
141 IB_PROT_T10DIF_TYPE_3 = 1 << 2,
142};
143
144enum ib_signature_guard_cap {
145 IB_GUARD_T10DIF_CRC = 1,
146 IB_GUARD_T10DIF_CSUM = 1 << 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149enum ib_atomic_cap {
150 IB_ATOMIC_NONE,
151 IB_ATOMIC_HCA,
152 IB_ATOMIC_GLOB
153};
154
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200155enum ib_odp_general_cap_bits {
156 IB_ODP_SUPPORT = 1 << 0,
157};
158
159enum ib_odp_transport_cap_bits {
160 IB_ODP_SUPPORT_SEND = 1 << 0,
161 IB_ODP_SUPPORT_RECV = 1 << 1,
162 IB_ODP_SUPPORT_WRITE = 1 << 2,
163 IB_ODP_SUPPORT_READ = 1 << 3,
164 IB_ODP_SUPPORT_ATOMIC = 1 << 4,
165};
166
167struct ib_odp_caps {
168 uint64_t general_caps;
169 struct {
170 uint32_t rc_odp_caps;
171 uint32_t uc_odp_caps;
172 uint32_t ud_odp_caps;
173 } per_transport_caps;
174};
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176struct ib_device_attr {
177 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700178 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 u64 max_mr_size;
180 u64 page_size_cap;
181 u32 vendor_id;
182 u32 vendor_part_id;
183 u32 hw_ver;
184 int max_qp;
185 int max_qp_wr;
186 int device_cap_flags;
187 int max_sge;
188 int max_sge_rd;
189 int max_cq;
190 int max_cqe;
191 int max_mr;
192 int max_pd;
193 int max_qp_rd_atom;
194 int max_ee_rd_atom;
195 int max_res_rd_atom;
196 int max_qp_init_rd_atom;
197 int max_ee_init_rd_atom;
198 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300199 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 int max_ee;
201 int max_rdd;
202 int max_mw;
203 int max_raw_ipv6_qp;
204 int max_raw_ethy_qp;
205 int max_mcast_grp;
206 int max_mcast_qp_attach;
207 int max_total_mcast_qp_attach;
208 int max_ah;
209 int max_fmr;
210 int max_map_per_fmr;
211 int max_srq;
212 int max_srq_wr;
213 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700214 unsigned int max_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 u16 max_pkeys;
216 u8 local_ca_ack_delay;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200217 int sig_prot_cap;
218 int sig_guard_cap;
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200219 struct ib_odp_caps odp_caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220};
221
222enum ib_mtu {
223 IB_MTU_256 = 1,
224 IB_MTU_512 = 2,
225 IB_MTU_1024 = 3,
226 IB_MTU_2048 = 4,
227 IB_MTU_4096 = 5
228};
229
230static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
231{
232 switch (mtu) {
233 case IB_MTU_256: return 256;
234 case IB_MTU_512: return 512;
235 case IB_MTU_1024: return 1024;
236 case IB_MTU_2048: return 2048;
237 case IB_MTU_4096: return 4096;
238 default: return -1;
239 }
240}
241
242enum ib_port_state {
243 IB_PORT_NOP = 0,
244 IB_PORT_DOWN = 1,
245 IB_PORT_INIT = 2,
246 IB_PORT_ARMED = 3,
247 IB_PORT_ACTIVE = 4,
248 IB_PORT_ACTIVE_DEFER = 5
249};
250
251enum ib_port_cap_flags {
252 IB_PORT_SM = 1 << 1,
253 IB_PORT_NOTICE_SUP = 1 << 2,
254 IB_PORT_TRAP_SUP = 1 << 3,
255 IB_PORT_OPT_IPD_SUP = 1 << 4,
256 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
257 IB_PORT_SL_MAP_SUP = 1 << 6,
258 IB_PORT_MKEY_NVRAM = 1 << 7,
259 IB_PORT_PKEY_NVRAM = 1 << 8,
260 IB_PORT_LED_INFO_SUP = 1 << 9,
261 IB_PORT_SM_DISABLED = 1 << 10,
262 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
263 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300264 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 IB_PORT_CM_SUP = 1 << 16,
266 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
267 IB_PORT_REINIT_SUP = 1 << 18,
268 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
269 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
270 IB_PORT_DR_NOTICE_SUP = 1 << 21,
271 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
272 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
273 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
Moni Shouab4a26a22014-02-09 11:54:34 +0200274 IB_PORT_CLIENT_REG_SUP = 1 << 25,
275 IB_PORT_IP_BASED_GIDS = 1 << 26
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
278enum ib_port_width {
279 IB_WIDTH_1X = 1,
280 IB_WIDTH_4X = 2,
281 IB_WIDTH_8X = 4,
282 IB_WIDTH_12X = 8
283};
284
285static inline int ib_width_enum_to_int(enum ib_port_width width)
286{
287 switch (width) {
288 case IB_WIDTH_1X: return 1;
289 case IB_WIDTH_4X: return 4;
290 case IB_WIDTH_8X: return 8;
291 case IB_WIDTH_12X: return 12;
292 default: return -1;
293 }
294}
295
Or Gerlitz2e966912012-02-28 18:49:50 +0200296enum ib_port_speed {
297 IB_SPEED_SDR = 1,
298 IB_SPEED_DDR = 2,
299 IB_SPEED_QDR = 4,
300 IB_SPEED_FDR10 = 8,
301 IB_SPEED_FDR = 16,
302 IB_SPEED_EDR = 32
303};
304
Steve Wise7f624d02008-07-14 23:48:48 -0700305struct ib_protocol_stats {
306 /* TBD... */
307};
308
309struct iw_protocol_stats {
310 u64 ipInReceives;
311 u64 ipInHdrErrors;
312 u64 ipInTooBigErrors;
313 u64 ipInNoRoutes;
314 u64 ipInAddrErrors;
315 u64 ipInUnknownProtos;
316 u64 ipInTruncatedPkts;
317 u64 ipInDiscards;
318 u64 ipInDelivers;
319 u64 ipOutForwDatagrams;
320 u64 ipOutRequests;
321 u64 ipOutDiscards;
322 u64 ipOutNoRoutes;
323 u64 ipReasmTimeout;
324 u64 ipReasmReqds;
325 u64 ipReasmOKs;
326 u64 ipReasmFails;
327 u64 ipFragOKs;
328 u64 ipFragFails;
329 u64 ipFragCreates;
330 u64 ipInMcastPkts;
331 u64 ipOutMcastPkts;
332 u64 ipInBcastPkts;
333 u64 ipOutBcastPkts;
334
335 u64 tcpRtoAlgorithm;
336 u64 tcpRtoMin;
337 u64 tcpRtoMax;
338 u64 tcpMaxConn;
339 u64 tcpActiveOpens;
340 u64 tcpPassiveOpens;
341 u64 tcpAttemptFails;
342 u64 tcpEstabResets;
343 u64 tcpCurrEstab;
344 u64 tcpInSegs;
345 u64 tcpOutSegs;
346 u64 tcpRetransSegs;
347 u64 tcpInErrs;
348 u64 tcpOutRsts;
349};
350
351union rdma_protocol_stats {
352 struct ib_protocol_stats ib;
353 struct iw_protocol_stats iw;
354};
355
Ira Weinyf9b22e32015-05-13 20:02:59 -0400356/* Define bits for the various functionality this port needs to be supported by
357 * the core.
358 */
359/* Management 0x00000FFF */
360#define RDMA_CORE_CAP_IB_MAD 0x00000001
361#define RDMA_CORE_CAP_IB_SMI 0x00000002
362#define RDMA_CORE_CAP_IB_CM 0x00000004
363#define RDMA_CORE_CAP_IW_CM 0x00000008
364#define RDMA_CORE_CAP_IB_SA 0x00000010
365
366/* Address format 0x000FF000 */
367#define RDMA_CORE_CAP_AF_IB 0x00001000
368#define RDMA_CORE_CAP_ETH_AH 0x00002000
369
370/* Protocol 0xFFF00000 */
371#define RDMA_CORE_CAP_PROT_IB 0x00100000
372#define RDMA_CORE_CAP_PROT_ROCE 0x00200000
373#define RDMA_CORE_CAP_PROT_IWARP 0x00400000
374
375#define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \
376 | RDMA_CORE_CAP_IB_MAD \
377 | RDMA_CORE_CAP_IB_SMI \
378 | RDMA_CORE_CAP_IB_CM \
379 | RDMA_CORE_CAP_IB_SA \
380 | RDMA_CORE_CAP_AF_IB)
381#define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \
382 | RDMA_CORE_CAP_IB_MAD \
383 | RDMA_CORE_CAP_IB_CM \
384 | RDMA_CORE_CAP_IB_SA \
385 | RDMA_CORE_CAP_AF_IB \
386 | RDMA_CORE_CAP_ETH_AH)
387#define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \
388 | RDMA_CORE_CAP_IW_CM)
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390struct ib_port_attr {
391 enum ib_port_state state;
392 enum ib_mtu max_mtu;
393 enum ib_mtu active_mtu;
394 int gid_tbl_len;
395 u32 port_cap_flags;
396 u32 max_msg_sz;
397 u32 bad_pkey_cntr;
398 u32 qkey_viol_cntr;
399 u16 pkey_tbl_len;
400 u16 lid;
401 u16 sm_lid;
402 u8 lmc;
403 u8 max_vl_num;
404 u8 sm_sl;
405 u8 subnet_timeout;
406 u8 init_type_reply;
407 u8 active_width;
408 u8 active_speed;
409 u8 phys_state;
410};
411
412enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800413 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
414 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415};
416
417struct ib_device_modify {
418 u64 sys_image_guid;
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800419 char node_desc[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420};
421
422enum ib_port_modify_flags {
423 IB_PORT_SHUTDOWN = 1,
424 IB_PORT_INIT_TYPE = (1<<2),
425 IB_PORT_RESET_QKEY_CNTR = (1<<3)
426};
427
428struct ib_port_modify {
429 u32 set_port_cap_mask;
430 u32 clr_port_cap_mask;
431 u8 init_type;
432};
433
434enum ib_event_type {
435 IB_EVENT_CQ_ERR,
436 IB_EVENT_QP_FATAL,
437 IB_EVENT_QP_REQ_ERR,
438 IB_EVENT_QP_ACCESS_ERR,
439 IB_EVENT_COMM_EST,
440 IB_EVENT_SQ_DRAINED,
441 IB_EVENT_PATH_MIG,
442 IB_EVENT_PATH_MIG_ERR,
443 IB_EVENT_DEVICE_FATAL,
444 IB_EVENT_PORT_ACTIVE,
445 IB_EVENT_PORT_ERR,
446 IB_EVENT_LID_CHANGE,
447 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700448 IB_EVENT_SM_CHANGE,
449 IB_EVENT_SRQ_ERR,
450 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700451 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000452 IB_EVENT_CLIENT_REREGISTER,
453 IB_EVENT_GID_CHANGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454};
455
456struct ib_event {
457 struct ib_device *device;
458 union {
459 struct ib_cq *cq;
460 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700461 struct ib_srq *srq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 u8 port_num;
463 } element;
464 enum ib_event_type event;
465};
466
467struct ib_event_handler {
468 struct ib_device *device;
469 void (*handler)(struct ib_event_handler *, struct ib_event *);
470 struct list_head list;
471};
472
473#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
474 do { \
475 (_ptr)->device = _device; \
476 (_ptr)->handler = _handler; \
477 INIT_LIST_HEAD(&(_ptr)->list); \
478 } while (0)
479
480struct ib_global_route {
481 union ib_gid dgid;
482 u32 flow_label;
483 u8 sgid_index;
484 u8 hop_limit;
485 u8 traffic_class;
486};
487
Hal Rosenstock513789e2005-07-27 11:45:34 -0700488struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700489 __be32 version_tclass_flow;
490 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700491 u8 next_hdr;
492 u8 hop_limit;
493 union ib_gid sgid;
494 union ib_gid dgid;
495};
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497enum {
498 IB_MULTICAST_QPN = 0xffffff
499};
500
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800501#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503enum ib_ah_flags {
504 IB_AH_GRH = 1
505};
506
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700507enum ib_rate {
508 IB_RATE_PORT_CURRENT = 0,
509 IB_RATE_2_5_GBPS = 2,
510 IB_RATE_5_GBPS = 5,
511 IB_RATE_10_GBPS = 3,
512 IB_RATE_20_GBPS = 6,
513 IB_RATE_30_GBPS = 4,
514 IB_RATE_40_GBPS = 7,
515 IB_RATE_60_GBPS = 8,
516 IB_RATE_80_GBPS = 9,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300517 IB_RATE_120_GBPS = 10,
518 IB_RATE_14_GBPS = 11,
519 IB_RATE_56_GBPS = 12,
520 IB_RATE_112_GBPS = 13,
521 IB_RATE_168_GBPS = 14,
522 IB_RATE_25_GBPS = 15,
523 IB_RATE_100_GBPS = 16,
524 IB_RATE_200_GBPS = 17,
525 IB_RATE_300_GBPS = 18
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700526};
527
528/**
529 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
530 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
531 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
532 * @rate: rate to convert.
533 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700534__attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700535
536/**
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300537 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
538 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
539 * @rate: rate to convert.
540 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700541__attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300542
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200543enum ib_mr_create_flags {
544 IB_MR_SIGNATURE_EN = 1,
545};
546
547/**
548 * ib_mr_init_attr - Memory region init attributes passed to routine
549 * ib_create_mr.
550 * @max_reg_descriptors: max number of registration descriptors that
551 * may be used with registration work requests.
552 * @flags: MR creation flags bit mask.
553 */
554struct ib_mr_init_attr {
555 int max_reg_descriptors;
556 u32 flags;
557};
558
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200559/**
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300560 * Signature types
561 * IB_SIG_TYPE_NONE: Unprotected.
562 * IB_SIG_TYPE_T10_DIF: Type T10-DIF
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200563 */
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300564enum ib_signature_type {
565 IB_SIG_TYPE_NONE,
566 IB_SIG_TYPE_T10_DIF,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200567};
568
569/**
570 * Signature T10-DIF block-guard types
571 * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
572 * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
573 */
574enum ib_t10_dif_bg_type {
575 IB_T10DIF_CRC,
576 IB_T10DIF_CSUM
577};
578
579/**
580 * struct ib_t10_dif_domain - Parameters specific for T10-DIF
581 * domain.
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200582 * @bg_type: T10-DIF block guard type (CRC|CSUM)
583 * @pi_interval: protection information interval.
584 * @bg: seed of guard computation.
585 * @app_tag: application tag of guard block
586 * @ref_tag: initial guard block reference tag.
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300587 * @ref_remap: Indicate wethear the reftag increments each block
588 * @app_escape: Indicate to skip block check if apptag=0xffff
589 * @ref_escape: Indicate to skip block check if reftag=0xffffffff
590 * @apptag_check_mask: check bitmask of application tag.
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200591 */
592struct ib_t10_dif_domain {
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200593 enum ib_t10_dif_bg_type bg_type;
594 u16 pi_interval;
595 u16 bg;
596 u16 app_tag;
597 u32 ref_tag;
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300598 bool ref_remap;
599 bool app_escape;
600 bool ref_escape;
601 u16 apptag_check_mask;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200602};
603
604/**
605 * struct ib_sig_domain - Parameters for signature domain
606 * @sig_type: specific signauture type
607 * @sig: union of all signature domain attributes that may
608 * be used to set domain layout.
609 */
610struct ib_sig_domain {
611 enum ib_signature_type sig_type;
612 union {
613 struct ib_t10_dif_domain dif;
614 } sig;
615};
616
617/**
618 * struct ib_sig_attrs - Parameters for signature handover operation
619 * @check_mask: bitmask for signature byte check (8 bytes)
620 * @mem: memory domain layout desciptor.
621 * @wire: wire domain layout desciptor.
622 */
623struct ib_sig_attrs {
624 u8 check_mask;
625 struct ib_sig_domain mem;
626 struct ib_sig_domain wire;
627};
628
629enum ib_sig_err_type {
630 IB_SIG_BAD_GUARD,
631 IB_SIG_BAD_REFTAG,
632 IB_SIG_BAD_APPTAG,
633};
634
635/**
636 * struct ib_sig_err - signature error descriptor
637 */
638struct ib_sig_err {
639 enum ib_sig_err_type err_type;
640 u32 expected;
641 u32 actual;
642 u64 sig_err_offset;
643 u32 key;
644};
645
646enum ib_mr_status_check {
647 IB_MR_CHECK_SIG_STATUS = 1,
648};
649
650/**
651 * struct ib_mr_status - Memory region status container
652 *
653 * @fail_status: Bitmask of MR checks status. For each
654 * failed check a corresponding status bit is set.
655 * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
656 * failure.
657 */
658struct ib_mr_status {
659 u32 fail_status;
660 struct ib_sig_err sig_err;
661};
662
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300663/**
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700664 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
665 * enum.
666 * @mult: multiple to convert.
667 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700668__attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670struct ib_ah_attr {
671 struct ib_global_route grh;
672 u16 dlid;
673 u8 sl;
674 u8 src_path_bits;
675 u8 static_rate;
676 u8 ah_flags;
677 u8 port_num;
Matan Barakdd5f03b2013-12-12 18:03:11 +0200678 u8 dmac[ETH_ALEN];
679 u16 vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680};
681
682enum ib_wc_status {
683 IB_WC_SUCCESS,
684 IB_WC_LOC_LEN_ERR,
685 IB_WC_LOC_QP_OP_ERR,
686 IB_WC_LOC_EEC_OP_ERR,
687 IB_WC_LOC_PROT_ERR,
688 IB_WC_WR_FLUSH_ERR,
689 IB_WC_MW_BIND_ERR,
690 IB_WC_BAD_RESP_ERR,
691 IB_WC_LOC_ACCESS_ERR,
692 IB_WC_REM_INV_REQ_ERR,
693 IB_WC_REM_ACCESS_ERR,
694 IB_WC_REM_OP_ERR,
695 IB_WC_RETRY_EXC_ERR,
696 IB_WC_RNR_RETRY_EXC_ERR,
697 IB_WC_LOC_RDD_VIOL_ERR,
698 IB_WC_REM_INV_RD_REQ_ERR,
699 IB_WC_REM_ABORT_ERR,
700 IB_WC_INV_EECN_ERR,
701 IB_WC_INV_EEC_STATE_ERR,
702 IB_WC_FATAL_ERR,
703 IB_WC_RESP_TIMEOUT_ERR,
704 IB_WC_GENERAL_ERR
705};
706
707enum ib_wc_opcode {
708 IB_WC_SEND,
709 IB_WC_RDMA_WRITE,
710 IB_WC_RDMA_READ,
711 IB_WC_COMP_SWAP,
712 IB_WC_FETCH_ADD,
713 IB_WC_BIND_MW,
Eli Cohenc93570f2008-04-16 21:09:27 -0700714 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700715 IB_WC_LOCAL_INV,
716 IB_WC_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300717 IB_WC_MASKED_COMP_SWAP,
718 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719/*
720 * Set value of IB_WC_RECV so consumers can test if a completion is a
721 * receive by testing (opcode & IB_WC_RECV).
722 */
723 IB_WC_RECV = 1 << 7,
724 IB_WC_RECV_RDMA_WITH_IMM
725};
726
727enum ib_wc_flags {
728 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -0700729 IB_WC_WITH_IMM = (1<<1),
730 IB_WC_WITH_INVALIDATE = (1<<2),
Or Gerlitzd927d502012-01-11 19:03:51 +0200731 IB_WC_IP_CSUM_OK = (1<<3),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200732 IB_WC_WITH_SMAC = (1<<4),
733 IB_WC_WITH_VLAN = (1<<5),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734};
735
736struct ib_wc {
737 u64 wr_id;
738 enum ib_wc_status status;
739 enum ib_wc_opcode opcode;
740 u32 vendor_err;
741 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +0200742 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -0700743 union {
744 __be32 imm_data;
745 u32 invalidate_rkey;
746 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 u32 src_qp;
748 int wc_flags;
749 u16 pkey_index;
750 u16 slid;
751 u8 sl;
752 u8 dlid_path_bits;
753 u8 port_num; /* valid only for DR SMPs on switches */
Matan Barakdd5f03b2013-12-12 18:03:11 +0200754 u8 smac[ETH_ALEN];
755 u16 vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756};
757
Roland Dreiered23a722007-05-06 21:02:48 -0700758enum ib_cq_notify_flags {
759 IB_CQ_SOLICITED = 1 << 0,
760 IB_CQ_NEXT_COMP = 1 << 1,
761 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
762 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763};
764
Sean Hefty96104ed2011-05-23 16:31:36 -0700765enum ib_srq_type {
Sean Hefty418d5132011-05-23 19:42:29 -0700766 IB_SRQT_BASIC,
767 IB_SRQT_XRC
Sean Hefty96104ed2011-05-23 16:31:36 -0700768};
769
Roland Dreierd41fcc62005-08-18 12:23:08 -0700770enum ib_srq_attr_mask {
771 IB_SRQ_MAX_WR = 1 << 0,
772 IB_SRQ_LIMIT = 1 << 1,
773};
774
775struct ib_srq_attr {
776 u32 max_wr;
777 u32 max_sge;
778 u32 srq_limit;
779};
780
781struct ib_srq_init_attr {
782 void (*event_handler)(struct ib_event *, void *);
783 void *srq_context;
784 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -0700785 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -0700786
787 union {
788 struct {
789 struct ib_xrcd *xrcd;
790 struct ib_cq *cq;
791 } xrc;
792 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700793};
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795struct ib_qp_cap {
796 u32 max_send_wr;
797 u32 max_recv_wr;
798 u32 max_send_sge;
799 u32 max_recv_sge;
800 u32 max_inline_data;
801};
802
803enum ib_sig_type {
804 IB_SIGNAL_ALL_WR,
805 IB_SIGNAL_REQ_WR
806};
807
808enum ib_qp_type {
809 /*
810 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
811 * here (and in that order) since the MAD layer uses them as
812 * indices into a 2-entry table.
813 */
814 IB_QPT_SMI,
815 IB_QPT_GSI,
816
817 IB_QPT_RC,
818 IB_QPT_UC,
819 IB_QPT_UD,
820 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700821 IB_QPT_RAW_ETHERTYPE,
Or Gerlitzc938a612012-03-01 12:17:51 +0200822 IB_QPT_RAW_PACKET = 8,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700823 IB_QPT_XRC_INI = 9,
824 IB_QPT_XRC_TGT,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300825 IB_QPT_MAX,
826 /* Reserve a range for qp types internal to the low level driver.
827 * These qp types will not be visible at the IB core layer, so the
828 * IB_QPT_MAX usages should not be affected in the core layer
829 */
830 IB_QPT_RESERVED1 = 0x1000,
831 IB_QPT_RESERVED2,
832 IB_QPT_RESERVED3,
833 IB_QPT_RESERVED4,
834 IB_QPT_RESERVED5,
835 IB_QPT_RESERVED6,
836 IB_QPT_RESERVED7,
837 IB_QPT_RESERVED8,
838 IB_QPT_RESERVED9,
839 IB_QPT_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840};
841
Eli Cohenb846f252008-04-16 21:09:27 -0700842enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -0700843 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
844 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
Matan Barak90f1d1b2013-11-07 15:25:12 +0200845 IB_QP_CREATE_NETIF_QP = 1 << 5,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200846 IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
Or Gerlitz09b93082014-05-11 15:15:11 +0300847 IB_QP_CREATE_USE_GFP_NOIO = 1 << 7,
Jack Morgensteind2b57062012-08-03 08:40:37 +0000848 /* reserve bits 26-31 for low level drivers' internal use */
849 IB_QP_CREATE_RESERVED_START = 1 << 26,
850 IB_QP_CREATE_RESERVED_END = 1 << 31,
Eli Cohenb846f252008-04-16 21:09:27 -0700851};
852
Yishai Hadas73c40c62013-08-01 18:49:53 +0300853
854/*
855 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
856 * callback to destroy the passed in QP.
857 */
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859struct ib_qp_init_attr {
860 void (*event_handler)(struct ib_event *, void *);
861 void *qp_context;
862 struct ib_cq *send_cq;
863 struct ib_cq *recv_cq;
864 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700865 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 struct ib_qp_cap cap;
867 enum ib_sig_type sq_sig_type;
868 enum ib_qp_type qp_type;
Eli Cohenb846f252008-04-16 21:09:27 -0700869 enum ib_qp_create_flags create_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 u8 port_num; /* special QP types only */
871};
872
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700873struct ib_qp_open_attr {
874 void (*event_handler)(struct ib_event *, void *);
875 void *qp_context;
876 u32 qp_num;
877 enum ib_qp_type qp_type;
878};
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880enum ib_rnr_timeout {
881 IB_RNR_TIMER_655_36 = 0,
882 IB_RNR_TIMER_000_01 = 1,
883 IB_RNR_TIMER_000_02 = 2,
884 IB_RNR_TIMER_000_03 = 3,
885 IB_RNR_TIMER_000_04 = 4,
886 IB_RNR_TIMER_000_06 = 5,
887 IB_RNR_TIMER_000_08 = 6,
888 IB_RNR_TIMER_000_12 = 7,
889 IB_RNR_TIMER_000_16 = 8,
890 IB_RNR_TIMER_000_24 = 9,
891 IB_RNR_TIMER_000_32 = 10,
892 IB_RNR_TIMER_000_48 = 11,
893 IB_RNR_TIMER_000_64 = 12,
894 IB_RNR_TIMER_000_96 = 13,
895 IB_RNR_TIMER_001_28 = 14,
896 IB_RNR_TIMER_001_92 = 15,
897 IB_RNR_TIMER_002_56 = 16,
898 IB_RNR_TIMER_003_84 = 17,
899 IB_RNR_TIMER_005_12 = 18,
900 IB_RNR_TIMER_007_68 = 19,
901 IB_RNR_TIMER_010_24 = 20,
902 IB_RNR_TIMER_015_36 = 21,
903 IB_RNR_TIMER_020_48 = 22,
904 IB_RNR_TIMER_030_72 = 23,
905 IB_RNR_TIMER_040_96 = 24,
906 IB_RNR_TIMER_061_44 = 25,
907 IB_RNR_TIMER_081_92 = 26,
908 IB_RNR_TIMER_122_88 = 27,
909 IB_RNR_TIMER_163_84 = 28,
910 IB_RNR_TIMER_245_76 = 29,
911 IB_RNR_TIMER_327_68 = 30,
912 IB_RNR_TIMER_491_52 = 31
913};
914
915enum ib_qp_attr_mask {
916 IB_QP_STATE = 1,
917 IB_QP_CUR_STATE = (1<<1),
918 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
919 IB_QP_ACCESS_FLAGS = (1<<3),
920 IB_QP_PKEY_INDEX = (1<<4),
921 IB_QP_PORT = (1<<5),
922 IB_QP_QKEY = (1<<6),
923 IB_QP_AV = (1<<7),
924 IB_QP_PATH_MTU = (1<<8),
925 IB_QP_TIMEOUT = (1<<9),
926 IB_QP_RETRY_CNT = (1<<10),
927 IB_QP_RNR_RETRY = (1<<11),
928 IB_QP_RQ_PSN = (1<<12),
929 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
930 IB_QP_ALT_PATH = (1<<14),
931 IB_QP_MIN_RNR_TIMER = (1<<15),
932 IB_QP_SQ_PSN = (1<<16),
933 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
934 IB_QP_PATH_MIG_STATE = (1<<18),
935 IB_QP_CAP = (1<<19),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200936 IB_QP_DEST_QPN = (1<<20),
937 IB_QP_SMAC = (1<<21),
938 IB_QP_ALT_SMAC = (1<<22),
939 IB_QP_VID = (1<<23),
940 IB_QP_ALT_VID = (1<<24),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941};
942
943enum ib_qp_state {
944 IB_QPS_RESET,
945 IB_QPS_INIT,
946 IB_QPS_RTR,
947 IB_QPS_RTS,
948 IB_QPS_SQD,
949 IB_QPS_SQE,
950 IB_QPS_ERR
951};
952
953enum ib_mig_state {
954 IB_MIG_MIGRATED,
955 IB_MIG_REARM,
956 IB_MIG_ARMED
957};
958
Shani Michaeli7083e422013-02-06 16:19:12 +0000959enum ib_mw_type {
960 IB_MW_TYPE_1 = 1,
961 IB_MW_TYPE_2 = 2
962};
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964struct ib_qp_attr {
965 enum ib_qp_state qp_state;
966 enum ib_qp_state cur_qp_state;
967 enum ib_mtu path_mtu;
968 enum ib_mig_state path_mig_state;
969 u32 qkey;
970 u32 rq_psn;
971 u32 sq_psn;
972 u32 dest_qp_num;
973 int qp_access_flags;
974 struct ib_qp_cap cap;
975 struct ib_ah_attr ah_attr;
976 struct ib_ah_attr alt_ah_attr;
977 u16 pkey_index;
978 u16 alt_pkey_index;
979 u8 en_sqd_async_notify;
980 u8 sq_draining;
981 u8 max_rd_atomic;
982 u8 max_dest_rd_atomic;
983 u8 min_rnr_timer;
984 u8 port_num;
985 u8 timeout;
986 u8 retry_cnt;
987 u8 rnr_retry;
988 u8 alt_port_num;
989 u8 alt_timeout;
Matan Barakdd5f03b2013-12-12 18:03:11 +0200990 u8 smac[ETH_ALEN];
991 u8 alt_smac[ETH_ALEN];
992 u16 vlan_id;
993 u16 alt_vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994};
995
996enum ib_wr_opcode {
997 IB_WR_RDMA_WRITE,
998 IB_WR_RDMA_WRITE_WITH_IMM,
999 IB_WR_SEND,
1000 IB_WR_SEND_WITH_IMM,
1001 IB_WR_RDMA_READ,
1002 IB_WR_ATOMIC_CMP_AND_SWP,
Eli Cohenc93570f2008-04-16 21:09:27 -07001003 IB_WR_ATOMIC_FETCH_AND_ADD,
Roland Dreier0f39cf32008-04-16 21:09:32 -07001004 IB_WR_LSO,
1005 IB_WR_SEND_WITH_INV,
Steve Wise00f7ec32008-07-14 23:48:45 -07001006 IB_WR_RDMA_READ_WITH_INV,
1007 IB_WR_LOCAL_INV,
1008 IB_WR_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +03001009 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
1010 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
Shani Michaeli7083e422013-02-06 16:19:12 +00001011 IB_WR_BIND_MW,
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001012 IB_WR_REG_SIG_MR,
Jack Morgenstein0134f162013-07-07 17:25:52 +03001013 /* reserve values for low level drivers' internal use.
1014 * These values will not be used at all in the ib core layer.
1015 */
1016 IB_WR_RESERVED1 = 0xf0,
1017 IB_WR_RESERVED2,
1018 IB_WR_RESERVED3,
1019 IB_WR_RESERVED4,
1020 IB_WR_RESERVED5,
1021 IB_WR_RESERVED6,
1022 IB_WR_RESERVED7,
1023 IB_WR_RESERVED8,
1024 IB_WR_RESERVED9,
1025 IB_WR_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026};
1027
1028enum ib_send_flags {
1029 IB_SEND_FENCE = 1,
1030 IB_SEND_SIGNALED = (1<<1),
1031 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +02001032 IB_SEND_INLINE = (1<<3),
Jack Morgenstein0134f162013-07-07 17:25:52 +03001033 IB_SEND_IP_CSUM = (1<<4),
1034
1035 /* reserve bits 26-31 for low level drivers' internal use */
1036 IB_SEND_RESERVED_START = (1 << 26),
1037 IB_SEND_RESERVED_END = (1 << 31),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038};
1039
1040struct ib_sge {
1041 u64 addr;
1042 u32 length;
1043 u32 lkey;
1044};
1045
Steve Wise00f7ec32008-07-14 23:48:45 -07001046struct ib_fast_reg_page_list {
1047 struct ib_device *device;
1048 u64 *page_list;
1049 unsigned int max_page_list_len;
1050};
1051
Shani Michaeli7083e422013-02-06 16:19:12 +00001052/**
1053 * struct ib_mw_bind_info - Parameters for a memory window bind operation.
1054 * @mr: A memory region to bind the memory window to.
1055 * @addr: The address where the memory window should begin.
1056 * @length: The length of the memory window, in bytes.
1057 * @mw_access_flags: Access flags from enum ib_access_flags for the window.
1058 *
1059 * This struct contains the shared parameters for type 1 and type 2
1060 * memory window bind operations.
1061 */
1062struct ib_mw_bind_info {
1063 struct ib_mr *mr;
1064 u64 addr;
1065 u64 length;
1066 int mw_access_flags;
1067};
1068
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069struct ib_send_wr {
1070 struct ib_send_wr *next;
1071 u64 wr_id;
1072 struct ib_sge *sg_list;
1073 int num_sge;
1074 enum ib_wr_opcode opcode;
1075 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -07001076 union {
1077 __be32 imm_data;
1078 u32 invalidate_rkey;
1079 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 union {
1081 struct {
1082 u64 remote_addr;
1083 u32 rkey;
1084 } rdma;
1085 struct {
1086 u64 remote_addr;
1087 u64 compare_add;
1088 u64 swap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +03001089 u64 compare_add_mask;
1090 u64 swap_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 u32 rkey;
1092 } atomic;
1093 struct {
1094 struct ib_ah *ah;
Eli Cohenc93570f2008-04-16 21:09:27 -07001095 void *header;
1096 int hlen;
1097 int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 u32 remote_qpn;
1099 u32 remote_qkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 u16 pkey_index; /* valid for GSI only */
1101 u8 port_num; /* valid for DR SMPs on switch only */
1102 } ud;
Steve Wise00f7ec32008-07-14 23:48:45 -07001103 struct {
1104 u64 iova_start;
1105 struct ib_fast_reg_page_list *page_list;
1106 unsigned int page_shift;
1107 unsigned int page_list_len;
1108 u32 length;
1109 int access_flags;
1110 u32 rkey;
1111 } fast_reg;
Shani Michaeli7083e422013-02-06 16:19:12 +00001112 struct {
1113 struct ib_mw *mw;
1114 /* The new rkey for the memory window. */
1115 u32 rkey;
1116 struct ib_mw_bind_info bind_info;
1117 } bind_mw;
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001118 struct {
1119 struct ib_sig_attrs *sig_attrs;
1120 struct ib_mr *sig_mr;
1121 int access_flags;
1122 struct ib_sge *prot;
1123 } sig_handover;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 } wr;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001125 u32 xrc_remote_srq_num; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126};
1127
1128struct ib_recv_wr {
1129 struct ib_recv_wr *next;
1130 u64 wr_id;
1131 struct ib_sge *sg_list;
1132 int num_sge;
1133};
1134
1135enum ib_access_flags {
1136 IB_ACCESS_LOCAL_WRITE = 1,
1137 IB_ACCESS_REMOTE_WRITE = (1<<1),
1138 IB_ACCESS_REMOTE_READ = (1<<2),
1139 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
Shani Michaeli7083e422013-02-06 16:19:12 +00001140 IB_ACCESS_MW_BIND = (1<<4),
Sagi Grimberg860f10a2014-12-11 17:04:16 +02001141 IB_ZERO_BASED = (1<<5),
1142 IB_ACCESS_ON_DEMAND = (1<<6),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143};
1144
1145struct ib_phys_buf {
1146 u64 addr;
1147 u64 size;
1148};
1149
1150struct ib_mr_attr {
1151 struct ib_pd *pd;
1152 u64 device_virt_addr;
1153 u64 size;
1154 int mr_access_flags;
1155 u32 lkey;
1156 u32 rkey;
1157};
1158
1159enum ib_mr_rereg_flags {
1160 IB_MR_REREG_TRANS = 1,
1161 IB_MR_REREG_PD = (1<<1),
Matan Barak7e6edb92014-07-31 11:01:28 +03001162 IB_MR_REREG_ACCESS = (1<<2),
1163 IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164};
1165
Shani Michaeli7083e422013-02-06 16:19:12 +00001166/**
1167 * struct ib_mw_bind - Parameters for a type 1 memory window bind operation.
1168 * @wr_id: Work request id.
1169 * @send_flags: Flags from ib_send_flags enum.
1170 * @bind_info: More parameters of the bind operation.
1171 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172struct ib_mw_bind {
Shani Michaeli7083e422013-02-06 16:19:12 +00001173 u64 wr_id;
1174 int send_flags;
1175 struct ib_mw_bind_info bind_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176};
1177
1178struct ib_fmr_attr {
1179 int max_pages;
1180 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -08001181 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182};
1183
Haggai Eran882214e2014-12-11 17:04:18 +02001184struct ib_umem;
1185
Roland Dreiere2773c02005-07-07 17:57:10 -07001186struct ib_ucontext {
1187 struct ib_device *device;
1188 struct list_head pd_list;
1189 struct list_head mr_list;
1190 struct list_head mw_list;
1191 struct list_head cq_list;
1192 struct list_head qp_list;
1193 struct list_head srq_list;
1194 struct list_head ah_list;
Sean Hefty53d0bd12011-05-24 08:33:46 -07001195 struct list_head xrcd_list;
Hadar Hen Zion436f2ad2013-08-14 13:58:30 +03001196 struct list_head rule_list;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001197 int closing;
Shachar Raindel8ada2c12014-12-11 17:04:17 +02001198
1199 struct pid *tgid;
Haggai Eran882214e2014-12-11 17:04:18 +02001200#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
1201 struct rb_root umem_tree;
1202 /*
1203 * Protects .umem_rbroot and tree, as well as odp_mrs_count and
1204 * mmu notifiers registration.
1205 */
1206 struct rw_semaphore umem_rwsem;
1207 void (*invalidate_range)(struct ib_umem *umem,
1208 unsigned long start, unsigned long end);
1209
1210 struct mmu_notifier mn;
1211 atomic_t notifier_count;
1212 /* A list of umems that don't have private mmu notifier counters yet. */
1213 struct list_head no_private_counters;
1214 int odp_mrs_count;
1215#endif
Roland Dreiere2773c02005-07-07 17:57:10 -07001216};
1217
1218struct ib_uobject {
1219 u64 user_handle; /* handle given to us by userspace */
1220 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -07001221 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -07001222 struct list_head list; /* link to context's list */
Roland Dreierb3d636b2008-04-16 21:01:06 -07001223 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -07001224 struct kref ref;
1225 struct rw_semaphore mutex; /* protects .live */
1226 int live;
Roland Dreiere2773c02005-07-07 17:57:10 -07001227};
1228
Roland Dreiere2773c02005-07-07 17:57:10 -07001229struct ib_udata {
Yann Droneaud309243e2013-12-11 23:01:44 +01001230 const void __user *inbuf;
Roland Dreiere2773c02005-07-07 17:57:10 -07001231 void __user *outbuf;
1232 size_t inlen;
1233 size_t outlen;
1234};
1235
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236struct ib_pd {
Roland Dreiere2773c02005-07-07 17:57:10 -07001237 struct ib_device *device;
1238 struct ib_uobject *uobject;
1239 atomic_t usecnt; /* count all resources */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240};
1241
Sean Hefty59991f92011-05-23 17:52:46 -07001242struct ib_xrcd {
1243 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001244 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -07001245 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001246
1247 struct mutex tgt_qp_mutex;
1248 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -07001249};
1250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251struct ib_ah {
1252 struct ib_device *device;
1253 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001254 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255};
1256
1257typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1258
1259struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -07001260 struct ib_device *device;
1261 struct ib_uobject *uobject;
1262 ib_comp_handler comp_handler;
1263 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -07001264 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -07001265 int cqe;
1266 atomic_t usecnt; /* count number of work queues */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267};
1268
1269struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -07001270 struct ib_device *device;
1271 struct ib_pd *pd;
1272 struct ib_uobject *uobject;
1273 void (*event_handler)(struct ib_event *, void *);
1274 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -07001275 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -07001277
1278 union {
1279 struct {
1280 struct ib_xrcd *xrcd;
1281 struct ib_cq *cq;
1282 u32 srq_num;
1283 } xrc;
1284 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285};
1286
1287struct ib_qp {
1288 struct ib_device *device;
1289 struct ib_pd *pd;
1290 struct ib_cq *send_cq;
1291 struct ib_cq *recv_cq;
1292 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001293 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -07001294 struct list_head xrcd_list;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001295 /* count times opened, mcast attaches, flow attaches */
1296 atomic_t usecnt;
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001297 struct list_head open_list;
1298 struct ib_qp *real_qp;
Roland Dreiere2773c02005-07-07 17:57:10 -07001299 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 void (*event_handler)(struct ib_event *, void *);
1301 void *qp_context;
1302 u32 qp_num;
1303 enum ib_qp_type qp_type;
1304};
1305
1306struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -07001307 struct ib_device *device;
1308 struct ib_pd *pd;
1309 struct ib_uobject *uobject;
1310 u32 lkey;
1311 u32 rkey;
1312 atomic_t usecnt; /* count number of MWs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313};
1314
1315struct ib_mw {
1316 struct ib_device *device;
1317 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001318 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 u32 rkey;
Shani Michaeli7083e422013-02-06 16:19:12 +00001320 enum ib_mw_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321};
1322
1323struct ib_fmr {
1324 struct ib_device *device;
1325 struct ib_pd *pd;
1326 struct list_head list;
1327 u32 lkey;
1328 u32 rkey;
1329};
1330
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001331/* Supported steering options */
1332enum ib_flow_attr_type {
1333 /* steering according to rule specifications */
1334 IB_FLOW_ATTR_NORMAL = 0x0,
1335 /* default unicast and multicast rule -
1336 * receive all Eth traffic which isn't steered to any QP
1337 */
1338 IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1339 /* default multicast rule -
1340 * receive all Eth multicast traffic which isn't steered to any QP
1341 */
1342 IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1343 /* sniffer rule - receive all port traffic */
1344 IB_FLOW_ATTR_SNIFFER = 0x3
1345};
1346
1347/* Supported steering header types */
1348enum ib_flow_spec_type {
1349 /* L2 headers*/
1350 IB_FLOW_SPEC_ETH = 0x20,
Matan Barak240ae002013-11-07 15:25:13 +02001351 IB_FLOW_SPEC_IB = 0x22,
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001352 /* L3 header*/
1353 IB_FLOW_SPEC_IPV4 = 0x30,
1354 /* L4 headers*/
1355 IB_FLOW_SPEC_TCP = 0x40,
1356 IB_FLOW_SPEC_UDP = 0x41
1357};
Matan Barak240ae002013-11-07 15:25:13 +02001358#define IB_FLOW_SPEC_LAYER_MASK 0xF0
Matan Barak22878db2013-09-01 18:39:52 +03001359#define IB_FLOW_SPEC_SUPPORT_LAYERS 4
1360
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001361/* Flow steering rule priority is set according to it's domain.
1362 * Lower domain value means higher priority.
1363 */
1364enum ib_flow_domain {
1365 IB_FLOW_DOMAIN_USER,
1366 IB_FLOW_DOMAIN_ETHTOOL,
1367 IB_FLOW_DOMAIN_RFS,
1368 IB_FLOW_DOMAIN_NIC,
1369 IB_FLOW_DOMAIN_NUM /* Must be last */
1370};
1371
1372struct ib_flow_eth_filter {
1373 u8 dst_mac[6];
1374 u8 src_mac[6];
1375 __be16 ether_type;
1376 __be16 vlan_tag;
1377};
1378
1379struct ib_flow_spec_eth {
1380 enum ib_flow_spec_type type;
1381 u16 size;
1382 struct ib_flow_eth_filter val;
1383 struct ib_flow_eth_filter mask;
1384};
1385
Matan Barak240ae002013-11-07 15:25:13 +02001386struct ib_flow_ib_filter {
1387 __be16 dlid;
1388 __u8 sl;
1389};
1390
1391struct ib_flow_spec_ib {
1392 enum ib_flow_spec_type type;
1393 u16 size;
1394 struct ib_flow_ib_filter val;
1395 struct ib_flow_ib_filter mask;
1396};
1397
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001398struct ib_flow_ipv4_filter {
1399 __be32 src_ip;
1400 __be32 dst_ip;
1401};
1402
1403struct ib_flow_spec_ipv4 {
1404 enum ib_flow_spec_type type;
1405 u16 size;
1406 struct ib_flow_ipv4_filter val;
1407 struct ib_flow_ipv4_filter mask;
1408};
1409
1410struct ib_flow_tcp_udp_filter {
1411 __be16 dst_port;
1412 __be16 src_port;
1413};
1414
1415struct ib_flow_spec_tcp_udp {
1416 enum ib_flow_spec_type type;
1417 u16 size;
1418 struct ib_flow_tcp_udp_filter val;
1419 struct ib_flow_tcp_udp_filter mask;
1420};
1421
1422union ib_flow_spec {
1423 struct {
1424 enum ib_flow_spec_type type;
1425 u16 size;
1426 };
1427 struct ib_flow_spec_eth eth;
Matan Barak240ae002013-11-07 15:25:13 +02001428 struct ib_flow_spec_ib ib;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001429 struct ib_flow_spec_ipv4 ipv4;
1430 struct ib_flow_spec_tcp_udp tcp_udp;
1431};
1432
1433struct ib_flow_attr {
1434 enum ib_flow_attr_type type;
1435 u16 size;
1436 u16 priority;
1437 u32 flags;
1438 u8 num_of_specs;
1439 u8 port;
1440 /* Following are the optional layers according to user request
1441 * struct ib_flow_spec_xxx
1442 * struct ib_flow_spec_yyy
1443 */
1444};
1445
1446struct ib_flow {
1447 struct ib_qp *qp;
1448 struct ib_uobject *uobject;
1449};
1450
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451struct ib_mad;
1452struct ib_grh;
1453
1454enum ib_process_mad_flags {
1455 IB_MAD_IGNORE_MKEY = 1,
1456 IB_MAD_IGNORE_BKEY = 2,
1457 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1458};
1459
1460enum ib_mad_result {
1461 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
1462 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
1463 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
1464 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
1465};
1466
1467#define IB_DEVICE_NAME_MAX 64
1468
1469struct ib_cache {
1470 rwlock_t lock;
1471 struct ib_event_handler event_handler;
1472 struct ib_pkey_cache **pkey_cache;
1473 struct ib_gid_cache **gid_cache;
Jack Morgenstein6fb9cdb2006-06-17 20:37:34 -07001474 u8 *lmc_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475};
1476
Ralph Campbell9b513092006-12-12 14:27:41 -08001477struct ib_dma_mapping_ops {
1478 int (*mapping_error)(struct ib_device *dev,
1479 u64 dma_addr);
1480 u64 (*map_single)(struct ib_device *dev,
1481 void *ptr, size_t size,
1482 enum dma_data_direction direction);
1483 void (*unmap_single)(struct ib_device *dev,
1484 u64 addr, size_t size,
1485 enum dma_data_direction direction);
1486 u64 (*map_page)(struct ib_device *dev,
1487 struct page *page, unsigned long offset,
1488 size_t size,
1489 enum dma_data_direction direction);
1490 void (*unmap_page)(struct ib_device *dev,
1491 u64 addr, size_t size,
1492 enum dma_data_direction direction);
1493 int (*map_sg)(struct ib_device *dev,
1494 struct scatterlist *sg, int nents,
1495 enum dma_data_direction direction);
1496 void (*unmap_sg)(struct ib_device *dev,
1497 struct scatterlist *sg, int nents,
1498 enum dma_data_direction direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001499 void (*sync_single_for_cpu)(struct ib_device *dev,
1500 u64 dma_handle,
1501 size_t size,
Dotan Barak4deccd62008-07-14 23:48:44 -07001502 enum dma_data_direction dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08001503 void (*sync_single_for_device)(struct ib_device *dev,
1504 u64 dma_handle,
1505 size_t size,
1506 enum dma_data_direction dir);
1507 void *(*alloc_coherent)(struct ib_device *dev,
1508 size_t size,
1509 u64 *dma_handle,
1510 gfp_t flag);
1511 void (*free_coherent)(struct ib_device *dev,
1512 size_t size, void *cpu_addr,
1513 u64 dma_handle);
1514};
1515
Tom Tucker07ebafb2006-08-03 16:02:42 -05001516struct iw_cm_verbs;
1517
Ira Weiny77386132015-05-13 20:02:58 -04001518struct ib_port_immutable {
1519 int pkey_tbl_len;
1520 int gid_tbl_len;
Ira Weinyf9b22e32015-05-13 20:02:59 -04001521 u32 core_cap_flags;
Ira Weiny77386132015-05-13 20:02:58 -04001522};
1523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524struct ib_device {
1525 struct device *dma_device;
1526
1527 char name[IB_DEVICE_NAME_MAX];
1528
1529 struct list_head event_handler_list;
1530 spinlock_t event_handler_lock;
1531
Alexander Chiang17a55f72010-02-02 19:09:16 +00001532 spinlock_t client_data_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 struct list_head core_list;
1534 struct list_head client_data_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 struct ib_cache cache;
Ira Weiny77386132015-05-13 20:02:58 -04001537 /**
1538 * port_immutable is indexed by port number
1539 */
1540 struct ib_port_immutable *port_immutable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001542 int num_comp_vectors;
1543
Tom Tucker07ebafb2006-08-03 16:02:42 -05001544 struct iw_cm_verbs *iwcm;
1545
Steve Wise7f624d02008-07-14 23:48:48 -07001546 int (*get_protocol_stats)(struct ib_device *device,
1547 union rdma_protocol_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 int (*query_device)(struct ib_device *device,
1549 struct ib_device_attr *device_attr);
1550 int (*query_port)(struct ib_device *device,
1551 u8 port_num,
1552 struct ib_port_attr *port_attr);
Eli Cohena3f5ada2010-09-27 17:51:10 -07001553 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1554 u8 port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 int (*query_gid)(struct ib_device *device,
1556 u8 port_num, int index,
1557 union ib_gid *gid);
1558 int (*query_pkey)(struct ib_device *device,
1559 u8 port_num, u16 index, u16 *pkey);
1560 int (*modify_device)(struct ib_device *device,
1561 int device_modify_mask,
1562 struct ib_device_modify *device_modify);
1563 int (*modify_port)(struct ib_device *device,
1564 u8 port_num, int port_modify_mask,
1565 struct ib_port_modify *port_modify);
Roland Dreiere2773c02005-07-07 17:57:10 -07001566 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1567 struct ib_udata *udata);
1568 int (*dealloc_ucontext)(struct ib_ucontext *context);
1569 int (*mmap)(struct ib_ucontext *context,
1570 struct vm_area_struct *vma);
1571 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1572 struct ib_ucontext *context,
1573 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 int (*dealloc_pd)(struct ib_pd *pd);
1575 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1576 struct ib_ah_attr *ah_attr);
1577 int (*modify_ah)(struct ib_ah *ah,
1578 struct ib_ah_attr *ah_attr);
1579 int (*query_ah)(struct ib_ah *ah,
1580 struct ib_ah_attr *ah_attr);
1581 int (*destroy_ah)(struct ib_ah *ah);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001582 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1583 struct ib_srq_init_attr *srq_init_attr,
1584 struct ib_udata *udata);
1585 int (*modify_srq)(struct ib_srq *srq,
1586 struct ib_srq_attr *srq_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001587 enum ib_srq_attr_mask srq_attr_mask,
1588 struct ib_udata *udata);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001589 int (*query_srq)(struct ib_srq *srq,
1590 struct ib_srq_attr *srq_attr);
1591 int (*destroy_srq)(struct ib_srq *srq);
1592 int (*post_srq_recv)(struct ib_srq *srq,
1593 struct ib_recv_wr *recv_wr,
1594 struct ib_recv_wr **bad_recv_wr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 struct ib_qp * (*create_qp)(struct ib_pd *pd,
Roland Dreiere2773c02005-07-07 17:57:10 -07001596 struct ib_qp_init_attr *qp_init_attr,
1597 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 int (*modify_qp)(struct ib_qp *qp,
1599 struct ib_qp_attr *qp_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001600 int qp_attr_mask,
1601 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 int (*query_qp)(struct ib_qp *qp,
1603 struct ib_qp_attr *qp_attr,
1604 int qp_attr_mask,
1605 struct ib_qp_init_attr *qp_init_attr);
1606 int (*destroy_qp)(struct ib_qp *qp);
1607 int (*post_send)(struct ib_qp *qp,
1608 struct ib_send_wr *send_wr,
1609 struct ib_send_wr **bad_send_wr);
1610 int (*post_recv)(struct ib_qp *qp,
1611 struct ib_recv_wr *recv_wr,
1612 struct ib_recv_wr **bad_recv_wr);
Roland Dreiere2773c02005-07-07 17:57:10 -07001613 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001614 int comp_vector,
Roland Dreiere2773c02005-07-07 17:57:10 -07001615 struct ib_ucontext *context,
1616 struct ib_udata *udata);
Eli Cohen2dd57162008-04-16 21:09:33 -07001617 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1618 u16 cq_period);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 int (*destroy_cq)(struct ib_cq *cq);
Roland Dreier33b9b3e2006-01-30 14:29:21 -08001620 int (*resize_cq)(struct ib_cq *cq, int cqe,
1621 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1623 struct ib_wc *wc);
1624 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1625 int (*req_notify_cq)(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001626 enum ib_cq_notify_flags flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 int (*req_ncomp_notif)(struct ib_cq *cq,
1628 int wc_cnt);
1629 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1630 int mr_access_flags);
1631 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
1632 struct ib_phys_buf *phys_buf_array,
1633 int num_phys_buf,
1634 int mr_access_flags,
1635 u64 *iova_start);
Roland Dreiere2773c02005-07-07 17:57:10 -07001636 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001637 u64 start, u64 length,
1638 u64 virt_addr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001639 int mr_access_flags,
1640 struct ib_udata *udata);
Matan Barak7e6edb92014-07-31 11:01:28 +03001641 int (*rereg_user_mr)(struct ib_mr *mr,
1642 int flags,
1643 u64 start, u64 length,
1644 u64 virt_addr,
1645 int mr_access_flags,
1646 struct ib_pd *pd,
1647 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 int (*query_mr)(struct ib_mr *mr,
1649 struct ib_mr_attr *mr_attr);
1650 int (*dereg_mr)(struct ib_mr *mr);
Sagi Grimberg17cd3a22014-02-23 14:19:04 +02001651 int (*destroy_mr)(struct ib_mr *mr);
1652 struct ib_mr * (*create_mr)(struct ib_pd *pd,
1653 struct ib_mr_init_attr *mr_init_attr);
Steve Wise00f7ec32008-07-14 23:48:45 -07001654 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
1655 int max_page_list_len);
1656 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1657 int page_list_len);
1658 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 int (*rereg_phys_mr)(struct ib_mr *mr,
1660 int mr_rereg_mask,
1661 struct ib_pd *pd,
1662 struct ib_phys_buf *phys_buf_array,
1663 int num_phys_buf,
1664 int mr_access_flags,
1665 u64 *iova_start);
Shani Michaeli7083e422013-02-06 16:19:12 +00001666 struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
1667 enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 int (*bind_mw)(struct ib_qp *qp,
1669 struct ib_mw *mw,
1670 struct ib_mw_bind *mw_bind);
1671 int (*dealloc_mw)(struct ib_mw *mw);
1672 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1673 int mr_access_flags,
1674 struct ib_fmr_attr *fmr_attr);
1675 int (*map_phys_fmr)(struct ib_fmr *fmr,
1676 u64 *page_list, int list_len,
1677 u64 iova);
1678 int (*unmap_fmr)(struct list_head *fmr_list);
1679 int (*dealloc_fmr)(struct ib_fmr *fmr);
1680 int (*attach_mcast)(struct ib_qp *qp,
1681 union ib_gid *gid,
1682 u16 lid);
1683 int (*detach_mcast)(struct ib_qp *qp,
1684 union ib_gid *gid,
1685 u16 lid);
1686 int (*process_mad)(struct ib_device *device,
1687 int process_mad_flags,
1688 u8 port_num,
1689 struct ib_wc *in_wc,
1690 struct ib_grh *in_grh,
1691 struct ib_mad *in_mad,
1692 struct ib_mad *out_mad);
Sean Hefty59991f92011-05-23 17:52:46 -07001693 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1694 struct ib_ucontext *ucontext,
1695 struct ib_udata *udata);
1696 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001697 struct ib_flow * (*create_flow)(struct ib_qp *qp,
1698 struct ib_flow_attr
1699 *flow_attr,
1700 int domain);
1701 int (*destroy_flow)(struct ib_flow *flow_id);
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001702 int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
1703 struct ib_mr_status *mr_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Ralph Campbell9b513092006-12-12 14:27:41 -08001705 struct ib_dma_mapping_ops *dma_ops;
1706
Roland Dreiere2773c02005-07-07 17:57:10 -07001707 struct module *owner;
Tony Jonesf4e91eb2008-02-22 00:13:36 +01001708 struct device dev;
Greg Kroah-Hartman35be0682007-12-17 15:54:39 -04001709 struct kobject *ports_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 struct list_head port_list;
1711
1712 enum {
1713 IB_DEV_UNINITIALIZED,
1714 IB_DEV_REGISTERED,
1715 IB_DEV_UNREGISTERED
1716 } reg_state;
1717
Roland Dreier274c0892005-09-29 14:17:48 -07001718 int uverbs_abi_ver;
Alexander Chiang17a55f72010-02-02 19:09:16 +00001719 u64 uverbs_cmd_mask;
Yann Droneaudf21519b2013-11-06 23:21:49 +01001720 u64 uverbs_ex_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07001721
Roland Dreierc5bcbbb2006-02-02 09:47:14 -08001722 char node_desc[64];
Sean Heftycf311cd2006-01-10 07:39:34 -08001723 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07001724 u32 local_dma_lkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 u8 node_type;
1726 u8 phys_port_cnt;
Ira Weiny77386132015-05-13 20:02:58 -04001727
1728 /**
1729 * The following mandatory functions are used only at device
1730 * registration. Keep functions such as these at the end of this
1731 * structure to avoid cache line misses when accessing struct ib_device
1732 * in fast paths.
1733 */
1734 int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735};
1736
1737struct ib_client {
1738 char *name;
1739 void (*add) (struct ib_device *);
1740 void (*remove)(struct ib_device *);
1741
1742 struct list_head list;
1743};
1744
1745struct ib_device *ib_alloc_device(size_t size);
1746void ib_dealloc_device(struct ib_device *device);
1747
Ralph Campbell9a6edb62010-05-06 17:03:25 -07001748int ib_register_device(struct ib_device *device,
1749 int (*port_callback)(struct ib_device *,
1750 u8, struct kobject *));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751void ib_unregister_device(struct ib_device *device);
1752
1753int ib_register_client (struct ib_client *client);
1754void ib_unregister_client(struct ib_client *client);
1755
1756void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1757void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1758 void *data);
1759
Roland Dreiere2773c02005-07-07 17:57:10 -07001760static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1761{
1762 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1763}
1764
1765static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1766{
Yann Droneaud43c611652015-02-05 22:10:18 +01001767 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
Roland Dreiere2773c02005-07-07 17:57:10 -07001768}
1769
Roland Dreier8a518662006-02-13 12:48:12 -08001770/**
1771 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1772 * contains all required attributes and no attributes not allowed for
1773 * the given QP state transition.
1774 * @cur_state: Current QP state
1775 * @next_state: Next QP state
1776 * @type: QP type
1777 * @mask: Mask of supplied QP attributes
Matan Barakdd5f03b2013-12-12 18:03:11 +02001778 * @ll : link layer of port
Roland Dreier8a518662006-02-13 12:48:12 -08001779 *
1780 * This function is a helper function that a low-level driver's
1781 * modify_qp method can use to validate the consumer's input. It
1782 * checks that cur_state and next_state are valid QP states, that a
1783 * transition from cur_state to next_state is allowed by the IB spec,
1784 * and that the attribute mask supplied is allowed for the transition.
1785 */
1786int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
Matan Barakdd5f03b2013-12-12 18:03:11 +02001787 enum ib_qp_type type, enum ib_qp_attr_mask mask,
1788 enum rdma_link_layer ll);
Roland Dreier8a518662006-02-13 12:48:12 -08001789
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790int ib_register_event_handler (struct ib_event_handler *event_handler);
1791int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1792void ib_dispatch_event(struct ib_event *event);
1793
1794int ib_query_device(struct ib_device *device,
1795 struct ib_device_attr *device_attr);
1796
1797int ib_query_port(struct ib_device *device,
1798 u8 port_num, struct ib_port_attr *port_attr);
1799
Eli Cohena3f5ada2010-09-27 17:51:10 -07001800enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1801 u8 port_num);
1802
Ira Weiny0cf18d72015-05-13 20:02:55 -04001803/**
1804 * rdma_start_port - Return the first valid port number for the device
1805 * specified
1806 *
1807 * @device: Device to be checked
1808 *
1809 * Return start port number
1810 */
1811static inline u8 rdma_start_port(const struct ib_device *device)
1812{
1813 return (device->node_type == RDMA_NODE_IB_SWITCH) ? 0 : 1;
1814}
1815
1816/**
1817 * rdma_end_port - Return the last valid port number for the device
1818 * specified
1819 *
1820 * @device: Device to be checked
1821 *
1822 * Return last port number
1823 */
1824static inline u8 rdma_end_port(const struct ib_device *device)
1825{
1826 return (device->node_type == RDMA_NODE_IB_SWITCH) ?
1827 0 : device->phys_port_cnt;
1828}
1829
Michael Wangde66be92015-05-05 14:50:19 +02001830static inline bool rdma_protocol_ib(struct ib_device *device, u8 port_num)
1831{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001832 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
Michael Wangde66be92015-05-05 14:50:19 +02001833}
1834
1835static inline bool rdma_protocol_iboe(struct ib_device *device, u8 port_num)
1836{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001837 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
Michael Wangde66be92015-05-05 14:50:19 +02001838}
1839
1840static inline bool rdma_protocol_iwarp(struct ib_device *device, u8 port_num)
1841{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001842 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
Michael Wangde66be92015-05-05 14:50:19 +02001843}
1844
1845static inline bool rdma_ib_or_iboe(struct ib_device *device, u8 port_num)
1846{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001847 return device->port_immutable[port_num].core_cap_flags &
1848 (RDMA_CORE_CAP_PROT_IB | RDMA_CORE_CAP_PROT_ROCE);
Michael Wangde66be92015-05-05 14:50:19 +02001849}
1850
Michael Wangc757dea2015-05-05 14:50:32 +02001851/**
Michael Wang296ec002015-05-18 10:41:45 +02001852 * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
Michael Wangc757dea2015-05-05 14:50:32 +02001853 * Management Datagrams.
Michael Wang296ec002015-05-18 10:41:45 +02001854 * @device: Device to check
1855 * @port_num: Port number to check
Michael Wangc757dea2015-05-05 14:50:32 +02001856 *
Michael Wang296ec002015-05-18 10:41:45 +02001857 * Management Datagrams (MAD) are a required part of the InfiniBand
1858 * specification and are supported on all InfiniBand devices. A slightly
1859 * extended version are also supported on OPA interfaces.
Michael Wangc757dea2015-05-05 14:50:32 +02001860 *
Michael Wang296ec002015-05-18 10:41:45 +02001861 * Return: true if the port supports sending/receiving of MAD packets.
Michael Wangc757dea2015-05-05 14:50:32 +02001862 */
1863static inline bool rdma_cap_ib_mad(struct ib_device *device, u8 port_num)
1864{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001865 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
Michael Wangc757dea2015-05-05 14:50:32 +02001866}
1867
Michael Wang29541e32015-05-05 14:50:33 +02001868/**
Michael Wang296ec002015-05-18 10:41:45 +02001869 * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
1870 * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
1871 * @device: Device to check
1872 * @port_num: Port number to check
Michael Wang29541e32015-05-05 14:50:33 +02001873 *
Michael Wang296ec002015-05-18 10:41:45 +02001874 * Each InfiniBand node is required to provide a Subnet Management Agent
1875 * that the subnet manager can access. Prior to the fabric being fully
1876 * configured by the subnet manager, the SMA is accessed via a well known
1877 * interface called the Subnet Management Interface (SMI). This interface
1878 * uses directed route packets to communicate with the SM to get around the
1879 * chicken and egg problem of the SM needing to know what's on the fabric
1880 * in order to configure the fabric, and needing to configure the fabric in
1881 * order to send packets to the devices on the fabric. These directed
1882 * route packets do not need the fabric fully configured in order to reach
1883 * their destination. The SMI is the only method allowed to send
1884 * directed route packets on an InfiniBand fabric.
Michael Wang29541e32015-05-05 14:50:33 +02001885 *
Michael Wang296ec002015-05-18 10:41:45 +02001886 * Return: true if the port provides an SMI.
Michael Wang29541e32015-05-05 14:50:33 +02001887 */
1888static inline bool rdma_cap_ib_smi(struct ib_device *device, u8 port_num)
1889{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001890 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
Michael Wang29541e32015-05-05 14:50:33 +02001891}
1892
Michael Wang72219cea2015-05-05 14:50:34 +02001893/**
1894 * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
1895 * Communication Manager.
Michael Wang296ec002015-05-18 10:41:45 +02001896 * @device: Device to check
1897 * @port_num: Port number to check
Michael Wang72219cea2015-05-05 14:50:34 +02001898 *
Michael Wang296ec002015-05-18 10:41:45 +02001899 * The InfiniBand Communication Manager is one of many pre-defined General
1900 * Service Agents (GSA) that are accessed via the General Service
1901 * Interface (GSI). It's role is to facilitate establishment of connections
1902 * between nodes as well as other management related tasks for established
1903 * connections.
Michael Wang72219cea2015-05-05 14:50:34 +02001904 *
Michael Wang296ec002015-05-18 10:41:45 +02001905 * Return: true if the port supports an IB CM (this does not guarantee that
1906 * a CM is actually running however).
Michael Wang72219cea2015-05-05 14:50:34 +02001907 */
1908static inline bool rdma_cap_ib_cm(struct ib_device *device, u8 port_num)
1909{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001910 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
Michael Wang72219cea2015-05-05 14:50:34 +02001911}
1912
Michael Wang04215332015-05-05 14:50:35 +02001913/**
1914 * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
1915 * Communication Manager.
Michael Wang296ec002015-05-18 10:41:45 +02001916 * @device: Device to check
1917 * @port_num: Port number to check
Michael Wang04215332015-05-05 14:50:35 +02001918 *
Michael Wang296ec002015-05-18 10:41:45 +02001919 * Similar to above, but specific to iWARP connections which have a different
1920 * managment protocol than InfiniBand.
Michael Wang04215332015-05-05 14:50:35 +02001921 *
Michael Wang296ec002015-05-18 10:41:45 +02001922 * Return: true if the port supports an iWARP CM (this does not guarantee that
1923 * a CM is actually running however).
Michael Wang04215332015-05-05 14:50:35 +02001924 */
1925static inline bool rdma_cap_iw_cm(struct ib_device *device, u8 port_num)
1926{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001927 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
Michael Wang04215332015-05-05 14:50:35 +02001928}
1929
Michael Wangfe53ba22015-05-05 14:50:36 +02001930/**
1931 * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
1932 * Subnet Administration.
Michael Wang296ec002015-05-18 10:41:45 +02001933 * @device: Device to check
1934 * @port_num: Port number to check
Michael Wangfe53ba22015-05-05 14:50:36 +02001935 *
Michael Wang296ec002015-05-18 10:41:45 +02001936 * An InfiniBand Subnet Administration (SA) service is a pre-defined General
1937 * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
1938 * fabrics, devices should resolve routes to other hosts by contacting the
1939 * SA to query the proper route.
Michael Wangfe53ba22015-05-05 14:50:36 +02001940 *
Michael Wang296ec002015-05-18 10:41:45 +02001941 * Return: true if the port should act as a client to the fabric Subnet
1942 * Administration interface. This does not imply that the SA service is
1943 * running locally.
Michael Wangfe53ba22015-05-05 14:50:36 +02001944 */
1945static inline bool rdma_cap_ib_sa(struct ib_device *device, u8 port_num)
1946{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001947 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
Michael Wangfe53ba22015-05-05 14:50:36 +02001948}
1949
Michael Wanga31ad3b2015-05-05 14:50:37 +02001950/**
1951 * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
1952 * Multicast.
Michael Wang296ec002015-05-18 10:41:45 +02001953 * @device: Device to check
1954 * @port_num: Port number to check
Michael Wanga31ad3b2015-05-05 14:50:37 +02001955 *
Michael Wang296ec002015-05-18 10:41:45 +02001956 * InfiniBand multicast registration is more complex than normal IPv4 or
1957 * IPv6 multicast registration. Each Host Channel Adapter must register
1958 * with the Subnet Manager when it wishes to join a multicast group. It
1959 * should do so only once regardless of how many queue pairs it subscribes
1960 * to this group. And it should leave the group only after all queue pairs
1961 * attached to the group have been detached.
Michael Wanga31ad3b2015-05-05 14:50:37 +02001962 *
Michael Wang296ec002015-05-18 10:41:45 +02001963 * Return: true if the port must undertake the additional adminstrative
1964 * overhead of registering/unregistering with the SM and tracking of the
1965 * total number of queue pairs attached to the multicast group.
Michael Wanga31ad3b2015-05-05 14:50:37 +02001966 */
1967static inline bool rdma_cap_ib_mcast(struct ib_device *device, u8 port_num)
1968{
1969 return rdma_cap_ib_sa(device, port_num);
1970}
1971
Michael Wangbc0f1d72015-05-05 14:50:38 +02001972/**
Michael Wang30a74ef2015-05-05 14:50:39 +02001973 * rdma_cap_af_ib - Check if the port of device has the capability
1974 * Native Infiniband Address.
Michael Wang296ec002015-05-18 10:41:45 +02001975 * @device: Device to check
1976 * @port_num: Port number to check
Michael Wang30a74ef2015-05-05 14:50:39 +02001977 *
Michael Wang296ec002015-05-18 10:41:45 +02001978 * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
1979 * GID. RoCE uses a different mechanism, but still generates a GID via
1980 * a prescribed mechanism and port specific data.
Michael Wang30a74ef2015-05-05 14:50:39 +02001981 *
Michael Wang296ec002015-05-18 10:41:45 +02001982 * Return: true if the port uses a GID address to identify devices on the
1983 * network.
Michael Wang30a74ef2015-05-05 14:50:39 +02001984 */
1985static inline bool rdma_cap_af_ib(struct ib_device *device, u8 port_num)
1986{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001987 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
Michael Wang30a74ef2015-05-05 14:50:39 +02001988}
1989
1990/**
Michael Wang227128f2015-05-05 14:50:40 +02001991 * rdma_cap_eth_ah - Check if the port of device has the capability
Michael Wang296ec002015-05-18 10:41:45 +02001992 * Ethernet Address Handle.
1993 * @device: Device to check
1994 * @port_num: Port number to check
Michael Wang227128f2015-05-05 14:50:40 +02001995 *
Michael Wang296ec002015-05-18 10:41:45 +02001996 * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
1997 * to fabricate GIDs over Ethernet/IP specific addresses native to the
1998 * port. Normally, packet headers are generated by the sending host
1999 * adapter, but when sending connectionless datagrams, we must manually
2000 * inject the proper headers for the fabric we are communicating over.
Michael Wang227128f2015-05-05 14:50:40 +02002001 *
Michael Wang296ec002015-05-18 10:41:45 +02002002 * Return: true if we are running as a RoCE port and must force the
2003 * addition of a Global Route Header built from our Ethernet Address
2004 * Handle into our header list for connectionless packets.
Michael Wang227128f2015-05-05 14:50:40 +02002005 */
2006static inline bool rdma_cap_eth_ah(struct ib_device *device, u8 port_num)
2007{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002008 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
Michael Wang227128f2015-05-05 14:50:40 +02002009}
2010
2011/**
Michael Wangbc0f1d72015-05-05 14:50:38 +02002012 * rdma_cap_read_multi_sge - Check if the port of device has the capability
2013 * RDMA Read Multiple Scatter-Gather Entries.
Michael Wang296ec002015-05-18 10:41:45 +02002014 * @device: Device to check
2015 * @port_num: Port number to check
Michael Wangbc0f1d72015-05-05 14:50:38 +02002016 *
Michael Wang296ec002015-05-18 10:41:45 +02002017 * iWARP has a restriction that RDMA READ requests may only have a single
2018 * Scatter/Gather Entry (SGE) in the work request.
Michael Wangbc0f1d72015-05-05 14:50:38 +02002019 *
Michael Wang296ec002015-05-18 10:41:45 +02002020 * NOTE: although the linux kernel currently assumes all devices are either
2021 * single SGE RDMA READ devices or identical SGE maximums for RDMA READs and
2022 * WRITEs, according to Tom Talpey, this is not accurate. There are some
2023 * devices out there that support more than a single SGE on RDMA READ
2024 * requests, but do not support the same number of SGEs as they do on
2025 * RDMA WRITE requests. The linux kernel would need rearchitecting to
2026 * support these imbalanced READ/WRITE SGEs allowed devices. So, for now,
2027 * suffice with either the device supports the same READ/WRITE SGEs, or
2028 * it only gets one READ sge.
2029 *
2030 * Return: true for any device that allows more than one SGE in RDMA READ
2031 * requests.
Michael Wangbc0f1d72015-05-05 14:50:38 +02002032 */
2033static inline bool rdma_cap_read_multi_sge(struct ib_device *device,
2034 u8 port_num)
2035{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002036 return !(device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP);
Michael Wangbc0f1d72015-05-05 14:50:38 +02002037}
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039int ib_query_gid(struct ib_device *device,
2040 u8 port_num, int index, union ib_gid *gid);
2041
2042int ib_query_pkey(struct ib_device *device,
2043 u8 port_num, u16 index, u16 *pkey);
2044
2045int ib_modify_device(struct ib_device *device,
2046 int device_modify_mask,
2047 struct ib_device_modify *device_modify);
2048
2049int ib_modify_port(struct ib_device *device,
2050 u8 port_num, int port_modify_mask,
2051 struct ib_port_modify *port_modify);
2052
Yosef Etigin5eb620c2007-05-14 07:26:51 +03002053int ib_find_gid(struct ib_device *device, union ib_gid *gid,
2054 u8 *port_num, u16 *index);
2055
2056int ib_find_pkey(struct ib_device *device,
2057 u8 port_num, u16 pkey, u16 *index);
2058
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059/**
2060 * ib_alloc_pd - Allocates an unused protection domain.
2061 * @device: The device on which to allocate the protection domain.
2062 *
2063 * A protection domain object provides an association between QPs, shared
2064 * receive queues, address handles, memory regions, and memory windows.
2065 */
2066struct ib_pd *ib_alloc_pd(struct ib_device *device);
2067
2068/**
2069 * ib_dealloc_pd - Deallocates a protection domain.
2070 * @pd: The protection domain to deallocate.
2071 */
2072int ib_dealloc_pd(struct ib_pd *pd);
2073
2074/**
2075 * ib_create_ah - Creates an address handle for the given address vector.
2076 * @pd: The protection domain associated with the address handle.
2077 * @ah_attr: The attributes of the address vector.
2078 *
2079 * The address handle is used to reference a local or global destination
2080 * in all UD QP post sends.
2081 */
2082struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
2083
2084/**
Sean Hefty4e00d692006-06-17 20:37:39 -07002085 * ib_init_ah_from_wc - Initializes address handle attributes from a
2086 * work completion.
2087 * @device: Device on which the received message arrived.
2088 * @port_num: Port on which the received message arrived.
2089 * @wc: Work completion associated with the received message.
2090 * @grh: References the received global route header. This parameter is
2091 * ignored unless the work completion indicates that the GRH is valid.
2092 * @ah_attr: Returned attributes that can be used when creating an address
2093 * handle for replying to the message.
2094 */
2095int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
2096 struct ib_grh *grh, struct ib_ah_attr *ah_attr);
2097
2098/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07002099 * ib_create_ah_from_wc - Creates an address handle associated with the
2100 * sender of the specified work completion.
2101 * @pd: The protection domain associated with the address handle.
2102 * @wc: Work completion information associated with a received message.
2103 * @grh: References the received global route header. This parameter is
2104 * ignored unless the work completion indicates that the GRH is valid.
2105 * @port_num: The outbound port number to associate with the address.
2106 *
2107 * The address handle is used to reference a local or global destination
2108 * in all UD QP post sends.
2109 */
2110struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
2111 struct ib_grh *grh, u8 port_num);
2112
2113/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 * ib_modify_ah - Modifies the address vector associated with an address
2115 * handle.
2116 * @ah: The address handle to modify.
2117 * @ah_attr: The new address vector attributes to associate with the
2118 * address handle.
2119 */
2120int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2121
2122/**
2123 * ib_query_ah - Queries the address vector associated with an address
2124 * handle.
2125 * @ah: The address handle to query.
2126 * @ah_attr: The address vector attributes associated with the address
2127 * handle.
2128 */
2129int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2130
2131/**
2132 * ib_destroy_ah - Destroys an address handle.
2133 * @ah: The address handle to destroy.
2134 */
2135int ib_destroy_ah(struct ib_ah *ah);
2136
2137/**
Roland Dreierd41fcc62005-08-18 12:23:08 -07002138 * ib_create_srq - Creates a SRQ associated with the specified protection
2139 * domain.
2140 * @pd: The protection domain associated with the SRQ.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08002141 * @srq_init_attr: A list of initial attributes required to create the
2142 * SRQ. If SRQ creation succeeds, then the attributes are updated to
2143 * the actual capabilities of the created SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07002144 *
2145 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
2146 * requested size of the SRQ, and set to the actual values allocated
2147 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
2148 * will always be at least as large as the requested values.
2149 */
2150struct ib_srq *ib_create_srq(struct ib_pd *pd,
2151 struct ib_srq_init_attr *srq_init_attr);
2152
2153/**
2154 * ib_modify_srq - Modifies the attributes for the specified SRQ.
2155 * @srq: The SRQ to modify.
2156 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
2157 * the current values of selected SRQ attributes are returned.
2158 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
2159 * are being modified.
2160 *
2161 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
2162 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
2163 * the number of receives queued drops below the limit.
2164 */
2165int ib_modify_srq(struct ib_srq *srq,
2166 struct ib_srq_attr *srq_attr,
2167 enum ib_srq_attr_mask srq_attr_mask);
2168
2169/**
2170 * ib_query_srq - Returns the attribute list and current values for the
2171 * specified SRQ.
2172 * @srq: The SRQ to query.
2173 * @srq_attr: The attributes of the specified SRQ.
2174 */
2175int ib_query_srq(struct ib_srq *srq,
2176 struct ib_srq_attr *srq_attr);
2177
2178/**
2179 * ib_destroy_srq - Destroys the specified SRQ.
2180 * @srq: The SRQ to destroy.
2181 */
2182int ib_destroy_srq(struct ib_srq *srq);
2183
2184/**
2185 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
2186 * @srq: The SRQ to post the work request on.
2187 * @recv_wr: A list of work requests to post on the receive queue.
2188 * @bad_recv_wr: On an immediate failure, this parameter will reference
2189 * the work request that failed to be posted on the QP.
2190 */
2191static inline int ib_post_srq_recv(struct ib_srq *srq,
2192 struct ib_recv_wr *recv_wr,
2193 struct ib_recv_wr **bad_recv_wr)
2194{
2195 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
2196}
2197
2198/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 * ib_create_qp - Creates a QP associated with the specified protection
2200 * domain.
2201 * @pd: The protection domain associated with the QP.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08002202 * @qp_init_attr: A list of initial attributes required to create the
2203 * QP. If QP creation succeeds, then the attributes are updated to
2204 * the actual capabilities of the created QP.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 */
2206struct ib_qp *ib_create_qp(struct ib_pd *pd,
2207 struct ib_qp_init_attr *qp_init_attr);
2208
2209/**
2210 * ib_modify_qp - Modifies the attributes for the specified QP and then
2211 * transitions the QP to the given state.
2212 * @qp: The QP to modify.
2213 * @qp_attr: On input, specifies the QP attributes to modify. On output,
2214 * the current values of selected QP attributes are returned.
2215 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
2216 * are being modified.
2217 */
2218int ib_modify_qp(struct ib_qp *qp,
2219 struct ib_qp_attr *qp_attr,
2220 int qp_attr_mask);
2221
2222/**
2223 * ib_query_qp - Returns the attribute list and current values for the
2224 * specified QP.
2225 * @qp: The QP to query.
2226 * @qp_attr: The attributes of the specified QP.
2227 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
2228 * @qp_init_attr: Additional attributes of the selected QP.
2229 *
2230 * The qp_attr_mask may be used to limit the query to gathering only the
2231 * selected attributes.
2232 */
2233int ib_query_qp(struct ib_qp *qp,
2234 struct ib_qp_attr *qp_attr,
2235 int qp_attr_mask,
2236 struct ib_qp_init_attr *qp_init_attr);
2237
2238/**
2239 * ib_destroy_qp - Destroys the specified QP.
2240 * @qp: The QP to destroy.
2241 */
2242int ib_destroy_qp(struct ib_qp *qp);
2243
2244/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002245 * ib_open_qp - Obtain a reference to an existing sharable QP.
2246 * @xrcd - XRC domain
2247 * @qp_open_attr: Attributes identifying the QP to open.
2248 *
2249 * Returns a reference to a sharable QP.
2250 */
2251struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
2252 struct ib_qp_open_attr *qp_open_attr);
2253
2254/**
2255 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07002256 * @qp: The QP handle to release
2257 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002258 * The opened QP handle is released by the caller. The underlying
2259 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07002260 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002261int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07002262
2263/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 * ib_post_send - Posts a list of work requests to the send queue of
2265 * the specified QP.
2266 * @qp: The QP to post the work request on.
2267 * @send_wr: A list of work requests to post on the send queue.
2268 * @bad_send_wr: On an immediate failure, this parameter will reference
2269 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08002270 *
2271 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
2272 * error is returned, the QP state shall not be affected,
2273 * ib_post_send() will return an immediate error after queueing any
2274 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 */
2276static inline int ib_post_send(struct ib_qp *qp,
2277 struct ib_send_wr *send_wr,
2278 struct ib_send_wr **bad_send_wr)
2279{
2280 return qp->device->post_send(qp, send_wr, bad_send_wr);
2281}
2282
2283/**
2284 * ib_post_recv - Posts a list of work requests to the receive queue of
2285 * the specified QP.
2286 * @qp: The QP to post the work request on.
2287 * @recv_wr: A list of work requests to post on the receive queue.
2288 * @bad_recv_wr: On an immediate failure, this parameter will reference
2289 * the work request that failed to be posted on the QP.
2290 */
2291static inline int ib_post_recv(struct ib_qp *qp,
2292 struct ib_recv_wr *recv_wr,
2293 struct ib_recv_wr **bad_recv_wr)
2294{
2295 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
2296}
2297
2298/**
2299 * ib_create_cq - Creates a CQ on the specified device.
2300 * @device: The device on which to create the CQ.
2301 * @comp_handler: A user-specified callback that is invoked when a
2302 * completion event occurs on the CQ.
2303 * @event_handler: A user-specified callback that is invoked when an
2304 * asynchronous event not associated with a completion occurs on the CQ.
2305 * @cq_context: Context associated with the CQ returned to the user via
2306 * the associated completion and event handlers.
2307 * @cqe: The minimum size of the CQ.
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03002308 * @comp_vector - Completion vector used to signal completion events.
2309 * Must be >= 0 and < context->num_comp_vectors.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 *
2311 * Users can examine the cq structure to determine the actual CQ size.
2312 */
2313struct ib_cq *ib_create_cq(struct ib_device *device,
2314 ib_comp_handler comp_handler,
2315 void (*event_handler)(struct ib_event *, void *),
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03002316 void *cq_context, int cqe, int comp_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
2318/**
2319 * ib_resize_cq - Modifies the capacity of the CQ.
2320 * @cq: The CQ to resize.
2321 * @cqe: The minimum size of the CQ.
2322 *
2323 * Users can examine the cq structure to determine the actual CQ size.
2324 */
2325int ib_resize_cq(struct ib_cq *cq, int cqe);
2326
2327/**
Eli Cohen2dd57162008-04-16 21:09:33 -07002328 * ib_modify_cq - Modifies moderation params of the CQ
2329 * @cq: The CQ to modify.
2330 * @cq_count: number of CQEs that will trigger an event
2331 * @cq_period: max period of time in usec before triggering an event
2332 *
2333 */
2334int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
2335
2336/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 * ib_destroy_cq - Destroys the specified CQ.
2338 * @cq: The CQ to destroy.
2339 */
2340int ib_destroy_cq(struct ib_cq *cq);
2341
2342/**
2343 * ib_poll_cq - poll a CQ for completion(s)
2344 * @cq:the CQ being polled
2345 * @num_entries:maximum number of completions to return
2346 * @wc:array of at least @num_entries &struct ib_wc where completions
2347 * will be returned
2348 *
2349 * Poll a CQ for (possibly multiple) completions. If the return value
2350 * is < 0, an error occurred. If the return value is >= 0, it is the
2351 * number of completions returned. If the return value is
2352 * non-negative and < num_entries, then the CQ was emptied.
2353 */
2354static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
2355 struct ib_wc *wc)
2356{
2357 return cq->device->poll_cq(cq, num_entries, wc);
2358}
2359
2360/**
2361 * ib_peek_cq - Returns the number of unreaped completions currently
2362 * on the specified CQ.
2363 * @cq: The CQ to peek.
2364 * @wc_cnt: A minimum number of unreaped completions to check for.
2365 *
2366 * If the number of unreaped completions is greater than or equal to wc_cnt,
2367 * this function returns wc_cnt, otherwise, it returns the actual number of
2368 * unreaped completions.
2369 */
2370int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
2371
2372/**
2373 * ib_req_notify_cq - Request completion notification on a CQ.
2374 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07002375 * @flags:
2376 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
2377 * to request an event on the next solicited event or next work
2378 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
2379 * may also be |ed in to request a hint about missed events, as
2380 * described below.
2381 *
2382 * Return Value:
2383 * < 0 means an error occurred while requesting notification
2384 * == 0 means notification was requested successfully, and if
2385 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
2386 * were missed and it is safe to wait for another event. In
2387 * this case is it guaranteed that any work completions added
2388 * to the CQ since the last CQ poll will trigger a completion
2389 * notification event.
2390 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
2391 * in. It means that the consumer must poll the CQ again to
2392 * make sure it is empty to avoid missing an event because of a
2393 * race between requesting notification and an entry being
2394 * added to the CQ. This return value means it is possible
2395 * (but not guaranteed) that a work completion has been added
2396 * to the CQ since the last poll without triggering a
2397 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 */
2399static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07002400 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401{
Roland Dreiered23a722007-05-06 21:02:48 -07002402 return cq->device->req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
2404
2405/**
2406 * ib_req_ncomp_notif - Request completion notification when there are
2407 * at least the specified number of unreaped completions on the CQ.
2408 * @cq: The CQ to generate an event for.
2409 * @wc_cnt: The number of unreaped completions that should be on the
2410 * CQ before an event is generated.
2411 */
2412static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
2413{
2414 return cq->device->req_ncomp_notif ?
2415 cq->device->req_ncomp_notif(cq, wc_cnt) :
2416 -ENOSYS;
2417}
2418
2419/**
2420 * ib_get_dma_mr - Returns a memory region for system memory that is
2421 * usable for DMA.
2422 * @pd: The protection domain associated with the memory region.
2423 * @mr_access_flags: Specifies the memory access rights.
Ralph Campbell9b513092006-12-12 14:27:41 -08002424 *
2425 * Note that the ib_dma_*() functions defined below must be used
2426 * to create/destroy addresses used with the Lkey or Rkey returned
2427 * by ib_get_dma_mr().
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 */
2429struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
2430
2431/**
Ralph Campbell9b513092006-12-12 14:27:41 -08002432 * ib_dma_mapping_error - check a DMA addr for error
2433 * @dev: The device for which the dma_addr was created
2434 * @dma_addr: The DMA address to check
2435 */
2436static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
2437{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002438 if (dev->dma_ops)
2439 return dev->dma_ops->mapping_error(dev, dma_addr);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07002440 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08002441}
2442
2443/**
2444 * ib_dma_map_single - Map a kernel virtual address to DMA address
2445 * @dev: The device for which the dma_addr is to be created
2446 * @cpu_addr: The kernel virtual address
2447 * @size: The size of the region in bytes
2448 * @direction: The direction of the DMA
2449 */
2450static inline u64 ib_dma_map_single(struct ib_device *dev,
2451 void *cpu_addr, size_t size,
2452 enum dma_data_direction direction)
2453{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002454 if (dev->dma_ops)
2455 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
2456 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002457}
2458
2459/**
2460 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
2461 * @dev: The device for which the DMA address was created
2462 * @addr: The DMA address
2463 * @size: The size of the region in bytes
2464 * @direction: The direction of the DMA
2465 */
2466static inline void ib_dma_unmap_single(struct ib_device *dev,
2467 u64 addr, size_t size,
2468 enum dma_data_direction direction)
2469{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002470 if (dev->dma_ops)
2471 dev->dma_ops->unmap_single(dev, addr, size, direction);
2472 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002473 dma_unmap_single(dev->dma_device, addr, size, direction);
2474}
2475
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002476static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
2477 void *cpu_addr, size_t size,
2478 enum dma_data_direction direction,
2479 struct dma_attrs *attrs)
2480{
2481 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
2482 direction, attrs);
2483}
2484
2485static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
2486 u64 addr, size_t size,
2487 enum dma_data_direction direction,
2488 struct dma_attrs *attrs)
2489{
2490 return dma_unmap_single_attrs(dev->dma_device, addr, size,
2491 direction, attrs);
2492}
2493
Ralph Campbell9b513092006-12-12 14:27:41 -08002494/**
2495 * ib_dma_map_page - Map a physical page to DMA address
2496 * @dev: The device for which the dma_addr is to be created
2497 * @page: The page to be mapped
2498 * @offset: The offset within the page
2499 * @size: The size of the region in bytes
2500 * @direction: The direction of the DMA
2501 */
2502static inline u64 ib_dma_map_page(struct ib_device *dev,
2503 struct page *page,
2504 unsigned long offset,
2505 size_t size,
2506 enum dma_data_direction direction)
2507{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002508 if (dev->dma_ops)
2509 return dev->dma_ops->map_page(dev, page, offset, size, direction);
2510 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002511}
2512
2513/**
2514 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
2515 * @dev: The device for which the DMA address was created
2516 * @addr: The DMA address
2517 * @size: The size of the region in bytes
2518 * @direction: The direction of the DMA
2519 */
2520static inline void ib_dma_unmap_page(struct ib_device *dev,
2521 u64 addr, size_t size,
2522 enum dma_data_direction direction)
2523{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002524 if (dev->dma_ops)
2525 dev->dma_ops->unmap_page(dev, addr, size, direction);
2526 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002527 dma_unmap_page(dev->dma_device, addr, size, direction);
2528}
2529
2530/**
2531 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
2532 * @dev: The device for which the DMA addresses are to be created
2533 * @sg: The array of scatter/gather entries
2534 * @nents: The number of scatter/gather entries
2535 * @direction: The direction of the DMA
2536 */
2537static inline int ib_dma_map_sg(struct ib_device *dev,
2538 struct scatterlist *sg, int nents,
2539 enum dma_data_direction direction)
2540{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002541 if (dev->dma_ops)
2542 return dev->dma_ops->map_sg(dev, sg, nents, direction);
2543 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002544}
2545
2546/**
2547 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
2548 * @dev: The device for which the DMA addresses were created
2549 * @sg: The array of scatter/gather entries
2550 * @nents: The number of scatter/gather entries
2551 * @direction: The direction of the DMA
2552 */
2553static inline void ib_dma_unmap_sg(struct ib_device *dev,
2554 struct scatterlist *sg, int nents,
2555 enum dma_data_direction direction)
2556{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002557 if (dev->dma_ops)
2558 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
2559 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002560 dma_unmap_sg(dev->dma_device, sg, nents, direction);
2561}
2562
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002563static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
2564 struct scatterlist *sg, int nents,
2565 enum dma_data_direction direction,
2566 struct dma_attrs *attrs)
2567{
2568 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2569}
2570
2571static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
2572 struct scatterlist *sg, int nents,
2573 enum dma_data_direction direction,
2574 struct dma_attrs *attrs)
2575{
2576 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2577}
Ralph Campbell9b513092006-12-12 14:27:41 -08002578/**
2579 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
2580 * @dev: The device for which the DMA addresses were created
2581 * @sg: The scatter/gather entry
Mike Marciniszynea58a592014-03-28 13:26:59 -04002582 *
2583 * Note: this function is obsolete. To do: change all occurrences of
2584 * ib_sg_dma_address() into sg_dma_address().
Ralph Campbell9b513092006-12-12 14:27:41 -08002585 */
2586static inline u64 ib_sg_dma_address(struct ib_device *dev,
2587 struct scatterlist *sg)
2588{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002589 return sg_dma_address(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002590}
2591
2592/**
2593 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
2594 * @dev: The device for which the DMA addresses were created
2595 * @sg: The scatter/gather entry
Mike Marciniszynea58a592014-03-28 13:26:59 -04002596 *
2597 * Note: this function is obsolete. To do: change all occurrences of
2598 * ib_sg_dma_len() into sg_dma_len().
Ralph Campbell9b513092006-12-12 14:27:41 -08002599 */
2600static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
2601 struct scatterlist *sg)
2602{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002603 return sg_dma_len(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002604}
2605
2606/**
2607 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
2608 * @dev: The device for which the DMA address was created
2609 * @addr: The DMA address
2610 * @size: The size of the region in bytes
2611 * @dir: The direction of the DMA
2612 */
2613static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
2614 u64 addr,
2615 size_t size,
2616 enum dma_data_direction dir)
2617{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002618 if (dev->dma_ops)
2619 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
2620 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002621 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
2622}
2623
2624/**
2625 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
2626 * @dev: The device for which the DMA address was created
2627 * @addr: The DMA address
2628 * @size: The size of the region in bytes
2629 * @dir: The direction of the DMA
2630 */
2631static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
2632 u64 addr,
2633 size_t size,
2634 enum dma_data_direction dir)
2635{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002636 if (dev->dma_ops)
2637 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
2638 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002639 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
2640}
2641
2642/**
2643 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
2644 * @dev: The device for which the DMA address is requested
2645 * @size: The size of the region to allocate in bytes
2646 * @dma_handle: A pointer for returning the DMA address of the region
2647 * @flag: memory allocator flags
2648 */
2649static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
2650 size_t size,
2651 u64 *dma_handle,
2652 gfp_t flag)
2653{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002654 if (dev->dma_ops)
2655 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Roland Dreierc59a3da2006-12-15 13:57:26 -08002656 else {
2657 dma_addr_t handle;
2658 void *ret;
2659
2660 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
2661 *dma_handle = handle;
2662 return ret;
2663 }
Ralph Campbell9b513092006-12-12 14:27:41 -08002664}
2665
2666/**
2667 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
2668 * @dev: The device for which the DMA addresses were allocated
2669 * @size: The size of the region
2670 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
2671 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
2672 */
2673static inline void ib_dma_free_coherent(struct ib_device *dev,
2674 size_t size, void *cpu_addr,
2675 u64 dma_handle)
2676{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002677 if (dev->dma_ops)
2678 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
2679 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002680 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
2681}
2682
2683/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
2685 * by an HCA.
2686 * @pd: The protection domain associated assigned to the registered region.
2687 * @phys_buf_array: Specifies a list of physical buffers to use in the
2688 * memory region.
2689 * @num_phys_buf: Specifies the size of the phys_buf_array.
2690 * @mr_access_flags: Specifies the memory access rights.
2691 * @iova_start: The offset of the region's starting I/O virtual address.
2692 */
2693struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
2694 struct ib_phys_buf *phys_buf_array,
2695 int num_phys_buf,
2696 int mr_access_flags,
2697 u64 *iova_start);
2698
2699/**
2700 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
2701 * Conceptually, this call performs the functions deregister memory region
2702 * followed by register physical memory region. Where possible,
2703 * resources are reused instead of deallocated and reallocated.
2704 * @mr: The memory region to modify.
2705 * @mr_rereg_mask: A bit-mask used to indicate which of the following
2706 * properties of the memory region are being modified.
2707 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
2708 * the new protection domain to associated with the memory region,
2709 * otherwise, this parameter is ignored.
2710 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2711 * field specifies a list of physical buffers to use in the new
2712 * translation, otherwise, this parameter is ignored.
2713 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2714 * field specifies the size of the phys_buf_array, otherwise, this
2715 * parameter is ignored.
2716 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
2717 * field specifies the new memory access rights, otherwise, this
2718 * parameter is ignored.
2719 * @iova_start: The offset of the region's starting I/O virtual address.
2720 */
2721int ib_rereg_phys_mr(struct ib_mr *mr,
2722 int mr_rereg_mask,
2723 struct ib_pd *pd,
2724 struct ib_phys_buf *phys_buf_array,
2725 int num_phys_buf,
2726 int mr_access_flags,
2727 u64 *iova_start);
2728
2729/**
2730 * ib_query_mr - Retrieves information about a specific memory region.
2731 * @mr: The memory region to retrieve information about.
2732 * @mr_attr: The attributes of the specified memory region.
2733 */
2734int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
2735
2736/**
2737 * ib_dereg_mr - Deregisters a memory region and removes it from the
2738 * HCA translation table.
2739 * @mr: The memory region to deregister.
Shani Michaeli7083e422013-02-06 16:19:12 +00002740 *
2741 * This function can fail, if the memory region has memory windows bound to it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 */
2743int ib_dereg_mr(struct ib_mr *mr);
2744
Sagi Grimberg17cd3a22014-02-23 14:19:04 +02002745
2746/**
2747 * ib_create_mr - Allocates a memory region that may be used for
2748 * signature handover operations.
2749 * @pd: The protection domain associated with the region.
2750 * @mr_init_attr: memory region init attributes.
2751 */
2752struct ib_mr *ib_create_mr(struct ib_pd *pd,
2753 struct ib_mr_init_attr *mr_init_attr);
2754
2755/**
2756 * ib_destroy_mr - Destroys a memory region that was created using
2757 * ib_create_mr and removes it from HW translation tables.
2758 * @mr: The memory region to destroy.
2759 *
2760 * This function can fail, if the memory region has memory windows bound to it.
2761 */
2762int ib_destroy_mr(struct ib_mr *mr);
2763
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764/**
Steve Wise00f7ec32008-07-14 23:48:45 -07002765 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
2766 * IB_WR_FAST_REG_MR send work request.
2767 * @pd: The protection domain associated with the region.
2768 * @max_page_list_len: requested max physical buffer list length to be
2769 * used with fast register work requests for this MR.
2770 */
2771struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2772
2773/**
2774 * ib_alloc_fast_reg_page_list - Allocates a page list array
2775 * @device - ib device pointer.
2776 * @page_list_len - size of the page list array to be allocated.
2777 *
2778 * This allocates and returns a struct ib_fast_reg_page_list * and a
2779 * page_list array that is at least page_list_len in size. The actual
2780 * size is returned in max_page_list_len. The caller is responsible
2781 * for initializing the contents of the page_list array before posting
2782 * a send work request with the IB_WC_FAST_REG_MR opcode.
2783 *
2784 * The page_list array entries must be translated using one of the
2785 * ib_dma_*() functions just like the addresses passed to
2786 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
2787 * ib_fast_reg_page_list must not be modified by the caller until the
2788 * IB_WC_FAST_REG_MR work request completes.
2789 */
2790struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2791 struct ib_device *device, int page_list_len);
2792
2793/**
2794 * ib_free_fast_reg_page_list - Deallocates a previously allocated
2795 * page list array.
2796 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2797 */
2798void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2799
2800/**
2801 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2802 * R_Key and L_Key.
2803 * @mr - struct ib_mr pointer to be updated.
2804 * @newkey - new key to be used.
2805 */
2806static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2807{
2808 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2809 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2810}
2811
2812/**
Shani Michaeli7083e422013-02-06 16:19:12 +00002813 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
2814 * for calculating a new rkey for type 2 memory windows.
2815 * @rkey - the rkey to increment.
2816 */
2817static inline u32 ib_inc_rkey(u32 rkey)
2818{
2819 const u32 mask = 0x000000ff;
2820 return ((rkey + 1) & mask) | (rkey & ~mask);
2821}
2822
2823/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 * ib_alloc_mw - Allocates a memory window.
2825 * @pd: The protection domain associated with the memory window.
Shani Michaeli7083e422013-02-06 16:19:12 +00002826 * @type: The type of the memory window (1 or 2).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 */
Shani Michaeli7083e422013-02-06 16:19:12 +00002828struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
2830/**
2831 * ib_bind_mw - Posts a work request to the send queue of the specified
2832 * QP, which binds the memory window to the given address range and
2833 * remote access attributes.
2834 * @qp: QP to post the bind work request on.
2835 * @mw: The memory window to bind.
2836 * @mw_bind: Specifies information about the memory window, including
2837 * its address range, remote access rights, and associated memory region.
Shani Michaeli7083e422013-02-06 16:19:12 +00002838 *
2839 * If there is no immediate error, the function will update the rkey member
2840 * of the mw parameter to its new value. The bind operation can still fail
2841 * asynchronously.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 */
2843static inline int ib_bind_mw(struct ib_qp *qp,
2844 struct ib_mw *mw,
2845 struct ib_mw_bind *mw_bind)
2846{
2847 /* XXX reference counting in corresponding MR? */
2848 return mw->device->bind_mw ?
2849 mw->device->bind_mw(qp, mw, mw_bind) :
2850 -ENOSYS;
2851}
2852
2853/**
2854 * ib_dealloc_mw - Deallocates a memory window.
2855 * @mw: The memory window to deallocate.
2856 */
2857int ib_dealloc_mw(struct ib_mw *mw);
2858
2859/**
2860 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2861 * @pd: The protection domain associated with the unmapped region.
2862 * @mr_access_flags: Specifies the memory access rights.
2863 * @fmr_attr: Attributes of the unmapped region.
2864 *
2865 * A fast memory region must be mapped before it can be used as part of
2866 * a work request.
2867 */
2868struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2869 int mr_access_flags,
2870 struct ib_fmr_attr *fmr_attr);
2871
2872/**
2873 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2874 * @fmr: The fast memory region to associate with the pages.
2875 * @page_list: An array of physical pages to map to the fast memory region.
2876 * @list_len: The number of pages in page_list.
2877 * @iova: The I/O virtual address to use with the mapped region.
2878 */
2879static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2880 u64 *page_list, int list_len,
2881 u64 iova)
2882{
2883 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2884}
2885
2886/**
2887 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2888 * @fmr_list: A linked list of fast memory regions to unmap.
2889 */
2890int ib_unmap_fmr(struct list_head *fmr_list);
2891
2892/**
2893 * ib_dealloc_fmr - Deallocates a fast memory region.
2894 * @fmr: The fast memory region to deallocate.
2895 */
2896int ib_dealloc_fmr(struct ib_fmr *fmr);
2897
2898/**
2899 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2900 * @qp: QP to attach to the multicast group. The QP must be type
2901 * IB_QPT_UD.
2902 * @gid: Multicast group GID.
2903 * @lid: Multicast group LID in host byte order.
2904 *
2905 * In order to send and receive multicast packets, subnet
2906 * administration must have created the multicast group and configured
2907 * the fabric appropriately. The port associated with the specified
2908 * QP must also be a member of the multicast group.
2909 */
2910int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2911
2912/**
2913 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2914 * @qp: QP to detach from the multicast group.
2915 * @gid: Multicast group GID.
2916 * @lid: Multicast group LID in host byte order.
2917 */
2918int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2919
Sean Hefty59991f92011-05-23 17:52:46 -07002920/**
2921 * ib_alloc_xrcd - Allocates an XRC domain.
2922 * @device: The device on which to allocate the XRC domain.
2923 */
2924struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2925
2926/**
2927 * ib_dealloc_xrcd - Deallocates an XRC domain.
2928 * @xrcd: The XRC domain to deallocate.
2929 */
2930int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2931
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002932struct ib_flow *ib_create_flow(struct ib_qp *qp,
2933 struct ib_flow_attr *flow_attr, int domain);
2934int ib_destroy_flow(struct ib_flow *flow_id);
2935
Eli Cohen1c636f82013-10-31 15:26:32 +02002936static inline int ib_check_mr_access(int flags)
2937{
2938 /*
2939 * Local write permission is required if remote write or
2940 * remote atomic permission is also requested.
2941 */
2942 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
2943 !(flags & IB_ACCESS_LOCAL_WRITE))
2944 return -EINVAL;
2945
2946 return 0;
2947}
2948
Sagi Grimberg1b01d332014-02-23 14:19:05 +02002949/**
2950 * ib_check_mr_status: lightweight check of MR status.
2951 * This routine may provide status checks on a selected
2952 * ib_mr. first use is for signature status check.
2953 *
2954 * @mr: A memory region.
2955 * @check_mask: Bitmask of which checks to perform from
2956 * ib_mr_status_check enumeration.
2957 * @mr_status: The container of relevant status checks.
2958 * failed checks will be indicated in the status bitmask
2959 * and the relevant info shall be in the error item.
2960 */
2961int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
2962 struct ib_mr_status *mr_status);
2963
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964#endif /* IB_VERBS_H */