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 "rvu_struct.h"
19 #define PCI_DEVID_OCTEONTX2_RVU_AF 0xA065
22 #define PCI_AF_REG_BAR_NUM 0
23 #define PCI_PF_REG_BAR_NUM 2
24 #define PCI_MBOX_BAR_NUM 4
29 #define RVU_PFVF_PF_SHIFT 10
30 #define RVU_PFVF_PF_MASK 0x3F
31 #define RVU_PFVF_FUNC_SHIFT 0
32 #define RVU_PFVF_FUNC_MASK 0x3FF
35 struct work_struct work;
40 unsigned long *bmap; /* Pointer to resource bitmap */
41 u16 max; /* Max resource id or count */
46 struct admin_queue *aq; /* NIX/NPA AQ */
47 u16 *fn_map; /* LF to pcifunc mapping */
50 u8 addr; /* RVU_BLOCK_ADDR_E */
51 u8 type; /* RVU_BLOCK_TYPE_E */
59 unsigned char name[NAME_SIZE];
64 struct qmem *mcast_buf;
67 spinlock_t mce_lock; /* Serialize MCE updates */
71 struct hlist_head head;
77 spinlock_t lock; /* MCAM entries and counters update lock */
78 u8 keysize; /* MCAM keysize 112/224/448 bits */
79 u8 banks; /* Number of MCAM banks */
80 u8 banks_per_entry;/* Number of keywords in key */
81 u16 banksize; /* Number of MCAM entries in each bank */
82 u16 total_entries; /* Total number of MCAM entries */
83 u16 entries; /* Total minus reserved for NIX LFs */
84 u16 nixlf_offset; /* Offset of nixlf rsvd uncast entries */
85 u16 pf_offset; /* Offset of PF's rsvd bcast, promisc entries */
88 /* Structure for per RVU func info ie PF/VF */
90 bool npalf; /* Only one NPALF per RVU_FUNC */
91 bool nixlf; /* Only one NIXLF per RVU_FUNC */
98 /* Block LF's MSIX vector info */
99 struct rsrc_bmap msix; /* Bitmap for MSIX vector alloc */
100 #define MSIX_BLKLF(blkaddr, lf) (((blkaddr) << 8) | ((lf) & 0xFF))
101 u16 *msix_lfmap; /* Vector to block LF mapping */
104 struct qmem *aura_ctx;
105 struct qmem *pool_ctx;
106 struct qmem *npa_qints_ctx;
107 unsigned long *aura_bmap;
108 unsigned long *pool_bmap;
114 struct qmem *rss_ctx;
115 struct qmem *cq_ints_ctx;
116 struct qmem *nix_qints_ctx;
117 unsigned long *sq_bmap;
118 unsigned long *rq_bmap;
119 unsigned long *cq_bmap;
123 u8 rx_chan_cnt; /* total number of RX channels */
124 u8 tx_chan_cnt; /* total number of TX channels */
126 u8 mac_addr[ETH_ALEN]; /* MAC address of this PF/VF */
128 /* Broadcast pkt replication info */
130 struct nix_mce_list bcast_mce_list;
134 struct rsrc_bmap schq;
140 struct rsrc_bmap rsrc;
145 struct nix_txsch txsch[NIX_TXSCH_LVL_CNT]; /* Tx schedulers */
146 struct nix_mcast mcast;
150 u8 total_pfs; /* MAX RVU PFs HW supports */
151 u16 total_vfs; /* Max RVU VFs HW supports */
152 u16 max_vfs_per_pf; /* Max VFs that can be attached to a PF */
158 u8 npc_kpus; /* No of parser units */
161 struct rvu_block block[BLK_COUNT]; /* Block info */
163 struct npc_pkind pkind;
164 struct npc_mcam mcam;
168 void __iomem *afreg_base;
169 void __iomem *pfreg_base;
170 struct pci_dev *pdev;
172 struct rvu_hwinfo *hw;
174 struct rvu_pfvf *hwvf;
175 spinlock_t rsrc_lock; /* Serialize resource alloc/free */
178 struct otx2_mbox mbox;
179 struct rvu_work *mbox_wrk;
180 struct otx2_mbox mbox_up;
181 struct rvu_work *mbox_wrk_up;
182 struct workqueue_struct *mbox_wq;
188 dma_addr_t msix_base_iova;
191 #define PF_CGXMAP_BASE 1 /* PF 0 is reserved for RVU PF */
193 u8 cgx_cnt; /* available cgx ports */
194 u8 *pf2cgxlmac_map; /* pf to cgx_lmac map */
195 u16 *cgxlmac2pf_map; /* bitmap of mapped pfs for
196 * every cgx lmac port
198 unsigned long pf_notify_bmap; /* Flags for PF notification */
199 void **cgx_idmap; /* cgx id to cgx data map table */
200 struct work_struct cgx_evh_work;
201 struct workqueue_struct *cgx_evh_wq;
202 spinlock_t cgx_evq_lock; /* cgx event queue lock */
203 struct list_head cgx_evq_head; /* cgx event queue head */
206 static inline void rvu_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
208 writeq(val, rvu->afreg_base + ((block << 28) | offset));
211 static inline u64 rvu_read64(struct rvu *rvu, u64 block, u64 offset)
213 return readq(rvu->afreg_base + ((block << 28) | offset));
216 static inline void rvupf_write64(struct rvu *rvu, u64 offset, u64 val)
218 writeq(val, rvu->pfreg_base + offset);
221 static inline u64 rvupf_read64(struct rvu *rvu, u64 offset)
223 return readq(rvu->pfreg_base + offset);
226 /* Function Prototypes
229 int rvu_alloc_bitmap(struct rsrc_bmap *rsrc);
230 int rvu_alloc_rsrc(struct rsrc_bmap *rsrc);
231 void rvu_free_rsrc(struct rsrc_bmap *rsrc, int id);
232 int rvu_rsrc_free_count(struct rsrc_bmap *rsrc);
233 int rvu_alloc_rsrc_contig(struct rsrc_bmap *rsrc, int nrsrc);
234 bool rvu_rsrc_check_contig(struct rsrc_bmap *rsrc, int nrsrc);
235 int rvu_get_pf(u16 pcifunc);
236 struct rvu_pfvf *rvu_get_pfvf(struct rvu *rvu, int pcifunc);
237 void rvu_get_pf_numvfs(struct rvu *rvu, int pf, int *numvfs, int *hwvf);
238 bool is_block_implemented(struct rvu_hwinfo *hw, int blkaddr);
239 int rvu_get_lf(struct rvu *rvu, struct rvu_block *block, u16 pcifunc, u16 slot);
240 int rvu_lf_reset(struct rvu *rvu, struct rvu_block *block, int lf);
241 int rvu_get_blkaddr(struct rvu *rvu, int blktype, u16 pcifunc);
242 int rvu_poll_reg(struct rvu *rvu, u64 block, u64 offset, u64 mask, bool zero);
244 /* RVU HW reg validation */
250 bool rvu_check_valid_reg(int regmap, int regblk, u64 reg);
252 /* NPA/NIX AQ APIs */
253 int rvu_aq_alloc(struct rvu *rvu, struct admin_queue **ad_queue,
254 int qsize, int inst_size, int res_size);
255 void rvu_aq_free(struct rvu *rvu, struct admin_queue *aq);
258 static inline bool is_pf_cgxmapped(struct rvu *rvu, u8 pf)
260 return (pf >= PF_CGXMAP_BASE && pf <= rvu->cgx_mapped_pfs);
263 static inline void rvu_get_cgx_lmac_id(u8 map, u8 *cgx_id, u8 *lmac_id)
265 *cgx_id = (map >> 4) & 0xF;
266 *lmac_id = (map & 0xF);
269 int rvu_cgx_probe(struct rvu *rvu);
270 void rvu_cgx_wq_destroy(struct rvu *rvu);
271 void *rvu_cgx_pdata(u8 cgx_id, struct rvu *rvu);
272 int rvu_cgx_config_rxtx(struct rvu *rvu, u16 pcifunc, bool start);
273 int rvu_mbox_handler_CGX_START_RXTX(struct rvu *rvu, struct msg_req *req,
274 struct msg_rsp *rsp);
275 int rvu_mbox_handler_CGX_STOP_RXTX(struct rvu *rvu, struct msg_req *req,
276 struct msg_rsp *rsp);
277 int rvu_mbox_handler_CGX_STATS(struct rvu *rvu, struct msg_req *req,
278 struct cgx_stats_rsp *rsp);
279 int rvu_mbox_handler_CGX_MAC_ADDR_SET(struct rvu *rvu,
280 struct cgx_mac_addr_set_or_get *req,
281 struct cgx_mac_addr_set_or_get *rsp);
282 int rvu_mbox_handler_CGX_MAC_ADDR_GET(struct rvu *rvu,
283 struct cgx_mac_addr_set_or_get *req,
284 struct cgx_mac_addr_set_or_get *rsp);
285 int rvu_mbox_handler_CGX_PROMISC_ENABLE(struct rvu *rvu, struct msg_req *req,
286 struct msg_rsp *rsp);
287 int rvu_mbox_handler_CGX_PROMISC_DISABLE(struct rvu *rvu, struct msg_req *req,
288 struct msg_rsp *rsp);
289 int rvu_mbox_handler_CGX_START_LINKEVENTS(struct rvu *rvu, struct msg_req *req,
290 struct msg_rsp *rsp);
291 int rvu_mbox_handler_CGX_STOP_LINKEVENTS(struct rvu *rvu, struct msg_req *req,
292 struct msg_rsp *rsp);
293 int rvu_mbox_handler_CGX_GET_LINKINFO(struct rvu *rvu, struct msg_req *req,
294 struct cgx_link_info_msg *rsp);
295 int rvu_mbox_handler_CGX_INTLBK_ENABLE(struct rvu *rvu, struct msg_req *req,
296 struct msg_rsp *rsp);
297 int rvu_mbox_handler_CGX_INTLBK_DISABLE(struct rvu *rvu, struct msg_req *req,
298 struct msg_rsp *rsp);
301 int rvu_npa_init(struct rvu *rvu);
302 void rvu_npa_freemem(struct rvu *rvu);
303 int rvu_mbox_handler_NPA_AQ_ENQ(struct rvu *rvu,
304 struct npa_aq_enq_req *req,
305 struct npa_aq_enq_rsp *rsp);
306 int rvu_mbox_handler_NPA_HWCTX_DISABLE(struct rvu *rvu,
307 struct hwctx_disable_req *req,
308 struct msg_rsp *rsp);
309 int rvu_mbox_handler_NPA_LF_ALLOC(struct rvu *rvu,
310 struct npa_lf_alloc_req *req,
311 struct npa_lf_alloc_rsp *rsp);
312 int rvu_mbox_handler_NPA_LF_FREE(struct rvu *rvu, struct msg_req *req,
313 struct msg_rsp *rsp);
316 int rvu_nix_init(struct rvu *rvu);
317 void rvu_nix_freemem(struct rvu *rvu);
318 int rvu_get_nixlf_count(struct rvu *rvu);
319 int rvu_mbox_handler_NIX_LF_ALLOC(struct rvu *rvu,
320 struct nix_lf_alloc_req *req,
321 struct nix_lf_alloc_rsp *rsp);
322 int rvu_mbox_handler_NIX_LF_FREE(struct rvu *rvu, struct msg_req *req,
323 struct msg_rsp *rsp);
324 int rvu_mbox_handler_NIX_AQ_ENQ(struct rvu *rvu,
325 struct nix_aq_enq_req *req,
326 struct nix_aq_enq_rsp *rsp);
327 int rvu_mbox_handler_NIX_HWCTX_DISABLE(struct rvu *rvu,
328 struct hwctx_disable_req *req,
329 struct msg_rsp *rsp);
330 int rvu_mbox_handler_NIX_TXSCH_ALLOC(struct rvu *rvu,
331 struct nix_txsch_alloc_req *req,
332 struct nix_txsch_alloc_rsp *rsp);
333 int rvu_mbox_handler_NIX_TXSCH_FREE(struct rvu *rvu,
334 struct nix_txsch_free_req *req,
335 struct msg_rsp *rsp);
336 int rvu_mbox_handler_NIX_TXSCHQ_CFG(struct rvu *rvu,
337 struct nix_txschq_config *req,
338 struct msg_rsp *rsp);
339 int rvu_mbox_handler_NIX_STATS_RST(struct rvu *rvu, struct msg_req *req,
340 struct msg_rsp *rsp);
341 int rvu_mbox_handler_NIX_VTAG_CFG(struct rvu *rvu,
342 struct nix_vtag_config *req,
343 struct msg_rsp *rsp);
346 int rvu_npc_init(struct rvu *rvu);
347 void rvu_npc_freemem(struct rvu *rvu);
348 int rvu_npc_get_pkind(struct rvu *rvu, u16 pf);
349 void rvu_npc_set_pkind(struct rvu *rvu, int pkind, struct rvu_pfvf *pfvf);