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
17 #define ICE_SEC_LBL_DATA_OFFSET 2
18 #define ICE_SID_LBL_ENTRY_SIZE 66
20 void ice_lbl_dump(struct ice_hw *hw, struct ice_lbl_item *item)
22 ice_info(hw, "index = %d\n", item->idx);
23 ice_info(hw, "label = %s\n", item->label);
26 void ice_parse_item_dflt(struct ice_hw *hw, u16 idx, void *item,
29 ice_memcpy(item, data, size, ICE_DMA_TO_NONDMA);
33 * ice_parser_sect_item_get - parse a item from a section
34 * @sect_type: section type
35 * @section: section object
36 * @index: index of the item to get
37 * @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
39 void *ice_parser_sect_item_get(u32 sect_type, void *section,
40 u32 index, u32 *offset)
42 struct ice_pkg_sect_hdr *hdr;
43 int data_off = ICE_SEC_DATA_OFFSET;
50 case ICE_SID_RXPARSER_IMEM:
51 size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
53 case ICE_SID_RXPARSER_METADATA_INIT:
54 size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
56 case ICE_SID_RXPARSER_CAM:
57 size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
59 case ICE_SID_RXPARSER_PG_SPILL:
60 size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
62 case ICE_SID_RXPARSER_NOMATCH_CAM:
63 size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
65 case ICE_SID_RXPARSER_NOMATCH_SPILL:
66 size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
68 case ICE_SID_RXPARSER_BOOST_TCAM:
69 size = ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE;
71 case ICE_SID_LBL_RXPARSER_TMEM:
72 data_off = ICE_SEC_LBL_DATA_OFFSET;
73 size = ICE_SID_LBL_ENTRY_SIZE;
79 hdr = (struct ice_pkg_sect_hdr *)section;
80 if (index >= LE16_TO_CPU(hdr->count))
83 return (void *)((uintptr_t)section + data_off + index * size);
87 * ice_parser_create_table - create a item table from a section
88 * @hw: pointer to the hardware structure
89 * @sect_type: section type
90 * @item_size: item size in byte
91 * @length: number of items in the table to create
92 * @item_get: the function will be parsed to ice_pkg_enum_entry
93 * @parser_item: the function to parse the item
94 * @no_offset: ignore header offset, calculate index from 0
96 void *ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
97 u32 item_size, u32 length,
98 void *(*item_get)(u32 sect_type, void *section,
99 u32 index, u32 *offset),
100 void (*parse_item)(struct ice_hw *hw, u16 idx,
101 void *item, void *data,
105 struct ice_seg *seg = hw->seg;
106 struct ice_pkg_enum state;
114 table = ice_malloc(hw, item_size * length);
116 ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for table type %d.\n",
121 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
123 data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
127 struct ice_pkg_sect_hdr *hdr =
128 (struct ice_pkg_sect_hdr *)state.sect;
133 idx = hdr->offset + state.entry_idx;
135 (void *)((uintptr_t)table + idx * item_size),
144 * ice_parser_create - create a parser instance
145 * @hw: pointer to the hardware structure
146 * @psr: output parameter for a new parser instance be created
148 enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr)
150 enum ice_status status;
151 struct ice_parser *p;
153 p = (struct ice_parser *)ice_malloc(hw, sizeof(struct ice_parser));
156 return ICE_ERR_NO_MEMORY;
160 p->imem_table = ice_imem_table_get(hw);
161 if (!p->imem_table) {
162 status = ICE_ERR_PARAM;
166 p->mi_table = ice_metainit_table_get(hw);
168 status = ICE_ERR_PARAM;
172 p->pg_cam_table = ice_pg_cam_table_get(hw);
173 if (!p->pg_cam_table) {
174 status = ICE_ERR_PARAM;
178 p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
179 if (!p->pg_sp_cam_table) {
180 status = ICE_ERR_PARAM;
184 p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
185 if (!p->pg_nm_cam_table) {
186 status = ICE_ERR_PARAM;
190 p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
191 if (!p->pg_nm_sp_cam_table) {
192 status = ICE_ERR_PARAM;
196 p->bst_tcam_table = ice_bst_tcam_table_get(hw);
197 if (!p->bst_tcam_table) {
198 status = ICE_ERR_PARAM;
202 p->bst_lbl_table = ice_bst_lbl_table_get(hw);
203 if (!p->bst_lbl_table) {
204 status = ICE_ERR_PARAM;
211 ice_parser_destroy(p);
216 * ice_parser_destroy - destroy a parser instance
217 * @psr: pointer to a parser instance
219 void ice_parser_destroy(struct ice_parser *psr)
221 ice_free(psr->hw, psr->imem_table);
222 ice_free(psr->hw, psr->mi_table);
223 ice_free(psr->hw, psr->pg_cam_table);
224 ice_free(psr->hw, psr->pg_sp_cam_table);
225 ice_free(psr->hw, psr->pg_nm_cam_table);
226 ice_free(psr->hw, psr->pg_nm_sp_cam_table);
227 ice_free(psr->hw, psr->bst_tcam_table);
228 ice_free(psr->hw, psr->bst_lbl_table);
230 ice_free(psr->hw, psr);