blob: 19864da78649dfaed077cf8c56a9f226fd1b0ef5 [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/dma-mapping.h>
Michael S. Tsirkin459d6e22007-02-04 14:11:55 -080045#include <linux/kref.h>
Dotan Barakbfb3ea12007-07-31 16:49:15 +030046#include <linux/list.h>
47#include <linux/rwsem.h>
Tejun Heof0626712010-10-19 15:24:36 +000048#include <linux/workqueue.h>
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -080049#include <linux/irq_poll.h>
Matan Barakdd5f03b2013-12-12 18:03:11 +020050#include <uapi/linux/if_ether.h>
Somnath Koturc865f242015-12-23 14:56:51 +020051#include <net/ipv6.h>
52#include <net/ip.h>
Matan Barak301a7212015-12-15 20:30:10 +020053#include <linux/string.h>
54#include <linux/slab.h>
Vishwanathapura, Niranjana2fc77572017-04-12 20:29:20 -070055#include <linux/netdevice.h>
Parav Pandit01b67112018-11-16 03:50:57 +020056#include <linux/refcount.h>
Eli Cohen50174a72016-03-11 22:58:38 +020057#include <linux/if_link.h>
Arun Sharma600634972011-07-26 16:09:06 -070058#include <linux/atomic.h>
Haggai Eran882214e2014-12-11 17:04:18 +020059#include <linux/mmu_notifier.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080060#include <linux/uaccess.h>
Parav Pandit43579b52017-01-10 00:02:14 +000061#include <linux/cgroup_rdma.h>
Leon Romanovskyf6316032019-03-28 15:12:58 +020062#include <linux/irqflags.h>
63#include <linux/preempt.h>
Yamin Friedmanda662972019-07-08 13:59:03 +030064#include <linux/dim.h>
Nicolas Dichtelea6819e2017-03-27 14:20:14 +020065#include <uapi/rdma/ib_user_verbs.h>
Mark Zhang413d3342019-07-02 13:02:34 +030066#include <rdma/rdma_counter.h>
Leon Romanovsky02d88832018-01-28 11:17:20 +020067#include <rdma/restrack.h>
Max Gurtovoy36b1e472019-06-11 18:52:37 +030068#include <rdma/signature.h>
Matan Barak0ede73b2018-03-19 15:02:34 +020069#include <uapi/rdma/rdma_user_ioctl.h>
Matan Barak2eb9bea2018-03-28 09:27:45 +030070#include <uapi/rdma/ib_user_ioctl_verbs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Leon Romanovsky9abb0d12017-06-27 16:49:53 +030072#define IB_FW_VERSION_NAME_MAX ETHTOOL_FWVERS_LEN
73
Jason Gunthorpeb5231b02018-09-16 20:48:04 +030074struct ib_umem_odp;
Jason Gunthorpe620d3f82020-01-08 19:21:59 +020075struct ib_uqp_object;
Jason Gunthorpe9fbe3342020-01-08 19:22:00 +020076struct ib_usrq_object;
Jason Gunthorpee04dd132020-01-08 19:22:01 +020077struct ib_uwq_object;
Jason Gunthorpeb5231b02018-09-16 20:48:04 +030078
Tejun Heof0626712010-10-19 15:24:36 +000079extern struct workqueue_struct *ib_wq;
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -080080extern struct workqueue_struct *ib_comp_wq;
Jack Morgensteinf7948092018-08-27 08:35:55 +030081extern struct workqueue_struct *ib_comp_unbound_wq;
Tejun Heof0626712010-10-19 15:24:36 +000082
Jason Gunthorpe5bd48c12020-01-08 19:21:58 +020083struct ib_ucq_object;
84
Gal Pressman923abb92019-05-01 13:48:13 +030085__printf(3, 4) __cold
86void ibdev_printk(const char *level, const struct ib_device *ibdev,
87 const char *format, ...);
88__printf(2, 3) __cold
89void ibdev_emerg(const struct ib_device *ibdev, const char *format, ...);
90__printf(2, 3) __cold
91void ibdev_alert(const struct ib_device *ibdev, const char *format, ...);
92__printf(2, 3) __cold
93void ibdev_crit(const struct ib_device *ibdev, const char *format, ...);
94__printf(2, 3) __cold
95void ibdev_err(const struct ib_device *ibdev, const char *format, ...);
96__printf(2, 3) __cold
97void ibdev_warn(const struct ib_device *ibdev, const char *format, ...);
98__printf(2, 3) __cold
99void ibdev_notice(const struct ib_device *ibdev, const char *format, ...);
100__printf(2, 3) __cold
101void ibdev_info(const struct ib_device *ibdev, const char *format, ...);
102
103#if defined(CONFIG_DYNAMIC_DEBUG)
104#define ibdev_dbg(__dev, format, args...) \
105 dynamic_ibdev_dbg(__dev, format, ##args)
Gal Pressman923abb92019-05-01 13:48:13 +0300106#else
107__printf(2, 3) __cold
108static inline
109void ibdev_dbg(const struct ib_device *ibdev, const char *format, ...) {}
110#endif
111
Gal Pressman05bb4112019-08-01 20:14:46 +0300112#define ibdev_level_ratelimited(ibdev_level, ibdev, fmt, ...) \
113do { \
114 static DEFINE_RATELIMIT_STATE(_rs, \
115 DEFAULT_RATELIMIT_INTERVAL, \
116 DEFAULT_RATELIMIT_BURST); \
117 if (__ratelimit(&_rs)) \
118 ibdev_level(ibdev, fmt, ##__VA_ARGS__); \
119} while (0)
120
121#define ibdev_emerg_ratelimited(ibdev, fmt, ...) \
122 ibdev_level_ratelimited(ibdev_emerg, ibdev, fmt, ##__VA_ARGS__)
123#define ibdev_alert_ratelimited(ibdev, fmt, ...) \
124 ibdev_level_ratelimited(ibdev_alert, ibdev, fmt, ##__VA_ARGS__)
125#define ibdev_crit_ratelimited(ibdev, fmt, ...) \
126 ibdev_level_ratelimited(ibdev_crit, ibdev, fmt, ##__VA_ARGS__)
127#define ibdev_err_ratelimited(ibdev, fmt, ...) \
128 ibdev_level_ratelimited(ibdev_err, ibdev, fmt, ##__VA_ARGS__)
129#define ibdev_warn_ratelimited(ibdev, fmt, ...) \
130 ibdev_level_ratelimited(ibdev_warn, ibdev, fmt, ##__VA_ARGS__)
131#define ibdev_notice_ratelimited(ibdev, fmt, ...) \
132 ibdev_level_ratelimited(ibdev_notice, ibdev, fmt, ##__VA_ARGS__)
133#define ibdev_info_ratelimited(ibdev, fmt, ...) \
134 ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__)
135
136#if defined(CONFIG_DYNAMIC_DEBUG)
137/* descriptor check is first to prevent flooding with "callbacks suppressed" */
138#define ibdev_dbg_ratelimited(ibdev, fmt, ...) \
139do { \
140 static DEFINE_RATELIMIT_STATE(_rs, \
141 DEFAULT_RATELIMIT_INTERVAL, \
142 DEFAULT_RATELIMIT_BURST); \
143 DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
144 if (DYNAMIC_DEBUG_BRANCH(descriptor) && __ratelimit(&_rs)) \
145 __dynamic_ibdev_dbg(&descriptor, ibdev, fmt, \
146 ##__VA_ARGS__); \
147} while (0)
148#else
149__printf(2, 3) __cold
150static inline
151void ibdev_dbg_ratelimited(const struct ib_device *ibdev, const char *format, ...) {}
152#endif
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154union ib_gid {
155 u8 raw[16];
156 struct {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700157 __be64 subnet_prefix;
158 __be64 interface_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 } global;
160};
161
Moni Shouae26be1b2015-07-30 18:33:29 +0300162extern union ib_gid zgid;
163
Matan Barakb39ffa12015-12-23 14:56:47 +0200164enum ib_gid_type {
165 /* If link layer is Ethernet, this is RoCE V1 */
166 IB_GID_TYPE_IB = 0,
167 IB_GID_TYPE_ROCE = 0,
Matan Barak7766a992015-12-23 14:56:50 +0200168 IB_GID_TYPE_ROCE_UDP_ENCAP = 1,
Matan Barakb39ffa12015-12-23 14:56:47 +0200169 IB_GID_TYPE_SIZE
170};
171
Moni Shoua7ead4bc2016-01-14 17:50:38 +0200172#define ROCE_V2_UDP_DPORT 4791
Matan Barak03db3a22015-07-30 18:33:26 +0300173struct ib_gid_attr {
Parav Pandit943bd982019-05-02 10:48:07 +0300174 struct net_device __rcu *ndev;
Parav Pandit598ff6b2018-04-01 15:08:21 +0300175 struct ib_device *device;
Parav Panditb150c382018-06-05 08:40:15 +0300176 union ib_gid gid;
Parav Pandit598ff6b2018-04-01 15:08:21 +0300177 enum ib_gid_type gid_type;
178 u16 index;
179 u8 port_num;
Matan Barak03db3a22015-07-30 18:33:26 +0300180};
181
Eli Cohena0c1b2a2016-03-11 22:58:37 +0200182enum {
183 /* set the local administered indication */
184 IB_SA_WELL_KNOWN_GUID = BIT_ULL(57) | 2,
185};
186
Tom Tucker07ebafb2006-08-03 16:02:42 -0500187enum rdma_transport_type {
188 RDMA_TRANSPORT_IB,
Upinder Malhi \(umalhi\)180771a2013-09-10 03:36:59 +0000189 RDMA_TRANSPORT_IWARP,
Upinder Malhi248567f2014-01-09 14:48:19 -0800190 RDMA_TRANSPORT_USNIC,
Gal Pressmanf95be3d2019-05-05 20:59:21 +0300191 RDMA_TRANSPORT_USNIC_UDP,
192 RDMA_TRANSPORT_UNSPECIFIED,
Tom Tucker07ebafb2006-08-03 16:02:42 -0500193};
194
Michael Wang6b90a6d2015-05-05 14:50:18 +0200195enum rdma_protocol_type {
196 RDMA_PROTOCOL_IB,
197 RDMA_PROTOCOL_IBOE,
198 RDMA_PROTOCOL_IWARP,
199 RDMA_PROTOCOL_USNIC_UDP
200};
201
Roland Dreier8385fd82014-06-04 10:00:16 -0700202__attribute_const__ enum rdma_transport_type
Jason Gunthorpe5d60c112019-06-13 21:38:17 -0300203rdma_node_get_transport(unsigned int node_type);
Tom Tucker07ebafb2006-08-03 16:02:42 -0500204
Somnath Koturc865f242015-12-23 14:56:51 +0200205enum rdma_network_type {
206 RDMA_NETWORK_IB,
207 RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB,
208 RDMA_NETWORK_IPV4,
209 RDMA_NETWORK_IPV6
210};
211
212static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
213{
214 if (network_type == RDMA_NETWORK_IPV4 ||
215 network_type == RDMA_NETWORK_IPV6)
216 return IB_GID_TYPE_ROCE_UDP_ENCAP;
217
218 /* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */
219 return IB_GID_TYPE_IB;
220}
221
Parav Pandit47ec3862018-06-13 10:22:06 +0300222static inline enum rdma_network_type
223rdma_gid_attr_network_type(const struct ib_gid_attr *attr)
Somnath Koturc865f242015-12-23 14:56:51 +0200224{
Parav Pandit47ec3862018-06-13 10:22:06 +0300225 if (attr->gid_type == IB_GID_TYPE_IB)
Somnath Koturc865f242015-12-23 14:56:51 +0200226 return RDMA_NETWORK_IB;
227
Parav Pandit47ec3862018-06-13 10:22:06 +0300228 if (ipv6_addr_v4mapped((struct in6_addr *)&attr->gid))
Somnath Koturc865f242015-12-23 14:56:51 +0200229 return RDMA_NETWORK_IPV4;
230 else
231 return RDMA_NETWORK_IPV6;
232}
233
Eli Cohena3f5ada2010-09-27 17:51:10 -0700234enum rdma_link_layer {
235 IB_LINK_LAYER_UNSPECIFIED,
236 IB_LINK_LAYER_INFINIBAND,
237 IB_LINK_LAYER_ETHERNET,
238};
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240enum ib_device_cap_flags {
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200241 IB_DEVICE_RESIZE_MAX_WR = (1 << 0),
242 IB_DEVICE_BAD_PKEY_CNTR = (1 << 1),
243 IB_DEVICE_BAD_QKEY_CNTR = (1 << 2),
244 IB_DEVICE_RAW_MULTI = (1 << 3),
245 IB_DEVICE_AUTO_PATH_MIG = (1 << 4),
246 IB_DEVICE_CHANGE_PHY_PORT = (1 << 5),
247 IB_DEVICE_UD_AV_PORT_ENFORCE = (1 << 6),
248 IB_DEVICE_CURR_QP_STATE_MOD = (1 << 7),
249 IB_DEVICE_SHUTDOWN_PORT = (1 << 8),
Leon Romanovsky78b57f92017-08-17 15:50:37 +0300250 /* Not in use, former INIT_TYPE = (1 << 9),*/
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200251 IB_DEVICE_PORT_ACTIVE_EVENT = (1 << 10),
252 IB_DEVICE_SYS_IMAGE_GUID = (1 << 11),
253 IB_DEVICE_RC_RNR_NAK_GEN = (1 << 12),
254 IB_DEVICE_SRQ_RESIZE = (1 << 13),
255 IB_DEVICE_N_NOTIFY_CQ = (1 << 14),
Christoph Hellwigb1adc712015-12-23 19:12:45 +0100256
257 /*
258 * This device supports a per-device lkey or stag that can be
259 * used without performing a memory registration for the local
260 * memory. Note that ULPs should never check this flag, but
261 * instead of use the local_dma_lkey flag in the ib_pd structure,
262 * which will always contain a usable lkey.
263 */
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200264 IB_DEVICE_LOCAL_DMA_LKEY = (1 << 15),
Leon Romanovsky78b57f92017-08-17 15:50:37 +0300265 /* Reserved, old SEND_W_INV = (1 << 16),*/
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200266 IB_DEVICE_MEM_WINDOW = (1 << 17),
Eli Cohene0605d92008-01-30 18:30:57 +0200267 /*
268 * Devices should set IB_DEVICE_UD_IP_SUM if they support
269 * insertion of UDP and TCP checksum on outgoing UD IPoIB
270 * messages and can verify the validity of checksum for
271 * incoming messages. Setting this flag implies that the
272 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
273 */
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200274 IB_DEVICE_UD_IP_CSUM = (1 << 18),
275 IB_DEVICE_UD_TSO = (1 << 19),
276 IB_DEVICE_XRC = (1 << 20),
Christoph Hellwigb1adc712015-12-23 19:12:45 +0100277
278 /*
279 * This device supports the IB "base memory management extension",
280 * which includes support for fast registrations (IB_WR_REG_MR,
281 * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs). This flag should
282 * also be set by any iWarp device which must support FRs to comply
283 * to the iWarp verbs spec. iWarp devices also support the
284 * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
285 * stag.
286 */
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200287 IB_DEVICE_MEM_MGT_EXTENSIONS = (1 << 21),
288 IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1 << 22),
289 IB_DEVICE_MEM_WINDOW_TYPE_2A = (1 << 23),
290 IB_DEVICE_MEM_WINDOW_TYPE_2B = (1 << 24),
291 IB_DEVICE_RC_IP_CSUM = (1 << 25),
Noa Osherovichebaaee22017-01-18 15:39:54 +0200292 /* Deprecated. Please use IB_RAW_PACKET_CAP_IP_CSUM. */
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200293 IB_DEVICE_RAW_IP_CSUM = (1 << 26),
Leon Romanovsky8a06ce52015-12-20 12:16:10 +0200294 /*
295 * Devices should set IB_DEVICE_CROSS_CHANNEL if they
296 * support execution of WQEs that involve synchronization
297 * of I/O operations with single completion queue managed
298 * by hardware.
299 */
Leon Romanovsky78b57f92017-08-17 15:50:37 +0300300 IB_DEVICE_CROSS_CHANNEL = (1 << 27),
Leon Romanovsky7ca0bc52015-12-20 12:16:09 +0200301 IB_DEVICE_MANAGED_FLOW_STEERING = (1 << 29),
Israel Rukshinc0a6cbb2019-06-11 18:52:50 +0300302 IB_DEVICE_INTEGRITY_HANDOVER = (1 << 30),
Max Gurtovoy47355b32016-06-06 19:34:39 +0300303 IB_DEVICE_ON_DEMAND_PAGING = (1ULL << 31),
Sagi Grimbergf5aa9152016-02-29 19:07:32 +0200304 IB_DEVICE_SG_GAPS_REG = (1ULL << 32),
Max Gurtovoyc7e162a2016-06-06 19:34:40 +0300305 IB_DEVICE_VIRTUAL_FUNCTION = (1ULL << 33),
Noa Osherovichebaaee22017-01-18 15:39:54 +0200306 /* Deprecated. Please use IB_RAW_PACKET_CAP_SCATTER_FCS. */
Max Gurtovoyc7e162a2016-06-06 19:34:40 +0300307 IB_DEVICE_RAW_SCATTER_FCS = (1ULL << 34),
Gary Leshner7f90a5a2020-05-11 12:06:07 -0400308 IB_DEVICE_RDMA_NETDEV_OPA = (1ULL << 35),
Noa Osheroviche1d2e882017-10-29 13:59:44 +0200309 /* The device supports padding incoming writes to cacheline. */
310 IB_DEVICE_PCI_WRITE_END_PADDING = (1ULL << 36),
Steve Wise3856ec42019-02-15 11:03:53 -0800311 IB_DEVICE_ALLOW_USER_UNREG = (1ULL << 37),
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200312};
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314enum ib_atomic_cap {
315 IB_ATOMIC_NONE,
316 IB_ATOMIC_HCA,
317 IB_ATOMIC_GLOB
318};
319
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200320enum ib_odp_general_cap_bits {
Artemy Kovalyov25bf14d2017-01-18 16:58:06 +0200321 IB_ODP_SUPPORT = 1 << 0,
322 IB_ODP_SUPPORT_IMPLICIT = 1 << 1,
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200323};
324
325enum ib_odp_transport_cap_bits {
326 IB_ODP_SUPPORT_SEND = 1 << 0,
327 IB_ODP_SUPPORT_RECV = 1 << 1,
328 IB_ODP_SUPPORT_WRITE = 1 << 2,
329 IB_ODP_SUPPORT_READ = 1 << 3,
330 IB_ODP_SUPPORT_ATOMIC = 1 << 4,
Moni Shouada823342019-01-22 08:48:41 +0200331 IB_ODP_SUPPORT_SRQ_RECV = 1 << 5,
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200332};
333
334struct ib_odp_caps {
335 uint64_t general_caps;
336 struct {
337 uint32_t rc_odp_caps;
338 uint32_t uc_odp_caps;
339 uint32_t ud_odp_caps;
Moni Shoua52a72e22019-01-22 08:48:42 +0200340 uint32_t xrc_odp_caps;
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200341 } per_transport_caps;
342};
343
Yishai Hadasccf20562016-08-28 11:28:43 +0300344struct ib_rss_caps {
345 /* Corresponding bit will be set if qp type from
346 * 'enum ib_qp_type' is supported, e.g.
347 * supported_qpts |= 1 << IB_QPT_UD
348 */
349 u32 supported_qpts;
350 u32 max_rwq_indirection_tables;
351 u32 max_rwq_indirection_table_size;
352};
353
Artemy Kovalyov6938fc1e2017-08-17 15:52:03 +0300354enum ib_tm_cap_flags {
Danit Goldberg89705e92019-07-05 19:21:57 +0300355 /* Support tag matching with rendezvous offload for RC transport */
356 IB_TM_CAP_RNDV_RC = 1 << 0,
Artemy Kovalyov6938fc1e2017-08-17 15:52:03 +0300357};
358
Leon Romanovsky78b1beb2017-09-24 21:46:29 +0300359struct ib_tm_caps {
Artemy Kovalyov6938fc1e2017-08-17 15:52:03 +0300360 /* Max size of RNDV header */
361 u32 max_rndv_hdr_size;
362 /* Max number of entries in tag matching list */
363 u32 max_num_tags;
364 /* From enum ib_tm_cap_flags */
365 u32 flags;
366 /* Max number of outstanding list operations */
367 u32 max_ops;
368 /* Max number of SGE in tag matching entry */
369 u32 max_sge;
370};
371
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300372struct ib_cq_init_attr {
373 unsigned int cqe;
Dan Carpentera9018ad2019-10-11 16:34:19 +0300374 u32 comp_vector;
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300375 u32 flags;
376};
377
Yonatan Cohen869ddcf2017-11-13 10:51:13 +0200378enum ib_cq_attr_mask {
379 IB_CQ_MODERATE = 1 << 0,
380};
381
Yonatan Cohen18bd9072017-11-13 10:51:16 +0200382struct ib_cq_caps {
383 u16 max_cq_moderation_count;
384 u16 max_cq_moderation_period;
385};
386
Ariel Levkovichbe934cc2018-04-05 18:53:25 +0300387struct ib_dm_mr_attr {
388 u64 length;
389 u64 offset;
390 u32 access_flags;
391};
392
Ariel Levkovichbee76d72018-04-05 18:53:24 +0300393struct ib_dm_alloc_attr {
394 u64 length;
395 u32 alignment;
396 u32 flags;
397};
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399struct ib_device_attr {
400 u64 fw_ver;
Sean Hefty97f52eb2005-08-13 21:05:57 -0700401 __be64 sys_image_guid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 u64 max_mr_size;
403 u64 page_size_cap;
404 u32 vendor_id;
405 u32 vendor_part_id;
406 u32 hw_ver;
407 int max_qp;
408 int max_qp_wr;
Leon Romanovskyfb532d62016-02-23 10:25:25 +0200409 u64 device_cap_flags;
Steve Wise33023fb2018-06-18 08:05:26 -0700410 int max_send_sge;
411 int max_recv_sge;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 int max_sge_rd;
413 int max_cq;
414 int max_cqe;
415 int max_mr;
416 int max_pd;
417 int max_qp_rd_atom;
418 int max_ee_rd_atom;
419 int max_res_rd_atom;
420 int max_qp_init_rd_atom;
421 int max_ee_init_rd_atom;
422 enum ib_atomic_cap atomic_cap;
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300423 enum ib_atomic_cap masked_atomic_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 int max_ee;
425 int max_rdd;
426 int max_mw;
427 int max_raw_ipv6_qp;
428 int max_raw_ethy_qp;
429 int max_mcast_grp;
430 int max_mcast_qp_attach;
431 int max_total_mcast_qp_attach;
432 int max_ah;
433 int max_fmr;
434 int max_map_per_fmr;
435 int max_srq;
436 int max_srq_wr;
437 int max_srq_sge;
Steve Wise00f7ec32008-07-14 23:48:45 -0700438 unsigned int max_fast_reg_page_list_len;
Max Gurtovoy62e3c372019-06-11 18:52:43 +0300439 unsigned int max_pi_fast_reg_page_list_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 u16 max_pkeys;
441 u8 local_ca_ack_delay;
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200442 int sig_prot_cap;
443 int sig_guard_cap;
Sagi Grimberg860f10a2014-12-11 17:04:16 +0200444 struct ib_odp_caps odp_caps;
Matan Barak24306dc2015-06-11 16:35:24 +0300445 uint64_t timestamp_mask;
446 uint64_t hca_core_clock; /* in KHZ */
Yishai Hadasccf20562016-08-28 11:28:43 +0300447 struct ib_rss_caps rss_caps;
448 u32 max_wq_type_rq;
Noa Osherovichebaaee22017-01-18 15:39:54 +0200449 u32 raw_packet_caps; /* Use ib_raw_packet_caps enum */
Leon Romanovsky78b1beb2017-09-24 21:46:29 +0300450 struct ib_tm_caps tm_caps;
Yonatan Cohen18bd9072017-11-13 10:51:16 +0200451 struct ib_cq_caps cq_caps;
Ariel Levkovich1d8eeb92018-04-05 18:53:23 +0300452 u64 max_dm_size;
Yamin Friedman00bd1432019-10-07 16:59:32 +0300453 /* Max entries for sgl for optimized performance per READ */
454 u32 max_sgl_rd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455};
456
457enum ib_mtu {
458 IB_MTU_256 = 1,
459 IB_MTU_512 = 2,
460 IB_MTU_1024 = 3,
461 IB_MTU_2048 = 4,
462 IB_MTU_4096 = 5
463};
464
Kaike Wan6d723442020-05-11 12:06:18 -0400465enum opa_mtu {
466 OPA_MTU_8192 = 6,
467 OPA_MTU_10240 = 7
468};
469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
471{
472 switch (mtu) {
473 case IB_MTU_256: return 256;
474 case IB_MTU_512: return 512;
475 case IB_MTU_1024: return 1024;
476 case IB_MTU_2048: return 2048;
477 case IB_MTU_4096: return 4096;
478 default: return -1;
479 }
480}
481
Amrani, Ramd3f4aad2016-12-26 08:40:57 +0200482static inline enum ib_mtu ib_mtu_int_to_enum(int mtu)
483{
484 if (mtu >= 4096)
485 return IB_MTU_4096;
486 else if (mtu >= 2048)
487 return IB_MTU_2048;
488 else if (mtu >= 1024)
489 return IB_MTU_1024;
490 else if (mtu >= 512)
491 return IB_MTU_512;
492 else
493 return IB_MTU_256;
494}
495
Kaike Wan6d723442020-05-11 12:06:18 -0400496static inline int opa_mtu_enum_to_int(enum opa_mtu mtu)
497{
498 switch (mtu) {
499 case OPA_MTU_8192:
500 return 8192;
501 case OPA_MTU_10240:
502 return 10240;
503 default:
504 return(ib_mtu_enum_to_int((enum ib_mtu)mtu));
505 }
506}
507
508static inline enum opa_mtu opa_mtu_int_to_enum(int mtu)
509{
510 if (mtu >= 10240)
511 return OPA_MTU_10240;
512 else if (mtu >= 8192)
513 return OPA_MTU_8192;
514 else
515 return ((enum opa_mtu)ib_mtu_int_to_enum(mtu));
516}
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518enum ib_port_state {
519 IB_PORT_NOP = 0,
520 IB_PORT_DOWN = 1,
521 IB_PORT_INIT = 2,
522 IB_PORT_ARMED = 3,
523 IB_PORT_ACTIVE = 4,
524 IB_PORT_ACTIVE_DEFER = 5
525};
526
Kamal Heib72a77202019-08-07 13:31:35 +0300527enum ib_port_phys_state {
528 IB_PORT_PHYS_STATE_SLEEP = 1,
529 IB_PORT_PHYS_STATE_POLLING = 2,
530 IB_PORT_PHYS_STATE_DISABLED = 3,
531 IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING = 4,
532 IB_PORT_PHYS_STATE_LINK_UP = 5,
533 IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY = 6,
534 IB_PORT_PHYS_STATE_PHY_TEST = 7,
535};
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537enum ib_port_width {
538 IB_WIDTH_1X = 1,
Michael Guralnikdbabf682018-12-09 11:49:49 +0200539 IB_WIDTH_2X = 16,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 IB_WIDTH_4X = 2,
541 IB_WIDTH_8X = 4,
542 IB_WIDTH_12X = 8
543};
544
545static inline int ib_width_enum_to_int(enum ib_port_width width)
546{
547 switch (width) {
548 case IB_WIDTH_1X: return 1;
Michael Guralnikdbabf682018-12-09 11:49:49 +0200549 case IB_WIDTH_2X: return 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 case IB_WIDTH_4X: return 4;
551 case IB_WIDTH_8X: return 8;
552 case IB_WIDTH_12X: return 12;
553 default: return -1;
554 }
555}
556
Or Gerlitz2e966912012-02-28 18:49:50 +0200557enum ib_port_speed {
558 IB_SPEED_SDR = 1,
559 IB_SPEED_DDR = 2,
560 IB_SPEED_QDR = 4,
561 IB_SPEED_FDR10 = 8,
562 IB_SPEED_FDR = 16,
Noa Osherovich12113a32017-04-20 20:53:31 +0300563 IB_SPEED_EDR = 32,
564 IB_SPEED_HDR = 64
Or Gerlitz2e966912012-02-28 18:49:50 +0200565};
566
Christoph Lameterb40f4752016-05-16 12:49:33 -0500567/**
568 * struct rdma_hw_stats
Mark Bloche9451302018-03-27 15:51:05 +0300569 * @lock - Mutex to protect parallel write access to lifespan and values
570 * of counters, which are 64bits and not guaranteeed to be written
571 * atomicaly on 32bits systems.
Christoph Lameterb40f4752016-05-16 12:49:33 -0500572 * @timestamp - Used by the core code to track when the last update was
573 * @lifespan - Used by the core code to determine how old the counters
574 * should be before being updated again. Stored in jiffies, defaults
575 * to 10 milliseconds, drivers can override the default be specifying
576 * their own value during their allocation routine.
577 * @name - Array of pointers to static names used for the counters in
578 * directory.
579 * @num_counters - How many hardware counters there are. If name is
580 * shorter than this number, a kernel oops will result. Driver authors
581 * are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
582 * in their code to prevent this.
583 * @value - Array of u64 counters that are accessed by the sysfs code and
584 * filled in by the drivers get_stats routine
585 */
586struct rdma_hw_stats {
Mark Bloche9451302018-03-27 15:51:05 +0300587 struct mutex lock; /* Protect lifespan and values[] */
Christoph Lameterb40f4752016-05-16 12:49:33 -0500588 unsigned long timestamp;
589 unsigned long lifespan;
590 const char * const *names;
591 int num_counters;
592 u64 value[];
Steve Wise7f624d02008-07-14 23:48:48 -0700593};
594
Christoph Lameterb40f4752016-05-16 12:49:33 -0500595#define RDMA_HW_STATS_DEFAULT_LIFESPAN 10
596/**
597 * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct
598 * for drivers.
599 * @names - Array of static const char *
600 * @num_counters - How many elements in array
601 * @lifespan - How many milliseconds between updates
602 */
603static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
604 const char * const *names, int num_counters,
605 unsigned long lifespan)
606{
607 struct rdma_hw_stats *stats;
Steve Wise7f624d02008-07-14 23:48:48 -0700608
Christoph Lameterb40f4752016-05-16 12:49:33 -0500609 stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
610 GFP_KERNEL);
611 if (!stats)
612 return NULL;
613 stats->names = names;
614 stats->num_counters = num_counters;
615 stats->lifespan = msecs_to_jiffies(lifespan);
Steve Wise7f624d02008-07-14 23:48:48 -0700616
Christoph Lameterb40f4752016-05-16 12:49:33 -0500617 return stats;
618}
619
Steve Wise7f624d02008-07-14 23:48:48 -0700620
Ira Weinyf9b22e32015-05-13 20:02:59 -0400621/* Define bits for the various functionality this port needs to be supported by
622 * the core.
623 */
624/* Management 0x00000FFF */
625#define RDMA_CORE_CAP_IB_MAD 0x00000001
626#define RDMA_CORE_CAP_IB_SMI 0x00000002
627#define RDMA_CORE_CAP_IB_CM 0x00000004
628#define RDMA_CORE_CAP_IW_CM 0x00000008
629#define RDMA_CORE_CAP_IB_SA 0x00000010
Ira Weiny65995fe2015-06-06 14:38:32 -0400630#define RDMA_CORE_CAP_OPA_MAD 0x00000020
Ira Weinyf9b22e32015-05-13 20:02:59 -0400631
632/* Address format 0x000FF000 */
633#define RDMA_CORE_CAP_AF_IB 0x00001000
634#define RDMA_CORE_CAP_ETH_AH 0x00002000
Dasaratharaman Chandramouli94d595c2017-03-20 19:38:09 -0400635#define RDMA_CORE_CAP_OPA_AH 0x00004000
Artemy Kovalyovb02289b2018-07-04 15:57:50 +0300636#define RDMA_CORE_CAP_IB_GRH_REQUIRED 0x00008000
Ira Weinyf9b22e32015-05-13 20:02:59 -0400637
638/* Protocol 0xFFF00000 */
639#define RDMA_CORE_CAP_PROT_IB 0x00100000
640#define RDMA_CORE_CAP_PROT_ROCE 0x00200000
641#define RDMA_CORE_CAP_PROT_IWARP 0x00400000
Matan Barak7766a992015-12-23 14:56:50 +0200642#define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
Or Gerlitzaa773bd2017-01-24 13:02:35 +0200643#define RDMA_CORE_CAP_PROT_RAW_PACKET 0x01000000
Or Gerlitzce1e0552017-01-24 13:02:38 +0200644#define RDMA_CORE_CAP_PROT_USNIC 0x02000000
Ira Weinyf9b22e32015-05-13 20:02:59 -0400645
Artemy Kovalyovb02289b2018-07-04 15:57:50 +0300646#define RDMA_CORE_PORT_IB_GRH_REQUIRED (RDMA_CORE_CAP_IB_GRH_REQUIRED \
647 | RDMA_CORE_CAP_PROT_ROCE \
648 | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP)
649
Ira Weinyf9b22e32015-05-13 20:02:59 -0400650#define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \
651 | RDMA_CORE_CAP_IB_MAD \
652 | RDMA_CORE_CAP_IB_SMI \
653 | RDMA_CORE_CAP_IB_CM \
654 | RDMA_CORE_CAP_IB_SA \
655 | RDMA_CORE_CAP_AF_IB)
656#define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \
657 | RDMA_CORE_CAP_IB_MAD \
658 | RDMA_CORE_CAP_IB_CM \
Ira Weinyf9b22e32015-05-13 20:02:59 -0400659 | RDMA_CORE_CAP_AF_IB \
660 | RDMA_CORE_CAP_ETH_AH)
Matan Barak7766a992015-12-23 14:56:50 +0200661#define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \
662 (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
663 | RDMA_CORE_CAP_IB_MAD \
664 | RDMA_CORE_CAP_IB_CM \
665 | RDMA_CORE_CAP_AF_IB \
666 | RDMA_CORE_CAP_ETH_AH)
Ira Weinyf9b22e32015-05-13 20:02:59 -0400667#define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \
668 | RDMA_CORE_CAP_IW_CM)
Ira Weiny65995fe2015-06-06 14:38:32 -0400669#define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \
670 | RDMA_CORE_CAP_OPA_MAD)
Ira Weinyf9b22e32015-05-13 20:02:59 -0400671
Or Gerlitzaa773bd2017-01-24 13:02:35 +0200672#define RDMA_CORE_PORT_RAW_PACKET (RDMA_CORE_CAP_PROT_RAW_PACKET)
673
Or Gerlitzce1e0552017-01-24 13:02:38 +0200674#define RDMA_CORE_PORT_USNIC (RDMA_CORE_CAP_PROT_USNIC)
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676struct ib_port_attr {
Eli Cohenfad61ad2016-03-11 22:58:36 +0200677 u64 subnet_prefix;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 enum ib_port_state state;
679 enum ib_mtu max_mtu;
680 enum ib_mtu active_mtu;
Kaike Wan6d723442020-05-11 12:06:18 -0400681 u32 phys_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 int gid_tbl_len;
Jason Gunthorpe2f944c02018-07-04 15:57:48 +0300683 unsigned int ip_gids:1;
684 /* This is the value from PortInfo CapabilityMask, defined by IBA */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 u32 port_cap_flags;
686 u32 max_msg_sz;
687 u32 bad_pkey_cntr;
688 u32 qkey_viol_cntr;
689 u16 pkey_tbl_len;
Dasaratharaman Chandramoulidb585402017-06-08 13:37:48 -0400690 u32 sm_lid;
Dasaratharaman Chandramouli582faf32017-06-08 13:37:47 -0400691 u32 lid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 u8 lmc;
693 u8 max_vl_num;
694 u8 sm_sl;
695 u8 subnet_timeout;
696 u8 init_type_reply;
697 u8 active_width;
698 u8 active_speed;
699 u8 phys_state;
Michael Guralnik1e8f43b2018-12-09 11:49:48 +0200700 u16 port_cap_flags2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701};
702
703enum ib_device_modify_flags {
Roland Dreierc5bcbbb2006-02-02 09:47:14 -0800704 IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
705 IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706};
707
Yuval Shaiabd99fde2016-08-25 10:57:07 -0700708#define IB_DEVICE_NODE_DESC_MAX 64
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710struct ib_device_modify {
711 u64 sys_image_guid;
Yuval Shaiabd99fde2016-08-25 10:57:07 -0700712 char node_desc[IB_DEVICE_NODE_DESC_MAX];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713};
714
715enum ib_port_modify_flags {
716 IB_PORT_SHUTDOWN = 1,
717 IB_PORT_INIT_TYPE = (1<<2),
Vishwanathapura, Niranjanacb493662017-06-01 17:04:02 -0700718 IB_PORT_RESET_QKEY_CNTR = (1<<3),
719 IB_PORT_OPA_MASK_CHG = (1<<4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720};
721
722struct ib_port_modify {
723 u32 set_port_cap_mask;
724 u32 clr_port_cap_mask;
725 u8 init_type;
726};
727
728enum ib_event_type {
729 IB_EVENT_CQ_ERR,
730 IB_EVENT_QP_FATAL,
731 IB_EVENT_QP_REQ_ERR,
732 IB_EVENT_QP_ACCESS_ERR,
733 IB_EVENT_COMM_EST,
734 IB_EVENT_SQ_DRAINED,
735 IB_EVENT_PATH_MIG,
736 IB_EVENT_PATH_MIG_ERR,
737 IB_EVENT_DEVICE_FATAL,
738 IB_EVENT_PORT_ACTIVE,
739 IB_EVENT_PORT_ERR,
740 IB_EVENT_LID_CHANGE,
741 IB_EVENT_PKEY_CHANGE,
Roland Dreierd41fcc62005-08-18 12:23:08 -0700742 IB_EVENT_SM_CHANGE,
743 IB_EVENT_SRQ_ERR,
744 IB_EVENT_SRQ_LIMIT_REACHED,
Leonid Arsh63942c92006-06-17 20:37:35 -0700745 IB_EVENT_QP_LAST_WQE_REACHED,
Or Gerlitz761d90e2011-06-15 14:39:29 +0000746 IB_EVENT_CLIENT_REREGISTER,
747 IB_EVENT_GID_CHANGE,
Yishai Hadasf213c052016-05-23 15:20:49 +0300748 IB_EVENT_WQ_FATAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749};
750
Bart Van Asschedb7489e2015-08-03 10:01:52 -0700751const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
Sagi Grimberg2b1b5b62015-05-18 13:40:28 +0300752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753struct ib_event {
754 struct ib_device *device;
755 union {
756 struct ib_cq *cq;
757 struct ib_qp *qp;
Roland Dreierd41fcc62005-08-18 12:23:08 -0700758 struct ib_srq *srq;
Yishai Hadasf213c052016-05-23 15:20:49 +0300759 struct ib_wq *wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 u8 port_num;
761 } element;
762 enum ib_event_type event;
763};
764
765struct ib_event_handler {
766 struct ib_device *device;
767 void (*handler)(struct ib_event_handler *, struct ib_event *);
768 struct list_head list;
769};
770
771#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
772 do { \
773 (_ptr)->device = _device; \
774 (_ptr)->handler = _handler; \
775 INIT_LIST_HEAD(&(_ptr)->list); \
776 } while (0)
777
778struct ib_global_route {
Jason Gunthorpe8d9ec9a2018-06-13 10:22:03 +0300779 const struct ib_gid_attr *sgid_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 union ib_gid dgid;
781 u32 flow_label;
782 u8 sgid_index;
783 u8 hop_limit;
784 u8 traffic_class;
785};
786
Hal Rosenstock513789e2005-07-27 11:45:34 -0700787struct ib_grh {
Sean Hefty97f52eb2005-08-13 21:05:57 -0700788 __be32 version_tclass_flow;
789 __be16 paylen;
Hal Rosenstock513789e2005-07-27 11:45:34 -0700790 u8 next_hdr;
791 u8 hop_limit;
792 union ib_gid sgid;
793 union ib_gid dgid;
794};
795
Somnath Koturc865f242015-12-23 14:56:51 +0200796union rdma_network_hdr {
797 struct ib_grh ibgrh;
798 struct {
799 /* The IB spec states that if it's IPv4, the header
800 * is located in the last 20 bytes of the header.
801 */
802 u8 reserved[20];
803 struct iphdr roce4grh;
804 };
805};
806
Don Hiatt7dafbab2017-05-12 09:19:55 -0700807#define IB_QPN_MASK 0xFFFFFF
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809enum {
810 IB_MULTICAST_QPN = 0xffffff
811};
812
Harvey Harrisonf3a7c662009-02-14 22:58:35 -0800813#define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
Dennis Dalessandrob4e64392016-01-06 10:04:31 -0800814#define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000)
Sean Hefty97f52eb2005-08-13 21:05:57 -0700815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816enum ib_ah_flags {
817 IB_AH_GRH = 1
818};
819
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700820enum ib_rate {
821 IB_RATE_PORT_CURRENT = 0,
822 IB_RATE_2_5_GBPS = 2,
823 IB_RATE_5_GBPS = 5,
824 IB_RATE_10_GBPS = 3,
825 IB_RATE_20_GBPS = 6,
826 IB_RATE_30_GBPS = 4,
827 IB_RATE_40_GBPS = 7,
828 IB_RATE_60_GBPS = 8,
829 IB_RATE_80_GBPS = 9,
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300830 IB_RATE_120_GBPS = 10,
831 IB_RATE_14_GBPS = 11,
832 IB_RATE_56_GBPS = 12,
833 IB_RATE_112_GBPS = 13,
834 IB_RATE_168_GBPS = 14,
835 IB_RATE_25_GBPS = 15,
836 IB_RATE_100_GBPS = 16,
837 IB_RATE_200_GBPS = 17,
Michael Guralnika5a5d192018-12-09 11:49:50 +0200838 IB_RATE_300_GBPS = 18,
839 IB_RATE_28_GBPS = 19,
840 IB_RATE_50_GBPS = 20,
841 IB_RATE_400_GBPS = 21,
842 IB_RATE_600_GBPS = 22,
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700843};
844
845/**
846 * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
847 * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
848 * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
849 * @rate: rate to convert.
850 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700851__attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700852
853/**
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300854 * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
855 * For example, IB_RATE_2_5_GBPS will be converted to 2500.
856 * @rate: rate to convert.
857 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700858__attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300859
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200860
861/**
Sagi Grimberg9bee1782015-07-30 10:32:35 +0300862 * enum ib_mr_type - memory region type
863 * @IB_MR_TYPE_MEM_REG: memory region that is used for
864 * normal registration
Sagi Grimbergf5aa9152016-02-29 19:07:32 +0200865 * @IB_MR_TYPE_SG_GAPS: memory region that is capable to
866 * register any arbitrary sg lists (without
867 * the normal mr constraints - see
868 * ib_map_mr_sg)
Max Gurtovoya0bc0992019-06-11 18:52:38 +0300869 * @IB_MR_TYPE_DM: memory region that is used for device
870 * memory registration
871 * @IB_MR_TYPE_USER: memory region that is used for the user-space
872 * application
873 * @IB_MR_TYPE_DMA: memory region that is used for DMA operations
874 * without address translations (VA=PA)
Israel Rukshin26bc7ea2019-06-11 18:52:39 +0300875 * @IB_MR_TYPE_INTEGRITY: memory region that is used for
876 * data integrity operations
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200877 */
Sagi Grimberg9bee1782015-07-30 10:32:35 +0300878enum ib_mr_type {
879 IB_MR_TYPE_MEM_REG,
Sagi Grimbergf5aa9152016-02-29 19:07:32 +0200880 IB_MR_TYPE_SG_GAPS,
Max Gurtovoya0bc0992019-06-11 18:52:38 +0300881 IB_MR_TYPE_DM,
882 IB_MR_TYPE_USER,
883 IB_MR_TYPE_DMA,
Israel Rukshin26bc7ea2019-06-11 18:52:39 +0300884 IB_MR_TYPE_INTEGRITY,
Sagi Grimberg17cd3a22014-02-23 14:19:04 +0200885};
886
Sagi Grimberg1b01d332014-02-23 14:19:05 +0200887enum ib_mr_status_check {
888 IB_MR_CHECK_SIG_STATUS = 1,
889};
890
891/**
892 * struct ib_mr_status - Memory region status container
893 *
894 * @fail_status: Bitmask of MR checks status. For each
895 * failed check a corresponding status bit is set.
896 * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
897 * failure.
898 */
899struct ib_mr_status {
900 u32 fail_status;
901 struct ib_sig_err sig_err;
902};
903
Marcel Apfelbaum71eeba12011-10-05 14:21:47 +0300904/**
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700905 * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
906 * enum.
907 * @mult: multiple to convert.
908 */
Roland Dreier8385fd82014-06-04 10:00:16 -0700909__attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
Jack Morgensteinbf6a9e32006-04-10 09:43:47 -0700910
Maor Gottliebfa5d0102020-04-30 22:21:42 +0300911struct rdma_ah_init_attr {
912 struct rdma_ah_attr *ah_attr;
913 u32 flags;
Maor Gottlieb51aab122020-04-30 22:21:44 +0300914 struct net_device *xmit_slave;
Maor Gottliebfa5d0102020-04-30 22:21:42 +0300915};
916
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -0400917enum rdma_ah_attr_type {
Don Hiatt87daac62018-02-01 10:57:03 -0800918 RDMA_AH_ATTR_TYPE_UNDEFINED,
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -0400919 RDMA_AH_ATTR_TYPE_IB,
920 RDMA_AH_ATTR_TYPE_ROCE,
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -0400921 RDMA_AH_ATTR_TYPE_OPA,
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -0400922};
923
924struct ib_ah_attr {
925 u16 dlid;
926 u8 src_path_bits;
927};
928
929struct roce_ah_attr {
930 u8 dmac[ETH_ALEN];
931};
932
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -0400933struct opa_ah_attr {
934 u32 dlid;
935 u8 src_path_bits;
Don Hiattd98bb7f2017-08-04 13:54:16 -0700936 bool make_grd;
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -0400937};
938
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -0400939struct rdma_ah_attr {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 struct ib_global_route grh;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 u8 sl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 u8 static_rate;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 u8 port_num;
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -0400944 u8 ah_flags;
945 enum rdma_ah_attr_type type;
946 union {
947 struct ib_ah_attr ib;
948 struct roce_ah_attr roce;
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -0400949 struct opa_ah_attr opa;
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -0400950 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951};
952
953enum ib_wc_status {
954 IB_WC_SUCCESS,
955 IB_WC_LOC_LEN_ERR,
956 IB_WC_LOC_QP_OP_ERR,
957 IB_WC_LOC_EEC_OP_ERR,
958 IB_WC_LOC_PROT_ERR,
959 IB_WC_WR_FLUSH_ERR,
960 IB_WC_MW_BIND_ERR,
961 IB_WC_BAD_RESP_ERR,
962 IB_WC_LOC_ACCESS_ERR,
963 IB_WC_REM_INV_REQ_ERR,
964 IB_WC_REM_ACCESS_ERR,
965 IB_WC_REM_OP_ERR,
966 IB_WC_RETRY_EXC_ERR,
967 IB_WC_RNR_RETRY_EXC_ERR,
968 IB_WC_LOC_RDD_VIOL_ERR,
969 IB_WC_REM_INV_RD_REQ_ERR,
970 IB_WC_REM_ABORT_ERR,
971 IB_WC_INV_EECN_ERR,
972 IB_WC_INV_EEC_STATE_ERR,
973 IB_WC_FATAL_ERR,
974 IB_WC_RESP_TIMEOUT_ERR,
975 IB_WC_GENERAL_ERR
976};
977
Bart Van Asschedb7489e2015-08-03 10:01:52 -0700978const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
Sagi Grimberg2b1b5b62015-05-18 13:40:28 +0300979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980enum ib_wc_opcode {
981 IB_WC_SEND,
982 IB_WC_RDMA_WRITE,
983 IB_WC_RDMA_READ,
984 IB_WC_COMP_SWAP,
985 IB_WC_FETCH_ADD,
Eli Cohenc93570f2008-04-16 21:09:27 -0700986 IB_WC_LSO,
Steve Wise00f7ec32008-07-14 23:48:45 -0700987 IB_WC_LOCAL_INV,
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +0300988 IB_WC_REG_MR,
Vladimir Sokolovsky5e80ba82010-04-14 17:23:01 +0300989 IB_WC_MASKED_COMP_SWAP,
990 IB_WC_MASKED_FETCH_ADD,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991/*
992 * Set value of IB_WC_RECV so consumers can test if a completion is a
993 * receive by testing (opcode & IB_WC_RECV).
994 */
995 IB_WC_RECV = 1 << 7,
996 IB_WC_RECV_RDMA_WITH_IMM
997};
998
999enum ib_wc_flags {
1000 IB_WC_GRH = 1,
Steve Wise00f7ec32008-07-14 23:48:45 -07001001 IB_WC_WITH_IMM = (1<<1),
1002 IB_WC_WITH_INVALIDATE = (1<<2),
Or Gerlitzd927d502012-01-11 19:03:51 +02001003 IB_WC_IP_CSUM_OK = (1<<3),
Matan Barakdd5f03b2013-12-12 18:03:11 +02001004 IB_WC_WITH_SMAC = (1<<4),
1005 IB_WC_WITH_VLAN = (1<<5),
Somnath Koturc865f242015-12-23 14:56:51 +02001006 IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007};
1008
1009struct ib_wc {
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001010 union {
1011 u64 wr_id;
1012 struct ib_cqe *wr_cqe;
1013 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 enum ib_wc_status status;
1015 enum ib_wc_opcode opcode;
1016 u32 vendor_err;
1017 u32 byte_len;
Michael S. Tsirkin062dbb62006-12-31 21:09:42 +02001018 struct ib_qp *qp;
Steve Wise00f7ec32008-07-14 23:48:45 -07001019 union {
1020 __be32 imm_data;
1021 u32 invalidate_rkey;
1022 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 u32 src_qp;
Bodong Wangcd2a6e72018-01-12 07:58:41 +02001024 u32 slid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 int wc_flags;
1026 u16 pkey_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 u8 sl;
1028 u8 dlid_path_bits;
1029 u8 port_num; /* valid only for DR SMPs on switches */
Matan Barakdd5f03b2013-12-12 18:03:11 +02001030 u8 smac[ETH_ALEN];
1031 u16 vlan_id;
Somnath Koturc865f242015-12-23 14:56:51 +02001032 u8 network_hdr_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033};
1034
Roland Dreiered23a722007-05-06 21:02:48 -07001035enum ib_cq_notify_flags {
1036 IB_CQ_SOLICITED = 1 << 0,
1037 IB_CQ_NEXT_COMP = 1 << 1,
1038 IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
1039 IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040};
1041
Sean Hefty96104ed2011-05-23 16:31:36 -07001042enum ib_srq_type {
Yishai Hadas175ba582020-05-19 10:27:08 +03001043 IB_SRQT_BASIC = IB_UVERBS_SRQT_BASIC,
1044 IB_SRQT_XRC = IB_UVERBS_SRQT_XRC,
1045 IB_SRQT_TM = IB_UVERBS_SRQT_TM,
Sean Hefty96104ed2011-05-23 16:31:36 -07001046};
1047
Artemy Kovalyov1a56ff62017-08-17 15:52:04 +03001048static inline bool ib_srq_has_cq(enum ib_srq_type srq_type)
1049{
Artemy Kovalyov9c2c8492017-08-17 15:52:05 +03001050 return srq_type == IB_SRQT_XRC ||
1051 srq_type == IB_SRQT_TM;
Artemy Kovalyov1a56ff62017-08-17 15:52:04 +03001052}
1053
Roland Dreierd41fcc62005-08-18 12:23:08 -07001054enum ib_srq_attr_mask {
1055 IB_SRQ_MAX_WR = 1 << 0,
1056 IB_SRQ_LIMIT = 1 << 1,
1057};
1058
1059struct ib_srq_attr {
1060 u32 max_wr;
1061 u32 max_sge;
1062 u32 srq_limit;
1063};
1064
1065struct ib_srq_init_attr {
1066 void (*event_handler)(struct ib_event *, void *);
1067 void *srq_context;
1068 struct ib_srq_attr attr;
Sean Hefty96104ed2011-05-23 16:31:36 -07001069 enum ib_srq_type srq_type;
Sean Hefty418d5132011-05-23 19:42:29 -07001070
Artemy Kovalyov1a56ff62017-08-17 15:52:04 +03001071 struct {
1072 struct ib_cq *cq;
1073 union {
1074 struct {
1075 struct ib_xrcd *xrcd;
1076 } xrc;
Artemy Kovalyov9c2c8492017-08-17 15:52:05 +03001077
1078 struct {
1079 u32 max_num_tags;
1080 } tag_matching;
Artemy Kovalyov1a56ff62017-08-17 15:52:04 +03001081 };
Sean Hefty418d5132011-05-23 19:42:29 -07001082 } ext;
Roland Dreierd41fcc62005-08-18 12:23:08 -07001083};
1084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085struct ib_qp_cap {
1086 u32 max_send_wr;
1087 u32 max_recv_wr;
1088 u32 max_send_sge;
1089 u32 max_recv_sge;
1090 u32 max_inline_data;
Christoph Hellwiga060b562016-05-03 18:01:09 +02001091
1092 /*
1093 * Maximum number of rdma_rw_ctx structures in flight at a time.
1094 * ib_create_qp() will calculate the right amount of neededed WRs
1095 * and MRs based on this.
1096 */
1097 u32 max_rdma_ctxs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098};
1099
1100enum ib_sig_type {
1101 IB_SIGNAL_ALL_WR,
1102 IB_SIGNAL_REQ_WR
1103};
1104
1105enum ib_qp_type {
1106 /*
1107 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
1108 * here (and in that order) since the MAD layer uses them as
1109 * indices into a 2-entry table.
1110 */
1111 IB_QPT_SMI,
1112 IB_QPT_GSI,
1113
Yishai Hadas175ba582020-05-19 10:27:08 +03001114 IB_QPT_RC = IB_UVERBS_QPT_RC,
1115 IB_QPT_UC = IB_UVERBS_QPT_UC,
1116 IB_QPT_UD = IB_UVERBS_QPT_UD,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 IB_QPT_RAW_IPV6,
Sean Heftyb42b63c2011-05-23 19:59:25 -07001118 IB_QPT_RAW_ETHERTYPE,
Yishai Hadas175ba582020-05-19 10:27:08 +03001119 IB_QPT_RAW_PACKET = IB_UVERBS_QPT_RAW_PACKET,
1120 IB_QPT_XRC_INI = IB_UVERBS_QPT_XRC_INI,
1121 IB_QPT_XRC_TGT = IB_UVERBS_QPT_XRC_TGT,
Jack Morgenstein0134f162013-07-07 17:25:52 +03001122 IB_QPT_MAX,
Yishai Hadas175ba582020-05-19 10:27:08 +03001123 IB_QPT_DRIVER = IB_UVERBS_QPT_DRIVER,
Jack Morgenstein0134f162013-07-07 17:25:52 +03001124 /* Reserve a range for qp types internal to the low level driver.
1125 * These qp types will not be visible at the IB core layer, so the
1126 * IB_QPT_MAX usages should not be affected in the core layer
1127 */
1128 IB_QPT_RESERVED1 = 0x1000,
1129 IB_QPT_RESERVED2,
1130 IB_QPT_RESERVED3,
1131 IB_QPT_RESERVED4,
1132 IB_QPT_RESERVED5,
1133 IB_QPT_RESERVED6,
1134 IB_QPT_RESERVED7,
1135 IB_QPT_RESERVED8,
1136 IB_QPT_RESERVED9,
1137 IB_QPT_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138};
1139
Eli Cohenb846f252008-04-16 21:09:27 -07001140enum ib_qp_create_flags {
Ron Livne47ee1b92008-07-14 23:48:48 -07001141 IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
Yishai Hadas175ba582020-05-19 10:27:08 +03001142 IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK =
1143 IB_UVERBS_QP_CREATE_BLOCK_MULTICAST_LOOPBACK,
Leon Romanovsky8a06ce52015-12-20 12:16:10 +02001144 IB_QP_CREATE_CROSS_CHANNEL = 1 << 2,
1145 IB_QP_CREATE_MANAGED_SEND = 1 << 3,
1146 IB_QP_CREATE_MANAGED_RECV = 1 << 4,
Matan Barak90f1d1b2013-11-07 15:25:12 +02001147 IB_QP_CREATE_NETIF_QP = 1 << 5,
Israel Rukshinc0a6cbb2019-06-11 18:52:50 +03001148 IB_QP_CREATE_INTEGRITY_EN = 1 << 6,
Gary Leshner7f90a5a2020-05-11 12:06:07 -04001149 IB_QP_CREATE_NETDEV_USE = 1 << 7,
Yishai Hadas175ba582020-05-19 10:27:08 +03001150 IB_QP_CREATE_SCATTER_FCS =
1151 IB_UVERBS_QP_CREATE_SCATTER_FCS,
1152 IB_QP_CREATE_CVLAN_STRIPPING =
1153 IB_UVERBS_QP_CREATE_CVLAN_STRIPPING,
Yishai Hadas02984cc2017-06-08 16:15:06 +03001154 IB_QP_CREATE_SOURCE_QPN = 1 << 10,
Yishai Hadas175ba582020-05-19 10:27:08 +03001155 IB_QP_CREATE_PCI_WRITE_END_PADDING =
1156 IB_UVERBS_QP_CREATE_PCI_WRITE_END_PADDING,
Jack Morgensteind2b57062012-08-03 08:40:37 +00001157 /* reserve bits 26-31 for low level drivers' internal use */
1158 IB_QP_CREATE_RESERVED_START = 1 << 26,
1159 IB_QP_CREATE_RESERVED_END = 1 << 31,
Eli Cohenb846f252008-04-16 21:09:27 -07001160};
1161
Yishai Hadas73c40c62013-08-01 18:49:53 +03001162/*
1163 * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
1164 * callback to destroy the passed in QP.
1165 */
1166
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167struct ib_qp_init_attr {
Chuck Levereb93c82e2018-09-04 11:45:20 -04001168 /* Consumer's event_handler callback must not block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 void (*event_handler)(struct ib_event *, void *);
Chuck Levereb93c82e2018-09-04 11:45:20 -04001170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 void *qp_context;
1172 struct ib_cq *send_cq;
1173 struct ib_cq *recv_cq;
1174 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001175 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 struct ib_qp_cap cap;
1177 enum ib_sig_type sq_sig_type;
1178 enum ib_qp_type qp_type;
Nathan Chancellorb56511c2018-09-24 12:57:16 -07001179 u32 create_flags;
Christoph Hellwiga060b562016-05-03 18:01:09 +02001180
1181 /*
1182 * Only needed for special QP types, or when using the RW API.
1183 */
1184 u8 port_num;
Yishai Hadasa9017e22016-05-23 15:20:54 +03001185 struct ib_rwq_ind_table *rwq_ind_tbl;
Yishai Hadas02984cc2017-06-08 16:15:06 +03001186 u32 source_qpn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187};
1188
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001189struct ib_qp_open_attr {
1190 void (*event_handler)(struct ib_event *, void *);
1191 void *qp_context;
1192 u32 qp_num;
1193 enum ib_qp_type qp_type;
1194};
1195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196enum ib_rnr_timeout {
1197 IB_RNR_TIMER_655_36 = 0,
1198 IB_RNR_TIMER_000_01 = 1,
1199 IB_RNR_TIMER_000_02 = 2,
1200 IB_RNR_TIMER_000_03 = 3,
1201 IB_RNR_TIMER_000_04 = 4,
1202 IB_RNR_TIMER_000_06 = 5,
1203 IB_RNR_TIMER_000_08 = 6,
1204 IB_RNR_TIMER_000_12 = 7,
1205 IB_RNR_TIMER_000_16 = 8,
1206 IB_RNR_TIMER_000_24 = 9,
1207 IB_RNR_TIMER_000_32 = 10,
1208 IB_RNR_TIMER_000_48 = 11,
1209 IB_RNR_TIMER_000_64 = 12,
1210 IB_RNR_TIMER_000_96 = 13,
1211 IB_RNR_TIMER_001_28 = 14,
1212 IB_RNR_TIMER_001_92 = 15,
1213 IB_RNR_TIMER_002_56 = 16,
1214 IB_RNR_TIMER_003_84 = 17,
1215 IB_RNR_TIMER_005_12 = 18,
1216 IB_RNR_TIMER_007_68 = 19,
1217 IB_RNR_TIMER_010_24 = 20,
1218 IB_RNR_TIMER_015_36 = 21,
1219 IB_RNR_TIMER_020_48 = 22,
1220 IB_RNR_TIMER_030_72 = 23,
1221 IB_RNR_TIMER_040_96 = 24,
1222 IB_RNR_TIMER_061_44 = 25,
1223 IB_RNR_TIMER_081_92 = 26,
1224 IB_RNR_TIMER_122_88 = 27,
1225 IB_RNR_TIMER_163_84 = 28,
1226 IB_RNR_TIMER_245_76 = 29,
1227 IB_RNR_TIMER_327_68 = 30,
1228 IB_RNR_TIMER_491_52 = 31
1229};
1230
1231enum ib_qp_attr_mask {
1232 IB_QP_STATE = 1,
1233 IB_QP_CUR_STATE = (1<<1),
1234 IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
1235 IB_QP_ACCESS_FLAGS = (1<<3),
1236 IB_QP_PKEY_INDEX = (1<<4),
1237 IB_QP_PORT = (1<<5),
1238 IB_QP_QKEY = (1<<6),
1239 IB_QP_AV = (1<<7),
1240 IB_QP_PATH_MTU = (1<<8),
1241 IB_QP_TIMEOUT = (1<<9),
1242 IB_QP_RETRY_CNT = (1<<10),
1243 IB_QP_RNR_RETRY = (1<<11),
1244 IB_QP_RQ_PSN = (1<<12),
1245 IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
1246 IB_QP_ALT_PATH = (1<<14),
1247 IB_QP_MIN_RNR_TIMER = (1<<15),
1248 IB_QP_SQ_PSN = (1<<16),
1249 IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
1250 IB_QP_PATH_MIG_STATE = (1<<18),
1251 IB_QP_CAP = (1<<19),
Matan Barakdd5f03b2013-12-12 18:03:11 +02001252 IB_QP_DEST_QPN = (1<<20),
Matan Barakaa744cc2015-10-15 18:38:53 +03001253 IB_QP_RESERVED1 = (1<<21),
1254 IB_QP_RESERVED2 = (1<<22),
1255 IB_QP_RESERVED3 = (1<<23),
1256 IB_QP_RESERVED4 = (1<<24),
Bodong Wang528e5a12016-12-01 13:43:14 +02001257 IB_QP_RATE_LIMIT = (1<<25),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258};
1259
1260enum ib_qp_state {
1261 IB_QPS_RESET,
1262 IB_QPS_INIT,
1263 IB_QPS_RTR,
1264 IB_QPS_RTS,
1265 IB_QPS_SQD,
1266 IB_QPS_SQE,
1267 IB_QPS_ERR
1268};
1269
1270enum ib_mig_state {
1271 IB_MIG_MIGRATED,
1272 IB_MIG_REARM,
1273 IB_MIG_ARMED
1274};
1275
Shani Michaeli7083e422013-02-06 16:19:12 +00001276enum ib_mw_type {
1277 IB_MW_TYPE_1 = 1,
1278 IB_MW_TYPE_2 = 2
1279};
1280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281struct ib_qp_attr {
1282 enum ib_qp_state qp_state;
1283 enum ib_qp_state cur_qp_state;
1284 enum ib_mtu path_mtu;
1285 enum ib_mig_state path_mig_state;
1286 u32 qkey;
1287 u32 rq_psn;
1288 u32 sq_psn;
1289 u32 dest_qp_num;
1290 int qp_access_flags;
1291 struct ib_qp_cap cap;
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -04001292 struct rdma_ah_attr ah_attr;
1293 struct rdma_ah_attr alt_ah_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 u16 pkey_index;
1295 u16 alt_pkey_index;
1296 u8 en_sqd_async_notify;
1297 u8 sq_draining;
1298 u8 max_rd_atomic;
1299 u8 max_dest_rd_atomic;
1300 u8 min_rnr_timer;
1301 u8 port_num;
1302 u8 timeout;
1303 u8 retry_cnt;
1304 u8 rnr_retry;
1305 u8 alt_port_num;
1306 u8 alt_timeout;
Bodong Wang528e5a12016-12-01 13:43:14 +02001307 u32 rate_limit;
Maor Gottlieb51aab122020-04-30 22:21:44 +03001308 struct net_device *xmit_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309};
1310
1311enum ib_wr_opcode {
Jason Gunthorpe9a597392018-08-14 15:33:02 -07001312 /* These are shared with userspace */
1313 IB_WR_RDMA_WRITE = IB_UVERBS_WR_RDMA_WRITE,
1314 IB_WR_RDMA_WRITE_WITH_IMM = IB_UVERBS_WR_RDMA_WRITE_WITH_IMM,
1315 IB_WR_SEND = IB_UVERBS_WR_SEND,
1316 IB_WR_SEND_WITH_IMM = IB_UVERBS_WR_SEND_WITH_IMM,
1317 IB_WR_RDMA_READ = IB_UVERBS_WR_RDMA_READ,
1318 IB_WR_ATOMIC_CMP_AND_SWP = IB_UVERBS_WR_ATOMIC_CMP_AND_SWP,
1319 IB_WR_ATOMIC_FETCH_AND_ADD = IB_UVERBS_WR_ATOMIC_FETCH_AND_ADD,
1320 IB_WR_LSO = IB_UVERBS_WR_TSO,
1321 IB_WR_SEND_WITH_INV = IB_UVERBS_WR_SEND_WITH_INV,
1322 IB_WR_RDMA_READ_WITH_INV = IB_UVERBS_WR_RDMA_READ_WITH_INV,
1323 IB_WR_LOCAL_INV = IB_UVERBS_WR_LOCAL_INV,
1324 IB_WR_MASKED_ATOMIC_CMP_AND_SWP =
1325 IB_UVERBS_WR_MASKED_ATOMIC_CMP_AND_SWP,
1326 IB_WR_MASKED_ATOMIC_FETCH_AND_ADD =
1327 IB_UVERBS_WR_MASKED_ATOMIC_FETCH_AND_ADD,
1328
1329 /* These are kernel only and can not be issued by userspace */
1330 IB_WR_REG_MR = 0x20,
Max Gurtovoy38ca87c2019-06-11 18:52:46 +03001331 IB_WR_REG_MR_INTEGRITY,
Jason Gunthorpe9a597392018-08-14 15:33:02 -07001332
Jack Morgenstein0134f162013-07-07 17:25:52 +03001333 /* reserve values for low level drivers' internal use.
1334 * These values will not be used at all in the ib core layer.
1335 */
1336 IB_WR_RESERVED1 = 0xf0,
1337 IB_WR_RESERVED2,
1338 IB_WR_RESERVED3,
1339 IB_WR_RESERVED4,
1340 IB_WR_RESERVED5,
1341 IB_WR_RESERVED6,
1342 IB_WR_RESERVED7,
1343 IB_WR_RESERVED8,
1344 IB_WR_RESERVED9,
1345 IB_WR_RESERVED10,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346};
1347
1348enum ib_send_flags {
1349 IB_SEND_FENCE = 1,
1350 IB_SEND_SIGNALED = (1<<1),
1351 IB_SEND_SOLICITED = (1<<2),
Eli Cohene0605d92008-01-30 18:30:57 +02001352 IB_SEND_INLINE = (1<<3),
Jack Morgenstein0134f162013-07-07 17:25:52 +03001353 IB_SEND_IP_CSUM = (1<<4),
1354
1355 /* reserve bits 26-31 for low level drivers' internal use */
1356 IB_SEND_RESERVED_START = (1 << 26),
1357 IB_SEND_RESERVED_END = (1 << 31),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358};
1359
1360struct ib_sge {
1361 u64 addr;
1362 u32 length;
1363 u32 lkey;
1364};
1365
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001366struct ib_cqe {
1367 void (*done)(struct ib_cq *cq, struct ib_wc *wc);
1368};
1369
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370struct ib_send_wr {
1371 struct ib_send_wr *next;
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001372 union {
1373 u64 wr_id;
1374 struct ib_cqe *wr_cqe;
1375 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 struct ib_sge *sg_list;
1377 int num_sge;
1378 enum ib_wr_opcode opcode;
1379 int send_flags;
Roland Dreier0f39cf32008-04-16 21:09:32 -07001380 union {
1381 __be32 imm_data;
1382 u32 invalidate_rkey;
1383 } ex;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384};
1385
Christoph Hellwige622f2f2015-10-08 09:16:33 +01001386struct ib_rdma_wr {
1387 struct ib_send_wr wr;
1388 u64 remote_addr;
1389 u32 rkey;
1390};
1391
Bart Van Asschef696bf62018-07-18 09:25:14 -07001392static inline const struct ib_rdma_wr *rdma_wr(const struct ib_send_wr *wr)
Christoph Hellwige622f2f2015-10-08 09:16:33 +01001393{
1394 return container_of(wr, struct ib_rdma_wr, wr);
1395}
1396
1397struct ib_atomic_wr {
1398 struct ib_send_wr wr;
1399 u64 remote_addr;
1400 u64 compare_add;
1401 u64 swap;
1402 u64 compare_add_mask;
1403 u64 swap_mask;
1404 u32 rkey;
1405};
1406
Bart Van Asschef696bf62018-07-18 09:25:14 -07001407static inline const struct ib_atomic_wr *atomic_wr(const struct ib_send_wr *wr)
Christoph Hellwige622f2f2015-10-08 09:16:33 +01001408{
1409 return container_of(wr, struct ib_atomic_wr, wr);
1410}
1411
1412struct ib_ud_wr {
1413 struct ib_send_wr wr;
1414 struct ib_ah *ah;
1415 void *header;
1416 int hlen;
1417 int mss;
1418 u32 remote_qpn;
1419 u32 remote_qkey;
1420 u16 pkey_index; /* valid for GSI only */
1421 u8 port_num; /* valid for DR SMPs on switch only */
1422};
1423
Bart Van Asschef696bf62018-07-18 09:25:14 -07001424static inline const struct ib_ud_wr *ud_wr(const struct ib_send_wr *wr)
Christoph Hellwige622f2f2015-10-08 09:16:33 +01001425{
1426 return container_of(wr, struct ib_ud_wr, wr);
1427}
1428
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03001429struct ib_reg_wr {
1430 struct ib_send_wr wr;
1431 struct ib_mr *mr;
1432 u32 key;
1433 int access;
1434};
1435
Bart Van Asschef696bf62018-07-18 09:25:14 -07001436static inline const struct ib_reg_wr *reg_wr(const struct ib_send_wr *wr)
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03001437{
1438 return container_of(wr, struct ib_reg_wr, wr);
1439}
1440
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441struct ib_recv_wr {
1442 struct ib_recv_wr *next;
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001443 union {
1444 u64 wr_id;
1445 struct ib_cqe *wr_cqe;
1446 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 struct ib_sge *sg_list;
1448 int num_sge;
1449};
1450
1451enum ib_access_flags {
Jason Gunthorpe4fca0372018-07-11 16:20:44 -06001452 IB_ACCESS_LOCAL_WRITE = IB_UVERBS_ACCESS_LOCAL_WRITE,
1453 IB_ACCESS_REMOTE_WRITE = IB_UVERBS_ACCESS_REMOTE_WRITE,
1454 IB_ACCESS_REMOTE_READ = IB_UVERBS_ACCESS_REMOTE_READ,
1455 IB_ACCESS_REMOTE_ATOMIC = IB_UVERBS_ACCESS_REMOTE_ATOMIC,
1456 IB_ACCESS_MW_BIND = IB_UVERBS_ACCESS_MW_BIND,
1457 IB_ZERO_BASED = IB_UVERBS_ACCESS_ZERO_BASED,
1458 IB_ACCESS_ON_DEMAND = IB_UVERBS_ACCESS_ON_DEMAND,
1459 IB_ACCESS_HUGETLB = IB_UVERBS_ACCESS_HUGETLB,
Michael Guralnik2233c662020-01-08 20:05:38 +02001460 IB_ACCESS_RELAXED_ORDERING = IB_UVERBS_ACCESS_RELAXED_ORDERING,
Jason Gunthorpe4fca0372018-07-11 16:20:44 -06001461
Michael Guralnik68d384b2020-01-08 20:05:36 +02001462 IB_ACCESS_OPTIONAL = IB_UVERBS_ACCESS_OPTIONAL_RANGE,
1463 IB_ACCESS_SUPPORTED =
1464 ((IB_ACCESS_HUGETLB << 1) - 1) | IB_ACCESS_OPTIONAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465};
1466
Christoph Hellwigb7d3e0a2015-12-23 19:12:47 +01001467/*
1468 * XXX: these are apparently used for ->rereg_user_mr, no idea why they
1469 * are hidden here instead of a uapi header!
1470 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471enum ib_mr_rereg_flags {
1472 IB_MR_REREG_TRANS = 1,
1473 IB_MR_REREG_PD = (1<<1),
Matan Barak7e6edb92014-07-31 11:01:28 +03001474 IB_MR_REREG_ACCESS = (1<<2),
1475 IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476};
1477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478struct ib_fmr_attr {
1479 int max_pages;
1480 int max_maps;
Or Gerlitzd36f34a2006-02-02 10:43:45 -08001481 u8 page_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482};
1483
Haggai Eran882214e2014-12-11 17:04:18 +02001484struct ib_umem;
1485
Matan Barak38321252017-04-04 13:31:42 +03001486enum rdma_remove_reason {
Yishai Hadas1c774832018-06-20 17:11:39 +03001487 /*
1488 * Userspace requested uobject deletion or initial try
1489 * to remove uobject via cleanup. Call could fail
1490 */
Matan Barak38321252017-04-04 13:31:42 +03001491 RDMA_REMOVE_DESTROY,
1492 /* Context deletion. This call should delete the actual object itself */
1493 RDMA_REMOVE_CLOSE,
1494 /* Driver is being hot-unplugged. This call should delete the actual object itself */
1495 RDMA_REMOVE_DRIVER_REMOVE,
Jason Gunthorpe87ad80a2018-07-25 21:40:12 -06001496 /* uobj is being cleaned-up before being committed */
1497 RDMA_REMOVE_ABORT,
Jason Gunthorpe0ac89032020-05-19 10:27:05 +03001498 /*
1499 * uobj has been fully created, with the uobj->object set, but is being
1500 * cleaned up before being comitted
1501 */
1502 RDMA_REMOVE_ABORT_HWOBJ,
Matan Barak38321252017-04-04 13:31:42 +03001503};
1504
Parav Pandit43579b52017-01-10 00:02:14 +00001505struct ib_rdmacg_object {
1506#ifdef CONFIG_CGROUP_RDMA
1507 struct rdma_cgroup *cg; /* owner rdma cgroup */
1508#endif
1509};
1510
Roland Dreiere2773c02005-07-07 17:57:10 -07001511struct ib_ucontext {
1512 struct ib_device *device;
Matan Barak771addf2017-04-04 13:31:41 +03001513 struct ib_uverbs_file *ufile;
Jason Gunthorpee9517472018-07-10 20:55:19 -06001514 /*
1515 * 'closing' can be read by the driver only during a destroy callback,
1516 * it is set when we are closing the file descriptor and indicates
1517 * that mm_sem may be locked.
1518 */
Leon Romanovsky6ceb6332018-09-03 20:18:03 +03001519 bool closing;
Shachar Raindel8ada2c12014-12-11 17:04:17 +02001520
Yishai Hadas1c774832018-06-20 17:11:39 +03001521 bool cleanup_retryable;
Matan Barak38321252017-04-04 13:31:42 +03001522
Parav Pandit43579b52017-01-10 00:02:14 +00001523 struct ib_rdmacg_object cg_obj;
Leon Romanovsky60615212018-11-28 13:16:43 +02001524 /*
1525 * Implementation details of the RDMA core, don't use in drivers:
1526 */
1527 struct rdma_restrack_entry res;
Michal Kalderon3411f9f2019-10-30 11:44:11 +02001528 struct xarray mmap_xa;
Roland Dreiere2773c02005-07-07 17:57:10 -07001529};
1530
1531struct ib_uobject {
1532 u64 user_handle; /* handle given to us by userspace */
Jason Gunthorpe6a5e9c82018-07-04 11:32:07 +03001533 /* ufile & ucontext owning this object */
1534 struct ib_uverbs_file *ufile;
1535 /* FIXME, save memory: ufile->context == context */
Roland Dreiere2773c02005-07-07 17:57:10 -07001536 struct ib_ucontext *context; /* associated user context */
Roland Dreier9ead1902006-06-17 20:44:49 -07001537 void *object; /* containing object */
Roland Dreiere2773c02005-07-07 17:57:10 -07001538 struct list_head list; /* link to context's list */
Parav Pandit43579b52017-01-10 00:02:14 +00001539 struct ib_rdmacg_object cg_obj; /* rdmacg object */
Roland Dreierb3d636b2008-04-16 21:01:06 -07001540 int id; /* index into kernel idr */
Roland Dreier9ead1902006-06-17 20:44:49 -07001541 struct kref ref;
Matan Barak38321252017-04-04 13:31:42 +03001542 atomic_t usecnt; /* protects exclusive access */
Mike Marciniszynd144da82015-11-02 12:13:25 -05001543 struct rcu_head rcu; /* kfree_rcu() overhead */
Matan Barak38321252017-04-04 13:31:42 +03001544
Jason Gunthorpe6b0d08f2018-08-09 20:14:37 -06001545 const struct uverbs_api_object *uapi_object;
Roland Dreiere2773c02005-07-07 17:57:10 -07001546};
1547
Roland Dreiere2773c02005-07-07 17:57:10 -07001548struct ib_udata {
Yann Droneaud309243e2013-12-11 23:01:44 +01001549 const void __user *inbuf;
Roland Dreiere2773c02005-07-07 17:57:10 -07001550 void __user *outbuf;
1551 size_t inlen;
1552 size_t outlen;
1553};
1554
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555struct ib_pd {
Jason Gunthorpe96249d72015-08-05 14:14:45 -06001556 u32 local_dma_lkey;
Christoph Hellwiged082d32016-09-05 12:56:17 +02001557 u32 flags;
Roland Dreiere2773c02005-07-07 17:57:10 -07001558 struct ib_device *device;
1559 struct ib_uobject *uobject;
1560 atomic_t usecnt; /* count all resources */
Christoph Hellwig50d46332016-09-05 12:56:16 +02001561
Christoph Hellwiged082d32016-09-05 12:56:17 +02001562 u32 unsafe_global_rkey;
1563
Christoph Hellwig50d46332016-09-05 12:56:16 +02001564 /*
1565 * Implementation details of the RDMA core, don't use in drivers:
1566 */
1567 struct ib_mr *__internal_mr;
Leon Romanovsky02d88832018-01-28 11:17:20 +02001568 struct rdma_restrack_entry res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569};
1570
Sean Hefty59991f92011-05-23 17:52:46 -07001571struct ib_xrcd {
1572 struct ib_device *device;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001573 atomic_t usecnt; /* count all exposed resources */
Sean Hefty53d0bd12011-05-24 08:33:46 -07001574 struct inode *inode;
Sean Heftyd3d72d92011-05-26 23:06:44 -07001575
1576 struct mutex tgt_qp_mutex;
1577 struct list_head tgt_qp_list;
Sean Hefty59991f92011-05-23 17:52:46 -07001578};
1579
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580struct ib_ah {
1581 struct ib_device *device;
1582 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001583 struct ib_uobject *uobject;
Jason Gunthorpe1a1f4602018-06-13 10:22:08 +03001584 const struct ib_gid_attr *sgid_attr;
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04001585 enum rdma_ah_attr_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586};
1587
1588typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1589
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001590enum ib_poll_context {
Jack Morgensteinf7948092018-08-27 08:35:55 +03001591 IB_POLL_SOFTIRQ, /* poll from softirq context */
1592 IB_POLL_WORKQUEUE, /* poll from workqueue */
1593 IB_POLL_UNBOUND_WORKQUEUE, /* poll from unbound workqueue */
Yamin Friedmanc7ff8192020-05-27 11:34:53 +03001594 IB_POLL_LAST_POOL_TYPE = IB_POLL_UNBOUND_WORKQUEUE,
1595
1596 IB_POLL_DIRECT, /* caller context, no hw completions */
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001597};
1598
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599struct ib_cq {
Roland Dreiere2773c02005-07-07 17:57:10 -07001600 struct ib_device *device;
Jason Gunthorpe5bd48c12020-01-08 19:21:58 +02001601 struct ib_ucq_object *uobject;
Roland Dreiere2773c02005-07-07 17:57:10 -07001602 ib_comp_handler comp_handler;
1603 void (*event_handler)(struct ib_event *, void *);
Dotan Barak4deccd62008-07-14 23:48:44 -07001604 void *cq_context;
Roland Dreiere2773c02005-07-07 17:57:10 -07001605 int cqe;
Yamin Friedmanc7ff8192020-05-27 11:34:53 +03001606 unsigned int cqe_used;
Roland Dreiere2773c02005-07-07 17:57:10 -07001607 atomic_t usecnt; /* count number of work queues */
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001608 enum ib_poll_context poll_ctx;
1609 struct ib_wc *wc;
Yamin Friedmanc7ff8192020-05-27 11:34:53 +03001610 struct list_head pool_entry;
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08001611 union {
1612 struct irq_poll iop;
1613 struct work_struct work;
1614 };
Jack Morgensteinf7948092018-08-27 08:35:55 +03001615 struct workqueue_struct *comp_wq;
Yamin Friedmanda662972019-07-08 13:59:03 +03001616 struct dim *dim;
Chuck Lever3e5901c2019-12-18 15:18:15 -05001617
1618 /* updated only by trace points */
1619 ktime_t timestamp;
Yamin Friedman3446cbd2020-05-27 11:34:52 +03001620 u8 interrupt:1;
1621 u8 shared:1;
Yamin Friedmanc7ff8192020-05-27 11:34:53 +03001622 unsigned int comp_vector;
Chuck Lever3e5901c2019-12-18 15:18:15 -05001623
Leon Romanovsky02d88832018-01-28 11:17:20 +02001624 /*
1625 * Implementation details of the RDMA core, don't use in drivers:
1626 */
1627 struct rdma_restrack_entry res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628};
1629
1630struct ib_srq {
Roland Dreierd41fcc62005-08-18 12:23:08 -07001631 struct ib_device *device;
1632 struct ib_pd *pd;
Jason Gunthorpe9fbe3342020-01-08 19:22:00 +02001633 struct ib_usrq_object *uobject;
Roland Dreierd41fcc62005-08-18 12:23:08 -07001634 void (*event_handler)(struct ib_event *, void *);
1635 void *srq_context;
Sean Hefty96104ed2011-05-23 16:31:36 -07001636 enum ib_srq_type srq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 atomic_t usecnt;
Sean Hefty418d5132011-05-23 19:42:29 -07001638
Artemy Kovalyov1a56ff62017-08-17 15:52:04 +03001639 struct {
1640 struct ib_cq *cq;
1641 union {
1642 struct {
1643 struct ib_xrcd *xrcd;
1644 u32 srq_num;
1645 } xrc;
1646 };
Sean Hefty418d5132011-05-23 19:42:29 -07001647 } ext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648};
1649
Noa Osherovichebaaee22017-01-18 15:39:54 +02001650enum ib_raw_packet_caps {
1651 /* Strip cvlan from incoming packet and report it in the matching work
1652 * completion is supported.
1653 */
1654 IB_RAW_PACKET_CAP_CVLAN_STRIPPING = (1 << 0),
1655 /* Scatter FCS field of an incoming packet to host memory is supported.
1656 */
1657 IB_RAW_PACKET_CAP_SCATTER_FCS = (1 << 1),
1658 /* Checksum offloads are supported (for both send and receive). */
1659 IB_RAW_PACKET_CAP_IP_CSUM = (1 << 2),
Maor Gottlieb7d9336d2017-05-30 10:29:10 +03001660 /* When a packet is received for an RQ with no receive WQEs, the
1661 * packet processing is delayed.
1662 */
1663 IB_RAW_PACKET_CAP_DELAY_DROP = (1 << 3),
Noa Osherovichebaaee22017-01-18 15:39:54 +02001664};
1665
Yishai Hadas5fd251c2016-05-23 15:20:48 +03001666enum ib_wq_type {
Yishai Hadas175ba582020-05-19 10:27:08 +03001667 IB_WQT_RQ = IB_UVERBS_WQT_RQ,
Yishai Hadas5fd251c2016-05-23 15:20:48 +03001668};
1669
1670enum ib_wq_state {
1671 IB_WQS_RESET,
1672 IB_WQS_RDY,
1673 IB_WQS_ERR
1674};
1675
1676struct ib_wq {
1677 struct ib_device *device;
Jason Gunthorpee04dd132020-01-08 19:22:01 +02001678 struct ib_uwq_object *uobject;
Yishai Hadas5fd251c2016-05-23 15:20:48 +03001679 void *wq_context;
1680 void (*event_handler)(struct ib_event *, void *);
1681 struct ib_pd *pd;
1682 struct ib_cq *cq;
1683 u32 wq_num;
1684 enum ib_wq_state state;
1685 enum ib_wq_type wq_type;
1686 atomic_t usecnt;
1687};
1688
Noa Osherovich10bac722017-01-18 15:39:55 +02001689enum ib_wq_flags {
Yishai Hadas175ba582020-05-19 10:27:08 +03001690 IB_WQ_FLAGS_CVLAN_STRIPPING = IB_UVERBS_WQ_FLAGS_CVLAN_STRIPPING,
1691 IB_WQ_FLAGS_SCATTER_FCS = IB_UVERBS_WQ_FLAGS_SCATTER_FCS,
1692 IB_WQ_FLAGS_DELAY_DROP = IB_UVERBS_WQ_FLAGS_DELAY_DROP,
1693 IB_WQ_FLAGS_PCI_WRITE_END_PADDING =
1694 IB_UVERBS_WQ_FLAGS_PCI_WRITE_END_PADDING,
Noa Osherovich10bac722017-01-18 15:39:55 +02001695};
1696
Yishai Hadas5fd251c2016-05-23 15:20:48 +03001697struct ib_wq_init_attr {
1698 void *wq_context;
1699 enum ib_wq_type wq_type;
1700 u32 max_wr;
1701 u32 max_sge;
1702 struct ib_cq *cq;
1703 void (*event_handler)(struct ib_event *, void *);
Noa Osherovich10bac722017-01-18 15:39:55 +02001704 u32 create_flags; /* Use enum ib_wq_flags */
Yishai Hadas5fd251c2016-05-23 15:20:48 +03001705};
1706
1707enum ib_wq_attr_mask {
Noa Osherovich10bac722017-01-18 15:39:55 +02001708 IB_WQ_STATE = 1 << 0,
1709 IB_WQ_CUR_STATE = 1 << 1,
1710 IB_WQ_FLAGS = 1 << 2,
Yishai Hadas5fd251c2016-05-23 15:20:48 +03001711};
1712
1713struct ib_wq_attr {
1714 enum ib_wq_state wq_state;
1715 enum ib_wq_state curr_wq_state;
Noa Osherovich10bac722017-01-18 15:39:55 +02001716 u32 flags; /* Use enum ib_wq_flags */
1717 u32 flags_mask; /* Use enum ib_wq_flags */
Yishai Hadas5fd251c2016-05-23 15:20:48 +03001718};
1719
Yishai Hadas6d397862016-05-23 15:20:51 +03001720struct ib_rwq_ind_table {
1721 struct ib_device *device;
1722 struct ib_uobject *uobject;
1723 atomic_t usecnt;
1724 u32 ind_tbl_num;
1725 u32 log_ind_tbl_size;
1726 struct ib_wq **ind_tbl;
1727};
1728
1729struct ib_rwq_ind_table_init_attr {
1730 u32 log_ind_tbl_size;
1731 /* Each entry is a pointer to Receive Work Queue */
1732 struct ib_wq **ind_tbl;
1733};
1734
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03001735enum port_pkey_state {
1736 IB_PORT_PKEY_NOT_VALID = 0,
1737 IB_PORT_PKEY_VALID = 1,
1738 IB_PORT_PKEY_LISTED = 2,
1739};
1740
1741struct ib_qp_security;
1742
1743struct ib_port_pkey {
1744 enum port_pkey_state state;
1745 u16 pkey_index;
1746 u8 port_num;
1747 struct list_head qp_list;
1748 struct list_head to_error_list;
1749 struct ib_qp_security *sec;
1750};
1751
1752struct ib_ports_pkeys {
1753 struct ib_port_pkey main;
1754 struct ib_port_pkey alt;
1755};
1756
1757struct ib_qp_security {
1758 struct ib_qp *qp;
1759 struct ib_device *dev;
1760 /* Hold this mutex when changing port and pkey settings. */
1761 struct mutex mutex;
1762 struct ib_ports_pkeys *ports_pkeys;
1763 /* A list of all open shared QP handles. Required to enforce security
1764 * properly for all users of a shared QP.
1765 */
1766 struct list_head shared_qp_list;
1767 void *security;
1768 bool destroying;
1769 atomic_t error_list_count;
1770 struct completion error_complete;
1771 int error_comps_pending;
1772};
1773
Bart Van Assche632bc3f2016-07-21 13:03:30 -07001774/*
1775 * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
1776 * @max_read_sge: Maximum SGE elements per RDMA READ request.
1777 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778struct ib_qp {
1779 struct ib_device *device;
1780 struct ib_pd *pd;
1781 struct ib_cq *send_cq;
1782 struct ib_cq *recv_cq;
Christoph Hellwigfffb0382016-05-03 18:01:07 +02001783 spinlock_t mr_lock;
1784 int mrs_used;
Christoph Hellwiga060b562016-05-03 18:01:09 +02001785 struct list_head rdma_mrs;
Christoph Hellwig0e353e32016-05-03 18:01:12 +02001786 struct list_head sig_mrs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 struct ib_srq *srq;
Sean Heftyb42b63c2011-05-23 19:59:25 -07001788 struct ib_xrcd *xrcd; /* XRC TGT QPs only */
Sean Heftyd3d72d92011-05-26 23:06:44 -07001789 struct list_head xrcd_list;
Christoph Hellwigfffb0382016-05-03 18:01:07 +02001790
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001791 /* count times opened, mcast attaches, flow attaches */
1792 atomic_t usecnt;
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07001793 struct list_head open_list;
1794 struct ib_qp *real_qp;
Jason Gunthorpe620d3f82020-01-08 19:21:59 +02001795 struct ib_uqp_object *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 void (*event_handler)(struct ib_event *, void *);
1797 void *qp_context;
Jason Gunthorpe1a1f4602018-06-13 10:22:08 +03001798 /* sgid_attrs associated with the AV's */
1799 const struct ib_gid_attr *av_sgid_attr;
1800 const struct ib_gid_attr *alt_path_sgid_attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 u32 qp_num;
Bart Van Assche632bc3f2016-07-21 13:03:30 -07001802 u32 max_write_sge;
1803 u32 max_read_sge;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 enum ib_qp_type qp_type;
Yishai Hadasa9017e22016-05-23 15:20:54 +03001805 struct ib_rwq_ind_table *rwq_ind_tbl;
Daniel Jurgensd291f1a2017-05-19 15:48:52 +03001806 struct ib_qp_security *qp_sec;
Noa Osherovich498ca3c2017-08-23 08:35:40 +03001807 u8 port;
Leon Romanovsky02d88832018-01-28 11:17:20 +02001808
Max Gurtovoy185eddc2019-06-11 18:52:51 +03001809 bool integrity_en;
Leon Romanovsky02d88832018-01-28 11:17:20 +02001810 /*
1811 * Implementation details of the RDMA core, don't use in drivers:
1812 */
1813 struct rdma_restrack_entry res;
Mark Zhang99fa3312019-07-02 13:02:35 +03001814
1815 /* The counter the qp is bind to */
1816 struct rdma_counter *counter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817};
1818
Ariel Levkovichbee76d72018-04-05 18:53:24 +03001819struct ib_dm {
1820 struct ib_device *device;
1821 u32 length;
1822 u32 flags;
1823 struct ib_uobject *uobject;
1824 atomic_t usecnt;
1825};
1826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827struct ib_mr {
Roland Dreiere2773c02005-07-07 17:57:10 -07001828 struct ib_device *device;
1829 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001830 u32 lkey;
1831 u32 rkey;
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03001832 u64 iova;
Parav Panditedd31552017-09-24 21:46:31 +03001833 u64 length;
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03001834 unsigned int page_size;
Max Gurtovoya0bc0992019-06-11 18:52:38 +03001835 enum ib_mr_type type;
Steve Wised4a85c32016-05-03 18:01:08 +02001836 bool need_inval;
Christoph Hellwigfffb0382016-05-03 18:01:07 +02001837 union {
1838 struct ib_uobject *uobject; /* user */
1839 struct list_head qp_entry; /* FR */
1840 };
Steve Wisefccec5b2018-03-01 13:58:13 -08001841
Ariel Levkovichbe934cc2018-04-05 18:53:25 +03001842 struct ib_dm *dm;
Max Gurtovoy7c717d32019-06-11 18:52:41 +03001843 struct ib_sig_attrs *sig_attrs; /* only for IB_MR_TYPE_INTEGRITY MRs */
Steve Wisefccec5b2018-03-01 13:58:13 -08001844 /*
1845 * Implementation details of the RDMA core, don't use in drivers:
1846 */
1847 struct rdma_restrack_entry res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848};
1849
1850struct ib_mw {
1851 struct ib_device *device;
1852 struct ib_pd *pd;
Roland Dreiere2773c02005-07-07 17:57:10 -07001853 struct ib_uobject *uobject;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 u32 rkey;
Shani Michaeli7083e422013-02-06 16:19:12 +00001855 enum ib_mw_type type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856};
1857
1858struct ib_fmr {
1859 struct ib_device *device;
1860 struct ib_pd *pd;
1861 struct list_head list;
1862 u32 lkey;
1863 u32 rkey;
1864};
1865
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001866/* Supported steering options */
1867enum ib_flow_attr_type {
1868 /* steering according to rule specifications */
1869 IB_FLOW_ATTR_NORMAL = 0x0,
1870 /* default unicast and multicast rule -
1871 * receive all Eth traffic which isn't steered to any QP
1872 */
1873 IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1874 /* default multicast rule -
1875 * receive all Eth multicast traffic which isn't steered to any QP
1876 */
1877 IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1878 /* sniffer rule - receive all port traffic */
1879 IB_FLOW_ATTR_SNIFFER = 0x3
1880};
1881
1882/* Supported steering header types */
1883enum ib_flow_spec_type {
1884 /* L2 headers*/
Moses Reuben76bd23b2016-11-14 19:04:48 +02001885 IB_FLOW_SPEC_ETH = 0x20,
1886 IB_FLOW_SPEC_IB = 0x22,
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001887 /* L3 header*/
Moses Reuben76bd23b2016-11-14 19:04:48 +02001888 IB_FLOW_SPEC_IPV4 = 0x30,
1889 IB_FLOW_SPEC_IPV6 = 0x31,
Matan Barak56ab0b32018-03-28 09:27:49 +03001890 IB_FLOW_SPEC_ESP = 0x34,
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001891 /* L4 headers*/
Moses Reuben76bd23b2016-11-14 19:04:48 +02001892 IB_FLOW_SPEC_TCP = 0x40,
1893 IB_FLOW_SPEC_UDP = 0x41,
Moses Reuben0dbf3332016-11-14 19:04:47 +02001894 IB_FLOW_SPEC_VXLAN_TUNNEL = 0x50,
Ariel Levkovichd90e5e52018-05-13 14:33:30 +03001895 IB_FLOW_SPEC_GRE = 0x51,
Ariel Levkovichb04f0f02018-05-13 14:33:32 +03001896 IB_FLOW_SPEC_MPLS = 0x60,
Moses Reubenfbf46862016-11-14 19:04:51 +02001897 IB_FLOW_SPEC_INNER = 0x100,
Moses Reuben460d0192017-01-18 14:59:48 +02001898 /* Actions */
1899 IB_FLOW_SPEC_ACTION_TAG = 0x1000,
Slava Shwartsman483a3962017-04-03 13:13:51 +03001900 IB_FLOW_SPEC_ACTION_DROP = 0x1001,
Matan Barak9b828442018-03-28 09:27:46 +03001901 IB_FLOW_SPEC_ACTION_HANDLE = 0x1002,
Raed Salem7eea23a2018-05-31 16:43:36 +03001902 IB_FLOW_SPEC_ACTION_COUNT = 0x1003,
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001903};
Matan Barak240ae002013-11-07 15:25:13 +02001904#define IB_FLOW_SPEC_LAYER_MASK 0xF0
Raed Salem7eea23a2018-05-31 16:43:36 +03001905#define IB_FLOW_SPEC_SUPPORT_LAYERS 10
Matan Barak22878db2013-09-01 18:39:52 +03001906
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001907/* Flow steering rule priority is set according to it's domain.
1908 * Lower domain value means higher priority.
1909 */
1910enum ib_flow_domain {
1911 IB_FLOW_DOMAIN_USER,
1912 IB_FLOW_DOMAIN_ETHTOOL,
1913 IB_FLOW_DOMAIN_RFS,
1914 IB_FLOW_DOMAIN_NIC,
1915 IB_FLOW_DOMAIN_NUM /* Must be last */
1916};
1917
Marina Varshavera3100a72016-02-18 18:31:05 +02001918enum ib_flow_flags {
1919 IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
Boris Pismenny21e82d32018-03-28 09:27:47 +03001920 IB_FLOW_ATTR_FLAGS_EGRESS = 1UL << 2, /* Egress flow */
1921 IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 3 /* Must be last */
Marina Varshavera3100a72016-02-18 18:31:05 +02001922};
1923
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001924struct ib_flow_eth_filter {
1925 u8 dst_mac[6];
1926 u8 src_mac[6];
1927 __be16 ether_type;
1928 __be16 vlan_tag;
Maor Gottlieb15dfbd62016-08-30 16:58:32 +03001929 /* Must be last */
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06001930 u8 real_sz[];
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001931};
1932
1933struct ib_flow_spec_eth {
Moses Reubenfbf46862016-11-14 19:04:51 +02001934 u32 type;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001935 u16 size;
1936 struct ib_flow_eth_filter val;
1937 struct ib_flow_eth_filter mask;
1938};
1939
Matan Barak240ae002013-11-07 15:25:13 +02001940struct ib_flow_ib_filter {
1941 __be16 dlid;
1942 __u8 sl;
Maor Gottlieb15dfbd62016-08-30 16:58:32 +03001943 /* Must be last */
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06001944 u8 real_sz[];
Matan Barak240ae002013-11-07 15:25:13 +02001945};
1946
1947struct ib_flow_spec_ib {
Moses Reubenfbf46862016-11-14 19:04:51 +02001948 u32 type;
Matan Barak240ae002013-11-07 15:25:13 +02001949 u16 size;
1950 struct ib_flow_ib_filter val;
1951 struct ib_flow_ib_filter mask;
1952};
1953
Maor Gottlieb989a3a82016-08-30 16:58:33 +03001954/* IPv4 header flags */
1955enum ib_ipv4_flags {
1956 IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */
1957 IB_IPV4_MORE_FRAG = 0X4 /* For All fragmented packets except the
1958 last have this flag set */
1959};
1960
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001961struct ib_flow_ipv4_filter {
1962 __be32 src_ip;
1963 __be32 dst_ip;
Maor Gottlieb989a3a82016-08-30 16:58:33 +03001964 u8 proto;
1965 u8 tos;
1966 u8 ttl;
1967 u8 flags;
Maor Gottlieb15dfbd62016-08-30 16:58:32 +03001968 /* Must be last */
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06001969 u8 real_sz[];
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001970};
1971
1972struct ib_flow_spec_ipv4 {
Moses Reubenfbf46862016-11-14 19:04:51 +02001973 u32 type;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001974 u16 size;
1975 struct ib_flow_ipv4_filter val;
1976 struct ib_flow_ipv4_filter mask;
1977};
1978
Maor Gottlieb4c2aae72016-06-17 15:14:50 +03001979struct ib_flow_ipv6_filter {
1980 u8 src_ip[16];
1981 u8 dst_ip[16];
Maor Gottlieba72c6a22016-08-30 16:58:34 +03001982 __be32 flow_label;
1983 u8 next_hdr;
1984 u8 traffic_class;
1985 u8 hop_limit;
Maor Gottlieb15dfbd62016-08-30 16:58:32 +03001986 /* Must be last */
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06001987 u8 real_sz[];
Maor Gottlieb4c2aae72016-06-17 15:14:50 +03001988};
1989
1990struct ib_flow_spec_ipv6 {
Moses Reubenfbf46862016-11-14 19:04:51 +02001991 u32 type;
Maor Gottlieb4c2aae72016-06-17 15:14:50 +03001992 u16 size;
1993 struct ib_flow_ipv6_filter val;
1994 struct ib_flow_ipv6_filter mask;
1995};
1996
Hadar Hen Zion319a4412013-08-07 14:01:59 +03001997struct ib_flow_tcp_udp_filter {
1998 __be16 dst_port;
1999 __be16 src_port;
Maor Gottlieb15dfbd62016-08-30 16:58:32 +03002000 /* Must be last */
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06002001 u8 real_sz[];
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002002};
2003
2004struct ib_flow_spec_tcp_udp {
Moses Reubenfbf46862016-11-14 19:04:51 +02002005 u32 type;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002006 u16 size;
2007 struct ib_flow_tcp_udp_filter val;
2008 struct ib_flow_tcp_udp_filter mask;
2009};
2010
Moses Reuben0dbf3332016-11-14 19:04:47 +02002011struct ib_flow_tunnel_filter {
2012 __be32 tunnel_id;
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06002013 u8 real_sz[];
Moses Reuben0dbf3332016-11-14 19:04:47 +02002014};
2015
2016/* ib_flow_spec_tunnel describes the Vxlan tunnel
2017 * the tunnel_id from val has the vni value
2018 */
2019struct ib_flow_spec_tunnel {
Moses Reubenfbf46862016-11-14 19:04:51 +02002020 u32 type;
Moses Reuben0dbf3332016-11-14 19:04:47 +02002021 u16 size;
2022 struct ib_flow_tunnel_filter val;
2023 struct ib_flow_tunnel_filter mask;
2024};
2025
Matan Barak56ab0b32018-03-28 09:27:49 +03002026struct ib_flow_esp_filter {
2027 __be32 spi;
2028 __be32 seq;
2029 /* Must be last */
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06002030 u8 real_sz[];
Matan Barak56ab0b32018-03-28 09:27:49 +03002031};
2032
2033struct ib_flow_spec_esp {
2034 u32 type;
2035 u16 size;
2036 struct ib_flow_esp_filter val;
2037 struct ib_flow_esp_filter mask;
2038};
2039
Ariel Levkovichd90e5e52018-05-13 14:33:30 +03002040struct ib_flow_gre_filter {
2041 __be16 c_ks_res0_ver;
2042 __be16 protocol;
2043 __be32 key;
2044 /* Must be last */
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06002045 u8 real_sz[];
Ariel Levkovichd90e5e52018-05-13 14:33:30 +03002046};
2047
2048struct ib_flow_spec_gre {
2049 u32 type;
2050 u16 size;
2051 struct ib_flow_gre_filter val;
2052 struct ib_flow_gre_filter mask;
2053};
2054
Ariel Levkovichb04f0f02018-05-13 14:33:32 +03002055struct ib_flow_mpls_filter {
2056 __be32 tag;
2057 /* Must be last */
Gustavo A. R. Silva5b361322020-02-12 19:04:25 -06002058 u8 real_sz[];
Ariel Levkovichb04f0f02018-05-13 14:33:32 +03002059};
2060
2061struct ib_flow_spec_mpls {
2062 u32 type;
2063 u16 size;
2064 struct ib_flow_mpls_filter val;
2065 struct ib_flow_mpls_filter mask;
2066};
2067
Moses Reuben460d0192017-01-18 14:59:48 +02002068struct ib_flow_spec_action_tag {
2069 enum ib_flow_spec_type type;
2070 u16 size;
2071 u32 tag_id;
2072};
2073
Slava Shwartsman483a3962017-04-03 13:13:51 +03002074struct ib_flow_spec_action_drop {
2075 enum ib_flow_spec_type type;
2076 u16 size;
2077};
2078
Matan Barak9b828442018-03-28 09:27:46 +03002079struct ib_flow_spec_action_handle {
2080 enum ib_flow_spec_type type;
2081 u16 size;
2082 struct ib_flow_action *act;
2083};
2084
Raed Salem7eea23a2018-05-31 16:43:36 +03002085enum ib_counters_description {
2086 IB_COUNTER_PACKETS,
2087 IB_COUNTER_BYTES,
2088};
2089
2090struct ib_flow_spec_action_count {
2091 enum ib_flow_spec_type type;
2092 u16 size;
2093 struct ib_counters *counters;
2094};
2095
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002096union ib_flow_spec {
2097 struct {
Moses Reubenfbf46862016-11-14 19:04:51 +02002098 u32 type;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002099 u16 size;
2100 };
2101 struct ib_flow_spec_eth eth;
Matan Barak240ae002013-11-07 15:25:13 +02002102 struct ib_flow_spec_ib ib;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002103 struct ib_flow_spec_ipv4 ipv4;
2104 struct ib_flow_spec_tcp_udp tcp_udp;
Maor Gottlieb4c2aae72016-06-17 15:14:50 +03002105 struct ib_flow_spec_ipv6 ipv6;
Moses Reuben0dbf3332016-11-14 19:04:47 +02002106 struct ib_flow_spec_tunnel tunnel;
Matan Barak56ab0b32018-03-28 09:27:49 +03002107 struct ib_flow_spec_esp esp;
Ariel Levkovichd90e5e52018-05-13 14:33:30 +03002108 struct ib_flow_spec_gre gre;
Ariel Levkovichb04f0f02018-05-13 14:33:32 +03002109 struct ib_flow_spec_mpls mpls;
Moses Reuben460d0192017-01-18 14:59:48 +02002110 struct ib_flow_spec_action_tag flow_tag;
Slava Shwartsman483a3962017-04-03 13:13:51 +03002111 struct ib_flow_spec_action_drop drop;
Matan Barak9b828442018-03-28 09:27:46 +03002112 struct ib_flow_spec_action_handle action;
Raed Salem7eea23a2018-05-31 16:43:36 +03002113 struct ib_flow_spec_action_count flow_count;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002114};
2115
2116struct ib_flow_attr {
2117 enum ib_flow_attr_type type;
2118 u16 size;
2119 u16 priority;
2120 u32 flags;
2121 u8 num_of_specs;
2122 u8 port;
Matthew Wilcox7654cb12018-06-07 07:57:16 -07002123 union ib_flow_spec flows[];
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002124};
2125
2126struct ib_flow {
2127 struct ib_qp *qp;
Yishai Hadas6cd080a2018-07-23 15:25:08 +03002128 struct ib_device *device;
Hadar Hen Zion319a4412013-08-07 14:01:59 +03002129 struct ib_uobject *uobject;
2130};
2131
Matan Barak2eb9bea2018-03-28 09:27:45 +03002132enum ib_flow_action_type {
2133 IB_FLOW_ACTION_UNSPECIFIED,
2134 IB_FLOW_ACTION_ESP = 1,
2135};
2136
2137struct ib_flow_action_attrs_esp_keymats {
2138 enum ib_uverbs_flow_action_esp_keymat protocol;
2139 union {
2140 struct ib_uverbs_flow_action_esp_keymat_aes_gcm aes_gcm;
2141 } keymat;
2142};
2143
2144struct ib_flow_action_attrs_esp_replays {
2145 enum ib_uverbs_flow_action_esp_replay protocol;
2146 union {
2147 struct ib_uverbs_flow_action_esp_replay_bmp bmp;
2148 } replay;
2149};
2150
2151enum ib_flow_action_attrs_esp_flags {
2152 /* All user-space flags at the top: Use enum ib_uverbs_flow_action_esp_flags
2153 * This is done in order to share the same flags between user-space and
2154 * kernel and spare an unnecessary translation.
2155 */
2156
2157 /* Kernel flags */
2158 IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED = 1ULL << 32,
Matan Barak7d12f8d2018-03-28 09:27:48 +03002159 IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS = 1ULL << 33,
Matan Barak2eb9bea2018-03-28 09:27:45 +03002160};
2161
2162struct ib_flow_spec_list {
2163 struct ib_flow_spec_list *next;
2164 union ib_flow_spec spec;
2165};
2166
2167struct ib_flow_action_attrs_esp {
2168 struct ib_flow_action_attrs_esp_keymats *keymat;
2169 struct ib_flow_action_attrs_esp_replays *replay;
2170 struct ib_flow_spec_list *encap;
2171 /* Used only if IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED is enabled.
2172 * Value of 0 is a valid value.
2173 */
2174 u32 esn;
2175 u32 spi;
2176 u32 seq;
2177 u32 tfc_pad;
2178 /* Use enum ib_flow_action_attrs_esp_flags */
2179 u64 flags;
2180 u64 hard_limit_pkts;
2181};
2182
2183struct ib_flow_action {
2184 struct ib_device *device;
2185 struct ib_uobject *uobject;
2186 enum ib_flow_action_type type;
2187 atomic_t usecnt;
2188};
2189
Leon Romanovskye26e7b82019-10-29 08:27:45 +02002190struct ib_mad;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191struct ib_grh;
2192
2193enum ib_process_mad_flags {
2194 IB_MAD_IGNORE_MKEY = 1,
2195 IB_MAD_IGNORE_BKEY = 2,
2196 IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
2197};
2198
2199enum ib_mad_result {
2200 IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
2201 IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
2202 IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
2203 IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
2204};
2205
Jack Wang21d64542017-01-17 10:11:12 +01002206struct ib_port_cache {
Daniel Jurgens883c71f2017-05-19 15:48:51 +03002207 u64 subnet_prefix;
Jack Wang21d64542017-01-17 10:11:12 +01002208 struct ib_pkey_cache *pkey;
2209 struct ib_gid_table *gid;
2210 u8 lmc;
2211 enum ib_port_state port_state;
2212};
2213
Ira Weiny77386132015-05-13 20:02:58 -04002214struct ib_port_immutable {
2215 int pkey_tbl_len;
2216 int gid_tbl_len;
Ira Weinyf9b22e32015-05-13 20:02:59 -04002217 u32 core_cap_flags;
Ira Weiny337877a2015-06-06 14:38:29 -04002218 u32 max_mad_size;
Ira Weiny77386132015-05-13 20:02:58 -04002219};
2220
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07002221struct ib_port_data {
Jason Gunthorpe324e2272019-02-12 21:12:51 -07002222 struct ib_device *ib_dev;
2223
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07002224 struct ib_port_immutable immutable;
2225
2226 spinlock_t pkey_list_lock;
2227 struct list_head pkey_list;
Jason Gunthorpe8faea9f2019-02-12 21:12:49 -07002228
2229 struct ib_port_cache cache;
Jason Gunthorpec2261dd2019-02-12 21:12:50 -07002230
2231 spinlock_t netdev_lock;
Jason Gunthorpe324e2272019-02-12 21:12:51 -07002232 struct net_device __rcu *netdev;
2233 struct hlist_node ndev_hash_link;
Mark Zhang413d3342019-07-02 13:02:34 +03002234 struct rdma_port_counter port_counter;
Mark Zhang6e7be472019-07-02 13:02:46 +03002235 struct rdma_hw_stats *hw_stats;
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07002236};
2237
Vishwanathapura, Niranjana2fc77572017-04-12 20:29:20 -07002238/* rdma netdev type - specifies protocol type */
2239enum rdma_netdev_t {
Niranjana Vishwanathapuraf0ad83ac2017-04-10 11:22:25 +03002240 RDMA_NETDEV_OPA_VNIC,
2241 RDMA_NETDEV_IPOIB,
Vishwanathapura, Niranjana2fc77572017-04-12 20:29:20 -07002242};
2243
2244/**
2245 * struct rdma_netdev - rdma netdev
2246 * For cases where netstack interfacing is required.
2247 */
2248struct rdma_netdev {
2249 void *clnt_priv;
2250 struct ib_device *hca;
2251 u8 port_num;
Gary Leshnerd99dc602020-05-11 12:05:48 -04002252 int mtu;
Vishwanathapura, Niranjana2fc77572017-04-12 20:29:20 -07002253
Jason Gunthorpe9f49a5b2018-07-29 11:34:56 +03002254 /*
2255 * cleanup function must be specified.
2256 * FIXME: This is only used for OPA_VNIC and that usage should be
2257 * removed too.
2258 */
Niranjana Vishwanathapura8e959602017-06-30 13:14:46 -07002259 void (*free_rdma_netdev)(struct net_device *netdev);
2260
Vishwanathapura, Niranjana2fc77572017-04-12 20:29:20 -07002261 /* control functions */
2262 void (*set_id)(struct net_device *netdev, int id);
Niranjana Vishwanathapuraf0ad83ac2017-04-10 11:22:25 +03002263 /* send packet */
2264 int (*send)(struct net_device *dev, struct sk_buff *skb,
2265 struct ib_ah *address, u32 dqpn);
2266 /* multicast */
2267 int (*attach_mcast)(struct net_device *dev, struct ib_device *hca,
2268 union ib_gid *gid, u16 mlid,
2269 int set_qkey, u32 qkey);
2270 int (*detach_mcast)(struct net_device *dev, struct ib_device *hca,
2271 union ib_gid *gid, u16 mlid);
Vishwanathapura, Niranjana2fc77572017-04-12 20:29:20 -07002272};
2273
Denis Drozdovf6a8a192018-08-14 14:08:51 +03002274struct rdma_netdev_alloc_params {
2275 size_t sizeof_priv;
2276 unsigned int txqs;
2277 unsigned int rxqs;
2278 void *param;
2279
2280 int (*initialize_rdma_netdev)(struct ib_device *device, u8 port_num,
2281 struct net_device *netdev, void *param);
2282};
2283
Erez Alfasia3de94e2019-10-16 09:23:05 +03002284struct ib_odp_counters {
2285 atomic64_t faults;
2286 atomic64_t invalidations;
2287};
2288
Raed Salemfa9b1802018-05-31 16:43:31 +03002289struct ib_counters {
2290 struct ib_device *device;
2291 struct ib_uobject *uobject;
2292 /* num of objects attached */
2293 atomic_t usecnt;
2294};
2295
Raed Salem51d7a532018-05-31 16:43:33 +03002296struct ib_counters_read_attr {
2297 u64 *counters_buff;
2298 u32 ncounters;
2299 u32 flags; /* use enum ib_read_counters_flags */
2300};
2301
Matan Barak2eb9bea2018-03-28 09:27:45 +03002302struct uverbs_attr_bundle;
Kamal Heibdd05cb82019-04-29 14:59:06 +03002303struct iw_cm_id;
2304struct iw_cm_conn_param;
Matan Barak2eb9bea2018-03-28 09:27:45 +03002305
Leon Romanovsky30471d42019-02-03 14:55:50 +02002306#define INIT_RDMA_OBJ_SIZE(ib_struct, drv_struct, member) \
2307 .size_##ib_struct = \
2308 (sizeof(struct drv_struct) + \
2309 BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) + \
2310 BUILD_BUG_ON_ZERO( \
2311 !__same_type(((struct drv_struct *)NULL)->member, \
2312 struct ib_struct)))
2313
Leon Romanovskyf6316032019-03-28 15:12:58 +02002314#define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp) \
2315 ((struct ib_type *)kzalloc(ib_dev->ops.size_##ib_type, gfp))
2316
Leon Romanovsky30471d42019-02-03 14:55:50 +02002317#define rdma_zalloc_drv_obj(ib_dev, ib_type) \
Leon Romanovskyf6316032019-03-28 15:12:58 +02002318 rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, GFP_KERNEL)
Leon Romanovsky30471d42019-02-03 14:55:50 +02002319
2320#define DECLARE_RDMA_OBJ_SIZE(ib_struct) size_t size_##ib_struct
2321
Michal Kalderon3411f9f2019-10-30 11:44:11 +02002322struct rdma_user_mmap_entry {
2323 struct kref ref;
2324 struct ib_ucontext *ucontext;
2325 unsigned long start_pgoff;
2326 size_t npages;
2327 bool driver_removed;
2328};
2329
2330/* Return the offset (in bytes) the user should pass to libc's mmap() */
2331static inline u64
2332rdma_user_mmap_get_offset(const struct rdma_user_mmap_entry *entry)
2333{
2334 return (u64)entry->start_pgoff << PAGE_SHIFT;
2335}
2336
Kamal Heib521ed0d2018-12-10 21:09:30 +02002337/**
2338 * struct ib_device_ops - InfiniBand device operations
2339 * This structure defines all the InfiniBand device operations, providers will
2340 * need to define the supported operations, otherwise they will be set to null.
2341 */
2342struct ib_device_ops {
Jason Gunthorpe7a154142019-06-05 14:39:26 -03002343 struct module *owner;
Jason Gunthorpeb9560a42019-06-05 14:39:24 -03002344 enum rdma_driver_id driver_id;
Jason Gunthorpe72c6ec12019-06-05 14:39:25 -03002345 u32 uverbs_abi_ver;
Jason Gunthorpe8f71bb02019-06-13 21:38:19 -03002346 unsigned int uverbs_no_driver_id_binding:1;
Jason Gunthorpeb9560a42019-06-05 14:39:24 -03002347
Kamal Heib521ed0d2018-12-10 21:09:30 +02002348 int (*post_send)(struct ib_qp *qp, const struct ib_send_wr *send_wr,
2349 const struct ib_send_wr **bad_send_wr);
2350 int (*post_recv)(struct ib_qp *qp, const struct ib_recv_wr *recv_wr,
2351 const struct ib_recv_wr **bad_recv_wr);
2352 void (*drain_rq)(struct ib_qp *qp);
2353 void (*drain_sq)(struct ib_qp *qp);
2354 int (*poll_cq)(struct ib_cq *cq, int num_entries, struct ib_wc *wc);
2355 int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
2356 int (*req_notify_cq)(struct ib_cq *cq, enum ib_cq_notify_flags flags);
2357 int (*req_ncomp_notif)(struct ib_cq *cq, int wc_cnt);
2358 int (*post_srq_recv)(struct ib_srq *srq,
2359 const struct ib_recv_wr *recv_wr,
2360 const struct ib_recv_wr **bad_recv_wr);
2361 int (*process_mad)(struct ib_device *device, int process_mad_flags,
2362 u8 port_num, const struct ib_wc *in_wc,
2363 const struct ib_grh *in_grh,
Leon Romanovskye26e7b82019-10-29 08:27:45 +02002364 const struct ib_mad *in_mad, struct ib_mad *out_mad,
2365 size_t *out_mad_size, u16 *out_mad_pkey_index);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002366 int (*query_device)(struct ib_device *device,
2367 struct ib_device_attr *device_attr,
2368 struct ib_udata *udata);
2369 int (*modify_device)(struct ib_device *device, int device_modify_mask,
2370 struct ib_device_modify *device_modify);
2371 void (*get_dev_fw_str)(struct ib_device *device, char *str);
2372 const struct cpumask *(*get_vector_affinity)(struct ib_device *ibdev,
2373 int comp_vector);
2374 int (*query_port)(struct ib_device *device, u8 port_num,
2375 struct ib_port_attr *port_attr);
2376 int (*modify_port)(struct ib_device *device, u8 port_num,
2377 int port_modify_mask,
2378 struct ib_port_modify *port_modify);
2379 /**
2380 * The following mandatory functions are used only at device
2381 * registration. Keep functions such as these at the end of this
2382 * structure to avoid cache line misses when accessing struct ib_device
2383 * in fast paths.
2384 */
2385 int (*get_port_immutable)(struct ib_device *device, u8 port_num,
2386 struct ib_port_immutable *immutable);
2387 enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
2388 u8 port_num);
2389 /**
2390 * When calling get_netdev, the HW vendor's driver should return the
2391 * net device of device @device at port @port_num or NULL if such
2392 * a net device doesn't exist. The vendor driver should call dev_hold
2393 * on this net device. The HW vendor's device driver must guarantee
2394 * that this function returns NULL before the net device has finished
2395 * NETDEV_UNREGISTER state.
2396 */
2397 struct net_device *(*get_netdev)(struct ib_device *device, u8 port_num);
2398 /**
2399 * rdma netdev operation
2400 *
2401 * Driver implementing alloc_rdma_netdev or rdma_netdev_get_params
2402 * must return -EOPNOTSUPP if it doesn't support the specified type.
2403 */
2404 struct net_device *(*alloc_rdma_netdev)(
2405 struct ib_device *device, u8 port_num, enum rdma_netdev_t type,
2406 const char *name, unsigned char name_assign_type,
2407 void (*setup)(struct net_device *));
2408
2409 int (*rdma_netdev_get_params)(struct ib_device *device, u8 port_num,
2410 enum rdma_netdev_t type,
2411 struct rdma_netdev_alloc_params *params);
2412 /**
2413 * query_gid should be return GID value for @device, when @port_num
2414 * link layer is either IB or iWarp. It is no-op if @port_num port
2415 * is RoCE link layer.
2416 */
2417 int (*query_gid)(struct ib_device *device, u8 port_num, int index,
2418 union ib_gid *gid);
2419 /**
2420 * When calling add_gid, the HW vendor's driver should add the gid
2421 * of device of port at gid index available at @attr. Meta-info of
2422 * that gid (for example, the network device related to this gid) is
2423 * available at @attr. @context allows the HW vendor driver to store
2424 * extra information together with a GID entry. The HW vendor driver may
2425 * allocate memory to contain this information and store it in @context
2426 * when a new GID entry is written to. Params are consistent until the
2427 * next call of add_gid or delete_gid. The function should return 0 on
2428 * success or error otherwise. The function could be called
2429 * concurrently for different ports. This function is only called when
2430 * roce_gid_table is used.
2431 */
2432 int (*add_gid)(const struct ib_gid_attr *attr, void **context);
2433 /**
2434 * When calling del_gid, the HW vendor's driver should delete the
2435 * gid of device @device at gid index gid_index of port port_num
2436 * available in @attr.
2437 * Upon the deletion of a GID entry, the HW vendor must free any
2438 * allocated memory. The caller will clear @context afterwards.
2439 * This function is only called when roce_gid_table is used.
2440 */
2441 int (*del_gid)(const struct ib_gid_attr *attr, void **context);
2442 int (*query_pkey)(struct ib_device *device, u8 port_num, u16 index,
2443 u16 *pkey);
Leon Romanovskya2a074e2019-02-12 20:39:16 +02002444 int (*alloc_ucontext)(struct ib_ucontext *context,
2445 struct ib_udata *udata);
2446 void (*dealloc_ucontext)(struct ib_ucontext *context);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002447 int (*mmap)(struct ib_ucontext *context, struct vm_area_struct *vma);
Michal Kalderon3411f9f2019-10-30 11:44:11 +02002448 /**
2449 * This will be called once refcount of an entry in mmap_xa reaches
2450 * zero. The type of the memory that was mapped may differ between
2451 * entries and is opaque to the rdma_user_mmap interface.
2452 * Therefore needs to be implemented by the driver in mmap_free.
2453 */
2454 void (*mmap_free)(struct rdma_user_mmap_entry *entry);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002455 void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
Shamir Rabinovitchff23dfa2019-03-31 19:10:07 +03002456 int (*alloc_pd)(struct ib_pd *pd, struct ib_udata *udata);
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03002457 void (*dealloc_pd)(struct ib_pd *pd, struct ib_udata *udata);
Maor Gottliebfa5d0102020-04-30 22:21:42 +03002458 int (*create_ah)(struct ib_ah *ah, struct rdma_ah_init_attr *attr,
2459 struct ib_udata *udata);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002460 int (*modify_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
2461 int (*query_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
Leon Romanovskyd3456912019-04-03 16:42:42 +03002462 void (*destroy_ah)(struct ib_ah *ah, u32 flags);
Leon Romanovsky68e326d2019-04-03 16:42:43 +03002463 int (*create_srq)(struct ib_srq *srq,
2464 struct ib_srq_init_attr *srq_init_attr,
2465 struct ib_udata *udata);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002466 int (*modify_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr,
2467 enum ib_srq_attr_mask srq_attr_mask,
2468 struct ib_udata *udata);
2469 int (*query_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
Leon Romanovsky68e326d2019-04-03 16:42:43 +03002470 void (*destroy_srq)(struct ib_srq *srq, struct ib_udata *udata);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002471 struct ib_qp *(*create_qp)(struct ib_pd *pd,
2472 struct ib_qp_init_attr *qp_init_attr,
2473 struct ib_udata *udata);
2474 int (*modify_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
2475 int qp_attr_mask, struct ib_udata *udata);
2476 int (*query_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
2477 int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr);
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03002478 int (*destroy_qp)(struct ib_qp *qp, struct ib_udata *udata);
Leon Romanovskye39afe32019-05-28 14:37:29 +03002479 int (*create_cq)(struct ib_cq *cq, const struct ib_cq_init_attr *attr,
2480 struct ib_udata *udata);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002481 int (*modify_cq)(struct ib_cq *cq, u16 cq_count, u16 cq_period);
Leon Romanovskya52c8e22019-05-28 14:37:28 +03002482 void (*destroy_cq)(struct ib_cq *cq, struct ib_udata *udata);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002483 int (*resize_cq)(struct ib_cq *cq, int cqe, struct ib_udata *udata);
2484 struct ib_mr *(*get_dma_mr)(struct ib_pd *pd, int mr_access_flags);
2485 struct ib_mr *(*reg_user_mr)(struct ib_pd *pd, u64 start, u64 length,
2486 u64 virt_addr, int mr_access_flags,
2487 struct ib_udata *udata);
2488 int (*rereg_user_mr)(struct ib_mr *mr, int flags, u64 start, u64 length,
2489 u64 virt_addr, int mr_access_flags,
2490 struct ib_pd *pd, struct ib_udata *udata);
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03002491 int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002492 struct ib_mr *(*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type,
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03002493 u32 max_num_sg, struct ib_udata *udata);
Israel Rukshin26bc7ea2019-06-11 18:52:39 +03002494 struct ib_mr *(*alloc_mr_integrity)(struct ib_pd *pd,
2495 u32 max_num_data_sg,
2496 u32 max_num_meta_sg);
Moni Shouaad8a4492018-12-11 13:37:52 +02002497 int (*advise_mr)(struct ib_pd *pd,
2498 enum ib_uverbs_advise_mr_advice advice, u32 flags,
2499 struct ib_sge *sg_list, u32 num_sge,
2500 struct uverbs_attr_bundle *attrs);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002501 int (*map_mr_sg)(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
2502 unsigned int *sg_offset);
2503 int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
2504 struct ib_mr_status *mr_status);
2505 struct ib_mw *(*alloc_mw)(struct ib_pd *pd, enum ib_mw_type type,
2506 struct ib_udata *udata);
2507 int (*dealloc_mw)(struct ib_mw *mw);
2508 struct ib_fmr *(*alloc_fmr)(struct ib_pd *pd, int mr_access_flags,
2509 struct ib_fmr_attr *fmr_attr);
2510 int (*map_phys_fmr)(struct ib_fmr *fmr, u64 *page_list, int list_len,
2511 u64 iova);
2512 int (*unmap_fmr)(struct list_head *fmr_list);
2513 int (*dealloc_fmr)(struct ib_fmr *fmr);
2514 int (*attach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2515 int (*detach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2516 struct ib_xrcd *(*alloc_xrcd)(struct ib_device *device,
Kamal Heib521ed0d2018-12-10 21:09:30 +02002517 struct ib_udata *udata);
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03002518 int (*dealloc_xrcd)(struct ib_xrcd *xrcd, struct ib_udata *udata);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002519 struct ib_flow *(*create_flow)(struct ib_qp *qp,
2520 struct ib_flow_attr *flow_attr,
2521 int domain, struct ib_udata *udata);
2522 int (*destroy_flow)(struct ib_flow *flow_id);
2523 struct ib_flow_action *(*create_flow_action_esp)(
2524 struct ib_device *device,
2525 const struct ib_flow_action_attrs_esp *attr,
2526 struct uverbs_attr_bundle *attrs);
2527 int (*destroy_flow_action)(struct ib_flow_action *action);
2528 int (*modify_flow_action_esp)(
2529 struct ib_flow_action *action,
2530 const struct ib_flow_action_attrs_esp *attr,
2531 struct uverbs_attr_bundle *attrs);
2532 int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
2533 int state);
2534 int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
2535 struct ifla_vf_info *ivf);
2536 int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
2537 struct ifla_vf_stats *stats);
Danit Goldbergbfcb3c5d2019-11-06 15:08:32 +02002538 int (*get_vf_guid)(struct ib_device *device, int vf, u8 port,
2539 struct ifla_vf_guid *node_guid,
2540 struct ifla_vf_guid *port_guid);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002541 int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
2542 int type);
2543 struct ib_wq *(*create_wq)(struct ib_pd *pd,
2544 struct ib_wq_init_attr *init_attr,
2545 struct ib_udata *udata);
Leon Romanovskya49b1dc2019-06-12 15:27:41 +03002546 void (*destroy_wq)(struct ib_wq *wq, struct ib_udata *udata);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002547 int (*modify_wq)(struct ib_wq *wq, struct ib_wq_attr *attr,
2548 u32 wq_attr_mask, struct ib_udata *udata);
2549 struct ib_rwq_ind_table *(*create_rwq_ind_table)(
2550 struct ib_device *device,
2551 struct ib_rwq_ind_table_init_attr *init_attr,
2552 struct ib_udata *udata);
2553 int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
2554 struct ib_dm *(*alloc_dm)(struct ib_device *device,
2555 struct ib_ucontext *context,
2556 struct ib_dm_alloc_attr *attr,
2557 struct uverbs_attr_bundle *attrs);
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03002558 int (*dealloc_dm)(struct ib_dm *dm, struct uverbs_attr_bundle *attrs);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002559 struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm,
2560 struct ib_dm_mr_attr *attr,
2561 struct uverbs_attr_bundle *attrs);
2562 struct ib_counters *(*create_counters)(
2563 struct ib_device *device, struct uverbs_attr_bundle *attrs);
2564 int (*destroy_counters)(struct ib_counters *counters);
2565 int (*read_counters)(struct ib_counters *counters,
2566 struct ib_counters_read_attr *counters_read_attr,
2567 struct uverbs_attr_bundle *attrs);
Max Gurtovoy2cdfcdd2019-06-11 18:52:40 +03002568 int (*map_mr_sg_pi)(struct ib_mr *mr, struct scatterlist *data_sg,
2569 int data_sg_nents, unsigned int *data_sg_offset,
2570 struct scatterlist *meta_sg, int meta_sg_nents,
2571 unsigned int *meta_sg_offset);
2572
Kamal Heib521ed0d2018-12-10 21:09:30 +02002573 /**
2574 * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
2575 * driver initialized data. The struct is kfree()'ed by the sysfs
2576 * core when the device is removed. A lifespan of -1 in the return
2577 * struct tells the core to set a default lifespan.
2578 */
2579 struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
2580 u8 port_num);
2581 /**
2582 * get_hw_stats - Fill in the counter value(s) in the stats struct.
2583 * @index - The index in the value array we wish to have updated, or
2584 * num_counters if we want all stats updated
2585 * Return codes -
2586 * < 0 - Error, no counters updated
2587 * index - Updated the single counter pointed to by index
2588 * num_counters - Updated all counters (will reset the timestamp
2589 * and prevent further calls for lifespan milliseconds)
2590 * Drivers are allowed to update all counters in leiu of just the
2591 * one given in index at their option
2592 */
2593 int (*get_hw_stats)(struct ib_device *device,
2594 struct rdma_hw_stats *stats, u8 port, int index);
Parav Panditea4baf72018-12-18 14:28:30 +02002595 /*
2596 * This function is called once for each port when a ib device is
2597 * registered.
2598 */
2599 int (*init_port)(struct ib_device *device, u8 port_num,
2600 struct kobject *port_sysfs);
Leon Romanovsky02da3752019-01-30 12:49:02 +02002601 /**
2602 * Allows rdma drivers to add their own restrack attributes.
2603 */
2604 int (*fill_res_entry)(struct sk_buff *msg,
2605 struct rdma_restrack_entry *entry);
Leon Romanovsky21a428a2019-02-03 14:55:51 +02002606
Jason Gunthorped0899892019-02-12 21:12:53 -07002607 /* Device lifecycle callbacks */
2608 /*
Jason Gunthorpeca223542019-02-12 21:12:56 -07002609 * Called after the device becomes registered, before clients are
2610 * attached
2611 */
2612 int (*enable_driver)(struct ib_device *dev);
2613 /*
Jason Gunthorped0899892019-02-12 21:12:53 -07002614 * This is called as part of ib_dealloc_device().
2615 */
2616 void (*dealloc_driver)(struct ib_device *dev);
2617
Kamal Heibdd05cb82019-04-29 14:59:06 +03002618 /* iWarp CM callbacks */
2619 void (*iw_add_ref)(struct ib_qp *qp);
2620 void (*iw_rem_ref)(struct ib_qp *qp);
2621 struct ib_qp *(*iw_get_qp)(struct ib_device *device, int qpn);
2622 int (*iw_connect)(struct iw_cm_id *cm_id,
2623 struct iw_cm_conn_param *conn_param);
2624 int (*iw_accept)(struct iw_cm_id *cm_id,
2625 struct iw_cm_conn_param *conn_param);
2626 int (*iw_reject)(struct iw_cm_id *cm_id, const void *pdata,
2627 u8 pdata_len);
2628 int (*iw_create_listen)(struct iw_cm_id *cm_id, int backlog);
2629 int (*iw_destroy_listen)(struct iw_cm_id *cm_id);
Mark Zhang99fa3312019-07-02 13:02:35 +03002630 /**
2631 * counter_bind_qp - Bind a QP to a counter.
2632 * @counter - The counter to be bound. If counter->id is zero then
2633 * the driver needs to allocate a new counter and set counter->id
2634 */
2635 int (*counter_bind_qp)(struct rdma_counter *counter, struct ib_qp *qp);
2636 /**
2637 * counter_unbind_qp - Unbind the qp from the dynamically-allocated
2638 * counter and bind it onto the default one
2639 */
2640 int (*counter_unbind_qp)(struct ib_qp *qp);
2641 /**
2642 * counter_dealloc -De-allocate the hw counter
2643 */
2644 int (*counter_dealloc)(struct rdma_counter *counter);
Mark Zhangc4ffee72019-07-02 13:02:40 +03002645 /**
2646 * counter_alloc_stats - Allocate a struct rdma_hw_stats and fill in
2647 * the driver initialized data.
2648 */
2649 struct rdma_hw_stats *(*counter_alloc_stats)(
2650 struct rdma_counter *counter);
2651 /**
2652 * counter_update_stats - Query the stats value of this counter
2653 */
2654 int (*counter_update_stats)(struct rdma_counter *counter);
Kamal Heibdd05cb82019-04-29 14:59:06 +03002655
Erez Alfasi4061ff72019-10-16 09:23:08 +03002656 /**
2657 * Allows rdma drivers to add their own restrack attributes
2658 * dumped via 'rdma stat' iproute2 command.
2659 */
2660 int (*fill_stat_entry)(struct sk_buff *msg,
2661 struct rdma_restrack_entry *entry);
2662
Leon Romanovskyd3456912019-04-03 16:42:42 +03002663 DECLARE_RDMA_OBJ_SIZE(ib_ah);
Leon Romanovskye39afe32019-05-28 14:37:29 +03002664 DECLARE_RDMA_OBJ_SIZE(ib_cq);
Leon Romanovsky21a428a2019-02-03 14:55:51 +02002665 DECLARE_RDMA_OBJ_SIZE(ib_pd);
Leon Romanovsky68e326d2019-04-03 16:42:43 +03002666 DECLARE_RDMA_OBJ_SIZE(ib_srq);
Leon Romanovskya2a074e2019-02-12 20:39:16 +02002667 DECLARE_RDMA_OBJ_SIZE(ib_ucontext);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002668};
2669
Parav Panditcebe5562019-02-26 13:56:11 +02002670struct ib_core_device {
2671 /* device must be the first element in structure until,
2672 * union of ib_core_device and device exists in ib_device.
2673 */
2674 struct device dev;
Parav Pandit4e0f7b92019-02-26 13:56:13 +02002675 possible_net_t rdma_net;
Parav Panditcebe5562019-02-26 13:56:11 +02002676 struct kobject *ports_kobj;
2677 struct list_head port_list;
2678 struct ib_device *owner; /* reach back to owner ib_device */
2679};
Leon Romanovsky41eda652019-02-18 22:25:47 +02002680
Parav Panditcebe5562019-02-26 13:56:11 +02002681struct rdma_restrack_root;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682struct ib_device {
Bart Van Assche0957c292017-03-07 22:56:53 +00002683 /* Do not access @dma_device directly from ULP nor from HW drivers. */
2684 struct device *dma_device;
Kamal Heib3023a1e2018-12-10 21:09:48 +02002685 struct ib_device_ops ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 char name[IB_DEVICE_NAME_MAX];
Jason Gunthorpe324e2272019-02-12 21:12:51 -07002687 struct rcu_head rcu_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
2689 struct list_head event_handler_list;
Parav Pandit6b57cea2019-12-12 13:30:22 +02002690 /* Protects event_handler_list */
2691 struct rw_semaphore event_handler_rwsem;
2692
2693 /* Protects QP's event_handler calls and open_qp list */
Parav Pandit40adf682019-12-12 13:30:24 +02002694 spinlock_t qp_open_list_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
Jason Gunthorpe921eab12019-02-06 22:41:54 -07002696 struct rw_semaphore client_data_rwsem;
Jason Gunthorpe0df91bb2019-02-06 22:41:53 -07002697 struct xarray client_data;
Jason Gunthorped0899892019-02-12 21:12:53 -07002698 struct mutex unregistration_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699
Parav Pandit17e10642019-12-12 13:30:23 +02002700 /* Synchronize GID, Pkey cache entries, subnet prefix, LMC */
2701 rwlock_t cache_lock;
Ira Weiny77386132015-05-13 20:02:58 -04002702 /**
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07002703 * port_data is indexed by port number
Ira Weiny77386132015-05-13 20:02:58 -04002704 */
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07002705 struct ib_port_data *port_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706
Michael S. Tsirkinf4fd0b22007-05-03 13:48:47 +03002707 int num_comp_vectors;
2708
Parav Panditcebe5562019-02-26 13:56:11 +02002709 union {
2710 struct device dev;
2711 struct ib_core_device coredev;
2712 };
2713
Parav Panditd4122f52018-10-11 22:31:53 +03002714 /* First group for device attributes,
2715 * Second group for driver provided attributes (optional).
2716 * It is NULL terminated array.
2717 */
2718 const struct attribute_group *groups[3];
Parav Panditadee9f32018-09-05 09:47:58 +03002719
Alexander Chiang17a55f72010-02-02 19:09:16 +00002720 u64 uverbs_cmd_mask;
Yann Droneaudf21519b2013-11-06 23:21:49 +01002721 u64 uverbs_ex_cmd_mask;
Roland Dreier274c0892005-09-29 14:17:48 -07002722
Yuval Shaiabd99fde2016-08-25 10:57:07 -07002723 char node_desc[IB_DEVICE_NODE_DESC_MAX];
Sean Heftycf311cd2006-01-10 07:39:34 -08002724 __be64 node_guid;
Steve Wise96f15c02008-07-14 23:48:53 -07002725 u32 local_dma_lkey;
Hal Rosenstock41390322015-06-29 09:57:00 -04002726 u16 is_switch:1;
Gal Pressman6780c4f2019-01-22 10:08:22 +02002727 /* Indicates kernel verbs support, should not be used in drivers */
2728 u16 kverbs_provider:1;
Yamin Friedmanda662972019-07-08 13:59:03 +03002729 /* CQ adaptive moderation (RDMA DIM) */
2730 u16 use_cq_dim:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 u8 node_type;
2732 u8 phys_port_cnt;
Ira Weiny3e153a92015-12-18 10:59:44 +02002733 struct ib_device_attr attrs;
Christoph Lameterb40f4752016-05-16 12:49:33 -05002734 struct attribute_group *hw_stats_ag;
2735 struct rdma_hw_stats *hw_stats;
Ira Weiny77386132015-05-13 20:02:58 -04002736
Parav Pandit43579b52017-01-10 00:02:14 +00002737#ifdef CONFIG_CGROUP_RDMA
2738 struct rdmacg_device cg_device;
2739#endif
2740
Leon Romanovskyecc82c52017-06-18 14:39:59 +03002741 u32 index;
Yamin Friedmanc7ff8192020-05-27 11:34:53 +03002742
2743 spinlock_t cq_pools_lock;
2744 struct list_head cq_pools[IB_POLL_LAST_POOL_TYPE + 1];
2745
Leon Romanovsky41eda652019-02-18 22:25:47 +02002746 struct rdma_restrack_root *res;
Leon Romanovskyecc82c52017-06-18 14:39:59 +03002747
Jason Gunthorpe0cbf4322018-11-12 22:59:50 +02002748 const struct uapi_definition *driver_def;
Jason Gunthorped79af722019-01-10 14:02:24 -07002749
Parav Pandit01b67112018-11-16 03:50:57 +02002750 /*
Jason Gunthorped79af722019-01-10 14:02:24 -07002751 * Positive refcount indicates that the device is currently
2752 * registered and cannot be unregistered.
Parav Pandit01b67112018-11-16 03:50:57 +02002753 */
2754 refcount_t refcount;
2755 struct completion unreg_completion;
Jason Gunthorped0899892019-02-12 21:12:53 -07002756 struct work_struct unregistration_work;
Steve Wise3856ec42019-02-15 11:03:53 -08002757
2758 const struct rdma_link_ops *link_ops;
Parav Pandit4e0f7b92019-02-26 13:56:13 +02002759
2760 /* Protects compat_devs xarray modifications */
2761 struct mutex compat_devs_mutex;
2762 /* Maintains compat devices for each net namespace */
2763 struct xarray compat_devs;
Kamal Heibdd05cb82019-04-29 14:59:06 +03002764
2765 /* Used by iWarp CM */
2766 char iw_ifname[IFNAMSIZ];
2767 u32 iw_driver_flags;
Maor Gottliebbd3920e2020-04-30 22:21:43 +03002768 u32 lag_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769};
2770
Jason Gunthorpe0e2d00e2019-06-13 21:38:18 -03002771struct ib_client_nl_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772struct ib_client {
Jason Gunthorpee59178d2019-02-06 22:41:52 -07002773 const char *name;
Jason Gunthorpe11a0ae42020-04-21 20:24:40 +03002774 int (*add)(struct ib_device *ibdev);
Haggai Eran7c1eb452015-07-30 17:50:14 +03002775 void (*remove)(struct ib_device *, void *client_data);
Leon Romanovskydc1435c2019-05-17 15:43:10 +03002776 void (*rename)(struct ib_device *dev, void *client_data);
Jason Gunthorpe0e2d00e2019-06-13 21:38:18 -03002777 int (*get_nl_info)(struct ib_device *ibdev, void *client_data,
2778 struct ib_client_nl_info *res);
2779 int (*get_global_nl_info)(struct ib_client_nl_info *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780
Yotam Kenneth9268f722015-07-30 17:50:15 +03002781 /* Returns the net_dev belonging to this ib_client and matching the
2782 * given parameters.
2783 * @dev: An RDMA device that the net_dev use for communication.
2784 * @port: A physical port number on the RDMA device.
2785 * @pkey: P_Key that the net_dev uses if applicable.
2786 * @gid: A GID that the net_dev uses to communicate.
2787 * @addr: An IP address the net_dev is configured with.
2788 * @client_data: The device's client data set by ib_set_client_data().
2789 *
2790 * An ib_client that implements a net_dev on top of RDMA devices
2791 * (such as IP over IB) should implement this callback, allowing the
2792 * rdma_cm module to find the right net_dev for a given request.
2793 *
2794 * The caller is responsible for calling dev_put on the returned
2795 * netdev. */
2796 struct net_device *(*get_net_dev_by_params)(
2797 struct ib_device *dev,
2798 u8 port,
2799 u16 pkey,
2800 const union ib_gid *gid,
2801 const struct sockaddr *addr,
2802 void *client_data);
Jason Gunthorpe621e55f2019-07-31 11:18:40 +03002803
2804 refcount_t uses;
2805 struct completion uses_zero;
Jason Gunthorpee59178d2019-02-06 22:41:52 -07002806 u32 client_id;
Gal Pressman6780c4f2019-01-22 10:08:22 +02002807
2808 /* kverbs are not required by the client */
2809 u8 no_kverbs_req:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810};
2811
Shiraz Saleema8082732019-05-06 08:53:33 -05002812/*
2813 * IB block DMA iterator
2814 *
2815 * Iterates the DMA-mapped SGL in contiguous memory blocks aligned
2816 * to a HW supported page size.
2817 */
2818struct ib_block_iter {
2819 /* internal states */
2820 struct scatterlist *__sg; /* sg holding the current aligned block */
2821 dma_addr_t __dma_addr; /* unaligned DMA address of this block */
2822 unsigned int __sg_nents; /* number of SG entries */
2823 unsigned int __sg_advance; /* number of bytes to advance in sg in next step */
2824 unsigned int __pg_bit; /* alignment of current block */
2825};
2826
Leon Romanovsky459cc692019-01-30 12:49:11 +02002827struct ib_device *_ib_alloc_device(size_t size);
2828#define ib_alloc_device(drv_struct, member) \
2829 container_of(_ib_alloc_device(sizeof(struct drv_struct) + \
2830 BUILD_BUG_ON_ZERO(offsetof( \
2831 struct drv_struct, member))), \
2832 struct drv_struct, member)
2833
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834void ib_dealloc_device(struct ib_device *device);
2835
Leon Romanovsky9abb0d12017-06-27 16:49:53 +03002836void ib_get_device_fw_str(struct ib_device *device, char *str);
Ira Weiny5fa76c22016-06-15 02:21:56 -04002837
Parav Panditea4baf72018-12-18 14:28:30 +02002838int ib_register_device(struct ib_device *device, const char *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839void ib_unregister_device(struct ib_device *device);
Jason Gunthorped0899892019-02-12 21:12:53 -07002840void ib_unregister_driver(enum rdma_driver_id driver_id);
2841void ib_unregister_device_and_put(struct ib_device *device);
2842void ib_unregister_device_queued(struct ib_device *ib_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
2844int ib_register_client (struct ib_client *client);
2845void ib_unregister_client(struct ib_client *client);
2846
Shiraz Saleema8082732019-05-06 08:53:33 -05002847void __rdma_block_iter_start(struct ib_block_iter *biter,
2848 struct scatterlist *sglist,
2849 unsigned int nents,
2850 unsigned long pgsz);
2851bool __rdma_block_iter_next(struct ib_block_iter *biter);
2852
2853/**
2854 * rdma_block_iter_dma_address - get the aligned dma address of the current
2855 * block held by the block iterator.
2856 * @biter: block iterator holding the memory block
2857 */
2858static inline dma_addr_t
2859rdma_block_iter_dma_address(struct ib_block_iter *biter)
2860{
2861 return biter->__dma_addr & ~(BIT_ULL(biter->__pg_bit) - 1);
2862}
2863
2864/**
2865 * rdma_for_each_block - iterate over contiguous memory blocks of the sg list
2866 * @sglist: sglist to iterate over
2867 * @biter: block iterator holding the memory block
2868 * @nents: maximum number of sg entries to iterate over
2869 * @pgsz: best HW supported page size to use
2870 *
2871 * Callers may use rdma_block_iter_dma_address() to get each
2872 * blocks aligned DMA address.
2873 */
2874#define rdma_for_each_block(sglist, biter, nents, pgsz) \
2875 for (__rdma_block_iter_start(biter, sglist, nents, \
2876 pgsz); \
2877 __rdma_block_iter_next(biter);)
2878
Jason Gunthorpe0df91bb2019-02-06 22:41:53 -07002879/**
2880 * ib_get_client_data - Get IB client context
2881 * @device:Device to get context for
2882 * @client:Client to get context for
2883 *
2884 * ib_get_client_data() returns the client context data set with
2885 * ib_set_client_data(). This can only be called while the client is
2886 * registered to the device, once the ib_client remove() callback returns this
2887 * cannot be called.
2888 */
2889static inline void *ib_get_client_data(struct ib_device *device,
2890 struct ib_client *client)
2891{
2892 return xa_load(&device->client_data, client->client_id);
2893}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894void ib_set_client_data(struct ib_device *device, struct ib_client *client,
2895 void *data);
Kamal Heib521ed0d2018-12-10 21:09:30 +02002896void ib_set_device_ops(struct ib_device *device,
2897 const struct ib_device_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
Jason Gunthorpe5f9794d2018-09-16 20:43:08 +03002899int rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma,
Michal Kalderonc043ff22019-10-30 11:44:12 +02002900 unsigned long pfn, unsigned long size, pgprot_t prot,
2901 struct rdma_user_mmap_entry *entry);
Michal Kalderon3411f9f2019-10-30 11:44:11 +02002902int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
2903 struct rdma_user_mmap_entry *entry,
2904 size_t length);
Yishai Hadas7a763d12019-12-12 12:02:36 +02002905int rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
2906 struct rdma_user_mmap_entry *entry,
2907 size_t length, u32 min_pgoff,
2908 u32 max_pgoff);
2909
Michal Kalderon3411f9f2019-10-30 11:44:11 +02002910struct rdma_user_mmap_entry *
2911rdma_user_mmap_entry_get_pgoff(struct ib_ucontext *ucontext,
2912 unsigned long pgoff);
2913struct rdma_user_mmap_entry *
2914rdma_user_mmap_entry_get(struct ib_ucontext *ucontext,
2915 struct vm_area_struct *vma);
2916void rdma_user_mmap_entry_put(struct rdma_user_mmap_entry *entry);
2917
2918void rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry);
Jason Gunthorpe5f9794d2018-09-16 20:43:08 +03002919
Roland Dreiere2773c02005-07-07 17:57:10 -07002920static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
2921{
2922 return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
2923}
2924
2925static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
2926{
Yann Droneaud43c611652015-02-05 22:10:18 +01002927 return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
Roland Dreiere2773c02005-07-07 17:57:10 -07002928}
2929
Matan Barakc66db312018-03-19 15:02:36 +02002930static inline bool ib_is_buffer_cleared(const void __user *p,
2931 size_t len)
Matan Barak301a7212015-12-15 20:30:10 +02002932{
Markus Elfring92d27ae2016-08-22 18:23:24 +02002933 bool ret;
Matan Barak301a7212015-12-15 20:30:10 +02002934 u8 *buf;
2935
2936 if (len > USHRT_MAX)
2937 return false;
2938
Markus Elfring92d27ae2016-08-22 18:23:24 +02002939 buf = memdup_user(p, len);
2940 if (IS_ERR(buf))
Matan Barak301a7212015-12-15 20:30:10 +02002941 return false;
2942
Matan Barak301a7212015-12-15 20:30:10 +02002943 ret = !memchr_inv(buf, 0, len);
Matan Barak301a7212015-12-15 20:30:10 +02002944 kfree(buf);
2945 return ret;
2946}
2947
Matan Barakc66db312018-03-19 15:02:36 +02002948static inline bool ib_is_udata_cleared(struct ib_udata *udata,
2949 size_t offset,
2950 size_t len)
2951{
2952 return ib_is_buffer_cleared(udata->inbuf + offset, len);
2953}
2954
Roland Dreier8a518662006-02-13 12:48:12 -08002955/**
Yishai Hadas1c774832018-06-20 17:11:39 +03002956 * ib_is_destroy_retryable - Check whether the uobject destruction
2957 * is retryable.
2958 * @ret: The initial destruction return code
2959 * @why: remove reason
2960 * @uobj: The uobject that is destroyed
2961 *
2962 * This function is a helper function that IB layer and low-level drivers
2963 * can use to consider whether the destruction of the given uobject is
2964 * retry-able.
2965 * It checks the original return code, if it wasn't success the destruction
2966 * is retryable according to the ucontext state (i.e. cleanup_retryable) and
2967 * the remove reason. (i.e. why).
2968 * Must be called with the object locked for destroy.
2969 */
2970static inline bool ib_is_destroy_retryable(int ret, enum rdma_remove_reason why,
2971 struct ib_uobject *uobj)
2972{
2973 return ret && (why == RDMA_REMOVE_DESTROY ||
2974 uobj->context->cleanup_retryable);
2975}
2976
2977/**
2978 * ib_destroy_usecnt - Called during destruction to check the usecnt
2979 * @usecnt: The usecnt atomic
2980 * @why: remove reason
2981 * @uobj: The uobject that is destroyed
2982 *
2983 * Non-zero usecnts will block destruction unless destruction was triggered by
2984 * a ucontext cleanup.
2985 */
2986static inline int ib_destroy_usecnt(atomic_t *usecnt,
2987 enum rdma_remove_reason why,
2988 struct ib_uobject *uobj)
2989{
2990 if (atomic_read(usecnt) && ib_is_destroy_retryable(-EBUSY, why, uobj))
2991 return -EBUSY;
2992 return 0;
2993}
2994
2995/**
Roland Dreier8a518662006-02-13 12:48:12 -08002996 * ib_modify_qp_is_ok - Check that the supplied attribute mask
2997 * contains all required attributes and no attributes not allowed for
2998 * the given QP state transition.
2999 * @cur_state: Current QP state
3000 * @next_state: Next QP state
3001 * @type: QP type
3002 * @mask: Mask of supplied QP attributes
3003 *
3004 * This function is a helper function that a low-level driver's
3005 * modify_qp method can use to validate the consumer's input. It
3006 * checks that cur_state and next_state are valid QP states, that a
3007 * transition from cur_state to next_state is allowed by the IB spec,
3008 * and that the attribute mask supplied is allowed for the transition.
3009 */
Leon Romanovsky19b1f542018-03-11 13:51:35 +02003010bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
Kamal Heibd31131b2018-10-02 16:11:21 +03003011 enum ib_qp_type type, enum ib_qp_attr_mask mask);
Roland Dreier8a518662006-02-13 12:48:12 -08003012
Leon Romanovskydcc98812017-08-17 15:50:36 +03003013void ib_register_event_handler(struct ib_event_handler *event_handler);
3014void ib_unregister_event_handler(struct ib_event_handler *event_handler);
Parav Pandit6b57cea2019-12-12 13:30:22 +02003015void ib_dispatch_event(const struct ib_event *event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017int ib_query_port(struct ib_device *device,
3018 u8 port_num, struct ib_port_attr *port_attr);
3019
Eli Cohena3f5ada2010-09-27 17:51:10 -07003020enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
3021 u8 port_num);
3022
Ira Weiny0cf18d72015-05-13 20:02:55 -04003023/**
Hal Rosenstock41390322015-06-29 09:57:00 -04003024 * rdma_cap_ib_switch - Check if the device is IB switch
3025 * @device: Device to check
3026 *
3027 * Device driver is responsible for setting is_switch bit on
3028 * in ib_device structure at init time.
3029 *
3030 * Return: true if the device is IB switch.
3031 */
3032static inline bool rdma_cap_ib_switch(const struct ib_device *device)
3033{
3034 return device->is_switch;
3035}
3036
3037/**
Ira Weiny0cf18d72015-05-13 20:02:55 -04003038 * rdma_start_port - Return the first valid port number for the device
3039 * specified
3040 *
3041 * @device: Device to be checked
3042 *
3043 * Return start port number
3044 */
3045static inline u8 rdma_start_port(const struct ib_device *device)
3046{
Hal Rosenstock41390322015-06-29 09:57:00 -04003047 return rdma_cap_ib_switch(device) ? 0 : 1;
Ira Weiny0cf18d72015-05-13 20:02:55 -04003048}
3049
3050/**
Jason Gunthorpeea1075e2019-02-12 21:12:47 -07003051 * rdma_for_each_port - Iterate over all valid port numbers of the IB device
3052 * @device - The struct ib_device * to iterate over
3053 * @iter - The unsigned int to store the port number
3054 */
3055#define rdma_for_each_port(device, iter) \
3056 for (iter = rdma_start_port(device + BUILD_BUG_ON_ZERO(!__same_type( \
3057 unsigned int, iter))); \
3058 iter <= rdma_end_port(device); (iter)++)
3059
3060/**
Ira Weiny0cf18d72015-05-13 20:02:55 -04003061 * rdma_end_port - Return the last valid port number for the device
3062 * specified
3063 *
3064 * @device: Device to be checked
3065 *
3066 * Return last port number
3067 */
3068static inline u8 rdma_end_port(const struct ib_device *device)
3069{
Hal Rosenstock41390322015-06-29 09:57:00 -04003070 return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
Ira Weiny0cf18d72015-05-13 20:02:55 -04003071}
3072
Yuval Shaia24dc8312017-01-25 18:41:37 +02003073static inline int rdma_is_port_valid(const struct ib_device *device,
3074 unsigned int port)
3075{
3076 return (port >= rdma_start_port(device) &&
3077 port <= rdma_end_port(device));
3078}
3079
Artemy Kovalyovb02289b2018-07-04 15:57:50 +03003080static inline bool rdma_is_grh_required(const struct ib_device *device,
3081 u8 port_num)
3082{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003083 return device->port_data[port_num].immutable.core_cap_flags &
3084 RDMA_CORE_PORT_IB_GRH_REQUIRED;
Artemy Kovalyovb02289b2018-07-04 15:57:50 +03003085}
3086
Ira Weiny5ede9282015-05-31 17:15:29 -04003087static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02003088{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003089 return device->port_data[port_num].immutable.core_cap_flags &
3090 RDMA_CORE_CAP_PROT_IB;
Michael Wangde66be92015-05-05 14:50:19 +02003091}
3092
Ira Weiny5ede9282015-05-31 17:15:29 -04003093static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02003094{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003095 return device->port_data[port_num].immutable.core_cap_flags &
3096 (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
Matan Barak7766a992015-12-23 14:56:50 +02003097}
3098
3099static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
3100{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003101 return device->port_data[port_num].immutable.core_cap_flags &
3102 RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
Matan Barak7766a992015-12-23 14:56:50 +02003103}
3104
3105static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
3106{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003107 return device->port_data[port_num].immutable.core_cap_flags &
3108 RDMA_CORE_CAP_PROT_ROCE;
Michael Wangde66be92015-05-05 14:50:19 +02003109}
3110
Ira Weiny5ede9282015-05-31 17:15:29 -04003111static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02003112{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003113 return device->port_data[port_num].immutable.core_cap_flags &
3114 RDMA_CORE_CAP_PROT_IWARP;
Michael Wangde66be92015-05-05 14:50:19 +02003115}
3116
Ira Weiny5ede9282015-05-31 17:15:29 -04003117static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
Michael Wangde66be92015-05-05 14:50:19 +02003118{
Matan Barak7766a992015-12-23 14:56:50 +02003119 return rdma_protocol_ib(device, port_num) ||
3120 rdma_protocol_roce(device, port_num);
Michael Wangde66be92015-05-05 14:50:19 +02003121}
3122
Or Gerlitzaa773bd2017-01-24 13:02:35 +02003123static inline bool rdma_protocol_raw_packet(const struct ib_device *device, u8 port_num)
3124{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003125 return device->port_data[port_num].immutable.core_cap_flags &
3126 RDMA_CORE_CAP_PROT_RAW_PACKET;
Or Gerlitzaa773bd2017-01-24 13:02:35 +02003127}
3128
Or Gerlitzce1e0552017-01-24 13:02:38 +02003129static inline bool rdma_protocol_usnic(const struct ib_device *device, u8 port_num)
3130{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003131 return device->port_data[port_num].immutable.core_cap_flags &
3132 RDMA_CORE_CAP_PROT_USNIC;
Or Gerlitzce1e0552017-01-24 13:02:38 +02003133}
3134
Michael Wangc757dea2015-05-05 14:50:32 +02003135/**
Michael Wang296ec002015-05-18 10:41:45 +02003136 * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
Michael Wangc757dea2015-05-05 14:50:32 +02003137 * Management Datagrams.
Michael Wang296ec002015-05-18 10:41:45 +02003138 * @device: Device to check
3139 * @port_num: Port number to check
Michael Wangc757dea2015-05-05 14:50:32 +02003140 *
Michael Wang296ec002015-05-18 10:41:45 +02003141 * Management Datagrams (MAD) are a required part of the InfiniBand
3142 * specification and are supported on all InfiniBand devices. A slightly
3143 * extended version are also supported on OPA interfaces.
Michael Wangc757dea2015-05-05 14:50:32 +02003144 *
Michael Wang296ec002015-05-18 10:41:45 +02003145 * Return: true if the port supports sending/receiving of MAD packets.
Michael Wangc757dea2015-05-05 14:50:32 +02003146 */
Ira Weiny5ede9282015-05-31 17:15:29 -04003147static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
Michael Wangc757dea2015-05-05 14:50:32 +02003148{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003149 return device->port_data[port_num].immutable.core_cap_flags &
3150 RDMA_CORE_CAP_IB_MAD;
Michael Wangc757dea2015-05-05 14:50:32 +02003151}
3152
Michael Wang29541e32015-05-05 14:50:33 +02003153/**
Ira Weiny65995fe2015-06-06 14:38:32 -04003154 * rdma_cap_opa_mad - Check if the port of device provides support for OPA
3155 * Management Datagrams.
3156 * @device: Device to check
3157 * @port_num: Port number to check
3158 *
3159 * Intel OmniPath devices extend and/or replace the InfiniBand Management
3160 * datagrams with their own versions. These OPA MADs share many but not all of
3161 * the characteristics of InfiniBand MADs.
3162 *
3163 * OPA MADs differ in the following ways:
3164 *
3165 * 1) MADs are variable size up to 2K
3166 * IBTA defined MADs remain fixed at 256 bytes
3167 * 2) OPA SMPs must carry valid PKeys
3168 * 3) OPA SMP packets are a different format
3169 *
3170 * Return: true if the port supports OPA MAD packet formats.
3171 */
3172static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
3173{
Leon Romanovskyd3243da2019-03-10 17:27:46 +02003174 return device->port_data[port_num].immutable.core_cap_flags &
3175 RDMA_CORE_CAP_OPA_MAD;
Ira Weiny65995fe2015-06-06 14:38:32 -04003176}
3177
3178/**
Michael Wang296ec002015-05-18 10:41:45 +02003179 * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
3180 * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
3181 * @device: Device to check
3182 * @port_num: Port number to check
Michael Wang29541e32015-05-05 14:50:33 +02003183 *
Michael Wang296ec002015-05-18 10:41:45 +02003184 * Each InfiniBand node is required to provide a Subnet Management Agent
3185 * that the subnet manager can access. Prior to the fabric being fully
3186 * configured by the subnet manager, the SMA is accessed via a well known
3187 * interface called the Subnet Management Interface (SMI). This interface
3188 * uses directed route packets to communicate with the SM to get around the
3189 * chicken and egg problem of the SM needing to know what's on the fabric
3190 * in order to configure the fabric, and needing to configure the fabric in
3191 * order to send packets to the devices on the fabric. These directed
3192 * route packets do not need the fabric fully configured in order to reach
3193 * their destination. The SMI is the only method allowed to send
3194 * directed route packets on an InfiniBand fabric.
Michael Wang29541e32015-05-05 14:50:33 +02003195 *
Michael Wang296ec002015-05-18 10:41:45 +02003196 * Return: true if the port provides an SMI.
Michael Wang29541e32015-05-05 14:50:33 +02003197 */
Ira Weiny5ede9282015-05-31 17:15:29 -04003198static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
Michael Wang29541e32015-05-05 14:50:33 +02003199{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003200 return device->port_data[port_num].immutable.core_cap_flags &
3201 RDMA_CORE_CAP_IB_SMI;
Michael Wang29541e32015-05-05 14:50:33 +02003202}
3203
Michael Wang72219cea2015-05-05 14:50:34 +02003204/**
3205 * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
3206 * Communication Manager.
Michael Wang296ec002015-05-18 10:41:45 +02003207 * @device: Device to check
3208 * @port_num: Port number to check
Michael Wang72219cea2015-05-05 14:50:34 +02003209 *
Michael Wang296ec002015-05-18 10:41:45 +02003210 * The InfiniBand Communication Manager is one of many pre-defined General
3211 * Service Agents (GSA) that are accessed via the General Service
3212 * Interface (GSI). It's role is to facilitate establishment of connections
3213 * between nodes as well as other management related tasks for established
3214 * connections.
Michael Wang72219cea2015-05-05 14:50:34 +02003215 *
Michael Wang296ec002015-05-18 10:41:45 +02003216 * Return: true if the port supports an IB CM (this does not guarantee that
3217 * a CM is actually running however).
Michael Wang72219cea2015-05-05 14:50:34 +02003218 */
Ira Weiny5ede9282015-05-31 17:15:29 -04003219static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
Michael Wang72219cea2015-05-05 14:50:34 +02003220{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003221 return device->port_data[port_num].immutable.core_cap_flags &
3222 RDMA_CORE_CAP_IB_CM;
Michael Wang72219cea2015-05-05 14:50:34 +02003223}
3224
Michael Wang04215332015-05-05 14:50:35 +02003225/**
3226 * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
3227 * Communication Manager.
Michael Wang296ec002015-05-18 10:41:45 +02003228 * @device: Device to check
3229 * @port_num: Port number to check
Michael Wang04215332015-05-05 14:50:35 +02003230 *
Michael Wang296ec002015-05-18 10:41:45 +02003231 * Similar to above, but specific to iWARP connections which have a different
3232 * managment protocol than InfiniBand.
Michael Wang04215332015-05-05 14:50:35 +02003233 *
Michael Wang296ec002015-05-18 10:41:45 +02003234 * Return: true if the port supports an iWARP CM (this does not guarantee that
3235 * a CM is actually running however).
Michael Wang04215332015-05-05 14:50:35 +02003236 */
Ira Weiny5ede9282015-05-31 17:15:29 -04003237static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
Michael Wang04215332015-05-05 14:50:35 +02003238{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003239 return device->port_data[port_num].immutable.core_cap_flags &
3240 RDMA_CORE_CAP_IW_CM;
Michael Wang04215332015-05-05 14:50:35 +02003241}
3242
Michael Wangfe53ba22015-05-05 14:50:36 +02003243/**
3244 * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
3245 * Subnet Administration.
Michael Wang296ec002015-05-18 10:41:45 +02003246 * @device: Device to check
3247 * @port_num: Port number to check
Michael Wangfe53ba22015-05-05 14:50:36 +02003248 *
Michael Wang296ec002015-05-18 10:41:45 +02003249 * An InfiniBand Subnet Administration (SA) service is a pre-defined General
3250 * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
3251 * fabrics, devices should resolve routes to other hosts by contacting the
3252 * SA to query the proper route.
Michael Wangfe53ba22015-05-05 14:50:36 +02003253 *
Michael Wang296ec002015-05-18 10:41:45 +02003254 * Return: true if the port should act as a client to the fabric Subnet
3255 * Administration interface. This does not imply that the SA service is
3256 * running locally.
Michael Wangfe53ba22015-05-05 14:50:36 +02003257 */
Ira Weiny5ede9282015-05-31 17:15:29 -04003258static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
Michael Wangfe53ba22015-05-05 14:50:36 +02003259{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003260 return device->port_data[port_num].immutable.core_cap_flags &
3261 RDMA_CORE_CAP_IB_SA;
Michael Wangfe53ba22015-05-05 14:50:36 +02003262}
3263
Michael Wanga31ad3b2015-05-05 14:50:37 +02003264/**
3265 * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
3266 * Multicast.
Michael Wang296ec002015-05-18 10:41:45 +02003267 * @device: Device to check
3268 * @port_num: Port number to check
Michael Wanga31ad3b2015-05-05 14:50:37 +02003269 *
Michael Wang296ec002015-05-18 10:41:45 +02003270 * InfiniBand multicast registration is more complex than normal IPv4 or
3271 * IPv6 multicast registration. Each Host Channel Adapter must register
3272 * with the Subnet Manager when it wishes to join a multicast group. It
3273 * should do so only once regardless of how many queue pairs it subscribes
3274 * to this group. And it should leave the group only after all queue pairs
3275 * attached to the group have been detached.
Michael Wanga31ad3b2015-05-05 14:50:37 +02003276 *
Michael Wang296ec002015-05-18 10:41:45 +02003277 * Return: true if the port must undertake the additional adminstrative
3278 * overhead of registering/unregistering with the SM and tracking of the
3279 * total number of queue pairs attached to the multicast group.
Michael Wanga31ad3b2015-05-05 14:50:37 +02003280 */
Ira Weiny5ede9282015-05-31 17:15:29 -04003281static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
Michael Wanga31ad3b2015-05-05 14:50:37 +02003282{
3283 return rdma_cap_ib_sa(device, port_num);
3284}
3285
Michael Wangbc0f1d72015-05-05 14:50:38 +02003286/**
Michael Wang30a74ef2015-05-05 14:50:39 +02003287 * rdma_cap_af_ib - Check if the port of device has the capability
3288 * Native Infiniband Address.
Michael Wang296ec002015-05-18 10:41:45 +02003289 * @device: Device to check
3290 * @port_num: Port number to check
Michael Wang30a74ef2015-05-05 14:50:39 +02003291 *
Michael Wang296ec002015-05-18 10:41:45 +02003292 * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
3293 * GID. RoCE uses a different mechanism, but still generates a GID via
3294 * a prescribed mechanism and port specific data.
Michael Wang30a74ef2015-05-05 14:50:39 +02003295 *
Michael Wang296ec002015-05-18 10:41:45 +02003296 * Return: true if the port uses a GID address to identify devices on the
3297 * network.
Michael Wang30a74ef2015-05-05 14:50:39 +02003298 */
Ira Weiny5ede9282015-05-31 17:15:29 -04003299static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
Michael Wang30a74ef2015-05-05 14:50:39 +02003300{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003301 return device->port_data[port_num].immutable.core_cap_flags &
3302 RDMA_CORE_CAP_AF_IB;
Michael Wang30a74ef2015-05-05 14:50:39 +02003303}
3304
3305/**
Michael Wang227128f2015-05-05 14:50:40 +02003306 * rdma_cap_eth_ah - Check if the port of device has the capability
Michael Wang296ec002015-05-18 10:41:45 +02003307 * Ethernet Address Handle.
3308 * @device: Device to check
3309 * @port_num: Port number to check
Michael Wang227128f2015-05-05 14:50:40 +02003310 *
Michael Wang296ec002015-05-18 10:41:45 +02003311 * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
3312 * to fabricate GIDs over Ethernet/IP specific addresses native to the
3313 * port. Normally, packet headers are generated by the sending host
3314 * adapter, but when sending connectionless datagrams, we must manually
3315 * inject the proper headers for the fabric we are communicating over.
Michael Wang227128f2015-05-05 14:50:40 +02003316 *
Michael Wang296ec002015-05-18 10:41:45 +02003317 * Return: true if we are running as a RoCE port and must force the
3318 * addition of a Global Route Header built from our Ethernet Address
3319 * Handle into our header list for connectionless packets.
Michael Wang227128f2015-05-05 14:50:40 +02003320 */
Ira Weiny5ede9282015-05-31 17:15:29 -04003321static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
Michael Wang227128f2015-05-05 14:50:40 +02003322{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003323 return device->port_data[port_num].immutable.core_cap_flags &
3324 RDMA_CORE_CAP_ETH_AH;
Michael Wang227128f2015-05-05 14:50:40 +02003325}
3326
3327/**
Dasaratharaman Chandramouli94d595c2017-03-20 19:38:09 -04003328 * rdma_cap_opa_ah - Check if the port of device supports
3329 * OPA Address handles
3330 * @device: Device to check
3331 * @port_num: Port number to check
3332 *
3333 * Return: true if we are running on an OPA device which supports
3334 * the extended OPA addressing.
3335 */
3336static inline bool rdma_cap_opa_ah(struct ib_device *device, u8 port_num)
3337{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003338 return (device->port_data[port_num].immutable.core_cap_flags &
Dasaratharaman Chandramouli94d595c2017-03-20 19:38:09 -04003339 RDMA_CORE_CAP_OPA_AH) == RDMA_CORE_CAP_OPA_AH;
3340}
3341
3342/**
Ira Weiny337877a2015-06-06 14:38:29 -04003343 * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
3344 *
3345 * @device: Device
3346 * @port_num: Port number
3347 *
3348 * This MAD size includes the MAD headers and MAD payload. No other headers
3349 * are included.
3350 *
3351 * Return the max MAD size required by the Port. Will return 0 if the port
3352 * does not support MADs
3353 */
3354static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
3355{
Jason Gunthorpe8ceb1352019-02-12 21:12:48 -07003356 return device->port_data[port_num].immutable.max_mad_size;
Ira Weiny337877a2015-06-06 14:38:29 -04003357}
3358
Matan Barak03db3a22015-07-30 18:33:26 +03003359/**
3360 * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
3361 * @device: Device to check
3362 * @port_num: Port number to check
3363 *
3364 * RoCE GID table mechanism manages the various GIDs for a device.
3365 *
3366 * NOTE: if allocating the port's GID table has failed, this call will still
3367 * return true, but any RoCE GID table API will fail.
3368 *
3369 * Return: true if the port uses RoCE GID table mechanism in order to manage
3370 * its GIDs.
3371 */
3372static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
3373 u8 port_num)
3374{
3375 return rdma_protocol_roce(device, port_num) &&
Kamal Heib3023a1e2018-12-10 21:09:48 +02003376 device->ops.add_gid && device->ops.del_gid;
Matan Barak03db3a22015-07-30 18:33:26 +03003377}
3378
Christoph Hellwig002516e2016-05-03 18:01:05 +02003379/*
3380 * Check if the device supports READ W/ INVALIDATE.
3381 */
3382static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
3383{
3384 /*
3385 * iWarp drivers must support READ W/ INVALIDATE. No other protocol
3386 * has support for it yet.
3387 */
3388 return rdma_protocol_iwarp(dev, port_num);
3389}
3390
Shiraz Saleem4a353392019-05-06 08:53:32 -05003391/**
3392 * rdma_find_pg_bit - Find page bit given address and HW supported page sizes
3393 *
3394 * @addr: address
3395 * @pgsz_bitmap: bitmap of HW supported page sizes
3396 */
3397static inline unsigned int rdma_find_pg_bit(unsigned long addr,
3398 unsigned long pgsz_bitmap)
3399{
3400 unsigned long align;
3401 unsigned long pgsz;
3402
3403 align = addr & -addr;
3404
3405 /* Find page bit such that addr is aligned to the highest supported
3406 * HW page size
3407 */
3408 pgsz = pgsz_bitmap & ~(-align << 1);
3409 if (!pgsz)
3410 return __ffs(pgsz_bitmap);
3411
3412 return __fls(pgsz);
3413}
3414
Kaike Wan6d723442020-05-11 12:06:18 -04003415/**
3416 * rdma_core_cap_opa_port - Return whether the RDMA Port is OPA or not.
3417 * @device: Device
3418 * @port_num: 1 based Port number
3419 *
3420 * Return true if port is an Intel OPA port , false if not
3421 */
3422static inline bool rdma_core_cap_opa_port(struct ib_device *device,
3423 u32 port_num)
3424{
3425 return (device->port_data[port_num].immutable.core_cap_flags &
3426 RDMA_CORE_PORT_INTEL_OPA) == RDMA_CORE_PORT_INTEL_OPA;
3427}
3428
3429/**
3430 * rdma_mtu_enum_to_int - Return the mtu of the port as an integer value.
3431 * @device: Device
3432 * @port_num: Port number
3433 * @mtu: enum value of MTU
3434 *
3435 * Return the MTU size supported by the port as an integer value. Will return
3436 * -1 if enum value of mtu is not supported.
3437 */
3438static inline int rdma_mtu_enum_to_int(struct ib_device *device, u8 port,
3439 int mtu)
3440{
3441 if (rdma_core_cap_opa_port(device, port))
3442 return opa_mtu_enum_to_int((enum opa_mtu)mtu);
3443 else
3444 return ib_mtu_enum_to_int((enum ib_mtu)mtu);
3445}
3446
3447/**
3448 * rdma_mtu_from_attr - Return the mtu of the port from the port attribute.
3449 * @device: Device
3450 * @port_num: Port number
3451 * @attr: port attribute
3452 *
3453 * Return the MTU size supported by the port as an integer value.
3454 */
3455static inline int rdma_mtu_from_attr(struct ib_device *device, u8 port,
3456 struct ib_port_attr *attr)
3457{
3458 if (rdma_core_cap_opa_port(device, port))
3459 return attr->phys_mtu;
3460 else
3461 return ib_mtu_enum_to_int(attr->max_mtu);
3462}
3463
Eli Cohen50174a72016-03-11 22:58:38 +02003464int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
3465 int state);
3466int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
3467 struct ifla_vf_info *info);
3468int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
3469 struct ifla_vf_stats *stats);
Danit Goldbergbfcb3c5d2019-11-06 15:08:32 +02003470int ib_get_vf_guid(struct ib_device *device, int vf, u8 port,
3471 struct ifla_vf_guid *node_guid,
3472 struct ifla_vf_guid *port_guid);
Eli Cohen50174a72016-03-11 22:58:38 +02003473int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
3474 int type);
3475
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476int ib_query_pkey(struct ib_device *device,
3477 u8 port_num, u16 index, u16 *pkey);
3478
3479int ib_modify_device(struct ib_device *device,
3480 int device_modify_mask,
3481 struct ib_device_modify *device_modify);
3482
3483int ib_modify_port(struct ib_device *device,
3484 u8 port_num, int port_modify_mask,
3485 struct ib_port_modify *port_modify);
3486
Yosef Etigin5eb620c2007-05-14 07:26:51 +03003487int ib_find_gid(struct ib_device *device, union ib_gid *gid,
Parav Panditb26c4a12018-03-13 16:06:12 +02003488 u8 *port_num, u16 *index);
Yosef Etigin5eb620c2007-05-14 07:26:51 +03003489
3490int ib_find_pkey(struct ib_device *device,
3491 u8 port_num, u16 pkey, u16 *index);
3492
Christoph Hellwiged082d32016-09-05 12:56:17 +02003493enum ib_pd_flags {
3494 /*
3495 * Create a memory registration for all memory in the system and place
3496 * the rkey for it into pd->unsafe_global_rkey. This can be used by
3497 * ULPs to avoid the overhead of dynamic MRs.
3498 *
3499 * This flag is generally considered unsafe and must only be used in
3500 * extremly trusted environments. Every use of it will log a warning
3501 * in the kernel log.
3502 */
3503 IB_PD_UNSAFE_GLOBAL_RKEY = 0x01,
3504};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505
Christoph Hellwiged082d32016-09-05 12:56:17 +02003506struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
3507 const char *caller);
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003508
Christoph Hellwiged082d32016-09-05 12:56:17 +02003509#define ib_alloc_pd(device, flags) \
Leon Romanovskye4496442018-01-28 11:17:18 +02003510 __ib_alloc_pd((device), (flags), KBUILD_MODNAME)
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003511
3512/**
3513 * ib_dealloc_pd_user - Deallocate kernel/user PD
3514 * @pd: The protection domain
3515 * @udata: Valid user data or NULL for kernel objects
3516 */
3517void ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata);
3518
3519/**
3520 * ib_dealloc_pd - Deallocate kernel PD
3521 * @pd: The protection domain
3522 *
3523 * NOTE: for user PD use ib_dealloc_pd_user with valid udata!
3524 */
3525static inline void ib_dealloc_pd(struct ib_pd *pd)
3526{
3527 ib_dealloc_pd_user(pd, NULL);
3528}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529
Gal Pressmanb090c4e2018-12-12 11:09:05 +02003530enum rdma_create_ah_flags {
3531 /* In a sleepable context */
3532 RDMA_CREATE_AH_SLEEPABLE = BIT(0),
3533};
3534
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535/**
Dasaratharaman Chandramouli0a18cfe2017-04-29 14:41:19 -04003536 * rdma_create_ah - Creates an address handle for the given address vector.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 * @pd: The protection domain associated with the address handle.
3538 * @ah_attr: The attributes of the address vector.
Gal Pressmanb090c4e2018-12-12 11:09:05 +02003539 * @flags: Create address handle flags (see enum rdma_create_ah_flags).
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 *
3541 * The address handle is used to reference a local or global destination
3542 * in all UD QP post sends.
3543 */
Gal Pressmanb090c4e2018-12-12 11:09:05 +02003544struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr,
3545 u32 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546
3547/**
Parav Pandit5cda6582017-10-16 08:45:12 +03003548 * rdma_create_user_ah - Creates an address handle for the given address vector.
3549 * It resolves destination mac address for ah attribute of RoCE type.
3550 * @pd: The protection domain associated with the address handle.
3551 * @ah_attr: The attributes of the address vector.
3552 * @udata: pointer to user's input output buffer information need by
3553 * provider driver.
3554 *
3555 * It returns 0 on success and returns appropriate error code on error.
3556 * The address handle is used to reference a local or global destination
3557 * in all UD QP post sends.
3558 */
3559struct ib_ah *rdma_create_user_ah(struct ib_pd *pd,
3560 struct rdma_ah_attr *ah_attr,
3561 struct ib_udata *udata);
3562/**
Moni Shoua850d8fd2016-11-10 11:30:56 +02003563 * ib_get_gids_from_rdma_hdr - Get sgid and dgid from GRH or IPv4 header
3564 * work completion.
3565 * @hdr: the L3 header to parse
3566 * @net_type: type of header to parse
3567 * @sgid: place to store source gid
3568 * @dgid: place to store destination gid
3569 */
3570int ib_get_gids_from_rdma_hdr(const union rdma_network_hdr *hdr,
3571 enum rdma_network_type net_type,
3572 union ib_gid *sgid, union ib_gid *dgid);
3573
3574/**
3575 * ib_get_rdma_header_version - Get the header version
3576 * @hdr: the L3 header to parse
3577 */
3578int ib_get_rdma_header_version(const union rdma_network_hdr *hdr);
3579
3580/**
Parav Panditf6bdb142017-11-14 14:52:17 +02003581 * ib_init_ah_attr_from_wc - Initializes address handle attributes from a
Sean Hefty4e00d692006-06-17 20:37:39 -07003582 * work completion.
3583 * @device: Device on which the received message arrived.
3584 * @port_num: Port on which the received message arrived.
3585 * @wc: Work completion associated with the received message.
3586 * @grh: References the received global route header. This parameter is
3587 * ignored unless the work completion indicates that the GRH is valid.
3588 * @ah_attr: Returned attributes that can be used when creating an address
3589 * handle for replying to the message.
Parav Panditb7403212018-06-19 10:59:14 +03003590 * When ib_init_ah_attr_from_wc() returns success,
3591 * (a) for IB link layer it optionally contains a reference to SGID attribute
3592 * when GRH is present for IB link layer.
3593 * (b) for RoCE link layer it contains a reference to SGID attribute.
3594 * User must invoke rdma_cleanup_ah_attr_gid_attr() to release reference to SGID
3595 * attributes which are initialized using ib_init_ah_attr_from_wc().
3596 *
Sean Hefty4e00d692006-06-17 20:37:39 -07003597 */
Parav Panditf6bdb142017-11-14 14:52:17 +02003598int ib_init_ah_attr_from_wc(struct ib_device *device, u8 port_num,
3599 const struct ib_wc *wc, const struct ib_grh *grh,
3600 struct rdma_ah_attr *ah_attr);
Sean Hefty4e00d692006-06-17 20:37:39 -07003601
3602/**
Hal Rosenstock513789e2005-07-27 11:45:34 -07003603 * ib_create_ah_from_wc - Creates an address handle associated with the
3604 * sender of the specified work completion.
3605 * @pd: The protection domain associated with the address handle.
3606 * @wc: Work completion information associated with a received message.
3607 * @grh: References the received global route header. This parameter is
3608 * ignored unless the work completion indicates that the GRH is valid.
3609 * @port_num: The outbound port number to associate with the address.
3610 *
3611 * The address handle is used to reference a local or global destination
3612 * in all UD QP post sends.
3613 */
Ira Weiny73cdaae2015-05-31 17:15:31 -04003614struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
3615 const struct ib_grh *grh, u8 port_num);
Hal Rosenstock513789e2005-07-27 11:45:34 -07003616
3617/**
Dasaratharaman Chandramouli67b985b2017-04-29 14:41:20 -04003618 * rdma_modify_ah - Modifies the address vector associated with an address
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 * handle.
3620 * @ah: The address handle to modify.
3621 * @ah_attr: The new address vector attributes to associate with the
3622 * address handle.
3623 */
Dasaratharaman Chandramouli67b985b2017-04-29 14:41:20 -04003624int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625
3626/**
Dasaratharaman Chandramoulibfbfd662017-04-29 14:41:21 -04003627 * rdma_query_ah - Queries the address vector associated with an address
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 * handle.
3629 * @ah: The address handle to query.
3630 * @ah_attr: The address vector attributes associated with the address
3631 * handle.
3632 */
Dasaratharaman Chandramoulibfbfd662017-04-29 14:41:21 -04003633int rdma_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634
Gal Pressman2553ba22018-12-12 11:09:06 +02003635enum rdma_destroy_ah_flags {
3636 /* In a sleepable context */
3637 RDMA_DESTROY_AH_SLEEPABLE = BIT(0),
3638};
3639
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640/**
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003641 * rdma_destroy_ah_user - Destroys an address handle.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 * @ah: The address handle to destroy.
Gal Pressman2553ba22018-12-12 11:09:06 +02003643 * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003644 * @udata: Valid user data or NULL for kernel objects
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 */
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003646int rdma_destroy_ah_user(struct ib_ah *ah, u32 flags, struct ib_udata *udata);
3647
3648/**
3649 * rdma_destroy_ah - Destroys an kernel address handle.
3650 * @ah: The address handle to destroy.
3651 * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
3652 *
3653 * NOTE: for user ah use rdma_destroy_ah_user with valid udata!
3654 */
3655static inline int rdma_destroy_ah(struct ib_ah *ah, u32 flags)
3656{
3657 return rdma_destroy_ah_user(ah, flags, NULL);
3658}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659
Jason Gunthorpeb0810b02020-05-06 11:24:39 +03003660struct ib_srq *ib_create_srq_user(struct ib_pd *pd,
3661 struct ib_srq_init_attr *srq_init_attr,
3662 struct ib_usrq_object *uobject,
3663 struct ib_udata *udata);
3664static inline struct ib_srq *
3665ib_create_srq(struct ib_pd *pd, struct ib_srq_init_attr *srq_init_attr)
3666{
3667 if (!pd->device->ops.create_srq)
3668 return ERR_PTR(-EOPNOTSUPP);
3669
3670 return ib_create_srq_user(pd, srq_init_attr, NULL, NULL);
3671}
Roland Dreierd41fcc62005-08-18 12:23:08 -07003672
3673/**
3674 * ib_modify_srq - Modifies the attributes for the specified SRQ.
3675 * @srq: The SRQ to modify.
3676 * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
3677 * the current values of selected SRQ attributes are returned.
3678 * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
3679 * are being modified.
3680 *
3681 * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
3682 * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
3683 * the number of receives queued drops below the limit.
3684 */
3685int ib_modify_srq(struct ib_srq *srq,
3686 struct ib_srq_attr *srq_attr,
3687 enum ib_srq_attr_mask srq_attr_mask);
3688
3689/**
3690 * ib_query_srq - Returns the attribute list and current values for the
3691 * specified SRQ.
3692 * @srq: The SRQ to query.
3693 * @srq_attr: The attributes of the specified SRQ.
3694 */
3695int ib_query_srq(struct ib_srq *srq,
3696 struct ib_srq_attr *srq_attr);
3697
3698/**
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003699 * ib_destroy_srq_user - Destroys the specified SRQ.
Roland Dreierd41fcc62005-08-18 12:23:08 -07003700 * @srq: The SRQ to destroy.
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003701 * @udata: Valid user data or NULL for kernel objects
Roland Dreierd41fcc62005-08-18 12:23:08 -07003702 */
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003703int ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata);
3704
3705/**
3706 * ib_destroy_srq - Destroys the specified kernel SRQ.
3707 * @srq: The SRQ to destroy.
3708 *
3709 * NOTE: for user srq use ib_destroy_srq_user with valid udata!
3710 */
3711static inline int ib_destroy_srq(struct ib_srq *srq)
3712{
3713 return ib_destroy_srq_user(srq, NULL);
3714}
Roland Dreierd41fcc62005-08-18 12:23:08 -07003715
3716/**
3717 * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
3718 * @srq: The SRQ to post the work request on.
3719 * @recv_wr: A list of work requests to post on the receive queue.
3720 * @bad_recv_wr: On an immediate failure, this parameter will reference
3721 * the work request that failed to be posted on the QP.
3722 */
3723static inline int ib_post_srq_recv(struct ib_srq *srq,
Bart Van Assched34ac5c2018-07-18 09:25:32 -07003724 const struct ib_recv_wr *recv_wr,
3725 const struct ib_recv_wr **bad_recv_wr)
Roland Dreierd41fcc62005-08-18 12:23:08 -07003726{
Bart Van Assched34ac5c2018-07-18 09:25:32 -07003727 const struct ib_recv_wr *dummy;
Bart Van Asschebb039a82018-07-18 09:25:16 -07003728
Kamal Heib3023a1e2018-12-10 21:09:48 +02003729 return srq->device->ops.post_srq_recv(srq, recv_wr,
3730 bad_recv_wr ? : &dummy);
Roland Dreierd41fcc62005-08-18 12:23:08 -07003731}
3732
Jason Gunthorpeb72bfc92020-02-13 15:19:11 -04003733struct ib_qp *ib_create_qp(struct ib_pd *pd,
3734 struct ib_qp_init_attr *qp_init_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735
3736/**
Parav Pandita512c2f2017-05-23 11:26:08 +03003737 * ib_modify_qp_with_udata - Modifies the attributes for the specified QP.
3738 * @qp: The QP to modify.
3739 * @attr: On input, specifies the QP attributes to modify. On output,
3740 * the current values of selected QP attributes are returned.
3741 * @attr_mask: A bit-mask used to specify which attributes of the QP
3742 * are being modified.
3743 * @udata: pointer to user's input output buffer information
3744 * are being modified.
3745 * It returns 0 on success and returns appropriate error code on error.
3746 */
3747int ib_modify_qp_with_udata(struct ib_qp *qp,
3748 struct ib_qp_attr *attr,
3749 int attr_mask,
3750 struct ib_udata *udata);
3751
3752/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 * ib_modify_qp - Modifies the attributes for the specified QP and then
3754 * transitions the QP to the given state.
3755 * @qp: The QP to modify.
3756 * @qp_attr: On input, specifies the QP attributes to modify. On output,
3757 * the current values of selected QP attributes are returned.
3758 * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
3759 * are being modified.
3760 */
3761int ib_modify_qp(struct ib_qp *qp,
3762 struct ib_qp_attr *qp_attr,
3763 int qp_attr_mask);
3764
3765/**
3766 * ib_query_qp - Returns the attribute list and current values for the
3767 * specified QP.
3768 * @qp: The QP to query.
3769 * @qp_attr: The attributes of the specified QP.
3770 * @qp_attr_mask: A bit-mask used to select specific attributes to query.
3771 * @qp_init_attr: Additional attributes of the selected QP.
3772 *
3773 * The qp_attr_mask may be used to limit the query to gathering only the
3774 * selected attributes.
3775 */
3776int ib_query_qp(struct ib_qp *qp,
3777 struct ib_qp_attr *qp_attr,
3778 int qp_attr_mask,
3779 struct ib_qp_init_attr *qp_init_attr);
3780
3781/**
3782 * ib_destroy_qp - Destroys the specified QP.
3783 * @qp: The QP to destroy.
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003784 * @udata: Valid udata or NULL for kernel objects
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 */
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003786int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata);
3787
3788/**
3789 * ib_destroy_qp - Destroys the specified kernel QP.
3790 * @qp: The QP to destroy.
3791 *
3792 * NOTE: for user qp use ib_destroy_qp_user with valid udata!
3793 */
3794static inline int ib_destroy_qp(struct ib_qp *qp)
3795{
3796 return ib_destroy_qp_user(qp, NULL);
3797}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798
3799/**
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07003800 * ib_open_qp - Obtain a reference to an existing sharable QP.
3801 * @xrcd - XRC domain
3802 * @qp_open_attr: Attributes identifying the QP to open.
3803 *
3804 * Returns a reference to a sharable QP.
3805 */
3806struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
3807 struct ib_qp_open_attr *qp_open_attr);
3808
3809/**
3810 * ib_close_qp - Release an external reference to a QP.
Sean Heftyd3d72d92011-05-26 23:06:44 -07003811 * @qp: The QP handle to release
3812 *
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07003813 * The opened QP handle is released by the caller. The underlying
3814 * shared QP is not destroyed until all internal references are released.
Sean Heftyd3d72d92011-05-26 23:06:44 -07003815 */
Sean Hefty0e0ec7e2011-08-08 15:31:51 -07003816int ib_close_qp(struct ib_qp *qp);
Sean Heftyd3d72d92011-05-26 23:06:44 -07003817
3818/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 * ib_post_send - Posts a list of work requests to the send queue of
3820 * the specified QP.
3821 * @qp: The QP to post the work request on.
3822 * @send_wr: A list of work requests to post on the send queue.
3823 * @bad_send_wr: On an immediate failure, this parameter will reference
3824 * the work request that failed to be posted on the QP.
Bart Van Assche55464d42009-12-09 14:20:04 -08003825 *
3826 * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
3827 * error is returned, the QP state shall not be affected,
3828 * ib_post_send() will return an immediate error after queueing any
3829 * earlier work requests in the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 */
3831static inline int ib_post_send(struct ib_qp *qp,
Bart Van Assched34ac5c2018-07-18 09:25:32 -07003832 const struct ib_send_wr *send_wr,
3833 const struct ib_send_wr **bad_send_wr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834{
Bart Van Assched34ac5c2018-07-18 09:25:32 -07003835 const struct ib_send_wr *dummy;
Bart Van Asschebb039a82018-07-18 09:25:16 -07003836
Kamal Heib3023a1e2018-12-10 21:09:48 +02003837 return qp->device->ops.post_send(qp, send_wr, bad_send_wr ? : &dummy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838}
3839
3840/**
3841 * ib_post_recv - Posts a list of work requests to the receive queue of
3842 * the specified QP.
3843 * @qp: The QP to post the work request on.
3844 * @recv_wr: A list of work requests to post on the receive queue.
3845 * @bad_recv_wr: On an immediate failure, this parameter will reference
3846 * the work request that failed to be posted on the QP.
3847 */
3848static inline int ib_post_recv(struct ib_qp *qp,
Bart Van Assched34ac5c2018-07-18 09:25:32 -07003849 const struct ib_recv_wr *recv_wr,
3850 const struct ib_recv_wr **bad_recv_wr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851{
Bart Van Assched34ac5c2018-07-18 09:25:32 -07003852 const struct ib_recv_wr *dummy;
Bart Van Asschebb039a82018-07-18 09:25:16 -07003853
Kamal Heib3023a1e2018-12-10 21:09:48 +02003854 return qp->device->ops.post_recv(qp, recv_wr, bad_recv_wr ? : &dummy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855}
3856
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003857struct ib_cq *__ib_alloc_cq_user(struct ib_device *dev, void *private,
3858 int nr_cqe, int comp_vector,
3859 enum ib_poll_context poll_ctx,
3860 const char *caller, struct ib_udata *udata);
Leon Romanovskyf66c8ba2018-01-28 11:17:19 +02003861
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003862/**
3863 * ib_alloc_cq_user: Allocate kernel/user CQ
3864 * @dev: The IB device
3865 * @private: Private data attached to the CQE
3866 * @nr_cqe: Number of CQEs in the CQ
3867 * @comp_vector: Completion vector used for the IRQs
3868 * @poll_ctx: Context used for polling the CQ
3869 * @udata: Valid user data or NULL for kernel objects
3870 */
3871static inline struct ib_cq *ib_alloc_cq_user(struct ib_device *dev,
3872 void *private, int nr_cqe,
3873 int comp_vector,
3874 enum ib_poll_context poll_ctx,
3875 struct ib_udata *udata)
3876{
3877 return __ib_alloc_cq_user(dev, private, nr_cqe, comp_vector, poll_ctx,
3878 KBUILD_MODNAME, udata);
3879}
3880
3881/**
3882 * ib_alloc_cq: Allocate kernel CQ
3883 * @dev: The IB device
3884 * @private: Private data attached to the CQE
3885 * @nr_cqe: Number of CQEs in the CQ
3886 * @comp_vector: Completion vector used for the IRQs
3887 * @poll_ctx: Context used for polling the CQ
3888 *
3889 * NOTE: for user cq use ib_alloc_cq_user with valid udata!
3890 */
3891static inline struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
3892 int nr_cqe, int comp_vector,
3893 enum ib_poll_context poll_ctx)
3894{
3895 return ib_alloc_cq_user(dev, private, nr_cqe, comp_vector, poll_ctx,
3896 NULL);
3897}
3898
Chuck Lever20cf4e02019-07-29 13:22:09 -04003899struct ib_cq *__ib_alloc_cq_any(struct ib_device *dev, void *private,
3900 int nr_cqe, enum ib_poll_context poll_ctx,
3901 const char *caller);
3902
3903/**
3904 * ib_alloc_cq_any: Allocate kernel CQ
3905 * @dev: The IB device
3906 * @private: Private data attached to the CQE
3907 * @nr_cqe: Number of CQEs in the CQ
3908 * @poll_ctx: Context used for polling the CQ
3909 */
3910static inline struct ib_cq *ib_alloc_cq_any(struct ib_device *dev,
3911 void *private, int nr_cqe,
3912 enum ib_poll_context poll_ctx)
3913{
3914 return __ib_alloc_cq_any(dev, private, nr_cqe, poll_ctx,
3915 KBUILD_MODNAME);
3916}
3917
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003918/**
3919 * ib_free_cq_user - Free kernel/user CQ
3920 * @cq: The CQ to free
3921 * @udata: Valid user data or NULL for kernel objects
Yamin Friedman3446cbd2020-05-27 11:34:52 +03003922 *
3923 * NOTE: This function shouldn't be called on shared CQs.
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003924 */
3925void ib_free_cq_user(struct ib_cq *cq, struct ib_udata *udata);
3926
3927/**
3928 * ib_free_cq - Free kernel CQ
3929 * @cq: The CQ to free
3930 *
3931 * NOTE: for user cq use ib_free_cq_user with valid udata!
3932 */
3933static inline void ib_free_cq(struct ib_cq *cq)
3934{
3935 ib_free_cq_user(cq, NULL);
3936}
3937
Christoph Hellwig14d3a3b2015-12-11 11:53:03 -08003938int ib_process_cq_direct(struct ib_cq *cq, int budget);
3939
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940/**
3941 * ib_create_cq - Creates a CQ on the specified device.
3942 * @device: The device on which to create the CQ.
3943 * @comp_handler: A user-specified callback that is invoked when a
3944 * completion event occurs on the CQ.
3945 * @event_handler: A user-specified callback that is invoked when an
3946 * asynchronous event not associated with a completion occurs on the CQ.
3947 * @cq_context: Context associated with the CQ returned to the user via
3948 * the associated completion and event handlers.
Matan Barak8e372102015-06-11 16:35:21 +03003949 * @cq_attr: The attributes the CQ should be created upon.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 *
3951 * Users can examine the cq structure to determine the actual CQ size.
3952 */
Bharat Potnuri7350cdd2018-06-15 20:52:33 +05303953struct ib_cq *__ib_create_cq(struct ib_device *device,
3954 ib_comp_handler comp_handler,
3955 void (*event_handler)(struct ib_event *, void *),
3956 void *cq_context,
3957 const struct ib_cq_init_attr *cq_attr,
3958 const char *caller);
3959#define ib_create_cq(device, cmp_hndlr, evt_hndlr, cq_ctxt, cq_attr) \
3960 __ib_create_cq((device), (cmp_hndlr), (evt_hndlr), (cq_ctxt), (cq_attr), KBUILD_MODNAME)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961
3962/**
3963 * ib_resize_cq - Modifies the capacity of the CQ.
3964 * @cq: The CQ to resize.
3965 * @cqe: The minimum size of the CQ.
3966 *
3967 * Users can examine the cq structure to determine the actual CQ size.
3968 */
3969int ib_resize_cq(struct ib_cq *cq, int cqe);
3970
3971/**
Leon Romanovsky4190b4e2017-11-13 10:51:19 +02003972 * rdma_set_cq_moderation - Modifies moderation params of the CQ
Eli Cohen2dd57162008-04-16 21:09:33 -07003973 * @cq: The CQ to modify.
3974 * @cq_count: number of CQEs that will trigger an event
3975 * @cq_period: max period of time in usec before triggering an event
3976 *
3977 */
Leon Romanovsky4190b4e2017-11-13 10:51:19 +02003978int rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period);
Eli Cohen2dd57162008-04-16 21:09:33 -07003979
3980/**
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003981 * ib_destroy_cq_user - Destroys the specified CQ.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 * @cq: The CQ to destroy.
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003983 * @udata: Valid user data or NULL for kernel objects
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984 */
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003985int ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata);
3986
3987/**
3988 * ib_destroy_cq - Destroys the specified kernel CQ.
3989 * @cq: The CQ to destroy.
3990 *
3991 * NOTE: for user cq use ib_destroy_cq_user with valid udata!
3992 */
Leon Romanovsky890ac8d2019-05-20 09:54:21 +03003993static inline void ib_destroy_cq(struct ib_cq *cq)
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003994{
Leon Romanovsky890ac8d2019-05-20 09:54:21 +03003995 ib_destroy_cq_user(cq, NULL);
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03003996}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997
3998/**
3999 * ib_poll_cq - poll a CQ for completion(s)
4000 * @cq:the CQ being polled
4001 * @num_entries:maximum number of completions to return
4002 * @wc:array of at least @num_entries &struct ib_wc where completions
4003 * will be returned
4004 *
4005 * Poll a CQ for (possibly multiple) completions. If the return value
4006 * is < 0, an error occurred. If the return value is >= 0, it is the
4007 * number of completions returned. If the return value is
4008 * non-negative and < num_entries, then the CQ was emptied.
4009 */
4010static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
4011 struct ib_wc *wc)
4012{
Kamal Heib3023a1e2018-12-10 21:09:48 +02004013 return cq->device->ops.poll_cq(cq, num_entries, wc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014}
4015
4016/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 * ib_req_notify_cq - Request completion notification on a CQ.
4018 * @cq: The CQ to generate an event for.
Roland Dreiered23a722007-05-06 21:02:48 -07004019 * @flags:
4020 * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
4021 * to request an event on the next solicited event or next work
4022 * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
4023 * may also be |ed in to request a hint about missed events, as
4024 * described below.
4025 *
4026 * Return Value:
4027 * < 0 means an error occurred while requesting notification
4028 * == 0 means notification was requested successfully, and if
4029 * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
4030 * were missed and it is safe to wait for another event. In
4031 * this case is it guaranteed that any work completions added
4032 * to the CQ since the last CQ poll will trigger a completion
4033 * notification event.
4034 * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
4035 * in. It means that the consumer must poll the CQ again to
4036 * make sure it is empty to avoid missing an event because of a
4037 * race between requesting notification and an entry being
4038 * added to the CQ. This return value means it is possible
4039 * (but not guaranteed) that a work completion has been added
4040 * to the CQ since the last poll without triggering a
4041 * completion notification event.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 */
4043static inline int ib_req_notify_cq(struct ib_cq *cq,
Roland Dreiered23a722007-05-06 21:02:48 -07004044 enum ib_cq_notify_flags flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045{
Kamal Heib3023a1e2018-12-10 21:09:48 +02004046 return cq->device->ops.req_notify_cq(cq, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047}
4048
Yamin Friedmanc7ff8192020-05-27 11:34:53 +03004049struct ib_cq *ib_cq_pool_get(struct ib_device *dev, unsigned int nr_cqe,
4050 int comp_vector_hint,
4051 enum ib_poll_context poll_ctx);
4052
4053void ib_cq_pool_put(struct ib_cq *cq, unsigned int nr_cqe);
4054
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055/**
4056 * ib_req_ncomp_notif - Request completion notification when there are
4057 * at least the specified number of unreaped completions on the CQ.
4058 * @cq: The CQ to generate an event for.
4059 * @wc_cnt: The number of unreaped completions that should be on the
4060 * CQ before an event is generated.
4061 */
4062static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
4063{
Kamal Heib3023a1e2018-12-10 21:09:48 +02004064 return cq->device->ops.req_ncomp_notif ?
4065 cq->device->ops.req_ncomp_notif(cq, wc_cnt) :
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 -ENOSYS;
4067}
4068
4069/**
Ralph Campbell9b513092006-12-12 14:27:41 -08004070 * ib_dma_mapping_error - check a DMA addr for error
4071 * @dev: The device for which the dma_addr was created
4072 * @dma_addr: The DMA address to check
4073 */
4074static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
4075{
Bart Van Assche0957c292017-03-07 22:56:53 +00004076 return dma_mapping_error(dev->dma_device, dma_addr);
Ralph Campbell9b513092006-12-12 14:27:41 -08004077}
4078
4079/**
4080 * ib_dma_map_single - Map a kernel virtual address to DMA address
4081 * @dev: The device for which the dma_addr is to be created
4082 * @cpu_addr: The kernel virtual address
4083 * @size: The size of the region in bytes
4084 * @direction: The direction of the DMA
4085 */
4086static inline u64 ib_dma_map_single(struct ib_device *dev,
4087 void *cpu_addr, size_t size,
4088 enum dma_data_direction direction)
4089{
Bart Van Assche0957c292017-03-07 22:56:53 +00004090 return dma_map_single(dev->dma_device, cpu_addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08004091}
4092
4093/**
4094 * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
4095 * @dev: The device for which the DMA address was created
4096 * @addr: The DMA address
4097 * @size: The size of the region in bytes
4098 * @direction: The direction of the DMA
4099 */
4100static inline void ib_dma_unmap_single(struct ib_device *dev,
4101 u64 addr, size_t size,
4102 enum dma_data_direction direction)
4103{
Bart Van Assche0957c292017-03-07 22:56:53 +00004104 dma_unmap_single(dev->dma_device, addr, size, direction);
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07004105}
4106
Ralph Campbell9b513092006-12-12 14:27:41 -08004107/**
4108 * ib_dma_map_page - Map a physical page to DMA address
4109 * @dev: The device for which the dma_addr is to be created
4110 * @page: The page to be mapped
4111 * @offset: The offset within the page
4112 * @size: The size of the region in bytes
4113 * @direction: The direction of the DMA
4114 */
4115static inline u64 ib_dma_map_page(struct ib_device *dev,
4116 struct page *page,
4117 unsigned long offset,
4118 size_t size,
4119 enum dma_data_direction direction)
4120{
Bart Van Assche0957c292017-03-07 22:56:53 +00004121 return dma_map_page(dev->dma_device, page, offset, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08004122}
4123
4124/**
4125 * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
4126 * @dev: The device for which the DMA address was created
4127 * @addr: The DMA address
4128 * @size: The size of the region in bytes
4129 * @direction: The direction of the DMA
4130 */
4131static inline void ib_dma_unmap_page(struct ib_device *dev,
4132 u64 addr, size_t size,
4133 enum dma_data_direction direction)
4134{
Bart Van Assche0957c292017-03-07 22:56:53 +00004135 dma_unmap_page(dev->dma_device, addr, size, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08004136}
4137
4138/**
4139 * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
4140 * @dev: The device for which the DMA addresses are to be created
4141 * @sg: The array of scatter/gather entries
4142 * @nents: The number of scatter/gather entries
4143 * @direction: The direction of the DMA
4144 */
4145static inline int ib_dma_map_sg(struct ib_device *dev,
4146 struct scatterlist *sg, int nents,
4147 enum dma_data_direction direction)
4148{
Bart Van Assche0957c292017-03-07 22:56:53 +00004149 return dma_map_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08004150}
4151
4152/**
4153 * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
4154 * @dev: The device for which the DMA addresses were created
4155 * @sg: The array of scatter/gather entries
4156 * @nents: The number of scatter/gather entries
4157 * @direction: The direction of the DMA
4158 */
4159static inline void ib_dma_unmap_sg(struct ib_device *dev,
4160 struct scatterlist *sg, int nents,
4161 enum dma_data_direction direction)
4162{
Bart Van Assche0957c292017-03-07 22:56:53 +00004163 dma_unmap_sg(dev->dma_device, sg, nents, direction);
Ralph Campbell9b513092006-12-12 14:27:41 -08004164}
4165
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07004166static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
4167 struct scatterlist *sg, int nents,
4168 enum dma_data_direction direction,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -07004169 unsigned long dma_attrs)
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07004170{
Bart Van Assche0957c292017-03-07 22:56:53 +00004171 return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
4172 dma_attrs);
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07004173}
4174
4175static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
4176 struct scatterlist *sg, int nents,
4177 enum dma_data_direction direction,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -07004178 unsigned long dma_attrs)
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07004179{
Bart Van Assche0957c292017-03-07 22:56:53 +00004180 dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, dma_attrs);
Arthur Kepnercb9fbc52008-04-29 01:00:34 -07004181}
Ralph Campbell9b513092006-12-12 14:27:41 -08004182
4183/**
Bart Van Assche0b5cb332019-01-22 10:25:20 -08004184 * ib_dma_max_seg_size - Return the size limit of a single DMA transfer
4185 * @dev: The device to query
4186 *
4187 * The returned value represents a size in bytes.
4188 */
4189static inline unsigned int ib_dma_max_seg_size(struct ib_device *dev)
4190{
Bart Van Asscheecdfdfd2019-10-25 15:58:27 -07004191 return dma_get_max_seg_size(dev->dma_device);
Bart Van Assche0b5cb332019-01-22 10:25:20 -08004192}
4193
4194/**
Ralph Campbell9b513092006-12-12 14:27:41 -08004195 * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
4196 * @dev: The device for which the DMA address was created
4197 * @addr: The DMA address
4198 * @size: The size of the region in bytes
4199 * @dir: The direction of the DMA
4200 */
4201static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
4202 u64 addr,
4203 size_t size,
4204 enum dma_data_direction dir)
4205{
Bart Van Assche0957c292017-03-07 22:56:53 +00004206 dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08004207}
4208
4209/**
4210 * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
4211 * @dev: The device for which the DMA address was created
4212 * @addr: The DMA address
4213 * @size: The size of the region in bytes
4214 * @dir: The direction of the DMA
4215 */
4216static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
4217 u64 addr,
4218 size_t size,
4219 enum dma_data_direction dir)
4220{
Bart Van Assche0957c292017-03-07 22:56:53 +00004221 dma_sync_single_for_device(dev->dma_device, addr, size, dir);
Ralph Campbell9b513092006-12-12 14:27:41 -08004222}
4223
4224/**
4225 * ib_dma_alloc_coherent - Allocate memory and map it for DMA
4226 * @dev: The device for which the DMA address is requested
4227 * @size: The size of the region to allocate in bytes
4228 * @dma_handle: A pointer for returning the DMA address of the region
4229 * @flag: memory allocator flags
4230 */
4231static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
4232 size_t size,
Bart Van Assched43dbac2017-01-20 13:04:10 -08004233 dma_addr_t *dma_handle,
Ralph Campbell9b513092006-12-12 14:27:41 -08004234 gfp_t flag)
4235{
Bart Van Assche0957c292017-03-07 22:56:53 +00004236 return dma_alloc_coherent(dev->dma_device, size, dma_handle, flag);
Ralph Campbell9b513092006-12-12 14:27:41 -08004237}
4238
4239/**
4240 * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
4241 * @dev: The device for which the DMA addresses were allocated
4242 * @size: The size of the region
4243 * @cpu_addr: the address returned by ib_dma_alloc_coherent()
4244 * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
4245 */
4246static inline void ib_dma_free_coherent(struct ib_device *dev,
4247 size_t size, void *cpu_addr,
Bart Van Assched43dbac2017-01-20 13:04:10 -08004248 dma_addr_t dma_handle)
Ralph Campbell9b513092006-12-12 14:27:41 -08004249{
Bart Van Assche0957c292017-03-07 22:56:53 +00004250 dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
Ralph Campbell9b513092006-12-12 14:27:41 -08004251}
4252
Moni Shoua33006bd2020-01-15 14:43:32 +02004253/* ib_reg_user_mr - register a memory region for virtual addresses from kernel
4254 * space. This function should be called when 'current' is the owning MM.
4255 */
4256struct ib_mr *ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
4257 u64 virt_addr, int mr_access_flags);
4258
Moni Shoua87d8069f2020-01-15 14:43:33 +02004259/* ib_advise_mr - give an advice about an address range in a memory region */
4260int ib_advise_mr(struct ib_pd *pd, enum ib_uverbs_advise_mr_advice advice,
4261 u32 flags, struct ib_sge *sg_list, u32 num_sge);
Ralph Campbell9b513092006-12-12 14:27:41 -08004262/**
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03004263 * ib_dereg_mr_user - Deregisters a memory region and removes it from the
4264 * HCA translation table.
4265 * @mr: The memory region to deregister.
4266 * @udata: Valid user data or NULL for kernel object
4267 *
4268 * This function can fail, if the memory region has memory windows bound to it.
4269 */
4270int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata);
4271
4272/**
4273 * ib_dereg_mr - Deregisters a kernel memory region and removes it from the
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 * HCA translation table.
4275 * @mr: The memory region to deregister.
Shani Michaeli7083e422013-02-06 16:19:12 +00004276 *
4277 * This function can fail, if the memory region has memory windows bound to it.
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03004278 *
4279 * NOTE: for user mr use ib_dereg_mr_user with valid udata!
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 */
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03004281static inline int ib_dereg_mr(struct ib_mr *mr)
4282{
4283 return ib_dereg_mr_user(mr, NULL);
4284}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03004286struct ib_mr *ib_alloc_mr_user(struct ib_pd *pd, enum ib_mr_type mr_type,
4287 u32 max_num_sg, struct ib_udata *udata);
4288
4289static inline struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
4290 enum ib_mr_type mr_type, u32 max_num_sg)
4291{
4292 return ib_alloc_mr_user(pd, mr_type, max_num_sg, NULL);
4293}
Steve Wise00f7ec32008-07-14 23:48:45 -07004294
Israel Rukshin26bc7ea2019-06-11 18:52:39 +03004295struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
4296 u32 max_num_data_sg,
4297 u32 max_num_meta_sg);
4298
Steve Wise00f7ec32008-07-14 23:48:45 -07004299/**
Steve Wise00f7ec32008-07-14 23:48:45 -07004300 * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
4301 * R_Key and L_Key.
4302 * @mr - struct ib_mr pointer to be updated.
4303 * @newkey - new key to be used.
4304 */
4305static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
4306{
4307 mr->lkey = (mr->lkey & 0xffffff00) | newkey;
4308 mr->rkey = (mr->rkey & 0xffffff00) | newkey;
4309}
4310
4311/**
Shani Michaeli7083e422013-02-06 16:19:12 +00004312 * ib_inc_rkey - increments the key portion of the given rkey. Can be used
4313 * for calculating a new rkey for type 2 memory windows.
4314 * @rkey - the rkey to increment.
4315 */
4316static inline u32 ib_inc_rkey(u32 rkey)
4317{
4318 const u32 mask = 0x000000ff;
4319 return ((rkey + 1) & mask) | (rkey & ~mask);
4320}
4321
4322/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 * ib_alloc_fmr - Allocates a unmapped fast memory region.
4324 * @pd: The protection domain associated with the unmapped region.
4325 * @mr_access_flags: Specifies the memory access rights.
4326 * @fmr_attr: Attributes of the unmapped region.
4327 *
4328 * A fast memory region must be mapped before it can be used as part of
4329 * a work request.
4330 */
4331struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
4332 int mr_access_flags,
4333 struct ib_fmr_attr *fmr_attr);
4334
4335/**
4336 * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
4337 * @fmr: The fast memory region to associate with the pages.
4338 * @page_list: An array of physical pages to map to the fast memory region.
4339 * @list_len: The number of pages in page_list.
4340 * @iova: The I/O virtual address to use with the mapped region.
4341 */
4342static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
4343 u64 *page_list, int list_len,
4344 u64 iova)
4345{
Kamal Heib3023a1e2018-12-10 21:09:48 +02004346 return fmr->device->ops.map_phys_fmr(fmr, page_list, list_len, iova);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347}
4348
4349/**
4350 * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
4351 * @fmr_list: A linked list of fast memory regions to unmap.
4352 */
4353int ib_unmap_fmr(struct list_head *fmr_list);
4354
4355/**
4356 * ib_dealloc_fmr - Deallocates a fast memory region.
4357 * @fmr: The fast memory region to deallocate.
4358 */
4359int ib_dealloc_fmr(struct ib_fmr *fmr);
4360
4361/**
4362 * ib_attach_mcast - Attaches the specified QP to a multicast group.
4363 * @qp: QP to attach to the multicast group. The QP must be type
4364 * IB_QPT_UD.
4365 * @gid: Multicast group GID.
4366 * @lid: Multicast group LID in host byte order.
4367 *
4368 * In order to send and receive multicast packets, subnet
4369 * administration must have created the multicast group and configured
4370 * the fabric appropriately. The port associated with the specified
4371 * QP must also be a member of the multicast group.
4372 */
4373int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
4374
4375/**
4376 * ib_detach_mcast - Detaches the specified QP from a multicast group.
4377 * @qp: QP to detach from the multicast group.
4378 * @gid: Multicast group GID.
4379 * @lid: Multicast group LID in host byte order.
4380 */
4381int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
4382
Sean Hefty59991f92011-05-23 17:52:46 -07004383/**
4384 * ib_alloc_xrcd - Allocates an XRC domain.
4385 * @device: The device on which to allocate the XRC domain.
Leon Romanovskyf66c8ba2018-01-28 11:17:19 +02004386 * @caller: Module name for kernel consumers
Sean Hefty59991f92011-05-23 17:52:46 -07004387 */
Leon Romanovskyf66c8ba2018-01-28 11:17:19 +02004388struct ib_xrcd *__ib_alloc_xrcd(struct ib_device *device, const char *caller);
4389#define ib_alloc_xrcd(device) \
4390 __ib_alloc_xrcd((device), KBUILD_MODNAME)
Sean Hefty59991f92011-05-23 17:52:46 -07004391
4392/**
4393 * ib_dealloc_xrcd - Deallocates an XRC domain.
4394 * @xrcd: The XRC domain to deallocate.
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03004395 * @udata: Valid user data or NULL for kernel object
Sean Hefty59991f92011-05-23 17:52:46 -07004396 */
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03004397int ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
Sean Hefty59991f92011-05-23 17:52:46 -07004398
Eli Cohen1c636f82013-10-31 15:26:32 +02004399static inline int ib_check_mr_access(int flags)
4400{
4401 /*
4402 * Local write permission is required if remote write or
4403 * remote atomic permission is also requested.
4404 */
4405 if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
4406 !(flags & IB_ACCESS_LOCAL_WRITE))
4407 return -EINVAL;
4408
Michael Guralnikca95c142020-01-08 20:05:35 +02004409 if (flags & ~IB_ACCESS_SUPPORTED)
4410 return -EINVAL;
4411
Eli Cohen1c636f82013-10-31 15:26:32 +02004412 return 0;
4413}
4414
Jack Morgenstein08bb5582018-05-23 15:30:30 +03004415static inline bool ib_access_writable(int access_flags)
4416{
4417 /*
4418 * We have writable memory backing the MR if any of the following
4419 * access flags are set. "Local write" and "remote write" obviously
4420 * require write access. "Remote atomic" can do things like fetch and
4421 * add, which will modify memory, and "MW bind" can change permissions
4422 * by binding a window.
4423 */
4424 return access_flags &
4425 (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE |
4426 IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND);
4427}
4428
Sagi Grimberg1b01d332014-02-23 14:19:05 +02004429/**
4430 * ib_check_mr_status: lightweight check of MR status.
4431 * This routine may provide status checks on a selected
4432 * ib_mr. first use is for signature status check.
4433 *
4434 * @mr: A memory region.
4435 * @check_mask: Bitmask of which checks to perform from
4436 * ib_mr_status_check enumeration.
4437 * @mr_status: The container of relevant status checks.
4438 * failed checks will be indicated in the status bitmask
4439 * and the relevant info shall be in the error item.
4440 */
4441int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
4442 struct ib_mr_status *mr_status);
4443
Jason Gunthorped79af722019-01-10 14:02:24 -07004444/**
4445 * ib_device_try_get: Hold a registration lock
4446 * device: The device to lock
4447 *
4448 * A device under an active registration lock cannot become unregistered. It
4449 * is only possible to obtain a registration lock on a device that is fully
4450 * registered, otherwise this function returns false.
4451 *
4452 * The registration lock is only necessary for actions which require the
4453 * device to still be registered. Uses that only require the device pointer to
4454 * be valid should use get_device(&ibdev->dev) to hold the memory.
4455 *
4456 */
4457static inline bool ib_device_try_get(struct ib_device *dev)
4458{
4459 return refcount_inc_not_zero(&dev->refcount);
4460}
4461
4462void ib_device_put(struct ib_device *device);
Jason Gunthorpe324e2272019-02-12 21:12:51 -07004463struct ib_device *ib_device_get_by_netdev(struct net_device *ndev,
4464 enum rdma_driver_id driver_id);
4465struct ib_device *ib_device_get_by_name(const char *name,
4466 enum rdma_driver_id driver_id);
Yotam Kenneth9268f722015-07-30 17:50:15 +03004467struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
4468 u16 pkey, const union ib_gid *gid,
4469 const struct sockaddr *addr);
Jason Gunthorpec2261dd2019-02-12 21:12:50 -07004470int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev,
4471 unsigned int port);
4472struct net_device *ib_device_netdev(struct ib_device *dev, u8 port);
4473
Yishai Hadas5fd251c2016-05-23 15:20:48 +03004474struct ib_wq *ib_create_wq(struct ib_pd *pd,
4475 struct ib_wq_init_attr *init_attr);
Shamir Rabinovitchc4367a22019-03-31 19:10:05 +03004476int ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata);
Yishai Hadas5fd251c2016-05-23 15:20:48 +03004477int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
4478 u32 wq_attr_mask);
Yishai Hadas6d397862016-05-23 15:20:51 +03004479struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
4480 struct ib_rwq_ind_table_init_attr*
4481 wq_ind_table_init_attr);
4482int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
Yotam Kenneth9268f722015-07-30 17:50:15 +03004483
Christoph Hellwigff2ba992016-05-03 18:01:04 +02004484int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
Bart Van Assche9aa8b322016-05-12 10:49:15 -07004485 unsigned int *sg_offset, unsigned int page_size);
Max Gurtovoy2cdfcdd2019-06-11 18:52:40 +03004486int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg,
4487 int data_sg_nents, unsigned int *data_sg_offset,
4488 struct scatterlist *meta_sg, int meta_sg_nents,
4489 unsigned int *meta_sg_offset, unsigned int page_size);
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03004490
4491static inline int
Christoph Hellwigff2ba992016-05-03 18:01:04 +02004492ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
Bart Van Assche9aa8b322016-05-12 10:49:15 -07004493 unsigned int *sg_offset, unsigned int page_size)
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03004494{
4495 int n;
4496
Christoph Hellwigff2ba992016-05-03 18:01:04 +02004497 n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03004498 mr->iova = 0;
4499
4500 return n;
4501}
4502
Christoph Hellwigff2ba992016-05-03 18:01:04 +02004503int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
Bart Van Assche9aa8b322016-05-12 10:49:15 -07004504 unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
Sagi Grimberg4c67e2b2015-10-13 19:11:24 +03004505
Steve Wise765d6772016-02-17 08:15:41 -08004506void ib_drain_rq(struct ib_qp *qp);
4507void ib_drain_sq(struct ib_qp *qp);
4508void ib_drain_qp(struct ib_qp *qp);
Moni Shoua850d8fd2016-11-10 11:30:56 +02004509
Yuval Shaiad4186192017-06-14 23:13:34 +03004510int ib_get_eth_speed(struct ib_device *dev, u8 port_num, u8 *speed, u8 *width);
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004511
4512static inline u8 *rdma_ah_retrieve_dmac(struct rdma_ah_attr *attr)
4513{
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004514 if (attr->type == RDMA_AH_ATTR_TYPE_ROCE)
4515 return attr->roce.dmac;
4516 return NULL;
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004517}
4518
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -04004519static inline void rdma_ah_set_dlid(struct rdma_ah_attr *attr, u32 dlid)
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004520{
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004521 if (attr->type == RDMA_AH_ATTR_TYPE_IB)
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -04004522 attr->ib.dlid = (u16)dlid;
4523 else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4524 attr->opa.dlid = dlid;
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004525}
4526
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -04004527static inline u32 rdma_ah_get_dlid(const struct rdma_ah_attr *attr)
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004528{
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004529 if (attr->type == RDMA_AH_ATTR_TYPE_IB)
4530 return attr->ib.dlid;
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -04004531 else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4532 return attr->opa.dlid;
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004533 return 0;
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004534}
4535
4536static inline void rdma_ah_set_sl(struct rdma_ah_attr *attr, u8 sl)
4537{
4538 attr->sl = sl;
4539}
4540
4541static inline u8 rdma_ah_get_sl(const struct rdma_ah_attr *attr)
4542{
4543 return attr->sl;
4544}
4545
4546static inline void rdma_ah_set_path_bits(struct rdma_ah_attr *attr,
4547 u8 src_path_bits)
4548{
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004549 if (attr->type == RDMA_AH_ATTR_TYPE_IB)
4550 attr->ib.src_path_bits = src_path_bits;
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -04004551 else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4552 attr->opa.src_path_bits = src_path_bits;
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004553}
4554
4555static inline u8 rdma_ah_get_path_bits(const struct rdma_ah_attr *attr)
4556{
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004557 if (attr->type == RDMA_AH_ATTR_TYPE_IB)
4558 return attr->ib.src_path_bits;
Dasaratharaman Chandramouli64b46462017-04-29 14:41:30 -04004559 else if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4560 return attr->opa.src_path_bits;
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004561 return 0;
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004562}
4563
Don Hiattd98bb7f2017-08-04 13:54:16 -07004564static inline void rdma_ah_set_make_grd(struct rdma_ah_attr *attr,
4565 bool make_grd)
4566{
4567 if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4568 attr->opa.make_grd = make_grd;
4569}
4570
4571static inline bool rdma_ah_get_make_grd(const struct rdma_ah_attr *attr)
4572{
4573 if (attr->type == RDMA_AH_ATTR_TYPE_OPA)
4574 return attr->opa.make_grd;
4575 return false;
4576}
4577
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004578static inline void rdma_ah_set_port_num(struct rdma_ah_attr *attr, u8 port_num)
4579{
4580 attr->port_num = port_num;
4581}
4582
4583static inline u8 rdma_ah_get_port_num(const struct rdma_ah_attr *attr)
4584{
4585 return attr->port_num;
4586}
4587
4588static inline void rdma_ah_set_static_rate(struct rdma_ah_attr *attr,
4589 u8 static_rate)
4590{
4591 attr->static_rate = static_rate;
4592}
4593
4594static inline u8 rdma_ah_get_static_rate(const struct rdma_ah_attr *attr)
4595{
4596 return attr->static_rate;
4597}
4598
4599static inline void rdma_ah_set_ah_flags(struct rdma_ah_attr *attr,
4600 enum ib_ah_flags flag)
4601{
4602 attr->ah_flags = flag;
4603}
4604
4605static inline enum ib_ah_flags
4606 rdma_ah_get_ah_flags(const struct rdma_ah_attr *attr)
4607{
4608 return attr->ah_flags;
4609}
4610
4611static inline const struct ib_global_route
4612 *rdma_ah_read_grh(const struct rdma_ah_attr *attr)
4613{
4614 return &attr->grh;
4615}
4616
4617/*To retrieve and modify the grh */
4618static inline struct ib_global_route
4619 *rdma_ah_retrieve_grh(struct rdma_ah_attr *attr)
4620{
4621 return &attr->grh;
4622}
4623
4624static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr, void *dgid)
4625{
4626 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
4627
4628 memcpy(grh->dgid.raw, dgid, sizeof(grh->dgid));
4629}
4630
4631static inline void rdma_ah_set_subnet_prefix(struct rdma_ah_attr *attr,
4632 __be64 prefix)
4633{
4634 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
4635
4636 grh->dgid.global.subnet_prefix = prefix;
4637}
4638
4639static inline void rdma_ah_set_interface_id(struct rdma_ah_attr *attr,
4640 __be64 if_id)
4641{
4642 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
4643
4644 grh->dgid.global.interface_id = if_id;
4645}
4646
4647static inline void rdma_ah_set_grh(struct rdma_ah_attr *attr,
4648 union ib_gid *dgid, u32 flow_label,
4649 u8 sgid_index, u8 hop_limit,
4650 u8 traffic_class)
4651{
4652 struct ib_global_route *grh = rdma_ah_retrieve_grh(attr);
4653
4654 attr->ah_flags = IB_AH_GRH;
4655 if (dgid)
4656 grh->dgid = *dgid;
4657 grh->flow_label = flow_label;
4658 grh->sgid_index = sgid_index;
4659 grh->hop_limit = hop_limit;
4660 grh->traffic_class = traffic_class;
Jason Gunthorpe8d9ec9a2018-06-13 10:22:03 +03004661 grh->sgid_attr = NULL;
Dasaratharaman Chandramouli2224c472017-04-29 14:41:27 -04004662}
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004663
Jason Gunthorpe8d9ec9a2018-06-13 10:22:03 +03004664void rdma_destroy_ah_attr(struct rdma_ah_attr *ah_attr);
4665void rdma_move_grh_sgid_attr(struct rdma_ah_attr *attr, union ib_gid *dgid,
4666 u32 flow_label, u8 hop_limit, u8 traffic_class,
4667 const struct ib_gid_attr *sgid_attr);
Jason Gunthorped97099f2018-06-13 10:22:05 +03004668void rdma_copy_ah_attr(struct rdma_ah_attr *dest,
4669 const struct rdma_ah_attr *src);
4670void rdma_replace_ah_attr(struct rdma_ah_attr *old,
4671 const struct rdma_ah_attr *new);
4672void rdma_move_ah_attr(struct rdma_ah_attr *dest, struct rdma_ah_attr *src);
Jason Gunthorpe8d9ec9a2018-06-13 10:22:03 +03004673
Don Hiatt87daac62018-02-01 10:57:03 -08004674/**
4675 * rdma_ah_find_type - Return address handle type.
4676 *
4677 * @dev: Device to be checked
4678 * @port_num: Port number
4679 */
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004680static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev,
Don Hiatt87daac62018-02-01 10:57:03 -08004681 u8 port_num)
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004682{
Parav Pandita6532e72018-01-12 07:58:42 +02004683 if (rdma_protocol_roce(dev, port_num))
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004684 return RDMA_AH_ATTR_TYPE_ROCE;
Don Hiatt87daac62018-02-01 10:57:03 -08004685 if (rdma_protocol_ib(dev, port_num)) {
4686 if (rdma_cap_opa_ah(dev, port_num))
4687 return RDMA_AH_ATTR_TYPE_OPA;
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004688 return RDMA_AH_ATTR_TYPE_IB;
Don Hiatt87daac62018-02-01 10:57:03 -08004689 }
4690
4691 return RDMA_AH_ATTR_TYPE_UNDEFINED;
Dasaratharaman Chandramouli44c58482017-04-29 14:41:29 -04004692}
Hiatt, Don7db20ec2017-06-08 13:37:49 -04004693
Hiatt, Don62ede772017-08-14 14:17:43 -04004694/**
4695 * ib_lid_cpu16 - Return lid in 16bit CPU encoding.
4696 * In the current implementation the only way to get
4697 * get the 32bit lid is from other sources for OPA.
4698 * For IB, lids will always be 16bits so cast the
4699 * value accordingly.
4700 *
4701 * @lid: A 32bit LID
4702 */
4703static inline u16 ib_lid_cpu16(u32 lid)
Hiatt, Don7db20ec2017-06-08 13:37:49 -04004704{
Hiatt, Don62ede772017-08-14 14:17:43 -04004705 WARN_ON_ONCE(lid & 0xFFFF0000);
4706 return (u16)lid;
Hiatt, Don7db20ec2017-06-08 13:37:49 -04004707}
4708
Hiatt, Don62ede772017-08-14 14:17:43 -04004709/**
4710 * ib_lid_be16 - Return lid in 16bit BE encoding.
4711 *
4712 * @lid: A 32bit LID
4713 */
4714static inline __be16 ib_lid_be16(u32 lid)
Hiatt, Don7db20ec2017-06-08 13:37:49 -04004715{
Hiatt, Don62ede772017-08-14 14:17:43 -04004716 WARN_ON_ONCE(lid & 0xFFFF0000);
4717 return cpu_to_be16((u16)lid);
Hiatt, Don7db20ec2017-06-08 13:37:49 -04004718}
Doug Ledford32043832017-08-10 14:31:29 -04004719
Sagi Grimbergc66cd352017-07-13 11:09:41 +03004720/**
4721 * ib_get_vector_affinity - Get the affinity mappings of a given completion
4722 * vector
4723 * @device: the rdma device
4724 * @comp_vector: index of completion vector
4725 *
4726 * Returns NULL on failure, otherwise a corresponding cpu map of the
4727 * completion vector (returns all-cpus map if the device driver doesn't
4728 * implement get_vector_affinity).
4729 */
4730static inline const struct cpumask *
4731ib_get_vector_affinity(struct ib_device *device, int comp_vector)
4732{
4733 if (comp_vector < 0 || comp_vector >= device->num_comp_vectors ||
Kamal Heib3023a1e2018-12-10 21:09:48 +02004734 !device->ops.get_vector_affinity)
Sagi Grimbergc66cd352017-07-13 11:09:41 +03004735 return NULL;
4736
Kamal Heib3023a1e2018-12-10 21:09:48 +02004737 return device->ops.get_vector_affinity(device, comp_vector);
Sagi Grimbergc66cd352017-07-13 11:09:41 +03004738
4739}
4740
Daniel Jurgens32f69e42018-01-04 17:25:36 +02004741/**
4742 * rdma_roce_rescan_device - Rescan all of the network devices in the system
4743 * and add their gids, as needed, to the relevant RoCE devices.
4744 *
4745 * @device: the rdma device
4746 */
4747void rdma_roce_rescan_device(struct ib_device *ibdev);
4748
Jason Gunthorpe8313c102018-11-25 20:51:13 +02004749struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
Yishai Hadas7dc08dc2018-06-17 12:59:59 +03004750
Jason Gunthorpe15a1b4b2018-11-25 20:51:15 +02004751int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs);
Denis Drozdovf6a8a192018-08-14 14:08:51 +03004752
4753struct net_device *rdma_alloc_netdev(struct ib_device *device, u8 port_num,
4754 enum rdma_netdev_t type, const char *name,
4755 unsigned char name_assign_type,
4756 void (*setup)(struct net_device *));
Denis Drozdov5d6b0cb2018-08-14 14:22:35 +03004757
4758int rdma_init_netdev(struct ib_device *device, u8 port_num,
4759 enum rdma_netdev_t type, const char *name,
4760 unsigned char name_assign_type,
4761 void (*setup)(struct net_device *),
4762 struct net_device *netdev);
4763
Parav Panditd4122f52018-10-11 22:31:53 +03004764/**
4765 * rdma_set_device_sysfs_group - Set device attributes group to have
4766 * driver specific sysfs entries at
4767 * for infiniband class.
4768 *
4769 * @device: device pointer for which attributes to be created
4770 * @group: Pointer to group which should be added when device
4771 * is registered with sysfs.
4772 * rdma_set_device_sysfs_group() allows existing drivers to expose one
4773 * group per device to have sysfs attributes.
4774 *
4775 * NOTE: New drivers should not make use of this API; instead new device
4776 * parameter should be exposed via netlink command. This API and mechanism
4777 * exist only for existing drivers.
4778 */
4779static inline void
4780rdma_set_device_sysfs_group(struct ib_device *dev,
4781 const struct attribute_group *group)
4782{
4783 dev->groups[1] = group;
4784}
4785
Parav Pandit54747232018-12-18 14:15:56 +02004786/**
4787 * rdma_device_to_ibdev - Get ib_device pointer from device pointer
4788 *
4789 * @device: device pointer for which ib_device pointer to retrieve
4790 *
4791 * rdma_device_to_ibdev() retrieves ib_device pointer from device.
4792 *
4793 */
4794static inline struct ib_device *rdma_device_to_ibdev(struct device *device)
4795{
Parav Panditcebe5562019-02-26 13:56:11 +02004796 struct ib_core_device *coredev =
4797 container_of(device, struct ib_core_device, dev);
4798
4799 return coredev->owner;
Parav Pandit54747232018-12-18 14:15:56 +02004800}
4801
4802/**
4803 * rdma_device_to_drv_device - Helper macro to reach back to driver's
4804 * ib_device holder structure from device pointer.
4805 *
4806 * NOTE: New drivers should not make use of this API; This API is only for
4807 * existing drivers who have exposed sysfs entries using
4808 * rdma_set_device_sysfs_group().
4809 */
4810#define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member) \
4811 container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member)
Parav Pandit41c61402019-02-26 14:01:46 +02004812
4813bool rdma_dev_access_netns(const struct ib_device *device,
4814 const struct net *net);
Mark Zhangd5665a22020-05-04 08:19:31 +03004815
4816#define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
4817#define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)
4818
4819/**
4820 * rdma_flow_label_to_udp_sport - generate a RoCE v2 UDP src port value based
4821 * on the flow_label
4822 *
4823 * This function will convert the 20 bit flow_label input to a valid RoCE v2
4824 * UDP src port 14 bit value. All RoCE V2 drivers should use this same
4825 * convention.
4826 */
4827static inline u16 rdma_flow_label_to_udp_sport(u32 fl)
4828{
4829 u32 fl_low = fl & 0x03fff, fl_high = fl & 0xFC000;
4830
4831 fl_low ^= fl_high >> 14;
4832 return (u16)(fl_low | IB_ROCE_UDP_ENCAP_VALID_PORT_MIN);
4833}
4834
4835/**
4836 * rdma_calc_flow_label - generate a RDMA symmetric flow label value based on
4837 * local and remote qpn values
4838 *
4839 * This function folded the multiplication results of two qpns, 24 bit each,
4840 * fields, and converts it to a 20 bit results.
4841 *
4842 * This function will create symmetric flow_label value based on the local
4843 * and remote qpn values. this will allow both the requester and responder
4844 * to calculate the same flow_label for a given connection.
4845 *
4846 * This helper function should be used by driver in case the upper layer
4847 * provide a zero flow_label value. This is to improve entropy of RDMA
4848 * traffic in the network.
4849 */
4850static inline u32 rdma_calc_flow_label(u32 lqpn, u32 rqpn)
4851{
4852 u64 v = (u64)lqpn * rqpn;
4853
4854 v ^= v >> 20;
4855 v ^= v >> 40;
4856
4857 return (u32)(v & IB_GRH_FLOWLABEL_MASK);
4858}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859#endif /* IB_VERBS_H */