Skip to content

Commit 350e822

Browse files
bcreeley13Jeff Kirsher
authored andcommitted
ice: Add functions to rebuild host VLAN/MAC config for a VF
When resetting a VF the VLAN and MAC filter configurations need to be replayed. Add helper functions for this purpose. Signed-off-by: Brett Creeley <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent eb2af3e commit 350e822

File tree

1 file changed

+89
-32
lines changed

1 file changed

+89
-32
lines changed

drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c

Lines changed: 89 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,82 @@ static int ice_calc_vf_first_vector_idx(struct ice_pf *pf, struct ice_vf *vf)
540540
return pf->sriov_base_vector + vf->vf_id * pf->num_msix_per_vf;
541541
}
542542

543+
/**
544+
* ice_vf_rebuild_host_vlan_cfg - add VLAN 0 filter or rebuild the Port VLAN
545+
* @vf: VF to add MAC filters for
546+
*
547+
* Called after a VF VSI has been re-added/rebuilt during reset. The PF driver
548+
* always re-adds either a VLAN 0 or port VLAN based filter after reset.
549+
*/
550+
static int ice_vf_rebuild_host_vlan_cfg(struct ice_vf *vf)
551+
{
552+
struct ice_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
553+
struct device *dev = ice_pf_to_dev(vf->pf);
554+
u16 vlan_id = 0;
555+
int err;
556+
557+
if (vf->port_vlan_info) {
558+
err = ice_vsi_manage_pvid(vsi, vf->port_vlan_info, true);
559+
if (err) {
560+
dev_err(dev, "failed to configure port VLAN via VSI parameters for VF %u, error %d\n",
561+
vf->vf_id, err);
562+
return err;
563+
}
564+
565+
vlan_id = vf->port_vlan_info & VLAN_VID_MASK;
566+
}
567+
568+
/* vlan_id will either be 0 or the port VLAN number */
569+
err = ice_vsi_add_vlan(vsi, vlan_id, ICE_FWD_TO_VSI);
570+
if (err) {
571+
dev_err(dev, "failed to add %s VLAN %u filter for VF %u, error %d\n",
572+
vf->port_vlan_info ? "port" : "", vlan_id, vf->vf_id,
573+
err);
574+
return err;
575+
}
576+
577+
return 0;
578+
}
579+
580+
/**
581+
* ice_vf_rebuild_host_mac_cfg - add broadcast and the VF's perm_addr/LAA
582+
* @vf: VF to add MAC filters for
583+
*
584+
* Called after a VF VSI has been re-added/rebuilt during reset. The PF driver
585+
* always re-adds a broadcast filter and the VF's perm_addr/LAA after reset.
586+
*/
587+
static int ice_vf_rebuild_host_mac_cfg(struct ice_vf *vf)
588+
{
589+
struct ice_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
590+
struct device *dev = ice_pf_to_dev(vf->pf);
591+
enum ice_status status;
592+
u8 broadcast[ETH_ALEN];
593+
594+
eth_broadcast_addr(broadcast);
595+
status = ice_fltr_add_mac(vsi, broadcast, ICE_FWD_TO_VSI);
596+
if (status) {
597+
dev_err(dev, "failed to add broadcast MAC filter for VF %u, error %s\n",
598+
vf->vf_id, ice_stat_str(status));
599+
return ice_status_to_errno(status);
600+
}
601+
602+
vf->num_mac++;
603+
604+
if (is_valid_ether_addr(vf->dflt_lan_addr.addr)) {
605+
status = ice_fltr_add_mac(vsi, vf->dflt_lan_addr.addr,
606+
ICE_FWD_TO_VSI);
607+
if (status) {
608+
dev_err(dev, "failed to add default unicast MAC filter %pM for VF %u, error %s\n",
609+
&vf->dflt_lan_addr.addr[0], vf->vf_id,
610+
ice_stat_str(status));
611+
return ice_status_to_errno(status);
612+
}
613+
vf->num_mac++;
614+
}
615+
616+
return 0;
617+
}
618+
543619
/**
544620
* ice_alloc_vsi_res - Setup VF VSI and its resources
545621
* @vf: pointer to the VF structure
@@ -549,10 +625,9 @@ static int ice_calc_vf_first_vector_idx(struct ice_pf *pf, struct ice_vf *vf)
549625
static int ice_alloc_vsi_res(struct ice_vf *vf)
550626
{
551627
struct ice_pf *pf = vf->pf;
552-
u8 broadcast[ETH_ALEN];
553628
struct ice_vsi *vsi;
554629
struct device *dev;
555-
int status = 0;
630+
int ret;
556631

557632
dev = ice_pf_to_dev(pf);
558633
/* first vector index is the VFs OICR index */
@@ -567,38 +642,20 @@ static int ice_alloc_vsi_res(struct ice_vf *vf)
567642
vf->lan_vsi_idx = vsi->idx;
568643
vf->lan_vsi_num = vsi->vsi_num;
569644

570-
/* Check if port VLAN exist before, and restore it accordingly */
571-
if (vf->port_vlan_info) {
572-
ice_vsi_manage_pvid(vsi, vf->port_vlan_info, true);
573-
if (ice_vsi_add_vlan(vsi, vf->port_vlan_info & VLAN_VID_MASK,
574-
ICE_FWD_TO_VSI))
575-
dev_warn(ice_pf_to_dev(pf), "Failed to add Port VLAN %d filter for VF %d\n",
576-
vf->port_vlan_info & VLAN_VID_MASK, vf->vf_id);
577-
} else {
578-
/* set VLAN 0 filter by default when no port VLAN is
579-
* enabled. If a port VLAN is enabled we don't want
580-
* untagged broadcast/multicast traffic seen on the VF
581-
* interface.
582-
*/
583-
if (ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI))
584-
dev_warn(ice_pf_to_dev(pf), "Failed to add VLAN 0 filter for VF %d, MDD events will trigger. Reset the VF, disable spoofchk, or enable 8021q module on the guest\n",
585-
vf->vf_id);
645+
ret = ice_vf_rebuild_host_vlan_cfg(vf);
646+
if (ret) {
647+
dev_err(dev, "failed to rebuild default MAC configuration for VF %d, error %d\n",
648+
vf->vf_id, ret);
649+
goto ice_alloc_vsi_res_exit;
586650
}
587651

588-
if (is_valid_ether_addr(vf->dflt_lan_addr.addr)) {
589-
status = ice_fltr_add_mac(vsi, vf->dflt_lan_addr.addr,
590-
ICE_FWD_TO_VSI);
591-
if (status)
592-
goto ice_alloc_vsi_res_exit;
593-
}
594652

595-
eth_broadcast_addr(broadcast);
596-
status = ice_fltr_add_mac(vsi, broadcast, ICE_FWD_TO_VSI);
597-
if (status)
598-
dev_err(dev, "could not add mac filters error %d\n",
599-
status);
600-
else
601-
vf->num_mac = 1;
653+
ret = ice_vf_rebuild_host_mac_cfg(vf);
654+
if (ret) {
655+
dev_err(dev, "failed to rebuild default MAC configuration for VF %d, error %d\n",
656+
vf->vf_id, ret);
657+
goto ice_alloc_vsi_res_exit;
658+
}
602659

603660
/* Clear this bit after VF initialization since we shouldn't reclaim
604661
* and reassign interrupts for synchronous or asynchronous VFR events.
@@ -607,7 +664,7 @@ static int ice_alloc_vsi_res(struct ice_vf *vf)
607664
* more vectors.
608665
*/
609666
ice_alloc_vsi_res_exit:
610-
return status;
667+
return ret;
611668
}
612669

613670
/**

0 commit comments

Comments
 (0)