xref: /linux/drivers/infiniband/hw/bnxt_re/qplib_fp.h (revision 3fb755b3d58084001c89e5f0fd558552bdef9051)
11ac5a404SSelvin Xavier /*
21ac5a404SSelvin Xavier  * Broadcom NetXtreme-E RoCE driver.
31ac5a404SSelvin Xavier  *
41ac5a404SSelvin Xavier  * Copyright (c) 2016 - 2017, Broadcom. All rights reserved.  The term
51ac5a404SSelvin Xavier  * Broadcom refers to Broadcom Limited and/or its subsidiaries.
61ac5a404SSelvin Xavier  *
71ac5a404SSelvin Xavier  * This software is available to you under a choice of one of two
81ac5a404SSelvin Xavier  * licenses.  You may choose to be licensed under the terms of the GNU
91ac5a404SSelvin Xavier  * General Public License (GPL) Version 2, available from the file
101ac5a404SSelvin Xavier  * COPYING in the main directory of this source tree, or the
111ac5a404SSelvin Xavier  * BSD license below:
121ac5a404SSelvin Xavier  *
131ac5a404SSelvin Xavier  * Redistribution and use in source and binary forms, with or without
141ac5a404SSelvin Xavier  * modification, are permitted provided that the following conditions
151ac5a404SSelvin Xavier  * are met:
161ac5a404SSelvin Xavier  *
171ac5a404SSelvin Xavier  * 1. Redistributions of source code must retain the above copyright
181ac5a404SSelvin Xavier  *    notice, this list of conditions and the following disclaimer.
191ac5a404SSelvin Xavier  * 2. Redistributions in binary form must reproduce the above copyright
201ac5a404SSelvin Xavier  *    notice, this list of conditions and the following disclaimer in
211ac5a404SSelvin Xavier  *    the documentation and/or other materials provided with the
221ac5a404SSelvin Xavier  *    distribution.
231ac5a404SSelvin Xavier  *
241ac5a404SSelvin Xavier  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
251ac5a404SSelvin Xavier  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
261ac5a404SSelvin Xavier  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
271ac5a404SSelvin Xavier  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
281ac5a404SSelvin Xavier  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
291ac5a404SSelvin Xavier  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
301ac5a404SSelvin Xavier  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
311ac5a404SSelvin Xavier  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
321ac5a404SSelvin Xavier  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
331ac5a404SSelvin Xavier  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
341ac5a404SSelvin Xavier  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
351ac5a404SSelvin Xavier  *
361ac5a404SSelvin Xavier  * Description: Fast Path Operators (header)
371ac5a404SSelvin Xavier  */
381ac5a404SSelvin Xavier 
391ac5a404SSelvin Xavier #ifndef __BNXT_QPLIB_FP_H__
401ac5a404SSelvin Xavier #define __BNXT_QPLIB_FP_H__
411ac5a404SSelvin Xavier 
421ac5a404SSelvin Xavier struct bnxt_qplib_sge {
431ac5a404SSelvin Xavier 	u64				addr;
441ac5a404SSelvin Xavier 	u32				lkey;
451ac5a404SSelvin Xavier 	u32				size;
461ac5a404SSelvin Xavier };
471ac5a404SSelvin Xavier 
481ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_SQE_ENTRY_SIZE	sizeof(struct sq_send)
491ac5a404SSelvin Xavier 
501ac5a404SSelvin Xavier #define SQE_CNT_PER_PG		(PAGE_SIZE / BNXT_QPLIB_MAX_SQE_ENTRY_SIZE)
511ac5a404SSelvin Xavier #define SQE_MAX_IDX_PER_PG	(SQE_CNT_PER_PG - 1)
521ac5a404SSelvin Xavier 
531ac5a404SSelvin Xavier static inline u32 get_sqe_pg(u32 val)
541ac5a404SSelvin Xavier {
551ac5a404SSelvin Xavier 	return ((val & ~SQE_MAX_IDX_PER_PG) / SQE_CNT_PER_PG);
561ac5a404SSelvin Xavier }
571ac5a404SSelvin Xavier 
581ac5a404SSelvin Xavier static inline u32 get_sqe_idx(u32 val)
591ac5a404SSelvin Xavier {
601ac5a404SSelvin Xavier 	return (val & SQE_MAX_IDX_PER_PG);
611ac5a404SSelvin Xavier }
621ac5a404SSelvin Xavier 
631ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_PSNE_ENTRY_SIZE	sizeof(struct sq_psn_search)
641ac5a404SSelvin Xavier 
651ac5a404SSelvin Xavier #define PSNE_CNT_PER_PG		(PAGE_SIZE / BNXT_QPLIB_MAX_PSNE_ENTRY_SIZE)
661ac5a404SSelvin Xavier #define PSNE_MAX_IDX_PER_PG	(PSNE_CNT_PER_PG - 1)
671ac5a404SSelvin Xavier 
681ac5a404SSelvin Xavier static inline u32 get_psne_pg(u32 val)
691ac5a404SSelvin Xavier {
701ac5a404SSelvin Xavier 	return ((val & ~PSNE_MAX_IDX_PER_PG) / PSNE_CNT_PER_PG);
711ac5a404SSelvin Xavier }
721ac5a404SSelvin Xavier 
731ac5a404SSelvin Xavier static inline u32 get_psne_idx(u32 val)
741ac5a404SSelvin Xavier {
751ac5a404SSelvin Xavier 	return (val & PSNE_MAX_IDX_PER_PG);
761ac5a404SSelvin Xavier }
771ac5a404SSelvin Xavier 
781ac5a404SSelvin Xavier #define BNXT_QPLIB_QP_MAX_SGL	6
791ac5a404SSelvin Xavier 
801ac5a404SSelvin Xavier struct bnxt_qplib_swq {
811ac5a404SSelvin Xavier 	u64				wr_id;
821ac5a404SSelvin Xavier 	u8				type;
831ac5a404SSelvin Xavier 	u8				flags;
841ac5a404SSelvin Xavier 	u32				start_psn;
851ac5a404SSelvin Xavier 	u32				next_psn;
861ac5a404SSelvin Xavier 	struct sq_psn_search		*psn_search;
871ac5a404SSelvin Xavier };
881ac5a404SSelvin Xavier 
891ac5a404SSelvin Xavier struct bnxt_qplib_swqe {
901ac5a404SSelvin Xavier 	/* General */
919152e0b7SEddie Wai #define	BNXT_QPLIB_FENCE_WRID	0x46454E43	/* "FENC" */
921ac5a404SSelvin Xavier 	u64				wr_id;
931ac5a404SSelvin Xavier 	u8				reqs_type;
941ac5a404SSelvin Xavier 	u8				type;
951ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_SEND			0
961ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_SEND_WITH_IMM		1
971ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_SEND_WITH_INV		2
981ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_RDMA_WRITE			4
991ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_RDMA_WRITE_WITH_IMM	5
1001ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_RDMA_READ			6
1011ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_ATOMIC_CMP_AND_SWP		8
1021ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_ATOMIC_FETCH_AND_ADD	11
1031ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_LOCAL_INV			12
1041ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_FAST_REG_MR		13
1051ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_REG_MR			13
1061ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_BIND_MW			14
1071ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_RECV			128
1081ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_TYPE_RECV_RDMA_IMM		129
1091ac5a404SSelvin Xavier 	u8				flags;
1101ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP		BIT(0)
1111ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_FLAGS_RD_ATOMIC_FENCE		BIT(1)
1121ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_FLAGS_UC_FENCE			BIT(2)
1131ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_FLAGS_SOLICIT_EVENT		BIT(3)
1141ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_FLAGS_INLINE			BIT(4)
1151ac5a404SSelvin Xavier 	struct bnxt_qplib_sge		sg_list[BNXT_QPLIB_QP_MAX_SGL];
1161ac5a404SSelvin Xavier 	int				num_sge;
1171ac5a404SSelvin Xavier 	/* Max inline data is 96 bytes */
1181ac5a404SSelvin Xavier 	u32				inline_len;
1191ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH		96
1201ac5a404SSelvin Xavier 	u8		inline_data[BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH];
1211ac5a404SSelvin Xavier 
1221ac5a404SSelvin Xavier 	union {
1231ac5a404SSelvin Xavier 		/* Send, with imm, inval key */
1241ac5a404SSelvin Xavier 		struct {
1251ac5a404SSelvin Xavier 			union {
1261ac5a404SSelvin Xavier 				__be32	imm_data;
1271ac5a404SSelvin Xavier 				u32	inv_key;
1281ac5a404SSelvin Xavier 			};
1291ac5a404SSelvin Xavier 			u32		q_key;
1301ac5a404SSelvin Xavier 			u32		dst_qp;
1311ac5a404SSelvin Xavier 			u16		avid;
1321ac5a404SSelvin Xavier 		} send;
1331ac5a404SSelvin Xavier 
1341ac5a404SSelvin Xavier 		/* Send Raw Ethernet and QP1 */
1351ac5a404SSelvin Xavier 		struct {
1361ac5a404SSelvin Xavier 			u16		lflags;
1371ac5a404SSelvin Xavier 			u16		cfa_action;
1381ac5a404SSelvin Xavier 			u32		cfa_meta;
1391ac5a404SSelvin Xavier 		} rawqp1;
1401ac5a404SSelvin Xavier 
1411ac5a404SSelvin Xavier 		/* RDMA write, with imm, read */
1421ac5a404SSelvin Xavier 		struct {
1431ac5a404SSelvin Xavier 			union {
1441ac5a404SSelvin Xavier 				__be32	imm_data;
1451ac5a404SSelvin Xavier 				u32	inv_key;
1461ac5a404SSelvin Xavier 			};
1471ac5a404SSelvin Xavier 			u64		remote_va;
1481ac5a404SSelvin Xavier 			u32		r_key;
1491ac5a404SSelvin Xavier 		} rdma;
1501ac5a404SSelvin Xavier 
1511ac5a404SSelvin Xavier 		/* Atomic cmp/swap, fetch/add */
1521ac5a404SSelvin Xavier 		struct {
1531ac5a404SSelvin Xavier 			u64		remote_va;
1541ac5a404SSelvin Xavier 			u32		r_key;
1551ac5a404SSelvin Xavier 			u64		swap_data;
1561ac5a404SSelvin Xavier 			u64		cmp_data;
1571ac5a404SSelvin Xavier 		} atomic;
1581ac5a404SSelvin Xavier 
1591ac5a404SSelvin Xavier 		/* Local Invalidate */
1601ac5a404SSelvin Xavier 		struct {
1611ac5a404SSelvin Xavier 			u32		inv_l_key;
1621ac5a404SSelvin Xavier 		} local_inv;
1631ac5a404SSelvin Xavier 
1641ac5a404SSelvin Xavier 		/* FR-PMR */
1651ac5a404SSelvin Xavier 		struct {
1661ac5a404SSelvin Xavier 			u8		access_cntl;
1671ac5a404SSelvin Xavier 			u8		pg_sz_log;
1681ac5a404SSelvin Xavier 			bool		zero_based;
1691ac5a404SSelvin Xavier 			u32		l_key;
1701ac5a404SSelvin Xavier 			u32		length;
1711ac5a404SSelvin Xavier 			u8		pbl_pg_sz_log;
1721ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_PAGE_SIZE_4K			0
1731ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_PAGE_SIZE_8K			1
1741ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_PAGE_SIZE_64K			4
1751ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_PAGE_SIZE_256K			6
1761ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_PAGE_SIZE_1M			8
1771ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_PAGE_SIZE_2M			9
1781ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_PAGE_SIZE_4M			10
1791ac5a404SSelvin Xavier #define BNXT_QPLIB_SWQE_PAGE_SIZE_1G			18
1801ac5a404SSelvin Xavier 			u8		levels;
1811ac5a404SSelvin Xavier #define PAGE_SHIFT_4K	12
1821ac5a404SSelvin Xavier 			__le64		*pbl_ptr;
1831ac5a404SSelvin Xavier 			dma_addr_t	pbl_dma_ptr;
1841ac5a404SSelvin Xavier 			u64		*page_list;
1851ac5a404SSelvin Xavier 			u16		page_list_len;
1861ac5a404SSelvin Xavier 			u64		va;
1871ac5a404SSelvin Xavier 		} frmr;
1881ac5a404SSelvin Xavier 
1891ac5a404SSelvin Xavier 		/* Bind */
1901ac5a404SSelvin Xavier 		struct {
1911ac5a404SSelvin Xavier 			u8		access_cntl;
1921ac5a404SSelvin Xavier #define BNXT_QPLIB_BIND_SWQE_ACCESS_LOCAL_WRITE		BIT(0)
1931ac5a404SSelvin Xavier #define BNXT_QPLIB_BIND_SWQE_ACCESS_REMOTE_READ		BIT(1)
1941ac5a404SSelvin Xavier #define BNXT_QPLIB_BIND_SWQE_ACCESS_REMOTE_WRITE	BIT(2)
1951ac5a404SSelvin Xavier #define BNXT_QPLIB_BIND_SWQE_ACCESS_REMOTE_ATOMIC	BIT(3)
1961ac5a404SSelvin Xavier #define BNXT_QPLIB_BIND_SWQE_ACCESS_WINDOW_BIND		BIT(4)
1971ac5a404SSelvin Xavier 			bool		zero_based;
1981ac5a404SSelvin Xavier 			u8		mw_type;
1991ac5a404SSelvin Xavier 			u32		parent_l_key;
2001ac5a404SSelvin Xavier 			u32		r_key;
2011ac5a404SSelvin Xavier 			u64		va;
2021ac5a404SSelvin Xavier 			u32		length;
2031ac5a404SSelvin Xavier 		} bind;
2041ac5a404SSelvin Xavier 	};
2051ac5a404SSelvin Xavier };
2061ac5a404SSelvin Xavier 
2071ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_RQE_ENTRY_SIZE	sizeof(struct rq_wqe)
2081ac5a404SSelvin Xavier 
2091ac5a404SSelvin Xavier #define RQE_CNT_PER_PG		(PAGE_SIZE / BNXT_QPLIB_MAX_RQE_ENTRY_SIZE)
2101ac5a404SSelvin Xavier #define RQE_MAX_IDX_PER_PG	(RQE_CNT_PER_PG - 1)
2111ac5a404SSelvin Xavier #define RQE_PG(x)		(((x) & ~RQE_MAX_IDX_PER_PG) / RQE_CNT_PER_PG)
2121ac5a404SSelvin Xavier #define RQE_IDX(x)		((x) & RQE_MAX_IDX_PER_PG)
2131ac5a404SSelvin Xavier 
2141ac5a404SSelvin Xavier struct bnxt_qplib_q {
2151ac5a404SSelvin Xavier 	struct bnxt_qplib_hwq		hwq;
2161ac5a404SSelvin Xavier 	struct bnxt_qplib_swq		*swq;
2171ac5a404SSelvin Xavier 	struct scatterlist		*sglist;
2181ac5a404SSelvin Xavier 	u32				nmap;
2191ac5a404SSelvin Xavier 	u32				max_wqe;
2209152e0b7SEddie Wai 	u16				q_full_delta;
2211ac5a404SSelvin Xavier 	u16				max_sge;
2221ac5a404SSelvin Xavier 	u32				psn;
2231ac5a404SSelvin Xavier 	bool				flush_in_progress;
2249152e0b7SEddie Wai 	bool				condition;
2259152e0b7SEddie Wai 	bool				single;
2269152e0b7SEddie Wai 	bool				send_phantom;
2279152e0b7SEddie Wai 	u32				phantom_wqe_cnt;
2289152e0b7SEddie Wai 	u32				phantom_cqe_cnt;
2299152e0b7SEddie Wai 	u32				next_cq_cons;
2301ac5a404SSelvin Xavier };
2311ac5a404SSelvin Xavier 
2321ac5a404SSelvin Xavier struct bnxt_qplib_qp {
2331ac5a404SSelvin Xavier 	struct bnxt_qplib_pd		*pd;
2341ac5a404SSelvin Xavier 	struct bnxt_qplib_dpi		*dpi;
2351ac5a404SSelvin Xavier 	u64				qp_handle;
2361ac5a404SSelvin Xavier 	u32				id;
2371ac5a404SSelvin Xavier 	u8				type;
2381ac5a404SSelvin Xavier 	u8				sig_type;
2391ac5a404SSelvin Xavier 	u32				modify_flags;
2401ac5a404SSelvin Xavier 	u8				state;
2411ac5a404SSelvin Xavier 	u8				cur_qp_state;
2421ac5a404SSelvin Xavier 	u32				max_inline_data;
2431ac5a404SSelvin Xavier 	u32				mtu;
2441ac5a404SSelvin Xavier 	u8				path_mtu;
2451ac5a404SSelvin Xavier 	bool				en_sqd_async_notify;
2461ac5a404SSelvin Xavier 	u16				pkey_index;
2471ac5a404SSelvin Xavier 	u32				qkey;
2481ac5a404SSelvin Xavier 	u32				dest_qp_id;
2491ac5a404SSelvin Xavier 	u8				access;
2501ac5a404SSelvin Xavier 	u8				timeout;
2511ac5a404SSelvin Xavier 	u8				retry_cnt;
2521ac5a404SSelvin Xavier 	u8				rnr_retry;
253*3fb755b3SSomnath Kotur 	u64				wqe_cnt;
2541ac5a404SSelvin Xavier 	u32				min_rnr_timer;
2551ac5a404SSelvin Xavier 	u32				max_rd_atomic;
2561ac5a404SSelvin Xavier 	u32				max_dest_rd_atomic;
2571ac5a404SSelvin Xavier 	u32				dest_qpn;
2581ac5a404SSelvin Xavier 	u8				smac[6];
2591ac5a404SSelvin Xavier 	u16				vlan_id;
2601ac5a404SSelvin Xavier 	u8				nw_type;
2611ac5a404SSelvin Xavier 	struct bnxt_qplib_ah		ah;
2621ac5a404SSelvin Xavier 
2631ac5a404SSelvin Xavier #define BTH_PSN_MASK			((1 << 24) - 1)
2641ac5a404SSelvin Xavier 	/* SQ */
2651ac5a404SSelvin Xavier 	struct bnxt_qplib_q		sq;
2661ac5a404SSelvin Xavier 	/* RQ */
2671ac5a404SSelvin Xavier 	struct bnxt_qplib_q		rq;
2681ac5a404SSelvin Xavier 	/* SRQ */
2691ac5a404SSelvin Xavier 	struct bnxt_qplib_srq		*srq;
2701ac5a404SSelvin Xavier 	/* CQ */
2711ac5a404SSelvin Xavier 	struct bnxt_qplib_cq		*scq;
2721ac5a404SSelvin Xavier 	struct bnxt_qplib_cq		*rcq;
2731ac5a404SSelvin Xavier 	/* IRRQ and ORRQ */
2741ac5a404SSelvin Xavier 	struct bnxt_qplib_hwq		irrq;
2751ac5a404SSelvin Xavier 	struct bnxt_qplib_hwq		orrq;
2761ac5a404SSelvin Xavier 	/* Header buffer for QP1 */
2771ac5a404SSelvin Xavier 	int				sq_hdr_buf_size;
2781ac5a404SSelvin Xavier 	int				rq_hdr_buf_size;
2791ac5a404SSelvin Xavier /*
2801ac5a404SSelvin Xavier  * Buffer space for ETH(14), IP or GRH(40), UDP header(8)
2811ac5a404SSelvin Xavier  * and ib_bth + ib_deth (20).
2821ac5a404SSelvin Xavier  * Max required is 82 when RoCE V2 is enabled
2831ac5a404SSelvin Xavier  */
2841ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_QP1_SQ_HDR_SIZE_V2	86
2851ac5a404SSelvin Xavier 	/* Ethernet header	=  14 */
2861ac5a404SSelvin Xavier 	/* ib_grh		=  40 (provided by MAD) */
2871ac5a404SSelvin Xavier 	/* ib_bth + ib_deth	=  20 */
2881ac5a404SSelvin Xavier 	/* MAD			= 256 (provided by MAD) */
2891ac5a404SSelvin Xavier 	/* iCRC			=   4 */
2901ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_QP1_RQ_ETH_HDR_SIZE	14
2911ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_QP1_RQ_HDR_SIZE_V2	512
2921ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_GRH_HDR_SIZE_IPV4	20
2931ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_GRH_HDR_SIZE_IPV6	40
2941ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_QP1_RQ_BDETH_HDR_SIZE	20
2951ac5a404SSelvin Xavier 	void				*sq_hdr_buf;
2961ac5a404SSelvin Xavier 	dma_addr_t			sq_hdr_buf_map;
2971ac5a404SSelvin Xavier 	void				*rq_hdr_buf;
2981ac5a404SSelvin Xavier 	dma_addr_t			rq_hdr_buf_map;
2991ac5a404SSelvin Xavier };
3001ac5a404SSelvin Xavier 
3011ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_CQE_ENTRY_SIZE	sizeof(struct cq_base)
3021ac5a404SSelvin Xavier 
3031ac5a404SSelvin Xavier #define CQE_CNT_PER_PG		(PAGE_SIZE / BNXT_QPLIB_MAX_CQE_ENTRY_SIZE)
3041ac5a404SSelvin Xavier #define CQE_MAX_IDX_PER_PG	(CQE_CNT_PER_PG - 1)
3051ac5a404SSelvin Xavier #define CQE_PG(x)		(((x) & ~CQE_MAX_IDX_PER_PG) / CQE_CNT_PER_PG)
3061ac5a404SSelvin Xavier #define CQE_IDX(x)		((x) & CQE_MAX_IDX_PER_PG)
3071ac5a404SSelvin Xavier 
3081ac5a404SSelvin Xavier #define ROCE_CQE_CMP_V			0
3091ac5a404SSelvin Xavier #define CQE_CMP_VALID(hdr, raw_cons, cp_bit)			\
3101ac5a404SSelvin Xavier 	(!!((hdr)->cqe_type_toggle & CQ_BASE_TOGGLE) ==		\
3111ac5a404SSelvin Xavier 	   !((raw_cons) & (cp_bit)))
3121ac5a404SSelvin Xavier 
3139152e0b7SEddie Wai static inline bool bnxt_qplib_queue_full(struct bnxt_qplib_q *qplib_q)
3149152e0b7SEddie Wai {
3159152e0b7SEddie Wai 	return HWQ_CMP((qplib_q->hwq.prod + qplib_q->q_full_delta),
3169152e0b7SEddie Wai 		       &qplib_q->hwq) == HWQ_CMP(qplib_q->hwq.cons,
3179152e0b7SEddie Wai 						 &qplib_q->hwq);
3189152e0b7SEddie Wai }
3199152e0b7SEddie Wai 
3201ac5a404SSelvin Xavier struct bnxt_qplib_cqe {
3211ac5a404SSelvin Xavier 	u8				status;
3221ac5a404SSelvin Xavier 	u8				type;
3231ac5a404SSelvin Xavier 	u8				opcode;
3241ac5a404SSelvin Xavier 	u32				length;
3251ac5a404SSelvin Xavier 	u64				wr_id;
3261ac5a404SSelvin Xavier 	union {
3271ac5a404SSelvin Xavier 		__be32			immdata;
3281ac5a404SSelvin Xavier 		u32			invrkey;
3291ac5a404SSelvin Xavier 	};
3301ac5a404SSelvin Xavier 	u64				qp_handle;
3311ac5a404SSelvin Xavier 	u64				mr_handle;
3321ac5a404SSelvin Xavier 	u16				flags;
3331ac5a404SSelvin Xavier 	u8				smac[6];
3341ac5a404SSelvin Xavier 	u32				src_qp;
3351ac5a404SSelvin Xavier 	u16				raweth_qp1_flags;
3361ac5a404SSelvin Xavier 	u16				raweth_qp1_errors;
3371ac5a404SSelvin Xavier 	u16				raweth_qp1_cfa_code;
3381ac5a404SSelvin Xavier 	u32				raweth_qp1_flags2;
3391ac5a404SSelvin Xavier 	u32				raweth_qp1_metadata;
3401ac5a404SSelvin Xavier 	u8				raweth_qp1_payload_offset;
3411ac5a404SSelvin Xavier 	u16				pkey_index;
3421ac5a404SSelvin Xavier };
3431ac5a404SSelvin Xavier 
3441ac5a404SSelvin Xavier #define BNXT_QPLIB_QUEUE_START_PERIOD		0x01
3451ac5a404SSelvin Xavier struct bnxt_qplib_cq {
3461ac5a404SSelvin Xavier 	struct bnxt_qplib_dpi		*dpi;
3471ac5a404SSelvin Xavier 	void __iomem			*dbr_base;
3481ac5a404SSelvin Xavier 	u32				max_wqe;
3491ac5a404SSelvin Xavier 	u32				id;
3501ac5a404SSelvin Xavier 	u16				count;
3511ac5a404SSelvin Xavier 	u16				period;
3521ac5a404SSelvin Xavier 	struct bnxt_qplib_hwq		hwq;
3531ac5a404SSelvin Xavier 	u32				cnq_hw_ring_id;
3541ac5a404SSelvin Xavier 	bool				resize_in_progress;
3551ac5a404SSelvin Xavier 	struct scatterlist		*sghead;
3561ac5a404SSelvin Xavier 	u32				nmap;
3571ac5a404SSelvin Xavier 	u64				cq_handle;
3581ac5a404SSelvin Xavier 
3591ac5a404SSelvin Xavier #define CQ_RESIZE_WAIT_TIME_MS		500
3601ac5a404SSelvin Xavier 	unsigned long			flags;
3611ac5a404SSelvin Xavier #define CQ_FLAGS_RESIZE_IN_PROG		1
3621ac5a404SSelvin Xavier 	wait_queue_head_t		waitq;
3631ac5a404SSelvin Xavier };
3641ac5a404SSelvin Xavier 
3651ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_IRRQE_ENTRY_SIZE	sizeof(struct xrrq_irrq)
3661ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_ORRQE_ENTRY_SIZE	sizeof(struct xrrq_orrq)
3671ac5a404SSelvin Xavier #define IRD_LIMIT_TO_IRRQ_SLOTS(x)	(2 * (x) + 2)
3681ac5a404SSelvin Xavier #define IRRQ_SLOTS_TO_IRD_LIMIT(s)	(((s) >> 1) - 1)
3691ac5a404SSelvin Xavier #define ORD_LIMIT_TO_ORRQ_SLOTS(x)	((x) + 1)
3701ac5a404SSelvin Xavier #define ORRQ_SLOTS_TO_ORD_LIMIT(s)	((s) - 1)
3711ac5a404SSelvin Xavier 
3721ac5a404SSelvin Xavier #define BNXT_QPLIB_MAX_NQE_ENTRY_SIZE	sizeof(struct nq_base)
3731ac5a404SSelvin Xavier 
3741ac5a404SSelvin Xavier #define NQE_CNT_PER_PG		(PAGE_SIZE / BNXT_QPLIB_MAX_NQE_ENTRY_SIZE)
3751ac5a404SSelvin Xavier #define NQE_MAX_IDX_PER_PG	(NQE_CNT_PER_PG - 1)
3761ac5a404SSelvin Xavier #define NQE_PG(x)		(((x) & ~NQE_MAX_IDX_PER_PG) / NQE_CNT_PER_PG)
3771ac5a404SSelvin Xavier #define NQE_IDX(x)		((x) & NQE_MAX_IDX_PER_PG)
3781ac5a404SSelvin Xavier 
3791ac5a404SSelvin Xavier #define NQE_CMP_VALID(hdr, raw_cons, cp_bit)			\
3801ac5a404SSelvin Xavier 	(!!(le32_to_cpu((hdr)->info63_v[0]) & NQ_BASE_V) ==	\
3811ac5a404SSelvin Xavier 	   !((raw_cons) & (cp_bit)))
3821ac5a404SSelvin Xavier 
3831ac5a404SSelvin Xavier #define BNXT_QPLIB_NQE_MAX_CNT		(128 * 1024)
3841ac5a404SSelvin Xavier 
3851ac5a404SSelvin Xavier #define NQ_CONS_PCI_BAR_REGION		2
3861ac5a404SSelvin Xavier #define NQ_DB_KEY_CP			(0x2 << CMPL_DOORBELL_KEY_SFT)
3871ac5a404SSelvin Xavier #define NQ_DB_IDX_VALID			CMPL_DOORBELL_IDX_VALID
3881ac5a404SSelvin Xavier #define NQ_DB_IRQ_DIS			CMPL_DOORBELL_MASK
3891ac5a404SSelvin Xavier #define NQ_DB_CP_FLAGS_REARM		(NQ_DB_KEY_CP |		\
3901ac5a404SSelvin Xavier 					 NQ_DB_IDX_VALID)
3911ac5a404SSelvin Xavier #define NQ_DB_CP_FLAGS			(NQ_DB_KEY_CP    |	\
3921ac5a404SSelvin Xavier 					 NQ_DB_IDX_VALID |	\
3931ac5a404SSelvin Xavier 					 NQ_DB_IRQ_DIS)
3941ac5a404SSelvin Xavier #define NQ_DB_REARM(db, raw_cons, cp_bit)			\
3951ac5a404SSelvin Xavier 	writel(NQ_DB_CP_FLAGS_REARM | ((raw_cons) & ((cp_bit) - 1)), db)
3961ac5a404SSelvin Xavier #define NQ_DB(db, raw_cons, cp_bit)				\
3971ac5a404SSelvin Xavier 	writel(NQ_DB_CP_FLAGS | ((raw_cons) & ((cp_bit) - 1)), db)
3981ac5a404SSelvin Xavier 
3991ac5a404SSelvin Xavier struct bnxt_qplib_nq {
4001ac5a404SSelvin Xavier 	struct pci_dev			*pdev;
4011ac5a404SSelvin Xavier 
4021ac5a404SSelvin Xavier 	int				vector;
4031ac5a404SSelvin Xavier 	int				budget;
4041ac5a404SSelvin Xavier 	bool				requested;
4051ac5a404SSelvin Xavier 	struct tasklet_struct		worker;
4061ac5a404SSelvin Xavier 	struct bnxt_qplib_hwq		hwq;
4071ac5a404SSelvin Xavier 
4081ac5a404SSelvin Xavier 	u16				bar_reg;
4091ac5a404SSelvin Xavier 	u16				bar_reg_off;
4101ac5a404SSelvin Xavier 	u16				ring_id;
4111ac5a404SSelvin Xavier 	void __iomem			*bar_reg_iomem;
4121ac5a404SSelvin Xavier 
4131ac5a404SSelvin Xavier 	int				(*cqn_handler)
4141ac5a404SSelvin Xavier 						(struct bnxt_qplib_nq *nq,
4151ac5a404SSelvin Xavier 						 struct bnxt_qplib_cq *cq);
4161ac5a404SSelvin Xavier 	int				(*srqn_handler)
4171ac5a404SSelvin Xavier 						(struct bnxt_qplib_nq *nq,
4181ac5a404SSelvin Xavier 						 void *srq,
4191ac5a404SSelvin Xavier 						 u8 event);
4201ac5a404SSelvin Xavier };
4211ac5a404SSelvin Xavier 
4221ac5a404SSelvin Xavier void bnxt_qplib_disable_nq(struct bnxt_qplib_nq *nq);
4231ac5a404SSelvin Xavier int bnxt_qplib_enable_nq(struct pci_dev *pdev, struct bnxt_qplib_nq *nq,
4241ac5a404SSelvin Xavier 			 int msix_vector, int bar_reg_offset,
4251ac5a404SSelvin Xavier 			 int (*cqn_handler)(struct bnxt_qplib_nq *nq,
4261ac5a404SSelvin Xavier 					    struct bnxt_qplib_cq *cq),
4271ac5a404SSelvin Xavier 			 int (*srqn_handler)(struct bnxt_qplib_nq *nq,
4281ac5a404SSelvin Xavier 					     void *srq,
4291ac5a404SSelvin Xavier 					     u8 event));
4301ac5a404SSelvin Xavier int bnxt_qplib_create_qp1(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
4311ac5a404SSelvin Xavier int bnxt_qplib_create_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
4321ac5a404SSelvin Xavier int bnxt_qplib_modify_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
4331ac5a404SSelvin Xavier int bnxt_qplib_query_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
4341ac5a404SSelvin Xavier int bnxt_qplib_destroy_qp(struct bnxt_qplib_res *res, struct bnxt_qplib_qp *qp);
4351ac5a404SSelvin Xavier void *bnxt_qplib_get_qp1_sq_buf(struct bnxt_qplib_qp *qp,
4361ac5a404SSelvin Xavier 				struct bnxt_qplib_sge *sge);
4371ac5a404SSelvin Xavier void *bnxt_qplib_get_qp1_rq_buf(struct bnxt_qplib_qp *qp,
4381ac5a404SSelvin Xavier 				struct bnxt_qplib_sge *sge);
4391ac5a404SSelvin Xavier u32 bnxt_qplib_get_rq_prod_index(struct bnxt_qplib_qp *qp);
4401ac5a404SSelvin Xavier dma_addr_t bnxt_qplib_get_qp_buf_from_index(struct bnxt_qplib_qp *qp,
4411ac5a404SSelvin Xavier 					    u32 index);
4421ac5a404SSelvin Xavier void bnxt_qplib_post_send_db(struct bnxt_qplib_qp *qp);
4431ac5a404SSelvin Xavier int bnxt_qplib_post_send(struct bnxt_qplib_qp *qp,
4441ac5a404SSelvin Xavier 			 struct bnxt_qplib_swqe *wqe);
4451ac5a404SSelvin Xavier void bnxt_qplib_post_recv_db(struct bnxt_qplib_qp *qp);
4461ac5a404SSelvin Xavier int bnxt_qplib_post_recv(struct bnxt_qplib_qp *qp,
4471ac5a404SSelvin Xavier 			 struct bnxt_qplib_swqe *wqe);
4481ac5a404SSelvin Xavier int bnxt_qplib_create_cq(struct bnxt_qplib_res *res, struct bnxt_qplib_cq *cq);
4491ac5a404SSelvin Xavier int bnxt_qplib_destroy_cq(struct bnxt_qplib_res *res, struct bnxt_qplib_cq *cq);
4501ac5a404SSelvin Xavier int bnxt_qplib_poll_cq(struct bnxt_qplib_cq *cq, struct bnxt_qplib_cqe *cqe,
4519152e0b7SEddie Wai 		       int num, struct bnxt_qplib_qp **qp);
4521ac5a404SSelvin Xavier void bnxt_qplib_req_notify_cq(struct bnxt_qplib_cq *cq, u32 arm_type);
4531ac5a404SSelvin Xavier void bnxt_qplib_free_nq(struct bnxt_qplib_nq *nq);
4541ac5a404SSelvin Xavier int bnxt_qplib_alloc_nq(struct pci_dev *pdev, struct bnxt_qplib_nq *nq);
4551ac5a404SSelvin Xavier #endif /* __BNXT_QPLIB_FP_H__ */
456