octeontx2-af: Support for VTAG strip and capture
[linux-2.6-microblaze.git] / drivers / net / ethernet / marvell / octeontx2 / af / mbox.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 MBOX_H
12 #define MBOX_H
13
14 #include <linux/etherdevice.h>
15 #include <linux/sizes.h>
16
17 #include "rvu_struct.h"
18 #include "common.h"
19
20 #define MBOX_SIZE               SZ_64K
21
22 /* AF/PF: PF initiated, PF/VF VF initiated */
23 #define MBOX_DOWN_RX_START      0
24 #define MBOX_DOWN_RX_SIZE       (46 * SZ_1K)
25 #define MBOX_DOWN_TX_START      (MBOX_DOWN_RX_START + MBOX_DOWN_RX_SIZE)
26 #define MBOX_DOWN_TX_SIZE       (16 * SZ_1K)
27 /* AF/PF: AF initiated, PF/VF PF initiated */
28 #define MBOX_UP_RX_START        (MBOX_DOWN_TX_START + MBOX_DOWN_TX_SIZE)
29 #define MBOX_UP_RX_SIZE         SZ_1K
30 #define MBOX_UP_TX_START        (MBOX_UP_RX_START + MBOX_UP_RX_SIZE)
31 #define MBOX_UP_TX_SIZE         SZ_1K
32
33 #if MBOX_UP_TX_SIZE + MBOX_UP_TX_START != MBOX_SIZE
34 # error "incorrect mailbox area sizes"
35 #endif
36
37 #define INTR_MASK(pfvfs) ((pfvfs < 64) ? (BIT_ULL(pfvfs) - 1) : (~0ull))
38
39 #define MBOX_RSP_TIMEOUT        1000 /* in ms, Time to wait for mbox response */
40
41 #define MBOX_MSG_ALIGN          16  /* Align mbox msg start to 16bytes */
42
43 /* Mailbox directions */
44 #define MBOX_DIR_AFPF           0  /* AF replies to PF */
45 #define MBOX_DIR_PFAF           1  /* PF sends messages to AF */
46 #define MBOX_DIR_PFVF           2  /* PF replies to VF */
47 #define MBOX_DIR_VFPF           3  /* VF sends messages to PF */
48 #define MBOX_DIR_AFPF_UP        4  /* AF sends messages to PF */
49 #define MBOX_DIR_PFAF_UP        5  /* PF replies to AF */
50 #define MBOX_DIR_PFVF_UP        6  /* PF sends messages to VF */
51 #define MBOX_DIR_VFPF_UP        7  /* VF replies to PF */
52
53 struct otx2_mbox_dev {
54         void        *mbase;   /* This dev's mbox region */
55         spinlock_t  mbox_lock;
56         u16         msg_size; /* Total msg size to be sent */
57         u16         rsp_size; /* Total rsp size to be sure the reply is ok */
58         u16         num_msgs; /* No of msgs sent or waiting for response */
59         u16         msgs_acked; /* No of msgs for which response is received */
60 };
61
62 struct otx2_mbox {
63         struct pci_dev *pdev;
64         void   *hwbase;  /* Mbox region advertised by HW */
65         void   *reg_base;/* CSR base for this dev */
66         u64    trigger;  /* Trigger mbox notification */
67         u16    tr_shift; /* Mbox trigger shift */
68         u64    rx_start; /* Offset of Rx region in mbox memory */
69         u64    tx_start; /* Offset of Tx region in mbox memory */
70         u16    rx_size;  /* Size of Rx region */
71         u16    tx_size;  /* Size of Tx region */
72         u16    ndevs;    /* The number of peers */
73         struct otx2_mbox_dev *dev;
74 };
75
76 /* Header which preceeds all mbox messages */
77 struct mbox_hdr {
78         u16  num_msgs;   /* No of msgs embedded */
79 };
80
81 /* Header which preceeds every msg and is also part of it */
82 struct mbox_msghdr {
83         u16 pcifunc;     /* Who's sending this msg */
84         u16 id;          /* Mbox message ID */
85 #define OTX2_MBOX_REQ_SIG (0xdead)
86 #define OTX2_MBOX_RSP_SIG (0xbeef)
87         u16 sig;         /* Signature, for validating corrupted msgs */
88 #define OTX2_MBOX_VERSION (0x0001)
89         u16 ver;         /* Version of msg's structure for this ID */
90         u16 next_msgoff; /* Offset of next msg within mailbox region */
91         int rc;          /* Msg process'ed response code */
92 };
93
94 void otx2_mbox_reset(struct otx2_mbox *mbox, int devid);
95 void otx2_mbox_destroy(struct otx2_mbox *mbox);
96 int otx2_mbox_init(struct otx2_mbox *mbox, void __force *hwbase,
97                    struct pci_dev *pdev, void __force *reg_base,
98                    int direction, int ndevs);
99 void otx2_mbox_msg_send(struct otx2_mbox *mbox, int devid);
100 int otx2_mbox_wait_for_rsp(struct otx2_mbox *mbox, int devid);
101 int otx2_mbox_busy_poll_for_rsp(struct otx2_mbox *mbox, int devid);
102 struct mbox_msghdr *otx2_mbox_alloc_msg_rsp(struct otx2_mbox *mbox, int devid,
103                                             int size, int size_rsp);
104 struct mbox_msghdr *otx2_mbox_get_rsp(struct otx2_mbox *mbox, int devid,
105                                       struct mbox_msghdr *msg);
106 int otx2_reply_invalid_msg(struct otx2_mbox *mbox, int devid,
107                            u16 pcifunc, u16 id);
108 bool otx2_mbox_nonempty(struct otx2_mbox *mbox, int devid);
109 const char *otx2_mbox_id2name(u16 id);
110 static inline struct mbox_msghdr *otx2_mbox_alloc_msg(struct otx2_mbox *mbox,
111                                                       int devid, int size)
112 {
113         return otx2_mbox_alloc_msg_rsp(mbox, devid, size, 0);
114 }
115
116 /* Mailbox message types */
117 #define MBOX_MSG_MASK                           0xFFFF
118 #define MBOX_MSG_INVALID                        0xFFFE
119 #define MBOX_MSG_MAX                            0xFFFF
120
121 #define MBOX_MESSAGES                                                   \
122 /* Generic mbox IDs (range 0x000 - 0x1FF) */                            \
123 M(READY,                0x001, msg_req, ready_msg_rsp)                  \
124 M(ATTACH_RESOURCES,     0x002, rsrc_attach, msg_rsp)                    \
125 M(DETACH_RESOURCES,     0x003, rsrc_detach, msg_rsp)                    \
126 M(MSIX_OFFSET,          0x004, msg_req, msix_offset_rsp)                \
127 /* CGX mbox IDs (range 0x200 - 0x3FF) */                                \
128 M(CGX_START_RXTX,       0x200, msg_req, msg_rsp)                        \
129 M(CGX_STOP_RXTX,        0x201, msg_req, msg_rsp)                        \
130 M(CGX_STATS,            0x202, msg_req, cgx_stats_rsp)                  \
131 M(CGX_MAC_ADDR_SET,     0x203, cgx_mac_addr_set_or_get,                 \
132                                 cgx_mac_addr_set_or_get)                \
133 M(CGX_MAC_ADDR_GET,     0x204, cgx_mac_addr_set_or_get,                 \
134                                 cgx_mac_addr_set_or_get)                \
135 M(CGX_PROMISC_ENABLE,   0x205, msg_req, msg_rsp)                        \
136 M(CGX_PROMISC_DISABLE,  0x206, msg_req, msg_rsp)                        \
137 M(CGX_START_LINKEVENTS, 0x207, msg_req, msg_rsp)                        \
138 M(CGX_STOP_LINKEVENTS,  0x208, msg_req, msg_rsp)                        \
139 M(CGX_GET_LINKINFO,     0x209, msg_req, cgx_link_info_msg)              \
140 M(CGX_INTLBK_ENABLE,    0x20A, msg_req, msg_rsp)                        \
141 M(CGX_INTLBK_DISABLE,   0x20B, msg_req, msg_rsp)                        \
142 /* NPA mbox IDs (range 0x400 - 0x5FF) */                                \
143 M(NPA_LF_ALLOC,         0x400, npa_lf_alloc_req, npa_lf_alloc_rsp)      \
144 M(NPA_LF_FREE,          0x401, msg_req, msg_rsp)                        \
145 M(NPA_AQ_ENQ,           0x402, npa_aq_enq_req, npa_aq_enq_rsp)          \
146 M(NPA_HWCTX_DISABLE,    0x403, hwctx_disable_req, msg_rsp)              \
147 /* SSO/SSOW mbox IDs (range 0x600 - 0x7FF) */                           \
148 /* TIM mbox IDs (range 0x800 - 0x9FF) */                                \
149 /* CPT mbox IDs (range 0xA00 - 0xBFF) */                                \
150 /* NPC mbox IDs (range 0x6000 - 0x7FFF) */                              \
151 /* NIX mbox IDs (range 0x8000 - 0xFFFF) */                              \
152 M(NIX_LF_ALLOC,         0x8000, nix_lf_alloc_req, nix_lf_alloc_rsp)     \
153 M(NIX_LF_FREE,          0x8001, msg_req, msg_rsp)                       \
154 M(NIX_AQ_ENQ,           0x8002, nix_aq_enq_req, nix_aq_enq_rsp)         \
155 M(NIX_HWCTX_DISABLE,    0x8003, hwctx_disable_req, msg_rsp)             \
156 M(NIX_TXSCH_ALLOC,      0x8004, nix_txsch_alloc_req, nix_txsch_alloc_rsp) \
157 M(NIX_TXSCH_FREE,       0x8005, nix_txsch_free_req, msg_rsp)            \
158 M(NIX_TXSCHQ_CFG,       0x8006, nix_txschq_config, msg_rsp)             \
159 M(NIX_STATS_RST,        0x8007, msg_req, msg_rsp)                       \
160 M(NIX_VTAG_CFG, 0x8008, nix_vtag_config, msg_rsp)
161
162 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
163 #define MBOX_UP_CGX_MESSAGES                                            \
164 M(CGX_LINK_EVENT,               0xC00, cgx_link_info_msg, msg_rsp)
165
166 enum {
167 #define M(_name, _id, _1, _2) MBOX_MSG_ ## _name = _id,
168 MBOX_MESSAGES
169 MBOX_UP_CGX_MESSAGES
170 #undef M
171 };
172
173 /* Mailbox message formats */
174
175 #define RVU_DEFAULT_PF_FUNC     0xFFFF
176
177 /* Generic request msg used for those mbox messages which
178  * don't send any data in the request.
179  */
180 struct msg_req {
181         struct mbox_msghdr hdr;
182 };
183
184 /* Generic rsponse msg used a ack or response for those mbox
185  * messages which doesn't have a specific rsp msg format.
186  */
187 struct msg_rsp {
188         struct mbox_msghdr hdr;
189 };
190
191 struct ready_msg_rsp {
192         struct mbox_msghdr hdr;
193         u16    sclk_feq;        /* SCLK frequency */
194 };
195
196 /* Structure for requesting resource provisioning.
197  * 'modify' flag to be used when either requesting more
198  * or to detach partial of a cetain resource type.
199  * Rest of the fields specify how many of what type to
200  * be attached.
201  */
202 struct rsrc_attach {
203         struct mbox_msghdr hdr;
204         u8   modify:1;
205         u8   npalf:1;
206         u8   nixlf:1;
207         u16  sso;
208         u16  ssow;
209         u16  timlfs;
210         u16  cptlfs;
211 };
212
213 /* Structure for relinquishing resources.
214  * 'partial' flag to be used when relinquishing all resources
215  * but only of a certain type. If not set, all resources of all
216  * types provisioned to the RVU function will be detached.
217  */
218 struct rsrc_detach {
219         struct mbox_msghdr hdr;
220         u8 partial:1;
221         u8 npalf:1;
222         u8 nixlf:1;
223         u8 sso:1;
224         u8 ssow:1;
225         u8 timlfs:1;
226         u8 cptlfs:1;
227 };
228
229 #define MSIX_VECTOR_INVALID     0xFFFF
230 #define MAX_RVU_BLKLF_CNT       256
231
232 struct msix_offset_rsp {
233         struct mbox_msghdr hdr;
234         u16  npa_msixoff;
235         u16  nix_msixoff;
236         u8   sso;
237         u8   ssow;
238         u8   timlfs;
239         u8   cptlfs;
240         u16  sso_msixoff[MAX_RVU_BLKLF_CNT];
241         u16  ssow_msixoff[MAX_RVU_BLKLF_CNT];
242         u16  timlf_msixoff[MAX_RVU_BLKLF_CNT];
243         u16  cptlf_msixoff[MAX_RVU_BLKLF_CNT];
244 };
245
246 /* CGX mbox message formats */
247
248 struct cgx_stats_rsp {
249         struct mbox_msghdr hdr;
250 #define CGX_RX_STATS_COUNT      13
251 #define CGX_TX_STATS_COUNT      18
252         u64 rx_stats[CGX_RX_STATS_COUNT];
253         u64 tx_stats[CGX_TX_STATS_COUNT];
254 };
255
256 /* Structure for requesting the operation for
257  * setting/getting mac address in the CGX interface
258  */
259 struct cgx_mac_addr_set_or_get {
260         struct mbox_msghdr hdr;
261         u8 mac_addr[ETH_ALEN];
262 };
263
264 struct cgx_link_user_info {
265         uint64_t link_up:1;
266         uint64_t full_duplex:1;
267         uint64_t lmac_type_id:4;
268         uint64_t speed:20; /* speed in Mbps */
269 #define LMACTYPE_STR_LEN 16
270         char lmac_type[LMACTYPE_STR_LEN];
271 };
272
273 struct cgx_link_info_msg {
274         struct mbox_msghdr hdr;
275         struct cgx_link_user_info link_info;
276 };
277
278 /* NPA mbox message formats */
279
280 /* NPA mailbox error codes
281  * Range 301 - 400.
282  */
283 enum npa_af_status {
284         NPA_AF_ERR_PARAM            = -301,
285         NPA_AF_ERR_AQ_FULL          = -302,
286         NPA_AF_ERR_AQ_ENQUEUE       = -303,
287         NPA_AF_ERR_AF_LF_INVALID    = -304,
288         NPA_AF_ERR_AF_LF_ALLOC      = -305,
289         NPA_AF_ERR_LF_RESET         = -306,
290 };
291
292 /* For NPA LF context alloc and init */
293 struct npa_lf_alloc_req {
294         struct mbox_msghdr hdr;
295         int node;
296         int aura_sz;  /* No of auras */
297         u32 nr_pools; /* No of pools */
298 };
299
300 struct npa_lf_alloc_rsp {
301         struct mbox_msghdr hdr;
302         u32 stack_pg_ptrs;  /* No of ptrs per stack page */
303         u32 stack_pg_bytes; /* Size of stack page */
304         u16 qints; /* NPA_AF_CONST::QINTS */
305 };
306
307 /* NPA AQ enqueue msg */
308 struct npa_aq_enq_req {
309         struct mbox_msghdr hdr;
310         u32 aura_id;
311         u8 ctype;
312         u8 op;
313         union {
314                 /* Valid when op == WRITE/INIT and ctype == AURA.
315                  * LF fills the pool_id in aura.pool_addr. AF will translate
316                  * the pool_id to pool context pointer.
317                  */
318                 struct npa_aura_s aura;
319                 /* Valid when op == WRITE/INIT and ctype == POOL */
320                 struct npa_pool_s pool;
321         };
322         /* Mask data when op == WRITE (1=write, 0=don't write) */
323         union {
324                 /* Valid when op == WRITE and ctype == AURA */
325                 struct npa_aura_s aura_mask;
326                 /* Valid when op == WRITE and ctype == POOL */
327                 struct npa_pool_s pool_mask;
328         };
329 };
330
331 struct npa_aq_enq_rsp {
332         struct mbox_msghdr hdr;
333         union {
334                 /* Valid when op == READ and ctype == AURA */
335                 struct npa_aura_s aura;
336                 /* Valid when op == READ and ctype == POOL */
337                 struct npa_pool_s pool;
338         };
339 };
340
341 /* Disable all contexts of type 'ctype' */
342 struct hwctx_disable_req {
343         struct mbox_msghdr hdr;
344         u8 ctype;
345 };
346
347 /* NIX mailbox error codes
348  * Range 401 - 500.
349  */
350 enum nix_af_status {
351         NIX_AF_ERR_PARAM            = -401,
352         NIX_AF_ERR_AQ_FULL          = -402,
353         NIX_AF_ERR_AQ_ENQUEUE       = -403,
354         NIX_AF_ERR_AF_LF_INVALID    = -404,
355         NIX_AF_ERR_AF_LF_ALLOC      = -405,
356         NIX_AF_ERR_TLX_ALLOC_FAIL   = -406,
357         NIX_AF_ERR_TLX_INVALID      = -407,
358         NIX_AF_ERR_RSS_SIZE_INVALID = -408,
359         NIX_AF_ERR_RSS_GRPS_INVALID = -409,
360         NIX_AF_ERR_FRS_INVALID      = -410,
361         NIX_AF_ERR_RX_LINK_INVALID  = -411,
362         NIX_AF_INVAL_TXSCHQ_CFG     = -412,
363         NIX_AF_SMQ_FLUSH_FAILED     = -413,
364         NIX_AF_ERR_LF_RESET         = -414,
365 };
366
367 /* For NIX LF context alloc and init */
368 struct nix_lf_alloc_req {
369         struct mbox_msghdr hdr;
370         int node;
371         u32 rq_cnt;   /* No of receive queues */
372         u32 sq_cnt;   /* No of send queues */
373         u32 cq_cnt;   /* No of completion queues */
374         u8  xqe_sz;
375         u16 rss_sz;
376         u8  rss_grps;
377         u16 npa_func;
378         u16 sso_func;
379         u64 rx_cfg;   /* See NIX_AF_LF(0..127)_RX_CFG */
380 };
381
382 struct nix_lf_alloc_rsp {
383         struct mbox_msghdr hdr;
384         u16     sqb_size;
385         u8      lso_tsov4_idx;
386         u8      lso_tsov6_idx;
387         u8      mac_addr[ETH_ALEN];
388 };
389
390 /* NIX AQ enqueue msg */
391 struct nix_aq_enq_req {
392         struct mbox_msghdr hdr;
393         u32  qidx;
394         u8 ctype;
395         u8 op;
396         union {
397                 struct nix_rq_ctx_s rq;
398                 struct nix_sq_ctx_s sq;
399                 struct nix_cq_ctx_s cq;
400                 struct nix_rsse_s   rss;
401                 struct nix_rx_mce_s mce;
402         };
403         union {
404                 struct nix_rq_ctx_s rq_mask;
405                 struct nix_sq_ctx_s sq_mask;
406                 struct nix_cq_ctx_s cq_mask;
407                 struct nix_rsse_s   rss_mask;
408                 struct nix_rx_mce_s mce_mask;
409         };
410 };
411
412 struct nix_aq_enq_rsp {
413         struct mbox_msghdr hdr;
414         union {
415                 struct nix_rq_ctx_s rq;
416                 struct nix_sq_ctx_s sq;
417                 struct nix_cq_ctx_s cq;
418                 struct nix_rsse_s   rss;
419                 struct nix_rx_mce_s mce;
420         };
421 };
422
423 /* Tx scheduler/shaper mailbox messages */
424
425 #define MAX_TXSCHQ_PER_FUNC             128
426
427 struct nix_txsch_alloc_req {
428         struct mbox_msghdr hdr;
429         /* Scheduler queue count request at each level */
430         u16 schq_contig[NIX_TXSCH_LVL_CNT]; /* No of contiguous queues */
431         u16 schq[NIX_TXSCH_LVL_CNT]; /* No of non-contiguous queues */
432 };
433
434 struct nix_txsch_alloc_rsp {
435         struct mbox_msghdr hdr;
436         /* Scheduler queue count allocated at each level */
437         u16 schq_contig[NIX_TXSCH_LVL_CNT];
438         u16 schq[NIX_TXSCH_LVL_CNT];
439         /* Scheduler queue list allocated at each level */
440         u16 schq_contig_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
441         u16 schq_list[NIX_TXSCH_LVL_CNT][MAX_TXSCHQ_PER_FUNC];
442 };
443
444 struct nix_txsch_free_req {
445         struct mbox_msghdr hdr;
446 #define TXSCHQ_FREE_ALL BIT_ULL(0)
447         u16 flags;
448         /* Scheduler queue level to be freed */
449         u16 schq_lvl;
450         /* List of scheduler queues to be freed */
451         u16 schq;
452 };
453
454 struct nix_txschq_config {
455         struct mbox_msghdr hdr;
456         u8 lvl; /* SMQ/MDQ/TL4/TL3/TL2/TL1 */
457 #define TXSCHQ_IDX_SHIFT        16
458 #define TXSCHQ_IDX_MASK         (BIT_ULL(10) - 1)
459 #define TXSCHQ_IDX(reg, shift)  (((reg) >> (shift)) & TXSCHQ_IDX_MASK)
460         u8 num_regs;
461 #define MAX_REGS_PER_MBOX_MSG   20
462         u64 reg[MAX_REGS_PER_MBOX_MSG];
463         u64 regval[MAX_REGS_PER_MBOX_MSG];
464 };
465
466 struct nix_vtag_config {
467         struct mbox_msghdr hdr;
468         u8 vtag_size;
469         /* cfg_type is '0' for tx vlan cfg
470          * cfg_type is '1' for rx vlan cfg
471          */
472         u8 cfg_type;
473         union {
474                 /* valid when cfg_type is '0' */
475                 struct {
476                         /* tx vlan0 tag(C-VLAN) */
477                         u64 vlan0;
478                         /* tx vlan1 tag(S-VLAN) */
479                         u64 vlan1;
480                         /* insert tx vlan tag */
481                         u8 insert_vlan :1;
482                         /* insert tx double vlan tag */
483                         u8 double_vlan :1;
484                 } tx;
485
486                 /* valid when cfg_type is '1' */
487                 struct {
488                         /* rx vtag type index */
489                         u8 vtag_type;
490                         /* rx vtag strip */
491                         u8 strip_vtag :1;
492                         /* rx vtag capture */
493                         u8 capture_vtag :1;
494                 } rx;
495         };
496 };
497
498 #endif /* MBOX_H */