From cc3f51e4662989c349035ce27a903d63bf64ff08 Mon Sep 17 00:00:00 2001 From: Qi Zhang Date: Fri, 17 Sep 2021 22:43:20 +0800 Subject: [PATCH] net/ice/base: support double VLAN mode configure for parser Add API ice_parser_dvm_set to support turn on/off parser's double vlan mode. Signed-off-by: Qi Zhang Acked-by: Junfeng Guo --- drivers/net/ice/base/ice_bst_tcam.c | 28 ++++++++++++++++++++++++++++ drivers/net/ice/base/ice_bst_tcam.h | 4 ++++ drivers/net/ice/base/ice_parser.c | 27 +++++++++++++++++++++++++++ drivers/net/ice/base/ice_parser.h | 1 + 4 files changed, 60 insertions(+) diff --git a/drivers/net/ice/base/ice_bst_tcam.c b/drivers/net/ice/base/ice_bst_tcam.c index 76b3a5c551..306f62db2a 100644 --- a/drivers/net/ice/base/ice_bst_tcam.c +++ b/drivers/net/ice/base/ice_bst_tcam.c @@ -261,3 +261,31 @@ ice_bst_tcam_match(struct ice_bst_tcam_item *tcam_table, u8 *pat) return NULL; } + +static bool _start_with(const char *prefix, const char *string) +{ + int len1 = strlen(prefix); + int len2 = strlen(string); + + if (len2 < len1) + return false; + + return !memcmp(prefix, string, len1); +} + +struct ice_bst_tcam_item * +ice_bst_tcam_search(struct ice_bst_tcam_item *tcam_table, + struct ice_lbl_item *lbl_table, + const char *prefix, u16 *start) +{ + u16 i = *start; + + for (; i < ICE_BST_TCAM_TABLE_SIZE; i++) { + if (_start_with(prefix, lbl_table[i].label)) { + *start = i; + return &tcam_table[lbl_table[i].idx]; + } + } + + return NULL; +} diff --git a/drivers/net/ice/base/ice_bst_tcam.h b/drivers/net/ice/base/ice_bst_tcam.h index 3cba0bbf55..e4c96c439d 100644 --- a/drivers/net/ice/base/ice_bst_tcam.h +++ b/drivers/net/ice/base/ice_bst_tcam.h @@ -28,4 +28,8 @@ 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); +struct ice_bst_tcam_item * +ice_bst_tcam_search(struct ice_bst_tcam_item *tcam_table, + struct ice_lbl_item *lbl_table, + const char *prefix, u16 *start); #endif /*_ICE_BST_TCAM_H_ */ diff --git a/drivers/net/ice/base/ice_parser.c b/drivers/net/ice/base/ice_parser.c index 8f423710fc..395ad220a0 100644 --- a/drivers/net/ice/base/ice_parser.c +++ b/drivers/net/ice/base/ice_parser.c @@ -340,3 +340,30 @@ void ice_parser_result_dump(struct ice_hw *hw, struct ice_parser_result *rslt) ice_info(hw, "flags_fd = 0x%04x\n", rslt->flags_fd); ice_info(hw, "flags_rss = 0x%04x\n", rslt->flags_rss); } + +static void _bst_vm_set(struct ice_parser *psr, const char *prefix, bool on) +{ + struct ice_bst_tcam_item *item; + u16 i = 0; + + while (true) { + item = ice_bst_tcam_search(psr->bst_tcam_table, + psr->bst_lbl_table, + prefix, &i); + if (!item) + break; + item->key[0] = (u8)(on ? 0xff : 0xfe); + item->key_inv[0] = (u8)(on ? 0xff : 0xfe); + i++; + } +} + +/** + * ice_parser_dvm_set - configure double vlan mode for parser + * @psr: pointer to a parser instance + */ +void ice_parser_dvm_set(struct ice_parser *psr, bool on) +{ + _bst_vm_set(psr, "BOOST_MAC_VLAN_DVM", on); + _bst_vm_set(psr, "BOOST_MAC_VLAN_SVM", !on); +} diff --git a/drivers/net/ice/base/ice_parser.h b/drivers/net/ice/base/ice_parser.h index 715158d6eb..e310466678 100644 --- a/drivers/net/ice/base/ice_parser.h +++ b/drivers/net/ice/base/ice_parser.h @@ -57,6 +57,7 @@ struct ice_parser { enum ice_status ice_parser_create(struct ice_hw *hw, struct ice_parser **psr); void ice_parser_destroy(struct ice_parser *psr); +void ice_parser_dvm_set(struct ice_parser *psr, bool on); struct ice_parser_proto_off { u8 proto_id; /* hardware protocol ID */ -- 2.20.1