Skip to content

Commit 12bb018

Browse files
bcreeley13Jeff Kirsher
authored andcommitted
ice: Refactor VF reset
Currently VF VSI are being reset twice during a PFR or greater. This is causing reset, specifically resetting all VFs, to take too long. This is causing various issues with VF drivers not being able to gracefully handle the VF reset timeout. Fix this by refactoring how VF reset is handled for the case mentioned previously and for the VFR/VFLR case. The refactor was done by doing the following: 1. Removing the call to ice_vsi_rebuild_by_type for ICE_VSI_VF VSI, which was causing the initial VSI rebuild. 2. Adding functions for pre/post VSI rebuild functions that can be called in both the reset all VFs case and reset individual VF case. 3. Adding VSI rebuild functions that are specific for the reset all VFs case and adding functions that are specific for the reset individual VF case. 4. Calling the pre-rebuild function, then the specific VSI rebuild function based on the reset type, and then calling the post-rebuild function to handle VF resets. This patch series makes some assumptions about how VSI are handling by FW during reset: 1. During a PFR or greater all VSI in FW will be cleared. 2. During a VFR/VFLR the VSI rebuild responsibility is in the hands of the PF software. 3. There is code in the ice_reset_all_vfs() case to amortize operations if possible. This was left intact. 4. PF software should not be replaying VSI based filters that were added other than host configured, PF software configured, or the VF's default/LAA MAC. This is the VF drivers job after it has been reset. Signed-off-by: Brett Creeley <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent a58e1d8 commit 12bb018

File tree

2 files changed

+130
-187
lines changed

2 files changed

+130
-187
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,6 +4897,11 @@ static void ice_update_pf_netdev_link(struct ice_pf *pf)
48974897
* ice_rebuild - rebuild after reset
48984898
* @pf: PF to rebuild
48994899
* @reset_type: type of reset
4900+
*
4901+
* Do not rebuild VF VSI in this flow because that is already handled via
4902+
* ice_reset_all_vfs(). This is because requirements for resetting a VF after a
4903+
* PFR/CORER/GLOBER/etc. are different than the normal flow. Also, we don't want
4904+
* to reset/rebuild all the VF VSI twice.
49004905
*/
49014906
static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
49024907
{
@@ -4994,14 +4999,6 @@ static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
49944999
goto err_vsi_rebuild;
49955000
}
49965001

4997-
if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4998-
err = ice_vsi_rebuild_by_type(pf, ICE_VSI_VF);
4999-
if (err) {
5000-
dev_err(dev, "VF VSI rebuild failed: %d\n", err);
5001-
goto err_vsi_rebuild;
5002-
}
5003-
}
5004-
50055002
/* If Flow Director is active */
50065003
if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
50075004
err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL);

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

Lines changed: 125 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,7 @@ static void ice_trigger_vf_reset(struct ice_vf *vf, bool is_vflr, bool is_pfr)
413413
clear_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
414414

415415
/* Disable VF's configuration API during reset. The flag is re-enabled
416-
* in ice_alloc_vf_res(), when it's safe again to access VF's VSI.
417-
* It's normally disabled in ice_free_vf_res(), but it's safer
418-
* to do it earlier to give some time to finish to any VF config
419-
* functions that may still be running at this point.
416+
* when it's safe again to access VF's VSI.
420417
*/
421418
clear_bit(ICE_VF_STATE_INIT, vf->vf_states);
422419

@@ -616,57 +613,6 @@ static int ice_vf_rebuild_host_mac_cfg(struct ice_vf *vf)
616613
return 0;
617614
}
618615

619-
/**
620-
* ice_alloc_vsi_res - Setup VF VSI and its resources
621-
* @vf: pointer to the VF structure
622-
*
623-
* Returns 0 on success, negative value on failure
624-
*/
625-
static int ice_alloc_vsi_res(struct ice_vf *vf)
626-
{
627-
struct ice_pf *pf = vf->pf;
628-
struct ice_vsi *vsi;
629-
struct device *dev;
630-
int ret;
631-
632-
dev = ice_pf_to_dev(pf);
633-
/* first vector index is the VFs OICR index */
634-
vf->first_vector_idx = ice_calc_vf_first_vector_idx(pf, vf);
635-
636-
vsi = ice_vf_vsi_setup(pf, pf->hw.port_info, vf->vf_id);
637-
if (!vsi) {
638-
dev_err(dev, "Failed to create VF VSI\n");
639-
return -ENOMEM;
640-
}
641-
642-
vf->lan_vsi_idx = vsi->idx;
643-
vf->lan_vsi_num = vsi->vsi_num;
644-
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;
650-
}
651-
652-
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-
}
659-
660-
/* Clear this bit after VF initialization since we shouldn't reclaim
661-
* and reassign interrupts for synchronous or asynchronous VFR events.
662-
* We don't want to reconfigure interrupts since AVF driver doesn't
663-
* expect vector assignment to be changed unless there is a request for
664-
* more vectors.
665-
*/
666-
ice_alloc_vsi_res_exit:
667-
return ret;
668-
}
669-
670616
/**
671617
* ice_vf_set_host_trust_cfg - set trust setting based on pre-reset value
672618
* @vf: VF to configure trust setting for
@@ -679,43 +625,6 @@ static void ice_vf_set_host_trust_cfg(struct ice_vf *vf)
679625
clear_bit(ICE_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
680626
}
681627

682-
/**
683-
* ice_alloc_vf_res - Allocate VF resources
684-
* @vf: pointer to the VF structure
685-
*/
686-
static int ice_alloc_vf_res(struct ice_vf *vf)
687-
{
688-
struct ice_pf *pf = vf->pf;
689-
int tx_rx_queue_left;
690-
int status;
691-
692-
/* Update number of VF queues, in case VF had requested for queue
693-
* changes
694-
*/
695-
tx_rx_queue_left = min_t(int, ice_get_avail_txq_count(pf),
696-
ice_get_avail_rxq_count(pf));
697-
tx_rx_queue_left += pf->num_qps_per_vf;
698-
if (vf->num_req_qs && vf->num_req_qs <= tx_rx_queue_left &&
699-
vf->num_req_qs != vf->num_vf_qs)
700-
vf->num_vf_qs = vf->num_req_qs;
701-
702-
/* setup VF VSI and necessary resources */
703-
status = ice_alloc_vsi_res(vf);
704-
if (status)
705-
goto ice_alloc_vf_res_exit;
706-
707-
ice_vf_set_host_trust_cfg(vf);
708-
709-
/* VF is now completely initialized */
710-
set_bit(ICE_VF_STATE_INIT, vf->vf_states);
711-
712-
return status;
713-
714-
ice_alloc_vf_res_exit:
715-
ice_free_vf_res(vf);
716-
return status;
717-
}
718-
719628
/**
720629
* ice_ena_vf_msix_mappings - enable VF MSIX mappings in hardware
721630
* @vf: VF to enable MSIX mappings for
@@ -1042,48 +951,6 @@ static void ice_clear_vf_reset_trigger(struct ice_vf *vf)
1042951
ice_flush(hw);
1043952
}
1044953

1045-
/**
1046-
* ice_cleanup_and_realloc_vf - Clean up VF and reallocate resources after reset
1047-
* @vf: pointer to the VF structure
1048-
*
1049-
* Cleanup a VF after the hardware reset is finished. Expects the caller to
1050-
* have verified whether the reset is finished properly, and ensure the
1051-
* minimum amount of wait time has passed. Reallocate VF resources back to make
1052-
* VF state active
1053-
*/
1054-
static void ice_cleanup_and_realloc_vf(struct ice_vf *vf)
1055-
{
1056-
struct ice_pf *pf = vf->pf;
1057-
struct ice_hw *hw;
1058-
1059-
hw = &pf->hw;
1060-
1061-
/* Allow HW to access VF memory after calling
1062-
* ice_clear_vf_reset_trigger(). If we did it any sooner, HW could
1063-
* access memory while it was being freed in ice_free_vf_res(), causing
1064-
* an IOMMU fault.
1065-
*
1066-
* On the other hand, this needs to be done ASAP, because the VF driver
1067-
* is waiting for this to happen and may report a timeout. It's
1068-
* harmless, but it gets logged into Guest OS kernel log, so best avoid
1069-
* it.
1070-
*/
1071-
ice_clear_vf_reset_trigger(vf);
1072-
1073-
/* reallocate VF resources to finish resetting the VSI state */
1074-
if (!ice_alloc_vf_res(vf)) {
1075-
ice_ena_vf_mappings(vf);
1076-
set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
1077-
clear_bit(ICE_VF_STATE_DIS, vf->vf_states);
1078-
}
1079-
1080-
/* Tell the VF driver the reset is done. This needs to be done only
1081-
* after VF has been fully initialized, because the VF driver may
1082-
* request resources immediately after setting this flag.
1083-
*/
1084-
wr32(hw, VFGEN_RSTAT(vf->vf_id), VIRTCHNL_VFR_VFACTIVE);
1085-
}
1086-
1087954
/**
1088955
* ice_vf_set_vsi_promisc - set given VF VSI to given promiscuous mode(s)
1089956
* @vf: pointer to the VF info
@@ -1125,44 +992,134 @@ ice_vf_set_vsi_promisc(struct ice_vf *vf, struct ice_vsi *vsi, u8 promisc_m,
1125992
return status;
1126993
}
1127994

995+
static void ice_vf_clear_counters(struct ice_vf *vf)
996+
{
997+
struct ice_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
998+
999+
vf->num_mac = 0;
1000+
vsi->num_vlan = 0;
1001+
memset(&vf->mdd_tx_events, 0, sizeof(vf->mdd_tx_events));
1002+
memset(&vf->mdd_rx_events, 0, sizeof(vf->mdd_rx_events));
1003+
}
1004+
11281005
/**
1129-
* ice_config_res_vfs - Finalize allocation of VFs resources in one go
1130-
* @pf: pointer to the PF structure
1006+
* ice_vf_pre_vsi_rebuild - tasks to be done prior to VSI rebuild
1007+
* @vf: VF to perform pre VSI rebuild tasks
11311008
*
1132-
* This function is being called as last part of resetting all VFs, or when
1133-
* configuring VFs for the first time, where there is no resource to be freed
1134-
* Returns true if resources were properly allocated for all VFs, and false
1135-
* otherwise.
1009+
* These tasks are items that don't need to be amortized since they are most
1010+
* likely called in a for loop with all VF(s) in the reset_all_vfs() case.
11361011
*/
1137-
static bool ice_config_res_vfs(struct ice_pf *pf)
1012+
static void ice_vf_pre_vsi_rebuild(struct ice_vf *vf)
11381013
{
1139-
struct device *dev = ice_pf_to_dev(pf);
1140-
struct ice_hw *hw = &pf->hw;
1141-
int v;
1014+
ice_vf_clear_counters(vf);
1015+
ice_clear_vf_reset_trigger(vf);
1016+
}
11421017

1143-
if (ice_set_per_vf_res(pf)) {
1144-
dev_err(dev, "Cannot allocate VF resources, try with fewer number of VFs\n");
1145-
return false;
1018+
/**
1019+
* ice_vf_rebuild_host_cfg - host admin configuration is persistent across reset
1020+
* @vf: VF to rebuild host configuration on
1021+
*/
1022+
static void ice_vf_rebuild_host_cfg(struct ice_vf *vf)
1023+
{
1024+
struct device *dev = ice_pf_to_dev(vf->pf);
1025+
1026+
ice_vf_set_host_trust_cfg(vf);
1027+
1028+
if (ice_vf_rebuild_host_mac_cfg(vf))
1029+
dev_err(dev, "failed to rebuild default MAC configuration for VF %d\n",
1030+
vf->vf_id);
1031+
1032+
if (ice_vf_rebuild_host_vlan_cfg(vf))
1033+
dev_err(dev, "failed to rebuild VLAN configuration for VF %u\n",
1034+
vf->vf_id);
1035+
}
1036+
1037+
/**
1038+
* ice_vf_rebuild_vsi_with_release - release and setup the VF's VSI
1039+
* @vf: VF to release and setup the VSI for
1040+
*
1041+
* This is only called when a single VF is being reset (i.e. VFR, VFLR, host VF
1042+
* configuration change, etc.).
1043+
*/
1044+
static int ice_vf_rebuild_vsi_with_release(struct ice_vf *vf)
1045+
{
1046+
struct ice_pf *pf = vf->pf;
1047+
struct ice_vsi *vsi;
1048+
1049+
vsi = pf->vsi[vf->lan_vsi_idx];
1050+
ice_vsi_release(vsi);
1051+
vsi = ice_vf_vsi_setup(pf, pf->hw.port_info, vf->vf_id);
1052+
if (!vsi) {
1053+
dev_err(ice_pf_to_dev(pf), "Failed to create VF VSI\n");
1054+
return -ENOMEM;
11461055
}
11471056

1148-
/* rearm global interrupts */
1149-
if (test_and_clear_bit(__ICE_OICR_INTR_DIS, pf->state))
1150-
ice_irq_dynamic_ena(hw, NULL, NULL);
1057+
vf->lan_vsi_idx = vsi->idx;
1058+
vf->lan_vsi_num = vsi->vsi_num;
11511059

1152-
/* Finish resetting each VF and allocate resources */
1153-
ice_for_each_vf(pf, v) {
1154-
struct ice_vf *vf = &pf->vf[v];
1060+
return 0;
1061+
}
11551062

1156-
vf->num_vf_qs = pf->num_qps_per_vf;
1157-
dev_dbg(dev, "VF-id %d has %d queues configured\n", vf->vf_id,
1158-
vf->num_vf_qs);
1159-
ice_cleanup_and_realloc_vf(vf);
1063+
/**
1064+
* ice_vf_rebuild_vsi - rebuild the VF's VSI
1065+
* @vf: VF to rebuild the VSI for
1066+
*
1067+
* This is only called when all VF(s) are being reset (i.e. PCIe Reset on the
1068+
* host, PFR, CORER, etc.).
1069+
*/
1070+
static int ice_vf_rebuild_vsi(struct ice_vf *vf)
1071+
{
1072+
struct ice_pf *pf = vf->pf;
1073+
struct ice_vsi *vsi;
1074+
1075+
vsi = pf->vsi[vf->lan_vsi_idx];
1076+
1077+
if (ice_vsi_rebuild(vsi, true)) {
1078+
dev_err(ice_pf_to_dev(pf), "failed to rebuild VF %d VSI\n",
1079+
vf->vf_id);
1080+
return -EIO;
11601081
}
1082+
/* vsi->idx will remain the same in this case so don't update
1083+
* vf->lan_vsi_idx
1084+
*/
1085+
vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
1086+
vf->lan_vsi_num = vsi->vsi_num;
11611087

1162-
ice_flush(hw);
1163-
clear_bit(__ICE_VF_DIS, pf->state);
1088+
return 0;
1089+
}
11641090

1165-
return true;
1091+
/**
1092+
* ice_vf_set_initialized - VF is ready for VIRTCHNL communication
1093+
* @vf: VF to set in initialized state
1094+
*
1095+
* After this function the VF will be ready to receive/handle the
1096+
* VIRTCHNL_OP_GET_VF_RESOURCES message
1097+
*/
1098+
static void ice_vf_set_initialized(struct ice_vf *vf)
1099+
{
1100+
ice_set_vf_state_qs_dis(vf);
1101+
clear_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states);
1102+
clear_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states);
1103+
clear_bit(ICE_VF_STATE_DIS, vf->vf_states);
1104+
set_bit(ICE_VF_STATE_INIT, vf->vf_states);
1105+
}
1106+
1107+
/**
1108+
* ice_vf_post_vsi_rebuild - tasks to do after the VF's VSI have been rebuilt
1109+
* @vf: VF to perform tasks on
1110+
*/
1111+
static void ice_vf_post_vsi_rebuild(struct ice_vf *vf)
1112+
{
1113+
struct ice_pf *pf = vf->pf;
1114+
struct ice_hw *hw;
1115+
1116+
hw = &pf->hw;
1117+
1118+
ice_vf_rebuild_host_cfg(vf);
1119+
1120+
ice_vf_set_initialized(vf);
1121+
ice_ena_vf_mappings(vf);
1122+
wr32(hw, VFGEN_RSTAT(vf->vf_id), VIRTCHNL_VFR_VFACTIVE);
11661123
}
11671124

11681125
/**
@@ -1232,21 +1189,13 @@ bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr)
12321189
ice_for_each_vf(pf, v) {
12331190
vf = &pf->vf[v];
12341191

1235-
ice_free_vf_res(vf);
1236-
1237-
/* Free VF queues as well, and reallocate later.
1238-
* If a given VF has different number of queues
1239-
* configured, the request for update will come
1240-
* via mailbox communication.
1241-
*/
1242-
vf->num_vf_qs = 0;
1192+
ice_vf_pre_vsi_rebuild(vf);
1193+
ice_vf_rebuild_vsi(vf);
1194+
ice_vf_post_vsi_rebuild(vf);
12431195
}
12441196

1245-
if (ice_sriov_free_msix_res(pf))
1246-
dev_err(dev, "Failed to free MSIX resources used by SR-IOV\n");
1247-
1248-
if (!ice_config_res_vfs(pf))
1249-
return false;
1197+
ice_flush(hw);
1198+
clear_bit(__ICE_VF_DIS, pf->state);
12501199

12511200
return true;
12521201
}
@@ -1358,12 +1307,9 @@ bool ice_reset_vf(struct ice_vf *vf, bool is_vflr)
13581307
dev_err(dev, "disabling promiscuous mode failed\n");
13591308
}
13601309

1361-
/* free VF resources to begin resetting the VSI state */
1362-
ice_free_vf_res(vf);
1363-
1364-
ice_cleanup_and_realloc_vf(vf);
1365-
1366-
ice_flush(hw);
1310+
ice_vf_pre_vsi_rebuild(vf);
1311+
ice_vf_rebuild_vsi_with_release(vf);
1312+
ice_vf_post_vsi_rebuild(vf);
13671313

13681314
return true;
13691315
}

0 commit comments

Comments
 (0)