Skip to content

Commit 91cdda4

Browse files
Vasundhara Volamdavem330
authored andcommitted
bnxt_en: Forward VF MAC address to the PF.
Forward hwrm_func_vf_cfg command from VF to PF driver, to store VF MAC address in PF's context. This will allow "ip link show" to display all VF MAC addresses. Maintain 2 locations of MAC address in VF info structure, one for a PF assigned MAC and one for VF assigned MAC. Display VF assigned MAC in "ip link show", only if PF assigned MAC is not valid. Signed-off-by: Vasundhara Volam <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 92abef3 commit 91cdda4

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl);
213213

214214
static const u16 bnxt_vf_req_snif[] = {
215215
HWRM_FUNC_CFG,
216+
HWRM_FUNC_VF_CFG,
216217
HWRM_PORT_PHY_QCFG,
217218
HWRM_CFA_L2_FILTER_ALLOC,
218219
};
@@ -8432,7 +8433,7 @@ static int bnxt_init_mac_addr(struct bnxt *bp)
84328433
struct bnxt_vf_info *vf = &bp->vf;
84338434

84348435
if (is_valid_ether_addr(vf->mac_addr)) {
8435-
/* overwrite netdev dev_adr with admin VF MAC */
8436+
/* overwrite netdev dev_addr with admin VF MAC */
84368437
memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN);
84378438
} else {
84388439
eth_hw_addr_random(bp->dev);

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,10 @@ struct bnxt_hw_resc {
804804
#if defined(CONFIG_BNXT_SRIOV)
805805
struct bnxt_vf_info {
806806
u16 fw_fid;
807-
u8 mac_addr[ETH_ALEN];
807+
u8 mac_addr[ETH_ALEN]; /* PF assigned MAC Address */
808+
u8 vf_mac_addr[ETH_ALEN]; /* VF assigned MAC address, only
809+
* stored by PF.
810+
*/
808811
u16 vlan;
809812
u32 flags;
810813
#define BNXT_VF_QOS 0x1

drivers/net/ethernet/broadcom/bnxt/bnxt_sriov.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ int bnxt_get_vf_config(struct net_device *dev, int vf_id,
135135
ivi->vf = vf_id;
136136
vf = &bp->pf.vf[vf_id];
137137

138-
memcpy(&ivi->mac, vf->mac_addr, ETH_ALEN);
138+
if (is_valid_ether_addr(vf->mac_addr))
139+
memcpy(&ivi->mac, vf->mac_addr, ETH_ALEN);
140+
else
141+
memcpy(&ivi->mac, vf->vf_mac_addr, ETH_ALEN);
139142
ivi->max_tx_rate = vf->max_tx_rate;
140143
ivi->min_tx_rate = vf->min_tx_rate;
141144
ivi->vlan = vf->vlan;
@@ -883,17 +886,51 @@ static int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, struct bnxt_vf_info *vf,
883886
return rc;
884887
}
885888

889+
static int bnxt_vf_store_mac(struct bnxt *bp, struct bnxt_vf_info *vf)
890+
{
891+
u32 msg_size = sizeof(struct hwrm_func_vf_cfg_input);
892+
struct hwrm_func_vf_cfg_input *req =
893+
(struct hwrm_func_vf_cfg_input *)vf->hwrm_cmd_req_addr;
894+
895+
/* Only allow VF to set a valid MAC address if the PF assigned MAC
896+
* address is zero
897+
*/
898+
if (req->enables & cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_DFLT_MAC_ADDR)) {
899+
if (is_valid_ether_addr(req->dflt_mac_addr) &&
900+
!is_valid_ether_addr(vf->mac_addr)) {
901+
ether_addr_copy(vf->vf_mac_addr, req->dflt_mac_addr);
902+
return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size);
903+
}
904+
return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size);
905+
}
906+
return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size);
907+
}
908+
886909
static int bnxt_vf_validate_set_mac(struct bnxt *bp, struct bnxt_vf_info *vf)
887910
{
888911
u32 msg_size = sizeof(struct hwrm_cfa_l2_filter_alloc_input);
889912
struct hwrm_cfa_l2_filter_alloc_input *req =
890913
(struct hwrm_cfa_l2_filter_alloc_input *)vf->hwrm_cmd_req_addr;
914+
bool mac_ok = false;
891915

892-
if (!is_valid_ether_addr(vf->mac_addr) ||
893-
ether_addr_equal((const u8 *)req->l2_addr, vf->mac_addr))
916+
/* VF MAC address must first match PF MAC address, if it is valid.
917+
* Otherwise, it must match the VF MAC address if firmware spec >=
918+
* 1.2.2
919+
*/
920+
if (is_valid_ether_addr(vf->mac_addr)) {
921+
if (ether_addr_equal((const u8 *)req->l2_addr, vf->mac_addr))
922+
mac_ok = true;
923+
} else if (is_valid_ether_addr(vf->vf_mac_addr)) {
924+
if (ether_addr_equal((const u8 *)req->l2_addr, vf->vf_mac_addr))
925+
mac_ok = true;
926+
} else if (bp->hwrm_spec_code < 0x10202) {
927+
mac_ok = true;
928+
} else {
929+
mac_ok = true;
930+
}
931+
if (mac_ok)
894932
return bnxt_hwrm_exec_fwd_resp(bp, vf, msg_size);
895-
else
896-
return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size);
933+
return bnxt_hwrm_fwd_err_resp(bp, vf, msg_size);
897934
}
898935

899936
static int bnxt_vf_set_link(struct bnxt *bp, struct bnxt_vf_info *vf)
@@ -955,6 +992,9 @@ static int bnxt_vf_req_validate_snd(struct bnxt *bp, struct bnxt_vf_info *vf)
955992
u32 req_type = le16_to_cpu(encap_req->req_type);
956993

957994
switch (req_type) {
995+
case HWRM_FUNC_VF_CFG:
996+
rc = bnxt_vf_store_mac(bp, vf);
997+
break;
958998
case HWRM_CFA_L2_FILTER_ALLOC:
959999
rc = bnxt_vf_validate_set_mac(bp, vf);
9601000
break;

0 commit comments

Comments
 (0)