blob: 2b4bf0632c64418ed0ffea60421241d52f1c7b73 [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
Matan Barakb9926b92015-06-11 16:35:22 +0300176enum ib_cq_creation_flags {
177 IB_CQ_FLAGS_TIMESTAMP_COMPLETION = 1 << 0,
178};
179
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300180struct ib_cq_init_attr {
181 unsigned int cqe;
182 int comp_vector;
183 u32 flags;
184};
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186struct ib_device_attr {
187 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700188 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 u64 max_mr_size;
190 u64 page_size_cap;
191 u32 vendor_id;
192 u32 vendor_part_id;
193 u32 hw_ver;
194 int max_qp;
195 int max_qp_wr;
196 int device_cap_flags;
197 int max_sge;
198 int max_sge_rd;
199 int max_cq;
200 int max_cqe;
201 int max_mr;
202 int max_pd;
203 int max_qp_rd_atom;
204 int max_ee_rd_atom;
205 int max_res_rd_atom;
206 int max_qp_init_rd_atom;
207 int max_ee_init_rd_atom;
208 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300209 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 int max_ee;
211 int max_rdd;
212 int max_mw;
213 int max_raw_ipv6_qp;
214 int max_raw_ethy_qp;
215 int max_mcast_grp;
216 int max_mcast_qp_attach;
217 int max_total_mcast_qp_attach;
218 int max_ah;
219 int max_fmr;
220 int max_map_per_fmr;
221 int max_srq;
222 int max_srq_wr;
223 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700224 unsigned int max_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 u16 max_pkeys;
226 u8 local_ca_ack_delay;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200227 int sig_prot_cap;
228 int sig_guard_cap;
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200229 struct ib_odp_caps odp_caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230};
231
232enum ib_mtu {
233 IB_MTU_256 = 1,
234 IB_MTU_512 = 2,
235 IB_MTU_1024 = 3,
236 IB_MTU_2048 = 4,
237 IB_MTU_4096 = 5
238};
239
240static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
241{
242 switch (mtu) {
243 case IB_MTU_256: return 256;
244 case IB_MTU_512: return 512;
245 case IB_MTU_1024: return 1024;
246 case IB_MTU_2048: return 2048;
247 case IB_MTU_4096: return 4096;
248 default: return -1;
249 }
250}
251
252enum ib_port_state {
253 IB_PORT_NOP = 0,
254 IB_PORT_DOWN = 1,
255 IB_PORT_INIT = 2,
256 IB_PORT_ARMED = 3,
257 IB_PORT_ACTIVE = 4,
258 IB_PORT_ACTIVE_DEFER = 5
259};
260
261enum ib_port_cap_flags {
262 IB_PORT_SM = 1 << 1,
263 IB_PORT_NOTICE_SUP = 1 << 2,
264 IB_PORT_TRAP_SUP = 1 << 3,
265 IB_PORT_OPT_IPD_SUP = 1 << 4,
266 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
267 IB_PORT_SL_MAP_SUP = 1 << 6,
268 IB_PORT_MKEY_NVRAM = 1 << 7,
269 IB_PORT_PKEY_NVRAM = 1 << 8,
270 IB_PORT_LED_INFO_SUP = 1 << 9,
271 IB_PORT_SM_DISABLED = 1 << 10,
272 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
273 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300274 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 IB_PORT_CM_SUP = 1 << 16,
276 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
277 IB_PORT_REINIT_SUP = 1 << 18,
278 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
279 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
280 IB_PORT_DR_NOTICE_SUP = 1 << 21,
281 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
282 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
283 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
Moni Shouab4a26a22014-02-09 11:54:34 +0200284 IB_PORT_CLIENT_REG_SUP = 1 << 25,
285 IB_PORT_IP_BASED_GIDS = 1 << 26
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286};
287
288enum ib_port_width {
289 IB_WIDTH_1X = 1,
290 IB_WIDTH_4X = 2,
291 IB_WIDTH_8X = 4,
292 IB_WIDTH_12X = 8
293};
294
295static inline int ib_width_enum_to_int(enum ib_port_width width)
296{
297 switch (width) {
298 case IB_WIDTH_1X: return 1;
299 case IB_WIDTH_4X: return 4;
300 case IB_WIDTH_8X: return 8;
301 case IB_WIDTH_12X: return 12;
302 default: return -1;
303 }
304}
305
Or Gerlitz2e966912012-02-28 18:49:50 +0200306enum ib_port_speed {
307 IB_SPEED_SDR = 1,
308 IB_SPEED_DDR = 2,
309 IB_SPEED_QDR = 4,
310 IB_SPEED_FDR10 = 8,
311 IB_SPEED_FDR = 16,
312 IB_SPEED_EDR = 32
313};
314
Steve Wise7f624d02008-07-14 23:48:48 -0700315struct ib_protocol_stats {
316 /* TBD... */
317};
318
319struct iw_protocol_stats {
320 u64 ipInReceives;
321 u64 ipInHdrErrors;
322 u64 ipInTooBigErrors;
323 u64 ipInNoRoutes;
324 u64 ipInAddrErrors;
325 u64 ipInUnknownProtos;
326 u64 ipInTruncatedPkts;
327 u64 ipInDiscards;
328 u64 ipInDelivers;
329 u64 ipOutForwDatagrams;
330 u64 ipOutRequests;
331 u64 ipOutDiscards;
332 u64 ipOutNoRoutes;
333 u64 ipReasmTimeout;
334 u64 ipReasmReqds;
335 u64 ipReasmOKs;
336 u64 ipReasmFails;
337 u64 ipFragOKs;
338 u64 ipFragFails;
339 u64 ipFragCreates;
340 u64 ipInMcastPkts;
341 u64 ipOutMcastPkts;
342 u64 ipInBcastPkts;
343 u64 ipOutBcastPkts;
344
345 u64 tcpRtoAlgorithm;
346 u64 tcpRtoMin;
347 u64 tcpRtoMax;
348 u64 tcpMaxConn;
349 u64 tcpActiveOpens;
350 u64 tcpPassiveOpens;
351 u64 tcpAttemptFails;
352 u64 tcpEstabResets;
353 u64 tcpCurrEstab;
354 u64 tcpInSegs;
355 u64 tcpOutSegs;
356 u64 tcpRetransSegs;
357 u64 tcpInErrs;
358 u64 tcpOutRsts;
359};
360
361union rdma_protocol_stats {
362 struct ib_protocol_stats ib;
363 struct iw_protocol_stats iw;
364};
365
Ira Weinyf9b22e32015-05-13 20:02:59 -0400366/* Define bits for the various functionality this port needs to be supported by
367 * the core.
368 */
369/* Management 0x00000FFF */
370#define RDMA_CORE_CAP_IB_MAD 0x00000001
371#define RDMA_CORE_CAP_IB_SMI 0x00000002
372#define RDMA_CORE_CAP_IB_CM 0x00000004
373#define RDMA_CORE_CAP_IW_CM 0x00000008
374#define RDMA_CORE_CAP_IB_SA 0x00000010
375
376/* Address format 0x000FF000 */
377#define RDMA_CORE_CAP_AF_IB 0x00001000
378#define RDMA_CORE_CAP_ETH_AH 0x00002000
379
380/* Protocol 0xFFF00000 */
381#define RDMA_CORE_CAP_PROT_IB 0x00100000
382#define RDMA_CORE_CAP_PROT_ROCE 0x00200000
383#define RDMA_CORE_CAP_PROT_IWARP 0x00400000
384
385#define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \
386 | RDMA_CORE_CAP_IB_MAD \
387 | RDMA_CORE_CAP_IB_SMI \
388 | RDMA_CORE_CAP_IB_CM \
389 | RDMA_CORE_CAP_IB_SA \
390 | RDMA_CORE_CAP_AF_IB)
391#define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \
392 | RDMA_CORE_CAP_IB_MAD \
393 | RDMA_CORE_CAP_IB_CM \
Ira Weinyf9b22e32015-05-13 20:02:59 -0400394 | RDMA_CORE_CAP_AF_IB \
395 | RDMA_CORE_CAP_ETH_AH)
396#define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \
397 | RDMA_CORE_CAP_IW_CM)
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399struct ib_port_attr {
400 enum ib_port_state state;
401 enum ib_mtu max_mtu;
402 enum ib_mtu active_mtu;
403 int gid_tbl_len;
404 u32 port_cap_flags;
405 u32 max_msg_sz;
406 u32 bad_pkey_cntr;
407 u32 qkey_viol_cntr;
408 u16 pkey_tbl_len;
409 u16 lid;
410 u16 sm_lid;
411 u8 lmc;
412 u8 max_vl_num;
413 u8 sm_sl;
414 u8 subnet_timeout;
415 u8 init_type_reply;
416 u8 active_width;
417 u8 active_speed;
418 u8 phys_state;
419};
420
421enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800422 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
423 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424};
425
426struct ib_device_modify {
427 u64 sys_image_guid;
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800428 char node_desc[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429};
430
431enum ib_port_modify_flags {
432 IB_PORT_SHUTDOWN = 1,
433 IB_PORT_INIT_TYPE = (1<<2),
434 IB_PORT_RESET_QKEY_CNTR = (1<<3)
435};
436
437struct ib_port_modify {
438 u32 set_port_cap_mask;
439 u32 clr_port_cap_mask;
440 u8 init_type;
441};
442
443enum ib_event_type {
444 IB_EVENT_CQ_ERR,
445 IB_EVENT_QP_FATAL,
446 IB_EVENT_QP_REQ_ERR,
447 IB_EVENT_QP_ACCESS_ERR,
448 IB_EVENT_COMM_EST,
449 IB_EVENT_SQ_DRAINED,
450 IB_EVENT_PATH_MIG,
451 IB_EVENT_PATH_MIG_ERR,
452 IB_EVENT_DEVICE_FATAL,
453 IB_EVENT_PORT_ACTIVE,
454 IB_EVENT_PORT_ERR,
455 IB_EVENT_LID_CHANGE,
456 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700457 IB_EVENT_SM_CHANGE,
458 IB_EVENT_SRQ_ERR,
459 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700460 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000461 IB_EVENT_CLIENT_REREGISTER,
462 IB_EVENT_GID_CHANGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463};
464
Sagi Grimberg2b1b5b62015-05-18 13:40:28 +0300465__attribute_const__ const char *ib_event_msg(enum ib_event_type event);
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467struct ib_event {
468 struct ib_device *device;
469 union {
470 struct ib_cq *cq;
471 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700472 struct ib_srq *srq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 u8 port_num;
474 } element;
475 enum ib_event_type event;
476};
477
478struct ib_event_handler {
479 struct ib_device *device;
480 void (*handler)(struct ib_event_handler *, struct ib_event *);
481 struct list_head list;
482};
483
484#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
485 do { \
486 (_ptr)->device = _device; \
487 (_ptr)->handler = _handler; \
488 INIT_LIST_HEAD(&(_ptr)->list); \
489 } while (0)
490
491struct ib_global_route {
492 union ib_gid dgid;
493 u32 flow_label;
494 u8 sgid_index;
495 u8 hop_limit;
496 u8 traffic_class;
497};
498
Hal Rosenstock513789e2005-07-27 11:45:34 -0700499struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700500 __be32 version_tclass_flow;
501 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700502 u8 next_hdr;
503 u8 hop_limit;
504 union ib_gid sgid;
505 union ib_gid dgid;
506};
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508enum {
509 IB_MULTICAST_QPN = 0xffffff
510};
511
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800512#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514enum ib_ah_flags {
515 IB_AH_GRH = 1
516};
517
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700518enum ib_rate {
519 IB_RATE_PORT_CURRENT = 0,
520 IB_RATE_2_5_GBPS = 2,
521 IB_RATE_5_GBPS = 5,
522 IB_RATE_10_GBPS = 3,
523 IB_RATE_20_GBPS = 6,
524 IB_RATE_30_GBPS = 4,
525 IB_RATE_40_GBPS = 7,
526 IB_RATE_60_GBPS = 8,
527 IB_RATE_80_GBPS = 9,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300528 IB_RATE_120_GBPS = 10,
529 IB_RATE_14_GBPS = 11,
530 IB_RATE_56_GBPS = 12,
531 IB_RATE_112_GBPS = 13,
532 IB_RATE_168_GBPS = 14,
533 IB_RATE_25_GBPS = 15,
534 IB_RATE_100_GBPS = 16,
535 IB_RATE_200_GBPS = 17,
536 IB_RATE_300_GBPS = 18
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700537};
538
539/**
540 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
541 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
542 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
543 * @rate: rate to convert.
544 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700545__attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700546
547/**
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300548 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
549 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
550 * @rate: rate to convert.
551 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700552__attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300553
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200554enum ib_mr_create_flags {
555 IB_MR_SIGNATURE_EN = 1,
556};
557
558/**
559 * ib_mr_init_attr - Memory region init attributes passed to routine
560 * ib_create_mr.
561 * @max_reg_descriptors: max number of registration descriptors that
562 * may be used with registration work requests.
563 * @flags: MR creation flags bit mask.
564 */
565struct ib_mr_init_attr {
566 int max_reg_descriptors;
567 u32 flags;
568};
569
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200570/**
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300571 * Signature types
572 * IB_SIG_TYPE_NONE: Unprotected.
573 * IB_SIG_TYPE_T10_DIF: Type T10-DIF
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200574 */
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300575enum ib_signature_type {
576 IB_SIG_TYPE_NONE,
577 IB_SIG_TYPE_T10_DIF,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200578};
579
580/**
581 * Signature T10-DIF block-guard types
582 * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
583 * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
584 */
585enum ib_t10_dif_bg_type {
586 IB_T10DIF_CRC,
587 IB_T10DIF_CSUM
588};
589
590/**
591 * struct ib_t10_dif_domain - Parameters specific for T10-DIF
592 * domain.
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200593 * @bg_type: T10-DIF block guard type (CRC|CSUM)
594 * @pi_interval: protection information interval.
595 * @bg: seed of guard computation.
596 * @app_tag: application tag of guard block
597 * @ref_tag: initial guard block reference tag.
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300598 * @ref_remap: Indicate wethear the reftag increments each block
599 * @app_escape: Indicate to skip block check if apptag=0xffff
600 * @ref_escape: Indicate to skip block check if reftag=0xffffffff
601 * @apptag_check_mask: check bitmask of application tag.
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200602 */
603struct ib_t10_dif_domain {
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200604 enum ib_t10_dif_bg_type bg_type;
605 u16 pi_interval;
606 u16 bg;
607 u16 app_tag;
608 u32 ref_tag;
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300609 bool ref_remap;
610 bool app_escape;
611 bool ref_escape;
612 u16 apptag_check_mask;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200613};
614
615/**
616 * struct ib_sig_domain - Parameters for signature domain
617 * @sig_type: specific signauture type
618 * @sig: union of all signature domain attributes that may
619 * be used to set domain layout.
620 */
621struct ib_sig_domain {
622 enum ib_signature_type sig_type;
623 union {
624 struct ib_t10_dif_domain dif;
625 } sig;
626};
627
628/**
629 * struct ib_sig_attrs - Parameters for signature handover operation
630 * @check_mask: bitmask for signature byte check (8 bytes)
631 * @mem: memory domain layout desciptor.
632 * @wire: wire domain layout desciptor.
633 */
634struct ib_sig_attrs {
635 u8 check_mask;
636 struct ib_sig_domain mem;
637 struct ib_sig_domain wire;
638};
639
640enum ib_sig_err_type {
641 IB_SIG_BAD_GUARD,
642 IB_SIG_BAD_REFTAG,
643 IB_SIG_BAD_APPTAG,
644};
645
646/**
647 * struct ib_sig_err - signature error descriptor
648 */
649struct ib_sig_err {
650 enum ib_sig_err_type err_type;
651 u32 expected;
652 u32 actual;
653 u64 sig_err_offset;
654 u32 key;
655};
656
657enum ib_mr_status_check {
658 IB_MR_CHECK_SIG_STATUS = 1,
659};
660
661/**
662 * struct ib_mr_status - Memory region status container
663 *
664 * @fail_status: Bitmask of MR checks status. For each
665 * failed check a corresponding status bit is set.
666 * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
667 * failure.
668 */
669struct ib_mr_status {
670 u32 fail_status;
671 struct ib_sig_err sig_err;
672};
673
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300674/**
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700675 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
676 * enum.
677 * @mult: multiple to convert.
678 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700679__attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681struct ib_ah_attr {
682 struct ib_global_route grh;
683 u16 dlid;
684 u8 sl;
685 u8 src_path_bits;
686 u8 static_rate;
687 u8 ah_flags;
688 u8 port_num;
Matan Barakdd5f03b2013-12-12 18:03:11 +0200689 u8 dmac[ETH_ALEN];
690 u16 vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691};
692
693enum ib_wc_status {
694 IB_WC_SUCCESS,
695 IB_WC_LOC_LEN_ERR,
696 IB_WC_LOC_QP_OP_ERR,
697 IB_WC_LOC_EEC_OP_ERR,
698 IB_WC_LOC_PROT_ERR,
699 IB_WC_WR_FLUSH_ERR,
700 IB_WC_MW_BIND_ERR,
701 IB_WC_BAD_RESP_ERR,
702 IB_WC_LOC_ACCESS_ERR,
703 IB_WC_REM_INV_REQ_ERR,
704 IB_WC_REM_ACCESS_ERR,
705 IB_WC_REM_OP_ERR,
706 IB_WC_RETRY_EXC_ERR,
707 IB_WC_RNR_RETRY_EXC_ERR,
708 IB_WC_LOC_RDD_VIOL_ERR,
709 IB_WC_REM_INV_RD_REQ_ERR,
710 IB_WC_REM_ABORT_ERR,
711 IB_WC_INV_EECN_ERR,
712 IB_WC_INV_EEC_STATE_ERR,
713 IB_WC_FATAL_ERR,
714 IB_WC_RESP_TIMEOUT_ERR,
715 IB_WC_GENERAL_ERR
716};
717
Sagi Grimberg2b1b5b62015-05-18 13:40:28 +0300718__attribute_const__ const char *ib_wc_status_msg(enum ib_wc_status status);
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720enum ib_wc_opcode {
721 IB_WC_SEND,
722 IB_WC_RDMA_WRITE,
723 IB_WC_RDMA_READ,
724 IB_WC_COMP_SWAP,
725 IB_WC_FETCH_ADD,
726 IB_WC_BIND_MW,
Eli Cohenc93570f2008-04-16 21:09:27 -0700727 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700728 IB_WC_LOCAL_INV,
729 IB_WC_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300730 IB_WC_MASKED_COMP_SWAP,
731 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732/*
733 * Set value of IB_WC_RECV so consumers can test if a completion is a
734 * receive by testing (opcode & IB_WC_RECV).
735 */
736 IB_WC_RECV = 1 << 7,
737 IB_WC_RECV_RDMA_WITH_IMM
738};
739
740enum ib_wc_flags {
741 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -0700742 IB_WC_WITH_IMM = (1<<1),
743 IB_WC_WITH_INVALIDATE = (1<<2),
Or Gerlitzd927d502012-01-11 19:03:51 +0200744 IB_WC_IP_CSUM_OK = (1<<3),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200745 IB_WC_WITH_SMAC = (1<<4),
746 IB_WC_WITH_VLAN = (1<<5),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747};
748
749struct ib_wc {
750 u64 wr_id;
751 enum ib_wc_status status;
752 enum ib_wc_opcode opcode;
753 u32 vendor_err;
754 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +0200755 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -0700756 union {
757 __be32 imm_data;
758 u32 invalidate_rkey;
759 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 u32 src_qp;
761 int wc_flags;
762 u16 pkey_index;
763 u16 slid;
764 u8 sl;
765 u8 dlid_path_bits;
766 u8 port_num; /* valid only for DR SMPs on switches */
Matan Barakdd5f03b2013-12-12 18:03:11 +0200767 u8 smac[ETH_ALEN];
768 u16 vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769};
770
Roland Dreiered23a722007-05-06 21:02:48 -0700771enum ib_cq_notify_flags {
772 IB_CQ_SOLICITED = 1 << 0,
773 IB_CQ_NEXT_COMP = 1 << 1,
774 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
775 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776};
777
Sean Hefty96104ed2011-05-23 16:31:36 -0700778enum ib_srq_type {
Sean Hefty418d5132011-05-23 19:42:29 -0700779 IB_SRQT_BASIC,
780 IB_SRQT_XRC
Sean Hefty96104ed2011-05-23 16:31:36 -0700781};
782
Roland Dreierd41fcc62005-08-18 12:23:08 -0700783enum ib_srq_attr_mask {
784 IB_SRQ_MAX_WR = 1 << 0,
785 IB_SRQ_LIMIT = 1 << 1,
786};
787
788struct ib_srq_attr {
789 u32 max_wr;
790 u32 max_sge;
791 u32 srq_limit;
792};
793
794struct ib_srq_init_attr {
795 void (*event_handler)(struct ib_event *, void *);
796 void *srq_context;
797 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -0700798 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -0700799
800 union {
801 struct {
802 struct ib_xrcd *xrcd;
803 struct ib_cq *cq;
804 } xrc;
805 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700806};
807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808struct ib_qp_cap {
809 u32 max_send_wr;
810 u32 max_recv_wr;
811 u32 max_send_sge;
812 u32 max_recv_sge;
813 u32 max_inline_data;
814};
815
816enum ib_sig_type {
817 IB_SIGNAL_ALL_WR,
818 IB_SIGNAL_REQ_WR
819};
820
821enum ib_qp_type {
822 /*
823 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
824 * here (and in that order) since the MAD layer uses them as
825 * indices into a 2-entry table.
826 */
827 IB_QPT_SMI,
828 IB_QPT_GSI,
829
830 IB_QPT_RC,
831 IB_QPT_UC,
832 IB_QPT_UD,
833 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700834 IB_QPT_RAW_ETHERTYPE,
Or Gerlitzc938a612012-03-01 12:17:51 +0200835 IB_QPT_RAW_PACKET = 8,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700836 IB_QPT_XRC_INI = 9,
837 IB_QPT_XRC_TGT,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300838 IB_QPT_MAX,
839 /* Reserve a range for qp types internal to the low level driver.
840 * These qp types will not be visible at the IB core layer, so the
841 * IB_QPT_MAX usages should not be affected in the core layer
842 */
843 IB_QPT_RESERVED1 = 0x1000,
844 IB_QPT_RESERVED2,
845 IB_QPT_RESERVED3,
846 IB_QPT_RESERVED4,
847 IB_QPT_RESERVED5,
848 IB_QPT_RESERVED6,
849 IB_QPT_RESERVED7,
850 IB_QPT_RESERVED8,
851 IB_QPT_RESERVED9,
852 IB_QPT_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853};
854
Eli Cohenb846f252008-04-16 21:09:27 -0700855enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -0700856 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
857 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
Matan Barak90f1d1b2013-11-07 15:25:12 +0200858 IB_QP_CREATE_NETIF_QP = 1 << 5,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200859 IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
Or Gerlitz09b93082014-05-11 15:15:11 +0300860 IB_QP_CREATE_USE_GFP_NOIO = 1 << 7,
Jack Morgensteind2b57062012-08-03 08:40:37 +0000861 /* reserve bits 26-31 for low level drivers' internal use */
862 IB_QP_CREATE_RESERVED_START = 1 << 26,
863 IB_QP_CREATE_RESERVED_END = 1 << 31,
Eli Cohenb846f252008-04-16 21:09:27 -0700864};
865
Yishai Hadas73c40c62013-08-01 18:49:53 +0300866
867/*
868 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
869 * callback to destroy the passed in QP.
870 */
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872struct ib_qp_init_attr {
873 void (*event_handler)(struct ib_event *, void *);
874 void *qp_context;
875 struct ib_cq *send_cq;
876 struct ib_cq *recv_cq;
877 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700878 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 struct ib_qp_cap cap;
880 enum ib_sig_type sq_sig_type;
881 enum ib_qp_type qp_type;
Eli Cohenb846f252008-04-16 21:09:27 -0700882 enum ib_qp_create_flags create_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 u8 port_num; /* special QP types only */
884};
885
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700886struct ib_qp_open_attr {
887 void (*event_handler)(struct ib_event *, void *);
888 void *qp_context;
889 u32 qp_num;
890 enum ib_qp_type qp_type;
891};
892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893enum ib_rnr_timeout {
894 IB_RNR_TIMER_655_36 = 0,
895 IB_RNR_TIMER_000_01 = 1,
896 IB_RNR_TIMER_000_02 = 2,
897 IB_RNR_TIMER_000_03 = 3,
898 IB_RNR_TIMER_000_04 = 4,
899 IB_RNR_TIMER_000_06 = 5,
900 IB_RNR_TIMER_000_08 = 6,
901 IB_RNR_TIMER_000_12 = 7,
902 IB_RNR_TIMER_000_16 = 8,
903 IB_RNR_TIMER_000_24 = 9,
904 IB_RNR_TIMER_000_32 = 10,
905 IB_RNR_TIMER_000_48 = 11,
906 IB_RNR_TIMER_000_64 = 12,
907 IB_RNR_TIMER_000_96 = 13,
908 IB_RNR_TIMER_001_28 = 14,
909 IB_RNR_TIMER_001_92 = 15,
910 IB_RNR_TIMER_002_56 = 16,
911 IB_RNR_TIMER_003_84 = 17,
912 IB_RNR_TIMER_005_12 = 18,
913 IB_RNR_TIMER_007_68 = 19,
914 IB_RNR_TIMER_010_24 = 20,
915 IB_RNR_TIMER_015_36 = 21,
916 IB_RNR_TIMER_020_48 = 22,
917 IB_RNR_TIMER_030_72 = 23,
918 IB_RNR_TIMER_040_96 = 24,
919 IB_RNR_TIMER_061_44 = 25,
920 IB_RNR_TIMER_081_92 = 26,
921 IB_RNR_TIMER_122_88 = 27,
922 IB_RNR_TIMER_163_84 = 28,
923 IB_RNR_TIMER_245_76 = 29,
924 IB_RNR_TIMER_327_68 = 30,
925 IB_RNR_TIMER_491_52 = 31
926};
927
928enum ib_qp_attr_mask {
929 IB_QP_STATE = 1,
930 IB_QP_CUR_STATE = (1<<1),
931 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
932 IB_QP_ACCESS_FLAGS = (1<<3),
933 IB_QP_PKEY_INDEX = (1<<4),
934 IB_QP_PORT = (1<<5),
935 IB_QP_QKEY = (1<<6),
936 IB_QP_AV = (1<<7),
937 IB_QP_PATH_MTU = (1<<8),
938 IB_QP_TIMEOUT = (1<<9),
939 IB_QP_RETRY_CNT = (1<<10),
940 IB_QP_RNR_RETRY = (1<<11),
941 IB_QP_RQ_PSN = (1<<12),
942 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
943 IB_QP_ALT_PATH = (1<<14),
944 IB_QP_MIN_RNR_TIMER = (1<<15),
945 IB_QP_SQ_PSN = (1<<16),
946 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
947 IB_QP_PATH_MIG_STATE = (1<<18),
948 IB_QP_CAP = (1<<19),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200949 IB_QP_DEST_QPN = (1<<20),
950 IB_QP_SMAC = (1<<21),
951 IB_QP_ALT_SMAC = (1<<22),
952 IB_QP_VID = (1<<23),
953 IB_QP_ALT_VID = (1<<24),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954};
955
956enum ib_qp_state {
957 IB_QPS_RESET,
958 IB_QPS_INIT,
959 IB_QPS_RTR,
960 IB_QPS_RTS,
961 IB_QPS_SQD,
962 IB_QPS_SQE,
963 IB_QPS_ERR
964};
965
966enum ib_mig_state {
967 IB_MIG_MIGRATED,
968 IB_MIG_REARM,
969 IB_MIG_ARMED
970};
971
Shani Michaeli7083e422013-02-06 16:19:12 +0000972enum ib_mw_type {
973 IB_MW_TYPE_1 = 1,
974 IB_MW_TYPE_2 = 2
975};
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977struct ib_qp_attr {
978 enum ib_qp_state qp_state;
979 enum ib_qp_state cur_qp_state;
980 enum ib_mtu path_mtu;
981 enum ib_mig_state path_mig_state;
982 u32 qkey;
983 u32 rq_psn;
984 u32 sq_psn;
985 u32 dest_qp_num;
986 int qp_access_flags;
987 struct ib_qp_cap cap;
988 struct ib_ah_attr ah_attr;
989 struct ib_ah_attr alt_ah_attr;
990 u16 pkey_index;
991 u16 alt_pkey_index;
992 u8 en_sqd_async_notify;
993 u8 sq_draining;
994 u8 max_rd_atomic;
995 u8 max_dest_rd_atomic;
996 u8 min_rnr_timer;
997 u8 port_num;
998 u8 timeout;
999 u8 retry_cnt;
1000 u8 rnr_retry;
1001 u8 alt_port_num;
1002 u8 alt_timeout;
Matan Barakdd5f03b2013-12-12 18:03:11 +02001003 u8 smac[ETH_ALEN];
1004 u8 alt_smac[ETH_ALEN];
1005 u16 vlan_id;
1006 u16 alt_vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007};
1008
1009enum ib_wr_opcode {
1010 IB_WR_RDMA_WRITE,
1011 IB_WR_RDMA_WRITE_WITH_IMM,
1012 IB_WR_SEND,
1013 IB_WR_SEND_WITH_IMM,
1014 IB_WR_RDMA_READ,
1015 IB_WR_ATOMIC_CMP_AND_SWP,
Eli Cohenc93570f2008-04-16 21:09:27 -07001016 IB_WR_ATOMIC_FETCH_AND_ADD,
Roland Dreier0f39cf32008-04-16 21:09:32 -07001017 IB_WR_LSO,
1018 IB_WR_SEND_WITH_INV,
Steve Wise00f7ec32008-07-14 23:48:45 -07001019 IB_WR_RDMA_READ_WITH_INV,
1020 IB_WR_LOCAL_INV,
1021 IB_WR_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +03001022 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
1023 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
Shani Michaeli7083e422013-02-06 16:19:12 +00001024 IB_WR_BIND_MW,
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001025 IB_WR_REG_SIG_MR,
Jack Morgenstein0134f162013-07-07 17:25:52 +03001026 /* reserve values for low level drivers' internal use.
1027 * These values will not be used at all in the ib core layer.
1028 */
1029 IB_WR_RESERVED1 = 0xf0,
1030 IB_WR_RESERVED2,
1031 IB_WR_RESERVED3,
1032 IB_WR_RESERVED4,
1033 IB_WR_RESERVED5,
1034 IB_WR_RESERVED6,
1035 IB_WR_RESERVED7,
1036 IB_WR_RESERVED8,
1037 IB_WR_RESERVED9,
1038 IB_WR_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039};
1040
1041enum ib_send_flags {
1042 IB_SEND_FENCE = 1,
1043 IB_SEND_SIGNALED = (1<<1),
1044 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +02001045 IB_SEND_INLINE = (1<<3),
Jack Morgenstein0134f162013-07-07 17:25:52 +03001046 IB_SEND_IP_CSUM = (1<<4),
1047
1048 /* reserve bits 26-31 for low level drivers' internal use */
1049 IB_SEND_RESERVED_START = (1 << 26),
1050 IB_SEND_RESERVED_END = (1 << 31),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051};
1052
1053struct ib_sge {
1054 u64 addr;
1055 u32 length;
1056 u32 lkey;
1057};
1058
Steve Wise00f7ec32008-07-14 23:48:45 -07001059struct ib_fast_reg_page_list {
1060 struct ib_device *device;
1061 u64 *page_list;
1062 unsigned int max_page_list_len;
1063};
1064
Shani Michaeli7083e422013-02-06 16:19:12 +00001065/**
1066 * struct ib_mw_bind_info - Parameters for a memory window bind operation.
1067 * @mr: A memory region to bind the memory window to.
1068 * @addr: The address where the memory window should begin.
1069 * @length: The length of the memory window, in bytes.
1070 * @mw_access_flags: Access flags from enum ib_access_flags for the window.
1071 *
1072 * This struct contains the shared parameters for type 1 and type 2
1073 * memory window bind operations.
1074 */
1075struct ib_mw_bind_info {
1076 struct ib_mr *mr;
1077 u64 addr;
1078 u64 length;
1079 int mw_access_flags;
1080};
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082struct ib_send_wr {
1083 struct ib_send_wr *next;
1084 u64 wr_id;
1085 struct ib_sge *sg_list;
1086 int num_sge;
1087 enum ib_wr_opcode opcode;
1088 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -07001089 union {
1090 __be32 imm_data;
1091 u32 invalidate_rkey;
1092 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 union {
1094 struct {
1095 u64 remote_addr;
1096 u32 rkey;
1097 } rdma;
1098 struct {
1099 u64 remote_addr;
1100 u64 compare_add;
1101 u64 swap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +03001102 u64 compare_add_mask;
1103 u64 swap_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 u32 rkey;
1105 } atomic;
1106 struct {
1107 struct ib_ah *ah;
Eli Cohenc93570f2008-04-16 21:09:27 -07001108 void *header;
1109 int hlen;
1110 int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 u32 remote_qpn;
1112 u32 remote_qkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 u16 pkey_index; /* valid for GSI only */
1114 u8 port_num; /* valid for DR SMPs on switch only */
1115 } ud;
Steve Wise00f7ec32008-07-14 23:48:45 -07001116 struct {
1117 u64 iova_start;
1118 struct ib_fast_reg_page_list *page_list;
1119 unsigned int page_shift;
1120 unsigned int page_list_len;
1121 u32 length;
1122 int access_flags;
1123 u32 rkey;
1124 } fast_reg;
Shani Michaeli7083e422013-02-06 16:19:12 +00001125 struct {
1126 struct ib_mw *mw;
1127 /* The new rkey for the memory window. */
1128 u32 rkey;
1129 struct ib_mw_bind_info bind_info;
1130 } bind_mw;
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001131 struct {
1132 struct ib_sig_attrs *sig_attrs;
1133 struct ib_mr *sig_mr;
1134 int access_flags;
1135 struct ib_sge *prot;
1136 } sig_handover;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 } wr;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001138 u32 xrc_remote_srq_num; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139};
1140
1141struct ib_recv_wr {
1142 struct ib_recv_wr *next;
1143 u64 wr_id;
1144 struct ib_sge *sg_list;
1145 int num_sge;
1146};
1147
1148enum ib_access_flags {
1149 IB_ACCESS_LOCAL_WRITE = 1,
1150 IB_ACCESS_REMOTE_WRITE = (1<<1),
1151 IB_ACCESS_REMOTE_READ = (1<<2),
1152 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
Shani Michaeli7083e422013-02-06 16:19:12 +00001153 IB_ACCESS_MW_BIND = (1<<4),
Sagi Grimberg860f10a2014-12-11 17:04:16 +02001154 IB_ZERO_BASED = (1<<5),
1155 IB_ACCESS_ON_DEMAND = (1<<6),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156};
1157
1158struct ib_phys_buf {
1159 u64 addr;
1160 u64 size;
1161};
1162
1163struct ib_mr_attr {
1164 struct ib_pd *pd;
1165 u64 device_virt_addr;
1166 u64 size;
1167 int mr_access_flags;
1168 u32 lkey;
1169 u32 rkey;
1170};
1171
1172enum ib_mr_rereg_flags {
1173 IB_MR_REREG_TRANS = 1,
1174 IB_MR_REREG_PD = (1<<1),
Matan Barak7e6edb92014-07-31 11:01:28 +03001175 IB_MR_REREG_ACCESS = (1<<2),
1176 IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177};
1178
Shani Michaeli7083e422013-02-06 16:19:12 +00001179/**
1180 * struct ib_mw_bind - Parameters for a type 1 memory window bind operation.
1181 * @wr_id: Work request id.
1182 * @send_flags: Flags from ib_send_flags enum.
1183 * @bind_info: More parameters of the bind operation.
1184 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185struct ib_mw_bind {
Shani Michaeli7083e422013-02-06 16:19:12 +00001186 u64 wr_id;
1187 int send_flags;
1188 struct ib_mw_bind_info bind_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189};
1190
1191struct ib_fmr_attr {
1192 int max_pages;
1193 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -08001194 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195};
1196
Haggai Eran882214e2014-12-11 17:04:18 +02001197struct ib_umem;
1198
Roland Dreiere2773c02005-07-07 17:57:10 -07001199struct ib_ucontext {
1200 struct ib_device *device;
1201 struct list_head pd_list;
1202 struct list_head mr_list;
1203 struct list_head mw_list;
1204 struct list_head cq_list;
1205 struct list_head qp_list;
1206 struct list_head srq_list;
1207 struct list_head ah_list;
Sean Hefty53d0bd12011-05-24 08:33:46 -07001208 struct list_head xrcd_list;
Hadar Hen Zion436f2ad2013-08-14 13:58:30 +03001209 struct list_head rule_list;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001210 int closing;
Shachar Raindel8ada2c12014-12-11 17:04:17 +02001211
1212 struct pid *tgid;
Haggai Eran882214e2014-12-11 17:04:18 +02001213#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
1214 struct rb_root umem_tree;
1215 /*
1216 * Protects .umem_rbroot and tree, as well as odp_mrs_count and
1217 * mmu notifiers registration.
1218 */
1219 struct rw_semaphore umem_rwsem;
1220 void (*invalidate_range)(struct ib_umem *umem,
1221 unsigned long start, unsigned long end);
1222
1223 struct mmu_notifier mn;
1224 atomic_t notifier_count;
1225 /* A list of umems that don't have private mmu notifier counters yet. */
1226 struct list_head no_private_counters;
1227 int odp_mrs_count;
1228#endif
Roland Dreiere2773c02005-07-07 17:57:10 -07001229};
1230
1231struct ib_uobject {
1232 u64 user_handle; /* handle given to us by userspace */
1233 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -07001234 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -07001235 struct list_head list; /* link to context's list */
Roland Dreierb3d636b2008-04-16 21:01:06 -07001236 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -07001237 struct kref ref;
1238 struct rw_semaphore mutex; /* protects .live */
1239 int live;
Roland Dreiere2773c02005-07-07 17:57:10 -07001240};
1241
Roland Dreiere2773c02005-07-07 17:57:10 -07001242struct ib_udata {
Yann Droneaud309243e2013-12-11 23:01:44 +01001243 const void __user *inbuf;
Roland Dreiere2773c02005-07-07 17:57:10 -07001244 void __user *outbuf;
1245 size_t inlen;
1246 size_t outlen;
1247};
1248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249struct ib_pd {
Roland Dreiere2773c02005-07-07 17:57:10 -07001250 struct ib_device *device;
1251 struct ib_uobject *uobject;
1252 atomic_t usecnt; /* count all resources */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253};
1254
Sean Hefty59991f92011-05-23 17:52:46 -07001255struct ib_xrcd {
1256 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001257 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -07001258 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001259
1260 struct mutex tgt_qp_mutex;
1261 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -07001262};
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264struct ib_ah {
1265 struct ib_device *device;
1266 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001267 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268};
1269
1270typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1271
1272struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -07001273 struct ib_device *device;
1274 struct ib_uobject *uobject;
1275 ib_comp_handler comp_handler;
1276 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -07001277 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -07001278 int cqe;
1279 atomic_t usecnt; /* count number of work queues */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280};
1281
1282struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -07001283 struct ib_device *device;
1284 struct ib_pd *pd;
1285 struct ib_uobject *uobject;
1286 void (*event_handler)(struct ib_event *, void *);
1287 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -07001288 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -07001290
1291 union {
1292 struct {
1293 struct ib_xrcd *xrcd;
1294 struct ib_cq *cq;
1295 u32 srq_num;
1296 } xrc;
1297 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298};
1299
1300struct ib_qp {
1301 struct ib_device *device;
1302 struct ib_pd *pd;
1303 struct ib_cq *send_cq;
1304 struct ib_cq *recv_cq;
1305 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001306 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -07001307 struct list_head xrcd_list;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001308 /* count times opened, mcast attaches, flow attaches */
1309 atomic_t usecnt;
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001310 struct list_head open_list;
1311 struct ib_qp *real_qp;
Roland Dreiere2773c02005-07-07 17:57:10 -07001312 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 void (*event_handler)(struct ib_event *, void *);
1314 void *qp_context;
1315 u32 qp_num;
1316 enum ib_qp_type qp_type;
1317};
1318
1319struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -07001320 struct ib_device *device;
1321 struct ib_pd *pd;
1322 struct ib_uobject *uobject;
1323 u32 lkey;
1324 u32 rkey;
1325 atomic_t usecnt; /* count number of MWs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326};
1327
1328struct ib_mw {
1329 struct ib_device *device;
1330 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001331 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 u32 rkey;
Shani Michaeli7083e422013-02-06 16:19:12 +00001333 enum ib_mw_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334};
1335
1336struct ib_fmr {
1337 struct ib_device *device;
1338 struct ib_pd *pd;
1339 struct list_head list;
1340 u32 lkey;
1341 u32 rkey;
1342};
1343
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001344/* Supported steering options */
1345enum ib_flow_attr_type {
1346 /* steering according to rule specifications */
1347 IB_FLOW_ATTR_NORMAL = 0x0,
1348 /* default unicast and multicast rule -
1349 * receive all Eth traffic which isn't steered to any QP
1350 */
1351 IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1352 /* default multicast rule -
1353 * receive all Eth multicast traffic which isn't steered to any QP
1354 */
1355 IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1356 /* sniffer rule - receive all port traffic */
1357 IB_FLOW_ATTR_SNIFFER = 0x3
1358};
1359
1360/* Supported steering header types */
1361enum ib_flow_spec_type {
1362 /* L2 headers*/
1363 IB_FLOW_SPEC_ETH = 0x20,
Matan Barak240ae002013-11-07 15:25:13 +02001364 IB_FLOW_SPEC_IB = 0x22,
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001365 /* L3 header*/
1366 IB_FLOW_SPEC_IPV4 = 0x30,
1367 /* L4 headers*/
1368 IB_FLOW_SPEC_TCP = 0x40,
1369 IB_FLOW_SPEC_UDP = 0x41
1370};
Matan Barak240ae002013-11-07 15:25:13 +02001371#define IB_FLOW_SPEC_LAYER_MASK 0xF0
Matan Barak22878db2013-09-01 18:39:52 +03001372#define IB_FLOW_SPEC_SUPPORT_LAYERS 4
1373
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001374/* Flow steering rule priority is set according to it's domain.
1375 * Lower domain value means higher priority.
1376 */
1377enum ib_flow_domain {
1378 IB_FLOW_DOMAIN_USER,
1379 IB_FLOW_DOMAIN_ETHTOOL,
1380 IB_FLOW_DOMAIN_RFS,
1381 IB_FLOW_DOMAIN_NIC,
1382 IB_FLOW_DOMAIN_NUM /* Must be last */
1383};
1384
1385struct ib_flow_eth_filter {
1386 u8 dst_mac[6];
1387 u8 src_mac[6];
1388 __be16 ether_type;
1389 __be16 vlan_tag;
1390};
1391
1392struct ib_flow_spec_eth {
1393 enum ib_flow_spec_type type;
1394 u16 size;
1395 struct ib_flow_eth_filter val;
1396 struct ib_flow_eth_filter mask;
1397};
1398
Matan Barak240ae002013-11-07 15:25:13 +02001399struct ib_flow_ib_filter {
1400 __be16 dlid;
1401 __u8 sl;
1402};
1403
1404struct ib_flow_spec_ib {
1405 enum ib_flow_spec_type type;
1406 u16 size;
1407 struct ib_flow_ib_filter val;
1408 struct ib_flow_ib_filter mask;
1409};
1410
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001411struct ib_flow_ipv4_filter {
1412 __be32 src_ip;
1413 __be32 dst_ip;
1414};
1415
1416struct ib_flow_spec_ipv4 {
1417 enum ib_flow_spec_type type;
1418 u16 size;
1419 struct ib_flow_ipv4_filter val;
1420 struct ib_flow_ipv4_filter mask;
1421};
1422
1423struct ib_flow_tcp_udp_filter {
1424 __be16 dst_port;
1425 __be16 src_port;
1426};
1427
1428struct ib_flow_spec_tcp_udp {
1429 enum ib_flow_spec_type type;
1430 u16 size;
1431 struct ib_flow_tcp_udp_filter val;
1432 struct ib_flow_tcp_udp_filter mask;
1433};
1434
1435union ib_flow_spec {
1436 struct {
1437 enum ib_flow_spec_type type;
1438 u16 size;
1439 };
1440 struct ib_flow_spec_eth eth;
Matan Barak240ae002013-11-07 15:25:13 +02001441 struct ib_flow_spec_ib ib;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001442 struct ib_flow_spec_ipv4 ipv4;
1443 struct ib_flow_spec_tcp_udp tcp_udp;
1444};
1445
1446struct ib_flow_attr {
1447 enum ib_flow_attr_type type;
1448 u16 size;
1449 u16 priority;
1450 u32 flags;
1451 u8 num_of_specs;
1452 u8 port;
1453 /* Following are the optional layers according to user request
1454 * struct ib_flow_spec_xxx
1455 * struct ib_flow_spec_yyy
1456 */
1457};
1458
1459struct ib_flow {
1460 struct ib_qp *qp;
1461 struct ib_uobject *uobject;
1462};
1463
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464struct ib_mad;
1465struct ib_grh;
1466
1467enum ib_process_mad_flags {
1468 IB_MAD_IGNORE_MKEY = 1,
1469 IB_MAD_IGNORE_BKEY = 2,
1470 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1471};
1472
1473enum ib_mad_result {
1474 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
1475 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
1476 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
1477 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
1478};
1479
1480#define IB_DEVICE_NAME_MAX 64
1481
1482struct ib_cache {
1483 rwlock_t lock;
1484 struct ib_event_handler event_handler;
1485 struct ib_pkey_cache **pkey_cache;
1486 struct ib_gid_cache **gid_cache;
Jack Morgenstein6fb9cdb2006-06-17 20:37:34 -07001487 u8 *lmc_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488};
1489
Ralph Campbell9b513092006-12-12 14:27:41 -08001490struct ib_dma_mapping_ops {
1491 int (*mapping_error)(struct ib_device *dev,
1492 u64 dma_addr);
1493 u64 (*map_single)(struct ib_device *dev,
1494 void *ptr, size_t size,
1495 enum dma_data_direction direction);
1496 void (*unmap_single)(struct ib_device *dev,
1497 u64 addr, size_t size,
1498 enum dma_data_direction direction);
1499 u64 (*map_page)(struct ib_device *dev,
1500 struct page *page, unsigned long offset,
1501 size_t size,
1502 enum dma_data_direction direction);
1503 void (*unmap_page)(struct ib_device *dev,
1504 u64 addr, size_t size,
1505 enum dma_data_direction direction);
1506 int (*map_sg)(struct ib_device *dev,
1507 struct scatterlist *sg, int nents,
1508 enum dma_data_direction direction);
1509 void (*unmap_sg)(struct ib_device *dev,
1510 struct scatterlist *sg, int nents,
1511 enum dma_data_direction direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001512 void (*sync_single_for_cpu)(struct ib_device *dev,
1513 u64 dma_handle,
1514 size_t size,
Dotan Barak4deccd62008-07-14 23:48:44 -07001515 enum dma_data_direction dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08001516 void (*sync_single_for_device)(struct ib_device *dev,
1517 u64 dma_handle,
1518 size_t size,
1519 enum dma_data_direction dir);
1520 void *(*alloc_coherent)(struct ib_device *dev,
1521 size_t size,
1522 u64 *dma_handle,
1523 gfp_t flag);
1524 void (*free_coherent)(struct ib_device *dev,
1525 size_t size, void *cpu_addr,
1526 u64 dma_handle);
1527};
1528
Tom Tucker07ebafb2006-08-03 16:02:42 -05001529struct iw_cm_verbs;
1530
Ira Weiny77386132015-05-13 20:02:58 -04001531struct ib_port_immutable {
1532 int pkey_tbl_len;
1533 int gid_tbl_len;
Ira Weinyf9b22e32015-05-13 20:02:59 -04001534 u32 core_cap_flags;
Ira Weiny77386132015-05-13 20:02:58 -04001535};
1536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537struct ib_device {
1538 struct device *dma_device;
1539
1540 char name[IB_DEVICE_NAME_MAX];
1541
1542 struct list_head event_handler_list;
1543 spinlock_t event_handler_lock;
1544
Alexander Chiang17a55f72010-02-02 19:09:16 +00001545 spinlock_t client_data_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 struct list_head core_list;
1547 struct list_head client_data_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 struct ib_cache cache;
Ira Weiny77386132015-05-13 20:02:58 -04001550 /**
1551 * port_immutable is indexed by port number
1552 */
1553 struct ib_port_immutable *port_immutable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001555 int num_comp_vectors;
1556
Tom Tucker07ebafb2006-08-03 16:02:42 -05001557 struct iw_cm_verbs *iwcm;
1558
Steve Wise7f624d02008-07-14 23:48:48 -07001559 int (*get_protocol_stats)(struct ib_device *device,
1560 union rdma_protocol_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 int (*query_device)(struct ib_device *device,
1562 struct ib_device_attr *device_attr);
1563 int (*query_port)(struct ib_device *device,
1564 u8 port_num,
1565 struct ib_port_attr *port_attr);
Eli Cohena3f5ada2010-09-27 17:51:10 -07001566 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1567 u8 port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 int (*query_gid)(struct ib_device *device,
1569 u8 port_num, int index,
1570 union ib_gid *gid);
1571 int (*query_pkey)(struct ib_device *device,
1572 u8 port_num, u16 index, u16 *pkey);
1573 int (*modify_device)(struct ib_device *device,
1574 int device_modify_mask,
1575 struct ib_device_modify *device_modify);
1576 int (*modify_port)(struct ib_device *device,
1577 u8 port_num, int port_modify_mask,
1578 struct ib_port_modify *port_modify);
Roland Dreiere2773c02005-07-07 17:57:10 -07001579 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1580 struct ib_udata *udata);
1581 int (*dealloc_ucontext)(struct ib_ucontext *context);
1582 int (*mmap)(struct ib_ucontext *context,
1583 struct vm_area_struct *vma);
1584 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1585 struct ib_ucontext *context,
1586 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 int (*dealloc_pd)(struct ib_pd *pd);
1588 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1589 struct ib_ah_attr *ah_attr);
1590 int (*modify_ah)(struct ib_ah *ah,
1591 struct ib_ah_attr *ah_attr);
1592 int (*query_ah)(struct ib_ah *ah,
1593 struct ib_ah_attr *ah_attr);
1594 int (*destroy_ah)(struct ib_ah *ah);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001595 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1596 struct ib_srq_init_attr *srq_init_attr,
1597 struct ib_udata *udata);
1598 int (*modify_srq)(struct ib_srq *srq,
1599 struct ib_srq_attr *srq_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001600 enum ib_srq_attr_mask srq_attr_mask,
1601 struct ib_udata *udata);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001602 int (*query_srq)(struct ib_srq *srq,
1603 struct ib_srq_attr *srq_attr);
1604 int (*destroy_srq)(struct ib_srq *srq);
1605 int (*post_srq_recv)(struct ib_srq *srq,
1606 struct ib_recv_wr *recv_wr,
1607 struct ib_recv_wr **bad_recv_wr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 struct ib_qp * (*create_qp)(struct ib_pd *pd,
Roland Dreiere2773c02005-07-07 17:57:10 -07001609 struct ib_qp_init_attr *qp_init_attr,
1610 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 int (*modify_qp)(struct ib_qp *qp,
1612 struct ib_qp_attr *qp_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001613 int qp_attr_mask,
1614 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 int (*query_qp)(struct ib_qp *qp,
1616 struct ib_qp_attr *qp_attr,
1617 int qp_attr_mask,
1618 struct ib_qp_init_attr *qp_init_attr);
1619 int (*destroy_qp)(struct ib_qp *qp);
1620 int (*post_send)(struct ib_qp *qp,
1621 struct ib_send_wr *send_wr,
1622 struct ib_send_wr **bad_send_wr);
1623 int (*post_recv)(struct ib_qp *qp,
1624 struct ib_recv_wr *recv_wr,
1625 struct ib_recv_wr **bad_recv_wr);
Matan Barakbcf4c1e2015-06-11 16:35:20 +03001626 struct ib_cq * (*create_cq)(struct ib_device *device,
1627 const struct ib_cq_init_attr *attr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001628 struct ib_ucontext *context,
1629 struct ib_udata *udata);
Eli Cohen2dd57162008-04-16 21:09:33 -07001630 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1631 u16 cq_period);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 int (*destroy_cq)(struct ib_cq *cq);
Roland Dreier33b9b3e2006-01-30 14:29:21 -08001633 int (*resize_cq)(struct ib_cq *cq, int cqe,
1634 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1636 struct ib_wc *wc);
1637 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1638 int (*req_notify_cq)(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001639 enum ib_cq_notify_flags flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 int (*req_ncomp_notif)(struct ib_cq *cq,
1641 int wc_cnt);
1642 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1643 int mr_access_flags);
1644 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
1645 struct ib_phys_buf *phys_buf_array,
1646 int num_phys_buf,
1647 int mr_access_flags,
1648 u64 *iova_start);
Roland Dreiere2773c02005-07-07 17:57:10 -07001649 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001650 u64 start, u64 length,
1651 u64 virt_addr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001652 int mr_access_flags,
1653 struct ib_udata *udata);
Matan Barak7e6edb92014-07-31 11:01:28 +03001654 int (*rereg_user_mr)(struct ib_mr *mr,
1655 int flags,
1656 u64 start, u64 length,
1657 u64 virt_addr,
1658 int mr_access_flags,
1659 struct ib_pd *pd,
1660 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 int (*query_mr)(struct ib_mr *mr,
1662 struct ib_mr_attr *mr_attr);
1663 int (*dereg_mr)(struct ib_mr *mr);
Sagi Grimberg17cd3a22014-02-23 14:19:04 +02001664 int (*destroy_mr)(struct ib_mr *mr);
1665 struct ib_mr * (*create_mr)(struct ib_pd *pd,
1666 struct ib_mr_init_attr *mr_init_attr);
Steve Wise00f7ec32008-07-14 23:48:45 -07001667 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
1668 int max_page_list_len);
1669 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1670 int page_list_len);
1671 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 int (*rereg_phys_mr)(struct ib_mr *mr,
1673 int mr_rereg_mask,
1674 struct ib_pd *pd,
1675 struct ib_phys_buf *phys_buf_array,
1676 int num_phys_buf,
1677 int mr_access_flags,
1678 u64 *iova_start);
Shani Michaeli7083e422013-02-06 16:19:12 +00001679 struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
1680 enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 int (*bind_mw)(struct ib_qp *qp,
1682 struct ib_mw *mw,
1683 struct ib_mw_bind *mw_bind);
1684 int (*dealloc_mw)(struct ib_mw *mw);
1685 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1686 int mr_access_flags,
1687 struct ib_fmr_attr *fmr_attr);
1688 int (*map_phys_fmr)(struct ib_fmr *fmr,
1689 u64 *page_list, int list_len,
1690 u64 iova);
1691 int (*unmap_fmr)(struct list_head *fmr_list);
1692 int (*dealloc_fmr)(struct ib_fmr *fmr);
1693 int (*attach_mcast)(struct ib_qp *qp,
1694 union ib_gid *gid,
1695 u16 lid);
1696 int (*detach_mcast)(struct ib_qp *qp,
1697 union ib_gid *gid,
1698 u16 lid);
1699 int (*process_mad)(struct ib_device *device,
1700 int process_mad_flags,
1701 u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -04001702 const struct ib_wc *in_wc,
1703 const struct ib_grh *in_grh,
1704 const struct ib_mad *in_mad,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 struct ib_mad *out_mad);
Sean Hefty59991f92011-05-23 17:52:46 -07001706 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1707 struct ib_ucontext *ucontext,
1708 struct ib_udata *udata);
1709 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001710 struct ib_flow * (*create_flow)(struct ib_qp *qp,
1711 struct ib_flow_attr
1712 *flow_attr,
1713 int domain);
1714 int (*destroy_flow)(struct ib_flow *flow_id);
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001715 int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
1716 struct ib_mr_status *mr_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Ralph Campbell9b513092006-12-12 14:27:41 -08001718 struct ib_dma_mapping_ops *dma_ops;
1719
Roland Dreiere2773c02005-07-07 17:57:10 -07001720 struct module *owner;
Tony Jonesf4e91eb2008-02-22 00:13:36 +01001721 struct device dev;
Greg Kroah-Hartman35be0682007-12-17 15:54:39 -04001722 struct kobject *ports_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 struct list_head port_list;
1724
1725 enum {
1726 IB_DEV_UNINITIALIZED,
1727 IB_DEV_REGISTERED,
1728 IB_DEV_UNREGISTERED
1729 } reg_state;
1730
Roland Dreier274c0892005-09-29 14:17:48 -07001731 int uverbs_abi_ver;
Alexander Chiang17a55f72010-02-02 19:09:16 +00001732 u64 uverbs_cmd_mask;
Yann Droneaudf21519b2013-11-06 23:21:49 +01001733 u64 uverbs_ex_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07001734
Roland Dreierc5bcbbb2006-02-02 09:47:14 -08001735 char node_desc[64];
Sean Heftycf311cd2006-01-10 07:39:34 -08001736 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07001737 u32 local_dma_lkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 u8 node_type;
1739 u8 phys_port_cnt;
Ira Weiny77386132015-05-13 20:02:58 -04001740
1741 /**
1742 * The following mandatory functions are used only at device
1743 * registration. Keep functions such as these at the end of this
1744 * structure to avoid cache line misses when accessing struct ib_device
1745 * in fast paths.
1746 */
1747 int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748};
1749
1750struct ib_client {
1751 char *name;
1752 void (*add) (struct ib_device *);
1753 void (*remove)(struct ib_device *);
1754
1755 struct list_head list;
1756};
1757
1758struct ib_device *ib_alloc_device(size_t size);
1759void ib_dealloc_device(struct ib_device *device);
1760
Ralph Campbell9a6edb62010-05-06 17:03:25 -07001761int ib_register_device(struct ib_device *device,
1762 int (*port_callback)(struct ib_device *,
1763 u8, struct kobject *));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764void ib_unregister_device(struct ib_device *device);
1765
1766int ib_register_client (struct ib_client *client);
1767void ib_unregister_client(struct ib_client *client);
1768
1769void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1770void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1771 void *data);
1772
Roland Dreiere2773c02005-07-07 17:57:10 -07001773static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1774{
1775 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1776}
1777
1778static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1779{
Yann Droneaud43c611652015-02-05 22:10:18 +01001780 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
Roland Dreiere2773c02005-07-07 17:57:10 -07001781}
1782
Roland Dreier8a518662006-02-13 12:48:12 -08001783/**
1784 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1785 * contains all required attributes and no attributes not allowed for
1786 * the given QP state transition.
1787 * @cur_state: Current QP state
1788 * @next_state: Next QP state
1789 * @type: QP type
1790 * @mask: Mask of supplied QP attributes
Matan Barakdd5f03b2013-12-12 18:03:11 +02001791 * @ll : link layer of port
Roland Dreier8a518662006-02-13 12:48:12 -08001792 *
1793 * This function is a helper function that a low-level driver's
1794 * modify_qp method can use to validate the consumer's input. It
1795 * checks that cur_state and next_state are valid QP states, that a
1796 * transition from cur_state to next_state is allowed by the IB spec,
1797 * and that the attribute mask supplied is allowed for the transition.
1798 */
1799int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
Matan Barakdd5f03b2013-12-12 18:03:11 +02001800 enum ib_qp_type type, enum ib_qp_attr_mask mask,
1801 enum rdma_link_layer ll);
Roland Dreier8a518662006-02-13 12:48:12 -08001802
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803int ib_register_event_handler (struct ib_event_handler *event_handler);
1804int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1805void ib_dispatch_event(struct ib_event *event);
1806
1807int ib_query_device(struct ib_device *device,
1808 struct ib_device_attr *device_attr);
1809
1810int ib_query_port(struct ib_device *device,
1811 u8 port_num, struct ib_port_attr *port_attr);
1812
Eli Cohena3f5ada2010-09-27 17:51:10 -07001813enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1814 u8 port_num);
1815
Ira Weiny0cf18d72015-05-13 20:02:55 -04001816/**
1817 * rdma_start_port - Return the first valid port number for the device
1818 * specified
1819 *
1820 * @device: Device to be checked
1821 *
1822 * Return start port number
1823 */
1824static inline u8 rdma_start_port(const struct ib_device *device)
1825{
1826 return (device->node_type == RDMA_NODE_IB_SWITCH) ? 0 : 1;
1827}
1828
1829/**
1830 * rdma_end_port - Return the last valid port number for the device
1831 * specified
1832 *
1833 * @device: Device to be checked
1834 *
1835 * Return last port number
1836 */
1837static inline u8 rdma_end_port(const struct ib_device *device)
1838{
1839 return (device->node_type == RDMA_NODE_IB_SWITCH) ?
1840 0 : device->phys_port_cnt;
1841}
1842
Ira Weiny5ede9282015-05-31 17:15:29 -04001843static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02001844{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001845 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
Michael Wangde66be92015-05-05 14:50:19 +02001846}
1847
Ira Weiny5ede9282015-05-31 17:15:29 -04001848static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02001849{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001850 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
Michael Wangde66be92015-05-05 14:50:19 +02001851}
1852
Ira Weiny5ede9282015-05-31 17:15:29 -04001853static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02001854{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001855 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
Michael Wangde66be92015-05-05 14:50:19 +02001856}
1857
Ira Weiny5ede9282015-05-31 17:15:29 -04001858static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02001859{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001860 return device->port_immutable[port_num].core_cap_flags &
1861 (RDMA_CORE_CAP_PROT_IB | RDMA_CORE_CAP_PROT_ROCE);
Michael Wangde66be92015-05-05 14:50:19 +02001862}
1863
Michael Wangc757dea2015-05-05 14:50:32 +02001864/**
Michael Wang296ec002015-05-18 10:41:45 +02001865 * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
Michael Wangc757dea2015-05-05 14:50:32 +02001866 * Management Datagrams.
Michael Wang296ec002015-05-18 10:41:45 +02001867 * @device: Device to check
1868 * @port_num: Port number to check
Michael Wangc757dea2015-05-05 14:50:32 +02001869 *
Michael Wang296ec002015-05-18 10:41:45 +02001870 * Management Datagrams (MAD) are a required part of the InfiniBand
1871 * specification and are supported on all InfiniBand devices. A slightly
1872 * extended version are also supported on OPA interfaces.
Michael Wangc757dea2015-05-05 14:50:32 +02001873 *
Michael Wang296ec002015-05-18 10:41:45 +02001874 * Return: true if the port supports sending/receiving of MAD packets.
Michael Wangc757dea2015-05-05 14:50:32 +02001875 */
Ira Weiny5ede9282015-05-31 17:15:29 -04001876static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
Michael Wangc757dea2015-05-05 14:50:32 +02001877{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001878 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
Michael Wangc757dea2015-05-05 14:50:32 +02001879}
1880
Michael Wang29541e32015-05-05 14:50:33 +02001881/**
Michael Wang296ec002015-05-18 10:41:45 +02001882 * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
1883 * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
1884 * @device: Device to check
1885 * @port_num: Port number to check
Michael Wang29541e32015-05-05 14:50:33 +02001886 *
Michael Wang296ec002015-05-18 10:41:45 +02001887 * Each InfiniBand node is required to provide a Subnet Management Agent
1888 * that the subnet manager can access. Prior to the fabric being fully
1889 * configured by the subnet manager, the SMA is accessed via a well known
1890 * interface called the Subnet Management Interface (SMI). This interface
1891 * uses directed route packets to communicate with the SM to get around the
1892 * chicken and egg problem of the SM needing to know what's on the fabric
1893 * in order to configure the fabric, and needing to configure the fabric in
1894 * order to send packets to the devices on the fabric. These directed
1895 * route packets do not need the fabric fully configured in order to reach
1896 * their destination. The SMI is the only method allowed to send
1897 * directed route packets on an InfiniBand fabric.
Michael Wang29541e32015-05-05 14:50:33 +02001898 *
Michael Wang296ec002015-05-18 10:41:45 +02001899 * Return: true if the port provides an SMI.
Michael Wang29541e32015-05-05 14:50:33 +02001900 */
Ira Weiny5ede9282015-05-31 17:15:29 -04001901static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
Michael Wang29541e32015-05-05 14:50:33 +02001902{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001903 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
Michael Wang29541e32015-05-05 14:50:33 +02001904}
1905
Michael Wang72219cea2015-05-05 14:50:34 +02001906/**
1907 * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
1908 * Communication Manager.
Michael Wang296ec002015-05-18 10:41:45 +02001909 * @device: Device to check
1910 * @port_num: Port number to check
Michael Wang72219cea2015-05-05 14:50:34 +02001911 *
Michael Wang296ec002015-05-18 10:41:45 +02001912 * The InfiniBand Communication Manager is one of many pre-defined General
1913 * Service Agents (GSA) that are accessed via the General Service
1914 * Interface (GSI). It's role is to facilitate establishment of connections
1915 * between nodes as well as other management related tasks for established
1916 * connections.
Michael Wang72219cea2015-05-05 14:50:34 +02001917 *
Michael Wang296ec002015-05-18 10:41:45 +02001918 * Return: true if the port supports an IB CM (this does not guarantee that
1919 * a CM is actually running however).
Michael Wang72219cea2015-05-05 14:50:34 +02001920 */
Ira Weiny5ede9282015-05-31 17:15:29 -04001921static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
Michael Wang72219cea2015-05-05 14:50:34 +02001922{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001923 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
Michael Wang72219cea2015-05-05 14:50:34 +02001924}
1925
Michael Wang04215332015-05-05 14:50:35 +02001926/**
1927 * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
1928 * Communication Manager.
Michael Wang296ec002015-05-18 10:41:45 +02001929 * @device: Device to check
1930 * @port_num: Port number to check
Michael Wang04215332015-05-05 14:50:35 +02001931 *
Michael Wang296ec002015-05-18 10:41:45 +02001932 * Similar to above, but specific to iWARP connections which have a different
1933 * managment protocol than InfiniBand.
Michael Wang04215332015-05-05 14:50:35 +02001934 *
Michael Wang296ec002015-05-18 10:41:45 +02001935 * Return: true if the port supports an iWARP CM (this does not guarantee that
1936 * a CM is actually running however).
Michael Wang04215332015-05-05 14:50:35 +02001937 */
Ira Weiny5ede9282015-05-31 17:15:29 -04001938static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
Michael Wang04215332015-05-05 14:50:35 +02001939{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001940 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
Michael Wang04215332015-05-05 14:50:35 +02001941}
1942
Michael Wangfe53ba22015-05-05 14:50:36 +02001943/**
1944 * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
1945 * Subnet Administration.
Michael Wang296ec002015-05-18 10:41:45 +02001946 * @device: Device to check
1947 * @port_num: Port number to check
Michael Wangfe53ba22015-05-05 14:50:36 +02001948 *
Michael Wang296ec002015-05-18 10:41:45 +02001949 * An InfiniBand Subnet Administration (SA) service is a pre-defined General
1950 * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
1951 * fabrics, devices should resolve routes to other hosts by contacting the
1952 * SA to query the proper route.
Michael Wangfe53ba22015-05-05 14:50:36 +02001953 *
Michael Wang296ec002015-05-18 10:41:45 +02001954 * Return: true if the port should act as a client to the fabric Subnet
1955 * Administration interface. This does not imply that the SA service is
1956 * running locally.
Michael Wangfe53ba22015-05-05 14:50:36 +02001957 */
Ira Weiny5ede9282015-05-31 17:15:29 -04001958static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
Michael Wangfe53ba22015-05-05 14:50:36 +02001959{
Ira Weinyf9b22e32015-05-13 20:02:59 -04001960 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
Michael Wangfe53ba22015-05-05 14:50:36 +02001961}
1962
Michael Wanga31ad3b2015-05-05 14:50:37 +02001963/**
1964 * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
1965 * Multicast.
Michael Wang296ec002015-05-18 10:41:45 +02001966 * @device: Device to check
1967 * @port_num: Port number to check
Michael Wanga31ad3b2015-05-05 14:50:37 +02001968 *
Michael Wang296ec002015-05-18 10:41:45 +02001969 * InfiniBand multicast registration is more complex than normal IPv4 or
1970 * IPv6 multicast registration. Each Host Channel Adapter must register
1971 * with the Subnet Manager when it wishes to join a multicast group. It
1972 * should do so only once regardless of how many queue pairs it subscribes
1973 * to this group. And it should leave the group only after all queue pairs
1974 * attached to the group have been detached.
Michael Wanga31ad3b2015-05-05 14:50:37 +02001975 *
Michael Wang296ec002015-05-18 10:41:45 +02001976 * Return: true if the port must undertake the additional adminstrative
1977 * overhead of registering/unregistering with the SM and tracking of the
1978 * total number of queue pairs attached to the multicast group.
Michael Wanga31ad3b2015-05-05 14:50:37 +02001979 */
Ira Weiny5ede9282015-05-31 17:15:29 -04001980static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
Michael Wanga31ad3b2015-05-05 14:50:37 +02001981{
1982 return rdma_cap_ib_sa(device, port_num);
1983}
1984
Michael Wangbc0f1d72015-05-05 14:50:38 +02001985/**
Michael Wang30a74ef2015-05-05 14:50:39 +02001986 * rdma_cap_af_ib - Check if the port of device has the capability
1987 * Native Infiniband Address.
Michael Wang296ec002015-05-18 10:41:45 +02001988 * @device: Device to check
1989 * @port_num: Port number to check
Michael Wang30a74ef2015-05-05 14:50:39 +02001990 *
Michael Wang296ec002015-05-18 10:41:45 +02001991 * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
1992 * GID. RoCE uses a different mechanism, but still generates a GID via
1993 * a prescribed mechanism and port specific data.
Michael Wang30a74ef2015-05-05 14:50:39 +02001994 *
Michael Wang296ec002015-05-18 10:41:45 +02001995 * Return: true if the port uses a GID address to identify devices on the
1996 * network.
Michael Wang30a74ef2015-05-05 14:50:39 +02001997 */
Ira Weiny5ede9282015-05-31 17:15:29 -04001998static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
Michael Wang30a74ef2015-05-05 14:50:39 +02001999{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002000 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
Michael Wang30a74ef2015-05-05 14:50:39 +02002001}
2002
2003/**
Michael Wang227128f2015-05-05 14:50:40 +02002004 * rdma_cap_eth_ah - Check if the port of device has the capability
Michael Wang296ec002015-05-18 10:41:45 +02002005 * Ethernet Address Handle.
2006 * @device: Device to check
2007 * @port_num: Port number to check
Michael Wang227128f2015-05-05 14:50:40 +02002008 *
Michael Wang296ec002015-05-18 10:41:45 +02002009 * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
2010 * to fabricate GIDs over Ethernet/IP specific addresses native to the
2011 * port. Normally, packet headers are generated by the sending host
2012 * adapter, but when sending connectionless datagrams, we must manually
2013 * inject the proper headers for the fabric we are communicating over.
Michael Wang227128f2015-05-05 14:50:40 +02002014 *
Michael Wang296ec002015-05-18 10:41:45 +02002015 * Return: true if we are running as a RoCE port and must force the
2016 * addition of a Global Route Header built from our Ethernet Address
2017 * Handle into our header list for connectionless packets.
Michael Wang227128f2015-05-05 14:50:40 +02002018 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002019static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
Michael Wang227128f2015-05-05 14:50:40 +02002020{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002021 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
Michael Wang227128f2015-05-05 14:50:40 +02002022}
2023
2024/**
Michael Wangbc0f1d72015-05-05 14:50:38 +02002025 * rdma_cap_read_multi_sge - Check if the port of device has the capability
2026 * RDMA Read Multiple Scatter-Gather Entries.
Michael Wang296ec002015-05-18 10:41:45 +02002027 * @device: Device to check
2028 * @port_num: Port number to check
Michael Wangbc0f1d72015-05-05 14:50:38 +02002029 *
Michael Wang296ec002015-05-18 10:41:45 +02002030 * iWARP has a restriction that RDMA READ requests may only have a single
2031 * Scatter/Gather Entry (SGE) in the work request.
Michael Wangbc0f1d72015-05-05 14:50:38 +02002032 *
Michael Wang296ec002015-05-18 10:41:45 +02002033 * NOTE: although the linux kernel currently assumes all devices are either
2034 * single SGE RDMA READ devices or identical SGE maximums for RDMA READs and
2035 * WRITEs, according to Tom Talpey, this is not accurate. There are some
2036 * devices out there that support more than a single SGE on RDMA READ
2037 * requests, but do not support the same number of SGEs as they do on
2038 * RDMA WRITE requests. The linux kernel would need rearchitecting to
2039 * support these imbalanced READ/WRITE SGEs allowed devices. So, for now,
2040 * suffice with either the device supports the same READ/WRITE SGEs, or
2041 * it only gets one READ sge.
2042 *
2043 * Return: true for any device that allows more than one SGE in RDMA READ
2044 * requests.
Michael Wangbc0f1d72015-05-05 14:50:38 +02002045 */
2046static inline bool rdma_cap_read_multi_sge(struct ib_device *device,
2047 u8 port_num)
2048{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002049 return !(device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP);
Michael Wangbc0f1d72015-05-05 14:50:38 +02002050}
2051
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052int ib_query_gid(struct ib_device *device,
2053 u8 port_num, int index, union ib_gid *gid);
2054
2055int ib_query_pkey(struct ib_device *device,
2056 u8 port_num, u16 index, u16 *pkey);
2057
2058int ib_modify_device(struct ib_device *device,
2059 int device_modify_mask,
2060 struct ib_device_modify *device_modify);
2061
2062int ib_modify_port(struct ib_device *device,
2063 u8 port_num, int port_modify_mask,
2064 struct ib_port_modify *port_modify);
2065
Yosef Etigin5eb620c2007-05-14 07:26:51 +03002066int ib_find_gid(struct ib_device *device, union ib_gid *gid,
2067 u8 *port_num, u16 *index);
2068
2069int ib_find_pkey(struct ib_device *device,
2070 u8 port_num, u16 pkey, u16 *index);
2071
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072/**
2073 * ib_alloc_pd - Allocates an unused protection domain.
2074 * @device: The device on which to allocate the protection domain.
2075 *
2076 * A protection domain object provides an association between QPs, shared
2077 * receive queues, address handles, memory regions, and memory windows.
2078 */
2079struct ib_pd *ib_alloc_pd(struct ib_device *device);
2080
2081/**
2082 * ib_dealloc_pd - Deallocates a protection domain.
2083 * @pd: The protection domain to deallocate.
2084 */
2085int ib_dealloc_pd(struct ib_pd *pd);
2086
2087/**
2088 * ib_create_ah - Creates an address handle for the given address vector.
2089 * @pd: The protection domain associated with the address handle.
2090 * @ah_attr: The attributes of the address vector.
2091 *
2092 * The address handle is used to reference a local or global destination
2093 * in all UD QP post sends.
2094 */
2095struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
2096
2097/**
Sean Hefty4e00d692006-06-17 20:37:39 -07002098 * ib_init_ah_from_wc - Initializes address handle attributes from a
2099 * work completion.
2100 * @device: Device on which the received message arrived.
2101 * @port_num: Port on which the received message arrived.
2102 * @wc: Work completion associated with the 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 * @ah_attr: Returned attributes that can be used when creating an address
2106 * handle for replying to the message.
2107 */
Ira Weiny73cdaae2015-05-31 17:15:31 -04002108int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
2109 const struct ib_wc *wc, const struct ib_grh *grh,
2110 struct ib_ah_attr *ah_attr);
Sean Hefty4e00d692006-06-17 20:37:39 -07002111
2112/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07002113 * ib_create_ah_from_wc - Creates an address handle associated with the
2114 * sender of the specified work completion.
2115 * @pd: The protection domain associated with the address handle.
2116 * @wc: Work completion information associated with a received message.
2117 * @grh: References the received global route header. This parameter is
2118 * ignored unless the work completion indicates that the GRH is valid.
2119 * @port_num: The outbound port number to associate with the address.
2120 *
2121 * The address handle is used to reference a local or global destination
2122 * in all UD QP post sends.
2123 */
Ira Weiny73cdaae2015-05-31 17:15:31 -04002124struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
2125 const struct ib_grh *grh, u8 port_num);
Hal Rosenstock513789e2005-07-27 11:45:34 -07002126
2127/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 * ib_modify_ah - Modifies the address vector associated with an address
2129 * handle.
2130 * @ah: The address handle to modify.
2131 * @ah_attr: The new address vector attributes to associate with the
2132 * address handle.
2133 */
2134int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2135
2136/**
2137 * ib_query_ah - Queries the address vector associated with an address
2138 * handle.
2139 * @ah: The address handle to query.
2140 * @ah_attr: The address vector attributes associated with the address
2141 * handle.
2142 */
2143int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2144
2145/**
2146 * ib_destroy_ah - Destroys an address handle.
2147 * @ah: The address handle to destroy.
2148 */
2149int ib_destroy_ah(struct ib_ah *ah);
2150
2151/**
Roland Dreierd41fcc62005-08-18 12:23:08 -07002152 * ib_create_srq - Creates a SRQ associated with the specified protection
2153 * domain.
2154 * @pd: The protection domain associated with the SRQ.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08002155 * @srq_init_attr: A list of initial attributes required to create the
2156 * SRQ. If SRQ creation succeeds, then the attributes are updated to
2157 * the actual capabilities of the created SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07002158 *
2159 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
2160 * requested size of the SRQ, and set to the actual values allocated
2161 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
2162 * will always be at least as large as the requested values.
2163 */
2164struct ib_srq *ib_create_srq(struct ib_pd *pd,
2165 struct ib_srq_init_attr *srq_init_attr);
2166
2167/**
2168 * ib_modify_srq - Modifies the attributes for the specified SRQ.
2169 * @srq: The SRQ to modify.
2170 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
2171 * the current values of selected SRQ attributes are returned.
2172 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
2173 * are being modified.
2174 *
2175 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
2176 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
2177 * the number of receives queued drops below the limit.
2178 */
2179int ib_modify_srq(struct ib_srq *srq,
2180 struct ib_srq_attr *srq_attr,
2181 enum ib_srq_attr_mask srq_attr_mask);
2182
2183/**
2184 * ib_query_srq - Returns the attribute list and current values for the
2185 * specified SRQ.
2186 * @srq: The SRQ to query.
2187 * @srq_attr: The attributes of the specified SRQ.
2188 */
2189int ib_query_srq(struct ib_srq *srq,
2190 struct ib_srq_attr *srq_attr);
2191
2192/**
2193 * ib_destroy_srq - Destroys the specified SRQ.
2194 * @srq: The SRQ to destroy.
2195 */
2196int ib_destroy_srq(struct ib_srq *srq);
2197
2198/**
2199 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
2200 * @srq: The SRQ to post the work request on.
2201 * @recv_wr: A list of work requests to post on the receive queue.
2202 * @bad_recv_wr: On an immediate failure, this parameter will reference
2203 * the work request that failed to be posted on the QP.
2204 */
2205static inline int ib_post_srq_recv(struct ib_srq *srq,
2206 struct ib_recv_wr *recv_wr,
2207 struct ib_recv_wr **bad_recv_wr)
2208{
2209 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
2210}
2211
2212/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 * ib_create_qp - Creates a QP associated with the specified protection
2214 * domain.
2215 * @pd: The protection domain associated with the QP.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08002216 * @qp_init_attr: A list of initial attributes required to create the
2217 * QP. If QP creation succeeds, then the attributes are updated to
2218 * the actual capabilities of the created QP.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 */
2220struct ib_qp *ib_create_qp(struct ib_pd *pd,
2221 struct ib_qp_init_attr *qp_init_attr);
2222
2223/**
2224 * ib_modify_qp - Modifies the attributes for the specified QP and then
2225 * transitions the QP to the given state.
2226 * @qp: The QP to modify.
2227 * @qp_attr: On input, specifies the QP attributes to modify. On output,
2228 * the current values of selected QP attributes are returned.
2229 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
2230 * are being modified.
2231 */
2232int ib_modify_qp(struct ib_qp *qp,
2233 struct ib_qp_attr *qp_attr,
2234 int qp_attr_mask);
2235
2236/**
2237 * ib_query_qp - Returns the attribute list and current values for the
2238 * specified QP.
2239 * @qp: The QP to query.
2240 * @qp_attr: The attributes of the specified QP.
2241 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
2242 * @qp_init_attr: Additional attributes of the selected QP.
2243 *
2244 * The qp_attr_mask may be used to limit the query to gathering only the
2245 * selected attributes.
2246 */
2247int ib_query_qp(struct ib_qp *qp,
2248 struct ib_qp_attr *qp_attr,
2249 int qp_attr_mask,
2250 struct ib_qp_init_attr *qp_init_attr);
2251
2252/**
2253 * ib_destroy_qp - Destroys the specified QP.
2254 * @qp: The QP to destroy.
2255 */
2256int ib_destroy_qp(struct ib_qp *qp);
2257
2258/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002259 * ib_open_qp - Obtain a reference to an existing sharable QP.
2260 * @xrcd - XRC domain
2261 * @qp_open_attr: Attributes identifying the QP to open.
2262 *
2263 * Returns a reference to a sharable QP.
2264 */
2265struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
2266 struct ib_qp_open_attr *qp_open_attr);
2267
2268/**
2269 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07002270 * @qp: The QP handle to release
2271 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002272 * The opened QP handle is released by the caller. The underlying
2273 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07002274 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002275int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07002276
2277/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 * ib_post_send - Posts a list of work requests to the send queue of
2279 * the specified QP.
2280 * @qp: The QP to post the work request on.
2281 * @send_wr: A list of work requests to post on the send queue.
2282 * @bad_send_wr: On an immediate failure, this parameter will reference
2283 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08002284 *
2285 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
2286 * error is returned, the QP state shall not be affected,
2287 * ib_post_send() will return an immediate error after queueing any
2288 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 */
2290static inline int ib_post_send(struct ib_qp *qp,
2291 struct ib_send_wr *send_wr,
2292 struct ib_send_wr **bad_send_wr)
2293{
2294 return qp->device->post_send(qp, send_wr, bad_send_wr);
2295}
2296
2297/**
2298 * ib_post_recv - Posts a list of work requests to the receive queue of
2299 * the specified QP.
2300 * @qp: The QP to post the work request on.
2301 * @recv_wr: A list of work requests to post on the receive queue.
2302 * @bad_recv_wr: On an immediate failure, this parameter will reference
2303 * the work request that failed to be posted on the QP.
2304 */
2305static inline int ib_post_recv(struct ib_qp *qp,
2306 struct ib_recv_wr *recv_wr,
2307 struct ib_recv_wr **bad_recv_wr)
2308{
2309 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
2310}
2311
2312/**
2313 * ib_create_cq - Creates a CQ on the specified device.
2314 * @device: The device on which to create the CQ.
2315 * @comp_handler: A user-specified callback that is invoked when a
2316 * completion event occurs on the CQ.
2317 * @event_handler: A user-specified callback that is invoked when an
2318 * asynchronous event not associated with a completion occurs on the CQ.
2319 * @cq_context: Context associated with the CQ returned to the user via
2320 * the associated completion and event handlers.
Matan Barak8e372102015-06-11 16:35:21 +03002321 * @cq_attr: The attributes the CQ should be created upon.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 *
2323 * Users can examine the cq structure to determine the actual CQ size.
2324 */
2325struct ib_cq *ib_create_cq(struct ib_device *device,
2326 ib_comp_handler comp_handler,
2327 void (*event_handler)(struct ib_event *, void *),
Matan Barak8e372102015-06-11 16:35:21 +03002328 void *cq_context,
2329 const struct ib_cq_init_attr *cq_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331/**
2332 * ib_resize_cq - Modifies the capacity of the CQ.
2333 * @cq: The CQ to resize.
2334 * @cqe: The minimum size of the CQ.
2335 *
2336 * Users can examine the cq structure to determine the actual CQ size.
2337 */
2338int ib_resize_cq(struct ib_cq *cq, int cqe);
2339
2340/**
Eli Cohen2dd57162008-04-16 21:09:33 -07002341 * ib_modify_cq - Modifies moderation params of the CQ
2342 * @cq: The CQ to modify.
2343 * @cq_count: number of CQEs that will trigger an event
2344 * @cq_period: max period of time in usec before triggering an event
2345 *
2346 */
2347int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
2348
2349/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 * ib_destroy_cq - Destroys the specified CQ.
2351 * @cq: The CQ to destroy.
2352 */
2353int ib_destroy_cq(struct ib_cq *cq);
2354
2355/**
2356 * ib_poll_cq - poll a CQ for completion(s)
2357 * @cq:the CQ being polled
2358 * @num_entries:maximum number of completions to return
2359 * @wc:array of at least @num_entries &struct ib_wc where completions
2360 * will be returned
2361 *
2362 * Poll a CQ for (possibly multiple) completions. If the return value
2363 * is < 0, an error occurred. If the return value is >= 0, it is the
2364 * number of completions returned. If the return value is
2365 * non-negative and < num_entries, then the CQ was emptied.
2366 */
2367static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
2368 struct ib_wc *wc)
2369{
2370 return cq->device->poll_cq(cq, num_entries, wc);
2371}
2372
2373/**
2374 * ib_peek_cq - Returns the number of unreaped completions currently
2375 * on the specified CQ.
2376 * @cq: The CQ to peek.
2377 * @wc_cnt: A minimum number of unreaped completions to check for.
2378 *
2379 * If the number of unreaped completions is greater than or equal to wc_cnt,
2380 * this function returns wc_cnt, otherwise, it returns the actual number of
2381 * unreaped completions.
2382 */
2383int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
2384
2385/**
2386 * ib_req_notify_cq - Request completion notification on a CQ.
2387 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07002388 * @flags:
2389 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
2390 * to request an event on the next solicited event or next work
2391 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
2392 * may also be |ed in to request a hint about missed events, as
2393 * described below.
2394 *
2395 * Return Value:
2396 * < 0 means an error occurred while requesting notification
2397 * == 0 means notification was requested successfully, and if
2398 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
2399 * were missed and it is safe to wait for another event. In
2400 * this case is it guaranteed that any work completions added
2401 * to the CQ since the last CQ poll will trigger a completion
2402 * notification event.
2403 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
2404 * in. It means that the consumer must poll the CQ again to
2405 * make sure it is empty to avoid missing an event because of a
2406 * race between requesting notification and an entry being
2407 * added to the CQ. This return value means it is possible
2408 * (but not guaranteed) that a work completion has been added
2409 * to the CQ since the last poll without triggering a
2410 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 */
2412static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07002413 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414{
Roland Dreiered23a722007-05-06 21:02:48 -07002415 return cq->device->req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416}
2417
2418/**
2419 * ib_req_ncomp_notif - Request completion notification when there are
2420 * at least the specified number of unreaped completions on the CQ.
2421 * @cq: The CQ to generate an event for.
2422 * @wc_cnt: The number of unreaped completions that should be on the
2423 * CQ before an event is generated.
2424 */
2425static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
2426{
2427 return cq->device->req_ncomp_notif ?
2428 cq->device->req_ncomp_notif(cq, wc_cnt) :
2429 -ENOSYS;
2430}
2431
2432/**
2433 * ib_get_dma_mr - Returns a memory region for system memory that is
2434 * usable for DMA.
2435 * @pd: The protection domain associated with the memory region.
2436 * @mr_access_flags: Specifies the memory access rights.
Ralph Campbell9b513092006-12-12 14:27:41 -08002437 *
2438 * Note that the ib_dma_*() functions defined below must be used
2439 * to create/destroy addresses used with the Lkey or Rkey returned
2440 * by ib_get_dma_mr().
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 */
2442struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
2443
2444/**
Ralph Campbell9b513092006-12-12 14:27:41 -08002445 * ib_dma_mapping_error - check a DMA addr for error
2446 * @dev: The device for which the dma_addr was created
2447 * @dma_addr: The DMA address to check
2448 */
2449static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
2450{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002451 if (dev->dma_ops)
2452 return dev->dma_ops->mapping_error(dev, dma_addr);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07002453 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08002454}
2455
2456/**
2457 * ib_dma_map_single - Map a kernel virtual address to DMA address
2458 * @dev: The device for which the dma_addr is to be created
2459 * @cpu_addr: The kernel virtual address
2460 * @size: The size of the region in bytes
2461 * @direction: The direction of the DMA
2462 */
2463static inline u64 ib_dma_map_single(struct ib_device *dev,
2464 void *cpu_addr, size_t size,
2465 enum dma_data_direction direction)
2466{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002467 if (dev->dma_ops)
2468 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
2469 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002470}
2471
2472/**
2473 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
2474 * @dev: The device for which the DMA address was created
2475 * @addr: The DMA address
2476 * @size: The size of the region in bytes
2477 * @direction: The direction of the DMA
2478 */
2479static inline void ib_dma_unmap_single(struct ib_device *dev,
2480 u64 addr, size_t size,
2481 enum dma_data_direction direction)
2482{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002483 if (dev->dma_ops)
2484 dev->dma_ops->unmap_single(dev, addr, size, direction);
2485 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002486 dma_unmap_single(dev->dma_device, addr, size, direction);
2487}
2488
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002489static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
2490 void *cpu_addr, size_t size,
2491 enum dma_data_direction direction,
2492 struct dma_attrs *attrs)
2493{
2494 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
2495 direction, attrs);
2496}
2497
2498static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
2499 u64 addr, size_t size,
2500 enum dma_data_direction direction,
2501 struct dma_attrs *attrs)
2502{
2503 return dma_unmap_single_attrs(dev->dma_device, addr, size,
2504 direction, attrs);
2505}
2506
Ralph Campbell9b513092006-12-12 14:27:41 -08002507/**
2508 * ib_dma_map_page - Map a physical page to DMA address
2509 * @dev: The device for which the dma_addr is to be created
2510 * @page: The page to be mapped
2511 * @offset: The offset within the page
2512 * @size: The size of the region in bytes
2513 * @direction: The direction of the DMA
2514 */
2515static inline u64 ib_dma_map_page(struct ib_device *dev,
2516 struct page *page,
2517 unsigned long offset,
2518 size_t size,
2519 enum dma_data_direction direction)
2520{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002521 if (dev->dma_ops)
2522 return dev->dma_ops->map_page(dev, page, offset, size, direction);
2523 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002524}
2525
2526/**
2527 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
2528 * @dev: The device for which the DMA address was created
2529 * @addr: The DMA address
2530 * @size: The size of the region in bytes
2531 * @direction: The direction of the DMA
2532 */
2533static inline void ib_dma_unmap_page(struct ib_device *dev,
2534 u64 addr, size_t size,
2535 enum dma_data_direction direction)
2536{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002537 if (dev->dma_ops)
2538 dev->dma_ops->unmap_page(dev, addr, size, direction);
2539 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002540 dma_unmap_page(dev->dma_device, addr, size, direction);
2541}
2542
2543/**
2544 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
2545 * @dev: The device for which the DMA addresses are to be created
2546 * @sg: The array of scatter/gather entries
2547 * @nents: The number of scatter/gather entries
2548 * @direction: The direction of the DMA
2549 */
2550static inline int ib_dma_map_sg(struct ib_device *dev,
2551 struct scatterlist *sg, int nents,
2552 enum dma_data_direction direction)
2553{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002554 if (dev->dma_ops)
2555 return dev->dma_ops->map_sg(dev, sg, nents, direction);
2556 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002557}
2558
2559/**
2560 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
2561 * @dev: The device for which the DMA addresses were created
2562 * @sg: The array of scatter/gather entries
2563 * @nents: The number of scatter/gather entries
2564 * @direction: The direction of the DMA
2565 */
2566static inline void ib_dma_unmap_sg(struct ib_device *dev,
2567 struct scatterlist *sg, int nents,
2568 enum dma_data_direction direction)
2569{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002570 if (dev->dma_ops)
2571 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
2572 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002573 dma_unmap_sg(dev->dma_device, sg, nents, direction);
2574}
2575
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002576static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
2577 struct scatterlist *sg, int nents,
2578 enum dma_data_direction direction,
2579 struct dma_attrs *attrs)
2580{
2581 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2582}
2583
2584static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
2585 struct scatterlist *sg, int nents,
2586 enum dma_data_direction direction,
2587 struct dma_attrs *attrs)
2588{
2589 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2590}
Ralph Campbell9b513092006-12-12 14:27:41 -08002591/**
2592 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
2593 * @dev: The device for which the DMA addresses were created
2594 * @sg: The scatter/gather entry
Mike Marciniszynea58a592014-03-28 13:26:59 -04002595 *
2596 * Note: this function is obsolete. To do: change all occurrences of
2597 * ib_sg_dma_address() into sg_dma_address().
Ralph Campbell9b513092006-12-12 14:27:41 -08002598 */
2599static inline u64 ib_sg_dma_address(struct ib_device *dev,
2600 struct scatterlist *sg)
2601{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002602 return sg_dma_address(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002603}
2604
2605/**
2606 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
2607 * @dev: The device for which the DMA addresses were created
2608 * @sg: The scatter/gather entry
Mike Marciniszynea58a592014-03-28 13:26:59 -04002609 *
2610 * Note: this function is obsolete. To do: change all occurrences of
2611 * ib_sg_dma_len() into sg_dma_len().
Ralph Campbell9b513092006-12-12 14:27:41 -08002612 */
2613static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
2614 struct scatterlist *sg)
2615{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002616 return sg_dma_len(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002617}
2618
2619/**
2620 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
2621 * @dev: The device for which the DMA address was created
2622 * @addr: The DMA address
2623 * @size: The size of the region in bytes
2624 * @dir: The direction of the DMA
2625 */
2626static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
2627 u64 addr,
2628 size_t size,
2629 enum dma_data_direction dir)
2630{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002631 if (dev->dma_ops)
2632 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
2633 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002634 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
2635}
2636
2637/**
2638 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
2639 * @dev: The device for which the DMA address was created
2640 * @addr: The DMA address
2641 * @size: The size of the region in bytes
2642 * @dir: The direction of the DMA
2643 */
2644static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
2645 u64 addr,
2646 size_t size,
2647 enum dma_data_direction dir)
2648{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002649 if (dev->dma_ops)
2650 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
2651 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002652 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
2653}
2654
2655/**
2656 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
2657 * @dev: The device for which the DMA address is requested
2658 * @size: The size of the region to allocate in bytes
2659 * @dma_handle: A pointer for returning the DMA address of the region
2660 * @flag: memory allocator flags
2661 */
2662static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
2663 size_t size,
2664 u64 *dma_handle,
2665 gfp_t flag)
2666{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002667 if (dev->dma_ops)
2668 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Roland Dreierc59a3da2006-12-15 13:57:26 -08002669 else {
2670 dma_addr_t handle;
2671 void *ret;
2672
2673 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
2674 *dma_handle = handle;
2675 return ret;
2676 }
Ralph Campbell9b513092006-12-12 14:27:41 -08002677}
2678
2679/**
2680 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
2681 * @dev: The device for which the DMA addresses were allocated
2682 * @size: The size of the region
2683 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
2684 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
2685 */
2686static inline void ib_dma_free_coherent(struct ib_device *dev,
2687 size_t size, void *cpu_addr,
2688 u64 dma_handle)
2689{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002690 if (dev->dma_ops)
2691 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
2692 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002693 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
2694}
2695
2696/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
2698 * by an HCA.
2699 * @pd: The protection domain associated assigned to the registered region.
2700 * @phys_buf_array: Specifies a list of physical buffers to use in the
2701 * memory region.
2702 * @num_phys_buf: Specifies the size of the phys_buf_array.
2703 * @mr_access_flags: Specifies the memory access rights.
2704 * @iova_start: The offset of the region's starting I/O virtual address.
2705 */
2706struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
2707 struct ib_phys_buf *phys_buf_array,
2708 int num_phys_buf,
2709 int mr_access_flags,
2710 u64 *iova_start);
2711
2712/**
2713 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
2714 * Conceptually, this call performs the functions deregister memory region
2715 * followed by register physical memory region. Where possible,
2716 * resources are reused instead of deallocated and reallocated.
2717 * @mr: The memory region to modify.
2718 * @mr_rereg_mask: A bit-mask used to indicate which of the following
2719 * properties of the memory region are being modified.
2720 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
2721 * the new protection domain to associated with the memory region,
2722 * otherwise, this parameter is ignored.
2723 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2724 * field specifies a list of physical buffers to use in the new
2725 * translation, otherwise, this parameter is ignored.
2726 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2727 * field specifies the size of the phys_buf_array, otherwise, this
2728 * parameter is ignored.
2729 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
2730 * field specifies the new memory access rights, otherwise, this
2731 * parameter is ignored.
2732 * @iova_start: The offset of the region's starting I/O virtual address.
2733 */
2734int ib_rereg_phys_mr(struct ib_mr *mr,
2735 int mr_rereg_mask,
2736 struct ib_pd *pd,
2737 struct ib_phys_buf *phys_buf_array,
2738 int num_phys_buf,
2739 int mr_access_flags,
2740 u64 *iova_start);
2741
2742/**
2743 * ib_query_mr - Retrieves information about a specific memory region.
2744 * @mr: The memory region to retrieve information about.
2745 * @mr_attr: The attributes of the specified memory region.
2746 */
2747int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
2748
2749/**
2750 * ib_dereg_mr - Deregisters a memory region and removes it from the
2751 * HCA translation table.
2752 * @mr: The memory region to deregister.
Shani Michaeli7083e422013-02-06 16:19:12 +00002753 *
2754 * This function can fail, if the memory region has memory windows bound to it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 */
2756int ib_dereg_mr(struct ib_mr *mr);
2757
Sagi Grimberg17cd3a22014-02-23 14:19:04 +02002758
2759/**
2760 * ib_create_mr - Allocates a memory region that may be used for
2761 * signature handover operations.
2762 * @pd: The protection domain associated with the region.
2763 * @mr_init_attr: memory region init attributes.
2764 */
2765struct ib_mr *ib_create_mr(struct ib_pd *pd,
2766 struct ib_mr_init_attr *mr_init_attr);
2767
2768/**
2769 * ib_destroy_mr - Destroys a memory region that was created using
2770 * ib_create_mr and removes it from HW translation tables.
2771 * @mr: The memory region to destroy.
2772 *
2773 * This function can fail, if the memory region has memory windows bound to it.
2774 */
2775int ib_destroy_mr(struct ib_mr *mr);
2776
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777/**
Steve Wise00f7ec32008-07-14 23:48:45 -07002778 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
2779 * IB_WR_FAST_REG_MR send work request.
2780 * @pd: The protection domain associated with the region.
2781 * @max_page_list_len: requested max physical buffer list length to be
2782 * used with fast register work requests for this MR.
2783 */
2784struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2785
2786/**
2787 * ib_alloc_fast_reg_page_list - Allocates a page list array
2788 * @device - ib device pointer.
2789 * @page_list_len - size of the page list array to be allocated.
2790 *
2791 * This allocates and returns a struct ib_fast_reg_page_list * and a
2792 * page_list array that is at least page_list_len in size. The actual
2793 * size is returned in max_page_list_len. The caller is responsible
2794 * for initializing the contents of the page_list array before posting
2795 * a send work request with the IB_WC_FAST_REG_MR opcode.
2796 *
2797 * The page_list array entries must be translated using one of the
2798 * ib_dma_*() functions just like the addresses passed to
2799 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
2800 * ib_fast_reg_page_list must not be modified by the caller until the
2801 * IB_WC_FAST_REG_MR work request completes.
2802 */
2803struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2804 struct ib_device *device, int page_list_len);
2805
2806/**
2807 * ib_free_fast_reg_page_list - Deallocates a previously allocated
2808 * page list array.
2809 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2810 */
2811void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2812
2813/**
2814 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2815 * R_Key and L_Key.
2816 * @mr - struct ib_mr pointer to be updated.
2817 * @newkey - new key to be used.
2818 */
2819static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2820{
2821 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2822 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2823}
2824
2825/**
Shani Michaeli7083e422013-02-06 16:19:12 +00002826 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
2827 * for calculating a new rkey for type 2 memory windows.
2828 * @rkey - the rkey to increment.
2829 */
2830static inline u32 ib_inc_rkey(u32 rkey)
2831{
2832 const u32 mask = 0x000000ff;
2833 return ((rkey + 1) & mask) | (rkey & ~mask);
2834}
2835
2836/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 * ib_alloc_mw - Allocates a memory window.
2838 * @pd: The protection domain associated with the memory window.
Shani Michaeli7083e422013-02-06 16:19:12 +00002839 * @type: The type of the memory window (1 or 2).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 */
Shani Michaeli7083e422013-02-06 16:19:12 +00002841struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842
2843/**
2844 * ib_bind_mw - Posts a work request to the send queue of the specified
2845 * QP, which binds the memory window to the given address range and
2846 * remote access attributes.
2847 * @qp: QP to post the bind work request on.
2848 * @mw: The memory window to bind.
2849 * @mw_bind: Specifies information about the memory window, including
2850 * its address range, remote access rights, and associated memory region.
Shani Michaeli7083e422013-02-06 16:19:12 +00002851 *
2852 * If there is no immediate error, the function will update the rkey member
2853 * of the mw parameter to its new value. The bind operation can still fail
2854 * asynchronously.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 */
2856static inline int ib_bind_mw(struct ib_qp *qp,
2857 struct ib_mw *mw,
2858 struct ib_mw_bind *mw_bind)
2859{
2860 /* XXX reference counting in corresponding MR? */
2861 return mw->device->bind_mw ?
2862 mw->device->bind_mw(qp, mw, mw_bind) :
2863 -ENOSYS;
2864}
2865
2866/**
2867 * ib_dealloc_mw - Deallocates a memory window.
2868 * @mw: The memory window to deallocate.
2869 */
2870int ib_dealloc_mw(struct ib_mw *mw);
2871
2872/**
2873 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2874 * @pd: The protection domain associated with the unmapped region.
2875 * @mr_access_flags: Specifies the memory access rights.
2876 * @fmr_attr: Attributes of the unmapped region.
2877 *
2878 * A fast memory region must be mapped before it can be used as part of
2879 * a work request.
2880 */
2881struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2882 int mr_access_flags,
2883 struct ib_fmr_attr *fmr_attr);
2884
2885/**
2886 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2887 * @fmr: The fast memory region to associate with the pages.
2888 * @page_list: An array of physical pages to map to the fast memory region.
2889 * @list_len: The number of pages in page_list.
2890 * @iova: The I/O virtual address to use with the mapped region.
2891 */
2892static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2893 u64 *page_list, int list_len,
2894 u64 iova)
2895{
2896 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2897}
2898
2899/**
2900 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2901 * @fmr_list: A linked list of fast memory regions to unmap.
2902 */
2903int ib_unmap_fmr(struct list_head *fmr_list);
2904
2905/**
2906 * ib_dealloc_fmr - Deallocates a fast memory region.
2907 * @fmr: The fast memory region to deallocate.
2908 */
2909int ib_dealloc_fmr(struct ib_fmr *fmr);
2910
2911/**
2912 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2913 * @qp: QP to attach to the multicast group. The QP must be type
2914 * IB_QPT_UD.
2915 * @gid: Multicast group GID.
2916 * @lid: Multicast group LID in host byte order.
2917 *
2918 * In order to send and receive multicast packets, subnet
2919 * administration must have created the multicast group and configured
2920 * the fabric appropriately. The port associated with the specified
2921 * QP must also be a member of the multicast group.
2922 */
2923int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2924
2925/**
2926 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2927 * @qp: QP to detach from the multicast group.
2928 * @gid: Multicast group GID.
2929 * @lid: Multicast group LID in host byte order.
2930 */
2931int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2932
Sean Hefty59991f92011-05-23 17:52:46 -07002933/**
2934 * ib_alloc_xrcd - Allocates an XRC domain.
2935 * @device: The device on which to allocate the XRC domain.
2936 */
2937struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2938
2939/**
2940 * ib_dealloc_xrcd - Deallocates an XRC domain.
2941 * @xrcd: The XRC domain to deallocate.
2942 */
2943int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2944
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002945struct ib_flow *ib_create_flow(struct ib_qp *qp,
2946 struct ib_flow_attr *flow_attr, int domain);
2947int ib_destroy_flow(struct ib_flow *flow_id);
2948
Eli Cohen1c636f82013-10-31 15:26:32 +02002949static inline int ib_check_mr_access(int flags)
2950{
2951 /*
2952 * Local write permission is required if remote write or
2953 * remote atomic permission is also requested.
2954 */
2955 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
2956 !(flags & IB_ACCESS_LOCAL_WRITE))
2957 return -EINVAL;
2958
2959 return 0;
2960}
2961
Sagi Grimberg1b01d332014-02-23 14:19:05 +02002962/**
2963 * ib_check_mr_status: lightweight check of MR status.
2964 * This routine may provide status checks on a selected
2965 * ib_mr. first use is for signature status check.
2966 *
2967 * @mr: A memory region.
2968 * @check_mask: Bitmask of which checks to perform from
2969 * ib_mr_status_check enumeration.
2970 * @mr_status: The container of relevant status checks.
2971 * failed checks will be indicated in the status bitmask
2972 * and the relevant info shall be in the error item.
2973 */
2974int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
2975 struct ib_mr_status *mr_status);
2976
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977#endif /* IB_VERBS_H */