Last active
January 30, 2024 07:01
-
-
Save singchia/60357856c02582937f2d4b5a6167a8e9 to your computer and use it in GitHub Desktop.
list dpdk supported nics
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"github.com/jaypipes/ghw" | |
) | |
var ( | |
dpdkSupportedDrivers = map[string]bool{ | |
"axgbe": true, // AMD | |
"ionic": true, // AMD Pensando | |
"ena": true, // Amazon | |
"atlantic": true, // Aquantia | |
"ark": true, // Atomic Rules | |
"bnxt": true, // Broadcom | |
"cxgbe": true, // Chelsio | |
"enic": true, // Cisco | |
"gve": true, // Google | |
"hns3": true, // Hisilicon | |
"hinic": true, // Huawei | |
"cpfl": true, "e1000": true, "fm10k": true, "i40e": true, "ice": true, "idpf": true, "ifc": true, "igc": true, "ipn3ke": true, "ixgbe": true, // Intel | |
"bnx2x": true, "liquidio": true, "mvneta": true, "mvpp2": true, "octeontx": true, "octeontx2": true, "thunderx": true, "cnxk": true, "qede": true, // Marvell | |
"mana": true, // Microsoft | |
"mlx4": true, "mlx5": true, // NVIDIA | |
"dpaa": true, "dpaa2": true, "enetc": true, "enetfec": true, "pfe": true, // NXP | |
"nfb": true, // Netcope, Netronome | |
"sfc": true, // Solarflare | |
"ngbe": true, "txgbe": true, // Wangxun | |
"igb_uio": true, "uio_generic_pci": true, // already bounded | |
} | |
) | |
type Nic struct { | |
Name string | |
PCIAddress string | |
Driver string | |
} | |
func main() { | |
pciNics := map[string]*Nic{} | |
nics := struct { | |
Nics []*Nic `json:"nics"` | |
}{} | |
pci, err := ghw.PCI() | |
if err != nil { | |
fmt.Printf("get pci err: %s", err) | |
return | |
} | |
for _, dev := range pci.Devices { | |
_, ok := dpdkSupportedDrivers[dev.Driver] | |
if dev.Subclass.Name == "Ethernet controller" && ok { | |
pciNics[dev.Address] = &Nic{ | |
Driver: dev.Driver, | |
PCIAddress: dev.Address, | |
} | |
} | |
} | |
net, err := ghw.Network() | |
if err != nil { | |
fmt.Printf("get network err: %s", err) | |
} | |
for _, nic := range net.NICs { | |
if nic.PCIAddress != nil { | |
pn, ok := pciNics[*nic.PCIAddress] | |
if !ok { | |
continue | |
} | |
pn.Name = nic.Name | |
} | |
} | |
for _, nic := range pciNics { | |
nics.Nics = append(nics.Nics, nic) | |
} | |
data, _ := json.Marshal(nics) | |
fmt.Printf("%v\n", string(data)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment