Skip to content

Commit

Permalink
feat: implement MlxResetFW to reset the FW on VF changes
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Giese <tgiese@nvidia.com>
  • Loading branch information
tobiasgiese committed Jul 24, 2024
1 parent ee40683 commit 192422f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.sriov-network-config-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN make _build-sriov-network-config-daemon BIN_PATH=build/_output/cmd

FROM quay.io/centos/centos:stream9
ARG MSTFLINT=mstflint
RUN ARCH_DEP_PKGS=$(if [ "$(uname -m)" != "s390x" ]; then echo -n ${MSTFLINT} ; fi) && yum -y install hwdata $ARCH_DEP_PKGS && yum clean all
RUN ARCH_DEP_PKGS=$(if [ "$(uname -m)" != "s390x" ]; then echo -n ${MSTFLINT} ; fi) && yum -y install hwdata pciutils $ARCH_DEP_PKGS && yum clean all
LABEL io.k8s.display-name="sriov-network-config-daemon" \
io.k8s.description="This is a daemon that manage and config sriov network devices in Kubernetes cluster"
COPY --from=builder /go/src/github.com/k8snetworkplumbingwg/sriov-network-operator/build/_output/cmd/sriov-network-config-daemon /usr/bin/
Expand Down
14 changes: 14 additions & 0 deletions pkg/helper/mock/mock_helper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion pkg/plugins/mellanox/mellanox_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type MellanoxPlugin struct {
helpers helper.HostHelpersInterface
}

var pciAddressesToReset []string
var attributesToChange map[string]mlx.MlxNic
var mellanoxNicsStatus map[string]map[string]sriovnetworkv1.InterfaceExt
var mellanoxNicsSpec map[string]sriovnetworkv1.Interface
Expand Down Expand Up @@ -51,6 +52,7 @@ func (p *MellanoxPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeS
needDrain = false
needReboot = false
err = nil
pciAddressesToReset = []string{}
attributesToChange = map[string]mlx.MlxNic{}
mellanoxNicsStatus = map[string]map[string]sriovnetworkv1.InterfaceExt{}
mellanoxNicsSpec = map[string]sriovnetworkv1.Interface{}
Expand Down Expand Up @@ -131,6 +133,10 @@ func (p *MellanoxPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeS
if needReboot || changeWithoutReboot {
attributesToChange[ifaceSpec.PciAddress] = *attrs
}

if needReboot {
pciAddressesToReset = append(pciAddressesToReset, ifaceSpec.PciAddress)
}
}

// Set total VFs to 0 for mellanox interfaces with no spec
Expand Down Expand Up @@ -189,7 +195,10 @@ func (p *MellanoxPlugin) Apply() error {
return nil
}
log.Log.Info("mellanox plugin Apply()")
return p.helpers.MlxConfigFW(attributesToChange)
if err := p.helpers.MlxConfigFW(attributesToChange); err != nil {
return err
}
return p.helpers.MlxResetFW(pciAddressesToReset)
}

// nicHasExternallyManagedPFs returns true if one of the ports(interface) of the NIC is marked as externally managed
Expand Down
15 changes: 15 additions & 0 deletions pkg/vendors/mellanox/mellanox.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type MellanoxInterface interface {
GetMlxNicFwData(pciAddress string) (current, next *MlxNic, err error)

MlxConfigFW(attributesToChange map[string]MlxNic) error
MlxResetFW(pciAddresses []string) error
}

type mellanoxHelper struct {
Expand Down Expand Up @@ -141,6 +142,20 @@ func (m *mellanoxHelper) GetMellanoxBlueFieldMode(PciAddress string) (BlueFieldM
return -1, fmt.Errorf("MellanoxBlueFieldMode(): unknown device status for %s", PciAddress)
}

func (m *mellanoxHelper) MlxResetFW(pciAddresses []string) error {
log.Log.Info("mellanox-plugin resetFW()")
for _, pciAddress := range pciAddresses {
cmdArgs := []string{"-d", pciAddress, "-l", "3", "-y", "reset"}
log.Log.Info("mellanox-plugin: resetFW()", "cmd-args", cmdArgs)
_, stderr, err := m.utils.RunCommand("mstfwreset", cmdArgs...)
if err != nil {
log.Log.Error(err, "mellanox-plugin resetFW(): failed", "stderr", stderr)
return err
}
}
return nil
}

func (m *mellanoxHelper) MlxConfigFW(attributesToChange map[string]MlxNic) error {
log.Log.Info("mellanox-plugin configFW()")
for pciAddr, fwArgs := range attributesToChange {
Expand Down
14 changes: 14 additions & 0 deletions pkg/vendors/mellanox/mock/mock_mellanox.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 192422f

Please sign in to comment.