1fe267a55SPedro F. Giffuni /*-
2fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3fe267a55SPedro F. Giffuni *
4aa0a1e58SJeff Roberson * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
5aa0a1e58SJeff Roberson * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
6aa0a1e58SJeff Roberson * Copyright (c) 2004 Intel Corporation. All rights reserved.
7aa0a1e58SJeff Roberson * Copyright (c) 2004 Topspin Corporation. All rights reserved.
8aa0a1e58SJeff Roberson * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
9aa0a1e58SJeff Roberson * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
10aa0a1e58SJeff Roberson * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
11aa0a1e58SJeff Roberson *
12aa0a1e58SJeff Roberson * This software is available to you under a choice of one of two
13aa0a1e58SJeff Roberson * licenses. You may choose to be licensed under the terms of the GNU
14aa0a1e58SJeff Roberson * General Public License (GPL) Version 2, available from the file
15aa0a1e58SJeff Roberson * COPYING in the main directory of this source tree, or the
16aa0a1e58SJeff Roberson * OpenIB.org BSD license below:
17aa0a1e58SJeff Roberson *
18aa0a1e58SJeff Roberson * Redistribution and use in source and binary forms, with or
19aa0a1e58SJeff Roberson * without modification, are permitted provided that the following
20aa0a1e58SJeff Roberson * conditions are met:
21aa0a1e58SJeff Roberson *
22aa0a1e58SJeff Roberson * - Redistributions of source code must retain the above
23aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following
24aa0a1e58SJeff Roberson * disclaimer.
25aa0a1e58SJeff Roberson *
26aa0a1e58SJeff Roberson * - Redistributions in binary form must reproduce the above
27aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following
28aa0a1e58SJeff Roberson * disclaimer in the documentation and/or other materials
29aa0a1e58SJeff Roberson * provided with the distribution.
30aa0a1e58SJeff Roberson *
31aa0a1e58SJeff Roberson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32aa0a1e58SJeff Roberson * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33aa0a1e58SJeff Roberson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34aa0a1e58SJeff Roberson * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
35aa0a1e58SJeff Roberson * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
36aa0a1e58SJeff Roberson * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
37aa0a1e58SJeff Roberson * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38aa0a1e58SJeff Roberson * SOFTWARE.
39aa0a1e58SJeff Roberson */
40aa0a1e58SJeff Roberson
41aa0a1e58SJeff Roberson #if !defined(IB_VERBS_H)
42aa0a1e58SJeff Roberson #define IB_VERBS_H
43aa0a1e58SJeff Roberson
44aa0a1e58SJeff Roberson #include <linux/types.h>
45aa0a1e58SJeff Roberson #include <linux/device.h>
46aa0a1e58SJeff Roberson #include <linux/mm.h>
47aa0a1e58SJeff Roberson #include <linux/dma-mapping.h>
48aa0a1e58SJeff Roberson #include <linux/kref.h>
49aa0a1e58SJeff Roberson #include <linux/list.h>
50aa0a1e58SJeff Roberson #include <linux/rwsem.h>
51aa0a1e58SJeff Roberson #include <linux/scatterlist.h>
52c9f432b7SAlfred Perlstein #include <linux/workqueue.h>
53478d3005SHans Petter Selasky #include <linux/socket.h>
54b5c1e0cbSHans Petter Selasky #include <linux/if_ether.h>
55478d3005SHans Petter Selasky #include <net/ipv6.h>
56478d3005SHans Petter Selasky #include <net/ip.h>
57478d3005SHans Petter Selasky #include <linux/string.h>
58478d3005SHans Petter Selasky #include <linux/slab.h>
59478d3005SHans Petter Selasky #include <linux/rcupdate.h>
60478d3005SHans Petter Selasky #include <linux/netdevice.h>
61b633e08cSHans Petter Selasky #include <linux/xarray.h>
62478d3005SHans Petter Selasky #include <netinet/ip.h>
63b633e08cSHans Petter Selasky #include <uapi/rdma/ib_user_verbs.h>
64b633e08cSHans Petter Selasky #include <rdma/signature.h>
65b633e08cSHans Petter Selasky #include <uapi/rdma/rdma_user_ioctl.h>
66b633e08cSHans Petter Selasky #include <uapi/rdma/ib_user_ioctl_verbs.h>
67aa0a1e58SJeff Roberson
68478d3005SHans Petter Selasky #include <asm/atomic.h>
69aa0a1e58SJeff Roberson #include <asm/uaccess.h>
70aa0a1e58SJeff Roberson
71b633e08cSHans Petter Selasky struct ib_uqp_object;
72b633e08cSHans Petter Selasky struct ib_usrq_object;
73b633e08cSHans Petter Selasky struct ib_uwq_object;
74478d3005SHans Petter Selasky struct ifla_vf_info;
75478d3005SHans Petter Selasky struct ifla_vf_stats;
7679b81708SHans Petter Selasky struct ib_uverbs_file;
77b633e08cSHans Petter Selasky struct uverbs_attr_bundle;
78b633e08cSHans Petter Selasky
79b633e08cSHans Petter Selasky enum ib_uverbs_advise_mr_advice;
80478d3005SHans Petter Selasky
81c9f432b7SAlfred Perlstein extern struct workqueue_struct *ib_wq;
82478d3005SHans Petter Selasky extern struct workqueue_struct *ib_comp_wq;
83c9f432b7SAlfred Perlstein
84b633e08cSHans Petter Selasky struct ib_ucq_object;
85b633e08cSHans Petter Selasky
86aa0a1e58SJeff Roberson union ib_gid {
87aa0a1e58SJeff Roberson u8 raw[16];
88aa0a1e58SJeff Roberson struct {
89aa0a1e58SJeff Roberson __be64 subnet_prefix;
90aa0a1e58SJeff Roberson __be64 interface_id;
91aa0a1e58SJeff Roberson } global;
92aa0a1e58SJeff Roberson };
93aa0a1e58SJeff Roberson
94478d3005SHans Petter Selasky extern union ib_gid zgid;
95478d3005SHans Petter Selasky
96478d3005SHans Petter Selasky enum ib_gid_type {
97478d3005SHans Petter Selasky /* If link layer is Ethernet, this is RoCE V1 */
98478d3005SHans Petter Selasky IB_GID_TYPE_IB = 0,
99478d3005SHans Petter Selasky IB_GID_TYPE_ROCE = 0,
100478d3005SHans Petter Selasky IB_GID_TYPE_ROCE_UDP_ENCAP = 1,
101478d3005SHans Petter Selasky IB_GID_TYPE_SIZE
102478d3005SHans Petter Selasky };
103478d3005SHans Petter Selasky
104478d3005SHans Petter Selasky #define ROCE_V2_UDP_DPORT 4791
105478d3005SHans Petter Selasky struct ib_gid_attr {
106478d3005SHans Petter Selasky enum ib_gid_type gid_type;
1073e142e07SJustin Hibbits if_t ndev;
108478d3005SHans Petter Selasky };
109478d3005SHans Petter Selasky
110aa0a1e58SJeff Roberson enum rdma_node_type {
111aa0a1e58SJeff Roberson /* IB values map to NodeInfo:NodeType. */
112aa0a1e58SJeff Roberson RDMA_NODE_IB_CA = 1,
113aa0a1e58SJeff Roberson RDMA_NODE_IB_SWITCH,
114aa0a1e58SJeff Roberson RDMA_NODE_IB_ROUTER,
115b5c1e0cbSHans Petter Selasky RDMA_NODE_RNIC,
116478d3005SHans Petter Selasky RDMA_NODE_USNIC,
117478d3005SHans Petter Selasky RDMA_NODE_USNIC_UDP,
118478d3005SHans Petter Selasky };
119478d3005SHans Petter Selasky
120478d3005SHans Petter Selasky enum {
121478d3005SHans Petter Selasky /* set the local administered indication */
122478d3005SHans Petter Selasky IB_SA_WELL_KNOWN_GUID = BIT_ULL(57) | 2,
123aa0a1e58SJeff Roberson };
124aa0a1e58SJeff Roberson
125aa0a1e58SJeff Roberson enum rdma_transport_type {
126aa0a1e58SJeff Roberson RDMA_TRANSPORT_IB,
127b5c1e0cbSHans Petter Selasky RDMA_TRANSPORT_IWARP,
128478d3005SHans Petter Selasky RDMA_TRANSPORT_USNIC,
129478d3005SHans Petter Selasky RDMA_TRANSPORT_USNIC_UDP
130aa0a1e58SJeff Roberson };
131aa0a1e58SJeff Roberson
132478d3005SHans Petter Selasky enum rdma_protocol_type {
133478d3005SHans Petter Selasky RDMA_PROTOCOL_IB,
134478d3005SHans Petter Selasky RDMA_PROTOCOL_IBOE,
135478d3005SHans Petter Selasky RDMA_PROTOCOL_IWARP,
136478d3005SHans Petter Selasky RDMA_PROTOCOL_USNIC_UDP
137478d3005SHans Petter Selasky };
138478d3005SHans Petter Selasky
139478d3005SHans Petter Selasky __attribute_const__ enum rdma_transport_type
140478d3005SHans Petter Selasky rdma_node_get_transport(enum rdma_node_type node_type);
141478d3005SHans Petter Selasky
142478d3005SHans Petter Selasky enum rdma_network_type {
143478d3005SHans Petter Selasky RDMA_NETWORK_IB,
144478d3005SHans Petter Selasky RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB,
145478d3005SHans Petter Selasky RDMA_NETWORK_IPV4,
146478d3005SHans Petter Selasky RDMA_NETWORK_IPV6
147478d3005SHans Petter Selasky };
148478d3005SHans Petter Selasky
ib_network_to_gid_type(enum rdma_network_type network_type)149478d3005SHans Petter Selasky static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
150478d3005SHans Petter Selasky {
151478d3005SHans Petter Selasky if (network_type == RDMA_NETWORK_IPV4 ||
152478d3005SHans Petter Selasky network_type == RDMA_NETWORK_IPV6)
153478d3005SHans Petter Selasky return IB_GID_TYPE_ROCE_UDP_ENCAP;
154478d3005SHans Petter Selasky
155478d3005SHans Petter Selasky /* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */
156478d3005SHans Petter Selasky return IB_GID_TYPE_IB;
157478d3005SHans Petter Selasky }
158478d3005SHans Petter Selasky
ib_gid_to_network_type(enum ib_gid_type gid_type,union ib_gid * gid)159478d3005SHans Petter Selasky static inline enum rdma_network_type ib_gid_to_network_type(enum ib_gid_type gid_type,
160478d3005SHans Petter Selasky union ib_gid *gid)
161478d3005SHans Petter Selasky {
162478d3005SHans Petter Selasky if (gid_type == IB_GID_TYPE_IB)
163478d3005SHans Petter Selasky return RDMA_NETWORK_IB;
164478d3005SHans Petter Selasky
165478d3005SHans Petter Selasky if (ipv6_addr_v4mapped((struct in6_addr *)gid))
166478d3005SHans Petter Selasky return RDMA_NETWORK_IPV4;
167478d3005SHans Petter Selasky else
168478d3005SHans Petter Selasky return RDMA_NETWORK_IPV6;
169478d3005SHans Petter Selasky }
170aa0a1e58SJeff Roberson
171aa0a1e58SJeff Roberson enum rdma_link_layer {
172aa0a1e58SJeff Roberson IB_LINK_LAYER_UNSPECIFIED,
173aa0a1e58SJeff Roberson IB_LINK_LAYER_INFINIBAND,
174aa0a1e58SJeff Roberson IB_LINK_LAYER_ETHERNET,
175aa0a1e58SJeff Roberson };
176aa0a1e58SJeff Roberson
177aa0a1e58SJeff Roberson enum ib_device_cap_flags {
178478d3005SHans Petter Selasky IB_DEVICE_RESIZE_MAX_WR = (1 << 0),
179aa0a1e58SJeff Roberson IB_DEVICE_BAD_PKEY_CNTR = (1 << 1),
180aa0a1e58SJeff Roberson IB_DEVICE_BAD_QKEY_CNTR = (1 << 2),
181aa0a1e58SJeff Roberson IB_DEVICE_RAW_MULTI = (1 << 3),
182aa0a1e58SJeff Roberson IB_DEVICE_AUTO_PATH_MIG = (1 << 4),
183aa0a1e58SJeff Roberson IB_DEVICE_CHANGE_PHY_PORT = (1 << 5),
184aa0a1e58SJeff Roberson IB_DEVICE_UD_AV_PORT_ENFORCE = (1 << 6),
185aa0a1e58SJeff Roberson IB_DEVICE_CURR_QP_STATE_MOD = (1 << 7),
186aa0a1e58SJeff Roberson IB_DEVICE_SHUTDOWN_PORT = (1 << 8),
187aa0a1e58SJeff Roberson IB_DEVICE_INIT_TYPE = (1 << 9),
188aa0a1e58SJeff Roberson IB_DEVICE_PORT_ACTIVE_EVENT = (1 << 10),
189aa0a1e58SJeff Roberson IB_DEVICE_SYS_IMAGE_GUID = (1 << 11),
190aa0a1e58SJeff Roberson IB_DEVICE_RC_RNR_NAK_GEN = (1 << 12),
191aa0a1e58SJeff Roberson IB_DEVICE_SRQ_RESIZE = (1 << 13),
192aa0a1e58SJeff Roberson IB_DEVICE_N_NOTIFY_CQ = (1 << 14),
193478d3005SHans Petter Selasky
194478d3005SHans Petter Selasky /*
195478d3005SHans Petter Selasky * This device supports a per-device lkey or stag that can be
196478d3005SHans Petter Selasky * used without performing a memory registration for the local
197478d3005SHans Petter Selasky * memory. Note that ULPs should never check this flag, but
198478d3005SHans Petter Selasky * instead of use the local_dma_lkey flag in the ib_pd structure,
199478d3005SHans Petter Selasky * which will always contain a usable lkey.
200478d3005SHans Petter Selasky */
201aa0a1e58SJeff Roberson IB_DEVICE_LOCAL_DMA_LKEY = (1 << 15),
202478d3005SHans Petter Selasky IB_DEVICE_RESERVED /* old SEND_W_INV */ = (1 << 16),
203aa0a1e58SJeff Roberson IB_DEVICE_MEM_WINDOW = (1 << 17),
204aa0a1e58SJeff Roberson /*
205aa0a1e58SJeff Roberson * Devices should set IB_DEVICE_UD_IP_SUM if they support
206aa0a1e58SJeff Roberson * insertion of UDP and TCP checksum on outgoing UD IPoIB
207aa0a1e58SJeff Roberson * messages and can verify the validity of checksum for
208aa0a1e58SJeff Roberson * incoming messages. Setting this flag implies that the
209aa0a1e58SJeff Roberson * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
210aa0a1e58SJeff Roberson */
211aa0a1e58SJeff Roberson IB_DEVICE_UD_IP_CSUM = (1 << 18),
212aa0a1e58SJeff Roberson IB_DEVICE_UD_TSO = (1 << 19),
213aa0a1e58SJeff Roberson IB_DEVICE_XRC = (1 << 20),
214478d3005SHans Petter Selasky
215478d3005SHans Petter Selasky /*
216478d3005SHans Petter Selasky * This device supports the IB "base memory management extension",
217478d3005SHans Petter Selasky * which includes support for fast registrations (IB_WR_REG_MR,
218478d3005SHans Petter Selasky * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs). This flag should
219478d3005SHans Petter Selasky * also be set by any iWarp device which must support FRs to comply
220478d3005SHans Petter Selasky * to the iWarp verbs spec. iWarp devices also support the
221478d3005SHans Petter Selasky * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
222478d3005SHans Petter Selasky * stag.
223478d3005SHans Petter Selasky */
224aa0a1e58SJeff Roberson IB_DEVICE_MEM_MGT_EXTENSIONS = (1 << 21),
225aa0a1e58SJeff Roberson IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1 << 22),
226478d3005SHans Petter Selasky IB_DEVICE_MEM_WINDOW_TYPE_2A = (1 << 23),
227478d3005SHans Petter Selasky IB_DEVICE_MEM_WINDOW_TYPE_2B = (1 << 24),
228478d3005SHans Petter Selasky IB_DEVICE_RC_IP_CSUM = (1 << 25),
229*a69b6af2SKa Ho Ng /* Deprecated. Please use IB_RAW_PACKET_CAP_IP_CSUM. */
230478d3005SHans Petter Selasky IB_DEVICE_RAW_IP_CSUM = (1 << 26),
231b5c1e0cbSHans Petter Selasky /*
232478d3005SHans Petter Selasky * Devices should set IB_DEVICE_CROSS_CHANNEL if they
233478d3005SHans Petter Selasky * support execution of WQEs that involve synchronization
234478d3005SHans Petter Selasky * of I/O operations with single completion queue managed
235478d3005SHans Petter Selasky * by hardware.
236b5c1e0cbSHans Petter Selasky */
237478d3005SHans Petter Selasky IB_DEVICE_CROSS_CHANNEL = (1 << 27),
238478d3005SHans Petter Selasky IB_DEVICE_MANAGED_FLOW_STEERING = (1 << 29),
239478d3005SHans Petter Selasky IB_DEVICE_SIGNATURE_HANDOVER = (1 << 30),
240478d3005SHans Petter Selasky IB_DEVICE_ON_DEMAND_PAGING = (1ULL << 31),
241478d3005SHans Petter Selasky IB_DEVICE_SG_GAPS_REG = (1ULL << 32),
242478d3005SHans Petter Selasky IB_DEVICE_VIRTUAL_FUNCTION = (1ULL << 33),
243*a69b6af2SKa Ho Ng /* Deprecated. Please use IB_RAW_PACKET_CAP_SCATTER_FCS. */
244478d3005SHans Petter Selasky IB_DEVICE_RAW_SCATTER_FCS = (1ULL << 34),
245fc6c93b6SZhenlei Huang IB_DEVICE_KNOWSEPOCH = (1ULL << 35),
246b5c1e0cbSHans Petter Selasky };
247b5c1e0cbSHans Petter Selasky
248aa0a1e58SJeff Roberson enum ib_atomic_cap {
249aa0a1e58SJeff Roberson IB_ATOMIC_NONE,
250aa0a1e58SJeff Roberson IB_ATOMIC_HCA,
251aa0a1e58SJeff Roberson IB_ATOMIC_GLOB
252aa0a1e58SJeff Roberson };
253aa0a1e58SJeff Roberson
254478d3005SHans Petter Selasky enum ib_odp_general_cap_bits {
255478d3005SHans Petter Selasky IB_ODP_SUPPORT = 1 << 0,
256478d3005SHans Petter Selasky };
257478d3005SHans Petter Selasky
258478d3005SHans Petter Selasky enum ib_odp_transport_cap_bits {
259478d3005SHans Petter Selasky IB_ODP_SUPPORT_SEND = 1 << 0,
260478d3005SHans Petter Selasky IB_ODP_SUPPORT_RECV = 1 << 1,
261478d3005SHans Petter Selasky IB_ODP_SUPPORT_WRITE = 1 << 2,
262478d3005SHans Petter Selasky IB_ODP_SUPPORT_READ = 1 << 3,
263478d3005SHans Petter Selasky IB_ODP_SUPPORT_ATOMIC = 1 << 4,
264478d3005SHans Petter Selasky };
265478d3005SHans Petter Selasky
266478d3005SHans Petter Selasky struct ib_odp_caps {
267478d3005SHans Petter Selasky uint64_t general_caps;
268478d3005SHans Petter Selasky struct {
269478d3005SHans Petter Selasky uint32_t rc_odp_caps;
270478d3005SHans Petter Selasky uint32_t uc_odp_caps;
271478d3005SHans Petter Selasky uint32_t ud_odp_caps;
272b633e08cSHans Petter Selasky uint32_t xrc_odp_caps;
273478d3005SHans Petter Selasky } per_transport_caps;
274478d3005SHans Petter Selasky };
275478d3005SHans Petter Selasky
276478d3005SHans Petter Selasky struct ib_rss_caps {
277478d3005SHans Petter Selasky /* Corresponding bit will be set if qp type from
278478d3005SHans Petter Selasky * 'enum ib_qp_type' is supported, e.g.
279478d3005SHans Petter Selasky * supported_qpts |= 1 << IB_QPT_UD
280478d3005SHans Petter Selasky */
281478d3005SHans Petter Selasky u32 supported_qpts;
282478d3005SHans Petter Selasky u32 max_rwq_indirection_tables;
283478d3005SHans Petter Selasky u32 max_rwq_indirection_table_size;
284478d3005SHans Petter Selasky };
285478d3005SHans Petter Selasky
286b633e08cSHans Petter Selasky enum ib_tm_cap_flags {
287b633e08cSHans Petter Selasky /* Support tag matching with rendezvous offload for RC transport */
288b633e08cSHans Petter Selasky IB_TM_CAP_RNDV_RC = 1 << 0,
289b633e08cSHans Petter Selasky };
290b633e08cSHans Petter Selasky
291b633e08cSHans Petter Selasky struct ib_tm_caps {
292b633e08cSHans Petter Selasky /* Max size of RNDV header */
293b633e08cSHans Petter Selasky u32 max_rndv_hdr_size;
294b633e08cSHans Petter Selasky /* Max number of entries in tag matching list */
295b633e08cSHans Petter Selasky u32 max_num_tags;
296b633e08cSHans Petter Selasky /* From enum ib_tm_cap_flags */
297b633e08cSHans Petter Selasky u32 flags;
298b633e08cSHans Petter Selasky /* Max number of outstanding list operations */
299b633e08cSHans Petter Selasky u32 max_ops;
300b633e08cSHans Petter Selasky /* Max number of SGE in tag matching entry */
301b633e08cSHans Petter Selasky u32 max_sge;
302b633e08cSHans Petter Selasky };
303b633e08cSHans Petter Selasky
304478d3005SHans Petter Selasky enum ib_cq_creation_flags {
305478d3005SHans Petter Selasky IB_CQ_FLAGS_TIMESTAMP_COMPLETION = 1 << 0,
306478d3005SHans Petter Selasky IB_CQ_FLAGS_IGNORE_OVERRUN = 1 << 1,
307478d3005SHans Petter Selasky };
308478d3005SHans Petter Selasky
309478d3005SHans Petter Selasky struct ib_cq_init_attr {
310478d3005SHans Petter Selasky unsigned int cqe;
31192203578SHans Petter Selasky u32 comp_vector;
312478d3005SHans Petter Selasky u32 flags;
313b5c1e0cbSHans Petter Selasky };
314b5c1e0cbSHans Petter Selasky
315b633e08cSHans Petter Selasky enum ib_cq_attr_mask {
316b633e08cSHans Petter Selasky IB_CQ_MODERATE = 1 << 0,
317b633e08cSHans Petter Selasky };
318b633e08cSHans Petter Selasky
319b633e08cSHans Petter Selasky struct ib_cq_caps {
320b633e08cSHans Petter Selasky u16 max_cq_moderation_count;
321b633e08cSHans Petter Selasky u16 max_cq_moderation_period;
322b633e08cSHans Petter Selasky };
323b633e08cSHans Petter Selasky
324b633e08cSHans Petter Selasky struct ib_dm_mr_attr {
325b633e08cSHans Petter Selasky u64 length;
326b633e08cSHans Petter Selasky u64 offset;
327b633e08cSHans Petter Selasky u32 access_flags;
328b633e08cSHans Petter Selasky };
329b633e08cSHans Petter Selasky
330b633e08cSHans Petter Selasky struct ib_dm_alloc_attr {
331b633e08cSHans Petter Selasky u64 length;
332b633e08cSHans Petter Selasky u32 alignment;
333b633e08cSHans Petter Selasky u32 flags;
334b633e08cSHans Petter Selasky };
335b633e08cSHans Petter Selasky
336aa0a1e58SJeff Roberson struct ib_device_attr {
337aa0a1e58SJeff Roberson u64 fw_ver;
338aa0a1e58SJeff Roberson __be64 sys_image_guid;
339aa0a1e58SJeff Roberson u64 max_mr_size;
340aa0a1e58SJeff Roberson u64 page_size_cap;
341aa0a1e58SJeff Roberson u32 vendor_id;
342aa0a1e58SJeff Roberson u32 vendor_part_id;
343aa0a1e58SJeff Roberson u32 hw_ver;
344aa0a1e58SJeff Roberson int max_qp;
345aa0a1e58SJeff Roberson int max_qp_wr;
346b5c1e0cbSHans Petter Selasky u64 device_cap_flags;
347aa0a1e58SJeff Roberson int max_sge;
348aa0a1e58SJeff Roberson int max_sge_rd;
349aa0a1e58SJeff Roberson int max_cq;
350aa0a1e58SJeff Roberson int max_cqe;
351aa0a1e58SJeff Roberson int max_mr;
352aa0a1e58SJeff Roberson int max_pd;
353aa0a1e58SJeff Roberson int max_qp_rd_atom;
354aa0a1e58SJeff Roberson int max_ee_rd_atom;
355aa0a1e58SJeff Roberson int max_res_rd_atom;
356aa0a1e58SJeff Roberson int max_qp_init_rd_atom;
357aa0a1e58SJeff Roberson int max_ee_init_rd_atom;
358aa0a1e58SJeff Roberson enum ib_atomic_cap atomic_cap;
359aa0a1e58SJeff Roberson enum ib_atomic_cap masked_atomic_cap;
360aa0a1e58SJeff Roberson int max_ee;
361aa0a1e58SJeff Roberson int max_rdd;
362aa0a1e58SJeff Roberson int max_mw;
363aa0a1e58SJeff Roberson int max_raw_ipv6_qp;
364aa0a1e58SJeff Roberson int max_raw_ethy_qp;
365aa0a1e58SJeff Roberson int max_mcast_grp;
366aa0a1e58SJeff Roberson int max_mcast_qp_attach;
367aa0a1e58SJeff Roberson int max_total_mcast_qp_attach;
368aa0a1e58SJeff Roberson int max_ah;
369aa0a1e58SJeff Roberson int max_fmr;
370aa0a1e58SJeff Roberson int max_map_per_fmr;
371aa0a1e58SJeff Roberson int max_srq;
372aa0a1e58SJeff Roberson int max_srq_wr;
373b633e08cSHans Petter Selasky union {
374aa0a1e58SJeff Roberson int max_srq_sge;
375b633e08cSHans Petter Selasky int max_send_sge;
376b633e08cSHans Petter Selasky int max_recv_sge;
377b633e08cSHans Petter Selasky };
378aa0a1e58SJeff Roberson unsigned int max_fast_reg_page_list_len;
379aa0a1e58SJeff Roberson u16 max_pkeys;
380aa0a1e58SJeff Roberson u8 local_ca_ack_delay;
381478d3005SHans Petter Selasky int sig_prot_cap;
382478d3005SHans Petter Selasky int sig_guard_cap;
383478d3005SHans Petter Selasky struct ib_odp_caps odp_caps;
384b5c1e0cbSHans Petter Selasky uint64_t timestamp_mask;
385478d3005SHans Petter Selasky uint64_t hca_core_clock; /* in KHZ */
386478d3005SHans Petter Selasky struct ib_rss_caps rss_caps;
387478d3005SHans Petter Selasky u32 max_wq_type_rq;
388b633e08cSHans Petter Selasky u32 raw_packet_caps; /* Use ib_raw_packet_caps enum */
389b633e08cSHans Petter Selasky struct ib_tm_caps tm_caps;
390b633e08cSHans Petter Selasky struct ib_cq_caps cq_caps;
391b633e08cSHans Petter Selasky u64 max_dm_size;
392b633e08cSHans Petter Selasky /* Max entries for sgl for optimized performance per READ */
393b633e08cSHans Petter Selasky u32 max_sgl_rd;
394aa0a1e58SJeff Roberson };
395aa0a1e58SJeff Roberson
396aa0a1e58SJeff Roberson enum ib_mtu {
397aa0a1e58SJeff Roberson IB_MTU_256 = 1,
398aa0a1e58SJeff Roberson IB_MTU_512 = 2,
399aa0a1e58SJeff Roberson IB_MTU_1024 = 3,
400aa0a1e58SJeff Roberson IB_MTU_2048 = 4,
401aa0a1e58SJeff Roberson IB_MTU_4096 = 5
402aa0a1e58SJeff Roberson };
403aa0a1e58SJeff Roberson
ib_mtu_enum_to_int(enum ib_mtu mtu)404aa0a1e58SJeff Roberson static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
405aa0a1e58SJeff Roberson {
406aa0a1e58SJeff Roberson switch (mtu) {
407aa0a1e58SJeff Roberson case IB_MTU_256: return 256;
408aa0a1e58SJeff Roberson case IB_MTU_512: return 512;
409aa0a1e58SJeff Roberson case IB_MTU_1024: return 1024;
410aa0a1e58SJeff Roberson case IB_MTU_2048: return 2048;
411aa0a1e58SJeff Roberson case IB_MTU_4096: return 4096;
412aa0a1e58SJeff Roberson default: return -1;
413aa0a1e58SJeff Roberson }
414aa0a1e58SJeff Roberson }
415aa0a1e58SJeff Roberson
416aa0a1e58SJeff Roberson enum ib_port_state {
417aa0a1e58SJeff Roberson IB_PORT_NOP = 0,
418aa0a1e58SJeff Roberson IB_PORT_DOWN = 1,
419aa0a1e58SJeff Roberson IB_PORT_INIT = 2,
420aa0a1e58SJeff Roberson IB_PORT_ARMED = 3,
421aa0a1e58SJeff Roberson IB_PORT_ACTIVE = 4,
422b5c1e0cbSHans Petter Selasky IB_PORT_ACTIVE_DEFER = 5,
423478d3005SHans Petter Selasky IB_PORT_DUMMY = -1, /* force enum signed */
424aa0a1e58SJeff Roberson };
425aa0a1e58SJeff Roberson
426aa0a1e58SJeff Roberson enum ib_port_cap_flags {
427aa0a1e58SJeff Roberson IB_PORT_SM = 1 << 1,
428aa0a1e58SJeff Roberson IB_PORT_NOTICE_SUP = 1 << 2,
429aa0a1e58SJeff Roberson IB_PORT_TRAP_SUP = 1 << 3,
430aa0a1e58SJeff Roberson IB_PORT_OPT_IPD_SUP = 1 << 4,
431aa0a1e58SJeff Roberson IB_PORT_AUTO_MIGR_SUP = 1 << 5,
432aa0a1e58SJeff Roberson IB_PORT_SL_MAP_SUP = 1 << 6,
433aa0a1e58SJeff Roberson IB_PORT_MKEY_NVRAM = 1 << 7,
434aa0a1e58SJeff Roberson IB_PORT_PKEY_NVRAM = 1 << 8,
435aa0a1e58SJeff Roberson IB_PORT_LED_INFO_SUP = 1 << 9,
436aa0a1e58SJeff Roberson IB_PORT_SM_DISABLED = 1 << 10,
437aa0a1e58SJeff Roberson IB_PORT_SYS_IMAGE_GUID_SUP = 1 << 11,
438aa0a1e58SJeff Roberson IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP = 1 << 12,
439c9f432b7SAlfred Perlstein IB_PORT_EXTENDED_SPEEDS_SUP = 1 << 14,
440aa0a1e58SJeff Roberson IB_PORT_CM_SUP = 1 << 16,
441aa0a1e58SJeff Roberson IB_PORT_SNMP_TUNNEL_SUP = 1 << 17,
442aa0a1e58SJeff Roberson IB_PORT_REINIT_SUP = 1 << 18,
443aa0a1e58SJeff Roberson IB_PORT_DEVICE_MGMT_SUP = 1 << 19,
444aa0a1e58SJeff Roberson IB_PORT_VENDOR_CLASS_SUP = 1 << 20,
445aa0a1e58SJeff Roberson IB_PORT_DR_NOTICE_SUP = 1 << 21,
446aa0a1e58SJeff Roberson IB_PORT_CAP_MASK_NOTICE_SUP = 1 << 22,
447aa0a1e58SJeff Roberson IB_PORT_BOOT_MGMT_SUP = 1 << 23,
448aa0a1e58SJeff Roberson IB_PORT_LINK_LATENCY_SUP = 1 << 24,
449478d3005SHans Petter Selasky IB_PORT_CLIENT_REG_SUP = 1 << 25,
450478d3005SHans Petter Selasky IB_PORT_IP_BASED_GIDS = 1 << 26,
451aa0a1e58SJeff Roberson };
452aa0a1e58SJeff Roberson
4534238b4a7SHans Petter Selasky enum ib_port_phys_state {
4544238b4a7SHans Petter Selasky IB_PORT_PHYS_STATE_SLEEP = 1,
4554238b4a7SHans Petter Selasky IB_PORT_PHYS_STATE_POLLING = 2,
4564238b4a7SHans Petter Selasky IB_PORT_PHYS_STATE_DISABLED = 3,
4574238b4a7SHans Petter Selasky IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING = 4,
4584238b4a7SHans Petter Selasky IB_PORT_PHYS_STATE_LINK_UP = 5,
4594238b4a7SHans Petter Selasky IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY = 6,
4604238b4a7SHans Petter Selasky IB_PORT_PHYS_STATE_PHY_TEST = 7,
4614238b4a7SHans Petter Selasky };
4624238b4a7SHans Petter Selasky
463aa0a1e58SJeff Roberson enum ib_port_width {
464aa0a1e58SJeff Roberson IB_WIDTH_1X = 1,
465013f1e14SHans Petter Selasky IB_WIDTH_2X = 16,
466aa0a1e58SJeff Roberson IB_WIDTH_4X = 2,
467aa0a1e58SJeff Roberson IB_WIDTH_8X = 4,
468aa0a1e58SJeff Roberson IB_WIDTH_12X = 8
469aa0a1e58SJeff Roberson };
470aa0a1e58SJeff Roberson
ib_width_enum_to_int(enum ib_port_width width)471aa0a1e58SJeff Roberson static inline int ib_width_enum_to_int(enum ib_port_width width)
472aa0a1e58SJeff Roberson {
473aa0a1e58SJeff Roberson switch (width) {
474aa0a1e58SJeff Roberson case IB_WIDTH_1X: return 1;
475013f1e14SHans Petter Selasky case IB_WIDTH_2X: return 2;
476aa0a1e58SJeff Roberson case IB_WIDTH_4X: return 4;
477aa0a1e58SJeff Roberson case IB_WIDTH_8X: return 8;
478aa0a1e58SJeff Roberson case IB_WIDTH_12X: return 12;
479aa0a1e58SJeff Roberson default: return -1;
480aa0a1e58SJeff Roberson }
481aa0a1e58SJeff Roberson }
482aa0a1e58SJeff Roberson
483c9f432b7SAlfred Perlstein enum ib_port_speed {
484c9f432b7SAlfred Perlstein IB_SPEED_SDR = 1,
485c9f432b7SAlfred Perlstein IB_SPEED_DDR = 2,
486c9f432b7SAlfred Perlstein IB_SPEED_QDR = 4,
487c9f432b7SAlfred Perlstein IB_SPEED_FDR10 = 8,
488c9f432b7SAlfred Perlstein IB_SPEED_FDR = 16,
489d0a82c24SHans Petter Selasky IB_SPEED_EDR = 32,
4901aa593b9SHans Petter Selasky IB_SPEED_HDR = 64,
4911aa593b9SHans Petter Selasky IB_SPEED_NDR = 128
492c9f432b7SAlfred Perlstein };
493c9f432b7SAlfred Perlstein
494478d3005SHans Petter Selasky /**
495478d3005SHans Petter Selasky * struct rdma_hw_stats
496912e98ceSHans Petter Selasky * @lock - Mutex to protect parallel write access to lifespan and values
497912e98ceSHans Petter Selasky * of counters, which are 64bits and not guaranteeed to be written
498912e98ceSHans Petter Selasky * atomicaly on 32bits systems.
499478d3005SHans Petter Selasky * @timestamp - Used by the core code to track when the last update was
500478d3005SHans Petter Selasky * @lifespan - Used by the core code to determine how old the counters
501478d3005SHans Petter Selasky * should be before being updated again. Stored in jiffies, defaults
502478d3005SHans Petter Selasky * to 10 milliseconds, drivers can override the default be specifying
503478d3005SHans Petter Selasky * their own value during their allocation routine.
504478d3005SHans Petter Selasky * @name - Array of pointers to static names used for the counters in
505478d3005SHans Petter Selasky * directory.
506478d3005SHans Petter Selasky * @num_counters - How many hardware counters there are. If name is
507478d3005SHans Petter Selasky * shorter than this number, a kernel oops will result. Driver authors
508478d3005SHans Petter Selasky * are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
509478d3005SHans Petter Selasky * in their code to prevent this.
510478d3005SHans Petter Selasky * @value - Array of u64 counters that are accessed by the sysfs code and
511478d3005SHans Petter Selasky * filled in by the drivers get_stats routine
512478d3005SHans Petter Selasky */
513478d3005SHans Petter Selasky struct rdma_hw_stats {
514912e98ceSHans Petter Selasky struct mutex lock; /* Protect lifespan and values[] */
515478d3005SHans Petter Selasky unsigned long timestamp;
516478d3005SHans Petter Selasky unsigned long lifespan;
517478d3005SHans Petter Selasky const char * const *names;
518478d3005SHans Petter Selasky int num_counters;
519478d3005SHans Petter Selasky u64 value[];
520aa0a1e58SJeff Roberson };
521aa0a1e58SJeff Roberson
522478d3005SHans Petter Selasky #define RDMA_HW_STATS_DEFAULT_LIFESPAN 10
523478d3005SHans Petter Selasky /**
524478d3005SHans Petter Selasky * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct
525478d3005SHans Petter Selasky * for drivers.
526478d3005SHans Petter Selasky * @names - Array of static const char *
527478d3005SHans Petter Selasky * @num_counters - How many elements in array
528478d3005SHans Petter Selasky * @lifespan - How many milliseconds between updates
529478d3005SHans Petter Selasky */
rdma_alloc_hw_stats_struct(const char * const * names,int num_counters,unsigned long lifespan)530478d3005SHans Petter Selasky static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
531478d3005SHans Petter Selasky const char * const *names, int num_counters,
532478d3005SHans Petter Selasky unsigned long lifespan)
533478d3005SHans Petter Selasky {
534478d3005SHans Petter Selasky struct rdma_hw_stats *stats;
535aa0a1e58SJeff Roberson
536478d3005SHans Petter Selasky stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
537478d3005SHans Petter Selasky GFP_KERNEL);
538478d3005SHans Petter Selasky if (!stats)
539478d3005SHans Petter Selasky return NULL;
540478d3005SHans Petter Selasky stats->names = names;
541478d3005SHans Petter Selasky stats->num_counters = num_counters;
542478d3005SHans Petter Selasky stats->lifespan = msecs_to_jiffies(lifespan);
543aa0a1e58SJeff Roberson
544478d3005SHans Petter Selasky return stats;
545478d3005SHans Petter Selasky }
546478d3005SHans Petter Selasky
547478d3005SHans Petter Selasky
548478d3005SHans Petter Selasky /* Define bits for the various functionality this port needs to be supported by
549478d3005SHans Petter Selasky * the core.
550478d3005SHans Petter Selasky */
551478d3005SHans Petter Selasky /* Management 0x00000FFF */
552478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IB_MAD 0x00000001
553478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IB_SMI 0x00000002
554478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IB_CM 0x00000004
555478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IW_CM 0x00000008
556478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IB_SA 0x00000010
557478d3005SHans Petter Selasky #define RDMA_CORE_CAP_OPA_MAD 0x00000020
558478d3005SHans Petter Selasky
559478d3005SHans Petter Selasky /* Address format 0x000FF000 */
560478d3005SHans Petter Selasky #define RDMA_CORE_CAP_AF_IB 0x00001000
561478d3005SHans Petter Selasky #define RDMA_CORE_CAP_ETH_AH 0x00002000
562478d3005SHans Petter Selasky
563478d3005SHans Petter Selasky /* Protocol 0xFFF00000 */
564478d3005SHans Petter Selasky #define RDMA_CORE_CAP_PROT_IB 0x00100000
565478d3005SHans Petter Selasky #define RDMA_CORE_CAP_PROT_ROCE 0x00200000
566478d3005SHans Petter Selasky #define RDMA_CORE_CAP_PROT_IWARP 0x00400000
567478d3005SHans Petter Selasky #define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
568478d3005SHans Petter Selasky
569478d3005SHans Petter Selasky #define RDMA_CORE_PORT_IBA_IB (RDMA_CORE_CAP_PROT_IB \
570478d3005SHans Petter Selasky | RDMA_CORE_CAP_IB_MAD \
571478d3005SHans Petter Selasky | RDMA_CORE_CAP_IB_SMI \
572478d3005SHans Petter Selasky | RDMA_CORE_CAP_IB_CM \
573478d3005SHans Petter Selasky | RDMA_CORE_CAP_IB_SA \
574478d3005SHans Petter Selasky | RDMA_CORE_CAP_AF_IB)
575478d3005SHans Petter Selasky #define RDMA_CORE_PORT_IBA_ROCE (RDMA_CORE_CAP_PROT_ROCE \
576478d3005SHans Petter Selasky | RDMA_CORE_CAP_IB_MAD \
577478d3005SHans Petter Selasky | RDMA_CORE_CAP_IB_CM \
578478d3005SHans Petter Selasky | RDMA_CORE_CAP_AF_IB \
579478d3005SHans Petter Selasky | RDMA_CORE_CAP_ETH_AH)
580478d3005SHans Petter Selasky #define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP \
581478d3005SHans Petter Selasky (RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
582478d3005SHans Petter Selasky | RDMA_CORE_CAP_IB_MAD \
583478d3005SHans Petter Selasky | RDMA_CORE_CAP_IB_CM \
584478d3005SHans Petter Selasky | RDMA_CORE_CAP_AF_IB \
585478d3005SHans Petter Selasky | RDMA_CORE_CAP_ETH_AH)
586478d3005SHans Petter Selasky #define RDMA_CORE_PORT_IWARP (RDMA_CORE_CAP_PROT_IWARP \
587478d3005SHans Petter Selasky | RDMA_CORE_CAP_IW_CM)
588478d3005SHans Petter Selasky #define RDMA_CORE_PORT_INTEL_OPA (RDMA_CORE_PORT_IBA_IB \
589478d3005SHans Petter Selasky | RDMA_CORE_CAP_OPA_MAD)
590aa0a1e58SJeff Roberson
591aa0a1e58SJeff Roberson struct ib_port_attr {
592478d3005SHans Petter Selasky u64 subnet_prefix;
593aa0a1e58SJeff Roberson enum ib_port_state state;
594aa0a1e58SJeff Roberson enum ib_mtu max_mtu;
595aa0a1e58SJeff Roberson enum ib_mtu active_mtu;
596aa0a1e58SJeff Roberson int gid_tbl_len;
597b633e08cSHans Petter Selasky unsigned int ip_gids:1;
598b633e08cSHans Petter Selasky /* This is the value from PortInfo CapabilityMask, defined by IBA */
599aa0a1e58SJeff Roberson u32 port_cap_flags;
600aa0a1e58SJeff Roberson u32 max_msg_sz;
601aa0a1e58SJeff Roberson u32 bad_pkey_cntr;
602aa0a1e58SJeff Roberson u32 qkey_viol_cntr;
603aa0a1e58SJeff Roberson u16 pkey_tbl_len;
604aa0a1e58SJeff Roberson u16 lid;
605aa0a1e58SJeff Roberson u16 sm_lid;
606aa0a1e58SJeff Roberson u8 lmc;
607aa0a1e58SJeff Roberson u8 max_vl_num;
608aa0a1e58SJeff Roberson u8 sm_sl;
609aa0a1e58SJeff Roberson u8 subnet_timeout;
610aa0a1e58SJeff Roberson u8 init_type_reply;
611aa0a1e58SJeff Roberson u8 active_width;
612aa0a1e58SJeff Roberson u8 active_speed;
613aa0a1e58SJeff Roberson u8 phys_state;
614478d3005SHans Petter Selasky bool grh_required;
615aa0a1e58SJeff Roberson };
616aa0a1e58SJeff Roberson
617aa0a1e58SJeff Roberson enum ib_device_modify_flags {
618aa0a1e58SJeff Roberson IB_DEVICE_MODIFY_SYS_IMAGE_GUID = 1 << 0,
619aa0a1e58SJeff Roberson IB_DEVICE_MODIFY_NODE_DESC = 1 << 1
620aa0a1e58SJeff Roberson };
621aa0a1e58SJeff Roberson
622478d3005SHans Petter Selasky #define IB_DEVICE_NODE_DESC_MAX 64
623478d3005SHans Petter Selasky
624aa0a1e58SJeff Roberson struct ib_device_modify {
625aa0a1e58SJeff Roberson u64 sys_image_guid;
626478d3005SHans Petter Selasky char node_desc[IB_DEVICE_NODE_DESC_MAX];
627aa0a1e58SJeff Roberson };
628aa0a1e58SJeff Roberson
629aa0a1e58SJeff Roberson enum ib_port_modify_flags {
630aa0a1e58SJeff Roberson IB_PORT_SHUTDOWN = 1,
631aa0a1e58SJeff Roberson IB_PORT_INIT_TYPE = (1<<2),
632aa0a1e58SJeff Roberson IB_PORT_RESET_QKEY_CNTR = (1<<3)
633aa0a1e58SJeff Roberson };
634aa0a1e58SJeff Roberson
635aa0a1e58SJeff Roberson struct ib_port_modify {
636aa0a1e58SJeff Roberson u32 set_port_cap_mask;
637aa0a1e58SJeff Roberson u32 clr_port_cap_mask;
638aa0a1e58SJeff Roberson u8 init_type;
639aa0a1e58SJeff Roberson };
640aa0a1e58SJeff Roberson
641aa0a1e58SJeff Roberson enum ib_event_type {
642aa0a1e58SJeff Roberson IB_EVENT_CQ_ERR,
643aa0a1e58SJeff Roberson IB_EVENT_QP_FATAL,
644aa0a1e58SJeff Roberson IB_EVENT_QP_REQ_ERR,
645aa0a1e58SJeff Roberson IB_EVENT_QP_ACCESS_ERR,
646aa0a1e58SJeff Roberson IB_EVENT_COMM_EST,
647aa0a1e58SJeff Roberson IB_EVENT_SQ_DRAINED,
648aa0a1e58SJeff Roberson IB_EVENT_PATH_MIG,
649aa0a1e58SJeff Roberson IB_EVENT_PATH_MIG_ERR,
650aa0a1e58SJeff Roberson IB_EVENT_DEVICE_FATAL,
651aa0a1e58SJeff Roberson IB_EVENT_PORT_ACTIVE,
652aa0a1e58SJeff Roberson IB_EVENT_PORT_ERR,
653aa0a1e58SJeff Roberson IB_EVENT_LID_CHANGE,
654aa0a1e58SJeff Roberson IB_EVENT_PKEY_CHANGE,
655aa0a1e58SJeff Roberson IB_EVENT_SM_CHANGE,
656aa0a1e58SJeff Roberson IB_EVENT_SRQ_ERR,
657aa0a1e58SJeff Roberson IB_EVENT_SRQ_LIMIT_REACHED,
658aa0a1e58SJeff Roberson IB_EVENT_QP_LAST_WQE_REACHED,
659aa0a1e58SJeff Roberson IB_EVENT_CLIENT_REREGISTER,
660aa0a1e58SJeff Roberson IB_EVENT_GID_CHANGE,
661478d3005SHans Petter Selasky IB_EVENT_WQ_FATAL,
662aa0a1e58SJeff Roberson };
663aa0a1e58SJeff Roberson
664478d3005SHans Petter Selasky const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
665478d3005SHans Petter Selasky
666aa0a1e58SJeff Roberson struct ib_event {
667aa0a1e58SJeff Roberson struct ib_device *device;
668aa0a1e58SJeff Roberson union {
669aa0a1e58SJeff Roberson struct ib_cq *cq;
670aa0a1e58SJeff Roberson struct ib_qp *qp;
671aa0a1e58SJeff Roberson struct ib_srq *srq;
672478d3005SHans Petter Selasky struct ib_wq *wq;
673aa0a1e58SJeff Roberson u8 port_num;
674aa0a1e58SJeff Roberson } element;
675aa0a1e58SJeff Roberson enum ib_event_type event;
676aa0a1e58SJeff Roberson };
677aa0a1e58SJeff Roberson
678aa0a1e58SJeff Roberson struct ib_event_handler {
679aa0a1e58SJeff Roberson struct ib_device *device;
680aa0a1e58SJeff Roberson void (*handler)(struct ib_event_handler *, struct ib_event *);
681aa0a1e58SJeff Roberson struct list_head list;
682aa0a1e58SJeff Roberson };
683aa0a1e58SJeff Roberson
684aa0a1e58SJeff Roberson #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \
685aa0a1e58SJeff Roberson do { \
686aa0a1e58SJeff Roberson (_ptr)->device = _device; \
687aa0a1e58SJeff Roberson (_ptr)->handler = _handler; \
688aa0a1e58SJeff Roberson INIT_LIST_HEAD(&(_ptr)->list); \
689aa0a1e58SJeff Roberson } while (0)
690aa0a1e58SJeff Roberson
691aa0a1e58SJeff Roberson struct ib_global_route {
692aa0a1e58SJeff Roberson union ib_gid dgid;
693aa0a1e58SJeff Roberson u32 flow_label;
694aa0a1e58SJeff Roberson u8 sgid_index;
695aa0a1e58SJeff Roberson u8 hop_limit;
696aa0a1e58SJeff Roberson u8 traffic_class;
697aa0a1e58SJeff Roberson };
698aa0a1e58SJeff Roberson
699aa0a1e58SJeff Roberson struct ib_grh {
700aa0a1e58SJeff Roberson __be32 version_tclass_flow;
701aa0a1e58SJeff Roberson __be16 paylen;
702aa0a1e58SJeff Roberson u8 next_hdr;
703aa0a1e58SJeff Roberson u8 hop_limit;
704aa0a1e58SJeff Roberson union ib_gid sgid;
705aa0a1e58SJeff Roberson union ib_gid dgid;
706aa0a1e58SJeff Roberson };
707aa0a1e58SJeff Roberson
708478d3005SHans Petter Selasky union rdma_network_hdr {
709478d3005SHans Petter Selasky struct ib_grh ibgrh;
710478d3005SHans Petter Selasky struct {
711478d3005SHans Petter Selasky /* The IB spec states that if it's IPv4, the header
712478d3005SHans Petter Selasky * is located in the last 20 bytes of the header.
713478d3005SHans Petter Selasky */
714478d3005SHans Petter Selasky u8 reserved[20];
715478d3005SHans Petter Selasky struct ip roce4grh;
716478d3005SHans Petter Selasky };
717478d3005SHans Petter Selasky };
718478d3005SHans Petter Selasky
719aa0a1e58SJeff Roberson enum {
720aa0a1e58SJeff Roberson IB_MULTICAST_QPN = 0xffffff
721aa0a1e58SJeff Roberson };
722aa0a1e58SJeff Roberson
723aa0a1e58SJeff Roberson #define IB_LID_PERMISSIVE cpu_to_be16(0xFFFF)
724478d3005SHans Petter Selasky #define IB_MULTICAST_LID_BASE cpu_to_be16(0xC000)
725aa0a1e58SJeff Roberson
726aa0a1e58SJeff Roberson enum ib_ah_flags {
727aa0a1e58SJeff Roberson IB_AH_GRH = 1
728aa0a1e58SJeff Roberson };
729aa0a1e58SJeff Roberson
730aa0a1e58SJeff Roberson enum ib_rate {
731aa0a1e58SJeff Roberson IB_RATE_PORT_CURRENT = 0,
732aa0a1e58SJeff Roberson IB_RATE_2_5_GBPS = 2,
733aa0a1e58SJeff Roberson IB_RATE_5_GBPS = 5,
734aa0a1e58SJeff Roberson IB_RATE_10_GBPS = 3,
735aa0a1e58SJeff Roberson IB_RATE_20_GBPS = 6,
736aa0a1e58SJeff Roberson IB_RATE_30_GBPS = 4,
737aa0a1e58SJeff Roberson IB_RATE_40_GBPS = 7,
738aa0a1e58SJeff Roberson IB_RATE_60_GBPS = 8,
739aa0a1e58SJeff Roberson IB_RATE_80_GBPS = 9,
740c9f432b7SAlfred Perlstein IB_RATE_120_GBPS = 10,
741c9f432b7SAlfred Perlstein IB_RATE_14_GBPS = 11,
742c9f432b7SAlfred Perlstein IB_RATE_56_GBPS = 12,
743c9f432b7SAlfred Perlstein IB_RATE_112_GBPS = 13,
744c9f432b7SAlfred Perlstein IB_RATE_168_GBPS = 14,
745c9f432b7SAlfred Perlstein IB_RATE_25_GBPS = 15,
746c9f432b7SAlfred Perlstein IB_RATE_100_GBPS = 16,
747c9f432b7SAlfred Perlstein IB_RATE_200_GBPS = 17,
748013f1e14SHans Petter Selasky IB_RATE_300_GBPS = 18,
749013f1e14SHans Petter Selasky IB_RATE_28_GBPS = 19,
750013f1e14SHans Petter Selasky IB_RATE_50_GBPS = 20,
751013f1e14SHans Petter Selasky IB_RATE_400_GBPS = 21,
752013f1e14SHans Petter Selasky IB_RATE_600_GBPS = 22,
753aa0a1e58SJeff Roberson };
754aa0a1e58SJeff Roberson
755aa0a1e58SJeff Roberson /**
756aa0a1e58SJeff Roberson * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
757aa0a1e58SJeff Roberson * base rate of 2.5 Gbit/sec. For example, IB_RATE_5_GBPS will be
758aa0a1e58SJeff Roberson * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
759aa0a1e58SJeff Roberson * @rate: rate to convert.
760aa0a1e58SJeff Roberson */
761478d3005SHans Petter Selasky __attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
762aa0a1e58SJeff Roberson
763aa0a1e58SJeff Roberson /**
764c9f432b7SAlfred Perlstein * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
765c9f432b7SAlfred Perlstein * For example, IB_RATE_2_5_GBPS will be converted to 2500.
766c9f432b7SAlfred Perlstein * @rate: rate to convert.
767c9f432b7SAlfred Perlstein */
768478d3005SHans Petter Selasky __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
769c9f432b7SAlfred Perlstein
770b5c1e0cbSHans Petter Selasky
771478d3005SHans Petter Selasky /**
772478d3005SHans Petter Selasky * enum ib_mr_type - memory region type
773478d3005SHans Petter Selasky * @IB_MR_TYPE_MEM_REG: memory region that is used for
774478d3005SHans Petter Selasky * normal registration
775478d3005SHans Petter Selasky * @IB_MR_TYPE_SG_GAPS: memory region that is capable to
776478d3005SHans Petter Selasky * register any arbitrary sg lists (without
777478d3005SHans Petter Selasky * the normal mr constraints - see
778478d3005SHans Petter Selasky * ib_map_mr_sg)
779b633e08cSHans Petter Selasky * @IB_MR_TYPE_DM: memory region that is used for device
780b633e08cSHans Petter Selasky * memory registration
781b633e08cSHans Petter Selasky * @IB_MR_TYPE_USER: memory region that is used for the user-space
782b633e08cSHans Petter Selasky * application
783b633e08cSHans Petter Selasky * @IB_MR_TYPE_DMA: memory region that is used for DMA operations
784b633e08cSHans Petter Selasky * without address translations (VA=PA)
785b633e08cSHans Petter Selasky * @IB_MR_TYPE_INTEGRITY: memory region that is used for
786b633e08cSHans Petter Selasky * data integrity operations
787478d3005SHans Petter Selasky */
788478d3005SHans Petter Selasky enum ib_mr_type {
789478d3005SHans Petter Selasky IB_MR_TYPE_MEM_REG,
790478d3005SHans Petter Selasky IB_MR_TYPE_SG_GAPS,
791b633e08cSHans Petter Selasky IB_MR_TYPE_DM,
792b633e08cSHans Petter Selasky IB_MR_TYPE_USER,
793b633e08cSHans Petter Selasky IB_MR_TYPE_DMA,
794b633e08cSHans Petter Selasky IB_MR_TYPE_INTEGRITY,
795b5c1e0cbSHans Petter Selasky };
796b5c1e0cbSHans Petter Selasky
797b5c1e0cbSHans Petter Selasky enum ib_mr_status_check {
798b5c1e0cbSHans Petter Selasky IB_MR_CHECK_SIG_STATUS = 1,
799b5c1e0cbSHans Petter Selasky };
800b5c1e0cbSHans Petter Selasky
801b5c1e0cbSHans Petter Selasky /**
802b5c1e0cbSHans Petter Selasky * struct ib_mr_status - Memory region status container
803b5c1e0cbSHans Petter Selasky *
804b5c1e0cbSHans Petter Selasky * @fail_status: Bitmask of MR checks status. For each
805b5c1e0cbSHans Petter Selasky * failed check a corresponding status bit is set.
806b5c1e0cbSHans Petter Selasky * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
807b5c1e0cbSHans Petter Selasky * failure.
808b5c1e0cbSHans Petter Selasky */
809b5c1e0cbSHans Petter Selasky struct ib_mr_status {
810b5c1e0cbSHans Petter Selasky u32 fail_status;
811b5c1e0cbSHans Petter Selasky struct ib_sig_err sig_err;
812b5c1e0cbSHans Petter Selasky };
813b5c1e0cbSHans Petter Selasky
814c9f432b7SAlfred Perlstein /**
815aa0a1e58SJeff Roberson * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
816aa0a1e58SJeff Roberson * enum.
817aa0a1e58SJeff Roberson * @mult: multiple to convert.
818aa0a1e58SJeff Roberson */
819478d3005SHans Petter Selasky __attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
820aa0a1e58SJeff Roberson
821aa0a1e58SJeff Roberson struct ib_ah_attr {
822aa0a1e58SJeff Roberson struct ib_global_route grh;
823aa0a1e58SJeff Roberson u16 dlid;
824aa0a1e58SJeff Roberson u8 sl;
825aa0a1e58SJeff Roberson u8 src_path_bits;
826aa0a1e58SJeff Roberson u8 static_rate;
827aa0a1e58SJeff Roberson u8 ah_flags;
828aa0a1e58SJeff Roberson u8 port_num;
829478d3005SHans Petter Selasky u8 dmac[ETH_ALEN];
830aa0a1e58SJeff Roberson };
831aa0a1e58SJeff Roberson
832aa0a1e58SJeff Roberson enum ib_wc_status {
833aa0a1e58SJeff Roberson IB_WC_SUCCESS,
834aa0a1e58SJeff Roberson IB_WC_LOC_LEN_ERR,
835aa0a1e58SJeff Roberson IB_WC_LOC_QP_OP_ERR,
836aa0a1e58SJeff Roberson IB_WC_LOC_EEC_OP_ERR,
837aa0a1e58SJeff Roberson IB_WC_LOC_PROT_ERR,
838aa0a1e58SJeff Roberson IB_WC_WR_FLUSH_ERR,
839aa0a1e58SJeff Roberson IB_WC_MW_BIND_ERR,
840aa0a1e58SJeff Roberson IB_WC_BAD_RESP_ERR,
841aa0a1e58SJeff Roberson IB_WC_LOC_ACCESS_ERR,
842aa0a1e58SJeff Roberson IB_WC_REM_INV_REQ_ERR,
843aa0a1e58SJeff Roberson IB_WC_REM_ACCESS_ERR,
844aa0a1e58SJeff Roberson IB_WC_REM_OP_ERR,
845aa0a1e58SJeff Roberson IB_WC_RETRY_EXC_ERR,
846aa0a1e58SJeff Roberson IB_WC_RNR_RETRY_EXC_ERR,
847aa0a1e58SJeff Roberson IB_WC_LOC_RDD_VIOL_ERR,
848aa0a1e58SJeff Roberson IB_WC_REM_INV_RD_REQ_ERR,
849aa0a1e58SJeff Roberson IB_WC_REM_ABORT_ERR,
850aa0a1e58SJeff Roberson IB_WC_INV_EECN_ERR,
851aa0a1e58SJeff Roberson IB_WC_INV_EEC_STATE_ERR,
852aa0a1e58SJeff Roberson IB_WC_FATAL_ERR,
853aa0a1e58SJeff Roberson IB_WC_RESP_TIMEOUT_ERR,
854aa0a1e58SJeff Roberson IB_WC_GENERAL_ERR
855aa0a1e58SJeff Roberson };
856aa0a1e58SJeff Roberson
857478d3005SHans Petter Selasky const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
858478d3005SHans Petter Selasky
859aa0a1e58SJeff Roberson enum ib_wc_opcode {
860aa0a1e58SJeff Roberson IB_WC_SEND,
861aa0a1e58SJeff Roberson IB_WC_RDMA_WRITE,
862aa0a1e58SJeff Roberson IB_WC_RDMA_READ,
863aa0a1e58SJeff Roberson IB_WC_COMP_SWAP,
864aa0a1e58SJeff Roberson IB_WC_FETCH_ADD,
865aa0a1e58SJeff Roberson IB_WC_LSO,
866aa0a1e58SJeff Roberson IB_WC_LOCAL_INV,
867478d3005SHans Petter Selasky IB_WC_REG_MR,
868aa0a1e58SJeff Roberson IB_WC_MASKED_COMP_SWAP,
869aa0a1e58SJeff Roberson IB_WC_MASKED_FETCH_ADD,
870aa0a1e58SJeff Roberson /*
871aa0a1e58SJeff Roberson * Set value of IB_WC_RECV so consumers can test if a completion is a
872aa0a1e58SJeff Roberson * receive by testing (opcode & IB_WC_RECV).
873aa0a1e58SJeff Roberson */
874aa0a1e58SJeff Roberson IB_WC_RECV = 1 << 7,
875478d3005SHans Petter Selasky IB_WC_RECV_RDMA_WITH_IMM,
876478d3005SHans Petter Selasky IB_WC_DUMMY = -1, /* force enum signed */
877aa0a1e58SJeff Roberson };
878aa0a1e58SJeff Roberson
879aa0a1e58SJeff Roberson enum ib_wc_flags {
880aa0a1e58SJeff Roberson IB_WC_GRH = 1,
881aa0a1e58SJeff Roberson IB_WC_WITH_IMM = (1<<1),
882aa0a1e58SJeff Roberson IB_WC_WITH_INVALIDATE = (1<<2),
883c9f432b7SAlfred Perlstein IB_WC_IP_CSUM_OK = (1<<3),
884478d3005SHans Petter Selasky IB_WC_WITH_SMAC = (1<<4),
885478d3005SHans Petter Selasky IB_WC_WITH_VLAN = (1<<5),
886478d3005SHans Petter Selasky IB_WC_WITH_NETWORK_HDR_TYPE = (1<<6),
887aa0a1e58SJeff Roberson };
888aa0a1e58SJeff Roberson
889aa0a1e58SJeff Roberson struct ib_wc {
890478d3005SHans Petter Selasky union {
891aa0a1e58SJeff Roberson u64 wr_id;
892478d3005SHans Petter Selasky struct ib_cqe *wr_cqe;
893478d3005SHans Petter Selasky };
894aa0a1e58SJeff Roberson enum ib_wc_status status;
895aa0a1e58SJeff Roberson enum ib_wc_opcode opcode;
896aa0a1e58SJeff Roberson u32 vendor_err;
897aa0a1e58SJeff Roberson u32 byte_len;
898aa0a1e58SJeff Roberson struct ib_qp *qp;
899aa0a1e58SJeff Roberson union {
900aa0a1e58SJeff Roberson __be32 imm_data;
901aa0a1e58SJeff Roberson u32 invalidate_rkey;
902aa0a1e58SJeff Roberson } ex;
903aa0a1e58SJeff Roberson u32 src_qp;
904aa0a1e58SJeff Roberson int wc_flags;
905aa0a1e58SJeff Roberson u16 pkey_index;
906aa0a1e58SJeff Roberson u16 slid;
907aa0a1e58SJeff Roberson u8 sl;
908aa0a1e58SJeff Roberson u8 dlid_path_bits;
909aa0a1e58SJeff Roberson u8 port_num; /* valid only for DR SMPs on switches */
910478d3005SHans Petter Selasky u8 smac[ETH_ALEN];
911b5c1e0cbSHans Petter Selasky u16 vlan_id;
912478d3005SHans Petter Selasky u8 network_hdr_type;
913aa0a1e58SJeff Roberson };
914aa0a1e58SJeff Roberson
915aa0a1e58SJeff Roberson enum ib_cq_notify_flags {
916aa0a1e58SJeff Roberson IB_CQ_SOLICITED = 1 << 0,
917aa0a1e58SJeff Roberson IB_CQ_NEXT_COMP = 1 << 1,
918aa0a1e58SJeff Roberson IB_CQ_SOLICITED_MASK = IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
919aa0a1e58SJeff Roberson IB_CQ_REPORT_MISSED_EVENTS = 1 << 2,
920aa0a1e58SJeff Roberson };
921aa0a1e58SJeff Roberson
922c9f432b7SAlfred Perlstein enum ib_srq_type {
923c9f432b7SAlfred Perlstein IB_SRQT_BASIC,
924b633e08cSHans Petter Selasky IB_SRQT_XRC,
925b633e08cSHans Petter Selasky IB_SRQT_TM,
926c9f432b7SAlfred Perlstein };
927c9f432b7SAlfred Perlstein
ib_srq_has_cq(enum ib_srq_type srq_type)928b633e08cSHans Petter Selasky static inline bool ib_srq_has_cq(enum ib_srq_type srq_type)
929b633e08cSHans Petter Selasky {
930b633e08cSHans Petter Selasky return srq_type == IB_SRQT_XRC ||
931b633e08cSHans Petter Selasky srq_type == IB_SRQT_TM;
932b633e08cSHans Petter Selasky }
933b633e08cSHans Petter Selasky
934aa0a1e58SJeff Roberson enum ib_srq_attr_mask {
935aa0a1e58SJeff Roberson IB_SRQ_MAX_WR = 1 << 0,
936aa0a1e58SJeff Roberson IB_SRQ_LIMIT = 1 << 1,
937aa0a1e58SJeff Roberson };
938aa0a1e58SJeff Roberson
939aa0a1e58SJeff Roberson struct ib_srq_attr {
940aa0a1e58SJeff Roberson u32 max_wr;
941aa0a1e58SJeff Roberson u32 max_sge;
942aa0a1e58SJeff Roberson u32 srq_limit;
943aa0a1e58SJeff Roberson };
944aa0a1e58SJeff Roberson
945aa0a1e58SJeff Roberson struct ib_srq_init_attr {
946aa0a1e58SJeff Roberson void (*event_handler)(struct ib_event *, void *);
947aa0a1e58SJeff Roberson void *srq_context;
948aa0a1e58SJeff Roberson struct ib_srq_attr attr;
949c9f432b7SAlfred Perlstein enum ib_srq_type srq_type;
950c9f432b7SAlfred Perlstein
951b633e08cSHans Petter Selasky struct {
952b633e08cSHans Petter Selasky struct ib_cq *cq;
953c9f432b7SAlfred Perlstein union {
954c9f432b7SAlfred Perlstein struct {
955c9f432b7SAlfred Perlstein struct ib_xrcd *xrcd;
956c9f432b7SAlfred Perlstein } xrc;
957b633e08cSHans Petter Selasky
958b633e08cSHans Petter Selasky struct {
959b633e08cSHans Petter Selasky u32 max_num_tags;
960b633e08cSHans Petter Selasky } tag_matching;
961b633e08cSHans Petter Selasky };
962c9f432b7SAlfred Perlstein } ext;
963aa0a1e58SJeff Roberson };
964aa0a1e58SJeff Roberson
965aa0a1e58SJeff Roberson struct ib_qp_cap {
966aa0a1e58SJeff Roberson u32 max_send_wr;
967aa0a1e58SJeff Roberson u32 max_recv_wr;
968aa0a1e58SJeff Roberson u32 max_send_sge;
969aa0a1e58SJeff Roberson u32 max_recv_sge;
970aa0a1e58SJeff Roberson u32 max_inline_data;
971478d3005SHans Petter Selasky
972478d3005SHans Petter Selasky /*
973478d3005SHans Petter Selasky * Maximum number of rdma_rw_ctx structures in flight at a time.
974478d3005SHans Petter Selasky * ib_create_qp() will calculate the right amount of neededed WRs
975478d3005SHans Petter Selasky * and MRs based on this.
976478d3005SHans Petter Selasky */
977478d3005SHans Petter Selasky u32 max_rdma_ctxs;
978aa0a1e58SJeff Roberson };
979aa0a1e58SJeff Roberson
980aa0a1e58SJeff Roberson enum ib_sig_type {
981aa0a1e58SJeff Roberson IB_SIGNAL_ALL_WR,
982aa0a1e58SJeff Roberson IB_SIGNAL_REQ_WR
983aa0a1e58SJeff Roberson };
984aa0a1e58SJeff Roberson
985aa0a1e58SJeff Roberson enum ib_qp_type {
986aa0a1e58SJeff Roberson /*
987aa0a1e58SJeff Roberson * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
988aa0a1e58SJeff Roberson * here (and in that order) since the MAD layer uses them as
989aa0a1e58SJeff Roberson * indices into a 2-entry table.
990aa0a1e58SJeff Roberson */
991aa0a1e58SJeff Roberson IB_QPT_SMI,
992aa0a1e58SJeff Roberson IB_QPT_GSI,
993aa0a1e58SJeff Roberson
994aa0a1e58SJeff Roberson IB_QPT_RC,
995aa0a1e58SJeff Roberson IB_QPT_UC,
996aa0a1e58SJeff Roberson IB_QPT_UD,
997aa0a1e58SJeff Roberson IB_QPT_RAW_IPV6,
998c9f432b7SAlfred Perlstein IB_QPT_RAW_ETHERTYPE,
999c9f432b7SAlfred Perlstein IB_QPT_RAW_PACKET = 8,
1000c9f432b7SAlfred Perlstein IB_QPT_XRC_INI = 9,
1001c9f432b7SAlfred Perlstein IB_QPT_XRC_TGT,
1002c9f432b7SAlfred Perlstein IB_QPT_MAX,
1003b633e08cSHans Petter Selasky IB_QPT_DRIVER = 0xFF,
1004b5c1e0cbSHans Petter Selasky /* Reserve a range for qp types internal to the low level driver.
1005b5c1e0cbSHans Petter Selasky * These qp types will not be visible at the IB core layer, so the
1006b5c1e0cbSHans Petter Selasky * IB_QPT_MAX usages should not be affected in the core layer
1007b5c1e0cbSHans Petter Selasky */
1008b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED1 = 0x1000,
1009b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED2,
1010b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED3,
1011b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED4,
1012b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED5,
1013b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED6,
1014b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED7,
1015b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED8,
1016b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED9,
1017b5c1e0cbSHans Petter Selasky IB_QPT_RESERVED10,
1018aa0a1e58SJeff Roberson };
1019aa0a1e58SJeff Roberson
1020aa0a1e58SJeff Roberson enum ib_qp_create_flags {
1021aa0a1e58SJeff Roberson IB_QP_CREATE_IPOIB_UD_LSO = 1 << 0,
1022aa0a1e58SJeff Roberson IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
1023b5c1e0cbSHans Petter Selasky IB_QP_CREATE_CROSS_CHANNEL = 1 << 2,
1024b5c1e0cbSHans Petter Selasky IB_QP_CREATE_MANAGED_SEND = 1 << 3,
1025b5c1e0cbSHans Petter Selasky IB_QP_CREATE_MANAGED_RECV = 1 << 4,
1026b5c1e0cbSHans Petter Selasky IB_QP_CREATE_NETIF_QP = 1 << 5,
1027b5c1e0cbSHans Petter Selasky IB_QP_CREATE_SIGNATURE_EN = 1 << 6,
1028478d3005SHans Petter Selasky IB_QP_CREATE_USE_GFP_NOIO = 1 << 7,
1029478d3005SHans Petter Selasky IB_QP_CREATE_SCATTER_FCS = 1 << 8,
1030b633e08cSHans Petter Selasky IB_QP_CREATE_CVLAN_STRIPPING = 1 << 9,
1031b633e08cSHans Petter Selasky IB_QP_CREATE_SOURCE_QPN = 1 << 10,
1032b633e08cSHans Petter Selasky IB_QP_CREATE_PCI_WRITE_END_PADDING = 1 << 11,
1033c9f432b7SAlfred Perlstein /* reserve bits 26-31 for low level drivers' internal use */
1034c9f432b7SAlfred Perlstein IB_QP_CREATE_RESERVED_START = 1 << 26,
1035c9f432b7SAlfred Perlstein IB_QP_CREATE_RESERVED_END = 1 << 31,
1036c9f432b7SAlfred Perlstein };
1037c9f432b7SAlfred Perlstein
1038478d3005SHans Petter Selasky /*
1039478d3005SHans Petter Selasky * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
1040478d3005SHans Petter Selasky * callback to destroy the passed in QP.
1041478d3005SHans Petter Selasky */
1042aa0a1e58SJeff Roberson
1043aa0a1e58SJeff Roberson struct ib_qp_init_attr {
1044aa0a1e58SJeff Roberson void (*event_handler)(struct ib_event *, void *);
1045aa0a1e58SJeff Roberson void *qp_context;
1046aa0a1e58SJeff Roberson struct ib_cq *send_cq;
1047aa0a1e58SJeff Roberson struct ib_cq *recv_cq;
1048aa0a1e58SJeff Roberson struct ib_srq *srq;
1049c9f432b7SAlfred Perlstein struct ib_xrcd *xrcd; /* XRC TGT QPs only */
1050aa0a1e58SJeff Roberson struct ib_qp_cap cap;
1051aa0a1e58SJeff Roberson enum ib_sig_type sq_sig_type;
1052aa0a1e58SJeff Roberson enum ib_qp_type qp_type;
1053aa0a1e58SJeff Roberson enum ib_qp_create_flags create_flags;
1054aa0a1e58SJeff Roberson
1055478d3005SHans Petter Selasky /*
1056478d3005SHans Petter Selasky * Only needed for special QP types, or when using the RW API.
1057478d3005SHans Petter Selasky */
1058478d3005SHans Petter Selasky u8 port_num;
1059478d3005SHans Petter Selasky struct ib_rwq_ind_table *rwq_ind_tbl;
1060b633e08cSHans Petter Selasky u32 source_qpn;
1061b5c1e0cbSHans Petter Selasky };
1062b5c1e0cbSHans Petter Selasky
1063c9f432b7SAlfred Perlstein struct ib_qp_open_attr {
1064c9f432b7SAlfred Perlstein void (*event_handler)(struct ib_event *, void *);
1065c9f432b7SAlfred Perlstein void *qp_context;
1066c9f432b7SAlfred Perlstein u32 qp_num;
1067c9f432b7SAlfred Perlstein enum ib_qp_type qp_type;
1068c9f432b7SAlfred Perlstein };
1069c9f432b7SAlfred Perlstein
1070aa0a1e58SJeff Roberson enum ib_rnr_timeout {
1071aa0a1e58SJeff Roberson IB_RNR_TIMER_655_36 = 0,
1072aa0a1e58SJeff Roberson IB_RNR_TIMER_000_01 = 1,
1073aa0a1e58SJeff Roberson IB_RNR_TIMER_000_02 = 2,
1074aa0a1e58SJeff Roberson IB_RNR_TIMER_000_03 = 3,
1075aa0a1e58SJeff Roberson IB_RNR_TIMER_000_04 = 4,
1076aa0a1e58SJeff Roberson IB_RNR_TIMER_000_06 = 5,
1077aa0a1e58SJeff Roberson IB_RNR_TIMER_000_08 = 6,
1078aa0a1e58SJeff Roberson IB_RNR_TIMER_000_12 = 7,
1079aa0a1e58SJeff Roberson IB_RNR_TIMER_000_16 = 8,
1080aa0a1e58SJeff Roberson IB_RNR_TIMER_000_24 = 9,
1081aa0a1e58SJeff Roberson IB_RNR_TIMER_000_32 = 10,
1082aa0a1e58SJeff Roberson IB_RNR_TIMER_000_48 = 11,
1083aa0a1e58SJeff Roberson IB_RNR_TIMER_000_64 = 12,
1084aa0a1e58SJeff Roberson IB_RNR_TIMER_000_96 = 13,
1085aa0a1e58SJeff Roberson IB_RNR_TIMER_001_28 = 14,
1086aa0a1e58SJeff Roberson IB_RNR_TIMER_001_92 = 15,
1087aa0a1e58SJeff Roberson IB_RNR_TIMER_002_56 = 16,
1088aa0a1e58SJeff Roberson IB_RNR_TIMER_003_84 = 17,
1089aa0a1e58SJeff Roberson IB_RNR_TIMER_005_12 = 18,
1090aa0a1e58SJeff Roberson IB_RNR_TIMER_007_68 = 19,
1091aa0a1e58SJeff Roberson IB_RNR_TIMER_010_24 = 20,
1092aa0a1e58SJeff Roberson IB_RNR_TIMER_015_36 = 21,
1093aa0a1e58SJeff Roberson IB_RNR_TIMER_020_48 = 22,
1094aa0a1e58SJeff Roberson IB_RNR_TIMER_030_72 = 23,
1095aa0a1e58SJeff Roberson IB_RNR_TIMER_040_96 = 24,
1096aa0a1e58SJeff Roberson IB_RNR_TIMER_061_44 = 25,
1097aa0a1e58SJeff Roberson IB_RNR_TIMER_081_92 = 26,
1098aa0a1e58SJeff Roberson IB_RNR_TIMER_122_88 = 27,
1099aa0a1e58SJeff Roberson IB_RNR_TIMER_163_84 = 28,
1100aa0a1e58SJeff Roberson IB_RNR_TIMER_245_76 = 29,
1101aa0a1e58SJeff Roberson IB_RNR_TIMER_327_68 = 30,
1102aa0a1e58SJeff Roberson IB_RNR_TIMER_491_52 = 31
1103aa0a1e58SJeff Roberson };
1104aa0a1e58SJeff Roberson
1105aa0a1e58SJeff Roberson enum ib_qp_attr_mask {
1106aa0a1e58SJeff Roberson IB_QP_STATE = 1,
1107aa0a1e58SJeff Roberson IB_QP_CUR_STATE = (1<<1),
1108aa0a1e58SJeff Roberson IB_QP_EN_SQD_ASYNC_NOTIFY = (1<<2),
1109aa0a1e58SJeff Roberson IB_QP_ACCESS_FLAGS = (1<<3),
1110aa0a1e58SJeff Roberson IB_QP_PKEY_INDEX = (1<<4),
1111aa0a1e58SJeff Roberson IB_QP_PORT = (1<<5),
1112aa0a1e58SJeff Roberson IB_QP_QKEY = (1<<6),
1113aa0a1e58SJeff Roberson IB_QP_AV = (1<<7),
1114aa0a1e58SJeff Roberson IB_QP_PATH_MTU = (1<<8),
1115aa0a1e58SJeff Roberson IB_QP_TIMEOUT = (1<<9),
1116aa0a1e58SJeff Roberson IB_QP_RETRY_CNT = (1<<10),
1117aa0a1e58SJeff Roberson IB_QP_RNR_RETRY = (1<<11),
1118aa0a1e58SJeff Roberson IB_QP_RQ_PSN = (1<<12),
1119aa0a1e58SJeff Roberson IB_QP_MAX_QP_RD_ATOMIC = (1<<13),
1120aa0a1e58SJeff Roberson IB_QP_ALT_PATH = (1<<14),
1121aa0a1e58SJeff Roberson IB_QP_MIN_RNR_TIMER = (1<<15),
1122aa0a1e58SJeff Roberson IB_QP_SQ_PSN = (1<<16),
1123aa0a1e58SJeff Roberson IB_QP_MAX_DEST_RD_ATOMIC = (1<<17),
1124aa0a1e58SJeff Roberson IB_QP_PATH_MIG_STATE = (1<<18),
1125aa0a1e58SJeff Roberson IB_QP_CAP = (1<<19),
1126c9f432b7SAlfred Perlstein IB_QP_DEST_QPN = (1<<20),
1127478d3005SHans Petter Selasky IB_QP_RESERVED1 = (1<<21),
1128478d3005SHans Petter Selasky IB_QP_RESERVED2 = (1<<22),
1129478d3005SHans Petter Selasky IB_QP_RESERVED3 = (1<<23),
1130478d3005SHans Petter Selasky IB_QP_RESERVED4 = (1<<24),
11310c13880cSHans Petter Selasky IB_QP_RATE_LIMIT = (1<<25),
1132aa0a1e58SJeff Roberson };
1133aa0a1e58SJeff Roberson
1134aa0a1e58SJeff Roberson enum ib_qp_state {
1135aa0a1e58SJeff Roberson IB_QPS_RESET,
1136aa0a1e58SJeff Roberson IB_QPS_INIT,
1137aa0a1e58SJeff Roberson IB_QPS_RTR,
1138aa0a1e58SJeff Roberson IB_QPS_RTS,
1139aa0a1e58SJeff Roberson IB_QPS_SQD,
1140aa0a1e58SJeff Roberson IB_QPS_SQE,
1141b5c1e0cbSHans Petter Selasky IB_QPS_ERR,
1142478d3005SHans Petter Selasky IB_QPS_DUMMY = -1, /* force enum signed */
1143aa0a1e58SJeff Roberson };
1144aa0a1e58SJeff Roberson
1145aa0a1e58SJeff Roberson enum ib_mig_state {
1146aa0a1e58SJeff Roberson IB_MIG_MIGRATED,
1147aa0a1e58SJeff Roberson IB_MIG_REARM,
1148aa0a1e58SJeff Roberson IB_MIG_ARMED
1149aa0a1e58SJeff Roberson };
1150aa0a1e58SJeff Roberson
1151b5c1e0cbSHans Petter Selasky enum ib_mw_type {
1152b5c1e0cbSHans Petter Selasky IB_MW_TYPE_1 = 1,
1153b5c1e0cbSHans Petter Selasky IB_MW_TYPE_2 = 2
1154b5c1e0cbSHans Petter Selasky };
1155b5c1e0cbSHans Petter Selasky
1156aa0a1e58SJeff Roberson struct ib_qp_attr {
1157aa0a1e58SJeff Roberson enum ib_qp_state qp_state;
1158aa0a1e58SJeff Roberson enum ib_qp_state cur_qp_state;
1159aa0a1e58SJeff Roberson enum ib_mtu path_mtu;
1160aa0a1e58SJeff Roberson enum ib_mig_state path_mig_state;
1161aa0a1e58SJeff Roberson u32 qkey;
1162aa0a1e58SJeff Roberson u32 rq_psn;
1163aa0a1e58SJeff Roberson u32 sq_psn;
1164aa0a1e58SJeff Roberson u32 dest_qp_num;
1165aa0a1e58SJeff Roberson int qp_access_flags;
1166aa0a1e58SJeff Roberson struct ib_qp_cap cap;
1167aa0a1e58SJeff Roberson struct ib_ah_attr ah_attr;
1168aa0a1e58SJeff Roberson struct ib_ah_attr alt_ah_attr;
1169aa0a1e58SJeff Roberson u16 pkey_index;
1170aa0a1e58SJeff Roberson u16 alt_pkey_index;
1171aa0a1e58SJeff Roberson u8 en_sqd_async_notify;
1172aa0a1e58SJeff Roberson u8 sq_draining;
1173aa0a1e58SJeff Roberson u8 max_rd_atomic;
1174aa0a1e58SJeff Roberson u8 max_dest_rd_atomic;
1175aa0a1e58SJeff Roberson u8 min_rnr_timer;
1176aa0a1e58SJeff Roberson u8 port_num;
1177aa0a1e58SJeff Roberson u8 timeout;
1178aa0a1e58SJeff Roberson u8 retry_cnt;
1179aa0a1e58SJeff Roberson u8 rnr_retry;
1180aa0a1e58SJeff Roberson u8 alt_port_num;
1181aa0a1e58SJeff Roberson u8 alt_timeout;
11820c13880cSHans Petter Selasky u32 rate_limit;
1183aa0a1e58SJeff Roberson };
1184aa0a1e58SJeff Roberson
1185aa0a1e58SJeff Roberson enum ib_wr_opcode {
1186aa0a1e58SJeff Roberson IB_WR_RDMA_WRITE,
1187aa0a1e58SJeff Roberson IB_WR_RDMA_WRITE_WITH_IMM,
1188aa0a1e58SJeff Roberson IB_WR_SEND,
1189aa0a1e58SJeff Roberson IB_WR_SEND_WITH_IMM,
1190aa0a1e58SJeff Roberson IB_WR_RDMA_READ,
1191aa0a1e58SJeff Roberson IB_WR_ATOMIC_CMP_AND_SWP,
1192aa0a1e58SJeff Roberson IB_WR_ATOMIC_FETCH_AND_ADD,
1193aa0a1e58SJeff Roberson IB_WR_LSO,
1194aa0a1e58SJeff Roberson IB_WR_SEND_WITH_INV,
1195aa0a1e58SJeff Roberson IB_WR_RDMA_READ_WITH_INV,
1196aa0a1e58SJeff Roberson IB_WR_LOCAL_INV,
1197478d3005SHans Petter Selasky IB_WR_REG_MR,
1198aa0a1e58SJeff Roberson IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
1199aa0a1e58SJeff Roberson IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
1200b5c1e0cbSHans Petter Selasky IB_WR_REG_SIG_MR,
1201b5c1e0cbSHans Petter Selasky /* reserve values for low level drivers' internal use.
1202b5c1e0cbSHans Petter Selasky * These values will not be used at all in the ib core layer.
1203b5c1e0cbSHans Petter Selasky */
1204b5c1e0cbSHans Petter Selasky IB_WR_RESERVED1 = 0xf0,
1205b5c1e0cbSHans Petter Selasky IB_WR_RESERVED2,
1206b5c1e0cbSHans Petter Selasky IB_WR_RESERVED3,
1207b5c1e0cbSHans Petter Selasky IB_WR_RESERVED4,
1208b5c1e0cbSHans Petter Selasky IB_WR_RESERVED5,
1209b5c1e0cbSHans Petter Selasky IB_WR_RESERVED6,
1210b5c1e0cbSHans Petter Selasky IB_WR_RESERVED7,
1211b5c1e0cbSHans Petter Selasky IB_WR_RESERVED8,
1212b5c1e0cbSHans Petter Selasky IB_WR_RESERVED9,
1213b5c1e0cbSHans Petter Selasky IB_WR_RESERVED10,
1214478d3005SHans Petter Selasky IB_WR_DUMMY = -1, /* force enum signed */
1215aa0a1e58SJeff Roberson };
1216aa0a1e58SJeff Roberson
1217aa0a1e58SJeff Roberson enum ib_send_flags {
1218aa0a1e58SJeff Roberson IB_SEND_FENCE = 1,
1219aa0a1e58SJeff Roberson IB_SEND_SIGNALED = (1<<1),
1220aa0a1e58SJeff Roberson IB_SEND_SOLICITED = (1<<2),
1221aa0a1e58SJeff Roberson IB_SEND_INLINE = (1<<3),
1222b5c1e0cbSHans Petter Selasky IB_SEND_IP_CSUM = (1<<4),
1223aa0a1e58SJeff Roberson
1224b5c1e0cbSHans Petter Selasky /* reserve bits 26-31 for low level drivers' internal use */
1225b5c1e0cbSHans Petter Selasky IB_SEND_RESERVED_START = (1 << 26),
1226b5c1e0cbSHans Petter Selasky IB_SEND_RESERVED_END = (1 << 31),
1227c9f432b7SAlfred Perlstein };
1228c9f432b7SAlfred Perlstein
1229aa0a1e58SJeff Roberson struct ib_sge {
1230aa0a1e58SJeff Roberson u64 addr;
1231aa0a1e58SJeff Roberson u32 length;
1232aa0a1e58SJeff Roberson u32 lkey;
1233aa0a1e58SJeff Roberson };
1234aa0a1e58SJeff Roberson
1235478d3005SHans Petter Selasky struct ib_cqe {
1236478d3005SHans Petter Selasky void (*done)(struct ib_cq *cq, struct ib_wc *wc);
1237b5c1e0cbSHans Petter Selasky };
1238b5c1e0cbSHans Petter Selasky
1239aa0a1e58SJeff Roberson struct ib_send_wr {
1240aa0a1e58SJeff Roberson struct ib_send_wr *next;
1241478d3005SHans Petter Selasky union {
1242aa0a1e58SJeff Roberson u64 wr_id;
1243478d3005SHans Petter Selasky struct ib_cqe *wr_cqe;
1244478d3005SHans Petter Selasky };
1245aa0a1e58SJeff Roberson struct ib_sge *sg_list;
1246aa0a1e58SJeff Roberson int num_sge;
1247aa0a1e58SJeff Roberson enum ib_wr_opcode opcode;
1248aa0a1e58SJeff Roberson int send_flags;
1249aa0a1e58SJeff Roberson union {
1250aa0a1e58SJeff Roberson __be32 imm_data;
1251aa0a1e58SJeff Roberson u32 invalidate_rkey;
1252aa0a1e58SJeff Roberson } ex;
1253478d3005SHans Petter Selasky };
1254478d3005SHans Petter Selasky
1255478d3005SHans Petter Selasky struct ib_rdma_wr {
1256478d3005SHans Petter Selasky struct ib_send_wr wr;
1257aa0a1e58SJeff Roberson u64 remote_addr;
1258aa0a1e58SJeff Roberson u32 rkey;
1259478d3005SHans Petter Selasky };
1260478d3005SHans Petter Selasky
rdma_wr(const struct ib_send_wr * wr)1261c3987b8eSHans Petter Selasky static inline const struct ib_rdma_wr *rdma_wr(const struct ib_send_wr *wr)
1262478d3005SHans Petter Selasky {
1263478d3005SHans Petter Selasky return container_of(wr, struct ib_rdma_wr, wr);
1264478d3005SHans Petter Selasky }
1265478d3005SHans Petter Selasky
1266478d3005SHans Petter Selasky struct ib_atomic_wr {
1267478d3005SHans Petter Selasky struct ib_send_wr wr;
1268aa0a1e58SJeff Roberson u64 remote_addr;
1269aa0a1e58SJeff Roberson u64 compare_add;
1270aa0a1e58SJeff Roberson u64 swap;
1271aa0a1e58SJeff Roberson u64 compare_add_mask;
1272aa0a1e58SJeff Roberson u64 swap_mask;
1273aa0a1e58SJeff Roberson u32 rkey;
1274478d3005SHans Petter Selasky };
1275478d3005SHans Petter Selasky
atomic_wr(const struct ib_send_wr * wr)1276c3987b8eSHans Petter Selasky static inline const struct ib_atomic_wr *atomic_wr(const struct ib_send_wr *wr)
1277478d3005SHans Petter Selasky {
1278478d3005SHans Petter Selasky return container_of(wr, struct ib_atomic_wr, wr);
1279478d3005SHans Petter Selasky }
1280478d3005SHans Petter Selasky
1281478d3005SHans Petter Selasky struct ib_ud_wr {
1282478d3005SHans Petter Selasky struct ib_send_wr wr;
1283aa0a1e58SJeff Roberson struct ib_ah *ah;
1284aa0a1e58SJeff Roberson void *header;
1285aa0a1e58SJeff Roberson int hlen;
1286aa0a1e58SJeff Roberson int mss;
1287aa0a1e58SJeff Roberson u32 remote_qpn;
1288aa0a1e58SJeff Roberson u32 remote_qkey;
1289aa0a1e58SJeff Roberson u16 pkey_index; /* valid for GSI only */
1290aa0a1e58SJeff Roberson u8 port_num; /* valid for DR SMPs on switch only */
1291478d3005SHans Petter Selasky };
1292478d3005SHans Petter Selasky
ud_wr(const struct ib_send_wr * wr)1293c3987b8eSHans Petter Selasky static inline const struct ib_ud_wr *ud_wr(const struct ib_send_wr *wr)
1294478d3005SHans Petter Selasky {
1295478d3005SHans Petter Selasky return container_of(wr, struct ib_ud_wr, wr);
1296478d3005SHans Petter Selasky }
1297478d3005SHans Petter Selasky
1298478d3005SHans Petter Selasky struct ib_reg_wr {
1299478d3005SHans Petter Selasky struct ib_send_wr wr;
1300478d3005SHans Petter Selasky struct ib_mr *mr;
1301478d3005SHans Petter Selasky u32 key;
1302478d3005SHans Petter Selasky int access;
1303478d3005SHans Petter Selasky };
1304478d3005SHans Petter Selasky
reg_wr(const struct ib_send_wr * wr)1305c3987b8eSHans Petter Selasky static inline const struct ib_reg_wr *reg_wr(const struct ib_send_wr *wr)
1306478d3005SHans Petter Selasky {
1307478d3005SHans Petter Selasky return container_of(wr, struct ib_reg_wr, wr);
1308478d3005SHans Petter Selasky }
1309478d3005SHans Petter Selasky
1310478d3005SHans Petter Selasky struct ib_sig_handover_wr {
1311478d3005SHans Petter Selasky struct ib_send_wr wr;
1312b5c1e0cbSHans Petter Selasky struct ib_sig_attrs *sig_attrs;
1313b5c1e0cbSHans Petter Selasky struct ib_mr *sig_mr;
1314b5c1e0cbSHans Petter Selasky int access_flags;
1315b5c1e0cbSHans Petter Selasky struct ib_sge *prot;
1316aa0a1e58SJeff Roberson };
1317aa0a1e58SJeff Roberson
sig_handover_wr(const struct ib_send_wr * wr)1318c3987b8eSHans Petter Selasky static inline const struct ib_sig_handover_wr *sig_handover_wr(const struct ib_send_wr *wr)
1319478d3005SHans Petter Selasky {
1320478d3005SHans Petter Selasky return container_of(wr, struct ib_sig_handover_wr, wr);
1321478d3005SHans Petter Selasky }
1322478d3005SHans Petter Selasky
1323aa0a1e58SJeff Roberson struct ib_recv_wr {
1324aa0a1e58SJeff Roberson struct ib_recv_wr *next;
1325478d3005SHans Petter Selasky union {
1326aa0a1e58SJeff Roberson u64 wr_id;
1327478d3005SHans Petter Selasky struct ib_cqe *wr_cqe;
1328478d3005SHans Petter Selasky };
1329aa0a1e58SJeff Roberson struct ib_sge *sg_list;
1330aa0a1e58SJeff Roberson int num_sge;
1331aa0a1e58SJeff Roberson };
1332aa0a1e58SJeff Roberson
1333aa0a1e58SJeff Roberson enum ib_access_flags {
1334b633e08cSHans Petter Selasky IB_ACCESS_LOCAL_WRITE = IB_UVERBS_ACCESS_LOCAL_WRITE,
1335b633e08cSHans Petter Selasky IB_ACCESS_REMOTE_WRITE = IB_UVERBS_ACCESS_REMOTE_WRITE,
1336b633e08cSHans Petter Selasky IB_ACCESS_REMOTE_READ = IB_UVERBS_ACCESS_REMOTE_READ,
1337b633e08cSHans Petter Selasky IB_ACCESS_REMOTE_ATOMIC = IB_UVERBS_ACCESS_REMOTE_ATOMIC,
1338b633e08cSHans Petter Selasky IB_ACCESS_MW_BIND = IB_UVERBS_ACCESS_MW_BIND,
1339b633e08cSHans Petter Selasky IB_ZERO_BASED = IB_UVERBS_ACCESS_ZERO_BASED,
1340b633e08cSHans Petter Selasky IB_ACCESS_ON_DEMAND = IB_UVERBS_ACCESS_ON_DEMAND,
1341b633e08cSHans Petter Selasky IB_ACCESS_HUGETLB = IB_UVERBS_ACCESS_HUGETLB,
1342b633e08cSHans Petter Selasky IB_ACCESS_RELAXED_ORDERING = IB_UVERBS_ACCESS_RELAXED_ORDERING,
1343b633e08cSHans Petter Selasky
1344b633e08cSHans Petter Selasky IB_ACCESS_OPTIONAL = IB_UVERBS_ACCESS_OPTIONAL_RANGE,
1345b633e08cSHans Petter Selasky IB_ACCESS_SUPPORTED =
1346b633e08cSHans Petter Selasky ((IB_ACCESS_HUGETLB << 1) - 1) | IB_ACCESS_OPTIONAL,
1347aa0a1e58SJeff Roberson };
1348aa0a1e58SJeff Roberson
1349478d3005SHans Petter Selasky /*
1350478d3005SHans Petter Selasky * XXX: these are apparently used for ->rereg_user_mr, no idea why they
1351478d3005SHans Petter Selasky * are hidden here instead of a uapi header!
1352478d3005SHans Petter Selasky */
1353aa0a1e58SJeff Roberson enum ib_mr_rereg_flags {
1354aa0a1e58SJeff Roberson IB_MR_REREG_TRANS = 1,
1355aa0a1e58SJeff Roberson IB_MR_REREG_PD = (1<<1),
1356478d3005SHans Petter Selasky IB_MR_REREG_ACCESS = (1<<2),
1357478d3005SHans Petter Selasky IB_MR_REREG_SUPPORTED = ((IB_MR_REREG_ACCESS << 1) - 1)
1358aa0a1e58SJeff Roberson };
1359aa0a1e58SJeff Roberson
1360aa0a1e58SJeff Roberson struct ib_fmr_attr {
1361aa0a1e58SJeff Roberson int max_pages;
1362aa0a1e58SJeff Roberson int max_maps;
1363aa0a1e58SJeff Roberson u8 page_shift;
1364aa0a1e58SJeff Roberson };
1365aa0a1e58SJeff Roberson
1366478d3005SHans Petter Selasky struct ib_umem;
1367478d3005SHans Petter Selasky
1368f60da09dSHans Petter Selasky enum rdma_remove_reason {
1369f60da09dSHans Petter Selasky /*
1370f60da09dSHans Petter Selasky * Userspace requested uobject deletion or initial try
1371f60da09dSHans Petter Selasky * to remove uobject via cleanup. Call could fail
1372f60da09dSHans Petter Selasky */
1373f60da09dSHans Petter Selasky RDMA_REMOVE_DESTROY,
1374f60da09dSHans Petter Selasky /* Context deletion. This call should delete the actual object itself */
1375f60da09dSHans Petter Selasky RDMA_REMOVE_CLOSE,
1376f60da09dSHans Petter Selasky /* Driver is being hot-unplugged. This call should delete the actual object itself */
1377f60da09dSHans Petter Selasky RDMA_REMOVE_DRIVER_REMOVE,
1378f60da09dSHans Petter Selasky /* uobj is being cleaned-up before being committed */
1379f60da09dSHans Petter Selasky RDMA_REMOVE_ABORT,
1380f60da09dSHans Petter Selasky };
1381f60da09dSHans Petter Selasky
1382b633e08cSHans Petter Selasky struct ib_rdmacg_object {
1383b633e08cSHans Petter Selasky };
1384b633e08cSHans Petter Selasky
1385aa0a1e58SJeff Roberson struct ib_ucontext {
1386aa0a1e58SJeff Roberson struct ib_device *device;
1387b633e08cSHans Petter Selasky struct ib_uverbs_file *ufile;
1388b633e08cSHans Petter Selasky /*
1389b633e08cSHans Petter Selasky * 'closing' can be read by the driver only during a destroy callback,
1390b633e08cSHans Petter Selasky * it is set when we are closing the file descriptor and indicates
1391b633e08cSHans Petter Selasky * that mm_sem may be locked.
1392b633e08cSHans Petter Selasky */
1393b633e08cSHans Petter Selasky bool closing;
1394478d3005SHans Petter Selasky
1395f60da09dSHans Petter Selasky bool cleanup_retryable;
1396f60da09dSHans Petter Selasky
1397b633e08cSHans Petter Selasky struct ib_rdmacg_object cg_obj;
1398478d3005SHans Petter Selasky /*
1399b633e08cSHans Petter Selasky * Implementation details of the RDMA core, don't use in drivers:
1400478d3005SHans Petter Selasky */
1401b633e08cSHans Petter Selasky struct xarray mmap_xa;
1402aa0a1e58SJeff Roberson };
1403aa0a1e58SJeff Roberson
1404aa0a1e58SJeff Roberson struct ib_uobject {
1405aa0a1e58SJeff Roberson u64 user_handle; /* handle given to us by userspace */
1406b633e08cSHans Petter Selasky /* ufile & ucontext owning this object */
1407b633e08cSHans Petter Selasky struct ib_uverbs_file *ufile;
1408b633e08cSHans Petter Selasky /* FIXME, save memory: ufile->context == context */
1409aa0a1e58SJeff Roberson struct ib_ucontext *context; /* associated user context */
1410aa0a1e58SJeff Roberson void *object; /* containing object */
1411aa0a1e58SJeff Roberson struct list_head list; /* link to context's list */
1412b633e08cSHans Petter Selasky struct ib_rdmacg_object cg_obj; /* rdmacg object */
1413aa0a1e58SJeff Roberson int id; /* index into kernel idr */
1414aa0a1e58SJeff Roberson struct kref ref;
1415b633e08cSHans Petter Selasky atomic_t usecnt; /* protects exclusive access */
1416478d3005SHans Petter Selasky struct rcu_head rcu; /* kfree_rcu() overhead */
1417b633e08cSHans Petter Selasky
1418b633e08cSHans Petter Selasky const struct uverbs_api_object *uapi_object;
1419aa0a1e58SJeff Roberson };
1420aa0a1e58SJeff Roberson
1421aa0a1e58SJeff Roberson struct ib_udata {
1422b633e08cSHans Petter Selasky const u8 __user *inbuf;
1423b633e08cSHans Petter Selasky u8 __user *outbuf;
1424aa0a1e58SJeff Roberson size_t inlen;
1425aa0a1e58SJeff Roberson size_t outlen;
1426aa0a1e58SJeff Roberson };
1427aa0a1e58SJeff Roberson
1428aa0a1e58SJeff Roberson struct ib_pd {
1429478d3005SHans Petter Selasky u32 local_dma_lkey;
1430478d3005SHans Petter Selasky u32 flags;
1431aa0a1e58SJeff Roberson struct ib_device *device;
1432aa0a1e58SJeff Roberson struct ib_uobject *uobject;
1433aa0a1e58SJeff Roberson atomic_t usecnt; /* count all resources */
1434478d3005SHans Petter Selasky
1435478d3005SHans Petter Selasky u32 unsafe_global_rkey;
1436478d3005SHans Petter Selasky
1437478d3005SHans Petter Selasky /*
1438478d3005SHans Petter Selasky * Implementation details of the RDMA core, don't use in drivers:
1439478d3005SHans Petter Selasky */
1440478d3005SHans Petter Selasky struct ib_mr *__internal_mr;
1441aa0a1e58SJeff Roberson };
1442aa0a1e58SJeff Roberson
1443aa0a1e58SJeff Roberson struct ib_xrcd {
1444aa0a1e58SJeff Roberson struct ib_device *device;
1445c9f432b7SAlfred Perlstein atomic_t usecnt; /* count all exposed resources */
1446aa0a1e58SJeff Roberson struct inode *inode;
1447aa0a1e58SJeff Roberson
1448c9f432b7SAlfred Perlstein struct mutex tgt_qp_mutex;
1449c9f432b7SAlfred Perlstein struct list_head tgt_qp_list;
1450c9f432b7SAlfred Perlstein };
1451aa0a1e58SJeff Roberson
1452aa0a1e58SJeff Roberson struct ib_ah {
1453aa0a1e58SJeff Roberson struct ib_device *device;
1454aa0a1e58SJeff Roberson struct ib_pd *pd;
1455aa0a1e58SJeff Roberson struct ib_uobject *uobject;
1456aa0a1e58SJeff Roberson };
1457aa0a1e58SJeff Roberson
1458aa0a1e58SJeff Roberson typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1459aa0a1e58SJeff Roberson
1460478d3005SHans Petter Selasky enum ib_poll_context {
1461478d3005SHans Petter Selasky IB_POLL_DIRECT, /* caller context, no hw completions */
1462478d3005SHans Petter Selasky IB_POLL_SOFTIRQ, /* poll from softirq context */
1463478d3005SHans Petter Selasky IB_POLL_WORKQUEUE, /* poll from workqueue */
1464478d3005SHans Petter Selasky };
1465478d3005SHans Petter Selasky
1466aa0a1e58SJeff Roberson struct ib_cq {
1467aa0a1e58SJeff Roberson struct ib_device *device;
1468b633e08cSHans Petter Selasky struct ib_ucq_object *uobject;
1469aa0a1e58SJeff Roberson ib_comp_handler comp_handler;
1470aa0a1e58SJeff Roberson void (*event_handler)(struct ib_event *, void *);
1471aa0a1e58SJeff Roberson void *cq_context;
1472aa0a1e58SJeff Roberson int cqe;
1473aa0a1e58SJeff Roberson atomic_t usecnt; /* count number of work queues */
1474478d3005SHans Petter Selasky enum ib_poll_context poll_ctx;
1475478d3005SHans Petter Selasky struct work_struct work;
1476aa0a1e58SJeff Roberson };
1477aa0a1e58SJeff Roberson
1478aa0a1e58SJeff Roberson struct ib_srq {
1479aa0a1e58SJeff Roberson struct ib_device *device;
1480aa0a1e58SJeff Roberson struct ib_pd *pd;
1481b633e08cSHans Petter Selasky struct ib_usrq_object *uobject;
1482aa0a1e58SJeff Roberson void (*event_handler)(struct ib_event *, void *);
1483aa0a1e58SJeff Roberson void *srq_context;
1484c9f432b7SAlfred Perlstein enum ib_srq_type srq_type;
1485aa0a1e58SJeff Roberson atomic_t usecnt;
1486c9f432b7SAlfred Perlstein
1487b633e08cSHans Petter Selasky struct {
1488b633e08cSHans Petter Selasky struct ib_cq *cq;
1489c9f432b7SAlfred Perlstein union {
1490c9f432b7SAlfred Perlstein struct {
1491c9f432b7SAlfred Perlstein struct ib_xrcd *xrcd;
1492c9f432b7SAlfred Perlstein u32 srq_num;
1493c9f432b7SAlfred Perlstein } xrc;
1494b633e08cSHans Petter Selasky };
1495c9f432b7SAlfred Perlstein } ext;
1496aa0a1e58SJeff Roberson };
1497aa0a1e58SJeff Roberson
1498*a69b6af2SKa Ho Ng enum ib_raw_packet_caps {
1499*a69b6af2SKa Ho Ng /* Strip cvlan from incoming packet and report it in the matching work
1500*a69b6af2SKa Ho Ng * completion is supported.
1501*a69b6af2SKa Ho Ng */
1502*a69b6af2SKa Ho Ng IB_RAW_PACKET_CAP_CVLAN_STRIPPING = (1 << 0),
1503*a69b6af2SKa Ho Ng /* Scatter FCS field of an incoming packet to host memory is supported.
1504*a69b6af2SKa Ho Ng */
1505*a69b6af2SKa Ho Ng IB_RAW_PACKET_CAP_SCATTER_FCS = (1 << 1),
1506*a69b6af2SKa Ho Ng /* Checksum offloads are supported (for both send and receive). */
1507*a69b6af2SKa Ho Ng IB_RAW_PACKET_CAP_IP_CSUM = (1 << 2),
1508*a69b6af2SKa Ho Ng };
1509*a69b6af2SKa Ho Ng
1510478d3005SHans Petter Selasky enum ib_wq_type {
1511478d3005SHans Petter Selasky IB_WQT_RQ
1512478d3005SHans Petter Selasky };
1513478d3005SHans Petter Selasky
1514478d3005SHans Petter Selasky enum ib_wq_state {
1515478d3005SHans Petter Selasky IB_WQS_RESET,
1516478d3005SHans Petter Selasky IB_WQS_RDY,
1517478d3005SHans Petter Selasky IB_WQS_ERR
1518478d3005SHans Petter Selasky };
1519478d3005SHans Petter Selasky
1520478d3005SHans Petter Selasky struct ib_wq {
1521478d3005SHans Petter Selasky struct ib_device *device;
1522b633e08cSHans Petter Selasky struct ib_uwq_object *uobject;
1523478d3005SHans Petter Selasky void *wq_context;
1524478d3005SHans Petter Selasky void (*event_handler)(struct ib_event *, void *);
1525478d3005SHans Petter Selasky struct ib_pd *pd;
1526478d3005SHans Petter Selasky struct ib_cq *cq;
1527478d3005SHans Petter Selasky u32 wq_num;
1528478d3005SHans Petter Selasky enum ib_wq_state state;
1529478d3005SHans Petter Selasky enum ib_wq_type wq_type;
1530478d3005SHans Petter Selasky atomic_t usecnt;
1531478d3005SHans Petter Selasky };
1532478d3005SHans Petter Selasky
1533b633e08cSHans Petter Selasky enum ib_wq_flags {
1534b633e08cSHans Petter Selasky IB_WQ_FLAGS_CVLAN_STRIPPING = 1 << 0,
1535b633e08cSHans Petter Selasky IB_WQ_FLAGS_SCATTER_FCS = 1 << 1,
1536b633e08cSHans Petter Selasky IB_WQ_FLAGS_DELAY_DROP = 1 << 2,
1537b633e08cSHans Petter Selasky IB_WQ_FLAGS_PCI_WRITE_END_PADDING = 1 << 3,
1538b633e08cSHans Petter Selasky };
1539b633e08cSHans Petter Selasky
1540478d3005SHans Petter Selasky struct ib_wq_init_attr {
1541478d3005SHans Petter Selasky void *wq_context;
1542478d3005SHans Petter Selasky enum ib_wq_type wq_type;
1543478d3005SHans Petter Selasky u32 max_wr;
1544478d3005SHans Petter Selasky u32 max_sge;
1545478d3005SHans Petter Selasky struct ib_cq *cq;
1546478d3005SHans Petter Selasky void (*event_handler)(struct ib_event *, void *);
1547b633e08cSHans Petter Selasky u32 create_flags; /* Use enum ib_wq_flags */
1548478d3005SHans Petter Selasky };
1549478d3005SHans Petter Selasky
1550478d3005SHans Petter Selasky enum ib_wq_attr_mask {
1551478d3005SHans Petter Selasky IB_WQ_STATE = 1 << 0,
1552478d3005SHans Petter Selasky IB_WQ_CUR_STATE = 1 << 1,
1553b633e08cSHans Petter Selasky IB_WQ_FLAGS = 1 << 2,
1554478d3005SHans Petter Selasky };
1555478d3005SHans Petter Selasky
1556478d3005SHans Petter Selasky struct ib_wq_attr {
1557478d3005SHans Petter Selasky enum ib_wq_state wq_state;
1558478d3005SHans Petter Selasky enum ib_wq_state curr_wq_state;
1559b633e08cSHans Petter Selasky u32 flags; /* Use enum ib_wq_flags */
1560b633e08cSHans Petter Selasky u32 flags_mask; /* Use enum ib_wq_flags */
1561478d3005SHans Petter Selasky };
1562478d3005SHans Petter Selasky
1563478d3005SHans Petter Selasky struct ib_rwq_ind_table {
1564478d3005SHans Petter Selasky struct ib_device *device;
1565478d3005SHans Petter Selasky struct ib_uobject *uobject;
1566478d3005SHans Petter Selasky atomic_t usecnt;
1567478d3005SHans Petter Selasky u32 ind_tbl_num;
1568478d3005SHans Petter Selasky u32 log_ind_tbl_size;
1569478d3005SHans Petter Selasky struct ib_wq **ind_tbl;
1570478d3005SHans Petter Selasky };
1571478d3005SHans Petter Selasky
1572478d3005SHans Petter Selasky struct ib_rwq_ind_table_init_attr {
1573478d3005SHans Petter Selasky u32 log_ind_tbl_size;
1574478d3005SHans Petter Selasky /* Each entry is a pointer to Receive Work Queue */
1575478d3005SHans Petter Selasky struct ib_wq **ind_tbl;
1576478d3005SHans Petter Selasky };
1577478d3005SHans Petter Selasky
1578478d3005SHans Petter Selasky /*
1579478d3005SHans Petter Selasky * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
1580478d3005SHans Petter Selasky * @max_read_sge: Maximum SGE elements per RDMA READ request.
1581478d3005SHans Petter Selasky */
1582aa0a1e58SJeff Roberson struct ib_qp {
1583aa0a1e58SJeff Roberson struct ib_device *device;
1584aa0a1e58SJeff Roberson struct ib_pd *pd;
1585aa0a1e58SJeff Roberson struct ib_cq *send_cq;
1586aa0a1e58SJeff Roberson struct ib_cq *recv_cq;
1587478d3005SHans Petter Selasky spinlock_t mr_lock;
1588aa0a1e58SJeff Roberson struct ib_srq *srq;
1589c9f432b7SAlfred Perlstein struct ib_xrcd *xrcd; /* XRC TGT QPs only */
1590c9f432b7SAlfred Perlstein struct list_head xrcd_list;
1591478d3005SHans Petter Selasky
1592b5c1e0cbSHans Petter Selasky /* count times opened, mcast attaches, flow attaches */
1593b5c1e0cbSHans Petter Selasky atomic_t usecnt;
1594c9f432b7SAlfred Perlstein struct list_head open_list;
1595c9f432b7SAlfred Perlstein struct ib_qp *real_qp;
1596b633e08cSHans Petter Selasky struct ib_uqp_object *uobject;
1597aa0a1e58SJeff Roberson void (*event_handler)(struct ib_event *, void *);
1598aa0a1e58SJeff Roberson void *qp_context;
1599aa0a1e58SJeff Roberson u32 qp_num;
1600478d3005SHans Petter Selasky u32 max_write_sge;
1601478d3005SHans Petter Selasky u32 max_read_sge;
1602aa0a1e58SJeff Roberson enum ib_qp_type qp_type;
1603478d3005SHans Petter Selasky struct ib_rwq_ind_table *rwq_ind_tbl;
1604b633e08cSHans Petter Selasky u8 port;
1605b633e08cSHans Petter Selasky };
1606b633e08cSHans Petter Selasky
1607b633e08cSHans Petter Selasky struct ib_dm {
1608b633e08cSHans Petter Selasky struct ib_device *device;
1609b633e08cSHans Petter Selasky u32 length;
1610b633e08cSHans Petter Selasky u32 flags;
1611b633e08cSHans Petter Selasky struct ib_uobject *uobject;
1612b633e08cSHans Petter Selasky atomic_t usecnt;
1613aa0a1e58SJeff Roberson };
1614aa0a1e58SJeff Roberson
1615aa0a1e58SJeff Roberson struct ib_mr {
1616aa0a1e58SJeff Roberson struct ib_device *device;
1617aa0a1e58SJeff Roberson struct ib_pd *pd;
1618aa0a1e58SJeff Roberson u32 lkey;
1619aa0a1e58SJeff Roberson u32 rkey;
1620478d3005SHans Petter Selasky u64 iova;
1621ae9a8ec9SHans Petter Selasky u64 length;
1622478d3005SHans Petter Selasky unsigned int page_size;
1623b633e08cSHans Petter Selasky enum ib_mr_type type;
1624478d3005SHans Petter Selasky bool need_inval;
1625478d3005SHans Petter Selasky union {
1626478d3005SHans Petter Selasky struct ib_uobject *uobject; /* user */
1627478d3005SHans Petter Selasky struct list_head qp_entry; /* FR */
1628478d3005SHans Petter Selasky };
1629b633e08cSHans Petter Selasky
1630b633e08cSHans Petter Selasky struct ib_dm *dm;
1631b633e08cSHans Petter Selasky struct ib_sig_attrs *sig_attrs; /* only for IB_MR_TYPE_INTEGRITY MRs */
1632aa0a1e58SJeff Roberson };
1633aa0a1e58SJeff Roberson
1634aa0a1e58SJeff Roberson struct ib_mw {
1635aa0a1e58SJeff Roberson struct ib_device *device;
1636aa0a1e58SJeff Roberson struct ib_pd *pd;
1637aa0a1e58SJeff Roberson struct ib_uobject *uobject;
1638aa0a1e58SJeff Roberson u32 rkey;
1639b5c1e0cbSHans Petter Selasky enum ib_mw_type type;
1640aa0a1e58SJeff Roberson };
1641aa0a1e58SJeff Roberson
1642aa0a1e58SJeff Roberson struct ib_fmr {
1643aa0a1e58SJeff Roberson struct ib_device *device;
1644aa0a1e58SJeff Roberson struct ib_pd *pd;
1645aa0a1e58SJeff Roberson struct list_head list;
1646aa0a1e58SJeff Roberson u32 lkey;
1647aa0a1e58SJeff Roberson u32 rkey;
1648aa0a1e58SJeff Roberson };
1649aa0a1e58SJeff Roberson
1650b5c1e0cbSHans Petter Selasky /* Supported steering options */
1651b5c1e0cbSHans Petter Selasky enum ib_flow_attr_type {
1652b5c1e0cbSHans Petter Selasky /* steering according to rule specifications */
1653b5c1e0cbSHans Petter Selasky IB_FLOW_ATTR_NORMAL = 0x0,
1654b5c1e0cbSHans Petter Selasky /* default unicast and multicast rule -
1655b5c1e0cbSHans Petter Selasky * receive all Eth traffic which isn't steered to any QP
1656b5c1e0cbSHans Petter Selasky */
1657b5c1e0cbSHans Petter Selasky IB_FLOW_ATTR_ALL_DEFAULT = 0x1,
1658b5c1e0cbSHans Petter Selasky /* default multicast rule -
1659b5c1e0cbSHans Petter Selasky * receive all Eth multicast traffic which isn't steered to any QP
1660b5c1e0cbSHans Petter Selasky */
1661b5c1e0cbSHans Petter Selasky IB_FLOW_ATTR_MC_DEFAULT = 0x2,
1662b5c1e0cbSHans Petter Selasky /* sniffer rule - receive all port traffic */
1663b5c1e0cbSHans Petter Selasky IB_FLOW_ATTR_SNIFFER = 0x3
1664b5c1e0cbSHans Petter Selasky };
1665b5c1e0cbSHans Petter Selasky
1666b5c1e0cbSHans Petter Selasky /* Supported steering header types */
1667b5c1e0cbSHans Petter Selasky enum ib_flow_spec_type {
1668b5c1e0cbSHans Petter Selasky /* L2 headers*/
1669b5c1e0cbSHans Petter Selasky IB_FLOW_SPEC_ETH = 0x20,
1670478d3005SHans Petter Selasky IB_FLOW_SPEC_IB = 0x22,
1671b5c1e0cbSHans Petter Selasky /* L3 header*/
1672b5c1e0cbSHans Petter Selasky IB_FLOW_SPEC_IPV4 = 0x30,
1673478d3005SHans Petter Selasky IB_FLOW_SPEC_IPV6 = 0x31,
1674b633e08cSHans Petter Selasky IB_FLOW_SPEC_ESP = 0x34,
1675b5c1e0cbSHans Petter Selasky /* L4 headers*/
1676b5c1e0cbSHans Petter Selasky IB_FLOW_SPEC_TCP = 0x40,
1677b633e08cSHans Petter Selasky IB_FLOW_SPEC_UDP = 0x41,
1678b633e08cSHans Petter Selasky IB_FLOW_SPEC_VXLAN_TUNNEL = 0x50,
1679b633e08cSHans Petter Selasky IB_FLOW_SPEC_GRE = 0x51,
1680b633e08cSHans Petter Selasky IB_FLOW_SPEC_MPLS = 0x60,
1681b633e08cSHans Petter Selasky IB_FLOW_SPEC_INNER = 0x100,
1682b633e08cSHans Petter Selasky /* Actions */
1683b633e08cSHans Petter Selasky IB_FLOW_SPEC_ACTION_TAG = 0x1000,
1684b633e08cSHans Petter Selasky IB_FLOW_SPEC_ACTION_DROP = 0x1001,
1685b633e08cSHans Petter Selasky IB_FLOW_SPEC_ACTION_HANDLE = 0x1002,
1686b633e08cSHans Petter Selasky IB_FLOW_SPEC_ACTION_COUNT = 0x1003,
1687b5c1e0cbSHans Petter Selasky };
1688478d3005SHans Petter Selasky #define IB_FLOW_SPEC_LAYER_MASK 0xF0
1689b633e08cSHans Petter Selasky #define IB_FLOW_SPEC_SUPPORT_LAYERS 10
1690b5c1e0cbSHans Petter Selasky
1691b5c1e0cbSHans Petter Selasky /* Flow steering rule priority is set according to it's domain.
1692b5c1e0cbSHans Petter Selasky * Lower domain value means higher priority.
1693b5c1e0cbSHans Petter Selasky */
1694b5c1e0cbSHans Petter Selasky enum ib_flow_domain {
1695b5c1e0cbSHans Petter Selasky IB_FLOW_DOMAIN_USER,
1696b5c1e0cbSHans Petter Selasky IB_FLOW_DOMAIN_ETHTOOL,
1697b5c1e0cbSHans Petter Selasky IB_FLOW_DOMAIN_RFS,
1698b5c1e0cbSHans Petter Selasky IB_FLOW_DOMAIN_NIC,
1699b5c1e0cbSHans Petter Selasky IB_FLOW_DOMAIN_NUM /* Must be last */
1700b5c1e0cbSHans Petter Selasky };
1701b5c1e0cbSHans Petter Selasky
1702b5c1e0cbSHans Petter Selasky enum ib_flow_flags {
1703478d3005SHans Petter Selasky IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
1704478d3005SHans Petter Selasky IB_FLOW_ATTR_FLAGS_RESERVED = 1UL << 2 /* Must be last */
1705b5c1e0cbSHans Petter Selasky };
1706b5c1e0cbSHans Petter Selasky
1707b5c1e0cbSHans Petter Selasky struct ib_flow_eth_filter {
1708b5c1e0cbSHans Petter Selasky u8 dst_mac[6];
1709b5c1e0cbSHans Petter Selasky u8 src_mac[6];
1710b5c1e0cbSHans Petter Selasky __be16 ether_type;
1711b5c1e0cbSHans Petter Selasky __be16 vlan_tag;
1712478d3005SHans Petter Selasky /* Must be last */
1713478d3005SHans Petter Selasky u8 real_sz[0];
1714b5c1e0cbSHans Petter Selasky };
1715b5c1e0cbSHans Petter Selasky
1716b5c1e0cbSHans Petter Selasky struct ib_flow_spec_eth {
1717b5c1e0cbSHans Petter Selasky enum ib_flow_spec_type type;
1718b5c1e0cbSHans Petter Selasky u16 size;
1719b5c1e0cbSHans Petter Selasky struct ib_flow_eth_filter val;
1720b5c1e0cbSHans Petter Selasky struct ib_flow_eth_filter mask;
1721b5c1e0cbSHans Petter Selasky };
1722b5c1e0cbSHans Petter Selasky
1723b5c1e0cbSHans Petter Selasky struct ib_flow_ib_filter {
1724478d3005SHans Petter Selasky __be16 dlid;
1725478d3005SHans Petter Selasky __u8 sl;
1726478d3005SHans Petter Selasky /* Must be last */
1727478d3005SHans Petter Selasky u8 real_sz[0];
1728b5c1e0cbSHans Petter Selasky };
1729b5c1e0cbSHans Petter Selasky
1730b5c1e0cbSHans Petter Selasky struct ib_flow_spec_ib {
1731b5c1e0cbSHans Petter Selasky enum ib_flow_spec_type type;
1732b5c1e0cbSHans Petter Selasky u16 size;
1733b5c1e0cbSHans Petter Selasky struct ib_flow_ib_filter val;
1734b5c1e0cbSHans Petter Selasky struct ib_flow_ib_filter mask;
1735b5c1e0cbSHans Petter Selasky };
1736b5c1e0cbSHans Petter Selasky
1737478d3005SHans Petter Selasky /* IPv4 header flags */
1738478d3005SHans Petter Selasky enum ib_ipv4_flags {
1739478d3005SHans Petter Selasky IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */
1740478d3005SHans Petter Selasky IB_IPV4_MORE_FRAG = 0X4 /* For All fragmented packets except the
1741478d3005SHans Petter Selasky last have this flag set */
1742478d3005SHans Petter Selasky };
1743478d3005SHans Petter Selasky
1744b5c1e0cbSHans Petter Selasky struct ib_flow_ipv4_filter {
1745c9f432b7SAlfred Perlstein __be32 src_ip;
1746c9f432b7SAlfred Perlstein __be32 dst_ip;
1747478d3005SHans Petter Selasky u8 proto;
1748478d3005SHans Petter Selasky u8 tos;
1749478d3005SHans Petter Selasky u8 ttl;
1750478d3005SHans Petter Selasky u8 flags;
1751478d3005SHans Petter Selasky /* Must be last */
1752478d3005SHans Petter Selasky u8 real_sz[0];
1753b5c1e0cbSHans Petter Selasky };
1754b5c1e0cbSHans Petter Selasky
1755b5c1e0cbSHans Petter Selasky struct ib_flow_spec_ipv4 {
1756b5c1e0cbSHans Petter Selasky enum ib_flow_spec_type type;
1757b5c1e0cbSHans Petter Selasky u16 size;
1758b5c1e0cbSHans Petter Selasky struct ib_flow_ipv4_filter val;
1759b5c1e0cbSHans Petter Selasky struct ib_flow_ipv4_filter mask;
1760b5c1e0cbSHans Petter Selasky };
1761b5c1e0cbSHans Petter Selasky
1762478d3005SHans Petter Selasky struct ib_flow_ipv6_filter {
1763478d3005SHans Petter Selasky u8 src_ip[16];
1764478d3005SHans Petter Selasky u8 dst_ip[16];
1765478d3005SHans Petter Selasky __be32 flow_label;
1766478d3005SHans Petter Selasky u8 next_hdr;
1767478d3005SHans Petter Selasky u8 traffic_class;
1768478d3005SHans Petter Selasky u8 hop_limit;
1769478d3005SHans Petter Selasky /* Must be last */
1770478d3005SHans Petter Selasky u8 real_sz[0];
1771478d3005SHans Petter Selasky };
1772478d3005SHans Petter Selasky
1773478d3005SHans Petter Selasky struct ib_flow_spec_ipv6 {
1774478d3005SHans Petter Selasky enum ib_flow_spec_type type;
1775478d3005SHans Petter Selasky u16 size;
1776478d3005SHans Petter Selasky struct ib_flow_ipv6_filter val;
1777478d3005SHans Petter Selasky struct ib_flow_ipv6_filter mask;
1778478d3005SHans Petter Selasky };
1779478d3005SHans Petter Selasky
1780b5c1e0cbSHans Petter Selasky struct ib_flow_tcp_udp_filter {
1781c9f432b7SAlfred Perlstein __be16 dst_port;
1782b5c1e0cbSHans Petter Selasky __be16 src_port;
1783478d3005SHans Petter Selasky /* Must be last */
1784478d3005SHans Petter Selasky u8 real_sz[0];
1785b5c1e0cbSHans Petter Selasky };
1786b5c1e0cbSHans Petter Selasky
1787b5c1e0cbSHans Petter Selasky struct ib_flow_spec_tcp_udp {
1788b5c1e0cbSHans Petter Selasky enum ib_flow_spec_type type;
1789b5c1e0cbSHans Petter Selasky u16 size;
1790b5c1e0cbSHans Petter Selasky struct ib_flow_tcp_udp_filter val;
1791b5c1e0cbSHans Petter Selasky struct ib_flow_tcp_udp_filter mask;
1792b5c1e0cbSHans Petter Selasky };
1793b5c1e0cbSHans Petter Selasky
1794b633e08cSHans Petter Selasky struct ib_flow_tunnel_filter {
1795b633e08cSHans Petter Selasky __be32 tunnel_id;
1796b633e08cSHans Petter Selasky u8 real_sz[0];
1797b633e08cSHans Petter Selasky };
1798b633e08cSHans Petter Selasky
1799b633e08cSHans Petter Selasky /* ib_flow_spec_tunnel describes the Vxlan tunnel
1800b633e08cSHans Petter Selasky * the tunnel_id from val has the vni value
1801b633e08cSHans Petter Selasky */
1802b633e08cSHans Petter Selasky struct ib_flow_spec_tunnel {
1803b633e08cSHans Petter Selasky u32 type;
1804b633e08cSHans Petter Selasky u16 size;
1805b633e08cSHans Petter Selasky struct ib_flow_tunnel_filter val;
1806b633e08cSHans Petter Selasky struct ib_flow_tunnel_filter mask;
1807b633e08cSHans Petter Selasky };
1808b633e08cSHans Petter Selasky
1809b633e08cSHans Petter Selasky struct ib_flow_esp_filter {
1810b633e08cSHans Petter Selasky __be32 spi;
1811b633e08cSHans Petter Selasky __be32 seq;
1812b633e08cSHans Petter Selasky /* Must be last */
1813b633e08cSHans Petter Selasky u8 real_sz[0];
1814b633e08cSHans Petter Selasky };
1815b633e08cSHans Petter Selasky
1816b633e08cSHans Petter Selasky struct ib_flow_spec_esp {
1817b633e08cSHans Petter Selasky u32 type;
1818b633e08cSHans Petter Selasky u16 size;
1819b633e08cSHans Petter Selasky struct ib_flow_esp_filter val;
1820b633e08cSHans Petter Selasky struct ib_flow_esp_filter mask;
1821b633e08cSHans Petter Selasky };
1822b633e08cSHans Petter Selasky
1823b633e08cSHans Petter Selasky struct ib_flow_gre_filter {
1824b633e08cSHans Petter Selasky __be16 c_ks_res0_ver;
1825b633e08cSHans Petter Selasky __be16 protocol;
1826b633e08cSHans Petter Selasky __be32 key;
1827b633e08cSHans Petter Selasky /* Must be last */
1828b633e08cSHans Petter Selasky u8 real_sz[0];
1829b633e08cSHans Petter Selasky };
1830b633e08cSHans Petter Selasky
1831b633e08cSHans Petter Selasky struct ib_flow_spec_gre {
1832b633e08cSHans Petter Selasky u32 type;
1833b633e08cSHans Petter Selasky u16 size;
1834b633e08cSHans Petter Selasky struct ib_flow_gre_filter val;
1835b633e08cSHans Petter Selasky struct ib_flow_gre_filter mask;
1836b633e08cSHans Petter Selasky };
1837b633e08cSHans Petter Selasky
1838b633e08cSHans Petter Selasky struct ib_flow_mpls_filter {
1839b633e08cSHans Petter Selasky __be32 tag;
1840b633e08cSHans Petter Selasky /* Must be last */
1841b633e08cSHans Petter Selasky u8 real_sz[0];
1842b633e08cSHans Petter Selasky };
1843b633e08cSHans Petter Selasky
1844b633e08cSHans Petter Selasky struct ib_flow_spec_mpls {
1845b633e08cSHans Petter Selasky u32 type;
1846b633e08cSHans Petter Selasky u16 size;
1847b633e08cSHans Petter Selasky struct ib_flow_mpls_filter val;
1848b633e08cSHans Petter Selasky struct ib_flow_mpls_filter mask;
1849b633e08cSHans Petter Selasky };
1850b633e08cSHans Petter Selasky
1851b633e08cSHans Petter Selasky struct ib_flow_spec_action_tag {
1852b633e08cSHans Petter Selasky enum ib_flow_spec_type type;
1853b633e08cSHans Petter Selasky u16 size;
1854b633e08cSHans Petter Selasky u32 tag_id;
1855b633e08cSHans Petter Selasky };
1856b633e08cSHans Petter Selasky
1857b633e08cSHans Petter Selasky struct ib_flow_spec_action_drop {
1858b633e08cSHans Petter Selasky enum ib_flow_spec_type type;
1859b633e08cSHans Petter Selasky u16 size;
1860b633e08cSHans Petter Selasky };
1861b633e08cSHans Petter Selasky
1862b633e08cSHans Petter Selasky struct ib_flow_spec_action_handle {
1863b633e08cSHans Petter Selasky enum ib_flow_spec_type type;
1864b633e08cSHans Petter Selasky u16 size;
1865b633e08cSHans Petter Selasky struct ib_flow_action *act;
1866b633e08cSHans Petter Selasky };
1867b633e08cSHans Petter Selasky
1868b633e08cSHans Petter Selasky enum ib_counters_description {
1869b633e08cSHans Petter Selasky IB_COUNTER_PACKETS,
1870b633e08cSHans Petter Selasky IB_COUNTER_BYTES,
1871b633e08cSHans Petter Selasky };
1872b633e08cSHans Petter Selasky
1873b633e08cSHans Petter Selasky struct ib_flow_spec_action_count {
1874b633e08cSHans Petter Selasky enum ib_flow_spec_type type;
1875b633e08cSHans Petter Selasky u16 size;
1876b633e08cSHans Petter Selasky struct ib_counters *counters;
1877b633e08cSHans Petter Selasky };
1878b633e08cSHans Petter Selasky
1879b5c1e0cbSHans Petter Selasky union ib_flow_spec {
1880b5c1e0cbSHans Petter Selasky struct {
1881b633e08cSHans Petter Selasky u32 type;
1882b5c1e0cbSHans Petter Selasky u16 size;
1883b5c1e0cbSHans Petter Selasky };
1884b5c1e0cbSHans Petter Selasky struct ib_flow_spec_eth eth;
1885478d3005SHans Petter Selasky struct ib_flow_spec_ib ib;
1886b5c1e0cbSHans Petter Selasky struct ib_flow_spec_ipv4 ipv4;
1887b5c1e0cbSHans Petter Selasky struct ib_flow_spec_tcp_udp tcp_udp;
1888478d3005SHans Petter Selasky struct ib_flow_spec_ipv6 ipv6;
1889b633e08cSHans Petter Selasky struct ib_flow_spec_tunnel tunnel;
1890b633e08cSHans Petter Selasky struct ib_flow_spec_esp esp;
1891b633e08cSHans Petter Selasky struct ib_flow_spec_gre gre;
1892b633e08cSHans Petter Selasky struct ib_flow_spec_mpls mpls;
1893b633e08cSHans Petter Selasky struct ib_flow_spec_action_tag flow_tag;
1894b633e08cSHans Petter Selasky struct ib_flow_spec_action_drop drop;
1895b633e08cSHans Petter Selasky struct ib_flow_spec_action_handle action;
1896b633e08cSHans Petter Selasky struct ib_flow_spec_action_count flow_count;
1897b5c1e0cbSHans Petter Selasky };
1898b5c1e0cbSHans Petter Selasky
1899b5c1e0cbSHans Petter Selasky struct ib_flow_attr {
1900b5c1e0cbSHans Petter Selasky enum ib_flow_attr_type type;
1901b5c1e0cbSHans Petter Selasky u16 size;
1902b5c1e0cbSHans Petter Selasky u16 priority;
1903478d3005SHans Petter Selasky u32 flags;
1904b5c1e0cbSHans Petter Selasky u8 num_of_specs;
1905b5c1e0cbSHans Petter Selasky u8 port;
1906b633e08cSHans Petter Selasky union ib_flow_spec flows[0];
1907b5c1e0cbSHans Petter Selasky };
1908b5c1e0cbSHans Petter Selasky
1909b5c1e0cbSHans Petter Selasky struct ib_flow {
1910b5c1e0cbSHans Petter Selasky struct ib_qp *qp;
1911b633e08cSHans Petter Selasky struct ib_device *device;
1912b5c1e0cbSHans Petter Selasky struct ib_uobject *uobject;
1913c9f432b7SAlfred Perlstein };
1914c9f432b7SAlfred Perlstein
1915b633e08cSHans Petter Selasky enum ib_flow_action_type {
1916b633e08cSHans Petter Selasky IB_FLOW_ACTION_UNSPECIFIED,
1917b633e08cSHans Petter Selasky IB_FLOW_ACTION_ESP = 1,
1918b633e08cSHans Petter Selasky };
1919b633e08cSHans Petter Selasky
1920b633e08cSHans Petter Selasky struct ib_flow_action_attrs_esp_keymats {
1921b633e08cSHans Petter Selasky enum ib_uverbs_flow_action_esp_keymat protocol;
1922b633e08cSHans Petter Selasky union {
1923b633e08cSHans Petter Selasky struct ib_uverbs_flow_action_esp_keymat_aes_gcm aes_gcm;
1924b633e08cSHans Petter Selasky } keymat;
1925b633e08cSHans Petter Selasky };
1926b633e08cSHans Petter Selasky
1927b633e08cSHans Petter Selasky struct ib_flow_action_attrs_esp_replays {
1928b633e08cSHans Petter Selasky enum ib_uverbs_flow_action_esp_replay protocol;
1929b633e08cSHans Petter Selasky union {
1930b633e08cSHans Petter Selasky struct ib_uverbs_flow_action_esp_replay_bmp bmp;
1931b633e08cSHans Petter Selasky } replay;
1932b633e08cSHans Petter Selasky };
1933b633e08cSHans Petter Selasky
1934b633e08cSHans Petter Selasky enum ib_flow_action_attrs_esp_flags {
1935b633e08cSHans Petter Selasky /* All user-space flags at the top: Use enum ib_uverbs_flow_action_esp_flags
1936b633e08cSHans Petter Selasky * This is done in order to share the same flags between user-space and
1937b633e08cSHans Petter Selasky * kernel and spare an unnecessary translation.
1938b633e08cSHans Petter Selasky */
1939b633e08cSHans Petter Selasky
1940b633e08cSHans Petter Selasky /* Kernel flags */
1941b633e08cSHans Petter Selasky IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED = 1ULL << 32,
1942b633e08cSHans Petter Selasky IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS = 1ULL << 33,
1943b633e08cSHans Petter Selasky };
1944b633e08cSHans Petter Selasky
1945b633e08cSHans Petter Selasky struct ib_flow_spec_list {
1946b633e08cSHans Petter Selasky struct ib_flow_spec_list *next;
1947b633e08cSHans Petter Selasky union ib_flow_spec spec;
1948b633e08cSHans Petter Selasky };
1949b633e08cSHans Petter Selasky
1950b633e08cSHans Petter Selasky struct ib_flow_action_attrs_esp {
1951b633e08cSHans Petter Selasky struct ib_flow_action_attrs_esp_keymats *keymat;
1952b633e08cSHans Petter Selasky struct ib_flow_action_attrs_esp_replays *replay;
1953b633e08cSHans Petter Selasky struct ib_flow_spec_list *encap;
1954b633e08cSHans Petter Selasky /* Used only if IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED is enabled.
1955b633e08cSHans Petter Selasky * Value of 0 is a valid value.
1956b633e08cSHans Petter Selasky */
1957b633e08cSHans Petter Selasky u32 esn;
1958b633e08cSHans Petter Selasky u32 spi;
1959b633e08cSHans Petter Selasky u32 seq;
1960b633e08cSHans Petter Selasky u32 tfc_pad;
1961b633e08cSHans Petter Selasky /* Use enum ib_flow_action_attrs_esp_flags */
1962b633e08cSHans Petter Selasky u64 flags;
1963b633e08cSHans Petter Selasky u64 hard_limit_pkts;
1964b633e08cSHans Petter Selasky };
1965b633e08cSHans Petter Selasky
1966b633e08cSHans Petter Selasky struct ib_flow_action {
1967b633e08cSHans Petter Selasky struct ib_device *device;
1968b633e08cSHans Petter Selasky struct ib_uobject *uobject;
1969b633e08cSHans Petter Selasky enum ib_flow_action_type type;
1970b633e08cSHans Petter Selasky atomic_t usecnt;
1971b633e08cSHans Petter Selasky };
1972b633e08cSHans Petter Selasky
1973b633e08cSHans Petter Selasky
1974478d3005SHans Petter Selasky struct ib_mad_hdr;
1975aa0a1e58SJeff Roberson struct ib_grh;
1976aa0a1e58SJeff Roberson
1977aa0a1e58SJeff Roberson enum ib_process_mad_flags {
1978aa0a1e58SJeff Roberson IB_MAD_IGNORE_MKEY = 1,
1979aa0a1e58SJeff Roberson IB_MAD_IGNORE_BKEY = 2,
1980aa0a1e58SJeff Roberson IB_MAD_IGNORE_ALL = IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1981aa0a1e58SJeff Roberson };
1982aa0a1e58SJeff Roberson
1983aa0a1e58SJeff Roberson enum ib_mad_result {
1984aa0a1e58SJeff Roberson IB_MAD_RESULT_FAILURE = 0, /* (!SUCCESS is the important flag) */
1985aa0a1e58SJeff Roberson IB_MAD_RESULT_SUCCESS = 1 << 0, /* MAD was successfully processed */
1986aa0a1e58SJeff Roberson IB_MAD_RESULT_REPLY = 1 << 1, /* Reply packet needs to be sent */
1987aa0a1e58SJeff Roberson IB_MAD_RESULT_CONSUMED = 1 << 2 /* Packet consumed: stop processing */
1988aa0a1e58SJeff Roberson };
1989aa0a1e58SJeff Roberson
1990aa0a1e58SJeff Roberson #define IB_DEVICE_NAME_MAX 64
1991aa0a1e58SJeff Roberson
1992aa0a1e58SJeff Roberson struct ib_cache {
1993aa0a1e58SJeff Roberson rwlock_t lock;
1994aa0a1e58SJeff Roberson struct ib_event_handler event_handler;
1995aa0a1e58SJeff Roberson struct ib_pkey_cache **pkey_cache;
1996478d3005SHans Petter Selasky struct ib_gid_table **gid_cache;
1997aa0a1e58SJeff Roberson u8 *lmc_cache;
1998aa0a1e58SJeff Roberson };
1999aa0a1e58SJeff Roberson
2000aa0a1e58SJeff Roberson struct ib_dma_mapping_ops {
2001aa0a1e58SJeff Roberson int (*mapping_error)(struct ib_device *dev,
2002aa0a1e58SJeff Roberson u64 dma_addr);
2003aa0a1e58SJeff Roberson u64 (*map_single)(struct ib_device *dev,
2004aa0a1e58SJeff Roberson void *ptr, size_t size,
2005aa0a1e58SJeff Roberson enum dma_data_direction direction);
2006aa0a1e58SJeff Roberson void (*unmap_single)(struct ib_device *dev,
2007aa0a1e58SJeff Roberson u64 addr, size_t size,
2008aa0a1e58SJeff Roberson enum dma_data_direction direction);
2009aa0a1e58SJeff Roberson u64 (*map_page)(struct ib_device *dev,
2010aa0a1e58SJeff Roberson struct page *page, unsigned long offset,
2011aa0a1e58SJeff Roberson size_t size,
2012aa0a1e58SJeff Roberson enum dma_data_direction direction);
2013aa0a1e58SJeff Roberson void (*unmap_page)(struct ib_device *dev,
2014aa0a1e58SJeff Roberson u64 addr, size_t size,
2015aa0a1e58SJeff Roberson enum dma_data_direction direction);
2016aa0a1e58SJeff Roberson int (*map_sg)(struct ib_device *dev,
2017aa0a1e58SJeff Roberson struct scatterlist *sg, int nents,
2018aa0a1e58SJeff Roberson enum dma_data_direction direction);
2019aa0a1e58SJeff Roberson void (*unmap_sg)(struct ib_device *dev,
2020aa0a1e58SJeff Roberson struct scatterlist *sg, int nents,
2021aa0a1e58SJeff Roberson enum dma_data_direction direction);
2022478d3005SHans Petter Selasky int (*map_sg_attrs)(struct ib_device *dev,
2023478d3005SHans Petter Selasky struct scatterlist *sg, int nents,
2024478d3005SHans Petter Selasky enum dma_data_direction direction,
2025478d3005SHans Petter Selasky struct dma_attrs *attrs);
2026478d3005SHans Petter Selasky void (*unmap_sg_attrs)(struct ib_device *dev,
2027478d3005SHans Petter Selasky struct scatterlist *sg, int nents,
2028478d3005SHans Petter Selasky enum dma_data_direction direction,
2029478d3005SHans Petter Selasky struct dma_attrs *attrs);
2030aa0a1e58SJeff Roberson void (*sync_single_for_cpu)(struct ib_device *dev,
2031aa0a1e58SJeff Roberson u64 dma_handle,
2032aa0a1e58SJeff Roberson size_t size,
2033aa0a1e58SJeff Roberson enum dma_data_direction dir);
2034aa0a1e58SJeff Roberson void (*sync_single_for_device)(struct ib_device *dev,
2035aa0a1e58SJeff Roberson u64 dma_handle,
2036aa0a1e58SJeff Roberson size_t size,
2037aa0a1e58SJeff Roberson enum dma_data_direction dir);
2038aa0a1e58SJeff Roberson void *(*alloc_coherent)(struct ib_device *dev,
2039aa0a1e58SJeff Roberson size_t size,
2040aa0a1e58SJeff Roberson u64 *dma_handle,
2041aa0a1e58SJeff Roberson gfp_t flag);
2042aa0a1e58SJeff Roberson void (*free_coherent)(struct ib_device *dev,
2043aa0a1e58SJeff Roberson size_t size, void *cpu_addr,
2044aa0a1e58SJeff Roberson u64 dma_handle);
2045aa0a1e58SJeff Roberson };
2046aa0a1e58SJeff Roberson
2047aa0a1e58SJeff Roberson struct iw_cm_verbs;
2048478d3005SHans Petter Selasky
2049478d3005SHans Petter Selasky struct ib_port_immutable {
2050478d3005SHans Petter Selasky int pkey_tbl_len;
2051478d3005SHans Petter Selasky int gid_tbl_len;
2052478d3005SHans Petter Selasky u32 core_cap_flags;
2053478d3005SHans Petter Selasky u32 max_mad_size;
2054478d3005SHans Petter Selasky };
2055aa0a1e58SJeff Roberson
2056b633e08cSHans Petter Selasky struct ib_counters {
2057b633e08cSHans Petter Selasky struct ib_device *device;
2058b633e08cSHans Petter Selasky struct ib_uobject *uobject;
2059b633e08cSHans Petter Selasky /* num of objects attached */
2060b633e08cSHans Petter Selasky atomic_t usecnt;
2061b633e08cSHans Petter Selasky };
2062b633e08cSHans Petter Selasky
2063b633e08cSHans Petter Selasky struct ib_counters_read_attr {
2064b633e08cSHans Petter Selasky u64 *counters_buff;
2065b633e08cSHans Petter Selasky u32 ncounters;
2066b633e08cSHans Petter Selasky u32 flags; /* use enum ib_read_counters_flags */
2067b633e08cSHans Petter Selasky };
2068b633e08cSHans Petter Selasky
2069b633e08cSHans Petter Selasky #define INIT_RDMA_OBJ_SIZE(ib_struct, drv_struct, member) \
2070b633e08cSHans Petter Selasky .size_##ib_struct = \
2071b633e08cSHans Petter Selasky (sizeof(struct drv_struct) + \
2072b633e08cSHans Petter Selasky BUILD_BUG_ON_ZERO(offsetof(struct drv_struct, member)) + \
2073b633e08cSHans Petter Selasky BUILD_BUG_ON_ZERO( \
2074b633e08cSHans Petter Selasky !__same_type(((struct drv_struct *)NULL)->member, \
2075b633e08cSHans Petter Selasky struct ib_struct)))
2076b633e08cSHans Petter Selasky
2077b633e08cSHans Petter Selasky #define rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, gfp) \
2078b633e08cSHans Petter Selasky ((struct ib_type *)kzalloc(ib_dev->ops.size_##ib_type, gfp))
2079b633e08cSHans Petter Selasky
2080b633e08cSHans Petter Selasky #define rdma_zalloc_drv_obj(ib_dev, ib_type) \
2081b633e08cSHans Petter Selasky rdma_zalloc_drv_obj_gfp(ib_dev, ib_type, GFP_KERNEL)
2082b633e08cSHans Petter Selasky
2083b633e08cSHans Petter Selasky #define DECLARE_RDMA_OBJ_SIZE(ib_struct) size_t size_##ib_struct
2084b633e08cSHans Petter Selasky
2085b633e08cSHans Petter Selasky struct rdma_user_mmap_entry {
2086b633e08cSHans Petter Selasky struct kref ref;
2087b633e08cSHans Petter Selasky struct ib_ucontext *ucontext;
2088b633e08cSHans Petter Selasky unsigned long start_pgoff;
2089b633e08cSHans Petter Selasky size_t npages;
2090b633e08cSHans Petter Selasky bool driver_removed;
2091b633e08cSHans Petter Selasky };
2092b633e08cSHans Petter Selasky
2093b633e08cSHans Petter Selasky /* Return the offset (in bytes) the user should pass to libc's mmap() */
2094b633e08cSHans Petter Selasky static inline u64
rdma_user_mmap_get_offset(const struct rdma_user_mmap_entry * entry)2095b633e08cSHans Petter Selasky rdma_user_mmap_get_offset(const struct rdma_user_mmap_entry *entry)
2096b633e08cSHans Petter Selasky {
2097b633e08cSHans Petter Selasky return (u64)entry->start_pgoff << PAGE_SHIFT;
2098b633e08cSHans Petter Selasky }
2099b633e08cSHans Petter Selasky
2100b633e08cSHans Petter Selasky struct ib_device_ops {
2101b633e08cSHans Petter Selasky enum rdma_driver_id driver_id;
2102b633e08cSHans Petter Selasky DECLARE_RDMA_OBJ_SIZE(ib_ah);
2103b633e08cSHans Petter Selasky DECLARE_RDMA_OBJ_SIZE(ib_cq);
2104b633e08cSHans Petter Selasky DECLARE_RDMA_OBJ_SIZE(ib_pd);
2105b633e08cSHans Petter Selasky DECLARE_RDMA_OBJ_SIZE(ib_srq);
2106b633e08cSHans Petter Selasky DECLARE_RDMA_OBJ_SIZE(ib_ucontext);
2107b633e08cSHans Petter Selasky };
2108b633e08cSHans Petter Selasky
2109b633e08cSHans Petter Selasky #define INIT_IB_DEVICE_OPS(pop, driver, DRIVER) do { \
2110b633e08cSHans Petter Selasky (pop)[0] .driver_id = RDMA_DRIVER_##DRIVER; \
2111b633e08cSHans Petter Selasky (pop)[0] INIT_RDMA_OBJ_SIZE(ib_ah, driver##_ib_ah, ibah); \
2112b633e08cSHans Petter Selasky (pop)[0] INIT_RDMA_OBJ_SIZE(ib_cq, driver##_ib_cq, ibcq); \
2113b633e08cSHans Petter Selasky (pop)[0] INIT_RDMA_OBJ_SIZE(ib_pd, driver##_ib_pd, ibpd); \
2114b633e08cSHans Petter Selasky (pop)[0] INIT_RDMA_OBJ_SIZE(ib_srq, driver##_ib_srq, ibsrq); \
2115b633e08cSHans Petter Selasky (pop)[0] INIT_RDMA_OBJ_SIZE(ib_ucontext, driver##_ib_ucontext, ibucontext); \
2116b633e08cSHans Petter Selasky } while (0)
2117b633e08cSHans Petter Selasky
2118aa0a1e58SJeff Roberson struct ib_device {
2119aa0a1e58SJeff Roberson struct device *dma_device;
2120b633e08cSHans Petter Selasky struct ib_device_ops ops;
2121aa0a1e58SJeff Roberson
2122aa0a1e58SJeff Roberson char name[IB_DEVICE_NAME_MAX];
2123aa0a1e58SJeff Roberson
2124aa0a1e58SJeff Roberson struct list_head event_handler_list;
2125aa0a1e58SJeff Roberson spinlock_t event_handler_lock;
2126aa0a1e58SJeff Roberson
2127c9f432b7SAlfred Perlstein spinlock_t client_data_lock;
2128aa0a1e58SJeff Roberson struct list_head core_list;
2129478d3005SHans Petter Selasky /* Access to the client_data_list is protected by the client_data_lock
2130478d3005SHans Petter Selasky * spinlock and the lists_rwsem read-write semaphore */
2131aa0a1e58SJeff Roberson struct list_head client_data_list;
2132aa0a1e58SJeff Roberson
2133aa0a1e58SJeff Roberson struct ib_cache cache;
2134478d3005SHans Petter Selasky /**
2135478d3005SHans Petter Selasky * port_immutable is indexed by port number
2136478d3005SHans Petter Selasky */
2137478d3005SHans Petter Selasky struct ib_port_immutable *port_immutable;
2138aa0a1e58SJeff Roberson
2139aa0a1e58SJeff Roberson int num_comp_vectors;
2140aa0a1e58SJeff Roberson
2141aa0a1e58SJeff Roberson struct iw_cm_verbs *iwcm;
2142aa0a1e58SJeff Roberson
2143478d3005SHans Petter Selasky /**
2144478d3005SHans Petter Selasky * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
2145478d3005SHans Petter Selasky * driver initialized data. The struct is kfree()'ed by the sysfs
2146478d3005SHans Petter Selasky * core when the device is removed. A lifespan of -1 in the return
2147478d3005SHans Petter Selasky * struct tells the core to set a default lifespan.
2148478d3005SHans Petter Selasky */
2149478d3005SHans Petter Selasky struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device,
2150478d3005SHans Petter Selasky u8 port_num);
2151478d3005SHans Petter Selasky /**
2152478d3005SHans Petter Selasky * get_hw_stats - Fill in the counter value(s) in the stats struct.
2153478d3005SHans Petter Selasky * @index - The index in the value array we wish to have updated, or
2154478d3005SHans Petter Selasky * num_counters if we want all stats updated
2155478d3005SHans Petter Selasky * Return codes -
2156478d3005SHans Petter Selasky * < 0 - Error, no counters updated
2157478d3005SHans Petter Selasky * index - Updated the single counter pointed to by index
2158478d3005SHans Petter Selasky * num_counters - Updated all counters (will reset the timestamp
2159478d3005SHans Petter Selasky * and prevent further calls for lifespan milliseconds)
2160478d3005SHans Petter Selasky * Drivers are allowed to update all counters in leiu of just the
2161478d3005SHans Petter Selasky * one given in index at their option
2162478d3005SHans Petter Selasky */
2163478d3005SHans Petter Selasky int (*get_hw_stats)(struct ib_device *device,
2164478d3005SHans Petter Selasky struct rdma_hw_stats *stats,
2165478d3005SHans Petter Selasky u8 port, int index);
2166aa0a1e58SJeff Roberson int (*query_device)(struct ib_device *device,
2167478d3005SHans Petter Selasky struct ib_device_attr *device_attr,
2168478d3005SHans Petter Selasky struct ib_udata *udata);
2169aa0a1e58SJeff Roberson int (*query_port)(struct ib_device *device,
2170aa0a1e58SJeff Roberson u8 port_num,
2171aa0a1e58SJeff Roberson struct ib_port_attr *port_attr);
2172aa0a1e58SJeff Roberson enum rdma_link_layer (*get_link_layer)(struct ib_device *device,
2173aa0a1e58SJeff Roberson u8 port_num);
21740bab509bSHans Petter Selasky /* When calling get_netdev, the HW vendor's driver should return the
2175478d3005SHans Petter Selasky * net device of device @device at port @port_num or NULL if such
2176478d3005SHans Petter Selasky * a net device doesn't exist. The vendor driver should call dev_hold
2177478d3005SHans Petter Selasky * on this net device. The HW vendor's device driver must guarantee
2178478d3005SHans Petter Selasky * that this function returns NULL before the net device reaches
21790bab509bSHans Petter Selasky * NETDEV_UNREGISTER_FINAL state.
21800bab509bSHans Petter Selasky */
21813e142e07SJustin Hibbits if_t (*get_netdev)(struct ib_device *device,
21820bab509bSHans Petter Selasky u8 port_num);
2183aa0a1e58SJeff Roberson int (*query_gid)(struct ib_device *device,
2184aa0a1e58SJeff Roberson u8 port_num, int index,
2185aa0a1e58SJeff Roberson union ib_gid *gid);
2186478d3005SHans Petter Selasky /* When calling add_gid, the HW vendor's driver should
2187478d3005SHans Petter Selasky * add the gid of device @device at gid index @index of
2188478d3005SHans Petter Selasky * port @port_num to be @gid. Meta-info of that gid (for example,
2189478d3005SHans Petter Selasky * the network device related to this gid is available
2190478d3005SHans Petter Selasky * at @attr. @context allows the HW vendor driver to store extra
2191478d3005SHans Petter Selasky * information together with a GID entry. The HW vendor may allocate
2192478d3005SHans Petter Selasky * memory to contain this information and store it in @context when a
2193478d3005SHans Petter Selasky * new GID entry is written to. Params are consistent until the next
2194478d3005SHans Petter Selasky * call of add_gid or delete_gid. The function should return 0 on
2195478d3005SHans Petter Selasky * success or error otherwise. The function could be called
2196478d3005SHans Petter Selasky * concurrently for different ports. This function is only called
2197478d3005SHans Petter Selasky * when roce_gid_table is used.
2198478d3005SHans Petter Selasky */
2199478d3005SHans Petter Selasky int (*add_gid)(struct ib_device *device,
2200478d3005SHans Petter Selasky u8 port_num,
2201478d3005SHans Petter Selasky unsigned int index,
2202478d3005SHans Petter Selasky const union ib_gid *gid,
2203478d3005SHans Petter Selasky const struct ib_gid_attr *attr,
2204478d3005SHans Petter Selasky void **context);
2205478d3005SHans Petter Selasky /* When calling del_gid, the HW vendor's driver should delete the
2206478d3005SHans Petter Selasky * gid of device @device at gid index @index of port @port_num.
2207478d3005SHans Petter Selasky * Upon the deletion of a GID entry, the HW vendor must free any
2208478d3005SHans Petter Selasky * allocated memory. The caller will clear @context afterwards.
2209478d3005SHans Petter Selasky * This function is only called when roce_gid_table is used.
2210478d3005SHans Petter Selasky */
2211478d3005SHans Petter Selasky int (*del_gid)(struct ib_device *device,
2212478d3005SHans Petter Selasky u8 port_num,
2213478d3005SHans Petter Selasky unsigned int index,
2214478d3005SHans Petter Selasky void **context);
2215aa0a1e58SJeff Roberson int (*query_pkey)(struct ib_device *device,
2216aa0a1e58SJeff Roberson u8 port_num, u16 index, u16 *pkey);
2217aa0a1e58SJeff Roberson int (*modify_device)(struct ib_device *device,
2218aa0a1e58SJeff Roberson int device_modify_mask,
2219aa0a1e58SJeff Roberson struct ib_device_modify *device_modify);
2220aa0a1e58SJeff Roberson int (*modify_port)(struct ib_device *device,
2221aa0a1e58SJeff Roberson u8 port_num, int port_modify_mask,
2222aa0a1e58SJeff Roberson struct ib_port_modify *port_modify);
2223b633e08cSHans Petter Selasky int (*alloc_ucontext)(struct ib_ucontext *uctx,
2224aa0a1e58SJeff Roberson struct ib_udata *udata);
2225b633e08cSHans Petter Selasky void (*dealloc_ucontext)(struct ib_ucontext *context);
2226aa0a1e58SJeff Roberson int (*mmap)(struct ib_ucontext *context,
2227aa0a1e58SJeff Roberson struct vm_area_struct *vma);
2228b633e08cSHans Petter Selasky int (*alloc_pd)(struct ib_pd *pd,
2229aa0a1e58SJeff Roberson struct ib_udata *udata);
2230b633e08cSHans Petter Selasky void (*dealloc_pd)(struct ib_pd *pd, struct ib_udata *udata);
2231b633e08cSHans Petter Selasky int (*create_ah)(struct ib_ah *ah, struct ib_ah_attr *ah_attr,
2232b633e08cSHans Petter Selasky u32 flags, struct ib_udata *udata);
2233aa0a1e58SJeff Roberson int (*modify_ah)(struct ib_ah *ah,
2234aa0a1e58SJeff Roberson struct ib_ah_attr *ah_attr);
2235aa0a1e58SJeff Roberson int (*query_ah)(struct ib_ah *ah,
2236aa0a1e58SJeff Roberson struct ib_ah_attr *ah_attr);
2237b633e08cSHans Petter Selasky void (*destroy_ah)(struct ib_ah *ah, u32 flags);
2238b633e08cSHans Petter Selasky int (*create_srq)(struct ib_srq *srq,
2239aa0a1e58SJeff Roberson struct ib_srq_init_attr *srq_init_attr,
2240aa0a1e58SJeff Roberson struct ib_udata *udata);
2241aa0a1e58SJeff Roberson int (*modify_srq)(struct ib_srq *srq,
2242aa0a1e58SJeff Roberson struct ib_srq_attr *srq_attr,
2243aa0a1e58SJeff Roberson enum ib_srq_attr_mask srq_attr_mask,
2244aa0a1e58SJeff Roberson struct ib_udata *udata);
2245aa0a1e58SJeff Roberson int (*query_srq)(struct ib_srq *srq,
2246aa0a1e58SJeff Roberson struct ib_srq_attr *srq_attr);
2247b633e08cSHans Petter Selasky void (*destroy_srq)(struct ib_srq *srq, struct ib_udata *udata);
2248aa0a1e58SJeff Roberson int (*post_srq_recv)(struct ib_srq *srq,
2249c3987b8eSHans Petter Selasky const struct ib_recv_wr *recv_wr,
2250c3987b8eSHans Petter Selasky const struct ib_recv_wr **bad_recv_wr);
2251aa0a1e58SJeff Roberson struct ib_qp * (*create_qp)(struct ib_pd *pd,
2252aa0a1e58SJeff Roberson struct ib_qp_init_attr *qp_init_attr,
2253aa0a1e58SJeff Roberson struct ib_udata *udata);
2254aa0a1e58SJeff Roberson int (*modify_qp)(struct ib_qp *qp,
2255aa0a1e58SJeff Roberson struct ib_qp_attr *qp_attr,
2256aa0a1e58SJeff Roberson int qp_attr_mask,
2257aa0a1e58SJeff Roberson struct ib_udata *udata);
2258aa0a1e58SJeff Roberson int (*query_qp)(struct ib_qp *qp,
2259aa0a1e58SJeff Roberson struct ib_qp_attr *qp_attr,
2260aa0a1e58SJeff Roberson int qp_attr_mask,
2261aa0a1e58SJeff Roberson struct ib_qp_init_attr *qp_init_attr);
2262b633e08cSHans Petter Selasky int (*destroy_qp)(struct ib_qp *qp, struct ib_udata *udata);
2263aa0a1e58SJeff Roberson int (*post_send)(struct ib_qp *qp,
2264c3987b8eSHans Petter Selasky const struct ib_send_wr *send_wr,
2265c3987b8eSHans Petter Selasky const struct ib_send_wr **bad_send_wr);
2266aa0a1e58SJeff Roberson int (*post_recv)(struct ib_qp *qp,
2267c3987b8eSHans Petter Selasky const struct ib_recv_wr *recv_wr,
2268c3987b8eSHans Petter Selasky const struct ib_recv_wr **bad_recv_wr);
2269b633e08cSHans Petter Selasky int (*create_cq)(struct ib_cq *,
2270478d3005SHans Petter Selasky const struct ib_cq_init_attr *attr,
2271aa0a1e58SJeff Roberson struct ib_udata *udata);
2272478d3005SHans Petter Selasky int (*modify_cq)(struct ib_cq *cq, u16 cq_count,
2273478d3005SHans Petter Selasky u16 cq_period);
2274b633e08cSHans Petter Selasky void (*destroy_cq)(struct ib_cq *cq, struct ib_udata *udata);
2275aa0a1e58SJeff Roberson int (*resize_cq)(struct ib_cq *cq, int cqe,
2276aa0a1e58SJeff Roberson struct ib_udata *udata);
2277aa0a1e58SJeff Roberson int (*poll_cq)(struct ib_cq *cq, int num_entries,
2278aa0a1e58SJeff Roberson struct ib_wc *wc);
2279aa0a1e58SJeff Roberson int (*peek_cq)(struct ib_cq *cq, int wc_cnt);
2280aa0a1e58SJeff Roberson int (*req_notify_cq)(struct ib_cq *cq,
2281aa0a1e58SJeff Roberson enum ib_cq_notify_flags flags);
2282aa0a1e58SJeff Roberson int (*req_ncomp_notif)(struct ib_cq *cq,
2283aa0a1e58SJeff Roberson int wc_cnt);
2284aa0a1e58SJeff Roberson struct ib_mr * (*get_dma_mr)(struct ib_pd *pd,
2285aa0a1e58SJeff Roberson int mr_access_flags);
2286aa0a1e58SJeff Roberson struct ib_mr * (*reg_user_mr)(struct ib_pd *pd,
2287aa0a1e58SJeff Roberson u64 start, u64 length,
2288aa0a1e58SJeff Roberson u64 virt_addr,
2289aa0a1e58SJeff Roberson int mr_access_flags,
2290478d3005SHans Petter Selasky struct ib_udata *udata);
2291478d3005SHans Petter Selasky int (*rereg_user_mr)(struct ib_mr *mr,
2292478d3005SHans Petter Selasky int flags,
2293478d3005SHans Petter Selasky u64 start, u64 length,
2294478d3005SHans Petter Selasky u64 virt_addr,
2295aa0a1e58SJeff Roberson int mr_access_flags,
2296478d3005SHans Petter Selasky struct ib_pd *pd,
2297478d3005SHans Petter Selasky struct ib_udata *udata);
2298b633e08cSHans Petter Selasky int (*dereg_mr)(struct ib_mr *mr, struct ib_udata *udata);
2299b633e08cSHans Petter Selasky struct ib_mr * (*alloc_mr)(struct ib_pd *pd, enum ib_mr_type mr_type,
2300b633e08cSHans Petter Selasky u32 max_num_sg, struct ib_udata *udata);
2301b633e08cSHans Petter Selasky int (*advise_mr)(struct ib_pd *pd,
2302b633e08cSHans Petter Selasky enum ib_uverbs_advise_mr_advice advice, u32 flags,
2303b633e08cSHans Petter Selasky const struct ib_sge *sg_list, u32 num_sge,
2304b633e08cSHans Petter Selasky struct uverbs_attr_bundle *attrs);
2305478d3005SHans Petter Selasky int (*map_mr_sg)(struct ib_mr *mr,
2306478d3005SHans Petter Selasky struct scatterlist *sg,
2307478d3005SHans Petter Selasky int sg_nents,
2308478d3005SHans Petter Selasky unsigned int *sg_offset);
2309b5c1e0cbSHans Petter Selasky struct ib_mw * (*alloc_mw)(struct ib_pd *pd,
2310478d3005SHans Petter Selasky enum ib_mw_type type,
2311478d3005SHans Petter Selasky struct ib_udata *udata);
2312aa0a1e58SJeff Roberson int (*dealloc_mw)(struct ib_mw *mw);
2313aa0a1e58SJeff Roberson struct ib_fmr * (*alloc_fmr)(struct ib_pd *pd,
2314aa0a1e58SJeff Roberson int mr_access_flags,
2315aa0a1e58SJeff Roberson struct ib_fmr_attr *fmr_attr);
2316aa0a1e58SJeff Roberson int (*map_phys_fmr)(struct ib_fmr *fmr,
2317aa0a1e58SJeff Roberson u64 *page_list, int list_len,
2318aa0a1e58SJeff Roberson u64 iova);
2319aa0a1e58SJeff Roberson int (*unmap_fmr)(struct list_head *fmr_list);
2320aa0a1e58SJeff Roberson int (*dealloc_fmr)(struct ib_fmr *fmr);
2321aa0a1e58SJeff Roberson int (*attach_mcast)(struct ib_qp *qp,
2322aa0a1e58SJeff Roberson union ib_gid *gid,
2323aa0a1e58SJeff Roberson u16 lid);
2324aa0a1e58SJeff Roberson int (*detach_mcast)(struct ib_qp *qp,
2325aa0a1e58SJeff Roberson union ib_gid *gid,
2326aa0a1e58SJeff Roberson u16 lid);
2327aa0a1e58SJeff Roberson int (*process_mad)(struct ib_device *device,
2328aa0a1e58SJeff Roberson int process_mad_flags,
2329aa0a1e58SJeff Roberson u8 port_num,
2330478d3005SHans Petter Selasky const struct ib_wc *in_wc,
2331478d3005SHans Petter Selasky const struct ib_grh *in_grh,
2332478d3005SHans Petter Selasky const struct ib_mad_hdr *in_mad,
2333478d3005SHans Petter Selasky size_t in_mad_size,
2334478d3005SHans Petter Selasky struct ib_mad_hdr *out_mad,
2335478d3005SHans Petter Selasky size_t *out_mad_size,
2336478d3005SHans Petter Selasky u16 *out_mad_pkey_index);
2337aa0a1e58SJeff Roberson struct ib_xrcd * (*alloc_xrcd)(struct ib_device *device,
2338aa0a1e58SJeff Roberson struct ib_udata *udata);
2339b633e08cSHans Petter Selasky int (*dealloc_xrcd)(struct ib_xrcd *xrcd, struct ib_udata *udata);
2340b5c1e0cbSHans Petter Selasky struct ib_flow * (*create_flow)(struct ib_qp *qp,
2341b5c1e0cbSHans Petter Selasky struct ib_flow_attr
2342b5c1e0cbSHans Petter Selasky *flow_attr,
2343b633e08cSHans Petter Selasky int domain, struct ib_udata *udata);
2344b5c1e0cbSHans Petter Selasky int (*destroy_flow)(struct ib_flow *flow_id);
2345b633e08cSHans Petter Selasky struct ib_flow_action *(*create_flow_action_esp)(
2346b633e08cSHans Petter Selasky struct ib_device *device,
2347b633e08cSHans Petter Selasky const struct ib_flow_action_attrs_esp *attr,
2348b633e08cSHans Petter Selasky struct uverbs_attr_bundle *attrs);
2349b633e08cSHans Petter Selasky int (*destroy_flow_action)(struct ib_flow_action *action);
2350b633e08cSHans Petter Selasky int (*modify_flow_action_esp)(
2351b633e08cSHans Petter Selasky struct ib_flow_action *action,
2352b633e08cSHans Petter Selasky const struct ib_flow_action_attrs_esp *attr,
2353b633e08cSHans Petter Selasky struct uverbs_attr_bundle *attrs);
2354b5c1e0cbSHans Petter Selasky int (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
2355b5c1e0cbSHans Petter Selasky struct ib_mr_status *mr_status);
2356b633e08cSHans Petter Selasky /**
2357b633e08cSHans Petter Selasky * This will be called once refcount of an entry in mmap_xa reaches
2358b633e08cSHans Petter Selasky * zero. The type of the memory that was mapped may differ between
2359b633e08cSHans Petter Selasky * entries and is opaque to the rdma_user_mmap interface.
2360b633e08cSHans Petter Selasky * Therefore needs to be implemented by the driver in mmap_free.
2361b633e08cSHans Petter Selasky */
2362b633e08cSHans Petter Selasky void (*mmap_free)(struct rdma_user_mmap_entry *entry);
2363478d3005SHans Petter Selasky void (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
2364478d3005SHans Petter Selasky void (*drain_rq)(struct ib_qp *qp);
2365478d3005SHans Petter Selasky void (*drain_sq)(struct ib_qp *qp);
2366478d3005SHans Petter Selasky int (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
2367478d3005SHans Petter Selasky int state);
2368478d3005SHans Petter Selasky int (*get_vf_config)(struct ib_device *device, int vf, u8 port,
2369478d3005SHans Petter Selasky struct ifla_vf_info *ivf);
2370478d3005SHans Petter Selasky int (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
2371478d3005SHans Petter Selasky struct ifla_vf_stats *stats);
2372478d3005SHans Petter Selasky int (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
2373478d3005SHans Petter Selasky int type);
2374478d3005SHans Petter Selasky struct ib_wq * (*create_wq)(struct ib_pd *pd,
2375478d3005SHans Petter Selasky struct ib_wq_init_attr *init_attr,
2376478d3005SHans Petter Selasky struct ib_udata *udata);
2377b633e08cSHans Petter Selasky void (*destroy_wq)(struct ib_wq *wq, struct ib_udata *udata);
2378478d3005SHans Petter Selasky int (*modify_wq)(struct ib_wq *wq,
2379478d3005SHans Petter Selasky struct ib_wq_attr *attr,
2380478d3005SHans Petter Selasky u32 wq_attr_mask,
2381478d3005SHans Petter Selasky struct ib_udata *udata);
2382478d3005SHans Petter Selasky struct ib_rwq_ind_table * (*create_rwq_ind_table)(struct ib_device *device,
2383478d3005SHans Petter Selasky struct ib_rwq_ind_table_init_attr *init_attr,
2384478d3005SHans Petter Selasky struct ib_udata *udata);
2385478d3005SHans Petter Selasky int (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
2386b633e08cSHans Petter Selasky struct ib_dm *(*alloc_dm)(struct ib_device *device,
2387b633e08cSHans Petter Selasky struct ib_ucontext *context,
2388b633e08cSHans Petter Selasky struct ib_dm_alloc_attr *attr,
2389b633e08cSHans Petter Selasky struct uverbs_attr_bundle *attrs);
2390b633e08cSHans Petter Selasky int (*dealloc_dm)(struct ib_dm *dm, struct uverbs_attr_bundle *attrs);
2391b633e08cSHans Petter Selasky struct ib_mr *(*reg_dm_mr)(struct ib_pd *pd, struct ib_dm *dm,
2392b633e08cSHans Petter Selasky struct ib_dm_mr_attr *attr,
2393b633e08cSHans Petter Selasky struct uverbs_attr_bundle *attrs);
2394b633e08cSHans Petter Selasky struct ib_counters *(*create_counters)(
2395b633e08cSHans Petter Selasky struct ib_device *device, struct uverbs_attr_bundle *attrs);
2396b633e08cSHans Petter Selasky int (*destroy_counters)(struct ib_counters *counters);
2397b633e08cSHans Petter Selasky int (*read_counters)(struct ib_counters *counters,
2398b633e08cSHans Petter Selasky struct ib_counters_read_attr *counters_read_attr,
2399b633e08cSHans Petter Selasky struct uverbs_attr_bundle *attrs);
2400aa0a1e58SJeff Roberson struct ib_dma_mapping_ops *dma_ops;
2401aa0a1e58SJeff Roberson
2402aa0a1e58SJeff Roberson struct module *owner;
2403aa0a1e58SJeff Roberson struct device dev;
2404aa0a1e58SJeff Roberson struct kobject *ports_parent;
2405aa0a1e58SJeff Roberson struct list_head port_list;
2406aa0a1e58SJeff Roberson
2407aa0a1e58SJeff Roberson enum {
2408aa0a1e58SJeff Roberson IB_DEV_UNINITIALIZED,
2409aa0a1e58SJeff Roberson IB_DEV_REGISTERED,
2410aa0a1e58SJeff Roberson IB_DEV_UNREGISTERED
2411aa0a1e58SJeff Roberson } reg_state;
2412aa0a1e58SJeff Roberson
2413aa0a1e58SJeff Roberson int uverbs_abi_ver;
2414c9f432b7SAlfred Perlstein u64 uverbs_cmd_mask;
2415b5c1e0cbSHans Petter Selasky u64 uverbs_ex_cmd_mask;
2416aa0a1e58SJeff Roberson
2417478d3005SHans Petter Selasky char node_desc[IB_DEVICE_NODE_DESC_MAX];
2418aa0a1e58SJeff Roberson __be64 node_guid;
2419aa0a1e58SJeff Roberson u32 local_dma_lkey;
2420478d3005SHans Petter Selasky u16 is_switch:1;
2421aa0a1e58SJeff Roberson u8 node_type;
2422aa0a1e58SJeff Roberson u8 phys_port_cnt;
2423478d3005SHans Petter Selasky struct ib_device_attr attrs;
2424478d3005SHans Petter Selasky struct attribute_group *hw_stats_ag;
2425478d3005SHans Petter Selasky struct rdma_hw_stats *hw_stats;
2426b5c1e0cbSHans Petter Selasky
2427b633e08cSHans Petter Selasky const struct uapi_definition *driver_def;
2428b633e08cSHans Petter Selasky
2429478d3005SHans Petter Selasky /**
2430478d3005SHans Petter Selasky * The following mandatory functions are used only at device
2431478d3005SHans Petter Selasky * registration. Keep functions such as these at the end of this
2432478d3005SHans Petter Selasky * structure to avoid cache line misses when accessing struct ib_device
2433478d3005SHans Petter Selasky * in fast paths.
2434b5c1e0cbSHans Petter Selasky */
2435478d3005SHans Petter Selasky int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
2436478d3005SHans Petter Selasky void (*get_dev_fw_str)(struct ib_device *, char *str, size_t str_len);
2437aa0a1e58SJeff Roberson };
2438aa0a1e58SJeff Roberson
2439aa0a1e58SJeff Roberson struct ib_client {
2440aa0a1e58SJeff Roberson char *name;
2441aa0a1e58SJeff Roberson void (*add) (struct ib_device *);
2442478d3005SHans Petter Selasky void (*remove)(struct ib_device *, void *client_data);
2443aa0a1e58SJeff Roberson
2444478d3005SHans Petter Selasky /* Returns the net_dev belonging to this ib_client and matching the
2445478d3005SHans Petter Selasky * given parameters.
2446478d3005SHans Petter Selasky * @dev: An RDMA device that the net_dev use for communication.
2447478d3005SHans Petter Selasky * @port: A physical port number on the RDMA device.
2448478d3005SHans Petter Selasky * @pkey: P_Key that the net_dev uses if applicable.
2449478d3005SHans Petter Selasky * @gid: A GID that the net_dev uses to communicate.
2450478d3005SHans Petter Selasky * @addr: An IP address the net_dev is configured with.
2451478d3005SHans Petter Selasky * @client_data: The device's client data set by ib_set_client_data().
2452478d3005SHans Petter Selasky *
2453478d3005SHans Petter Selasky * An ib_client that implements a net_dev on top of RDMA devices
2454478d3005SHans Petter Selasky * (such as IP over IB) should implement this callback, allowing the
2455478d3005SHans Petter Selasky * rdma_cm module to find the right net_dev for a given request.
2456478d3005SHans Petter Selasky *
2457478d3005SHans Petter Selasky * The caller is responsible for calling dev_put on the returned
2458478d3005SHans Petter Selasky * netdev. */
24593e142e07SJustin Hibbits if_t (*get_net_dev_by_params)(
2460478d3005SHans Petter Selasky struct ib_device *dev,
2461478d3005SHans Petter Selasky u8 port,
2462478d3005SHans Petter Selasky u16 pkey,
2463478d3005SHans Petter Selasky const union ib_gid *gid,
2464478d3005SHans Petter Selasky const struct sockaddr *addr,
2465478d3005SHans Petter Selasky void *client_data);
2466aa0a1e58SJeff Roberson struct list_head list;
2467aa0a1e58SJeff Roberson };
2468aa0a1e58SJeff Roberson
2469aa0a1e58SJeff Roberson struct ib_device *ib_alloc_device(size_t size);
2470aa0a1e58SJeff Roberson void ib_dealloc_device(struct ib_device *device);
2471aa0a1e58SJeff Roberson
2472478d3005SHans Petter Selasky void ib_get_device_fw_str(struct ib_device *device, char *str, size_t str_len);
2473478d3005SHans Petter Selasky
2474c9f432b7SAlfred Perlstein int ib_register_device(struct ib_device *device,
2475c9f432b7SAlfred Perlstein int (*port_callback)(struct ib_device *,
2476c9f432b7SAlfred Perlstein u8, struct kobject *));
2477aa0a1e58SJeff Roberson void ib_unregister_device(struct ib_device *device);
2478aa0a1e58SJeff Roberson
2479aa0a1e58SJeff Roberson int ib_register_client (struct ib_client *client);
2480aa0a1e58SJeff Roberson void ib_unregister_client(struct ib_client *client);
2481aa0a1e58SJeff Roberson
2482aa0a1e58SJeff Roberson void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
2483aa0a1e58SJeff Roberson void ib_set_client_data(struct ib_device *device, struct ib_client *client,
2484aa0a1e58SJeff Roberson void *data);
2485aa0a1e58SJeff Roberson
2486b633e08cSHans Petter Selasky int rdma_user_mmap_io(struct ib_ucontext *ucontext, struct vm_area_struct *vma,
2487b633e08cSHans Petter Selasky unsigned long pfn, unsigned long size, pgprot_t prot,
2488b633e08cSHans Petter Selasky struct rdma_user_mmap_entry *entry);
2489b633e08cSHans Petter Selasky int rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
2490b633e08cSHans Petter Selasky struct rdma_user_mmap_entry *entry,
2491b633e08cSHans Petter Selasky size_t length);
2492b633e08cSHans Petter Selasky int rdma_user_mmap_entry_insert_range(struct ib_ucontext *ucontext,
2493b633e08cSHans Petter Selasky struct rdma_user_mmap_entry *entry,
2494b633e08cSHans Petter Selasky size_t length, u32 min_pgoff,
2495b633e08cSHans Petter Selasky u32 max_pgoff);
2496b633e08cSHans Petter Selasky
2497b633e08cSHans Petter Selasky struct rdma_user_mmap_entry *
2498b633e08cSHans Petter Selasky rdma_user_mmap_entry_get_pgoff(struct ib_ucontext *ucontext,
2499b633e08cSHans Petter Selasky unsigned long pgoff);
2500b633e08cSHans Petter Selasky struct rdma_user_mmap_entry *
2501b633e08cSHans Petter Selasky rdma_user_mmap_entry_get(struct ib_ucontext *ucontext,
2502b633e08cSHans Petter Selasky struct vm_area_struct *vma);
2503b633e08cSHans Petter Selasky void rdma_user_mmap_entry_put(struct rdma_user_mmap_entry *entry);
2504b633e08cSHans Petter Selasky
2505b633e08cSHans Petter Selasky void rdma_user_mmap_entry_remove(struct rdma_user_mmap_entry *entry);
ib_copy_from_udata(void * dest,struct ib_udata * udata,size_t len)2506aa0a1e58SJeff Roberson static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
2507aa0a1e58SJeff Roberson {
2508478d3005SHans Petter Selasky return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
2509aa0a1e58SJeff Roberson }
2510aa0a1e58SJeff Roberson
ib_copy_to_udata(struct ib_udata * udata,void * src,size_t len)2511aa0a1e58SJeff Roberson static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
2512aa0a1e58SJeff Roberson {
2513478d3005SHans Petter Selasky return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
2514478d3005SHans Petter Selasky }
2515478d3005SHans Petter Selasky
ib_is_buffer_cleared(const void __user * p,size_t len)2516b633e08cSHans Petter Selasky static inline bool ib_is_buffer_cleared(const void __user *p,
2517478d3005SHans Petter Selasky size_t len)
2518478d3005SHans Petter Selasky {
2519478d3005SHans Petter Selasky bool ret;
2520478d3005SHans Petter Selasky u8 *buf;
2521478d3005SHans Petter Selasky
2522478d3005SHans Petter Selasky if (len > USHRT_MAX)
2523478d3005SHans Petter Selasky return false;
2524478d3005SHans Petter Selasky
2525478d3005SHans Petter Selasky buf = memdup_user(p, len);
2526478d3005SHans Petter Selasky if (IS_ERR(buf))
2527478d3005SHans Petter Selasky return false;
2528478d3005SHans Petter Selasky
2529478d3005SHans Petter Selasky ret = !memchr_inv(buf, 0, len);
2530478d3005SHans Petter Selasky kfree(buf);
2531478d3005SHans Petter Selasky return ret;
2532aa0a1e58SJeff Roberson }
2533aa0a1e58SJeff Roberson
ib_is_udata_cleared(struct ib_udata * udata,size_t offset,size_t len)2534b633e08cSHans Petter Selasky static inline bool ib_is_udata_cleared(struct ib_udata *udata,
2535b633e08cSHans Petter Selasky size_t offset,
2536b633e08cSHans Petter Selasky size_t len)
2537b633e08cSHans Petter Selasky {
2538b633e08cSHans Petter Selasky return ib_is_buffer_cleared(udata->inbuf + offset, len);
2539b633e08cSHans Petter Selasky }
2540b633e08cSHans Petter Selasky
2541aa0a1e58SJeff Roberson /**
2542f60da09dSHans Petter Selasky * ib_is_destroy_retryable - Check whether the uobject destruction
2543f60da09dSHans Petter Selasky * is retryable.
2544f60da09dSHans Petter Selasky * @ret: The initial destruction return code
2545f60da09dSHans Petter Selasky * @why: remove reason
2546f60da09dSHans Petter Selasky * @uobj: The uobject that is destroyed
2547f60da09dSHans Petter Selasky *
2548f60da09dSHans Petter Selasky * This function is a helper function that IB layer and low-level drivers
2549f60da09dSHans Petter Selasky * can use to consider whether the destruction of the given uobject is
2550f60da09dSHans Petter Selasky * retry-able.
2551f60da09dSHans Petter Selasky * It checks the original return code, if it wasn't success the destruction
2552f60da09dSHans Petter Selasky * is retryable according to the ucontext state (i.e. cleanup_retryable) and
2553f60da09dSHans Petter Selasky * the remove reason. (i.e. why).
2554f60da09dSHans Petter Selasky * Must be called with the object locked for destroy.
2555f60da09dSHans Petter Selasky */
ib_is_destroy_retryable(int ret,enum rdma_remove_reason why,struct ib_uobject * uobj)2556f60da09dSHans Petter Selasky static inline bool ib_is_destroy_retryable(int ret, enum rdma_remove_reason why,
2557f60da09dSHans Petter Selasky struct ib_uobject *uobj)
2558f60da09dSHans Petter Selasky {
2559f60da09dSHans Petter Selasky return ret && (why == RDMA_REMOVE_DESTROY ||
2560f60da09dSHans Petter Selasky uobj->context->cleanup_retryable);
2561f60da09dSHans Petter Selasky }
2562f60da09dSHans Petter Selasky
2563f60da09dSHans Petter Selasky /**
2564f60da09dSHans Petter Selasky * ib_destroy_usecnt - Called during destruction to check the usecnt
2565f60da09dSHans Petter Selasky * @usecnt: The usecnt atomic
2566f60da09dSHans Petter Selasky * @why: remove reason
2567f60da09dSHans Petter Selasky * @uobj: The uobject that is destroyed
2568f60da09dSHans Petter Selasky *
2569f60da09dSHans Petter Selasky * Non-zero usecnts will block destruction unless destruction was triggered by
2570f60da09dSHans Petter Selasky * a ucontext cleanup.
2571f60da09dSHans Petter Selasky */
ib_destroy_usecnt(atomic_t * usecnt,enum rdma_remove_reason why,struct ib_uobject * uobj)2572f60da09dSHans Petter Selasky static inline int ib_destroy_usecnt(atomic_t *usecnt,
2573f60da09dSHans Petter Selasky enum rdma_remove_reason why,
2574f60da09dSHans Petter Selasky struct ib_uobject *uobj)
2575f60da09dSHans Petter Selasky {
2576f60da09dSHans Petter Selasky if (atomic_read(usecnt) && ib_is_destroy_retryable(-EBUSY, why, uobj))
2577f60da09dSHans Petter Selasky return -EBUSY;
2578f60da09dSHans Petter Selasky return 0;
2579f60da09dSHans Petter Selasky }
2580f60da09dSHans Petter Selasky
2581f60da09dSHans Petter Selasky /**
2582aa0a1e58SJeff Roberson * ib_modify_qp_is_ok - Check that the supplied attribute mask
2583aa0a1e58SJeff Roberson * contains all required attributes and no attributes not allowed for
2584aa0a1e58SJeff Roberson * the given QP state transition.
2585aa0a1e58SJeff Roberson * @cur_state: Current QP state
2586aa0a1e58SJeff Roberson * @next_state: Next QP state
2587aa0a1e58SJeff Roberson * @type: QP type
2588aa0a1e58SJeff Roberson * @mask: Mask of supplied QP attributes
2589aa0a1e58SJeff Roberson *
2590aa0a1e58SJeff Roberson * This function is a helper function that a low-level driver's
2591aa0a1e58SJeff Roberson * modify_qp method can use to validate the consumer's input. It
2592aa0a1e58SJeff Roberson * checks that cur_state and next_state are valid QP states, that a
2593aa0a1e58SJeff Roberson * transition from cur_state to next_state is allowed by the IB spec,
2594aa0a1e58SJeff Roberson * and that the attribute mask supplied is allowed for the transition.
2595aa0a1e58SJeff Roberson */
2596d92a9e56SHans Petter Selasky bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
2597d92a9e56SHans Petter Selasky enum ib_qp_type type, enum ib_qp_attr_mask mask);
2598aa0a1e58SJeff Roberson
2599aa0a1e58SJeff Roberson int ib_register_event_handler (struct ib_event_handler *event_handler);
2600aa0a1e58SJeff Roberson int ib_unregister_event_handler(struct ib_event_handler *event_handler);
2601aa0a1e58SJeff Roberson void ib_dispatch_event(struct ib_event *event);
2602aa0a1e58SJeff Roberson
2603aa0a1e58SJeff Roberson int ib_query_port(struct ib_device *device,
2604aa0a1e58SJeff Roberson u8 port_num, struct ib_port_attr *port_attr);
2605aa0a1e58SJeff Roberson
2606aa0a1e58SJeff Roberson enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
2607aa0a1e58SJeff Roberson u8 port_num);
2608aa0a1e58SJeff Roberson
2609478d3005SHans Petter Selasky /**
2610478d3005SHans Petter Selasky * rdma_cap_ib_switch - Check if the device is IB switch
2611478d3005SHans Petter Selasky * @device: Device to check
2612478d3005SHans Petter Selasky *
2613478d3005SHans Petter Selasky * Device driver is responsible for setting is_switch bit on
2614478d3005SHans Petter Selasky * in ib_device structure at init time.
2615478d3005SHans Petter Selasky *
2616478d3005SHans Petter Selasky * Return: true if the device is IB switch.
2617478d3005SHans Petter Selasky */
rdma_cap_ib_switch(const struct ib_device * device)2618478d3005SHans Petter Selasky static inline bool rdma_cap_ib_switch(const struct ib_device *device)
2619478d3005SHans Petter Selasky {
2620478d3005SHans Petter Selasky return device->is_switch;
2621478d3005SHans Petter Selasky }
2622478d3005SHans Petter Selasky
2623478d3005SHans Petter Selasky /**
2624478d3005SHans Petter Selasky * rdma_start_port - Return the first valid port number for the device
2625478d3005SHans Petter Selasky * specified
2626478d3005SHans Petter Selasky *
2627478d3005SHans Petter Selasky * @device: Device to be checked
2628478d3005SHans Petter Selasky *
2629478d3005SHans Petter Selasky * Return start port number
2630478d3005SHans Petter Selasky */
rdma_start_port(const struct ib_device * device)2631478d3005SHans Petter Selasky static inline u8 rdma_start_port(const struct ib_device *device)
2632478d3005SHans Petter Selasky {
2633478d3005SHans Petter Selasky return rdma_cap_ib_switch(device) ? 0 : 1;
2634478d3005SHans Petter Selasky }
2635478d3005SHans Petter Selasky
2636478d3005SHans Petter Selasky /**
2637478d3005SHans Petter Selasky * rdma_end_port - Return the last valid port number for the device
2638478d3005SHans Petter Selasky * specified
2639478d3005SHans Petter Selasky *
2640478d3005SHans Petter Selasky * @device: Device to be checked
2641478d3005SHans Petter Selasky *
2642478d3005SHans Petter Selasky * Return last port number
2643478d3005SHans Petter Selasky */
rdma_end_port(const struct ib_device * device)2644478d3005SHans Petter Selasky static inline u8 rdma_end_port(const struct ib_device *device)
2645478d3005SHans Petter Selasky {
2646478d3005SHans Petter Selasky return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
2647478d3005SHans Petter Selasky }
2648478d3005SHans Petter Selasky
rdma_is_port_valid(const struct ib_device * device,unsigned int port)2649f736cb92SHans Petter Selasky static inline int rdma_is_port_valid(const struct ib_device *device,
2650f736cb92SHans Petter Selasky unsigned int port)
2651f736cb92SHans Petter Selasky {
2652f736cb92SHans Petter Selasky return (port >= rdma_start_port(device) &&
2653f736cb92SHans Petter Selasky port <= rdma_end_port(device));
2654f736cb92SHans Petter Selasky }
2655f736cb92SHans Petter Selasky
rdma_protocol_ib(const struct ib_device * device,u8 port_num)2656478d3005SHans Petter Selasky static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
2657478d3005SHans Petter Selasky {
2658478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
2659478d3005SHans Petter Selasky }
2660478d3005SHans Petter Selasky
rdma_protocol_roce(const struct ib_device * device,u8 port_num)2661478d3005SHans Petter Selasky static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
2662478d3005SHans Petter Selasky {
2663478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags &
2664478d3005SHans Petter Selasky (RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
2665478d3005SHans Petter Selasky }
2666478d3005SHans Petter Selasky
rdma_protocol_roce_udp_encap(const struct ib_device * device,u8 port_num)2667478d3005SHans Petter Selasky static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
2668478d3005SHans Petter Selasky {
2669478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
2670478d3005SHans Petter Selasky }
2671478d3005SHans Petter Selasky
rdma_protocol_roce_eth_encap(const struct ib_device * device,u8 port_num)2672478d3005SHans Petter Selasky static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
2673478d3005SHans Petter Selasky {
2674478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
2675478d3005SHans Petter Selasky }
2676478d3005SHans Petter Selasky
rdma_protocol_iwarp(const struct ib_device * device,u8 port_num)2677478d3005SHans Petter Selasky static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
2678478d3005SHans Petter Selasky {
2679478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
2680478d3005SHans Petter Selasky }
2681478d3005SHans Petter Selasky
rdma_ib_or_roce(const struct ib_device * device,u8 port_num)2682478d3005SHans Petter Selasky static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
2683478d3005SHans Petter Selasky {
2684478d3005SHans Petter Selasky return rdma_protocol_ib(device, port_num) ||
2685478d3005SHans Petter Selasky rdma_protocol_roce(device, port_num);
2686478d3005SHans Petter Selasky }
2687478d3005SHans Petter Selasky
2688478d3005SHans Petter Selasky /**
2689478d3005SHans Petter Selasky * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
2690478d3005SHans Petter Selasky * Management Datagrams.
2691478d3005SHans Petter Selasky * @device: Device to check
2692478d3005SHans Petter Selasky * @port_num: Port number to check
2693478d3005SHans Petter Selasky *
2694478d3005SHans Petter Selasky * Management Datagrams (MAD) are a required part of the InfiniBand
2695478d3005SHans Petter Selasky * specification and are supported on all InfiniBand devices. A slightly
2696478d3005SHans Petter Selasky * extended version are also supported on OPA interfaces.
2697478d3005SHans Petter Selasky *
2698478d3005SHans Petter Selasky * Return: true if the port supports sending/receiving of MAD packets.
2699478d3005SHans Petter Selasky */
rdma_cap_ib_mad(const struct ib_device * device,u8 port_num)2700478d3005SHans Petter Selasky static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
2701478d3005SHans Petter Selasky {
2702478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
2703478d3005SHans Petter Selasky }
2704478d3005SHans Petter Selasky
2705478d3005SHans Petter Selasky /**
2706478d3005SHans Petter Selasky * rdma_cap_opa_mad - Check if the port of device provides support for OPA
2707478d3005SHans Petter Selasky * Management Datagrams.
2708478d3005SHans Petter Selasky * @device: Device to check
2709478d3005SHans Petter Selasky * @port_num: Port number to check
2710478d3005SHans Petter Selasky *
2711478d3005SHans Petter Selasky * Intel OmniPath devices extend and/or replace the InfiniBand Management
2712478d3005SHans Petter Selasky * datagrams with their own versions. These OPA MADs share many but not all of
2713478d3005SHans Petter Selasky * the characteristics of InfiniBand MADs.
2714478d3005SHans Petter Selasky *
2715478d3005SHans Petter Selasky * OPA MADs differ in the following ways:
2716478d3005SHans Petter Selasky *
2717478d3005SHans Petter Selasky * 1) MADs are variable size up to 2K
2718478d3005SHans Petter Selasky * IBTA defined MADs remain fixed at 256 bytes
2719478d3005SHans Petter Selasky * 2) OPA SMPs must carry valid PKeys
2720478d3005SHans Petter Selasky * 3) OPA SMP packets are a different format
2721478d3005SHans Petter Selasky *
2722478d3005SHans Petter Selasky * Return: true if the port supports OPA MAD packet formats.
2723478d3005SHans Petter Selasky */
rdma_cap_opa_mad(struct ib_device * device,u8 port_num)2724478d3005SHans Petter Selasky static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
2725478d3005SHans Petter Selasky {
2726478d3005SHans Petter Selasky return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD)
2727478d3005SHans Petter Selasky == RDMA_CORE_CAP_OPA_MAD;
2728478d3005SHans Petter Selasky }
2729478d3005SHans Petter Selasky
2730478d3005SHans Petter Selasky /**
2731478d3005SHans Petter Selasky * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
2732478d3005SHans Petter Selasky * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
2733478d3005SHans Petter Selasky * @device: Device to check
2734478d3005SHans Petter Selasky * @port_num: Port number to check
2735478d3005SHans Petter Selasky *
2736478d3005SHans Petter Selasky * Each InfiniBand node is required to provide a Subnet Management Agent
2737478d3005SHans Petter Selasky * that the subnet manager can access. Prior to the fabric being fully
2738478d3005SHans Petter Selasky * configured by the subnet manager, the SMA is accessed via a well known
2739478d3005SHans Petter Selasky * interface called the Subnet Management Interface (SMI). This interface
2740478d3005SHans Petter Selasky * uses directed route packets to communicate with the SM to get around the
2741478d3005SHans Petter Selasky * chicken and egg problem of the SM needing to know what's on the fabric
2742478d3005SHans Petter Selasky * in order to configure the fabric, and needing to configure the fabric in
2743478d3005SHans Petter Selasky * order to send packets to the devices on the fabric. These directed
2744478d3005SHans Petter Selasky * route packets do not need the fabric fully configured in order to reach
2745478d3005SHans Petter Selasky * their destination. The SMI is the only method allowed to send
2746478d3005SHans Petter Selasky * directed route packets on an InfiniBand fabric.
2747478d3005SHans Petter Selasky *
2748478d3005SHans Petter Selasky * Return: true if the port provides an SMI.
2749478d3005SHans Petter Selasky */
rdma_cap_ib_smi(const struct ib_device * device,u8 port_num)2750478d3005SHans Petter Selasky static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
2751478d3005SHans Petter Selasky {
2752478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
2753478d3005SHans Petter Selasky }
2754478d3005SHans Petter Selasky
2755478d3005SHans Petter Selasky /**
2756478d3005SHans Petter Selasky * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
2757478d3005SHans Petter Selasky * Communication Manager.
2758478d3005SHans Petter Selasky * @device: Device to check
2759478d3005SHans Petter Selasky * @port_num: Port number to check
2760478d3005SHans Petter Selasky *
2761478d3005SHans Petter Selasky * The InfiniBand Communication Manager is one of many pre-defined General
2762478d3005SHans Petter Selasky * Service Agents (GSA) that are accessed via the General Service
2763478d3005SHans Petter Selasky * Interface (GSI). It's role is to facilitate establishment of connections
2764478d3005SHans Petter Selasky * between nodes as well as other management related tasks for established
2765478d3005SHans Petter Selasky * connections.
2766478d3005SHans Petter Selasky *
2767478d3005SHans Petter Selasky * Return: true if the port supports an IB CM (this does not guarantee that
2768478d3005SHans Petter Selasky * a CM is actually running however).
2769478d3005SHans Petter Selasky */
rdma_cap_ib_cm(const struct ib_device * device,u8 port_num)2770478d3005SHans Petter Selasky static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
2771478d3005SHans Petter Selasky {
2772478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
2773478d3005SHans Petter Selasky }
2774478d3005SHans Petter Selasky
2775478d3005SHans Petter Selasky /**
2776478d3005SHans Petter Selasky * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
2777478d3005SHans Petter Selasky * Communication Manager.
2778478d3005SHans Petter Selasky * @device: Device to check
2779478d3005SHans Petter Selasky * @port_num: Port number to check
2780478d3005SHans Petter Selasky *
2781478d3005SHans Petter Selasky * Similar to above, but specific to iWARP connections which have a different
2782478d3005SHans Petter Selasky * managment protocol than InfiniBand.
2783478d3005SHans Petter Selasky *
2784478d3005SHans Petter Selasky * Return: true if the port supports an iWARP CM (this does not guarantee that
2785478d3005SHans Petter Selasky * a CM is actually running however).
2786478d3005SHans Petter Selasky */
rdma_cap_iw_cm(const struct ib_device * device,u8 port_num)2787478d3005SHans Petter Selasky static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
2788478d3005SHans Petter Selasky {
2789478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
2790478d3005SHans Petter Selasky }
2791478d3005SHans Petter Selasky
2792478d3005SHans Petter Selasky /**
2793478d3005SHans Petter Selasky * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
2794478d3005SHans Petter Selasky * Subnet Administration.
2795478d3005SHans Petter Selasky * @device: Device to check
2796478d3005SHans Petter Selasky * @port_num: Port number to check
2797478d3005SHans Petter Selasky *
2798478d3005SHans Petter Selasky * An InfiniBand Subnet Administration (SA) service is a pre-defined General
2799478d3005SHans Petter Selasky * Service Agent (GSA) provided by the Subnet Manager (SM). On InfiniBand
2800478d3005SHans Petter Selasky * fabrics, devices should resolve routes to other hosts by contacting the
2801478d3005SHans Petter Selasky * SA to query the proper route.
2802478d3005SHans Petter Selasky *
2803478d3005SHans Petter Selasky * Return: true if the port should act as a client to the fabric Subnet
2804478d3005SHans Petter Selasky * Administration interface. This does not imply that the SA service is
2805478d3005SHans Petter Selasky * running locally.
2806478d3005SHans Petter Selasky */
rdma_cap_ib_sa(const struct ib_device * device,u8 port_num)2807478d3005SHans Petter Selasky static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
2808478d3005SHans Petter Selasky {
2809478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
2810478d3005SHans Petter Selasky }
2811478d3005SHans Petter Selasky
2812478d3005SHans Petter Selasky /**
2813478d3005SHans Petter Selasky * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
2814478d3005SHans Petter Selasky * Multicast.
2815478d3005SHans Petter Selasky * @device: Device to check
2816478d3005SHans Petter Selasky * @port_num: Port number to check
2817478d3005SHans Petter Selasky *
2818478d3005SHans Petter Selasky * InfiniBand multicast registration is more complex than normal IPv4 or
2819478d3005SHans Petter Selasky * IPv6 multicast registration. Each Host Channel Adapter must register
2820478d3005SHans Petter Selasky * with the Subnet Manager when it wishes to join a multicast group. It
2821478d3005SHans Petter Selasky * should do so only once regardless of how many queue pairs it subscribes
2822478d3005SHans Petter Selasky * to this group. And it should leave the group only after all queue pairs
2823478d3005SHans Petter Selasky * attached to the group have been detached.
2824478d3005SHans Petter Selasky *
2825478d3005SHans Petter Selasky * Return: true if the port must undertake the additional adminstrative
2826478d3005SHans Petter Selasky * overhead of registering/unregistering with the SM and tracking of the
2827478d3005SHans Petter Selasky * total number of queue pairs attached to the multicast group.
2828478d3005SHans Petter Selasky */
rdma_cap_ib_mcast(const struct ib_device * device,u8 port_num)2829478d3005SHans Petter Selasky static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
2830478d3005SHans Petter Selasky {
2831478d3005SHans Petter Selasky return rdma_cap_ib_sa(device, port_num);
2832478d3005SHans Petter Selasky }
2833478d3005SHans Petter Selasky
2834478d3005SHans Petter Selasky /**
2835478d3005SHans Petter Selasky * rdma_cap_af_ib - Check if the port of device has the capability
2836478d3005SHans Petter Selasky * Native Infiniband Address.
2837478d3005SHans Petter Selasky * @device: Device to check
2838478d3005SHans Petter Selasky * @port_num: Port number to check
2839478d3005SHans Petter Selasky *
2840478d3005SHans Petter Selasky * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
2841478d3005SHans Petter Selasky * GID. RoCE uses a different mechanism, but still generates a GID via
2842478d3005SHans Petter Selasky * a prescribed mechanism and port specific data.
2843478d3005SHans Petter Selasky *
2844478d3005SHans Petter Selasky * Return: true if the port uses a GID address to identify devices on the
2845478d3005SHans Petter Selasky * network.
2846478d3005SHans Petter Selasky */
rdma_cap_af_ib(const struct ib_device * device,u8 port_num)2847478d3005SHans Petter Selasky static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
2848478d3005SHans Petter Selasky {
2849478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
2850478d3005SHans Petter Selasky }
2851478d3005SHans Petter Selasky
2852478d3005SHans Petter Selasky /**
2853478d3005SHans Petter Selasky * rdma_cap_eth_ah - Check if the port of device has the capability
2854478d3005SHans Petter Selasky * Ethernet Address Handle.
2855478d3005SHans Petter Selasky * @device: Device to check
2856478d3005SHans Petter Selasky * @port_num: Port number to check
2857478d3005SHans Petter Selasky *
2858478d3005SHans Petter Selasky * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
2859478d3005SHans Petter Selasky * to fabricate GIDs over Ethernet/IP specific addresses native to the
2860478d3005SHans Petter Selasky * port. Normally, packet headers are generated by the sending host
2861478d3005SHans Petter Selasky * adapter, but when sending connectionless datagrams, we must manually
2862478d3005SHans Petter Selasky * inject the proper headers for the fabric we are communicating over.
2863478d3005SHans Petter Selasky *
2864478d3005SHans Petter Selasky * Return: true if we are running as a RoCE port and must force the
2865478d3005SHans Petter Selasky * addition of a Global Route Header built from our Ethernet Address
2866478d3005SHans Petter Selasky * Handle into our header list for connectionless packets.
2867478d3005SHans Petter Selasky */
rdma_cap_eth_ah(const struct ib_device * device,u8 port_num)2868478d3005SHans Petter Selasky static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
2869478d3005SHans Petter Selasky {
2870478d3005SHans Petter Selasky return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
2871478d3005SHans Petter Selasky }
2872478d3005SHans Petter Selasky
2873478d3005SHans Petter Selasky /**
2874478d3005SHans Petter Selasky * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
2875478d3005SHans Petter Selasky *
2876478d3005SHans Petter Selasky * @device: Device
2877478d3005SHans Petter Selasky * @port_num: Port number
2878478d3005SHans Petter Selasky *
2879478d3005SHans Petter Selasky * This MAD size includes the MAD headers and MAD payload. No other headers
2880478d3005SHans Petter Selasky * are included.
2881478d3005SHans Petter Selasky *
2882478d3005SHans Petter Selasky * Return the max MAD size required by the Port. Will return 0 if the port
2883478d3005SHans Petter Selasky * does not support MADs
2884478d3005SHans Petter Selasky */
rdma_max_mad_size(const struct ib_device * device,u8 port_num)2885478d3005SHans Petter Selasky static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
2886478d3005SHans Petter Selasky {
2887478d3005SHans Petter Selasky return device->port_immutable[port_num].max_mad_size;
2888478d3005SHans Petter Selasky }
2889478d3005SHans Petter Selasky
2890478d3005SHans Petter Selasky /**
2891478d3005SHans Petter Selasky * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
2892478d3005SHans Petter Selasky * @device: Device to check
2893478d3005SHans Petter Selasky * @port_num: Port number to check
2894478d3005SHans Petter Selasky *
2895478d3005SHans Petter Selasky * RoCE GID table mechanism manages the various GIDs for a device.
2896478d3005SHans Petter Selasky *
2897478d3005SHans Petter Selasky * NOTE: if allocating the port's GID table has failed, this call will still
2898478d3005SHans Petter Selasky * return true, but any RoCE GID table API will fail.
2899478d3005SHans Petter Selasky *
2900478d3005SHans Petter Selasky * Return: true if the port uses RoCE GID table mechanism in order to manage
2901478d3005SHans Petter Selasky * its GIDs.
2902478d3005SHans Petter Selasky */
rdma_cap_roce_gid_table(const struct ib_device * device,u8 port_num)2903478d3005SHans Petter Selasky static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
2904478d3005SHans Petter Selasky u8 port_num)
2905478d3005SHans Petter Selasky {
2906478d3005SHans Petter Selasky return rdma_protocol_roce(device, port_num) &&
2907478d3005SHans Petter Selasky device->add_gid && device->del_gid;
2908478d3005SHans Petter Selasky }
2909478d3005SHans Petter Selasky
2910478d3005SHans Petter Selasky /*
2911478d3005SHans Petter Selasky * Check if the device supports READ W/ INVALIDATE.
2912478d3005SHans Petter Selasky */
rdma_cap_read_inv(struct ib_device * dev,u32 port_num)2913478d3005SHans Petter Selasky static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
2914478d3005SHans Petter Selasky {
2915478d3005SHans Petter Selasky /*
2916478d3005SHans Petter Selasky * iWarp drivers must support READ W/ INVALIDATE. No other protocol
2917478d3005SHans Petter Selasky * has support for it yet.
2918478d3005SHans Petter Selasky */
2919478d3005SHans Petter Selasky return rdma_protocol_iwarp(dev, port_num);
2920478d3005SHans Petter Selasky }
2921478d3005SHans Petter Selasky
2922aa0a1e58SJeff Roberson int ib_query_gid(struct ib_device *device,
2923478d3005SHans Petter Selasky u8 port_num, int index, union ib_gid *gid,
2924478d3005SHans Petter Selasky struct ib_gid_attr *attr);
2925478d3005SHans Petter Selasky
2926478d3005SHans Petter Selasky int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
2927478d3005SHans Petter Selasky int state);
2928478d3005SHans Petter Selasky int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
2929478d3005SHans Petter Selasky struct ifla_vf_info *info);
2930478d3005SHans Petter Selasky int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
2931478d3005SHans Petter Selasky struct ifla_vf_stats *stats);
2932478d3005SHans Petter Selasky int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
2933478d3005SHans Petter Selasky int type);
2934aa0a1e58SJeff Roberson
2935aa0a1e58SJeff Roberson int ib_query_pkey(struct ib_device *device,
2936aa0a1e58SJeff Roberson u8 port_num, u16 index, u16 *pkey);
2937aa0a1e58SJeff Roberson
2938aa0a1e58SJeff Roberson int ib_modify_device(struct ib_device *device,
2939aa0a1e58SJeff Roberson int device_modify_mask,
2940aa0a1e58SJeff Roberson struct ib_device_modify *device_modify);
2941aa0a1e58SJeff Roberson
2942aa0a1e58SJeff Roberson int ib_modify_port(struct ib_device *device,
2943aa0a1e58SJeff Roberson u8 port_num, int port_modify_mask,
2944aa0a1e58SJeff Roberson struct ib_port_modify *port_modify);
2945aa0a1e58SJeff Roberson
2946aa0a1e58SJeff Roberson int ib_find_gid(struct ib_device *device, union ib_gid *gid,
29473e142e07SJustin Hibbits enum ib_gid_type gid_type, if_t ndev,
2948aa0a1e58SJeff Roberson u8 *port_num, u16 *index);
2949aa0a1e58SJeff Roberson
2950aa0a1e58SJeff Roberson int ib_find_pkey(struct ib_device *device,
2951aa0a1e58SJeff Roberson u8 port_num, u16 pkey, u16 *index);
2952aa0a1e58SJeff Roberson
2953478d3005SHans Petter Selasky enum ib_pd_flags {
2954478d3005SHans Petter Selasky /*
2955478d3005SHans Petter Selasky * Create a memory registration for all memory in the system and place
2956478d3005SHans Petter Selasky * the rkey for it into pd->unsafe_global_rkey. This can be used by
2957478d3005SHans Petter Selasky * ULPs to avoid the overhead of dynamic MRs.
2958aa0a1e58SJeff Roberson *
2959478d3005SHans Petter Selasky * This flag is generally considered unsafe and must only be used in
2960478d3005SHans Petter Selasky * extremly trusted environments. Every use of it will log a warning
2961478d3005SHans Petter Selasky * in the kernel log.
2962aa0a1e58SJeff Roberson */
2963478d3005SHans Petter Selasky IB_PD_UNSAFE_GLOBAL_RKEY = 0x01,
2964478d3005SHans Petter Selasky };
2965aa0a1e58SJeff Roberson
2966478d3005SHans Petter Selasky struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
2967478d3005SHans Petter Selasky const char *caller);
2968478d3005SHans Petter Selasky #define ib_alloc_pd(device, flags) \
2969478d3005SHans Petter Selasky __ib_alloc_pd((device), (flags), __func__)
2970b633e08cSHans Petter Selasky
2971b633e08cSHans Petter Selasky /**
2972b633e08cSHans Petter Selasky * ib_dealloc_pd_user - Deallocate kernel/user PD
2973b633e08cSHans Petter Selasky * @pd: The protection domain
2974b633e08cSHans Petter Selasky * @udata: Valid user data or NULL for kernel objects
2975b633e08cSHans Petter Selasky */
2976b633e08cSHans Petter Selasky void ib_dealloc_pd_user(struct ib_pd *pd, struct ib_udata *udata);
2977b633e08cSHans Petter Selasky
2978b633e08cSHans Petter Selasky /**
2979b633e08cSHans Petter Selasky * ib_dealloc_pd - Deallocate kernel PD
2980b633e08cSHans Petter Selasky * @pd: The protection domain
2981b633e08cSHans Petter Selasky *
2982b633e08cSHans Petter Selasky * NOTE: for user PD use ib_dealloc_pd_user with valid udata!
2983b633e08cSHans Petter Selasky */
ib_dealloc_pd(struct ib_pd * pd)2984b633e08cSHans Petter Selasky static inline void ib_dealloc_pd(struct ib_pd *pd)
2985b633e08cSHans Petter Selasky {
2986b633e08cSHans Petter Selasky ib_dealloc_pd_user(pd, NULL);
2987b633e08cSHans Petter Selasky }
2988b633e08cSHans Petter Selasky
2989b633e08cSHans Petter Selasky enum rdma_create_ah_flags {
2990b633e08cSHans Petter Selasky /* In a sleepable context */
2991b633e08cSHans Petter Selasky RDMA_CREATE_AH_SLEEPABLE = BIT(0),
2992b633e08cSHans Petter Selasky };
2993aa0a1e58SJeff Roberson
2994aa0a1e58SJeff Roberson /**
2995aa0a1e58SJeff Roberson * ib_create_ah - Creates an address handle for the given address vector.
2996aa0a1e58SJeff Roberson * @pd: The protection domain associated with the address handle.
2997aa0a1e58SJeff Roberson * @ah_attr: The attributes of the address vector.
2998b633e08cSHans Petter Selasky * @flags: Create address handle flags (see enum rdma_create_ah_flags).
2999aa0a1e58SJeff Roberson *
3000aa0a1e58SJeff Roberson * The address handle is used to reference a local or global destination
3001aa0a1e58SJeff Roberson * in all UD QP post sends.
3002aa0a1e58SJeff Roberson */
3003b633e08cSHans Petter Selasky struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr,
3004b633e08cSHans Petter Selasky u32 flags);
3005b633e08cSHans Petter Selasky
3006b633e08cSHans Petter Selasky /**
3007b633e08cSHans Petter Selasky * ib_create_user_ah - Creates an address handle for the given address vector.
3008b633e08cSHans Petter Selasky * It resolves destination mac address for ah attribute of RoCE type.
3009b633e08cSHans Petter Selasky * @pd: The protection domain associated with the address handle.
3010b633e08cSHans Petter Selasky * @ah_attr: The attributes of the address vector.
3011b633e08cSHans Petter Selasky * @udata: pointer to user's input output buffer information need by
3012b633e08cSHans Petter Selasky * provider driver.
3013b633e08cSHans Petter Selasky *
3014b633e08cSHans Petter Selasky * It returns 0 on success and returns appropriate error code on error.
3015b633e08cSHans Petter Selasky * The address handle is used to reference a local or global destination
3016b633e08cSHans Petter Selasky * in all UD QP post sends.
3017b633e08cSHans Petter Selasky */
3018b633e08cSHans Petter Selasky struct ib_ah *ib_create_user_ah(struct ib_pd *pd,
3019b633e08cSHans Petter Selasky struct ib_ah_attr *ah_attr,
3020b633e08cSHans Petter Selasky struct ib_udata *udata);
3021aa0a1e58SJeff Roberson
3022aa0a1e58SJeff Roberson /**
3023aa0a1e58SJeff Roberson * ib_init_ah_from_wc - Initializes address handle attributes from a
3024aa0a1e58SJeff Roberson * work completion.
3025aa0a1e58SJeff Roberson * @device: Device on which the received message arrived.
3026aa0a1e58SJeff Roberson * @port_num: Port on which the received message arrived.
3027aa0a1e58SJeff Roberson * @wc: Work completion associated with the received message.
3028aa0a1e58SJeff Roberson * @grh: References the received global route header. This parameter is
3029aa0a1e58SJeff Roberson * ignored unless the work completion indicates that the GRH is valid.
3030aa0a1e58SJeff Roberson * @ah_attr: Returned attributes that can be used when creating an address
3031aa0a1e58SJeff Roberson * handle for replying to the message.
3032aa0a1e58SJeff Roberson */
3033478d3005SHans Petter Selasky int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
3034478d3005SHans Petter Selasky const struct ib_wc *wc, const struct ib_grh *grh,
3035478d3005SHans Petter Selasky struct ib_ah_attr *ah_attr);
3036aa0a1e58SJeff Roberson
3037aa0a1e58SJeff Roberson /**
3038aa0a1e58SJeff Roberson * ib_create_ah_from_wc - Creates an address handle associated with the
3039aa0a1e58SJeff Roberson * sender of the specified work completion.
3040aa0a1e58SJeff Roberson * @pd: The protection domain associated with the address handle.
3041aa0a1e58SJeff Roberson * @wc: Work completion information associated with a received message.
3042aa0a1e58SJeff Roberson * @grh: References the received global route header. This parameter is
3043aa0a1e58SJeff Roberson * ignored unless the work completion indicates that the GRH is valid.
3044aa0a1e58SJeff Roberson * @port_num: The outbound port number to associate with the address.
3045aa0a1e58SJeff Roberson *
3046aa0a1e58SJeff Roberson * The address handle is used to reference a local or global destination
3047aa0a1e58SJeff Roberson * in all UD QP post sends.
3048aa0a1e58SJeff Roberson */
3049478d3005SHans Petter Selasky struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
3050478d3005SHans Petter Selasky const struct ib_grh *grh, u8 port_num);
3051aa0a1e58SJeff Roberson
3052aa0a1e58SJeff Roberson /**
3053aa0a1e58SJeff Roberson * ib_modify_ah - Modifies the address vector associated with an address
3054aa0a1e58SJeff Roberson * handle.
3055aa0a1e58SJeff Roberson * @ah: The address handle to modify.
3056aa0a1e58SJeff Roberson * @ah_attr: The new address vector attributes to associate with the
3057aa0a1e58SJeff Roberson * address handle.
3058aa0a1e58SJeff Roberson */
3059aa0a1e58SJeff Roberson int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
3060aa0a1e58SJeff Roberson
3061aa0a1e58SJeff Roberson /**
3062aa0a1e58SJeff Roberson * ib_query_ah - Queries the address vector associated with an address
3063aa0a1e58SJeff Roberson * handle.
3064aa0a1e58SJeff Roberson * @ah: The address handle to query.
3065aa0a1e58SJeff Roberson * @ah_attr: The address vector attributes associated with the address
3066aa0a1e58SJeff Roberson * handle.
3067aa0a1e58SJeff Roberson */
3068aa0a1e58SJeff Roberson int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
3069aa0a1e58SJeff Roberson
3070b633e08cSHans Petter Selasky enum rdma_destroy_ah_flags {
3071b633e08cSHans Petter Selasky /* In a sleepable context */
3072b633e08cSHans Petter Selasky RDMA_DESTROY_AH_SLEEPABLE = BIT(0),
3073b633e08cSHans Petter Selasky };
3074b633e08cSHans Petter Selasky
3075aa0a1e58SJeff Roberson /**
3076b633e08cSHans Petter Selasky * ib_destroy_ah_user - Destroys an address handle.
3077aa0a1e58SJeff Roberson * @ah: The address handle to destroy.
3078b633e08cSHans Petter Selasky * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
3079b633e08cSHans Petter Selasky * @udata: Valid user data or NULL for kernel objects
3080aa0a1e58SJeff Roberson */
3081b633e08cSHans Petter Selasky int ib_destroy_ah_user(struct ib_ah *ah, u32 flags, struct ib_udata *udata);
3082b633e08cSHans Petter Selasky
3083b633e08cSHans Petter Selasky /**
3084b633e08cSHans Petter Selasky * rdma_destroy_ah - Destroys an kernel address handle.
3085b633e08cSHans Petter Selasky * @ah: The address handle to destroy.
3086b633e08cSHans Petter Selasky * @flags: Destroy address handle flags (see enum rdma_destroy_ah_flags).
3087b633e08cSHans Petter Selasky *
3088b633e08cSHans Petter Selasky * NOTE: for user ah use ib_destroy_ah_user with valid udata!
3089b633e08cSHans Petter Selasky */
ib_destroy_ah(struct ib_ah * ah,u32 flags)3090b633e08cSHans Petter Selasky static inline int ib_destroy_ah(struct ib_ah *ah, u32 flags)
3091b633e08cSHans Petter Selasky {
3092b633e08cSHans Petter Selasky return ib_destroy_ah_user(ah, flags, NULL);
3093b633e08cSHans Petter Selasky }
3094aa0a1e58SJeff Roberson
3095aa0a1e58SJeff Roberson /**
3096c9f432b7SAlfred Perlstein * ib_create_srq - Creates a SRQ associated with the specified protection
3097c9f432b7SAlfred Perlstein * domain.
3098aa0a1e58SJeff Roberson * @pd: The protection domain associated with the SRQ.
3099aa0a1e58SJeff Roberson * @srq_init_attr: A list of initial attributes required to create the
3100aa0a1e58SJeff Roberson * SRQ. If SRQ creation succeeds, then the attributes are updated to
3101aa0a1e58SJeff Roberson * the actual capabilities of the created SRQ.
3102aa0a1e58SJeff Roberson *
3103aa0a1e58SJeff Roberson * srq_attr->max_wr and srq_attr->max_sge are read the determine the
3104aa0a1e58SJeff Roberson * requested size of the SRQ, and set to the actual values allocated
3105aa0a1e58SJeff Roberson * on return. If ib_create_srq() succeeds, then max_wr and max_sge
3106aa0a1e58SJeff Roberson * will always be at least as large as the requested values.
3107aa0a1e58SJeff Roberson */
3108aa0a1e58SJeff Roberson struct ib_srq *ib_create_srq(struct ib_pd *pd,
3109aa0a1e58SJeff Roberson struct ib_srq_init_attr *srq_init_attr);
3110aa0a1e58SJeff Roberson
3111aa0a1e58SJeff Roberson /**
3112aa0a1e58SJeff Roberson * ib_modify_srq - Modifies the attributes for the specified SRQ.
3113aa0a1e58SJeff Roberson * @srq: The SRQ to modify.
3114aa0a1e58SJeff Roberson * @srq_attr: On input, specifies the SRQ attributes to modify. On output,
3115aa0a1e58SJeff Roberson * the current values of selected SRQ attributes are returned.
3116aa0a1e58SJeff Roberson * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
3117aa0a1e58SJeff Roberson * are being modified.
3118aa0a1e58SJeff Roberson *
3119aa0a1e58SJeff Roberson * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
3120aa0a1e58SJeff Roberson * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
3121aa0a1e58SJeff Roberson * the number of receives queued drops below the limit.
3122aa0a1e58SJeff Roberson */
3123aa0a1e58SJeff Roberson int ib_modify_srq(struct ib_srq *srq,
3124aa0a1e58SJeff Roberson struct ib_srq_attr *srq_attr,
3125aa0a1e58SJeff Roberson enum ib_srq_attr_mask srq_attr_mask);
3126aa0a1e58SJeff Roberson
3127aa0a1e58SJeff Roberson /**
3128aa0a1e58SJeff Roberson * ib_query_srq - Returns the attribute list and current values for the
3129aa0a1e58SJeff Roberson * specified SRQ.
3130aa0a1e58SJeff Roberson * @srq: The SRQ to query.
3131aa0a1e58SJeff Roberson * @srq_attr: The attributes of the specified SRQ.
3132aa0a1e58SJeff Roberson */
3133aa0a1e58SJeff Roberson int ib_query_srq(struct ib_srq *srq,
3134aa0a1e58SJeff Roberson struct ib_srq_attr *srq_attr);
3135aa0a1e58SJeff Roberson
3136aa0a1e58SJeff Roberson /**
3137b633e08cSHans Petter Selasky * ib_destroy_srq_user - Destroys the specified SRQ.
3138aa0a1e58SJeff Roberson * @srq: The SRQ to destroy.
3139b633e08cSHans Petter Selasky * @udata: Valid user data or NULL for kernel objects
3140aa0a1e58SJeff Roberson */
3141b633e08cSHans Petter Selasky int ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata);
3142b633e08cSHans Petter Selasky
3143b633e08cSHans Petter Selasky /**
3144b633e08cSHans Petter Selasky * ib_destroy_srq - Destroys the specified kernel SRQ.
3145b633e08cSHans Petter Selasky * @srq: The SRQ to destroy.
3146b633e08cSHans Petter Selasky *
3147b633e08cSHans Petter Selasky * NOTE: for user srq use ib_destroy_srq_user with valid udata!
3148b633e08cSHans Petter Selasky */
ib_destroy_srq(struct ib_srq * srq)3149b633e08cSHans Petter Selasky static inline int ib_destroy_srq(struct ib_srq *srq)
3150b633e08cSHans Petter Selasky {
3151b633e08cSHans Petter Selasky return ib_destroy_srq_user(srq, NULL);
3152b633e08cSHans Petter Selasky }
3153aa0a1e58SJeff Roberson
3154aa0a1e58SJeff Roberson /**
3155aa0a1e58SJeff Roberson * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
3156aa0a1e58SJeff Roberson * @srq: The SRQ to post the work request on.
3157aa0a1e58SJeff Roberson * @recv_wr: A list of work requests to post on the receive queue.
3158aa0a1e58SJeff Roberson * @bad_recv_wr: On an immediate failure, this parameter will reference
3159aa0a1e58SJeff Roberson * the work request that failed to be posted on the QP.
3160aa0a1e58SJeff Roberson */
ib_post_srq_recv(struct ib_srq * srq,const struct ib_recv_wr * recv_wr,const struct ib_recv_wr ** bad_recv_wr)3161aa0a1e58SJeff Roberson static inline int ib_post_srq_recv(struct ib_srq *srq,
3162c3987b8eSHans Petter Selasky const struct ib_recv_wr *recv_wr,
3163c3987b8eSHans Petter Selasky const struct ib_recv_wr **bad_recv_wr)
3164aa0a1e58SJeff Roberson {
3165aa0a1e58SJeff Roberson return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
3166aa0a1e58SJeff Roberson }
3167aa0a1e58SJeff Roberson
3168aa0a1e58SJeff Roberson /**
3169aa0a1e58SJeff Roberson * ib_create_qp - Creates a QP associated with the specified protection
3170aa0a1e58SJeff Roberson * domain.
3171aa0a1e58SJeff Roberson * @pd: The protection domain associated with the QP.
3172aa0a1e58SJeff Roberson * @qp_init_attr: A list of initial attributes required to create the
3173aa0a1e58SJeff Roberson * QP. If QP creation succeeds, then the attributes are updated to
3174aa0a1e58SJeff Roberson * the actual capabilities of the created QP.
3175aa0a1e58SJeff Roberson */
3176aa0a1e58SJeff Roberson struct ib_qp *ib_create_qp(struct ib_pd *pd,
3177aa0a1e58SJeff Roberson struct ib_qp_init_attr *qp_init_attr);
3178aa0a1e58SJeff Roberson
3179aa0a1e58SJeff Roberson /**
3180b633e08cSHans Petter Selasky * ib_modify_qp_with_udata - Modifies the attributes for the specified QP.
3181b633e08cSHans Petter Selasky * @qp: The QP to modify.
3182b633e08cSHans Petter Selasky * @attr: On input, specifies the QP attributes to modify. On output,
3183b633e08cSHans Petter Selasky * the current values of selected QP attributes are returned.
3184b633e08cSHans Petter Selasky * @attr_mask: A bit-mask used to specify which attributes of the QP
3185b633e08cSHans Petter Selasky * are being modified.
3186b633e08cSHans Petter Selasky * @udata: pointer to user's input output buffer information
3187b633e08cSHans Petter Selasky * are being modified.
3188b633e08cSHans Petter Selasky * It returns 0 on success and returns appropriate error code on error.
3189b633e08cSHans Petter Selasky */
3190b633e08cSHans Petter Selasky int ib_modify_qp_with_udata(struct ib_qp *qp,
3191b633e08cSHans Petter Selasky struct ib_qp_attr *attr,
3192b633e08cSHans Petter Selasky int attr_mask,
3193b633e08cSHans Petter Selasky struct ib_udata *udata);
3194b633e08cSHans Petter Selasky
3195b633e08cSHans Petter Selasky /**
3196aa0a1e58SJeff Roberson * ib_modify_qp - Modifies the attributes for the specified QP and then
3197aa0a1e58SJeff Roberson * transitions the QP to the given state.
3198aa0a1e58SJeff Roberson * @qp: The QP to modify.
3199aa0a1e58SJeff Roberson * @qp_attr: On input, specifies the QP attributes to modify. On output,
3200aa0a1e58SJeff Roberson * the current values of selected QP attributes are returned.
3201aa0a1e58SJeff Roberson * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
3202aa0a1e58SJeff Roberson * are being modified.
3203aa0a1e58SJeff Roberson */
3204aa0a1e58SJeff Roberson int ib_modify_qp(struct ib_qp *qp,
3205aa0a1e58SJeff Roberson struct ib_qp_attr *qp_attr,
3206aa0a1e58SJeff Roberson int qp_attr_mask);
3207aa0a1e58SJeff Roberson
3208aa0a1e58SJeff Roberson /**
3209aa0a1e58SJeff Roberson * ib_query_qp - Returns the attribute list and current values for the
3210aa0a1e58SJeff Roberson * specified QP.
3211aa0a1e58SJeff Roberson * @qp: The QP to query.
3212aa0a1e58SJeff Roberson * @qp_attr: The attributes of the specified QP.
3213aa0a1e58SJeff Roberson * @qp_attr_mask: A bit-mask used to select specific attributes to query.
3214aa0a1e58SJeff Roberson * @qp_init_attr: Additional attributes of the selected QP.
3215aa0a1e58SJeff Roberson *
3216aa0a1e58SJeff Roberson * The qp_attr_mask may be used to limit the query to gathering only the
3217aa0a1e58SJeff Roberson * selected attributes.
3218aa0a1e58SJeff Roberson */
3219aa0a1e58SJeff Roberson int ib_query_qp(struct ib_qp *qp,
3220aa0a1e58SJeff Roberson struct ib_qp_attr *qp_attr,
3221aa0a1e58SJeff Roberson int qp_attr_mask,
3222aa0a1e58SJeff Roberson struct ib_qp_init_attr *qp_init_attr);
3223aa0a1e58SJeff Roberson
3224aa0a1e58SJeff Roberson /**
3225aa0a1e58SJeff Roberson * ib_destroy_qp - Destroys the specified QP.
3226aa0a1e58SJeff Roberson * @qp: The QP to destroy.
3227b633e08cSHans Petter Selasky * @udata: Valid udata or NULL for kernel objects
3228aa0a1e58SJeff Roberson */
3229b633e08cSHans Petter Selasky int ib_destroy_qp_user(struct ib_qp *qp, struct ib_udata *udata);
3230b633e08cSHans Petter Selasky
3231b633e08cSHans Petter Selasky /**
3232b633e08cSHans Petter Selasky * ib_destroy_qp - Destroys the specified kernel QP.
3233b633e08cSHans Petter Selasky * @qp: The QP to destroy.
3234b633e08cSHans Petter Selasky *
3235b633e08cSHans Petter Selasky * NOTE: for user qp use ib_destroy_qp_user with valid udata!
3236b633e08cSHans Petter Selasky */
ib_destroy_qp(struct ib_qp * qp)3237b633e08cSHans Petter Selasky static inline int ib_destroy_qp(struct ib_qp *qp)
3238b633e08cSHans Petter Selasky {
3239b633e08cSHans Petter Selasky return ib_destroy_qp_user(qp, NULL);
3240b633e08cSHans Petter Selasky }
3241aa0a1e58SJeff Roberson
3242aa0a1e58SJeff Roberson /**
3243c9f432b7SAlfred Perlstein * ib_open_qp - Obtain a reference to an existing sharable QP.
3244c9f432b7SAlfred Perlstein * @xrcd - XRC domain
3245c9f432b7SAlfred Perlstein * @qp_open_attr: Attributes identifying the QP to open.
3246c9f432b7SAlfred Perlstein *
3247c9f432b7SAlfred Perlstein * Returns a reference to a sharable QP.
3248c9f432b7SAlfred Perlstein */
3249c9f432b7SAlfred Perlstein struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
3250c9f432b7SAlfred Perlstein struct ib_qp_open_attr *qp_open_attr);
3251c9f432b7SAlfred Perlstein
3252c9f432b7SAlfred Perlstein /**
3253c9f432b7SAlfred Perlstein * ib_close_qp - Release an external reference to a QP.
3254c9f432b7SAlfred Perlstein * @qp: The QP handle to release
3255c9f432b7SAlfred Perlstein *
3256c9f432b7SAlfred Perlstein * The opened QP handle is released by the caller. The underlying
3257c9f432b7SAlfred Perlstein * shared QP is not destroyed until all internal references are released.
3258c9f432b7SAlfred Perlstein */
3259c9f432b7SAlfred Perlstein int ib_close_qp(struct ib_qp *qp);
3260c9f432b7SAlfred Perlstein
3261c9f432b7SAlfred Perlstein /**
3262aa0a1e58SJeff Roberson * ib_post_send - Posts a list of work requests to the send queue of
3263aa0a1e58SJeff Roberson * the specified QP.
3264aa0a1e58SJeff Roberson * @qp: The QP to post the work request on.
3265aa0a1e58SJeff Roberson * @send_wr: A list of work requests to post on the send queue.
3266aa0a1e58SJeff Roberson * @bad_send_wr: On an immediate failure, this parameter will reference
3267aa0a1e58SJeff Roberson * the work request that failed to be posted on the QP.
3268c9f432b7SAlfred Perlstein *
3269c9f432b7SAlfred Perlstein * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
3270c9f432b7SAlfred Perlstein * error is returned, the QP state shall not be affected,
3271c9f432b7SAlfred Perlstein * ib_post_send() will return an immediate error after queueing any
3272c9f432b7SAlfred Perlstein * earlier work requests in the list.
3273aa0a1e58SJeff Roberson */
ib_post_send(struct ib_qp * qp,const struct ib_send_wr * send_wr,const struct ib_send_wr ** bad_send_wr)3274aa0a1e58SJeff Roberson static inline int ib_post_send(struct ib_qp *qp,
3275c3987b8eSHans Petter Selasky const struct ib_send_wr *send_wr,
3276c3987b8eSHans Petter Selasky const struct ib_send_wr **bad_send_wr)
3277aa0a1e58SJeff Roberson {
3278aa0a1e58SJeff Roberson return qp->device->post_send(qp, send_wr, bad_send_wr);
3279aa0a1e58SJeff Roberson }
3280aa0a1e58SJeff Roberson
3281aa0a1e58SJeff Roberson /**
3282aa0a1e58SJeff Roberson * ib_post_recv - Posts a list of work requests to the receive queue of
3283aa0a1e58SJeff Roberson * the specified QP.
3284aa0a1e58SJeff Roberson * @qp: The QP to post the work request on.
3285aa0a1e58SJeff Roberson * @recv_wr: A list of work requests to post on the receive queue.
3286aa0a1e58SJeff Roberson * @bad_recv_wr: On an immediate failure, this parameter will reference
3287aa0a1e58SJeff Roberson * the work request that failed to be posted on the QP.
3288aa0a1e58SJeff Roberson */
ib_post_recv(struct ib_qp * qp,const struct ib_recv_wr * recv_wr,const struct ib_recv_wr ** bad_recv_wr)3289aa0a1e58SJeff Roberson static inline int ib_post_recv(struct ib_qp *qp,
3290c3987b8eSHans Petter Selasky const struct ib_recv_wr *recv_wr,
3291c3987b8eSHans Petter Selasky const struct ib_recv_wr **bad_recv_wr)
3292aa0a1e58SJeff Roberson {
3293aa0a1e58SJeff Roberson return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
3294aa0a1e58SJeff Roberson }
3295aa0a1e58SJeff Roberson
3296b633e08cSHans Petter Selasky struct ib_cq *__ib_alloc_cq_user(struct ib_device *dev, void *private,
3297b633e08cSHans Petter Selasky int nr_cqe, int comp_vector,
3298b633e08cSHans Petter Selasky enum ib_poll_context poll_ctx,
3299b633e08cSHans Petter Selasky const char *caller, struct ib_udata *udata);
3300b633e08cSHans Petter Selasky
3301b633e08cSHans Petter Selasky /**
3302b633e08cSHans Petter Selasky * ib_alloc_cq_user: Allocate kernel/user CQ
3303b633e08cSHans Petter Selasky * @dev: The IB device
3304b633e08cSHans Petter Selasky * @private: Private data attached to the CQE
3305b633e08cSHans Petter Selasky * @nr_cqe: Number of CQEs in the CQ
3306b633e08cSHans Petter Selasky * @comp_vector: Completion vector used for the IRQs
3307b633e08cSHans Petter Selasky * @poll_ctx: Context used for polling the CQ
3308b633e08cSHans Petter Selasky * @udata: Valid user data or NULL for kernel objects
3309b633e08cSHans Petter Selasky */
ib_alloc_cq_user(struct ib_device * dev,void * private,int nr_cqe,int comp_vector,enum ib_poll_context poll_ctx,struct ib_udata * udata)3310b633e08cSHans Petter Selasky static inline struct ib_cq *ib_alloc_cq_user(struct ib_device *dev,
3311b633e08cSHans Petter Selasky void *private, int nr_cqe,
3312b633e08cSHans Petter Selasky int comp_vector,
3313b633e08cSHans Petter Selasky enum ib_poll_context poll_ctx,
3314b633e08cSHans Petter Selasky struct ib_udata *udata)
3315b633e08cSHans Petter Selasky {
3316b633e08cSHans Petter Selasky return __ib_alloc_cq_user(dev, private, nr_cqe, comp_vector, poll_ctx,
3317b633e08cSHans Petter Selasky "ibcore", udata);
3318b633e08cSHans Petter Selasky }
3319b633e08cSHans Petter Selasky
3320b633e08cSHans Petter Selasky /**
3321b633e08cSHans Petter Selasky * ib_alloc_cq: Allocate kernel CQ
3322b633e08cSHans Petter Selasky * @dev: The IB device
3323b633e08cSHans Petter Selasky * @private: Private data attached to the CQE
3324b633e08cSHans Petter Selasky * @nr_cqe: Number of CQEs in the CQ
3325b633e08cSHans Petter Selasky * @comp_vector: Completion vector used for the IRQs
3326b633e08cSHans Petter Selasky * @poll_ctx: Context used for polling the CQ
3327b633e08cSHans Petter Selasky *
3328b633e08cSHans Petter Selasky * NOTE: for user cq use ib_alloc_cq_user with valid udata!
3329b633e08cSHans Petter Selasky */
ib_alloc_cq(struct ib_device * dev,void * private,int nr_cqe,int comp_vector,enum ib_poll_context poll_ctx)3330b633e08cSHans Petter Selasky static inline struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
3331b633e08cSHans Petter Selasky int nr_cqe, int comp_vector,
3332b633e08cSHans Petter Selasky enum ib_poll_context poll_ctx)
3333b633e08cSHans Petter Selasky {
3334b633e08cSHans Petter Selasky return ib_alloc_cq_user(dev, private, nr_cqe, comp_vector, poll_ctx,
3335b633e08cSHans Petter Selasky NULL);
3336b633e08cSHans Petter Selasky }
3337b633e08cSHans Petter Selasky
3338b633e08cSHans Petter Selasky /**
3339b633e08cSHans Petter Selasky * ib_free_cq_user - Free kernel/user CQ
3340b633e08cSHans Petter Selasky * @cq: The CQ to free
3341b633e08cSHans Petter Selasky * @udata: Valid user data or NULL for kernel objects
3342b633e08cSHans Petter Selasky */
3343b633e08cSHans Petter Selasky void ib_free_cq_user(struct ib_cq *cq, struct ib_udata *udata);
3344b633e08cSHans Petter Selasky
3345b633e08cSHans Petter Selasky /**
3346b633e08cSHans Petter Selasky * ib_free_cq - Free kernel CQ
3347b633e08cSHans Petter Selasky * @cq: The CQ to free
3348b633e08cSHans Petter Selasky *
3349b633e08cSHans Petter Selasky * NOTE: for user cq use ib_free_cq_user with valid udata!
3350b633e08cSHans Petter Selasky */
ib_free_cq(struct ib_cq * cq)3351b633e08cSHans Petter Selasky static inline void ib_free_cq(struct ib_cq *cq)
3352b633e08cSHans Petter Selasky {
3353b633e08cSHans Petter Selasky ib_free_cq_user(cq, NULL);
3354b633e08cSHans Petter Selasky }
3355478d3005SHans Petter Selasky
3356aa0a1e58SJeff Roberson /**
3357aa0a1e58SJeff Roberson * ib_create_cq - Creates a CQ on the specified device.
3358aa0a1e58SJeff Roberson * @device: The device on which to create the CQ.
3359aa0a1e58SJeff Roberson * @comp_handler: A user-specified callback that is invoked when a
3360aa0a1e58SJeff Roberson * completion event occurs on the CQ.
3361aa0a1e58SJeff Roberson * @event_handler: A user-specified callback that is invoked when an
3362aa0a1e58SJeff Roberson * asynchronous event not associated with a completion occurs on the CQ.
3363aa0a1e58SJeff Roberson * @cq_context: Context associated with the CQ returned to the user via
3364aa0a1e58SJeff Roberson * the associated completion and event handlers.
3365478d3005SHans Petter Selasky * @cq_attr: The attributes the CQ should be created upon.
3366aa0a1e58SJeff Roberson *
3367aa0a1e58SJeff Roberson * Users can examine the cq structure to determine the actual CQ size.
3368aa0a1e58SJeff Roberson */
3369b633e08cSHans Petter Selasky struct ib_cq *__ib_create_cq(struct ib_device *device,
3370aa0a1e58SJeff Roberson ib_comp_handler comp_handler,
3371aa0a1e58SJeff Roberson void (*event_handler)(struct ib_event *, void *),
3372478d3005SHans Petter Selasky void *cq_context,
3373b633e08cSHans Petter Selasky const struct ib_cq_init_attr *cq_attr,
3374b633e08cSHans Petter Selasky const char *caller);
3375b633e08cSHans Petter Selasky #define ib_create_cq(device, cmp_hndlr, evt_hndlr, cq_ctxt, cq_attr) \
3376b633e08cSHans Petter Selasky __ib_create_cq((device), (cmp_hndlr), (evt_hndlr), (cq_ctxt), (cq_attr), "ibcore")
3377aa0a1e58SJeff Roberson
3378aa0a1e58SJeff Roberson /**
3379aa0a1e58SJeff Roberson * ib_resize_cq - Modifies the capacity of the CQ.
3380aa0a1e58SJeff Roberson * @cq: The CQ to resize.
3381aa0a1e58SJeff Roberson * @cqe: The minimum size of the CQ.
3382aa0a1e58SJeff Roberson *
3383aa0a1e58SJeff Roberson * Users can examine the cq structure to determine the actual CQ size.
3384aa0a1e58SJeff Roberson */
3385aa0a1e58SJeff Roberson int ib_resize_cq(struct ib_cq *cq, int cqe);
3386aa0a1e58SJeff Roberson
3387aa0a1e58SJeff Roberson /**
3388478d3005SHans Petter Selasky * ib_modify_cq - Modifies moderation params of the CQ
3389aa0a1e58SJeff Roberson * @cq: The CQ to modify.
3390478d3005SHans Petter Selasky * @cq_count: number of CQEs that will trigger an event
3391478d3005SHans Petter Selasky * @cq_period: max period of time in usec before triggering an event
3392478d3005SHans Petter Selasky *
3393aa0a1e58SJeff Roberson */
3394478d3005SHans Petter Selasky int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
3395aa0a1e58SJeff Roberson
3396aa0a1e58SJeff Roberson /**
3397b633e08cSHans Petter Selasky * ib_destroy_cq_user - Destroys the specified CQ.
3398aa0a1e58SJeff Roberson * @cq: The CQ to destroy.
3399b633e08cSHans Petter Selasky * @udata: Valid user data or NULL for kernel objects
3400aa0a1e58SJeff Roberson */
3401b633e08cSHans Petter Selasky int ib_destroy_cq_user(struct ib_cq *cq, struct ib_udata *udata);
3402b633e08cSHans Petter Selasky
3403b633e08cSHans Petter Selasky /**
3404b633e08cSHans Petter Selasky * ib_destroy_cq - Destroys the specified kernel CQ.
3405b633e08cSHans Petter Selasky * @cq: The CQ to destroy.
3406b633e08cSHans Petter Selasky *
3407b633e08cSHans Petter Selasky * NOTE: for user cq use ib_destroy_cq_user with valid udata!
3408b633e08cSHans Petter Selasky */
ib_destroy_cq(struct ib_cq * cq)3409b633e08cSHans Petter Selasky static inline void ib_destroy_cq(struct ib_cq *cq)
3410b633e08cSHans Petter Selasky {
3411b633e08cSHans Petter Selasky ib_destroy_cq_user(cq, NULL);
3412b633e08cSHans Petter Selasky }
3413aa0a1e58SJeff Roberson
3414aa0a1e58SJeff Roberson /**
3415aa0a1e58SJeff Roberson * ib_poll_cq - poll a CQ for completion(s)
3416aa0a1e58SJeff Roberson * @cq:the CQ being polled
3417aa0a1e58SJeff Roberson * @num_entries:maximum number of completions to return
3418aa0a1e58SJeff Roberson * @wc:array of at least @num_entries &struct ib_wc where completions
3419aa0a1e58SJeff Roberson * will be returned
3420aa0a1e58SJeff Roberson *
3421aa0a1e58SJeff Roberson * Poll a CQ for (possibly multiple) completions. If the return value
3422aa0a1e58SJeff Roberson * is < 0, an error occurred. If the return value is >= 0, it is the
3423aa0a1e58SJeff Roberson * number of completions returned. If the return value is
3424aa0a1e58SJeff Roberson * non-negative and < num_entries, then the CQ was emptied.
3425aa0a1e58SJeff Roberson */
ib_poll_cq(struct ib_cq * cq,int num_entries,struct ib_wc * wc)3426aa0a1e58SJeff Roberson static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
3427aa0a1e58SJeff Roberson struct ib_wc *wc)
3428aa0a1e58SJeff Roberson {
3429aa0a1e58SJeff Roberson return cq->device->poll_cq(cq, num_entries, wc);
3430aa0a1e58SJeff Roberson }
3431aa0a1e58SJeff Roberson
3432aa0a1e58SJeff Roberson /**
3433aa0a1e58SJeff Roberson * ib_peek_cq - Returns the number of unreaped completions currently
3434aa0a1e58SJeff Roberson * on the specified CQ.
3435aa0a1e58SJeff Roberson * @cq: The CQ to peek.
3436aa0a1e58SJeff Roberson * @wc_cnt: A minimum number of unreaped completions to check for.
3437aa0a1e58SJeff Roberson *
3438aa0a1e58SJeff Roberson * If the number of unreaped completions is greater than or equal to wc_cnt,
3439aa0a1e58SJeff Roberson * this function returns wc_cnt, otherwise, it returns the actual number of
3440aa0a1e58SJeff Roberson * unreaped completions.
3441aa0a1e58SJeff Roberson */
3442aa0a1e58SJeff Roberson int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
3443aa0a1e58SJeff Roberson
3444aa0a1e58SJeff Roberson /**
3445aa0a1e58SJeff Roberson * ib_req_notify_cq - Request completion notification on a CQ.
3446aa0a1e58SJeff Roberson * @cq: The CQ to generate an event for.
3447aa0a1e58SJeff Roberson * @flags:
3448aa0a1e58SJeff Roberson * Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
3449aa0a1e58SJeff Roberson * to request an event on the next solicited event or next work
3450aa0a1e58SJeff Roberson * completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
3451aa0a1e58SJeff Roberson * may also be |ed in to request a hint about missed events, as
3452aa0a1e58SJeff Roberson * described below.
3453aa0a1e58SJeff Roberson *
3454aa0a1e58SJeff Roberson * Return Value:
3455aa0a1e58SJeff Roberson * < 0 means an error occurred while requesting notification
3456aa0a1e58SJeff Roberson * == 0 means notification was requested successfully, and if
3457aa0a1e58SJeff Roberson * IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
3458aa0a1e58SJeff Roberson * were missed and it is safe to wait for another event. In
3459aa0a1e58SJeff Roberson * this case is it guaranteed that any work completions added
3460aa0a1e58SJeff Roberson * to the CQ since the last CQ poll will trigger a completion
3461aa0a1e58SJeff Roberson * notification event.
3462aa0a1e58SJeff Roberson * > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
3463aa0a1e58SJeff Roberson * in. It means that the consumer must poll the CQ again to
3464aa0a1e58SJeff Roberson * make sure it is empty to avoid missing an event because of a
3465aa0a1e58SJeff Roberson * race between requesting notification and an entry being
3466aa0a1e58SJeff Roberson * added to the CQ. This return value means it is possible
3467aa0a1e58SJeff Roberson * (but not guaranteed) that a work completion has been added
3468aa0a1e58SJeff Roberson * to the CQ since the last poll without triggering a
3469aa0a1e58SJeff Roberson * completion notification event.
3470aa0a1e58SJeff Roberson */
ib_req_notify_cq(struct ib_cq * cq,enum ib_cq_notify_flags flags)3471aa0a1e58SJeff Roberson static inline int ib_req_notify_cq(struct ib_cq *cq,
3472aa0a1e58SJeff Roberson enum ib_cq_notify_flags flags)
3473aa0a1e58SJeff Roberson {
3474aa0a1e58SJeff Roberson return cq->device->req_notify_cq(cq, flags);
3475aa0a1e58SJeff Roberson }
3476aa0a1e58SJeff Roberson
3477aa0a1e58SJeff Roberson /**
3478aa0a1e58SJeff Roberson * ib_req_ncomp_notif - Request completion notification when there are
3479aa0a1e58SJeff Roberson * at least the specified number of unreaped completions on the CQ.
3480aa0a1e58SJeff Roberson * @cq: The CQ to generate an event for.
3481aa0a1e58SJeff Roberson * @wc_cnt: The number of unreaped completions that should be on the
3482aa0a1e58SJeff Roberson * CQ before an event is generated.
3483aa0a1e58SJeff Roberson */
ib_req_ncomp_notif(struct ib_cq * cq,int wc_cnt)3484aa0a1e58SJeff Roberson static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
3485aa0a1e58SJeff Roberson {
3486aa0a1e58SJeff Roberson return cq->device->req_ncomp_notif ?
3487aa0a1e58SJeff Roberson cq->device->req_ncomp_notif(cq, wc_cnt) :
3488aa0a1e58SJeff Roberson -ENOSYS;
3489aa0a1e58SJeff Roberson }
3490aa0a1e58SJeff Roberson
3491aa0a1e58SJeff Roberson /**
3492aa0a1e58SJeff Roberson * ib_dma_mapping_error - check a DMA addr for error
3493aa0a1e58SJeff Roberson * @dev: The device for which the dma_addr was created
3494aa0a1e58SJeff Roberson * @dma_addr: The DMA address to check
3495aa0a1e58SJeff Roberson */
ib_dma_mapping_error(struct ib_device * dev,u64 dma_addr)3496aa0a1e58SJeff Roberson static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
3497aa0a1e58SJeff Roberson {
3498aa0a1e58SJeff Roberson if (dev->dma_ops)
3499aa0a1e58SJeff Roberson return dev->dma_ops->mapping_error(dev, dma_addr);
3500aa0a1e58SJeff Roberson return dma_mapping_error(dev->dma_device, dma_addr);
3501aa0a1e58SJeff Roberson }
3502aa0a1e58SJeff Roberson
3503aa0a1e58SJeff Roberson /**
3504aa0a1e58SJeff Roberson * ib_dma_map_single - Map a kernel virtual address to DMA address
3505aa0a1e58SJeff Roberson * @dev: The device for which the dma_addr is to be created
3506aa0a1e58SJeff Roberson * @cpu_addr: The kernel virtual address
3507aa0a1e58SJeff Roberson * @size: The size of the region in bytes
3508aa0a1e58SJeff Roberson * @direction: The direction of the DMA
3509aa0a1e58SJeff Roberson */
ib_dma_map_single(struct ib_device * dev,void * cpu_addr,size_t size,enum dma_data_direction direction)3510aa0a1e58SJeff Roberson static inline u64 ib_dma_map_single(struct ib_device *dev,
3511aa0a1e58SJeff Roberson void *cpu_addr, size_t size,
3512aa0a1e58SJeff Roberson enum dma_data_direction direction)
3513aa0a1e58SJeff Roberson {
3514aa0a1e58SJeff Roberson if (dev->dma_ops)
3515aa0a1e58SJeff Roberson return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
3516aa0a1e58SJeff Roberson return dma_map_single(dev->dma_device, cpu_addr, size, direction);
3517aa0a1e58SJeff Roberson }
3518aa0a1e58SJeff Roberson
3519aa0a1e58SJeff Roberson /**
3520aa0a1e58SJeff Roberson * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
3521aa0a1e58SJeff Roberson * @dev: The device for which the DMA address was created
3522aa0a1e58SJeff Roberson * @addr: The DMA address
3523aa0a1e58SJeff Roberson * @size: The size of the region in bytes
3524aa0a1e58SJeff Roberson * @direction: The direction of the DMA
3525aa0a1e58SJeff Roberson */
ib_dma_unmap_single(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction direction)3526aa0a1e58SJeff Roberson static inline void ib_dma_unmap_single(struct ib_device *dev,
3527aa0a1e58SJeff Roberson u64 addr, size_t size,
3528aa0a1e58SJeff Roberson enum dma_data_direction direction)
3529aa0a1e58SJeff Roberson {
3530aa0a1e58SJeff Roberson if (dev->dma_ops)
3531aa0a1e58SJeff Roberson dev->dma_ops->unmap_single(dev, addr, size, direction);
3532aa0a1e58SJeff Roberson else
3533aa0a1e58SJeff Roberson dma_unmap_single(dev->dma_device, addr, size, direction);
3534aa0a1e58SJeff Roberson }
3535aa0a1e58SJeff Roberson
ib_dma_map_single_attrs(struct ib_device * dev,void * cpu_addr,size_t size,enum dma_data_direction direction,struct dma_attrs * dma_attrs)3536aa0a1e58SJeff Roberson static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
3537aa0a1e58SJeff Roberson void *cpu_addr, size_t size,
3538aa0a1e58SJeff Roberson enum dma_data_direction direction,
3539478d3005SHans Petter Selasky struct dma_attrs *dma_attrs)
3540aa0a1e58SJeff Roberson {
3541aa0a1e58SJeff Roberson return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
3542478d3005SHans Petter Selasky direction, dma_attrs);
3543aa0a1e58SJeff Roberson }
3544aa0a1e58SJeff Roberson
ib_dma_unmap_single_attrs(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction direction,struct dma_attrs * dma_attrs)3545aa0a1e58SJeff Roberson static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
3546aa0a1e58SJeff Roberson u64 addr, size_t size,
3547aa0a1e58SJeff Roberson enum dma_data_direction direction,
3548478d3005SHans Petter Selasky struct dma_attrs *dma_attrs)
3549aa0a1e58SJeff Roberson {
3550aa0a1e58SJeff Roberson return dma_unmap_single_attrs(dev->dma_device, addr, size,
3551478d3005SHans Petter Selasky direction, dma_attrs);
3552aa0a1e58SJeff Roberson }
3553aa0a1e58SJeff Roberson
3554aa0a1e58SJeff Roberson /**
3555aa0a1e58SJeff Roberson * ib_dma_map_page - Map a physical page to DMA address
3556aa0a1e58SJeff Roberson * @dev: The device for which the dma_addr is to be created
3557aa0a1e58SJeff Roberson * @page: The page to be mapped
3558aa0a1e58SJeff Roberson * @offset: The offset within the page
3559aa0a1e58SJeff Roberson * @size: The size of the region in bytes
3560aa0a1e58SJeff Roberson * @direction: The direction of the DMA
3561aa0a1e58SJeff Roberson */
ib_dma_map_page(struct ib_device * dev,struct page * page,unsigned long offset,size_t size,enum dma_data_direction direction)3562aa0a1e58SJeff Roberson static inline u64 ib_dma_map_page(struct ib_device *dev,
3563aa0a1e58SJeff Roberson struct page *page,
3564aa0a1e58SJeff Roberson unsigned long offset,
3565aa0a1e58SJeff Roberson size_t size,
3566aa0a1e58SJeff Roberson enum dma_data_direction direction)
3567aa0a1e58SJeff Roberson {
3568aa0a1e58SJeff Roberson if (dev->dma_ops)
3569aa0a1e58SJeff Roberson return dev->dma_ops->map_page(dev, page, offset, size, direction);
3570aa0a1e58SJeff Roberson return dma_map_page(dev->dma_device, page, offset, size, direction);
3571aa0a1e58SJeff Roberson }
3572aa0a1e58SJeff Roberson
3573aa0a1e58SJeff Roberson /**
3574aa0a1e58SJeff Roberson * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
3575aa0a1e58SJeff Roberson * @dev: The device for which the DMA address was created
3576aa0a1e58SJeff Roberson * @addr: The DMA address
3577aa0a1e58SJeff Roberson * @size: The size of the region in bytes
3578aa0a1e58SJeff Roberson * @direction: The direction of the DMA
3579aa0a1e58SJeff Roberson */
ib_dma_unmap_page(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction direction)3580aa0a1e58SJeff Roberson static inline void ib_dma_unmap_page(struct ib_device *dev,
3581aa0a1e58SJeff Roberson u64 addr, size_t size,
3582aa0a1e58SJeff Roberson enum dma_data_direction direction)
3583aa0a1e58SJeff Roberson {
3584aa0a1e58SJeff Roberson if (dev->dma_ops)
3585aa0a1e58SJeff Roberson dev->dma_ops->unmap_page(dev, addr, size, direction);
3586aa0a1e58SJeff Roberson else
3587aa0a1e58SJeff Roberson dma_unmap_page(dev->dma_device, addr, size, direction);
3588aa0a1e58SJeff Roberson }
3589aa0a1e58SJeff Roberson
3590aa0a1e58SJeff Roberson /**
3591aa0a1e58SJeff Roberson * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
3592aa0a1e58SJeff Roberson * @dev: The device for which the DMA addresses are to be created
3593aa0a1e58SJeff Roberson * @sg: The array of scatter/gather entries
3594aa0a1e58SJeff Roberson * @nents: The number of scatter/gather entries
3595aa0a1e58SJeff Roberson * @direction: The direction of the DMA
3596aa0a1e58SJeff Roberson */
ib_dma_map_sg(struct ib_device * dev,struct scatterlist * sg,int nents,enum dma_data_direction direction)3597aa0a1e58SJeff Roberson static inline int ib_dma_map_sg(struct ib_device *dev,
3598aa0a1e58SJeff Roberson struct scatterlist *sg, int nents,
3599aa0a1e58SJeff Roberson enum dma_data_direction direction)
3600aa0a1e58SJeff Roberson {
3601aa0a1e58SJeff Roberson if (dev->dma_ops)
3602aa0a1e58SJeff Roberson return dev->dma_ops->map_sg(dev, sg, nents, direction);
3603aa0a1e58SJeff Roberson return dma_map_sg(dev->dma_device, sg, nents, direction);
3604aa0a1e58SJeff Roberson }
3605aa0a1e58SJeff Roberson
3606aa0a1e58SJeff Roberson /**
3607aa0a1e58SJeff Roberson * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
3608aa0a1e58SJeff Roberson * @dev: The device for which the DMA addresses were created
3609aa0a1e58SJeff Roberson * @sg: The array of scatter/gather entries
3610aa0a1e58SJeff Roberson * @nents: The number of scatter/gather entries
3611aa0a1e58SJeff Roberson * @direction: The direction of the DMA
3612aa0a1e58SJeff Roberson */
ib_dma_unmap_sg(struct ib_device * dev,struct scatterlist * sg,int nents,enum dma_data_direction direction)3613aa0a1e58SJeff Roberson static inline void ib_dma_unmap_sg(struct ib_device *dev,
3614aa0a1e58SJeff Roberson struct scatterlist *sg, int nents,
3615aa0a1e58SJeff Roberson enum dma_data_direction direction)
3616aa0a1e58SJeff Roberson {
3617aa0a1e58SJeff Roberson if (dev->dma_ops)
3618aa0a1e58SJeff Roberson dev->dma_ops->unmap_sg(dev, sg, nents, direction);
3619aa0a1e58SJeff Roberson else
3620aa0a1e58SJeff Roberson dma_unmap_sg(dev->dma_device, sg, nents, direction);
3621aa0a1e58SJeff Roberson }
3622aa0a1e58SJeff Roberson
ib_dma_map_sg_attrs(struct ib_device * dev,struct scatterlist * sg,int nents,enum dma_data_direction direction,struct dma_attrs * dma_attrs)3623aa0a1e58SJeff Roberson static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
3624aa0a1e58SJeff Roberson struct scatterlist *sg, int nents,
3625aa0a1e58SJeff Roberson enum dma_data_direction direction,
3626478d3005SHans Petter Selasky struct dma_attrs *dma_attrs)
3627aa0a1e58SJeff Roberson {
3628478d3005SHans Petter Selasky if (dev->dma_ops)
3629478d3005SHans Petter Selasky return dev->dma_ops->map_sg_attrs(dev, sg, nents, direction,
3630478d3005SHans Petter Selasky dma_attrs);
3631478d3005SHans Petter Selasky else
3632478d3005SHans Petter Selasky return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
3633478d3005SHans Petter Selasky dma_attrs);
3634aa0a1e58SJeff Roberson }
3635aa0a1e58SJeff Roberson
ib_dma_unmap_sg_attrs(struct ib_device * dev,struct scatterlist * sg,int nents,enum dma_data_direction direction,struct dma_attrs * dma_attrs)3636aa0a1e58SJeff Roberson static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
3637aa0a1e58SJeff Roberson struct scatterlist *sg, int nents,
3638aa0a1e58SJeff Roberson enum dma_data_direction direction,
3639478d3005SHans Petter Selasky struct dma_attrs *dma_attrs)
3640aa0a1e58SJeff Roberson {
3641478d3005SHans Petter Selasky if (dev->dma_ops)
3642478d3005SHans Petter Selasky return dev->dma_ops->unmap_sg_attrs(dev, sg, nents, direction,
3643478d3005SHans Petter Selasky dma_attrs);
3644478d3005SHans Petter Selasky else
3645478d3005SHans Petter Selasky dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction,
3646478d3005SHans Petter Selasky dma_attrs);
3647aa0a1e58SJeff Roberson }
3648aa0a1e58SJeff Roberson /**
3649aa0a1e58SJeff Roberson * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
3650aa0a1e58SJeff Roberson * @dev: The device for which the DMA addresses were created
3651aa0a1e58SJeff Roberson * @sg: The scatter/gather entry
3652478d3005SHans Petter Selasky *
3653478d3005SHans Petter Selasky * Note: this function is obsolete. To do: change all occurrences of
3654478d3005SHans Petter Selasky * ib_sg_dma_address() into sg_dma_address().
3655aa0a1e58SJeff Roberson */
ib_sg_dma_address(struct ib_device * dev,struct scatterlist * sg)3656aa0a1e58SJeff Roberson static inline u64 ib_sg_dma_address(struct ib_device *dev,
3657aa0a1e58SJeff Roberson struct scatterlist *sg)
3658aa0a1e58SJeff Roberson {
3659aa0a1e58SJeff Roberson return sg_dma_address(sg);
3660aa0a1e58SJeff Roberson }
3661aa0a1e58SJeff Roberson
3662aa0a1e58SJeff Roberson /**
3663aa0a1e58SJeff Roberson * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
3664aa0a1e58SJeff Roberson * @dev: The device for which the DMA addresses were created
3665aa0a1e58SJeff Roberson * @sg: The scatter/gather entry
3666478d3005SHans Petter Selasky *
3667478d3005SHans Petter Selasky * Note: this function is obsolete. To do: change all occurrences of
3668478d3005SHans Petter Selasky * ib_sg_dma_len() into sg_dma_len().
3669aa0a1e58SJeff Roberson */
ib_sg_dma_len(struct ib_device * dev,struct scatterlist * sg)3670aa0a1e58SJeff Roberson static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
3671aa0a1e58SJeff Roberson struct scatterlist *sg)
3672aa0a1e58SJeff Roberson {
3673aa0a1e58SJeff Roberson return sg_dma_len(sg);
3674aa0a1e58SJeff Roberson }
3675aa0a1e58SJeff Roberson
3676aa0a1e58SJeff Roberson /**
3677aa0a1e58SJeff Roberson * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
3678aa0a1e58SJeff Roberson * @dev: The device for which the DMA address was created
3679aa0a1e58SJeff Roberson * @addr: The DMA address
3680aa0a1e58SJeff Roberson * @size: The size of the region in bytes
3681aa0a1e58SJeff Roberson * @dir: The direction of the DMA
3682aa0a1e58SJeff Roberson */
ib_dma_sync_single_for_cpu(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction dir)3683aa0a1e58SJeff Roberson static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
3684aa0a1e58SJeff Roberson u64 addr,
3685aa0a1e58SJeff Roberson size_t size,
3686aa0a1e58SJeff Roberson enum dma_data_direction dir)
3687aa0a1e58SJeff Roberson {
3688aa0a1e58SJeff Roberson if (dev->dma_ops)
3689aa0a1e58SJeff Roberson dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
3690aa0a1e58SJeff Roberson else
3691aa0a1e58SJeff Roberson dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
3692aa0a1e58SJeff Roberson }
3693aa0a1e58SJeff Roberson
3694aa0a1e58SJeff Roberson /**
3695aa0a1e58SJeff Roberson * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
3696aa0a1e58SJeff Roberson * @dev: The device for which the DMA address was created
3697aa0a1e58SJeff Roberson * @addr: The DMA address
3698aa0a1e58SJeff Roberson * @size: The size of the region in bytes
3699aa0a1e58SJeff Roberson * @dir: The direction of the DMA
3700aa0a1e58SJeff Roberson */
ib_dma_sync_single_for_device(struct ib_device * dev,u64 addr,size_t size,enum dma_data_direction dir)3701aa0a1e58SJeff Roberson static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
3702aa0a1e58SJeff Roberson u64 addr,
3703aa0a1e58SJeff Roberson size_t size,
3704aa0a1e58SJeff Roberson enum dma_data_direction dir)
3705aa0a1e58SJeff Roberson {
3706aa0a1e58SJeff Roberson if (dev->dma_ops)
3707aa0a1e58SJeff Roberson dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
3708aa0a1e58SJeff Roberson else
3709aa0a1e58SJeff Roberson dma_sync_single_for_device(dev->dma_device, addr, size, dir);
3710aa0a1e58SJeff Roberson }
3711aa0a1e58SJeff Roberson
3712aa0a1e58SJeff Roberson /**
3713aa0a1e58SJeff Roberson * ib_dma_alloc_coherent - Allocate memory and map it for DMA
3714aa0a1e58SJeff Roberson * @dev: The device for which the DMA address is requested
3715aa0a1e58SJeff Roberson * @size: The size of the region to allocate in bytes
3716aa0a1e58SJeff Roberson * @dma_handle: A pointer for returning the DMA address of the region
3717aa0a1e58SJeff Roberson * @flag: memory allocator flags
3718aa0a1e58SJeff Roberson */
ib_dma_alloc_coherent(struct ib_device * dev,size_t size,u64 * dma_handle,gfp_t flag)3719aa0a1e58SJeff Roberson static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
3720aa0a1e58SJeff Roberson size_t size,
3721aa0a1e58SJeff Roberson u64 *dma_handle,
3722aa0a1e58SJeff Roberson gfp_t flag)
3723aa0a1e58SJeff Roberson {
3724aa0a1e58SJeff Roberson if (dev->dma_ops)
3725aa0a1e58SJeff Roberson return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
3726aa0a1e58SJeff Roberson else {
3727aa0a1e58SJeff Roberson dma_addr_t handle;
3728aa0a1e58SJeff Roberson void *ret;
3729aa0a1e58SJeff Roberson
3730aa0a1e58SJeff Roberson ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
3731aa0a1e58SJeff Roberson *dma_handle = handle;
3732aa0a1e58SJeff Roberson return ret;
3733aa0a1e58SJeff Roberson }
3734aa0a1e58SJeff Roberson }
3735aa0a1e58SJeff Roberson
3736aa0a1e58SJeff Roberson /**
3737aa0a1e58SJeff Roberson * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
3738aa0a1e58SJeff Roberson * @dev: The device for which the DMA addresses were allocated
3739aa0a1e58SJeff Roberson * @size: The size of the region
3740aa0a1e58SJeff Roberson * @cpu_addr: the address returned by ib_dma_alloc_coherent()
3741aa0a1e58SJeff Roberson * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
3742aa0a1e58SJeff Roberson */
ib_dma_free_coherent(struct ib_device * dev,size_t size,void * cpu_addr,u64 dma_handle)3743aa0a1e58SJeff Roberson static inline void ib_dma_free_coherent(struct ib_device *dev,
3744aa0a1e58SJeff Roberson size_t size, void *cpu_addr,
3745aa0a1e58SJeff Roberson u64 dma_handle)
3746aa0a1e58SJeff Roberson {
3747aa0a1e58SJeff Roberson if (dev->dma_ops)
3748aa0a1e58SJeff Roberson dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
3749aa0a1e58SJeff Roberson else
3750aa0a1e58SJeff Roberson dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
3751aa0a1e58SJeff Roberson }
3752aa0a1e58SJeff Roberson
3753aa0a1e58SJeff Roberson /**
3754aa0a1e58SJeff Roberson * ib_dereg_mr - Deregisters a memory region and removes it from the
3755aa0a1e58SJeff Roberson * HCA translation table.
3756aa0a1e58SJeff Roberson * @mr: The memory region to deregister.
3757b5c1e0cbSHans Petter Selasky *
3758b5c1e0cbSHans Petter Selasky * This function can fail, if the memory region has memory windows bound to it.
3759aa0a1e58SJeff Roberson */
3760b633e08cSHans Petter Selasky int ib_dereg_mr_user(struct ib_mr *mr, struct ib_udata *udata);
3761aa0a1e58SJeff Roberson
3762b633e08cSHans Petter Selasky /**
3763b633e08cSHans Petter Selasky * ib_dereg_mr - Deregisters a kernel memory region and removes it from the
3764b633e08cSHans Petter Selasky * HCA translation table.
3765b633e08cSHans Petter Selasky * @mr: The memory region to deregister.
3766b633e08cSHans Petter Selasky *
3767b633e08cSHans Petter Selasky * This function can fail, if the memory region has memory windows bound to it.
3768b633e08cSHans Petter Selasky *
3769b633e08cSHans Petter Selasky * NOTE: for user mr use ib_dereg_mr_user with valid udata!
3770b633e08cSHans Petter Selasky */
ib_dereg_mr(struct ib_mr * mr)3771b633e08cSHans Petter Selasky static inline int ib_dereg_mr(struct ib_mr *mr)
3772b633e08cSHans Petter Selasky {
3773b633e08cSHans Petter Selasky return ib_dereg_mr_user(mr, NULL);
3774b633e08cSHans Petter Selasky }
3775b633e08cSHans Petter Selasky
3776b633e08cSHans Petter Selasky struct ib_mr *ib_alloc_mr_user(struct ib_pd *pd, enum ib_mr_type mr_type,
3777b633e08cSHans Petter Selasky u32 max_num_sg, struct ib_udata *udata);
3778b633e08cSHans Petter Selasky
ib_alloc_mr(struct ib_pd * pd,enum ib_mr_type mr_type,u32 max_num_sg)3779b633e08cSHans Petter Selasky static inline struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
3780b633e08cSHans Petter Selasky enum ib_mr_type mr_type, u32 max_num_sg)
3781b633e08cSHans Petter Selasky {
3782b633e08cSHans Petter Selasky return ib_alloc_mr_user(pd, mr_type, max_num_sg, NULL);
3783b633e08cSHans Petter Selasky }
3784b633e08cSHans Petter Selasky
3785b633e08cSHans Petter Selasky struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
3786b633e08cSHans Petter Selasky u32 max_num_data_sg,
3787b633e08cSHans Petter Selasky u32 max_num_meta_sg);
3788aa0a1e58SJeff Roberson
3789aa0a1e58SJeff Roberson /**
3790aa0a1e58SJeff Roberson * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
3791aa0a1e58SJeff Roberson * R_Key and L_Key.
3792aa0a1e58SJeff Roberson * @mr - struct ib_mr pointer to be updated.
3793aa0a1e58SJeff Roberson * @newkey - new key to be used.
3794aa0a1e58SJeff Roberson */
ib_update_fast_reg_key(struct ib_mr * mr,u8 newkey)3795aa0a1e58SJeff Roberson static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
3796aa0a1e58SJeff Roberson {
3797aa0a1e58SJeff Roberson mr->lkey = (mr->lkey & 0xffffff00) | newkey;
3798aa0a1e58SJeff Roberson mr->rkey = (mr->rkey & 0xffffff00) | newkey;
3799aa0a1e58SJeff Roberson }
3800aa0a1e58SJeff Roberson
3801aa0a1e58SJeff Roberson /**
3802b5c1e0cbSHans Petter Selasky * ib_inc_rkey - increments the key portion of the given rkey. Can be used
3803b5c1e0cbSHans Petter Selasky * for calculating a new rkey for type 2 memory windows.
3804b5c1e0cbSHans Petter Selasky * @rkey - the rkey to increment.
3805b5c1e0cbSHans Petter Selasky */
ib_inc_rkey(u32 rkey)3806b5c1e0cbSHans Petter Selasky static inline u32 ib_inc_rkey(u32 rkey)
3807b5c1e0cbSHans Petter Selasky {
3808b5c1e0cbSHans Petter Selasky const u32 mask = 0x000000ff;
3809b5c1e0cbSHans Petter Selasky return ((rkey + 1) & mask) | (rkey & ~mask);
3810b5c1e0cbSHans Petter Selasky }
3811b5c1e0cbSHans Petter Selasky
3812b5c1e0cbSHans Petter Selasky /**
3813aa0a1e58SJeff Roberson * ib_alloc_fmr - Allocates a unmapped fast memory region.
3814aa0a1e58SJeff Roberson * @pd: The protection domain associated with the unmapped region.
3815aa0a1e58SJeff Roberson * @mr_access_flags: Specifies the memory access rights.
3816aa0a1e58SJeff Roberson * @fmr_attr: Attributes of the unmapped region.
3817aa0a1e58SJeff Roberson *
3818aa0a1e58SJeff Roberson * A fast memory region must be mapped before it can be used as part of
3819aa0a1e58SJeff Roberson * a work request.
3820aa0a1e58SJeff Roberson */
3821aa0a1e58SJeff Roberson struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
3822aa0a1e58SJeff Roberson int mr_access_flags,
3823aa0a1e58SJeff Roberson struct ib_fmr_attr *fmr_attr);
3824aa0a1e58SJeff Roberson
3825aa0a1e58SJeff Roberson /**
3826aa0a1e58SJeff Roberson * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
3827aa0a1e58SJeff Roberson * @fmr: The fast memory region to associate with the pages.
3828aa0a1e58SJeff Roberson * @page_list: An array of physical pages to map to the fast memory region.
3829aa0a1e58SJeff Roberson * @list_len: The number of pages in page_list.
3830aa0a1e58SJeff Roberson * @iova: The I/O virtual address to use with the mapped region.
3831aa0a1e58SJeff Roberson */
ib_map_phys_fmr(struct ib_fmr * fmr,u64 * page_list,int list_len,u64 iova)3832aa0a1e58SJeff Roberson static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
3833aa0a1e58SJeff Roberson u64 *page_list, int list_len,
3834aa0a1e58SJeff Roberson u64 iova)
3835aa0a1e58SJeff Roberson {
3836aa0a1e58SJeff Roberson return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
3837aa0a1e58SJeff Roberson }
3838aa0a1e58SJeff Roberson
3839aa0a1e58SJeff Roberson /**
3840aa0a1e58SJeff Roberson * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
3841aa0a1e58SJeff Roberson * @fmr_list: A linked list of fast memory regions to unmap.
3842aa0a1e58SJeff Roberson */
3843aa0a1e58SJeff Roberson int ib_unmap_fmr(struct list_head *fmr_list);
3844aa0a1e58SJeff Roberson
3845aa0a1e58SJeff Roberson /**
3846aa0a1e58SJeff Roberson * ib_dealloc_fmr - Deallocates a fast memory region.
3847aa0a1e58SJeff Roberson * @fmr: The fast memory region to deallocate.
3848aa0a1e58SJeff Roberson */
3849aa0a1e58SJeff Roberson int ib_dealloc_fmr(struct ib_fmr *fmr);
3850aa0a1e58SJeff Roberson
3851aa0a1e58SJeff Roberson /**
3852aa0a1e58SJeff Roberson * ib_attach_mcast - Attaches the specified QP to a multicast group.
3853aa0a1e58SJeff Roberson * @qp: QP to attach to the multicast group. The QP must be type
3854aa0a1e58SJeff Roberson * IB_QPT_UD.
3855aa0a1e58SJeff Roberson * @gid: Multicast group GID.
3856aa0a1e58SJeff Roberson * @lid: Multicast group LID in host byte order.
3857aa0a1e58SJeff Roberson *
3858aa0a1e58SJeff Roberson * In order to send and receive multicast packets, subnet
3859aa0a1e58SJeff Roberson * administration must have created the multicast group and configured
3860aa0a1e58SJeff Roberson * the fabric appropriately. The port associated with the specified
3861aa0a1e58SJeff Roberson * QP must also be a member of the multicast group.
3862aa0a1e58SJeff Roberson */
3863aa0a1e58SJeff Roberson int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
3864aa0a1e58SJeff Roberson
3865aa0a1e58SJeff Roberson /**
3866aa0a1e58SJeff Roberson * ib_detach_mcast - Detaches the specified QP from a multicast group.
3867aa0a1e58SJeff Roberson * @qp: QP to detach from the multicast group.
3868aa0a1e58SJeff Roberson * @gid: Multicast group GID.
3869aa0a1e58SJeff Roberson * @lid: Multicast group LID in host byte order.
3870aa0a1e58SJeff Roberson */
3871aa0a1e58SJeff Roberson int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
3872aa0a1e58SJeff Roberson
3873c9f432b7SAlfred Perlstein /**
3874c9f432b7SAlfred Perlstein * ib_alloc_xrcd - Allocates an XRC domain.
3875c9f432b7SAlfred Perlstein * @device: The device on which to allocate the XRC domain.
3876b633e08cSHans Petter Selasky * @caller: Module name for kernel consumers
3877c9f432b7SAlfred Perlstein */
3878b633e08cSHans Petter Selasky struct ib_xrcd *__ib_alloc_xrcd(struct ib_device *device, const char *caller);
3879b633e08cSHans Petter Selasky #define ib_alloc_xrcd(device) \
3880b633e08cSHans Petter Selasky __ib_alloc_xrcd((device), "ibcore")
3881aa0a1e58SJeff Roberson
3882aa0a1e58SJeff Roberson /**
3883c9f432b7SAlfred Perlstein * ib_dealloc_xrcd - Deallocates an XRC domain.
3884c9f432b7SAlfred Perlstein * @xrcd: The XRC domain to deallocate.
3885b633e08cSHans Petter Selasky * @udata: Valid user data or NULL for kernel object
3886aa0a1e58SJeff Roberson */
3887b633e08cSHans Petter Selasky int ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
3888b5c1e0cbSHans Petter Selasky
ib_check_mr_access(int flags)3889b5c1e0cbSHans Petter Selasky static inline int ib_check_mr_access(int flags)
3890b5c1e0cbSHans Petter Selasky {
3891b5c1e0cbSHans Petter Selasky /*
3892b5c1e0cbSHans Petter Selasky * Local write permission is required if remote write or
3893b5c1e0cbSHans Petter Selasky * remote atomic permission is also requested.
3894b5c1e0cbSHans Petter Selasky */
3895b5c1e0cbSHans Petter Selasky if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
3896b5c1e0cbSHans Petter Selasky !(flags & IB_ACCESS_LOCAL_WRITE))
3897b5c1e0cbSHans Petter Selasky return -EINVAL;
3898b5c1e0cbSHans Petter Selasky
3899b633e08cSHans Petter Selasky if (flags & ~IB_ACCESS_SUPPORTED)
3900b633e08cSHans Petter Selasky return -EINVAL;
3901b633e08cSHans Petter Selasky
3902b5c1e0cbSHans Petter Selasky return 0;
3903b5c1e0cbSHans Petter Selasky }
3904b5c1e0cbSHans Petter Selasky
ib_access_writable(int access_flags)3905b633e08cSHans Petter Selasky static inline bool ib_access_writable(int access_flags)
3906b633e08cSHans Petter Selasky {
3907b633e08cSHans Petter Selasky /*
3908b633e08cSHans Petter Selasky * We have writable memory backing the MR if any of the following
3909b633e08cSHans Petter Selasky * access flags are set. "Local write" and "remote write" obviously
3910b633e08cSHans Petter Selasky * require write access. "Remote atomic" can do things like fetch and
3911b633e08cSHans Petter Selasky * add, which will modify memory, and "MW bind" can change permissions
3912b633e08cSHans Petter Selasky * by binding a window.
3913b633e08cSHans Petter Selasky */
3914b633e08cSHans Petter Selasky return access_flags &
3915b633e08cSHans Petter Selasky (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE |
3916b633e08cSHans Petter Selasky IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND);
3917b633e08cSHans Petter Selasky }
3918b633e08cSHans Petter Selasky
3919b5c1e0cbSHans Petter Selasky /**
3920b5c1e0cbSHans Petter Selasky * ib_check_mr_status: lightweight check of MR status.
3921b5c1e0cbSHans Petter Selasky * This routine may provide status checks on a selected
3922b5c1e0cbSHans Petter Selasky * ib_mr. first use is for signature status check.
3923b5c1e0cbSHans Petter Selasky *
3924b5c1e0cbSHans Petter Selasky * @mr: A memory region.
3925b5c1e0cbSHans Petter Selasky * @check_mask: Bitmask of which checks to perform from
3926b5c1e0cbSHans Petter Selasky * ib_mr_status_check enumeration.
3927b5c1e0cbSHans Petter Selasky * @mr_status: The container of relevant status checks.
3928b5c1e0cbSHans Petter Selasky * failed checks will be indicated in the status bitmask
3929b5c1e0cbSHans Petter Selasky * and the relevant info shall be in the error item.
3930b5c1e0cbSHans Petter Selasky */
3931b5c1e0cbSHans Petter Selasky int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
3932b5c1e0cbSHans Petter Selasky struct ib_mr_status *mr_status);
3933aa0a1e58SJeff Roberson
39343e142e07SJustin Hibbits if_t ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
3935478d3005SHans Petter Selasky u16 pkey, const union ib_gid *gid,
3936478d3005SHans Petter Selasky const struct sockaddr *addr);
3937478d3005SHans Petter Selasky struct ib_wq *ib_create_wq(struct ib_pd *pd,
3938478d3005SHans Petter Selasky struct ib_wq_init_attr *init_attr);
3939b633e08cSHans Petter Selasky int ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata);
3940478d3005SHans Petter Selasky int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
3941478d3005SHans Petter Selasky u32 wq_attr_mask);
3942478d3005SHans Petter Selasky struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
3943478d3005SHans Petter Selasky struct ib_rwq_ind_table_init_attr*
3944478d3005SHans Petter Selasky wq_ind_table_init_attr);
3945478d3005SHans Petter Selasky int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
3946478d3005SHans Petter Selasky
3947478d3005SHans Petter Selasky int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
3948478d3005SHans Petter Selasky unsigned int *sg_offset, unsigned int page_size);
3949478d3005SHans Petter Selasky
3950478d3005SHans Petter Selasky static inline int
ib_map_mr_sg_zbva(struct ib_mr * mr,struct scatterlist * sg,int sg_nents,unsigned int * sg_offset,unsigned int page_size)3951478d3005SHans Petter Selasky ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
3952478d3005SHans Petter Selasky unsigned int *sg_offset, unsigned int page_size)
3953478d3005SHans Petter Selasky {
3954478d3005SHans Petter Selasky int n;
3955478d3005SHans Petter Selasky
3956478d3005SHans Petter Selasky n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
3957478d3005SHans Petter Selasky mr->iova = 0;
3958478d3005SHans Petter Selasky
3959478d3005SHans Petter Selasky return n;
3960478d3005SHans Petter Selasky }
3961478d3005SHans Petter Selasky
3962478d3005SHans Petter Selasky int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
3963478d3005SHans Petter Selasky unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
3964478d3005SHans Petter Selasky
3965478d3005SHans Petter Selasky void ib_drain_rq(struct ib_qp *qp);
3966478d3005SHans Petter Selasky void ib_drain_sq(struct ib_qp *qp);
3967478d3005SHans Petter Selasky void ib_drain_qp(struct ib_qp *qp);
39681456d97cSHans Petter Selasky
396979b81708SHans Petter Selasky struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
397079b81708SHans Petter Selasky
3971b633e08cSHans Petter Selasky int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs);
3972b633e08cSHans Petter Selasky
39731456d97cSHans Petter Selasky int ib_resolve_eth_dmac(struct ib_device *device,
39741456d97cSHans Petter Selasky struct ib_ah_attr *ah_attr);
3975aa0a1e58SJeff Roberson #endif /* IB_VERBS_H */
3976