for (i = 0; i < pf->num_alloc_vfs; i++, vf++) { int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id; /* Not all vfs are enabled so skip the ones that are not */ if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states) &&
!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) continue;
/* Ignore return value on purpose - a given VF may fail, but *weneedtokeepgoingandsendtoallofthem
*/
i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
msg, msglen, NULL);
}
}
/** *i40e_vc_link_speed2mbps *convertsi40e_aq_link_speedtointegervalueofMbps *@link_speed:thespeedtoconvert * *returnthespeedasdirectvalueofMbps.
**/ static u32
i40e_vc_link_speed2mbps(enum i40e_aq_link_speed link_speed)
{ switch (link_speed) { case I40E_LINK_SPEED_100MB: return SPEED_100; case I40E_LINK_SPEED_1GB: return SPEED_1000; case I40E_LINK_SPEED_2_5GB: return SPEED_2500; case I40E_LINK_SPEED_5GB: return SPEED_5000; case I40E_LINK_SPEED_10GB: return SPEED_10000; case I40E_LINK_SPEED_20GB: return SPEED_20000; case I40E_LINK_SPEED_25GB: return SPEED_25000; case I40E_LINK_SPEED_40GB: return SPEED_40000; case I40E_LINK_SPEED_UNKNOWN: return SPEED_UNKNOWN;
} return SPEED_UNKNOWN;
}
/* validate the request */ if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs) return;
/* verify if the VF is in either init or active before proceeding */ if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states) &&
!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) return;
/* We want to ensure that an actual reset occurs initiated after this *functionwascalled.However,wedonotwanttowaitforever,so *we'llgiveareasonabletimeandprintamessageifwefailedto *ensureareset.
*/ for (i = 0; i < 20; i++) { /* If PF is in VFs releasing state reset VF is impossible, *soleaveit.
*/ if (test_bit(__I40E_VFS_RELEASING, pf->state)) return; if (i40e_reset_vf(vf, false)) return;
usleep_range(10000, 20000);
}
if (notify_vf)
dev_warn(&vf->pf->pdev->dev, "Failed to initiate reset for VF %d after 200 milliseconds\n",
vf->vf_id); else
dev_dbg(&vf->pf->pdev->dev, "Failed to initiate reset for VF %d after 200 milliseconds\n",
vf->vf_id);
}
if (vf->adq_enabled) { /* Although VF considers all the queues(can be 1 to 16) as its *ownbuttheymayactuallybelongtodifferentVSIs(upto4). *WeneedtofindwhichqueuesbelongstowhichVSI.
*/ for (i = 0; i < vf->num_tc; i++) { if (queue_id < vf->ch[i].num_qps) {
vsi_id = vf->ch[i].vsi_id; break;
} /* find right queue id which is relative to a *givenVSI.
*/
queue_id -= vf->ch[i].num_qps;
}
}
if (qvlist_info->num_vectors > msix_vf) {
dev_warn(&pf->pdev->dev, "Incorrect number of iwarp vectors %u. Maximum %u allowed.\n",
qvlist_info->num_vectors,
msix_vf);
ret = -EINVAL; goto err_out;
}
if (!i40e_vc_isvalid_vsi_id(vf, info->vsi_id)) {
ret = -ENOENT; goto error_context;
}
pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
vsi = i40e_find_vsi_from_id(pf, vsi_id); if (!vsi) {
ret = -ENOENT; goto error_context;
}
/* clear the context structure first */
memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
/* only set the required fields */
tx_ctx.base = info->dma_ring_addr / 128;
/* ring_len has to be multiple of 8 */ if (!IS_ALIGNED(info->ring_len, 8) ||
info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) {
ret = -EINVAL; goto error_context;
}
tx_ctx.qlen = info->ring_len;
tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
tx_ctx.rdylist_act = 0;
tx_ctx.head_wb_ena = info->headwb_enabled;
tx_ctx.head_wb_addr = info->dma_headwb_addr;
/* clear the context in the HMC */
ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id); if (ret) {
dev_err(&pf->pdev->dev, "Failed to clear VF LAN Tx queue context %d, error: %d\n",
pf_queue_id, ret);
ret = -ENOENT; goto error_context;
}
/* set the context in the HMC */
ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx); if (ret) {
dev_err(&pf->pdev->dev, "Failed to set VF LAN Tx queue context %d error: %d\n",
pf_queue_id, ret);
ret = -ENOENT; goto error_context;
}
/* associate this queue with the PCI VF function */
qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
qtx_ctl |= FIELD_PREP(I40E_QTX_CTL_PF_INDX_MASK, hw->pf_id);
qtx_ctl |= FIELD_PREP(I40E_QTX_CTL_VFVM_INDX_MASK,
vf->vf_id + hw->func_caps.vf_base_id);
wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
i40e_flush(hw);
/* clear the context structure first */
memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
/* only set the required fields */
rx_ctx.base = info->dma_ring_addr / 128;
/* ring_len has to be multiple of 32 */ if (!IS_ALIGNED(info->ring_len, 32) ||
info->ring_len > I40E_MAX_NUM_DESCRIPTORS_XL710) {
ret = -EINVAL; goto error_param;
}
rx_ctx.qlen = info->ring_len;
/* clear the context in the HMC */
ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id); if (ret) {
dev_err(&pf->pdev->dev, "Failed to clear VF LAN Rx queue context %d, error: %d\n",
pf_queue_id, ret);
ret = -ENOENT; goto error_param;
}
/* set the context in the HMC */
ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx); if (ret) {
dev_err(&pf->pdev->dev, "Failed to set VF LAN Rx queue context %d error: %d\n",
pf_queue_id, ret);
ret = -ENOENT; goto error_param;
}
main_vsi = i40e_pf_get_main_vsi(pf);
vsi = i40e_vsi_setup(pf, I40E_VSI_SRIOV, main_vsi->seid, vf->vf_id);
if (!vsi) {
dev_err(&pf->pdev->dev, "add vsi failed for VF %d, aq_err %d\n",
vf->vf_id, pf->hw.aq.asq_last_status);
ret = -ENOENT; goto error_alloc_vsi_res;
}
if (!idx) {
u64 hashcfg = i40e_pf_get_default_rss_hashcfg(pf);
u8 broadcast[ETH_ALEN];
vf->lan_vsi_idx = vsi->idx;
vf->lan_vsi_id = vsi->id; /* If the port VLAN has been configured and then the *VFdriverwasremovedthentheVSIportVLAN *configurationwasdestroyed.Checkifthereis *aportVLANandrestoretheVSIconfigurationif *needed.
*/ if (vf->port_vlan_id)
i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
spin_lock_bh(&vsi->mac_filter_hash_lock); if (is_valid_ether_addr(vf->default_lan_addr.addr)) {
f = i40e_add_mac_filter(vsi,
vf->default_lan_addr.addr); if (!f)
dev_info(&pf->pdev->dev, "Could not add MAC filter %pM for VF %d\n",
vf->default_lan_addr.addr, vf->vf_id);
}
eth_broadcast_addr(broadcast);
f = i40e_add_mac_filter(vsi, broadcast); if (!f)
dev_info(&pf->pdev->dev, "Could not allocate VF broadcast filter\n");
spin_unlock_bh(&vsi->mac_filter_hash_lock);
wr32(&pf->hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)hashcfg);
wr32(&pf->hw, I40E_VFQF_HENA1(1, vf->vf_id),
(u32)(hashcfg >> 32)); /* program mac filter only for VF VSI */
ret = i40e_sync_vsi_filters(vsi); if (ret)
dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
}
/* storing VSI index and id for ADq and don't apply the mac filter */ if (vf->adq_enabled) {
vf->ch[idx].vsi_idx = vsi->idx;
vf->ch[idx].vsi_id = vsi->id;
}
/* Set VF bandwidth if specified */ if (vf->tx_rate) {
max_tx_rate = vf->tx_rate;
} elseif (vf->ch[idx].max_tx_rate) {
max_tx_rate = vf->ch[idx].max_tx_rate;
}
if (max_tx_rate) {
max_tx_rate = div_u64(max_tx_rate, I40E_BW_CREDIT_DIVISOR);
ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
max_tx_rate, 0, NULL); if (ret)
dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
vf->vf_id, ret);
}
error_alloc_vsi_res: return ret;
}
/** *i40e_map_pf_queues_to_vsi *@vf:pointertotheVFinfo * *PFmapsLQPstoaVFbyprogrammingVSILAN_QTABLE&VPLAN_QTABLE.This *functiontakescareoffirstpartVSILAN_QTABLE,mappingpfqueuestoVSI.
**/ staticvoid i40e_map_pf_queues_to_vsi(struct i40e_vf *vf)
{ struct i40e_pf *pf = vf->pf; struct i40e_hw *hw = &pf->hw;
u32 reg, num_tc = 1; /* VF has at least one traffic class */
u16 vsi_id, qps; int i, j;
if (vf->adq_enabled)
num_tc = vf->num_tc;
for (i = 0; i < num_tc; i++) { if (vf->adq_enabled) {
qps = vf->ch[i].num_qps;
vsi_id = vf->ch[i].vsi_id;
} else {
qps = pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
vsi_id = vf->lan_vsi_id;
}
/* Start by disabling VF's configuration API to prevent the OS from *accessingtheVF'sVSIafterit'sfreed/invalidated.
*/
clear_bit(I40E_VF_STATE_INIT, &vf->vf_states);
/* It's possible the VF had requeuested more queues than the default so *dotheaccountingherewhenwe'reabouttofreethem.
*/ if (vf->num_queue_pairs > I40E_DEFAULT_QUEUES_PER_VF) {
pf->queues_left += vf->num_queue_pairs -
I40E_DEFAULT_QUEUES_PER_VF;
}
/* free vsi & disconnect it from the parent uplink */ if (vf->lan_vsi_idx) {
i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
vf->lan_vsi_idx = 0;
vf->lan_vsi_id = 0;
}
/* do the accounting and remove additional ADq VSI's */ if (vf->adq_enabled && vf->ch[0].vsi_idx) { for (j = 0; j < vf->num_tc; j++) { /* At this point VSI0 is already released so don't *releaseitagainandonlycleartheirvaluesin *structurevariables
*/ if (j)
i40e_vsi_release(pf->vsi[vf->ch[j].vsi_idx]);
vf->ch[j].vsi_idx = 0;
vf->ch[j].vsi_id = 0;
}
}
msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
/* disable interrupts so the VF starts in a known state */ for (i = 0; i < msix_vf; i++) { /* format is same for both registers */ if (0 == i)
reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id); else
reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
(vf->vf_id))
+ (i - 1));
wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
i40e_flush(hw);
}
/* clear the irq settings */ for (i = 0; i < msix_vf; i++) { /* format is same for both registers */ if (0 == i)
reg_idx = I40E_VPINT_LNKLST0(vf->vf_id); else
reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
(vf->vf_id))
+ (i - 1));
reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
wr32(hw, reg_idx, reg);
i40e_flush(hw);
} /* reset some of the state variables keeping track of the resources */
vf->num_queue_pairs = 0;
clear_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
clear_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
}
/* allocate hw vsi context & associated resources */
ret = i40e_alloc_vsi_res(vf, 0); if (ret) goto error_alloc;
total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
/* allocate additional VSIs based on tc information for ADq */ if (vf->adq_enabled) { if (pf->queues_left >=
(I40E_MAX_VF_QUEUES - I40E_DEFAULT_QUEUES_PER_VF)) { /* TC 0 always belongs to VF VSI */ for (idx = 1; idx < vf->num_tc; idx++) {
ret = i40e_alloc_vsi_res(vf, idx); if (ret) goto error_alloc;
} /* send correct number of queues */
total_queue_pairs = I40E_MAX_VF_QUEUES;
} else {
dev_info(&pf->pdev->dev, "VF %d: Not enough queues to allocate, disabling ADq\n",
vf->vf_id);
vf->adq_enabled = false;
}
}
/* We account for each VF to get a default number of queue pairs. If *theVFhasnowrequestedmore,weneedtoaccountforthattomake *certainweneverrequestmorequeuesthanweactuallyhaveleftin *HW.
*/ if (total_queue_pairs > I40E_DEFAULT_QUEUES_PER_VF)
pf->queues_left -=
total_queue_pairs - I40E_DEFAULT_QUEUES_PER_VF;
if (vf->trusted)
set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps); else
clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
/* store the total qps number for the runtime *VFreqvalidation
*/
vf->num_queue_pairs = total_queue_pairs;
/* VF is now completely initialized */
set_bit(I40E_VF_STATE_INIT, &vf->vf_states);
/* No VLAN to set promisc on, set on VSI */ if (!num_vlans || !vl) {
aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, seid,
multi_enable,
NULL); if (aq_ret) { int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev, "VF %d failed to set multicast promiscuous mode err %pe aq_err %s\n",
vf->vf_id, ERR_PTR(aq_ret),
libie_aq_str(aq_err));
if (aq_ret) { int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev, "VF %d failed to set unicast promiscuous mode err %pe aq_err %s\n",
vf->vf_id, ERR_PTR(aq_ret),
libie_aq_str(aq_err));
}
return aq_ret;
}
for (i = 0; i < num_vlans; i++) {
aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, seid,
multi_enable,
vl[i], NULL); if (aq_ret) { int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev, "VF %d failed to set multicast promiscuous mode err %pe aq_err %s\n",
vf->vf_id, ERR_PTR(aq_ret),
libie_aq_str(aq_err));
if (!aq_tmp)
aq_tmp = aq_ret;
}
aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, seid,
unicast_enable,
vl[i], NULL); if (aq_ret) { int aq_err = pf->hw.aq.asq_last_status;
dev_err(&pf->pdev->dev, "VF %d failed to set unicast promiscuous mode err %pe aq_err %s\n",
vf->vf_id, ERR_PTR(aq_ret),
libie_aq_str(aq_err));
/* warn the VF */
vf_active = test_and_clear_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
/* Disable VF's configuration API during reset. The flag is re-enabled *ini40e_alloc_vf_res(),whenit'ssafeagaintoaccessVF'sVSI. *It'snormallydisabledini40e_free_vf_res(),butit'ssafer *todoitearliertogivesometimetofinishtoanyVFconfig *functionsthatmaystillberunningatthispoint.
*/
clear_bit(I40E_VF_STATE_INIT, &vf->vf_states);
clear_bit(I40E_VF_STATE_RESOURCES_LOADED, &vf->vf_states);
/* In the case of a VFLR, the HW has already reset the VF and we *justneedtocleanup,sodon'thittheVFRTRIGregister.
*/ if (!flr) { /* Sync VFR reset before trigger next one */
radq = rd32(hw, I40E_VFINT_ICR0_ENA(vf->vf_id)) &
I40E_VFINT_ICR0_ADMINQ_MASK; if (vf_active && !radq) /* waiting for finish reset by virtual driver */ if (i40e_sync_vfr_reset(hw, vf->vf_id))
dev_info(&pf->pdev->dev, "Reset VF %d never finished\n",
vf->vf_id);
/* Reset VF using VPGEN_VFRTRIG reg. It is also setting *inprogressstateinrstat1register.
*/
reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
i40e_flush(hw);
} /* clear the VFLR bit in GLGEN_VFLRSTAT */
reg_idx = (hw->func_caps.vf_base_id + vf->vf_id) / 32;
bit_idx = (hw->func_caps.vf_base_id + vf->vf_id) % 32;
wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
i40e_flush(hw);
if (i40e_quiesce_vf_pci(vf))
dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
vf->vf_id);
}
/* disable promisc modes in case they were enabled */
i40e_config_vf_promiscuous_mode(vf, vf->lan_vsi_id, false, false);
/* free VF resources to begin resetting the VSI state */
i40e_free_vf_res(vf);
/* Enable hardware by clearing the reset bit in the VPGEN_VFRTRIG reg. *BydoingthisweallowHWtoaccessVFmemoryatanypoint.Ifwe *diditanysooner,HWcouldaccessmemorywhileitwasbeingfreed *ini40e_free_vf_res(),causinganIOMMUfault. * *Ontheotherhand,thisneedstobedoneASAP,becausetheVFdriver *iswaitingforthistohappenandmayreportatimeout.It's *harmless,butitgetsloggedintoGuestOSkernellog,sobestavoid *it.
*/
reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
/* reallocate VF resources to finish resetting the VSI state */ if (!i40e_alloc_vf_res(vf)) { int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
i40e_enable_vf_mappings(vf);
set_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
clear_bit(I40E_VF_STATE_DISABLED, &vf->vf_states); /* Do not notify the client during VF init */ if (!test_and_clear_bit(I40E_VF_STATE_PRE_ENABLE,
&vf->vf_states))
i40e_notify_client_of_vf_reset(pf, abs_vf_id);
vf->num_vlan = 0;
}
/* Tell the VF driver the reset is done. This needs to be done only *afterVFhasbeenfullyinitialized,becausetheVFdrivermay *requestresourcesimmediatelyaftersettingthisflag.
*/
wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), VIRTCHNL_VFR_VFACTIVE);
}
if (test_bit(__I40E_VF_RESETS_DISABLED, pf->state)) returntrue;
/* Bail out if VFs are disabled. */ if (test_bit(__I40E_VF_DISABLE, pf->state)) returntrue;
/* If VF is being reset already we don't need to continue. */ if (test_and_set_bit(I40E_VF_STATE_RESETTING, &vf->vf_states)) returnfalse;
i40e_trigger_vf_reset(vf, flr);
/* poll VPGEN_VFRSTAT reg to make sure *thatresetiscomplete
*/ for (i = 0; i < 10; i++) { /* VF reset requires driver to first reset the VF and then *pollthestatusregistertomakesurethatthereset *completedsuccessfully.DuetointernalHWFIFOflushes, *wemustwait10msbeforetheregisterwillbevalid.
*/
usleep_range(10000, 20000);
reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id)); if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
rsd = true; break;
}
}
if (flr)
usleep_range(10000, 20000);
if (!rsd)
dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
vf->vf_id);
usleep_range(10000, 20000);
/* On initial reset, we don't have any queues to disable */ if (vf->lan_vsi_idx != 0)
i40e_vsi_stop_rings(pf->vsi[vf->lan_vsi_idx]);
/* If we don't have any VFs, then there is nothing to reset */ if (!pf->num_alloc_vfs) returnfalse;
/* If VFs have been disabled, there is no need to reset */ if (test_and_set_bit(__I40E_VF_DISABLE, pf->state)) returnfalse;
/* Begin reset on all VFs at once */ for (vf = &pf->vf[0]; vf < &pf->vf[pf->num_alloc_vfs]; ++vf) { /* If VF is being reset no need to trigger reset again */ if (!test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states))
i40e_trigger_vf_reset(vf, flr);
}
/* HW requires some time to make sure it can flush the FIFO for a VF *whenitresetsit.PolltheVPGEN_VFRSTATregisterforeachVFin *sequencetomakesurethatithascompleted.We'llkeeptrackof *theVFsusingasimpleiteratorthatincrementsoncethatVFhas *finishedresetting.
*/ for (i = 0, vf = &pf->vf[0]; i < 10 && vf < &pf->vf[pf->num_alloc_vfs]; ++i) {
usleep_range(10000, 20000);
/* Check each VF in sequence, beginning with the VF to fail *thepreviouscheck.
*/ while (vf < &pf->vf[pf->num_alloc_vfs]) { if (!test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states)) {
reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id)); if (!(reg & I40E_VPGEN_VFRSTAT_VFRD_MASK)) break;
}
/* If the current VF has finished resetting, move on *tothenextVFinsequence.
*/
++vf;
}
}
if (flr)
usleep_range(10000, 20000);
/* Display a warning if at least one VF didn't manage to reset in *time,butcontinueonwiththeoperation.
*/ if (vf < &pf->vf[pf->num_alloc_vfs])
dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
vf->vf_id);
usleep_range(10000, 20000);
/* Begin disabling all the rings associated with VFs, but do not wait *betweeneachVF.
*/ for (vf = &pf->vf[0]; vf < &pf->vf[pf->num_alloc_vfs]; ++vf) { /* On initial reset, we don't have any queues to disable */ if (vf->lan_vsi_idx == 0) continue;
/* If VF is reset in another thread just continue */ if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states)) continue;
/* Now that we've notified HW to disable all of the VF rings, wait *untiltheyfinish.
*/ for (vf = &pf->vf[0]; vf < &pf->vf[pf->num_alloc_vfs]; ++vf) { /* On initial reset, we don't have any queues to disable */ if (vf->lan_vsi_idx == 0) continue;
/* If VF is reset in another thread just continue */ if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states)) continue;
/* Hw may need up to 50ms to finish disabling the RX queues. We *minimizethewaitbydelayingonlyonceforallVFs.
*/
mdelay(50);
/* Finish the reset on each VF */ for (vf = &pf->vf[0]; vf < &pf->vf[pf->num_alloc_vfs]; ++vf) { /* If VF is reset in another thread just continue */ if (test_bit(I40E_VF_STATE_RESETTING, &vf->vf_states)) continue;
set_bit(__I40E_VFS_RELEASING, pf->state); while (test_and_set_bit(__I40E_VF_DISABLE, pf->state))
usleep_range(1000, 2000);
i40e_notify_client_of_vf_enable(pf, 0);
/* 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(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
/* Amortize wait time by stopping all VFs at the same time */ for (i = 0; i < pf->num_alloc_vfs; i++) { if (test_bit(I40E_VF_STATE_INIT, &pf->vf[i].vf_states)) continue;
/* free up VF resources */
tmp = pf->num_alloc_vfs;
pf->num_alloc_vfs = 0; for (i = 0; i < tmp; i++) { if (test_bit(I40E_VF_STATE_INIT, &pf->vf[i].vf_states))
i40e_free_vf_res(&pf->vf[i]); /* disable qp mappings */
i40e_disable_vf_mappings(&pf->vf[i]);
}
kfree(pf->vf);
pf->vf = NULL;
/* This check is for when the driver is unloaded while VFs are *assigned.SettingthenumberofVFsto0throughsysfsiscaught *beforethisfunctionevergetscalled.
*/ if (!pci_vfs_assigned(pf->pdev)) { /* Acknowledge VFLR for all VFS. Without this, VFs will fail to *workcorrectlywhenSR-IOVgetsre-enabled.
*/ for (vf_id = 0; vf_id < tmp; vf_id++) {
reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
}
}
clear_bit(__I40E_VF_DISABLE, pf->state);
clear_bit(__I40E_VFS_RELEASING, pf->state);
}
#ifdef CONFIG_PCI_IOV /** *i40e_alloc_vfs *@pf:pointertothePFstructure *@num_alloc_vfs:numberofVFstoallocate * *allocateVFresources
**/ int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
{ struct i40e_vf *vfs; int i, ret = 0;
/* Disable interrupt 0 so we don't try to handle the VFLR. */
i40e_irq_dynamic_disable_icr0(pf);
/* Check to see if we're just allocating resources for extant VFs */ if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
ret = pci_enable_sriov(pf->pdev, num_alloc_vfs); if (ret) {
clear_bit(I40E_FLAG_VEB_MODE_ENA, pf->flags);
pf->num_alloc_vfs = 0; goto err_iov;
}
} /* allocate memory */
vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL); if (!vfs) {
ret = -ENOMEM; goto err_alloc;
}
pf->vf = vfs;
/* apply default profile */ for (i = 0; i < num_alloc_vfs; i++) {
vfs[i].pf = pf;
vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
vfs[i].vf_id = i;
/** *i40e_pci_sriov_configure *@pdev:pointertoapci_devstructure *@num_vfs:numberofVFstoallocate * *EnableorchangethenumberofVFs.Calledwhentheuserupdatesthenumber *ofVFsinsysfs.
**/ int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
{ struct i40e_pf *pf = pci_get_drvdata(pdev); int ret = 0;
if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
dev_warn(&pdev->dev, "Unable to configure VFs, other operation is pending.\n"); return -EAGAIN;
}
if (num_vfs) { if (!test_bit(I40E_FLAG_VEB_MODE_ENA, pf->flags)) {
set_bit(I40E_FLAG_VEB_MODE_ENA, pf->flags);
i40e_do_reset_safe(pf, I40E_PF_RESET_AND_REBUILD_FLAG);
}
ret = i40e_pci_sriov_enable(pdev, num_vfs); goto sriov_configure_out;
}
if (!pci_vfs_assigned(pf->pdev)) {
i40e_free_vfs(pf);
clear_bit(I40E_FLAG_VEB_MODE_ENA, pf->flags);
i40e_do_reset_safe(pf, I40E_PF_RESET_AND_REBUILD_FLAG);
} else {
dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
ret = -EINVAL; goto sriov_configure_out;
}
sriov_configure_out:
clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state); return ret;
}
/* When handling some messages, it needs VF state to be set. *ItispossiblethatthisflagisclearedduringVFreset, *sothereisaneedtowaituntiltheendoftheresetto *handletherequestmessagecorrectly.
*/ for (i = 0; i < I40E_VF_STATE_WAIT_COUNT; i++) { if (test_bit(state, &vf->vf_states)) returntrue;
usleep_range(10000, 20000);
}
vf->vf_ver = *(struct virtchnl_version_info *)msg; /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */ if (VF_IS_V10(&vf->vf_ver))
info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS; return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION, 0, (u8 *)&info, sizeof(struct virtchnl_version_info));
}
/* first element in the array belongs to primary VF VSI and we shouldn't *deleteit.WeshouldhoweverdeletetherestoftheVSIscreated
*/ for (i = 1; i < vf->num_tc; i++) { if (vf->ch[i].vsi_idx) {
i40e_vsi_release(pf->vsi[vf->ch[i].vsi_idx]);
vf->ch[i].vsi_idx = 0;
vf->ch[i].vsi_id = 0;
}
}
}
if (test_bit(I40E_HW_CAP_MULTI_TCP_UDP_RSS_PCTYPE, pf->hw.caps)) { if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
vfres->vf_cap_flags |=
VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
}
if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
if (test_bit(I40E_HW_CAP_OUTER_UDP_CSUM, pf->hw.caps) &&
(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM))
vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING) { if (test_bit(I40E_FLAG_MFP_ENA, pf->flags)) {
dev_err(&pf->pdev->dev, "VF %d requested polling mode: this feature is supported only when the device is running in single function per port (SFP) mode\n",
vf->vf_id);
aq_ret = -EINVAL; goto err;
}
vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
}
if (test_bit(I40E_HW_CAP_WB_ON_ITR, pf->hw.caps)) { if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
vfres->vf_cap_flags |=
VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
}
if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADQ)
vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADQ;
/* For ADq there can be up to 4 VSIs with max 4 queues each. *VFdoesnotknowabouttheseadditionalVSIsandall *itcaresisaboutitsownqueues.PFconfiguresthesequeues *toitsappropriateVSIsbasedonTCmapping
*/ if (vf->adq_enabled) { if (idx >= vf->num_tc) {
aq_ret = -ENODEV; goto error_param;
} if (j == (vf->ch[idx].num_qps - 1)) {
idx++;
j = 0; /* resetting the queue count */
vsi_queue_id = 0;
} else {
j++;
vsi_queue_id++;
}
}
} /* set vsi num_queue_pairs in use to num configured by VF */ if (!vf->adq_enabled) {
pf->vsi[vf->lan_vsi_idx]->num_queue_pairs =
qci->num_queue_pairs;
} else { for (i = 0; i < vf->num_tc; i++) {
vsi = pf->vsi[vf->ch[i].vsi_idx];
vsi->num_queue_pairs = vf->ch[i].num_qps;
if (vf->is_disabled_from_host) {
aq_ret = -EPERM;
dev_info(&pf->pdev->dev, "Admin has disabled VF %d, will not enable queues\n",
vf->vf_id); goto error_param;
}
if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
aq_ret = -EINVAL; goto error_param;
}
if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
aq_ret = -EINVAL; goto error_param;
}
if (!i40e_vc_validate_vqs_bitmaps(vqs)) {
aq_ret = -EINVAL; goto error_param;
}
/* Use the queue bit map sent by the VF */ if (i40e_ctrl_vf_rx_rings(pf->vsi[vf->lan_vsi_idx], vqs->rx_queues, true)) {
aq_ret = -EIO; goto error_param;
} if (i40e_ctrl_vf_tx_rings(pf->vsi[vf->lan_vsi_idx], vqs->tx_queues, true)) {
aq_ret = -EIO; goto error_param;
}
/* need to start the rings for additional ADq VSI's as well */ if (vf->adq_enabled) { /* zero belongs to LAN VSI */ for (i = 1; i < vf->num_tc; i++) { if (i40e_vsi_start_rings(pf->vsi[vf->ch[i].vsi_idx]))
aq_ret = -EIO;
}
}
error_param: /* send the response to the VF */ return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES,
aq_ret);
}
if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
aq_ret = -EINVAL; goto error_param;
}
if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
aq_ret = -EINVAL; goto error_param;
}
if (!i40e_vc_validate_vqs_bitmaps(vqs)) {
aq_ret = -EINVAL; goto error_param;
}
/* Use the queue bit map sent by the VF */ if (i40e_ctrl_vf_tx_rings(pf->vsi[vf->lan_vsi_idx], vqs->tx_queues, false)) {
aq_ret = -EIO; goto error_param;
} if (i40e_ctrl_vf_rx_rings(pf->vsi[vf->lan_vsi_idx], vqs->rx_queues, false)) {
aq_ret = -EIO; goto error_param;
}
error_param: /* send the response to the VF */ return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES,
aq_ret);
}
vsi = pf->vsi[vf->lan_vsi_idx];
cur_queues = vsi->alloc_queue_pairs;
/* if current allocated queues are enough for need */ if (cur_queues >= needed) return vsi->base_queue;
pile = pf->qp_pile; if (cur_queues > 0) { /* if the allocated queues are not zero *justcheckifthereareenoughqueuesformore *behindtheallocatedqueues.
*/
more = needed - cur_queues; for (i = vsi->base_queue + cur_queues;
i < pile->num_entries; i++) { if (pile->list[i] & I40E_PILE_VALID_BIT) break;
if (more-- == 1) /* there is enough */ return vsi->base_queue;
}
}
pool_size = 0; for (i = 0; i < pile->num_entries; i++) { if (pile->list[i] & I40E_PILE_VALID_BIT) {
pool_size = 0; continue;
} if (needed <= ++pool_size) /* there is enough */ return i;
}
if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
aq_ret = -EINVAL; goto error_param;
}
if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
aq_ret = -EINVAL; goto error_param;
}
vsi = pf->vsi[vf->lan_vsi_idx]; if (!vsi) {
aq_ret = -EINVAL; goto error_param;
}
i40e_update_eth_stats(vsi);
stats = vsi->eth_stats;
error_param: /* send the response back to the VF */ return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, aq_ret,
(u8 *)&stats, sizeof(stats));
}
#define I40E_MAX_MACVLAN_PER_HW 3072 #define I40E_MAX_MACVLAN_PER_PF(num_ports) (I40E_MAX_MACVLAN_PER_HW / \
(num_ports)) /* If the VF is not trusted restrict the number of MAC/VLAN it can program *MACfilters:16formulticast,1forMAC,1forbroadcast
*/ #define I40E_VC_MAX_MAC_ADDR_PER_VF (16 + 1 + 1) #define I40E_VC_MAX_VLAN_PER_VF 16
for (i = 0; i < al->num_elements; i++) { struct i40e_mac_filter *f;
u8 *addr = al->list[i].addr;
if (is_broadcast_ether_addr(addr) ||
is_zero_ether_addr(addr)) {
dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
addr); return -EINVAL;
}
/* If the host VMM administrator has set the VF MAC address *administrativelyviathendo_set_vf_maccommandthendeny *permissiontotheVFtoaddordeleteunicastMACaddresses. *UnlesstheVFisprivilegedandthenitcandowhatever. *TheVFmayrequesttosettheMACaddressfilteralready *assignedtoitsodonotreturnanerrorinthatcase.
*/ if (!vf_trusted && !is_multicast_ether_addr(addr) &&
vf->pf_set_mac && !ether_addr_equal(addr, vf->default_lan_addr.addr)) {
dev_err(&pf->pdev->dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n"); return -EPERM;
}
/*count filters that really will be added*/
f = i40e_find_mac(vsi, addr); if (!f)
++mac_add_cnt;
}
/* If this VF is not privileged, then we can't add more than a limited *numberofaddresses. * *IfthisVFistrusted,itcanusemoreresourcesthanuntrusted. *HowevertoensurethateverytrustedVFhasappropriatenumberof *resources,dividewholepoolofresourcesperportandthenacross *allVFs.
*/ if (!vf_trusted)
mac_add_max = I40E_VC_MAX_MAC_ADDR_PER_VF; else
mac_add_max = I40E_VC_MAX_MACVLAN_PER_TRUSTED_VF(pf->num_alloc_vfs, hw->num_ports);
/* VF can replace all its filters in one step, in this case mac_add_max *willbeaddedasactiveandanothermac_add_maxwillbein *ato-be-removedstate.Accountforthat.
*/ if ((i40e_count_active_filters(vsi) + mac_add_cnt) > mac_add_max ||
(i40e_count_all_filters(vsi) + mac_add_cnt) > 2 * mac_add_max) { if (!vf_trusted) {
dev_err(&pf->pdev->dev, "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n"); return -EPERM;
} else {
dev_err(&pf->pdev->dev, "Cannot add more MAC addresses, trusted VF exhausted it's resources\n"); return -EPERM;
}
} return0;
}
/* If request to add MAC filter is a primary request update its default *MACaddresswiththerequestedone.Ifitisalegacyrequestthen *checkifcurrentdefaultisemptyifsoupdatethedefaultMAC
*/ if (i40e_is_vc_addr_primary(vc_ether_addr)) {
ether_addr_copy(vf->default_lan_addr.addr, mac_addr);
} elseif (i40e_is_vc_addr_legacy(vc_ether_addr)) { if (is_zero_ether_addr(vf->default_lan_addr.addr))
ether_addr_copy(vf->default_lan_addr.addr, mac_addr);
}
}
if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE) ||
!i40e_vc_isvalid_vsi_id(vf, al->vsi_id)) {
ret = -EINVAL; goto error_param;
}
vsi = pf->vsi[vf->lan_vsi_idx];
/* Lock once, because all function inside for loop accesses VSI's *MACfilterlistwhichneedstobeprotectedusingsamelock.
*/
spin_lock_bh(&vsi->mac_filter_hash_lock);
ret = i40e_check_vf_permission(vf, al); if (ret) {
spin_unlock_bh(&vsi->mac_filter_hash_lock); goto error_param;
}
/* add new addresses to the list */ for (i = 0; i < al->num_elements; i++) { struct i40e_mac_filter *f;
f = i40e_find_mac(vsi, al->list[i].addr); if (!f) {
f = i40e_add_mac_filter(vsi, al->list[i].addr);
if (!f) {
dev_err(&pf->pdev->dev, "Unable to add MAC filter %pM for VF %d\n",
al->list[i].addr, vf->vf_id);
ret = -EINVAL;
spin_unlock_bh(&vsi->mac_filter_hash_lock); goto error_param;
}
}
i40e_update_vf_mac_addr(vf, &al->list[i]);
}
spin_unlock_bh(&vsi->mac_filter_hash_lock);
/* program the updated filter list */
ret = i40e_sync_vsi_filters(vsi); if (ret)
dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
vf->vf_id, ret);
error_param: /* send the response to the VF */ return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
ret, NULL, 0);
}
if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE) ||
!i40e_vc_isvalid_vsi_id(vf, al->vsi_id)) {
ret = -EINVAL; goto error_param;
}
for (i = 0; i < al->num_elements; i++) { if (is_broadcast_ether_addr(al->list[i].addr) ||
is_zero_ether_addr(al->list[i].addr)) {
dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n",
al->list[i].addr, vf->vf_id);
ret = -EINVAL; goto error_param;
}
}
vsi = pf->vsi[vf->lan_vsi_idx];
spin_lock_bh(&vsi->mac_filter_hash_lock); /* delete addresses from the list */ for (i = 0; i < al->num_elements; i++) { const u8 *addr = al->list[i].addr;
/* Allow to delete VF primary MAC only if it was not set *administrativelybyPF.
*/ if (ether_addr_equal(addr, vf->default_lan_addr.addr)) { if (!vf->pf_set_mac)
was_unimac_deleted = true; else continue;
}
if (i40e_del_mac_filter(vsi, al->list[i].addr)) {
ret = -EINVAL;
spin_unlock_bh(&vsi->mac_filter_hash_lock); goto error_param;
}
}
spin_unlock_bh(&vsi->mac_filter_hash_lock);
if (was_unimac_deleted)
eth_zero_addr(vf->default_lan_addr.addr);
/* program the updated filter list */
ret = i40e_sync_vsi_filters(vsi); if (ret)
dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
vf->vf_id, ret);
if (vf->trusted && was_unimac_deleted) { struct i40e_mac_filter *f; struct hlist_node *h;
u8 *macaddr = NULL; int bkt;
/* set last unicast mac address as default */
spin_lock_bh(&vsi->mac_filter_hash_lock);
hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) { if (is_valid_ether_addr(f->macaddr))
macaddr = f->macaddr;
} if (macaddr)
ether_addr_copy(vf->default_lan_addr.addr, macaddr);
spin_unlock_bh(&vsi->mac_filter_hash_lock);
}
error_param: /* send the response to the VF */ return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR, ret);
}
if ((vf->num_vlan >= I40E_VC_MAX_VLAN_PER_VF) &&
!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
dev_err(&pf->pdev->dev, "VF is not trusted, switch the VF to trusted to add more VLAN addresses\n"); goto error_param;
} if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
!i40e_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
aq_ret = -EINVAL; goto error_param;
}
for (i = 0; i < vfl->num_elements; i++) { if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
aq_ret = -EINVAL;
dev_err(&pf->pdev->dev, "invalid VF VLAN id %d\n", vfl->vlan_id[i]); goto error_param;
}
}
vsi = pf->vsi[vf->lan_vsi_idx]; if (vsi->info.pvid) {
aq_ret = -EINVAL; goto error_param;
}
i40e_vlan_stripping_enable(vsi); for (i = 0; i < vfl->num_elements; i++) { /* add new VLAN filter */ int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]); if (!ret)
vf->num_vlan++;
if (test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states))
i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid, true,
vfl->vlan_id[i],
NULL); if (test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))
i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid, true,
vfl->vlan_id[i],
NULL);
if (ret)
dev_err(&pf->pdev->dev, "Unable to add VLAN filter %d for VF %d, error %d\n",
vfl->vlan_id[i], vf->vf_id, ret);
}
error_param: /* send the response to the VF */ return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, aq_ret);
}
if (tc_filter->action != VIRTCHNL_ACTION_TC_REDIRECT) {
dev_info(&pf->pdev->dev, "VF %d: ADQ doesn't support this action (%d)\n",
vf->vf_id, tc_filter->action); goto err;
}
/* action_meta is TC number here to which the filter is applied */ if (!tc_filter->action_meta ||
tc_filter->action_meta >= vf->num_tc) {
dev_info(&pf->pdev->dev, "VF %d: Invalid TC number %u\n",
vf->vf_id, tc_filter->action_meta); goto err;
}
/* Check filter if it's programmed for advanced mode or basic mode. *TherearetwoADqmodes(forVFonly), *1.Basicmode:intendedtoallowasmanyfilteroptionsaspossible *tobeaddedtoaVFinNon-trustedmode.Maingoalis *toaddfilterstoitsownMACandVLANid. *2.Advancedmode:isforallowingfilterstobeappliedotherthan *itsownMACorVLAN.ThismoderequirestheVFtobe *Trusted.
*/ if (mask.dst_mac[0] && !mask.dst_ip[0]) {
vsi = pf->vsi[vf->lan_vsi_idx];
f = i40e_find_mac(vsi, data.dst_mac);
if (!f) {
dev_info(&pf->pdev->dev, "Destination MAC %pM doesn't belong to VF %d\n",
data.dst_mac, vf->vf_id); goto err;
}
if (mask.vlan_id) {
hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f,
hlist) { if (f->vlan == ntohs(data.vlan_id)) {
found = true; break;
}
} if (!found) {
dev_info(&pf->pdev->dev, "VF %d doesn't have any VLAN id %u\n",
vf->vf_id, ntohs(data.vlan_id)); goto err;
}
}
} else { /* Check if VF is trusted */ if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
dev_err(&pf->pdev->dev, "VF %d not trusted, make VF trusted to add advanced mode ADq cloud filters\n",
vf->vf_id); return -EIO;
}
}
if (mask.dst_mac[0] & data.dst_mac[0]) { if (is_broadcast_ether_addr(data.dst_mac) ||
is_zero_ether_addr(data.dst_mac)) {
dev_info(&pf->pdev->dev, "VF %d: Invalid Dest MAC addr %pM\n",
vf->vf_id, data.dst_mac); goto err;
}
}
if (mask.src_mac[0] & data.src_mac[0]) { if (is_broadcast_ether_addr(data.src_mac) ||
is_zero_ether_addr(data.src_mac)) {
dev_info(&pf->pdev->dev, "VF %d: Invalid Source MAC addr %pM\n",
vf->vf_id, data.src_mac); goto err;
}
}
if (mask.dst_port & data.dst_port) { if (!data.dst_port) {
dev_info(&pf->pdev->dev, "VF %d: Invalid Dest port\n",
vf->vf_id); goto err;
}
}
if (mask.src_port & data.src_port) { if (!data.src_port) {
dev_info(&pf->pdev->dev, "VF %d: Invalid Source port\n",
vf->vf_id); goto err;
}
}
switch (vcf->flow_type) { case VIRTCHNL_TCP_V4_FLOW:
cfilter.n_proto = ETH_P_IP; if (mask.dst_ip[0] & tcf.dst_ip[0])
memcpy(&cfilter.ip.v4.dst_ip, tcf.dst_ip,
ARRAY_SIZE(tcf.dst_ip)); elseif (mask.src_ip[0] & tcf.dst_ip[0])
memcpy(&cfilter.ip.v4.src_ip, tcf.src_ip,
ARRAY_SIZE(tcf.dst_ip)); break; case VIRTCHNL_TCP_V6_FLOW:
cfilter.n_proto = ETH_P_IPV6; if (mask.dst_ip[3] & tcf.dst_ip[3])
memcpy(&cfilter.ip.v6.dst_ip6, tcf.dst_ip, sizeof(cfilter.ip.v6.dst_ip6)); if (mask.src_ip[3] & tcf.src_ip[3])
memcpy(&cfilter.ip.v6.src_ip6, tcf.src_ip, sizeof(cfilter.ip.v6.src_ip6)); break; default: /* TC filter can be configured based on different combinations *andinthiscaseIPisnotapartoffilterconfig
*/
dev_info(&pf->pdev->dev, "VF %d: Flow type not configured\n",
vf->vf_id);
}
/* get the vsi to which the tc belongs to */
vsi = pf->vsi[vf->ch[vcf->action_meta].vsi_idx];
cfilter.seid = vsi->seid;
cfilter.flags = vcf->field_flags;
/* Deleting TC filter */ if (tcf.dst_port)
ret = i40e_add_del_cloud_filter_big_buf(vsi, &cfilter, false); else
ret = i40e_add_del_cloud_filter(vsi, &cfilter, false); if (ret) {
dev_err(&pf->pdev->dev, "VF %d: Failed to delete cloud filter, err %pe aq_err %s\n",
vf->vf_id, ERR_PTR(ret),
libie_aq_str(pf->hw.aq.asq_last_status)); goto err;
}
hlist_for_each_entry_safe(cf, node,
&vf->cloud_filter_list, cloud_node) { if (cf->seid != cfilter.seid) continue; if (mask.dst_port) if (cfilter.dst_port != cf->dst_port) continue; if (mask.dst_mac[0]) if (!ether_addr_equal(cf->src_mac, cfilter.src_mac)) continue; /* for ipv4 data to be valid, only first byte of mask is set */ if (cfilter.n_proto == ETH_P_IP && mask.dst_ip[0]) if (memcmp(&cfilter.ip.v4.dst_ip, &cf->ip.v4.dst_ip,
ARRAY_SIZE(tcf.dst_ip))) continue; /* for ipv6, mask is set for all sixteen bytes (4 words) */ if (cfilter.n_proto == ETH_P_IPV6 && mask.dst_ip[3]) if (memcmp(&cfilter.ip.v6.dst_ip6, &cf->ip.v6.dst_ip6, sizeof(cfilter.ip.v6.src_ip6))) continue; if (mask.vlan_id) if (cfilter.vlan_id != cf->vlan_id) continue;
switch (vcf->flow_type) { case VIRTCHNL_TCP_V4_FLOW:
cfilter->n_proto = ETH_P_IP; if (mask.dst_ip[0] & tcf.dst_ip[0])
memcpy(&cfilter->ip.v4.dst_ip, tcf.dst_ip,
ARRAY_SIZE(tcf.dst_ip)); elseif (mask.src_ip[0] & tcf.dst_ip[0])
memcpy(&cfilter->ip.v4.src_ip, tcf.src_ip,
ARRAY_SIZE(tcf.dst_ip)); break; case VIRTCHNL_TCP_V6_FLOW:
cfilter->n_proto = ETH_P_IPV6; if (mask.dst_ip[3] & tcf.dst_ip[3])
memcpy(&cfilter->ip.v6.dst_ip6, tcf.dst_ip, sizeof(cfilter->ip.v6.dst_ip6)); if (mask.src_ip[3] & tcf.src_ip[3])
memcpy(&cfilter->ip.v6.src_ip6, tcf.src_ip, sizeof(cfilter->ip.v6.src_ip6)); break; default: /* TC filter can be configured based on different combinations *andinthiscaseIPisnotapartoffilterconfig
*/
dev_info(&pf->pdev->dev, "VF %d: Flow type not configured\n",
vf->vf_id);
}
/* get the VSI to which the TC belongs to */
vsi = pf->vsi[vf->ch[vcf->action_meta].vsi_idx];
cfilter->seid = vsi->seid;
cfilter->flags = vcf->field_flags;
if (!i40e_sync_vf_state(vf, I40E_VF_STATE_ACTIVE)) {
aq_ret = -EINVAL; goto err;
}
/* ADq cannot be applied if spoof check is ON */ if (vf->spoofchk) {
dev_err(&pf->pdev->dev, "Spoof check is ON, turn it OFF to enable ADq\n");
aq_ret = -EINVAL; goto err;
}
if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADQ)) {
dev_err(&pf->pdev->dev, "VF %d attempting to enable ADq, but hasn't properly negotiated that capability\n",
vf->vf_id);
aq_ret = -EINVAL; goto err;
}
/* max number of traffic classes for VF currently capped at 4 */ if (!tci->num_tc || tci->num_tc > I40E_MAX_VF_VSI) {
dev_err(&pf->pdev->dev, "VF %d trying to set %u TCs, valid range 1-%u TCs per VF\n",
vf->vf_id, tci->num_tc, I40E_MAX_VF_VSI);
aq_ret = -EINVAL; goto err;
}
/* validate queues for each TC */ for (i = 0; i < tci->num_tc; i++) if (!tci->list[i].count ||
tci->list[i].count > I40E_DEFAULT_QUEUES_PER_VF) {
dev_err(&pf->pdev->dev, "VF %d: TC %d trying to set %u queues, valid range 1-%u queues per TC\n",
vf->vf_id, i, tci->list[i].count,
I40E_DEFAULT_QUEUES_PER_VF);
aq_ret = -EINVAL; goto err;
}
/* need Max VF queues but already have default number of queues */
adq_request_qps = I40E_MAX_VF_QUEUES - I40E_DEFAULT_QUEUES_PER_VF;
if (pf->queues_left < adq_request_qps) {
dev_err(&pf->pdev->dev, "No queues left to allocate to VF %d\n",
vf->vf_id);
aq_ret = -EINVAL; goto err;
} else { /* we need to allocate max VF queues to enable ADq so as to *makesureADqenabledVFalwaysgetsbackqueueswhenit *goesthroughareset.
*/
vf->num_queue_pairs = I40E_MAX_VF_QUEUES;
}
/* get link speed in MB to validate rate limit */
speed = i40e_vc_link_speed2mbps(ls->link_speed); if (speed == SPEED_UNKNOWN) {
dev_err(&pf->pdev->dev, "Cannot detect link speed\n");
aq_ret = -EINVAL; goto err;
}
/* parse data from the queue channel info */
vf->num_tc = tci->num_tc; for (i = 0; i < vf->num_tc; i++) { if (tci->list[i].max_tx_rate) { if (tci->list[i].max_tx_rate > speed) {
dev_err(&pf->pdev->dev, "Invalid max tx rate %llu specified for VF %d.",
tci->list[i].max_tx_rate,
vf->vf_id);
aq_ret = -EINVAL; goto err;
} else {
vf->ch[i].max_tx_rate =
tci->list[i].max_tx_rate;
}
}
vf->ch[i].num_qps = tci->list[i].count;
}
/* set this flag only after making sure all inputs are sane */
vf->adq_enabled = true;
/* reset the VF in order to allocate resources */
i40e_vc_reset_vf(vf, true);
return0;
/* send the response to the VF */
err: return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ENABLE_CHANNELS,
aq_ret);
}
/* Check if VF is disabled. */ if (test_bit(I40E_VF_STATE_DISABLED, &vf->vf_states)) return -EINVAL;
/* perform basic checks on the msg */
ret = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
if (ret) {
i40e_vc_send_resp_to_vf(vf, v_opcode, -EINVAL);
dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
local_vf_id, v_opcode, msglen); return ret;
}
switch (v_opcode) { case VIRTCHNL_OP_VERSION:
ret = i40e_vc_get_version_msg(vf, msg); break; case VIRTCHNL_OP_GET_VF_RESOURCES:
ret = i40e_vc_get_vf_resources_msg(vf, msg);
i40e_vc_notify_vf_link_state(vf); break; case VIRTCHNL_OP_RESET_VF:
i40e_vc_reset_vf(vf, false);
ret = 0; break; case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
ret = i40e_vc_config_promiscuous_mode_msg(vf, msg); break; case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
ret = i40e_vc_config_queues_msg(vf, msg); break; case VIRTCHNL_OP_CONFIG_IRQ_MAP:
ret = i40e_vc_config_irq_map_msg(vf, msg); break; case VIRTCHNL_OP_ENABLE_QUEUES:
ret = i40e_vc_enable_queues_msg(vf, msg);
i40e_vc_notify_vf_link_state(vf); break; case VIRTCHNL_OP_DISABLE_QUEUES:
ret = i40e_vc_disable_queues_msg(vf, msg); break; case VIRTCHNL_OP_ADD_ETH_ADDR:
ret = i40e_vc_add_mac_addr_msg(vf, msg); break; case VIRTCHNL_OP_DEL_ETH_ADDR:
ret = i40e_vc_del_mac_addr_msg(vf, msg); break; case VIRTCHNL_OP_ADD_VLAN:
ret = i40e_vc_add_vlan_msg(vf, msg); break; case VIRTCHNL_OP_DEL_VLAN:
ret = i40e_vc_remove_vlan_msg(vf, msg); break; case VIRTCHNL_OP_GET_STATS:
ret = i40e_vc_get_stats_msg(vf, msg); break; case VIRTCHNL_OP_RDMA:
ret = i40e_vc_rdma_msg(vf, msg, msglen); break; case VIRTCHNL_OP_CONFIG_RDMA_IRQ_MAP:
ret = i40e_vc_rdma_qvmap_msg(vf, msg, true); break; case VIRTCHNL_OP_RELEASE_RDMA_IRQ_MAP:
ret = i40e_vc_rdma_qvmap_msg(vf, msg, false); break; case VIRTCHNL_OP_CONFIG_RSS_KEY:
ret = i40e_vc_config_rss_key(vf, msg); break; case VIRTCHNL_OP_CONFIG_RSS_LUT:
ret = i40e_vc_config_rss_lut(vf, msg); break; case VIRTCHNL_OP_GET_RSS_HASHCFG_CAPS:
ret = i40e_vc_get_rss_hashcfg(vf, msg); break; case VIRTCHNL_OP_SET_RSS_HASHCFG:
ret = i40e_vc_set_rss_hashcfg(vf, msg); break; case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
ret = i40e_vc_enable_vlan_stripping(vf, msg); break; case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
ret = i40e_vc_disable_vlan_stripping(vf, msg); break; case VIRTCHNL_OP_REQUEST_QUEUES:
ret = i40e_vc_request_queues_msg(vf, msg); break; case VIRTCHNL_OP_ENABLE_CHANNELS:
ret = i40e_vc_add_qch_msg(vf, msg); break; case VIRTCHNL_OP_DISABLE_CHANNELS:
ret = i40e_vc_del_qch_msg(vf, msg); break; case VIRTCHNL_OP_ADD_CLOUD_FILTER:
ret = i40e_vc_add_cloud_filter(vf, msg); break; case VIRTCHNL_OP_DEL_CLOUD_FILTER:
ret = i40e_vc_del_cloud_filter(vf, msg); break; case VIRTCHNL_OP_UNKNOWN: default:
dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
v_opcode, local_vf_id);
ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
-EOPNOTSUPP); break;
}
if (!test_bit(__I40E_VFLR_EVENT_PENDING, pf->state)) return0;
/* Re-enable the VFLR interrupt cause here, before looking for which *VFgotreset.Otherwise,ifanotherVFgetsaresetwhilethe *firstoneisbeingprocessed,thatinterruptwillbelost,and *thatVFwillbestuckinresetforever.
*/
reg = rd32(hw, I40E_PFINT_ICR0_ENA);
reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
wr32(hw, I40E_PFINT_ICR0_ENA, reg);
i40e_flush(hw);
clear_bit(__I40E_VFLR_EVENT_PENDING, pf->state); for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32; /* read GLGEN_VFLRSTAT register to find out the flr VFs */
vf = &pf->vf[vf_id];
reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx)); if (reg & BIT(bit_idx)) /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */ if (!i40e_reset_vf(vf, true)) { /* At least one VF did not finish resetting, retry next time */
set_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
}
}
return0;
}
/** *i40e_validate_vf *@pf:thephysicalfunction *@vf_id:VFidentifier * *CheckthattheVFisenabledandtheVSIexists. * *Returns0onsuccess,negativeonfailure
**/ staticint i40e_validate_vf(struct i40e_pf *pf, int vf_id)
{ struct i40e_vsi *vsi; struct i40e_vf *vf; int ret = 0;
if (vf_id >= pf->num_alloc_vfs) {
dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
ret = -EINVAL; goto err_out;
}
vf = &pf->vf[vf_id];
vsi = i40e_find_vsi_from_id(pf, vf->lan_vsi_id); if (!vsi)
ret = -EINVAL;
err_out: return ret;
}
/* When the VF is resetting wait until it is done. *Itcantakeupto200milliseconds,butwaitfor *upto300millisecondstobesafe.
*/ for (i = 0; i < 15; i++) { if (test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) returntrue;
msleep(20);
}
if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
dev_err(&vf->pf->pdev->dev, "VF %d still in reset. Try again.\n", vf->vf_id); returnfalse;
}
returntrue;
}
/** *i40e_ndo_set_vf_mac *@netdev:networkinterfacedevicestructure *@vf_id:VFidentifier *@mac:macaddress * *programVFmacaddress
**/ int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
{ struct i40e_netdev_priv *np = netdev_priv(netdev); struct i40e_vsi *vsi = np->vsi; struct i40e_pf *pf = vsi->back; struct i40e_mac_filter *f; struct i40e_vf *vf; int ret = 0; struct hlist_node *h; int bkt;
if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n"); return -EAGAIN;
}
/* validate the request */
ret = i40e_validate_vf(pf, vf_id); if (ret) goto error_param;
vf = &pf->vf[vf_id]; if (!i40e_check_vf_init_timeout(vf)) {
ret = -EAGAIN; goto error_param;
}
vsi = pf->vsi[vf->lan_vsi_idx];
if (is_multicast_ether_addr(mac)) {
dev_err(&pf->pdev->dev, "Invalid Ethernet address %pM for VF %d\n", mac, vf_id);
ret = -EINVAL; goto error_param;
}
/* Lock once because below invoked function add/del_filter requires *mac_filter_hash_locktobeheld
*/
spin_lock_bh(&vsi->mac_filter_hash_lock);
/* delete the temporary mac address */ if (!is_zero_ether_addr(vf->default_lan_addr.addr))
i40e_del_mac_filter(vsi, vf->default_lan_addr.addr);
/* Delete all the filters for this VSI - we're going to kill it *anyway.
*/
hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
__i40e_del_filter(vsi, f);
spin_unlock_bh(&vsi->mac_filter_hash_lock);
/* program mac filter */ if (i40e_sync_vsi_filters(vsi)) {
dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
ret = -EIO; goto error_param;
}
ether_addr_copy(vf->default_lan_addr.addr, mac);
if (is_zero_ether_addr(mac)) {
vf->pf_set_mac = false;
dev_info(&pf->pdev->dev, "Removing MAC on VF %d\n", vf_id);
} else {
vf->pf_set_mac = true;
dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n",
mac, vf_id);
}
/* Force the VF interface down so it has to bring up with new MAC *address
*/
i40e_vc_reset_vf(vf, true);
dev_info(&pf->pdev->dev, "Bring down and up the VF interface to make this change effective.\n");
if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n"); return -EAGAIN;
}
/* validate the request */
ret = i40e_validate_vf(pf, vf_id); if (ret) goto error_pvid;
if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
ret = -EINVAL; goto error_pvid;
}
if (vlan_proto != htons(ETH_P_8021Q)) {
dev_err(&pf->pdev->dev, "VF VLAN protocol is not supported\n");
ret = -EPROTONOSUPPORT; goto error_pvid;
}
vf = &pf->vf[vf_id]; if (!i40e_check_vf_init_timeout(vf)) {
ret = -EAGAIN; goto error_pvid;
}
vsi = pf->vsi[vf->lan_vsi_idx];
if (le16_to_cpu(vsi->info.pvid) == vlanprio) /* duplicate request, so just return success */ goto error_pvid;
i40e_vlan_stripping_enable(vsi);
/* Locked once because multiple functions below iterate list */
spin_lock_bh(&vsi->mac_filter_hash_lock);
/* Check for condition where there was already a port VLAN ID *filtersetandnowitisbeingdeletedbysettingittozero. *Additionallycheckfortheconditionwheretherewasaport *VLANbutnowthereisanewanddifferentportVLANbeingset. *BeforedeletingalltheoldVLANfilterswemustaddnewones *with-1(I40E_VLAN_ANY)orotherwisewe'releftwithallour *MACaddressesdeleted.
*/ if ((!(vlan_id || qos) ||
vlanprio != le16_to_cpu(vsi->info.pvid)) &&
vsi->info.pvid) {
ret = i40e_add_vlan_all_mac(vsi, I40E_VLAN_ANY); if (ret) {
dev_info(&vsi->back->pdev->dev, "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
vsi->back->hw.aq.asq_last_status);
spin_unlock_bh(&vsi->mac_filter_hash_lock); goto error_pvid;
}
}
if (vsi->info.pvid) { /* remove all filters on the old VLAN */
i40e_rm_vlan_all_mac(vsi, (le16_to_cpu(vsi->info.pvid) &
VLAN_VID_MASK));
}
spin_unlock_bh(&vsi->mac_filter_hash_lock);
/* disable promisc modes in case they were enabled */
ret = i40e_config_vf_promiscuous_mode(vf, vf->lan_vsi_id,
allmulti, alluni); if (ret) {
dev_err(&pf->pdev->dev, "Unable to config VF promiscuous mode\n"); goto error_pvid;
}
if (vlan_id || qos)
ret = i40e_vsi_add_pvid(vsi, vlanprio); else
i40e_vsi_remove_pvid(vsi);
spin_lock_bh(&vsi->mac_filter_hash_lock);
if (vlan_id) {
dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
vlan_id, qos, vf_id);
/* add new VLAN filter for each MAC */
ret = i40e_add_vlan_all_mac(vsi, vlan_id); if (ret) {
dev_info(&vsi->back->pdev->dev, "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
vsi->back->hw.aq.asq_last_status);
spin_unlock_bh(&vsi->mac_filter_hash_lock); goto error_pvid;
}
/* remove the previously added non-VLAN MAC filters */
i40e_rm_vlan_all_mac(vsi, I40E_VLAN_ANY);
}
spin_unlock_bh(&vsi->mac_filter_hash_lock);
if (test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states))
alluni = true;
if (test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))
allmulti = true;
/* Schedule the worker thread to take care of applying changes */
i40e_service_event_schedule(vsi->back);
if (ret) {
dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n"); goto error_pvid;
}
/* The Port VLAN needs to be saved across resets the same as the *defaultLANMACaddress.
*/
vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
i40e_vc_reset_vf(vf, true); /* During reset the VF got a new VSI, so refresh a pointer. */
vsi = pf->vsi[vf->lan_vsi_idx];
ret = i40e_config_vf_promiscuous_mode(vf, vsi->id, allmulti, alluni); if (ret) {
dev_err(&pf->pdev->dev, "Unable to config vf promiscuous mode\n"); goto error_pvid;
}
/** *i40e_ndo_set_vf_bw *@netdev:networkinterfacedevicestructure *@vf_id:VFidentifier *@min_tx_rate:MinimumTxrate *@max_tx_rate:MaximumTxrate * *configureVFTxrate
**/ int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate, int max_tx_rate)
{ struct i40e_netdev_priv *np = netdev_priv(netdev); struct i40e_pf *pf = np->vsi->back; struct i40e_vsi *vsi; struct i40e_vf *vf; int ret = 0;
if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n"); return -EAGAIN;
}
/* validate the request */
ret = i40e_validate_vf(pf, vf_id); if (ret) goto error;
if (min_tx_rate) {
dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
min_tx_rate, vf_id);
ret = -EINVAL; goto error;
}
vf = &pf->vf[vf_id]; if (!i40e_check_vf_init_timeout(vf)) {
ret = -EAGAIN; goto error;
}
vsi = pf->vsi[vf->lan_vsi_idx];
ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate); if (ret) goto error;
/** *i40e_ndo_get_vf_config *@netdev:networkinterfacedevicestructure *@vf_id:VFidentifier *@ivi:VFconfigurationstructure * *returnVFconfiguration
**/ int i40e_ndo_get_vf_config(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi)
{ struct i40e_netdev_priv *np = netdev_priv(netdev); struct i40e_vsi *vsi = np->vsi; struct i40e_pf *pf = vsi->back; struct i40e_vf *vf; int ret = 0;
if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n"); return -EAGAIN;
}
/* validate the request */
ret = i40e_validate_vf(pf, vf_id); if (ret) goto error_param;
vf = &pf->vf[vf_id]; /* first vsi is always the LAN vsi */
vsi = pf->vsi[vf->lan_vsi_idx]; if (!vsi) {
ret = -ENOENT; goto error_param;
}
/** *i40e_ndo_set_vf_link_state *@netdev:networkinterfacedevicestructure *@vf_id:VFidentifier *@link:requiredlinkstate * *SetthelinkstateofaspecifiedVF,regardlessofphysicallinkstate
**/ int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
{ struct i40e_netdev_priv *np = netdev_priv(netdev); struct i40e_pf *pf = np->vsi->back; struct i40e_link_status *ls = &pf->hw.phy.link_info; struct virtchnl_pf_event pfe; struct i40e_hw *hw = &pf->hw; struct i40e_vsi *vsi; unsignedlong q_map; struct i40e_vf *vf; int abs_vf_id; int ret = 0; int tmp;
if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n"); return -EAGAIN;
}
/* validate the request */ if (vf_id >= pf->num_alloc_vfs) {
dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
ret = -EINVAL; goto error_out;
}
vsi = pf->vsi[vf->lan_vsi_idx];
q_map = BIT(vsi->num_queue_pairs) - 1;
vf->is_disabled_from_host = true;
/* Try to stop both Tx&Rx rings even if one of the calls fails *toensurewestoptheringsevenincaseoferrors. *Ifanyofthemreturnswithanerrorthenthefirst *errorthatoccurredwillbereturned.
*/
tmp = i40e_ctrl_vf_tx_rings(vsi, q_map, false);
ret = i40e_ctrl_vf_rx_rings(vsi, q_map, false);
ret = tmp ? tmp : ret; break; default:
ret = -EINVAL; goto error_out;
} /* Notify the VF of its new link state */
i40e_aq_send_msg_to_vf(hw, abs_vf_id, VIRTCHNL_OP_EVENT, 0, (u8 *)&pfe, sizeof(pfe), NULL);
if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n"); return -EAGAIN;
}
/* validate the request */ if (vf_id >= pf->num_alloc_vfs) {
dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
ret = -EINVAL; goto out;
}
vf = &(pf->vf[vf_id]); if (!i40e_check_vf_init_timeout(vf)) {
ret = -EAGAIN; goto out;
}
if (enable == vf->spoofchk) goto out;
vf->spoofchk = enable;
memset(&ctxt, 0, sizeof(ctxt));
ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
ctxt.pf_num = pf->hw.pf_id;
ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID); if (enable)
ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL); if (ret) {
dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
ret);
ret = -EIO;
}
out:
clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state); return ret;
}
/** *i40e_ndo_set_vf_trust *@netdev:networkinterfacedevicestructureofthepf *@vf_id:VFidentifier *@setting:trustsetting * *EnableordisableVFtrustsetting
**/ int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
{ struct i40e_netdev_priv *np = netdev_priv(netdev); struct i40e_pf *pf = np->vsi->back; struct i40e_vf *vf; int ret = 0;
if (test_and_set_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state)) {
dev_warn(&pf->pdev->dev, "Unable to configure VFs, other operation is pending.\n"); return -EAGAIN;
}
/* validate the request */ if (vf_id >= pf->num_alloc_vfs) {
dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
ret = -EINVAL; goto out;
}
if (test_bit(I40E_FLAG_MFP_ENA, pf->flags)) {
dev_err(&pf->pdev->dev, "Trusted VF not supported in MFP mode.\n");
ret = -EINVAL; goto out;
}
vf = &pf->vf[vf_id];
if (setting == vf->trusted) goto out;
vf->trusted = setting;
/* request PF to sync mac/vlan filters for the VF */
set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
pf->vsi[vf->lan_vsi_idx]->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
i40e_vc_reset_vf(vf, true);
dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
vf_id, setting ? "" : "un");
if (vf->adq_enabled) { if (!vf->trusted) {
dev_info(&pf->pdev->dev, "VF %u no longer Trusted, deleting all cloud filters\n",
vf_id);
i40e_del_all_cloud_filters(vf);
}
}
¤ 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.0.147Bemerkung:
¤
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.