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;
76 /* Structure for per RVU func info ie PF/VF */
78 bool npalf; /* Only one NPALF per RVU_FUNC */
79 bool nixlf; /* Only one NIXLF per RVU_FUNC */
86 /* Block LF's MSIX vector info */
87 struct rsrc_bmap msix; /* Bitmap for MSIX vector alloc */
88 #define MSIX_BLKLF(blkaddr, lf) (((blkaddr) << 8) | ((lf) & 0xFF))
89 u16 *msix_lfmap; /* Vector to block LF mapping */
92 struct qmem *aura_ctx;
93 struct qmem *pool_ctx;
94 struct qmem *npa_qints_ctx;
95 unsigned long *aura_bmap;
96 unsigned long *pool_bmap;
102 struct qmem *rss_ctx;
103 struct qmem *cq_ints_ctx;
104 struct qmem *nix_qints_ctx;
105 unsigned long *sq_bmap;
106 unsigned long *rq_bmap;
107 unsigned long *cq_bmap;
109 u8 mac_addr[ETH_ALEN]; /* MAC address of this PF/VF */
111 /* Broadcast pkt replication info */
113 struct nix_mce_list bcast_mce_list;
117 struct rsrc_bmap schq;
123 struct rsrc_bmap rsrc;
128 struct nix_txsch txsch[NIX_TXSCH_LVL_CNT]; /* Tx schedulers */
129 struct nix_mcast mcast;
133 u8 total_pfs; /* MAX RVU PFs HW supports */
134 u16 total_vfs; /* Max RVU VFs HW supports */
135 u16 max_vfs_per_pf; /* Max VFs that can be attached to a PF */
141 u8 npc_kpus; /* No of parser units */
144 struct rvu_block block[BLK_COUNT]; /* Block info */
146 struct npc_pkind pkind;
150 void __iomem *afreg_base;
151 void __iomem *pfreg_base;
152 struct pci_dev *pdev;
154 struct rvu_hwinfo *hw;
156 struct rvu_pfvf *hwvf;
157 spinlock_t rsrc_lock; /* Serialize resource alloc/free */
160 struct otx2_mbox mbox;
161 struct rvu_work *mbox_wrk;
162 struct otx2_mbox mbox_up;
163 struct rvu_work *mbox_wrk_up;
164 struct workqueue_struct *mbox_wq;
170 dma_addr_t msix_base_iova;
173 #define PF_CGXMAP_BASE 1 /* PF 0 is reserved for RVU PF */
175 u8 cgx_cnt; /* available cgx ports */
176 u8 *pf2cgxlmac_map; /* pf to cgx_lmac map */
177 u16 *cgxlmac2pf_map; /* bitmap of mapped pfs for
178 * every cgx lmac port
180 unsigned long pf_notify_bmap; /* Flags for PF notification */
181 void **cgx_idmap; /* cgx id to cgx data map table */
182 struct work_struct cgx_evh_work;
183 struct workqueue_struct *cgx_evh_wq;
184 spinlock_t cgx_evq_lock; /* cgx event queue lock */
185 struct list_head cgx_evq_head; /* cgx event queue head */
188 static inline void rvu_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
190 writeq(val, rvu->afreg_base + ((block << 28) | offset));
193 static inline u64 rvu_read64(struct rvu *rvu, u64 block, u64 offset)
195 return readq(rvu->afreg_base + ((block << 28) | offset));
198 static inline void rvupf_write64(struct rvu *rvu, u64 offset, u64 val)
200 writeq(val, rvu->pfreg_base + offset);
203 static inline u64 rvupf_read64(struct rvu *rvu, u64 offset)
205 return readq(rvu->pfreg_base + offset);
208 /* Function Prototypes
211 int rvu_alloc_bitmap(struct rsrc_bmap *rsrc);
212 int rvu_alloc_rsrc(struct rsrc_bmap *rsrc);
213 void rvu_free_rsrc(struct rsrc_bmap *rsrc, int id);
214 int rvu_rsrc_free_count(struct rsrc_bmap *rsrc);
215 int rvu_alloc_rsrc_contig(struct rsrc_bmap *rsrc, int nrsrc);
216 bool rvu_rsrc_check_contig(struct rsrc_bmap *rsrc, int nrsrc);
217 int rvu_get_pf(u16 pcifunc);
218 struct rvu_pfvf *rvu_get_pfvf(struct rvu *rvu, int pcifunc);
219 void rvu_get_pf_numvfs(struct rvu *rvu, int pf, int *numvfs, int *hwvf);
220 bool is_block_implemented(struct rvu_hwinfo *hw, int blkaddr);
221 int rvu_get_lf(struct rvu *rvu, struct rvu_block *block, u16 pcifunc, u16 slot);
222 int rvu_lf_reset(struct rvu *rvu, struct rvu_block *block, int lf);
223 int rvu_get_blkaddr(struct rvu *rvu, int blktype, u16 pcifunc);
224 int rvu_poll_reg(struct rvu *rvu, u64 block, u64 offset, u64 mask, bool zero);
226 /* RVU HW reg validation */
232 bool rvu_check_valid_reg(int regmap, int regblk, u64 reg);
234 /* NPA/NIX AQ APIs */
235 int rvu_aq_alloc(struct rvu *rvu, struct admin_queue **ad_queue,
236 int qsize, int inst_size, int res_size);
237 void rvu_aq_free(struct rvu *rvu, struct admin_queue *aq);
240 static inline bool is_pf_cgxmapped(struct rvu *rvu, u8 pf)
242 return (pf >= PF_CGXMAP_BASE && pf <= rvu->cgx_mapped_pfs);
245 static inline void rvu_get_cgx_lmac_id(u8 map, u8 *cgx_id, u8 *lmac_id)
247 *cgx_id = (map >> 4) & 0xF;
248 *lmac_id = (map & 0xF);
251 int rvu_cgx_probe(struct rvu *rvu);
252 void rvu_cgx_wq_destroy(struct rvu *rvu);
253 void *rvu_cgx_pdata(u8 cgx_id, struct rvu *rvu);
254 int rvu_cgx_config_rxtx(struct rvu *rvu, u16 pcifunc, bool start);
255 int rvu_mbox_handler_CGX_START_RXTX(struct rvu *rvu, struct msg_req *req,
256 struct msg_rsp *rsp);
257 int rvu_mbox_handler_CGX_STOP_RXTX(struct rvu *rvu, struct msg_req *req,
258 struct msg_rsp *rsp);
259 int rvu_mbox_handler_CGX_STATS(struct rvu *rvu, struct msg_req *req,
260 struct cgx_stats_rsp *rsp);
261 int rvu_mbox_handler_CGX_MAC_ADDR_SET(struct rvu *rvu,
262 struct cgx_mac_addr_set_or_get *req,
263 struct cgx_mac_addr_set_or_get *rsp);
264 int rvu_mbox_handler_CGX_MAC_ADDR_GET(struct rvu *rvu,
265 struct cgx_mac_addr_set_or_get *req,
266 struct cgx_mac_addr_set_or_get *rsp);
267 int rvu_mbox_handler_CGX_PROMISC_ENABLE(struct rvu *rvu, struct msg_req *req,
268 struct msg_rsp *rsp);
269 int rvu_mbox_handler_CGX_PROMISC_DISABLE(struct rvu *rvu, struct msg_req *req,
270 struct msg_rsp *rsp);
271 int rvu_mbox_handler_CGX_START_LINKEVENTS(struct rvu *rvu, struct msg_req *req,
272 struct msg_rsp *rsp);
273 int rvu_mbox_handler_CGX_STOP_LINKEVENTS(struct rvu *rvu, struct msg_req *req,
274 struct msg_rsp *rsp);
275 int rvu_mbox_handler_CGX_GET_LINKINFO(struct rvu *rvu, struct msg_req *req,
276 struct cgx_link_info_msg *rsp);
277 int rvu_mbox_handler_CGX_INTLBK_ENABLE(struct rvu *rvu, struct msg_req *req,
278 struct msg_rsp *rsp);
279 int rvu_mbox_handler_CGX_INTLBK_DISABLE(struct rvu *rvu, struct msg_req *req,
280 struct msg_rsp *rsp);
283 int rvu_npa_init(struct rvu *rvu);
284 void rvu_npa_freemem(struct rvu *rvu);
285 int rvu_mbox_handler_NPA_AQ_ENQ(struct rvu *rvu,
286 struct npa_aq_enq_req *req,
287 struct npa_aq_enq_rsp *rsp);
288 int rvu_mbox_handler_NPA_HWCTX_DISABLE(struct rvu *rvu,
289 struct hwctx_disable_req *req,
290 struct msg_rsp *rsp);
291 int rvu_mbox_handler_NPA_LF_ALLOC(struct rvu *rvu,
292 struct npa_lf_alloc_req *req,
293 struct npa_lf_alloc_rsp *rsp);
294 int rvu_mbox_handler_NPA_LF_FREE(struct rvu *rvu, struct msg_req *req,
295 struct msg_rsp *rsp);
298 int rvu_nix_init(struct rvu *rvu);
299 void rvu_nix_freemem(struct rvu *rvu);
300 int rvu_mbox_handler_NIX_LF_ALLOC(struct rvu *rvu,
301 struct nix_lf_alloc_req *req,
302 struct nix_lf_alloc_rsp *rsp);
303 int rvu_mbox_handler_NIX_LF_FREE(struct rvu *rvu, struct msg_req *req,
304 struct msg_rsp *rsp);
305 int rvu_mbox_handler_NIX_AQ_ENQ(struct rvu *rvu,
306 struct nix_aq_enq_req *req,
307 struct nix_aq_enq_rsp *rsp);
308 int rvu_mbox_handler_NIX_HWCTX_DISABLE(struct rvu *rvu,
309 struct hwctx_disable_req *req,
310 struct msg_rsp *rsp);
311 int rvu_mbox_handler_NIX_TXSCH_ALLOC(struct rvu *rvu,
312 struct nix_txsch_alloc_req *req,
313 struct nix_txsch_alloc_rsp *rsp);
314 int rvu_mbox_handler_NIX_TXSCH_FREE(struct rvu *rvu,
315 struct nix_txsch_free_req *req,
316 struct msg_rsp *rsp);
317 int rvu_mbox_handler_NIX_TXSCHQ_CFG(struct rvu *rvu,
318 struct nix_txschq_config *req,
319 struct msg_rsp *rsp);
320 int rvu_mbox_handler_NIX_STATS_RST(struct rvu *rvu, struct msg_req *req,
321 struct msg_rsp *rsp);
322 int rvu_mbox_handler_NIX_VTAG_CFG(struct rvu *rvu,
323 struct nix_vtag_config *req,
324 struct msg_rsp *rsp);
327 int rvu_npc_init(struct rvu *rvu);
328 void rvu_npc_freemem(struct rvu *rvu);
329 int rvu_npc_get_pkind(struct rvu *rvu, u16 pf);
330 void rvu_npc_set_pkind(struct rvu *rvu, int pkind, struct rvu_pfvf *pfvf);