18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Broadcom NetXtreme-E RoCE driver.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2016 - 2017, Broadcom. All rights reserved.  The term
58c2ecf20Sopenharmony_ci * Broadcom refers to Broadcom Limited and/or its subsidiaries.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
88c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
98c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
108c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
118c2ecf20Sopenharmony_ci * BSD license below:
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
148c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
158c2ecf20Sopenharmony_ci * are met:
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
188c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
198c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
208c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
218c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
228c2ecf20Sopenharmony_ci *    distribution.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
258c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
268c2ecf20Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
278c2ecf20Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
288c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
298c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
308c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
318c2ecf20Sopenharmony_ci * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
328c2ecf20Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
338c2ecf20Sopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
348c2ecf20Sopenharmony_ci * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * Description: QPLib resource manager (header)
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#ifndef __BNXT_QPLIB_RES_H__
408c2ecf20Sopenharmony_ci#define __BNXT_QPLIB_RES_H__
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciextern const struct bnxt_qplib_gid bnxt_qplib_gid_zero;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define CHIP_NUM_57508		0x1750
458c2ecf20Sopenharmony_ci#define CHIP_NUM_57504		0x1751
468c2ecf20Sopenharmony_ci#define CHIP_NUM_57502		0x1752
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cienum bnxt_qplib_wqe_mode {
498c2ecf20Sopenharmony_ci	BNXT_QPLIB_WQE_MODE_STATIC	= 0x00,
508c2ecf20Sopenharmony_ci	BNXT_QPLIB_WQE_MODE_VARIABLE	= 0x01,
518c2ecf20Sopenharmony_ci	BNXT_QPLIB_WQE_MODE_INVALID	= 0x02
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct bnxt_qplib_drv_modes {
558c2ecf20Sopenharmony_ci	u8	wqe_mode;
568c2ecf20Sopenharmony_ci	/* Other modes to follow here */
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistruct bnxt_qplib_chip_ctx {
608c2ecf20Sopenharmony_ci	u16	chip_num;
618c2ecf20Sopenharmony_ci	u8	chip_rev;
628c2ecf20Sopenharmony_ci	u8	chip_metal;
638c2ecf20Sopenharmony_ci	u16	hw_stats_size;
648c2ecf20Sopenharmony_ci	struct bnxt_qplib_drv_modes modes;
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define PTR_CNT_PER_PG		(PAGE_SIZE / sizeof(void *))
688c2ecf20Sopenharmony_ci#define PTR_MAX_IDX_PER_PG	(PTR_CNT_PER_PG - 1)
698c2ecf20Sopenharmony_ci#define PTR_PG(x)		(((x) & ~PTR_MAX_IDX_PER_PG) / PTR_CNT_PER_PG)
708c2ecf20Sopenharmony_ci#define PTR_IDX(x)		((x) & PTR_MAX_IDX_PER_PG)
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#define HWQ_CMP(idx, hwq)	((idx) & ((hwq)->max_elements - 1))
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define HWQ_FREE_SLOTS(hwq)	(hwq->max_elements - \
758c2ecf20Sopenharmony_ci				((HWQ_CMP(hwq->prod, hwq)\
768c2ecf20Sopenharmony_ci				- HWQ_CMP(hwq->cons, hwq))\
778c2ecf20Sopenharmony_ci				& (hwq->max_elements - 1)))
788c2ecf20Sopenharmony_cienum bnxt_qplib_hwq_type {
798c2ecf20Sopenharmony_ci	HWQ_TYPE_CTX,
808c2ecf20Sopenharmony_ci	HWQ_TYPE_QUEUE,
818c2ecf20Sopenharmony_ci	HWQ_TYPE_L2_CMPL,
828c2ecf20Sopenharmony_ci	HWQ_TYPE_MR
838c2ecf20Sopenharmony_ci};
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#define MAX_PBL_LVL_0_PGS		1
868c2ecf20Sopenharmony_ci#define MAX_PBL_LVL_1_PGS		512
878c2ecf20Sopenharmony_ci#define MAX_PBL_LVL_1_PGS_SHIFT		9
888c2ecf20Sopenharmony_ci#define MAX_PBL_LVL_1_PGS_FOR_LVL_2	256
898c2ecf20Sopenharmony_ci#define MAX_PBL_LVL_2_PGS		(256 * 512)
908c2ecf20Sopenharmony_ci#define MAX_PDL_LVL_SHIFT               9
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cienum bnxt_qplib_pbl_lvl {
938c2ecf20Sopenharmony_ci	PBL_LVL_0,
948c2ecf20Sopenharmony_ci	PBL_LVL_1,
958c2ecf20Sopenharmony_ci	PBL_LVL_2,
968c2ecf20Sopenharmony_ci	PBL_LVL_MAX
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define ROCE_PG_SIZE_4K		(4 * 1024)
1008c2ecf20Sopenharmony_ci#define ROCE_PG_SIZE_8K		(8 * 1024)
1018c2ecf20Sopenharmony_ci#define ROCE_PG_SIZE_64K	(64 * 1024)
1028c2ecf20Sopenharmony_ci#define ROCE_PG_SIZE_2M		(2 * 1024 * 1024)
1038c2ecf20Sopenharmony_ci#define ROCE_PG_SIZE_8M		(8 * 1024 * 1024)
1048c2ecf20Sopenharmony_ci#define ROCE_PG_SIZE_1G		(1024 * 1024 * 1024)
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cienum bnxt_qplib_hwrm_pg_size {
1078c2ecf20Sopenharmony_ci	BNXT_QPLIB_HWRM_PG_SIZE_4K	= 0,
1088c2ecf20Sopenharmony_ci	BNXT_QPLIB_HWRM_PG_SIZE_8K	= 1,
1098c2ecf20Sopenharmony_ci	BNXT_QPLIB_HWRM_PG_SIZE_64K	= 2,
1108c2ecf20Sopenharmony_ci	BNXT_QPLIB_HWRM_PG_SIZE_2M	= 3,
1118c2ecf20Sopenharmony_ci	BNXT_QPLIB_HWRM_PG_SIZE_8M	= 4,
1128c2ecf20Sopenharmony_ci	BNXT_QPLIB_HWRM_PG_SIZE_1G	= 5,
1138c2ecf20Sopenharmony_ci};
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistruct bnxt_qplib_reg_desc {
1168c2ecf20Sopenharmony_ci	u8		bar_id;
1178c2ecf20Sopenharmony_ci	resource_size_t	bar_base;
1188c2ecf20Sopenharmony_ci	void __iomem	*bar_reg;
1198c2ecf20Sopenharmony_ci	size_t		len;
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistruct bnxt_qplib_pbl {
1238c2ecf20Sopenharmony_ci	u32				pg_count;
1248c2ecf20Sopenharmony_ci	u32				pg_size;
1258c2ecf20Sopenharmony_ci	void				**pg_arr;
1268c2ecf20Sopenharmony_ci	dma_addr_t			*pg_map_arr;
1278c2ecf20Sopenharmony_ci};
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistruct bnxt_qplib_sg_info {
1308c2ecf20Sopenharmony_ci	struct ib_umem			*umem;
1318c2ecf20Sopenharmony_ci	u32				npages;
1328c2ecf20Sopenharmony_ci	u32				pgshft;
1338c2ecf20Sopenharmony_ci	u32				pgsize;
1348c2ecf20Sopenharmony_ci	bool				nopte;
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistruct bnxt_qplib_hwq_attr {
1388c2ecf20Sopenharmony_ci	struct bnxt_qplib_res		*res;
1398c2ecf20Sopenharmony_ci	struct bnxt_qplib_sg_info	*sginfo;
1408c2ecf20Sopenharmony_ci	enum bnxt_qplib_hwq_type	type;
1418c2ecf20Sopenharmony_ci	u32				depth;
1428c2ecf20Sopenharmony_ci	u32				stride;
1438c2ecf20Sopenharmony_ci	u32				aux_stride;
1448c2ecf20Sopenharmony_ci	u32				aux_depth;
1458c2ecf20Sopenharmony_ci};
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistruct bnxt_qplib_hwq {
1488c2ecf20Sopenharmony_ci	struct pci_dev			*pdev;
1498c2ecf20Sopenharmony_ci	/* lock to protect qplib_hwq */
1508c2ecf20Sopenharmony_ci	spinlock_t			lock;
1518c2ecf20Sopenharmony_ci	struct bnxt_qplib_pbl		pbl[PBL_LVL_MAX + 1];
1528c2ecf20Sopenharmony_ci	enum bnxt_qplib_pbl_lvl		level;		/* 0, 1, or 2 */
1538c2ecf20Sopenharmony_ci	/* ptr for easy access to the PBL entries */
1548c2ecf20Sopenharmony_ci	void				**pbl_ptr;
1558c2ecf20Sopenharmony_ci	/* ptr for easy access to the dma_addr */
1568c2ecf20Sopenharmony_ci	dma_addr_t			*pbl_dma_ptr;
1578c2ecf20Sopenharmony_ci	u32				max_elements;
1588c2ecf20Sopenharmony_ci	u32				depth;
1598c2ecf20Sopenharmony_ci	u16				element_size;	/* Size of each entry */
1608c2ecf20Sopenharmony_ci	u16				qe_ppg;	/* queue entry per page */
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	u32				prod;		/* raw */
1638c2ecf20Sopenharmony_ci	u32				cons;		/* raw */
1648c2ecf20Sopenharmony_ci	u8				cp_bit;
1658c2ecf20Sopenharmony_ci	u8				is_user;
1668c2ecf20Sopenharmony_ci	u64				*pad_pg;
1678c2ecf20Sopenharmony_ci	u32				pad_stride;
1688c2ecf20Sopenharmony_ci	u32				pad_pgofft;
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistruct bnxt_qplib_db_info {
1728c2ecf20Sopenharmony_ci	void __iomem		*db;
1738c2ecf20Sopenharmony_ci	void __iomem		*priv_db;
1748c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq	*hwq;
1758c2ecf20Sopenharmony_ci	u32			xid;
1768c2ecf20Sopenharmony_ci	u32			max_slot;
1778c2ecf20Sopenharmony_ci};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/* Tables */
1808c2ecf20Sopenharmony_cistruct bnxt_qplib_pd_tbl {
1818c2ecf20Sopenharmony_ci	unsigned long			*tbl;
1828c2ecf20Sopenharmony_ci	u32				max;
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistruct bnxt_qplib_sgid_tbl {
1868c2ecf20Sopenharmony_ci	struct bnxt_qplib_gid_info	*tbl;
1878c2ecf20Sopenharmony_ci	u16				*hw_id;
1888c2ecf20Sopenharmony_ci	u16				max;
1898c2ecf20Sopenharmony_ci	u16				active;
1908c2ecf20Sopenharmony_ci	void				*ctx;
1918c2ecf20Sopenharmony_ci	u8				*vlan;
1928c2ecf20Sopenharmony_ci};
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistruct bnxt_qplib_pkey_tbl {
1958c2ecf20Sopenharmony_ci	u16				*tbl;
1968c2ecf20Sopenharmony_ci	u16				max;
1978c2ecf20Sopenharmony_ci	u16				active;
1988c2ecf20Sopenharmony_ci};
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistruct bnxt_qplib_dpi {
2018c2ecf20Sopenharmony_ci	u32				dpi;
2028c2ecf20Sopenharmony_ci	void __iomem			*dbr;
2038c2ecf20Sopenharmony_ci	u64				umdbr;
2048c2ecf20Sopenharmony_ci};
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistruct bnxt_qplib_dpi_tbl {
2078c2ecf20Sopenharmony_ci	void				**app_tbl;
2088c2ecf20Sopenharmony_ci	unsigned long			*tbl;
2098c2ecf20Sopenharmony_ci	u16				max;
2108c2ecf20Sopenharmony_ci	void __iomem			*dbr_bar_reg_iomem;
2118c2ecf20Sopenharmony_ci	u64				unmapped_dbr;
2128c2ecf20Sopenharmony_ci};
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistruct bnxt_qplib_stats {
2158c2ecf20Sopenharmony_ci	dma_addr_t			dma_map;
2168c2ecf20Sopenharmony_ci	void				*dma;
2178c2ecf20Sopenharmony_ci	u32				size;
2188c2ecf20Sopenharmony_ci	u32				fw_id;
2198c2ecf20Sopenharmony_ci};
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_cistruct bnxt_qplib_vf_res {
2228c2ecf20Sopenharmony_ci	u32 max_qp_per_vf;
2238c2ecf20Sopenharmony_ci	u32 max_mrw_per_vf;
2248c2ecf20Sopenharmony_ci	u32 max_srq_per_vf;
2258c2ecf20Sopenharmony_ci	u32 max_cq_per_vf;
2268c2ecf20Sopenharmony_ci	u32 max_gid_per_vf;
2278c2ecf20Sopenharmony_ci};
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci#define BNXT_QPLIB_MAX_QP_CTX_ENTRY_SIZE	448
2308c2ecf20Sopenharmony_ci#define BNXT_QPLIB_MAX_SRQ_CTX_ENTRY_SIZE	64
2318c2ecf20Sopenharmony_ci#define BNXT_QPLIB_MAX_CQ_CTX_ENTRY_SIZE	64
2328c2ecf20Sopenharmony_ci#define BNXT_QPLIB_MAX_MRW_CTX_ENTRY_SIZE	128
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci#define MAX_TQM_ALLOC_REQ               48
2358c2ecf20Sopenharmony_ci#define MAX_TQM_ALLOC_BLK_SIZE          8
2368c2ecf20Sopenharmony_cistruct bnxt_qplib_tqm_ctx {
2378c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq           pde;
2388c2ecf20Sopenharmony_ci	u8                              pde_level; /* Original level */
2398c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq           qtbl[MAX_TQM_ALLOC_REQ];
2408c2ecf20Sopenharmony_ci	u8                              qcount[MAX_TQM_ALLOC_REQ];
2418c2ecf20Sopenharmony_ci};
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cistruct bnxt_qplib_ctx {
2448c2ecf20Sopenharmony_ci	u32				qpc_count;
2458c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq		qpc_tbl;
2468c2ecf20Sopenharmony_ci	u32				mrw_count;
2478c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq		mrw_tbl;
2488c2ecf20Sopenharmony_ci	u32				srqc_count;
2498c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq		srqc_tbl;
2508c2ecf20Sopenharmony_ci	u32				cq_count;
2518c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq		cq_tbl;
2528c2ecf20Sopenharmony_ci	struct bnxt_qplib_hwq		tim_tbl;
2538c2ecf20Sopenharmony_ci	struct bnxt_qplib_tqm_ctx	tqm_ctx;
2548c2ecf20Sopenharmony_ci	struct bnxt_qplib_stats		stats;
2558c2ecf20Sopenharmony_ci	struct bnxt_qplib_vf_res	vf_res;
2568c2ecf20Sopenharmony_ci	u64				hwrm_intf_ver;
2578c2ecf20Sopenharmony_ci};
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistruct bnxt_qplib_res {
2608c2ecf20Sopenharmony_ci	struct pci_dev			*pdev;
2618c2ecf20Sopenharmony_ci	struct bnxt_qplib_chip_ctx	*cctx;
2628c2ecf20Sopenharmony_ci	struct net_device		*netdev;
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci	struct bnxt_qplib_rcfw		*rcfw;
2658c2ecf20Sopenharmony_ci	struct bnxt_qplib_pd_tbl	pd_tbl;
2668c2ecf20Sopenharmony_ci	struct bnxt_qplib_sgid_tbl	sgid_tbl;
2678c2ecf20Sopenharmony_ci	struct bnxt_qplib_pkey_tbl	pkey_tbl;
2688c2ecf20Sopenharmony_ci	struct bnxt_qplib_dpi_tbl	dpi_tbl;
2698c2ecf20Sopenharmony_ci	bool				prio;
2708c2ecf20Sopenharmony_ci};
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistatic inline bool bnxt_qplib_is_chip_gen_p5(struct bnxt_qplib_chip_ctx *cctx)
2738c2ecf20Sopenharmony_ci{
2748c2ecf20Sopenharmony_ci	return (cctx->chip_num == CHIP_NUM_57508 ||
2758c2ecf20Sopenharmony_ci		cctx->chip_num == CHIP_NUM_57504 ||
2768c2ecf20Sopenharmony_ci		cctx->chip_num == CHIP_NUM_57502);
2778c2ecf20Sopenharmony_ci}
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_cistatic inline u8 bnxt_qplib_get_hwq_type(struct bnxt_qplib_res *res)
2808c2ecf20Sopenharmony_ci{
2818c2ecf20Sopenharmony_ci	return bnxt_qplib_is_chip_gen_p5(res->cctx) ?
2828c2ecf20Sopenharmony_ci					HWQ_TYPE_QUEUE : HWQ_TYPE_L2_CMPL;
2838c2ecf20Sopenharmony_ci}
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_cistatic inline u8 bnxt_qplib_get_ring_type(struct bnxt_qplib_chip_ctx *cctx)
2868c2ecf20Sopenharmony_ci{
2878c2ecf20Sopenharmony_ci	return bnxt_qplib_is_chip_gen_p5(cctx) ?
2888c2ecf20Sopenharmony_ci	       RING_ALLOC_REQ_RING_TYPE_NQ :
2898c2ecf20Sopenharmony_ci	       RING_ALLOC_REQ_RING_TYPE_ROCE_CMPL;
2908c2ecf20Sopenharmony_ci}
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_cistatic inline u8 bnxt_qplib_base_pg_size(struct bnxt_qplib_hwq *hwq)
2938c2ecf20Sopenharmony_ci{
2948c2ecf20Sopenharmony_ci	u8 pg_size = BNXT_QPLIB_HWRM_PG_SIZE_4K;
2958c2ecf20Sopenharmony_ci	struct bnxt_qplib_pbl *pbl;
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	pbl = &hwq->pbl[PBL_LVL_0];
2988c2ecf20Sopenharmony_ci	switch (pbl->pg_size) {
2998c2ecf20Sopenharmony_ci	case ROCE_PG_SIZE_4K:
3008c2ecf20Sopenharmony_ci		pg_size = BNXT_QPLIB_HWRM_PG_SIZE_4K;
3018c2ecf20Sopenharmony_ci		break;
3028c2ecf20Sopenharmony_ci	case ROCE_PG_SIZE_8K:
3038c2ecf20Sopenharmony_ci		pg_size = BNXT_QPLIB_HWRM_PG_SIZE_8K;
3048c2ecf20Sopenharmony_ci		break;
3058c2ecf20Sopenharmony_ci	case ROCE_PG_SIZE_64K:
3068c2ecf20Sopenharmony_ci		pg_size = BNXT_QPLIB_HWRM_PG_SIZE_64K;
3078c2ecf20Sopenharmony_ci		break;
3088c2ecf20Sopenharmony_ci	case ROCE_PG_SIZE_2M:
3098c2ecf20Sopenharmony_ci		pg_size = BNXT_QPLIB_HWRM_PG_SIZE_2M;
3108c2ecf20Sopenharmony_ci		break;
3118c2ecf20Sopenharmony_ci	case ROCE_PG_SIZE_8M:
3128c2ecf20Sopenharmony_ci		pg_size = BNXT_QPLIB_HWRM_PG_SIZE_8M;
3138c2ecf20Sopenharmony_ci		break;
3148c2ecf20Sopenharmony_ci	case ROCE_PG_SIZE_1G:
3158c2ecf20Sopenharmony_ci		pg_size = BNXT_QPLIB_HWRM_PG_SIZE_1G;
3168c2ecf20Sopenharmony_ci		break;
3178c2ecf20Sopenharmony_ci	default:
3188c2ecf20Sopenharmony_ci		break;
3198c2ecf20Sopenharmony_ci	}
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	return pg_size;
3228c2ecf20Sopenharmony_ci}
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cistatic inline void *bnxt_qplib_get_qe(struct bnxt_qplib_hwq *hwq,
3258c2ecf20Sopenharmony_ci				      u32 indx, u64 *pg)
3268c2ecf20Sopenharmony_ci{
3278c2ecf20Sopenharmony_ci	u32 pg_num, pg_idx;
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	pg_num = (indx / hwq->qe_ppg);
3308c2ecf20Sopenharmony_ci	pg_idx = (indx % hwq->qe_ppg);
3318c2ecf20Sopenharmony_ci	if (pg)
3328c2ecf20Sopenharmony_ci		*pg = (u64)&hwq->pbl_ptr[pg_num];
3338c2ecf20Sopenharmony_ci	return (void *)(hwq->pbl_ptr[pg_num] + hwq->element_size * pg_idx);
3348c2ecf20Sopenharmony_ci}
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_cistatic inline void *bnxt_qplib_get_prod_qe(struct bnxt_qplib_hwq *hwq, u32 idx)
3378c2ecf20Sopenharmony_ci{
3388c2ecf20Sopenharmony_ci	idx += hwq->prod;
3398c2ecf20Sopenharmony_ci	if (idx >= hwq->depth)
3408c2ecf20Sopenharmony_ci		idx -= hwq->depth;
3418c2ecf20Sopenharmony_ci	return bnxt_qplib_get_qe(hwq, idx, NULL);
3428c2ecf20Sopenharmony_ci}
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci#define to_bnxt_qplib(ptr, type, member)	\
3458c2ecf20Sopenharmony_ci	container_of(ptr, type, member)
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_cistruct bnxt_qplib_pd;
3488c2ecf20Sopenharmony_cistruct bnxt_qplib_dev_attr;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_civoid bnxt_qplib_free_hwq(struct bnxt_qplib_res *res,
3518c2ecf20Sopenharmony_ci			 struct bnxt_qplib_hwq *hwq);
3528c2ecf20Sopenharmony_ciint bnxt_qplib_alloc_init_hwq(struct bnxt_qplib_hwq *hwq,
3538c2ecf20Sopenharmony_ci			      struct bnxt_qplib_hwq_attr *hwq_attr);
3548c2ecf20Sopenharmony_civoid bnxt_qplib_get_guid(u8 *dev_addr, u8 *guid);
3558c2ecf20Sopenharmony_ciint bnxt_qplib_alloc_pd(struct bnxt_qplib_pd_tbl *pd_tbl,
3568c2ecf20Sopenharmony_ci			struct bnxt_qplib_pd *pd);
3578c2ecf20Sopenharmony_ciint bnxt_qplib_dealloc_pd(struct bnxt_qplib_res *res,
3588c2ecf20Sopenharmony_ci			  struct bnxt_qplib_pd_tbl *pd_tbl,
3598c2ecf20Sopenharmony_ci			  struct bnxt_qplib_pd *pd);
3608c2ecf20Sopenharmony_ciint bnxt_qplib_alloc_dpi(struct bnxt_qplib_dpi_tbl *dpit,
3618c2ecf20Sopenharmony_ci			 struct bnxt_qplib_dpi     *dpi,
3628c2ecf20Sopenharmony_ci			 void                      *app);
3638c2ecf20Sopenharmony_ciint bnxt_qplib_dealloc_dpi(struct bnxt_qplib_res *res,
3648c2ecf20Sopenharmony_ci			   struct bnxt_qplib_dpi_tbl *dpi_tbl,
3658c2ecf20Sopenharmony_ci			   struct bnxt_qplib_dpi *dpi);
3668c2ecf20Sopenharmony_civoid bnxt_qplib_cleanup_res(struct bnxt_qplib_res *res);
3678c2ecf20Sopenharmony_ciint bnxt_qplib_init_res(struct bnxt_qplib_res *res);
3688c2ecf20Sopenharmony_civoid bnxt_qplib_free_res(struct bnxt_qplib_res *res);
3698c2ecf20Sopenharmony_ciint bnxt_qplib_alloc_res(struct bnxt_qplib_res *res, struct pci_dev *pdev,
3708c2ecf20Sopenharmony_ci			 struct net_device *netdev,
3718c2ecf20Sopenharmony_ci			 struct bnxt_qplib_dev_attr *dev_attr);
3728c2ecf20Sopenharmony_civoid bnxt_qplib_free_ctx(struct bnxt_qplib_res *res,
3738c2ecf20Sopenharmony_ci			 struct bnxt_qplib_ctx *ctx);
3748c2ecf20Sopenharmony_ciint bnxt_qplib_alloc_ctx(struct bnxt_qplib_res *res,
3758c2ecf20Sopenharmony_ci			 struct bnxt_qplib_ctx *ctx,
3768c2ecf20Sopenharmony_ci			 bool virt_fn, bool is_p5);
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_hwq_incr_prod(struct bnxt_qplib_hwq *hwq, u32 cnt)
3798c2ecf20Sopenharmony_ci{
3808c2ecf20Sopenharmony_ci	hwq->prod = (hwq->prod + cnt) % hwq->depth;
3818c2ecf20Sopenharmony_ci}
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_hwq_incr_cons(struct bnxt_qplib_hwq *hwq,
3848c2ecf20Sopenharmony_ci					    u32 cnt)
3858c2ecf20Sopenharmony_ci{
3868c2ecf20Sopenharmony_ci	hwq->cons = (hwq->cons + cnt) % hwq->depth;
3878c2ecf20Sopenharmony_ci}
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_ring_db32(struct bnxt_qplib_db_info *info,
3908c2ecf20Sopenharmony_ci					bool arm)
3918c2ecf20Sopenharmony_ci{
3928c2ecf20Sopenharmony_ci	u32 key;
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci	key = info->hwq->cons & (info->hwq->max_elements - 1);
3958c2ecf20Sopenharmony_ci	key |= (CMPL_DOORBELL_IDX_VALID |
3968c2ecf20Sopenharmony_ci		(CMPL_DOORBELL_KEY_CMPL & CMPL_DOORBELL_KEY_MASK));
3978c2ecf20Sopenharmony_ci	if (!arm)
3988c2ecf20Sopenharmony_ci		key |= CMPL_DOORBELL_MASK;
3998c2ecf20Sopenharmony_ci	writel(key, info->db);
4008c2ecf20Sopenharmony_ci}
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_ring_db(struct bnxt_qplib_db_info *info,
4038c2ecf20Sopenharmony_ci				      u32 type)
4048c2ecf20Sopenharmony_ci{
4058c2ecf20Sopenharmony_ci	u64 key = 0;
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_ci	key = (info->xid & DBC_DBC_XID_MASK) | DBC_DBC_PATH_ROCE | type;
4088c2ecf20Sopenharmony_ci	key <<= 32;
4098c2ecf20Sopenharmony_ci	key |= (info->hwq->cons & (info->hwq->max_elements - 1)) &
4108c2ecf20Sopenharmony_ci		DBC_DBC_INDEX_MASK;
4118c2ecf20Sopenharmony_ci	writeq(key, info->db);
4128c2ecf20Sopenharmony_ci}
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_ring_prod_db(struct bnxt_qplib_db_info *info,
4158c2ecf20Sopenharmony_ci					   u32 type)
4168c2ecf20Sopenharmony_ci{
4178c2ecf20Sopenharmony_ci	u64 key = 0;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	key = (info->xid & DBC_DBC_XID_MASK) | DBC_DBC_PATH_ROCE | type;
4208c2ecf20Sopenharmony_ci	key <<= 32;
4218c2ecf20Sopenharmony_ci	key |= ((info->hwq->prod / info->max_slot)) & DBC_DBC_INDEX_MASK;
4228c2ecf20Sopenharmony_ci	writeq(key, info->db);
4238c2ecf20Sopenharmony_ci}
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_armen_db(struct bnxt_qplib_db_info *info,
4268c2ecf20Sopenharmony_ci				       u32 type)
4278c2ecf20Sopenharmony_ci{
4288c2ecf20Sopenharmony_ci	u64 key = 0;
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	key = (info->xid & DBC_DBC_XID_MASK) | DBC_DBC_PATH_ROCE | type;
4318c2ecf20Sopenharmony_ci	key <<= 32;
4328c2ecf20Sopenharmony_ci	writeq(key, info->priv_db);
4338c2ecf20Sopenharmony_ci}
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_srq_arm_db(struct bnxt_qplib_db_info *info,
4368c2ecf20Sopenharmony_ci					 u32 th)
4378c2ecf20Sopenharmony_ci{
4388c2ecf20Sopenharmony_ci	u64 key = 0;
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	key = (info->xid & DBC_DBC_XID_MASK) | DBC_DBC_PATH_ROCE | th;
4418c2ecf20Sopenharmony_ci	key <<= 32;
4428c2ecf20Sopenharmony_ci	key |=  th & DBC_DBC_INDEX_MASK;
4438c2ecf20Sopenharmony_ci	writeq(key, info->priv_db);
4448c2ecf20Sopenharmony_ci}
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_cistatic inline void bnxt_qplib_ring_nq_db(struct bnxt_qplib_db_info *info,
4478c2ecf20Sopenharmony_ci					 struct bnxt_qplib_chip_ctx *cctx,
4488c2ecf20Sopenharmony_ci					 bool arm)
4498c2ecf20Sopenharmony_ci{
4508c2ecf20Sopenharmony_ci	u32 type;
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ci	type = arm ? DBC_DBC_TYPE_NQ_ARM : DBC_DBC_TYPE_NQ;
4538c2ecf20Sopenharmony_ci	if (bnxt_qplib_is_chip_gen_p5(cctx))
4548c2ecf20Sopenharmony_ci		bnxt_qplib_ring_db(info, type);
4558c2ecf20Sopenharmony_ci	else
4568c2ecf20Sopenharmony_ci		bnxt_qplib_ring_db32(info, arm);
4578c2ecf20Sopenharmony_ci}
4588c2ecf20Sopenharmony_ci#endif /* __BNXT_QPLIB_RES_H__ */
459