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>
50255932Salfred#include <linux/workqueue.h>
51219820Sjeff
52219820Sjeff#include <asm/uaccess.h>
53219820Sjeff#include <linux/rbtree.h>
54219820Sjeff#include <linux/mutex.h>
55219820Sjeff
56255932Salfredextern struct workqueue_struct *ib_wq;
57255932Salfred
58219820Sjeffunion ib_gid {
59219820Sjeff	u8	raw[16];
60219820Sjeff	struct {
61219820Sjeff		__be64	subnet_prefix;
62219820Sjeff		__be64	interface_id;
63219820Sjeff	} global;
64219820Sjeff};
65219820Sjeff
66219820Sjeffenum rdma_node_type {
67219820Sjeff	/* IB values map to NodeInfo:NodeType. */
68219820Sjeff	RDMA_NODE_IB_CA 	= 1,
69219820Sjeff	RDMA_NODE_IB_SWITCH,
70219820Sjeff	RDMA_NODE_IB_ROUTER,
71219820Sjeff	RDMA_NODE_RNIC
72219820Sjeff};
73219820Sjeff
74219820Sjeffenum rdma_transport_type {
75219820Sjeff	RDMA_TRANSPORT_IB,
76219820Sjeff	RDMA_TRANSPORT_IWARP
77219820Sjeff};
78219820Sjeff
79219820Sjeffenum rdma_transport_type
80219820Sjeffrdma_node_get_transport(enum rdma_node_type node_type) __attribute_const__;
81219820Sjeff
82219820Sjeffenum rdma_link_layer {
83219820Sjeff	IB_LINK_LAYER_UNSPECIFIED,
84219820Sjeff	IB_LINK_LAYER_INFINIBAND,
85219820Sjeff	IB_LINK_LAYER_ETHERNET,
86219820Sjeff};
87219820Sjeff
88219820Sjeffenum ib_device_cap_flags {
89219820Sjeff	IB_DEVICE_RESIZE_MAX_WR		= 1,
90219820Sjeff	IB_DEVICE_BAD_PKEY_CNTR		= (1<<1),
91219820Sjeff	IB_DEVICE_BAD_QKEY_CNTR		= (1<<2),
92219820Sjeff	IB_DEVICE_RAW_MULTI		= (1<<3),
93219820Sjeff	IB_DEVICE_AUTO_PATH_MIG		= (1<<4),
94219820Sjeff	IB_DEVICE_CHANGE_PHY_PORT	= (1<<5),
95219820Sjeff	IB_DEVICE_UD_AV_PORT_ENFORCE	= (1<<6),
96219820Sjeff	IB_DEVICE_CURR_QP_STATE_MOD	= (1<<7),
97219820Sjeff	IB_DEVICE_SHUTDOWN_PORT		= (1<<8),
98219820Sjeff	IB_DEVICE_INIT_TYPE		= (1<<9),
99219820Sjeff	IB_DEVICE_PORT_ACTIVE_EVENT	= (1<<10),
100219820Sjeff	IB_DEVICE_SYS_IMAGE_GUID	= (1<<11),
101219820Sjeff	IB_DEVICE_RC_RNR_NAK_GEN	= (1<<12),
102219820Sjeff	IB_DEVICE_SRQ_RESIZE		= (1<<13),
103219820Sjeff	IB_DEVICE_N_NOTIFY_CQ		= (1<<14),
104219820Sjeff	IB_DEVICE_LOCAL_DMA_LKEY	= (1<<15),
105219820Sjeff	IB_DEVICE_RESERVED		= (1<<16), /* old SEND_W_INV */
106219820Sjeff	IB_DEVICE_MEM_WINDOW		= (1<<17),
107219820Sjeff	/*
108219820Sjeff	 * Devices should set IB_DEVICE_UD_IP_SUM if they support
109219820Sjeff	 * insertion of UDP and TCP checksum on outgoing UD IPoIB
110219820Sjeff	 * messages and can verify the validity of checksum for
111219820Sjeff	 * incoming messages.  Setting this flag implies that the
112219820Sjeff	 * IPoIB driver may set NETIF_F_IP_CSUM for datagram mode.
113219820Sjeff	 */
114219820Sjeff	IB_DEVICE_UD_IP_CSUM		= (1<<18),
115219820Sjeff	IB_DEVICE_UD_TSO		= (1<<19),
116219820Sjeff	IB_DEVICE_XRC			= (1<<20),
117219820Sjeff	IB_DEVICE_MEM_MGT_EXTENSIONS	= (1<<21),
118219820Sjeff	IB_DEVICE_BLOCK_MULTICAST_LOOPBACK = (1<<22),
119255932Salfred	IB_DEVICE_MR_ALLOCATE		= (1<<23),
120255932Salfred	IB_DEVICE_SHARED_MR             = (1<<24),
121255932Salfred	IB_DEVICE_QPG			= (1<<25),
122255932Salfred	IB_DEVICE_UD_RSS		= (1<<26),
123255932Salfred	IB_DEVICE_UD_TSS		= (1<<27)
124219820Sjeff};
125219820Sjeff
126219820Sjeffenum ib_atomic_cap {
127219820Sjeff	IB_ATOMIC_NONE,
128219820Sjeff	IB_ATOMIC_HCA,
129219820Sjeff	IB_ATOMIC_GLOB
130219820Sjeff};
131219820Sjeff
132219820Sjeffstruct ib_device_attr {
133219820Sjeff	u64			fw_ver;
134219820Sjeff	__be64			sys_image_guid;
135219820Sjeff	u64			max_mr_size;
136219820Sjeff	u64			page_size_cap;
137219820Sjeff	u32			vendor_id;
138219820Sjeff	u32			vendor_part_id;
139219820Sjeff	u32			hw_ver;
140219820Sjeff	int			max_qp;
141219820Sjeff	int			max_qp_wr;
142219820Sjeff	int			device_cap_flags;
143219820Sjeff	int			max_sge;
144219820Sjeff	int			max_sge_rd;
145219820Sjeff	int			max_cq;
146219820Sjeff	int			max_cqe;
147219820Sjeff	int			max_mr;
148219820Sjeff	int			max_pd;
149219820Sjeff	int			max_qp_rd_atom;
150219820Sjeff	int			max_ee_rd_atom;
151219820Sjeff	int			max_res_rd_atom;
152219820Sjeff	int			max_qp_init_rd_atom;
153219820Sjeff	int			max_ee_init_rd_atom;
154219820Sjeff	enum ib_atomic_cap	atomic_cap;
155219820Sjeff	enum ib_atomic_cap	masked_atomic_cap;
156219820Sjeff	int			max_ee;
157219820Sjeff	int			max_rdd;
158219820Sjeff	int			max_mw;
159219820Sjeff	int			max_raw_ipv6_qp;
160219820Sjeff	int			max_raw_ethy_qp;
161219820Sjeff	int			max_mcast_grp;
162219820Sjeff	int			max_mcast_qp_attach;
163219820Sjeff	int			max_total_mcast_qp_attach;
164219820Sjeff	int			max_ah;
165219820Sjeff	int			max_fmr;
166219820Sjeff	int			max_map_per_fmr;
167219820Sjeff	int			max_srq;
168219820Sjeff	int			max_srq_wr;
169219820Sjeff	int			max_srq_sge;
170219820Sjeff	unsigned int		max_fast_reg_page_list_len;
171255932Salfred	int			max_rss_tbl_sz;
172219820Sjeff	u16			max_pkeys;
173219820Sjeff	u8			local_ca_ack_delay;
174219820Sjeff};
175219820Sjeff
176219820Sjeffenum ib_mtu {
177219820Sjeff	IB_MTU_256  = 1,
178219820Sjeff	IB_MTU_512  = 2,
179219820Sjeff	IB_MTU_1024 = 3,
180219820Sjeff	IB_MTU_2048 = 4,
181219820Sjeff	IB_MTU_4096 = 5
182219820Sjeff};
183219820Sjeff
184219820Sjeffstatic inline int ib_mtu_enum_to_int(enum ib_mtu mtu)
185219820Sjeff{
186219820Sjeff	switch (mtu) {
187219820Sjeff	case IB_MTU_256:  return  256;
188219820Sjeff	case IB_MTU_512:  return  512;
189219820Sjeff	case IB_MTU_1024: return 1024;
190219820Sjeff	case IB_MTU_2048: return 2048;
191219820Sjeff	case IB_MTU_4096: return 4096;
192219820Sjeff	default: 	  return -1;
193219820Sjeff	}
194219820Sjeff}
195219820Sjeff
196219820Sjeffenum ib_port_state {
197219820Sjeff	IB_PORT_NOP		= 0,
198219820Sjeff	IB_PORT_DOWN		= 1,
199219820Sjeff	IB_PORT_INIT		= 2,
200219820Sjeff	IB_PORT_ARMED		= 3,
201219820Sjeff	IB_PORT_ACTIVE		= 4,
202219820Sjeff	IB_PORT_ACTIVE_DEFER	= 5
203219820Sjeff};
204219820Sjeff
205219820Sjeffenum ib_port_cap_flags {
206219820Sjeff	IB_PORT_SM				= 1 <<  1,
207219820Sjeff	IB_PORT_NOTICE_SUP			= 1 <<  2,
208219820Sjeff	IB_PORT_TRAP_SUP			= 1 <<  3,
209219820Sjeff	IB_PORT_OPT_IPD_SUP                     = 1 <<  4,
210219820Sjeff	IB_PORT_AUTO_MIGR_SUP			= 1 <<  5,
211219820Sjeff	IB_PORT_SL_MAP_SUP			= 1 <<  6,
212219820Sjeff	IB_PORT_MKEY_NVRAM			= 1 <<  7,
213219820Sjeff	IB_PORT_PKEY_NVRAM			= 1 <<  8,
214219820Sjeff	IB_PORT_LED_INFO_SUP			= 1 <<  9,
215219820Sjeff	IB_PORT_SM_DISABLED			= 1 << 10,
216219820Sjeff	IB_PORT_SYS_IMAGE_GUID_SUP		= 1 << 11,
217219820Sjeff	IB_PORT_PKEY_SW_EXT_PORT_TRAP_SUP	= 1 << 12,
218255932Salfred	IB_PORT_EXTENDED_SPEEDS_SUP             = 1 << 14,
219219820Sjeff	IB_PORT_CM_SUP				= 1 << 16,
220219820Sjeff	IB_PORT_SNMP_TUNNEL_SUP			= 1 << 17,
221219820Sjeff	IB_PORT_REINIT_SUP			= 1 << 18,
222219820Sjeff	IB_PORT_DEVICE_MGMT_SUP			= 1 << 19,
223219820Sjeff	IB_PORT_VENDOR_CLASS_SUP		= 1 << 20,
224219820Sjeff	IB_PORT_DR_NOTICE_SUP			= 1 << 21,
225219820Sjeff	IB_PORT_CAP_MASK_NOTICE_SUP		= 1 << 22,
226219820Sjeff	IB_PORT_BOOT_MGMT_SUP			= 1 << 23,
227219820Sjeff	IB_PORT_LINK_LATENCY_SUP		= 1 << 24,
228219820Sjeff	IB_PORT_CLIENT_REG_SUP			= 1 << 25
229219820Sjeff};
230219820Sjeff
231219820Sjeffenum ib_port_width {
232219820Sjeff	IB_WIDTH_1X	= 1,
233219820Sjeff	IB_WIDTH_4X	= 2,
234219820Sjeff	IB_WIDTH_8X	= 4,
235219820Sjeff	IB_WIDTH_12X	= 8
236219820Sjeff};
237219820Sjeff
238219820Sjeffstatic inline int ib_width_enum_to_int(enum ib_port_width width)
239219820Sjeff{
240219820Sjeff	switch (width) {
241219820Sjeff	case IB_WIDTH_1X:  return  1;
242219820Sjeff	case IB_WIDTH_4X:  return  4;
243219820Sjeff	case IB_WIDTH_8X:  return  8;
244219820Sjeff	case IB_WIDTH_12X: return 12;
245219820Sjeff	default: 	  return -1;
246219820Sjeff	}
247219820Sjeff}
248219820Sjeff
249255932Salfredenum ib_port_speed {
250255932Salfred	IB_SPEED_SDR	= 1,
251255932Salfred	IB_SPEED_DDR	= 2,
252255932Salfred	IB_SPEED_QDR	= 4,
253255932Salfred	IB_SPEED_FDR10	= 8,
254255932Salfred	IB_SPEED_FDR	= 16,
255255932Salfred	IB_SPEED_EDR	= 32
256255932Salfred};
257255932Salfred
258219820Sjeffstruct ib_protocol_stats {
259219820Sjeff	/* TBD... */
260219820Sjeff};
261219820Sjeff
262219820Sjeffstruct iw_protocol_stats {
263219820Sjeff	u64	ipInReceives;
264219820Sjeff	u64	ipInHdrErrors;
265219820Sjeff	u64	ipInTooBigErrors;
266219820Sjeff	u64	ipInNoRoutes;
267219820Sjeff	u64	ipInAddrErrors;
268219820Sjeff	u64	ipInUnknownProtos;
269219820Sjeff	u64	ipInTruncatedPkts;
270219820Sjeff	u64	ipInDiscards;
271219820Sjeff	u64	ipInDelivers;
272219820Sjeff	u64	ipOutForwDatagrams;
273219820Sjeff	u64	ipOutRequests;
274219820Sjeff	u64	ipOutDiscards;
275219820Sjeff	u64	ipOutNoRoutes;
276219820Sjeff	u64	ipReasmTimeout;
277219820Sjeff	u64	ipReasmReqds;
278219820Sjeff	u64	ipReasmOKs;
279219820Sjeff	u64	ipReasmFails;
280219820Sjeff	u64	ipFragOKs;
281219820Sjeff	u64	ipFragFails;
282219820Sjeff	u64	ipFragCreates;
283219820Sjeff	u64	ipInMcastPkts;
284219820Sjeff	u64	ipOutMcastPkts;
285219820Sjeff	u64	ipInBcastPkts;
286219820Sjeff	u64	ipOutBcastPkts;
287219820Sjeff
288219820Sjeff	u64	tcpRtoAlgorithm;
289219820Sjeff	u64	tcpRtoMin;
290219820Sjeff	u64	tcpRtoMax;
291219820Sjeff	u64	tcpMaxConn;
292219820Sjeff	u64	tcpActiveOpens;
293219820Sjeff	u64	tcpPassiveOpens;
294219820Sjeff	u64	tcpAttemptFails;
295219820Sjeff	u64	tcpEstabResets;
296219820Sjeff	u64	tcpCurrEstab;
297219820Sjeff	u64	tcpInSegs;
298219820Sjeff	u64	tcpOutSegs;
299219820Sjeff	u64	tcpRetransSegs;
300219820Sjeff	u64	tcpInErrs;
301219820Sjeff	u64	tcpOutRsts;
302219820Sjeff};
303219820Sjeff
304219820Sjeffunion rdma_protocol_stats {
305219820Sjeff	struct ib_protocol_stats	ib;
306219820Sjeff	struct iw_protocol_stats	iw;
307219820Sjeff};
308219820Sjeff
309219820Sjeffstruct ib_port_attr {
310219820Sjeff	enum ib_port_state	state;
311219820Sjeff	enum ib_mtu		max_mtu;
312219820Sjeff	enum ib_mtu		active_mtu;
313219820Sjeff	int			gid_tbl_len;
314219820Sjeff	u32			port_cap_flags;
315219820Sjeff	u32			max_msg_sz;
316219820Sjeff	u32			bad_pkey_cntr;
317219820Sjeff	u32			qkey_viol_cntr;
318219820Sjeff	u16			pkey_tbl_len;
319219820Sjeff	u16			lid;
320219820Sjeff	u16			sm_lid;
321219820Sjeff	u8			lmc;
322219820Sjeff	u8			max_vl_num;
323219820Sjeff	u8			sm_sl;
324219820Sjeff	u8			subnet_timeout;
325219820Sjeff	u8			init_type_reply;
326219820Sjeff	u8			active_width;
327219820Sjeff	u8			active_speed;
328219820Sjeff	u8                      phys_state;
329219820Sjeff	enum rdma_link_layer	link_layer;
330219820Sjeff};
331219820Sjeff
332219820Sjeffenum ib_device_modify_flags {
333219820Sjeff	IB_DEVICE_MODIFY_SYS_IMAGE_GUID	= 1 << 0,
334219820Sjeff	IB_DEVICE_MODIFY_NODE_DESC	= 1 << 1
335219820Sjeff};
336219820Sjeff
337219820Sjeffstruct ib_device_modify {
338219820Sjeff	u64	sys_image_guid;
339219820Sjeff	char	node_desc[64];
340219820Sjeff};
341219820Sjeff
342219820Sjeffenum ib_port_modify_flags {
343219820Sjeff	IB_PORT_SHUTDOWN		= 1,
344219820Sjeff	IB_PORT_INIT_TYPE		= (1<<2),
345219820Sjeff	IB_PORT_RESET_QKEY_CNTR		= (1<<3)
346219820Sjeff};
347219820Sjeff
348219820Sjeffstruct ib_port_modify {
349219820Sjeff	u32	set_port_cap_mask;
350219820Sjeff	u32	clr_port_cap_mask;
351219820Sjeff	u8	init_type;
352219820Sjeff};
353219820Sjeff
354219820Sjeffenum ib_event_type {
355219820Sjeff	IB_EVENT_CQ_ERR,
356219820Sjeff	IB_EVENT_QP_FATAL,
357219820Sjeff	IB_EVENT_QP_REQ_ERR,
358219820Sjeff	IB_EVENT_QP_ACCESS_ERR,
359219820Sjeff	IB_EVENT_COMM_EST,
360219820Sjeff	IB_EVENT_SQ_DRAINED,
361219820Sjeff	IB_EVENT_PATH_MIG,
362219820Sjeff	IB_EVENT_PATH_MIG_ERR,
363219820Sjeff	IB_EVENT_DEVICE_FATAL,
364219820Sjeff	IB_EVENT_PORT_ACTIVE,
365219820Sjeff	IB_EVENT_PORT_ERR,
366219820Sjeff	IB_EVENT_LID_CHANGE,
367219820Sjeff	IB_EVENT_PKEY_CHANGE,
368219820Sjeff	IB_EVENT_SM_CHANGE,
369219820Sjeff	IB_EVENT_SRQ_ERR,
370219820Sjeff	IB_EVENT_SRQ_LIMIT_REACHED,
371219820Sjeff	IB_EVENT_QP_LAST_WQE_REACHED,
372219820Sjeff	IB_EVENT_CLIENT_REREGISTER,
373219820Sjeff	IB_EVENT_GID_CHANGE,
374219820Sjeff};
375219820Sjeff
376219820Sjeffenum ib_event_flags {
377219820Sjeff	IB_XRC_QP_EVENT_FLAG = 0x80000000,
378219820Sjeff};
379219820Sjeff
380219820Sjeffstruct ib_event {
381219820Sjeff	struct ib_device	*device;
382219820Sjeff	union {
383219820Sjeff		struct ib_cq	*cq;
384219820Sjeff		struct ib_qp	*qp;
385219820Sjeff		struct ib_srq	*srq;
386219820Sjeff		u8		port_num;
387219820Sjeff		u32		xrc_qp_num;
388219820Sjeff	} element;
389219820Sjeff	enum ib_event_type	event;
390219820Sjeff};
391219820Sjeff
392219820Sjeffstruct ib_event_handler {
393219820Sjeff	struct ib_device *device;
394219820Sjeff	void            (*handler)(struct ib_event_handler *, struct ib_event *);
395219820Sjeff	struct list_head  list;
396219820Sjeff};
397219820Sjeff
398219820Sjeff#define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler)		\
399219820Sjeff	do {							\
400219820Sjeff		(_ptr)->device  = _device;			\
401219820Sjeff		(_ptr)->handler = _handler;			\
402219820Sjeff		INIT_LIST_HEAD(&(_ptr)->list);			\
403219820Sjeff	} while (0)
404219820Sjeff
405219820Sjeffstruct ib_global_route {
406219820Sjeff	union ib_gid	dgid;
407219820Sjeff	u32		flow_label;
408219820Sjeff	u8		sgid_index;
409219820Sjeff	u8		hop_limit;
410219820Sjeff	u8		traffic_class;
411219820Sjeff};
412219820Sjeff
413219820Sjeffstruct ib_grh {
414219820Sjeff	__be32		version_tclass_flow;
415219820Sjeff	__be16		paylen;
416219820Sjeff	u8		next_hdr;
417219820Sjeff	u8		hop_limit;
418219820Sjeff	union ib_gid	sgid;
419219820Sjeff	union ib_gid	dgid;
420219820Sjeff};
421219820Sjeff
422219820Sjeffenum {
423219820Sjeff	IB_MULTICAST_QPN = 0xffffff
424219820Sjeff};
425219820Sjeff
426219820Sjeff#define IB_LID_PERMISSIVE	cpu_to_be16(0xFFFF)
427219820Sjeff
428219820Sjeffenum ib_ah_flags {
429219820Sjeff	IB_AH_GRH	= 1
430219820Sjeff};
431219820Sjeff
432219820Sjeffenum ib_rate {
433219820Sjeff	IB_RATE_PORT_CURRENT = 0,
434219820Sjeff	IB_RATE_2_5_GBPS = 2,
435219820Sjeff	IB_RATE_5_GBPS   = 5,
436219820Sjeff	IB_RATE_10_GBPS  = 3,
437219820Sjeff	IB_RATE_20_GBPS  = 6,
438219820Sjeff	IB_RATE_30_GBPS  = 4,
439219820Sjeff	IB_RATE_40_GBPS  = 7,
440219820Sjeff	IB_RATE_60_GBPS  = 8,
441219820Sjeff	IB_RATE_80_GBPS  = 9,
442255932Salfred	IB_RATE_120_GBPS = 10,
443255932Salfred	IB_RATE_14_GBPS  = 11,
444255932Salfred	IB_RATE_56_GBPS  = 12,
445255932Salfred	IB_RATE_112_GBPS = 13,
446255932Salfred	IB_RATE_168_GBPS = 14,
447255932Salfred	IB_RATE_25_GBPS  = 15,
448255932Salfred	IB_RATE_100_GBPS = 16,
449255932Salfred	IB_RATE_200_GBPS = 17,
450255932Salfred	IB_RATE_300_GBPS = 18
451219820Sjeff};
452219820Sjeff
453219820Sjeff/**
454219820Sjeff * ib_rate_to_mult - Convert the IB rate enum to a multiple of the
455219820Sjeff * base rate of 2.5 Gbit/sec.  For example, IB_RATE_5_GBPS will be
456219820Sjeff * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
457219820Sjeff * @rate: rate to convert.
458219820Sjeff */
459219820Sjeffint ib_rate_to_mult(enum ib_rate rate) __attribute_const__;
460219820Sjeff
461219820Sjeff/**
462255932Salfred * ib_rate_to_mbps - Convert the IB rate enum to Mbps.
463255932Salfred * For example, IB_RATE_2_5_GBPS will be converted to 2500.
464255932Salfred * @rate: rate to convert.
465255932Salfred */
466255932Salfredint ib_rate_to_mbps(enum ib_rate rate) __attribute_const__;
467255932Salfred
468255932Salfred/**
469219820Sjeff * mult_to_ib_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate
470219820Sjeff * enum.
471219820Sjeff * @mult: multiple to convert.
472219820Sjeff */
473219820Sjeffenum ib_rate mult_to_ib_rate(int mult) __attribute_const__;
474219820Sjeff
475219820Sjeffstruct ib_ah_attr {
476219820Sjeff	struct ib_global_route	grh;
477219820Sjeff	u16			dlid;
478219820Sjeff	u8			sl;
479219820Sjeff	u8			src_path_bits;
480219820Sjeff	u8			static_rate;
481219820Sjeff	u8			ah_flags;
482219820Sjeff	u8			port_num;
483219820Sjeff};
484219820Sjeff
485219820Sjeffenum ib_wc_status {
486219820Sjeff	IB_WC_SUCCESS,
487219820Sjeff	IB_WC_LOC_LEN_ERR,
488219820Sjeff	IB_WC_LOC_QP_OP_ERR,
489219820Sjeff	IB_WC_LOC_EEC_OP_ERR,
490219820Sjeff	IB_WC_LOC_PROT_ERR,
491219820Sjeff	IB_WC_WR_FLUSH_ERR,
492219820Sjeff	IB_WC_MW_BIND_ERR,
493219820Sjeff	IB_WC_BAD_RESP_ERR,
494219820Sjeff	IB_WC_LOC_ACCESS_ERR,
495219820Sjeff	IB_WC_REM_INV_REQ_ERR,
496219820Sjeff	IB_WC_REM_ACCESS_ERR,
497219820Sjeff	IB_WC_REM_OP_ERR,
498219820Sjeff	IB_WC_RETRY_EXC_ERR,
499219820Sjeff	IB_WC_RNR_RETRY_EXC_ERR,
500219820Sjeff	IB_WC_LOC_RDD_VIOL_ERR,
501219820Sjeff	IB_WC_REM_INV_RD_REQ_ERR,
502219820Sjeff	IB_WC_REM_ABORT_ERR,
503219820Sjeff	IB_WC_INV_EECN_ERR,
504219820Sjeff	IB_WC_INV_EEC_STATE_ERR,
505219820Sjeff	IB_WC_FATAL_ERR,
506219820Sjeff	IB_WC_RESP_TIMEOUT_ERR,
507219820Sjeff	IB_WC_GENERAL_ERR
508219820Sjeff};
509219820Sjeff
510219820Sjeffenum ib_wc_opcode {
511219820Sjeff	IB_WC_SEND,
512219820Sjeff	IB_WC_RDMA_WRITE,
513219820Sjeff	IB_WC_RDMA_READ,
514219820Sjeff	IB_WC_COMP_SWAP,
515219820Sjeff	IB_WC_FETCH_ADD,
516219820Sjeff	IB_WC_BIND_MW,
517219820Sjeff	IB_WC_LSO,
518219820Sjeff	IB_WC_LOCAL_INV,
519219820Sjeff	IB_WC_FAST_REG_MR,
520219820Sjeff	IB_WC_MASKED_COMP_SWAP,
521219820Sjeff	IB_WC_MASKED_FETCH_ADD,
522219820Sjeff/*
523219820Sjeff * Set value of IB_WC_RECV so consumers can test if a completion is a
524219820Sjeff * receive by testing (opcode & IB_WC_RECV).
525219820Sjeff */
526219820Sjeff	IB_WC_RECV			= 1 << 7,
527219820Sjeff	IB_WC_RECV_RDMA_WITH_IMM
528219820Sjeff};
529219820Sjeff
530219820Sjeffenum ib_wc_flags {
531219820Sjeff	IB_WC_GRH		= 1,
532219820Sjeff	IB_WC_WITH_IMM		= (1<<1),
533219820Sjeff	IB_WC_WITH_INVALIDATE	= (1<<2),
534255932Salfred	IB_WC_IP_CSUM_OK	= (1<<3),
535219820Sjeff};
536219820Sjeff
537219820Sjeffstruct ib_wc {
538219820Sjeff	u64			wr_id;
539219820Sjeff	enum ib_wc_status	status;
540219820Sjeff	enum ib_wc_opcode	opcode;
541219820Sjeff	u32			vendor_err;
542219820Sjeff	u32			byte_len;
543219820Sjeff	struct ib_qp	       *qp;
544219820Sjeff	union {
545219820Sjeff		__be32		imm_data;
546219820Sjeff		u32		invalidate_rkey;
547219820Sjeff	} ex;
548219820Sjeff	u32			src_qp;
549219820Sjeff	int			wc_flags;
550219820Sjeff	u16			pkey_index;
551219820Sjeff	u16			slid;
552219820Sjeff	u8			sl;
553219820Sjeff	u8			dlid_path_bits;
554219820Sjeff	u8			port_num;	/* valid only for DR SMPs on switches */
555219820Sjeff	int			csum_ok;
556219820Sjeff};
557219820Sjeff
558219820Sjeffenum ib_cq_notify_flags {
559219820Sjeff	IB_CQ_SOLICITED			= 1 << 0,
560219820Sjeff	IB_CQ_NEXT_COMP			= 1 << 1,
561219820Sjeff	IB_CQ_SOLICITED_MASK		= IB_CQ_SOLICITED | IB_CQ_NEXT_COMP,
562219820Sjeff	IB_CQ_REPORT_MISSED_EVENTS	= 1 << 2,
563219820Sjeff};
564219820Sjeff
565255932Salfredenum ib_srq_type {
566255932Salfred	IB_SRQT_BASIC,
567255932Salfred	IB_SRQT_XRC
568255932Salfred};
569255932Salfred
570219820Sjeffenum ib_srq_attr_mask {
571219820Sjeff	IB_SRQ_MAX_WR	= 1 << 0,
572219820Sjeff	IB_SRQ_LIMIT	= 1 << 1,
573219820Sjeff};
574219820Sjeff
575219820Sjeffstruct ib_srq_attr {
576219820Sjeff	u32	max_wr;
577219820Sjeff	u32	max_sge;
578219820Sjeff	u32	srq_limit;
579219820Sjeff};
580219820Sjeff
581219820Sjeffstruct ib_srq_init_attr {
582219820Sjeff	void		      (*event_handler)(struct ib_event *, void *);
583219820Sjeff	void		       *srq_context;
584219820Sjeff	struct ib_srq_attr	attr;
585255932Salfred	enum ib_srq_type	srq_type;
586255932Salfred
587255932Salfred	union {
588255932Salfred		struct {
589255932Salfred			struct ib_xrcd *xrcd;
590255932Salfred			struct ib_cq   *cq;
591255932Salfred		} xrc;
592255932Salfred	} ext;
593219820Sjeff};
594219820Sjeff
595219820Sjeffstruct ib_qp_cap {
596219820Sjeff	u32	max_send_wr;
597219820Sjeff	u32	max_recv_wr;
598219820Sjeff	u32	max_send_sge;
599219820Sjeff	u32	max_recv_sge;
600219820Sjeff	u32	max_inline_data;
601255932Salfred	u32	qpg_tss_mask_sz;
602219820Sjeff};
603219820Sjeff
604219820Sjeffenum ib_sig_type {
605219820Sjeff	IB_SIGNAL_ALL_WR,
606219820Sjeff	IB_SIGNAL_REQ_WR
607219820Sjeff};
608219820Sjeff
609219820Sjeffenum ib_qp_type {
610219820Sjeff	/*
611219820Sjeff	 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
612219820Sjeff	 * here (and in that order) since the MAD layer uses them as
613219820Sjeff	 * indices into a 2-entry table.
614219820Sjeff	 */
615219820Sjeff	IB_QPT_SMI,
616219820Sjeff	IB_QPT_GSI,
617219820Sjeff
618219820Sjeff	IB_QPT_RC,
619219820Sjeff	IB_QPT_UC,
620219820Sjeff	IB_QPT_UD,
621219820Sjeff	IB_QPT_XRC,
622219820Sjeff	IB_QPT_RAW_IPV6,
623255932Salfred	IB_QPT_RAW_ETHERTYPE,
624255932Salfred	IB_QPT_RAW_PACKET = 8,
625255932Salfred	IB_QPT_XRC_INI = 9,
626255932Salfred	IB_QPT_XRC_TGT,
627255932Salfred	IB_QPT_MAX,
628219820Sjeff};
629219820Sjeff
630219820Sjeffenum ib_qp_create_flags {
631219820Sjeff	IB_QP_CREATE_IPOIB_UD_LSO		= 1 << 0,
632219820Sjeff	IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK	= 1 << 1,
633255932Salfred	IB_QP_CREATE_NETIF_QP			= 1 << 2,
634255932Salfred	/* reserve bits 26-31 for low level drivers' internal use */
635255932Salfred	IB_QP_CREATE_RESERVED_START		= 1 << 26,
636255932Salfred	IB_QP_CREATE_RESERVED_END		= 1 << 31,
637219820Sjeff};
638219820Sjeff
639255932Salfredenum ib_qpg_type {
640255932Salfred	IB_QPG_NONE	= 0,
641255932Salfred	IB_QPG_PARENT	= (1<<0),
642255932Salfred	IB_QPG_CHILD_RX = (1<<1),
643255932Salfred	IB_QPG_CHILD_TX = (1<<2)
644255932Salfred};
645255932Salfred
646255932Salfredstruct ib_qpg_init_attrib {
647255932Salfred	u32 tss_child_count;
648255932Salfred	u32 rss_child_count;
649255932Salfred};
650255932Salfred
651219820Sjeffstruct ib_qp_init_attr {
652219820Sjeff	void                  (*event_handler)(struct ib_event *, void *);
653219820Sjeff	void		       *qp_context;
654219820Sjeff	struct ib_cq	       *send_cq;
655219820Sjeff	struct ib_cq	       *recv_cq;
656219820Sjeff	struct ib_srq	       *srq;
657255932Salfred	struct ib_xrcd	       *xrcd;     /* XRC TGT QPs only */
658219820Sjeff	struct ib_qp_cap	cap;
659255932Salfred	union {
660255932Salfred		struct ib_qp *qpg_parent; /* see qpg_type */
661255932Salfred		struct ib_qpg_init_attrib parent_attrib;
662256116Sdim	} pp;
663219820Sjeff	enum ib_sig_type	sq_sig_type;
664219820Sjeff	enum ib_qp_type		qp_type;
665219820Sjeff	enum ib_qp_create_flags	create_flags;
666255932Salfred	enum ib_qpg_type	qpg_type;
667219820Sjeff	u8			port_num; /* special QP types only */
668219820Sjeff};
669219820Sjeff
670255932Salfredstruct ib_qp_open_attr {
671255932Salfred	void                  (*event_handler)(struct ib_event *, void *);
672255932Salfred	void		       *qp_context;
673255932Salfred	u32			qp_num;
674255932Salfred	enum ib_qp_type		qp_type;
675255932Salfred};
676255932Salfred
677219820Sjeffenum ib_rnr_timeout {
678219820Sjeff	IB_RNR_TIMER_655_36 =  0,
679219820Sjeff	IB_RNR_TIMER_000_01 =  1,
680219820Sjeff	IB_RNR_TIMER_000_02 =  2,
681219820Sjeff	IB_RNR_TIMER_000_03 =  3,
682219820Sjeff	IB_RNR_TIMER_000_04 =  4,
683219820Sjeff	IB_RNR_TIMER_000_06 =  5,
684219820Sjeff	IB_RNR_TIMER_000_08 =  6,
685219820Sjeff	IB_RNR_TIMER_000_12 =  7,
686219820Sjeff	IB_RNR_TIMER_000_16 =  8,
687219820Sjeff	IB_RNR_TIMER_000_24 =  9,
688219820Sjeff	IB_RNR_TIMER_000_32 = 10,
689219820Sjeff	IB_RNR_TIMER_000_48 = 11,
690219820Sjeff	IB_RNR_TIMER_000_64 = 12,
691219820Sjeff	IB_RNR_TIMER_000_96 = 13,
692219820Sjeff	IB_RNR_TIMER_001_28 = 14,
693219820Sjeff	IB_RNR_TIMER_001_92 = 15,
694219820Sjeff	IB_RNR_TIMER_002_56 = 16,
695219820Sjeff	IB_RNR_TIMER_003_84 = 17,
696219820Sjeff	IB_RNR_TIMER_005_12 = 18,
697219820Sjeff	IB_RNR_TIMER_007_68 = 19,
698219820Sjeff	IB_RNR_TIMER_010_24 = 20,
699219820Sjeff	IB_RNR_TIMER_015_36 = 21,
700219820Sjeff	IB_RNR_TIMER_020_48 = 22,
701219820Sjeff	IB_RNR_TIMER_030_72 = 23,
702219820Sjeff	IB_RNR_TIMER_040_96 = 24,
703219820Sjeff	IB_RNR_TIMER_061_44 = 25,
704219820Sjeff	IB_RNR_TIMER_081_92 = 26,
705219820Sjeff	IB_RNR_TIMER_122_88 = 27,
706219820Sjeff	IB_RNR_TIMER_163_84 = 28,
707219820Sjeff	IB_RNR_TIMER_245_76 = 29,
708219820Sjeff	IB_RNR_TIMER_327_68 = 30,
709219820Sjeff	IB_RNR_TIMER_491_52 = 31
710219820Sjeff};
711219820Sjeff
712219820Sjeffenum ib_qp_attr_mask {
713219820Sjeff	IB_QP_STATE			= 1,
714219820Sjeff	IB_QP_CUR_STATE			= (1<<1),
715219820Sjeff	IB_QP_EN_SQD_ASYNC_NOTIFY	= (1<<2),
716219820Sjeff	IB_QP_ACCESS_FLAGS		= (1<<3),
717219820Sjeff	IB_QP_PKEY_INDEX		= (1<<4),
718219820Sjeff	IB_QP_PORT			= (1<<5),
719219820Sjeff	IB_QP_QKEY			= (1<<6),
720219820Sjeff	IB_QP_AV			= (1<<7),
721219820Sjeff	IB_QP_PATH_MTU			= (1<<8),
722219820Sjeff	IB_QP_TIMEOUT			= (1<<9),
723219820Sjeff	IB_QP_RETRY_CNT			= (1<<10),
724219820Sjeff	IB_QP_RNR_RETRY			= (1<<11),
725219820Sjeff	IB_QP_RQ_PSN			= (1<<12),
726219820Sjeff	IB_QP_MAX_QP_RD_ATOMIC		= (1<<13),
727219820Sjeff	IB_QP_ALT_PATH			= (1<<14),
728219820Sjeff	IB_QP_MIN_RNR_TIMER		= (1<<15),
729219820Sjeff	IB_QP_SQ_PSN			= (1<<16),
730219820Sjeff	IB_QP_MAX_DEST_RD_ATOMIC	= (1<<17),
731219820Sjeff	IB_QP_PATH_MIG_STATE		= (1<<18),
732219820Sjeff	IB_QP_CAP			= (1<<19),
733255932Salfred	IB_QP_DEST_QPN			= (1<<20),
734255932Salfred	IB_QP_GROUP_RSS			= (1<<21)
735219820Sjeff};
736219820Sjeff
737219820Sjeffenum ib_qp_state {
738219820Sjeff	IB_QPS_RESET,
739219820Sjeff	IB_QPS_INIT,
740219820Sjeff	IB_QPS_RTR,
741219820Sjeff	IB_QPS_RTS,
742219820Sjeff	IB_QPS_SQD,
743219820Sjeff	IB_QPS_SQE,
744219820Sjeff	IB_QPS_ERR
745219820Sjeff};
746219820Sjeff
747219820Sjeffenum ib_mig_state {
748219820Sjeff	IB_MIG_MIGRATED,
749219820Sjeff	IB_MIG_REARM,
750219820Sjeff	IB_MIG_ARMED
751219820Sjeff};
752219820Sjeff
753219820Sjeffstruct ib_qp_attr {
754219820Sjeff	enum ib_qp_state	qp_state;
755219820Sjeff	enum ib_qp_state	cur_qp_state;
756219820Sjeff	enum ib_mtu		path_mtu;
757219820Sjeff	enum ib_mig_state	path_mig_state;
758219820Sjeff	u32			qkey;
759219820Sjeff	u32			rq_psn;
760219820Sjeff	u32			sq_psn;
761219820Sjeff	u32			dest_qp_num;
762219820Sjeff	int			qp_access_flags;
763219820Sjeff	struct ib_qp_cap	cap;
764219820Sjeff	struct ib_ah_attr	ah_attr;
765219820Sjeff	struct ib_ah_attr	alt_ah_attr;
766219820Sjeff	u16			pkey_index;
767219820Sjeff	u16			alt_pkey_index;
768219820Sjeff	u8			en_sqd_async_notify;
769219820Sjeff	u8			sq_draining;
770219820Sjeff	u8			max_rd_atomic;
771219820Sjeff	u8			max_dest_rd_atomic;
772219820Sjeff	u8			min_rnr_timer;
773219820Sjeff	u8			port_num;
774219820Sjeff	u8			timeout;
775219820Sjeff	u8			retry_cnt;
776219820Sjeff	u8			rnr_retry;
777219820Sjeff	u8			alt_port_num;
778219820Sjeff	u8			alt_timeout;
779219820Sjeff};
780219820Sjeff
781219820Sjeffenum ib_wr_opcode {
782219820Sjeff	IB_WR_RDMA_WRITE,
783219820Sjeff	IB_WR_RDMA_WRITE_WITH_IMM,
784219820Sjeff	IB_WR_SEND,
785219820Sjeff	IB_WR_SEND_WITH_IMM,
786219820Sjeff	IB_WR_RDMA_READ,
787219820Sjeff	IB_WR_ATOMIC_CMP_AND_SWP,
788219820Sjeff	IB_WR_ATOMIC_FETCH_AND_ADD,
789219820Sjeff	IB_WR_LSO,
790219820Sjeff	IB_WR_BIG_LSO,
791219820Sjeff	IB_WR_SEND_WITH_INV,
792219820Sjeff	IB_WR_RDMA_READ_WITH_INV,
793219820Sjeff	IB_WR_LOCAL_INV,
794219820Sjeff	IB_WR_FAST_REG_MR,
795219820Sjeff	IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
796219820Sjeff	IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
797219820Sjeff};
798219820Sjeff
799219820Sjeffenum ib_send_flags {
800219820Sjeff	IB_SEND_FENCE		= 1,
801219820Sjeff	IB_SEND_SIGNALED	= (1<<1),
802219820Sjeff	IB_SEND_SOLICITED	= (1<<2),
803219820Sjeff	IB_SEND_INLINE		= (1<<3),
804219820Sjeff	IB_SEND_IP_CSUM		= (1<<4)
805219820Sjeff};
806219820Sjeff
807255932Salfredenum ib_flow_types {
808255932Salfred	IB_FLOW_ETH = 0,
809255932Salfred	IB_FLOW_IB_UC = 1,
810255932Salfred	IB_FLOW_IB_MC_IPV4 = 2,
811255932Salfred	IB_FLOW_IB_MC_IPV6 = 3
812255932Salfred};
813255932Salfred
814255932Salfredenum {
815255932Salfred	IB_FLOW_L4_NONE = 0,
816255932Salfred	IB_FLOW_L4_OTHER = 3,
817255932Salfred	IB_FLOW_L4_UDP = 5,
818255932Salfred	IB_FLOW_L4_TCP = 6
819255932Salfred};
820255932Salfred
821219820Sjeffstruct ib_sge {
822219820Sjeff	u64	addr;
823219820Sjeff	u32	length;
824219820Sjeff	u32	lkey;
825219820Sjeff};
826219820Sjeff
827219820Sjeffstruct ib_fast_reg_page_list {
828219820Sjeff	struct ib_device       *device;
829219820Sjeff	u64		       *page_list;
830219820Sjeff	unsigned int		max_page_list_len;
831219820Sjeff};
832219820Sjeff
833219820Sjeffstruct ib_send_wr {
834219820Sjeff	struct ib_send_wr      *next;
835219820Sjeff	u64			wr_id;
836219820Sjeff	struct ib_sge	       *sg_list;
837219820Sjeff	int			num_sge;
838219820Sjeff	enum ib_wr_opcode	opcode;
839219820Sjeff	int			send_flags;
840219820Sjeff	union {
841219820Sjeff		__be32		imm_data;
842219820Sjeff		u32		invalidate_rkey;
843219820Sjeff	} ex;
844219820Sjeff	union {
845219820Sjeff		struct {
846219820Sjeff			u64	remote_addr;
847219820Sjeff			u32	rkey;
848219820Sjeff		} rdma;
849219820Sjeff		struct {
850219820Sjeff			u64	remote_addr;
851219820Sjeff			u64	compare_add;
852219820Sjeff			u64	swap;
853219820Sjeff			u64	compare_add_mask;
854219820Sjeff			u64	swap_mask;
855219820Sjeff			u32	rkey;
856219820Sjeff		} atomic;
857219820Sjeff		struct {
858219820Sjeff			struct ib_ah *ah;
859219820Sjeff			void   *header;
860219820Sjeff			int     hlen;
861219820Sjeff			int     mss;
862219820Sjeff			u32	remote_qpn;
863219820Sjeff			u32	remote_qkey;
864219820Sjeff			u16	pkey_index; /* valid for GSI only */
865219820Sjeff			u8	port_num;   /* valid for DR SMPs on switch only */
866219820Sjeff		} ud;
867219820Sjeff		struct {
868219820Sjeff			u64				iova_start;
869219820Sjeff			struct ib_fast_reg_page_list   *page_list;
870219820Sjeff			unsigned int			page_shift;
871219820Sjeff			unsigned int			page_list_len;
872219820Sjeff			u32				length;
873219820Sjeff			int				access_flags;
874219820Sjeff			u32				rkey;
875219820Sjeff		} fast_reg;
876219820Sjeff		struct {
877219820Sjeff			struct ib_unpacked_lrh	*lrh;
878219820Sjeff			u32			eth_type;
879219820Sjeff			u8			static_rate;
880219820Sjeff		} raw_ety;
881219820Sjeff	} wr;
882255932Salfred	u32			xrc_remote_srq_num;	/* XRC TGT QPs only */
883219820Sjeff};
884219820Sjeff
885219820Sjeffstruct ib_recv_wr {
886219820Sjeff	struct ib_recv_wr      *next;
887219820Sjeff	u64			wr_id;
888219820Sjeff	struct ib_sge	       *sg_list;
889219820Sjeff	int			num_sge;
890219820Sjeff};
891219820Sjeff
892219820Sjeffenum ib_access_flags {
893219820Sjeff	IB_ACCESS_LOCAL_WRITE	= 1,
894219820Sjeff	IB_ACCESS_REMOTE_WRITE	= (1<<1),
895219820Sjeff	IB_ACCESS_REMOTE_READ	= (1<<2),
896219820Sjeff	IB_ACCESS_REMOTE_ATOMIC	= (1<<3),
897255932Salfred	IB_ACCESS_MW_BIND	= (1<<4),
898255932Salfred	IB_ACCESS_ALLOCATE_MR	= (1<<5),
899255932Salfred	IB_ACCESS_SHARED_MR_USER_READ   = (1<<6),
900255932Salfred	IB_ACCESS_SHARED_MR_USER_WRITE  = (1<<7),
901255932Salfred	IB_ACCESS_SHARED_MR_GROUP_READ  = (1<<8),
902255932Salfred	IB_ACCESS_SHARED_MR_GROUP_WRITE = (1<<9),
903255932Salfred	IB_ACCESS_SHARED_MR_OTHER_READ  = (1<<10),
904255932Salfred	IB_ACCESS_SHARED_MR_OTHER_WRITE = (1<<11)
905255932Salfred
906219820Sjeff};
907219820Sjeff
908219820Sjeffstruct ib_phys_buf {
909219820Sjeff	u64      addr;
910219820Sjeff	u64      size;
911219820Sjeff};
912219820Sjeff
913219820Sjeffstruct ib_mr_attr {
914219820Sjeff	struct ib_pd	*pd;
915219820Sjeff	u64		device_virt_addr;
916219820Sjeff	u64		size;
917219820Sjeff	int		mr_access_flags;
918219820Sjeff	u32		lkey;
919219820Sjeff	u32		rkey;
920219820Sjeff};
921219820Sjeff
922219820Sjeffenum ib_mr_rereg_flags {
923219820Sjeff	IB_MR_REREG_TRANS	= 1,
924219820Sjeff	IB_MR_REREG_PD		= (1<<1),
925219820Sjeff	IB_MR_REREG_ACCESS	= (1<<2)
926219820Sjeff};
927219820Sjeff
928219820Sjeffstruct ib_mw_bind {
929219820Sjeff	struct ib_mr   *mr;
930219820Sjeff	u64		wr_id;
931219820Sjeff	u64		addr;
932219820Sjeff	u32		length;
933219820Sjeff	int		send_flags;
934219820Sjeff	int		mw_access_flags;
935219820Sjeff};
936219820Sjeff
937219820Sjeffstruct ib_fmr_attr {
938219820Sjeff	int	max_pages;
939219820Sjeff	int	max_maps;
940219820Sjeff	u8	page_shift;
941219820Sjeff};
942219820Sjeff
943219820Sjeffstruct ib_ucontext {
944219820Sjeff	struct ib_device       *device;
945219820Sjeff	struct list_head	pd_list;
946219820Sjeff	struct list_head	mr_list;
947219820Sjeff	struct list_head	mw_list;
948219820Sjeff	struct list_head	cq_list;
949219820Sjeff	struct list_head	qp_list;
950219820Sjeff	struct list_head	srq_list;
951219820Sjeff	struct list_head	ah_list;
952255932Salfred	struct list_head	xrcd_list;
953219820Sjeff	int			closing;
954219820Sjeff};
955219820Sjeff
956219820Sjeffstruct ib_uobject {
957219820Sjeff	u64			user_handle;	/* handle given to us by userspace */
958219820Sjeff	struct ib_ucontext     *context;	/* associated user context */
959219820Sjeff	void		       *object;		/* containing object */
960219820Sjeff	struct list_head	list;		/* link to context's list */
961219820Sjeff	int			id;		/* index into kernel idr */
962219820Sjeff	struct kref		ref;
963219820Sjeff	struct rw_semaphore	mutex;		/* protects .live */
964219820Sjeff	int			live;
965219820Sjeff};
966219820Sjeff
967219820Sjeffstruct ib_udata {
968219820Sjeff	void __user *inbuf;
969219820Sjeff	void __user *outbuf;
970219820Sjeff	size_t       inlen;
971219820Sjeff	size_t       outlen;
972219820Sjeff};
973219820Sjeff
974219820Sjeffstruct ib_uxrc_rcv_object {
975219820Sjeff	struct list_head	list;		/* link to context's list */
976219820Sjeff	u32			qp_num;
977219820Sjeff	u32			domain_handle;
978219820Sjeff};
979219820Sjeff
980219820Sjeffstruct ib_pd {
981219820Sjeff	struct ib_device       *device;
982219820Sjeff	struct ib_uobject      *uobject;
983219820Sjeff	atomic_t          	usecnt; /* count all resources */
984219820Sjeff};
985219820Sjeff
986219820Sjeffstruct ib_xrcd {
987219820Sjeff	struct ib_device       *device;
988219820Sjeff	struct ib_uobject      *uobject;
989255932Salfred	atomic_t		usecnt; /* count all exposed resources */
990219820Sjeff	struct inode	       *inode;
991219820Sjeff	struct rb_node		node;
992255932Salfred
993255932Salfred	struct mutex		tgt_qp_mutex;
994255932Salfred	struct list_head	tgt_qp_list;
995219820Sjeff};
996219820Sjeff
997219820Sjeffstruct ib_ah {
998219820Sjeff	struct ib_device	*device;
999219820Sjeff	struct ib_pd		*pd;
1000219820Sjeff	struct ib_uobject	*uobject;
1001219820Sjeff};
1002219820Sjeff
1003219820Sjefftypedef void (*ib_comp_handler)(struct ib_cq *cq, void *cq_context);
1004219820Sjeff
1005219820Sjeffstruct ib_cq {
1006219820Sjeff	struct ib_device       *device;
1007219820Sjeff	struct ib_uobject      *uobject;
1008219820Sjeff	ib_comp_handler   	comp_handler;
1009219820Sjeff	void                  (*event_handler)(struct ib_event *, void *);
1010219820Sjeff	void                   *cq_context;
1011219820Sjeff	int               	cqe;
1012219820Sjeff	atomic_t          	usecnt; /* count number of work queues */
1013219820Sjeff};
1014219820Sjeff
1015219820Sjeffstruct ib_srq {
1016219820Sjeff	struct ib_device       *device;
1017219820Sjeff	struct ib_pd	       *pd;
1018219820Sjeff	struct ib_uobject      *uobject;
1019219820Sjeff	void		      (*event_handler)(struct ib_event *, void *);
1020219820Sjeff	void		       *srq_context;
1021255932Salfred	enum ib_srq_type	srq_type;
1022219820Sjeff	atomic_t		usecnt;
1023255932Salfred
1024255932Salfred	union {
1025255932Salfred		struct {
1026255932Salfred			struct ib_xrcd *xrcd;
1027255932Salfred			struct ib_cq   *cq;
1028255932Salfred			u32		srq_num;
1029255932Salfred		} xrc;
1030255932Salfred	} ext;
1031219820Sjeff};
1032219820Sjeff
1033219820Sjeffstruct ib_qp {
1034219820Sjeff	struct ib_device       *device;
1035219820Sjeff	struct ib_pd	       *pd;
1036219820Sjeff	struct ib_cq	       *send_cq;
1037219820Sjeff	struct ib_cq	       *recv_cq;
1038219820Sjeff	struct ib_srq	       *srq;
1039255932Salfred	struct ib_xrcd	       *xrcd; /* XRC TGT QPs only */
1040255932Salfred	struct list_head	xrcd_list;
1041255932Salfred	atomic_t		usecnt; /* count times opened, mcast attaches */
1042255932Salfred	struct list_head	open_list;
1043255932Salfred	struct ib_qp           *real_qp;
1044219820Sjeff	struct ib_uobject      *uobject;
1045219820Sjeff	void                  (*event_handler)(struct ib_event *, void *);
1046219820Sjeff	void		       *qp_context;
1047219820Sjeff	u32			qp_num;
1048219820Sjeff	enum ib_qp_type		qp_type;
1049255932Salfred	enum ib_qpg_type	qpg_type;
1050219820Sjeff};
1051219820Sjeff
1052219820Sjeffstruct ib_mr {
1053219820Sjeff	struct ib_device  *device;
1054219820Sjeff	struct ib_pd	  *pd;
1055219820Sjeff	struct ib_uobject *uobject;
1056219820Sjeff	u32		   lkey;
1057219820Sjeff	u32		   rkey;
1058219820Sjeff	atomic_t	   usecnt; /* count number of MWs */
1059219820Sjeff};
1060219820Sjeff
1061219820Sjeffstruct ib_mw {
1062219820Sjeff	struct ib_device	*device;
1063219820Sjeff	struct ib_pd		*pd;
1064219820Sjeff	struct ib_uobject	*uobject;
1065219820Sjeff	u32			rkey;
1066219820Sjeff};
1067219820Sjeff
1068219820Sjeffstruct ib_fmr {
1069219820Sjeff	struct ib_device	*device;
1070219820Sjeff	struct ib_pd		*pd;
1071219820Sjeff	struct list_head	list;
1072219820Sjeff	u32			lkey;
1073219820Sjeff	u32			rkey;
1074219820Sjeff};
1075219820Sjeff
1076255932Salfredstruct ib_flow_spec {
1077255932Salfred	enum ib_flow_types type;
1078255932Salfred	union {
1079255932Salfred		struct {
1080255932Salfred			__be16 ethertype;
1081255932Salfred			__be16 vlan;
1082255932Salfred			u8 vlan_present;
1083255932Salfred			u8  mac[6];
1084255932Salfred			u8  port;
1085255932Salfred		} eth;
1086255932Salfred		struct {
1087255932Salfred			__be32 qpn;
1088255932Salfred		} ib_uc;
1089255932Salfred		struct {
1090255932Salfred			u8  mgid[16];
1091255932Salfred		} ib_mc;
1092255932Salfred	} l2_id;
1093255932Salfred	__be32 src_ip;
1094255932Salfred	__be32 dst_ip;
1095255932Salfred	__be16 src_port;
1096255932Salfred	__be16 dst_port;
1097255932Salfred	u8 l4_protocol;
1098255932Salfred	u8 block_mc_loopback;
1099255932Salfred	u8 rule_type;
1100255932Salfred};
1101255932Salfred
1102219820Sjeffstruct ib_mad;
1103219820Sjeffstruct ib_grh;
1104219820Sjeff
1105219820Sjeffenum ib_process_mad_flags {
1106219820Sjeff	IB_MAD_IGNORE_MKEY	= 1,
1107219820Sjeff	IB_MAD_IGNORE_BKEY	= 2,
1108219820Sjeff	IB_MAD_IGNORE_ALL	= IB_MAD_IGNORE_MKEY | IB_MAD_IGNORE_BKEY
1109219820Sjeff};
1110219820Sjeff
1111219820Sjeffenum ib_mad_result {
1112219820Sjeff	IB_MAD_RESULT_FAILURE  = 0,      /* (!SUCCESS is the important flag) */
1113219820Sjeff	IB_MAD_RESULT_SUCCESS  = 1 << 0, /* MAD was successfully processed   */
1114219820Sjeff	IB_MAD_RESULT_REPLY    = 1 << 1, /* Reply packet needs to be sent    */
1115219820Sjeff	IB_MAD_RESULT_CONSUMED = 1 << 2  /* Packet consumed: stop processing */
1116219820Sjeff};
1117219820Sjeff
1118219820Sjeff#define IB_DEVICE_NAME_MAX 64
1119219820Sjeff
1120219820Sjeffstruct ib_cache {
1121219820Sjeff	rwlock_t                lock;
1122219820Sjeff	struct ib_event_handler event_handler;
1123219820Sjeff	struct ib_pkey_cache  **pkey_cache;
1124219820Sjeff	struct ib_gid_cache   **gid_cache;
1125219820Sjeff	u8                     *lmc_cache;
1126219820Sjeff};
1127219820Sjeff
1128219820Sjeffstruct ib_dma_mapping_ops {
1129219820Sjeff	int		(*mapping_error)(struct ib_device *dev,
1130219820Sjeff					 u64 dma_addr);
1131219820Sjeff	u64		(*map_single)(struct ib_device *dev,
1132219820Sjeff				      void *ptr, size_t size,
1133219820Sjeff				      enum dma_data_direction direction);
1134219820Sjeff	void		(*unmap_single)(struct ib_device *dev,
1135219820Sjeff					u64 addr, size_t size,
1136219820Sjeff					enum dma_data_direction direction);
1137219820Sjeff	u64		(*map_page)(struct ib_device *dev,
1138219820Sjeff				    struct page *page, unsigned long offset,
1139219820Sjeff				    size_t size,
1140219820Sjeff				    enum dma_data_direction direction);
1141219820Sjeff	void		(*unmap_page)(struct ib_device *dev,
1142219820Sjeff				      u64 addr, size_t size,
1143219820Sjeff				      enum dma_data_direction direction);
1144219820Sjeff	int		(*map_sg)(struct ib_device *dev,
1145219820Sjeff				  struct scatterlist *sg, int nents,
1146219820Sjeff				  enum dma_data_direction direction);
1147219820Sjeff	void		(*unmap_sg)(struct ib_device *dev,
1148219820Sjeff				    struct scatterlist *sg, int nents,
1149219820Sjeff				    enum dma_data_direction direction);
1150219820Sjeff	u64		(*dma_address)(struct ib_device *dev,
1151219820Sjeff				       struct scatterlist *sg);
1152219820Sjeff	unsigned int	(*dma_len)(struct ib_device *dev,
1153219820Sjeff				   struct scatterlist *sg);
1154219820Sjeff	void		(*sync_single_for_cpu)(struct ib_device *dev,
1155219820Sjeff					       u64 dma_handle,
1156219820Sjeff					       size_t size,
1157219820Sjeff					       enum dma_data_direction dir);
1158219820Sjeff	void		(*sync_single_for_device)(struct ib_device *dev,
1159219820Sjeff						  u64 dma_handle,
1160219820Sjeff						  size_t size,
1161219820Sjeff						  enum dma_data_direction dir);
1162219820Sjeff	void		*(*alloc_coherent)(struct ib_device *dev,
1163219820Sjeff					   size_t size,
1164219820Sjeff					   u64 *dma_handle,
1165219820Sjeff					   gfp_t flag);
1166219820Sjeff	void		(*free_coherent)(struct ib_device *dev,
1167219820Sjeff					 size_t size, void *cpu_addr,
1168219820Sjeff					 u64 dma_handle);
1169219820Sjeff};
1170219820Sjeff
1171219820Sjeffstruct iw_cm_verbs;
1172219820Sjeff
1173219820Sjeffstruct ib_device {
1174219820Sjeff	struct device                *dma_device;
1175219820Sjeff
1176219820Sjeff	char                          name[IB_DEVICE_NAME_MAX];
1177219820Sjeff
1178219820Sjeff	struct list_head              event_handler_list;
1179219820Sjeff	spinlock_t                    event_handler_lock;
1180219820Sjeff
1181255932Salfred	spinlock_t                    client_data_lock;
1182219820Sjeff	struct list_head              core_list;
1183219820Sjeff	struct list_head              client_data_list;
1184219820Sjeff
1185219820Sjeff	struct ib_cache               cache;
1186219820Sjeff	int                          *pkey_tbl_len;
1187219820Sjeff	int                          *gid_tbl_len;
1188219820Sjeff
1189219820Sjeff	int			      num_comp_vectors;
1190219820Sjeff
1191219820Sjeff	struct iw_cm_verbs	     *iwcm;
1192219820Sjeff
1193219820Sjeff	int		           (*get_protocol_stats)(struct ib_device *device,
1194219820Sjeff							 union rdma_protocol_stats *stats);
1195219820Sjeff	int		           (*query_device)(struct ib_device *device,
1196219820Sjeff						   struct ib_device_attr *device_attr);
1197219820Sjeff	int		           (*query_port)(struct ib_device *device,
1198219820Sjeff						 u8 port_num,
1199219820Sjeff						 struct ib_port_attr *port_attr);
1200219820Sjeff	enum rdma_link_layer	   (*get_link_layer)(struct ib_device *device,
1201219820Sjeff						     u8 port_num);
1202219820Sjeff	int		           (*query_gid)(struct ib_device *device,
1203219820Sjeff						u8 port_num, int index,
1204219820Sjeff						union ib_gid *gid);
1205219820Sjeff	int		           (*query_pkey)(struct ib_device *device,
1206219820Sjeff						 u8 port_num, u16 index, u16 *pkey);
1207219820Sjeff	int		           (*modify_device)(struct ib_device *device,
1208219820Sjeff						    int device_modify_mask,
1209219820Sjeff						    struct ib_device_modify *device_modify);
1210219820Sjeff	int		           (*modify_port)(struct ib_device *device,
1211219820Sjeff						  u8 port_num, int port_modify_mask,
1212219820Sjeff						  struct ib_port_modify *port_modify);
1213219820Sjeff	struct ib_ucontext *       (*alloc_ucontext)(struct ib_device *device,
1214219820Sjeff						     struct ib_udata *udata);
1215219820Sjeff	int                        (*dealloc_ucontext)(struct ib_ucontext *context);
1216219820Sjeff	int                        (*mmap)(struct ib_ucontext *context,
1217219820Sjeff					   struct vm_area_struct *vma);
1218219820Sjeff	struct ib_pd *             (*alloc_pd)(struct ib_device *device,
1219219820Sjeff					       struct ib_ucontext *context,
1220219820Sjeff					       struct ib_udata *udata);
1221219820Sjeff	int                        (*dealloc_pd)(struct ib_pd *pd);
1222219820Sjeff	struct ib_ah *             (*create_ah)(struct ib_pd *pd,
1223219820Sjeff						struct ib_ah_attr *ah_attr);
1224219820Sjeff	int                        (*modify_ah)(struct ib_ah *ah,
1225219820Sjeff						struct ib_ah_attr *ah_attr);
1226219820Sjeff	int                        (*query_ah)(struct ib_ah *ah,
1227219820Sjeff					       struct ib_ah_attr *ah_attr);
1228219820Sjeff	int                        (*destroy_ah)(struct ib_ah *ah);
1229219820Sjeff	struct ib_srq *            (*create_srq)(struct ib_pd *pd,
1230219820Sjeff						 struct ib_srq_init_attr *srq_init_attr,
1231219820Sjeff						 struct ib_udata *udata);
1232219820Sjeff	int                        (*modify_srq)(struct ib_srq *srq,
1233219820Sjeff						 struct ib_srq_attr *srq_attr,
1234219820Sjeff						 enum ib_srq_attr_mask srq_attr_mask,
1235219820Sjeff						 struct ib_udata *udata);
1236219820Sjeff	int                        (*query_srq)(struct ib_srq *srq,
1237219820Sjeff						struct ib_srq_attr *srq_attr);
1238219820Sjeff	int                        (*destroy_srq)(struct ib_srq *srq);
1239219820Sjeff	int                        (*post_srq_recv)(struct ib_srq *srq,
1240219820Sjeff						    struct ib_recv_wr *recv_wr,
1241219820Sjeff						    struct ib_recv_wr **bad_recv_wr);
1242219820Sjeff	struct ib_qp *             (*create_qp)(struct ib_pd *pd,
1243219820Sjeff						struct ib_qp_init_attr *qp_init_attr,
1244219820Sjeff						struct ib_udata *udata);
1245219820Sjeff	int                        (*modify_qp)(struct ib_qp *qp,
1246219820Sjeff						struct ib_qp_attr *qp_attr,
1247219820Sjeff						int qp_attr_mask,
1248219820Sjeff						struct ib_udata *udata);
1249219820Sjeff	int                        (*query_qp)(struct ib_qp *qp,
1250219820Sjeff					       struct ib_qp_attr *qp_attr,
1251219820Sjeff					       int qp_attr_mask,
1252219820Sjeff					       struct ib_qp_init_attr *qp_init_attr);
1253219820Sjeff	int                        (*destroy_qp)(struct ib_qp *qp);
1254219820Sjeff	int                        (*post_send)(struct ib_qp *qp,
1255219820Sjeff						struct ib_send_wr *send_wr,
1256219820Sjeff						struct ib_send_wr **bad_send_wr);
1257219820Sjeff	int                        (*post_recv)(struct ib_qp *qp,
1258219820Sjeff						struct ib_recv_wr *recv_wr,
1259219820Sjeff						struct ib_recv_wr **bad_recv_wr);
1260219820Sjeff	struct ib_cq *             (*create_cq)(struct ib_device *device, int cqe,
1261219820Sjeff						int comp_vector,
1262219820Sjeff						struct ib_ucontext *context,
1263219820Sjeff						struct ib_udata *udata);
1264219820Sjeff	int                        (*modify_cq)(struct ib_cq *cq, u16 cq_count,
1265219820Sjeff						u16 cq_period);
1266219820Sjeff	int                        (*destroy_cq)(struct ib_cq *cq);
1267219820Sjeff	int                        (*resize_cq)(struct ib_cq *cq, int cqe,
1268219820Sjeff						struct ib_udata *udata);
1269219820Sjeff	int                        (*poll_cq)(struct ib_cq *cq, int num_entries,
1270219820Sjeff					      struct ib_wc *wc);
1271219820Sjeff	int                        (*peek_cq)(struct ib_cq *cq, int wc_cnt);
1272219820Sjeff	int                        (*req_notify_cq)(struct ib_cq *cq,
1273219820Sjeff						    enum ib_cq_notify_flags flags);
1274219820Sjeff	int                        (*req_ncomp_notif)(struct ib_cq *cq,
1275219820Sjeff						      int wc_cnt);
1276219820Sjeff	struct ib_mr *             (*get_dma_mr)(struct ib_pd *pd,
1277219820Sjeff						 int mr_access_flags);
1278219820Sjeff	struct ib_mr *             (*reg_phys_mr)(struct ib_pd *pd,
1279219820Sjeff						  struct ib_phys_buf *phys_buf_array,
1280219820Sjeff						  int num_phys_buf,
1281219820Sjeff						  int mr_access_flags,
1282219820Sjeff						  u64 *iova_start);
1283219820Sjeff	struct ib_mr *             (*reg_user_mr)(struct ib_pd *pd,
1284219820Sjeff						  u64 start, u64 length,
1285219820Sjeff						  u64 virt_addr,
1286219820Sjeff						  int mr_access_flags,
1287255932Salfred						  struct ib_udata *udata,
1288255932Salfred							int mr_id);
1289219820Sjeff	int                        (*query_mr)(struct ib_mr *mr,
1290219820Sjeff					       struct ib_mr_attr *mr_attr);
1291219820Sjeff	int                        (*dereg_mr)(struct ib_mr *mr);
1292219820Sjeff	struct ib_mr *		   (*alloc_fast_reg_mr)(struct ib_pd *pd,
1293219820Sjeff					       int max_page_list_len);
1294219820Sjeff	struct ib_fast_reg_page_list * (*alloc_fast_reg_page_list)(struct ib_device *device,
1295219820Sjeff								   int page_list_len);
1296219820Sjeff	void			   (*free_fast_reg_page_list)(struct ib_fast_reg_page_list *page_list);
1297219820Sjeff	int                        (*rereg_phys_mr)(struct ib_mr *mr,
1298219820Sjeff						    int mr_rereg_mask,
1299219820Sjeff						    struct ib_pd *pd,
1300219820Sjeff						    struct ib_phys_buf *phys_buf_array,
1301219820Sjeff						    int num_phys_buf,
1302219820Sjeff						    int mr_access_flags,
1303219820Sjeff						    u64 *iova_start);
1304219820Sjeff	struct ib_mw *             (*alloc_mw)(struct ib_pd *pd);
1305219820Sjeff	int                        (*bind_mw)(struct ib_qp *qp,
1306219820Sjeff					      struct ib_mw *mw,
1307219820Sjeff					      struct ib_mw_bind *mw_bind);
1308219820Sjeff	int                        (*dealloc_mw)(struct ib_mw *mw);
1309219820Sjeff	struct ib_fmr *	           (*alloc_fmr)(struct ib_pd *pd,
1310219820Sjeff						int mr_access_flags,
1311219820Sjeff						struct ib_fmr_attr *fmr_attr);
1312219820Sjeff	int		           (*map_phys_fmr)(struct ib_fmr *fmr,
1313219820Sjeff						   u64 *page_list, int list_len,
1314219820Sjeff						   u64 iova);
1315219820Sjeff	int		           (*unmap_fmr)(struct list_head *fmr_list);
1316219820Sjeff	int		           (*dealloc_fmr)(struct ib_fmr *fmr);
1317219820Sjeff	int                        (*attach_mcast)(struct ib_qp *qp,
1318219820Sjeff						   union ib_gid *gid,
1319219820Sjeff						   u16 lid);
1320219820Sjeff	int                        (*detach_mcast)(struct ib_qp *qp,
1321219820Sjeff						   union ib_gid *gid,
1322219820Sjeff						   u16 lid);
1323219820Sjeff	int                        (*process_mad)(struct ib_device *device,
1324219820Sjeff						  int process_mad_flags,
1325219820Sjeff						  u8 port_num,
1326219820Sjeff						  struct ib_wc *in_wc,
1327219820Sjeff						  struct ib_grh *in_grh,
1328219820Sjeff						  struct ib_mad *in_mad,
1329219820Sjeff						  struct ib_mad *out_mad);
1330219820Sjeff	struct ib_srq *		   (*create_xrc_srq)(struct ib_pd *pd,
1331219820Sjeff						     struct ib_cq *xrc_cq,
1332219820Sjeff						     struct ib_xrcd *xrcd,
1333219820Sjeff						     struct ib_srq_init_attr *srq_init_attr,
1334219820Sjeff						     struct ib_udata *udata);
1335219820Sjeff	struct ib_xrcd *	   (*alloc_xrcd)(struct ib_device *device,
1336255932Salfred						 struct ib_ucontext *ucontext,
1337219820Sjeff						 struct ib_udata *udata);
1338219820Sjeff	int			   (*dealloc_xrcd)(struct ib_xrcd *xrcd);
1339219820Sjeff	int			   (*create_xrc_rcv_qp)(struct ib_qp_init_attr *init_attr,
1340219820Sjeff							u32 *qp_num);
1341219820Sjeff	int			   (*modify_xrc_rcv_qp)(struct ib_xrcd *xrcd,
1342219820Sjeff							u32 qp_num,
1343219820Sjeff							struct ib_qp_attr *attr,
1344219820Sjeff							int attr_mask);
1345219820Sjeff	int			   (*query_xrc_rcv_qp)(struct ib_xrcd *xrcd,
1346219820Sjeff						       u32 qp_num,
1347219820Sjeff						       struct ib_qp_attr *attr,
1348219820Sjeff						       int attr_mask,
1349219820Sjeff						       struct ib_qp_init_attr *init_attr);
1350219820Sjeff	int 			   (*reg_xrc_rcv_qp)(struct ib_xrcd *xrcd,
1351219820Sjeff						     void *context,
1352219820Sjeff						     u32 qp_num);
1353219820Sjeff	int 			   (*unreg_xrc_rcv_qp)(struct ib_xrcd *xrcd,
1354219820Sjeff						       void *context,
1355219820Sjeff						       u32 qp_num);
1356255932Salfred	int                        (*attach_flow)(struct ib_qp *qp,
1357255932Salfred						  struct ib_flow_spec *spec,
1358255932Salfred						  int priority);
1359255932Salfred	int                        (*detach_flow)(struct ib_qp *qp,
1360255932Salfred						  struct ib_flow_spec *spec,
1361255932Salfred						  int priority);
1362219820Sjeff
1363255932Salfred	unsigned long		   (*get_unmapped_area)(struct file *file,
1364255932Salfred					unsigned long addr,
1365255932Salfred					unsigned long len, unsigned long pgoff,
1366255932Salfred					unsigned long flags);
1367219820Sjeff	struct ib_dma_mapping_ops   *dma_ops;
1368219820Sjeff
1369219820Sjeff	struct module               *owner;
1370219820Sjeff	struct device                dev;
1371219820Sjeff	struct kobject               *ports_parent;
1372219820Sjeff	struct list_head             port_list;
1373219820Sjeff
1374219820Sjeff	enum {
1375219820Sjeff		IB_DEV_UNINITIALIZED,
1376219820Sjeff		IB_DEV_REGISTERED,
1377219820Sjeff		IB_DEV_UNREGISTERED
1378219820Sjeff	}                            reg_state;
1379219820Sjeff
1380255932Salfred	int			     uverbs_abi_ver;
1381219820Sjeff	u64			     uverbs_cmd_mask;
1382219820Sjeff
1383219820Sjeff	char			     node_desc[64];
1384219820Sjeff	__be64			     node_guid;
1385219820Sjeff	u32			     local_dma_lkey;
1386219820Sjeff	u8                           node_type;
1387219820Sjeff	u8                           phys_port_cnt;
1388219820Sjeff	struct rb_root		     ib_uverbs_xrcd_table;
1389219820Sjeff	struct mutex		     xrcd_table_mutex;
1390219820Sjeff};
1391219820Sjeff
1392219820Sjeffstruct ib_client {
1393219820Sjeff	char  *name;
1394219820Sjeff	void (*add)   (struct ib_device *);
1395219820Sjeff	void (*remove)(struct ib_device *);
1396219820Sjeff
1397219820Sjeff	struct list_head list;
1398219820Sjeff};
1399219820Sjeff
1400219820Sjeffstruct ib_device *ib_alloc_device(size_t size);
1401219820Sjeffvoid ib_dealloc_device(struct ib_device *device);
1402219820Sjeff
1403255932Salfredint ib_register_device(struct ib_device *device,
1404255932Salfred		       int (*port_callback)(struct ib_device *,
1405255932Salfred					    u8, struct kobject *));
1406219820Sjeffvoid ib_unregister_device(struct ib_device *device);
1407219820Sjeff
1408219820Sjeffint ib_register_client   (struct ib_client *client);
1409219820Sjeffvoid ib_unregister_client(struct ib_client *client);
1410219820Sjeff
1411219820Sjeffvoid *ib_get_client_data(struct ib_device *device, struct ib_client *client);
1412219820Sjeffvoid  ib_set_client_data(struct ib_device *device, struct ib_client *client,
1413219820Sjeff			 void *data);
1414219820Sjeff
1415219820Sjeffstatic inline int ib_copy_from_udata(void *dest, struct ib_udata *udata, size_t len)
1416219820Sjeff{
1417219820Sjeff	return copy_from_user(dest, udata->inbuf, len) ? -EFAULT : 0;
1418219820Sjeff}
1419219820Sjeff
1420219820Sjeffstatic inline int ib_copy_to_udata(struct ib_udata *udata, void *src, size_t len)
1421219820Sjeff{
1422219820Sjeff	return copy_to_user(udata->outbuf, src, len) ? -EFAULT : 0;
1423219820Sjeff}
1424219820Sjeff
1425219820Sjeff/**
1426219820Sjeff * ib_modify_qp_is_ok - Check that the supplied attribute mask
1427219820Sjeff * contains all required attributes and no attributes not allowed for
1428219820Sjeff * the given QP state transition.
1429219820Sjeff * @cur_state: Current QP state
1430219820Sjeff * @next_state: Next QP state
1431219820Sjeff * @type: QP type
1432219820Sjeff * @mask: Mask of supplied QP attributes
1433219820Sjeff *
1434219820Sjeff * This function is a helper function that a low-level driver's
1435219820Sjeff * modify_qp method can use to validate the consumer's input.  It
1436219820Sjeff * checks that cur_state and next_state are valid QP states, that a
1437219820Sjeff * transition from cur_state to next_state is allowed by the IB spec,
1438219820Sjeff * and that the attribute mask supplied is allowed for the transition.
1439219820Sjeff */
1440219820Sjeffint ib_modify_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state next_state,
1441219820Sjeff		       enum ib_qp_type type, enum ib_qp_attr_mask mask);
1442219820Sjeff
1443219820Sjeffint ib_register_event_handler  (struct ib_event_handler *event_handler);
1444219820Sjeffint ib_unregister_event_handler(struct ib_event_handler *event_handler);
1445219820Sjeffvoid ib_dispatch_event(struct ib_event *event);
1446219820Sjeff
1447219820Sjeffint ib_query_device(struct ib_device *device,
1448219820Sjeff		    struct ib_device_attr *device_attr);
1449219820Sjeff
1450219820Sjeffint ib_query_port(struct ib_device *device,
1451219820Sjeff		  u8 port_num, struct ib_port_attr *port_attr);
1452219820Sjeff
1453219820Sjeffenum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
1454219820Sjeff					       u8 port_num);
1455219820Sjeff
1456219820Sjeffint ib_query_gid(struct ib_device *device,
1457219820Sjeff		 u8 port_num, int index, union ib_gid *gid);
1458219820Sjeff
1459219820Sjeffint ib_query_pkey(struct ib_device *device,
1460219820Sjeff		  u8 port_num, u16 index, u16 *pkey);
1461219820Sjeff
1462219820Sjeffint ib_modify_device(struct ib_device *device,
1463219820Sjeff		     int device_modify_mask,
1464219820Sjeff		     struct ib_device_modify *device_modify);
1465219820Sjeff
1466219820Sjeffint ib_modify_port(struct ib_device *device,
1467219820Sjeff		   u8 port_num, int port_modify_mask,
1468219820Sjeff		   struct ib_port_modify *port_modify);
1469219820Sjeff
1470219820Sjeffint ib_find_gid(struct ib_device *device, union ib_gid *gid,
1471219820Sjeff		u8 *port_num, u16 *index);
1472219820Sjeff
1473219820Sjeffint ib_find_pkey(struct ib_device *device,
1474219820Sjeff		 u8 port_num, u16 pkey, u16 *index);
1475219820Sjeff
1476219820Sjeff/**
1477219820Sjeff * ib_alloc_pd - Allocates an unused protection domain.
1478219820Sjeff * @device: The device on which to allocate the protection domain.
1479219820Sjeff *
1480219820Sjeff * A protection domain object provides an association between QPs, shared
1481219820Sjeff * receive queues, address handles, memory regions, and memory windows.
1482219820Sjeff */
1483219820Sjeffstruct ib_pd *ib_alloc_pd(struct ib_device *device);
1484219820Sjeff
1485219820Sjeff/**
1486219820Sjeff * ib_dealloc_pd - Deallocates a protection domain.
1487219820Sjeff * @pd: The protection domain to deallocate.
1488219820Sjeff */
1489219820Sjeffint ib_dealloc_pd(struct ib_pd *pd);
1490219820Sjeff
1491219820Sjeff/**
1492219820Sjeff * ib_create_ah - Creates an address handle for the given address vector.
1493219820Sjeff * @pd: The protection domain associated with the address handle.
1494219820Sjeff * @ah_attr: The attributes of the address vector.
1495219820Sjeff *
1496219820Sjeff * The address handle is used to reference a local or global destination
1497219820Sjeff * in all UD QP post sends.
1498219820Sjeff */
1499219820Sjeffstruct ib_ah *ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
1500219820Sjeff
1501219820Sjeff/**
1502219820Sjeff * ib_init_ah_from_wc - Initializes address handle attributes from a
1503219820Sjeff *   work completion.
1504219820Sjeff * @device: Device on which the received message arrived.
1505219820Sjeff * @port_num: Port on which the received message arrived.
1506219820Sjeff * @wc: Work completion associated with the received message.
1507219820Sjeff * @grh: References the received global route header.  This parameter is
1508219820Sjeff *   ignored unless the work completion indicates that the GRH is valid.
1509219820Sjeff * @ah_attr: Returned attributes that can be used when creating an address
1510219820Sjeff *   handle for replying to the message.
1511219820Sjeff */
1512219820Sjeffint ib_init_ah_from_wc(struct ib_device *device, u8 port_num, struct ib_wc *wc,
1513219820Sjeff		       struct ib_grh *grh, struct ib_ah_attr *ah_attr);
1514219820Sjeff
1515219820Sjeff/**
1516219820Sjeff * ib_create_ah_from_wc - Creates an address handle associated with the
1517219820Sjeff *   sender of the specified work completion.
1518219820Sjeff * @pd: The protection domain associated with the address handle.
1519219820Sjeff * @wc: Work completion information associated with a received message.
1520219820Sjeff * @grh: References the received global route header.  This parameter is
1521219820Sjeff *   ignored unless the work completion indicates that the GRH is valid.
1522219820Sjeff * @port_num: The outbound port number to associate with the address.
1523219820Sjeff *
1524219820Sjeff * The address handle is used to reference a local or global destination
1525219820Sjeff * in all UD QP post sends.
1526219820Sjeff */
1527219820Sjeffstruct ib_ah *ib_create_ah_from_wc(struct ib_pd *pd, struct ib_wc *wc,
1528219820Sjeff				   struct ib_grh *grh, u8 port_num);
1529219820Sjeff
1530219820Sjeff/**
1531219820Sjeff * ib_modify_ah - Modifies the address vector associated with an address
1532219820Sjeff *   handle.
1533219820Sjeff * @ah: The address handle to modify.
1534219820Sjeff * @ah_attr: The new address vector attributes to associate with the
1535219820Sjeff *   address handle.
1536219820Sjeff */
1537219820Sjeffint ib_modify_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1538219820Sjeff
1539219820Sjeff/**
1540219820Sjeff * ib_query_ah - Queries the address vector associated with an address
1541219820Sjeff *   handle.
1542219820Sjeff * @ah: The address handle to query.
1543219820Sjeff * @ah_attr: The address vector attributes associated with the address
1544219820Sjeff *   handle.
1545219820Sjeff */
1546219820Sjeffint ib_query_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr);
1547219820Sjeff
1548219820Sjeff/**
1549219820Sjeff * ib_destroy_ah - Destroys an address handle.
1550219820Sjeff * @ah: The address handle to destroy.
1551219820Sjeff */
1552219820Sjeffint ib_destroy_ah(struct ib_ah *ah);
1553219820Sjeff
1554219820Sjeff/**
1555219820Sjeff * ib_create_xrc_srq - Creates an XRC SRQ associated with the specified
1556219820Sjeff *   protection domain, cq, and xrc domain.
1557219820Sjeff * @pd: The protection domain associated with the SRQ.
1558219820Sjeff * @xrc_cq: The cq to be associated with the XRC SRQ.
1559219820Sjeff * @xrcd: The XRC domain to be associated with the XRC SRQ.
1560219820Sjeff * @srq_init_attr: A list of initial attributes required to create the
1561219820Sjeff *   XRC SRQ.  If XRC SRQ creation succeeds, then the attributes are updated
1562219820Sjeff *   to the actual capabilities of the created XRC SRQ.
1563219820Sjeff *
1564219820Sjeff * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1565219820Sjeff * requested size of the XRC SRQ, and set to the actual values allocated
1566219820Sjeff * on return.  If ib_create_xrc_srq() succeeds, then max_wr and max_sge
1567219820Sjeff * will always be at least as large as the requested values.
1568219820Sjeff */
1569219820Sjeffstruct ib_srq *ib_create_xrc_srq(struct ib_pd *pd,
1570219820Sjeff				 struct ib_cq *xrc_cq,
1571219820Sjeff				 struct ib_xrcd *xrcd,
1572219820Sjeff				 struct ib_srq_init_attr *srq_init_attr);
1573219820Sjeff
1574219820Sjeff/**
1575255932Salfred * ib_create_srq - Creates a SRQ associated with the specified protection
1576255932Salfred *   domain.
1577219820Sjeff * @pd: The protection domain associated with the SRQ.
1578219820Sjeff * @srq_init_attr: A list of initial attributes required to create the
1579219820Sjeff *   SRQ.  If SRQ creation succeeds, then the attributes are updated to
1580219820Sjeff *   the actual capabilities of the created SRQ.
1581219820Sjeff *
1582219820Sjeff * srq_attr->max_wr and srq_attr->max_sge are read the determine the
1583219820Sjeff * requested size of the SRQ, and set to the actual values allocated
1584219820Sjeff * on return.  If ib_create_srq() succeeds, then max_wr and max_sge
1585219820Sjeff * will always be at least as large as the requested values.
1586219820Sjeff */
1587219820Sjeffstruct ib_srq *ib_create_srq(struct ib_pd *pd,
1588219820Sjeff			     struct ib_srq_init_attr *srq_init_attr);
1589219820Sjeff
1590219820Sjeff/**
1591219820Sjeff * ib_modify_srq - Modifies the attributes for the specified SRQ.
1592219820Sjeff * @srq: The SRQ to modify.
1593219820Sjeff * @srq_attr: On input, specifies the SRQ attributes to modify.  On output,
1594219820Sjeff *   the current values of selected SRQ attributes are returned.
1595219820Sjeff * @srq_attr_mask: A bit-mask used to specify which attributes of the SRQ
1596219820Sjeff *   are being modified.
1597219820Sjeff *
1598219820Sjeff * The mask may contain IB_SRQ_MAX_WR to resize the SRQ and/or
1599219820Sjeff * IB_SRQ_LIMIT to set the SRQ's limit and request notification when
1600219820Sjeff * the number of receives queued drops below the limit.
1601219820Sjeff */
1602219820Sjeffint ib_modify_srq(struct ib_srq *srq,
1603219820Sjeff		  struct ib_srq_attr *srq_attr,
1604219820Sjeff		  enum ib_srq_attr_mask srq_attr_mask);
1605219820Sjeff
1606219820Sjeff/**
1607219820Sjeff * ib_query_srq - Returns the attribute list and current values for the
1608219820Sjeff *   specified SRQ.
1609219820Sjeff * @srq: The SRQ to query.
1610219820Sjeff * @srq_attr: The attributes of the specified SRQ.
1611219820Sjeff */
1612219820Sjeffint ib_query_srq(struct ib_srq *srq,
1613219820Sjeff		 struct ib_srq_attr *srq_attr);
1614219820Sjeff
1615219820Sjeff/**
1616219820Sjeff * ib_destroy_srq - Destroys the specified SRQ.
1617219820Sjeff * @srq: The SRQ to destroy.
1618219820Sjeff */
1619219820Sjeffint ib_destroy_srq(struct ib_srq *srq);
1620219820Sjeff
1621219820Sjeff/**
1622219820Sjeff * ib_post_srq_recv - Posts a list of work requests to the specified SRQ.
1623219820Sjeff * @srq: The SRQ to post the work request on.
1624219820Sjeff * @recv_wr: A list of work requests to post on the receive queue.
1625219820Sjeff * @bad_recv_wr: On an immediate failure, this parameter will reference
1626219820Sjeff *   the work request that failed to be posted on the QP.
1627219820Sjeff */
1628219820Sjeffstatic inline int ib_post_srq_recv(struct ib_srq *srq,
1629219820Sjeff				   struct ib_recv_wr *recv_wr,
1630219820Sjeff				   struct ib_recv_wr **bad_recv_wr)
1631219820Sjeff{
1632219820Sjeff	return srq->device->post_srq_recv(srq, recv_wr, bad_recv_wr);
1633219820Sjeff}
1634219820Sjeff
1635219820Sjeff/**
1636219820Sjeff * ib_create_qp - Creates a QP associated with the specified protection
1637219820Sjeff *   domain.
1638219820Sjeff * @pd: The protection domain associated with the QP.
1639219820Sjeff * @qp_init_attr: A list of initial attributes required to create the
1640219820Sjeff *   QP.  If QP creation succeeds, then the attributes are updated to
1641219820Sjeff *   the actual capabilities of the created QP.
1642219820Sjeff */
1643219820Sjeffstruct ib_qp *ib_create_qp(struct ib_pd *pd,
1644219820Sjeff			   struct ib_qp_init_attr *qp_init_attr);
1645219820Sjeff
1646219820Sjeff/**
1647219820Sjeff * ib_modify_qp - Modifies the attributes for the specified QP and then
1648219820Sjeff *   transitions the QP to the given state.
1649219820Sjeff * @qp: The QP to modify.
1650219820Sjeff * @qp_attr: On input, specifies the QP attributes to modify.  On output,
1651219820Sjeff *   the current values of selected QP attributes are returned.
1652219820Sjeff * @qp_attr_mask: A bit-mask used to specify which attributes of the QP
1653219820Sjeff *   are being modified.
1654219820Sjeff */
1655219820Sjeffint ib_modify_qp(struct ib_qp *qp,
1656219820Sjeff		 struct ib_qp_attr *qp_attr,
1657219820Sjeff		 int qp_attr_mask);
1658219820Sjeff
1659219820Sjeff/**
1660219820Sjeff * ib_query_qp - Returns the attribute list and current values for the
1661219820Sjeff *   specified QP.
1662219820Sjeff * @qp: The QP to query.
1663219820Sjeff * @qp_attr: The attributes of the specified QP.
1664219820Sjeff * @qp_attr_mask: A bit-mask used to select specific attributes to query.
1665219820Sjeff * @qp_init_attr: Additional attributes of the selected QP.
1666219820Sjeff *
1667219820Sjeff * The qp_attr_mask may be used to limit the query to gathering only the
1668219820Sjeff * selected attributes.
1669219820Sjeff */
1670219820Sjeffint ib_query_qp(struct ib_qp *qp,
1671219820Sjeff		struct ib_qp_attr *qp_attr,
1672219820Sjeff		int qp_attr_mask,
1673219820Sjeff		struct ib_qp_init_attr *qp_init_attr);
1674219820Sjeff
1675219820Sjeff/**
1676219820Sjeff * ib_destroy_qp - Destroys the specified QP.
1677219820Sjeff * @qp: The QP to destroy.
1678219820Sjeff */
1679219820Sjeffint ib_destroy_qp(struct ib_qp *qp);
1680219820Sjeff
1681219820Sjeff/**
1682255932Salfred * ib_open_qp - Obtain a reference to an existing sharable QP.
1683255932Salfred * @xrcd - XRC domain
1684255932Salfred * @qp_open_attr: Attributes identifying the QP to open.
1685255932Salfred *
1686255932Salfred * Returns a reference to a sharable QP.
1687255932Salfred */
1688255932Salfredstruct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
1689255932Salfred			 struct ib_qp_open_attr *qp_open_attr);
1690255932Salfred
1691255932Salfred/**
1692255932Salfred * ib_close_qp - Release an external reference to a QP.
1693255932Salfred * @qp: The QP handle to release
1694255932Salfred *
1695255932Salfred * The opened QP handle is released by the caller.  The underlying
1696255932Salfred * shared QP is not destroyed until all internal references are released.
1697255932Salfred */
1698255932Salfredint ib_close_qp(struct ib_qp *qp);
1699255932Salfred
1700255932Salfred/**
1701219820Sjeff * ib_post_send - Posts a list of work requests to the send queue of
1702219820Sjeff *   the specified QP.
1703219820Sjeff * @qp: The QP to post the work request on.
1704219820Sjeff * @send_wr: A list of work requests to post on the send queue.
1705219820Sjeff * @bad_send_wr: On an immediate failure, this parameter will reference
1706219820Sjeff *   the work request that failed to be posted on the QP.
1707255932Salfred *
1708255932Salfred * While IBA Vol. 1 section 11.4.1.1 specifies that if an immediate
1709255932Salfred * error is returned, the QP state shall not be affected,
1710255932Salfred * ib_post_send() will return an immediate error after queueing any
1711255932Salfred * earlier work requests in the list.
1712219820Sjeff */
1713219820Sjeffstatic inline int ib_post_send(struct ib_qp *qp,
1714219820Sjeff			       struct ib_send_wr *send_wr,
1715219820Sjeff			       struct ib_send_wr **bad_send_wr)
1716219820Sjeff{
1717219820Sjeff	return qp->device->post_send(qp, send_wr, bad_send_wr);
1718219820Sjeff}
1719219820Sjeff
1720219820Sjeff/**
1721219820Sjeff * ib_post_recv - Posts a list of work requests to the receive queue of
1722219820Sjeff *   the specified QP.
1723219820Sjeff * @qp: The QP to post the work request on.
1724219820Sjeff * @recv_wr: A list of work requests to post on the receive queue.
1725219820Sjeff * @bad_recv_wr: On an immediate failure, this parameter will reference
1726219820Sjeff *   the work request that failed to be posted on the QP.
1727219820Sjeff */
1728219820Sjeffstatic inline int ib_post_recv(struct ib_qp *qp,
1729219820Sjeff			       struct ib_recv_wr *recv_wr,
1730219820Sjeff			       struct ib_recv_wr **bad_recv_wr)
1731219820Sjeff{
1732219820Sjeff	return qp->device->post_recv(qp, recv_wr, bad_recv_wr);
1733219820Sjeff}
1734219820Sjeff
1735219820Sjeff/*
1736219820Sjeff * IB_CQ_VECTOR_LEAST_ATTACHED: The constant specifies that
1737219820Sjeff *	the CQ will be attached to the completion vector that has
1738219820Sjeff *	the least number of CQs already attached to it.
1739219820Sjeff */
1740219820Sjeff#define IB_CQ_VECTOR_LEAST_ATTACHED	0xffffffff
1741219820Sjeff
1742219820Sjeff/**
1743219820Sjeff * ib_create_cq - Creates a CQ on the specified device.
1744219820Sjeff * @device: The device on which to create the CQ.
1745219820Sjeff * @comp_handler: A user-specified callback that is invoked when a
1746219820Sjeff *   completion event occurs on the CQ.
1747219820Sjeff * @event_handler: A user-specified callback that is invoked when an
1748219820Sjeff *   asynchronous event not associated with a completion occurs on the CQ.
1749219820Sjeff * @cq_context: Context associated with the CQ returned to the user via
1750219820Sjeff *   the associated completion and event handlers.
1751219820Sjeff * @cqe: The minimum size of the CQ.
1752219820Sjeff * @comp_vector - Completion vector used to signal completion events.
1753255932Salfred *     Must be >= 0 and < context->num_comp_vectors.
1754219820Sjeff *
1755219820Sjeff * Users can examine the cq structure to determine the actual CQ size.
1756219820Sjeff */
1757219820Sjeffstruct ib_cq *ib_create_cq(struct ib_device *device,
1758219820Sjeff			   ib_comp_handler comp_handler,
1759219820Sjeff			   void (*event_handler)(struct ib_event *, void *),
1760219820Sjeff			   void *cq_context, int cqe, int comp_vector);
1761219820Sjeff
1762219820Sjeff/**
1763219820Sjeff * ib_resize_cq - Modifies the capacity of the CQ.
1764219820Sjeff * @cq: The CQ to resize.
1765219820Sjeff * @cqe: The minimum size of the CQ.
1766219820Sjeff *
1767219820Sjeff * Users can examine the cq structure to determine the actual CQ size.
1768219820Sjeff */
1769219820Sjeffint ib_resize_cq(struct ib_cq *cq, int cqe);
1770219820Sjeff
1771219820Sjeff/**
1772219820Sjeff * ib_modify_cq - Modifies moderation params of the CQ
1773219820Sjeff * @cq: The CQ to modify.
1774219820Sjeff * @cq_count: number of CQEs that will trigger an event
1775219820Sjeff * @cq_period: max period of time in usec before triggering an event
1776219820Sjeff *
1777219820Sjeff */
1778219820Sjeffint ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
1779219820Sjeff
1780219820Sjeff/**
1781219820Sjeff * ib_destroy_cq - Destroys the specified CQ.
1782219820Sjeff * @cq: The CQ to destroy.
1783219820Sjeff */
1784219820Sjeffint ib_destroy_cq(struct ib_cq *cq);
1785219820Sjeff
1786219820Sjeff/**
1787219820Sjeff * ib_poll_cq - poll a CQ for completion(s)
1788219820Sjeff * @cq:the CQ being polled
1789219820Sjeff * @num_entries:maximum number of completions to return
1790219820Sjeff * @wc:array of at least @num_entries &struct ib_wc where completions
1791219820Sjeff *   will be returned
1792219820Sjeff *
1793219820Sjeff * Poll a CQ for (possibly multiple) completions.  If the return value
1794219820Sjeff * is < 0, an error occurred.  If the return value is >= 0, it is the
1795219820Sjeff * number of completions returned.  If the return value is
1796219820Sjeff * non-negative and < num_entries, then the CQ was emptied.
1797219820Sjeff */
1798219820Sjeffstatic inline int ib_poll_cq(struct ib_cq *cq, int num_entries,
1799219820Sjeff			     struct ib_wc *wc)
1800219820Sjeff{
1801219820Sjeff	return cq->device->poll_cq(cq, num_entries, wc);
1802219820Sjeff}
1803219820Sjeff
1804219820Sjeff/**
1805219820Sjeff * ib_peek_cq - Returns the number of unreaped completions currently
1806219820Sjeff *   on the specified CQ.
1807219820Sjeff * @cq: The CQ to peek.
1808219820Sjeff * @wc_cnt: A minimum number of unreaped completions to check for.
1809219820Sjeff *
1810219820Sjeff * If the number of unreaped completions is greater than or equal to wc_cnt,
1811219820Sjeff * this function returns wc_cnt, otherwise, it returns the actual number of
1812219820Sjeff * unreaped completions.
1813219820Sjeff */
1814219820Sjeffint ib_peek_cq(struct ib_cq *cq, int wc_cnt);
1815219820Sjeff
1816219820Sjeff/**
1817219820Sjeff * ib_req_notify_cq - Request completion notification on a CQ.
1818219820Sjeff * @cq: The CQ to generate an event for.
1819219820Sjeff * @flags:
1820219820Sjeff *   Must contain exactly one of %IB_CQ_SOLICITED or %IB_CQ_NEXT_COMP
1821219820Sjeff *   to request an event on the next solicited event or next work
1822219820Sjeff *   completion at any type, respectively. %IB_CQ_REPORT_MISSED_EVENTS
1823219820Sjeff *   may also be |ed in to request a hint about missed events, as
1824219820Sjeff *   described below.
1825219820Sjeff *
1826219820Sjeff * Return Value:
1827219820Sjeff *    < 0 means an error occurred while requesting notification
1828219820Sjeff *   == 0 means notification was requested successfully, and if
1829219820Sjeff *        IB_CQ_REPORT_MISSED_EVENTS was passed in, then no events
1830219820Sjeff *        were missed and it is safe to wait for another event.  In
1831219820Sjeff *        this case is it guaranteed that any work completions added
1832219820Sjeff *        to the CQ since the last CQ poll will trigger a completion
1833219820Sjeff *        notification event.
1834219820Sjeff *    > 0 is only returned if IB_CQ_REPORT_MISSED_EVENTS was passed
1835219820Sjeff *        in.  It means that the consumer must poll the CQ again to
1836219820Sjeff *        make sure it is empty to avoid missing an event because of a
1837219820Sjeff *        race between requesting notification and an entry being
1838219820Sjeff *        added to the CQ.  This return value means it is possible
1839219820Sjeff *        (but not guaranteed) that a work completion has been added
1840219820Sjeff *        to the CQ since the last poll without triggering a
1841219820Sjeff *        completion notification event.
1842219820Sjeff */
1843219820Sjeffstatic inline int ib_req_notify_cq(struct ib_cq *cq,
1844219820Sjeff				   enum ib_cq_notify_flags flags)
1845219820Sjeff{
1846219820Sjeff	return cq->device->req_notify_cq(cq, flags);
1847219820Sjeff}
1848219820Sjeff
1849219820Sjeff/**
1850219820Sjeff * ib_req_ncomp_notif - Request completion notification when there are
1851219820Sjeff *   at least the specified number of unreaped completions on the CQ.
1852219820Sjeff * @cq: The CQ to generate an event for.
1853219820Sjeff * @wc_cnt: The number of unreaped completions that should be on the
1854219820Sjeff *   CQ before an event is generated.
1855219820Sjeff */
1856219820Sjeffstatic inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt)
1857219820Sjeff{
1858219820Sjeff	return cq->device->req_ncomp_notif ?
1859219820Sjeff		cq->device->req_ncomp_notif(cq, wc_cnt) :
1860219820Sjeff		-ENOSYS;
1861219820Sjeff}
1862219820Sjeff
1863219820Sjeff/**
1864219820Sjeff * ib_get_dma_mr - Returns a memory region for system memory that is
1865219820Sjeff *   usable for DMA.
1866219820Sjeff * @pd: The protection domain associated with the memory region.
1867219820Sjeff * @mr_access_flags: Specifies the memory access rights.
1868219820Sjeff *
1869219820Sjeff * Note that the ib_dma_*() functions defined below must be used
1870219820Sjeff * to create/destroy addresses used with the Lkey or Rkey returned
1871219820Sjeff * by ib_get_dma_mr().
1872219820Sjeff */
1873219820Sjeffstruct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags);
1874219820Sjeff
1875219820Sjeff/**
1876219820Sjeff * ib_dma_mapping_error - check a DMA addr for error
1877219820Sjeff * @dev: The device for which the dma_addr was created
1878219820Sjeff * @dma_addr: The DMA address to check
1879219820Sjeff */
1880219820Sjeffstatic inline int ib_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
1881219820Sjeff{
1882219820Sjeff	if (dev->dma_ops)
1883219820Sjeff		return dev->dma_ops->mapping_error(dev, dma_addr);
1884219820Sjeff	return dma_mapping_error(dev->dma_device, dma_addr);
1885219820Sjeff}
1886219820Sjeff
1887219820Sjeff/**
1888219820Sjeff * ib_dma_map_single - Map a kernel virtual address to DMA address
1889219820Sjeff * @dev: The device for which the dma_addr is to be created
1890219820Sjeff * @cpu_addr: The kernel virtual address
1891219820Sjeff * @size: The size of the region in bytes
1892219820Sjeff * @direction: The direction of the DMA
1893219820Sjeff */
1894219820Sjeffstatic inline u64 ib_dma_map_single(struct ib_device *dev,
1895219820Sjeff				    void *cpu_addr, size_t size,
1896219820Sjeff				    enum dma_data_direction direction)
1897219820Sjeff{
1898219820Sjeff	if (dev->dma_ops)
1899219820Sjeff		return dev->dma_ops->map_single(dev, cpu_addr, size, direction);
1900219820Sjeff	return dma_map_single(dev->dma_device, cpu_addr, size, direction);
1901219820Sjeff}
1902219820Sjeff
1903219820Sjeff/**
1904219820Sjeff * ib_dma_unmap_single - Destroy a mapping created by ib_dma_map_single()
1905219820Sjeff * @dev: The device for which the DMA address was created
1906219820Sjeff * @addr: The DMA address
1907219820Sjeff * @size: The size of the region in bytes
1908219820Sjeff * @direction: The direction of the DMA
1909219820Sjeff */
1910219820Sjeffstatic inline void ib_dma_unmap_single(struct ib_device *dev,
1911219820Sjeff				       u64 addr, size_t size,
1912219820Sjeff				       enum dma_data_direction direction)
1913219820Sjeff{
1914219820Sjeff	if (dev->dma_ops)
1915219820Sjeff		dev->dma_ops->unmap_single(dev, addr, size, direction);
1916219820Sjeff	else
1917219820Sjeff		dma_unmap_single(dev->dma_device, addr, size, direction);
1918219820Sjeff}
1919219820Sjeff
1920219820Sjeffstatic inline u64 ib_dma_map_single_attrs(struct ib_device *dev,
1921219820Sjeff					  void *cpu_addr, size_t size,
1922219820Sjeff					  enum dma_data_direction direction,
1923219820Sjeff					  struct dma_attrs *attrs)
1924219820Sjeff{
1925219820Sjeff	return dma_map_single_attrs(dev->dma_device, cpu_addr, size,
1926219820Sjeff				    direction, attrs);
1927219820Sjeff}
1928219820Sjeff
1929219820Sjeffstatic inline void ib_dma_unmap_single_attrs(struct ib_device *dev,
1930219820Sjeff					     u64 addr, size_t size,
1931219820Sjeff					     enum dma_data_direction direction,
1932219820Sjeff					     struct dma_attrs *attrs)
1933219820Sjeff{
1934219820Sjeff	return dma_unmap_single_attrs(dev->dma_device, addr, size,
1935219820Sjeff				      direction, attrs);
1936219820Sjeff}
1937219820Sjeff
1938219820Sjeff/**
1939219820Sjeff * ib_dma_map_page - Map a physical page to DMA address
1940219820Sjeff * @dev: The device for which the dma_addr is to be created
1941219820Sjeff * @page: The page to be mapped
1942219820Sjeff * @offset: The offset within the page
1943219820Sjeff * @size: The size of the region in bytes
1944219820Sjeff * @direction: The direction of the DMA
1945219820Sjeff */
1946219820Sjeffstatic inline u64 ib_dma_map_page(struct ib_device *dev,
1947219820Sjeff				  struct page *page,
1948219820Sjeff				  unsigned long offset,
1949219820Sjeff				  size_t size,
1950219820Sjeff					 enum dma_data_direction direction)
1951219820Sjeff{
1952219820Sjeff	if (dev->dma_ops)
1953219820Sjeff		return dev->dma_ops->map_page(dev, page, offset, size, direction);
1954219820Sjeff	return dma_map_page(dev->dma_device, page, offset, size, direction);
1955219820Sjeff}
1956219820Sjeff
1957219820Sjeff/**
1958219820Sjeff * ib_dma_unmap_page - Destroy a mapping created by ib_dma_map_page()
1959219820Sjeff * @dev: The device for which the DMA address was created
1960219820Sjeff * @addr: The DMA address
1961219820Sjeff * @size: The size of the region in bytes
1962219820Sjeff * @direction: The direction of the DMA
1963219820Sjeff */
1964219820Sjeffstatic inline void ib_dma_unmap_page(struct ib_device *dev,
1965219820Sjeff				     u64 addr, size_t size,
1966219820Sjeff				     enum dma_data_direction direction)
1967219820Sjeff{
1968219820Sjeff	if (dev->dma_ops)
1969219820Sjeff		dev->dma_ops->unmap_page(dev, addr, size, direction);
1970219820Sjeff	else
1971219820Sjeff		dma_unmap_page(dev->dma_device, addr, size, direction);
1972219820Sjeff}
1973219820Sjeff
1974219820Sjeff/**
1975219820Sjeff * ib_dma_map_sg - Map a scatter/gather list to DMA addresses
1976219820Sjeff * @dev: The device for which the DMA addresses are to be created
1977219820Sjeff * @sg: The array of scatter/gather entries
1978219820Sjeff * @nents: The number of scatter/gather entries
1979219820Sjeff * @direction: The direction of the DMA
1980219820Sjeff */
1981219820Sjeffstatic inline int ib_dma_map_sg(struct ib_device *dev,
1982219820Sjeff				struct scatterlist *sg, int nents,
1983219820Sjeff				enum dma_data_direction direction)
1984219820Sjeff{
1985219820Sjeff	if (dev->dma_ops)
1986219820Sjeff		return dev->dma_ops->map_sg(dev, sg, nents, direction);
1987219820Sjeff	return dma_map_sg(dev->dma_device, sg, nents, direction);
1988219820Sjeff}
1989219820Sjeff
1990219820Sjeff/**
1991219820Sjeff * ib_dma_unmap_sg - Unmap a scatter/gather list of DMA addresses
1992219820Sjeff * @dev: The device for which the DMA addresses were created
1993219820Sjeff * @sg: The array of scatter/gather entries
1994219820Sjeff * @nents: The number of scatter/gather entries
1995219820Sjeff * @direction: The direction of the DMA
1996219820Sjeff */
1997219820Sjeffstatic inline void ib_dma_unmap_sg(struct ib_device *dev,
1998219820Sjeff				   struct scatterlist *sg, int nents,
1999219820Sjeff				   enum dma_data_direction direction)
2000219820Sjeff{
2001219820Sjeff	if (dev->dma_ops)
2002219820Sjeff		dev->dma_ops->unmap_sg(dev, sg, nents, direction);
2003219820Sjeff	else
2004219820Sjeff		dma_unmap_sg(dev->dma_device, sg, nents, direction);
2005219820Sjeff}
2006219820Sjeff
2007219820Sjeffstatic inline int ib_dma_map_sg_attrs(struct ib_device *dev,
2008219820Sjeff				      struct scatterlist *sg, int nents,
2009219820Sjeff				      enum dma_data_direction direction,
2010219820Sjeff				      struct dma_attrs *attrs)
2011219820Sjeff{
2012219820Sjeff	return dma_map_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2013219820Sjeff}
2014219820Sjeff
2015219820Sjeffstatic inline void ib_dma_unmap_sg_attrs(struct ib_device *dev,
2016219820Sjeff					 struct scatterlist *sg, int nents,
2017219820Sjeff					 enum dma_data_direction direction,
2018219820Sjeff					 struct dma_attrs *attrs)
2019219820Sjeff{
2020219820Sjeff	dma_unmap_sg_attrs(dev->dma_device, sg, nents, direction, attrs);
2021219820Sjeff}
2022219820Sjeff/**
2023219820Sjeff * ib_sg_dma_address - Return the DMA address from a scatter/gather entry
2024219820Sjeff * @dev: The device for which the DMA addresses were created
2025219820Sjeff * @sg: The scatter/gather entry
2026219820Sjeff */
2027219820Sjeffstatic inline u64 ib_sg_dma_address(struct ib_device *dev,
2028219820Sjeff				    struct scatterlist *sg)
2029219820Sjeff{
2030219820Sjeff	if (dev->dma_ops)
2031219820Sjeff		return dev->dma_ops->dma_address(dev, sg);
2032219820Sjeff	return sg_dma_address(sg);
2033219820Sjeff}
2034219820Sjeff
2035219820Sjeff/**
2036219820Sjeff * ib_sg_dma_len - Return the DMA length from a scatter/gather entry
2037219820Sjeff * @dev: The device for which the DMA addresses were created
2038219820Sjeff * @sg: The scatter/gather entry
2039219820Sjeff */
2040219820Sjeffstatic inline unsigned int ib_sg_dma_len(struct ib_device *dev,
2041219820Sjeff					 struct scatterlist *sg)
2042219820Sjeff{
2043219820Sjeff	if (dev->dma_ops)
2044219820Sjeff		return dev->dma_ops->dma_len(dev, sg);
2045219820Sjeff	return sg_dma_len(sg);
2046219820Sjeff}
2047219820Sjeff
2048219820Sjeff/**
2049219820Sjeff * ib_dma_sync_single_for_cpu - Prepare DMA region to be accessed by CPU
2050219820Sjeff * @dev: The device for which the DMA address was created
2051219820Sjeff * @addr: The DMA address
2052219820Sjeff * @size: The size of the region in bytes
2053219820Sjeff * @dir: The direction of the DMA
2054219820Sjeff */
2055219820Sjeffstatic inline void ib_dma_sync_single_for_cpu(struct ib_device *dev,
2056219820Sjeff					      u64 addr,
2057219820Sjeff					      size_t size,
2058219820Sjeff					      enum dma_data_direction dir)
2059219820Sjeff{
2060219820Sjeff	if (dev->dma_ops)
2061219820Sjeff		dev->dma_ops->sync_single_for_cpu(dev, addr, size, dir);
2062219820Sjeff	else
2063219820Sjeff		dma_sync_single_for_cpu(dev->dma_device, addr, size, dir);
2064219820Sjeff}
2065219820Sjeff
2066219820Sjeff/**
2067219820Sjeff * ib_dma_sync_single_for_device - Prepare DMA region to be accessed by device
2068219820Sjeff * @dev: The device for which the DMA address was created
2069219820Sjeff * @addr: The DMA address
2070219820Sjeff * @size: The size of the region in bytes
2071219820Sjeff * @dir: The direction of the DMA
2072219820Sjeff */
2073219820Sjeffstatic inline void ib_dma_sync_single_for_device(struct ib_device *dev,
2074219820Sjeff						 u64 addr,
2075219820Sjeff						 size_t size,
2076219820Sjeff						 enum dma_data_direction dir)
2077219820Sjeff{
2078219820Sjeff	if (dev->dma_ops)
2079219820Sjeff		dev->dma_ops->sync_single_for_device(dev, addr, size, dir);
2080219820Sjeff	else
2081219820Sjeff		dma_sync_single_for_device(dev->dma_device, addr, size, dir);
2082219820Sjeff}
2083219820Sjeff
2084219820Sjeff/**
2085219820Sjeff * ib_dma_alloc_coherent - Allocate memory and map it for DMA
2086219820Sjeff * @dev: The device for which the DMA address is requested
2087219820Sjeff * @size: The size of the region to allocate in bytes
2088219820Sjeff * @dma_handle: A pointer for returning the DMA address of the region
2089219820Sjeff * @flag: memory allocator flags
2090219820Sjeff */
2091219820Sjeffstatic inline void *ib_dma_alloc_coherent(struct ib_device *dev,
2092219820Sjeff					   size_t size,
2093219820Sjeff					   u64 *dma_handle,
2094219820Sjeff					   gfp_t flag)
2095219820Sjeff{
2096219820Sjeff	if (dev->dma_ops)
2097219820Sjeff		return dev->dma_ops->alloc_coherent(dev, size, dma_handle, flag);
2098219820Sjeff	else {
2099219820Sjeff		dma_addr_t handle;
2100219820Sjeff		void *ret;
2101219820Sjeff
2102219820Sjeff		ret = dma_alloc_coherent(dev->dma_device, size, &handle, flag);
2103219820Sjeff		*dma_handle = handle;
2104219820Sjeff		return ret;
2105219820Sjeff	}
2106219820Sjeff}
2107219820Sjeff
2108219820Sjeff/**
2109219820Sjeff * ib_dma_free_coherent - Free memory allocated by ib_dma_alloc_coherent()
2110219820Sjeff * @dev: The device for which the DMA addresses were allocated
2111219820Sjeff * @size: The size of the region
2112219820Sjeff * @cpu_addr: the address returned by ib_dma_alloc_coherent()
2113219820Sjeff * @dma_handle: the DMA address returned by ib_dma_alloc_coherent()
2114219820Sjeff */
2115219820Sjeffstatic inline void ib_dma_free_coherent(struct ib_device *dev,
2116219820Sjeff					size_t size, void *cpu_addr,
2117219820Sjeff					u64 dma_handle)
2118219820Sjeff{
2119219820Sjeff	if (dev->dma_ops)
2120219820Sjeff		dev->dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
2121219820Sjeff	else
2122219820Sjeff		dma_free_coherent(dev->dma_device, size, cpu_addr, dma_handle);
2123219820Sjeff}
2124219820Sjeff
2125219820Sjeff/**
2126219820Sjeff * ib_reg_phys_mr - Prepares a virtually addressed memory region for use
2127219820Sjeff *   by an HCA.
2128219820Sjeff * @pd: The protection domain associated assigned to the registered region.
2129219820Sjeff * @phys_buf_array: Specifies a list of physical buffers to use in the
2130219820Sjeff *   memory region.
2131219820Sjeff * @num_phys_buf: Specifies the size of the phys_buf_array.
2132219820Sjeff * @mr_access_flags: Specifies the memory access rights.
2133219820Sjeff * @iova_start: The offset of the region's starting I/O virtual address.
2134219820Sjeff */
2135219820Sjeffstruct ib_mr *ib_reg_phys_mr(struct ib_pd *pd,
2136219820Sjeff			     struct ib_phys_buf *phys_buf_array,
2137219820Sjeff			     int num_phys_buf,
2138219820Sjeff			     int mr_access_flags,
2139219820Sjeff			     u64 *iova_start);
2140219820Sjeff
2141219820Sjeff/**
2142219820Sjeff * ib_rereg_phys_mr - Modifies the attributes of an existing memory region.
2143219820Sjeff *   Conceptually, this call performs the functions deregister memory region
2144219820Sjeff *   followed by register physical memory region.  Where possible,
2145219820Sjeff *   resources are reused instead of deallocated and reallocated.
2146219820Sjeff * @mr: The memory region to modify.
2147219820Sjeff * @mr_rereg_mask: A bit-mask used to indicate which of the following
2148219820Sjeff *   properties of the memory region are being modified.
2149219820Sjeff * @pd: If %IB_MR_REREG_PD is set in mr_rereg_mask, this field specifies
2150219820Sjeff *   the new protection domain to associated with the memory region,
2151219820Sjeff *   otherwise, this parameter is ignored.
2152219820Sjeff * @phys_buf_array: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2153219820Sjeff *   field specifies a list of physical buffers to use in the new
2154219820Sjeff *   translation, otherwise, this parameter is ignored.
2155219820Sjeff * @num_phys_buf: If %IB_MR_REREG_TRANS is set in mr_rereg_mask, this
2156219820Sjeff *   field specifies the size of the phys_buf_array, otherwise, this
2157219820Sjeff *   parameter is ignored.
2158219820Sjeff * @mr_access_flags: If %IB_MR_REREG_ACCESS is set in mr_rereg_mask, this
2159219820Sjeff *   field specifies the new memory access rights, otherwise, this
2160219820Sjeff *   parameter is ignored.
2161219820Sjeff * @iova_start: The offset of the region's starting I/O virtual address.
2162219820Sjeff */
2163219820Sjeffint ib_rereg_phys_mr(struct ib_mr *mr,
2164219820Sjeff		     int mr_rereg_mask,
2165219820Sjeff		     struct ib_pd *pd,
2166219820Sjeff		     struct ib_phys_buf *phys_buf_array,
2167219820Sjeff		     int num_phys_buf,
2168219820Sjeff		     int mr_access_flags,
2169219820Sjeff		     u64 *iova_start);
2170219820Sjeff
2171219820Sjeff/**
2172219820Sjeff * ib_query_mr - Retrieves information about a specific memory region.
2173219820Sjeff * @mr: The memory region to retrieve information about.
2174219820Sjeff * @mr_attr: The attributes of the specified memory region.
2175219820Sjeff */
2176219820Sjeffint ib_query_mr(struct ib_mr *mr, struct ib_mr_attr *mr_attr);
2177219820Sjeff
2178219820Sjeff/**
2179219820Sjeff * ib_dereg_mr - Deregisters a memory region and removes it from the
2180219820Sjeff *   HCA translation table.
2181219820Sjeff * @mr: The memory region to deregister.
2182219820Sjeff */
2183219820Sjeffint ib_dereg_mr(struct ib_mr *mr);
2184219820Sjeff
2185219820Sjeff/**
2186219820Sjeff * ib_alloc_fast_reg_mr - Allocates memory region usable with the
2187219820Sjeff *   IB_WR_FAST_REG_MR send work request.
2188219820Sjeff * @pd: The protection domain associated with the region.
2189219820Sjeff * @max_page_list_len: requested max physical buffer list length to be
2190219820Sjeff *   used with fast register work requests for this MR.
2191219820Sjeff */
2192219820Sjeffstruct ib_mr *ib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
2193219820Sjeff
2194219820Sjeff/**
2195219820Sjeff * ib_alloc_fast_reg_page_list - Allocates a page list array
2196219820Sjeff * @device - ib device pointer.
2197219820Sjeff * @page_list_len - size of the page list array to be allocated.
2198219820Sjeff *
2199219820Sjeff * This allocates and returns a struct ib_fast_reg_page_list * and a
2200219820Sjeff * page_list array that is at least page_list_len in size.  The actual
2201219820Sjeff * size is returned in max_page_list_len.  The caller is responsible
2202219820Sjeff * for initializing the contents of the page_list array before posting
2203219820Sjeff * a send work request with the IB_WC_FAST_REG_MR opcode.
2204219820Sjeff *
2205219820Sjeff * The page_list array entries must be translated using one of the
2206219820Sjeff * ib_dma_*() functions just like the addresses passed to
2207219820Sjeff * ib_map_phys_fmr().  Once the ib_post_send() is issued, the struct
2208219820Sjeff * ib_fast_reg_page_list must not be modified by the caller until the
2209219820Sjeff * IB_WC_FAST_REG_MR work request completes.
2210219820Sjeff */
2211219820Sjeffstruct ib_fast_reg_page_list *ib_alloc_fast_reg_page_list(
2212219820Sjeff				struct ib_device *device, int page_list_len);
2213219820Sjeff
2214219820Sjeff/**
2215219820Sjeff * ib_free_fast_reg_page_list - Deallocates a previously allocated
2216219820Sjeff *   page list array.
2217219820Sjeff * @page_list - struct ib_fast_reg_page_list pointer to be deallocated.
2218219820Sjeff */
2219219820Sjeffvoid ib_free_fast_reg_page_list(struct ib_fast_reg_page_list *page_list);
2220219820Sjeff
2221219820Sjeff/**
2222219820Sjeff * ib_update_fast_reg_key - updates the key portion of the fast_reg MR
2223219820Sjeff *   R_Key and L_Key.
2224219820Sjeff * @mr - struct ib_mr pointer to be updated.
2225219820Sjeff * @newkey - new key to be used.
2226219820Sjeff */
2227219820Sjeffstatic inline void ib_update_fast_reg_key(struct ib_mr *mr, u8 newkey)
2228219820Sjeff{
2229219820Sjeff	mr->lkey = (mr->lkey & 0xffffff00) | newkey;
2230219820Sjeff	mr->rkey = (mr->rkey & 0xffffff00) | newkey;
2231219820Sjeff}
2232219820Sjeff
2233219820Sjeff/**
2234219820Sjeff * ib_alloc_mw - Allocates a memory window.
2235219820Sjeff * @pd: The protection domain associated with the memory window.
2236219820Sjeff */
2237219820Sjeffstruct ib_mw *ib_alloc_mw(struct ib_pd *pd);
2238219820Sjeff
2239219820Sjeff/**
2240219820Sjeff * ib_bind_mw - Posts a work request to the send queue of the specified
2241219820Sjeff *   QP, which binds the memory window to the given address range and
2242219820Sjeff *   remote access attributes.
2243219820Sjeff * @qp: QP to post the bind work request on.
2244219820Sjeff * @mw: The memory window to bind.
2245219820Sjeff * @mw_bind: Specifies information about the memory window, including
2246219820Sjeff *   its address range, remote access rights, and associated memory region.
2247219820Sjeff */
2248219820Sjeffstatic inline int ib_bind_mw(struct ib_qp *qp,
2249219820Sjeff			     struct ib_mw *mw,
2250219820Sjeff			     struct ib_mw_bind *mw_bind)
2251219820Sjeff{
2252219820Sjeff	/* XXX reference counting in corresponding MR? */
2253219820Sjeff	return mw->device->bind_mw ?
2254219820Sjeff		mw->device->bind_mw(qp, mw, mw_bind) :
2255219820Sjeff		-ENOSYS;
2256219820Sjeff}
2257219820Sjeff
2258219820Sjeff/**
2259219820Sjeff * ib_dealloc_mw - Deallocates a memory window.
2260219820Sjeff * @mw: The memory window to deallocate.
2261219820Sjeff */
2262219820Sjeffint ib_dealloc_mw(struct ib_mw *mw);
2263219820Sjeff
2264219820Sjeff/**
2265219820Sjeff * ib_alloc_fmr - Allocates a unmapped fast memory region.
2266219820Sjeff * @pd: The protection domain associated with the unmapped region.
2267219820Sjeff * @mr_access_flags: Specifies the memory access rights.
2268219820Sjeff * @fmr_attr: Attributes of the unmapped region.
2269219820Sjeff *
2270219820Sjeff * A fast memory region must be mapped before it can be used as part of
2271219820Sjeff * a work request.
2272219820Sjeff */
2273219820Sjeffstruct ib_fmr *ib_alloc_fmr(struct ib_pd *pd,
2274219820Sjeff			    int mr_access_flags,
2275219820Sjeff			    struct ib_fmr_attr *fmr_attr);
2276219820Sjeff
2277219820Sjeff/**
2278219820Sjeff * ib_map_phys_fmr - Maps a list of physical pages to a fast memory region.
2279219820Sjeff * @fmr: The fast memory region to associate with the pages.
2280219820Sjeff * @page_list: An array of physical pages to map to the fast memory region.
2281219820Sjeff * @list_len: The number of pages in page_list.
2282219820Sjeff * @iova: The I/O virtual address to use with the mapped region.
2283219820Sjeff */
2284219820Sjeffstatic inline int ib_map_phys_fmr(struct ib_fmr *fmr,
2285219820Sjeff				  u64 *page_list, int list_len,
2286219820Sjeff				  u64 iova)
2287219820Sjeff{
2288219820Sjeff	return fmr->device->map_phys_fmr(fmr, page_list, list_len, iova);
2289219820Sjeff}
2290219820Sjeff
2291219820Sjeff/**
2292219820Sjeff * ib_unmap_fmr - Removes the mapping from a list of fast memory regions.
2293219820Sjeff * @fmr_list: A linked list of fast memory regions to unmap.
2294219820Sjeff */
2295219820Sjeffint ib_unmap_fmr(struct list_head *fmr_list);
2296219820Sjeff
2297219820Sjeff/**
2298219820Sjeff * ib_dealloc_fmr - Deallocates a fast memory region.
2299219820Sjeff * @fmr: The fast memory region to deallocate.
2300219820Sjeff */
2301219820Sjeffint ib_dealloc_fmr(struct ib_fmr *fmr);
2302219820Sjeff
2303219820Sjeff/**
2304219820Sjeff * ib_attach_mcast - Attaches the specified QP to a multicast group.
2305219820Sjeff * @qp: QP to attach to the multicast group.  The QP must be type
2306219820Sjeff *   IB_QPT_UD.
2307219820Sjeff * @gid: Multicast group GID.
2308219820Sjeff * @lid: Multicast group LID in host byte order.
2309219820Sjeff *
2310219820Sjeff * In order to send and receive multicast packets, subnet
2311219820Sjeff * administration must have created the multicast group and configured
2312219820Sjeff * the fabric appropriately.  The port associated with the specified
2313219820Sjeff * QP must also be a member of the multicast group.
2314219820Sjeff */
2315219820Sjeffint ib_attach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2316219820Sjeff
2317219820Sjeff/**
2318219820Sjeff * ib_detach_mcast - Detaches the specified QP from a multicast group.
2319219820Sjeff * @qp: QP to detach from the multicast group.
2320219820Sjeff * @gid: Multicast group GID.
2321219820Sjeff * @lid: Multicast group LID in host byte order.
2322219820Sjeff */
2323219820Sjeffint ib_detach_mcast(struct ib_qp *qp, union ib_gid *gid, u16 lid);
2324219820Sjeff
2325219820Sjeff/**
2326255932Salfred * ib_alloc_xrcd - Allocates an XRC domain.
2327255932Salfred * @device: The device on which to allocate the XRC domain.
2328219820Sjeff */
2329255932Salfredstruct ib_xrcd *ib_alloc_xrcd(struct ib_device *device);
2330219820Sjeff
2331219820Sjeff/**
2332255932Salfred * ib_dealloc_xrcd - Deallocates an XRC domain.
2333255932Salfred * @xrcd: The XRC domain to deallocate.
2334219820Sjeff */
2335255932Salfredint ib_dealloc_xrcd(struct ib_xrcd *xrcd);
2336219820Sjeff
2337255932Salfredint ib_attach_flow(struct ib_qp *qp, struct ib_flow_spec *spec, int priority);
2338255932Salfredint ib_detach_flow(struct ib_qp *qp, struct ib_flow_spec *spec, int priority);
2339255932Salfred
2340219820Sjeff#endif /* IB_VERBS_H */
2341