xref: /freebsd/contrib/ofed/libmlx4/mlx4.h (revision a687910fc4352117413b8e0275383e4c687d4c4c)
1d6b92ffaSHans Petter Selasky /*
2d6b92ffaSHans Petter Selasky  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
3d6b92ffaSHans Petter Selasky  * Copyright (c) 2005, 2006, 2007 Cisco Systems.  All rights reserved.
4d6b92ffaSHans Petter Selasky  *
5d6b92ffaSHans Petter Selasky  * This software is available to you under a choice of one of two
6d6b92ffaSHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
7d6b92ffaSHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
8d6b92ffaSHans Petter Selasky  * COPYING in the main directory of this source tree, or the
9d6b92ffaSHans Petter Selasky  * OpenIB.org BSD license below:
10d6b92ffaSHans Petter Selasky  *
11d6b92ffaSHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
12d6b92ffaSHans Petter Selasky  *     without modification, are permitted provided that the following
13d6b92ffaSHans Petter Selasky  *     conditions are met:
14d6b92ffaSHans Petter Selasky  *
15d6b92ffaSHans Petter Selasky  *      - Redistributions of source code must retain the above
16d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
17d6b92ffaSHans Petter Selasky  *        disclaimer.
18d6b92ffaSHans Petter Selasky  *
19d6b92ffaSHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
20d6b92ffaSHans Petter Selasky  *        copyright notice, this list of conditions and the following
21d6b92ffaSHans Petter Selasky  *        disclaimer in the documentation and/or other materials
22d6b92ffaSHans Petter Selasky  *        provided with the distribution.
23d6b92ffaSHans Petter Selasky  *
24d6b92ffaSHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25d6b92ffaSHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26d6b92ffaSHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27d6b92ffaSHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28d6b92ffaSHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29d6b92ffaSHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30d6b92ffaSHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31d6b92ffaSHans Petter Selasky  * SOFTWARE.
32d6b92ffaSHans Petter Selasky  */
33d6b92ffaSHans Petter Selasky 
34d6b92ffaSHans Petter Selasky #ifndef MLX4_H
35d6b92ffaSHans Petter Selasky #define MLX4_H
36d6b92ffaSHans Petter Selasky 
37d6b92ffaSHans Petter Selasky #include <infiniband/endian.h>
38d6b92ffaSHans Petter Selasky #include <stddef.h>
39d6b92ffaSHans Petter Selasky 
40d6b92ffaSHans Petter Selasky #include <infiniband/driver.h>
41d6b92ffaSHans Petter Selasky #include <infiniband/udma_barrier.h>
42d6b92ffaSHans Petter Selasky #include <infiniband/verbs.h>
43d6b92ffaSHans Petter Selasky 
44d6b92ffaSHans Petter Selasky #define MLX4_PORTS_NUM 2
45d6b92ffaSHans Petter Selasky 
46d6b92ffaSHans Petter Selasky #define PFX		"mlx4: "
47d6b92ffaSHans Petter Selasky 
48d6b92ffaSHans Petter Selasky enum {
49d6b92ffaSHans Petter Selasky 	MLX4_STAT_RATE_OFFSET		= 5
50d6b92ffaSHans Petter Selasky };
51d6b92ffaSHans Petter Selasky 
52d6b92ffaSHans Petter Selasky enum {
53d6b92ffaSHans Petter Selasky 	MLX4_QP_TABLE_BITS		= 8,
54d6b92ffaSHans Petter Selasky 	MLX4_QP_TABLE_SIZE		= 1 << MLX4_QP_TABLE_BITS,
55d6b92ffaSHans Petter Selasky 	MLX4_QP_TABLE_MASK		= MLX4_QP_TABLE_SIZE - 1
56d6b92ffaSHans Petter Selasky };
57d6b92ffaSHans Petter Selasky 
58d6b92ffaSHans Petter Selasky #define MLX4_REMOTE_SRQN_FLAGS(wr) htobe32(wr->qp_type.xrc.remote_srqn << 8)
59d6b92ffaSHans Petter Selasky 
60d6b92ffaSHans Petter Selasky enum {
61d6b92ffaSHans Petter Selasky 	MLX4_XSRQ_TABLE_BITS = 8,
62d6b92ffaSHans Petter Selasky 	MLX4_XSRQ_TABLE_SIZE = 1 << MLX4_XSRQ_TABLE_BITS,
63d6b92ffaSHans Petter Selasky 	MLX4_XSRQ_TABLE_MASK = MLX4_XSRQ_TABLE_SIZE - 1
64d6b92ffaSHans Petter Selasky };
65d6b92ffaSHans Petter Selasky 
66d6b92ffaSHans Petter Selasky struct mlx4_xsrq_table {
67d6b92ffaSHans Petter Selasky 	struct {
68d6b92ffaSHans Petter Selasky 		struct mlx4_srq **table;
69d6b92ffaSHans Petter Selasky 		int		  refcnt;
70d6b92ffaSHans Petter Selasky 	} xsrq_table[MLX4_XSRQ_TABLE_SIZE];
71d6b92ffaSHans Petter Selasky 
72d6b92ffaSHans Petter Selasky 	pthread_mutex_t		  mutex;
73d6b92ffaSHans Petter Selasky 	int			  num_xsrq;
74d6b92ffaSHans Petter Selasky 	int			  shift;
75d6b92ffaSHans Petter Selasky 	int			  mask;
76d6b92ffaSHans Petter Selasky };
77d6b92ffaSHans Petter Selasky 
78d6b92ffaSHans Petter Selasky enum {
79d6b92ffaSHans Petter Selasky 	MLX4_XRC_QPN_BIT     = (1 << 23)
80d6b92ffaSHans Petter Selasky };
81d6b92ffaSHans Petter Selasky 
82d6b92ffaSHans Petter Selasky enum mlx4_db_type {
83d6b92ffaSHans Petter Selasky 	MLX4_DB_TYPE_CQ,
84d6b92ffaSHans Petter Selasky 	MLX4_DB_TYPE_RQ,
85d6b92ffaSHans Petter Selasky 	MLX4_NUM_DB_TYPE
86d6b92ffaSHans Petter Selasky };
87d6b92ffaSHans Petter Selasky 
88d6b92ffaSHans Petter Selasky enum {
89d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_NOP			= 0x00,
90d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_SEND_INVAL		= 0x01,
91d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_RDMA_WRITE		= 0x08,
92d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_RDMA_WRITE_IMM	= 0x09,
93d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_SEND		= 0x0a,
94d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_SEND_IMM		= 0x0b,
95d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_LSO			= 0x0e,
96d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_RDMA_READ		= 0x10,
97d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_ATOMIC_CS		= 0x11,
98d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_ATOMIC_FA		= 0x12,
99d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_MASKED_ATOMIC_CS	= 0x14,
100d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_MASKED_ATOMIC_FA	= 0x15,
101d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_BIND_MW		= 0x18,
102d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_FMR			= 0x19,
103d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_LOCAL_INVAL		= 0x1b,
104d6b92ffaSHans Petter Selasky 	MLX4_OPCODE_CONFIG_CMD		= 0x1f,
105d6b92ffaSHans Petter Selasky 
106d6b92ffaSHans Petter Selasky 	MLX4_RECV_OPCODE_RDMA_WRITE_IMM	= 0x00,
107d6b92ffaSHans Petter Selasky 	MLX4_RECV_OPCODE_SEND		= 0x01,
108d6b92ffaSHans Petter Selasky 	MLX4_RECV_OPCODE_SEND_IMM	= 0x02,
109d6b92ffaSHans Petter Selasky 	MLX4_RECV_OPCODE_SEND_INVAL	= 0x03,
110d6b92ffaSHans Petter Selasky 
111d6b92ffaSHans Petter Selasky 	MLX4_CQE_OPCODE_ERROR		= 0x1e,
112d6b92ffaSHans Petter Selasky 	MLX4_CQE_OPCODE_RESIZE		= 0x16,
113d6b92ffaSHans Petter Selasky };
114d6b92ffaSHans Petter Selasky 
115d6b92ffaSHans Petter Selasky struct mlx4_device {
116d6b92ffaSHans Petter Selasky 	struct verbs_device		verbs_dev;
117d6b92ffaSHans Petter Selasky 	int				page_size;
118d6b92ffaSHans Petter Selasky 	int				abi_version;
119d6b92ffaSHans Petter Selasky };
120d6b92ffaSHans Petter Selasky 
121d6b92ffaSHans Petter Selasky struct mlx4_db_page;
122d6b92ffaSHans Petter Selasky 
123d6b92ffaSHans Petter Selasky struct mlx4_context {
124d6b92ffaSHans Petter Selasky 	struct ibv_context		ibv_ctx;
125d6b92ffaSHans Petter Selasky 
126d6b92ffaSHans Petter Selasky 	void			       *uar;
127d6b92ffaSHans Petter Selasky 	pthread_spinlock_t		uar_lock;
128d6b92ffaSHans Petter Selasky 
129d6b92ffaSHans Petter Selasky 	void			       *bf_page;
130d6b92ffaSHans Petter Selasky 	int				bf_buf_size;
131d6b92ffaSHans Petter Selasky 	int				bf_offset;
132d6b92ffaSHans Petter Selasky 	pthread_spinlock_t		bf_lock;
133d6b92ffaSHans Petter Selasky 
134d6b92ffaSHans Petter Selasky 	struct {
135d6b92ffaSHans Petter Selasky 		struct mlx4_qp	      **table;
136d6b92ffaSHans Petter Selasky 		int			refcnt;
137d6b92ffaSHans Petter Selasky 	}				qp_table[MLX4_QP_TABLE_SIZE];
138d6b92ffaSHans Petter Selasky 	pthread_mutex_t			qp_table_mutex;
139d6b92ffaSHans Petter Selasky 	int				num_qps;
140d6b92ffaSHans Petter Selasky 	int				qp_table_shift;
141d6b92ffaSHans Petter Selasky 	int				qp_table_mask;
142d6b92ffaSHans Petter Selasky 	int				max_qp_wr;
143d6b92ffaSHans Petter Selasky 	int				max_sge;
144d6b92ffaSHans Petter Selasky 
145d6b92ffaSHans Petter Selasky 	struct mlx4_db_page	       *db_list[MLX4_NUM_DB_TYPE];
146d6b92ffaSHans Petter Selasky 	pthread_mutex_t			db_list_mutex;
147d6b92ffaSHans Petter Selasky 	int				cqe_size;
148d6b92ffaSHans Petter Selasky 	struct mlx4_xsrq_table		xsrq_table;
149d6b92ffaSHans Petter Selasky 	struct {
150d6b92ffaSHans Petter Selasky 		uint8_t                 valid;
151d6b92ffaSHans Petter Selasky 		uint8_t                 link_layer;
152d6b92ffaSHans Petter Selasky 		enum ibv_port_cap_flags caps;
153d6b92ffaSHans Petter Selasky 	} port_query_cache[MLX4_PORTS_NUM];
154d6b92ffaSHans Petter Selasky 	struct {
155d6b92ffaSHans Petter Selasky 		uint64_t                offset;
156d6b92ffaSHans Petter Selasky 		uint8_t                 offset_valid;
157d6b92ffaSHans Petter Selasky 	} core_clock;
158d6b92ffaSHans Petter Selasky 	void			       *hca_core_clock;
159d6b92ffaSHans Petter Selasky };
160d6b92ffaSHans Petter Selasky 
161d6b92ffaSHans Petter Selasky struct mlx4_buf {
162d6b92ffaSHans Petter Selasky 	void			       *buf;
163d6b92ffaSHans Petter Selasky 	size_t				length;
164d6b92ffaSHans Petter Selasky };
165d6b92ffaSHans Petter Selasky 
166d6b92ffaSHans Petter Selasky struct mlx4_pd {
167d6b92ffaSHans Petter Selasky 	struct ibv_pd			ibv_pd;
168d6b92ffaSHans Petter Selasky 	uint32_t			pdn;
169d6b92ffaSHans Petter Selasky };
170d6b92ffaSHans Petter Selasky 
171d6b92ffaSHans Petter Selasky enum {
172d6b92ffaSHans Petter Selasky 	MLX4_CQ_FLAGS_RX_CSUM_VALID = 1 << 0,
173d6b92ffaSHans Petter Selasky 	MLX4_CQ_FLAGS_EXTENDED = 1 << 1,
174d6b92ffaSHans Petter Selasky 	MLX4_CQ_FLAGS_SINGLE_THREADED = 1 << 2,
175d6b92ffaSHans Petter Selasky };
176d6b92ffaSHans Petter Selasky 
177d6b92ffaSHans Petter Selasky struct mlx4_cq {
178d6b92ffaSHans Petter Selasky 	struct ibv_cq_ex		ibv_cq;
179d6b92ffaSHans Petter Selasky 	struct mlx4_buf			buf;
180d6b92ffaSHans Petter Selasky 	struct mlx4_buf			resize_buf;
181d6b92ffaSHans Petter Selasky 	pthread_spinlock_t		lock;
182d6b92ffaSHans Petter Selasky 	uint32_t			cqn;
183d6b92ffaSHans Petter Selasky 	uint32_t			cons_index;
184d6b92ffaSHans Petter Selasky 	uint32_t		       *set_ci_db;
185d6b92ffaSHans Petter Selasky 	uint32_t		       *arm_db;
186d6b92ffaSHans Petter Selasky 	int				arm_sn;
187d6b92ffaSHans Petter Selasky 	int				cqe_size;
188d6b92ffaSHans Petter Selasky 	struct mlx4_qp			*cur_qp;
189d6b92ffaSHans Petter Selasky 	struct mlx4_cqe			*cqe;
190d6b92ffaSHans Petter Selasky 	uint32_t			flags;
191d6b92ffaSHans Petter Selasky };
192d6b92ffaSHans Petter Selasky 
193d6b92ffaSHans Petter Selasky struct mlx4_srq {
194d6b92ffaSHans Petter Selasky 	struct verbs_srq		verbs_srq;
195d6b92ffaSHans Petter Selasky 	struct mlx4_buf			buf;
196d6b92ffaSHans Petter Selasky 	pthread_spinlock_t		lock;
197d6b92ffaSHans Petter Selasky 	uint64_t		       *wrid;
198d6b92ffaSHans Petter Selasky 	uint32_t			srqn;
199d6b92ffaSHans Petter Selasky 	int				max;
200d6b92ffaSHans Petter Selasky 	int				max_gs;
201d6b92ffaSHans Petter Selasky 	int				wqe_shift;
202d6b92ffaSHans Petter Selasky 	int				head;
203d6b92ffaSHans Petter Selasky 	int				tail;
204d6b92ffaSHans Petter Selasky 	uint32_t		       *db;
205d6b92ffaSHans Petter Selasky 	uint16_t			counter;
206d6b92ffaSHans Petter Selasky 	uint8_t				ext_srq;
207d6b92ffaSHans Petter Selasky };
208d6b92ffaSHans Petter Selasky 
209d6b92ffaSHans Petter Selasky struct mlx4_wq {
210d6b92ffaSHans Petter Selasky 	uint64_t		       *wrid;
211d6b92ffaSHans Petter Selasky 	pthread_spinlock_t		lock;
212d6b92ffaSHans Petter Selasky 	int				wqe_cnt;
213d6b92ffaSHans Petter Selasky 	int				max_post;
214d6b92ffaSHans Petter Selasky 	unsigned			head;
215d6b92ffaSHans Petter Selasky 	unsigned			tail;
216d6b92ffaSHans Petter Selasky 	int				max_gs;
217d6b92ffaSHans Petter Selasky 	int				wqe_shift;
218d6b92ffaSHans Petter Selasky 	int				offset;
219d6b92ffaSHans Petter Selasky };
220d6b92ffaSHans Petter Selasky 
221d6b92ffaSHans Petter Selasky struct mlx4_qp {
222d6b92ffaSHans Petter Selasky 	struct verbs_qp			verbs_qp;
223d6b92ffaSHans Petter Selasky 	struct mlx4_buf			buf;
224d6b92ffaSHans Petter Selasky 	int				max_inline_data;
225d6b92ffaSHans Petter Selasky 	int				buf_size;
226d6b92ffaSHans Petter Selasky 
227d6b92ffaSHans Petter Selasky 	uint32_t			doorbell_qpn;
228d6b92ffaSHans Petter Selasky 	uint32_t			sq_signal_bits;
229d6b92ffaSHans Petter Selasky 	int				sq_spare_wqes;
230d6b92ffaSHans Petter Selasky 	struct mlx4_wq			sq;
231d6b92ffaSHans Petter Selasky 
232d6b92ffaSHans Petter Selasky 	uint32_t		       *db;
233d6b92ffaSHans Petter Selasky 	struct mlx4_wq			rq;
234d6b92ffaSHans Petter Selasky 
235d6b92ffaSHans Petter Selasky 	uint8_t				link_layer;
236d6b92ffaSHans Petter Selasky 	uint32_t			qp_cap_cache;
237d6b92ffaSHans Petter Selasky };
238d6b92ffaSHans Petter Selasky 
239d6b92ffaSHans Petter Selasky struct mlx4_av {
240d6b92ffaSHans Petter Selasky 	uint32_t			port_pd;
241d6b92ffaSHans Petter Selasky 	uint8_t				reserved1;
242d6b92ffaSHans Petter Selasky 	uint8_t				g_slid;
243d6b92ffaSHans Petter Selasky 	uint16_t			dlid;
244d6b92ffaSHans Petter Selasky 	uint8_t				reserved2;
245d6b92ffaSHans Petter Selasky 	uint8_t				gid_index;
246d6b92ffaSHans Petter Selasky 	uint8_t				stat_rate;
247d6b92ffaSHans Petter Selasky 	uint8_t				hop_limit;
248d6b92ffaSHans Petter Selasky 	uint32_t			sl_tclass_flowlabel;
249d6b92ffaSHans Petter Selasky 	uint8_t				dgid[16];
250d6b92ffaSHans Petter Selasky };
251d6b92ffaSHans Petter Selasky 
252d6b92ffaSHans Petter Selasky struct mlx4_ah {
253d6b92ffaSHans Petter Selasky 	struct ibv_ah			ibv_ah;
254d6b92ffaSHans Petter Selasky 	struct mlx4_av			av;
255d6b92ffaSHans Petter Selasky 	uint16_t			vlan;
256d6b92ffaSHans Petter Selasky 	uint8_t				mac[6];
257d6b92ffaSHans Petter Selasky };
258d6b92ffaSHans Petter Selasky 
259d6b92ffaSHans Petter Selasky enum {
260d6b92ffaSHans Petter Selasky 	MLX4_CSUM_SUPPORT_UD_OVER_IB	= (1 <<  0),
261d6b92ffaSHans Petter Selasky 	MLX4_CSUM_SUPPORT_RAW_OVER_ETH	= (1 <<  1),
262d6b92ffaSHans Petter Selasky 	/* Only report rx checksum when the validation is valid */
263d6b92ffaSHans Petter Selasky 	MLX4_RX_CSUM_VALID		= (1 <<  16),
264d6b92ffaSHans Petter Selasky };
265d6b92ffaSHans Petter Selasky 
266d6b92ffaSHans Petter Selasky enum mlx4_cqe_status {
267d6b92ffaSHans Petter Selasky 	MLX4_CQE_STATUS_TCP_UDP_CSUM_OK	= (1 <<  2),
268d6b92ffaSHans Petter Selasky 	MLX4_CQE_STATUS_IPV4_PKT	= (1 << 22),
269d6b92ffaSHans Petter Selasky 	MLX4_CQE_STATUS_IP_HDR_CSUM_OK	= (1 << 28),
270d6b92ffaSHans Petter Selasky 	MLX4_CQE_STATUS_IPV4_CSUM_OK	= MLX4_CQE_STATUS_IPV4_PKT |
271d6b92ffaSHans Petter Selasky 					MLX4_CQE_STATUS_IP_HDR_CSUM_OK |
272d6b92ffaSHans Petter Selasky 					MLX4_CQE_STATUS_TCP_UDP_CSUM_OK
273d6b92ffaSHans Petter Selasky };
274d6b92ffaSHans Petter Selasky 
275d6b92ffaSHans Petter Selasky struct mlx4_cqe {
276d6b92ffaSHans Petter Selasky 	uint32_t	vlan_my_qpn;
277d6b92ffaSHans Petter Selasky 	uint32_t	immed_rss_invalid;
278d6b92ffaSHans Petter Selasky 	uint32_t	g_mlpath_rqpn;
279d6b92ffaSHans Petter Selasky 	union {
280d6b92ffaSHans Petter Selasky 		struct {
281d6b92ffaSHans Petter Selasky 			uint16_t	sl_vid;
282d6b92ffaSHans Petter Selasky 			uint16_t	rlid;
283d6b92ffaSHans Petter Selasky 		};
284d6b92ffaSHans Petter Selasky 		uint32_t ts_47_16;
285d6b92ffaSHans Petter Selasky 	};
286d6b92ffaSHans Petter Selasky 	uint32_t	status;
287d6b92ffaSHans Petter Selasky 	uint32_t	byte_cnt;
288d6b92ffaSHans Petter Selasky 	uint16_t	wqe_index;
289d6b92ffaSHans Petter Selasky 	uint16_t	checksum;
290d6b92ffaSHans Petter Selasky 	uint8_t		reserved3;
291d6b92ffaSHans Petter Selasky 	uint8_t		ts_15_8;
292d6b92ffaSHans Petter Selasky 	uint8_t		ts_7_0;
293d6b92ffaSHans Petter Selasky 	uint8_t		owner_sr_opcode;
294d6b92ffaSHans Petter Selasky };
295d6b92ffaSHans Petter Selasky 
align(unsigned long val,unsigned long align)296d6b92ffaSHans Petter Selasky static inline unsigned long align(unsigned long val, unsigned long align)
297d6b92ffaSHans Petter Selasky {
298d6b92ffaSHans Petter Selasky 	return (val + align - 1) & ~(align - 1);
299d6b92ffaSHans Petter Selasky }
300d6b92ffaSHans Petter Selasky int align_queue_size(int req);
301d6b92ffaSHans Petter Selasky 
302d6b92ffaSHans Petter Selasky #define to_mxxx(xxx, type)						\
303d6b92ffaSHans Petter Selasky 	((struct mlx4_##type *)					\
304d6b92ffaSHans Petter Selasky 	 ((void *) ib##xxx - offsetof(struct mlx4_##type, ibv_##xxx)))
305d6b92ffaSHans Petter Selasky 
to_mdev(struct ibv_device * ibdev)306d6b92ffaSHans Petter Selasky static inline struct mlx4_device *to_mdev(struct ibv_device *ibdev)
307d6b92ffaSHans Petter Selasky {
308d6b92ffaSHans Petter Selasky 	/* ibv_device is first field of verbs_device
309d6b92ffaSHans Petter Selasky 	 * see try_driver() in libibverbs.
310d6b92ffaSHans Petter Selasky 	 */
311d6b92ffaSHans Petter Selasky 	return container_of(ibdev, struct mlx4_device, verbs_dev);
312d6b92ffaSHans Petter Selasky }
313d6b92ffaSHans Petter Selasky 
to_mctx(struct ibv_context * ibctx)314d6b92ffaSHans Petter Selasky static inline struct mlx4_context *to_mctx(struct ibv_context *ibctx)
315d6b92ffaSHans Petter Selasky {
316d6b92ffaSHans Petter Selasky 	return to_mxxx(ctx, context);
317d6b92ffaSHans Petter Selasky }
318d6b92ffaSHans Petter Selasky 
to_mpd(struct ibv_pd * ibpd)319d6b92ffaSHans Petter Selasky static inline struct mlx4_pd *to_mpd(struct ibv_pd *ibpd)
320d6b92ffaSHans Petter Selasky {
321d6b92ffaSHans Petter Selasky 	return to_mxxx(pd, pd);
322d6b92ffaSHans Petter Selasky }
323d6b92ffaSHans Petter Selasky 
to_mcq(struct ibv_cq * ibcq)324d6b92ffaSHans Petter Selasky static inline struct mlx4_cq *to_mcq(struct ibv_cq *ibcq)
325d6b92ffaSHans Petter Selasky {
326d6b92ffaSHans Petter Selasky 	return to_mxxx(cq, cq);
327d6b92ffaSHans Petter Selasky }
328d6b92ffaSHans Petter Selasky 
to_msrq(struct ibv_srq * ibsrq)329d6b92ffaSHans Petter Selasky static inline struct mlx4_srq *to_msrq(struct ibv_srq *ibsrq)
330d6b92ffaSHans Petter Selasky {
331d6b92ffaSHans Petter Selasky 	return container_of(container_of(ibsrq, struct verbs_srq, srq),
332d6b92ffaSHans Petter Selasky 			    struct mlx4_srq, verbs_srq);
333d6b92ffaSHans Petter Selasky }
334d6b92ffaSHans Petter Selasky 
to_mqp(struct ibv_qp * ibqp)335d6b92ffaSHans Petter Selasky static inline struct mlx4_qp *to_mqp(struct ibv_qp *ibqp)
336d6b92ffaSHans Petter Selasky {
337d6b92ffaSHans Petter Selasky 	return container_of(container_of(ibqp, struct verbs_qp, qp),
338d6b92ffaSHans Petter Selasky 			    struct mlx4_qp, verbs_qp);
339d6b92ffaSHans Petter Selasky }
340d6b92ffaSHans Petter Selasky 
to_mah(struct ibv_ah * ibah)341d6b92ffaSHans Petter Selasky static inline struct mlx4_ah *to_mah(struct ibv_ah *ibah)
342d6b92ffaSHans Petter Selasky {
343d6b92ffaSHans Petter Selasky 	return to_mxxx(ah, ah);
344d6b92ffaSHans Petter Selasky }
345d6b92ffaSHans Petter Selasky 
mlx4_update_cons_index(struct mlx4_cq * cq)346d6b92ffaSHans Petter Selasky static inline void mlx4_update_cons_index(struct mlx4_cq *cq)
347d6b92ffaSHans Petter Selasky {
348d6b92ffaSHans Petter Selasky 	*cq->set_ci_db = htobe32(cq->cons_index & 0xffffff);
349d6b92ffaSHans Petter Selasky }
350d6b92ffaSHans Petter Selasky 
351d6b92ffaSHans Petter Selasky int mlx4_alloc_buf(struct mlx4_buf *buf, size_t size, int page_size);
352d6b92ffaSHans Petter Selasky void mlx4_free_buf(struct mlx4_buf *buf);
353d6b92ffaSHans Petter Selasky 
354d6b92ffaSHans Petter Selasky uint32_t *mlx4_alloc_db(struct mlx4_context *context, enum mlx4_db_type type);
355d6b92ffaSHans Petter Selasky void mlx4_free_db(struct mlx4_context *context, enum mlx4_db_type type, uint32_t *db);
356d6b92ffaSHans Petter Selasky 
357d6b92ffaSHans Petter Selasky int mlx4_query_device(struct ibv_context *context,
358d6b92ffaSHans Petter Selasky 		       struct ibv_device_attr *attr);
359d6b92ffaSHans Petter Selasky int mlx4_query_device_ex(struct ibv_context *context,
360d6b92ffaSHans Petter Selasky 			 const struct ibv_query_device_ex_input *input,
361d6b92ffaSHans Petter Selasky 			 struct ibv_device_attr_ex *attr,
362d6b92ffaSHans Petter Selasky 			 size_t attr_size);
363d6b92ffaSHans Petter Selasky int mlx4_query_port(struct ibv_context *context, uint8_t port,
364d6b92ffaSHans Petter Selasky 		     struct ibv_port_attr *attr);
365d6b92ffaSHans Petter Selasky int mlx4_query_rt_values(struct ibv_context *context,
366d6b92ffaSHans Petter Selasky 			 struct ibv_values_ex *values);
367d6b92ffaSHans Petter Selasky struct ibv_pd *mlx4_alloc_pd(struct ibv_context *context);
368d6b92ffaSHans Petter Selasky int mlx4_free_pd(struct ibv_pd *pd);
369d6b92ffaSHans Petter Selasky struct ibv_xrcd *mlx4_open_xrcd(struct ibv_context *context,
370d6b92ffaSHans Petter Selasky 				struct ibv_xrcd_init_attr *attr);
371d6b92ffaSHans Petter Selasky int mlx4_close_xrcd(struct ibv_xrcd *xrcd);
372d6b92ffaSHans Petter Selasky 
373d6b92ffaSHans Petter Selasky struct ibv_mr *mlx4_reg_mr(struct ibv_pd *pd, void *addr,
374d6b92ffaSHans Petter Selasky 			    size_t length, int access);
375d6b92ffaSHans Petter Selasky int mlx4_rereg_mr(struct ibv_mr *mr, int flags, struct ibv_pd *pd,
376d6b92ffaSHans Petter Selasky 		  void *addr, size_t length, int access);
377d6b92ffaSHans Petter Selasky int mlx4_dereg_mr(struct ibv_mr *mr);
378d6b92ffaSHans Petter Selasky 
379d6b92ffaSHans Petter Selasky struct ibv_mw *mlx4_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type);
380d6b92ffaSHans Petter Selasky int mlx4_dealloc_mw(struct ibv_mw *mw);
381d6b92ffaSHans Petter Selasky int mlx4_bind_mw(struct ibv_qp *qp, struct ibv_mw *mw,
382d6b92ffaSHans Petter Selasky 		 struct ibv_mw_bind *mw_bind);
383d6b92ffaSHans Petter Selasky 
384d6b92ffaSHans Petter Selasky struct ibv_cq *mlx4_create_cq(struct ibv_context *context, int cqe,
385d6b92ffaSHans Petter Selasky 			       struct ibv_comp_channel *channel,
386d6b92ffaSHans Petter Selasky 			       int comp_vector);
387d6b92ffaSHans Petter Selasky struct ibv_cq_ex *mlx4_create_cq_ex(struct ibv_context *context,
388d6b92ffaSHans Petter Selasky 				    struct ibv_cq_init_attr_ex *cq_attr);
389d6b92ffaSHans Petter Selasky void mlx4_cq_fill_pfns(struct mlx4_cq *cq, const struct ibv_cq_init_attr_ex *cq_attr);
390d6b92ffaSHans Petter Selasky int mlx4_alloc_cq_buf(struct mlx4_device *dev, struct mlx4_buf *buf, int nent,
391d6b92ffaSHans Petter Selasky 		      int entry_size);
392d6b92ffaSHans Petter Selasky int mlx4_resize_cq(struct ibv_cq *cq, int cqe);
393d6b92ffaSHans Petter Selasky int mlx4_destroy_cq(struct ibv_cq *cq);
394d6b92ffaSHans Petter Selasky int mlx4_poll_cq(struct ibv_cq *cq, int ne, struct ibv_wc *wc);
395d6b92ffaSHans Petter Selasky int mlx4_arm_cq(struct ibv_cq *cq, int solicited);
396d6b92ffaSHans Petter Selasky void mlx4_cq_event(struct ibv_cq *cq);
397d6b92ffaSHans Petter Selasky void __mlx4_cq_clean(struct mlx4_cq *cq, uint32_t qpn, struct mlx4_srq *srq);
398d6b92ffaSHans Petter Selasky void mlx4_cq_clean(struct mlx4_cq *cq, uint32_t qpn, struct mlx4_srq *srq);
399d6b92ffaSHans Petter Selasky int mlx4_get_outstanding_cqes(struct mlx4_cq *cq);
400d6b92ffaSHans Petter Selasky void mlx4_cq_resize_copy_cqes(struct mlx4_cq *cq, void *buf, int new_cqe);
401d6b92ffaSHans Petter Selasky 
402d6b92ffaSHans Petter Selasky struct ibv_srq *mlx4_create_srq(struct ibv_pd *pd,
403d6b92ffaSHans Petter Selasky 				 struct ibv_srq_init_attr *attr);
404d6b92ffaSHans Petter Selasky struct ibv_srq *mlx4_create_srq_ex(struct ibv_context *context,
405d6b92ffaSHans Petter Selasky 				   struct ibv_srq_init_attr_ex *attr_ex);
406d6b92ffaSHans Petter Selasky struct ibv_srq *mlx4_create_xrc_srq(struct ibv_context *context,
407d6b92ffaSHans Petter Selasky 				    struct ibv_srq_init_attr_ex *attr_ex);
408d6b92ffaSHans Petter Selasky int mlx4_modify_srq(struct ibv_srq *srq,
409d6b92ffaSHans Petter Selasky 		     struct ibv_srq_attr *attr,
410d6b92ffaSHans Petter Selasky 		     int mask);
411d6b92ffaSHans Petter Selasky int mlx4_query_srq(struct ibv_srq *srq,
412d6b92ffaSHans Petter Selasky 			   struct ibv_srq_attr *attr);
413d6b92ffaSHans Petter Selasky int mlx4_destroy_srq(struct ibv_srq *srq);
414d6b92ffaSHans Petter Selasky int mlx4_destroy_xrc_srq(struct ibv_srq *srq);
415d6b92ffaSHans Petter Selasky int mlx4_alloc_srq_buf(struct ibv_pd *pd, struct ibv_srq_attr *attr,
416d6b92ffaSHans Petter Selasky 			struct mlx4_srq *srq);
417*a687910fSSean Lim void mlx4_cleanup_xsrq_table(struct mlx4_xsrq_table *xsrq_table);
418*a687910fSSean Lim int mlx4_init_xsrq_table(struct mlx4_xsrq_table *xsrq_table, int size);
419d6b92ffaSHans Petter Selasky struct mlx4_srq *mlx4_find_xsrq(struct mlx4_xsrq_table *xsrq_table, uint32_t srqn);
420d6b92ffaSHans Petter Selasky int mlx4_store_xsrq(struct mlx4_xsrq_table *xsrq_table, uint32_t srqn,
421d6b92ffaSHans Petter Selasky 		    struct mlx4_srq *srq);
422d6b92ffaSHans Petter Selasky void mlx4_clear_xsrq(struct mlx4_xsrq_table *xsrq_table, uint32_t srqn);
423d6b92ffaSHans Petter Selasky void mlx4_free_srq_wqe(struct mlx4_srq *srq, int ind);
424d6b92ffaSHans Petter Selasky int mlx4_post_srq_recv(struct ibv_srq *ibsrq,
425d6b92ffaSHans Petter Selasky 		       struct ibv_recv_wr *wr,
426d6b92ffaSHans Petter Selasky 		       struct ibv_recv_wr **bad_wr);
427d6b92ffaSHans Petter Selasky 
428d6b92ffaSHans Petter Selasky struct ibv_qp *mlx4_create_qp(struct ibv_pd *pd, struct ibv_qp_init_attr *attr);
429d6b92ffaSHans Petter Selasky struct ibv_qp *mlx4_create_qp_ex(struct ibv_context *context,
430d6b92ffaSHans Petter Selasky 				 struct ibv_qp_init_attr_ex *attr);
431d6b92ffaSHans Petter Selasky struct ibv_qp *mlx4_open_qp(struct ibv_context *context, struct ibv_qp_open_attr *attr);
432d6b92ffaSHans Petter Selasky int mlx4_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
433d6b92ffaSHans Petter Selasky 		   int attr_mask,
434d6b92ffaSHans Petter Selasky 		   struct ibv_qp_init_attr *init_attr);
435d6b92ffaSHans Petter Selasky int mlx4_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
436d6b92ffaSHans Petter Selasky 		    int attr_mask);
437d6b92ffaSHans Petter Selasky int mlx4_destroy_qp(struct ibv_qp *qp);
438d6b92ffaSHans Petter Selasky void mlx4_init_qp_indices(struct mlx4_qp *qp);
439d6b92ffaSHans Petter Selasky void mlx4_qp_init_sq_ownership(struct mlx4_qp *qp);
440d6b92ffaSHans Petter Selasky int mlx4_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
441d6b92ffaSHans Petter Selasky 			  struct ibv_send_wr **bad_wr);
442d6b92ffaSHans Petter Selasky int mlx4_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr,
443d6b92ffaSHans Petter Selasky 			  struct ibv_recv_wr **bad_wr);
444d6b92ffaSHans Petter Selasky void mlx4_calc_sq_wqe_size(struct ibv_qp_cap *cap, enum ibv_qp_type type,
445d6b92ffaSHans Petter Selasky 			   struct mlx4_qp *qp);
446d6b92ffaSHans Petter Selasky int mlx4_alloc_qp_buf(struct ibv_context *context, struct ibv_qp_cap *cap,
447d6b92ffaSHans Petter Selasky 		       enum ibv_qp_type type, struct mlx4_qp *qp);
448d6b92ffaSHans Petter Selasky void mlx4_set_sq_sizes(struct mlx4_qp *qp, struct ibv_qp_cap *cap,
449d6b92ffaSHans Petter Selasky 		       enum ibv_qp_type type);
450d6b92ffaSHans Petter Selasky struct mlx4_qp *mlx4_find_qp(struct mlx4_context *ctx, uint32_t qpn);
451d6b92ffaSHans Petter Selasky int mlx4_store_qp(struct mlx4_context *ctx, uint32_t qpn, struct mlx4_qp *qp);
452d6b92ffaSHans Petter Selasky void mlx4_clear_qp(struct mlx4_context *ctx, uint32_t qpn);
453d6b92ffaSHans Petter Selasky struct ibv_ah *mlx4_create_ah(struct ibv_pd *pd, struct ibv_ah_attr *attr);
454d6b92ffaSHans Petter Selasky int mlx4_destroy_ah(struct ibv_ah *ah);
455d6b92ffaSHans Petter Selasky int mlx4_alloc_av(struct mlx4_pd *pd, struct ibv_ah_attr *attr,
456d6b92ffaSHans Petter Selasky 		   struct mlx4_ah *ah);
457d6b92ffaSHans Petter Selasky void mlx4_free_av(struct mlx4_ah *ah);
458d6b92ffaSHans Petter Selasky 
459d6b92ffaSHans Petter Selasky #endif /* MLX4_H */
460