Skip to content

Instantly share code, notes, and snippets.

@singchia
Last active January 30, 2024 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save singchia/60357856c02582937f2d4b5a6167a8e9 to your computer and use it in GitHub Desktop.
Save singchia/60357856c02582937f2d4b5a6167a8e9 to your computer and use it in GitHub Desktop.
list dpdk supported nics
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