1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (C) 2024 Intel Corporation */ 3 4 #ifndef _ICE_PARSER_H_ 5 #define _ICE_PARSER_H_ 6 7 #define ICE_SEC_DATA_OFFSET 4 8 #define ICE_SID_RXPARSER_IMEM_ENTRY_SIZE 48 9 #define ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE 24 10 #define ICE_SID_RXPARSER_CAM_ENTRY_SIZE 16 11 #define ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE 17 12 #define ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE 12 13 #define ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE 13 14 #define ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE 88 15 #define ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE 24 16 #define ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE 8 17 #define ICE_SID_RXPARSER_PROTO_GRP_ENTRY_SIZE 24 18 #define ICE_SID_RXPARSER_FLAG_REDIR_ENTRY_SIZE 1 19 20 #define ICE_SEC_LBL_DATA_OFFSET 2 21 #define ICE_SID_LBL_ENTRY_SIZE 66 22 23 /*** ICE_SID_RXPARSER_IMEM section ***/ 24 #define ICE_IMEM_TABLE_SIZE 192 25 26 /* TCAM boost Master; if bit is set, and TCAM hit, TCAM output overrides iMEM 27 * output. 28 */ 29 struct ice_bst_main { 30 bool alu0; 31 bool alu1; 32 bool alu2; 33 bool pg; 34 }; 35 36 struct ice_bst_keybuilder { 37 u8 prio; /* 0-3: PG precedence within ALUs (3 highest) */ 38 bool tsr_ctrl; /* TCAM Search Register control */ 39 }; 40 41 /* Next protocol Key builder */ 42 struct ice_np_keybuilder { 43 u8 opc; 44 u8 start_reg0; 45 u8 len_reg1; 46 }; 47 48 enum ice_np_keybuilder_opcode { 49 ICE_NPKB_OPC_EXTRACT = 0, 50 ICE_NPKB_OPC_BUILD = 1, 51 ICE_NPKB_OPC_BYPASS = 2, 52 }; 53 54 /* Parse Graph Key builder */ 55 struct ice_pg_keybuilder { 56 bool flag0_ena; 57 bool flag1_ena; 58 bool flag2_ena; 59 bool flag3_ena; 60 u8 flag0_idx; 61 u8 flag1_idx; 62 u8 flag2_idx; 63 u8 flag3_idx; 64 u8 alu_reg_idx; 65 }; 66 67 enum ice_alu_idx { 68 ICE_ALU0_IDX = 0, 69 ICE_ALU1_IDX = 1, 70 ICE_ALU2_IDX = 2, 71 }; 72 73 enum ice_alu_opcode { 74 ICE_ALU_PARK = 0, 75 ICE_ALU_MOV_ADD = 1, 76 ICE_ALU_ADD = 2, 77 ICE_ALU_MOV_AND = 4, 78 ICE_ALU_AND = 5, 79 ICE_ALU_AND_IMM = 6, 80 ICE_ALU_MOV_OR = 7, 81 ICE_ALU_OR = 8, 82 ICE_ALU_MOV_XOR = 9, 83 ICE_ALU_XOR = 10, 84 ICE_ALU_NOP = 11, 85 ICE_ALU_BR = 12, 86 ICE_ALU_BREQ = 13, 87 ICE_ALU_BRNEQ = 14, 88 ICE_ALU_BRGT = 15, 89 ICE_ALU_BRLT = 16, 90 ICE_ALU_BRGEQ = 17, 91 ICE_ALU_BRLEG = 18, 92 ICE_ALU_SETEQ = 19, 93 ICE_ALU_ANDEQ = 20, 94 ICE_ALU_OREQ = 21, 95 ICE_ALU_SETNEQ = 22, 96 ICE_ALU_ANDNEQ = 23, 97 ICE_ALU_ORNEQ = 24, 98 ICE_ALU_SETGT = 25, 99 ICE_ALU_ANDGT = 26, 100 ICE_ALU_ORGT = 27, 101 ICE_ALU_SETLT = 28, 102 ICE_ALU_ANDLT = 29, 103 ICE_ALU_ORLT = 30, 104 ICE_ALU_MOV_SUB = 31, 105 ICE_ALU_SUB = 32, 106 ICE_ALU_INVALID = 64, 107 }; 108 109 enum ice_proto_off_opcode { 110 ICE_PO_OFF_REMAIN = 0, 111 ICE_PO_OFF_HDR_ADD = 1, 112 ICE_PO_OFF_HDR_SUB = 2, 113 }; 114 115 struct ice_alu { 116 enum ice_alu_opcode opc; 117 u8 src_start; 118 u8 src_len; 119 bool shift_xlate_sel; 120 u8 shift_xlate_key; 121 u8 src_reg_id; 122 u8 dst_reg_id; 123 bool inc0; 124 bool inc1; 125 u8 proto_offset_opc; 126 u8 proto_offset; 127 u8 branch_addr; 128 u16 imm; 129 bool dedicate_flags_ena; 130 u8 dst_start; 131 u8 dst_len; 132 bool flags_extr_imm; 133 u8 flags_start_imm; 134 }; 135 136 /* Parser program code (iMEM) */ 137 struct ice_imem_item { 138 u16 idx; 139 struct ice_bst_main b_m; 140 struct ice_bst_keybuilder b_kb; 141 u8 pg_prio; 142 struct ice_np_keybuilder np_kb; 143 struct ice_pg_keybuilder pg_kb; 144 struct ice_alu alu0; 145 struct ice_alu alu1; 146 struct ice_alu alu2; 147 }; 148 149 /*** ICE_SID_RXPARSER_METADATA_INIT section ***/ 150 #define ICE_METAINIT_TABLE_SIZE 16 151 152 /* Metadata Initialization item */ 153 struct ice_metainit_item { 154 u16 idx; 155 156 u8 tsr; /* TCAM Search key Register */ 157 u16 ho; /* Header Offset register */ 158 u16 pc; /* Program Counter register */ 159 u16 pg_rn; /* Parse Graph Root Node */ 160 u8 cd; /* Control Domain ID */ 161 162 /* General Purpose Registers */ 163 bool gpr_a_ctrl; 164 u8 gpr_a_data_mdid; 165 u8 gpr_a_data_start; 166 u8 gpr_a_data_len; 167 u8 gpr_a_id; 168 169 bool gpr_b_ctrl; 170 u8 gpr_b_data_mdid; 171 u8 gpr_b_data_start; 172 u8 gpr_b_data_len; 173 u8 gpr_b_id; 174 175 bool gpr_c_ctrl; 176 u8 gpr_c_data_mdid; 177 u8 gpr_c_data_start; 178 u8 gpr_c_data_len; 179 u8 gpr_c_id; 180 181 bool gpr_d_ctrl; 182 u8 gpr_d_data_mdid; 183 u8 gpr_d_data_start; 184 u8 gpr_d_data_len; 185 u8 gpr_d_id; 186 187 u64 flags; /* Initial value for all flags */ 188 }; 189 190 /*** ICE_SID_RXPARSER_CAM, ICE_SID_RXPARSER_PG_SPILL, 191 * ICE_SID_RXPARSER_NOMATCH_CAM and ICE_SID_RXPARSER_NOMATCH_CAM 192 * sections ***/ 193 #define ICE_PG_CAM_TABLE_SIZE 2048 194 #define ICE_PG_SP_CAM_TABLE_SIZE 128 195 #define ICE_PG_NM_CAM_TABLE_SIZE 1024 196 #define ICE_PG_NM_SP_CAM_TABLE_SIZE 64 197 198 struct ice_pg_cam_key { 199 bool valid; 200 struct_group_attr(val, __packed, 201 u16 node_id; /* Node ID of protocol in parse graph */ 202 bool flag0; 203 bool flag1; 204 bool flag2; 205 bool flag3; 206 u8 boost_idx; /* Boost TCAM match index */ 207 u16 alu_reg; 208 u32 next_proto; /* next Protocol value (must be last) */ 209 ); 210 }; 211 212 struct ice_pg_nm_cam_key { 213 bool valid; 214 struct_group_attr(val, __packed, 215 u16 node_id; 216 bool flag0; 217 bool flag1; 218 bool flag2; 219 bool flag3; 220 u8 boost_idx; 221 u16 alu_reg; 222 ); 223 }; 224 225 struct ice_pg_cam_action { 226 u16 next_node; /* Parser Node ID for the next round */ 227 u8 next_pc; /* next Program Counter */ 228 bool is_pg; /* is protocol group */ 229 u8 proto_id; /* protocol ID or proto group ID */ 230 bool is_mg; /* is marker group */ 231 u8 marker_id; /* marker ID or marker group ID */ 232 bool is_last_round; 233 bool ho_polarity; /* header offset polarity */ 234 u16 ho_inc; 235 }; 236 237 /* Parse Graph item */ 238 struct ice_pg_cam_item { 239 u16 idx; 240 struct ice_pg_cam_key key; 241 struct ice_pg_cam_action action; 242 }; 243 244 /* Parse Graph No Match item */ 245 struct ice_pg_nm_cam_item { 246 u16 idx; 247 struct ice_pg_nm_cam_key key; 248 struct ice_pg_cam_action action; 249 }; 250 251 struct ice_pg_cam_item *ice_pg_cam_match(struct ice_pg_cam_item *table, 252 int size, struct ice_pg_cam_key *key); 253 struct ice_pg_nm_cam_item * 254 ice_pg_nm_cam_match(struct ice_pg_nm_cam_item *table, int size, 255 struct ice_pg_cam_key *key); 256 257 /*** ICE_SID_RXPARSER_BOOST_TCAM and ICE_SID_LBL_RXPARSER_TMEM sections ***/ 258 #define ICE_BST_TCAM_TABLE_SIZE 256 259 #define ICE_BST_TCAM_KEY_SIZE 20 260 #define ICE_BST_KEY_TCAM_SIZE 19 261 262 /* Boost TCAM item */ 263 struct ice_bst_tcam_item { 264 u16 addr; 265 u8 key[ICE_BST_TCAM_KEY_SIZE]; 266 u8 key_inv[ICE_BST_TCAM_KEY_SIZE]; 267 u8 hit_idx_grp; 268 u8 pg_prio; 269 struct ice_np_keybuilder np_kb; 270 struct ice_pg_keybuilder pg_kb; 271 struct ice_alu alu0; 272 struct ice_alu alu1; 273 struct ice_alu alu2; 274 }; 275 276 #define ICE_LBL_LEN 64 277 #define ICE_LBL_BST_DVM "BOOST_MAC_VLAN_DVM" 278 #define ICE_LBL_BST_SVM "BOOST_MAC_VLAN_SVM" 279 #define ICE_LBL_TNL_VXLAN "TNL_VXLAN" 280 #define ICE_LBL_TNL_GENEVE "TNL_GENEVE" 281 #define ICE_LBL_TNL_UDP_ECPRI "TNL_UDP_ECPRI" 282 283 enum ice_lbl_type { 284 ICE_LBL_BST_TYPE_UNKNOWN, 285 ICE_LBL_BST_TYPE_DVM, 286 ICE_LBL_BST_TYPE_SVM, 287 ICE_LBL_BST_TYPE_VXLAN, 288 ICE_LBL_BST_TYPE_GENEVE, 289 ICE_LBL_BST_TYPE_UDP_ECPRI, 290 }; 291 292 struct ice_lbl_item { 293 u16 idx; 294 char label[ICE_LBL_LEN]; 295 296 /* must be at the end, not part of the DDP section */ 297 enum ice_lbl_type type; 298 }; 299 300 struct ice_bst_tcam_item * 301 ice_bst_tcam_match(struct ice_bst_tcam_item *tcam_table, u8 *pat); 302 struct ice_bst_tcam_item * 303 ice_bst_tcam_search(struct ice_bst_tcam_item *tcam_table, 304 struct ice_lbl_item *lbl_table, 305 enum ice_lbl_type type, u16 *start); 306 307 /*** ICE_SID_RXPARSER_MARKER_PTYPE section ***/ 308 #define ICE_PTYPE_MK_TCAM_TABLE_SIZE 1024 309 #define ICE_PTYPE_MK_TCAM_KEY_SIZE 10 310 311 struct ice_ptype_mk_tcam_item { 312 u16 address; 313 u16 ptype; 314 u8 key[ICE_PTYPE_MK_TCAM_KEY_SIZE]; 315 u8 key_inv[ICE_PTYPE_MK_TCAM_KEY_SIZE]; 316 } __packed; 317 318 struct ice_ptype_mk_tcam_item * 319 ice_ptype_mk_tcam_match(struct ice_ptype_mk_tcam_item *table, 320 u8 *pat, int len); 321 /*** ICE_SID_RXPARSER_MARKER_GRP section ***/ 322 #define ICE_MK_GRP_TABLE_SIZE 128 323 #define ICE_MK_COUNT_PER_GRP 8 324 325 /* Marker Group item */ 326 struct ice_mk_grp_item { 327 int idx; 328 u8 markers[ICE_MK_COUNT_PER_GRP]; 329 }; 330 331 /*** ICE_SID_RXPARSER_PROTO_GRP section ***/ 332 #define ICE_PROTO_COUNT_PER_GRP 8 333 #define ICE_PROTO_GRP_TABLE_SIZE 192 334 #define ICE_PROTO_GRP_ITEM_SIZE 22 335 struct ice_proto_off { 336 bool polarity; /* true: positive, false: negative */ 337 u8 proto_id; 338 u16 offset; /* 10 bit protocol offset */ 339 }; 340 341 /* Protocol Group item */ 342 struct ice_proto_grp_item { 343 u16 idx; 344 struct ice_proto_off po[ICE_PROTO_COUNT_PER_GRP]; 345 }; 346 347 /*** ICE_SID_RXPARSER_FLAG_REDIR section ***/ 348 #define ICE_FLG_RD_TABLE_SIZE 64 349 #define ICE_FLG_RDT_SIZE 64 350 351 /* Flags Redirection item */ 352 struct ice_flg_rd_item { 353 u16 idx; 354 bool expose; 355 u8 intr_flg_id; /* Internal Flag ID */ 356 }; 357 358 u64 ice_flg_redirect(struct ice_flg_rd_item *table, u64 psr_flg); 359 360 /*** ICE_SID_XLT_KEY_BUILDER_SW, ICE_SID_XLT_KEY_BUILDER_ACL, 361 * ICE_SID_XLT_KEY_BUILDER_FD and ICE_SID_XLT_KEY_BUILDER_RSS 362 * sections ***/ 363 #define ICE_XLT_KB_FLAG0_14_CNT 15 364 #define ICE_XLT_KB_TBL_CNT 8 365 #define ICE_XLT_KB_TBL_ENTRY_SIZE 24 366 367 struct ice_xlt_kb_entry { 368 u8 xlt1_ad_sel; 369 u8 xlt2_ad_sel; 370 u16 flg0_14_sel[ICE_XLT_KB_FLAG0_14_CNT]; 371 u8 xlt1_md_sel; 372 u8 xlt2_md_sel; 373 }; 374 375 /* XLT Key Builder */ 376 struct ice_xlt_kb { 377 u8 xlt1_pm; /* XLT1 Partition Mode */ 378 u8 xlt2_pm; /* XLT2 Partition Mode */ 379 u8 prof_id_pm; /* Profile ID Partition Mode */ 380 u64 flag15; 381 382 struct ice_xlt_kb_entry entries[ICE_XLT_KB_TBL_CNT]; 383 }; 384 385 u16 ice_xlt_kb_flag_get(struct ice_xlt_kb *kb, u64 pkt_flag); 386 387 /*** Parser API ***/ 388 #define ICE_GPR_HV_IDX 64 389 #define ICE_GPR_HV_SIZE 32 390 #define ICE_GPR_ERR_IDX 84 391 #define ICE_GPR_FLG_IDX 104 392 #define ICE_GPR_FLG_SIZE 16 393 394 #define ICE_GPR_TSR_IDX 108 /* TSR: TCAM Search Register */ 395 #define ICE_GPR_NN_IDX 109 /* NN: Next Parsing Cycle Node ID */ 396 #define ICE_GPR_HO_IDX 110 /* HO: Next Parsing Cycle hdr Offset */ 397 #define ICE_GPR_NP_IDX 111 /* NP: Next Parsing Cycle */ 398 399 #define ICE_PARSER_MAX_PKT_LEN 504 400 #define ICE_PARSER_PKT_REV 32 401 #define ICE_PARSER_GPR_NUM 128 402 #define ICE_PARSER_FLG_NUM 64 403 #define ICE_PARSER_ERR_NUM 16 404 #define ICE_BST_KEY_SIZE 10 405 #define ICE_MARKER_ID_SIZE 9 406 #define ICE_MARKER_MAX_SIZE \ 407 (ICE_MARKER_ID_SIZE * BITS_PER_BYTE - 1) 408 #define ICE_MARKER_ID_NUM 8 409 #define ICE_PO_PAIR_SIZE 256 410 411 struct ice_gpr_pu { 412 /* array of flags to indicate if GRP needs to be updated */ 413 bool gpr_val_upd[ICE_PARSER_GPR_NUM]; 414 u16 gpr_val[ICE_PARSER_GPR_NUM]; 415 u64 flg_msk; 416 u64 flg_val; 417 u16 err_msk; 418 u16 err_val; 419 }; 420 421 enum ice_pg_prio { 422 ICE_PG_P0 = 0, 423 ICE_PG_P1 = 1, 424 ICE_PG_P2 = 2, 425 ICE_PG_P3 = 3, 426 }; 427 428 struct ice_parser_rt { 429 struct ice_parser *psr; 430 u16 gpr[ICE_PARSER_GPR_NUM]; 431 u8 pkt_buf[ICE_PARSER_MAX_PKT_LEN + ICE_PARSER_PKT_REV]; 432 u16 pkt_len; 433 u16 po; 434 u8 bst_key[ICE_BST_KEY_SIZE]; 435 struct ice_pg_cam_key pg_key; 436 struct ice_alu *alu0; 437 struct ice_alu *alu1; 438 struct ice_alu *alu2; 439 struct ice_pg_cam_action *action; 440 u8 pg_prio; 441 struct ice_gpr_pu pu; 442 u8 markers[ICE_MARKER_ID_SIZE]; 443 bool protocols[ICE_PO_PAIR_SIZE]; 444 u16 offsets[ICE_PO_PAIR_SIZE]; 445 }; 446 447 struct ice_parser_proto_off { 448 u8 proto_id; /* hardware protocol ID */ 449 u16 offset; /* offset from the start of the protocol header */ 450 }; 451 452 #define ICE_PARSER_PROTO_OFF_PAIR_SIZE 16 453 #define ICE_PARSER_FLAG_PSR_SIZE 8 454 #define ICE_PARSER_FV_SIZE 48 455 #define ICE_PARSER_FV_MAX 24 456 #define ICE_BT_TUN_PORT_OFF_H 16 457 #define ICE_BT_TUN_PORT_OFF_L 15 458 #define ICE_BT_VM_OFF 0 459 #define ICE_UDP_PORT_OFF_H 1 460 #define ICE_UDP_PORT_OFF_L 0 461 462 struct ice_parser_result { 463 u16 ptype; /* 16 bits hardware PTYPE */ 464 /* array of protocol and header offset pairs */ 465 struct ice_parser_proto_off po[ICE_PARSER_PROTO_OFF_PAIR_SIZE]; 466 int po_num; /* # of protocol-offset pairs must <= 16 */ 467 u64 flags_psr; /* parser flags */ 468 u64 flags_pkt; /* packet flags */ 469 u16 flags_sw; /* key builder flags for SW */ 470 u16 flags_acl; /* key builder flags for ACL */ 471 u16 flags_fd; /* key builder flags for FD */ 472 u16 flags_rss; /* key builder flags for RSS */ 473 }; 474 475 void ice_parser_rt_reset(struct ice_parser_rt *rt); 476 void ice_parser_rt_pktbuf_set(struct ice_parser_rt *rt, const u8 *pkt_buf, 477 int pkt_len); 478 int ice_parser_rt_execute(struct ice_parser_rt *rt, 479 struct ice_parser_result *rslt); 480 481 struct ice_parser { 482 struct ice_hw *hw; /* pointer to the hardware structure */ 483 484 struct ice_imem_item *imem_table; 485 struct ice_metainit_item *mi_table; 486 487 struct ice_pg_cam_item *pg_cam_table; 488 struct ice_pg_cam_item *pg_sp_cam_table; 489 struct ice_pg_nm_cam_item *pg_nm_cam_table; 490 struct ice_pg_nm_cam_item *pg_nm_sp_cam_table; 491 492 struct ice_bst_tcam_item *bst_tcam_table; 493 struct ice_lbl_item *bst_lbl_table; 494 struct ice_ptype_mk_tcam_item *ptype_mk_tcam_table; 495 struct ice_mk_grp_item *mk_grp_table; 496 struct ice_proto_grp_item *proto_grp_table; 497 struct ice_flg_rd_item *flg_rd_table; 498 499 struct ice_xlt_kb *xlt_kb_sw; 500 struct ice_xlt_kb *xlt_kb_acl; 501 struct ice_xlt_kb *xlt_kb_fd; 502 struct ice_xlt_kb *xlt_kb_rss; 503 504 struct ice_parser_rt rt; 505 }; 506 507 struct ice_parser *ice_parser_create(struct ice_hw *hw); 508 void ice_parser_destroy(struct ice_parser *psr); 509 void ice_parser_dvm_set(struct ice_parser *psr, bool on); 510 int ice_parser_vxlan_tunnel_set(struct ice_parser *psr, u16 udp_port, bool on); 511 int ice_parser_geneve_tunnel_set(struct ice_parser *psr, u16 udp_port, bool on); 512 int ice_parser_ecpri_tunnel_set(struct ice_parser *psr, u16 udp_port, bool on); 513 int ice_parser_run(struct ice_parser *psr, const u8 *pkt_buf, 514 int pkt_len, struct ice_parser_result *rslt); 515 void ice_parser_result_dump(struct ice_hw *hw, struct ice_parser_result *rslt); 516 517 struct ice_parser_fv { 518 u8 proto_id; /* hardware protocol ID */ 519 u16 offset; /* offset from the start of the protocol header */ 520 u16 spec; /* pattern to match */ 521 u16 msk; /* pattern mask */ 522 }; 523 524 struct ice_parser_profile { 525 /* array of field vectors */ 526 struct ice_parser_fv fv[ICE_PARSER_FV_SIZE]; 527 int fv_num; /* # of field vectors must <= 48 */ 528 u16 flags; /* key builder flags */ 529 u16 flags_msk; /* key builder flag mask */ 530 531 DECLARE_BITMAP(ptypes, ICE_FLOW_PTYPE_MAX); /* PTYPE bitmap */ 532 }; 533 534 int ice_parser_profile_init(struct ice_parser_result *rslt, 535 const u8 *pkt_buf, const u8 *msk_buf, 536 int buf_len, enum ice_block blk, 537 struct ice_parser_profile *prof); 538 void ice_parser_profile_dump(struct ice_hw *hw, 539 struct ice_parser_profile *prof); 540 #endif /* _ICE_PARSER_H_ */ 541