octeontx2-af: Support for VTAG strip and capture
[linux-2.6-microblaze.git] / drivers / net / ethernet / marvell / octeontx2 / af / rvu.h
1 /* SPDX-License-Identifier: GPL-2.0
2  * Marvell OcteonTx2 RVU Admin Function driver
3  *
4  * Copyright (C) 2018 Marvell International Ltd.
5  *
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.
9  */
10
11 #ifndef RVU_H
12 #define RVU_H
13
14 #include "rvu_struct.h"
15 #include "common.h"
16 #include "mbox.h"
17
18 /* PCI device IDs */
19 #define PCI_DEVID_OCTEONTX2_RVU_AF              0xA065
20
21 /* PCI BAR nos */
22 #define PCI_AF_REG_BAR_NUM                      0
23 #define PCI_PF_REG_BAR_NUM                      2
24 #define PCI_MBOX_BAR_NUM                        4
25
26 #define NAME_SIZE                               32
27
28 /* PF_FUNC */
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
33
34 struct rvu_work {
35         struct  work_struct work;
36         struct  rvu *rvu;
37 };
38
39 struct rsrc_bmap {
40         unsigned long *bmap;    /* Pointer to resource bitmap */
41         u16  max;               /* Max resource id or count */
42 };
43
44 struct rvu_block {
45         struct rsrc_bmap        lf;
46         struct admin_queue      *aq; /* NIX/NPA AQ */
47         u16  *fn_map; /* LF to pcifunc mapping */
48         bool multislot;
49         bool implemented;
50         u8   addr;  /* RVU_BLOCK_ADDR_E */
51         u8   type;  /* RVU_BLOCK_TYPE_E */
52         u8   lfshift;
53         u64  lookup_reg;
54         u64  pf_lfcnt_reg;
55         u64  vf_lfcnt_reg;
56         u64  lfcfg_reg;
57         u64  msixcfg_reg;
58         u64  lfreset_reg;
59         unsigned char name[NAME_SIZE];
60 };
61
62 struct nix_mcast {
63         struct qmem     *mce_ctx;
64         struct qmem     *mcast_buf;
65         int             replay_pkind;
66         int             next_free_mce;
67         spinlock_t      mce_lock; /* Serialize MCE updates */
68 };
69
70 struct nix_mce_list {
71         struct hlist_head       head;
72         int                     count;
73         int                     max;
74 };
75
76 /* Structure for per RVU func info ie PF/VF */
77 struct rvu_pfvf {
78         bool            npalf; /* Only one NPALF per RVU_FUNC */
79         bool            nixlf; /* Only one NIXLF per RVU_FUNC */
80         u16             sso;
81         u16             ssow;
82         u16             cptlfs;
83         u16             timlfs;
84         u8              cgx_lmac;
85
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 */
90
91         /* NPA contexts */
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;
97
98         /* NIX contexts */
99         struct qmem     *rq_ctx;
100         struct qmem     *sq_ctx;
101         struct qmem     *cq_ctx;
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;
108
109         u8              mac_addr[ETH_ALEN]; /* MAC address of this PF/VF */
110
111         /* Broadcast pkt replication info */
112         u16                     bcast_mce_idx;
113         struct nix_mce_list     bcast_mce_list;
114 };
115
116 struct nix_txsch {
117         struct rsrc_bmap schq;
118         u8   lvl;
119         u16  *pfvf_map;
120 };
121
122 struct npc_pkind {
123         struct rsrc_bmap rsrc;
124         u32     *pfchan_map;
125 };
126
127 struct nix_hw {
128         struct nix_txsch txsch[NIX_TXSCH_LVL_CNT]; /* Tx schedulers */
129         struct nix_mcast mcast;
130 };
131
132 struct rvu_hwinfo {
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 */
136         u8      cgx;
137         u8      lmac_per_cgx;
138         u8      cgx_links;
139         u8      lbk_links;
140         u8      sdp_links;
141         u8      npc_kpus;          /* No of parser units */
142
143
144         struct rvu_block block[BLK_COUNT]; /* Block info */
145         struct nix_hw    *nix0;
146         struct npc_pkind pkind;
147 };
148
149 struct rvu {
150         void __iomem            *afreg_base;
151         void __iomem            *pfreg_base;
152         struct pci_dev          *pdev;
153         struct device           *dev;
154         struct rvu_hwinfo       *hw;
155         struct rvu_pfvf         *pf;
156         struct rvu_pfvf         *hwvf;
157         spinlock_t              rsrc_lock; /* Serialize resource alloc/free */
158
159         /* Mbox */
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;
165
166         /* MSI-X */
167         u16                     num_vec;
168         char                    *irq_name;
169         bool                    *irq_allocated;
170         dma_addr_t              msix_base_iova;
171
172         /* CGX */
173 #define PF_CGXMAP_BASE          1 /* PF 0 is reserved for RVU PF */
174         u8                      cgx_mapped_pfs;
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
179                                                   */
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 */
186 };
187
188 static inline void rvu_write64(struct rvu *rvu, u64 block, u64 offset, u64 val)
189 {
190         writeq(val, rvu->afreg_base + ((block << 28) | offset));
191 }
192
193 static inline u64 rvu_read64(struct rvu *rvu, u64 block, u64 offset)
194 {
195         return readq(rvu->afreg_base + ((block << 28) | offset));
196 }
197
198 static inline void rvupf_write64(struct rvu *rvu, u64 offset, u64 val)
199 {
200         writeq(val, rvu->pfreg_base + offset);
201 }
202
203 static inline u64 rvupf_read64(struct rvu *rvu, u64 offset)
204 {
205         return readq(rvu->pfreg_base + offset);
206 }
207
208 /* Function Prototypes
209  * RVU
210  */
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);
225
226 /* RVU HW reg validation */
227 enum regmap_block {
228         TXSCHQ_HWREGMAP = 0,
229         MAX_HWREGMAP,
230 };
231
232 bool rvu_check_valid_reg(int regmap, int regblk, u64 reg);
233
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);
238
239 /* CGX APIs */
240 static inline bool is_pf_cgxmapped(struct rvu *rvu, u8 pf)
241 {
242         return (pf >= PF_CGXMAP_BASE && pf <= rvu->cgx_mapped_pfs);
243 }
244
245 static inline void rvu_get_cgx_lmac_id(u8 map, u8 *cgx_id, u8 *lmac_id)
246 {
247         *cgx_id = (map >> 4) & 0xF;
248         *lmac_id = (map & 0xF);
249 }
250
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);
281
282 /* NPA APIs */
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);
296
297 /* NIX APIs */
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);
325
326 /* NPC APIs */
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);
331 #endif /* RVU_H */