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
12 * ice_parser_sect_item_get - parse a item from a section
13 * @sect_type: section type
14 * @section: section object
15 * @index: index of the item to get
16 * @offset: dummy as prototype of ice_pkg_enum_entry's last parameter
18 void *ice_parser_sect_item_get(u32 sect_type, void *section,
19 u32 index, u32 *offset)
21 struct ice_pkg_sect_hdr *hdr;
22 int data_off = ICE_SEC_DATA_OFFSET;
29 case ICE_SID_RXPARSER_IMEM:
30 size = ICE_SID_RXPARSER_IMEM_ENTRY_SIZE;
36 hdr = (struct ice_pkg_sect_hdr *)section;
37 if (index >= LE16_TO_CPU(hdr->count))
40 return (void *)((uintptr_t)section + data_off + index * size);
44 * ice_parser_create_table - create a item table from a section
45 * @hw: pointer to the hardware structure
46 * @sect_type: section type
47 * @item_size: item size in byte
48 * @length: number of items in the table to create
49 * @item_get: the function will be parsed to ice_pkg_enum_entry
50 * @parser_item: the function to parse the item
52 void *ice_parser_create_table(struct ice_hw *hw, u32 sect_type,
53 u32 item_size, u32 length,
54 void *(*item_get)(u32 sect_type, void *section,
55 u32 index, u32 *offset),
56 void (*parse_item)(struct ice_hw *hw, u16 idx,
57 void *item, void *data,
60 struct ice_seg *seg = hw->seg;
61 struct ice_pkg_enum state;
69 table = ice_malloc(hw, item_size * length);
71 ice_debug(hw, ICE_DBG_PARSER, "failed to allocate memory for table type %d.\n",
76 ice_memset(&state, 0, sizeof(state), ICE_NONDMA_MEM);
78 data = ice_pkg_enum_entry(seg, &state, sect_type, NULL,
82 struct ice_pkg_sect_hdr *hdr =
83 (struct ice_pkg_sect_hdr *)state.sect;
85 idx = hdr->offset + state.entry_idx;
87 (void *)((uintptr_t)table + idx * item_size),
96 * ice_parser_create - create a parser instance
97 * @hw: pointer to the hardware structure
98 * @psr: output parameter for a new parser instance be created
100 enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr)
102 enum ice_status status;
103 struct ice_parser *p;
105 p = (struct ice_parser *)ice_malloc(hw, sizeof(struct ice_parser));
108 return ICE_ERR_NO_MEMORY;
112 p->imem_table = ice_imem_table_get(hw);
113 if (!p->imem_table) {
114 status = ICE_ERR_PARAM;
121 ice_parser_destroy(p);
126 * ice_parser_destroy - destroy a parser instance
127 * @psr: pointer to a parser instance
129 void ice_parser_destroy(struct ice_parser *psr)
131 ice_free(psr->hw, psr->imem_table);
133 ice_free(psr->hw, psr);