Commit 61f723e6 authored by Przemek Kitszel's avatar Przemek Kitszel Committed by Tony Nguyen
Browse files

iavf: fix err handling for MAC replace

Defer removal of current primary MAC until a replacement is successfully
added. Previous implementation would left filter list with no primary MAC.
This was found while reading the code.

The patch takes advantage of the fact that there can only be a single primary
MAC filter at any time ([1] by Piotr)

Piotr has also applied some review suggestions during our internal patch
submittal process.

[1] https://lore.kernel.org/netdev/20230614145302.902301-2-piotrx.gardocki@intel.com/



Reviewed-by: default avatarMichal Swiatkowski <michal.swiatkowski@linux.intel.com>
Tested-by: default avatarRafal Romanowski <rafal.romanowski@intel.com>
Signed-off-by: default avatarPiotr Gardocki <piotrx.gardocki@intel.com>
Signed-off-by: default avatarPrzemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: default avatarMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent 98e95872
Loading
Loading
Loading
Loading
+19 −23
Original line number Diff line number Diff line
@@ -1007,41 +1007,37 @@ int iavf_replace_primary_mac(struct iavf_adapter *adapter,
			     const u8 *new_mac)
{
	struct iavf_hw *hw = &adapter->hw;
	struct iavf_mac_filter *f;
	struct iavf_mac_filter *new_f;
	struct iavf_mac_filter *old_f;

	spin_lock_bh(&adapter->mac_vlan_list_lock);

	list_for_each_entry(f, &adapter->mac_filter_list, list) {
		f->is_primary = false;
	new_f = iavf_add_filter(adapter, new_mac);
	if (!new_f) {
		spin_unlock_bh(&adapter->mac_vlan_list_lock);
		return -ENOMEM;
	}

	f = iavf_find_filter(adapter, hw->mac.addr);
	if (f) {
		f->remove = true;
	old_f = iavf_find_filter(adapter, hw->mac.addr);
	if (old_f) {
		old_f->is_primary = false;
		old_f->remove = true;
		adapter->aq_required |= IAVF_FLAG_AQ_DEL_MAC_FILTER;
	}

	f = iavf_add_filter(adapter, new_mac);

	if (f) {
		/* Always send the request to add if changing primary MAC
	/* Always send the request to add if changing primary MAC,
	 * even if filter is already present on the list
	 */
		f->is_primary = true;
		f->add = true;
	new_f->is_primary = true;
	new_f->add = true;
	adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER;
	ether_addr_copy(hw->mac.addr, new_mac);
	}

	spin_unlock_bh(&adapter->mac_vlan_list_lock);

	/* schedule the watchdog task to immediately process the request */
	if (f) {
	mod_delayed_work(adapter->wq, &adapter->watchdog_task, 0);
	return 0;
}
	return -ENOMEM;
}

/**
 * iavf_is_mac_set_handled - wait for a response to set MAC from PF