-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for BF2 in connectX mode
Fix the issue introduced in https://github.com/k8snetworkplumbingwg/sriov-network-operator/pull/240/files#r808624002 Allow to use BF in connectX mode also for OCP platform. This is needed until we support the systemd configuration Signed-off-by: Sebastian Sch <[email protected]>
- Loading branch information
Showing
5 changed files
with
154 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"github.com/golang/glog" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
//BlueField2 mode representation | ||
type BlueField2Mode int | ||
|
||
const ( | ||
bluefield2Dpu BlueField2Mode = iota | ||
bluefield2Conntexd | ||
|
||
internalCPUPageSupplier = "INTERNAL_CPU_PAGE_SUPPLIER" | ||
internalCPUEswitchManager = "INTERNAL_CPU_ESWITCH_MANAGER" | ||
internalCPUIbVporto = "INTERNAL_CPU_IB_VPORT0" | ||
internalCPUOffloadEngine = "INTERNAL_CPU_OFFLOAD_ENGINE" | ||
|
||
ecpf = "ECPF" | ||
extHostPf = "EXT_HOST_PF" | ||
|
||
disabled = "DISABLED" | ||
enabled = "ENABLED" | ||
) | ||
|
||
func MstConfigReadData(pciAddress string) (string, error) { | ||
glog.Infof("MstConfigReadData(): device %s", pciAddress) | ||
args := []string{"-e", "-d", pciAddress, "q"} | ||
out, err := RunCommand("mstconfig", args...) | ||
return out, err | ||
} | ||
|
||
func ParseMstconfigOutput(mstOutput string, attributes []string) (fwCurrent, fwNext map[string]string) { | ||
glog.Infof("ParseMstconfigOutput(): Attributes %v", attributes) | ||
fwCurrent = map[string]string{} | ||
fwNext = map[string]string{} | ||
formatRegex := regexp.MustCompile(`(?P<Attribute>\w+)\s+(?P<Default>\S+)\s+(?P<Current>\S+)\s+(?P<Next>\S+)`) | ||
mstOutputLines := strings.Split(mstOutput, "\n") | ||
for _, attr := range attributes { | ||
for _, line := range mstOutputLines { | ||
if strings.Contains(line, attr) { | ||
regexResult := formatRegex.FindStringSubmatch(line) | ||
fwCurrent[attr] = regexResult[3] | ||
fwNext[attr] = regexResult[4] | ||
break | ||
} | ||
} | ||
} | ||
return | ||
} | ||
|
||
func mellanoxBlueFieldMode(PciAddress string) (BlueField2Mode, error) { | ||
glog.V(2).Infof("MellanoxBlueFieldMode():checking mode for card %s", PciAddress) | ||
out, err := MstConfigReadData(PciAddress) | ||
if err != nil { | ||
glog.Errorf("MellanoxBlueFieldMode(): failed to get mlx nic fw data %v", err) | ||
return -1, fmt.Errorf("failed to get mlx nic fw data %v", err) | ||
} | ||
|
||
attrs := []string{internalCPUPageSupplier, internalCPUEswitchManager, internalCPUIbVporto, internalCPUOffloadEngine} | ||
mstCurrentData, _ := ParseMstconfigOutput(out, attrs) | ||
|
||
internalCPUPageSupplierstatus, exist := mstCurrentData[internalCPUPageSupplier] | ||
if !exist { | ||
return 0, fmt.Errorf("failed to find %s in the mstconfig output command", internalCPUPageSupplier) | ||
} | ||
|
||
internalCPUEswitchManagerStatus, exist := mstCurrentData[internalCPUEswitchManager] | ||
if !exist { | ||
return 0, fmt.Errorf("failed to find %s in the mstconfig output command", internalCPUEswitchManager) | ||
} | ||
|
||
internalCPUIbVportoStatus, exist := mstCurrentData[internalCPUIbVporto] | ||
if !exist { | ||
return 0, fmt.Errorf("failed to find %s in the mstconfig output command", internalCPUIbVporto) | ||
} | ||
internalCPUOffloadEngineStatus, exist := mstCurrentData[internalCPUOffloadEngine] | ||
if !exist { | ||
return 0, fmt.Errorf("failed to find %s in the mstconfig output command", internalCPUOffloadEngine) | ||
} | ||
|
||
// check for DPU | ||
if strings.Contains(internalCPUPageSupplierstatus, ecpf) && | ||
strings.Contains(internalCPUEswitchManagerStatus, ecpf) && | ||
strings.Contains(internalCPUIbVportoStatus, ecpf) && | ||
strings.Contains(internalCPUOffloadEngineStatus, enabled) { | ||
glog.V(2).Infof("MellanoxBlueFieldMode():card %s in DPU mode", PciAddress) | ||
return bluefield2Dpu, nil | ||
} else if strings.Contains(internalCPUPageSupplierstatus, extHostPf) && | ||
strings.Contains(internalCPUEswitchManagerStatus, extHostPf) && | ||
strings.Contains(internalCPUIbVportoStatus, extHostPf) && | ||
strings.Contains(internalCPUOffloadEngineStatus, disabled) { | ||
glog.V(2).Infof("MellanoxBlueFieldMode():card %s in ConnectX mode", PciAddress) | ||
return bluefield2Conntexd, nil | ||
} | ||
|
||
return -1, fmt.Errorf("MellanoxBlueFieldMode(): unknow card status for %s", PciAddress) | ||
} |