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
18 #define ICE_SID_RXPARSER_PROTO_GRP_ENTRY_SIZE 24
19 #define ICE_SID_RXPARSER_FLAG_REDIR_ENTRY_SIZE 1
21 #define ICE_SEC_LBL_DATA_OFFSET 2
22 #define ICE_SID_LBL_ENTRY_SIZE 66
24 void ice_lbl_dump(struct ice_hw *hw, struct ice_lbl_item *item)
26 ice_info(hw, "index = %d\n", item->idx);
27 ice_info(hw, "label = %s\n", item->label);
30 void ice_parse_item_dflt(struct ice_hw *hw, u16 idx, void *item,
33 ice_memcpy(item, data, size, ICE_DMA_TO_NONDMA);
37 * ice_parser_sect_item_get - parse a item from a section
38 * @sect_type: section type
39 * @section: section object
40 * @index: index of the item to get
41 * @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
43 void *ice_parser_sect_item_get(u32 sect_type, void *section,
44 u32 index, u32 *offset)
46 struct ice_pkg_sect_hdr *hdr;
47 int data_off = ICE_SEC_DATA_OFFSET;
54 case ICE_SID_RXPARSER_IMEM:
55 size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
57 case ICE_SID_RXPARSER_METADATA_INIT:
58 size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
60 case ICE_SID_RXPARSER_CAM:
61 size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
63 case ICE_SID_RXPARSER_PG_SPILL:
64 size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
66 case ICE_SID_RXPARSER_NOMATCH_CAM:
67 size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
69 case ICE_SID_RXPARSER_NOMATCH_SPILL:
70 size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
72 case ICE_SID_RXPARSER_BOOST_TCAM:
73 size = ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE;
75 case ICE_SID_LBL_RXPARSER_TMEM:
76 data_off = ICE_SEC_LBL_DATA_OFFSET;
77 size = ICE_SID_LBL_ENTRY_SIZE;
79 case ICE_SID_RXPARSER_MARKER_PTYPE:
80 size = ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE;
82 case ICE_SID_RXPARSER_MARKER_GRP:
83 size = ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE;
85 case ICE_SID_RXPARSER_PROTO_GRP:
86 size = ICE_SID_RXPARSER_PROTO_GRP_ENTRY_SIZE;
88 case ICE_SID_RXPARSER_FLAG_REDIR:
89 size = ICE_SID_RXPARSER_FLAG_REDIR_ENTRY_SIZE;
95 hdr = (struct ice_pkg_sect_hdr *)section;
96 if (index >= LE16_TO_CPU(hdr->count))
99 return (void *)((uintptr_t)section + data_off + index * size);
103 * ice_parser_create_table - create a item table from a section
104 * @hw: pointer to the hardware structure
105 * @sect_type: section type
106 * @item_size: item size in byte
107 * @length: number of items in the table to create
108 * @item_get: the function will be parsed to ice_pkg_enum_entry
109 * @parser_item: the function to parse the item
110 * @no_offset: ignore header offset, calculate index from 0
112 void *ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
113 u32 item_size, u32 length,
114 void *(*item_get)(u32 sect_type, void *section,
115 u32 index, u32 *offset),
116 void (*parse_item)(struct ice_hw *hw, u16 idx,
117 void *item, void *data,
121 struct ice_seg *seg = hw->seg;
122 struct ice_pkg_enum state;
130 table = ice_malloc(hw, item_size * length);
132 ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for table type %d.\n",
137 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
139 data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
143 struct ice_pkg_sect_hdr *hdr =
144 (struct ice_pkg_sect_hdr *)state.sect;
149 idx = hdr->offset + state.entry_idx;
151 (void *)((uintptr_t)table + idx * item_size),
160 * ice_parser_create - create a parser instance
161 * @hw: pointer to the hardware structure
162 * @psr: output parameter for a new parser instance be created
164 enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr)
166 enum ice_status status;
167 struct ice_parser *p;
169 p = (struct ice_parser *)ice_malloc(hw, sizeof(struct ice_parser));
172 return ICE_ERR_NO_MEMORY;
176 p->imem_table = ice_imem_table_get(hw);
177 if (!p->imem_table) {
178 status = ICE_ERR_PARAM;
182 p->mi_table = ice_metainit_table_get(hw);
184 status = ICE_ERR_PARAM;
188 p->pg_cam_table = ice_pg_cam_table_get(hw);
189 if (!p->pg_cam_table) {
190 status = ICE_ERR_PARAM;
194 p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
195 if (!p->pg_sp_cam_table) {
196 status = ICE_ERR_PARAM;
200 p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
201 if (!p->pg_nm_cam_table) {
202 status = ICE_ERR_PARAM;
206 p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
207 if (!p->pg_nm_sp_cam_table) {
208 status = ICE_ERR_PARAM;
212 p->bst_tcam_table = ice_bst_tcam_table_get(hw);
213 if (!p->bst_tcam_table) {
214 status = ICE_ERR_PARAM;
218 p->bst_lbl_table = ice_bst_lbl_table_get(hw);
219 if (!p->bst_lbl_table) {
220 status = ICE_ERR_PARAM;
224 p->ptype_mk_tcam_table = ice_ptype_mk_tcam_table_get(hw);
225 if (!p->ptype_mk_tcam_table) {
226 status = ICE_ERR_PARAM;
230 p->mk_grp_table = ice_mk_grp_table_get(hw);
231 if (!p->mk_grp_table) {
232 status = ICE_ERR_PARAM;
236 p->proto_grp_table = ice_proto_grp_table_get(hw);
237 if (!p->proto_grp_table) {
238 status = ICE_ERR_PARAM;
242 p->flg_rd_table = ice_flg_rd_table_get(hw);
243 if (!p->flg_rd_table) {
244 status = ICE_ERR_PARAM;
251 ice_parser_destroy(p);
256 * ice_parser_destroy - destroy a parser instance
257 * @psr: pointer to a parser instance
259 void ice_parser_destroy(struct ice_parser *psr)
261 ice_free(psr->hw, psr->imem_table);
262 ice_free(psr->hw, psr->mi_table);
263 ice_free(psr->hw, psr->pg_cam_table);
264 ice_free(psr->hw, psr->pg_sp_cam_table);
265 ice_free(psr->hw, psr->pg_nm_cam_table);
266 ice_free(psr->hw, psr->pg_nm_sp_cam_table);
267 ice_free(psr->hw, psr->bst_tcam_table);
268 ice_free(psr->hw, psr->bst_lbl_table);
269 ice_free(psr->hw, psr->ptype_mk_tcam_table);
270 ice_free(psr->hw, psr->mk_grp_table);
271 ice_free(psr->hw, psr->proto_grp_table);
272 ice_free(psr->hw, psr->flg_rd_table);
274 ice_free(psr->hw, psr);