Commit cc6a96a4 authored by Alan Brady's avatar Alan Brady Committed by Jeff Kirsher

i40e: refactor promisc_changed in i40e_sync_vsi_filters

This code here is quite complex and easy to screw up.  Let's see if we
can't improve the readability and maintainability a bit.  This refactors
out promisc_changed into two variables 'old_overflow' and 'new_overflow'
which makes it a bit clearer when we're concerned about when and how
overflow promiscuous is changed.  This also makes so that we no longer
need to pass a boolean pointer to i40e_aqc_add_filters.  Instead we can
simply check if we changed the overflow promiscuous flag since the
function start.
Signed-off-by: default avatarAlan Brady <alan.brady@intel.com>
Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent fbd5eb54
...@@ -2116,17 +2116,16 @@ void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name, ...@@ -2116,17 +2116,16 @@ void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
* @list: the list of filters to send to firmware * @list: the list of filters to send to firmware
* @add_head: Position in the add hlist * @add_head: Position in the add hlist
* @num_add: the number of filters to add * @num_add: the number of filters to add
* @promisc_change: set to true on exit if promiscuous mode was forced on
* *
* Send a request to firmware via AdminQ to add a chunk of filters. Will set * Send a request to firmware via AdminQ to add a chunk of filters. Will set
* promisc_changed to true if the firmware has run out of space for more * __I40E_VSI_OVERFLOW_PROMISC bit in vsi->state if the firmware has run out of
* filters. * space for more filters.
*/ */
static static
void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
struct i40e_aqc_add_macvlan_element_data *list, struct i40e_aqc_add_macvlan_element_data *list,
struct i40e_new_mac_filter *add_head, struct i40e_new_mac_filter *add_head,
int num_add, bool *promisc_changed) int num_add)
{ {
struct i40e_hw *hw = &vsi->back->hw; struct i40e_hw *hw = &vsi->back->hw;
int aq_err, fcnt; int aq_err, fcnt;
...@@ -2136,7 +2135,6 @@ void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name, ...@@ -2136,7 +2135,6 @@ void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
fcnt = i40e_update_filter_state(num_add, list, add_head); fcnt = i40e_update_filter_state(num_add, list, add_head);
if (fcnt != num_add) { if (fcnt != num_add) {
*promisc_changed = true;
set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
dev_warn(&vsi->back->pdev->dev, dev_warn(&vsi->back->pdev->dev,
"Error %s adding RX filters on %s, promiscuous mode forced on\n", "Error %s adding RX filters on %s, promiscuous mode forced on\n",
...@@ -2269,9 +2267,9 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi) ...@@ -2269,9 +2267,9 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
struct i40e_mac_filter *f; struct i40e_mac_filter *f;
struct i40e_new_mac_filter *new, *add_head = NULL; struct i40e_new_mac_filter *new, *add_head = NULL;
struct i40e_hw *hw = &vsi->back->hw; struct i40e_hw *hw = &vsi->back->hw;
bool old_overflow, new_overflow;
unsigned int failed_filters = 0; unsigned int failed_filters = 0;
unsigned int vlan_filters = 0; unsigned int vlan_filters = 0;
bool promisc_changed = false;
char vsi_name[16] = "PF"; char vsi_name[16] = "PF";
int filter_list_len = 0; int filter_list_len = 0;
i40e_status aq_ret = 0; i40e_status aq_ret = 0;
...@@ -2293,6 +2291,8 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi) ...@@ -2293,6 +2291,8 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
usleep_range(1000, 2000); usleep_range(1000, 2000);
pf = vsi->back; pf = vsi->back;
old_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
if (vsi->netdev) { if (vsi->netdev) {
changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
vsi->current_netdev_flags = vsi->netdev->flags; vsi->current_netdev_flags = vsi->netdev->flags;
...@@ -2466,15 +2466,14 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi) ...@@ -2466,15 +2466,14 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
/* flush a full buffer */ /* flush a full buffer */
if (num_add == filter_list_len) { if (num_add == filter_list_len) {
i40e_aqc_add_filters(vsi, vsi_name, add_list, i40e_aqc_add_filters(vsi, vsi_name, add_list,
add_head, num_add, add_head, num_add);
&promisc_changed);
memset(add_list, 0, list_size); memset(add_list, 0, list_size);
num_add = 0; num_add = 0;
} }
} }
if (num_add) { if (num_add) {
i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head, i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
num_add, &promisc_changed); num_add);
} }
/* Now move all of the filters from the temp add list back to /* Now move all of the filters from the temp add list back to
* the VSI's list. * the VSI's list.
...@@ -2503,24 +2502,16 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi) ...@@ -2503,24 +2502,16 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
} }
spin_unlock_bh(&vsi->mac_filter_hash_lock); spin_unlock_bh(&vsi->mac_filter_hash_lock);
/* If promiscuous mode has changed, we need to calculate a new
* threshold for when we are safe to exit
*/
if (promisc_changed)
vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
/* Check if we are able to exit overflow promiscuous mode. We can /* Check if we are able to exit overflow promiscuous mode. We can
* safely exit if we didn't just enter, we no longer have any failed * safely exit if we didn't just enter, we no longer have any failed
* filters, and we have reduced filters below the threshold value. * filters, and we have reduced filters below the threshold value.
*/ */
if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) && if (old_overflow && !failed_filters &&
!promisc_changed && !failed_filters && vsi->active_filters < vsi->promisc_threshold) {
(vsi->active_filters < vsi->promisc_threshold)) {
dev_info(&pf->pdev->dev, dev_info(&pf->pdev->dev,
"filter logjam cleared on %s, leaving overflow promiscuous mode\n", "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
vsi_name); vsi_name);
clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state); clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
promisc_changed = true;
vsi->promisc_threshold = 0; vsi->promisc_threshold = 0;
} }
...@@ -2530,6 +2521,14 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi) ...@@ -2530,6 +2521,14 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
goto out; goto out;
} }
new_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
/* If we are entering overflow promiscuous, we need to calculate a new
* threshold for when we are safe to exit
*/
if (!old_overflow && new_overflow)
vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
/* check for changes in promiscuous modes */ /* check for changes in promiscuous modes */
if (changed_flags & IFF_ALLMULTI) { if (changed_flags & IFF_ALLMULTI) {
bool cur_multipromisc; bool cur_multipromisc;
...@@ -2550,12 +2549,11 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi) ...@@ -2550,12 +2549,11 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
} }
} }
if ((changed_flags & IFF_PROMISC) || promisc_changed) { if ((changed_flags & IFF_PROMISC) || old_overflow != new_overflow) {
bool cur_promisc; bool cur_promisc;
cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) || cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
test_bit(__I40E_VSI_OVERFLOW_PROMISC, new_overflow);
vsi->state));
aq_ret = i40e_set_promiscuous(pf, cur_promisc); aq_ret = i40e_set_promiscuous(pf, cur_promisc);
if (aq_ret) { if (aq_ret) {
retval = i40e_aq_rc_to_posix(aq_ret, retval = i40e_aq_rc_to_posix(aq_ret,
......
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