@@ -413,10 +413,7 @@ static void ice_trigger_vf_reset(struct ice_vf *vf, bool is_vflr, bool is_pfr)
413
413
clear_bit (ICE_VF_STATE_ACTIVE , vf -> vf_states );
414
414
415
415
/* 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.
420
417
*/
421
418
clear_bit (ICE_VF_STATE_INIT , vf -> vf_states );
422
419
@@ -616,57 +613,6 @@ static int ice_vf_rebuild_host_mac_cfg(struct ice_vf *vf)
616
613
return 0 ;
617
614
}
618
615
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
-
670
616
/**
671
617
* ice_vf_set_host_trust_cfg - set trust setting based on pre-reset value
672
618
* @vf: VF to configure trust setting for
@@ -679,43 +625,6 @@ static void ice_vf_set_host_trust_cfg(struct ice_vf *vf)
679
625
clear_bit (ICE_VIRTCHNL_VF_CAP_PRIVILEGE , & vf -> vf_caps );
680
626
}
681
627
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
-
719
628
/**
720
629
* ice_ena_vf_msix_mappings - enable VF MSIX mappings in hardware
721
630
* @vf: VF to enable MSIX mappings for
@@ -1042,48 +951,6 @@ static void ice_clear_vf_reset_trigger(struct ice_vf *vf)
1042
951
ice_flush (hw );
1043
952
}
1044
953
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
-
1087
954
/**
1088
955
* ice_vf_set_vsi_promisc - set given VF VSI to given promiscuous mode(s)
1089
956
* @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,
1125
992
return status ;
1126
993
}
1127
994
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
+
1128
1005
/**
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
1131
1008
*
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.
1136
1011
*/
1137
- static bool ice_config_res_vfs (struct ice_pf * pf )
1012
+ static void ice_vf_pre_vsi_rebuild (struct ice_vf * vf )
1138
1013
{
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
+ }
1142
1017
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 ;
1146
1055
}
1147
1056
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 ;
1151
1059
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
+ }
1155
1062
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 ;
1160
1081
}
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 ;
1161
1087
1162
- ice_flush ( hw ) ;
1163
- clear_bit ( __ICE_VF_DIS , pf -> state );
1088
+ return 0 ;
1089
+ }
1164
1090
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 );
1166
1123
}
1167
1124
1168
1125
/**
@@ -1232,21 +1189,13 @@ bool ice_reset_all_vfs(struct ice_pf *pf, bool is_vflr)
1232
1189
ice_for_each_vf (pf , v ) {
1233
1190
vf = & pf -> vf [v ];
1234
1191
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 );
1243
1195
}
1244
1196
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 );
1250
1199
1251
1200
return true;
1252
1201
}
@@ -1358,12 +1307,9 @@ bool ice_reset_vf(struct ice_vf *vf, bool is_vflr)
1358
1307
dev_err (dev , "disabling promiscuous mode failed\n" );
1359
1308
}
1360
1309
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 );
1367
1313
1368
1314
return true;
1369
1315
}
0 commit comments