From e9561456c9485314c9c522da8279b2c337525226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Thu, 8 Feb 2024 09:45:37 +0100 Subject: [PATCH] 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 c61c87f8a6b6e49a4912521aa91562f299f539a7) --- src/libnm-client-impl/libnm.ver | 2 + ...gen-metadata-nm-settings-libnm-core.xml.in | 4 ++ src/libnm-core-impl/nm-setting-sriov.c | 47 ++++++++++++++++++- src/libnm-core-public/nm-setting-sriov.h | 17 +++++++ src/libnmc-setting/nm-meta-setting-desc.c | 3 ++ src/libnmc-setting/settings-docs.h.in | 1 + .../gen-metadata-nm-settings-nmcli.xml.in | 4 ++ 7 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/libnm-client-impl/libnm.ver b/src/libnm-client-impl/libnm.ver index 052e701854..17fc25c6c2 100644 --- a/src/libnm-client-impl/libnm.ver +++ b/src/libnm-client-impl/libnm.ver @@ -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; diff --git a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in index 033639e063..f3fa8e162d 100644 --- a/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in +++ b/src/libnm-core-impl/gen-metadata-nm-settings-libnm-core.xml.in @@ -2198,6 +2198,10 @@ dbus-type="i" gprop-type="NMTernary" /> + 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, diff --git a/src/libnm-core-public/nm-setting-sriov.h b/src/libnm-core-public/nm-setting-sriov.h index 071b983775..16e493258f 100644 --- a/src/libnm-core-public/nm-setting-sriov.h +++ b/src/libnm-core-public/nm-setting-sriov.h @@ -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); diff --git a/src/libnmc-setting/nm-meta-setting-desc.c b/src/libnmc-setting/nm-meta-setting-desc.c index 1e8f8809a3..8a53af36e2 100644 --- a/src/libnmc-setting/nm-meta-setting-desc.c +++ b/src/libnmc-setting/nm-meta-setting-desc.c @@ -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 }; diff --git a/src/libnmc-setting/settings-docs.h.in b/src/libnmc-setting/settings-docs.h.in index 854e925ae6..578cd3ca42 100644 --- a/src/libnmc-setting/settings-docs.h.in +++ b/src/libnmc-setting/settings-docs.h.in @@ -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.") diff --git a/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in b/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in index 40ef214f9d..a735dba7f1 100644 --- a/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in +++ b/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in @@ -1820,6 +1820,10 @@ nmcli-description="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)." format="ternary" values="true/yes/on, false/no/off, default/unknown" /> +