sriov: add eswitch-mode property

Add property to allow changing the eswitch mode between legacy SRIOV and
switchdev. Allow also to set "preserve" to prevent NM from modifying the
eswitch mode.

(cherry picked from commit c61c87f8a6)
This commit is contained in:
Íñigo Huguet 2024-02-08 09:45:37 +01:00
parent 61788cf901
commit e9561456c9
7 changed files with 77 additions and 1 deletions

View file

@ -1967,4 +1967,6 @@ global:
nm_setting_hsr_new;
nm_setting_ip_config_get_dhcp_dscp;
nm_setting_get_enum_property_type;
nm_setting_sriov_get_eswitch_mode;
nm_sriov_eswitch_mode_get_type;
} libnm_1_44_0;

View file

@ -2198,6 +2198,10 @@
dbus-type="i"
gprop-type="NMTernary"
/>
<property name="eswitch-mode"
dbus-type="i"
gprop-type="gint"
/>
<property name="total-vfs"
dbus-type="u"
gprop-type="guint"

View file

@ -9,6 +9,7 @@
#include "nm-setting-private.h"
#include "nm-utils-private.h"
#include "nm-core-enum-types.h"
/**
* SECTION:nm-setting-sriov
@ -18,7 +19,11 @@
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE(NMSettingSriov, PROP_TOTAL_VFS, PROP_VFS, PROP_AUTOPROBE_DRIVERS, );
NM_GOBJECT_PROPERTIES_DEFINE(NMSettingSriov,
PROP_TOTAL_VFS,
PROP_VFS,
PROP_AUTOPROBE_DRIVERS,
PROP_ESWITCH_MODE, );
/**
* NMSettingSriov:
@ -32,6 +37,7 @@ struct _NMSettingSriov {
GPtrArray *vfs;
int autoprobe_drivers;
guint32 total_vfs;
int eswitch_mode;
};
struct _NMSettingSriovClass {
@ -835,6 +841,22 @@ nm_setting_sriov_get_autoprobe_drivers(NMSettingSriov *setting)
return setting->autoprobe_drivers;
}
/**
* nm_setting_sriov_get_eswitch_mode:
* @setting: the #NMSettingSriov
*
* Returns: the value contained in the #NMSettingSriov:eswitch-mode property.
*
* Since: 1.46
*/
NMSriovEswitchMode
nm_setting_sriov_get_eswitch_mode(NMSettingSriov *setting)
{
g_return_val_if_fail(NM_IS_SETTING_SRIOV(setting), NM_SRIOV_ESWITCH_MODE_PRESERVE);
return setting->eswitch_mode;
}
static int
vf_index_compare(gconstpointer a, gconstpointer b)
{
@ -1331,6 +1353,29 @@ nm_setting_sriov_class_init(NMSettingSriovClass *klass)
NMSettingSriov,
autoprobe_drivers);
/**
* NMSettingSriov:eswitch-mode
*
* Select the eswitch mode of the device. Currently it's only supported for
* PCI PF devices, and only if the eswitch device is managed from the same
* PCI address than the PF.
*
* If set to %NM_SRIOV_ESWITCH_MODE_PRESERVE (default) the eswitch mode won't be
* modified by NetworkManager.
*
* Since: 1.46
*/
_nm_setting_property_define_direct_enum(properties_override,
obj_properties,
NM_SETTING_SRIOV_ESWITCH_MODE,
PROP_ESWITCH_MODE,
NM_TYPE_SRIOV_ESWITCH_MODE,
NM_SRIOV_ESWITCH_MODE_PRESERVE,
NM_SETTING_PARAM_FUZZY_IGNORE,
NULL,
NMSettingSriov,
eswitch_mode);
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nm_setting_class_commit(setting_class,

View file

@ -29,6 +29,7 @@ G_BEGIN_DECLS
#define NM_SETTING_SRIOV_TOTAL_VFS "total-vfs"
#define NM_SETTING_SRIOV_VFS "vfs"
#define NM_SETTING_SRIOV_AUTOPROBE_DRIVERS "autoprobe-drivers"
#define NM_SETTING_SRIOV_ESWITCH_MODE "eswitch-mode"
#define NM_SRIOV_VF_ATTRIBUTE_MAC "mac"
#define NM_SRIOV_VF_ATTRIBUTE_SPOOF_CHECK "spoof-check"
@ -53,6 +54,20 @@ typedef enum {
NM_SRIOV_VF_VLAN_PROTOCOL_802_1AD = 1,
} NMSriovVFVlanProtocol;
/**
* NMSriovEswitchMode:
* @NM_SRIOV_ESWITCH_MODE_PRESERVE: don't modify current eswitch mode
* @NM_SRIOV_ESWITCH_MODE_LEGACY: use legacy SRIOV
* @NM_SRIOV_ESWITCH_MODE_SWITCHDEV: use switchdev mode
*
* Since: 1.46
*/
typedef enum {
NM_SRIOV_ESWITCH_MODE_PRESERVE = -1,
NM_SRIOV_ESWITCH_MODE_LEGACY = 0,
NM_SRIOV_ESWITCH_MODE_SWITCHDEV = 1,
} NMSriovEswitchMode;
NM_AVAILABLE_IN_1_14
GType nm_setting_sriov_get_type(void);
NM_AVAILABLE_IN_1_14
@ -73,6 +88,8 @@ NM_AVAILABLE_IN_1_14
void nm_setting_sriov_clear_vfs(NMSettingSriov *setting);
NM_AVAILABLE_IN_1_14
NMTernary nm_setting_sriov_get_autoprobe_drivers(NMSettingSriov *setting);
NM_AVAILABLE_IN_1_46
NMSriovEswitchMode nm_setting_sriov_get_eswitch_mode(NMSettingSriov *setting);
NM_AVAILABLE_IN_1_14
gboolean nm_sriov_vf_add_vlan(NMSriovVF *vf, guint vlan_id);

View file

@ -7363,6 +7363,9 @@ static const NMMetaPropertyInfo *const property_infos_SRIOV[] = {
PROPERTY_INFO_WITH_DESC (NM_SETTING_SRIOV_AUTOPROBE_DRIVERS,
.property_type = &_pt_gobject_ternary,
),
PROPERTY_INFO_WITH_DESC (NM_SETTING_SRIOV_ESWITCH_MODE,
.property_type = &_pt_gobject_enum,
),
NULL
};

View file

@ -310,6 +310,7 @@
#define DESCRIBE_DOC_NM_SETTING_SERIAL_SEND_DELAY N_("Time to delay between each byte sent to the modem, in microseconds.")
#define DESCRIBE_DOC_NM_SETTING_SERIAL_STOPBITS N_("Number of stop bits for communication on the serial port. Either 1 or 2. The 1 in \"8n1\" for example.")
#define DESCRIBE_DOC_NM_SETTING_SRIOV_AUTOPROBE_DRIVERS N_("Whether to autoprobe virtual functions by a compatible driver. If set to \"true\" (1), the kernel will try to bind VFs to a compatible driver and if this succeeds a new network interface will be instantiated for each VF. If set to \"false\" (0), VFs will not be claimed and no network interfaces will be created for them. When set to \"default\" (-1), the global default is used; in case the global default is unspecified it is assumed to be \"true\" (1).")
#define DESCRIBE_DOC_NM_SETTING_SRIOV_ESWITCH_MODE N_("Select the eswitch mode of the device. Currently it's only supported for PCI PF devices, and only if the eswitch device is managed from the same PCI address than the PF. If set to \"preserve\" (-1) (default) the eswitch mode won't be modified by NetworkManager.")
#define DESCRIBE_DOC_NM_SETTING_SRIOV_TOTAL_VFS N_("The total number of virtual functions to create. Note that when the sriov setting is present NetworkManager enforces the number of virtual functions on the interface (also when it is zero) during activation and resets it upon deactivation. To prevent any changes to SR-IOV parameters don't add a sriov setting to the connection.")
#define DESCRIBE_DOC_NM_SETTING_SRIOV_VFS N_("Array of virtual function descriptors. Each VF descriptor is a dictionary mapping attribute names to GVariant values. The 'index' entry is mandatory for each VF. When represented as string a VF is in the form: \"INDEX [ATTR=VALUE[ ATTR=VALUE]...]\". for example: \"2 mac=00:11:22:33:44:55 spoof-check=true\". Multiple VFs can be specified using a comma as separator. Currently, the following attributes are supported: mac, spoof-check, trust, min-tx-rate, max-tx-rate, vlans. The \"vlans\" attribute is represented as a semicolon-separated list of VLAN descriptors, where each descriptor has the form \"ID[.PRIORITY[.PROTO]]\". PROTO can be either 'q' for 802.1Q (the default) or 'ad' for 802.1ad.")
#define DESCRIBE_DOC_NM_SETTING_TC_CONFIG_QDISCS N_("Array of TC queueing disciplines. When the \"tc\" setting is present, qdiscs from this property are applied upon activation. If the property is empty, all qdiscs are removed and the device will only have the default qdisc assigned by kernel according to the \"net.core.default_qdisc\" sysctl. If the \"tc\" setting is not present, NetworkManager doesn't touch the qdiscs present on the interface.")

View file

@ -1820,6 +1820,10 @@
nmcli-description="Whether to autoprobe virtual functions by a compatible driver. If set to &quot;true&quot; (1), the kernel will try to bind VFs to a compatible driver and if this succeeds a new network interface will be instantiated for each VF. If set to &quot;false&quot; (0), VFs will not be claimed and no network interfaces will be created for them. When set to &quot;default&quot; (-1), the global default is used; in case the global default is unspecified it is assumed to be &quot;true&quot; (1)."
format="ternary"
values="true/yes/on, false/no/off, default/unknown" />
<property name="eswitch-mode"
nmcli-description="Select the eswitch mode of the device. Currently it&apos;s only supported for PCI PF devices, and only if the eswitch device is managed from the same PCI address than the PF. If set to &quot;preserve&quot; (-1) (default) the eswitch mode won&apos;t be modified by NetworkManager."
format="choice (NMSriovEswitchMode)"
values="preserve (-1), legacy (0), switchdev (1)" />
</setting>
<setting name="tc" >
<property name="qdiscs"