From patchwork Fri Sep 17 11:02:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 99122 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3A65EA0C47; Fri, 17 Sep 2021 13:01:16 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 18DFE41156; Fri, 17 Sep 2021 13:00:00 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 5AE8141145 for ; Fri, 17 Sep 2021 12:59:56 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10109"; a="286458723" X-IronPort-AV: E=Sophos;i="5.85,301,1624345200"; d="scan'208";a="286458723" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2021 03:59:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,301,1624345200"; d="scan'208";a="699440727" Received: from dpdk51.sh.intel.com ([10.67.111.142]) by fmsmga006.fm.intel.com with ESMTP; 17 Sep 2021 03:59:54 -0700 From: Qi Zhang To: qiming.yang@intel.com Cc: junfeng.guo@intel.com, dev@dpdk.org, Qi Zhang Date: Fri, 17 Sep 2021 19:02:34 +0800 Message-Id: <20210917110242.3127658-13-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210917110242.3127658-1-qi.z.zhang@intel.com> References: <20210917110242.3127658-1-qi.z.zhang@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 12/20] net/ice/base: add helper function for boost TCAM match X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add internal helper function ice_bst_tcam_match to perform ternary match on boost TCAM. Signed-off-by: Qi Zhang --- drivers/net/ice/base/ice_bst_tcam.c | 22 +++++++++++++++ drivers/net/ice/base/ice_bst_tcam.h | 3 ++ drivers/net/ice/base/ice_parser.h | 1 + drivers/net/ice/base/ice_tmatch.h | 44 +++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 drivers/net/ice/base/ice_tmatch.h diff --git a/drivers/net/ice/base/ice_bst_tcam.c b/drivers/net/ice/base/ice_bst_tcam.c index 1c82359681..76b3a5c551 100644 --- a/drivers/net/ice/base/ice_bst_tcam.c +++ b/drivers/net/ice/base/ice_bst_tcam.c @@ -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; +} diff --git a/drivers/net/ice/base/ice_bst_tcam.h b/drivers/net/ice/base/ice_bst_tcam.h index a4ab40721f..3cba0bbf55 100644 --- a/drivers/net/ice/base/ice_bst_tcam.h +++ b/drivers/net/ice/base/ice_bst_tcam.h @@ -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_ */ diff --git a/drivers/net/ice/base/ice_parser.h b/drivers/net/ice/base/ice_parser.h index 3a307e0344..b2ab21728e 100644 --- a/drivers/net/ice/base/ice_parser.h +++ b/drivers/net/ice/base/ice_parser.h @@ -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 */ diff --git a/drivers/net/ice/base/ice_tmatch.h b/drivers/net/ice/base/ice_tmatch.h new file mode 100644 index 0000000000..178a084639 --- /dev/null +++ b/drivers/net/ice/base/ice_tmatch.h @@ -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_ */