Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func (p *SriovNetworkNodePolicy) Apply(state *SriovNetworkNodeState, equalPriori
Name: iface.Name,
LinkType: p.Spec.LinkType,
EswitchMode: p.Spec.EswitchMode,
ESwitchParams: p.Spec.ESwitchParams,
NumVfs: p.Spec.NumVfs,
ExternallyManaged: p.Spec.ExternallyManaged,
}
Expand Down
8 changes: 8 additions & 0 deletions api/v1/sriovnetworknodepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ type SriovNetworkNodePolicySpec struct {
// contains bridge configuration for matching PFs,
// valid only for eSwitchMode==switchdev
Bridge Bridge `json:"bridge,omitempty"`
// contains bridge configuration eSwitch,
// valid only for eSwitchMode==switchdev
ESwitchParams ESwitchParams `json:"eSwitchParams,omitempty"`
}

type SriovNetworkNicSelector struct {
Expand All @@ -91,6 +94,11 @@ func (b *Bridge) IsEmpty() bool {
return b.OVS == nil
}

type ESwitchParams struct {
// enabled multiport eswitch mode
Multiport bool `json:"multiport,omitempty"`
}

// OVSConfig optional configuration for OVS bridge and uplink Interface
type OVSConfig struct {
// contains bridge level settings
Expand Down
18 changes: 10 additions & 8 deletions api/v1/sriovnetworknodestate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ type SriovNetworkNodeStateSpec struct {
type Interfaces []Interface

type Interface struct {
PciAddress string `json:"pciAddress"`
NumVfs int `json:"numVfs,omitempty"`
Mtu int `json:"mtu,omitempty"`
Name string `json:"name,omitempty"`
LinkType string `json:"linkType,omitempty"`
EswitchMode string `json:"eSwitchMode,omitempty"`
VfGroups []VfGroup `json:"vfGroups,omitempty"`
ExternallyManaged bool `json:"externallyManaged,omitempty"`
PciAddress string `json:"pciAddress"`
NumVfs int `json:"numVfs,omitempty"`
Mtu int `json:"mtu,omitempty"`
Name string `json:"name,omitempty"`
LinkType string `json:"linkType,omitempty"`
EswitchMode string `json:"eSwitchMode,omitempty"`
VfGroups []VfGroup `json:"vfGroups,omitempty"`
ExternallyManaged bool `json:"externallyManaged,omitempty"`
ESwitchParams ESwitchParams `json:"eSwitchParams,omitempty"`
}

type VfGroup struct {
Expand Down Expand Up @@ -70,6 +71,7 @@ type InterfaceExt struct {
ExternallyManaged bool `json:"externallyManaged,omitempty"`
TotalVfs int `json:"totalvfs,omitempty"`
VFs []VirtualFunction `json:"Vfs,omitempty"`
ESwitchParams ESwitchParams `json:"eSwitchParams,omitempty"`
}
type InterfaceExts []InterfaceExt

Expand Down
17 changes: 17 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ spec:
- legacy
- switchdev
type: string
eSwitchParams:
description: |-
contains bridge configuration eSwitch,
valid only for eSwitchMode==switchdev
properties:
multiport:
description: enabled multiport eswitch mode
type: boolean
type: object
excludeTopology:
description: Exclude device's NUMA node when advertising this resource
by SRIOV network device plugin. Default to false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ spec:
properties:
eSwitchMode:
type: string
eSwitchParams:
properties:
multiport:
description: enabled multiport eswitch mode
type: boolean
type: object
externallyManaged:
type: boolean
linkType:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ spec:
- legacy
- switchdev
type: string
eSwitchParams:
description: |-
contains bridge configuration eSwitch,
valid only for eSwitchMode==switchdev
properties:
multiport:
description: enabled multiport eswitch mode
type: boolean
type: object
excludeTopology:
description: Exclude device's NUMA node when advertising this resource
by SRIOV network device plugin. Default to false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ spec:
properties:
eSwitchMode:
type: string
eSwitchParams:
properties:
multiport:
description: enabled multiport eswitch mode
type: boolean
type: object
externallyManaged:
type: boolean
linkType:
Expand Down
3 changes: 3 additions & 0 deletions pkg/plugins/mellanox/mellanox_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (p *MellanoxPlugin) OnNodeStateChange(new *sriovnetworkv1.SriovNetworkNodeS
needReboot = totalVfsNeedReboot || sriovEnNeedReboot
changeWithoutReboot = totalVfsChangeWithoutReboot || sriovEnChangeWithoutReboot

needESwitchParamsChange := mlx.HandleESwitchParams(pciPrefix, attrs, mellanoxNicsSpec, mellanoxNicsStatus)
needReboot = needReboot || needESwitchParamsChange

needLinkChange, err := mlx.HandleLinkType(pciPrefix, fwCurrent, attrs, mellanoxNicsSpec, mellanoxNicsStatus)
if err != nil {
return false, false, err
Expand Down
38 changes: 34 additions & 4 deletions pkg/vendors/mellanox/mellanox.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ const (
disabled = "DISABLED"
enabled = "ENABLED"

VendorMellanox = "15b3"
DeviceBF2 = "a2d6"
DeviceBF3 = "a2dc"

PreconfiguredLinkType = "Preconfigured"
UnknownLinkType = "Unknown"
TotalVfs = "NUM_OF_VFS"
EnableSriov = "SRIOV_EN"
LinkTypeP1 = "LINK_TYPE_P1"
LinkTypeP2 = "LINK_TYPE_P2"
LagResourceAllocation = "LAG_RESOURCE_ALLOCATION"
MellanoxVendorID = "15b3"
)

Expand All @@ -54,6 +51,7 @@ type MlxNic struct {
TotalVfs int
LinkTypeP1 string
LinkTypeP2 string
Multiport int
}

//go:generate ../../../bin/mockgen -destination mock/mock_mellanox.go -source mellanox.go
Expand Down Expand Up @@ -207,6 +205,8 @@ func (m *mellanoxHelper) MlxConfigFW(attributesToChange map[string]MlxNic) error
cmdArgs = append(cmdArgs, fmt.Sprintf("%s=%s", LinkTypeP2, fwArgs.LinkTypeP2))
}

cmdArgs = append(cmdArgs, fmt.Sprintf("%s=%d", LagResourceAllocation, fwArgs.Multiport))

log.Log.V(2).Info("mellanox-plugin: configFW()", "cmd-args", cmdArgs)
if len(cmdArgs) <= 4 {
continue
Expand Down Expand Up @@ -376,6 +376,30 @@ func HandleLinkType(pciPrefix string, fwData, attr *MlxNic,
return needReboot, nil
}

// HandleESwitchParams check if eswitch params should be changes
func HandleESwitchParams(pciPrefix string, attr *MlxNic,
mellanoxNicsSpec map[string]sriovnetworkv1.Interface,
mellanoxNicsStatus map[string]map[string]sriovnetworkv1.InterfaceExt) bool {
needReboot := false

pciAddress := pciPrefix + "0"
if firstPortSpec, ok := mellanoxNicsSpec[pciAddress]; ok {
ifaceStatus := getIfaceStatus(pciAddress, mellanoxNicsStatus)
needChange := isESwitchParamsRequireChange(firstPortSpec, ifaceStatus)
if needChange {
log.Log.V(2).Info("Changing eswitch params (multiport), needs reboot",
"from", firstPortSpec.ESwitchParams.Multiport, "to", firstPortSpec.ESwitchParams.Multiport)
if firstPortSpec.ESwitchParams.Multiport {
attr.Multiport = 1
} else {
attr.Multiport = 0
}
needReboot = true
}
}
return needReboot
}

func mlnxNicFromMap(mstData map[string]string) (*MlxNic, error) {
log.Log.Info("mellanox-plugin mlnxNicFromMap()", "data", mstData)
fwData := &MlxNic{}
Expand Down Expand Up @@ -432,6 +456,12 @@ func isLinkTypeRequireChange(iface sriovnetworkv1.Interface, ifaceStatus sriovne
return false, nil
}

func isESwitchParamsRequireChange(iface sriovnetworkv1.Interface, ifaceStatus sriovnetworkv1.InterfaceExt) bool {
log.Log.Info("mellanox-plugin isLagResourceAllocationRequireChange()", "device", iface.PciAddress)

return iface.ESwitchParams.Multiport != ifaceStatus.ESwitchParams.Multiport
}

func getOtherPortPCIAddress(pciAddress string) string {
log.Log.Info("mellanox-plugin getOtherPortSpec()", "pciAddress", pciAddress)
pciAddrPrefix := GetPciAddressPrefix(pciAddress)
Expand Down
4 changes: 4 additions & 0 deletions pkg/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ func staticValidateSriovNetworkNodePolicy(cr *sriovnetworkv1.SriovNetworkNodePol
if !cr.Spec.Bridge.IsEmpty() && cr.Spec.ExternallyManaged {
return false, fmt.Errorf("software bridge management can't be used when the device externally managed")
}
// multiport must be enabled only in switchdev mode
if cr.Spec.ESwitchParams.Multiport && cr.Spec.EswitchMode != sriovnetworkv1.ESwithModeSwitchDev {
return false, fmt.Errorf("multiport requires the device to be configured in switchdev mode")
}
return true, nil
}

Expand Down
Loading