Commit 794e5bc8 authored by Andre Guedes's avatar Andre Guedes Committed by Jeff Kirsher

igc: Refactor igc_mac_entry_can_be_used()

The helper igc_mac_entry_can_be_used() implementation is a bit
convoluted since it does two different things: find a not-in-use slot
in mac_table or find an in-use slot where the address and address type
match. This patch does a code refactoring and break it up into two
helper functions.

With this patch we might traverse mac_table twice in some situations,
but this is not harmful performance-wise (mac_table has only 16 entries
and adding mac filters is not hot-path), and it improves igc_add_mac_
filter() readability considerably.
Signed-off-by: default avatarAndre Guedes <andre.guedes@intel.com>
Tested-by: default avatarAaron Brown <aaron.f.brown@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 83ba21b9
...@@ -2176,25 +2176,44 @@ static void igc_nfc_filter_restore(struct igc_adapter *adapter) ...@@ -2176,25 +2176,44 @@ static void igc_nfc_filter_restore(struct igc_adapter *adapter)
spin_unlock(&adapter->nfc_lock); spin_unlock(&adapter->nfc_lock);
} }
/* If the filter to be added and an already existing filter express static int igc_find_mac_filter(struct igc_adapter *adapter, const u8 *addr,
* the same address and address type, it should be possible to only u8 flags)
* override the other configurations, for example the queue to steer
* traffic.
*/
static bool igc_mac_entry_can_be_used(const struct igc_mac_addr *entry,
const u8 *addr, const u8 flags)
{ {
if (!(entry->state & IGC_MAC_STATE_IN_USE)) int max_entries = adapter->hw.mac.rar_entry_count;
return true; struct igc_mac_addr *entry;
int i;
if ((entry->state & IGC_MAC_STATE_SRC_ADDR) != for (i = 0; i < max_entries; i++) {
(flags & IGC_MAC_STATE_SRC_ADDR)) entry = &adapter->mac_table[i];
return false;
if (!ether_addr_equal(addr, entry->addr)) if (!(entry->state & IGC_MAC_STATE_IN_USE))
return false; continue;
if (!ether_addr_equal(addr, entry->addr))
continue;
if ((entry->state & IGC_MAC_STATE_SRC_ADDR) !=
(flags & IGC_MAC_STATE_SRC_ADDR))
continue;
return true; return i;
}
return -1;
}
static int igc_get_avail_mac_filter_slot(struct igc_adapter *adapter)
{
int max_entries = adapter->hw.mac.rar_entry_count;
struct igc_mac_addr *entry;
int i;
for (i = 0; i < max_entries; i++) {
entry = &adapter->mac_table[i];
if (!(entry->state & IGC_MAC_STATE_IN_USE))
return i;
}
return -1;
} }
/** /**
...@@ -2212,33 +2231,28 @@ static bool igc_mac_entry_can_be_used(const struct igc_mac_addr *entry, ...@@ -2212,33 +2231,28 @@ static bool igc_mac_entry_can_be_used(const struct igc_mac_addr *entry,
int igc_add_mac_filter(struct igc_adapter *adapter, const u8 *addr, int igc_add_mac_filter(struct igc_adapter *adapter, const u8 *addr,
const s8 queue, const u8 flags) const s8 queue, const u8 flags)
{ {
struct igc_hw *hw = &adapter->hw; int index;
int rar_entries = hw->mac.rar_entry_count;
int i;
if (!is_valid_ether_addr(addr)) if (!is_valid_ether_addr(addr))
return -EINVAL; return -EINVAL;
if (flags & IGC_MAC_STATE_SRC_ADDR) if (flags & IGC_MAC_STATE_SRC_ADDR)
return -ENOTSUPP; return -ENOTSUPP;
/* Search for the first empty entry in the MAC table. index = igc_find_mac_filter(adapter, addr, flags);
* Do not touch entries at the end of the table reserved for the VF MAC if (index >= 0)
* addresses. goto update_queue_assignment;
*/
for (i = 0; i < rar_entries; i++) {
if (!igc_mac_entry_can_be_used(&adapter->mac_table[i],
addr, flags))
continue;
ether_addr_copy(adapter->mac_table[i].addr, addr); index = igc_get_avail_mac_filter_slot(adapter);
adapter->mac_table[i].queue = queue; if (index < 0)
adapter->mac_table[i].state |= IGC_MAC_STATE_IN_USE | flags; return -ENOSPC;
igc_set_mac_filter_hw(adapter, i, addr, queue); ether_addr_copy(adapter->mac_table[index].addr, addr);
return 0; adapter->mac_table[index].state |= IGC_MAC_STATE_IN_USE | flags;
} update_queue_assignment:
adapter->mac_table[index].queue = queue;
return -ENOSPC; igc_set_mac_filter_hw(adapter, index, addr, queue);
return 0;
} }
/** /**
......
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