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