Skip to content

Commit

Permalink
Add support for setting InfininBand Node and Port GUID of a VF
Browse files Browse the repository at this point in the history
Add support for setting InfiniBand Node and Port GUID address
configuration of a VF when InfiniBand HCA are used with SR-IOV mode.

Signed-off-by: Parav Pandit <[email protected]>
  • Loading branch information
paravmellanox authored and aboch committed Mar 27, 2018
1 parent 41009d5 commit aa0edbe
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
44 changes: 44 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,50 @@ func (h *Handle) LinkSetVfTrust(link Link, vf int, state bool) error {
return err
}

// LinkSetVfNodeGUID sets the node GUID of a vf for the link.
// Equivalent to: `ip link set dev $link vf $vf node_guid $nodeguid`
func LinkSetVfNodeGUID(link Link, vf int, nodeguid net.HardwareAddr) error {
return pkgHandle.LinkSetVfGUID(link, vf, nodeguid, nl.IFLA_VF_IB_NODE_GUID)
}

// LinkSetVfPortGUID sets the port GUID of a vf for the link.
// Equivalent to: `ip link set dev $link vf $vf port_guid $portguid`
func LinkSetVfPortGUID(link Link, vf int, portguid net.HardwareAddr) error {
return pkgHandle.LinkSetVfGUID(link, vf, portguid, nl.IFLA_VF_IB_PORT_GUID)
}

// LinkSetVfGUID sets the node or port GUID of a vf for the link.
func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error {
var err error
var guid uint64

buf := bytes.NewBuffer(vfGuid)
err = binary.Read(buf, binary.LittleEndian, &guid)
if err != nil {
return err
}

base := link.Attrs()
h.ensureIndex(base)
req := h.newNetlinkRequest(unix.RTM_SETLINK, unix.NLM_F_ACK)

msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(base.Index)
req.AddData(msg)

data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfGUID{
Vf: uint32(vf),
GUID: guid,
}
nl.NewRtAttrChild(info, guidType, vfmsg.Serialize())
req.AddData(data)

_, err = req.Execute(unix.NETLINK_ROUTE, 0)
return err
}

// LinkSetMaster sets the master of the link device.
// Equivalent to: `ip link set $link master $master`
func LinkSetMaster(link Link, master *Bridge) error {
Expand Down
33 changes: 30 additions & 3 deletions nl/link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ const (
IFLA_VF_RSS_QUERY_EN /* RSS Redirection Table and Hash Key query
* on/off switch
*/
IFLA_VF_STATS /* network device statistics */
IFLA_VF_TRUST /* Trust state of VF */
IFLA_VF_MAX = IFLA_VF_TRUST
IFLA_VF_STATS /* network device statistics */
IFLA_VF_TRUST /* Trust state of VF */
IFLA_VF_IB_NODE_GUID /* VF Infiniband node GUID */
IFLA_VF_IB_PORT_GUID /* VF Infiniband port GUID */
IFLA_VF_MAX = IFLA_VF_IB_PORT_GUID
)

const (
Expand Down Expand Up @@ -248,6 +250,7 @@ const (
SizeofVfLinkState = 0x08
SizeofVfRssQueryEn = 0x08
SizeofVfTrust = 0x08
SizeofVfGUID = 0x10
)

// struct ifla_vf_mac {
Expand Down Expand Up @@ -430,6 +433,30 @@ func (msg *VfTrust) Serialize() []byte {
return (*(*[SizeofVfTrust]byte)(unsafe.Pointer(msg)))[:]
}

// struct ifla_vf_guid {
// __u32 vf;
// __u32 rsvd;
// __u64 guid;
// };

type VfGUID struct {
Vf uint32
Rsvd uint32
GUID uint64
}

func (msg *VfGUID) Len() int {
return SizeofVfGUID
}

func DeserializeVfGUID(b []byte) *VfGUID {
return (*VfGUID)(unsafe.Pointer(&b[0:SizeofVfGUID][0]))
}

func (msg *VfGUID) Serialize() []byte {
return (*(*[SizeofVfGUID]byte)(unsafe.Pointer(msg)))[:]
}

const (
XDP_FLAGS_UPDATE_IF_NOEXIST = 1 << iota
XDP_FLAGS_SKB_MODE
Expand Down

0 comments on commit aa0edbe

Please sign in to comment.