blob: 75fcc97886de026969e61f7c87a1df24b7337499 [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>
Yotam Kenneth9268f722015-07-30 17:50:15 +030051#include <linux/socket.h>
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -080052#include <linux/irq_poll.h>
Matan Barakdd5f03b2013-12-12 18:03:11 +020053#include <uapi/linux/if_ether.h>
Somnath Koturc865f242015-12-23 14:56:51 +020054#include <net/ipv6.h>
55#include <net/ip.h>
Matan Barak301a7212015-12-15 20:30:10 +020056#include <linux/string.h>
57#include <linux/slab.h>
Roland Dreiere2773c02005-07-07 17:57:10 -070058
Arun Sharma600634972011-07-26 16:09:06 -070059#include <linux/atomic.h>
Haggai Eran882214e2014-12-11 17:04:18 +020060#include <linux/mmu_notifier.h>
Roland Dreiere2773c02005-07-07 17:57:10 -070061#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Tejun Heof0626712010-10-19 15:24:36 +000063extern struct workqueue_struct *ib_wq;
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -080064extern struct workqueue_struct *ib_comp_wq;
Tejun Heof0626712010-10-19 15:24:36 +000065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066union ib_gid {
67 u8 raw[16];
68 struct {
Sean Hefty97f52eb2005-08-13 21:05:57 -070069 __be64 subnet_prefix;
70 __be64 interface_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 } global;
72};
73
Moni Shouae26be1b2015-07-30 18:33:29 +030074extern union ib_gid zgid;
75
Matan Barakb39ffa12015-12-23 14:56:47 +020076enum ib_gid_type {
77 /* If link layer is Ethernet, this is RoCE V1 */
78 IB_GID_TYPE_IB = 0,
79 IB_GID_TYPE_ROCE = 0,
Matan Barak7766a992015-12-23 14:56:50 +020080 IB_GID_TYPE_ROCE_UDP_ENCAP = 1,
Matan Barakb39ffa12015-12-23 14:56:47 +020081 IB_GID_TYPE_SIZE
82};
83
Matan Barak03db3a22015-07-30 18:33:26 +030084struct ib_gid_attr {
Matan Barakb39ffa12015-12-23 14:56:47 +020085 enum ib_gid_type gid_type;
Matan Barak03db3a22015-07-30 18:33:26 +030086 struct net_device *ndev;
87};
88
Tom Tucker07ebafb2006-08-03 16:02:42 -050089enum rdma_node_type {
90 /* IB values map to NodeInfo:NodeType. */
91 RDMA_NODE_IB_CA = 1,
92 RDMA_NODE_IB_SWITCH,
93 RDMA_NODE_IB_ROUTER,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +000094 RDMA_NODE_RNIC,
95 RDMA_NODE_USNIC,
Upinder Malhi5db57652014-01-15 17:02:36 -080096 RDMA_NODE_USNIC_UDP,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
Tom Tucker07ebafb2006-08-03 16:02:42 -050099enum rdma_transport_type {
100 RDMA_TRANSPORT_IB,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +0000101 RDMA_TRANSPORT_IWARP,
Upinder Malhi248567f2014-01-09 14:48:19 -0800102 RDMA_TRANSPORT_USNIC,
103 RDMA_TRANSPORT_USNIC_UDP
Tom Tucker07ebafb2006-08-03 16:02:42 -0500104};
105
Michael Wang6b90a6d2015-05-05 14:50:18 +0200106enum rdma_protocol_type {
107 RDMA_PROTOCOL_IB,
108 RDMA_PROTOCOL_IBOE,
109 RDMA_PROTOCOL_IWARP,
110 RDMA_PROTOCOL_USNIC_UDP
111};
112
Roland Dreier8385fd82014-06-04 10:00:16 -0700113__attribute_const__ enum rdma_transport_type
114rdma_node_get_transport(enum rdma_node_type node_type);
Tom Tucker07ebafb2006-08-03 16:02:42 -0500115
Somnath Koturc865f242015-12-23 14:56:51 +0200116enum rdma_network_type {
117 RDMA_NETWORK_IB,
118 RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB,
119 RDMA_NETWORK_IPV4,
120 RDMA_NETWORK_IPV6
121};
122
123static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
124{
125 if (network_type == RDMA_NETWORK_IPV4 ||
126 network_type == RDMA_NETWORK_IPV6)
127 return IB_GID_TYPE_ROCE_UDP_ENCAP;
128
129 /* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */
130 return IB_GID_TYPE_IB;
131}
132
133static inline enum rdma_network_type ib_gid_to_network_type(enum ib_gid_type gid_type,
134 union ib_gid *gid)
135{
136 if (gid_type == IB_GID_TYPE_IB)
137 return RDMA_NETWORK_IB;
138
139 if (ipv6_addr_v4mapped((struct in6_addr *)gid))
140 return RDMA_NETWORK_IPV4;
141 else
142 return RDMA_NETWORK_IPV6;
143}
144
Eli Cohena3f5ada2010-09-27 17:51:10 -0700145enum rdma_link_layer {
146 IB_LINK_LAYER_UNSPECIFIED,
147 IB_LINK_LAYER_INFINIBAND,
148 IB_LINK_LAYER_ETHERNET,
149};
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151enum ib_device_cap_flags {
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200152 IB_DEVICE_RESIZE_MAX_WR = (1 << 0),
153 IB_DEVICE_BAD_PKEY_CNTR = (1 << 1),
154 IB_DEVICE_BAD_QKEY_CNTR = (1 << 2),
155 IB_DEVICE_RAW_MULTI = (1 << 3),
156 IB_DEVICE_AUTO_PATH_MIG = (1 << 4),
157 IB_DEVICE_CHANGE_PHY_PORT = (1 << 5),
158 IB_DEVICE_UD_AV_PORT_ENFORCE = (1 << 6),
159 IB_DEVICE_CURR_QP_STATE_MOD = (1 << 7),
160 IB_DEVICE_SHUTDOWN_PORT = (1 << 8),
161 IB_DEVICE_INIT_TYPE = (1 << 9),
162 IB_DEVICE_PORT_ACTIVE_EVENT = (1 << 10),
163 IB_DEVICE_SYS_IMAGE_GUID = (1 << 11),
164 IB_DEVICE_RC_RNR_NAK_GEN = (1 << 12),
165 IB_DEVICE_SRQ_RESIZE = (1 << 13),
166 IB_DEVICE_N_NOTIFY_CQ = (1 << 14),
Christoph Hellwigb1adc712015-12-23 19:12:45 +0100167
168 /*
169 * This device supports a per-device lkey or stag that can be
170 * used without performing a memory registration for the local
171 * memory. Note that ULPs should never check this flag, but
172 * instead of use the local_dma_lkey flag in the ib_pd structure,
173 * which will always contain a usable lkey.
174 */
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200175 IB_DEVICE_LOCAL_DMA_LKEY = (1 << 15),
176 IB_DEVICE_RESERVED /* old SEND_W_INV */ = (1 << 16),
177 IB_DEVICE_MEM_WINDOW = (1 << 17),
Eli Cohene0605d92008-01-30 18:30:57 +0200178 /*
179 * Devices should set IB_DEVICE_UD_IP_SUM if they support
180 * insertion of UDP and TCP checksum on outgoing UD IPoIB
181 * messages and can verify the validity of checksum for
182 * incoming messages. Setting this flag implies that the
183 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
184 */
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200185 IB_DEVICE_UD_IP_CSUM = (1 << 18),
186 IB_DEVICE_UD_TSO = (1 << 19),
187 IB_DEVICE_XRC = (1 << 20),
Christoph Hellwigb1adc712015-12-23 19:12:45 +0100188
189 /*
190 * This device supports the IB "base memory management extension",
191 * which includes support for fast registrations (IB_WR_REG_MR,
192 * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs). This flag should
193 * also be set by any iWarp device which must support FRs to comply
194 * to the iWarp verbs spec. iWarp devices also support the
195 * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
196 * stag.
197 */
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200198 IB_DEVICE_MEM_MGT_EXTENSIONS = (1 << 21),
199 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1 << 22),
200 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1 << 23),
201 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1 << 24),
202 IB_DEVICE_RC_IP_CSUM = (1 << 25),
203 IB_DEVICE_RAW_IP_CSUM = (1 << 26),
Leon Romanovsky8a06ce52015-12-20 12:16:10 +0200204 /*
205 * Devices should set IB_DEVICE_CROSS_CHANNEL if they
206 * support execution of WQEs that involve synchronization
207 * of I/O operations with single completion queue managed
208 * by hardware.
209 */
210 IB_DEVICE_CROSS_CHANNEL = (1 << 27),
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200211 IB_DEVICE_MANAGED_FLOW_STEERING = (1 << 29),
212 IB_DEVICE_SIGNATURE_HANDOVER = (1 << 30),
213 IB_DEVICE_ON_DEMAND_PAGING = (1 << 31),
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200214};
215
216enum ib_signature_prot_cap {
217 IB_PROT_T10DIF_TYPE_1 = 1,
218 IB_PROT_T10DIF_TYPE_2 = 1 << 1,
219 IB_PROT_T10DIF_TYPE_3 = 1 << 2,
220};
221
222enum ib_signature_guard_cap {
223 IB_GUARD_T10DIF_CRC = 1,
224 IB_GUARD_T10DIF_CSUM = 1 << 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225};
226
227enum ib_atomic_cap {
228 IB_ATOMIC_NONE,
229 IB_ATOMIC_HCA,
230 IB_ATOMIC_GLOB
231};
232
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200233enum ib_odp_general_cap_bits {
234 IB_ODP_SUPPORT = 1 << 0,
235};
236
237enum ib_odp_transport_cap_bits {
238 IB_ODP_SUPPORT_SEND = 1 << 0,
239 IB_ODP_SUPPORT_RECV = 1 << 1,
240 IB_ODP_SUPPORT_WRITE = 1 << 2,
241 IB_ODP_SUPPORT_READ = 1 << 3,
242 IB_ODP_SUPPORT_ATOMIC = 1 << 4,
243};
244
245struct ib_odp_caps {
246 uint64_t general_caps;
247 struct {
248 uint32_t rc_odp_caps;
249 uint32_t uc_odp_caps;
250 uint32_t ud_odp_caps;
251 } per_transport_caps;
252};
253
Matan Barakb9926b92015-06-11 16:35:22 +0300254enum ib_cq_creation_flags {
255 IB_CQ_FLAGS_TIMESTAMP_COMPLETION = 1 << 0,
Leon Romanovsky8a06ce52015-12-20 12:16:10 +0200256 IB_CQ_FLAGS_IGNORE_OVERRUN = 1 << 1,
Matan Barakb9926b92015-06-11 16:35:22 +0300257};
258
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300259struct ib_cq_init_attr {
260 unsigned int cqe;
261 int comp_vector;
262 u32 flags;
263};
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265struct ib_device_attr {
266 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700267 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 u64 max_mr_size;
269 u64 page_size_cap;
270 u32 vendor_id;
271 u32 vendor_part_id;
272 u32 hw_ver;
273 int max_qp;
274 int max_qp_wr;
275 int device_cap_flags;
276 int max_sge;
277 int max_sge_rd;
278 int max_cq;
279 int max_cqe;
280 int max_mr;
281 int max_pd;
282 int max_qp_rd_atom;
283 int max_ee_rd_atom;
284 int max_res_rd_atom;
285 int max_qp_init_rd_atom;
286 int max_ee_init_rd_atom;
287 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300288 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 int max_ee;
290 int max_rdd;
291 int max_mw;
292 int max_raw_ipv6_qp;
293 int max_raw_ethy_qp;
294 int max_mcast_grp;
295 int max_mcast_qp_attach;
296 int max_total_mcast_qp_attach;
297 int max_ah;
298 int max_fmr;
299 int max_map_per_fmr;
300 int max_srq;
301 int max_srq_wr;
302 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700303 unsigned int max_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 u16 max_pkeys;
305 u8 local_ca_ack_delay;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200306 int sig_prot_cap;
307 int sig_guard_cap;
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200308 struct ib_odp_caps odp_caps;
Matan Barak24306dc2015-06-11 16:35:24 +0300309 uint64_t timestamp_mask;
310 uint64_t hca_core_clock; /* in KHZ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311};
312
313enum ib_mtu {
314 IB_MTU_256 = 1,
315 IB_MTU_512 = 2,
316 IB_MTU_1024 = 3,
317 IB_MTU_2048 = 4,
318 IB_MTU_4096 = 5
319};
320
321static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
322{
323 switch (mtu) {
324 case IB_MTU_256: return 256;
325 case IB_MTU_512: return 512;
326 case IB_MTU_1024: return 1024;
327 case IB_MTU_2048: return 2048;
328 case IB_MTU_4096: return 4096;
329 default: return -1;
330 }
331}
332
333enum ib_port_state {
334 IB_PORT_NOP = 0,
335 IB_PORT_DOWN = 1,
336 IB_PORT_INIT = 2,
337 IB_PORT_ARMED = 3,
338 IB_PORT_ACTIVE = 4,
339 IB_PORT_ACTIVE_DEFER = 5
340};
341
342enum ib_port_cap_flags {
343 IB_PORT_SM = 1 << 1,
344 IB_PORT_NOTICE_SUP = 1 << 2,
345 IB_PORT_TRAP_SUP = 1 << 3,
346 IB_PORT_OPT_IPD_SUP = 1 << 4,
347 IB_PORT_AUTO_MIGR_SUP = 1 << 5,
348 IB_PORT_SL_MAP_SUP = 1 << 6,
349 IB_PORT_MKEY_NVRAM = 1 << 7,
350 IB_PORT_PKEY_NVRAM = 1 << 8,
351 IB_PORT_LED_INFO_SUP = 1 << 9,
352 IB_PORT_SM_DISABLED = 1 << 10,
353 IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
354 IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300355 IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 IB_PORT_CM_SUP = 1 << 16,
357 IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
358 IB_PORT_REINIT_SUP = 1 << 18,
359 IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
360 IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
361 IB_PORT_DR_NOTICE_SUP = 1 << 21,
362 IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
363 IB_PORT_BOOT_MGMT_SUP = 1 << 23,
364 IB_PORT_LINK_LATENCY_SUP = 1 << 24,
Moni Shouab4a26a22014-02-09 11:54:34 +0200365 IB_PORT_CLIENT_REG_SUP = 1 << 25,
Matan Barak03db3a22015-07-30 18:33:26 +0300366 IB_PORT_IP_BASED_GIDS = 1 << 26,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367};
368
369enum ib_port_width {
370 IB_WIDTH_1X = 1,
371 IB_WIDTH_4X = 2,
372 IB_WIDTH_8X = 4,
373 IB_WIDTH_12X = 8
374};
375
376static inline int ib_width_enum_to_int(enum ib_port_width width)
377{
378 switch (width) {
379 case IB_WIDTH_1X: return 1;
380 case IB_WIDTH_4X: return 4;
381 case IB_WIDTH_8X: return 8;
382 case IB_WIDTH_12X: return 12;
383 default: return -1;
384 }
385}
386
Or Gerlitz2e966912012-02-28 18:49:50 +0200387enum ib_port_speed {
388 IB_SPEED_SDR = 1,
389 IB_SPEED_DDR = 2,
390 IB_SPEED_QDR = 4,
391 IB_SPEED_FDR10 = 8,
392 IB_SPEED_FDR = 16,
393 IB_SPEED_EDR = 32
394};
395
Steve Wise7f624d02008-07-14 23:48:48 -0700396struct ib_protocol_stats {
397 /* TBD... */
398};
399
400struct iw_protocol_stats {
401 u64 ipInReceives;
402 u64 ipInHdrErrors;
403 u64 ipInTooBigErrors;
404 u64 ipInNoRoutes;
405 u64 ipInAddrErrors;
406 u64 ipInUnknownProtos;
407 u64 ipInTruncatedPkts;
408 u64 ipInDiscards;
409 u64 ipInDelivers;
410 u64 ipOutForwDatagrams;
411 u64 ipOutRequests;
412 u64 ipOutDiscards;
413 u64 ipOutNoRoutes;
414 u64 ipReasmTimeout;
415 u64 ipReasmReqds;
416 u64 ipReasmOKs;
417 u64 ipReasmFails;
418 u64 ipFragOKs;
419 u64 ipFragFails;
420 u64 ipFragCreates;
421 u64 ipInMcastPkts;
422 u64 ipOutMcastPkts;
423 u64 ipInBcastPkts;
424 u64 ipOutBcastPkts;
425
426 u64 tcpRtoAlgorithm;
427 u64 tcpRtoMin;
428 u64 tcpRtoMax;
429 u64 tcpMaxConn;
430 u64 tcpActiveOpens;
431 u64 tcpPassiveOpens;
432 u64 tcpAttemptFails;
433 u64 tcpEstabResets;
434 u64 tcpCurrEstab;
435 u64 tcpInSegs;
436 u64 tcpOutSegs;
437 u64 tcpRetransSegs;
438 u64 tcpInErrs;
439 u64 tcpOutRsts;
440};
441
442union rdma_protocol_stats {
443 struct ib_protocol_stats ib;
444 struct iw_protocol_stats iw;
445};
446
Ira Weinyf9b22e32015-05-13 20:02:59 -0400447/* Define bits for the various functionality this port needs to be supported by
448 * the core.
449 */
450/* Management 0x00000FFF */
451#define RDMA_CORE_CAP_IB_MAD 0x00000001
452#define RDMA_CORE_CAP_IB_SMI 0x00000002
453#define RDMA_CORE_CAP_IB_CM 0x00000004
454#define RDMA_CORE_CAP_IW_CM 0x00000008
455#define RDMA_CORE_CAP_IB_SA 0x00000010
Ira Weiny65995fe2015-06-06 14:38:32 -0400456#define RDMA_CORE_CAP_OPA_MAD 0x00000020
Ira Weinyf9b22e32015-05-13 20:02:59 -0400457
458/* Address format 0x000FF000 */
459#define RDMA_CORE_CAP_AF_IB 0x00001000
460#define RDMA_CORE_CAP_ETH_AH 0x00002000
461
462/* Protocol 0xFFF00000 */
463#define RDMA_CORE_CAP_PROT_IB 0x00100000
464#define RDMA_CORE_CAP_PROT_ROCE 0x00200000
465#define RDMA_CORE_CAP_PROT_IWARP 0x00400000
Matan Barak7766a992015-12-23 14:56:50 +0200466#define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
Ira Weinyf9b22e32015-05-13 20:02:59 -0400467
468#define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \
469 | RDMA_CORE_CAP_IB_MAD \
470 | RDMA_CORE_CAP_IB_SMI \
471 | RDMA_CORE_CAP_IB_CM \
472 | RDMA_CORE_CAP_IB_SA \
473 | RDMA_CORE_CAP_AF_IB)
474#define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \
475 | RDMA_CORE_CAP_IB_MAD \
476 | RDMA_CORE_CAP_IB_CM \
Ira Weinyf9b22e32015-05-13 20:02:59 -0400477 | RDMA_CORE_CAP_AF_IB \
478 | RDMA_CORE_CAP_ETH_AH)
Matan Barak7766a992015-12-23 14:56:50 +0200479#define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \
480 (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
481 | RDMA_CORE_CAP_IB_MAD \
482 | RDMA_CORE_CAP_IB_CM \
483 | RDMA_CORE_CAP_AF_IB \
484 | RDMA_CORE_CAP_ETH_AH)
Ira Weinyf9b22e32015-05-13 20:02:59 -0400485#define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \
486 | RDMA_CORE_CAP_IW_CM)
Ira Weiny65995fe2015-06-06 14:38:32 -0400487#define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \
488 | RDMA_CORE_CAP_OPA_MAD)
Ira Weinyf9b22e32015-05-13 20:02:59 -0400489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490struct ib_port_attr {
491 enum ib_port_state state;
492 enum ib_mtu max_mtu;
493 enum ib_mtu active_mtu;
494 int gid_tbl_len;
495 u32 port_cap_flags;
496 u32 max_msg_sz;
497 u32 bad_pkey_cntr;
498 u32 qkey_viol_cntr;
499 u16 pkey_tbl_len;
500 u16 lid;
501 u16 sm_lid;
502 u8 lmc;
503 u8 max_vl_num;
504 u8 sm_sl;
505 u8 subnet_timeout;
506 u8 init_type_reply;
507 u8 active_width;
508 u8 active_speed;
509 u8 phys_state;
510};
511
512enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800513 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
514 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515};
516
517struct ib_device_modify {
518 u64 sys_image_guid;
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800519 char node_desc[64];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520};
521
522enum ib_port_modify_flags {
523 IB_PORT_SHUTDOWN = 1,
524 IB_PORT_INIT_TYPE = (1<<2),
525 IB_PORT_RESET_QKEY_CNTR = (1<<3)
526};
527
528struct ib_port_modify {
529 u32 set_port_cap_mask;
530 u32 clr_port_cap_mask;
531 u8 init_type;
532};
533
534enum ib_event_type {
535 IB_EVENT_CQ_ERR,
536 IB_EVENT_QP_FATAL,
537 IB_EVENT_QP_REQ_ERR,
538 IB_EVENT_QP_ACCESS_ERR,
539 IB_EVENT_COMM_EST,
540 IB_EVENT_SQ_DRAINED,
541 IB_EVENT_PATH_MIG,
542 IB_EVENT_PATH_MIG_ERR,
543 IB_EVENT_DEVICE_FATAL,
544 IB_EVENT_PORT_ACTIVE,
545 IB_EVENT_PORT_ERR,
546 IB_EVENT_LID_CHANGE,
547 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700548 IB_EVENT_SM_CHANGE,
549 IB_EVENT_SRQ_ERR,
550 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700551 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000552 IB_EVENT_CLIENT_REREGISTER,
553 IB_EVENT_GID_CHANGE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554};
555
Bart Van Asschedb7489e2015-08-03 10:01:52 -0700556const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
Sagi Grimberg2b1b5b62015-05-18 13:40:28 +0300557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558struct ib_event {
559 struct ib_device *device;
560 union {
561 struct ib_cq *cq;
562 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700563 struct ib_srq *srq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 u8 port_num;
565 } element;
566 enum ib_event_type event;
567};
568
569struct ib_event_handler {
570 struct ib_device *device;
571 void (*handler)(struct ib_event_handler *, struct ib_event *);
572 struct list_head list;
573};
574
575#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
576 do { \
577 (_ptr)->device = _device; \
578 (_ptr)->handler = _handler; \
579 INIT_LIST_HEAD(&(_ptr)->list); \
580 } while (0)
581
582struct ib_global_route {
583 union ib_gid dgid;
584 u32 flow_label;
585 u8 sgid_index;
586 u8 hop_limit;
587 u8 traffic_class;
588};
589
Hal Rosenstock513789e2005-07-27 11:45:34 -0700590struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700591 __be32 version_tclass_flow;
592 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700593 u8 next_hdr;
594 u8 hop_limit;
595 union ib_gid sgid;
596 union ib_gid dgid;
597};
598
Somnath Koturc865f242015-12-23 14:56:51 +0200599union rdma_network_hdr {
600 struct ib_grh ibgrh;
601 struct {
602 /* The IB spec states that if it's IPv4, the header
603 * is located in the last 20 bytes of the header.
604 */
605 u8 reserved[20];
606 struct iphdr roce4grh;
607 };
608};
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610enum {
611 IB_MULTICAST_QPN = 0xffffff
612};
613
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800614#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616enum ib_ah_flags {
617 IB_AH_GRH = 1
618};
619
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700620enum ib_rate {
621 IB_RATE_PORT_CURRENT = 0,
622 IB_RATE_2_5_GBPS = 2,
623 IB_RATE_5_GBPS = 5,
624 IB_RATE_10_GBPS = 3,
625 IB_RATE_20_GBPS = 6,
626 IB_RATE_30_GBPS = 4,
627 IB_RATE_40_GBPS = 7,
628 IB_RATE_60_GBPS = 8,
629 IB_RATE_80_GBPS = 9,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300630 IB_RATE_120_GBPS = 10,
631 IB_RATE_14_GBPS = 11,
632 IB_RATE_56_GBPS = 12,
633 IB_RATE_112_GBPS = 13,
634 IB_RATE_168_GBPS = 14,
635 IB_RATE_25_GBPS = 15,
636 IB_RATE_100_GBPS = 16,
637 IB_RATE_200_GBPS = 17,
638 IB_RATE_300_GBPS = 18
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700639};
640
641/**
642 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
643 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
644 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
645 * @rate: rate to convert.
646 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700647__attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700648
649/**
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300650 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
651 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
652 * @rate: rate to convert.
653 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700654__attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300655
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200656
657/**
Sagi Grimberg9bee1782015-07-30 10:32:35 +0300658 * enum ib_mr_type - memory region type
659 * @IB_MR_TYPE_MEM_REG: memory region that is used for
660 * normal registration
661 * @IB_MR_TYPE_SIGNATURE: memory region that is used for
662 * signature operations (data-integrity
663 * capable regions)
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200664 */
Sagi Grimberg9bee1782015-07-30 10:32:35 +0300665enum ib_mr_type {
666 IB_MR_TYPE_MEM_REG,
667 IB_MR_TYPE_SIGNATURE,
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200668};
669
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200670/**
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300671 * Signature types
672 * IB_SIG_TYPE_NONE: Unprotected.
673 * IB_SIG_TYPE_T10_DIF: Type T10-DIF
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200674 */
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300675enum ib_signature_type {
676 IB_SIG_TYPE_NONE,
677 IB_SIG_TYPE_T10_DIF,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200678};
679
680/**
681 * Signature T10-DIF block-guard types
682 * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
683 * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
684 */
685enum ib_t10_dif_bg_type {
686 IB_T10DIF_CRC,
687 IB_T10DIF_CSUM
688};
689
690/**
691 * struct ib_t10_dif_domain - Parameters specific for T10-DIF
692 * domain.
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200693 * @bg_type: T10-DIF block guard type (CRC|CSUM)
694 * @pi_interval: protection information interval.
695 * @bg: seed of guard computation.
696 * @app_tag: application tag of guard block
697 * @ref_tag: initial guard block reference tag.
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300698 * @ref_remap: Indicate wethear the reftag increments each block
699 * @app_escape: Indicate to skip block check if apptag=0xffff
700 * @ref_escape: Indicate to skip block check if reftag=0xffffffff
701 * @apptag_check_mask: check bitmask of application tag.
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200702 */
703struct ib_t10_dif_domain {
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200704 enum ib_t10_dif_bg_type bg_type;
705 u16 pi_interval;
706 u16 bg;
707 u16 app_tag;
708 u32 ref_tag;
Sagi Grimberg78eda2b2014-08-13 19:54:35 +0300709 bool ref_remap;
710 bool app_escape;
711 bool ref_escape;
712 u16 apptag_check_mask;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200713};
714
715/**
716 * struct ib_sig_domain - Parameters for signature domain
717 * @sig_type: specific signauture type
718 * @sig: union of all signature domain attributes that may
719 * be used to set domain layout.
720 */
721struct ib_sig_domain {
722 enum ib_signature_type sig_type;
723 union {
724 struct ib_t10_dif_domain dif;
725 } sig;
726};
727
728/**
729 * struct ib_sig_attrs - Parameters for signature handover operation
730 * @check_mask: bitmask for signature byte check (8 bytes)
731 * @mem: memory domain layout desciptor.
732 * @wire: wire domain layout desciptor.
733 */
734struct ib_sig_attrs {
735 u8 check_mask;
736 struct ib_sig_domain mem;
737 struct ib_sig_domain wire;
738};
739
740enum ib_sig_err_type {
741 IB_SIG_BAD_GUARD,
742 IB_SIG_BAD_REFTAG,
743 IB_SIG_BAD_APPTAG,
744};
745
746/**
747 * struct ib_sig_err - signature error descriptor
748 */
749struct ib_sig_err {
750 enum ib_sig_err_type err_type;
751 u32 expected;
752 u32 actual;
753 u64 sig_err_offset;
754 u32 key;
755};
756
757enum ib_mr_status_check {
758 IB_MR_CHECK_SIG_STATUS = 1,
759};
760
761/**
762 * struct ib_mr_status - Memory region status container
763 *
764 * @fail_status: Bitmask of MR checks status. For each
765 * failed check a corresponding status bit is set.
766 * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
767 * failure.
768 */
769struct ib_mr_status {
770 u32 fail_status;
771 struct ib_sig_err sig_err;
772};
773
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300774/**
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700775 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
776 * enum.
777 * @mult: multiple to convert.
778 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700779__attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781struct ib_ah_attr {
782 struct ib_global_route grh;
783 u16 dlid;
784 u8 sl;
785 u8 src_path_bits;
786 u8 static_rate;
787 u8 ah_flags;
788 u8 port_num;
Matan Barakdd5f03b2013-12-12 18:03:11 +0200789 u8 dmac[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790};
791
792enum ib_wc_status {
793 IB_WC_SUCCESS,
794 IB_WC_LOC_LEN_ERR,
795 IB_WC_LOC_QP_OP_ERR,
796 IB_WC_LOC_EEC_OP_ERR,
797 IB_WC_LOC_PROT_ERR,
798 IB_WC_WR_FLUSH_ERR,
799 IB_WC_MW_BIND_ERR,
800 IB_WC_BAD_RESP_ERR,
801 IB_WC_LOC_ACCESS_ERR,
802 IB_WC_REM_INV_REQ_ERR,
803 IB_WC_REM_ACCESS_ERR,
804 IB_WC_REM_OP_ERR,
805 IB_WC_RETRY_EXC_ERR,
806 IB_WC_RNR_RETRY_EXC_ERR,
807 IB_WC_LOC_RDD_VIOL_ERR,
808 IB_WC_REM_INV_RD_REQ_ERR,
809 IB_WC_REM_ABORT_ERR,
810 IB_WC_INV_EECN_ERR,
811 IB_WC_INV_EEC_STATE_ERR,
812 IB_WC_FATAL_ERR,
813 IB_WC_RESP_TIMEOUT_ERR,
814 IB_WC_GENERAL_ERR
815};
816
Bart Van Asschedb7489e2015-08-03 10:01:52 -0700817const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
Sagi Grimberg2b1b5b62015-05-18 13:40:28 +0300818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819enum ib_wc_opcode {
820 IB_WC_SEND,
821 IB_WC_RDMA_WRITE,
822 IB_WC_RDMA_READ,
823 IB_WC_COMP_SWAP,
824 IB_WC_FETCH_ADD,
Eli Cohenc93570f2008-04-16 21:09:27 -0700825 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700826 IB_WC_LOCAL_INV,
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +0300827 IB_WC_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300828 IB_WC_MASKED_COMP_SWAP,
829 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830/*
831 * Set value of IB_WC_RECV so consumers can test if a completion is a
832 * receive by testing (opcode & IB_WC_RECV).
833 */
834 IB_WC_RECV = 1 << 7,
835 IB_WC_RECV_RDMA_WITH_IMM
836};
837
838enum ib_wc_flags {
839 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -0700840 IB_WC_WITH_IMM = (1<<1),
841 IB_WC_WITH_INVALIDATE = (1<<2),
Or Gerlitzd927d502012-01-11 19:03:51 +0200842 IB_WC_IP_CSUM_OK = (1<<3),
Matan Barakdd5f03b2013-12-12 18:03:11 +0200843 IB_WC_WITH_SMAC = (1<<4),
844 IB_WC_WITH_VLAN = (1<<5),
Somnath Koturc865f242015-12-23 14:56:51 +0200845 IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846};
847
848struct ib_wc {
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -0800849 union {
850 u64 wr_id;
851 struct ib_cqe *wr_cqe;
852 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 enum ib_wc_status status;
854 enum ib_wc_opcode opcode;
855 u32 vendor_err;
856 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +0200857 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -0700858 union {
859 __be32 imm_data;
860 u32 invalidate_rkey;
861 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 u32 src_qp;
863 int wc_flags;
864 u16 pkey_index;
865 u16 slid;
866 u8 sl;
867 u8 dlid_path_bits;
868 u8 port_num; /* valid only for DR SMPs on switches */
Matan Barakdd5f03b2013-12-12 18:03:11 +0200869 u8 smac[ETH_ALEN];
870 u16 vlan_id;
Somnath Koturc865f242015-12-23 14:56:51 +0200871 u8 network_hdr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872};
873
Roland Dreiered23a722007-05-06 21:02:48 -0700874enum ib_cq_notify_flags {
875 IB_CQ_SOLICITED = 1 << 0,
876 IB_CQ_NEXT_COMP = 1 << 1,
877 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
878 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Sean Hefty96104ed2011-05-23 16:31:36 -0700881enum ib_srq_type {
Sean Hefty418d5132011-05-23 19:42:29 -0700882 IB_SRQT_BASIC,
883 IB_SRQT_XRC
Sean Hefty96104ed2011-05-23 16:31:36 -0700884};
885
Roland Dreierd41fcc62005-08-18 12:23:08 -0700886enum ib_srq_attr_mask {
887 IB_SRQ_MAX_WR = 1 << 0,
888 IB_SRQ_LIMIT = 1 << 1,
889};
890
891struct ib_srq_attr {
892 u32 max_wr;
893 u32 max_sge;
894 u32 srq_limit;
895};
896
897struct ib_srq_init_attr {
898 void (*event_handler)(struct ib_event *, void *);
899 void *srq_context;
900 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -0700901 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -0700902
903 union {
904 struct {
905 struct ib_xrcd *xrcd;
906 struct ib_cq *cq;
907 } xrc;
908 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700909};
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911struct ib_qp_cap {
912 u32 max_send_wr;
913 u32 max_recv_wr;
914 u32 max_send_sge;
915 u32 max_recv_sge;
916 u32 max_inline_data;
917};
918
919enum ib_sig_type {
920 IB_SIGNAL_ALL_WR,
921 IB_SIGNAL_REQ_WR
922};
923
924enum ib_qp_type {
925 /*
926 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
927 * here (and in that order) since the MAD layer uses them as
928 * indices into a 2-entry table.
929 */
930 IB_QPT_SMI,
931 IB_QPT_GSI,
932
933 IB_QPT_RC,
934 IB_QPT_UC,
935 IB_QPT_UD,
936 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700937 IB_QPT_RAW_ETHERTYPE,
Or Gerlitzc938a612012-03-01 12:17:51 +0200938 IB_QPT_RAW_PACKET = 8,
Sean Heftyb42b63c2011-05-23 19:59:25 -0700939 IB_QPT_XRC_INI = 9,
940 IB_QPT_XRC_TGT,
Jack Morgenstein0134f162013-07-07 17:25:52 +0300941 IB_QPT_MAX,
942 /* Reserve a range for qp types internal to the low level driver.
943 * These qp types will not be visible at the IB core layer, so the
944 * IB_QPT_MAX usages should not be affected in the core layer
945 */
946 IB_QPT_RESERVED1 = 0x1000,
947 IB_QPT_RESERVED2,
948 IB_QPT_RESERVED3,
949 IB_QPT_RESERVED4,
950 IB_QPT_RESERVED5,
951 IB_QPT_RESERVED6,
952 IB_QPT_RESERVED7,
953 IB_QPT_RESERVED8,
954 IB_QPT_RESERVED9,
955 IB_QPT_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956};
957
Eli Cohenb846f252008-04-16 21:09:27 -0700958enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -0700959 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
960 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
Leon Romanovsky8a06ce52015-12-20 12:16:10 +0200961 IB_QP_CREATE_CROSS_CHANNEL = 1 << 2,
962 IB_QP_CREATE_MANAGED_SEND = 1 << 3,
963 IB_QP_CREATE_MANAGED_RECV = 1 << 4,
Matan Barak90f1d1b2013-11-07 15:25:12 +0200964 IB_QP_CREATE_NETIF_QP = 1 << 5,
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200965 IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
Or Gerlitz09b93082014-05-11 15:15:11 +0300966 IB_QP_CREATE_USE_GFP_NOIO = 1 << 7,
Jack Morgensteind2b57062012-08-03 08:40:37 +0000967 /* reserve bits 26-31 for low level drivers' internal use */
968 IB_QP_CREATE_RESERVED_START = 1 << 26,
969 IB_QP_CREATE_RESERVED_END = 1 << 31,
Eli Cohenb846f252008-04-16 21:09:27 -0700970};
971
Yishai Hadas73c40c62013-08-01 18:49:53 +0300972/*
973 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
974 * callback to destroy the passed in QP.
975 */
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977struct ib_qp_init_attr {
978 void (*event_handler)(struct ib_event *, void *);
979 void *qp_context;
980 struct ib_cq *send_cq;
981 struct ib_cq *recv_cq;
982 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -0700983 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 struct ib_qp_cap cap;
985 enum ib_sig_type sq_sig_type;
986 enum ib_qp_type qp_type;
Eli Cohenb846f252008-04-16 21:09:27 -0700987 enum ib_qp_create_flags create_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 u8 port_num; /* special QP types only */
989};
990
Sean Hefty0e0ec7e2011-08-08 15:31:51 -0700991struct ib_qp_open_attr {
992 void (*event_handler)(struct ib_event *, void *);
993 void *qp_context;
994 u32 qp_num;
995 enum ib_qp_type qp_type;
996};
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998enum ib_rnr_timeout {
999 IB_RNR_TIMER_655_36 = 0,
1000 IB_RNR_TIMER_000_01 = 1,
1001 IB_RNR_TIMER_000_02 = 2,
1002 IB_RNR_TIMER_000_03 = 3,
1003 IB_RNR_TIMER_000_04 = 4,
1004 IB_RNR_TIMER_000_06 = 5,
1005 IB_RNR_TIMER_000_08 = 6,
1006 IB_RNR_TIMER_000_12 = 7,
1007 IB_RNR_TIMER_000_16 = 8,
1008 IB_RNR_TIMER_000_24 = 9,
1009 IB_RNR_TIMER_000_32 = 10,
1010 IB_RNR_TIMER_000_48 = 11,
1011 IB_RNR_TIMER_000_64 = 12,
1012 IB_RNR_TIMER_000_96 = 13,
1013 IB_RNR_TIMER_001_28 = 14,
1014 IB_RNR_TIMER_001_92 = 15,
1015 IB_RNR_TIMER_002_56 = 16,
1016 IB_RNR_TIMER_003_84 = 17,
1017 IB_RNR_TIMER_005_12 = 18,
1018 IB_RNR_TIMER_007_68 = 19,
1019 IB_RNR_TIMER_010_24 = 20,
1020 IB_RNR_TIMER_015_36 = 21,
1021 IB_RNR_TIMER_020_48 = 22,
1022 IB_RNR_TIMER_030_72 = 23,
1023 IB_RNR_TIMER_040_96 = 24,
1024 IB_RNR_TIMER_061_44 = 25,
1025 IB_RNR_TIMER_081_92 = 26,
1026 IB_RNR_TIMER_122_88 = 27,
1027 IB_RNR_TIMER_163_84 = 28,
1028 IB_RNR_TIMER_245_76 = 29,
1029 IB_RNR_TIMER_327_68 = 30,
1030 IB_RNR_TIMER_491_52 = 31
1031};
1032
1033enum ib_qp_attr_mask {
1034 IB_QP_STATE = 1,
1035 IB_QP_CUR_STATE = (1<<1),
1036 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
1037 IB_QP_ACCESS_FLAGS = (1<<3),
1038 IB_QP_PKEY_INDEX = (1<<4),
1039 IB_QP_PORT = (1<<5),
1040 IB_QP_QKEY = (1<<6),
1041 IB_QP_AV = (1<<7),
1042 IB_QP_PATH_MTU = (1<<8),
1043 IB_QP_TIMEOUT = (1<<9),
1044 IB_QP_RETRY_CNT = (1<<10),
1045 IB_QP_RNR_RETRY = (1<<11),
1046 IB_QP_RQ_PSN = (1<<12),
1047 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
1048 IB_QP_ALT_PATH = (1<<14),
1049 IB_QP_MIN_RNR_TIMER = (1<<15),
1050 IB_QP_SQ_PSN = (1<<16),
1051 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
1052 IB_QP_PATH_MIG_STATE = (1<<18),
1053 IB_QP_CAP = (1<<19),
Matan Barakdd5f03b2013-12-12 18:03:11 +02001054 IB_QP_DEST_QPN = (1<<20),
Matan Barakaa744cc2015-10-15 18:38:53 +03001055 IB_QP_RESERVED1 = (1<<21),
1056 IB_QP_RESERVED2 = (1<<22),
1057 IB_QP_RESERVED3 = (1<<23),
1058 IB_QP_RESERVED4 = (1<<24),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059};
1060
1061enum ib_qp_state {
1062 IB_QPS_RESET,
1063 IB_QPS_INIT,
1064 IB_QPS_RTR,
1065 IB_QPS_RTS,
1066 IB_QPS_SQD,
1067 IB_QPS_SQE,
1068 IB_QPS_ERR
1069};
1070
1071enum ib_mig_state {
1072 IB_MIG_MIGRATED,
1073 IB_MIG_REARM,
1074 IB_MIG_ARMED
1075};
1076
Shani Michaeli7083e422013-02-06 16:19:12 +00001077enum ib_mw_type {
1078 IB_MW_TYPE_1 = 1,
1079 IB_MW_TYPE_2 = 2
1080};
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082struct ib_qp_attr {
1083 enum ib_qp_state qp_state;
1084 enum ib_qp_state cur_qp_state;
1085 enum ib_mtu path_mtu;
1086 enum ib_mig_state path_mig_state;
1087 u32 qkey;
1088 u32 rq_psn;
1089 u32 sq_psn;
1090 u32 dest_qp_num;
1091 int qp_access_flags;
1092 struct ib_qp_cap cap;
1093 struct ib_ah_attr ah_attr;
1094 struct ib_ah_attr alt_ah_attr;
1095 u16 pkey_index;
1096 u16 alt_pkey_index;
1097 u8 en_sqd_async_notify;
1098 u8 sq_draining;
1099 u8 max_rd_atomic;
1100 u8 max_dest_rd_atomic;
1101 u8 min_rnr_timer;
1102 u8 port_num;
1103 u8 timeout;
1104 u8 retry_cnt;
1105 u8 rnr_retry;
1106 u8 alt_port_num;
1107 u8 alt_timeout;
1108};
1109
1110enum ib_wr_opcode {
1111 IB_WR_RDMA_WRITE,
1112 IB_WR_RDMA_WRITE_WITH_IMM,
1113 IB_WR_SEND,
1114 IB_WR_SEND_WITH_IMM,
1115 IB_WR_RDMA_READ,
1116 IB_WR_ATOMIC_CMP_AND_SWP,
Eli Cohenc93570f2008-04-16 21:09:27 -07001117 IB_WR_ATOMIC_FETCH_AND_ADD,
Roland Dreier0f39cf32008-04-16 21:09:32 -07001118 IB_WR_LSO,
1119 IB_WR_SEND_WITH_INV,
Steve Wise00f7ec32008-07-14 23:48:45 -07001120 IB_WR_RDMA_READ_WITH_INV,
1121 IB_WR_LOCAL_INV,
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03001122 IB_WR_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +03001123 IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
1124 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001125 IB_WR_REG_SIG_MR,
Jack Morgenstein0134f162013-07-07 17:25:52 +03001126 /* reserve values for low level drivers' internal use.
1127 * These values will not be used at all in the ib core layer.
1128 */
1129 IB_WR_RESERVED1 = 0xf0,
1130 IB_WR_RESERVED2,
1131 IB_WR_RESERVED3,
1132 IB_WR_RESERVED4,
1133 IB_WR_RESERVED5,
1134 IB_WR_RESERVED6,
1135 IB_WR_RESERVED7,
1136 IB_WR_RESERVED8,
1137 IB_WR_RESERVED9,
1138 IB_WR_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139};
1140
1141enum ib_send_flags {
1142 IB_SEND_FENCE = 1,
1143 IB_SEND_SIGNALED = (1<<1),
1144 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +02001145 IB_SEND_INLINE = (1<<3),
Jack Morgenstein0134f162013-07-07 17:25:52 +03001146 IB_SEND_IP_CSUM = (1<<4),
1147
1148 /* reserve bits 26-31 for low level drivers' internal use */
1149 IB_SEND_RESERVED_START = (1 << 26),
1150 IB_SEND_RESERVED_END = (1 << 31),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151};
1152
1153struct ib_sge {
1154 u64 addr;
1155 u32 length;
1156 u32 lkey;
1157};
1158
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001159struct ib_cqe {
1160 void (*done)(struct ib_cq *cq, struct ib_wc *wc);
1161};
1162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163struct ib_send_wr {
1164 struct ib_send_wr *next;
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001165 union {
1166 u64 wr_id;
1167 struct ib_cqe *wr_cqe;
1168 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 struct ib_sge *sg_list;
1170 int num_sge;
1171 enum ib_wr_opcode opcode;
1172 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -07001173 union {
1174 __be32 imm_data;
1175 u32 invalidate_rkey;
1176 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177};
1178
Christoph Hellwige622f2f2015-10-08 09:16:33 +01001179struct ib_rdma_wr {
1180 struct ib_send_wr wr;
1181 u64 remote_addr;
1182 u32 rkey;
1183};
1184
1185static inline struct ib_rdma_wr *rdma_wr(struct ib_send_wr *wr)
1186{
1187 return container_of(wr, struct ib_rdma_wr, wr);
1188}
1189
1190struct ib_atomic_wr {
1191 struct ib_send_wr wr;
1192 u64 remote_addr;
1193 u64 compare_add;
1194 u64 swap;
1195 u64 compare_add_mask;
1196 u64 swap_mask;
1197 u32 rkey;
1198};
1199
1200static inline struct ib_atomic_wr *atomic_wr(struct ib_send_wr *wr)
1201{
1202 return container_of(wr, struct ib_atomic_wr, wr);
1203}
1204
1205struct ib_ud_wr {
1206 struct ib_send_wr wr;
1207 struct ib_ah *ah;
1208 void *header;
1209 int hlen;
1210 int mss;
1211 u32 remote_qpn;
1212 u32 remote_qkey;
1213 u16 pkey_index; /* valid for GSI only */
1214 u8 port_num; /* valid for DR SMPs on switch only */
1215};
1216
1217static inline struct ib_ud_wr *ud_wr(struct ib_send_wr *wr)
1218{
1219 return container_of(wr, struct ib_ud_wr, wr);
1220}
1221
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03001222struct ib_reg_wr {
1223 struct ib_send_wr wr;
1224 struct ib_mr *mr;
1225 u32 key;
1226 int access;
1227};
1228
1229static inline struct ib_reg_wr *reg_wr(struct ib_send_wr *wr)
1230{
1231 return container_of(wr, struct ib_reg_wr, wr);
1232}
1233
Christoph Hellwige622f2f2015-10-08 09:16:33 +01001234struct ib_sig_handover_wr {
1235 struct ib_send_wr wr;
1236 struct ib_sig_attrs *sig_attrs;
1237 struct ib_mr *sig_mr;
1238 int access_flags;
1239 struct ib_sge *prot;
1240};
1241
1242static inline struct ib_sig_handover_wr *sig_handover_wr(struct ib_send_wr *wr)
1243{
1244 return container_of(wr, struct ib_sig_handover_wr, wr);
1245}
1246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247struct ib_recv_wr {
1248 struct ib_recv_wr *next;
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001249 union {
1250 u64 wr_id;
1251 struct ib_cqe *wr_cqe;
1252 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 struct ib_sge *sg_list;
1254 int num_sge;
1255};
1256
1257enum ib_access_flags {
1258 IB_ACCESS_LOCAL_WRITE = 1,
1259 IB_ACCESS_REMOTE_WRITE = (1<<1),
1260 IB_ACCESS_REMOTE_READ = (1<<2),
1261 IB_ACCESS_REMOTE_ATOMIC = (1<<3),
Shani Michaeli7083e422013-02-06 16:19:12 +00001262 IB_ACCESS_MW_BIND = (1<<4),
Sagi Grimberg860f10a2014-12-11 17:04:16 +02001263 IB_ZERO_BASED = (1<<5),
1264 IB_ACCESS_ON_DEMAND = (1<<6),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265};
1266
Christoph Hellwigb7d3e0a2015-12-23 19:12:47 +01001267/*
1268 * XXX: these are apparently used for ->rereg_user_mr, no idea why they
1269 * are hidden here instead of a uapi header!
1270 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271enum ib_mr_rereg_flags {
1272 IB_MR_REREG_TRANS = 1,
1273 IB_MR_REREG_PD = (1<<1),
Matan Barak7e6edb92014-07-31 11:01:28 +03001274 IB_MR_REREG_ACCESS = (1<<2),
1275 IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276};
1277
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278struct ib_fmr_attr {
1279 int max_pages;
1280 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -08001281 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282};
1283
Haggai Eran882214e2014-12-11 17:04:18 +02001284struct ib_umem;
1285
Roland Dreiere2773c02005-07-07 17:57:10 -07001286struct ib_ucontext {
1287 struct ib_device *device;
1288 struct list_head pd_list;
1289 struct list_head mr_list;
1290 struct list_head mw_list;
1291 struct list_head cq_list;
1292 struct list_head qp_list;
1293 struct list_head srq_list;
1294 struct list_head ah_list;
Sean Hefty53d0bd12011-05-24 08:33:46 -07001295 struct list_head xrcd_list;
Hadar Hen Zion436f2ad2013-08-14 13:58:30 +03001296 struct list_head rule_list;
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001297 int closing;
Shachar Raindel8ada2c12014-12-11 17:04:17 +02001298
1299 struct pid *tgid;
Haggai Eran882214e2014-12-11 17:04:18 +02001300#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
1301 struct rb_root umem_tree;
1302 /*
1303 * Protects .umem_rbroot and tree, as well as odp_mrs_count and
1304 * mmu notifiers registration.
1305 */
1306 struct rw_semaphore umem_rwsem;
1307 void (*invalidate_range)(struct ib_umem *umem,
1308 unsigned long start, unsigned long end);
1309
1310 struct mmu_notifier mn;
1311 atomic_t notifier_count;
1312 /* A list of umems that don't have private mmu notifier counters yet. */
1313 struct list_head no_private_counters;
1314 int odp_mrs_count;
1315#endif
Roland Dreiere2773c02005-07-07 17:57:10 -07001316};
1317
1318struct ib_uobject {
1319 u64 user_handle; /* handle given to us by userspace */
1320 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -07001321 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -07001322 struct list_head list; /* link to context's list */
Roland Dreierb3d636b2008-04-16 21:01:06 -07001323 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -07001324 struct kref ref;
1325 struct rw_semaphore mutex; /* protects .live */
Mike Marciniszynd144da82015-11-02 12:13:25 -05001326 struct rcu_head rcu; /* kfree_rcu() overhead */
Roland Dreier9ead1902006-06-17 20:44:49 -07001327 int live;
Roland Dreiere2773c02005-07-07 17:57:10 -07001328};
1329
Roland Dreiere2773c02005-07-07 17:57:10 -07001330struct ib_udata {
Yann Droneaud309243e2013-12-11 23:01:44 +01001331 const void __user *inbuf;
Roland Dreiere2773c02005-07-07 17:57:10 -07001332 void __user *outbuf;
1333 size_t inlen;
1334 size_t outlen;
1335};
1336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337struct ib_pd {
Jason Gunthorpe96249d72015-08-05 14:14:45 -06001338 u32 local_dma_lkey;
Roland Dreiere2773c02005-07-07 17:57:10 -07001339 struct ib_device *device;
1340 struct ib_uobject *uobject;
1341 atomic_t usecnt; /* count all resources */
Jason Gunthorpe96249d72015-08-05 14:14:45 -06001342 struct ib_mr *local_mr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343};
1344
Sean Hefty59991f92011-05-23 17:52:46 -07001345struct ib_xrcd {
1346 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001347 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -07001348 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001349
1350 struct mutex tgt_qp_mutex;
1351 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -07001352};
1353
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354struct ib_ah {
1355 struct ib_device *device;
1356 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001357 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358};
1359
1360typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1361
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001362enum ib_poll_context {
1363 IB_POLL_DIRECT, /* caller context, no hw completions */
1364 IB_POLL_SOFTIRQ, /* poll from softirq context */
1365 IB_POLL_WORKQUEUE, /* poll from workqueue */
1366};
1367
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -07001369 struct ib_device *device;
1370 struct ib_uobject *uobject;
1371 ib_comp_handler comp_handler;
1372 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -07001373 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -07001374 int cqe;
1375 atomic_t usecnt; /* count number of work queues */
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001376 enum ib_poll_context poll_ctx;
1377 struct ib_wc *wc;
1378 union {
1379 struct irq_poll iop;
1380 struct work_struct work;
1381 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382};
1383
1384struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -07001385 struct ib_device *device;
1386 struct ib_pd *pd;
1387 struct ib_uobject *uobject;
1388 void (*event_handler)(struct ib_event *, void *);
1389 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -07001390 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -07001392
1393 union {
1394 struct {
1395 struct ib_xrcd *xrcd;
1396 struct ib_cq *cq;
1397 u32 srq_num;
1398 } xrc;
1399 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400};
1401
1402struct ib_qp {
1403 struct ib_device *device;
1404 struct ib_pd *pd;
1405 struct ib_cq *send_cq;
1406 struct ib_cq *recv_cq;
1407 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001408 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -07001409 struct list_head xrcd_list;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001410 /* count times opened, mcast attaches, flow attaches */
1411 atomic_t usecnt;
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001412 struct list_head open_list;
1413 struct ib_qp *real_qp;
Roland Dreiere2773c02005-07-07 17:57:10 -07001414 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 void (*event_handler)(struct ib_event *, void *);
1416 void *qp_context;
1417 u32 qp_num;
1418 enum ib_qp_type qp_type;
1419};
1420
1421struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -07001422 struct ib_device *device;
1423 struct ib_pd *pd;
1424 struct ib_uobject *uobject;
1425 u32 lkey;
1426 u32 rkey;
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03001427 u64 iova;
1428 u32 length;
1429 unsigned int page_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430};
1431
1432struct ib_mw {
1433 struct ib_device *device;
1434 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001435 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 u32 rkey;
Shani Michaeli7083e422013-02-06 16:19:12 +00001437 enum ib_mw_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438};
1439
1440struct ib_fmr {
1441 struct ib_device *device;
1442 struct ib_pd *pd;
1443 struct list_head list;
1444 u32 lkey;
1445 u32 rkey;
1446};
1447
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001448/* Supported steering options */
1449enum ib_flow_attr_type {
1450 /* steering according to rule specifications */
1451 IB_FLOW_ATTR_NORMAL = 0x0,
1452 /* default unicast and multicast rule -
1453 * receive all Eth traffic which isn't steered to any QP
1454 */
1455 IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1456 /* default multicast rule -
1457 * receive all Eth multicast traffic which isn't steered to any QP
1458 */
1459 IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1460 /* sniffer rule - receive all port traffic */
1461 IB_FLOW_ATTR_SNIFFER = 0x3
1462};
1463
1464/* Supported steering header types */
1465enum ib_flow_spec_type {
1466 /* L2 headers*/
1467 IB_FLOW_SPEC_ETH = 0x20,
Matan Barak240ae002013-11-07 15:25:13 +02001468 IB_FLOW_SPEC_IB = 0x22,
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001469 /* L3 header*/
1470 IB_FLOW_SPEC_IPV4 = 0x30,
1471 /* L4 headers*/
1472 IB_FLOW_SPEC_TCP = 0x40,
1473 IB_FLOW_SPEC_UDP = 0x41
1474};
Matan Barak240ae002013-11-07 15:25:13 +02001475#define IB_FLOW_SPEC_LAYER_MASK 0xF0
Matan Barak22878db2013-09-01 18:39:52 +03001476#define IB_FLOW_SPEC_SUPPORT_LAYERS 4
1477
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001478/* Flow steering rule priority is set according to it's domain.
1479 * Lower domain value means higher priority.
1480 */
1481enum ib_flow_domain {
1482 IB_FLOW_DOMAIN_USER,
1483 IB_FLOW_DOMAIN_ETHTOOL,
1484 IB_FLOW_DOMAIN_RFS,
1485 IB_FLOW_DOMAIN_NIC,
1486 IB_FLOW_DOMAIN_NUM /* Must be last */
1487};
1488
1489struct ib_flow_eth_filter {
1490 u8 dst_mac[6];
1491 u8 src_mac[6];
1492 __be16 ether_type;
1493 __be16 vlan_tag;
1494};
1495
1496struct ib_flow_spec_eth {
1497 enum ib_flow_spec_type type;
1498 u16 size;
1499 struct ib_flow_eth_filter val;
1500 struct ib_flow_eth_filter mask;
1501};
1502
Matan Barak240ae002013-11-07 15:25:13 +02001503struct ib_flow_ib_filter {
1504 __be16 dlid;
1505 __u8 sl;
1506};
1507
1508struct ib_flow_spec_ib {
1509 enum ib_flow_spec_type type;
1510 u16 size;
1511 struct ib_flow_ib_filter val;
1512 struct ib_flow_ib_filter mask;
1513};
1514
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001515struct ib_flow_ipv4_filter {
1516 __be32 src_ip;
1517 __be32 dst_ip;
1518};
1519
1520struct ib_flow_spec_ipv4 {
1521 enum ib_flow_spec_type type;
1522 u16 size;
1523 struct ib_flow_ipv4_filter val;
1524 struct ib_flow_ipv4_filter mask;
1525};
1526
1527struct ib_flow_tcp_udp_filter {
1528 __be16 dst_port;
1529 __be16 src_port;
1530};
1531
1532struct ib_flow_spec_tcp_udp {
1533 enum ib_flow_spec_type type;
1534 u16 size;
1535 struct ib_flow_tcp_udp_filter val;
1536 struct ib_flow_tcp_udp_filter mask;
1537};
1538
1539union ib_flow_spec {
1540 struct {
1541 enum ib_flow_spec_type type;
1542 u16 size;
1543 };
1544 struct ib_flow_spec_eth eth;
Matan Barak240ae002013-11-07 15:25:13 +02001545 struct ib_flow_spec_ib ib;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001546 struct ib_flow_spec_ipv4 ipv4;
1547 struct ib_flow_spec_tcp_udp tcp_udp;
1548};
1549
1550struct ib_flow_attr {
1551 enum ib_flow_attr_type type;
1552 u16 size;
1553 u16 priority;
1554 u32 flags;
1555 u8 num_of_specs;
1556 u8 port;
1557 /* Following are the optional layers according to user request
1558 * struct ib_flow_spec_xxx
1559 * struct ib_flow_spec_yyy
1560 */
1561};
1562
1563struct ib_flow {
1564 struct ib_qp *qp;
1565 struct ib_uobject *uobject;
1566};
1567
Ira Weiny4cd7c942015-06-06 14:38:31 -04001568struct ib_mad_hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569struct ib_grh;
1570
1571enum ib_process_mad_flags {
1572 IB_MAD_IGNORE_MKEY = 1,
1573 IB_MAD_IGNORE_BKEY = 2,
1574 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1575};
1576
1577enum ib_mad_result {
1578 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
1579 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
1580 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
1581 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
1582};
1583
1584#define IB_DEVICE_NAME_MAX 64
1585
1586struct ib_cache {
1587 rwlock_t lock;
1588 struct ib_event_handler event_handler;
1589 struct ib_pkey_cache **pkey_cache;
Matan Barak03db3a22015-07-30 18:33:26 +03001590 struct ib_gid_table **gid_cache;
Jack Morgenstein6fb9cdb2006-06-17 20:37:34 -07001591 u8 *lmc_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592};
1593
Ralph Campbell9b513092006-12-12 14:27:41 -08001594struct ib_dma_mapping_ops {
1595 int (*mapping_error)(struct ib_device *dev,
1596 u64 dma_addr);
1597 u64 (*map_single)(struct ib_device *dev,
1598 void *ptr, size_t size,
1599 enum dma_data_direction direction);
1600 void (*unmap_single)(struct ib_device *dev,
1601 u64 addr, size_t size,
1602 enum dma_data_direction direction);
1603 u64 (*map_page)(struct ib_device *dev,
1604 struct page *page, unsigned long offset,
1605 size_t size,
1606 enum dma_data_direction direction);
1607 void (*unmap_page)(struct ib_device *dev,
1608 u64 addr, size_t size,
1609 enum dma_data_direction direction);
1610 int (*map_sg)(struct ib_device *dev,
1611 struct scatterlist *sg, int nents,
1612 enum dma_data_direction direction);
1613 void (*unmap_sg)(struct ib_device *dev,
1614 struct scatterlist *sg, int nents,
1615 enum dma_data_direction direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08001616 void (*sync_single_for_cpu)(struct ib_device *dev,
1617 u64 dma_handle,
1618 size_t size,
Dotan Barak4deccd62008-07-14 23:48:44 -07001619 enum dma_data_direction dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08001620 void (*sync_single_for_device)(struct ib_device *dev,
1621 u64 dma_handle,
1622 size_t size,
1623 enum dma_data_direction dir);
1624 void *(*alloc_coherent)(struct ib_device *dev,
1625 size_t size,
1626 u64 *dma_handle,
1627 gfp_t flag);
1628 void (*free_coherent)(struct ib_device *dev,
1629 size_t size, void *cpu_addr,
1630 u64 dma_handle);
1631};
1632
Tom Tucker07ebafb2006-08-03 16:02:42 -05001633struct iw_cm_verbs;
1634
Ira Weiny77386132015-05-13 20:02:58 -04001635struct ib_port_immutable {
1636 int pkey_tbl_len;
1637 int gid_tbl_len;
Ira Weinyf9b22e32015-05-13 20:02:59 -04001638 u32 core_cap_flags;
Ira Weiny337877a2015-06-06 14:38:29 -04001639 u32 max_mad_size;
Ira Weiny77386132015-05-13 20:02:58 -04001640};
1641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642struct ib_device {
1643 struct device *dma_device;
1644
1645 char name[IB_DEVICE_NAME_MAX];
1646
1647 struct list_head event_handler_list;
1648 spinlock_t event_handler_lock;
1649
Alexander Chiang17a55f72010-02-02 19:09:16 +00001650 spinlock_t client_data_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 struct list_head core_list;
Haggai Eran7c1eb452015-07-30 17:50:14 +03001652 /* Access to the client_data_list is protected by the client_data_lock
1653 * spinlock and the lists_rwsem read-write semaphore */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 struct list_head client_data_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
1656 struct ib_cache cache;
Ira Weiny77386132015-05-13 20:02:58 -04001657 /**
1658 * port_immutable is indexed by port number
1659 */
1660 struct ib_port_immutable *port_immutable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03001662 int num_comp_vectors;
1663
Tom Tucker07ebafb2006-08-03 16:02:42 -05001664 struct iw_cm_verbs *iwcm;
1665
Steve Wise7f624d02008-07-14 23:48:48 -07001666 int (*get_protocol_stats)(struct ib_device *device,
1667 union rdma_protocol_stats *stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 int (*query_device)(struct ib_device *device,
Matan Barak2528e332015-06-11 16:35:25 +03001669 struct ib_device_attr *device_attr,
1670 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 int (*query_port)(struct ib_device *device,
1672 u8 port_num,
1673 struct ib_port_attr *port_attr);
Eli Cohena3f5ada2010-09-27 17:51:10 -07001674 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
1675 u8 port_num);
Matan Barak03db3a22015-07-30 18:33:26 +03001676 /* When calling get_netdev, the HW vendor's driver should return the
1677 * net device of device @device at port @port_num or NULL if such
1678 * a net device doesn't exist. The vendor driver should call dev_hold
1679 * on this net device. The HW vendor's device driver must guarantee
1680 * that this function returns NULL before the net device reaches
1681 * NETDEV_UNREGISTER_FINAL state.
1682 */
1683 struct net_device *(*get_netdev)(struct ib_device *device,
1684 u8 port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 int (*query_gid)(struct ib_device *device,
1686 u8 port_num, int index,
1687 union ib_gid *gid);
Matan Barak03db3a22015-07-30 18:33:26 +03001688 /* When calling add_gid, the HW vendor's driver should
1689 * add the gid of device @device at gid index @index of
1690 * port @port_num to be @gid. Meta-info of that gid (for example,
1691 * the network device related to this gid is available
1692 * at @attr. @context allows the HW vendor driver to store extra
1693 * information together with a GID entry. The HW vendor may allocate
1694 * memory to contain this information and store it in @context when a
1695 * new GID entry is written to. Params are consistent until the next
1696 * call of add_gid or delete_gid. The function should return 0 on
1697 * success or error otherwise. The function could be called
1698 * concurrently for different ports. This function is only called
1699 * when roce_gid_table is used.
1700 */
1701 int (*add_gid)(struct ib_device *device,
1702 u8 port_num,
1703 unsigned int index,
1704 const union ib_gid *gid,
1705 const struct ib_gid_attr *attr,
1706 void **context);
1707 /* When calling del_gid, the HW vendor's driver should delete the
1708 * gid of device @device at gid index @index of port @port_num.
1709 * Upon the deletion of a GID entry, the HW vendor must free any
1710 * allocated memory. The caller will clear @context afterwards.
1711 * This function is only called when roce_gid_table is used.
1712 */
1713 int (*del_gid)(struct ib_device *device,
1714 u8 port_num,
1715 unsigned int index,
1716 void **context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 int (*query_pkey)(struct ib_device *device,
1718 u8 port_num, u16 index, u16 *pkey);
1719 int (*modify_device)(struct ib_device *device,
1720 int device_modify_mask,
1721 struct ib_device_modify *device_modify);
1722 int (*modify_port)(struct ib_device *device,
1723 u8 port_num, int port_modify_mask,
1724 struct ib_port_modify *port_modify);
Roland Dreiere2773c02005-07-07 17:57:10 -07001725 struct ib_ucontext * (*alloc_ucontext)(struct ib_device *device,
1726 struct ib_udata *udata);
1727 int (*dealloc_ucontext)(struct ib_ucontext *context);
1728 int (*mmap)(struct ib_ucontext *context,
1729 struct vm_area_struct *vma);
1730 struct ib_pd * (*alloc_pd)(struct ib_device *device,
1731 struct ib_ucontext *context,
1732 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 int (*dealloc_pd)(struct ib_pd *pd);
1734 struct ib_ah * (*create_ah)(struct ib_pd *pd,
1735 struct ib_ah_attr *ah_attr);
1736 int (*modify_ah)(struct ib_ah *ah,
1737 struct ib_ah_attr *ah_attr);
1738 int (*query_ah)(struct ib_ah *ah,
1739 struct ib_ah_attr *ah_attr);
1740 int (*destroy_ah)(struct ib_ah *ah);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001741 struct ib_srq * (*create_srq)(struct ib_pd *pd,
1742 struct ib_srq_init_attr *srq_init_attr,
1743 struct ib_udata *udata);
1744 int (*modify_srq)(struct ib_srq *srq,
1745 struct ib_srq_attr *srq_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001746 enum ib_srq_attr_mask srq_attr_mask,
1747 struct ib_udata *udata);
Roland Dreierd41fcc62005-08-18 12:23:08 -07001748 int (*query_srq)(struct ib_srq *srq,
1749 struct ib_srq_attr *srq_attr);
1750 int (*destroy_srq)(struct ib_srq *srq);
1751 int (*post_srq_recv)(struct ib_srq *srq,
1752 struct ib_recv_wr *recv_wr,
1753 struct ib_recv_wr **bad_recv_wr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 struct ib_qp * (*create_qp)(struct ib_pd *pd,
Roland Dreiere2773c02005-07-07 17:57:10 -07001755 struct ib_qp_init_attr *qp_init_attr,
1756 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 int (*modify_qp)(struct ib_qp *qp,
1758 struct ib_qp_attr *qp_attr,
Ralph Campbell9bc57e22006-08-11 14:58:09 -07001759 int qp_attr_mask,
1760 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 int (*query_qp)(struct ib_qp *qp,
1762 struct ib_qp_attr *qp_attr,
1763 int qp_attr_mask,
1764 struct ib_qp_init_attr *qp_init_attr);
1765 int (*destroy_qp)(struct ib_qp *qp);
1766 int (*post_send)(struct ib_qp *qp,
1767 struct ib_send_wr *send_wr,
1768 struct ib_send_wr **bad_send_wr);
1769 int (*post_recv)(struct ib_qp *qp,
1770 struct ib_recv_wr *recv_wr,
1771 struct ib_recv_wr **bad_recv_wr);
Matan Barakbcf4c1e2015-06-11 16:35:20 +03001772 struct ib_cq * (*create_cq)(struct ib_device *device,
1773 const struct ib_cq_init_attr *attr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001774 struct ib_ucontext *context,
1775 struct ib_udata *udata);
Eli Cohen2dd57162008-04-16 21:09:33 -07001776 int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1777 u16 cq_period);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 int (*destroy_cq)(struct ib_cq *cq);
Roland Dreier33b9b3e2006-01-30 14:29:21 -08001779 int (*resize_cq)(struct ib_cq *cq, int cqe,
1780 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 int (*poll_cq)(struct ib_cq *cq, int num_entries,
1782 struct ib_wc *wc);
1783 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1784 int (*req_notify_cq)(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07001785 enum ib_cq_notify_flags flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 int (*req_ncomp_notif)(struct ib_cq *cq,
1787 int wc_cnt);
1788 struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
1789 int mr_access_flags);
Roland Dreiere2773c02005-07-07 17:57:10 -07001790 struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
Roland Dreierf7c6a7b2007-03-04 16:15:11 -08001791 u64 start, u64 length,
1792 u64 virt_addr,
Roland Dreiere2773c02005-07-07 17:57:10 -07001793 int mr_access_flags,
1794 struct ib_udata *udata);
Matan Barak7e6edb92014-07-31 11:01:28 +03001795 int (*rereg_user_mr)(struct ib_mr *mr,
1796 int flags,
1797 u64 start, u64 length,
1798 u64 virt_addr,
1799 int mr_access_flags,
1800 struct ib_pd *pd,
1801 struct ib_udata *udata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 int (*dereg_mr)(struct ib_mr *mr);
Sagi Grimberg9bee1782015-07-30 10:32:35 +03001803 struct ib_mr * (*alloc_mr)(struct ib_pd *pd,
1804 enum ib_mr_type mr_type,
1805 u32 max_num_sg);
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03001806 int (*map_mr_sg)(struct ib_mr *mr,
1807 struct scatterlist *sg,
1808 int sg_nents);
Shani Michaeli7083e422013-02-06 16:19:12 +00001809 struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
1810 enum ib_mw_type type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 int (*dealloc_mw)(struct ib_mw *mw);
1812 struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
1813 int mr_access_flags,
1814 struct ib_fmr_attr *fmr_attr);
1815 int (*map_phys_fmr)(struct ib_fmr *fmr,
1816 u64 *page_list, int list_len,
1817 u64 iova);
1818 int (*unmap_fmr)(struct list_head *fmr_list);
1819 int (*dealloc_fmr)(struct ib_fmr *fmr);
1820 int (*attach_mcast)(struct ib_qp *qp,
1821 union ib_gid *gid,
1822 u16 lid);
1823 int (*detach_mcast)(struct ib_qp *qp,
1824 union ib_gid *gid,
1825 u16 lid);
1826 int (*process_mad)(struct ib_device *device,
1827 int process_mad_flags,
1828 u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -04001829 const struct ib_wc *in_wc,
1830 const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -04001831 const struct ib_mad_hdr *in_mad,
1832 size_t in_mad_size,
1833 struct ib_mad_hdr *out_mad,
1834 size_t *out_mad_size,
1835 u16 *out_mad_pkey_index);
Sean Hefty59991f92011-05-23 17:52:46 -07001836 struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
1837 struct ib_ucontext *ucontext,
1838 struct ib_udata *udata);
1839 int (*dealloc_xrcd)(struct ib_xrcd *xrcd);
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001840 struct ib_flow * (*create_flow)(struct ib_qp *qp,
1841 struct ib_flow_attr
1842 *flow_attr,
1843 int domain);
1844 int (*destroy_flow)(struct ib_flow *flow_id);
Sagi Grimberg1b01d332014-02-23 14:19:05 +02001845 int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
1846 struct ib_mr_status *mr_status);
Yishai Hadas036b1062015-08-13 18:32:05 +03001847 void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
Ralph Campbell9b513092006-12-12 14:27:41 -08001849 struct ib_dma_mapping_ops *dma_ops;
1850
Roland Dreiere2773c02005-07-07 17:57:10 -07001851 struct module *owner;
Tony Jonesf4e91eb2008-02-22 00:13:36 +01001852 struct device dev;
Greg Kroah-Hartman35be0682007-12-17 15:54:39 -04001853 struct kobject *ports_parent;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 struct list_head port_list;
1855
1856 enum {
1857 IB_DEV_UNINITIALIZED,
1858 IB_DEV_REGISTERED,
1859 IB_DEV_UNREGISTERED
1860 } reg_state;
1861
Roland Dreier274c0892005-09-29 14:17:48 -07001862 int uverbs_abi_ver;
Alexander Chiang17a55f72010-02-02 19:09:16 +00001863 u64 uverbs_cmd_mask;
Yann Droneaudf21519b2013-11-06 23:21:49 +01001864 u64 uverbs_ex_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07001865
Roland Dreierc5bcbbb2006-02-02 09:47:14 -08001866 char node_desc[64];
Sean Heftycf311cd2006-01-10 07:39:34 -08001867 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07001868 u32 local_dma_lkey;
Hal Rosenstock41390322015-06-29 09:57:00 -04001869 u16 is_switch:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 u8 node_type;
1871 u8 phys_port_cnt;
Ira Weiny3e153a92015-12-18 10:59:44 +02001872 struct ib_device_attr attrs;
Ira Weiny77386132015-05-13 20:02:58 -04001873
1874 /**
1875 * The following mandatory functions are used only at device
1876 * registration. Keep functions such as these at the end of this
1877 * structure to avoid cache line misses when accessing struct ib_device
1878 * in fast paths.
1879 */
1880 int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881};
1882
1883struct ib_client {
1884 char *name;
1885 void (*add) (struct ib_device *);
Haggai Eran7c1eb452015-07-30 17:50:14 +03001886 void (*remove)(struct ib_device *, void *client_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Yotam Kenneth9268f722015-07-30 17:50:15 +03001888 /* Returns the net_dev belonging to this ib_client and matching the
1889 * given parameters.
1890 * @dev: An RDMA device that the net_dev use for communication.
1891 * @port: A physical port number on the RDMA device.
1892 * @pkey: P_Key that the net_dev uses if applicable.
1893 * @gid: A GID that the net_dev uses to communicate.
1894 * @addr: An IP address the net_dev is configured with.
1895 * @client_data: The device's client data set by ib_set_client_data().
1896 *
1897 * An ib_client that implements a net_dev on top of RDMA devices
1898 * (such as IP over IB) should implement this callback, allowing the
1899 * rdma_cm module to find the right net_dev for a given request.
1900 *
1901 * The caller is responsible for calling dev_put on the returned
1902 * netdev. */
1903 struct net_device *(*get_net_dev_by_params)(
1904 struct ib_device *dev,
1905 u8 port,
1906 u16 pkey,
1907 const union ib_gid *gid,
1908 const struct sockaddr *addr,
1909 void *client_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 struct list_head list;
1911};
1912
1913struct ib_device *ib_alloc_device(size_t size);
1914void ib_dealloc_device(struct ib_device *device);
1915
Ralph Campbell9a6edb62010-05-06 17:03:25 -07001916int ib_register_device(struct ib_device *device,
1917 int (*port_callback)(struct ib_device *,
1918 u8, struct kobject *));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919void ib_unregister_device(struct ib_device *device);
1920
1921int ib_register_client (struct ib_client *client);
1922void ib_unregister_client(struct ib_client *client);
1923
1924void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1925void ib_set_client_data(struct ib_device *device, struct ib_client *client,
1926 void *data);
1927
Roland Dreiere2773c02005-07-07 17:57:10 -07001928static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1929{
1930 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1931}
1932
1933static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1934{
Yann Droneaud43c611652015-02-05 22:10:18 +01001935 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
Roland Dreiere2773c02005-07-07 17:57:10 -07001936}
1937
Matan Barak301a7212015-12-15 20:30:10 +02001938static inline bool ib_is_udata_cleared(struct ib_udata *udata,
1939 size_t offset,
1940 size_t len)
1941{
1942 const void __user *p = udata->inbuf + offset;
1943 bool ret = false;
1944 u8 *buf;
1945
1946 if (len > USHRT_MAX)
1947 return false;
1948
1949 buf = kmalloc(len, GFP_KERNEL);
1950 if (!buf)
1951 return false;
1952
1953 if (copy_from_user(buf, p, len))
1954 goto free;
1955
1956 ret = !memchr_inv(buf, 0, len);
1957
1958free:
1959 kfree(buf);
1960 return ret;
1961}
1962
Roland Dreier8a518662006-02-13 12:48:12 -08001963/**
1964 * ib_modify_qp_is_ok - Check that the supplied attribute mask
1965 * contains all required attributes and no attributes not allowed for
1966 * the given QP state transition.
1967 * @cur_state: Current QP state
1968 * @next_state: Next QP state
1969 * @type: QP type
1970 * @mask: Mask of supplied QP attributes
Matan Barakdd5f03b2013-12-12 18:03:11 +02001971 * @ll : link layer of port
Roland Dreier8a518662006-02-13 12:48:12 -08001972 *
1973 * This function is a helper function that a low-level driver's
1974 * modify_qp method can use to validate the consumer's input. It
1975 * checks that cur_state and next_state are valid QP states, that a
1976 * transition from cur_state to next_state is allowed by the IB spec,
1977 * and that the attribute mask supplied is allowed for the transition.
1978 */
1979int ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
Matan Barakdd5f03b2013-12-12 18:03:11 +02001980 enum ib_qp_type type, enum ib_qp_attr_mask mask,
1981 enum rdma_link_layer ll);
Roland Dreier8a518662006-02-13 12:48:12 -08001982
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983int ib_register_event_handler (struct ib_event_handler *event_handler);
1984int ib_unregister_event_handler(struct ib_event_handler *event_handler);
1985void ib_dispatch_event(struct ib_event *event);
1986
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987int ib_query_port(struct ib_device *device,
1988 u8 port_num, struct ib_port_attr *port_attr);
1989
Eli Cohena3f5ada2010-09-27 17:51:10 -07001990enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1991 u8 port_num);
1992
Ira Weiny0cf18d72015-05-13 20:02:55 -04001993/**
Hal Rosenstock41390322015-06-29 09:57:00 -04001994 * rdma_cap_ib_switch - Check if the device is IB switch
1995 * @device: Device to check
1996 *
1997 * Device driver is responsible for setting is_switch bit on
1998 * in ib_device structure at init time.
1999 *
2000 * Return: true if the device is IB switch.
2001 */
2002static inline bool rdma_cap_ib_switch(const struct ib_device *device)
2003{
2004 return device->is_switch;
2005}
2006
2007/**
Ira Weiny0cf18d72015-05-13 20:02:55 -04002008 * rdma_start_port - Return the first valid port number for the device
2009 * specified
2010 *
2011 * @device: Device to be checked
2012 *
2013 * Return start port number
2014 */
2015static inline u8 rdma_start_port(const struct ib_device *device)
2016{
Hal Rosenstock41390322015-06-29 09:57:00 -04002017 return rdma_cap_ib_switch(device) ? 0 : 1;
Ira Weiny0cf18d72015-05-13 20:02:55 -04002018}
2019
2020/**
2021 * rdma_end_port - Return the last valid port number for the device
2022 * specified
2023 *
2024 * @device: Device to be checked
2025 *
2026 * Return last port number
2027 */
2028static inline u8 rdma_end_port(const struct ib_device *device)
2029{
Hal Rosenstock41390322015-06-29 09:57:00 -04002030 return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
Ira Weiny0cf18d72015-05-13 20:02:55 -04002031}
2032
Ira Weiny5ede9282015-05-31 17:15:29 -04002033static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02002034{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002035 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
Michael Wangde66be92015-05-05 14:50:19 +02002036}
2037
Ira Weiny5ede9282015-05-31 17:15:29 -04002038static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02002039{
Matan Barak7766a992015-12-23 14:56:50 +02002040 return device->port_immutable[port_num].core_cap_flags &
2041 (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
2042}
2043
2044static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
2045{
2046 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
2047}
2048
2049static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
2050{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002051 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
Michael Wangde66be92015-05-05 14:50:19 +02002052}
2053
Ira Weiny5ede9282015-05-31 17:15:29 -04002054static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02002055{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002056 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
Michael Wangde66be92015-05-05 14:50:19 +02002057}
2058
Ira Weiny5ede9282015-05-31 17:15:29 -04002059static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02002060{
Matan Barak7766a992015-12-23 14:56:50 +02002061 return rdma_protocol_ib(device, port_num) ||
2062 rdma_protocol_roce(device, port_num);
Michael Wangde66be92015-05-05 14:50:19 +02002063}
2064
Michael Wangc757dea2015-05-05 14:50:32 +02002065/**
Michael Wang296ec002015-05-18 10:41:45 +02002066 * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
Michael Wangc757dea2015-05-05 14:50:32 +02002067 * Management Datagrams.
Michael Wang296ec002015-05-18 10:41:45 +02002068 * @device: Device to check
2069 * @port_num: Port number to check
Michael Wangc757dea2015-05-05 14:50:32 +02002070 *
Michael Wang296ec002015-05-18 10:41:45 +02002071 * Management Datagrams (MAD) are a required part of the InfiniBand
2072 * specification and are supported on all InfiniBand devices. A slightly
2073 * extended version are also supported on OPA interfaces.
Michael Wangc757dea2015-05-05 14:50:32 +02002074 *
Michael Wang296ec002015-05-18 10:41:45 +02002075 * Return: true if the port supports sending/receiving of MAD packets.
Michael Wangc757dea2015-05-05 14:50:32 +02002076 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002077static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
Michael Wangc757dea2015-05-05 14:50:32 +02002078{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002079 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
Michael Wangc757dea2015-05-05 14:50:32 +02002080}
2081
Michael Wang29541e32015-05-05 14:50:33 +02002082/**
Ira Weiny65995fe2015-06-06 14:38:32 -04002083 * rdma_cap_opa_mad - Check if the port of device provides support for OPA
2084 * Management Datagrams.
2085 * @device: Device to check
2086 * @port_num: Port number to check
2087 *
2088 * Intel OmniPath devices extend and/or replace the InfiniBand Management
2089 * datagrams with their own versions. These OPA MADs share many but not all of
2090 * the characteristics of InfiniBand MADs.
2091 *
2092 * OPA MADs differ in the following ways:
2093 *
2094 * 1) MADs are variable size up to 2K
2095 * IBTA defined MADs remain fixed at 256 bytes
2096 * 2) OPA SMPs must carry valid PKeys
2097 * 3) OPA SMP packets are a different format
2098 *
2099 * Return: true if the port supports OPA MAD packet formats.
2100 */
2101static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
2102{
2103 return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD)
2104 == RDMA_CORE_CAP_OPA_MAD;
2105}
2106
2107/**
Michael Wang296ec002015-05-18 10:41:45 +02002108 * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
2109 * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
2110 * @device: Device to check
2111 * @port_num: Port number to check
Michael Wang29541e32015-05-05 14:50:33 +02002112 *
Michael Wang296ec002015-05-18 10:41:45 +02002113 * Each InfiniBand node is required to provide a Subnet Management Agent
2114 * that the subnet manager can access. Prior to the fabric being fully
2115 * configured by the subnet manager, the SMA is accessed via a well known
2116 * interface called the Subnet Management Interface (SMI). This interface
2117 * uses directed route packets to communicate with the SM to get around the
2118 * chicken and egg problem of the SM needing to know what's on the fabric
2119 * in order to configure the fabric, and needing to configure the fabric in
2120 * order to send packets to the devices on the fabric. These directed
2121 * route packets do not need the fabric fully configured in order to reach
2122 * their destination. The SMI is the only method allowed to send
2123 * directed route packets on an InfiniBand fabric.
Michael Wang29541e32015-05-05 14:50:33 +02002124 *
Michael Wang296ec002015-05-18 10:41:45 +02002125 * Return: true if the port provides an SMI.
Michael Wang29541e32015-05-05 14:50:33 +02002126 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002127static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
Michael Wang29541e32015-05-05 14:50:33 +02002128{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002129 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
Michael Wang29541e32015-05-05 14:50:33 +02002130}
2131
Michael Wang72219cea2015-05-05 14:50:34 +02002132/**
2133 * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
2134 * Communication Manager.
Michael Wang296ec002015-05-18 10:41:45 +02002135 * @device: Device to check
2136 * @port_num: Port number to check
Michael Wang72219cea2015-05-05 14:50:34 +02002137 *
Michael Wang296ec002015-05-18 10:41:45 +02002138 * The InfiniBand Communication Manager is one of many pre-defined General
2139 * Service Agents (GSA) that are accessed via the General Service
2140 * Interface (GSI). It's role is to facilitate establishment of connections
2141 * between nodes as well as other management related tasks for established
2142 * connections.
Michael Wang72219cea2015-05-05 14:50:34 +02002143 *
Michael Wang296ec002015-05-18 10:41:45 +02002144 * Return: true if the port supports an IB CM (this does not guarantee that
2145 * a CM is actually running however).
Michael Wang72219cea2015-05-05 14:50:34 +02002146 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002147static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
Michael Wang72219cea2015-05-05 14:50:34 +02002148{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002149 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
Michael Wang72219cea2015-05-05 14:50:34 +02002150}
2151
Michael Wang04215332015-05-05 14:50:35 +02002152/**
2153 * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
2154 * Communication Manager.
Michael Wang296ec002015-05-18 10:41:45 +02002155 * @device: Device to check
2156 * @port_num: Port number to check
Michael Wang04215332015-05-05 14:50:35 +02002157 *
Michael Wang296ec002015-05-18 10:41:45 +02002158 * Similar to above, but specific to iWARP connections which have a different
2159 * managment protocol than InfiniBand.
Michael Wang04215332015-05-05 14:50:35 +02002160 *
Michael Wang296ec002015-05-18 10:41:45 +02002161 * Return: true if the port supports an iWARP CM (this does not guarantee that
2162 * a CM is actually running however).
Michael Wang04215332015-05-05 14:50:35 +02002163 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002164static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
Michael Wang04215332015-05-05 14:50:35 +02002165{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002166 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
Michael Wang04215332015-05-05 14:50:35 +02002167}
2168
Michael Wangfe53ba22015-05-05 14:50:36 +02002169/**
2170 * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
2171 * Subnet Administration.
Michael Wang296ec002015-05-18 10:41:45 +02002172 * @device: Device to check
2173 * @port_num: Port number to check
Michael Wangfe53ba22015-05-05 14:50:36 +02002174 *
Michael Wang296ec002015-05-18 10:41:45 +02002175 * An InfiniBand Subnet Administration (SA) service is a pre-defined General
2176 * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
2177 * fabrics, devices should resolve routes to other hosts by contacting the
2178 * SA to query the proper route.
Michael Wangfe53ba22015-05-05 14:50:36 +02002179 *
Michael Wang296ec002015-05-18 10:41:45 +02002180 * Return: true if the port should act as a client to the fabric Subnet
2181 * Administration interface. This does not imply that the SA service is
2182 * running locally.
Michael Wangfe53ba22015-05-05 14:50:36 +02002183 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002184static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
Michael Wangfe53ba22015-05-05 14:50:36 +02002185{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002186 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
Michael Wangfe53ba22015-05-05 14:50:36 +02002187}
2188
Michael Wanga31ad3b2015-05-05 14:50:37 +02002189/**
2190 * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
2191 * Multicast.
Michael Wang296ec002015-05-18 10:41:45 +02002192 * @device: Device to check
2193 * @port_num: Port number to check
Michael Wanga31ad3b2015-05-05 14:50:37 +02002194 *
Michael Wang296ec002015-05-18 10:41:45 +02002195 * InfiniBand multicast registration is more complex than normal IPv4 or
2196 * IPv6 multicast registration. Each Host Channel Adapter must register
2197 * with the Subnet Manager when it wishes to join a multicast group. It
2198 * should do so only once regardless of how many queue pairs it subscribes
2199 * to this group. And it should leave the group only after all queue pairs
2200 * attached to the group have been detached.
Michael Wanga31ad3b2015-05-05 14:50:37 +02002201 *
Michael Wang296ec002015-05-18 10:41:45 +02002202 * Return: true if the port must undertake the additional adminstrative
2203 * overhead of registering/unregistering with the SM and tracking of the
2204 * total number of queue pairs attached to the multicast group.
Michael Wanga31ad3b2015-05-05 14:50:37 +02002205 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002206static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
Michael Wanga31ad3b2015-05-05 14:50:37 +02002207{
2208 return rdma_cap_ib_sa(device, port_num);
2209}
2210
Michael Wangbc0f1d72015-05-05 14:50:38 +02002211/**
Michael Wang30a74ef2015-05-05 14:50:39 +02002212 * rdma_cap_af_ib - Check if the port of device has the capability
2213 * Native Infiniband Address.
Michael Wang296ec002015-05-18 10:41:45 +02002214 * @device: Device to check
2215 * @port_num: Port number to check
Michael Wang30a74ef2015-05-05 14:50:39 +02002216 *
Michael Wang296ec002015-05-18 10:41:45 +02002217 * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
2218 * GID. RoCE uses a different mechanism, but still generates a GID via
2219 * a prescribed mechanism and port specific data.
Michael Wang30a74ef2015-05-05 14:50:39 +02002220 *
Michael Wang296ec002015-05-18 10:41:45 +02002221 * Return: true if the port uses a GID address to identify devices on the
2222 * network.
Michael Wang30a74ef2015-05-05 14:50:39 +02002223 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002224static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
Michael Wang30a74ef2015-05-05 14:50:39 +02002225{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002226 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
Michael Wang30a74ef2015-05-05 14:50:39 +02002227}
2228
2229/**
Michael Wang227128f2015-05-05 14:50:40 +02002230 * rdma_cap_eth_ah - Check if the port of device has the capability
Michael Wang296ec002015-05-18 10:41:45 +02002231 * Ethernet Address Handle.
2232 * @device: Device to check
2233 * @port_num: Port number to check
Michael Wang227128f2015-05-05 14:50:40 +02002234 *
Michael Wang296ec002015-05-18 10:41:45 +02002235 * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
2236 * to fabricate GIDs over Ethernet/IP specific addresses native to the
2237 * port. Normally, packet headers are generated by the sending host
2238 * adapter, but when sending connectionless datagrams, we must manually
2239 * inject the proper headers for the fabric we are communicating over.
Michael Wang227128f2015-05-05 14:50:40 +02002240 *
Michael Wang296ec002015-05-18 10:41:45 +02002241 * Return: true if we are running as a RoCE port and must force the
2242 * addition of a Global Route Header built from our Ethernet Address
2243 * Handle into our header list for connectionless packets.
Michael Wang227128f2015-05-05 14:50:40 +02002244 */
Ira Weiny5ede9282015-05-31 17:15:29 -04002245static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
Michael Wang227128f2015-05-05 14:50:40 +02002246{
Ira Weinyf9b22e32015-05-13 20:02:59 -04002247 return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
Michael Wang227128f2015-05-05 14:50:40 +02002248}
2249
2250/**
Ira Weiny337877a2015-06-06 14:38:29 -04002251 * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
2252 *
2253 * @device: Device
2254 * @port_num: Port number
2255 *
2256 * This MAD size includes the MAD headers and MAD payload. No other headers
2257 * are included.
2258 *
2259 * Return the max MAD size required by the Port. Will return 0 if the port
2260 * does not support MADs
2261 */
2262static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
2263{
2264 return device->port_immutable[port_num].max_mad_size;
2265}
2266
Matan Barak03db3a22015-07-30 18:33:26 +03002267/**
2268 * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
2269 * @device: Device to check
2270 * @port_num: Port number to check
2271 *
2272 * RoCE GID table mechanism manages the various GIDs for a device.
2273 *
2274 * NOTE: if allocating the port's GID table has failed, this call will still
2275 * return true, but any RoCE GID table API will fail.
2276 *
2277 * Return: true if the port uses RoCE GID table mechanism in order to manage
2278 * its GIDs.
2279 */
2280static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
2281 u8 port_num)
2282{
2283 return rdma_protocol_roce(device, port_num) &&
2284 device->add_gid && device->del_gid;
2285}
2286
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287int ib_query_gid(struct ib_device *device,
Matan Barak55ee3ab2015-10-15 18:38:45 +03002288 u8 port_num, int index, union ib_gid *gid,
2289 struct ib_gid_attr *attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
2291int ib_query_pkey(struct ib_device *device,
2292 u8 port_num, u16 index, u16 *pkey);
2293
2294int ib_modify_device(struct ib_device *device,
2295 int device_modify_mask,
2296 struct ib_device_modify *device_modify);
2297
2298int ib_modify_port(struct ib_device *device,
2299 u8 port_num, int port_modify_mask,
2300 struct ib_port_modify *port_modify);
2301
Yosef Etigin5eb620c2007-05-14 07:26:51 +03002302int ib_find_gid(struct ib_device *device, union ib_gid *gid,
Matan Barakb39ffa12015-12-23 14:56:47 +02002303 enum ib_gid_type gid_type, struct net_device *ndev,
2304 u8 *port_num, u16 *index);
Yosef Etigin5eb620c2007-05-14 07:26:51 +03002305
2306int ib_find_pkey(struct ib_device *device,
2307 u8 port_num, u16 pkey, u16 *index);
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309struct ib_pd *ib_alloc_pd(struct ib_device *device);
2310
Jason Gunthorpe7dd78642015-08-05 14:34:31 -06002311void ib_dealloc_pd(struct ib_pd *pd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
2313/**
2314 * ib_create_ah - Creates an address handle for the given address vector.
2315 * @pd: The protection domain associated with the address handle.
2316 * @ah_attr: The attributes of the address vector.
2317 *
2318 * The address handle is used to reference a local or global destination
2319 * in all UD QP post sends.
2320 */
2321struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
2322
2323/**
Sean Hefty4e00d692006-06-17 20:37:39 -07002324 * ib_init_ah_from_wc - Initializes address handle attributes from a
2325 * work completion.
2326 * @device: Device on which the received message arrived.
2327 * @port_num: Port on which the received message arrived.
2328 * @wc: Work completion associated with the received message.
2329 * @grh: References the received global route header. This parameter is
2330 * ignored unless the work completion indicates that the GRH is valid.
2331 * @ah_attr: Returned attributes that can be used when creating an address
2332 * handle for replying to the message.
2333 */
Ira Weiny73cdaae2015-05-31 17:15:31 -04002334int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
2335 const struct ib_wc *wc, const struct ib_grh *grh,
2336 struct ib_ah_attr *ah_attr);
Sean Hefty4e00d692006-06-17 20:37:39 -07002337
2338/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07002339 * ib_create_ah_from_wc - Creates an address handle associated with the
2340 * sender of the specified work completion.
2341 * @pd: The protection domain associated with the address handle.
2342 * @wc: Work completion information associated with a received message.
2343 * @grh: References the received global route header. This parameter is
2344 * ignored unless the work completion indicates that the GRH is valid.
2345 * @port_num: The outbound port number to associate with the address.
2346 *
2347 * The address handle is used to reference a local or global destination
2348 * in all UD QP post sends.
2349 */
Ira Weiny73cdaae2015-05-31 17:15:31 -04002350struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
2351 const struct ib_grh *grh, u8 port_num);
Hal Rosenstock513789e2005-07-27 11:45:34 -07002352
2353/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 * ib_modify_ah - Modifies the address vector associated with an address
2355 * handle.
2356 * @ah: The address handle to modify.
2357 * @ah_attr: The new address vector attributes to associate with the
2358 * address handle.
2359 */
2360int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2361
2362/**
2363 * ib_query_ah - Queries the address vector associated with an address
2364 * handle.
2365 * @ah: The address handle to query.
2366 * @ah_attr: The address vector attributes associated with the address
2367 * handle.
2368 */
2369int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2370
2371/**
2372 * ib_destroy_ah - Destroys an address handle.
2373 * @ah: The address handle to destroy.
2374 */
2375int ib_destroy_ah(struct ib_ah *ah);
2376
2377/**
Roland Dreierd41fcc62005-08-18 12:23:08 -07002378 * ib_create_srq - Creates a SRQ associated with the specified protection
2379 * domain.
2380 * @pd: The protection domain associated with the SRQ.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08002381 * @srq_init_attr: A list of initial attributes required to create the
2382 * SRQ. If SRQ creation succeeds, then the attributes are updated to
2383 * the actual capabilities of the created SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07002384 *
2385 * srq_attr->max_wr and srq_attr->max_sge are read the determine the
2386 * requested size of the SRQ, and set to the actual values allocated
2387 * on return. If ib_create_srq() succeeds, then max_wr and max_sge
2388 * will always be at least as large as the requested values.
2389 */
2390struct ib_srq *ib_create_srq(struct ib_pd *pd,
2391 struct ib_srq_init_attr *srq_init_attr);
2392
2393/**
2394 * ib_modify_srq - Modifies the attributes for the specified SRQ.
2395 * @srq: The SRQ to modify.
2396 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
2397 * the current values of selected SRQ attributes are returned.
2398 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
2399 * are being modified.
2400 *
2401 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
2402 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
2403 * the number of receives queued drops below the limit.
2404 */
2405int ib_modify_srq(struct ib_srq *srq,
2406 struct ib_srq_attr *srq_attr,
2407 enum ib_srq_attr_mask srq_attr_mask);
2408
2409/**
2410 * ib_query_srq - Returns the attribute list and current values for the
2411 * specified SRQ.
2412 * @srq: The SRQ to query.
2413 * @srq_attr: The attributes of the specified SRQ.
2414 */
2415int ib_query_srq(struct ib_srq *srq,
2416 struct ib_srq_attr *srq_attr);
2417
2418/**
2419 * ib_destroy_srq - Destroys the specified SRQ.
2420 * @srq: The SRQ to destroy.
2421 */
2422int ib_destroy_srq(struct ib_srq *srq);
2423
2424/**
2425 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
2426 * @srq: The SRQ to post the work request on.
2427 * @recv_wr: A list of work requests to post on the receive queue.
2428 * @bad_recv_wr: On an immediate failure, this parameter will reference
2429 * the work request that failed to be posted on the QP.
2430 */
2431static inline int ib_post_srq_recv(struct ib_srq *srq,
2432 struct ib_recv_wr *recv_wr,
2433 struct ib_recv_wr **bad_recv_wr)
2434{
2435 return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
2436}
2437
2438/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 * ib_create_qp - Creates a QP associated with the specified protection
2440 * domain.
2441 * @pd: The protection domain associated with the QP.
Dotan Barakabb6e9b2006-02-23 12:13:51 -08002442 * @qp_init_attr: A list of initial attributes required to create the
2443 * QP. If QP creation succeeds, then the attributes are updated to
2444 * the actual capabilities of the created QP.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 */
2446struct ib_qp *ib_create_qp(struct ib_pd *pd,
2447 struct ib_qp_init_attr *qp_init_attr);
2448
2449/**
2450 * ib_modify_qp - Modifies the attributes for the specified QP and then
2451 * transitions the QP to the given state.
2452 * @qp: The QP to modify.
2453 * @qp_attr: On input, specifies the QP attributes to modify. On output,
2454 * the current values of selected QP attributes are returned.
2455 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
2456 * are being modified.
2457 */
2458int ib_modify_qp(struct ib_qp *qp,
2459 struct ib_qp_attr *qp_attr,
2460 int qp_attr_mask);
2461
2462/**
2463 * ib_query_qp - Returns the attribute list and current values for the
2464 * specified QP.
2465 * @qp: The QP to query.
2466 * @qp_attr: The attributes of the specified QP.
2467 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
2468 * @qp_init_attr: Additional attributes of the selected QP.
2469 *
2470 * The qp_attr_mask may be used to limit the query to gathering only the
2471 * selected attributes.
2472 */
2473int ib_query_qp(struct ib_qp *qp,
2474 struct ib_qp_attr *qp_attr,
2475 int qp_attr_mask,
2476 struct ib_qp_init_attr *qp_init_attr);
2477
2478/**
2479 * ib_destroy_qp - Destroys the specified QP.
2480 * @qp: The QP to destroy.
2481 */
2482int ib_destroy_qp(struct ib_qp *qp);
2483
2484/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002485 * ib_open_qp - Obtain a reference to an existing sharable QP.
2486 * @xrcd - XRC domain
2487 * @qp_open_attr: Attributes identifying the QP to open.
2488 *
2489 * Returns a reference to a sharable QP.
2490 */
2491struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
2492 struct ib_qp_open_attr *qp_open_attr);
2493
2494/**
2495 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07002496 * @qp: The QP handle to release
2497 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002498 * The opened QP handle is released by the caller. The underlying
2499 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07002500 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07002501int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07002502
2503/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 * ib_post_send - Posts a list of work requests to the send queue of
2505 * the specified QP.
2506 * @qp: The QP to post the work request on.
2507 * @send_wr: A list of work requests to post on the send queue.
2508 * @bad_send_wr: On an immediate failure, this parameter will reference
2509 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08002510 *
2511 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
2512 * error is returned, the QP state shall not be affected,
2513 * ib_post_send() will return an immediate error after queueing any
2514 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 */
2516static inline int ib_post_send(struct ib_qp *qp,
2517 struct ib_send_wr *send_wr,
2518 struct ib_send_wr **bad_send_wr)
2519{
2520 return qp->device->post_send(qp, send_wr, bad_send_wr);
2521}
2522
2523/**
2524 * ib_post_recv - Posts a list of work requests to the receive queue of
2525 * the specified QP.
2526 * @qp: The QP to post the work request on.
2527 * @recv_wr: A list of work requests to post on the receive queue.
2528 * @bad_recv_wr: On an immediate failure, this parameter will reference
2529 * the work request that failed to be posted on the QP.
2530 */
2531static inline int ib_post_recv(struct ib_qp *qp,
2532 struct ib_recv_wr *recv_wr,
2533 struct ib_recv_wr **bad_recv_wr)
2534{
2535 return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
2536}
2537
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08002538struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
2539 int nr_cqe, int comp_vector, enum ib_poll_context poll_ctx);
2540void ib_free_cq(struct ib_cq *cq);
2541int ib_process_cq_direct(struct ib_cq *cq, int budget);
2542
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543/**
2544 * ib_create_cq - Creates a CQ on the specified device.
2545 * @device: The device on which to create the CQ.
2546 * @comp_handler: A user-specified callback that is invoked when a
2547 * completion event occurs on the CQ.
2548 * @event_handler: A user-specified callback that is invoked when an
2549 * asynchronous event not associated with a completion occurs on the CQ.
2550 * @cq_context: Context associated with the CQ returned to the user via
2551 * the associated completion and event handlers.
Matan Barak8e372102015-06-11 16:35:21 +03002552 * @cq_attr: The attributes the CQ should be created upon.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 *
2554 * Users can examine the cq structure to determine the actual CQ size.
2555 */
2556struct ib_cq *ib_create_cq(struct ib_device *device,
2557 ib_comp_handler comp_handler,
2558 void (*event_handler)(struct ib_event *, void *),
Matan Barak8e372102015-06-11 16:35:21 +03002559 void *cq_context,
2560 const struct ib_cq_init_attr *cq_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
2562/**
2563 * ib_resize_cq - Modifies the capacity of the CQ.
2564 * @cq: The CQ to resize.
2565 * @cqe: The minimum size of the CQ.
2566 *
2567 * Users can examine the cq structure to determine the actual CQ size.
2568 */
2569int ib_resize_cq(struct ib_cq *cq, int cqe);
2570
2571/**
Eli Cohen2dd57162008-04-16 21:09:33 -07002572 * ib_modify_cq - Modifies moderation params of the CQ
2573 * @cq: The CQ to modify.
2574 * @cq_count: number of CQEs that will trigger an event
2575 * @cq_period: max period of time in usec before triggering an event
2576 *
2577 */
2578int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
2579
2580/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 * ib_destroy_cq - Destroys the specified CQ.
2582 * @cq: The CQ to destroy.
2583 */
2584int ib_destroy_cq(struct ib_cq *cq);
2585
2586/**
2587 * ib_poll_cq - poll a CQ for completion(s)
2588 * @cq:the CQ being polled
2589 * @num_entries:maximum number of completions to return
2590 * @wc:array of at least @num_entries &struct ib_wc where completions
2591 * will be returned
2592 *
2593 * Poll a CQ for (possibly multiple) completions. If the return value
2594 * is < 0, an error occurred. If the return value is >= 0, it is the
2595 * number of completions returned. If the return value is
2596 * non-negative and < num_entries, then the CQ was emptied.
2597 */
2598static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
2599 struct ib_wc *wc)
2600{
2601 return cq->device->poll_cq(cq, num_entries, wc);
2602}
2603
2604/**
2605 * ib_peek_cq - Returns the number of unreaped completions currently
2606 * on the specified CQ.
2607 * @cq: The CQ to peek.
2608 * @wc_cnt: A minimum number of unreaped completions to check for.
2609 *
2610 * If the number of unreaped completions is greater than or equal to wc_cnt,
2611 * this function returns wc_cnt, otherwise, it returns the actual number of
2612 * unreaped completions.
2613 */
2614int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
2615
2616/**
2617 * ib_req_notify_cq - Request completion notification on a CQ.
2618 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07002619 * @flags:
2620 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
2621 * to request an event on the next solicited event or next work
2622 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
2623 * may also be |ed in to request a hint about missed events, as
2624 * described below.
2625 *
2626 * Return Value:
2627 * < 0 means an error occurred while requesting notification
2628 * == 0 means notification was requested successfully, and if
2629 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
2630 * were missed and it is safe to wait for another event. In
2631 * this case is it guaranteed that any work completions added
2632 * to the CQ since the last CQ poll will trigger a completion
2633 * notification event.
2634 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
2635 * in. It means that the consumer must poll the CQ again to
2636 * make sure it is empty to avoid missing an event because of a
2637 * race between requesting notification and an entry being
2638 * added to the CQ. This return value means it is possible
2639 * (but not guaranteed) that a work completion has been added
2640 * to the CQ since the last poll without triggering a
2641 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 */
2643static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07002644 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645{
Roland Dreiered23a722007-05-06 21:02:48 -07002646 return cq->device->req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647}
2648
2649/**
2650 * ib_req_ncomp_notif - Request completion notification when there are
2651 * at least the specified number of unreaped completions on the CQ.
2652 * @cq: The CQ to generate an event for.
2653 * @wc_cnt: The number of unreaped completions that should be on the
2654 * CQ before an event is generated.
2655 */
2656static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
2657{
2658 return cq->device->req_ncomp_notif ?
2659 cq->device->req_ncomp_notif(cq, wc_cnt) :
2660 -ENOSYS;
2661}
2662
2663/**
2664 * ib_get_dma_mr - Returns a memory region for system memory that is
2665 * usable for DMA.
2666 * @pd: The protection domain associated with the memory region.
2667 * @mr_access_flags: Specifies the memory access rights.
Ralph Campbell9b513092006-12-12 14:27:41 -08002668 *
2669 * Note that the ib_dma_*() functions defined below must be used
2670 * to create/destroy addresses used with the Lkey or Rkey returned
2671 * by ib_get_dma_mr().
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 */
2673struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
2674
2675/**
Ralph Campbell9b513092006-12-12 14:27:41 -08002676 * ib_dma_mapping_error - check a DMA addr for error
2677 * @dev: The device for which the dma_addr was created
2678 * @dma_addr: The DMA address to check
2679 */
2680static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
2681{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002682 if (dev->dma_ops)
2683 return dev->dma_ops->mapping_error(dev, dma_addr);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07002684 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08002685}
2686
2687/**
2688 * ib_dma_map_single - Map a kernel virtual address to DMA address
2689 * @dev: The device for which the dma_addr is to be created
2690 * @cpu_addr: The kernel virtual address
2691 * @size: The size of the region in bytes
2692 * @direction: The direction of the DMA
2693 */
2694static inline u64 ib_dma_map_single(struct ib_device *dev,
2695 void *cpu_addr, size_t size,
2696 enum dma_data_direction direction)
2697{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002698 if (dev->dma_ops)
2699 return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
2700 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002701}
2702
2703/**
2704 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
2705 * @dev: The device for which the DMA address was created
2706 * @addr: The DMA address
2707 * @size: The size of the region in bytes
2708 * @direction: The direction of the DMA
2709 */
2710static inline void ib_dma_unmap_single(struct ib_device *dev,
2711 u64 addr, size_t size,
2712 enum dma_data_direction direction)
2713{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002714 if (dev->dma_ops)
2715 dev->dma_ops->unmap_single(dev, addr, size, direction);
2716 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002717 dma_unmap_single(dev->dma_device, addr, size, direction);
2718}
2719
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002720static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
2721 void *cpu_addr, size_t size,
2722 enum dma_data_direction direction,
2723 struct dma_attrs *attrs)
2724{
2725 return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
2726 direction, attrs);
2727}
2728
2729static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
2730 u64 addr, size_t size,
2731 enum dma_data_direction direction,
2732 struct dma_attrs *attrs)
2733{
2734 return dma_unmap_single_attrs(dev->dma_device, addr, size,
2735 direction, attrs);
2736}
2737
Ralph Campbell9b513092006-12-12 14:27:41 -08002738/**
2739 * ib_dma_map_page - Map a physical page to DMA address
2740 * @dev: The device for which the dma_addr is to be created
2741 * @page: The page to be mapped
2742 * @offset: The offset within the page
2743 * @size: The size of the region in bytes
2744 * @direction: The direction of the DMA
2745 */
2746static inline u64 ib_dma_map_page(struct ib_device *dev,
2747 struct page *page,
2748 unsigned long offset,
2749 size_t size,
2750 enum dma_data_direction direction)
2751{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002752 if (dev->dma_ops)
2753 return dev->dma_ops->map_page(dev, page, offset, size, direction);
2754 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002755}
2756
2757/**
2758 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
2759 * @dev: The device for which the DMA address was created
2760 * @addr: The DMA address
2761 * @size: The size of the region in bytes
2762 * @direction: The direction of the DMA
2763 */
2764static inline void ib_dma_unmap_page(struct ib_device *dev,
2765 u64 addr, size_t size,
2766 enum dma_data_direction direction)
2767{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002768 if (dev->dma_ops)
2769 dev->dma_ops->unmap_page(dev, addr, size, direction);
2770 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002771 dma_unmap_page(dev->dma_device, addr, size, direction);
2772}
2773
2774/**
2775 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
2776 * @dev: The device for which the DMA addresses are to be created
2777 * @sg: The array of scatter/gather entries
2778 * @nents: The number of scatter/gather entries
2779 * @direction: The direction of the DMA
2780 */
2781static inline int ib_dma_map_sg(struct ib_device *dev,
2782 struct scatterlist *sg, int nents,
2783 enum dma_data_direction direction)
2784{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002785 if (dev->dma_ops)
2786 return dev->dma_ops->map_sg(dev, sg, nents, direction);
2787 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08002788}
2789
2790/**
2791 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
2792 * @dev: The device for which the DMA addresses were created
2793 * @sg: The array of scatter/gather entries
2794 * @nents: The number of scatter/gather entries
2795 * @direction: The direction of the DMA
2796 */
2797static inline void ib_dma_unmap_sg(struct ib_device *dev,
2798 struct scatterlist *sg, int nents,
2799 enum dma_data_direction direction)
2800{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002801 if (dev->dma_ops)
2802 dev->dma_ops->unmap_sg(dev, sg, nents, direction);
2803 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002804 dma_unmap_sg(dev->dma_device, sg, nents, direction);
2805}
2806
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07002807static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
2808 struct scatterlist *sg, int nents,
2809 enum dma_data_direction direction,
2810 struct dma_attrs *attrs)
2811{
2812 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2813}
2814
2815static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
2816 struct scatterlist *sg, int nents,
2817 enum dma_data_direction direction,
2818 struct dma_attrs *attrs)
2819{
2820 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2821}
Ralph Campbell9b513092006-12-12 14:27:41 -08002822/**
2823 * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
2824 * @dev: The device for which the DMA addresses were created
2825 * @sg: The scatter/gather entry
Mike Marciniszynea58a592014-03-28 13:26:59 -04002826 *
2827 * Note: this function is obsolete. To do: change all occurrences of
2828 * ib_sg_dma_address() into sg_dma_address().
Ralph Campbell9b513092006-12-12 14:27:41 -08002829 */
2830static inline u64 ib_sg_dma_address(struct ib_device *dev,
2831 struct scatterlist *sg)
2832{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002833 return sg_dma_address(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002834}
2835
2836/**
2837 * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
2838 * @dev: The device for which the DMA addresses were created
2839 * @sg: The scatter/gather entry
Mike Marciniszynea58a592014-03-28 13:26:59 -04002840 *
2841 * Note: this function is obsolete. To do: change all occurrences of
2842 * ib_sg_dma_len() into sg_dma_len().
Ralph Campbell9b513092006-12-12 14:27:41 -08002843 */
2844static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
2845 struct scatterlist *sg)
2846{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002847 return sg_dma_len(sg);
Ralph Campbell9b513092006-12-12 14:27:41 -08002848}
2849
2850/**
2851 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
2852 * @dev: The device for which the DMA address was created
2853 * @addr: The DMA address
2854 * @size: The size of the region in bytes
2855 * @dir: The direction of the DMA
2856 */
2857static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
2858 u64 addr,
2859 size_t size,
2860 enum dma_data_direction dir)
2861{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002862 if (dev->dma_ops)
2863 dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
2864 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002865 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
2866}
2867
2868/**
2869 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
2870 * @dev: The device for which the DMA address was created
2871 * @addr: The DMA address
2872 * @size: The size of the region in bytes
2873 * @dir: The direction of the DMA
2874 */
2875static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
2876 u64 addr,
2877 size_t size,
2878 enum dma_data_direction dir)
2879{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002880 if (dev->dma_ops)
2881 dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
2882 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002883 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
2884}
2885
2886/**
2887 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
2888 * @dev: The device for which the DMA address is requested
2889 * @size: The size of the region to allocate in bytes
2890 * @dma_handle: A pointer for returning the DMA address of the region
2891 * @flag: memory allocator flags
2892 */
2893static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
2894 size_t size,
2895 u64 *dma_handle,
2896 gfp_t flag)
2897{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002898 if (dev->dma_ops)
2899 return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
Roland Dreierc59a3da2006-12-15 13:57:26 -08002900 else {
2901 dma_addr_t handle;
2902 void *ret;
2903
2904 ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
2905 *dma_handle = handle;
2906 return ret;
2907 }
Ralph Campbell9b513092006-12-12 14:27:41 -08002908}
2909
2910/**
2911 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
2912 * @dev: The device for which the DMA addresses were allocated
2913 * @size: The size of the region
2914 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
2915 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
2916 */
2917static inline void ib_dma_free_coherent(struct ib_device *dev,
2918 size_t size, void *cpu_addr,
2919 u64 dma_handle)
2920{
Ben Collinsd1998ef2006-12-13 22:10:05 -05002921 if (dev->dma_ops)
2922 dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
2923 else
Ralph Campbell9b513092006-12-12 14:27:41 -08002924 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
2925}
2926
2927/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 * ib_dereg_mr - Deregisters a memory region and removes it from the
2929 * HCA translation table.
2930 * @mr: The memory region to deregister.
Shani Michaeli7083e422013-02-06 16:19:12 +00002931 *
2932 * This function can fail, if the memory region has memory windows bound to it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 */
2934int ib_dereg_mr(struct ib_mr *mr);
2935
Sagi Grimberg9bee1782015-07-30 10:32:35 +03002936struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
2937 enum ib_mr_type mr_type,
2938 u32 max_num_sg);
Steve Wise00f7ec32008-07-14 23:48:45 -07002939
2940/**
Steve Wise00f7ec32008-07-14 23:48:45 -07002941 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2942 * R_Key and L_Key.
2943 * @mr - struct ib_mr pointer to be updated.
2944 * @newkey - new key to be used.
2945 */
2946static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2947{
2948 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2949 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2950}
2951
2952/**
Shani Michaeli7083e422013-02-06 16:19:12 +00002953 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
2954 * for calculating a new rkey for type 2 memory windows.
2955 * @rkey - the rkey to increment.
2956 */
2957static inline u32 ib_inc_rkey(u32 rkey)
2958{
2959 const u32 mask = 0x000000ff;
2960 return ((rkey + 1) & mask) | (rkey & ~mask);
2961}
2962
2963/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 * ib_alloc_fmr - Allocates a unmapped fast memory region.
2965 * @pd: The protection domain associated with the unmapped region.
2966 * @mr_access_flags: Specifies the memory access rights.
2967 * @fmr_attr: Attributes of the unmapped region.
2968 *
2969 * A fast memory region must be mapped before it can be used as part of
2970 * a work request.
2971 */
2972struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2973 int mr_access_flags,
2974 struct ib_fmr_attr *fmr_attr);
2975
2976/**
2977 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2978 * @fmr: The fast memory region to associate with the pages.
2979 * @page_list: An array of physical pages to map to the fast memory region.
2980 * @list_len: The number of pages in page_list.
2981 * @iova: The I/O virtual address to use with the mapped region.
2982 */
2983static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2984 u64 *page_list, int list_len,
2985 u64 iova)
2986{
2987 return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2988}
2989
2990/**
2991 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2992 * @fmr_list: A linked list of fast memory regions to unmap.
2993 */
2994int ib_unmap_fmr(struct list_head *fmr_list);
2995
2996/**
2997 * ib_dealloc_fmr - Deallocates a fast memory region.
2998 * @fmr: The fast memory region to deallocate.
2999 */
3000int ib_dealloc_fmr(struct ib_fmr *fmr);
3001
3002/**
3003 * ib_attach_mcast - Attaches the specified QP to a multicast group.
3004 * @qp: QP to attach to the multicast group. The QP must be type
3005 * IB_QPT_UD.
3006 * @gid: Multicast group GID.
3007 * @lid: Multicast group LID in host byte order.
3008 *
3009 * In order to send and receive multicast packets, subnet
3010 * administration must have created the multicast group and configured
3011 * the fabric appropriately. The port associated with the specified
3012 * QP must also be a member of the multicast group.
3013 */
3014int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
3015
3016/**
3017 * ib_detach_mcast - Detaches the specified QP from a multicast group.
3018 * @qp: QP to detach from the multicast group.
3019 * @gid: Multicast group GID.
3020 * @lid: Multicast group LID in host byte order.
3021 */
3022int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
3023
Sean Hefty59991f92011-05-23 17:52:46 -07003024/**
3025 * ib_alloc_xrcd - Allocates an XRC domain.
3026 * @device: The device on which to allocate the XRC domain.
3027 */
3028struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
3029
3030/**
3031 * ib_dealloc_xrcd - Deallocates an XRC domain.
3032 * @xrcd: The XRC domain to deallocate.
3033 */
3034int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
3035
Hadar Hen Zion319a4412013-08-07 14:01:59 +03003036struct ib_flow *ib_create_flow(struct ib_qp *qp,
3037 struct ib_flow_attr *flow_attr, int domain);
3038int ib_destroy_flow(struct ib_flow *flow_id);
3039
Eli Cohen1c636f82013-10-31 15:26:32 +02003040static inline int ib_check_mr_access(int flags)
3041{
3042 /*
3043 * Local write permission is required if remote write or
3044 * remote atomic permission is also requested.
3045 */
3046 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
3047 !(flags & IB_ACCESS_LOCAL_WRITE))
3048 return -EINVAL;
3049
3050 return 0;
3051}
3052
Sagi Grimberg1b01d332014-02-23 14:19:05 +02003053/**
3054 * ib_check_mr_status: lightweight check of MR status.
3055 * This routine may provide status checks on a selected
3056 * ib_mr. first use is for signature status check.
3057 *
3058 * @mr: A memory region.
3059 * @check_mask: Bitmask of which checks to perform from
3060 * ib_mr_status_check enumeration.
3061 * @mr_status: The container of relevant status checks.
3062 * failed checks will be indicated in the status bitmask
3063 * and the relevant info shall be in the error item.
3064 */
3065int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
3066 struct ib_mr_status *mr_status);
3067
Yotam Kenneth9268f722015-07-30 17:50:15 +03003068struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
3069 u16 pkey, const union ib_gid *gid,
3070 const struct sockaddr *addr);
3071
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03003072int ib_map_mr_sg(struct ib_mr *mr,
3073 struct scatterlist *sg,
3074 int sg_nents,
3075 unsigned int page_size);
3076
3077static inline int
3078ib_map_mr_sg_zbva(struct ib_mr *mr,
3079 struct scatterlist *sg,
3080 int sg_nents,
3081 unsigned int page_size)
3082{
3083 int n;
3084
3085 n = ib_map_mr_sg(mr, sg, sg_nents, page_size);
3086 mr->iova = 0;
3087
3088 return n;
3089}
3090
3091int ib_sg_to_pages(struct ib_mr *mr,
3092 struct scatterlist *sgl,
3093 int sg_nents,
3094 int (*set_page)(struct ib_mr *, u64));
3095
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096#endif /* IB_VERBS_H */