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