Skip to content

Commit cc6a96a

Browse files
atbrady-intelJeff Kirsher
authored andcommitted
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: Alan Brady <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent fbd5eb5 commit cc6a96a

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,17 +2116,16 @@ void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
21162116
* @list: the list of filters to send to firmware
21172117
* @add_head: Position in the add hlist
21182118
* @num_add: the number of filters to add
2119-
* @promisc_change: set to true on exit if promiscuous mode was forced on
21202119
*
21212120
* Send a request to firmware via AdminQ to add a chunk of filters. Will set
2122-
* promisc_changed to true if the firmware has run out of space for more
2123-
* filters.
2121+
* __I40E_VSI_OVERFLOW_PROMISC bit in vsi->state if the firmware has run out of
2122+
* space for more filters.
21242123
*/
21252124
static
21262125
void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
21272126
struct i40e_aqc_add_macvlan_element_data *list,
21282127
struct i40e_new_mac_filter *add_head,
2129-
int num_add, bool *promisc_changed)
2128+
int num_add)
21302129
{
21312130
struct i40e_hw *hw = &vsi->back->hw;
21322131
int aq_err, fcnt;
@@ -2136,7 +2135,6 @@ void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
21362135
fcnt = i40e_update_filter_state(num_add, list, add_head);
21372136

21382137
if (fcnt != num_add) {
2139-
*promisc_changed = true;
21402138
set_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
21412139
dev_warn(&vsi->back->pdev->dev,
21422140
"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)
22692267
struct i40e_mac_filter *f;
22702268
struct i40e_new_mac_filter *new, *add_head = NULL;
22712269
struct i40e_hw *hw = &vsi->back->hw;
2270+
bool old_overflow, new_overflow;
22722271
unsigned int failed_filters = 0;
22732272
unsigned int vlan_filters = 0;
2274-
bool promisc_changed = false;
22752273
char vsi_name[16] = "PF";
22762274
int filter_list_len = 0;
22772275
i40e_status aq_ret = 0;
@@ -2293,6 +2291,8 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
22932291
usleep_range(1000, 2000);
22942292
pf = vsi->back;
22952293

2294+
old_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2295+
22962296
if (vsi->netdev) {
22972297
changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
22982298
vsi->current_netdev_flags = vsi->netdev->flags;
@@ -2466,15 +2466,14 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
24662466
/* flush a full buffer */
24672467
if (num_add == filter_list_len) {
24682468
i40e_aqc_add_filters(vsi, vsi_name, add_list,
2469-
add_head, num_add,
2470-
&promisc_changed);
2469+
add_head, num_add);
24712470
memset(add_list, 0, list_size);
24722471
num_add = 0;
24732472
}
24742473
}
24752474
if (num_add) {
24762475
i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
2477-
num_add, &promisc_changed);
2476+
num_add);
24782477
}
24792478
/* Now move all of the filters from the temp add list back to
24802479
* the VSI's list.
@@ -2503,24 +2502,16 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
25032502
}
25042503
spin_unlock_bh(&vsi->mac_filter_hash_lock);
25052504

2506-
/* If promiscuous mode has changed, we need to calculate a new
2507-
* threshold for when we are safe to exit
2508-
*/
2509-
if (promisc_changed)
2510-
vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
2511-
25122505
/* Check if we are able to exit overflow promiscuous mode. We can
25132506
* safely exit if we didn't just enter, we no longer have any failed
25142507
* filters, and we have reduced filters below the threshold value.
25152508
*/
2516-
if (test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state) &&
2517-
!promisc_changed && !failed_filters &&
2518-
(vsi->active_filters < vsi->promisc_threshold)) {
2509+
if (old_overflow && !failed_filters &&
2510+
vsi->active_filters < vsi->promisc_threshold) {
25192511
dev_info(&pf->pdev->dev,
25202512
"filter logjam cleared on %s, leaving overflow promiscuous mode\n",
25212513
vsi_name);
25222514
clear_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2523-
promisc_changed = true;
25242515
vsi->promisc_threshold = 0;
25252516
}
25262517

@@ -2530,6 +2521,14 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
25302521
goto out;
25312522
}
25322523

2524+
new_overflow = test_bit(__I40E_VSI_OVERFLOW_PROMISC, vsi->state);
2525+
2526+
/* If we are entering overflow promiscuous, we need to calculate a new
2527+
* threshold for when we are safe to exit
2528+
*/
2529+
if (!old_overflow && new_overflow)
2530+
vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
2531+
25332532
/* check for changes in promiscuous modes */
25342533
if (changed_flags & IFF_ALLMULTI) {
25352534
bool cur_multipromisc;
@@ -2550,12 +2549,11 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
25502549
}
25512550
}
25522551

2553-
if ((changed_flags & IFF_PROMISC) || promisc_changed) {
2552+
if ((changed_flags & IFF_PROMISC) || old_overflow != new_overflow) {
25542553
bool cur_promisc;
25552554

25562555
cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
2557-
test_bit(__I40E_VSI_OVERFLOW_PROMISC,
2558-
vsi->state));
2556+
new_overflow);
25592557
aq_ret = i40e_set_promiscuous(pf, cur_promisc);
25602558
if (aq_ret) {
25612559
retval = i40e_aq_rc_to_posix(aq_ret,

0 commit comments

Comments
 (0)