xref: /freebsd/sys/ofed/include/rdma/ib_verbs.h (revision 79b817084ca891e465fe1a868ef1d9f1a3f33a69)
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.
3909938b21SHans Petter Selasky  *
4009938b21SHans Petter Selasky  * $FreeBSD$
41aa0a1e58SJeff Roberson  */
42aa0a1e58SJeff Roberson 
43aa0a1e58SJeff Roberson #if !defined(IB_VERBS_H)
44aa0a1e58SJeff Roberson #define IB_VERBS_H
45aa0a1e58SJeff Roberson 
46aa0a1e58SJeff Roberson #include <linux/types.h>
47aa0a1e58SJeff Roberson #include <linux/device.h>
48aa0a1e58SJeff Roberson #include <linux/mm.h>
49aa0a1e58SJeff Roberson #include <linux/dma-mapping.h>
50aa0a1e58SJeff Roberson #include <linux/kref.h>
51aa0a1e58SJeff Roberson #include <linux/list.h>
52aa0a1e58SJeff Roberson #include <linux/rwsem.h>
53aa0a1e58SJeff Roberson #include <linux/scatterlist.h>
54c9f432b7SAlfred Perlstein #include <linux/workqueue.h>
55478d3005SHans Petter Selasky #include <linux/socket.h>
56b5c1e0cbSHans Petter Selasky #include <linux/if_ether.h>
57478d3005SHans Petter Selasky #include <net/ipv6.h>
58478d3005SHans Petter Selasky #include <net/ip.h>
59478d3005SHans Petter Selasky #include <linux/string.h>
60478d3005SHans Petter Selasky #include <linux/slab.h>
61478d3005SHans Petter Selasky #include <linux/rcupdate.h>
62478d3005SHans Petter Selasky #include <linux/netdevice.h>
63478d3005SHans Petter Selasky #include <netinet/ip.h>
64aa0a1e58SJeff Roberson 
65478d3005SHans Petter Selasky #include <asm/atomic.h>
66aa0a1e58SJeff Roberson #include <asm/uaccess.h>
67aa0a1e58SJeff Roberson 
68478d3005SHans Petter Selasky struct ifla_vf_info;
69478d3005SHans Petter Selasky struct ifla_vf_stats;
70*79b81708SHans Petter Selasky struct ib_uverbs_file;
71478d3005SHans Petter Selasky 
72c9f432b7SAlfred Perlstein extern struct workqueue_struct *ib_wq;
73478d3005SHans Petter Selasky extern struct workqueue_struct *ib_comp_wq;
74c9f432b7SAlfred Perlstein 
75aa0a1e58SJeff Roberson union ib_gid {
76aa0a1e58SJeff Roberson 	u8	raw[16];
77aa0a1e58SJeff Roberson 	struct {
78aa0a1e58SJeff Roberson 		__be64	subnet_prefix;
79aa0a1e58SJeff Roberson 		__be64	interface_id;
80aa0a1e58SJeff Roberson 	} global;
81aa0a1e58SJeff Roberson };
82aa0a1e58SJeff Roberson 
83478d3005SHans Petter Selasky extern union ib_gid zgid;
84478d3005SHans Petter Selasky 
85478d3005SHans Petter Selasky enum ib_gid_type {
86478d3005SHans Petter Selasky 	/* If link layer is Ethernet, this is RoCE V1 */
87478d3005SHans Petter Selasky 	IB_GID_TYPE_IB        = 0,
88478d3005SHans Petter Selasky 	IB_GID_TYPE_ROCE      = 0,
89478d3005SHans Petter Selasky 	IB_GID_TYPE_ROCE_UDP_ENCAP = 1,
90478d3005SHans Petter Selasky 	IB_GID_TYPE_SIZE
91478d3005SHans Petter Selasky };
92478d3005SHans Petter Selasky 
93478d3005SHans Petter Selasky #define ROCE_V2_UDP_DPORT      4791
94478d3005SHans Petter Selasky struct ib_gid_attr {
95478d3005SHans Petter Selasky 	enum ib_gid_type	gid_type;
961411f52fSBjoern A. Zeeb 	struct ifnet	*ndev;
97478d3005SHans Petter Selasky };
98478d3005SHans Petter Selasky 
99aa0a1e58SJeff Roberson enum rdma_node_type {
100aa0a1e58SJeff Roberson 	/* IB values map to NodeInfo:NodeType. */
101aa0a1e58SJeff Roberson 	RDMA_NODE_IB_CA 	= 1,
102aa0a1e58SJeff Roberson 	RDMA_NODE_IB_SWITCH,
103aa0a1e58SJeff Roberson 	RDMA_NODE_IB_ROUTER,
104b5c1e0cbSHans Petter Selasky 	RDMA_NODE_RNIC,
105478d3005SHans Petter Selasky 	RDMA_NODE_USNIC,
106478d3005SHans Petter Selasky 	RDMA_NODE_USNIC_UDP,
107478d3005SHans Petter Selasky };
108478d3005SHans Petter Selasky 
109478d3005SHans Petter Selasky enum {
110478d3005SHans Petter Selasky 	/* set the local administered indication */
111478d3005SHans Petter Selasky 	IB_SA_WELL_KNOWN_GUID	= BIT_ULL(57) | 2,
112aa0a1e58SJeff Roberson };
113aa0a1e58SJeff Roberson 
114aa0a1e58SJeff Roberson enum rdma_transport_type {
115aa0a1e58SJeff Roberson 	RDMA_TRANSPORT_IB,
116b5c1e0cbSHans Petter Selasky 	RDMA_TRANSPORT_IWARP,
117478d3005SHans Petter Selasky 	RDMA_TRANSPORT_USNIC,
118478d3005SHans Petter Selasky 	RDMA_TRANSPORT_USNIC_UDP
119aa0a1e58SJeff Roberson };
120aa0a1e58SJeff Roberson 
121478d3005SHans Petter Selasky enum rdma_protocol_type {
122478d3005SHans Petter Selasky 	RDMA_PROTOCOL_IB,
123478d3005SHans Petter Selasky 	RDMA_PROTOCOL_IBOE,
124478d3005SHans Petter Selasky 	RDMA_PROTOCOL_IWARP,
125478d3005SHans Petter Selasky 	RDMA_PROTOCOL_USNIC_UDP
126478d3005SHans Petter Selasky };
127478d3005SHans Petter Selasky 
128478d3005SHans Petter Selasky __attribute_const__ enum rdma_transport_type
129478d3005SHans Petter Selasky rdma_node_get_transport(enum rdma_node_type node_type);
130478d3005SHans Petter Selasky 
131478d3005SHans Petter Selasky enum rdma_network_type {
132478d3005SHans Petter Selasky 	RDMA_NETWORK_IB,
133478d3005SHans Petter Selasky 	RDMA_NETWORK_ROCE_V1 = RDMA_NETWORK_IB,
134478d3005SHans Petter Selasky 	RDMA_NETWORK_IPV4,
135478d3005SHans Petter Selasky 	RDMA_NETWORK_IPV6
136478d3005SHans Petter Selasky };
137478d3005SHans Petter Selasky 
138478d3005SHans Petter Selasky static inline enum ib_gid_type ib_network_to_gid_type(enum rdma_network_type network_type)
139478d3005SHans Petter Selasky {
140478d3005SHans Petter Selasky 	if (network_type == RDMA_NETWORK_IPV4 ||
141478d3005SHans Petter Selasky 	    network_type == RDMA_NETWORK_IPV6)
142478d3005SHans Petter Selasky 		return IB_GID_TYPE_ROCE_UDP_ENCAP;
143478d3005SHans Petter Selasky 
144478d3005SHans Petter Selasky 	/* IB_GID_TYPE_IB same as RDMA_NETWORK_ROCE_V1 */
145478d3005SHans Petter Selasky 	return IB_GID_TYPE_IB;
146478d3005SHans Petter Selasky }
147478d3005SHans Petter Selasky 
148478d3005SHans Petter Selasky static inline enum rdma_network_type ib_gid_to_network_type(enum ib_gid_type gid_type,
149478d3005SHans Petter Selasky 							    union ib_gid *gid)
150478d3005SHans Petter Selasky {
151478d3005SHans Petter Selasky 	if (gid_type == IB_GID_TYPE_IB)
152478d3005SHans Petter Selasky 		return RDMA_NETWORK_IB;
153478d3005SHans Petter Selasky 
154478d3005SHans Petter Selasky 	if (ipv6_addr_v4mapped((struct in6_addr *)gid))
155478d3005SHans Petter Selasky 		return RDMA_NETWORK_IPV4;
156478d3005SHans Petter Selasky 	else
157478d3005SHans Petter Selasky 		return RDMA_NETWORK_IPV6;
158478d3005SHans Petter Selasky }
159aa0a1e58SJeff Roberson 
160aa0a1e58SJeff Roberson enum rdma_link_layer {
161aa0a1e58SJeff Roberson 	IB_LINK_LAYER_UNSPECIFIED,
162aa0a1e58SJeff Roberson 	IB_LINK_LAYER_INFINIBAND,
163aa0a1e58SJeff Roberson 	IB_LINK_LAYER_ETHERNET,
164aa0a1e58SJeff Roberson };
165aa0a1e58SJeff Roberson 
166aa0a1e58SJeff Roberson enum ib_device_cap_flags {
167478d3005SHans Petter Selasky 	IB_DEVICE_RESIZE_MAX_WR			= (1 << 0),
168aa0a1e58SJeff Roberson 	IB_DEVICE_BAD_PKEY_CNTR			= (1 << 1),
169aa0a1e58SJeff Roberson 	IB_DEVICE_BAD_QKEY_CNTR			= (1 << 2),
170aa0a1e58SJeff Roberson 	IB_DEVICE_RAW_MULTI			= (1 << 3),
171aa0a1e58SJeff Roberson 	IB_DEVICE_AUTO_PATH_MIG			= (1 << 4),
172aa0a1e58SJeff Roberson 	IB_DEVICE_CHANGE_PHY_PORT		= (1 << 5),
173aa0a1e58SJeff Roberson 	IB_DEVICE_UD_AV_PORT_ENFORCE		= (1 << 6),
174aa0a1e58SJeff Roberson 	IB_DEVICE_CURR_QP_STATE_MOD		= (1 << 7),
175aa0a1e58SJeff Roberson 	IB_DEVICE_SHUTDOWN_PORT			= (1 << 8),
176aa0a1e58SJeff Roberson 	IB_DEVICE_INIT_TYPE			= (1 << 9),
177aa0a1e58SJeff Roberson 	IB_DEVICE_PORT_ACTIVE_EVENT		= (1 << 10),
178aa0a1e58SJeff Roberson 	IB_DEVICE_SYS_IMAGE_GUID		= (1 << 11),
179aa0a1e58SJeff Roberson 	IB_DEVICE_RC_RNR_NAK_GEN		= (1 << 12),
180aa0a1e58SJeff Roberson 	IB_DEVICE_SRQ_RESIZE			= (1 << 13),
181aa0a1e58SJeff Roberson 	IB_DEVICE_N_NOTIFY_CQ			= (1 << 14),
182478d3005SHans Petter Selasky 
183478d3005SHans Petter Selasky 	/*
184478d3005SHans Petter Selasky 	 * This device supports a per-device lkey or stag that can be
185478d3005SHans Petter Selasky 	 * used without performing a memory registration for the local
186478d3005SHans Petter Selasky 	 * memory.  Note that ULPs should never check this flag, but
187478d3005SHans Petter Selasky 	 * instead of use the local_dma_lkey flag in the ib_pd structure,
188478d3005SHans Petter Selasky 	 * which will always contain a usable lkey.
189478d3005SHans Petter Selasky 	 */
190aa0a1e58SJeff Roberson 	IB_DEVICE_LOCAL_DMA_LKEY		= (1 << 15),
191478d3005SHans Petter Selasky 	IB_DEVICE_RESERVED /* old SEND_W_INV */	= (1 << 16),
192aa0a1e58SJeff Roberson 	IB_DEVICE_MEM_WINDOW			= (1 << 17),
193aa0a1e58SJeff Roberson 	/*
194aa0a1e58SJeff Roberson 	 * Devices should set IB_DEVICE_UD_IP_SUM if they support
195aa0a1e58SJeff Roberson 	 * insertion of UDP and TCP checksum on outgoing UD IPoIB
196aa0a1e58SJeff Roberson 	 * messages and can verify the validity of checksum for
197aa0a1e58SJeff Roberson 	 * incoming messages.  Setting this flag implies that the
198aa0a1e58SJeff Roberson 	 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
199aa0a1e58SJeff Roberson 	 */
200aa0a1e58SJeff Roberson 	IB_DEVICE_UD_IP_CSUM			= (1 << 18),
201aa0a1e58SJeff Roberson 	IB_DEVICE_UD_TSO			= (1 << 19),
202aa0a1e58SJeff Roberson 	IB_DEVICE_XRC				= (1 << 20),
203478d3005SHans Petter Selasky 
204478d3005SHans Petter Selasky 	/*
205478d3005SHans Petter Selasky 	 * This device supports the IB "base memory management extension",
206478d3005SHans Petter Selasky 	 * which includes support for fast registrations (IB_WR_REG_MR,
207478d3005SHans Petter Selasky 	 * IB_WR_LOCAL_INV and IB_WR_SEND_WITH_INV verbs).  This flag should
208478d3005SHans Petter Selasky 	 * also be set by any iWarp device which must support FRs to comply
209478d3005SHans Petter Selasky 	 * to the iWarp verbs spec.  iWarp devices also support the
210478d3005SHans Petter Selasky 	 * IB_WR_RDMA_READ_WITH_INV verb for RDMA READs that invalidate the
211478d3005SHans Petter Selasky 	 * stag.
212478d3005SHans Petter Selasky 	 */
213aa0a1e58SJeff Roberson 	IB_DEVICE_MEM_MGT_EXTENSIONS		= (1 << 21),
214aa0a1e58SJeff Roberson 	IB_DEVICE_BLOCK_MULTICAST_LOOPBACK	= (1 << 22),
215478d3005SHans Petter Selasky 	IB_DEVICE_MEM_WINDOW_TYPE_2A		= (1 << 23),
216478d3005SHans Petter Selasky 	IB_DEVICE_MEM_WINDOW_TYPE_2B		= (1 << 24),
217478d3005SHans Petter Selasky 	IB_DEVICE_RC_IP_CSUM			= (1 << 25),
218478d3005SHans Petter Selasky 	IB_DEVICE_RAW_IP_CSUM			= (1 << 26),
219b5c1e0cbSHans Petter Selasky 	/*
220478d3005SHans Petter Selasky 	 * Devices should set IB_DEVICE_CROSS_CHANNEL if they
221478d3005SHans Petter Selasky 	 * support execution of WQEs that involve synchronization
222478d3005SHans Petter Selasky 	 * of I/O operations with single completion queue managed
223478d3005SHans Petter Selasky 	 * by hardware.
224b5c1e0cbSHans Petter Selasky 	 */
225478d3005SHans Petter Selasky 	IB_DEVICE_CROSS_CHANNEL		= (1 << 27),
226478d3005SHans Petter Selasky 	IB_DEVICE_MANAGED_FLOW_STEERING		= (1 << 29),
227478d3005SHans Petter Selasky 	IB_DEVICE_SIGNATURE_HANDOVER		= (1 << 30),
228478d3005SHans Petter Selasky 	IB_DEVICE_ON_DEMAND_PAGING		= (1ULL << 31),
229478d3005SHans Petter Selasky 	IB_DEVICE_SG_GAPS_REG			= (1ULL << 32),
230478d3005SHans Petter Selasky 	IB_DEVICE_VIRTUAL_FUNCTION		= (1ULL << 33),
231478d3005SHans Petter Selasky 	IB_DEVICE_RAW_SCATTER_FCS		= (1ULL << 34),
232b5c1e0cbSHans Petter Selasky };
233b5c1e0cbSHans Petter Selasky 
234b5c1e0cbSHans Petter Selasky enum ib_signature_prot_cap {
235b5c1e0cbSHans Petter Selasky 	IB_PROT_T10DIF_TYPE_1 = 1,
236b5c1e0cbSHans Petter Selasky 	IB_PROT_T10DIF_TYPE_2 = 1 << 1,
237b5c1e0cbSHans Petter Selasky 	IB_PROT_T10DIF_TYPE_3 = 1 << 2,
238b5c1e0cbSHans Petter Selasky };
239b5c1e0cbSHans Petter Selasky 
240b5c1e0cbSHans Petter Selasky enum ib_signature_guard_cap {
241b5c1e0cbSHans Petter Selasky 	IB_GUARD_T10DIF_CRC	= 1,
242b5c1e0cbSHans Petter Selasky 	IB_GUARD_T10DIF_CSUM	= 1 << 1,
243aa0a1e58SJeff Roberson };
244aa0a1e58SJeff Roberson 
245aa0a1e58SJeff Roberson enum ib_atomic_cap {
246aa0a1e58SJeff Roberson 	IB_ATOMIC_NONE,
247aa0a1e58SJeff Roberson 	IB_ATOMIC_HCA,
248aa0a1e58SJeff Roberson 	IB_ATOMIC_GLOB
249aa0a1e58SJeff Roberson };
250aa0a1e58SJeff Roberson 
251478d3005SHans Petter Selasky enum ib_odp_general_cap_bits {
252478d3005SHans Petter Selasky 	IB_ODP_SUPPORT = 1 << 0,
253478d3005SHans Petter Selasky };
254478d3005SHans Petter Selasky 
255478d3005SHans Petter Selasky enum ib_odp_transport_cap_bits {
256478d3005SHans Petter Selasky 	IB_ODP_SUPPORT_SEND	= 1 << 0,
257478d3005SHans Petter Selasky 	IB_ODP_SUPPORT_RECV	= 1 << 1,
258478d3005SHans Petter Selasky 	IB_ODP_SUPPORT_WRITE	= 1 << 2,
259478d3005SHans Petter Selasky 	IB_ODP_SUPPORT_READ	= 1 << 3,
260478d3005SHans Petter Selasky 	IB_ODP_SUPPORT_ATOMIC	= 1 << 4,
261478d3005SHans Petter Selasky };
262478d3005SHans Petter Selasky 
263478d3005SHans Petter Selasky struct ib_odp_caps {
264478d3005SHans Petter Selasky 	uint64_t general_caps;
265478d3005SHans Petter Selasky 	struct {
266478d3005SHans Petter Selasky 		uint32_t  rc_odp_caps;
267478d3005SHans Petter Selasky 		uint32_t  uc_odp_caps;
268478d3005SHans Petter Selasky 		uint32_t  ud_odp_caps;
269478d3005SHans Petter Selasky 	} per_transport_caps;
270478d3005SHans Petter Selasky };
271478d3005SHans Petter Selasky 
272478d3005SHans Petter Selasky struct ib_rss_caps {
273478d3005SHans Petter Selasky 	/* Corresponding bit will be set if qp type from
274478d3005SHans Petter Selasky 	 * 'enum ib_qp_type' is supported, e.g.
275478d3005SHans Petter Selasky 	 * supported_qpts |= 1 << IB_QPT_UD
276478d3005SHans Petter Selasky 	 */
277478d3005SHans Petter Selasky 	u32 supported_qpts;
278478d3005SHans Petter Selasky 	u32 max_rwq_indirection_tables;
279478d3005SHans Petter Selasky 	u32 max_rwq_indirection_table_size;
280478d3005SHans Petter Selasky };
281478d3005SHans Petter Selasky 
282478d3005SHans Petter Selasky enum ib_cq_creation_flags {
283478d3005SHans Petter Selasky 	IB_CQ_FLAGS_TIMESTAMP_COMPLETION   = 1 << 0,
284478d3005SHans Petter Selasky 	IB_CQ_FLAGS_IGNORE_OVERRUN	   = 1 << 1,
285478d3005SHans Petter Selasky };
286478d3005SHans Petter Selasky 
287478d3005SHans Petter Selasky struct ib_cq_init_attr {
288478d3005SHans Petter Selasky 	unsigned int	cqe;
28992203578SHans Petter Selasky 	u32		comp_vector;
290478d3005SHans Petter Selasky 	u32		flags;
291b5c1e0cbSHans Petter Selasky };
292b5c1e0cbSHans Petter Selasky 
293aa0a1e58SJeff Roberson struct ib_device_attr {
294aa0a1e58SJeff Roberson 	u64			fw_ver;
295aa0a1e58SJeff Roberson 	__be64			sys_image_guid;
296aa0a1e58SJeff Roberson 	u64			max_mr_size;
297aa0a1e58SJeff Roberson 	u64			page_size_cap;
298aa0a1e58SJeff Roberson 	u32			vendor_id;
299aa0a1e58SJeff Roberson 	u32			vendor_part_id;
300aa0a1e58SJeff Roberson 	u32			hw_ver;
301aa0a1e58SJeff Roberson 	int			max_qp;
302aa0a1e58SJeff Roberson 	int			max_qp_wr;
303b5c1e0cbSHans Petter Selasky 	u64			device_cap_flags;
304aa0a1e58SJeff Roberson 	int			max_sge;
305aa0a1e58SJeff Roberson 	int			max_sge_rd;
306aa0a1e58SJeff Roberson 	int			max_cq;
307aa0a1e58SJeff Roberson 	int			max_cqe;
308aa0a1e58SJeff Roberson 	int			max_mr;
309aa0a1e58SJeff Roberson 	int			max_pd;
310aa0a1e58SJeff Roberson 	int			max_qp_rd_atom;
311aa0a1e58SJeff Roberson 	int			max_ee_rd_atom;
312aa0a1e58SJeff Roberson 	int			max_res_rd_atom;
313aa0a1e58SJeff Roberson 	int			max_qp_init_rd_atom;
314aa0a1e58SJeff Roberson 	int			max_ee_init_rd_atom;
315aa0a1e58SJeff Roberson 	enum ib_atomic_cap	atomic_cap;
316aa0a1e58SJeff Roberson 	enum ib_atomic_cap	masked_atomic_cap;
317aa0a1e58SJeff Roberson 	int			max_ee;
318aa0a1e58SJeff Roberson 	int			max_rdd;
319aa0a1e58SJeff Roberson 	int			max_mw;
320aa0a1e58SJeff Roberson 	int			max_raw_ipv6_qp;
321aa0a1e58SJeff Roberson 	int			max_raw_ethy_qp;
322aa0a1e58SJeff Roberson 	int			max_mcast_grp;
323aa0a1e58SJeff Roberson 	int			max_mcast_qp_attach;
324aa0a1e58SJeff Roberson 	int			max_total_mcast_qp_attach;
325aa0a1e58SJeff Roberson 	int			max_ah;
326aa0a1e58SJeff Roberson 	int			max_fmr;
327aa0a1e58SJeff Roberson 	int			max_map_per_fmr;
328aa0a1e58SJeff Roberson 	int			max_srq;
329aa0a1e58SJeff Roberson 	int			max_srq_wr;
330aa0a1e58SJeff Roberson 	int			max_srq_sge;
331aa0a1e58SJeff Roberson 	unsigned int		max_fast_reg_page_list_len;
332aa0a1e58SJeff Roberson 	u16			max_pkeys;
333aa0a1e58SJeff Roberson 	u8			local_ca_ack_delay;
334478d3005SHans Petter Selasky 	int			sig_prot_cap;
335478d3005SHans Petter Selasky 	int			sig_guard_cap;
336478d3005SHans Petter Selasky 	struct ib_odp_caps	odp_caps;
337b5c1e0cbSHans Petter Selasky 	uint64_t		timestamp_mask;
338478d3005SHans Petter Selasky 	uint64_t		hca_core_clock; /* in KHZ */
339478d3005SHans Petter Selasky 	struct ib_rss_caps	rss_caps;
340478d3005SHans Petter Selasky 	u32			max_wq_type_rq;
341aa0a1e58SJeff Roberson };
342aa0a1e58SJeff Roberson 
343aa0a1e58SJeff Roberson enum ib_mtu {
344aa0a1e58SJeff Roberson 	IB_MTU_256  = 1,
345aa0a1e58SJeff Roberson 	IB_MTU_512  = 2,
346aa0a1e58SJeff Roberson 	IB_MTU_1024 = 3,
347aa0a1e58SJeff Roberson 	IB_MTU_2048 = 4,
348aa0a1e58SJeff Roberson 	IB_MTU_4096 = 5
349aa0a1e58SJeff Roberson };
350aa0a1e58SJeff Roberson 
351aa0a1e58SJeff Roberson static inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
352aa0a1e58SJeff Roberson {
353aa0a1e58SJeff Roberson 	switch (mtu) {
354aa0a1e58SJeff Roberson 	case IB_MTU_256:  return  256;
355aa0a1e58SJeff Roberson 	case IB_MTU_512:  return  512;
356aa0a1e58SJeff Roberson 	case IB_MTU_1024: return 1024;
357aa0a1e58SJeff Roberson 	case IB_MTU_2048: return 2048;
358aa0a1e58SJeff Roberson 	case IB_MTU_4096: return 4096;
359aa0a1e58SJeff Roberson 	default: 	  return -1;
360aa0a1e58SJeff Roberson 	}
361aa0a1e58SJeff Roberson }
362aa0a1e58SJeff Roberson 
363aa0a1e58SJeff Roberson enum ib_port_state {
364aa0a1e58SJeff Roberson 	IB_PORT_NOP		= 0,
365aa0a1e58SJeff Roberson 	IB_PORT_DOWN		= 1,
366aa0a1e58SJeff Roberson 	IB_PORT_INIT		= 2,
367aa0a1e58SJeff Roberson 	IB_PORT_ARMED		= 3,
368aa0a1e58SJeff Roberson 	IB_PORT_ACTIVE		= 4,
369b5c1e0cbSHans Petter Selasky 	IB_PORT_ACTIVE_DEFER	= 5,
370478d3005SHans Petter Selasky 	IB_PORT_DUMMY		= -1,	/* force enum signed */
371aa0a1e58SJeff Roberson };
372aa0a1e58SJeff Roberson 
373aa0a1e58SJeff Roberson enum ib_port_cap_flags {
374aa0a1e58SJeff Roberson 	IB_PORT_SM				= 1 <<  1,
375aa0a1e58SJeff Roberson 	IB_PORT_NOTICE_SUP			= 1 <<  2,
376aa0a1e58SJeff Roberson 	IB_PORT_TRAP_SUP			= 1 <<  3,
377aa0a1e58SJeff Roberson 	IB_PORT_OPT_IPD_SUP                     = 1 <<  4,
378aa0a1e58SJeff Roberson 	IB_PORT_AUTO_MIGR_SUP			= 1 <<  5,
379aa0a1e58SJeff Roberson 	IB_PORT_SL_MAP_SUP			= 1 <<  6,
380aa0a1e58SJeff Roberson 	IB_PORT_MKEY_NVRAM			= 1 <<  7,
381aa0a1e58SJeff Roberson 	IB_PORT_PKEY_NVRAM			= 1 <<  8,
382aa0a1e58SJeff Roberson 	IB_PORT_LED_INFO_SUP			= 1 <<  9,
383aa0a1e58SJeff Roberson 	IB_PORT_SM_DISABLED			= 1 << 10,
384aa0a1e58SJeff Roberson 	IB_PORT_SYS_IMAGE_GUID_SUP		= 1 << 11,
385aa0a1e58SJeff Roberson 	IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP	= 1 << 12,
386c9f432b7SAlfred Perlstein 	IB_PORT_EXTENDED_SPEEDS_SUP             = 1 << 14,
387aa0a1e58SJeff Roberson 	IB_PORT_CM_SUP				= 1 << 16,
388aa0a1e58SJeff Roberson 	IB_PORT_SNMP_TUNNEL_SUP			= 1 << 17,
389aa0a1e58SJeff Roberson 	IB_PORT_REINIT_SUP			= 1 << 18,
390aa0a1e58SJeff Roberson 	IB_PORT_DEVICE_MGMT_SUP			= 1 << 19,
391aa0a1e58SJeff Roberson 	IB_PORT_VENDOR_CLASS_SUP		= 1 << 20,
392aa0a1e58SJeff Roberson 	IB_PORT_DR_NOTICE_SUP			= 1 << 21,
393aa0a1e58SJeff Roberson 	IB_PORT_CAP_MASK_NOTICE_SUP		= 1 << 22,
394aa0a1e58SJeff Roberson 	IB_PORT_BOOT_MGMT_SUP			= 1 << 23,
395aa0a1e58SJeff Roberson 	IB_PORT_LINK_LATENCY_SUP		= 1 << 24,
396478d3005SHans Petter Selasky 	IB_PORT_CLIENT_REG_SUP			= 1 << 25,
397478d3005SHans Petter Selasky 	IB_PORT_IP_BASED_GIDS			= 1 << 26,
398aa0a1e58SJeff Roberson };
399aa0a1e58SJeff Roberson 
4004238b4a7SHans Petter Selasky enum ib_port_phys_state {
4014238b4a7SHans Petter Selasky 	IB_PORT_PHYS_STATE_SLEEP = 1,
4024238b4a7SHans Petter Selasky 	IB_PORT_PHYS_STATE_POLLING = 2,
4034238b4a7SHans Petter Selasky 	IB_PORT_PHYS_STATE_DISABLED = 3,
4044238b4a7SHans Petter Selasky 	IB_PORT_PHYS_STATE_PORT_CONFIGURATION_TRAINING = 4,
4054238b4a7SHans Petter Selasky 	IB_PORT_PHYS_STATE_LINK_UP = 5,
4064238b4a7SHans Petter Selasky 	IB_PORT_PHYS_STATE_LINK_ERROR_RECOVERY = 6,
4074238b4a7SHans Petter Selasky 	IB_PORT_PHYS_STATE_PHY_TEST = 7,
4084238b4a7SHans Petter Selasky };
4094238b4a7SHans Petter Selasky 
410aa0a1e58SJeff Roberson enum ib_port_width {
411aa0a1e58SJeff Roberson 	IB_WIDTH_1X	= 1,
412013f1e14SHans Petter Selasky 	IB_WIDTH_2X	= 16,
413aa0a1e58SJeff Roberson 	IB_WIDTH_4X	= 2,
414aa0a1e58SJeff Roberson 	IB_WIDTH_8X	= 4,
415aa0a1e58SJeff Roberson 	IB_WIDTH_12X	= 8
416aa0a1e58SJeff Roberson };
417aa0a1e58SJeff Roberson 
418aa0a1e58SJeff Roberson static inline int ib_width_enum_to_int(enum ib_port_width width)
419aa0a1e58SJeff Roberson {
420aa0a1e58SJeff Roberson 	switch (width) {
421aa0a1e58SJeff Roberson 	case IB_WIDTH_1X:  return  1;
422013f1e14SHans Petter Selasky 	case IB_WIDTH_2X:  return  2;
423aa0a1e58SJeff Roberson 	case IB_WIDTH_4X:  return  4;
424aa0a1e58SJeff Roberson 	case IB_WIDTH_8X:  return  8;
425aa0a1e58SJeff Roberson 	case IB_WIDTH_12X: return 12;
426aa0a1e58SJeff Roberson 	default: 	  return -1;
427aa0a1e58SJeff Roberson 	}
428aa0a1e58SJeff Roberson }
429aa0a1e58SJeff Roberson 
430c9f432b7SAlfred Perlstein enum ib_port_speed {
431c9f432b7SAlfred Perlstein 	IB_SPEED_SDR	= 1,
432c9f432b7SAlfred Perlstein 	IB_SPEED_DDR	= 2,
433c9f432b7SAlfred Perlstein 	IB_SPEED_QDR	= 4,
434c9f432b7SAlfred Perlstein 	IB_SPEED_FDR10	= 8,
435c9f432b7SAlfred Perlstein 	IB_SPEED_FDR	= 16,
436d0a82c24SHans Petter Selasky 	IB_SPEED_EDR	= 32,
437d0a82c24SHans Petter Selasky 	IB_SPEED_HDR	= 64
438c9f432b7SAlfred Perlstein };
439c9f432b7SAlfred Perlstein 
440478d3005SHans Petter Selasky /**
441478d3005SHans Petter Selasky  * struct rdma_hw_stats
442912e98ceSHans Petter Selasky  * @lock - Mutex to protect parallel write access to lifespan and values
443912e98ceSHans Petter Selasky  *    of counters, which are 64bits and not guaranteeed to be written
444912e98ceSHans Petter Selasky  *    atomicaly on 32bits systems.
445478d3005SHans Petter Selasky  * @timestamp - Used by the core code to track when the last update was
446478d3005SHans Petter Selasky  * @lifespan - Used by the core code to determine how old the counters
447478d3005SHans Petter Selasky  *   should be before being updated again.  Stored in jiffies, defaults
448478d3005SHans Petter Selasky  *   to 10 milliseconds, drivers can override the default be specifying
449478d3005SHans Petter Selasky  *   their own value during their allocation routine.
450478d3005SHans Petter Selasky  * @name - Array of pointers to static names used for the counters in
451478d3005SHans Petter Selasky  *   directory.
452478d3005SHans Petter Selasky  * @num_counters - How many hardware counters there are.  If name is
453478d3005SHans Petter Selasky  *   shorter than this number, a kernel oops will result.  Driver authors
454478d3005SHans Petter Selasky  *   are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters)
455478d3005SHans Petter Selasky  *   in their code to prevent this.
456478d3005SHans Petter Selasky  * @value - Array of u64 counters that are accessed by the sysfs code and
457478d3005SHans Petter Selasky  *   filled in by the drivers get_stats routine
458478d3005SHans Petter Selasky  */
459478d3005SHans Petter Selasky struct rdma_hw_stats {
460912e98ceSHans Petter Selasky 	struct mutex	lock; /* Protect lifespan and values[] */
461478d3005SHans Petter Selasky 	unsigned long	timestamp;
462478d3005SHans Petter Selasky 	unsigned long	lifespan;
463478d3005SHans Petter Selasky 	const char * const *names;
464478d3005SHans Petter Selasky 	int		num_counters;
465478d3005SHans Petter Selasky 	u64		value[];
466aa0a1e58SJeff Roberson };
467aa0a1e58SJeff Roberson 
468478d3005SHans Petter Selasky #define RDMA_HW_STATS_DEFAULT_LIFESPAN 10
469478d3005SHans Petter Selasky /**
470478d3005SHans Petter Selasky  * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct
471478d3005SHans Petter Selasky  *   for drivers.
472478d3005SHans Petter Selasky  * @names - Array of static const char *
473478d3005SHans Petter Selasky  * @num_counters - How many elements in array
474478d3005SHans Petter Selasky  * @lifespan - How many milliseconds between updates
475478d3005SHans Petter Selasky  */
476478d3005SHans Petter Selasky static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct(
477478d3005SHans Petter Selasky 		const char * const *names, int num_counters,
478478d3005SHans Petter Selasky 		unsigned long lifespan)
479478d3005SHans Petter Selasky {
480478d3005SHans Petter Selasky 	struct rdma_hw_stats *stats;
481aa0a1e58SJeff Roberson 
482478d3005SHans Petter Selasky 	stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64),
483478d3005SHans Petter Selasky 			GFP_KERNEL);
484478d3005SHans Petter Selasky 	if (!stats)
485478d3005SHans Petter Selasky 		return NULL;
486478d3005SHans Petter Selasky 	stats->names = names;
487478d3005SHans Petter Selasky 	stats->num_counters = num_counters;
488478d3005SHans Petter Selasky 	stats->lifespan = msecs_to_jiffies(lifespan);
489aa0a1e58SJeff Roberson 
490478d3005SHans Petter Selasky 	return stats;
491478d3005SHans Petter Selasky }
492478d3005SHans Petter Selasky 
493478d3005SHans Petter Selasky 
494478d3005SHans Petter Selasky /* Define bits for the various functionality this port needs to be supported by
495478d3005SHans Petter Selasky  * the core.
496478d3005SHans Petter Selasky  */
497478d3005SHans Petter Selasky /* Management                           0x00000FFF */
498478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IB_MAD            0x00000001
499478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IB_SMI            0x00000002
500478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IB_CM             0x00000004
501478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IW_CM             0x00000008
502478d3005SHans Petter Selasky #define RDMA_CORE_CAP_IB_SA             0x00000010
503478d3005SHans Petter Selasky #define RDMA_CORE_CAP_OPA_MAD           0x00000020
504478d3005SHans Petter Selasky 
505478d3005SHans Petter Selasky /* Address format                       0x000FF000 */
506478d3005SHans Petter Selasky #define RDMA_CORE_CAP_AF_IB             0x00001000
507478d3005SHans Petter Selasky #define RDMA_CORE_CAP_ETH_AH            0x00002000
508478d3005SHans Petter Selasky 
509478d3005SHans Petter Selasky /* Protocol                             0xFFF00000 */
510478d3005SHans Petter Selasky #define RDMA_CORE_CAP_PROT_IB           0x00100000
511478d3005SHans Petter Selasky #define RDMA_CORE_CAP_PROT_ROCE         0x00200000
512478d3005SHans Petter Selasky #define RDMA_CORE_CAP_PROT_IWARP        0x00400000
513478d3005SHans Petter Selasky #define RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP 0x00800000
514478d3005SHans Petter Selasky 
515478d3005SHans Petter Selasky #define RDMA_CORE_PORT_IBA_IB          (RDMA_CORE_CAP_PROT_IB  \
516478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IB_MAD \
517478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IB_SMI \
518478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IB_CM  \
519478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IB_SA  \
520478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_AF_IB)
521478d3005SHans Petter Selasky #define RDMA_CORE_PORT_IBA_ROCE        (RDMA_CORE_CAP_PROT_ROCE \
522478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IB_MAD  \
523478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IB_CM   \
524478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_AF_IB   \
525478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_ETH_AH)
526478d3005SHans Petter Selasky #define RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP			\
527478d3005SHans Petter Selasky 					(RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP \
528478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IB_MAD  \
529478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IB_CM   \
530478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_AF_IB   \
531478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_ETH_AH)
532478d3005SHans Petter Selasky #define RDMA_CORE_PORT_IWARP           (RDMA_CORE_CAP_PROT_IWARP \
533478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_IW_CM)
534478d3005SHans Petter Selasky #define RDMA_CORE_PORT_INTEL_OPA       (RDMA_CORE_PORT_IBA_IB  \
535478d3005SHans Petter Selasky 					| RDMA_CORE_CAP_OPA_MAD)
536aa0a1e58SJeff Roberson 
537aa0a1e58SJeff Roberson struct ib_port_attr {
538478d3005SHans Petter Selasky 	u64			subnet_prefix;
539aa0a1e58SJeff Roberson 	enum ib_port_state	state;
540aa0a1e58SJeff Roberson 	enum ib_mtu		max_mtu;
541aa0a1e58SJeff Roberson 	enum ib_mtu		active_mtu;
542aa0a1e58SJeff Roberson 	int			gid_tbl_len;
543aa0a1e58SJeff Roberson 	u32			port_cap_flags;
544aa0a1e58SJeff Roberson 	u32			max_msg_sz;
545aa0a1e58SJeff Roberson 	u32			bad_pkey_cntr;
546aa0a1e58SJeff Roberson 	u32			qkey_viol_cntr;
547aa0a1e58SJeff Roberson 	u16			pkey_tbl_len;
548aa0a1e58SJeff Roberson 	u16			lid;
549aa0a1e58SJeff Roberson 	u16			sm_lid;
550aa0a1e58SJeff Roberson 	u8			lmc;
551aa0a1e58SJeff Roberson 	u8			max_vl_num;
552aa0a1e58SJeff Roberson 	u8			sm_sl;
553aa0a1e58SJeff Roberson 	u8			subnet_timeout;
554aa0a1e58SJeff Roberson 	u8			init_type_reply;
555aa0a1e58SJeff Roberson 	u8			active_width;
556aa0a1e58SJeff Roberson 	u8			active_speed;
557aa0a1e58SJeff Roberson 	u8                      phys_state;
558478d3005SHans Petter Selasky 	bool			grh_required;
559aa0a1e58SJeff Roberson };
560aa0a1e58SJeff Roberson 
561aa0a1e58SJeff Roberson enum ib_device_modify_flags {
562aa0a1e58SJeff Roberson 	IB_DEVICE_MODIFY_SYS_IMAGE_GUID	= 1 << 0,
563aa0a1e58SJeff Roberson 	IB_DEVICE_MODIFY_NODE_DESC	= 1 << 1
564aa0a1e58SJeff Roberson };
565aa0a1e58SJeff Roberson 
566478d3005SHans Petter Selasky #define IB_DEVICE_NODE_DESC_MAX 64
567478d3005SHans Petter Selasky 
568aa0a1e58SJeff Roberson struct ib_device_modify {
569aa0a1e58SJeff Roberson 	u64	sys_image_guid;
570478d3005SHans Petter Selasky 	char	node_desc[IB_DEVICE_NODE_DESC_MAX];
571aa0a1e58SJeff Roberson };
572aa0a1e58SJeff Roberson 
573aa0a1e58SJeff Roberson enum ib_port_modify_flags {
574aa0a1e58SJeff Roberson 	IB_PORT_SHUTDOWN		= 1,
575aa0a1e58SJeff Roberson 	IB_PORT_INIT_TYPE		= (1<<2),
576aa0a1e58SJeff Roberson 	IB_PORT_RESET_QKEY_CNTR		= (1<<3)
577aa0a1e58SJeff Roberson };
578aa0a1e58SJeff Roberson 
579aa0a1e58SJeff Roberson struct ib_port_modify {
580aa0a1e58SJeff Roberson 	u32	set_port_cap_mask;
581aa0a1e58SJeff Roberson 	u32	clr_port_cap_mask;
582aa0a1e58SJeff Roberson 	u8	init_type;
583aa0a1e58SJeff Roberson };
584aa0a1e58SJeff Roberson 
585aa0a1e58SJeff Roberson enum ib_event_type {
586aa0a1e58SJeff Roberson 	IB_EVENT_CQ_ERR,
587aa0a1e58SJeff Roberson 	IB_EVENT_QP_FATAL,
588aa0a1e58SJeff Roberson 	IB_EVENT_QP_REQ_ERR,
589aa0a1e58SJeff Roberson 	IB_EVENT_QP_ACCESS_ERR,
590aa0a1e58SJeff Roberson 	IB_EVENT_COMM_EST,
591aa0a1e58SJeff Roberson 	IB_EVENT_SQ_DRAINED,
592aa0a1e58SJeff Roberson 	IB_EVENT_PATH_MIG,
593aa0a1e58SJeff Roberson 	IB_EVENT_PATH_MIG_ERR,
594aa0a1e58SJeff Roberson 	IB_EVENT_DEVICE_FATAL,
595aa0a1e58SJeff Roberson 	IB_EVENT_PORT_ACTIVE,
596aa0a1e58SJeff Roberson 	IB_EVENT_PORT_ERR,
597aa0a1e58SJeff Roberson 	IB_EVENT_LID_CHANGE,
598aa0a1e58SJeff Roberson 	IB_EVENT_PKEY_CHANGE,
599aa0a1e58SJeff Roberson 	IB_EVENT_SM_CHANGE,
600aa0a1e58SJeff Roberson 	IB_EVENT_SRQ_ERR,
601aa0a1e58SJeff Roberson 	IB_EVENT_SRQ_LIMIT_REACHED,
602aa0a1e58SJeff Roberson 	IB_EVENT_QP_LAST_WQE_REACHED,
603aa0a1e58SJeff Roberson 	IB_EVENT_CLIENT_REREGISTER,
604aa0a1e58SJeff Roberson 	IB_EVENT_GID_CHANGE,
605478d3005SHans Petter Selasky 	IB_EVENT_WQ_FATAL,
606aa0a1e58SJeff Roberson };
607aa0a1e58SJeff Roberson 
608478d3005SHans Petter Selasky const char *__attribute_const__ ib_event_msg(enum ib_event_type event);
609478d3005SHans Petter Selasky 
610aa0a1e58SJeff Roberson struct ib_event {
611aa0a1e58SJeff Roberson 	struct ib_device	*device;
612aa0a1e58SJeff Roberson 	union {
613aa0a1e58SJeff Roberson 		struct ib_cq	*cq;
614aa0a1e58SJeff Roberson 		struct ib_qp	*qp;
615aa0a1e58SJeff Roberson 		struct ib_srq	*srq;
616478d3005SHans Petter Selasky 		struct ib_wq	*wq;
617aa0a1e58SJeff Roberson 		u8		port_num;
618aa0a1e58SJeff Roberson 	} element;
619aa0a1e58SJeff Roberson 	enum ib_event_type	event;
620aa0a1e58SJeff Roberson };
621aa0a1e58SJeff Roberson 
622aa0a1e58SJeff Roberson struct ib_event_handler {
623aa0a1e58SJeff Roberson 	struct ib_device *device;
624aa0a1e58SJeff Roberson 	void            (*handler)(struct ib_event_handler *, struct ib_event *);
625aa0a1e58SJeff Roberson 	struct list_head  list;
626aa0a1e58SJeff Roberson };
627aa0a1e58SJeff Roberson 
628aa0a1e58SJeff Roberson #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler)		\
629aa0a1e58SJeff Roberson 	do {							\
630aa0a1e58SJeff Roberson 		(_ptr)->device  = _device;			\
631aa0a1e58SJeff Roberson 		(_ptr)->handler = _handler;			\
632aa0a1e58SJeff Roberson 		INIT_LIST_HEAD(&(_ptr)->list);			\
633aa0a1e58SJeff Roberson 	} while (0)
634aa0a1e58SJeff Roberson 
635aa0a1e58SJeff Roberson struct ib_global_route {
636aa0a1e58SJeff Roberson 	union ib_gid	dgid;
637aa0a1e58SJeff Roberson 	u32		flow_label;
638aa0a1e58SJeff Roberson 	u8		sgid_index;
639aa0a1e58SJeff Roberson 	u8		hop_limit;
640aa0a1e58SJeff Roberson 	u8		traffic_class;
641aa0a1e58SJeff Roberson };
642aa0a1e58SJeff Roberson 
643aa0a1e58SJeff Roberson struct ib_grh {
644aa0a1e58SJeff Roberson 	__be32		version_tclass_flow;
645aa0a1e58SJeff Roberson 	__be16		paylen;
646aa0a1e58SJeff Roberson 	u8		next_hdr;
647aa0a1e58SJeff Roberson 	u8		hop_limit;
648aa0a1e58SJeff Roberson 	union ib_gid	sgid;
649aa0a1e58SJeff Roberson 	union ib_gid	dgid;
650aa0a1e58SJeff Roberson };
651aa0a1e58SJeff Roberson 
652478d3005SHans Petter Selasky union rdma_network_hdr {
653478d3005SHans Petter Selasky 	struct ib_grh ibgrh;
654478d3005SHans Petter Selasky 	struct {
655478d3005SHans Petter Selasky 		/* The IB spec states that if it's IPv4, the header
656478d3005SHans Petter Selasky 		 * is located in the last 20 bytes of the header.
657478d3005SHans Petter Selasky 		 */
658478d3005SHans Petter Selasky 		u8		reserved[20];
659478d3005SHans Petter Selasky 		struct ip	roce4grh;
660478d3005SHans Petter Selasky 	};
661478d3005SHans Petter Selasky };
662478d3005SHans Petter Selasky 
663aa0a1e58SJeff Roberson enum {
664aa0a1e58SJeff Roberson 	IB_MULTICAST_QPN = 0xffffff
665aa0a1e58SJeff Roberson };
666aa0a1e58SJeff Roberson 
667aa0a1e58SJeff Roberson #define IB_LID_PERMISSIVE	cpu_to_be16(0xFFFF)
668478d3005SHans Petter Selasky #define IB_MULTICAST_LID_BASE	cpu_to_be16(0xC000)
669aa0a1e58SJeff Roberson 
670aa0a1e58SJeff Roberson enum ib_ah_flags {
671aa0a1e58SJeff Roberson 	IB_AH_GRH	= 1
672aa0a1e58SJeff Roberson };
673aa0a1e58SJeff Roberson 
674aa0a1e58SJeff Roberson enum ib_rate {
675aa0a1e58SJeff Roberson 	IB_RATE_PORT_CURRENT = 0,
676aa0a1e58SJeff Roberson 	IB_RATE_2_5_GBPS = 2,
677aa0a1e58SJeff Roberson 	IB_RATE_5_GBPS   = 5,
678aa0a1e58SJeff Roberson 	IB_RATE_10_GBPS  = 3,
679aa0a1e58SJeff Roberson 	IB_RATE_20_GBPS  = 6,
680aa0a1e58SJeff Roberson 	IB_RATE_30_GBPS  = 4,
681aa0a1e58SJeff Roberson 	IB_RATE_40_GBPS  = 7,
682aa0a1e58SJeff Roberson 	IB_RATE_60_GBPS  = 8,
683aa0a1e58SJeff Roberson 	IB_RATE_80_GBPS  = 9,
684c9f432b7SAlfred Perlstein 	IB_RATE_120_GBPS = 10,
685c9f432b7SAlfred Perlstein 	IB_RATE_14_GBPS  = 11,
686c9f432b7SAlfred Perlstein 	IB_RATE_56_GBPS  = 12,
687c9f432b7SAlfred Perlstein 	IB_RATE_112_GBPS = 13,
688c9f432b7SAlfred Perlstein 	IB_RATE_168_GBPS = 14,
689c9f432b7SAlfred Perlstein 	IB_RATE_25_GBPS  = 15,
690c9f432b7SAlfred Perlstein 	IB_RATE_100_GBPS = 16,
691c9f432b7SAlfred Perlstein 	IB_RATE_200_GBPS = 17,
692013f1e14SHans Petter Selasky 	IB_RATE_300_GBPS = 18,
693013f1e14SHans Petter Selasky 	IB_RATE_28_GBPS  = 19,
694013f1e14SHans Petter Selasky 	IB_RATE_50_GBPS  = 20,
695013f1e14SHans Petter Selasky 	IB_RATE_400_GBPS = 21,
696013f1e14SHans Petter Selasky 	IB_RATE_600_GBPS = 22,
697aa0a1e58SJeff Roberson };
698aa0a1e58SJeff Roberson 
699aa0a1e58SJeff Roberson /**
700aa0a1e58SJeff Roberson  * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
701aa0a1e58SJeff Roberson  * base rate of 2.5 Gbit/sec.  For example, IB_RATE_5_GBPS will be
702aa0a1e58SJeff Roberson  * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
703aa0a1e58SJeff Roberson  * @rate: rate to convert.
704aa0a1e58SJeff Roberson  */
705478d3005SHans Petter Selasky __attribute_const__ int ib_rate_to_mult(enum ib_rate rate);
706aa0a1e58SJeff Roberson 
707aa0a1e58SJeff Roberson /**
708c9f432b7SAlfred Perlstein  * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
709c9f432b7SAlfred Perlstein  * For example, IB_RATE_2_5_GBPS will be converted to 2500.
710c9f432b7SAlfred Perlstein  * @rate: rate to convert.
711c9f432b7SAlfred Perlstein  */
712478d3005SHans Petter Selasky __attribute_const__ int ib_rate_to_mbps(enum ib_rate rate);
713c9f432b7SAlfred Perlstein 
714b5c1e0cbSHans Petter Selasky 
715478d3005SHans Petter Selasky /**
716478d3005SHans Petter Selasky  * enum ib_mr_type - memory region type
717478d3005SHans Petter Selasky  * @IB_MR_TYPE_MEM_REG:       memory region that is used for
718478d3005SHans Petter Selasky  *                            normal registration
719478d3005SHans Petter Selasky  * @IB_MR_TYPE_SIGNATURE:     memory region that is used for
720478d3005SHans Petter Selasky  *                            signature operations (data-integrity
721478d3005SHans Petter Selasky  *                            capable regions)
722478d3005SHans Petter Selasky  * @IB_MR_TYPE_SG_GAPS:       memory region that is capable to
723478d3005SHans Petter Selasky  *                            register any arbitrary sg lists (without
724478d3005SHans Petter Selasky  *                            the normal mr constraints - see
725478d3005SHans Petter Selasky  *                            ib_map_mr_sg)
726478d3005SHans Petter Selasky  */
727478d3005SHans Petter Selasky enum ib_mr_type {
728478d3005SHans Petter Selasky 	IB_MR_TYPE_MEM_REG,
729478d3005SHans Petter Selasky 	IB_MR_TYPE_SIGNATURE,
730478d3005SHans Petter Selasky 	IB_MR_TYPE_SG_GAPS,
731b5c1e0cbSHans Petter Selasky };
732b5c1e0cbSHans Petter Selasky 
733b5c1e0cbSHans Petter Selasky /**
734478d3005SHans Petter Selasky  * Signature types
735478d3005SHans Petter Selasky  * IB_SIG_TYPE_NONE: Unprotected.
736478d3005SHans Petter Selasky  * IB_SIG_TYPE_T10_DIF: Type T10-DIF
737b5c1e0cbSHans Petter Selasky  */
738478d3005SHans Petter Selasky enum ib_signature_type {
739478d3005SHans Petter Selasky 	IB_SIG_TYPE_NONE,
740478d3005SHans Petter Selasky 	IB_SIG_TYPE_T10_DIF,
741b5c1e0cbSHans Petter Selasky };
742b5c1e0cbSHans Petter Selasky 
743b5c1e0cbSHans Petter Selasky /**
744b5c1e0cbSHans Petter Selasky  * Signature T10-DIF block-guard types
745b5c1e0cbSHans Petter Selasky  * IB_T10DIF_CRC: Corresponds to T10-PI mandated CRC checksum rules.
746b5c1e0cbSHans Petter Selasky  * IB_T10DIF_CSUM: Corresponds to IP checksum rules.
747b5c1e0cbSHans Petter Selasky  */
748b5c1e0cbSHans Petter Selasky enum ib_t10_dif_bg_type {
749b5c1e0cbSHans Petter Selasky 	IB_T10DIF_CRC,
750b5c1e0cbSHans Petter Selasky 	IB_T10DIF_CSUM
751b5c1e0cbSHans Petter Selasky };
752b5c1e0cbSHans Petter Selasky 
753b5c1e0cbSHans Petter Selasky /**
754b5c1e0cbSHans Petter Selasky  * struct ib_t10_dif_domain - Parameters specific for T10-DIF
755b5c1e0cbSHans Petter Selasky  *     domain.
756b5c1e0cbSHans Petter Selasky  * @bg_type: T10-DIF block guard type (CRC|CSUM)
757b5c1e0cbSHans Petter Selasky  * @pi_interval: protection information interval.
758b5c1e0cbSHans Petter Selasky  * @bg: seed of guard computation.
759b5c1e0cbSHans Petter Selasky  * @app_tag: application tag of guard block
760b5c1e0cbSHans Petter Selasky  * @ref_tag: initial guard block reference tag.
761478d3005SHans Petter Selasky  * @ref_remap: Indicate wethear the reftag increments each block
762478d3005SHans Petter Selasky  * @app_escape: Indicate to skip block check if apptag=0xffff
763478d3005SHans Petter Selasky  * @ref_escape: Indicate to skip block check if reftag=0xffffffff
764478d3005SHans Petter Selasky  * @apptag_check_mask: check bitmask of application tag.
765b5c1e0cbSHans Petter Selasky  */
766b5c1e0cbSHans Petter Selasky struct ib_t10_dif_domain {
767b5c1e0cbSHans Petter Selasky 	enum ib_t10_dif_bg_type bg_type;
768478d3005SHans Petter Selasky 	u16			pi_interval;
769b5c1e0cbSHans Petter Selasky 	u16			bg;
770b5c1e0cbSHans Petter Selasky 	u16			app_tag;
771b5c1e0cbSHans Petter Selasky 	u32			ref_tag;
772478d3005SHans Petter Selasky 	bool			ref_remap;
773478d3005SHans Petter Selasky 	bool			app_escape;
774478d3005SHans Petter Selasky 	bool			ref_escape;
775478d3005SHans Petter Selasky 	u16			apptag_check_mask;
776b5c1e0cbSHans Petter Selasky };
777b5c1e0cbSHans Petter Selasky 
778b5c1e0cbSHans Petter Selasky /**
779b5c1e0cbSHans Petter Selasky  * struct ib_sig_domain - Parameters for signature domain
780b5c1e0cbSHans Petter Selasky  * @sig_type: specific signauture type
781b5c1e0cbSHans Petter Selasky  * @sig: union of all signature domain attributes that may
782b5c1e0cbSHans Petter Selasky  *     be used to set domain layout.
783b5c1e0cbSHans Petter Selasky  */
784b5c1e0cbSHans Petter Selasky struct ib_sig_domain {
785b5c1e0cbSHans Petter Selasky 	enum ib_signature_type sig_type;
786b5c1e0cbSHans Petter Selasky 	union {
787b5c1e0cbSHans Petter Selasky 		struct ib_t10_dif_domain dif;
788b5c1e0cbSHans Petter Selasky 	} sig;
789b5c1e0cbSHans Petter Selasky };
790b5c1e0cbSHans Petter Selasky 
791b5c1e0cbSHans Petter Selasky /**
792b5c1e0cbSHans Petter Selasky  * struct ib_sig_attrs - Parameters for signature handover operation
793b5c1e0cbSHans Petter Selasky  * @check_mask: bitmask for signature byte check (8 bytes)
794b5c1e0cbSHans Petter Selasky  * @mem: memory domain layout desciptor.
795b5c1e0cbSHans Petter Selasky  * @wire: wire domain layout desciptor.
796b5c1e0cbSHans Petter Selasky  */
797b5c1e0cbSHans Petter Selasky struct ib_sig_attrs {
798b5c1e0cbSHans Petter Selasky 	u8			check_mask;
799b5c1e0cbSHans Petter Selasky 	struct ib_sig_domain	mem;
800b5c1e0cbSHans Petter Selasky 	struct ib_sig_domain	wire;
801b5c1e0cbSHans Petter Selasky };
802b5c1e0cbSHans Petter Selasky 
803b5c1e0cbSHans Petter Selasky enum ib_sig_err_type {
804b5c1e0cbSHans Petter Selasky 	IB_SIG_BAD_GUARD,
805b5c1e0cbSHans Petter Selasky 	IB_SIG_BAD_REFTAG,
806b5c1e0cbSHans Petter Selasky 	IB_SIG_BAD_APPTAG,
807b5c1e0cbSHans Petter Selasky };
808b5c1e0cbSHans Petter Selasky 
809b5c1e0cbSHans Petter Selasky /**
810b5c1e0cbSHans Petter Selasky  * struct ib_sig_err - signature error descriptor
811b5c1e0cbSHans Petter Selasky  */
812b5c1e0cbSHans Petter Selasky struct ib_sig_err {
813b5c1e0cbSHans Petter Selasky 	enum ib_sig_err_type	err_type;
814b5c1e0cbSHans Petter Selasky 	u32			expected;
815b5c1e0cbSHans Petter Selasky 	u32			actual;
816b5c1e0cbSHans Petter Selasky 	u64			sig_err_offset;
817b5c1e0cbSHans Petter Selasky 	u32			key;
818b5c1e0cbSHans Petter Selasky };
819b5c1e0cbSHans Petter Selasky 
820b5c1e0cbSHans Petter Selasky enum ib_mr_status_check {
821b5c1e0cbSHans Petter Selasky 	IB_MR_CHECK_SIG_STATUS = 1,
822b5c1e0cbSHans Petter Selasky };
823b5c1e0cbSHans Petter Selasky 
824b5c1e0cbSHans Petter Selasky /**
825b5c1e0cbSHans Petter Selasky  * struct ib_mr_status - Memory region status container
826b5c1e0cbSHans Petter Selasky  *
827b5c1e0cbSHans Petter Selasky  * @fail_status: Bitmask of MR checks status. For each
828b5c1e0cbSHans Petter Selasky  *     failed check a corresponding status bit is set.
829b5c1e0cbSHans Petter Selasky  * @sig_err: Additional info for IB_MR_CEHCK_SIG_STATUS
830b5c1e0cbSHans Petter Selasky  *     failure.
831b5c1e0cbSHans Petter Selasky  */
832b5c1e0cbSHans Petter Selasky struct ib_mr_status {
833b5c1e0cbSHans Petter Selasky 	u32		    fail_status;
834b5c1e0cbSHans Petter Selasky 	struct ib_sig_err   sig_err;
835b5c1e0cbSHans Petter Selasky };
836b5c1e0cbSHans Petter Selasky 
837c9f432b7SAlfred Perlstein /**
838aa0a1e58SJeff Roberson  * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
839aa0a1e58SJeff Roberson  * enum.
840aa0a1e58SJeff Roberson  * @mult: multiple to convert.
841aa0a1e58SJeff Roberson  */
842478d3005SHans Petter Selasky __attribute_const__ enum ib_rate mult_to_ib_rate(int mult);
843aa0a1e58SJeff Roberson 
844aa0a1e58SJeff Roberson struct ib_ah_attr {
845aa0a1e58SJeff Roberson 	struct ib_global_route	grh;
846aa0a1e58SJeff Roberson 	u16			dlid;
847aa0a1e58SJeff Roberson 	u8			sl;
848aa0a1e58SJeff Roberson 	u8			src_path_bits;
849aa0a1e58SJeff Roberson 	u8			static_rate;
850aa0a1e58SJeff Roberson 	u8			ah_flags;
851aa0a1e58SJeff Roberson 	u8			port_num;
852478d3005SHans Petter Selasky 	u8			dmac[ETH_ALEN];
853aa0a1e58SJeff Roberson };
854aa0a1e58SJeff Roberson 
855aa0a1e58SJeff Roberson enum ib_wc_status {
856aa0a1e58SJeff Roberson 	IB_WC_SUCCESS,
857aa0a1e58SJeff Roberson 	IB_WC_LOC_LEN_ERR,
858aa0a1e58SJeff Roberson 	IB_WC_LOC_QP_OP_ERR,
859aa0a1e58SJeff Roberson 	IB_WC_LOC_EEC_OP_ERR,
860aa0a1e58SJeff Roberson 	IB_WC_LOC_PROT_ERR,
861aa0a1e58SJeff Roberson 	IB_WC_WR_FLUSH_ERR,
862aa0a1e58SJeff Roberson 	IB_WC_MW_BIND_ERR,
863aa0a1e58SJeff Roberson 	IB_WC_BAD_RESP_ERR,
864aa0a1e58SJeff Roberson 	IB_WC_LOC_ACCESS_ERR,
865aa0a1e58SJeff Roberson 	IB_WC_REM_INV_REQ_ERR,
866aa0a1e58SJeff Roberson 	IB_WC_REM_ACCESS_ERR,
867aa0a1e58SJeff Roberson 	IB_WC_REM_OP_ERR,
868aa0a1e58SJeff Roberson 	IB_WC_RETRY_EXC_ERR,
869aa0a1e58SJeff Roberson 	IB_WC_RNR_RETRY_EXC_ERR,
870aa0a1e58SJeff Roberson 	IB_WC_LOC_RDD_VIOL_ERR,
871aa0a1e58SJeff Roberson 	IB_WC_REM_INV_RD_REQ_ERR,
872aa0a1e58SJeff Roberson 	IB_WC_REM_ABORT_ERR,
873aa0a1e58SJeff Roberson 	IB_WC_INV_EECN_ERR,
874aa0a1e58SJeff Roberson 	IB_WC_INV_EEC_STATE_ERR,
875aa0a1e58SJeff Roberson 	IB_WC_FATAL_ERR,
876aa0a1e58SJeff Roberson 	IB_WC_RESP_TIMEOUT_ERR,
877aa0a1e58SJeff Roberson 	IB_WC_GENERAL_ERR
878aa0a1e58SJeff Roberson };
879aa0a1e58SJeff Roberson 
880478d3005SHans Petter Selasky const char *__attribute_const__ ib_wc_status_msg(enum ib_wc_status status);
881478d3005SHans Petter Selasky 
882aa0a1e58SJeff Roberson enum ib_wc_opcode {
883aa0a1e58SJeff Roberson 	IB_WC_SEND,
884aa0a1e58SJeff Roberson 	IB_WC_RDMA_WRITE,
885aa0a1e58SJeff Roberson 	IB_WC_RDMA_READ,
886aa0a1e58SJeff Roberson 	IB_WC_COMP_SWAP,
887aa0a1e58SJeff Roberson 	IB_WC_FETCH_ADD,
888aa0a1e58SJeff Roberson 	IB_WC_LSO,
889aa0a1e58SJeff Roberson 	IB_WC_LOCAL_INV,
890478d3005SHans Petter Selasky 	IB_WC_REG_MR,
891aa0a1e58SJeff Roberson 	IB_WC_MASKED_COMP_SWAP,
892aa0a1e58SJeff Roberson 	IB_WC_MASKED_FETCH_ADD,
893aa0a1e58SJeff Roberson /*
894aa0a1e58SJeff Roberson  * Set value of IB_WC_RECV so consumers can test if a completion is a
895aa0a1e58SJeff Roberson  * receive by testing (opcode & IB_WC_RECV).
896aa0a1e58SJeff Roberson  */
897aa0a1e58SJeff Roberson 	IB_WC_RECV			= 1 << 7,
898478d3005SHans Petter Selasky 	IB_WC_RECV_RDMA_WITH_IMM,
899478d3005SHans Petter Selasky 	IB_WC_DUMMY = -1,	/* force enum signed */
900aa0a1e58SJeff Roberson };
901aa0a1e58SJeff Roberson 
902aa0a1e58SJeff Roberson enum ib_wc_flags {
903aa0a1e58SJeff Roberson 	IB_WC_GRH		= 1,
904aa0a1e58SJeff Roberson 	IB_WC_WITH_IMM		= (1<<1),
905aa0a1e58SJeff Roberson 	IB_WC_WITH_INVALIDATE	= (1<<2),
906c9f432b7SAlfred Perlstein 	IB_WC_IP_CSUM_OK	= (1<<3),
907478d3005SHans Petter Selasky 	IB_WC_WITH_SMAC		= (1<<4),
908478d3005SHans Petter Selasky 	IB_WC_WITH_VLAN		= (1<<5),
909478d3005SHans Petter Selasky 	IB_WC_WITH_NETWORK_HDR_TYPE	= (1<<6),
910aa0a1e58SJeff Roberson };
911aa0a1e58SJeff Roberson 
912aa0a1e58SJeff Roberson struct ib_wc {
913478d3005SHans Petter Selasky 	union {
914aa0a1e58SJeff Roberson 		u64		wr_id;
915478d3005SHans Petter Selasky 		struct ib_cqe	*wr_cqe;
916478d3005SHans Petter Selasky 	};
917aa0a1e58SJeff Roberson 	enum ib_wc_status	status;
918aa0a1e58SJeff Roberson 	enum ib_wc_opcode	opcode;
919aa0a1e58SJeff Roberson 	u32			vendor_err;
920aa0a1e58SJeff Roberson 	u32			byte_len;
921aa0a1e58SJeff Roberson 	struct ib_qp	       *qp;
922aa0a1e58SJeff Roberson 	union {
923aa0a1e58SJeff Roberson 		__be32		imm_data;
924aa0a1e58SJeff Roberson 		u32		invalidate_rkey;
925aa0a1e58SJeff Roberson 	} ex;
926aa0a1e58SJeff Roberson 	u32			src_qp;
927aa0a1e58SJeff Roberson 	int			wc_flags;
928aa0a1e58SJeff Roberson 	u16			pkey_index;
929aa0a1e58SJeff Roberson 	u16			slid;
930aa0a1e58SJeff Roberson 	u8			sl;
931aa0a1e58SJeff Roberson 	u8			dlid_path_bits;
932aa0a1e58SJeff Roberson 	u8			port_num;	/* valid only for DR SMPs on switches */
933478d3005SHans Petter Selasky 	u8			smac[ETH_ALEN];
934b5c1e0cbSHans Petter Selasky 	u16			vlan_id;
935478d3005SHans Petter Selasky 	u8			network_hdr_type;
936aa0a1e58SJeff Roberson };
937aa0a1e58SJeff Roberson 
938aa0a1e58SJeff Roberson enum ib_cq_notify_flags {
939aa0a1e58SJeff Roberson 	IB_CQ_SOLICITED			= 1 << 0,
940aa0a1e58SJeff Roberson 	IB_CQ_NEXT_COMP			= 1 << 1,
941aa0a1e58SJeff Roberson 	IB_CQ_SOLICITED_MASK		= IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
942aa0a1e58SJeff Roberson 	IB_CQ_REPORT_MISSED_EVENTS	= 1 << 2,
943aa0a1e58SJeff Roberson };
944aa0a1e58SJeff Roberson 
945c9f432b7SAlfred Perlstein enum ib_srq_type {
946c9f432b7SAlfred Perlstein 	IB_SRQT_BASIC,
947c9f432b7SAlfred Perlstein 	IB_SRQT_XRC
948c9f432b7SAlfred Perlstein };
949c9f432b7SAlfred Perlstein 
950aa0a1e58SJeff Roberson enum ib_srq_attr_mask {
951aa0a1e58SJeff Roberson 	IB_SRQ_MAX_WR	= 1 << 0,
952aa0a1e58SJeff Roberson 	IB_SRQ_LIMIT	= 1 << 1,
953aa0a1e58SJeff Roberson };
954aa0a1e58SJeff Roberson 
955aa0a1e58SJeff Roberson struct ib_srq_attr {
956aa0a1e58SJeff Roberson 	u32	max_wr;
957aa0a1e58SJeff Roberson 	u32	max_sge;
958aa0a1e58SJeff Roberson 	u32	srq_limit;
959aa0a1e58SJeff Roberson };
960aa0a1e58SJeff Roberson 
961aa0a1e58SJeff Roberson struct ib_srq_init_attr {
962aa0a1e58SJeff Roberson 	void		      (*event_handler)(struct ib_event *, void *);
963aa0a1e58SJeff Roberson 	void		       *srq_context;
964aa0a1e58SJeff Roberson 	struct ib_srq_attr	attr;
965c9f432b7SAlfred Perlstein 	enum ib_srq_type	srq_type;
966c9f432b7SAlfred Perlstein 
967c9f432b7SAlfred Perlstein 	union {
968c9f432b7SAlfred Perlstein 		struct {
969c9f432b7SAlfred Perlstein 			struct ib_xrcd *xrcd;
970c9f432b7SAlfred Perlstein 			struct ib_cq   *cq;
971c9f432b7SAlfred Perlstein 		} xrc;
972c9f432b7SAlfred Perlstein 	} ext;
973aa0a1e58SJeff Roberson };
974aa0a1e58SJeff Roberson 
975aa0a1e58SJeff Roberson struct ib_qp_cap {
976aa0a1e58SJeff Roberson 	u32	max_send_wr;
977aa0a1e58SJeff Roberson 	u32	max_recv_wr;
978aa0a1e58SJeff Roberson 	u32	max_send_sge;
979aa0a1e58SJeff Roberson 	u32	max_recv_sge;
980aa0a1e58SJeff Roberson 	u32	max_inline_data;
981478d3005SHans Petter Selasky 
982478d3005SHans Petter Selasky 	/*
983478d3005SHans Petter Selasky 	 * Maximum number of rdma_rw_ctx structures in flight at a time.
984478d3005SHans Petter Selasky 	 * ib_create_qp() will calculate the right amount of neededed WRs
985478d3005SHans Petter Selasky 	 * and MRs based on this.
986478d3005SHans Petter Selasky 	 */
987478d3005SHans Petter Selasky 	u32	max_rdma_ctxs;
988aa0a1e58SJeff Roberson };
989aa0a1e58SJeff Roberson 
990aa0a1e58SJeff Roberson enum ib_sig_type {
991aa0a1e58SJeff Roberson 	IB_SIGNAL_ALL_WR,
992aa0a1e58SJeff Roberson 	IB_SIGNAL_REQ_WR
993aa0a1e58SJeff Roberson };
994aa0a1e58SJeff Roberson 
995aa0a1e58SJeff Roberson enum ib_qp_type {
996aa0a1e58SJeff Roberson 	/*
997aa0a1e58SJeff Roberson 	 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
998aa0a1e58SJeff Roberson 	 * here (and in that order) since the MAD layer uses them as
999aa0a1e58SJeff Roberson 	 * indices into a 2-entry table.
1000aa0a1e58SJeff Roberson 	 */
1001aa0a1e58SJeff Roberson 	IB_QPT_SMI,
1002aa0a1e58SJeff Roberson 	IB_QPT_GSI,
1003aa0a1e58SJeff Roberson 
1004aa0a1e58SJeff Roberson 	IB_QPT_RC,
1005aa0a1e58SJeff Roberson 	IB_QPT_UC,
1006aa0a1e58SJeff Roberson 	IB_QPT_UD,
1007aa0a1e58SJeff Roberson 	IB_QPT_RAW_IPV6,
1008c9f432b7SAlfred Perlstein 	IB_QPT_RAW_ETHERTYPE,
1009c9f432b7SAlfred Perlstein 	IB_QPT_RAW_PACKET = 8,
1010c9f432b7SAlfred Perlstein 	IB_QPT_XRC_INI = 9,
1011c9f432b7SAlfred Perlstein 	IB_QPT_XRC_TGT,
1012c9f432b7SAlfred Perlstein 	IB_QPT_MAX,
1013b5c1e0cbSHans Petter Selasky 	/* Reserve a range for qp types internal to the low level driver.
1014b5c1e0cbSHans Petter Selasky 	 * These qp types will not be visible at the IB core layer, so the
1015b5c1e0cbSHans Petter Selasky 	 * IB_QPT_MAX usages should not be affected in the core layer
1016b5c1e0cbSHans Petter Selasky 	 */
1017b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED1 = 0x1000,
1018b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED2,
1019b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED3,
1020b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED4,
1021b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED5,
1022b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED6,
1023b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED7,
1024b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED8,
1025b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED9,
1026b5c1e0cbSHans Petter Selasky 	IB_QPT_RESERVED10,
1027aa0a1e58SJeff Roberson };
1028aa0a1e58SJeff Roberson 
1029aa0a1e58SJeff Roberson enum ib_qp_create_flags {
1030aa0a1e58SJeff Roberson 	IB_QP_CREATE_IPOIB_UD_LSO		= 1 << 0,
1031aa0a1e58SJeff Roberson 	IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK	= 1 << 1,
1032b5c1e0cbSHans Petter Selasky 	IB_QP_CREATE_CROSS_CHANNEL              = 1 << 2,
1033b5c1e0cbSHans Petter Selasky 	IB_QP_CREATE_MANAGED_SEND               = 1 << 3,
1034b5c1e0cbSHans Petter Selasky 	IB_QP_CREATE_MANAGED_RECV               = 1 << 4,
1035b5c1e0cbSHans Petter Selasky 	IB_QP_CREATE_NETIF_QP			= 1 << 5,
1036b5c1e0cbSHans Petter Selasky 	IB_QP_CREATE_SIGNATURE_EN		= 1 << 6,
1037478d3005SHans Petter Selasky 	IB_QP_CREATE_USE_GFP_NOIO		= 1 << 7,
1038478d3005SHans Petter Selasky 	IB_QP_CREATE_SCATTER_FCS		= 1 << 8,
1039c9f432b7SAlfred Perlstein 	/* reserve bits 26-31 for low level drivers' internal use */
1040c9f432b7SAlfred Perlstein 	IB_QP_CREATE_RESERVED_START		= 1 << 26,
1041c9f432b7SAlfred Perlstein 	IB_QP_CREATE_RESERVED_END		= 1 << 31,
1042c9f432b7SAlfred Perlstein };
1043c9f432b7SAlfred Perlstein 
1044478d3005SHans Petter Selasky /*
1045478d3005SHans Petter Selasky  * Note: users may not call ib_close_qp or ib_destroy_qp from the event_handler
1046478d3005SHans Petter Selasky  * callback to destroy the passed in QP.
1047478d3005SHans Petter Selasky  */
1048aa0a1e58SJeff Roberson 
1049aa0a1e58SJeff Roberson struct ib_qp_init_attr {
1050aa0a1e58SJeff Roberson 	void                  (*event_handler)(struct ib_event *, void *);
1051aa0a1e58SJeff Roberson 	void		       *qp_context;
1052aa0a1e58SJeff Roberson 	struct ib_cq	       *send_cq;
1053aa0a1e58SJeff Roberson 	struct ib_cq	       *recv_cq;
1054aa0a1e58SJeff Roberson 	struct ib_srq	       *srq;
1055c9f432b7SAlfred Perlstein 	struct ib_xrcd	       *xrcd;     /* XRC TGT QPs only */
1056aa0a1e58SJeff Roberson 	struct ib_qp_cap	cap;
1057aa0a1e58SJeff Roberson 	enum ib_sig_type	sq_sig_type;
1058aa0a1e58SJeff Roberson 	enum ib_qp_type		qp_type;
1059aa0a1e58SJeff Roberson 	enum ib_qp_create_flags	create_flags;
1060aa0a1e58SJeff Roberson 
1061478d3005SHans Petter Selasky 	/*
1062478d3005SHans Petter Selasky 	 * Only needed for special QP types, or when using the RW API.
1063478d3005SHans Petter Selasky 	 */
1064478d3005SHans Petter Selasky 	u8			port_num;
1065478d3005SHans Petter Selasky 	struct ib_rwq_ind_table *rwq_ind_tbl;
1066b5c1e0cbSHans Petter Selasky };
1067b5c1e0cbSHans Petter Selasky 
1068c9f432b7SAlfred Perlstein struct ib_qp_open_attr {
1069c9f432b7SAlfred Perlstein 	void                  (*event_handler)(struct ib_event *, void *);
1070c9f432b7SAlfred Perlstein 	void		       *qp_context;
1071c9f432b7SAlfred Perlstein 	u32			qp_num;
1072c9f432b7SAlfred Perlstein 	enum ib_qp_type		qp_type;
1073c9f432b7SAlfred Perlstein };
1074c9f432b7SAlfred Perlstein 
1075aa0a1e58SJeff Roberson enum ib_rnr_timeout {
1076aa0a1e58SJeff Roberson 	IB_RNR_TIMER_655_36 =  0,
1077aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_01 =  1,
1078aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_02 =  2,
1079aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_03 =  3,
1080aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_04 =  4,
1081aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_06 =  5,
1082aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_08 =  6,
1083aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_12 =  7,
1084aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_16 =  8,
1085aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_24 =  9,
1086aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_32 = 10,
1087aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_48 = 11,
1088aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_64 = 12,
1089aa0a1e58SJeff Roberson 	IB_RNR_TIMER_000_96 = 13,
1090aa0a1e58SJeff Roberson 	IB_RNR_TIMER_001_28 = 14,
1091aa0a1e58SJeff Roberson 	IB_RNR_TIMER_001_92 = 15,
1092aa0a1e58SJeff Roberson 	IB_RNR_TIMER_002_56 = 16,
1093aa0a1e58SJeff Roberson 	IB_RNR_TIMER_003_84 = 17,
1094aa0a1e58SJeff Roberson 	IB_RNR_TIMER_005_12 = 18,
1095aa0a1e58SJeff Roberson 	IB_RNR_TIMER_007_68 = 19,
1096aa0a1e58SJeff Roberson 	IB_RNR_TIMER_010_24 = 20,
1097aa0a1e58SJeff Roberson 	IB_RNR_TIMER_015_36 = 21,
1098aa0a1e58SJeff Roberson 	IB_RNR_TIMER_020_48 = 22,
1099aa0a1e58SJeff Roberson 	IB_RNR_TIMER_030_72 = 23,
1100aa0a1e58SJeff Roberson 	IB_RNR_TIMER_040_96 = 24,
1101aa0a1e58SJeff Roberson 	IB_RNR_TIMER_061_44 = 25,
1102aa0a1e58SJeff Roberson 	IB_RNR_TIMER_081_92 = 26,
1103aa0a1e58SJeff Roberson 	IB_RNR_TIMER_122_88 = 27,
1104aa0a1e58SJeff Roberson 	IB_RNR_TIMER_163_84 = 28,
1105aa0a1e58SJeff Roberson 	IB_RNR_TIMER_245_76 = 29,
1106aa0a1e58SJeff Roberson 	IB_RNR_TIMER_327_68 = 30,
1107aa0a1e58SJeff Roberson 	IB_RNR_TIMER_491_52 = 31
1108aa0a1e58SJeff Roberson };
1109aa0a1e58SJeff Roberson 
1110aa0a1e58SJeff Roberson enum ib_qp_attr_mask {
1111aa0a1e58SJeff Roberson 	IB_QP_STATE			= 1,
1112aa0a1e58SJeff Roberson 	IB_QP_CUR_STATE			= (1<<1),
1113aa0a1e58SJeff Roberson 	IB_QP_EN_SQD_ASYNC_NOTIFY	= (1<<2),
1114aa0a1e58SJeff Roberson 	IB_QP_ACCESS_FLAGS		= (1<<3),
1115aa0a1e58SJeff Roberson 	IB_QP_PKEY_INDEX		= (1<<4),
1116aa0a1e58SJeff Roberson 	IB_QP_PORT			= (1<<5),
1117aa0a1e58SJeff Roberson 	IB_QP_QKEY			= (1<<6),
1118aa0a1e58SJeff Roberson 	IB_QP_AV			= (1<<7),
1119aa0a1e58SJeff Roberson 	IB_QP_PATH_MTU			= (1<<8),
1120aa0a1e58SJeff Roberson 	IB_QP_TIMEOUT			= (1<<9),
1121aa0a1e58SJeff Roberson 	IB_QP_RETRY_CNT			= (1<<10),
1122aa0a1e58SJeff Roberson 	IB_QP_RNR_RETRY			= (1<<11),
1123aa0a1e58SJeff Roberson 	IB_QP_RQ_PSN			= (1<<12),
1124aa0a1e58SJeff Roberson 	IB_QP_MAX_QP_RD_ATOMIC		= (1<<13),
1125aa0a1e58SJeff Roberson 	IB_QP_ALT_PATH			= (1<<14),
1126aa0a1e58SJeff Roberson 	IB_QP_MIN_RNR_TIMER		= (1<<15),
1127aa0a1e58SJeff Roberson 	IB_QP_SQ_PSN			= (1<<16),
1128aa0a1e58SJeff Roberson 	IB_QP_MAX_DEST_RD_ATOMIC	= (1<<17),
1129aa0a1e58SJeff Roberson 	IB_QP_PATH_MIG_STATE		= (1<<18),
1130aa0a1e58SJeff Roberson 	IB_QP_CAP			= (1<<19),
1131c9f432b7SAlfred Perlstein 	IB_QP_DEST_QPN			= (1<<20),
1132478d3005SHans Petter Selasky 	IB_QP_RESERVED1			= (1<<21),
1133478d3005SHans Petter Selasky 	IB_QP_RESERVED2			= (1<<22),
1134478d3005SHans Petter Selasky 	IB_QP_RESERVED3			= (1<<23),
1135478d3005SHans Petter Selasky 	IB_QP_RESERVED4			= (1<<24),
11360c13880cSHans Petter Selasky 	IB_QP_RATE_LIMIT		= (1<<25),
1137aa0a1e58SJeff Roberson };
1138aa0a1e58SJeff Roberson 
1139aa0a1e58SJeff Roberson enum ib_qp_state {
1140aa0a1e58SJeff Roberson 	IB_QPS_RESET,
1141aa0a1e58SJeff Roberson 	IB_QPS_INIT,
1142aa0a1e58SJeff Roberson 	IB_QPS_RTR,
1143aa0a1e58SJeff Roberson 	IB_QPS_RTS,
1144aa0a1e58SJeff Roberson 	IB_QPS_SQD,
1145aa0a1e58SJeff Roberson 	IB_QPS_SQE,
1146b5c1e0cbSHans Petter Selasky 	IB_QPS_ERR,
1147478d3005SHans Petter Selasky 	IB_QPS_DUMMY = -1,	/* force enum signed */
1148aa0a1e58SJeff Roberson };
1149aa0a1e58SJeff Roberson 
1150aa0a1e58SJeff Roberson enum ib_mig_state {
1151aa0a1e58SJeff Roberson 	IB_MIG_MIGRATED,
1152aa0a1e58SJeff Roberson 	IB_MIG_REARM,
1153aa0a1e58SJeff Roberson 	IB_MIG_ARMED
1154aa0a1e58SJeff Roberson };
1155aa0a1e58SJeff Roberson 
1156b5c1e0cbSHans Petter Selasky enum ib_mw_type {
1157b5c1e0cbSHans Petter Selasky 	IB_MW_TYPE_1 = 1,
1158b5c1e0cbSHans Petter Selasky 	IB_MW_TYPE_2 = 2
1159b5c1e0cbSHans Petter Selasky };
1160b5c1e0cbSHans Petter Selasky 
1161aa0a1e58SJeff Roberson struct ib_qp_attr {
1162aa0a1e58SJeff Roberson 	enum ib_qp_state	qp_state;
1163aa0a1e58SJeff Roberson 	enum ib_qp_state	cur_qp_state;
1164aa0a1e58SJeff Roberson 	enum ib_mtu		path_mtu;
1165aa0a1e58SJeff Roberson 	enum ib_mig_state	path_mig_state;
1166aa0a1e58SJeff Roberson 	u32			qkey;
1167aa0a1e58SJeff Roberson 	u32			rq_psn;
1168aa0a1e58SJeff Roberson 	u32			sq_psn;
1169aa0a1e58SJeff Roberson 	u32			dest_qp_num;
1170aa0a1e58SJeff Roberson 	int			qp_access_flags;
1171aa0a1e58SJeff Roberson 	struct ib_qp_cap	cap;
1172aa0a1e58SJeff Roberson 	struct ib_ah_attr	ah_attr;
1173aa0a1e58SJeff Roberson 	struct ib_ah_attr	alt_ah_attr;
1174aa0a1e58SJeff Roberson 	u16			pkey_index;
1175aa0a1e58SJeff Roberson 	u16			alt_pkey_index;
1176aa0a1e58SJeff Roberson 	u8			en_sqd_async_notify;
1177aa0a1e58SJeff Roberson 	u8			sq_draining;
1178aa0a1e58SJeff Roberson 	u8			max_rd_atomic;
1179aa0a1e58SJeff Roberson 	u8			max_dest_rd_atomic;
1180aa0a1e58SJeff Roberson 	u8			min_rnr_timer;
1181aa0a1e58SJeff Roberson 	u8			port_num;
1182aa0a1e58SJeff Roberson 	u8			timeout;
1183aa0a1e58SJeff Roberson 	u8			retry_cnt;
1184aa0a1e58SJeff Roberson 	u8			rnr_retry;
1185aa0a1e58SJeff Roberson 	u8			alt_port_num;
1186aa0a1e58SJeff Roberson 	u8			alt_timeout;
11870c13880cSHans Petter Selasky 	u32			rate_limit;
1188aa0a1e58SJeff Roberson };
1189aa0a1e58SJeff Roberson 
1190aa0a1e58SJeff Roberson enum ib_wr_opcode {
1191aa0a1e58SJeff Roberson 	IB_WR_RDMA_WRITE,
1192aa0a1e58SJeff Roberson 	IB_WR_RDMA_WRITE_WITH_IMM,
1193aa0a1e58SJeff Roberson 	IB_WR_SEND,
1194aa0a1e58SJeff Roberson 	IB_WR_SEND_WITH_IMM,
1195aa0a1e58SJeff Roberson 	IB_WR_RDMA_READ,
1196aa0a1e58SJeff Roberson 	IB_WR_ATOMIC_CMP_AND_SWP,
1197aa0a1e58SJeff Roberson 	IB_WR_ATOMIC_FETCH_AND_ADD,
1198aa0a1e58SJeff Roberson 	IB_WR_LSO,
1199aa0a1e58SJeff Roberson 	IB_WR_SEND_WITH_INV,
1200aa0a1e58SJeff Roberson 	IB_WR_RDMA_READ_WITH_INV,
1201aa0a1e58SJeff Roberson 	IB_WR_LOCAL_INV,
1202478d3005SHans Petter Selasky 	IB_WR_REG_MR,
1203aa0a1e58SJeff Roberson 	IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
1204aa0a1e58SJeff Roberson 	IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
1205b5c1e0cbSHans Petter Selasky 	IB_WR_REG_SIG_MR,
1206b5c1e0cbSHans Petter Selasky 	/* reserve values for low level drivers' internal use.
1207b5c1e0cbSHans Petter Selasky 	 * These values will not be used at all in the ib core layer.
1208b5c1e0cbSHans Petter Selasky 	 */
1209b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED1 = 0xf0,
1210b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED2,
1211b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED3,
1212b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED4,
1213b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED5,
1214b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED6,
1215b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED7,
1216b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED8,
1217b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED9,
1218b5c1e0cbSHans Petter Selasky 	IB_WR_RESERVED10,
1219478d3005SHans Petter Selasky 	IB_WR_DUMMY = -1,	/* force enum signed */
1220aa0a1e58SJeff Roberson };
1221aa0a1e58SJeff Roberson 
1222aa0a1e58SJeff Roberson enum ib_send_flags {
1223aa0a1e58SJeff Roberson 	IB_SEND_FENCE		= 1,
1224aa0a1e58SJeff Roberson 	IB_SEND_SIGNALED	= (1<<1),
1225aa0a1e58SJeff Roberson 	IB_SEND_SOLICITED	= (1<<2),
1226aa0a1e58SJeff Roberson 	IB_SEND_INLINE		= (1<<3),
1227b5c1e0cbSHans Petter Selasky 	IB_SEND_IP_CSUM		= (1<<4),
1228aa0a1e58SJeff Roberson 
1229b5c1e0cbSHans Petter Selasky 	/* reserve bits 26-31 for low level drivers' internal use */
1230b5c1e0cbSHans Petter Selasky 	IB_SEND_RESERVED_START	= (1 << 26),
1231b5c1e0cbSHans Petter Selasky 	IB_SEND_RESERVED_END	= (1 << 31),
1232c9f432b7SAlfred Perlstein };
1233c9f432b7SAlfred Perlstein 
1234aa0a1e58SJeff Roberson struct ib_sge {
1235aa0a1e58SJeff Roberson 	u64	addr;
1236aa0a1e58SJeff Roberson 	u32	length;
1237aa0a1e58SJeff Roberson 	u32	lkey;
1238aa0a1e58SJeff Roberson };
1239aa0a1e58SJeff Roberson 
1240478d3005SHans Petter Selasky struct ib_cqe {
1241478d3005SHans Petter Selasky 	void (*done)(struct ib_cq *cq, struct ib_wc *wc);
1242b5c1e0cbSHans Petter Selasky };
1243b5c1e0cbSHans Petter Selasky 
1244aa0a1e58SJeff Roberson struct ib_send_wr {
1245aa0a1e58SJeff Roberson 	struct ib_send_wr      *next;
1246478d3005SHans Petter Selasky 	union {
1247aa0a1e58SJeff Roberson 		u64		wr_id;
1248478d3005SHans Petter Selasky 		struct ib_cqe	*wr_cqe;
1249478d3005SHans Petter Selasky 	};
1250aa0a1e58SJeff Roberson 	struct ib_sge	       *sg_list;
1251aa0a1e58SJeff Roberson 	int			num_sge;
1252aa0a1e58SJeff Roberson 	enum ib_wr_opcode	opcode;
1253aa0a1e58SJeff Roberson 	int			send_flags;
1254aa0a1e58SJeff Roberson 	union {
1255aa0a1e58SJeff Roberson 		__be32		imm_data;
1256aa0a1e58SJeff Roberson 		u32		invalidate_rkey;
1257aa0a1e58SJeff Roberson 	} ex;
1258478d3005SHans Petter Selasky };
1259478d3005SHans Petter Selasky 
1260478d3005SHans Petter Selasky struct ib_rdma_wr {
1261478d3005SHans Petter Selasky 	struct ib_send_wr	wr;
1262aa0a1e58SJeff Roberson 	u64			remote_addr;
1263aa0a1e58SJeff Roberson 	u32			rkey;
1264478d3005SHans Petter Selasky };
1265478d3005SHans Petter Selasky 
1266478d3005SHans Petter Selasky static inline struct ib_rdma_wr *rdma_wr(struct ib_send_wr *wr)
1267478d3005SHans Petter Selasky {
1268478d3005SHans Petter Selasky 	return container_of(wr, struct ib_rdma_wr, wr);
1269478d3005SHans Petter Selasky }
1270478d3005SHans Petter Selasky 
1271478d3005SHans Petter Selasky struct ib_atomic_wr {
1272478d3005SHans Petter Selasky 	struct ib_send_wr	wr;
1273aa0a1e58SJeff Roberson 	u64			remote_addr;
1274aa0a1e58SJeff Roberson 	u64			compare_add;
1275aa0a1e58SJeff Roberson 	u64			swap;
1276aa0a1e58SJeff Roberson 	u64			compare_add_mask;
1277aa0a1e58SJeff Roberson 	u64			swap_mask;
1278aa0a1e58SJeff Roberson 	u32			rkey;
1279478d3005SHans Petter Selasky };
1280478d3005SHans Petter Selasky 
1281478d3005SHans Petter Selasky static inline struct ib_atomic_wr *atomic_wr(struct ib_send_wr *wr)
1282478d3005SHans Petter Selasky {
1283478d3005SHans Petter Selasky 	return container_of(wr, struct ib_atomic_wr, wr);
1284478d3005SHans Petter Selasky }
1285478d3005SHans Petter Selasky 
1286478d3005SHans Petter Selasky struct ib_ud_wr {
1287478d3005SHans Petter Selasky 	struct ib_send_wr	wr;
1288aa0a1e58SJeff Roberson 	struct ib_ah		*ah;
1289aa0a1e58SJeff Roberson 	void			*header;
1290aa0a1e58SJeff Roberson 	int			hlen;
1291aa0a1e58SJeff Roberson 	int			mss;
1292aa0a1e58SJeff Roberson 	u32			remote_qpn;
1293aa0a1e58SJeff Roberson 	u32			remote_qkey;
1294aa0a1e58SJeff Roberson 	u16			pkey_index; /* valid for GSI only */
1295aa0a1e58SJeff Roberson 	u8			port_num;   /* valid for DR SMPs on switch only */
1296478d3005SHans Petter Selasky };
1297478d3005SHans Petter Selasky 
1298478d3005SHans Petter Selasky static inline struct ib_ud_wr *ud_wr(struct ib_send_wr *wr)
1299478d3005SHans Petter Selasky {
1300478d3005SHans Petter Selasky 	return container_of(wr, struct ib_ud_wr, wr);
1301478d3005SHans Petter Selasky }
1302478d3005SHans Petter Selasky 
1303478d3005SHans Petter Selasky struct ib_reg_wr {
1304478d3005SHans Petter Selasky 	struct ib_send_wr	wr;
1305478d3005SHans Petter Selasky 	struct ib_mr		*mr;
1306478d3005SHans Petter Selasky 	u32			key;
1307478d3005SHans Petter Selasky 	int			access;
1308478d3005SHans Petter Selasky };
1309478d3005SHans Petter Selasky 
1310478d3005SHans Petter Selasky static inline struct ib_reg_wr *reg_wr(struct ib_send_wr *wr)
1311478d3005SHans Petter Selasky {
1312478d3005SHans Petter Selasky 	return container_of(wr, struct ib_reg_wr, wr);
1313478d3005SHans Petter Selasky }
1314478d3005SHans Petter Selasky 
1315478d3005SHans Petter Selasky struct ib_sig_handover_wr {
1316478d3005SHans Petter Selasky 	struct ib_send_wr	wr;
1317b5c1e0cbSHans Petter Selasky 	struct ib_sig_attrs    *sig_attrs;
1318b5c1e0cbSHans Petter Selasky 	struct ib_mr	       *sig_mr;
1319b5c1e0cbSHans Petter Selasky 	int			access_flags;
1320b5c1e0cbSHans Petter Selasky 	struct ib_sge	       *prot;
1321aa0a1e58SJeff Roberson };
1322aa0a1e58SJeff Roberson 
1323478d3005SHans Petter Selasky static inline struct ib_sig_handover_wr *sig_handover_wr(struct ib_send_wr *wr)
1324478d3005SHans Petter Selasky {
1325478d3005SHans Petter Selasky 	return container_of(wr, struct ib_sig_handover_wr, wr);
1326478d3005SHans Petter Selasky }
1327478d3005SHans Petter Selasky 
1328aa0a1e58SJeff Roberson struct ib_recv_wr {
1329aa0a1e58SJeff Roberson 	struct ib_recv_wr      *next;
1330478d3005SHans Petter Selasky 	union {
1331aa0a1e58SJeff Roberson 		u64		wr_id;
1332478d3005SHans Petter Selasky 		struct ib_cqe	*wr_cqe;
1333478d3005SHans Petter Selasky 	};
1334aa0a1e58SJeff Roberson 	struct ib_sge	       *sg_list;
1335aa0a1e58SJeff Roberson 	int			num_sge;
1336aa0a1e58SJeff Roberson };
1337aa0a1e58SJeff Roberson 
1338aa0a1e58SJeff Roberson enum ib_access_flags {
1339aa0a1e58SJeff Roberson 	IB_ACCESS_LOCAL_WRITE	= 1,
1340aa0a1e58SJeff Roberson 	IB_ACCESS_REMOTE_WRITE	= (1<<1),
1341aa0a1e58SJeff Roberson 	IB_ACCESS_REMOTE_READ	= (1<<2),
1342aa0a1e58SJeff Roberson 	IB_ACCESS_REMOTE_ATOMIC	= (1<<3),
1343c9f432b7SAlfred Perlstein 	IB_ACCESS_MW_BIND	= (1<<4),
1344478d3005SHans Petter Selasky 	IB_ZERO_BASED		= (1<<5),
1345478d3005SHans Petter Selasky 	IB_ACCESS_ON_DEMAND     = (1<<6),
1346aa0a1e58SJeff Roberson };
1347aa0a1e58SJeff Roberson 
1348478d3005SHans Petter Selasky /*
1349478d3005SHans Petter Selasky  * XXX: these are apparently used for ->rereg_user_mr, no idea why they
1350478d3005SHans Petter Selasky  * are hidden here instead of a uapi header!
1351478d3005SHans Petter Selasky  */
1352aa0a1e58SJeff Roberson enum ib_mr_rereg_flags {
1353aa0a1e58SJeff Roberson 	IB_MR_REREG_TRANS	= 1,
1354aa0a1e58SJeff Roberson 	IB_MR_REREG_PD		= (1<<1),
1355478d3005SHans Petter Selasky 	IB_MR_REREG_ACCESS	= (1<<2),
1356478d3005SHans Petter Selasky 	IB_MR_REREG_SUPPORTED	= ((IB_MR_REREG_ACCESS << 1) - 1)
1357aa0a1e58SJeff Roberson };
1358aa0a1e58SJeff Roberson 
1359aa0a1e58SJeff Roberson struct ib_fmr_attr {
1360aa0a1e58SJeff Roberson 	int	max_pages;
1361aa0a1e58SJeff Roberson 	int	max_maps;
1362aa0a1e58SJeff Roberson 	u8	page_shift;
1363aa0a1e58SJeff Roberson };
1364aa0a1e58SJeff Roberson 
1365478d3005SHans Petter Selasky struct ib_umem;
1366478d3005SHans Petter Selasky 
1367aa0a1e58SJeff Roberson struct ib_ucontext {
1368aa0a1e58SJeff Roberson 	struct ib_device       *device;
1369aa0a1e58SJeff Roberson 	struct list_head	pd_list;
1370aa0a1e58SJeff Roberson 	struct list_head	mr_list;
1371aa0a1e58SJeff Roberson 	struct list_head	mw_list;
1372aa0a1e58SJeff Roberson 	struct list_head	cq_list;
1373aa0a1e58SJeff Roberson 	struct list_head	qp_list;
1374aa0a1e58SJeff Roberson 	struct list_head	srq_list;
1375aa0a1e58SJeff Roberson 	struct list_head	ah_list;
1376c9f432b7SAlfred Perlstein 	struct list_head	xrcd_list;
1377b5c1e0cbSHans Petter Selasky 	struct list_head	rule_list;
1378478d3005SHans Petter Selasky 	struct list_head	wq_list;
1379478d3005SHans Petter Selasky 	struct list_head	rwq_ind_tbl_list;
1380aa0a1e58SJeff Roberson 	int			closing;
1381478d3005SHans Petter Selasky 
1382478d3005SHans Petter Selasky 	pid_t			tgid;
1383478d3005SHans Petter Selasky #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
1384478d3005SHans Petter Selasky 	struct rb_root      umem_tree;
1385478d3005SHans Petter Selasky 	/*
1386478d3005SHans Petter Selasky 	 * Protects .umem_rbroot and tree, as well as odp_mrs_count and
1387478d3005SHans Petter Selasky 	 * mmu notifiers registration.
1388478d3005SHans Petter Selasky 	 */
1389478d3005SHans Petter Selasky 	struct rw_semaphore	umem_rwsem;
1390478d3005SHans Petter Selasky 	void (*invalidate_range)(struct ib_umem *umem,
1391478d3005SHans Petter Selasky 				 unsigned long start, unsigned long end);
1392478d3005SHans Petter Selasky 
1393478d3005SHans Petter Selasky 	struct mmu_notifier	mn;
1394478d3005SHans Petter Selasky 	atomic_t		notifier_count;
1395478d3005SHans Petter Selasky 	/* A list of umems that don't have private mmu notifier counters yet. */
1396478d3005SHans Petter Selasky 	struct list_head	no_private_counters;
1397478d3005SHans Petter Selasky 	int                     odp_mrs_count;
1398478d3005SHans Petter Selasky #endif
1399aa0a1e58SJeff Roberson };
1400aa0a1e58SJeff Roberson 
1401aa0a1e58SJeff Roberson struct ib_uobject {
1402aa0a1e58SJeff Roberson 	u64			user_handle;	/* handle given to us by userspace */
1403aa0a1e58SJeff Roberson 	struct ib_ucontext     *context;	/* associated user context */
1404aa0a1e58SJeff Roberson 	void		       *object;		/* containing object */
1405aa0a1e58SJeff Roberson 	struct list_head	list;		/* link to context's list */
1406aa0a1e58SJeff Roberson 	int			id;		/* index into kernel idr */
1407aa0a1e58SJeff Roberson 	struct kref		ref;
1408aa0a1e58SJeff Roberson 	struct rw_semaphore	mutex;		/* protects .live */
1409478d3005SHans Petter Selasky 	struct rcu_head		rcu;		/* kfree_rcu() overhead */
1410aa0a1e58SJeff Roberson 	int			live;
1411aa0a1e58SJeff Roberson };
1412aa0a1e58SJeff Roberson 
1413aa0a1e58SJeff Roberson struct ib_udata {
1414478d3005SHans Petter Selasky 	const void __user *inbuf;
1415aa0a1e58SJeff Roberson 	void __user *outbuf;
1416aa0a1e58SJeff Roberson 	size_t       inlen;
1417aa0a1e58SJeff Roberson 	size_t       outlen;
1418aa0a1e58SJeff Roberson };
1419aa0a1e58SJeff Roberson 
1420aa0a1e58SJeff Roberson struct ib_pd {
1421478d3005SHans Petter Selasky 	u32			local_dma_lkey;
1422478d3005SHans Petter Selasky 	u32			flags;
1423aa0a1e58SJeff Roberson 	struct ib_device       *device;
1424aa0a1e58SJeff Roberson 	struct ib_uobject      *uobject;
1425aa0a1e58SJeff Roberson 	atomic_t          	usecnt; /* count all resources */
1426478d3005SHans Petter Selasky 
1427478d3005SHans Petter Selasky 	u32			unsafe_global_rkey;
1428478d3005SHans Petter Selasky 
1429478d3005SHans Petter Selasky 	/*
1430478d3005SHans Petter Selasky 	 * Implementation details of the RDMA core, don't use in drivers:
1431478d3005SHans Petter Selasky 	 */
1432478d3005SHans Petter Selasky 	struct ib_mr	       *__internal_mr;
1433aa0a1e58SJeff Roberson };
1434aa0a1e58SJeff Roberson 
1435aa0a1e58SJeff Roberson struct ib_xrcd {
1436aa0a1e58SJeff Roberson 	struct ib_device       *device;
1437c9f432b7SAlfred Perlstein 	atomic_t		usecnt; /* count all exposed resources */
1438aa0a1e58SJeff Roberson 	struct inode	       *inode;
1439aa0a1e58SJeff Roberson 
1440c9f432b7SAlfred Perlstein 	struct mutex		tgt_qp_mutex;
1441c9f432b7SAlfred Perlstein 	struct list_head	tgt_qp_list;
1442c9f432b7SAlfred Perlstein };
1443aa0a1e58SJeff Roberson 
1444aa0a1e58SJeff Roberson struct ib_ah {
1445aa0a1e58SJeff Roberson 	struct ib_device	*device;
1446aa0a1e58SJeff Roberson 	struct ib_pd		*pd;
1447aa0a1e58SJeff Roberson 	struct ib_uobject	*uobject;
1448aa0a1e58SJeff Roberson };
1449aa0a1e58SJeff Roberson 
1450aa0a1e58SJeff Roberson typedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1451aa0a1e58SJeff Roberson 
1452478d3005SHans Petter Selasky enum ib_poll_context {
1453478d3005SHans Petter Selasky 	IB_POLL_DIRECT,		/* caller context, no hw completions */
1454478d3005SHans Petter Selasky 	IB_POLL_SOFTIRQ,	/* poll from softirq context */
1455478d3005SHans Petter Selasky 	IB_POLL_WORKQUEUE,	/* poll from workqueue */
1456478d3005SHans Petter Selasky };
1457478d3005SHans Petter Selasky 
1458aa0a1e58SJeff Roberson struct ib_cq {
1459aa0a1e58SJeff Roberson 	struct ib_device       *device;
1460aa0a1e58SJeff Roberson 	struct ib_uobject      *uobject;
1461aa0a1e58SJeff Roberson 	ib_comp_handler   	comp_handler;
1462aa0a1e58SJeff Roberson 	void                  (*event_handler)(struct ib_event *, void *);
1463aa0a1e58SJeff Roberson 	void                   *cq_context;
1464aa0a1e58SJeff Roberson 	int               	cqe;
1465aa0a1e58SJeff Roberson 	atomic_t          	usecnt; /* count number of work queues */
1466478d3005SHans Petter Selasky 	enum ib_poll_context	poll_ctx;
1467478d3005SHans Petter Selasky 	struct work_struct	work;
1468aa0a1e58SJeff Roberson };
1469aa0a1e58SJeff Roberson 
1470aa0a1e58SJeff Roberson struct ib_srq {
1471aa0a1e58SJeff Roberson 	struct ib_device       *device;
1472aa0a1e58SJeff Roberson 	struct ib_pd	       *pd;
1473aa0a1e58SJeff Roberson 	struct ib_uobject      *uobject;
1474aa0a1e58SJeff Roberson 	void		      (*event_handler)(struct ib_event *, void *);
1475aa0a1e58SJeff Roberson 	void		       *srq_context;
1476c9f432b7SAlfred Perlstein 	enum ib_srq_type	srq_type;
1477aa0a1e58SJeff Roberson 	atomic_t		usecnt;
1478c9f432b7SAlfred Perlstein 
1479c9f432b7SAlfred Perlstein 	union {
1480c9f432b7SAlfred Perlstein 		struct {
1481c9f432b7SAlfred Perlstein 			struct ib_xrcd *xrcd;
1482c9f432b7SAlfred Perlstein 			struct ib_cq   *cq;
1483c9f432b7SAlfred Perlstein 			u32		srq_num;
1484c9f432b7SAlfred Perlstein 		} xrc;
1485c9f432b7SAlfred Perlstein 	} ext;
1486aa0a1e58SJeff Roberson };
1487aa0a1e58SJeff Roberson 
1488478d3005SHans Petter Selasky enum ib_wq_type {
1489478d3005SHans Petter Selasky 	IB_WQT_RQ
1490478d3005SHans Petter Selasky };
1491478d3005SHans Petter Selasky 
1492478d3005SHans Petter Selasky enum ib_wq_state {
1493478d3005SHans Petter Selasky 	IB_WQS_RESET,
1494478d3005SHans Petter Selasky 	IB_WQS_RDY,
1495478d3005SHans Petter Selasky 	IB_WQS_ERR
1496478d3005SHans Petter Selasky };
1497478d3005SHans Petter Selasky 
1498478d3005SHans Petter Selasky struct ib_wq {
1499478d3005SHans Petter Selasky 	struct ib_device       *device;
1500478d3005SHans Petter Selasky 	struct ib_uobject      *uobject;
1501478d3005SHans Petter Selasky 	void		    *wq_context;
1502478d3005SHans Petter Selasky 	void		    (*event_handler)(struct ib_event *, void *);
1503478d3005SHans Petter Selasky 	struct ib_pd	       *pd;
1504478d3005SHans Petter Selasky 	struct ib_cq	       *cq;
1505478d3005SHans Petter Selasky 	u32		wq_num;
1506478d3005SHans Petter Selasky 	enum ib_wq_state       state;
1507478d3005SHans Petter Selasky 	enum ib_wq_type	wq_type;
1508478d3005SHans Petter Selasky 	atomic_t		usecnt;
1509478d3005SHans Petter Selasky };
1510478d3005SHans Petter Selasky 
1511478d3005SHans Petter Selasky struct ib_wq_init_attr {
1512478d3005SHans Petter Selasky 	void		       *wq_context;
1513478d3005SHans Petter Selasky 	enum ib_wq_type	wq_type;
1514478d3005SHans Petter Selasky 	u32		max_wr;
1515478d3005SHans Petter Selasky 	u32		max_sge;
1516478d3005SHans Petter Selasky 	struct	ib_cq	       *cq;
1517478d3005SHans Petter Selasky 	void		    (*event_handler)(struct ib_event *, void *);
1518478d3005SHans Petter Selasky };
1519478d3005SHans Petter Selasky 
1520478d3005SHans Petter Selasky enum ib_wq_attr_mask {
1521478d3005SHans Petter Selasky 	IB_WQ_STATE	= 1 << 0,
1522478d3005SHans Petter Selasky 	IB_WQ_CUR_STATE	= 1 << 1,
1523478d3005SHans Petter Selasky };
1524478d3005SHans Petter Selasky 
1525478d3005SHans Petter Selasky struct ib_wq_attr {
1526478d3005SHans Petter Selasky 	enum	ib_wq_state	wq_state;
1527478d3005SHans Petter Selasky 	enum	ib_wq_state	curr_wq_state;
1528478d3005SHans Petter Selasky };
1529478d3005SHans Petter Selasky 
1530478d3005SHans Petter Selasky struct ib_rwq_ind_table {
1531478d3005SHans Petter Selasky 	struct ib_device	*device;
1532478d3005SHans Petter Selasky 	struct ib_uobject      *uobject;
1533478d3005SHans Petter Selasky 	atomic_t		usecnt;
1534478d3005SHans Petter Selasky 	u32		ind_tbl_num;
1535478d3005SHans Petter Selasky 	u32		log_ind_tbl_size;
1536478d3005SHans Petter Selasky 	struct ib_wq	**ind_tbl;
1537478d3005SHans Petter Selasky };
1538478d3005SHans Petter Selasky 
1539478d3005SHans Petter Selasky struct ib_rwq_ind_table_init_attr {
1540478d3005SHans Petter Selasky 	u32		log_ind_tbl_size;
1541478d3005SHans Petter Selasky 	/* Each entry is a pointer to Receive Work Queue */
1542478d3005SHans Petter Selasky 	struct ib_wq	**ind_tbl;
1543478d3005SHans Petter Selasky };
1544478d3005SHans Petter Selasky 
1545478d3005SHans Petter Selasky /*
1546478d3005SHans Petter Selasky  * @max_write_sge: Maximum SGE elements per RDMA WRITE request.
1547478d3005SHans Petter Selasky  * @max_read_sge:  Maximum SGE elements per RDMA READ request.
1548478d3005SHans Petter Selasky  */
1549aa0a1e58SJeff Roberson struct ib_qp {
1550aa0a1e58SJeff Roberson 	struct ib_device       *device;
1551aa0a1e58SJeff Roberson 	struct ib_pd	       *pd;
1552aa0a1e58SJeff Roberson 	struct ib_cq	       *send_cq;
1553aa0a1e58SJeff Roberson 	struct ib_cq	       *recv_cq;
1554478d3005SHans Petter Selasky 	spinlock_t		mr_lock;
1555aa0a1e58SJeff Roberson 	struct ib_srq	       *srq;
1556c9f432b7SAlfred Perlstein 	struct ib_xrcd	       *xrcd; /* XRC TGT QPs only */
1557c9f432b7SAlfred Perlstein 	struct list_head	xrcd_list;
1558478d3005SHans Petter Selasky 
1559b5c1e0cbSHans Petter Selasky 	/* count times opened, mcast attaches, flow attaches */
1560b5c1e0cbSHans Petter Selasky 	atomic_t		usecnt;
1561c9f432b7SAlfred Perlstein 	struct list_head	open_list;
1562c9f432b7SAlfred Perlstein 	struct ib_qp           *real_qp;
1563aa0a1e58SJeff Roberson 	struct ib_uobject      *uobject;
1564aa0a1e58SJeff Roberson 	void                  (*event_handler)(struct ib_event *, void *);
1565aa0a1e58SJeff Roberson 	void		       *qp_context;
1566aa0a1e58SJeff Roberson 	u32			qp_num;
1567478d3005SHans Petter Selasky 	u32			max_write_sge;
1568478d3005SHans Petter Selasky 	u32			max_read_sge;
1569aa0a1e58SJeff Roberson 	enum ib_qp_type		qp_type;
1570478d3005SHans Petter Selasky 	struct ib_rwq_ind_table *rwq_ind_tbl;
1571aa0a1e58SJeff Roberson };
1572aa0a1e58SJeff Roberson 
1573aa0a1e58SJeff Roberson struct ib_mr {
1574aa0a1e58SJeff Roberson 	struct ib_device  *device;
1575aa0a1e58SJeff Roberson 	struct ib_pd	  *pd;
1576aa0a1e58SJeff Roberson 	u32		   lkey;
1577aa0a1e58SJeff Roberson 	u32		   rkey;
1578478d3005SHans Petter Selasky 	u64		   iova;
1579ae9a8ec9SHans Petter Selasky 	u64		   length;
1580478d3005SHans Petter Selasky 	unsigned int	   page_size;
1581478d3005SHans Petter Selasky 	bool		   need_inval;
1582478d3005SHans Petter Selasky 	union {
1583478d3005SHans Petter Selasky 		struct ib_uobject	*uobject;	/* user */
1584478d3005SHans Petter Selasky 		struct list_head	qp_entry;	/* FR */
1585478d3005SHans Petter Selasky 	};
1586aa0a1e58SJeff Roberson };
1587aa0a1e58SJeff Roberson 
1588aa0a1e58SJeff Roberson struct ib_mw {
1589aa0a1e58SJeff Roberson 	struct ib_device	*device;
1590aa0a1e58SJeff Roberson 	struct ib_pd		*pd;
1591aa0a1e58SJeff Roberson 	struct ib_uobject	*uobject;
1592aa0a1e58SJeff Roberson 	u32			rkey;
1593b5c1e0cbSHans Petter Selasky 	enum ib_mw_type         type;
1594aa0a1e58SJeff Roberson };
1595aa0a1e58SJeff Roberson 
1596aa0a1e58SJeff Roberson struct ib_fmr {
1597aa0a1e58SJeff Roberson 	struct ib_device	*device;
1598aa0a1e58SJeff Roberson 	struct ib_pd		*pd;
1599aa0a1e58SJeff Roberson 	struct list_head	list;
1600aa0a1e58SJeff Roberson 	u32			lkey;
1601aa0a1e58SJeff Roberson 	u32			rkey;
1602aa0a1e58SJeff Roberson };
1603aa0a1e58SJeff Roberson 
1604b5c1e0cbSHans Petter Selasky /* Supported steering options */
1605b5c1e0cbSHans Petter Selasky enum ib_flow_attr_type {
1606b5c1e0cbSHans Petter Selasky 	/* steering according to rule specifications */
1607b5c1e0cbSHans Petter Selasky 	IB_FLOW_ATTR_NORMAL		= 0x0,
1608b5c1e0cbSHans Petter Selasky 	/* default unicast and multicast rule -
1609b5c1e0cbSHans Petter Selasky 	 * receive all Eth traffic which isn't steered to any QP
1610b5c1e0cbSHans Petter Selasky 	 */
1611b5c1e0cbSHans Petter Selasky 	IB_FLOW_ATTR_ALL_DEFAULT	= 0x1,
1612b5c1e0cbSHans Petter Selasky 	/* default multicast rule -
1613b5c1e0cbSHans Petter Selasky 	 * receive all Eth multicast traffic which isn't steered to any QP
1614b5c1e0cbSHans Petter Selasky 	 */
1615b5c1e0cbSHans Petter Selasky 	IB_FLOW_ATTR_MC_DEFAULT		= 0x2,
1616b5c1e0cbSHans Petter Selasky 	/* sniffer rule - receive all port traffic */
1617b5c1e0cbSHans Petter Selasky 	IB_FLOW_ATTR_SNIFFER		= 0x3
1618b5c1e0cbSHans Petter Selasky };
1619b5c1e0cbSHans Petter Selasky 
1620b5c1e0cbSHans Petter Selasky /* Supported steering header types */
1621b5c1e0cbSHans Petter Selasky enum ib_flow_spec_type {
1622b5c1e0cbSHans Petter Selasky 	/* L2 headers*/
1623b5c1e0cbSHans Petter Selasky 	IB_FLOW_SPEC_ETH	= 0x20,
1624478d3005SHans Petter Selasky 	IB_FLOW_SPEC_IB		= 0x22,
1625b5c1e0cbSHans Petter Selasky 	/* L3 header*/
1626b5c1e0cbSHans Petter Selasky 	IB_FLOW_SPEC_IPV4	= 0x30,
1627478d3005SHans Petter Selasky 	IB_FLOW_SPEC_IPV6	= 0x31,
1628b5c1e0cbSHans Petter Selasky 	/* L4 headers*/
1629b5c1e0cbSHans Petter Selasky 	IB_FLOW_SPEC_TCP	= 0x40,
1630b5c1e0cbSHans Petter Selasky 	IB_FLOW_SPEC_UDP	= 0x41
1631b5c1e0cbSHans Petter Selasky };
1632478d3005SHans Petter Selasky #define IB_FLOW_SPEC_LAYER_MASK	0xF0
1633b5c1e0cbSHans Petter Selasky #define IB_FLOW_SPEC_SUPPORT_LAYERS 4
1634b5c1e0cbSHans Petter Selasky 
1635b5c1e0cbSHans Petter Selasky /* Flow steering rule priority is set according to it's domain.
1636b5c1e0cbSHans Petter Selasky  * Lower domain value means higher priority.
1637b5c1e0cbSHans Petter Selasky  */
1638b5c1e0cbSHans Petter Selasky enum ib_flow_domain {
1639b5c1e0cbSHans Petter Selasky 	IB_FLOW_DOMAIN_USER,
1640b5c1e0cbSHans Petter Selasky 	IB_FLOW_DOMAIN_ETHTOOL,
1641b5c1e0cbSHans Petter Selasky 	IB_FLOW_DOMAIN_RFS,
1642b5c1e0cbSHans Petter Selasky 	IB_FLOW_DOMAIN_NIC,
1643b5c1e0cbSHans Petter Selasky 	IB_FLOW_DOMAIN_NUM /* Must be last */
1644b5c1e0cbSHans Petter Selasky };
1645b5c1e0cbSHans Petter Selasky 
1646b5c1e0cbSHans Petter Selasky enum ib_flow_flags {
1647478d3005SHans Petter Selasky 	IB_FLOW_ATTR_FLAGS_DONT_TRAP = 1UL << 1, /* Continue match, no steal */
1648478d3005SHans Petter Selasky 	IB_FLOW_ATTR_FLAGS_RESERVED  = 1UL << 2  /* Must be last */
1649b5c1e0cbSHans Petter Selasky };
1650b5c1e0cbSHans Petter Selasky 
1651b5c1e0cbSHans Petter Selasky struct ib_flow_eth_filter {
1652b5c1e0cbSHans Petter Selasky 	u8	dst_mac[6];
1653b5c1e0cbSHans Petter Selasky 	u8	src_mac[6];
1654b5c1e0cbSHans Petter Selasky 	__be16	ether_type;
1655b5c1e0cbSHans Petter Selasky 	__be16	vlan_tag;
1656478d3005SHans Petter Selasky 	/* Must be last */
1657478d3005SHans Petter Selasky 	u8	real_sz[0];
1658b5c1e0cbSHans Petter Selasky };
1659b5c1e0cbSHans Petter Selasky 
1660b5c1e0cbSHans Petter Selasky struct ib_flow_spec_eth {
1661b5c1e0cbSHans Petter Selasky 	enum ib_flow_spec_type	  type;
1662b5c1e0cbSHans Petter Selasky 	u16			  size;
1663b5c1e0cbSHans Petter Selasky 	struct ib_flow_eth_filter val;
1664b5c1e0cbSHans Petter Selasky 	struct ib_flow_eth_filter mask;
1665b5c1e0cbSHans Petter Selasky };
1666b5c1e0cbSHans Petter Selasky 
1667b5c1e0cbSHans Petter Selasky struct ib_flow_ib_filter {
1668478d3005SHans Petter Selasky 	__be16 dlid;
1669478d3005SHans Petter Selasky 	__u8   sl;
1670478d3005SHans Petter Selasky 	/* Must be last */
1671478d3005SHans Petter Selasky 	u8	real_sz[0];
1672b5c1e0cbSHans Petter Selasky };
1673b5c1e0cbSHans Petter Selasky 
1674b5c1e0cbSHans Petter Selasky struct ib_flow_spec_ib {
1675b5c1e0cbSHans Petter Selasky 	enum ib_flow_spec_type	 type;
1676b5c1e0cbSHans Petter Selasky 	u16			 size;
1677b5c1e0cbSHans Petter Selasky 	struct ib_flow_ib_filter val;
1678b5c1e0cbSHans Petter Selasky 	struct ib_flow_ib_filter mask;
1679b5c1e0cbSHans Petter Selasky };
1680b5c1e0cbSHans Petter Selasky 
1681478d3005SHans Petter Selasky /* IPv4 header flags */
1682478d3005SHans Petter Selasky enum ib_ipv4_flags {
1683478d3005SHans Petter Selasky 	IB_IPV4_DONT_FRAG = 0x2, /* Don't enable packet fragmentation */
1684478d3005SHans Petter Selasky 	IB_IPV4_MORE_FRAG = 0X4  /* For All fragmented packets except the
1685478d3005SHans Petter Selasky 				    last have this flag set */
1686478d3005SHans Petter Selasky };
1687478d3005SHans Petter Selasky 
1688b5c1e0cbSHans Petter Selasky struct ib_flow_ipv4_filter {
1689c9f432b7SAlfred Perlstein 	__be32	src_ip;
1690c9f432b7SAlfred Perlstein 	__be32	dst_ip;
1691478d3005SHans Petter Selasky 	u8	proto;
1692478d3005SHans Petter Selasky 	u8	tos;
1693478d3005SHans Petter Selasky 	u8	ttl;
1694478d3005SHans Petter Selasky 	u8	flags;
1695478d3005SHans Petter Selasky 	/* Must be last */
1696478d3005SHans Petter Selasky 	u8	real_sz[0];
1697b5c1e0cbSHans Petter Selasky };
1698b5c1e0cbSHans Petter Selasky 
1699b5c1e0cbSHans Petter Selasky struct ib_flow_spec_ipv4 {
1700b5c1e0cbSHans Petter Selasky 	enum ib_flow_spec_type	   type;
1701b5c1e0cbSHans Petter Selasky 	u16			   size;
1702b5c1e0cbSHans Petter Selasky 	struct ib_flow_ipv4_filter val;
1703b5c1e0cbSHans Petter Selasky 	struct ib_flow_ipv4_filter mask;
1704b5c1e0cbSHans Petter Selasky };
1705b5c1e0cbSHans Petter Selasky 
1706478d3005SHans Petter Selasky struct ib_flow_ipv6_filter {
1707478d3005SHans Petter Selasky 	u8	src_ip[16];
1708478d3005SHans Petter Selasky 	u8	dst_ip[16];
1709478d3005SHans Petter Selasky 	__be32	flow_label;
1710478d3005SHans Petter Selasky 	u8	next_hdr;
1711478d3005SHans Petter Selasky 	u8	traffic_class;
1712478d3005SHans Petter Selasky 	u8	hop_limit;
1713478d3005SHans Petter Selasky 	/* Must be last */
1714478d3005SHans Petter Selasky 	u8	real_sz[0];
1715478d3005SHans Petter Selasky };
1716478d3005SHans Petter Selasky 
1717478d3005SHans Petter Selasky struct ib_flow_spec_ipv6 {
1718478d3005SHans Petter Selasky 	enum ib_flow_spec_type	   type;
1719478d3005SHans Petter Selasky 	u16			   size;
1720478d3005SHans Petter Selasky 	struct ib_flow_ipv6_filter val;
1721478d3005SHans Petter Selasky 	struct ib_flow_ipv6_filter mask;
1722478d3005SHans Petter Selasky };
1723478d3005SHans Petter Selasky 
1724b5c1e0cbSHans Petter Selasky struct ib_flow_tcp_udp_filter {
1725c9f432b7SAlfred Perlstein 	__be16	dst_port;
1726b5c1e0cbSHans Petter Selasky 	__be16	src_port;
1727478d3005SHans Petter Selasky 	/* Must be last */
1728478d3005SHans Petter Selasky 	u8	real_sz[0];
1729b5c1e0cbSHans Petter Selasky };
1730b5c1e0cbSHans Petter Selasky 
1731b5c1e0cbSHans Petter Selasky struct ib_flow_spec_tcp_udp {
1732b5c1e0cbSHans Petter Selasky 	enum ib_flow_spec_type	      type;
1733b5c1e0cbSHans Petter Selasky 	u16			      size;
1734b5c1e0cbSHans Petter Selasky 	struct ib_flow_tcp_udp_filter val;
1735b5c1e0cbSHans Petter Selasky 	struct ib_flow_tcp_udp_filter mask;
1736b5c1e0cbSHans Petter Selasky };
1737b5c1e0cbSHans Petter Selasky 
1738b5c1e0cbSHans Petter Selasky union ib_flow_spec {
1739b5c1e0cbSHans Petter Selasky 	struct {
1740b5c1e0cbSHans Petter Selasky 		enum ib_flow_spec_type	type;
1741b5c1e0cbSHans Petter Selasky 		u16			size;
1742b5c1e0cbSHans Petter Selasky 	};
1743b5c1e0cbSHans Petter Selasky 	struct ib_flow_spec_eth		eth;
1744478d3005SHans Petter Selasky 	struct ib_flow_spec_ib		ib;
1745b5c1e0cbSHans Petter Selasky 	struct ib_flow_spec_ipv4        ipv4;
1746b5c1e0cbSHans Petter Selasky 	struct ib_flow_spec_tcp_udp	tcp_udp;
1747478d3005SHans Petter Selasky 	struct ib_flow_spec_ipv6        ipv6;
1748b5c1e0cbSHans Petter Selasky };
1749b5c1e0cbSHans Petter Selasky 
1750b5c1e0cbSHans Petter Selasky struct ib_flow_attr {
1751b5c1e0cbSHans Petter Selasky 	enum ib_flow_attr_type type;
1752b5c1e0cbSHans Petter Selasky 	u16	     size;
1753b5c1e0cbSHans Petter Selasky 	u16	     priority;
1754478d3005SHans Petter Selasky 	u32	     flags;
1755b5c1e0cbSHans Petter Selasky 	u8	     num_of_specs;
1756b5c1e0cbSHans Petter Selasky 	u8	     port;
1757b5c1e0cbSHans Petter Selasky 	/* Following are the optional layers according to user request
1758b5c1e0cbSHans Petter Selasky 	 * struct ib_flow_spec_xxx
1759b5c1e0cbSHans Petter Selasky 	 * struct ib_flow_spec_yyy
1760b5c1e0cbSHans Petter Selasky 	 */
1761b5c1e0cbSHans Petter Selasky };
1762b5c1e0cbSHans Petter Selasky 
1763b5c1e0cbSHans Petter Selasky struct ib_flow {
1764b5c1e0cbSHans Petter Selasky 	struct ib_qp		*qp;
1765b5c1e0cbSHans Petter Selasky 	struct ib_uobject	*uobject;
1766c9f432b7SAlfred Perlstein };
1767c9f432b7SAlfred Perlstein 
1768478d3005SHans Petter Selasky struct ib_mad_hdr;
1769aa0a1e58SJeff Roberson struct ib_grh;
1770aa0a1e58SJeff Roberson 
1771aa0a1e58SJeff Roberson enum ib_process_mad_flags {
1772aa0a1e58SJeff Roberson 	IB_MAD_IGNORE_MKEY	= 1,
1773aa0a1e58SJeff Roberson 	IB_MAD_IGNORE_BKEY	= 2,
1774aa0a1e58SJeff Roberson 	IB_MAD_IGNORE_ALL	= IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1775aa0a1e58SJeff Roberson };
1776aa0a1e58SJeff Roberson 
1777aa0a1e58SJeff Roberson enum ib_mad_result {
1778aa0a1e58SJeff Roberson 	IB_MAD_RESULT_FAILURE  = 0,      /* (!SUCCESS is the important flag) */
1779aa0a1e58SJeff Roberson 	IB_MAD_RESULT_SUCCESS  = 1 << 0, /* MAD was successfully processed   */
1780aa0a1e58SJeff Roberson 	IB_MAD_RESULT_REPLY    = 1 << 1, /* Reply packet needs to be sent    */
1781aa0a1e58SJeff Roberson 	IB_MAD_RESULT_CONSUMED = 1 << 2  /* Packet consumed: stop processing */
1782aa0a1e58SJeff Roberson };
1783aa0a1e58SJeff Roberson 
1784aa0a1e58SJeff Roberson #define IB_DEVICE_NAME_MAX 64
1785aa0a1e58SJeff Roberson 
1786aa0a1e58SJeff Roberson struct ib_cache {
1787aa0a1e58SJeff Roberson 	rwlock_t                lock;
1788aa0a1e58SJeff Roberson 	struct ib_event_handler event_handler;
1789aa0a1e58SJeff Roberson 	struct ib_pkey_cache  **pkey_cache;
1790478d3005SHans Petter Selasky 	struct ib_gid_table   **gid_cache;
1791aa0a1e58SJeff Roberson 	u8                     *lmc_cache;
1792aa0a1e58SJeff Roberson };
1793aa0a1e58SJeff Roberson 
1794aa0a1e58SJeff Roberson struct ib_dma_mapping_ops {
1795aa0a1e58SJeff Roberson 	int		(*mapping_error)(struct ib_device *dev,
1796aa0a1e58SJeff Roberson 					 u64 dma_addr);
1797aa0a1e58SJeff Roberson 	u64		(*map_single)(struct ib_device *dev,
1798aa0a1e58SJeff Roberson 				      void *ptr, size_t size,
1799aa0a1e58SJeff Roberson 				      enum dma_data_direction direction);
1800aa0a1e58SJeff Roberson 	void		(*unmap_single)(struct ib_device *dev,
1801aa0a1e58SJeff Roberson 					u64 addr, size_t size,
1802aa0a1e58SJeff Roberson 					enum dma_data_direction direction);
1803aa0a1e58SJeff Roberson 	u64		(*map_page)(struct ib_device *dev,
1804aa0a1e58SJeff Roberson 				    struct page *page, unsigned long offset,
1805aa0a1e58SJeff Roberson 				    size_t size,
1806aa0a1e58SJeff Roberson 				    enum dma_data_direction direction);
1807aa0a1e58SJeff Roberson 	void		(*unmap_page)(struct ib_device *dev,
1808aa0a1e58SJeff Roberson 				      u64 addr, size_t size,
1809aa0a1e58SJeff Roberson 				      enum dma_data_direction direction);
1810aa0a1e58SJeff Roberson 	int		(*map_sg)(struct ib_device *dev,
1811aa0a1e58SJeff Roberson 				  struct scatterlist *sg, int nents,
1812aa0a1e58SJeff Roberson 				  enum dma_data_direction direction);
1813aa0a1e58SJeff Roberson 	void		(*unmap_sg)(struct ib_device *dev,
1814aa0a1e58SJeff Roberson 				    struct scatterlist *sg, int nents,
1815aa0a1e58SJeff Roberson 				    enum dma_data_direction direction);
1816478d3005SHans Petter Selasky 	int		(*map_sg_attrs)(struct ib_device *dev,
1817478d3005SHans Petter Selasky 					struct scatterlist *sg, int nents,
1818478d3005SHans Petter Selasky 					enum dma_data_direction direction,
1819478d3005SHans Petter Selasky 					struct dma_attrs *attrs);
1820478d3005SHans Petter Selasky 	void		(*unmap_sg_attrs)(struct ib_device *dev,
1821478d3005SHans Petter Selasky 					  struct scatterlist *sg, int nents,
1822478d3005SHans Petter Selasky 					  enum dma_data_direction direction,
1823478d3005SHans Petter Selasky 					  struct dma_attrs *attrs);
1824aa0a1e58SJeff Roberson 	void		(*sync_single_for_cpu)(struct ib_device *dev,
1825aa0a1e58SJeff Roberson 					       u64 dma_handle,
1826aa0a1e58SJeff Roberson 					       size_t size,
1827aa0a1e58SJeff Roberson 					       enum dma_data_direction dir);
1828aa0a1e58SJeff Roberson 	void		(*sync_single_for_device)(struct ib_device *dev,
1829aa0a1e58SJeff Roberson 						  u64 dma_handle,
1830aa0a1e58SJeff Roberson 						  size_t size,
1831aa0a1e58SJeff Roberson 						  enum dma_data_direction dir);
1832aa0a1e58SJeff Roberson 	void		*(*alloc_coherent)(struct ib_device *dev,
1833aa0a1e58SJeff Roberson 					   size_t size,
1834aa0a1e58SJeff Roberson 					   u64 *dma_handle,
1835aa0a1e58SJeff Roberson 					   gfp_t flag);
1836aa0a1e58SJeff Roberson 	void		(*free_coherent)(struct ib_device *dev,
1837aa0a1e58SJeff Roberson 					 size_t size, void *cpu_addr,
1838aa0a1e58SJeff Roberson 					 u64 dma_handle);
1839aa0a1e58SJeff Roberson };
1840aa0a1e58SJeff Roberson 
1841aa0a1e58SJeff Roberson struct iw_cm_verbs;
1842478d3005SHans Petter Selasky 
1843478d3005SHans Petter Selasky struct ib_port_immutable {
1844478d3005SHans Petter Selasky 	int                           pkey_tbl_len;
1845478d3005SHans Petter Selasky 	int                           gid_tbl_len;
1846478d3005SHans Petter Selasky 	u32                           core_cap_flags;
1847478d3005SHans Petter Selasky 	u32                           max_mad_size;
1848478d3005SHans Petter Selasky };
1849aa0a1e58SJeff Roberson 
1850aa0a1e58SJeff Roberson struct ib_device {
1851aa0a1e58SJeff Roberson 	struct device                *dma_device;
1852aa0a1e58SJeff Roberson 
1853aa0a1e58SJeff Roberson 	char                          name[IB_DEVICE_NAME_MAX];
1854aa0a1e58SJeff Roberson 
1855aa0a1e58SJeff Roberson 	struct list_head              event_handler_list;
1856aa0a1e58SJeff Roberson 	spinlock_t                    event_handler_lock;
1857aa0a1e58SJeff Roberson 
1858c9f432b7SAlfred Perlstein 	spinlock_t                    client_data_lock;
1859aa0a1e58SJeff Roberson 	struct list_head              core_list;
1860478d3005SHans Petter Selasky 	/* Access to the client_data_list is protected by the client_data_lock
1861478d3005SHans Petter Selasky 	 * spinlock and the lists_rwsem read-write semaphore */
1862aa0a1e58SJeff Roberson 	struct list_head              client_data_list;
1863aa0a1e58SJeff Roberson 
1864aa0a1e58SJeff Roberson 	struct ib_cache               cache;
1865478d3005SHans Petter Selasky 	/**
1866478d3005SHans Petter Selasky 	 * port_immutable is indexed by port number
1867478d3005SHans Petter Selasky 	 */
1868478d3005SHans Petter Selasky 	struct ib_port_immutable     *port_immutable;
1869aa0a1e58SJeff Roberson 
1870aa0a1e58SJeff Roberson 	int			      num_comp_vectors;
1871aa0a1e58SJeff Roberson 
1872aa0a1e58SJeff Roberson 	struct iw_cm_verbs	     *iwcm;
1873aa0a1e58SJeff Roberson 
1874478d3005SHans Petter Selasky 	/**
1875478d3005SHans Petter Selasky 	 * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
1876478d3005SHans Petter Selasky 	 *   driver initialized data.  The struct is kfree()'ed by the sysfs
1877478d3005SHans Petter Selasky 	 *   core when the device is removed.  A lifespan of -1 in the return
1878478d3005SHans Petter Selasky 	 *   struct tells the core to set a default lifespan.
1879478d3005SHans Petter Selasky 	 */
1880478d3005SHans Petter Selasky 	struct rdma_hw_stats      *(*alloc_hw_stats)(struct ib_device *device,
1881478d3005SHans Petter Selasky 						     u8 port_num);
1882478d3005SHans Petter Selasky 	/**
1883478d3005SHans Petter Selasky 	 * get_hw_stats - Fill in the counter value(s) in the stats struct.
1884478d3005SHans Petter Selasky 	 * @index - The index in the value array we wish to have updated, or
1885478d3005SHans Petter Selasky 	 *   num_counters if we want all stats updated
1886478d3005SHans Petter Selasky 	 * Return codes -
1887478d3005SHans Petter Selasky 	 *   < 0 - Error, no counters updated
1888478d3005SHans Petter Selasky 	 *   index - Updated the single counter pointed to by index
1889478d3005SHans Petter Selasky 	 *   num_counters - Updated all counters (will reset the timestamp
1890478d3005SHans Petter Selasky 	 *     and prevent further calls for lifespan milliseconds)
1891478d3005SHans Petter Selasky 	 * Drivers are allowed to update all counters in leiu of just the
1892478d3005SHans Petter Selasky 	 *   one given in index at their option
1893478d3005SHans Petter Selasky 	 */
1894478d3005SHans Petter Selasky 	int		           (*get_hw_stats)(struct ib_device *device,
1895478d3005SHans Petter Selasky 						   struct rdma_hw_stats *stats,
1896478d3005SHans Petter Selasky 						   u8 port, int index);
1897aa0a1e58SJeff Roberson 	int		           (*query_device)(struct ib_device *device,
1898478d3005SHans Petter Selasky 						   struct ib_device_attr *device_attr,
1899478d3005SHans Petter Selasky 						   struct ib_udata *udata);
1900aa0a1e58SJeff Roberson 	int		           (*query_port)(struct ib_device *device,
1901aa0a1e58SJeff Roberson 						 u8 port_num,
1902aa0a1e58SJeff Roberson 						 struct ib_port_attr *port_attr);
1903aa0a1e58SJeff Roberson 	enum rdma_link_layer	   (*get_link_layer)(struct ib_device *device,
1904aa0a1e58SJeff Roberson 						     u8 port_num);
19050bab509bSHans Petter Selasky 	/* When calling get_netdev, the HW vendor's driver should return the
1906478d3005SHans Petter Selasky 	 * net device of device @device at port @port_num or NULL if such
1907478d3005SHans Petter Selasky 	 * a net device doesn't exist. The vendor driver should call dev_hold
1908478d3005SHans Petter Selasky 	 * on this net device. The HW vendor's device driver must guarantee
1909478d3005SHans Petter Selasky 	 * that this function returns NULL before the net device reaches
19100bab509bSHans Petter Selasky 	 * NETDEV_UNREGISTER_FINAL state.
19110bab509bSHans Petter Selasky 	 */
19121411f52fSBjoern A. Zeeb 	struct ifnet		  *(*get_netdev)(struct ib_device *device,
19130bab509bSHans Petter Selasky 						 u8 port_num);
1914aa0a1e58SJeff Roberson 	int		           (*query_gid)(struct ib_device *device,
1915aa0a1e58SJeff Roberson 						u8 port_num, int index,
1916aa0a1e58SJeff Roberson 						union ib_gid *gid);
1917478d3005SHans Petter Selasky 	/* When calling add_gid, the HW vendor's driver should
1918478d3005SHans Petter Selasky 	 * add the gid of device @device at gid index @index of
1919478d3005SHans Petter Selasky 	 * port @port_num to be @gid. Meta-info of that gid (for example,
1920478d3005SHans Petter Selasky 	 * the network device related to this gid is available
1921478d3005SHans Petter Selasky 	 * at @attr. @context allows the HW vendor driver to store extra
1922478d3005SHans Petter Selasky 	 * information together with a GID entry. The HW vendor may allocate
1923478d3005SHans Petter Selasky 	 * memory to contain this information and store it in @context when a
1924478d3005SHans Petter Selasky 	 * new GID entry is written to. Params are consistent until the next
1925478d3005SHans Petter Selasky 	 * call of add_gid or delete_gid. The function should return 0 on
1926478d3005SHans Petter Selasky 	 * success or error otherwise. The function could be called
1927478d3005SHans Petter Selasky 	 * concurrently for different ports. This function is only called
1928478d3005SHans Petter Selasky 	 * when roce_gid_table is used.
1929478d3005SHans Petter Selasky 	 */
1930478d3005SHans Petter Selasky 	int		           (*add_gid)(struct ib_device *device,
1931478d3005SHans Petter Selasky 					      u8 port_num,
1932478d3005SHans Petter Selasky 					      unsigned int index,
1933478d3005SHans Petter Selasky 					      const union ib_gid *gid,
1934478d3005SHans Petter Selasky 					      const struct ib_gid_attr *attr,
1935478d3005SHans Petter Selasky 					      void **context);
1936478d3005SHans Petter Selasky 	/* When calling del_gid, the HW vendor's driver should delete the
1937478d3005SHans Petter Selasky 	 * gid of device @device at gid index @index of port @port_num.
1938478d3005SHans Petter Selasky 	 * Upon the deletion of a GID entry, the HW vendor must free any
1939478d3005SHans Petter Selasky 	 * allocated memory. The caller will clear @context afterwards.
1940478d3005SHans Petter Selasky 	 * This function is only called when roce_gid_table is used.
1941478d3005SHans Petter Selasky 	 */
1942478d3005SHans Petter Selasky 	int		           (*del_gid)(struct ib_device *device,
1943478d3005SHans Petter Selasky 					      u8 port_num,
1944478d3005SHans Petter Selasky 					      unsigned int index,
1945478d3005SHans Petter Selasky 					      void **context);
1946aa0a1e58SJeff Roberson 	int		           (*query_pkey)(struct ib_device *device,
1947aa0a1e58SJeff Roberson 						 u8 port_num, u16 index, u16 *pkey);
1948aa0a1e58SJeff Roberson 	int		           (*modify_device)(struct ib_device *device,
1949aa0a1e58SJeff Roberson 						    int device_modify_mask,
1950aa0a1e58SJeff Roberson 						    struct ib_device_modify *device_modify);
1951aa0a1e58SJeff Roberson 	int		           (*modify_port)(struct ib_device *device,
1952aa0a1e58SJeff Roberson 						  u8 port_num, int port_modify_mask,
1953aa0a1e58SJeff Roberson 						  struct ib_port_modify *port_modify);
1954aa0a1e58SJeff Roberson 	struct ib_ucontext *       (*alloc_ucontext)(struct ib_device *device,
1955aa0a1e58SJeff Roberson 						     struct ib_udata *udata);
1956aa0a1e58SJeff Roberson 	int                        (*dealloc_ucontext)(struct ib_ucontext *context);
1957aa0a1e58SJeff Roberson 	int                        (*mmap)(struct ib_ucontext *context,
1958aa0a1e58SJeff Roberson 					   struct vm_area_struct *vma);
1959aa0a1e58SJeff Roberson 	struct ib_pd *             (*alloc_pd)(struct ib_device *device,
1960aa0a1e58SJeff Roberson 					       struct ib_ucontext *context,
1961aa0a1e58SJeff Roberson 					       struct ib_udata *udata);
1962aa0a1e58SJeff Roberson 	int                        (*dealloc_pd)(struct ib_pd *pd);
1963aa0a1e58SJeff Roberson 	struct ib_ah *             (*create_ah)(struct ib_pd *pd,
19641456d97cSHans Petter Selasky 						struct ib_ah_attr *ah_attr,
19651456d97cSHans Petter Selasky 						struct ib_udata *udata);
1966aa0a1e58SJeff Roberson 	int                        (*modify_ah)(struct ib_ah *ah,
1967aa0a1e58SJeff Roberson 						struct ib_ah_attr *ah_attr);
1968aa0a1e58SJeff Roberson 	int                        (*query_ah)(struct ib_ah *ah,
1969aa0a1e58SJeff Roberson 					       struct ib_ah_attr *ah_attr);
1970aa0a1e58SJeff Roberson 	int                        (*destroy_ah)(struct ib_ah *ah);
1971aa0a1e58SJeff Roberson 	struct ib_srq *            (*create_srq)(struct ib_pd *pd,
1972aa0a1e58SJeff Roberson 						 struct ib_srq_init_attr *srq_init_attr,
1973aa0a1e58SJeff Roberson 						 struct ib_udata *udata);
1974aa0a1e58SJeff Roberson 	int                        (*modify_srq)(struct ib_srq *srq,
1975aa0a1e58SJeff Roberson 						 struct ib_srq_attr *srq_attr,
1976aa0a1e58SJeff Roberson 						 enum ib_srq_attr_mask srq_attr_mask,
1977aa0a1e58SJeff Roberson 						 struct ib_udata *udata);
1978aa0a1e58SJeff Roberson 	int                        (*query_srq)(struct ib_srq *srq,
1979aa0a1e58SJeff Roberson 						struct ib_srq_attr *srq_attr);
1980aa0a1e58SJeff Roberson 	int                        (*destroy_srq)(struct ib_srq *srq);
1981aa0a1e58SJeff Roberson 	int                        (*post_srq_recv)(struct ib_srq *srq,
1982aa0a1e58SJeff Roberson 						    struct ib_recv_wr *recv_wr,
1983aa0a1e58SJeff Roberson 						    struct ib_recv_wr **bad_recv_wr);
1984aa0a1e58SJeff Roberson 	struct ib_qp *             (*create_qp)(struct ib_pd *pd,
1985aa0a1e58SJeff Roberson 						struct ib_qp_init_attr *qp_init_attr,
1986aa0a1e58SJeff Roberson 						struct ib_udata *udata);
1987aa0a1e58SJeff Roberson 	int                        (*modify_qp)(struct ib_qp *qp,
1988aa0a1e58SJeff Roberson 						struct ib_qp_attr *qp_attr,
1989aa0a1e58SJeff Roberson 						int qp_attr_mask,
1990aa0a1e58SJeff Roberson 						struct ib_udata *udata);
1991aa0a1e58SJeff Roberson 	int                        (*query_qp)(struct ib_qp *qp,
1992aa0a1e58SJeff Roberson 					       struct ib_qp_attr *qp_attr,
1993aa0a1e58SJeff Roberson 					       int qp_attr_mask,
1994aa0a1e58SJeff Roberson 					       struct ib_qp_init_attr *qp_init_attr);
1995aa0a1e58SJeff Roberson 	int                        (*destroy_qp)(struct ib_qp *qp);
1996aa0a1e58SJeff Roberson 	int                        (*post_send)(struct ib_qp *qp,
1997aa0a1e58SJeff Roberson 						struct ib_send_wr *send_wr,
1998aa0a1e58SJeff Roberson 						struct ib_send_wr **bad_send_wr);
1999aa0a1e58SJeff Roberson 	int                        (*post_recv)(struct ib_qp *qp,
2000aa0a1e58SJeff Roberson 						struct ib_recv_wr *recv_wr,
2001aa0a1e58SJeff Roberson 						struct ib_recv_wr **bad_recv_wr);
2002b5c1e0cbSHans Petter Selasky 	struct ib_cq *             (*create_cq)(struct ib_device *device,
2003478d3005SHans Petter Selasky 						const struct ib_cq_init_attr *attr,
2004aa0a1e58SJeff Roberson 						struct ib_ucontext *context,
2005aa0a1e58SJeff Roberson 						struct ib_udata *udata);
2006478d3005SHans Petter Selasky 	int                        (*modify_cq)(struct ib_cq *cq, u16 cq_count,
2007478d3005SHans Petter Selasky 						u16 cq_period);
2008aa0a1e58SJeff Roberson 	int                        (*destroy_cq)(struct ib_cq *cq);
2009aa0a1e58SJeff Roberson 	int                        (*resize_cq)(struct ib_cq *cq, int cqe,
2010aa0a1e58SJeff Roberson 						struct ib_udata *udata);
2011aa0a1e58SJeff Roberson 	int                        (*poll_cq)(struct ib_cq *cq, int num_entries,
2012aa0a1e58SJeff Roberson 					      struct ib_wc *wc);
2013aa0a1e58SJeff Roberson 	int                        (*peek_cq)(struct ib_cq *cq, int wc_cnt);
2014aa0a1e58SJeff Roberson 	int                        (*req_notify_cq)(struct ib_cq *cq,
2015aa0a1e58SJeff Roberson 						    enum ib_cq_notify_flags flags);
2016aa0a1e58SJeff Roberson 	int                        (*req_ncomp_notif)(struct ib_cq *cq,
2017aa0a1e58SJeff Roberson 						      int wc_cnt);
2018aa0a1e58SJeff Roberson 	struct ib_mr *             (*get_dma_mr)(struct ib_pd *pd,
2019aa0a1e58SJeff Roberson 						 int mr_access_flags);
2020aa0a1e58SJeff Roberson 	struct ib_mr *             (*reg_user_mr)(struct ib_pd *pd,
2021aa0a1e58SJeff Roberson 						  u64 start, u64 length,
2022aa0a1e58SJeff Roberson 						  u64 virt_addr,
2023aa0a1e58SJeff Roberson 						  int mr_access_flags,
2024478d3005SHans Petter Selasky 						  struct ib_udata *udata);
2025478d3005SHans Petter Selasky 	int			   (*rereg_user_mr)(struct ib_mr *mr,
2026478d3005SHans Petter Selasky 						    int flags,
2027478d3005SHans Petter Selasky 						    u64 start, u64 length,
2028478d3005SHans Petter Selasky 						    u64 virt_addr,
2029aa0a1e58SJeff Roberson 						    int mr_access_flags,
2030478d3005SHans Petter Selasky 						    struct ib_pd *pd,
2031478d3005SHans Petter Selasky 						    struct ib_udata *udata);
2032478d3005SHans Petter Selasky 	int                        (*dereg_mr)(struct ib_mr *mr);
2033478d3005SHans Petter Selasky 	struct ib_mr *		   (*alloc_mr)(struct ib_pd *pd,
2034478d3005SHans Petter Selasky 					       enum ib_mr_type mr_type,
2035478d3005SHans Petter Selasky 					       u32 max_num_sg);
2036478d3005SHans Petter Selasky 	int                        (*map_mr_sg)(struct ib_mr *mr,
2037478d3005SHans Petter Selasky 						struct scatterlist *sg,
2038478d3005SHans Petter Selasky 						int sg_nents,
2039478d3005SHans Petter Selasky 						unsigned int *sg_offset);
2040b5c1e0cbSHans Petter Selasky 	struct ib_mw *             (*alloc_mw)(struct ib_pd *pd,
2041478d3005SHans Petter Selasky 					       enum ib_mw_type type,
2042478d3005SHans Petter Selasky 					       struct ib_udata *udata);
2043aa0a1e58SJeff Roberson 	int                        (*dealloc_mw)(struct ib_mw *mw);
2044aa0a1e58SJeff Roberson 	struct ib_fmr *	           (*alloc_fmr)(struct ib_pd *pd,
2045aa0a1e58SJeff Roberson 						int mr_access_flags,
2046aa0a1e58SJeff Roberson 						struct ib_fmr_attr *fmr_attr);
2047aa0a1e58SJeff Roberson 	int		           (*map_phys_fmr)(struct ib_fmr *fmr,
2048aa0a1e58SJeff Roberson 						   u64 *page_list, int list_len,
2049aa0a1e58SJeff Roberson 						   u64 iova);
2050aa0a1e58SJeff Roberson 	int		           (*unmap_fmr)(struct list_head *fmr_list);
2051aa0a1e58SJeff Roberson 	int		           (*dealloc_fmr)(struct ib_fmr *fmr);
2052aa0a1e58SJeff Roberson 	int                        (*attach_mcast)(struct ib_qp *qp,
2053aa0a1e58SJeff Roberson 						   union ib_gid *gid,
2054aa0a1e58SJeff Roberson 						   u16 lid);
2055aa0a1e58SJeff Roberson 	int                        (*detach_mcast)(struct ib_qp *qp,
2056aa0a1e58SJeff Roberson 						   union ib_gid *gid,
2057aa0a1e58SJeff Roberson 						   u16 lid);
2058aa0a1e58SJeff Roberson 	int                        (*process_mad)(struct ib_device *device,
2059aa0a1e58SJeff Roberson 						  int process_mad_flags,
2060aa0a1e58SJeff Roberson 						  u8 port_num,
2061478d3005SHans Petter Selasky 						  const struct ib_wc *in_wc,
2062478d3005SHans Petter Selasky 						  const struct ib_grh *in_grh,
2063478d3005SHans Petter Selasky 						  const struct ib_mad_hdr *in_mad,
2064478d3005SHans Petter Selasky 						  size_t in_mad_size,
2065478d3005SHans Petter Selasky 						  struct ib_mad_hdr *out_mad,
2066478d3005SHans Petter Selasky 						  size_t *out_mad_size,
2067478d3005SHans Petter Selasky 						  u16 *out_mad_pkey_index);
2068aa0a1e58SJeff Roberson 	struct ib_xrcd *	   (*alloc_xrcd)(struct ib_device *device,
2069c9f432b7SAlfred Perlstein 						 struct ib_ucontext *ucontext,
2070aa0a1e58SJeff Roberson 						 struct ib_udata *udata);
2071aa0a1e58SJeff Roberson 	int			   (*dealloc_xrcd)(struct ib_xrcd *xrcd);
2072b5c1e0cbSHans Petter Selasky 	struct ib_flow *	   (*create_flow)(struct ib_qp *qp,
2073b5c1e0cbSHans Petter Selasky 						  struct ib_flow_attr
2074b5c1e0cbSHans Petter Selasky 						  *flow_attr,
2075b5c1e0cbSHans Petter Selasky 						  int domain);
2076b5c1e0cbSHans Petter Selasky 	int			   (*destroy_flow)(struct ib_flow *flow_id);
2077b5c1e0cbSHans Petter Selasky 	int			   (*check_mr_status)(struct ib_mr *mr, u32 check_mask,
2078b5c1e0cbSHans Petter Selasky 						      struct ib_mr_status *mr_status);
2079478d3005SHans Petter Selasky 	void			   (*disassociate_ucontext)(struct ib_ucontext *ibcontext);
2080478d3005SHans Petter Selasky 	void			   (*drain_rq)(struct ib_qp *qp);
2081478d3005SHans Petter Selasky 	void			   (*drain_sq)(struct ib_qp *qp);
2082478d3005SHans Petter Selasky 	int			   (*set_vf_link_state)(struct ib_device *device, int vf, u8 port,
2083478d3005SHans Petter Selasky 							int state);
2084478d3005SHans Petter Selasky 	int			   (*get_vf_config)(struct ib_device *device, int vf, u8 port,
2085478d3005SHans Petter Selasky 						   struct ifla_vf_info *ivf);
2086478d3005SHans Petter Selasky 	int			   (*get_vf_stats)(struct ib_device *device, int vf, u8 port,
2087478d3005SHans Petter Selasky 						   struct ifla_vf_stats *stats);
2088478d3005SHans Petter Selasky 	int			   (*set_vf_guid)(struct ib_device *device, int vf, u8 port, u64 guid,
2089478d3005SHans Petter Selasky 						  int type);
2090478d3005SHans Petter Selasky 	struct ib_wq *		   (*create_wq)(struct ib_pd *pd,
2091478d3005SHans Petter Selasky 						struct ib_wq_init_attr *init_attr,
2092478d3005SHans Petter Selasky 						struct ib_udata *udata);
2093478d3005SHans Petter Selasky 	int			   (*destroy_wq)(struct ib_wq *wq);
2094478d3005SHans Petter Selasky 	int			   (*modify_wq)(struct ib_wq *wq,
2095478d3005SHans Petter Selasky 						struct ib_wq_attr *attr,
2096478d3005SHans Petter Selasky 						u32 wq_attr_mask,
2097478d3005SHans Petter Selasky 						struct ib_udata *udata);
2098478d3005SHans Petter Selasky 	struct ib_rwq_ind_table *  (*create_rwq_ind_table)(struct ib_device *device,
2099478d3005SHans Petter Selasky 							   struct ib_rwq_ind_table_init_attr *init_attr,
2100478d3005SHans Petter Selasky 							   struct ib_udata *udata);
2101478d3005SHans Petter Selasky 	int                        (*destroy_rwq_ind_table)(struct ib_rwq_ind_table *wq_ind_table);
2102aa0a1e58SJeff Roberson 	struct ib_dma_mapping_ops   *dma_ops;
2103aa0a1e58SJeff Roberson 
2104aa0a1e58SJeff Roberson 	struct module               *owner;
2105aa0a1e58SJeff Roberson 	struct device                dev;
2106aa0a1e58SJeff Roberson 	struct kobject               *ports_parent;
2107aa0a1e58SJeff Roberson 	struct list_head             port_list;
2108aa0a1e58SJeff Roberson 
2109aa0a1e58SJeff Roberson 	enum {
2110aa0a1e58SJeff Roberson 		IB_DEV_UNINITIALIZED,
2111aa0a1e58SJeff Roberson 		IB_DEV_REGISTERED,
2112aa0a1e58SJeff Roberson 		IB_DEV_UNREGISTERED
2113aa0a1e58SJeff Roberson 	}                            reg_state;
2114aa0a1e58SJeff Roberson 
2115aa0a1e58SJeff Roberson 	int			     uverbs_abi_ver;
2116c9f432b7SAlfred Perlstein 	u64			     uverbs_cmd_mask;
2117b5c1e0cbSHans Petter Selasky 	u64			     uverbs_ex_cmd_mask;
2118aa0a1e58SJeff Roberson 
2119478d3005SHans Petter Selasky 	char			     node_desc[IB_DEVICE_NODE_DESC_MAX];
2120aa0a1e58SJeff Roberson 	__be64			     node_guid;
2121aa0a1e58SJeff Roberson 	u32			     local_dma_lkey;
2122478d3005SHans Petter Selasky 	u16                          is_switch:1;
2123aa0a1e58SJeff Roberson 	u8                           node_type;
2124aa0a1e58SJeff Roberson 	u8                           phys_port_cnt;
2125478d3005SHans Petter Selasky 	struct ib_device_attr        attrs;
2126478d3005SHans Petter Selasky 	struct attribute_group	     *hw_stats_ag;
2127478d3005SHans Petter Selasky 	struct rdma_hw_stats         *hw_stats;
2128b5c1e0cbSHans Petter Selasky 
2129478d3005SHans Petter Selasky 	/**
2130478d3005SHans Petter Selasky 	 * The following mandatory functions are used only at device
2131478d3005SHans Petter Selasky 	 * registration.  Keep functions such as these at the end of this
2132478d3005SHans Petter Selasky 	 * structure to avoid cache line misses when accessing struct ib_device
2133478d3005SHans Petter Selasky 	 * in fast paths.
2134b5c1e0cbSHans Petter Selasky 	 */
2135478d3005SHans Petter Selasky 	int (*get_port_immutable)(struct ib_device *, u8, struct ib_port_immutable *);
2136478d3005SHans Petter Selasky 	void (*get_dev_fw_str)(struct ib_device *, char *str, size_t str_len);
2137aa0a1e58SJeff Roberson };
2138aa0a1e58SJeff Roberson 
2139aa0a1e58SJeff Roberson struct ib_client {
2140aa0a1e58SJeff Roberson 	char  *name;
2141aa0a1e58SJeff Roberson 	void (*add)   (struct ib_device *);
2142478d3005SHans Petter Selasky 	void (*remove)(struct ib_device *, void *client_data);
2143aa0a1e58SJeff Roberson 
2144478d3005SHans Petter Selasky 	/* Returns the net_dev belonging to this ib_client and matching the
2145478d3005SHans Petter Selasky 	 * given parameters.
2146478d3005SHans Petter Selasky 	 * @dev:	 An RDMA device that the net_dev use for communication.
2147478d3005SHans Petter Selasky 	 * @port:	 A physical port number on the RDMA device.
2148478d3005SHans Petter Selasky 	 * @pkey:	 P_Key that the net_dev uses if applicable.
2149478d3005SHans Petter Selasky 	 * @gid:	 A GID that the net_dev uses to communicate.
2150478d3005SHans Petter Selasky 	 * @addr:	 An IP address the net_dev is configured with.
2151478d3005SHans Petter Selasky 	 * @client_data: The device's client data set by ib_set_client_data().
2152478d3005SHans Petter Selasky 	 *
2153478d3005SHans Petter Selasky 	 * An ib_client that implements a net_dev on top of RDMA devices
2154478d3005SHans Petter Selasky 	 * (such as IP over IB) should implement this callback, allowing the
2155478d3005SHans Petter Selasky 	 * rdma_cm module to find the right net_dev for a given request.
2156478d3005SHans Petter Selasky 	 *
2157478d3005SHans Petter Selasky 	 * The caller is responsible for calling dev_put on the returned
2158478d3005SHans Petter Selasky 	 * netdev. */
21591411f52fSBjoern A. Zeeb 	struct ifnet *(*get_net_dev_by_params)(
2160478d3005SHans Petter Selasky 			struct ib_device *dev,
2161478d3005SHans Petter Selasky 			u8 port,
2162478d3005SHans Petter Selasky 			u16 pkey,
2163478d3005SHans Petter Selasky 			const union ib_gid *gid,
2164478d3005SHans Petter Selasky 			const struct sockaddr *addr,
2165478d3005SHans Petter Selasky 			void *client_data);
2166aa0a1e58SJeff Roberson 	struct list_head list;
2167aa0a1e58SJeff Roberson };
2168aa0a1e58SJeff Roberson 
2169aa0a1e58SJeff Roberson struct ib_device *ib_alloc_device(size_t size);
2170aa0a1e58SJeff Roberson void ib_dealloc_device(struct ib_device *device);
2171aa0a1e58SJeff Roberson 
2172478d3005SHans Petter Selasky void ib_get_device_fw_str(struct ib_device *device, char *str, size_t str_len);
2173478d3005SHans Petter Selasky 
2174c9f432b7SAlfred Perlstein int ib_register_device(struct ib_device *device,
2175c9f432b7SAlfred Perlstein 		       int (*port_callback)(struct ib_device *,
2176c9f432b7SAlfred Perlstein 					    u8, struct kobject *));
2177aa0a1e58SJeff Roberson void ib_unregister_device(struct ib_device *device);
2178aa0a1e58SJeff Roberson 
2179aa0a1e58SJeff Roberson int ib_register_client   (struct ib_client *client);
2180aa0a1e58SJeff Roberson void ib_unregister_client(struct ib_client *client);
2181aa0a1e58SJeff Roberson 
2182aa0a1e58SJeff Roberson void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
2183aa0a1e58SJeff Roberson void  ib_set_client_data(struct ib_device *device, struct ib_client *client,
2184aa0a1e58SJeff Roberson 			 void *data);
2185aa0a1e58SJeff Roberson 
2186aa0a1e58SJeff Roberson static inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
2187aa0a1e58SJeff Roberson {
2188478d3005SHans Petter Selasky 	return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
2189aa0a1e58SJeff Roberson }
2190aa0a1e58SJeff Roberson 
2191aa0a1e58SJeff Roberson static inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
2192aa0a1e58SJeff Roberson {
2193478d3005SHans Petter Selasky 	return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
2194478d3005SHans Petter Selasky }
2195478d3005SHans Petter Selasky 
2196478d3005SHans Petter Selasky static inline bool ib_is_udata_cleared(struct ib_udata *udata,
2197478d3005SHans Petter Selasky 				       size_t offset,
2198478d3005SHans Petter Selasky 				       size_t len)
2199478d3005SHans Petter Selasky {
2200478d3005SHans Petter Selasky 	const void __user *p = (const char __user *)udata->inbuf + offset;
2201478d3005SHans Petter Selasky 	bool ret;
2202478d3005SHans Petter Selasky 	u8 *buf;
2203478d3005SHans Petter Selasky 
2204478d3005SHans Petter Selasky 	if (len > USHRT_MAX)
2205478d3005SHans Petter Selasky 		return false;
2206478d3005SHans Petter Selasky 
2207478d3005SHans Petter Selasky 	buf = memdup_user(p, len);
2208478d3005SHans Petter Selasky 	if (IS_ERR(buf))
2209478d3005SHans Petter Selasky 		return false;
2210478d3005SHans Petter Selasky 
2211478d3005SHans Petter Selasky 	ret = !memchr_inv(buf, 0, len);
2212478d3005SHans Petter Selasky 	kfree(buf);
2213478d3005SHans Petter Selasky 	return ret;
2214aa0a1e58SJeff Roberson }
2215aa0a1e58SJeff Roberson 
2216aa0a1e58SJeff Roberson /**
2217aa0a1e58SJeff Roberson  * ib_modify_qp_is_ok - Check that the supplied attribute mask
2218aa0a1e58SJeff Roberson  * contains all required attributes and no attributes not allowed for
2219aa0a1e58SJeff Roberson  * the given QP state transition.
2220aa0a1e58SJeff Roberson  * @cur_state: Current QP state
2221aa0a1e58SJeff Roberson  * @next_state: Next QP state
2222aa0a1e58SJeff Roberson  * @type: QP type
2223aa0a1e58SJeff Roberson  * @mask: Mask of supplied QP attributes
2224aa0a1e58SJeff Roberson  *
2225aa0a1e58SJeff Roberson  * This function is a helper function that a low-level driver's
2226aa0a1e58SJeff Roberson  * modify_qp method can use to validate the consumer's input.  It
2227aa0a1e58SJeff Roberson  * checks that cur_state and next_state are valid QP states, that a
2228aa0a1e58SJeff Roberson  * transition from cur_state to next_state is allowed by the IB spec,
2229aa0a1e58SJeff Roberson  * and that the attribute mask supplied is allowed for the transition.
2230aa0a1e58SJeff Roberson  */
2231d92a9e56SHans Petter Selasky bool ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
2232d92a9e56SHans Petter Selasky 			enum ib_qp_type type, enum ib_qp_attr_mask mask);
2233aa0a1e58SJeff Roberson 
2234aa0a1e58SJeff Roberson int ib_register_event_handler  (struct ib_event_handler *event_handler);
2235aa0a1e58SJeff Roberson int ib_unregister_event_handler(struct ib_event_handler *event_handler);
2236aa0a1e58SJeff Roberson void ib_dispatch_event(struct ib_event *event);
2237aa0a1e58SJeff Roberson 
2238aa0a1e58SJeff Roberson int ib_query_port(struct ib_device *device,
2239aa0a1e58SJeff Roberson 		  u8 port_num, struct ib_port_attr *port_attr);
2240aa0a1e58SJeff Roberson 
2241aa0a1e58SJeff Roberson enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
2242aa0a1e58SJeff Roberson 					       u8 port_num);
2243aa0a1e58SJeff Roberson 
2244478d3005SHans Petter Selasky /**
2245478d3005SHans Petter Selasky  * rdma_cap_ib_switch - Check if the device is IB switch
2246478d3005SHans Petter Selasky  * @device: Device to check
2247478d3005SHans Petter Selasky  *
2248478d3005SHans Petter Selasky  * Device driver is responsible for setting is_switch bit on
2249478d3005SHans Petter Selasky  * in ib_device structure at init time.
2250478d3005SHans Petter Selasky  *
2251478d3005SHans Petter Selasky  * Return: true if the device is IB switch.
2252478d3005SHans Petter Selasky  */
2253478d3005SHans Petter Selasky static inline bool rdma_cap_ib_switch(const struct ib_device *device)
2254478d3005SHans Petter Selasky {
2255478d3005SHans Petter Selasky 	return device->is_switch;
2256478d3005SHans Petter Selasky }
2257478d3005SHans Petter Selasky 
2258478d3005SHans Petter Selasky /**
2259478d3005SHans Petter Selasky  * rdma_start_port - Return the first valid port number for the device
2260478d3005SHans Petter Selasky  * specified
2261478d3005SHans Petter Selasky  *
2262478d3005SHans Petter Selasky  * @device: Device to be checked
2263478d3005SHans Petter Selasky  *
2264478d3005SHans Petter Selasky  * Return start port number
2265478d3005SHans Petter Selasky  */
2266478d3005SHans Petter Selasky static inline u8 rdma_start_port(const struct ib_device *device)
2267478d3005SHans Petter Selasky {
2268478d3005SHans Petter Selasky 	return rdma_cap_ib_switch(device) ? 0 : 1;
2269478d3005SHans Petter Selasky }
2270478d3005SHans Petter Selasky 
2271478d3005SHans Petter Selasky /**
2272478d3005SHans Petter Selasky  * rdma_end_port - Return the last valid port number for the device
2273478d3005SHans Petter Selasky  * specified
2274478d3005SHans Petter Selasky  *
2275478d3005SHans Petter Selasky  * @device: Device to be checked
2276478d3005SHans Petter Selasky  *
2277478d3005SHans Petter Selasky  * Return last port number
2278478d3005SHans Petter Selasky  */
2279478d3005SHans Petter Selasky static inline u8 rdma_end_port(const struct ib_device *device)
2280478d3005SHans Petter Selasky {
2281478d3005SHans Petter Selasky 	return rdma_cap_ib_switch(device) ? 0 : device->phys_port_cnt;
2282478d3005SHans Petter Selasky }
2283478d3005SHans Petter Selasky 
2284f736cb92SHans Petter Selasky static inline int rdma_is_port_valid(const struct ib_device *device,
2285f736cb92SHans Petter Selasky 				     unsigned int port)
2286f736cb92SHans Petter Selasky {
2287f736cb92SHans Petter Selasky 	return (port >= rdma_start_port(device) &&
2288f736cb92SHans Petter Selasky 		port <= rdma_end_port(device));
2289f736cb92SHans Petter Selasky }
2290f736cb92SHans Petter Selasky 
2291478d3005SHans Petter Selasky static inline bool rdma_protocol_ib(const struct ib_device *device, u8 port_num)
2292478d3005SHans Petter Selasky {
2293478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IB;
2294478d3005SHans Petter Selasky }
2295478d3005SHans Petter Selasky 
2296478d3005SHans Petter Selasky static inline bool rdma_protocol_roce(const struct ib_device *device, u8 port_num)
2297478d3005SHans Petter Selasky {
2298478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags &
2299478d3005SHans Petter Selasky 		(RDMA_CORE_CAP_PROT_ROCE | RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP);
2300478d3005SHans Petter Selasky }
2301478d3005SHans Petter Selasky 
2302478d3005SHans Petter Selasky static inline bool rdma_protocol_roce_udp_encap(const struct ib_device *device, u8 port_num)
2303478d3005SHans Petter Selasky {
2304478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP;
2305478d3005SHans Petter Selasky }
2306478d3005SHans Petter Selasky 
2307478d3005SHans Petter Selasky static inline bool rdma_protocol_roce_eth_encap(const struct ib_device *device, u8 port_num)
2308478d3005SHans Petter Selasky {
2309478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_ROCE;
2310478d3005SHans Petter Selasky }
2311478d3005SHans Petter Selasky 
2312478d3005SHans Petter Selasky static inline bool rdma_protocol_iwarp(const struct ib_device *device, u8 port_num)
2313478d3005SHans Petter Selasky {
2314478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_PROT_IWARP;
2315478d3005SHans Petter Selasky }
2316478d3005SHans Petter Selasky 
2317478d3005SHans Petter Selasky static inline bool rdma_ib_or_roce(const struct ib_device *device, u8 port_num)
2318478d3005SHans Petter Selasky {
2319478d3005SHans Petter Selasky 	return rdma_protocol_ib(device, port_num) ||
2320478d3005SHans Petter Selasky 		rdma_protocol_roce(device, port_num);
2321478d3005SHans Petter Selasky }
2322478d3005SHans Petter Selasky 
2323478d3005SHans Petter Selasky /**
2324478d3005SHans Petter Selasky  * rdma_cap_ib_mad - Check if the port of a device supports Infiniband
2325478d3005SHans Petter Selasky  * Management Datagrams.
2326478d3005SHans Petter Selasky  * @device: Device to check
2327478d3005SHans Petter Selasky  * @port_num: Port number to check
2328478d3005SHans Petter Selasky  *
2329478d3005SHans Petter Selasky  * Management Datagrams (MAD) are a required part of the InfiniBand
2330478d3005SHans Petter Selasky  * specification and are supported on all InfiniBand devices.  A slightly
2331478d3005SHans Petter Selasky  * extended version are also supported on OPA interfaces.
2332478d3005SHans Petter Selasky  *
2333478d3005SHans Petter Selasky  * Return: true if the port supports sending/receiving of MAD packets.
2334478d3005SHans Petter Selasky  */
2335478d3005SHans Petter Selasky static inline bool rdma_cap_ib_mad(const struct ib_device *device, u8 port_num)
2336478d3005SHans Petter Selasky {
2337478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_MAD;
2338478d3005SHans Petter Selasky }
2339478d3005SHans Petter Selasky 
2340478d3005SHans Petter Selasky /**
2341478d3005SHans Petter Selasky  * rdma_cap_opa_mad - Check if the port of device provides support for OPA
2342478d3005SHans Petter Selasky  * Management Datagrams.
2343478d3005SHans Petter Selasky  * @device: Device to check
2344478d3005SHans Petter Selasky  * @port_num: Port number to check
2345478d3005SHans Petter Selasky  *
2346478d3005SHans Petter Selasky  * Intel OmniPath devices extend and/or replace the InfiniBand Management
2347478d3005SHans Petter Selasky  * datagrams with their own versions.  These OPA MADs share many but not all of
2348478d3005SHans Petter Selasky  * the characteristics of InfiniBand MADs.
2349478d3005SHans Petter Selasky  *
2350478d3005SHans Petter Selasky  * OPA MADs differ in the following ways:
2351478d3005SHans Petter Selasky  *
2352478d3005SHans Petter Selasky  *    1) MADs are variable size up to 2K
2353478d3005SHans Petter Selasky  *       IBTA defined MADs remain fixed at 256 bytes
2354478d3005SHans Petter Selasky  *    2) OPA SMPs must carry valid PKeys
2355478d3005SHans Petter Selasky  *    3) OPA SMP packets are a different format
2356478d3005SHans Petter Selasky  *
2357478d3005SHans Petter Selasky  * Return: true if the port supports OPA MAD packet formats.
2358478d3005SHans Petter Selasky  */
2359478d3005SHans Petter Selasky static inline bool rdma_cap_opa_mad(struct ib_device *device, u8 port_num)
2360478d3005SHans Petter Selasky {
2361478d3005SHans Petter Selasky 	return (device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_OPA_MAD)
2362478d3005SHans Petter Selasky 		== RDMA_CORE_CAP_OPA_MAD;
2363478d3005SHans Petter Selasky }
2364478d3005SHans Petter Selasky 
2365478d3005SHans Petter Selasky /**
2366478d3005SHans Petter Selasky  * rdma_cap_ib_smi - Check if the port of a device provides an Infiniband
2367478d3005SHans Petter Selasky  * Subnet Management Agent (SMA) on the Subnet Management Interface (SMI).
2368478d3005SHans Petter Selasky  * @device: Device to check
2369478d3005SHans Petter Selasky  * @port_num: Port number to check
2370478d3005SHans Petter Selasky  *
2371478d3005SHans Petter Selasky  * Each InfiniBand node is required to provide a Subnet Management Agent
2372478d3005SHans Petter Selasky  * that the subnet manager can access.  Prior to the fabric being fully
2373478d3005SHans Petter Selasky  * configured by the subnet manager, the SMA is accessed via a well known
2374478d3005SHans Petter Selasky  * interface called the Subnet Management Interface (SMI).  This interface
2375478d3005SHans Petter Selasky  * uses directed route packets to communicate with the SM to get around the
2376478d3005SHans Petter Selasky  * chicken and egg problem of the SM needing to know what's on the fabric
2377478d3005SHans Petter Selasky  * in order to configure the fabric, and needing to configure the fabric in
2378478d3005SHans Petter Selasky  * order to send packets to the devices on the fabric.  These directed
2379478d3005SHans Petter Selasky  * route packets do not need the fabric fully configured in order to reach
2380478d3005SHans Petter Selasky  * their destination.  The SMI is the only method allowed to send
2381478d3005SHans Petter Selasky  * directed route packets on an InfiniBand fabric.
2382478d3005SHans Petter Selasky  *
2383478d3005SHans Petter Selasky  * Return: true if the port provides an SMI.
2384478d3005SHans Petter Selasky  */
2385478d3005SHans Petter Selasky static inline bool rdma_cap_ib_smi(const struct ib_device *device, u8 port_num)
2386478d3005SHans Petter Selasky {
2387478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SMI;
2388478d3005SHans Petter Selasky }
2389478d3005SHans Petter Selasky 
2390478d3005SHans Petter Selasky /**
2391478d3005SHans Petter Selasky  * rdma_cap_ib_cm - Check if the port of device has the capability Infiniband
2392478d3005SHans Petter Selasky  * Communication Manager.
2393478d3005SHans Petter Selasky  * @device: Device to check
2394478d3005SHans Petter Selasky  * @port_num: Port number to check
2395478d3005SHans Petter Selasky  *
2396478d3005SHans Petter Selasky  * The InfiniBand Communication Manager is one of many pre-defined General
2397478d3005SHans Petter Selasky  * Service Agents (GSA) that are accessed via the General Service
2398478d3005SHans Petter Selasky  * Interface (GSI).  It's role is to facilitate establishment of connections
2399478d3005SHans Petter Selasky  * between nodes as well as other management related tasks for established
2400478d3005SHans Petter Selasky  * connections.
2401478d3005SHans Petter Selasky  *
2402478d3005SHans Petter Selasky  * Return: true if the port supports an IB CM (this does not guarantee that
2403478d3005SHans Petter Selasky  * a CM is actually running however).
2404478d3005SHans Petter Selasky  */
2405478d3005SHans Petter Selasky static inline bool rdma_cap_ib_cm(const struct ib_device *device, u8 port_num)
2406478d3005SHans Petter Selasky {
2407478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_CM;
2408478d3005SHans Petter Selasky }
2409478d3005SHans Petter Selasky 
2410478d3005SHans Petter Selasky /**
2411478d3005SHans Petter Selasky  * rdma_cap_iw_cm - Check if the port of device has the capability IWARP
2412478d3005SHans Petter Selasky  * Communication Manager.
2413478d3005SHans Petter Selasky  * @device: Device to check
2414478d3005SHans Petter Selasky  * @port_num: Port number to check
2415478d3005SHans Petter Selasky  *
2416478d3005SHans Petter Selasky  * Similar to above, but specific to iWARP connections which have a different
2417478d3005SHans Petter Selasky  * managment protocol than InfiniBand.
2418478d3005SHans Petter Selasky  *
2419478d3005SHans Petter Selasky  * Return: true if the port supports an iWARP CM (this does not guarantee that
2420478d3005SHans Petter Selasky  * a CM is actually running however).
2421478d3005SHans Petter Selasky  */
2422478d3005SHans Petter Selasky static inline bool rdma_cap_iw_cm(const struct ib_device *device, u8 port_num)
2423478d3005SHans Petter Selasky {
2424478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IW_CM;
2425478d3005SHans Petter Selasky }
2426478d3005SHans Petter Selasky 
2427478d3005SHans Petter Selasky /**
2428478d3005SHans Petter Selasky  * rdma_cap_ib_sa - Check if the port of device has the capability Infiniband
2429478d3005SHans Petter Selasky  * Subnet Administration.
2430478d3005SHans Petter Selasky  * @device: Device to check
2431478d3005SHans Petter Selasky  * @port_num: Port number to check
2432478d3005SHans Petter Selasky  *
2433478d3005SHans Petter Selasky  * An InfiniBand Subnet Administration (SA) service is a pre-defined General
2434478d3005SHans Petter Selasky  * Service Agent (GSA) provided by the Subnet Manager (SM).  On InfiniBand
2435478d3005SHans Petter Selasky  * fabrics, devices should resolve routes to other hosts by contacting the
2436478d3005SHans Petter Selasky  * SA to query the proper route.
2437478d3005SHans Petter Selasky  *
2438478d3005SHans Petter Selasky  * Return: true if the port should act as a client to the fabric Subnet
2439478d3005SHans Petter Selasky  * Administration interface.  This does not imply that the SA service is
2440478d3005SHans Petter Selasky  * running locally.
2441478d3005SHans Petter Selasky  */
2442478d3005SHans Petter Selasky static inline bool rdma_cap_ib_sa(const struct ib_device *device, u8 port_num)
2443478d3005SHans Petter Selasky {
2444478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_IB_SA;
2445478d3005SHans Petter Selasky }
2446478d3005SHans Petter Selasky 
2447478d3005SHans Petter Selasky /**
2448478d3005SHans Petter Selasky  * rdma_cap_ib_mcast - Check if the port of device has the capability Infiniband
2449478d3005SHans Petter Selasky  * Multicast.
2450478d3005SHans Petter Selasky  * @device: Device to check
2451478d3005SHans Petter Selasky  * @port_num: Port number to check
2452478d3005SHans Petter Selasky  *
2453478d3005SHans Petter Selasky  * InfiniBand multicast registration is more complex than normal IPv4 or
2454478d3005SHans Petter Selasky  * IPv6 multicast registration.  Each Host Channel Adapter must register
2455478d3005SHans Petter Selasky  * with the Subnet Manager when it wishes to join a multicast group.  It
2456478d3005SHans Petter Selasky  * should do so only once regardless of how many queue pairs it subscribes
2457478d3005SHans Petter Selasky  * to this group.  And it should leave the group only after all queue pairs
2458478d3005SHans Petter Selasky  * attached to the group have been detached.
2459478d3005SHans Petter Selasky  *
2460478d3005SHans Petter Selasky  * Return: true if the port must undertake the additional adminstrative
2461478d3005SHans Petter Selasky  * overhead of registering/unregistering with the SM and tracking of the
2462478d3005SHans Petter Selasky  * total number of queue pairs attached to the multicast group.
2463478d3005SHans Petter Selasky  */
2464478d3005SHans Petter Selasky static inline bool rdma_cap_ib_mcast(const struct ib_device *device, u8 port_num)
2465478d3005SHans Petter Selasky {
2466478d3005SHans Petter Selasky 	return rdma_cap_ib_sa(device, port_num);
2467478d3005SHans Petter Selasky }
2468478d3005SHans Petter Selasky 
2469478d3005SHans Petter Selasky /**
2470478d3005SHans Petter Selasky  * rdma_cap_af_ib - Check if the port of device has the capability
2471478d3005SHans Petter Selasky  * Native Infiniband Address.
2472478d3005SHans Petter Selasky  * @device: Device to check
2473478d3005SHans Petter Selasky  * @port_num: Port number to check
2474478d3005SHans Petter Selasky  *
2475478d3005SHans Petter Selasky  * InfiniBand addressing uses a port's GUID + Subnet Prefix to make a default
2476478d3005SHans Petter Selasky  * GID.  RoCE uses a different mechanism, but still generates a GID via
2477478d3005SHans Petter Selasky  * a prescribed mechanism and port specific data.
2478478d3005SHans Petter Selasky  *
2479478d3005SHans Petter Selasky  * Return: true if the port uses a GID address to identify devices on the
2480478d3005SHans Petter Selasky  * network.
2481478d3005SHans Petter Selasky  */
2482478d3005SHans Petter Selasky static inline bool rdma_cap_af_ib(const struct ib_device *device, u8 port_num)
2483478d3005SHans Petter Selasky {
2484478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_AF_IB;
2485478d3005SHans Petter Selasky }
2486478d3005SHans Petter Selasky 
2487478d3005SHans Petter Selasky /**
2488478d3005SHans Petter Selasky  * rdma_cap_eth_ah - Check if the port of device has the capability
2489478d3005SHans Petter Selasky  * Ethernet Address Handle.
2490478d3005SHans Petter Selasky  * @device: Device to check
2491478d3005SHans Petter Selasky  * @port_num: Port number to check
2492478d3005SHans Petter Selasky  *
2493478d3005SHans Petter Selasky  * RoCE is InfiniBand over Ethernet, and it uses a well defined technique
2494478d3005SHans Petter Selasky  * to fabricate GIDs over Ethernet/IP specific addresses native to the
2495478d3005SHans Petter Selasky  * port.  Normally, packet headers are generated by the sending host
2496478d3005SHans Petter Selasky  * adapter, but when sending connectionless datagrams, we must manually
2497478d3005SHans Petter Selasky  * inject the proper headers for the fabric we are communicating over.
2498478d3005SHans Petter Selasky  *
2499478d3005SHans Petter Selasky  * Return: true if we are running as a RoCE port and must force the
2500478d3005SHans Petter Selasky  * addition of a Global Route Header built from our Ethernet Address
2501478d3005SHans Petter Selasky  * Handle into our header list for connectionless packets.
2502478d3005SHans Petter Selasky  */
2503478d3005SHans Petter Selasky static inline bool rdma_cap_eth_ah(const struct ib_device *device, u8 port_num)
2504478d3005SHans Petter Selasky {
2505478d3005SHans Petter Selasky 	return device->port_immutable[port_num].core_cap_flags & RDMA_CORE_CAP_ETH_AH;
2506478d3005SHans Petter Selasky }
2507478d3005SHans Petter Selasky 
2508478d3005SHans Petter Selasky /**
2509478d3005SHans Petter Selasky  * rdma_max_mad_size - Return the max MAD size required by this RDMA Port.
2510478d3005SHans Petter Selasky  *
2511478d3005SHans Petter Selasky  * @device: Device
2512478d3005SHans Petter Selasky  * @port_num: Port number
2513478d3005SHans Petter Selasky  *
2514478d3005SHans Petter Selasky  * This MAD size includes the MAD headers and MAD payload.  No other headers
2515478d3005SHans Petter Selasky  * are included.
2516478d3005SHans Petter Selasky  *
2517478d3005SHans Petter Selasky  * Return the max MAD size required by the Port.  Will return 0 if the port
2518478d3005SHans Petter Selasky  * does not support MADs
2519478d3005SHans Petter Selasky  */
2520478d3005SHans Petter Selasky static inline size_t rdma_max_mad_size(const struct ib_device *device, u8 port_num)
2521478d3005SHans Petter Selasky {
2522478d3005SHans Petter Selasky 	return device->port_immutable[port_num].max_mad_size;
2523478d3005SHans Petter Selasky }
2524478d3005SHans Petter Selasky 
2525478d3005SHans Petter Selasky /**
2526478d3005SHans Petter Selasky  * rdma_cap_roce_gid_table - Check if the port of device uses roce_gid_table
2527478d3005SHans Petter Selasky  * @device: Device to check
2528478d3005SHans Petter Selasky  * @port_num: Port number to check
2529478d3005SHans Petter Selasky  *
2530478d3005SHans Petter Selasky  * RoCE GID table mechanism manages the various GIDs for a device.
2531478d3005SHans Petter Selasky  *
2532478d3005SHans Petter Selasky  * NOTE: if allocating the port's GID table has failed, this call will still
2533478d3005SHans Petter Selasky  * return true, but any RoCE GID table API will fail.
2534478d3005SHans Petter Selasky  *
2535478d3005SHans Petter Selasky  * Return: true if the port uses RoCE GID table mechanism in order to manage
2536478d3005SHans Petter Selasky  * its GIDs.
2537478d3005SHans Petter Selasky  */
2538478d3005SHans Petter Selasky static inline bool rdma_cap_roce_gid_table(const struct ib_device *device,
2539478d3005SHans Petter Selasky 					   u8 port_num)
2540478d3005SHans Petter Selasky {
2541478d3005SHans Petter Selasky 	return rdma_protocol_roce(device, port_num) &&
2542478d3005SHans Petter Selasky 		device->add_gid && device->del_gid;
2543478d3005SHans Petter Selasky }
2544478d3005SHans Petter Selasky 
2545478d3005SHans Petter Selasky /*
2546478d3005SHans Petter Selasky  * Check if the device supports READ W/ INVALIDATE.
2547478d3005SHans Petter Selasky  */
2548478d3005SHans Petter Selasky static inline bool rdma_cap_read_inv(struct ib_device *dev, u32 port_num)
2549478d3005SHans Petter Selasky {
2550478d3005SHans Petter Selasky 	/*
2551478d3005SHans Petter Selasky 	 * iWarp drivers must support READ W/ INVALIDATE.  No other protocol
2552478d3005SHans Petter Selasky 	 * has support for it yet.
2553478d3005SHans Petter Selasky 	 */
2554478d3005SHans Petter Selasky 	return rdma_protocol_iwarp(dev, port_num);
2555478d3005SHans Petter Selasky }
2556478d3005SHans Petter Selasky 
2557aa0a1e58SJeff Roberson int ib_query_gid(struct ib_device *device,
2558478d3005SHans Petter Selasky 		 u8 port_num, int index, union ib_gid *gid,
2559478d3005SHans Petter Selasky 		 struct ib_gid_attr *attr);
2560478d3005SHans Petter Selasky 
2561478d3005SHans Petter Selasky int ib_set_vf_link_state(struct ib_device *device, int vf, u8 port,
2562478d3005SHans Petter Selasky 			 int state);
2563478d3005SHans Petter Selasky int ib_get_vf_config(struct ib_device *device, int vf, u8 port,
2564478d3005SHans Petter Selasky 		     struct ifla_vf_info *info);
2565478d3005SHans Petter Selasky int ib_get_vf_stats(struct ib_device *device, int vf, u8 port,
2566478d3005SHans Petter Selasky 		    struct ifla_vf_stats *stats);
2567478d3005SHans Petter Selasky int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
2568478d3005SHans Petter Selasky 		   int type);
2569aa0a1e58SJeff Roberson 
2570aa0a1e58SJeff Roberson int ib_query_pkey(struct ib_device *device,
2571aa0a1e58SJeff Roberson 		  u8 port_num, u16 index, u16 *pkey);
2572aa0a1e58SJeff Roberson 
2573aa0a1e58SJeff Roberson int ib_modify_device(struct ib_device *device,
2574aa0a1e58SJeff Roberson 		     int device_modify_mask,
2575aa0a1e58SJeff Roberson 		     struct ib_device_modify *device_modify);
2576aa0a1e58SJeff Roberson 
2577aa0a1e58SJeff Roberson int ib_modify_port(struct ib_device *device,
2578aa0a1e58SJeff Roberson 		   u8 port_num, int port_modify_mask,
2579aa0a1e58SJeff Roberson 		   struct ib_port_modify *port_modify);
2580aa0a1e58SJeff Roberson 
2581aa0a1e58SJeff Roberson int ib_find_gid(struct ib_device *device, union ib_gid *gid,
25821411f52fSBjoern A. Zeeb 		enum ib_gid_type gid_type, struct ifnet *ndev,
2583aa0a1e58SJeff Roberson 		u8 *port_num, u16 *index);
2584aa0a1e58SJeff Roberson 
2585aa0a1e58SJeff Roberson int ib_find_pkey(struct ib_device *device,
2586aa0a1e58SJeff Roberson 		 u8 port_num, u16 pkey, u16 *index);
2587aa0a1e58SJeff Roberson 
2588478d3005SHans Petter Selasky enum ib_pd_flags {
2589478d3005SHans Petter Selasky 	/*
2590478d3005SHans Petter Selasky 	 * Create a memory registration for all memory in the system and place
2591478d3005SHans Petter Selasky 	 * the rkey for it into pd->unsafe_global_rkey.  This can be used by
2592478d3005SHans Petter Selasky 	 * ULPs to avoid the overhead of dynamic MRs.
2593aa0a1e58SJeff Roberson 	 *
2594478d3005SHans Petter Selasky 	 * This flag is generally considered unsafe and must only be used in
2595478d3005SHans Petter Selasky 	 * extremly trusted environments.  Every use of it will log a warning
2596478d3005SHans Petter Selasky 	 * in the kernel log.
2597aa0a1e58SJeff Roberson 	 */
2598478d3005SHans Petter Selasky 	IB_PD_UNSAFE_GLOBAL_RKEY	= 0x01,
2599478d3005SHans Petter Selasky };
2600aa0a1e58SJeff Roberson 
2601478d3005SHans Petter Selasky struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,
2602478d3005SHans Petter Selasky 		const char *caller);
2603478d3005SHans Petter Selasky #define ib_alloc_pd(device, flags) \
2604478d3005SHans Petter Selasky 	__ib_alloc_pd((device), (flags), __func__)
2605478d3005SHans Petter Selasky void ib_dealloc_pd(struct ib_pd *pd);
2606aa0a1e58SJeff Roberson 
2607aa0a1e58SJeff Roberson /**
2608aa0a1e58SJeff Roberson  * ib_create_ah - Creates an address handle for the given address vector.
2609aa0a1e58SJeff Roberson  * @pd: The protection domain associated with the address handle.
2610aa0a1e58SJeff Roberson  * @ah_attr: The attributes of the address vector.
2611aa0a1e58SJeff Roberson  *
2612aa0a1e58SJeff Roberson  * The address handle is used to reference a local or global destination
2613aa0a1e58SJeff Roberson  * in all UD QP post sends.
2614aa0a1e58SJeff Roberson  */
2615aa0a1e58SJeff Roberson struct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
2616aa0a1e58SJeff Roberson 
2617aa0a1e58SJeff Roberson /**
2618aa0a1e58SJeff Roberson  * ib_init_ah_from_wc - Initializes address handle attributes from a
2619aa0a1e58SJeff Roberson  *   work completion.
2620aa0a1e58SJeff Roberson  * @device: Device on which the received message arrived.
2621aa0a1e58SJeff Roberson  * @port_num: Port on which the received message arrived.
2622aa0a1e58SJeff Roberson  * @wc: Work completion associated with the received message.
2623aa0a1e58SJeff Roberson  * @grh: References the received global route header.  This parameter is
2624aa0a1e58SJeff Roberson  *   ignored unless the work completion indicates that the GRH is valid.
2625aa0a1e58SJeff Roberson  * @ah_attr: Returned attributes that can be used when creating an address
2626aa0a1e58SJeff Roberson  *   handle for replying to the message.
2627aa0a1e58SJeff Roberson  */
2628478d3005SHans Petter Selasky int ib_init_ah_from_wc(struct ib_device *device, u8 port_num,
2629478d3005SHans Petter Selasky 		       const struct ib_wc *wc, const struct ib_grh *grh,
2630478d3005SHans Petter Selasky 		       struct ib_ah_attr *ah_attr);
2631aa0a1e58SJeff Roberson 
2632aa0a1e58SJeff Roberson /**
2633aa0a1e58SJeff Roberson  * ib_create_ah_from_wc - Creates an address handle associated with the
2634aa0a1e58SJeff Roberson  *   sender of the specified work completion.
2635aa0a1e58SJeff Roberson  * @pd: The protection domain associated with the address handle.
2636aa0a1e58SJeff Roberson  * @wc: Work completion information associated with a received message.
2637aa0a1e58SJeff Roberson  * @grh: References the received global route header.  This parameter is
2638aa0a1e58SJeff Roberson  *   ignored unless the work completion indicates that the GRH is valid.
2639aa0a1e58SJeff Roberson  * @port_num: The outbound port number to associate with the address.
2640aa0a1e58SJeff Roberson  *
2641aa0a1e58SJeff Roberson  * The address handle is used to reference a local or global destination
2642aa0a1e58SJeff Roberson  * in all UD QP post sends.
2643aa0a1e58SJeff Roberson  */
2644478d3005SHans Petter Selasky struct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, const struct ib_wc *wc,
2645478d3005SHans Petter Selasky 				   const struct ib_grh *grh, u8 port_num);
2646aa0a1e58SJeff Roberson 
2647aa0a1e58SJeff Roberson /**
2648aa0a1e58SJeff Roberson  * ib_modify_ah - Modifies the address vector associated with an address
2649aa0a1e58SJeff Roberson  *   handle.
2650aa0a1e58SJeff Roberson  * @ah: The address handle to modify.
2651aa0a1e58SJeff Roberson  * @ah_attr: The new address vector attributes to associate with the
2652aa0a1e58SJeff Roberson  *   address handle.
2653aa0a1e58SJeff Roberson  */
2654aa0a1e58SJeff Roberson int ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2655aa0a1e58SJeff Roberson 
2656aa0a1e58SJeff Roberson /**
2657aa0a1e58SJeff Roberson  * ib_query_ah - Queries the address vector associated with an address
2658aa0a1e58SJeff Roberson  *   handle.
2659aa0a1e58SJeff Roberson  * @ah: The address handle to query.
2660aa0a1e58SJeff Roberson  * @ah_attr: The address vector attributes associated with the address
2661aa0a1e58SJeff Roberson  *   handle.
2662aa0a1e58SJeff Roberson  */
2663aa0a1e58SJeff Roberson int ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
2664aa0a1e58SJeff Roberson 
2665aa0a1e58SJeff Roberson /**
2666aa0a1e58SJeff Roberson  * ib_destroy_ah - Destroys an address handle.
2667aa0a1e58SJeff Roberson  * @ah: The address handle to destroy.
2668aa0a1e58SJeff Roberson  */
2669aa0a1e58SJeff Roberson int ib_destroy_ah(struct ib_ah *ah);
2670aa0a1e58SJeff Roberson 
2671aa0a1e58SJeff Roberson /**
2672c9f432b7SAlfred Perlstein  * ib_create_srq - Creates a SRQ associated with the specified protection
2673c9f432b7SAlfred Perlstein  *   domain.
2674aa0a1e58SJeff Roberson  * @pd: The protection domain associated with the SRQ.
2675aa0a1e58SJeff Roberson  * @srq_init_attr: A list of initial attributes required to create the
2676aa0a1e58SJeff Roberson  *   SRQ.  If SRQ creation succeeds, then the attributes are updated to
2677aa0a1e58SJeff Roberson  *   the actual capabilities of the created SRQ.
2678aa0a1e58SJeff Roberson  *
2679aa0a1e58SJeff Roberson  * srq_attr->max_wr and srq_attr->max_sge are read the determine the
2680aa0a1e58SJeff Roberson  * requested size of the SRQ, and set to the actual values allocated
2681aa0a1e58SJeff Roberson  * on return.  If ib_create_srq() succeeds, then max_wr and max_sge
2682aa0a1e58SJeff Roberson  * will always be at least as large as the requested values.
2683aa0a1e58SJeff Roberson  */
2684aa0a1e58SJeff Roberson struct ib_srq *ib_create_srq(struct ib_pd *pd,
2685aa0a1e58SJeff Roberson 			     struct ib_srq_init_attr *srq_init_attr);
2686aa0a1e58SJeff Roberson 
2687aa0a1e58SJeff Roberson /**
2688aa0a1e58SJeff Roberson  * ib_modify_srq - Modifies the attributes for the specified SRQ.
2689aa0a1e58SJeff Roberson  * @srq: The SRQ to modify.
2690aa0a1e58SJeff Roberson  * @srq_attr: On input, specifies the SRQ attributes to modify.  On output,
2691aa0a1e58SJeff Roberson  *   the current values of selected SRQ attributes are returned.
2692aa0a1e58SJeff Roberson  * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
2693aa0a1e58SJeff Roberson  *   are being modified.
2694aa0a1e58SJeff Roberson  *
2695aa0a1e58SJeff Roberson  * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
2696aa0a1e58SJeff Roberson  * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
2697aa0a1e58SJeff Roberson  * the number of receives queued drops below the limit.
2698aa0a1e58SJeff Roberson  */
2699aa0a1e58SJeff Roberson int ib_modify_srq(struct ib_srq *srq,
2700aa0a1e58SJeff Roberson 		  struct ib_srq_attr *srq_attr,
2701aa0a1e58SJeff Roberson 		  enum ib_srq_attr_mask srq_attr_mask);
2702aa0a1e58SJeff Roberson 
2703aa0a1e58SJeff Roberson /**
2704aa0a1e58SJeff Roberson  * ib_query_srq - Returns the attribute list and current values for the
2705aa0a1e58SJeff Roberson  *   specified SRQ.
2706aa0a1e58SJeff Roberson  * @srq: The SRQ to query.
2707aa0a1e58SJeff Roberson  * @srq_attr: The attributes of the specified SRQ.
2708aa0a1e58SJeff Roberson  */
2709aa0a1e58SJeff Roberson int ib_query_srq(struct ib_srq *srq,
2710aa0a1e58SJeff Roberson 		 struct ib_srq_attr *srq_attr);
2711aa0a1e58SJeff Roberson 
2712aa0a1e58SJeff Roberson /**
2713aa0a1e58SJeff Roberson  * ib_destroy_srq - Destroys the specified SRQ.
2714aa0a1e58SJeff Roberson  * @srq: The SRQ to destroy.
2715aa0a1e58SJeff Roberson  */
2716aa0a1e58SJeff Roberson int ib_destroy_srq(struct ib_srq *srq);
2717aa0a1e58SJeff Roberson 
2718aa0a1e58SJeff Roberson /**
2719aa0a1e58SJeff Roberson  * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
2720aa0a1e58SJeff Roberson  * @srq: The SRQ to post the work request on.
2721aa0a1e58SJeff Roberson  * @recv_wr: A list of work requests to post on the receive queue.
2722aa0a1e58SJeff Roberson  * @bad_recv_wr: On an immediate failure, this parameter will reference
2723aa0a1e58SJeff Roberson  *   the work request that failed to be posted on the QP.
2724aa0a1e58SJeff Roberson  */
2725aa0a1e58SJeff Roberson static inline int ib_post_srq_recv(struct ib_srq *srq,
2726aa0a1e58SJeff Roberson 				   struct ib_recv_wr *recv_wr,
2727aa0a1e58SJeff Roberson 				   struct ib_recv_wr **bad_recv_wr)
2728aa0a1e58SJeff Roberson {
2729aa0a1e58SJeff Roberson 	return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
2730aa0a1e58SJeff Roberson }
2731aa0a1e58SJeff Roberson 
2732aa0a1e58SJeff Roberson /**
2733aa0a1e58SJeff Roberson  * ib_create_qp - Creates a QP associated with the specified protection
2734aa0a1e58SJeff Roberson  *   domain.
2735aa0a1e58SJeff Roberson  * @pd: The protection domain associated with the QP.
2736aa0a1e58SJeff Roberson  * @qp_init_attr: A list of initial attributes required to create the
2737aa0a1e58SJeff Roberson  *   QP.  If QP creation succeeds, then the attributes are updated to
2738aa0a1e58SJeff Roberson  *   the actual capabilities of the created QP.
2739aa0a1e58SJeff Roberson  */
2740aa0a1e58SJeff Roberson struct ib_qp *ib_create_qp(struct ib_pd *pd,
2741aa0a1e58SJeff Roberson 			   struct ib_qp_init_attr *qp_init_attr);
2742aa0a1e58SJeff Roberson 
2743aa0a1e58SJeff Roberson /**
2744aa0a1e58SJeff Roberson  * ib_modify_qp - Modifies the attributes for the specified QP and then
2745aa0a1e58SJeff Roberson  *   transitions the QP to the given state.
2746aa0a1e58SJeff Roberson  * @qp: The QP to modify.
2747aa0a1e58SJeff Roberson  * @qp_attr: On input, specifies the QP attributes to modify.  On output,
2748aa0a1e58SJeff Roberson  *   the current values of selected QP attributes are returned.
2749aa0a1e58SJeff Roberson  * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
2750aa0a1e58SJeff Roberson  *   are being modified.
2751aa0a1e58SJeff Roberson  */
2752aa0a1e58SJeff Roberson int ib_modify_qp(struct ib_qp *qp,
2753aa0a1e58SJeff Roberson 		 struct ib_qp_attr *qp_attr,
2754aa0a1e58SJeff Roberson 		 int qp_attr_mask);
2755aa0a1e58SJeff Roberson 
2756aa0a1e58SJeff Roberson /**
2757aa0a1e58SJeff Roberson  * ib_query_qp - Returns the attribute list and current values for the
2758aa0a1e58SJeff Roberson  *   specified QP.
2759aa0a1e58SJeff Roberson  * @qp: The QP to query.
2760aa0a1e58SJeff Roberson  * @qp_attr: The attributes of the specified QP.
2761aa0a1e58SJeff Roberson  * @qp_attr_mask: A bit-mask used to select specific attributes to query.
2762aa0a1e58SJeff Roberson  * @qp_init_attr: Additional attributes of the selected QP.
2763aa0a1e58SJeff Roberson  *
2764aa0a1e58SJeff Roberson  * The qp_attr_mask may be used to limit the query to gathering only the
2765aa0a1e58SJeff Roberson  * selected attributes.
2766aa0a1e58SJeff Roberson  */
2767aa0a1e58SJeff Roberson int ib_query_qp(struct ib_qp *qp,
2768aa0a1e58SJeff Roberson 		struct ib_qp_attr *qp_attr,
2769aa0a1e58SJeff Roberson 		int qp_attr_mask,
2770aa0a1e58SJeff Roberson 		struct ib_qp_init_attr *qp_init_attr);
2771aa0a1e58SJeff Roberson 
2772aa0a1e58SJeff Roberson /**
2773aa0a1e58SJeff Roberson  * ib_destroy_qp - Destroys the specified QP.
2774aa0a1e58SJeff Roberson  * @qp: The QP to destroy.
2775aa0a1e58SJeff Roberson  */
2776aa0a1e58SJeff Roberson int ib_destroy_qp(struct ib_qp *qp);
2777aa0a1e58SJeff Roberson 
2778aa0a1e58SJeff Roberson /**
2779c9f432b7SAlfred Perlstein  * ib_open_qp - Obtain a reference to an existing sharable QP.
2780c9f432b7SAlfred Perlstein  * @xrcd - XRC domain
2781c9f432b7SAlfred Perlstein  * @qp_open_attr: Attributes identifying the QP to open.
2782c9f432b7SAlfred Perlstein  *
2783c9f432b7SAlfred Perlstein  * Returns a reference to a sharable QP.
2784c9f432b7SAlfred Perlstein  */
2785c9f432b7SAlfred Perlstein struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
2786c9f432b7SAlfred Perlstein 			 struct ib_qp_open_attr *qp_open_attr);
2787c9f432b7SAlfred Perlstein 
2788c9f432b7SAlfred Perlstein /**
2789c9f432b7SAlfred Perlstein  * ib_close_qp - Release an external reference to a QP.
2790c9f432b7SAlfred Perlstein  * @qp: The QP handle to release
2791c9f432b7SAlfred Perlstein  *
2792c9f432b7SAlfred Perlstein  * The opened QP handle is released by the caller.  The underlying
2793c9f432b7SAlfred Perlstein  * shared QP is not destroyed until all internal references are released.
2794c9f432b7SAlfred Perlstein  */
2795c9f432b7SAlfred Perlstein int ib_close_qp(struct ib_qp *qp);
2796c9f432b7SAlfred Perlstein 
2797c9f432b7SAlfred Perlstein /**
2798aa0a1e58SJeff Roberson  * ib_post_send - Posts a list of work requests to the send queue of
2799aa0a1e58SJeff Roberson  *   the specified QP.
2800aa0a1e58SJeff Roberson  * @qp: The QP to post the work request on.
2801aa0a1e58SJeff Roberson  * @send_wr: A list of work requests to post on the send queue.
2802aa0a1e58SJeff Roberson  * @bad_send_wr: On an immediate failure, this parameter will reference
2803aa0a1e58SJeff Roberson  *   the work request that failed to be posted on the QP.
2804c9f432b7SAlfred Perlstein  *
2805c9f432b7SAlfred Perlstein  * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
2806c9f432b7SAlfred Perlstein  * error is returned, the QP state shall not be affected,
2807c9f432b7SAlfred Perlstein  * ib_post_send() will return an immediate error after queueing any
2808c9f432b7SAlfred Perlstein  * earlier work requests in the list.
2809aa0a1e58SJeff Roberson  */
2810aa0a1e58SJeff Roberson static inline int ib_post_send(struct ib_qp *qp,
2811aa0a1e58SJeff Roberson 			       struct ib_send_wr *send_wr,
2812aa0a1e58SJeff Roberson 			       struct ib_send_wr **bad_send_wr)
2813aa0a1e58SJeff Roberson {
2814aa0a1e58SJeff Roberson 	return qp->device->post_send(qp, send_wr, bad_send_wr);
2815aa0a1e58SJeff Roberson }
2816aa0a1e58SJeff Roberson 
2817aa0a1e58SJeff Roberson /**
2818aa0a1e58SJeff Roberson  * ib_post_recv - Posts a list of work requests to the receive queue of
2819aa0a1e58SJeff Roberson  *   the specified QP.
2820aa0a1e58SJeff Roberson  * @qp: The QP to post the work request on.
2821aa0a1e58SJeff Roberson  * @recv_wr: A list of work requests to post on the receive queue.
2822aa0a1e58SJeff Roberson  * @bad_recv_wr: On an immediate failure, this parameter will reference
2823aa0a1e58SJeff Roberson  *   the work request that failed to be posted on the QP.
2824aa0a1e58SJeff Roberson  */
2825aa0a1e58SJeff Roberson static inline int ib_post_recv(struct ib_qp *qp,
2826aa0a1e58SJeff Roberson 			       struct ib_recv_wr *recv_wr,
2827aa0a1e58SJeff Roberson 			       struct ib_recv_wr **bad_recv_wr)
2828aa0a1e58SJeff Roberson {
2829aa0a1e58SJeff Roberson 	return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
2830aa0a1e58SJeff Roberson }
2831aa0a1e58SJeff Roberson 
2832478d3005SHans Petter Selasky struct ib_cq *ib_alloc_cq(struct ib_device *dev, void *private,
2833478d3005SHans Petter Selasky 		int nr_cqe, int comp_vector, enum ib_poll_context poll_ctx);
2834478d3005SHans Petter Selasky void ib_free_cq(struct ib_cq *cq);
2835478d3005SHans Petter Selasky 
2836aa0a1e58SJeff Roberson /**
2837aa0a1e58SJeff Roberson  * ib_create_cq - Creates a CQ on the specified device.
2838aa0a1e58SJeff Roberson  * @device: The device on which to create the CQ.
2839aa0a1e58SJeff Roberson  * @comp_handler: A user-specified callback that is invoked when a
2840aa0a1e58SJeff Roberson  *   completion event occurs on the CQ.
2841aa0a1e58SJeff Roberson  * @event_handler: A user-specified callback that is invoked when an
2842aa0a1e58SJeff Roberson  *   asynchronous event not associated with a completion occurs on the CQ.
2843aa0a1e58SJeff Roberson  * @cq_context: Context associated with the CQ returned to the user via
2844aa0a1e58SJeff Roberson  *   the associated completion and event handlers.
2845478d3005SHans Petter Selasky  * @cq_attr: The attributes the CQ should be created upon.
2846aa0a1e58SJeff Roberson  *
2847aa0a1e58SJeff Roberson  * Users can examine the cq structure to determine the actual CQ size.
2848aa0a1e58SJeff Roberson  */
2849aa0a1e58SJeff Roberson struct ib_cq *ib_create_cq(struct ib_device *device,
2850aa0a1e58SJeff Roberson 			   ib_comp_handler comp_handler,
2851aa0a1e58SJeff Roberson 			   void (*event_handler)(struct ib_event *, void *),
2852478d3005SHans Petter Selasky 			   void *cq_context,
2853478d3005SHans Petter Selasky 			   const struct ib_cq_init_attr *cq_attr);
2854aa0a1e58SJeff Roberson 
2855aa0a1e58SJeff Roberson /**
2856aa0a1e58SJeff Roberson  * ib_resize_cq - Modifies the capacity of the CQ.
2857aa0a1e58SJeff Roberson  * @cq: The CQ to resize.
2858aa0a1e58SJeff Roberson  * @cqe: The minimum size of the CQ.
2859aa0a1e58SJeff Roberson  *
2860aa0a1e58SJeff Roberson  * Users can examine the cq structure to determine the actual CQ size.
2861aa0a1e58SJeff Roberson  */
2862aa0a1e58SJeff Roberson int ib_resize_cq(struct ib_cq *cq, int cqe);
2863aa0a1e58SJeff Roberson 
2864aa0a1e58SJeff Roberson /**
2865478d3005SHans Petter Selasky  * ib_modify_cq - Modifies moderation params of the CQ
2866aa0a1e58SJeff Roberson  * @cq: The CQ to modify.
2867478d3005SHans Petter Selasky  * @cq_count: number of CQEs that will trigger an event
2868478d3005SHans Petter Selasky  * @cq_period: max period of time in usec before triggering an event
2869478d3005SHans Petter Selasky  *
2870aa0a1e58SJeff Roberson  */
2871478d3005SHans Petter Selasky int ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
2872aa0a1e58SJeff Roberson 
2873aa0a1e58SJeff Roberson /**
2874aa0a1e58SJeff Roberson  * ib_destroy_cq - Destroys the specified CQ.
2875aa0a1e58SJeff Roberson  * @cq: The CQ to destroy.
2876aa0a1e58SJeff Roberson  */
2877aa0a1e58SJeff Roberson int ib_destroy_cq(struct ib_cq *cq);
2878aa0a1e58SJeff Roberson 
2879aa0a1e58SJeff Roberson /**
2880aa0a1e58SJeff Roberson  * ib_poll_cq - poll a CQ for completion(s)
2881aa0a1e58SJeff Roberson  * @cq:the CQ being polled
2882aa0a1e58SJeff Roberson  * @num_entries:maximum number of completions to return
2883aa0a1e58SJeff Roberson  * @wc:array of at least @num_entries &struct ib_wc where completions
2884aa0a1e58SJeff Roberson  *   will be returned
2885aa0a1e58SJeff Roberson  *
2886aa0a1e58SJeff Roberson  * Poll a CQ for (possibly multiple) completions.  If the return value
2887aa0a1e58SJeff Roberson  * is < 0, an error occurred.  If the return value is >= 0, it is the
2888aa0a1e58SJeff Roberson  * number of completions returned.  If the return value is
2889aa0a1e58SJeff Roberson  * non-negative and < num_entries, then the CQ was emptied.
2890aa0a1e58SJeff Roberson  */
2891aa0a1e58SJeff Roberson static inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
2892aa0a1e58SJeff Roberson 			     struct ib_wc *wc)
2893aa0a1e58SJeff Roberson {
2894aa0a1e58SJeff Roberson 	return cq->device->poll_cq(cq, num_entries, wc);
2895aa0a1e58SJeff Roberson }
2896aa0a1e58SJeff Roberson 
2897aa0a1e58SJeff Roberson /**
2898aa0a1e58SJeff Roberson  * ib_peek_cq - Returns the number of unreaped completions currently
2899aa0a1e58SJeff Roberson  *   on the specified CQ.
2900aa0a1e58SJeff Roberson  * @cq: The CQ to peek.
2901aa0a1e58SJeff Roberson  * @wc_cnt: A minimum number of unreaped completions to check for.
2902aa0a1e58SJeff Roberson  *
2903aa0a1e58SJeff Roberson  * If the number of unreaped completions is greater than or equal to wc_cnt,
2904aa0a1e58SJeff Roberson  * this function returns wc_cnt, otherwise, it returns the actual number of
2905aa0a1e58SJeff Roberson  * unreaped completions.
2906aa0a1e58SJeff Roberson  */
2907aa0a1e58SJeff Roberson int ib_peek_cq(struct ib_cq *cq, int wc_cnt);
2908aa0a1e58SJeff Roberson 
2909aa0a1e58SJeff Roberson /**
2910aa0a1e58SJeff Roberson  * ib_req_notify_cq - Request completion notification on a CQ.
2911aa0a1e58SJeff Roberson  * @cq: The CQ to generate an event for.
2912aa0a1e58SJeff Roberson  * @flags:
2913aa0a1e58SJeff Roberson  *   Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
2914aa0a1e58SJeff Roberson  *   to request an event on the next solicited event or next work
2915aa0a1e58SJeff Roberson  *   completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
2916aa0a1e58SJeff Roberson  *   may also be |ed in to request a hint about missed events, as
2917aa0a1e58SJeff Roberson  *   described below.
2918aa0a1e58SJeff Roberson  *
2919aa0a1e58SJeff Roberson  * Return Value:
2920aa0a1e58SJeff Roberson  *    < 0 means an error occurred while requesting notification
2921aa0a1e58SJeff Roberson  *   == 0 means notification was requested successfully, and if
2922aa0a1e58SJeff Roberson  *        IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
2923aa0a1e58SJeff Roberson  *        were missed and it is safe to wait for another event.  In
2924aa0a1e58SJeff Roberson  *        this case is it guaranteed that any work completions added
2925aa0a1e58SJeff Roberson  *        to the CQ since the last CQ poll will trigger a completion
2926aa0a1e58SJeff Roberson  *        notification event.
2927aa0a1e58SJeff Roberson  *    > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
2928aa0a1e58SJeff Roberson  *        in.  It means that the consumer must poll the CQ again to
2929aa0a1e58SJeff Roberson  *        make sure it is empty to avoid missing an event because of a
2930aa0a1e58SJeff Roberson  *        race between requesting notification and an entry being
2931aa0a1e58SJeff Roberson  *        added to the CQ.  This return value means it is possible
2932aa0a1e58SJeff Roberson  *        (but not guaranteed) that a work completion has been added
2933aa0a1e58SJeff Roberson  *        to the CQ since the last poll without triggering a
2934aa0a1e58SJeff Roberson  *        completion notification event.
2935aa0a1e58SJeff Roberson  */
2936aa0a1e58SJeff Roberson static inline int ib_req_notify_cq(struct ib_cq *cq,
2937aa0a1e58SJeff Roberson 				   enum ib_cq_notify_flags flags)
2938aa0a1e58SJeff Roberson {
2939aa0a1e58SJeff Roberson 	return cq->device->req_notify_cq(cq, flags);
2940aa0a1e58SJeff Roberson }
2941aa0a1e58SJeff Roberson 
2942aa0a1e58SJeff Roberson /**
2943aa0a1e58SJeff Roberson  * ib_req_ncomp_notif - Request completion notification when there are
2944aa0a1e58SJeff Roberson  *   at least the specified number of unreaped completions on the CQ.
2945aa0a1e58SJeff Roberson  * @cq: The CQ to generate an event for.
2946aa0a1e58SJeff Roberson  * @wc_cnt: The number of unreaped completions that should be on the
2947aa0a1e58SJeff Roberson  *   CQ before an event is generated.
2948aa0a1e58SJeff Roberson  */
2949aa0a1e58SJeff Roberson static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
2950aa0a1e58SJeff Roberson {
2951aa0a1e58SJeff Roberson 	return cq->device->req_ncomp_notif ?
2952aa0a1e58SJeff Roberson 		cq->device->req_ncomp_notif(cq, wc_cnt) :
2953aa0a1e58SJeff Roberson 		-ENOSYS;
2954aa0a1e58SJeff Roberson }
2955aa0a1e58SJeff Roberson 
2956aa0a1e58SJeff Roberson /**
2957aa0a1e58SJeff Roberson  * ib_dma_mapping_error - check a DMA addr for error
2958aa0a1e58SJeff Roberson  * @dev: The device for which the dma_addr was created
2959aa0a1e58SJeff Roberson  * @dma_addr: The DMA address to check
2960aa0a1e58SJeff Roberson  */
2961aa0a1e58SJeff Roberson static inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
2962aa0a1e58SJeff Roberson {
2963aa0a1e58SJeff Roberson 	if (dev->dma_ops)
2964aa0a1e58SJeff Roberson 		return dev->dma_ops->mapping_error(dev, dma_addr);
2965aa0a1e58SJeff Roberson 	return dma_mapping_error(dev->dma_device, dma_addr);
2966aa0a1e58SJeff Roberson }
2967aa0a1e58SJeff Roberson 
2968aa0a1e58SJeff Roberson /**
2969aa0a1e58SJeff Roberson  * ib_dma_map_single - Map a kernel virtual address to DMA address
2970aa0a1e58SJeff Roberson  * @dev: The device for which the dma_addr is to be created
2971aa0a1e58SJeff Roberson  * @cpu_addr: The kernel virtual address
2972aa0a1e58SJeff Roberson  * @size: The size of the region in bytes
2973aa0a1e58SJeff Roberson  * @direction: The direction of the DMA
2974aa0a1e58SJeff Roberson  */
2975aa0a1e58SJeff Roberson static inline u64 ib_dma_map_single(struct ib_device *dev,
2976aa0a1e58SJeff Roberson 				    void *cpu_addr, size_t size,
2977aa0a1e58SJeff Roberson 				    enum dma_data_direction direction)
2978aa0a1e58SJeff Roberson {
2979aa0a1e58SJeff Roberson 	if (dev->dma_ops)
2980aa0a1e58SJeff Roberson 		return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
2981aa0a1e58SJeff Roberson 	return dma_map_single(dev->dma_device, cpu_addr, size, direction);
2982aa0a1e58SJeff Roberson }
2983aa0a1e58SJeff Roberson 
2984aa0a1e58SJeff Roberson /**
2985aa0a1e58SJeff Roberson  * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
2986aa0a1e58SJeff Roberson  * @dev: The device for which the DMA address was created
2987aa0a1e58SJeff Roberson  * @addr: The DMA address
2988aa0a1e58SJeff Roberson  * @size: The size of the region in bytes
2989aa0a1e58SJeff Roberson  * @direction: The direction of the DMA
2990aa0a1e58SJeff Roberson  */
2991aa0a1e58SJeff Roberson static inline void ib_dma_unmap_single(struct ib_device *dev,
2992aa0a1e58SJeff Roberson 				       u64 addr, size_t size,
2993aa0a1e58SJeff Roberson 				       enum dma_data_direction direction)
2994aa0a1e58SJeff Roberson {
2995aa0a1e58SJeff Roberson 	if (dev->dma_ops)
2996aa0a1e58SJeff Roberson 		dev->dma_ops->unmap_single(dev, addr, size, direction);
2997aa0a1e58SJeff Roberson 	else
2998aa0a1e58SJeff Roberson 		dma_unmap_single(dev->dma_device, addr, size, direction);
2999aa0a1e58SJeff Roberson }
3000aa0a1e58SJeff Roberson 
3001aa0a1e58SJeff Roberson static inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
3002aa0a1e58SJeff Roberson 					  void *cpu_addr, size_t size,
3003aa0a1e58SJeff Roberson 					  enum dma_data_direction direction,
3004478d3005SHans Petter Selasky 					  struct dma_attrs *dma_attrs)
3005aa0a1e58SJeff Roberson {
3006aa0a1e58SJeff Roberson 	return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
3007478d3005SHans Petter Selasky 				    direction, dma_attrs);
3008aa0a1e58SJeff Roberson }
3009aa0a1e58SJeff Roberson 
3010aa0a1e58SJeff Roberson static inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
3011aa0a1e58SJeff Roberson 					     u64 addr, size_t size,
3012aa0a1e58SJeff Roberson 					     enum dma_data_direction direction,
3013478d3005SHans Petter Selasky 					     struct dma_attrs *dma_attrs)
3014aa0a1e58SJeff Roberson {
3015aa0a1e58SJeff Roberson 	return dma_unmap_single_attrs(dev->dma_device, addr, size,
3016478d3005SHans Petter Selasky 				      direction, dma_attrs);
3017aa0a1e58SJeff Roberson }
3018aa0a1e58SJeff Roberson 
3019aa0a1e58SJeff Roberson /**
3020aa0a1e58SJeff Roberson  * ib_dma_map_page - Map a physical page to DMA address
3021aa0a1e58SJeff Roberson  * @dev: The device for which the dma_addr is to be created
3022aa0a1e58SJeff Roberson  * @page: The page to be mapped
3023aa0a1e58SJeff Roberson  * @offset: The offset within the page
3024aa0a1e58SJeff Roberson  * @size: The size of the region in bytes
3025aa0a1e58SJeff Roberson  * @direction: The direction of the DMA
3026aa0a1e58SJeff Roberson  */
3027aa0a1e58SJeff Roberson static inline u64 ib_dma_map_page(struct ib_device *dev,
3028aa0a1e58SJeff Roberson 				  struct page *page,
3029aa0a1e58SJeff Roberson 				  unsigned long offset,
3030aa0a1e58SJeff Roberson 				  size_t size,
3031aa0a1e58SJeff Roberson 					 enum dma_data_direction direction)
3032aa0a1e58SJeff Roberson {
3033aa0a1e58SJeff Roberson 	if (dev->dma_ops)
3034aa0a1e58SJeff Roberson 		return dev->dma_ops->map_page(dev, page, offset, size, direction);
3035aa0a1e58SJeff Roberson 	return dma_map_page(dev->dma_device, page, offset, size, direction);
3036aa0a1e58SJeff Roberson }
3037aa0a1e58SJeff Roberson 
3038aa0a1e58SJeff Roberson /**
3039aa0a1e58SJeff Roberson  * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
3040aa0a1e58SJeff Roberson  * @dev: The device for which the DMA address was created
3041aa0a1e58SJeff Roberson  * @addr: The DMA address
3042aa0a1e58SJeff Roberson  * @size: The size of the region in bytes
3043aa0a1e58SJeff Roberson  * @direction: The direction of the DMA
3044aa0a1e58SJeff Roberson  */
3045aa0a1e58SJeff Roberson static inline void ib_dma_unmap_page(struct ib_device *dev,
3046aa0a1e58SJeff Roberson 				     u64 addr, size_t size,
3047aa0a1e58SJeff Roberson 				     enum dma_data_direction direction)
3048aa0a1e58SJeff Roberson {
3049aa0a1e58SJeff Roberson 	if (dev->dma_ops)
3050aa0a1e58SJeff Roberson 		dev->dma_ops->unmap_page(dev, addr, size, direction);
3051aa0a1e58SJeff Roberson 	else
3052aa0a1e58SJeff Roberson 		dma_unmap_page(dev->dma_device, addr, size, direction);
3053aa0a1e58SJeff Roberson }
3054aa0a1e58SJeff Roberson 
3055aa0a1e58SJeff Roberson /**
3056aa0a1e58SJeff Roberson  * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
3057aa0a1e58SJeff Roberson  * @dev: The device for which the DMA addresses are to be created
3058aa0a1e58SJeff Roberson  * @sg: The array of scatter/gather entries
3059aa0a1e58SJeff Roberson  * @nents: The number of scatter/gather entries
3060aa0a1e58SJeff Roberson  * @direction: The direction of the DMA
3061aa0a1e58SJeff Roberson  */
3062aa0a1e58SJeff Roberson static inline int ib_dma_map_sg(struct ib_device *dev,
3063aa0a1e58SJeff Roberson 				struct scatterlist *sg, int nents,
3064aa0a1e58SJeff Roberson 				enum dma_data_direction direction)
3065aa0a1e58SJeff Roberson {
3066aa0a1e58SJeff Roberson 	if (dev->dma_ops)
3067aa0a1e58SJeff Roberson 		return dev->dma_ops->map_sg(dev, sg, nents, direction);
3068aa0a1e58SJeff Roberson 	return dma_map_sg(dev->dma_device, sg, nents, direction);
3069aa0a1e58SJeff Roberson }
3070aa0a1e58SJeff Roberson 
3071aa0a1e58SJeff Roberson /**
3072aa0a1e58SJeff Roberson  * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
3073aa0a1e58SJeff Roberson  * @dev: The device for which the DMA addresses were created
3074aa0a1e58SJeff Roberson  * @sg: The array of scatter/gather entries
3075aa0a1e58SJeff Roberson  * @nents: The number of scatter/gather entries
3076aa0a1e58SJeff Roberson  * @direction: The direction of the DMA
3077aa0a1e58SJeff Roberson  */
3078aa0a1e58SJeff Roberson static inline void ib_dma_unmap_sg(struct ib_device *dev,
3079aa0a1e58SJeff Roberson 				   struct scatterlist *sg, int nents,
3080aa0a1e58SJeff Roberson 				   enum dma_data_direction direction)
3081aa0a1e58SJeff Roberson {
3082aa0a1e58SJeff Roberson 	if (dev->dma_ops)
3083aa0a1e58SJeff Roberson 		dev->dma_ops->unmap_sg(dev, sg, nents, direction);
3084aa0a1e58SJeff Roberson 	else
3085aa0a1e58SJeff Roberson 		dma_unmap_sg(dev->dma_device, sg, nents, direction);
3086aa0a1e58SJeff Roberson }
3087aa0a1e58SJeff Roberson 
3088aa0a1e58SJeff Roberson static inline int ib_dma_map_sg_attrs(struct ib_device *dev,
3089aa0a1e58SJeff Roberson 				      struct scatterlist *sg, int nents,
3090aa0a1e58SJeff Roberson 				      enum dma_data_direction direction,
3091478d3005SHans Petter Selasky 				      struct dma_attrs *dma_attrs)
3092aa0a1e58SJeff Roberson {
3093478d3005SHans Petter Selasky 	if (dev->dma_ops)
3094478d3005SHans Petter Selasky 		return dev->dma_ops->map_sg_attrs(dev, sg, nents, direction,
3095478d3005SHans Petter Selasky 						  dma_attrs);
3096478d3005SHans Petter Selasky 	else
3097478d3005SHans Petter Selasky 		return dma_map_sg_attrs(dev->dma_device, sg, nents, direction,
3098478d3005SHans Petter Selasky 					dma_attrs);
3099aa0a1e58SJeff Roberson }
3100aa0a1e58SJeff Roberson 
3101aa0a1e58SJeff Roberson static inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
3102aa0a1e58SJeff Roberson 					 struct scatterlist *sg, int nents,
3103aa0a1e58SJeff Roberson 					 enum dma_data_direction direction,
3104478d3005SHans Petter Selasky 					 struct dma_attrs *dma_attrs)
3105aa0a1e58SJeff Roberson {
3106478d3005SHans Petter Selasky 	if (dev->dma_ops)
3107478d3005SHans Petter Selasky 		return dev->dma_ops->unmap_sg_attrs(dev, sg, nents, direction,
3108478d3005SHans Petter Selasky 						  dma_attrs);
3109478d3005SHans Petter Selasky 	else
3110478d3005SHans Petter Selasky 		dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction,
3111478d3005SHans Petter Selasky 				   dma_attrs);
3112aa0a1e58SJeff Roberson }
3113aa0a1e58SJeff Roberson /**
3114aa0a1e58SJeff Roberson  * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
3115aa0a1e58SJeff Roberson  * @dev: The device for which the DMA addresses were created
3116aa0a1e58SJeff Roberson  * @sg: The scatter/gather entry
3117478d3005SHans Petter Selasky  *
3118478d3005SHans Petter Selasky  * Note: this function is obsolete. To do: change all occurrences of
3119478d3005SHans Petter Selasky  * ib_sg_dma_address() into sg_dma_address().
3120aa0a1e58SJeff Roberson  */
3121aa0a1e58SJeff Roberson static inline u64 ib_sg_dma_address(struct ib_device *dev,
3122aa0a1e58SJeff Roberson 				    struct scatterlist *sg)
3123aa0a1e58SJeff Roberson {
3124aa0a1e58SJeff Roberson 	return sg_dma_address(sg);
3125aa0a1e58SJeff Roberson }
3126aa0a1e58SJeff Roberson 
3127aa0a1e58SJeff Roberson /**
3128aa0a1e58SJeff Roberson  * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
3129aa0a1e58SJeff Roberson  * @dev: The device for which the DMA addresses were created
3130aa0a1e58SJeff Roberson  * @sg: The scatter/gather entry
3131478d3005SHans Petter Selasky  *
3132478d3005SHans Petter Selasky  * Note: this function is obsolete. To do: change all occurrences of
3133478d3005SHans Petter Selasky  * ib_sg_dma_len() into sg_dma_len().
3134aa0a1e58SJeff Roberson  */
3135aa0a1e58SJeff Roberson static inline unsigned int ib_sg_dma_len(struct ib_device *dev,
3136aa0a1e58SJeff Roberson 					 struct scatterlist *sg)
3137aa0a1e58SJeff Roberson {
3138aa0a1e58SJeff Roberson 	return sg_dma_len(sg);
3139aa0a1e58SJeff Roberson }
3140aa0a1e58SJeff Roberson 
3141aa0a1e58SJeff Roberson /**
3142aa0a1e58SJeff Roberson  * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
3143aa0a1e58SJeff Roberson  * @dev: The device for which the DMA address was created
3144aa0a1e58SJeff Roberson  * @addr: The DMA address
3145aa0a1e58SJeff Roberson  * @size: The size of the region in bytes
3146aa0a1e58SJeff Roberson  * @dir: The direction of the DMA
3147aa0a1e58SJeff Roberson  */
3148aa0a1e58SJeff Roberson static inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
3149aa0a1e58SJeff Roberson 					      u64 addr,
3150aa0a1e58SJeff Roberson 					      size_t size,
3151aa0a1e58SJeff Roberson 					      enum dma_data_direction dir)
3152aa0a1e58SJeff Roberson {
3153aa0a1e58SJeff Roberson 	if (dev->dma_ops)
3154aa0a1e58SJeff Roberson 		dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
3155aa0a1e58SJeff Roberson 	else
3156aa0a1e58SJeff Roberson 		dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
3157aa0a1e58SJeff Roberson }
3158aa0a1e58SJeff Roberson 
3159aa0a1e58SJeff Roberson /**
3160aa0a1e58SJeff Roberson  * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
3161aa0a1e58SJeff Roberson  * @dev: The device for which the DMA address was created
3162aa0a1e58SJeff Roberson  * @addr: The DMA address
3163aa0a1e58SJeff Roberson  * @size: The size of the region in bytes
3164aa0a1e58SJeff Roberson  * @dir: The direction of the DMA
3165aa0a1e58SJeff Roberson  */
3166aa0a1e58SJeff Roberson static inline void ib_dma_sync_single_for_device(struct ib_device *dev,
3167aa0a1e58SJeff Roberson 						 u64 addr,
3168aa0a1e58SJeff Roberson 						 size_t size,
3169aa0a1e58SJeff Roberson 						 enum dma_data_direction dir)
3170aa0a1e58SJeff Roberson {
3171aa0a1e58SJeff Roberson 	if (dev->dma_ops)
3172aa0a1e58SJeff Roberson 		dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
3173aa0a1e58SJeff Roberson 	else
3174aa0a1e58SJeff Roberson 		dma_sync_single_for_device(dev->dma_device, addr, size, dir);
3175aa0a1e58SJeff Roberson }
3176aa0a1e58SJeff Roberson 
3177aa0a1e58SJeff Roberson /**
3178aa0a1e58SJeff Roberson  * ib_dma_alloc_coherent - Allocate memory and map it for DMA
3179aa0a1e58SJeff Roberson  * @dev: The device for which the DMA address is requested
3180aa0a1e58SJeff Roberson  * @size: The size of the region to allocate in bytes
3181aa0a1e58SJeff Roberson  * @dma_handle: A pointer for returning the DMA address of the region
3182aa0a1e58SJeff Roberson  * @flag: memory allocator flags
3183aa0a1e58SJeff Roberson  */
3184aa0a1e58SJeff Roberson static inline void *ib_dma_alloc_coherent(struct ib_device *dev,
3185aa0a1e58SJeff Roberson 					   size_t size,
3186aa0a1e58SJeff Roberson 					   u64 *dma_handle,
3187aa0a1e58SJeff Roberson 					   gfp_t flag)
3188aa0a1e58SJeff Roberson {
3189aa0a1e58SJeff Roberson 	if (dev->dma_ops)
3190aa0a1e58SJeff Roberson 		return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
3191aa0a1e58SJeff Roberson 	else {
3192aa0a1e58SJeff Roberson 		dma_addr_t handle;
3193aa0a1e58SJeff Roberson 		void *ret;
3194aa0a1e58SJeff Roberson 
3195aa0a1e58SJeff Roberson 		ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
3196aa0a1e58SJeff Roberson 		*dma_handle = handle;
3197aa0a1e58SJeff Roberson 		return ret;
3198aa0a1e58SJeff Roberson 	}
3199aa0a1e58SJeff Roberson }
3200aa0a1e58SJeff Roberson 
3201aa0a1e58SJeff Roberson /**
3202aa0a1e58SJeff Roberson  * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
3203aa0a1e58SJeff Roberson  * @dev: The device for which the DMA addresses were allocated
3204aa0a1e58SJeff Roberson  * @size: The size of the region
3205aa0a1e58SJeff Roberson  * @cpu_addr: the address returned by ib_dma_alloc_coherent()
3206aa0a1e58SJeff Roberson  * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
3207aa0a1e58SJeff Roberson  */
3208aa0a1e58SJeff Roberson static inline void ib_dma_free_coherent(struct ib_device *dev,
3209aa0a1e58SJeff Roberson 					size_t size, void *cpu_addr,
3210aa0a1e58SJeff Roberson 					u64 dma_handle)
3211aa0a1e58SJeff Roberson {
3212aa0a1e58SJeff Roberson 	if (dev->dma_ops)
3213aa0a1e58SJeff Roberson 		dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
3214aa0a1e58SJeff Roberson 	else
3215aa0a1e58SJeff Roberson 		dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
3216aa0a1e58SJeff Roberson }
3217aa0a1e58SJeff Roberson 
3218aa0a1e58SJeff Roberson /**
3219aa0a1e58SJeff Roberson  * ib_dereg_mr - Deregisters a memory region and removes it from the
3220aa0a1e58SJeff Roberson  *   HCA translation table.
3221aa0a1e58SJeff Roberson  * @mr: The memory region to deregister.
3222b5c1e0cbSHans Petter Selasky  *
3223b5c1e0cbSHans Petter Selasky  * This function can fail, if the memory region has memory windows bound to it.
3224aa0a1e58SJeff Roberson  */
3225aa0a1e58SJeff Roberson int ib_dereg_mr(struct ib_mr *mr);
3226aa0a1e58SJeff Roberson 
3227478d3005SHans Petter Selasky struct ib_mr *ib_alloc_mr(struct ib_pd *pd,
3228478d3005SHans Petter Selasky 			  enum ib_mr_type mr_type,
3229478d3005SHans Petter Selasky 			  u32 max_num_sg);
3230aa0a1e58SJeff Roberson 
3231aa0a1e58SJeff Roberson /**
3232aa0a1e58SJeff Roberson  * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
3233aa0a1e58SJeff Roberson  *   R_Key and L_Key.
3234aa0a1e58SJeff Roberson  * @mr - struct ib_mr pointer to be updated.
3235aa0a1e58SJeff Roberson  * @newkey - new key to be used.
3236aa0a1e58SJeff Roberson  */
3237aa0a1e58SJeff Roberson static inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
3238aa0a1e58SJeff Roberson {
3239aa0a1e58SJeff Roberson 	mr->lkey = (mr->lkey & 0xffffff00) | newkey;
3240aa0a1e58SJeff Roberson 	mr->rkey = (mr->rkey & 0xffffff00) | newkey;
3241aa0a1e58SJeff Roberson }
3242aa0a1e58SJeff Roberson 
3243aa0a1e58SJeff Roberson /**
3244b5c1e0cbSHans Petter Selasky  * ib_inc_rkey - increments the key portion of the given rkey. Can be used
3245b5c1e0cbSHans Petter Selasky  * for calculating a new rkey for type 2 memory windows.
3246b5c1e0cbSHans Petter Selasky  * @rkey - the rkey to increment.
3247b5c1e0cbSHans Petter Selasky  */
3248b5c1e0cbSHans Petter Selasky static inline u32 ib_inc_rkey(u32 rkey)
3249b5c1e0cbSHans Petter Selasky {
3250b5c1e0cbSHans Petter Selasky 	const u32 mask = 0x000000ff;
3251b5c1e0cbSHans Petter Selasky 	return ((rkey + 1) & mask) | (rkey & ~mask);
3252b5c1e0cbSHans Petter Selasky }
3253b5c1e0cbSHans Petter Selasky 
3254b5c1e0cbSHans Petter Selasky /**
3255aa0a1e58SJeff Roberson  * ib_alloc_fmr - Allocates a unmapped fast memory region.
3256aa0a1e58SJeff Roberson  * @pd: The protection domain associated with the unmapped region.
3257aa0a1e58SJeff Roberson  * @mr_access_flags: Specifies the memory access rights.
3258aa0a1e58SJeff Roberson  * @fmr_attr: Attributes of the unmapped region.
3259aa0a1e58SJeff Roberson  *
3260aa0a1e58SJeff Roberson  * A fast memory region must be mapped before it can be used as part of
3261aa0a1e58SJeff Roberson  * a work request.
3262aa0a1e58SJeff Roberson  */
3263aa0a1e58SJeff Roberson struct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
3264aa0a1e58SJeff Roberson 			    int mr_access_flags,
3265aa0a1e58SJeff Roberson 			    struct ib_fmr_attr *fmr_attr);
3266aa0a1e58SJeff Roberson 
3267aa0a1e58SJeff Roberson /**
3268aa0a1e58SJeff Roberson  * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
3269aa0a1e58SJeff Roberson  * @fmr: The fast memory region to associate with the pages.
3270aa0a1e58SJeff Roberson  * @page_list: An array of physical pages to map to the fast memory region.
3271aa0a1e58SJeff Roberson  * @list_len: The number of pages in page_list.
3272aa0a1e58SJeff Roberson  * @iova: The I/O virtual address to use with the mapped region.
3273aa0a1e58SJeff Roberson  */
3274aa0a1e58SJeff Roberson static inline int ib_map_phys_fmr(struct ib_fmr *fmr,
3275aa0a1e58SJeff Roberson 				  u64 *page_list, int list_len,
3276aa0a1e58SJeff Roberson 				  u64 iova)
3277aa0a1e58SJeff Roberson {
3278aa0a1e58SJeff Roberson 	return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
3279aa0a1e58SJeff Roberson }
3280aa0a1e58SJeff Roberson 
3281aa0a1e58SJeff Roberson /**
3282aa0a1e58SJeff Roberson  * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
3283aa0a1e58SJeff Roberson  * @fmr_list: A linked list of fast memory regions to unmap.
3284aa0a1e58SJeff Roberson  */
3285aa0a1e58SJeff Roberson int ib_unmap_fmr(struct list_head *fmr_list);
3286aa0a1e58SJeff Roberson 
3287aa0a1e58SJeff Roberson /**
3288aa0a1e58SJeff Roberson  * ib_dealloc_fmr - Deallocates a fast memory region.
3289aa0a1e58SJeff Roberson  * @fmr: The fast memory region to deallocate.
3290aa0a1e58SJeff Roberson  */
3291aa0a1e58SJeff Roberson int ib_dealloc_fmr(struct ib_fmr *fmr);
3292aa0a1e58SJeff Roberson 
3293aa0a1e58SJeff Roberson /**
3294aa0a1e58SJeff Roberson  * ib_attach_mcast - Attaches the specified QP to a multicast group.
3295aa0a1e58SJeff Roberson  * @qp: QP to attach to the multicast group.  The QP must be type
3296aa0a1e58SJeff Roberson  *   IB_QPT_UD.
3297aa0a1e58SJeff Roberson  * @gid: Multicast group GID.
3298aa0a1e58SJeff Roberson  * @lid: Multicast group LID in host byte order.
3299aa0a1e58SJeff Roberson  *
3300aa0a1e58SJeff Roberson  * In order to send and receive multicast packets, subnet
3301aa0a1e58SJeff Roberson  * administration must have created the multicast group and configured
3302aa0a1e58SJeff Roberson  * the fabric appropriately.  The port associated with the specified
3303aa0a1e58SJeff Roberson  * QP must also be a member of the multicast group.
3304aa0a1e58SJeff Roberson  */
3305aa0a1e58SJeff Roberson int ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
3306aa0a1e58SJeff Roberson 
3307aa0a1e58SJeff Roberson /**
3308aa0a1e58SJeff Roberson  * ib_detach_mcast - Detaches the specified QP from a multicast group.
3309aa0a1e58SJeff Roberson  * @qp: QP to detach from the multicast group.
3310aa0a1e58SJeff Roberson  * @gid: Multicast group GID.
3311aa0a1e58SJeff Roberson  * @lid: Multicast group LID in host byte order.
3312aa0a1e58SJeff Roberson  */
3313aa0a1e58SJeff Roberson int ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
3314aa0a1e58SJeff Roberson 
3315c9f432b7SAlfred Perlstein /**
3316c9f432b7SAlfred Perlstein  * ib_alloc_xrcd - Allocates an XRC domain.
3317c9f432b7SAlfred Perlstein  * @device: The device on which to allocate the XRC domain.
3318c9f432b7SAlfred Perlstein  */
3319c9f432b7SAlfred Perlstein struct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
3320aa0a1e58SJeff Roberson 
3321aa0a1e58SJeff Roberson /**
3322c9f432b7SAlfred Perlstein  * ib_dealloc_xrcd - Deallocates an XRC domain.
3323c9f432b7SAlfred Perlstein  * @xrcd: The XRC domain to deallocate.
3324aa0a1e58SJeff Roberson  */
3325aa0a1e58SJeff Roberson int ib_dealloc_xrcd(struct ib_xrcd *xrcd);
3326aa0a1e58SJeff Roberson 
3327b5c1e0cbSHans Petter Selasky struct ib_flow *ib_create_flow(struct ib_qp *qp,
3328b5c1e0cbSHans Petter Selasky 			       struct ib_flow_attr *flow_attr, int domain);
3329b5c1e0cbSHans Petter Selasky int ib_destroy_flow(struct ib_flow *flow_id);
3330b5c1e0cbSHans Petter Selasky 
3331b5c1e0cbSHans Petter Selasky static inline int ib_check_mr_access(int flags)
3332b5c1e0cbSHans Petter Selasky {
3333b5c1e0cbSHans Petter Selasky 	/*
3334b5c1e0cbSHans Petter Selasky 	 * Local write permission is required if remote write or
3335b5c1e0cbSHans Petter Selasky 	 * remote atomic permission is also requested.
3336b5c1e0cbSHans Petter Selasky 	 */
3337b5c1e0cbSHans Petter Selasky 	if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
3338b5c1e0cbSHans Petter Selasky 	    !(flags & IB_ACCESS_LOCAL_WRITE))
3339b5c1e0cbSHans Petter Selasky 		return -EINVAL;
3340b5c1e0cbSHans Petter Selasky 
3341b5c1e0cbSHans Petter Selasky 	return 0;
3342b5c1e0cbSHans Petter Selasky }
3343b5c1e0cbSHans Petter Selasky 
3344b5c1e0cbSHans Petter Selasky /**
3345b5c1e0cbSHans Petter Selasky  * ib_check_mr_status: lightweight check of MR status.
3346b5c1e0cbSHans Petter Selasky  *     This routine may provide status checks on a selected
3347b5c1e0cbSHans Petter Selasky  *     ib_mr. first use is for signature status check.
3348b5c1e0cbSHans Petter Selasky  *
3349b5c1e0cbSHans Petter Selasky  * @mr: A memory region.
3350b5c1e0cbSHans Petter Selasky  * @check_mask: Bitmask of which checks to perform from
3351b5c1e0cbSHans Petter Selasky  *     ib_mr_status_check enumeration.
3352b5c1e0cbSHans Petter Selasky  * @mr_status: The container of relevant status checks.
3353b5c1e0cbSHans Petter Selasky  *     failed checks will be indicated in the status bitmask
3354b5c1e0cbSHans Petter Selasky  *     and the relevant info shall be in the error item.
3355b5c1e0cbSHans Petter Selasky  */
3356b5c1e0cbSHans Petter Selasky int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
3357b5c1e0cbSHans Petter Selasky 		       struct ib_mr_status *mr_status);
3358aa0a1e58SJeff Roberson 
33591411f52fSBjoern A. Zeeb struct ifnet *ib_get_net_dev_by_params(struct ib_device *dev, u8 port,
3360478d3005SHans Petter Selasky 					    u16 pkey, const union ib_gid *gid,
3361478d3005SHans Petter Selasky 					    const struct sockaddr *addr);
3362478d3005SHans Petter Selasky struct ib_wq *ib_create_wq(struct ib_pd *pd,
3363478d3005SHans Petter Selasky 			   struct ib_wq_init_attr *init_attr);
3364478d3005SHans Petter Selasky int ib_destroy_wq(struct ib_wq *wq);
3365478d3005SHans Petter Selasky int ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *attr,
3366478d3005SHans Petter Selasky 		 u32 wq_attr_mask);
3367478d3005SHans Petter Selasky struct ib_rwq_ind_table *ib_create_rwq_ind_table(struct ib_device *device,
3368478d3005SHans Petter Selasky 						 struct ib_rwq_ind_table_init_attr*
3369478d3005SHans Petter Selasky 						 wq_ind_table_init_attr);
3370478d3005SHans Petter Selasky int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
3371478d3005SHans Petter Selasky 
3372478d3005SHans Petter Selasky int ib_map_mr_sg(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
3373478d3005SHans Petter Selasky 		 unsigned int *sg_offset, unsigned int page_size);
3374478d3005SHans Petter Selasky 
3375478d3005SHans Petter Selasky static inline int
3376478d3005SHans Petter Selasky ib_map_mr_sg_zbva(struct ib_mr *mr, struct scatterlist *sg, int sg_nents,
3377478d3005SHans Petter Selasky 		  unsigned int *sg_offset, unsigned int page_size)
3378478d3005SHans Petter Selasky {
3379478d3005SHans Petter Selasky 	int n;
3380478d3005SHans Petter Selasky 
3381478d3005SHans Petter Selasky 	n = ib_map_mr_sg(mr, sg, sg_nents, sg_offset, page_size);
3382478d3005SHans Petter Selasky 	mr->iova = 0;
3383478d3005SHans Petter Selasky 
3384478d3005SHans Petter Selasky 	return n;
3385478d3005SHans Petter Selasky }
3386478d3005SHans Petter Selasky 
3387478d3005SHans Petter Selasky int ib_sg_to_pages(struct ib_mr *mr, struct scatterlist *sgl, int sg_nents,
3388478d3005SHans Petter Selasky 		unsigned int *sg_offset, int (*set_page)(struct ib_mr *, u64));
3389478d3005SHans Petter Selasky 
3390478d3005SHans Petter Selasky void ib_drain_rq(struct ib_qp *qp);
3391478d3005SHans Petter Selasky void ib_drain_sq(struct ib_qp *qp);
3392478d3005SHans Petter Selasky void ib_drain_qp(struct ib_qp *qp);
33931456d97cSHans Petter Selasky 
3394*79b81708SHans Petter Selasky struct ib_ucontext *ib_uverbs_get_ucontext_file(struct ib_uverbs_file *ufile);
3395*79b81708SHans Petter Selasky 
33961456d97cSHans Petter Selasky int ib_resolve_eth_dmac(struct ib_device *device,
33971456d97cSHans Petter Selasky 			struct ib_ah_attr *ah_attr);
3398aa0a1e58SJeff Roberson #endif /* IB_VERBS_H */
3399