net/ice/base: add helper function for boost TCAM match

Add internal helper function ice_bst_tcam_match to perform ternary
match on boost TCAM.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
Acked-by: Junfeng Guo <junfeng.guo@intel.com>
This commit is contained in:
Qi Zhang 2021-09-17 22:43:14 +08:00
parent c84f8aa210
commit 4b20fa1b1d
4 changed files with 70 additions and 0 deletions

View File

@ -239,3 +239,25 @@ struct ice_lbl_item *ice_bst_lbl_table_get(struct ice_hw *hw)
ice_parser_sect_item_get,
_parse_lbl_item, true);
}
/**
* ice_bst_tcam_match - match a pattern on the boost tcam table
* @tcam_table: boost tcam table to search
* @pat: pattern to match
*/
struct ice_bst_tcam_item *
ice_bst_tcam_match(struct ice_bst_tcam_item *tcam_table, u8 *pat)
{
int i;
for (i = 0; i < ICE_BST_TCAM_TABLE_SIZE; i++) {
struct ice_bst_tcam_item *item = &tcam_table[i];
if (item->hit_idx_grp == 0)
continue;
if (ice_ternary_match(item->key, item->key_inv, pat, 20))
return item;
}
return NULL;
}

View File

@ -25,4 +25,7 @@ void ice_bst_tcam_dump(struct ice_hw *hw, struct ice_bst_tcam_item *item);
struct ice_bst_tcam_item *ice_bst_tcam_table_get(struct ice_hw *hw);
struct ice_lbl_item *ice_bst_lbl_table_get(struct ice_hw *hw);
struct ice_bst_tcam_item *
ice_bst_tcam_match(struct ice_bst_tcam_item *tcam_table, u8 *pat);
#endif /*_ICE_BST_TCAM_H_ */

View File

@ -15,6 +15,7 @@
#include "ice_flg_rd.h"
#include "ice_xlt_kb.h"
#include "ice_parser_rt.h"
#include "ice_tmatch.h"
struct ice_parser {
struct ice_hw *hw; /* pointer to the hardware structure */

View File

@ -0,0 +1,44 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2001-2021 Intel Corporation
*/
#ifndef _ICE_TMATCH_H_
#define _ICE_TMATCH_H_
static inline
bool ice_ternary_match_byte(u8 key, u8 key_inv, u8 pat)
{
u8 k1, k2, v;
int i;
for (i = 0; i < 8; i++) {
k1 = (u8)(key & (1 << i));
k2 = (u8)(key_inv & (1 << i));
v = (u8)(pat & (1 << i));
if (k1 != 0 && k2 != 0)
continue;
if (k1 == 0 && k2 == 0)
return false;
if (k1 == v)
return false;
}
return true;
}
static inline
bool ice_ternary_match(const u8 *key, const u8 *key_inv,
const u8 *pat, int len)
{
int i;
for (i = 0; i < len; i++)
if (!ice_ternary_match_byte(key[i], key_inv[i], pat[i]))
return false;
return true;
}
#endif /* _ICE_TMATCH_H_ */