Commit 0c0da0e9 authored by Ahmed Zaki's avatar Ahmed Zaki Committed by Tony Nguyen

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: default avatarAhmed Zaki <ahmed.zaki@intel.com>
Tested-by: default avatarRafal Romanowski <rafal.romanowski@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent b9881d9a
...@@ -158,15 +158,18 @@ struct iavf_vlan { ...@@ -158,15 +158,18 @@ struct iavf_vlan {
u16 tpid; u16 tpid;
}; };
enum iavf_vlan_state_t {
IAVF_VLAN_INVALID,
IAVF_VLAN_ADD, /* filter needs to be added */
IAVF_VLAN_IS_NEW, /* filter is new, wait for PF answer */
IAVF_VLAN_ACTIVE, /* filter is accepted by PF */
IAVF_VLAN_REMOVE, /* filter needs to be removed */
};
struct iavf_vlan_filter { struct iavf_vlan_filter {
struct list_head list; struct list_head list;
struct iavf_vlan vlan; struct iavf_vlan vlan;
struct { enum iavf_vlan_state_t state;
u8 is_new_vlan:1; /* filter is new, wait for PF answer */
u8 remove:1; /* filter needs to be removed */
u8 add:1; /* filter needs to be added */
u8 padding:5;
};
}; };
#define IAVF_MAX_TRAFFIC_CLASS 4 #define IAVF_MAX_TRAFFIC_CLASS 4
......
...@@ -791,7 +791,7 @@ iavf_vlan_filter *iavf_add_vlan(struct iavf_adapter *adapter, ...@@ -791,7 +791,7 @@ iavf_vlan_filter *iavf_add_vlan(struct iavf_adapter *adapter,
f->vlan = vlan; f->vlan = vlan;
list_add_tail(&f->list, &adapter->vlan_filter_list); list_add_tail(&f->list, &adapter->vlan_filter_list);
f->add = true; f->state = IAVF_VLAN_ADD;
adapter->aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER; adapter->aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
} }
...@@ -813,7 +813,7 @@ static void iavf_del_vlan(struct iavf_adapter *adapter, struct iavf_vlan vlan) ...@@ -813,7 +813,7 @@ static void iavf_del_vlan(struct iavf_adapter *adapter, struct iavf_vlan vlan)
f = iavf_find_vlan(adapter, vlan); f = iavf_find_vlan(adapter, vlan);
if (f) { if (f) {
f->remove = true; f->state = IAVF_VLAN_REMOVE;
adapter->aq_required |= IAVF_FLAG_AQ_DEL_VLAN_FILTER; adapter->aq_required |= IAVF_FLAG_AQ_DEL_VLAN_FILTER;
} }
...@@ -1296,11 +1296,11 @@ static void iavf_clear_mac_vlan_filters(struct iavf_adapter *adapter) ...@@ -1296,11 +1296,11 @@ static void iavf_clear_mac_vlan_filters(struct iavf_adapter *adapter)
/* remove all VLAN filters */ /* remove all VLAN filters */
list_for_each_entry_safe(vlf, vlftmp, &adapter->vlan_filter_list, list_for_each_entry_safe(vlf, vlftmp, &adapter->vlan_filter_list,
list) { list) {
if (vlf->add) { if (vlf->state == IAVF_VLAN_ADD) {
list_del(&vlf->list); list_del(&vlf->list);
kfree(vlf); kfree(vlf);
} else { } else {
vlf->remove = true; vlf->state = IAVF_VLAN_REMOVE;
} }
} }
spin_unlock_bh(&adapter->mac_vlan_list_lock); spin_unlock_bh(&adapter->mac_vlan_list_lock);
......
...@@ -642,7 +642,7 @@ static void iavf_vlan_add_reject(struct iavf_adapter *adapter) ...@@ -642,7 +642,7 @@ static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
spin_lock_bh(&adapter->mac_vlan_list_lock); spin_lock_bh(&adapter->mac_vlan_list_lock);
list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
if (f->is_new_vlan) { if (f->state == IAVF_VLAN_IS_NEW) {
if (f->vlan.tpid == ETH_P_8021Q) if (f->vlan.tpid == ETH_P_8021Q)
clear_bit(f->vlan.vid, clear_bit(f->vlan.vid,
adapter->vsi.active_cvlans); adapter->vsi.active_cvlans);
...@@ -679,7 +679,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter) ...@@ -679,7 +679,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter)
spin_lock_bh(&adapter->mac_vlan_list_lock); spin_lock_bh(&adapter->mac_vlan_list_lock);
list_for_each_entry(f, &adapter->vlan_filter_list, list) { list_for_each_entry(f, &adapter->vlan_filter_list, list) {
if (f->add) if (f->state == IAVF_VLAN_ADD)
count++; count++;
} }
if (!count || !VLAN_FILTERING_ALLOWED(adapter)) { if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
...@@ -710,11 +710,10 @@ void iavf_add_vlans(struct iavf_adapter *adapter) ...@@ -710,11 +710,10 @@ void iavf_add_vlans(struct iavf_adapter *adapter)
vvfl->vsi_id = adapter->vsi_res->vsi_id; vvfl->vsi_id = adapter->vsi_res->vsi_id;
vvfl->num_elements = count; vvfl->num_elements = count;
list_for_each_entry(f, &adapter->vlan_filter_list, list) { list_for_each_entry(f, &adapter->vlan_filter_list, list) {
if (f->add) { if (f->state == IAVF_VLAN_ADD) {
vvfl->vlan_id[i] = f->vlan.vid; vvfl->vlan_id[i] = f->vlan.vid;
i++; i++;
f->add = false; f->state = IAVF_VLAN_IS_NEW;
f->is_new_vlan = true;
if (i == count) if (i == count)
break; break;
} }
...@@ -760,7 +759,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter) ...@@ -760,7 +759,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter)
vvfl_v2->vport_id = adapter->vsi_res->vsi_id; vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
vvfl_v2->num_elements = count; vvfl_v2->num_elements = count;
list_for_each_entry(f, &adapter->vlan_filter_list, list) { list_for_each_entry(f, &adapter->vlan_filter_list, list) {
if (f->add) { if (f->state == IAVF_VLAN_ADD) {
struct virtchnl_vlan_supported_caps *filtering_support = struct virtchnl_vlan_supported_caps *filtering_support =
&adapter->vlan_v2_caps.filtering.filtering_support; &adapter->vlan_v2_caps.filtering.filtering_support;
struct virtchnl_vlan *vlan; struct virtchnl_vlan *vlan;
...@@ -778,8 +777,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter) ...@@ -778,8 +777,7 @@ void iavf_add_vlans(struct iavf_adapter *adapter)
vlan->tpid = f->vlan.tpid; vlan->tpid = f->vlan.tpid;
i++; i++;
f->add = false; f->state = IAVF_VLAN_IS_NEW;
f->is_new_vlan = true;
} }
} }
...@@ -822,10 +820,11 @@ void iavf_del_vlans(struct iavf_adapter *adapter) ...@@ -822,10 +820,11 @@ void iavf_del_vlans(struct iavf_adapter *adapter)
* filters marked for removal to enable bailing out before * filters marked for removal to enable bailing out before
* sending a virtchnl message * sending a virtchnl message
*/ */
if (f->remove && !VLAN_FILTERING_ALLOWED(adapter)) { if (f->state == IAVF_VLAN_REMOVE &&
!VLAN_FILTERING_ALLOWED(adapter)) {
list_del(&f->list); list_del(&f->list);
kfree(f); kfree(f);
} else if (f->remove) { } else if (f->state == IAVF_VLAN_REMOVE) {
count++; count++;
} }
} }
...@@ -857,7 +856,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter) ...@@ -857,7 +856,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter)
vvfl->vsi_id = adapter->vsi_res->vsi_id; vvfl->vsi_id = adapter->vsi_res->vsi_id;
vvfl->num_elements = count; vvfl->num_elements = count;
list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
if (f->remove) { if (f->state == IAVF_VLAN_REMOVE) {
vvfl->vlan_id[i] = f->vlan.vid; vvfl->vlan_id[i] = f->vlan.vid;
i++; i++;
list_del(&f->list); list_del(&f->list);
...@@ -901,7 +900,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter) ...@@ -901,7 +900,7 @@ void iavf_del_vlans(struct iavf_adapter *adapter)
vvfl_v2->vport_id = adapter->vsi_res->vsi_id; vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
vvfl_v2->num_elements = count; vvfl_v2->num_elements = count;
list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) { list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
if (f->remove) { if (f->state == IAVF_VLAN_REMOVE) {
struct virtchnl_vlan_supported_caps *filtering_support = struct virtchnl_vlan_supported_caps *filtering_support =
&adapter->vlan_v2_caps.filtering.filtering_support; &adapter->vlan_v2_caps.filtering.filtering_support;
struct virtchnl_vlan *vlan; struct virtchnl_vlan *vlan;
...@@ -2192,7 +2191,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter, ...@@ -2192,7 +2191,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
list_for_each_entry(vlf, list_for_each_entry(vlf,
&adapter->vlan_filter_list, &adapter->vlan_filter_list,
list) list)
vlf->add = true; vlf->state = IAVF_VLAN_ADD;
adapter->aq_required |= adapter->aq_required |=
IAVF_FLAG_AQ_ADD_VLAN_FILTER; IAVF_FLAG_AQ_ADD_VLAN_FILTER;
...@@ -2260,7 +2259,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter, ...@@ -2260,7 +2259,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
list_for_each_entry(vlf, list_for_each_entry(vlf,
&adapter->vlan_filter_list, &adapter->vlan_filter_list,
list) list)
vlf->add = true; vlf->state = IAVF_VLAN_ADD;
aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER; aq_required |= IAVF_FLAG_AQ_ADD_VLAN_FILTER;
} }
...@@ -2444,8 +2443,8 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter, ...@@ -2444,8 +2443,8 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
spin_lock_bh(&adapter->mac_vlan_list_lock); spin_lock_bh(&adapter->mac_vlan_list_lock);
list_for_each_entry(f, &adapter->vlan_filter_list, list) { list_for_each_entry(f, &adapter->vlan_filter_list, list) {
if (f->is_new_vlan) { if (f->state == IAVF_VLAN_IS_NEW) {
f->is_new_vlan = false; f->state = IAVF_VLAN_ACTIVE;
if (f->vlan.tpid == ETH_P_8021Q) if (f->vlan.tpid == ETH_P_8021Q)
set_bit(f->vlan.vid, set_bit(f->vlan.vid,
adapter->vsi.active_cvlans); adapter->vsi.active_cvlans);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment