Skip to content

Commit 0c0da0e

Browse files
azaki1anguy11
authored andcommitted
iavf: refactor VLAN filter states
The VLAN filter states are currently being saved as individual bits. This is error prone as multiple bits might be mistakenly set. Fix by replacing the bits with a single state enum. Also, add an "ACTIVE" state for filters that are accepted by the PF. Signed-off-by: Ahmed Zaki <ahmed.zaki@intel.com> Tested-by: Rafal Romanowski <rafal.romanowski@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent b9881d9 commit 0c0da0e

3 files changed

Lines changed: 28 additions & 26 deletions

File tree

drivers/net/ethernet/intel/iavf/iavf.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,18 @@ struct iavf_vlan {
158158
u16 tpid;
159159
};
160160

161+
enum iavf_vlan_state_t {
162+
IAVF_VLAN_INVALID,
163+
IAVF_VLAN_ADD, /* filter needs to be added */
164+
IAVF_VLAN_IS_NEW, /* filter is new, wait for PF answer */
165+
IAVF_VLAN_ACTIVE, /* filter is accepted by PF */
166+
IAVF_VLAN_REMOVE, /* filter needs to be removed */
167+
};
168+
161169
struct iavf_vlan_filter {
162170
struct list_head list;
163171
struct iavf_vlan vlan;
164-
struct {
165-
u8 is_new_vlan:1; /* filter is new, wait for PF answer */
166-
u8 remove:1; /* filter needs to be removed */
167-
u8 add:1; /* filter needs to be added */
168-
u8 padding:5;
169-
};
172+
enum iavf_vlan_state_t state;
170173
};
171174

172175
#define IAVF_MAX_TRAFFIC_CLASS 4

drivers/net/ethernet/intel/iavf/iavf_main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ iavf_vlan_filter *iavf_add_vlan(struct iavf_adapter *adapter,
791791
f->vlan = vlan;
792792

793793
list_add_tail(&f->list, &adapter->vlan_filter_list);
794-
f->add = true;
794+
f->state = IAVF_VLAN_ADD;
795795
adapter->aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
796796
}
797797

@@ -813,7 +813,7 @@ static void iavf_del_vlan(struct iavf_adapter *adapter, struct iavf_vlan vlan)
813813

814814
f = iavf_find_vlan(adapter, vlan);
815815
if (f) {
816-
f->remove = true;
816+
f->state = IAVF_VLAN_REMOVE;
817817
adapter->aq_required |= IAVF_FLAG_AQ_DEL_VLAN_FILTER;
818818
}
819819

@@ -1296,11 +1296,11 @@ static void iavf_clear_mac_vlan_filters(struct iavf_adapter *adapter)
12961296
/* remove all VLAN filters */
12971297
list_for_each_entry_safe(vlf, vlftmp, &adapter->vlan_filter_list,
12981298
list) {
1299-
if (vlf->add) {
1299+
if (vlf->state == IAVF_VLAN_ADD) {
13001300
list_del(&vlf->list);
13011301
kfree(vlf);
13021302
} else {
1303-
vlf->remove = true;
1303+
vlf->state = IAVF_VLAN_REMOVE;
13041304
}
13051305
}
13061306
spin_unlock_bh(&adapter->mac_vlan_list_lock);

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
642642

643643
spin_lock_bh(&adapter->mac_vlan_list_lock);
644644
list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
645-
if (f->is_new_vlan) {
645+
if (f->state == IAVF_VLAN_IS_NEW) {
646646
if (f->vlan.tpid == ETH_P_8021Q)
647647
clear_bit(f->vlan.vid,
648648
adapter->vsi.active_cvlans);
@@ -679,7 +679,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter)
679679
spin_lock_bh(&adapter->mac_vlan_list_lock);
680680

681681
list_for_each_entry(f, &adapter->vlan_filter_list, list) {
682-
if (f->add)
682+
if (f->state == IAVF_VLAN_ADD)
683683
count++;
684684
}
685685
if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
@@ -710,11 +710,10 @@ void iavf_add_vlans(struct iavf_adapter *adapter)
710710
vvfl->vsi_id = adapter->vsi_res->vsi_id;
711711
vvfl->num_elements = count;
712712
list_for_each_entry(f, &adapter->vlan_filter_list, list) {
713-
if (f->add) {
713+
if (f->state == IAVF_VLAN_ADD) {
714714
vvfl->vlan_id[i] = f->vlan.vid;
715715
i++;
716-
f->add = false;
717-
f->is_new_vlan = true;
716+
f->state = IAVF_VLAN_IS_NEW;
718717
if (i == count)
719718
break;
720719
}
@@ -760,7 +759,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter)
760759
vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
761760
vvfl_v2->num_elements = count;
762761
list_for_each_entry(f, &adapter->vlan_filter_list, list) {
763-
if (f->add) {
762+
if (f->state == IAVF_VLAN_ADD) {
764763
struct virtchnl_vlan_supported_caps *filtering_support =
765764
&adapter->vlan_v2_caps.filtering.filtering_support;
766765
struct virtchnl_vlan *vlan;
@@ -778,8 +777,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter)
778777
vlan->tpid = f->vlan.tpid;
779778

780779
i++;
781-
f->add = false;
782-
f->is_new_vlan = true;
780+
f->state = IAVF_VLAN_IS_NEW;
783781
}
784782
}
785783

@@ -822,10 +820,11 @@ void iavf_del_vlans(struct iavf_adapter *adapter)
822820
* filters marked for removal to enable bailing out before
823821
* sending a virtchnl message
824822
*/
825-
if (f->remove && !VLAN_FILTERING_ALLOWED(adapter)) {
823+
if (f->state == IAVF_VLAN_REMOVE &&
824+
!VLAN_FILTERING_ALLOWED(adapter)) {
826825
list_del(&f->list);
827826
kfree(f);
828-
} else if (f->remove) {
827+
} else if (f->state == IAVF_VLAN_REMOVE) {
829828
count++;
830829
}
831830
}
@@ -857,7 +856,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter)
857856
vvfl->vsi_id = adapter->vsi_res->vsi_id;
858857
vvfl->num_elements = count;
859858
list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
860-
if (f->remove) {
859+
if (f->state == IAVF_VLAN_REMOVE) {
861860
vvfl->vlan_id[i] = f->vlan.vid;
862861
i++;
863862
list_del(&f->list);
@@ -901,7 +900,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter)
901900
vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
902901
vvfl_v2->num_elements = count;
903902
list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
904-
if (f->remove) {
903+
if (f->state == IAVF_VLAN_REMOVE) {
905904
struct virtchnl_vlan_supported_caps *filtering_support =
906905
&adapter->vlan_v2_caps.filtering.filtering_support;
907906
struct virtchnl_vlan *vlan;
@@ -2192,7 +2191,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
21922191
list_for_each_entry(vlf,
21932192
&adapter->vlan_filter_list,
21942193
list)
2195-
vlf->add = true;
2194+
vlf->state = IAVF_VLAN_ADD;
21962195

21972196
adapter->aq_required |=
21982197
IAVF_FLAG_AQ_ADD_VLAN_FILTER;
@@ -2260,7 +2259,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
22602259
list_for_each_entry(vlf,
22612260
&adapter->vlan_filter_list,
22622261
list)
2263-
vlf->add = true;
2262+
vlf->state = IAVF_VLAN_ADD;
22642263

22652264
aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
22662265
}
@@ -2444,8 +2443,8 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
24442443

24452444
spin_lock_bh(&adapter->mac_vlan_list_lock);
24462445
list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2447-
if (f->is_new_vlan) {
2448-
f->is_new_vlan = false;
2446+
if (f->state == IAVF_VLAN_IS_NEW) {
2447+
f->state = IAVF_VLAN_ACTIVE;
24492448
if (f->vlan.tpid == ETH_P_8021Q)
24502449
set_bit(f->vlan.vid,
24512450
adapter->vsi.active_cvlans);

0 commit comments

Comments
 (0)