blob: 688511ed52f59b472ccc7861b52badd54f8817b0 [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>
Roland Dreiere2773c02005-07-07 17:57:10 -070051
Arun Sharma600634972011-07-26 16:09:06 -070052#include <linux/atomic.h>
Roland Dreiere2773c02005-07-07 17:57:10 -070053#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Tejun Heof0626712010-10-19 15:24:36 +000055extern struct workqueue_struct *ib_wq;
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057union ib_gid {
58 u8 raw[16];
59 struct {
Sean Hefty97f52eb2005-08-13 21:05:57 -070060 __be64 subnet_prefix;
61 __be64 interface_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 } global;
63};
64
Tom Tucker07ebafb2006-08-03 16:02:42 -050065enum rdma_node_type {
66 /* IB values map to NodeInfo:NodeType. */
67 RDMA_NODE_IB_CA = 1,
68 RDMA_NODE_IB_SWITCH,
69 RDMA_NODE_IB_ROUTER,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000070 RDMA_NODE_RNIC,
71 RDMA_NODE_USNIC,
Upinder Malhi5db57652014-01-15 17:02:36 -080072 RDMA_NODE_USNIC_UDP,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
74
Tom Tucker07ebafb2006-08-03 16:02:42 -050075enum rdma_transport_type {
76 RDMA_TRANSPORT_IB,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000077 RDMA_TRANSPORT_IWARP,
Upinder Malhi248567f2014-01-09 14:48:19 -080078 RDMA_TRANSPORT_USNIC,
79 RDMA_TRANSPORT_USNIC_UDP
Tom Tucker07ebafb2006-08-03 16:02:42 -050080};
81
82enum rdma_transport_type
83rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
84
Eli Cohena3f5ada2010-09-27 17:51:10 -070085enum rdma_link_layer {
86 IB_LINK_LAYER_UNSPECIFIED,
87 IB_LINK_LAYER_INFINIBAND,
88 IB_LINK_LAYER_ETHERNET,
89};
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091enum ib_device_cap_flags {
92 IB_DEVICE_RESIZE_MAX_WR = 1,
93 IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
94 IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
95 IB_DEVICE_RAW_MULTI = (1<<3),
96 IB_DEVICE_AUTO_PATH_MIG = (1<<4),
97 IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
98 IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
99 IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
100 IB_DEVICE_SHUTDOWN_PORT = (1<<8),
101 IB_DEVICE_INIT_TYPE = (1<<9),
102 IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
103 IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
104 IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
105 IB_DEVICE_SRQ_RESIZE = (1<<13),
106 IB_DEVICE_N_NOTIFY_CQ = (1<<14),
Steve Wise96f15c02008-07-14 23:48:53 -0700107 IB_DEVICE_LOCAL_DMA_LKEY = (1<<15),
Roland Dreier0f39cf32008-04-16 21:09:32 -0700108 IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
Eli Cohene0605d92008-01-30 18:30:57 +0200109 IB_DEVICE_MEM_WINDOW = (1<<17),
110 /*
111 * Devices should set IB_DEVICE_UD_IP_SUM if they support
112 * insertion of UDP and TCP checksum on outgoing UD IPoIB
113 * messages and can verify the validity of checksum for
114 * incoming messages. Setting this flag implies that the
115 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
116 */
117 IB_DEVICE_UD_IP_CSUM = (1<<18),
Eli Cohenc93570f2008-04-16 21:09:27 -0700118 IB_DEVICE_UD_TSO = (1<<19),
Sean Hefty59991f92011-05-23 17:52:46 -0700119 IB_DEVICE_XRC = (1<<20),
Steve Wise00f7ec32008-07-14 23:48:45 -0700120 IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21),
Ron Livne47ee1b92008-07-14 23:48:48 -0700121 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
Shani Michaeli7083e422013-02-06 16:19:12 +0000122 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1<<23),
Hadar Hen Zion319a4412013-08-07 14:01:59 +0300123 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1<<24),
124 IB_DEVICE_MANAGED_FLOW_STEERING = (1<<29)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125};
126
127enum ib_atomic_cap {
128 IB_ATOMIC_NONE,
129 IB_ATOMIC_HCA,
130 IB_ATOMIC_GLOB
131};
132
133struct ib_device_attr {
134 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700135 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 u64 max_mr_size;
137 u64 page_size_cap;
138 u32 vendor_id;
139 u32 vendor_part_id;
140 u32 hw_ver;
141 int max_qp;
142 int max_qp_wr;
143 int device_cap_flags;
144 int max_sge;
145 int max_sge_rd;
146 int max_cq;
147 int max_cqe;
148 int max_mr;
149 int max_pd;
150 int max_qp_rd_atom;
151 int max_ee_rd_atom;
152 int max_res_rd_atom;
153 int max_qp_init_rd_atom;
154 int max_ee_init_rd_atom;
155 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300156 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 int max_ee;
158 int max_rdd;
159 int max_mw;
160 int max_raw_ipv6_qp;
161 int max_raw_ethy_qp;
162 int max_mcast_grp;
163 int max_mcast_qp_attach;
164 int max_total_mcast_qp_attach;
165 int max_ah;
166 int max_fmr;
167 int max_map_per_fmr;
168 int max_srq;
169 int max_srq_wr;
170 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700171 unsigned int max_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 u16 max_pkeys;
173 u8 local_ca_ack_delay;
174};
175
176enum ib_mtu {
177 IB_MTU_256 = 1,
178 IB_MTU_512 = 2,
179 IB_MTU_1024 = 3,
180 IB_MTU_2048 = 4,
181 IB_MTU_4096 = 5
182};
183
184static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
185{
186 switch (mtu) {
187 case IB_MTU_256: return 256;
188 case IB_MTU_512: return 512;
189 case IB_MTU_1024: return 1024;
190 case IB_MTU_2048: return 2048;
191 case IB_MTU_4096: return 4096;
192 default: return -1;
193 }
194}
195
196enum ib_port_state {
197 IB_PORT_NOP = 0,
198 IB_PORT_DOWN = 1,
199 IB_PORT_INIT = 2,
200 IB_PORT_ARMED = 3,
201 IB_PORT_ACTIVE = 4,
202 IB_PORT_ACTIVE_DEFER = 5
203};
204
205enum ib_port_cap_flags {
206 IB_PORT_SM = 1 << 1,
207 IB_PORT_NOTICE_SUP = 1 << 2,
208 IB_PORT_TRAP_SUP = 1 << 3,
209 IB_PORT_OPT_IPD_SUP = 1 << 4,
210 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
211 IB_PORT_SL_MAP_SUP = 1 << 6,
212 IB_PORT_MKEY_NVRAM = 1 << 7,
213 IB_PORT_PKEY_NVRAM = 1 << 8,
214 IB_PORT_LED_INFO_SUP = 1 << 9,
215 IB_PORT_SM_DISABLED = 1 << 10,
216 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
217 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300218 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 IB_PORT_CM_SUP = 1 << 16,
220 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
221 IB_PORT_REINIT_SUP = 1 << 18,
222 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
223 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
224 IB_PORT_DR_NOTICE_SUP = 1 << 21,
225 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
226 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
227 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
228 IB_PORT_CLIENT_REG_SUP = 1 << 25
229};
230
231enum ib_port_width {
232 IB_WIDTH_1X = 1,
233 IB_WIDTH_4X = 2,
234 IB_WIDTH_8X = 4,
235 IB_WIDTH_12X = 8
236};
237
238static inline int ib_width_enum_to_int(enum ib_port_width width)
239{
240 switch (width) {
241 case IB_WIDTH_1X: return 1;
242 case IB_WIDTH_4X: return 4;
243 case IB_WIDTH_8X: return 8;
244 case IB_WIDTH_12X: return 12;
245 default: return -1;
246 }
247}
248
Or Gerlitz2e966912012-02-28 18:49:50 +0200249enum ib_port_speed {
250 IB_SPEED_SDR = 1,
251 IB_SPEED_DDR = 2,
252 IB_SPEED_QDR = 4,
253 IB_SPEED_FDR10 = 8,
254 IB_SPEED_FDR = 16,
255 IB_SPEED_EDR = 32
256};
257
Steve Wise7f624d02008-07-14 23:48:48 -0700258struct ib_protocol_stats {
259 /* TBD... */
260};
261
262struct iw_protocol_stats {
263 u64 ipInReceives;
264 u64 ipInHdrErrors;
265 u64 ipInTooBigErrors;
266 u64 ipInNoRoutes;
267 u64 ipInAddrErrors;
268 u64 ipInUnknownProtos;
269 u64 ipInTruncatedPkts;
270 u64 ipInDiscards;
271 u64 ipInDelivers;
272 u64 ipOutForwDatagrams;
273 u64 ipOutRequests;
274 u64 ipOutDiscards;
275 u64 ipOutNoRoutes;
276 u64 ipReasmTimeout;
277 u64 ipReasmReqds;
278 u64 ipReasmOKs;
279 u64 ipReasmFails;
280 u64 ipFragOKs;
281 u64 ipFragFails;
282 u64 ipFragCreates;
283 u64 ipInMcastPkts;
284 u64 ipOutMcastPkts;
285 u64 ipInBcastPkts;
286 u64 ipOutBcastPkts;
287
288 u64 tcpRtoAlgorithm;
289 u64 tcpRtoMin;
290 u64 tcpRtoMax;
291 u64 tcpMaxConn;
292 u64 tcpActiveOpens;
293 u64 tcpPassiveOpens;
294 u64 tcpAttemptFails;
295 u64 tcpEstabResets;
296 u64 tcpCurrEstab;
297 u64 tcpInSegs;
298 u64 tcpOutSegs;
299 u64 tcpRetransSegs;
300 u64 tcpInErrs;
301 u64 tcpOutRsts;
302};
303
304union rdma_protocol_stats {
305 struct ib_protocol_stats ib;
306 struct iw_protocol_stats iw;
307};
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309struct ib_port_attr {
310 enum ib_port_state state;
311 enum ib_mtu max_mtu;
312 enum ib_mtu active_mtu;
313 int gid_tbl_len;
314 u32 port_cap_flags;
315 u32 max_msg_sz;
316 u32 bad_pkey_cntr;
317 u32 qkey_viol_cntr;
318 u16 pkey_tbl_len;
319 u16 lid;
320 u16 sm_lid;
321 u8 lmc;
322 u8 max_vl_num;
323 u8 sm_sl;
324 u8 subnet_timeout;
325 u8 init_type_reply;
326 u8 active_width;
327 u8 active_speed;
328 u8 phys_state;
329};
330
331enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800332 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
333 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334};
335
336struct ib_device_modify {
337 u64 sys_image_guid;
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800338 char node_desc[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339};
340
341enum ib_port_modify_flags {
342 IB_PORT_SHUTDOWN = 1,
343 IB_PORT_INIT_TYPE = (1<<2),
344 IB_PORT_RESET_QKEY_CNTR = (1<<3)
345};
346
347struct ib_port_modify {
348 u32 set_port_cap_mask;
349 u32 clr_port_cap_mask;
350 u8 init_type;
351};
352
353enum ib_event_type {
354 IB_EVENT_CQ_ERR,
355 IB_EVENT_QP_FATAL,
356 IB_EVENT_QP_REQ_ERR,
357 IB_EVENT_QP_ACCESS_ERR,
358 IB_EVENT_COMM_EST,
359 IB_EVENT_SQ_DRAINED,
360 IB_EVENT_PATH_MIG,
361 IB_EVENT_PATH_MIG_ERR,
362 IB_EVENT_DEVICE_FATAL,
363 IB_EVENT_PORT_ACTIVE,
364 IB_EVENT_PORT_ERR,
365 IB_EVENT_LID_CHANGE,
366 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700367 IB_EVENT_SM_CHANGE,
368 IB_EVENT_SRQ_ERR,
369 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700370 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000371 IB_EVENT_CLIENT_REREGISTER,
372 IB_EVENT_GID_CHANGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373};
374
375struct ib_event {
376 struct ib_device *device;
377 union {
378 struct ib_cq *cq;
379 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700380 struct ib_srq *srq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 u8 port_num;
382 } element;
383 enum ib_event_type event;
384};
385
386struct ib_event_handler {
387 struct ib_device *device;
388 void (*handler)(struct ib_event_handler *, struct ib_event *);
389 struct list_head list;
390};
391
392#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
393 do { \
394 (_ptr)->device = _device; \
395 (_ptr)->handler = _handler; \
396 INIT_LIST_HEAD(&(_ptr)->list); \
397 } while (0)
398
399struct ib_global_route {
400 union ib_gid dgid;
401 u32 flow_label;
402 u8 sgid_index;
403 u8 hop_limit;
404 u8 traffic_class;
405};
406
Hal Rosenstock513789e2005-07-27 11:45:34 -0700407struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700408 __be32 version_tclass_flow;
409 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700410 u8 next_hdr;
411 u8 hop_limit;
412 union ib_gid sgid;
413 union ib_gid dgid;
414};
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416enum {
417 IB_MULTICAST_QPN = 0xffffff
418};
419
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800420#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422enum ib_ah_flags {
423 IB_AH_GRH = 1
424};
425
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700426enum ib_rate {
427 IB_RATE_PORT_CURRENT = 0,
428 IB_RATE_2_5_GBPS = 2,
429 IB_RATE_5_GBPS = 5,
430 IB_RATE_10_GBPS = 3,
431 IB_RATE_20_GBPS = 6,
432 IB_RATE_30_GBPS = 4,
433 IB_RATE_40_GBPS = 7,
434 IB_RATE_60_GBPS = 8,
435 IB_RATE_80_GBPS = 9,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300436 IB_RATE_120_GBPS = 10,
437 IB_RATE_14_GBPS = 11,
438 IB_RATE_56_GBPS = 12,
439 IB_RATE_112_GBPS = 13,
440 IB_RATE_168_GBPS = 14,
441 IB_RATE_25_GBPS = 15,
442 IB_RATE_100_GBPS = 16,
443 IB_RATE_200_GBPS = 17,
444 IB_RATE_300_GBPS = 18
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700445};
446
447/**
448 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
449 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
450 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
451 * @rate: rate to convert.
452 */
453int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
454
455/**
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300456 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
457 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
458 * @rate: rate to convert.
459 */
460int ib_rate_to_mbps(enum ib_rate rate) __attribute_const__;
461
462/**
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700463 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
464 * enum.
465 * @mult: multiple to convert.
466 */
467enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469struct ib_ah_attr {
470 struct ib_global_route grh;
471 u16 dlid;
472 u8 sl;
473 u8 src_path_bits;
474 u8 static_rate;
475 u8 ah_flags;
476 u8 port_num;
477};
478
479enum ib_wc_status {
480 IB_WC_SUCCESS,
481 IB_WC_LOC_LEN_ERR,
482 IB_WC_LOC_QP_OP_ERR,
483 IB_WC_LOC_EEC_OP_ERR,
484 IB_WC_LOC_PROT_ERR,
485 IB_WC_WR_FLUSH_ERR,
486 IB_WC_MW_BIND_ERR,
487 IB_WC_BAD_RESP_ERR,
488 IB_WC_LOC_ACCESS_ERR,
489 IB_WC_REM_INV_REQ_ERR,
490 IB_WC_REM_ACCESS_ERR,
491 IB_WC_REM_OP_ERR,
492 IB_WC_RETRY_EXC_ERR,
493 IB_WC_RNR_RETRY_EXC_ERR,
494 IB_WC_LOC_RDD_VIOL_ERR,
495 IB_WC_REM_INV_RD_REQ_ERR,
496 IB_WC_REM_ABORT_ERR,
497 IB_WC_INV_EECN_ERR,
498 IB_WC_INV_EEC_STATE_ERR,
499 IB_WC_FATAL_ERR,
500 IB_WC_RESP_TIMEOUT_ERR,
501 IB_WC_GENERAL_ERR
502};
503
504enum ib_wc_opcode {
505 IB_WC_SEND,
506 IB_WC_RDMA_WRITE,
507 IB_WC_RDMA_READ,
508 IB_WC_COMP_SWAP,
509 IB_WC_FETCH_ADD,
510 IB_WC_BIND_MW,
Eli Cohenc93570f2008-04-16 21:09:27 -0700511 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700512 IB_WC_LOCAL_INV,
513 IB_WC_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300514 IB_WC_MASKED_COMP_SWAP,
515 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516/*
517 * Set value of IB_WC_RECV so consumers can test if a completion is a
518 * receive by testing (opcode & IB_WC_RECV).
519 */
520 IB_WC_RECV = 1 << 7,
521 IB_WC_RECV_RDMA_WITH_IMM
522};
523
524enum ib_wc_flags {
525 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -0700526 IB_WC_WITH_IMM = (1<<1),
527 IB_WC_WITH_INVALIDATE = (1<<2),
Or Gerlitzd927d502012-01-11 19:03:51 +0200528 IB_WC_IP_CSUM_OK = (1<<3),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529};
530
531struct ib_wc {
532 u64 wr_id;
533 enum ib_wc_status status;
534 enum ib_wc_opcode opcode;
535 u32 vendor_err;
536 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +0200537 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -0700538 union {
539 __be32 imm_data;
540 u32 invalidate_rkey;
541 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 u32 src_qp;
543 int wc_flags;
544 u16 pkey_index;
545 u16 slid;
546 u8 sl;
547 u8 dlid_path_bits;
548 u8 port_num; /* valid only for DR SMPs on switches */
549};
550
Roland Dreiered23a722007-05-06 21:02:48 -0700551enum ib_cq_notify_flags {
552 IB_CQ_SOLICITED = 1 << 0,
553 IB_CQ_NEXT_COMP = 1 << 1,
554 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
555 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556};
557
Sean Hefty96104ed2011-05-23 16:31:36 -0700558enum ib_srq_type {
Sean Hefty418d5132011-05-23 19:42:29 -0700559 IB_SRQT_BASIC,
560 IB_SRQT_XRC
Sean Hefty96104ed2011-05-23 16:31:36 -0700561};
562
Roland Dreierd41fcc62005-08-18 12:23:08 -0700563enum ib_srq_attr_mask {
564 IB_SRQ_MAX_WR = 1 << 0,
565 IB_SRQ_LIMIT = 1 << 1,
566};
567
568struct ib_srq_attr {
569 u32 max_wr;
570 u32 max_sge;
571 u32 srq_limit;
572};
573
574struct ib_srq_init_attr {
575 void (*event_handler)(struct ib_event *, void *);
576 void *srq_context;
577 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -0700578 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -0700579
580 union {
581 struct {
582 struct ib_xrcd *xrcd;
583 struct ib_cq *cq;
584 } xrc;
585 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700586};
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588struct ib_qp_cap {
589 u32 max_send_wr;
590 u32 max_recv_wr;
591 u32 max_send_sge;
592 u32 max_recv_sge;
593 u32 max_inline_data;
594};
595
596enum ib_sig_type {
597 IB_SIGNAL_ALL_WR,
598 IB_SIGNAL_REQ_WR
599};
600
601enum ib_qp_type {
602 /*
603 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
604 * here (and in that order) since the MAD layer uses them as
605 * indices into a 2-entry table.
606 */
607 IB_QPT_SMI,
608 IB_QPT_GSI,
609
610 IB_QPT_RC,
611 IB_QPT_UC,
612 IB_QPT_UD,
613 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700614 IB_QPT_RAW_ETHERTYPE,
Or Gerlitzc938a612012-03-01 12:17:51 +0200615 IB_QPT_RAW_PACKET = 8,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700616 IB_QPT_XRC_INI = 9,
617 IB_QPT_XRC_TGT,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300618 IB_QPT_MAX,
619 /* Reserve a range for qp types internal to the low level driver.
620 * These qp types will not be visible at the IB core layer, so the
621 * IB_QPT_MAX usages should not be affected in the core layer
622 */
623 IB_QPT_RESERVED1 = 0x1000,
624 IB_QPT_RESERVED2,
625 IB_QPT_RESERVED3,
626 IB_QPT_RESERVED4,
627 IB_QPT_RESERVED5,
628 IB_QPT_RESERVED6,
629 IB_QPT_RESERVED7,
630 IB_QPT_RESERVED8,
631 IB_QPT_RESERVED9,
632 IB_QPT_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633};
634
Eli Cohenb846f252008-04-16 21:09:27 -0700635enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -0700636 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
637 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
Jack Morgensteind2b57062012-08-03 08:40:37 +0000638 /* reserve bits 26-31 for low level drivers' internal use */
639 IB_QP_CREATE_RESERVED_START = 1 << 26,
640 IB_QP_CREATE_RESERVED_END = 1 << 31,
Eli Cohenb846f252008-04-16 21:09:27 -0700641};
642
Yishai Hadas73c40c62013-08-01 18:49:53 +0300643
644/*
645 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
646 * callback to destroy the passed in QP.
647 */
648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649struct ib_qp_init_attr {
650 void (*event_handler)(struct ib_event *, void *);
651 void *qp_context;
652 struct ib_cq *send_cq;
653 struct ib_cq *recv_cq;
654 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700655 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 struct ib_qp_cap cap;
657 enum ib_sig_type sq_sig_type;
658 enum ib_qp_type qp_type;
Eli Cohenb846f252008-04-16 21:09:27 -0700659 enum ib_qp_create_flags create_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 u8 port_num; /* special QP types only */
661};
662
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700663struct ib_qp_open_attr {
664 void (*event_handler)(struct ib_event *, void *);
665 void *qp_context;
666 u32 qp_num;
667 enum ib_qp_type qp_type;
668};
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670enum ib_rnr_timeout {
671 IB_RNR_TIMER_655_36 = 0,
672 IB_RNR_TIMER_000_01 = 1,
673 IB_RNR_TIMER_000_02 = 2,
674 IB_RNR_TIMER_000_03 = 3,
675 IB_RNR_TIMER_000_04 = 4,
676 IB_RNR_TIMER_000_06 = 5,
677 IB_RNR_TIMER_000_08 = 6,
678 IB_RNR_TIMER_000_12 = 7,
679 IB_RNR_TIMER_000_16 = 8,
680 IB_RNR_TIMER_000_24 = 9,
681 IB_RNR_TIMER_000_32 = 10,
682 IB_RNR_TIMER_000_48 = 11,
683 IB_RNR_TIMER_000_64 = 12,
684 IB_RNR_TIMER_000_96 = 13,
685 IB_RNR_TIMER_001_28 = 14,
686 IB_RNR_TIMER_001_92 = 15,
687 IB_RNR_TIMER_002_56 = 16,
688 IB_RNR_TIMER_003_84 = 17,
689 IB_RNR_TIMER_005_12 = 18,
690 IB_RNR_TIMER_007_68 = 19,
691 IB_RNR_TIMER_010_24 = 20,
692 IB_RNR_TIMER_015_36 = 21,
693 IB_RNR_TIMER_020_48 = 22,
694 IB_RNR_TIMER_030_72 = 23,
695 IB_RNR_TIMER_040_96 = 24,
696 IB_RNR_TIMER_061_44 = 25,
697 IB_RNR_TIMER_081_92 = 26,
698 IB_RNR_TIMER_122_88 = 27,
699 IB_RNR_TIMER_163_84 = 28,
700 IB_RNR_TIMER_245_76 = 29,
701 IB_RNR_TIMER_327_68 = 30,
702 IB_RNR_TIMER_491_52 = 31
703};
704
705enum ib_qp_attr_mask {
706 IB_QP_STATE = 1,
707 IB_QP_CUR_STATE = (1<<1),
708 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
709 IB_QP_ACCESS_FLAGS = (1<<3),
710 IB_QP_PKEY_INDEX = (1<<4),
711 IB_QP_PORT = (1<<5),
712 IB_QP_QKEY = (1<<6),
713 IB_QP_AV = (1<<7),
714 IB_QP_PATH_MTU = (1<<8),
715 IB_QP_TIMEOUT = (1<<9),
716 IB_QP_RETRY_CNT = (1<<10),
717 IB_QP_RNR_RETRY = (1<<11),
718 IB_QP_RQ_PSN = (1<<12),
719 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
720 IB_QP_ALT_PATH = (1<<14),
721 IB_QP_MIN_RNR_TIMER = (1<<15),
722 IB_QP_SQ_PSN = (1<<16),
723 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
724 IB_QP_PATH_MIG_STATE = (1<<18),
725 IB_QP_CAP = (1<<19),
726 IB_QP_DEST_QPN = (1<<20)
727};
728
729enum ib_qp_state {
730 IB_QPS_RESET,
731 IB_QPS_INIT,
732 IB_QPS_RTR,
733 IB_QPS_RTS,
734 IB_QPS_SQD,
735 IB_QPS_SQE,
736 IB_QPS_ERR
737};
738
739enum ib_mig_state {
740 IB_MIG_MIGRATED,
741 IB_MIG_REARM,
742 IB_MIG_ARMED
743};
744
Shani Michaeli7083e422013-02-06 16:19:12 +0000745enum ib_mw_type {
746 IB_MW_TYPE_1 = 1,
747 IB_MW_TYPE_2 = 2
748};
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750struct ib_qp_attr {
751 enum ib_qp_state qp_state;
752 enum ib_qp_state cur_qp_state;
753 enum ib_mtu path_mtu;
754 enum ib_mig_state path_mig_state;
755 u32 qkey;
756 u32 rq_psn;
757 u32 sq_psn;
758 u32 dest_qp_num;
759 int qp_access_flags;
760 struct ib_qp_cap cap;
761 struct ib_ah_attr ah_attr;
762 struct ib_ah_attr alt_ah_attr;
763 u16 pkey_index;
764 u16 alt_pkey_index;
765 u8 en_sqd_async_notify;
766 u8 sq_draining;
767 u8 max_rd_atomic;
768 u8 max_dest_rd_atomic;
769 u8 min_rnr_timer;
770 u8 port_num;
771 u8 timeout;
772 u8 retry_cnt;
773 u8 rnr_retry;
774 u8 alt_port_num;
775 u8 alt_timeout;
776};
777
778enum ib_wr_opcode {
779 IB_WR_RDMA_WRITE,
780 IB_WR_RDMA_WRITE_WITH_IMM,
781 IB_WR_SEND,
782 IB_WR_SEND_WITH_IMM,
783 IB_WR_RDMA_READ,
784 IB_WR_ATOMIC_CMP_AND_SWP,
Eli Cohenc93570f2008-04-16 21:09:27 -0700785 IB_WR_ATOMIC_FETCH_AND_ADD,
Roland Dreier0f39cf32008-04-16 21:09:32 -0700786 IB_WR_LSO,
787 IB_WR_SEND_WITH_INV,
Steve Wise00f7ec32008-07-14 23:48:45 -0700788 IB_WR_RDMA_READ_WITH_INV,
789 IB_WR_LOCAL_INV,
790 IB_WR_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300791 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
792 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
Shani Michaeli7083e422013-02-06 16:19:12 +0000793 IB_WR_BIND_MW,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300794 /* reserve values for low level drivers' internal use.
795 * These values will not be used at all in the ib core layer.
796 */
797 IB_WR_RESERVED1 = 0xf0,
798 IB_WR_RESERVED2,
799 IB_WR_RESERVED3,
800 IB_WR_RESERVED4,
801 IB_WR_RESERVED5,
802 IB_WR_RESERVED6,
803 IB_WR_RESERVED7,
804 IB_WR_RESERVED8,
805 IB_WR_RESERVED9,
806 IB_WR_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807};
808
809enum ib_send_flags {
810 IB_SEND_FENCE = 1,
811 IB_SEND_SIGNALED = (1<<1),
812 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +0200813 IB_SEND_INLINE = (1<<3),
Jack Morgenstein0134f162013-07-07 17:25:52 +0300814 IB_SEND_IP_CSUM = (1<<4),
815
816 /* reserve bits 26-31 for low level drivers' internal use */
817 IB_SEND_RESERVED_START = (1 << 26),
818 IB_SEND_RESERVED_END = (1 << 31),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819};
820
821struct ib_sge {
822 u64 addr;
823 u32 length;
824 u32 lkey;
825};
826
Steve Wise00f7ec32008-07-14 23:48:45 -0700827struct ib_fast_reg_page_list {
828 struct ib_device *device;
829 u64 *page_list;
830 unsigned int max_page_list_len;
831};
832
Shani Michaeli7083e422013-02-06 16:19:12 +0000833/**
834 * struct ib_mw_bind_info - Parameters for a memory window bind operation.
835 * @mr: A memory region to bind the memory window to.
836 * @addr: The address where the memory window should begin.
837 * @length: The length of the memory window, in bytes.
838 * @mw_access_flags: Access flags from enum ib_access_flags for the window.
839 *
840 * This struct contains the shared parameters for type 1 and type 2
841 * memory window bind operations.
842 */
843struct ib_mw_bind_info {
844 struct ib_mr *mr;
845 u64 addr;
846 u64 length;
847 int mw_access_flags;
848};
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850struct ib_send_wr {
851 struct ib_send_wr *next;
852 u64 wr_id;
853 struct ib_sge *sg_list;
854 int num_sge;
855 enum ib_wr_opcode opcode;
856 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -0700857 union {
858 __be32 imm_data;
859 u32 invalidate_rkey;
860 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 union {
862 struct {
863 u64 remote_addr;
864 u32 rkey;
865 } rdma;
866 struct {
867 u64 remote_addr;
868 u64 compare_add;
869 u64 swap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300870 u64 compare_add_mask;
871 u64 swap_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 u32 rkey;
873 } atomic;
874 struct {
875 struct ib_ah *ah;
Eli Cohenc93570f2008-04-16 21:09:27 -0700876 void *header;
877 int hlen;
878 int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 u32 remote_qpn;
880 u32 remote_qkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 u16 pkey_index; /* valid for GSI only */
882 u8 port_num; /* valid for DR SMPs on switch only */
883 } ud;
Steve Wise00f7ec32008-07-14 23:48:45 -0700884 struct {
885 u64 iova_start;
886 struct ib_fast_reg_page_list *page_list;
887 unsigned int page_shift;
888 unsigned int page_list_len;
889 u32 length;
890 int access_flags;
891 u32 rkey;
892 } fast_reg;
Shani Michaeli7083e422013-02-06 16:19:12 +0000893 struct {
894 struct ib_mw *mw;
895 /* The new rkey for the memory window. */
896 u32 rkey;
897 struct ib_mw_bind_info bind_info;
898 } bind_mw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 } wr;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700900 u32 xrc_remote_srq_num; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901};
902
903struct ib_recv_wr {
904 struct ib_recv_wr *next;
905 u64 wr_id;
906 struct ib_sge *sg_list;
907 int num_sge;
908};
909
910enum ib_access_flags {
911 IB_ACCESS_LOCAL_WRITE = 1,
912 IB_ACCESS_REMOTE_WRITE = (1<<1),
913 IB_ACCESS_REMOTE_READ = (1<<2),
914 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
Shani Michaeli7083e422013-02-06 16:19:12 +0000915 IB_ACCESS_MW_BIND = (1<<4),
916 IB_ZERO_BASED = (1<<5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917};
918
919struct ib_phys_buf {
920 u64 addr;
921 u64 size;
922};
923
924struct ib_mr_attr {
925 struct ib_pd *pd;
926 u64 device_virt_addr;
927 u64 size;
928 int mr_access_flags;
929 u32 lkey;
930 u32 rkey;
931};
932
933enum ib_mr_rereg_flags {
934 IB_MR_REREG_TRANS = 1,
935 IB_MR_REREG_PD = (1<<1),
936 IB_MR_REREG_ACCESS = (1<<2)
937};
938
Shani Michaeli7083e422013-02-06 16:19:12 +0000939/**
940 * struct ib_mw_bind - Parameters for a type 1 memory window bind operation.
941 * @wr_id: Work request id.
942 * @send_flags: Flags from ib_send_flags enum.
943 * @bind_info: More parameters of the bind operation.
944 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945struct ib_mw_bind {
Shani Michaeli7083e422013-02-06 16:19:12 +0000946 u64 wr_id;
947 int send_flags;
948 struct ib_mw_bind_info bind_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949};
950
951struct ib_fmr_attr {
952 int max_pages;
953 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -0800954 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955};
956
Roland Dreiere2773c02005-07-07 17:57:10 -0700957struct ib_ucontext {
958 struct ib_device *device;
959 struct list_head pd_list;
960 struct list_head mr_list;
961 struct list_head mw_list;
962 struct list_head cq_list;
963 struct list_head qp_list;
964 struct list_head srq_list;
965 struct list_head ah_list;
Sean Hefty53d0bd12011-05-24 08:33:46 -0700966 struct list_head xrcd_list;
Hadar Hen Zion436f2ad2013-08-14 13:58:30 +0300967 struct list_head rule_list;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -0800968 int closing;
Roland Dreiere2773c02005-07-07 17:57:10 -0700969};
970
971struct ib_uobject {
972 u64 user_handle; /* handle given to us by userspace */
973 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -0700974 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -0700975 struct list_head list; /* link to context's list */
Roland Dreierb3d636b2008-04-16 21:01:06 -0700976 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -0700977 struct kref ref;
978 struct rw_semaphore mutex; /* protects .live */
979 int live;
Roland Dreiere2773c02005-07-07 17:57:10 -0700980};
981
Roland Dreiere2773c02005-07-07 17:57:10 -0700982struct ib_udata {
Yann Droneaud309243e2013-12-11 23:01:44 +0100983 const void __user *inbuf;
Roland Dreiere2773c02005-07-07 17:57:10 -0700984 void __user *outbuf;
985 size_t inlen;
986 size_t outlen;
987};
988
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989struct ib_pd {
Roland Dreiere2773c02005-07-07 17:57:10 -0700990 struct ib_device *device;
991 struct ib_uobject *uobject;
992 atomic_t usecnt; /* count all resources */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993};
994
Sean Hefty59991f92011-05-23 17:52:46 -0700995struct ib_xrcd {
996 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -0700997 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -0700998 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -0700999
1000 struct mutex tgt_qp_mutex;
1001 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -07001002};
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004struct ib_ah {
1005 struct ib_device *device;
1006 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001007 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008};
1009
1010typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1011
1012struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -07001013 struct ib_device *device;
1014 struct ib_uobject *uobject;
1015 ib_comp_handler comp_handler;
1016 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -07001017 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -07001018 int cqe;
1019 atomic_t usecnt; /* count number of work queues */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020};
1021
1022struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -07001023 struct ib_device *device;
1024 struct ib_pd *pd;
1025 struct ib_uobject *uobject;
1026 void (*event_handler)(struct ib_event *, void *);
1027 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -07001028 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -07001030
1031 union {
1032 struct {
1033 struct ib_xrcd *xrcd;
1034 struct ib_cq *cq;
1035 u32 srq_num;
1036 } xrc;
1037 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038};
1039
1040struct ib_qp {
1041 struct ib_device *device;
1042 struct ib_pd *pd;
1043 struct ib_cq *send_cq;
1044 struct ib_cq *recv_cq;
1045 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001046 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -07001047 struct list_head xrcd_list;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001048 /* count times opened, mcast attaches, flow attaches */
1049 atomic_t usecnt;
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001050 struct list_head open_list;
1051 struct ib_qp *real_qp;
Roland Dreiere2773c02005-07-07 17:57:10 -07001052 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 void (*event_handler)(struct ib_event *, void *);
1054 void *qp_context;
1055 u32 qp_num;
1056 enum ib_qp_type qp_type;
1057};
1058
1059struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -07001060 struct ib_device *device;
1061 struct ib_pd *pd;
1062 struct ib_uobject *uobject;
1063 u32 lkey;
1064 u32 rkey;
1065 atomic_t usecnt; /* count number of MWs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066};
1067
1068struct ib_mw {
1069 struct ib_device *device;
1070 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001071 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 u32 rkey;
Shani Michaeli7083e422013-02-06 16:19:12 +00001073 enum ib_mw_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074};
1075
1076struct ib_fmr {
1077 struct ib_device *device;
1078 struct ib_pd *pd;
1079 struct list_head list;
1080 u32 lkey;
1081 u32 rkey;
1082};
1083
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001084/* Supported steering options */
1085enum ib_flow_attr_type {
1086 /* steering according to rule specifications */
1087 IB_FLOW_ATTR_NORMAL = 0x0,
1088 /* default unicast and multicast rule -
1089 * receive all Eth traffic which isn't steered to any QP
1090 */
1091 IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1092 /* default multicast rule -
1093 * receive all Eth multicast traffic which isn't steered to any QP
1094 */
1095 IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1096 /* sniffer rule - receive all port traffic */
1097 IB_FLOW_ATTR_SNIFFER = 0x3
1098};
1099
1100/* Supported steering header types */
1101enum ib_flow_spec_type {
1102 /* L2 headers*/
1103 IB_FLOW_SPEC_ETH = 0x20,
1104 /* L3 header*/
1105 IB_FLOW_SPEC_IPV4 = 0x30,
1106 /* L4 headers*/
1107 IB_FLOW_SPEC_TCP = 0x40,
1108 IB_FLOW_SPEC_UDP = 0x41
1109};
1110
Matan Barak22878db2013-09-01 18:39:52 +03001111#define IB_FLOW_SPEC_SUPPORT_LAYERS 4
1112
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001113/* Flow steering rule priority is set according to it's domain.
1114 * Lower domain value means higher priority.
1115 */
1116enum ib_flow_domain {
1117 IB_FLOW_DOMAIN_USER,
1118 IB_FLOW_DOMAIN_ETHTOOL,
1119 IB_FLOW_DOMAIN_RFS,
1120 IB_FLOW_DOMAIN_NIC,
1121 IB_FLOW_DOMAIN_NUM /* Must be last */
1122};
1123
1124struct ib_flow_eth_filter {
1125 u8 dst_mac[6];
1126 u8 src_mac[6];
1127 __be16 ether_type;
1128 __be16 vlan_tag;
1129};
1130
1131struct ib_flow_spec_eth {
1132 enum ib_flow_spec_type type;
1133 u16 size;
1134 struct ib_flow_eth_filter val;
1135 struct ib_flow_eth_filter mask;
1136};
1137
1138struct ib_flow_ipv4_filter {
1139 __be32 src_ip;
1140 __be32 dst_ip;
1141};
1142
1143struct ib_flow_spec_ipv4 {
1144 enum ib_flow_spec_type type;
1145 u16 size;
1146 struct ib_flow_ipv4_filter val;
1147 struct ib_flow_ipv4_filter mask;
1148};
1149
1150struct ib_flow_tcp_udp_filter {
1151 __be16 dst_port;
1152 __be16 src_port;
1153};
1154
1155struct ib_flow_spec_tcp_udp {
1156 enum ib_flow_spec_type type;
1157 u16 size;
1158 struct ib_flow_tcp_udp_filter val;
1159 struct ib_flow_tcp_udp_filter mask;
1160};
1161
1162union ib_flow_spec {
1163 struct {
1164 enum ib_flow_spec_type type;
1165 u16 size;
1166 };
1167 struct ib_flow_spec_eth eth;
1168 struct ib_flow_spec_ipv4 ipv4;
1169 struct ib_flow_spec_tcp_udp tcp_udp;
1170};
1171
1172struct ib_flow_attr {
1173 enum ib_flow_attr_type type;
1174 u16 size;
1175 u16 priority;
1176 u32 flags;
1177 u8 num_of_specs;
1178 u8 port;
1179 /* Following are the optional layers according to user request
1180 * struct ib_flow_spec_xxx
1181 * struct ib_flow_spec_yyy
1182 */
1183};
1184
1185struct ib_flow {
1186 struct ib_qp *qp;
1187 struct ib_uobject *uobject;
1188};
1189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190struct ib_mad;
1191struct ib_grh;
1192
1193enum ib_process_mad_flags {
1194 IB_MAD_IGNORE_MKEY = 1,
1195 IB_MAD_IGNORE_BKEY = 2,
1196 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1197};
1198
1199enum ib_mad_result {
1200 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
1201 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
1202 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
1203 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
1204};
1205
1206#define IB_DEVICE_NAME_MAX 64
1207
1208struct ib_cache {
1209 rwlock_t lock;
1210 struct ib_event_handler event_handler;
1211 struct ib_pkey_cache **pkey_cache;
1212 struct ib_gid_cache **gid_cache;
Jack Morgenstein6fb9cdb2006-06-17 20:37:34 -07001213 u8 *lmc_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214};
1215
Ralph Campbell9b513092006-12-12 14:27:41 -08001216struct ib_dma_mapping_ops {
1217 int (*mapping_error)(struct ib_device *dev,
1218 u64 dma_addr);
1219 u64 (*map_single)(struct ib_device *dev,
1220 void *ptr, size_t size,
1221 enum dma_data_direction direction);
1222 void (*unmap_single)(struct ib_device *dev,
1223 u64 addr, size_t size,
1224 enum dma_data_direction direction);
1225 u64 (*map_page)(struct ib_device *dev,
1226 struct page *page, unsigned long offset,
1227 size_t size,
1228 enum dma_data_direction direction);
1229 void (*unmap_page)(struct ib_device *dev,
1230 u64 addr, size_t size,
1231 enum dma_data_direction direction);
1232 int (*map_sg)(struct ib_device *dev,
1233 struct scatterlist *sg, int nents,
1234 enum dma_data_direction direction);
1235 void (*unmap_sg)(struct ib_device *dev,
1236 struct scatterlist *sg, int nents,
1237 enum dma_data_direction direction);
1238 u64 (*dma_address)(struct ib_device *dev,
1239 struct scatterlist *sg);
1240 unsigned int (*dma_len)(struct ib_device *dev,
1241 struct scatterlist *sg);
1242 void (*sync_single_for_cpu)(struct ib_device *dev,
1243 u64 dma_handle,
1244 size_t size,
Dotan Barak4deccd62008-07-14 23:48:44 -07001245 enum dma_data_direction dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08001246 void (*sync_single_for_device)(struct ib_device *dev,
1247 u64 dma_handle,
1248 size_t size,
1249 enum dma_data_direction dir);
1250 void *(*alloc_coherent)(struct ib_device *dev,
1251 size_t size,
1252 u64 *dma_handle,
1253 gfp_t flag);
1254 void (*free_coherent)(struct ib_device *dev,
1255 size_t size, void *cpu_addr,
1256 u64 dma_handle);
1257};
1258
Tom Tucker07ebafb2006-08-03 16:02:42 -05001259struct iw_cm_verbs;
1260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261struct ib_device {
1262 struct device *dma_device;
1263
1264 char name[IB_DEVICE_NAME_MAX];
1265
1266 struct list_head event_handler_list;
1267 spinlock_t event_handler_lock;
1268
Alexander Chiang17a55f72010-02-02 19:09:16 +00001269 spinlock_t client_data_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 struct list_head core_list;
1271 struct list_head client_data_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 struct ib_cache cache;
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001274 int *pkey_tbl_len;
1275 int *gid_tbl_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001277 int num_comp_vectors;
1278
Tom Tucker07ebafb2006-08-03 16:02:42 -05001279 struct iw_cm_verbs *iwcm;
1280
Steve Wise7f624d02008-07-14 23:48:48 -07001281 int (*get_protocol_stats)(struct ib_device *device,
1282 union rdma_protocol_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 int (*query_device)(struct ib_device *device,
1284 struct ib_device_attr *device_attr);
1285 int (*query_port)(struct ib_device *device,
1286 u8 port_num,
1287 struct ib_port_attr *port_attr);
Eli Cohena3f5ada2010-09-27 17:51:10 -07001288 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1289 u8 port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 int (*query_gid)(struct ib_device *device,
1291 u8 port_num, int index,
1292 union ib_gid *gid);
1293 int (*query_pkey)(struct ib_device *device,
1294 u8 port_num, u16 index, u16 *pkey);
1295 int (*modify_device)(struct ib_device *device,
1296 int device_modify_mask,
1297 struct ib_device_modify *device_modify);
1298 int (*modify_port)(struct ib_device *device,
1299 u8 port_num, int port_modify_mask,
1300 struct ib_port_modify *port_modify);
Roland Dreiere2773c02005-07-07 17:57:10 -07001301 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1302 struct ib_udata *udata);
1303 int (*dealloc_ucontext)(struct ib_ucontext *context);
1304 int (*mmap)(struct ib_ucontext *context,
1305 struct vm_area_struct *vma);
1306 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1307 struct ib_ucontext *context,
1308 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 int (*dealloc_pd)(struct ib_pd *pd);
1310 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1311 struct ib_ah_attr *ah_attr);
1312 int (*modify_ah)(struct ib_ah *ah,
1313 struct ib_ah_attr *ah_attr);
1314 int (*query_ah)(struct ib_ah *ah,
1315 struct ib_ah_attr *ah_attr);
1316 int (*destroy_ah)(struct ib_ah *ah);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001317 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1318 struct ib_srq_init_attr *srq_init_attr,
1319 struct ib_udata *udata);
1320 int (*modify_srq)(struct ib_srq *srq,
1321 struct ib_srq_attr *srq_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001322 enum ib_srq_attr_mask srq_attr_mask,
1323 struct ib_udata *udata);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001324 int (*query_srq)(struct ib_srq *srq,
1325 struct ib_srq_attr *srq_attr);
1326 int (*destroy_srq)(struct ib_srq *srq);
1327 int (*post_srq_recv)(struct ib_srq *srq,
1328 struct ib_recv_wr *recv_wr,
1329 struct ib_recv_wr **bad_recv_wr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 struct ib_qp * (*create_qp)(struct ib_pd *pd,
Roland Dreiere2773c02005-07-07 17:57:10 -07001331 struct ib_qp_init_attr *qp_init_attr,
1332 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 int (*modify_qp)(struct ib_qp *qp,
1334 struct ib_qp_attr *qp_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001335 int qp_attr_mask,
1336 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 int (*query_qp)(struct ib_qp *qp,
1338 struct ib_qp_attr *qp_attr,
1339 int qp_attr_mask,
1340 struct ib_qp_init_attr *qp_init_attr);
1341 int (*destroy_qp)(struct ib_qp *qp);
1342 int (*post_send)(struct ib_qp *qp,
1343 struct ib_send_wr *send_wr,
1344 struct ib_send_wr **bad_send_wr);
1345 int (*post_recv)(struct ib_qp *qp,
1346 struct ib_recv_wr *recv_wr,
1347 struct ib_recv_wr **bad_recv_wr);
Roland Dreiere2773c02005-07-07 17:57:10 -07001348 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001349 int comp_vector,
Roland Dreiere2773c02005-07-07 17:57:10 -07001350 struct ib_ucontext *context,
1351 struct ib_udata *udata);
Eli Cohen2dd57162008-04-16 21:09:33 -07001352 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1353 u16 cq_period);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 int (*destroy_cq)(struct ib_cq *cq);
Roland Dreier33b9b3e2006-01-30 14:29:21 -08001355 int (*resize_cq)(struct ib_cq *cq, int cqe,
1356 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1358 struct ib_wc *wc);
1359 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1360 int (*req_notify_cq)(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001361 enum ib_cq_notify_flags flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 int (*req_ncomp_notif)(struct ib_cq *cq,
1363 int wc_cnt);
1364 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1365 int mr_access_flags);
1366 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
1367 struct ib_phys_buf *phys_buf_array,
1368 int num_phys_buf,
1369 int mr_access_flags,
1370 u64 *iova_start);
Roland Dreiere2773c02005-07-07 17:57:10 -07001371 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001372 u64 start, u64 length,
1373 u64 virt_addr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001374 int mr_access_flags,
1375 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 int (*query_mr)(struct ib_mr *mr,
1377 struct ib_mr_attr *mr_attr);
1378 int (*dereg_mr)(struct ib_mr *mr);
Steve Wise00f7ec32008-07-14 23:48:45 -07001379 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
1380 int max_page_list_len);
1381 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1382 int page_list_len);
1383 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 int (*rereg_phys_mr)(struct ib_mr *mr,
1385 int mr_rereg_mask,
1386 struct ib_pd *pd,
1387 struct ib_phys_buf *phys_buf_array,
1388 int num_phys_buf,
1389 int mr_access_flags,
1390 u64 *iova_start);
Shani Michaeli7083e422013-02-06 16:19:12 +00001391 struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
1392 enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 int (*bind_mw)(struct ib_qp *qp,
1394 struct ib_mw *mw,
1395 struct ib_mw_bind *mw_bind);
1396 int (*dealloc_mw)(struct ib_mw *mw);
1397 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1398 int mr_access_flags,
1399 struct ib_fmr_attr *fmr_attr);
1400 int (*map_phys_fmr)(struct ib_fmr *fmr,
1401 u64 *page_list, int list_len,
1402 u64 iova);
1403 int (*unmap_fmr)(struct list_head *fmr_list);
1404 int (*dealloc_fmr)(struct ib_fmr *fmr);
1405 int (*attach_mcast)(struct ib_qp *qp,
1406 union ib_gid *gid,
1407 u16 lid);
1408 int (*detach_mcast)(struct ib_qp *qp,
1409 union ib_gid *gid,
1410 u16 lid);
1411 int (*process_mad)(struct ib_device *device,
1412 int process_mad_flags,
1413 u8 port_num,
1414 struct ib_wc *in_wc,
1415 struct ib_grh *in_grh,
1416 struct ib_mad *in_mad,
1417 struct ib_mad *out_mad);
Sean Hefty59991f92011-05-23 17:52:46 -07001418 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1419 struct ib_ucontext *ucontext,
1420 struct ib_udata *udata);
1421 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001422 struct ib_flow * (*create_flow)(struct ib_qp *qp,
1423 struct ib_flow_attr
1424 *flow_attr,
1425 int domain);
1426 int (*destroy_flow)(struct ib_flow *flow_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Ralph Campbell9b513092006-12-12 14:27:41 -08001428 struct ib_dma_mapping_ops *dma_ops;
1429
Roland Dreiere2773c02005-07-07 17:57:10 -07001430 struct module *owner;
Tony Jonesf4e91eb2008-02-22 00:13:36 +01001431 struct device dev;
Greg Kroah-Hartman35be0682007-12-17 15:54:39 -04001432 struct kobject *ports_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 struct list_head port_list;
1434
1435 enum {
1436 IB_DEV_UNINITIALIZED,
1437 IB_DEV_REGISTERED,
1438 IB_DEV_UNREGISTERED
1439 } reg_state;
1440
Roland Dreier274c0892005-09-29 14:17:48 -07001441 int uverbs_abi_ver;
Alexander Chiang17a55f72010-02-02 19:09:16 +00001442 u64 uverbs_cmd_mask;
Yann Droneaudf21519b2013-11-06 23:21:49 +01001443 u64 uverbs_ex_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07001444
Roland Dreierc5bcbbb2006-02-02 09:47:14 -08001445 char node_desc[64];
Sean Heftycf311cd2006-01-10 07:39:34 -08001446 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07001447 u32 local_dma_lkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 u8 node_type;
1449 u8 phys_port_cnt;
1450};
1451
1452struct ib_client {
1453 char *name;
1454 void (*add) (struct ib_device *);
1455 void (*remove)(struct ib_device *);
1456
1457 struct list_head list;
1458};
1459
1460struct ib_device *ib_alloc_device(size_t size);
1461void ib_dealloc_device(struct ib_device *device);
1462
Ralph Campbell9a6edb62010-05-06 17:03:25 -07001463int ib_register_device(struct ib_device *device,
1464 int (*port_callback)(struct ib_device *,
1465 u8, struct kobject *));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466void ib_unregister_device(struct ib_device *device);
1467
1468int ib_register_client (struct ib_client *client);
1469void ib_unregister_client(struct ib_client *client);
1470
1471void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1472void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1473 void *data);
1474
Roland Dreiere2773c02005-07-07 17:57:10 -07001475static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1476{
1477 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1478}
1479
1480static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1481{
1482 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1483}
1484
Roland Dreier8a518662006-02-13 12:48:12 -08001485/**
1486 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1487 * contains all required attributes and no attributes not allowed for
1488 * the given QP state transition.
1489 * @cur_state: Current QP state
1490 * @next_state: Next QP state
1491 * @type: QP type
1492 * @mask: Mask of supplied QP attributes
1493 *
1494 * This function is a helper function that a low-level driver's
1495 * modify_qp method can use to validate the consumer's input. It
1496 * checks that cur_state and next_state are valid QP states, that a
1497 * transition from cur_state to next_state is allowed by the IB spec,
1498 * and that the attribute mask supplied is allowed for the transition.
1499 */
1500int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
1501 enum ib_qp_type type, enum ib_qp_attr_mask mask);
1502
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503int ib_register_event_handler (struct ib_event_handler *event_handler);
1504int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1505void ib_dispatch_event(struct ib_event *event);
1506
1507int ib_query_device(struct ib_device *device,
1508 struct ib_device_attr *device_attr);
1509
1510int ib_query_port(struct ib_device *device,
1511 u8 port_num, struct ib_port_attr *port_attr);
1512
Eli Cohena3f5ada2010-09-27 17:51:10 -07001513enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1514 u8 port_num);
1515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516int ib_query_gid(struct ib_device *device,
1517 u8 port_num, int index, union ib_gid *gid);
1518
1519int ib_query_pkey(struct ib_device *device,
1520 u8 port_num, u16 index, u16 *pkey);
1521
1522int ib_modify_device(struct ib_device *device,
1523 int device_modify_mask,
1524 struct ib_device_modify *device_modify);
1525
1526int ib_modify_port(struct ib_device *device,
1527 u8 port_num, int port_modify_mask,
1528 struct ib_port_modify *port_modify);
1529
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001530int ib_find_gid(struct ib_device *device, union ib_gid *gid,
1531 u8 *port_num, u16 *index);
1532
1533int ib_find_pkey(struct ib_device *device,
1534 u8 port_num, u16 pkey, u16 *index);
1535
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536/**
1537 * ib_alloc_pd - Allocates an unused protection domain.
1538 * @device: The device on which to allocate the protection domain.
1539 *
1540 * A protection domain object provides an association between QPs, shared
1541 * receive queues, address handles, memory regions, and memory windows.
1542 */
1543struct ib_pd *ib_alloc_pd(struct ib_device *device);
1544
1545/**
1546 * ib_dealloc_pd - Deallocates a protection domain.
1547 * @pd: The protection domain to deallocate.
1548 */
1549int ib_dealloc_pd(struct ib_pd *pd);
1550
1551/**
1552 * ib_create_ah - Creates an address handle for the given address vector.
1553 * @pd: The protection domain associated with the address handle.
1554 * @ah_attr: The attributes of the address vector.
1555 *
1556 * The address handle is used to reference a local or global destination
1557 * in all UD QP post sends.
1558 */
1559struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1560
1561/**
Sean Hefty4e00d692006-06-17 20:37:39 -07001562 * ib_init_ah_from_wc - Initializes address handle attributes from a
1563 * work completion.
1564 * @device: Device on which the received message arrived.
1565 * @port_num: Port on which the received message arrived.
1566 * @wc: Work completion associated with the received message.
1567 * @grh: References the received global route header. This parameter is
1568 * ignored unless the work completion indicates that the GRH is valid.
1569 * @ah_attr: Returned attributes that can be used when creating an address
1570 * handle for replying to the message.
1571 */
1572int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1573 struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1574
1575/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07001576 * ib_create_ah_from_wc - Creates an address handle associated with the
1577 * sender of the specified work completion.
1578 * @pd: The protection domain associated with the address handle.
1579 * @wc: Work completion information associated with a received message.
1580 * @grh: References the received global route header. This parameter is
1581 * ignored unless the work completion indicates that the GRH is valid.
1582 * @port_num: The outbound port number to associate with the address.
1583 *
1584 * The address handle is used to reference a local or global destination
1585 * in all UD QP post sends.
1586 */
1587struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1588 struct ib_grh *grh, u8 port_num);
1589
1590/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 * ib_modify_ah - Modifies the address vector associated with an address
1592 * handle.
1593 * @ah: The address handle to modify.
1594 * @ah_attr: The new address vector attributes to associate with the
1595 * address handle.
1596 */
1597int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1598
1599/**
1600 * ib_query_ah - Queries the address vector associated with an address
1601 * handle.
1602 * @ah: The address handle to query.
1603 * @ah_attr: The address vector attributes associated with the address
1604 * handle.
1605 */
1606int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1607
1608/**
1609 * ib_destroy_ah - Destroys an address handle.
1610 * @ah: The address handle to destroy.
1611 */
1612int ib_destroy_ah(struct ib_ah *ah);
1613
1614/**
Roland Dreierd41fcc62005-08-18 12:23:08 -07001615 * ib_create_srq - Creates a SRQ associated with the specified protection
1616 * domain.
1617 * @pd: The protection domain associated with the SRQ.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001618 * @srq_init_attr: A list of initial attributes required to create the
1619 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1620 * the actual capabilities of the created SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07001621 *
1622 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1623 * requested size of the SRQ, and set to the actual values allocated
1624 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
1625 * will always be at least as large as the requested values.
1626 */
1627struct ib_srq *ib_create_srq(struct ib_pd *pd,
1628 struct ib_srq_init_attr *srq_init_attr);
1629
1630/**
1631 * ib_modify_srq - Modifies the attributes for the specified SRQ.
1632 * @srq: The SRQ to modify.
1633 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1634 * the current values of selected SRQ attributes are returned.
1635 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1636 * are being modified.
1637 *
1638 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1639 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1640 * the number of receives queued drops below the limit.
1641 */
1642int ib_modify_srq(struct ib_srq *srq,
1643 struct ib_srq_attr *srq_attr,
1644 enum ib_srq_attr_mask srq_attr_mask);
1645
1646/**
1647 * ib_query_srq - Returns the attribute list and current values for the
1648 * specified SRQ.
1649 * @srq: The SRQ to query.
1650 * @srq_attr: The attributes of the specified SRQ.
1651 */
1652int ib_query_srq(struct ib_srq *srq,
1653 struct ib_srq_attr *srq_attr);
1654
1655/**
1656 * ib_destroy_srq - Destroys the specified SRQ.
1657 * @srq: The SRQ to destroy.
1658 */
1659int ib_destroy_srq(struct ib_srq *srq);
1660
1661/**
1662 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1663 * @srq: The SRQ to post the work request on.
1664 * @recv_wr: A list of work requests to post on the receive queue.
1665 * @bad_recv_wr: On an immediate failure, this parameter will reference
1666 * the work request that failed to be posted on the QP.
1667 */
1668static inline int ib_post_srq_recv(struct ib_srq *srq,
1669 struct ib_recv_wr *recv_wr,
1670 struct ib_recv_wr **bad_recv_wr)
1671{
1672 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1673}
1674
1675/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 * ib_create_qp - Creates a QP associated with the specified protection
1677 * domain.
1678 * @pd: The protection domain associated with the QP.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001679 * @qp_init_attr: A list of initial attributes required to create the
1680 * QP. If QP creation succeeds, then the attributes are updated to
1681 * the actual capabilities of the created QP.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 */
1683struct ib_qp *ib_create_qp(struct ib_pd *pd,
1684 struct ib_qp_init_attr *qp_init_attr);
1685
1686/**
1687 * ib_modify_qp - Modifies the attributes for the specified QP and then
1688 * transitions the QP to the given state.
1689 * @qp: The QP to modify.
1690 * @qp_attr: On input, specifies the QP attributes to modify. On output,
1691 * the current values of selected QP attributes are returned.
1692 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1693 * are being modified.
1694 */
1695int ib_modify_qp(struct ib_qp *qp,
1696 struct ib_qp_attr *qp_attr,
1697 int qp_attr_mask);
1698
1699/**
1700 * ib_query_qp - Returns the attribute list and current values for the
1701 * specified QP.
1702 * @qp: The QP to query.
1703 * @qp_attr: The attributes of the specified QP.
1704 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1705 * @qp_init_attr: Additional attributes of the selected QP.
1706 *
1707 * The qp_attr_mask may be used to limit the query to gathering only the
1708 * selected attributes.
1709 */
1710int ib_query_qp(struct ib_qp *qp,
1711 struct ib_qp_attr *qp_attr,
1712 int qp_attr_mask,
1713 struct ib_qp_init_attr *qp_init_attr);
1714
1715/**
1716 * ib_destroy_qp - Destroys the specified QP.
1717 * @qp: The QP to destroy.
1718 */
1719int ib_destroy_qp(struct ib_qp *qp);
1720
1721/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001722 * ib_open_qp - Obtain a reference to an existing sharable QP.
1723 * @xrcd - XRC domain
1724 * @qp_open_attr: Attributes identifying the QP to open.
1725 *
1726 * Returns a reference to a sharable QP.
1727 */
1728struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
1729 struct ib_qp_open_attr *qp_open_attr);
1730
1731/**
1732 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001733 * @qp: The QP handle to release
1734 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001735 * The opened QP handle is released by the caller. The underlying
1736 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001737 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001738int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07001739
1740/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 * ib_post_send - Posts a list of work requests to the send queue of
1742 * the specified QP.
1743 * @qp: The QP to post the work request on.
1744 * @send_wr: A list of work requests to post on the send queue.
1745 * @bad_send_wr: On an immediate failure, this parameter will reference
1746 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08001747 *
1748 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
1749 * error is returned, the QP state shall not be affected,
1750 * ib_post_send() will return an immediate error after queueing any
1751 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 */
1753static inline int ib_post_send(struct ib_qp *qp,
1754 struct ib_send_wr *send_wr,
1755 struct ib_send_wr **bad_send_wr)
1756{
1757 return qp->device->post_send(qp, send_wr, bad_send_wr);
1758}
1759
1760/**
1761 * ib_post_recv - Posts a list of work requests to the receive queue of
1762 * the specified QP.
1763 * @qp: The QP to post the work request on.
1764 * @recv_wr: A list of work requests to post on the receive queue.
1765 * @bad_recv_wr: On an immediate failure, this parameter will reference
1766 * the work request that failed to be posted on the QP.
1767 */
1768static inline int ib_post_recv(struct ib_qp *qp,
1769 struct ib_recv_wr *recv_wr,
1770 struct ib_recv_wr **bad_recv_wr)
1771{
1772 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1773}
1774
1775/**
1776 * ib_create_cq - Creates a CQ on the specified device.
1777 * @device: The device on which to create the CQ.
1778 * @comp_handler: A user-specified callback that is invoked when a
1779 * completion event occurs on the CQ.
1780 * @event_handler: A user-specified callback that is invoked when an
1781 * asynchronous event not associated with a completion occurs on the CQ.
1782 * @cq_context: Context associated with the CQ returned to the user via
1783 * the associated completion and event handlers.
1784 * @cqe: The minimum size of the CQ.
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001785 * @comp_vector - Completion vector used to signal completion events.
1786 * Must be >= 0 and < context->num_comp_vectors.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 *
1788 * Users can examine the cq structure to determine the actual CQ size.
1789 */
1790struct ib_cq *ib_create_cq(struct ib_device *device,
1791 ib_comp_handler comp_handler,
1792 void (*event_handler)(struct ib_event *, void *),
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001793 void *cq_context, int cqe, int comp_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
1795/**
1796 * ib_resize_cq - Modifies the capacity of the CQ.
1797 * @cq: The CQ to resize.
1798 * @cqe: The minimum size of the CQ.
1799 *
1800 * Users can examine the cq structure to determine the actual CQ size.
1801 */
1802int ib_resize_cq(struct ib_cq *cq, int cqe);
1803
1804/**
Eli Cohen2dd57162008-04-16 21:09:33 -07001805 * ib_modify_cq - Modifies moderation params of the CQ
1806 * @cq: The CQ to modify.
1807 * @cq_count: number of CQEs that will trigger an event
1808 * @cq_period: max period of time in usec before triggering an event
1809 *
1810 */
1811int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
1812
1813/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 * ib_destroy_cq - Destroys the specified CQ.
1815 * @cq: The CQ to destroy.
1816 */
1817int ib_destroy_cq(struct ib_cq *cq);
1818
1819/**
1820 * ib_poll_cq - poll a CQ for completion(s)
1821 * @cq:the CQ being polled
1822 * @num_entries:maximum number of completions to return
1823 * @wc:array of at least @num_entries &struct ib_wc where completions
1824 * will be returned
1825 *
1826 * Poll a CQ for (possibly multiple) completions. If the return value
1827 * is < 0, an error occurred. If the return value is >= 0, it is the
1828 * number of completions returned. If the return value is
1829 * non-negative and < num_entries, then the CQ was emptied.
1830 */
1831static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1832 struct ib_wc *wc)
1833{
1834 return cq->device->poll_cq(cq, num_entries, wc);
1835}
1836
1837/**
1838 * ib_peek_cq - Returns the number of unreaped completions currently
1839 * on the specified CQ.
1840 * @cq: The CQ to peek.
1841 * @wc_cnt: A minimum number of unreaped completions to check for.
1842 *
1843 * If the number of unreaped completions is greater than or equal to wc_cnt,
1844 * this function returns wc_cnt, otherwise, it returns the actual number of
1845 * unreaped completions.
1846 */
1847int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1848
1849/**
1850 * ib_req_notify_cq - Request completion notification on a CQ.
1851 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07001852 * @flags:
1853 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
1854 * to request an event on the next solicited event or next work
1855 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
1856 * may also be |ed in to request a hint about missed events, as
1857 * described below.
1858 *
1859 * Return Value:
1860 * < 0 means an error occurred while requesting notification
1861 * == 0 means notification was requested successfully, and if
1862 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
1863 * were missed and it is safe to wait for another event. In
1864 * this case is it guaranteed that any work completions added
1865 * to the CQ since the last CQ poll will trigger a completion
1866 * notification event.
1867 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
1868 * in. It means that the consumer must poll the CQ again to
1869 * make sure it is empty to avoid missing an event because of a
1870 * race between requesting notification and an entry being
1871 * added to the CQ. This return value means it is possible
1872 * (but not guaranteed) that a work completion has been added
1873 * to the CQ since the last poll without triggering a
1874 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 */
1876static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001877 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
Roland Dreiered23a722007-05-06 21:02:48 -07001879 return cq->device->req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880}
1881
1882/**
1883 * ib_req_ncomp_notif - Request completion notification when there are
1884 * at least the specified number of unreaped completions on the CQ.
1885 * @cq: The CQ to generate an event for.
1886 * @wc_cnt: The number of unreaped completions that should be on the
1887 * CQ before an event is generated.
1888 */
1889static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1890{
1891 return cq->device->req_ncomp_notif ?
1892 cq->device->req_ncomp_notif(cq, wc_cnt) :
1893 -ENOSYS;
1894}
1895
1896/**
1897 * ib_get_dma_mr - Returns a memory region for system memory that is
1898 * usable for DMA.
1899 * @pd: The protection domain associated with the memory region.
1900 * @mr_access_flags: Specifies the memory access rights.
Ralph Campbell9b513092006-12-12 14:27:41 -08001901 *
1902 * Note that the ib_dma_*() functions defined below must be used
1903 * to create/destroy addresses used with the Lkey or Rkey returned
1904 * by ib_get_dma_mr().
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 */
1906struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1907
1908/**
Ralph Campbell9b513092006-12-12 14:27:41 -08001909 * ib_dma_mapping_error - check a DMA addr for error
1910 * @dev: The device for which the dma_addr was created
1911 * @dma_addr: The DMA address to check
1912 */
1913static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1914{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001915 if (dev->dma_ops)
1916 return dev->dma_ops->mapping_error(dev, dma_addr);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001917 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08001918}
1919
1920/**
1921 * ib_dma_map_single - Map a kernel virtual address to DMA address
1922 * @dev: The device for which the dma_addr is to be created
1923 * @cpu_addr: The kernel virtual address
1924 * @size: The size of the region in bytes
1925 * @direction: The direction of the DMA
1926 */
1927static inline u64 ib_dma_map_single(struct ib_device *dev,
1928 void *cpu_addr, size_t size,
1929 enum dma_data_direction direction)
1930{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001931 if (dev->dma_ops)
1932 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
1933 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001934}
1935
1936/**
1937 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
1938 * @dev: The device for which the DMA address was created
1939 * @addr: The DMA address
1940 * @size: The size of the region in bytes
1941 * @direction: The direction of the DMA
1942 */
1943static inline void ib_dma_unmap_single(struct ib_device *dev,
1944 u64 addr, size_t size,
1945 enum dma_data_direction direction)
1946{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001947 if (dev->dma_ops)
1948 dev->dma_ops->unmap_single(dev, addr, size, direction);
1949 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001950 dma_unmap_single(dev->dma_device, addr, size, direction);
1951}
1952
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07001953static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
1954 void *cpu_addr, size_t size,
1955 enum dma_data_direction direction,
1956 struct dma_attrs *attrs)
1957{
1958 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
1959 direction, attrs);
1960}
1961
1962static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
1963 u64 addr, size_t size,
1964 enum dma_data_direction direction,
1965 struct dma_attrs *attrs)
1966{
1967 return dma_unmap_single_attrs(dev->dma_device, addr, size,
1968 direction, attrs);
1969}
1970
Ralph Campbell9b513092006-12-12 14:27:41 -08001971/**
1972 * ib_dma_map_page - Map a physical page to DMA address
1973 * @dev: The device for which the dma_addr is to be created
1974 * @page: The page to be mapped
1975 * @offset: The offset within the page
1976 * @size: The size of the region in bytes
1977 * @direction: The direction of the DMA
1978 */
1979static inline u64 ib_dma_map_page(struct ib_device *dev,
1980 struct page *page,
1981 unsigned long offset,
1982 size_t size,
1983 enum dma_data_direction direction)
1984{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001985 if (dev->dma_ops)
1986 return dev->dma_ops->map_page(dev, page, offset, size, direction);
1987 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001988}
1989
1990/**
1991 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
1992 * @dev: The device for which the DMA address was created
1993 * @addr: The DMA address
1994 * @size: The size of the region in bytes
1995 * @direction: The direction of the DMA
1996 */
1997static inline void ib_dma_unmap_page(struct ib_device *dev,
1998 u64 addr, size_t size,
1999 enum dma_data_direction direction)
2000{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002001 if (dev->dma_ops)
2002 dev->dma_ops->unmap_page(dev, addr, size, direction);
2003 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002004 dma_unmap_page(dev->dma_device, addr, size, direction);
2005}
2006
2007/**
2008 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
2009 * @dev: The device for which the DMA addresses are to be created
2010 * @sg: The array of scatter/gather entries
2011 * @nents: The number of scatter/gather entries
2012 * @direction: The direction of the DMA
2013 */
2014static inline int ib_dma_map_sg(struct ib_device *dev,
2015 struct scatterlist *sg, int nents,
2016 enum dma_data_direction direction)
2017{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002018 if (dev->dma_ops)
2019 return dev->dma_ops->map_sg(dev, sg, nents, direction);
2020 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002021}
2022
2023/**
2024 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
2025 * @dev: The device for which the DMA addresses were created
2026 * @sg: The array of scatter/gather entries
2027 * @nents: The number of scatter/gather entries
2028 * @direction: The direction of the DMA
2029 */
2030static inline void ib_dma_unmap_sg(struct ib_device *dev,
2031 struct scatterlist *sg, int nents,
2032 enum dma_data_direction direction)
2033{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002034 if (dev->dma_ops)
2035 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
2036 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002037 dma_unmap_sg(dev->dma_device, sg, nents, direction);
2038}
2039
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002040static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
2041 struct scatterlist *sg, int nents,
2042 enum dma_data_direction direction,
2043 struct dma_attrs *attrs)
2044{
2045 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2046}
2047
2048static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
2049 struct scatterlist *sg, int nents,
2050 enum dma_data_direction direction,
2051 struct dma_attrs *attrs)
2052{
2053 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2054}
Ralph Campbell9b513092006-12-12 14:27:41 -08002055/**
2056 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
2057 * @dev: The device for which the DMA addresses were created
2058 * @sg: The scatter/gather entry
2059 */
2060static inline u64 ib_sg_dma_address(struct ib_device *dev,
2061 struct scatterlist *sg)
2062{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002063 if (dev->dma_ops)
2064 return dev->dma_ops->dma_address(dev, sg);
2065 return sg_dma_address(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002066}
2067
2068/**
2069 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
2070 * @dev: The device for which the DMA addresses were created
2071 * @sg: The scatter/gather entry
2072 */
2073static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
2074 struct scatterlist *sg)
2075{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002076 if (dev->dma_ops)
2077 return dev->dma_ops->dma_len(dev, sg);
2078 return sg_dma_len(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002079}
2080
2081/**
2082 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
2083 * @dev: The device for which the DMA address was created
2084 * @addr: The DMA address
2085 * @size: The size of the region in bytes
2086 * @dir: The direction of the DMA
2087 */
2088static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
2089 u64 addr,
2090 size_t size,
2091 enum dma_data_direction dir)
2092{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002093 if (dev->dma_ops)
2094 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
2095 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002096 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
2097}
2098
2099/**
2100 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
2101 * @dev: The device for which the DMA address was created
2102 * @addr: The DMA address
2103 * @size: The size of the region in bytes
2104 * @dir: The direction of the DMA
2105 */
2106static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
2107 u64 addr,
2108 size_t size,
2109 enum dma_data_direction dir)
2110{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002111 if (dev->dma_ops)
2112 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
2113 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002114 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
2115}
2116
2117/**
2118 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
2119 * @dev: The device for which the DMA address is requested
2120 * @size: The size of the region to allocate in bytes
2121 * @dma_handle: A pointer for returning the DMA address of the region
2122 * @flag: memory allocator flags
2123 */
2124static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
2125 size_t size,
2126 u64 *dma_handle,
2127 gfp_t flag)
2128{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002129 if (dev->dma_ops)
2130 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Roland Dreierc59a3da2006-12-15 13:57:26 -08002131 else {
2132 dma_addr_t handle;
2133 void *ret;
2134
2135 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
2136 *dma_handle = handle;
2137 return ret;
2138 }
Ralph Campbell9b513092006-12-12 14:27:41 -08002139}
2140
2141/**
2142 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
2143 * @dev: The device for which the DMA addresses were allocated
2144 * @size: The size of the region
2145 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
2146 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
2147 */
2148static inline void ib_dma_free_coherent(struct ib_device *dev,
2149 size_t size, void *cpu_addr,
2150 u64 dma_handle)
2151{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002152 if (dev->dma_ops)
2153 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
2154 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002155 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
2156}
2157
2158/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
2160 * by an HCA.
2161 * @pd: The protection domain associated assigned to the registered region.
2162 * @phys_buf_array: Specifies a list of physical buffers to use in the
2163 * memory region.
2164 * @num_phys_buf: Specifies the size of the phys_buf_array.
2165 * @mr_access_flags: Specifies the memory access rights.
2166 * @iova_start: The offset of the region's starting I/O virtual address.
2167 */
2168struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
2169 struct ib_phys_buf *phys_buf_array,
2170 int num_phys_buf,
2171 int mr_access_flags,
2172 u64 *iova_start);
2173
2174/**
2175 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
2176 * Conceptually, this call performs the functions deregister memory region
2177 * followed by register physical memory region. Where possible,
2178 * resources are reused instead of deallocated and reallocated.
2179 * @mr: The memory region to modify.
2180 * @mr_rereg_mask: A bit-mask used to indicate which of the following
2181 * properties of the memory region are being modified.
2182 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
2183 * the new protection domain to associated with the memory region,
2184 * otherwise, this parameter is ignored.
2185 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2186 * field specifies a list of physical buffers to use in the new
2187 * translation, otherwise, this parameter is ignored.
2188 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2189 * field specifies the size of the phys_buf_array, otherwise, this
2190 * parameter is ignored.
2191 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
2192 * field specifies the new memory access rights, otherwise, this
2193 * parameter is ignored.
2194 * @iova_start: The offset of the region's starting I/O virtual address.
2195 */
2196int ib_rereg_phys_mr(struct ib_mr *mr,
2197 int mr_rereg_mask,
2198 struct ib_pd *pd,
2199 struct ib_phys_buf *phys_buf_array,
2200 int num_phys_buf,
2201 int mr_access_flags,
2202 u64 *iova_start);
2203
2204/**
2205 * ib_query_mr - Retrieves information about a specific memory region.
2206 * @mr: The memory region to retrieve information about.
2207 * @mr_attr: The attributes of the specified memory region.
2208 */
2209int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
2210
2211/**
2212 * ib_dereg_mr - Deregisters a memory region and removes it from the
2213 * HCA translation table.
2214 * @mr: The memory region to deregister.
Shani Michaeli7083e422013-02-06 16:19:12 +00002215 *
2216 * This function can fail, if the memory region has memory windows bound to it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 */
2218int ib_dereg_mr(struct ib_mr *mr);
2219
2220/**
Steve Wise00f7ec32008-07-14 23:48:45 -07002221 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
2222 * IB_WR_FAST_REG_MR send work request.
2223 * @pd: The protection domain associated with the region.
2224 * @max_page_list_len: requested max physical buffer list length to be
2225 * used with fast register work requests for this MR.
2226 */
2227struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2228
2229/**
2230 * ib_alloc_fast_reg_page_list - Allocates a page list array
2231 * @device - ib device pointer.
2232 * @page_list_len - size of the page list array to be allocated.
2233 *
2234 * This allocates and returns a struct ib_fast_reg_page_list * and a
2235 * page_list array that is at least page_list_len in size. The actual
2236 * size is returned in max_page_list_len. The caller is responsible
2237 * for initializing the contents of the page_list array before posting
2238 * a send work request with the IB_WC_FAST_REG_MR opcode.
2239 *
2240 * The page_list array entries must be translated using one of the
2241 * ib_dma_*() functions just like the addresses passed to
2242 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
2243 * ib_fast_reg_page_list must not be modified by the caller until the
2244 * IB_WC_FAST_REG_MR work request completes.
2245 */
2246struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2247 struct ib_device *device, int page_list_len);
2248
2249/**
2250 * ib_free_fast_reg_page_list - Deallocates a previously allocated
2251 * page list array.
2252 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2253 */
2254void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2255
2256/**
2257 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2258 * R_Key and L_Key.
2259 * @mr - struct ib_mr pointer to be updated.
2260 * @newkey - new key to be used.
2261 */
2262static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2263{
2264 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2265 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2266}
2267
2268/**
Shani Michaeli7083e422013-02-06 16:19:12 +00002269 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
2270 * for calculating a new rkey for type 2 memory windows.
2271 * @rkey - the rkey to increment.
2272 */
2273static inline u32 ib_inc_rkey(u32 rkey)
2274{
2275 const u32 mask = 0x000000ff;
2276 return ((rkey + 1) & mask) | (rkey & ~mask);
2277}
2278
2279/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 * ib_alloc_mw - Allocates a memory window.
2281 * @pd: The protection domain associated with the memory window.
Shani Michaeli7083e422013-02-06 16:19:12 +00002282 * @type: The type of the memory window (1 or 2).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 */
Shani Michaeli7083e422013-02-06 16:19:12 +00002284struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
2286/**
2287 * ib_bind_mw - Posts a work request to the send queue of the specified
2288 * QP, which binds the memory window to the given address range and
2289 * remote access attributes.
2290 * @qp: QP to post the bind work request on.
2291 * @mw: The memory window to bind.
2292 * @mw_bind: Specifies information about the memory window, including
2293 * its address range, remote access rights, and associated memory region.
Shani Michaeli7083e422013-02-06 16:19:12 +00002294 *
2295 * If there is no immediate error, the function will update the rkey member
2296 * of the mw parameter to its new value. The bind operation can still fail
2297 * asynchronously.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 */
2299static inline int ib_bind_mw(struct ib_qp *qp,
2300 struct ib_mw *mw,
2301 struct ib_mw_bind *mw_bind)
2302{
2303 /* XXX reference counting in corresponding MR? */
2304 return mw->device->bind_mw ?
2305 mw->device->bind_mw(qp, mw, mw_bind) :
2306 -ENOSYS;
2307}
2308
2309/**
2310 * ib_dealloc_mw - Deallocates a memory window.
2311 * @mw: The memory window to deallocate.
2312 */
2313int ib_dealloc_mw(struct ib_mw *mw);
2314
2315/**
2316 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2317 * @pd: The protection domain associated with the unmapped region.
2318 * @mr_access_flags: Specifies the memory access rights.
2319 * @fmr_attr: Attributes of the unmapped region.
2320 *
2321 * A fast memory region must be mapped before it can be used as part of
2322 * a work request.
2323 */
2324struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2325 int mr_access_flags,
2326 struct ib_fmr_attr *fmr_attr);
2327
2328/**
2329 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2330 * @fmr: The fast memory region to associate with the pages.
2331 * @page_list: An array of physical pages to map to the fast memory region.
2332 * @list_len: The number of pages in page_list.
2333 * @iova: The I/O virtual address to use with the mapped region.
2334 */
2335static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2336 u64 *page_list, int list_len,
2337 u64 iova)
2338{
2339 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2340}
2341
2342/**
2343 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2344 * @fmr_list: A linked list of fast memory regions to unmap.
2345 */
2346int ib_unmap_fmr(struct list_head *fmr_list);
2347
2348/**
2349 * ib_dealloc_fmr - Deallocates a fast memory region.
2350 * @fmr: The fast memory region to deallocate.
2351 */
2352int ib_dealloc_fmr(struct ib_fmr *fmr);
2353
2354/**
2355 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2356 * @qp: QP to attach to the multicast group. The QP must be type
2357 * IB_QPT_UD.
2358 * @gid: Multicast group GID.
2359 * @lid: Multicast group LID in host byte order.
2360 *
2361 * In order to send and receive multicast packets, subnet
2362 * administration must have created the multicast group and configured
2363 * the fabric appropriately. The port associated with the specified
2364 * QP must also be a member of the multicast group.
2365 */
2366int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2367
2368/**
2369 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2370 * @qp: QP to detach from the multicast group.
2371 * @gid: Multicast group GID.
2372 * @lid: Multicast group LID in host byte order.
2373 */
2374int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2375
Sean Hefty59991f92011-05-23 17:52:46 -07002376/**
2377 * ib_alloc_xrcd - Allocates an XRC domain.
2378 * @device: The device on which to allocate the XRC domain.
2379 */
2380struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2381
2382/**
2383 * ib_dealloc_xrcd - Deallocates an XRC domain.
2384 * @xrcd: The XRC domain to deallocate.
2385 */
2386int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2387
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002388struct ib_flow *ib_create_flow(struct ib_qp *qp,
2389 struct ib_flow_attr *flow_attr, int domain);
2390int ib_destroy_flow(struct ib_flow *flow_id);
2391
Eli Cohen1c636f82013-10-31 15:26:32 +02002392static inline int ib_check_mr_access(int flags)
2393{
2394 /*
2395 * Local write permission is required if remote write or
2396 * remote atomic permission is also requested.
2397 */
2398 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
2399 !(flags & IB_ACCESS_LOCAL_WRITE))
2400 return -EINVAL;
2401
2402 return 0;
2403}
2404
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405#endif /* IB_VERBS_H */