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
17 * ice_parser_sect_item_get - parse a item from a section
18 * @sect_type: section type
19 * @section: section object
20 * @index: index of the item to get
21 * @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
23 void *ice_parser_sect_item_get(u32 sect_type, void *section,
24 u32 index, u32 *offset)
26 struct ice_pkg_sect_hdr *hdr;
27 int data_off = ICE_SEC_DATA_OFFSET;
34 case ICE_SID_RXPARSER_IMEM:
35 size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
37 case ICE_SID_RXPARSER_METADATA_INIT:
38 size = ICE_SID_RXPARSER_METADATA_INIT_ENTRY_SIZE;
40 case ICE_SID_RXPARSER_CAM:
41 size = ICE_SID_RXPARSER_CAM_ENTRY_SIZE;
43 case ICE_SID_RXPARSER_PG_SPILL:
44 size = ICE_SID_RXPARSER_PG_SPILL_ENTRY_SIZE;
46 case ICE_SID_RXPARSER_NOMATCH_CAM:
47 size = ICE_SID_RXPARSER_NOMATCH_CAM_ENTRY_SIZE;
49 case ICE_SID_RXPARSER_NOMATCH_SPILL:
50 size = ICE_SID_RXPARSER_NOMATCH_SPILL_ENTRY_SIZE;
56 hdr = (struct ice_pkg_sect_hdr *)section;
57 if (index >= LE16_TO_CPU(hdr->count))
60 return (void *)((uintptr_t)section + data_off + index * size);
64 * ice_parser_create_table - create a item table from a section
65 * @hw: pointer to the hardware structure
66 * @sect_type: section type
67 * @item_size: item size in byte
68 * @length: number of items in the table to create
69 * @item_get: the function will be parsed to ice_pkg_enum_entry
70 * @parser_item: the function to parse the item
72 void *ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
73 u32 item_size, u32 length,
74 void *(*item_get)(u32 sect_type, void *section,
75 u32 index, u32 *offset),
76 void (*parse_item)(struct ice_hw *hw, u16 idx,
77 void *item, void *data,
80 struct ice_seg *seg = hw->seg;
81 struct ice_pkg_enum state;
89 table = ice_malloc(hw, item_size * length);
91 ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for table type %d.\n",
96 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
98 data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
102 struct ice_pkg_sect_hdr *hdr =
103 (struct ice_pkg_sect_hdr *)state.sect;
105 idx = hdr->offset + state.entry_idx;
107 (void *)((uintptr_t)table + idx * item_size),
116 * ice_parser_create - create a parser instance
117 * @hw: pointer to the hardware structure
118 * @psr: output parameter for a new parser instance be created
120 enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr)
122 enum ice_status status;
123 struct ice_parser *p;
125 p = (struct ice_parser *)ice_malloc(hw, sizeof(struct ice_parser));
128 return ICE_ERR_NO_MEMORY;
132 p->imem_table = ice_imem_table_get(hw);
133 if (!p->imem_table) {
134 status = ICE_ERR_PARAM;
138 p->mi_table = ice_metainit_table_get(hw);
140 status = ICE_ERR_PARAM;
144 p->pg_cam_table = ice_pg_cam_table_get(hw);
145 if (!p->pg_cam_table) {
146 status = ICE_ERR_PARAM;
150 p->pg_sp_cam_table = ice_pg_sp_cam_table_get(hw);
151 if (!p->pg_sp_cam_table) {
152 status = ICE_ERR_PARAM;
156 p->pg_nm_cam_table = ice_pg_nm_cam_table_get(hw);
157 if (!p->pg_nm_cam_table) {
158 status = ICE_ERR_PARAM;
162 p->pg_nm_sp_cam_table = ice_pg_nm_sp_cam_table_get(hw);
163 if (!p->pg_nm_sp_cam_table) {
164 status = ICE_ERR_PARAM;
171 ice_parser_destroy(p);
176 * ice_parser_destroy - destroy a parser instance
177 * @psr: pointer to a parser instance
179 void ice_parser_destroy(struct ice_parser *psr)
181 ice_free(psr->hw, psr->imem_table);
182 ice_free(psr->hw, psr->mi_table);
183 ice_free(psr->hw, psr->pg_cam_table);
184 ice_free(psr->hw, psr->pg_sp_cam_table);
185 ice_free(psr->hw, psr->pg_nm_cam_table);
186 ice_free(psr->hw, psr->pg_nm_sp_cam_table);
188 ice_free(psr->hw, psr);