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