1 /* SPDX-License-Identifier: GPL-2.0
2 * Marvell OcteonTx2 RVU Admin Function driver
4 * Copyright (C) 2018 Marvell International Ltd.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
14 #include <linux/pci.h>
15 #include "rvu_struct.h"
20 #define PCI_DEVID_OCTEONTX2_RVU_AF 0xA065
22 /* Subsystem Device ID */
23 #define PCI_SUBSYS_DEVID_96XX 0xB200
26 #define PCI_AF_REG_BAR_NUM 0
27 #define PCI_PF_REG_BAR_NUM 2
28 #define PCI_MBOX_BAR_NUM 4
33 #define RVU_PFVF_PF_SHIFT 10
34 #define RVU_PFVF_PF_MASK 0x3F
35 #define RVU_PFVF_FUNC_SHIFT 0
36 #define RVU_PFVF_FUNC_MASK 0x3FF
38 #ifdef CONFIG_DEBUG_FS
47 struct dentry *cgx_root;
53 struct dump_ctx npa_aura_ctx;
54 struct dump_ctx npa_pool_ctx;
55 struct dump_ctx nix_cq_ctx;
56 struct dump_ctx nix_rq_ctx;
57 struct dump_ctx nix_sq_ctx;
64 struct work_struct work;
71 unsigned long *bmap; /* Pointer to resource bitmap */
72 u16 max; /* Max resource id or count */
77 struct admin_queue *aq; /* NIX/NPA AQ */
78 u16 *fn_map; /* LF to pcifunc mapping */
81 u8 addr; /* RVU_BLOCK_ADDR_E */
82 u8 type; /* RVU_BLOCK_TYPE_E */
90 unsigned char name[NAME_SIZE];
95 struct qmem *mcast_buf;
98 struct mutex mce_lock; /* Serialize MCE updates */
101 struct nix_mce_list {
102 struct hlist_head head;
108 struct rsrc_bmap counters;
109 struct mutex lock; /* MCAM entries and counters update lock */
110 unsigned long *bmap; /* bitmap, 0 => bmap_entries */
111 unsigned long *bmap_reverse; /* Reverse bitmap, bmap_entries => 0 */
112 u16 bmap_entries; /* Number of unreserved MCAM entries */
113 u16 bmap_fcnt; /* MCAM entries free count */
118 u8 keysize; /* MCAM keysize 112/224/448 bits */
119 u8 banks; /* Number of MCAM banks */
120 u8 banks_per_entry;/* Number of keywords in key */
121 u16 banksize; /* Number of MCAM entries in each bank */
122 u16 total_entries; /* Total number of MCAM entries */
123 u16 nixlf_offset; /* Offset of nixlf rsvd uncast entries */
124 u16 pf_offset; /* Offset of PF's rsvd bcast, promisc entries */
129 u16 rx_miss_act_cntr; /* Counter for RX MISS action */
132 /* Structure for per RVU func info ie PF/VF */
134 bool npalf; /* Only one NPALF per RVU_FUNC */
135 bool nixlf; /* Only one NIXLF per RVU_FUNC */
142 /* Block LF's MSIX vector info */
143 struct rsrc_bmap msix; /* Bitmap for MSIX vector alloc */
144 #define MSIX_BLKLF(blkaddr, lf) (((blkaddr) << 8) | ((lf) & 0xFF))
145 u16 *msix_lfmap; /* Vector to block LF mapping */
148 struct qmem *aura_ctx;
149 struct qmem *pool_ctx;
150 struct qmem *npa_qints_ctx;
151 unsigned long *aura_bmap;
152 unsigned long *pool_bmap;
158 struct qmem *rss_ctx;
159 struct qmem *cq_ints_ctx;
160 struct qmem *nix_qints_ctx;
161 unsigned long *sq_bmap;
162 unsigned long *rq_bmap;
163 unsigned long *cq_bmap;
167 u8 rx_chan_cnt; /* total number of RX channels */
168 u8 tx_chan_cnt; /* total number of TX channels */
172 u8 mac_addr[ETH_ALEN]; /* MAC address of this PF/VF */
174 /* Broadcast pkt replication info */
176 struct nix_mce_list bcast_mce_list;
179 struct mcam_entry entry;
185 struct rsrc_bmap schq;
187 #define NIX_TXSCHQ_FREE BIT_ULL(1)
188 #define NIX_TXSCHQ_CFG_DONE BIT_ULL(0)
189 #define TXSCH_MAP_FUNC(__pfvf_map) ((__pfvf_map) & 0xFFFF)
190 #define TXSCH_MAP_FLAGS(__pfvf_map) ((__pfvf_map) >> 16)
191 #define TXSCH_MAP(__func, __flags) (((__func) & 0xFFFF) | ((__flags) << 16))
192 #define TXSCH_SET_FLAG(__pfvf_map, flag) ((__pfvf_map) | ((flag) << 16))
196 struct nix_mark_format {
203 struct rsrc_bmap rsrc;
208 #define NIX_FLOW_KEY_ALG_MAX 32
209 u32 flowkey[NIX_FLOW_KEY_ALG_MAX];
219 struct nix_txsch txsch[NIX_TXSCH_LVL_CNT]; /* Tx schedulers */
220 struct nix_mcast mcast;
221 struct nix_flowkey flowkey;
222 struct nix_mark_format mark_format;
226 /* RVU block's capabilities or functionality,
227 * which vary by silicon version/skew.
230 /* Transmit side supported functionality */
231 u8 nix_tx_aggr_lvl; /* Tx link's traffic aggregation level */
232 u16 nix_txsch_per_cgx_lmac; /* Max Q's transmitting to CGX LMAC */
233 u16 nix_txsch_per_lbk_lmac; /* Max Q's transmitting to LBK LMAC */
234 u16 nix_txsch_per_sdp_lmac; /* Max Q's transmitting to SDP LMAC */
235 bool nix_fixed_txschq_mapping; /* Schq mapping fixed or flexible */
236 bool nix_shaping; /* Is shaping and coloring supported */
237 bool nix_tx_link_bp; /* Can link backpressure TL queues ? */
241 u8 total_pfs; /* MAX RVU PFs HW supports */
242 u16 total_vfs; /* Max RVU VFs HW supports */
243 u16 max_vfs_per_pf; /* Max VFs that can be attached to a PF */
249 u8 npc_kpus; /* No of parser units */
252 struct rvu_block block[BLK_COUNT]; /* Block info */
254 struct npc_pkind pkind;
255 struct npc_mcam mcam;
258 struct mbox_wq_info {
259 struct otx2_mbox mbox;
260 struct rvu_work *mbox_wrk;
262 struct otx2_mbox mbox_up;
263 struct rvu_work *mbox_wrk_up;
265 struct workqueue_struct *mbox_wq;
269 void __iomem *afreg_base;
270 void __iomem *pfreg_base;
271 struct pci_dev *pdev;
273 struct rvu_hwinfo *hw;
275 struct rvu_pfvf *hwvf;
276 struct mutex rsrc_lock; /* Serialize resource alloc/free */
277 int vfs; /* Number of VFs attached to RVU */
280 struct mbox_wq_info afpf_wq_info;
281 struct mbox_wq_info afvf_wq_info;
284 struct rvu_work *flr_wrk;
285 struct workqueue_struct *flr_wq;
286 struct mutex flr_lock; /* Serialize FLRs */
292 dma_addr_t msix_base_iova;
295 #define PF_CGXMAP_BASE 1 /* PF 0 is reserved for RVU PF */
297 u8 cgx_cnt_max; /* CGX port count max */
298 u8 *pf2cgxlmac_map; /* pf to cgx_lmac map */
299 u16 *cgxlmac2pf_map; /* bitmap of mapped pfs for
300 * every cgx lmac port
302 unsigned long pf_notify_bmap; /* Flags for PF notification */
303 void **cgx_idmap; /* cgx id to cgx data map table */
304 struct work_struct cgx_evh_work;
305 struct workqueue_struct *cgx_evh_wq;
306 spinlock_t cgx_evq_lock; /* cgx event queue lock */
307 struct list_head cgx_evq_head; /* cgx event queue head */
309 char mkex_pfl_name[MKEX_NAME_LEN]; /* Configured MKEX profile name */
311 #ifdef CONFIG_DEBUG_FS
312 struct rvu_debugfs rvu_dbg;
316 static inline void rvu_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
318 writeq(val, rvu->afreg_base + ((block << 28) | offset));
321 static inline u64 rvu_read64(struct rvu *rvu, u64 block, u64 offset)
323 return readq(rvu->afreg_base + ((block << 28) | offset));
326 static inline void rvupf_write64(struct rvu *rvu, u64 offset, u64 val)
328 writeq(val, rvu->pfreg_base + offset);
331 static inline u64 rvupf_read64(struct rvu *rvu, u64 offset)
333 return readq(rvu->pfreg_base + offset);
336 /* Silicon revisions */
337 static inline bool is_rvu_96xx_A0(struct rvu *rvu)
339 struct pci_dev *pdev = rvu->pdev;
341 return (pdev->revision == 0x00) &&
342 (pdev->subsystem_device == PCI_SUBSYS_DEVID_96XX);
345 static inline bool is_rvu_96xx_B0(struct rvu *rvu)
347 struct pci_dev *pdev = rvu->pdev;
349 return ((pdev->revision == 0x00) || (pdev->revision == 0x01)) &&
350 (pdev->subsystem_device == PCI_SUBSYS_DEVID_96XX);
353 /* Function Prototypes
356 static inline int is_afvf(u16 pcifunc)
358 return !(pcifunc & ~RVU_PFVF_FUNC_MASK);
361 int rvu_alloc_bitmap(struct rsrc_bmap *rsrc);
362 int rvu_alloc_rsrc(struct rsrc_bmap *rsrc);
363 void rvu_free_rsrc(struct rsrc_bmap *rsrc, int id);
364 int rvu_rsrc_free_count(struct rsrc_bmap *rsrc);
365 int rvu_alloc_rsrc_contig(struct rsrc_bmap *rsrc, int nrsrc);
366 bool rvu_rsrc_check_contig(struct rsrc_bmap *rsrc, int nrsrc);
367 int rvu_get_pf(u16 pcifunc);
368 struct rvu_pfvf *rvu_get_pfvf(struct rvu *rvu, int pcifunc);
369 void rvu_get_pf_numvfs(struct rvu *rvu, int pf, int *numvfs, int *hwvf);
370 bool is_block_implemented(struct rvu_hwinfo *hw, int blkaddr);
371 bool is_pffunc_map_valid(struct rvu *rvu, u16 pcifunc, int blktype);
372 int rvu_get_lf(struct rvu *rvu, struct rvu_block *block, u16 pcifunc, u16 slot);
373 int rvu_lf_reset(struct rvu *rvu, struct rvu_block *block, int lf);
374 int rvu_get_blkaddr(struct rvu *rvu, int blktype, u16 pcifunc);
375 int rvu_poll_reg(struct rvu *rvu, u64 block, u64 offset, u64 mask, bool zero);
377 /* RVU HW reg validation */
383 bool rvu_check_valid_reg(int regmap, int regblk, u64 reg);
385 /* NPA/NIX AQ APIs */
386 int rvu_aq_alloc(struct rvu *rvu, struct admin_queue **ad_queue,
387 int qsize, int inst_size, int res_size);
388 void rvu_aq_free(struct rvu *rvu, struct admin_queue *aq);
391 static inline bool is_pf_cgxmapped(struct rvu *rvu, u8 pf)
393 return (pf >= PF_CGXMAP_BASE && pf <= rvu->cgx_mapped_pfs);
396 static inline void rvu_get_cgx_lmac_id(u8 map, u8 *cgx_id, u8 *lmac_id)
398 *cgx_id = (map >> 4) & 0xF;
399 *lmac_id = (map & 0xF);
402 #define M(_name, _id, fn_name, req, rsp) \
403 int rvu_mbox_handler_ ## fn_name(struct rvu *, struct req *, struct rsp *);
407 int rvu_cgx_init(struct rvu *rvu);
408 int rvu_cgx_exit(struct rvu *rvu);
409 void *rvu_cgx_pdata(u8 cgx_id, struct rvu *rvu);
410 int rvu_cgx_config_rxtx(struct rvu *rvu, u16 pcifunc, bool start);
411 void rvu_cgx_enadis_rx_bp(struct rvu *rvu, int pf, bool enable);
412 int rvu_cgx_nix_cuml_stats(struct rvu *rvu, void *cgxd, int lmac_id, int index,
413 int rxtxflag, u64 *stat);
415 int rvu_npa_init(struct rvu *rvu);
416 void rvu_npa_freemem(struct rvu *rvu);
417 void rvu_npa_lf_teardown(struct rvu *rvu, u16 pcifunc, int npalf);
418 int rvu_npa_aq_enq_inst(struct rvu *rvu, struct npa_aq_enq_req *req,
419 struct npa_aq_enq_rsp *rsp);
422 bool is_nixlf_attached(struct rvu *rvu, u16 pcifunc);
423 int rvu_nix_init(struct rvu *rvu);
424 int rvu_nix_reserve_mark_format(struct rvu *rvu, struct nix_hw *nix_hw,
425 int blkaddr, u32 cfg);
426 void rvu_nix_freemem(struct rvu *rvu);
427 int rvu_get_nixlf_count(struct rvu *rvu);
428 void rvu_nix_lf_teardown(struct rvu *rvu, u16 pcifunc, int blkaddr, int npalf);
429 int nix_get_nixlf(struct rvu *rvu, u16 pcifunc, int *nixlf);
432 int rvu_npc_init(struct rvu *rvu);
433 void rvu_npc_freemem(struct rvu *rvu);
434 int rvu_npc_get_pkind(struct rvu *rvu, u16 pf);
435 void rvu_npc_set_pkind(struct rvu *rvu, int pkind, struct rvu_pfvf *pfvf);
436 void rvu_npc_install_ucast_entry(struct rvu *rvu, u16 pcifunc,
437 int nixlf, u64 chan, u8 *mac_addr);
438 void rvu_npc_install_promisc_entry(struct rvu *rvu, u16 pcifunc,
439 int nixlf, u64 chan, bool allmulti);
440 void rvu_npc_disable_promisc_entry(struct rvu *rvu, u16 pcifunc, int nixlf);
441 void rvu_npc_enable_promisc_entry(struct rvu *rvu, u16 pcifunc, int nixlf);
442 void rvu_npc_install_bcast_match_entry(struct rvu *rvu, u16 pcifunc,
443 int nixlf, u64 chan);
444 int rvu_npc_update_rxvlan(struct rvu *rvu, u16 pcifunc, int nixlf);
445 void rvu_npc_disable_mcam_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
446 void rvu_npc_disable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
447 void rvu_npc_enable_default_entries(struct rvu *rvu, u16 pcifunc, int nixlf);
448 void rvu_npc_update_flowkey_alg_idx(struct rvu *rvu, u16 pcifunc, int nixlf,
449 int group, int alg_idx, int mcam_index);
450 void rvu_npc_get_mcam_entry_alloc_info(struct rvu *rvu, u16 pcifunc,
451 int blkaddr, int *alloc_cnt,
453 void rvu_npc_get_mcam_counter_alloc_info(struct rvu *rvu, u16 pcifunc,
454 int blkaddr, int *alloc_cnt,
457 #ifdef CONFIG_DEBUG_FS
458 void rvu_dbg_init(struct rvu *rvu);
459 void rvu_dbg_exit(struct rvu *rvu);
461 static inline void rvu_dbg_init(struct rvu *rvu) {}
462 static inline void rvu_dbg_exit(struct rvu *rvu) {}