1219820Sjeff/*
2219820Sjeff * Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
3219820Sjeff * Copyright (c) 2004 Infinicon Corporation.  All rights reserved.
4219820Sjeff * Copyright (c) 2004 Intel Corporation.  All rights reserved.
5219820Sjeff * Copyright (c) 2004 Topspin Corporation.  All rights reserved.
6219820Sjeff * Copyright (c) 2004 Voltaire Corporation.  All rights reserved.
7219820Sjeff * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
8219820Sjeff * Copyright (c) 2005, 2006, 2007 Cisco Systems.  All rights reserved.
9219820Sjeff *
10219820Sjeff * This software is available to you under a choice of one of two
11219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
12219820Sjeff * General Public License (GPL) Version 2, available from the file
13219820Sjeff * COPYING in the main directory of this source tree, or the
14219820Sjeff * OpenIB.org BSD license below:
15219820Sjeff *
16219820Sjeff *     Redistribution and use in source and binary forms, with or
17219820Sjeff *     without modification, are permitted provided that the following
18219820Sjeff *     conditions are met:
19219820Sjeff *
20219820Sjeff *      - Redistributions of source code must retain the above
21219820Sjeff *        copyright notice, this list of conditions and the following
22219820Sjeff *        disclaimer.
23219820Sjeff *
24219820Sjeff *      - Redistributions in binary form must reproduce the above
25219820Sjeff *        copyright notice, this list of conditions and the following
26219820Sjeff *        disclaimer in the documentation and/or other materials
27219820Sjeff *        provided with the distribution.
28219820Sjeff *
29219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36219820Sjeff * SOFTWARE.
37219820Sjeff */
38219820Sjeff
39219820Sjeff#if !defined(IB_VERBS_H)
40219820Sjeff#define IB_VERBS_H
41219820Sjeff
42219820Sjeff#include <linux/types.h>
43219820Sjeff#include <linux/device.h>
44219820Sjeff#include <linux/mm.h>
45219820Sjeff#include <linux/dma-mapping.h>
46219820Sjeff#include <linux/kref.h>
47219820Sjeff#include <linux/list.h>
48219820Sjeff#include <linux/rwsem.h>
49219820Sjeff#include <linux/scatterlist.h>
50219820Sjeff
51219820Sjeff#include <asm/atomic.h>
52219820Sjeff#include <asm/uaccess.h>
53219820Sjeff#include <linux/rbtree.h>
54219820Sjeff#include <linux/mutex.h>
55219820Sjeff
56219820Sjeffunion ib_gid {
57219820Sjeff	u8	raw[16];
58219820Sjeff	struct {
59219820Sjeff		__be64	subnet_prefix;
60219820Sjeff		__be64	interface_id;
61219820Sjeff	} global;
62219820Sjeff};
63219820Sjeff
64219820Sjeffenum rdma_node_type {
65219820Sjeff	/* IB values map to NodeInfo:NodeType. */
66219820Sjeff	RDMA_NODE_IB_CA 	= 1,
67219820Sjeff	RDMA_NODE_IB_SWITCH,
68219820Sjeff	RDMA_NODE_IB_ROUTER,
69219820Sjeff	RDMA_NODE_RNIC
70219820Sjeff};
71219820Sjeff
72219820Sjeffenum rdma_transport_type {
73219820Sjeff	RDMA_TRANSPORT_IB,
74219820Sjeff	RDMA_TRANSPORT_IWARP
75219820Sjeff};
76219820Sjeff
77219820Sjeffenum rdma_transport_type
78219820Sjeffrdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
79219820Sjeff
80219820Sjeffenum rdma_link_layer {
81219820Sjeff	IB_LINK_LAYER_UNSPECIFIED,
82219820Sjeff	IB_LINK_LAYER_INFINIBAND,
83219820Sjeff	IB_LINK_LAYER_ETHERNET,
84219820Sjeff};
85219820Sjeff
86219820Sjeffenum ib_device_cap_flags {
87219820Sjeff	IB_DEVICE_RESIZE_MAX_WR		= 1,
88219820Sjeff	IB_DEVICE_BAD_PKEY_CNTR		= (1<<1),
89219820Sjeff	IB_DEVICE_BAD_QKEY_CNTR		= (1<<2),
90219820Sjeff	IB_DEVICE_RAW_MULTI		= (1<<3),
91219820Sjeff	IB_DEVICE_AUTO_PATH_MIG		= (1<<4),
92219820Sjeff	IB_DEVICE_CHANGE_PHY_PORT	= (1<<5),
93219820Sjeff	IB_DEVICE_UD_AV_PORT_ENFORCE	= (1<<6),
94219820Sjeff	IB_DEVICE_CURR_QP_STATE_MOD	= (1<<7),
95219820Sjeff	IB_DEVICE_SHUTDOWN_PORT		= (1<<8),
96219820Sjeff	IB_DEVICE_INIT_TYPE		= (1<<9),
97219820Sjeff	IB_DEVICE_PORT_ACTIVE_EVENT	= (1<<10),
98219820Sjeff	IB_DEVICE_SYS_IMAGE_GUID	= (1<<11),
99219820Sjeff	IB_DEVICE_RC_RNR_NAK_GEN	= (1<<12),
100219820Sjeff	IB_DEVICE_SRQ_RESIZE		= (1<<13),
101219820Sjeff	IB_DEVICE_N_NOTIFY_CQ		= (1<<14),
102219820Sjeff	IB_DEVICE_LOCAL_DMA_LKEY	= (1<<15),
103219820Sjeff	IB_DEVICE_RESERVED		= (1<<16), /* old SEND_W_INV */
104219820Sjeff	IB_DEVICE_MEM_WINDOW		= (1<<17),
105219820Sjeff	/*
106219820Sjeff	 * Devices should set IB_DEVICE_UD_IP_SUM if they support
107219820Sjeff	 * insertion of UDP and TCP checksum on outgoing UD IPoIB
108219820Sjeff	 * messages and can verify the validity of checksum for
109219820Sjeff	 * incoming messages.  Setting this flag implies that the
110219820Sjeff	 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
111219820Sjeff	 */
112219820Sjeff	IB_DEVICE_UD_IP_CSUM		= (1<<18),
113219820Sjeff	IB_DEVICE_UD_TSO		= (1<<19),
114219820Sjeff	IB_DEVICE_XRC			= (1<<20),
115219820Sjeff	IB_DEVICE_MEM_MGT_EXTENSIONS	= (1<<21),
116219820Sjeff	IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
117219820Sjeff};
118219820Sjeff
119219820Sjeffenum ib_atomic_cap {
120219820Sjeff	IB_ATOMIC_NONE,
121219820Sjeff	IB_ATOMIC_HCA,
122219820Sjeff	IB_ATOMIC_GLOB
123219820Sjeff};
124219820Sjeff
125219820Sjeffstruct ib_device_attr {
126219820Sjeff	u64			fw_ver;
127219820Sjeff	__be64			sys_image_guid;
128219820Sjeff	u64			max_mr_size;
129219820Sjeff	u64			page_size_cap;
130219820Sjeff	u32			vendor_id;
131219820Sjeff	u32			vendor_part_id;
132219820Sjeff	u32			hw_ver;
133219820Sjeff	int			max_qp;
134219820Sjeff	int			max_qp_wr;
135219820Sjeff	int			device_cap_flags;
136219820Sjeff	int			max_sge;
137219820Sjeff	int			max_sge_rd;
138219820Sjeff	int			max_cq;
139219820Sjeff	int			max_cqe;
140219820Sjeff	int			max_mr;
141219820Sjeff	int			max_pd;
142219820Sjeff	int			max_qp_rd_atom;
143219820Sjeff	int			max_ee_rd_atom;
144219820Sjeff	int			max_res_rd_atom;
145219820Sjeff	int			max_qp_init_rd_atom;
146219820Sjeff	int			max_ee_init_rd_atom;
147219820Sjeff	enum ib_atomic_cap	atomic_cap;
148219820Sjeff	enum ib_atomic_cap	masked_atomic_cap;
149219820Sjeff	int			max_ee;
150219820Sjeff	int			max_rdd;
151219820Sjeff	int			max_mw;
152219820Sjeff	int			max_raw_ipv6_qp;
153219820Sjeff	int			max_raw_ethy_qp;
154219820Sjeff	int			max_mcast_grp;
155219820Sjeff	int			max_mcast_qp_attach;
156219820Sjeff	int			max_total_mcast_qp_attach;
157219820Sjeff	int			max_ah;
158219820Sjeff	int			max_fmr;
159219820Sjeff	int			max_map_per_fmr;
160219820Sjeff	int			max_srq;
161219820Sjeff	int			max_srq_wr;
162219820Sjeff	int			max_srq_sge;
163219820Sjeff	unsigned int		max_fast_reg_page_list_len;
164219820Sjeff	u16			max_pkeys;
165219820Sjeff	u8			local_ca_ack_delay;
166219820Sjeff};
167219820Sjeff
168219820Sjeffenum ib_mtu {
169219820Sjeff	IB_MTU_256  = 1,
170219820Sjeff	IB_MTU_512  = 2,
171219820Sjeff	IB_MTU_1024 = 3,
172219820Sjeff	IB_MTU_2048 = 4,
173219820Sjeff	IB_MTU_4096 = 5
174219820Sjeff};
175219820Sjeff
176219820Sjeffstatic inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
177219820Sjeff{
178219820Sjeff	switch (mtu) {
179219820Sjeff	case IB_MTU_256:  return  256;
180219820Sjeff	case IB_MTU_512:  return  512;
181219820Sjeff	case IB_MTU_1024: return 1024;
182219820Sjeff	case IB_MTU_2048: return 2048;
183219820Sjeff	case IB_MTU_4096: return 4096;
184219820Sjeff	default: 	  return -1;
185219820Sjeff	}
186219820Sjeff}
187219820Sjeff
188219820Sjeffenum ib_port_state {
189219820Sjeff	IB_PORT_NOP		= 0,
190219820Sjeff	IB_PORT_DOWN		= 1,
191219820Sjeff	IB_PORT_INIT		= 2,
192219820Sjeff	IB_PORT_ARMED		= 3,
193219820Sjeff	IB_PORT_ACTIVE		= 4,
194219820Sjeff	IB_PORT_ACTIVE_DEFER	= 5
195219820Sjeff};
196219820Sjeff
197219820Sjeffenum ib_port_cap_flags {
198219820Sjeff	IB_PORT_SM				= 1 <<  1,
199219820Sjeff	IB_PORT_NOTICE_SUP			= 1 <<  2,
200219820Sjeff	IB_PORT_TRAP_SUP			= 1 <<  3,
201219820Sjeff	IB_PORT_OPT_IPD_SUP                     = 1 <<  4,
202219820Sjeff	IB_PORT_AUTO_MIGR_SUP			= 1 <<  5,
203219820Sjeff	IB_PORT_SL_MAP_SUP			= 1 <<  6,
204219820Sjeff	IB_PORT_MKEY_NVRAM			= 1 <<  7,
205219820Sjeff	IB_PORT_PKEY_NVRAM			= 1 <<  8,
206219820Sjeff	IB_PORT_LED_INFO_SUP			= 1 <<  9,
207219820Sjeff	IB_PORT_SM_DISABLED			= 1 << 10,
208219820Sjeff	IB_PORT_SYS_IMAGE_GUID_SUP		= 1 << 11,
209219820Sjeff	IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP	= 1 << 12,
210219820Sjeff	IB_PORT_CM_SUP				= 1 << 16,
211219820Sjeff	IB_PORT_SNMP_TUNNEL_SUP			= 1 << 17,
212219820Sjeff	IB_PORT_REINIT_SUP			= 1 << 18,
213219820Sjeff	IB_PORT_DEVICE_MGMT_SUP			= 1 << 19,
214219820Sjeff	IB_PORT_VENDOR_CLASS_SUP		= 1 << 20,
215219820Sjeff	IB_PORT_DR_NOTICE_SUP			= 1 << 21,
216219820Sjeff	IB_PORT_CAP_MASK_NOTICE_SUP		= 1 << 22,
217219820Sjeff	IB_PORT_BOOT_MGMT_SUP			= 1 << 23,
218219820Sjeff	IB_PORT_LINK_LATENCY_SUP		= 1 << 24,
219219820Sjeff	IB_PORT_CLIENT_REG_SUP			= 1 << 25
220219820Sjeff};
221219820Sjeff
222219820Sjeffenum ib_port_width {
223219820Sjeff	IB_WIDTH_1X	= 1,
224219820Sjeff	IB_WIDTH_4X	= 2,
225219820Sjeff	IB_WIDTH_8X	= 4,
226219820Sjeff	IB_WIDTH_12X	= 8
227219820Sjeff};
228219820Sjeff
229219820Sjeffstatic inline int ib_width_enum_to_int(enum ib_port_width width)
230219820Sjeff{
231219820Sjeff	switch (width) {
232219820Sjeff	case IB_WIDTH_1X:  return  1;
233219820Sjeff	case IB_WIDTH_4X:  return  4;
234219820Sjeff	case IB_WIDTH_8X:  return  8;
235219820Sjeff	case IB_WIDTH_12X: return 12;
236219820Sjeff	default: 	  return -1;
237219820Sjeff	}
238219820Sjeff}
239219820Sjeff
240219820Sjeffstruct ib_protocol_stats {
241219820Sjeff	/* TBD... */
242219820Sjeff};
243219820Sjeff
244219820Sjeffstruct iw_protocol_stats {
245219820Sjeff	u64	ipInReceives;
246219820Sjeff	u64	ipInHdrErrors;
247219820Sjeff	u64	ipInTooBigErrors;
248219820Sjeff	u64	ipInNoRoutes;
249219820Sjeff	u64	ipInAddrErrors;
250219820Sjeff	u64	ipInUnknownProtos;
251219820Sjeff	u64	ipInTruncatedPkts;
252219820Sjeff	u64	ipInDiscards;
253219820Sjeff	u64	ipInDelivers;
254219820Sjeff	u64	ipOutForwDatagrams;
255219820Sjeff	u64	ipOutRequests;
256219820Sjeff	u64	ipOutDiscards;
257219820Sjeff	u64	ipOutNoRoutes;
258219820Sjeff	u64	ipReasmTimeout;
259219820Sjeff	u64	ipReasmReqds;
260219820Sjeff	u64	ipReasmOKs;
261219820Sjeff	u64	ipReasmFails;
262219820Sjeff	u64	ipFragOKs;
263219820Sjeff	u64	ipFragFails;
264219820Sjeff	u64	ipFragCreates;
265219820Sjeff	u64	ipInMcastPkts;
266219820Sjeff	u64	ipOutMcastPkts;
267219820Sjeff	u64	ipInBcastPkts;
268219820Sjeff	u64	ipOutBcastPkts;
269219820Sjeff
270219820Sjeff	u64	tcpRtoAlgorithm;
271219820Sjeff	u64	tcpRtoMin;
272219820Sjeff	u64	tcpRtoMax;
273219820Sjeff	u64	tcpMaxConn;
274219820Sjeff	u64	tcpActiveOpens;
275219820Sjeff	u64	tcpPassiveOpens;
276219820Sjeff	u64	tcpAttemptFails;
277219820Sjeff	u64	tcpEstabResets;
278219820Sjeff	u64	tcpCurrEstab;
279219820Sjeff	u64	tcpInSegs;
280219820Sjeff	u64	tcpOutSegs;
281219820Sjeff	u64	tcpRetransSegs;
282219820Sjeff	u64	tcpInErrs;
283219820Sjeff	u64	tcpOutRsts;
284219820Sjeff};
285219820Sjeff
286219820Sjeffunion rdma_protocol_stats {
287219820Sjeff	struct ib_protocol_stats	ib;
288219820Sjeff	struct iw_protocol_stats	iw;
289219820Sjeff};
290219820Sjeff
291219820Sjeffstruct ib_port_attr {
292219820Sjeff	enum ib_port_state	state;
293219820Sjeff	enum ib_mtu		max_mtu;
294219820Sjeff	enum ib_mtu		active_mtu;
295219820Sjeff	int			gid_tbl_len;
296219820Sjeff	u32			port_cap_flags;
297219820Sjeff	u32			max_msg_sz;
298219820Sjeff	u32			bad_pkey_cntr;
299219820Sjeff	u32			qkey_viol_cntr;
300219820Sjeff	u16			pkey_tbl_len;
301219820Sjeff	u16			lid;
302219820Sjeff	u16			sm_lid;
303219820Sjeff	u8			lmc;
304219820Sjeff	u8			max_vl_num;
305219820Sjeff	u8			sm_sl;
306219820Sjeff	u8			subnet_timeout;
307219820Sjeff	u8			init_type_reply;
308219820Sjeff	u8			active_width;
309219820Sjeff	u8			active_speed;
310219820Sjeff	u8                      phys_state;
311219820Sjeff	enum rdma_link_layer	link_layer;
312219820Sjeff};
313219820Sjeff
314219820Sjeffenum ib_device_modify_flags {
315219820Sjeff	IB_DEVICE_MODIFY_SYS_IMAGE_GUID	= 1 << 0,
316219820Sjeff	IB_DEVICE_MODIFY_NODE_DESC	= 1 << 1
317219820Sjeff};
318219820Sjeff
319219820Sjeffstruct ib_device_modify {
320219820Sjeff	u64	sys_image_guid;
321219820Sjeff	char	node_desc[64];
322219820Sjeff};
323219820Sjeff
324219820Sjeffenum ib_port_modify_flags {
325219820Sjeff	IB_PORT_SHUTDOWN		= 1,
326219820Sjeff	IB_PORT_INIT_TYPE		= (1<<2),
327219820Sjeff	IB_PORT_RESET_QKEY_CNTR		= (1<<3)
328219820Sjeff};
329219820Sjeff
330219820Sjeffstruct ib_port_modify {
331219820Sjeff	u32	set_port_cap_mask;
332219820Sjeff	u32	clr_port_cap_mask;
333219820Sjeff	u8	init_type;
334219820Sjeff};
335219820Sjeff
336219820Sjeffenum ib_event_type {
337219820Sjeff	IB_EVENT_CQ_ERR,
338219820Sjeff	IB_EVENT_QP_FATAL,
339219820Sjeff	IB_EVENT_QP_REQ_ERR,
340219820Sjeff	IB_EVENT_QP_ACCESS_ERR,
341219820Sjeff	IB_EVENT_COMM_EST,
342219820Sjeff	IB_EVENT_SQ_DRAINED,
343219820Sjeff	IB_EVENT_PATH_MIG,
344219820Sjeff	IB_EVENT_PATH_MIG_ERR,
345219820Sjeff	IB_EVENT_DEVICE_FATAL,
346219820Sjeff	IB_EVENT_PORT_ACTIVE,
347219820Sjeff	IB_EVENT_PORT_ERR,
348219820Sjeff	IB_EVENT_LID_CHANGE,
349219820Sjeff	IB_EVENT_PKEY_CHANGE,
350219820Sjeff	IB_EVENT_SM_CHANGE,
351219820Sjeff	IB_EVENT_SRQ_ERR,
352219820Sjeff	IB_EVENT_SRQ_LIMIT_REACHED,
353219820Sjeff	IB_EVENT_QP_LAST_WQE_REACHED,
354219820Sjeff	IB_EVENT_CLIENT_REREGISTER,
355219820Sjeff	IB_EVENT_GID_CHANGE,
356219820Sjeff};
357219820Sjeff
358219820Sjeffenum ib_event_flags {
359219820Sjeff	IB_XRC_QP_EVENT_FLAG = 0x80000000,
360219820Sjeff};
361219820Sjeff
362219820Sjeffstruct ib_event {
363219820Sjeff	struct ib_device	*device;
364219820Sjeff	union {
365219820Sjeff		struct ib_cq	*cq;
366219820Sjeff		struct ib_qp	*qp;
367219820Sjeff		struct ib_srq	*srq;
368219820Sjeff		u8		port_num;
369219820Sjeff		u32		xrc_qp_num;
370219820Sjeff	} element;
371219820Sjeff	enum ib_event_type	event;
372219820Sjeff};
373219820Sjeff
374219820Sjeffstruct ib_event_handler {
375219820Sjeff	struct ib_device *device;
376219820Sjeff	void            (*handler)(struct ib_event_handler *, struct ib_event *);
377219820Sjeff	struct list_head  list;
378219820Sjeff};
379219820Sjeff
380219820Sjeff#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler)		\
381219820Sjeff	do {							\
382219820Sjeff		(_ptr)->device  = _device;			\
383219820Sjeff		(_ptr)->handler = _handler;			\
384219820Sjeff		INIT_LIST_HEAD(&(_ptr)->list);			\
385219820Sjeff	} while (0)
386219820Sjeff
387219820Sjeffstruct ib_global_route {
388219820Sjeff	union ib_gid	dgid;
389219820Sjeff	u32		flow_label;
390219820Sjeff	u8		sgid_index;
391219820Sjeff	u8		hop_limit;
392219820Sjeff	u8		traffic_class;
393219820Sjeff};
394219820Sjeff
395219820Sjeffstruct ib_grh {
396219820Sjeff	__be32		version_tclass_flow;
397219820Sjeff	__be16		paylen;
398219820Sjeff	u8		next_hdr;
399219820Sjeff	u8		hop_limit;
400219820Sjeff	union ib_gid	sgid;
401219820Sjeff	union ib_gid	dgid;
402219820Sjeff};
403219820Sjeff
404219820Sjeffenum {
405219820Sjeff	IB_MULTICAST_QPN = 0xffffff
406219820Sjeff};
407219820Sjeff
408219820Sjeff#define IB_LID_PERMISSIVE	cpu_to_be16(0xFFFF)
409219820Sjeff
410219820Sjeffenum ib_ah_flags {
411219820Sjeff	IB_AH_GRH	= 1
412219820Sjeff};
413219820Sjeff
414219820Sjeffenum ib_rate {
415219820Sjeff	IB_RATE_PORT_CURRENT = 0,
416219820Sjeff	IB_RATE_2_5_GBPS = 2,
417219820Sjeff	IB_RATE_5_GBPS   = 5,
418219820Sjeff	IB_RATE_10_GBPS  = 3,
419219820Sjeff	IB_RATE_20_GBPS  = 6,
420219820Sjeff	IB_RATE_30_GBPS  = 4,
421219820Sjeff	IB_RATE_40_GBPS  = 7,
422219820Sjeff	IB_RATE_60_GBPS  = 8,
423219820Sjeff	IB_RATE_80_GBPS  = 9,
424219820Sjeff	IB_RATE_120_GBPS = 10
425219820Sjeff};
426219820Sjeff
427219820Sjeff/**
428219820Sjeff * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
429219820Sjeff * base rate of 2.5 Gbit/sec.  For example, IB_RATE_5_GBPS will be
430219820Sjeff * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
431219820Sjeff * @rate: rate to convert.
432219820Sjeff */
433219820Sjeffint ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
434219820Sjeff
435219820Sjeff/**
436219820Sjeff * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
437219820Sjeff * enum.
438219820Sjeff * @mult: multiple to convert.
439219820Sjeff */
440219820Sjeffenum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
441219820Sjeff
442219820Sjeffstruct ib_ah_attr {
443219820Sjeff	struct ib_global_route	grh;
444219820Sjeff	u16			dlid;
445219820Sjeff	u8			sl;
446219820Sjeff	u8			src_path_bits;
447219820Sjeff	u8			static_rate;
448219820Sjeff	u8			ah_flags;
449219820Sjeff	u8			port_num;
450219820Sjeff};
451219820Sjeff
452219820Sjeffenum ib_wc_status {
453219820Sjeff	IB_WC_SUCCESS,
454219820Sjeff	IB_WC_LOC_LEN_ERR,
455219820Sjeff	IB_WC_LOC_QP_OP_ERR,
456219820Sjeff	IB_WC_LOC_EEC_OP_ERR,
457219820Sjeff	IB_WC_LOC_PROT_ERR,
458219820Sjeff	IB_WC_WR_FLUSH_ERR,
459219820Sjeff	IB_WC_MW_BIND_ERR,
460219820Sjeff	IB_WC_BAD_RESP_ERR,
461219820Sjeff	IB_WC_LOC_ACCESS_ERR,
462219820Sjeff	IB_WC_REM_INV_REQ_ERR,
463219820Sjeff	IB_WC_REM_ACCESS_ERR,
464219820Sjeff	IB_WC_REM_OP_ERR,
465219820Sjeff	IB_WC_RETRY_EXC_ERR,
466219820Sjeff	IB_WC_RNR_RETRY_EXC_ERR,
467219820Sjeff	IB_WC_LOC_RDD_VIOL_ERR,
468219820Sjeff	IB_WC_REM_INV_RD_REQ_ERR,
469219820Sjeff	IB_WC_REM_ABORT_ERR,
470219820Sjeff	IB_WC_INV_EECN_ERR,
471219820Sjeff	IB_WC_INV_EEC_STATE_ERR,
472219820Sjeff	IB_WC_FATAL_ERR,
473219820Sjeff	IB_WC_RESP_TIMEOUT_ERR,
474219820Sjeff	IB_WC_GENERAL_ERR
475219820Sjeff};
476219820Sjeff
477219820Sjeffenum ib_wc_opcode {
478219820Sjeff	IB_WC_SEND,
479219820Sjeff	IB_WC_RDMA_WRITE,
480219820Sjeff	IB_WC_RDMA_READ,
481219820Sjeff	IB_WC_COMP_SWAP,
482219820Sjeff	IB_WC_FETCH_ADD,
483219820Sjeff	IB_WC_BIND_MW,
484219820Sjeff	IB_WC_LSO,
485219820Sjeff	IB_WC_LOCAL_INV,
486219820Sjeff	IB_WC_FAST_REG_MR,
487219820Sjeff	IB_WC_MASKED_COMP_SWAP,
488219820Sjeff	IB_WC_MASKED_FETCH_ADD,
489219820Sjeff/*
490219820Sjeff * Set value of IB_WC_RECV so consumers can test if a completion is a
491219820Sjeff * receive by testing (opcode & IB_WC_RECV).
492219820Sjeff */
493219820Sjeff	IB_WC_RECV			= 1 << 7,
494219820Sjeff	IB_WC_RECV_RDMA_WITH_IMM
495219820Sjeff};
496219820Sjeff
497219820Sjeffenum ib_wc_flags {
498219820Sjeff	IB_WC_GRH		= 1,
499219820Sjeff	IB_WC_WITH_IMM		= (1<<1),
500219820Sjeff	IB_WC_WITH_INVALIDATE	= (1<<2),
501219820Sjeff};
502219820Sjeff
503219820Sjeffstruct ib_wc {
504219820Sjeff	u64			wr_id;
505219820Sjeff	enum ib_wc_status	status;
506219820Sjeff	enum ib_wc_opcode	opcode;
507219820Sjeff	u32			vendor_err;
508219820Sjeff	u32			byte_len;
509219820Sjeff	struct ib_qp	       *qp;
510219820Sjeff	union {
511219820Sjeff		__be32		imm_data;
512219820Sjeff		u32		invalidate_rkey;
513219820Sjeff	} ex;
514219820Sjeff	u32			src_qp;
515219820Sjeff	int			wc_flags;
516219820Sjeff	u16			pkey_index;
517219820Sjeff	u16			slid;
518219820Sjeff	u8			sl;
519219820Sjeff	u8			dlid_path_bits;
520219820Sjeff	u8			port_num;	/* valid only for DR SMPs on switches */
521219820Sjeff	int			csum_ok;
522219820Sjeff};
523219820Sjeff
524219820Sjeffenum ib_cq_notify_flags {
525219820Sjeff	IB_CQ_SOLICITED			= 1 << 0,
526219820Sjeff	IB_CQ_NEXT_COMP			= 1 << 1,
527219820Sjeff	IB_CQ_SOLICITED_MASK		= IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
528219820Sjeff	IB_CQ_REPORT_MISSED_EVENTS	= 1 << 2,
529219820Sjeff};
530219820Sjeff
531219820Sjeffenum ib_srq_attr_mask {
532219820Sjeff	IB_SRQ_MAX_WR	= 1 << 0,
533219820Sjeff	IB_SRQ_LIMIT	= 1 << 1,
534219820Sjeff};
535219820Sjeff
536219820Sjeffstruct ib_srq_attr {
537219820Sjeff	u32	max_wr;
538219820Sjeff	u32	max_sge;
539219820Sjeff	u32	srq_limit;
540219820Sjeff};
541219820Sjeff
542219820Sjeffstruct ib_srq_init_attr {
543219820Sjeff	void		      (*event_handler)(struct ib_event *, void *);
544219820Sjeff	void		       *srq_context;
545219820Sjeff	struct ib_srq_attr	attr;
546219820Sjeff};
547219820Sjeff
548219820Sjeffstruct ib_qp_cap {
549219820Sjeff	u32	max_send_wr;
550219820Sjeff	u32	max_recv_wr;
551219820Sjeff	u32	max_send_sge;
552219820Sjeff	u32	max_recv_sge;
553219820Sjeff	u32	max_inline_data;
554219820Sjeff};
555219820Sjeff
556219820Sjeffenum ib_sig_type {
557219820Sjeff	IB_SIGNAL_ALL_WR,
558219820Sjeff	IB_SIGNAL_REQ_WR
559219820Sjeff};
560219820Sjeff
561219820Sjeffenum ib_qp_type {
562219820Sjeff	/*
563219820Sjeff	 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
564219820Sjeff	 * here (and in that order) since the MAD layer uses them as
565219820Sjeff	 * indices into a 2-entry table.
566219820Sjeff	 */
567219820Sjeff	IB_QPT_SMI,
568219820Sjeff	IB_QPT_GSI,
569219820Sjeff
570219820Sjeff	IB_QPT_RC,
571219820Sjeff	IB_QPT_UC,
572219820Sjeff	IB_QPT_UD,
573219820Sjeff	IB_QPT_XRC,
574219820Sjeff	IB_QPT_RAW_IPV6,
575219820Sjeff	IB_QPT_RAW_ETY,
576219820Sjeff	IB_QPT_RAW_ETH
577219820Sjeff};
578219820Sjeff
579219820Sjeffenum ib_qp_create_flags {
580219820Sjeff	IB_QP_CREATE_IPOIB_UD_LSO		= 1 << 0,
581219820Sjeff	IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK	= 1 << 1,
582219820Sjeff};
583219820Sjeff
584219820Sjeffstruct ib_qp_init_attr {
585219820Sjeff	void                  (*event_handler)(struct ib_event *, void *);
586219820Sjeff	void		       *qp_context;
587219820Sjeff	struct ib_cq	       *send_cq;
588219820Sjeff	struct ib_cq	       *recv_cq;
589219820Sjeff	struct ib_srq	       *srq;
590219820Sjeff	struct ib_qp_cap	cap;
591219820Sjeff	enum ib_sig_type	sq_sig_type;
592219820Sjeff	enum ib_qp_type		qp_type;
593219820Sjeff	enum ib_qp_create_flags	create_flags;
594219820Sjeff	struct ib_xrcd	       *xrc_domain; /* XRC qp's only */
595219820Sjeff	u8			port_num; /* special QP types only */
596219820Sjeff};
597219820Sjeff
598219820Sjeffenum ib_rnr_timeout {
599219820Sjeff	IB_RNR_TIMER_655_36 =  0,
600219820Sjeff	IB_RNR_TIMER_000_01 =  1,
601219820Sjeff	IB_RNR_TIMER_000_02 =  2,
602219820Sjeff	IB_RNR_TIMER_000_03 =  3,
603219820Sjeff	IB_RNR_TIMER_000_04 =  4,
604219820Sjeff	IB_RNR_TIMER_000_06 =  5,
605219820Sjeff	IB_RNR_TIMER_000_08 =  6,
606219820Sjeff	IB_RNR_TIMER_000_12 =  7,
607219820Sjeff	IB_RNR_TIMER_000_16 =  8,
608219820Sjeff	IB_RNR_TIMER_000_24 =  9,
609219820Sjeff	IB_RNR_TIMER_000_32 = 10,
610219820Sjeff	IB_RNR_TIMER_000_48 = 11,
611219820Sjeff	IB_RNR_TIMER_000_64 = 12,
612219820Sjeff	IB_RNR_TIMER_000_96 = 13,
613219820Sjeff	IB_RNR_TIMER_001_28 = 14,
614219820Sjeff	IB_RNR_TIMER_001_92 = 15,
615219820Sjeff	IB_RNR_TIMER_002_56 = 16,
616219820Sjeff	IB_RNR_TIMER_003_84 = 17,
617219820Sjeff	IB_RNR_TIMER_005_12 = 18,
618219820Sjeff	IB_RNR_TIMER_007_68 = 19,
619219820Sjeff	IB_RNR_TIMER_010_24 = 20,
620219820Sjeff	IB_RNR_TIMER_015_36 = 21,
621219820Sjeff	IB_RNR_TIMER_020_48 = 22,
622219820Sjeff	IB_RNR_TIMER_030_72 = 23,
623219820Sjeff	IB_RNR_TIMER_040_96 = 24,
624219820Sjeff	IB_RNR_TIMER_061_44 = 25,
625219820Sjeff	IB_RNR_TIMER_081_92 = 26,
626219820Sjeff	IB_RNR_TIMER_122_88 = 27,
627219820Sjeff	IB_RNR_TIMER_163_84 = 28,
628219820Sjeff	IB_RNR_TIMER_245_76 = 29,
629219820Sjeff	IB_RNR_TIMER_327_68 = 30,
630219820Sjeff	IB_RNR_TIMER_491_52 = 31
631219820Sjeff};
632219820Sjeff
633219820Sjeffenum ib_qp_attr_mask {
634219820Sjeff	IB_QP_STATE			= 1,
635219820Sjeff	IB_QP_CUR_STATE			= (1<<1),
636219820Sjeff	IB_QP_EN_SQD_ASYNC_NOTIFY	= (1<<2),
637219820Sjeff	IB_QP_ACCESS_FLAGS		= (1<<3),
638219820Sjeff	IB_QP_PKEY_INDEX		= (1<<4),
639219820Sjeff	IB_QP_PORT			= (1<<5),
640219820Sjeff	IB_QP_QKEY			= (1<<6),
641219820Sjeff	IB_QP_AV			= (1<<7),
642219820Sjeff	IB_QP_PATH_MTU			= (1<<8),
643219820Sjeff	IB_QP_TIMEOUT			= (1<<9),
644219820Sjeff	IB_QP_RETRY_CNT			= (1<<10),
645219820Sjeff	IB_QP_RNR_RETRY			= (1<<11),
646219820Sjeff	IB_QP_RQ_PSN			= (1<<12),
647219820Sjeff	IB_QP_MAX_QP_RD_ATOMIC		= (1<<13),
648219820Sjeff	IB_QP_ALT_PATH			= (1<<14),
649219820Sjeff	IB_QP_MIN_RNR_TIMER		= (1<<15),
650219820Sjeff	IB_QP_SQ_PSN			= (1<<16),
651219820Sjeff	IB_QP_MAX_DEST_RD_ATOMIC	= (1<<17),
652219820Sjeff	IB_QP_PATH_MIG_STATE		= (1<<18),
653219820Sjeff	IB_QP_CAP			= (1<<19),
654219820Sjeff	IB_QP_DEST_QPN			= (1<<20)
655219820Sjeff};
656219820Sjeff
657219820Sjeffenum ib_qp_state {
658219820Sjeff	IB_QPS_RESET,
659219820Sjeff	IB_QPS_INIT,
660219820Sjeff	IB_QPS_RTR,
661219820Sjeff	IB_QPS_RTS,
662219820Sjeff	IB_QPS_SQD,
663219820Sjeff	IB_QPS_SQE,
664219820Sjeff	IB_QPS_ERR
665219820Sjeff};
666219820Sjeff
667219820Sjeffenum ib_mig_state {
668219820Sjeff	IB_MIG_MIGRATED,
669219820Sjeff	IB_MIG_REARM,
670219820Sjeff	IB_MIG_ARMED
671219820Sjeff};
672219820Sjeff
673219820Sjeffstruct ib_qp_attr {
674219820Sjeff	enum ib_qp_state	qp_state;
675219820Sjeff	enum ib_qp_state	cur_qp_state;
676219820Sjeff	enum ib_mtu		path_mtu;
677219820Sjeff	enum ib_mig_state	path_mig_state;
678219820Sjeff	u32			qkey;
679219820Sjeff	u32			rq_psn;
680219820Sjeff	u32			sq_psn;
681219820Sjeff	u32			dest_qp_num;
682219820Sjeff	int			qp_access_flags;
683219820Sjeff	struct ib_qp_cap	cap;
684219820Sjeff	struct ib_ah_attr	ah_attr;
685219820Sjeff	struct ib_ah_attr	alt_ah_attr;
686219820Sjeff	u16			pkey_index;
687219820Sjeff	u16			alt_pkey_index;
688219820Sjeff	u8			en_sqd_async_notify;
689219820Sjeff	u8			sq_draining;
690219820Sjeff	u8			max_rd_atomic;
691219820Sjeff	u8			max_dest_rd_atomic;
692219820Sjeff	u8			min_rnr_timer;
693219820Sjeff	u8			port_num;
694219820Sjeff	u8			timeout;
695219820Sjeff	u8			retry_cnt;
696219820Sjeff	u8			rnr_retry;
697219820Sjeff	u8			alt_port_num;
698219820Sjeff	u8			alt_timeout;
699219820Sjeff};
700219820Sjeff
701219820Sjeffenum ib_wr_opcode {
702219820Sjeff	IB_WR_RDMA_WRITE,
703219820Sjeff	IB_WR_RDMA_WRITE_WITH_IMM,
704219820Sjeff	IB_WR_SEND,
705219820Sjeff	IB_WR_SEND_WITH_IMM,
706219820Sjeff	IB_WR_RDMA_READ,
707219820Sjeff	IB_WR_ATOMIC_CMP_AND_SWP,
708219820Sjeff	IB_WR_ATOMIC_FETCH_AND_ADD,
709219820Sjeff	IB_WR_LSO,
710219820Sjeff	IB_WR_BIG_LSO,
711219820Sjeff	IB_WR_SEND_WITH_INV,
712219820Sjeff	IB_WR_RDMA_READ_WITH_INV,
713219820Sjeff	IB_WR_LOCAL_INV,
714219820Sjeff	IB_WR_FAST_REG_MR,
715219820Sjeff	IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
716219820Sjeff	IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
717219820Sjeff};
718219820Sjeff
719219820Sjeffenum ib_send_flags {
720219820Sjeff	IB_SEND_FENCE		= 1,
721219820Sjeff	IB_SEND_SIGNALED	= (1<<1),
722219820Sjeff	IB_SEND_SOLICITED	= (1<<2),
723219820Sjeff	IB_SEND_INLINE		= (1<<3),
724219820Sjeff	IB_SEND_IP_CSUM		= (1<<4)
725219820Sjeff};
726219820Sjeff
727219820Sjeffstruct ib_sge {
728219820Sjeff	u64	addr;
729219820Sjeff	u32	length;
730219820Sjeff	u32	lkey;
731219820Sjeff};
732219820Sjeff
733219820Sjeffstruct ib_fast_reg_page_list {
734219820Sjeff	struct ib_device       *device;
735219820Sjeff	u64		       *page_list;
736219820Sjeff	unsigned int		max_page_list_len;
737219820Sjeff};
738219820Sjeff
739219820Sjeffstruct ib_send_wr {
740219820Sjeff	struct ib_send_wr      *next;
741219820Sjeff	u64			wr_id;
742219820Sjeff	struct ib_sge	       *sg_list;
743219820Sjeff	int			num_sge;
744219820Sjeff	enum ib_wr_opcode	opcode;
745219820Sjeff	int			send_flags;
746219820Sjeff	union {
747219820Sjeff		__be32		imm_data;
748219820Sjeff		u32		invalidate_rkey;
749219820Sjeff	} ex;
750219820Sjeff	union {
751219820Sjeff		struct {
752219820Sjeff			u64	remote_addr;
753219820Sjeff			u32	rkey;
754219820Sjeff		} rdma;
755219820Sjeff		struct {
756219820Sjeff			u64	remote_addr;
757219820Sjeff			u64	compare_add;
758219820Sjeff			u64	swap;
759219820Sjeff			u64	compare_add_mask;
760219820Sjeff			u64	swap_mask;
761219820Sjeff			u32	rkey;
762219820Sjeff		} atomic;
763219820Sjeff		struct {
764219820Sjeff			struct ib_ah *ah;
765219820Sjeff			void   *header;
766219820Sjeff			int     hlen;
767219820Sjeff			int     mss;
768219820Sjeff			u32	remote_qpn;
769219820Sjeff			u32	remote_qkey;
770219820Sjeff			u16	pkey_index; /* valid for GSI only */
771219820Sjeff			u8	port_num;   /* valid for DR SMPs on switch only */
772219820Sjeff		} ud;
773219820Sjeff		struct {
774219820Sjeff			u64				iova_start;
775219820Sjeff			struct ib_fast_reg_page_list   *page_list;
776219820Sjeff			unsigned int			page_shift;
777219820Sjeff			unsigned int			page_list_len;
778219820Sjeff			u32				length;
779219820Sjeff			int				access_flags;
780219820Sjeff			u32				rkey;
781219820Sjeff		} fast_reg;
782219820Sjeff		struct {
783219820Sjeff			struct ib_unpacked_lrh	*lrh;
784219820Sjeff			u32			eth_type;
785219820Sjeff			u8			static_rate;
786219820Sjeff		} raw_ety;
787219820Sjeff	} wr;
788219820Sjeff	u32			xrc_remote_srq_num; /* valid for XRC sends only */
789219820Sjeff};
790219820Sjeff
791219820Sjeffstruct ib_recv_wr {
792219820Sjeff	struct ib_recv_wr      *next;
793219820Sjeff	u64			wr_id;
794219820Sjeff	struct ib_sge	       *sg_list;
795219820Sjeff	int			num_sge;
796219820Sjeff};
797219820Sjeff
798219820Sjeffenum ib_access_flags {
799219820Sjeff	IB_ACCESS_LOCAL_WRITE	= 1,
800219820Sjeff	IB_ACCESS_REMOTE_WRITE	= (1<<1),
801219820Sjeff	IB_ACCESS_REMOTE_READ	= (1<<2),
802219820Sjeff	IB_ACCESS_REMOTE_ATOMIC	= (1<<3),
803219820Sjeff	IB_ACCESS_MW_BIND	= (1<<4)
804219820Sjeff};
805219820Sjeff
806219820Sjeffstruct ib_phys_buf {
807219820Sjeff	u64      addr;
808219820Sjeff	u64      size;
809219820Sjeff};
810219820Sjeff
811219820Sjeffstruct ib_mr_attr {
812219820Sjeff	struct ib_pd	*pd;
813219820Sjeff	u64		device_virt_addr;
814219820Sjeff	u64		size;
815219820Sjeff	int		mr_access_flags;
816219820Sjeff	u32		lkey;
817219820Sjeff	u32		rkey;
818219820Sjeff};
819219820Sjeff
820219820Sjeffenum ib_mr_rereg_flags {
821219820Sjeff	IB_MR_REREG_TRANS	= 1,
822219820Sjeff	IB_MR_REREG_PD		= (1<<1),
823219820Sjeff	IB_MR_REREG_ACCESS	= (1<<2)
824219820Sjeff};
825219820Sjeff
826219820Sjeffstruct ib_mw_bind {
827219820Sjeff	struct ib_mr   *mr;
828219820Sjeff	u64		wr_id;
829219820Sjeff	u64		addr;
830219820Sjeff	u32		length;
831219820Sjeff	int		send_flags;
832219820Sjeff	int		mw_access_flags;
833219820Sjeff};
834219820Sjeff
835219820Sjeffstruct ib_fmr_attr {
836219820Sjeff	int	max_pages;
837219820Sjeff	int	max_maps;
838219820Sjeff	u8	page_shift;
839219820Sjeff};
840219820Sjeff
841219820Sjeffstruct ib_ucontext {
842219820Sjeff	struct ib_device       *device;
843219820Sjeff	struct list_head	pd_list;
844219820Sjeff	struct list_head	mr_list;
845219820Sjeff	struct list_head	mw_list;
846219820Sjeff	struct list_head	cq_list;
847219820Sjeff	struct list_head	qp_list;
848219820Sjeff	struct list_head	srq_list;
849219820Sjeff	struct list_head	ah_list;
850219820Sjeff	struct list_head	xrc_domain_list;
851219820Sjeff	int			closing;
852219820Sjeff};
853219820Sjeff
854219820Sjeffstruct ib_uobject {
855219820Sjeff	u64			user_handle;	/* handle given to us by userspace */
856219820Sjeff	struct ib_ucontext     *context;	/* associated user context */
857219820Sjeff	void		       *object;		/* containing object */
858219820Sjeff	struct list_head	list;		/* link to context's list */
859219820Sjeff	int			id;		/* index into kernel idr */
860219820Sjeff	struct kref		ref;
861219820Sjeff	struct rw_semaphore	mutex;		/* protects .live */
862219820Sjeff	int			live;
863219820Sjeff};
864219820Sjeff
865219820Sjeffstruct ib_udata {
866219820Sjeff	void __user *inbuf;
867219820Sjeff	void __user *outbuf;
868219820Sjeff	size_t       inlen;
869219820Sjeff	size_t       outlen;
870219820Sjeff};
871219820Sjeff
872219820Sjeffstruct ib_uxrc_rcv_object {
873219820Sjeff	struct list_head	list;		/* link to context's list */
874219820Sjeff	u32			qp_num;
875219820Sjeff	u32			domain_handle;
876219820Sjeff};
877219820Sjeff
878219820Sjeffstruct ib_pd {
879219820Sjeff	struct ib_device       *device;
880219820Sjeff	struct ib_uobject      *uobject;
881219820Sjeff	atomic_t          	usecnt; /* count all resources */
882219820Sjeff};
883219820Sjeff
884219820Sjeffstruct ib_xrcd {
885219820Sjeff	struct ib_device       *device;
886219820Sjeff	struct ib_uobject      *uobject;
887219820Sjeff	struct inode	       *inode;
888219820Sjeff	struct rb_node		node;
889219820Sjeff	atomic_t		usecnt; /* count all resources */
890219820Sjeff};
891219820Sjeff
892219820Sjeff
893219820Sjeffstruct ib_ah {
894219820Sjeff	struct ib_device	*device;
895219820Sjeff	struct ib_pd		*pd;
896219820Sjeff	struct ib_uobject	*uobject;
897219820Sjeff};
898219820Sjeff
899219820Sjefftypedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
900219820Sjeff
901219820Sjeffstruct ib_cq {
902219820Sjeff	struct ib_device       *device;
903219820Sjeff	struct ib_uobject      *uobject;
904219820Sjeff	ib_comp_handler   	comp_handler;
905219820Sjeff	void                  (*event_handler)(struct ib_event *, void *);
906219820Sjeff	void                   *cq_context;
907219820Sjeff	int               	cqe;
908219820Sjeff	atomic_t          	usecnt; /* count number of work queues */
909219820Sjeff};
910219820Sjeff
911219820Sjeffstruct ib_srq {
912219820Sjeff	struct ib_device       *device;
913219820Sjeff	struct ib_pd	       *pd;
914219820Sjeff	struct ib_cq	       *xrc_cq;
915219820Sjeff	struct ib_xrcd	       *xrcd;
916219820Sjeff	struct ib_uobject      *uobject;
917219820Sjeff	void		      (*event_handler)(struct ib_event *, void *);
918219820Sjeff	void		       *srq_context;
919219820Sjeff	atomic_t		usecnt;
920219820Sjeff	u32			xrc_srq_num;
921219820Sjeff};
922219820Sjeff
923219820Sjeffstruct ib_qp {
924219820Sjeff	struct ib_device       *device;
925219820Sjeff	struct ib_pd	       *pd;
926219820Sjeff	struct ib_cq	       *send_cq;
927219820Sjeff	struct ib_cq	       *recv_cq;
928219820Sjeff	struct ib_srq	       *srq;
929219820Sjeff	struct ib_uobject      *uobject;
930219820Sjeff	void                  (*event_handler)(struct ib_event *, void *);
931219820Sjeff	void		       *qp_context;
932219820Sjeff	u32			qp_num;
933219820Sjeff	enum ib_qp_type		qp_type;
934219820Sjeff	struct ib_xrcd	       *xrcd;  /* XRC QPs only */
935219820Sjeff};
936219820Sjeff
937219820Sjeffstruct ib_mr {
938219820Sjeff	struct ib_device  *device;
939219820Sjeff	struct ib_pd	  *pd;
940219820Sjeff	struct ib_uobject *uobject;
941219820Sjeff	u32		   lkey;
942219820Sjeff	u32		   rkey;
943219820Sjeff	atomic_t	   usecnt; /* count number of MWs */
944219820Sjeff};
945219820Sjeff
946219820Sjeffstruct ib_mw {
947219820Sjeff	struct ib_device	*device;
948219820Sjeff	struct ib_pd		*pd;
949219820Sjeff	struct ib_uobject	*uobject;
950219820Sjeff	u32			rkey;
951219820Sjeff};
952219820Sjeff
953219820Sjeffstruct ib_fmr {
954219820Sjeff	struct ib_device	*device;
955219820Sjeff	struct ib_pd		*pd;
956219820Sjeff	struct list_head	list;
957219820Sjeff	u32			lkey;
958219820Sjeff	u32			rkey;
959219820Sjeff};
960219820Sjeff
961219820Sjeffstruct ib_mad;
962219820Sjeffstruct ib_grh;
963219820Sjeff
964219820Sjeffenum ib_process_mad_flags {
965219820Sjeff	IB_MAD_IGNORE_MKEY	= 1,
966219820Sjeff	IB_MAD_IGNORE_BKEY	= 2,
967219820Sjeff	IB_MAD_IGNORE_ALL	= IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
968219820Sjeff};
969219820Sjeff
970219820Sjeffenum ib_mad_result {
971219820Sjeff	IB_MAD_RESULT_FAILURE  = 0,      /* (!SUCCESS is the important flag) */
972219820Sjeff	IB_MAD_RESULT_SUCCESS  = 1 << 0, /* MAD was successfully processed   */
973219820Sjeff	IB_MAD_RESULT_REPLY    = 1 << 1, /* Reply packet needs to be sent    */
974219820Sjeff	IB_MAD_RESULT_CONSUMED = 1 << 2  /* Packet consumed: stop processing */
975219820Sjeff};
976219820Sjeff
977219820Sjeff#define IB_DEVICE_NAME_MAX 64
978219820Sjeff
979219820Sjeffstruct ib_cache {
980219820Sjeff	rwlock_t                lock;
981219820Sjeff	struct ib_event_handler event_handler;
982219820Sjeff	struct ib_pkey_cache  **pkey_cache;
983219820Sjeff	struct ib_gid_cache   **gid_cache;
984219820Sjeff	u8                     *lmc_cache;
985219820Sjeff};
986219820Sjeff
987219820Sjeffstruct ib_dma_mapping_ops {
988219820Sjeff	int		(*mapping_error)(struct ib_device *dev,
989219820Sjeff					 u64 dma_addr);
990219820Sjeff	u64		(*map_single)(struct ib_device *dev,
991219820Sjeff				      void *ptr, size_t size,
992219820Sjeff				      enum dma_data_direction direction);
993219820Sjeff	void		(*unmap_single)(struct ib_device *dev,
994219820Sjeff					u64 addr, size_t size,
995219820Sjeff					enum dma_data_direction direction);
996219820Sjeff	u64		(*map_page)(struct ib_device *dev,
997219820Sjeff				    struct page *page, unsigned long offset,
998219820Sjeff				    size_t size,
999219820Sjeff				    enum dma_data_direction direction);
1000219820Sjeff	void		(*unmap_page)(struct ib_device *dev,
1001219820Sjeff				      u64 addr, size_t size,
1002219820Sjeff				      enum dma_data_direction direction);
1003219820Sjeff	int		(*map_sg)(struct ib_device *dev,
1004219820Sjeff				  struct scatterlist *sg, int nents,
1005219820Sjeff				  enum dma_data_direction direction);
1006219820Sjeff	void		(*unmap_sg)(struct ib_device *dev,
1007219820Sjeff				    struct scatterlist *sg, int nents,
1008219820Sjeff				    enum dma_data_direction direction);
1009219820Sjeff	u64		(*dma_address)(struct ib_device *dev,
1010219820Sjeff				       struct scatterlist *sg);
1011219820Sjeff	unsigned int	(*dma_len)(struct ib_device *dev,
1012219820Sjeff				   struct scatterlist *sg);
1013219820Sjeff	void		(*sync_single_for_cpu)(struct ib_device *dev,
1014219820Sjeff					       u64 dma_handle,
1015219820Sjeff					       size_t size,
1016219820Sjeff					       enum dma_data_direction dir);
1017219820Sjeff	void		(*sync_single_for_device)(struct ib_device *dev,
1018219820Sjeff						  u64 dma_handle,
1019219820Sjeff						  size_t size,
1020219820Sjeff						  enum dma_data_direction dir);
1021219820Sjeff	void		*(*alloc_coherent)(struct ib_device *dev,
1022219820Sjeff					   size_t size,
1023219820Sjeff					   u64 *dma_handle,
1024219820Sjeff					   gfp_t flag);
1025219820Sjeff	void		(*free_coherent)(struct ib_device *dev,
1026219820Sjeff					 size_t size, void *cpu_addr,
1027219820Sjeff					 u64 dma_handle);
1028219820Sjeff};
1029219820Sjeff
1030219820Sjeffstruct iw_cm_verbs;
1031219820Sjeff
1032219820Sjeffstruct ib_device {
1033219820Sjeff	struct device                *dma_device;
1034219820Sjeff
1035219820Sjeff	char                          name[IB_DEVICE_NAME_MAX];
1036219820Sjeff
1037219820Sjeff	struct list_head              event_handler_list;
1038219820Sjeff	spinlock_t                    event_handler_lock;
1039219820Sjeff
1040219820Sjeff	struct list_head              core_list;
1041219820Sjeff	struct list_head              client_data_list;
1042219820Sjeff	spinlock_t                    client_data_lock;
1043219820Sjeff
1044219820Sjeff	struct ib_cache               cache;
1045219820Sjeff	int                          *pkey_tbl_len;
1046219820Sjeff	int                          *gid_tbl_len;
1047219820Sjeff
1048219820Sjeff	int			      num_comp_vectors;
1049219820Sjeff
1050219820Sjeff	struct iw_cm_verbs	     *iwcm;
1051219820Sjeff
1052219820Sjeff	int		           (*get_protocol_stats)(struct ib_device *device,
1053219820Sjeff							 union rdma_protocol_stats *stats);
1054219820Sjeff	int		           (*query_device)(struct ib_device *device,
1055219820Sjeff						   struct ib_device_attr *device_attr);
1056219820Sjeff	int		           (*query_port)(struct ib_device *device,
1057219820Sjeff						 u8 port_num,
1058219820Sjeff						 struct ib_port_attr *port_attr);
1059219820Sjeff	enum rdma_link_layer	   (*get_link_layer)(struct ib_device *device,
1060219820Sjeff						     u8 port_num);
1061219820Sjeff	int		           (*query_gid)(struct ib_device *device,
1062219820Sjeff						u8 port_num, int index,
1063219820Sjeff						union ib_gid *gid);
1064219820Sjeff	int		           (*query_pkey)(struct ib_device *device,
1065219820Sjeff						 u8 port_num, u16 index, u16 *pkey);
1066219820Sjeff	int		           (*modify_device)(struct ib_device *device,
1067219820Sjeff						    int device_modify_mask,
1068219820Sjeff						    struct ib_device_modify *device_modify);
1069219820Sjeff	int		           (*modify_port)(struct ib_device *device,
1070219820Sjeff						  u8 port_num, int port_modify_mask,
1071219820Sjeff						  struct ib_port_modify *port_modify);
1072219820Sjeff	struct ib_ucontext *       (*alloc_ucontext)(struct ib_device *device,
1073219820Sjeff						     struct ib_udata *udata);
1074219820Sjeff	int                        (*dealloc_ucontext)(struct ib_ucontext *context);
1075219820Sjeff	int                        (*mmap)(struct ib_ucontext *context,
1076219820Sjeff					   struct vm_area_struct *vma);
1077219820Sjeff	struct ib_pd *             (*alloc_pd)(struct ib_device *device,
1078219820Sjeff					       struct ib_ucontext *context,
1079219820Sjeff					       struct ib_udata *udata);
1080219820Sjeff	int                        (*dealloc_pd)(struct ib_pd *pd);
1081219820Sjeff	struct ib_ah *             (*create_ah)(struct ib_pd *pd,
1082219820Sjeff						struct ib_ah_attr *ah_attr);
1083219820Sjeff	int                        (*modify_ah)(struct ib_ah *ah,
1084219820Sjeff						struct ib_ah_attr *ah_attr);
1085219820Sjeff	int                        (*query_ah)(struct ib_ah *ah,
1086219820Sjeff					       struct ib_ah_attr *ah_attr);
1087219820Sjeff	int                        (*destroy_ah)(struct ib_ah *ah);
1088219820Sjeff	struct ib_srq *            (*create_srq)(struct ib_pd *pd,
1089219820Sjeff						 struct ib_srq_init_attr *srq_init_attr,
1090219820Sjeff						 struct ib_udata *udata);
1091219820Sjeff	int                        (*modify_srq)(struct ib_srq *srq,
1092219820Sjeff						 struct ib_srq_attr *srq_attr,
1093219820Sjeff						 enum ib_srq_attr_mask srq_attr_mask,
1094219820Sjeff						 struct ib_udata *udata);
1095219820Sjeff	int                        (*query_srq)(struct ib_srq *srq,
1096219820Sjeff						struct ib_srq_attr *srq_attr);
1097219820Sjeff	int                        (*destroy_srq)(struct ib_srq *srq);
1098219820Sjeff	int                        (*post_srq_recv)(struct ib_srq *srq,
1099219820Sjeff						    struct ib_recv_wr *recv_wr,
1100219820Sjeff						    struct ib_recv_wr **bad_recv_wr);
1101219820Sjeff	struct ib_qp *             (*create_qp)(struct ib_pd *pd,
1102219820Sjeff						struct ib_qp_init_attr *qp_init_attr,
1103219820Sjeff						struct ib_udata *udata);
1104219820Sjeff	int                        (*modify_qp)(struct ib_qp *qp,
1105219820Sjeff						struct ib_qp_attr *qp_attr,
1106219820Sjeff						int qp_attr_mask,
1107219820Sjeff						struct ib_udata *udata);
1108219820Sjeff	int                        (*query_qp)(struct ib_qp *qp,
1109219820Sjeff					       struct ib_qp_attr *qp_attr,
1110219820Sjeff					       int qp_attr_mask,
1111219820Sjeff					       struct ib_qp_init_attr *qp_init_attr);
1112219820Sjeff	int                        (*destroy_qp)(struct ib_qp *qp);
1113219820Sjeff	int                        (*post_send)(struct ib_qp *qp,
1114219820Sjeff						struct ib_send_wr *send_wr,
1115219820Sjeff						struct ib_send_wr **bad_send_wr);
1116219820Sjeff	int                        (*post_recv)(struct ib_qp *qp,
1117219820Sjeff						struct ib_recv_wr *recv_wr,
1118219820Sjeff						struct ib_recv_wr **bad_recv_wr);
1119219820Sjeff	struct ib_cq *             (*create_cq)(struct ib_device *device, int cqe,
1120219820Sjeff						int comp_vector,
1121219820Sjeff						struct ib_ucontext *context,
1122219820Sjeff						struct ib_udata *udata);
1123219820Sjeff	int                        (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1124219820Sjeff						u16 cq_period);
1125219820Sjeff	int                        (*destroy_cq)(struct ib_cq *cq);
1126219820Sjeff	int                        (*resize_cq)(struct ib_cq *cq, int cqe,
1127219820Sjeff						struct ib_udata *udata);
1128219820Sjeff	int                        (*poll_cq)(struct ib_cq *cq, int num_entries,
1129219820Sjeff					      struct ib_wc *wc);
1130219820Sjeff	int                        (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1131219820Sjeff	int                        (*req_notify_cq)(struct ib_cq *cq,
1132219820Sjeff						    enum ib_cq_notify_flags flags);
1133219820Sjeff	int                        (*req_ncomp_notif)(struct ib_cq *cq,
1134219820Sjeff						      int wc_cnt);
1135219820Sjeff	struct ib_mr *             (*get_dma_mr)(struct ib_pd *pd,
1136219820Sjeff						 int mr_access_flags);
1137219820Sjeff	struct ib_mr *             (*reg_phys_mr)(struct ib_pd *pd,
1138219820Sjeff						  struct ib_phys_buf *phys_buf_array,
1139219820Sjeff						  int num_phys_buf,
1140219820Sjeff						  int mr_access_flags,
1141219820Sjeff						  u64 *iova_start);
1142219820Sjeff	struct ib_mr *             (*reg_user_mr)(struct ib_pd *pd,
1143219820Sjeff						  u64 start, u64 length,
1144219820Sjeff						  u64 virt_addr,
1145219820Sjeff						  int mr_access_flags,
1146219820Sjeff						  struct ib_udata *udata);
1147219820Sjeff	int                        (*query_mr)(struct ib_mr *mr,
1148219820Sjeff					       struct ib_mr_attr *mr_attr);
1149219820Sjeff	int                        (*dereg_mr)(struct ib_mr *mr);
1150219820Sjeff	struct ib_mr *		   (*alloc_fast_reg_mr)(struct ib_pd *pd,
1151219820Sjeff					       int max_page_list_len);
1152219820Sjeff	struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1153219820Sjeff								   int page_list_len);
1154219820Sjeff	void			   (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
1155219820Sjeff	int                        (*rereg_phys_mr)(struct ib_mr *mr,
1156219820Sjeff						    int mr_rereg_mask,
1157219820Sjeff						    struct ib_pd *pd,
1158219820Sjeff						    struct ib_phys_buf *phys_buf_array,
1159219820Sjeff						    int num_phys_buf,
1160219820Sjeff						    int mr_access_flags,
1161219820Sjeff						    u64 *iova_start);
1162219820Sjeff	struct ib_mw *             (*alloc_mw)(struct ib_pd *pd);
1163219820Sjeff	int                        (*bind_mw)(struct ib_qp *qp,
1164219820Sjeff					      struct ib_mw *mw,
1165219820Sjeff					      struct ib_mw_bind *mw_bind);
1166219820Sjeff	int                        (*dealloc_mw)(struct ib_mw *mw);
1167219820Sjeff	struct ib_fmr *	           (*alloc_fmr)(struct ib_pd *pd,
1168219820Sjeff						int mr_access_flags,
1169219820Sjeff						struct ib_fmr_attr *fmr_attr);
1170219820Sjeff	int		           (*map_phys_fmr)(struct ib_fmr *fmr,
1171219820Sjeff						   u64 *page_list, int list_len,
1172219820Sjeff						   u64 iova);
1173219820Sjeff	int		           (*unmap_fmr)(struct list_head *fmr_list);
1174219820Sjeff	int		           (*dealloc_fmr)(struct ib_fmr *fmr);
1175219820Sjeff	int                        (*attach_mcast)(struct ib_qp *qp,
1176219820Sjeff						   union ib_gid *gid,
1177219820Sjeff						   u16 lid);
1178219820Sjeff	int                        (*detach_mcast)(struct ib_qp *qp,
1179219820Sjeff						   union ib_gid *gid,
1180219820Sjeff						   u16 lid);
1181219820Sjeff	int                        (*process_mad)(struct ib_device *device,
1182219820Sjeff						  int process_mad_flags,
1183219820Sjeff						  u8 port_num,
1184219820Sjeff						  struct ib_wc *in_wc,
1185219820Sjeff						  struct ib_grh *in_grh,
1186219820Sjeff						  struct ib_mad *in_mad,
1187219820Sjeff						  struct ib_mad *out_mad);
1188219820Sjeff	struct ib_srq *		   (*create_xrc_srq)(struct ib_pd *pd,
1189219820Sjeff						     struct ib_cq *xrc_cq,
1190219820Sjeff						     struct ib_xrcd *xrcd,
1191219820Sjeff						     struct ib_srq_init_attr *srq_init_attr,
1192219820Sjeff						     struct ib_udata *udata);
1193219820Sjeff	struct ib_xrcd *	   (*alloc_xrcd)(struct ib_device *device,
1194219820Sjeff						 struct ib_ucontext *context,
1195219820Sjeff						 struct ib_udata *udata);
1196219820Sjeff	int			   (*dealloc_xrcd)(struct ib_xrcd *xrcd);
1197219820Sjeff	int			   (*create_xrc_rcv_qp)(struct ib_qp_init_attr *init_attr,
1198219820Sjeff							u32 *qp_num);
1199219820Sjeff	int			   (*modify_xrc_rcv_qp)(struct ib_xrcd *xrcd,
1200219820Sjeff							u32 qp_num,
1201219820Sjeff							struct ib_qp_attr *attr,
1202219820Sjeff							int attr_mask);
1203219820Sjeff	int			   (*query_xrc_rcv_qp)(struct ib_xrcd *xrcd,
1204219820Sjeff						       u32 qp_num,
1205219820Sjeff						       struct ib_qp_attr *attr,
1206219820Sjeff						       int attr_mask,
1207219820Sjeff						       struct ib_qp_init_attr *init_attr);
1208219820Sjeff	int 			   (*reg_xrc_rcv_qp)(struct ib_xrcd *xrcd,
1209219820Sjeff						     void *context,
1210219820Sjeff						     u32 qp_num);
1211219820Sjeff	int 			   (*unreg_xrc_rcv_qp)(struct ib_xrcd *xrcd,
1212219820Sjeff						       void *context,
1213219820Sjeff						       u32 qp_num);
1214219820Sjeff
1215219820Sjeff	struct ib_dma_mapping_ops   *dma_ops;
1216219820Sjeff
1217219820Sjeff	struct module               *owner;
1218219820Sjeff	struct device                dev;
1219219820Sjeff	struct kobject               *ports_parent;
1220219820Sjeff	struct list_head             port_list;
1221219820Sjeff
1222219820Sjeff	enum {
1223219820Sjeff		IB_DEV_UNINITIALIZED,
1224219820Sjeff		IB_DEV_REGISTERED,
1225219820Sjeff		IB_DEV_UNREGISTERED
1226219820Sjeff	}                            reg_state;
1227219820Sjeff
1228219820Sjeff	u64			     uverbs_cmd_mask;
1229219820Sjeff	int			     uverbs_abi_ver;
1230219820Sjeff
1231219820Sjeff	char			     node_desc[64];
1232219820Sjeff	__be64			     node_guid;
1233219820Sjeff	u32			     local_dma_lkey;
1234219820Sjeff	u8                           node_type;
1235219820Sjeff	u8                           phys_port_cnt;
1236219820Sjeff	struct rb_root		     ib_uverbs_xrcd_table;
1237219820Sjeff	struct mutex		     xrcd_table_mutex;
1238219820Sjeff};
1239219820Sjeff
1240219820Sjeffstruct ib_client {
1241219820Sjeff	char  *name;
1242219820Sjeff	void (*add)   (struct ib_device *);
1243219820Sjeff	void (*remove)(struct ib_device *);
1244219820Sjeff
1245219820Sjeff	struct list_head list;
1246219820Sjeff};
1247219820Sjeff
1248219820Sjeffstruct ib_device *ib_alloc_device(size_t size);
1249219820Sjeffvoid ib_dealloc_device(struct ib_device *device);
1250219820Sjeff
1251219820Sjeffint ib_register_device   (struct ib_device *device);
1252219820Sjeffvoid ib_unregister_device(struct ib_device *device);
1253219820Sjeff
1254219820Sjeffint ib_register_client   (struct ib_client *client);
1255219820Sjeffvoid ib_unregister_client(struct ib_client *client);
1256219820Sjeff
1257219820Sjeffvoid *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1258219820Sjeffvoid  ib_set_client_data(struct ib_device *device, struct ib_client *client,
1259219820Sjeff			 void *data);
1260219820Sjeff
1261219820Sjeffstatic inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1262219820Sjeff{
1263219820Sjeff	return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1264219820Sjeff}
1265219820Sjeff
1266219820Sjeffstatic inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1267219820Sjeff{
1268219820Sjeff	return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1269219820Sjeff}
1270219820Sjeff
1271219820Sjeff/**
1272219820Sjeff * ib_sysfs_create_port_files - iterate over port sysfs directories
1273219820Sjeff * @device: the IB device
1274219820Sjeff * @create: a function to create sysfs files in each port directory
1275219820Sjeff */
1276219820Sjeffint ib_sysfs_create_port_files(struct ib_device *device,
1277219820Sjeff			       int (*create)(struct ib_device *dev, u8 port_num,
1278219820Sjeff					     struct kobject *kobj));
1279219820Sjeff
1280219820Sjeff/**
1281219820Sjeff * ib_modify_qp_is_ok - Check that the supplied attribute mask
1282219820Sjeff * contains all required attributes and no attributes not allowed for
1283219820Sjeff * the given QP state transition.
1284219820Sjeff * @cur_state: Current QP state
1285219820Sjeff * @next_state: Next QP state
1286219820Sjeff * @type: QP type
1287219820Sjeff * @mask: Mask of supplied QP attributes
1288219820Sjeff *
1289219820Sjeff * This function is a helper function that a low-level driver's
1290219820Sjeff * modify_qp method can use to validate the consumer's input.  It
1291219820Sjeff * checks that cur_state and next_state are valid QP states, that a
1292219820Sjeff * transition from cur_state to next_state is allowed by the IB spec,
1293219820Sjeff * and that the attribute mask supplied is allowed for the transition.
1294219820Sjeff */
1295219820Sjeffint ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
1296219820Sjeff		       enum ib_qp_type type, enum ib_qp_attr_mask mask);
1297219820Sjeff
1298219820Sjeffint ib_register_event_handler  (struct ib_event_handler *event_handler);
1299219820Sjeffint ib_unregister_event_handler(struct ib_event_handler *event_handler);
1300219820Sjeffvoid ib_dispatch_event(struct ib_event *event);
1301219820Sjeff
1302219820Sjeffint ib_query_device(struct ib_device *device,
1303219820Sjeff		    struct ib_device_attr *device_attr);
1304219820Sjeff
1305219820Sjeffint ib_query_port(struct ib_device *device,
1306219820Sjeff		  u8 port_num, struct ib_port_attr *port_attr);
1307219820Sjeff
1308219820Sjeffenum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1309219820Sjeff					       u8 port_num);
1310219820Sjeff
1311219820Sjeffint ib_query_gid(struct ib_device *device,
1312219820Sjeff		 u8 port_num, int index, union ib_gid *gid);
1313219820Sjeff
1314219820Sjeffint ib_query_pkey(struct ib_device *device,
1315219820Sjeff		  u8 port_num, u16 index, u16 *pkey);
1316219820Sjeff
1317219820Sjeffint ib_modify_device(struct ib_device *device,
1318219820Sjeff		     int device_modify_mask,
1319219820Sjeff		     struct ib_device_modify *device_modify);
1320219820Sjeff
1321219820Sjeffint ib_modify_port(struct ib_device *device,
1322219820Sjeff		   u8 port_num, int port_modify_mask,
1323219820Sjeff		   struct ib_port_modify *port_modify);
1324219820Sjeff
1325219820Sjeffint ib_find_gid(struct ib_device *device, union ib_gid *gid,
1326219820Sjeff		u8 *port_num, u16 *index);
1327219820Sjeff
1328219820Sjeffint ib_find_pkey(struct ib_device *device,
1329219820Sjeff		 u8 port_num, u16 pkey, u16 *index);
1330219820Sjeff
1331219820Sjeff/**
1332219820Sjeff * ib_alloc_pd - Allocates an unused protection domain.
1333219820Sjeff * @device: The device on which to allocate the protection domain.
1334219820Sjeff *
1335219820Sjeff * A protection domain object provides an association between QPs, shared
1336219820Sjeff * receive queues, address handles, memory regions, and memory windows.
1337219820Sjeff */
1338219820Sjeffstruct ib_pd *ib_alloc_pd(struct ib_device *device);
1339219820Sjeff
1340219820Sjeff/**
1341219820Sjeff * ib_dealloc_pd - Deallocates a protection domain.
1342219820Sjeff * @pd: The protection domain to deallocate.
1343219820Sjeff */
1344219820Sjeffint ib_dealloc_pd(struct ib_pd *pd);
1345219820Sjeff
1346219820Sjeff/**
1347219820Sjeff * ib_create_ah - Creates an address handle for the given address vector.
1348219820Sjeff * @pd: The protection domain associated with the address handle.
1349219820Sjeff * @ah_attr: The attributes of the address vector.
1350219820Sjeff *
1351219820Sjeff * The address handle is used to reference a local or global destination
1352219820Sjeff * in all UD QP post sends.
1353219820Sjeff */
1354219820Sjeffstruct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1355219820Sjeff
1356219820Sjeff/**
1357219820Sjeff * ib_init_ah_from_wc - Initializes address handle attributes from a
1358219820Sjeff *   work completion.
1359219820Sjeff * @device: Device on which the received message arrived.
1360219820Sjeff * @port_num: Port on which the received message arrived.
1361219820Sjeff * @wc: Work completion associated with the received message.
1362219820Sjeff * @grh: References the received global route header.  This parameter is
1363219820Sjeff *   ignored unless the work completion indicates that the GRH is valid.
1364219820Sjeff * @ah_attr: Returned attributes that can be used when creating an address
1365219820Sjeff *   handle for replying to the message.
1366219820Sjeff */
1367219820Sjeffint ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1368219820Sjeff		       struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1369219820Sjeff
1370219820Sjeff/**
1371219820Sjeff * ib_create_ah_from_wc - Creates an address handle associated with the
1372219820Sjeff *   sender of the specified work completion.
1373219820Sjeff * @pd: The protection domain associated with the address handle.
1374219820Sjeff * @wc: Work completion information associated with a received message.
1375219820Sjeff * @grh: References the received global route header.  This parameter is
1376219820Sjeff *   ignored unless the work completion indicates that the GRH is valid.
1377219820Sjeff * @port_num: The outbound port number to associate with the address.
1378219820Sjeff *
1379219820Sjeff * The address handle is used to reference a local or global destination
1380219820Sjeff * in all UD QP post sends.
1381219820Sjeff */
1382219820Sjeffstruct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1383219820Sjeff				   struct ib_grh *grh, u8 port_num);
1384219820Sjeff
1385219820Sjeff/**
1386219820Sjeff * ib_modify_ah - Modifies the address vector associated with an address
1387219820Sjeff *   handle.
1388219820Sjeff * @ah: The address handle to modify.
1389219820Sjeff * @ah_attr: The new address vector attributes to associate with the
1390219820Sjeff *   address handle.
1391219820Sjeff */
1392219820Sjeffint ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1393219820Sjeff
1394219820Sjeff/**
1395219820Sjeff * ib_query_ah - Queries the address vector associated with an address
1396219820Sjeff *   handle.
1397219820Sjeff * @ah: The address handle to query.
1398219820Sjeff * @ah_attr: The address vector attributes associated with the address
1399219820Sjeff *   handle.
1400219820Sjeff */
1401219820Sjeffint ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1402219820Sjeff
1403219820Sjeff/**
1404219820Sjeff * ib_destroy_ah - Destroys an address handle.
1405219820Sjeff * @ah: The address handle to destroy.
1406219820Sjeff */
1407219820Sjeffint ib_destroy_ah(struct ib_ah *ah);
1408219820Sjeff
1409219820Sjeff/**
1410219820Sjeff * ib_create_xrc_srq - Creates an XRC SRQ associated with the specified
1411219820Sjeff *   protection domain, cq, and xrc domain.
1412219820Sjeff * @pd: The protection domain associated with the SRQ.
1413219820Sjeff * @xrc_cq: The cq to be associated with the XRC SRQ.
1414219820Sjeff * @xrcd: The XRC domain to be associated with the XRC SRQ.
1415219820Sjeff * @srq_init_attr: A list of initial attributes required to create the
1416219820Sjeff *   XRC SRQ.  If XRC SRQ creation succeeds, then the attributes are updated
1417219820Sjeff *   to the actual capabilities of the created XRC SRQ.
1418219820Sjeff *
1419219820Sjeff * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1420219820Sjeff * requested size of the XRC SRQ, and set to the actual values allocated
1421219820Sjeff * on return.  If ib_create_xrc_srq() succeeds, then max_wr and max_sge
1422219820Sjeff * will always be at least as large as the requested values.
1423219820Sjeff */
1424219820Sjeffstruct ib_srq *ib_create_xrc_srq(struct ib_pd *pd,
1425219820Sjeff				 struct ib_cq *xrc_cq,
1426219820Sjeff				 struct ib_xrcd *xrcd,
1427219820Sjeff				 struct ib_srq_init_attr *srq_init_attr);
1428219820Sjeff
1429219820Sjeff/**
1430219820Sjeff * ib_create_srq - Creates an SRQ associated with the specified
1431219820Sjeff *   protection domain.
1432219820Sjeff * @pd: The protection domain associated with the SRQ.
1433219820Sjeff * @srq_init_attr: A list of initial attributes required to create the
1434219820Sjeff *   SRQ.  If SRQ creation succeeds, then the attributes are updated to
1435219820Sjeff *   the actual capabilities of the created SRQ.
1436219820Sjeff *
1437219820Sjeff * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1438219820Sjeff * requested size of the SRQ, and set to the actual values allocated
1439219820Sjeff * on return.  If ib_create_srq() succeeds, then max_wr and max_sge
1440219820Sjeff * will always be at least as large as the requested values.
1441219820Sjeff */
1442219820Sjeffstruct ib_srq *ib_create_srq(struct ib_pd *pd,
1443219820Sjeff			     struct ib_srq_init_attr *srq_init_attr);
1444219820Sjeff
1445219820Sjeff/**
1446219820Sjeff * ib_modify_srq - Modifies the attributes for the specified SRQ.
1447219820Sjeff * @srq: The SRQ to modify.
1448219820Sjeff * @srq_attr: On input, specifies the SRQ attributes to modify.  On output,
1449219820Sjeff *   the current values of selected SRQ attributes are returned.
1450219820Sjeff * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1451219820Sjeff *   are being modified.
1452219820Sjeff *
1453219820Sjeff * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1454219820Sjeff * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1455219820Sjeff * the number of receives queued drops below the limit.
1456219820Sjeff */
1457219820Sjeffint ib_modify_srq(struct ib_srq *srq,
1458219820Sjeff		  struct ib_srq_attr *srq_attr,
1459219820Sjeff		  enum ib_srq_attr_mask srq_attr_mask);
1460219820Sjeff
1461219820Sjeff/**
1462219820Sjeff * ib_query_srq - Returns the attribute list and current values for the
1463219820Sjeff *   specified SRQ.
1464219820Sjeff * @srq: The SRQ to query.
1465219820Sjeff * @srq_attr: The attributes of the specified SRQ.
1466219820Sjeff */
1467219820Sjeffint ib_query_srq(struct ib_srq *srq,
1468219820Sjeff		 struct ib_srq_attr *srq_attr);
1469219820Sjeff
1470219820Sjeff/**
1471219820Sjeff * ib_destroy_srq - Destroys the specified SRQ.
1472219820Sjeff * @srq: The SRQ to destroy.
1473219820Sjeff */
1474219820Sjeffint ib_destroy_srq(struct ib_srq *srq);
1475219820Sjeff
1476219820Sjeff/**
1477219820Sjeff * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1478219820Sjeff * @srq: The SRQ to post the work request on.
1479219820Sjeff * @recv_wr: A list of work requests to post on the receive queue.
1480219820Sjeff * @bad_recv_wr: On an immediate failure, this parameter will reference
1481219820Sjeff *   the work request that failed to be posted on the QP.
1482219820Sjeff */
1483219820Sjeffstatic inline int ib_post_srq_recv(struct ib_srq *srq,
1484219820Sjeff				   struct ib_recv_wr *recv_wr,
1485219820Sjeff				   struct ib_recv_wr **bad_recv_wr)
1486219820Sjeff{
1487219820Sjeff	return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1488219820Sjeff}
1489219820Sjeff
1490219820Sjeff/**
1491219820Sjeff * ib_create_qp - Creates a QP associated with the specified protection
1492219820Sjeff *   domain.
1493219820Sjeff * @pd: The protection domain associated with the QP.
1494219820Sjeff * @qp_init_attr: A list of initial attributes required to create the
1495219820Sjeff *   QP.  If QP creation succeeds, then the attributes are updated to
1496219820Sjeff *   the actual capabilities of the created QP.
1497219820Sjeff */
1498219820Sjeffstruct ib_qp *ib_create_qp(struct ib_pd *pd,
1499219820Sjeff			   struct ib_qp_init_attr *qp_init_attr);
1500219820Sjeff
1501219820Sjeff/**
1502219820Sjeff * ib_modify_qp - Modifies the attributes for the specified QP and then
1503219820Sjeff *   transitions the QP to the given state.
1504219820Sjeff * @qp: The QP to modify.
1505219820Sjeff * @qp_attr: On input, specifies the QP attributes to modify.  On output,
1506219820Sjeff *   the current values of selected QP attributes are returned.
1507219820Sjeff * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1508219820Sjeff *   are being modified.
1509219820Sjeff */
1510219820Sjeffint ib_modify_qp(struct ib_qp *qp,
1511219820Sjeff		 struct ib_qp_attr *qp_attr,
1512219820Sjeff		 int qp_attr_mask);
1513219820Sjeff
1514219820Sjeff/**
1515219820Sjeff * ib_query_qp - Returns the attribute list and current values for the
1516219820Sjeff *   specified QP.
1517219820Sjeff * @qp: The QP to query.
1518219820Sjeff * @qp_attr: The attributes of the specified QP.
1519219820Sjeff * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1520219820Sjeff * @qp_init_attr: Additional attributes of the selected QP.
1521219820Sjeff *
1522219820Sjeff * The qp_attr_mask may be used to limit the query to gathering only the
1523219820Sjeff * selected attributes.
1524219820Sjeff */
1525219820Sjeffint ib_query_qp(struct ib_qp *qp,
1526219820Sjeff		struct ib_qp_attr *qp_attr,
1527219820Sjeff		int qp_attr_mask,
1528219820Sjeff		struct ib_qp_init_attr *qp_init_attr);
1529219820Sjeff
1530219820Sjeff/**
1531219820Sjeff * ib_destroy_qp - Destroys the specified QP.
1532219820Sjeff * @qp: The QP to destroy.
1533219820Sjeff */
1534219820Sjeffint ib_destroy_qp(struct ib_qp *qp);
1535219820Sjeff
1536219820Sjeff/**
1537219820Sjeff * ib_post_send - Posts a list of work requests to the send queue of
1538219820Sjeff *   the specified QP.
1539219820Sjeff * @qp: The QP to post the work request on.
1540219820Sjeff * @send_wr: A list of work requests to post on the send queue.
1541219820Sjeff * @bad_send_wr: On an immediate failure, this parameter will reference
1542219820Sjeff *   the work request that failed to be posted on the QP.
1543219820Sjeff */
1544219820Sjeffstatic inline int ib_post_send(struct ib_qp *qp,
1545219820Sjeff			       struct ib_send_wr *send_wr,
1546219820Sjeff			       struct ib_send_wr **bad_send_wr)
1547219820Sjeff{
1548219820Sjeff	return qp->device->post_send(qp, send_wr, bad_send_wr);
1549219820Sjeff}
1550219820Sjeff
1551219820Sjeff/**
1552219820Sjeff * ib_post_recv - Posts a list of work requests to the receive queue of
1553219820Sjeff *   the specified QP.
1554219820Sjeff * @qp: The QP to post the work request on.
1555219820Sjeff * @recv_wr: A list of work requests to post on the receive queue.
1556219820Sjeff * @bad_recv_wr: On an immediate failure, this parameter will reference
1557219820Sjeff *   the work request that failed to be posted on the QP.
1558219820Sjeff */
1559219820Sjeffstatic inline int ib_post_recv(struct ib_qp *qp,
1560219820Sjeff			       struct ib_recv_wr *recv_wr,
1561219820Sjeff			       struct ib_recv_wr **bad_recv_wr)
1562219820Sjeff{
1563219820Sjeff	return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1564219820Sjeff}
1565219820Sjeff
1566219820Sjeff/*
1567219820Sjeff * IB_CQ_VECTOR_LEAST_ATTACHED: The constant specifies that
1568219820Sjeff *	the CQ will be attached to the completion vector that has
1569219820Sjeff *	the least number of CQs already attached to it.
1570219820Sjeff */
1571219820Sjeff#define IB_CQ_VECTOR_LEAST_ATTACHED	0xffffffff
1572219820Sjeff
1573219820Sjeff/**
1574219820Sjeff * ib_create_cq - Creates a CQ on the specified device.
1575219820Sjeff * @device: The device on which to create the CQ.
1576219820Sjeff * @comp_handler: A user-specified callback that is invoked when a
1577219820Sjeff *   completion event occurs on the CQ.
1578219820Sjeff * @event_handler: A user-specified callback that is invoked when an
1579219820Sjeff *   asynchronous event not associated with a completion occurs on the CQ.
1580219820Sjeff * @cq_context: Context associated with the CQ returned to the user via
1581219820Sjeff *   the associated completion and event handlers.
1582219820Sjeff * @cqe: The minimum size of the CQ.
1583219820Sjeff * @comp_vector - Completion vector used to signal completion events.
1584219820Sjeff *     Must be >= 0 and < context->num_comp_vectors
1585219820Sjeff *     or IB_CQ_VECTOR_LEAST_ATTACHED.
1586219820Sjeff *
1587219820Sjeff * Users can examine the cq structure to determine the actual CQ size.
1588219820Sjeff */
1589219820Sjeffstruct ib_cq *ib_create_cq(struct ib_device *device,
1590219820Sjeff			   ib_comp_handler comp_handler,
1591219820Sjeff			   void (*event_handler)(struct ib_event *, void *),
1592219820Sjeff			   void *cq_context, int cqe, int comp_vector);
1593219820Sjeff
1594219820Sjeff/**
1595219820Sjeff * ib_resize_cq - Modifies the capacity of the CQ.
1596219820Sjeff * @cq: The CQ to resize.
1597219820Sjeff * @cqe: The minimum size of the CQ.
1598219820Sjeff *
1599219820Sjeff * Users can examine the cq structure to determine the actual CQ size.
1600219820Sjeff */
1601219820Sjeffint ib_resize_cq(struct ib_cq *cq, int cqe);
1602219820Sjeff
1603219820Sjeff/**
1604219820Sjeff * ib_modify_cq - Modifies moderation params of the CQ
1605219820Sjeff * @cq: The CQ to modify.
1606219820Sjeff * @cq_count: number of CQEs that will trigger an event
1607219820Sjeff * @cq_period: max period of time in usec before triggering an event
1608219820Sjeff *
1609219820Sjeff */
1610219820Sjeffint ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
1611219820Sjeff
1612219820Sjeff/**
1613219820Sjeff * ib_destroy_cq - Destroys the specified CQ.
1614219820Sjeff * @cq: The CQ to destroy.
1615219820Sjeff */
1616219820Sjeffint ib_destroy_cq(struct ib_cq *cq);
1617219820Sjeff
1618219820Sjeff/**
1619219820Sjeff * ib_poll_cq - poll a CQ for completion(s)
1620219820Sjeff * @cq:the CQ being polled
1621219820Sjeff * @num_entries:maximum number of completions to return
1622219820Sjeff * @wc:array of at least @num_entries &struct ib_wc where completions
1623219820Sjeff *   will be returned
1624219820Sjeff *
1625219820Sjeff * Poll a CQ for (possibly multiple) completions.  If the return value
1626219820Sjeff * is < 0, an error occurred.  If the return value is >= 0, it is the
1627219820Sjeff * number of completions returned.  If the return value is
1628219820Sjeff * non-negative and < num_entries, then the CQ was emptied.
1629219820Sjeff */
1630219820Sjeffstatic inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1631219820Sjeff			     struct ib_wc *wc)
1632219820Sjeff{
1633219820Sjeff	return cq->device->poll_cq(cq, num_entries, wc);
1634219820Sjeff}
1635219820Sjeff
1636219820Sjeff/**
1637219820Sjeff * ib_peek_cq - Returns the number of unreaped completions currently
1638219820Sjeff *   on the specified CQ.
1639219820Sjeff * @cq: The CQ to peek.
1640219820Sjeff * @wc_cnt: A minimum number of unreaped completions to check for.
1641219820Sjeff *
1642219820Sjeff * If the number of unreaped completions is greater than or equal to wc_cnt,
1643219820Sjeff * this function returns wc_cnt, otherwise, it returns the actual number of
1644219820Sjeff * unreaped completions.
1645219820Sjeff */
1646219820Sjeffint ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1647219820Sjeff
1648219820Sjeff/**
1649219820Sjeff * ib_req_notify_cq - Request completion notification on a CQ.
1650219820Sjeff * @cq: The CQ to generate an event for.
1651219820Sjeff * @flags:
1652219820Sjeff *   Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
1653219820Sjeff *   to request an event on the next solicited event or next work
1654219820Sjeff *   completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
1655219820Sjeff *   may also be |ed in to request a hint about missed events, as
1656219820Sjeff *   described below.
1657219820Sjeff *
1658219820Sjeff * Return Value:
1659219820Sjeff *    < 0 means an error occurred while requesting notification
1660219820Sjeff *   == 0 means notification was requested successfully, and if
1661219820Sjeff *        IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
1662219820Sjeff *        were missed and it is safe to wait for another event.  In
1663219820Sjeff *        this case is it guaranteed that any work completions added
1664219820Sjeff *        to the CQ since the last CQ poll will trigger a completion
1665219820Sjeff *        notification event.
1666219820Sjeff *    > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
1667219820Sjeff *        in.  It means that the consumer must poll the CQ again to
1668219820Sjeff *        make sure it is empty to avoid missing an event because of a
1669219820Sjeff *        race between requesting notification and an entry being
1670219820Sjeff *        added to the CQ.  This return value means it is possible
1671219820Sjeff *        (but not guaranteed) that a work completion has been added
1672219820Sjeff *        to the CQ since the last poll without triggering a
1673219820Sjeff *        completion notification event.
1674219820Sjeff */
1675219820Sjeffstatic inline int ib_req_notify_cq(struct ib_cq *cq,
1676219820Sjeff				   enum ib_cq_notify_flags flags)
1677219820Sjeff{
1678219820Sjeff	return cq->device->req_notify_cq(cq, flags);
1679219820Sjeff}
1680219820Sjeff
1681219820Sjeff/**
1682219820Sjeff * ib_req_ncomp_notif - Request completion notification when there are
1683219820Sjeff *   at least the specified number of unreaped completions on the CQ.
1684219820Sjeff * @cq: The CQ to generate an event for.
1685219820Sjeff * @wc_cnt: The number of unreaped completions that should be on the
1686219820Sjeff *   CQ before an event is generated.
1687219820Sjeff */
1688219820Sjeffstatic inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1689219820Sjeff{
1690219820Sjeff	return cq->device->req_ncomp_notif ?
1691219820Sjeff		cq->device->req_ncomp_notif(cq, wc_cnt) :
1692219820Sjeff		-ENOSYS;
1693219820Sjeff}
1694219820Sjeff
1695219820Sjeff/**
1696219820Sjeff * ib_get_dma_mr - Returns a memory region for system memory that is
1697219820Sjeff *   usable for DMA.
1698219820Sjeff * @pd: The protection domain associated with the memory region.
1699219820Sjeff * @mr_access_flags: Specifies the memory access rights.
1700219820Sjeff *
1701219820Sjeff * Note that the ib_dma_*() functions defined below must be used
1702219820Sjeff * to create/destroy addresses used with the Lkey or Rkey returned
1703219820Sjeff * by ib_get_dma_mr().
1704219820Sjeff */
1705219820Sjeffstruct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1706219820Sjeff
1707219820Sjeff/**
1708219820Sjeff * ib_dma_mapping_error - check a DMA addr for error
1709219820Sjeff * @dev: The device for which the dma_addr was created
1710219820Sjeff * @dma_addr: The DMA address to check
1711219820Sjeff */
1712219820Sjeffstatic inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1713219820Sjeff{
1714219820Sjeff	if (dev->dma_ops)
1715219820Sjeff		return dev->dma_ops->mapping_error(dev, dma_addr);
1716219820Sjeff	return dma_mapping_error(dev->dma_device, dma_addr);
1717219820Sjeff}
1718219820Sjeff
1719219820Sjeff/**
1720219820Sjeff * ib_dma_map_single - Map a kernel virtual address to DMA address
1721219820Sjeff * @dev: The device for which the dma_addr is to be created
1722219820Sjeff * @cpu_addr: The kernel virtual address
1723219820Sjeff * @size: The size of the region in bytes
1724219820Sjeff * @direction: The direction of the DMA
1725219820Sjeff */
1726219820Sjeffstatic inline u64 ib_dma_map_single(struct ib_device *dev,
1727219820Sjeff				    void *cpu_addr, size_t size,
1728219820Sjeff				    enum dma_data_direction direction)
1729219820Sjeff{
1730219820Sjeff	if (dev->dma_ops)
1731219820Sjeff		return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
1732219820Sjeff	return dma_map_single(dev->dma_device, cpu_addr, size, direction);
1733219820Sjeff}
1734219820Sjeff
1735219820Sjeff/**
1736219820Sjeff * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
1737219820Sjeff * @dev: The device for which the DMA address was created
1738219820Sjeff * @addr: The DMA address
1739219820Sjeff * @size: The size of the region in bytes
1740219820Sjeff * @direction: The direction of the DMA
1741219820Sjeff */
1742219820Sjeffstatic inline void ib_dma_unmap_single(struct ib_device *dev,
1743219820Sjeff				       u64 addr, size_t size,
1744219820Sjeff				       enum dma_data_direction direction)
1745219820Sjeff{
1746219820Sjeff	if (dev->dma_ops)
1747219820Sjeff		dev->dma_ops->unmap_single(dev, addr, size, direction);
1748219820Sjeff	else
1749219820Sjeff		dma_unmap_single(dev->dma_device, addr, size, direction);
1750219820Sjeff}
1751219820Sjeff
1752219820Sjeffstatic inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
1753219820Sjeff					  void *cpu_addr, size_t size,
1754219820Sjeff					  enum dma_data_direction direction,
1755219820Sjeff					  struct dma_attrs *attrs)
1756219820Sjeff{
1757219820Sjeff	return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
1758219820Sjeff				    direction, attrs);
1759219820Sjeff}
1760219820Sjeff
1761219820Sjeffstatic inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
1762219820Sjeff					     u64 addr, size_t size,
1763219820Sjeff					     enum dma_data_direction direction,
1764219820Sjeff					     struct dma_attrs *attrs)
1765219820Sjeff{
1766219820Sjeff	return dma_unmap_single_attrs(dev->dma_device, addr, size,
1767219820Sjeff				      direction, attrs);
1768219820Sjeff}
1769219820Sjeff
1770219820Sjeff/**
1771219820Sjeff * ib_dma_map_page - Map a physical page to DMA address
1772219820Sjeff * @dev: The device for which the dma_addr is to be created
1773219820Sjeff * @page: The page to be mapped
1774219820Sjeff * @offset: The offset within the page
1775219820Sjeff * @size: The size of the region in bytes
1776219820Sjeff * @direction: The direction of the DMA
1777219820Sjeff */
1778219820Sjeffstatic inline u64 ib_dma_map_page(struct ib_device *dev,
1779219820Sjeff				  struct page *page,
1780219820Sjeff				  unsigned long offset,
1781219820Sjeff				  size_t size,
1782219820Sjeff					 enum dma_data_direction direction)
1783219820Sjeff{
1784219820Sjeff	if (dev->dma_ops)
1785219820Sjeff		return dev->dma_ops->map_page(dev, page, offset, size, direction);
1786219820Sjeff	return dma_map_page(dev->dma_device, page, offset, size, direction);
1787219820Sjeff}
1788219820Sjeff
1789219820Sjeff/**
1790219820Sjeff * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
1791219820Sjeff * @dev: The device for which the DMA address was created
1792219820Sjeff * @addr: The DMA address
1793219820Sjeff * @size: The size of the region in bytes
1794219820Sjeff * @direction: The direction of the DMA
1795219820Sjeff */
1796219820Sjeffstatic inline void ib_dma_unmap_page(struct ib_device *dev,
1797219820Sjeff				     u64 addr, size_t size,
1798219820Sjeff				     enum dma_data_direction direction)
1799219820Sjeff{
1800219820Sjeff	if (dev->dma_ops)
1801219820Sjeff		dev->dma_ops->unmap_page(dev, addr, size, direction);
1802219820Sjeff	else
1803219820Sjeff		dma_unmap_page(dev->dma_device, addr, size, direction);
1804219820Sjeff}
1805219820Sjeff
1806219820Sjeff/**
1807219820Sjeff * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
1808219820Sjeff * @dev: The device for which the DMA addresses are to be created
1809219820Sjeff * @sg: The array of scatter/gather entries
1810219820Sjeff * @nents: The number of scatter/gather entries
1811219820Sjeff * @direction: The direction of the DMA
1812219820Sjeff */
1813219820Sjeffstatic inline int ib_dma_map_sg(struct ib_device *dev,
1814219820Sjeff				struct scatterlist *sg, int nents,
1815219820Sjeff				enum dma_data_direction direction)
1816219820Sjeff{
1817219820Sjeff	if (dev->dma_ops)
1818219820Sjeff		return dev->dma_ops->map_sg(dev, sg, nents, direction);
1819219820Sjeff	return dma_map_sg(dev->dma_device, sg, nents, direction);
1820219820Sjeff}
1821219820Sjeff
1822219820Sjeff/**
1823219820Sjeff * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
1824219820Sjeff * @dev: The device for which the DMA addresses were created
1825219820Sjeff * @sg: The array of scatter/gather entries
1826219820Sjeff * @nents: The number of scatter/gather entries
1827219820Sjeff * @direction: The direction of the DMA
1828219820Sjeff */
1829219820Sjeffstatic inline void ib_dma_unmap_sg(struct ib_device *dev,
1830219820Sjeff				   struct scatterlist *sg, int nents,
1831219820Sjeff				   enum dma_data_direction direction)
1832219820Sjeff{
1833219820Sjeff	if (dev->dma_ops)
1834219820Sjeff		dev->dma_ops->unmap_sg(dev, sg, nents, direction);
1835219820Sjeff	else
1836219820Sjeff		dma_unmap_sg(dev->dma_device, sg, nents, direction);
1837219820Sjeff}
1838219820Sjeff
1839219820Sjeffstatic inline int ib_dma_map_sg_attrs(struct ib_device *dev,
1840219820Sjeff				      struct scatterlist *sg, int nents,
1841219820Sjeff				      enum dma_data_direction direction,
1842219820Sjeff				      struct dma_attrs *attrs)
1843219820Sjeff{
1844219820Sjeff	return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
1845219820Sjeff}
1846219820Sjeff
1847219820Sjeffstatic inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
1848219820Sjeff					 struct scatterlist *sg, int nents,
1849219820Sjeff					 enum dma_data_direction direction,
1850219820Sjeff					 struct dma_attrs *attrs)
1851219820Sjeff{
1852219820Sjeff	dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
1853219820Sjeff}
1854219820Sjeff/**
1855219820Sjeff * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
1856219820Sjeff * @dev: The device for which the DMA addresses were created
1857219820Sjeff * @sg: The scatter/gather entry
1858219820Sjeff */
1859219820Sjeffstatic inline u64 ib_sg_dma_address(struct ib_device *dev,
1860219820Sjeff				    struct scatterlist *sg)
1861219820Sjeff{
1862219820Sjeff	if (dev->dma_ops)
1863219820Sjeff		return dev->dma_ops->dma_address(dev, sg);
1864219820Sjeff	return sg_dma_address(sg);
1865219820Sjeff}
1866219820Sjeff
1867219820Sjeff/**
1868219820Sjeff * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
1869219820Sjeff * @dev: The device for which the DMA addresses were created
1870219820Sjeff * @sg: The scatter/gather entry
1871219820Sjeff */
1872219820Sjeffstatic inline unsigned int ib_sg_dma_len(struct ib_device *dev,
1873219820Sjeff					 struct scatterlist *sg)
1874219820Sjeff{
1875219820Sjeff	if (dev->dma_ops)
1876219820Sjeff		return dev->dma_ops->dma_len(dev, sg);
1877219820Sjeff	return sg_dma_len(sg);
1878219820Sjeff}
1879219820Sjeff
1880219820Sjeff/**
1881219820Sjeff * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
1882219820Sjeff * @dev: The device for which the DMA address was created
1883219820Sjeff * @addr: The DMA address
1884219820Sjeff * @size: The size of the region in bytes
1885219820Sjeff * @dir: The direction of the DMA
1886219820Sjeff */
1887219820Sjeffstatic inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
1888219820Sjeff					      u64 addr,
1889219820Sjeff					      size_t size,
1890219820Sjeff					      enum dma_data_direction dir)
1891219820Sjeff{
1892219820Sjeff	if (dev->dma_ops)
1893219820Sjeff		dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
1894219820Sjeff	else
1895219820Sjeff		dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
1896219820Sjeff}
1897219820Sjeff
1898219820Sjeff/**
1899219820Sjeff * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
1900219820Sjeff * @dev: The device for which the DMA address was created
1901219820Sjeff * @addr: The DMA address
1902219820Sjeff * @size: The size of the region in bytes
1903219820Sjeff * @dir: The direction of the DMA
1904219820Sjeff */
1905219820Sjeffstatic inline void ib_dma_sync_single_for_device(struct ib_device *dev,
1906219820Sjeff						 u64 addr,
1907219820Sjeff						 size_t size,
1908219820Sjeff						 enum dma_data_direction dir)
1909219820Sjeff{
1910219820Sjeff	if (dev->dma_ops)
1911219820Sjeff		dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
1912219820Sjeff	else
1913219820Sjeff		dma_sync_single_for_device(dev->dma_device, addr, size, dir);
1914219820Sjeff}
1915219820Sjeff
1916219820Sjeff/**
1917219820Sjeff * ib_dma_alloc_coherent - Allocate memory and map it for DMA
1918219820Sjeff * @dev: The device for which the DMA address is requested
1919219820Sjeff * @size: The size of the region to allocate in bytes
1920219820Sjeff * @dma_handle: A pointer for returning the DMA address of the region
1921219820Sjeff * @flag: memory allocator flags
1922219820Sjeff */
1923219820Sjeffstatic inline void *ib_dma_alloc_coherent(struct ib_device *dev,
1924219820Sjeff					   size_t size,
1925219820Sjeff					   u64 *dma_handle,
1926219820Sjeff					   gfp_t flag)
1927219820Sjeff{
1928219820Sjeff	if (dev->dma_ops)
1929219820Sjeff		return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
1930219820Sjeff	else {
1931219820Sjeff		dma_addr_t handle;
1932219820Sjeff		void *ret;
1933219820Sjeff
1934219820Sjeff		ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
1935219820Sjeff		*dma_handle = handle;
1936219820Sjeff		return ret;
1937219820Sjeff	}
1938219820Sjeff}
1939219820Sjeff
1940219820Sjeff/**
1941219820Sjeff * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
1942219820Sjeff * @dev: The device for which the DMA addresses were allocated
1943219820Sjeff * @size: The size of the region
1944219820Sjeff * @cpu_addr: the address returned by ib_dma_alloc_coherent()
1945219820Sjeff * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
1946219820Sjeff */
1947219820Sjeffstatic inline void ib_dma_free_coherent(struct ib_device *dev,
1948219820Sjeff					size_t size, void *cpu_addr,
1949219820Sjeff					u64 dma_handle)
1950219820Sjeff{
1951219820Sjeff	if (dev->dma_ops)
1952219820Sjeff		dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
1953219820Sjeff	else
1954219820Sjeff		dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
1955219820Sjeff}
1956219820Sjeff
1957219820Sjeff/**
1958219820Sjeff * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
1959219820Sjeff *   by an HCA.
1960219820Sjeff * @pd: The protection domain associated assigned to the registered region.
1961219820Sjeff * @phys_buf_array: Specifies a list of physical buffers to use in the
1962219820Sjeff *   memory region.
1963219820Sjeff * @num_phys_buf: Specifies the size of the phys_buf_array.
1964219820Sjeff * @mr_access_flags: Specifies the memory access rights.
1965219820Sjeff * @iova_start: The offset of the region's starting I/O virtual address.
1966219820Sjeff */
1967219820Sjeffstruct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
1968219820Sjeff			     struct ib_phys_buf *phys_buf_array,
1969219820Sjeff			     int num_phys_buf,
1970219820Sjeff			     int mr_access_flags,
1971219820Sjeff			     u64 *iova_start);
1972219820Sjeff
1973219820Sjeff/**
1974219820Sjeff * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
1975219820Sjeff *   Conceptually, this call performs the functions deregister memory region
1976219820Sjeff *   followed by register physical memory region.  Where possible,
1977219820Sjeff *   resources are reused instead of deallocated and reallocated.
1978219820Sjeff * @mr: The memory region to modify.
1979219820Sjeff * @mr_rereg_mask: A bit-mask used to indicate which of the following
1980219820Sjeff *   properties of the memory region are being modified.
1981219820Sjeff * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
1982219820Sjeff *   the new protection domain to associated with the memory region,
1983219820Sjeff *   otherwise, this parameter is ignored.
1984219820Sjeff * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1985219820Sjeff *   field specifies a list of physical buffers to use in the new
1986219820Sjeff *   translation, otherwise, this parameter is ignored.
1987219820Sjeff * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
1988219820Sjeff *   field specifies the size of the phys_buf_array, otherwise, this
1989219820Sjeff *   parameter is ignored.
1990219820Sjeff * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
1991219820Sjeff *   field specifies the new memory access rights, otherwise, this
1992219820Sjeff *   parameter is ignored.
1993219820Sjeff * @iova_start: The offset of the region's starting I/O virtual address.
1994219820Sjeff */
1995219820Sjeffint ib_rereg_phys_mr(struct ib_mr *mr,
1996219820Sjeff		     int mr_rereg_mask,
1997219820Sjeff		     struct ib_pd *pd,
1998219820Sjeff		     struct ib_phys_buf *phys_buf_array,
1999219820Sjeff		     int num_phys_buf,
2000219820Sjeff		     int mr_access_flags,
2001219820Sjeff		     u64 *iova_start);
2002219820Sjeff
2003219820Sjeff/**
2004219820Sjeff * ib_query_mr - Retrieves information about a specific memory region.
2005219820Sjeff * @mr: The memory region to retrieve information about.
2006219820Sjeff * @mr_attr: The attributes of the specified memory region.
2007219820Sjeff */
2008219820Sjeffint ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
2009219820Sjeff
2010219820Sjeff/**
2011219820Sjeff * ib_dereg_mr - Deregisters a memory region and removes it from the
2012219820Sjeff *   HCA translation table.
2013219820Sjeff * @mr: The memory region to deregister.
2014219820Sjeff */
2015219820Sjeffint ib_dereg_mr(struct ib_mr *mr);
2016219820Sjeff
2017219820Sjeff/**
2018219820Sjeff * ib_alloc_fast_reg_mr - Allocates memory region usable with the
2019219820Sjeff *   IB_WR_FAST_REG_MR send work request.
2020219820Sjeff * @pd: The protection domain associated with the region.
2021219820Sjeff * @max_page_list_len: requested max physical buffer list length to be
2022219820Sjeff *   used with fast register work requests for this MR.
2023219820Sjeff */
2024219820Sjeffstruct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2025219820Sjeff
2026219820Sjeff/**
2027219820Sjeff * ib_alloc_fast_reg_page_list - Allocates a page list array
2028219820Sjeff * @device - ib device pointer.
2029219820Sjeff * @page_list_len - size of the page list array to be allocated.
2030219820Sjeff *
2031219820Sjeff * This allocates and returns a struct ib_fast_reg_page_list * and a
2032219820Sjeff * page_list array that is at least page_list_len in size.  The actual
2033219820Sjeff * size is returned in max_page_list_len.  The caller is responsible
2034219820Sjeff * for initializing the contents of the page_list array before posting
2035219820Sjeff * a send work request with the IB_WC_FAST_REG_MR opcode.
2036219820Sjeff *
2037219820Sjeff * The page_list array entries must be translated using one of the
2038219820Sjeff * ib_dma_*() functions just like the addresses passed to
2039219820Sjeff * ib_map_phys_fmr().  Once the ib_post_send() is issued, the struct
2040219820Sjeff * ib_fast_reg_page_list must not be modified by the caller until the
2041219820Sjeff * IB_WC_FAST_REG_MR work request completes.
2042219820Sjeff */
2043219820Sjeffstruct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2044219820Sjeff				struct ib_device *device, int page_list_len);
2045219820Sjeff
2046219820Sjeff/**
2047219820Sjeff * ib_free_fast_reg_page_list - Deallocates a previously allocated
2048219820Sjeff *   page list array.
2049219820Sjeff * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2050219820Sjeff */
2051219820Sjeffvoid ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2052219820Sjeff
2053219820Sjeff/**
2054219820Sjeff * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2055219820Sjeff *   R_Key and L_Key.
2056219820Sjeff * @mr - struct ib_mr pointer to be updated.
2057219820Sjeff * @newkey - new key to be used.
2058219820Sjeff */
2059219820Sjeffstatic inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2060219820Sjeff{
2061219820Sjeff	mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2062219820Sjeff	mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2063219820Sjeff}
2064219820Sjeff
2065219820Sjeff/**
2066219820Sjeff * ib_alloc_mw - Allocates a memory window.
2067219820Sjeff * @pd: The protection domain associated with the memory window.
2068219820Sjeff */
2069219820Sjeffstruct ib_mw *ib_alloc_mw(struct ib_pd *pd);
2070219820Sjeff
2071219820Sjeff/**
2072219820Sjeff * ib_bind_mw - Posts a work request to the send queue of the specified
2073219820Sjeff *   QP, which binds the memory window to the given address range and
2074219820Sjeff *   remote access attributes.
2075219820Sjeff * @qp: QP to post the bind work request on.
2076219820Sjeff * @mw: The memory window to bind.
2077219820Sjeff * @mw_bind: Specifies information about the memory window, including
2078219820Sjeff *   its address range, remote access rights, and associated memory region.
2079219820Sjeff */
2080219820Sjeffstatic inline int ib_bind_mw(struct ib_qp *qp,
2081219820Sjeff			     struct ib_mw *mw,
2082219820Sjeff			     struct ib_mw_bind *mw_bind)
2083219820Sjeff{
2084219820Sjeff	/* XXX reference counting in corresponding MR? */
2085219820Sjeff	return mw->device->bind_mw ?
2086219820Sjeff		mw->device->bind_mw(qp, mw, mw_bind) :
2087219820Sjeff		-ENOSYS;
2088219820Sjeff}
2089219820Sjeff
2090219820Sjeff/**
2091219820Sjeff * ib_dealloc_mw - Deallocates a memory window.
2092219820Sjeff * @mw: The memory window to deallocate.
2093219820Sjeff */
2094219820Sjeffint ib_dealloc_mw(struct ib_mw *mw);
2095219820Sjeff
2096219820Sjeff/**
2097219820Sjeff * ib_alloc_fmr - Allocates a unmapped fast memory region.
2098219820Sjeff * @pd: The protection domain associated with the unmapped region.
2099219820Sjeff * @mr_access_flags: Specifies the memory access rights.
2100219820Sjeff * @fmr_attr: Attributes of the unmapped region.
2101219820Sjeff *
2102219820Sjeff * A fast memory region must be mapped before it can be used as part of
2103219820Sjeff * a work request.
2104219820Sjeff */
2105219820Sjeffstruct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2106219820Sjeff			    int mr_access_flags,
2107219820Sjeff			    struct ib_fmr_attr *fmr_attr);
2108219820Sjeff
2109219820Sjeff/**
2110219820Sjeff * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2111219820Sjeff * @fmr: The fast memory region to associate with the pages.
2112219820Sjeff * @page_list: An array of physical pages to map to the fast memory region.
2113219820Sjeff * @list_len: The number of pages in page_list.
2114219820Sjeff * @iova: The I/O virtual address to use with the mapped region.
2115219820Sjeff */
2116219820Sjeffstatic inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2117219820Sjeff				  u64 *page_list, int list_len,
2118219820Sjeff				  u64 iova)
2119219820Sjeff{
2120219820Sjeff	return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2121219820Sjeff}
2122219820Sjeff
2123219820Sjeff/**
2124219820Sjeff * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2125219820Sjeff * @fmr_list: A linked list of fast memory regions to unmap.
2126219820Sjeff */
2127219820Sjeffint ib_unmap_fmr(struct list_head *fmr_list);
2128219820Sjeff
2129219820Sjeff/**
2130219820Sjeff * ib_dealloc_fmr - Deallocates a fast memory region.
2131219820Sjeff * @fmr: The fast memory region to deallocate.
2132219820Sjeff */
2133219820Sjeffint ib_dealloc_fmr(struct ib_fmr *fmr);
2134219820Sjeff
2135219820Sjeff/**
2136219820Sjeff * ib_attach_mcast - Attaches the specified QP to a multicast group.
2137219820Sjeff * @qp: QP to attach to the multicast group.  The QP must be type
2138219820Sjeff *   IB_QPT_UD.
2139219820Sjeff * @gid: Multicast group GID.
2140219820Sjeff * @lid: Multicast group LID in host byte order.
2141219820Sjeff *
2142219820Sjeff * In order to send and receive multicast packets, subnet
2143219820Sjeff * administration must have created the multicast group and configured
2144219820Sjeff * the fabric appropriately.  The port associated with the specified
2145219820Sjeff * QP must also be a member of the multicast group.
2146219820Sjeff */
2147219820Sjeffint ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2148219820Sjeff
2149219820Sjeff/**
2150219820Sjeff * ib_detach_mcast - Detaches the specified QP from a multicast group.
2151219820Sjeff * @qp: QP to detach from the multicast group.
2152219820Sjeff * @gid: Multicast group GID.
2153219820Sjeff * @lid: Multicast group LID in host byte order.
2154219820Sjeff */
2155219820Sjeffint ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2156219820Sjeff
2157219820Sjeff
2158219820Sjeff/**
2159219820Sjeff * ib_dealloc_xrcd - Deallocates an extended reliably connected domain.
2160219820Sjeff * @xrcd: The xrc domain to deallocate.
2161219820Sjeff */
2162219820Sjeffint ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2163219820Sjeff
2164219820Sjeff/**
2165219820Sjeff * ib_alloc_xrcd - Allocates an extended reliably connected domain.
2166219820Sjeff * @device: The device on which to allocate the xrcd.
2167219820Sjeff */
2168219820Sjeffstruct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2169219820Sjeff
2170219820Sjeff#endif /* IB_VERBS_H */
2171