Blame SOURCES/0174-devlink-Add-usage-help-for-eswitch-subcommand.patch

4aca6e
From 7a4657ac620bfdac456696fb44a6d7656baf8af2 Mon Sep 17 00:00:00 2001
4aca6e
From: Sabrina Dubroca <sdubroca@redhat.com>
4aca6e
Date: Fri, 9 Jun 2017 10:31:05 +0200
4aca6e
Subject: [PATCH] devlink: Add usage help for eswitch subcommand
4aca6e
4aca6e
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1459772
4aca6e
Upstream Status: iproute2.git commit a93b6bb3a2e5
4aca6e
4aca6e
Conflicts: in pr_out_eswitch, because we don't support json output. Fix
4aca6e
that by doing the reverse of the transformation that commit e3d0f0c0e3d8
4aca6e
did to pr_out_port().
4aca6e
4aca6e
commit a93b6bb3a2e50528fa20056c2fba33cbd9cf2ec7
4aca6e
Author: Roi Dayan <roid@mellanox.com>
4aca6e
Date:   Sun Nov 27 13:21:02 2016 +0200
4aca6e
4aca6e
    devlink: Add usage help for eswitch subcommand
4aca6e
4aca6e
    Add missing usage help for devlink dev eswitch subcommand.
4aca6e
4aca6e
    Signed-off-by: Roi Dayan <roid@mellanox.com>
4aca6e
    Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
4aca6e
4aca6e
Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
4aca6e
---
4aca6e
 devlink/devlink.c      | 88 ++++++++++++++++++++++++++++++++++++++++++++++++--
4aca6e
 man/man8/devlink-dev.8 | 21 +++++++++++-
4aca6e
 2 files changed, 106 insertions(+), 3 deletions(-)
4aca6e
4aca6e
diff --git a/devlink/devlink.c b/devlink/devlink.c
4aca6e
index bd801880c75f..ce4aff871595 100644
4aca6e
--- a/devlink/devlink.c
4aca6e
+++ b/devlink/devlink.c
4aca6e
@@ -27,6 +27,10 @@
4aca6e
 
4aca6e
 #define ESWITCH_MODE_LEGACY "legacy"
4aca6e
 #define ESWITCH_MODE_SWITCHDEV "switchdev"
4aca6e
+#define ESWITCH_INLINE_MODE_NONE "none"
4aca6e
+#define ESWITCH_INLINE_MODE_LINK "link"
4aca6e
+#define ESWITCH_INLINE_MODE_NETWORK "network"
4aca6e
+#define ESWITCH_INLINE_MODE_TRANSPORT "transport"
4aca6e
 
4aca6e
 #define pr_err(args...) fprintf(stderr, ##args)
4aca6e
 #define pr_out(args...) fprintf(stdout, ##args)
4aca6e
@@ -131,6 +135,7 @@ static void ifname_map_free(struct ifname_map *ifname_map)
4aca6e
 #define DL_OPT_SB_TH		BIT(9)
4aca6e
 #define DL_OPT_SB_TC		BIT(10)
4aca6e
 #define DL_OPT_ESWITCH_MODE	BIT(11)
4aca6e
+#define DL_OPT_ESWITCH_INLINE_MODE	BIT(12)
4aca6e
 
4aca6e
 struct dl_opts {
4aca6e
 	uint32_t present; /* flags of present items */
4aca6e
@@ -147,6 +152,7 @@ struct dl_opts {
4aca6e
 	uint32_t sb_threshold;
4aca6e
 	uint16_t sb_tc_index;
4aca6e
 	enum devlink_eswitch_mode eswitch_mode;
4aca6e
+	enum devlink_eswitch_inline_mode eswitch_inline_mode;
4aca6e
 };
4aca6e
 
4aca6e
 struct dl {
4aca6e
@@ -295,6 +301,9 @@ static int attr_cb(const struct nlattr *attr, void *data)
4aca6e
 	if (type == DEVLINK_ATTR_ESWITCH_MODE &&
4aca6e
 	    mnl_attr_validate(attr, MNL_TYPE_U16) < 0)
4aca6e
 		return MNL_CB_ERROR;
4aca6e
+	if (type == DEVLINK_ATTR_ESWITCH_INLINE_MODE &&
4aca6e
+	    mnl_attr_validate(attr, MNL_TYPE_U8) < 0)
4aca6e
+		return MNL_CB_ERROR;
4aca6e
 	tb[type] = attr;
4aca6e
 	return MNL_CB_OK;
4aca6e
 }
4aca6e
@@ -672,6 +681,24 @@ static int eswitch_mode_get(const char *typestr,
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
+static int eswitch_inline_mode_get(const char *typestr,
4aca6e
+				   enum devlink_eswitch_inline_mode *p_mode)
4aca6e
+{
4aca6e
+	if (strcmp(typestr, ESWITCH_INLINE_MODE_NONE) == 0) {
4aca6e
+		*p_mode = DEVLINK_ESWITCH_INLINE_MODE_NONE;
4aca6e
+	} else if (strcmp(typestr, ESWITCH_INLINE_MODE_LINK) == 0) {
4aca6e
+		*p_mode = DEVLINK_ESWITCH_INLINE_MODE_LINK;
4aca6e
+	} else if (strcmp(typestr, ESWITCH_INLINE_MODE_NETWORK) == 0) {
4aca6e
+		*p_mode = DEVLINK_ESWITCH_INLINE_MODE_NETWORK;
4aca6e
+	} else if (strcmp(typestr, ESWITCH_INLINE_MODE_TRANSPORT) == 0) {
4aca6e
+		*p_mode = DEVLINK_ESWITCH_INLINE_MODE_TRANSPORT;
4aca6e
+	} else {
4aca6e
+		pr_err("Unknown eswitch inline mode \"%s\"\n", typestr);
4aca6e
+		return -EINVAL;
4aca6e
+	}
4aca6e
+	return 0;
4aca6e
+}
4aca6e
+
4aca6e
 static int dl_argv_parse(struct dl *dl, uint32_t o_required,
4aca6e
 			 uint32_t o_optional)
4aca6e
 {
4aca6e
@@ -793,6 +820,19 @@ static int dl_argv_parse(struct dl *dl, uint32_t o_required,
4aca6e
 			if (err)
4aca6e
 				return err;
4aca6e
 			o_found |= DL_OPT_ESWITCH_MODE;
4aca6e
+		} else if (dl_argv_match(dl, "inline-mode") &&
4aca6e
+			   (o_all & DL_OPT_ESWITCH_INLINE_MODE)) {
4aca6e
+			const char *typestr;
4aca6e
+
4aca6e
+			dl_arg_inc(dl);
4aca6e
+			err = dl_argv_str(dl, &typestr);
4aca6e
+			if (err)
4aca6e
+				return err;
4aca6e
+			err = eswitch_inline_mode_get(
4aca6e
+				typestr, &opts->eswitch_inline_mode);
4aca6e
+			if (err)
4aca6e
+				return err;
4aca6e
+			o_found |= DL_OPT_ESWITCH_INLINE_MODE;
4aca6e
 		} else {
4aca6e
 			pr_err("Unknown option \"%s\"\n", dl_argv(dl));
4aca6e
 			return -EINVAL;
4aca6e
@@ -853,6 +893,12 @@ static int dl_argv_parse(struct dl *dl, uint32_t o_required,
4aca6e
 		return -EINVAL;
4aca6e
 	}
4aca6e
 
4aca6e
+	if ((o_required & DL_OPT_ESWITCH_INLINE_MODE) &&
4aca6e
+	    !(o_found & DL_OPT_ESWITCH_INLINE_MODE)) {
4aca6e
+		pr_err("E-Switch inline-mode option expected.\n");
4aca6e
+		return -EINVAL;
4aca6e
+	}
4aca6e
+
4aca6e
 	return 0;
4aca6e
 }
4aca6e
 
4aca6e
@@ -899,6 +945,9 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
4aca6e
 	if (opts->present & DL_OPT_ESWITCH_MODE)
4aca6e
 		mnl_attr_put_u16(nlh, DEVLINK_ATTR_ESWITCH_MODE,
4aca6e
 				 opts->eswitch_mode);
4aca6e
+	if (opts->present & DL_OPT_ESWITCH_INLINE_MODE)
4aca6e
+		mnl_attr_put_u8(nlh, DEVLINK_ATTR_ESWITCH_INLINE_MODE,
4aca6e
+				opts->eswitch_inline_mode);
4aca6e
 }
4aca6e
 
4aca6e
 static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
4aca6e
@@ -953,6 +1002,9 @@ static bool dl_dump_filter(struct dl *dl, struct nlattr **tb)
4aca6e
 static void cmd_dev_help(void)
4aca6e
 {
4aca6e
 	pr_err("Usage: devlink dev show [ DEV ]\n");
4aca6e
+	pr_err("       devlink dev eswitch set DEV [ mode { legacy | switchdev } ]\n");
4aca6e
+	pr_err("                               [ inline-mode { none | link | network | transport } ]\n");
4aca6e
+	pr_err("       devlink dev eswitch show DEV\n");
4aca6e
 }
4aca6e
 
4aca6e
 static void __pr_out_handle(const char *bus_name, const char *dev_name)
4aca6e
@@ -1028,6 +1080,22 @@ static const char *eswitch_mode_name(uint32_t mode)
4aca6e
 	}
4aca6e
 }
4aca6e
 
4aca6e
+static const char *eswitch_inline_mode_name(uint32_t mode)
4aca6e
+{
4aca6e
+	switch (mode) {
4aca6e
+	case DEVLINK_ESWITCH_INLINE_MODE_NONE:
4aca6e
+		return ESWITCH_INLINE_MODE_NONE;
4aca6e
+	case DEVLINK_ESWITCH_INLINE_MODE_LINK:
4aca6e
+		return ESWITCH_INLINE_MODE_LINK;
4aca6e
+	case DEVLINK_ESWITCH_INLINE_MODE_NETWORK:
4aca6e
+		return ESWITCH_INLINE_MODE_NETWORK;
4aca6e
+	case DEVLINK_ESWITCH_INLINE_MODE_TRANSPORT:
4aca6e
+		return ESWITCH_INLINE_MODE_TRANSPORT;
4aca6e
+	default:
4aca6e
+		return "<unknown mode>";
4aca6e
+	}
4aca6e
+}
4aca6e
+
4aca6e
 static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
4aca6e
 {
4aca6e
 	pr_out_handle(tb);
4aca6e
@@ -1037,6 +1105,11 @@ static void pr_out_eswitch(struct dl *dl, struct nlattr **tb)
4aca6e
 		pr_out(" mode %s",
4aca6e
 			   eswitch_mode_name(mnl_attr_get_u16(tb[DEVLINK_ATTR_ESWITCH_MODE])));
4aca6e
 
4aca6e
+	if (tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])
4aca6e
+		pr_out(" inline-mode %s",
4aca6e
+			   eswitch_inline_mode_name(mnl_attr_get_u8(
4aca6e
+				   tb[DEVLINK_ATTR_ESWITCH_INLINE_MODE])));
4aca6e
+
4aca6e
 	pr_out("\n");
4aca6e
 }
4aca6e
 
4aca6e
@@ -1076,16 +1149,27 @@ static int cmd_dev_eswitch_set(struct dl *dl)
4aca6e
 	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_ESWITCH_MODE_SET,
4aca6e
 			       NLM_F_REQUEST | NLM_F_ACK);
4aca6e
 
4aca6e
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE | DL_OPT_ESWITCH_MODE, 0);
4aca6e
+	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE,
4aca6e
+				DL_OPT_ESWITCH_MODE |
4aca6e
+				DL_OPT_ESWITCH_INLINE_MODE);
4aca6e
+
4aca6e
 	if (err)
4aca6e
 		return err;
4aca6e
 
4aca6e
+	if (dl->opts.present == 1) {
4aca6e
+		pr_err("Need to set at least one option\n");
4aca6e
+		return -ENOENT;
4aca6e
+	}
4aca6e
+
4aca6e
 	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
4aca6e
 }
4aca6e
 
4aca6e
 static int cmd_dev_eswitch(struct dl *dl)
4aca6e
 {
4aca6e
-	if (dl_argv_match(dl, "set")) {
4aca6e
+	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
4aca6e
+		cmd_dev_help();
4aca6e
+		return 0;
4aca6e
+	} else if (dl_argv_match(dl, "set")) {
4aca6e
 		dl_arg_inc(dl);
4aca6e
 		return cmd_dev_eswitch_set(dl);
4aca6e
 	} else if (dl_argv_match(dl, "show")) {
4aca6e
diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
4aca6e
index 9ce319374551..6bfe66f87955 100644
4aca6e
--- a/man/man8/devlink-dev.8
4aca6e
+++ b/man/man8/devlink-dev.8
4aca6e
@@ -31,6 +31,9 @@ devlink-dev \- devlink device configuration
4aca6e
 .RI "[ "
4aca6e
 .BR mode " { " legacy " | " switchdev " } "
4aca6e
 .RI "]"
4aca6e
+.RI "[ "
4aca6e
+.BR inline-mode " { " none " | " link " | " network " | " transport " } "
4aca6e
+.RI "]"
4aca6e
 
4aca6e
 .ti -8
4aca6e
 .BR "devlink dev eswitch show"
4aca6e
@@ -54,7 +57,7 @@ BUS_NAME/BUS_ADDRESS
4aca6e
 
4aca6e
 .TP
4aca6e
 .BR mode " { " legacy " | " switchdev " } "
4aca6e
-set eswitch mode
4aca6e
+Set eswitch mode
4aca6e
 
4aca6e
 .I legacy
4aca6e
 - Legacy SRIOV
4aca6e
@@ -62,6 +65,22 @@ set eswitch mode
4aca6e
 .I switchdev
4aca6e
 - SRIOV switchdev offloads
4aca6e
 
4aca6e
+.TP
4aca6e
+.BR inline-mode " { " none " | " link " | " network " | " transport " } "
4aca6e
+Some HWs need the VF driver to put part of the packet headers on the TX descriptor so the e-switch can do proper matching and steering.
4aca6e
+
4aca6e
+.I none
4aca6e
+- None
4aca6e
+
4aca6e
+.I link
4aca6e
+- L2 mode
4aca6e
+
4aca6e
+.I network
4aca6e
+- L3 mode
4aca6e
+
4aca6e
+.I transport
4aca6e
+- L4 mode
4aca6e
+
4aca6e
 .SH "EXAMPLES"
4aca6e
 .PP
4aca6e
 devlink dev show
4aca6e
-- 
4aca6e
2.13.1
4aca6e