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
17 #define ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE 8
19 #define ICE_SEC_LBL_DATA_OFFSET 2
20 #define ICE_SID_LBL_ENTRY_SIZE 66
22 void ice_lbl_dump(struct ice_hw *hw, struct ice_lbl_item *item)
24 ice_info(hw, "index = %d\n", item->idx);
25 ice_info(hw, "label = %s\n", item->label);
28 void ice_parse_item_dflt(struct ice_hw *hw, u16 idx, void *item,
31 ice_memcpy(item, data, size, ICE_DMA_TO_NONDMA);
35 * ice_parser_sect_item_get - parse a item from a section
36 * @sect_type: section type
37 * @section: section object
38 * @index: index of the item to get
39 * @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
41 void *ice_parser_sect_item_get(u32 sect_type, void *section,
42 u32 index, u32 *offset)
44 struct ice_pkg_sect_hdr *hdr;
45 int data_off = ICE_SEC_DATA_OFFSET;
52 case ICE_SID_RXPARSER_IMEM:
53 size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
55 case ICE_SID_RXPARSER_METADATA_INIT:
56 size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
58 case ICE_SID_RXPARSER_CAM:
59 size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
61 case ICE_SID_RXPARSER_PG_SPILL:
62 size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
64 case ICE_SID_RXPARSER_NOMATCH_CAM:
65 size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
67 case ICE_SID_RXPARSER_NOMATCH_SPILL:
68 size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
70 case ICE_SID_RXPARSER_BOOST_TCAM:
71 size = ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE;
73 case ICE_SID_LBL_RXPARSER_TMEM:
74 data_off = ICE_SEC_LBL_DATA_OFFSET;
75 size = ICE_SID_LBL_ENTRY_SIZE;
77 case ICE_SID_RXPARSER_MARKER_PTYPE:
78 size = ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE;
80 case ICE_SID_RXPARSER_MARKER_GRP:
81 size = ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE;
87 hdr = (struct ice_pkg_sect_hdr *)section;
88 if (index >= LE16_TO_CPU(hdr->count))
91 return (void *)((uintptr_t)section + data_off + index * size);
95 * ice_parser_create_table - create a item table from a section
96 * @hw: pointer to the hardware structure
97 * @sect_type: section type
98 * @item_size: item size in byte
99 * @length: number of items in the table to create
100 * @item_get: the function will be parsed to ice_pkg_enum_entry
101 * @parser_item: the function to parse the item
102 * @no_offset: ignore header offset, calculate index from 0
104 void *ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
105 u32 item_size, u32 length,
106 void *(*item_get)(u32 sect_type, void *section,
107 u32 index, u32 *offset),
108 void (*parse_item)(struct ice_hw *hw, u16 idx,
109 void *item, void *data,
113 struct ice_seg *seg = hw->seg;
114 struct ice_pkg_enum state;
122 table = ice_malloc(hw, item_size * length);
124 ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for table type %d.\n",
129 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
131 data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
135 struct ice_pkg_sect_hdr *hdr =
136 (struct ice_pkg_sect_hdr *)state.sect;
141 idx = hdr->offset + state.entry_idx;
143 (void *)((uintptr_t)table + idx * item_size),
152 * ice_parser_create - create a parser instance
153 * @hw: pointer to the hardware structure
154 * @psr: output parameter for a new parser instance be created
156 enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr)
158 enum ice_status status;
159 struct ice_parser *p;
161 p = (struct ice_parser *)ice_malloc(hw, sizeof(struct ice_parser));
164 return ICE_ERR_NO_MEMORY;
168 p->imem_table = ice_imem_table_get(hw);
169 if (!p->imem_table) {
170 status = ICE_ERR_PARAM;
174 p->mi_table = ice_metainit_table_get(hw);
176 status = ICE_ERR_PARAM;
180 p->pg_cam_table = ice_pg_cam_table_get(hw);
181 if (!p->pg_cam_table) {
182 status = ICE_ERR_PARAM;
186 p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
187 if (!p->pg_sp_cam_table) {
188 status = ICE_ERR_PARAM;
192 p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
193 if (!p->pg_nm_cam_table) {
194 status = ICE_ERR_PARAM;
198 p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
199 if (!p->pg_nm_sp_cam_table) {
200 status = ICE_ERR_PARAM;
204 p->bst_tcam_table = ice_bst_tcam_table_get(hw);
205 if (!p->bst_tcam_table) {
206 status = ICE_ERR_PARAM;
210 p->bst_lbl_table = ice_bst_lbl_table_get(hw);
211 if (!p->bst_lbl_table) {
212 status = ICE_ERR_PARAM;
216 p->ptype_mk_tcam_table = ice_ptype_mk_tcam_table_get(hw);
217 if (!p->ptype_mk_tcam_table) {
218 status = ICE_ERR_PARAM;
222 p->mk_grp_table = ice_mk_grp_table_get(hw);
223 if (!p->mk_grp_table) {
224 status = ICE_ERR_PARAM;
231 ice_parser_destroy(p);
236 * ice_parser_destroy - destroy a parser instance
237 * @psr: pointer to a parser instance
239 void ice_parser_destroy(struct ice_parser *psr)
241 ice_free(psr->hw, psr->imem_table);
242 ice_free(psr->hw, psr->mi_table);
243 ice_free(psr->hw, psr->pg_cam_table);
244 ice_free(psr->hw, psr->pg_sp_cam_table);
245 ice_free(psr->hw, psr->pg_nm_cam_table);
246 ice_free(psr->hw, psr->pg_nm_sp_cam_table);
247 ice_free(psr->hw, psr->bst_tcam_table);
248 ice_free(psr->hw, psr->bst_lbl_table);
249 ice_free(psr->hw, psr->ptype_mk_tcam_table);
250 ice_free(psr->hw, psr->mk_grp_table);
252 ice_free(psr->hw, psr);