naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0032-devlink-Add-option-to-set-and-show-eswitch-encapsula.patch

cd1737
From d9857ffec0266aea1c56ee26369972ade68f501a Mon Sep 17 00:00:00 2001
cd1737
From: Kamal Heib <kheib@redhat.com>
cd1737
Date: Thu, 9 Nov 2017 04:44:32 -0500
cd1737
Subject: [PATCH] devlink: Add option to set and show eswitch encapsulation
cd1737
 support
cd1737
cd1737
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1456539
cd1737
cd1737
commit d315b706e9d4a550096140aa298d46b2aa7733e9
cd1737
Author: Roi Dayan <roid@mellanox.com>
cd1737
Date:   Sun May 21 08:37:27 2017 +0300
cd1737
cd1737
    devlink: Add option to set and show eswitch encapsulation support
cd1737
cd1737
    This is an e-switch global knob to enable HW support for applying
cd1737
    encapsulation/decapsulation to VF traffic as part of SRIOV e-switch offloading.
cd1737
cd1737
    The actual encap/decap is carried out (along with the matching and other
cd1737
    actions) per offloaded e-switch rules, e.g as done when offloading the TC tunnel
cd1737
    key action.
cd1737
cd1737
    Possible values are enable/disable.
cd1737
cd1737
    Signed-off-by: Roi Dayan <roid@mellanox.com>
cd1737
    Reviewed-by: Jiri Pirko <jiri@mellanox.com>
cd1737
cd1737
Signed-off-by: Kamal Heib <kheib@redhat.com>
cd1737
---
cd1737
 devlink/devlink.c      | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
cd1737
 man/man8/devlink-dev.8 | 13 +++++++++++++
cd1737
 2 files changed, 60 insertions(+), 1 deletion(-)
cd1737
cd1737
diff --git a/devlink/devlink.c b/devlink/devlink.c
cd1737
index e22ee0a..f9bc16c 100644
cd1737
--- a/devlink/devlink.c
cd1737
+++ b/devlink/devlink.c
cd1737
@@ -176,6 +176,7 @@ static void ifname_map_free(struct ifname_map *ifname_map)
cd1737
 #define DL_OPT_ESWITCH_INLINE_MODE	BIT(12)
cd1737
 #define DL_OPT_DPIPE_TABLE_NAME	BIT(13)
cd1737
 #define DL_OPT_DPIPE_TABLE_COUNTERS	BIT(14)
cd1737
+#define DL_OPT_ESWITCH_ENCAP_MODE	BIT(15)
cd1737
 
cd1737
 struct dl_opts {
cd1737
 	uint32_t present; /* flags of present items */
cd1737
@@ -195,6 +196,7 @@ struct dl_opts {
cd1737
 	enum devlink_eswitch_inline_mode eswitch_inline_mode;
cd1737
 	const char *dpipe_table_name;
cd1737
 	bool dpipe_counters_enable;
cd1737
+	bool eswitch_encap_mode;
cd1737
 };
cd1737
 
cd1737
 struct dl {
cd1737
@@ -299,6 +301,7 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
cd1737
 	[DEVLINK_ATTR_SB_OCC_MAX] = MNL_TYPE_U32,
cd1737
 	[DEVLINK_ATTR_ESWITCH_MODE] = MNL_TYPE_U16,
cd1737
 	[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = MNL_TYPE_U8,
cd1737
+	[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = MNL_TYPE_U8,
cd1737
 	[DEVLINK_ATTR_DPIPE_TABLES] = MNL_TYPE_NESTED,
cd1737
 	[DEVLINK_ATTR_DPIPE_TABLE] = MNL_TYPE_NESTED,
cd1737
 	[DEVLINK_ATTR_DPIPE_TABLE_NAME] = MNL_TYPE_STRING,
cd1737
@@ -754,6 +757,19 @@ static int dpipe_counters_enable_get(const char *typestr,
cd1737
 	return 0;
cd1737
 }
cd1737
 
cd1737
+static int eswitch_encap_mode_get(const char *typestr, bool *p_mode)
cd1737
+{
cd1737
+	if (strcmp(typestr, "enable") == 0) {
cd1737
+		*p_mode = true;
cd1737
+	} else if (strcmp(typestr, "disable") == 0) {
cd1737
+		*p_mode = false;
cd1737
+	} else {
cd1737
+		pr_err("Unknown eswitch encap mode \"%s\"\n", typestr);
cd1737
+		return -EINVAL;
cd1737
+	}
cd1737
+	return 0;
cd1737
+}
cd1737
+
cd1737
 static int dl_argv_parse(struct dl *dl, uint32_t o_required,
cd1737
 			 uint32_t o_optional)
cd1737
 {
cd1737
@@ -908,7 +924,19 @@ static int dl_argv_parse(struct dl *dl, uint32_t o_required,
cd1737
 			if (err)
cd1737
 				return err;
cd1737
 			o_found |= DL_OPT_DPIPE_TABLE_COUNTERS;
cd1737
+		} else if (dl_argv_match(dl, "encap") &&
cd1737
+			   (o_all & DL_OPT_ESWITCH_ENCAP_MODE)) {
cd1737
+			const char *typestr;
cd1737
 
cd1737
+			dl_arg_inc(dl);
cd1737
+			err = dl_argv_str(dl, &typestr);
cd1737
+			if (err)
cd1737
+				return err;
cd1737
+			err = eswitch_encap_mode_get(typestr,
cd1737
+						     &opts->eswitch_encap_mode);
cd1737
+			if (err)
cd1737
+				return err;
cd1737
+			o_found |= DL_OPT_ESWITCH_ENCAP_MODE;
cd1737
 		} else {
cd1737
 			pr_err("Unknown option \"%s\"\n", dl_argv(dl));
cd1737
 			return -EINVAL;
cd1737
@@ -986,6 +1014,13 @@ static int dl_argv_parse(struct dl *dl, uint32_t o_required,
cd1737
 		pr_err("Dpipe table counter state expected\n");
cd1737
 		return -EINVAL;
cd1737
 	}
cd1737
+
cd1737
+	if ((o_required & DL_OPT_ESWITCH_ENCAP_MODE) &&
cd1737
+	    !(o_found & DL_OPT_ESWITCH_ENCAP_MODE)) {
cd1737
+		pr_err("E-Switch encapsulation option expected.\n");
cd1737
+		return -EINVAL;
cd1737
+	}
cd1737
+
cd1737
 	return 0;
cd1737
 }
cd1737
 
cd1737
@@ -1041,6 +1076,9 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
cd1737
 	if (opts->present & DL_OPT_DPIPE_TABLE_COUNTERS)
cd1737
 		mnl_attr_put_u8(nlh, DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED,
cd1737
 				opts->dpipe_counters_enable);
cd1737
+	if (opts->present & DL_OPT_ESWITCH_ENCAP_MODE)
cd1737
+		mnl_attr_put_u8(nlh, DEVLINK_ATTR_ESWITCH_ENCAP_MODE,
cd1737
+				opts->eswitch_encap_mode);
cd1737
 }
cd1737
 
cd1737
 static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
cd1737
@@ -1097,6 +1135,7 @@ static void cmd_dev_help(void)
cd1737
 	pr_err("Usage: devlink dev show [ DEV ]\n");
cd1737
 	pr_err("       devlink dev eswitch set DEV [ mode { legacy | switchdev } ]\n");
cd1737
 	pr_err("                               [ inline-mode { none | link | network | transport } ]\n");
cd1737
+	pr_err("                               [ encap { disable | enable } ]\n");
cd1737
 	pr_err("       devlink dev eswitch show DEV\n");
cd1737
 }
cd1737
 
cd1737
@@ -1421,6 +1460,12 @@ static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
cd1737
 			   eswitch_inline_mode_name(mnl_attr_get_u8(
cd1737
 				   tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
cd1737
 
cd1737
+	if (tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]) {
cd1737
+		bool encap_mode = !!mnl_attr_get_u8(tb[DEVLINK_ATTR_ESWITCH_ENCAP_MODE]);
cd1737
+
cd1737
+		pr_out_str(dl, "encap", encap_mode ? "enable" : "disable");
cd1737
+	}
cd1737
+
cd1737
 	pr_out_handle_end(dl);
cd1737
 }
cd1737
 
cd1737
@@ -1465,7 +1510,8 @@ static int cmd_dev_eswitch_set(struct dl *dl)
cd1737
 
cd1737
 	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE,
cd1737
 				DL_OPT_ESWITCH_MODE |
cd1737
-				DL_OPT_ESWITCH_INLINE_MODE);
cd1737
+				DL_OPT_ESWITCH_INLINE_MODE |
cd1737
+				DL_OPT_ESWITCH_ENCAP_MODE);
cd1737
 
cd1737
 	if (err)
cd1737
 		return err;
cd1737
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
cd1737
index 6bfe66f..b074d57 100644
cd1737
--- a/man/man8/devlink-dev.8
cd1737
+++ b/man/man8/devlink-dev.8
cd1737
@@ -34,6 +34,9 @@ devlink-dev \- devlink device configuration
cd1737
 .RI "[ "
cd1737
 .BR inline-mode " { " none " | " link " | " network " | " transport " } "
cd1737
 .RI "]"
cd1737
+.RI "[ "
cd1737
+.BR encap " { " disable " | " enable " } "
cd1737
+.RI "]"
cd1737
 
cd1737
 .ti -8
cd1737
 .BR "devlink dev eswitch show"
cd1737
@@ -81,6 +84,16 @@ Some HWs need the VF driver to put part of the packet headers on the TX descript
cd1737
 .I transport
cd1737
 - L4 mode
cd1737
 
cd1737
+.TP
cd1737
+.BR encap " { " disable " | " enable " } "
cd1737
+Set eswitch encapsulation support
cd1737
+
cd1737
+.I disable
cd1737
+- Disable encapsulation support
cd1737
+
cd1737
+.I enable
cd1737
+- Enable encapsulation support
cd1737
+
cd1737
 .SH "EXAMPLES"
cd1737
 .PP
cd1737
 devlink dev show
cd1737
-- 
cd1737
1.8.3.1
cd1737