mlxdevm

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: Apache-2.0 Imports: 9 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
	DEVLINK_CMD_PARAM_GET   = 38
	DEVLINK_CMD_PARAM_SET   = 39
	DEVLINK_CMD_EXT_CAP_SET = 161
)
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_PARAM                  = 80  /* nested */
	DEVLINK_ATTR_PARAM_NAME             = 81  /* string */
	DEVLINK_ATTR_PARAM_GENERIC          = 82  /* flag */
	DEVLINK_ATTR_PARAM_TYPE             = 83  /* u8 */
	DEVLINK_ATTR_PARAM_VALUES_LIST      = 84  /* nested */
	DEVLINK_ATTR_PARAM_VALUE            = 85  /* nested */
	DEVLINK_ATTR_PARAM_VALUE_DATA       = 86  /* dynamic */
	DEVLINK_ATTR_PARAM_VALUE_CMODE      = 87  /* u8 */
	DEVLINK_ATTR_PORT_PCI_PF_NUMBER     = 127 /* u16 */
	DEVLINK_ATTR_PORT_FUNCTION          = 145 /* nested */
	DEVLINK_ATTR_PORT_CONTROLLER_NUMBER = 150 /* u32 */
	DEVLINK_ATTR_PORT_PCI_SF_NUMBER     = 164 /* u32 */
	DEVLINK_ATTR_EXT_PORT_FN_CAP        = 8193
	DEVLINK_ATTR_MAX                    = 8201
)
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
)
View Source
const (
	DEVLINK_PORT_FN_ATTR_EXT_CAP_ROCE    = 161
	DEVLINK_PORT_FN_ATTR_EXT_CAP_UC_LIST = 162
)
View Source
const (
	DEVLINK_PARAM_CMODE_RUNTIME    = 0
	DEVLINK_PARAM_CMODE_DRIVERINIT = 1
)
View Source
const (
	MNL_TYPE_U8            = 1
	MNL_TYPE_U16           = 2
	MNL_TYPE_U32           = 3
	MNL_TYPE_U64           = 4
	MNL_TYPE_STRING        = 5
	MNL_TYPE_FLAG          = 6
	MNL_TYPE_MSECS         = 7
	MNL_TYPE_NESTED        = 8
	MNL_TYPE_NESTED_COMPAT = 9
	MNL_TYPE_NUL_STRING    = 10
	MNL_TYPE_BINARY        = 11
	MNL_TYPE_MAX           = 12
)

Variables

This section is empty.

Functions

func DevlinkDevParamSet added in v0.3.0

func DevlinkDevParamSet(Socket string, Bus string, Device string, ParamName string, NewValue string, NewCMode string) error

DevlinkDevParamSet sets one device parameter. It returns 0 on success or error code. Equivalent to: `mlxdevm dev param set $dev name disable_netdev value true cmode runtime`

func DevlinkPortDel added in v0.3.0

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

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

func DevlinkPortFnCapSet added in v0.3.0

func DevlinkPortFnCapSet(Socket string, Bus string, Device string, PortIndex uint32, FnCapAttrs DevlinkPortFnCapSetAttrs) error

DevlinkPortFnCapSet sets roce and max_uc_macs port function cap attributes. It returns 0 on success or error code. Equivalent to: `mlxdevm port function cap sep $port roce true max_uc_macs 64` Equivalent to: `mlxdevm port function cap sep $port roce false max_uc_macs 128`

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 DevlinkSetEswitchMode added in v0.3.0

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 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 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 DevlinkDevParam added in v0.3.0

type DevlinkDevParam struct {
	Name      string
	Attribute nl.Attribute
	CMode     uint8
}

DevlinkDevParam represents a device parameter

func DevlinkDevParamGet added in v0.3.0

func DevlinkDevParamGet(Socket string, Bus string, Device string, ParamName string) (*DevlinkDevParam, error)

DevlinkDevParamGet returns information about a set device parameter Equivalent to `mlxdevm dev param show $dev name disable_netdev`

type DevlinkDevice

type DevlinkDevice struct {
	BusName    string
	DeviceName string
	Attrs      DevlinkDevAttrs
}

DevlinkDevice represents device and its attributes

func DevlinkGetDeviceByName added in v0.3.0

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 added in v0.3.0

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
	Controller     uint32
	PfNumber       uint16
	SfNumber       uint32
	Fn             *DevlinkPortFn
	PortCap        *DevlinkPortFnCap
}

DevlinkPort represents port and its attributes

func DevlinkGetAllPortList added in v0.3.0

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

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

func DevlinkGetPortByIndex added in v0.3.0

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 added in v0.3.0

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 DevlinkPortAddAttrs added in v0.3.0

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

type DevlinkPortFn

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

DevlinkPortFn represents port function and its attributes

type DevlinkPortFnCap added in v0.3.0

type DevlinkPortFnCap struct {
	Roce   bool
	UCList uint32
}

DevlinkPortFnCap represents port function and its attributes

type DevlinkPortFnCapSetAttrs added in v0.3.0

type DevlinkPortFnCapSetAttrs struct {
	FnCapAttrs  DevlinkPortFnCap
	RoceValid   bool
	UCListValid bool
}

DevlinkPortFnCapSetAttrs represents attributes to set

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) DevlinkDevParamGet added in v0.3.0

func (h *Handle) DevlinkDevParamGet(Socket string, Bus string, Device string, ParamName string) (*DevlinkDevParam, error)

DevlinkDevParamGet returns information about a set device parameter Equivalent to `mlxdevm dev param show $dev name disable_netdev`

func (*Handle) DevlinkDevParamSet added in v0.3.0

func (h *Handle) DevlinkDevParamSet(Socket string, Bus string, Device string, ParamName string, NewValue string, NewCMode string) error

DevlinkDevParamSet sets one device parameter. It returns 0 on success or error code. Equivalent to: `mlxdevm dev param set $dev name disable_netdev value true cmode runtime`

func (*Handle) DevlinkGetAllPortList added in v0.3.0

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

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

func (*Handle) DevlinkGetDeviceByName added in v0.3.0

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 added in v0.3.0

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 added in v0.3.0

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

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

func (*Handle) DevlinkPortAdd added in v0.3.0

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 added in v0.3.0

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) DevlinkPortFnCapSet added in v0.3.0

func (h *Handle) DevlinkPortFnCapSet(Socket string, Bus string, Device string, PortIndex uint32, FnCapAttrs DevlinkPortFnCapSetAttrs) error

DevlinkPortFnCapSet sets roce and max_uc_macs port function cap attributes. It returns 0 on success or error code. Equivalent to: `mlxdevm port function cap sep $port roce true max_uc_macs 64` Equivalent to: `mlxdevm port function cap sep $port roce false max_uc_macs 128`

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) DevlinkSetEswitchMode added in v0.3.0

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) 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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