xref: /linux/include/linux/mlx5/qp.h (revision 3161625589c1d7c54e949d462f4d0c327664881a)
1e126ba97SEli Cohen /*
2302bdf68SSaeed Mahameed  * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
3e126ba97SEli Cohen  *
4e126ba97SEli Cohen  * This software is available to you under a choice of one of two
5e126ba97SEli Cohen  * licenses.  You may choose to be licensed under the terms of the GNU
6e126ba97SEli Cohen  * General Public License (GPL) Version 2, available from the file
7e126ba97SEli Cohen  * COPYING in the main directory of this source tree, or the
8e126ba97SEli Cohen  * OpenIB.org BSD license below:
9e126ba97SEli Cohen  *
10e126ba97SEli Cohen  *     Redistribution and use in source and binary forms, with or
11e126ba97SEli Cohen  *     without modification, are permitted provided that the following
12e126ba97SEli Cohen  *     conditions are met:
13e126ba97SEli Cohen  *
14e126ba97SEli Cohen  *      - Redistributions of source code must retain the above
15e126ba97SEli Cohen  *        copyright notice, this list of conditions and the following
16e126ba97SEli Cohen  *        disclaimer.
17e126ba97SEli Cohen  *
18e126ba97SEli Cohen  *      - Redistributions in binary form must reproduce the above
19e126ba97SEli Cohen  *        copyright notice, this list of conditions and the following
20e126ba97SEli Cohen  *        disclaimer in the documentation and/or other materials
21e126ba97SEli Cohen  *        provided with the distribution.
22e126ba97SEli Cohen  *
23e126ba97SEli Cohen  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24e126ba97SEli Cohen  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25e126ba97SEli Cohen  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26e126ba97SEli Cohen  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27e126ba97SEli Cohen  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28e126ba97SEli Cohen  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29e126ba97SEli Cohen  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30e126ba97SEli Cohen  * SOFTWARE.
31e126ba97SEli Cohen  */
32e126ba97SEli Cohen 
33e126ba97SEli Cohen #ifndef MLX5_QP_H
34e126ba97SEli Cohen #define MLX5_QP_H
35e126ba97SEli Cohen 
36e126ba97SEli Cohen #include <linux/mlx5/device.h>
37e126ba97SEli Cohen #include <linux/mlx5/driver.h>
38e126ba97SEli Cohen 
39e126ba97SEli Cohen #define MLX5_INVALID_LKEY	0x100
40e1e66cc2SSagi Grimberg #define MLX5_SIG_WQE_SIZE	(MLX5_SEND_WQE_BB * 5)
41e6631814SSagi Grimberg #define MLX5_DIF_SIZE		8
42e6631814SSagi Grimberg #define MLX5_STRIDE_BLOCK_OP	0x400
43fd22f78cSSagi Grimberg #define MLX5_CPY_GRD_MASK	0xc0
44fd22f78cSSagi Grimberg #define MLX5_CPY_APP_MASK	0x30
45fd22f78cSSagi Grimberg #define MLX5_CPY_REF_MASK	0x0f
46142537f4SSagi Grimberg #define MLX5_BSF_INC_REFTAG	(1 << 6)
47142537f4SSagi Grimberg #define MLX5_BSF_INL_VALID	(1 << 15)
48142537f4SSagi Grimberg #define MLX5_BSF_REFRESH_DIF	(1 << 14)
49142537f4SSagi Grimberg #define MLX5_BSF_REPEAT_BLOCK	(1 << 7)
50142537f4SSagi Grimberg #define MLX5_BSF_APPTAG_ESCAPE	0x1
51142537f4SSagi Grimberg #define MLX5_BSF_APPREF_ESCAPE	0x2
52e126ba97SEli Cohen 
53e420f0c0SHaggai Eran #define MLX5_QPN_BITS		24
54e420f0c0SHaggai Eran #define MLX5_QPN_MASK		((1 << MLX5_QPN_BITS) - 1)
55e420f0c0SHaggai Eran 
56e126ba97SEli Cohen enum mlx5_qp_optpar {
57e126ba97SEli Cohen 	MLX5_QP_OPTPAR_ALT_ADDR_PATH		= 1 << 0,
58e126ba97SEli Cohen 	MLX5_QP_OPTPAR_RRE			= 1 << 1,
59e126ba97SEli Cohen 	MLX5_QP_OPTPAR_RAE			= 1 << 2,
60e126ba97SEli Cohen 	MLX5_QP_OPTPAR_RWE			= 1 << 3,
61e126ba97SEli Cohen 	MLX5_QP_OPTPAR_PKEY_INDEX		= 1 << 4,
62e126ba97SEli Cohen 	MLX5_QP_OPTPAR_Q_KEY			= 1 << 5,
63e126ba97SEli Cohen 	MLX5_QP_OPTPAR_RNR_TIMEOUT		= 1 << 6,
64e126ba97SEli Cohen 	MLX5_QP_OPTPAR_PRIMARY_ADDR_PATH	= 1 << 7,
65e126ba97SEli Cohen 	MLX5_QP_OPTPAR_SRA_MAX			= 1 << 8,
66e126ba97SEli Cohen 	MLX5_QP_OPTPAR_RRA_MAX			= 1 << 9,
67e126ba97SEli Cohen 	MLX5_QP_OPTPAR_PM_STATE			= 1 << 10,
68e126ba97SEli Cohen 	MLX5_QP_OPTPAR_RETRY_COUNT		= 1 << 12,
69e126ba97SEli Cohen 	MLX5_QP_OPTPAR_RNR_RETRY		= 1 << 13,
70e126ba97SEli Cohen 	MLX5_QP_OPTPAR_ACK_TIMEOUT		= 1 << 14,
71e126ba97SEli Cohen 	MLX5_QP_OPTPAR_PRI_PORT			= 1 << 16,
72e126ba97SEli Cohen 	MLX5_QP_OPTPAR_SRQN			= 1 << 18,
73e126ba97SEli Cohen 	MLX5_QP_OPTPAR_CQN_RCV			= 1 << 19,
74e126ba97SEli Cohen 	MLX5_QP_OPTPAR_DC_HS			= 1 << 20,
75e126ba97SEli Cohen 	MLX5_QP_OPTPAR_DC_KEY			= 1 << 21,
76e126ba97SEli Cohen };
77e126ba97SEli Cohen 
78e126ba97SEli Cohen enum mlx5_qp_state {
79e126ba97SEli Cohen 	MLX5_QP_STATE_RST			= 0,
80e126ba97SEli Cohen 	MLX5_QP_STATE_INIT			= 1,
81e126ba97SEli Cohen 	MLX5_QP_STATE_RTR			= 2,
82e126ba97SEli Cohen 	MLX5_QP_STATE_RTS			= 3,
83e126ba97SEli Cohen 	MLX5_QP_STATE_SQER			= 4,
84e126ba97SEli Cohen 	MLX5_QP_STATE_SQD			= 5,
85e126ba97SEli Cohen 	MLX5_QP_STATE_ERR			= 6,
86e126ba97SEli Cohen 	MLX5_QP_STATE_SQ_DRAINING		= 7,
87e126ba97SEli Cohen 	MLX5_QP_STATE_SUSPENDED			= 9,
886d2f89dfSmajd@mellanox.com 	MLX5_QP_NUM_STATE,
896d2f89dfSmajd@mellanox.com 	MLX5_QP_STATE,
906d2f89dfSmajd@mellanox.com 	MLX5_QP_STATE_BAD,
916d2f89dfSmajd@mellanox.com };
926d2f89dfSmajd@mellanox.com 
936d2f89dfSmajd@mellanox.com enum {
946d2f89dfSmajd@mellanox.com 	MLX5_SQ_STATE_NA	= MLX5_SQC_STATE_ERR + 1,
956d2f89dfSmajd@mellanox.com 	MLX5_SQ_NUM_STATE	= MLX5_SQ_STATE_NA + 1,
966d2f89dfSmajd@mellanox.com 	MLX5_RQ_STATE_NA	= MLX5_RQC_STATE_ERR + 1,
976d2f89dfSmajd@mellanox.com 	MLX5_RQ_NUM_STATE	= MLX5_RQ_STATE_NA + 1,
98e126ba97SEli Cohen };
99e126ba97SEli Cohen 
100e126ba97SEli Cohen enum {
101e126ba97SEli Cohen 	MLX5_QP_ST_RC				= 0x0,
102e126ba97SEli Cohen 	MLX5_QP_ST_UC				= 0x1,
103e126ba97SEli Cohen 	MLX5_QP_ST_UD				= 0x2,
104e126ba97SEli Cohen 	MLX5_QP_ST_XRC				= 0x3,
105e126ba97SEli Cohen 	MLX5_QP_ST_MLX				= 0x4,
106e126ba97SEli Cohen 	MLX5_QP_ST_DCI				= 0x5,
107e126ba97SEli Cohen 	MLX5_QP_ST_DCT				= 0x6,
108e126ba97SEli Cohen 	MLX5_QP_ST_QP0				= 0x7,
109e126ba97SEli Cohen 	MLX5_QP_ST_QP1				= 0x8,
110e126ba97SEli Cohen 	MLX5_QP_ST_RAW_ETHERTYPE		= 0x9,
111e126ba97SEli Cohen 	MLX5_QP_ST_RAW_IPV6			= 0xa,
112e126ba97SEli Cohen 	MLX5_QP_ST_SNIFFER			= 0xb,
113e126ba97SEli Cohen 	MLX5_QP_ST_SYNC_UMR			= 0xe,
114e126ba97SEli Cohen 	MLX5_QP_ST_PTP_1588			= 0xd,
115e126ba97SEli Cohen 	MLX5_QP_ST_REG_UMR			= 0xc,
116e126ba97SEli Cohen 	MLX5_QP_ST_MAX
117e126ba97SEli Cohen };
118e126ba97SEli Cohen 
119e126ba97SEli Cohen enum {
120e126ba97SEli Cohen 	MLX5_QP_PM_MIGRATED			= 0x3,
121e126ba97SEli Cohen 	MLX5_QP_PM_ARMED			= 0x0,
122e126ba97SEli Cohen 	MLX5_QP_PM_REARM			= 0x1
123e126ba97SEli Cohen };
124e126ba97SEli Cohen 
125e126ba97SEli Cohen enum {
12609a7d9ecSSaeed Mahameed 	MLX5_NON_ZERO_RQ	= 0x0,
12709a7d9ecSSaeed Mahameed 	MLX5_SRQ_RQ		= 0x1,
12809a7d9ecSSaeed Mahameed 	MLX5_CRQ_RQ		= 0x2,
12909a7d9ecSSaeed Mahameed 	MLX5_ZERO_LEN_RQ	= 0x3
130e126ba97SEli Cohen };
131e126ba97SEli Cohen 
13209a7d9ecSSaeed Mahameed /* TODO REM */
133e126ba97SEli Cohen enum {
134e126ba97SEli Cohen 	/* params1 */
135e126ba97SEli Cohen 	MLX5_QP_BIT_SRE				= 1 << 15,
136e126ba97SEli Cohen 	MLX5_QP_BIT_SWE				= 1 << 14,
137e126ba97SEli Cohen 	MLX5_QP_BIT_SAE				= 1 << 13,
138e126ba97SEli Cohen 	/* params2 */
139e126ba97SEli Cohen 	MLX5_QP_BIT_RRE				= 1 << 15,
140e126ba97SEli Cohen 	MLX5_QP_BIT_RWE				= 1 << 14,
141e126ba97SEli Cohen 	MLX5_QP_BIT_RAE				= 1 << 13,
142e126ba97SEli Cohen 	MLX5_QP_BIT_RIC				= 1 <<	4,
143051f2630SLeon Romanovsky 	MLX5_QP_BIT_CC_SLAVE_RECV		= 1 <<  2,
144051f2630SLeon Romanovsky 	MLX5_QP_BIT_CC_SLAVE_SEND		= 1 <<  1,
145051f2630SLeon Romanovsky 	MLX5_QP_BIT_CC_MASTER			= 1 <<  0
146e126ba97SEli Cohen };
147e126ba97SEli Cohen 
148e126ba97SEli Cohen enum {
149e126ba97SEli Cohen 	MLX5_WQE_CTRL_CQ_UPDATE		= 2 << 2,
150e281682bSSaeed Mahameed 	MLX5_WQE_CTRL_CQ_UPDATE_AND_EQE	= 3 << 2,
151e126ba97SEli Cohen 	MLX5_WQE_CTRL_SOLICITED		= 1 << 1,
152e126ba97SEli Cohen };
153e126ba97SEli Cohen 
154e126ba97SEli Cohen enum {
155e281682bSSaeed Mahameed 	MLX5_SEND_WQE_DS	= 16,
156e126ba97SEli Cohen 	MLX5_SEND_WQE_BB	= 64,
157e126ba97SEli Cohen };
158e126ba97SEli Cohen 
159e281682bSSaeed Mahameed #define MLX5_SEND_WQEBB_NUM_DS	(MLX5_SEND_WQE_BB / MLX5_SEND_WQE_DS)
160e281682bSSaeed Mahameed 
161e281682bSSaeed Mahameed enum {
162e281682bSSaeed Mahameed 	MLX5_SEND_WQE_MAX_WQEBBS	= 16,
163e281682bSSaeed Mahameed };
164e281682bSSaeed Mahameed 
165e126ba97SEli Cohen enum {
166e126ba97SEli Cohen 	MLX5_WQE_FMR_PERM_LOCAL_READ	= 1 << 27,
167e126ba97SEli Cohen 	MLX5_WQE_FMR_PERM_LOCAL_WRITE	= 1 << 28,
168e126ba97SEli Cohen 	MLX5_WQE_FMR_PERM_REMOTE_READ	= 1 << 29,
169e126ba97SEli Cohen 	MLX5_WQE_FMR_PERM_REMOTE_WRITE	= 1 << 30,
170e126ba97SEli Cohen 	MLX5_WQE_FMR_PERM_ATOMIC	= 1 << 31
171e126ba97SEli Cohen };
172e126ba97SEli Cohen 
173e126ba97SEli Cohen enum {
174e126ba97SEli Cohen 	MLX5_FENCE_MODE_NONE			= 0 << 5,
175e126ba97SEli Cohen 	MLX5_FENCE_MODE_INITIATOR_SMALL		= 1 << 5,
176c9b25495SEli Cohen 	MLX5_FENCE_MODE_FENCE			= 2 << 5,
177e126ba97SEli Cohen 	MLX5_FENCE_MODE_STRONG_ORDERING		= 3 << 5,
178e126ba97SEli Cohen 	MLX5_FENCE_MODE_SMALL_AND_FENCE		= 4 << 5,
179e126ba97SEli Cohen };
180e126ba97SEli Cohen 
181e126ba97SEli Cohen enum {
182e126ba97SEli Cohen 	MLX5_RCV_DBR	= 0,
183e126ba97SEli Cohen 	MLX5_SND_DBR	= 1,
184e126ba97SEli Cohen };
185e126ba97SEli Cohen 
186e6631814SSagi Grimberg enum {
187e6631814SSagi Grimberg 	MLX5_FLAGS_INLINE	= 1<<7,
188e6631814SSagi Grimberg 	MLX5_FLAGS_CHECK_FREE   = 1<<5,
189e6631814SSagi Grimberg };
190e6631814SSagi Grimberg 
191e126ba97SEli Cohen struct mlx5_wqe_fmr_seg {
192e126ba97SEli Cohen 	__be32			flags;
193e126ba97SEli Cohen 	__be32			mem_key;
194e126ba97SEli Cohen 	__be64			buf_list;
195e126ba97SEli Cohen 	__be64			start_addr;
196e126ba97SEli Cohen 	__be64			reg_len;
197e126ba97SEli Cohen 	__be32			offset;
198e126ba97SEli Cohen 	__be32			page_size;
199e126ba97SEli Cohen 	u32			reserved[2];
200e126ba97SEli Cohen };
201e126ba97SEli Cohen 
202e126ba97SEli Cohen struct mlx5_wqe_ctrl_seg {
203e126ba97SEli Cohen 	__be32			opmod_idx_opcode;
204e126ba97SEli Cohen 	__be32			qpn_ds;
205e126ba97SEli Cohen 	u8			signature;
206e126ba97SEli Cohen 	u8			rsvd[2];
207e126ba97SEli Cohen 	u8			fm_ce_se;
208e126ba97SEli Cohen 	__be32			imm;
209e126ba97SEli Cohen };
210e126ba97SEli Cohen 
211c1395a2aSHaggai Eran #define MLX5_WQE_CTRL_DS_MASK 0x3f
2127bdf65d4SHaggai Eran #define MLX5_WQE_CTRL_QPN_MASK 0xffffff00
2137bdf65d4SHaggai Eran #define MLX5_WQE_CTRL_QPN_SHIFT 8
214c1395a2aSHaggai Eran #define MLX5_WQE_DS_UNITS 16
2157bdf65d4SHaggai Eran #define MLX5_WQE_CTRL_OPCODE_MASK 0xff
2167bdf65d4SHaggai Eran #define MLX5_WQE_CTRL_WQE_INDEX_MASK 0x00ffff00
2177bdf65d4SHaggai Eran #define MLX5_WQE_CTRL_WQE_INDEX_SHIFT 8
218c1395a2aSHaggai Eran 
219e281682bSSaeed Mahameed enum {
220e281682bSSaeed Mahameed 	MLX5_ETH_WQE_L3_INNER_CSUM      = 1 << 4,
221e281682bSSaeed Mahameed 	MLX5_ETH_WQE_L4_INNER_CSUM      = 1 << 5,
222e281682bSSaeed Mahameed 	MLX5_ETH_WQE_L3_CSUM            = 1 << 6,
223e281682bSSaeed Mahameed 	MLX5_ETH_WQE_L4_CSUM            = 1 << 7,
224e281682bSSaeed Mahameed };
225e281682bSSaeed Mahameed 
226e281682bSSaeed Mahameed struct mlx5_wqe_eth_seg {
227e281682bSSaeed Mahameed 	u8              rsvd0[4];
228e281682bSSaeed Mahameed 	u8              cs_flags;
229e281682bSSaeed Mahameed 	u8              rsvd1;
230e281682bSSaeed Mahameed 	__be16          mss;
231e281682bSSaeed Mahameed 	__be32          rsvd2;
232e281682bSSaeed Mahameed 	__be16          inline_hdr_sz;
233e281682bSSaeed Mahameed 	u8              inline_hdr_start[2];
234e281682bSSaeed Mahameed };
235e281682bSSaeed Mahameed 
236e126ba97SEli Cohen struct mlx5_wqe_xrc_seg {
237e126ba97SEli Cohen 	__be32			xrc_srqn;
238e126ba97SEli Cohen 	u8			rsvd[12];
239e126ba97SEli Cohen };
240e126ba97SEli Cohen 
241e126ba97SEli Cohen struct mlx5_wqe_masked_atomic_seg {
242e126ba97SEli Cohen 	__be64			swap_add;
243e126ba97SEli Cohen 	__be64			compare;
244e126ba97SEli Cohen 	__be64			swap_add_mask;
245e126ba97SEli Cohen 	__be64			compare_mask;
246e126ba97SEli Cohen };
247e126ba97SEli Cohen 
248e126ba97SEli Cohen struct mlx5_av {
249e126ba97SEli Cohen 	union {
250e126ba97SEli Cohen 		struct {
251e126ba97SEli Cohen 			__be32	qkey;
252e126ba97SEli Cohen 			__be32	reserved;
253e126ba97SEli Cohen 		} qkey;
254e126ba97SEli Cohen 		__be64	dc_key;
255e126ba97SEli Cohen 	} key;
256e126ba97SEli Cohen 	__be32	dqp_dct;
257e126ba97SEli Cohen 	u8	stat_rate_sl;
258e126ba97SEli Cohen 	u8	fl_mlid;
2592811ba51SAchiad Shochat 	union {
260e126ba97SEli Cohen 		__be16	rlid;
2612811ba51SAchiad Shochat 		__be16  udp_sport;
2622811ba51SAchiad Shochat 	};
2632811ba51SAchiad Shochat 	u8	reserved0[4];
2642811ba51SAchiad Shochat 	u8	rmac[6];
265e126ba97SEli Cohen 	u8	tclass;
266e126ba97SEli Cohen 	u8	hop_limit;
267e126ba97SEli Cohen 	__be32	grh_gid_fl;
268e126ba97SEli Cohen 	u8	rgid[16];
269e126ba97SEli Cohen };
270e126ba97SEli Cohen 
271e126ba97SEli Cohen struct mlx5_wqe_datagram_seg {
272e126ba97SEli Cohen 	struct mlx5_av	av;
273e126ba97SEli Cohen };
274e126ba97SEli Cohen 
275e126ba97SEli Cohen struct mlx5_wqe_raddr_seg {
276e126ba97SEli Cohen 	__be64			raddr;
277e126ba97SEli Cohen 	__be32			rkey;
278e126ba97SEli Cohen 	u32			reserved;
279e126ba97SEli Cohen };
280e126ba97SEli Cohen 
281e126ba97SEli Cohen struct mlx5_wqe_atomic_seg {
282e126ba97SEli Cohen 	__be64			swap_add;
283e126ba97SEli Cohen 	__be64			compare;
284e126ba97SEli Cohen };
285e126ba97SEli Cohen 
286e126ba97SEli Cohen struct mlx5_wqe_data_seg {
287e126ba97SEli Cohen 	__be32			byte_count;
288e126ba97SEli Cohen 	__be32			lkey;
289e126ba97SEli Cohen 	__be64			addr;
290e126ba97SEli Cohen };
291e126ba97SEli Cohen 
292e126ba97SEli Cohen struct mlx5_wqe_umr_ctrl_seg {
293e126ba97SEli Cohen 	u8		flags;
294e126ba97SEli Cohen 	u8		rsvd0[3];
295*31616255SArtemy Kovalyov 	__be16		xlt_octowords;
296*31616255SArtemy Kovalyov 	union {
297*31616255SArtemy Kovalyov 		__be16	xlt_offset;
298e126ba97SEli Cohen 		__be16	bsf_octowords;
299*31616255SArtemy Kovalyov 	};
300e126ba97SEli Cohen 	__be64		mkey_mask;
301*31616255SArtemy Kovalyov 	__be32		xlt_offset_47_16;
302*31616255SArtemy Kovalyov 	u8		rsvd1[28];
303e126ba97SEli Cohen };
304e126ba97SEli Cohen 
305e126ba97SEli Cohen struct mlx5_seg_set_psv {
306e126ba97SEli Cohen 	__be32		psv_num;
307e126ba97SEli Cohen 	__be16		syndrome;
308e126ba97SEli Cohen 	__be16		status;
309e126ba97SEli Cohen 	__be32		transient_sig;
310e126ba97SEli Cohen 	__be32		ref_tag;
311e126ba97SEli Cohen };
312e126ba97SEli Cohen 
313e126ba97SEli Cohen struct mlx5_seg_get_psv {
314e126ba97SEli Cohen 	u8		rsvd[19];
315e126ba97SEli Cohen 	u8		num_psv;
316e126ba97SEli Cohen 	__be32		l_key;
317e126ba97SEli Cohen 	__be64		va;
318e126ba97SEli Cohen 	__be32		psv_index[4];
319e126ba97SEli Cohen };
320e126ba97SEli Cohen 
321e126ba97SEli Cohen struct mlx5_seg_check_psv {
322e126ba97SEli Cohen 	u8		rsvd0[2];
323e126ba97SEli Cohen 	__be16		err_coalescing_op;
324e126ba97SEli Cohen 	u8		rsvd1[2];
325e126ba97SEli Cohen 	__be16		xport_err_op;
326e126ba97SEli Cohen 	u8		rsvd2[2];
327e126ba97SEli Cohen 	__be16		xport_err_mask;
328e126ba97SEli Cohen 	u8		rsvd3[7];
329e126ba97SEli Cohen 	u8		num_psv;
330e126ba97SEli Cohen 	__be32		l_key;
331e126ba97SEli Cohen 	__be64		va;
332e126ba97SEli Cohen 	__be32		psv_index[4];
333e126ba97SEli Cohen };
334e126ba97SEli Cohen 
335e126ba97SEli Cohen struct mlx5_rwqe_sig {
336e126ba97SEli Cohen 	u8	rsvd0[4];
337e126ba97SEli Cohen 	u8	signature;
338e126ba97SEli Cohen 	u8	rsvd1[11];
339e126ba97SEli Cohen };
340e126ba97SEli Cohen 
341e126ba97SEli Cohen struct mlx5_wqe_signature_seg {
342e126ba97SEli Cohen 	u8	rsvd0[4];
343e126ba97SEli Cohen 	u8	signature;
344e126ba97SEli Cohen 	u8	rsvd1[11];
345e126ba97SEli Cohen };
346e126ba97SEli Cohen 
3477bdf65d4SHaggai Eran #define MLX5_WQE_INLINE_SEG_BYTE_COUNT_MASK 0x3ff
3487bdf65d4SHaggai Eran 
349e126ba97SEli Cohen struct mlx5_wqe_inline_seg {
350e126ba97SEli Cohen 	__be32	byte_count;
351e126ba97SEli Cohen };
352e126ba97SEli Cohen 
353142537f4SSagi Grimberg enum mlx5_sig_type {
354142537f4SSagi Grimberg 	MLX5_DIF_CRC = 0x1,
355142537f4SSagi Grimberg 	MLX5_DIF_IPCS = 0x2,
356142537f4SSagi Grimberg };
357142537f4SSagi Grimberg 
358142537f4SSagi Grimberg struct mlx5_bsf_inl {
359142537f4SSagi Grimberg 	__be16		vld_refresh;
360142537f4SSagi Grimberg 	__be16		dif_apptag;
361142537f4SSagi Grimberg 	__be32		dif_reftag;
362142537f4SSagi Grimberg 	u8		sig_type;
363142537f4SSagi Grimberg 	u8		rp_inv_seed;
364142537f4SSagi Grimberg 	u8		rsvd[3];
365142537f4SSagi Grimberg 	u8		dif_inc_ref_guard_check;
366142537f4SSagi Grimberg 	__be16		dif_app_bitmask_check;
367142537f4SSagi Grimberg };
368142537f4SSagi Grimberg 
369e6631814SSagi Grimberg struct mlx5_bsf {
370e6631814SSagi Grimberg 	struct mlx5_bsf_basic {
371e6631814SSagi Grimberg 		u8		bsf_size_sbs;
372e6631814SSagi Grimberg 		u8		check_byte_mask;
373e6631814SSagi Grimberg 		union {
374e6631814SSagi Grimberg 			u8	copy_byte_mask;
375e6631814SSagi Grimberg 			u8	bs_selector;
376e6631814SSagi Grimberg 			u8	rsvd_wflags;
377e6631814SSagi Grimberg 		} wire;
378e6631814SSagi Grimberg 		union {
379e6631814SSagi Grimberg 			u8	bs_selector;
380e6631814SSagi Grimberg 			u8	rsvd_mflags;
381e6631814SSagi Grimberg 		} mem;
382e6631814SSagi Grimberg 		__be32		raw_data_size;
383e6631814SSagi Grimberg 		__be32		w_bfs_psv;
384e6631814SSagi Grimberg 		__be32		m_bfs_psv;
385e6631814SSagi Grimberg 	} basic;
386e6631814SSagi Grimberg 	struct mlx5_bsf_ext {
387e6631814SSagi Grimberg 		__be32		t_init_gen_pro_size;
388e6631814SSagi Grimberg 		__be32		rsvd_epi_size;
389e6631814SSagi Grimberg 		__be32		w_tfs_psv;
390e6631814SSagi Grimberg 		__be32		m_tfs_psv;
391e6631814SSagi Grimberg 	} ext;
392142537f4SSagi Grimberg 	struct mlx5_bsf_inl	w_inl;
393142537f4SSagi Grimberg 	struct mlx5_bsf_inl	m_inl;
394e6631814SSagi Grimberg };
395e6631814SSagi Grimberg 
396*31616255SArtemy Kovalyov struct mlx5_mtt {
397*31616255SArtemy Kovalyov 	__be64		ptag;
398*31616255SArtemy Kovalyov };
399*31616255SArtemy Kovalyov 
400e6631814SSagi Grimberg struct mlx5_klm {
401e6631814SSagi Grimberg 	__be32		bcount;
402e6631814SSagi Grimberg 	__be32		key;
403e6631814SSagi Grimberg 	__be64		va;
404e6631814SSagi Grimberg };
405e6631814SSagi Grimberg 
406e6631814SSagi Grimberg struct mlx5_stride_block_entry {
407e6631814SSagi Grimberg 	__be16		stride;
408e6631814SSagi Grimberg 	__be16		bcount;
409e6631814SSagi Grimberg 	__be32		key;
410e6631814SSagi Grimberg 	__be64		va;
411e6631814SSagi Grimberg };
412e6631814SSagi Grimberg 
413e6631814SSagi Grimberg struct mlx5_stride_block_ctrl_seg {
414e6631814SSagi Grimberg 	__be32		bcount_per_cycle;
415e6631814SSagi Grimberg 	__be32		op;
416e6631814SSagi Grimberg 	__be32		repeat_count;
417e6631814SSagi Grimberg 	u16		rsvd;
418e6631814SSagi Grimberg 	__be16		num_entries;
419e6631814SSagi Grimberg };
420e6631814SSagi Grimberg 
421e420f0c0SHaggai Eran enum mlx5_pagefault_flags {
422e420f0c0SHaggai Eran 	MLX5_PFAULT_REQUESTOR = 1 << 0,
423e420f0c0SHaggai Eran 	MLX5_PFAULT_WRITE     = 1 << 1,
424e420f0c0SHaggai Eran 	MLX5_PFAULT_RDMA      = 1 << 2,
425e420f0c0SHaggai Eran };
426e420f0c0SHaggai Eran 
427e420f0c0SHaggai Eran /* Contains the details of a pagefault. */
428e420f0c0SHaggai Eran struct mlx5_pagefault {
429e420f0c0SHaggai Eran 	u32			bytes_committed;
430e420f0c0SHaggai Eran 	u8			event_subtype;
431e420f0c0SHaggai Eran 	enum mlx5_pagefault_flags flags;
432e420f0c0SHaggai Eran 	union {
433e420f0c0SHaggai Eran 		/* Initiator or send message responder pagefault details. */
434e420f0c0SHaggai Eran 		struct {
435e420f0c0SHaggai Eran 			/* Received packet size, only valid for responders. */
436e420f0c0SHaggai Eran 			u32	packet_size;
437e420f0c0SHaggai Eran 			/*
438e420f0c0SHaggai Eran 			 * WQE index. Refers to either the send queue or
439e420f0c0SHaggai Eran 			 * receive queue, according to event_subtype.
440e420f0c0SHaggai Eran 			 */
441e420f0c0SHaggai Eran 			u16	wqe_index;
442e420f0c0SHaggai Eran 		} wqe;
443e420f0c0SHaggai Eran 		/* RDMA responder pagefault details */
444e420f0c0SHaggai Eran 		struct {
445e420f0c0SHaggai Eran 			u32	r_key;
446e420f0c0SHaggai Eran 			/*
447e420f0c0SHaggai Eran 			 * Received packet size, minimal size page fault
448e420f0c0SHaggai Eran 			 * resolution required for forward progress.
449e420f0c0SHaggai Eran 			 */
450e420f0c0SHaggai Eran 			u32	packet_size;
451e420f0c0SHaggai Eran 			u32	rdma_op_len;
452e420f0c0SHaggai Eran 			u64	rdma_va;
453e420f0c0SHaggai Eran 		} rdma;
454e420f0c0SHaggai Eran 	};
455e420f0c0SHaggai Eran };
456e420f0c0SHaggai Eran 
457e126ba97SEli Cohen struct mlx5_core_qp {
4585903325aSEli Cohen 	struct mlx5_core_rsc_common	common; /* must be first */
459e126ba97SEli Cohen 	void (*event)		(struct mlx5_core_qp *, int);
460e420f0c0SHaggai Eran 	void (*pfault_handler)(struct mlx5_core_qp *, struct mlx5_pagefault *);
461e126ba97SEli Cohen 	int			qpn;
462e126ba97SEli Cohen 	struct mlx5_rsc_debug	*dbg;
463e126ba97SEli Cohen 	int			pid;
464e126ba97SEli Cohen };
465e126ba97SEli Cohen 
466e126ba97SEli Cohen struct mlx5_qp_path {
467d3ae2bdeSNoa Osherovich 	u8			fl_free_ar;
468e126ba97SEli Cohen 	u8			rsvd3;
469d3ae2bdeSNoa Osherovich 	__be16			pkey_index;
470e126ba97SEli Cohen 	u8			rsvd0;
471e126ba97SEli Cohen 	u8			grh_mlid;
472e126ba97SEli Cohen 	__be16			rlid;
473e126ba97SEli Cohen 	u8			ackto_lt;
474e126ba97SEli Cohen 	u8			mgid_index;
475e126ba97SEli Cohen 	u8			static_rate;
476e126ba97SEli Cohen 	u8			hop_limit;
477e126ba97SEli Cohen 	__be32			tclass_flowlabel;
4782811ba51SAchiad Shochat 	union {
479e126ba97SEli Cohen 		u8		rgid[16];
4802811ba51SAchiad Shochat 		u8		rip[16];
4812811ba51SAchiad Shochat 	};
4822811ba51SAchiad Shochat 	u8			f_dscp_ecn_prio;
4832811ba51SAchiad Shochat 	u8			ecn_dscp;
4842811ba51SAchiad Shochat 	__be16			udp_sport;
4852811ba51SAchiad Shochat 	u8			dci_cfi_prio_sl;
486e126ba97SEli Cohen 	u8			port;
4872811ba51SAchiad Shochat 	u8			rmac[6];
488e126ba97SEli Cohen };
489e126ba97SEli Cohen 
4901a412fb1SSaeed Mahameed /* FIXME: use mlx5_ifc.h qpc */
491e126ba97SEli Cohen struct mlx5_qp_context {
492e126ba97SEli Cohen 	__be32			flags;
493e126ba97SEli Cohen 	__be32			flags_pd;
494e126ba97SEli Cohen 	u8			mtu_msgmax;
495e126ba97SEli Cohen 	u8			rq_size_stride;
496e126ba97SEli Cohen 	__be16			sq_crq_size;
497e126ba97SEli Cohen 	__be32			qp_counter_set_usr_page;
498e126ba97SEli Cohen 	__be32			wire_qpn;
499e126ba97SEli Cohen 	__be32			log_pg_sz_remote_qpn;
500e126ba97SEli Cohen 	struct			mlx5_qp_path pri_path;
501e126ba97SEli Cohen 	struct			mlx5_qp_path alt_path;
502e126ba97SEli Cohen 	__be32			params1;
503e126ba97SEli Cohen 	u8			reserved2[4];
504e126ba97SEli Cohen 	__be32			next_send_psn;
505e126ba97SEli Cohen 	__be32			cqn_send;
506b11a4f9cSHaggai Eran 	__be32			deth_sqpn;
507b11a4f9cSHaggai Eran 	u8			reserved3[4];
508e126ba97SEli Cohen 	__be32			last_acked_psn;
509e126ba97SEli Cohen 	__be32			ssn;
510e126ba97SEli Cohen 	__be32			params2;
511e126ba97SEli Cohen 	__be32			rnr_nextrecvpsn;
512e126ba97SEli Cohen 	__be32			xrcd;
513e126ba97SEli Cohen 	__be32			cqn_recv;
514e126ba97SEli Cohen 	__be64			db_rec_addr;
515e126ba97SEli Cohen 	__be32			qkey;
516e126ba97SEli Cohen 	__be32			rq_type_srqn;
517e126ba97SEli Cohen 	__be32			rmsn;
518e126ba97SEli Cohen 	__be16			hw_sq_wqe_counter;
519e126ba97SEli Cohen 	__be16			sw_sq_wqe_counter;
520e126ba97SEli Cohen 	__be16			hw_rcyclic_byte_counter;
521e126ba97SEli Cohen 	__be16			hw_rq_counter;
522e126ba97SEli Cohen 	__be16			sw_rcyclic_byte_counter;
523e126ba97SEli Cohen 	__be16			sw_rq_counter;
524e126ba97SEli Cohen 	u8			rsvd0[5];
525e126ba97SEli Cohen 	u8			cgs;
526e126ba97SEli Cohen 	u8			cs_req;
527e126ba97SEli Cohen 	u8			cs_res;
528e126ba97SEli Cohen 	__be64			dc_access_key;
529e126ba97SEli Cohen 	u8			rsvd1[24];
530e126ba97SEli Cohen };
531e126ba97SEli Cohen 
532e126ba97SEli Cohen static inline struct mlx5_core_qp *__mlx5_qp_lookup(struct mlx5_core_dev *dev, u32 qpn)
533e126ba97SEli Cohen {
534e126ba97SEli Cohen 	return radix_tree_lookup(&dev->priv.qp_table.tree, qpn);
535e126ba97SEli Cohen }
536e126ba97SEli Cohen 
537a606b0f6SMatan Barak static inline struct mlx5_core_mkey *__mlx5_mr_lookup(struct mlx5_core_dev *dev, u32 key)
538d5436ba0SSagi Grimberg {
539a606b0f6SMatan Barak 	return radix_tree_lookup(&dev->priv.mkey_table.tree, key);
540d5436ba0SSagi Grimberg }
541d5436ba0SSagi Grimberg 
542e126ba97SEli Cohen int mlx5_core_create_qp(struct mlx5_core_dev *dev,
543e126ba97SEli Cohen 			struct mlx5_core_qp *qp,
54409a7d9ecSSaeed Mahameed 			u32 *in,
545e126ba97SEli Cohen 			int inlen);
5461a412fb1SSaeed Mahameed int mlx5_core_qp_modify(struct mlx5_core_dev *dev, u16 opcode,
5471a412fb1SSaeed Mahameed 			u32 opt_param_mask, void *qpc,
548e126ba97SEli Cohen 			struct mlx5_core_qp *qp);
549e126ba97SEli Cohen int mlx5_core_destroy_qp(struct mlx5_core_dev *dev,
550e126ba97SEli Cohen 			 struct mlx5_core_qp *qp);
551e126ba97SEli Cohen int mlx5_core_qp_query(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp,
55209a7d9ecSSaeed Mahameed 		       u32 *out, int outlen);
553e126ba97SEli Cohen 
554e126ba97SEli Cohen int mlx5_core_xrcd_alloc(struct mlx5_core_dev *dev, u32 *xrcdn);
555e126ba97SEli Cohen int mlx5_core_xrcd_dealloc(struct mlx5_core_dev *dev, u32 xrcdn);
556e126ba97SEli Cohen void mlx5_init_qp_table(struct mlx5_core_dev *dev);
557e126ba97SEli Cohen void mlx5_cleanup_qp_table(struct mlx5_core_dev *dev);
558e126ba97SEli Cohen int mlx5_debug_qp_add(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp);
559e126ba97SEli Cohen void mlx5_debug_qp_remove(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp);
560e420f0c0SHaggai Eran #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
561e420f0c0SHaggai Eran int mlx5_core_page_fault_resume(struct mlx5_core_dev *dev, u32 qpn,
562e420f0c0SHaggai Eran 				u8 context, int error);
563e420f0c0SHaggai Eran #endif
564e2013b21Smajd@mellanox.com int mlx5_core_create_rq_tracked(struct mlx5_core_dev *dev, u32 *in, int inlen,
565e2013b21Smajd@mellanox.com 				struct mlx5_core_qp *rq);
566e2013b21Smajd@mellanox.com void mlx5_core_destroy_rq_tracked(struct mlx5_core_dev *dev,
567e2013b21Smajd@mellanox.com 				  struct mlx5_core_qp *rq);
568e2013b21Smajd@mellanox.com int mlx5_core_create_sq_tracked(struct mlx5_core_dev *dev, u32 *in, int inlen,
569e2013b21Smajd@mellanox.com 				struct mlx5_core_qp *sq);
570e2013b21Smajd@mellanox.com void mlx5_core_destroy_sq_tracked(struct mlx5_core_dev *dev,
571e2013b21Smajd@mellanox.com 				  struct mlx5_core_qp *sq);
572237cd218STariq Toukan int mlx5_core_alloc_q_counter(struct mlx5_core_dev *dev, u16 *counter_id);
573237cd218STariq Toukan int mlx5_core_dealloc_q_counter(struct mlx5_core_dev *dev, u16 counter_id);
574237cd218STariq Toukan int mlx5_core_query_q_counter(struct mlx5_core_dev *dev, u16 counter_id,
575237cd218STariq Toukan 			      int reset, void *out, int out_size);
576237cd218STariq Toukan int mlx5_core_query_out_of_buffer(struct mlx5_core_dev *dev, u16 counter_id,
577237cd218STariq Toukan 				  u32 *out_of_buffer);
578e126ba97SEli Cohen 
579db81a5c3SEli Cohen static inline const char *mlx5_qp_type_str(int type)
580db81a5c3SEli Cohen {
581db81a5c3SEli Cohen 	switch (type) {
582db81a5c3SEli Cohen 	case MLX5_QP_ST_RC: return "RC";
583db81a5c3SEli Cohen 	case MLX5_QP_ST_UC: return "C";
584db81a5c3SEli Cohen 	case MLX5_QP_ST_UD: return "UD";
585db81a5c3SEli Cohen 	case MLX5_QP_ST_XRC: return "XRC";
586db81a5c3SEli Cohen 	case MLX5_QP_ST_MLX: return "MLX";
587db81a5c3SEli Cohen 	case MLX5_QP_ST_QP0: return "QP0";
588db81a5c3SEli Cohen 	case MLX5_QP_ST_QP1: return "QP1";
589db81a5c3SEli Cohen 	case MLX5_QP_ST_RAW_ETHERTYPE: return "RAW_ETHERTYPE";
590db81a5c3SEli Cohen 	case MLX5_QP_ST_RAW_IPV6: return "RAW_IPV6";
591db81a5c3SEli Cohen 	case MLX5_QP_ST_SNIFFER: return "SNIFFER";
592db81a5c3SEli Cohen 	case MLX5_QP_ST_SYNC_UMR: return "SYNC_UMR";
593db81a5c3SEli Cohen 	case MLX5_QP_ST_PTP_1588: return "PTP_1588";
594db81a5c3SEli Cohen 	case MLX5_QP_ST_REG_UMR: return "REG_UMR";
595db81a5c3SEli Cohen 	default: return "Invalid transport type";
596db81a5c3SEli Cohen 	}
597db81a5c3SEli Cohen }
598db81a5c3SEli Cohen 
599db81a5c3SEli Cohen static inline const char *mlx5_qp_state_str(int state)
600db81a5c3SEli Cohen {
601db81a5c3SEli Cohen 	switch (state) {
602db81a5c3SEli Cohen 	case MLX5_QP_STATE_RST:
603db81a5c3SEli Cohen 	return "RST";
604db81a5c3SEli Cohen 	case MLX5_QP_STATE_INIT:
605db81a5c3SEli Cohen 	return "INIT";
606db81a5c3SEli Cohen 	case MLX5_QP_STATE_RTR:
607db81a5c3SEli Cohen 	return "RTR";
608db81a5c3SEli Cohen 	case MLX5_QP_STATE_RTS:
609db81a5c3SEli Cohen 	return "RTS";
610db81a5c3SEli Cohen 	case MLX5_QP_STATE_SQER:
611db81a5c3SEli Cohen 	return "SQER";
612db81a5c3SEli Cohen 	case MLX5_QP_STATE_SQD:
613db81a5c3SEli Cohen 	return "SQD";
614db81a5c3SEli Cohen 	case MLX5_QP_STATE_ERR:
615db81a5c3SEli Cohen 	return "ERR";
616db81a5c3SEli Cohen 	case MLX5_QP_STATE_SQ_DRAINING:
617db81a5c3SEli Cohen 	return "SQ_DRAINING";
618db81a5c3SEli Cohen 	case MLX5_QP_STATE_SUSPENDED:
619db81a5c3SEli Cohen 	return "SUSPENDED";
620db81a5c3SEli Cohen 	default: return "Invalid QP state";
621db81a5c3SEli Cohen 	}
622db81a5c3SEli Cohen }
623db81a5c3SEli Cohen 
624e126ba97SEli Cohen #endif /* MLX5_QP_H */
625