]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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. | |
2a1d9b7f | 7 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
f7c6a7b5 | 8 | * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved. |
1da177e4 LT |
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. | |
1da177e4 LT |
37 | */ |
38 | ||
39 | #if !defined(IB_VERBS_H) | |
40 | #define IB_VERBS_H | |
41 | ||
42 | #include <linux/types.h> | |
43 | #include <linux/device.h> | |
9b513090 | 44 | #include <linux/dma-mapping.h> |
459d6e2a | 45 | #include <linux/kref.h> |
bfb3ea12 DB |
46 | #include <linux/list.h> |
47 | #include <linux/rwsem.h> | |
f0626710 | 48 | #include <linux/workqueue.h> |
14d3a3b2 | 49 | #include <linux/irq_poll.h> |
dd5f03be | 50 | #include <uapi/linux/if_ether.h> |
c865f246 SK |
51 | #include <net/ipv6.h> |
52 | #include <net/ip.h> | |
301a721e MB |
53 | #include <linux/string.h> |
54 | #include <linux/slab.h> | |
2fc77572 | 55 | #include <linux/netdevice.h> |
01b67117 | 56 | #include <linux/refcount.h> |
50174a7f | 57 | #include <linux/if_link.h> |
60063497 | 58 | #include <linux/atomic.h> |
882214e2 | 59 | #include <linux/mmu_notifier.h> |
7c0f6ba6 | 60 | #include <linux/uaccess.h> |
43579b5f | 61 | #include <linux/cgroup_rdma.h> |
f6316032 LR |
62 | #include <linux/irqflags.h> |
63 | #include <linux/preempt.h> | |
da662979 | 64 | #include <linux/dim.h> |
ea6819e1 | 65 | #include <uapi/rdma/ib_user_verbs.h> |
413d3347 | 66 | #include <rdma/rdma_counter.h> |
02d8883f | 67 | #include <rdma/restrack.h> |
36b1e47f | 68 | #include <rdma/signature.h> |
0ede73bc | 69 | #include <uapi/rdma/rdma_user_ioctl.h> |
2eb9beae | 70 | #include <uapi/rdma/ib_user_ioctl_verbs.h> |
1da177e4 | 71 | |
9abb0d1b LR |
72 | #define IB_FW_VERSION_NAME_MAX ETHTOOL_FWVERS_LEN |
73 | ||
b5231b01 JG |
74 | struct ib_umem_odp; |
75 | ||
f0626710 | 76 | extern struct workqueue_struct *ib_wq; |
14d3a3b2 | 77 | extern struct workqueue_struct *ib_comp_wq; |
f794809a | 78 | extern struct workqueue_struct *ib_comp_unbound_wq; |
f0626710 | 79 | |
923abb9d GP |
80 | __printf(3, 4) __cold |
81 | void ibdev_printk(const char *level, const struct ib_device *ibdev, | |
82 | const char *format, ...); | |
83 | __printf(2, 3) __cold | |
84 | void ibdev_emerg(const struct ib_device *ibdev, const char *format, ...); | |
85 | __printf(2, 3) __cold | |
86 | void ibdev_alert(const struct ib_device *ibdev, const char *format, ...); | |
87 | __printf(2, 3) __cold | |
88 | void ibdev_crit(const struct ib_device *ibdev, const char *format, ...); | |
89 | __printf(2, 3) __cold | |
90 | void ibdev_err(const struct ib_device *ibdev, const char *format, ...); | |
91 | __printf(2, 3) __cold | |
92 | void ibdev_warn(const struct ib_device *ibdev, const char *format, ...); | |
93 | __printf(2, 3) __cold | |
94 | void ibdev_notice(const struct ib_device *ibdev, const char *format, ...); | |
95 | __printf(2, 3) __cold | |
96 | void ibdev_info(const struct ib_device *ibdev, const char *format, ...); | |
97 | ||
98 | #if defined(CONFIG_DYNAMIC_DEBUG) | |
99 | #define ibdev_dbg(__dev, format, args...) \ | |
100 | dynamic_ibdev_dbg(__dev, format, ##args) | |
101 | #elif defined(DEBUG) | |
102 | #define ibdev_dbg(__dev, format, args...) \ | |
103 | ibdev_printk(KERN_DEBUG, __dev, format, ##args) | |
104 | #else | |
105 | __printf(2, 3) __cold | |
106 | static inline | |
107 | void ibdev_dbg(const struct ib_device *ibdev, const char *format, ...) {} | |
108 | #endif | |
109 | ||
05bb411a GP |
110 | #define ibdev_level_ratelimited(ibdev_level, ibdev, fmt, ...) \ |
111 | do { \ | |
112 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
113 | DEFAULT_RATELIMIT_INTERVAL, \ | |
114 | DEFAULT_RATELIMIT_BURST); \ | |
115 | if (__ratelimit(&_rs)) \ | |
116 | ibdev_level(ibdev, fmt, ##__VA_ARGS__); \ | |
117 | } while (0) | |
118 | ||
119 | #define ibdev_emerg_ratelimited(ibdev, fmt, ...) \ | |
120 | ibdev_level_ratelimited(ibdev_emerg, ibdev, fmt, ##__VA_ARGS__) | |
121 | #define ibdev_alert_ratelimited(ibdev, fmt, ...) \ | |
122 | ibdev_level_ratelimited(ibdev_alert, ibdev, fmt, ##__VA_ARGS__) | |
123 | #define ibdev_crit_ratelimited(ibdev, fmt, ...) \ | |
124 | ibdev_level_ratelimited(ibdev_crit, ibdev, fmt, ##__VA_ARGS__) | |
125 | #define ibdev_err_ratelimited(ibdev, fmt, ...) \ | |
126 | ibdev_level_ratelimited(ibdev_err, ibdev, fmt, ##__VA_ARGS__) | |
127 | #define ibdev_warn_ratelimited(ibdev, fmt, ...) \ | |
128 | ibdev_level_ratelimited(ibdev_warn, ibdev, fmt, ##__VA_ARGS__) | |
129 | #define ibdev_notice_ratelimited(ibdev, fmt, ...) \ | |
130 | ibdev_level_ratelimited(ibdev_notice, ibdev, fmt, ##__VA_ARGS__) | |
131 | #define ibdev_info_ratelimited(ibdev, fmt, ...) \ | |
132 | ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__) | |
133 | ||
134 | #if defined(CONFIG_DYNAMIC_DEBUG) | |
135 | /* descriptor check is first to prevent flooding with "callbacks suppressed" */ | |
136 | #define ibdev_dbg_ratelimited(ibdev, fmt, ...) \ | |
137 | do { \ | |
138 | static DEFINE_RATELIMIT_STATE(_rs, \ | |
139 | DEFAULT_RATELIMIT_INTERVAL, \ | |
140 | DEFAULT_RATELIMIT_BURST); \ | |
141 | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ | |
142 | if (DYNAMIC_DEBUG_BRANCH(descriptor) && __ratelimit(&_rs)) \ | |
143 | __dynamic_ibdev_dbg(&descriptor, ibdev, fmt, \ | |
144 | ##__VA_ARGS__); \ | |
145 | } while (0) | |
146 | #else | |
147 | __printf(2, 3) __cold | |
148 | static inline | |
149 | void ibdev_dbg_ratelimited(const struct ib_device *ibdev, const char *format, ...) {} | |
150 | #endif | |
151 | ||
1da177e4 LT |
152 | union ib_gid { |
153 | u8 raw[16]; | |
154 | struct { | |
97f52eb4 SH |
155 | __be64 subnet_prefix; |
156 | __be64 interface_id; | |
1da177e4 LT |
157 | } global; |
158 | }; | |
159 | ||
e26be1bf MS |
160 | extern union ib_gid zgid; |
161 | ||
b39ffa1d MB |
162 | enum ib_gid_type { |
163 | /* If link layer is Ethernet, this is RoCE V1 */ | |
164 | IB_GID_TYPE_IB = 0, | |
165 | IB_GID_TYPE_ROCE = 0, | |
7766a99f | 166 | IB_GID_TYPE_ROCE_UDP_ENCAP = 1, |
b39ffa1d MB |
167 | IB_GID_TYPE_SIZE |
168 | }; | |
169 | ||
7ead4bcb | 170 | #define ROCE_V2_UDP_DPORT 4791 |
03db3a2d | 171 | struct ib_gid_attr { |
943bd984 | 172 | struct net_device __rcu *ndev; |
598ff6ba | 173 | struct ib_device *device; |
b150c386 | 174 | union ib_gid gid; |
598ff6ba PP |
175 | enum ib_gid_type gid_type; |
176 | u16 index; | |
177 | u8 port_num; | |
03db3a2d MB |
178 | }; |
179 | ||
a0c1b2a3 EC |
180 | enum { |
181 | /* set the local administered indication */ | |
182 | IB_SA_WELL_KNOWN_GUID = BIT_ULL(57) | 2, | |
183 | }; | |
184 | ||
07ebafba TT |
185 | enum rdma_transport_type { |
186 | RDMA_TRANSPORT_IB, | |
180771a3 | 187 | RDMA_TRANSPORT_IWARP, |
248567f7 | 188 | RDMA_TRANSPORT_USNIC, |
f95be3d2 GP |
189 | RDMA_TRANSPORT_USNIC_UDP, |
190 | RDMA_TRANSPORT_UNSPECIFIED, | |
07ebafba TT |
191 | }; |
192 | ||
6b90a6d6 MW |
193 | enum rdma_protocol_type { |
194 | RDMA_PROTOCOL_IB, | |
195 | RDMA_PROTOCOL_IBOE, | |
196 | RDMA_PROTOCOL_IWARP, | |
197 | RDMA_PROTOCOL_USNIC_UDP | |
198 | }; | |
199 | ||
8385fd84 | 200 | __attribute_const__ enum rdma_transport_type |
5d60c111 | 201 | rdma_node_get_transport(unsigned int node_type); |
07ebafba | 202 | |
c865f246 SK |
203 | enum rdma_network_type { |
204 | RDMA_NETWORK_IB, | |
205 | RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB, | |
206 | RDMA_NETWORK_IPV4, | |
207 | RDMA_NETWORK_IPV6 | |
208 | }; | |
209 | ||
210 | static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type) | |
211 | { | |
212 | if (network_type == RDMA_NETWORK_IPV4 || | |
213 | network_type == RDMA_NETWORK_IPV6) | |
214 | return IB_GID_TYPE_ROCE_UDP_ENCAP; | |
215 | ||
216 | /* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */ | |
217 | return IB_GID_TYPE_IB; | |
218 | } | |
219 | ||
47ec3866 PP |
220 | static inline enum rdma_network_type |
221 | rdma_gid_attr_network_type(const struct ib_gid_attr *attr) | |
c865f246 | 222 | { |
47ec3866 | 223 | if (attr->gid_type == IB_GID_TYPE_IB) |
c865f246 SK |
224 | return RDMA_NETWORK_IB; |
225 | ||
47ec3866 | 226 | if (ipv6_addr_v4mapped((struct in6_addr *)&attr->gid)) |
c865f246 SK |
227 | return RDMA_NETWORK_IPV4; |
228 | else | |
229 | return RDMA_NETWORK_IPV6; | |
230 | } | |
231 | ||
a3f5adaf EC |
232 | enum rdma_link_layer { |
233 | IB_LINK_LAYER_UNSPECIFIED, | |
234 | IB_LINK_LAYER_INFINIBAND, | |
235 | IB_LINK_LAYER_ETHERNET, | |
236 | }; | |
237 | ||
1da177e4 | 238 | enum ib_device_cap_flags { |
7ca0bc53 LR |
239 | IB_DEVICE_RESIZE_MAX_WR = (1 << 0), |
240 | IB_DEVICE_BAD_PKEY_CNTR = (1 << 1), | |
241 | IB_DEVICE_BAD_QKEY_CNTR = (1 << 2), | |
242 | IB_DEVICE_RAW_MULTI = (1 << 3), | |
243 | IB_DEVICE_AUTO_PATH_MIG = (1 << 4), | |
244 | IB_DEVICE_CHANGE_PHY_PORT = (1 << 5), | |
245 | IB_DEVICE_UD_AV_PORT_ENFORCE = (1 << 6), | |
246 | IB_DEVICE_CURR_QP_STATE_MOD = (1 << 7), | |
247 | IB_DEVICE_SHUTDOWN_PORT = (1 << 8), | |
78b57f95 | 248 | /* Not in use, former INIT_TYPE = (1 << 9),*/ |
7ca0bc53 LR |
249 | IB_DEVICE_PORT_ACTIVE_EVENT = (1 << 10), |
250 | IB_DEVICE_SYS_IMAGE_GUID = (1 << 11), | |
251 | IB_DEVICE_RC_RNR_NAK_GEN = (1 << 12), | |
252 | IB_DEVICE_SRQ_RESIZE = (1 << 13), | |
253 | IB_DEVICE_N_NOTIFY_CQ = (1 << 14), | |
b1adc714 CH |
254 | |
255 | /* | |
256 | * This device supports a per-device lkey or stag that can be | |
257 | * used without performing a memory registration for the local | |
258 | * memory. Note that ULPs should never check this flag, but | |
259 | * instead of use the local_dma_lkey flag in the ib_pd structure, | |
260 | * which will always contain a usable lkey. | |
261 | */ | |
7ca0bc53 | 262 | IB_DEVICE_LOCAL_DMA_LKEY = (1 << 15), |
78b57f95 | 263 | /* Reserved, old SEND_W_INV = (1 << 16),*/ |
7ca0bc53 | 264 | IB_DEVICE_MEM_WINDOW = (1 << 17), |
e0605d91 EC |
265 | /* |
266 | * Devices should set IB_DEVICE_UD_IP_SUM if they support | |
267 | * insertion of UDP and TCP checksum on outgoing UD IPoIB | |
268 | * messages and can verify the validity of checksum for | |
269 | * incoming messages. Setting this flag implies that the | |
270 | * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode. | |
271 | */ | |
7ca0bc53 LR |
272 | IB_DEVICE_UD_IP_CSUM = (1 << 18), |
273 | IB_DEVICE_UD_TSO = (1 << 19), | |
274 | IB_DEVICE_XRC = (1 << 20), | |
b1adc714 CH |
275 | |
276 | /* | |
277 | * This device supports the IB "base memory management extension", | |
278 | * which includes support for fast registrations (IB_WR_REG_MR, | |
279 | * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs). This flag should | |
280 | * also be set by any iWarp device which must support FRs to comply | |
281 | * to the iWarp verbs spec. iWarp devices also support the | |
282 | * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the | |
283 | * stag. | |
284 | */ | |
7ca0bc53 LR |
285 | IB_DEVICE_MEM_MGT_EXTENSIONS = (1 << 21), |
286 | IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1 << 22), | |
287 | IB_DEVICE_MEM_WINDOW_TYPE_2A = (1 << 23), | |
288 | IB_DEVICE_MEM_WINDOW_TYPE_2B = (1 << 24), | |
289 | IB_DEVICE_RC_IP_CSUM = (1 << 25), | |
ebaaee25 | 290 | /* Deprecated. Please use IB_RAW_PACKET_CAP_IP_CSUM. */ |
7ca0bc53 | 291 | IB_DEVICE_RAW_IP_CSUM = (1 << 26), |
8a06ce59 LR |
292 | /* |
293 | * Devices should set IB_DEVICE_CROSS_CHANNEL if they | |
294 | * support execution of WQEs that involve synchronization | |
295 | * of I/O operations with single completion queue managed | |
296 | * by hardware. | |
297 | */ | |
78b57f95 | 298 | IB_DEVICE_CROSS_CHANNEL = (1 << 27), |
7ca0bc53 | 299 | IB_DEVICE_MANAGED_FLOW_STEERING = (1 << 29), |
c0a6cbb9 | 300 | IB_DEVICE_INTEGRITY_HANDOVER = (1 << 30), |
47355b3c | 301 | IB_DEVICE_ON_DEMAND_PAGING = (1ULL << 31), |
f5aa9159 | 302 | IB_DEVICE_SG_GAPS_REG = (1ULL << 32), |
c7e162a4 | 303 | IB_DEVICE_VIRTUAL_FUNCTION = (1ULL << 33), |
ebaaee25 | 304 | /* Deprecated. Please use IB_RAW_PACKET_CAP_SCATTER_FCS. */ |
c7e162a4 | 305 | IB_DEVICE_RAW_SCATTER_FCS = (1ULL << 34), |
62e45949 | 306 | IB_DEVICE_RDMA_NETDEV_OPA_VNIC = (1ULL << 35), |
e1d2e887 NO |
307 | /* The device supports padding incoming writes to cacheline. */ |
308 | IB_DEVICE_PCI_WRITE_END_PADDING = (1ULL << 36), | |
3856ec4b | 309 | IB_DEVICE_ALLOW_USER_UNREG = (1ULL << 37), |
1b01d335 SG |
310 | }; |
311 | ||
1da177e4 LT |
312 | enum ib_atomic_cap { |
313 | IB_ATOMIC_NONE, | |
314 | IB_ATOMIC_HCA, | |
315 | IB_ATOMIC_GLOB | |
316 | }; | |
317 | ||
860f10a7 | 318 | enum ib_odp_general_cap_bits { |
25bf14d6 AK |
319 | IB_ODP_SUPPORT = 1 << 0, |
320 | IB_ODP_SUPPORT_IMPLICIT = 1 << 1, | |
860f10a7 SG |
321 | }; |
322 | ||
323 | enum ib_odp_transport_cap_bits { | |
324 | IB_ODP_SUPPORT_SEND = 1 << 0, | |
325 | IB_ODP_SUPPORT_RECV = 1 << 1, | |
326 | IB_ODP_SUPPORT_WRITE = 1 << 2, | |
327 | IB_ODP_SUPPORT_READ = 1 << 3, | |
328 | IB_ODP_SUPPORT_ATOMIC = 1 << 4, | |
da823342 | 329 | IB_ODP_SUPPORT_SRQ_RECV = 1 << 5, |
860f10a7 SG |
330 | }; |
331 | ||
332 | struct ib_odp_caps { | |
333 | uint64_t general_caps; | |
334 | struct { | |
335 | uint32_t rc_odp_caps; | |
336 | uint32_t uc_odp_caps; | |
337 | uint32_t ud_odp_caps; | |
52a72e2a | 338 | uint32_t xrc_odp_caps; |
860f10a7 SG |
339 | } per_transport_caps; |
340 | }; | |
341 | ||
ccf20562 YH |
342 | struct ib_rss_caps { |
343 | /* Corresponding bit will be set if qp type from | |
344 | * 'enum ib_qp_type' is supported, e.g. | |
345 | * supported_qpts |= 1 << IB_QPT_UD | |
346 | */ | |
347 | u32 supported_qpts; | |
348 | u32 max_rwq_indirection_tables; | |
349 | u32 max_rwq_indirection_table_size; | |
350 | }; | |
351 | ||
6938fc1e | 352 | enum ib_tm_cap_flags { |
89705e92 DG |
353 | /* Support tag matching with rendezvous offload for RC transport */ |
354 | IB_TM_CAP_RNDV_RC = 1 << 0, | |
6938fc1e AK |
355 | }; |
356 | ||
78b1beb0 | 357 | struct ib_tm_caps { |
6938fc1e AK |
358 | /* Max size of RNDV header */ |
359 | u32 max_rndv_hdr_size; | |
360 | /* Max number of entries in tag matching list */ | |
361 | u32 max_num_tags; | |
362 | /* From enum ib_tm_cap_flags */ | |
363 | u32 flags; | |
364 | /* Max number of outstanding list operations */ | |
365 | u32 max_ops; | |
366 | /* Max number of SGE in tag matching entry */ | |
367 | u32 max_sge; | |
368 | }; | |
369 | ||
bcf4c1ea MB |
370 | struct ib_cq_init_attr { |
371 | unsigned int cqe; | |
372 | int comp_vector; | |
373 | u32 flags; | |
374 | }; | |
375 | ||
869ddcf8 YC |
376 | enum ib_cq_attr_mask { |
377 | IB_CQ_MODERATE = 1 << 0, | |
378 | }; | |
379 | ||
18bd9072 YC |
380 | struct ib_cq_caps { |
381 | u16 max_cq_moderation_count; | |
382 | u16 max_cq_moderation_period; | |
383 | }; | |
384 | ||
be934cca AL |
385 | struct ib_dm_mr_attr { |
386 | u64 length; | |
387 | u64 offset; | |
388 | u32 access_flags; | |
389 | }; | |
390 | ||
bee76d7a AL |
391 | struct ib_dm_alloc_attr { |
392 | u64 length; | |
393 | u32 alignment; | |
394 | u32 flags; | |
395 | }; | |
396 | ||
1da177e4 LT |
397 | struct ib_device_attr { |
398 | u64 fw_ver; | |
97f52eb4 | 399 | __be64 sys_image_guid; |
1da177e4 LT |
400 | u64 max_mr_size; |
401 | u64 page_size_cap; | |
402 | u32 vendor_id; | |
403 | u32 vendor_part_id; | |
404 | u32 hw_ver; | |
405 | int max_qp; | |
406 | int max_qp_wr; | |
fb532d6a | 407 | u64 device_cap_flags; |
33023fb8 SW |
408 | int max_send_sge; |
409 | int max_recv_sge; | |
1da177e4 LT |
410 | int max_sge_rd; |
411 | int max_cq; | |
412 | int max_cqe; | |
413 | int max_mr; | |
414 | int max_pd; | |
415 | int max_qp_rd_atom; | |
416 | int max_ee_rd_atom; | |
417 | int max_res_rd_atom; | |
418 | int max_qp_init_rd_atom; | |
419 | int max_ee_init_rd_atom; | |
420 | enum ib_atomic_cap atomic_cap; | |
5e80ba8f | 421 | enum ib_atomic_cap masked_atomic_cap; |
1da177e4 LT |
422 | int max_ee; |
423 | int max_rdd; | |
424 | int max_mw; | |
425 | int max_raw_ipv6_qp; | |
426 | int max_raw_ethy_qp; | |
427 | int max_mcast_grp; | |
428 | int max_mcast_qp_attach; | |
429 | int max_total_mcast_qp_attach; | |
430 | int max_ah; | |
431 | int max_fmr; | |
432 | int max_map_per_fmr; | |
433 | int max_srq; | |
434 | int max_srq_wr; | |
435 | int max_srq_sge; | |
00f7ec36 | 436 | unsigned int max_fast_reg_page_list_len; |
62e3c379 | 437 | unsigned int max_pi_fast_reg_page_list_len; |
1da177e4 LT |
438 | u16 max_pkeys; |
439 | u8 local_ca_ack_delay; | |
1b01d335 SG |
440 | int sig_prot_cap; |
441 | int sig_guard_cap; | |
860f10a7 | 442 | struct ib_odp_caps odp_caps; |
24306dc6 MB |
443 | uint64_t timestamp_mask; |
444 | uint64_t hca_core_clock; /* in KHZ */ | |
ccf20562 YH |
445 | struct ib_rss_caps rss_caps; |
446 | u32 max_wq_type_rq; | |
ebaaee25 | 447 | u32 raw_packet_caps; /* Use ib_raw_packet_caps enum */ |
78b1beb0 | 448 | struct ib_tm_caps tm_caps; |
18bd9072 | 449 | struct ib_cq_caps cq_caps; |
1d8eeb9f | 450 | u64 max_dm_size; |
1da177e4 LT |
451 | }; |
452 | ||
453 | enum ib_mtu { | |
454 | IB_MTU_256 = 1, | |
455 | IB_MTU_512 = 2, | |
456 | IB_MTU_1024 = 3, | |
457 | IB_MTU_2048 = 4, | |
458 | IB_MTU_4096 = 5 | |
459 | }; | |
460 | ||
461 | static inline int ib_mtu_enum_to_int(enum ib_mtu mtu) | |
462 | { | |
463 | switch (mtu) { | |
464 | case IB_MTU_256: return 256; | |
465 | case IB_MTU_512: return 512; | |
466 | case IB_MTU_1024: return 1024; | |
467 | case IB_MTU_2048: return 2048; | |
468 | case IB_MTU_4096: return 4096; | |
469 | default: return -1; | |
470 | } | |
471 | } | |
472 | ||
d3f4aadd AR |
473 | static inline enum ib_mtu ib_mtu_int_to_enum(int mtu) |
474 | { | |
475 | if (mtu >= 4096) | |
476 | return IB_MTU_4096; | |
477 | else if (mtu >= 2048) | |
478 | return IB_MTU_2048; | |
479 | else if (mtu >= 1024) | |
480 | return IB_MTU_1024; | |
481 | else if (mtu >= 512) | |
482 | return IB_MTU_512; | |
483 | else | |
484 | return IB_MTU_256; | |
485 | } | |
486 | ||
1da177e4 LT |
487 | enum ib_port_state { |
488 | IB_PORT_NOP = 0, | |
489 | IB_PORT_DOWN = 1, | |
490 | IB_PORT_INIT = 2, | |
491 | IB_PORT_ARMED = 3, | |
492 | IB_PORT_ACTIVE = 4, | |
493 | IB_PORT_ACTIVE_DEFER = 5 | |
494 | }; | |
495 | ||
1da177e4 LT |
496 | enum ib_port_width { |
497 | IB_WIDTH_1X = 1, | |
dbabf685 | 498 | IB_WIDTH_2X = 16, |
1da177e4 LT |
499 | IB_WIDTH_4X = 2, |
500 | IB_WIDTH_8X = 4, | |
501 | IB_WIDTH_12X = 8 | |
502 | }; | |
503 | ||
504 | static inline int ib_width_enum_to_int(enum ib_port_width width) | |
505 | { | |
506 | switch (width) { | |
507 | case IB_WIDTH_1X: return 1; | |
dbabf685 | 508 | case IB_WIDTH_2X: return 2; |
1da177e4 LT |
509 | case IB_WIDTH_4X: return 4; |
510 | case IB_WIDTH_8X: return 8; | |
511 | case IB_WIDTH_12X: return 12; | |
512 | default: return -1; | |
513 | } | |
514 | } | |
515 | ||
2e96691c OG |
516 | enum ib_port_speed { |
517 | IB_SPEED_SDR = 1, | |
518 | IB_SPEED_DDR = 2, | |
519 | IB_SPEED_QDR = 4, | |
520 | IB_SPEED_FDR10 = 8, | |
521 | IB_SPEED_FDR = 16, | |
12113a35 NO |
522 | IB_SPEED_EDR = 32, |
523 | IB_SPEED_HDR = 64 | |
2e96691c OG |
524 | }; |
525 | ||
b40f4757 CL |
526 | /** |
527 | * struct rdma_hw_stats | |
e945130b MB |
528 | * @lock - Mutex to protect parallel write access to lifespan and values |
529 | * of counters, which are 64bits and not guaranteeed to be written | |
530 | * atomicaly on 32bits systems. | |
b40f4757 CL |
531 | * @timestamp - Used by the core code to track when the last update was |
532 | * @lifespan - Used by the core code to determine how old the counters | |
533 | * should be before being updated again. Stored in jiffies, defaults | |
534 | * to 10 milliseconds, drivers can override the default be specifying | |
535 | * their own value during their allocation routine. | |
536 | * @name - Array of pointers to static names used for the counters in | |
537 | * directory. | |
538 | * @num_counters - How many hardware counters there are. If name is | |
539 | * shorter than this number, a kernel oops will result. Driver authors | |
540 | * are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters) | |
541 | * in their code to prevent this. | |
542 | * @value - Array of u64 counters that are accessed by the sysfs code and | |
543 | * filled in by the drivers get_stats routine | |
544 | */ | |
545 | struct rdma_hw_stats { | |
e945130b | 546 | struct mutex lock; /* Protect lifespan and values[] */ |
b40f4757 CL |
547 | unsigned long timestamp; |
548 | unsigned long lifespan; | |
549 | const char * const *names; | |
550 | int num_counters; | |
551 | u64 value[]; | |
7f624d02 SW |
552 | }; |
553 | ||
b40f4757 CL |
554 | #define RDMA_HW_STATS_DEFAULT_LIFESPAN 10 |
555 | /** | |
556 | * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct | |
557 | * for drivers. | |
558 | * @names - Array of static const char * | |
559 | * @num_counters - How many elements in array | |
560 | * @lifespan - How many milliseconds between updates | |
561 | */ | |
562 | static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct( | |
563 | const char * const *names, int num_counters, | |
564 | unsigned long lifespan) | |
565 | { | |
566 | struct rdma_hw_stats *stats; | |
567 | ||
568 | stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64), | |
569 | GFP_KERNEL); | |
570 | if (!stats) | |
571 | return NULL; | |
572 | stats->names = names; | |
573 | stats->num_counters = num_counters; | |
574 | stats->lifespan = msecs_to_jiffies(lifespan); | |
575 | ||
576 | return stats; | |
577 | } | |
578 | ||
579 | ||
f9b22e35 IW |
580 | /* Define bits for the various functionality this port needs to be supported by |
581 | * the core. | |
582 | */ | |
583 | /* Management 0x00000FFF */ | |
584 | #define RDMA_CORE_CAP_IB_MAD 0x00000001 | |
585 | #define RDMA_CORE_CAP_IB_SMI 0x00000002 | |
586 | #define RDMA_CORE_CAP_IB_CM 0x00000004 | |
587 | #define RDMA_CORE_CAP_IW_CM 0x00000008 | |
588 | #define RDMA_CORE_CAP_IB_SA 0x00000010 | |
65995fee | 589 | #define RDMA_CORE_CAP_OPA_MAD 0x00000020 |
f9b22e35 IW |
590 | |
591 | /* Address format 0x000FF000 */ | |
592 | #define RDMA_CORE_CAP_AF_IB 0x00001000 | |
593 | #define RDMA_CORE_CAP_ETH_AH 0x00002000 | |
94d595c5 | 594 | #define RDMA_CORE_CAP_OPA_AH 0x00004000 |
b02289b3 | 595 | #define RDMA_CORE_CAP_IB_GRH_REQUIRED 0x00008000 |
f9b22e35 IW |
596 | |
597 | /* Protocol 0xFFF00000 */ | |
598 | #define RDMA_CORE_CAP_PROT_IB 0x00100000 | |
599 | #define RDMA_CORE_CAP_PROT_ROCE 0x00200000 | |
600 | #define RDMA_CORE_CAP_PROT_IWARP 0x00400000 | |
7766a99f | 601 | #define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000 |
aa773bd4 | 602 | #define RDMA_CORE_CAP_PROT_RAW_PACKET 0x01000000 |
ce1e055f | 603 | #define RDMA_CORE_CAP_PROT_USNIC 0x02000000 |
f9b22e35 | 604 | |
b02289b3 AK |
605 | #define RDMA_CORE_PORT_IB_GRH_REQUIRED (RDMA_CORE_CAP_IB_GRH_REQUIRED \ |
606 | | RDMA_CORE_CAP_PROT_ROCE \ | |
607 | | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP) | |
608 | ||
f9b22e35 IW |
609 | #define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \ |
610 | | RDMA_CORE_CAP_IB_MAD \ | |
611 | | RDMA_CORE_CAP_IB_SMI \ | |
612 | | RDMA_CORE_CAP_IB_CM \ | |
613 | | RDMA_CORE_CAP_IB_SA \ | |
614 | | RDMA_CORE_CAP_AF_IB) | |
615 | #define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \ | |
616 | | RDMA_CORE_CAP_IB_MAD \ | |
617 | | RDMA_CORE_CAP_IB_CM \ | |
f9b22e35 IW |
618 | | RDMA_CORE_CAP_AF_IB \ |
619 | | RDMA_CORE_CAP_ETH_AH) | |
7766a99f MB |
620 | #define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \ |
621 | (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \ | |
622 | | RDMA_CORE_CAP_IB_MAD \ | |
623 | | RDMA_CORE_CAP_IB_CM \ | |
624 | | RDMA_CORE_CAP_AF_IB \ | |
625 | | RDMA_CORE_CAP_ETH_AH) | |
f9b22e35 IW |
626 | #define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \ |
627 | | RDMA_CORE_CAP_IW_CM) | |
65995fee IW |
628 | #define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \ |
629 | | RDMA_CORE_CAP_OPA_MAD) | |
f9b22e35 | 630 | |
aa773bd4 OG |
631 | #define RDMA_CORE_PORT_RAW_PACKET (RDMA_CORE_CAP_PROT_RAW_PACKET) |
632 | ||
ce1e055f OG |
633 | #define RDMA_CORE_PORT_USNIC (RDMA_CORE_CAP_PROT_USNIC) |
634 | ||
1da177e4 | 635 | struct ib_port_attr { |
fad61ad4 | 636 | u64 subnet_prefix; |
1da177e4 LT |
637 | enum ib_port_state state; |
638 | enum ib_mtu max_mtu; | |
639 | enum ib_mtu active_mtu; | |
640 | int gid_tbl_len; | |
2f944c0f JG |
641 | unsigned int ip_gids:1; |
642 | /* This is the value from PortInfo CapabilityMask, defined by IBA */ | |
1da177e4 LT |
643 | u32 port_cap_flags; |
644 | u32 max_msg_sz; | |
645 | u32 bad_pkey_cntr; | |
646 | u32 qkey_viol_cntr; | |
647 | u16 pkey_tbl_len; | |
db58540b | 648 | u32 sm_lid; |
582faf31 | 649 | u32 lid; |
1da177e4 LT |
650 | u8 lmc; |
651 | u8 max_vl_num; | |
652 | u8 sm_sl; | |
653 | u8 subnet_timeout; | |
654 | u8 init_type_reply; | |
655 | u8 active_width; | |
656 | u8 active_speed; | |
657 | u8 phys_state; | |
1e8f43b7 | 658 | u16 port_cap_flags2; |
1da177e4 LT |
659 | }; |
660 | ||
661 | enum ib_device_modify_flags { | |
c5bcbbb9 RD |
662 | IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0, |
663 | IB_DEVICE_MODIFY_NODE_DESC = 1 << 1 | |
1da177e4 LT |
664 | }; |
665 | ||
bd99fdea YS |
666 | #define IB_DEVICE_NODE_DESC_MAX 64 |
667 | ||
1da177e4 LT |
668 | struct ib_device_modify { |
669 | u64 sys_image_guid; | |
bd99fdea | 670 | char node_desc[IB_DEVICE_NODE_DESC_MAX]; |
1da177e4 LT |
671 | }; |
672 | ||
673 | enum ib_port_modify_flags { | |
674 | IB_PORT_SHUTDOWN = 1, | |
675 | IB_PORT_INIT_TYPE = (1<<2), | |
cb49366f VN |
676 | IB_PORT_RESET_QKEY_CNTR = (1<<3), |
677 | IB_PORT_OPA_MASK_CHG = (1<<4) | |
1da177e4 LT |
678 | }; |
679 | ||
680 | struct ib_port_modify { | |
681 | u32 set_port_cap_mask; | |
682 | u32 clr_port_cap_mask; | |
683 | u8 init_type; | |
684 | }; | |
685 | ||
686 | enum ib_event_type { | |
687 | IB_EVENT_CQ_ERR, | |
688 | IB_EVENT_QP_FATAL, | |
689 | IB_EVENT_QP_REQ_ERR, | |
690 | IB_EVENT_QP_ACCESS_ERR, | |
691 | IB_EVENT_COMM_EST, | |
692 | IB_EVENT_SQ_DRAINED, | |
693 | IB_EVENT_PATH_MIG, | |
694 | IB_EVENT_PATH_MIG_ERR, | |
695 | IB_EVENT_DEVICE_FATAL, | |
696 | IB_EVENT_PORT_ACTIVE, | |
697 | IB_EVENT_PORT_ERR, | |
698 | IB_EVENT_LID_CHANGE, | |
699 | IB_EVENT_PKEY_CHANGE, | |
d41fcc67 RD |
700 | IB_EVENT_SM_CHANGE, |
701 | IB_EVENT_SRQ_ERR, | |
702 | IB_EVENT_SRQ_LIMIT_REACHED, | |
63942c9a | 703 | IB_EVENT_QP_LAST_WQE_REACHED, |
761d90ed OG |
704 | IB_EVENT_CLIENT_REREGISTER, |
705 | IB_EVENT_GID_CHANGE, | |
f213c052 | 706 | IB_EVENT_WQ_FATAL, |
1da177e4 LT |
707 | }; |
708 | ||
db7489e0 | 709 | const char *__attribute_const__ ib_event_msg(enum ib_event_type event); |
2b1b5b60 | 710 | |
1da177e4 LT |
711 | struct ib_event { |
712 | struct ib_device *device; | |
713 | union { | |
714 | struct ib_cq *cq; | |
715 | struct ib_qp *qp; | |
d41fcc67 | 716 | struct ib_srq *srq; |
f213c052 | 717 | struct ib_wq *wq; |
1da177e4 LT |
718 | u8 port_num; |
719 | } element; | |
720 | enum ib_event_type event; | |
721 | }; | |
722 | ||
723 | struct ib_event_handler { | |
724 | struct ib_device *device; | |
725 | void (*handler)(struct ib_event_handler *, struct ib_event *); | |
726 | struct list_head list; | |
727 | }; | |
728 | ||
729 | #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \ | |
730 | do { \ | |
731 | (_ptr)->device = _device; \ | |
732 | (_ptr)->handler = _handler; \ | |
733 | INIT_LIST_HEAD(&(_ptr)->list); \ | |
734 | } while (0) | |
735 | ||
736 | struct ib_global_route { | |
8d9ec9ad | 737 | const struct ib_gid_attr *sgid_attr; |
1da177e4 LT |
738 | union ib_gid dgid; |
739 | u32 flow_label; | |
740 | u8 sgid_index; | |
741 | u8 hop_limit; | |
742 | u8 traffic_class; | |
743 | }; | |
744 | ||
513789ed | 745 | struct ib_grh { |
97f52eb4 SH |
746 | __be32 version_tclass_flow; |
747 | __be16 paylen; | |
513789ed HR |
748 | u8 next_hdr; |
749 | u8 hop_limit; | |
750 | union ib_gid sgid; | |
751 | union ib_gid dgid; | |
752 | }; | |
753 | ||
c865f246 SK |
754 | union rdma_network_hdr { |
755 | struct ib_grh ibgrh; | |
756 | struct { | |
757 | /* The IB spec states that if it's IPv4, the header | |
758 | * is located in the last 20 bytes of the header. | |
759 | */ | |
760 | u8 reserved[20]; | |
761 | struct iphdr roce4grh; | |
762 | }; | |
763 | }; | |
764 | ||
7dafbab3 DH |
765 | #define IB_QPN_MASK 0xFFFFFF |
766 | ||
1da177e4 LT |
767 | enum { |
768 | IB_MULTICAST_QPN = 0xffffff | |
769 | }; | |
770 | ||
f3a7c66b | 771 | #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF) |
b4e64397 | 772 | #define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000) |
97f52eb4 | 773 | |
1da177e4 LT |
774 | enum ib_ah_flags { |
775 | IB_AH_GRH = 1 | |
776 | }; | |
777 | ||
bf6a9e31 JM |
778 | enum ib_rate { |
779 | IB_RATE_PORT_CURRENT = 0, | |
780 | IB_RATE_2_5_GBPS = 2, | |
781 | IB_RATE_5_GBPS = 5, | |
782 | IB_RATE_10_GBPS = 3, | |
783 | IB_RATE_20_GBPS = 6, | |
784 | IB_RATE_30_GBPS = 4, | |
785 | IB_RATE_40_GBPS = 7, | |
786 | IB_RATE_60_GBPS = 8, | |
787 | IB_RATE_80_GBPS = 9, | |
71eeba16 MA |
788 | IB_RATE_120_GBPS = 10, |
789 | IB_RATE_14_GBPS = 11, | |
790 | IB_RATE_56_GBPS = 12, | |
791 | IB_RATE_112_GBPS = 13, | |
792 | IB_RATE_168_GBPS = 14, | |
793 | IB_RATE_25_GBPS = 15, | |
794 | IB_RATE_100_GBPS = 16, | |
795 | IB_RATE_200_GBPS = 17, | |
a5a5d199 MG |
796 | IB_RATE_300_GBPS = 18, |
797 | IB_RATE_28_GBPS = 19, | |
798 | IB_RATE_50_GBPS = 20, | |
799 | IB_RATE_400_GBPS = 21, | |
800 | IB_RATE_600_GBPS = 22, | |
bf6a9e31 JM |
801 | }; |
802 | ||
803 | /** | |
804 | * ib_rate_to_mult - Convert the IB rate enum to a multiple of the | |
805 | * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be | |
806 | * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec. | |
807 | * @rate: rate to convert. | |
808 | */ | |
8385fd84 | 809 | __attribute_const__ int ib_rate_to_mult(enum ib_rate rate); |
bf6a9e31 | 810 | |
71eeba16 MA |
811 | /** |
812 | * ib_rate_to_mbps - Convert the IB rate enum to Mbps. | |
813 | * For example, IB_RATE_2_5_GBPS will be converted to 2500. | |
814 | * @rate: rate to convert. | |
815 | */ | |
8385fd84 | 816 | __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate); |
71eeba16 | 817 | |
17cd3a2d SG |
818 | |
819 | /** | |
9bee178b SG |
820 | * enum ib_mr_type - memory region type |
821 | * @IB_MR_TYPE_MEM_REG: memory region that is used for | |
822 | * normal registration | |
f5aa9159 SG |
823 | * @IB_MR_TYPE_SG_GAPS: memory region that is capable to |
824 | * register any arbitrary sg lists (without | |
825 | * the normal mr constraints - see | |
826 | * ib_map_mr_sg) | |
a0bc099a MG |
827 | * @IB_MR_TYPE_DM: memory region that is used for device |
828 | * memory registration | |
829 | * @IB_MR_TYPE_USER: memory region that is used for the user-space | |
830 | * application | |
831 | * @IB_MR_TYPE_DMA: memory region that is used for DMA operations | |
832 | * without address translations (VA=PA) | |
26bc7eae IR |
833 | * @IB_MR_TYPE_INTEGRITY: memory region that is used for |
834 | * data integrity operations | |
17cd3a2d | 835 | */ |
9bee178b SG |
836 | enum ib_mr_type { |
837 | IB_MR_TYPE_MEM_REG, | |
f5aa9159 | 838 | IB_MR_TYPE_SG_GAPS, |
a0bc099a MG |
839 | IB_MR_TYPE_DM, |
840 | IB_MR_TYPE_USER, | |
841 | IB_MR_TYPE_DMA, | |
26bc7eae | 842 | IB_MR_TYPE_INTEGRITY, |
17cd3a2d SG |
843 | }; |
844 | ||
1b01d335 SG |
845 | enum ib_mr_status_check { |
846 | IB_MR_CHECK_SIG_STATUS = 1, | |
847 | }; | |
848 | ||
849 | /** | |
850 | * struct ib_mr_status - Memory region status container | |
851 | * | |
852 | * @fail_status: Bitmask of MR checks status. For each | |
853 | * failed check a corresponding status bit is set. | |
854 | * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS | |
855 | * failure. | |
856 | */ | |
857 | struct ib_mr_status { | |
858 | u32 fail_status; | |
859 | struct ib_sig_err sig_err; | |
860 | }; | |
861 | ||
bf6a9e31 JM |
862 | /** |
863 | * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate | |
864 | * enum. | |
865 | * @mult: multiple to convert. | |
866 | */ | |
8385fd84 | 867 | __attribute_const__ enum ib_rate mult_to_ib_rate(int mult); |
bf6a9e31 | 868 | |
44c58487 | 869 | enum rdma_ah_attr_type { |
87daac68 | 870 | RDMA_AH_ATTR_TYPE_UNDEFINED, |
44c58487 DC |
871 | RDMA_AH_ATTR_TYPE_IB, |
872 | RDMA_AH_ATTR_TYPE_ROCE, | |
64b4646e | 873 | RDMA_AH_ATTR_TYPE_OPA, |
44c58487 DC |
874 | }; |
875 | ||
876 | struct ib_ah_attr { | |
877 | u16 dlid; | |
878 | u8 src_path_bits; | |
879 | }; | |
880 | ||
881 | struct roce_ah_attr { | |
882 | u8 dmac[ETH_ALEN]; | |
883 | }; | |
884 | ||
64b4646e DC |
885 | struct opa_ah_attr { |
886 | u32 dlid; | |
887 | u8 src_path_bits; | |
d98bb7f7 | 888 | bool make_grd; |
64b4646e DC |
889 | }; |
890 | ||
90898850 | 891 | struct rdma_ah_attr { |
1da177e4 | 892 | struct ib_global_route grh; |
1da177e4 | 893 | u8 sl; |
1da177e4 | 894 | u8 static_rate; |
1da177e4 | 895 | u8 port_num; |
44c58487 DC |
896 | u8 ah_flags; |
897 | enum rdma_ah_attr_type type; | |
898 | union { | |
899 | struct ib_ah_attr ib; | |
900 | struct roce_ah_attr roce; | |
64b4646e | 901 | struct opa_ah_attr opa; |
44c58487 | 902 | }; |
1da177e4 LT |
903 | }; |
904 | ||
905 | enum ib_wc_status { | |
906 | IB_WC_SUCCESS, | |
907 | IB_WC_LOC_LEN_ERR, | |
908 | IB_WC_LOC_QP_OP_ERR, | |
909 | IB_WC_LOC_EEC_OP_ERR, | |
910 | IB_WC_LOC_PROT_ERR, | |
911 | IB_WC_WR_FLUSH_ERR, | |
912 | IB_WC_MW_BIND_ERR, | |
913 | IB_WC_BAD_RESP_ERR, | |
914 | IB_WC_LOC_ACCESS_ERR, | |
915 | IB_WC_REM_INV_REQ_ERR, | |
916 | IB_WC_REM_ACCESS_ERR, | |
917 | IB_WC_REM_OP_ERR, | |
918 | IB_WC_RETRY_EXC_ERR, | |
919 | IB_WC_RNR_RETRY_EXC_ERR, | |
920 | IB_WC_LOC_RDD_VIOL_ERR, | |
921 | IB_WC_REM_INV_RD_REQ_ERR, | |
922 | IB_WC_REM_ABORT_ERR, | |
923 | IB_WC_INV_EECN_ERR, | |
924 | IB_WC_INV_EEC_STATE_ERR, | |
925 | IB_WC_FATAL_ERR, | |
926 | IB_WC_RESP_TIMEOUT_ERR, | |
927 | IB_WC_GENERAL_ERR | |
928 | }; | |
929 | ||
db7489e0 | 930 | const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status); |
2b1b5b60 | 931 | |
1da177e4 LT |
932 | enum ib_wc_opcode { |
933 | IB_WC_SEND, | |
934 | IB_WC_RDMA_WRITE, | |
935 | IB_WC_RDMA_READ, | |
936 | IB_WC_COMP_SWAP, | |
937 | IB_WC_FETCH_ADD, | |
c93570f2 | 938 | IB_WC_LSO, |
00f7ec36 | 939 | IB_WC_LOCAL_INV, |
4c67e2bf | 940 | IB_WC_REG_MR, |
5e80ba8f VS |
941 | IB_WC_MASKED_COMP_SWAP, |
942 | IB_WC_MASKED_FETCH_ADD, | |
1da177e4 LT |
943 | /* |
944 | * Set value of IB_WC_RECV so consumers can test if a completion is a | |
945 | * receive by testing (opcode & IB_WC_RECV). | |
946 | */ | |
947 | IB_WC_RECV = 1 << 7, | |
948 | IB_WC_RECV_RDMA_WITH_IMM | |
949 | }; | |
950 | ||
951 | enum ib_wc_flags { | |
952 | IB_WC_GRH = 1, | |
00f7ec36 SW |
953 | IB_WC_WITH_IMM = (1<<1), |
954 | IB_WC_WITH_INVALIDATE = (1<<2), | |
d927d505 | 955 | IB_WC_IP_CSUM_OK = (1<<3), |
dd5f03be MB |
956 | IB_WC_WITH_SMAC = (1<<4), |
957 | IB_WC_WITH_VLAN = (1<<5), | |
c865f246 | 958 | IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6), |
1da177e4 LT |
959 | }; |
960 | ||
961 | struct ib_wc { | |
14d3a3b2 CH |
962 | union { |
963 | u64 wr_id; | |
964 | struct ib_cqe *wr_cqe; | |
965 | }; | |
1da177e4 LT |
966 | enum ib_wc_status status; |
967 | enum ib_wc_opcode opcode; | |
968 | u32 vendor_err; | |
969 | u32 byte_len; | |
062dbb69 | 970 | struct ib_qp *qp; |
00f7ec36 SW |
971 | union { |
972 | __be32 imm_data; | |
973 | u32 invalidate_rkey; | |
974 | } ex; | |
1da177e4 | 975 | u32 src_qp; |
cd2a6e7d | 976 | u32 slid; |
1da177e4 LT |
977 | int wc_flags; |
978 | u16 pkey_index; | |
1da177e4 LT |
979 | u8 sl; |
980 | u8 dlid_path_bits; | |
981 | u8 port_num; /* valid only for DR SMPs on switches */ | |
dd5f03be MB |
982 | u8 smac[ETH_ALEN]; |
983 | u16 vlan_id; | |
c865f246 | 984 | u8 network_hdr_type; |
1da177e4 LT |
985 | }; |
986 | ||
ed23a727 RD |
987 | enum ib_cq_notify_flags { |
988 | IB_CQ_SOLICITED = 1 << 0, | |
989 | IB_CQ_NEXT_COMP = 1 << 1, | |
990 | IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP, | |
991 | IB_CQ_REPORT_MISSED_EVENTS = 1 << 2, | |
1da177e4 LT |
992 | }; |
993 | ||
96104eda | 994 | enum ib_srq_type { |
418d5130 | 995 | IB_SRQT_BASIC, |
9c2c8496 AK |
996 | IB_SRQT_XRC, |
997 | IB_SRQT_TM, | |
96104eda SH |
998 | }; |
999 | ||
1a56ff6d AK |
1000 | static inline bool ib_srq_has_cq(enum ib_srq_type srq_type) |
1001 | { | |
9c2c8496 AK |
1002 | return srq_type == IB_SRQT_XRC || |
1003 | srq_type == IB_SRQT_TM; | |
1a56ff6d AK |
1004 | } |
1005 | ||
d41fcc67 RD |
1006 | enum ib_srq_attr_mask { |
1007 | IB_SRQ_MAX_WR = 1 << 0, | |
1008 | IB_SRQ_LIMIT = 1 << 1, | |
1009 | }; | |
1010 | ||
1011 | struct ib_srq_attr { | |
1012 | u32 max_wr; | |
1013 | u32 max_sge; | |
1014 | u32 srq_limit; | |
1015 | }; | |
1016 | ||
1017 | struct ib_srq_init_attr { | |
1018 | void (*event_handler)(struct ib_event *, void *); | |
1019 | void *srq_context; | |
1020 | struct ib_srq_attr attr; | |
96104eda | 1021 | enum ib_srq_type srq_type; |
418d5130 | 1022 | |
1a56ff6d AK |
1023 | struct { |
1024 | struct ib_cq *cq; | |
1025 | union { | |
1026 | struct { | |
1027 | struct ib_xrcd *xrcd; | |
1028 | } xrc; | |
9c2c8496 AK |
1029 | |
1030 | struct { | |
1031 | u32 max_num_tags; | |
1032 | } tag_matching; | |
1a56ff6d | 1033 | }; |
418d5130 | 1034 | } ext; |
d41fcc67 RD |
1035 | }; |
1036 | ||
1da177e4 LT |
1037 | struct ib_qp_cap { |
1038 | u32 max_send_wr; | |
1039 | u32 max_recv_wr; | |
1040 | u32 max_send_sge; | |
1041 | u32 max_recv_sge; | |
1042 | u32 max_inline_data; | |
a060b562 CH |
1043 | |
1044 | /* | |
1045 | * Maximum number of rdma_rw_ctx structures in flight at a time. | |
1046 | * ib_create_qp() will calculate the right amount of neededed WRs | |
1047 | * and MRs based on this. | |
1048 | */ | |
1049 | u32 max_rdma_ctxs; | |
1da177e4 LT |
1050 | }; |
1051 | ||
1052 | enum ib_sig_type { | |
1053 | IB_SIGNAL_ALL_WR, | |
1054 | IB_SIGNAL_REQ_WR | |
1055 | }; | |
1056 | ||
1057 | enum ib_qp_type { | |
1058 | /* | |
1059 | * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries | |
1060 | * here (and in that order) since the MAD layer uses them as | |
1061 | * indices into a 2-entry table. | |
1062 | */ | |
1063 | IB_QPT_SMI, | |
1064 | IB_QPT_GSI, | |
1065 | ||
1066 | IB_QPT_RC, | |
1067 | IB_QPT_UC, | |
1068 | IB_QPT_UD, | |
1069 | IB_QPT_RAW_IPV6, | |
b42b63cf | 1070 | IB_QPT_RAW_ETHERTYPE, |
c938a616 | 1071 | IB_QPT_RAW_PACKET = 8, |
b42b63cf SH |
1072 | IB_QPT_XRC_INI = 9, |
1073 | IB_QPT_XRC_TGT, | |
0134f16b | 1074 | IB_QPT_MAX, |
8011c1e3 | 1075 | IB_QPT_DRIVER = 0xFF, |
0134f16b JM |
1076 | /* Reserve a range for qp types internal to the low level driver. |
1077 | * These qp types will not be visible at the IB core layer, so the | |
1078 | * IB_QPT_MAX usages should not be affected in the core layer | |
1079 | */ | |
1080 | IB_QPT_RESERVED1 = 0x1000, | |
1081 | IB_QPT_RESERVED2, | |
1082 | IB_QPT_RESERVED3, | |
1083 | IB_QPT_RESERVED4, | |
1084 | IB_QPT_RESERVED5, | |
1085 | IB_QPT_RESERVED6, | |
1086 | IB_QPT_RESERVED7, | |
1087 | IB_QPT_RESERVED8, | |
1088 | IB_QPT_RESERVED9, | |
1089 | IB_QPT_RESERVED10, | |
1da177e4 LT |
1090 | }; |
1091 | ||
b846f25a | 1092 | enum ib_qp_create_flags { |
47ee1b9f RL |
1093 | IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0, |
1094 | IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1, | |
8a06ce59 LR |
1095 | IB_QP_CREATE_CROSS_CHANNEL = 1 << 2, |
1096 | IB_QP_CREATE_MANAGED_SEND = 1 << 3, | |
1097 | IB_QP_CREATE_MANAGED_RECV = 1 << 4, | |
90f1d1b4 | 1098 | IB_QP_CREATE_NETIF_QP = 1 << 5, |
c0a6cbb9 | 1099 | IB_QP_CREATE_INTEGRITY_EN = 1 << 6, |
7855f584 | 1100 | /* FREE = 1 << 7, */ |
b531b909 | 1101 | IB_QP_CREATE_SCATTER_FCS = 1 << 8, |
9c2b270e | 1102 | IB_QP_CREATE_CVLAN_STRIPPING = 1 << 9, |
02984cc7 | 1103 | IB_QP_CREATE_SOURCE_QPN = 1 << 10, |
e1d2e887 | 1104 | IB_QP_CREATE_PCI_WRITE_END_PADDING = 1 << 11, |
d2b57063 JM |
1105 | /* reserve bits 26-31 for low level drivers' internal use */ |
1106 | IB_QP_CREATE_RESERVED_START = 1 << 26, | |
1107 | IB_QP_CREATE_RESERVED_END = 1 << 31, | |
b846f25a EC |
1108 | }; |
1109 | ||
73c40c61 YH |
1110 | /* |
1111 | * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler | |
1112 | * callback to destroy the passed in QP. | |
1113 | */ | |
1114 | ||
1da177e4 | 1115 | struct ib_qp_init_attr { |
eb93c82e | 1116 | /* Consumer's event_handler callback must not block */ |
1da177e4 | 1117 | void (*event_handler)(struct ib_event *, void *); |
eb93c82e | 1118 | |
1da177e4 LT |
1119 | void *qp_context; |
1120 | struct ib_cq *send_cq; | |
1121 | struct ib_cq *recv_cq; | |
1122 | struct ib_srq *srq; | |
b42b63cf | 1123 | struct ib_xrcd *xrcd; /* XRC TGT QPs only */ |
1da177e4 LT |
1124 | struct ib_qp_cap cap; |
1125 | enum ib_sig_type sq_sig_type; | |
1126 | enum ib_qp_type qp_type; | |
b56511c1 | 1127 | u32 create_flags; |
a060b562 CH |
1128 | |
1129 | /* | |
1130 | * Only needed for special QP types, or when using the RW API. | |
1131 | */ | |
1132 | u8 port_num; | |
a9017e23 | 1133 | struct ib_rwq_ind_table *rwq_ind_tbl; |
02984cc7 | 1134 | u32 source_qpn; |
1da177e4 LT |
1135 | }; |
1136 | ||
0e0ec7e0 SH |
1137 | struct ib_qp_open_attr { |
1138 | void (*event_handler)(struct ib_event *, void *); | |
1139 | void *qp_context; | |
1140 | u32 qp_num; | |
1141 | enum ib_qp_type qp_type; | |
1142 | }; | |
1143 | ||
1da177e4 LT |
1144 | enum ib_rnr_timeout { |
1145 | IB_RNR_TIMER_655_36 = 0, | |
1146 | IB_RNR_TIMER_000_01 = 1, | |
1147 | IB_RNR_TIMER_000_02 = 2, | |
1148 | IB_RNR_TIMER_000_03 = 3, | |
1149 | IB_RNR_TIMER_000_04 = 4, | |
1150 | IB_RNR_TIMER_000_06 = 5, | |
1151 | IB_RNR_TIMER_000_08 = 6, | |
1152 | IB_RNR_TIMER_000_12 = 7, | |
1153 | IB_RNR_TIMER_000_16 = 8, | |
1154 | IB_RNR_TIMER_000_24 = 9, | |
1155 | IB_RNR_TIMER_000_32 = 10, | |
1156 | IB_RNR_TIMER_000_48 = 11, | |
1157 | IB_RNR_TIMER_000_64 = 12, | |
1158 | IB_RNR_TIMER_000_96 = 13, | |
1159 | IB_RNR_TIMER_001_28 = 14, | |
1160 | IB_RNR_TIMER_001_92 = 15, | |
1161 | IB_RNR_TIMER_002_56 = 16, | |
1162 | IB_RNR_TIMER_003_84 = 17, | |
1163 | IB_RNR_TIMER_005_12 = 18, | |
1164 | IB_RNR_TIMER_007_68 = 19, | |
1165 | IB_RNR_TIMER_010_24 = 20, | |
1166 | IB_RNR_TIMER_015_36 = 21, | |
1167 | IB_RNR_TIMER_020_48 = 22, | |
1168 | IB_RNR_TIMER_030_72 = 23, | |
1169 | IB_RNR_TIMER_040_96 = 24, | |
1170 | IB_RNR_TIMER_061_44 = 25, | |
1171 | IB_RNR_TIMER_081_92 = 26, | |
1172 | IB_RNR_TIMER_122_88 = 27, | |
1173 | IB_RNR_TIMER_163_84 = 28, | |
1174 | IB_RNR_TIMER_245_76 = 29, | |
1175 | IB_RNR_TIMER_327_68 = 30, | |
1176 | IB_RNR_TIMER_491_52 = 31 | |
1177 | }; | |
1178 | ||
1179 | enum ib_qp_attr_mask { | |
1180 | IB_QP_STATE = 1, | |
1181 | IB_QP_CUR_STATE = (1<<1), | |
1182 | IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2), | |
1183 | IB_QP_ACCESS_FLAGS = (1<<3), | |
1184 | IB_QP_PKEY_INDEX = (1<<4), | |
1185 | IB_QP_PORT = (1<<5), | |
1186 | IB_QP_QKEY = (1<<6), | |
1187 | IB_QP_AV = (1<<7), | |
1188 | IB_QP_PATH_MTU = (1<<8), | |
1189 | IB_QP_TIMEOUT = (1<<9), | |
1190 | IB_QP_RETRY_CNT = (1<<10), | |
1191 | IB_QP_RNR_RETRY = (1<<11), | |
1192 | IB_QP_RQ_PSN = (1<<12), | |
1193 | IB_QP_MAX_QP_RD_ATOMIC = (1<<13), | |
1194 | IB_QP_ALT_PATH = (1<<14), | |
1195 | IB_QP_MIN_RNR_TIMER = (1<<15), | |
1196 | IB_QP_SQ_PSN = (1<<16), | |
1197 | IB_QP_MAX_DEST_RD_ATOMIC = (1<<17), | |
1198 | IB_QP_PATH_MIG_STATE = (1<<18), | |
1199 | IB_QP_CAP = (1<<19), | |
dd5f03be | 1200 | IB_QP_DEST_QPN = (1<<20), |
aa744cc0 MB |
1201 | IB_QP_RESERVED1 = (1<<21), |
1202 | IB_QP_RESERVED2 = (1<<22), | |
1203 | IB_QP_RESERVED3 = (1<<23), | |
1204 | IB_QP_RESERVED4 = (1<<24), | |
528e5a1b | 1205 | IB_QP_RATE_LIMIT = (1<<25), |
1da177e4 LT |
1206 | }; |
1207 | ||
1208 | enum ib_qp_state { | |
1209 | IB_QPS_RESET, | |
1210 | IB_QPS_INIT, | |
1211 | IB_QPS_RTR, | |
1212 | IB_QPS_RTS, | |
1213 | IB_QPS_SQD, | |
1214 | IB_QPS_SQE, | |
1215 | IB_QPS_ERR | |
1216 | }; | |
1217 | ||
1218 | enum ib_mig_state { | |
1219 | IB_MIG_MIGRATED, | |
1220 | IB_MIG_REARM, | |
1221 | IB_MIG_ARMED | |
1222 | }; | |
1223 | ||
7083e42e SM |
1224 | enum ib_mw_type { |
1225 | IB_MW_TYPE_1 = 1, | |
1226 | IB_MW_TYPE_2 = 2 | |
1227 | }; | |
1228 | ||
1da177e4 LT |
1229 | struct ib_qp_attr { |
1230 | enum ib_qp_state qp_state; | |
1231 | enum ib_qp_state cur_qp_state; | |
1232 | enum ib_mtu path_mtu; | |
1233 | enum ib_mig_state path_mig_state; | |
1234 | u32 qkey; | |
1235 | u32 rq_psn; | |
1236 | u32 sq_psn; | |
1237 | u32 dest_qp_num; | |
1238 | int qp_access_flags; | |
1239 | struct ib_qp_cap cap; | |
90898850 DC |
1240 | struct rdma_ah_attr ah_attr; |
1241 | struct rdma_ah_attr alt_ah_attr; | |
1da177e4 LT |
1242 | u16 pkey_index; |
1243 | u16 alt_pkey_index; | |
1244 | u8 en_sqd_async_notify; | |
1245 | u8 sq_draining; | |
1246 | u8 max_rd_atomic; | |
1247 | u8 max_dest_rd_atomic; | |
1248 | u8 min_rnr_timer; | |
1249 | u8 port_num; | |
1250 | u8 timeout; | |
1251 | u8 retry_cnt; | |
1252 | u8 rnr_retry; | |
1253 | u8 alt_port_num; | |
1254 | u8 alt_timeout; | |
528e5a1b | 1255 | u32 rate_limit; |
1da177e4 LT |
1256 | }; |
1257 | ||
1258 | enum ib_wr_opcode { | |
9a59739b JG |
1259 | /* These are shared with userspace */ |
1260 | IB_WR_RDMA_WRITE = IB_UVERBS_WR_RDMA_WRITE, | |
1261 | IB_WR_RDMA_WRITE_WITH_IMM = IB_UVERBS_WR_RDMA_WRITE_WITH_IMM, | |
1262 | IB_WR_SEND = IB_UVERBS_WR_SEND, | |
1263 | IB_WR_SEND_WITH_IMM = IB_UVERBS_WR_SEND_WITH_IMM, | |
1264 | IB_WR_RDMA_READ = IB_UVERBS_WR_RDMA_READ, | |
1265 | IB_WR_ATOMIC_CMP_AND_SWP = IB_UVERBS_WR_ATOMIC_CMP_AND_SWP, | |
1266 | IB_WR_ATOMIC_FETCH_AND_ADD = IB_UVERBS_WR_ATOMIC_FETCH_AND_ADD, | |
1267 | IB_WR_LSO = IB_UVERBS_WR_TSO, | |
1268 | IB_WR_SEND_WITH_INV = IB_UVERBS_WR_SEND_WITH_INV, | |
1269 | IB_WR_RDMA_READ_WITH_INV = IB_UVERBS_WR_RDMA_READ_WITH_INV, | |
1270 | IB_WR_LOCAL_INV = IB_UVERBS_WR_LOCAL_INV, | |
1271 | IB_WR_MASKED_ATOMIC_CMP_AND_SWP = | |
1272 | IB_UVERBS_WR_MASKED_ATOMIC_CMP_AND_SWP, | |
1273 | IB_WR_MASKED_ATOMIC_FETCH_AND_ADD = | |
1274 | IB_UVERBS_WR_MASKED_ATOMIC_FETCH_AND_ADD, | |
1275 | ||
1276 | /* These are kernel only and can not be issued by userspace */ | |
1277 | IB_WR_REG_MR = 0x20, | |
38ca87c6 | 1278 | IB_WR_REG_MR_INTEGRITY, |
9a59739b | 1279 | |
0134f16b JM |
1280 | /* reserve values for low level drivers' internal use. |
1281 | * These values will not be used at all in the ib core layer. | |
1282 | */ | |
1283 | IB_WR_RESERVED1 = 0xf0, | |
1284 | IB_WR_RESERVED2, | |
1285 | IB_WR_RESERVED3, | |
1286 | IB_WR_RESERVED4, | |
1287 | IB_WR_RESERVED5, | |
1288 | IB_WR_RESERVED6, | |
1289 | IB_WR_RESERVED7, | |
1290 | IB_WR_RESERVED8, | |
1291 | IB_WR_RESERVED9, | |
1292 | IB_WR_RESERVED10, | |
1da177e4 LT |
1293 | }; |
1294 | ||
1295 | enum ib_send_flags { | |
1296 | IB_SEND_FENCE = 1, | |
1297 | IB_SEND_SIGNALED = (1<<1), | |
1298 | IB_SEND_SOLICITED = (1<<2), | |
e0605d91 | 1299 | IB_SEND_INLINE = (1<<3), |
0134f16b JM |
1300 | IB_SEND_IP_CSUM = (1<<4), |
1301 | ||
1302 | /* reserve bits 26-31 for low level drivers' internal use */ | |
1303 | IB_SEND_RESERVED_START = (1 << 26), | |
1304 | IB_SEND_RESERVED_END = (1 << 31), | |
1da177e4 LT |
1305 | }; |
1306 | ||
1307 | struct ib_sge { | |
1308 | u64 addr; | |
1309 | u32 length; | |
1310 | u32 lkey; | |
1311 | }; | |
1312 | ||
14d3a3b2 CH |
1313 | struct ib_cqe { |
1314 | void (*done)(struct ib_cq *cq, struct ib_wc *wc); | |
1315 | }; | |
1316 | ||
1da177e4 LT |
1317 | struct ib_send_wr { |
1318 | struct ib_send_wr *next; | |
14d3a3b2 CH |
1319 | union { |
1320 | u64 wr_id; | |
1321 | struct ib_cqe *wr_cqe; | |
1322 | }; | |
1da177e4 LT |
1323 | struct ib_sge *sg_list; |
1324 | int num_sge; | |
1325 | enum ib_wr_opcode opcode; | |
1326 | int send_flags; | |
0f39cf3d RD |
1327 | union { |
1328 | __be32 imm_data; | |
1329 | u32 invalidate_rkey; | |
1330 | } ex; | |
1da177e4 LT |
1331 | }; |
1332 | ||
e622f2f4 CH |
1333 | struct ib_rdma_wr { |
1334 | struct ib_send_wr wr; | |
1335 | u64 remote_addr; | |
1336 | u32 rkey; | |
1337 | }; | |
1338 | ||
f696bf6d | 1339 | static inline const struct ib_rdma_wr *rdma_wr(const struct ib_send_wr *wr) |
e622f2f4 CH |
1340 | { |
1341 | return container_of(wr, struct ib_rdma_wr, wr); | |
1342 | } | |
1343 | ||
1344 | struct ib_atomic_wr { | |
1345 | struct ib_send_wr wr; | |
1346 | u64 remote_addr; | |
1347 | u64 compare_add; | |
1348 | u64 swap; | |
1349 | u64 compare_add_mask; | |
1350 | u64 swap_mask; | |
1351 | u32 rkey; | |
1352 | }; | |
1353 | ||
f696bf6d | 1354 | static inline const struct ib_atomic_wr *atomic_wr(const struct ib_send_wr *wr) |
e622f2f4 CH |
1355 | { |
1356 | return container_of(wr, struct ib_atomic_wr, wr); | |
1357 | } | |
1358 | ||
1359 | struct ib_ud_wr { | |
1360 | struct ib_send_wr wr; | |
1361 | struct ib_ah *ah; | |
1362 | void *header; | |
1363 | int hlen; | |
1364 | int mss; | |
1365 | u32 remote_qpn; | |
1366 | u32 remote_qkey; | |
1367 | u16 pkey_index; /* valid for GSI only */ | |
1368 | u8 port_num; /* valid for DR SMPs on switch only */ | |
1369 | }; | |
1370 | ||
f696bf6d | 1371 | static inline const struct ib_ud_wr *ud_wr(const struct ib_send_wr *wr) |
e622f2f4 CH |
1372 | { |
1373 | return container_of(wr, struct ib_ud_wr, wr); | |
1374 | } | |
1375 | ||
4c67e2bf SG |
1376 | struct ib_reg_wr { |
1377 | struct ib_send_wr wr; | |
1378 | struct ib_mr *mr; | |
1379 | u32 key; | |
1380 | int access; | |
1381 | }; | |
1382 | ||
f696bf6d | 1383 | static inline const struct ib_reg_wr *reg_wr(const struct ib_send_wr *wr) |
4c67e2bf SG |
1384 | { |
1385 | return container_of(wr, struct ib_reg_wr, wr); | |
1386 | } | |
1387 | ||
1da177e4 LT |
1388 | struct ib_recv_wr { |
1389 | struct ib_recv_wr *next; | |
14d3a3b2 CH |
1390 | union { |
1391 | u64 wr_id; | |
1392 | struct ib_cqe *wr_cqe; | |
1393 | }; | |
1da177e4 LT |
1394 | struct ib_sge *sg_list; |
1395 | int num_sge; | |
1396 | }; | |
1397 | ||
1398 | enum ib_access_flags { | |
4fca0377 JG |
1399 | IB_ACCESS_LOCAL_WRITE = IB_UVERBS_ACCESS_LOCAL_WRITE, |
1400 | IB_ACCESS_REMOTE_WRITE = IB_UVERBS_ACCESS_REMOTE_WRITE, | |
1401 | IB_ACCESS_REMOTE_READ = IB_UVERBS_ACCESS_REMOTE_READ, | |
1402 | IB_ACCESS_REMOTE_ATOMIC = IB_UVERBS_ACCESS_REMOTE_ATOMIC, | |
1403 | IB_ACCESS_MW_BIND = IB_UVERBS_ACCESS_MW_BIND, | |
1404 | IB_ZERO_BASED = IB_UVERBS_ACCESS_ZERO_BASED, | |
1405 | IB_ACCESS_ON_DEMAND = IB_UVERBS_ACCESS_ON_DEMAND, | |
1406 | IB_ACCESS_HUGETLB = IB_UVERBS_ACCESS_HUGETLB, | |
1407 | ||
1408 | IB_ACCESS_SUPPORTED = ((IB_ACCESS_HUGETLB << 1) - 1) | |
1da177e4 LT |
1409 | }; |
1410 | ||
b7d3e0a9 CH |
1411 | /* |
1412 | * XXX: these are apparently used for ->rereg_user_mr, no idea why they | |
1413 | * are hidden here instead of a uapi header! | |
1414 | */ | |
1da177e4 LT |
1415 | enum ib_mr_rereg_flags { |
1416 | IB_MR_REREG_TRANS = 1, | |
1417 | IB_MR_REREG_PD = (1<<1), | |
7e6edb9b MB |
1418 | IB_MR_REREG_ACCESS = (1<<2), |
1419 | IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1) | |
1da177e4 LT |
1420 | }; |
1421 | ||
1da177e4 LT |
1422 | struct ib_fmr_attr { |
1423 | int max_pages; | |
1424 | int max_maps; | |
d36f34aa | 1425 | u8 page_shift; |
1da177e4 LT |
1426 | }; |
1427 | ||
882214e2 HE |
1428 | struct ib_umem; |
1429 | ||
38321256 | 1430 | enum rdma_remove_reason { |
1c77483e YH |
1431 | /* |
1432 | * Userspace requested uobject deletion or initial try | |
1433 | * to remove uobject via cleanup. Call could fail | |
1434 | */ | |
38321256 MB |
1435 | RDMA_REMOVE_DESTROY, |
1436 | /* Context deletion. This call should delete the actual object itself */ | |
1437 | RDMA_REMOVE_CLOSE, | |
1438 | /* Driver is being hot-unplugged. This call should delete the actual object itself */ | |
1439 | RDMA_REMOVE_DRIVER_REMOVE, | |
87ad80ab JG |
1440 | /* uobj is being cleaned-up before being committed */ |
1441 | RDMA_REMOVE_ABORT, | |
38321256 MB |
1442 | }; |
1443 | ||
43579b5f PP |
1444 | struct ib_rdmacg_object { |
1445 | #ifdef CONFIG_CGROUP_RDMA | |
1446 | struct rdma_cgroup *cg; /* owner rdma cgroup */ | |
1447 | #endif | |
1448 | }; | |
1449 | ||
e2773c06 RD |
1450 | struct ib_ucontext { |
1451 | struct ib_device *device; | |
771addf6 | 1452 | struct ib_uverbs_file *ufile; |
e951747a JG |
1453 | /* |
1454 | * 'closing' can be read by the driver only during a destroy callback, | |
1455 | * it is set when we are closing the file descriptor and indicates | |
1456 | * that mm_sem may be locked. | |
1457 | */ | |
6ceb6331 | 1458 | bool closing; |
8ada2c1c | 1459 | |
1c77483e | 1460 | bool cleanup_retryable; |
38321256 | 1461 | |
b5231b01 | 1462 | void (*invalidate_range)(struct ib_umem_odp *umem_odp, |
882214e2 | 1463 | unsigned long start, unsigned long end); |
f27a0d50 JG |
1464 | struct mutex per_mm_list_lock; |
1465 | struct list_head per_mm_list; | |
43579b5f PP |
1466 | |
1467 | struct ib_rdmacg_object cg_obj; | |
60615210 LR |
1468 | /* |
1469 | * Implementation details of the RDMA core, don't use in drivers: | |
1470 | */ | |
1471 | struct rdma_restrack_entry res; | |
e2773c06 RD |
1472 | }; |
1473 | ||
1474 | struct ib_uobject { | |
1475 | u64 user_handle; /* handle given to us by userspace */ | |
6a5e9c88 JG |
1476 | /* ufile & ucontext owning this object */ |
1477 | struct ib_uverbs_file *ufile; | |
1478 | /* FIXME, save memory: ufile->context == context */ | |
e2773c06 | 1479 | struct ib_ucontext *context; /* associated user context */ |
9ead190b | 1480 | void *object; /* containing object */ |
e2773c06 | 1481 | struct list_head list; /* link to context's list */ |
43579b5f | 1482 | struct ib_rdmacg_object cg_obj; /* rdmacg object */ |
b3d636b0 | 1483 | int id; /* index into kernel idr */ |
9ead190b | 1484 | struct kref ref; |
38321256 | 1485 | atomic_t usecnt; /* protects exclusive access */ |
d144da8c | 1486 | struct rcu_head rcu; /* kfree_rcu() overhead */ |
38321256 | 1487 | |
6b0d08f4 | 1488 | const struct uverbs_api_object *uapi_object; |
e2773c06 RD |
1489 | }; |
1490 | ||
e2773c06 | 1491 | struct ib_udata { |
309243ec | 1492 | const void __user *inbuf; |
e2773c06 RD |
1493 | void __user *outbuf; |
1494 | size_t inlen; | |
1495 | size_t outlen; | |
1496 | }; | |
1497 | ||
1da177e4 | 1498 | struct ib_pd { |
96249d70 | 1499 | u32 local_dma_lkey; |
ed082d36 | 1500 | u32 flags; |
e2773c06 RD |
1501 | struct ib_device *device; |
1502 | struct ib_uobject *uobject; | |
1503 | atomic_t usecnt; /* count all resources */ | |
50d46335 | 1504 | |
ed082d36 CH |
1505 | u32 unsafe_global_rkey; |
1506 | ||
50d46335 CH |
1507 | /* |
1508 | * Implementation details of the RDMA core, don't use in drivers: | |
1509 | */ | |
1510 | struct ib_mr *__internal_mr; | |
02d8883f | 1511 | struct rdma_restrack_entry res; |
1da177e4 LT |
1512 | }; |
1513 | ||
59991f94 SH |
1514 | struct ib_xrcd { |
1515 | struct ib_device *device; | |
d3d72d90 | 1516 | atomic_t usecnt; /* count all exposed resources */ |
53d0bd1e | 1517 | struct inode *inode; |
d3d72d90 SH |
1518 | |
1519 | struct mutex tgt_qp_mutex; | |
1520 | struct list_head tgt_qp_list; | |
59991f94 SH |
1521 | }; |
1522 | ||
1da177e4 LT |
1523 | struct ib_ah { |
1524 | struct ib_device *device; | |
1525 | struct ib_pd *pd; | |
e2773c06 | 1526 | struct ib_uobject *uobject; |
1a1f460f | 1527 | const struct ib_gid_attr *sgid_attr; |
44c58487 | 1528 | enum rdma_ah_attr_type type; |
1da177e4 LT |
1529 | }; |
1530 | ||
1531 | typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context); | |
1532 | ||
14d3a3b2 | 1533 | enum ib_poll_context { |
f794809a JM |
1534 | IB_POLL_DIRECT, /* caller context, no hw completions */ |
1535 | IB_POLL_SOFTIRQ, /* poll from softirq context */ | |
1536 | IB_POLL_WORKQUEUE, /* poll from workqueue */ | |
1537 | IB_POLL_UNBOUND_WORKQUEUE, /* poll from unbound workqueue */ | |
14d3a3b2 CH |
1538 | }; |
1539 | ||
1da177e4 | 1540 | struct ib_cq { |
e2773c06 RD |
1541 | struct ib_device *device; |
1542 | struct ib_uobject *uobject; | |
1543 | ib_comp_handler comp_handler; | |
1544 | void (*event_handler)(struct ib_event *, void *); | |
4deccd6d | 1545 | void *cq_context; |
e2773c06 RD |
1546 | int cqe; |
1547 | atomic_t usecnt; /* count number of work queues */ | |
14d3a3b2 CH |
1548 | enum ib_poll_context poll_ctx; |
1549 | struct ib_wc *wc; | |
1550 | union { | |
1551 | struct irq_poll iop; | |
1552 | struct work_struct work; | |
1553 | }; | |
f794809a | 1554 | struct workqueue_struct *comp_wq; |
da662979 | 1555 | struct dim *dim; |
02d8883f LR |
1556 | /* |
1557 | * Implementation details of the RDMA core, don't use in drivers: | |
1558 | */ | |
1559 | struct rdma_restrack_entry res; | |
1da177e4 LT |
1560 | }; |
1561 | ||
1562 | struct ib_srq { | |
d41fcc67 RD |
1563 | struct ib_device *device; |
1564 | struct ib_pd *pd; | |
1565 | struct ib_uobject *uobject; | |
1566 | void (*event_handler)(struct ib_event *, void *); | |
1567 | void *srq_context; | |
96104eda | 1568 | enum ib_srq_type srq_type; |
1da177e4 | 1569 | atomic_t usecnt; |
418d5130 | 1570 | |
1a56ff6d AK |
1571 | struct { |
1572 | struct ib_cq *cq; | |
1573 | union { | |
1574 | struct { | |
1575 | struct ib_xrcd *xrcd; | |
1576 | u32 srq_num; | |
1577 | } xrc; | |
1578 | }; | |
418d5130 | 1579 | } ext; |
1da177e4 LT |
1580 | }; |
1581 | ||
ebaaee25 NO |
1582 | enum ib_raw_packet_caps { |
1583 | /* Strip cvlan from incoming packet and report it in the matching work | |
1584 | * completion is supported. | |
1585 | */ | |
1586 | IB_RAW_PACKET_CAP_CVLAN_STRIPPING = (1 << 0), | |
1587 | /* Scatter FCS field of an incoming packet to host memory is supported. | |
1588 | */ | |
1589 | IB_RAW_PACKET_CAP_SCATTER_FCS = (1 << 1), | |
1590 | /* Checksum offloads are supported (for both send and receive). */ | |
1591 | IB_RAW_PACKET_CAP_IP_CSUM = (1 << 2), | |
7d9336d8 MG |
1592 | /* When a packet is received for an RQ with no receive WQEs, the |
1593 | * packet processing is delayed. | |
1594 | */ | |
1595 | IB_RAW_PACKET_CAP_DELAY_DROP = (1 << 3), | |
ebaaee25 NO |
1596 | }; |
1597 | ||
5fd251c8 YH |
1598 | enum ib_wq_type { |
1599 | IB_WQT_RQ | |
1600 | }; | |
1601 | ||
1602 | enum ib_wq_state { | |
1603 | IB_WQS_RESET, | |
1604 | IB_WQS_RDY, | |
1605 | IB_WQS_ERR | |
1606 | }; | |
1607 | ||
1608 | struct ib_wq { | |
1609 | struct ib_device *device; | |
1610 | struct ib_uobject *uobject; | |
1611 | void *wq_context; | |
1612 | void (*event_handler)(struct ib_event *, void *); | |
1613 | struct ib_pd *pd; | |
1614 | struct ib_cq *cq; | |
1615 | u32 wq_num; | |
1616 | enum ib_wq_state state; | |
1617 | enum ib_wq_type wq_type; | |
1618 | atomic_t usecnt; | |
1619 | }; | |
1620 | ||
10bac72b NO |
1621 | enum ib_wq_flags { |
1622 | IB_WQ_FLAGS_CVLAN_STRIPPING = 1 << 0, | |
27b0df11 | 1623 | IB_WQ_FLAGS_SCATTER_FCS = 1 << 1, |
7d9336d8 | 1624 | IB_WQ_FLAGS_DELAY_DROP = 1 << 2, |
e1d2e887 | 1625 | IB_WQ_FLAGS_PCI_WRITE_END_PADDING = 1 << 3, |
10bac72b NO |
1626 | }; |
1627 | ||
5fd251c8 YH |
1628 | struct ib_wq_init_attr { |
1629 | void *wq_context; | |
1630 | enum ib_wq_type wq_type; | |
1631 | u32 max_wr; | |
1632 | u32 max_sge; | |
1633 | struct ib_cq *cq; | |
1634 | void (*event_handler)(struct ib_event *, void *); | |
10bac72b | 1635 | u32 create_flags; /* Use enum ib_wq_flags */ |
5fd251c8 YH |
1636 | }; |
1637 | ||
1638 | enum ib_wq_attr_mask { | |
10bac72b NO |
1639 | IB_WQ_STATE = 1 << 0, |
1640 | IB_WQ_CUR_STATE = 1 << 1, | |
1641 | IB_WQ_FLAGS = 1 << 2, | |
5fd251c8 YH |
1642 | }; |
1643 | ||
1644 | struct ib_wq_attr { | |
1645 | enum ib_wq_state wq_state; | |
1646 | enum ib_wq_state curr_wq_state; | |
10bac72b NO |
1647 | u32 flags; /* Use enum ib_wq_flags */ |
1648 | u32 flags_mask; /* Use enum ib_wq_flags */ | |
5fd251c8 YH |
1649 | }; |
1650 | ||
6d39786b YH |
1651 | struct ib_rwq_ind_table { |
1652 | struct ib_device *device; | |
1653 | struct ib_uobject *uobject; | |
1654 | atomic_t usecnt; | |
1655 | u32 ind_tbl_num; | |
1656 | u32 log_ind_tbl_size; | |
1657 | struct ib_wq **ind_tbl; | |
1658 | }; | |
1659 | ||
1660 | struct ib_rwq_ind_table_init_attr { | |
1661 | u32 log_ind_tbl_size; | |
1662 | /* Each entry is a pointer to Receive Work Queue */ | |
1663 | struct ib_wq **ind_tbl; | |
1664 | }; | |
1665 | ||
d291f1a6 DJ |
1666 | enum port_pkey_state { |
1667 | IB_PORT_PKEY_NOT_VALID = 0, | |
1668 | IB_PORT_PKEY_VALID = 1, | |
1669 | IB_PORT_PKEY_LISTED = 2, | |
1670 | }; | |
1671 | ||
1672 | struct ib_qp_security; | |
1673 | ||
1674 | struct ib_port_pkey { | |
1675 | enum port_pkey_state state; | |
1676 | u16 pkey_index; | |
1677 | u8 port_num; | |
1678 | struct list_head qp_list; | |
1679 | struct list_head to_error_list; | |
1680 | struct ib_qp_security *sec; | |
1681 | }; | |
1682 | ||
1683 | struct ib_ports_pkeys { | |
1684 | struct ib_port_pkey main; | |
1685 | struct ib_port_pkey alt; | |
1686 | }; | |
1687 | ||
1688 | struct ib_qp_security { | |
1689 | struct ib_qp *qp; | |
1690 | struct ib_device *dev; | |
1691 | /* Hold this mutex when changing port and pkey settings. */ | |
1692 | struct mutex mutex; | |
1693 | struct ib_ports_pkeys *ports_pkeys; | |
1694 | /* A list of all open shared QP handles. Required to enforce security | |
1695 | * properly for all users of a shared QP. | |
1696 | */ | |
1697 | struct list_head shared_qp_list; | |
1698 | void *security; | |
1699 | bool destroying; | |
1700 | atomic_t error_list_count; | |
1701 | struct completion error_complete; | |
1702 | int error_comps_pending; | |
1703 | }; | |
1704 | ||
632bc3f6 BVA |
1705 | /* |
1706 | * @max_write_sge: Maximum SGE elements per RDMA WRITE request. | |
1707 | * @max_read_sge: Maximum SGE elements per RDMA READ request. | |
1708 | */ | |
1da177e4 LT |
1709 | struct ib_qp { |
1710 | struct ib_device *device; | |
1711 | struct ib_pd *pd; | |
1712 | struct ib_cq *send_cq; | |
1713 | struct ib_cq *recv_cq; | |
fffb0383 CH |
1714 | spinlock_t mr_lock; |
1715 | int mrs_used; | |
a060b562 | 1716 | struct list_head rdma_mrs; |
0e353e34 | 1717 | struct list_head sig_mrs; |
1da177e4 | 1718 | struct ib_srq *srq; |
b42b63cf | 1719 | struct ib_xrcd *xrcd; /* XRC TGT QPs only */ |
d3d72d90 | 1720 | struct list_head xrcd_list; |
fffb0383 | 1721 | |
319a441d HHZ |
1722 | /* count times opened, mcast attaches, flow attaches */ |
1723 | atomic_t usecnt; | |
0e0ec7e0 SH |
1724 | struct list_head open_list; |
1725 | struct ib_qp *real_qp; | |
e2773c06 | 1726 | struct ib_uobject *uobject; |
1da177e4 LT |
1727 | void (*event_handler)(struct ib_event *, void *); |
1728 | void *qp_context; | |
1a1f460f JG |
1729 | /* sgid_attrs associated with the AV's */ |
1730 | const struct ib_gid_attr *av_sgid_attr; | |
1731 | const struct ib_gid_attr *alt_path_sgid_attr; | |
1da177e4 | 1732 | u32 qp_num; |
632bc3f6 BVA |
1733 | u32 max_write_sge; |
1734 | u32 max_read_sge; | |
1da177e4 | 1735 | enum ib_qp_type qp_type; |
a9017e23 | 1736 | struct ib_rwq_ind_table *rwq_ind_tbl; |
d291f1a6 | 1737 | struct ib_qp_security *qp_sec; |
498ca3c8 | 1738 | u8 port; |
02d8883f | 1739 | |
185eddc4 | 1740 | bool integrity_en; |
02d8883f LR |
1741 | /* |
1742 | * Implementation details of the RDMA core, don't use in drivers: | |
1743 | */ | |
1744 | struct rdma_restrack_entry res; | |
99fa331d MZ |
1745 | |
1746 | /* The counter the qp is bind to */ | |
1747 | struct rdma_counter *counter; | |
1da177e4 LT |
1748 | }; |
1749 | ||
bee76d7a AL |
1750 | struct ib_dm { |
1751 | struct ib_device *device; | |
1752 | u32 length; | |
1753 | u32 flags; | |
1754 | struct ib_uobject *uobject; | |
1755 | atomic_t usecnt; | |
1756 | }; | |
1757 | ||
1da177e4 | 1758 | struct ib_mr { |
e2773c06 RD |
1759 | struct ib_device *device; |
1760 | struct ib_pd *pd; | |
e2773c06 RD |
1761 | u32 lkey; |
1762 | u32 rkey; | |
4c67e2bf | 1763 | u64 iova; |
edd31551 | 1764 | u64 length; |
4c67e2bf | 1765 | unsigned int page_size; |
a0bc099a | 1766 | enum ib_mr_type type; |
d4a85c30 | 1767 | bool need_inval; |
fffb0383 CH |
1768 | union { |
1769 | struct ib_uobject *uobject; /* user */ | |
1770 | struct list_head qp_entry; /* FR */ | |
1771 | }; | |
fccec5b8 | 1772 | |
be934cca | 1773 | struct ib_dm *dm; |
7c717d3a | 1774 | struct ib_sig_attrs *sig_attrs; /* only for IB_MR_TYPE_INTEGRITY MRs */ |
fccec5b8 SW |
1775 | /* |
1776 | * Implementation details of the RDMA core, don't use in drivers: | |
1777 | */ | |
1778 | struct rdma_restrack_entry res; | |
1da177e4 LT |
1779 | }; |
1780 | ||
1781 | struct ib_mw { | |
1782 | struct ib_device *device; | |
1783 | struct ib_pd *pd; | |
e2773c06 | 1784 | struct ib_uobject *uobject; |
1da177e4 | 1785 | u32 rkey; |
7083e42e | 1786 | enum ib_mw_type type; |
1da177e4 LT |
1787 | }; |
1788 | ||
1789 | struct ib_fmr { | |
1790 | struct ib_device *device; | |
1791 | struct ib_pd *pd; | |
1792 | struct list_head list; | |
1793 | u32 lkey; | |
1794 | u32 rkey; | |
1795 | }; | |
1796 | ||
319a441d HHZ |
1797 | /* Supported steering options */ |
1798 | enum ib_flow_attr_type { | |
1799 | /* steering according to rule specifications */ | |
1800 | IB_FLOW_ATTR_NORMAL = 0x0, | |
1801 | /* default unicast and multicast rule - | |
1802 | * receive all Eth traffic which isn't steered to any QP | |
1803 | */ | |
1804 | IB_FLOW_ATTR_ALL_DEFAULT = 0x1, | |
1805 | /* default multicast rule - | |
1806 | * receive all Eth multicast traffic which isn't steered to any QP | |
1807 | */ | |
1808 | IB_FLOW_ATTR_MC_DEFAULT = 0x2, | |
1809 | /* sniffer rule - receive all port traffic */ | |
1810 | IB_FLOW_ATTR_SNIFFER = 0x3 | |
1811 | }; | |
1812 | ||
1813 | /* Supported steering header types */ | |
1814 | enum ib_flow_spec_type { | |
1815 | /* L2 headers*/ | |
76bd23b3 MR |
1816 | IB_FLOW_SPEC_ETH = 0x20, |
1817 | IB_FLOW_SPEC_IB = 0x22, | |
319a441d | 1818 | /* L3 header*/ |
76bd23b3 MR |
1819 | IB_FLOW_SPEC_IPV4 = 0x30, |
1820 | IB_FLOW_SPEC_IPV6 = 0x31, | |
56ab0b38 | 1821 | IB_FLOW_SPEC_ESP = 0x34, |
319a441d | 1822 | /* L4 headers*/ |
76bd23b3 MR |
1823 | IB_FLOW_SPEC_TCP = 0x40, |
1824 | IB_FLOW_SPEC_UDP = 0x41, | |
0dbf3332 | 1825 | IB_FLOW_SPEC_VXLAN_TUNNEL = 0x50, |
d90e5e50 | 1826 | IB_FLOW_SPEC_GRE = 0x51, |
b04f0f03 | 1827 | IB_FLOW_SPEC_MPLS = 0x60, |
fbf46860 | 1828 | IB_FLOW_SPEC_INNER = 0x100, |
460d0198 MR |
1829 | /* Actions */ |
1830 | IB_FLOW_SPEC_ACTION_TAG = 0x1000, | |
483a3966 | 1831 | IB_FLOW_SPEC_ACTION_DROP = 0x1001, |
9b828441 | 1832 | IB_FLOW_SPEC_ACTION_HANDLE = 0x1002, |
7eea23a5 | 1833 | IB_FLOW_SPEC_ACTION_COUNT = 0x1003, |
319a441d | 1834 | }; |
240ae00e | 1835 | #define IB_FLOW_SPEC_LAYER_MASK 0xF0 |
7eea23a5 | 1836 | #define IB_FLOW_SPEC_SUPPORT_LAYERS 10 |
22878dbc | 1837 | |
319a441d HHZ |
1838 | /* Flow steering rule priority is set according to it's domain. |
1839 | * Lower domain value means higher priority. | |
1840 | */ | |
1841 | enum ib_flow_domain { | |
1842 | IB_FLOW_DOMAIN_USER, | |
1843 | IB_FLOW_DOMAIN_ETHTOOL, | |
1844 | IB_FLOW_DOMAIN_RFS, | |
1845 | IB_FLOW_DOMAIN_NIC, | |
1846 | IB_FLOW_DOMAIN_NUM /* Must be last */ | |
1847 | }; | |
1848 | ||
a3100a78 MV |
1849 | enum ib_flow_flags { |
1850 | IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */ | |
21e82d3e BP |
1851 | IB_FLOW_ATTR_FLAGS_EGRESS = 1UL << 2, /* Egress flow */ |
1852 | IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 3 /* Must be last */ | |
a3100a78 MV |
1853 | }; |
1854 | ||
319a441d HHZ |
1855 | struct ib_flow_eth_filter { |
1856 | u8 dst_mac[6]; | |
1857 | u8 src_mac[6]; | |
1858 | __be16 ether_type; | |
1859 | __be16 vlan_tag; | |
15dfbd6b MG |
1860 | /* Must be last */ |
1861 | u8 real_sz[0]; | |
319a441d HHZ |
1862 | }; |
1863 | ||
1864 | struct ib_flow_spec_eth { | |
fbf46860 | 1865 | u32 type; |
319a441d HHZ |
1866 | u16 size; |
1867 | struct ib_flow_eth_filter val; | |
1868 | struct ib_flow_eth_filter mask; | |
1869 | }; | |
1870 | ||
240ae00e MB |
1871 | struct ib_flow_ib_filter { |
1872 | __be16 dlid; | |
1873 | __u8 sl; | |
15dfbd6b MG |
1874 | /* Must be last */ |
1875 | u8 real_sz[0]; | |
240ae00e MB |
1876 | }; |
1877 | ||
1878 | struct ib_flow_spec_ib { | |
fbf46860 | 1879 | u32 type; |
240ae00e MB |
1880 | u16 size; |
1881 | struct ib_flow_ib_filter val; | |
1882 | struct ib_flow_ib_filter mask; | |
1883 | }; | |
1884 | ||
989a3a8f MG |
1885 | /* IPv4 header flags */ |
1886 | enum ib_ipv4_flags { | |
1887 | IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */ | |
1888 | IB_IPV4_MORE_FRAG = 0X4 /* For All fragmented packets except the | |
1889 | last have this flag set */ | |
1890 | }; | |
1891 | ||
319a441d HHZ |
1892 | struct ib_flow_ipv4_filter { |
1893 | __be32 src_ip; | |
1894 | __be32 dst_ip; | |
989a3a8f MG |
1895 | u8 proto; |
1896 | u8 tos; | |
1897 | u8 ttl; | |
1898 | u8 flags; | |
15dfbd6b MG |
1899 | /* Must be last */ |
1900 | u8 real_sz[0]; | |
319a441d HHZ |
1901 | }; |
1902 | ||
1903 | struct ib_flow_spec_ipv4 { | |
fbf46860 | 1904 | u32 type; |
319a441d HHZ |
1905 | u16 size; |
1906 | struct ib_flow_ipv4_filter val; | |
1907 | struct ib_flow_ipv4_filter mask; | |
1908 | }; | |
1909 | ||
4c2aae71 MG |
1910 | struct ib_flow_ipv6_filter { |
1911 | u8 src_ip[16]; | |
1912 | u8 dst_ip[16]; | |
a72c6a2b MG |
1913 | __be32 flow_label; |
1914 | u8 next_hdr; | |
1915 | u8 traffic_class; | |
1916 | u8 hop_limit; | |
15dfbd6b MG |
1917 | /* Must be last */ |
1918 | u8 real_sz[0]; | |
4c2aae71 MG |
1919 | }; |
1920 | ||
1921 | struct ib_flow_spec_ipv6 { | |
fbf46860 | 1922 | u32 type; |
4c2aae71 MG |
1923 | u16 size; |
1924 | struct ib_flow_ipv6_filter val; | |
1925 | struct ib_flow_ipv6_filter mask; | |
1926 | }; | |
1927 | ||
319a441d HHZ |
1928 | struct ib_flow_tcp_udp_filter { |
1929 | __be16 dst_port; | |
1930 | __be16 src_port; | |
15dfbd6b MG |
1931 | /* Must be last */ |
1932 | u8 real_sz[0]; | |
319a441d HHZ |
1933 | }; |
1934 | ||
1935 | struct ib_flow_spec_tcp_udp { | |
fbf46860 | 1936 | u32 type; |
319a441d HHZ |
1937 | u16 size; |
1938 | struct ib_flow_tcp_udp_filter val; | |
1939 | struct ib_flow_tcp_udp_filter mask; | |
1940 | }; | |
1941 | ||
0dbf3332 MR |
1942 | struct ib_flow_tunnel_filter { |
1943 | __be32 tunnel_id; | |
1944 | u8 real_sz[0]; | |
1945 | }; | |
1946 | ||
1947 | /* ib_flow_spec_tunnel describes the Vxlan tunnel | |
1948 | * the tunnel_id from val has the vni value | |
1949 | */ | |
1950 | struct ib_flow_spec_tunnel { | |
fbf46860 | 1951 | u32 type; |
0dbf3332 MR |
1952 | u16 size; |
1953 | struct ib_flow_tunnel_filter val; | |
1954 | struct ib_flow_tunnel_filter mask; | |
1955 | }; | |
1956 | ||
56ab0b38 MB |
1957 | struct ib_flow_esp_filter { |
1958 | __be32 spi; | |
1959 | __be32 seq; | |
1960 | /* Must be last */ | |
1961 | u8 real_sz[0]; | |
1962 | }; | |
1963 | ||
1964 | struct ib_flow_spec_esp { | |
1965 | u32 type; | |
1966 | u16 size; | |
1967 | struct ib_flow_esp_filter val; | |
1968 | struct ib_flow_esp_filter mask; | |
1969 | }; | |
1970 | ||
d90e5e50 AL |
1971 | struct ib_flow_gre_filter { |
1972 | __be16 c_ks_res0_ver; | |
1973 | __be16 protocol; | |
1974 | __be32 key; | |
1975 | /* Must be last */ | |
1976 | u8 real_sz[0]; | |
1977 | }; | |
1978 | ||
1979 | struct ib_flow_spec_gre { | |
1980 | u32 type; | |
1981 | u16 size; | |
1982 | struct ib_flow_gre_filter val; | |
1983 | struct ib_flow_gre_filter mask; | |
1984 | }; | |
1985 | ||
b04f0f03 AL |
1986 | struct ib_flow_mpls_filter { |
1987 | __be32 tag; | |
1988 | /* Must be last */ | |
1989 | u8 real_sz[0]; | |
1990 | }; | |
1991 | ||
1992 | struct ib_flow_spec_mpls { | |
1993 | u32 type; | |
1994 | u16 size; | |
1995 | struct ib_flow_mpls_filter val; | |
1996 | struct ib_flow_mpls_filter mask; | |
1997 | }; | |
1998 | ||
460d0198 MR |
1999 | struct ib_flow_spec_action_tag { |
2000 | enum ib_flow_spec_type type; | |
2001 | u16 size; | |
2002 | u32 tag_id; | |
2003 | }; | |
2004 | ||
483a3966 SS |
2005 | struct ib_flow_spec_action_drop { |
2006 | enum ib_flow_spec_type type; | |
2007 | u16 size; | |
2008 | }; | |
2009 | ||
9b828441 MB |
2010 | struct ib_flow_spec_action_handle { |
2011 | enum ib_flow_spec_type type; | |
2012 | u16 size; | |
2013 | struct ib_flow_action *act; | |
2014 | }; | |
2015 | ||
7eea23a5 RS |
2016 | enum ib_counters_description { |
2017 | IB_COUNTER_PACKETS, | |
2018 | IB_COUNTER_BYTES, | |
2019 | }; | |
2020 | ||
2021 | struct ib_flow_spec_action_count { | |
2022 | enum ib_flow_spec_type type; | |
2023 | u16 size; | |
2024 | struct ib_counters *counters; | |
2025 | }; | |
2026 | ||
319a441d HHZ |
2027 | union ib_flow_spec { |
2028 | struct { | |
fbf46860 | 2029 | u32 type; |
319a441d HHZ |
2030 | u16 size; |
2031 | }; | |
2032 | struct ib_flow_spec_eth eth; | |
240ae00e | 2033 | struct ib_flow_spec_ib ib; |
319a441d HHZ |
2034 | struct ib_flow_spec_ipv4 ipv4; |
2035 | struct ib_flow_spec_tcp_udp tcp_udp; | |
4c2aae71 | 2036 | struct ib_flow_spec_ipv6 ipv6; |
0dbf3332 | 2037 | struct ib_flow_spec_tunnel tunnel; |
56ab0b38 | 2038 | struct ib_flow_spec_esp esp; |
d90e5e50 | 2039 | struct ib_flow_spec_gre gre; |
b04f0f03 | 2040 | struct ib_flow_spec_mpls mpls; |
460d0198 | 2041 | struct ib_flow_spec_action_tag flow_tag; |
483a3966 | 2042 | struct ib_flow_spec_action_drop drop; |
9b828441 | 2043 | struct ib_flow_spec_action_handle action; |
7eea23a5 | 2044 | struct ib_flow_spec_action_count flow_count; |
319a441d HHZ |
2045 | }; |
2046 | ||
2047 | struct ib_flow_attr { | |
2048 | enum ib_flow_attr_type type; | |
2049 | u16 size; | |
2050 | u16 priority; | |
2051 | u32 flags; | |
2052 | u8 num_of_specs; | |
2053 | u8 port; | |
7654cb1b | 2054 | union ib_flow_spec flows[]; |
319a441d HHZ |
2055 | }; |
2056 | ||
2057 | struct ib_flow { | |
2058 | struct ib_qp *qp; | |
6cd080a6 | 2059 | struct ib_device *device; |
319a441d HHZ |
2060 | struct ib_uobject *uobject; |
2061 | }; | |
2062 | ||
2eb9beae MB |
2063 | enum ib_flow_action_type { |
2064 | IB_FLOW_ACTION_UNSPECIFIED, | |
2065 | IB_FLOW_ACTION_ESP = 1, | |
2066 | }; | |
2067 | ||
2068 | struct ib_flow_action_attrs_esp_keymats { | |
2069 | enum ib_uverbs_flow_action_esp_keymat protocol; | |
2070 | union { | |
2071 | struct ib_uverbs_flow_action_esp_keymat_aes_gcm aes_gcm; | |
2072 | } keymat; | |
2073 | }; | |
2074 | ||
2075 | struct ib_flow_action_attrs_esp_replays { | |
2076 | enum ib_uverbs_flow_action_esp_replay protocol; | |
2077 | union { | |
2078 | struct ib_uverbs_flow_action_esp_replay_bmp bmp; | |
2079 | } replay; | |
2080 | }; | |
2081 | ||
2082 | enum ib_flow_action_attrs_esp_flags { | |
2083 | /* All user-space flags at the top: Use enum ib_uverbs_flow_action_esp_flags | |
2084 | * This is done in order to share the same flags between user-space and | |
2085 | * kernel and spare an unnecessary translation. | |
2086 | */ | |
2087 | ||
2088 | /* Kernel flags */ | |
2089 | IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED = 1ULL << 32, | |
7d12f8d5 | 2090 | IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS = 1ULL << 33, |
2eb9beae MB |
2091 | }; |
2092 | ||
2093 | struct ib_flow_spec_list { | |
2094 | struct ib_flow_spec_list *next; | |
2095 | union ib_flow_spec spec; | |
2096 | }; | |
2097 | ||
2098 | struct ib_flow_action_attrs_esp { | |
2099 | struct ib_flow_action_attrs_esp_keymats *keymat; | |
2100 | struct ib_flow_action_attrs_esp_replays *replay; | |
2101 | struct ib_flow_spec_list *encap; | |
2102 | /* Used only if IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED is enabled. | |
2103 | * Value of 0 is a valid value. | |
2104 | */ | |
2105 | u32 esn; | |
2106 | u32 spi; | |
2107 | u32 seq; | |
2108 | u32 tfc_pad; | |
2109 | /* Use enum ib_flow_action_attrs_esp_flags */ | |
2110 | u64 flags; | |
2111 | u64 hard_limit_pkts; | |
2112 | }; | |
2113 | ||
2114 | struct ib_flow_action { | |
2115 | struct ib_device *device; | |
2116 | struct ib_uobject *uobject; | |
2117 | enum ib_flow_action_type type; | |
2118 | atomic_t usecnt; | |
2119 | }; | |
2120 | ||
4cd7c947 | 2121 | struct ib_mad_hdr; |
1da177e4 LT |
2122 | struct ib_grh; |
2123 | ||
2124 | enum ib_process_mad_flags { | |
2125 | IB_MAD_IGNORE_MKEY = 1, | |
2126 | IB_MAD_IGNORE_BKEY = 2, | |
2127 | IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY | |
2128 | }; | |
2129 | ||
2130 | enum ib_mad_result { | |
2131 | IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */ | |
2132 | IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */ | |
2133 | IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */ | |
2134 | IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */ | |
2135 | }; | |
2136 | ||
21d6454a | 2137 | struct ib_port_cache { |
883c71fe | 2138 | u64 subnet_prefix; |
21d6454a JW |
2139 | struct ib_pkey_cache *pkey; |
2140 | struct ib_gid_table *gid; | |
2141 | u8 lmc; | |
2142 | enum ib_port_state port_state; | |
2143 | }; | |
2144 | ||
1da177e4 LT |
2145 | struct ib_cache { |
2146 | rwlock_t lock; | |
2147 | struct ib_event_handler event_handler; | |
1da177e4 LT |
2148 | }; |
2149 | ||
7738613e IW |
2150 | struct ib_port_immutable { |
2151 | int pkey_tbl_len; | |
2152 | int gid_tbl_len; | |
f9b22e35 | 2153 | u32 core_cap_flags; |
337877a4 | 2154 | u32 max_mad_size; |
7738613e IW |
2155 | }; |
2156 | ||
8ceb1357 | 2157 | struct ib_port_data { |
324e227e JG |
2158 | struct ib_device *ib_dev; |
2159 | ||
8ceb1357 JG |
2160 | struct ib_port_immutable immutable; |
2161 | ||
2162 | spinlock_t pkey_list_lock; | |
2163 | struct list_head pkey_list; | |
8faea9fd JG |
2164 | |
2165 | struct ib_port_cache cache; | |
c2261dd7 JG |
2166 | |
2167 | spinlock_t netdev_lock; | |
324e227e JG |
2168 | struct net_device __rcu *netdev; |
2169 | struct hlist_node ndev_hash_link; | |
413d3347 | 2170 | struct rdma_port_counter port_counter; |
6e7be47a | 2171 | struct rdma_hw_stats *hw_stats; |
8ceb1357 JG |
2172 | }; |
2173 | ||
2fc77572 VN |
2174 | /* rdma netdev type - specifies protocol type */ |
2175 | enum rdma_netdev_t { | |
f0ad83ac NV |
2176 | RDMA_NETDEV_OPA_VNIC, |
2177 | RDMA_NETDEV_IPOIB, | |
2fc77572 VN |
2178 | }; |
2179 | ||
2180 | /** | |
2181 | * struct rdma_netdev - rdma netdev | |
2182 | * For cases where netstack interfacing is required. | |
2183 | */ | |
2184 | struct rdma_netdev { | |
2185 | void *clnt_priv; | |
2186 | struct ib_device *hca; | |
2187 | u8 port_num; | |
2188 | ||
9f49a5b5 JG |
2189 | /* |
2190 | * cleanup function must be specified. | |
2191 | * FIXME: This is only used for OPA_VNIC and that usage should be | |
2192 | * removed too. | |
2193 | */ | |
8e959601 NV |
2194 | void (*free_rdma_netdev)(struct net_device *netdev); |
2195 | ||
2fc77572 VN |
2196 | /* control functions */ |
2197 | void (*set_id)(struct net_device *netdev, int id); | |
f0ad83ac NV |
2198 | /* send packet */ |
2199 | int (*send)(struct net_device *dev, struct sk_buff *skb, | |
2200 | struct ib_ah *address, u32 dqpn); | |
2201 | /* multicast */ | |
2202 | int (*attach_mcast)(struct net_device *dev, struct ib_device *hca, | |
2203 | union ib_gid *gid, u16 mlid, | |
2204 | int set_qkey, u32 qkey); | |
2205 | int (*detach_mcast)(struct net_device *dev, struct ib_device *hca, | |
2206 | union ib_gid *gid, u16 mlid); | |
2fc77572 VN |
2207 | }; |
2208 | ||
f6a8a19b DD |
2209 | struct rdma_netdev_alloc_params { |
2210 | size_t sizeof_priv; | |
2211 | unsigned int txqs; | |
2212 | unsigned int rxqs; | |
2213 | void *param; | |
2214 | ||
2215 | int (*initialize_rdma_netdev)(struct ib_device *device, u8 port_num, | |
2216 | struct net_device *netdev, void *param); | |
2217 | }; | |
2218 | ||
fa9b1802 RS |
2219 | struct ib_counters { |
2220 | struct ib_device *device; | |
2221 | struct ib_uobject *uobject; | |
2222 | /* num of objects attached */ | |
2223 | atomic_t usecnt; | |
2224 | }; | |
2225 | ||
51d7a538 RS |
2226 | struct ib_counters_read_attr { |
2227 | u64 *counters_buff; | |
2228 | u32 ncounters; | |
2229 | u32 flags; /* use enum ib_read_counters_flags */ | |
2230 | }; | |
2231 | ||
2eb9beae | 2232 | struct uverbs_attr_bundle; |
dd05cb82 KH |
2233 | struct iw_cm_id; |
2234 | struct iw_cm_conn_param; | |
2eb9beae | 2235 | |
30471d4b LR |
2236 | #define INIT_RDMA_OBJ_SIZE(ib_struct, drv_struct, member) \ |
2237 | .size_##ib_struct = \ | |
2238 | (sizeof(struct drv_struct) + \ | |
2239 | BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) + \ | |
2240 | BUILD_BUG_ON_ZERO( \ | |
2241 | !__same_type(((struct drv_struct *)NULL)->member, \ | |
2242 | struct ib_struct))) | |
2243 | ||
f6316032 LR |
2244 | #define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp) \ |
2245 | ((struct ib_type *)kzalloc(ib_dev->ops.size_##ib_type, gfp)) | |
2246 | ||
30471d4b | 2247 | #define rdma_zalloc_drv_obj(ib_dev, ib_type) \ |
f6316032 | 2248 | rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, GFP_KERNEL) |
30471d4b LR |
2249 | |
2250 | #define DECLARE_RDMA_OBJ_SIZE(ib_struct) size_t size_##ib_struct | |
2251 | ||
521ed0d9 KH |
2252 | /** |
2253 | * struct ib_device_ops - InfiniBand device operations | |
2254 | * This structure defines all the InfiniBand device operations, providers will | |
2255 | * need to define the supported operations, otherwise they will be set to null. | |
2256 | */ | |
2257 | struct ib_device_ops { | |
7a154142 | 2258 | struct module *owner; |
b9560a41 | 2259 | enum rdma_driver_id driver_id; |
72c6ec18 | 2260 | u32 uverbs_abi_ver; |
8f71bb00 | 2261 | unsigned int uverbs_no_driver_id_binding:1; |
b9560a41 | 2262 | |
521ed0d9 KH |
2263 | int (*post_send)(struct ib_qp *qp, const struct ib_send_wr *send_wr, |
2264 | const struct ib_send_wr **bad_send_wr); | |
2265 | int (*post_recv)(struct ib_qp *qp, const struct ib_recv_wr *recv_wr, | |
2266 | const struct ib_recv_wr **bad_recv_wr); | |
2267 | void (*drain_rq)(struct ib_qp *qp); | |
2268 | void (*drain_sq)(struct ib_qp *qp); | |
2269 | int (*poll_cq)(struct ib_cq *cq, int num_entries, struct ib_wc *wc); | |
2270 | int (*peek_cq)(struct ib_cq *cq, int wc_cnt); | |
2271 | int (*req_notify_cq)(struct ib_cq *cq, enum ib_cq_notify_flags flags); | |
2272 | int (*req_ncomp_notif)(struct ib_cq *cq, int wc_cnt); | |
2273 | int (*post_srq_recv)(struct ib_srq *srq, | |
2274 | const struct ib_recv_wr *recv_wr, | |
2275 | const struct ib_recv_wr **bad_recv_wr); | |
2276 | int (*process_mad)(struct ib_device *device, int process_mad_flags, | |
2277 | u8 port_num, const struct ib_wc *in_wc, | |
2278 | const struct ib_grh *in_grh, | |
2279 | const struct ib_mad_hdr *in_mad, size_t in_mad_size, | |
2280 | struct ib_mad_hdr *out_mad, size_t *out_mad_size, | |
2281 | u16 *out_mad_pkey_index); | |
2282 | int (*query_device)(struct ib_device *device, | |
2283 | struct ib_device_attr *device_attr, | |
2284 | struct ib_udata *udata); | |
2285 | int (*modify_device)(struct ib_device *device, int device_modify_mask, | |
2286 | struct ib_device_modify *device_modify); | |
2287 | void (*get_dev_fw_str)(struct ib_device *device, char *str); | |
2288 | const struct cpumask *(*get_vector_affinity)(struct ib_device *ibdev, | |
2289 | int comp_vector); | |
2290 | int (*query_port)(struct ib_device *device, u8 port_num, | |
2291 | struct ib_port_attr *port_attr); | |
2292 | int (*modify_port)(struct ib_device *device, u8 port_num, | |
2293 | int port_modify_mask, | |
2294 | struct ib_port_modify *port_modify); | |
2295 | /** | |
2296 | * The following mandatory functions are used only at device | |
2297 | * registration. Keep functions such as these at the end of this | |
2298 | * structure to avoid cache line misses when accessing struct ib_device | |
2299 | * in fast paths. | |
2300 | */ | |
2301 | int (*get_port_immutable)(struct ib_device *device, u8 port_num, | |
2302 | struct ib_port_immutable *immutable); | |
2303 | enum rdma_link_layer (*get_link_layer)(struct ib_device *device, | |
2304 | u8 port_num); | |
2305 | /** | |
2306 | * When calling get_netdev, the HW vendor's driver should return the | |
2307 | * net device of device @device at port @port_num or NULL if such | |
2308 | * a net device doesn't exist. The vendor driver should call dev_hold | |
2309 | * on this net device. The HW vendor's device driver must guarantee | |
2310 | * that this function returns NULL before the net device has finished | |
2311 | * NETDEV_UNREGISTER state. | |
2312 | */ | |
2313 | struct net_device *(*get_netdev)(struct ib_device *device, u8 port_num); | |
2314 | /** | |
2315 | * rdma netdev operation | |
2316 | * | |
2317 | * Driver implementing alloc_rdma_netdev or rdma_netdev_get_params | |
2318 | * must return -EOPNOTSUPP if it doesn't support the specified type. | |
2319 | */ | |
2320 | struct net_device *(*alloc_rdma_netdev)( | |
2321 | struct ib_device *device, u8 port_num, enum rdma_netdev_t type, | |
2322 | const char *name, unsigned char name_assign_type, | |
2323 | void (*setup)(struct net_device *)); | |
2324 | ||
2325 | int (*rdma_netdev_get_params)(struct ib_device *device, u8 port_num, | |
2326 | enum rdma_netdev_t type, | |
2327 | struct rdma_netdev_alloc_params *params); | |
2328 | /** | |
2329 | * query_gid should be return GID value for @device, when @port_num | |
2330 | * link layer is either IB or iWarp. It is no-op if @port_num port | |
2331 | * is RoCE link layer. | |
2332 | */ | |
2333 | int (*query_gid)(struct ib_device *device, u8 port_num, int index, | |
2334 | union ib_gid *gid); | |
2335 | /** | |
2336 | * When calling add_gid, the HW vendor's driver should add the gid | |
2337 | * of device of port at gid index available at @attr. Meta-info of | |
2338 | * that gid (for example, the network device related to this gid) is | |
2339 | * available at @attr. @context allows the HW vendor driver to store | |
2340 | * extra information together with a GID entry. The HW vendor driver may | |
2341 | * allocate memory to contain this information and store it in @context | |
2342 | * when a new GID entry is written to. Params are consistent until the | |
2343 | * next call of add_gid or delete_gid. The function should return 0 on | |
2344 | * success or error otherwise. The function could be called | |
2345 | * concurrently for different ports. This function is only called when | |
2346 | * roce_gid_table is used. | |
2347 | */ | |
2348 | int (*add_gid)(const struct ib_gid_attr *attr, void **context); | |
2349 | /** | |
2350 | * When calling del_gid, the HW vendor's driver should delete the | |
2351 | * gid of device @device at gid index gid_index of port port_num | |
2352 | * available in @attr. | |
2353 | * Upon the deletion of a GID entry, the HW vendor must free any | |
2354 | * allocated memory. The caller will clear @context afterwards. | |
2355 | * This function is only called when roce_gid_table is used. | |
2356 | */ | |
2357 | int (*del_gid)(const struct ib_gid_attr *attr, void **context); | |
2358 | int (*query_pkey)(struct ib_device *device, u8 port_num, u16 index, | |
2359 | u16 *pkey); | |
a2a074ef LR |
2360 | int (*alloc_ucontext)(struct ib_ucontext *context, |
2361 | struct ib_udata *udata); | |
2362 | void (*dealloc_ucontext)(struct ib_ucontext *context); | |
521ed0d9 KH |
2363 | int (*mmap)(struct ib_ucontext *context, struct vm_area_struct *vma); |
2364 | void (*disassociate_ucontext)(struct ib_ucontext *ibcontext); | |
ff23dfa1 | 2365 | int (*alloc_pd)(struct ib_pd *pd, struct ib_udata *udata); |
c4367a26 | 2366 | void (*dealloc_pd)(struct ib_pd *pd, struct ib_udata *udata); |
d3456914 LR |
2367 | int (*create_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr, |
2368 | u32 flags, struct ib_udata *udata); | |
521ed0d9 KH |
2369 | int (*modify_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr); |
2370 | int (*query_ah)(struct ib_ah *ah, struct rdma_ah_attr *ah_attr); | |
d3456914 | 2371 | void (*destroy_ah)(struct ib_ah *ah, u32 flags); |
68e326de LR |
2372 | int (*create_srq)(struct ib_srq *srq, |
2373 | struct ib_srq_init_attr *srq_init_attr, | |
2374 | struct ib_udata *udata); | |
521ed0d9 KH |
2375 | int (*modify_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr, |
2376 | enum ib_srq_attr_mask srq_attr_mask, | |
2377 | struct ib_udata *udata); | |
2378 | int (*query_srq)(struct ib_srq *srq, struct ib_srq_attr *srq_attr); | |
68e326de | 2379 | void (*destroy_srq)(struct ib_srq *srq, struct ib_udata *udata); |
521ed0d9 KH |
2380 | struct ib_qp *(*create_qp)(struct ib_pd *pd, |
2381 | struct ib_qp_init_attr *qp_init_attr, | |
2382 | struct ib_udata *udata); | |
2383 | int (*modify_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr, | |
2384 | int qp_attr_mask, struct ib_udata *udata); | |
2385 | int (*query_qp)(struct ib_qp *qp, struct ib_qp_attr *qp_attr, | |
2386 | int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr); | |
c4367a26 | 2387 | int (*destroy_qp)(struct ib_qp *qp, struct ib_udata *udata); |
e39afe3d LR |
2388 | int (*create_cq)(struct ib_cq *cq, const struct ib_cq_init_attr *attr, |
2389 | struct ib_udata *udata); | |
521ed0d9 | 2390 | int (*modify_cq)(struct ib_cq *cq, u16 cq_count, u16 cq_period); |
a52c8e24 | 2391 | void (*destroy_cq)(struct ib_cq *cq, struct ib_udata *udata); |
521ed0d9 KH |
2392 | int (*resize_cq)(struct ib_cq *cq, int cqe, struct ib_udata *udata); |
2393 | struct ib_mr *(*get_dma_mr)(struct ib_pd *pd, int mr_access_flags); | |
2394 | struct ib_mr *(*reg_user_mr)(struct ib_pd *pd, u64 start, u64 length, | |
2395 | u64 virt_addr, int mr_access_flags, | |
2396 | struct ib_udata *udata); | |
2397 | int (*rereg_user_mr)(struct ib_mr *mr, int flags, u64 start, u64 length, | |
2398 | u64 virt_addr, int mr_access_flags, | |
2399 | struct ib_pd *pd, struct ib_udata *udata); | |
c4367a26 | 2400 | int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata); |
521ed0d9 | 2401 | struct ib_mr *(*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type, |
c4367a26 | 2402 | u32 max_num_sg, struct ib_udata *udata); |
26bc7eae IR |
2403 | struct ib_mr *(*alloc_mr_integrity)(struct ib_pd *pd, |
2404 | u32 max_num_data_sg, | |
2405 | u32 max_num_meta_sg); | |
ad8a4496 MS |
2406 | int (*advise_mr)(struct ib_pd *pd, |
2407 | enum ib_uverbs_advise_mr_advice advice, u32 flags, | |
2408 | struct ib_sge *sg_list, u32 num_sge, | |
2409 | struct uverbs_attr_bundle *attrs); | |
521ed0d9 KH |
2410 | int (*map_mr_sg)(struct ib_mr *mr, struct scatterlist *sg, int sg_nents, |
2411 | unsigned int *sg_offset); | |
2412 | int (*check_mr_status)(struct ib_mr *mr, u32 check_mask, | |
2413 | struct ib_mr_status *mr_status); | |
2414 | struct ib_mw *(*alloc_mw)(struct ib_pd *pd, enum ib_mw_type type, | |
2415 | struct ib_udata *udata); | |
2416 | int (*dealloc_mw)(struct ib_mw *mw); | |
2417 | struct ib_fmr *(*alloc_fmr)(struct ib_pd *pd, int mr_access_flags, | |
2418 | struct ib_fmr_attr *fmr_attr); | |
2419 | int (*map_phys_fmr)(struct ib_fmr *fmr, u64 *page_list, int list_len, | |
2420 | u64 iova); | |
2421 | int (*unmap_fmr)(struct list_head *fmr_list); | |
2422 | int (*dealloc_fmr)(struct ib_fmr *fmr); | |
2423 | int (*attach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid); | |
2424 | int (*detach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid); | |
2425 | struct ib_xrcd *(*alloc_xrcd)(struct ib_device *device, | |
521ed0d9 | 2426 | struct ib_udata *udata); |
c4367a26 | 2427 | int (*dealloc_xrcd)(struct ib_xrcd *xrcd, struct ib_udata *udata); |
521ed0d9 KH |
2428 | struct ib_flow *(*create_flow)(struct ib_qp *qp, |
2429 | struct ib_flow_attr *flow_attr, | |
2430 | int domain, struct ib_udata *udata); | |
2431 | int (*destroy_flow)(struct ib_flow *flow_id); | |
2432 | struct ib_flow_action *(*create_flow_action_esp)( | |
2433 | struct ib_device *device, | |
2434 | const struct ib_flow_action_attrs_esp *attr, | |
2435 | struct uverbs_attr_bundle *attrs); | |
2436 | int (*destroy_flow_action)(struct ib_flow_action *action); | |
2437 | int (*modify_flow_action_esp)( | |
2438 | struct ib_flow_action *action, | |
2439 | const struct ib_flow_action_attrs_esp *attr, | |
2440 | struct uverbs_attr_bundle *attrs); | |
2441 | int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port, | |
2442 | int state); | |
2443 | int (*get_vf_config)(struct ib_device *device, int vf, u8 port, | |
2444 | struct ifla_vf_info *ivf); | |
2445 | int (*get_vf_stats)(struct ib_device *device, int vf, u8 port, | |
2446 | struct ifla_vf_stats *stats); | |
2447 | int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid, | |
2448 | int type); | |
2449 | struct ib_wq *(*create_wq)(struct ib_pd *pd, | |
2450 | struct ib_wq_init_attr *init_attr, | |
2451 | struct ib_udata *udata); | |
a49b1dc7 | 2452 | void (*destroy_wq)(struct ib_wq *wq, struct ib_udata *udata); |
521ed0d9 KH |
2453 | int (*modify_wq)(struct ib_wq *wq, struct ib_wq_attr *attr, |
2454 | u32 wq_attr_mask, struct ib_udata *udata); | |
2455 | struct ib_rwq_ind_table *(*create_rwq_ind_table)( | |
2456 | struct ib_device *device, | |
2457 | struct ib_rwq_ind_table_init_attr *init_attr, | |
2458 | struct ib_udata *udata); | |
2459 | int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table); | |
2460 | struct ib_dm *(*alloc_dm)(struct ib_device *device, | |
2461 | struct ib_ucontext *context, | |
2462 | struct ib_dm_alloc_attr *attr, | |
2463 | struct uverbs_attr_bundle *attrs); | |
c4367a26 | 2464 | int (*dealloc_dm)(struct ib_dm *dm, struct uverbs_attr_bundle *attrs); |
521ed0d9 KH |
2465 | struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm, |
2466 | struct ib_dm_mr_attr *attr, | |
2467 | struct uverbs_attr_bundle *attrs); | |
2468 | struct ib_counters *(*create_counters)( | |
2469 | struct ib_device *device, struct uverbs_attr_bundle *attrs); | |
2470 | int (*destroy_counters)(struct ib_counters *counters); | |
2471 | int (*read_counters)(struct ib_counters *counters, | |
2472 | struct ib_counters_read_attr *counters_read_attr, | |
2473 | struct uverbs_attr_bundle *attrs); | |
2cdfcdd8 MG |
2474 | int (*map_mr_sg_pi)(struct ib_mr *mr, struct scatterlist *data_sg, |
2475 | int data_sg_nents, unsigned int *data_sg_offset, | |
2476 | struct scatterlist *meta_sg, int meta_sg_nents, | |
2477 | unsigned int *meta_sg_offset); | |
2478 | ||
521ed0d9 KH |
2479 | /** |
2480 | * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the | |
2481 | * driver initialized data. The struct is kfree()'ed by the sysfs | |
2482 | * core when the device is removed. A lifespan of -1 in the return | |
2483 | * struct tells the core to set a default lifespan. | |
2484 | */ | |
2485 | struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device, | |
2486 | u8 port_num); | |
2487 | /** | |
2488 | * get_hw_stats - Fill in the counter value(s) in the stats struct. | |
2489 | * @index - The index in the value array we wish to have updated, or | |
2490 | * num_counters if we want all stats updated | |
2491 | * Return codes - | |
2492 | * < 0 - Error, no counters updated | |
2493 | * index - Updated the single counter pointed to by index | |
2494 | * num_counters - Updated all counters (will reset the timestamp | |
2495 | * and prevent further calls for lifespan milliseconds) | |
2496 | * Drivers are allowed to update all counters in leiu of just the | |
2497 | * one given in index at their option | |
2498 | */ | |
2499 | int (*get_hw_stats)(struct ib_device *device, | |
2500 | struct rdma_hw_stats *stats, u8 port, int index); | |
ea4baf7f PP |
2501 | /* |
2502 | * This function is called once for each port when a ib device is | |
2503 | * registered. | |
2504 | */ | |
2505 | int (*init_port)(struct ib_device *device, u8 port_num, | |
2506 | struct kobject *port_sysfs); | |
02da3750 LR |
2507 | /** |
2508 | * Allows rdma drivers to add their own restrack attributes. | |
2509 | */ | |
2510 | int (*fill_res_entry)(struct sk_buff *msg, | |
2511 | struct rdma_restrack_entry *entry); | |
21a428a0 | 2512 | |
d0899892 | 2513 | /* Device lifecycle callbacks */ |
ca22354b JG |
2514 | /* |
2515 | * Called after the device becomes registered, before clients are | |
2516 | * attached | |
2517 | */ | |
2518 | int (*enable_driver)(struct ib_device *dev); | |
d0899892 JG |
2519 | /* |
2520 | * This is called as part of ib_dealloc_device(). | |
2521 | */ | |
2522 | void (*dealloc_driver)(struct ib_device *dev); | |
2523 | ||
dd05cb82 KH |
2524 | /* iWarp CM callbacks */ |
2525 | void (*iw_add_ref)(struct ib_qp *qp); | |
2526 | void (*iw_rem_ref)(struct ib_qp *qp); | |
2527 | struct ib_qp *(*iw_get_qp)(struct ib_device *device, int qpn); | |
2528 | int (*iw_connect)(struct iw_cm_id *cm_id, | |
2529 | struct iw_cm_conn_param *conn_param); | |
2530 | int (*iw_accept)(struct iw_cm_id *cm_id, | |
2531 | struct iw_cm_conn_param *conn_param); | |
2532 | int (*iw_reject)(struct iw_cm_id *cm_id, const void *pdata, | |
2533 | u8 pdata_len); | |
2534 | int (*iw_create_listen)(struct iw_cm_id *cm_id, int backlog); | |
2535 | int (*iw_destroy_listen)(struct iw_cm_id *cm_id); | |
99fa331d MZ |
2536 | /** |
2537 | * counter_bind_qp - Bind a QP to a counter. | |
2538 | * @counter - The counter to be bound. If counter->id is zero then | |
2539 | * the driver needs to allocate a new counter and set counter->id | |
2540 | */ | |
2541 | int (*counter_bind_qp)(struct rdma_counter *counter, struct ib_qp *qp); | |
2542 | /** | |
2543 | * counter_unbind_qp - Unbind the qp from the dynamically-allocated | |
2544 | * counter and bind it onto the default one | |
2545 | */ | |
2546 | int (*counter_unbind_qp)(struct ib_qp *qp); | |
2547 | /** | |
2548 | * counter_dealloc -De-allocate the hw counter | |
2549 | */ | |
2550 | int (*counter_dealloc)(struct rdma_counter *counter); | |
c4ffee7c MZ |
2551 | /** |
2552 | * counter_alloc_stats - Allocate a struct rdma_hw_stats and fill in | |
2553 | * the driver initialized data. | |
2554 | */ | |
2555 | struct rdma_hw_stats *(*counter_alloc_stats)( | |
2556 | struct rdma_counter *counter); | |
2557 | /** | |
2558 | * counter_update_stats - Query the stats value of this counter | |
2559 | */ | |
2560 | int (*counter_update_stats)(struct rdma_counter *counter); | |
dd05cb82 | 2561 | |
d3456914 | 2562 | DECLARE_RDMA_OBJ_SIZE(ib_ah); |
e39afe3d | 2563 | DECLARE_RDMA_OBJ_SIZE(ib_cq); |
21a428a0 | 2564 | DECLARE_RDMA_OBJ_SIZE(ib_pd); |
68e326de | 2565 | DECLARE_RDMA_OBJ_SIZE(ib_srq); |
a2a074ef | 2566 | DECLARE_RDMA_OBJ_SIZE(ib_ucontext); |
521ed0d9 KH |
2567 | }; |
2568 | ||
cebe556b PP |
2569 | struct ib_core_device { |
2570 | /* device must be the first element in structure until, | |
2571 | * union of ib_core_device and device exists in ib_device. | |
2572 | */ | |
2573 | struct device dev; | |
4e0f7b90 | 2574 | possible_net_t rdma_net; |
cebe556b PP |
2575 | struct kobject *ports_kobj; |
2576 | struct list_head port_list; | |
2577 | struct ib_device *owner; /* reach back to owner ib_device */ | |
2578 | }; | |
41eda65c | 2579 | |
cebe556b | 2580 | struct rdma_restrack_root; |
1da177e4 | 2581 | struct ib_device { |
0957c29f BVA |
2582 | /* Do not access @dma_device directly from ULP nor from HW drivers. */ |
2583 | struct device *dma_device; | |
3023a1e9 | 2584 | struct ib_device_ops ops; |
1da177e4 | 2585 | char name[IB_DEVICE_NAME_MAX]; |
324e227e | 2586 | struct rcu_head rcu_head; |
1da177e4 LT |
2587 | |
2588 | struct list_head event_handler_list; | |
2589 | spinlock_t event_handler_lock; | |
2590 | ||
921eab11 | 2591 | struct rw_semaphore client_data_rwsem; |
0df91bb6 | 2592 | struct xarray client_data; |
d0899892 | 2593 | struct mutex unregistration_lock; |
1da177e4 LT |
2594 | |
2595 | struct ib_cache cache; | |
7738613e | 2596 | /** |
8ceb1357 | 2597 | * port_data is indexed by port number |
7738613e | 2598 | */ |
8ceb1357 | 2599 | struct ib_port_data *port_data; |
1da177e4 | 2600 | |
f4fd0b22 MT |
2601 | int num_comp_vectors; |
2602 | ||
cebe556b PP |
2603 | union { |
2604 | struct device dev; | |
2605 | struct ib_core_device coredev; | |
2606 | }; | |
2607 | ||
d4122f5a PP |
2608 | /* First group for device attributes, |
2609 | * Second group for driver provided attributes (optional). | |
2610 | * It is NULL terminated array. | |
2611 | */ | |
2612 | const struct attribute_group *groups[3]; | |
adee9f3f | 2613 | |
17a55f79 | 2614 | u64 uverbs_cmd_mask; |
f21519b2 | 2615 | u64 uverbs_ex_cmd_mask; |
274c0891 | 2616 | |
bd99fdea | 2617 | char node_desc[IB_DEVICE_NODE_DESC_MAX]; |
cf311cd4 | 2618 | __be64 node_guid; |
96f15c03 | 2619 | u32 local_dma_lkey; |
4139032b | 2620 | u16 is_switch:1; |
6780c4fa GP |
2621 | /* Indicates kernel verbs support, should not be used in drivers */ |
2622 | u16 kverbs_provider:1; | |
da662979 YF |
2623 | /* CQ adaptive moderation (RDMA DIM) */ |
2624 | u16 use_cq_dim:1; | |
1da177e4 LT |
2625 | u8 node_type; |
2626 | u8 phys_port_cnt; | |
3e153a93 | 2627 | struct ib_device_attr attrs; |
b40f4757 CL |
2628 | struct attribute_group *hw_stats_ag; |
2629 | struct rdma_hw_stats *hw_stats; | |
7738613e | 2630 | |
43579b5f PP |
2631 | #ifdef CONFIG_CGROUP_RDMA |
2632 | struct rdmacg_device cg_device; | |
2633 | #endif | |
2634 | ||
ecc82c53 | 2635 | u32 index; |
41eda65c | 2636 | struct rdma_restrack_root *res; |
ecc82c53 | 2637 | |
0cbf432d | 2638 | const struct uapi_definition *driver_def; |
d79af724 | 2639 | |
01b67117 | 2640 | /* |
d79af724 JG |
2641 | * Positive refcount indicates that the device is currently |
2642 | * registered and cannot be unregistered. | |
01b67117 PP |
2643 | */ |
2644 | refcount_t refcount; | |
2645 | struct completion unreg_completion; | |
d0899892 | 2646 | struct work_struct unregistration_work; |
3856ec4b SW |
2647 | |
2648 | const struct rdma_link_ops *link_ops; | |
4e0f7b90 PP |
2649 | |
2650 | /* Protects compat_devs xarray modifications */ | |
2651 | struct mutex compat_devs_mutex; | |
2652 | /* Maintains compat devices for each net namespace */ | |
2653 | struct xarray compat_devs; | |
dd05cb82 KH |
2654 | |
2655 | /* Used by iWarp CM */ | |
2656 | char iw_ifname[IFNAMSIZ]; | |
2657 | u32 iw_driver_flags; | |
1da177e4 LT |
2658 | }; |
2659 | ||
0e2d00eb | 2660 | struct ib_client_nl_info; |
1da177e4 | 2661 | struct ib_client { |
e59178d8 | 2662 | const char *name; |
1da177e4 | 2663 | void (*add) (struct ib_device *); |
7c1eb45a | 2664 | void (*remove)(struct ib_device *, void *client_data); |
dc1435c0 | 2665 | void (*rename)(struct ib_device *dev, void *client_data); |
0e2d00eb JG |
2666 | int (*get_nl_info)(struct ib_device *ibdev, void *client_data, |
2667 | struct ib_client_nl_info *res); | |
2668 | int (*get_global_nl_info)(struct ib_client_nl_info *res); | |
1da177e4 | 2669 | |
9268f72d YK |
2670 | /* Returns the net_dev belonging to this ib_client and matching the |
2671 | * given parameters. | |
2672 | * @dev: An RDMA device that the net_dev use for communication. | |
2673 | * @port: A physical port number on the RDMA device. | |
2674 | * @pkey: P_Key that the net_dev uses if applicable. | |
2675 | * @gid: A GID that the net_dev uses to communicate. | |
2676 | * @addr: An IP address the net_dev is configured with. | |
2677 | * @client_data: The device's client data set by ib_set_client_data(). | |
2678 | * | |
2679 | * An ib_client that implements a net_dev on top of RDMA devices | |
2680 | * (such as IP over IB) should implement this callback, allowing the | |
2681 | * rdma_cm module to find the right net_dev for a given request. | |
2682 | * | |
2683 | * The caller is responsible for calling dev_put on the returned | |
2684 | * netdev. */ | |
2685 | struct net_device *(*get_net_dev_by_params)( | |
2686 | struct ib_device *dev, | |
2687 | u8 port, | |
2688 | u16 pkey, | |
2689 | const union ib_gid *gid, | |
2690 | const struct sockaddr *addr, | |
2691 | void *client_data); | |
1da177e4 | 2692 | struct list_head list; |
e59178d8 | 2693 | u32 client_id; |
6780c4fa GP |
2694 | |
2695 | /* kverbs are not required by the client */ | |
2696 | u8 no_kverbs_req:1; | |
1da177e4 LT |
2697 | }; |
2698 | ||
a808273a SS |
2699 | /* |
2700 | * IB block DMA iterator | |
2701 | * | |
2702 | * Iterates the DMA-mapped SGL in contiguous memory blocks aligned | |
2703 | * to a HW supported page size. | |
2704 | */ | |
2705 | struct ib_block_iter { | |
2706 | /* internal states */ | |
2707 | struct scatterlist *__sg; /* sg holding the current aligned block */ | |
2708 | dma_addr_t __dma_addr; /* unaligned DMA address of this block */ | |
2709 | unsigned int __sg_nents; /* number of SG entries */ | |
2710 | unsigned int __sg_advance; /* number of bytes to advance in sg in next step */ | |
2711 | unsigned int __pg_bit; /* alignment of current block */ | |
2712 | }; | |
2713 | ||
459cc69f LR |
2714 | struct ib_device *_ib_alloc_device(size_t size); |
2715 | #define ib_alloc_device(drv_struct, member) \ | |
2716 | container_of(_ib_alloc_device(sizeof(struct drv_struct) + \ | |
2717 | BUILD_BUG_ON_ZERO(offsetof( \ | |
2718 | struct drv_struct, member))), \ | |
2719 | struct drv_struct, member) | |
2720 | ||
1da177e4 LT |
2721 | void ib_dealloc_device(struct ib_device *device); |
2722 | ||
9abb0d1b | 2723 | void ib_get_device_fw_str(struct ib_device *device, char *str); |
5fa76c20 | 2724 | |
ea4baf7f | 2725 | int ib_register_device(struct ib_device *device, const char *name); |
1da177e4 | 2726 | void ib_unregister_device(struct ib_device *device); |
d0899892 JG |
2727 | void ib_unregister_driver(enum rdma_driver_id driver_id); |
2728 | void ib_unregister_device_and_put(struct ib_device *device); | |
2729 | void ib_unregister_device_queued(struct ib_device *ib_dev); | |
1da177e4 LT |
2730 | |
2731 | int ib_register_client (struct ib_client *client); | |
2732 | void ib_unregister_client(struct ib_client *client); | |
2733 | ||
a808273a SS |
2734 | void __rdma_block_iter_start(struct ib_block_iter *biter, |
2735 | struct scatterlist *sglist, | |
2736 | unsigned int nents, | |
2737 | unsigned long pgsz); | |
2738 | bool __rdma_block_iter_next(struct ib_block_iter *biter); | |
2739 | ||
2740 | /** | |
2741 | * rdma_block_iter_dma_address - get the aligned dma address of the current | |
2742 | * block held by the block iterator. | |
2743 | * @biter: block iterator holding the memory block | |
2744 | */ | |
2745 | static inline dma_addr_t | |
2746 | rdma_block_iter_dma_address(struct ib_block_iter *biter) | |
2747 | { | |
2748 | return biter->__dma_addr & ~(BIT_ULL(biter->__pg_bit) - 1); | |
2749 | } | |
2750 | ||
2751 | /** | |
2752 | * rdma_for_each_block - iterate over contiguous memory blocks of the sg list | |
2753 | * @sglist: sglist to iterate over | |
2754 | * @biter: block iterator holding the memory block | |
2755 | * @nents: maximum number of sg entries to iterate over | |
2756 | * @pgsz: best HW supported page size to use | |
2757 | * | |
2758 | * Callers may use rdma_block_iter_dma_address() to get each | |
2759 | * blocks aligned DMA address. | |
2760 | */ | |
2761 | #define rdma_for_each_block(sglist, biter, nents, pgsz) \ | |
2762 | for (__rdma_block_iter_start(biter, sglist, nents, \ | |
2763 | pgsz); \ | |
2764 | __rdma_block_iter_next(biter);) | |
2765 | ||
0df91bb6 JG |
2766 | /** |
2767 | * ib_get_client_data - Get IB client context | |
2768 | * @device:Device to get context for | |
2769 | * @client:Client to get context for | |
2770 | * | |
2771 | * ib_get_client_data() returns the client context data set with | |
2772 | * ib_set_client_data(). This can only be called while the client is | |
2773 | * registered to the device, once the ib_client remove() callback returns this | |
2774 | * cannot be called. | |
2775 | */ | |
2776 | static inline void *ib_get_client_data(struct ib_device *device, | |
2777 | struct ib_client *client) | |
2778 | { | |
2779 | return xa_load(&device->client_data, client->client_id); | |
2780 | } | |
1da177e4 LT |
2781 | void ib_set_client_data(struct ib_device *device, struct ib_client *client, |
2782 | void *data); | |
521ed0d9 KH |
2783 | void ib_set_device_ops(struct ib_device *device, |
2784 | const struct ib_device_ops *ops); | |
1da177e4 | 2785 | |
5f9794dc JG |
2786 | #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) |
2787 | int rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma, | |
2788 | unsigned long pfn, unsigned long size, pgprot_t prot); | |
5f9794dc JG |
2789 | #else |
2790 | static inline int rdma_user_mmap_io(struct ib_ucontext *ucontext, | |
2791 | struct vm_area_struct *vma, | |
2792 | unsigned long pfn, unsigned long size, | |
2793 | pgprot_t prot) | |
2794 | { | |
2795 | return -EINVAL; | |
2796 | } | |
5f9794dc JG |
2797 | #endif |
2798 | ||
e2773c06 RD |
2799 | static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len) |
2800 | { | |
2801 | return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0; | |
2802 | } | |
2803 | ||
2804 | static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len) | |
2805 | { | |
43c61165 | 2806 | return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0; |
e2773c06 RD |
2807 | } |
2808 | ||
c66db311 MB |
2809 | static inline bool ib_is_buffer_cleared(const void __user *p, |
2810 | size_t len) | |
301a721e | 2811 | { |
92d27ae6 | 2812 | bool ret; |
301a721e MB |
2813 | u8 *buf; |
2814 | ||
2815 | if (len > USHRT_MAX) | |
2816 | return false; | |
2817 | ||
92d27ae6 ME |
2818 | buf = memdup_user(p, len); |
2819 | if (IS_ERR(buf)) | |
301a721e MB |
2820 | return false; |
2821 | ||
301a721e | 2822 | ret = !memchr_inv(buf, 0, len); |
301a721e MB |
2823 | kfree(buf); |
2824 | return ret; | |
2825 | } | |
2826 | ||
c66db311 MB |
2827 | static inline bool ib_is_udata_cleared(struct ib_udata *udata, |
2828 | size_t offset, | |
2829 | size_t len) | |
2830 | { | |
2831 | return ib_is_buffer_cleared(udata->inbuf + offset, len); | |
2832 | } | |
2833 | ||
1c77483e YH |
2834 | /** |
2835 | * ib_is_destroy_retryable - Check whether the uobject destruction | |
2836 | * is retryable. | |
2837 | * @ret: The initial destruction return code | |
2838 | * @why: remove reason | |
2839 | * @uobj: The uobject that is destroyed | |
2840 | * | |
2841 | * This function is a helper function that IB layer and low-level drivers | |
2842 | * can use to consider whether the destruction of the given uobject is | |
2843 | * retry-able. | |
2844 | * It checks the original return code, if it wasn't success the destruction | |
2845 | * is retryable according to the ucontext state (i.e. cleanup_retryable) and | |
2846 | * the remove reason. (i.e. why). | |
2847 | * Must be called with the object locked for destroy. | |
2848 | */ | |
2849 | static inline bool ib_is_destroy_retryable(int ret, enum rdma_remove_reason why, | |
2850 | struct ib_uobject *uobj) | |
2851 | { | |
2852 | return ret && (why == RDMA_REMOVE_DESTROY || | |
2853 | uobj->context->cleanup_retryable); | |
2854 | } | |
2855 | ||
2856 | /** | |
2857 | * ib_destroy_usecnt - Called during destruction to check the usecnt | |
2858 | * @usecnt: The usecnt atomic | |
2859 | * @why: remove reason | |
2860 | * @uobj: The uobject that is destroyed | |
2861 | * | |
2862 | * Non-zero usecnts will block destruction unless destruction was triggered by | |
2863 | * a ucontext cleanup. | |
2864 | */ | |
2865 | static inline int ib_destroy_usecnt(atomic_t *usecnt, | |
2866 | enum rdma_remove_reason why, | |
2867 | struct ib_uobject *uobj) | |
2868 | { | |
2869 | if (atomic_read(usecnt) && ib_is_destroy_retryable(-EBUSY, why, uobj)) | |
2870 | return -EBUSY; | |
2871 | return 0; | |
2872 | } | |
2873 | ||
8a51866f RD |
2874 | /** |
2875 | * ib_modify_qp_is_ok - Check that the supplied attribute mask | |
2876 | * contains all required attributes and no attributes not allowed for | |
2877 | * the given QP state transition. | |
2878 | * @cur_state: Current QP state | |
2879 | * @next_state: Next QP state | |
2880 | * @type: QP type | |
2881 | * @mask: Mask of supplied QP attributes | |
2882 | * | |
2883 | * This function is a helper function that a low-level driver's | |
2884 | * modify_qp method can use to validate the consumer's input. It | |
2885 | * checks that cur_state and next_state are valid QP states, that a | |
2886 | * transition from cur_state to next_state is allowed by the IB spec, | |
2887 | * and that the attribute mask supplied is allowed for the transition. | |
2888 | */ | |
19b1f540 | 2889 | bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state, |
d31131bb | 2890 | enum ib_qp_type type, enum ib_qp_attr_mask mask); |
8a51866f | 2891 | |
dcc9881e LR |
2892 | void ib_register_event_handler(struct ib_event_handler *event_handler); |
2893 | void ib_unregister_event_handler(struct ib_event_handler *event_handler); | |
1da177e4 LT |
2894 | void ib_dispatch_event(struct ib_event *event); |
2895 | ||
1da177e4 LT |
2896 | int ib_query_port(struct ib_device *device, |
2897 | u8 port_num, struct ib_port_attr *port_attr); | |
2898 | ||
a3f5adaf EC |
2899 | enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, |
2900 | u8 port_num); | |
2901 | ||
4139032b HR |
2902 | /** |
2903 | * rdma_cap_ib_switch - Check if the device is IB switch | |
2904 | * @device: Device to check | |
2905 | * | |
2906 | * Device driver is responsible for setting is_switch bit on | |
2907 | * in ib_device structure at init time. | |
2908 | * | |
2909 | * Return: true if the device is IB switch. | |
2910 | */ | |
2911 | static inline bool rdma_cap_ib_switch(const struct ib_device *device) | |
2912 | { | |
2913 | return device->is_switch; | |
2914 | } | |
2915 | ||
0cf18d77 IW |
2916 | /** |
2917 | * rdma_start_port - Return the first valid port number for the device | |
2918 | * specified | |
2919 | * | |
2920 | * @device: Device to be checked | |
2921 | * | |
2922 | * Return start port number | |
2923 | */ | |
2924 | static inline u8 rdma_start_port(const struct ib_device *device) | |
2925 | { | |
4139032b | 2926 | return rdma_cap_ib_switch(device) ? 0 : 1; |
0cf18d77 IW |
2927 | } |
2928 | ||
ea1075ed JG |
2929 | /** |
2930 | * rdma_for_each_port - Iterate over all valid port numbers of the IB device | |
2931 | * @device - The struct ib_device * to iterate over | |
2932 | * @iter - The unsigned int to store the port number | |
2933 | */ | |
2934 | #define rdma_for_each_port(device, iter) \ | |
2935 | for (iter = rdma_start_port(device + BUILD_BUG_ON_ZERO(!__same_type( \ | |
2936 | unsigned int, iter))); \ | |
2937 | iter <= rdma_end_port(device); (iter)++) | |
2938 | ||
0cf18d77 IW |
2939 | /** |
2940 | * rdma_end_port - Return the last valid port number for the device | |
2941 | * specified | |
2942 | * | |
2943 | * @device: Device to be checked | |
2944 | * | |
2945 | * Return last port number | |
2946 | */ | |
2947 | static inline u8 rdma_end_port(const struct ib_device *device) | |
2948 | { | |
4139032b | 2949 | return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt; |
0cf18d77 IW |
2950 | } |
2951 | ||
24dc831b YS |
2952 | static inline int rdma_is_port_valid(const struct ib_device *device, |
2953 | unsigned int port) | |
2954 | { | |
2955 | return (port >= rdma_start_port(device) && | |
2956 | port <= rdma_end_port(device)); | |
2957 | } | |
2958 | ||
b02289b3 AK |
2959 | static inline bool rdma_is_grh_required(const struct ib_device *device, |
2960 | u8 port_num) | |
2961 | { | |
8ceb1357 JG |
2962 | return device->port_data[port_num].immutable.core_cap_flags & |
2963 | RDMA_CORE_PORT_IB_GRH_REQUIRED; | |
b02289b3 AK |
2964 | } |
2965 | ||
5ede9289 | 2966 | static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num) |
de66be94 | 2967 | { |
8ceb1357 JG |
2968 | return device->port_data[port_num].immutable.core_cap_flags & |
2969 | RDMA_CORE_CAP_PROT_IB; | |
de66be94 MW |
2970 | } |
2971 | ||
5ede9289 | 2972 | static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num) |
7766a99f | 2973 | { |
8ceb1357 JG |
2974 | return device->port_data[port_num].immutable.core_cap_flags & |
2975 | (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP); | |
7766a99f MB |
2976 | } |
2977 | ||
2978 | static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num) | |
2979 | { | |
8ceb1357 JG |
2980 | return device->port_data[port_num].immutable.core_cap_flags & |
2981 | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP; | |
7766a99f MB |
2982 | } |
2983 | ||
2984 | static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num) | |
de66be94 | 2985 | { |
8ceb1357 JG |
2986 | return device->port_data[port_num].immutable.core_cap_flags & |
2987 | RDMA_CORE_CAP_PROT_ROCE; | |
de66be94 MW |
2988 | } |
2989 | ||
5ede9289 | 2990 | static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num) |
de66be94 | 2991 | { |
8ceb1357 JG |
2992 | return device->port_data[port_num].immutable.core_cap_flags & |
2993 | RDMA_CORE_CAP_PROT_IWARP; | |
de66be94 MW |
2994 | } |
2995 | ||
5ede9289 | 2996 | static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num) |
de66be94 | 2997 | { |
7766a99f MB |
2998 | return rdma_protocol_ib(device, port_num) || |
2999 | rdma_protocol_roce(device, port_num); | |
de66be94 MW |
3000 | } |
3001 | ||
aa773bd4 OG |
3002 | static inline bool rdma_protocol_raw_packet(const struct ib_device *device, u8 port_num) |
3003 | { | |
8ceb1357 JG |
3004 | return device->port_data[port_num].immutable.core_cap_flags & |
3005 | RDMA_CORE_CAP_PROT_RAW_PACKET; | |
aa773bd4 OG |
3006 | } |
3007 | ||
ce1e055f OG |
3008 | static inline bool rdma_protocol_usnic(const struct ib_device *device, u8 port_num) |
3009 | { | |
8ceb1357 JG |
3010 | return device->port_data[port_num].immutable.core_cap_flags & |
3011 | RDMA_CORE_CAP_PROT_USNIC; | |
ce1e055f OG |
3012 | } |
3013 | ||
c757dea8 | 3014 | /** |
296ec009 | 3015 | * rdma_cap_ib_mad - Check if the port of a device supports Infiniband |
c757dea8 | 3016 | * Management Datagrams. |
296ec009 MW |
3017 | * @device: Device to check |
3018 | * @port_num: Port number to check | |
c757dea8 | 3019 | * |
296ec009 MW |
3020 | * Management Datagrams (MAD) are a required part of the InfiniBand |
3021 | * specification and are supported on all InfiniBand devices. A slightly | |
3022 | * extended version are also supported on OPA interfaces. | |
c757dea8 | 3023 | * |
296ec009 | 3024 | * Return: true if the port supports sending/receiving of MAD packets. |
c757dea8 | 3025 | */ |
5ede9289 | 3026 | static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num) |
c757dea8 | 3027 | { |
8ceb1357 JG |
3028 | return device->port_data[port_num].immutable.core_cap_flags & |
3029 | RDMA_CORE_CAP_IB_MAD; | |
c757dea8 MW |
3030 | } |
3031 | ||
65995fee IW |
3032 | /** |
3033 | * rdma_cap_opa_mad - Check if the port of device provides support for OPA | |
3034 | * Management Datagrams. | |
3035 | * @device: Device to check | |
3036 | * @port_num: Port number to check | |
3037 | * | |
3038 | * Intel OmniPath devices extend and/or replace the InfiniBand Management | |
3039 | * datagrams with their own versions. These OPA MADs share many but not all of | |
3040 | * the characteristics of InfiniBand MADs. | |
3041 | * | |
3042 | * OPA MADs differ in the following ways: | |
3043 | * | |
3044 | * 1) MADs are variable size up to 2K | |
3045 | * IBTA defined MADs remain fixed at 256 bytes | |
3046 | * 2) OPA SMPs must carry valid PKeys | |
3047 | * 3) OPA SMP packets are a different format | |
3048 | * | |
3049 | * Return: true if the port supports OPA MAD packet formats. | |
3050 | */ | |
3051 | static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num) | |
3052 | { | |
d3243da8 LR |
3053 | return device->port_data[port_num].immutable.core_cap_flags & |
3054 | RDMA_CORE_CAP_OPA_MAD; | |
65995fee IW |
3055 | } |
3056 | ||
29541e3a | 3057 | /** |
296ec009 MW |
3058 | * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband |
3059 | * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI). | |
3060 | * @device: Device to check | |
3061 | * @port_num: Port number to check | |
29541e3a | 3062 | * |
296ec009 MW |
3063 | * Each InfiniBand node is required to provide a Subnet Management Agent |
3064 | * that the subnet manager can access. Prior to the fabric being fully | |
3065 | * configured by the subnet manager, the SMA is accessed via a well known | |
3066 | * interface called the Subnet Management Interface (SMI). This interface | |
3067 | * uses directed route packets to communicate with the SM to get around the | |
3068 | * chicken and egg problem of the SM needing to know what's on the fabric | |
3069 | * in order to configure the fabric, and needing to configure the fabric in | |
3070 | * order to send packets to the devices on the fabric. These directed | |
3071 | * route packets do not need the fabric fully configured in order to reach | |
3072 | * their destination. The SMI is the only method allowed to send | |
3073 | * directed route packets on an InfiniBand fabric. | |
29541e3a | 3074 | * |
296ec009 | 3075 | * Return: true if the port provides an SMI. |
29541e3a | 3076 | */ |
5ede9289 | 3077 | static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num) |
29541e3a | 3078 | { |
8ceb1357 JG |
3079 | return device->port_data[port_num].immutable.core_cap_flags & |
3080 | RDMA_CORE_CAP_IB_SMI; | |
29541e3a MW |
3081 | } |
3082 | ||
72219cea MW |
3083 | /** |
3084 | * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband | |
3085 | * Communication Manager. | |
296ec009 MW |
3086 | * @device: Device to check |
3087 | * @port_num: Port number to check | |
72219cea | 3088 | * |
296ec009 MW |
3089 | * The InfiniBand Communication Manager is one of many pre-defined General |
3090 | * Service Agents (GSA) that are accessed via the General Service | |
3091 | * Interface (GSI). It's role is to facilitate establishment of connections | |
3092 | * between nodes as well as other management related tasks for established | |
3093 | * connections. | |
72219cea | 3094 | * |
296ec009 MW |
3095 | * Return: true if the port supports an IB CM (this does not guarantee that |
3096 | * a CM is actually running however). | |
72219cea | 3097 | */ |
5ede9289 | 3098 | static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num) |
72219cea | 3099 | { |
8ceb1357 JG |
3100 | return device->port_data[port_num].immutable.core_cap_flags & |
3101 | RDMA_CORE_CAP_IB_CM; | |
72219cea MW |
3102 | } |
3103 | ||
04215330 MW |
3104 | /** |
3105 | * rdma_cap_iw_cm - Check if the port of device has the capability IWARP | |
3106 | * Communication Manager. | |
296ec009 MW |
3107 | * @device: Device to check |
3108 | * @port_num: Port number to check | |
04215330 | 3109 | * |
296ec009 MW |
3110 | * Similar to above, but specific to iWARP connections which have a different |
3111 | * managment protocol than InfiniBand. | |
04215330 | 3112 | * |
296ec009 MW |
3113 | * Return: true if the port supports an iWARP CM (this does not guarantee that |
3114 | * a CM is actually running however). | |
04215330 | 3115 | */ |
5ede9289 | 3116 | static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num) |
04215330 | 3117 | { |
8ceb1357 JG |
3118 | return device->port_data[port_num].immutable.core_cap_flags & |
3119 | RDMA_CORE_CAP_IW_CM; | |
04215330 MW |
3120 | } |
3121 | ||
fe53ba2f MW |
3122 | /** |
3123 | * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband | |
3124 | * Subnet Administration. | |
296ec009 MW |
3125 | * @device: Device to check |
3126 | * @port_num: Port number to check | |
fe53ba2f | 3127 | * |
296ec009 MW |
3128 | * An InfiniBand Subnet Administration (SA) service is a pre-defined General |
3129 | * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand | |
3130 | * fabrics, devices should resolve routes to other hosts by contacting the | |
3131 | * SA to query the proper route. | |
fe53ba2f | 3132 | * |
296ec009 MW |
3133 | * Return: true if the port should act as a client to the fabric Subnet |
3134 | * Administration interface. This does not imply that the SA service is | |
3135 | * running locally. | |
fe53ba2f | 3136 | */ |
5ede9289 | 3137 | static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num) |
fe53ba2f | 3138 | { |
8ceb1357 JG |
3139 | return device->port_data[port_num].immutable.core_cap_flags & |
3140 | RDMA_CORE_CAP_IB_SA; | |
fe53ba2f MW |
3141 | } |
3142 | ||
a31ad3b0 MW |
3143 | /** |
3144 | * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband | |
3145 | * Multicast. | |
296ec009 MW |
3146 | * @device: Device to check |
3147 | * @port_num: Port number to check | |
a31ad3b0 | 3148 | * |
296ec009 MW |
3149 | * InfiniBand multicast registration is more complex than normal IPv4 or |
3150 | * IPv6 multicast registration. Each Host Channel Adapter must register | |
3151 | * with the Subnet Manager when it wishes to join a multicast group. It | |
3152 | * should do so only once regardless of how many queue pairs it subscribes | |
3153 | * to this group. And it should leave the group only after all queue pairs | |
3154 | * attached to the group have been detached. | |
a31ad3b0 | 3155 | * |
296ec009 MW |
3156 | * Return: true if the port must undertake the additional adminstrative |
3157 | * overhead of registering/unregistering with the SM and tracking of the | |
3158 | * total number of queue pairs attached to the multicast group. | |
a31ad3b0 | 3159 | */ |
5ede9289 | 3160 | static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num) |
a31ad3b0 MW |
3161 | { |
3162 | return rdma_cap_ib_sa(device, port_num); | |
3163 | } | |
3164 | ||
30a74ef4 MW |
3165 | /** |
3166 | * rdma_cap_af_ib - Check if the port of device has the capability | |
3167 | * Native Infiniband Address. | |
296ec009 MW |
3168 | * @device: Device to check |
3169 | * @port_num: Port number to check | |
30a74ef4 | 3170 | * |
296ec009 MW |
3171 | * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default |
3172 | * GID. RoCE uses a different mechanism, but still generates a GID via | |
3173 | * a prescribed mechanism and port specific data. | |
30a74ef4 | 3174 | * |
296ec009 MW |
3175 | * Return: true if the port uses a GID address to identify devices on the |
3176 | * network. | |
30a74ef4 | 3177 | */ |
5ede9289 | 3178 | static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num) |
30a74ef4 | 3179 | { |
8ceb1357 JG |
3180 | return device->port_data[port_num].immutable.core_cap_flags & |
3181 | RDMA_CORE_CAP_AF_IB; | |
30a74ef4 MW |
3182 | } |
3183 | ||
227128fc MW |
3184 | /** |
3185 | * rdma_cap_eth_ah - Check if the port of device has the capability | |
296ec009 MW |
3186 | * Ethernet Address Handle. |
3187 | * @device: Device to check | |
3188 | * @port_num: Port number to check | |
227128fc | 3189 | * |
296ec009 MW |
3190 | * RoCE is InfiniBand over Ethernet, and it uses a well defined technique |
3191 | * to fabricate GIDs over Ethernet/IP specific addresses native to the | |
3192 | * port. Normally, packet headers are generated by the sending host | |
3193 | * adapter, but when sending connectionless datagrams, we must manually | |
3194 | * inject the proper headers for the fabric we are communicating over. | |
227128fc | 3195 | * |
296ec009 MW |
3196 | * Return: true if we are running as a RoCE port and must force the |
3197 | * addition of a Global Route Header built from our Ethernet Address | |
3198 | * Handle into our header list for connectionless packets. | |
227128fc | 3199 | */ |
5ede9289 | 3200 | static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num) |
227128fc | 3201 | { |
8ceb1357 JG |
3202 | return device->port_data[port_num].immutable.core_cap_flags & |
3203 | RDMA_CORE_CAP_ETH_AH; | |
227128fc MW |
3204 | } |
3205 | ||
94d595c5 DC |
3206 | /** |
3207 | * rdma_cap_opa_ah - Check if the port of device supports | |
3208 | * OPA Address handles | |
3209 | * @device: Device to check | |
3210 | * @port_num: Port number to check | |
3211 | * | |
3212 | * Return: true if we are running on an OPA device which supports | |
3213 | * the extended OPA addressing. | |
3214 | */ | |
3215 | static inline bool rdma_cap_opa_ah(struct ib_device *device, u8 port_num) | |
3216 | { | |
8ceb1357 | 3217 | return (device->port_data[port_num].immutable.core_cap_flags & |
94d595c5 DC |
3218 | RDMA_CORE_CAP_OPA_AH) == RDMA_CORE_CAP_OPA_AH; |
3219 | } | |
3220 | ||
337877a4 IW |
3221 | /** |
3222 | * rdma_max_mad_size - Return the max MAD size required by this RDMA Port. | |
3223 | * | |
3224 | * @device: Device | |
3225 | * @port_num: Port number | |
3226 | * | |
3227 | * This MAD size includes the MAD headers and MAD payload. No other headers | |
3228 | * are included. | |
3229 | * | |
3230 | * Return the max MAD size required by the Port. Will return 0 if the port | |
3231 | * does not support MADs | |
3232 | */ | |
3233 | static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num) | |
3234 | { | |
8ceb1357 | 3235 | return device->port_data[port_num].immutable.max_mad_size; |
337877a4 IW |
3236 | } |
3237 | ||
03db3a2d MB |
3238 | /** |
3239 | * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table | |
3240 | * @device: Device to check | |
3241 | * @port_num: Port number to check | |
3242 | * | |
3243 | * RoCE GID table mechanism manages the various GIDs for a device. | |
3244 | * | |
3245 | * NOTE: if allocating the port's GID table has failed, this call will still | |
3246 | * return true, but any RoCE GID table API will fail. | |
3247 | * | |
3248 | * Return: true if the port uses RoCE GID table mechanism in order to manage | |
3249 | * its GIDs. | |
3250 | */ | |
3251 | static inline bool rdma_cap_roce_gid_table(const struct ib_device *device, | |
3252 | u8 port_num) | |
3253 | { | |
3254 | return rdma_protocol_roce(device, port_num) && | |
3023a1e9 | 3255 | device->ops.add_gid && device->ops.del_gid; |
03db3a2d MB |
3256 | } |
3257 | ||
002516ed CH |
3258 | /* |
3259 | * Check if the device supports READ W/ INVALIDATE. | |
3260 | */ | |
3261 | static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num) | |
3262 | { | |
3263 | /* | |
3264 | * iWarp drivers must support READ W/ INVALIDATE. No other protocol | |
3265 | * has support for it yet. | |
3266 | */ | |
3267 | return rdma_protocol_iwarp(dev, port_num); | |
3268 | } | |
3269 | ||
4a353399 SS |
3270 | /** |
3271 | * rdma_find_pg_bit - Find page bit given address and HW supported page sizes | |
3272 | * | |
3273 | * @addr: address | |
3274 | * @pgsz_bitmap: bitmap of HW supported page sizes | |
3275 | */ | |
3276 | static inline unsigned int rdma_find_pg_bit(unsigned long addr, | |
3277 | unsigned long pgsz_bitmap) | |
3278 | { | |
3279 | unsigned long align; | |
3280 | unsigned long pgsz; | |
3281 | ||
3282 | align = addr & -addr; | |
3283 | ||
3284 | /* Find page bit such that addr is aligned to the highest supported | |
3285 | * HW page size | |
3286 | */ | |
3287 | pgsz = pgsz_bitmap & ~(-align << 1); | |
3288 | if (!pgsz) | |
3289 | return __ffs(pgsz_bitmap); | |
3290 | ||
3291 | return __fls(pgsz); | |
3292 | } | |
3293 | ||
50174a7f EC |
3294 | int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port, |
3295 | int state); | |
3296 | int ib_get_vf_config(struct ib_device *device, int vf, u8 port, | |
3297 | struct ifla_vf_info *info); | |
3298 | int ib_get_vf_stats(struct ib_device *device, int vf, u8 port, | |
3299 | struct ifla_vf_stats *stats); | |
3300 | int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid, | |
3301 | int type); | |
3302 | ||
1da177e4 LT |
3303 | int ib_query_pkey(struct ib_device *device, |
3304 | u8 port_num, u16 index, u16 *pkey); | |
3305 | ||
3306 | int ib_modify_device(struct ib_device *device, | |
3307 | int device_modify_mask, | |
3308 | struct ib_device_modify *device_modify); | |
3309 | ||
3310 | int ib_modify_port(struct ib_device *device, | |
3311 | u8 port_num, int port_modify_mask, | |
3312 | struct ib_port_modify *port_modify); | |
3313 | ||
5eb620c8 | 3314 | int ib_find_gid(struct ib_device *device, union ib_gid *gid, |
b26c4a11 | 3315 | u8 *port_num, u16 *index); |
5eb620c8 YE |
3316 | |
3317 | int ib_find_pkey(struct ib_device *device, | |
3318 | u8 port_num, u16 pkey, u16 *index); | |
3319 | ||
ed082d36 CH |
3320 | enum ib_pd_flags { |
3321 | /* | |
3322 | * Create a memory registration for all memory in the system and place | |
3323 | * the rkey for it into pd->unsafe_global_rkey. This can be used by | |
3324 | * ULPs to avoid the overhead of dynamic MRs. | |
3325 | * | |
3326 | * This flag is generally considered unsafe and must only be used in | |
3327 | * extremly trusted environments. Every use of it will log a warning | |
3328 | * in the kernel log. | |
3329 | */ | |
3330 | IB_PD_UNSAFE_GLOBAL_RKEY = 0x01, | |
3331 | }; | |
1da177e4 | 3332 | |
ed082d36 CH |
3333 | struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags, |
3334 | const char *caller); | |
c4367a26 | 3335 | |
ed082d36 | 3336 | #define ib_alloc_pd(device, flags) \ |
e4496447 | 3337 | __ib_alloc_pd((device), (flags), KBUILD_MODNAME) |
c4367a26 SR |
3338 | |
3339 | /** | |
3340 | * ib_dealloc_pd_user - Deallocate kernel/user PD | |
3341 | * @pd: The protection domain | |
3342 | * @udata: Valid user data or NULL for kernel objects | |
3343 | */ | |
3344 | void ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata); | |
3345 | ||
3346 | /** | |
3347 | * ib_dealloc_pd - Deallocate kernel PD | |
3348 | * @pd: The protection domain | |
3349 | * | |
3350 | * NOTE: for user PD use ib_dealloc_pd_user with valid udata! | |
3351 | */ | |
3352 | static inline void ib_dealloc_pd(struct ib_pd *pd) | |
3353 | { | |
3354 | ib_dealloc_pd_user(pd, NULL); | |
3355 | } | |
1da177e4 | 3356 | |
b090c4e3 GP |
3357 | enum rdma_create_ah_flags { |
3358 | /* In a sleepable context */ | |
3359 | RDMA_CREATE_AH_SLEEPABLE = BIT(0), | |
3360 | }; | |
3361 | ||
1da177e4 | 3362 | /** |
0a18cfe4 | 3363 | * rdma_create_ah - Creates an address handle for the given address vector. |
1da177e4 LT |
3364 | * @pd: The protection domain associated with the address handle. |
3365 | * @ah_attr: The attributes of the address vector. | |
b090c4e3 | 3366 | * @flags: Create address handle flags (see enum rdma_create_ah_flags). |
1da177e4 LT |
3367 | * |
3368 | * The address handle is used to reference a local or global destination | |
3369 | * in all UD QP post sends. | |
3370 | */ | |
b090c4e3 GP |
3371 | struct ib_ah *rdma_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr, |
3372 | u32 flags); | |
1da177e4 | 3373 | |
5cda6587 PP |
3374 | /** |
3375 | * rdma_create_user_ah - Creates an address handle for the given address vector. | |
3376 | * It resolves destination mac address for ah attribute of RoCE type. | |
3377 | * @pd: The protection domain associated with the address handle. | |
3378 | * @ah_attr: The attributes of the address vector. | |
3379 | * @udata: pointer to user's input output buffer information need by | |
3380 | * provider driver. | |
3381 | * | |
3382 | * It returns 0 on success and returns appropriate error code on error. | |
3383 | * The address handle is used to reference a local or global destination | |
3384 | * in all UD QP post sends. | |
3385 | */ | |
3386 | struct ib_ah *rdma_create_user_ah(struct ib_pd *pd, | |
3387 | struct rdma_ah_attr *ah_attr, | |
3388 | struct ib_udata *udata); | |
850d8fd7 MS |
3389 | /** |
3390 | * ib_get_gids_from_rdma_hdr - Get sgid and dgid from GRH or IPv4 header | |
3391 | * work completion. | |
3392 | * @hdr: the L3 header to parse | |
3393 | * @net_type: type of header to parse | |
3394 | * @sgid: place to store source gid | |
3395 | * @dgid: place to store destination gid | |
3396 | */ | |
3397 | int ib_get_gids_from_rdma_hdr(const union rdma_network_hdr *hdr, | |
3398 | enum rdma_network_type net_type, | |
3399 | union ib_gid *sgid, union ib_gid *dgid); | |
3400 | ||
3401 | /** | |
3402 | * ib_get_rdma_header_version - Get the header version | |
3403 | * @hdr: the L3 header to parse | |
3404 | */ | |
3405 | int ib_get_rdma_header_version(const union rdma_network_hdr *hdr); | |
3406 | ||
4e00d694 | 3407 | /** |
f6bdb142 | 3408 | * ib_init_ah_attr_from_wc - Initializes address handle attributes from a |
4e00d694 SH |
3409 | * work completion. |
3410 | * @device: Device on which the received message arrived. | |
3411 | * @port_num: Port on which the received message arrived. | |
3412 | * @wc: Work completion associated with the received message. | |
3413 | * @grh: References the received global route header. This parameter is | |
3414 | * ignored unless the work completion indicates that the GRH is valid. | |
3415 | * @ah_attr: Returned attributes that can be used when creating an address | |
3416 | * handle for replying to the message. | |
b7403217 PP |
3417 | * When ib_init_ah_attr_from_wc() returns success, |
3418 | * (a) for IB link layer it optionally contains a reference to SGID attribute | |
3419 | * when GRH is present for IB link layer. | |
3420 | * (b) for RoCE link layer it contains a reference to SGID attribute. | |
3421 | * User must invoke rdma_cleanup_ah_attr_gid_attr() to release reference to SGID | |
3422 | * attributes which are initialized using ib_init_ah_attr_from_wc(). | |
3423 | * | |
4e00d694 | 3424 | */ |
f6bdb142 PP |
3425 | int ib_init_ah_attr_from_wc(struct ib_device *device, u8 port_num, |
3426 | const struct ib_wc *wc, const struct ib_grh *grh, | |
3427 | struct rdma_ah_attr *ah_attr); | |
4e00d694 | 3428 | |
513789ed HR |
3429 | /** |
3430 | * ib_create_ah_from_wc - Creates an address handle associated with the | |
3431 | * sender of the specified work completion. | |
3432 | * @pd: The protection domain associated with the address handle. | |
3433 | * @wc: Work completion information associated with a received message. | |
3434 | * @grh: References the received global route header. This parameter is | |
3435 | * ignored unless the work completion indicates that the GRH is valid. | |
3436 | * @port_num: The outbound port number to associate with the address. | |
3437 | * | |
3438 | * The address handle is used to reference a local or global destination | |
3439 | * in all UD QP post sends. | |
3440 | */ | |
73cdaaee IW |
3441 | struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc, |
3442 | const struct ib_grh *grh, u8 port_num); | |
513789ed | 3443 | |
1da177e4 | 3444 | /** |
67b985b6 | 3445 | * rdma_modify_ah - Modifies the address vector associated with an address |
1da177e4 LT |
3446 | * handle. |
3447 | * @ah: The address handle to modify. | |
3448 | * @ah_attr: The new address vector attributes to associate with the | |
3449 | * address handle. | |
3450 | */ | |
67b985b6 | 3451 | int rdma_modify_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr); |
1da177e4 LT |
3452 | |
3453 | /** | |
bfbfd661 | 3454 | * rdma_query_ah - Queries the address vector associated with an address |
1da177e4 LT |
3455 | * handle. |
3456 | * @ah: The address handle to query. | |
3457 | * @ah_attr: The address vector attributes associated with the address | |
3458 | * handle. | |
3459 | */ | |
bfbfd661 | 3460 | int rdma_query_ah(struct ib_ah *ah, struct rdma_ah_attr *ah_attr); |
1da177e4 | 3461 | |
2553ba21 GP |
3462 | enum rdma_destroy_ah_flags { |
3463 | /* In a sleepable context */ | |
3464 | RDMA_DESTROY_AH_SLEEPABLE = BIT(0), | |
3465 | }; | |
3466 | ||
1da177e4 | 3467 | /** |
c4367a26 | 3468 | * rdma_destroy_ah_user - Destroys an address handle. |
1da177e4 | 3469 | * @ah: The address handle to destroy. |
2553ba21 | 3470 | * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags). |
c4367a26 | 3471 | * @udata: Valid user data or NULL for kernel objects |
1da177e4 | 3472 | */ |
c4367a26 SR |
3473 | int rdma_destroy_ah_user(struct ib_ah *ah, u32 flags, struct ib_udata *udata); |
3474 | ||
3475 | /** | |
3476 | * rdma_destroy_ah - Destroys an kernel address handle. | |
3477 | * @ah: The address handle to destroy. | |
3478 | * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags). | |
3479 | * | |
3480 | * NOTE: for user ah use rdma_destroy_ah_user with valid udata! | |
3481 | */ | |
3482 | static inline int rdma_destroy_ah(struct ib_ah *ah, u32 flags) | |
3483 | { | |
3484 | return rdma_destroy_ah_user(ah, flags, NULL); | |
3485 | } | |
1da177e4 | 3486 | |
d41fcc67 RD |
3487 | /** |
3488 | * ib_create_srq - Creates a SRQ associated with the specified protection | |
3489 | * domain. | |
3490 | * @pd: The protection domain associated with the SRQ. | |
abb6e9ba DB |
3491 | * @srq_init_attr: A list of initial attributes required to create the |
3492 | * SRQ. If SRQ creation succeeds, then the attributes are updated to | |
3493 | * the actual capabilities of the created SRQ. | |
d41fcc67 RD |
3494 | * |
3495 | * srq_attr->max_wr and srq_attr->max_sge are read the determine the | |
3496 | * requested size of the SRQ, and set to the actual values allocated | |
3497 | * on return. If ib_create_srq() succeeds, then max_wr and max_sge | |
3498 | * will always be at least as large as the requested values. | |
3499 | */ | |
3500 | struct ib_srq *ib_create_srq(struct ib_pd *pd, | |
3501 | struct ib_srq_init_attr *srq_init_attr); | |
3502 | ||
3503 | /** | |
3504 | * ib_modify_srq - Modifies the attributes for the specified SRQ. | |
3505 | * @srq: The SRQ to modify. | |
3506 | * @srq_attr: On input, specifies the SRQ attributes to modify. On output, | |
3507 | * the current values of selected SRQ attributes are returned. | |
3508 | * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ | |
3509 | * are being modified. | |
3510 | * | |
3511 | * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or | |
3512 | * IB_SRQ_LIMIT to set the SRQ's limit and request notification when | |
3513 | * the number of receives queued drops below the limit. | |
3514 | */ | |
3515 | int ib_modify_srq(struct ib_srq *srq, | |
3516 | struct ib_srq_attr *srq_attr, | |
3517 | enum ib_srq_attr_mask srq_attr_mask); | |
3518 | ||
3519 | /** | |
3520 | * ib_query_srq - Returns the attribute list and current values for the | |
3521 | * specified SRQ. | |
3522 | * @srq: The SRQ to query. | |
3523 | * @srq_attr: The attributes of the specified SRQ. | |
3524 | */ | |
3525 | int ib_query_srq(struct ib_srq *srq, | |
3526 | struct ib_srq_attr *srq_attr); | |
3527 | ||
3528 | /** | |
c4367a26 SR |
3529 | * ib_destroy_srq_user - Destroys the specified SRQ. |
3530 | * @srq: The SRQ to destroy. | |
3531 | * @udata: Valid user data or NULL for kernel objects | |
3532 | */ | |
3533 | int ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata); | |
3534 | ||
3535 | /** | |
3536 | * ib_destroy_srq - Destroys the specified kernel SRQ. | |
d41fcc67 | 3537 | * @srq: The SRQ to destroy. |
c4367a26 SR |
3538 | * |
3539 | * NOTE: for user srq use ib_destroy_srq_user with valid udata! | |
d41fcc67 | 3540 | */ |
c4367a26 SR |
3541 | static inline int ib_destroy_srq(struct ib_srq *srq) |
3542 | { | |
3543 | return ib_destroy_srq_user(srq, NULL); | |
3544 | } | |
d41fcc67 RD |
3545 | |
3546 | /** | |
3547 | * ib_post_srq_recv - Posts a list of work requests to the specified SRQ. | |
3548 | * @srq: The SRQ to post the work request on. | |
3549 | * @recv_wr: A list of work requests to post on the receive queue. | |
3550 | * @bad_recv_wr: On an immediate failure, this parameter will reference | |
3551 | * the work request that failed to be posted on the QP. | |
3552 | */ | |
3553 | static inline int ib_post_srq_recv(struct ib_srq *srq, | |
d34ac5cd BVA |
3554 | const struct ib_recv_wr *recv_wr, |
3555 | const struct ib_recv_wr **bad_recv_wr) | |
d41fcc67 | 3556 | { |
d34ac5cd | 3557 | const struct ib_recv_wr *dummy; |
bb039a87 | 3558 | |
3023a1e9 KH |
3559 | return srq->device->ops.post_srq_recv(srq, recv_wr, |
3560 | bad_recv_wr ? : &dummy); | |
d41fcc67 RD |
3561 | } |
3562 | ||
1da177e4 | 3563 | /** |
c4367a26 | 3564 | * ib_create_qp_user - Creates a QP associated with the specified protection |
1da177e4 LT |
3565 | * domain. |
3566 | * @pd: The protection domain associated with the QP. | |
abb6e9ba DB |
3567 | * @qp_init_attr: A list of initial attributes required to create the |
3568 | * QP. If QP creation succeeds, then the attributes are updated to | |
3569 | * the actual capabilities of the created QP. | |
c4367a26 | 3570 | * @udata: Valid user data or NULL for kernel objects |
1da177e4 | 3571 | */ |
c4367a26 SR |
3572 | struct ib_qp *ib_create_qp_user(struct ib_pd *pd, |
3573 | struct ib_qp_init_attr *qp_init_attr, | |
3574 | struct ib_udata *udata); | |
3575 | ||
3576 | /** | |
3577 | * ib_create_qp - Creates a kernel QP associated with the specified protection | |
3578 | * domain. | |
3579 | * @pd: The protection domain associated with the QP. | |
3580 | * @qp_init_attr: A list of initial attributes required to create the | |
3581 | * QP. If QP creation succeeds, then the attributes are updated to | |
3582 | * the actual capabilities of the created QP. | |
3583 | * @udata: Valid user data or NULL for kernel objects | |
3584 | * | |
3585 | * NOTE: for user qp use ib_create_qp_user with valid udata! | |
3586 | */ | |
3587 | static inline struct ib_qp *ib_create_qp(struct ib_pd *pd, | |
3588 | struct ib_qp_init_attr *qp_init_attr) | |
3589 | { | |
3590 | return ib_create_qp_user(pd, qp_init_attr, NULL); | |
3591 | } | |
1da177e4 | 3592 | |
a512c2fb PP |
3593 | /** |
3594 | * ib_modify_qp_with_udata - Modifies the attributes for the specified QP. | |
3595 | * @qp: The QP to modify. | |
3596 | * @attr: On input, specifies the QP attributes to modify. On output, | |
3597 | * the current values of selected QP attributes are returned. | |
3598 | * @attr_mask: A bit-mask used to specify which attributes of the QP | |
3599 | * are being modified. | |
3600 | * @udata: pointer to user's input output buffer information | |
3601 | * are being modified. | |
3602 | * It returns 0 on success and returns appropriate error code on error. | |
3603 | */ | |
3604 | int ib_modify_qp_with_udata(struct ib_qp *qp, | |
3605 | struct ib_qp_attr *attr, | |
3606 | int attr_mask, | |
3607 | struct ib_udata *udata); | |
3608 | ||
1da177e4 LT |
3609 | /** |
3610 | * ib_modify_qp - Modifies the attributes for the specified QP and then | |
3611 | * transitions the QP to the given state. | |
3612 | * @qp: The QP to modify. | |
3613 | * @qp_attr: On input, specifies the QP attributes to modify. On output, | |
3614 | * the current values of selected QP attributes are returned. | |
3615 | * @qp_attr_mask: A bit-mask used to specify which attributes of the QP | |
3616 | * are being modified. | |
3617 | */ | |
3618 | int ib_modify_qp(struct ib_qp *qp, | |
3619 | struct ib_qp_attr *qp_attr, | |
3620 | int qp_attr_mask); | |
3621 | ||
3622 | /** | |
3623 | * ib_query_qp - Returns the attribute list and current values for the | |
3624 | * specified QP. | |
3625 | * @qp: The QP to query. | |
3626 | * @qp_attr: The attributes of the specified QP. | |
3627 | * @qp_attr_mask: A bit-mask used to select specific attributes to query. | |
3628 | * @qp_init_attr: Additional attributes of the selected QP. | |
3629 | * | |
3630 | * The qp_attr_mask may be used to limit the query to gathering only the | |
3631 | * selected attributes. | |
3632 | */ | |
3633 | int ib_query_qp(struct ib_qp *qp, | |
3634 | struct ib_qp_attr *qp_attr, | |
3635 | int qp_attr_mask, | |
3636 | struct ib_qp_init_attr *qp_init_attr); | |
3637 | ||
3638 | /** | |
3639 | * ib_destroy_qp - Destroys the specified QP. | |
3640 | * @qp: The QP to destroy. | |
c4367a26 | 3641 | * @udata: Valid udata or NULL for kernel objects |
1da177e4 | 3642 | */ |
c4367a26 SR |
3643 | int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata); |
3644 | ||
3645 | /** | |
3646 | * ib_destroy_qp - Destroys the specified kernel QP. | |
3647 | * @qp: The QP to destroy. | |
3648 | * | |
3649 | * NOTE: for user qp use ib_destroy_qp_user with valid udata! | |
3650 | */ | |
3651 | static inline int ib_destroy_qp(struct ib_qp *qp) | |
3652 | { | |
3653 | return ib_destroy_qp_user(qp, NULL); | |
3654 | } | |
1da177e4 | 3655 | |
d3d72d90 | 3656 | /** |
0e0ec7e0 SH |
3657 | * ib_open_qp - Obtain a reference to an existing sharable QP. |
3658 | * @xrcd - XRC domain | |
3659 | * @qp_open_attr: Attributes identifying the QP to open. | |
3660 | * | |
3661 | * Returns a reference to a sharable QP. | |
3662 | */ | |
3663 | struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd, | |
3664 | struct ib_qp_open_attr *qp_open_attr); | |
3665 | ||
3666 | /** | |
3667 | * ib_close_qp - Release an external reference to a QP. | |
d3d72d90 SH |
3668 | * @qp: The QP handle to release |
3669 | * | |
0e0ec7e0 SH |
3670 | * The opened QP handle is released by the caller. The underlying |
3671 | * shared QP is not destroyed until all internal references are released. | |
d3d72d90 | 3672 | */ |
0e0ec7e0 | 3673 | int ib_close_qp(struct ib_qp *qp); |
d3d72d90 | 3674 | |
1da177e4 LT |
3675 | /** |
3676 | * ib_post_send - Posts a list of work requests to the send queue of | |
3677 | * the specified QP. | |
3678 | * @qp: The QP to post the work request on. | |
3679 | * @send_wr: A list of work requests to post on the send queue. | |
3680 | * @bad_send_wr: On an immediate failure, this parameter will reference | |
3681 | * the work request that failed to be posted on the QP. | |
55464d46 BVA |
3682 | * |
3683 | * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate | |
3684 | * error is returned, the QP state shall not be affected, | |
3685 | * ib_post_send() will return an immediate error after queueing any | |
3686 | * earlier work requests in the list. | |
1da177e4 LT |
3687 | */ |
3688 | static inline int ib_post_send(struct ib_qp *qp, | |
d34ac5cd BVA |
3689 | const struct ib_send_wr *send_wr, |
3690 | const struct ib_send_wr **bad_send_wr) | |
1da177e4 | 3691 | { |
d34ac5cd | 3692 | const struct ib_send_wr *dummy; |
bb039a87 | 3693 | |
3023a1e9 | 3694 | return qp->device->ops.post_send(qp, send_wr, bad_send_wr ? : &dummy); |
1da177e4 LT |
3695 | } |
3696 | ||
3697 | /** | |
3698 | * ib_post_recv - Posts a list of work requests to the receive queue of | |
3699 | * the specified QP. | |
3700 | * @qp: The QP to post the work request on. | |
3701 | * @recv_wr: A list of work requests to post on the receive queue. | |
3702 | * @bad_recv_wr: On an immediate failure, this parameter will reference | |
3703 | * the work request that failed to be posted on the QP. | |
3704 | */ | |
3705 | static inline int ib_post_recv(struct ib_qp *qp, | |
d34ac5cd BVA |
3706 | const struct ib_recv_wr *recv_wr, |
3707 | const struct ib_recv_wr **bad_recv_wr) | |
1da177e4 | 3708 | { |
d34ac5cd | 3709 | const struct ib_recv_wr *dummy; |
bb039a87 | 3710 | |
3023a1e9 | 3711 | return qp->device->ops.post_recv(qp, recv_wr, bad_recv_wr ? : &dummy); |
1da177e4 LT |
3712 | } |
3713 | ||
c4367a26 SR |
3714 | struct ib_cq *__ib_alloc_cq_user(struct ib_device *dev, void *private, |
3715 | int nr_cqe, int comp_vector, | |
3716 | enum ib_poll_context poll_ctx, | |
3717 | const char *caller, struct ib_udata *udata); | |
3718 | ||
3719 | /** | |
3720 | * ib_alloc_cq_user: Allocate kernel/user CQ | |
3721 | * @dev: The IB device | |
3722 | * @private: Private data attached to the CQE | |
3723 | * @nr_cqe: Number of CQEs in the CQ | |
3724 | * @comp_vector: Completion vector used for the IRQs | |
3725 | * @poll_ctx: Context used for polling the CQ | |
3726 | * @udata: Valid user data or NULL for kernel objects | |
3727 | */ | |
3728 | static inline struct ib_cq *ib_alloc_cq_user(struct ib_device *dev, | |
3729 | void *private, int nr_cqe, | |
3730 | int comp_vector, | |
3731 | enum ib_poll_context poll_ctx, | |
3732 | struct ib_udata *udata) | |
3733 | { | |
3734 | return __ib_alloc_cq_user(dev, private, nr_cqe, comp_vector, poll_ctx, | |
3735 | KBUILD_MODNAME, udata); | |
3736 | } | |
3737 | ||
3738 | /** | |
3739 | * ib_alloc_cq: Allocate kernel CQ | |
3740 | * @dev: The IB device | |
3741 | * @private: Private data attached to the CQE | |
3742 | * @nr_cqe: Number of CQEs in the CQ | |
3743 | * @comp_vector: Completion vector used for the IRQs | |
3744 | * @poll_ctx: Context used for polling the CQ | |
3745 | * | |
3746 | * NOTE: for user cq use ib_alloc_cq_user with valid udata! | |
3747 | */ | |
3748 | static inline struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private, | |
3749 | int nr_cqe, int comp_vector, | |
3750 | enum ib_poll_context poll_ctx) | |
3751 | { | |
3752 | return ib_alloc_cq_user(dev, private, nr_cqe, comp_vector, poll_ctx, | |
3753 | NULL); | |
3754 | } | |
3755 | ||
20cf4e02 CL |
3756 | struct ib_cq *__ib_alloc_cq_any(struct ib_device *dev, void *private, |
3757 | int nr_cqe, enum ib_poll_context poll_ctx, | |
3758 | const char *caller); | |
3759 | ||
3760 | /** | |
3761 | * ib_alloc_cq_any: Allocate kernel CQ | |
3762 | * @dev: The IB device | |
3763 | * @private: Private data attached to the CQE | |
3764 | * @nr_cqe: Number of CQEs in the CQ | |
3765 | * @poll_ctx: Context used for polling the CQ | |
3766 | */ | |
3767 | static inline struct ib_cq *ib_alloc_cq_any(struct ib_device *dev, | |
3768 | void *private, int nr_cqe, | |
3769 | enum ib_poll_context poll_ctx) | |
3770 | { | |
3771 | return __ib_alloc_cq_any(dev, private, nr_cqe, poll_ctx, | |
3772 | KBUILD_MODNAME); | |
3773 | } | |
3774 | ||
c4367a26 SR |
3775 | /** |
3776 | * ib_free_cq_user - Free kernel/user CQ | |
3777 | * @cq: The CQ to free | |
3778 | * @udata: Valid user data or NULL for kernel objects | |
3779 | */ | |
3780 | void ib_free_cq_user(struct ib_cq *cq, struct ib_udata *udata); | |
3781 | ||
3782 | /** | |
3783 | * ib_free_cq - Free kernel CQ | |
3784 | * @cq: The CQ to free | |
3785 | * | |
3786 | * NOTE: for user cq use ib_free_cq_user with valid udata! | |
3787 | */ | |
3788 | static inline void ib_free_cq(struct ib_cq *cq) | |
3789 | { | |
3790 | ib_free_cq_user(cq, NULL); | |
3791 | } | |
f66c8ba4 | 3792 | |
14d3a3b2 CH |
3793 | int ib_process_cq_direct(struct ib_cq *cq, int budget); |
3794 | ||
1da177e4 LT |
3795 | /** |
3796 | * ib_create_cq - Creates a CQ on the specified device. | |
3797 | * @device: The device on which to create the CQ. | |
3798 | * @comp_handler: A user-specified callback that is invoked when a | |
3799 | * completion event occurs on the CQ. | |
3800 | * @event_handler: A user-specified callback that is invoked when an | |
3801 | * asynchronous event not associated with a completion occurs on the CQ. | |
3802 | * @cq_context: Context associated with the CQ returned to the user via | |
3803 | * the associated completion and event handlers. | |
8e37210b | 3804 | * @cq_attr: The attributes the CQ should be created upon. |
1da177e4 LT |
3805 | * |
3806 | * Users can examine the cq structure to determine the actual CQ size. | |
3807 | */ | |
7350cdd0 BP |
3808 | struct ib_cq *__ib_create_cq(struct ib_device *device, |
3809 | ib_comp_handler comp_handler, | |
3810 | void (*event_handler)(struct ib_event *, void *), | |
3811 | void *cq_context, | |
3812 | const struct ib_cq_init_attr *cq_attr, | |
3813 | const char *caller); | |
3814 | #define ib_create_cq(device, cmp_hndlr, evt_hndlr, cq_ctxt, cq_attr) \ | |
3815 | __ib_create_cq((device), (cmp_hndlr), (evt_hndlr), (cq_ctxt), (cq_attr), KBUILD_MODNAME) | |
1da177e4 LT |
3816 | |
3817 | /** | |
3818 | * ib_resize_cq - Modifies the capacity of the CQ. | |
3819 | * @cq: The CQ to resize. | |
3820 | * @cqe: The minimum size of the CQ. | |
3821 | * | |
3822 | * Users can examine the cq structure to determine the actual CQ size. | |
3823 | */ | |
3824 | int ib_resize_cq(struct ib_cq *cq, int cqe); | |
3825 | ||
2dd57162 | 3826 | /** |
4190b4e9 | 3827 | * rdma_set_cq_moderation - Modifies moderation params of the CQ |
2dd57162 EC |
3828 | * @cq: The CQ to modify. |
3829 | * @cq_count: number of CQEs that will trigger an event | |
3830 | * @cq_period: max period of time in usec before triggering an event | |
3831 | * | |
3832 | */ | |
4190b4e9 | 3833 | int rdma_set_cq_moderation(struct ib_cq *cq, u16 cq_count, u16 cq_period); |
2dd57162 | 3834 | |
1da177e4 | 3835 | /** |
c4367a26 | 3836 | * ib_destroy_cq_user - Destroys the specified CQ. |
1da177e4 | 3837 | * @cq: The CQ to destroy. |
c4367a26 | 3838 | * @udata: Valid user data or NULL for kernel objects |
1da177e4 | 3839 | */ |
c4367a26 SR |
3840 | int ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata); |
3841 | ||
3842 | /** | |
3843 | * ib_destroy_cq - Destroys the specified kernel CQ. | |
3844 | * @cq: The CQ to destroy. | |
3845 | * | |
3846 | * NOTE: for user cq use ib_destroy_cq_user with valid udata! | |
3847 | */ | |
890ac8d9 | 3848 | static inline void ib_destroy_cq(struct ib_cq *cq) |
c4367a26 | 3849 | { |
890ac8d9 | 3850 | ib_destroy_cq_user(cq, NULL); |
c4367a26 | 3851 | } |
1da177e4 LT |
3852 | |
3853 | /** | |
3854 | * ib_poll_cq - poll a CQ for completion(s) | |
3855 | * @cq:the CQ being polled | |
3856 | * @num_entries:maximum number of completions to return | |
3857 | * @wc:array of at least @num_entries &struct ib_wc where completions | |
3858 | * will be returned | |
3859 | * | |
3860 | * Poll a CQ for (possibly multiple) completions. If the return value | |
3861 | * is < 0, an error occurred. If the return value is >= 0, it is the | |
3862 | * number of completions returned. If the return value is | |
3863 | * non-negative and < num_entries, then the CQ was emptied. | |
3864 | */ | |
3865 | static inline int ib_poll_cq(struct ib_cq *cq, int num_entries, | |
3866 | struct ib_wc *wc) | |
3867 | { | |
3023a1e9 | 3868 | return cq->device->ops.poll_cq(cq, num_entries, wc); |
1da177e4 LT |
3869 | } |
3870 | ||
1da177e4 LT |
3871 | /** |
3872 | * ib_req_notify_cq - Request completion notification on a CQ. | |
3873 | * @cq: The CQ to generate an event for. | |
ed23a727 RD |
3874 | * @flags: |
3875 | * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP | |
3876 | * to request an event on the next solicited event or next work | |
3877 | * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS | |
3878 | * may also be |ed in to request a hint about missed events, as | |
3879 | * described below. | |
3880 | * | |
3881 | * Return Value: | |
3882 | * < 0 means an error occurred while requesting notification | |
3883 | * == 0 means notification was requested successfully, and if | |
3884 | * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events | |
3885 | * were missed and it is safe to wait for another event. In | |
3886 | * this case is it guaranteed that any work completions added | |
3887 | * to the CQ since the last CQ poll will trigger a completion | |
3888 | * notification event. | |
3889 | * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed | |
3890 | * in. It means that the consumer must poll the CQ again to | |
3891 | * make sure it is empty to avoid missing an event because of a | |
3892 | * race between requesting notification and an entry being | |
3893 | * added to the CQ. This return value means it is possible | |
3894 | * (but not guaranteed) that a work completion has been added | |
3895 | * to the CQ since the last poll without triggering a | |
3896 | * completion notification event. | |
1da177e4 LT |
3897 | */ |
3898 | static inline int ib_req_notify_cq(struct ib_cq *cq, | |
ed23a727 | 3899 | enum ib_cq_notify_flags flags) |
1da177e4 | 3900 | { |
3023a1e9 | 3901 | return cq->device->ops.req_notify_cq(cq, flags); |
1da177e4 LT |
3902 | } |
3903 | ||
3904 | /** | |
3905 | * ib_req_ncomp_notif - Request completion notification when there are | |
3906 | * at least the specified number of unreaped completions on the CQ. | |
3907 | * @cq: The CQ to generate an event for. | |
3908 | * @wc_cnt: The number of unreaped completions that should be on the | |
3909 | * CQ before an event is generated. | |
3910 | */ | |
3911 | static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt) | |
3912 | { | |
3023a1e9 KH |
3913 | return cq->device->ops.req_ncomp_notif ? |
3914 | cq->device->ops.req_ncomp_notif(cq, wc_cnt) : | |
1da177e4 LT |
3915 | -ENOSYS; |
3916 | } | |
3917 | ||
9b513090 RC |
3918 | /** |
3919 | * ib_dma_mapping_error - check a DMA addr for error | |
3920 | * @dev: The device for which the dma_addr was created | |
3921 | * @dma_addr: The DMA address to check | |
3922 | */ | |
3923 | static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr) | |
3924 | { | |
0957c29f | 3925 | return dma_mapping_error(dev->dma_device, dma_addr); |
9b513090 RC |
3926 | } |
3927 | ||
3928 | /** | |
3929 | * ib_dma_map_single - Map a kernel virtual address to DMA address | |
3930 | * @dev: The device for which the dma_addr is to be created | |
3931 | * @cpu_addr: The kernel virtual address | |
3932 | * @size: The size of the region in bytes | |
3933 | * @direction: The direction of the DMA | |
3934 | */ | |
3935 | static inline u64 ib_dma_map_single(struct ib_device *dev, | |
3936 | void *cpu_addr, size_t size, | |
3937 | enum dma_data_direction direction) | |
3938 | { | |
0957c29f | 3939 | return dma_map_single(dev->dma_device, cpu_addr, size, direction); |
9b513090 RC |
3940 | } |
3941 | ||
3942 | /** | |
3943 | * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single() | |
3944 | * @dev: The device for which the DMA address was created | |
3945 | * @addr: The DMA address | |
3946 | * @size: The size of the region in bytes | |
3947 | * @direction: The direction of the DMA | |
3948 | */ | |
3949 | static inline void ib_dma_unmap_single(struct ib_device *dev, | |
3950 | u64 addr, size_t size, | |
3951 | enum dma_data_direction direction) | |
3952 | { | |
0957c29f | 3953 | dma_unmap_single(dev->dma_device, addr, size, direction); |
cb9fbc5c AK |
3954 | } |
3955 | ||
9b513090 RC |
3956 | /** |
3957 | * ib_dma_map_page - Map a physical page to DMA address | |
3958 | * @dev: The device for which the dma_addr is to be created | |
3959 | * @page: The page to be mapped | |
3960 | * @offset: The offset within the page | |
3961 | * @size: The size of the region in bytes | |
3962 | * @direction: The direction of the DMA | |
3963 | */ | |
3964 | static inline u64 ib_dma_map_page(struct ib_device *dev, | |
3965 | struct page *page, | |
3966 | unsigned long offset, | |
3967 | size_t size, | |
3968 | enum dma_data_direction direction) | |
3969 | { | |
0957c29f | 3970 | return dma_map_page(dev->dma_device, page, offset, size, direction); |
9b513090 RC |
3971 | } |
3972 | ||
3973 | /** | |
3974 | * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page() | |
3975 | * @dev: The device for which the DMA address was created | |
3976 | * @addr: The DMA address | |
3977 | * @size: The size of the region in bytes | |
3978 | * @direction: The direction of the DMA | |
3979 | */ | |
3980 | static inline void ib_dma_unmap_page(struct ib_device *dev, | |
3981 | u64 addr, size_t size, | |
3982 | enum dma_data_direction direction) | |
3983 | { | |
0957c29f | 3984 | dma_unmap_page(dev->dma_device, addr, size, direction); |
9b513090 RC |
3985 | } |
3986 | ||
3987 | /** | |
3988 | * ib_dma_map_sg - Map a scatter/gather list to DMA addresses | |
3989 | * @dev: The device for which the DMA addresses are to be created | |
3990 | * @sg: The array of scatter/gather entries | |
3991 | * @nents: The number of scatter/gather entries | |
3992 | * @direction: The direction of the DMA | |
3993 | */ | |
3994 | static inline int ib_dma_map_sg(struct ib_device *dev, | |
3995 | struct scatterlist *sg, int nents, | |
3996 | enum dma_data_direction direction) | |
3997 | { | |
0957c29f | 3998 | return dma_map_sg(dev->dma_device, sg, nents, direction); |
9b513090 RC |
3999 | } |
4000 | ||
4001 | /** | |
4002 | * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses | |
4003 | * @dev: The device for which the DMA addresses were created | |
4004 | * @sg: The array of scatter/gather entries | |
4005 | * @nents: The number of scatter/gather entries | |
4006 | * @direction: The direction of the DMA | |
4007 | */ | |
4008 | static inline void ib_dma_unmap_sg(struct ib_device *dev, | |
4009 | struct scatterlist *sg, int nents, | |
4010 | enum dma_data_direction direction) | |
4011 | { | |
0957c29f | 4012 | dma_unmap_sg(dev->dma_device, sg, nents, direction); |
9b513090 RC |
4013 | } |
4014 | ||
cb9fbc5c AK |
4015 | static inline int ib_dma_map_sg_attrs(struct ib_device *dev, |
4016 | struct scatterlist *sg, int nents, | |
4017 | enum dma_data_direction direction, | |
00085f1e | 4018 | unsigned long dma_attrs) |
cb9fbc5c | 4019 | { |
0957c29f BVA |
4020 | return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, |
4021 | dma_attrs); | |
cb9fbc5c AK |
4022 | } |
4023 | ||
4024 | static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev, | |
4025 | struct scatterlist *sg, int nents, | |
4026 | enum dma_data_direction direction, | |
00085f1e | 4027 | unsigned long dma_attrs) |
cb9fbc5c | 4028 | { |
0957c29f | 4029 | dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, dma_attrs); |
cb9fbc5c | 4030 | } |
9b513090 | 4031 | |
0b5cb330 BVA |
4032 | /** |
4033 | * ib_dma_max_seg_size - Return the size limit of a single DMA transfer | |
4034 | * @dev: The device to query | |
4035 | * | |
4036 | * The returned value represents a size in bytes. | |
4037 | */ | |
4038 | static inline unsigned int ib_dma_max_seg_size(struct ib_device *dev) | |
4039 | { | |
4040 | struct device_dma_parameters *p = dev->dma_device->dma_parms; | |
4041 | ||
4042 | return p ? p->max_segment_size : UINT_MAX; | |
4043 | } | |
4044 | ||
9b513090 RC |
4045 | /** |
4046 | * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU | |
4047 | * @dev: The device for which the DMA address was created | |
4048 | * @addr: The DMA address | |
4049 | * @size: The size of the region in bytes | |
4050 | * @dir: The direction of the DMA | |
4051 | */ | |
4052 | static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev, | |
4053 | u64 addr, | |
4054 | size_t size, | |
4055 | enum dma_data_direction dir) | |
4056 | { | |
0957c29f | 4057 | dma_sync_single_for_cpu(dev->dma_device, addr, size, dir); |
9b513090 RC |
4058 | } |
4059 | ||
4060 | /** | |
4061 | * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device | |
4062 | * @dev: The device for which the DMA address was created | |
4063 | * @addr: The DMA address | |
4064 | * @size: The size of the region in bytes | |
4065 | * @dir: The direction of the DMA | |
4066 | */ | |
4067 | static inline void ib_dma_sync_single_for_device(struct ib_device *dev, | |
4068 | u64 addr, | |
4069 | size_t size, | |
4070 | enum dma_data_direction dir) | |
4071 | { | |
0957c29f | 4072 | dma_sync_single_for_device(dev->dma_device, addr, size, dir); |
9b513090 RC |
4073 | } |
4074 | ||
4075 | /** | |
4076 | * ib_dma_alloc_coherent - Allocate memory and map it for DMA | |
4077 | * @dev: The device for which the DMA address is requested | |
4078 | * @size: The size of the region to allocate in bytes | |
4079 | * @dma_handle: A pointer for returning the DMA address of the region | |
4080 | * @flag: memory allocator flags | |
4081 | */ | |
4082 | static inline void *ib_dma_alloc_coherent(struct ib_device *dev, | |
4083 | size_t size, | |
d43dbacf | 4084 | dma_addr_t *dma_handle, |
9b513090 RC |
4085 | gfp_t flag) |
4086 | { | |
0957c29f | 4087 | return dma_alloc_coherent(dev->dma_device, size, dma_handle, flag); |
9b513090 RC |
4088 | } |
4089 | ||
4090 | /** | |
4091 | * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent() | |
4092 | * @dev: The device for which the DMA addresses were allocated | |
4093 | * @size: The size of the region | |
4094 | * @cpu_addr: the address returned by ib_dma_alloc_coherent() | |
4095 | * @dma_handle: the DMA address returned by ib_dma_alloc_coherent() | |
4096 | */ | |
4097 | static inline void ib_dma_free_coherent(struct ib_device *dev, | |
4098 | size_t size, void *cpu_addr, | |
d43dbacf | 4099 | dma_addr_t dma_handle) |
9b513090 | 4100 | { |
0957c29f | 4101 | dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle); |
9b513090 RC |
4102 | } |
4103 | ||
1da177e4 | 4104 | /** |
c4367a26 SR |
4105 | * ib_dereg_mr_user - Deregisters a memory region and removes it from the |
4106 | * HCA translation table. | |
4107 | * @mr: The memory region to deregister. | |
4108 | * @udata: Valid user data or NULL for kernel object | |
4109 | * | |
4110 | * This function can fail, if the memory region has memory windows bound to it. | |
4111 | */ | |
4112 | int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata); | |
4113 | ||
4114 | /** | |
4115 | * ib_dereg_mr - Deregisters a kernel memory region and removes it from the | |
1da177e4 LT |
4116 | * HCA translation table. |
4117 | * @mr: The memory region to deregister. | |
7083e42e SM |
4118 | * |
4119 | * This function can fail, if the memory region has memory windows bound to it. | |
c4367a26 SR |
4120 | * |
4121 | * NOTE: for user mr use ib_dereg_mr_user with valid udata! | |
1da177e4 | 4122 | */ |
c4367a26 SR |
4123 | static inline int ib_dereg_mr(struct ib_mr *mr) |
4124 | { | |
4125 | return ib_dereg_mr_user(mr, NULL); | |
4126 | } | |
4127 | ||
4128 | struct ib_mr *ib_alloc_mr_user(struct ib_pd *pd, enum ib_mr_type mr_type, | |
4129 | u32 max_num_sg, struct ib_udata *udata); | |
1da177e4 | 4130 | |
c4367a26 SR |
4131 | static inline struct ib_mr *ib_alloc_mr(struct ib_pd *pd, |
4132 | enum ib_mr_type mr_type, u32 max_num_sg) | |
4133 | { | |
4134 | return ib_alloc_mr_user(pd, mr_type, max_num_sg, NULL); | |
4135 | } | |
00f7ec36 | 4136 | |
26bc7eae IR |
4137 | struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd, |
4138 | u32 max_num_data_sg, | |
4139 | u32 max_num_meta_sg); | |
4140 | ||
00f7ec36 SW |
4141 | /** |
4142 | * ib_update_fast_reg_key - updates the key portion of the fast_reg MR | |
4143 | * R_Key and L_Key. | |
4144 | * @mr - struct ib_mr pointer to be updated. | |
4145 | * @newkey - new key to be used. | |
4146 | */ | |
4147 | static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey) | |
4148 | { | |
4149 | mr->lkey = (mr->lkey & 0xffffff00) | newkey; | |
4150 | mr->rkey = (mr->rkey & 0xffffff00) | newkey; | |
4151 | } | |
4152 | ||
7083e42e SM |
4153 | /** |
4154 | * ib_inc_rkey - increments the key portion of the given rkey. Can be used | |
4155 | * for calculating a new rkey for type 2 memory windows. | |
4156 | * @rkey - the rkey to increment. | |
4157 | */ | |
4158 | static inline u32 ib_inc_rkey(u32 rkey) | |
4159 | { | |
4160 | const u32 mask = 0x000000ff; | |
4161 | return ((rkey + 1) & mask) | (rkey & ~mask); | |
4162 | } | |
4163 | ||
1da177e4 LT |
4164 | /** |
4165 | * ib_alloc_fmr - Allocates a unmapped fast memory region. | |
4166 | * @pd: The protection domain associated with the unmapped region. | |
4167 | * @mr_access_flags: Specifies the memory access rights. | |
4168 | * @fmr_attr: Attributes of the unmapped region. | |
4169 | * | |
4170 | * A fast memory region must be mapped before it can be used as part of | |
4171 | * a work request. | |
4172 | */ | |
4173 | struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd, | |
4174 | int mr_access_flags, | |
4175 | struct ib_fmr_attr *fmr_attr); | |
4176 | ||
4177 | /** | |
4178 | * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region. | |
4179 | * @fmr: The fast memory region to associate with the pages. | |
4180 | * @page_list: An array of physical pages to map to the fast memory region. | |
4181 | * @list_len: The number of pages in page_list. | |
4182 | * @iova: The I/O virtual address to use with the mapped region. | |
4183 | */ | |
4184 | static inline int ib_map_phys_fmr(struct ib_fmr *fmr, | |
4185 | u64 *page_list, int list_len, | |
4186 | u64 iova) | |
4187 | { | |
3023a1e9 | 4188 | return fmr->device->ops.map_phys_fmr(fmr, page_list, list_len, iova); |
1da177e4 LT |
4189 | } |
4190 | ||
4191 | /** | |
4192 | * ib_unmap_fmr - Removes the mapping from a list of fast memory regions. | |
4193 | * @fmr_list: A linked list of fast memory regions to unmap. | |
4194 | */ | |
4195 | int ib_unmap_fmr(struct list_head *fmr_list); | |
4196 | ||
4197 | /** | |
4198 | * ib_dealloc_fmr - Deallocates a fast memory region. | |
4199 | * @fmr: The fast memory region to deallocate. | |
4200 | */ | |
4201 | int ib_dealloc_fmr(struct ib_fmr *fmr); | |
4202 | ||
4203 | /** | |
4204 | * ib_attach_mcast - Attaches the specified QP to a multicast group. | |
4205 | * @qp: QP to attach to the multicast group. The QP must be type | |
4206 | * IB_QPT_UD. | |
4207 | * @gid: Multicast group GID. | |
4208 | * @lid: Multicast group LID in host byte order. | |
4209 | * | |
4210 | * In order to send and receive multicast packets, subnet | |
4211 | * administration must have created the multicast group and configured | |
4212 | * the fabric appropriately. The port associated with the specified | |
4213 | * QP must also be a member of the multicast group. | |
4214 | */ | |
4215 | int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); | |
4216 | ||
4217 | /** | |
4218 | * ib_detach_mcast - Detaches the specified QP from a multicast group. | |
4219 | * @qp: QP to detach from the multicast group. | |
4220 | * @gid: Multicast group GID. | |
4221 | * @lid: Multicast group LID in host byte order. | |
4222 | */ | |
4223 | int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid); | |
4224 | ||
59991f94 SH |
4225 | /** |
4226 | * ib_alloc_xrcd - Allocates an XRC domain. | |
4227 | * @device: The device on which to allocate the XRC domain. | |
f66c8ba4 | 4228 | * @caller: Module name for kernel consumers |
59991f94 | 4229 | */ |
f66c8ba4 LR |
4230 | struct ib_xrcd *__ib_alloc_xrcd(struct ib_device *device, const char *caller); |
4231 | #define ib_alloc_xrcd(device) \ | |
4232 | __ib_alloc_xrcd((device), KBUILD_MODNAME) | |
59991f94 SH |
4233 | |
4234 | /** | |
4235 | * ib_dealloc_xrcd - Deallocates an XRC domain. | |
4236 | * @xrcd: The XRC domain to deallocate. | |
c4367a26 | 4237 | * @udata: Valid user data or NULL for kernel object |
59991f94 | 4238 | */ |
c4367a26 | 4239 | int ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata); |
59991f94 | 4240 | |
1c636f80 EC |
4241 | static inline int ib_check_mr_access(int flags) |
4242 | { | |
4243 | /* | |
4244 | * Local write permission is required if remote write or | |
4245 | * remote atomic permission is also requested. | |
4246 | */ | |
4247 | if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) && | |
4248 | !(flags & IB_ACCESS_LOCAL_WRITE)) | |
4249 | return -EINVAL; | |
4250 | ||
4251 | return 0; | |
4252 | } | |
4253 | ||
08bb558a JM |
4254 | static inline bool ib_access_writable(int access_flags) |
4255 | { | |
4256 | /* | |
4257 | * We have writable memory backing the MR if any of the following | |
4258 | * access flags are set. "Local write" and "remote write" obviously | |
4259 | * require write access. "Remote atomic" can do things like fetch and | |
4260 | * add, which will modify memory, and "MW bind" can change permissions | |
4261 | * by binding a window. | |
4262 | */ | |
4263 | return access_flags & | |
4264 | (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE | | |
4265 | IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND); | |
4266 | } | |
4267 | ||
1b01d335 SG |
4268 | /** |
4269 | * ib_check_mr_status: lightweight check of MR status. | |
4270 | * This routine may provide status checks on a selected | |
4271 | * ib_mr. first use is for signature status check. | |
4272 | * | |
4273 | * @mr: A memory region. | |
4274 | * @check_mask: Bitmask of which checks to perform from | |
4275 | * ib_mr_status_check enumeration. | |
4276 | * @mr_status: The container of relevant status checks. | |
4277 | * failed checks will be indicated in the status bitmask | |
4278 | * and the relevant info shall be in the error item. | |
4279 | */ | |
4280 | int ib_check_mr_status(struct ib_mr *mr, u32 check_mask, | |
4281 | struct ib_mr_status *mr_status); | |
4282 | ||
d79af724 JG |
4283 | /** |
4284 | * ib_device_try_get: Hold a registration lock | |
4285 | * device: The device to lock | |
4286 | * | |
4287 | * A device under an active registration lock cannot become unregistered. It | |
4288 | * is only possible to obtain a registration lock on a device that is fully | |
4289 | * registered, otherwise this function returns false. | |
4290 | * | |
4291 | * The registration lock is only necessary for actions which require the | |
4292 | * device to still be registered. Uses that only require the device pointer to | |
4293 | * be valid should use get_device(&ibdev->dev) to hold the memory. | |
4294 | * | |
4295 | */ | |
4296 | static inline bool ib_device_try_get(struct ib_device *dev) | |
4297 | { | |
4298 | return refcount_inc_not_zero(&dev->refcount); | |
4299 | } | |
4300 | ||
4301 | void ib_device_put(struct ib_device *device); | |
324e227e JG |
4302 | struct ib_device *ib_device_get_by_netdev(struct net_device *ndev, |
4303 | enum rdma_driver_id driver_id); | |
4304 | struct ib_device *ib_device_get_by_name(const char *name, | |
4305 | enum rdma_driver_id driver_id); | |
9268f72d YK |
4306 | struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port, |
4307 | u16 pkey, const union ib_gid *gid, | |
4308 | const struct sockaddr *addr); | |
c2261dd7 JG |
4309 | int ib_device_set_netdev(struct ib_device *ib_dev, struct net_device *ndev, |
4310 | unsigned int port); | |
4311 | struct net_device *ib_device_netdev(struct ib_device *dev, u8 port); | |
4312 | ||
5fd251c8 YH |
4313 | struct ib_wq *ib_create_wq(struct ib_pd *pd, |
4314 | struct ib_wq_init_attr *init_attr); | |
c4367a26 | 4315 | int ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata); |
5fd251c8 YH |
4316 | int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr, |
4317 | u32 wq_attr_mask); | |
6d39786b YH |
4318 | struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device, |
4319 | struct ib_rwq_ind_table_init_attr* | |
4320 | wq_ind_table_init_attr); | |
4321 | int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table); | |
9268f72d | 4322 | |
ff2ba993 | 4323 | int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents, |
9aa8b321 | 4324 | unsigned int *sg_offset, unsigned int page_size); |
2cdfcdd8 MG |
4325 | int ib_map_mr_sg_pi(struct ib_mr *mr, struct scatterlist *data_sg, |
4326 | int data_sg_nents, unsigned int *data_sg_offset, | |
4327 | struct scatterlist *meta_sg, int meta_sg_nents, | |
4328 | unsigned int *meta_sg_offset, unsigned int page_size); | |
4c67e2bf SG |
4329 | |
4330 | static inline int | |
ff2ba993 | 4331 | ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents, |
9aa8b321 | 4332 | unsigned int *sg_offset, unsigned int page_size) |
4c67e2bf SG |
4333 | { |
4334 | int n; | |
4335 | ||
ff2ba993 | 4336 | n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size); |
4c67e2bf SG |
4337 | mr->iova = 0; |
4338 | ||
4339 | return n; | |
4340 | } | |
4341 | ||
ff2ba993 | 4342 | int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents, |
9aa8b321 | 4343 | unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64)); |
4c67e2bf | 4344 | |
765d6774 SW |
4345 | void ib_drain_rq(struct ib_qp *qp); |
4346 | void ib_drain_sq(struct ib_qp *qp); | |
4347 | void ib_drain_qp(struct ib_qp *qp); | |
850d8fd7 | 4348 | |
d4186194 | 4349 | int ib_get_eth_speed(struct ib_device *dev, u8 port_num, u8 *speed, u8 *width); |
2224c47a DC |
4350 | |
4351 | static inline u8 *rdma_ah_retrieve_dmac(struct rdma_ah_attr *attr) | |
4352 | { | |
44c58487 DC |
4353 | if (attr->type == RDMA_AH_ATTR_TYPE_ROCE) |
4354 | return attr->roce.dmac; | |
4355 | return NULL; | |
2224c47a DC |
4356 | } |
4357 | ||
64b4646e | 4358 | static inline void rdma_ah_set_dlid(struct rdma_ah_attr *attr, u32 dlid) |
2224c47a | 4359 | { |
44c58487 | 4360 | if (attr->type == RDMA_AH_ATTR_TYPE_IB) |
64b4646e DC |
4361 | attr->ib.dlid = (u16)dlid; |
4362 | else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) | |
4363 | attr->opa.dlid = dlid; | |
2224c47a DC |
4364 | } |
4365 | ||
64b4646e | 4366 | static inline u32 rdma_ah_get_dlid(const struct rdma_ah_attr *attr) |
2224c47a | 4367 | { |
44c58487 DC |
4368 | if (attr->type == RDMA_AH_ATTR_TYPE_IB) |
4369 | return attr->ib.dlid; | |
64b4646e DC |
4370 | else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) |
4371 | return attr->opa.dlid; | |
44c58487 | 4372 | return 0; |
2224c47a DC |
4373 | } |
4374 | ||
4375 | static inline void rdma_ah_set_sl(struct rdma_ah_attr *attr, u8 sl) | |
4376 | { | |
4377 | attr->sl = sl; | |
4378 | } | |
4379 | ||
4380 | static inline u8 rdma_ah_get_sl(const struct rdma_ah_attr *attr) | |
4381 | { | |
4382 | return attr->sl; | |
4383 | } | |
4384 | ||
4385 | static inline void rdma_ah_set_path_bits(struct rdma_ah_attr *attr, | |
4386 | u8 src_path_bits) | |
4387 | { | |
44c58487 DC |
4388 | if (attr->type == RDMA_AH_ATTR_TYPE_IB) |
4389 | attr->ib.src_path_bits = src_path_bits; | |
64b4646e DC |
4390 | else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) |
4391 | attr->opa.src_path_bits = src_path_bits; | |
2224c47a DC |
4392 | } |
4393 | ||
4394 | static inline u8 rdma_ah_get_path_bits(const struct rdma_ah_attr *attr) | |
4395 | { | |
44c58487 DC |
4396 | if (attr->type == RDMA_AH_ATTR_TYPE_IB) |
4397 | return attr->ib.src_path_bits; | |
64b4646e DC |
4398 | else if (attr->type == RDMA_AH_ATTR_TYPE_OPA) |
4399 | return attr->opa.src_path_bits; | |
44c58487 | 4400 | return 0; |
2224c47a DC |
4401 | } |
4402 | ||
d98bb7f7 DH |
4403 | static inline void rdma_ah_set_make_grd(struct rdma_ah_attr *attr, |
4404 | bool make_grd) | |
4405 | { | |
4406 | if (attr->type == RDMA_AH_ATTR_TYPE_OPA) | |
4407 | attr->opa.make_grd = make_grd; | |
4408 | } | |
4409 | ||
4410 | static inline bool rdma_ah_get_make_grd(const struct rdma_ah_attr *attr) | |
4411 | { | |
4412 | if (attr->type == RDMA_AH_ATTR_TYPE_OPA) | |
4413 | return attr->opa.make_grd; | |
4414 | return false; | |
4415 | } | |
4416 | ||
2224c47a DC |
4417 | static inline void rdma_ah_set_port_num(struct rdma_ah_attr *attr, u8 port_num) |
4418 | { | |
4419 | attr->port_num = port_num; | |
4420 | } | |
4421 | ||
4422 | static inline u8 rdma_ah_get_port_num(const struct rdma_ah_attr *attr) | |
4423 | { | |
4424 | return attr->port_num; | |
4425 | } | |
4426 | ||
4427 | static inline void rdma_ah_set_static_rate(struct rdma_ah_attr *attr, | |
4428 | u8 static_rate) | |
4429 | { | |
4430 | attr->static_rate = static_rate; | |
4431 | } | |
4432 | ||
4433 | static inline u8 rdma_ah_get_static_rate(const struct rdma_ah_attr *attr) | |
4434 | { | |
4435 | return attr->static_rate; | |
4436 | } | |
4437 | ||
4438 | static inline void rdma_ah_set_ah_flags(struct rdma_ah_attr *attr, | |
4439 | enum ib_ah_flags flag) | |
4440 | { | |
4441 | attr->ah_flags = flag; | |
4442 | } | |
4443 | ||
4444 | static inline enum ib_ah_flags | |
4445 | rdma_ah_get_ah_flags(const struct rdma_ah_attr *attr) | |
4446 | { | |
4447 | return attr->ah_flags; | |
4448 | } | |
4449 | ||
4450 | static inline const struct ib_global_route | |
4451 | *rdma_ah_read_grh(const struct rdma_ah_attr *attr) | |
4452 | { | |
4453 | return &attr->grh; | |
4454 | } | |
4455 | ||
4456 | /*To retrieve and modify the grh */ | |
4457 | static inline struct ib_global_route | |
4458 | *rdma_ah_retrieve_grh(struct rdma_ah_attr *attr) | |
4459 | { | |
4460 | return &attr->grh; | |
4461 | } | |
4462 | ||
4463 | static inline void rdma_ah_set_dgid_raw(struct rdma_ah_attr *attr, void *dgid) | |
4464 | { | |
4465 | struct ib_global_route *grh = rdma_ah_retrieve_grh(attr); | |
4466 | ||
4467 | memcpy(grh->dgid.raw, dgid, sizeof(grh->dgid)); | |
4468 | } | |
4469 | ||
4470 | static inline void rdma_ah_set_subnet_prefix(struct rdma_ah_attr *attr, | |
4471 | __be64 prefix) | |
4472 | { | |
4473 | struct ib_global_route *grh = rdma_ah_retrieve_grh(attr); | |
4474 | ||
4475 | grh->dgid.global.subnet_prefix = prefix; | |
4476 | } | |
4477 | ||
4478 | static inline void rdma_ah_set_interface_id(struct rdma_ah_attr *attr, | |
4479 | __be64 if_id) | |
4480 | { | |
4481 | struct ib_global_route *grh = rdma_ah_retrieve_grh(attr); | |
4482 | ||
4483 | grh->dgid.global.interface_id = if_id; | |
4484 | } | |
4485 | ||
4486 | static inline void rdma_ah_set_grh(struct rdma_ah_attr *attr, | |
4487 | union ib_gid *dgid, u32 flow_label, | |
4488 | u8 sgid_index, u8 hop_limit, | |
4489 | u8 traffic_class) | |
4490 | { | |
4491 | struct ib_global_route *grh = rdma_ah_retrieve_grh(attr); | |
4492 | ||
4493 | attr->ah_flags = IB_AH_GRH; | |
4494 | if (dgid) | |
4495 | grh->dgid = *dgid; | |
4496 | grh->flow_label = flow_label; | |
4497 | grh->sgid_index = sgid_index; | |
4498 | grh->hop_limit = hop_limit; | |
4499 | grh->traffic_class = traffic_class; | |
8d9ec9ad | 4500 | grh->sgid_attr = NULL; |
2224c47a | 4501 | } |
44c58487 | 4502 | |
8d9ec9ad JG |
4503 | void rdma_destroy_ah_attr(struct rdma_ah_attr *ah_attr); |
4504 | void rdma_move_grh_sgid_attr(struct rdma_ah_attr *attr, union ib_gid *dgid, | |
4505 | u32 flow_label, u8 hop_limit, u8 traffic_class, | |
4506 | const struct ib_gid_attr *sgid_attr); | |
d97099fe JG |
4507 | void rdma_copy_ah_attr(struct rdma_ah_attr *dest, |
4508 | const struct rdma_ah_attr *src); | |
4509 | void rdma_replace_ah_attr(struct rdma_ah_attr *old, | |
4510 | const struct rdma_ah_attr *new); | |
4511 | void rdma_move_ah_attr(struct rdma_ah_attr *dest, struct rdma_ah_attr *src); | |
8d9ec9ad | 4512 | |
87daac68 DH |
4513 | /** |
4514 | * rdma_ah_find_type - Return address handle type. | |
4515 | * | |
4516 | * @dev: Device to be checked | |
4517 | * @port_num: Port number | |
4518 | */ | |
44c58487 | 4519 | static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev, |
87daac68 | 4520 | u8 port_num) |
44c58487 | 4521 | { |
a6532e71 | 4522 | if (rdma_protocol_roce(dev, port_num)) |
44c58487 | 4523 | return RDMA_AH_ATTR_TYPE_ROCE; |
87daac68 DH |
4524 | if (rdma_protocol_ib(dev, port_num)) { |
4525 | if (rdma_cap_opa_ah(dev, port_num)) | |
4526 | return RDMA_AH_ATTR_TYPE_OPA; | |
44c58487 | 4527 | return RDMA_AH_ATTR_TYPE_IB; |
87daac68 DH |
4528 | } |
4529 | ||
4530 | return RDMA_AH_ATTR_TYPE_UNDEFINED; | |
44c58487 | 4531 | } |
7db20ecd | 4532 | |
62ede777 HD |
4533 | /** |
4534 | * ib_lid_cpu16 - Return lid in 16bit CPU encoding. | |
4535 | * In the current implementation the only way to get | |
4536 | * get the 32bit lid is from other sources for OPA. | |
4537 | * For IB, lids will always be 16bits so cast the | |
4538 | * value accordingly. | |
4539 | * | |
4540 | * @lid: A 32bit LID | |
4541 | */ | |
4542 | static inline u16 ib_lid_cpu16(u32 lid) | |
7db20ecd | 4543 | { |
62ede777 HD |
4544 | WARN_ON_ONCE(lid & 0xFFFF0000); |
4545 | return (u16)lid; | |
7db20ecd HD |
4546 | } |
4547 | ||
62ede777 HD |
4548 | /** |
4549 | * ib_lid_be16 - Return lid in 16bit BE encoding. | |
4550 | * | |
4551 | * @lid: A 32bit LID | |
4552 | */ | |
4553 | static inline __be16 ib_lid_be16(u32 lid) | |
7db20ecd | 4554 | { |
62ede777 HD |
4555 | WARN_ON_ONCE(lid & 0xFFFF0000); |
4556 | return cpu_to_be16((u16)lid); | |
7db20ecd | 4557 | } |
32043830 | 4558 | |
c66cd353 SG |
4559 | /** |
4560 | * ib_get_vector_affinity - Get the affinity mappings of a given completion | |
4561 | * vector | |
4562 | * @device: the rdma device | |
4563 | * @comp_vector: index of completion vector | |
4564 | * | |
4565 | * Returns NULL on failure, otherwise a corresponding cpu map of the | |
4566 | * completion vector (returns all-cpus map if the device driver doesn't | |
4567 | * implement get_vector_affinity). | |
4568 | */ | |
4569 | static inline const struct cpumask * | |
4570 | ib_get_vector_affinity(struct ib_device *device, int comp_vector) | |
4571 | { | |
4572 | if (comp_vector < 0 || comp_vector >= device->num_comp_vectors || | |
3023a1e9 | 4573 | !device->ops.get_vector_affinity) |
c66cd353 SG |
4574 | return NULL; |
4575 | ||
3023a1e9 | 4576 | return device->ops.get_vector_affinity(device, comp_vector); |
c66cd353 SG |
4577 | |
4578 | } | |
4579 | ||
32f69e4b DJ |
4580 | /** |
4581 | * rdma_roce_rescan_device - Rescan all of the network devices in the system | |
4582 | * and add their gids, as needed, to the relevant RoCE devices. | |
4583 | * | |
4584 | * @device: the rdma device | |
4585 | */ | |
4586 | void rdma_roce_rescan_device(struct ib_device *ibdev); | |
4587 | ||
8313c10f | 4588 | struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile); |
7dc08dcf | 4589 | |
15a1b4be | 4590 | int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs); |
f6a8a19b DD |
4591 | |
4592 | struct net_device *rdma_alloc_netdev(struct ib_device *device, u8 port_num, | |
4593 | enum rdma_netdev_t type, const char *name, | |
4594 | unsigned char name_assign_type, | |
4595 | void (*setup)(struct net_device *)); | |
5d6b0cb3 DD |
4596 | |
4597 | int rdma_init_netdev(struct ib_device *device, u8 port_num, | |
4598 | enum rdma_netdev_t type, const char *name, | |
4599 | unsigned char name_assign_type, | |
4600 | void (*setup)(struct net_device *), | |
4601 | struct net_device *netdev); | |
4602 | ||
d4122f5a PP |
4603 | /** |
4604 | * rdma_set_device_sysfs_group - Set device attributes group to have | |
4605 | * driver specific sysfs entries at | |
4606 | * for infiniband class. | |
4607 | * | |
4608 | * @device: device pointer for which attributes to be created | |
4609 | * @group: Pointer to group which should be added when device | |
4610 | * is registered with sysfs. | |
4611 | * rdma_set_device_sysfs_group() allows existing drivers to expose one | |
4612 | * group per device to have sysfs attributes. | |
4613 | * | |
4614 | * NOTE: New drivers should not make use of this API; instead new device | |
4615 | * parameter should be exposed via netlink command. This API and mechanism | |
4616 | * exist only for existing drivers. | |
4617 | */ | |
4618 | static inline void | |
4619 | rdma_set_device_sysfs_group(struct ib_device *dev, | |
4620 | const struct attribute_group *group) | |
4621 | { | |
4622 | dev->groups[1] = group; | |
4623 | } | |
4624 | ||
54747231 PP |
4625 | /** |
4626 | * rdma_device_to_ibdev - Get ib_device pointer from device pointer | |
4627 | * | |
4628 | * @device: device pointer for which ib_device pointer to retrieve | |
4629 | * | |
4630 | * rdma_device_to_ibdev() retrieves ib_device pointer from device. | |
4631 | * | |
4632 | */ | |
4633 | static inline struct ib_device *rdma_device_to_ibdev(struct device *device) | |
4634 | { | |
cebe556b PP |
4635 | struct ib_core_device *coredev = |
4636 | container_of(device, struct ib_core_device, dev); | |
4637 | ||
4638 | return coredev->owner; | |
54747231 PP |
4639 | } |
4640 | ||
4641 | /** | |
4642 | * rdma_device_to_drv_device - Helper macro to reach back to driver's | |
4643 | * ib_device holder structure from device pointer. | |
4644 | * | |
4645 | * NOTE: New drivers should not make use of this API; This API is only for | |
4646 | * existing drivers who have exposed sysfs entries using | |
4647 | * rdma_set_device_sysfs_group(). | |
4648 | */ | |
4649 | #define rdma_device_to_drv_device(dev, drv_dev_struct, ibdev_member) \ | |
4650 | container_of(rdma_device_to_ibdev(dev), drv_dev_struct, ibdev_member) | |
41c61401 PP |
4651 | |
4652 | bool rdma_dev_access_netns(const struct ib_device *device, | |
4653 | const struct net *net); | |
1da177e4 | 4654 | #endif /* IB_VERBS_H */ |