Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Dreier | 2a1d9b7 | 2005-08-10 23:03:10 -0700 | [diff] [blame] | 7 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
Roland Dreier | f7c6a7b | 2007-03-04 16:15:11 -0800 | [diff] [blame] | 8 | * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | #if !defined(IB_VERBS_H) |
| 40 | #define IB_VERBS_H |
| 41 | |
| 42 | #include <linux/types.h> |
| 43 | #include <linux/device.h> |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 44 | #include <linux/dma-mapping.h> |
Michael S. Tsirkin | 459d6e2 | 2007-02-04 14:11:55 -0800 | [diff] [blame] | 45 | #include <linux/kref.h> |
Dotan Barak | bfb3ea1 | 2007-07-31 16:49:15 +0300 | [diff] [blame] | 46 | #include <linux/list.h> |
| 47 | #include <linux/rwsem.h> |
Tejun Heo | f062671 | 2010-10-19 15:24:36 +0000 | [diff] [blame] | 48 | #include <linux/workqueue.h> |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 49 | #include <linux/irq_poll.h> |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 50 | #include <uapi/linux/if_ether.h> |
Somnath Kotur | c865f24 | 2015-12-23 14:56:51 +0200 | [diff] [blame] | 51 | #include <net/ipv6.h> |
| 52 | #include <net/ip.h> |
Matan Barak | 301a721 | 2015-12-15 20:30:10 +0200 | [diff] [blame] | 53 | #include <linux/string.h> |
| 54 | #include <linux/slab.h> |
Vishwanathapura, Niranjana | 2fc7757 | 2017-04-12 20:29:20 -0700 | [diff] [blame] | 55 | #include <linux/netdevice.h> |
Parav Pandit | 01b6711 | 2018-11-16 03:50:57 +0200 | [diff] [blame] | 56 | #include <linux/refcount.h> |
Eli Cohen | 50174a7 | 2016-03-11 22:58:38 +0200 | [diff] [blame] | 57 | #include <linux/if_link.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 58 | #include <linux/atomic.h> |
Haggai Eran | 882214e | 2014-12-11 17:04:18 +0200 | [diff] [blame] | 59 | #include <linux/mmu_notifier.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 60 | #include <linux/uaccess.h> |
Parav Pandit | 43579b5 | 2017-01-10 00:02:14 +0000 | [diff] [blame] | 61 | #include <linux/cgroup_rdma.h> |
Leon Romanovsky | f631603 | 2019-03-28 15:12:58 +0200 | [diff] [blame] | 62 | #include <linux/irqflags.h> |
| 63 | #include <linux/preempt.h> |
Yamin Friedman | da66297 | 2019-07-08 13:59:03 +0300 | [diff] [blame] | 64 | #include <linux/dim.h> |
Nicolas Dichtel | ea6819e | 2017-03-27 14:20:14 +0200 | [diff] [blame] | 65 | #include <uapi/rdma/ib_user_verbs.h> |
Mark Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 66 | #include <rdma/rdma_counter.h> |
Leon Romanovsky | 02d8883 | 2018-01-28 11:17:20 +0200 | [diff] [blame] | 67 | #include <rdma/restrack.h> |
Max Gurtovoy | 36b1e47 | 2019-06-11 18:52:37 +0300 | [diff] [blame] | 68 | #include <rdma/signature.h> |
Matan Barak | 0ede73b | 2018-03-19 15:02:34 +0200 | [diff] [blame] | 69 | #include <uapi/rdma/rdma_user_ioctl.h> |
Matan Barak | 2eb9bea | 2018-03-28 09:27:45 +0300 | [diff] [blame] | 70 | #include <uapi/rdma/ib_user_ioctl_verbs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 72 | #define IB_FW_VERSION_NAME_MAX ETHTOOL_FWVERS_LEN |
| 73 | |
Jason Gunthorpe | b5231b0 | 2018-09-16 20:48:04 +0300 | [diff] [blame] | 74 | struct ib_umem_odp; |
Jason Gunthorpe | 620d3f8 | 2020-01-08 19:21:59 +0200 | [diff] [blame] | 75 | struct ib_uqp_object; |
Jason Gunthorpe | 9fbe334 | 2020-01-08 19:22:00 +0200 | [diff] [blame] | 76 | struct ib_usrq_object; |
Jason Gunthorpe | e04dd13 | 2020-01-08 19:22:01 +0200 | [diff] [blame] | 77 | struct ib_uwq_object; |
Jason Gunthorpe | b5231b0 | 2018-09-16 20:48:04 +0300 | [diff] [blame] | 78 | |
Tejun Heo | f062671 | 2010-10-19 15:24:36 +0000 | [diff] [blame] | 79 | extern struct workqueue_struct *ib_wq; |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 80 | extern struct workqueue_struct *ib_comp_wq; |
Jack Morgenstein | f794809 | 2018-08-27 08:35:55 +0300 | [diff] [blame] | 81 | extern struct workqueue_struct *ib_comp_unbound_wq; |
Tejun Heo | f062671 | 2010-10-19 15:24:36 +0000 | [diff] [blame] | 82 | |
Jason Gunthorpe | 5bd48c1 | 2020-01-08 19:21:58 +0200 | [diff] [blame] | 83 | struct ib_ucq_object; |
| 84 | |
Gal Pressman | 923abb9 | 2019-05-01 13:48:13 +0300 | [diff] [blame] | 85 | __printf(3, 4) __cold |
| 86 | void ibdev_printk(const char *level, const struct ib_device *ibdev, |
| 87 | const char *format, ...); |
| 88 | __printf(2, 3) __cold |
| 89 | void ibdev_emerg(const struct ib_device *ibdev, const char *format, ...); |
| 90 | __printf(2, 3) __cold |
| 91 | void ibdev_alert(const struct ib_device *ibdev, const char *format, ...); |
| 92 | __printf(2, 3) __cold |
| 93 | void ibdev_crit(const struct ib_device *ibdev, const char *format, ...); |
| 94 | __printf(2, 3) __cold |
| 95 | void ibdev_err(const struct ib_device *ibdev, const char *format, ...); |
| 96 | __printf(2, 3) __cold |
| 97 | void ibdev_warn(const struct ib_device *ibdev, const char *format, ...); |
| 98 | __printf(2, 3) __cold |
| 99 | void ibdev_notice(const struct ib_device *ibdev, const char *format, ...); |
| 100 | __printf(2, 3) __cold |
| 101 | void 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 Pressman | 923abb9 | 2019-05-01 13:48:13 +0300 | [diff] [blame] | 106 | #else |
| 107 | __printf(2, 3) __cold |
| 108 | static inline |
| 109 | void ibdev_dbg(const struct ib_device *ibdev, const char *format, ...) {} |
| 110 | #endif |
| 111 | |
Gal Pressman | 05bb411 | 2019-08-01 20:14:46 +0300 | [diff] [blame] | 112 | #define ibdev_level_ratelimited(ibdev_level, ibdev, fmt, ...) \ |
| 113 | do { \ |
| 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, ...) \ |
| 139 | do { \ |
| 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 |
| 150 | static inline |
| 151 | void ibdev_dbg_ratelimited(const struct ib_device *ibdev, const char *format, ...) {} |
| 152 | #endif |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | union ib_gid { |
| 155 | u8 raw[16]; |
| 156 | struct { |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 157 | __be64 subnet_prefix; |
| 158 | __be64 interface_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } global; |
| 160 | }; |
| 161 | |
Moni Shoua | e26be1b | 2015-07-30 18:33:29 +0300 | [diff] [blame] | 162 | extern union ib_gid zgid; |
| 163 | |
Matan Barak | b39ffa1 | 2015-12-23 14:56:47 +0200 | [diff] [blame] | 164 | enum 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 Barak | 7766a99 | 2015-12-23 14:56:50 +0200 | [diff] [blame] | 168 | IB_GID_TYPE_ROCE_UDP_ENCAP = 1, |
Matan Barak | b39ffa1 | 2015-12-23 14:56:47 +0200 | [diff] [blame] | 169 | IB_GID_TYPE_SIZE |
| 170 | }; |
| 171 | |
Moni Shoua | 7ead4bc | 2016-01-14 17:50:38 +0200 | [diff] [blame] | 172 | #define ROCE_V2_UDP_DPORT 4791 |
Matan Barak | 03db3a2 | 2015-07-30 18:33:26 +0300 | [diff] [blame] | 173 | struct ib_gid_attr { |
Parav Pandit | 943bd98 | 2019-05-02 10:48:07 +0300 | [diff] [blame] | 174 | struct net_device __rcu *ndev; |
Parav Pandit | 598ff6b | 2018-04-01 15:08:21 +0300 | [diff] [blame] | 175 | struct ib_device *device; |
Parav Pandit | b150c38 | 2018-06-05 08:40:15 +0300 | [diff] [blame] | 176 | union ib_gid gid; |
Parav Pandit | 598ff6b | 2018-04-01 15:08:21 +0300 | [diff] [blame] | 177 | enum ib_gid_type gid_type; |
| 178 | u16 index; |
| 179 | u8 port_num; |
Matan Barak | 03db3a2 | 2015-07-30 18:33:26 +0300 | [diff] [blame] | 180 | }; |
| 181 | |
Eli Cohen | a0c1b2a | 2016-03-11 22:58:37 +0200 | [diff] [blame] | 182 | enum { |
| 183 | /* set the local administered indication */ |
| 184 | IB_SA_WELL_KNOWN_GUID = BIT_ULL(57) | 2, |
| 185 | }; |
| 186 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 187 | enum rdma_transport_type { |
| 188 | RDMA_TRANSPORT_IB, |
Upinder Malhi \(umalhi\) | 180771a | 2013-09-10 03:36:59 +0000 | [diff] [blame] | 189 | RDMA_TRANSPORT_IWARP, |
Upinder Malhi | 248567f | 2014-01-09 14:48:19 -0800 | [diff] [blame] | 190 | RDMA_TRANSPORT_USNIC, |
Gal Pressman | f95be3d | 2019-05-05 20:59:21 +0300 | [diff] [blame] | 191 | RDMA_TRANSPORT_USNIC_UDP, |
| 192 | RDMA_TRANSPORT_UNSPECIFIED, |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 193 | }; |
| 194 | |
Michael Wang | 6b90a6d | 2015-05-05 14:50:18 +0200 | [diff] [blame] | 195 | enum rdma_protocol_type { |
| 196 | RDMA_PROTOCOL_IB, |
| 197 | RDMA_PROTOCOL_IBOE, |
| 198 | RDMA_PROTOCOL_IWARP, |
| 199 | RDMA_PROTOCOL_USNIC_UDP |
| 200 | }; |
| 201 | |
Roland Dreier | 8385fd8 | 2014-06-04 10:00:16 -0700 | [diff] [blame] | 202 | __attribute_const__ enum rdma_transport_type |
Jason Gunthorpe | 5d60c11 | 2019-06-13 21:38:17 -0300 | [diff] [blame] | 203 | rdma_node_get_transport(unsigned int node_type); |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 204 | |
Somnath Kotur | c865f24 | 2015-12-23 14:56:51 +0200 | [diff] [blame] | 205 | enum 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 | |
| 212 | static 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 Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 222 | static inline enum rdma_network_type |
| 223 | rdma_gid_attr_network_type(const struct ib_gid_attr *attr) |
Somnath Kotur | c865f24 | 2015-12-23 14:56:51 +0200 | [diff] [blame] | 224 | { |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 225 | if (attr->gid_type == IB_GID_TYPE_IB) |
Somnath Kotur | c865f24 | 2015-12-23 14:56:51 +0200 | [diff] [blame] | 226 | return RDMA_NETWORK_IB; |
| 227 | |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 228 | if (ipv6_addr_v4mapped((struct in6_addr *)&attr->gid)) |
Somnath Kotur | c865f24 | 2015-12-23 14:56:51 +0200 | [diff] [blame] | 229 | return RDMA_NETWORK_IPV4; |
| 230 | else |
| 231 | return RDMA_NETWORK_IPV6; |
| 232 | } |
| 233 | |
Eli Cohen | a3f5ada | 2010-09-27 17:51:10 -0700 | [diff] [blame] | 234 | enum rdma_link_layer { |
| 235 | IB_LINK_LAYER_UNSPECIFIED, |
| 236 | IB_LINK_LAYER_INFINIBAND, |
| 237 | IB_LINK_LAYER_ETHERNET, |
| 238 | }; |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | enum ib_device_cap_flags { |
Leon Romanovsky | 7ca0bc5 | 2015-12-20 12:16:09 +0200 | [diff] [blame] | 241 | 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 Romanovsky | 78b57f9 | 2017-08-17 15:50:37 +0300 | [diff] [blame] | 250 | /* Not in use, former INIT_TYPE = (1 << 9),*/ |
Leon Romanovsky | 7ca0bc5 | 2015-12-20 12:16:09 +0200 | [diff] [blame] | 251 | 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 Hellwig | b1adc71 | 2015-12-23 19:12:45 +0100 | [diff] [blame] | 256 | |
| 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 Romanovsky | 7ca0bc5 | 2015-12-20 12:16:09 +0200 | [diff] [blame] | 264 | IB_DEVICE_LOCAL_DMA_LKEY = (1 << 15), |
Leon Romanovsky | 78b57f9 | 2017-08-17 15:50:37 +0300 | [diff] [blame] | 265 | /* Reserved, old SEND_W_INV = (1 << 16),*/ |
Leon Romanovsky | 7ca0bc5 | 2015-12-20 12:16:09 +0200 | [diff] [blame] | 266 | IB_DEVICE_MEM_WINDOW = (1 << 17), |
Eli Cohen | e0605d9 | 2008-01-30 18:30:57 +0200 | [diff] [blame] | 267 | /* |
| 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 Romanovsky | 7ca0bc5 | 2015-12-20 12:16:09 +0200 | [diff] [blame] | 274 | IB_DEVICE_UD_IP_CSUM = (1 << 18), |
| 275 | IB_DEVICE_UD_TSO = (1 << 19), |
| 276 | IB_DEVICE_XRC = (1 << 20), |
Christoph Hellwig | b1adc71 | 2015-12-23 19:12:45 +0100 | [diff] [blame] | 277 | |
| 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 Romanovsky | 7ca0bc5 | 2015-12-20 12:16:09 +0200 | [diff] [blame] | 287 | 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 Osherovich | ebaaee2 | 2017-01-18 15:39:54 +0200 | [diff] [blame] | 292 | /* Deprecated. Please use IB_RAW_PACKET_CAP_IP_CSUM. */ |
Leon Romanovsky | 7ca0bc5 | 2015-12-20 12:16:09 +0200 | [diff] [blame] | 293 | IB_DEVICE_RAW_IP_CSUM = (1 << 26), |
Leon Romanovsky | 8a06ce5 | 2015-12-20 12:16:10 +0200 | [diff] [blame] | 294 | /* |
| 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 Romanovsky | 78b57f9 | 2017-08-17 15:50:37 +0300 | [diff] [blame] | 300 | IB_DEVICE_CROSS_CHANNEL = (1 << 27), |
Leon Romanovsky | 7ca0bc5 | 2015-12-20 12:16:09 +0200 | [diff] [blame] | 301 | IB_DEVICE_MANAGED_FLOW_STEERING = (1 << 29), |
Israel Rukshin | c0a6cbb | 2019-06-11 18:52:50 +0300 | [diff] [blame] | 302 | IB_DEVICE_INTEGRITY_HANDOVER = (1 << 30), |
Max Gurtovoy | 47355b3 | 2016-06-06 19:34:39 +0300 | [diff] [blame] | 303 | IB_DEVICE_ON_DEMAND_PAGING = (1ULL << 31), |
Sagi Grimberg | f5aa915 | 2016-02-29 19:07:32 +0200 | [diff] [blame] | 304 | IB_DEVICE_SG_GAPS_REG = (1ULL << 32), |
Max Gurtovoy | c7e162a | 2016-06-06 19:34:40 +0300 | [diff] [blame] | 305 | IB_DEVICE_VIRTUAL_FUNCTION = (1ULL << 33), |
Noa Osherovich | ebaaee2 | 2017-01-18 15:39:54 +0200 | [diff] [blame] | 306 | /* Deprecated. Please use IB_RAW_PACKET_CAP_SCATTER_FCS. */ |
Max Gurtovoy | c7e162a | 2016-06-06 19:34:40 +0300 | [diff] [blame] | 307 | IB_DEVICE_RAW_SCATTER_FCS = (1ULL << 34), |
Gary Leshner | 7f90a5a | 2020-05-11 12:06:07 -0400 | [diff] [blame] | 308 | IB_DEVICE_RDMA_NETDEV_OPA = (1ULL << 35), |
Noa Osherovich | e1d2e88 | 2017-10-29 13:59:44 +0200 | [diff] [blame] | 309 | /* The device supports padding incoming writes to cacheline. */ |
| 310 | IB_DEVICE_PCI_WRITE_END_PADDING = (1ULL << 36), |
Steve Wise | 3856ec4 | 2019-02-15 11:03:53 -0800 | [diff] [blame] | 311 | IB_DEVICE_ALLOW_USER_UNREG = (1ULL << 37), |
Sagi Grimberg | 1b01d33 | 2014-02-23 14:19:05 +0200 | [diff] [blame] | 312 | }; |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | enum ib_atomic_cap { |
| 315 | IB_ATOMIC_NONE, |
| 316 | IB_ATOMIC_HCA, |
| 317 | IB_ATOMIC_GLOB |
| 318 | }; |
| 319 | |
Sagi Grimberg | 860f10a | 2014-12-11 17:04:16 +0200 | [diff] [blame] | 320 | enum ib_odp_general_cap_bits { |
Artemy Kovalyov | 25bf14d | 2017-01-18 16:58:06 +0200 | [diff] [blame] | 321 | IB_ODP_SUPPORT = 1 << 0, |
| 322 | IB_ODP_SUPPORT_IMPLICIT = 1 << 1, |
Sagi Grimberg | 860f10a | 2014-12-11 17:04:16 +0200 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | enum 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 Shoua | da82334 | 2019-01-22 08:48:41 +0200 | [diff] [blame] | 331 | IB_ODP_SUPPORT_SRQ_RECV = 1 << 5, |
Sagi Grimberg | 860f10a | 2014-12-11 17:04:16 +0200 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | struct 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 Shoua | 52a72e2 | 2019-01-22 08:48:42 +0200 | [diff] [blame] | 340 | uint32_t xrc_odp_caps; |
Sagi Grimberg | 860f10a | 2014-12-11 17:04:16 +0200 | [diff] [blame] | 341 | } per_transport_caps; |
| 342 | }; |
| 343 | |
Yishai Hadas | ccf2056 | 2016-08-28 11:28:43 +0300 | [diff] [blame] | 344 | struct 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 Kovalyov | 6938fc1e | 2017-08-17 15:52:03 +0300 | [diff] [blame] | 354 | enum ib_tm_cap_flags { |
Danit Goldberg | 89705e9 | 2019-07-05 19:21:57 +0300 | [diff] [blame] | 355 | /* Support tag matching with rendezvous offload for RC transport */ |
| 356 | IB_TM_CAP_RNDV_RC = 1 << 0, |
Artemy Kovalyov | 6938fc1e | 2017-08-17 15:52:03 +0300 | [diff] [blame] | 357 | }; |
| 358 | |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 359 | struct ib_tm_caps { |
Artemy Kovalyov | 6938fc1e | 2017-08-17 15:52:03 +0300 | [diff] [blame] | 360 | /* 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 Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 372 | struct ib_cq_init_attr { |
| 373 | unsigned int cqe; |
Dan Carpenter | a9018ad | 2019-10-11 16:34:19 +0300 | [diff] [blame] | 374 | u32 comp_vector; |
Matan Barak | bcf4c1e | 2015-06-11 16:35:20 +0300 | [diff] [blame] | 375 | u32 flags; |
| 376 | }; |
| 377 | |
Yonatan Cohen | 869ddcf | 2017-11-13 10:51:13 +0200 | [diff] [blame] | 378 | enum ib_cq_attr_mask { |
| 379 | IB_CQ_MODERATE = 1 << 0, |
| 380 | }; |
| 381 | |
Yonatan Cohen | 18bd907 | 2017-11-13 10:51:16 +0200 | [diff] [blame] | 382 | struct ib_cq_caps { |
| 383 | u16 max_cq_moderation_count; |
| 384 | u16 max_cq_moderation_period; |
| 385 | }; |
| 386 | |
Ariel Levkovich | be934cc | 2018-04-05 18:53:25 +0300 | [diff] [blame] | 387 | struct ib_dm_mr_attr { |
| 388 | u64 length; |
| 389 | u64 offset; |
| 390 | u32 access_flags; |
| 391 | }; |
| 392 | |
Ariel Levkovich | bee76d7 | 2018-04-05 18:53:24 +0300 | [diff] [blame] | 393 | struct ib_dm_alloc_attr { |
| 394 | u64 length; |
| 395 | u32 alignment; |
| 396 | u32 flags; |
| 397 | }; |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | struct ib_device_attr { |
| 400 | u64 fw_ver; |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 401 | __be64 sys_image_guid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | 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 Romanovsky | fb532d6 | 2016-02-23 10:25:25 +0200 | [diff] [blame] | 409 | u64 device_cap_flags; |
Steve Wise | 33023fb | 2018-06-18 08:05:26 -0700 | [diff] [blame] | 410 | int max_send_sge; |
| 411 | int max_recv_sge; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | 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 Sokolovsky | 5e80ba8 | 2010-04-14 17:23:01 +0300 | [diff] [blame] | 423 | enum ib_atomic_cap masked_atomic_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | 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 Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 438 | unsigned int max_fast_reg_page_list_len; |
Max Gurtovoy | 62e3c37 | 2019-06-11 18:52:43 +0300 | [diff] [blame] | 439 | unsigned int max_pi_fast_reg_page_list_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | u16 max_pkeys; |
| 441 | u8 local_ca_ack_delay; |
Sagi Grimberg | 1b01d33 | 2014-02-23 14:19:05 +0200 | [diff] [blame] | 442 | int sig_prot_cap; |
| 443 | int sig_guard_cap; |
Sagi Grimberg | 860f10a | 2014-12-11 17:04:16 +0200 | [diff] [blame] | 444 | struct ib_odp_caps odp_caps; |
Matan Barak | 24306dc | 2015-06-11 16:35:24 +0300 | [diff] [blame] | 445 | uint64_t timestamp_mask; |
| 446 | uint64_t hca_core_clock; /* in KHZ */ |
Yishai Hadas | ccf2056 | 2016-08-28 11:28:43 +0300 | [diff] [blame] | 447 | struct ib_rss_caps rss_caps; |
| 448 | u32 max_wq_type_rq; |
Noa Osherovich | ebaaee2 | 2017-01-18 15:39:54 +0200 | [diff] [blame] | 449 | u32 raw_packet_caps; /* Use ib_raw_packet_caps enum */ |
Leon Romanovsky | 78b1beb | 2017-09-24 21:46:29 +0300 | [diff] [blame] | 450 | struct ib_tm_caps tm_caps; |
Yonatan Cohen | 18bd907 | 2017-11-13 10:51:16 +0200 | [diff] [blame] | 451 | struct ib_cq_caps cq_caps; |
Ariel Levkovich | 1d8eeb9 | 2018-04-05 18:53:23 +0300 | [diff] [blame] | 452 | u64 max_dm_size; |
Yamin Friedman | 00bd143 | 2019-10-07 16:59:32 +0300 | [diff] [blame] | 453 | /* Max entries for sgl for optimized performance per READ */ |
| 454 | u32 max_sgl_rd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | }; |
| 456 | |
| 457 | enum 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 Wan | 6d72344 | 2020-05-11 12:06:18 -0400 | [diff] [blame] | 465 | enum opa_mtu { |
| 466 | OPA_MTU_8192 = 6, |
| 467 | OPA_MTU_10240 = 7 |
| 468 | }; |
| 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | static 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, Ram | d3f4aad | 2016-12-26 08:40:57 +0200 | [diff] [blame] | 482 | static 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 Wan | 6d72344 | 2020-05-11 12:06:18 -0400 | [diff] [blame] | 496 | static 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 | |
| 508 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | enum 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 Heib | 72a7720 | 2019-08-07 13:31:35 +0300 | [diff] [blame] | 527 | enum 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | enum ib_port_width { |
| 538 | IB_WIDTH_1X = 1, |
Michael Guralnik | dbabf68 | 2018-12-09 11:49:49 +0200 | [diff] [blame] | 539 | IB_WIDTH_2X = 16, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | IB_WIDTH_4X = 2, |
| 541 | IB_WIDTH_8X = 4, |
| 542 | IB_WIDTH_12X = 8 |
| 543 | }; |
| 544 | |
| 545 | static inline int ib_width_enum_to_int(enum ib_port_width width) |
| 546 | { |
| 547 | switch (width) { |
| 548 | case IB_WIDTH_1X: return 1; |
Michael Guralnik | dbabf68 | 2018-12-09 11:49:49 +0200 | [diff] [blame] | 549 | case IB_WIDTH_2X: return 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | 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 Gerlitz | 2e96691 | 2012-02-28 18:49:50 +0200 | [diff] [blame] | 557 | enum 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 Osherovich | 12113a3 | 2017-04-20 20:53:31 +0300 | [diff] [blame] | 563 | IB_SPEED_EDR = 32, |
| 564 | IB_SPEED_HDR = 64 |
Or Gerlitz | 2e96691 | 2012-02-28 18:49:50 +0200 | [diff] [blame] | 565 | }; |
| 566 | |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 567 | /** |
| 568 | * struct rdma_hw_stats |
Mark Bloch | e945130 | 2018-03-27 15:51:05 +0300 | [diff] [blame] | 569 | * @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 Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 572 | * @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 | */ |
| 586 | struct rdma_hw_stats { |
Mark Bloch | e945130 | 2018-03-27 15:51:05 +0300 | [diff] [blame] | 587 | struct mutex lock; /* Protect lifespan and values[] */ |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 588 | unsigned long timestamp; |
| 589 | unsigned long lifespan; |
| 590 | const char * const *names; |
| 591 | int num_counters; |
| 592 | u64 value[]; |
Steve Wise | 7f624d0 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 593 | }; |
| 594 | |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 595 | #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 | */ |
| 603 | static 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 Wise | 7f624d0 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 608 | |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 609 | 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 Wise | 7f624d0 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 616 | |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 617 | return stats; |
| 618 | } |
| 619 | |
Steve Wise | 7f624d0 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 620 | |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 621 | /* 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 Weiny | 65995fe | 2015-06-06 14:38:32 -0400 | [diff] [blame] | 630 | #define RDMA_CORE_CAP_OPA_MAD 0x00000020 |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 631 | |
| 632 | /* Address format 0x000FF000 */ |
| 633 | #define RDMA_CORE_CAP_AF_IB 0x00001000 |
| 634 | #define RDMA_CORE_CAP_ETH_AH 0x00002000 |
Dasaratharaman Chandramouli | 94d595c | 2017-03-20 19:38:09 -0400 | [diff] [blame] | 635 | #define RDMA_CORE_CAP_OPA_AH 0x00004000 |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 636 | #define RDMA_CORE_CAP_IB_GRH_REQUIRED 0x00008000 |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 637 | |
| 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 Barak | 7766a99 | 2015-12-23 14:56:50 +0200 | [diff] [blame] | 642 | #define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000 |
Or Gerlitz | aa773bd | 2017-01-24 13:02:35 +0200 | [diff] [blame] | 643 | #define RDMA_CORE_CAP_PROT_RAW_PACKET 0x01000000 |
Or Gerlitz | ce1e055 | 2017-01-24 13:02:38 +0200 | [diff] [blame] | 644 | #define RDMA_CORE_CAP_PROT_USNIC 0x02000000 |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 645 | |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 646 | #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 Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 650 | #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 Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 659 | | RDMA_CORE_CAP_AF_IB \ |
| 660 | | RDMA_CORE_CAP_ETH_AH) |
Matan Barak | 7766a99 | 2015-12-23 14:56:50 +0200 | [diff] [blame] | 661 | #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 Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 667 | #define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \ |
| 668 | | RDMA_CORE_CAP_IW_CM) |
Ira Weiny | 65995fe | 2015-06-06 14:38:32 -0400 | [diff] [blame] | 669 | #define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \ |
| 670 | | RDMA_CORE_CAP_OPA_MAD) |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 671 | |
Or Gerlitz | aa773bd | 2017-01-24 13:02:35 +0200 | [diff] [blame] | 672 | #define RDMA_CORE_PORT_RAW_PACKET (RDMA_CORE_CAP_PROT_RAW_PACKET) |
| 673 | |
Or Gerlitz | ce1e055 | 2017-01-24 13:02:38 +0200 | [diff] [blame] | 674 | #define RDMA_CORE_PORT_USNIC (RDMA_CORE_CAP_PROT_USNIC) |
| 675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | struct ib_port_attr { |
Eli Cohen | fad61ad | 2016-03-11 22:58:36 +0200 | [diff] [blame] | 677 | u64 subnet_prefix; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | enum ib_port_state state; |
| 679 | enum ib_mtu max_mtu; |
| 680 | enum ib_mtu active_mtu; |
Kaike Wan | 6d72344 | 2020-05-11 12:06:18 -0400 | [diff] [blame] | 681 | u32 phys_mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | int gid_tbl_len; |
Jason Gunthorpe | 2f944c0 | 2018-07-04 15:57:48 +0300 | [diff] [blame] | 683 | unsigned int ip_gids:1; |
| 684 | /* This is the value from PortInfo CapabilityMask, defined by IBA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | 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 Chandramouli | db58540 | 2017-06-08 13:37:48 -0400 | [diff] [blame] | 690 | u32 sm_lid; |
Dasaratharaman Chandramouli | 582faf3 | 2017-06-08 13:37:47 -0400 | [diff] [blame] | 691 | u32 lid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | 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 Guralnik | 1e8f43b | 2018-12-09 11:49:48 +0200 | [diff] [blame] | 700 | u16 port_cap_flags2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | enum ib_device_modify_flags { |
Roland Dreier | c5bcbbb | 2006-02-02 09:47:14 -0800 | [diff] [blame] | 704 | IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0, |
| 705 | IB_DEVICE_MODIFY_NODE_DESC = 1 << 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | }; |
| 707 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 708 | #define IB_DEVICE_NODE_DESC_MAX 64 |
| 709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | struct ib_device_modify { |
| 711 | u64 sys_image_guid; |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 712 | char node_desc[IB_DEVICE_NODE_DESC_MAX]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | }; |
| 714 | |
| 715 | enum ib_port_modify_flags { |
| 716 | IB_PORT_SHUTDOWN = 1, |
| 717 | IB_PORT_INIT_TYPE = (1<<2), |
Vishwanathapura, Niranjana | cb49366 | 2017-06-01 17:04:02 -0700 | [diff] [blame] | 718 | IB_PORT_RESET_QKEY_CNTR = (1<<3), |
| 719 | IB_PORT_OPA_MASK_CHG = (1<<4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | }; |
| 721 | |
| 722 | struct ib_port_modify { |
| 723 | u32 set_port_cap_mask; |
| 724 | u32 clr_port_cap_mask; |
| 725 | u8 init_type; |
| 726 | }; |
| 727 | |
| 728 | enum 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 Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 742 | IB_EVENT_SM_CHANGE, |
| 743 | IB_EVENT_SRQ_ERR, |
| 744 | IB_EVENT_SRQ_LIMIT_REACHED, |
Leonid Arsh | 63942c9 | 2006-06-17 20:37:35 -0700 | [diff] [blame] | 745 | IB_EVENT_QP_LAST_WQE_REACHED, |
Or Gerlitz | 761d90e | 2011-06-15 14:39:29 +0000 | [diff] [blame] | 746 | IB_EVENT_CLIENT_REREGISTER, |
| 747 | IB_EVENT_GID_CHANGE, |
Yishai Hadas | f213c05 | 2016-05-23 15:20:49 +0300 | [diff] [blame] | 748 | IB_EVENT_WQ_FATAL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | }; |
| 750 | |
Bart Van Assche | db7489e | 2015-08-03 10:01:52 -0700 | [diff] [blame] | 751 | const char *__attribute_const__ ib_event_msg(enum ib_event_type event); |
Sagi Grimberg | 2b1b5b6 | 2015-05-18 13:40:28 +0300 | [diff] [blame] | 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | struct ib_event { |
| 754 | struct ib_device *device; |
| 755 | union { |
| 756 | struct ib_cq *cq; |
| 757 | struct ib_qp *qp; |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 758 | struct ib_srq *srq; |
Yishai Hadas | f213c05 | 2016-05-23 15:20:49 +0300 | [diff] [blame] | 759 | struct ib_wq *wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | u8 port_num; |
| 761 | } element; |
| 762 | enum ib_event_type event; |
| 763 | }; |
| 764 | |
| 765 | struct 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 | |
| 778 | struct ib_global_route { |
Jason Gunthorpe | 8d9ec9a | 2018-06-13 10:22:03 +0300 | [diff] [blame] | 779 | const struct ib_gid_attr *sgid_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | union ib_gid dgid; |
| 781 | u32 flow_label; |
| 782 | u8 sgid_index; |
| 783 | u8 hop_limit; |
| 784 | u8 traffic_class; |
| 785 | }; |
| 786 | |
Hal Rosenstock | 513789e | 2005-07-27 11:45:34 -0700 | [diff] [blame] | 787 | struct ib_grh { |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 788 | __be32 version_tclass_flow; |
| 789 | __be16 paylen; |
Hal Rosenstock | 513789e | 2005-07-27 11:45:34 -0700 | [diff] [blame] | 790 | u8 next_hdr; |
| 791 | u8 hop_limit; |
| 792 | union ib_gid sgid; |
| 793 | union ib_gid dgid; |
| 794 | }; |
| 795 | |
Somnath Kotur | c865f24 | 2015-12-23 14:56:51 +0200 | [diff] [blame] | 796 | union 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 Hiatt | 7dafbab | 2017-05-12 09:19:55 -0700 | [diff] [blame] | 807 | #define IB_QPN_MASK 0xFFFFFF |
| 808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | enum { |
| 810 | IB_MULTICAST_QPN = 0xffffff |
| 811 | }; |
| 812 | |
Harvey Harrison | f3a7c66 | 2009-02-14 22:58:35 -0800 | [diff] [blame] | 813 | #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF) |
Dennis Dalessandro | b4e6439 | 2016-01-06 10:04:31 -0800 | [diff] [blame] | 814 | #define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000) |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | enum ib_ah_flags { |
| 817 | IB_AH_GRH = 1 |
| 818 | }; |
| 819 | |
Jack Morgenstein | bf6a9e3 | 2006-04-10 09:43:47 -0700 | [diff] [blame] | 820 | enum 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 Apfelbaum | 71eeba1 | 2011-10-05 14:21:47 +0300 | [diff] [blame] | 830 | 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 Guralnik | a5a5d19 | 2018-12-09 11:49:50 +0200 | [diff] [blame] | 838 | 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 Morgenstein | bf6a9e3 | 2006-04-10 09:43:47 -0700 | [diff] [blame] | 843 | }; |
| 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 Dreier | 8385fd8 | 2014-06-04 10:00:16 -0700 | [diff] [blame] | 851 | __attribute_const__ int ib_rate_to_mult(enum ib_rate rate); |
Jack Morgenstein | bf6a9e3 | 2006-04-10 09:43:47 -0700 | [diff] [blame] | 852 | |
| 853 | /** |
Marcel Apfelbaum | 71eeba1 | 2011-10-05 14:21:47 +0300 | [diff] [blame] | 854 | * 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 Dreier | 8385fd8 | 2014-06-04 10:00:16 -0700 | [diff] [blame] | 858 | __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate); |
Marcel Apfelbaum | 71eeba1 | 2011-10-05 14:21:47 +0300 | [diff] [blame] | 859 | |
Sagi Grimberg | 17cd3a2 | 2014-02-23 14:19:04 +0200 | [diff] [blame] | 860 | |
| 861 | /** |
Sagi Grimberg | 9bee178 | 2015-07-30 10:32:35 +0300 | [diff] [blame] | 862 | * enum ib_mr_type - memory region type |
| 863 | * @IB_MR_TYPE_MEM_REG: memory region that is used for |
| 864 | * normal registration |
Sagi Grimberg | f5aa915 | 2016-02-29 19:07:32 +0200 | [diff] [blame] | 865 | * @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 Gurtovoy | a0bc099 | 2019-06-11 18:52:38 +0300 | [diff] [blame] | 869 | * @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 Rukshin | 26bc7ea | 2019-06-11 18:52:39 +0300 | [diff] [blame] | 875 | * @IB_MR_TYPE_INTEGRITY: memory region that is used for |
| 876 | * data integrity operations |
Sagi Grimberg | 17cd3a2 | 2014-02-23 14:19:04 +0200 | [diff] [blame] | 877 | */ |
Sagi Grimberg | 9bee178 | 2015-07-30 10:32:35 +0300 | [diff] [blame] | 878 | enum ib_mr_type { |
| 879 | IB_MR_TYPE_MEM_REG, |
Sagi Grimberg | f5aa915 | 2016-02-29 19:07:32 +0200 | [diff] [blame] | 880 | IB_MR_TYPE_SG_GAPS, |
Max Gurtovoy | a0bc099 | 2019-06-11 18:52:38 +0300 | [diff] [blame] | 881 | IB_MR_TYPE_DM, |
| 882 | IB_MR_TYPE_USER, |
| 883 | IB_MR_TYPE_DMA, |
Israel Rukshin | 26bc7ea | 2019-06-11 18:52:39 +0300 | [diff] [blame] | 884 | IB_MR_TYPE_INTEGRITY, |
Sagi Grimberg | 17cd3a2 | 2014-02-23 14:19:04 +0200 | [diff] [blame] | 885 | }; |
| 886 | |
Sagi Grimberg | 1b01d33 | 2014-02-23 14:19:05 +0200 | [diff] [blame] | 887 | enum 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 | */ |
| 899 | struct ib_mr_status { |
| 900 | u32 fail_status; |
| 901 | struct ib_sig_err sig_err; |
| 902 | }; |
| 903 | |
Marcel Apfelbaum | 71eeba1 | 2011-10-05 14:21:47 +0300 | [diff] [blame] | 904 | /** |
Jack Morgenstein | bf6a9e3 | 2006-04-10 09:43:47 -0700 | [diff] [blame] | 905 | * 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 Dreier | 8385fd8 | 2014-06-04 10:00:16 -0700 | [diff] [blame] | 909 | __attribute_const__ enum ib_rate mult_to_ib_rate(int mult); |
Jack Morgenstein | bf6a9e3 | 2006-04-10 09:43:47 -0700 | [diff] [blame] | 910 | |
Maor Gottlieb | fa5d010 | 2020-04-30 22:21:42 +0300 | [diff] [blame] | 911 | struct rdma_ah_init_attr { |
| 912 | struct rdma_ah_attr *ah_attr; |
| 913 | u32 flags; |
Maor Gottlieb | 51aab12 | 2020-04-30 22:21:44 +0300 | [diff] [blame] | 914 | struct net_device *xmit_slave; |
Maor Gottlieb | fa5d010 | 2020-04-30 22:21:42 +0300 | [diff] [blame] | 915 | }; |
| 916 | |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 917 | enum rdma_ah_attr_type { |
Don Hiatt | 87daac6 | 2018-02-01 10:57:03 -0800 | [diff] [blame] | 918 | RDMA_AH_ATTR_TYPE_UNDEFINED, |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 919 | RDMA_AH_ATTR_TYPE_IB, |
| 920 | RDMA_AH_ATTR_TYPE_ROCE, |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 921 | RDMA_AH_ATTR_TYPE_OPA, |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 922 | }; |
| 923 | |
| 924 | struct ib_ah_attr { |
| 925 | u16 dlid; |
| 926 | u8 src_path_bits; |
| 927 | }; |
| 928 | |
| 929 | struct roce_ah_attr { |
| 930 | u8 dmac[ETH_ALEN]; |
| 931 | }; |
| 932 | |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 933 | struct opa_ah_attr { |
| 934 | u32 dlid; |
| 935 | u8 src_path_bits; |
Don Hiatt | d98bb7f | 2017-08-04 13:54:16 -0700 | [diff] [blame] | 936 | bool make_grd; |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 937 | }; |
| 938 | |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 939 | struct rdma_ah_attr { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | struct ib_global_route grh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | u8 sl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | u8 static_rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | u8 port_num; |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 944 | 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 Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 949 | struct opa_ah_attr opa; |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 950 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | }; |
| 952 | |
| 953 | enum 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 Assche | db7489e | 2015-08-03 10:01:52 -0700 | [diff] [blame] | 978 | const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status); |
Sagi Grimberg | 2b1b5b6 | 2015-05-18 13:40:28 +0300 | [diff] [blame] | 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | enum 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 Cohen | c93570f | 2008-04-16 21:09:27 -0700 | [diff] [blame] | 986 | IB_WC_LSO, |
Steve Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 987 | IB_WC_LOCAL_INV, |
Sagi Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 988 | IB_WC_REG_MR, |
Vladimir Sokolovsky | 5e80ba8 | 2010-04-14 17:23:01 +0300 | [diff] [blame] | 989 | IB_WC_MASKED_COMP_SWAP, |
| 990 | IB_WC_MASKED_FETCH_ADD, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | /* |
| 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 | |
| 999 | enum ib_wc_flags { |
| 1000 | IB_WC_GRH = 1, |
Steve Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 1001 | IB_WC_WITH_IMM = (1<<1), |
| 1002 | IB_WC_WITH_INVALIDATE = (1<<2), |
Or Gerlitz | d927d50 | 2012-01-11 19:03:51 +0200 | [diff] [blame] | 1003 | IB_WC_IP_CSUM_OK = (1<<3), |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 1004 | IB_WC_WITH_SMAC = (1<<4), |
| 1005 | IB_WC_WITH_VLAN = (1<<5), |
Somnath Kotur | c865f24 | 2015-12-23 14:56:51 +0200 | [diff] [blame] | 1006 | IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | }; |
| 1008 | |
| 1009 | struct ib_wc { |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 1010 | union { |
| 1011 | u64 wr_id; |
| 1012 | struct ib_cqe *wr_cqe; |
| 1013 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | enum ib_wc_status status; |
| 1015 | enum ib_wc_opcode opcode; |
| 1016 | u32 vendor_err; |
| 1017 | u32 byte_len; |
Michael S. Tsirkin | 062dbb6 | 2006-12-31 21:09:42 +0200 | [diff] [blame] | 1018 | struct ib_qp *qp; |
Steve Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 1019 | union { |
| 1020 | __be32 imm_data; |
| 1021 | u32 invalidate_rkey; |
| 1022 | } ex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | u32 src_qp; |
Bodong Wang | cd2a6e7 | 2018-01-12 07:58:41 +0200 | [diff] [blame] | 1024 | u32 slid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | int wc_flags; |
| 1026 | u16 pkey_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | u8 sl; |
| 1028 | u8 dlid_path_bits; |
| 1029 | u8 port_num; /* valid only for DR SMPs on switches */ |
Matan Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 1030 | u8 smac[ETH_ALEN]; |
| 1031 | u16 vlan_id; |
Somnath Kotur | c865f24 | 2015-12-23 14:56:51 +0200 | [diff] [blame] | 1032 | u8 network_hdr_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | }; |
| 1034 | |
Roland Dreier | ed23a72 | 2007-05-06 21:02:48 -0700 | [diff] [blame] | 1035 | enum 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | }; |
| 1041 | |
Sean Hefty | 96104ed | 2011-05-23 16:31:36 -0700 | [diff] [blame] | 1042 | enum ib_srq_type { |
Yishai Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1043 | IB_SRQT_BASIC = IB_UVERBS_SRQT_BASIC, |
| 1044 | IB_SRQT_XRC = IB_UVERBS_SRQT_XRC, |
| 1045 | IB_SRQT_TM = IB_UVERBS_SRQT_TM, |
Sean Hefty | 96104ed | 2011-05-23 16:31:36 -0700 | [diff] [blame] | 1046 | }; |
| 1047 | |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 1048 | static inline bool ib_srq_has_cq(enum ib_srq_type srq_type) |
| 1049 | { |
Artemy Kovalyov | 9c2c849 | 2017-08-17 15:52:05 +0300 | [diff] [blame] | 1050 | return srq_type == IB_SRQT_XRC || |
| 1051 | srq_type == IB_SRQT_TM; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 1052 | } |
| 1053 | |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 1054 | enum ib_srq_attr_mask { |
| 1055 | IB_SRQ_MAX_WR = 1 << 0, |
| 1056 | IB_SRQ_LIMIT = 1 << 1, |
| 1057 | }; |
| 1058 | |
| 1059 | struct ib_srq_attr { |
| 1060 | u32 max_wr; |
| 1061 | u32 max_sge; |
| 1062 | u32 srq_limit; |
| 1063 | }; |
| 1064 | |
| 1065 | struct ib_srq_init_attr { |
| 1066 | void (*event_handler)(struct ib_event *, void *); |
| 1067 | void *srq_context; |
| 1068 | struct ib_srq_attr attr; |
Sean Hefty | 96104ed | 2011-05-23 16:31:36 -0700 | [diff] [blame] | 1069 | enum ib_srq_type srq_type; |
Sean Hefty | 418d513 | 2011-05-23 19:42:29 -0700 | [diff] [blame] | 1070 | |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 1071 | struct { |
| 1072 | struct ib_cq *cq; |
| 1073 | union { |
| 1074 | struct { |
| 1075 | struct ib_xrcd *xrcd; |
| 1076 | } xrc; |
Artemy Kovalyov | 9c2c849 | 2017-08-17 15:52:05 +0300 | [diff] [blame] | 1077 | |
| 1078 | struct { |
| 1079 | u32 max_num_tags; |
| 1080 | } tag_matching; |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 1081 | }; |
Sean Hefty | 418d513 | 2011-05-23 19:42:29 -0700 | [diff] [blame] | 1082 | } ext; |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 1083 | }; |
| 1084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | struct 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 Hellwig | a060b56 | 2016-05-03 18:01:09 +0200 | [diff] [blame] | 1091 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | }; |
| 1099 | |
| 1100 | enum ib_sig_type { |
| 1101 | IB_SIGNAL_ALL_WR, |
| 1102 | IB_SIGNAL_REQ_WR |
| 1103 | }; |
| 1104 | |
| 1105 | enum 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 Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1114 | IB_QPT_RC = IB_UVERBS_QPT_RC, |
| 1115 | IB_QPT_UC = IB_UVERBS_QPT_UC, |
| 1116 | IB_QPT_UD = IB_UVERBS_QPT_UD, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | IB_QPT_RAW_IPV6, |
Sean Hefty | b42b63c | 2011-05-23 19:59:25 -0700 | [diff] [blame] | 1118 | IB_QPT_RAW_ETHERTYPE, |
Yishai Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1119 | 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 Morgenstein | 0134f16 | 2013-07-07 17:25:52 +0300 | [diff] [blame] | 1122 | IB_QPT_MAX, |
Yishai Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1123 | IB_QPT_DRIVER = IB_UVERBS_QPT_DRIVER, |
Jack Morgenstein | 0134f16 | 2013-07-07 17:25:52 +0300 | [diff] [blame] | 1124 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | }; |
| 1139 | |
Eli Cohen | b846f25 | 2008-04-16 21:09:27 -0700 | [diff] [blame] | 1140 | enum ib_qp_create_flags { |
Ron Livne | 47ee1b9 | 2008-07-14 23:48:48 -0700 | [diff] [blame] | 1141 | IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0, |
Yishai Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1142 | IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = |
| 1143 | IB_UVERBS_QP_CREATE_BLOCK_MULTICAST_LOOPBACK, |
Leon Romanovsky | 8a06ce5 | 2015-12-20 12:16:10 +0200 | [diff] [blame] | 1144 | IB_QP_CREATE_CROSS_CHANNEL = 1 << 2, |
| 1145 | IB_QP_CREATE_MANAGED_SEND = 1 << 3, |
| 1146 | IB_QP_CREATE_MANAGED_RECV = 1 << 4, |
Matan Barak | 90f1d1b | 2013-11-07 15:25:12 +0200 | [diff] [blame] | 1147 | IB_QP_CREATE_NETIF_QP = 1 << 5, |
Israel Rukshin | c0a6cbb | 2019-06-11 18:52:50 +0300 | [diff] [blame] | 1148 | IB_QP_CREATE_INTEGRITY_EN = 1 << 6, |
Gary Leshner | 7f90a5a | 2020-05-11 12:06:07 -0400 | [diff] [blame] | 1149 | IB_QP_CREATE_NETDEV_USE = 1 << 7, |
Yishai Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1150 | 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 Hadas | 02984cc | 2017-06-08 16:15:06 +0300 | [diff] [blame] | 1154 | IB_QP_CREATE_SOURCE_QPN = 1 << 10, |
Yishai Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1155 | IB_QP_CREATE_PCI_WRITE_END_PADDING = |
| 1156 | IB_UVERBS_QP_CREATE_PCI_WRITE_END_PADDING, |
Jack Morgenstein | d2b5706 | 2012-08-03 08:40:37 +0000 | [diff] [blame] | 1157 | /* 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 Cohen | b846f25 | 2008-04-16 21:09:27 -0700 | [diff] [blame] | 1160 | }; |
| 1161 | |
Yishai Hadas | 73c40c6 | 2013-08-01 18:49:53 +0300 | [diff] [blame] | 1162 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | struct ib_qp_init_attr { |
Chuck Lever | eb93c82e | 2018-09-04 11:45:20 -0400 | [diff] [blame] | 1168 | /* Consumer's event_handler callback must not block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | void (*event_handler)(struct ib_event *, void *); |
Chuck Lever | eb93c82e | 2018-09-04 11:45:20 -0400 | [diff] [blame] | 1170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | void *qp_context; |
| 1172 | struct ib_cq *send_cq; |
| 1173 | struct ib_cq *recv_cq; |
| 1174 | struct ib_srq *srq; |
Sean Hefty | b42b63c | 2011-05-23 19:59:25 -0700 | [diff] [blame] | 1175 | struct ib_xrcd *xrcd; /* XRC TGT QPs only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | struct ib_qp_cap cap; |
| 1177 | enum ib_sig_type sq_sig_type; |
| 1178 | enum ib_qp_type qp_type; |
Nathan Chancellor | b56511c | 2018-09-24 12:57:16 -0700 | [diff] [blame] | 1179 | u32 create_flags; |
Christoph Hellwig | a060b56 | 2016-05-03 18:01:09 +0200 | [diff] [blame] | 1180 | |
| 1181 | /* |
| 1182 | * Only needed for special QP types, or when using the RW API. |
| 1183 | */ |
| 1184 | u8 port_num; |
Yishai Hadas | a9017e2 | 2016-05-23 15:20:54 +0300 | [diff] [blame] | 1185 | struct ib_rwq_ind_table *rwq_ind_tbl; |
Yishai Hadas | 02984cc | 2017-06-08 16:15:06 +0300 | [diff] [blame] | 1186 | u32 source_qpn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | }; |
| 1188 | |
Sean Hefty | 0e0ec7e | 2011-08-08 15:31:51 -0700 | [diff] [blame] | 1189 | struct 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | enum 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 | |
| 1231 | enum 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 Barak | dd5f03b | 2013-12-12 18:03:11 +0200 | [diff] [blame] | 1252 | IB_QP_DEST_QPN = (1<<20), |
Matan Barak | aa744cc | 2015-10-15 18:38:53 +0300 | [diff] [blame] | 1253 | IB_QP_RESERVED1 = (1<<21), |
| 1254 | IB_QP_RESERVED2 = (1<<22), |
| 1255 | IB_QP_RESERVED3 = (1<<23), |
| 1256 | IB_QP_RESERVED4 = (1<<24), |
Bodong Wang | 528e5a1 | 2016-12-01 13:43:14 +0200 | [diff] [blame] | 1257 | IB_QP_RATE_LIMIT = (1<<25), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | }; |
| 1259 | |
| 1260 | enum 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 | |
| 1270 | enum ib_mig_state { |
| 1271 | IB_MIG_MIGRATED, |
| 1272 | IB_MIG_REARM, |
| 1273 | IB_MIG_ARMED |
| 1274 | }; |
| 1275 | |
Shani Michaeli | 7083e42 | 2013-02-06 16:19:12 +0000 | [diff] [blame] | 1276 | enum ib_mw_type { |
| 1277 | IB_MW_TYPE_1 = 1, |
| 1278 | IB_MW_TYPE_2 = 2 |
| 1279 | }; |
| 1280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | struct 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 Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 1292 | struct rdma_ah_attr ah_attr; |
| 1293 | struct rdma_ah_attr alt_ah_attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | 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 Wang | 528e5a1 | 2016-12-01 13:43:14 +0200 | [diff] [blame] | 1307 | u32 rate_limit; |
Maor Gottlieb | 51aab12 | 2020-04-30 22:21:44 +0300 | [diff] [blame] | 1308 | struct net_device *xmit_slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | }; |
| 1310 | |
| 1311 | enum ib_wr_opcode { |
Jason Gunthorpe | 9a59739 | 2018-08-14 15:33:02 -0700 | [diff] [blame] | 1312 | /* 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 Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 1331 | IB_WR_REG_MR_INTEGRITY, |
Jason Gunthorpe | 9a59739 | 2018-08-14 15:33:02 -0700 | [diff] [blame] | 1332 | |
Jack Morgenstein | 0134f16 | 2013-07-07 17:25:52 +0300 | [diff] [blame] | 1333 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | }; |
| 1347 | |
| 1348 | enum ib_send_flags { |
| 1349 | IB_SEND_FENCE = 1, |
| 1350 | IB_SEND_SIGNALED = (1<<1), |
| 1351 | IB_SEND_SOLICITED = (1<<2), |
Eli Cohen | e0605d9 | 2008-01-30 18:30:57 +0200 | [diff] [blame] | 1352 | IB_SEND_INLINE = (1<<3), |
Jack Morgenstein | 0134f16 | 2013-07-07 17:25:52 +0300 | [diff] [blame] | 1353 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | }; |
| 1359 | |
| 1360 | struct ib_sge { |
| 1361 | u64 addr; |
| 1362 | u32 length; |
| 1363 | u32 lkey; |
| 1364 | }; |
| 1365 | |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 1366 | struct ib_cqe { |
| 1367 | void (*done)(struct ib_cq *cq, struct ib_wc *wc); |
| 1368 | }; |
| 1369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | struct ib_send_wr { |
| 1371 | struct ib_send_wr *next; |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 1372 | union { |
| 1373 | u64 wr_id; |
| 1374 | struct ib_cqe *wr_cqe; |
| 1375 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | struct ib_sge *sg_list; |
| 1377 | int num_sge; |
| 1378 | enum ib_wr_opcode opcode; |
| 1379 | int send_flags; |
Roland Dreier | 0f39cf3 | 2008-04-16 21:09:32 -0700 | [diff] [blame] | 1380 | union { |
| 1381 | __be32 imm_data; |
| 1382 | u32 invalidate_rkey; |
| 1383 | } ex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | }; |
| 1385 | |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 1386 | struct ib_rdma_wr { |
| 1387 | struct ib_send_wr wr; |
| 1388 | u64 remote_addr; |
| 1389 | u32 rkey; |
| 1390 | }; |
| 1391 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 1392 | static inline const struct ib_rdma_wr *rdma_wr(const struct ib_send_wr *wr) |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 1393 | { |
| 1394 | return container_of(wr, struct ib_rdma_wr, wr); |
| 1395 | } |
| 1396 | |
| 1397 | struct 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 Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 1407 | static inline const struct ib_atomic_wr *atomic_wr(const struct ib_send_wr *wr) |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 1408 | { |
| 1409 | return container_of(wr, struct ib_atomic_wr, wr); |
| 1410 | } |
| 1411 | |
| 1412 | struct 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 Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 1424 | static inline const struct ib_ud_wr *ud_wr(const struct ib_send_wr *wr) |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 1425 | { |
| 1426 | return container_of(wr, struct ib_ud_wr, wr); |
| 1427 | } |
| 1428 | |
Sagi Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 1429 | struct ib_reg_wr { |
| 1430 | struct ib_send_wr wr; |
| 1431 | struct ib_mr *mr; |
| 1432 | u32 key; |
| 1433 | int access; |
| 1434 | }; |
| 1435 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 1436 | static inline const struct ib_reg_wr *reg_wr(const struct ib_send_wr *wr) |
Sagi Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 1437 | { |
| 1438 | return container_of(wr, struct ib_reg_wr, wr); |
| 1439 | } |
| 1440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | struct ib_recv_wr { |
| 1442 | struct ib_recv_wr *next; |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 1443 | union { |
| 1444 | u64 wr_id; |
| 1445 | struct ib_cqe *wr_cqe; |
| 1446 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | struct ib_sge *sg_list; |
| 1448 | int num_sge; |
| 1449 | }; |
| 1450 | |
| 1451 | enum ib_access_flags { |
Jason Gunthorpe | 4fca037 | 2018-07-11 16:20:44 -0600 | [diff] [blame] | 1452 | 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 Guralnik | 2233c66 | 2020-01-08 20:05:38 +0200 | [diff] [blame] | 1460 | IB_ACCESS_RELAXED_ORDERING = IB_UVERBS_ACCESS_RELAXED_ORDERING, |
Jason Gunthorpe | 4fca037 | 2018-07-11 16:20:44 -0600 | [diff] [blame] | 1461 | |
Michael Guralnik | 68d384b | 2020-01-08 20:05:36 +0200 | [diff] [blame] | 1462 | IB_ACCESS_OPTIONAL = IB_UVERBS_ACCESS_OPTIONAL_RANGE, |
| 1463 | IB_ACCESS_SUPPORTED = |
| 1464 | ((IB_ACCESS_HUGETLB << 1) - 1) | IB_ACCESS_OPTIONAL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | }; |
| 1466 | |
Christoph Hellwig | b7d3e0a | 2015-12-23 19:12:47 +0100 | [diff] [blame] | 1467 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | enum ib_mr_rereg_flags { |
| 1472 | IB_MR_REREG_TRANS = 1, |
| 1473 | IB_MR_REREG_PD = (1<<1), |
Matan Barak | 7e6edb9 | 2014-07-31 11:01:28 +0300 | [diff] [blame] | 1474 | IB_MR_REREG_ACCESS = (1<<2), |
| 1475 | IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | }; |
| 1477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | struct ib_fmr_attr { |
| 1479 | int max_pages; |
| 1480 | int max_maps; |
Or Gerlitz | d36f34a | 2006-02-02 10:43:45 -0800 | [diff] [blame] | 1481 | u8 page_shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | }; |
| 1483 | |
Haggai Eran | 882214e | 2014-12-11 17:04:18 +0200 | [diff] [blame] | 1484 | struct ib_umem; |
| 1485 | |
Matan Barak | 3832125 | 2017-04-04 13:31:42 +0300 | [diff] [blame] | 1486 | enum rdma_remove_reason { |
Yishai Hadas | 1c77483 | 2018-06-20 17:11:39 +0300 | [diff] [blame] | 1487 | /* |
| 1488 | * Userspace requested uobject deletion or initial try |
| 1489 | * to remove uobject via cleanup. Call could fail |
| 1490 | */ |
Matan Barak | 3832125 | 2017-04-04 13:31:42 +0300 | [diff] [blame] | 1491 | 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 Gunthorpe | 87ad80a | 2018-07-25 21:40:12 -0600 | [diff] [blame] | 1496 | /* uobj is being cleaned-up before being committed */ |
| 1497 | RDMA_REMOVE_ABORT, |
Jason Gunthorpe | 0ac8903 | 2020-05-19 10:27:05 +0300 | [diff] [blame] | 1498 | /* |
| 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 Barak | 3832125 | 2017-04-04 13:31:42 +0300 | [diff] [blame] | 1503 | }; |
| 1504 | |
Parav Pandit | 43579b5 | 2017-01-10 00:02:14 +0000 | [diff] [blame] | 1505 | struct ib_rdmacg_object { |
| 1506 | #ifdef CONFIG_CGROUP_RDMA |
| 1507 | struct rdma_cgroup *cg; /* owner rdma cgroup */ |
| 1508 | #endif |
| 1509 | }; |
| 1510 | |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1511 | struct ib_ucontext { |
| 1512 | struct ib_device *device; |
Matan Barak | 771addf | 2017-04-04 13:31:41 +0300 | [diff] [blame] | 1513 | struct ib_uverbs_file *ufile; |
Jason Gunthorpe | e951747 | 2018-07-10 20:55:19 -0600 | [diff] [blame] | 1514 | /* |
| 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 Romanovsky | 6ceb633 | 2018-09-03 20:18:03 +0300 | [diff] [blame] | 1519 | bool closing; |
Shachar Raindel | 8ada2c1 | 2014-12-11 17:04:17 +0200 | [diff] [blame] | 1520 | |
Yishai Hadas | 1c77483 | 2018-06-20 17:11:39 +0300 | [diff] [blame] | 1521 | bool cleanup_retryable; |
Matan Barak | 3832125 | 2017-04-04 13:31:42 +0300 | [diff] [blame] | 1522 | |
Parav Pandit | 43579b5 | 2017-01-10 00:02:14 +0000 | [diff] [blame] | 1523 | struct ib_rdmacg_object cg_obj; |
Leon Romanovsky | 6061521 | 2018-11-28 13:16:43 +0200 | [diff] [blame] | 1524 | /* |
| 1525 | * Implementation details of the RDMA core, don't use in drivers: |
| 1526 | */ |
| 1527 | struct rdma_restrack_entry res; |
Michal Kalderon | 3411f9f | 2019-10-30 11:44:11 +0200 | [diff] [blame] | 1528 | struct xarray mmap_xa; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1529 | }; |
| 1530 | |
| 1531 | struct ib_uobject { |
| 1532 | u64 user_handle; /* handle given to us by userspace */ |
Jason Gunthorpe | 6a5e9c8 | 2018-07-04 11:32:07 +0300 | [diff] [blame] | 1533 | /* ufile & ucontext owning this object */ |
| 1534 | struct ib_uverbs_file *ufile; |
| 1535 | /* FIXME, save memory: ufile->context == context */ |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1536 | struct ib_ucontext *context; /* associated user context */ |
Roland Dreier | 9ead190 | 2006-06-17 20:44:49 -0700 | [diff] [blame] | 1537 | void *object; /* containing object */ |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1538 | struct list_head list; /* link to context's list */ |
Parav Pandit | 43579b5 | 2017-01-10 00:02:14 +0000 | [diff] [blame] | 1539 | struct ib_rdmacg_object cg_obj; /* rdmacg object */ |
Roland Dreier | b3d636b | 2008-04-16 21:01:06 -0700 | [diff] [blame] | 1540 | int id; /* index into kernel idr */ |
Roland Dreier | 9ead190 | 2006-06-17 20:44:49 -0700 | [diff] [blame] | 1541 | struct kref ref; |
Matan Barak | 3832125 | 2017-04-04 13:31:42 +0300 | [diff] [blame] | 1542 | atomic_t usecnt; /* protects exclusive access */ |
Mike Marciniszyn | d144da8 | 2015-11-02 12:13:25 -0500 | [diff] [blame] | 1543 | struct rcu_head rcu; /* kfree_rcu() overhead */ |
Matan Barak | 3832125 | 2017-04-04 13:31:42 +0300 | [diff] [blame] | 1544 | |
Jason Gunthorpe | 6b0d08f | 2018-08-09 20:14:37 -0600 | [diff] [blame] | 1545 | const struct uverbs_api_object *uapi_object; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1546 | }; |
| 1547 | |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1548 | struct ib_udata { |
Yann Droneaud | 309243e | 2013-12-11 23:01:44 +0100 | [diff] [blame] | 1549 | const void __user *inbuf; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1550 | void __user *outbuf; |
| 1551 | size_t inlen; |
| 1552 | size_t outlen; |
| 1553 | }; |
| 1554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | struct ib_pd { |
Jason Gunthorpe | 96249d7 | 2015-08-05 14:14:45 -0600 | [diff] [blame] | 1556 | u32 local_dma_lkey; |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 1557 | u32 flags; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1558 | struct ib_device *device; |
| 1559 | struct ib_uobject *uobject; |
| 1560 | atomic_t usecnt; /* count all resources */ |
Christoph Hellwig | 50d4633 | 2016-09-05 12:56:16 +0200 | [diff] [blame] | 1561 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 1562 | u32 unsafe_global_rkey; |
| 1563 | |
Christoph Hellwig | 50d4633 | 2016-09-05 12:56:16 +0200 | [diff] [blame] | 1564 | /* |
| 1565 | * Implementation details of the RDMA core, don't use in drivers: |
| 1566 | */ |
| 1567 | struct ib_mr *__internal_mr; |
Leon Romanovsky | 02d8883 | 2018-01-28 11:17:20 +0200 | [diff] [blame] | 1568 | struct rdma_restrack_entry res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | }; |
| 1570 | |
Sean Hefty | 59991f9 | 2011-05-23 17:52:46 -0700 | [diff] [blame] | 1571 | struct ib_xrcd { |
| 1572 | struct ib_device *device; |
Sean Hefty | d3d72d9 | 2011-05-26 23:06:44 -0700 | [diff] [blame] | 1573 | atomic_t usecnt; /* count all exposed resources */ |
Sean Hefty | 53d0bd1 | 2011-05-24 08:33:46 -0700 | [diff] [blame] | 1574 | struct inode *inode; |
Sean Hefty | d3d72d9 | 2011-05-26 23:06:44 -0700 | [diff] [blame] | 1575 | |
| 1576 | struct mutex tgt_qp_mutex; |
| 1577 | struct list_head tgt_qp_list; |
Sean Hefty | 59991f9 | 2011-05-23 17:52:46 -0700 | [diff] [blame] | 1578 | }; |
| 1579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | struct ib_ah { |
| 1581 | struct ib_device *device; |
| 1582 | struct ib_pd *pd; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1583 | struct ib_uobject *uobject; |
Jason Gunthorpe | 1a1f460 | 2018-06-13 10:22:08 +0300 | [diff] [blame] | 1584 | const struct ib_gid_attr *sgid_attr; |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 1585 | enum rdma_ah_attr_type type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | }; |
| 1587 | |
| 1588 | typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context); |
| 1589 | |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 1590 | enum ib_poll_context { |
Jack Morgenstein | f794809 | 2018-08-27 08:35:55 +0300 | [diff] [blame] | 1591 | IB_POLL_SOFTIRQ, /* poll from softirq context */ |
| 1592 | IB_POLL_WORKQUEUE, /* poll from workqueue */ |
| 1593 | IB_POLL_UNBOUND_WORKQUEUE, /* poll from unbound workqueue */ |
Yamin Friedman | c7ff819 | 2020-05-27 11:34:53 +0300 | [diff] [blame^] | 1594 | IB_POLL_LAST_POOL_TYPE = IB_POLL_UNBOUND_WORKQUEUE, |
| 1595 | |
| 1596 | IB_POLL_DIRECT, /* caller context, no hw completions */ |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 1597 | }; |
| 1598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | struct ib_cq { |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1600 | struct ib_device *device; |
Jason Gunthorpe | 5bd48c1 | 2020-01-08 19:21:58 +0200 | [diff] [blame] | 1601 | struct ib_ucq_object *uobject; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1602 | ib_comp_handler comp_handler; |
| 1603 | void (*event_handler)(struct ib_event *, void *); |
Dotan Barak | 4deccd6 | 2008-07-14 23:48:44 -0700 | [diff] [blame] | 1604 | void *cq_context; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1605 | int cqe; |
Yamin Friedman | c7ff819 | 2020-05-27 11:34:53 +0300 | [diff] [blame^] | 1606 | unsigned int cqe_used; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1607 | atomic_t usecnt; /* count number of work queues */ |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 1608 | enum ib_poll_context poll_ctx; |
| 1609 | struct ib_wc *wc; |
Yamin Friedman | c7ff819 | 2020-05-27 11:34:53 +0300 | [diff] [blame^] | 1610 | struct list_head pool_entry; |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 1611 | union { |
| 1612 | struct irq_poll iop; |
| 1613 | struct work_struct work; |
| 1614 | }; |
Jack Morgenstein | f794809 | 2018-08-27 08:35:55 +0300 | [diff] [blame] | 1615 | struct workqueue_struct *comp_wq; |
Yamin Friedman | da66297 | 2019-07-08 13:59:03 +0300 | [diff] [blame] | 1616 | struct dim *dim; |
Chuck Lever | 3e5901c | 2019-12-18 15:18:15 -0500 | [diff] [blame] | 1617 | |
| 1618 | /* updated only by trace points */ |
| 1619 | ktime_t timestamp; |
Yamin Friedman | 3446cbd | 2020-05-27 11:34:52 +0300 | [diff] [blame] | 1620 | u8 interrupt:1; |
| 1621 | u8 shared:1; |
Yamin Friedman | c7ff819 | 2020-05-27 11:34:53 +0300 | [diff] [blame^] | 1622 | unsigned int comp_vector; |
Chuck Lever | 3e5901c | 2019-12-18 15:18:15 -0500 | [diff] [blame] | 1623 | |
Leon Romanovsky | 02d8883 | 2018-01-28 11:17:20 +0200 | [diff] [blame] | 1624 | /* |
| 1625 | * Implementation details of the RDMA core, don't use in drivers: |
| 1626 | */ |
| 1627 | struct rdma_restrack_entry res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | }; |
| 1629 | |
| 1630 | struct ib_srq { |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 1631 | struct ib_device *device; |
| 1632 | struct ib_pd *pd; |
Jason Gunthorpe | 9fbe334 | 2020-01-08 19:22:00 +0200 | [diff] [blame] | 1633 | struct ib_usrq_object *uobject; |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 1634 | void (*event_handler)(struct ib_event *, void *); |
| 1635 | void *srq_context; |
Sean Hefty | 96104ed | 2011-05-23 16:31:36 -0700 | [diff] [blame] | 1636 | enum ib_srq_type srq_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | atomic_t usecnt; |
Sean Hefty | 418d513 | 2011-05-23 19:42:29 -0700 | [diff] [blame] | 1638 | |
Artemy Kovalyov | 1a56ff6 | 2017-08-17 15:52:04 +0300 | [diff] [blame] | 1639 | struct { |
| 1640 | struct ib_cq *cq; |
| 1641 | union { |
| 1642 | struct { |
| 1643 | struct ib_xrcd *xrcd; |
| 1644 | u32 srq_num; |
| 1645 | } xrc; |
| 1646 | }; |
Sean Hefty | 418d513 | 2011-05-23 19:42:29 -0700 | [diff] [blame] | 1647 | } ext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | }; |
| 1649 | |
Noa Osherovich | ebaaee2 | 2017-01-18 15:39:54 +0200 | [diff] [blame] | 1650 | enum 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 Gottlieb | 7d9336d | 2017-05-30 10:29:10 +0300 | [diff] [blame] | 1660 | /* 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 Osherovich | ebaaee2 | 2017-01-18 15:39:54 +0200 | [diff] [blame] | 1664 | }; |
| 1665 | |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 1666 | enum ib_wq_type { |
Yishai Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1667 | IB_WQT_RQ = IB_UVERBS_WQT_RQ, |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 1668 | }; |
| 1669 | |
| 1670 | enum ib_wq_state { |
| 1671 | IB_WQS_RESET, |
| 1672 | IB_WQS_RDY, |
| 1673 | IB_WQS_ERR |
| 1674 | }; |
| 1675 | |
| 1676 | struct ib_wq { |
| 1677 | struct ib_device *device; |
Jason Gunthorpe | e04dd13 | 2020-01-08 19:22:01 +0200 | [diff] [blame] | 1678 | struct ib_uwq_object *uobject; |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 1679 | 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 Osherovich | 10bac72 | 2017-01-18 15:39:55 +0200 | [diff] [blame] | 1689 | enum ib_wq_flags { |
Yishai Hadas | 175ba58 | 2020-05-19 10:27:08 +0300 | [diff] [blame] | 1690 | 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 Osherovich | 10bac72 | 2017-01-18 15:39:55 +0200 | [diff] [blame] | 1695 | }; |
| 1696 | |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 1697 | struct 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 Osherovich | 10bac72 | 2017-01-18 15:39:55 +0200 | [diff] [blame] | 1704 | u32 create_flags; /* Use enum ib_wq_flags */ |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 1705 | }; |
| 1706 | |
| 1707 | enum ib_wq_attr_mask { |
Noa Osherovich | 10bac72 | 2017-01-18 15:39:55 +0200 | [diff] [blame] | 1708 | IB_WQ_STATE = 1 << 0, |
| 1709 | IB_WQ_CUR_STATE = 1 << 1, |
| 1710 | IB_WQ_FLAGS = 1 << 2, |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 1711 | }; |
| 1712 | |
| 1713 | struct ib_wq_attr { |
| 1714 | enum ib_wq_state wq_state; |
| 1715 | enum ib_wq_state curr_wq_state; |
Noa Osherovich | 10bac72 | 2017-01-18 15:39:55 +0200 | [diff] [blame] | 1716 | u32 flags; /* Use enum ib_wq_flags */ |
| 1717 | u32 flags_mask; /* Use enum ib_wq_flags */ |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 1718 | }; |
| 1719 | |
Yishai Hadas | 6d39786 | 2016-05-23 15:20:51 +0300 | [diff] [blame] | 1720 | struct 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 | |
| 1729 | struct 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 Jurgens | d291f1a | 2017-05-19 15:48:52 +0300 | [diff] [blame] | 1735 | enum port_pkey_state { |
| 1736 | IB_PORT_PKEY_NOT_VALID = 0, |
| 1737 | IB_PORT_PKEY_VALID = 1, |
| 1738 | IB_PORT_PKEY_LISTED = 2, |
| 1739 | }; |
| 1740 | |
| 1741 | struct ib_qp_security; |
| 1742 | |
| 1743 | struct 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 | |
| 1752 | struct ib_ports_pkeys { |
| 1753 | struct ib_port_pkey main; |
| 1754 | struct ib_port_pkey alt; |
| 1755 | }; |
| 1756 | |
| 1757 | struct 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 Assche | 632bc3f | 2016-07-21 13:03:30 -0700 | [diff] [blame] | 1774 | /* |
| 1775 | * @max_write_sge: Maximum SGE elements per RDMA WRITE request. |
| 1776 | * @max_read_sge: Maximum SGE elements per RDMA READ request. |
| 1777 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | struct 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 Hellwig | fffb038 | 2016-05-03 18:01:07 +0200 | [diff] [blame] | 1783 | spinlock_t mr_lock; |
| 1784 | int mrs_used; |
Christoph Hellwig | a060b56 | 2016-05-03 18:01:09 +0200 | [diff] [blame] | 1785 | struct list_head rdma_mrs; |
Christoph Hellwig | 0e353e3 | 2016-05-03 18:01:12 +0200 | [diff] [blame] | 1786 | struct list_head sig_mrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | struct ib_srq *srq; |
Sean Hefty | b42b63c | 2011-05-23 19:59:25 -0700 | [diff] [blame] | 1788 | struct ib_xrcd *xrcd; /* XRC TGT QPs only */ |
Sean Hefty | d3d72d9 | 2011-05-26 23:06:44 -0700 | [diff] [blame] | 1789 | struct list_head xrcd_list; |
Christoph Hellwig | fffb038 | 2016-05-03 18:01:07 +0200 | [diff] [blame] | 1790 | |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1791 | /* count times opened, mcast attaches, flow attaches */ |
| 1792 | atomic_t usecnt; |
Sean Hefty | 0e0ec7e | 2011-08-08 15:31:51 -0700 | [diff] [blame] | 1793 | struct list_head open_list; |
| 1794 | struct ib_qp *real_qp; |
Jason Gunthorpe | 620d3f8 | 2020-01-08 19:21:59 +0200 | [diff] [blame] | 1795 | struct ib_uqp_object *uobject; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | void (*event_handler)(struct ib_event *, void *); |
| 1797 | void *qp_context; |
Jason Gunthorpe | 1a1f460 | 2018-06-13 10:22:08 +0300 | [diff] [blame] | 1798 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | u32 qp_num; |
Bart Van Assche | 632bc3f | 2016-07-21 13:03:30 -0700 | [diff] [blame] | 1802 | u32 max_write_sge; |
| 1803 | u32 max_read_sge; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | enum ib_qp_type qp_type; |
Yishai Hadas | a9017e2 | 2016-05-23 15:20:54 +0300 | [diff] [blame] | 1805 | struct ib_rwq_ind_table *rwq_ind_tbl; |
Daniel Jurgens | d291f1a | 2017-05-19 15:48:52 +0300 | [diff] [blame] | 1806 | struct ib_qp_security *qp_sec; |
Noa Osherovich | 498ca3c | 2017-08-23 08:35:40 +0300 | [diff] [blame] | 1807 | u8 port; |
Leon Romanovsky | 02d8883 | 2018-01-28 11:17:20 +0200 | [diff] [blame] | 1808 | |
Max Gurtovoy | 185eddc | 2019-06-11 18:52:51 +0300 | [diff] [blame] | 1809 | bool integrity_en; |
Leon Romanovsky | 02d8883 | 2018-01-28 11:17:20 +0200 | [diff] [blame] | 1810 | /* |
| 1811 | * Implementation details of the RDMA core, don't use in drivers: |
| 1812 | */ |
| 1813 | struct rdma_restrack_entry res; |
Mark Zhang | 99fa331 | 2019-07-02 13:02:35 +0300 | [diff] [blame] | 1814 | |
| 1815 | /* The counter the qp is bind to */ |
| 1816 | struct rdma_counter *counter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | }; |
| 1818 | |
Ariel Levkovich | bee76d7 | 2018-04-05 18:53:24 +0300 | [diff] [blame] | 1819 | struct 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | struct ib_mr { |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1828 | struct ib_device *device; |
| 1829 | struct ib_pd *pd; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1830 | u32 lkey; |
| 1831 | u32 rkey; |
Sagi Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 1832 | u64 iova; |
Parav Pandit | edd3155 | 2017-09-24 21:46:31 +0300 | [diff] [blame] | 1833 | u64 length; |
Sagi Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 1834 | unsigned int page_size; |
Max Gurtovoy | a0bc099 | 2019-06-11 18:52:38 +0300 | [diff] [blame] | 1835 | enum ib_mr_type type; |
Steve Wise | d4a85c3 | 2016-05-03 18:01:08 +0200 | [diff] [blame] | 1836 | bool need_inval; |
Christoph Hellwig | fffb038 | 2016-05-03 18:01:07 +0200 | [diff] [blame] | 1837 | union { |
| 1838 | struct ib_uobject *uobject; /* user */ |
| 1839 | struct list_head qp_entry; /* FR */ |
| 1840 | }; |
Steve Wise | fccec5b | 2018-03-01 13:58:13 -0800 | [diff] [blame] | 1841 | |
Ariel Levkovich | be934cc | 2018-04-05 18:53:25 +0300 | [diff] [blame] | 1842 | struct ib_dm *dm; |
Max Gurtovoy | 7c717d3 | 2019-06-11 18:52:41 +0300 | [diff] [blame] | 1843 | struct ib_sig_attrs *sig_attrs; /* only for IB_MR_TYPE_INTEGRITY MRs */ |
Steve Wise | fccec5b | 2018-03-01 13:58:13 -0800 | [diff] [blame] | 1844 | /* |
| 1845 | * Implementation details of the RDMA core, don't use in drivers: |
| 1846 | */ |
| 1847 | struct rdma_restrack_entry res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | }; |
| 1849 | |
| 1850 | struct ib_mw { |
| 1851 | struct ib_device *device; |
| 1852 | struct ib_pd *pd; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 1853 | struct ib_uobject *uobject; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | u32 rkey; |
Shani Michaeli | 7083e42 | 2013-02-06 16:19:12 +0000 | [diff] [blame] | 1855 | enum ib_mw_type type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | }; |
| 1857 | |
| 1858 | struct 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 Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1866 | /* Supported steering options */ |
| 1867 | enum 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 */ |
| 1883 | enum ib_flow_spec_type { |
| 1884 | /* L2 headers*/ |
Moses Reuben | 76bd23b | 2016-11-14 19:04:48 +0200 | [diff] [blame] | 1885 | IB_FLOW_SPEC_ETH = 0x20, |
| 1886 | IB_FLOW_SPEC_IB = 0x22, |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1887 | /* L3 header*/ |
Moses Reuben | 76bd23b | 2016-11-14 19:04:48 +0200 | [diff] [blame] | 1888 | IB_FLOW_SPEC_IPV4 = 0x30, |
| 1889 | IB_FLOW_SPEC_IPV6 = 0x31, |
Matan Barak | 56ab0b3 | 2018-03-28 09:27:49 +0300 | [diff] [blame] | 1890 | IB_FLOW_SPEC_ESP = 0x34, |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1891 | /* L4 headers*/ |
Moses Reuben | 76bd23b | 2016-11-14 19:04:48 +0200 | [diff] [blame] | 1892 | IB_FLOW_SPEC_TCP = 0x40, |
| 1893 | IB_FLOW_SPEC_UDP = 0x41, |
Moses Reuben | 0dbf333 | 2016-11-14 19:04:47 +0200 | [diff] [blame] | 1894 | IB_FLOW_SPEC_VXLAN_TUNNEL = 0x50, |
Ariel Levkovich | d90e5e5 | 2018-05-13 14:33:30 +0300 | [diff] [blame] | 1895 | IB_FLOW_SPEC_GRE = 0x51, |
Ariel Levkovich | b04f0f0 | 2018-05-13 14:33:32 +0300 | [diff] [blame] | 1896 | IB_FLOW_SPEC_MPLS = 0x60, |
Moses Reuben | fbf4686 | 2016-11-14 19:04:51 +0200 | [diff] [blame] | 1897 | IB_FLOW_SPEC_INNER = 0x100, |
Moses Reuben | 460d019 | 2017-01-18 14:59:48 +0200 | [diff] [blame] | 1898 | /* Actions */ |
| 1899 | IB_FLOW_SPEC_ACTION_TAG = 0x1000, |
Slava Shwartsman | 483a396 | 2017-04-03 13:13:51 +0300 | [diff] [blame] | 1900 | IB_FLOW_SPEC_ACTION_DROP = 0x1001, |
Matan Barak | 9b82844 | 2018-03-28 09:27:46 +0300 | [diff] [blame] | 1901 | IB_FLOW_SPEC_ACTION_HANDLE = 0x1002, |
Raed Salem | 7eea23a | 2018-05-31 16:43:36 +0300 | [diff] [blame] | 1902 | IB_FLOW_SPEC_ACTION_COUNT = 0x1003, |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1903 | }; |
Matan Barak | 240ae00 | 2013-11-07 15:25:13 +0200 | [diff] [blame] | 1904 | #define IB_FLOW_SPEC_LAYER_MASK 0xF0 |
Raed Salem | 7eea23a | 2018-05-31 16:43:36 +0300 | [diff] [blame] | 1905 | #define IB_FLOW_SPEC_SUPPORT_LAYERS 10 |
Matan Barak | 22878db | 2013-09-01 18:39:52 +0300 | [diff] [blame] | 1906 | |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1907 | /* Flow steering rule priority is set according to it's domain. |
| 1908 | * Lower domain value means higher priority. |
| 1909 | */ |
| 1910 | enum 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 Varshaver | a3100a7 | 2016-02-18 18:31:05 +0200 | [diff] [blame] | 1918 | enum ib_flow_flags { |
| 1919 | IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */ |
Boris Pismenny | 21e82d3 | 2018-03-28 09:27:47 +0300 | [diff] [blame] | 1920 | IB_FLOW_ATTR_FLAGS_EGRESS = 1UL << 2, /* Egress flow */ |
| 1921 | IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 3 /* Must be last */ |
Marina Varshaver | a3100a7 | 2016-02-18 18:31:05 +0200 | [diff] [blame] | 1922 | }; |
| 1923 | |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1924 | struct ib_flow_eth_filter { |
| 1925 | u8 dst_mac[6]; |
| 1926 | u8 src_mac[6]; |
| 1927 | __be16 ether_type; |
| 1928 | __be16 vlan_tag; |
Maor Gottlieb | 15dfbd6 | 2016-08-30 16:58:32 +0300 | [diff] [blame] | 1929 | /* Must be last */ |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 1930 | u8 real_sz[]; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1931 | }; |
| 1932 | |
| 1933 | struct ib_flow_spec_eth { |
Moses Reuben | fbf4686 | 2016-11-14 19:04:51 +0200 | [diff] [blame] | 1934 | u32 type; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1935 | u16 size; |
| 1936 | struct ib_flow_eth_filter val; |
| 1937 | struct ib_flow_eth_filter mask; |
| 1938 | }; |
| 1939 | |
Matan Barak | 240ae00 | 2013-11-07 15:25:13 +0200 | [diff] [blame] | 1940 | struct ib_flow_ib_filter { |
| 1941 | __be16 dlid; |
| 1942 | __u8 sl; |
Maor Gottlieb | 15dfbd6 | 2016-08-30 16:58:32 +0300 | [diff] [blame] | 1943 | /* Must be last */ |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 1944 | u8 real_sz[]; |
Matan Barak | 240ae00 | 2013-11-07 15:25:13 +0200 | [diff] [blame] | 1945 | }; |
| 1946 | |
| 1947 | struct ib_flow_spec_ib { |
Moses Reuben | fbf4686 | 2016-11-14 19:04:51 +0200 | [diff] [blame] | 1948 | u32 type; |
Matan Barak | 240ae00 | 2013-11-07 15:25:13 +0200 | [diff] [blame] | 1949 | u16 size; |
| 1950 | struct ib_flow_ib_filter val; |
| 1951 | struct ib_flow_ib_filter mask; |
| 1952 | }; |
| 1953 | |
Maor Gottlieb | 989a3a8 | 2016-08-30 16:58:33 +0300 | [diff] [blame] | 1954 | /* IPv4 header flags */ |
| 1955 | enum 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 Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1961 | struct ib_flow_ipv4_filter { |
| 1962 | __be32 src_ip; |
| 1963 | __be32 dst_ip; |
Maor Gottlieb | 989a3a8 | 2016-08-30 16:58:33 +0300 | [diff] [blame] | 1964 | u8 proto; |
| 1965 | u8 tos; |
| 1966 | u8 ttl; |
| 1967 | u8 flags; |
Maor Gottlieb | 15dfbd6 | 2016-08-30 16:58:32 +0300 | [diff] [blame] | 1968 | /* Must be last */ |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 1969 | u8 real_sz[]; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1970 | }; |
| 1971 | |
| 1972 | struct ib_flow_spec_ipv4 { |
Moses Reuben | fbf4686 | 2016-11-14 19:04:51 +0200 | [diff] [blame] | 1973 | u32 type; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1974 | u16 size; |
| 1975 | struct ib_flow_ipv4_filter val; |
| 1976 | struct ib_flow_ipv4_filter mask; |
| 1977 | }; |
| 1978 | |
Maor Gottlieb | 4c2aae7 | 2016-06-17 15:14:50 +0300 | [diff] [blame] | 1979 | struct ib_flow_ipv6_filter { |
| 1980 | u8 src_ip[16]; |
| 1981 | u8 dst_ip[16]; |
Maor Gottlieb | a72c6a2 | 2016-08-30 16:58:34 +0300 | [diff] [blame] | 1982 | __be32 flow_label; |
| 1983 | u8 next_hdr; |
| 1984 | u8 traffic_class; |
| 1985 | u8 hop_limit; |
Maor Gottlieb | 15dfbd6 | 2016-08-30 16:58:32 +0300 | [diff] [blame] | 1986 | /* Must be last */ |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 1987 | u8 real_sz[]; |
Maor Gottlieb | 4c2aae7 | 2016-06-17 15:14:50 +0300 | [diff] [blame] | 1988 | }; |
| 1989 | |
| 1990 | struct ib_flow_spec_ipv6 { |
Moses Reuben | fbf4686 | 2016-11-14 19:04:51 +0200 | [diff] [blame] | 1991 | u32 type; |
Maor Gottlieb | 4c2aae7 | 2016-06-17 15:14:50 +0300 | [diff] [blame] | 1992 | u16 size; |
| 1993 | struct ib_flow_ipv6_filter val; |
| 1994 | struct ib_flow_ipv6_filter mask; |
| 1995 | }; |
| 1996 | |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 1997 | struct ib_flow_tcp_udp_filter { |
| 1998 | __be16 dst_port; |
| 1999 | __be16 src_port; |
Maor Gottlieb | 15dfbd6 | 2016-08-30 16:58:32 +0300 | [diff] [blame] | 2000 | /* Must be last */ |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 2001 | u8 real_sz[]; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 2002 | }; |
| 2003 | |
| 2004 | struct ib_flow_spec_tcp_udp { |
Moses Reuben | fbf4686 | 2016-11-14 19:04:51 +0200 | [diff] [blame] | 2005 | u32 type; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 2006 | u16 size; |
| 2007 | struct ib_flow_tcp_udp_filter val; |
| 2008 | struct ib_flow_tcp_udp_filter mask; |
| 2009 | }; |
| 2010 | |
Moses Reuben | 0dbf333 | 2016-11-14 19:04:47 +0200 | [diff] [blame] | 2011 | struct ib_flow_tunnel_filter { |
| 2012 | __be32 tunnel_id; |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 2013 | u8 real_sz[]; |
Moses Reuben | 0dbf333 | 2016-11-14 19:04:47 +0200 | [diff] [blame] | 2014 | }; |
| 2015 | |
| 2016 | /* ib_flow_spec_tunnel describes the Vxlan tunnel |
| 2017 | * the tunnel_id from val has the vni value |
| 2018 | */ |
| 2019 | struct ib_flow_spec_tunnel { |
Moses Reuben | fbf4686 | 2016-11-14 19:04:51 +0200 | [diff] [blame] | 2020 | u32 type; |
Moses Reuben | 0dbf333 | 2016-11-14 19:04:47 +0200 | [diff] [blame] | 2021 | u16 size; |
| 2022 | struct ib_flow_tunnel_filter val; |
| 2023 | struct ib_flow_tunnel_filter mask; |
| 2024 | }; |
| 2025 | |
Matan Barak | 56ab0b3 | 2018-03-28 09:27:49 +0300 | [diff] [blame] | 2026 | struct ib_flow_esp_filter { |
| 2027 | __be32 spi; |
| 2028 | __be32 seq; |
| 2029 | /* Must be last */ |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 2030 | u8 real_sz[]; |
Matan Barak | 56ab0b3 | 2018-03-28 09:27:49 +0300 | [diff] [blame] | 2031 | }; |
| 2032 | |
| 2033 | struct 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 Levkovich | d90e5e5 | 2018-05-13 14:33:30 +0300 | [diff] [blame] | 2040 | struct ib_flow_gre_filter { |
| 2041 | __be16 c_ks_res0_ver; |
| 2042 | __be16 protocol; |
| 2043 | __be32 key; |
| 2044 | /* Must be last */ |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 2045 | u8 real_sz[]; |
Ariel Levkovich | d90e5e5 | 2018-05-13 14:33:30 +0300 | [diff] [blame] | 2046 | }; |
| 2047 | |
| 2048 | struct 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 Levkovich | b04f0f0 | 2018-05-13 14:33:32 +0300 | [diff] [blame] | 2055 | struct ib_flow_mpls_filter { |
| 2056 | __be32 tag; |
| 2057 | /* Must be last */ |
Gustavo A. R. Silva | 5b36132 | 2020-02-12 19:04:25 -0600 | [diff] [blame] | 2058 | u8 real_sz[]; |
Ariel Levkovich | b04f0f0 | 2018-05-13 14:33:32 +0300 | [diff] [blame] | 2059 | }; |
| 2060 | |
| 2061 | struct 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 Reuben | 460d019 | 2017-01-18 14:59:48 +0200 | [diff] [blame] | 2068 | struct ib_flow_spec_action_tag { |
| 2069 | enum ib_flow_spec_type type; |
| 2070 | u16 size; |
| 2071 | u32 tag_id; |
| 2072 | }; |
| 2073 | |
Slava Shwartsman | 483a396 | 2017-04-03 13:13:51 +0300 | [diff] [blame] | 2074 | struct ib_flow_spec_action_drop { |
| 2075 | enum ib_flow_spec_type type; |
| 2076 | u16 size; |
| 2077 | }; |
| 2078 | |
Matan Barak | 9b82844 | 2018-03-28 09:27:46 +0300 | [diff] [blame] | 2079 | struct ib_flow_spec_action_handle { |
| 2080 | enum ib_flow_spec_type type; |
| 2081 | u16 size; |
| 2082 | struct ib_flow_action *act; |
| 2083 | }; |
| 2084 | |
Raed Salem | 7eea23a | 2018-05-31 16:43:36 +0300 | [diff] [blame] | 2085 | enum ib_counters_description { |
| 2086 | IB_COUNTER_PACKETS, |
| 2087 | IB_COUNTER_BYTES, |
| 2088 | }; |
| 2089 | |
| 2090 | struct ib_flow_spec_action_count { |
| 2091 | enum ib_flow_spec_type type; |
| 2092 | u16 size; |
| 2093 | struct ib_counters *counters; |
| 2094 | }; |
| 2095 | |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 2096 | union ib_flow_spec { |
| 2097 | struct { |
Moses Reuben | fbf4686 | 2016-11-14 19:04:51 +0200 | [diff] [blame] | 2098 | u32 type; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 2099 | u16 size; |
| 2100 | }; |
| 2101 | struct ib_flow_spec_eth eth; |
Matan Barak | 240ae00 | 2013-11-07 15:25:13 +0200 | [diff] [blame] | 2102 | struct ib_flow_spec_ib ib; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 2103 | struct ib_flow_spec_ipv4 ipv4; |
| 2104 | struct ib_flow_spec_tcp_udp tcp_udp; |
Maor Gottlieb | 4c2aae7 | 2016-06-17 15:14:50 +0300 | [diff] [blame] | 2105 | struct ib_flow_spec_ipv6 ipv6; |
Moses Reuben | 0dbf333 | 2016-11-14 19:04:47 +0200 | [diff] [blame] | 2106 | struct ib_flow_spec_tunnel tunnel; |
Matan Barak | 56ab0b3 | 2018-03-28 09:27:49 +0300 | [diff] [blame] | 2107 | struct ib_flow_spec_esp esp; |
Ariel Levkovich | d90e5e5 | 2018-05-13 14:33:30 +0300 | [diff] [blame] | 2108 | struct ib_flow_spec_gre gre; |
Ariel Levkovich | b04f0f0 | 2018-05-13 14:33:32 +0300 | [diff] [blame] | 2109 | struct ib_flow_spec_mpls mpls; |
Moses Reuben | 460d019 | 2017-01-18 14:59:48 +0200 | [diff] [blame] | 2110 | struct ib_flow_spec_action_tag flow_tag; |
Slava Shwartsman | 483a396 | 2017-04-03 13:13:51 +0300 | [diff] [blame] | 2111 | struct ib_flow_spec_action_drop drop; |
Matan Barak | 9b82844 | 2018-03-28 09:27:46 +0300 | [diff] [blame] | 2112 | struct ib_flow_spec_action_handle action; |
Raed Salem | 7eea23a | 2018-05-31 16:43:36 +0300 | [diff] [blame] | 2113 | struct ib_flow_spec_action_count flow_count; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 2114 | }; |
| 2115 | |
| 2116 | struct 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 Wilcox | 7654cb1 | 2018-06-07 07:57:16 -0700 | [diff] [blame] | 2123 | union ib_flow_spec flows[]; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 2124 | }; |
| 2125 | |
| 2126 | struct ib_flow { |
| 2127 | struct ib_qp *qp; |
Yishai Hadas | 6cd080a | 2018-07-23 15:25:08 +0300 | [diff] [blame] | 2128 | struct ib_device *device; |
Hadar Hen Zion | 319a441 | 2013-08-07 14:01:59 +0300 | [diff] [blame] | 2129 | struct ib_uobject *uobject; |
| 2130 | }; |
| 2131 | |
Matan Barak | 2eb9bea | 2018-03-28 09:27:45 +0300 | [diff] [blame] | 2132 | enum ib_flow_action_type { |
| 2133 | IB_FLOW_ACTION_UNSPECIFIED, |
| 2134 | IB_FLOW_ACTION_ESP = 1, |
| 2135 | }; |
| 2136 | |
| 2137 | struct 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 | |
| 2144 | struct 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 | |
| 2151 | enum 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 Barak | 7d12f8d | 2018-03-28 09:27:48 +0300 | [diff] [blame] | 2159 | IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS = 1ULL << 33, |
Matan Barak | 2eb9bea | 2018-03-28 09:27:45 +0300 | [diff] [blame] | 2160 | }; |
| 2161 | |
| 2162 | struct ib_flow_spec_list { |
| 2163 | struct ib_flow_spec_list *next; |
| 2164 | union ib_flow_spec spec; |
| 2165 | }; |
| 2166 | |
| 2167 | struct 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 | |
| 2183 | struct 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 Romanovsky | e26e7b8 | 2019-10-29 08:27:45 +0200 | [diff] [blame] | 2190 | struct ib_mad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | struct ib_grh; |
| 2192 | |
| 2193 | enum 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 | |
| 2199 | enum 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 Wang | 21d6454 | 2017-01-17 10:11:12 +0100 | [diff] [blame] | 2206 | struct ib_port_cache { |
Daniel Jurgens | 883c71f | 2017-05-19 15:48:51 +0300 | [diff] [blame] | 2207 | u64 subnet_prefix; |
Jack Wang | 21d6454 | 2017-01-17 10:11:12 +0100 | [diff] [blame] | 2208 | struct ib_pkey_cache *pkey; |
| 2209 | struct ib_gid_table *gid; |
| 2210 | u8 lmc; |
| 2211 | enum ib_port_state port_state; |
| 2212 | }; |
| 2213 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2214 | struct ib_port_immutable { |
| 2215 | int pkey_tbl_len; |
| 2216 | int gid_tbl_len; |
Ira Weiny | f9b22e3 | 2015-05-13 20:02:59 -0400 | [diff] [blame] | 2217 | u32 core_cap_flags; |
Ira Weiny | 337877a | 2015-06-06 14:38:29 -0400 | [diff] [blame] | 2218 | u32 max_mad_size; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2219 | }; |
| 2220 | |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 2221 | struct ib_port_data { |
Jason Gunthorpe | 324e227 | 2019-02-12 21:12:51 -0700 | [diff] [blame] | 2222 | struct ib_device *ib_dev; |
| 2223 | |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 2224 | struct ib_port_immutable immutable; |
| 2225 | |
| 2226 | spinlock_t pkey_list_lock; |
| 2227 | struct list_head pkey_list; |
Jason Gunthorpe | 8faea9f | 2019-02-12 21:12:49 -0700 | [diff] [blame] | 2228 | |
| 2229 | struct ib_port_cache cache; |
Jason Gunthorpe | c2261dd | 2019-02-12 21:12:50 -0700 | [diff] [blame] | 2230 | |
| 2231 | spinlock_t netdev_lock; |
Jason Gunthorpe | 324e227 | 2019-02-12 21:12:51 -0700 | [diff] [blame] | 2232 | struct net_device __rcu *netdev; |
| 2233 | struct hlist_node ndev_hash_link; |
Mark Zhang | 413d334 | 2019-07-02 13:02:34 +0300 | [diff] [blame] | 2234 | struct rdma_port_counter port_counter; |
Mark Zhang | 6e7be47 | 2019-07-02 13:02:46 +0300 | [diff] [blame] | 2235 | struct rdma_hw_stats *hw_stats; |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 2236 | }; |
| 2237 | |
Vishwanathapura, Niranjana | 2fc7757 | 2017-04-12 20:29:20 -0700 | [diff] [blame] | 2238 | /* rdma netdev type - specifies protocol type */ |
| 2239 | enum rdma_netdev_t { |
Niranjana Vishwanathapura | f0ad83ac | 2017-04-10 11:22:25 +0300 | [diff] [blame] | 2240 | RDMA_NETDEV_OPA_VNIC, |
| 2241 | RDMA_NETDEV_IPOIB, |
Vishwanathapura, Niranjana | 2fc7757 | 2017-04-12 20:29:20 -0700 | [diff] [blame] | 2242 | }; |
| 2243 | |
| 2244 | /** |
| 2245 | * struct rdma_netdev - rdma netdev |
| 2246 | * For cases where netstack interfacing is required. |
| 2247 | */ |
| 2248 | struct rdma_netdev { |
| 2249 | void *clnt_priv; |
| 2250 | struct ib_device *hca; |
| 2251 | u8 port_num; |
Gary Leshner | d99dc60 | 2020-05-11 12:05:48 -0400 | [diff] [blame] | 2252 | int mtu; |
Vishwanathapura, Niranjana | 2fc7757 | 2017-04-12 20:29:20 -0700 | [diff] [blame] | 2253 | |
Jason Gunthorpe | 9f49a5b | 2018-07-29 11:34:56 +0300 | [diff] [blame] | 2254 | /* |
| 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 Vishwanathapura | 8e95960 | 2017-06-30 13:14:46 -0700 | [diff] [blame] | 2259 | void (*free_rdma_netdev)(struct net_device *netdev); |
| 2260 | |
Vishwanathapura, Niranjana | 2fc7757 | 2017-04-12 20:29:20 -0700 | [diff] [blame] | 2261 | /* control functions */ |
| 2262 | void (*set_id)(struct net_device *netdev, int id); |
Niranjana Vishwanathapura | f0ad83ac | 2017-04-10 11:22:25 +0300 | [diff] [blame] | 2263 | /* 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, Niranjana | 2fc7757 | 2017-04-12 20:29:20 -0700 | [diff] [blame] | 2272 | }; |
| 2273 | |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 2274 | struct 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 Alfasi | a3de94e | 2019-10-16 09:23:05 +0300 | [diff] [blame] | 2284 | struct ib_odp_counters { |
| 2285 | atomic64_t faults; |
| 2286 | atomic64_t invalidations; |
| 2287 | }; |
| 2288 | |
Raed Salem | fa9b180 | 2018-05-31 16:43:31 +0300 | [diff] [blame] | 2289 | struct ib_counters { |
| 2290 | struct ib_device *device; |
| 2291 | struct ib_uobject *uobject; |
| 2292 | /* num of objects attached */ |
| 2293 | atomic_t usecnt; |
| 2294 | }; |
| 2295 | |
Raed Salem | 51d7a53 | 2018-05-31 16:43:33 +0300 | [diff] [blame] | 2296 | struct ib_counters_read_attr { |
| 2297 | u64 *counters_buff; |
| 2298 | u32 ncounters; |
| 2299 | u32 flags; /* use enum ib_read_counters_flags */ |
| 2300 | }; |
| 2301 | |
Matan Barak | 2eb9bea | 2018-03-28 09:27:45 +0300 | [diff] [blame] | 2302 | struct uverbs_attr_bundle; |
Kamal Heib | dd05cb8 | 2019-04-29 14:59:06 +0300 | [diff] [blame] | 2303 | struct iw_cm_id; |
| 2304 | struct iw_cm_conn_param; |
Matan Barak | 2eb9bea | 2018-03-28 09:27:45 +0300 | [diff] [blame] | 2305 | |
Leon Romanovsky | 30471d4 | 2019-02-03 14:55:50 +0200 | [diff] [blame] | 2306 | #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 Romanovsky | f631603 | 2019-03-28 15:12:58 +0200 | [diff] [blame] | 2314 | #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 Romanovsky | 30471d4 | 2019-02-03 14:55:50 +0200 | [diff] [blame] | 2317 | #define rdma_zalloc_drv_obj(ib_dev, ib_type) \ |
Leon Romanovsky | f631603 | 2019-03-28 15:12:58 +0200 | [diff] [blame] | 2318 | rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, GFP_KERNEL) |
Leon Romanovsky | 30471d4 | 2019-02-03 14:55:50 +0200 | [diff] [blame] | 2319 | |
| 2320 | #define DECLARE_RDMA_OBJ_SIZE(ib_struct) size_t size_##ib_struct |
| 2321 | |
Michal Kalderon | 3411f9f | 2019-10-30 11:44:11 +0200 | [diff] [blame] | 2322 | struct 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() */ |
| 2331 | static inline u64 |
| 2332 | rdma_user_mmap_get_offset(const struct rdma_user_mmap_entry *entry) |
| 2333 | { |
| 2334 | return (u64)entry->start_pgoff << PAGE_SHIFT; |
| 2335 | } |
| 2336 | |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2337 | /** |
| 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 | */ |
| 2342 | struct ib_device_ops { |
Jason Gunthorpe | 7a15414 | 2019-06-05 14:39:26 -0300 | [diff] [blame] | 2343 | struct module *owner; |
Jason Gunthorpe | b9560a4 | 2019-06-05 14:39:24 -0300 | [diff] [blame] | 2344 | enum rdma_driver_id driver_id; |
Jason Gunthorpe | 72c6ec1 | 2019-06-05 14:39:25 -0300 | [diff] [blame] | 2345 | u32 uverbs_abi_ver; |
Jason Gunthorpe | 8f71bb0 | 2019-06-13 21:38:19 -0300 | [diff] [blame] | 2346 | unsigned int uverbs_no_driver_id_binding:1; |
Jason Gunthorpe | b9560a4 | 2019-06-05 14:39:24 -0300 | [diff] [blame] | 2347 | |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2348 | 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 Romanovsky | e26e7b8 | 2019-10-29 08:27:45 +0200 | [diff] [blame] | 2364 | const struct ib_mad *in_mad, struct ib_mad *out_mad, |
| 2365 | size_t *out_mad_size, u16 *out_mad_pkey_index); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2366 | 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 Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 2444 | int (*alloc_ucontext)(struct ib_ucontext *context, |
| 2445 | struct ib_udata *udata); |
| 2446 | void (*dealloc_ucontext)(struct ib_ucontext *context); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2447 | int (*mmap)(struct ib_ucontext *context, struct vm_area_struct *vma); |
Michal Kalderon | 3411f9f | 2019-10-30 11:44:11 +0200 | [diff] [blame] | 2448 | /** |
| 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 Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2455 | void (*disassociate_ucontext)(struct ib_ucontext *ibcontext); |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 2456 | int (*alloc_pd)(struct ib_pd *pd, struct ib_udata *udata); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2457 | void (*dealloc_pd)(struct ib_pd *pd, struct ib_udata *udata); |
Maor Gottlieb | fa5d010 | 2020-04-30 22:21:42 +0300 | [diff] [blame] | 2458 | int (*create_ah)(struct ib_ah *ah, struct rdma_ah_init_attr *attr, |
| 2459 | struct ib_udata *udata); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2460 | 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 Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 2462 | void (*destroy_ah)(struct ib_ah *ah, u32 flags); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 2463 | int (*create_srq)(struct ib_srq *srq, |
| 2464 | struct ib_srq_init_attr *srq_init_attr, |
| 2465 | struct ib_udata *udata); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2466 | 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 Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 2470 | void (*destroy_srq)(struct ib_srq *srq, struct ib_udata *udata); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2471 | 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 Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2478 | int (*destroy_qp)(struct ib_qp *qp, struct ib_udata *udata); |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 2479 | int (*create_cq)(struct ib_cq *cq, const struct ib_cq_init_attr *attr, |
| 2480 | struct ib_udata *udata); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2481 | int (*modify_cq)(struct ib_cq *cq, u16 cq_count, u16 cq_period); |
Leon Romanovsky | a52c8e2 | 2019-05-28 14:37:28 +0300 | [diff] [blame] | 2482 | void (*destroy_cq)(struct ib_cq *cq, struct ib_udata *udata); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2483 | 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 Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2491 | int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2492 | struct ib_mr *(*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type, |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2493 | u32 max_num_sg, struct ib_udata *udata); |
Israel Rukshin | 26bc7ea | 2019-06-11 18:52:39 +0300 | [diff] [blame] | 2494 | struct ib_mr *(*alloc_mr_integrity)(struct ib_pd *pd, |
| 2495 | u32 max_num_data_sg, |
| 2496 | u32 max_num_meta_sg); |
Moni Shoua | ad8a449 | 2018-12-11 13:37:52 +0200 | [diff] [blame] | 2497 | 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 Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2501 | 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 Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2517 | struct ib_udata *udata); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2518 | int (*dealloc_xrcd)(struct ib_xrcd *xrcd, struct ib_udata *udata); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2519 | 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 Goldberg | bfcb3c5d | 2019-11-06 15:08:32 +0200 | [diff] [blame] | 2538 | 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 Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2541 | 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 Romanovsky | a49b1dc | 2019-06-12 15:27:41 +0300 | [diff] [blame] | 2546 | void (*destroy_wq)(struct ib_wq *wq, struct ib_udata *udata); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2547 | 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 Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2558 | int (*dealloc_dm)(struct ib_dm *dm, struct uverbs_attr_bundle *attrs); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2559 | 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 Gurtovoy | 2cdfcdd | 2019-06-11 18:52:40 +0300 | [diff] [blame] | 2568 | 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 Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2573 | /** |
| 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 Pandit | ea4baf7 | 2018-12-18 14:28:30 +0200 | [diff] [blame] | 2595 | /* |
| 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 Romanovsky | 02da375 | 2019-01-30 12:49:02 +0200 | [diff] [blame] | 2601 | /** |
| 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 Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2606 | |
Jason Gunthorpe | d089989 | 2019-02-12 21:12:53 -0700 | [diff] [blame] | 2607 | /* Device lifecycle callbacks */ |
| 2608 | /* |
Jason Gunthorpe | ca22354 | 2019-02-12 21:12:56 -0700 | [diff] [blame] | 2609 | * Called after the device becomes registered, before clients are |
| 2610 | * attached |
| 2611 | */ |
| 2612 | int (*enable_driver)(struct ib_device *dev); |
| 2613 | /* |
Jason Gunthorpe | d089989 | 2019-02-12 21:12:53 -0700 | [diff] [blame] | 2614 | * This is called as part of ib_dealloc_device(). |
| 2615 | */ |
| 2616 | void (*dealloc_driver)(struct ib_device *dev); |
| 2617 | |
Kamal Heib | dd05cb8 | 2019-04-29 14:59:06 +0300 | [diff] [blame] | 2618 | /* 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 Zhang | 99fa331 | 2019-07-02 13:02:35 +0300 | [diff] [blame] | 2630 | /** |
| 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 Zhang | c4ffee7 | 2019-07-02 13:02:40 +0300 | [diff] [blame] | 2645 | /** |
| 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 Heib | dd05cb8 | 2019-04-29 14:59:06 +0300 | [diff] [blame] | 2655 | |
Erez Alfasi | 4061ff7 | 2019-10-16 09:23:08 +0300 | [diff] [blame] | 2656 | /** |
| 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 Romanovsky | d345691 | 2019-04-03 16:42:42 +0300 | [diff] [blame] | 2663 | DECLARE_RDMA_OBJ_SIZE(ib_ah); |
Leon Romanovsky | e39afe3 | 2019-05-28 14:37:29 +0300 | [diff] [blame] | 2664 | DECLARE_RDMA_OBJ_SIZE(ib_cq); |
Leon Romanovsky | 21a428a | 2019-02-03 14:55:51 +0200 | [diff] [blame] | 2665 | DECLARE_RDMA_OBJ_SIZE(ib_pd); |
Leon Romanovsky | 68e326d | 2019-04-03 16:42:43 +0300 | [diff] [blame] | 2666 | DECLARE_RDMA_OBJ_SIZE(ib_srq); |
Leon Romanovsky | a2a074e | 2019-02-12 20:39:16 +0200 | [diff] [blame] | 2667 | DECLARE_RDMA_OBJ_SIZE(ib_ucontext); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2668 | }; |
| 2669 | |
Parav Pandit | cebe556 | 2019-02-26 13:56:11 +0200 | [diff] [blame] | 2670 | struct 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 Pandit | 4e0f7b9 | 2019-02-26 13:56:13 +0200 | [diff] [blame] | 2675 | possible_net_t rdma_net; |
Parav Pandit | cebe556 | 2019-02-26 13:56:11 +0200 | [diff] [blame] | 2676 | struct kobject *ports_kobj; |
| 2677 | struct list_head port_list; |
| 2678 | struct ib_device *owner; /* reach back to owner ib_device */ |
| 2679 | }; |
Leon Romanovsky | 41eda65 | 2019-02-18 22:25:47 +0200 | [diff] [blame] | 2680 | |
Parav Pandit | cebe556 | 2019-02-26 13:56:11 +0200 | [diff] [blame] | 2681 | struct rdma_restrack_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | struct ib_device { |
Bart Van Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 2683 | /* Do not access @dma_device directly from ULP nor from HW drivers. */ |
| 2684 | struct device *dma_device; |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 2685 | struct ib_device_ops ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | char name[IB_DEVICE_NAME_MAX]; |
Jason Gunthorpe | 324e227 | 2019-02-12 21:12:51 -0700 | [diff] [blame] | 2687 | struct rcu_head rcu_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | |
| 2689 | struct list_head event_handler_list; |
Parav Pandit | 6b57cea | 2019-12-12 13:30:22 +0200 | [diff] [blame] | 2690 | /* Protects event_handler_list */ |
| 2691 | struct rw_semaphore event_handler_rwsem; |
| 2692 | |
| 2693 | /* Protects QP's event_handler calls and open_qp list */ |
Parav Pandit | 40adf68 | 2019-12-12 13:30:24 +0200 | [diff] [blame] | 2694 | spinlock_t qp_open_list_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | |
Jason Gunthorpe | 921eab1 | 2019-02-06 22:41:54 -0700 | [diff] [blame] | 2696 | struct rw_semaphore client_data_rwsem; |
Jason Gunthorpe | 0df91bb | 2019-02-06 22:41:53 -0700 | [diff] [blame] | 2697 | struct xarray client_data; |
Jason Gunthorpe | d089989 | 2019-02-12 21:12:53 -0700 | [diff] [blame] | 2698 | struct mutex unregistration_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | |
Parav Pandit | 17e1064 | 2019-12-12 13:30:23 +0200 | [diff] [blame] | 2700 | /* Synchronize GID, Pkey cache entries, subnet prefix, LMC */ |
| 2701 | rwlock_t cache_lock; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2702 | /** |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 2703 | * port_data is indexed by port number |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2704 | */ |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 2705 | struct ib_port_data *port_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | |
Michael S. Tsirkin | f4fd0b2 | 2007-05-03 13:48:47 +0300 | [diff] [blame] | 2707 | int num_comp_vectors; |
| 2708 | |
Parav Pandit | cebe556 | 2019-02-26 13:56:11 +0200 | [diff] [blame] | 2709 | union { |
| 2710 | struct device dev; |
| 2711 | struct ib_core_device coredev; |
| 2712 | }; |
| 2713 | |
Parav Pandit | d4122f5 | 2018-10-11 22:31:53 +0300 | [diff] [blame] | 2714 | /* 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 Pandit | adee9f3 | 2018-09-05 09:47:58 +0300 | [diff] [blame] | 2719 | |
Alexander Chiang | 17a55f7 | 2010-02-02 19:09:16 +0000 | [diff] [blame] | 2720 | u64 uverbs_cmd_mask; |
Yann Droneaud | f21519b | 2013-11-06 23:21:49 +0100 | [diff] [blame] | 2721 | u64 uverbs_ex_cmd_mask; |
Roland Dreier | 274c089 | 2005-09-29 14:17:48 -0700 | [diff] [blame] | 2722 | |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 2723 | char node_desc[IB_DEVICE_NODE_DESC_MAX]; |
Sean Hefty | cf311cd | 2006-01-10 07:39:34 -0800 | [diff] [blame] | 2724 | __be64 node_guid; |
Steve Wise | 96f15c0 | 2008-07-14 23:48:53 -0700 | [diff] [blame] | 2725 | u32 local_dma_lkey; |
Hal Rosenstock | 4139032 | 2015-06-29 09:57:00 -0400 | [diff] [blame] | 2726 | u16 is_switch:1; |
Gal Pressman | 6780c4f | 2019-01-22 10:08:22 +0200 | [diff] [blame] | 2727 | /* Indicates kernel verbs support, should not be used in drivers */ |
| 2728 | u16 kverbs_provider:1; |
Yamin Friedman | da66297 | 2019-07-08 13:59:03 +0300 | [diff] [blame] | 2729 | /* CQ adaptive moderation (RDMA DIM) */ |
| 2730 | u16 use_cq_dim:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | u8 node_type; |
| 2732 | u8 phys_port_cnt; |
Ira Weiny | 3e153a9 | 2015-12-18 10:59:44 +0200 | [diff] [blame] | 2733 | struct ib_device_attr attrs; |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 2734 | struct attribute_group *hw_stats_ag; |
| 2735 | struct rdma_hw_stats *hw_stats; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 2736 | |
Parav Pandit | 43579b5 | 2017-01-10 00:02:14 +0000 | [diff] [blame] | 2737 | #ifdef CONFIG_CGROUP_RDMA |
| 2738 | struct rdmacg_device cg_device; |
| 2739 | #endif |
| 2740 | |
Leon Romanovsky | ecc82c5 | 2017-06-18 14:39:59 +0300 | [diff] [blame] | 2741 | u32 index; |
Yamin Friedman | c7ff819 | 2020-05-27 11:34:53 +0300 | [diff] [blame^] | 2742 | |
| 2743 | spinlock_t cq_pools_lock; |
| 2744 | struct list_head cq_pools[IB_POLL_LAST_POOL_TYPE + 1]; |
| 2745 | |
Leon Romanovsky | 41eda65 | 2019-02-18 22:25:47 +0200 | [diff] [blame] | 2746 | struct rdma_restrack_root *res; |
Leon Romanovsky | ecc82c5 | 2017-06-18 14:39:59 +0300 | [diff] [blame] | 2747 | |
Jason Gunthorpe | 0cbf432 | 2018-11-12 22:59:50 +0200 | [diff] [blame] | 2748 | const struct uapi_definition *driver_def; |
Jason Gunthorpe | d79af72 | 2019-01-10 14:02:24 -0700 | [diff] [blame] | 2749 | |
Parav Pandit | 01b6711 | 2018-11-16 03:50:57 +0200 | [diff] [blame] | 2750 | /* |
Jason Gunthorpe | d79af72 | 2019-01-10 14:02:24 -0700 | [diff] [blame] | 2751 | * Positive refcount indicates that the device is currently |
| 2752 | * registered and cannot be unregistered. |
Parav Pandit | 01b6711 | 2018-11-16 03:50:57 +0200 | [diff] [blame] | 2753 | */ |
| 2754 | refcount_t refcount; |
| 2755 | struct completion unreg_completion; |
Jason Gunthorpe | d089989 | 2019-02-12 21:12:53 -0700 | [diff] [blame] | 2756 | struct work_struct unregistration_work; |
Steve Wise | 3856ec4 | 2019-02-15 11:03:53 -0800 | [diff] [blame] | 2757 | |
| 2758 | const struct rdma_link_ops *link_ops; |
Parav Pandit | 4e0f7b9 | 2019-02-26 13:56:13 +0200 | [diff] [blame] | 2759 | |
| 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 Heib | dd05cb8 | 2019-04-29 14:59:06 +0300 | [diff] [blame] | 2764 | |
| 2765 | /* Used by iWarp CM */ |
| 2766 | char iw_ifname[IFNAMSIZ]; |
| 2767 | u32 iw_driver_flags; |
Maor Gottlieb | bd3920e | 2020-04-30 22:21:43 +0300 | [diff] [blame] | 2768 | u32 lag_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | }; |
| 2770 | |
Jason Gunthorpe | 0e2d00e | 2019-06-13 21:38:18 -0300 | [diff] [blame] | 2771 | struct ib_client_nl_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | struct ib_client { |
Jason Gunthorpe | e59178d | 2019-02-06 22:41:52 -0700 | [diff] [blame] | 2773 | const char *name; |
Jason Gunthorpe | 11a0ae4 | 2020-04-21 20:24:40 +0300 | [diff] [blame] | 2774 | int (*add)(struct ib_device *ibdev); |
Haggai Eran | 7c1eb45 | 2015-07-30 17:50:14 +0300 | [diff] [blame] | 2775 | void (*remove)(struct ib_device *, void *client_data); |
Leon Romanovsky | dc1435c | 2019-05-17 15:43:10 +0300 | [diff] [blame] | 2776 | void (*rename)(struct ib_device *dev, void *client_data); |
Jason Gunthorpe | 0e2d00e | 2019-06-13 21:38:18 -0300 | [diff] [blame] | 2777 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | |
Yotam Kenneth | 9268f72 | 2015-07-30 17:50:15 +0300 | [diff] [blame] | 2781 | /* 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 Gunthorpe | 621e55f | 2019-07-31 11:18:40 +0300 | [diff] [blame] | 2803 | |
| 2804 | refcount_t uses; |
| 2805 | struct completion uses_zero; |
Jason Gunthorpe | e59178d | 2019-02-06 22:41:52 -0700 | [diff] [blame] | 2806 | u32 client_id; |
Gal Pressman | 6780c4f | 2019-01-22 10:08:22 +0200 | [diff] [blame] | 2807 | |
| 2808 | /* kverbs are not required by the client */ |
| 2809 | u8 no_kverbs_req:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | }; |
| 2811 | |
Shiraz Saleem | a808273 | 2019-05-06 08:53:33 -0500 | [diff] [blame] | 2812 | /* |
| 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 | */ |
| 2818 | struct 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 Romanovsky | 459cc69 | 2019-01-30 12:49:11 +0200 | [diff] [blame] | 2827 | struct 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | void ib_dealloc_device(struct ib_device *device); |
| 2835 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 2836 | void ib_get_device_fw_str(struct ib_device *device, char *str); |
Ira Weiny | 5fa76c2 | 2016-06-15 02:21:56 -0400 | [diff] [blame] | 2837 | |
Parav Pandit | ea4baf7 | 2018-12-18 14:28:30 +0200 | [diff] [blame] | 2838 | int ib_register_device(struct ib_device *device, const char *name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | void ib_unregister_device(struct ib_device *device); |
Jason Gunthorpe | d089989 | 2019-02-12 21:12:53 -0700 | [diff] [blame] | 2840 | void ib_unregister_driver(enum rdma_driver_id driver_id); |
| 2841 | void ib_unregister_device_and_put(struct ib_device *device); |
| 2842 | void ib_unregister_device_queued(struct ib_device *ib_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | |
| 2844 | int ib_register_client (struct ib_client *client); |
| 2845 | void ib_unregister_client(struct ib_client *client); |
| 2846 | |
Shiraz Saleem | a808273 | 2019-05-06 08:53:33 -0500 | [diff] [blame] | 2847 | void __rdma_block_iter_start(struct ib_block_iter *biter, |
| 2848 | struct scatterlist *sglist, |
| 2849 | unsigned int nents, |
| 2850 | unsigned long pgsz); |
| 2851 | bool __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 | */ |
| 2858 | static inline dma_addr_t |
| 2859 | rdma_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 Gunthorpe | 0df91bb | 2019-02-06 22:41:53 -0700 | [diff] [blame] | 2879 | /** |
| 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 | */ |
| 2889 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | void ib_set_client_data(struct ib_device *device, struct ib_client *client, |
| 2895 | void *data); |
Kamal Heib | 521ed0d | 2018-12-10 21:09:30 +0200 | [diff] [blame] | 2896 | void ib_set_device_ops(struct ib_device *device, |
| 2897 | const struct ib_device_ops *ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | |
Jason Gunthorpe | 5f9794d | 2018-09-16 20:43:08 +0300 | [diff] [blame] | 2899 | int rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma, |
Michal Kalderon | c043ff2 | 2019-10-30 11:44:12 +0200 | [diff] [blame] | 2900 | unsigned long pfn, unsigned long size, pgprot_t prot, |
| 2901 | struct rdma_user_mmap_entry *entry); |
Michal Kalderon | 3411f9f | 2019-10-30 11:44:11 +0200 | [diff] [blame] | 2902 | int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext, |
| 2903 | struct rdma_user_mmap_entry *entry, |
| 2904 | size_t length); |
Yishai Hadas | 7a763d1 | 2019-12-12 12:02:36 +0200 | [diff] [blame] | 2905 | int 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 Kalderon | 3411f9f | 2019-10-30 11:44:11 +0200 | [diff] [blame] | 2910 | struct rdma_user_mmap_entry * |
| 2911 | rdma_user_mmap_entry_get_pgoff(struct ib_ucontext *ucontext, |
| 2912 | unsigned long pgoff); |
| 2913 | struct rdma_user_mmap_entry * |
| 2914 | rdma_user_mmap_entry_get(struct ib_ucontext *ucontext, |
| 2915 | struct vm_area_struct *vma); |
| 2916 | void rdma_user_mmap_entry_put(struct rdma_user_mmap_entry *entry); |
| 2917 | |
| 2918 | void rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry); |
Jason Gunthorpe | 5f9794d | 2018-09-16 20:43:08 +0300 | [diff] [blame] | 2919 | |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 2920 | static 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 | |
| 2925 | static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len) |
| 2926 | { |
Yann Droneaud | 43c61165 | 2015-02-05 22:10:18 +0100 | [diff] [blame] | 2927 | return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0; |
Roland Dreier | e2773c0 | 2005-07-07 17:57:10 -0700 | [diff] [blame] | 2928 | } |
| 2929 | |
Matan Barak | c66db31 | 2018-03-19 15:02:36 +0200 | [diff] [blame] | 2930 | static inline bool ib_is_buffer_cleared(const void __user *p, |
| 2931 | size_t len) |
Matan Barak | 301a721 | 2015-12-15 20:30:10 +0200 | [diff] [blame] | 2932 | { |
Markus Elfring | 92d27ae | 2016-08-22 18:23:24 +0200 | [diff] [blame] | 2933 | bool ret; |
Matan Barak | 301a721 | 2015-12-15 20:30:10 +0200 | [diff] [blame] | 2934 | u8 *buf; |
| 2935 | |
| 2936 | if (len > USHRT_MAX) |
| 2937 | return false; |
| 2938 | |
Markus Elfring | 92d27ae | 2016-08-22 18:23:24 +0200 | [diff] [blame] | 2939 | buf = memdup_user(p, len); |
| 2940 | if (IS_ERR(buf)) |
Matan Barak | 301a721 | 2015-12-15 20:30:10 +0200 | [diff] [blame] | 2941 | return false; |
| 2942 | |
Matan Barak | 301a721 | 2015-12-15 20:30:10 +0200 | [diff] [blame] | 2943 | ret = !memchr_inv(buf, 0, len); |
Matan Barak | 301a721 | 2015-12-15 20:30:10 +0200 | [diff] [blame] | 2944 | kfree(buf); |
| 2945 | return ret; |
| 2946 | } |
| 2947 | |
Matan Barak | c66db31 | 2018-03-19 15:02:36 +0200 | [diff] [blame] | 2948 | static 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 Dreier | 8a51866 | 2006-02-13 12:48:12 -0800 | [diff] [blame] | 2955 | /** |
Yishai Hadas | 1c77483 | 2018-06-20 17:11:39 +0300 | [diff] [blame] | 2956 | * 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 | */ |
| 2970 | static 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 | */ |
| 2986 | static 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 Dreier | 8a51866 | 2006-02-13 12:48:12 -0800 | [diff] [blame] | 2996 | * 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 Romanovsky | 19b1f54 | 2018-03-11 13:51:35 +0200 | [diff] [blame] | 3010 | bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state, |
Kamal Heib | d31131b | 2018-10-02 16:11:21 +0300 | [diff] [blame] | 3011 | enum ib_qp_type type, enum ib_qp_attr_mask mask); |
Roland Dreier | 8a51866 | 2006-02-13 12:48:12 -0800 | [diff] [blame] | 3012 | |
Leon Romanovsky | dcc9881 | 2017-08-17 15:50:36 +0300 | [diff] [blame] | 3013 | void ib_register_event_handler(struct ib_event_handler *event_handler); |
| 3014 | void ib_unregister_event_handler(struct ib_event_handler *event_handler); |
Parav Pandit | 6b57cea | 2019-12-12 13:30:22 +0200 | [diff] [blame] | 3015 | void ib_dispatch_event(const struct ib_event *event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | int ib_query_port(struct ib_device *device, |
| 3018 | u8 port_num, struct ib_port_attr *port_attr); |
| 3019 | |
Eli Cohen | a3f5ada | 2010-09-27 17:51:10 -0700 | [diff] [blame] | 3020 | enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, |
| 3021 | u8 port_num); |
| 3022 | |
Ira Weiny | 0cf18d7 | 2015-05-13 20:02:55 -0400 | [diff] [blame] | 3023 | /** |
Hal Rosenstock | 4139032 | 2015-06-29 09:57:00 -0400 | [diff] [blame] | 3024 | * 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 | */ |
| 3032 | static inline bool rdma_cap_ib_switch(const struct ib_device *device) |
| 3033 | { |
| 3034 | return device->is_switch; |
| 3035 | } |
| 3036 | |
| 3037 | /** |
Ira Weiny | 0cf18d7 | 2015-05-13 20:02:55 -0400 | [diff] [blame] | 3038 | * 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 | */ |
| 3045 | static inline u8 rdma_start_port(const struct ib_device *device) |
| 3046 | { |
Hal Rosenstock | 4139032 | 2015-06-29 09:57:00 -0400 | [diff] [blame] | 3047 | return rdma_cap_ib_switch(device) ? 0 : 1; |
Ira Weiny | 0cf18d7 | 2015-05-13 20:02:55 -0400 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | /** |
Jason Gunthorpe | ea1075e | 2019-02-12 21:12:47 -0700 | [diff] [blame] | 3051 | * 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 Weiny | 0cf18d7 | 2015-05-13 20:02:55 -0400 | [diff] [blame] | 3061 | * 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 | */ |
| 3068 | static inline u8 rdma_end_port(const struct ib_device *device) |
| 3069 | { |
Hal Rosenstock | 4139032 | 2015-06-29 09:57:00 -0400 | [diff] [blame] | 3070 | return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt; |
Ira Weiny | 0cf18d7 | 2015-05-13 20:02:55 -0400 | [diff] [blame] | 3071 | } |
| 3072 | |
Yuval Shaia | 24dc831 | 2017-01-25 18:41:37 +0200 | [diff] [blame] | 3073 | static 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 Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 3080 | static inline bool rdma_is_grh_required(const struct ib_device *device, |
| 3081 | u8 port_num) |
| 3082 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3083 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3084 | RDMA_CORE_PORT_IB_GRH_REQUIRED; |
Artemy Kovalyov | b02289b | 2018-07-04 15:57:50 +0300 | [diff] [blame] | 3085 | } |
| 3086 | |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3087 | static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num) |
Michael Wang | de66be9 | 2015-05-05 14:50:19 +0200 | [diff] [blame] | 3088 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3089 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3090 | RDMA_CORE_CAP_PROT_IB; |
Michael Wang | de66be9 | 2015-05-05 14:50:19 +0200 | [diff] [blame] | 3091 | } |
| 3092 | |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3093 | static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num) |
Michael Wang | de66be9 | 2015-05-05 14:50:19 +0200 | [diff] [blame] | 3094 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3095 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3096 | (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP); |
Matan Barak | 7766a99 | 2015-12-23 14:56:50 +0200 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num) |
| 3100 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3101 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3102 | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP; |
Matan Barak | 7766a99 | 2015-12-23 14:56:50 +0200 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num) |
| 3106 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3107 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3108 | RDMA_CORE_CAP_PROT_ROCE; |
Michael Wang | de66be9 | 2015-05-05 14:50:19 +0200 | [diff] [blame] | 3109 | } |
| 3110 | |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3111 | static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num) |
Michael Wang | de66be9 | 2015-05-05 14:50:19 +0200 | [diff] [blame] | 3112 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3113 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3114 | RDMA_CORE_CAP_PROT_IWARP; |
Michael Wang | de66be9 | 2015-05-05 14:50:19 +0200 | [diff] [blame] | 3115 | } |
| 3116 | |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3117 | static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num) |
Michael Wang | de66be9 | 2015-05-05 14:50:19 +0200 | [diff] [blame] | 3118 | { |
Matan Barak | 7766a99 | 2015-12-23 14:56:50 +0200 | [diff] [blame] | 3119 | return rdma_protocol_ib(device, port_num) || |
| 3120 | rdma_protocol_roce(device, port_num); |
Michael Wang | de66be9 | 2015-05-05 14:50:19 +0200 | [diff] [blame] | 3121 | } |
| 3122 | |
Or Gerlitz | aa773bd | 2017-01-24 13:02:35 +0200 | [diff] [blame] | 3123 | static inline bool rdma_protocol_raw_packet(const struct ib_device *device, u8 port_num) |
| 3124 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3125 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3126 | RDMA_CORE_CAP_PROT_RAW_PACKET; |
Or Gerlitz | aa773bd | 2017-01-24 13:02:35 +0200 | [diff] [blame] | 3127 | } |
| 3128 | |
Or Gerlitz | ce1e055 | 2017-01-24 13:02:38 +0200 | [diff] [blame] | 3129 | static inline bool rdma_protocol_usnic(const struct ib_device *device, u8 port_num) |
| 3130 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3131 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3132 | RDMA_CORE_CAP_PROT_USNIC; |
Or Gerlitz | ce1e055 | 2017-01-24 13:02:38 +0200 | [diff] [blame] | 3133 | } |
| 3134 | |
Michael Wang | c757dea | 2015-05-05 14:50:32 +0200 | [diff] [blame] | 3135 | /** |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3136 | * rdma_cap_ib_mad - Check if the port of a device supports Infiniband |
Michael Wang | c757dea | 2015-05-05 14:50:32 +0200 | [diff] [blame] | 3137 | * Management Datagrams. |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3138 | * @device: Device to check |
| 3139 | * @port_num: Port number to check |
Michael Wang | c757dea | 2015-05-05 14:50:32 +0200 | [diff] [blame] | 3140 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3141 | * 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 Wang | c757dea | 2015-05-05 14:50:32 +0200 | [diff] [blame] | 3144 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3145 | * Return: true if the port supports sending/receiving of MAD packets. |
Michael Wang | c757dea | 2015-05-05 14:50:32 +0200 | [diff] [blame] | 3146 | */ |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3147 | static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num) |
Michael Wang | c757dea | 2015-05-05 14:50:32 +0200 | [diff] [blame] | 3148 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3149 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3150 | RDMA_CORE_CAP_IB_MAD; |
Michael Wang | c757dea | 2015-05-05 14:50:32 +0200 | [diff] [blame] | 3151 | } |
| 3152 | |
Michael Wang | 29541e3 | 2015-05-05 14:50:33 +0200 | [diff] [blame] | 3153 | /** |
Ira Weiny | 65995fe | 2015-06-06 14:38:32 -0400 | [diff] [blame] | 3154 | * 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 | */ |
| 3172 | static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num) |
| 3173 | { |
Leon Romanovsky | d3243da | 2019-03-10 17:27:46 +0200 | [diff] [blame] | 3174 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3175 | RDMA_CORE_CAP_OPA_MAD; |
Ira Weiny | 65995fe | 2015-06-06 14:38:32 -0400 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | /** |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3179 | * 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 Wang | 29541e3 | 2015-05-05 14:50:33 +0200 | [diff] [blame] | 3183 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3184 | * 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 Wang | 29541e3 | 2015-05-05 14:50:33 +0200 | [diff] [blame] | 3195 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3196 | * Return: true if the port provides an SMI. |
Michael Wang | 29541e3 | 2015-05-05 14:50:33 +0200 | [diff] [blame] | 3197 | */ |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3198 | static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num) |
Michael Wang | 29541e3 | 2015-05-05 14:50:33 +0200 | [diff] [blame] | 3199 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3200 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3201 | RDMA_CORE_CAP_IB_SMI; |
Michael Wang | 29541e3 | 2015-05-05 14:50:33 +0200 | [diff] [blame] | 3202 | } |
| 3203 | |
Michael Wang | 72219cea | 2015-05-05 14:50:34 +0200 | [diff] [blame] | 3204 | /** |
| 3205 | * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband |
| 3206 | * Communication Manager. |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3207 | * @device: Device to check |
| 3208 | * @port_num: Port number to check |
Michael Wang | 72219cea | 2015-05-05 14:50:34 +0200 | [diff] [blame] | 3209 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3210 | * 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 Wang | 72219cea | 2015-05-05 14:50:34 +0200 | [diff] [blame] | 3215 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3216 | * Return: true if the port supports an IB CM (this does not guarantee that |
| 3217 | * a CM is actually running however). |
Michael Wang | 72219cea | 2015-05-05 14:50:34 +0200 | [diff] [blame] | 3218 | */ |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3219 | static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num) |
Michael Wang | 72219cea | 2015-05-05 14:50:34 +0200 | [diff] [blame] | 3220 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3221 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3222 | RDMA_CORE_CAP_IB_CM; |
Michael Wang | 72219cea | 2015-05-05 14:50:34 +0200 | [diff] [blame] | 3223 | } |
| 3224 | |
Michael Wang | 0421533 | 2015-05-05 14:50:35 +0200 | [diff] [blame] | 3225 | /** |
| 3226 | * rdma_cap_iw_cm - Check if the port of device has the capability IWARP |
| 3227 | * Communication Manager. |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3228 | * @device: Device to check |
| 3229 | * @port_num: Port number to check |
Michael Wang | 0421533 | 2015-05-05 14:50:35 +0200 | [diff] [blame] | 3230 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3231 | * Similar to above, but specific to iWARP connections which have a different |
| 3232 | * managment protocol than InfiniBand. |
Michael Wang | 0421533 | 2015-05-05 14:50:35 +0200 | [diff] [blame] | 3233 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3234 | * Return: true if the port supports an iWARP CM (this does not guarantee that |
| 3235 | * a CM is actually running however). |
Michael Wang | 0421533 | 2015-05-05 14:50:35 +0200 | [diff] [blame] | 3236 | */ |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3237 | static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num) |
Michael Wang | 0421533 | 2015-05-05 14:50:35 +0200 | [diff] [blame] | 3238 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3239 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3240 | RDMA_CORE_CAP_IW_CM; |
Michael Wang | 0421533 | 2015-05-05 14:50:35 +0200 | [diff] [blame] | 3241 | } |
| 3242 | |
Michael Wang | fe53ba2 | 2015-05-05 14:50:36 +0200 | [diff] [blame] | 3243 | /** |
| 3244 | * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband |
| 3245 | * Subnet Administration. |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3246 | * @device: Device to check |
| 3247 | * @port_num: Port number to check |
Michael Wang | fe53ba2 | 2015-05-05 14:50:36 +0200 | [diff] [blame] | 3248 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3249 | * 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 Wang | fe53ba2 | 2015-05-05 14:50:36 +0200 | [diff] [blame] | 3253 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3254 | * 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 Wang | fe53ba2 | 2015-05-05 14:50:36 +0200 | [diff] [blame] | 3257 | */ |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3258 | static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num) |
Michael Wang | fe53ba2 | 2015-05-05 14:50:36 +0200 | [diff] [blame] | 3259 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3260 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3261 | RDMA_CORE_CAP_IB_SA; |
Michael Wang | fe53ba2 | 2015-05-05 14:50:36 +0200 | [diff] [blame] | 3262 | } |
| 3263 | |
Michael Wang | a31ad3b | 2015-05-05 14:50:37 +0200 | [diff] [blame] | 3264 | /** |
| 3265 | * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband |
| 3266 | * Multicast. |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3267 | * @device: Device to check |
| 3268 | * @port_num: Port number to check |
Michael Wang | a31ad3b | 2015-05-05 14:50:37 +0200 | [diff] [blame] | 3269 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3270 | * 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 Wang | a31ad3b | 2015-05-05 14:50:37 +0200 | [diff] [blame] | 3276 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3277 | * 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 Wang | a31ad3b | 2015-05-05 14:50:37 +0200 | [diff] [blame] | 3280 | */ |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3281 | static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num) |
Michael Wang | a31ad3b | 2015-05-05 14:50:37 +0200 | [diff] [blame] | 3282 | { |
| 3283 | return rdma_cap_ib_sa(device, port_num); |
| 3284 | } |
| 3285 | |
Michael Wang | bc0f1d7 | 2015-05-05 14:50:38 +0200 | [diff] [blame] | 3286 | /** |
Michael Wang | 30a74ef | 2015-05-05 14:50:39 +0200 | [diff] [blame] | 3287 | * rdma_cap_af_ib - Check if the port of device has the capability |
| 3288 | * Native Infiniband Address. |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3289 | * @device: Device to check |
| 3290 | * @port_num: Port number to check |
Michael Wang | 30a74ef | 2015-05-05 14:50:39 +0200 | [diff] [blame] | 3291 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3292 | * 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 Wang | 30a74ef | 2015-05-05 14:50:39 +0200 | [diff] [blame] | 3295 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3296 | * Return: true if the port uses a GID address to identify devices on the |
| 3297 | * network. |
Michael Wang | 30a74ef | 2015-05-05 14:50:39 +0200 | [diff] [blame] | 3298 | */ |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3299 | static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num) |
Michael Wang | 30a74ef | 2015-05-05 14:50:39 +0200 | [diff] [blame] | 3300 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3301 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3302 | RDMA_CORE_CAP_AF_IB; |
Michael Wang | 30a74ef | 2015-05-05 14:50:39 +0200 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | /** |
Michael Wang | 227128f | 2015-05-05 14:50:40 +0200 | [diff] [blame] | 3306 | * rdma_cap_eth_ah - Check if the port of device has the capability |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3307 | * Ethernet Address Handle. |
| 3308 | * @device: Device to check |
| 3309 | * @port_num: Port number to check |
Michael Wang | 227128f | 2015-05-05 14:50:40 +0200 | [diff] [blame] | 3310 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3311 | * 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 Wang | 227128f | 2015-05-05 14:50:40 +0200 | [diff] [blame] | 3316 | * |
Michael Wang | 296ec00 | 2015-05-18 10:41:45 +0200 | [diff] [blame] | 3317 | * 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 Wang | 227128f | 2015-05-05 14:50:40 +0200 | [diff] [blame] | 3320 | */ |
Ira Weiny | 5ede928 | 2015-05-31 17:15:29 -0400 | [diff] [blame] | 3321 | static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num) |
Michael Wang | 227128f | 2015-05-05 14:50:40 +0200 | [diff] [blame] | 3322 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3323 | return device->port_data[port_num].immutable.core_cap_flags & |
| 3324 | RDMA_CORE_CAP_ETH_AH; |
Michael Wang | 227128f | 2015-05-05 14:50:40 +0200 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | /** |
Dasaratharaman Chandramouli | 94d595c | 2017-03-20 19:38:09 -0400 | [diff] [blame] | 3328 | * 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 | */ |
| 3336 | static inline bool rdma_cap_opa_ah(struct ib_device *device, u8 port_num) |
| 3337 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3338 | return (device->port_data[port_num].immutable.core_cap_flags & |
Dasaratharaman Chandramouli | 94d595c | 2017-03-20 19:38:09 -0400 | [diff] [blame] | 3339 | RDMA_CORE_CAP_OPA_AH) == RDMA_CORE_CAP_OPA_AH; |
| 3340 | } |
| 3341 | |
| 3342 | /** |
Ira Weiny | 337877a | 2015-06-06 14:38:29 -0400 | [diff] [blame] | 3343 | * 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 | */ |
| 3354 | static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num) |
| 3355 | { |
Jason Gunthorpe | 8ceb135 | 2019-02-12 21:12:48 -0700 | [diff] [blame] | 3356 | return device->port_data[port_num].immutable.max_mad_size; |
Ira Weiny | 337877a | 2015-06-06 14:38:29 -0400 | [diff] [blame] | 3357 | } |
| 3358 | |
Matan Barak | 03db3a2 | 2015-07-30 18:33:26 +0300 | [diff] [blame] | 3359 | /** |
| 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 | */ |
| 3372 | static 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 Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 3376 | device->ops.add_gid && device->ops.del_gid; |
Matan Barak | 03db3a2 | 2015-07-30 18:33:26 +0300 | [diff] [blame] | 3377 | } |
| 3378 | |
Christoph Hellwig | 002516e | 2016-05-03 18:01:05 +0200 | [diff] [blame] | 3379 | /* |
| 3380 | * Check if the device supports READ W/ INVALIDATE. |
| 3381 | */ |
| 3382 | static 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 Saleem | 4a35339 | 2019-05-06 08:53:32 -0500 | [diff] [blame] | 3391 | /** |
| 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 | */ |
| 3397 | static 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 Wan | 6d72344 | 2020-05-11 12:06:18 -0400 | [diff] [blame] | 3415 | /** |
| 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 | */ |
| 3422 | static 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 | */ |
| 3438 | static 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 | */ |
| 3455 | static 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 Cohen | 50174a7 | 2016-03-11 22:58:38 +0200 | [diff] [blame] | 3464 | int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port, |
| 3465 | int state); |
| 3466 | int ib_get_vf_config(struct ib_device *device, int vf, u8 port, |
| 3467 | struct ifla_vf_info *info); |
| 3468 | int ib_get_vf_stats(struct ib_device *device, int vf, u8 port, |
| 3469 | struct ifla_vf_stats *stats); |
Danit Goldberg | bfcb3c5d | 2019-11-06 15:08:32 +0200 | [diff] [blame] | 3470 | int 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 Cohen | 50174a7 | 2016-03-11 22:58:38 +0200 | [diff] [blame] | 3473 | int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid, |
| 3474 | int type); |
| 3475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | int ib_query_pkey(struct ib_device *device, |
| 3477 | u8 port_num, u16 index, u16 *pkey); |
| 3478 | |
| 3479 | int ib_modify_device(struct ib_device *device, |
| 3480 | int device_modify_mask, |
| 3481 | struct ib_device_modify *device_modify); |
| 3482 | |
| 3483 | int ib_modify_port(struct ib_device *device, |
| 3484 | u8 port_num, int port_modify_mask, |
| 3485 | struct ib_port_modify *port_modify); |
| 3486 | |
Yosef Etigin | 5eb620c | 2007-05-14 07:26:51 +0300 | [diff] [blame] | 3487 | int ib_find_gid(struct ib_device *device, union ib_gid *gid, |
Parav Pandit | b26c4a1 | 2018-03-13 16:06:12 +0200 | [diff] [blame] | 3488 | u8 *port_num, u16 *index); |
Yosef Etigin | 5eb620c | 2007-05-14 07:26:51 +0300 | [diff] [blame] | 3489 | |
| 3490 | int ib_find_pkey(struct ib_device *device, |
| 3491 | u8 port_num, u16 pkey, u16 *index); |
| 3492 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 3493 | enum 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3505 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 3506 | struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags, |
| 3507 | const char *caller); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3508 | |
Christoph Hellwig | ed082d3 | 2016-09-05 12:56:17 +0200 | [diff] [blame] | 3509 | #define ib_alloc_pd(device, flags) \ |
Leon Romanovsky | e449644 | 2018-01-28 11:17:18 +0200 | [diff] [blame] | 3510 | __ib_alloc_pd((device), (flags), KBUILD_MODNAME) |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3511 | |
| 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 | */ |
| 3517 | void 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 | */ |
| 3525 | static inline void ib_dealloc_pd(struct ib_pd *pd) |
| 3526 | { |
| 3527 | ib_dealloc_pd_user(pd, NULL); |
| 3528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | |
Gal Pressman | b090c4e | 2018-12-12 11:09:05 +0200 | [diff] [blame] | 3530 | enum rdma_create_ah_flags { |
| 3531 | /* In a sleepable context */ |
| 3532 | RDMA_CREATE_AH_SLEEPABLE = BIT(0), |
| 3533 | }; |
| 3534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | /** |
Dasaratharaman Chandramouli | 0a18cfe | 2017-04-29 14:41:19 -0400 | [diff] [blame] | 3536 | * rdma_create_ah - Creates an address handle for the given address vector. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | * @pd: The protection domain associated with the address handle. |
| 3538 | * @ah_attr: The attributes of the address vector. |
Gal Pressman | b090c4e | 2018-12-12 11:09:05 +0200 | [diff] [blame] | 3539 | * @flags: Create address handle flags (see enum rdma_create_ah_flags). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3540 | * |
| 3541 | * The address handle is used to reference a local or global destination |
| 3542 | * in all UD QP post sends. |
| 3543 | */ |
Gal Pressman | b090c4e | 2018-12-12 11:09:05 +0200 | [diff] [blame] | 3544 | struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr, |
| 3545 | u32 flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | |
| 3547 | /** |
Parav Pandit | 5cda658 | 2017-10-16 08:45:12 +0300 | [diff] [blame] | 3548 | * 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 | */ |
| 3559 | struct ib_ah *rdma_create_user_ah(struct ib_pd *pd, |
| 3560 | struct rdma_ah_attr *ah_attr, |
| 3561 | struct ib_udata *udata); |
| 3562 | /** |
Moni Shoua | 850d8fd | 2016-11-10 11:30:56 +0200 | [diff] [blame] | 3563 | * 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 | */ |
| 3570 | int 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 | */ |
| 3578 | int ib_get_rdma_header_version(const union rdma_network_hdr *hdr); |
| 3579 | |
| 3580 | /** |
Parav Pandit | f6bdb14 | 2017-11-14 14:52:17 +0200 | [diff] [blame] | 3581 | * ib_init_ah_attr_from_wc - Initializes address handle attributes from a |
Sean Hefty | 4e00d69 | 2006-06-17 20:37:39 -0700 | [diff] [blame] | 3582 | * 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 Pandit | b740321 | 2018-06-19 10:59:14 +0300 | [diff] [blame] | 3590 | * 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 Hefty | 4e00d69 | 2006-06-17 20:37:39 -0700 | [diff] [blame] | 3597 | */ |
Parav Pandit | f6bdb14 | 2017-11-14 14:52:17 +0200 | [diff] [blame] | 3598 | int 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 Hefty | 4e00d69 | 2006-06-17 20:37:39 -0700 | [diff] [blame] | 3601 | |
| 3602 | /** |
Hal Rosenstock | 513789e | 2005-07-27 11:45:34 -0700 | [diff] [blame] | 3603 | * 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 Weiny | 73cdaae | 2015-05-31 17:15:31 -0400 | [diff] [blame] | 3614 | struct 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 Rosenstock | 513789e | 2005-07-27 11:45:34 -0700 | [diff] [blame] | 3616 | |
| 3617 | /** |
Dasaratharaman Chandramouli | 67b985b | 2017-04-29 14:41:20 -0400 | [diff] [blame] | 3618 | * rdma_modify_ah - Modifies the address vector associated with an address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | * 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 Chandramouli | 67b985b | 2017-04-29 14:41:20 -0400 | [diff] [blame] | 3624 | int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | |
| 3626 | /** |
Dasaratharaman Chandramouli | bfbfd66 | 2017-04-29 14:41:21 -0400 | [diff] [blame] | 3627 | * rdma_query_ah - Queries the address vector associated with an address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | * handle. |
| 3629 | * @ah: The address handle to query. |
| 3630 | * @ah_attr: The address vector attributes associated with the address |
| 3631 | * handle. |
| 3632 | */ |
Dasaratharaman Chandramouli | bfbfd66 | 2017-04-29 14:41:21 -0400 | [diff] [blame] | 3633 | int rdma_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | |
Gal Pressman | 2553ba2 | 2018-12-12 11:09:06 +0200 | [diff] [blame] | 3635 | enum rdma_destroy_ah_flags { |
| 3636 | /* In a sleepable context */ |
| 3637 | RDMA_DESTROY_AH_SLEEPABLE = BIT(0), |
| 3638 | }; |
| 3639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | /** |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3641 | * rdma_destroy_ah_user - Destroys an address handle. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | * @ah: The address handle to destroy. |
Gal Pressman | 2553ba2 | 2018-12-12 11:09:06 +0200 | [diff] [blame] | 3643 | * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags). |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3644 | * @udata: Valid user data or NULL for kernel objects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | */ |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3646 | int 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 | */ |
| 3655 | static inline int rdma_destroy_ah(struct ib_ah *ah, u32 flags) |
| 3656 | { |
| 3657 | return rdma_destroy_ah_user(ah, flags, NULL); |
| 3658 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | |
Jason Gunthorpe | b0810b0 | 2020-05-06 11:24:39 +0300 | [diff] [blame] | 3660 | struct 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); |
| 3664 | static inline struct ib_srq * |
| 3665 | ib_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 Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 3672 | |
| 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 | */ |
| 3685 | int 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 | */ |
| 3695 | int ib_query_srq(struct ib_srq *srq, |
| 3696 | struct ib_srq_attr *srq_attr); |
| 3697 | |
| 3698 | /** |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3699 | * ib_destroy_srq_user - Destroys the specified SRQ. |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 3700 | * @srq: The SRQ to destroy. |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3701 | * @udata: Valid user data or NULL for kernel objects |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 3702 | */ |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3703 | int 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 | */ |
| 3711 | static inline int ib_destroy_srq(struct ib_srq *srq) |
| 3712 | { |
| 3713 | return ib_destroy_srq_user(srq, NULL); |
| 3714 | } |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 3715 | |
| 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 | */ |
| 3723 | static inline int ib_post_srq_recv(struct ib_srq *srq, |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 3724 | const struct ib_recv_wr *recv_wr, |
| 3725 | const struct ib_recv_wr **bad_recv_wr) |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 3726 | { |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 3727 | const struct ib_recv_wr *dummy; |
Bart Van Assche | bb039a8 | 2018-07-18 09:25:16 -0700 | [diff] [blame] | 3728 | |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 3729 | return srq->device->ops.post_srq_recv(srq, recv_wr, |
| 3730 | bad_recv_wr ? : &dummy); |
Roland Dreier | d41fcc6 | 2005-08-18 12:23:08 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
Jason Gunthorpe | b72bfc9 | 2020-02-13 15:19:11 -0400 | [diff] [blame] | 3733 | struct ib_qp *ib_create_qp(struct ib_pd *pd, |
| 3734 | struct ib_qp_init_attr *qp_init_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
| 3736 | /** |
Parav Pandit | a512c2f | 2017-05-23 11:26:08 +0300 | [diff] [blame] | 3737 | * 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 | */ |
| 3747 | int 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | * 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 | */ |
| 3761 | int 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 | */ |
| 3776 | int 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 Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3784 | * @udata: Valid udata or NULL for kernel objects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | */ |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3786 | int 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 | */ |
| 3794 | static inline int ib_destroy_qp(struct ib_qp *qp) |
| 3795 | { |
| 3796 | return ib_destroy_qp_user(qp, NULL); |
| 3797 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | |
| 3799 | /** |
Sean Hefty | 0e0ec7e | 2011-08-08 15:31:51 -0700 | [diff] [blame] | 3800 | * 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 | */ |
| 3806 | struct 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 Hefty | d3d72d9 | 2011-05-26 23:06:44 -0700 | [diff] [blame] | 3811 | * @qp: The QP handle to release |
| 3812 | * |
Sean Hefty | 0e0ec7e | 2011-08-08 15:31:51 -0700 | [diff] [blame] | 3813 | * The opened QP handle is released by the caller. The underlying |
| 3814 | * shared QP is not destroyed until all internal references are released. |
Sean Hefty | d3d72d9 | 2011-05-26 23:06:44 -0700 | [diff] [blame] | 3815 | */ |
Sean Hefty | 0e0ec7e | 2011-08-08 15:31:51 -0700 | [diff] [blame] | 3816 | int ib_close_qp(struct ib_qp *qp); |
Sean Hefty | d3d72d9 | 2011-05-26 23:06:44 -0700 | [diff] [blame] | 3817 | |
| 3818 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | * 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 Assche | 55464d4 | 2009-12-09 14:20:04 -0800 | [diff] [blame] | 3825 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | */ |
| 3831 | static inline int ib_post_send(struct ib_qp *qp, |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 3832 | const struct ib_send_wr *send_wr, |
| 3833 | const struct ib_send_wr **bad_send_wr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | { |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 3835 | const struct ib_send_wr *dummy; |
Bart Van Assche | bb039a8 | 2018-07-18 09:25:16 -0700 | [diff] [blame] | 3836 | |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 3837 | return qp->device->ops.post_send(qp, send_wr, bad_send_wr ? : &dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | } |
| 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 | */ |
| 3848 | static inline int ib_post_recv(struct ib_qp *qp, |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 3849 | const struct ib_recv_wr *recv_wr, |
| 3850 | const struct ib_recv_wr **bad_recv_wr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | { |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 3852 | const struct ib_recv_wr *dummy; |
Bart Van Assche | bb039a8 | 2018-07-18 09:25:16 -0700 | [diff] [blame] | 3853 | |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 3854 | return qp->device->ops.post_recv(qp, recv_wr, bad_recv_wr ? : &dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3857 | struct 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 Romanovsky | f66c8ba | 2018-01-28 11:17:19 +0200 | [diff] [blame] | 3861 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3862 | /** |
| 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 | */ |
| 3871 | static 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 | */ |
| 3891 | static 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 Lever | 20cf4e0 | 2019-07-29 13:22:09 -0400 | [diff] [blame] | 3899 | struct 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 | */ |
| 3910 | static 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 Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3918 | /** |
| 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 Friedman | 3446cbd | 2020-05-27 11:34:52 +0300 | [diff] [blame] | 3922 | * |
| 3923 | * NOTE: This function shouldn't be called on shared CQs. |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3924 | */ |
| 3925 | void 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 | */ |
| 3933 | static inline void ib_free_cq(struct ib_cq *cq) |
| 3934 | { |
| 3935 | ib_free_cq_user(cq, NULL); |
| 3936 | } |
| 3937 | |
Christoph Hellwig | 14d3a3b | 2015-12-11 11:53:03 -0800 | [diff] [blame] | 3938 | int ib_process_cq_direct(struct ib_cq *cq, int budget); |
| 3939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | /** |
| 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 Barak | 8e37210 | 2015-06-11 16:35:21 +0300 | [diff] [blame] | 3949 | * @cq_attr: The attributes the CQ should be created upon. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | * |
| 3951 | * Users can examine the cq structure to determine the actual CQ size. |
| 3952 | */ |
Bharat Potnuri | 7350cdd | 2018-06-15 20:52:33 +0530 | [diff] [blame] | 3953 | struct 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | |
| 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 | */ |
| 3969 | int ib_resize_cq(struct ib_cq *cq, int cqe); |
| 3970 | |
| 3971 | /** |
Leon Romanovsky | 4190b4e | 2017-11-13 10:51:19 +0200 | [diff] [blame] | 3972 | * rdma_set_cq_moderation - Modifies moderation params of the CQ |
Eli Cohen | 2dd5716 | 2008-04-16 21:09:33 -0700 | [diff] [blame] | 3973 | * @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 Romanovsky | 4190b4e | 2017-11-13 10:51:19 +0200 | [diff] [blame] | 3978 | int rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period); |
Eli Cohen | 2dd5716 | 2008-04-16 21:09:33 -0700 | [diff] [blame] | 3979 | |
| 3980 | /** |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3981 | * ib_destroy_cq_user - Destroys the specified CQ. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | * @cq: The CQ to destroy. |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3983 | * @udata: Valid user data or NULL for kernel objects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | */ |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3985 | int 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 Romanovsky | 890ac8d | 2019-05-20 09:54:21 +0300 | [diff] [blame] | 3993 | static inline void ib_destroy_cq(struct ib_cq *cq) |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3994 | { |
Leon Romanovsky | 890ac8d | 2019-05-20 09:54:21 +0300 | [diff] [blame] | 3995 | ib_destroy_cq_user(cq, NULL); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3996 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3997 | |
| 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 | */ |
| 4010 | static inline int ib_poll_cq(struct ib_cq *cq, int num_entries, |
| 4011 | struct ib_wc *wc) |
| 4012 | { |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 4013 | return cq->device->ops.poll_cq(cq, num_entries, wc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | } |
| 4015 | |
| 4016 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | * ib_req_notify_cq - Request completion notification on a CQ. |
| 4018 | * @cq: The CQ to generate an event for. |
Roland Dreier | ed23a72 | 2007-05-06 21:02:48 -0700 | [diff] [blame] | 4019 | * @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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | */ |
| 4043 | static inline int ib_req_notify_cq(struct ib_cq *cq, |
Roland Dreier | ed23a72 | 2007-05-06 21:02:48 -0700 | [diff] [blame] | 4044 | enum ib_cq_notify_flags flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | { |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 4046 | return cq->device->ops.req_notify_cq(cq, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | } |
| 4048 | |
Yamin Friedman | c7ff819 | 2020-05-27 11:34:53 +0300 | [diff] [blame^] | 4049 | struct 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 | |
| 4053 | void ib_cq_pool_put(struct ib_cq *cq, unsigned int nr_cqe); |
| 4054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | /** |
| 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 | */ |
| 4062 | static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt) |
| 4063 | { |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 4064 | return cq->device->ops.req_ncomp_notif ? |
| 4065 | cq->device->ops.req_ncomp_notif(cq, wc_cnt) : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | -ENOSYS; |
| 4067 | } |
| 4068 | |
| 4069 | /** |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4070 | * 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 | */ |
| 4074 | static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr) |
| 4075 | { |
Bart Van Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4076 | return dma_mapping_error(dev->dma_device, dma_addr); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4077 | } |
| 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 | */ |
| 4086 | static 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 Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4090 | return dma_map_single(dev->dma_device, cpu_addr, size, direction); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4091 | } |
| 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 | */ |
| 4100 | static 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 Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4104 | dma_unmap_single(dev->dma_device, addr, size, direction); |
Arthur Kepner | cb9fbc5 | 2008-04-29 01:00:34 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4107 | /** |
| 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 | */ |
| 4115 | static 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 Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4121 | return dma_map_page(dev->dma_device, page, offset, size, direction); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4122 | } |
| 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 | */ |
| 4131 | static 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 Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4135 | dma_unmap_page(dev->dma_device, addr, size, direction); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4136 | } |
| 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 | */ |
| 4145 | static 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 Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4149 | return dma_map_sg(dev->dma_device, sg, nents, direction); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4150 | } |
| 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 | */ |
| 4159 | static 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 Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4163 | dma_unmap_sg(dev->dma_device, sg, nents, direction); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4164 | } |
| 4165 | |
Arthur Kepner | cb9fbc5 | 2008-04-29 01:00:34 -0700 | [diff] [blame] | 4166 | static inline int ib_dma_map_sg_attrs(struct ib_device *dev, |
| 4167 | struct scatterlist *sg, int nents, |
| 4168 | enum dma_data_direction direction, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 4169 | unsigned long dma_attrs) |
Arthur Kepner | cb9fbc5 | 2008-04-29 01:00:34 -0700 | [diff] [blame] | 4170 | { |
Bart Van Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4171 | return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, |
| 4172 | dma_attrs); |
Arthur Kepner | cb9fbc5 | 2008-04-29 01:00:34 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev, |
| 4176 | struct scatterlist *sg, int nents, |
| 4177 | enum dma_data_direction direction, |
Krzysztof Kozlowski | 00085f1 | 2016-08-03 13:46:00 -0700 | [diff] [blame] | 4178 | unsigned long dma_attrs) |
Arthur Kepner | cb9fbc5 | 2008-04-29 01:00:34 -0700 | [diff] [blame] | 4179 | { |
Bart Van Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4180 | dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, dma_attrs); |
Arthur Kepner | cb9fbc5 | 2008-04-29 01:00:34 -0700 | [diff] [blame] | 4181 | } |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4182 | |
| 4183 | /** |
Bart Van Assche | 0b5cb33 | 2019-01-22 10:25:20 -0800 | [diff] [blame] | 4184 | * 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 | */ |
| 4189 | static inline unsigned int ib_dma_max_seg_size(struct ib_device *dev) |
| 4190 | { |
Bart Van Assche | ecdfdfd | 2019-10-25 15:58:27 -0700 | [diff] [blame] | 4191 | return dma_get_max_seg_size(dev->dma_device); |
Bart Van Assche | 0b5cb33 | 2019-01-22 10:25:20 -0800 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | /** |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4195 | * 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 | */ |
| 4201 | static 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 Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4206 | dma_sync_single_for_cpu(dev->dma_device, addr, size, dir); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4207 | } |
| 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 | */ |
| 4216 | static 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 Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4221 | dma_sync_single_for_device(dev->dma_device, addr, size, dir); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4222 | } |
| 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 | */ |
| 4231 | static inline void *ib_dma_alloc_coherent(struct ib_device *dev, |
| 4232 | size_t size, |
Bart Van Assche | d43dbac | 2017-01-20 13:04:10 -0800 | [diff] [blame] | 4233 | dma_addr_t *dma_handle, |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4234 | gfp_t flag) |
| 4235 | { |
Bart Van Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4236 | return dma_alloc_coherent(dev->dma_device, size, dma_handle, flag); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4237 | } |
| 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 | */ |
| 4246 | static inline void ib_dma_free_coherent(struct ib_device *dev, |
| 4247 | size_t size, void *cpu_addr, |
Bart Van Assche | d43dbac | 2017-01-20 13:04:10 -0800 | [diff] [blame] | 4248 | dma_addr_t dma_handle) |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4249 | { |
Bart Van Assche | 0957c29 | 2017-03-07 22:56:53 +0000 | [diff] [blame] | 4250 | dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle); |
Ralph Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4251 | } |
| 4252 | |
Moni Shoua | 33006bd | 2020-01-15 14:43:32 +0200 | [diff] [blame] | 4253 | /* 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 | */ |
| 4256 | struct ib_mr *ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, |
| 4257 | u64 virt_addr, int mr_access_flags); |
| 4258 | |
Moni Shoua | 87d8069f | 2020-01-15 14:43:33 +0200 | [diff] [blame] | 4259 | /* ib_advise_mr - give an advice about an address range in a memory region */ |
| 4260 | int 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 Campbell | 9b51309 | 2006-12-12 14:27:41 -0800 | [diff] [blame] | 4262 | /** |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4263 | * 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 | */ |
| 4270 | int 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | * HCA translation table. |
| 4275 | * @mr: The memory region to deregister. |
Shani Michaeli | 7083e42 | 2013-02-06 16:19:12 +0000 | [diff] [blame] | 4276 | * |
| 4277 | * This function can fail, if the memory region has memory windows bound to it. |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4278 | * |
| 4279 | * NOTE: for user mr use ib_dereg_mr_user with valid udata! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | */ |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4281 | static inline int ib_dereg_mr(struct ib_mr *mr) |
| 4282 | { |
| 4283 | return ib_dereg_mr_user(mr, NULL); |
| 4284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4286 | struct 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 | |
| 4289 | static 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 Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 4294 | |
Israel Rukshin | 26bc7ea | 2019-06-11 18:52:39 +0300 | [diff] [blame] | 4295 | struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd, |
| 4296 | u32 max_num_data_sg, |
| 4297 | u32 max_num_meta_sg); |
| 4298 | |
Steve Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 4299 | /** |
Steve Wise | 00f7ec3 | 2008-07-14 23:48:45 -0700 | [diff] [blame] | 4300 | * 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 | */ |
| 4305 | static 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 Michaeli | 7083e42 | 2013-02-06 16:19:12 +0000 | [diff] [blame] | 4312 | * 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 | */ |
| 4316 | static inline u32 ib_inc_rkey(u32 rkey) |
| 4317 | { |
| 4318 | const u32 mask = 0x000000ff; |
| 4319 | return ((rkey + 1) & mask) | (rkey & ~mask); |
| 4320 | } |
| 4321 | |
| 4322 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | * 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 | */ |
| 4331 | struct 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 | */ |
| 4342 | static inline int ib_map_phys_fmr(struct ib_fmr *fmr, |
| 4343 | u64 *page_list, int list_len, |
| 4344 | u64 iova) |
| 4345 | { |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 4346 | return fmr->device->ops.map_phys_fmr(fmr, page_list, list_len, iova); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | } |
| 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 | */ |
| 4353 | int 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 | */ |
| 4359 | int 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 | */ |
| 4373 | int 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 | */ |
| 4381 | int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); |
| 4382 | |
Sean Hefty | 59991f9 | 2011-05-23 17:52:46 -0700 | [diff] [blame] | 4383 | /** |
| 4384 | * ib_alloc_xrcd - Allocates an XRC domain. |
| 4385 | * @device: The device on which to allocate the XRC domain. |
Leon Romanovsky | f66c8ba | 2018-01-28 11:17:19 +0200 | [diff] [blame] | 4386 | * @caller: Module name for kernel consumers |
Sean Hefty | 59991f9 | 2011-05-23 17:52:46 -0700 | [diff] [blame] | 4387 | */ |
Leon Romanovsky | f66c8ba | 2018-01-28 11:17:19 +0200 | [diff] [blame] | 4388 | struct 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 Hefty | 59991f9 | 2011-05-23 17:52:46 -0700 | [diff] [blame] | 4391 | |
| 4392 | /** |
| 4393 | * ib_dealloc_xrcd - Deallocates an XRC domain. |
| 4394 | * @xrcd: The XRC domain to deallocate. |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4395 | * @udata: Valid user data or NULL for kernel object |
Sean Hefty | 59991f9 | 2011-05-23 17:52:46 -0700 | [diff] [blame] | 4396 | */ |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4397 | int ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata); |
Sean Hefty | 59991f9 | 2011-05-23 17:52:46 -0700 | [diff] [blame] | 4398 | |
Eli Cohen | 1c636f8 | 2013-10-31 15:26:32 +0200 | [diff] [blame] | 4399 | static 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 Guralnik | ca95c14 | 2020-01-08 20:05:35 +0200 | [diff] [blame] | 4409 | if (flags & ~IB_ACCESS_SUPPORTED) |
| 4410 | return -EINVAL; |
| 4411 | |
Eli Cohen | 1c636f8 | 2013-10-31 15:26:32 +0200 | [diff] [blame] | 4412 | return 0; |
| 4413 | } |
| 4414 | |
Jack Morgenstein | 08bb558 | 2018-05-23 15:30:30 +0300 | [diff] [blame] | 4415 | static 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 Grimberg | 1b01d33 | 2014-02-23 14:19:05 +0200 | [diff] [blame] | 4429 | /** |
| 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 | */ |
| 4441 | int ib_check_mr_status(struct ib_mr *mr, u32 check_mask, |
| 4442 | struct ib_mr_status *mr_status); |
| 4443 | |
Jason Gunthorpe | d79af72 | 2019-01-10 14:02:24 -0700 | [diff] [blame] | 4444 | /** |
| 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 | */ |
| 4457 | static inline bool ib_device_try_get(struct ib_device *dev) |
| 4458 | { |
| 4459 | return refcount_inc_not_zero(&dev->refcount); |
| 4460 | } |
| 4461 | |
| 4462 | void ib_device_put(struct ib_device *device); |
Jason Gunthorpe | 324e227 | 2019-02-12 21:12:51 -0700 | [diff] [blame] | 4463 | struct ib_device *ib_device_get_by_netdev(struct net_device *ndev, |
| 4464 | enum rdma_driver_id driver_id); |
| 4465 | struct ib_device *ib_device_get_by_name(const char *name, |
| 4466 | enum rdma_driver_id driver_id); |
Yotam Kenneth | 9268f72 | 2015-07-30 17:50:15 +0300 | [diff] [blame] | 4467 | struct 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 Gunthorpe | c2261dd | 2019-02-12 21:12:50 -0700 | [diff] [blame] | 4470 | int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev, |
| 4471 | unsigned int port); |
| 4472 | struct net_device *ib_device_netdev(struct ib_device *dev, u8 port); |
| 4473 | |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 4474 | struct ib_wq *ib_create_wq(struct ib_pd *pd, |
| 4475 | struct ib_wq_init_attr *init_attr); |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 4476 | int ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata); |
Yishai Hadas | 5fd251c | 2016-05-23 15:20:48 +0300 | [diff] [blame] | 4477 | int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr, |
| 4478 | u32 wq_attr_mask); |
Yishai Hadas | 6d39786 | 2016-05-23 15:20:51 +0300 | [diff] [blame] | 4479 | struct 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); |
| 4482 | int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table); |
Yotam Kenneth | 9268f72 | 2015-07-30 17:50:15 +0300 | [diff] [blame] | 4483 | |
Christoph Hellwig | ff2ba99 | 2016-05-03 18:01:04 +0200 | [diff] [blame] | 4484 | int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents, |
Bart Van Assche | 9aa8b32 | 2016-05-12 10:49:15 -0700 | [diff] [blame] | 4485 | unsigned int *sg_offset, unsigned int page_size); |
Max Gurtovoy | 2cdfcdd | 2019-06-11 18:52:40 +0300 | [diff] [blame] | 4486 | int 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 Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 4490 | |
| 4491 | static inline int |
Christoph Hellwig | ff2ba99 | 2016-05-03 18:01:04 +0200 | [diff] [blame] | 4492 | ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents, |
Bart Van Assche | 9aa8b32 | 2016-05-12 10:49:15 -0700 | [diff] [blame] | 4493 | unsigned int *sg_offset, unsigned int page_size) |
Sagi Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 4494 | { |
| 4495 | int n; |
| 4496 | |
Christoph Hellwig | ff2ba99 | 2016-05-03 18:01:04 +0200 | [diff] [blame] | 4497 | n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size); |
Sagi Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 4498 | mr->iova = 0; |
| 4499 | |
| 4500 | return n; |
| 4501 | } |
| 4502 | |
Christoph Hellwig | ff2ba99 | 2016-05-03 18:01:04 +0200 | [diff] [blame] | 4503 | int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents, |
Bart Van Assche | 9aa8b32 | 2016-05-12 10:49:15 -0700 | [diff] [blame] | 4504 | unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64)); |
Sagi Grimberg | 4c67e2b | 2015-10-13 19:11:24 +0300 | [diff] [blame] | 4505 | |
Steve Wise | 765d677 | 2016-02-17 08:15:41 -0800 | [diff] [blame] | 4506 | void ib_drain_rq(struct ib_qp *qp); |
| 4507 | void ib_drain_sq(struct ib_qp *qp); |
| 4508 | void ib_drain_qp(struct ib_qp *qp); |
Moni Shoua | 850d8fd | 2016-11-10 11:30:56 +0200 | [diff] [blame] | 4509 | |
Yuval Shaia | d418619 | 2017-06-14 23:13:34 +0300 | [diff] [blame] | 4510 | int ib_get_eth_speed(struct ib_device *dev, u8 port_num, u8 *speed, u8 *width); |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4511 | |
| 4512 | static inline u8 *rdma_ah_retrieve_dmac(struct rdma_ah_attr *attr) |
| 4513 | { |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4514 | if (attr->type == RDMA_AH_ATTR_TYPE_ROCE) |
| 4515 | return attr->roce.dmac; |
| 4516 | return NULL; |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4517 | } |
| 4518 | |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 4519 | static inline void rdma_ah_set_dlid(struct rdma_ah_attr *attr, u32 dlid) |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4520 | { |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4521 | if (attr->type == RDMA_AH_ATTR_TYPE_IB) |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 4522 | attr->ib.dlid = (u16)dlid; |
| 4523 | else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) |
| 4524 | attr->opa.dlid = dlid; |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4525 | } |
| 4526 | |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 4527 | static inline u32 rdma_ah_get_dlid(const struct rdma_ah_attr *attr) |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4528 | { |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4529 | if (attr->type == RDMA_AH_ATTR_TYPE_IB) |
| 4530 | return attr->ib.dlid; |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 4531 | else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) |
| 4532 | return attr->opa.dlid; |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4533 | return 0; |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | static inline void rdma_ah_set_sl(struct rdma_ah_attr *attr, u8 sl) |
| 4537 | { |
| 4538 | attr->sl = sl; |
| 4539 | } |
| 4540 | |
| 4541 | static inline u8 rdma_ah_get_sl(const struct rdma_ah_attr *attr) |
| 4542 | { |
| 4543 | return attr->sl; |
| 4544 | } |
| 4545 | |
| 4546 | static inline void rdma_ah_set_path_bits(struct rdma_ah_attr *attr, |
| 4547 | u8 src_path_bits) |
| 4548 | { |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4549 | if (attr->type == RDMA_AH_ATTR_TYPE_IB) |
| 4550 | attr->ib.src_path_bits = src_path_bits; |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 4551 | else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) |
| 4552 | attr->opa.src_path_bits = src_path_bits; |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | static inline u8 rdma_ah_get_path_bits(const struct rdma_ah_attr *attr) |
| 4556 | { |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4557 | if (attr->type == RDMA_AH_ATTR_TYPE_IB) |
| 4558 | return attr->ib.src_path_bits; |
Dasaratharaman Chandramouli | 64b4646 | 2017-04-29 14:41:30 -0400 | [diff] [blame] | 4559 | else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) |
| 4560 | return attr->opa.src_path_bits; |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4561 | return 0; |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4562 | } |
| 4563 | |
Don Hiatt | d98bb7f | 2017-08-04 13:54:16 -0700 | [diff] [blame] | 4564 | static 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 | |
| 4571 | static 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 Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4578 | static inline void rdma_ah_set_port_num(struct rdma_ah_attr *attr, u8 port_num) |
| 4579 | { |
| 4580 | attr->port_num = port_num; |
| 4581 | } |
| 4582 | |
| 4583 | static inline u8 rdma_ah_get_port_num(const struct rdma_ah_attr *attr) |
| 4584 | { |
| 4585 | return attr->port_num; |
| 4586 | } |
| 4587 | |
| 4588 | static 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 | |
| 4594 | static inline u8 rdma_ah_get_static_rate(const struct rdma_ah_attr *attr) |
| 4595 | { |
| 4596 | return attr->static_rate; |
| 4597 | } |
| 4598 | |
| 4599 | static 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 | |
| 4605 | static 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 | |
| 4611 | static 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 */ |
| 4618 | static inline struct ib_global_route |
| 4619 | *rdma_ah_retrieve_grh(struct rdma_ah_attr *attr) |
| 4620 | { |
| 4621 | return &attr->grh; |
| 4622 | } |
| 4623 | |
| 4624 | static 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 | |
| 4631 | static 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 | |
| 4639 | static 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 | |
| 4647 | static 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 Gunthorpe | 8d9ec9a | 2018-06-13 10:22:03 +0300 | [diff] [blame] | 4661 | grh->sgid_attr = NULL; |
Dasaratharaman Chandramouli | 2224c47 | 2017-04-29 14:41:27 -0400 | [diff] [blame] | 4662 | } |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4663 | |
Jason Gunthorpe | 8d9ec9a | 2018-06-13 10:22:03 +0300 | [diff] [blame] | 4664 | void rdma_destroy_ah_attr(struct rdma_ah_attr *ah_attr); |
| 4665 | void 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 Gunthorpe | d97099f | 2018-06-13 10:22:05 +0300 | [diff] [blame] | 4668 | void rdma_copy_ah_attr(struct rdma_ah_attr *dest, |
| 4669 | const struct rdma_ah_attr *src); |
| 4670 | void rdma_replace_ah_attr(struct rdma_ah_attr *old, |
| 4671 | const struct rdma_ah_attr *new); |
| 4672 | void rdma_move_ah_attr(struct rdma_ah_attr *dest, struct rdma_ah_attr *src); |
Jason Gunthorpe | 8d9ec9a | 2018-06-13 10:22:03 +0300 | [diff] [blame] | 4673 | |
Don Hiatt | 87daac6 | 2018-02-01 10:57:03 -0800 | [diff] [blame] | 4674 | /** |
| 4675 | * rdma_ah_find_type - Return address handle type. |
| 4676 | * |
| 4677 | * @dev: Device to be checked |
| 4678 | * @port_num: Port number |
| 4679 | */ |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4680 | static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev, |
Don Hiatt | 87daac6 | 2018-02-01 10:57:03 -0800 | [diff] [blame] | 4681 | u8 port_num) |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4682 | { |
Parav Pandit | a6532e7 | 2018-01-12 07:58:42 +0200 | [diff] [blame] | 4683 | if (rdma_protocol_roce(dev, port_num)) |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4684 | return RDMA_AH_ATTR_TYPE_ROCE; |
Don Hiatt | 87daac6 | 2018-02-01 10:57:03 -0800 | [diff] [blame] | 4685 | if (rdma_protocol_ib(dev, port_num)) { |
| 4686 | if (rdma_cap_opa_ah(dev, port_num)) |
| 4687 | return RDMA_AH_ATTR_TYPE_OPA; |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4688 | return RDMA_AH_ATTR_TYPE_IB; |
Don Hiatt | 87daac6 | 2018-02-01 10:57:03 -0800 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | return RDMA_AH_ATTR_TYPE_UNDEFINED; |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 4692 | } |
Hiatt, Don | 7db20ec | 2017-06-08 13:37:49 -0400 | [diff] [blame] | 4693 | |
Hiatt, Don | 62ede77 | 2017-08-14 14:17:43 -0400 | [diff] [blame] | 4694 | /** |
| 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 | */ |
| 4703 | static inline u16 ib_lid_cpu16(u32 lid) |
Hiatt, Don | 7db20ec | 2017-06-08 13:37:49 -0400 | [diff] [blame] | 4704 | { |
Hiatt, Don | 62ede77 | 2017-08-14 14:17:43 -0400 | [diff] [blame] | 4705 | WARN_ON_ONCE(lid & 0xFFFF0000); |
| 4706 | return (u16)lid; |
Hiatt, Don | 7db20ec | 2017-06-08 13:37:49 -0400 | [diff] [blame] | 4707 | } |
| 4708 | |
Hiatt, Don | 62ede77 | 2017-08-14 14:17:43 -0400 | [diff] [blame] | 4709 | /** |
| 4710 | * ib_lid_be16 - Return lid in 16bit BE encoding. |
| 4711 | * |
| 4712 | * @lid: A 32bit LID |
| 4713 | */ |
| 4714 | static inline __be16 ib_lid_be16(u32 lid) |
Hiatt, Don | 7db20ec | 2017-06-08 13:37:49 -0400 | [diff] [blame] | 4715 | { |
Hiatt, Don | 62ede77 | 2017-08-14 14:17:43 -0400 | [diff] [blame] | 4716 | WARN_ON_ONCE(lid & 0xFFFF0000); |
| 4717 | return cpu_to_be16((u16)lid); |
Hiatt, Don | 7db20ec | 2017-06-08 13:37:49 -0400 | [diff] [blame] | 4718 | } |
Doug Ledford | 3204383 | 2017-08-10 14:31:29 -0400 | [diff] [blame] | 4719 | |
Sagi Grimberg | c66cd35 | 2017-07-13 11:09:41 +0300 | [diff] [blame] | 4720 | /** |
| 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 | */ |
| 4730 | static inline const struct cpumask * |
| 4731 | ib_get_vector_affinity(struct ib_device *device, int comp_vector) |
| 4732 | { |
| 4733 | if (comp_vector < 0 || comp_vector >= device->num_comp_vectors || |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 4734 | !device->ops.get_vector_affinity) |
Sagi Grimberg | c66cd35 | 2017-07-13 11:09:41 +0300 | [diff] [blame] | 4735 | return NULL; |
| 4736 | |
Kamal Heib | 3023a1e | 2018-12-10 21:09:48 +0200 | [diff] [blame] | 4737 | return device->ops.get_vector_affinity(device, comp_vector); |
Sagi Grimberg | c66cd35 | 2017-07-13 11:09:41 +0300 | [diff] [blame] | 4738 | |
| 4739 | } |
| 4740 | |
Daniel Jurgens | 32f69e4 | 2018-01-04 17:25:36 +0200 | [diff] [blame] | 4741 | /** |
| 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 | */ |
| 4747 | void rdma_roce_rescan_device(struct ib_device *ibdev); |
| 4748 | |
Jason Gunthorpe | 8313c10 | 2018-11-25 20:51:13 +0200 | [diff] [blame] | 4749 | struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile); |
Yishai Hadas | 7dc08dc | 2018-06-17 12:59:59 +0300 | [diff] [blame] | 4750 | |
Jason Gunthorpe | 15a1b4b | 2018-11-25 20:51:15 +0200 | [diff] [blame] | 4751 | int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs); |
Denis Drozdov | f6a8a19 | 2018-08-14 14:08:51 +0300 | [diff] [blame] | 4752 | |
| 4753 | struct 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 Drozdov | 5d6b0cb | 2018-08-14 14:22:35 +0300 | [diff] [blame] | 4757 | |
| 4758 | int 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 Pandit | d4122f5 | 2018-10-11 22:31:53 +0300 | [diff] [blame] | 4764 | /** |
| 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 | */ |
| 4779 | static inline void |
| 4780 | rdma_set_device_sysfs_group(struct ib_device *dev, |
| 4781 | const struct attribute_group *group) |
| 4782 | { |
| 4783 | dev->groups[1] = group; |
| 4784 | } |
| 4785 | |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4786 | /** |
| 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 | */ |
| 4794 | static inline struct ib_device *rdma_device_to_ibdev(struct device *device) |
| 4795 | { |
Parav Pandit | cebe556 | 2019-02-26 13:56:11 +0200 | [diff] [blame] | 4796 | struct ib_core_device *coredev = |
| 4797 | container_of(device, struct ib_core_device, dev); |
| 4798 | |
| 4799 | return coredev->owner; |
Parav Pandit | 5474723 | 2018-12-18 14:15:56 +0200 | [diff] [blame] | 4800 | } |
| 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 Pandit | 41c6140 | 2019-02-26 14:01:46 +0200 | [diff] [blame] | 4812 | |
| 4813 | bool rdma_dev_access_netns(const struct ib_device *device, |
| 4814 | const struct net *net); |
Mark Zhang | d5665a2 | 2020-05-04 08:19:31 +0300 | [diff] [blame] | 4815 | |
| 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 | */ |
| 4827 | static 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 | */ |
| 4850 | static 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | #endif /* IB_VERBS_H */ |