xref: /dpdk/drivers/net/ice/base/ice_flg_rd.c (revision 1c9e61b3)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2021 Intel Corporation
3  */
4 
5 #include "ice_common.h"
6 #include "ice_parser_util.h"
7 
8 #define ICE_FLG_RD_TABLE_SIZE 64
9 
10 /**
11  * ice_flg_rd_dump - dump a flag redirect item info
12  * @ice_hw: pointer to the hardware structure
13  * @item: flag redirect item to dump
14  */
ice_flg_rd_dump(struct ice_hw * hw,struct ice_flg_rd_item * item)15 void ice_flg_rd_dump(struct ice_hw *hw, struct ice_flg_rd_item *item)
16 {
17 	ice_info(hw, "index = %d\n", item->idx);
18 	ice_info(hw, "expose = %d\n", item->expose);
19 	ice_info(hw, "intr_flg_id = %d\n", item->intr_flg_id);
20 }
21 
22 /** The function parses a 8 bits Flag Redirect Table entry with below format:
23  *  BIT 0:	Expose (rdi->expose)
24  *  BIT 1-6:	Internal Flag ID (rdi->intr_flg_id)
25  *  BIT 7:	reserved
26  */
_flg_rd_parse_item(struct ice_hw * hw,u16 idx,void * item,void * data,int size)27 static void _flg_rd_parse_item(struct ice_hw *hw, u16 idx, void *item,
28 			       void *data, int size)
29 {
30 	struct ice_flg_rd_item *rdi = (struct ice_flg_rd_item *)item;
31 	u8 d8 = *(u8 *)data;
32 
33 	rdi->idx = idx;
34 	rdi->expose = (d8 & 0x1) != 0;
35 	rdi->intr_flg_id = (u8)((d8 >> 1) & 0x3f);
36 
37 	if (hw->debug_mask & ICE_DBG_PARSER)
38 		ice_flg_rd_dump(hw, rdi);
39 }
40 
41 /**
42  * ice_flg_rd_table_get - create a flag redirect table
43  * @ice_hw: pointer to the hardware structure
44  */
ice_flg_rd_table_get(struct ice_hw * hw)45 struct ice_flg_rd_item *ice_flg_rd_table_get(struct ice_hw *hw)
46 {
47 	return (struct ice_flg_rd_item *)
48 		ice_parser_create_table(hw, ICE_SID_RXPARSER_FLAG_REDIR,
49 					sizeof(struct ice_flg_rd_item),
50 					ICE_FLG_RD_TABLE_SIZE,
51 					ice_parser_sect_item_get,
52 					_flg_rd_parse_item, false);
53 }
54 
55 /**
56  * ice_flg_redirect - redirect a parser flag to packet flag
57  * @table: flag redirect table
58  * @psr_flg: parser flag to redirect
59  */
ice_flg_redirect(struct ice_flg_rd_item * table,u64 psr_flg)60 u64 ice_flg_redirect(struct ice_flg_rd_item *table, u64 psr_flg)
61 {
62 	u64 flg = 0;
63 	int i;
64 
65 	for (i = 0; i < 64; i++) {
66 		struct ice_flg_rd_item *item = &table[i];
67 
68 		if (!item->expose)
69 			continue;
70 
71 		if (psr_flg & (1ul << item->intr_flg_id))
72 			flg |= (1ul << i);
73 	}
74 
75 	return flg;
76 }
77