ice: Add functions to rebuild host VLAN/MAC config for a VF
authorBrett Creeley <brett.creeley@intel.com>
Sat, 16 May 2020 00:51:13 +0000 (17:51 -0700)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Thu, 28 May 2020 23:10:02 +0000 (16:10 -0700)
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 <brett.creeley@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c

index 4005a4c..3a714c8 100644 (file)
@@ -541,6 +541,82 @@ static int ice_calc_vf_first_vector_idx(struct ice_pf *pf, struct ice_vf *vf)
 }
 
 /**
+ * ice_vf_rebuild_host_vlan_cfg - add VLAN 0 filter or rebuild the Port VLAN
+ * @vf: VF to add MAC filters for
+ *
+ * Called after a VF VSI has been re-added/rebuilt during reset. The PF driver
+ * always re-adds either a VLAN 0 or port VLAN based filter after reset.
+ */
+static int ice_vf_rebuild_host_vlan_cfg(struct ice_vf *vf)
+{
+       struct ice_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
+       struct device *dev = ice_pf_to_dev(vf->pf);
+       u16 vlan_id = 0;
+       int err;
+
+       if (vf->port_vlan_info) {
+               err = ice_vsi_manage_pvid(vsi, vf->port_vlan_info, true);
+               if (err) {
+                       dev_err(dev, "failed to configure port VLAN via VSI parameters for VF %u, error %d\n",
+                               vf->vf_id, err);
+                       return err;
+               }
+
+               vlan_id = vf->port_vlan_info & VLAN_VID_MASK;
+       }
+
+       /* vlan_id will either be 0 or the port VLAN number */
+       err = ice_vsi_add_vlan(vsi, vlan_id, ICE_FWD_TO_VSI);
+       if (err) {
+               dev_err(dev, "failed to add %s VLAN %u filter for VF %u, error %d\n",
+                       vf->port_vlan_info ? "port" : "", vlan_id, vf->vf_id,
+                       err);
+               return err;
+       }
+
+       return 0;
+}
+
+/**
+ * ice_vf_rebuild_host_mac_cfg - add broadcast and the VF's perm_addr/LAA
+ * @vf: VF to add MAC filters for
+ *
+ * Called after a VF VSI has been re-added/rebuilt during reset. The PF driver
+ * always re-adds a broadcast filter and the VF's perm_addr/LAA after reset.
+ */
+static int ice_vf_rebuild_host_mac_cfg(struct ice_vf *vf)
+{
+       struct ice_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
+       struct device *dev = ice_pf_to_dev(vf->pf);
+       enum ice_status status;
+       u8 broadcast[ETH_ALEN];
+
+       eth_broadcast_addr(broadcast);
+       status = ice_fltr_add_mac(vsi, broadcast, ICE_FWD_TO_VSI);
+       if (status) {
+               dev_err(dev, "failed to add broadcast MAC filter for VF %u, error %s\n",
+                       vf->vf_id, ice_stat_str(status));
+               return ice_status_to_errno(status);
+       }
+
+       vf->num_mac++;
+
+       if (is_valid_ether_addr(vf->dflt_lan_addr.addr)) {
+               status = ice_fltr_add_mac(vsi, vf->dflt_lan_addr.addr,
+                                         ICE_FWD_TO_VSI);
+               if (status) {
+                       dev_err(dev, "failed to add default unicast MAC filter %pM for VF %u, error %s\n",
+                               &vf->dflt_lan_addr.addr[0], vf->vf_id,
+                               ice_stat_str(status));
+                       return ice_status_to_errno(status);
+               }
+               vf->num_mac++;
+       }
+
+       return 0;
+}
+
+/**
  * ice_alloc_vsi_res - Setup VF VSI and its resources
  * @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)
 static int ice_alloc_vsi_res(struct ice_vf *vf)
 {
        struct ice_pf *pf = vf->pf;
-       u8 broadcast[ETH_ALEN];
        struct ice_vsi *vsi;
        struct device *dev;
-       int status = 0;
+       int ret;
 
        dev = ice_pf_to_dev(pf);
        /* first vector index is the VFs OICR index */
@@ -567,38 +642,20 @@ static int ice_alloc_vsi_res(struct ice_vf *vf)
        vf->lan_vsi_idx = vsi->idx;
        vf->lan_vsi_num = vsi->vsi_num;
 
-       /* Check if port VLAN exist before, and restore it accordingly */
-       if (vf->port_vlan_info) {
-               ice_vsi_manage_pvid(vsi, vf->port_vlan_info, true);
-               if (ice_vsi_add_vlan(vsi, vf->port_vlan_info & VLAN_VID_MASK,
-                                    ICE_FWD_TO_VSI))
-                       dev_warn(ice_pf_to_dev(pf), "Failed to add Port VLAN %d filter for VF %d\n",
-                                vf->port_vlan_info & VLAN_VID_MASK, vf->vf_id);
-       } else {
-               /* set VLAN 0 filter by default when no port VLAN is
-                * enabled. If a port VLAN is enabled we don't want
-                * untagged broadcast/multicast traffic seen on the VF
-                * interface.
-                */
-               if (ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI))
-                       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",
-                                vf->vf_id);
+       ret = ice_vf_rebuild_host_vlan_cfg(vf);
+       if (ret) {
+               dev_err(dev, "failed to rebuild default MAC configuration for VF %d, error %d\n",
+                       vf->vf_id, ret);
+               goto ice_alloc_vsi_res_exit;
        }
 
-       if (is_valid_ether_addr(vf->dflt_lan_addr.addr)) {
-               status = ice_fltr_add_mac(vsi, vf->dflt_lan_addr.addr,
-                                         ICE_FWD_TO_VSI);
-               if (status)
-                       goto ice_alloc_vsi_res_exit;
-       }
 
-       eth_broadcast_addr(broadcast);
-       status = ice_fltr_add_mac(vsi, broadcast, ICE_FWD_TO_VSI);
-       if (status)
-               dev_err(dev, "could not add mac filters error %d\n",
-                       status);
-       else
-               vf->num_mac = 1;
+       ret = ice_vf_rebuild_host_mac_cfg(vf);
+       if (ret) {
+               dev_err(dev, "failed to rebuild default MAC configuration for VF %d, error %d\n",
+                       vf->vf_id, ret);
+               goto ice_alloc_vsi_res_exit;
+       }
 
        /* Clear this bit after VF initialization since we shouldn't reclaim
         * and reassign interrupts for synchronous or asynchronous VFR events.
@@ -607,7 +664,7 @@ static int ice_alloc_vsi_res(struct ice_vf *vf)
         * more vectors.
         */
 ice_alloc_vsi_res_exit:
-       return status;
+       return ret;
 }
 
 /**