1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2024 Intel Corporation */
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
20 #define ICE_SEC_LBL_DATA_OFFSET 2
21 #define ICE_SID_LBL_ENTRY_SIZE 66
23 /*** ICE_SID_RXPARSER_IMEM section ***/
24 #define ICE_IMEM_TABLE_SIZE 192
26 /* TCAM boost Master; if bit is set, and TCAM hit, TCAM output overrides iMEM
36 struct ice_bst_keybuilder {
37 u8 prio; /* 0-3: PG precedence within ALUs (3 highest) */
38 bool tsr_ctrl; /* TCAM Search Register control */
41 /* Next protocol Key builder */
42 struct ice_np_keybuilder {
48 enum ice_np_keybuilder_opcode {
49 ICE_NPKB_OPC_EXTRACT = 0,
50 ICE_NPKB_OPC_BUILD = 1,
51 ICE_NPKB_OPC_BYPASS = 2,
54 /* Parse Graph Key builder */
55 struct ice_pg_keybuilder {
104 ICE_ALU_MOV_SUB = 31,
106 ICE_ALU_INVALID = 64,
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,
116 enum ice_alu_opcode opc;
119 bool shift_xlate_sel;
129 bool dedicate_flags_ena;
136 /* Parser program code (iMEM) */
137 struct ice_imem_item {
139 struct ice_bst_main b_m;
140 struct ice_bst_keybuilder b_kb;
142 struct ice_np_keybuilder np_kb;
143 struct ice_pg_keybuilder pg_kb;
149 /*** ICE_SID_RXPARSER_METADATA_INIT section ***/
150 #define ICE_METAINIT_TABLE_SIZE 16
152 /* Metadata Initialization item */
153 struct ice_metainit_item {
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 */
162 /* General Purpose Registers */
187 u64 flags; /* Initial value for all flags */
190 /*** ICE_SID_RXPARSER_CAM, ICE_SID_RXPARSER_PG_SPILL,
191 * ICE_SID_RXPARSER_NOMATCH_CAM and ICE_SID_RXPARSER_NOMATCH_CAM
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
198 struct ice_pg_cam_key {
200 struct_group_attr(val, __packed,
201 u16 node_id; /* Node ID of protocol in parse graph */
206 u8 boost_idx; /* Boost TCAM match index */
208 u32 next_proto; /* next Protocol value (must be last) */
212 struct ice_pg_nm_cam_key {
214 struct_group_attr(val, __packed,
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 */
233 bool ho_polarity; /* header offset polarity */
237 /* Parse Graph item */
238 struct ice_pg_cam_item {
240 struct ice_pg_cam_key key;
241 struct ice_pg_cam_action action;
244 /* Parse Graph No Match item */
245 struct ice_pg_nm_cam_item {
247 struct ice_pg_nm_cam_key key;
248 struct ice_pg_cam_action action;
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);
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
262 /* Boost TCAM item */
263 struct ice_bst_tcam_item {
265 u8 key[ICE_BST_TCAM_KEY_SIZE];
266 u8 key_inv[ICE_BST_TCAM_KEY_SIZE];
269 struct ice_np_keybuilder np_kb;
270 struct ice_pg_keybuilder pg_kb;
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"
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,
292 struct ice_lbl_item {
294 char label[ICE_LBL_LEN];
296 /* must be at the end, not part of the DDP section */
297 enum ice_lbl_type type;
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);
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
311 struct ice_ptype_mk_tcam_item {
314 u8 key[ICE_PTYPE_MK_TCAM_KEY_SIZE];
315 u8 key_inv[ICE_PTYPE_MK_TCAM_KEY_SIZE];
318 struct ice_ptype_mk_tcam_item *
319 ice_ptype_mk_tcam_match(struct ice_ptype_mk_tcam_item *table,
321 /*** ICE_SID_RXPARSER_MARKER_GRP section ***/
322 #define ICE_MK_GRP_TABLE_SIZE 128
323 #define ICE_MK_COUNT_PER_GRP 8
325 /* Marker Group item */
326 struct ice_mk_grp_item {
328 u8 markers[ICE_MK_COUNT_PER_GRP];
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 */
338 u16 offset; /* 10 bit protocol offset */
341 /* Protocol Group item */
342 struct ice_proto_grp_item {
344 struct ice_proto_off po[ICE_PROTO_COUNT_PER_GRP];
347 /*** ICE_SID_RXPARSER_FLAG_REDIR section ***/
348 #define ICE_FLG_RD_TABLE_SIZE 64
349 #define ICE_FLG_RDT_SIZE 64
351 /* Flags Redirection item */
352 struct ice_flg_rd_item {
355 u8 intr_flg_id; /* Internal Flag ID */
358 u64 ice_flg_redirect(struct ice_flg_rd_item *table, u64 psr_flg);
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
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
367 struct ice_xlt_kb_entry {
370 u16 flg0_14_sel[ICE_XLT_KB_FLAG0_14_CNT];
375 /* XLT Key Builder */
377 u8 xlt1_pm; /* XLT1 Partition Mode */
378 u8 xlt2_pm; /* XLT2 Partition Mode */
379 u8 prof_id_pm; /* Profile ID Partition Mode */
382 struct ice_xlt_kb_entry entries[ICE_XLT_KB_TBL_CNT];
385 u16 ice_xlt_kb_flag_get(struct ice_xlt_kb *kb, u64 pkt_flag);
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
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 */
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
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];
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];
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;
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];
447 struct ice_parser_proto_off {
448 u8 proto_id; /* hardware protocol ID */
449 u16 offset; /* offset from the start of the protocol header */
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
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 */
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,
478 int ice_parser_rt_execute(struct ice_parser_rt *rt,
479 struct ice_parser_result *rslt);
482 struct ice_hw *hw; /* pointer to the hardware structure */
484 struct ice_imem_item *imem_table;
485 struct ice_metainit_item *mi_table;
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;
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;
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;
504 struct ice_parser_rt rt;
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);
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 */
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 */
531 DECLARE_BITMAP(ptypes, ICE_FLOW_PTYPE_MAX); /* PTYPE bitmap */
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_ */