Commit 424045be authored by Andre Guedes's avatar Andre Guedes Committed by Jeff Kirsher

igc: Refactor igc_rar_set_index()

Current igc_rar_set_index() implementation is a bit convoluted so this
patch does some code refactoring to improve it.

The helper igc_rar_set_index() is about writing MAC filter settings into
hardware registers. Logic such as address validation belongs to
functions upper in the call chain such as igc_set_mac() and
igc_add_mac_filter(). So this patch moves the is_valid_ether_addr() call
to igc_add_mac_filter(). No need to touch igc_set_mac() since it already
checks it.

The variables 'rar_low' and 'rar_high' represent the value in registers
RAL and RAH so we rename them to 'ral' and 'rah', respectively, to
match the registers names.

To make it explicit, filter settings are passed as arguments to the
function instead of reading them from adapter->mac_table "under the
hood". Also, the function was renamed to igc_set_mac_filter_hw to make
it more clear what it does.

Finally, the patch removes some wrfl() calls and comments not needed.
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 ec00f109
...@@ -765,42 +765,52 @@ static void igc_setup_tctl(struct igc_adapter *adapter) ...@@ -765,42 +765,52 @@ static void igc_setup_tctl(struct igc_adapter *adapter)
} }
/** /**
* igc_rar_set_index - Sync RAL[index] and RAH[index] registers with MAC table * igc_set_mac_filter_hw() - Set MAC address filter in hardware
* @adapter: address of board private structure * @adapter: Pointer to adapter where the filter should be set
* @index: Index of the RAR entry which need to be synced with MAC table * @index: Filter index
* @addr: Destination MAC address
* @queue: If non-negative, queue assignment feature is enabled and frames
* matching the filter are enqueued onto 'queue'. Otherwise, queue
* assignment is disabled.
*/ */
static void igc_rar_set_index(struct igc_adapter *adapter, u32 index) static void igc_set_mac_filter_hw(struct igc_adapter *adapter, int index,
const u8 *addr, int queue)
{ {
u8 *addr = adapter->mac_table[index].addr;
struct igc_hw *hw = &adapter->hw; struct igc_hw *hw = &adapter->hw;
u32 rar_low, rar_high; u32 ral, rah;
/* HW expects these to be in network order when they are plugged if (WARN_ON(index >= hw->mac.rar_entry_count))
* into the registers which are little endian. In order to guarantee return;
* that ordering we need to do an leXX_to_cpup here in order to be
* ready for the byteswap that occurs with writel
*/
rar_low = le32_to_cpup((__le32 *)(addr));
rar_high = le16_to_cpup((__le16 *)(addr + 4));
if (adapter->mac_table[index].state & IGC_MAC_STATE_QUEUE_STEERING) { ral = le32_to_cpup((__le32 *)(addr));
u8 queue = adapter->mac_table[index].queue; rah = le16_to_cpup((__le16 *)(addr + 4));
u32 qsel = IGC_RAH_QSEL_MASK & (queue << IGC_RAH_QSEL_SHIFT);
rar_high |= qsel; if (queue >= 0) {
rar_high |= IGC_RAH_QSEL_ENABLE; rah &= ~IGC_RAH_QSEL_MASK;
rah |= (queue << IGC_RAH_QSEL_SHIFT);
rah |= IGC_RAH_QSEL_ENABLE;
} }
/* Indicate to hardware the Address is Valid. */ rah |= IGC_RAH_AV;
if (adapter->mac_table[index].state & IGC_MAC_STATE_IN_USE) {
if (is_valid_ether_addr(addr))
rar_high |= IGC_RAH_AV;
}
wr32(IGC_RAL(index), rar_low); wr32(IGC_RAL(index), ral);
wrfl(); wr32(IGC_RAH(index), rah);
wr32(IGC_RAH(index), rar_high); }
wrfl();
/**
* igc_clear_mac_filter_hw() - Clear MAC address filter in hardware
* @adapter: Pointer to adapter where the filter should be cleared
* @index: Filter index
*/
static void igc_clear_mac_filter_hw(struct igc_adapter *adapter, int index)
{
struct igc_hw *hw = &adapter->hw;
if (WARN_ON(index >= hw->mac.rar_entry_count))
return;
wr32(IGC_RAL(index), 0);
wr32(IGC_RAH(index), 0);
} }
/* Set default MAC address for the PF in the first RAR entry */ /* Set default MAC address for the PF in the first RAR entry */
...@@ -811,7 +821,7 @@ static void igc_set_default_mac_filter(struct igc_adapter *adapter) ...@@ -811,7 +821,7 @@ static void igc_set_default_mac_filter(struct igc_adapter *adapter)
ether_addr_copy(mac_table->addr, adapter->hw.mac.addr); ether_addr_copy(mac_table->addr, adapter->hw.mac.addr);
mac_table->state = IGC_MAC_STATE_DEFAULT | IGC_MAC_STATE_IN_USE; mac_table->state = IGC_MAC_STATE_DEFAULT | IGC_MAC_STATE_IN_USE;
igc_rar_set_index(adapter, 0); igc_set_mac_filter_hw(adapter, 0, mac_table->addr, -1);
} }
/** /**
...@@ -2198,7 +2208,7 @@ static int igc_add_mac_filter(struct igc_adapter *adapter, const u8 *addr, ...@@ -2198,7 +2208,7 @@ static int igc_add_mac_filter(struct igc_adapter *adapter, const u8 *addr,
int rar_entries = hw->mac.rar_entry_count; int rar_entries = hw->mac.rar_entry_count;
int i; int i;
if (is_zero_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;
...@@ -2216,7 +2226,7 @@ static int igc_add_mac_filter(struct igc_adapter *adapter, const u8 *addr, ...@@ -2216,7 +2226,7 @@ static int igc_add_mac_filter(struct igc_adapter *adapter, const u8 *addr,
adapter->mac_table[i].queue = queue; adapter->mac_table[i].queue = queue;
adapter->mac_table[i].state |= IGC_MAC_STATE_IN_USE | flags; adapter->mac_table[i].state |= IGC_MAC_STATE_IN_USE | flags;
igc_rar_set_index(adapter, i); igc_set_mac_filter_hw(adapter, i, addr, queue);
return 0; return 0;
} }
...@@ -2260,13 +2270,14 @@ static int igc_del_mac_filter(struct igc_adapter *adapter, const u8 *addr, ...@@ -2260,13 +2270,14 @@ static int igc_del_mac_filter(struct igc_adapter *adapter, const u8 *addr,
adapter->mac_table[i].state = adapter->mac_table[i].state =
IGC_MAC_STATE_DEFAULT | IGC_MAC_STATE_IN_USE; IGC_MAC_STATE_DEFAULT | IGC_MAC_STATE_IN_USE;
adapter->mac_table[i].queue = 0; adapter->mac_table[i].queue = 0;
igc_set_mac_filter_hw(adapter, 0, addr, -1);
} else { } else {
adapter->mac_table[i].state = 0; adapter->mac_table[i].state = 0;
adapter->mac_table[i].queue = 0; adapter->mac_table[i].queue = 0;
memset(adapter->mac_table[i].addr, 0, ETH_ALEN); memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
igc_clear_mac_filter_hw(adapter, i);
} }
igc_rar_set_index(adapter, i);
return 0; 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