All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Kubecek <mkubecek@suse.cz>
To: John Linville <linville@tuxdriver.com>, netdev@vger.kernel.org
Cc: Andrew Lunn <andrew@lunn.ch>, Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH ethtool 15/21] netlink: add netlink handler for gcoalesce (-c)
Date: Fri, 29 May 2020 01:22:23 +0200 (CEST)	[thread overview]
Message-ID: <3bc7c003d31a82ffe1d1254fcf606ae3dba3fa64.1590707335.git.mkubecek@suse.cz> (raw)
In-Reply-To: <cover.1590707335.git.mkubecek@suse.cz>

Implement "ethtool -c <dev>" subcommand using ETHTOOL_MSG_COALESCE_GET
netlink message. This retrieves and displays device coalescing parameters,
traditionally provided by ETHTOOL_GCOALESCE ioctl request.

Unlike the ioctl code, netlink can distinguish between unsupported
parameter (shown as "n/a") and zero value ("0" or "off").

Also register the callback with monitor code so that the monitor can
display ETHTOOL_MSG_COALESCE_NTF notifications.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 Makefile.am        |  2 +-
 ethtool.c          |  1 +
 netlink/coalesce.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++
 netlink/extapi.h   |  2 +
 netlink/monitor.c  |  8 ++++
 netlink/netlink.h  |  9 +++++
 6 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 netlink/coalesce.c

diff --git a/Makefile.am b/Makefile.am
index b5e32bec68f1..19cef636286f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,7 +32,7 @@ ethtool_SOURCES += \
 		  netlink/settings.c netlink/parser.c netlink/parser.h \
 		  netlink/permaddr.c netlink/prettymsg.c netlink/prettymsg.h \
 		  netlink/features.c netlink/privflags.c netlink/rings.c \
-		  netlink/channels.c \
+		  netlink/channels.c netlink/coalesce.c \
 		  netlink/desc-ethtool.c netlink/desc-genlctrl.c \
 		  netlink/desc-rtnl.c \
 		  uapi/linux/ethtool_netlink.h \
diff --git a/ethtool.c b/ethtool.c
index cf888e08b5a4..97280cb676db 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5167,6 +5167,7 @@ static const struct option args[] = {
 	{
 		.opts	= "-c|--show-coalesce",
 		.func	= do_gcoalesce,
+		.nlfunc	= nl_gcoalesce,
 		.help	= "Show coalesce options"
 	},
 	{
diff --git a/netlink/coalesce.c b/netlink/coalesce.c
new file mode 100644
index 000000000000..f1ad671c3bd4
--- /dev/null
+++ b/netlink/coalesce.c
@@ -0,0 +1,91 @@
+/*
+ * coalesce.c - netlink implementation of coalescing commands
+ *
+ * Implementation of "ethtool -c <dev>"
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "../internal.h"
+#include "../common.h"
+#include "netlink.h"
+
+/* COALESCE_GET */
+
+int coalesce_reply_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+	const struct nlattr *tb[ETHTOOL_A_COALESCE_MAX + 1] = {};
+	DECLARE_ATTR_TB_INFO(tb);
+	struct nl_context *nlctx = data;
+	bool silent;
+	int err_ret;
+	int ret;
+
+	silent = nlctx->is_dump || nlctx->is_monitor;
+	err_ret = silent ? MNL_CB_OK : MNL_CB_ERROR;
+	ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+	if (ret < 0)
+		return err_ret;
+	nlctx->devname = get_dev_name(tb[ETHTOOL_A_COALESCE_HEADER]);
+	if (!dev_ok(nlctx))
+		return err_ret;
+
+	if (silent)
+		putchar('\n');
+	printf("Coalesce parameters for %s:\n", nlctx->devname);
+	printf("Adaptive RX: %s  TX: %s\n",
+	       u8_to_bool(tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX]),
+	       u8_to_bool(tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX]));
+	show_u32(tb[ETHTOOL_A_COALESCE_STATS_BLOCK_USECS],
+		 "stats-block-usecs: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL],
+		 "sample-interval: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_PKT_RATE_LOW], "pkt-rate-low: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_PKT_RATE_HIGH], "pkt-rate-high: ");
+	putchar('\n');
+	show_u32(tb[ETHTOOL_A_COALESCE_RX_USECS], "rx-usecs: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES], "rx-frames: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_RX_USECS_IRQ], "rx-usecs-irq: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ], "rx-frames-irq: ");
+	putchar('\n');
+	show_u32(tb[ETHTOOL_A_COALESCE_TX_USECS], "tx-usecs: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES], "tx-frames: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_TX_USECS_IRQ], "tx-usecs-irq: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ], "tx-frames-irq: ");
+	putchar('\n');
+	show_u32(tb[ETHTOOL_A_COALESCE_RX_USECS_LOW], "rx-usecs-low: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW], "rx-frame-low: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_TX_USECS_LOW], "tx-usecs-low: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW], "tx-frame-low: ");
+	putchar('\n');
+	show_u32(tb[ETHTOOL_A_COALESCE_RX_USECS_HIGH], "rx-usecs-high: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH], "rx-frame-high: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_TX_USECS_HIGH], "tx-usecs-high: ");
+	show_u32(tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH], "tx-frame-high: ");
+	putchar('\n');
+
+	return MNL_CB_OK;
+}
+
+int nl_gcoalesce(struct cmd_context *ctx)
+{
+	struct nl_context *nlctx = ctx->nlctx;
+	struct nl_socket *nlsk = nlctx->ethnl_socket;
+	int ret;
+
+	if (netlink_cmd_check(ctx, ETHTOOL_MSG_COALESCE_GET, true))
+		return -EOPNOTSUPP;
+	if (ctx->argc > 0) {
+		fprintf(stderr, "ethtool: unexpected parameter '%s'\n",
+			*ctx->argp);
+		return 1;
+	}
+
+	ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_COALESCE_GET,
+				      ETHTOOL_A_COALESCE_HEADER, 0);
+	if (ret < 0)
+		return ret;
+	return nlsock_send_get_request(nlsk, coalesce_reply_cb);
+}
diff --git a/netlink/extapi.h b/netlink/extapi.h
index 9cea57ac040a..f25fc6e4389f 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -28,6 +28,7 @@ int nl_gring(struct cmd_context *ctx);
 int nl_sring(struct cmd_context *ctx);
 int nl_gchannels(struct cmd_context *ctx);
 int nl_schannels(struct cmd_context *ctx);
+int nl_gcoalesce(struct cmd_context *ctx);
 int nl_monitor(struct cmd_context *ctx);
 
 void nl_monitor_usage(void);
@@ -60,6 +61,7 @@ static inline void nl_monitor_usage(void)
 #define nl_sring		NULL
 #define nl_gchannels		NULL
 #define nl_schannels		NULL
+#define nl_gcoalesce		NULL
 
 #endif /* ETHTOOL_ENABLE_NETLINK */
 
diff --git a/netlink/monitor.c b/netlink/monitor.c
index 5dada99168b0..ef9cc7a6923a 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -47,6 +47,10 @@ static struct {
 		.cmd	= ETHTOOL_MSG_CHANNELS_NTF,
 		.cb	= channels_reply_cb,
 	},
+	{
+		.cmd	= ETHTOOL_MSG_COALESCE_NTF,
+		.cb	= coalesce_reply_cb,
+	},
 };
 
 static void clear_filter(struct nl_context *nlctx)
@@ -134,6 +138,10 @@ static struct monitor_option monitor_opts[] = {
 		.pattern	= "-l|--show-channels|-L|--set-channels",
 		.cmd		= ETHTOOL_MSG_CHANNELS_NTF,
 	},
+	{
+		.pattern	= "-c|--show-coalesce|-C|--coalesce",
+		.cmd		= ETHTOOL_MSG_COALESCE_NTF,
+	},
 };
 
 static bool pattern_match(const char *s, const char *pattern)
diff --git a/netlink/netlink.h b/netlink/netlink.h
index 511bcb2f2098..d35048583f5e 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -66,6 +66,7 @@ int features_reply_cb(const struct nlmsghdr *nlhdr, void *data);
 int privflags_reply_cb(const struct nlmsghdr *nlhdr, void *data);
 int rings_reply_cb(const struct nlmsghdr *nlhdr, void *data);
 int channels_reply_cb(const struct nlmsghdr *nlhdr, void *data);
+int coalesce_reply_cb(const struct nlmsghdr *nlhdr, void *data);
 
 /* dump helpers */
 
@@ -77,6 +78,14 @@ static inline void show_u32(const struct nlattr *attr, const char *label)
 		printf("%sn/a\n", label);
 }
 
+static inline const char *u8_to_bool(const struct nlattr *attr)
+{
+	if (attr)
+		return mnl_attr_get_u8(attr) ? "on" : "off";
+	else
+		return "n/a";
+}
+
 /* misc */
 
 static inline void copy_devname(char *dst, const char *src)
-- 
2.26.2


  parent reply	other threads:[~2020-05-28 23:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28 23:21 [PATCH ethtool 00/21] netlink interface update for 5.7 release Michal Kubecek
2020-05-28 23:21 ` [PATCH ethtool 01/21] netlink: fix build warnings Michal Kubecek
2020-06-06 18:47   ` Heiko Thiery
2020-05-28 23:21 ` [PATCH ethtool 02/21] netlink: fix nest type grouping in parser Michal Kubecek
2020-05-29 14:28   ` Andrew Lunn
2020-05-28 23:21 ` [PATCH ethtool 03/21] netlink: fix msgbuff_append() helper Michal Kubecek
2020-05-29 14:29   ` Andrew Lunn
2020-05-28 23:21 ` [PATCH ethtool 04/21] update UAPI header copies Michal Kubecek
2020-05-28 23:21 ` [PATCH ethtool 05/21] netlink: add more ethtool netlink message format descriptions Michal Kubecek
2020-05-28 23:21 ` [PATCH ethtool 06/21] selftest: omit test-features if netlink is enabled Michal Kubecek
2020-05-28 23:21 ` [PATCH ethtool 07/21] netlink: add netlink handler for gfeatures (-k) Michal Kubecek
2020-05-28 23:21 ` [PATCH ethtool 08/21] netlink: add netlink handler for sfeatures (-K) Michal Kubecek
2020-05-28 23:21 ` [PATCH ethtool 09/21] netlink: add netlink handler for gprivflags (--show-priv-flags) Michal Kubecek
2020-05-28 23:21 ` [PATCH ethtool 10/21] netlink: add netlink handler for sprivflags (--set-priv-flags) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 11/21] netlink: add netlink handler for gring (-g) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 12/21] netlink: add netlink handler for sring (-G) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 13/21] netlink: add netlink handler for gchannels (-l) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 14/21] netlink: add netlink handler for schannels (-L) Michal Kubecek
2020-05-28 23:22 ` Michal Kubecek [this message]
2020-05-28 23:22 ` [PATCH ethtool 16/21] netlink: add netlink handler for scoalesce (-C) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 17/21] netlink: add netlink handler for gpause (-a) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 18/21] netlink: add netlink handler for spause (-A) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 19/21] netlink: add netlink handler for geee (--show-eee) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 20/21] netlink: add netlink handler for seee (--set-eee) Michal Kubecek
2020-05-28 23:22 ` [PATCH ethtool 21/21] netlink: add netlink handler for tsinfo (-T) Michal Kubecek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3bc7c003d31a82ffe1d1254fcf606ae3dba3fa64.1590707335.git.mkubecek@suse.cz \
    --to=mkubecek@suse.cz \
    --cc=andrew@lunn.ch \
    --cc=linville@tuxdriver.com \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.