Skip to content

Commit

Permalink
Merge pull request #9 from DmytroLinkin/master
Browse files Browse the repository at this point in the history
Auxiliary devices support
  • Loading branch information
adrianchiris authored Aug 11, 2022
2 parents 903adba + 0251650 commit 9f6303b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
30 changes: 22 additions & 8 deletions rdma_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
RdmaHwCountersDir = "hw_counters"

PciDevDir = "/sys/bus/pci/devices"
AuxDevDir = "/sys/bus/auxiliary/devices"

// For local usage
prevDir = ".."
Expand Down Expand Up @@ -356,17 +357,10 @@ func IsRDmaDeviceForNetdevice(netdevName string) bool {
return (rdma != "")
}

// Get list of RDMA devices for a pci device.
// When switchdev mode is used, there may be more than one rdma device.
// Example pcidevName: 0000:05:00:00,
// when found, returns list of devices one or more devices names such as
// mlx5_0, mlx5_10
//nolint:prealloc
func GetRdmaDevicesForPcidev(pcidevName string) []string {
func getRdmaDevicesFromDir(dirName string) []string {
var rdmadevs []string

dirName := filepath.Join(PciDevDir, pcidevName, RdmaClassName)

entries, err := ioutil.ReadDir(dirName)
if err != nil {
return rdmadevs
Expand All @@ -380,3 +374,23 @@ func GetRdmaDevicesForPcidev(pcidevName string) []string {
}
return rdmadevs
}

// Get list of RDMA devices for a pci device.
// When switchdev mode is used, there may be more than one rdma device.
// Example pcidevName: 0000:05:00.0,
// when found, returns list of devices one or more devices names such as
// mlx5_0, mlx5_10
func GetRdmaDevicesForPcidev(pcidevName string) []string {
dirName := filepath.Join(PciDevDir, pcidevName, RdmaClassName)
return getRdmaDevicesFromDir(dirName)
}

// Get list of RDMA devices for an auxiliary device.
// When switchdev mode is used, there may be more than one rdma device.
// Example deviceID: mlx5_core.sf.4,
// when found, returns list of devices one or more devices names such as
// mlx5_0, mlx5_10
func GetRdmaDevicesForAuxdev(deviceID string) []string {
dirName := filepath.Join(AuxDevDir, deviceID, RdmaClassName)
return getRdmaDevicesFromDir(dirName)
}
5 changes: 5 additions & 0 deletions rdma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ func TestRdmaDeviceForPcidev(t *testing.T) {
devs := GetRdmaDevicesForPcidev("0000:05:00.0")
t.Log("rdma devs :", devs)
}

func TestRdmaDeviceForAuxdev(t *testing.T) {
devs := GetRdmaDevicesForAuxdev("mlx5_core.sf.4")
t.Log("rdma devs :", devs)
}

0 comments on commit 9f6303b

Please sign in to comment.