18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*  Marvell OcteonTx2 RVU Admin Function driver
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2018 Marvell International Ltd.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
78c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License version 2 as
88c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef RVU_H
128c2ecf20Sopenharmony_ci#define RVU_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/pci.h>
158c2ecf20Sopenharmony_ci#include "rvu_struct.h"
168c2ecf20Sopenharmony_ci#include "common.h"
178c2ecf20Sopenharmony_ci#include "mbox.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* PCI device IDs */
208c2ecf20Sopenharmony_ci#define	PCI_DEVID_OCTEONTX2_RVU_AF		0xA065
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* Subsystem Device ID */
238c2ecf20Sopenharmony_ci#define PCI_SUBSYS_DEVID_98XX                  0xB100
248c2ecf20Sopenharmony_ci#define PCI_SUBSYS_DEVID_96XX                  0xB200
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* PCI BAR nos */
278c2ecf20Sopenharmony_ci#define	PCI_AF_REG_BAR_NUM			0
288c2ecf20Sopenharmony_ci#define	PCI_PF_REG_BAR_NUM			2
298c2ecf20Sopenharmony_ci#define	PCI_MBOX_BAR_NUM			4
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define NAME_SIZE				32
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* PF_FUNC */
348c2ecf20Sopenharmony_ci#define RVU_PFVF_PF_SHIFT	10
358c2ecf20Sopenharmony_ci#define RVU_PFVF_PF_MASK	0x3F
368c2ecf20Sopenharmony_ci#define RVU_PFVF_FUNC_SHIFT	0
378c2ecf20Sopenharmony_ci#define RVU_PFVF_FUNC_MASK	0x3FF
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
408c2ecf20Sopenharmony_cistruct dump_ctx {
418c2ecf20Sopenharmony_ci	int	lf;
428c2ecf20Sopenharmony_ci	int	id;
438c2ecf20Sopenharmony_ci	bool	all;
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct rvu_debugfs {
478c2ecf20Sopenharmony_ci	struct dentry *root;
488c2ecf20Sopenharmony_ci	struct dentry *cgx_root;
498c2ecf20Sopenharmony_ci	struct dentry *cgx;
508c2ecf20Sopenharmony_ci	struct dentry *lmac;
518c2ecf20Sopenharmony_ci	struct dentry *npa;
528c2ecf20Sopenharmony_ci	struct dentry *nix;
538c2ecf20Sopenharmony_ci	struct dentry *npc;
548c2ecf20Sopenharmony_ci	struct dump_ctx npa_aura_ctx;
558c2ecf20Sopenharmony_ci	struct dump_ctx npa_pool_ctx;
568c2ecf20Sopenharmony_ci	struct dump_ctx nix_cq_ctx;
578c2ecf20Sopenharmony_ci	struct dump_ctx nix_rq_ctx;
588c2ecf20Sopenharmony_ci	struct dump_ctx nix_sq_ctx;
598c2ecf20Sopenharmony_ci	int npa_qsize_id;
608c2ecf20Sopenharmony_ci	int nix_qsize_id;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci#endif
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct rvu_work {
658c2ecf20Sopenharmony_ci	struct	work_struct work;
668c2ecf20Sopenharmony_ci	struct	rvu *rvu;
678c2ecf20Sopenharmony_ci	int num_msgs;
688c2ecf20Sopenharmony_ci	int up_num_msgs;
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistruct rsrc_bmap {
728c2ecf20Sopenharmony_ci	unsigned long *bmap;	/* Pointer to resource bitmap */
738c2ecf20Sopenharmony_ci	u16  max;		/* Max resource id or count */
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistruct rvu_block {
778c2ecf20Sopenharmony_ci	struct rsrc_bmap	lf;
788c2ecf20Sopenharmony_ci	struct admin_queue	*aq; /* NIX/NPA AQ */
798c2ecf20Sopenharmony_ci	u16  *fn_map; /* LF to pcifunc mapping */
808c2ecf20Sopenharmony_ci	bool multislot;
818c2ecf20Sopenharmony_ci	bool implemented;
828c2ecf20Sopenharmony_ci	u8   addr;  /* RVU_BLOCK_ADDR_E */
838c2ecf20Sopenharmony_ci	u8   type;  /* RVU_BLOCK_TYPE_E */
848c2ecf20Sopenharmony_ci	u8   lfshift;
858c2ecf20Sopenharmony_ci	u64  lookup_reg;
868c2ecf20Sopenharmony_ci	u64  pf_lfcnt_reg;
878c2ecf20Sopenharmony_ci	u64  vf_lfcnt_reg;
888c2ecf20Sopenharmony_ci	u64  lfcfg_reg;
898c2ecf20Sopenharmony_ci	u64  msixcfg_reg;
908c2ecf20Sopenharmony_ci	u64  lfreset_reg;
918c2ecf20Sopenharmony_ci	unsigned char name[NAME_SIZE];
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistruct nix_mcast {
958c2ecf20Sopenharmony_ci	struct qmem	*mce_ctx;
968c2ecf20Sopenharmony_ci	struct qmem	*mcast_buf;
978c2ecf20Sopenharmony_ci	int		replay_pkind;
988c2ecf20Sopenharmony_ci	int		next_free_mce;
998c2ecf20Sopenharmony_ci	struct mutex	mce_lock; /* Serialize MCE updates */
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_cistruct nix_mce_list {
1038c2ecf20Sopenharmony_ci	struct hlist_head	head;
1048c2ecf20Sopenharmony_ci	int			count;
1058c2ecf20Sopenharmony_ci	int			max;
1068c2ecf20Sopenharmony_ci};
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistruct npc_mcam {
1098c2ecf20Sopenharmony_ci	struct rsrc_bmap counters;
1108c2ecf20Sopenharmony_ci	struct mutex	lock;	/* MCAM entries and counters update lock */
1118c2ecf20Sopenharmony_ci	unsigned long	*bmap;		/* bitmap, 0 => bmap_entries */
1128c2ecf20Sopenharmony_ci	unsigned long	*bmap_reverse;	/* Reverse bitmap, bmap_entries => 0 */
1138c2ecf20Sopenharmony_ci	u16	bmap_entries;	/* Number of unreserved MCAM entries */
1148c2ecf20Sopenharmony_ci	u16	bmap_fcnt;	/* MCAM entries free count */
1158c2ecf20Sopenharmony_ci	u16	*entry2pfvf_map;
1168c2ecf20Sopenharmony_ci	u16	*entry2cntr_map;
1178c2ecf20Sopenharmony_ci	u16	*cntr2pfvf_map;
1188c2ecf20Sopenharmony_ci	u16	*cntr_refcnt;
1198c2ecf20Sopenharmony_ci	u8	keysize;	/* MCAM keysize 112/224/448 bits */
1208c2ecf20Sopenharmony_ci	u8	banks;		/* Number of MCAM banks */
1218c2ecf20Sopenharmony_ci	u8	banks_per_entry;/* Number of keywords in key */
1228c2ecf20Sopenharmony_ci	u16	banksize;	/* Number of MCAM entries in each bank */
1238c2ecf20Sopenharmony_ci	u16	total_entries;	/* Total number of MCAM entries */
1248c2ecf20Sopenharmony_ci	u16	nixlf_offset;	/* Offset of nixlf rsvd uncast entries */
1258c2ecf20Sopenharmony_ci	u16	pf_offset;	/* Offset of PF's rsvd bcast, promisc entries */
1268c2ecf20Sopenharmony_ci	u16	lprio_count;
1278c2ecf20Sopenharmony_ci	u16	lprio_start;
1288c2ecf20Sopenharmony_ci	u16	hprio_count;
1298c2ecf20Sopenharmony_ci	u16	hprio_end;
1308c2ecf20Sopenharmony_ci	u16     rx_miss_act_cntr; /* Counter for RX MISS action */
1318c2ecf20Sopenharmony_ci};
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci/* Structure for per RVU func info ie PF/VF */
1348c2ecf20Sopenharmony_cistruct rvu_pfvf {
1358c2ecf20Sopenharmony_ci	bool		npalf; /* Only one NPALF per RVU_FUNC */
1368c2ecf20Sopenharmony_ci	bool		nixlf; /* Only one NIXLF per RVU_FUNC */
1378c2ecf20Sopenharmony_ci	u16		sso;
1388c2ecf20Sopenharmony_ci	u16		ssow;
1398c2ecf20Sopenharmony_ci	u16		cptlfs;
1408c2ecf20Sopenharmony_ci	u16		timlfs;
1418c2ecf20Sopenharmony_ci	u16		cpt1_lfs;
1428c2ecf20Sopenharmony_ci	u8		cgx_lmac;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	/* Block LF's MSIX vector info */
1458c2ecf20Sopenharmony_ci	struct rsrc_bmap msix;      /* Bitmap for MSIX vector alloc */
1468c2ecf20Sopenharmony_ci#define MSIX_BLKLF(blkaddr, lf) (((blkaddr) << 8) | ((lf) & 0xFF))
1478c2ecf20Sopenharmony_ci	u16		 *msix_lfmap; /* Vector to block LF mapping */
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	/* NPA contexts */
1508c2ecf20Sopenharmony_ci	struct qmem	*aura_ctx;
1518c2ecf20Sopenharmony_ci	struct qmem	*pool_ctx;
1528c2ecf20Sopenharmony_ci	struct qmem	*npa_qints_ctx;
1538c2ecf20Sopenharmony_ci	unsigned long	*aura_bmap;
1548c2ecf20Sopenharmony_ci	unsigned long	*pool_bmap;
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	/* NIX contexts */
1578c2ecf20Sopenharmony_ci	struct qmem	*rq_ctx;
1588c2ecf20Sopenharmony_ci	struct qmem	*sq_ctx;
1598c2ecf20Sopenharmony_ci	struct qmem	*cq_ctx;
1608c2ecf20Sopenharmony_ci	struct qmem	*rss_ctx;
1618c2ecf20Sopenharmony_ci	struct qmem	*cq_ints_ctx;
1628c2ecf20Sopenharmony_ci	struct qmem	*nix_qints_ctx;
1638c2ecf20Sopenharmony_ci	unsigned long	*sq_bmap;
1648c2ecf20Sopenharmony_ci	unsigned long	*rq_bmap;
1658c2ecf20Sopenharmony_ci	unsigned long	*cq_bmap;
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci	u16		rx_chan_base;
1688c2ecf20Sopenharmony_ci	u16		tx_chan_base;
1698c2ecf20Sopenharmony_ci	u8              rx_chan_cnt; /* total number of RX channels */
1708c2ecf20Sopenharmony_ci	u8              tx_chan_cnt; /* total number of TX channels */
1718c2ecf20Sopenharmony_ci	u16		maxlen;
1728c2ecf20Sopenharmony_ci	u16		minlen;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	u8		mac_addr[ETH_ALEN]; /* MAC address of this PF/VF */
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	/* Broadcast pkt replication info */
1778c2ecf20Sopenharmony_ci	u16			bcast_mce_idx;
1788c2ecf20Sopenharmony_ci	struct nix_mce_list	bcast_mce_list;
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci	/* VLAN offload */
1818c2ecf20Sopenharmony_ci	struct mcam_entry entry;
1828c2ecf20Sopenharmony_ci	int rxvlan_index;
1838c2ecf20Sopenharmony_ci	bool rxvlan;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	bool	cgx_in_use; /* this PF/VF using CGX? */
1868c2ecf20Sopenharmony_ci	int	cgx_users;  /* number of cgx users - used only by PFs */
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	u8	nix_blkaddr; /* BLKADDR_NIX0/1 assigned to this PF */
1898c2ecf20Sopenharmony_ci};
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistruct nix_txsch {
1928c2ecf20Sopenharmony_ci	struct rsrc_bmap schq;
1938c2ecf20Sopenharmony_ci	u8   lvl;
1948c2ecf20Sopenharmony_ci#define NIX_TXSCHQ_FREE		      BIT_ULL(1)
1958c2ecf20Sopenharmony_ci#define NIX_TXSCHQ_CFG_DONE	      BIT_ULL(0)
1968c2ecf20Sopenharmony_ci#define TXSCH_MAP_FUNC(__pfvf_map)    ((__pfvf_map) & 0xFFFF)
1978c2ecf20Sopenharmony_ci#define TXSCH_MAP_FLAGS(__pfvf_map)   ((__pfvf_map) >> 16)
1988c2ecf20Sopenharmony_ci#define TXSCH_MAP(__func, __flags)    (((__func) & 0xFFFF) | ((__flags) << 16))
1998c2ecf20Sopenharmony_ci#define TXSCH_SET_FLAG(__pfvf_map, flag)    ((__pfvf_map) | ((flag) << 16))
2008c2ecf20Sopenharmony_ci	u32  *pfvf_map;
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistruct nix_mark_format {
2048c2ecf20Sopenharmony_ci	u8 total;
2058c2ecf20Sopenharmony_ci	u8 in_use;
2068c2ecf20Sopenharmony_ci	u32 *cfg;
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistruct npc_pkind {
2108c2ecf20Sopenharmony_ci	struct rsrc_bmap rsrc;
2118c2ecf20Sopenharmony_ci	u32	*pfchan_map;
2128c2ecf20Sopenharmony_ci};
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistruct nix_flowkey {
2158c2ecf20Sopenharmony_ci#define NIX_FLOW_KEY_ALG_MAX 32
2168c2ecf20Sopenharmony_ci	u32 flowkey[NIX_FLOW_KEY_ALG_MAX];
2178c2ecf20Sopenharmony_ci	int in_use;
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistruct nix_lso {
2218c2ecf20Sopenharmony_ci	u8 total;
2228c2ecf20Sopenharmony_ci	u8 in_use;
2238c2ecf20Sopenharmony_ci};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistruct nix_hw {
2268c2ecf20Sopenharmony_ci	struct nix_txsch txsch[NIX_TXSCH_LVL_CNT]; /* Tx schedulers */
2278c2ecf20Sopenharmony_ci	struct nix_mcast mcast;
2288c2ecf20Sopenharmony_ci	struct nix_flowkey flowkey;
2298c2ecf20Sopenharmony_ci	struct nix_mark_format mark_format;
2308c2ecf20Sopenharmony_ci	struct nix_lso lso;
2318c2ecf20Sopenharmony_ci};
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci/* RVU block's capabilities or functionality,
2348c2ecf20Sopenharmony_ci * which vary by silicon version/skew.
2358c2ecf20Sopenharmony_ci */
2368c2ecf20Sopenharmony_cistruct hw_cap {
2378c2ecf20Sopenharmony_ci	/* Transmit side supported functionality */
2388c2ecf20Sopenharmony_ci	u8	nix_tx_aggr_lvl; /* Tx link's traffic aggregation level */
2398c2ecf20Sopenharmony_ci	u16	nix_txsch_per_cgx_lmac; /* Max Q's transmitting to CGX LMAC */
2408c2ecf20Sopenharmony_ci	u16	nix_txsch_per_lbk_lmac; /* Max Q's transmitting to LBK LMAC */
2418c2ecf20Sopenharmony_ci	u16	nix_txsch_per_sdp_lmac; /* Max Q's transmitting to SDP LMAC */
2428c2ecf20Sopenharmony_ci	bool	nix_fixed_txschq_mapping; /* Schq mapping fixed or flexible */
2438c2ecf20Sopenharmony_ci	bool	nix_shaping;		 /* Is shaping and coloring supported */
2448c2ecf20Sopenharmony_ci	bool	nix_tx_link_bp;		 /* Can link backpressure TL queues ? */
2458c2ecf20Sopenharmony_ci	bool	nix_rx_multicast;	 /* Rx packet replication support */
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistruct rvu_hwinfo {
2498c2ecf20Sopenharmony_ci	u8	total_pfs;   /* MAX RVU PFs HW supports */
2508c2ecf20Sopenharmony_ci	u16	total_vfs;   /* Max RVU VFs HW supports */
2518c2ecf20Sopenharmony_ci	u16	max_vfs_per_pf; /* Max VFs that can be attached to a PF */
2528c2ecf20Sopenharmony_ci	u8	cgx;
2538c2ecf20Sopenharmony_ci	u8	lmac_per_cgx;
2548c2ecf20Sopenharmony_ci	u8	cgx_links;
2558c2ecf20Sopenharmony_ci	u8	lbk_links;
2568c2ecf20Sopenharmony_ci	u8	sdp_links;
2578c2ecf20Sopenharmony_ci	u8	npc_kpus;          /* No of parser units */
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	struct hw_cap    cap;
2608c2ecf20Sopenharmony_ci	struct rvu_block block[BLK_COUNT]; /* Block info */
2618c2ecf20Sopenharmony_ci	struct nix_hw    *nix0;
2628c2ecf20Sopenharmony_ci	struct npc_pkind pkind;
2638c2ecf20Sopenharmony_ci	struct npc_mcam  mcam;
2648c2ecf20Sopenharmony_ci};
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistruct mbox_wq_info {
2678c2ecf20Sopenharmony_ci	struct otx2_mbox mbox;
2688c2ecf20Sopenharmony_ci	struct rvu_work *mbox_wrk;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	struct otx2_mbox mbox_up;
2718c2ecf20Sopenharmony_ci	struct rvu_work *mbox_wrk_up;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	struct workqueue_struct *mbox_wq;
2748c2ecf20Sopenharmony_ci};
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_cistruct rvu_fwdata {
2778c2ecf20Sopenharmony_ci#define RVU_FWDATA_HEADER_MAGIC	0xCFDA	/* Custom Firmware Data*/
2788c2ecf20Sopenharmony_ci#define RVU_FWDATA_VERSION	0x0001
2798c2ecf20Sopenharmony_ci	u32 header_magic;
2808c2ecf20Sopenharmony_ci	u32 version;		/* version id */
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	/* MAC address */
2838c2ecf20Sopenharmony_ci#define PF_MACNUM_MAX	32
2848c2ecf20Sopenharmony_ci#define VF_MACNUM_MAX	256
2858c2ecf20Sopenharmony_ci	u64 pf_macs[PF_MACNUM_MAX];
2868c2ecf20Sopenharmony_ci	u64 vf_macs[VF_MACNUM_MAX];
2878c2ecf20Sopenharmony_ci	u64 sclk;
2888c2ecf20Sopenharmony_ci	u64 rclk;
2898c2ecf20Sopenharmony_ci	u64 mcam_addr;
2908c2ecf20Sopenharmony_ci	u64 mcam_sz;
2918c2ecf20Sopenharmony_ci	u64 msixtr_base;
2928c2ecf20Sopenharmony_ci#define FWDATA_RESERVED_MEM 1023
2938c2ecf20Sopenharmony_ci	u64 reserved[FWDATA_RESERVED_MEM];
2948c2ecf20Sopenharmony_ci};
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_cistruct ptp;
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci/* KPU profile adapter structure gathering all KPU configuration data and abstracting out the
2998c2ecf20Sopenharmony_ci * source where it came from.
3008c2ecf20Sopenharmony_ci */
3018c2ecf20Sopenharmony_cistruct npc_kpu_profile_adapter {
3028c2ecf20Sopenharmony_ci	const char			*name;
3038c2ecf20Sopenharmony_ci	u64				version;
3048c2ecf20Sopenharmony_ci	const struct npc_lt_def_cfg	*lt_def;
3058c2ecf20Sopenharmony_ci	const struct npc_kpu_profile_action	*ikpu; /* array[pkinds] */
3068c2ecf20Sopenharmony_ci	const struct npc_kpu_profile	*kpu; /* array[kpus] */
3078c2ecf20Sopenharmony_ci	const struct npc_mcam_kex	*mkex;
3088c2ecf20Sopenharmony_ci	size_t				pkinds;
3098c2ecf20Sopenharmony_ci	size_t				kpus;
3108c2ecf20Sopenharmony_ci};
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_cistruct rvu {
3138c2ecf20Sopenharmony_ci	void __iomem		*afreg_base;
3148c2ecf20Sopenharmony_ci	void __iomem		*pfreg_base;
3158c2ecf20Sopenharmony_ci	struct pci_dev		*pdev;
3168c2ecf20Sopenharmony_ci	struct device		*dev;
3178c2ecf20Sopenharmony_ci	struct rvu_hwinfo       *hw;
3188c2ecf20Sopenharmony_ci	struct rvu_pfvf		*pf;
3198c2ecf20Sopenharmony_ci	struct rvu_pfvf		*hwvf;
3208c2ecf20Sopenharmony_ci	struct mutex		rsrc_lock; /* Serialize resource alloc/free */
3218c2ecf20Sopenharmony_ci	int			vfs; /* Number of VFs attached to RVU */
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	/* Mbox */
3248c2ecf20Sopenharmony_ci	struct mbox_wq_info	afpf_wq_info;
3258c2ecf20Sopenharmony_ci	struct mbox_wq_info	afvf_wq_info;
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci	/* PF FLR */
3288c2ecf20Sopenharmony_ci	struct rvu_work		*flr_wrk;
3298c2ecf20Sopenharmony_ci	struct workqueue_struct *flr_wq;
3308c2ecf20Sopenharmony_ci	struct mutex		flr_lock; /* Serialize FLRs */
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	/* MSI-X */
3338c2ecf20Sopenharmony_ci	u16			num_vec;
3348c2ecf20Sopenharmony_ci	char			*irq_name;
3358c2ecf20Sopenharmony_ci	bool			*irq_allocated;
3368c2ecf20Sopenharmony_ci	dma_addr_t		msix_base_iova;
3378c2ecf20Sopenharmony_ci	u64			msixtr_base_phy; /* Register reset value */
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	/* CGX */
3408c2ecf20Sopenharmony_ci#define PF_CGXMAP_BASE		1 /* PF 0 is reserved for RVU PF */
3418c2ecf20Sopenharmony_ci	u8			cgx_mapped_pfs;
3428c2ecf20Sopenharmony_ci	u8			cgx_cnt_max;	 /* CGX port count max */
3438c2ecf20Sopenharmony_ci	u8			*pf2cgxlmac_map; /* pf to cgx_lmac map */
3448c2ecf20Sopenharmony_ci	u16			*cgxlmac2pf_map; /* bitmap of mapped pfs for
3458c2ecf20Sopenharmony_ci						  * every cgx lmac port
3468c2ecf20Sopenharmony_ci						  */
3478c2ecf20Sopenharmony_ci	unsigned long		pf_notify_bmap; /* Flags for PF notification */
3488c2ecf20Sopenharmony_ci	void			**cgx_idmap; /* cgx id to cgx data map table */
3498c2ecf20Sopenharmony_ci	struct			work_struct cgx_evh_work;
3508c2ecf20Sopenharmony_ci	struct			workqueue_struct *cgx_evh_wq;
3518c2ecf20Sopenharmony_ci	spinlock_t		cgx_evq_lock; /* cgx event queue lock */
3528c2ecf20Sopenharmony_ci	struct list_head	cgx_evq_head; /* cgx event queue head */
3538c2ecf20Sopenharmony_ci	struct mutex		cgx_cfg_lock; /* serialize cgx configuration */
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	char mkex_pfl_name[MKEX_NAME_LEN]; /* Configured MKEX profile name */
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	/* Firmware data */
3588c2ecf20Sopenharmony_ci	struct rvu_fwdata	*fwdata;
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	/* NPC KPU data */
3618c2ecf20Sopenharmony_ci	struct npc_kpu_profile_adapter kpu;
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_ci	struct ptp		*ptp;
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
3668c2ecf20Sopenharmony_ci	struct rvu_debugfs	rvu_dbg;
3678c2ecf20Sopenharmony_ci#endif
3688c2ecf20Sopenharmony_ci};
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_cistatic inline void rvu_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	writeq(val, rvu->afreg_base + ((block << 28) | offset));
3738c2ecf20Sopenharmony_ci}
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_cistatic inline u64 rvu_read64(struct rvu *rvu, u64 block, u64 offset)
3768c2ecf20Sopenharmony_ci{
3778c2ecf20Sopenharmony_ci	return readq(rvu->afreg_base + ((block << 28) | offset));
3788c2ecf20Sopenharmony_ci}
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_cistatic inline void rvupf_write64(struct rvu *rvu, u64 offset, u64 val)
3818c2ecf20Sopenharmony_ci{
3828c2ecf20Sopenharmony_ci	writeq(val, rvu->pfreg_base + offset);
3838c2ecf20Sopenharmony_ci}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_cistatic inline u64 rvupf_read64(struct rvu *rvu, u64 offset)
3868c2ecf20Sopenharmony_ci{
3878c2ecf20Sopenharmony_ci	return readq(rvu->pfreg_base + offset);
3888c2ecf20Sopenharmony_ci}
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci/* Silicon revisions */
3918c2ecf20Sopenharmony_cistatic inline bool is_rvu_96xx_A0(struct rvu *rvu)
3928c2ecf20Sopenharmony_ci{
3938c2ecf20Sopenharmony_ci	struct pci_dev *pdev = rvu->pdev;
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	return (pdev->revision == 0x00) &&
3968c2ecf20Sopenharmony_ci		(pdev->subsystem_device == PCI_SUBSYS_DEVID_96XX);
3978c2ecf20Sopenharmony_ci}
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_cistatic inline bool is_rvu_96xx_B0(struct rvu *rvu)
4008c2ecf20Sopenharmony_ci{
4018c2ecf20Sopenharmony_ci	struct pci_dev *pdev = rvu->pdev;
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	return ((pdev->revision == 0x00) || (pdev->revision == 0x01)) &&
4048c2ecf20Sopenharmony_ci		(pdev->subsystem_device == PCI_SUBSYS_DEVID_96XX);
4058c2ecf20Sopenharmony_ci}
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_cistatic inline bool is_rvu_supports_nix1(struct rvu *rvu)
4088c2ecf20Sopenharmony_ci{
4098c2ecf20Sopenharmony_ci	struct pci_dev *pdev = rvu->pdev;
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	if (pdev->subsystem_device == PCI_SUBSYS_DEVID_98XX)
4128c2ecf20Sopenharmony_ci		return true;
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	return false;
4158c2ecf20Sopenharmony_ci}
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ci/* Function Prototypes
4188c2ecf20Sopenharmony_ci * RVU
4198c2ecf20Sopenharmony_ci */
4208c2ecf20Sopenharmony_cistatic inline int is_afvf(u16 pcifunc)
4218c2ecf20Sopenharmony_ci{
4228c2ecf20Sopenharmony_ci	return !(pcifunc & ~RVU_PFVF_FUNC_MASK);
4238c2ecf20Sopenharmony_ci}
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_cistatic inline bool is_rvu_fwdata_valid(struct rvu *rvu)
4268c2ecf20Sopenharmony_ci{
4278c2ecf20Sopenharmony_ci	return (rvu->fwdata->header_magic == RVU_FWDATA_HEADER_MAGIC) &&
4288c2ecf20Sopenharmony_ci		(rvu->fwdata->version == RVU_FWDATA_VERSION);
4298c2ecf20Sopenharmony_ci}
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ciint rvu_alloc_bitmap(struct rsrc_bmap *rsrc);
4328c2ecf20Sopenharmony_ciint rvu_alloc_rsrc(struct rsrc_bmap *rsrc);
4338c2ecf20Sopenharmony_civoid rvu_free_rsrc(struct rsrc_bmap *rsrc, int id);
4348c2ecf20Sopenharmony_ciint rvu_rsrc_free_count(struct rsrc_bmap *rsrc);
4358c2ecf20Sopenharmony_ciint rvu_alloc_rsrc_contig(struct rsrc_bmap *rsrc, int nrsrc);
4368c2ecf20Sopenharmony_cibool rvu_rsrc_check_contig(struct rsrc_bmap *rsrc, int nrsrc);
4378c2ecf20Sopenharmony_ciu16 rvu_get_rsrc_mapcount(struct rvu_pfvf *pfvf, int blkaddr);
4388c2ecf20Sopenharmony_ciint rvu_get_pf(u16 pcifunc);
4398c2ecf20Sopenharmony_cistruct rvu_pfvf *rvu_get_pfvf(struct rvu *rvu, int pcifunc);
4408c2ecf20Sopenharmony_civoid rvu_get_pf_numvfs(struct rvu *rvu, int pf, int *numvfs, int *hwvf);
4418c2ecf20Sopenharmony_cibool is_block_implemented(struct rvu_hwinfo *hw, int blkaddr);
4428c2ecf20Sopenharmony_cibool is_pffunc_map_valid(struct rvu *rvu, u16 pcifunc, int blktype);
4438c2ecf20Sopenharmony_ciint rvu_get_lf(struct rvu *rvu, struct rvu_block *block, u16 pcifunc, u16 slot);
4448c2ecf20Sopenharmony_ciint rvu_lf_reset(struct rvu *rvu, struct rvu_block *block, int lf);
4458c2ecf20Sopenharmony_ciint rvu_get_blkaddr(struct rvu *rvu, int blktype, u16 pcifunc);
4468c2ecf20Sopenharmony_ciint rvu_poll_reg(struct rvu *rvu, u64 block, u64 offset, u64 mask, bool zero);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci/* RVU HW reg validation */
4498c2ecf20Sopenharmony_cienum regmap_block {
4508c2ecf20Sopenharmony_ci	TXSCHQ_HWREGMAP = 0,
4518c2ecf20Sopenharmony_ci	MAX_HWREGMAP,
4528c2ecf20Sopenharmony_ci};
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_cibool rvu_check_valid_reg(int regmap, int regblk, u64 reg);
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci/* NPA/NIX AQ APIs */
4578c2ecf20Sopenharmony_ciint rvu_aq_alloc(struct rvu *rvu, struct admin_queue **ad_queue,
4588c2ecf20Sopenharmony_ci		 int qsize, int inst_size, int res_size);
4598c2ecf20Sopenharmony_civoid rvu_aq_free(struct rvu *rvu, struct admin_queue *aq);
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci/* CGX APIs */
4628c2ecf20Sopenharmony_cistatic inline bool is_pf_cgxmapped(struct rvu *rvu, u8 pf)
4638c2ecf20Sopenharmony_ci{
4648c2ecf20Sopenharmony_ci	return (pf >= PF_CGXMAP_BASE && pf <= rvu->cgx_mapped_pfs);
4658c2ecf20Sopenharmony_ci}
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_cistatic inline void rvu_get_cgx_lmac_id(u8 map, u8 *cgx_id, u8 *lmac_id)
4688c2ecf20Sopenharmony_ci{
4698c2ecf20Sopenharmony_ci	*cgx_id = (map >> 4) & 0xF;
4708c2ecf20Sopenharmony_ci	*lmac_id = (map & 0xF);
4718c2ecf20Sopenharmony_ci}
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci#define M(_name, _id, fn_name, req, rsp)				\
4748c2ecf20Sopenharmony_ciint rvu_mbox_handler_ ## fn_name(struct rvu *, struct req *, struct rsp *);
4758c2ecf20Sopenharmony_ciMBOX_MESSAGES
4768c2ecf20Sopenharmony_ci#undef M
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ciint rvu_cgx_init(struct rvu *rvu);
4798c2ecf20Sopenharmony_ciint rvu_cgx_exit(struct rvu *rvu);
4808c2ecf20Sopenharmony_civoid *rvu_cgx_pdata(u8 cgx_id, struct rvu *rvu);
4818c2ecf20Sopenharmony_ciint rvu_cgx_config_rxtx(struct rvu *rvu, u16 pcifunc, bool start);
4828c2ecf20Sopenharmony_civoid rvu_cgx_enadis_rx_bp(struct rvu *rvu, int pf, bool enable);
4838c2ecf20Sopenharmony_ciint rvu_cgx_start_stop_io(struct rvu *rvu, u16 pcifunc, bool start);
4848c2ecf20Sopenharmony_ciint rvu_cgx_nix_cuml_stats(struct rvu *rvu, void *cgxd, int lmac_id, int index,
4858c2ecf20Sopenharmony_ci			   int rxtxflag, u64 *stat);
4868c2ecf20Sopenharmony_ci/* NPA APIs */
4878c2ecf20Sopenharmony_ciint rvu_npa_init(struct rvu *rvu);
4888c2ecf20Sopenharmony_civoid rvu_npa_freemem(struct rvu *rvu);
4898c2ecf20Sopenharmony_civoid rvu_npa_lf_teardown(struct rvu *rvu, u16 pcifunc, int npalf);
4908c2ecf20Sopenharmony_ciint rvu_npa_aq_enq_inst(struct rvu *rvu, struct npa_aq_enq_req *req,
4918c2ecf20Sopenharmony_ci			struct npa_aq_enq_rsp *rsp);
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci/* NIX APIs */
4948c2ecf20Sopenharmony_cibool is_nixlf_attached(struct rvu *rvu, u16 pcifunc);
4958c2ecf20Sopenharmony_ciint rvu_nix_init(struct rvu *rvu);
4968c2ecf20Sopenharmony_ciint rvu_nix_reserve_mark_format(struct rvu *rvu, struct nix_hw *nix_hw,
4978c2ecf20Sopenharmony_ci				int blkaddr, u32 cfg);
4988c2ecf20Sopenharmony_civoid rvu_nix_freemem(struct rvu *rvu);
4998c2ecf20Sopenharmony_ciint rvu_get_nixlf_count(struct rvu *rvu);
5008c2ecf20Sopenharmony_civoid rvu_nix_lf_teardown(struct rvu *rvu, u16 pcifunc, int blkaddr, int npalf);
5018c2ecf20Sopenharmony_ciint nix_get_nixlf(struct rvu *rvu, u16 pcifunc, int *nixlf, int *nix_blkaddr);
5028c2ecf20Sopenharmony_ciint nix_update_bcast_mce_list(struct rvu *rvu, u16 pcifunc, bool add);
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci/* NPC APIs */
5058c2ecf20Sopenharmony_ciint rvu_npc_init(struct rvu *rvu);
5068c2ecf20Sopenharmony_civoid rvu_npc_freemem(struct rvu *rvu);
5078c2ecf20Sopenharmony_ciint rvu_npc_get_pkind(struct rvu *rvu, u16 pf);
5088c2ecf20Sopenharmony_civoid rvu_npc_set_pkind(struct rvu *rvu, int pkind, struct rvu_pfvf *pfvf);
5098c2ecf20Sopenharmony_ciint npc_config_ts_kpuaction(struct rvu *rvu, int pf, u16 pcifunc, bool en);
5108c2ecf20Sopenharmony_civoid rvu_npc_install_ucast_entry(struct rvu *rvu, u16 pcifunc,
5118c2ecf20Sopenharmony_ci				 int nixlf, u64 chan, u8 *mac_addr);
5128c2ecf20Sopenharmony_civoid rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,
5138c2ecf20Sopenharmony_ci				   int nixlf, u64 chan, bool allmulti);
5148c2ecf20Sopenharmony_civoid rvu_npc_disable_promisc_entry(struct rvu *rvu, u16 pcifunc, int nixlf);
5158c2ecf20Sopenharmony_civoid rvu_npc_enable_promisc_entry(struct rvu *rvu, u16 pcifunc, int nixlf);
5168c2ecf20Sopenharmony_civoid rvu_npc_install_bcast_match_entry(struct rvu *rvu, u16 pcifunc,
5178c2ecf20Sopenharmony_ci				       int nixlf, u64 chan);
5188c2ecf20Sopenharmony_civoid rvu_npc_enable_bcast_entry(struct rvu *rvu, u16 pcifunc, bool enable);
5198c2ecf20Sopenharmony_ciint rvu_npc_update_rxvlan(struct rvu *rvu, u16 pcifunc, int nixlf);
5208c2ecf20Sopenharmony_civoid rvu_npc_disable_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
5218c2ecf20Sopenharmony_civoid rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
5228c2ecf20Sopenharmony_civoid rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
5238c2ecf20Sopenharmony_civoid rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, u16 pcifunc, int nixlf,
5248c2ecf20Sopenharmony_ci				    int group, int alg_idx, int mcam_index);
5258c2ecf20Sopenharmony_civoid rvu_npc_get_mcam_entry_alloc_info(struct rvu *rvu, u16 pcifunc,
5268c2ecf20Sopenharmony_ci				       int blkaddr, int *alloc_cnt,
5278c2ecf20Sopenharmony_ci				       int *enable_cnt);
5288c2ecf20Sopenharmony_civoid rvu_npc_get_mcam_counter_alloc_info(struct rvu *rvu, u16 pcifunc,
5298c2ecf20Sopenharmony_ci					 int blkaddr, int *alloc_cnt,
5308c2ecf20Sopenharmony_ci					 int *enable_cnt);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
5338c2ecf20Sopenharmony_civoid rvu_dbg_init(struct rvu *rvu);
5348c2ecf20Sopenharmony_civoid rvu_dbg_exit(struct rvu *rvu);
5358c2ecf20Sopenharmony_ci#else
5368c2ecf20Sopenharmony_cistatic inline void rvu_dbg_init(struct rvu *rvu) {}
5378c2ecf20Sopenharmony_cistatic inline void rvu_dbg_exit(struct rvu *rvu) {}
5388c2ecf20Sopenharmony_ci#endif
5398c2ecf20Sopenharmony_ci#endif /* RVU_H */
540