mlxdevm

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

README

mlxdevm-go

mlxdevm library for for device management in go language

Overview

Subfunction(SF) aka scalable function are managed by devlink interface in upstream kernel. They can be also managed in Mellanox OFED distrubtion using a similar interface called mlxdevm. This is helpful to use SFs in older kernel distributions where devlink interface of latest and greast kernel is not unavailable.

Only difference between the two interfaces are their socket name. For example devlink socket name is "devlink" vs mlxdevm socket name is "mlxdevm".

Container orchestration software such as CNI or device plugin which needs to operate over both the interfaces (upstream devlink and mlxdevm) in simple and elegant way.

This package enables orchestration software to use upstream devlink compliant APIs over mlxdevm interface.

How to use this library in the application?

$ go get github.com/Mellanox/mlxdevm-go

Sample application:

package main

import (
    mlxdevm "github.com/Mellanox/mlxdevm-go"
    "fmt"
)

func main() {
    var portAttr mlxdevm.DevLinkPortAddAttrs
    
    portAttr.PfNumber = 0
    
    portAttr.SfNumber = 88 // Any number starting 0 to 999
    portAttr.SfNumberValid = true
    // To use upstream devlink interface
    dl_port, err := mlxdevm.DevLinkPortAdd("devlink", "pci", "0000:06:00.0", mlxdevm.DEVLINK_PORT_FLAVOUR_PCI_SF, portAttr)
    if err != nil {
        return
    }
    fmt.Printf("Port = ", dl_port)
    
    portAttr.SfNumber = 99 // Any number starting 0 to 999
    // To use mlxdevm interface
    dl_port2, err2 := mlxdevm.DevLinkPortAdd("mlxdevm", "pci", "0000:06:00.0", mlxdevm.DEVLINK_PORT_FLAVOUR_PCI_SF, portAttr)
    if err2 != nil {
        return
    }
    fmt.Printf("Port = ", dl_port2)
}

Documentation

Index

Constants

View Source
const (
	GENL_DEVLINK_VERSION = 1
	GENL_DEVLINK_NAME    = "devlink"
	GENL_MLXDEVM_NAME    = "mlxdevm"
)
View Source
const (
	DEVLINK_CMD_GET         = 1
	DEVLINK_CMD_PORT_GET    = 5
	DEVLINK_CMD_PORT_SET    = 6
	DEVLINK_CMD_PORT_NEW    = 7
	DEVLINK_CMD_PORT_DEL    = 8
	DEVLINK_CMD_ESWITCH_GET = 29
	DEVLINK_CMD_ESWITCH_SET = 30
)
View Source
const (
	DEVLINK_ATTR_BUS_NAME               = 1
	DEVLINK_ATTR_DEV_NAME               = 2
	DEVLINK_ATTR_PORT_INDEX             = 3
	DEVLINK_ATTR_PORT_TYPE              = 4
	DEVLINK_ATTR_PORT_NETDEV_IFINDEX    = 6
	DEVLINK_ATTR_PORT_NETDEV_NAME       = 7
	DEVLINK_ATTR_PORT_IBDEV_NAME        = 8
	DEVLINK_ATTR_ESWITCH_MODE           = 25
	DEVLINK_ATTR_ESWITCH_INLINE_MODE    = 26
	DEVLINK_ATTR_ESWITCH_ENCAP_MODE     = 62
	DEVLINK_ATTR_PORT_FLAVOUR           = 77
	DEVLINK_ATTR_PORT_PCI_PF_NUMBER     = 127
	DEVLINK_ATTR_PORT_FUNCTION          = 145
	DEVLINK_ATTR_PORT_CONTROLLER_NUMBER = 150
	DEVLINK_ATTR_PORT_PCI_SF_NUMBER     = 164
)
View Source
const (
	DEVLINK_ESWITCH_MODE_LEGACY    = 0
	DEVLINK_ESWITCH_MODE_SWITCHDEV = 1
)
View Source
const (
	DEVLINK_ESWITCH_INLINE_MODE_NONE      = 0
	DEVLINK_ESWITCH_INLINE_MODE_LINK      = 1
	DEVLINK_ESWITCH_INLINE_MODE_NETWORK   = 2
	DEVLINK_ESWITCH_INLINE_MODE_TRANSPORT = 3
)
View Source
const (
	DEVLINK_ESWITCH_ENCAP_MODE_NONE  = 0
	DEVLINK_ESWITCH_ENCAP_MODE_BASIC = 1
)
View Source
const (
	DEVLINK_PORT_FLAVOUR_PHYSICAL = 0
	DEVLINK_PORT_FLAVOUR_CPU      = 1
	DEVLINK_PORT_FLAVOUR_DSA      = 2
	DEVLINK_PORT_FLAVOUR_PCI_PF   = 3
	DEVLINK_PORT_FLAVOUR_PCI_VF   = 4
	DEVLINK_PORT_FLAVOUR_VIRTUAL  = 5
	DEVLINK_PORT_FLAVOUR_UNUSED   = 6
	DEVLINK_PORT_FLAVOUR_PCI_SF   = 7
)
View Source
const (
	DEVLINK_PORT_TYPE_NOTSET = 0
	DEVLINK_PORT_TYPE_AUTO   = 1
	DEVLINK_PORT_TYPE_ETH    = 2
	DEVLINK_PORT_TYPE_IB     = 3
)
View Source
const (
	DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR = 1
	DEVLINK_PORT_FN_ATTR_STATE         = 2
	DEVLINK_PORT_FN_ATTR_OPSTATE       = 3
)
View Source
const (
	DEVLINK_PORT_FN_STATE_INACTIVE = 0
	DEVLINK_PORT_FN_STATE_ACTIVE   = 1
)
View Source
const (
	DEVLINK_PORT_FN_OPSTATE_DETACHED = 0
	DEVLINK_PORT_FN_OPSTATE_ATTACHED = 1
)

Variables

This section is empty.

Functions

func DevLinkPortDel

func DevLinkPortDel(Socket string, Bus string, Device string, PortIndex uint32) error

DevLinkPortDel deletes a devlink port and returns success or error code.

func DevLinkSetEswitchMode

func DevLinkSetEswitchMode(Socket string, Dev *DevlinkDevice, NewMode string) error

DevLinkSetEswitchMode sets eswitch mode if able to set successfully or returns an error code. Equivalent to: `devlink dev eswitch set $dev mode switchdev` Equivalent to: `devlink dev eswitch set $dev mode legacy`

func DevlinkPortFnSet

func DevlinkPortFnSet(Socket string, Bus string, Device string, PortIndex uint32, FnAttrs DevlinkPortFnSetAttrs) error

DevlinkPortFnSet sets one or more port function attributes specified by the attribute mask. It returns 0 on success or error code.

func GetSocketTimeout

func GetSocketTimeout() time.Duration

GetSocketTimeout returns the timeout value used by default netlink sockets

func SetSocketTimeout

func SetSocketTimeout(to time.Duration) error

SetSocketTimeout configures timeout for default netlink sockets

Types

type DevLinkPortAddAttrs

type DevLinkPortAddAttrs struct {
	Controller      uint32
	SfNumber        uint32
	PortIndex       uint32
	PfNumber        uint16
	SfNumberValid   bool
	PortIndexValid  bool
	ControllerValid bool
}

type DevlinkDevAttrs

type DevlinkDevAttrs struct {
	Eswitch DevlinkDevEswitchAttr
}

DevlinkDevAttrs represents device attributes

type DevlinkDevEswitchAttr

type DevlinkDevEswitchAttr struct {
	Mode       string
	InlineMode string
	EncapMode  string
}

DevlinkDevEswitchAttr represents device's eswitch attributes

type DevlinkDevice

type DevlinkDevice struct {
	BusName    string
	DeviceName string
	Attrs      DevlinkDevAttrs
}

DevlinkDevice represents device and its attributes

func DevLinkGetDeviceByName

func DevLinkGetDeviceByName(Socket string, Bus string, Device string) (*DevlinkDevice, error)

DevlinkGetDeviceByName provides a pointer to devlink device and nil error, otherwise returns an error code. Take Socket as either GENL_DEVLINK_NAME or as GENL_MLXDEVM_NAME.

func DevLinkGetDeviceList

func DevLinkGetDeviceList(Socket string) ([]*DevlinkDevice, error)

DevLinkGetDeviceList provides a pointer to devlink devices and nil error, otherwise returns an error code.

type DevlinkPort

type DevlinkPort struct {
	BusName        string
	DeviceName     string
	PortIndex      uint32
	PortType       uint16
	NetdeviceName  string
	NetdevIfIndex  uint32
	RdmaDeviceName string
	PortFlavour    uint16
	Fn             *DevlinkPortFn
}

DevlinkPort represents port and its attributes

func DevLinkGetAllPortList

func DevLinkGetAllPortList(Socket string) ([]*DevlinkPort, error)

DevLinkGetPortList provides a pointer to devlink ports and nil error, otherwise returns an error code.

func DevLinkGetPortByIndex

func DevLinkGetPortByIndex(Socket string, Bus string, Device string, PortIndex uint32) (*DevlinkPort, error)

DevLinkGetPortByIndex provides a pointer to devlink portand nil error, otherwise returns an error code.

func DevLinkPortAdd

func DevLinkPortAdd(Socket string, Bus string, Device string, Flavour uint16, Attrs DevLinkPortAddAttrs) (*DevlinkPort, error)

DevLinkPortAdd adds a devlink port and returns a port on success otherwise returns nil port and an error code.

type DevlinkPortFn

type DevlinkPortFn struct {
	HwAddr  net.HardwareAddr
	State   uint8
	OpState uint8
}

DevlinkPortFn represents port function and its attributes

type DevlinkPortFnSetAttrs

type DevlinkPortFnSetAttrs struct {
	FnAttrs     DevlinkPortFn
	HwAddrValid bool
	StateValid  bool
}

DevlinkPortFnSetAttrs represents attributes to set

type GenlFamily

type GenlFamily struct {
	ID      uint16
	HdrSize uint32
	Name    string
	Version uint32
	MaxAttr uint32
	Ops     []GenlOp
	Groups  []GenlMulticastGroup
}

func GenlFamilyGet

func GenlFamilyGet(name string) (*GenlFamily, error)

func GenlFamilyList

func GenlFamilyList() ([]*GenlFamily, error)

type GenlMulticastGroup

type GenlMulticastGroup struct {
	ID   uint32
	Name string
}

type GenlOp

type GenlOp struct {
	ID    uint32
	Flags uint32
}

type Handle

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

Handle is an handle for the netlink requests on a specific network namespace. All the requests on the same netlink family share the same netlink socket, which gets released when the handle is deleted.

func NewHandle

func NewHandle(nlFamilies ...int) (*Handle, error)

NewHandle returns a netlink handle on the current network namespace. Caller may specify the netlink families the handle should support. If no families are specified, all the families the netlink package supports will be automatically added.

func NewHandleAt

func NewHandleAt(ns netns.NsHandle, nlFamilies ...int) (*Handle, error)

NewHandleAt returns a netlink handle on the network namespace specified by ns. If ns=netns.None(), current network namespace will be assumed

func NewHandleAtFrom

func NewHandleAtFrom(newNs, curNs netns.NsHandle) (*Handle, error)

NewHandleAtFrom works as NewHandle but allows client to specify the new and the origin netns Handle.

func (*Handle) Delete

func (h *Handle) Delete()

Delete releases the resources allocated to this handle

func (*Handle) DevLinkGetAllPortList

func (h *Handle) DevLinkGetAllPortList(Socket string) ([]*DevlinkPort, error)

DevLinkGetPortList provides a pointer to devlink ports and nil error, otherwise returns an error code.

func (*Handle) DevLinkGetDeviceByName

func (h *Handle) DevLinkGetDeviceByName(Socket string, Bus string, Device string) (*DevlinkDevice, error)

DevlinkGetDeviceByName provides a pointer to devlink device and nil error, otherwise returns an error code. Take Socket as either GENL_DEVLINK_NAME or as GENL_MLXDEVM_NAME.

func (*Handle) DevLinkGetDeviceList

func (h *Handle) DevLinkGetDeviceList(Socket string) ([]*DevlinkDevice, error)

DevLinkGetDeviceList provides a pointer to devlink devices and nil error, otherwise returns an error code.

func (*Handle) DevLinkGetPortByIndex

func (h *Handle) DevLinkGetPortByIndex(Socket string, Bus string, Device string, PortIndex uint32) (*DevlinkPort, error)

DevLinkGetPortByIndexprovides a pointer to devlink device and nil error, otherwise returns an error code.

func (*Handle) DevLinkPortAdd

func (h *Handle) DevLinkPortAdd(Socket string, Bus string, Device string, Flavour uint16, Attrs DevLinkPortAddAttrs) (*DevlinkPort, error)

DevLinkPortAdd adds a devlink port and returns a port on success otherwise returns nil port and an error code.

func (*Handle) DevLinkPortDel

func (h *Handle) DevLinkPortDel(Socket string, Bus string, Device string, PortIndex uint32) error

DevLinkPortDel deletes a devlink port and returns success or error code.

func (*Handle) DevLinkSetEswitchMode

func (h *Handle) DevLinkSetEswitchMode(Socket string, Dev *DevlinkDevice, NewMode string) error

DevLinkSetEswitchMode sets eswitch mode if able to set successfully or returns an error code. Equivalent to: `devlink dev eswitch set $dev mode switchdev` Equivalent to: `devlink dev eswitch set $dev mode legacy`

func (*Handle) DevlinkPortFnSet

func (h *Handle) DevlinkPortFnSet(Socket string, Bus string, Device string, PortIndex uint32, FnAttrs DevlinkPortFnSetAttrs) error

DevlinkPortFnSet sets one or more port function attributes specified by the attribute mask. It returns 0 on success or error code.

func (*Handle) GenlFamilyGet

func (h *Handle) GenlFamilyGet(name string) (*GenlFamily, error)

func (*Handle) GenlFamilyList

func (h *Handle) GenlFamilyList() ([]*GenlFamily, error)

func (*Handle) GetSocketReceiveBufferSize

func (h *Handle) GetSocketReceiveBufferSize() ([]int, error)

GetSocketReceiveBufferSize gets the receiver buffer size for each socket in the netlink handle. The retrieved value should be the double to the one set for SetSocketReceiveBufferSize.

func (*Handle) SetSocketReceiveBufferSize

func (h *Handle) SetSocketReceiveBufferSize(size int, force bool) error

SetSocketReceiveBufferSize sets the receive buffer size for each socket in the netlink handle. The maximum value is capped by /proc/sys/net/core/rmem_max.

func (*Handle) SetSocketTimeout

func (h *Handle) SetSocketTimeout(to time.Duration) error

SetSocketTimeout sets the send and receive timeout for each socket in the netlink handle. Although the socket timeout has granularity of one microsecond, the effective granularity is floored by the kernel timer tick, which default value is four milliseconds.

func (*Handle) SupportsNetlinkFamily

func (h *Handle) SupportsNetlinkFamily(nlFamily int) bool

SupportsNetlinkFamily reports whether the passed netlink family is supported by this Handle

Jump to

Keyboard shortcuts

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