blob: a41bc5a39ebf6917cf547a3ae3186385b6d247e5 [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>
Roland Dreiere2773c02005-07-07 17:57:10 -070054#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Tejun Heof0626712010-10-19 15:24:36 +000056extern struct workqueue_struct *ib_wq;
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058union ib_gid {
59 u8 raw[16];
60 struct {
Sean Hefty97f52eb2005-08-13 21:05:57 -070061 __be64 subnet_prefix;
62 __be64 interface_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 } global;
64};
65
Tom Tucker07ebafb2006-08-03 16:02:42 -050066enum rdma_node_type {
67 /* IB values map to NodeInfo:NodeType. */
68 RDMA_NODE_IB_CA = 1,
69 RDMA_NODE_IB_SWITCH,
70 RDMA_NODE_IB_ROUTER,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000071 RDMA_NODE_RNIC,
72 RDMA_NODE_USNIC,
Upinder Malhi5db57652014-01-15 17:02:36 -080073 RDMA_NODE_USNIC_UDP,
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
75
Tom Tucker07ebafb2006-08-03 16:02:42 -050076enum rdma_transport_type {
77 RDMA_TRANSPORT_IB,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000078 RDMA_TRANSPORT_IWARP,
Upinder Malhi248567f2014-01-09 14:48:19 -080079 RDMA_TRANSPORT_USNIC,
80 RDMA_TRANSPORT_USNIC_UDP
Tom Tucker07ebafb2006-08-03 16:02:42 -050081};
82
Roland Dreier8385fd82014-06-04 10:00:16 -070083__attribute_const__ enum rdma_transport_type
84rdma_node_get_transport(enum rdma_node_type node_type);
Tom Tucker07ebafb2006-08-03 16:02:42 -050085
Eli Cohena3f5ada2010-09-27 17:51:10 -070086enum rdma_link_layer {
87 IB_LINK_LAYER_UNSPECIFIED,
88 IB_LINK_LAYER_INFINIBAND,
89 IB_LINK_LAYER_ETHERNET,
90};
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092enum ib_device_cap_flags {
93 IB_DEVICE_RESIZE_MAX_WR = 1,
94 IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
95 IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
96 IB_DEVICE_RAW_MULTI = (1<<3),
97 IB_DEVICE_AUTO_PATH_MIG = (1<<4),
98 IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
99 IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
100 IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
101 IB_DEVICE_SHUTDOWN_PORT = (1<<8),
102 IB_DEVICE_INIT_TYPE = (1<<9),
103 IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
104 IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
105 IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
106 IB_DEVICE_SRQ_RESIZE = (1<<13),
107 IB_DEVICE_N_NOTIFY_CQ = (1<<14),
Steve Wise96f15c02008-07-14 23:48:53 -0700108 IB_DEVICE_LOCAL_DMA_LKEY = (1<<15),
Roland Dreier0f39cf32008-04-16 21:09:32 -0700109 IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
Eli Cohene0605d92008-01-30 18:30:57 +0200110 IB_DEVICE_MEM_WINDOW = (1<<17),
111 /*
112 * Devices should set IB_DEVICE_UD_IP_SUM if they support
113 * insertion of UDP and TCP checksum on outgoing UD IPoIB
114 * messages and can verify the validity of checksum for
115 * incoming messages. Setting this flag implies that the
116 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
117 */
118 IB_DEVICE_UD_IP_CSUM = (1<<18),
Eli Cohenc93570f2008-04-16 21:09:27 -0700119 IB_DEVICE_UD_TSO = (1<<19),
Sean Hefty59991f92011-05-23 17:52:46 -0700120 IB_DEVICE_XRC = (1<<20),
Steve Wise00f7ec32008-07-14 23:48:45 -0700121 IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21),
Ron Livne47ee1b92008-07-14 23:48:48 -0700122 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
Shani Michaeli7083e422013-02-06 16:19:12 +0000123 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1<<23),
Hadar Hen Zion319a4412013-08-07 14:01:59 +0300124 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1<<24),
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200125 IB_DEVICE_MANAGED_FLOW_STEERING = (1<<29),
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200126 IB_DEVICE_SIGNATURE_HANDOVER = (1<<30),
127 IB_DEVICE_ON_DEMAND_PAGING = (1<<31),
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200128};
129
130enum ib_signature_prot_cap {
131 IB_PROT_T10DIF_TYPE_1 = 1,
132 IB_PROT_T10DIF_TYPE_2 = 1 << 1,
133 IB_PROT_T10DIF_TYPE_3 = 1 << 2,
134};
135
136enum ib_signature_guard_cap {
137 IB_GUARD_T10DIF_CRC = 1,
138 IB_GUARD_T10DIF_CSUM = 1 << 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139};
140
141enum ib_atomic_cap {
142 IB_ATOMIC_NONE,
143 IB_ATOMIC_HCA,
144 IB_ATOMIC_GLOB
145};
146
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200147enum ib_odp_general_cap_bits {
148 IB_ODP_SUPPORT = 1 << 0,
149};
150
151enum ib_odp_transport_cap_bits {
152 IB_ODP_SUPPORT_SEND = 1 << 0,
153 IB_ODP_SUPPORT_RECV = 1 << 1,
154 IB_ODP_SUPPORT_WRITE = 1 << 2,
155 IB_ODP_SUPPORT_READ = 1 << 3,
156 IB_ODP_SUPPORT_ATOMIC = 1 << 4,
157};
158
159struct ib_odp_caps {
160 uint64_t general_caps;
161 struct {
162 uint32_t rc_odp_caps;
163 uint32_t uc_odp_caps;
164 uint32_t ud_odp_caps;
165 } per_transport_caps;
166};
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168struct ib_device_attr {
169 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700170 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 u64 max_mr_size;
172 u64 page_size_cap;
173 u32 vendor_id;
174 u32 vendor_part_id;
175 u32 hw_ver;
176 int max_qp;
177 int max_qp_wr;
178 int device_cap_flags;
179 int max_sge;
180 int max_sge_rd;
181 int max_cq;
182 int max_cqe;
183 int max_mr;
184 int max_pd;
185 int max_qp_rd_atom;
186 int max_ee_rd_atom;
187 int max_res_rd_atom;
188 int max_qp_init_rd_atom;
189 int max_ee_init_rd_atom;
190 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300191 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 int max_ee;
193 int max_rdd;
194 int max_mw;
195 int max_raw_ipv6_qp;
196 int max_raw_ethy_qp;
197 int max_mcast_grp;
198 int max_mcast_qp_attach;
199 int max_total_mcast_qp_attach;
200 int max_ah;
201 int max_fmr;
202 int max_map_per_fmr;
203 int max_srq;
204 int max_srq_wr;
205 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700206 unsigned int max_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 u16 max_pkeys;
208 u8 local_ca_ack_delay;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200209 int sig_prot_cap;
210 int sig_guard_cap;
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200211 struct ib_odp_caps odp_caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212};
213
214enum ib_mtu {
215 IB_MTU_256 = 1,
216 IB_MTU_512 = 2,
217 IB_MTU_1024 = 3,
218 IB_MTU_2048 = 4,
219 IB_MTU_4096 = 5
220};
221
222static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
223{
224 switch (mtu) {
225 case IB_MTU_256: return 256;
226 case IB_MTU_512: return 512;
227 case IB_MTU_1024: return 1024;
228 case IB_MTU_2048: return 2048;
229 case IB_MTU_4096: return 4096;
230 default: return -1;
231 }
232}
233
234enum ib_port_state {
235 IB_PORT_NOP = 0,
236 IB_PORT_DOWN = 1,
237 IB_PORT_INIT = 2,
238 IB_PORT_ARMED = 3,
239 IB_PORT_ACTIVE = 4,
240 IB_PORT_ACTIVE_DEFER = 5
241};
242
243enum ib_port_cap_flags {
244 IB_PORT_SM = 1 << 1,
245 IB_PORT_NOTICE_SUP = 1 << 2,
246 IB_PORT_TRAP_SUP = 1 << 3,
247 IB_PORT_OPT_IPD_SUP = 1 << 4,
248 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
249 IB_PORT_SL_MAP_SUP = 1 << 6,
250 IB_PORT_MKEY_NVRAM = 1 << 7,
251 IB_PORT_PKEY_NVRAM = 1 << 8,
252 IB_PORT_LED_INFO_SUP = 1 << 9,
253 IB_PORT_SM_DISABLED = 1 << 10,
254 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
255 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300256 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 IB_PORT_CM_SUP = 1 << 16,
258 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
259 IB_PORT_REINIT_SUP = 1 << 18,
260 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
261 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
262 IB_PORT_DR_NOTICE_SUP = 1 << 21,
263 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
264 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
265 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
Moni Shouab4a26a22014-02-09 11:54:34 +0200266 IB_PORT_CLIENT_REG_SUP = 1 << 25,
267 IB_PORT_IP_BASED_GIDS = 1 << 26
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268};
269
270enum ib_port_width {
271 IB_WIDTH_1X = 1,
272 IB_WIDTH_4X = 2,
273 IB_WIDTH_8X = 4,
274 IB_WIDTH_12X = 8
275};
276
277static inline int ib_width_enum_to_int(enum ib_port_width width)
278{
279 switch (width) {
280 case IB_WIDTH_1X: return 1;
281 case IB_WIDTH_4X: return 4;
282 case IB_WIDTH_8X: return 8;
283 case IB_WIDTH_12X: return 12;
284 default: return -1;
285 }
286}
287
Or Gerlitz2e966912012-02-28 18:49:50 +0200288enum ib_port_speed {
289 IB_SPEED_SDR = 1,
290 IB_SPEED_DDR = 2,
291 IB_SPEED_QDR = 4,
292 IB_SPEED_FDR10 = 8,
293 IB_SPEED_FDR = 16,
294 IB_SPEED_EDR = 32
295};
296
Steve Wise7f624d02008-07-14 23:48:48 -0700297struct ib_protocol_stats {
298 /* TBD... */
299};
300
301struct iw_protocol_stats {
302 u64 ipInReceives;
303 u64 ipInHdrErrors;
304 u64 ipInTooBigErrors;
305 u64 ipInNoRoutes;
306 u64 ipInAddrErrors;
307 u64 ipInUnknownProtos;
308 u64 ipInTruncatedPkts;
309 u64 ipInDiscards;
310 u64 ipInDelivers;
311 u64 ipOutForwDatagrams;
312 u64 ipOutRequests;
313 u64 ipOutDiscards;
314 u64 ipOutNoRoutes;
315 u64 ipReasmTimeout;
316 u64 ipReasmReqds;
317 u64 ipReasmOKs;
318 u64 ipReasmFails;
319 u64 ipFragOKs;
320 u64 ipFragFails;
321 u64 ipFragCreates;
322 u64 ipInMcastPkts;
323 u64 ipOutMcastPkts;
324 u64 ipInBcastPkts;
325 u64 ipOutBcastPkts;
326
327 u64 tcpRtoAlgorithm;
328 u64 tcpRtoMin;
329 u64 tcpRtoMax;
330 u64 tcpMaxConn;
331 u64 tcpActiveOpens;
332 u64 tcpPassiveOpens;
333 u64 tcpAttemptFails;
334 u64 tcpEstabResets;
335 u64 tcpCurrEstab;
336 u64 tcpInSegs;
337 u64 tcpOutSegs;
338 u64 tcpRetransSegs;
339 u64 tcpInErrs;
340 u64 tcpOutRsts;
341};
342
343union rdma_protocol_stats {
344 struct ib_protocol_stats ib;
345 struct iw_protocol_stats iw;
346};
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348struct ib_port_attr {
349 enum ib_port_state state;
350 enum ib_mtu max_mtu;
351 enum ib_mtu active_mtu;
352 int gid_tbl_len;
353 u32 port_cap_flags;
354 u32 max_msg_sz;
355 u32 bad_pkey_cntr;
356 u32 qkey_viol_cntr;
357 u16 pkey_tbl_len;
358 u16 lid;
359 u16 sm_lid;
360 u8 lmc;
361 u8 max_vl_num;
362 u8 sm_sl;
363 u8 subnet_timeout;
364 u8 init_type_reply;
365 u8 active_width;
366 u8 active_speed;
367 u8 phys_state;
368};
369
370enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800371 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
372 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373};
374
375struct ib_device_modify {
376 u64 sys_image_guid;
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800377 char node_desc[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378};
379
380enum ib_port_modify_flags {
381 IB_PORT_SHUTDOWN = 1,
382 IB_PORT_INIT_TYPE = (1<<2),
383 IB_PORT_RESET_QKEY_CNTR = (1<<3)
384};
385
386struct ib_port_modify {
387 u32 set_port_cap_mask;
388 u32 clr_port_cap_mask;
389 u8 init_type;
390};
391
392enum ib_event_type {
393 IB_EVENT_CQ_ERR,
394 IB_EVENT_QP_FATAL,
395 IB_EVENT_QP_REQ_ERR,
396 IB_EVENT_QP_ACCESS_ERR,
397 IB_EVENT_COMM_EST,
398 IB_EVENT_SQ_DRAINED,
399 IB_EVENT_PATH_MIG,
400 IB_EVENT_PATH_MIG_ERR,
401 IB_EVENT_DEVICE_FATAL,
402 IB_EVENT_PORT_ACTIVE,
403 IB_EVENT_PORT_ERR,
404 IB_EVENT_LID_CHANGE,
405 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700406 IB_EVENT_SM_CHANGE,
407 IB_EVENT_SRQ_ERR,
408 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700409 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000410 IB_EVENT_CLIENT_REREGISTER,
411 IB_EVENT_GID_CHANGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412};
413
414struct ib_event {
415 struct ib_device *device;
416 union {
417 struct ib_cq *cq;
418 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700419 struct ib_srq *srq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 u8 port_num;
421 } element;
422 enum ib_event_type event;
423};
424
425struct ib_event_handler {
426 struct ib_device *device;
427 void (*handler)(struct ib_event_handler *, struct ib_event *);
428 struct list_head list;
429};
430
431#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
432 do { \
433 (_ptr)->device = _device; \
434 (_ptr)->handler = _handler; \
435 INIT_LIST_HEAD(&(_ptr)->list); \
436 } while (0)
437
438struct ib_global_route {
439 union ib_gid dgid;
440 u32 flow_label;
441 u8 sgid_index;
442 u8 hop_limit;
443 u8 traffic_class;
444};
445
Hal Rosenstock513789e2005-07-27 11:45:34 -0700446struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700447 __be32 version_tclass_flow;
448 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700449 u8 next_hdr;
450 u8 hop_limit;
451 union ib_gid sgid;
452 union ib_gid dgid;
453};
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455enum {
456 IB_MULTICAST_QPN = 0xffffff
457};
458
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800459#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461enum ib_ah_flags {
462 IB_AH_GRH = 1
463};
464
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700465enum ib_rate {
466 IB_RATE_PORT_CURRENT = 0,
467 IB_RATE_2_5_GBPS = 2,
468 IB_RATE_5_GBPS = 5,
469 IB_RATE_10_GBPS = 3,
470 IB_RATE_20_GBPS = 6,
471 IB_RATE_30_GBPS = 4,
472 IB_RATE_40_GBPS = 7,
473 IB_RATE_60_GBPS = 8,
474 IB_RATE_80_GBPS = 9,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300475 IB_RATE_120_GBPS = 10,
476 IB_RATE_14_GBPS = 11,
477 IB_RATE_56_GBPS = 12,
478 IB_RATE_112_GBPS = 13,
479 IB_RATE_168_GBPS = 14,
480 IB_RATE_25_GBPS = 15,
481 IB_RATE_100_GBPS = 16,
482 IB_RATE_200_GBPS = 17,
483 IB_RATE_300_GBPS = 18
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700484};
485
486/**
487 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
488 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
489 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
490 * @rate: rate to convert.
491 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700492__attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700493
494/**
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300495 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
496 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
497 * @rate: rate to convert.
498 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700499__attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300500
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200501enum ib_mr_create_flags {
502 IB_MR_SIGNATURE_EN = 1,
503};
504
505/**
506 * ib_mr_init_attr - Memory region init attributes passed to routine
507 * ib_create_mr.
508 * @max_reg_descriptors: max number of registration descriptors that
509 * may be used with registration work requests.
510 * @flags: MR creation flags bit mask.
511 */
512struct ib_mr_init_attr {
513 int max_reg_descriptors;
514 u32 flags;
515};
516
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200517/**
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300518 * Signature types
519 * IB_SIG_TYPE_NONE: Unprotected.
520 * IB_SIG_TYPE_T10_DIF: Type T10-DIF
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200521 */
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300522enum ib_signature_type {
523 IB_SIG_TYPE_NONE,
524 IB_SIG_TYPE_T10_DIF,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200525};
526
527/**
528 * Signature T10-DIF block-guard types
529 * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
530 * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
531 */
532enum ib_t10_dif_bg_type {
533 IB_T10DIF_CRC,
534 IB_T10DIF_CSUM
535};
536
537/**
538 * struct ib_t10_dif_domain - Parameters specific for T10-DIF
539 * domain.
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200540 * @bg_type: T10-DIF block guard type (CRC|CSUM)
541 * @pi_interval: protection information interval.
542 * @bg: seed of guard computation.
543 * @app_tag: application tag of guard block
544 * @ref_tag: initial guard block reference tag.
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300545 * @ref_remap: Indicate wethear the reftag increments each block
546 * @app_escape: Indicate to skip block check if apptag=0xffff
547 * @ref_escape: Indicate to skip block check if reftag=0xffffffff
548 * @apptag_check_mask: check bitmask of application tag.
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200549 */
550struct ib_t10_dif_domain {
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200551 enum ib_t10_dif_bg_type bg_type;
552 u16 pi_interval;
553 u16 bg;
554 u16 app_tag;
555 u32 ref_tag;
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300556 bool ref_remap;
557 bool app_escape;
558 bool ref_escape;
559 u16 apptag_check_mask;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200560};
561
562/**
563 * struct ib_sig_domain - Parameters for signature domain
564 * @sig_type: specific signauture type
565 * @sig: union of all signature domain attributes that may
566 * be used to set domain layout.
567 */
568struct ib_sig_domain {
569 enum ib_signature_type sig_type;
570 union {
571 struct ib_t10_dif_domain dif;
572 } sig;
573};
574
575/**
576 * struct ib_sig_attrs - Parameters for signature handover operation
577 * @check_mask: bitmask for signature byte check (8 bytes)
578 * @mem: memory domain layout desciptor.
579 * @wire: wire domain layout desciptor.
580 */
581struct ib_sig_attrs {
582 u8 check_mask;
583 struct ib_sig_domain mem;
584 struct ib_sig_domain wire;
585};
586
587enum ib_sig_err_type {
588 IB_SIG_BAD_GUARD,
589 IB_SIG_BAD_REFTAG,
590 IB_SIG_BAD_APPTAG,
591};
592
593/**
594 * struct ib_sig_err - signature error descriptor
595 */
596struct ib_sig_err {
597 enum ib_sig_err_type err_type;
598 u32 expected;
599 u32 actual;
600 u64 sig_err_offset;
601 u32 key;
602};
603
604enum ib_mr_status_check {
605 IB_MR_CHECK_SIG_STATUS = 1,
606};
607
608/**
609 * struct ib_mr_status - Memory region status container
610 *
611 * @fail_status: Bitmask of MR checks status. For each
612 * failed check a corresponding status bit is set.
613 * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
614 * failure.
615 */
616struct ib_mr_status {
617 u32 fail_status;
618 struct ib_sig_err sig_err;
619};
620
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300621/**
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700622 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
623 * enum.
624 * @mult: multiple to convert.
625 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700626__attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628struct ib_ah_attr {
629 struct ib_global_route grh;
630 u16 dlid;
631 u8 sl;
632 u8 src_path_bits;
633 u8 static_rate;
634 u8 ah_flags;
635 u8 port_num;
Matan Barakdd5f03b2013-12-12 18:03:11 +0200636 u8 dmac[ETH_ALEN];
637 u16 vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638};
639
640enum ib_wc_status {
641 IB_WC_SUCCESS,
642 IB_WC_LOC_LEN_ERR,
643 IB_WC_LOC_QP_OP_ERR,
644 IB_WC_LOC_EEC_OP_ERR,
645 IB_WC_LOC_PROT_ERR,
646 IB_WC_WR_FLUSH_ERR,
647 IB_WC_MW_BIND_ERR,
648 IB_WC_BAD_RESP_ERR,
649 IB_WC_LOC_ACCESS_ERR,
650 IB_WC_REM_INV_REQ_ERR,
651 IB_WC_REM_ACCESS_ERR,
652 IB_WC_REM_OP_ERR,
653 IB_WC_RETRY_EXC_ERR,
654 IB_WC_RNR_RETRY_EXC_ERR,
655 IB_WC_LOC_RDD_VIOL_ERR,
656 IB_WC_REM_INV_RD_REQ_ERR,
657 IB_WC_REM_ABORT_ERR,
658 IB_WC_INV_EECN_ERR,
659 IB_WC_INV_EEC_STATE_ERR,
660 IB_WC_FATAL_ERR,
661 IB_WC_RESP_TIMEOUT_ERR,
662 IB_WC_GENERAL_ERR
663};
664
665enum ib_wc_opcode {
666 IB_WC_SEND,
667 IB_WC_RDMA_WRITE,
668 IB_WC_RDMA_READ,
669 IB_WC_COMP_SWAP,
670 IB_WC_FETCH_ADD,
671 IB_WC_BIND_MW,
Eli Cohenc93570f2008-04-16 21:09:27 -0700672 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700673 IB_WC_LOCAL_INV,
674 IB_WC_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300675 IB_WC_MASKED_COMP_SWAP,
676 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677/*
678 * Set value of IB_WC_RECV so consumers can test if a completion is a
679 * receive by testing (opcode & IB_WC_RECV).
680 */
681 IB_WC_RECV = 1 << 7,
682 IB_WC_RECV_RDMA_WITH_IMM
683};
684
685enum ib_wc_flags {
686 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -0700687 IB_WC_WITH_IMM = (1<<1),
688 IB_WC_WITH_INVALIDATE = (1<<2),
Or Gerlitzd927d502012-01-11 19:03:51 +0200689 IB_WC_IP_CSUM_OK = (1<<3),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200690 IB_WC_WITH_SMAC = (1<<4),
691 IB_WC_WITH_VLAN = (1<<5),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692};
693
694struct ib_wc {
695 u64 wr_id;
696 enum ib_wc_status status;
697 enum ib_wc_opcode opcode;
698 u32 vendor_err;
699 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +0200700 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -0700701 union {
702 __be32 imm_data;
703 u32 invalidate_rkey;
704 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 u32 src_qp;
706 int wc_flags;
707 u16 pkey_index;
708 u16 slid;
709 u8 sl;
710 u8 dlid_path_bits;
711 u8 port_num; /* valid only for DR SMPs on switches */
Matan Barakdd5f03b2013-12-12 18:03:11 +0200712 u8 smac[ETH_ALEN];
713 u16 vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714};
715
Roland Dreiered23a722007-05-06 21:02:48 -0700716enum ib_cq_notify_flags {
717 IB_CQ_SOLICITED = 1 << 0,
718 IB_CQ_NEXT_COMP = 1 << 1,
719 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
720 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721};
722
Sean Hefty96104ed2011-05-23 16:31:36 -0700723enum ib_srq_type {
Sean Hefty418d5132011-05-23 19:42:29 -0700724 IB_SRQT_BASIC,
725 IB_SRQT_XRC
Sean Hefty96104ed2011-05-23 16:31:36 -0700726};
727
Roland Dreierd41fcc62005-08-18 12:23:08 -0700728enum ib_srq_attr_mask {
729 IB_SRQ_MAX_WR = 1 << 0,
730 IB_SRQ_LIMIT = 1 << 1,
731};
732
733struct ib_srq_attr {
734 u32 max_wr;
735 u32 max_sge;
736 u32 srq_limit;
737};
738
739struct ib_srq_init_attr {
740 void (*event_handler)(struct ib_event *, void *);
741 void *srq_context;
742 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -0700743 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -0700744
745 union {
746 struct {
747 struct ib_xrcd *xrcd;
748 struct ib_cq *cq;
749 } xrc;
750 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700751};
752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753struct ib_qp_cap {
754 u32 max_send_wr;
755 u32 max_recv_wr;
756 u32 max_send_sge;
757 u32 max_recv_sge;
758 u32 max_inline_data;
759};
760
761enum ib_sig_type {
762 IB_SIGNAL_ALL_WR,
763 IB_SIGNAL_REQ_WR
764};
765
766enum ib_qp_type {
767 /*
768 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
769 * here (and in that order) since the MAD layer uses them as
770 * indices into a 2-entry table.
771 */
772 IB_QPT_SMI,
773 IB_QPT_GSI,
774
775 IB_QPT_RC,
776 IB_QPT_UC,
777 IB_QPT_UD,
778 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700779 IB_QPT_RAW_ETHERTYPE,
Or Gerlitzc938a612012-03-01 12:17:51 +0200780 IB_QPT_RAW_PACKET = 8,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700781 IB_QPT_XRC_INI = 9,
782 IB_QPT_XRC_TGT,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300783 IB_QPT_MAX,
784 /* Reserve a range for qp types internal to the low level driver.
785 * These qp types will not be visible at the IB core layer, so the
786 * IB_QPT_MAX usages should not be affected in the core layer
787 */
788 IB_QPT_RESERVED1 = 0x1000,
789 IB_QPT_RESERVED2,
790 IB_QPT_RESERVED3,
791 IB_QPT_RESERVED4,
792 IB_QPT_RESERVED5,
793 IB_QPT_RESERVED6,
794 IB_QPT_RESERVED7,
795 IB_QPT_RESERVED8,
796 IB_QPT_RESERVED9,
797 IB_QPT_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798};
799
Eli Cohenb846f252008-04-16 21:09:27 -0700800enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -0700801 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
802 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
Matan Barak90f1d1b2013-11-07 15:25:12 +0200803 IB_QP_CREATE_NETIF_QP = 1 << 5,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200804 IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
Or Gerlitz09b93082014-05-11 15:15:11 +0300805 IB_QP_CREATE_USE_GFP_NOIO = 1 << 7,
Jack Morgensteind2b57062012-08-03 08:40:37 +0000806 /* reserve bits 26-31 for low level drivers' internal use */
807 IB_QP_CREATE_RESERVED_START = 1 << 26,
808 IB_QP_CREATE_RESERVED_END = 1 << 31,
Eli Cohenb846f252008-04-16 21:09:27 -0700809};
810
Yishai Hadas73c40c62013-08-01 18:49:53 +0300811
812/*
813 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
814 * callback to destroy the passed in QP.
815 */
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817struct ib_qp_init_attr {
818 void (*event_handler)(struct ib_event *, void *);
819 void *qp_context;
820 struct ib_cq *send_cq;
821 struct ib_cq *recv_cq;
822 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700823 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 struct ib_qp_cap cap;
825 enum ib_sig_type sq_sig_type;
826 enum ib_qp_type qp_type;
Eli Cohenb846f252008-04-16 21:09:27 -0700827 enum ib_qp_create_flags create_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 u8 port_num; /* special QP types only */
829};
830
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700831struct ib_qp_open_attr {
832 void (*event_handler)(struct ib_event *, void *);
833 void *qp_context;
834 u32 qp_num;
835 enum ib_qp_type qp_type;
836};
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838enum ib_rnr_timeout {
839 IB_RNR_TIMER_655_36 = 0,
840 IB_RNR_TIMER_000_01 = 1,
841 IB_RNR_TIMER_000_02 = 2,
842 IB_RNR_TIMER_000_03 = 3,
843 IB_RNR_TIMER_000_04 = 4,
844 IB_RNR_TIMER_000_06 = 5,
845 IB_RNR_TIMER_000_08 = 6,
846 IB_RNR_TIMER_000_12 = 7,
847 IB_RNR_TIMER_000_16 = 8,
848 IB_RNR_TIMER_000_24 = 9,
849 IB_RNR_TIMER_000_32 = 10,
850 IB_RNR_TIMER_000_48 = 11,
851 IB_RNR_TIMER_000_64 = 12,
852 IB_RNR_TIMER_000_96 = 13,
853 IB_RNR_TIMER_001_28 = 14,
854 IB_RNR_TIMER_001_92 = 15,
855 IB_RNR_TIMER_002_56 = 16,
856 IB_RNR_TIMER_003_84 = 17,
857 IB_RNR_TIMER_005_12 = 18,
858 IB_RNR_TIMER_007_68 = 19,
859 IB_RNR_TIMER_010_24 = 20,
860 IB_RNR_TIMER_015_36 = 21,
861 IB_RNR_TIMER_020_48 = 22,
862 IB_RNR_TIMER_030_72 = 23,
863 IB_RNR_TIMER_040_96 = 24,
864 IB_RNR_TIMER_061_44 = 25,
865 IB_RNR_TIMER_081_92 = 26,
866 IB_RNR_TIMER_122_88 = 27,
867 IB_RNR_TIMER_163_84 = 28,
868 IB_RNR_TIMER_245_76 = 29,
869 IB_RNR_TIMER_327_68 = 30,
870 IB_RNR_TIMER_491_52 = 31
871};
872
873enum ib_qp_attr_mask {
874 IB_QP_STATE = 1,
875 IB_QP_CUR_STATE = (1<<1),
876 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
877 IB_QP_ACCESS_FLAGS = (1<<3),
878 IB_QP_PKEY_INDEX = (1<<4),
879 IB_QP_PORT = (1<<5),
880 IB_QP_QKEY = (1<<6),
881 IB_QP_AV = (1<<7),
882 IB_QP_PATH_MTU = (1<<8),
883 IB_QP_TIMEOUT = (1<<9),
884 IB_QP_RETRY_CNT = (1<<10),
885 IB_QP_RNR_RETRY = (1<<11),
886 IB_QP_RQ_PSN = (1<<12),
887 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
888 IB_QP_ALT_PATH = (1<<14),
889 IB_QP_MIN_RNR_TIMER = (1<<15),
890 IB_QP_SQ_PSN = (1<<16),
891 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
892 IB_QP_PATH_MIG_STATE = (1<<18),
893 IB_QP_CAP = (1<<19),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200894 IB_QP_DEST_QPN = (1<<20),
895 IB_QP_SMAC = (1<<21),
896 IB_QP_ALT_SMAC = (1<<22),
897 IB_QP_VID = (1<<23),
898 IB_QP_ALT_VID = (1<<24),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899};
900
901enum ib_qp_state {
902 IB_QPS_RESET,
903 IB_QPS_INIT,
904 IB_QPS_RTR,
905 IB_QPS_RTS,
906 IB_QPS_SQD,
907 IB_QPS_SQE,
908 IB_QPS_ERR
909};
910
911enum ib_mig_state {
912 IB_MIG_MIGRATED,
913 IB_MIG_REARM,
914 IB_MIG_ARMED
915};
916
Shani Michaeli7083e422013-02-06 16:19:12 +0000917enum ib_mw_type {
918 IB_MW_TYPE_1 = 1,
919 IB_MW_TYPE_2 = 2
920};
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922struct ib_qp_attr {
923 enum ib_qp_state qp_state;
924 enum ib_qp_state cur_qp_state;
925 enum ib_mtu path_mtu;
926 enum ib_mig_state path_mig_state;
927 u32 qkey;
928 u32 rq_psn;
929 u32 sq_psn;
930 u32 dest_qp_num;
931 int qp_access_flags;
932 struct ib_qp_cap cap;
933 struct ib_ah_attr ah_attr;
934 struct ib_ah_attr alt_ah_attr;
935 u16 pkey_index;
936 u16 alt_pkey_index;
937 u8 en_sqd_async_notify;
938 u8 sq_draining;
939 u8 max_rd_atomic;
940 u8 max_dest_rd_atomic;
941 u8 min_rnr_timer;
942 u8 port_num;
943 u8 timeout;
944 u8 retry_cnt;
945 u8 rnr_retry;
946 u8 alt_port_num;
947 u8 alt_timeout;
Matan Barakdd5f03b2013-12-12 18:03:11 +0200948 u8 smac[ETH_ALEN];
949 u8 alt_smac[ETH_ALEN];
950 u16 vlan_id;
951 u16 alt_vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952};
953
954enum ib_wr_opcode {
955 IB_WR_RDMA_WRITE,
956 IB_WR_RDMA_WRITE_WITH_IMM,
957 IB_WR_SEND,
958 IB_WR_SEND_WITH_IMM,
959 IB_WR_RDMA_READ,
960 IB_WR_ATOMIC_CMP_AND_SWP,
Eli Cohenc93570f2008-04-16 21:09:27 -0700961 IB_WR_ATOMIC_FETCH_AND_ADD,
Roland Dreier0f39cf32008-04-16 21:09:32 -0700962 IB_WR_LSO,
963 IB_WR_SEND_WITH_INV,
Steve Wise00f7ec32008-07-14 23:48:45 -0700964 IB_WR_RDMA_READ_WITH_INV,
965 IB_WR_LOCAL_INV,
966 IB_WR_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300967 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
968 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
Shani Michaeli7083e422013-02-06 16:19:12 +0000969 IB_WR_BIND_MW,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200970 IB_WR_REG_SIG_MR,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300971 /* reserve values for low level drivers' internal use.
972 * These values will not be used at all in the ib core layer.
973 */
974 IB_WR_RESERVED1 = 0xf0,
975 IB_WR_RESERVED2,
976 IB_WR_RESERVED3,
977 IB_WR_RESERVED4,
978 IB_WR_RESERVED5,
979 IB_WR_RESERVED6,
980 IB_WR_RESERVED7,
981 IB_WR_RESERVED8,
982 IB_WR_RESERVED9,
983 IB_WR_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984};
985
986enum ib_send_flags {
987 IB_SEND_FENCE = 1,
988 IB_SEND_SIGNALED = (1<<1),
989 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +0200990 IB_SEND_INLINE = (1<<3),
Jack Morgenstein0134f162013-07-07 17:25:52 +0300991 IB_SEND_IP_CSUM = (1<<4),
992
993 /* reserve bits 26-31 for low level drivers' internal use */
994 IB_SEND_RESERVED_START = (1 << 26),
995 IB_SEND_RESERVED_END = (1 << 31),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996};
997
998struct ib_sge {
999 u64 addr;
1000 u32 length;
1001 u32 lkey;
1002};
1003
Steve Wise00f7ec32008-07-14 23:48:45 -07001004struct ib_fast_reg_page_list {
1005 struct ib_device *device;
1006 u64 *page_list;
1007 unsigned int max_page_list_len;
1008};
1009
Shani Michaeli7083e422013-02-06 16:19:12 +00001010/**
1011 * struct ib_mw_bind_info - Parameters for a memory window bind operation.
1012 * @mr: A memory region to bind the memory window to.
1013 * @addr: The address where the memory window should begin.
1014 * @length: The length of the memory window, in bytes.
1015 * @mw_access_flags: Access flags from enum ib_access_flags for the window.
1016 *
1017 * This struct contains the shared parameters for type 1 and type 2
1018 * memory window bind operations.
1019 */
1020struct ib_mw_bind_info {
1021 struct ib_mr *mr;
1022 u64 addr;
1023 u64 length;
1024 int mw_access_flags;
1025};
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027struct ib_send_wr {
1028 struct ib_send_wr *next;
1029 u64 wr_id;
1030 struct ib_sge *sg_list;
1031 int num_sge;
1032 enum ib_wr_opcode opcode;
1033 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -07001034 union {
1035 __be32 imm_data;
1036 u32 invalidate_rkey;
1037 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 union {
1039 struct {
1040 u64 remote_addr;
1041 u32 rkey;
1042 } rdma;
1043 struct {
1044 u64 remote_addr;
1045 u64 compare_add;
1046 u64 swap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +03001047 u64 compare_add_mask;
1048 u64 swap_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 u32 rkey;
1050 } atomic;
1051 struct {
1052 struct ib_ah *ah;
Eli Cohenc93570f2008-04-16 21:09:27 -07001053 void *header;
1054 int hlen;
1055 int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 u32 remote_qpn;
1057 u32 remote_qkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 u16 pkey_index; /* valid for GSI only */
1059 u8 port_num; /* valid for DR SMPs on switch only */
1060 } ud;
Steve Wise00f7ec32008-07-14 23:48:45 -07001061 struct {
1062 u64 iova_start;
1063 struct ib_fast_reg_page_list *page_list;
1064 unsigned int page_shift;
1065 unsigned int page_list_len;
1066 u32 length;
1067 int access_flags;
1068 u32 rkey;
1069 } fast_reg;
Shani Michaeli7083e422013-02-06 16:19:12 +00001070 struct {
1071 struct ib_mw *mw;
1072 /* The new rkey for the memory window. */
1073 u32 rkey;
1074 struct ib_mw_bind_info bind_info;
1075 } bind_mw;
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001076 struct {
1077 struct ib_sig_attrs *sig_attrs;
1078 struct ib_mr *sig_mr;
1079 int access_flags;
1080 struct ib_sge *prot;
1081 } sig_handover;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 } wr;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001083 u32 xrc_remote_srq_num; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084};
1085
1086struct ib_recv_wr {
1087 struct ib_recv_wr *next;
1088 u64 wr_id;
1089 struct ib_sge *sg_list;
1090 int num_sge;
1091};
1092
1093enum ib_access_flags {
1094 IB_ACCESS_LOCAL_WRITE = 1,
1095 IB_ACCESS_REMOTE_WRITE = (1<<1),
1096 IB_ACCESS_REMOTE_READ = (1<<2),
1097 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
Shani Michaeli7083e422013-02-06 16:19:12 +00001098 IB_ACCESS_MW_BIND = (1<<4),
Sagi Grimberg860f10a2014-12-11 17:04:16 +02001099 IB_ZERO_BASED = (1<<5),
1100 IB_ACCESS_ON_DEMAND = (1<<6),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101};
1102
1103struct ib_phys_buf {
1104 u64 addr;
1105 u64 size;
1106};
1107
1108struct ib_mr_attr {
1109 struct ib_pd *pd;
1110 u64 device_virt_addr;
1111 u64 size;
1112 int mr_access_flags;
1113 u32 lkey;
1114 u32 rkey;
1115};
1116
1117enum ib_mr_rereg_flags {
1118 IB_MR_REREG_TRANS = 1,
1119 IB_MR_REREG_PD = (1<<1),
Matan Barak7e6edb92014-07-31 11:01:28 +03001120 IB_MR_REREG_ACCESS = (1<<2),
1121 IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122};
1123
Shani Michaeli7083e422013-02-06 16:19:12 +00001124/**
1125 * struct ib_mw_bind - Parameters for a type 1 memory window bind operation.
1126 * @wr_id: Work request id.
1127 * @send_flags: Flags from ib_send_flags enum.
1128 * @bind_info: More parameters of the bind operation.
1129 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130struct ib_mw_bind {
Shani Michaeli7083e422013-02-06 16:19:12 +00001131 u64 wr_id;
1132 int send_flags;
1133 struct ib_mw_bind_info bind_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134};
1135
1136struct ib_fmr_attr {
1137 int max_pages;
1138 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -08001139 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140};
1141
Roland Dreiere2773c02005-07-07 17:57:10 -07001142struct ib_ucontext {
1143 struct ib_device *device;
1144 struct list_head pd_list;
1145 struct list_head mr_list;
1146 struct list_head mw_list;
1147 struct list_head cq_list;
1148 struct list_head qp_list;
1149 struct list_head srq_list;
1150 struct list_head ah_list;
Sean Hefty53d0bd12011-05-24 08:33:46 -07001151 struct list_head xrcd_list;
Hadar Hen Zion436f2ad2013-08-14 13:58:30 +03001152 struct list_head rule_list;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001153 int closing;
Roland Dreiere2773c02005-07-07 17:57:10 -07001154};
1155
1156struct ib_uobject {
1157 u64 user_handle; /* handle given to us by userspace */
1158 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -07001159 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -07001160 struct list_head list; /* link to context's list */
Roland Dreierb3d636b2008-04-16 21:01:06 -07001161 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -07001162 struct kref ref;
1163 struct rw_semaphore mutex; /* protects .live */
1164 int live;
Roland Dreiere2773c02005-07-07 17:57:10 -07001165};
1166
Roland Dreiere2773c02005-07-07 17:57:10 -07001167struct ib_udata {
Yann Droneaud309243e2013-12-11 23:01:44 +01001168 const void __user *inbuf;
Roland Dreiere2773c02005-07-07 17:57:10 -07001169 void __user *outbuf;
1170 size_t inlen;
1171 size_t outlen;
1172};
1173
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174struct ib_pd {
Roland Dreiere2773c02005-07-07 17:57:10 -07001175 struct ib_device *device;
1176 struct ib_uobject *uobject;
1177 atomic_t usecnt; /* count all resources */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178};
1179
Sean Hefty59991f92011-05-23 17:52:46 -07001180struct ib_xrcd {
1181 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001182 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -07001183 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001184
1185 struct mutex tgt_qp_mutex;
1186 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -07001187};
1188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189struct ib_ah {
1190 struct ib_device *device;
1191 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001192 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193};
1194
1195typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1196
1197struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -07001198 struct ib_device *device;
1199 struct ib_uobject *uobject;
1200 ib_comp_handler comp_handler;
1201 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -07001202 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -07001203 int cqe;
1204 atomic_t usecnt; /* count number of work queues */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205};
1206
1207struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -07001208 struct ib_device *device;
1209 struct ib_pd *pd;
1210 struct ib_uobject *uobject;
1211 void (*event_handler)(struct ib_event *, void *);
1212 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -07001213 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -07001215
1216 union {
1217 struct {
1218 struct ib_xrcd *xrcd;
1219 struct ib_cq *cq;
1220 u32 srq_num;
1221 } xrc;
1222 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223};
1224
1225struct ib_qp {
1226 struct ib_device *device;
1227 struct ib_pd *pd;
1228 struct ib_cq *send_cq;
1229 struct ib_cq *recv_cq;
1230 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001231 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -07001232 struct list_head xrcd_list;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001233 /* count times opened, mcast attaches, flow attaches */
1234 atomic_t usecnt;
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001235 struct list_head open_list;
1236 struct ib_qp *real_qp;
Roland Dreiere2773c02005-07-07 17:57:10 -07001237 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 void (*event_handler)(struct ib_event *, void *);
1239 void *qp_context;
1240 u32 qp_num;
1241 enum ib_qp_type qp_type;
1242};
1243
1244struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -07001245 struct ib_device *device;
1246 struct ib_pd *pd;
1247 struct ib_uobject *uobject;
1248 u32 lkey;
1249 u32 rkey;
1250 atomic_t usecnt; /* count number of MWs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251};
1252
1253struct ib_mw {
1254 struct ib_device *device;
1255 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001256 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 u32 rkey;
Shani Michaeli7083e422013-02-06 16:19:12 +00001258 enum ib_mw_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259};
1260
1261struct ib_fmr {
1262 struct ib_device *device;
1263 struct ib_pd *pd;
1264 struct list_head list;
1265 u32 lkey;
1266 u32 rkey;
1267};
1268
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001269/* Supported steering options */
1270enum ib_flow_attr_type {
1271 /* steering according to rule specifications */
1272 IB_FLOW_ATTR_NORMAL = 0x0,
1273 /* default unicast and multicast rule -
1274 * receive all Eth traffic which isn't steered to any QP
1275 */
1276 IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1277 /* default multicast rule -
1278 * receive all Eth multicast traffic which isn't steered to any QP
1279 */
1280 IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1281 /* sniffer rule - receive all port traffic */
1282 IB_FLOW_ATTR_SNIFFER = 0x3
1283};
1284
1285/* Supported steering header types */
1286enum ib_flow_spec_type {
1287 /* L2 headers*/
1288 IB_FLOW_SPEC_ETH = 0x20,
Matan Barak240ae002013-11-07 15:25:13 +02001289 IB_FLOW_SPEC_IB = 0x22,
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001290 /* L3 header*/
1291 IB_FLOW_SPEC_IPV4 = 0x30,
1292 /* L4 headers*/
1293 IB_FLOW_SPEC_TCP = 0x40,
1294 IB_FLOW_SPEC_UDP = 0x41
1295};
Matan Barak240ae002013-11-07 15:25:13 +02001296#define IB_FLOW_SPEC_LAYER_MASK 0xF0
Matan Barak22878db2013-09-01 18:39:52 +03001297#define IB_FLOW_SPEC_SUPPORT_LAYERS 4
1298
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001299/* Flow steering rule priority is set according to it's domain.
1300 * Lower domain value means higher priority.
1301 */
1302enum ib_flow_domain {
1303 IB_FLOW_DOMAIN_USER,
1304 IB_FLOW_DOMAIN_ETHTOOL,
1305 IB_FLOW_DOMAIN_RFS,
1306 IB_FLOW_DOMAIN_NIC,
1307 IB_FLOW_DOMAIN_NUM /* Must be last */
1308};
1309
1310struct ib_flow_eth_filter {
1311 u8 dst_mac[6];
1312 u8 src_mac[6];
1313 __be16 ether_type;
1314 __be16 vlan_tag;
1315};
1316
1317struct ib_flow_spec_eth {
1318 enum ib_flow_spec_type type;
1319 u16 size;
1320 struct ib_flow_eth_filter val;
1321 struct ib_flow_eth_filter mask;
1322};
1323
Matan Barak240ae002013-11-07 15:25:13 +02001324struct ib_flow_ib_filter {
1325 __be16 dlid;
1326 __u8 sl;
1327};
1328
1329struct ib_flow_spec_ib {
1330 enum ib_flow_spec_type type;
1331 u16 size;
1332 struct ib_flow_ib_filter val;
1333 struct ib_flow_ib_filter mask;
1334};
1335
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001336struct ib_flow_ipv4_filter {
1337 __be32 src_ip;
1338 __be32 dst_ip;
1339};
1340
1341struct ib_flow_spec_ipv4 {
1342 enum ib_flow_spec_type type;
1343 u16 size;
1344 struct ib_flow_ipv4_filter val;
1345 struct ib_flow_ipv4_filter mask;
1346};
1347
1348struct ib_flow_tcp_udp_filter {
1349 __be16 dst_port;
1350 __be16 src_port;
1351};
1352
1353struct ib_flow_spec_tcp_udp {
1354 enum ib_flow_spec_type type;
1355 u16 size;
1356 struct ib_flow_tcp_udp_filter val;
1357 struct ib_flow_tcp_udp_filter mask;
1358};
1359
1360union ib_flow_spec {
1361 struct {
1362 enum ib_flow_spec_type type;
1363 u16 size;
1364 };
1365 struct ib_flow_spec_eth eth;
Matan Barak240ae002013-11-07 15:25:13 +02001366 struct ib_flow_spec_ib ib;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001367 struct ib_flow_spec_ipv4 ipv4;
1368 struct ib_flow_spec_tcp_udp tcp_udp;
1369};
1370
1371struct ib_flow_attr {
1372 enum ib_flow_attr_type type;
1373 u16 size;
1374 u16 priority;
1375 u32 flags;
1376 u8 num_of_specs;
1377 u8 port;
1378 /* Following are the optional layers according to user request
1379 * struct ib_flow_spec_xxx
1380 * struct ib_flow_spec_yyy
1381 */
1382};
1383
1384struct ib_flow {
1385 struct ib_qp *qp;
1386 struct ib_uobject *uobject;
1387};
1388
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389struct ib_mad;
1390struct ib_grh;
1391
1392enum ib_process_mad_flags {
1393 IB_MAD_IGNORE_MKEY = 1,
1394 IB_MAD_IGNORE_BKEY = 2,
1395 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1396};
1397
1398enum ib_mad_result {
1399 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
1400 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
1401 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
1402 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
1403};
1404
1405#define IB_DEVICE_NAME_MAX 64
1406
1407struct ib_cache {
1408 rwlock_t lock;
1409 struct ib_event_handler event_handler;
1410 struct ib_pkey_cache **pkey_cache;
1411 struct ib_gid_cache **gid_cache;
Jack Morgenstein6fb9cdb2006-06-17 20:37:34 -07001412 u8 *lmc_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413};
1414
Ralph Campbell9b513092006-12-12 14:27:41 -08001415struct ib_dma_mapping_ops {
1416 int (*mapping_error)(struct ib_device *dev,
1417 u64 dma_addr);
1418 u64 (*map_single)(struct ib_device *dev,
1419 void *ptr, size_t size,
1420 enum dma_data_direction direction);
1421 void (*unmap_single)(struct ib_device *dev,
1422 u64 addr, size_t size,
1423 enum dma_data_direction direction);
1424 u64 (*map_page)(struct ib_device *dev,
1425 struct page *page, unsigned long offset,
1426 size_t size,
1427 enum dma_data_direction direction);
1428 void (*unmap_page)(struct ib_device *dev,
1429 u64 addr, size_t size,
1430 enum dma_data_direction direction);
1431 int (*map_sg)(struct ib_device *dev,
1432 struct scatterlist *sg, int nents,
1433 enum dma_data_direction direction);
1434 void (*unmap_sg)(struct ib_device *dev,
1435 struct scatterlist *sg, int nents,
1436 enum dma_data_direction direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001437 void (*sync_single_for_cpu)(struct ib_device *dev,
1438 u64 dma_handle,
1439 size_t size,
Dotan Barak4deccd62008-07-14 23:48:44 -07001440 enum dma_data_direction dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08001441 void (*sync_single_for_device)(struct ib_device *dev,
1442 u64 dma_handle,
1443 size_t size,
1444 enum dma_data_direction dir);
1445 void *(*alloc_coherent)(struct ib_device *dev,
1446 size_t size,
1447 u64 *dma_handle,
1448 gfp_t flag);
1449 void (*free_coherent)(struct ib_device *dev,
1450 size_t size, void *cpu_addr,
1451 u64 dma_handle);
1452};
1453
Tom Tucker07ebafb2006-08-03 16:02:42 -05001454struct iw_cm_verbs;
1455
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456struct ib_device {
1457 struct device *dma_device;
1458
1459 char name[IB_DEVICE_NAME_MAX];
1460
1461 struct list_head event_handler_list;
1462 spinlock_t event_handler_lock;
1463
Alexander Chiang17a55f72010-02-02 19:09:16 +00001464 spinlock_t client_data_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 struct list_head core_list;
1466 struct list_head client_data_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 struct ib_cache cache;
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001469 int *pkey_tbl_len;
1470 int *gid_tbl_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001472 int num_comp_vectors;
1473
Tom Tucker07ebafb2006-08-03 16:02:42 -05001474 struct iw_cm_verbs *iwcm;
1475
Steve Wise7f624d02008-07-14 23:48:48 -07001476 int (*get_protocol_stats)(struct ib_device *device,
1477 union rdma_protocol_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 int (*query_device)(struct ib_device *device,
1479 struct ib_device_attr *device_attr);
1480 int (*query_port)(struct ib_device *device,
1481 u8 port_num,
1482 struct ib_port_attr *port_attr);
Eli Cohena3f5ada2010-09-27 17:51:10 -07001483 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1484 u8 port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 int (*query_gid)(struct ib_device *device,
1486 u8 port_num, int index,
1487 union ib_gid *gid);
1488 int (*query_pkey)(struct ib_device *device,
1489 u8 port_num, u16 index, u16 *pkey);
1490 int (*modify_device)(struct ib_device *device,
1491 int device_modify_mask,
1492 struct ib_device_modify *device_modify);
1493 int (*modify_port)(struct ib_device *device,
1494 u8 port_num, int port_modify_mask,
1495 struct ib_port_modify *port_modify);
Roland Dreiere2773c02005-07-07 17:57:10 -07001496 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1497 struct ib_udata *udata);
1498 int (*dealloc_ucontext)(struct ib_ucontext *context);
1499 int (*mmap)(struct ib_ucontext *context,
1500 struct vm_area_struct *vma);
1501 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1502 struct ib_ucontext *context,
1503 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 int (*dealloc_pd)(struct ib_pd *pd);
1505 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1506 struct ib_ah_attr *ah_attr);
1507 int (*modify_ah)(struct ib_ah *ah,
1508 struct ib_ah_attr *ah_attr);
1509 int (*query_ah)(struct ib_ah *ah,
1510 struct ib_ah_attr *ah_attr);
1511 int (*destroy_ah)(struct ib_ah *ah);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001512 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1513 struct ib_srq_init_attr *srq_init_attr,
1514 struct ib_udata *udata);
1515 int (*modify_srq)(struct ib_srq *srq,
1516 struct ib_srq_attr *srq_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001517 enum ib_srq_attr_mask srq_attr_mask,
1518 struct ib_udata *udata);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001519 int (*query_srq)(struct ib_srq *srq,
1520 struct ib_srq_attr *srq_attr);
1521 int (*destroy_srq)(struct ib_srq *srq);
1522 int (*post_srq_recv)(struct ib_srq *srq,
1523 struct ib_recv_wr *recv_wr,
1524 struct ib_recv_wr **bad_recv_wr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 struct ib_qp * (*create_qp)(struct ib_pd *pd,
Roland Dreiere2773c02005-07-07 17:57:10 -07001526 struct ib_qp_init_attr *qp_init_attr,
1527 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 int (*modify_qp)(struct ib_qp *qp,
1529 struct ib_qp_attr *qp_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001530 int qp_attr_mask,
1531 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 int (*query_qp)(struct ib_qp *qp,
1533 struct ib_qp_attr *qp_attr,
1534 int qp_attr_mask,
1535 struct ib_qp_init_attr *qp_init_attr);
1536 int (*destroy_qp)(struct ib_qp *qp);
1537 int (*post_send)(struct ib_qp *qp,
1538 struct ib_send_wr *send_wr,
1539 struct ib_send_wr **bad_send_wr);
1540 int (*post_recv)(struct ib_qp *qp,
1541 struct ib_recv_wr *recv_wr,
1542 struct ib_recv_wr **bad_recv_wr);
Roland Dreiere2773c02005-07-07 17:57:10 -07001543 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001544 int comp_vector,
Roland Dreiere2773c02005-07-07 17:57:10 -07001545 struct ib_ucontext *context,
1546 struct ib_udata *udata);
Eli Cohen2dd57162008-04-16 21:09:33 -07001547 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1548 u16 cq_period);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 int (*destroy_cq)(struct ib_cq *cq);
Roland Dreier33b9b3e2006-01-30 14:29:21 -08001550 int (*resize_cq)(struct ib_cq *cq, int cqe,
1551 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1553 struct ib_wc *wc);
1554 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1555 int (*req_notify_cq)(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001556 enum ib_cq_notify_flags flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 int (*req_ncomp_notif)(struct ib_cq *cq,
1558 int wc_cnt);
1559 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1560 int mr_access_flags);
1561 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
1562 struct ib_phys_buf *phys_buf_array,
1563 int num_phys_buf,
1564 int mr_access_flags,
1565 u64 *iova_start);
Roland Dreiere2773c02005-07-07 17:57:10 -07001566 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001567 u64 start, u64 length,
1568 u64 virt_addr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001569 int mr_access_flags,
1570 struct ib_udata *udata);
Matan Barak7e6edb92014-07-31 11:01:28 +03001571 int (*rereg_user_mr)(struct ib_mr *mr,
1572 int flags,
1573 u64 start, u64 length,
1574 u64 virt_addr,
1575 int mr_access_flags,
1576 struct ib_pd *pd,
1577 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 int (*query_mr)(struct ib_mr *mr,
1579 struct ib_mr_attr *mr_attr);
1580 int (*dereg_mr)(struct ib_mr *mr);
Sagi Grimberg17cd3a22014-02-23 14:19:04 +02001581 int (*destroy_mr)(struct ib_mr *mr);
1582 struct ib_mr * (*create_mr)(struct ib_pd *pd,
1583 struct ib_mr_init_attr *mr_init_attr);
Steve Wise00f7ec32008-07-14 23:48:45 -07001584 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
1585 int max_page_list_len);
1586 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1587 int page_list_len);
1588 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 int (*rereg_phys_mr)(struct ib_mr *mr,
1590 int mr_rereg_mask,
1591 struct ib_pd *pd,
1592 struct ib_phys_buf *phys_buf_array,
1593 int num_phys_buf,
1594 int mr_access_flags,
1595 u64 *iova_start);
Shani Michaeli7083e422013-02-06 16:19:12 +00001596 struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
1597 enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 int (*bind_mw)(struct ib_qp *qp,
1599 struct ib_mw *mw,
1600 struct ib_mw_bind *mw_bind);
1601 int (*dealloc_mw)(struct ib_mw *mw);
1602 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1603 int mr_access_flags,
1604 struct ib_fmr_attr *fmr_attr);
1605 int (*map_phys_fmr)(struct ib_fmr *fmr,
1606 u64 *page_list, int list_len,
1607 u64 iova);
1608 int (*unmap_fmr)(struct list_head *fmr_list);
1609 int (*dealloc_fmr)(struct ib_fmr *fmr);
1610 int (*attach_mcast)(struct ib_qp *qp,
1611 union ib_gid *gid,
1612 u16 lid);
1613 int (*detach_mcast)(struct ib_qp *qp,
1614 union ib_gid *gid,
1615 u16 lid);
1616 int (*process_mad)(struct ib_device *device,
1617 int process_mad_flags,
1618 u8 port_num,
1619 struct ib_wc *in_wc,
1620 struct ib_grh *in_grh,
1621 struct ib_mad *in_mad,
1622 struct ib_mad *out_mad);
Sean Hefty59991f92011-05-23 17:52:46 -07001623 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1624 struct ib_ucontext *ucontext,
1625 struct ib_udata *udata);
1626 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001627 struct ib_flow * (*create_flow)(struct ib_qp *qp,
1628 struct ib_flow_attr
1629 *flow_attr,
1630 int domain);
1631 int (*destroy_flow)(struct ib_flow *flow_id);
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001632 int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
1633 struct ib_mr_status *mr_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Ralph Campbell9b513092006-12-12 14:27:41 -08001635 struct ib_dma_mapping_ops *dma_ops;
1636
Roland Dreiere2773c02005-07-07 17:57:10 -07001637 struct module *owner;
Tony Jonesf4e91eb2008-02-22 00:13:36 +01001638 struct device dev;
Greg Kroah-Hartman35be0682007-12-17 15:54:39 -04001639 struct kobject *ports_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 struct list_head port_list;
1641
1642 enum {
1643 IB_DEV_UNINITIALIZED,
1644 IB_DEV_REGISTERED,
1645 IB_DEV_UNREGISTERED
1646 } reg_state;
1647
Roland Dreier274c0892005-09-29 14:17:48 -07001648 int uverbs_abi_ver;
Alexander Chiang17a55f72010-02-02 19:09:16 +00001649 u64 uverbs_cmd_mask;
Yann Droneaudf21519b2013-11-06 23:21:49 +01001650 u64 uverbs_ex_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07001651
Roland Dreierc5bcbbb2006-02-02 09:47:14 -08001652 char node_desc[64];
Sean Heftycf311cd2006-01-10 07:39:34 -08001653 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07001654 u32 local_dma_lkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 u8 node_type;
1656 u8 phys_port_cnt;
1657};
1658
1659struct ib_client {
1660 char *name;
1661 void (*add) (struct ib_device *);
1662 void (*remove)(struct ib_device *);
1663
1664 struct list_head list;
1665};
1666
1667struct ib_device *ib_alloc_device(size_t size);
1668void ib_dealloc_device(struct ib_device *device);
1669
Ralph Campbell9a6edb62010-05-06 17:03:25 -07001670int ib_register_device(struct ib_device *device,
1671 int (*port_callback)(struct ib_device *,
1672 u8, struct kobject *));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673void ib_unregister_device(struct ib_device *device);
1674
1675int ib_register_client (struct ib_client *client);
1676void ib_unregister_client(struct ib_client *client);
1677
1678void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1679void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1680 void *data);
1681
Roland Dreiere2773c02005-07-07 17:57:10 -07001682static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1683{
1684 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1685}
1686
1687static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1688{
Eli Cohen5a77abf2014-12-11 17:04:15 +02001689 size_t copy_sz;
1690
1691 copy_sz = min_t(size_t, len, udata->outlen);
1692 return copy_to_user(udata->outbuf, src, copy_sz) ? -EFAULT : 0;
Roland Dreiere2773c02005-07-07 17:57:10 -07001693}
1694
Roland Dreier8a518662006-02-13 12:48:12 -08001695/**
1696 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1697 * contains all required attributes and no attributes not allowed for
1698 * the given QP state transition.
1699 * @cur_state: Current QP state
1700 * @next_state: Next QP state
1701 * @type: QP type
1702 * @mask: Mask of supplied QP attributes
Matan Barakdd5f03b2013-12-12 18:03:11 +02001703 * @ll : link layer of port
Roland Dreier8a518662006-02-13 12:48:12 -08001704 *
1705 * This function is a helper function that a low-level driver's
1706 * modify_qp method can use to validate the consumer's input. It
1707 * checks that cur_state and next_state are valid QP states, that a
1708 * transition from cur_state to next_state is allowed by the IB spec,
1709 * and that the attribute mask supplied is allowed for the transition.
1710 */
1711int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
Matan Barakdd5f03b2013-12-12 18:03:11 +02001712 enum ib_qp_type type, enum ib_qp_attr_mask mask,
1713 enum rdma_link_layer ll);
Roland Dreier8a518662006-02-13 12:48:12 -08001714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715int ib_register_event_handler (struct ib_event_handler *event_handler);
1716int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1717void ib_dispatch_event(struct ib_event *event);
1718
1719int ib_query_device(struct ib_device *device,
1720 struct ib_device_attr *device_attr);
1721
1722int ib_query_port(struct ib_device *device,
1723 u8 port_num, struct ib_port_attr *port_attr);
1724
Eli Cohena3f5ada2010-09-27 17:51:10 -07001725enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1726 u8 port_num);
1727
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728int ib_query_gid(struct ib_device *device,
1729 u8 port_num, int index, union ib_gid *gid);
1730
1731int ib_query_pkey(struct ib_device *device,
1732 u8 port_num, u16 index, u16 *pkey);
1733
1734int ib_modify_device(struct ib_device *device,
1735 int device_modify_mask,
1736 struct ib_device_modify *device_modify);
1737
1738int ib_modify_port(struct ib_device *device,
1739 u8 port_num, int port_modify_mask,
1740 struct ib_port_modify *port_modify);
1741
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001742int ib_find_gid(struct ib_device *device, union ib_gid *gid,
1743 u8 *port_num, u16 *index);
1744
1745int ib_find_pkey(struct ib_device *device,
1746 u8 port_num, u16 pkey, u16 *index);
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748/**
1749 * ib_alloc_pd - Allocates an unused protection domain.
1750 * @device: The device on which to allocate the protection domain.
1751 *
1752 * A protection domain object provides an association between QPs, shared
1753 * receive queues, address handles, memory regions, and memory windows.
1754 */
1755struct ib_pd *ib_alloc_pd(struct ib_device *device);
1756
1757/**
1758 * ib_dealloc_pd - Deallocates a protection domain.
1759 * @pd: The protection domain to deallocate.
1760 */
1761int ib_dealloc_pd(struct ib_pd *pd);
1762
1763/**
1764 * ib_create_ah - Creates an address handle for the given address vector.
1765 * @pd: The protection domain associated with the address handle.
1766 * @ah_attr: The attributes of the address vector.
1767 *
1768 * The address handle is used to reference a local or global destination
1769 * in all UD QP post sends.
1770 */
1771struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1772
1773/**
Sean Hefty4e00d692006-06-17 20:37:39 -07001774 * ib_init_ah_from_wc - Initializes address handle attributes from a
1775 * work completion.
1776 * @device: Device on which the received message arrived.
1777 * @port_num: Port on which the received message arrived.
1778 * @wc: Work completion associated with the received message.
1779 * @grh: References the received global route header. This parameter is
1780 * ignored unless the work completion indicates that the GRH is valid.
1781 * @ah_attr: Returned attributes that can be used when creating an address
1782 * handle for replying to the message.
1783 */
1784int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1785 struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1786
1787/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07001788 * ib_create_ah_from_wc - Creates an address handle associated with the
1789 * sender of the specified work completion.
1790 * @pd: The protection domain associated with the address handle.
1791 * @wc: Work completion information associated with a received message.
1792 * @grh: References the received global route header. This parameter is
1793 * ignored unless the work completion indicates that the GRH is valid.
1794 * @port_num: The outbound port number to associate with the address.
1795 *
1796 * The address handle is used to reference a local or global destination
1797 * in all UD QP post sends.
1798 */
1799struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1800 struct ib_grh *grh, u8 port_num);
1801
1802/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 * ib_modify_ah - Modifies the address vector associated with an address
1804 * handle.
1805 * @ah: The address handle to modify.
1806 * @ah_attr: The new address vector attributes to associate with the
1807 * address handle.
1808 */
1809int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1810
1811/**
1812 * ib_query_ah - Queries the address vector associated with an address
1813 * handle.
1814 * @ah: The address handle to query.
1815 * @ah_attr: The address vector attributes associated with the address
1816 * handle.
1817 */
1818int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1819
1820/**
1821 * ib_destroy_ah - Destroys an address handle.
1822 * @ah: The address handle to destroy.
1823 */
1824int ib_destroy_ah(struct ib_ah *ah);
1825
1826/**
Roland Dreierd41fcc62005-08-18 12:23:08 -07001827 * ib_create_srq - Creates a SRQ associated with the specified protection
1828 * domain.
1829 * @pd: The protection domain associated with the SRQ.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001830 * @srq_init_attr: A list of initial attributes required to create the
1831 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1832 * the actual capabilities of the created SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07001833 *
1834 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1835 * requested size of the SRQ, and set to the actual values allocated
1836 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
1837 * will always be at least as large as the requested values.
1838 */
1839struct ib_srq *ib_create_srq(struct ib_pd *pd,
1840 struct ib_srq_init_attr *srq_init_attr);
1841
1842/**
1843 * ib_modify_srq - Modifies the attributes for the specified SRQ.
1844 * @srq: The SRQ to modify.
1845 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1846 * the current values of selected SRQ attributes are returned.
1847 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1848 * are being modified.
1849 *
1850 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1851 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1852 * the number of receives queued drops below the limit.
1853 */
1854int ib_modify_srq(struct ib_srq *srq,
1855 struct ib_srq_attr *srq_attr,
1856 enum ib_srq_attr_mask srq_attr_mask);
1857
1858/**
1859 * ib_query_srq - Returns the attribute list and current values for the
1860 * specified SRQ.
1861 * @srq: The SRQ to query.
1862 * @srq_attr: The attributes of the specified SRQ.
1863 */
1864int ib_query_srq(struct ib_srq *srq,
1865 struct ib_srq_attr *srq_attr);
1866
1867/**
1868 * ib_destroy_srq - Destroys the specified SRQ.
1869 * @srq: The SRQ to destroy.
1870 */
1871int ib_destroy_srq(struct ib_srq *srq);
1872
1873/**
1874 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1875 * @srq: The SRQ to post the work request on.
1876 * @recv_wr: A list of work requests to post on the receive queue.
1877 * @bad_recv_wr: On an immediate failure, this parameter will reference
1878 * the work request that failed to be posted on the QP.
1879 */
1880static inline int ib_post_srq_recv(struct ib_srq *srq,
1881 struct ib_recv_wr *recv_wr,
1882 struct ib_recv_wr **bad_recv_wr)
1883{
1884 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1885}
1886
1887/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 * ib_create_qp - Creates a QP associated with the specified protection
1889 * domain.
1890 * @pd: The protection domain associated with the QP.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001891 * @qp_init_attr: A list of initial attributes required to create the
1892 * QP. If QP creation succeeds, then the attributes are updated to
1893 * the actual capabilities of the created QP.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 */
1895struct ib_qp *ib_create_qp(struct ib_pd *pd,
1896 struct ib_qp_init_attr *qp_init_attr);
1897
1898/**
1899 * ib_modify_qp - Modifies the attributes for the specified QP and then
1900 * transitions the QP to the given state.
1901 * @qp: The QP to modify.
1902 * @qp_attr: On input, specifies the QP attributes to modify. On output,
1903 * the current values of selected QP attributes are returned.
1904 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1905 * are being modified.
1906 */
1907int ib_modify_qp(struct ib_qp *qp,
1908 struct ib_qp_attr *qp_attr,
1909 int qp_attr_mask);
1910
1911/**
1912 * ib_query_qp - Returns the attribute list and current values for the
1913 * specified QP.
1914 * @qp: The QP to query.
1915 * @qp_attr: The attributes of the specified QP.
1916 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1917 * @qp_init_attr: Additional attributes of the selected QP.
1918 *
1919 * The qp_attr_mask may be used to limit the query to gathering only the
1920 * selected attributes.
1921 */
1922int ib_query_qp(struct ib_qp *qp,
1923 struct ib_qp_attr *qp_attr,
1924 int qp_attr_mask,
1925 struct ib_qp_init_attr *qp_init_attr);
1926
1927/**
1928 * ib_destroy_qp - Destroys the specified QP.
1929 * @qp: The QP to destroy.
1930 */
1931int ib_destroy_qp(struct ib_qp *qp);
1932
1933/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001934 * ib_open_qp - Obtain a reference to an existing sharable QP.
1935 * @xrcd - XRC domain
1936 * @qp_open_attr: Attributes identifying the QP to open.
1937 *
1938 * Returns a reference to a sharable QP.
1939 */
1940struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
1941 struct ib_qp_open_attr *qp_open_attr);
1942
1943/**
1944 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001945 * @qp: The QP handle to release
1946 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001947 * The opened QP handle is released by the caller. The underlying
1948 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001949 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001950int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07001951
1952/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 * ib_post_send - Posts a list of work requests to the send queue of
1954 * the specified QP.
1955 * @qp: The QP to post the work request on.
1956 * @send_wr: A list of work requests to post on the send queue.
1957 * @bad_send_wr: On an immediate failure, this parameter will reference
1958 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08001959 *
1960 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
1961 * error is returned, the QP state shall not be affected,
1962 * ib_post_send() will return an immediate error after queueing any
1963 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 */
1965static inline int ib_post_send(struct ib_qp *qp,
1966 struct ib_send_wr *send_wr,
1967 struct ib_send_wr **bad_send_wr)
1968{
1969 return qp->device->post_send(qp, send_wr, bad_send_wr);
1970}
1971
1972/**
1973 * ib_post_recv - Posts a list of work requests to the receive queue of
1974 * the specified QP.
1975 * @qp: The QP to post the work request on.
1976 * @recv_wr: A list of work requests to post on the receive queue.
1977 * @bad_recv_wr: On an immediate failure, this parameter will reference
1978 * the work request that failed to be posted on the QP.
1979 */
1980static inline int ib_post_recv(struct ib_qp *qp,
1981 struct ib_recv_wr *recv_wr,
1982 struct ib_recv_wr **bad_recv_wr)
1983{
1984 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1985}
1986
1987/**
1988 * ib_create_cq - Creates a CQ on the specified device.
1989 * @device: The device on which to create the CQ.
1990 * @comp_handler: A user-specified callback that is invoked when a
1991 * completion event occurs on the CQ.
1992 * @event_handler: A user-specified callback that is invoked when an
1993 * asynchronous event not associated with a completion occurs on the CQ.
1994 * @cq_context: Context associated with the CQ returned to the user via
1995 * the associated completion and event handlers.
1996 * @cqe: The minimum size of the CQ.
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001997 * @comp_vector - Completion vector used to signal completion events.
1998 * Must be >= 0 and < context->num_comp_vectors.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 *
2000 * Users can examine the cq structure to determine the actual CQ size.
2001 */
2002struct ib_cq *ib_create_cq(struct ib_device *device,
2003 ib_comp_handler comp_handler,
2004 void (*event_handler)(struct ib_event *, void *),
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03002005 void *cq_context, int cqe, int comp_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007/**
2008 * ib_resize_cq - Modifies the capacity of the CQ.
2009 * @cq: The CQ to resize.
2010 * @cqe: The minimum size of the CQ.
2011 *
2012 * Users can examine the cq structure to determine the actual CQ size.
2013 */
2014int ib_resize_cq(struct ib_cq *cq, int cqe);
2015
2016/**
Eli Cohen2dd57162008-04-16 21:09:33 -07002017 * ib_modify_cq - Modifies moderation params of the CQ
2018 * @cq: The CQ to modify.
2019 * @cq_count: number of CQEs that will trigger an event
2020 * @cq_period: max period of time in usec before triggering an event
2021 *
2022 */
2023int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
2024
2025/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 * ib_destroy_cq - Destroys the specified CQ.
2027 * @cq: The CQ to destroy.
2028 */
2029int ib_destroy_cq(struct ib_cq *cq);
2030
2031/**
2032 * ib_poll_cq - poll a CQ for completion(s)
2033 * @cq:the CQ being polled
2034 * @num_entries:maximum number of completions to return
2035 * @wc:array of at least @num_entries &struct ib_wc where completions
2036 * will be returned
2037 *
2038 * Poll a CQ for (possibly multiple) completions. If the return value
2039 * is < 0, an error occurred. If the return value is >= 0, it is the
2040 * number of completions returned. If the return value is
2041 * non-negative and < num_entries, then the CQ was emptied.
2042 */
2043static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
2044 struct ib_wc *wc)
2045{
2046 return cq->device->poll_cq(cq, num_entries, wc);
2047}
2048
2049/**
2050 * ib_peek_cq - Returns the number of unreaped completions currently
2051 * on the specified CQ.
2052 * @cq: The CQ to peek.
2053 * @wc_cnt: A minimum number of unreaped completions to check for.
2054 *
2055 * If the number of unreaped completions is greater than or equal to wc_cnt,
2056 * this function returns wc_cnt, otherwise, it returns the actual number of
2057 * unreaped completions.
2058 */
2059int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
2060
2061/**
2062 * ib_req_notify_cq - Request completion notification on a CQ.
2063 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07002064 * @flags:
2065 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
2066 * to request an event on the next solicited event or next work
2067 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
2068 * may also be |ed in to request a hint about missed events, as
2069 * described below.
2070 *
2071 * Return Value:
2072 * < 0 means an error occurred while requesting notification
2073 * == 0 means notification was requested successfully, and if
2074 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
2075 * were missed and it is safe to wait for another event. In
2076 * this case is it guaranteed that any work completions added
2077 * to the CQ since the last CQ poll will trigger a completion
2078 * notification event.
2079 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
2080 * in. It means that the consumer must poll the CQ again to
2081 * make sure it is empty to avoid missing an event because of a
2082 * race between requesting notification and an entry being
2083 * added to the CQ. This return value means it is possible
2084 * (but not guaranteed) that a work completion has been added
2085 * to the CQ since the last poll without triggering a
2086 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 */
2088static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07002089 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090{
Roland Dreiered23a722007-05-06 21:02:48 -07002091 return cq->device->req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092}
2093
2094/**
2095 * ib_req_ncomp_notif - Request completion notification when there are
2096 * at least the specified number of unreaped completions on the CQ.
2097 * @cq: The CQ to generate an event for.
2098 * @wc_cnt: The number of unreaped completions that should be on the
2099 * CQ before an event is generated.
2100 */
2101static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
2102{
2103 return cq->device->req_ncomp_notif ?
2104 cq->device->req_ncomp_notif(cq, wc_cnt) :
2105 -ENOSYS;
2106}
2107
2108/**
2109 * ib_get_dma_mr - Returns a memory region for system memory that is
2110 * usable for DMA.
2111 * @pd: The protection domain associated with the memory region.
2112 * @mr_access_flags: Specifies the memory access rights.
Ralph Campbell9b513092006-12-12 14:27:41 -08002113 *
2114 * Note that the ib_dma_*() functions defined below must be used
2115 * to create/destroy addresses used with the Lkey or Rkey returned
2116 * by ib_get_dma_mr().
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 */
2118struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
2119
2120/**
Ralph Campbell9b513092006-12-12 14:27:41 -08002121 * ib_dma_mapping_error - check a DMA addr for error
2122 * @dev: The device for which the dma_addr was created
2123 * @dma_addr: The DMA address to check
2124 */
2125static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
2126{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002127 if (dev->dma_ops)
2128 return dev->dma_ops->mapping_error(dev, dma_addr);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07002129 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08002130}
2131
2132/**
2133 * ib_dma_map_single - Map a kernel virtual address to DMA address
2134 * @dev: The device for which the dma_addr is to be created
2135 * @cpu_addr: The kernel virtual address
2136 * @size: The size of the region in bytes
2137 * @direction: The direction of the DMA
2138 */
2139static inline u64 ib_dma_map_single(struct ib_device *dev,
2140 void *cpu_addr, size_t size,
2141 enum dma_data_direction direction)
2142{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002143 if (dev->dma_ops)
2144 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
2145 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002146}
2147
2148/**
2149 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
2150 * @dev: The device for which the DMA address was created
2151 * @addr: The DMA address
2152 * @size: The size of the region in bytes
2153 * @direction: The direction of the DMA
2154 */
2155static inline void ib_dma_unmap_single(struct ib_device *dev,
2156 u64 addr, size_t size,
2157 enum dma_data_direction direction)
2158{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002159 if (dev->dma_ops)
2160 dev->dma_ops->unmap_single(dev, addr, size, direction);
2161 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002162 dma_unmap_single(dev->dma_device, addr, size, direction);
2163}
2164
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002165static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
2166 void *cpu_addr, size_t size,
2167 enum dma_data_direction direction,
2168 struct dma_attrs *attrs)
2169{
2170 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
2171 direction, attrs);
2172}
2173
2174static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
2175 u64 addr, size_t size,
2176 enum dma_data_direction direction,
2177 struct dma_attrs *attrs)
2178{
2179 return dma_unmap_single_attrs(dev->dma_device, addr, size,
2180 direction, attrs);
2181}
2182
Ralph Campbell9b513092006-12-12 14:27:41 -08002183/**
2184 * ib_dma_map_page - Map a physical page to DMA address
2185 * @dev: The device for which the dma_addr is to be created
2186 * @page: The page to be mapped
2187 * @offset: The offset within the page
2188 * @size: The size of the region in bytes
2189 * @direction: The direction of the DMA
2190 */
2191static inline u64 ib_dma_map_page(struct ib_device *dev,
2192 struct page *page,
2193 unsigned long offset,
2194 size_t size,
2195 enum dma_data_direction direction)
2196{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002197 if (dev->dma_ops)
2198 return dev->dma_ops->map_page(dev, page, offset, size, direction);
2199 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002200}
2201
2202/**
2203 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
2204 * @dev: The device for which the DMA address was created
2205 * @addr: The DMA address
2206 * @size: The size of the region in bytes
2207 * @direction: The direction of the DMA
2208 */
2209static inline void ib_dma_unmap_page(struct ib_device *dev,
2210 u64 addr, size_t size,
2211 enum dma_data_direction direction)
2212{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002213 if (dev->dma_ops)
2214 dev->dma_ops->unmap_page(dev, addr, size, direction);
2215 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002216 dma_unmap_page(dev->dma_device, addr, size, direction);
2217}
2218
2219/**
2220 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
2221 * @dev: The device for which the DMA addresses are to be created
2222 * @sg: The array of scatter/gather entries
2223 * @nents: The number of scatter/gather entries
2224 * @direction: The direction of the DMA
2225 */
2226static inline int ib_dma_map_sg(struct ib_device *dev,
2227 struct scatterlist *sg, int nents,
2228 enum dma_data_direction direction)
2229{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002230 if (dev->dma_ops)
2231 return dev->dma_ops->map_sg(dev, sg, nents, direction);
2232 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002233}
2234
2235/**
2236 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
2237 * @dev: The device for which the DMA addresses were created
2238 * @sg: The array of scatter/gather entries
2239 * @nents: The number of scatter/gather entries
2240 * @direction: The direction of the DMA
2241 */
2242static inline void ib_dma_unmap_sg(struct ib_device *dev,
2243 struct scatterlist *sg, int nents,
2244 enum dma_data_direction direction)
2245{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002246 if (dev->dma_ops)
2247 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
2248 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002249 dma_unmap_sg(dev->dma_device, sg, nents, direction);
2250}
2251
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002252static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
2253 struct scatterlist *sg, int nents,
2254 enum dma_data_direction direction,
2255 struct dma_attrs *attrs)
2256{
2257 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2258}
2259
2260static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
2261 struct scatterlist *sg, int nents,
2262 enum dma_data_direction direction,
2263 struct dma_attrs *attrs)
2264{
2265 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2266}
Ralph Campbell9b513092006-12-12 14:27:41 -08002267/**
2268 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
2269 * @dev: The device for which the DMA addresses were created
2270 * @sg: The scatter/gather entry
Mike Marciniszynea58a592014-03-28 13:26:59 -04002271 *
2272 * Note: this function is obsolete. To do: change all occurrences of
2273 * ib_sg_dma_address() into sg_dma_address().
Ralph Campbell9b513092006-12-12 14:27:41 -08002274 */
2275static inline u64 ib_sg_dma_address(struct ib_device *dev,
2276 struct scatterlist *sg)
2277{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002278 return sg_dma_address(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002279}
2280
2281/**
2282 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
2283 * @dev: The device for which the DMA addresses were created
2284 * @sg: The scatter/gather entry
Mike Marciniszynea58a592014-03-28 13:26:59 -04002285 *
2286 * Note: this function is obsolete. To do: change all occurrences of
2287 * ib_sg_dma_len() into sg_dma_len().
Ralph Campbell9b513092006-12-12 14:27:41 -08002288 */
2289static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
2290 struct scatterlist *sg)
2291{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002292 return sg_dma_len(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002293}
2294
2295/**
2296 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
2297 * @dev: The device for which the DMA address was created
2298 * @addr: The DMA address
2299 * @size: The size of the region in bytes
2300 * @dir: The direction of the DMA
2301 */
2302static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
2303 u64 addr,
2304 size_t size,
2305 enum dma_data_direction dir)
2306{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002307 if (dev->dma_ops)
2308 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
2309 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002310 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
2311}
2312
2313/**
2314 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
2315 * @dev: The device for which the DMA address was created
2316 * @addr: The DMA address
2317 * @size: The size of the region in bytes
2318 * @dir: The direction of the DMA
2319 */
2320static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
2321 u64 addr,
2322 size_t size,
2323 enum dma_data_direction dir)
2324{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002325 if (dev->dma_ops)
2326 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
2327 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002328 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
2329}
2330
2331/**
2332 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
2333 * @dev: The device for which the DMA address is requested
2334 * @size: The size of the region to allocate in bytes
2335 * @dma_handle: A pointer for returning the DMA address of the region
2336 * @flag: memory allocator flags
2337 */
2338static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
2339 size_t size,
2340 u64 *dma_handle,
2341 gfp_t flag)
2342{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002343 if (dev->dma_ops)
2344 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Roland Dreierc59a3da2006-12-15 13:57:26 -08002345 else {
2346 dma_addr_t handle;
2347 void *ret;
2348
2349 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
2350 *dma_handle = handle;
2351 return ret;
2352 }
Ralph Campbell9b513092006-12-12 14:27:41 -08002353}
2354
2355/**
2356 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
2357 * @dev: The device for which the DMA addresses were allocated
2358 * @size: The size of the region
2359 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
2360 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
2361 */
2362static inline void ib_dma_free_coherent(struct ib_device *dev,
2363 size_t size, void *cpu_addr,
2364 u64 dma_handle)
2365{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002366 if (dev->dma_ops)
2367 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
2368 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002369 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
2370}
2371
2372/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
2374 * by an HCA.
2375 * @pd: The protection domain associated assigned to the registered region.
2376 * @phys_buf_array: Specifies a list of physical buffers to use in the
2377 * memory region.
2378 * @num_phys_buf: Specifies the size of the phys_buf_array.
2379 * @mr_access_flags: Specifies the memory access rights.
2380 * @iova_start: The offset of the region's starting I/O virtual address.
2381 */
2382struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
2383 struct ib_phys_buf *phys_buf_array,
2384 int num_phys_buf,
2385 int mr_access_flags,
2386 u64 *iova_start);
2387
2388/**
2389 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
2390 * Conceptually, this call performs the functions deregister memory region
2391 * followed by register physical memory region. Where possible,
2392 * resources are reused instead of deallocated and reallocated.
2393 * @mr: The memory region to modify.
2394 * @mr_rereg_mask: A bit-mask used to indicate which of the following
2395 * properties of the memory region are being modified.
2396 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
2397 * the new protection domain to associated with the memory region,
2398 * otherwise, this parameter is ignored.
2399 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2400 * field specifies a list of physical buffers to use in the new
2401 * translation, otherwise, this parameter is ignored.
2402 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2403 * field specifies the size of the phys_buf_array, otherwise, this
2404 * parameter is ignored.
2405 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
2406 * field specifies the new memory access rights, otherwise, this
2407 * parameter is ignored.
2408 * @iova_start: The offset of the region's starting I/O virtual address.
2409 */
2410int ib_rereg_phys_mr(struct ib_mr *mr,
2411 int mr_rereg_mask,
2412 struct ib_pd *pd,
2413 struct ib_phys_buf *phys_buf_array,
2414 int num_phys_buf,
2415 int mr_access_flags,
2416 u64 *iova_start);
2417
2418/**
2419 * ib_query_mr - Retrieves information about a specific memory region.
2420 * @mr: The memory region to retrieve information about.
2421 * @mr_attr: The attributes of the specified memory region.
2422 */
2423int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
2424
2425/**
2426 * ib_dereg_mr - Deregisters a memory region and removes it from the
2427 * HCA translation table.
2428 * @mr: The memory region to deregister.
Shani Michaeli7083e422013-02-06 16:19:12 +00002429 *
2430 * This function can fail, if the memory region has memory windows bound to it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 */
2432int ib_dereg_mr(struct ib_mr *mr);
2433
Sagi Grimberg17cd3a22014-02-23 14:19:04 +02002434
2435/**
2436 * ib_create_mr - Allocates a memory region that may be used for
2437 * signature handover operations.
2438 * @pd: The protection domain associated with the region.
2439 * @mr_init_attr: memory region init attributes.
2440 */
2441struct ib_mr *ib_create_mr(struct ib_pd *pd,
2442 struct ib_mr_init_attr *mr_init_attr);
2443
2444/**
2445 * ib_destroy_mr - Destroys a memory region that was created using
2446 * ib_create_mr and removes it from HW translation tables.
2447 * @mr: The memory region to destroy.
2448 *
2449 * This function can fail, if the memory region has memory windows bound to it.
2450 */
2451int ib_destroy_mr(struct ib_mr *mr);
2452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453/**
Steve Wise00f7ec32008-07-14 23:48:45 -07002454 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
2455 * IB_WR_FAST_REG_MR send work request.
2456 * @pd: The protection domain associated with the region.
2457 * @max_page_list_len: requested max physical buffer list length to be
2458 * used with fast register work requests for this MR.
2459 */
2460struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2461
2462/**
2463 * ib_alloc_fast_reg_page_list - Allocates a page list array
2464 * @device - ib device pointer.
2465 * @page_list_len - size of the page list array to be allocated.
2466 *
2467 * This allocates and returns a struct ib_fast_reg_page_list * and a
2468 * page_list array that is at least page_list_len in size. The actual
2469 * size is returned in max_page_list_len. The caller is responsible
2470 * for initializing the contents of the page_list array before posting
2471 * a send work request with the IB_WC_FAST_REG_MR opcode.
2472 *
2473 * The page_list array entries must be translated using one of the
2474 * ib_dma_*() functions just like the addresses passed to
2475 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
2476 * ib_fast_reg_page_list must not be modified by the caller until the
2477 * IB_WC_FAST_REG_MR work request completes.
2478 */
2479struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2480 struct ib_device *device, int page_list_len);
2481
2482/**
2483 * ib_free_fast_reg_page_list - Deallocates a previously allocated
2484 * page list array.
2485 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2486 */
2487void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2488
2489/**
2490 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2491 * R_Key and L_Key.
2492 * @mr - struct ib_mr pointer to be updated.
2493 * @newkey - new key to be used.
2494 */
2495static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2496{
2497 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2498 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2499}
2500
2501/**
Shani Michaeli7083e422013-02-06 16:19:12 +00002502 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
2503 * for calculating a new rkey for type 2 memory windows.
2504 * @rkey - the rkey to increment.
2505 */
2506static inline u32 ib_inc_rkey(u32 rkey)
2507{
2508 const u32 mask = 0x000000ff;
2509 return ((rkey + 1) & mask) | (rkey & ~mask);
2510}
2511
2512/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 * ib_alloc_mw - Allocates a memory window.
2514 * @pd: The protection domain associated with the memory window.
Shani Michaeli7083e422013-02-06 16:19:12 +00002515 * @type: The type of the memory window (1 or 2).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 */
Shani Michaeli7083e422013-02-06 16:19:12 +00002517struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
2519/**
2520 * ib_bind_mw - Posts a work request to the send queue of the specified
2521 * QP, which binds the memory window to the given address range and
2522 * remote access attributes.
2523 * @qp: QP to post the bind work request on.
2524 * @mw: The memory window to bind.
2525 * @mw_bind: Specifies information about the memory window, including
2526 * its address range, remote access rights, and associated memory region.
Shani Michaeli7083e422013-02-06 16:19:12 +00002527 *
2528 * If there is no immediate error, the function will update the rkey member
2529 * of the mw parameter to its new value. The bind operation can still fail
2530 * asynchronously.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 */
2532static inline int ib_bind_mw(struct ib_qp *qp,
2533 struct ib_mw *mw,
2534 struct ib_mw_bind *mw_bind)
2535{
2536 /* XXX reference counting in corresponding MR? */
2537 return mw->device->bind_mw ?
2538 mw->device->bind_mw(qp, mw, mw_bind) :
2539 -ENOSYS;
2540}
2541
2542/**
2543 * ib_dealloc_mw - Deallocates a memory window.
2544 * @mw: The memory window to deallocate.
2545 */
2546int ib_dealloc_mw(struct ib_mw *mw);
2547
2548/**
2549 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2550 * @pd: The protection domain associated with the unmapped region.
2551 * @mr_access_flags: Specifies the memory access rights.
2552 * @fmr_attr: Attributes of the unmapped region.
2553 *
2554 * A fast memory region must be mapped before it can be used as part of
2555 * a work request.
2556 */
2557struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2558 int mr_access_flags,
2559 struct ib_fmr_attr *fmr_attr);
2560
2561/**
2562 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2563 * @fmr: The fast memory region to associate with the pages.
2564 * @page_list: An array of physical pages to map to the fast memory region.
2565 * @list_len: The number of pages in page_list.
2566 * @iova: The I/O virtual address to use with the mapped region.
2567 */
2568static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2569 u64 *page_list, int list_len,
2570 u64 iova)
2571{
2572 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2573}
2574
2575/**
2576 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2577 * @fmr_list: A linked list of fast memory regions to unmap.
2578 */
2579int ib_unmap_fmr(struct list_head *fmr_list);
2580
2581/**
2582 * ib_dealloc_fmr - Deallocates a fast memory region.
2583 * @fmr: The fast memory region to deallocate.
2584 */
2585int ib_dealloc_fmr(struct ib_fmr *fmr);
2586
2587/**
2588 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2589 * @qp: QP to attach to the multicast group. The QP must be type
2590 * IB_QPT_UD.
2591 * @gid: Multicast group GID.
2592 * @lid: Multicast group LID in host byte order.
2593 *
2594 * In order to send and receive multicast packets, subnet
2595 * administration must have created the multicast group and configured
2596 * the fabric appropriately. The port associated with the specified
2597 * QP must also be a member of the multicast group.
2598 */
2599int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2600
2601/**
2602 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2603 * @qp: QP to detach from the multicast group.
2604 * @gid: Multicast group GID.
2605 * @lid: Multicast group LID in host byte order.
2606 */
2607int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2608
Sean Hefty59991f92011-05-23 17:52:46 -07002609/**
2610 * ib_alloc_xrcd - Allocates an XRC domain.
2611 * @device: The device on which to allocate the XRC domain.
2612 */
2613struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2614
2615/**
2616 * ib_dealloc_xrcd - Deallocates an XRC domain.
2617 * @xrcd: The XRC domain to deallocate.
2618 */
2619int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2620
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002621struct ib_flow *ib_create_flow(struct ib_qp *qp,
2622 struct ib_flow_attr *flow_attr, int domain);
2623int ib_destroy_flow(struct ib_flow *flow_id);
2624
Eli Cohen1c636f82013-10-31 15:26:32 +02002625static inline int ib_check_mr_access(int flags)
2626{
2627 /*
2628 * Local write permission is required if remote write or
2629 * remote atomic permission is also requested.
2630 */
2631 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
2632 !(flags & IB_ACCESS_LOCAL_WRITE))
2633 return -EINVAL;
2634
2635 return 0;
2636}
2637
Sagi Grimberg1b01d332014-02-23 14:19:05 +02002638/**
2639 * ib_check_mr_status: lightweight check of MR status.
2640 * This routine may provide status checks on a selected
2641 * ib_mr. first use is for signature status check.
2642 *
2643 * @mr: A memory region.
2644 * @check_mask: Bitmask of which checks to perform from
2645 * ib_mr_status_check enumeration.
2646 * @mr_status: The container of relevant status checks.
2647 * failed checks will be indicated in the status bitmask
2648 * and the relevant info shall be in the error item.
2649 */
2650int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
2651 struct ib_mr_status *mr_status);
2652
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653#endif /* IB_VERBS_H */