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 /* Interface types: */ 52 enum { 53 OCTTX_PORT_TYPE_NET, /* Network interface ports */ 54 OCTTX_PORT_TYPE_INT, /* CPU internal interface ports */ 55 OCTTX_PORT_TYPE_PCI, /* DPI/PCIe interface ports */ 56 OCTTX_PORT_TYPE_MAX 57 }; 58 59 /* pki port config */ 60 typedef struct mbox_pki_port_type { 61 uint8_t port_type; 62 } mbox_pki_port_t; 63 64 /* pki port config */ 65 typedef struct mbox_pki_port_cfg { 66 uint8_t port_type; 67 struct { 68 uint8_t fcs_pres:1; 69 uint8_t fcs_skip:1; 70 uint8_t inst_skip:1; 71 uint8_t parse_mode:1; 72 uint8_t mpls_parse:1; 73 uint8_t inst_hdr_parse:1; 74 uint8_t fulc_parse:1; 75 uint8_t dsa_parse:1; 76 uint8_t hg2_parse:1; 77 uint8_t hg_parse:1; 78 } mmask; 79 uint8_t fcs_pres; 80 uint8_t fcs_skip; 81 uint8_t inst_skip; 82 uint8_t parse_mode; 83 uint8_t mpls_parse; 84 uint8_t inst_hdr_parse; 85 uint8_t fulc_parse; 86 uint8_t dsa_parse; 87 uint8_t hg2_parse; 88 uint8_t hg_parse; 89 } mbox_pki_prt_cfg_t; 90 91 /* pki Flow/style packet buffer config */ 92 typedef struct mbox_pki_port_pktbuf_cfg { 93 uint8_t port_type; 94 struct { 95 uint16_t f_mbuff_size:1; 96 uint16_t f_wqe_skip:1; 97 uint16_t f_first_skip:1; 98 uint16_t f_later_skip:1; 99 uint16_t f_pkt_outside_wqe:1; 100 uint16_t f_wqe_endian:1; 101 uint16_t f_cache_mode:1; 102 } mmask; 103 uint16_t mbuff_size; 104 uint16_t wqe_skip; 105 uint16_t first_skip; 106 uint16_t later_skip; 107 uint8_t pkt_outside_wqe; 108 uint8_t wqe_endian; 109 uint8_t cache_mode; 110 } mbox_pki_pktbuf_cfg_t; 111 112 /* pki flow/style tag config */ 113 typedef struct mbox_pki_port_hash_cfg { 114 uint8_t port_type; 115 uint32_t tag_slf:1; 116 uint32_t tag_sle:1; 117 uint32_t tag_sld:1; 118 uint32_t tag_slc:1; 119 uint32_t tag_dlf:1; 120 uint32_t tag_dle:1; 121 uint32_t tag_dld:1; 122 uint32_t tag_dlc:1; 123 uint32_t tag_prt:1; 124 uint32_t tag_vlan0:1; 125 uint32_t tag_vlan1:1; 126 uint32_t tag_ip_pctl:1; 127 uint32_t tag_sync:1; 128 uint32_t tag_spi:1; 129 uint32_t tag_gtp:1; 130 uint32_t tag_vni:1; 131 } mbox_pki_hash_cfg_t; 132 133 /* pki flow/style errcheck config */ 134 typedef struct mbox_pki_port_errcheck_cfg { 135 uint8_t port_type; 136 struct { 137 uint32_t f_ip6_udp_opt:1; 138 uint32_t f_lenerr_en:1; 139 uint32_t f_maxerr_en:1; 140 uint32_t f_minerr_en:1; 141 uint32_t f_fcs_chk:1; 142 uint32_t f_fcs_strip:1; 143 uint32_t f_len_lf:1; 144 uint32_t f_len_le:1; 145 uint32_t f_len_ld:1; 146 uint32_t f_len_lc:1; 147 uint32_t f_csum_lf:1; 148 uint32_t f_csum_le:1; 149 uint32_t f_csum_ld:1; 150 uint32_t f_csum_lc:1; 151 uint32_t f_min_frame_len; 152 uint32_t f_max_frame_len; 153 } mmask; 154 uint64_t ip6_udp_opt:1; 155 uint64_t lenerr_en:1; 156 uint64_t maxerr_en:1; 157 uint64_t minerr_en:1; 158 uint64_t fcs_chk:1; 159 uint64_t fcs_strip:1; 160 uint64_t len_lf:1; 161 uint64_t len_le:1; 162 uint64_t len_ld:1; 163 uint64_t len_lc:1; 164 uint64_t csum_lf:1; 165 uint64_t csum_le:1; 166 uint64_t csum_ld:1; 167 uint64_t csum_lc:1; 168 uint64_t min_frame_len; 169 uint64_t max_frame_len; 170 } mbox_pki_errcheck_cfg_t; 171 172 /* CACHE MODE*/ 173 enum { 174 MBOX_PKI_OPC_MODE_STT = 0LL, 175 MBOX_PKI_OPC_MODE_STF = 1LL, 176 MBOX_PKI_OPC_MODE_STF1_STT = 2LL, 177 MBOX_PKI_OPC_MODE_STF2_STT = 3LL 178 }; 179 180 /* PKI QPG QOS*/ 181 enum { 182 MBOX_PKI_QPG_QOS_NONE = 0, 183 MBOX_PKI_QPG_QOS_VLAN, 184 MBOX_PKI_QPG_QOS_MPLS, 185 MBOX_PKI_QPG_QOS_DSA_SRC, 186 MBOX_PKI_QPG_QOS_DIFFSERV, 187 MBOX_PKI_QPG_QOS_HIGIG, 188 }; 189 190 struct mbox_pki_qos_entry { 191 uint16_t port_add; 192 uint16_t ggrp_ok; 193 uint16_t ggrp_bad; 194 uint16_t gaura; 195 uint8_t grptag_ok; 196 uint8_t grptag_bad; 197 uint8_t ena_red; 198 uint8_t ena_drop; 199 uint8_t tag_type; 200 }; 201 202 /* pki flow/style enable qos */ 203 typedef struct mbox_pki_port_create_qos { 204 uint8_t port_type; 205 uint8_t qpg_qos; 206 uint8_t num_entry; 207 uint8_t tag_type; 208 uint8_t drop_policy; 209 struct mbox_pki_qos_entry qos_entry[MBOX_PKI_MAX_QOS_ENTRY]; 210 } mbox_pki_qos_cfg_t; 211 212 /* pki flow/style modify qos */ 213 typedef struct mbox_pki_port_modify_qos_entry { 214 uint8_t port_type; 215 uint16_t index; 216 struct { 217 uint8_t f_port_add:1; 218 uint8_t f_grp_ok:1; 219 uint8_t f_grp_bad:1; 220 uint8_t f_gaura:1; 221 uint8_t f_grptag_ok:1; 222 uint8_t f_grptag_bad:1; 223 uint8_t f_tag_type:1; 224 } mmask; 225 struct mbox_pki_qos_entry qos_entry; 226 } mbox_pki_mod_qos_t; 227 228 /* pki flow/style delete qos */ 229 typedef struct mbox_pki_port_delete_qos_entry { 230 uint8_t port_type; 231 uint16_t index; 232 } mbox_pki_del_qos_t; 233 234 /* PKI maximum constants */ 235 #define PKI_VF_MAX (1) 236 #define PKI_MAX_PKTLEN (32768) 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