blob: a84d3dfc40765f7ac688bb3e1932e4aa89e544a7 [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,
70 RDMA_NODE_RNIC
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};
72
Tom Tucker07ebafb2006-08-03 16:02:42 -050073enum rdma_transport_type {
74 RDMA_TRANSPORT_IB,
75 RDMA_TRANSPORT_IWARP
76};
77
78enum rdma_transport_type
79rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
80
Eli Cohena3f5ada2010-09-27 17:51:10 -070081enum rdma_link_layer {
82 IB_LINK_LAYER_UNSPECIFIED,
83 IB_LINK_LAYER_INFINIBAND,
84 IB_LINK_LAYER_ETHERNET,
85};
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087enum ib_device_cap_flags {
88 IB_DEVICE_RESIZE_MAX_WR = 1,
89 IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
90 IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
91 IB_DEVICE_RAW_MULTI = (1<<3),
92 IB_DEVICE_AUTO_PATH_MIG = (1<<4),
93 IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
94 IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
95 IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
96 IB_DEVICE_SHUTDOWN_PORT = (1<<8),
97 IB_DEVICE_INIT_TYPE = (1<<9),
98 IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
99 IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
100 IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
101 IB_DEVICE_SRQ_RESIZE = (1<<13),
102 IB_DEVICE_N_NOTIFY_CQ = (1<<14),
Steve Wise96f15c02008-07-14 23:48:53 -0700103 IB_DEVICE_LOCAL_DMA_LKEY = (1<<15),
Roland Dreier0f39cf32008-04-16 21:09:32 -0700104 IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
Eli Cohene0605d92008-01-30 18:30:57 +0200105 IB_DEVICE_MEM_WINDOW = (1<<17),
106 /*
107 * Devices should set IB_DEVICE_UD_IP_SUM if they support
108 * insertion of UDP and TCP checksum on outgoing UD IPoIB
109 * messages and can verify the validity of checksum for
110 * incoming messages. Setting this flag implies that the
111 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
112 */
113 IB_DEVICE_UD_IP_CSUM = (1<<18),
Eli Cohenc93570f2008-04-16 21:09:27 -0700114 IB_DEVICE_UD_TSO = (1<<19),
Sean Hefty59991f92011-05-23 17:52:46 -0700115 IB_DEVICE_XRC = (1<<20),
Steve Wise00f7ec32008-07-14 23:48:45 -0700116 IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21),
Ron Livne47ee1b92008-07-14 23:48:48 -0700117 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
Shani Michaeli7083e422013-02-06 16:19:12 +0000118 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1<<23),
119 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
122enum ib_atomic_cap {
123 IB_ATOMIC_NONE,
124 IB_ATOMIC_HCA,
125 IB_ATOMIC_GLOB
126};
127
128struct ib_device_attr {
129 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700130 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 u64 max_mr_size;
132 u64 page_size_cap;
133 u32 vendor_id;
134 u32 vendor_part_id;
135 u32 hw_ver;
136 int max_qp;
137 int max_qp_wr;
138 int device_cap_flags;
139 int max_sge;
140 int max_sge_rd;
141 int max_cq;
142 int max_cqe;
143 int max_mr;
144 int max_pd;
145 int max_qp_rd_atom;
146 int max_ee_rd_atom;
147 int max_res_rd_atom;
148 int max_qp_init_rd_atom;
149 int max_ee_init_rd_atom;
150 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300151 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 int max_ee;
153 int max_rdd;
154 int max_mw;
155 int max_raw_ipv6_qp;
156 int max_raw_ethy_qp;
157 int max_mcast_grp;
158 int max_mcast_qp_attach;
159 int max_total_mcast_qp_attach;
160 int max_ah;
161 int max_fmr;
162 int max_map_per_fmr;
163 int max_srq;
164 int max_srq_wr;
165 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700166 unsigned int max_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 u16 max_pkeys;
168 u8 local_ca_ack_delay;
169};
170
171enum ib_mtu {
172 IB_MTU_256 = 1,
173 IB_MTU_512 = 2,
174 IB_MTU_1024 = 3,
175 IB_MTU_2048 = 4,
176 IB_MTU_4096 = 5
177};
178
179static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
180{
181 switch (mtu) {
182 case IB_MTU_256: return 256;
183 case IB_MTU_512: return 512;
184 case IB_MTU_1024: return 1024;
185 case IB_MTU_2048: return 2048;
186 case IB_MTU_4096: return 4096;
187 default: return -1;
188 }
189}
190
191enum ib_port_state {
192 IB_PORT_NOP = 0,
193 IB_PORT_DOWN = 1,
194 IB_PORT_INIT = 2,
195 IB_PORT_ARMED = 3,
196 IB_PORT_ACTIVE = 4,
197 IB_PORT_ACTIVE_DEFER = 5
198};
199
200enum ib_port_cap_flags {
201 IB_PORT_SM = 1 << 1,
202 IB_PORT_NOTICE_SUP = 1 << 2,
203 IB_PORT_TRAP_SUP = 1 << 3,
204 IB_PORT_OPT_IPD_SUP = 1 << 4,
205 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
206 IB_PORT_SL_MAP_SUP = 1 << 6,
207 IB_PORT_MKEY_NVRAM = 1 << 7,
208 IB_PORT_PKEY_NVRAM = 1 << 8,
209 IB_PORT_LED_INFO_SUP = 1 << 9,
210 IB_PORT_SM_DISABLED = 1 << 10,
211 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
212 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300213 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 IB_PORT_CM_SUP = 1 << 16,
215 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
216 IB_PORT_REINIT_SUP = 1 << 18,
217 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
218 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
219 IB_PORT_DR_NOTICE_SUP = 1 << 21,
220 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
221 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
222 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
223 IB_PORT_CLIENT_REG_SUP = 1 << 25
224};
225
226enum ib_port_width {
227 IB_WIDTH_1X = 1,
228 IB_WIDTH_4X = 2,
229 IB_WIDTH_8X = 4,
230 IB_WIDTH_12X = 8
231};
232
233static inline int ib_width_enum_to_int(enum ib_port_width width)
234{
235 switch (width) {
236 case IB_WIDTH_1X: return 1;
237 case IB_WIDTH_4X: return 4;
238 case IB_WIDTH_8X: return 8;
239 case IB_WIDTH_12X: return 12;
240 default: return -1;
241 }
242}
243
Or Gerlitz2e966912012-02-28 18:49:50 +0200244enum ib_port_speed {
245 IB_SPEED_SDR = 1,
246 IB_SPEED_DDR = 2,
247 IB_SPEED_QDR = 4,
248 IB_SPEED_FDR10 = 8,
249 IB_SPEED_FDR = 16,
250 IB_SPEED_EDR = 32
251};
252
Steve Wise7f624d02008-07-14 23:48:48 -0700253struct ib_protocol_stats {
254 /* TBD... */
255};
256
257struct iw_protocol_stats {
258 u64 ipInReceives;
259 u64 ipInHdrErrors;
260 u64 ipInTooBigErrors;
261 u64 ipInNoRoutes;
262 u64 ipInAddrErrors;
263 u64 ipInUnknownProtos;
264 u64 ipInTruncatedPkts;
265 u64 ipInDiscards;
266 u64 ipInDelivers;
267 u64 ipOutForwDatagrams;
268 u64 ipOutRequests;
269 u64 ipOutDiscards;
270 u64 ipOutNoRoutes;
271 u64 ipReasmTimeout;
272 u64 ipReasmReqds;
273 u64 ipReasmOKs;
274 u64 ipReasmFails;
275 u64 ipFragOKs;
276 u64 ipFragFails;
277 u64 ipFragCreates;
278 u64 ipInMcastPkts;
279 u64 ipOutMcastPkts;
280 u64 ipInBcastPkts;
281 u64 ipOutBcastPkts;
282
283 u64 tcpRtoAlgorithm;
284 u64 tcpRtoMin;
285 u64 tcpRtoMax;
286 u64 tcpMaxConn;
287 u64 tcpActiveOpens;
288 u64 tcpPassiveOpens;
289 u64 tcpAttemptFails;
290 u64 tcpEstabResets;
291 u64 tcpCurrEstab;
292 u64 tcpInSegs;
293 u64 tcpOutSegs;
294 u64 tcpRetransSegs;
295 u64 tcpInErrs;
296 u64 tcpOutRsts;
297};
298
299union rdma_protocol_stats {
300 struct ib_protocol_stats ib;
301 struct iw_protocol_stats iw;
302};
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304struct ib_port_attr {
305 enum ib_port_state state;
306 enum ib_mtu max_mtu;
307 enum ib_mtu active_mtu;
308 int gid_tbl_len;
309 u32 port_cap_flags;
310 u32 max_msg_sz;
311 u32 bad_pkey_cntr;
312 u32 qkey_viol_cntr;
313 u16 pkey_tbl_len;
314 u16 lid;
315 u16 sm_lid;
316 u8 lmc;
317 u8 max_vl_num;
318 u8 sm_sl;
319 u8 subnet_timeout;
320 u8 init_type_reply;
321 u8 active_width;
322 u8 active_speed;
323 u8 phys_state;
324};
325
326enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800327 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
328 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329};
330
331struct ib_device_modify {
332 u64 sys_image_guid;
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800333 char node_desc[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334};
335
336enum ib_port_modify_flags {
337 IB_PORT_SHUTDOWN = 1,
338 IB_PORT_INIT_TYPE = (1<<2),
339 IB_PORT_RESET_QKEY_CNTR = (1<<3)
340};
341
342struct ib_port_modify {
343 u32 set_port_cap_mask;
344 u32 clr_port_cap_mask;
345 u8 init_type;
346};
347
348enum ib_event_type {
349 IB_EVENT_CQ_ERR,
350 IB_EVENT_QP_FATAL,
351 IB_EVENT_QP_REQ_ERR,
352 IB_EVENT_QP_ACCESS_ERR,
353 IB_EVENT_COMM_EST,
354 IB_EVENT_SQ_DRAINED,
355 IB_EVENT_PATH_MIG,
356 IB_EVENT_PATH_MIG_ERR,
357 IB_EVENT_DEVICE_FATAL,
358 IB_EVENT_PORT_ACTIVE,
359 IB_EVENT_PORT_ERR,
360 IB_EVENT_LID_CHANGE,
361 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700362 IB_EVENT_SM_CHANGE,
363 IB_EVENT_SRQ_ERR,
364 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700365 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000366 IB_EVENT_CLIENT_REREGISTER,
367 IB_EVENT_GID_CHANGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368};
369
370struct ib_event {
371 struct ib_device *device;
372 union {
373 struct ib_cq *cq;
374 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700375 struct ib_srq *srq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 u8 port_num;
377 } element;
378 enum ib_event_type event;
379};
380
381struct ib_event_handler {
382 struct ib_device *device;
383 void (*handler)(struct ib_event_handler *, struct ib_event *);
384 struct list_head list;
385};
386
387#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
388 do { \
389 (_ptr)->device = _device; \
390 (_ptr)->handler = _handler; \
391 INIT_LIST_HEAD(&(_ptr)->list); \
392 } while (0)
393
394struct ib_global_route {
395 union ib_gid dgid;
396 u32 flow_label;
397 u8 sgid_index;
398 u8 hop_limit;
399 u8 traffic_class;
400};
401
Hal Rosenstock513789e2005-07-27 11:45:34 -0700402struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700403 __be32 version_tclass_flow;
404 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700405 u8 next_hdr;
406 u8 hop_limit;
407 union ib_gid sgid;
408 union ib_gid dgid;
409};
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411enum {
412 IB_MULTICAST_QPN = 0xffffff
413};
414
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800415#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417enum ib_ah_flags {
418 IB_AH_GRH = 1
419};
420
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700421enum ib_rate {
422 IB_RATE_PORT_CURRENT = 0,
423 IB_RATE_2_5_GBPS = 2,
424 IB_RATE_5_GBPS = 5,
425 IB_RATE_10_GBPS = 3,
426 IB_RATE_20_GBPS = 6,
427 IB_RATE_30_GBPS = 4,
428 IB_RATE_40_GBPS = 7,
429 IB_RATE_60_GBPS = 8,
430 IB_RATE_80_GBPS = 9,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300431 IB_RATE_120_GBPS = 10,
432 IB_RATE_14_GBPS = 11,
433 IB_RATE_56_GBPS = 12,
434 IB_RATE_112_GBPS = 13,
435 IB_RATE_168_GBPS = 14,
436 IB_RATE_25_GBPS = 15,
437 IB_RATE_100_GBPS = 16,
438 IB_RATE_200_GBPS = 17,
439 IB_RATE_300_GBPS = 18
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700440};
441
442/**
443 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
444 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
445 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
446 * @rate: rate to convert.
447 */
448int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
449
450/**
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300451 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
452 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
453 * @rate: rate to convert.
454 */
455int ib_rate_to_mbps(enum ib_rate rate) __attribute_const__;
456
457/**
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700458 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
459 * enum.
460 * @mult: multiple to convert.
461 */
462enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464struct ib_ah_attr {
465 struct ib_global_route grh;
466 u16 dlid;
467 u8 sl;
468 u8 src_path_bits;
469 u8 static_rate;
470 u8 ah_flags;
471 u8 port_num;
472};
473
474enum ib_wc_status {
475 IB_WC_SUCCESS,
476 IB_WC_LOC_LEN_ERR,
477 IB_WC_LOC_QP_OP_ERR,
478 IB_WC_LOC_EEC_OP_ERR,
479 IB_WC_LOC_PROT_ERR,
480 IB_WC_WR_FLUSH_ERR,
481 IB_WC_MW_BIND_ERR,
482 IB_WC_BAD_RESP_ERR,
483 IB_WC_LOC_ACCESS_ERR,
484 IB_WC_REM_INV_REQ_ERR,
485 IB_WC_REM_ACCESS_ERR,
486 IB_WC_REM_OP_ERR,
487 IB_WC_RETRY_EXC_ERR,
488 IB_WC_RNR_RETRY_EXC_ERR,
489 IB_WC_LOC_RDD_VIOL_ERR,
490 IB_WC_REM_INV_RD_REQ_ERR,
491 IB_WC_REM_ABORT_ERR,
492 IB_WC_INV_EECN_ERR,
493 IB_WC_INV_EEC_STATE_ERR,
494 IB_WC_FATAL_ERR,
495 IB_WC_RESP_TIMEOUT_ERR,
496 IB_WC_GENERAL_ERR
497};
498
499enum ib_wc_opcode {
500 IB_WC_SEND,
501 IB_WC_RDMA_WRITE,
502 IB_WC_RDMA_READ,
503 IB_WC_COMP_SWAP,
504 IB_WC_FETCH_ADD,
505 IB_WC_BIND_MW,
Eli Cohenc93570f2008-04-16 21:09:27 -0700506 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700507 IB_WC_LOCAL_INV,
508 IB_WC_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300509 IB_WC_MASKED_COMP_SWAP,
510 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511/*
512 * Set value of IB_WC_RECV so consumers can test if a completion is a
513 * receive by testing (opcode & IB_WC_RECV).
514 */
515 IB_WC_RECV = 1 << 7,
516 IB_WC_RECV_RDMA_WITH_IMM
517};
518
519enum ib_wc_flags {
520 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -0700521 IB_WC_WITH_IMM = (1<<1),
522 IB_WC_WITH_INVALIDATE = (1<<2),
Or Gerlitzd927d502012-01-11 19:03:51 +0200523 IB_WC_IP_CSUM_OK = (1<<3),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524};
525
526struct ib_wc {
527 u64 wr_id;
528 enum ib_wc_status status;
529 enum ib_wc_opcode opcode;
530 u32 vendor_err;
531 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +0200532 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -0700533 union {
534 __be32 imm_data;
535 u32 invalidate_rkey;
536 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 u32 src_qp;
538 int wc_flags;
539 u16 pkey_index;
540 u16 slid;
541 u8 sl;
542 u8 dlid_path_bits;
543 u8 port_num; /* valid only for DR SMPs on switches */
544};
545
Roland Dreiered23a722007-05-06 21:02:48 -0700546enum ib_cq_notify_flags {
547 IB_CQ_SOLICITED = 1 << 0,
548 IB_CQ_NEXT_COMP = 1 << 1,
549 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
550 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551};
552
Sean Hefty96104ed2011-05-23 16:31:36 -0700553enum ib_srq_type {
Sean Hefty418d5132011-05-23 19:42:29 -0700554 IB_SRQT_BASIC,
555 IB_SRQT_XRC
Sean Hefty96104ed2011-05-23 16:31:36 -0700556};
557
Roland Dreierd41fcc62005-08-18 12:23:08 -0700558enum ib_srq_attr_mask {
559 IB_SRQ_MAX_WR = 1 << 0,
560 IB_SRQ_LIMIT = 1 << 1,
561};
562
563struct ib_srq_attr {
564 u32 max_wr;
565 u32 max_sge;
566 u32 srq_limit;
567};
568
569struct ib_srq_init_attr {
570 void (*event_handler)(struct ib_event *, void *);
571 void *srq_context;
572 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -0700573 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -0700574
575 union {
576 struct {
577 struct ib_xrcd *xrcd;
578 struct ib_cq *cq;
579 } xrc;
580 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700581};
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583struct ib_qp_cap {
584 u32 max_send_wr;
585 u32 max_recv_wr;
586 u32 max_send_sge;
587 u32 max_recv_sge;
588 u32 max_inline_data;
589};
590
591enum ib_sig_type {
592 IB_SIGNAL_ALL_WR,
593 IB_SIGNAL_REQ_WR
594};
595
596enum ib_qp_type {
597 /*
598 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
599 * here (and in that order) since the MAD layer uses them as
600 * indices into a 2-entry table.
601 */
602 IB_QPT_SMI,
603 IB_QPT_GSI,
604
605 IB_QPT_RC,
606 IB_QPT_UC,
607 IB_QPT_UD,
608 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700609 IB_QPT_RAW_ETHERTYPE,
Or Gerlitzc938a612012-03-01 12:17:51 +0200610 IB_QPT_RAW_PACKET = 8,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700611 IB_QPT_XRC_INI = 9,
612 IB_QPT_XRC_TGT,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300613 IB_QPT_MAX,
614 /* Reserve a range for qp types internal to the low level driver.
615 * These qp types will not be visible at the IB core layer, so the
616 * IB_QPT_MAX usages should not be affected in the core layer
617 */
618 IB_QPT_RESERVED1 = 0x1000,
619 IB_QPT_RESERVED2,
620 IB_QPT_RESERVED3,
621 IB_QPT_RESERVED4,
622 IB_QPT_RESERVED5,
623 IB_QPT_RESERVED6,
624 IB_QPT_RESERVED7,
625 IB_QPT_RESERVED8,
626 IB_QPT_RESERVED9,
627 IB_QPT_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628};
629
Eli Cohenb846f252008-04-16 21:09:27 -0700630enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -0700631 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
632 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
Jack Morgensteind2b57062012-08-03 08:40:37 +0000633 /* reserve bits 26-31 for low level drivers' internal use */
634 IB_QP_CREATE_RESERVED_START = 1 << 26,
635 IB_QP_CREATE_RESERVED_END = 1 << 31,
Eli Cohenb846f252008-04-16 21:09:27 -0700636};
637
Yishai Hadas73c40c62013-08-01 18:49:53 +0300638
639/*
640 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
641 * callback to destroy the passed in QP.
642 */
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644struct ib_qp_init_attr {
645 void (*event_handler)(struct ib_event *, void *);
646 void *qp_context;
647 struct ib_cq *send_cq;
648 struct ib_cq *recv_cq;
649 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700650 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 struct ib_qp_cap cap;
652 enum ib_sig_type sq_sig_type;
653 enum ib_qp_type qp_type;
Eli Cohenb846f252008-04-16 21:09:27 -0700654 enum ib_qp_create_flags create_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 u8 port_num; /* special QP types only */
656};
657
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700658struct ib_qp_open_attr {
659 void (*event_handler)(struct ib_event *, void *);
660 void *qp_context;
661 u32 qp_num;
662 enum ib_qp_type qp_type;
663};
664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665enum ib_rnr_timeout {
666 IB_RNR_TIMER_655_36 = 0,
667 IB_RNR_TIMER_000_01 = 1,
668 IB_RNR_TIMER_000_02 = 2,
669 IB_RNR_TIMER_000_03 = 3,
670 IB_RNR_TIMER_000_04 = 4,
671 IB_RNR_TIMER_000_06 = 5,
672 IB_RNR_TIMER_000_08 = 6,
673 IB_RNR_TIMER_000_12 = 7,
674 IB_RNR_TIMER_000_16 = 8,
675 IB_RNR_TIMER_000_24 = 9,
676 IB_RNR_TIMER_000_32 = 10,
677 IB_RNR_TIMER_000_48 = 11,
678 IB_RNR_TIMER_000_64 = 12,
679 IB_RNR_TIMER_000_96 = 13,
680 IB_RNR_TIMER_001_28 = 14,
681 IB_RNR_TIMER_001_92 = 15,
682 IB_RNR_TIMER_002_56 = 16,
683 IB_RNR_TIMER_003_84 = 17,
684 IB_RNR_TIMER_005_12 = 18,
685 IB_RNR_TIMER_007_68 = 19,
686 IB_RNR_TIMER_010_24 = 20,
687 IB_RNR_TIMER_015_36 = 21,
688 IB_RNR_TIMER_020_48 = 22,
689 IB_RNR_TIMER_030_72 = 23,
690 IB_RNR_TIMER_040_96 = 24,
691 IB_RNR_TIMER_061_44 = 25,
692 IB_RNR_TIMER_081_92 = 26,
693 IB_RNR_TIMER_122_88 = 27,
694 IB_RNR_TIMER_163_84 = 28,
695 IB_RNR_TIMER_245_76 = 29,
696 IB_RNR_TIMER_327_68 = 30,
697 IB_RNR_TIMER_491_52 = 31
698};
699
700enum ib_qp_attr_mask {
701 IB_QP_STATE = 1,
702 IB_QP_CUR_STATE = (1<<1),
703 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
704 IB_QP_ACCESS_FLAGS = (1<<3),
705 IB_QP_PKEY_INDEX = (1<<4),
706 IB_QP_PORT = (1<<5),
707 IB_QP_QKEY = (1<<6),
708 IB_QP_AV = (1<<7),
709 IB_QP_PATH_MTU = (1<<8),
710 IB_QP_TIMEOUT = (1<<9),
711 IB_QP_RETRY_CNT = (1<<10),
712 IB_QP_RNR_RETRY = (1<<11),
713 IB_QP_RQ_PSN = (1<<12),
714 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
715 IB_QP_ALT_PATH = (1<<14),
716 IB_QP_MIN_RNR_TIMER = (1<<15),
717 IB_QP_SQ_PSN = (1<<16),
718 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
719 IB_QP_PATH_MIG_STATE = (1<<18),
720 IB_QP_CAP = (1<<19),
721 IB_QP_DEST_QPN = (1<<20)
722};
723
724enum ib_qp_state {
725 IB_QPS_RESET,
726 IB_QPS_INIT,
727 IB_QPS_RTR,
728 IB_QPS_RTS,
729 IB_QPS_SQD,
730 IB_QPS_SQE,
731 IB_QPS_ERR
732};
733
734enum ib_mig_state {
735 IB_MIG_MIGRATED,
736 IB_MIG_REARM,
737 IB_MIG_ARMED
738};
739
Shani Michaeli7083e422013-02-06 16:19:12 +0000740enum ib_mw_type {
741 IB_MW_TYPE_1 = 1,
742 IB_MW_TYPE_2 = 2
743};
744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745struct ib_qp_attr {
746 enum ib_qp_state qp_state;
747 enum ib_qp_state cur_qp_state;
748 enum ib_mtu path_mtu;
749 enum ib_mig_state path_mig_state;
750 u32 qkey;
751 u32 rq_psn;
752 u32 sq_psn;
753 u32 dest_qp_num;
754 int qp_access_flags;
755 struct ib_qp_cap cap;
756 struct ib_ah_attr ah_attr;
757 struct ib_ah_attr alt_ah_attr;
758 u16 pkey_index;
759 u16 alt_pkey_index;
760 u8 en_sqd_async_notify;
761 u8 sq_draining;
762 u8 max_rd_atomic;
763 u8 max_dest_rd_atomic;
764 u8 min_rnr_timer;
765 u8 port_num;
766 u8 timeout;
767 u8 retry_cnt;
768 u8 rnr_retry;
769 u8 alt_port_num;
770 u8 alt_timeout;
771};
772
773enum ib_wr_opcode {
774 IB_WR_RDMA_WRITE,
775 IB_WR_RDMA_WRITE_WITH_IMM,
776 IB_WR_SEND,
777 IB_WR_SEND_WITH_IMM,
778 IB_WR_RDMA_READ,
779 IB_WR_ATOMIC_CMP_AND_SWP,
Eli Cohenc93570f2008-04-16 21:09:27 -0700780 IB_WR_ATOMIC_FETCH_AND_ADD,
Roland Dreier0f39cf32008-04-16 21:09:32 -0700781 IB_WR_LSO,
782 IB_WR_SEND_WITH_INV,
Steve Wise00f7ec32008-07-14 23:48:45 -0700783 IB_WR_RDMA_READ_WITH_INV,
784 IB_WR_LOCAL_INV,
785 IB_WR_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300786 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
787 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
Shani Michaeli7083e422013-02-06 16:19:12 +0000788 IB_WR_BIND_MW,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300789 /* reserve values for low level drivers' internal use.
790 * These values will not be used at all in the ib core layer.
791 */
792 IB_WR_RESERVED1 = 0xf0,
793 IB_WR_RESERVED2,
794 IB_WR_RESERVED3,
795 IB_WR_RESERVED4,
796 IB_WR_RESERVED5,
797 IB_WR_RESERVED6,
798 IB_WR_RESERVED7,
799 IB_WR_RESERVED8,
800 IB_WR_RESERVED9,
801 IB_WR_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802};
803
804enum ib_send_flags {
805 IB_SEND_FENCE = 1,
806 IB_SEND_SIGNALED = (1<<1),
807 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +0200808 IB_SEND_INLINE = (1<<3),
Jack Morgenstein0134f162013-07-07 17:25:52 +0300809 IB_SEND_IP_CSUM = (1<<4),
810
811 /* reserve bits 26-31 for low level drivers' internal use */
812 IB_SEND_RESERVED_START = (1 << 26),
813 IB_SEND_RESERVED_END = (1 << 31),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814};
815
816struct ib_sge {
817 u64 addr;
818 u32 length;
819 u32 lkey;
820};
821
Steve Wise00f7ec32008-07-14 23:48:45 -0700822struct ib_fast_reg_page_list {
823 struct ib_device *device;
824 u64 *page_list;
825 unsigned int max_page_list_len;
826};
827
Shani Michaeli7083e422013-02-06 16:19:12 +0000828/**
829 * struct ib_mw_bind_info - Parameters for a memory window bind operation.
830 * @mr: A memory region to bind the memory window to.
831 * @addr: The address where the memory window should begin.
832 * @length: The length of the memory window, in bytes.
833 * @mw_access_flags: Access flags from enum ib_access_flags for the window.
834 *
835 * This struct contains the shared parameters for type 1 and type 2
836 * memory window bind operations.
837 */
838struct ib_mw_bind_info {
839 struct ib_mr *mr;
840 u64 addr;
841 u64 length;
842 int mw_access_flags;
843};
844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845struct ib_send_wr {
846 struct ib_send_wr *next;
847 u64 wr_id;
848 struct ib_sge *sg_list;
849 int num_sge;
850 enum ib_wr_opcode opcode;
851 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -0700852 union {
853 __be32 imm_data;
854 u32 invalidate_rkey;
855 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 union {
857 struct {
858 u64 remote_addr;
859 u32 rkey;
860 } rdma;
861 struct {
862 u64 remote_addr;
863 u64 compare_add;
864 u64 swap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300865 u64 compare_add_mask;
866 u64 swap_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 u32 rkey;
868 } atomic;
869 struct {
870 struct ib_ah *ah;
Eli Cohenc93570f2008-04-16 21:09:27 -0700871 void *header;
872 int hlen;
873 int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 u32 remote_qpn;
875 u32 remote_qkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 u16 pkey_index; /* valid for GSI only */
877 u8 port_num; /* valid for DR SMPs on switch only */
878 } ud;
Steve Wise00f7ec32008-07-14 23:48:45 -0700879 struct {
880 u64 iova_start;
881 struct ib_fast_reg_page_list *page_list;
882 unsigned int page_shift;
883 unsigned int page_list_len;
884 u32 length;
885 int access_flags;
886 u32 rkey;
887 } fast_reg;
Shani Michaeli7083e422013-02-06 16:19:12 +0000888 struct {
889 struct ib_mw *mw;
890 /* The new rkey for the memory window. */
891 u32 rkey;
892 struct ib_mw_bind_info bind_info;
893 } bind_mw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 } wr;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700895 u32 xrc_remote_srq_num; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896};
897
898struct ib_recv_wr {
899 struct ib_recv_wr *next;
900 u64 wr_id;
901 struct ib_sge *sg_list;
902 int num_sge;
903};
904
905enum ib_access_flags {
906 IB_ACCESS_LOCAL_WRITE = 1,
907 IB_ACCESS_REMOTE_WRITE = (1<<1),
908 IB_ACCESS_REMOTE_READ = (1<<2),
909 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
Shani Michaeli7083e422013-02-06 16:19:12 +0000910 IB_ACCESS_MW_BIND = (1<<4),
911 IB_ZERO_BASED = (1<<5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912};
913
914struct ib_phys_buf {
915 u64 addr;
916 u64 size;
917};
918
919struct ib_mr_attr {
920 struct ib_pd *pd;
921 u64 device_virt_addr;
922 u64 size;
923 int mr_access_flags;
924 u32 lkey;
925 u32 rkey;
926};
927
928enum ib_mr_rereg_flags {
929 IB_MR_REREG_TRANS = 1,
930 IB_MR_REREG_PD = (1<<1),
931 IB_MR_REREG_ACCESS = (1<<2)
932};
933
Shani Michaeli7083e422013-02-06 16:19:12 +0000934/**
935 * struct ib_mw_bind - Parameters for a type 1 memory window bind operation.
936 * @wr_id: Work request id.
937 * @send_flags: Flags from ib_send_flags enum.
938 * @bind_info: More parameters of the bind operation.
939 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940struct ib_mw_bind {
Shani Michaeli7083e422013-02-06 16:19:12 +0000941 u64 wr_id;
942 int send_flags;
943 struct ib_mw_bind_info bind_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944};
945
946struct ib_fmr_attr {
947 int max_pages;
948 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -0800949 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950};
951
Roland Dreiere2773c02005-07-07 17:57:10 -0700952struct ib_ucontext {
953 struct ib_device *device;
954 struct list_head pd_list;
955 struct list_head mr_list;
956 struct list_head mw_list;
957 struct list_head cq_list;
958 struct list_head qp_list;
959 struct list_head srq_list;
960 struct list_head ah_list;
Sean Hefty53d0bd12011-05-24 08:33:46 -0700961 struct list_head xrcd_list;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -0800962 int closing;
Roland Dreiere2773c02005-07-07 17:57:10 -0700963};
964
965struct ib_uobject {
966 u64 user_handle; /* handle given to us by userspace */
967 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -0700968 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -0700969 struct list_head list; /* link to context's list */
Roland Dreierb3d636b2008-04-16 21:01:06 -0700970 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -0700971 struct kref ref;
972 struct rw_semaphore mutex; /* protects .live */
973 int live;
Roland Dreiere2773c02005-07-07 17:57:10 -0700974};
975
Roland Dreiere2773c02005-07-07 17:57:10 -0700976struct ib_udata {
977 void __user *inbuf;
978 void __user *outbuf;
979 size_t inlen;
980 size_t outlen;
981};
982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983struct ib_pd {
Roland Dreiere2773c02005-07-07 17:57:10 -0700984 struct ib_device *device;
985 struct ib_uobject *uobject;
986 atomic_t usecnt; /* count all resources */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987};
988
Sean Hefty59991f92011-05-23 17:52:46 -0700989struct ib_xrcd {
990 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -0700991 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -0700992 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -0700993
994 struct mutex tgt_qp_mutex;
995 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -0700996};
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998struct ib_ah {
999 struct ib_device *device;
1000 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001001 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002};
1003
1004typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1005
1006struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -07001007 struct ib_device *device;
1008 struct ib_uobject *uobject;
1009 ib_comp_handler comp_handler;
1010 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -07001011 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -07001012 int cqe;
1013 atomic_t usecnt; /* count number of work queues */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014};
1015
1016struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -07001017 struct ib_device *device;
1018 struct ib_pd *pd;
1019 struct ib_uobject *uobject;
1020 void (*event_handler)(struct ib_event *, void *);
1021 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -07001022 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -07001024
1025 union {
1026 struct {
1027 struct ib_xrcd *xrcd;
1028 struct ib_cq *cq;
1029 u32 srq_num;
1030 } xrc;
1031 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032};
1033
1034struct ib_qp {
1035 struct ib_device *device;
1036 struct ib_pd *pd;
1037 struct ib_cq *send_cq;
1038 struct ib_cq *recv_cq;
1039 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001040 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -07001041 struct list_head xrcd_list;
Or Gerlitzc3bccbfb2012-04-29 17:04:22 +03001042 atomic_t usecnt; /* count times opened, mcast attaches */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001043 struct list_head open_list;
1044 struct ib_qp *real_qp;
Roland Dreiere2773c02005-07-07 17:57:10 -07001045 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 void (*event_handler)(struct ib_event *, void *);
1047 void *qp_context;
1048 u32 qp_num;
1049 enum ib_qp_type qp_type;
1050};
1051
1052struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -07001053 struct ib_device *device;
1054 struct ib_pd *pd;
1055 struct ib_uobject *uobject;
1056 u32 lkey;
1057 u32 rkey;
1058 atomic_t usecnt; /* count number of MWs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059};
1060
1061struct ib_mw {
1062 struct ib_device *device;
1063 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001064 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 u32 rkey;
Shani Michaeli7083e422013-02-06 16:19:12 +00001066 enum ib_mw_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067};
1068
1069struct ib_fmr {
1070 struct ib_device *device;
1071 struct ib_pd *pd;
1072 struct list_head list;
1073 u32 lkey;
1074 u32 rkey;
1075};
1076
1077struct ib_mad;
1078struct ib_grh;
1079
1080enum ib_process_mad_flags {
1081 IB_MAD_IGNORE_MKEY = 1,
1082 IB_MAD_IGNORE_BKEY = 2,
1083 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1084};
1085
1086enum ib_mad_result {
1087 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
1088 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
1089 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
1090 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
1091};
1092
1093#define IB_DEVICE_NAME_MAX 64
1094
1095struct ib_cache {
1096 rwlock_t lock;
1097 struct ib_event_handler event_handler;
1098 struct ib_pkey_cache **pkey_cache;
1099 struct ib_gid_cache **gid_cache;
Jack Morgenstein6fb9cdb2006-06-17 20:37:34 -07001100 u8 *lmc_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101};
1102
Ralph Campbell9b513092006-12-12 14:27:41 -08001103struct ib_dma_mapping_ops {
1104 int (*mapping_error)(struct ib_device *dev,
1105 u64 dma_addr);
1106 u64 (*map_single)(struct ib_device *dev,
1107 void *ptr, size_t size,
1108 enum dma_data_direction direction);
1109 void (*unmap_single)(struct ib_device *dev,
1110 u64 addr, size_t size,
1111 enum dma_data_direction direction);
1112 u64 (*map_page)(struct ib_device *dev,
1113 struct page *page, unsigned long offset,
1114 size_t size,
1115 enum dma_data_direction direction);
1116 void (*unmap_page)(struct ib_device *dev,
1117 u64 addr, size_t size,
1118 enum dma_data_direction direction);
1119 int (*map_sg)(struct ib_device *dev,
1120 struct scatterlist *sg, int nents,
1121 enum dma_data_direction direction);
1122 void (*unmap_sg)(struct ib_device *dev,
1123 struct scatterlist *sg, int nents,
1124 enum dma_data_direction direction);
1125 u64 (*dma_address)(struct ib_device *dev,
1126 struct scatterlist *sg);
1127 unsigned int (*dma_len)(struct ib_device *dev,
1128 struct scatterlist *sg);
1129 void (*sync_single_for_cpu)(struct ib_device *dev,
1130 u64 dma_handle,
1131 size_t size,
Dotan Barak4deccd62008-07-14 23:48:44 -07001132 enum dma_data_direction dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08001133 void (*sync_single_for_device)(struct ib_device *dev,
1134 u64 dma_handle,
1135 size_t size,
1136 enum dma_data_direction dir);
1137 void *(*alloc_coherent)(struct ib_device *dev,
1138 size_t size,
1139 u64 *dma_handle,
1140 gfp_t flag);
1141 void (*free_coherent)(struct ib_device *dev,
1142 size_t size, void *cpu_addr,
1143 u64 dma_handle);
1144};
1145
Tom Tucker07ebafb2006-08-03 16:02:42 -05001146struct iw_cm_verbs;
1147
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148struct ib_device {
1149 struct device *dma_device;
1150
1151 char name[IB_DEVICE_NAME_MAX];
1152
1153 struct list_head event_handler_list;
1154 spinlock_t event_handler_lock;
1155
Alexander Chiang17a55f72010-02-02 19:09:16 +00001156 spinlock_t client_data_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 struct list_head core_list;
1158 struct list_head client_data_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 struct ib_cache cache;
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001161 int *pkey_tbl_len;
1162 int *gid_tbl_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001164 int num_comp_vectors;
1165
Tom Tucker07ebafb2006-08-03 16:02:42 -05001166 struct iw_cm_verbs *iwcm;
1167
Steve Wise7f624d02008-07-14 23:48:48 -07001168 int (*get_protocol_stats)(struct ib_device *device,
1169 union rdma_protocol_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 int (*query_device)(struct ib_device *device,
1171 struct ib_device_attr *device_attr);
1172 int (*query_port)(struct ib_device *device,
1173 u8 port_num,
1174 struct ib_port_attr *port_attr);
Eli Cohena3f5ada2010-09-27 17:51:10 -07001175 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1176 u8 port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 int (*query_gid)(struct ib_device *device,
1178 u8 port_num, int index,
1179 union ib_gid *gid);
1180 int (*query_pkey)(struct ib_device *device,
1181 u8 port_num, u16 index, u16 *pkey);
1182 int (*modify_device)(struct ib_device *device,
1183 int device_modify_mask,
1184 struct ib_device_modify *device_modify);
1185 int (*modify_port)(struct ib_device *device,
1186 u8 port_num, int port_modify_mask,
1187 struct ib_port_modify *port_modify);
Roland Dreiere2773c02005-07-07 17:57:10 -07001188 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1189 struct ib_udata *udata);
1190 int (*dealloc_ucontext)(struct ib_ucontext *context);
1191 int (*mmap)(struct ib_ucontext *context,
1192 struct vm_area_struct *vma);
1193 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1194 struct ib_ucontext *context,
1195 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 int (*dealloc_pd)(struct ib_pd *pd);
1197 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1198 struct ib_ah_attr *ah_attr);
1199 int (*modify_ah)(struct ib_ah *ah,
1200 struct ib_ah_attr *ah_attr);
1201 int (*query_ah)(struct ib_ah *ah,
1202 struct ib_ah_attr *ah_attr);
1203 int (*destroy_ah)(struct ib_ah *ah);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001204 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1205 struct ib_srq_init_attr *srq_init_attr,
1206 struct ib_udata *udata);
1207 int (*modify_srq)(struct ib_srq *srq,
1208 struct ib_srq_attr *srq_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001209 enum ib_srq_attr_mask srq_attr_mask,
1210 struct ib_udata *udata);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001211 int (*query_srq)(struct ib_srq *srq,
1212 struct ib_srq_attr *srq_attr);
1213 int (*destroy_srq)(struct ib_srq *srq);
1214 int (*post_srq_recv)(struct ib_srq *srq,
1215 struct ib_recv_wr *recv_wr,
1216 struct ib_recv_wr **bad_recv_wr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 struct ib_qp * (*create_qp)(struct ib_pd *pd,
Roland Dreiere2773c02005-07-07 17:57:10 -07001218 struct ib_qp_init_attr *qp_init_attr,
1219 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 int (*modify_qp)(struct ib_qp *qp,
1221 struct ib_qp_attr *qp_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001222 int qp_attr_mask,
1223 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 int (*query_qp)(struct ib_qp *qp,
1225 struct ib_qp_attr *qp_attr,
1226 int qp_attr_mask,
1227 struct ib_qp_init_attr *qp_init_attr);
1228 int (*destroy_qp)(struct ib_qp *qp);
1229 int (*post_send)(struct ib_qp *qp,
1230 struct ib_send_wr *send_wr,
1231 struct ib_send_wr **bad_send_wr);
1232 int (*post_recv)(struct ib_qp *qp,
1233 struct ib_recv_wr *recv_wr,
1234 struct ib_recv_wr **bad_recv_wr);
Roland Dreiere2773c02005-07-07 17:57:10 -07001235 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001236 int comp_vector,
Roland Dreiere2773c02005-07-07 17:57:10 -07001237 struct ib_ucontext *context,
1238 struct ib_udata *udata);
Eli Cohen2dd57162008-04-16 21:09:33 -07001239 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1240 u16 cq_period);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 int (*destroy_cq)(struct ib_cq *cq);
Roland Dreier33b9b3e2006-01-30 14:29:21 -08001242 int (*resize_cq)(struct ib_cq *cq, int cqe,
1243 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1245 struct ib_wc *wc);
1246 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1247 int (*req_notify_cq)(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001248 enum ib_cq_notify_flags flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 int (*req_ncomp_notif)(struct ib_cq *cq,
1250 int wc_cnt);
1251 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1252 int mr_access_flags);
1253 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
1254 struct ib_phys_buf *phys_buf_array,
1255 int num_phys_buf,
1256 int mr_access_flags,
1257 u64 *iova_start);
Roland Dreiere2773c02005-07-07 17:57:10 -07001258 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001259 u64 start, u64 length,
1260 u64 virt_addr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001261 int mr_access_flags,
1262 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 int (*query_mr)(struct ib_mr *mr,
1264 struct ib_mr_attr *mr_attr);
1265 int (*dereg_mr)(struct ib_mr *mr);
Steve Wise00f7ec32008-07-14 23:48:45 -07001266 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
1267 int max_page_list_len);
1268 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1269 int page_list_len);
1270 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 int (*rereg_phys_mr)(struct ib_mr *mr,
1272 int mr_rereg_mask,
1273 struct ib_pd *pd,
1274 struct ib_phys_buf *phys_buf_array,
1275 int num_phys_buf,
1276 int mr_access_flags,
1277 u64 *iova_start);
Shani Michaeli7083e422013-02-06 16:19:12 +00001278 struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
1279 enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 int (*bind_mw)(struct ib_qp *qp,
1281 struct ib_mw *mw,
1282 struct ib_mw_bind *mw_bind);
1283 int (*dealloc_mw)(struct ib_mw *mw);
1284 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1285 int mr_access_flags,
1286 struct ib_fmr_attr *fmr_attr);
1287 int (*map_phys_fmr)(struct ib_fmr *fmr,
1288 u64 *page_list, int list_len,
1289 u64 iova);
1290 int (*unmap_fmr)(struct list_head *fmr_list);
1291 int (*dealloc_fmr)(struct ib_fmr *fmr);
1292 int (*attach_mcast)(struct ib_qp *qp,
1293 union ib_gid *gid,
1294 u16 lid);
1295 int (*detach_mcast)(struct ib_qp *qp,
1296 union ib_gid *gid,
1297 u16 lid);
1298 int (*process_mad)(struct ib_device *device,
1299 int process_mad_flags,
1300 u8 port_num,
1301 struct ib_wc *in_wc,
1302 struct ib_grh *in_grh,
1303 struct ib_mad *in_mad,
1304 struct ib_mad *out_mad);
Sean Hefty59991f92011-05-23 17:52:46 -07001305 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1306 struct ib_ucontext *ucontext,
1307 struct ib_udata *udata);
1308 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Ralph Campbell9b513092006-12-12 14:27:41 -08001310 struct ib_dma_mapping_ops *dma_ops;
1311
Roland Dreiere2773c02005-07-07 17:57:10 -07001312 struct module *owner;
Tony Jonesf4e91eb2008-02-22 00:13:36 +01001313 struct device dev;
Greg Kroah-Hartman35be0682007-12-17 15:54:39 -04001314 struct kobject *ports_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 struct list_head port_list;
1316
1317 enum {
1318 IB_DEV_UNINITIALIZED,
1319 IB_DEV_REGISTERED,
1320 IB_DEV_UNREGISTERED
1321 } reg_state;
1322
Roland Dreier274c0892005-09-29 14:17:48 -07001323 int uverbs_abi_ver;
Alexander Chiang17a55f72010-02-02 19:09:16 +00001324 u64 uverbs_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07001325
Roland Dreierc5bcbbb2006-02-02 09:47:14 -08001326 char node_desc[64];
Sean Heftycf311cd2006-01-10 07:39:34 -08001327 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07001328 u32 local_dma_lkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 u8 node_type;
1330 u8 phys_port_cnt;
1331};
1332
1333struct ib_client {
1334 char *name;
1335 void (*add) (struct ib_device *);
1336 void (*remove)(struct ib_device *);
1337
1338 struct list_head list;
1339};
1340
1341struct ib_device *ib_alloc_device(size_t size);
1342void ib_dealloc_device(struct ib_device *device);
1343
Ralph Campbell9a6edb62010-05-06 17:03:25 -07001344int ib_register_device(struct ib_device *device,
1345 int (*port_callback)(struct ib_device *,
1346 u8, struct kobject *));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347void ib_unregister_device(struct ib_device *device);
1348
1349int ib_register_client (struct ib_client *client);
1350void ib_unregister_client(struct ib_client *client);
1351
1352void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1353void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1354 void *data);
1355
Roland Dreiere2773c02005-07-07 17:57:10 -07001356static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1357{
1358 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1359}
1360
1361static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1362{
1363 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1364}
1365
Roland Dreier8a518662006-02-13 12:48:12 -08001366/**
1367 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1368 * contains all required attributes and no attributes not allowed for
1369 * the given QP state transition.
1370 * @cur_state: Current QP state
1371 * @next_state: Next QP state
1372 * @type: QP type
1373 * @mask: Mask of supplied QP attributes
1374 *
1375 * This function is a helper function that a low-level driver's
1376 * modify_qp method can use to validate the consumer's input. It
1377 * checks that cur_state and next_state are valid QP states, that a
1378 * transition from cur_state to next_state is allowed by the IB spec,
1379 * and that the attribute mask supplied is allowed for the transition.
1380 */
1381int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
1382 enum ib_qp_type type, enum ib_qp_attr_mask mask);
1383
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384int ib_register_event_handler (struct ib_event_handler *event_handler);
1385int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1386void ib_dispatch_event(struct ib_event *event);
1387
1388int ib_query_device(struct ib_device *device,
1389 struct ib_device_attr *device_attr);
1390
1391int ib_query_port(struct ib_device *device,
1392 u8 port_num, struct ib_port_attr *port_attr);
1393
Eli Cohena3f5ada2010-09-27 17:51:10 -07001394enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1395 u8 port_num);
1396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397int ib_query_gid(struct ib_device *device,
1398 u8 port_num, int index, union ib_gid *gid);
1399
1400int ib_query_pkey(struct ib_device *device,
1401 u8 port_num, u16 index, u16 *pkey);
1402
1403int ib_modify_device(struct ib_device *device,
1404 int device_modify_mask,
1405 struct ib_device_modify *device_modify);
1406
1407int ib_modify_port(struct ib_device *device,
1408 u8 port_num, int port_modify_mask,
1409 struct ib_port_modify *port_modify);
1410
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001411int ib_find_gid(struct ib_device *device, union ib_gid *gid,
1412 u8 *port_num, u16 *index);
1413
1414int ib_find_pkey(struct ib_device *device,
1415 u8 port_num, u16 pkey, u16 *index);
1416
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417/**
1418 * ib_alloc_pd - Allocates an unused protection domain.
1419 * @device: The device on which to allocate the protection domain.
1420 *
1421 * A protection domain object provides an association between QPs, shared
1422 * receive queues, address handles, memory regions, and memory windows.
1423 */
1424struct ib_pd *ib_alloc_pd(struct ib_device *device);
1425
1426/**
1427 * ib_dealloc_pd - Deallocates a protection domain.
1428 * @pd: The protection domain to deallocate.
1429 */
1430int ib_dealloc_pd(struct ib_pd *pd);
1431
1432/**
1433 * ib_create_ah - Creates an address handle for the given address vector.
1434 * @pd: The protection domain associated with the address handle.
1435 * @ah_attr: The attributes of the address vector.
1436 *
1437 * The address handle is used to reference a local or global destination
1438 * in all UD QP post sends.
1439 */
1440struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1441
1442/**
Sean Hefty4e00d692006-06-17 20:37:39 -07001443 * ib_init_ah_from_wc - Initializes address handle attributes from a
1444 * work completion.
1445 * @device: Device on which the received message arrived.
1446 * @port_num: Port on which the received message arrived.
1447 * @wc: Work completion associated with the received message.
1448 * @grh: References the received global route header. This parameter is
1449 * ignored unless the work completion indicates that the GRH is valid.
1450 * @ah_attr: Returned attributes that can be used when creating an address
1451 * handle for replying to the message.
1452 */
1453int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1454 struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1455
1456/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07001457 * ib_create_ah_from_wc - Creates an address handle associated with the
1458 * sender of the specified work completion.
1459 * @pd: The protection domain associated with the address handle.
1460 * @wc: Work completion information associated with a received message.
1461 * @grh: References the received global route header. This parameter is
1462 * ignored unless the work completion indicates that the GRH is valid.
1463 * @port_num: The outbound port number to associate with the address.
1464 *
1465 * The address handle is used to reference a local or global destination
1466 * in all UD QP post sends.
1467 */
1468struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1469 struct ib_grh *grh, u8 port_num);
1470
1471/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 * ib_modify_ah - Modifies the address vector associated with an address
1473 * handle.
1474 * @ah: The address handle to modify.
1475 * @ah_attr: The new address vector attributes to associate with the
1476 * address handle.
1477 */
1478int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1479
1480/**
1481 * ib_query_ah - Queries the address vector associated with an address
1482 * handle.
1483 * @ah: The address handle to query.
1484 * @ah_attr: The address vector attributes associated with the address
1485 * handle.
1486 */
1487int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1488
1489/**
1490 * ib_destroy_ah - Destroys an address handle.
1491 * @ah: The address handle to destroy.
1492 */
1493int ib_destroy_ah(struct ib_ah *ah);
1494
1495/**
Roland Dreierd41fcc62005-08-18 12:23:08 -07001496 * ib_create_srq - Creates a SRQ associated with the specified protection
1497 * domain.
1498 * @pd: The protection domain associated with the SRQ.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001499 * @srq_init_attr: A list of initial attributes required to create the
1500 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1501 * the actual capabilities of the created SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07001502 *
1503 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1504 * requested size of the SRQ, and set to the actual values allocated
1505 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
1506 * will always be at least as large as the requested values.
1507 */
1508struct ib_srq *ib_create_srq(struct ib_pd *pd,
1509 struct ib_srq_init_attr *srq_init_attr);
1510
1511/**
1512 * ib_modify_srq - Modifies the attributes for the specified SRQ.
1513 * @srq: The SRQ to modify.
1514 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1515 * the current values of selected SRQ attributes are returned.
1516 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1517 * are being modified.
1518 *
1519 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1520 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1521 * the number of receives queued drops below the limit.
1522 */
1523int ib_modify_srq(struct ib_srq *srq,
1524 struct ib_srq_attr *srq_attr,
1525 enum ib_srq_attr_mask srq_attr_mask);
1526
1527/**
1528 * ib_query_srq - Returns the attribute list and current values for the
1529 * specified SRQ.
1530 * @srq: The SRQ to query.
1531 * @srq_attr: The attributes of the specified SRQ.
1532 */
1533int ib_query_srq(struct ib_srq *srq,
1534 struct ib_srq_attr *srq_attr);
1535
1536/**
1537 * ib_destroy_srq - Destroys the specified SRQ.
1538 * @srq: The SRQ to destroy.
1539 */
1540int ib_destroy_srq(struct ib_srq *srq);
1541
1542/**
1543 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1544 * @srq: The SRQ to post the work request on.
1545 * @recv_wr: A list of work requests to post on the receive queue.
1546 * @bad_recv_wr: On an immediate failure, this parameter will reference
1547 * the work request that failed to be posted on the QP.
1548 */
1549static inline int ib_post_srq_recv(struct ib_srq *srq,
1550 struct ib_recv_wr *recv_wr,
1551 struct ib_recv_wr **bad_recv_wr)
1552{
1553 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1554}
1555
1556/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 * ib_create_qp - Creates a QP associated with the specified protection
1558 * domain.
1559 * @pd: The protection domain associated with the QP.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001560 * @qp_init_attr: A list of initial attributes required to create the
1561 * QP. If QP creation succeeds, then the attributes are updated to
1562 * the actual capabilities of the created QP.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 */
1564struct ib_qp *ib_create_qp(struct ib_pd *pd,
1565 struct ib_qp_init_attr *qp_init_attr);
1566
1567/**
1568 * ib_modify_qp - Modifies the attributes for the specified QP and then
1569 * transitions the QP to the given state.
1570 * @qp: The QP to modify.
1571 * @qp_attr: On input, specifies the QP attributes to modify. On output,
1572 * the current values of selected QP attributes are returned.
1573 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1574 * are being modified.
1575 */
1576int ib_modify_qp(struct ib_qp *qp,
1577 struct ib_qp_attr *qp_attr,
1578 int qp_attr_mask);
1579
1580/**
1581 * ib_query_qp - Returns the attribute list and current values for the
1582 * specified QP.
1583 * @qp: The QP to query.
1584 * @qp_attr: The attributes of the specified QP.
1585 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1586 * @qp_init_attr: Additional attributes of the selected QP.
1587 *
1588 * The qp_attr_mask may be used to limit the query to gathering only the
1589 * selected attributes.
1590 */
1591int ib_query_qp(struct ib_qp *qp,
1592 struct ib_qp_attr *qp_attr,
1593 int qp_attr_mask,
1594 struct ib_qp_init_attr *qp_init_attr);
1595
1596/**
1597 * ib_destroy_qp - Destroys the specified QP.
1598 * @qp: The QP to destroy.
1599 */
1600int ib_destroy_qp(struct ib_qp *qp);
1601
1602/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001603 * ib_open_qp - Obtain a reference to an existing sharable QP.
1604 * @xrcd - XRC domain
1605 * @qp_open_attr: Attributes identifying the QP to open.
1606 *
1607 * Returns a reference to a sharable QP.
1608 */
1609struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
1610 struct ib_qp_open_attr *qp_open_attr);
1611
1612/**
1613 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001614 * @qp: The QP handle to release
1615 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001616 * The opened QP handle is released by the caller. The underlying
1617 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001618 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001619int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07001620
1621/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 * ib_post_send - Posts a list of work requests to the send queue of
1623 * the specified QP.
1624 * @qp: The QP to post the work request on.
1625 * @send_wr: A list of work requests to post on the send queue.
1626 * @bad_send_wr: On an immediate failure, this parameter will reference
1627 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08001628 *
1629 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
1630 * error is returned, the QP state shall not be affected,
1631 * ib_post_send() will return an immediate error after queueing any
1632 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 */
1634static inline int ib_post_send(struct ib_qp *qp,
1635 struct ib_send_wr *send_wr,
1636 struct ib_send_wr **bad_send_wr)
1637{
1638 return qp->device->post_send(qp, send_wr, bad_send_wr);
1639}
1640
1641/**
1642 * ib_post_recv - Posts a list of work requests to the receive queue of
1643 * the specified QP.
1644 * @qp: The QP to post the work request on.
1645 * @recv_wr: A list of work requests to post on the receive queue.
1646 * @bad_recv_wr: On an immediate failure, this parameter will reference
1647 * the work request that failed to be posted on the QP.
1648 */
1649static inline int ib_post_recv(struct ib_qp *qp,
1650 struct ib_recv_wr *recv_wr,
1651 struct ib_recv_wr **bad_recv_wr)
1652{
1653 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1654}
1655
1656/**
1657 * ib_create_cq - Creates a CQ on the specified device.
1658 * @device: The device on which to create the CQ.
1659 * @comp_handler: A user-specified callback that is invoked when a
1660 * completion event occurs on the CQ.
1661 * @event_handler: A user-specified callback that is invoked when an
1662 * asynchronous event not associated with a completion occurs on the CQ.
1663 * @cq_context: Context associated with the CQ returned to the user via
1664 * the associated completion and event handlers.
1665 * @cqe: The minimum size of the CQ.
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001666 * @comp_vector - Completion vector used to signal completion events.
1667 * Must be >= 0 and < context->num_comp_vectors.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 *
1669 * Users can examine the cq structure to determine the actual CQ size.
1670 */
1671struct ib_cq *ib_create_cq(struct ib_device *device,
1672 ib_comp_handler comp_handler,
1673 void (*event_handler)(struct ib_event *, void *),
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001674 void *cq_context, int cqe, int comp_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
1676/**
1677 * ib_resize_cq - Modifies the capacity of the CQ.
1678 * @cq: The CQ to resize.
1679 * @cqe: The minimum size of the CQ.
1680 *
1681 * Users can examine the cq structure to determine the actual CQ size.
1682 */
1683int ib_resize_cq(struct ib_cq *cq, int cqe);
1684
1685/**
Eli Cohen2dd57162008-04-16 21:09:33 -07001686 * ib_modify_cq - Modifies moderation params of the CQ
1687 * @cq: The CQ to modify.
1688 * @cq_count: number of CQEs that will trigger an event
1689 * @cq_period: max period of time in usec before triggering an event
1690 *
1691 */
1692int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
1693
1694/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 * ib_destroy_cq - Destroys the specified CQ.
1696 * @cq: The CQ to destroy.
1697 */
1698int ib_destroy_cq(struct ib_cq *cq);
1699
1700/**
1701 * ib_poll_cq - poll a CQ for completion(s)
1702 * @cq:the CQ being polled
1703 * @num_entries:maximum number of completions to return
1704 * @wc:array of at least @num_entries &struct ib_wc where completions
1705 * will be returned
1706 *
1707 * Poll a CQ for (possibly multiple) completions. If the return value
1708 * is < 0, an error occurred. If the return value is >= 0, it is the
1709 * number of completions returned. If the return value is
1710 * non-negative and < num_entries, then the CQ was emptied.
1711 */
1712static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1713 struct ib_wc *wc)
1714{
1715 return cq->device->poll_cq(cq, num_entries, wc);
1716}
1717
1718/**
1719 * ib_peek_cq - Returns the number of unreaped completions currently
1720 * on the specified CQ.
1721 * @cq: The CQ to peek.
1722 * @wc_cnt: A minimum number of unreaped completions to check for.
1723 *
1724 * If the number of unreaped completions is greater than or equal to wc_cnt,
1725 * this function returns wc_cnt, otherwise, it returns the actual number of
1726 * unreaped completions.
1727 */
1728int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1729
1730/**
1731 * ib_req_notify_cq - Request completion notification on a CQ.
1732 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07001733 * @flags:
1734 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
1735 * to request an event on the next solicited event or next work
1736 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
1737 * may also be |ed in to request a hint about missed events, as
1738 * described below.
1739 *
1740 * Return Value:
1741 * < 0 means an error occurred while requesting notification
1742 * == 0 means notification was requested successfully, and if
1743 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
1744 * were missed and it is safe to wait for another event. In
1745 * this case is it guaranteed that any work completions added
1746 * to the CQ since the last CQ poll will trigger a completion
1747 * notification event.
1748 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
1749 * in. It means that the consumer must poll the CQ again to
1750 * make sure it is empty to avoid missing an event because of a
1751 * race between requesting notification and an entry being
1752 * added to the CQ. This return value means it is possible
1753 * (but not guaranteed) that a work completion has been added
1754 * to the CQ since the last poll without triggering a
1755 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 */
1757static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001758 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759{
Roland Dreiered23a722007-05-06 21:02:48 -07001760 return cq->device->req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
1763/**
1764 * ib_req_ncomp_notif - Request completion notification when there are
1765 * at least the specified number of unreaped completions on the CQ.
1766 * @cq: The CQ to generate an event for.
1767 * @wc_cnt: The number of unreaped completions that should be on the
1768 * CQ before an event is generated.
1769 */
1770static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1771{
1772 return cq->device->req_ncomp_notif ?
1773 cq->device->req_ncomp_notif(cq, wc_cnt) :
1774 -ENOSYS;
1775}
1776
1777/**
1778 * ib_get_dma_mr - Returns a memory region for system memory that is
1779 * usable for DMA.
1780 * @pd: The protection domain associated with the memory region.
1781 * @mr_access_flags: Specifies the memory access rights.
Ralph Campbell9b513092006-12-12 14:27:41 -08001782 *
1783 * Note that the ib_dma_*() functions defined below must be used
1784 * to create/destroy addresses used with the Lkey or Rkey returned
1785 * by ib_get_dma_mr().
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 */
1787struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1788
1789/**
Ralph Campbell9b513092006-12-12 14:27:41 -08001790 * ib_dma_mapping_error - check a DMA addr for error
1791 * @dev: The device for which the dma_addr was created
1792 * @dma_addr: The DMA address to check
1793 */
1794static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1795{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001796 if (dev->dma_ops)
1797 return dev->dma_ops->mapping_error(dev, dma_addr);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001798 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08001799}
1800
1801/**
1802 * ib_dma_map_single - Map a kernel virtual address to DMA address
1803 * @dev: The device for which the dma_addr is to be created
1804 * @cpu_addr: The kernel virtual address
1805 * @size: The size of the region in bytes
1806 * @direction: The direction of the DMA
1807 */
1808static inline u64 ib_dma_map_single(struct ib_device *dev,
1809 void *cpu_addr, size_t size,
1810 enum dma_data_direction direction)
1811{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001812 if (dev->dma_ops)
1813 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
1814 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001815}
1816
1817/**
1818 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
1819 * @dev: The device for which the DMA address was created
1820 * @addr: The DMA address
1821 * @size: The size of the region in bytes
1822 * @direction: The direction of the DMA
1823 */
1824static inline void ib_dma_unmap_single(struct ib_device *dev,
1825 u64 addr, size_t size,
1826 enum dma_data_direction direction)
1827{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001828 if (dev->dma_ops)
1829 dev->dma_ops->unmap_single(dev, addr, size, direction);
1830 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001831 dma_unmap_single(dev->dma_device, addr, size, direction);
1832}
1833
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07001834static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
1835 void *cpu_addr, size_t size,
1836 enum dma_data_direction direction,
1837 struct dma_attrs *attrs)
1838{
1839 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
1840 direction, attrs);
1841}
1842
1843static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
1844 u64 addr, size_t size,
1845 enum dma_data_direction direction,
1846 struct dma_attrs *attrs)
1847{
1848 return dma_unmap_single_attrs(dev->dma_device, addr, size,
1849 direction, attrs);
1850}
1851
Ralph Campbell9b513092006-12-12 14:27:41 -08001852/**
1853 * ib_dma_map_page - Map a physical page to DMA address
1854 * @dev: The device for which the dma_addr is to be created
1855 * @page: The page to be mapped
1856 * @offset: The offset within the page
1857 * @size: The size of the region in bytes
1858 * @direction: The direction of the DMA
1859 */
1860static inline u64 ib_dma_map_page(struct ib_device *dev,
1861 struct page *page,
1862 unsigned long offset,
1863 size_t size,
1864 enum dma_data_direction direction)
1865{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001866 if (dev->dma_ops)
1867 return dev->dma_ops->map_page(dev, page, offset, size, direction);
1868 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001869}
1870
1871/**
1872 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
1873 * @dev: The device for which the DMA address was created
1874 * @addr: The DMA address
1875 * @size: The size of the region in bytes
1876 * @direction: The direction of the DMA
1877 */
1878static inline void ib_dma_unmap_page(struct ib_device *dev,
1879 u64 addr, size_t size,
1880 enum dma_data_direction direction)
1881{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001882 if (dev->dma_ops)
1883 dev->dma_ops->unmap_page(dev, addr, size, direction);
1884 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001885 dma_unmap_page(dev->dma_device, addr, size, direction);
1886}
1887
1888/**
1889 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
1890 * @dev: The device for which the DMA addresses are to be created
1891 * @sg: The array of scatter/gather entries
1892 * @nents: The number of scatter/gather entries
1893 * @direction: The direction of the DMA
1894 */
1895static inline int ib_dma_map_sg(struct ib_device *dev,
1896 struct scatterlist *sg, int nents,
1897 enum dma_data_direction direction)
1898{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001899 if (dev->dma_ops)
1900 return dev->dma_ops->map_sg(dev, sg, nents, direction);
1901 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001902}
1903
1904/**
1905 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
1906 * @dev: The device for which the DMA addresses were created
1907 * @sg: The array of scatter/gather entries
1908 * @nents: The number of scatter/gather entries
1909 * @direction: The direction of the DMA
1910 */
1911static inline void ib_dma_unmap_sg(struct ib_device *dev,
1912 struct scatterlist *sg, int nents,
1913 enum dma_data_direction direction)
1914{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001915 if (dev->dma_ops)
1916 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
1917 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001918 dma_unmap_sg(dev->dma_device, sg, nents, direction);
1919}
1920
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07001921static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
1922 struct scatterlist *sg, int nents,
1923 enum dma_data_direction direction,
1924 struct dma_attrs *attrs)
1925{
1926 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
1927}
1928
1929static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
1930 struct scatterlist *sg, int nents,
1931 enum dma_data_direction direction,
1932 struct dma_attrs *attrs)
1933{
1934 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
1935}
Ralph Campbell9b513092006-12-12 14:27:41 -08001936/**
1937 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
1938 * @dev: The device for which the DMA addresses were created
1939 * @sg: The scatter/gather entry
1940 */
1941static inline u64 ib_sg_dma_address(struct ib_device *dev,
1942 struct scatterlist *sg)
1943{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001944 if (dev->dma_ops)
1945 return dev->dma_ops->dma_address(dev, sg);
1946 return sg_dma_address(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08001947}
1948
1949/**
1950 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
1951 * @dev: The device for which the DMA addresses were created
1952 * @sg: The scatter/gather entry
1953 */
1954static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
1955 struct scatterlist *sg)
1956{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001957 if (dev->dma_ops)
1958 return dev->dma_ops->dma_len(dev, sg);
1959 return sg_dma_len(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08001960}
1961
1962/**
1963 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
1964 * @dev: The device for which the DMA address was created
1965 * @addr: The DMA address
1966 * @size: The size of the region in bytes
1967 * @dir: The direction of the DMA
1968 */
1969static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
1970 u64 addr,
1971 size_t size,
1972 enum dma_data_direction dir)
1973{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001974 if (dev->dma_ops)
1975 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
1976 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001977 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
1978}
1979
1980/**
1981 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
1982 * @dev: The device for which the DMA address was created
1983 * @addr: The DMA address
1984 * @size: The size of the region in bytes
1985 * @dir: The direction of the DMA
1986 */
1987static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
1988 u64 addr,
1989 size_t size,
1990 enum dma_data_direction dir)
1991{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001992 if (dev->dma_ops)
1993 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
1994 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001995 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
1996}
1997
1998/**
1999 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
2000 * @dev: The device for which the DMA address is requested
2001 * @size: The size of the region to allocate in bytes
2002 * @dma_handle: A pointer for returning the DMA address of the region
2003 * @flag: memory allocator flags
2004 */
2005static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
2006 size_t size,
2007 u64 *dma_handle,
2008 gfp_t flag)
2009{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002010 if (dev->dma_ops)
2011 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Roland Dreierc59a3da2006-12-15 13:57:26 -08002012 else {
2013 dma_addr_t handle;
2014 void *ret;
2015
2016 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
2017 *dma_handle = handle;
2018 return ret;
2019 }
Ralph Campbell9b513092006-12-12 14:27:41 -08002020}
2021
2022/**
2023 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
2024 * @dev: The device for which the DMA addresses were allocated
2025 * @size: The size of the region
2026 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
2027 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
2028 */
2029static inline void ib_dma_free_coherent(struct ib_device *dev,
2030 size_t size, void *cpu_addr,
2031 u64 dma_handle)
2032{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002033 if (dev->dma_ops)
2034 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
2035 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002036 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
2037}
2038
2039/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
2041 * by an HCA.
2042 * @pd: The protection domain associated assigned to the registered region.
2043 * @phys_buf_array: Specifies a list of physical buffers to use in the
2044 * memory region.
2045 * @num_phys_buf: Specifies the size of the phys_buf_array.
2046 * @mr_access_flags: Specifies the memory access rights.
2047 * @iova_start: The offset of the region's starting I/O virtual address.
2048 */
2049struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
2050 struct ib_phys_buf *phys_buf_array,
2051 int num_phys_buf,
2052 int mr_access_flags,
2053 u64 *iova_start);
2054
2055/**
2056 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
2057 * Conceptually, this call performs the functions deregister memory region
2058 * followed by register physical memory region. Where possible,
2059 * resources are reused instead of deallocated and reallocated.
2060 * @mr: The memory region to modify.
2061 * @mr_rereg_mask: A bit-mask used to indicate which of the following
2062 * properties of the memory region are being modified.
2063 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
2064 * the new protection domain to associated with the memory region,
2065 * otherwise, this parameter is ignored.
2066 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2067 * field specifies a list of physical buffers to use in the new
2068 * translation, otherwise, this parameter is ignored.
2069 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2070 * field specifies the size of the phys_buf_array, otherwise, this
2071 * parameter is ignored.
2072 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
2073 * field specifies the new memory access rights, otherwise, this
2074 * parameter is ignored.
2075 * @iova_start: The offset of the region's starting I/O virtual address.
2076 */
2077int ib_rereg_phys_mr(struct ib_mr *mr,
2078 int mr_rereg_mask,
2079 struct ib_pd *pd,
2080 struct ib_phys_buf *phys_buf_array,
2081 int num_phys_buf,
2082 int mr_access_flags,
2083 u64 *iova_start);
2084
2085/**
2086 * ib_query_mr - Retrieves information about a specific memory region.
2087 * @mr: The memory region to retrieve information about.
2088 * @mr_attr: The attributes of the specified memory region.
2089 */
2090int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
2091
2092/**
2093 * ib_dereg_mr - Deregisters a memory region and removes it from the
2094 * HCA translation table.
2095 * @mr: The memory region to deregister.
Shani Michaeli7083e422013-02-06 16:19:12 +00002096 *
2097 * This function can fail, if the memory region has memory windows bound to it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 */
2099int ib_dereg_mr(struct ib_mr *mr);
2100
2101/**
Steve Wise00f7ec32008-07-14 23:48:45 -07002102 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
2103 * IB_WR_FAST_REG_MR send work request.
2104 * @pd: The protection domain associated with the region.
2105 * @max_page_list_len: requested max physical buffer list length to be
2106 * used with fast register work requests for this MR.
2107 */
2108struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2109
2110/**
2111 * ib_alloc_fast_reg_page_list - Allocates a page list array
2112 * @device - ib device pointer.
2113 * @page_list_len - size of the page list array to be allocated.
2114 *
2115 * This allocates and returns a struct ib_fast_reg_page_list * and a
2116 * page_list array that is at least page_list_len in size. The actual
2117 * size is returned in max_page_list_len. The caller is responsible
2118 * for initializing the contents of the page_list array before posting
2119 * a send work request with the IB_WC_FAST_REG_MR opcode.
2120 *
2121 * The page_list array entries must be translated using one of the
2122 * ib_dma_*() functions just like the addresses passed to
2123 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
2124 * ib_fast_reg_page_list must not be modified by the caller until the
2125 * IB_WC_FAST_REG_MR work request completes.
2126 */
2127struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2128 struct ib_device *device, int page_list_len);
2129
2130/**
2131 * ib_free_fast_reg_page_list - Deallocates a previously allocated
2132 * page list array.
2133 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2134 */
2135void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2136
2137/**
2138 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2139 * R_Key and L_Key.
2140 * @mr - struct ib_mr pointer to be updated.
2141 * @newkey - new key to be used.
2142 */
2143static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2144{
2145 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2146 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2147}
2148
2149/**
Shani Michaeli7083e422013-02-06 16:19:12 +00002150 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
2151 * for calculating a new rkey for type 2 memory windows.
2152 * @rkey - the rkey to increment.
2153 */
2154static inline u32 ib_inc_rkey(u32 rkey)
2155{
2156 const u32 mask = 0x000000ff;
2157 return ((rkey + 1) & mask) | (rkey & ~mask);
2158}
2159
2160/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 * ib_alloc_mw - Allocates a memory window.
2162 * @pd: The protection domain associated with the memory window.
Shani Michaeli7083e422013-02-06 16:19:12 +00002163 * @type: The type of the memory window (1 or 2).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 */
Shani Michaeli7083e422013-02-06 16:19:12 +00002165struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167/**
2168 * ib_bind_mw - Posts a work request to the send queue of the specified
2169 * QP, which binds the memory window to the given address range and
2170 * remote access attributes.
2171 * @qp: QP to post the bind work request on.
2172 * @mw: The memory window to bind.
2173 * @mw_bind: Specifies information about the memory window, including
2174 * its address range, remote access rights, and associated memory region.
Shani Michaeli7083e422013-02-06 16:19:12 +00002175 *
2176 * If there is no immediate error, the function will update the rkey member
2177 * of the mw parameter to its new value. The bind operation can still fail
2178 * asynchronously.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 */
2180static inline int ib_bind_mw(struct ib_qp *qp,
2181 struct ib_mw *mw,
2182 struct ib_mw_bind *mw_bind)
2183{
2184 /* XXX reference counting in corresponding MR? */
2185 return mw->device->bind_mw ?
2186 mw->device->bind_mw(qp, mw, mw_bind) :
2187 -ENOSYS;
2188}
2189
2190/**
2191 * ib_dealloc_mw - Deallocates a memory window.
2192 * @mw: The memory window to deallocate.
2193 */
2194int ib_dealloc_mw(struct ib_mw *mw);
2195
2196/**
2197 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2198 * @pd: The protection domain associated with the unmapped region.
2199 * @mr_access_flags: Specifies the memory access rights.
2200 * @fmr_attr: Attributes of the unmapped region.
2201 *
2202 * A fast memory region must be mapped before it can be used as part of
2203 * a work request.
2204 */
2205struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2206 int mr_access_flags,
2207 struct ib_fmr_attr *fmr_attr);
2208
2209/**
2210 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2211 * @fmr: The fast memory region to associate with the pages.
2212 * @page_list: An array of physical pages to map to the fast memory region.
2213 * @list_len: The number of pages in page_list.
2214 * @iova: The I/O virtual address to use with the mapped region.
2215 */
2216static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2217 u64 *page_list, int list_len,
2218 u64 iova)
2219{
2220 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2221}
2222
2223/**
2224 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2225 * @fmr_list: A linked list of fast memory regions to unmap.
2226 */
2227int ib_unmap_fmr(struct list_head *fmr_list);
2228
2229/**
2230 * ib_dealloc_fmr - Deallocates a fast memory region.
2231 * @fmr: The fast memory region to deallocate.
2232 */
2233int ib_dealloc_fmr(struct ib_fmr *fmr);
2234
2235/**
2236 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2237 * @qp: QP to attach to the multicast group. The QP must be type
2238 * IB_QPT_UD.
2239 * @gid: Multicast group GID.
2240 * @lid: Multicast group LID in host byte order.
2241 *
2242 * In order to send and receive multicast packets, subnet
2243 * administration must have created the multicast group and configured
2244 * the fabric appropriately. The port associated with the specified
2245 * QP must also be a member of the multicast group.
2246 */
2247int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2248
2249/**
2250 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2251 * @qp: QP to detach from the multicast group.
2252 * @gid: Multicast group GID.
2253 * @lid: Multicast group LID in host byte order.
2254 */
2255int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2256
Sean Hefty59991f92011-05-23 17:52:46 -07002257/**
2258 * ib_alloc_xrcd - Allocates an XRC domain.
2259 * @device: The device on which to allocate the XRC domain.
2260 */
2261struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2262
2263/**
2264 * ib_dealloc_xrcd - Deallocates an XRC domain.
2265 * @xrcd: The XRC domain to deallocate.
2266 */
2267int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2268
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269#endif /* IB_VERBS_H */