Skip to content

Commit

Permalink
set mellanox ib vf state to Follow
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyd1988 committed Sep 4, 2023
1 parent 73e7564 commit a34e58c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"math/rand"
"net"
"os"
Expand Down Expand Up @@ -323,11 +324,19 @@ func configSriovDevice(iface *sriovnetworkv1.Interface, ifaceStatus *sriovnetwor
return err
}

for _, addr := range vfAddrs {
for vfNum, addr := range vfAddrs {
var group sriovnetworkv1.VfGroup
i := 0
var dpdkDriver string
var isRdma bool

// LinkType is an optional field. Let's fallback to current link type
// if nothing is specified in the SriovNodePolicy
linkType := iface.LinkType
if linkType == "" {
linkType = ifaceStatus.LinkType
}

vfID, err := dputils.GetVFID(addr)
for i, group = range iface.VfGroups {
if err != nil {
Expand All @@ -346,12 +355,7 @@ func configSriovDevice(iface *sriovnetworkv1.Interface, ifaceStatus *sriovnetwor
// for userspace drivers like vfio we configure the vf mac using the kernel nic mac address
// before we switch to the userspace driver
if yes, d := hasDriver(addr); yes && !sriovnetworkv1.StringInArray(d, DpdkDrivers) {
// LinkType is an optional field. Let's fallback to current link type
// if nothing is specified in the SriovNodePolicy
linkType := iface.LinkType
if linkType == "" {
linkType = ifaceStatus.LinkType
}

if strings.EqualFold(linkType, constants.LinkTypeIB) {
if err = setVfGUID(addr, pfLink); err != nil {
return err
Expand Down Expand Up @@ -402,6 +406,15 @@ func configSriovDevice(iface *sriovnetworkv1.Interface, ifaceStatus *sriovnetwor
return err
}
}

// Set the vf state to "Follow"
if strings.EqualFold(linkType, constants.LinkTypeIB) && "mlx5_core" == ifaceStatus.Driver {
devicePolicyPath := filepath.Join(sysClassNet, ifaceStatus.Name, "device/sriov/"+strconv.Itoa(vfNum)+"/policy")
if err := ioutil.WriteFile(devicePolicyPath, []byte("Follow"), 0666); err != nil {
glog.Warningf("configSriovDevice(): fail to set vf state %s: %v", devicePolicyPath, err)
return err
}
}
}
}
// Set PF link up
Expand Down

0 comments on commit a34e58c

Please sign in to comment.