blob: cb12e6a4e55324286f40ac6c260549a2fd501611 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
4 * Copyright (c) 2004 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
Roland Dreier2a1d9b72005-08-10 23:03:10 -07007 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08008 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * This software is available to you under a choice of one of two
11 * licenses. You may choose to be licensed under the terms of the GNU
12 * General Public License (GPL) Version 2, available from the file
13 * COPYING in the main directory of this source tree, or the
14 * OpenIB.org BSD license below:
15 *
16 * Redistribution and use in source and binary forms, with or
17 * without modification, are permitted provided that the following
18 * conditions are met:
19 *
20 * - Redistributions of source code must retain the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer.
23 *
24 * - Redistributions in binary form must reproduce the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer in the documentation and/or other materials
27 * provided with the distribution.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 * SOFTWARE.
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 */
38
39#if !defined(IB_VERBS_H)
40#define IB_VERBS_H
41
42#include <linux/types.h>
43#include <linux/device.h>
Ralph Campbell9b513092006-12-12 14:27:41 -080044#include <linux/mm.h>
45#include <linux/dma-mapping.h>
Michael S. Tsirkin459d6e22007-02-04 14:11:55 -080046#include <linux/kref.h>
Dotan Barakbfb3ea12007-07-31 16:49:15 +030047#include <linux/list.h>
48#include <linux/rwsem.h>
Adrian Bunk87ae9af2007-10-30 10:35:04 +010049#include <linux/scatterlist.h>
Tejun Heof0626712010-10-19 15:24:36 +000050#include <linux/workqueue.h>
Matan Barakdd5f03b2013-12-12 18:03:11 +020051#include <uapi/linux/if_ether.h>
Roland Dreiere2773c02005-07-07 17:57:10 -070052
Arun Sharma600634972011-07-26 16:09:06 -070053#include <linux/atomic.h>
Roland Dreiere2773c02005-07-07 17:57:10 -070054#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Tejun Heof0626712010-10-19 15:24:36 +000056extern struct workqueue_struct *ib_wq;
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058union ib_gid {
59 u8 raw[16];
60 struct {
Sean Hefty97f52eb2005-08-13 21:05:57 -070061 __be64 subnet_prefix;
62 __be64 interface_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 } global;
64};
65
Tom Tucker07ebafb2006-08-03 16:02:42 -050066enum rdma_node_type {
67 /* IB values map to NodeInfo:NodeType. */
68 RDMA_NODE_IB_CA = 1,
69 RDMA_NODE_IB_SWITCH,
70 RDMA_NODE_IB_ROUTER,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000071 RDMA_NODE_RNIC,
72 RDMA_NODE_USNIC,
Upinder Malhi5db57652014-01-15 17:02:36 -080073 RDMA_NODE_USNIC_UDP,
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
75
Tom Tucker07ebafb2006-08-03 16:02:42 -050076enum rdma_transport_type {
77 RDMA_TRANSPORT_IB,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000078 RDMA_TRANSPORT_IWARP,
Upinder Malhi248567f2014-01-09 14:48:19 -080079 RDMA_TRANSPORT_USNIC,
80 RDMA_TRANSPORT_USNIC_UDP
Tom Tucker07ebafb2006-08-03 16:02:42 -050081};
82
83enum rdma_transport_type
84rdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
85
Eli Cohena3f5ada2010-09-27 17:51:10 -070086enum rdma_link_layer {
87 IB_LINK_LAYER_UNSPECIFIED,
88 IB_LINK_LAYER_INFINIBAND,
89 IB_LINK_LAYER_ETHERNET,
90};
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092enum ib_device_cap_flags {
93 IB_DEVICE_RESIZE_MAX_WR = 1,
94 IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
95 IB_DEVICE_BAD_QKEY_CNTR = (1<<2),
96 IB_DEVICE_RAW_MULTI = (1<<3),
97 IB_DEVICE_AUTO_PATH_MIG = (1<<4),
98 IB_DEVICE_CHANGE_PHY_PORT = (1<<5),
99 IB_DEVICE_UD_AV_PORT_ENFORCE = (1<<6),
100 IB_DEVICE_CURR_QP_STATE_MOD = (1<<7),
101 IB_DEVICE_SHUTDOWN_PORT = (1<<8),
102 IB_DEVICE_INIT_TYPE = (1<<9),
103 IB_DEVICE_PORT_ACTIVE_EVENT = (1<<10),
104 IB_DEVICE_SYS_IMAGE_GUID = (1<<11),
105 IB_DEVICE_RC_RNR_NAK_GEN = (1<<12),
106 IB_DEVICE_SRQ_RESIZE = (1<<13),
107 IB_DEVICE_N_NOTIFY_CQ = (1<<14),
Steve Wise96f15c02008-07-14 23:48:53 -0700108 IB_DEVICE_LOCAL_DMA_LKEY = (1<<15),
Roland Dreier0f39cf32008-04-16 21:09:32 -0700109 IB_DEVICE_RESERVED = (1<<16), /* old SEND_W_INV */
Eli Cohene0605d92008-01-30 18:30:57 +0200110 IB_DEVICE_MEM_WINDOW = (1<<17),
111 /*
112 * Devices should set IB_DEVICE_UD_IP_SUM if they support
113 * insertion of UDP and TCP checksum on outgoing UD IPoIB
114 * messages and can verify the validity of checksum for
115 * incoming messages. Setting this flag implies that the
116 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
117 */
118 IB_DEVICE_UD_IP_CSUM = (1<<18),
Eli Cohenc93570f2008-04-16 21:09:27 -0700119 IB_DEVICE_UD_TSO = (1<<19),
Sean Hefty59991f92011-05-23 17:52:46 -0700120 IB_DEVICE_XRC = (1<<20),
Steve Wise00f7ec32008-07-14 23:48:45 -0700121 IB_DEVICE_MEM_MGT_EXTENSIONS = (1<<21),
Ron Livne47ee1b92008-07-14 23:48:48 -0700122 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
Shani Michaeli7083e422013-02-06 16:19:12 +0000123 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1<<23),
Hadar Hen Zion319a4412013-08-07 14:01:59 +0300124 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1<<24),
125 IB_DEVICE_MANAGED_FLOW_STEERING = (1<<29)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
128enum ib_atomic_cap {
129 IB_ATOMIC_NONE,
130 IB_ATOMIC_HCA,
131 IB_ATOMIC_GLOB
132};
133
134struct ib_device_attr {
135 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700136 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 u64 max_mr_size;
138 u64 page_size_cap;
139 u32 vendor_id;
140 u32 vendor_part_id;
141 u32 hw_ver;
142 int max_qp;
143 int max_qp_wr;
144 int device_cap_flags;
145 int max_sge;
146 int max_sge_rd;
147 int max_cq;
148 int max_cqe;
149 int max_mr;
150 int max_pd;
151 int max_qp_rd_atom;
152 int max_ee_rd_atom;
153 int max_res_rd_atom;
154 int max_qp_init_rd_atom;
155 int max_ee_init_rd_atom;
156 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300157 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int max_ee;
159 int max_rdd;
160 int max_mw;
161 int max_raw_ipv6_qp;
162 int max_raw_ethy_qp;
163 int max_mcast_grp;
164 int max_mcast_qp_attach;
165 int max_total_mcast_qp_attach;
166 int max_ah;
167 int max_fmr;
168 int max_map_per_fmr;
169 int max_srq;
170 int max_srq_wr;
171 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700172 unsigned int max_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 u16 max_pkeys;
174 u8 local_ca_ack_delay;
175};
176
177enum ib_mtu {
178 IB_MTU_256 = 1,
179 IB_MTU_512 = 2,
180 IB_MTU_1024 = 3,
181 IB_MTU_2048 = 4,
182 IB_MTU_4096 = 5
183};
184
185static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
186{
187 switch (mtu) {
188 case IB_MTU_256: return 256;
189 case IB_MTU_512: return 512;
190 case IB_MTU_1024: return 1024;
191 case IB_MTU_2048: return 2048;
192 case IB_MTU_4096: return 4096;
193 default: return -1;
194 }
195}
196
197enum ib_port_state {
198 IB_PORT_NOP = 0,
199 IB_PORT_DOWN = 1,
200 IB_PORT_INIT = 2,
201 IB_PORT_ARMED = 3,
202 IB_PORT_ACTIVE = 4,
203 IB_PORT_ACTIVE_DEFER = 5
204};
205
206enum ib_port_cap_flags {
207 IB_PORT_SM = 1 << 1,
208 IB_PORT_NOTICE_SUP = 1 << 2,
209 IB_PORT_TRAP_SUP = 1 << 3,
210 IB_PORT_OPT_IPD_SUP = 1 << 4,
211 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
212 IB_PORT_SL_MAP_SUP = 1 << 6,
213 IB_PORT_MKEY_NVRAM = 1 << 7,
214 IB_PORT_PKEY_NVRAM = 1 << 8,
215 IB_PORT_LED_INFO_SUP = 1 << 9,
216 IB_PORT_SM_DISABLED = 1 << 10,
217 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
218 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300219 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 IB_PORT_CM_SUP = 1 << 16,
221 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
222 IB_PORT_REINIT_SUP = 1 << 18,
223 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
224 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
225 IB_PORT_DR_NOTICE_SUP = 1 << 21,
226 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
227 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
228 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
Moni Shouab4a26a22014-02-09 11:54:34 +0200229 IB_PORT_CLIENT_REG_SUP = 1 << 25,
230 IB_PORT_IP_BASED_GIDS = 1 << 26
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231};
232
233enum ib_port_width {
234 IB_WIDTH_1X = 1,
235 IB_WIDTH_4X = 2,
236 IB_WIDTH_8X = 4,
237 IB_WIDTH_12X = 8
238};
239
240static inline int ib_width_enum_to_int(enum ib_port_width width)
241{
242 switch (width) {
243 case IB_WIDTH_1X: return 1;
244 case IB_WIDTH_4X: return 4;
245 case IB_WIDTH_8X: return 8;
246 case IB_WIDTH_12X: return 12;
247 default: return -1;
248 }
249}
250
Or Gerlitz2e966912012-02-28 18:49:50 +0200251enum ib_port_speed {
252 IB_SPEED_SDR = 1,
253 IB_SPEED_DDR = 2,
254 IB_SPEED_QDR = 4,
255 IB_SPEED_FDR10 = 8,
256 IB_SPEED_FDR = 16,
257 IB_SPEED_EDR = 32
258};
259
Steve Wise7f624d02008-07-14 23:48:48 -0700260struct ib_protocol_stats {
261 /* TBD... */
262};
263
264struct iw_protocol_stats {
265 u64 ipInReceives;
266 u64 ipInHdrErrors;
267 u64 ipInTooBigErrors;
268 u64 ipInNoRoutes;
269 u64 ipInAddrErrors;
270 u64 ipInUnknownProtos;
271 u64 ipInTruncatedPkts;
272 u64 ipInDiscards;
273 u64 ipInDelivers;
274 u64 ipOutForwDatagrams;
275 u64 ipOutRequests;
276 u64 ipOutDiscards;
277 u64 ipOutNoRoutes;
278 u64 ipReasmTimeout;
279 u64 ipReasmReqds;
280 u64 ipReasmOKs;
281 u64 ipReasmFails;
282 u64 ipFragOKs;
283 u64 ipFragFails;
284 u64 ipFragCreates;
285 u64 ipInMcastPkts;
286 u64 ipOutMcastPkts;
287 u64 ipInBcastPkts;
288 u64 ipOutBcastPkts;
289
290 u64 tcpRtoAlgorithm;
291 u64 tcpRtoMin;
292 u64 tcpRtoMax;
293 u64 tcpMaxConn;
294 u64 tcpActiveOpens;
295 u64 tcpPassiveOpens;
296 u64 tcpAttemptFails;
297 u64 tcpEstabResets;
298 u64 tcpCurrEstab;
299 u64 tcpInSegs;
300 u64 tcpOutSegs;
301 u64 tcpRetransSegs;
302 u64 tcpInErrs;
303 u64 tcpOutRsts;
304};
305
306union rdma_protocol_stats {
307 struct ib_protocol_stats ib;
308 struct iw_protocol_stats iw;
309};
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311struct ib_port_attr {
312 enum ib_port_state state;
313 enum ib_mtu max_mtu;
314 enum ib_mtu active_mtu;
315 int gid_tbl_len;
316 u32 port_cap_flags;
317 u32 max_msg_sz;
318 u32 bad_pkey_cntr;
319 u32 qkey_viol_cntr;
320 u16 pkey_tbl_len;
321 u16 lid;
322 u16 sm_lid;
323 u8 lmc;
324 u8 max_vl_num;
325 u8 sm_sl;
326 u8 subnet_timeout;
327 u8 init_type_reply;
328 u8 active_width;
329 u8 active_speed;
330 u8 phys_state;
331};
332
333enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800334 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
335 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336};
337
338struct ib_device_modify {
339 u64 sys_image_guid;
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800340 char node_desc[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341};
342
343enum ib_port_modify_flags {
344 IB_PORT_SHUTDOWN = 1,
345 IB_PORT_INIT_TYPE = (1<<2),
346 IB_PORT_RESET_QKEY_CNTR = (1<<3)
347};
348
349struct ib_port_modify {
350 u32 set_port_cap_mask;
351 u32 clr_port_cap_mask;
352 u8 init_type;
353};
354
355enum ib_event_type {
356 IB_EVENT_CQ_ERR,
357 IB_EVENT_QP_FATAL,
358 IB_EVENT_QP_REQ_ERR,
359 IB_EVENT_QP_ACCESS_ERR,
360 IB_EVENT_COMM_EST,
361 IB_EVENT_SQ_DRAINED,
362 IB_EVENT_PATH_MIG,
363 IB_EVENT_PATH_MIG_ERR,
364 IB_EVENT_DEVICE_FATAL,
365 IB_EVENT_PORT_ACTIVE,
366 IB_EVENT_PORT_ERR,
367 IB_EVENT_LID_CHANGE,
368 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700369 IB_EVENT_SM_CHANGE,
370 IB_EVENT_SRQ_ERR,
371 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700372 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000373 IB_EVENT_CLIENT_REREGISTER,
374 IB_EVENT_GID_CHANGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375};
376
377struct ib_event {
378 struct ib_device *device;
379 union {
380 struct ib_cq *cq;
381 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700382 struct ib_srq *srq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 u8 port_num;
384 } element;
385 enum ib_event_type event;
386};
387
388struct ib_event_handler {
389 struct ib_device *device;
390 void (*handler)(struct ib_event_handler *, struct ib_event *);
391 struct list_head list;
392};
393
394#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
395 do { \
396 (_ptr)->device = _device; \
397 (_ptr)->handler = _handler; \
398 INIT_LIST_HEAD(&(_ptr)->list); \
399 } while (0)
400
401struct ib_global_route {
402 union ib_gid dgid;
403 u32 flow_label;
404 u8 sgid_index;
405 u8 hop_limit;
406 u8 traffic_class;
407};
408
Hal Rosenstock513789e2005-07-27 11:45:34 -0700409struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700410 __be32 version_tclass_flow;
411 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700412 u8 next_hdr;
413 u8 hop_limit;
414 union ib_gid sgid;
415 union ib_gid dgid;
416};
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418enum {
419 IB_MULTICAST_QPN = 0xffffff
420};
421
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800422#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424enum ib_ah_flags {
425 IB_AH_GRH = 1
426};
427
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700428enum ib_rate {
429 IB_RATE_PORT_CURRENT = 0,
430 IB_RATE_2_5_GBPS = 2,
431 IB_RATE_5_GBPS = 5,
432 IB_RATE_10_GBPS = 3,
433 IB_RATE_20_GBPS = 6,
434 IB_RATE_30_GBPS = 4,
435 IB_RATE_40_GBPS = 7,
436 IB_RATE_60_GBPS = 8,
437 IB_RATE_80_GBPS = 9,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300438 IB_RATE_120_GBPS = 10,
439 IB_RATE_14_GBPS = 11,
440 IB_RATE_56_GBPS = 12,
441 IB_RATE_112_GBPS = 13,
442 IB_RATE_168_GBPS = 14,
443 IB_RATE_25_GBPS = 15,
444 IB_RATE_100_GBPS = 16,
445 IB_RATE_200_GBPS = 17,
446 IB_RATE_300_GBPS = 18
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700447};
448
449/**
450 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
451 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
452 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
453 * @rate: rate to convert.
454 */
455int ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
456
457/**
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300458 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
459 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
460 * @rate: rate to convert.
461 */
462int ib_rate_to_mbps(enum ib_rate rate) __attribute_const__;
463
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200464enum ib_mr_create_flags {
465 IB_MR_SIGNATURE_EN = 1,
466};
467
468/**
469 * ib_mr_init_attr - Memory region init attributes passed to routine
470 * ib_create_mr.
471 * @max_reg_descriptors: max number of registration descriptors that
472 * may be used with registration work requests.
473 * @flags: MR creation flags bit mask.
474 */
475struct ib_mr_init_attr {
476 int max_reg_descriptors;
477 u32 flags;
478};
479
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300480/**
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700481 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
482 * enum.
483 * @mult: multiple to convert.
484 */
485enum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487struct ib_ah_attr {
488 struct ib_global_route grh;
489 u16 dlid;
490 u8 sl;
491 u8 src_path_bits;
492 u8 static_rate;
493 u8 ah_flags;
494 u8 port_num;
Matan Barakdd5f03b2013-12-12 18:03:11 +0200495 u8 dmac[ETH_ALEN];
496 u16 vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497};
498
499enum ib_wc_status {
500 IB_WC_SUCCESS,
501 IB_WC_LOC_LEN_ERR,
502 IB_WC_LOC_QP_OP_ERR,
503 IB_WC_LOC_EEC_OP_ERR,
504 IB_WC_LOC_PROT_ERR,
505 IB_WC_WR_FLUSH_ERR,
506 IB_WC_MW_BIND_ERR,
507 IB_WC_BAD_RESP_ERR,
508 IB_WC_LOC_ACCESS_ERR,
509 IB_WC_REM_INV_REQ_ERR,
510 IB_WC_REM_ACCESS_ERR,
511 IB_WC_REM_OP_ERR,
512 IB_WC_RETRY_EXC_ERR,
513 IB_WC_RNR_RETRY_EXC_ERR,
514 IB_WC_LOC_RDD_VIOL_ERR,
515 IB_WC_REM_INV_RD_REQ_ERR,
516 IB_WC_REM_ABORT_ERR,
517 IB_WC_INV_EECN_ERR,
518 IB_WC_INV_EEC_STATE_ERR,
519 IB_WC_FATAL_ERR,
520 IB_WC_RESP_TIMEOUT_ERR,
521 IB_WC_GENERAL_ERR
522};
523
524enum ib_wc_opcode {
525 IB_WC_SEND,
526 IB_WC_RDMA_WRITE,
527 IB_WC_RDMA_READ,
528 IB_WC_COMP_SWAP,
529 IB_WC_FETCH_ADD,
530 IB_WC_BIND_MW,
Eli Cohenc93570f2008-04-16 21:09:27 -0700531 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700532 IB_WC_LOCAL_INV,
533 IB_WC_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300534 IB_WC_MASKED_COMP_SWAP,
535 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536/*
537 * Set value of IB_WC_RECV so consumers can test if a completion is a
538 * receive by testing (opcode & IB_WC_RECV).
539 */
540 IB_WC_RECV = 1 << 7,
541 IB_WC_RECV_RDMA_WITH_IMM
542};
543
544enum ib_wc_flags {
545 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -0700546 IB_WC_WITH_IMM = (1<<1),
547 IB_WC_WITH_INVALIDATE = (1<<2),
Or Gerlitzd927d502012-01-11 19:03:51 +0200548 IB_WC_IP_CSUM_OK = (1<<3),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200549 IB_WC_WITH_SMAC = (1<<4),
550 IB_WC_WITH_VLAN = (1<<5),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551};
552
553struct ib_wc {
554 u64 wr_id;
555 enum ib_wc_status status;
556 enum ib_wc_opcode opcode;
557 u32 vendor_err;
558 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +0200559 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -0700560 union {
561 __be32 imm_data;
562 u32 invalidate_rkey;
563 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 u32 src_qp;
565 int wc_flags;
566 u16 pkey_index;
567 u16 slid;
568 u8 sl;
569 u8 dlid_path_bits;
570 u8 port_num; /* valid only for DR SMPs on switches */
Matan Barakdd5f03b2013-12-12 18:03:11 +0200571 u8 smac[ETH_ALEN];
572 u16 vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573};
574
Roland Dreiered23a722007-05-06 21:02:48 -0700575enum ib_cq_notify_flags {
576 IB_CQ_SOLICITED = 1 << 0,
577 IB_CQ_NEXT_COMP = 1 << 1,
578 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
579 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580};
581
Sean Hefty96104ed2011-05-23 16:31:36 -0700582enum ib_srq_type {
Sean Hefty418d5132011-05-23 19:42:29 -0700583 IB_SRQT_BASIC,
584 IB_SRQT_XRC
Sean Hefty96104ed2011-05-23 16:31:36 -0700585};
586
Roland Dreierd41fcc62005-08-18 12:23:08 -0700587enum ib_srq_attr_mask {
588 IB_SRQ_MAX_WR = 1 << 0,
589 IB_SRQ_LIMIT = 1 << 1,
590};
591
592struct ib_srq_attr {
593 u32 max_wr;
594 u32 max_sge;
595 u32 srq_limit;
596};
597
598struct ib_srq_init_attr {
599 void (*event_handler)(struct ib_event *, void *);
600 void *srq_context;
601 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -0700602 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -0700603
604 union {
605 struct {
606 struct ib_xrcd *xrcd;
607 struct ib_cq *cq;
608 } xrc;
609 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700610};
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612struct ib_qp_cap {
613 u32 max_send_wr;
614 u32 max_recv_wr;
615 u32 max_send_sge;
616 u32 max_recv_sge;
617 u32 max_inline_data;
618};
619
620enum ib_sig_type {
621 IB_SIGNAL_ALL_WR,
622 IB_SIGNAL_REQ_WR
623};
624
625enum ib_qp_type {
626 /*
627 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
628 * here (and in that order) since the MAD layer uses them as
629 * indices into a 2-entry table.
630 */
631 IB_QPT_SMI,
632 IB_QPT_GSI,
633
634 IB_QPT_RC,
635 IB_QPT_UC,
636 IB_QPT_UD,
637 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700638 IB_QPT_RAW_ETHERTYPE,
Or Gerlitzc938a612012-03-01 12:17:51 +0200639 IB_QPT_RAW_PACKET = 8,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700640 IB_QPT_XRC_INI = 9,
641 IB_QPT_XRC_TGT,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300642 IB_QPT_MAX,
643 /* Reserve a range for qp types internal to the low level driver.
644 * These qp types will not be visible at the IB core layer, so the
645 * IB_QPT_MAX usages should not be affected in the core layer
646 */
647 IB_QPT_RESERVED1 = 0x1000,
648 IB_QPT_RESERVED2,
649 IB_QPT_RESERVED3,
650 IB_QPT_RESERVED4,
651 IB_QPT_RESERVED5,
652 IB_QPT_RESERVED6,
653 IB_QPT_RESERVED7,
654 IB_QPT_RESERVED8,
655 IB_QPT_RESERVED9,
656 IB_QPT_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657};
658
Eli Cohenb846f252008-04-16 21:09:27 -0700659enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -0700660 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
661 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
Matan Barak90f1d1b2013-11-07 15:25:12 +0200662 IB_QP_CREATE_NETIF_QP = 1 << 5,
Jack Morgensteind2b57062012-08-03 08:40:37 +0000663 /* reserve bits 26-31 for low level drivers' internal use */
664 IB_QP_CREATE_RESERVED_START = 1 << 26,
665 IB_QP_CREATE_RESERVED_END = 1 << 31,
Eli Cohenb846f252008-04-16 21:09:27 -0700666};
667
Yishai Hadas73c40c62013-08-01 18:49:53 +0300668
669/*
670 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
671 * callback to destroy the passed in QP.
672 */
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674struct ib_qp_init_attr {
675 void (*event_handler)(struct ib_event *, void *);
676 void *qp_context;
677 struct ib_cq *send_cq;
678 struct ib_cq *recv_cq;
679 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700680 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 struct ib_qp_cap cap;
682 enum ib_sig_type sq_sig_type;
683 enum ib_qp_type qp_type;
Eli Cohenb846f252008-04-16 21:09:27 -0700684 enum ib_qp_create_flags create_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 u8 port_num; /* special QP types only */
686};
687
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700688struct ib_qp_open_attr {
689 void (*event_handler)(struct ib_event *, void *);
690 void *qp_context;
691 u32 qp_num;
692 enum ib_qp_type qp_type;
693};
694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695enum ib_rnr_timeout {
696 IB_RNR_TIMER_655_36 = 0,
697 IB_RNR_TIMER_000_01 = 1,
698 IB_RNR_TIMER_000_02 = 2,
699 IB_RNR_TIMER_000_03 = 3,
700 IB_RNR_TIMER_000_04 = 4,
701 IB_RNR_TIMER_000_06 = 5,
702 IB_RNR_TIMER_000_08 = 6,
703 IB_RNR_TIMER_000_12 = 7,
704 IB_RNR_TIMER_000_16 = 8,
705 IB_RNR_TIMER_000_24 = 9,
706 IB_RNR_TIMER_000_32 = 10,
707 IB_RNR_TIMER_000_48 = 11,
708 IB_RNR_TIMER_000_64 = 12,
709 IB_RNR_TIMER_000_96 = 13,
710 IB_RNR_TIMER_001_28 = 14,
711 IB_RNR_TIMER_001_92 = 15,
712 IB_RNR_TIMER_002_56 = 16,
713 IB_RNR_TIMER_003_84 = 17,
714 IB_RNR_TIMER_005_12 = 18,
715 IB_RNR_TIMER_007_68 = 19,
716 IB_RNR_TIMER_010_24 = 20,
717 IB_RNR_TIMER_015_36 = 21,
718 IB_RNR_TIMER_020_48 = 22,
719 IB_RNR_TIMER_030_72 = 23,
720 IB_RNR_TIMER_040_96 = 24,
721 IB_RNR_TIMER_061_44 = 25,
722 IB_RNR_TIMER_081_92 = 26,
723 IB_RNR_TIMER_122_88 = 27,
724 IB_RNR_TIMER_163_84 = 28,
725 IB_RNR_TIMER_245_76 = 29,
726 IB_RNR_TIMER_327_68 = 30,
727 IB_RNR_TIMER_491_52 = 31
728};
729
730enum ib_qp_attr_mask {
731 IB_QP_STATE = 1,
732 IB_QP_CUR_STATE = (1<<1),
733 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
734 IB_QP_ACCESS_FLAGS = (1<<3),
735 IB_QP_PKEY_INDEX = (1<<4),
736 IB_QP_PORT = (1<<5),
737 IB_QP_QKEY = (1<<6),
738 IB_QP_AV = (1<<7),
739 IB_QP_PATH_MTU = (1<<8),
740 IB_QP_TIMEOUT = (1<<9),
741 IB_QP_RETRY_CNT = (1<<10),
742 IB_QP_RNR_RETRY = (1<<11),
743 IB_QP_RQ_PSN = (1<<12),
744 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
745 IB_QP_ALT_PATH = (1<<14),
746 IB_QP_MIN_RNR_TIMER = (1<<15),
747 IB_QP_SQ_PSN = (1<<16),
748 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
749 IB_QP_PATH_MIG_STATE = (1<<18),
750 IB_QP_CAP = (1<<19),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200751 IB_QP_DEST_QPN = (1<<20),
752 IB_QP_SMAC = (1<<21),
753 IB_QP_ALT_SMAC = (1<<22),
754 IB_QP_VID = (1<<23),
755 IB_QP_ALT_VID = (1<<24),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756};
757
758enum ib_qp_state {
759 IB_QPS_RESET,
760 IB_QPS_INIT,
761 IB_QPS_RTR,
762 IB_QPS_RTS,
763 IB_QPS_SQD,
764 IB_QPS_SQE,
765 IB_QPS_ERR
766};
767
768enum ib_mig_state {
769 IB_MIG_MIGRATED,
770 IB_MIG_REARM,
771 IB_MIG_ARMED
772};
773
Shani Michaeli7083e422013-02-06 16:19:12 +0000774enum ib_mw_type {
775 IB_MW_TYPE_1 = 1,
776 IB_MW_TYPE_2 = 2
777};
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779struct ib_qp_attr {
780 enum ib_qp_state qp_state;
781 enum ib_qp_state cur_qp_state;
782 enum ib_mtu path_mtu;
783 enum ib_mig_state path_mig_state;
784 u32 qkey;
785 u32 rq_psn;
786 u32 sq_psn;
787 u32 dest_qp_num;
788 int qp_access_flags;
789 struct ib_qp_cap cap;
790 struct ib_ah_attr ah_attr;
791 struct ib_ah_attr alt_ah_attr;
792 u16 pkey_index;
793 u16 alt_pkey_index;
794 u8 en_sqd_async_notify;
795 u8 sq_draining;
796 u8 max_rd_atomic;
797 u8 max_dest_rd_atomic;
798 u8 min_rnr_timer;
799 u8 port_num;
800 u8 timeout;
801 u8 retry_cnt;
802 u8 rnr_retry;
803 u8 alt_port_num;
804 u8 alt_timeout;
Matan Barakdd5f03b2013-12-12 18:03:11 +0200805 u8 smac[ETH_ALEN];
806 u8 alt_smac[ETH_ALEN];
807 u16 vlan_id;
808 u16 alt_vlan_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809};
810
811enum ib_wr_opcode {
812 IB_WR_RDMA_WRITE,
813 IB_WR_RDMA_WRITE_WITH_IMM,
814 IB_WR_SEND,
815 IB_WR_SEND_WITH_IMM,
816 IB_WR_RDMA_READ,
817 IB_WR_ATOMIC_CMP_AND_SWP,
Eli Cohenc93570f2008-04-16 21:09:27 -0700818 IB_WR_ATOMIC_FETCH_AND_ADD,
Roland Dreier0f39cf32008-04-16 21:09:32 -0700819 IB_WR_LSO,
820 IB_WR_SEND_WITH_INV,
Steve Wise00f7ec32008-07-14 23:48:45 -0700821 IB_WR_RDMA_READ_WITH_INV,
822 IB_WR_LOCAL_INV,
823 IB_WR_FAST_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300824 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
825 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
Shani Michaeli7083e422013-02-06 16:19:12 +0000826 IB_WR_BIND_MW,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300827 /* reserve values for low level drivers' internal use.
828 * These values will not be used at all in the ib core layer.
829 */
830 IB_WR_RESERVED1 = 0xf0,
831 IB_WR_RESERVED2,
832 IB_WR_RESERVED3,
833 IB_WR_RESERVED4,
834 IB_WR_RESERVED5,
835 IB_WR_RESERVED6,
836 IB_WR_RESERVED7,
837 IB_WR_RESERVED8,
838 IB_WR_RESERVED9,
839 IB_WR_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840};
841
842enum ib_send_flags {
843 IB_SEND_FENCE = 1,
844 IB_SEND_SIGNALED = (1<<1),
845 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +0200846 IB_SEND_INLINE = (1<<3),
Jack Morgenstein0134f162013-07-07 17:25:52 +0300847 IB_SEND_IP_CSUM = (1<<4),
848
849 /* reserve bits 26-31 for low level drivers' internal use */
850 IB_SEND_RESERVED_START = (1 << 26),
851 IB_SEND_RESERVED_END = (1 << 31),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852};
853
854struct ib_sge {
855 u64 addr;
856 u32 length;
857 u32 lkey;
858};
859
Steve Wise00f7ec32008-07-14 23:48:45 -0700860struct ib_fast_reg_page_list {
861 struct ib_device *device;
862 u64 *page_list;
863 unsigned int max_page_list_len;
864};
865
Shani Michaeli7083e422013-02-06 16:19:12 +0000866/**
867 * struct ib_mw_bind_info - Parameters for a memory window bind operation.
868 * @mr: A memory region to bind the memory window to.
869 * @addr: The address where the memory window should begin.
870 * @length: The length of the memory window, in bytes.
871 * @mw_access_flags: Access flags from enum ib_access_flags for the window.
872 *
873 * This struct contains the shared parameters for type 1 and type 2
874 * memory window bind operations.
875 */
876struct ib_mw_bind_info {
877 struct ib_mr *mr;
878 u64 addr;
879 u64 length;
880 int mw_access_flags;
881};
882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883struct ib_send_wr {
884 struct ib_send_wr *next;
885 u64 wr_id;
886 struct ib_sge *sg_list;
887 int num_sge;
888 enum ib_wr_opcode opcode;
889 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -0700890 union {
891 __be32 imm_data;
892 u32 invalidate_rkey;
893 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 union {
895 struct {
896 u64 remote_addr;
897 u32 rkey;
898 } rdma;
899 struct {
900 u64 remote_addr;
901 u64 compare_add;
902 u64 swap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300903 u64 compare_add_mask;
904 u64 swap_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 u32 rkey;
906 } atomic;
907 struct {
908 struct ib_ah *ah;
Eli Cohenc93570f2008-04-16 21:09:27 -0700909 void *header;
910 int hlen;
911 int mss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 u32 remote_qpn;
913 u32 remote_qkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 u16 pkey_index; /* valid for GSI only */
915 u8 port_num; /* valid for DR SMPs on switch only */
916 } ud;
Steve Wise00f7ec32008-07-14 23:48:45 -0700917 struct {
918 u64 iova_start;
919 struct ib_fast_reg_page_list *page_list;
920 unsigned int page_shift;
921 unsigned int page_list_len;
922 u32 length;
923 int access_flags;
924 u32 rkey;
925 } fast_reg;
Shani Michaeli7083e422013-02-06 16:19:12 +0000926 struct {
927 struct ib_mw *mw;
928 /* The new rkey for the memory window. */
929 u32 rkey;
930 struct ib_mw_bind_info bind_info;
931 } bind_mw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 } wr;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700933 u32 xrc_remote_srq_num; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934};
935
936struct ib_recv_wr {
937 struct ib_recv_wr *next;
938 u64 wr_id;
939 struct ib_sge *sg_list;
940 int num_sge;
941};
942
943enum ib_access_flags {
944 IB_ACCESS_LOCAL_WRITE = 1,
945 IB_ACCESS_REMOTE_WRITE = (1<<1),
946 IB_ACCESS_REMOTE_READ = (1<<2),
947 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
Shani Michaeli7083e422013-02-06 16:19:12 +0000948 IB_ACCESS_MW_BIND = (1<<4),
949 IB_ZERO_BASED = (1<<5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950};
951
952struct ib_phys_buf {
953 u64 addr;
954 u64 size;
955};
956
957struct ib_mr_attr {
958 struct ib_pd *pd;
959 u64 device_virt_addr;
960 u64 size;
961 int mr_access_flags;
962 u32 lkey;
963 u32 rkey;
964};
965
966enum ib_mr_rereg_flags {
967 IB_MR_REREG_TRANS = 1,
968 IB_MR_REREG_PD = (1<<1),
969 IB_MR_REREG_ACCESS = (1<<2)
970};
971
Shani Michaeli7083e422013-02-06 16:19:12 +0000972/**
973 * struct ib_mw_bind - Parameters for a type 1 memory window bind operation.
974 * @wr_id: Work request id.
975 * @send_flags: Flags from ib_send_flags enum.
976 * @bind_info: More parameters of the bind operation.
977 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978struct ib_mw_bind {
Shani Michaeli7083e422013-02-06 16:19:12 +0000979 u64 wr_id;
980 int send_flags;
981 struct ib_mw_bind_info bind_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982};
983
984struct ib_fmr_attr {
985 int max_pages;
986 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -0800987 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988};
989
Roland Dreiere2773c02005-07-07 17:57:10 -0700990struct ib_ucontext {
991 struct ib_device *device;
992 struct list_head pd_list;
993 struct list_head mr_list;
994 struct list_head mw_list;
995 struct list_head cq_list;
996 struct list_head qp_list;
997 struct list_head srq_list;
998 struct list_head ah_list;
Sean Hefty53d0bd12011-05-24 08:33:46 -0700999 struct list_head xrcd_list;
Hadar Hen Zion436f2ad2013-08-14 13:58:30 +03001000 struct list_head rule_list;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001001 int closing;
Roland Dreiere2773c02005-07-07 17:57:10 -07001002};
1003
1004struct ib_uobject {
1005 u64 user_handle; /* handle given to us by userspace */
1006 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -07001007 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -07001008 struct list_head list; /* link to context's list */
Roland Dreierb3d636b2008-04-16 21:01:06 -07001009 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -07001010 struct kref ref;
1011 struct rw_semaphore mutex; /* protects .live */
1012 int live;
Roland Dreiere2773c02005-07-07 17:57:10 -07001013};
1014
Roland Dreiere2773c02005-07-07 17:57:10 -07001015struct ib_udata {
Yann Droneaud309243e2013-12-11 23:01:44 +01001016 const void __user *inbuf;
Roland Dreiere2773c02005-07-07 17:57:10 -07001017 void __user *outbuf;
1018 size_t inlen;
1019 size_t outlen;
1020};
1021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022struct ib_pd {
Roland Dreiere2773c02005-07-07 17:57:10 -07001023 struct ib_device *device;
1024 struct ib_uobject *uobject;
1025 atomic_t usecnt; /* count all resources */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026};
1027
Sean Hefty59991f92011-05-23 17:52:46 -07001028struct ib_xrcd {
1029 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001030 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -07001031 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001032
1033 struct mutex tgt_qp_mutex;
1034 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -07001035};
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037struct ib_ah {
1038 struct ib_device *device;
1039 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001040 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041};
1042
1043typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1044
1045struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -07001046 struct ib_device *device;
1047 struct ib_uobject *uobject;
1048 ib_comp_handler comp_handler;
1049 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -07001050 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -07001051 int cqe;
1052 atomic_t usecnt; /* count number of work queues */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053};
1054
1055struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -07001056 struct ib_device *device;
1057 struct ib_pd *pd;
1058 struct ib_uobject *uobject;
1059 void (*event_handler)(struct ib_event *, void *);
1060 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -07001061 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -07001063
1064 union {
1065 struct {
1066 struct ib_xrcd *xrcd;
1067 struct ib_cq *cq;
1068 u32 srq_num;
1069 } xrc;
1070 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071};
1072
1073struct ib_qp {
1074 struct ib_device *device;
1075 struct ib_pd *pd;
1076 struct ib_cq *send_cq;
1077 struct ib_cq *recv_cq;
1078 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001079 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -07001080 struct list_head xrcd_list;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001081 /* count times opened, mcast attaches, flow attaches */
1082 atomic_t usecnt;
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001083 struct list_head open_list;
1084 struct ib_qp *real_qp;
Roland Dreiere2773c02005-07-07 17:57:10 -07001085 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 void (*event_handler)(struct ib_event *, void *);
1087 void *qp_context;
1088 u32 qp_num;
1089 enum ib_qp_type qp_type;
1090};
1091
1092struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -07001093 struct ib_device *device;
1094 struct ib_pd *pd;
1095 struct ib_uobject *uobject;
1096 u32 lkey;
1097 u32 rkey;
1098 atomic_t usecnt; /* count number of MWs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099};
1100
1101struct ib_mw {
1102 struct ib_device *device;
1103 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001104 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 u32 rkey;
Shani Michaeli7083e422013-02-06 16:19:12 +00001106 enum ib_mw_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107};
1108
1109struct ib_fmr {
1110 struct ib_device *device;
1111 struct ib_pd *pd;
1112 struct list_head list;
1113 u32 lkey;
1114 u32 rkey;
1115};
1116
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001117/* Supported steering options */
1118enum ib_flow_attr_type {
1119 /* steering according to rule specifications */
1120 IB_FLOW_ATTR_NORMAL = 0x0,
1121 /* default unicast and multicast rule -
1122 * receive all Eth traffic which isn't steered to any QP
1123 */
1124 IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1125 /* default multicast rule -
1126 * receive all Eth multicast traffic which isn't steered to any QP
1127 */
1128 IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1129 /* sniffer rule - receive all port traffic */
1130 IB_FLOW_ATTR_SNIFFER = 0x3
1131};
1132
1133/* Supported steering header types */
1134enum ib_flow_spec_type {
1135 /* L2 headers*/
1136 IB_FLOW_SPEC_ETH = 0x20,
Matan Barak240ae002013-11-07 15:25:13 +02001137 IB_FLOW_SPEC_IB = 0x22,
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001138 /* L3 header*/
1139 IB_FLOW_SPEC_IPV4 = 0x30,
1140 /* L4 headers*/
1141 IB_FLOW_SPEC_TCP = 0x40,
1142 IB_FLOW_SPEC_UDP = 0x41
1143};
Matan Barak240ae002013-11-07 15:25:13 +02001144#define IB_FLOW_SPEC_LAYER_MASK 0xF0
Matan Barak22878db2013-09-01 18:39:52 +03001145#define IB_FLOW_SPEC_SUPPORT_LAYERS 4
1146
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001147/* Flow steering rule priority is set according to it's domain.
1148 * Lower domain value means higher priority.
1149 */
1150enum ib_flow_domain {
1151 IB_FLOW_DOMAIN_USER,
1152 IB_FLOW_DOMAIN_ETHTOOL,
1153 IB_FLOW_DOMAIN_RFS,
1154 IB_FLOW_DOMAIN_NIC,
1155 IB_FLOW_DOMAIN_NUM /* Must be last */
1156};
1157
1158struct ib_flow_eth_filter {
1159 u8 dst_mac[6];
1160 u8 src_mac[6];
1161 __be16 ether_type;
1162 __be16 vlan_tag;
1163};
1164
1165struct ib_flow_spec_eth {
1166 enum ib_flow_spec_type type;
1167 u16 size;
1168 struct ib_flow_eth_filter val;
1169 struct ib_flow_eth_filter mask;
1170};
1171
Matan Barak240ae002013-11-07 15:25:13 +02001172struct ib_flow_ib_filter {
1173 __be16 dlid;
1174 __u8 sl;
1175};
1176
1177struct ib_flow_spec_ib {
1178 enum ib_flow_spec_type type;
1179 u16 size;
1180 struct ib_flow_ib_filter val;
1181 struct ib_flow_ib_filter mask;
1182};
1183
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001184struct ib_flow_ipv4_filter {
1185 __be32 src_ip;
1186 __be32 dst_ip;
1187};
1188
1189struct ib_flow_spec_ipv4 {
1190 enum ib_flow_spec_type type;
1191 u16 size;
1192 struct ib_flow_ipv4_filter val;
1193 struct ib_flow_ipv4_filter mask;
1194};
1195
1196struct ib_flow_tcp_udp_filter {
1197 __be16 dst_port;
1198 __be16 src_port;
1199};
1200
1201struct ib_flow_spec_tcp_udp {
1202 enum ib_flow_spec_type type;
1203 u16 size;
1204 struct ib_flow_tcp_udp_filter val;
1205 struct ib_flow_tcp_udp_filter mask;
1206};
1207
1208union ib_flow_spec {
1209 struct {
1210 enum ib_flow_spec_type type;
1211 u16 size;
1212 };
1213 struct ib_flow_spec_eth eth;
Matan Barak240ae002013-11-07 15:25:13 +02001214 struct ib_flow_spec_ib ib;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001215 struct ib_flow_spec_ipv4 ipv4;
1216 struct ib_flow_spec_tcp_udp tcp_udp;
1217};
1218
1219struct ib_flow_attr {
1220 enum ib_flow_attr_type type;
1221 u16 size;
1222 u16 priority;
1223 u32 flags;
1224 u8 num_of_specs;
1225 u8 port;
1226 /* Following are the optional layers according to user request
1227 * struct ib_flow_spec_xxx
1228 * struct ib_flow_spec_yyy
1229 */
1230};
1231
1232struct ib_flow {
1233 struct ib_qp *qp;
1234 struct ib_uobject *uobject;
1235};
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237struct ib_mad;
1238struct ib_grh;
1239
1240enum ib_process_mad_flags {
1241 IB_MAD_IGNORE_MKEY = 1,
1242 IB_MAD_IGNORE_BKEY = 2,
1243 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1244};
1245
1246enum ib_mad_result {
1247 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
1248 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
1249 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
1250 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
1251};
1252
1253#define IB_DEVICE_NAME_MAX 64
1254
1255struct ib_cache {
1256 rwlock_t lock;
1257 struct ib_event_handler event_handler;
1258 struct ib_pkey_cache **pkey_cache;
1259 struct ib_gid_cache **gid_cache;
Jack Morgenstein6fb9cdb2006-06-17 20:37:34 -07001260 u8 *lmc_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261};
1262
Ralph Campbell9b513092006-12-12 14:27:41 -08001263struct ib_dma_mapping_ops {
1264 int (*mapping_error)(struct ib_device *dev,
1265 u64 dma_addr);
1266 u64 (*map_single)(struct ib_device *dev,
1267 void *ptr, size_t size,
1268 enum dma_data_direction direction);
1269 void (*unmap_single)(struct ib_device *dev,
1270 u64 addr, size_t size,
1271 enum dma_data_direction direction);
1272 u64 (*map_page)(struct ib_device *dev,
1273 struct page *page, unsigned long offset,
1274 size_t size,
1275 enum dma_data_direction direction);
1276 void (*unmap_page)(struct ib_device *dev,
1277 u64 addr, size_t size,
1278 enum dma_data_direction direction);
1279 int (*map_sg)(struct ib_device *dev,
1280 struct scatterlist *sg, int nents,
1281 enum dma_data_direction direction);
1282 void (*unmap_sg)(struct ib_device *dev,
1283 struct scatterlist *sg, int nents,
1284 enum dma_data_direction direction);
1285 u64 (*dma_address)(struct ib_device *dev,
1286 struct scatterlist *sg);
1287 unsigned int (*dma_len)(struct ib_device *dev,
1288 struct scatterlist *sg);
1289 void (*sync_single_for_cpu)(struct ib_device *dev,
1290 u64 dma_handle,
1291 size_t size,
Dotan Barak4deccd62008-07-14 23:48:44 -07001292 enum dma_data_direction dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08001293 void (*sync_single_for_device)(struct ib_device *dev,
1294 u64 dma_handle,
1295 size_t size,
1296 enum dma_data_direction dir);
1297 void *(*alloc_coherent)(struct ib_device *dev,
1298 size_t size,
1299 u64 *dma_handle,
1300 gfp_t flag);
1301 void (*free_coherent)(struct ib_device *dev,
1302 size_t size, void *cpu_addr,
1303 u64 dma_handle);
1304};
1305
Tom Tucker07ebafb2006-08-03 16:02:42 -05001306struct iw_cm_verbs;
1307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308struct ib_device {
1309 struct device *dma_device;
1310
1311 char name[IB_DEVICE_NAME_MAX];
1312
1313 struct list_head event_handler_list;
1314 spinlock_t event_handler_lock;
1315
Alexander Chiang17a55f72010-02-02 19:09:16 +00001316 spinlock_t client_data_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 struct list_head core_list;
1318 struct list_head client_data_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 struct ib_cache cache;
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001321 int *pkey_tbl_len;
1322 int *gid_tbl_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001324 int num_comp_vectors;
1325
Tom Tucker07ebafb2006-08-03 16:02:42 -05001326 struct iw_cm_verbs *iwcm;
1327
Steve Wise7f624d02008-07-14 23:48:48 -07001328 int (*get_protocol_stats)(struct ib_device *device,
1329 union rdma_protocol_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 int (*query_device)(struct ib_device *device,
1331 struct ib_device_attr *device_attr);
1332 int (*query_port)(struct ib_device *device,
1333 u8 port_num,
1334 struct ib_port_attr *port_attr);
Eli Cohena3f5ada2010-09-27 17:51:10 -07001335 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1336 u8 port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 int (*query_gid)(struct ib_device *device,
1338 u8 port_num, int index,
1339 union ib_gid *gid);
1340 int (*query_pkey)(struct ib_device *device,
1341 u8 port_num, u16 index, u16 *pkey);
1342 int (*modify_device)(struct ib_device *device,
1343 int device_modify_mask,
1344 struct ib_device_modify *device_modify);
1345 int (*modify_port)(struct ib_device *device,
1346 u8 port_num, int port_modify_mask,
1347 struct ib_port_modify *port_modify);
Roland Dreiere2773c02005-07-07 17:57:10 -07001348 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1349 struct ib_udata *udata);
1350 int (*dealloc_ucontext)(struct ib_ucontext *context);
1351 int (*mmap)(struct ib_ucontext *context,
1352 struct vm_area_struct *vma);
1353 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1354 struct ib_ucontext *context,
1355 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 int (*dealloc_pd)(struct ib_pd *pd);
1357 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1358 struct ib_ah_attr *ah_attr);
1359 int (*modify_ah)(struct ib_ah *ah,
1360 struct ib_ah_attr *ah_attr);
1361 int (*query_ah)(struct ib_ah *ah,
1362 struct ib_ah_attr *ah_attr);
1363 int (*destroy_ah)(struct ib_ah *ah);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001364 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1365 struct ib_srq_init_attr *srq_init_attr,
1366 struct ib_udata *udata);
1367 int (*modify_srq)(struct ib_srq *srq,
1368 struct ib_srq_attr *srq_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001369 enum ib_srq_attr_mask srq_attr_mask,
1370 struct ib_udata *udata);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001371 int (*query_srq)(struct ib_srq *srq,
1372 struct ib_srq_attr *srq_attr);
1373 int (*destroy_srq)(struct ib_srq *srq);
1374 int (*post_srq_recv)(struct ib_srq *srq,
1375 struct ib_recv_wr *recv_wr,
1376 struct ib_recv_wr **bad_recv_wr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 struct ib_qp * (*create_qp)(struct ib_pd *pd,
Roland Dreiere2773c02005-07-07 17:57:10 -07001378 struct ib_qp_init_attr *qp_init_attr,
1379 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 int (*modify_qp)(struct ib_qp *qp,
1381 struct ib_qp_attr *qp_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001382 int qp_attr_mask,
1383 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 int (*query_qp)(struct ib_qp *qp,
1385 struct ib_qp_attr *qp_attr,
1386 int qp_attr_mask,
1387 struct ib_qp_init_attr *qp_init_attr);
1388 int (*destroy_qp)(struct ib_qp *qp);
1389 int (*post_send)(struct ib_qp *qp,
1390 struct ib_send_wr *send_wr,
1391 struct ib_send_wr **bad_send_wr);
1392 int (*post_recv)(struct ib_qp *qp,
1393 struct ib_recv_wr *recv_wr,
1394 struct ib_recv_wr **bad_recv_wr);
Roland Dreiere2773c02005-07-07 17:57:10 -07001395 struct ib_cq * (*create_cq)(struct ib_device *device, int cqe,
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001396 int comp_vector,
Roland Dreiere2773c02005-07-07 17:57:10 -07001397 struct ib_ucontext *context,
1398 struct ib_udata *udata);
Eli Cohen2dd57162008-04-16 21:09:33 -07001399 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1400 u16 cq_period);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 int (*destroy_cq)(struct ib_cq *cq);
Roland Dreier33b9b3e2006-01-30 14:29:21 -08001402 int (*resize_cq)(struct ib_cq *cq, int cqe,
1403 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1405 struct ib_wc *wc);
1406 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1407 int (*req_notify_cq)(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001408 enum ib_cq_notify_flags flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 int (*req_ncomp_notif)(struct ib_cq *cq,
1410 int wc_cnt);
1411 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1412 int mr_access_flags);
1413 struct ib_mr * (*reg_phys_mr)(struct ib_pd *pd,
1414 struct ib_phys_buf *phys_buf_array,
1415 int num_phys_buf,
1416 int mr_access_flags,
1417 u64 *iova_start);
Roland Dreiere2773c02005-07-07 17:57:10 -07001418 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001419 u64 start, u64 length,
1420 u64 virt_addr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001421 int mr_access_flags,
1422 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 int (*query_mr)(struct ib_mr *mr,
1424 struct ib_mr_attr *mr_attr);
1425 int (*dereg_mr)(struct ib_mr *mr);
Sagi Grimberg17cd3a22014-02-23 14:19:04 +02001426 int (*destroy_mr)(struct ib_mr *mr);
1427 struct ib_mr * (*create_mr)(struct ib_pd *pd,
1428 struct ib_mr_init_attr *mr_init_attr);
Steve Wise00f7ec32008-07-14 23:48:45 -07001429 struct ib_mr * (*alloc_fast_reg_mr)(struct ib_pd *pd,
1430 int max_page_list_len);
1431 struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1432 int page_list_len);
1433 void (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 int (*rereg_phys_mr)(struct ib_mr *mr,
1435 int mr_rereg_mask,
1436 struct ib_pd *pd,
1437 struct ib_phys_buf *phys_buf_array,
1438 int num_phys_buf,
1439 int mr_access_flags,
1440 u64 *iova_start);
Shani Michaeli7083e422013-02-06 16:19:12 +00001441 struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
1442 enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 int (*bind_mw)(struct ib_qp *qp,
1444 struct ib_mw *mw,
1445 struct ib_mw_bind *mw_bind);
1446 int (*dealloc_mw)(struct ib_mw *mw);
1447 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1448 int mr_access_flags,
1449 struct ib_fmr_attr *fmr_attr);
1450 int (*map_phys_fmr)(struct ib_fmr *fmr,
1451 u64 *page_list, int list_len,
1452 u64 iova);
1453 int (*unmap_fmr)(struct list_head *fmr_list);
1454 int (*dealloc_fmr)(struct ib_fmr *fmr);
1455 int (*attach_mcast)(struct ib_qp *qp,
1456 union ib_gid *gid,
1457 u16 lid);
1458 int (*detach_mcast)(struct ib_qp *qp,
1459 union ib_gid *gid,
1460 u16 lid);
1461 int (*process_mad)(struct ib_device *device,
1462 int process_mad_flags,
1463 u8 port_num,
1464 struct ib_wc *in_wc,
1465 struct ib_grh *in_grh,
1466 struct ib_mad *in_mad,
1467 struct ib_mad *out_mad);
Sean Hefty59991f92011-05-23 17:52:46 -07001468 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1469 struct ib_ucontext *ucontext,
1470 struct ib_udata *udata);
1471 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001472 struct ib_flow * (*create_flow)(struct ib_qp *qp,
1473 struct ib_flow_attr
1474 *flow_attr,
1475 int domain);
1476 int (*destroy_flow)(struct ib_flow *flow_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Ralph Campbell9b513092006-12-12 14:27:41 -08001478 struct ib_dma_mapping_ops *dma_ops;
1479
Roland Dreiere2773c02005-07-07 17:57:10 -07001480 struct module *owner;
Tony Jonesf4e91eb2008-02-22 00:13:36 +01001481 struct device dev;
Greg Kroah-Hartman35be0682007-12-17 15:54:39 -04001482 struct kobject *ports_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 struct list_head port_list;
1484
1485 enum {
1486 IB_DEV_UNINITIALIZED,
1487 IB_DEV_REGISTERED,
1488 IB_DEV_UNREGISTERED
1489 } reg_state;
1490
Roland Dreier274c0892005-09-29 14:17:48 -07001491 int uverbs_abi_ver;
Alexander Chiang17a55f72010-02-02 19:09:16 +00001492 u64 uverbs_cmd_mask;
Yann Droneaudf21519b2013-11-06 23:21:49 +01001493 u64 uverbs_ex_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07001494
Roland Dreierc5bcbbb2006-02-02 09:47:14 -08001495 char node_desc[64];
Sean Heftycf311cd2006-01-10 07:39:34 -08001496 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07001497 u32 local_dma_lkey;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 u8 node_type;
1499 u8 phys_port_cnt;
1500};
1501
1502struct ib_client {
1503 char *name;
1504 void (*add) (struct ib_device *);
1505 void (*remove)(struct ib_device *);
1506
1507 struct list_head list;
1508};
1509
1510struct ib_device *ib_alloc_device(size_t size);
1511void ib_dealloc_device(struct ib_device *device);
1512
Ralph Campbell9a6edb62010-05-06 17:03:25 -07001513int ib_register_device(struct ib_device *device,
1514 int (*port_callback)(struct ib_device *,
1515 u8, struct kobject *));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516void ib_unregister_device(struct ib_device *device);
1517
1518int ib_register_client (struct ib_client *client);
1519void ib_unregister_client(struct ib_client *client);
1520
1521void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1522void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1523 void *data);
1524
Roland Dreiere2773c02005-07-07 17:57:10 -07001525static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1526{
1527 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1528}
1529
1530static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1531{
1532 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1533}
1534
Roland Dreier8a518662006-02-13 12:48:12 -08001535/**
1536 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1537 * contains all required attributes and no attributes not allowed for
1538 * the given QP state transition.
1539 * @cur_state: Current QP state
1540 * @next_state: Next QP state
1541 * @type: QP type
1542 * @mask: Mask of supplied QP attributes
Matan Barakdd5f03b2013-12-12 18:03:11 +02001543 * @ll : link layer of port
Roland Dreier8a518662006-02-13 12:48:12 -08001544 *
1545 * This function is a helper function that a low-level driver's
1546 * modify_qp method can use to validate the consumer's input. It
1547 * checks that cur_state and next_state are valid QP states, that a
1548 * transition from cur_state to next_state is allowed by the IB spec,
1549 * and that the attribute mask supplied is allowed for the transition.
1550 */
1551int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
Matan Barakdd5f03b2013-12-12 18:03:11 +02001552 enum ib_qp_type type, enum ib_qp_attr_mask mask,
1553 enum rdma_link_layer ll);
Roland Dreier8a518662006-02-13 12:48:12 -08001554
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555int ib_register_event_handler (struct ib_event_handler *event_handler);
1556int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1557void ib_dispatch_event(struct ib_event *event);
1558
1559int ib_query_device(struct ib_device *device,
1560 struct ib_device_attr *device_attr);
1561
1562int ib_query_port(struct ib_device *device,
1563 u8 port_num, struct ib_port_attr *port_attr);
1564
Eli Cohena3f5ada2010-09-27 17:51:10 -07001565enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1566 u8 port_num);
1567
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568int ib_query_gid(struct ib_device *device,
1569 u8 port_num, int index, union ib_gid *gid);
1570
1571int ib_query_pkey(struct ib_device *device,
1572 u8 port_num, u16 index, u16 *pkey);
1573
1574int ib_modify_device(struct ib_device *device,
1575 int device_modify_mask,
1576 struct ib_device_modify *device_modify);
1577
1578int ib_modify_port(struct ib_device *device,
1579 u8 port_num, int port_modify_mask,
1580 struct ib_port_modify *port_modify);
1581
Yosef Etigin5eb620c2007-05-14 07:26:51 +03001582int ib_find_gid(struct ib_device *device, union ib_gid *gid,
1583 u8 *port_num, u16 *index);
1584
1585int ib_find_pkey(struct ib_device *device,
1586 u8 port_num, u16 pkey, u16 *index);
1587
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588/**
1589 * ib_alloc_pd - Allocates an unused protection domain.
1590 * @device: The device on which to allocate the protection domain.
1591 *
1592 * A protection domain object provides an association between QPs, shared
1593 * receive queues, address handles, memory regions, and memory windows.
1594 */
1595struct ib_pd *ib_alloc_pd(struct ib_device *device);
1596
1597/**
1598 * ib_dealloc_pd - Deallocates a protection domain.
1599 * @pd: The protection domain to deallocate.
1600 */
1601int ib_dealloc_pd(struct ib_pd *pd);
1602
1603/**
1604 * ib_create_ah - Creates an address handle for the given address vector.
1605 * @pd: The protection domain associated with the address handle.
1606 * @ah_attr: The attributes of the address vector.
1607 *
1608 * The address handle is used to reference a local or global destination
1609 * in all UD QP post sends.
1610 */
1611struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1612
1613/**
Sean Hefty4e00d692006-06-17 20:37:39 -07001614 * ib_init_ah_from_wc - Initializes address handle attributes from a
1615 * work completion.
1616 * @device: Device on which the received message arrived.
1617 * @port_num: Port on which the received message arrived.
1618 * @wc: Work completion associated with the received message.
1619 * @grh: References the received global route header. This parameter is
1620 * ignored unless the work completion indicates that the GRH is valid.
1621 * @ah_attr: Returned attributes that can be used when creating an address
1622 * handle for replying to the message.
1623 */
1624int ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1625 struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1626
1627/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07001628 * ib_create_ah_from_wc - Creates an address handle associated with the
1629 * sender of the specified work completion.
1630 * @pd: The protection domain associated with the address handle.
1631 * @wc: Work completion information associated with a received message.
1632 * @grh: References the received global route header. This parameter is
1633 * ignored unless the work completion indicates that the GRH is valid.
1634 * @port_num: The outbound port number to associate with the address.
1635 *
1636 * The address handle is used to reference a local or global destination
1637 * in all UD QP post sends.
1638 */
1639struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1640 struct ib_grh *grh, u8 port_num);
1641
1642/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 * ib_modify_ah - Modifies the address vector associated with an address
1644 * handle.
1645 * @ah: The address handle to modify.
1646 * @ah_attr: The new address vector attributes to associate with the
1647 * address handle.
1648 */
1649int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1650
1651/**
1652 * ib_query_ah - Queries the address vector associated with an address
1653 * handle.
1654 * @ah: The address handle to query.
1655 * @ah_attr: The address vector attributes associated with the address
1656 * handle.
1657 */
1658int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1659
1660/**
1661 * ib_destroy_ah - Destroys an address handle.
1662 * @ah: The address handle to destroy.
1663 */
1664int ib_destroy_ah(struct ib_ah *ah);
1665
1666/**
Roland Dreierd41fcc62005-08-18 12:23:08 -07001667 * ib_create_srq - Creates a SRQ associated with the specified protection
1668 * domain.
1669 * @pd: The protection domain associated with the SRQ.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001670 * @srq_init_attr: A list of initial attributes required to create the
1671 * SRQ. If SRQ creation succeeds, then the attributes are updated to
1672 * the actual capabilities of the created SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07001673 *
1674 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1675 * requested size of the SRQ, and set to the actual values allocated
1676 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
1677 * will always be at least as large as the requested values.
1678 */
1679struct ib_srq *ib_create_srq(struct ib_pd *pd,
1680 struct ib_srq_init_attr *srq_init_attr);
1681
1682/**
1683 * ib_modify_srq - Modifies the attributes for the specified SRQ.
1684 * @srq: The SRQ to modify.
1685 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
1686 * the current values of selected SRQ attributes are returned.
1687 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1688 * are being modified.
1689 *
1690 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1691 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1692 * the number of receives queued drops below the limit.
1693 */
1694int ib_modify_srq(struct ib_srq *srq,
1695 struct ib_srq_attr *srq_attr,
1696 enum ib_srq_attr_mask srq_attr_mask);
1697
1698/**
1699 * ib_query_srq - Returns the attribute list and current values for the
1700 * specified SRQ.
1701 * @srq: The SRQ to query.
1702 * @srq_attr: The attributes of the specified SRQ.
1703 */
1704int ib_query_srq(struct ib_srq *srq,
1705 struct ib_srq_attr *srq_attr);
1706
1707/**
1708 * ib_destroy_srq - Destroys the specified SRQ.
1709 * @srq: The SRQ to destroy.
1710 */
1711int ib_destroy_srq(struct ib_srq *srq);
1712
1713/**
1714 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1715 * @srq: The SRQ to post the work request on.
1716 * @recv_wr: A list of work requests to post on the receive queue.
1717 * @bad_recv_wr: On an immediate failure, this parameter will reference
1718 * the work request that failed to be posted on the QP.
1719 */
1720static inline int ib_post_srq_recv(struct ib_srq *srq,
1721 struct ib_recv_wr *recv_wr,
1722 struct ib_recv_wr **bad_recv_wr)
1723{
1724 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1725}
1726
1727/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 * ib_create_qp - Creates a QP associated with the specified protection
1729 * domain.
1730 * @pd: The protection domain associated with the QP.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08001731 * @qp_init_attr: A list of initial attributes required to create the
1732 * QP. If QP creation succeeds, then the attributes are updated to
1733 * the actual capabilities of the created QP.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 */
1735struct ib_qp *ib_create_qp(struct ib_pd *pd,
1736 struct ib_qp_init_attr *qp_init_attr);
1737
1738/**
1739 * ib_modify_qp - Modifies the attributes for the specified QP and then
1740 * transitions the QP to the given state.
1741 * @qp: The QP to modify.
1742 * @qp_attr: On input, specifies the QP attributes to modify. On output,
1743 * the current values of selected QP attributes are returned.
1744 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1745 * are being modified.
1746 */
1747int ib_modify_qp(struct ib_qp *qp,
1748 struct ib_qp_attr *qp_attr,
1749 int qp_attr_mask);
1750
1751/**
1752 * ib_query_qp - Returns the attribute list and current values for the
1753 * specified QP.
1754 * @qp: The QP to query.
1755 * @qp_attr: The attributes of the specified QP.
1756 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1757 * @qp_init_attr: Additional attributes of the selected QP.
1758 *
1759 * The qp_attr_mask may be used to limit the query to gathering only the
1760 * selected attributes.
1761 */
1762int ib_query_qp(struct ib_qp *qp,
1763 struct ib_qp_attr *qp_attr,
1764 int qp_attr_mask,
1765 struct ib_qp_init_attr *qp_init_attr);
1766
1767/**
1768 * ib_destroy_qp - Destroys the specified QP.
1769 * @qp: The QP to destroy.
1770 */
1771int ib_destroy_qp(struct ib_qp *qp);
1772
1773/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001774 * ib_open_qp - Obtain a reference to an existing sharable QP.
1775 * @xrcd - XRC domain
1776 * @qp_open_attr: Attributes identifying the QP to open.
1777 *
1778 * Returns a reference to a sharable QP.
1779 */
1780struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
1781 struct ib_qp_open_attr *qp_open_attr);
1782
1783/**
1784 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001785 * @qp: The QP handle to release
1786 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001787 * The opened QP handle is released by the caller. The underlying
1788 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07001789 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001790int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07001791
1792/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 * ib_post_send - Posts a list of work requests to the send queue of
1794 * the specified QP.
1795 * @qp: The QP to post the work request on.
1796 * @send_wr: A list of work requests to post on the send queue.
1797 * @bad_send_wr: On an immediate failure, this parameter will reference
1798 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08001799 *
1800 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
1801 * error is returned, the QP state shall not be affected,
1802 * ib_post_send() will return an immediate error after queueing any
1803 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 */
1805static inline int ib_post_send(struct ib_qp *qp,
1806 struct ib_send_wr *send_wr,
1807 struct ib_send_wr **bad_send_wr)
1808{
1809 return qp->device->post_send(qp, send_wr, bad_send_wr);
1810}
1811
1812/**
1813 * ib_post_recv - Posts a list of work requests to the receive queue of
1814 * the specified QP.
1815 * @qp: The QP to post the work request on.
1816 * @recv_wr: A list of work requests to post on the receive queue.
1817 * @bad_recv_wr: On an immediate failure, this parameter will reference
1818 * the work request that failed to be posted on the QP.
1819 */
1820static inline int ib_post_recv(struct ib_qp *qp,
1821 struct ib_recv_wr *recv_wr,
1822 struct ib_recv_wr **bad_recv_wr)
1823{
1824 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1825}
1826
1827/**
1828 * ib_create_cq - Creates a CQ on the specified device.
1829 * @device: The device on which to create the CQ.
1830 * @comp_handler: A user-specified callback that is invoked when a
1831 * completion event occurs on the CQ.
1832 * @event_handler: A user-specified callback that is invoked when an
1833 * asynchronous event not associated with a completion occurs on the CQ.
1834 * @cq_context: Context associated with the CQ returned to the user via
1835 * the associated completion and event handlers.
1836 * @cqe: The minimum size of the CQ.
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001837 * @comp_vector - Completion vector used to signal completion events.
1838 * Must be >= 0 and < context->num_comp_vectors.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 *
1840 * Users can examine the cq structure to determine the actual CQ size.
1841 */
1842struct ib_cq *ib_create_cq(struct ib_device *device,
1843 ib_comp_handler comp_handler,
1844 void (*event_handler)(struct ib_event *, void *),
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001845 void *cq_context, int cqe, int comp_vector);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847/**
1848 * ib_resize_cq - Modifies the capacity of the CQ.
1849 * @cq: The CQ to resize.
1850 * @cqe: The minimum size of the CQ.
1851 *
1852 * Users can examine the cq structure to determine the actual CQ size.
1853 */
1854int ib_resize_cq(struct ib_cq *cq, int cqe);
1855
1856/**
Eli Cohen2dd57162008-04-16 21:09:33 -07001857 * ib_modify_cq - Modifies moderation params of the CQ
1858 * @cq: The CQ to modify.
1859 * @cq_count: number of CQEs that will trigger an event
1860 * @cq_period: max period of time in usec before triggering an event
1861 *
1862 */
1863int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
1864
1865/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 * ib_destroy_cq - Destroys the specified CQ.
1867 * @cq: The CQ to destroy.
1868 */
1869int ib_destroy_cq(struct ib_cq *cq);
1870
1871/**
1872 * ib_poll_cq - poll a CQ for completion(s)
1873 * @cq:the CQ being polled
1874 * @num_entries:maximum number of completions to return
1875 * @wc:array of at least @num_entries &struct ib_wc where completions
1876 * will be returned
1877 *
1878 * Poll a CQ for (possibly multiple) completions. If the return value
1879 * is < 0, an error occurred. If the return value is >= 0, it is the
1880 * number of completions returned. If the return value is
1881 * non-negative and < num_entries, then the CQ was emptied.
1882 */
1883static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1884 struct ib_wc *wc)
1885{
1886 return cq->device->poll_cq(cq, num_entries, wc);
1887}
1888
1889/**
1890 * ib_peek_cq - Returns the number of unreaped completions currently
1891 * on the specified CQ.
1892 * @cq: The CQ to peek.
1893 * @wc_cnt: A minimum number of unreaped completions to check for.
1894 *
1895 * If the number of unreaped completions is greater than or equal to wc_cnt,
1896 * this function returns wc_cnt, otherwise, it returns the actual number of
1897 * unreaped completions.
1898 */
1899int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1900
1901/**
1902 * ib_req_notify_cq - Request completion notification on a CQ.
1903 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07001904 * @flags:
1905 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
1906 * to request an event on the next solicited event or next work
1907 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
1908 * may also be |ed in to request a hint about missed events, as
1909 * described below.
1910 *
1911 * Return Value:
1912 * < 0 means an error occurred while requesting notification
1913 * == 0 means notification was requested successfully, and if
1914 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
1915 * were missed and it is safe to wait for another event. In
1916 * this case is it guaranteed that any work completions added
1917 * to the CQ since the last CQ poll will trigger a completion
1918 * notification event.
1919 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
1920 * in. It means that the consumer must poll the CQ again to
1921 * make sure it is empty to avoid missing an event because of a
1922 * race between requesting notification and an entry being
1923 * added to the CQ. This return value means it is possible
1924 * (but not guaranteed) that a work completion has been added
1925 * to the CQ since the last poll without triggering a
1926 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 */
1928static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001929 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
Roland Dreiered23a722007-05-06 21:02:48 -07001931 return cq->device->req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932}
1933
1934/**
1935 * ib_req_ncomp_notif - Request completion notification when there are
1936 * at least the specified number of unreaped completions on the CQ.
1937 * @cq: The CQ to generate an event for.
1938 * @wc_cnt: The number of unreaped completions that should be on the
1939 * CQ before an event is generated.
1940 */
1941static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1942{
1943 return cq->device->req_ncomp_notif ?
1944 cq->device->req_ncomp_notif(cq, wc_cnt) :
1945 -ENOSYS;
1946}
1947
1948/**
1949 * ib_get_dma_mr - Returns a memory region for system memory that is
1950 * usable for DMA.
1951 * @pd: The protection domain associated with the memory region.
1952 * @mr_access_flags: Specifies the memory access rights.
Ralph Campbell9b513092006-12-12 14:27:41 -08001953 *
1954 * Note that the ib_dma_*() functions defined below must be used
1955 * to create/destroy addresses used with the Lkey or Rkey returned
1956 * by ib_get_dma_mr().
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 */
1958struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1959
1960/**
Ralph Campbell9b513092006-12-12 14:27:41 -08001961 * ib_dma_mapping_error - check a DMA addr for error
1962 * @dev: The device for which the dma_addr was created
1963 * @dma_addr: The DMA address to check
1964 */
1965static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1966{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001967 if (dev->dma_ops)
1968 return dev->dma_ops->mapping_error(dev, dma_addr);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001969 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08001970}
1971
1972/**
1973 * ib_dma_map_single - Map a kernel virtual address to DMA address
1974 * @dev: The device for which the dma_addr is to be created
1975 * @cpu_addr: The kernel virtual address
1976 * @size: The size of the region in bytes
1977 * @direction: The direction of the DMA
1978 */
1979static inline u64 ib_dma_map_single(struct ib_device *dev,
1980 void *cpu_addr, size_t size,
1981 enum dma_data_direction direction)
1982{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001983 if (dev->dma_ops)
1984 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
1985 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001986}
1987
1988/**
1989 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
1990 * @dev: The device for which the DMA address was created
1991 * @addr: The DMA address
1992 * @size: The size of the region in bytes
1993 * @direction: The direction of the DMA
1994 */
1995static inline void ib_dma_unmap_single(struct ib_device *dev,
1996 u64 addr, size_t size,
1997 enum dma_data_direction direction)
1998{
Ben Collinsd1998ef2006-12-13 22:10:05 -05001999 if (dev->dma_ops)
2000 dev->dma_ops->unmap_single(dev, addr, size, direction);
2001 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002002 dma_unmap_single(dev->dma_device, addr, size, direction);
2003}
2004
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002005static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
2006 void *cpu_addr, size_t size,
2007 enum dma_data_direction direction,
2008 struct dma_attrs *attrs)
2009{
2010 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
2011 direction, attrs);
2012}
2013
2014static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
2015 u64 addr, size_t size,
2016 enum dma_data_direction direction,
2017 struct dma_attrs *attrs)
2018{
2019 return dma_unmap_single_attrs(dev->dma_device, addr, size,
2020 direction, attrs);
2021}
2022
Ralph Campbell9b513092006-12-12 14:27:41 -08002023/**
2024 * ib_dma_map_page - Map a physical page to DMA address
2025 * @dev: The device for which the dma_addr is to be created
2026 * @page: The page to be mapped
2027 * @offset: The offset within the page
2028 * @size: The size of the region in bytes
2029 * @direction: The direction of the DMA
2030 */
2031static inline u64 ib_dma_map_page(struct ib_device *dev,
2032 struct page *page,
2033 unsigned long offset,
2034 size_t size,
2035 enum dma_data_direction direction)
2036{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002037 if (dev->dma_ops)
2038 return dev->dma_ops->map_page(dev, page, offset, size, direction);
2039 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002040}
2041
2042/**
2043 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
2044 * @dev: The device for which the DMA address was created
2045 * @addr: The DMA address
2046 * @size: The size of the region in bytes
2047 * @direction: The direction of the DMA
2048 */
2049static inline void ib_dma_unmap_page(struct ib_device *dev,
2050 u64 addr, size_t size,
2051 enum dma_data_direction direction)
2052{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002053 if (dev->dma_ops)
2054 dev->dma_ops->unmap_page(dev, addr, size, direction);
2055 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002056 dma_unmap_page(dev->dma_device, addr, size, direction);
2057}
2058
2059/**
2060 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
2061 * @dev: The device for which the DMA addresses are to be created
2062 * @sg: The array of scatter/gather entries
2063 * @nents: The number of scatter/gather entries
2064 * @direction: The direction of the DMA
2065 */
2066static inline int ib_dma_map_sg(struct ib_device *dev,
2067 struct scatterlist *sg, int nents,
2068 enum dma_data_direction direction)
2069{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002070 if (dev->dma_ops)
2071 return dev->dma_ops->map_sg(dev, sg, nents, direction);
2072 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002073}
2074
2075/**
2076 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
2077 * @dev: The device for which the DMA addresses were created
2078 * @sg: The array of scatter/gather entries
2079 * @nents: The number of scatter/gather entries
2080 * @direction: The direction of the DMA
2081 */
2082static inline void ib_dma_unmap_sg(struct ib_device *dev,
2083 struct scatterlist *sg, int nents,
2084 enum dma_data_direction direction)
2085{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002086 if (dev->dma_ops)
2087 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
2088 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002089 dma_unmap_sg(dev->dma_device, sg, nents, direction);
2090}
2091
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002092static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
2093 struct scatterlist *sg, int nents,
2094 enum dma_data_direction direction,
2095 struct dma_attrs *attrs)
2096{
2097 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2098}
2099
2100static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
2101 struct scatterlist *sg, int nents,
2102 enum dma_data_direction direction,
2103 struct dma_attrs *attrs)
2104{
2105 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2106}
Ralph Campbell9b513092006-12-12 14:27:41 -08002107/**
2108 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
2109 * @dev: The device for which the DMA addresses were created
2110 * @sg: The scatter/gather entry
2111 */
2112static inline u64 ib_sg_dma_address(struct ib_device *dev,
2113 struct scatterlist *sg)
2114{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002115 if (dev->dma_ops)
2116 return dev->dma_ops->dma_address(dev, sg);
2117 return sg_dma_address(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002118}
2119
2120/**
2121 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
2122 * @dev: The device for which the DMA addresses were created
2123 * @sg: The scatter/gather entry
2124 */
2125static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
2126 struct scatterlist *sg)
2127{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002128 if (dev->dma_ops)
2129 return dev->dma_ops->dma_len(dev, sg);
2130 return sg_dma_len(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002131}
2132
2133/**
2134 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
2135 * @dev: The device for which the DMA address was created
2136 * @addr: The DMA address
2137 * @size: The size of the region in bytes
2138 * @dir: The direction of the DMA
2139 */
2140static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
2141 u64 addr,
2142 size_t size,
2143 enum dma_data_direction dir)
2144{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002145 if (dev->dma_ops)
2146 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
2147 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002148 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
2149}
2150
2151/**
2152 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
2153 * @dev: The device for which the DMA address was created
2154 * @addr: The DMA address
2155 * @size: The size of the region in bytes
2156 * @dir: The direction of the DMA
2157 */
2158static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
2159 u64 addr,
2160 size_t size,
2161 enum dma_data_direction dir)
2162{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002163 if (dev->dma_ops)
2164 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
2165 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002166 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
2167}
2168
2169/**
2170 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
2171 * @dev: The device for which the DMA address is requested
2172 * @size: The size of the region to allocate in bytes
2173 * @dma_handle: A pointer for returning the DMA address of the region
2174 * @flag: memory allocator flags
2175 */
2176static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
2177 size_t size,
2178 u64 *dma_handle,
2179 gfp_t flag)
2180{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002181 if (dev->dma_ops)
2182 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Roland Dreierc59a3da2006-12-15 13:57:26 -08002183 else {
2184 dma_addr_t handle;
2185 void *ret;
2186
2187 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
2188 *dma_handle = handle;
2189 return ret;
2190 }
Ralph Campbell9b513092006-12-12 14:27:41 -08002191}
2192
2193/**
2194 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
2195 * @dev: The device for which the DMA addresses were allocated
2196 * @size: The size of the region
2197 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
2198 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
2199 */
2200static inline void ib_dma_free_coherent(struct ib_device *dev,
2201 size_t size, void *cpu_addr,
2202 u64 dma_handle)
2203{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002204 if (dev->dma_ops)
2205 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
2206 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002207 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
2208}
2209
2210/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
2212 * by an HCA.
2213 * @pd: The protection domain associated assigned to the registered region.
2214 * @phys_buf_array: Specifies a list of physical buffers to use in the
2215 * memory region.
2216 * @num_phys_buf: Specifies the size of the phys_buf_array.
2217 * @mr_access_flags: Specifies the memory access rights.
2218 * @iova_start: The offset of the region's starting I/O virtual address.
2219 */
2220struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
2221 struct ib_phys_buf *phys_buf_array,
2222 int num_phys_buf,
2223 int mr_access_flags,
2224 u64 *iova_start);
2225
2226/**
2227 * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
2228 * Conceptually, this call performs the functions deregister memory region
2229 * followed by register physical memory region. Where possible,
2230 * resources are reused instead of deallocated and reallocated.
2231 * @mr: The memory region to modify.
2232 * @mr_rereg_mask: A bit-mask used to indicate which of the following
2233 * properties of the memory region are being modified.
2234 * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
2235 * the new protection domain to associated with the memory region,
2236 * otherwise, this parameter is ignored.
2237 * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2238 * field specifies a list of physical buffers to use in the new
2239 * translation, otherwise, this parameter is ignored.
2240 * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2241 * field specifies the size of the phys_buf_array, otherwise, this
2242 * parameter is ignored.
2243 * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
2244 * field specifies the new memory access rights, otherwise, this
2245 * parameter is ignored.
2246 * @iova_start: The offset of the region's starting I/O virtual address.
2247 */
2248int ib_rereg_phys_mr(struct ib_mr *mr,
2249 int mr_rereg_mask,
2250 struct ib_pd *pd,
2251 struct ib_phys_buf *phys_buf_array,
2252 int num_phys_buf,
2253 int mr_access_flags,
2254 u64 *iova_start);
2255
2256/**
2257 * ib_query_mr - Retrieves information about a specific memory region.
2258 * @mr: The memory region to retrieve information about.
2259 * @mr_attr: The attributes of the specified memory region.
2260 */
2261int ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
2262
2263/**
2264 * ib_dereg_mr - Deregisters a memory region and removes it from the
2265 * HCA translation table.
2266 * @mr: The memory region to deregister.
Shani Michaeli7083e422013-02-06 16:19:12 +00002267 *
2268 * This function can fail, if the memory region has memory windows bound to it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 */
2270int ib_dereg_mr(struct ib_mr *mr);
2271
Sagi Grimberg17cd3a22014-02-23 14:19:04 +02002272
2273/**
2274 * ib_create_mr - Allocates a memory region that may be used for
2275 * signature handover operations.
2276 * @pd: The protection domain associated with the region.
2277 * @mr_init_attr: memory region init attributes.
2278 */
2279struct ib_mr *ib_create_mr(struct ib_pd *pd,
2280 struct ib_mr_init_attr *mr_init_attr);
2281
2282/**
2283 * ib_destroy_mr - Destroys a memory region that was created using
2284 * ib_create_mr and removes it from HW translation tables.
2285 * @mr: The memory region to destroy.
2286 *
2287 * This function can fail, if the memory region has memory windows bound to it.
2288 */
2289int ib_destroy_mr(struct ib_mr *mr);
2290
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291/**
Steve Wise00f7ec32008-07-14 23:48:45 -07002292 * ib_alloc_fast_reg_mr - Allocates memory region usable with the
2293 * IB_WR_FAST_REG_MR send work request.
2294 * @pd: The protection domain associated with the region.
2295 * @max_page_list_len: requested max physical buffer list length to be
2296 * used with fast register work requests for this MR.
2297 */
2298struct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2299
2300/**
2301 * ib_alloc_fast_reg_page_list - Allocates a page list array
2302 * @device - ib device pointer.
2303 * @page_list_len - size of the page list array to be allocated.
2304 *
2305 * This allocates and returns a struct ib_fast_reg_page_list * and a
2306 * page_list array that is at least page_list_len in size. The actual
2307 * size is returned in max_page_list_len. The caller is responsible
2308 * for initializing the contents of the page_list array before posting
2309 * a send work request with the IB_WC_FAST_REG_MR opcode.
2310 *
2311 * The page_list array entries must be translated using one of the
2312 * ib_dma_*() functions just like the addresses passed to
2313 * ib_map_phys_fmr(). Once the ib_post_send() is issued, the struct
2314 * ib_fast_reg_page_list must not be modified by the caller until the
2315 * IB_WC_FAST_REG_MR work request completes.
2316 */
2317struct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2318 struct ib_device *device, int page_list_len);
2319
2320/**
2321 * ib_free_fast_reg_page_list - Deallocates a previously allocated
2322 * page list array.
2323 * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2324 */
2325void ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2326
2327/**
2328 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2329 * R_Key and L_Key.
2330 * @mr - struct ib_mr pointer to be updated.
2331 * @newkey - new key to be used.
2332 */
2333static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2334{
2335 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2336 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2337}
2338
2339/**
Shani Michaeli7083e422013-02-06 16:19:12 +00002340 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
2341 * for calculating a new rkey for type 2 memory windows.
2342 * @rkey - the rkey to increment.
2343 */
2344static inline u32 ib_inc_rkey(u32 rkey)
2345{
2346 const u32 mask = 0x000000ff;
2347 return ((rkey + 1) & mask) | (rkey & ~mask);
2348}
2349
2350/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 * ib_alloc_mw - Allocates a memory window.
2352 * @pd: The protection domain associated with the memory window.
Shani Michaeli7083e422013-02-06 16:19:12 +00002353 * @type: The type of the memory window (1 or 2).
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 */
Shani Michaeli7083e422013-02-06 16:19:12 +00002355struct ib_mw *ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
2357/**
2358 * ib_bind_mw - Posts a work request to the send queue of the specified
2359 * QP, which binds the memory window to the given address range and
2360 * remote access attributes.
2361 * @qp: QP to post the bind work request on.
2362 * @mw: The memory window to bind.
2363 * @mw_bind: Specifies information about the memory window, including
2364 * its address range, remote access rights, and associated memory region.
Shani Michaeli7083e422013-02-06 16:19:12 +00002365 *
2366 * If there is no immediate error, the function will update the rkey member
2367 * of the mw parameter to its new value. The bind operation can still fail
2368 * asynchronously.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 */
2370static inline int ib_bind_mw(struct ib_qp *qp,
2371 struct ib_mw *mw,
2372 struct ib_mw_bind *mw_bind)
2373{
2374 /* XXX reference counting in corresponding MR? */
2375 return mw->device->bind_mw ?
2376 mw->device->bind_mw(qp, mw, mw_bind) :
2377 -ENOSYS;
2378}
2379
2380/**
2381 * ib_dealloc_mw - Deallocates a memory window.
2382 * @mw: The memory window to deallocate.
2383 */
2384int ib_dealloc_mw(struct ib_mw *mw);
2385
2386/**
2387 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2388 * @pd: The protection domain associated with the unmapped region.
2389 * @mr_access_flags: Specifies the memory access rights.
2390 * @fmr_attr: Attributes of the unmapped region.
2391 *
2392 * A fast memory region must be mapped before it can be used as part of
2393 * a work request.
2394 */
2395struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2396 int mr_access_flags,
2397 struct ib_fmr_attr *fmr_attr);
2398
2399/**
2400 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2401 * @fmr: The fast memory region to associate with the pages.
2402 * @page_list: An array of physical pages to map to the fast memory region.
2403 * @list_len: The number of pages in page_list.
2404 * @iova: The I/O virtual address to use with the mapped region.
2405 */
2406static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2407 u64 *page_list, int list_len,
2408 u64 iova)
2409{
2410 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2411}
2412
2413/**
2414 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2415 * @fmr_list: A linked list of fast memory regions to unmap.
2416 */
2417int ib_unmap_fmr(struct list_head *fmr_list);
2418
2419/**
2420 * ib_dealloc_fmr - Deallocates a fast memory region.
2421 * @fmr: The fast memory region to deallocate.
2422 */
2423int ib_dealloc_fmr(struct ib_fmr *fmr);
2424
2425/**
2426 * ib_attach_mcast - Attaches the specified QP to a multicast group.
2427 * @qp: QP to attach to the multicast group. The QP must be type
2428 * IB_QPT_UD.
2429 * @gid: Multicast group GID.
2430 * @lid: Multicast group LID in host byte order.
2431 *
2432 * In order to send and receive multicast packets, subnet
2433 * administration must have created the multicast group and configured
2434 * the fabric appropriately. The port associated with the specified
2435 * QP must also be a member of the multicast group.
2436 */
2437int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2438
2439/**
2440 * ib_detach_mcast - Detaches the specified QP from a multicast group.
2441 * @qp: QP to detach from the multicast group.
2442 * @gid: Multicast group GID.
2443 * @lid: Multicast group LID in host byte order.
2444 */
2445int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2446
Sean Hefty59991f92011-05-23 17:52:46 -07002447/**
2448 * ib_alloc_xrcd - Allocates an XRC domain.
2449 * @device: The device on which to allocate the XRC domain.
2450 */
2451struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2452
2453/**
2454 * ib_dealloc_xrcd - Deallocates an XRC domain.
2455 * @xrcd: The XRC domain to deallocate.
2456 */
2457int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2458
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002459struct ib_flow *ib_create_flow(struct ib_qp *qp,
2460 struct ib_flow_attr *flow_attr, int domain);
2461int ib_destroy_flow(struct ib_flow *flow_id);
2462
Eli Cohen1c636f82013-10-31 15:26:32 +02002463static inline int ib_check_mr_access(int flags)
2464{
2465 /*
2466 * Local write permission is required if remote write or
2467 * remote atomic permission is also requested.
2468 */
2469 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
2470 !(flags & IB_ACCESS_LOCAL_WRITE))
2471 return -EINVAL;
2472
2473 return 0;
2474}
2475
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476#endif /* IB_VERBS_H */