xref: /linux/drivers/net/ethernet/marvell/octeontx2/af/rvu.h (revision 2007f7e37142ebdb341949dca8098f898cc871f7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Marvell RVU Admin Function driver
3  *
4  * Copyright (C) 2018 Marvell.
5  *
6  */
7 
8 #ifndef RVU_H
9 #define RVU_H
10 
11 #include <linux/pci.h>
12 #include <net/devlink.h>
13 #include <linux/soc/marvell/silicons.h>
14 
15 #include "rvu_struct.h"
16 #include "rvu_devlink.h"
17 #include "common.h"
18 #include "mbox.h"
19 #include "npc.h"
20 #include "rvu_reg.h"
21 #include "ptp.h"
22 
23 /* PCI device IDs */
24 #define	PCI_DEVID_OCTEONTX2_RVU_AF		0xA065
25 #define	PCI_DEVID_OCTEONTX2_RVU_AFVF		0xA0F8
26 #define	PCI_DEVID_OCTEONTX2_LBK			0xA061
27 
28 /* Subsystem Device ID */
29 #define PCI_SUBSYS_DEVID_98XX                  0xB100
30 #define PCI_SUBSYS_DEVID_96XX                  0xB200
31 #define PCI_SUBSYS_DEVID_CN10K_A	       0xB900
32 #define PCI_SUBSYS_DEVID_CNF10K_A	       0xBA00
33 #define PCI_SUBSYS_DEVID_CNF10K_B              0xBC00
34 #define PCI_SUBSYS_DEVID_CN10K_B               0xBD00
35 #define PCI_SUBSYS_DEVID_CN20KA                0xC220
36 #define PCI_SUBSYS_DEVID_CNF20KA               0xC320
37 
38 /* PCI BAR nos */
39 #define	PCI_AF_REG_BAR_NUM			0
40 #define	PCI_PF_REG_BAR_NUM			2
41 #define	PCI_MBOX_BAR_NUM			4
42 
43 #define NAME_SIZE				32
44 #define MAX_NIX_BLKS				2
45 #define MAX_CPT_BLKS				2
46 
47 /* PF_FUNC */
48 #define RVU_OTX2_PFVF_PF_SHIFT			10
49 #define RVU_OTX2_PFVF_PF_MASK			0x3F
50 #define RVU_PFVF_FUNC_SHIFT			0
51 #define RVU_PFVF_FUNC_MASK			0x3FF
52 #define RVU_CN20K_PFVF_PF_SHIFT			9
53 #define RVU_CN20K_PFVF_PF_MASK			0x7F
54 
55 static inline u16 rvu_make_pcifunc(struct pci_dev *pdev, int pf, int func)
56 {
57 	if (is_cn20k(pdev))
58 		return ((pf & RVU_CN20K_PFVF_PF_MASK) <<
59 			RVU_CN20K_PFVF_PF_SHIFT) |
60 			((func & RVU_PFVF_FUNC_MASK) <<
61 			RVU_PFVF_FUNC_SHIFT);
62 	else
63 		return ((pf & RVU_OTX2_PFVF_PF_MASK) <<
64 			RVU_OTX2_PFVF_PF_SHIFT) |
65 			((func & RVU_PFVF_FUNC_MASK) <<
66 			RVU_PFVF_FUNC_SHIFT);
67 }
68 
69 static inline int rvu_pcifunc_pf_mask(struct pci_dev *pdev)
70 {
71 	if (is_cn20k(pdev))
72 		return ~(RVU_CN20K_PFVF_PF_MASK << RVU_CN20K_PFVF_PF_SHIFT);
73 	else
74 		return ~(RVU_OTX2_PFVF_PF_MASK << RVU_OTX2_PFVF_PF_SHIFT);
75 }
76 
77 #define RVU_AFPF           25
78 
79 struct dump_ctx {
80 	int	lf;
81 	int	id;
82 	bool	all;
83 };
84 
85 struct cpt_ctx {
86 	int blkaddr;
87 	struct rvu *rvu;
88 };
89 
90 struct rvu_debugfs {
91 	struct dentry *root;
92 	struct dentry *cgx_root;
93 	struct dentry *cgx;
94 	struct dentry *lmac;
95 	struct dentry *npa;
96 	struct dentry *nix;
97 	struct dentry *npc;
98 	struct dentry *cpt;
99 	struct dentry *mcs_root;
100 	struct dentry *mcs;
101 	struct dentry *mcs_rx;
102 	struct dentry *mcs_tx;
103 	struct dump_ctx npa_aura_ctx;
104 	struct dump_ctx npa_pool_ctx;
105 	struct dump_ctx nix_cq_ctx;
106 	struct dump_ctx nix_rq_ctx;
107 	struct dump_ctx nix_sq_ctx;
108 	struct dump_ctx nix_tm_ctx;
109 	struct cpt_ctx cpt_ctx[MAX_CPT_BLKS];
110 	int npa_qsize_id;
111 	int nix_qsize_id;
112 };
113 
114 struct rvu_work {
115 	struct	work_struct work;
116 	struct	rvu *rvu;
117 	int num_msgs;
118 	int up_num_msgs;
119 };
120 
121 struct rsrc_bmap {
122 	unsigned long *bmap;	/* Pointer to resource bitmap */
123 	u16  max;		/* Max resource id or count */
124 };
125 
126 struct rvu_block {
127 	struct rsrc_bmap	lf;
128 	struct admin_queue	*aq; /* NIX/NPA AQ */
129 	u16  *fn_map; /* LF to pcifunc mapping */
130 	bool multislot;
131 	bool implemented;
132 	u8   addr;  /* RVU_BLOCK_ADDR_E */
133 	u8   type;  /* RVU_BLOCK_TYPE_E */
134 	u8   lfshift;
135 	u64  lookup_reg;
136 	u64  pf_lfcnt_reg;
137 	u64  vf_lfcnt_reg;
138 	u64  lfcfg_reg;
139 	u64  msixcfg_reg;
140 	u64  lfreset_reg;
141 	unsigned char name[NAME_SIZE];
142 	struct rvu *rvu;
143 	u64 cpt_flt_eng_map[3];
144 	u64 cpt_rcvrd_eng_map[3];
145 };
146 
147 struct nix_mcast {
148 	struct qmem		*mce_ctx;
149 	struct qmem		*mcast_buf;
150 	int			replay_pkind;
151 	struct rsrc_bmap	mce_counter[2];
152 	/* Counters for both ingress and egress mcast lists */
153 	struct mutex		mce_lock; /* Serialize MCE updates */
154 };
155 
156 struct nix_mce_list {
157 	struct hlist_head	head;
158 	int			count;
159 	int			max;
160 };
161 
162 struct nix_mcast_grp_elem {
163 	struct nix_mce_list	mcast_mce_list;
164 	u32			mcast_grp_idx;
165 	u32			pcifunc;
166 	int			mcam_index;
167 	int			mce_start_index;
168 	struct list_head	list;
169 	u8			dir;
170 };
171 
172 struct nix_mcast_grp {
173 	struct list_head	mcast_grp_head;
174 	int			count;
175 	int			next_grp_index;
176 	struct mutex		mcast_grp_lock; /* Serialize MCE updates */
177 };
178 
179 /* layer metadata to uniquely identify a packet header field */
180 struct npc_layer_mdata {
181 	u8 lid;
182 	u8 ltype;
183 	u8 hdr;
184 	u8 key;
185 	u8 len;
186 };
187 
188 /* Structure to represent a field present in the
189  * generated key. A key field may present anywhere and can
190  * be of any size in the generated key. Once this structure
191  * is populated for fields of interest then field's presence
192  * and location (if present) can be known.
193  */
194 struct npc_key_field {
195 	/* Masks where all set bits indicate position
196 	 * of a field in the key
197 	 */
198 	u64 kw_mask[NPC_KWS_IN_KEY_SZ_MAX];
199 	/* Number of words in the key a field spans. If a field is
200 	 * of 16 bytes and key offset is 4 then the field will use
201 	 * 4 bytes in KW0, 8 bytes in KW1 and 4 bytes in KW2 and
202 	 * nr_kws will be 3(KW0, KW1 and KW2).
203 	 */
204 	int nr_kws;
205 	/* used by packet header fields */
206 	struct npc_layer_mdata layer_mdata;
207 };
208 
209 struct npc_mcam {
210 	struct rsrc_bmap counters;
211 	struct mutex	lock;	/* MCAM entries and counters update lock */
212 	unsigned long	*bmap;		/* bitmap, 0 => bmap_entries */
213 	unsigned long	*bmap_reverse;	/* Reverse bitmap, bmap_entries => 0 */
214 	u16	bmap_entries;	/* Number of unreserved MCAM entries */
215 	u16	bmap_fcnt;	/* MCAM entries free count */
216 	u16	*entry2pfvf_map;
217 	u16	*entry2cntr_map;
218 	u16	*cntr2pfvf_map;
219 	u16	*cntr_refcnt;
220 	u16	*entry2target_pffunc;
221 	u8	keysize;	/* MCAM keysize 112/224/448 bits */
222 	u8	banks;		/* Number of MCAM banks */
223 	u8	banks_per_entry;/* Number of keywords in key */
224 	u16	banksize;	/* Number of MCAM entries in each bank */
225 	u16	total_entries;	/* Total number of MCAM entries */
226 	u16	nixlf_offset;	/* Offset of nixlf rsvd uncast entries */
227 	u16	pf_offset;	/* Offset of PF's rsvd bcast, promisc entries */
228 	u16	lprio_count;
229 	u16	lprio_start;
230 	u16	hprio_count;
231 	u16	hprio_end;
232 	u16     rx_miss_act_cntr; /* Counter for RX MISS action */
233 	/* fields present in the generated key */
234 	struct npc_key_field	tx_key_fields[NPC_KEY_FIELDS_MAX];
235 	struct npc_key_field	rx_key_fields[NPC_KEY_FIELDS_MAX];
236 	u64	tx_features;
237 	u64	rx_features;
238 	struct list_head mcam_rules;
239 };
240 
241 /* Structure for per RVU func info ie PF/VF */
242 struct rvu_pfvf {
243 	bool		npalf; /* Only one NPALF per RVU_FUNC */
244 	bool		nixlf; /* Only one NIXLF per RVU_FUNC */
245 	u16		sso;
246 	u16		ssow;
247 	u16		cptlfs;
248 	u16		timlfs;
249 	u16		cpt1_lfs;
250 	u8		cgx_lmac;
251 
252 	/* Block LF's MSIX vector info */
253 	struct rsrc_bmap msix;      /* Bitmap for MSIX vector alloc */
254 #define MSIX_BLKLF(blkaddr, lf) (((blkaddr) << 8) | ((lf) & 0xFF))
255 	u16		 *msix_lfmap; /* Vector to block LF mapping */
256 
257 	/* NPA contexts */
258 	struct qmem	*aura_ctx;
259 	struct qmem	*pool_ctx;
260 	struct qmem	*npa_qints_ctx;
261 	unsigned long	*aura_bmap;
262 	unsigned long	*pool_bmap;
263 
264 	/* NIX contexts */
265 	struct qmem	*rq_ctx;
266 	struct qmem	*sq_ctx;
267 	struct qmem	*cq_ctx;
268 	struct qmem	*rss_ctx;
269 	struct qmem	*cq_ints_ctx;
270 	struct qmem	*nix_qints_ctx;
271 	unsigned long	*sq_bmap;
272 	unsigned long	*rq_bmap;
273 	unsigned long	*cq_bmap;
274 
275 	u16		rx_chan_base;
276 	u16		tx_chan_base;
277 	u8              rx_chan_cnt; /* total number of RX channels */
278 	u8              tx_chan_cnt; /* total number of TX channels */
279 	u16		maxlen;
280 	u16		minlen;
281 
282 	bool		hw_rx_tstamp_en; /* Is rx_tstamp enabled */
283 	u8		mac_addr[ETH_ALEN]; /* MAC address of this PF/VF */
284 	u8		default_mac[ETH_ALEN]; /* MAC address from FWdata */
285 
286 	/* Broadcast/Multicast/Promisc pkt replication info */
287 	u16			bcast_mce_idx;
288 	u16			mcast_mce_idx;
289 	u16			promisc_mce_idx;
290 	struct nix_mce_list	bcast_mce_list;
291 	struct nix_mce_list	mcast_mce_list;
292 	struct nix_mce_list	promisc_mce_list;
293 	bool			use_mce_list;
294 
295 	struct rvu_npc_mcam_rule *def_ucast_rule;
296 
297 	bool	cgx_in_use; /* this PF/VF using CGX? */
298 	int	cgx_users;  /* number of cgx users - used only by PFs */
299 
300 	int     intf_mode;
301 	u8	nix_blkaddr; /* BLKADDR_NIX0/1 assigned to this PF */
302 	u8	nix_rx_intf; /* NIX0_RX/NIX1_RX interface to NPC */
303 	u8	nix_tx_intf; /* NIX0_TX/NIX1_TX interface to NPC */
304 	u8	lbkid;	     /* NIX0/1 lbk link ID */
305 	u64     lmt_base_addr; /* Preseving the pcifunc's lmtst base addr*/
306 	u64     lmt_map_ent_w1; /* Preseving the word1 of lmtst map table entry*/
307 	unsigned long flags;
308 	struct  sdp_node_info *sdp_info;
309 	u8	hw_prio;   /* Hw priority of default rules */
310 };
311 
312 enum rvu_pfvf_flags {
313 	NIXLF_INITIALIZED = 0,
314 	PF_SET_VF_MAC,
315 	PF_SET_VF_CFG,
316 	PF_SET_VF_TRUSTED,
317 };
318 
319 #define RVU_CLEAR_VF_PERM  ~GENMASK(PF_SET_VF_TRUSTED, PF_SET_VF_MAC)
320 
321 struct nix_bp {
322 	struct rsrc_bmap bpids; /* free bpids bitmap */
323 	u16 cgx_bpid_cnt;
324 	u16 sdp_bpid_cnt;
325 	u16 free_pool_base;
326 	u16 *fn_map; /* pcifunc mapping */
327 	u8 *intf_map;  /* interface type map */
328 	u8 *ref_cnt;
329 };
330 
331 struct nix_txsch {
332 	struct rsrc_bmap schq;
333 	u8   lvl;
334 #define NIX_TXSCHQ_FREE		      BIT_ULL(1)
335 #define NIX_TXSCHQ_CFG_DONE	      BIT_ULL(0)
336 #define TXSCH_MAP_FUNC(__pfvf_map)    ((__pfvf_map) & 0xFFFF)
337 #define TXSCH_MAP_FLAGS(__pfvf_map)   ((__pfvf_map) >> 16)
338 #define TXSCH_MAP(__func, __flags)    (((__func) & 0xFFFF) | ((__flags) << 16))
339 #define TXSCH_SET_FLAG(__pfvf_map, flag)    ((__pfvf_map) | ((flag) << 16))
340 	u32  *pfvf_map;
341 };
342 
343 struct nix_mark_format {
344 	u8 total;
345 	u8 in_use;
346 	u32 *cfg;
347 };
348 
349 /* smq(flush) to tl1 cir/pir info */
350 struct nix_smq_tree_ctx {
351 	u16 schq;
352 	u64 cir_off;
353 	u64 cir_val;
354 	u64 pir_off;
355 	u64 pir_val;
356 };
357 
358 /* smq flush context */
359 struct nix_smq_flush_ctx {
360 	int smq;
361 	struct nix_smq_tree_ctx smq_tree_ctx[NIX_TXSCH_LVL_CNT];
362 };
363 
364 struct npc_pkind {
365 	struct rsrc_bmap rsrc;
366 	u32	*pfchan_map;
367 };
368 
369 struct nix_flowkey {
370 #define NIX_FLOW_KEY_ALG_MAX 32
371 	u32 flowkey[NIX_FLOW_KEY_ALG_MAX];
372 	int in_use;
373 };
374 
375 struct nix_lso {
376 	u8 total;
377 	u8 in_use;
378 };
379 
380 struct nix_txvlan {
381 #define NIX_TX_VTAG_DEF_MAX 0x400
382 	struct rsrc_bmap rsrc;
383 	u16 *entry2pfvf_map;
384 	struct mutex rsrc_lock; /* Serialize resource alloc/free */
385 };
386 
387 struct nix_ipolicer {
388 	struct rsrc_bmap band_prof;
389 	u16 *pfvf_map;
390 	u16 *match_id;
391 	u16 *ref_count;
392 };
393 
394 struct nix_hw {
395 	int blkaddr;
396 	struct rvu *rvu;
397 	struct nix_txsch txsch[NIX_TXSCH_LVL_CNT]; /* Tx schedulers */
398 	struct nix_mcast mcast;
399 	struct nix_mcast_grp mcast_grp;
400 	struct nix_flowkey flowkey;
401 	struct nix_mark_format mark_format;
402 	struct nix_lso lso;
403 	struct nix_txvlan txvlan;
404 	struct nix_ipolicer *ipolicer;
405 	struct nix_bp bp;
406 	u64    *tx_credits;
407 	u8	cc_mcs_cnt;
408 };
409 
410 /* RVU block's capabilities or functionality,
411  * which vary by silicon version/skew.
412  */
413 struct hw_cap {
414 	/* Transmit side supported functionality */
415 	u8	nix_tx_aggr_lvl; /* Tx link's traffic aggregation level */
416 	u16	nix_txsch_per_cgx_lmac; /* Max Q's transmitting to CGX LMAC */
417 	u16	nix_txsch_per_lbk_lmac; /* Max Q's transmitting to LBK LMAC */
418 	u16	nix_txsch_per_sdp_lmac; /* Max Q's transmitting to SDP LMAC */
419 	bool	nix_fixed_txschq_mapping; /* Schq mapping fixed or flexible */
420 	bool	nix_shaping;		 /* Is shaping and coloring supported */
421 	bool    nix_shaper_toggle_wait; /* Shaping toggle needs poll/wait */
422 	bool	nix_tx_link_bp;		 /* Can link backpressure TL queues ? */
423 	bool	nix_rx_multicast;	 /* Rx packet replication support */
424 	bool	nix_common_dwrr_mtu;	 /* Common DWRR MTU for quantum config */
425 	bool	per_pf_mbox_regs; /* PF mbox specified in per PF registers ? */
426 	bool	programmable_chans; /* Channels programmable ? */
427 	bool	ipolicer;
428 	bool	nix_multiple_dwrr_mtu;   /* Multiple DWRR_MTU to choose from */
429 	bool	npc_hash_extract; /* Hash extract enabled ? */
430 	bool	npc_exact_match_enabled; /* Exact match supported ? */
431 	bool    cpt_rxc;   /* Is CPT-RXC supported */
432 };
433 
434 struct rvu_hwinfo {
435 	u8	total_pfs;   /* MAX RVU PFs HW supports */
436 	u16	total_vfs;   /* Max RVU VFs HW supports */
437 	u16	max_vfs_per_pf; /* Max VFs that can be attached to a PF */
438 	u8	cgx;
439 	u8	lmac_per_cgx;
440 	u16	cgx_chan_base;	/* CGX base channel number */
441 	u16	lbk_chan_base;	/* LBK base channel number */
442 	u16	sdp_chan_base;	/* SDP base channel number */
443 	u16	cpt_chan_base;	/* CPT base channel number */
444 	u8	cgx_links;
445 	u8	lbk_links;
446 	u8	sdp_links;
447 	u8	cpt_links;	/* Number of CPT links */
448 	u8	npc_kpus;          /* No of parser units */
449 	u8	npc_kpms;	/* Number of enhanced parser units */
450 	u8	npc_kex_extr;	/* Number of LDATA extractors per KEX */
451 	u8	npc_pkinds;        /* No of port kinds */
452 	u8	npc_intfs;         /* No of interfaces */
453 	u16	npc_kpu_entries;   /* No of KPU entries */
454 	u16	npc_counters;	   /* No of match stats counters */
455 	u32	lbk_bufsize;	   /* FIFO size supported by LBK */
456 	bool	npc_ext_set;	   /* Extended register set */
457 	u64     npc_stat_ena;      /* Match stats enable bit */
458 
459 	struct hw_cap    cap;
460 	struct rvu_block block[BLK_COUNT]; /* Block info */
461 	struct nix_hw    *nix;
462 	struct rvu	 *rvu;
463 	struct npc_pkind pkind;
464 	struct npc_mcam  mcam;
465 	struct npc_exact_table *table;
466 };
467 
468 struct mbox_wq_info {
469 	struct otx2_mbox mbox;
470 	struct rvu_work *mbox_wrk;
471 
472 	struct otx2_mbox mbox_up;
473 	struct rvu_work *mbox_wrk_up;
474 
475 	struct workqueue_struct *mbox_wq;
476 };
477 
478 struct rvu_irq_data {
479 	u64 intr_status;
480 	void (*rvu_queue_work_hdlr)(struct mbox_wq_info *mw, int first,
481 				    int mdevs, u64 intr);
482 	void (*afvf_queue_work_hdlr)(struct mbox_wq_info *mw, int first,
483 				     int mdevs, u64 intr);
484 	struct	rvu *rvu;
485 	int vec_num;
486 	int start;
487 	int mdevs;
488 };
489 
490 struct mbox_ops {
491 	irqreturn_t (*pf_intr_handler)(int irq, void *rvu_irq);
492 	irqreturn_t (*afvf_intr_handler)(int irq, void *rvu_irq);
493 };
494 
495 struct channel_fwdata {
496 	struct sdp_node_info info;
497 	u8 valid;
498 #define RVU_CHANL_INFO_RESERVED	379
499 	u8 reserved[RVU_CHANL_INFO_RESERVED];
500 };
501 
502 struct altaf_intr_notify {
503 	unsigned long flr_pf_bmap[2];
504 	unsigned long flr_vf_bmap[2];
505 	unsigned long gint_paddr;
506 	unsigned long gint_iova_addr;
507 	unsigned long reserved[6];
508 };
509 
510 struct rvu_fwdata {
511 #define RVU_FWDATA_HEADER_MAGIC	0xCFDA	/* Custom Firmware Data*/
512 #define RVU_FWDATA_VERSION	0x0001
513 	u32 header_magic;
514 	u32 version;		/* version id */
515 
516 	/* MAC address */
517 #define PF_MACNUM_MAX	32
518 #define VF_MACNUM_MAX	256
519 	u64 pf_macs[PF_MACNUM_MAX];
520 	u64 vf_macs[VF_MACNUM_MAX];
521 	u64 sclk;
522 	u64 rclk;
523 	u64 mcam_addr;
524 	u64 mcam_sz;
525 	u64 msixtr_base;
526 	u32 ptp_ext_clk_rate;
527 	u32 ptp_ext_tstamp;
528 	struct channel_fwdata channel_data;
529 	struct altaf_intr_notify altaf_intr_info;
530 #define FWDATA_RESERVED_MEM 946
531 	u64 reserved[FWDATA_RESERVED_MEM];
532 #define CGX_MAX         9
533 #define CGX_LMACS_MAX   4
534 #define CGX_LMACS_USX   8
535 #define FWDATA_CGX_LMAC_OFFSET 10536
536 	union {
537 		struct cgx_lmac_fwdata_s
538 			cgx_fw_data[CGX_MAX][CGX_LMACS_MAX];
539 		struct cgx_lmac_fwdata_s
540 			cgx_fw_data_usx[CGX_MAX][CGX_LMACS_USX];
541 	};
542 	/* Do not add new fields below this line */
543 };
544 
545 struct ptp;
546 
547 /* KPU profile adapter structure gathering all KPU configuration data and abstracting out the
548  * source where it came from.
549  */
550 struct npc_kpu_profile_adapter {
551 	const char			*name;
552 	u64				version;
553 	const struct npc_lt_def_cfg	*lt_def;
554 	struct npc_kpu_profile_action	*ikpu; /* array[pkinds] */
555 	struct npc_kpu_profile_action	*ikpu2; /* array[pkinds] */
556 	struct npc_kpu_profile	*kpu; /* array[kpus] */
557 	union npc_mcam_key_prfl {
558 		const struct npc_mcam_kex		*mkex;
559 					/* used for cn9k and cn10k */
560 		const struct npc_mcam_kex_extr	*mkex_extr; /* used for cn20k */
561 	} mcam_kex_prfl;
562 	struct npc_mcam_kex_hash	*mkex_hash;
563 	bool				custom;
564 	size_t				pkinds;
565 	size_t				kpus;
566 	bool				from_fs;
567 };
568 
569 #define RVU_SWITCH_LBK_CHAN	63
570 
571 struct rvu_switch {
572 	struct mutex switch_lock; /* Serialize flow installation */
573 	u32 used_entries;
574 	u16 *entry2pcifunc;
575 	u16 mode;
576 	u16 start_entry;
577 };
578 
579 struct rep_evtq_ent {
580 	struct list_head node;
581 	struct rep_event event;
582 };
583 
584 struct rvu {
585 	void __iomem		*afreg_base;
586 	void __iomem		*pfreg_base;
587 	struct pci_dev		*pdev;
588 	struct device		*dev;
589 	struct rvu_hwinfo       *hw;
590 	struct rvu_pfvf		*pf;
591 	struct rvu_pfvf		*hwvf;
592 	struct mutex		rsrc_lock; /* Serialize resource alloc/free */
593 	struct mutex		alias_lock; /* Serialize bar2 alias access */
594 	int			vfs; /* Number of VFs attached to RVU */
595 	u16			vf_devid; /* VF devices id */
596 	bool			def_rule_cntr_en;
597 	int			nix_blkaddr[MAX_NIX_BLKS];
598 
599 	/* Mbox */
600 	struct mbox_wq_info	afpf_wq_info;
601 	struct mbox_wq_info	afvf_wq_info;
602 
603 	/* PF FLR */
604 	struct rvu_work		*flr_wrk;
605 	struct workqueue_struct *flr_wq;
606 	struct mutex		flr_lock; /* Serialize FLRs */
607 
608 	/* MSI-X */
609 	u16			num_vec;
610 	char			*irq_name;
611 	bool			*irq_allocated;
612 	dma_addr_t		msix_base_iova;
613 	u64			msixtr_base_phy; /* Register reset value */
614 
615 	/* CGX */
616 #define PF_CGXMAP_BASE		1 /* PF 0 is reserved for RVU PF */
617 	u16			cgx_mapped_vfs; /* maximum CGX mapped VFs */
618 	u8			cgx_mapped_pfs;
619 	u8			cgx_cnt_max;	 /* CGX port count max */
620 	u8			*pf2cgxlmac_map; /* pf to cgx_lmac map */
621 	u64			*cgxlmac2pf_map; /* bitmap of mapped pfs for
622 						  * every cgx lmac port
623 						  */
624 	unsigned long		pf_notify_bmap; /* Flags for PF notification */
625 	void			**cgx_idmap; /* cgx id to cgx data map table */
626 	struct			work_struct cgx_evh_work;
627 	struct			workqueue_struct *cgx_evh_wq;
628 	spinlock_t		cgx_evq_lock; /* cgx event queue lock */
629 	struct list_head	cgx_evq_head; /* cgx event queue head */
630 	struct mutex		cgx_cfg_lock; /* serialize cgx configuration */
631 
632 	char mkex_pfl_name[MKEX_NAME_LEN]; /* Configured MKEX profile name */
633 	char kpu_pfl_name[KPU_NAME_LEN]; /* Configured KPU profile name */
634 
635 	/* Firmware data */
636 	struct rvu_fwdata	*fwdata;
637 	const void		*kpu_fwdata;
638 	size_t			kpu_fwdata_sz;
639 	void __iomem		*kpu_prfl_addr;
640 
641 	/* NPC KPU data */
642 	struct npc_kpu_profile_adapter kpu;
643 
644 	struct ptp		*ptp;
645 
646 	int			mcs_blk_cnt;
647 	int			cpt_pf_num;
648 
649 	struct rvu_debugfs	rvu_dbg;
650 	struct rvu_devlink	*rvu_dl;
651 
652 	/* RVU switch implementation over NPC with DMAC rules */
653 	struct rvu_switch	rswitch;
654 
655 	struct			work_struct mcs_intr_work;
656 	struct			workqueue_struct *mcs_intr_wq;
657 	struct list_head	mcs_intrq_head;
658 	/* mcs interrupt queue lock */
659 	spinlock_t		mcs_intrq_lock;
660 	/* CPT interrupt lock */
661 	spinlock_t		cpt_intr_lock;
662 
663 	struct mutex		mbox_lock; /* Serialize mbox up and down msgs */
664 	u16			rep_pcifunc;
665 	bool			altaf_ready;
666 	int			rep_cnt;
667 	u16			*rep2pfvf_map;
668 	u8			rep_mode;
669 	struct			work_struct rep_evt_work;
670 	struct			workqueue_struct *rep_evt_wq;
671 	struct list_head	rep_evtq_head;
672 	/* Representor event lock */
673 	spinlock_t		rep_evtq_lock;
674 
675 	struct ng_rvu           *ng_rvu;
676 };
677 
678 static inline void rvu_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
679 {
680 	writeq(val, rvu->afreg_base + ((block << 28) | offset));
681 }
682 
683 static inline u64 rvu_read64(struct rvu *rvu, u64 block, u64 offset)
684 {
685 	return readq(rvu->afreg_base + ((block << 28) | offset));
686 }
687 
688 static inline void rvupf_write64(struct rvu *rvu, u64 offset, u64 val)
689 {
690 	writeq(val, rvu->pfreg_base + offset);
691 }
692 
693 static inline u64 rvupf_read64(struct rvu *rvu, u64 offset)
694 {
695 	return readq(rvu->pfreg_base + offset);
696 }
697 
698 static inline void rvu_bar2_sel_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
699 {
700 	/* HW requires read back of RVU_AF_BAR2_SEL register to make sure completion of
701 	 * write operation.
702 	 */
703 	rvu_write64(rvu, block, offset, val);
704 	rvu_read64(rvu, block, offset);
705 	/* Barrier to ensure read completes before accessing LF registers */
706 	mb();
707 }
708 
709 /* Silicon revisions */
710 static inline bool is_rvu_pre_96xx_C0(struct rvu *rvu)
711 {
712 	struct pci_dev *pdev = rvu->pdev;
713 	/* 96XX A0/B0, 95XX A0/A1/B0 chips */
714 	return ((pdev->revision == 0x00) || (pdev->revision == 0x01) ||
715 		(pdev->revision == 0x10) || (pdev->revision == 0x11) ||
716 		(pdev->revision == 0x14));
717 }
718 
719 static inline bool is_rvu_96xx_A0(struct rvu *rvu)
720 {
721 	struct pci_dev *pdev = rvu->pdev;
722 
723 	return (pdev->revision == 0x00);
724 }
725 
726 static inline bool is_rvu_96xx_B0(struct rvu *rvu)
727 {
728 	struct pci_dev *pdev = rvu->pdev;
729 
730 	return (pdev->revision == 0x00) || (pdev->revision == 0x01);
731 }
732 
733 static inline bool is_rvu_95xx_A0(struct rvu *rvu)
734 {
735 	struct pci_dev *pdev = rvu->pdev;
736 
737 	return (pdev->revision == 0x10) || (pdev->revision == 0x11);
738 }
739 
740 /* REVID for PCIe devices.
741  * Bits 0..1: minor pass, bit 3..2: major pass
742  * bits 7..4: midr id
743  */
744 #define PCI_REVISION_ID_96XX		0x00
745 #define PCI_REVISION_ID_95XX		0x10
746 #define PCI_REVISION_ID_95XXN		0x20
747 #define PCI_REVISION_ID_98XX		0x30
748 #define PCI_REVISION_ID_95XXMM		0x40
749 #define PCI_REVISION_ID_95XXO		0xE0
750 
751 static inline bool is_rvu_otx2(struct rvu *rvu)
752 {
753 	struct pci_dev *pdev = rvu->pdev;
754 
755 	u8 midr = pdev->revision & 0xF0;
756 
757 	return (midr == PCI_REVISION_ID_96XX || midr == PCI_REVISION_ID_95XX ||
758 		midr == PCI_REVISION_ID_95XXN || midr == PCI_REVISION_ID_98XX ||
759 		midr == PCI_REVISION_ID_95XXMM || midr == PCI_REVISION_ID_95XXO);
760 }
761 
762 static inline bool is_cnf10ka_a0(struct rvu *rvu)
763 {
764 	struct pci_dev *pdev = rvu->pdev;
765 
766 	if (pdev->subsystem_device == PCI_SUBSYS_DEVID_CNF10K_A &&
767 	    (pdev->revision & 0x0F) == 0x0)
768 		return true;
769 	return false;
770 }
771 
772 static inline bool is_cn10ka_a0(struct rvu *rvu)
773 {
774 	struct pci_dev *pdev = rvu->pdev;
775 
776 	if (pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_A &&
777 	    (pdev->revision & 0x0F) == 0x0)
778 		return true;
779 	return false;
780 }
781 
782 static inline bool is_cn10ka_a1(struct rvu *rvu)
783 {
784 	struct pci_dev *pdev = rvu->pdev;
785 
786 	if (pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_A &&
787 	    (pdev->revision & 0x0F) == 0x1)
788 		return true;
789 	return false;
790 }
791 
792 static inline bool is_cn10kb(struct rvu *rvu)
793 {
794 	struct pci_dev *pdev = rvu->pdev;
795 
796 	if (pdev->subsystem_device == PCI_SUBSYS_DEVID_CN10K_B)
797 		return true;
798 	return false;
799 }
800 
801 static inline bool is_cgx_mapped_to_nix(unsigned short id, u8 cgx_id)
802 {
803 	/* On CNF10KA and CNF10KB silicons only two CGX blocks are connected
804 	 * to NIX.
805 	 */
806 	if (id == PCI_SUBSYS_DEVID_CNF10K_A || id == PCI_SUBSYS_DEVID_CNF10K_B)
807 		return cgx_id <= 1;
808 
809 	return !(cgx_id && !(id == PCI_SUBSYS_DEVID_96XX ||
810 			     id == PCI_SUBSYS_DEVID_98XX ||
811 			     id == PCI_SUBSYS_DEVID_CN10K_A ||
812 			     id == PCI_SUBSYS_DEVID_CN10K_B));
813 }
814 
815 static inline bool is_rvu_npc_hash_extract_en(struct rvu *rvu)
816 {
817 	u64 npc_const3;
818 
819 	npc_const3 = rvu_read64(rvu, BLKADDR_NPC, NPC_AF_CONST3);
820 	if (!(npc_const3 & BIT_ULL(62)))
821 		return false;
822 
823 	return true;
824 }
825 
826 static inline u16 rvu_nix_chan_cgx(struct rvu *rvu, u8 cgxid,
827 				   u8 lmacid, u8 chan)
828 {
829 	u64 nix_const = rvu_read64(rvu, BLKADDR_NIX0, NIX_AF_CONST);
830 	u16 cgx_chans = nix_const & 0xFFULL;
831 	struct rvu_hwinfo *hw = rvu->hw;
832 
833 	if (!hw->cap.programmable_chans)
834 		return NIX_CHAN_CGX_LMAC_CHX(cgxid, lmacid, chan);
835 
836 	return rvu->hw->cgx_chan_base +
837 		(cgxid * hw->lmac_per_cgx + lmacid) * cgx_chans + chan;
838 }
839 
840 static inline u16 rvu_nix_chan_lbk(struct rvu *rvu, u8 lbkid,
841 				   u8 chan)
842 {
843 	u64 nix_const = rvu_read64(rvu, BLKADDR_NIX0, NIX_AF_CONST);
844 	u16 lbk_chans = (nix_const >> 16) & 0xFFULL;
845 	struct rvu_hwinfo *hw = rvu->hw;
846 
847 	if (!hw->cap.programmable_chans)
848 		return NIX_CHAN_LBK_CHX(lbkid, chan);
849 
850 	return rvu->hw->lbk_chan_base + lbkid * lbk_chans + chan;
851 }
852 
853 static inline u16 rvu_nix_chan_sdp(struct rvu *rvu, u8 chan)
854 {
855 	struct rvu_hwinfo *hw = rvu->hw;
856 
857 	if (!hw->cap.programmable_chans)
858 		return NIX_CHAN_SDP_CHX(chan);
859 
860 	return hw->sdp_chan_base + chan;
861 }
862 
863 static inline u16 rvu_nix_chan_cpt(struct rvu *rvu, u8 chan)
864 {
865 	return rvu->hw->cpt_chan_base + chan;
866 }
867 
868 static inline bool is_rvu_supports_nix1(struct rvu *rvu)
869 {
870 	struct pci_dev *pdev = rvu->pdev;
871 
872 	if (pdev->subsystem_device == PCI_SUBSYS_DEVID_98XX)
873 		return true;
874 
875 	return false;
876 }
877 
878 /* Function Prototypes
879  * RVU
880  */
881 static inline bool is_lbk_vf(struct rvu *rvu, u16 pcifunc)
882 {
883 	return (!(pcifunc & ~RVU_PFVF_FUNC_MASK) &&
884 		(rvu->vf_devid == PCI_DEVID_OCTEONTX2_RVU_AFVF));
885 }
886 
887 static inline bool is_vf(u16 pcifunc)
888 {
889 	return !!(pcifunc & RVU_PFVF_FUNC_MASK);
890 }
891 
892 /* check if PF_FUNC is AF */
893 static inline bool is_pffunc_af(u16 pcifunc)
894 {
895 	return !pcifunc;
896 }
897 
898 static inline bool is_rvu_fwdata_valid(struct rvu *rvu)
899 {
900 	return (rvu->fwdata->header_magic == RVU_FWDATA_HEADER_MAGIC) &&
901 		(rvu->fwdata->version == RVU_FWDATA_VERSION);
902 }
903 
904 int rvu_alloc_bitmap(struct rsrc_bmap *rsrc);
905 void rvu_free_bitmap(struct rsrc_bmap *rsrc);
906 int rvu_alloc_rsrc(struct rsrc_bmap *rsrc);
907 void rvu_free_rsrc(struct rsrc_bmap *rsrc, int id);
908 bool is_rsrc_free(struct rsrc_bmap *rsrc, int id);
909 int rvu_rsrc_free_count(struct rsrc_bmap *rsrc);
910 int rvu_alloc_rsrc_contig(struct rsrc_bmap *rsrc, int nrsrc);
911 void rvu_free_rsrc_contig(struct rsrc_bmap *rsrc, int nrsrc, int start);
912 bool rvu_rsrc_check_contig(struct rsrc_bmap *rsrc, int nrsrc);
913 u16 rvu_get_rsrc_mapcount(struct rvu_pfvf *pfvf, int blkaddr);
914 struct rvu_pfvf *rvu_get_pfvf(struct rvu *rvu, int pcifunc);
915 void rvu_get_pf_numvfs(struct rvu *rvu, int pf, int *numvfs, int *hwvf);
916 bool is_block_implemented(struct rvu_hwinfo *hw, int blkaddr);
917 bool is_pf_func_valid(struct rvu *rvu, u16 pcifunc);
918 bool is_pffunc_map_valid(struct rvu *rvu, u16 pcifunc, int blktype);
919 int rvu_get_lf(struct rvu *rvu, struct rvu_block *block, u16 pcifunc, u16 slot);
920 int rvu_lf_reset(struct rvu *rvu, struct rvu_block *block, int lf);
921 int rvu_get_blkaddr(struct rvu *rvu, int blktype, u16 pcifunc);
922 int rvu_poll_reg(struct rvu *rvu, u64 block, u64 offset, u64 mask, bool zero);
923 int rvu_get_num_lbk_chans(void);
924 int rvu_ndc_sync(struct rvu *rvu, int lfblkid, int lfidx, u64 lfoffset);
925 int rvu_get_blkaddr_from_slot(struct rvu *rvu, int blktype, u16 pcifunc,
926 			      u16 global_slot, u16 *slot_in_block);
927 
928 /* RVU HW reg validation */
929 enum regmap_block {
930 	TXSCHQ_HWREGMAP = 0,
931 	MAX_HWREGMAP,
932 };
933 
934 bool rvu_check_valid_reg(int regmap, int regblk, u64 reg);
935 
936 /* NPA/NIX AQ APIs */
937 int rvu_aq_alloc(struct rvu *rvu, struct admin_queue **ad_queue,
938 		 int qsize, int inst_size, int res_size);
939 void rvu_aq_free(struct rvu *rvu, struct admin_queue *aq);
940 
941 /* SDP APIs */
942 int rvu_sdp_init(struct rvu *rvu);
943 bool is_sdp_pfvf(struct rvu *rvu, u16 pcifunc);
944 bool is_sdp_pf(struct rvu *rvu, u16 pcifunc);
945 bool is_sdp_vf(struct rvu *rvu, u16 pcifunc);
946 
947 static inline bool is_rep_dev(struct rvu *rvu, u16 pcifunc)
948 {
949 	if (rvu->rep_pcifunc && rvu->rep_pcifunc == pcifunc)
950 		return true;
951 
952 	return false;
953 }
954 
955 static inline int rvu_get_pf(struct pci_dev *pdev, u16 pcifunc)
956 {
957 	if (is_cn20k(pdev))
958 		return (pcifunc >> RVU_CN20K_PFVF_PF_SHIFT) &
959 			RVU_CN20K_PFVF_PF_MASK;
960 	else
961 		return (pcifunc >> RVU_OTX2_PFVF_PF_SHIFT) &
962 			RVU_OTX2_PFVF_PF_MASK;
963 }
964 
965 /* CGX APIs */
966 static inline bool is_pf_cgxmapped(struct rvu *rvu, u8 pf)
967 {
968 	return (pf >= PF_CGXMAP_BASE && pf <= rvu->cgx_mapped_pfs) &&
969 		!is_sdp_pf(rvu, rvu_make_pcifunc(rvu->pdev, pf, 0));
970 }
971 
972 static inline void rvu_get_cgx_lmac_id(u8 map, u8 *cgx_id, u8 *lmac_id)
973 {
974 	*cgx_id = (map >> 4) & 0xF;
975 	*lmac_id = (map & 0xF);
976 }
977 
978 static inline bool is_cgx_vf(struct rvu *rvu, u16 pcifunc)
979 {
980 	return ((pcifunc & RVU_PFVF_FUNC_MASK) &&
981 		is_pf_cgxmapped(rvu, rvu_get_pf(rvu->pdev, pcifunc)));
982 }
983 
984 #define M(_name, _id, fn_name, req, rsp)				\
985 int rvu_mbox_handler_ ## fn_name(struct rvu *, struct req *, struct rsp *);
986 MBOX_MESSAGES
987 #undef M
988 
989 /* Mbox APIs */
990 void rvu_queue_work(struct mbox_wq_info *mw, int first,
991 		    int mdevs, u64 intr);
992 
993 int rvu_cgx_init(struct rvu *rvu);
994 int rvu_cgx_exit(struct rvu *rvu);
995 void *rvu_cgx_pdata(u8 cgx_id, struct rvu *rvu);
996 int rvu_cgx_config_rxtx(struct rvu *rvu, u16 pcifunc, bool start);
997 void rvu_cgx_enadis_rx_bp(struct rvu *rvu, int pf, bool enable);
998 int rvu_cgx_start_stop_io(struct rvu *rvu, u16 pcifunc, bool start);
999 int rvu_cgx_nix_cuml_stats(struct rvu *rvu, void *cgxd, int lmac_id, int index,
1000 			   int rxtxflag, u64 *stat);
1001 void rvu_cgx_disable_dmac_entries(struct rvu *rvu, u16 pcifunc);
1002 
1003 /* NPA APIs */
1004 int rvu_npa_init(struct rvu *rvu);
1005 void rvu_npa_freemem(struct rvu *rvu);
1006 void rvu_npa_lf_teardown(struct rvu *rvu, u16 pcifunc, int npalf);
1007 int rvu_npa_aq_enq_inst(struct rvu *rvu, struct npa_aq_enq_req *req,
1008 			struct npa_aq_enq_rsp *rsp);
1009 
1010 /* NIX APIs */
1011 bool is_nixlf_attached(struct rvu *rvu, u16 pcifunc);
1012 int rvu_nix_init(struct rvu *rvu);
1013 int rvu_nix_reserve_mark_format(struct rvu *rvu, struct nix_hw *nix_hw,
1014 				int blkaddr, u32 cfg);
1015 void rvu_nix_freemem(struct rvu *rvu);
1016 int rvu_get_nixlf_count(struct rvu *rvu);
1017 void rvu_nix_lf_teardown(struct rvu *rvu, u16 pcifunc, int blkaddr, int npalf);
1018 int nix_get_nixlf(struct rvu *rvu, u16 pcifunc, int *nixlf, int *nix_blkaddr);
1019 int nix_update_mce_list(struct rvu *rvu, u16 pcifunc,
1020 			struct nix_mce_list *mce_list,
1021 			int mce_idx, int mcam_index, bool add);
1022 void nix_get_mce_list(struct rvu *rvu, u16 pcifunc, int type,
1023 		      struct nix_mce_list **mce_list, int *mce_idx);
1024 struct nix_hw *get_nix_hw(struct rvu_hwinfo *hw, int blkaddr);
1025 int rvu_get_next_nix_blkaddr(struct rvu *rvu, int blkaddr);
1026 void rvu_nix_reset_mac(struct rvu_pfvf *pfvf, int pcifunc);
1027 int nix_get_struct_ptrs(struct rvu *rvu, u16 pcifunc,
1028 			struct nix_hw **nix_hw, int *blkaddr);
1029 int rvu_nix_setup_ratelimit_aggr(struct rvu *rvu, u16 pcifunc,
1030 				 u16 rq_idx, u16 match_id);
1031 int nix_aq_context_read(struct rvu *rvu, struct nix_hw *nix_hw,
1032 			struct nix_cn10k_aq_enq_req *aq_req,
1033 			struct nix_cn10k_aq_enq_rsp *aq_rsp,
1034 			u16 pcifunc, u8 ctype, u32 qidx);
1035 int rvu_get_nix_blkaddr(struct rvu *rvu, u16 pcifunc);
1036 int nix_get_dwrr_mtu_reg(struct rvu_hwinfo *hw, int smq_link_type);
1037 u32 convert_dwrr_mtu_to_bytes(u8 dwrr_mtu);
1038 u32 convert_bytes_to_dwrr_mtu(u32 bytes);
1039 void rvu_nix_tx_tl2_cfg(struct rvu *rvu, int blkaddr, u16 pcifunc,
1040 			struct nix_txsch *txsch, bool enable);
1041 void rvu_nix_mcast_flr_free_entries(struct rvu *rvu, u16 pcifunc);
1042 int rvu_nix_mcast_get_mce_index(struct rvu *rvu, u16 pcifunc,
1043 				u32 mcast_grp_idx);
1044 int rvu_nix_mcast_update_mcam_entry(struct rvu *rvu, u16 pcifunc,
1045 				    u32 mcast_grp_idx, u16 mcam_index);
1046 void rvu_nix_flr_free_bpids(struct rvu *rvu, u16 pcifunc);
1047 int rvu_alloc_cint_qint_mem(struct rvu *rvu, struct rvu_pfvf *pfvf,
1048 			    int blkaddr, int nixlf);
1049 void rvu_block_bcast_xon(struct rvu *rvu, int blkaddr);
1050 int rvu_nix_aq_enq_inst(struct rvu *rvu, struct nix_aq_enq_req *req,
1051 			struct nix_aq_enq_rsp *rsp);
1052 
1053 /* NPC APIs */
1054 void rvu_npc_freemem(struct rvu *rvu);
1055 int rvu_npc_get_pkind(struct rvu *rvu, u16 pf);
1056 void rvu_npc_set_pkind(struct rvu *rvu, int pkind, struct rvu_pfvf *pfvf);
1057 int npc_config_ts_kpuaction(struct rvu *rvu, int pf, u16 pcifunc, bool en);
1058 void rvu_npc_install_ucast_entry(struct rvu *rvu, u16 pcifunc,
1059 				 int nixlf, u64 chan, u8 *mac_addr);
1060 void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,
1061 				   int nixlf, u64 chan, u8 chan_cnt);
1062 void rvu_npc_enable_promisc_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
1063 				  bool enable);
1064 void rvu_npc_install_bcast_match_entry(struct rvu *rvu, u16 pcifunc,
1065 				       int nixlf, u64 chan);
1066 void rvu_npc_install_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
1067 				    u64 chan);
1068 void rvu_npc_enable_allmulti_entry(struct rvu *rvu, u16 pcifunc, int nixlf,
1069 				   bool enable);
1070 
1071 void npc_enadis_default_mce_entry(struct rvu *rvu, u16 pcifunc,
1072 				  int nixlf, int type, bool enable);
1073 void rvu_npc_disable_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
1074 bool rvu_npc_enable_mcam_by_entry_index(struct rvu *rvu, int entry, int intf, bool enable);
1075 void rvu_npc_free_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
1076 void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
1077 void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
1078 void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, u16 pcifunc, int nixlf,
1079 				    int group, int alg_idx, int mcam_index);
1080 void __rvu_mcam_remove_counter_from_rule(struct rvu *rvu, u16 pcifunc,
1081 					 struct rvu_npc_mcam_rule *rule);
1082 void __rvu_mcam_add_counter_to_rule(struct rvu *rvu, u16 pcifunc,
1083 				    struct rvu_npc_mcam_rule *rule,
1084 				    struct npc_install_flow_rsp *rsp);
1085 void rvu_npc_get_mcam_entry_alloc_info(struct rvu *rvu, u16 pcifunc,
1086 				       int blkaddr, int *alloc_cnt,
1087 				       int *enable_cnt);
1088 void rvu_npc_get_mcam_counter_alloc_info(struct rvu *rvu, u16 pcifunc,
1089 					 int blkaddr, int *alloc_cnt,
1090 					 int *enable_cnt);
1091 void rvu_npc_clear_ucast_entry(struct rvu *rvu, int pcifunc, int nixlf);
1092 
1093 bool is_npc_intf_tx(u8 intf);
1094 bool is_npc_intf_rx(u8 intf);
1095 bool is_npc_interface_valid(struct rvu *rvu, u8 intf);
1096 int rvu_npc_get_tx_nibble_cfg(struct rvu *rvu, u64 nibble_ena);
1097 int npc_flow_steering_init(struct rvu *rvu, int blkaddr);
1098 const char *npc_get_field_name(u8 hdr);
1099 int npc_get_bank(struct npc_mcam *mcam, int index);
1100 void npc_mcam_enable_flows(struct rvu *rvu, u16 target);
1101 void npc_mcam_disable_flows(struct rvu *rvu, u16 target);
1102 void npc_enable_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
1103 			   int blkaddr, int index, bool enable);
1104 u64 npc_get_mcam_action(struct rvu *rvu, struct npc_mcam *mcam,
1105 			int blkaddr, int index);
1106 void npc_set_mcam_action(struct rvu *rvu, struct npc_mcam *mcam,
1107 			 int blkaddr, int index, u64 cfg);
1108 void npc_read_mcam_entry(struct rvu *rvu, struct npc_mcam *mcam,
1109 			 int blkaddr, u16 src, struct mcam_entry *entry,
1110 			 u8 *intf, u8 *ena);
1111 int npc_config_cntr_default_entries(struct rvu *rvu, bool enable);
1112 bool is_cgx_config_permitted(struct rvu *rvu, u16 pcifunc);
1113 bool rvu_cgx_check_permission_and_set_pkind(struct rvu *rvu, u16 pcifunc, int pkind);
1114 bool rvu_cgx_is_pkind_config_permitted(struct rvu *rvu, u16 pcifunc);
1115 bool is_mac_feature_supported(struct rvu *rvu, int pf, int feature);
1116 u32  rvu_cgx_get_fifolen(struct rvu *rvu);
1117 void *rvu_first_cgx_pdata(struct rvu *rvu);
1118 int cgxlmac_to_pf(struct rvu *rvu, int cgx_id, int lmac_id);
1119 int rvu_cgx_config_tx(void *cgxd, int lmac_id, bool enable);
1120 int rvu_cgx_tx_enable(struct rvu *rvu, u16 pcifunc, bool enable);
1121 int rvu_cgx_prio_flow_ctrl_cfg(struct rvu *rvu, u16 pcifunc, u8 tx_pause, u8 rx_pause,
1122 			       u16 pfc_en);
1123 int rvu_cgx_cfg_pause_frm(struct rvu *rvu, u16 pcifunc, u8 tx_pause, u8 rx_pause);
1124 void rvu_mac_reset(struct rvu *rvu, u16 pcifunc);
1125 u64 rvu_cgx_get_dmacflt_dropped_pktcnt(void *cgxd, int lmac_id);
1126 u32 rvu_cgx_get_lmac_fifolen(struct rvu *rvu, int cgx, int lmac);
1127 void cgx_start_linkup(struct rvu *rvu);
1128 int npc_get_nixlf_mcam_index(struct npc_mcam *mcam,
1129 			     u16 pcifunc, int nixlf, int type);
1130 bool is_mcam_entry_enabled(struct rvu *rvu, struct npc_mcam *mcam, int blkaddr,
1131 			   int index);
1132 int rvu_npc_init(struct rvu *rvu);
1133 int npc_install_mcam_drop_rule(struct rvu *rvu, int mcam_idx, u16 *counter_idx,
1134 			       u64 chan_val, u64 chan_mask, u64 exact_val, u64 exact_mask,
1135 			       u64 bcast_mcast_val, u64 bcast_mcast_mask);
1136 void npc_mcam_rsrcs_reserve(struct rvu *rvu, int blkaddr, int entry_idx);
1137 bool npc_is_feature_supported(struct rvu *rvu, u64 features, u8 intf);
1138 int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr);
1139 void npc_mcam_rsrcs_deinit(struct rvu *rvu);
1140 
1141 /* CPT APIs */
1142 int rvu_cpt_register_interrupts(struct rvu *rvu);
1143 void rvu_cpt_unregister_interrupts(struct rvu *rvu);
1144 int rvu_cpt_lf_teardown(struct rvu *rvu, u16 pcifunc, int blkaddr, int lf,
1145 			int slot);
1146 int rvu_cpt_ctx_flush(struct rvu *rvu, u16 pcifunc);
1147 int rvu_cpt_init(struct rvu *rvu);
1148 u32 rvu_get_cpt_chan_mask(struct rvu *rvu);
1149 
1150 #define NDC_AF_BANK_MASK       GENMASK_ULL(7, 0)
1151 #define NDC_AF_BANK_LINE_MASK  GENMASK_ULL(31, 16)
1152 
1153 /* CN10K RVU */
1154 int rvu_set_channels_base(struct rvu *rvu);
1155 void rvu_program_channels(struct rvu *rvu);
1156 
1157 /* CN10K NIX */
1158 void rvu_nix_block_cn10k_init(struct rvu *rvu, struct nix_hw *nix_hw);
1159 
1160 /* CN10K RVU - LMT*/
1161 void rvu_reset_lmt_map_tbl(struct rvu *rvu, u16 pcifunc);
1162 void rvu_apr_block_cn10k_init(struct rvu *rvu);
1163 
1164 #ifdef CONFIG_DEBUG_FS
1165 void rvu_dbg_init(struct rvu *rvu);
1166 void rvu_dbg_exit(struct rvu *rvu);
1167 #else
1168 static inline void rvu_dbg_init(struct rvu *rvu) {}
1169 static inline void rvu_dbg_exit(struct rvu *rvu) {}
1170 #endif
1171 
1172 int rvu_ndc_fix_locked_cacheline(struct rvu *rvu, int blkaddr);
1173 
1174 /* RVU Switch */
1175 void rvu_switch_enable(struct rvu *rvu);
1176 void rvu_switch_disable(struct rvu *rvu);
1177 void rvu_switch_update_rules(struct rvu *rvu, u16 pcifunc, bool ena);
1178 void rvu_switch_enable_lbk_link(struct rvu *rvu, u16 pcifunc, bool ena);
1179 
1180 int rvu_npc_set_parse_mode(struct rvu *rvu, u16 pcifunc, u64 mode, u8 dir,
1181 			   u64 pkind, u8 var_len_off, u8 var_len_off_mask,
1182 			   u8 shift_dir, u8 skip_size);
1183 int rvu_get_hwvf(struct rvu *rvu, int pcifunc);
1184 
1185 /* CN10K MCS */
1186 int rvu_mcs_init(struct rvu *rvu);
1187 int rvu_mcs_flr_handler(struct rvu *rvu, u16 pcifunc);
1188 void rvu_mcs_ptp_cfg(struct rvu *rvu, u8 rpm_id, u8 lmac_id, bool ena);
1189 void rvu_mcs_exit(struct rvu *rvu);
1190 
1191 /* Representor APIs */
1192 int rvu_rep_pf_init(struct rvu *rvu);
1193 int rvu_rep_install_mcam_rules(struct rvu *rvu);
1194 void rvu_rep_update_rules(struct rvu *rvu, u16 pcifunc, bool ena);
1195 int rvu_rep_notify_pfvf_state(struct rvu *rvu, u16 pcifunc, bool enable);
1196 int npc_mcam_verify_entry(struct npc_mcam *mcam, u16 pcifunc, int entry);
1197 #endif /* RVU_H */
1198