Skip to content

Commit

Permalink
support yusur smartnic
Browse files Browse the repository at this point in the history
Signed-off-by: wangs <[email protected]>
  • Loading branch information
wangwangyusur288 committed Aug 13, 2024
1 parent 75ab775 commit 9010514
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/daemon/ovs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (csh cniServerHandler) configureDpdkNic(podName, podNamespace, provider, ne
func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns, containerID, vfDriver, ifName, mac string, mtu int, ip, gateway string, isDefaultRoute, detectIPConflict bool, routes []request.Route, _, _ []string, ingress, egress, deviceID, nicType, latency, limit, loss, jitter string, gwCheckMode int, u2oInterconnectionIP, oldPodName string) ([]request.Route, error) {
var err error
var hostNicName, containerNicName, pfPci string
var vfId int
var vfID int
if deviceID == "" {
hostNicName, containerNicName, err = setupVethPair(containerID, ifName, mtu)
if err != nil {
Expand All @@ -87,7 +87,7 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns,
}
}()
} else {
hostNicName, containerNicName, pfPci, vfId, err = setupSriovInterface(containerID, deviceID, vfDriver, ifName, mtu, mac)
hostNicName, containerNicName, pfPci, vfID, err = setupSriovInterface(containerID, deviceID, vfDriver, ifName, mtu, mac)
if err != nil {
klog.Errorf("failed to create sriov interfaces %v", err)
return nil, err
Expand All @@ -102,7 +102,7 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns,
// Add yusur ovs port
output, err := ovs.Exec(ovs.MayExist, "add-port", "br-int", hostNicName, "--",
"set", "interface", hostNicName, "type=dpdk",
fmt.Sprintf("options:dpdk-devargs=%s,representor=[%d]", pfPci, vfId),
fmt.Sprintf("options:dpdk-devargs=%s,representor=[%d]", pfPci, vfID),
fmt.Sprintf("mtu_request=%d", mtu),
fmt.Sprintf("external_ids:iface-id=%s", ifaceID),
fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName),
Expand Down
15 changes: 6 additions & 9 deletions pkg/net/yusur/yusur_sriovnet.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package yusur

import (
"errors"
"fmt"
"os"
"path"
Expand Down Expand Up @@ -34,29 +35,25 @@ func IsYusurSmartNic(pciAddress string) bool {
}

yusurSmartNic := strings.TrimSpace(string(platName))
if strings.HasSuffix(yusurSmartNic, YusurSmartNic) {
return true
}

return false
return strings.HasSuffix(yusurSmartNic, YusurSmartNic)
}

// GetYusurNicPfPciFromVfPci retrieves the PF PCI address
func GetYusurNicPfPciFromVfPci(vfPciAddress string) (string, error) {
pfPath := filepath.Join(PciSysDir, vfPciAddress, "physfn")
absPath, err := filepath.Abs(pfPath)
if err != nil || !strings.HasPrefix(absPath, PciSysDir) {
return "", fmt.Errorf("pfPath is not ")
return "", errors.New("pfPath is not ")
}

pciDevDir, err := os.Readlink(absPath)
if err != nil {
return "", fmt.Errorf("failed to read physfn link, provided address may not be a VF. %v", err)
return "", fmt.Errorf("failed to read physfn link, provided address may not be a VF. %w", err)
}

pf := path.Base(pciDevDir)
if pf == "" {
return pf, fmt.Errorf("could not find PF PCI Address")
return pf, errors.New("could not find PF PCI Address")
}
return pf, err
}
Expand All @@ -78,7 +75,7 @@ func GetYusurNicVfIndexByPciAddress(vfPciAddress string) (int, error) {
vfPath := filepath.Join(PciSysDir, vfPciAddress, "physfn", "virtfn*")
absPath, err := filepath.Abs(vfPath)
if err != nil || !strings.HasPrefix(absPath, PciSysDir) {
return -1, fmt.Errorf("pfPath is not ")
return -1, errors.New("pfPath is not ")
}

matches, err := filepath.Glob(absPath)
Expand Down

0 comments on commit 9010514

Please sign in to comment.