common/cnxk: add lower bound check for SSO resources
[dpdk.git] / drivers / net / ice / base / ice_ptype_mk.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2021 Intel Corporation
3  */
4
5 #include "ice_common.h"
6 #include "ice_parser_util.h"
7
8 #define ICE_PTYPE_MK_TCAM_TABLE_SIZE 1024
9
10 /**
11  * ice_ptype_mk_tcam_dump - dump an ptype marker tcam info_
12  * @ice_hw: pointer to the hardware structure
13  * @item: ptype marker tcam to dump
14  */
15 void ice_ptype_mk_tcam_dump(struct ice_hw *hw,
16                             struct ice_ptype_mk_tcam_item *item)
17 {
18         int i;
19
20         ice_info(hw, "address = %d\n", item->address);
21         ice_info(hw, "ptype = %d\n", item->ptype);
22         ice_info(hw, "key    :");
23         for (i = 0; i < 10; i++)
24                 ice_info(hw, "%02x ", item->key[i]);
25         ice_info(hw, "\n");
26         ice_info(hw, "key_inv:");
27         for (i = 0; i < 10; i++)
28                 ice_info(hw, "%02x ", item->key_inv[i]);
29         ice_info(hw, "\n");
30 }
31
32 static void _parse_ptype_mk_tcam_item(struct ice_hw *hw, u16 idx, void *item,
33                                       void *data, int size)
34 {
35         ice_parse_item_dflt(hw, idx, item, data, size);
36
37         if (hw->debug_mask & ICE_DBG_PARSER)
38                 ice_ptype_mk_tcam_dump(hw,
39                                        (struct ice_ptype_mk_tcam_item *)item);
40 }
41
42 /**
43  * ice_ptype_mk_tcam_table_get - create a ptype marker tcam table
44  * @ice_hw: pointer to the hardware structure
45  */
46 struct ice_ptype_mk_tcam_item *ice_ptype_mk_tcam_table_get(struct ice_hw *hw)
47 {
48         return (struct ice_ptype_mk_tcam_item *)
49                 ice_parser_create_table(hw, ICE_SID_RXPARSER_MARKER_PTYPE,
50                                         sizeof(struct ice_ptype_mk_tcam_item),
51                                         ICE_PTYPE_MK_TCAM_TABLE_SIZE,
52                                         ice_parser_sect_item_get,
53                                         _parse_ptype_mk_tcam_item, true);
54 }
55
56 /**
57  * ice_ptype_mk_tcam_match - match a pattern on a ptype marker tcam table
58  * @table: ptype marker tcam table to search
59  * @pat: pattern to match
60  * @len: length of the pattern
61  */
62 struct ice_ptype_mk_tcam_item *
63 ice_ptype_mk_tcam_match(struct ice_ptype_mk_tcam_item *table,
64                         u8 *pat, int len)
65 {
66         int i;
67
68         for (i = 0; i < ICE_PTYPE_MK_TCAM_TABLE_SIZE; i++) {
69                 struct ice_ptype_mk_tcam_item *item = &table[i];
70
71                 if (ice_ternary_match(item->key, item->key_inv, pat, len))
72                         return item;
73         }
74
75         return NULL;
76 }