/* Remove all VFs from the hash table and release their main *reference.OnceallreferencestotheVFaredropped,ice_put_vf() *willcallice_release_vfwhichwillremovetheVFmemory.
*/
lockdep_assert_held(&vfs->table_lock);
/** *ice_free_vf_res-FreeaVF'sresources *@vf:pointertotheVFinfo
*/ staticvoid ice_free_vf_res(struct ice_vf *vf)
{ struct ice_pf *pf = vf->pf; int i, last_vector_idx;
/* First, disable VF's configuration API to prevent OS from *accessingtheVF'sVSIafterit'sfreedorinvalidated.
*/
clear_bit(ICE_VF_STATE_INIT, vf->vf_states);
ice_vf_fdir_exit(vf); /* free VF control VSI */ if (vf->ctrl_vsi_idx != ICE_NO_VSI)
ice_vf_ctrl_vsi_release(vf);
/* free VSI and disconnect it from the parent uplink */ if (vf->lan_vsi_idx != ICE_NO_VSI) {
ice_vf_vsi_release(vf);
vf->num_mac = 0;
vf->num_mac_lldp = 0;
}
/* Disable interrupts so that VF starts in a known state */ for (i = vf->first_vector_idx; i <= last_vector_idx; i++) {
wr32(&pf->hw, GLINT_DYN_CTL(i), GLINT_DYN_CTL_CLEARPBA_M);
ice_flush(&pf->hw);
} /* reset some of the state variables keeping track of the resources */
clear_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states);
clear_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states);
}
if (vsi->tx_mapping_mode == ICE_VSI_MAP_CONTIG)
wr32(hw, VPLAN_TX_QBASE(vf->vf_id), 0); else
dev_err(dev, "Scattered mode for VF Tx queues is not yet implemented\n");
if (vsi->rx_mapping_mode == ICE_VSI_MAP_CONTIG)
wr32(hw, VPLAN_RX_QBASE(vf->vf_id), 0); else
dev_err(dev, "Scattered mode for VF Rx queues is not yet implemented\n");
}
while (test_and_set_bit(ICE_VF_DIS, pf->state))
usleep_range(1000, 2000);
/* Disable IOV before freeing resources. This lets any VF drivers *runninginthehostgetthemselvescleanedupbeforeweyank *thecarpetoutfromunderneaththeirfeet.
*/ if (!pci_vfs_assigned(pf->pdev))
pci_disable_sriov(pf->pdev); else
dev_warn(dev, "VFs are assigned - not disabling SR-IOV\n");
if (test_bit(ICE_VF_STATE_INIT, vf->vf_states)) { /* disable VF qp mappings and set VF disable state */
ice_dis_vf_mappings(vf);
set_bit(ICE_VF_STATE_DIS, vf->vf_states);
ice_free_vf_res(vf);
}
if (!pci_vfs_assigned(pf->pdev)) {
u32 reg_idx, bit_idx;
/* map the interrupts to its functions */ for (v = pf_based_first_msix; v <= pf_based_last_msix; v++) {
reg = FIELD_PREP(GLINT_VECT2FUNC_VF_NUM_M, device_based_vf_id) |
FIELD_PREP(GLINT_VECT2FUNC_PF_NUM_M, hw->pf_id);
wr32(hw, GLINT_VECT2FUNC(v), reg);
}
/* always add one to account for the OICR being the first MSIX */
q_vector->vf_reg_idx = q_vector->v_idx + ICE_NONQ_VECS_VF;
q_vector->reg_idx = vf->first_vector_idx + q_vector->vf_reg_idx;
}
if (num_txq < ICE_MIN_QS_PER_VF || num_rxq < ICE_MIN_QS_PER_VF) {
dev_err(dev, "Not enough queues to support minimum of %d queue pairs per VF for %d VFs\n",
ICE_MIN_QS_PER_VF, num_vfs); return -ENOSPC;
}
/* only allow equal Tx/Rx queue count (i.e. queue pairs) */
pf->vfs.num_qps_per = min_t(int, num_txq, num_rxq);
pf->vfs.num_msix_per = num_msix_per_vf;
dev_info(dev, "Enabling %d VFs with %d vectors and %d queues per VF\n",
num_vfs, pf->vfs.num_msix_per, pf->vfs.num_qps_per);
/* Clear the reset status register so that VF immediately sees that *thedeviceisresetting,evenifhardwarehasn'tyetgottenaround *toclearingVFGEN_RSTATforus.
*/
wr32(hw, VFGEN_RSTAT(vf->vf_id), VIRTCHNL_VFR_INPROGRESS);
}
/* In the case of a VFLR, HW has already reset the VF and we just need *tocleanup.Otherwisewemustfirsttriggertheresetusingthe *VFRTRIGregister.
*/ if (!is_vflr) {
reg = rd32(hw, VPGEN_VFRTRIG(vf->vf_id));
reg |= VPGEN_VFRTRIG_VFSWR_M;
wr32(hw, VPGEN_VFRTRIG(vf->vf_id), reg);
}
/* clear the VFLR bit in GLGEN_VFLRSTAT */
reg_idx = (vf_abs_id) / 32;
bit_idx = (vf_abs_id) % 32;
wr32(hw, GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
ice_flush(hw);
wr32(hw, PF_PCI_CIAA,
VF_DEVICE_STATUS | (vf_abs_id << PF_PCI_CIAA_VF_NUM_S)); for (i = 0; i < ICE_PCI_CIAD_WAIT_COUNT; i++) {
reg = rd32(hw, PF_PCI_CIAD); /* no transactions pending so stop polling */ if ((reg & VF_TRANS_PENDING_M) == 0) break;
for (i = 0; i < 10; i++) { /* VF reset requires driver to first reset the VF and then *pollthestatusregistertomakesurethatthereset *completedsuccessfully.
*/
reg = rd32(&pf->hw, VPGEN_VFRSTAT(vf->vf_id)); if (reg & VPGEN_VFRSTAT_VFRD_M) returntrue;
/* only sleep if the reset is not done */
usleep_range(10, 20);
} returnfalse;
}
/* set sriov vf ops for VFs created during SRIOV flow */
vf->vf_ops = &ice_sriov_vf_ops;
ice_initialize_vf_entry(vf);
do {
vfdev = pci_get_device(pdev->vendor, vf_pdev_id, vfdev);
} while (vfdev && vfdev->physfn != pdev);
vf->vfdev = vfdev;
vf->vf_sw_id = pf->first_sw;
pci_dev_get(vfdev);
hash_add_rcu(vfs->table, &vf->entry, vf_id);
}
/* Decrement of refcount done by pci_get_device() inside the loop does *nottouchthelastiteration'svfdev,soithastobedonemanually *tobalancepci_dev_get()addedwithintheloop.
*/
pci_dev_put(vfdev);
/* Disable global interrupt 0 so we don't try to handle the VFLR. */
wr32(hw, GLINT_DYN_CTL(pf->oicr_irq.index),
ICE_ITR_NONE << GLINT_DYN_CTL_ITR_INDX_S);
set_bit(ICE_OICR_INTR_DIS, pf->state);
ice_flush(hw);
ret = pci_enable_sriov(pf->pdev, num_vfs); if (ret) goto err_unroll_intr;
mutex_lock(&pf->vfs.table_lock);
ret = ice_set_per_vf_res(pf, num_vfs); if (ret) {
dev_err(dev, "Not enough resources for %d VFs, err %d. Try with fewer number of VFs\n",
num_vfs, ret); goto err_unroll_sriov;
}
ret = ice_create_vf_entries(pf, num_vfs); if (ret) {
dev_err(dev, "Failed to allocate VF entries for %d VFs\n",
num_vfs); goto err_unroll_sriov;
}
ret = ice_start_vfs(pf); if (ret) {
dev_err(dev, "Failed to start %d VFs, err %d\n", num_vfs, ret);
ret = -EAGAIN; goto err_unroll_vf_entries;
}
clear_bit(ICE_VF_DIS, pf->state);
/* rearm global interrupts */ if (test_and_clear_bit(ICE_OICR_INTR_DIS, pf->state))
ice_irq_dynamic_ena(hw, NULL, NULL);
/* For better irqs usage try to remap irqs of VFs *thataren'trunningyet
*/
ice_for_each_vf(pf, bkt, tmp_vf) { /* skip VF which is changing the number of MSI-X */ if (restricted_id == tmp_vf->vf_id ||
test_bit(ICE_VF_STATE_ACTIVE, tmp_vf->vf_states)) continue;
for (int i = 0; i < to_remap; i++) {
tmp_vf = ice_get_vf_by_id(pf, vf_ids[i]); if (!tmp_vf) continue;
tmp_vf->first_vector_idx =
ice_virt_get_irqs(pf, tmp_vf->num_msix); /* there is no need to rebuild VSI as we are only changing the *vectorindexesnotamountofMSI-Xorqueues
*/
ice_ena_vf_mappings(tmp_vf);
ice_put_vf(tmp_vf);
}
}
vf = ice_get_vf_by_id(pf, vf_id); if (!vf) return -EINVAL;
ret = ice_check_vf_ready_for_cfg(vf); if (ret) goto out_put_vf;
vf_vsi = ice_get_vf_vsi(vf); if (!vf_vsi) {
netdev_err(netdev, "VSI %d for VF %d is null\n",
vf->lan_vsi_idx, vf->vf_id);
ret = -EINVAL; goto out_put_vf;
}
if (vf_vsi->type != ICE_VSI_VF) {
netdev_err(netdev, "Type %d of VSI %d for VF %d is no ICE_VSI_VF\n",
vf_vsi->type, vf_vsi->vsi_num, vf->vf_id);
ret = -ENODEV; goto out_put_vf;
}
if (ena == vf->spoofchk) {
dev_dbg(dev, "VF spoofchk already %s\n", ena ? "ON" : "OFF");
ret = 0; goto out_put_vf;
}
ret = ice_vsi_apply_spoofchk(vf_vsi, ena); if (ret)
dev_err(dev, "Failed to set spoofchk %s for VF %d VSI %d\n error %d\n",
ena ? "ON" : "OFF", vf->vf_id, vf_vsi->vsi_num, ret); else
vf->spoofchk = ena;
out_put_vf:
ice_put_vf(vf); return ret;
}
/** *ice_get_vf_cfg *@netdev:networkinterfacedevicestructure *@vf_id:VFidentifier *@ivi:VFconfigurationstructure * *returnVFconfiguration
*/ int
ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi)
{ struct ice_pf *pf = ice_netdev_to_pf(netdev); struct ice_vf *vf; int ret;
vf = ice_get_vf_by_id(pf, vf_id); if (!vf) return -EINVAL;
ret = ice_check_vf_ready_for_cfg(vf); if (ret) goto out_put_vf;
dev = ice_pf_to_dev(pf); if (is_multicast_ether_addr(mac)) {
dev_err(dev, "%pM not a valid unicast address\n", mac); return -EINVAL;
}
vf = ice_get_vf_by_id(pf, vf_id); if (!vf) return -EINVAL;
/* nothing left to do, unicast MAC already set */ if (ether_addr_equal(vf->dev_lan_addr, mac) &&
ether_addr_equal(vf->hw_lan_addr, mac)) {
ret = 0; goto out_put_vf;
}
ret = ice_check_vf_ready_for_cfg(vf); if (ret) goto out_put_vf;
mutex_lock(&vf->cfg_lock);
/* VF is notified of its new MAC via the PF's response to the *VIRTCHNL_OP_GET_VF_RESOURCESmessageaftertheVFhasbeenreset
*/
ether_addr_copy(vf->dev_lan_addr, mac);
ether_addr_copy(vf->hw_lan_addr, mac); if (is_zero_ether_addr(mac)) { /* VF will send VIRTCHNL_OP_ADD_ETH_ADDR message with its MAC */
vf->pf_set_mac = false;
dev_info(dev, "Removing MAC on VF %d. VF driver will be reinitialized\n",
vf->vf_id);
} else { /* PF will add MAC rule for the VF */
vf->pf_set_mac = true;
dev_info(dev, "Setting MAC %pM on VF %d. VF driver will be reinitialized\n",
mac, vf_id);
}
/* this VF's previous rate is being overwritten */
all_vfs_min_tx_rate -= vf->min_tx_rate;
if (all_vfs_min_tx_rate + min_tx_rate > link_speed_mbps) {
dev_err(ice_pf_to_dev(vf->pf), "min_tx_rate of %d Mbps on VF %u would cause oversubscription of %d Mbps based on the current link speed %d Mbps\n",
min_tx_rate, vf->vf_id,
all_vfs_min_tx_rate + min_tx_rate - link_speed_mbps,
link_speed_mbps); returntrue;
}
returnfalse;
}
/** *ice_set_vf_bw-setmin/maxVFbandwidth *@netdev:networkinterfacedevicestructure *@vf_id:VFidentifier *@min_tx_rate:MinimumTxrateinMbps *@max_tx_rate:MaximumTxrateinMbps
*/ int
ice_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate, int max_tx_rate)
{ struct ice_pf *pf = ice_netdev_to_pf(netdev); struct ice_vsi *vsi; struct device *dev; struct ice_vf *vf; int ret;
dev = ice_pf_to_dev(pf);
vf = ice_get_vf_by_id(pf, vf_id); if (!vf) return -EINVAL;
ret = ice_check_vf_ready_for_cfg(vf); if (ret) goto out_put_vf;
vsi = ice_get_vf_vsi(vf); if (!vsi) {
ret = -EINVAL; goto out_put_vf;
}
if (min_tx_rate && ice_is_dcb_active(pf)) {
dev_err(dev, "DCB on PF is currently enabled. VF min Tx rate limiting not allowed on this PF.\n");
ret = -EOPNOTSUPP; goto out_put_vf;
}
if (ice_min_tx_rate_oversubscribed(vf, min_tx_rate)) {
ret = -EINVAL; goto out_put_vf;
}
if (vf->min_tx_rate != (unsignedint)min_tx_rate) {
ret = ice_set_min_bw_limit(vsi, (u64)min_tx_rate * 1000); if (ret) {
dev_err(dev, "Unable to set min-tx-rate for VF %d\n",
vf->vf_id); goto out_put_vf;
}
vf->min_tx_rate = min_tx_rate;
}
if (vf->max_tx_rate != (unsignedint)max_tx_rate) {
ret = ice_set_max_bw_limit(vsi, (u64)max_tx_rate * 1000); if (ret) {
dev_err(dev, "Unable to set max-tx-rate for VF %d\n",
vf->vf_id); goto out_put_vf;
}
/* check that there are pending MDD events to print */ if (!test_and_clear_bit(ICE_MDD_VF_PRINT_PENDING, pf->state)) return;
/* VF MDD event logs are rate limited to one second intervals */ if (time_is_after_jiffies(pf->vfs.last_printed_mdd_jiffies + HZ * 1)) return;
pf->vfs.last_printed_mdd_jiffies = jiffies;
mutex_lock(&pf->vfs.table_lock);
ice_for_each_vf(pf, bkt, vf) { /* only print Rx MDD event message if there are new events */ if (vf->mdd_rx_events.count != vf->mdd_rx_events.last_printed) {
vf->mdd_rx_events.last_printed =
vf->mdd_rx_events.count;
ice_print_vf_rx_mdd_event(vf);
}
/* only print Tx MDD event message if there are new events */ if (vf->mdd_tx_events.count != vf->mdd_tx_events.last_printed) {
vf->mdd_tx_events.last_printed =
vf->mdd_tx_events.count;
ice_print_vf_tx_mdd_event(vf);
}
}
mutex_unlock(&pf->vfs.table_lock);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.