Commit bdd4347b authored by Jeffrey Huang's avatar Jeffrey Huang Committed by David S. Miller

bnxt_en: enforce proper storing of MAC address

For PF, the bp->pf.mac_addr always holds the permanent MAC
addr assigned by the HW.  For VF, the bp->vf.mac_addr always
holds the administrator assigned VF MAC addr. The random
generated VF MAC addr should never get stored to bp->vf.mac_addr.
This way, when the VF wants to change the MAC address, we can tell
if the adminstrator has already set it and disallow the VF from
changing it.

v2: Fix compile error if CONFIG_BNXT_SRIOV is not set.
Signed-off-by: default avatarJeffrey Huang <huangjw@broadcom.com>
Signed-off-by: default avatarMichael Chan <mchan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1fc2cfd0
...@@ -3625,6 +3625,7 @@ static int bnxt_hwrm_func_qcaps(struct bnxt *bp) ...@@ -3625,6 +3625,7 @@ static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
pf->fw_fid = le16_to_cpu(resp->fid); pf->fw_fid = le16_to_cpu(resp->fid);
pf->port_id = le16_to_cpu(resp->port_id); pf->port_id = le16_to_cpu(resp->port_id);
memcpy(pf->mac_addr, resp->perm_mac_address, ETH_ALEN); memcpy(pf->mac_addr, resp->perm_mac_address, ETH_ALEN);
memcpy(bp->dev->dev_addr, pf->mac_addr, ETH_ALEN);
pf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); pf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
pf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); pf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
pf->max_tx_rings = le16_to_cpu(resp->max_tx_rings); pf->max_tx_rings = le16_to_cpu(resp->max_tx_rings);
...@@ -3648,8 +3649,11 @@ static int bnxt_hwrm_func_qcaps(struct bnxt *bp) ...@@ -3648,8 +3649,11 @@ static int bnxt_hwrm_func_qcaps(struct bnxt *bp)
vf->fw_fid = le16_to_cpu(resp->fid); vf->fw_fid = le16_to_cpu(resp->fid);
memcpy(vf->mac_addr, resp->perm_mac_address, ETH_ALEN); memcpy(vf->mac_addr, resp->perm_mac_address, ETH_ALEN);
if (!is_valid_ether_addr(vf->mac_addr)) if (is_valid_ether_addr(vf->mac_addr))
random_ether_addr(vf->mac_addr); /* overwrite netdev dev_adr with admin VF MAC */
memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
else
random_ether_addr(bp->dev->dev_addr);
vf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); vf->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx);
vf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); vf->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings);
...@@ -5218,6 +5222,11 @@ static int bnxt_change_mac_addr(struct net_device *dev, void *p) ...@@ -5218,6 +5222,11 @@ static int bnxt_change_mac_addr(struct net_device *dev, void *p)
if (!is_valid_ether_addr(addr->sa_data)) if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
#ifdef CONFIG_BNXT_SRIOV
if (BNXT_VF(bp) && is_valid_ether_addr(bp->vf.mac_addr))
return -EADDRNOTAVAIL;
#endif
if (ether_addr_equal(addr->sa_data, dev->dev_addr)) if (ether_addr_equal(addr->sa_data, dev->dev_addr))
return 0; return 0;
...@@ -5695,15 +5704,12 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -5695,15 +5704,12 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
bnxt_set_tpa_flags(bp); bnxt_set_tpa_flags(bp);
bnxt_set_ring_params(bp); bnxt_set_ring_params(bp);
dflt_rings = netif_get_num_default_rss_queues(); dflt_rings = netif_get_num_default_rss_queues();
if (BNXT_PF(bp)) { if (BNXT_PF(bp))
memcpy(dev->dev_addr, bp->pf.mac_addr, ETH_ALEN);
bp->pf.max_irqs = max_irqs; bp->pf.max_irqs = max_irqs;
} else {
#if defined(CONFIG_BNXT_SRIOV) #if defined(CONFIG_BNXT_SRIOV)
memcpy(dev->dev_addr, bp->vf.mac_addr, ETH_ALEN); else
bp->vf.max_irqs = max_irqs; bp->vf.max_irqs = max_irqs;
#endif #endif
}
bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings); bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings);
bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings); bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings);
bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings); bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings);
......
...@@ -804,10 +804,9 @@ void bnxt_update_vf_mac(struct bnxt *bp) ...@@ -804,10 +804,9 @@ void bnxt_update_vf_mac(struct bnxt *bp)
if (!is_valid_ether_addr(resp->perm_mac_address)) if (!is_valid_ether_addr(resp->perm_mac_address))
goto update_vf_mac_exit; goto update_vf_mac_exit;
if (ether_addr_equal(resp->perm_mac_address, bp->vf.mac_addr)) if (!ether_addr_equal(resp->perm_mac_address, bp->vf.mac_addr))
goto update_vf_mac_exit; memcpy(bp->vf.mac_addr, resp->perm_mac_address, ETH_ALEN);
/* overwrite netdev dev_adr with admin VF MAC */
memcpy(bp->vf.mac_addr, resp->perm_mac_address, ETH_ALEN);
memcpy(bp->dev->dev_addr, bp->vf.mac_addr, ETH_ALEN); memcpy(bp->dev->dev_addr, bp->vf.mac_addr, ETH_ALEN);
update_vf_mac_exit: update_vf_mac_exit:
mutex_unlock(&bp->hwrm_cmd_lock); mutex_unlock(&bp->hwrm_cmd_lock);
......
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