New upstream version 18.08
[deb_dpdk.git] / drivers / net / octeontx / base / octeontx_pkivf.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4
5 #ifndef __OCTEONTX_PKI_H__
6 #define __OCTEONTX_PKI_H__
7
8 #include <stdint.h>
9
10 #include <octeontx_mbox.h>
11
12 #define OCTEONTX_PKI_COPROC                     5
13
14 /* PKI messages */
15
16 #define MBOX_PKI_PORT_OPEN                      1
17 #define MBOX_PKI_PORT_START                     2
18 #define MBOX_PKI_PORT_STOP                      3
19 #define MBOX_PKI_PORT_CLOSE                     4
20 #define MBOX_PKI_PORT_CONFIG                    5
21 #define MBOX_PKI_PORT_OPT_PARSER_CONFIG         6
22 #define MBOX_PKI_PORT_CUSTOM_PARSER_CONFIG      7
23 #define MBOX_PKI_PORT_PKTBUF_CONFIG             8
24 #define MBOX_PKI_PORT_HASH_CONFIG               9
25 #define MBOX_PKI_PORT_ERRCHK_CONFIG             10
26 #define MBOX_PKI_PORT_CREATE_QOS                11
27 #define MBOX_PKI_PORT_MODIFY_QOS                12
28 #define MBOX_PKI_PORT_DELETE_QOS                13
29 #define MBOX_PKI_PORT_PKTDROP_CONFIG            14
30 #define MBOX_PKI_PORT_WQE_GEN_CONFIG            15
31 #define MBOX_PKI_BACKPRESSURE_CONFIG            16
32 #define MBOX_PKI_PORT_GET_STATS                 17
33 #define MBOX_PKI_PORT_RESET_STATS               18
34 #define MBOX_PKI_GET_PORT_CONFIG                19
35 #define MBOX_PKI_GET_PORT_QOS_CONFIG            20
36
37 #define MBOX_PKI_MAX_QOS_ENTRY 64
38
39 /* pki pkind parse mode */
40 enum  {
41         MBOX_PKI_PARSE_LA_TO_LG = 0,
42         MBOX_PKI_PARSE_LB_TO_LG = 1,
43         MBOX_PKI_PARSE_LC_TO_LG = 3,
44         MBOX_PKI_PARSE_LG = 0x3f,
45         MBOX_PKI_PARSE_NOTHING = 0x7f
46 };
47
48 /* Interface types: */
49 enum {
50         OCTTX_PORT_TYPE_NET, /* Network interface ports */
51         OCTTX_PORT_TYPE_INT, /* CPU internal interface ports */
52         OCTTX_PORT_TYPE_PCI, /* DPI/PCIe interface ports */
53         OCTTX_PORT_TYPE_MAX
54 };
55
56 /* pki port config */
57 typedef struct mbox_pki_port_type {
58         uint8_t port_type;
59 } mbox_pki_port_t;
60
61 /* pki port config */
62 typedef struct mbox_pki_port_cfg {
63         uint8_t port_type;
64         struct {
65                 uint8_t fcs_pres:1;
66                 uint8_t fcs_skip:1;
67                 uint8_t parse_mode:1;
68                 uint8_t mpls_parse:1;
69                 uint8_t inst_hdr_parse:1;
70                 uint8_t fulc_parse:1;
71                 uint8_t dsa_parse:1;
72                 uint8_t hg2_parse:1;
73                 uint8_t hg_parse:1;
74         } mmask;
75         uint8_t fcs_pres;
76         uint8_t fcs_skip;
77         uint8_t parse_mode;
78         uint8_t mpls_parse;
79         uint8_t inst_hdr_parse;
80         uint8_t fulc_parse;
81         uint8_t dsa_parse;
82         uint8_t hg2_parse;
83         uint8_t hg_parse;
84 } mbox_pki_prt_cfg_t;
85
86 /* pki Flow/style packet buffer config */
87 typedef struct mbox_pki_port_pktbuf_cfg {
88         uint8_t port_type;
89         struct {
90                 uint16_t f_mbuff_size:1;
91                 uint16_t f_wqe_skip:1;
92                 uint16_t f_first_skip:1;
93                 uint16_t f_later_skip:1;
94                 uint16_t f_pkt_outside_wqe:1;
95                 uint16_t f_wqe_endian:1;
96                 uint16_t f_cache_mode:1;
97         } mmask;
98         uint16_t mbuff_size;
99         uint16_t wqe_skip;
100         uint16_t first_skip;
101         uint16_t later_skip;
102         uint8_t pkt_outside_wqe;
103         uint8_t wqe_endian;
104         uint8_t cache_mode;
105 } mbox_pki_pktbuf_cfg_t;
106
107 /* pki flow/style tag config */
108 typedef struct mbox_pki_port_hash_cfg {
109         uint8_t port_type;
110         uint32_t tag_slf:1;
111         uint32_t tag_sle:1;
112         uint32_t tag_sld:1;
113         uint32_t tag_slc:1;
114         uint32_t tag_dlf:1;
115         uint32_t tag_dle:1;
116         uint32_t tag_dld:1;
117         uint32_t tag_dlc:1;
118         uint32_t tag_prt:1;
119         uint32_t tag_vlan0:1;
120         uint32_t tag_vlan1:1;
121         uint32_t tag_ip_pctl:1;
122         uint32_t tag_sync:1;
123         uint32_t tag_spi:1;
124         uint32_t tag_gtp:1;
125         uint32_t tag_vni:1;
126 } mbox_pki_hash_cfg_t;
127
128 /* pki flow/style errcheck config */
129 typedef struct mbox_pki_port_errcheck_cfg {
130         uint8_t port_type;
131         struct {
132                 uint32_t f_ip6_udp_opt:1;
133                 uint32_t f_lenerr_en:1;
134                 uint32_t f_maxerr_en:1;
135                 uint32_t f_minerr_en:1;
136                 uint32_t f_fcs_chk:1;
137                 uint32_t f_fcs_strip:1;
138                 uint32_t f_len_lf:1;
139                 uint32_t f_len_le:1;
140                 uint32_t f_len_ld:1;
141                 uint32_t f_len_lc:1;
142                 uint32_t f_csum_lf:1;
143                 uint32_t f_csum_le:1;
144                 uint32_t f_csum_ld:1;
145                 uint32_t f_csum_lc:1;
146                 uint32_t f_min_frame_len;
147                 uint32_t f_max_frame_len;
148         } mmask;
149         uint64_t ip6_udp_opt:1;
150         uint64_t lenerr_en:1;
151         uint64_t maxerr_en:1;
152         uint64_t minerr_en:1;
153         uint64_t fcs_chk:1;
154         uint64_t fcs_strip:1;
155         uint64_t len_lf:1;
156         uint64_t len_le:1;
157         uint64_t len_ld:1;
158         uint64_t len_lc:1;
159         uint64_t csum_lf:1;
160         uint64_t csum_le:1;
161         uint64_t csum_ld:1;
162         uint64_t csum_lc:1;
163         uint64_t min_frame_len;
164         uint64_t max_frame_len;
165 } mbox_pki_errcheck_cfg_t;
166
167 /* CACHE MODE*/
168 enum {
169         MBOX_PKI_OPC_MODE_STT = 0LL,
170         MBOX_PKI_OPC_MODE_STF = 1LL,
171         MBOX_PKI_OPC_MODE_STF1_STT = 2LL,
172         MBOX_PKI_OPC_MODE_STF2_STT = 3LL
173 };
174
175 /* PKI QPG QOS*/
176 enum {
177         MBOX_PKI_QPG_QOS_NONE = 0,
178         MBOX_PKI_QPG_QOS_VLAN,
179         MBOX_PKI_QPG_QOS_MPLS,
180         MBOX_PKI_QPG_QOS_DSA_SRC,
181         MBOX_PKI_QPG_QOS_DIFFSERV,
182         MBOX_PKI_QPG_QOS_HIGIG,
183 };
184
185 struct mbox_pki_qos_entry {
186         uint16_t port_add;
187         uint16_t ggrp_ok;
188         uint16_t ggrp_bad;
189         uint16_t gaura;
190         uint8_t grptag_ok;
191         uint8_t grptag_bad;
192 };
193
194 /* pki flow/style enable qos */
195 typedef struct mbox_pki_port_create_qos {
196         uint8_t port_type;
197         uint8_t qpg_qos;
198         uint8_t num_entry;
199         uint8_t tag_type;
200         uint8_t drop_policy;
201         struct mbox_pki_qos_entry qos_entry[MBOX_PKI_MAX_QOS_ENTRY];
202 } mbox_pki_qos_cfg_t;
203
204 /* pki flow/style enable qos */
205 typedef struct mbox_pki_port_modify_qos_entry {
206         uint8_t port_type;
207         uint16_t index;
208         struct {
209                 uint8_t f_port_add:1;
210                 uint8_t f_grp_ok:1;
211                 uint8_t f_grp_bad:1;
212                 uint8_t f_gaura:1;
213                 uint8_t f_grptag_ok:1;
214                 uint8_t f_grptag_bad:1;
215                 uint8_t f_tag_type:1;
216         } mmask;
217         uint8_t tag_type;
218         struct mbox_pki_qos_entry qos_entry;
219 } mbox_pki_mod_qos_t;
220
221 /* pki flow/style enable qos */
222 typedef struct mbox_pki_port_delete_qos_entry {
223         uint8_t port_type;
224         uint16_t index;
225 } mbox_pki_del_qos_t;
226
227 /* PKI maximum constants */
228 #define PKI_VF_MAX                      (1)
229 #define PKI_MAX_PKTLEN                  (32768)
230
231 /* pki pkind parse mode */
232 enum  {
233         PKI_PARSE_LA_TO_LG = 0,
234         PKI_PARSE_LB_TO_LG = 1,
235         PKI_PARSE_LC_TO_LG = 3,
236         PKI_PARSE_LG = 0x3f,
237         PKI_PARSE_NOTHING = 0x7f
238 };
239
240 /* pki port config */
241 typedef struct pki_port_cfg {
242         uint8_t port_type;
243         struct {
244                 uint8_t fcs_pres:1;
245                 uint8_t fcs_skip:1;
246                 uint8_t parse_mode:1;
247                 uint8_t mpls_parse:1;
248                 uint8_t inst_hdr_parse:1;
249                 uint8_t fulc_parse:1;
250                 uint8_t dsa_parse:1;
251                 uint8_t hg2_parse:1;
252                 uint8_t hg_parse:1;
253         } mmask;
254         uint8_t fcs_pres;
255         uint8_t fcs_skip;
256         uint8_t parse_mode;
257         uint8_t mpls_parse;
258         uint8_t inst_hdr_parse;
259         uint8_t fulc_parse;
260         uint8_t dsa_parse;
261         uint8_t hg2_parse;
262         uint8_t hg_parse;
263 } pki_prt_cfg_t;
264
265
266 /* pki Flow/style packet buffer config */
267 typedef struct pki_port_pktbuf_cfg {
268         uint8_t port_type;
269         struct {
270                 uint16_t f_mbuff_size:1;
271                 uint16_t f_wqe_skip:1;
272                 uint16_t f_first_skip:1;
273                 uint16_t f_later_skip:1;
274                 uint16_t f_pkt_outside_wqe:1;
275                 uint16_t f_wqe_endian:1;
276                 uint16_t f_cache_mode:1;
277         } mmask;
278         uint16_t mbuff_size;
279         uint16_t wqe_skip;
280         uint16_t first_skip;
281         uint16_t later_skip;
282         uint8_t pkt_outside_wqe;
283         uint8_t wqe_endian;
284         uint8_t cache_mode;
285 } pki_pktbuf_cfg_t;
286
287 /* pki flow/style tag config */
288 typedef struct pki_port_hash_cfg {
289         uint8_t port_type;
290         uint32_t tag_slf:1;
291         uint32_t tag_sle:1;
292         uint32_t tag_sld:1;
293         uint32_t tag_slc:1;
294         uint32_t tag_dlf:1;
295         uint32_t tag_dle:1;
296         uint32_t tag_dld:1;
297         uint32_t tag_dlc:1;
298         uint32_t tag_prt:1;
299         uint32_t tag_vlan0:1;
300         uint32_t tag_vlan1:1;
301         uint32_t tag_ip_pctl:1;
302         uint32_t tag_sync:1;
303         uint32_t tag_spi:1;
304         uint32_t tag_gtp:1;
305         uint32_t tag_vni:1;
306 } pki_hash_cfg_t;
307
308 /* pki flow/style errcheck config */
309 typedef struct pki_port_errcheck_cfg {
310         uint8_t port_type;
311         struct {
312                 uint32_t f_ip6_udp_opt:1;
313                 uint32_t f_lenerr_en:1;
314                 uint32_t f_maxerr_en:1;
315                 uint32_t f_minerr_en:1;
316                 uint32_t f_fcs_chk:1;
317                 uint32_t f_fcs_strip:1;
318                 uint32_t f_len_lf:1;
319                 uint32_t f_len_le:1;
320                 uint32_t f_len_ld:1;
321                 uint32_t f_len_lc:1;
322                 uint32_t f_csum_lf:1;
323                 uint32_t f_csum_le:1;
324                 uint32_t f_csum_ld:1;
325                 uint32_t f_csum_lc:1;
326                 uint32_t f_min_frame_len;
327                 uint32_t f_max_frame_len;
328         } mmask;
329         uint64_t ip6_udp_opt:1;
330         uint64_t lenerr_en:1;
331         uint64_t maxerr_en:1;
332         uint64_t minerr_en:1;
333         uint64_t fcs_chk:1;
334         uint64_t fcs_strip:1;
335         uint64_t len_lf:1;
336         uint64_t len_le:1;
337         uint64_t len_ld:1;
338         uint64_t len_lc:1;
339         uint64_t csum_lf:1;
340         uint64_t csum_le:1;
341         uint64_t csum_ld:1;
342         uint64_t csum_lc:1;
343         uint64_t min_frame_len;
344         uint64_t max_frame_len;
345 } pki_errchk_cfg_t;
346
347
348 /* CACHE MODE*/
349 enum {
350         PKI_OPC_MODE_STT = 0LL,
351         PKI_OPC_MODE_STF = 1LL,
352         PKI_OPC_MODE_STF1_STT = 2LL,
353         PKI_OPC_MODE_STF2_STT = 3LL
354 };
355
356 /* PKI QPG QOS*/
357 enum {
358         PKI_QPG_QOS_NONE = 0,
359         PKI_QPG_QOS_VLAN,
360         PKI_QPG_QOS_MPLS,
361         PKI_QPG_QOS_DSA_SRC,
362         PKI_QPG_QOS_DIFFSERV,
363         PKI_QPG_QOS_HIGIG,
364 };
365
366 struct pki_qos_entry {
367         uint16_t port_add;
368         uint16_t ggrp_ok;
369         uint16_t ggrp_bad;
370         uint16_t gaura;
371         uint8_t grptag_ok;
372         uint8_t grptag_bad;
373         uint8_t ena_red;
374         uint8_t ena_drop;
375 };
376
377 #define PKO_MAX_QOS_ENTRY 64
378
379 /* pki flow/style enable qos */
380 typedef struct pki_port_create_qos {
381         uint8_t port_type;
382         uint8_t qpg_qos;
383         uint8_t num_entry;
384         uint8_t tag_type;
385         uint8_t drop_policy;
386         struct pki_qos_entry qos_entry[PKO_MAX_QOS_ENTRY];
387 } pki_qos_cfg_t;
388
389 /* pki flow/style enable qos */
390 typedef struct pki_port_delete_qos_entry {
391         uint8_t port_type;
392         uint16_t index;
393 } pki_del_qos_t;
394
395 /* pki flow/style enable qos */
396 typedef struct pki_port_modify_qos_entry {
397         uint8_t port_type;
398         uint16_t index;
399         struct {
400                 uint8_t f_port_add:1;
401                 uint8_t f_grp_ok:1;
402                 uint8_t f_grp_bad:1;
403                 uint8_t f_gaura:1;
404                 uint8_t f_grptag_ok:1;
405                 uint8_t f_grptag_bad:1;
406                 uint8_t f_tag_type:1;
407         } mmask;
408         uint8_t tag_type;
409         struct pki_qos_entry qos_entry;
410 } pki_mod_qos_t;
411
412 static inline int
413 octeontx_pki_port_modify_qos(int port, pki_mod_qos_t *qos_cfg)
414 {
415         struct octeontx_mbox_hdr hdr;
416         int res;
417
418         mbox_pki_mod_qos_t q_cfg = *(mbox_pki_mod_qos_t *)qos_cfg;
419         int len = sizeof(mbox_pki_mod_qos_t);
420
421         hdr.coproc = OCTEONTX_PKI_COPROC;
422         hdr.msg = MBOX_PKI_PORT_MODIFY_QOS;
423         hdr.vfid = port;
424
425         res = octeontx_mbox_send(&hdr, &q_cfg, len, NULL, 0);
426         if (res < 0)
427                 return -EACCES;
428
429         return res;
430 }
431
432 static inline int
433 octeontx_pki_port_delete_qos(int port, pki_del_qos_t *qos_cfg)
434 {
435         struct octeontx_mbox_hdr hdr;
436         int res;
437
438         mbox_pki_del_qos_t q_cfg = *(mbox_pki_del_qos_t *)qos_cfg;
439         int len = sizeof(mbox_pki_del_qos_t);
440
441         hdr.coproc = OCTEONTX_PKI_COPROC;
442         hdr.msg = MBOX_PKI_PORT_DELETE_QOS;
443         hdr.vfid = port;
444
445         res = octeontx_mbox_send(&hdr, &q_cfg, len, NULL, 0);
446         if (res < 0)
447                 return -EACCES;
448
449         return res;
450 }
451
452 static inline int
453 octeontx_pki_port_close(int port)
454 {
455         struct octeontx_mbox_hdr hdr;
456         int res;
457
458         mbox_pki_port_t ptype;
459         int len = sizeof(mbox_pki_port_t);
460         memset(&ptype, 0, len);
461         ptype.port_type = OCTTX_PORT_TYPE_NET;
462
463         hdr.coproc = OCTEONTX_PKI_COPROC;
464         hdr.msg = MBOX_PKI_PORT_CLOSE;
465         hdr.vfid = port;
466
467         res = octeontx_mbox_send(&hdr, &ptype, len, NULL, 0);
468         if (res < 0)
469                 return -EACCES;
470
471         return res;
472 }
473
474 static inline int
475 octeontx_pki_port_start(int port)
476 {
477         struct octeontx_mbox_hdr hdr;
478         int res;
479
480         mbox_pki_port_t ptype;
481         int len = sizeof(mbox_pki_port_t);
482         memset(&ptype, 0, len);
483         ptype.port_type = OCTTX_PORT_TYPE_NET;
484
485         hdr.coproc = OCTEONTX_PKI_COPROC;
486         hdr.msg = MBOX_PKI_PORT_START;
487         hdr.vfid = port;
488
489         res = octeontx_mbox_send(&hdr, &ptype, len, NULL, 0);
490         if (res < 0)
491                 return -EACCES;
492
493         return res;
494 }
495
496 static inline int
497 octeontx_pki_port_stop(int port)
498 {
499         struct octeontx_mbox_hdr hdr;
500         int res;
501
502         mbox_pki_port_t ptype;
503         int len = sizeof(mbox_pki_port_t);
504         memset(&ptype, 0, len);
505         ptype.port_type = OCTTX_PORT_TYPE_NET;
506
507         hdr.coproc = OCTEONTX_PKI_COPROC;
508         hdr.msg = MBOX_PKI_PORT_STOP;
509         hdr.vfid = port;
510
511         res = octeontx_mbox_send(&hdr, &ptype, len, NULL, 0);
512         if (res < 0)
513                 return -EACCES;
514
515         return res;
516 }
517
518 int octeontx_pki_port_open(int port);
519 int octeontx_pki_port_hash_config(int port, pki_hash_cfg_t *hash_cfg);
520 int octeontx_pki_port_pktbuf_config(int port, pki_pktbuf_cfg_t *buf_cfg);
521 int octeontx_pki_port_create_qos(int port, pki_qos_cfg_t *qos_cfg);
522 int octeontx_pki_port_close(int port);
523 int octeontx_pki_port_errchk_config(int port, pki_errchk_cfg_t *cfg);
524
525 #endif /* __OCTEONTX_PKI_H__ */