diff --git a/pkg/host/internal/sriov/sriov.go b/pkg/host/internal/sriov/sriov.go index 64f1fa537e..017e9ef094 100644 --- a/pkg/host/internal/sriov/sriov.go +++ b/pkg/host/internal/sriov/sriov.go @@ -1000,6 +1000,18 @@ func (s *sriov) setEswitchMode(pciAddr, eswitchMode string) error { return nil } +type switchdevConfigureOrder int + +const ( + eswitchFirstThenVfs switchdevConfigureOrder = iota + vfsFirstThenEswitch +) + +var driverToSwitchdevConfigureOrder map[string]switchdevConfigureOrder = map[string]switchdevConfigureOrder{ + "ice": vfsFirstThenEswitch, + "mlx5_core": eswitchFirstThenVfs, +} + func (s *sriov) setEswitchModeAndNumVFs(pciAddr string, desiredEswitchMode string, numVFs int) error { log.Log.V(2).Info("setEswitchModeAndNumVFs(): configure VFs for device", "device", pciAddr, "count", numVFs, "mode", desiredEswitchMode) @@ -1011,13 +1023,34 @@ func (s *sriov) setEswitchModeAndNumVFs(pciAddr string, desiredEswitchMode strin return err } } - if err := s.SetSriovNumVfs(pciAddr, numVFs); err != nil { + + + pfDriverName, err := s.dputilsLib.GetDriverName(pciAddr) + if err != nil { return err } - if desiredEswitchMode == sriovnetworkv1.ESwithModeSwitchDev { - return s.setEswitchMode(pciAddr, sriovnetworkv1.ESwithModeSwitchDev) + configureOrder, ok := driverToSwitchdevConfigureOrder[pfDriverName] + if !ok || configureOrder == eswitchFirstThenVfs { + if err := s.SetSriovNumVfs(pciAddr, numVFs); err != nil { + return err + } + + if desiredEswitchMode == sriovnetworkv1.ESwithModeSwitchDev { + return s.setEswitchMode(pciAddr, sriovnetworkv1.ESwithModeSwitchDev) + } + } else { + if desiredEswitchMode == sriovnetworkv1.ESwithModeSwitchDev { + if err := s.setEswitchMode(pciAddr, sriovnetworkv1.ESwithModeSwitchDev); err != nil { + return err + } + } + + if err := s.SetSriovNumVfs(pciAddr, numVFs); err != nil { + return err + } } + return nil } @@ -1035,3 +1068,5 @@ func (s *sriov) unbindAllVFsOnPF(addr string) error { } return nil } + +