pcidevices

package
v0.0.0-...-8fa78e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

Go-P4Pack pcidevices Package

This package helps to query DPDK compatibles pci devices and to bind/unbind drivers to pci devices in the Linux Kernel. With this package the commands of dpdk-devbind.py can be re-created in Go.

API

The package exports the following API functions that return a PciDevice pointer or an array of PciDevice pointers:

New(id string) (*PciDevice, error)                             // input supports PCI identifier string or NIC name
NewDeviceByPciID(pciID string) (*PciDevice, error)
NewDeviceByNicName(nicName string) (*PciDevice, error)
GetPciDevices(classFilter ClassesFilter) ([]*PciDevice, error) // returns a filtered list of current active PCI devs

The PciDevice supports the following methods:

PciDevice.Bind(driver string) error
PciDevice.Unbind() error
PciDevice.Probe() error
PciDevice.CurrentDriver() (string, error)
PciDevice.ID() string
PciDevice.String() string

ClassFilter values:

AllDevices
NetworkDevices
BasebandDevices
CryptoDevices
DmaDevices
EventdevDevices
MempoolDevices
CompressDevices
RegexDevices
MiscDevices

Extra exported low level API functions

Lower Level API functions:

BindPci(devID, driver, vendor, device string) (string, error)
UnbindPci(devID, driver string) error
ProbePci(devID string) (string, error)
GetCurrentPciDriver(devID string) (string, error)
IsModuleLoaded(driver string) bool

Documentation

Overview

Package pcidevices helps to query DPDK compatibles devices and to bind/unbind drivers

Package pcidevices helps to query DPDK compatibles devices and to bind/unbind drivers

Package pcidevices helps to query DPDK compatibles devices and to bind/unbind drivers

Package pcidevices helps to query DPDK compatibles devices and to bind/unbind drivers

Index

Constants

View Source
const (
	DriverUioPciGeneric = "uio_pci_generic"
	DriverIgbUio        = "igb_uio"
	DriverVfioPci       = "vfio-pci"
)

Driver names

View Source
const (
	PathSysPciDevices     = "/sys/bus/pci/devices"
	PathSysPciDrivers     = "/sys/bus/pci/drivers"
	PathSysPciDriverProbe = "/sys/bus/pci/drivers_probe"
)

Path to PCI

View Source
const (
	PathSysClassNet = "/sys/class/net"
)

Path to net

Variables

View Source
var (
	DefaultDpdkDriver = DriverVfioPci
	DpdkDrivers       = [...]string{DriverUioPciGeneric, DriverIgbUio, DriverVfioPci}
	DpdkPciDrivers    = [...]string{DriverUioPciGeneric, DriverIgbUio, DriverVfioPci}
)

DPDK related drivers

View Source
var (
	AllDevices      = ClassesFilter{allClasses}
	NetworkDevices  = ClassesFilter{networkClass, caviumPkx, avpVnic, ifpgaClass}
	BasebandDevices = ClassesFilter{accelerationClass}
	CryptoDevices   = ClassesFilter{encryptionClass, intelProcessorClass}
	DmaDevices      = ClassesFilter{cnxkDma, hisiliconDma, intelIdxdSpr, intelIoatBdw, intelIoatIcx, intelIoatSkx}
	EventdevDevices = ClassesFilter{caviumSso, caviumTim, intelDlb, cnxkSso}
	MempoolDevices  = ClassesFilter{caviumFpa, cnxkNpa}
	CompressDevices = ClassesFilter{caviumZip}
	RegexDevices    = ClassesFilter{cn9kRee}
	MiscDevices     = ClassesFilter{cnxkBphy, cnxkBphyCgx, cnxkInlDev, intelNtbSkx, intelNtbIcx, virtioBlk}
)
View Source
var (
	ErrNoBoundDriver         = errors.New("no driver is bound to the device")
	ErrAlreadyBoundDriver    = errors.New("device has already bound the selected driver")
	ErrBind                  = errors.New("fail to bind the driver")
	ErrUnbind                = errors.New("fail to unbind the driver")
	ErrUnsupportedDriver     = errors.New("unsupported DPDK driver")
	ErrNotProbe              = errors.New("device doesn't support 'drive_probe'")
	ErrKernelModuleNotLoaded = errors.New("kernel module is not loaded")
	ErrNoValidPciID          = errors.New("no valid pci identifier")
	ErrNoDeviceID            = errors.New("can't get device ID from NIC")
)

Errors of devices package

View Source
var (
	IsPciID *regexp.Regexp
)

Regular expressions for PCI-ID

Functions

func BindPci

func BindPci(devID, driver, vendor, device string) (string, error)

BindPci binds the driver to the given device ID

func GetCurrentPciDriver

func GetCurrentPciDriver(devID string) (string, error)

GetCurrentPciDriver returns the current driver that device bound to.

func IsModuleLoaded

func IsModuleLoaded(driver string) bool

IsModuleLoaded checks if the kernel has already loaded the driver or not.

func ProbePci

func ProbePci(devID string) (string, error)

func UnbindPci

func UnbindPci(devID, driver string) error

UnbindPci unbinds the driver that is bound to the given device ID

Types

type ClassFilter

type ClassFilter struct {
	Class  string
	Vendor string
	Device string
}

type ClassesFilter

type ClassesFilter []ClassFilter

type PciDevice

type PciDevice struct {
	// contains filtered or unexported fields
}

func GetPciDeviceByPciID

func GetPciDeviceByPciID(pciID string) (*PciDevice, error)

GetPciDeviceByPciID gets device info by PCI bus id.

func GetPciDevices

func GetPciDevices(classFilter ClassesFilter) ([]*PciDevice, error)

get the list of current PCI devices on this system. The list can be filteren by adding a classesfilter list

func New

func New(id string) (*PciDevice, error)

New returns a corresponding device by given input name

func NewDeviceByNicName

func NewDeviceByNicName(nicName string) (*PciDevice, error)

NewDeviceByNicName returns a device by given NIC name, e.g. eth0.

func NewDeviceByPciID

func NewDeviceByPciID(pciID string) (*PciDevice, error)

NewDeviceByPciID returns a PCI device by given PCI ID

func (*PciDevice) Bind

func (p *PciDevice) Bind(driver string) error

func (*PciDevice) Class

func (p *PciDevice) Class() string

func (*PciDevice) ClassExt

func (p *PciDevice) ClassExt() string

func (*PciDevice) CurrentDriver

func (p *PciDevice) CurrentDriver() (string, error)

func (*PciDevice) Device

func (p *PciDevice) Device() string

func (*PciDevice) DeviceExt

func (p *PciDevice) DeviceExt() string

func (*PciDevice) Driver

func (p *PciDevice) Driver() string

func (*PciDevice) GetInfo

func (p *PciDevice) GetInfo() [5]string

func (*PciDevice) ID

func (p *PciDevice) ID() string

func (*PciDevice) Probe

func (p *PciDevice) Probe() error

func (*PciDevice) String

func (p *PciDevice) String() string

func (*PciDevice) Unbind

func (p *PciDevice) Unbind() error

func (*PciDevice) Vendor

func (p *PciDevice) Vendor() string

func (*PciDevice) VendorExt

func (p *PciDevice) VendorExt() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL