blob: 8705539bce75c11092c66c1a8e700a5d69204c30 [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),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118};
119
120enum ib_atomic_cap {
121 IB_ATOMIC_NONE,
122 IB_ATOMIC_HCA,
123 IB_ATOMIC_GLOB
124};
125
126struct ib_device_attr {
127 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700128 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 u64 max_mr_size;
130 u64 page_size_cap;
131 u32 vendor_id;
132 u32 vendor_part_id;
133 u32 hw_ver;
134 int max_qp;
135 int max_qp_wr;
136 int device_cap_flags;
137 int max_sge;
138 int max_sge_rd;
139 int max_cq;
140 int max_cqe;
141 int max_mr;
142 int max_pd;
143 int max_qp_rd_atom;
144 int max_ee_rd_atom;
145 int max_res_rd_atom;
146 int max_qp_init_rd_atom;
147 int max_ee_init_rd_atom;
148 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300149 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 int max_ee;
151 int max_rdd;
152 int max_mw;
153 int max_raw_ipv6_qp;
154 int max_raw_ethy_qp;
155 int max_mcast_grp;
156 int max_mcast_qp_attach;
157 int max_total_mcast_qp_attach;
158 int max_ah;
159 int max_fmr;
160 int max_map_per_fmr;
161 int max_srq;
162 int max_srq_wr;
163 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700164 unsigned int max_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 u16 max_pkeys;
166 u8 local_ca_ack_delay;
167};
168
169enum ib_mtu {
170 IB_MTU_256 = 1,
171 IB_MTU_512 = 2,
172 IB_MTU_1024 = 3,
173 IB_MTU_2048 = 4,
174 IB_MTU_4096 = 5
175};
176
177static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
178{
179 switch (mtu) {
180 case IB_MTU_256: return 256;
181 case IB_MTU_512: return 512;
182 case IB_MTU_1024: return 1024;
183 case IB_MTU_2048: return 2048;
184 case IB_MTU_4096: return 4096;
185 default: return -1;
186 }
187}
188
189enum ib_port_state {
190 IB_PORT_NOP = 0,
191 IB_PORT_DOWN = 1,
192 IB_PORT_INIT = 2,
193 IB_PORT_ARMED = 3,
194 IB_PORT_ACTIVE = 4,
195 IB_PORT_ACTIVE_DEFER = 5
196};
197
198enum ib_port_cap_flags {
199 IB_PORT_SM = 1 << 1,
200 IB_PORT_NOTICE_SUP = 1 << 2,
201 IB_PORT_TRAP_SUP = 1 << 3,
202 IB_PORT_OPT_IPD_SUP = 1 << 4,
203 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
204 IB_PORT_SL_MAP_SUP = 1 << 6,
205 IB_PORT_MKEY_NVRAM = 1 << 7,
206 IB_PORT_PKEY_NVRAM = 1 << 8,
207 IB_PORT_LED_INFO_SUP = 1 << 9,
208 IB_PORT_SM_DISABLED = 1 << 10,
209 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
210 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
211 IB_PORT_CM_SUP = 1 << 16,
212 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
213 IB_PORT_REINIT_SUP = 1 << 18,
214 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
215 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
216 IB_PORT_DR_NOTICE_SUP = 1 << 21,
217 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
218 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
219 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
220 IB_PORT_CLIENT_REG_SUP = 1 << 25
221};
222
223enum ib_port_width {
224 IB_WIDTH_1X = 1,
225 IB_WIDTH_4X = 2,
226 IB_WIDTH_8X = 4,
227 IB_WIDTH_12X = 8
228};
229
230static inline int ib_width_enum_to_int(enum ib_port_width width)
231{
232 switch (width) {
233 case IB_WIDTH_1X: return 1;
234 case IB_WIDTH_4X: return 4;
235 case IB_WIDTH_8X: return 8;
236 case IB_WIDTH_12X: return 12;
237 default: return -1;
238 }
239}
240
Steve Wise7f624d02008-07-14 23:48:48 -0700241struct ib_protocol_stats {
242 /* TBD... */
243};
244
245struct iw_protocol_stats {
246 u64 ipInReceives;
247 u64 ipInHdrErrors;
248 u64 ipInTooBigErrors;
249 u64 ipInNoRoutes;
250 u64 ipInAddrErrors;
251 u64 ipInUnknownProtos;
252 u64 ipInTruncatedPkts;
253 u64 ipInDiscards;
254 u64 ipInDelivers;
255 u64 ipOutForwDatagrams;
256 u64 ipOutRequests;
257 u64 ipOutDiscards;
258 u64 ipOutNoRoutes;
259 u64 ipReasmTimeout;
260 u64 ipReasmReqds;
261 u64 ipReasmOKs;
262 u64 ipReasmFails;
263 u64 ipFragOKs;
264 u64 ipFragFails;
265 u64 ipFragCreates;
266 u64 ipInMcastPkts;
267 u64 ipOutMcastPkts;
268 u64 ipInBcastPkts;
269 u64 ipOutBcastPkts;
270
271 u64 tcpRtoAlgorithm;
272 u64 tcpRtoMin;
273 u64 tcpRtoMax;
274 u64 tcpMaxConn;
275 u64 tcpActiveOpens;
276 u64 tcpPassiveOpens;
277 u64 tcpAttemptFails;
278 u64 tcpEstabResets;
279 u64 tcpCurrEstab;
280 u64 tcpInSegs;
281 u64 tcpOutSegs;
282 u64 tcpRetransSegs;
283 u64 tcpInErrs;
284 u64 tcpOutRsts;
285};
286
287union rdma_protocol_stats {
288 struct ib_protocol_stats ib;
289 struct iw_protocol_stats iw;
290};
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292struct ib_port_attr {
293 enum ib_port_state state;
294 enum ib_mtu max_mtu;
295 enum ib_mtu active_mtu;
296 int gid_tbl_len;
297 u32 port_cap_flags;
298 u32 max_msg_sz;
299 u32 bad_pkey_cntr;
300 u32 qkey_viol_cntr;
301 u16 pkey_tbl_len;
302 u16 lid;
303 u16 sm_lid;
304 u8 lmc;
305 u8 max_vl_num;
306 u8 sm_sl;
307 u8 subnet_timeout;
308 u8 init_type_reply;
309 u8 active_width;
310 u8 active_speed;
311 u8 phys_state;
312};
313
314enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800315 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
316 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317};
318
319struct ib_device_modify {
320 u64 sys_image_guid;
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800321 char node_desc[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322};
323
324enum ib_port_modify_flags {
325 IB_PORT_SHUTDOWN = 1,
326 IB_PORT_INIT_TYPE = (1<<2),
327 IB_PORT_RESET_QKEY_CNTR = (1<<3)
328};
329
330struct ib_port_modify {
331 u32 set_port_cap_mask;
332 u32 clr_port_cap_mask;
333 u8 init_type;
334};
335
336enum ib_event_type {
337 IB_EVENT_CQ_ERR,
338 IB_EVENT_QP_FATAL,
339 IB_EVENT_QP_REQ_ERR,
340 IB_EVENT_QP_ACCESS_ERR,
341 IB_EVENT_COMM_EST,
342 IB_EVENT_SQ_DRAINED,
343 IB_EVENT_PATH_MIG,
344 IB_EVENT_PATH_MIG_ERR,
345 IB_EVENT_DEVICE_FATAL,
346 IB_EVENT_PORT_ACTIVE,
347 IB_EVENT_PORT_ERR,
348 IB_EVENT_LID_CHANGE,
349 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700350 IB_EVENT_SM_CHANGE,
351 IB_EVENT_SRQ_ERR,
352 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700353 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000354 IB_EVENT_CLIENT_REREGISTER,
355 IB_EVENT_GID_CHANGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356};
357
358struct ib_event {
359 struct ib_device *device;
360 union {
361 struct ib_cq *cq;
362 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700363 struct ib_srq *srq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 u8 port_num;
365 } element;
366 enum ib_event_type event;
367};
368
369struct ib_event_handler {
370 struct ib_device *device;
371 void (*handler)(struct ib_event_handler *, struct ib_event *);
372 struct list_head list;
373};
374
375#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
376 do { \
377 (_ptr)->device = _device; \
378 (_ptr)->handler = _handler; \
379 INIT_LIST_HEAD(&(_ptr)->list); \
380 } while (0)
381
382struct ib_global_route {
383 union ib_gid dgid;
384 u32 flow_label;
385 u8 sgid_index;
386 u8 hop_limit;
387 u8 traffic_class;
388};
389
Hal Rosenstock513789e2005-07-27 11:45:34 -0700390struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700391 __be32 version_tclass_flow;
392 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700393 u8 next_hdr;
394 u8 hop_limit;
395 union ib_gid sgid;
396 union ib_gid dgid;
397};
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399enum {
400 IB_MULTICAST_QPN = 0xffffff
401};
402
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800403#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405enum ib_ah_flags {
406 IB_AH_GRH = 1
407};
408
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700409enum ib_rate {
410 IB_RATE_PORT_CURRENT = 0,
411 IB_RATE_2_5_GBPS = 2,
412 IB_RATE_5_GBPS = 5,
413 IB_RATE_10_GBPS = 3,
414 IB_RATE_20_GBPS = 6,
415 IB_RATE_30_GBPS = 4,
416 IB_RATE_40_GBPS = 7,
417 IB_RATE_60_GBPS = 8,
418 IB_RATE_80_GBPS = 9,
419 IB_RATE_120_GBPS = 10
420};
421
422/**
423 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
424 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
425 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
426 * @rate: rate to convert.
427 */
428int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
429
430/**
431 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
432 * enum.
433 * @mult: multiple to convert.
434 */
435enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437struct ib_ah_attr {
438 struct ib_global_route grh;
439 u16 dlid;
440 u8 sl;
441 u8 src_path_bits;
442 u8 static_rate;
443 u8 ah_flags;
444 u8 port_num;
445};
446
447enum ib_wc_status {
448 IB_WC_SUCCESS,
449 IB_WC_LOC_LEN_ERR,
450 IB_WC_LOC_QP_OP_ERR,
451 IB_WC_LOC_EEC_OP_ERR,
452 IB_WC_LOC_PROT_ERR,
453 IB_WC_WR_FLUSH_ERR,
454 IB_WC_MW_BIND_ERR,
455 IB_WC_BAD_RESP_ERR,
456 IB_WC_LOC_ACCESS_ERR,
457 IB_WC_REM_INV_REQ_ERR,
458 IB_WC_REM_ACCESS_ERR,
459 IB_WC_REM_OP_ERR,
460 IB_WC_RETRY_EXC_ERR,
461 IB_WC_RNR_RETRY_EXC_ERR,
462 IB_WC_LOC_RDD_VIOL_ERR,
463 IB_WC_REM_INV_RD_REQ_ERR,
464 IB_WC_REM_ABORT_ERR,
465 IB_WC_INV_EECN_ERR,
466 IB_WC_INV_EEC_STATE_ERR,
467 IB_WC_FATAL_ERR,
468 IB_WC_RESP_TIMEOUT_ERR,
469 IB_WC_GENERAL_ERR
470};
471
472enum ib_wc_opcode {
473 IB_WC_SEND,
474 IB_WC_RDMA_WRITE,
475 IB_WC_RDMA_READ,
476 IB_WC_COMP_SWAP,
477 IB_WC_FETCH_ADD,
478 IB_WC_BIND_MW,
Eli Cohenc93570f2008-04-16 21:09:27 -0700479 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700480 IB_WC_LOCAL_INV,
481 IB_WC_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300482 IB_WC_MASKED_COMP_SWAP,
483 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484/*
485 * Set value of IB_WC_RECV so consumers can test if a completion is a
486 * receive by testing (opcode & IB_WC_RECV).
487 */
488 IB_WC_RECV = 1 << 7,
489 IB_WC_RECV_RDMA_WITH_IMM
490};
491
492enum ib_wc_flags {
493 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -0700494 IB_WC_WITH_IMM = (1<<1),
495 IB_WC_WITH_INVALIDATE = (1<<2),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496};
497
498struct ib_wc {
499 u64 wr_id;
500 enum ib_wc_status status;
501 enum ib_wc_opcode opcode;
502 u32 vendor_err;
503 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +0200504 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -0700505 union {
506 __be32 imm_data;
507 u32 invalidate_rkey;
508 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 u32 src_qp;
510 int wc_flags;
511 u16 pkey_index;
512 u16 slid;
513 u8 sl;
514 u8 dlid_path_bits;
515 u8 port_num; /* valid only for DR SMPs on switches */
Eli Cohene0605d92008-01-30 18:30:57 +0200516 int csum_ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517};
518
Roland Dreiered23a722007-05-06 21:02:48 -0700519enum ib_cq_notify_flags {
520 IB_CQ_SOLICITED = 1 << 0,
521 IB_CQ_NEXT_COMP = 1 << 1,
522 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
523 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524};
525
Sean Hefty96104ed2011-05-23 16:31:36 -0700526enum ib_srq_type {
Sean Hefty418d5132011-05-23 19:42:29 -0700527 IB_SRQT_BASIC,
528 IB_SRQT_XRC
Sean Hefty96104ed2011-05-23 16:31:36 -0700529};
530
Roland Dreierd41fcc62005-08-18 12:23:08 -0700531enum ib_srq_attr_mask {
532 IB_SRQ_MAX_WR = 1 << 0,
533 IB_SRQ_LIMIT = 1 << 1,
534};
535
536struct ib_srq_attr {
537 u32 max_wr;
538 u32 max_sge;
539 u32 srq_limit;
540};
541
542struct ib_srq_init_attr {
543 void (*event_handler)(struct ib_event *, void *);
544 void *srq_context;
545 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -0700546 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -0700547
548 union {
549 struct {
550 struct ib_xrcd *xrcd;
551 struct ib_cq *cq;
552 } xrc;
553 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700554};
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556struct ib_qp_cap {
557 u32 max_send_wr;
558 u32 max_recv_wr;
559 u32 max_send_sge;
560 u32 max_recv_sge;
561 u32 max_inline_data;
562};
563
564enum ib_sig_type {
565 IB_SIGNAL_ALL_WR,
566 IB_SIGNAL_REQ_WR
567};
568
569enum ib_qp_type {
570 /*
571 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
572 * here (and in that order) since the MAD layer uses them as
573 * indices into a 2-entry table.
574 */
575 IB_QPT_SMI,
576 IB_QPT_GSI,
577
578 IB_QPT_RC,
579 IB_QPT_UC,
580 IB_QPT_UD,
581 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700582 IB_QPT_RAW_ETHERTYPE,
583 /* Save 8 for RAW_PACKET */
584 IB_QPT_XRC_INI = 9,
585 IB_QPT_XRC_TGT,
586 IB_QPT_MAX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587};
588
Eli Cohenb846f252008-04-16 21:09:27 -0700589enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -0700590 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
591 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
Eli Cohenb846f252008-04-16 21:09:27 -0700592};
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594struct ib_qp_init_attr {
595 void (*event_handler)(struct ib_event *, void *);
596 void *qp_context;
597 struct ib_cq *send_cq;
598 struct ib_cq *recv_cq;
599 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700600 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 struct ib_qp_cap cap;
602 enum ib_sig_type sq_sig_type;
603 enum ib_qp_type qp_type;
Eli Cohenb846f252008-04-16 21:09:27 -0700604 enum ib_qp_create_flags create_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 u8 port_num; /* special QP types only */
606};
607
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700608struct ib_qp_open_attr {
609 void (*event_handler)(struct ib_event *, void *);
610 void *qp_context;
611 u32 qp_num;
612 enum ib_qp_type qp_type;
613};
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615enum ib_rnr_timeout {
616 IB_RNR_TIMER_655_36 = 0,
617 IB_RNR_TIMER_000_01 = 1,
618 IB_RNR_TIMER_000_02 = 2,
619 IB_RNR_TIMER_000_03 = 3,
620 IB_RNR_TIMER_000_04 = 4,
621 IB_RNR_TIMER_000_06 = 5,
622 IB_RNR_TIMER_000_08 = 6,
623 IB_RNR_TIMER_000_12 = 7,
624 IB_RNR_TIMER_000_16 = 8,
625 IB_RNR_TIMER_000_24 = 9,
626 IB_RNR_TIMER_000_32 = 10,
627 IB_RNR_TIMER_000_48 = 11,
628 IB_RNR_TIMER_000_64 = 12,
629 IB_RNR_TIMER_000_96 = 13,
630 IB_RNR_TIMER_001_28 = 14,
631 IB_RNR_TIMER_001_92 = 15,
632 IB_RNR_TIMER_002_56 = 16,
633 IB_RNR_TIMER_003_84 = 17,
634 IB_RNR_TIMER_005_12 = 18,
635 IB_RNR_TIMER_007_68 = 19,
636 IB_RNR_TIMER_010_24 = 20,
637 IB_RNR_TIMER_015_36 = 21,
638 IB_RNR_TIMER_020_48 = 22,
639 IB_RNR_TIMER_030_72 = 23,
640 IB_RNR_TIMER_040_96 = 24,
641 IB_RNR_TIMER_061_44 = 25,
642 IB_RNR_TIMER_081_92 = 26,
643 IB_RNR_TIMER_122_88 = 27,
644 IB_RNR_TIMER_163_84 = 28,
645 IB_RNR_TIMER_245_76 = 29,
646 IB_RNR_TIMER_327_68 = 30,
647 IB_RNR_TIMER_491_52 = 31
648};
649
650enum ib_qp_attr_mask {
651 IB_QP_STATE = 1,
652 IB_QP_CUR_STATE = (1<<1),
653 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
654 IB_QP_ACCESS_FLAGS = (1<<3),
655 IB_QP_PKEY_INDEX = (1<<4),
656 IB_QP_PORT = (1<<5),
657 IB_QP_QKEY = (1<<6),
658 IB_QP_AV = (1<<7),
659 IB_QP_PATH_MTU = (1<<8),
660 IB_QP_TIMEOUT = (1<<9),
661 IB_QP_RETRY_CNT = (1<<10),
662 IB_QP_RNR_RETRY = (1<<11),
663 IB_QP_RQ_PSN = (1<<12),
664 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
665 IB_QP_ALT_PATH = (1<<14),
666 IB_QP_MIN_RNR_TIMER = (1<<15),
667 IB_QP_SQ_PSN = (1<<16),
668 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
669 IB_QP_PATH_MIG_STATE = (1<<18),
670 IB_QP_CAP = (1<<19),
671 IB_QP_DEST_QPN = (1<<20)
672};
673
674enum ib_qp_state {
675 IB_QPS_RESET,
676 IB_QPS_INIT,
677 IB_QPS_RTR,
678 IB_QPS_RTS,
679 IB_QPS_SQD,
680 IB_QPS_SQE,
681 IB_QPS_ERR
682};
683
684enum ib_mig_state {
685 IB_MIG_MIGRATED,
686 IB_MIG_REARM,
687 IB_MIG_ARMED
688};
689
690struct ib_qp_attr {
691 enum ib_qp_state qp_state;
692 enum ib_qp_state cur_qp_state;
693 enum ib_mtu path_mtu;
694 enum ib_mig_state path_mig_state;
695 u32 qkey;
696 u32 rq_psn;
697 u32 sq_psn;
698 u32 dest_qp_num;
699 int qp_access_flags;
700 struct ib_qp_cap cap;
701 struct ib_ah_attr ah_attr;
702 struct ib_ah_attr alt_ah_attr;
703 u16 pkey_index;
704 u16 alt_pkey_index;
705 u8 en_sqd_async_notify;
706 u8 sq_draining;
707 u8 max_rd_atomic;
708 u8 max_dest_rd_atomic;
709 u8 min_rnr_timer;
710 u8 port_num;
711 u8 timeout;
712 u8 retry_cnt;
713 u8 rnr_retry;
714 u8 alt_port_num;
715 u8 alt_timeout;
716};
717
718enum ib_wr_opcode {
719 IB_WR_RDMA_WRITE,
720 IB_WR_RDMA_WRITE_WITH_IMM,
721 IB_WR_SEND,
722 IB_WR_SEND_WITH_IMM,
723 IB_WR_RDMA_READ,
724 IB_WR_ATOMIC_CMP_AND_SWP,
Eli Cohenc93570f2008-04-16 21:09:27 -0700725 IB_WR_ATOMIC_FETCH_AND_ADD,
Roland Dreier0f39cf32008-04-16 21:09:32 -0700726 IB_WR_LSO,
727 IB_WR_SEND_WITH_INV,
Steve Wise00f7ec32008-07-14 23:48:45 -0700728 IB_WR_RDMA_READ_WITH_INV,
729 IB_WR_LOCAL_INV,
730 IB_WR_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300731 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
732 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733};
734
735enum ib_send_flags {
736 IB_SEND_FENCE = 1,
737 IB_SEND_SIGNALED = (1<<1),
738 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +0200739 IB_SEND_INLINE = (1<<3),
740 IB_SEND_IP_CSUM = (1<<4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741};
742
743struct ib_sge {
744 u64 addr;
745 u32 length;
746 u32 lkey;
747};
748
Steve Wise00f7ec32008-07-14 23:48:45 -0700749struct ib_fast_reg_page_list {
750 struct ib_device *device;
751 u64 *page_list;
752 unsigned int max_page_list_len;
753};
754
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755struct ib_send_wr {
756 struct ib_send_wr *next;
757 u64 wr_id;
758 struct ib_sge *sg_list;
759 int num_sge;
760 enum ib_wr_opcode opcode;
761 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -0700762 union {
763 __be32 imm_data;
764 u32 invalidate_rkey;
765 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 union {
767 struct {
768 u64 remote_addr;
769 u32 rkey;
770 } rdma;
771 struct {
772 u64 remote_addr;
773 u64 compare_add;
774 u64 swap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300775 u64 compare_add_mask;
776 u64 swap_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 u32 rkey;
778 } atomic;
779 struct {
780 struct ib_ah *ah;
Eli Cohenc93570f2008-04-16 21:09:27 -0700781 void *header;
782 int hlen;
783 int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 u32 remote_qpn;
785 u32 remote_qkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 u16 pkey_index; /* valid for GSI only */
787 u8 port_num; /* valid for DR SMPs on switch only */
788 } ud;
Steve Wise00f7ec32008-07-14 23:48:45 -0700789 struct {
790 u64 iova_start;
791 struct ib_fast_reg_page_list *page_list;
792 unsigned int page_shift;
793 unsigned int page_list_len;
794 u32 length;
795 int access_flags;
796 u32 rkey;
797 } fast_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 } wr;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700799 u32 xrc_remote_srq_num; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800};
801
802struct ib_recv_wr {
803 struct ib_recv_wr *next;
804 u64 wr_id;
805 struct ib_sge *sg_list;
806 int num_sge;
807};
808
809enum ib_access_flags {
810 IB_ACCESS_LOCAL_WRITE = 1,
811 IB_ACCESS_REMOTE_WRITE = (1<<1),
812 IB_ACCESS_REMOTE_READ = (1<<2),
813 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
814 IB_ACCESS_MW_BIND = (1<<4)
815};
816
817struct ib_phys_buf {
818 u64 addr;
819 u64 size;
820};
821
822struct ib_mr_attr {
823 struct ib_pd *pd;
824 u64 device_virt_addr;
825 u64 size;
826 int mr_access_flags;
827 u32 lkey;
828 u32 rkey;
829};
830
831enum ib_mr_rereg_flags {
832 IB_MR_REREG_TRANS = 1,
833 IB_MR_REREG_PD = (1<<1),
834 IB_MR_REREG_ACCESS = (1<<2)
835};
836
837struct ib_mw_bind {
838 struct ib_mr *mr;
839 u64 wr_id;
840 u64 addr;
841 u32 length;
842 int send_flags;
843 int mw_access_flags;
844};
845
846struct ib_fmr_attr {
847 int max_pages;
848 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -0800849 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850};
851
Roland Dreiere2773c02005-07-07 17:57:10 -0700852struct ib_ucontext {
853 struct ib_device *device;
854 struct list_head pd_list;
855 struct list_head mr_list;
856 struct list_head mw_list;
857 struct list_head cq_list;
858 struct list_head qp_list;
859 struct list_head srq_list;
860 struct list_head ah_list;
Sean Hefty53d0bd12011-05-24 08:33:46 -0700861 struct list_head xrcd_list;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -0800862 int closing;
Roland Dreiere2773c02005-07-07 17:57:10 -0700863};
864
865struct ib_uobject {
866 u64 user_handle; /* handle given to us by userspace */
867 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -0700868 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -0700869 struct list_head list; /* link to context's list */
Roland Dreierb3d636b2008-04-16 21:01:06 -0700870 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -0700871 struct kref ref;
872 struct rw_semaphore mutex; /* protects .live */
873 int live;
Roland Dreiere2773c02005-07-07 17:57:10 -0700874};
875
Roland Dreiere2773c02005-07-07 17:57:10 -0700876struct ib_udata {
877 void __user *inbuf;
878 void __user *outbuf;
879 size_t inlen;
880 size_t outlen;
881};
882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883struct ib_pd {
Roland Dreiere2773c02005-07-07 17:57:10 -0700884 struct ib_device *device;
885 struct ib_uobject *uobject;
886 atomic_t usecnt; /* count all resources */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887};
888
Sean Hefty59991f92011-05-23 17:52:46 -0700889struct ib_xrcd {
890 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -0700891 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -0700892 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -0700893
894 struct mutex tgt_qp_mutex;
895 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -0700896};
897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898struct ib_ah {
899 struct ib_device *device;
900 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -0700901 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902};
903
904typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
905
906struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -0700907 struct ib_device *device;
908 struct ib_uobject *uobject;
909 ib_comp_handler comp_handler;
910 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -0700911 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -0700912 int cqe;
913 atomic_t usecnt; /* count number of work queues */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914};
915
916struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -0700917 struct ib_device *device;
918 struct ib_pd *pd;
919 struct ib_uobject *uobject;
920 void (*event_handler)(struct ib_event *, void *);
921 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -0700922 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -0700924
925 union {
926 struct {
927 struct ib_xrcd *xrcd;
928 struct ib_cq *cq;
929 u32 srq_num;
930 } xrc;
931 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932};
933
934struct ib_qp {
935 struct ib_device *device;
936 struct ib_pd *pd;
937 struct ib_cq *send_cq;
938 struct ib_cq *recv_cq;
939 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700940 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -0700941 struct list_head xrcd_list;
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700942 atomic_t usecnt; /* count times opened */
943 struct list_head open_list;
944 struct ib_qp *real_qp;
Roland Dreiere2773c02005-07-07 17:57:10 -0700945 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 void (*event_handler)(struct ib_event *, void *);
947 void *qp_context;
948 u32 qp_num;
949 enum ib_qp_type qp_type;
950};
951
952struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -0700953 struct ib_device *device;
954 struct ib_pd *pd;
955 struct ib_uobject *uobject;
956 u32 lkey;
957 u32 rkey;
958 atomic_t usecnt; /* count number of MWs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959};
960
961struct ib_mw {
962 struct ib_device *device;
963 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -0700964 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 u32 rkey;
966};
967
968struct ib_fmr {
969 struct ib_device *device;
970 struct ib_pd *pd;
971 struct list_head list;
972 u32 lkey;
973 u32 rkey;
974};
975
976struct ib_mad;
977struct ib_grh;
978
979enum ib_process_mad_flags {
980 IB_MAD_IGNORE_MKEY = 1,
981 IB_MAD_IGNORE_BKEY = 2,
982 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
983};
984
985enum ib_mad_result {
986 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
987 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
988 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
989 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
990};
991
992#define IB_DEVICE_NAME_MAX 64
993
994struct ib_cache {
995 rwlock_t lock;
996 struct ib_event_handler event_handler;
997 struct ib_pkey_cache **pkey_cache;
998 struct ib_gid_cache **gid_cache;
Jack Morgenstein6fb9cdb2006-06-17 20:37:34 -0700999 u8 *lmc_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000};
1001
Ralph Campbell9b513092006-12-12 14:27:41 -08001002struct ib_dma_mapping_ops {
1003 int (*mapping_error)(struct ib_device *dev,
1004 u64 dma_addr);
1005 u64 (*map_single)(struct ib_device *dev,
1006 void *ptr, size_t size,
1007 enum dma_data_direction direction);
1008 void (*unmap_single)(struct ib_device *dev,
1009 u64 addr, size_t size,
1010 enum dma_data_direction direction);
1011 u64 (*map_page)(struct ib_device *dev,
1012 struct page *page, unsigned long offset,
1013 size_t size,
1014 enum dma_data_direction direction);
1015 void (*unmap_page)(struct ib_device *dev,
1016 u64 addr, size_t size,
1017 enum dma_data_direction direction);
1018 int (*map_sg)(struct ib_device *dev,
1019 struct scatterlist *sg, int nents,
1020 enum dma_data_direction direction);
1021 void (*unmap_sg)(struct ib_device *dev,
1022 struct scatterlist *sg, int nents,
1023 enum dma_data_direction direction);
1024 u64 (*dma_address)(struct ib_device *dev,
1025 struct scatterlist *sg);
1026 unsigned int (*dma_len)(struct ib_device *dev,
1027 struct scatterlist *sg);
1028 void (*sync_single_for_cpu)(struct ib_device *dev,
1029 u64 dma_handle,
1030 size_t size,
Dotan Barak4deccd62008-07-14 23:48:44 -07001031 enum dma_data_direction dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08001032 void (*sync_single_for_device)(struct ib_device *dev,
1033 u64 dma_handle,
1034 size_t size,
1035 enum dma_data_direction dir);
1036 void *(*alloc_coherent)(struct ib_device *dev,
1037 size_t size,
1038 u64 *dma_handle,
1039 gfp_t flag);
1040 void (*free_coherent)(struct ib_device *dev,
1041 size_t size, void *cpu_addr,
1042 u64 dma_handle);
1043};
1044
Tom Tucker07ebafb2006-08-03 16:02:42 -05001045struct iw_cm_verbs;
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047struct ib_device {
1048 struct device *dma_device;
1049
1050 char name[IB_DEVICE_NAME_MAX];
1051
1052 struct list_head event_handler_list;
1053 spinlock_t event_handler_lock;
1054
Alexander Chiang17a55f72010-02-02 19:09:16 +00001055 spinlock_t client_data_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 struct list_head core_list;
1057 struct list_head client_data_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 struct ib_cache cache;
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001060 int *pkey_tbl_len;
1061 int *gid_tbl_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001063 int num_comp_vectors;
1064
Tom Tucker07ebafb2006-08-03 16:02:42 -05001065 struct iw_cm_verbs *iwcm;
1066
Steve Wise7f624d02008-07-14 23:48:48 -07001067 int (*get_protocol_stats)(struct ib_device *device,
1068 union rdma_protocol_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 int (*query_device)(struct ib_device *device,
1070 struct ib_device_attr *device_attr);
1071 int (*query_port)(struct ib_device *device,
1072 u8 port_num,
1073 struct ib_port_attr *port_attr);
Eli Cohena3f5ada2010-09-27 17:51:10 -07001074 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1075 u8 port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 int (*query_gid)(struct ib_device *device,
1077 u8 port_num, int index,
1078 union ib_gid *gid);
1079 int (*query_pkey)(struct ib_device *device,
1080 u8 port_num, u16 index, u16 *pkey);
1081 int (*modify_device)(struct ib_device *device,
1082 int device_modify_mask,
1083 struct ib_device_modify *device_modify);
1084 int (*modify_port)(struct ib_device *device,
1085 u8 port_num, int port_modify_mask,
1086 struct ib_port_modify *port_modify);
Roland Dreiere2773c02005-07-07 17:57:10 -07001087 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1088 struct ib_udata *udata);
1089 int (*dealloc_ucontext)(struct ib_ucontext *context);
1090 int (*mmap)(struct ib_ucontext *context,
1091 struct vm_area_struct *vma);
1092 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1093 struct ib_ucontext *context,
1094 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 int (*dealloc_pd)(struct ib_pd *pd);
1096 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1097 struct ib_ah_attr *ah_attr);
1098 int (*modify_ah)(struct ib_ah *ah,
1099 struct ib_ah_attr *ah_attr);
1100 int (*query_ah)(struct ib_ah *ah,
1101 struct ib_ah_attr *ah_attr);
1102 int (*destroy_ah)(struct ib_ah *ah);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001103 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1104 struct ib_srq_init_attr *srq_init_attr,
1105 struct ib_udata *udata);
1106 int (*modify_srq)(struct ib_srq *srq,
1107 struct ib_srq_attr *srq_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001108 enum ib_srq_attr_mask srq_attr_mask,
1109 struct ib_udata *udata);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001110 int (*query_srq)(struct ib_srq *srq,
1111 struct ib_srq_attr *srq_attr);
1112 int (*destroy_srq)(struct ib_srq *srq);
1113 int (*post_srq_recv)(struct ib_srq *srq,
1114 struct ib_recv_wr *recv_wr,
1115 struct ib_recv_wr **bad_recv_wr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 struct ib_qp * (*create_qp)(struct ib_pd *pd,
Roland Dreiere2773c02005-07-07 17:57:10 -07001117 struct ib_qp_init_attr *qp_init_attr,
1118 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 int (*modify_qp)(struct ib_qp *qp,
1120 struct ib_qp_attr *qp_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001121 int qp_attr_mask,
1122 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 int (*query_qp)(struct ib_qp *qp,
1124 struct ib_qp_attr *qp_attr,
1125 int qp_attr_mask,
1126 struct ib_qp_init_attr *qp_init_attr);
1127 int (*destroy_qp)(struct ib_qp *qp);
1128 int (*post_send)(struct ib_qp *qp,
1129 struct ib_send_wr *send_wr,
1130 struct ib_send_wr **bad_send_wr);
1131 int (*post_recv)(struct ib_qp *qp,
1132 struct ib_recv_wr *recv_wr,
1133 struct ib_recv_wr **bad_recv_wr);
Roland Dreiere2773c02005-07-07 17:57:10 -07001134 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001135 int comp_vector,
Roland Dreiere2773c02005-07-07 17:57:10 -07001136 struct ib_ucontext *context,
1137 struct ib_udata *udata);
Eli Cohen2dd57162008-04-16 21:09:33 -07001138 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1139 u16 cq_period);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 int (*destroy_cq)(struct ib_cq *cq);
Roland Dreier33b9b3e2006-01-30 14:29:21 -08001141 int (*resize_cq)(struct ib_cq *cq, int cqe,
1142 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1144 struct ib_wc *wc);
1145 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1146 int (*req_notify_cq)(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001147 enum ib_cq_notify_flags flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 int (*req_ncomp_notif)(struct ib_cq *cq,
1149 int wc_cnt);
1150 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1151 int mr_access_flags);
1152 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
1153 struct ib_phys_buf *phys_buf_array,
1154 int num_phys_buf,
1155 int mr_access_flags,
1156 u64 *iova_start);
Roland Dreiere2773c02005-07-07 17:57:10 -07001157 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001158 u64 start, u64 length,
1159 u64 virt_addr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001160 int mr_access_flags,
1161 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 int (*query_mr)(struct ib_mr *mr,
1163 struct ib_mr_attr *mr_attr);
1164 int (*dereg_mr)(struct ib_mr *mr);
Steve Wise00f7ec32008-07-14 23:48:45 -07001165 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
1166 int max_page_list_len);
1167 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1168 int page_list_len);
1169 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 int (*rereg_phys_mr)(struct ib_mr *mr,
1171 int mr_rereg_mask,
1172 struct ib_pd *pd,
1173 struct ib_phys_buf *phys_buf_array,
1174 int num_phys_buf,
1175 int mr_access_flags,
1176 u64 *iova_start);
1177 struct ib_mw * (*alloc_mw)(struct ib_pd *pd);
1178 int (*bind_mw)(struct ib_qp *qp,
1179 struct ib_mw *mw,
1180 struct ib_mw_bind *mw_bind);
1181 int (*dealloc_mw)(struct ib_mw *mw);
1182 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1183 int mr_access_flags,
1184 struct ib_fmr_attr *fmr_attr);
1185 int (*map_phys_fmr)(struct ib_fmr *fmr,
1186 u64 *page_list, int list_len,
1187 u64 iova);
1188 int (*unmap_fmr)(struct list_head *fmr_list);
1189 int (*dealloc_fmr)(struct ib_fmr *fmr);
1190 int (*attach_mcast)(struct ib_qp *qp,
1191 union ib_gid *gid,
1192 u16 lid);
1193 int (*detach_mcast)(struct ib_qp *qp,
1194 union ib_gid *gid,
1195 u16 lid);
1196 int (*process_mad)(struct ib_device *device,
1197 int process_mad_flags,
1198 u8 port_num,
1199 struct ib_wc *in_wc,
1200 struct ib_grh *in_grh,
1201 struct ib_mad *in_mad,
1202 struct ib_mad *out_mad);
Sean Hefty59991f92011-05-23 17:52:46 -07001203 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1204 struct ib_ucontext *ucontext,
1205 struct ib_udata *udata);
1206 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Ralph Campbell9b513092006-12-12 14:27:41 -08001208 struct ib_dma_mapping_ops *dma_ops;
1209
Roland Dreiere2773c02005-07-07 17:57:10 -07001210 struct module *owner;
Tony Jonesf4e91eb2008-02-22 00:13:36 +01001211 struct device dev;
Greg Kroah-Hartman35be0682007-12-17 15:54:39 -04001212 struct kobject *ports_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 struct list_head port_list;
1214
1215 enum {
1216 IB_DEV_UNINITIALIZED,
1217 IB_DEV_REGISTERED,
1218 IB_DEV_UNREGISTERED
1219 } reg_state;
1220
Roland Dreier274c0892005-09-29 14:17:48 -07001221 int uverbs_abi_ver;
Alexander Chiang17a55f72010-02-02 19:09:16 +00001222 u64 uverbs_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07001223
Roland Dreierc5bcbbb2006-02-02 09:47:14 -08001224 char node_desc[64];
Sean Heftycf311cd2006-01-10 07:39:34 -08001225 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07001226 u32 local_dma_lkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 u8 node_type;
1228 u8 phys_port_cnt;
1229};
1230
1231struct ib_client {
1232 char *name;
1233 void (*add) (struct ib_device *);
1234 void (*remove)(struct ib_device *);
1235
1236 struct list_head list;
1237};
1238
1239struct ib_device *ib_alloc_device(size_t size);
1240void ib_dealloc_device(struct ib_device *device);
1241
Ralph Campbell9a6edb62010-05-06 17:03:25 -07001242int ib_register_device(struct ib_device *device,
1243 int (*port_callback)(struct ib_device *,
1244 u8, struct kobject *));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245void ib_unregister_device(struct ib_device *device);
1246
1247int ib_register_client (struct ib_client *client);
1248void ib_unregister_client(struct ib_client *client);
1249
1250void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1251void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1252 void *data);
1253
Roland Dreiere2773c02005-07-07 17:57:10 -07001254static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1255{
1256 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1257}
1258
1259static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1260{
1261 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1262}
1263
Roland Dreier8a518662006-02-13 12:48:12 -08001264/**
1265 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1266 * contains all required attributes and no attributes not allowed for
1267 * the given QP state transition.
1268 * @cur_state: Current QP state
1269 * @next_state: Next QP state
1270 * @type: QP type
1271 * @mask: Mask of supplied QP attributes
1272 *
1273 * This function is a helper function that a low-level driver's
1274 * modify_qp method can use to validate the consumer's input. It
1275 * checks that cur_state and next_state are valid QP states, that a
1276 * transition from cur_state to next_state is allowed by the IB spec,
1277 * and that the attribute mask supplied is allowed for the transition.
1278 */
1279int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
1280 enum ib_qp_type type, enum ib_qp_attr_mask mask);
1281
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282int ib_register_event_handler (struct ib_event_handler *event_handler);
1283int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1284void ib_dispatch_event(struct ib_event *event);
1285
1286int ib_query_device(struct ib_device *device,
1287 struct ib_device_attr *device_attr);
1288
1289int ib_query_port(struct ib_device *device,
1290 u8 port_num, struct ib_port_attr *port_attr);
1291
Eli Cohena3f5ada2010-09-27 17:51:10 -07001292enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1293 u8 port_num);
1294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295int ib_query_gid(struct ib_device *device,
1296 u8 port_num, int index, union ib_gid *gid);
1297
1298int ib_query_pkey(struct ib_device *device,
1299 u8 port_num, u16 index, u16 *pkey);
1300
1301int ib_modify_device(struct ib_device *device,
1302 int device_modify_mask,
1303 struct ib_device_modify *device_modify);
1304
1305int ib_modify_port(struct ib_device *device,
1306 u8 port_num, int port_modify_mask,
1307 struct ib_port_modify *port_modify);
1308
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001309int ib_find_gid(struct ib_device *device, union ib_gid *gid,
1310 u8 *port_num, u16 *index);
1311
1312int ib_find_pkey(struct ib_device *device,
1313 u8 port_num, u16 pkey, u16 *index);
1314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315/**
1316 * ib_alloc_pd - Allocates an unused protection domain.
1317 * @device: The device on which to allocate the protection domain.
1318 *
1319 * A protection domain object provides an association between QPs, shared
1320 * receive queues, address handles, memory regions, and memory windows.
1321 */
1322struct ib_pd *ib_alloc_pd(struct ib_device *device);
1323
1324/**
1325 * ib_dealloc_pd - Deallocates a protection domain.
1326 * @pd: The protection domain to deallocate.
1327 */
1328int ib_dealloc_pd(struct ib_pd *pd);
1329
1330/**
1331 * ib_create_ah - Creates an address handle for the given address vector.
1332 * @pd: The protection domain associated with the address handle.
1333 * @ah_attr: The attributes of the address vector.
1334 *
1335 * The address handle is used to reference a local or global destination
1336 * in all UD QP post sends.
1337 */
1338struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1339
1340/**
Sean Hefty4e00d692006-06-17 20:37:39 -07001341 * ib_init_ah_from_wc - Initializes address handle attributes from a
1342 * work completion.
1343 * @device: Device on which the received message arrived.
1344 * @port_num: Port on which the received message arrived.
1345 * @wc: Work completion associated with the received message.
1346 * @grh: References the received global route header. This parameter is
1347 * ignored unless the work completion indicates that the GRH is valid.
1348 * @ah_attr: Returned attributes that can be used when creating an address
1349 * handle for replying to the message.
1350 */
1351int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1352 struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1353
1354/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07001355 * ib_create_ah_from_wc - Creates an address handle associated with the
1356 * sender of the specified work completion.
1357 * @pd: The protection domain associated with the address handle.
1358 * @wc: Work completion information associated with a received message.
1359 * @grh: References the received global route header. This parameter is
1360 * ignored unless the work completion indicates that the GRH is valid.
1361 * @port_num: The outbound port number to associate with the address.
1362 *
1363 * The address handle is used to reference a local or global destination
1364 * in all UD QP post sends.
1365 */
1366struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1367 struct ib_grh *grh, u8 port_num);
1368
1369/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 * ib_modify_ah - Modifies the address vector associated with an address
1371 * handle.
1372 * @ah: The address handle to modify.
1373 * @ah_attr: The new address vector attributes to associate with the
1374 * address handle.
1375 */
1376int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1377
1378/**
1379 * ib_query_ah - Queries the address vector associated with an address
1380 * handle.
1381 * @ah: The address handle to query.
1382 * @ah_attr: The address vector attributes associated with the address
1383 * handle.
1384 */
1385int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1386
1387/**
1388 * ib_destroy_ah - Destroys an address handle.
1389 * @ah: The address handle to destroy.
1390 */
1391int ib_destroy_ah(struct ib_ah *ah);
1392
1393/**
Roland Dreierd41fcc62005-08-18 12:23:08 -07001394 * ib_create_srq - Creates a SRQ associated with the specified protection
1395 * domain.
1396 * @pd: The protection domain associated with the SRQ.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001397 * @srq_init_attr: A list of initial attributes required to create the
1398 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1399 * the actual capabilities of the created SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07001400 *
1401 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1402 * requested size of the SRQ, and set to the actual values allocated
1403 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
1404 * will always be at least as large as the requested values.
1405 */
1406struct ib_srq *ib_create_srq(struct ib_pd *pd,
1407 struct ib_srq_init_attr *srq_init_attr);
1408
1409/**
1410 * ib_modify_srq - Modifies the attributes for the specified SRQ.
1411 * @srq: The SRQ to modify.
1412 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1413 * the current values of selected SRQ attributes are returned.
1414 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1415 * are being modified.
1416 *
1417 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1418 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1419 * the number of receives queued drops below the limit.
1420 */
1421int ib_modify_srq(struct ib_srq *srq,
1422 struct ib_srq_attr *srq_attr,
1423 enum ib_srq_attr_mask srq_attr_mask);
1424
1425/**
1426 * ib_query_srq - Returns the attribute list and current values for the
1427 * specified SRQ.
1428 * @srq: The SRQ to query.
1429 * @srq_attr: The attributes of the specified SRQ.
1430 */
1431int ib_query_srq(struct ib_srq *srq,
1432 struct ib_srq_attr *srq_attr);
1433
1434/**
1435 * ib_destroy_srq - Destroys the specified SRQ.
1436 * @srq: The SRQ to destroy.
1437 */
1438int ib_destroy_srq(struct ib_srq *srq);
1439
1440/**
1441 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1442 * @srq: The SRQ to post the work request on.
1443 * @recv_wr: A list of work requests to post on the receive queue.
1444 * @bad_recv_wr: On an immediate failure, this parameter will reference
1445 * the work request that failed to be posted on the QP.
1446 */
1447static inline int ib_post_srq_recv(struct ib_srq *srq,
1448 struct ib_recv_wr *recv_wr,
1449 struct ib_recv_wr **bad_recv_wr)
1450{
1451 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1452}
1453
1454/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 * ib_create_qp - Creates a QP associated with the specified protection
1456 * domain.
1457 * @pd: The protection domain associated with the QP.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001458 * @qp_init_attr: A list of initial attributes required to create the
1459 * QP. If QP creation succeeds, then the attributes are updated to
1460 * the actual capabilities of the created QP.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 */
1462struct ib_qp *ib_create_qp(struct ib_pd *pd,
1463 struct ib_qp_init_attr *qp_init_attr);
1464
1465/**
1466 * ib_modify_qp - Modifies the attributes for the specified QP and then
1467 * transitions the QP to the given state.
1468 * @qp: The QP to modify.
1469 * @qp_attr: On input, specifies the QP attributes to modify. On output,
1470 * the current values of selected QP attributes are returned.
1471 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1472 * are being modified.
1473 */
1474int ib_modify_qp(struct ib_qp *qp,
1475 struct ib_qp_attr *qp_attr,
1476 int qp_attr_mask);
1477
1478/**
1479 * ib_query_qp - Returns the attribute list and current values for the
1480 * specified QP.
1481 * @qp: The QP to query.
1482 * @qp_attr: The attributes of the specified QP.
1483 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1484 * @qp_init_attr: Additional attributes of the selected QP.
1485 *
1486 * The qp_attr_mask may be used to limit the query to gathering only the
1487 * selected attributes.
1488 */
1489int ib_query_qp(struct ib_qp *qp,
1490 struct ib_qp_attr *qp_attr,
1491 int qp_attr_mask,
1492 struct ib_qp_init_attr *qp_init_attr);
1493
1494/**
1495 * ib_destroy_qp - Destroys the specified QP.
1496 * @qp: The QP to destroy.
1497 */
1498int ib_destroy_qp(struct ib_qp *qp);
1499
1500/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001501 * ib_open_qp - Obtain a reference to an existing sharable QP.
1502 * @xrcd - XRC domain
1503 * @qp_open_attr: Attributes identifying the QP to open.
1504 *
1505 * Returns a reference to a sharable QP.
1506 */
1507struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
1508 struct ib_qp_open_attr *qp_open_attr);
1509
1510/**
1511 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001512 * @qp: The QP handle to release
1513 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001514 * The opened QP handle is released by the caller. The underlying
1515 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001516 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001517int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07001518
1519/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 * ib_post_send - Posts a list of work requests to the send queue of
1521 * the specified QP.
1522 * @qp: The QP to post the work request on.
1523 * @send_wr: A list of work requests to post on the send queue.
1524 * @bad_send_wr: On an immediate failure, this parameter will reference
1525 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08001526 *
1527 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
1528 * error is returned, the QP state shall not be affected,
1529 * ib_post_send() will return an immediate error after queueing any
1530 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 */
1532static inline int ib_post_send(struct ib_qp *qp,
1533 struct ib_send_wr *send_wr,
1534 struct ib_send_wr **bad_send_wr)
1535{
1536 return qp->device->post_send(qp, send_wr, bad_send_wr);
1537}
1538
1539/**
1540 * ib_post_recv - Posts a list of work requests to the receive queue of
1541 * the specified QP.
1542 * @qp: The QP to post the work request on.
1543 * @recv_wr: A list of work requests to post on the receive queue.
1544 * @bad_recv_wr: On an immediate failure, this parameter will reference
1545 * the work request that failed to be posted on the QP.
1546 */
1547static inline int ib_post_recv(struct ib_qp *qp,
1548 struct ib_recv_wr *recv_wr,
1549 struct ib_recv_wr **bad_recv_wr)
1550{
1551 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1552}
1553
1554/**
1555 * ib_create_cq - Creates a CQ on the specified device.
1556 * @device: The device on which to create the CQ.
1557 * @comp_handler: A user-specified callback that is invoked when a
1558 * completion event occurs on the CQ.
1559 * @event_handler: A user-specified callback that is invoked when an
1560 * asynchronous event not associated with a completion occurs on the CQ.
1561 * @cq_context: Context associated with the CQ returned to the user via
1562 * the associated completion and event handlers.
1563 * @cqe: The minimum size of the CQ.
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001564 * @comp_vector - Completion vector used to signal completion events.
1565 * Must be >= 0 and < context->num_comp_vectors.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 *
1567 * Users can examine the cq structure to determine the actual CQ size.
1568 */
1569struct ib_cq *ib_create_cq(struct ib_device *device,
1570 ib_comp_handler comp_handler,
1571 void (*event_handler)(struct ib_event *, void *),
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001572 void *cq_context, int cqe, int comp_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
1574/**
1575 * ib_resize_cq - Modifies the capacity of the CQ.
1576 * @cq: The CQ to resize.
1577 * @cqe: The minimum size of the CQ.
1578 *
1579 * Users can examine the cq structure to determine the actual CQ size.
1580 */
1581int ib_resize_cq(struct ib_cq *cq, int cqe);
1582
1583/**
Eli Cohen2dd57162008-04-16 21:09:33 -07001584 * ib_modify_cq - Modifies moderation params of the CQ
1585 * @cq: The CQ to modify.
1586 * @cq_count: number of CQEs that will trigger an event
1587 * @cq_period: max period of time in usec before triggering an event
1588 *
1589 */
1590int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
1591
1592/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 * ib_destroy_cq - Destroys the specified CQ.
1594 * @cq: The CQ to destroy.
1595 */
1596int ib_destroy_cq(struct ib_cq *cq);
1597
1598/**
1599 * ib_poll_cq - poll a CQ for completion(s)
1600 * @cq:the CQ being polled
1601 * @num_entries:maximum number of completions to return
1602 * @wc:array of at least @num_entries &struct ib_wc where completions
1603 * will be returned
1604 *
1605 * Poll a CQ for (possibly multiple) completions. If the return value
1606 * is < 0, an error occurred. If the return value is >= 0, it is the
1607 * number of completions returned. If the return value is
1608 * non-negative and < num_entries, then the CQ was emptied.
1609 */
1610static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1611 struct ib_wc *wc)
1612{
1613 return cq->device->poll_cq(cq, num_entries, wc);
1614}
1615
1616/**
1617 * ib_peek_cq - Returns the number of unreaped completions currently
1618 * on the specified CQ.
1619 * @cq: The CQ to peek.
1620 * @wc_cnt: A minimum number of unreaped completions to check for.
1621 *
1622 * If the number of unreaped completions is greater than or equal to wc_cnt,
1623 * this function returns wc_cnt, otherwise, it returns the actual number of
1624 * unreaped completions.
1625 */
1626int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1627
1628/**
1629 * ib_req_notify_cq - Request completion notification on a CQ.
1630 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07001631 * @flags:
1632 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
1633 * to request an event on the next solicited event or next work
1634 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
1635 * may also be |ed in to request a hint about missed events, as
1636 * described below.
1637 *
1638 * Return Value:
1639 * < 0 means an error occurred while requesting notification
1640 * == 0 means notification was requested successfully, and if
1641 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
1642 * were missed and it is safe to wait for another event. In
1643 * this case is it guaranteed that any work completions added
1644 * to the CQ since the last CQ poll will trigger a completion
1645 * notification event.
1646 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
1647 * in. It means that the consumer must poll the CQ again to
1648 * make sure it is empty to avoid missing an event because of a
1649 * race between requesting notification and an entry being
1650 * added to the CQ. This return value means it is possible
1651 * (but not guaranteed) that a work completion has been added
1652 * to the CQ since the last poll without triggering a
1653 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 */
1655static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001656 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
Roland Dreiered23a722007-05-06 21:02:48 -07001658 return cq->device->req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
1661/**
1662 * ib_req_ncomp_notif - Request completion notification when there are
1663 * at least the specified number of unreaped completions on the CQ.
1664 * @cq: The CQ to generate an event for.
1665 * @wc_cnt: The number of unreaped completions that should be on the
1666 * CQ before an event is generated.
1667 */
1668static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1669{
1670 return cq->device->req_ncomp_notif ?
1671 cq->device->req_ncomp_notif(cq, wc_cnt) :
1672 -ENOSYS;
1673}
1674
1675/**
1676 * ib_get_dma_mr - Returns a memory region for system memory that is
1677 * usable for DMA.
1678 * @pd: The protection domain associated with the memory region.
1679 * @mr_access_flags: Specifies the memory access rights.
Ralph Campbell9b513092006-12-12 14:27:41 -08001680 *
1681 * Note that the ib_dma_*() functions defined below must be used
1682 * to create/destroy addresses used with the Lkey or Rkey returned
1683 * by ib_get_dma_mr().
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 */
1685struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1686
1687/**
Ralph Campbell9b513092006-12-12 14:27:41 -08001688 * ib_dma_mapping_error - check a DMA addr for error
1689 * @dev: The device for which the dma_addr was created
1690 * @dma_addr: The DMA address to check
1691 */
1692static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1693{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001694 if (dev->dma_ops)
1695 return dev->dma_ops->mapping_error(dev, dma_addr);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001696 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08001697}
1698
1699/**
1700 * ib_dma_map_single - Map a kernel virtual address to DMA address
1701 * @dev: The device for which the dma_addr is to be created
1702 * @cpu_addr: The kernel virtual address
1703 * @size: The size of the region in bytes
1704 * @direction: The direction of the DMA
1705 */
1706static inline u64 ib_dma_map_single(struct ib_device *dev,
1707 void *cpu_addr, size_t size,
1708 enum dma_data_direction direction)
1709{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001710 if (dev->dma_ops)
1711 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
1712 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001713}
1714
1715/**
1716 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
1717 * @dev: The device for which the DMA address was created
1718 * @addr: The DMA address
1719 * @size: The size of the region in bytes
1720 * @direction: The direction of the DMA
1721 */
1722static inline void ib_dma_unmap_single(struct ib_device *dev,
1723 u64 addr, size_t size,
1724 enum dma_data_direction direction)
1725{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001726 if (dev->dma_ops)
1727 dev->dma_ops->unmap_single(dev, addr, size, direction);
1728 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001729 dma_unmap_single(dev->dma_device, addr, size, direction);
1730}
1731
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07001732static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
1733 void *cpu_addr, size_t size,
1734 enum dma_data_direction direction,
1735 struct dma_attrs *attrs)
1736{
1737 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
1738 direction, attrs);
1739}
1740
1741static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
1742 u64 addr, size_t size,
1743 enum dma_data_direction direction,
1744 struct dma_attrs *attrs)
1745{
1746 return dma_unmap_single_attrs(dev->dma_device, addr, size,
1747 direction, attrs);
1748}
1749
Ralph Campbell9b513092006-12-12 14:27:41 -08001750/**
1751 * ib_dma_map_page - Map a physical page to DMA address
1752 * @dev: The device for which the dma_addr is to be created
1753 * @page: The page to be mapped
1754 * @offset: The offset within the page
1755 * @size: The size of the region in bytes
1756 * @direction: The direction of the DMA
1757 */
1758static inline u64 ib_dma_map_page(struct ib_device *dev,
1759 struct page *page,
1760 unsigned long offset,
1761 size_t size,
1762 enum dma_data_direction direction)
1763{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001764 if (dev->dma_ops)
1765 return dev->dma_ops->map_page(dev, page, offset, size, direction);
1766 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001767}
1768
1769/**
1770 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
1771 * @dev: The device for which the DMA address was created
1772 * @addr: The DMA address
1773 * @size: The size of the region in bytes
1774 * @direction: The direction of the DMA
1775 */
1776static inline void ib_dma_unmap_page(struct ib_device *dev,
1777 u64 addr, size_t size,
1778 enum dma_data_direction direction)
1779{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001780 if (dev->dma_ops)
1781 dev->dma_ops->unmap_page(dev, addr, size, direction);
1782 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001783 dma_unmap_page(dev->dma_device, addr, size, direction);
1784}
1785
1786/**
1787 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
1788 * @dev: The device for which the DMA addresses are to be created
1789 * @sg: The array of scatter/gather entries
1790 * @nents: The number of scatter/gather entries
1791 * @direction: The direction of the DMA
1792 */
1793static inline int ib_dma_map_sg(struct ib_device *dev,
1794 struct scatterlist *sg, int nents,
1795 enum dma_data_direction direction)
1796{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001797 if (dev->dma_ops)
1798 return dev->dma_ops->map_sg(dev, sg, nents, direction);
1799 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001800}
1801
1802/**
1803 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
1804 * @dev: The device for which the DMA addresses were created
1805 * @sg: The array of scatter/gather entries
1806 * @nents: The number of scatter/gather entries
1807 * @direction: The direction of the DMA
1808 */
1809static inline void ib_dma_unmap_sg(struct ib_device *dev,
1810 struct scatterlist *sg, int nents,
1811 enum dma_data_direction direction)
1812{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001813 if (dev->dma_ops)
1814 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
1815 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001816 dma_unmap_sg(dev->dma_device, sg, nents, direction);
1817}
1818
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07001819static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
1820 struct scatterlist *sg, int nents,
1821 enum dma_data_direction direction,
1822 struct dma_attrs *attrs)
1823{
1824 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
1825}
1826
1827static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
1828 struct scatterlist *sg, int nents,
1829 enum dma_data_direction direction,
1830 struct dma_attrs *attrs)
1831{
1832 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
1833}
Ralph Campbell9b513092006-12-12 14:27:41 -08001834/**
1835 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
1836 * @dev: The device for which the DMA addresses were created
1837 * @sg: The scatter/gather entry
1838 */
1839static inline u64 ib_sg_dma_address(struct ib_device *dev,
1840 struct scatterlist *sg)
1841{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001842 if (dev->dma_ops)
1843 return dev->dma_ops->dma_address(dev, sg);
1844 return sg_dma_address(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08001845}
1846
1847/**
1848 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
1849 * @dev: The device for which the DMA addresses were created
1850 * @sg: The scatter/gather entry
1851 */
1852static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
1853 struct scatterlist *sg)
1854{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001855 if (dev->dma_ops)
1856 return dev->dma_ops->dma_len(dev, sg);
1857 return sg_dma_len(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08001858}
1859
1860/**
1861 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
1862 * @dev: The device for which the DMA address was created
1863 * @addr: The DMA address
1864 * @size: The size of the region in bytes
1865 * @dir: The direction of the DMA
1866 */
1867static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
1868 u64 addr,
1869 size_t size,
1870 enum dma_data_direction dir)
1871{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001872 if (dev->dma_ops)
1873 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
1874 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001875 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
1876}
1877
1878/**
1879 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
1880 * @dev: The device for which the DMA address was created
1881 * @addr: The DMA address
1882 * @size: The size of the region in bytes
1883 * @dir: The direction of the DMA
1884 */
1885static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
1886 u64 addr,
1887 size_t size,
1888 enum dma_data_direction dir)
1889{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001890 if (dev->dma_ops)
1891 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
1892 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001893 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
1894}
1895
1896/**
1897 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
1898 * @dev: The device for which the DMA address is requested
1899 * @size: The size of the region to allocate in bytes
1900 * @dma_handle: A pointer for returning the DMA address of the region
1901 * @flag: memory allocator flags
1902 */
1903static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
1904 size_t size,
1905 u64 *dma_handle,
1906 gfp_t flag)
1907{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001908 if (dev->dma_ops)
1909 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Roland Dreierc59a3da2006-12-15 13:57:26 -08001910 else {
1911 dma_addr_t handle;
1912 void *ret;
1913
1914 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
1915 *dma_handle = handle;
1916 return ret;
1917 }
Ralph Campbell9b513092006-12-12 14:27:41 -08001918}
1919
1920/**
1921 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
1922 * @dev: The device for which the DMA addresses were allocated
1923 * @size: The size of the region
1924 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
1925 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
1926 */
1927static inline void ib_dma_free_coherent(struct ib_device *dev,
1928 size_t size, void *cpu_addr,
1929 u64 dma_handle)
1930{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001931 if (dev->dma_ops)
1932 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
1933 else
Ralph Campbell9b513092006-12-12 14:27:41 -08001934 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
1935}
1936
1937/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
1939 * by an HCA.
1940 * @pd: The protection domain associated assigned to the registered region.
1941 * @phys_buf_array: Specifies a list of physical buffers to use in the
1942 * memory region.
1943 * @num_phys_buf: Specifies the size of the phys_buf_array.
1944 * @mr_access_flags: Specifies the memory access rights.
1945 * @iova_start: The offset of the region's starting I/O virtual address.
1946 */
1947struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
1948 struct ib_phys_buf *phys_buf_array,
1949 int num_phys_buf,
1950 int mr_access_flags,
1951 u64 *iova_start);
1952
1953/**
1954 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
1955 * Conceptually, this call performs the functions deregister memory region
1956 * followed by register physical memory region. Where possible,
1957 * resources are reused instead of deallocated and reallocated.
1958 * @mr: The memory region to modify.
1959 * @mr_rereg_mask: A bit-mask used to indicate which of the following
1960 * properties of the memory region are being modified.
1961 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
1962 * the new protection domain to associated with the memory region,
1963 * otherwise, this parameter is ignored.
1964 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1965 * field specifies a list of physical buffers to use in the new
1966 * translation, otherwise, this parameter is ignored.
1967 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1968 * field specifies the size of the phys_buf_array, otherwise, this
1969 * parameter is ignored.
1970 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
1971 * field specifies the new memory access rights, otherwise, this
1972 * parameter is ignored.
1973 * @iova_start: The offset of the region's starting I/O virtual address.
1974 */
1975int ib_rereg_phys_mr(struct ib_mr *mr,
1976 int mr_rereg_mask,
1977 struct ib_pd *pd,
1978 struct ib_phys_buf *phys_buf_array,
1979 int num_phys_buf,
1980 int mr_access_flags,
1981 u64 *iova_start);
1982
1983/**
1984 * ib_query_mr - Retrieves information about a specific memory region.
1985 * @mr: The memory region to retrieve information about.
1986 * @mr_attr: The attributes of the specified memory region.
1987 */
1988int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
1989
1990/**
1991 * ib_dereg_mr - Deregisters a memory region and removes it from the
1992 * HCA translation table.
1993 * @mr: The memory region to deregister.
1994 */
1995int ib_dereg_mr(struct ib_mr *mr);
1996
1997/**
Steve Wise00f7ec32008-07-14 23:48:45 -07001998 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
1999 * IB_WR_FAST_REG_MR send work request.
2000 * @pd: The protection domain associated with the region.
2001 * @max_page_list_len: requested max physical buffer list length to be
2002 * used with fast register work requests for this MR.
2003 */
2004struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2005
2006/**
2007 * ib_alloc_fast_reg_page_list - Allocates a page list array
2008 * @device - ib device pointer.
2009 * @page_list_len - size of the page list array to be allocated.
2010 *
2011 * This allocates and returns a struct ib_fast_reg_page_list * and a
2012 * page_list array that is at least page_list_len in size. The actual
2013 * size is returned in max_page_list_len. The caller is responsible
2014 * for initializing the contents of the page_list array before posting
2015 * a send work request with the IB_WC_FAST_REG_MR opcode.
2016 *
2017 * The page_list array entries must be translated using one of the
2018 * ib_dma_*() functions just like the addresses passed to
2019 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
2020 * ib_fast_reg_page_list must not be modified by the caller until the
2021 * IB_WC_FAST_REG_MR work request completes.
2022 */
2023struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2024 struct ib_device *device, int page_list_len);
2025
2026/**
2027 * ib_free_fast_reg_page_list - Deallocates a previously allocated
2028 * page list array.
2029 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2030 */
2031void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2032
2033/**
2034 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2035 * R_Key and L_Key.
2036 * @mr - struct ib_mr pointer to be updated.
2037 * @newkey - new key to be used.
2038 */
2039static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2040{
2041 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2042 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2043}
2044
2045/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 * ib_alloc_mw - Allocates a memory window.
2047 * @pd: The protection domain associated with the memory window.
2048 */
2049struct ib_mw *ib_alloc_mw(struct ib_pd *pd);
2050
2051/**
2052 * ib_bind_mw - Posts a work request to the send queue of the specified
2053 * QP, which binds the memory window to the given address range and
2054 * remote access attributes.
2055 * @qp: QP to post the bind work request on.
2056 * @mw: The memory window to bind.
2057 * @mw_bind: Specifies information about the memory window, including
2058 * its address range, remote access rights, and associated memory region.
2059 */
2060static inline int ib_bind_mw(struct ib_qp *qp,
2061 struct ib_mw *mw,
2062 struct ib_mw_bind *mw_bind)
2063{
2064 /* XXX reference counting in corresponding MR? */
2065 return mw->device->bind_mw ?
2066 mw->device->bind_mw(qp, mw, mw_bind) :
2067 -ENOSYS;
2068}
2069
2070/**
2071 * ib_dealloc_mw - Deallocates a memory window.
2072 * @mw: The memory window to deallocate.
2073 */
2074int ib_dealloc_mw(struct ib_mw *mw);
2075
2076/**
2077 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2078 * @pd: The protection domain associated with the unmapped region.
2079 * @mr_access_flags: Specifies the memory access rights.
2080 * @fmr_attr: Attributes of the unmapped region.
2081 *
2082 * A fast memory region must be mapped before it can be used as part of
2083 * a work request.
2084 */
2085struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2086 int mr_access_flags,
2087 struct ib_fmr_attr *fmr_attr);
2088
2089/**
2090 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2091 * @fmr: The fast memory region to associate with the pages.
2092 * @page_list: An array of physical pages to map to the fast memory region.
2093 * @list_len: The number of pages in page_list.
2094 * @iova: The I/O virtual address to use with the mapped region.
2095 */
2096static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2097 u64 *page_list, int list_len,
2098 u64 iova)
2099{
2100 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2101}
2102
2103/**
2104 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2105 * @fmr_list: A linked list of fast memory regions to unmap.
2106 */
2107int ib_unmap_fmr(struct list_head *fmr_list);
2108
2109/**
2110 * ib_dealloc_fmr - Deallocates a fast memory region.
2111 * @fmr: The fast memory region to deallocate.
2112 */
2113int ib_dealloc_fmr(struct ib_fmr *fmr);
2114
2115/**
2116 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2117 * @qp: QP to attach to the multicast group. The QP must be type
2118 * IB_QPT_UD.
2119 * @gid: Multicast group GID.
2120 * @lid: Multicast group LID in host byte order.
2121 *
2122 * In order to send and receive multicast packets, subnet
2123 * administration must have created the multicast group and configured
2124 * the fabric appropriately. The port associated with the specified
2125 * QP must also be a member of the multicast group.
2126 */
2127int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2128
2129/**
2130 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2131 * @qp: QP to detach from the multicast group.
2132 * @gid: Multicast group GID.
2133 * @lid: Multicast group LID in host byte order.
2134 */
2135int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2136
Sean Hefty59991f92011-05-23 17:52:46 -07002137/**
2138 * ib_alloc_xrcd - Allocates an XRC domain.
2139 * @device: The device on which to allocate the XRC domain.
2140 */
2141struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2142
2143/**
2144 * ib_dealloc_xrcd - Deallocates an XRC domain.
2145 * @xrcd: The XRC domain to deallocate.
2146 */
2147int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2148
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149#endif /* IB_VERBS_H */