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
20 #define ICE_SEC_LBL_DATA_OFFSET 2
21 #define ICE_SID_LBL_ENTRY_SIZE 66
23 void ice_lbl_dump(struct ice_hw *hw, struct ice_lbl_item *item)
25 ice_info(hw, "index = %d\n", item->idx);
26 ice_info(hw, "label = %s\n", item->label);
29 void ice_parse_item_dflt(struct ice_hw *hw, u16 idx, void *item,
32 ice_memcpy(item, data, size, ICE_DMA_TO_NONDMA);
36 * ice_parser_sect_item_get - parse a item from a section
37 * @sect_type: section type
38 * @section: section object
39 * @index: index of the item to get
40 * @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
42 void *ice_parser_sect_item_get(u32 sect_type, void *section,
43 u32 index, u32 *offset)
45 struct ice_pkg_sect_hdr *hdr;
46 int data_off = ICE_SEC_DATA_OFFSET;
53 case ICE_SID_RXPARSER_IMEM:
54 size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
56 case ICE_SID_RXPARSER_METADATA_INIT:
57 size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
59 case ICE_SID_RXPARSER_CAM:
60 size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
62 case ICE_SID_RXPARSER_PG_SPILL:
63 size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
65 case ICE_SID_RXPARSER_NOMATCH_CAM:
66 size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
68 case ICE_SID_RXPARSER_NOMATCH_SPILL:
69 size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
71 case ICE_SID_RXPARSER_BOOST_TCAM:
72 size = ICE_SID_RXPARSER_BOOST_TCAM_ENTRY_SIZE;
74 case ICE_SID_LBL_RXPARSER_TMEM:
75 data_off = ICE_SEC_LBL_DATA_OFFSET;
76 size = ICE_SID_LBL_ENTRY_SIZE;
78 case ICE_SID_RXPARSER_MARKER_PTYPE:
79 size = ICE_SID_RXPARSER_MARKER_TYPE_ENTRY_SIZE;
81 case ICE_SID_RXPARSER_MARKER_GRP:
82 size = ICE_SID_RXPARSER_MARKER_GRP_ENTRY_SIZE;
84 case ICE_SID_RXPARSER_PROTO_GRP:
85 size = ICE_SID_RXPARSER_PROTO_GRP_ENTRY_SIZE;
91 hdr = (struct ice_pkg_sect_hdr *)section;
92 if (index >= LE16_TO_CPU(hdr->count))
95 return (void *)((uintptr_t)section + data_off + index * size);
99 * ice_parser_create_table - create a item table from a section
100 * @hw: pointer to the hardware structure
101 * @sect_type: section type
102 * @item_size: item size in byte
103 * @length: number of items in the table to create
104 * @item_get: the function will be parsed to ice_pkg_enum_entry
105 * @parser_item: the function to parse the item
106 * @no_offset: ignore header offset, calculate index from 0
108 void *ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
109 u32 item_size, u32 length,
110 void *(*item_get)(u32 sect_type, void *section,
111 u32 index, u32 *offset),
112 void (*parse_item)(struct ice_hw *hw, u16 idx,
113 void *item, void *data,
117 struct ice_seg *seg = hw->seg;
118 struct ice_pkg_enum state;
126 table = ice_malloc(hw, item_size * length);
128 ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for table type %d.\n",
133 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
135 data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
139 struct ice_pkg_sect_hdr *hdr =
140 (struct ice_pkg_sect_hdr *)state.sect;
145 idx = hdr->offset + state.entry_idx;
147 (void *)((uintptr_t)table + idx * item_size),
156 * ice_parser_create - create a parser instance
157 * @hw: pointer to the hardware structure
158 * @psr: output parameter for a new parser instance be created
160 enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr)
162 enum ice_status status;
163 struct ice_parser *p;
165 p = (struct ice_parser *)ice_malloc(hw, sizeof(struct ice_parser));
168 return ICE_ERR_NO_MEMORY;
172 p->imem_table = ice_imem_table_get(hw);
173 if (!p->imem_table) {
174 status = ICE_ERR_PARAM;
178 p->mi_table = ice_metainit_table_get(hw);
180 status = ICE_ERR_PARAM;
184 p->pg_cam_table = ice_pg_cam_table_get(hw);
185 if (!p->pg_cam_table) {
186 status = ICE_ERR_PARAM;
190 p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
191 if (!p->pg_sp_cam_table) {
192 status = ICE_ERR_PARAM;
196 p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
197 if (!p->pg_nm_cam_table) {
198 status = ICE_ERR_PARAM;
202 p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
203 if (!p->pg_nm_sp_cam_table) {
204 status = ICE_ERR_PARAM;
208 p->bst_tcam_table = ice_bst_tcam_table_get(hw);
209 if (!p->bst_tcam_table) {
210 status = ICE_ERR_PARAM;
214 p->bst_lbl_table = ice_bst_lbl_table_get(hw);
215 if (!p->bst_lbl_table) {
216 status = ICE_ERR_PARAM;
220 p->ptype_mk_tcam_table = ice_ptype_mk_tcam_table_get(hw);
221 if (!p->ptype_mk_tcam_table) {
222 status = ICE_ERR_PARAM;
226 p->mk_grp_table = ice_mk_grp_table_get(hw);
227 if (!p->mk_grp_table) {
228 status = ICE_ERR_PARAM;
232 p->proto_grp_table = ice_proto_grp_table_get(hw);
233 if (!p->proto_grp_table) {
234 status = ICE_ERR_PARAM;
241 ice_parser_destroy(p);
246 * ice_parser_destroy - destroy a parser instance
247 * @psr: pointer to a parser instance
249 void ice_parser_destroy(struct ice_parser *psr)
251 ice_free(psr->hw, psr->imem_table);
252 ice_free(psr->hw, psr->mi_table);
253 ice_free(psr->hw, psr->pg_cam_table);
254 ice_free(psr->hw, psr->pg_sp_cam_table);
255 ice_free(psr->hw, psr->pg_nm_cam_table);
256 ice_free(psr->hw, psr->pg_nm_sp_cam_table);
257 ice_free(psr->hw, psr->bst_tcam_table);
258 ice_free(psr->hw, psr->bst_lbl_table);
259 ice_free(psr->hw, psr->ptype_mk_tcam_table);
260 ice_free(psr->hw, psr->mk_grp_table);
261 ice_free(psr->hw, psr->proto_grp_table);
263 ice_free(psr->hw, psr);