Commit 6af3d0fa authored by Tony Nguyen's avatar Tony Nguyen Committed by Jeff Kirsher

ixgbe: Add error checking to setting VF MAC

Currently, when setting a VF MAC address there are no error checks to
ensure that the MAC filter was successfully added.  This patch adds
additional error checks, reporting, and propagation of errors.  It also
will not set the MAC address unless adding the MAC filter was successful.

With these changes, setting the mac address to zeros can no longer call
ixgbe_set_vf_mac() as adding a zero MAC address filter is not valid.
Instead directly delete the filter and, if successful, clear the MAC
address.
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 22cb4fff
...@@ -778,11 +778,17 @@ static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf) ...@@ -778,11 +778,17 @@ static inline void ixgbe_vf_reset_event(struct ixgbe_adapter *adapter, u32 vf)
static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter, static int ixgbe_set_vf_mac(struct ixgbe_adapter *adapter,
int vf, unsigned char *mac_addr) int vf, unsigned char *mac_addr)
{ {
s32 retval;
ixgbe_del_mac_filter(adapter, adapter->vfinfo[vf].vf_mac_addresses, vf); ixgbe_del_mac_filter(adapter, adapter->vfinfo[vf].vf_mac_addresses, vf);
memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr, ETH_ALEN); retval = ixgbe_add_mac_filter(adapter, mac_addr, vf);
ixgbe_add_mac_filter(adapter, adapter->vfinfo[vf].vf_mac_addresses, vf); if (retval >= 0)
memcpy(adapter->vfinfo[vf].vf_mac_addresses, mac_addr,
ETH_ALEN);
else
memset(adapter->vfinfo[vf].vf_mac_addresses, 0, ETH_ALEN);
return 0; return retval;
} }
int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask) int ixgbe_vf_configuration(struct pci_dev *pdev, unsigned int event_mask)
...@@ -1347,27 +1353,49 @@ void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter) ...@@ -1347,27 +1353,49 @@ void ixgbe_ping_all_vfs(struct ixgbe_adapter *adapter)
int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac) int ixgbe_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
{ {
struct ixgbe_adapter *adapter = netdev_priv(netdev); struct ixgbe_adapter *adapter = netdev_priv(netdev);
s32 retval;
if (vf >= adapter->num_vfs) if (vf >= adapter->num_vfs)
return -EINVAL; return -EINVAL;
if (is_zero_ether_addr(mac)) { if (is_valid_ether_addr(mac)) {
adapter->vfinfo[vf].pf_set_mac = false;
dev_info(&adapter->pdev->dev, "removing MAC on VF %d\n", vf);
} else if (is_valid_ether_addr(mac)) {
adapter->vfinfo[vf].pf_set_mac = true;
dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n",
mac, vf); mac, vf);
dev_info(&adapter->pdev->dev, "Reload the VF driver to make this change effective."); dev_info(&adapter->pdev->dev, "Reload the VF driver to make this change effective.");
if (test_bit(__IXGBE_DOWN, &adapter->state)) {
dev_warn(&adapter->pdev->dev, "The VF MAC address has been set, but the PF device is not up.\n"); retval = ixgbe_set_vf_mac(adapter, vf, mac);
dev_warn(&adapter->pdev->dev, "Bring the PF device up before attempting to use the VF device.\n"); if (retval >= 0) {
adapter->vfinfo[vf].pf_set_mac = true;
if (test_bit(__IXGBE_DOWN, &adapter->state)) {
dev_warn(&adapter->pdev->dev, "The VF MAC address has been set, but the PF device is not up.\n");
dev_warn(&adapter->pdev->dev, "Bring the PF device up before attempting to use the VF device.\n");
}
} else {
dev_warn(&adapter->pdev->dev, "The VF MAC address was NOT set due to invalid or duplicate MAC address.\n");
}
} else if (is_zero_ether_addr(mac)) {
unsigned char *vf_mac_addr =
adapter->vfinfo[vf].vf_mac_addresses;
/* nothing to do */
if (is_zero_ether_addr(vf_mac_addr))
return 0;
dev_info(&adapter->pdev->dev, "removing MAC on VF %d\n", vf);
retval = ixgbe_del_mac_filter(adapter, vf_mac_addr, vf);
if (retval >= 0) {
adapter->vfinfo[vf].pf_set_mac = false;
memcpy(vf_mac_addr, mac, ETH_ALEN);
} else {
dev_warn(&adapter->pdev->dev, "Could NOT remove the VF MAC address.\n");
} }
} else { } else {
return -EINVAL; retval = -EINVAL;
} }
return ixgbe_set_vf_mac(adapter, vf, mac); return retval;
} }
static int ixgbe_enable_port_vlan(struct ixgbe_adapter *adapter, int vf, static int ixgbe_enable_port_vlan(struct ixgbe_adapter *adapter, int vf,
......
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