From bc8e0f501cf4c3bee3de8ee26a98e72e517cfe32 Mon Sep 17 00:00:00 2001 From: Huawei Xie Date: Tue, 2 Dec 2014 17:02:06 +0800 Subject: [PATCH] i40e: use macros for vlan filtering registers Add two macros I40E_VFTA_IDX and I40E_VFTA_BIT for vlan filter search and set. Add vlan_id check in vlan filter search and set function. Signed-off-by: Huawei Xie Acked-by: Helin Zhang Acked-by: Jing Chen --- lib/librte_pmd_i40e/i40e_ethdev.c | 17 ++++++++++------- lib/librte_pmd_i40e/i40e_ethdev.h | 9 +++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/librte_pmd_i40e/i40e_ethdev.c b/lib/librte_pmd_i40e/i40e_ethdev.c index 17876114d3..899cb42245 100644 --- a/lib/librte_pmd_i40e/i40e_ethdev.c +++ b/lib/librte_pmd_i40e/i40e_ethdev.c @@ -4168,8 +4168,11 @@ i40e_find_vlan_filter(struct i40e_vsi *vsi, { uint32_t vid_idx, vid_bit; - vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F); - vid_bit = (uint32_t) (1 << (vlan_id & 0x1F)); + if (vlan_id > ETH_VLAN_ID_MAX) + return 0; + + vid_idx = I40E_VFTA_IDX(vlan_id); + vid_bit = I40E_VFTA_BIT(vlan_id); if (vsi->vfta[vid_idx] & vid_bit) return 1; @@ -4183,11 +4186,11 @@ i40e_set_vlan_filter(struct i40e_vsi *vsi, { uint32_t vid_idx, vid_bit; - /* VFTA is 32-bits size array, each element contains 32 vlan bits, Find the - * element first, then find the bits it belongs to - */ - vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F); - vid_bit = (uint32_t) (1 << (vlan_id & 0x1F)); + if (vlan_id > ETH_VLAN_ID_MAX) + return; + + vid_idx = I40E_VFTA_IDX(vlan_id); + vid_bit = I40E_VFTA_BIT(vlan_id); if (on) vsi->vfta[vid_idx] |= vid_bit; diff --git a/lib/librte_pmd_i40e/i40e_ethdev.h b/lib/librte_pmd_i40e/i40e_ethdev.h index f99fbeadfc..f913ea9680 100644 --- a/lib/librte_pmd_i40e/i40e_ethdev.h +++ b/lib/librte_pmd_i40e/i40e_ethdev.h @@ -50,6 +50,15 @@ #define I40E_DEFAULT_QP_NUM_FDIR 1 #define I40E_UINT32_BIT_SIZE (CHAR_BIT * sizeof(uint32_t)) #define I40E_VFTA_SIZE (4096 / I40E_UINT32_BIT_SIZE) +/* + * vlan_id is a 12 bit number. + * The VFTA array is actually a 4096 bit array, 128 of 32bit elements. + * 2^5 = 32. The val of lower 5 bits specifies the bit in the 32bit element. + * The higher 7 bit val specifies VFTA array index. + */ +#define I40E_VFTA_BIT(vlan_id) (1 << ((vlan_id) & 0x1F)) +#define I40E_VFTA_IDX(vlan_id) ((vlan_id) >> 5) + /* Default TC traffic in case DCB is not enabled */ #define I40E_DEFAULT_TCMAP 0x1 #define I40E_FDIR_QUEUE_ID 0 -- 2.20.1