File netlink-add-netlink-handler-for-gpause-a.patch of Package ethtool

From: Michal Kubecek <mkubecek@suse.cz>
Date: Sat, 9 Dec 2017 00:04:09 +0100
Subject: netlink: add netlink handler for gpause (-a)
Patch-mainline: Not yet, work in progress
References: none

Implement "ethtool -a <dev>" subcommand using netlink interface command
ETHNL_CMD_GET_PARAMS with ETH_PARAMS_IM_PAUSE mask.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 ethtool.c         |  3 ++-
 netlink/extapi.h  |  1 +
 netlink/monitor.c |  5 +++++
 netlink/params.c  | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/ethtool.c b/ethtool.c
index 342f5554d442..74b81be85e48 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4845,6 +4845,7 @@ static int show_usage(struct cmd_context *ctx);
 #define nl_sfeatures	NULL
 #define nl_gcoalesce	NULL
 #define nl_gring	NULL
+#define nl_gpause	NULL
 #endif
 
 static const struct option {
@@ -4868,7 +4869,7 @@ static const struct option {
 	  "		[ wol %d[/%d] |  p|u|m|b|a|g|s|f|d...[/p|u|m|b|a|g|s|f|d...] ]\n"
 	  "		[ sopass %x:%x:%x:%x:%x:%x ]\n"
 	  "		[ msglvl %d[/%d] | type on|off ... [--] ]\n" },
-	{ "-a|--show-pause", 1, do_gpause, NULL,
+	{ "-a|--show-pause", 1, do_gpause, nl_gpause,
 	  "Show pause options" },
 	{ "-A|--pause", 1, do_spause, NULL,
 	  "Set pause options",
diff --git a/netlink/extapi.h b/netlink/extapi.h
index 9c84a80d223c..1f7de2a7992c 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -22,6 +22,7 @@ int nl_gfeatures(struct cmd_context *ctx);
 int nl_sfeatures(struct cmd_context *ctx);
 int nl_gcoalesce(struct cmd_context *ctx);
 int nl_gring(struct cmd_context *ctx);
+int nl_gpause(struct cmd_context *ctx);
 int nl_monitor(struct cmd_context *ctx);
 
 void monitor_usage();
diff --git a/netlink/monitor.c b/netlink/monitor.c
index 0f65d21c9377..b6912c556780 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -148,6 +148,11 @@ static struct monitor_option monitor_opts[] = {
 		.cmd		= ETHNL_CMD_SET_PARAMS,
 		.info_mask	= ETH_PARAMS_IM_RING,
 	},
+	{
+		.pattern	= "-a|--show-pause|-A|--pause",
+		.cmd		= ETHNL_CMD_SET_PARAMS,
+		.info_mask	= ETH_PARAMS_IM_PAUSE,
+	},
 };
 
 static bool pattern_match(const char *s, const char *pattern)
diff --git a/netlink/params.c b/netlink/params.c
index 6782d98a6956..b45aac166dcd 100644
--- a/netlink/params.c
+++ b/netlink/params.c
@@ -83,6 +83,28 @@ static int show_ring(struct nl_context *nlctx, const struct nlattr *nest)
 	return 0;
 }
 
+static int show_pause(struct nl_context *nlctx, const struct nlattr *nest)
+{
+	const struct nlattr *tb[ETHA_PAUSE_MAX + 1] = {};
+	DECLARE_ATTR_TB_INFO(tb);
+	int ret;
+
+	if (!nest)
+		return -EOPNOTSUPP;
+	ret = mnl_attr_parse_nested(nest, attr_cb, &tb_info);
+	if (ret < 0)
+		return ret;
+
+	printf("Pause parameters for %s:\n", nlctx->devname);
+	show_bool(tb[ETHA_PAUSE_AUTONEG], "Autonegotiate:\t");
+	show_bool(tb[ETHA_PAUSE_RX], "RX:\t\t");
+	show_bool(tb[ETHA_PAUSE_TX], "TX:\t\t");
+	/* ToDo: query negotiated pause frame usage */
+	putchar('\n');
+
+	return 0;
+}
+
 int params_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 {
 	const struct nlattr *tb[ETHA_PARAMS_MAX + 1] = {};
@@ -115,6 +137,15 @@ int params_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 			return MNL_CB_ERROR;
 		}
 	}
+	if (mask_ok(nlctx, ETH_PARAMS_IM_PAUSE)) {
+		ret = show_pause(nlctx, tb[ETHA_PARAMS_PAUSE]);
+		if ((ret < 0) && show_only(nlctx, ETH_PARAMS_IM_PAUSE)) {
+			nlctx->exit_code = 76;
+			errno = -ret;
+			perror("Cannot get device pause settings");
+			return MNL_CB_ERROR;
+		}
+	}
 
 	return MNL_CB_OK;
 }
@@ -141,3 +172,8 @@ int nl_gring(struct cmd_context *ctx)
 {
 	return params_request(ctx, ETH_PARAMS_IM_RING);
 }
+
+int nl_gpause(struct cmd_context *ctx)
+{
+	return params_request(ctx, ETH_PARAMS_IM_PAUSE);
+}
-- 
2.19.0