@@ -31,7 +31,7 @@ ethtool_SOURCES += \
netlink/monitor.c netlink/bitset.c netlink/bitset.h \
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/features.c netlink/privflags.c netlink/rings.c \
netlink/desc-ethtool.c netlink/desc-genlctrl.c \
netlink/desc-rtnl.c \
uapi/linux/ethtool_netlink.h \
@@ -5199,6 +5199,7 @@ static const struct option args[] = {
{
.opts = "-g|--show-ring",
.func = do_gring,
+ .nlfunc = nl_gring,
.help = "Query RX/TX ring parameters"
},
{
@@ -24,6 +24,7 @@ int nl_gfeatures(struct cmd_context *ctx);
int nl_sfeatures(struct cmd_context *ctx);
int nl_gprivflags(struct cmd_context *ctx);
int nl_sprivflags(struct cmd_context *ctx);
+int nl_gring(struct cmd_context *ctx);
int nl_monitor(struct cmd_context *ctx);
void nl_monitor_usage(void);
@@ -52,6 +53,7 @@ static inline void nl_monitor_usage(void)
#define nl_sfeatures NULL
#define nl_gprivflags NULL
#define nl_sprivflags NULL
+#define nl_gring NULL
#endif /* ETHTOOL_ENABLE_NETLINK */
@@ -39,6 +39,10 @@ static struct {
.cmd = ETHTOOL_MSG_PRIVFLAGS_NTF,
.cb = privflags_reply_cb,
},
+ {
+ .cmd = ETHTOOL_MSG_RINGS_NTF,
+ .cb = rings_reply_cb,
+ },
};
static void clear_filter(struct nl_context *nlctx)
@@ -118,6 +122,10 @@ static struct monitor_option monitor_opts[] = {
.pattern = "--show-priv-flags|--set-priv-flags",
.cmd = ETHTOOL_MSG_PRIVFLAGS_NTF,
},
+ {
+ .pattern = "-g|--show-ring|-G|--set-ring",
+ .cmd = ETHTOOL_MSG_RINGS_NTF,
+ },
};
static bool pattern_match(const char *s, const char *pattern)
@@ -64,6 +64,19 @@ int wol_reply_cb(const struct nlmsghdr *nlhdr, void *data);
int debug_reply_cb(const struct nlmsghdr *nlhdr, void *data);
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);
+
+/* dump helpers */
+
+static inline void show_u32(const struct nlattr *attr, const char *label)
+{
+ if (attr)
+ printf("%s%u\n", label, mnl_attr_get_u32(attr));
+ else
+ printf("%sn/a\n", label);
+}
+
+/* misc */
static inline void copy_devname(char *dst, const char *src)
{
new file mode 100644
@@ -0,0 +1,71 @@
+/*
+ * rings.c - netlink implementation of ring commands
+ *
+ * Implementation of "ethtool -g <dev>"
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "../internal.h"
+#include "../common.h"
+#include "netlink.h"
+
+/* RINGS_GET */
+
+int rings_reply_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+ const struct nlattr *tb[ETHTOOL_A_RINGS_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_RINGS_HEADER]);
+ if (!dev_ok(nlctx))
+ return err_ret;
+
+ if (silent)
+ putchar('\n');
+ printf("Ring parameters for %s:\n", nlctx->devname);
+ printf("Pre-set maximums:\n");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_MAX], "RX:\t\t");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_MINI_MAX], "RX Mini:\t");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_JUMBO_MAX], "RX Jumbo:\t");
+ show_u32(tb[ETHTOOL_A_RINGS_TX_MAX], "TX:\t\t");
+ printf("Current hardware settings:\n");
+ show_u32(tb[ETHTOOL_A_RINGS_RX], "RX:\t\t");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_MINI], "RX Mini:\t");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_JUMBO], "RX Jumbo:\t");
+ show_u32(tb[ETHTOOL_A_RINGS_TX], "TX:\t\t");
+
+ return MNL_CB_OK;
+}
+
+int nl_gring(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_RINGS_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_RINGS_GET,
+ ETHTOOL_A_RINGS_HEADER, 0);
+ if (ret < 0)
+ return ret;
+ return nlsock_send_get_request(nlsk, rings_reply_cb);
+}
Implement "ethtool -g <dev>" subcommand using ETHTOOL_MSG_RINGS_GET netlink message. This retrieves and displays device ring sizes, traditionally provided by ETHTOOL_GRINGPARAM ioctl request. Also register the callback with monitor code so that the monitor can display ETHTOOL_MSG_RINGS_NTF notifications. Signed-off-by: Michal Kubecek <mkubecek@suse.cz> --- Makefile.am | 2 +- ethtool.c | 1 + netlink/extapi.h | 2 ++ netlink/monitor.c | 8 ++++++ netlink/netlink.h | 13 +++++++++ netlink/rings.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 netlink/rings.c