1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2021 Intel Corporation
5 #include "ice_common.h"
6 #include "ice_parser_util.h"
8 #define ICE_SEC_DATA_OFFSET 4
9 #define ICE_SID_RXPARSER_IMEM_ENTRY_SIZE 48
10 #define ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE 24
11 #define ICE_SID_RXPARSER_CAM_ENTRY_SIZE 16
12 #define ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE 17
13 #define ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE 12
14 #define ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE 13
15 #define ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE 88
16 #define ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE 24
18 #define ICE_SEC_LBL_DATA_OFFSET 2
19 #define ICE_SID_LBL_ENTRY_SIZE 66
21 void ice_lbl_dump(struct ice_hw *hw, struct ice_lbl_item *item)
23 ice_info(hw, "index = %d\n", item->idx);
24 ice_info(hw, "label = %s\n", item->label);
27 void ice_parse_item_dflt(struct ice_hw *hw, u16 idx, void *item,
30 ice_memcpy(item, data, size, ICE_DMA_TO_NONDMA);
34 * ice_parser_sect_item_get - parse a item from a section
35 * @sect_type: section type
36 * @section: section object
37 * @index: index of the item to get
38 * @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
40 void *ice_parser_sect_item_get(u32 sect_type, void *section,
41 u32 index, u32 *offset)
43 struct ice_pkg_sect_hdr *hdr;
44 int data_off = ICE_SEC_DATA_OFFSET;
51 case ICE_SID_RXPARSER_IMEM:
52 size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
54 case ICE_SID_RXPARSER_METADATA_INIT:
55 size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
57 case ICE_SID_RXPARSER_CAM:
58 size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
60 case ICE_SID_RXPARSER_PG_SPILL:
61 size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
63 case ICE_SID_RXPARSER_NOMATCH_CAM:
64 size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
66 case ICE_SID_RXPARSER_NOMATCH_SPILL:
67 size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
69 case ICE_SID_RXPARSER_BOOST_TCAM:
70 size = ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE;
72 case ICE_SID_LBL_RXPARSER_TMEM:
73 data_off = ICE_SEC_LBL_DATA_OFFSET;
74 size = ICE_SID_LBL_ENTRY_SIZE;
76 case ICE_SID_RXPARSER_MARKER_PTYPE:
77 size = ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE;
83 hdr = (struct ice_pkg_sect_hdr *)section;
84 if (index >= LE16_TO_CPU(hdr->count))
87 return (void *)((uintptr_t)section + data_off + index * size);
91 * ice_parser_create_table - create a item table from a section
92 * @hw: pointer to the hardware structure
93 * @sect_type: section type
94 * @item_size: item size in byte
95 * @length: number of items in the table to create
96 * @item_get: the function will be parsed to ice_pkg_enum_entry
97 * @parser_item: the function to parse the item
98 * @no_offset: ignore header offset, calculate index from 0
100 void *ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
101 u32 item_size, u32 length,
102 void *(*item_get)(u32 sect_type, void *section,
103 u32 index, u32 *offset),
104 void (*parse_item)(struct ice_hw *hw, u16 idx,
105 void *item, void *data,
109 struct ice_seg *seg = hw->seg;
110 struct ice_pkg_enum state;
118 table = ice_malloc(hw, item_size * length);
120 ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for table type %d.\n",
125 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
127 data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
131 struct ice_pkg_sect_hdr *hdr =
132 (struct ice_pkg_sect_hdr *)state.sect;
137 idx = hdr->offset + state.entry_idx;
139 (void *)((uintptr_t)table + idx * item_size),
148 * ice_parser_create - create a parser instance
149 * @hw: pointer to the hardware structure
150 * @psr: output parameter for a new parser instance be created
152 enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr)
154 enum ice_status status;
155 struct ice_parser *p;
157 p = (struct ice_parser *)ice_malloc(hw, sizeof(struct ice_parser));
160 return ICE_ERR_NO_MEMORY;
164 p->imem_table = ice_imem_table_get(hw);
165 if (!p->imem_table) {
166 status = ICE_ERR_PARAM;
170 p->mi_table = ice_metainit_table_get(hw);
172 status = ICE_ERR_PARAM;
176 p->pg_cam_table = ice_pg_cam_table_get(hw);
177 if (!p->pg_cam_table) {
178 status = ICE_ERR_PARAM;
182 p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
183 if (!p->pg_sp_cam_table) {
184 status = ICE_ERR_PARAM;
188 p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
189 if (!p->pg_nm_cam_table) {
190 status = ICE_ERR_PARAM;
194 p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
195 if (!p->pg_nm_sp_cam_table) {
196 status = ICE_ERR_PARAM;
200 p->bst_tcam_table = ice_bst_tcam_table_get(hw);
201 if (!p->bst_tcam_table) {
202 status = ICE_ERR_PARAM;
206 p->bst_lbl_table = ice_bst_lbl_table_get(hw);
207 if (!p->bst_lbl_table) {
208 status = ICE_ERR_PARAM;
212 p->ptype_mk_tcam_table = ice_ptype_mk_tcam_table_get(hw);
213 if (!p->ptype_mk_tcam_table) {
214 status = ICE_ERR_PARAM;
221 ice_parser_destroy(p);
226 * ice_parser_destroy - destroy a parser instance
227 * @psr: pointer to a parser instance
229 void ice_parser_destroy(struct ice_parser *psr)
231 ice_free(psr->hw, psr->imem_table);
232 ice_free(psr->hw, psr->mi_table);
233 ice_free(psr->hw, psr->pg_cam_table);
234 ice_free(psr->hw, psr->pg_sp_cam_table);
235 ice_free(psr->hw, psr->pg_nm_cam_table);
236 ice_free(psr->hw, psr->pg_nm_sp_cam_table);
237 ice_free(psr->hw, psr->bst_tcam_table);
238 ice_free(psr->hw, psr->bst_lbl_table);
239 ice_free(psr->hw, psr->ptype_mk_tcam_table);
241 ice_free(psr->hw, psr);