From: Michal Kubecek <mkubecek@suse.cz>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
"John W. Linville" <linville@tuxdriver.com>
Subject: [RFC PATCH ethtool v2 06/23] netlink: add netlink handler for gdrv (-i)
Date: Mon, 30 Jul 2018 14:56:14 +0200 (CEST) [thread overview]
Message-ID: <26ffda3b080026f5f0ca1d36dcdee201923b4f33.1532954671.git.mkubecek@suse.cz> (raw)
In-Reply-To: <cover.1532954671.git.mkubecek@suse.cz>
Implement "-i" subcommand using netlink interface command
ETHNL_CMD_GET_DRVINFO.
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
Makefile.am | 1 +
ethtool.c | 3 ++-
netlink/drvinfo.c | 43 +++++++++++++++++++++++++++++++++++++++++++
netlink/extapi.h | 1 +
netlink/monitor.c | 10 ++++++++++
5 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 netlink/drvinfo.c
diff --git a/Makefile.am b/Makefile.am
index a412734fffd1..7e24fe8c50f4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -23,6 +23,7 @@ if ETHTOOL_ENABLE_NETLINK
ethtool_SOURCES += \
netlink/netlink.c netlink/netlink.h netlink/extapi.h \
netlink/strset.c netlink/strset.h netlink/monitor.c \
+ netlink/drvinfo.c \
uapi/linux/ethtool_netlink.h \
uapi/linux/netlink.h uapi/linux/genetlink.h
ethtool_CFLAGS += @MNL_CFLAGS@
diff --git a/ethtool.c b/ethtool.c
index b7f40d2f3826..0edb80b19b9d 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5056,6 +5056,7 @@ static int show_usage(struct cmd_context *ctx);
/* Just define all netlink handlers as null when building without netlink
* support so that we do not get unresolved symbols in args array below
*/
+#define nl_gdrv NULL
#endif
static const struct option {
@@ -5125,7 +5126,7 @@ static const struct option {
{ "-K|--features|--offload", 1, do_sfeatures, NULL,
"Set protocol offload and other features",
" FEATURE on|off ...\n" },
- { "-i|--driver", 1, do_gdrv, NULL,
+ { "-i|--driver", 1, do_gdrv, nl_gdrv,
"Show driver information" },
{ "-d|--register-dump", 1, do_gregs, NULL,
"Do a register dump",
diff --git a/netlink/drvinfo.c b/netlink/drvinfo.c
new file mode 100644
index 000000000000..78b4394788a5
--- /dev/null
+++ b/netlink/drvinfo.c
@@ -0,0 +1,43 @@
+#include "../internal.h"
+#include "netlink.h"
+
+int drvinfo_reply_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+ const struct nlattr *tb[ETHA_DRVINFO_MAX + 1] = {};
+ DECLARE_ATTR_TB_INFO(tb);
+ struct nl_context *nlctx = data;
+ int ret;
+
+ ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+ if (ret < 0)
+ return ret;
+ nlctx->devname = get_dev_name(tb[ETHA_DRVINFO_DEV]);
+ if (!dev_ok(nlctx))
+ return MNL_CB_OK;
+ if (nlctx->is_dump || nlctx->is_monitor)
+ fprintf(stdout, "\nDriver info for %s:\n", nlctx->devname);
+
+ show_string(tb, ETHA_DRVINFO_DRIVER, "driver");
+ show_string(tb, ETHA_DRVINFO_VERSION, "version");
+ show_string(tb, ETHA_DRVINFO_FWVERSION, "firmware-version");
+ show_string(tb, ETHA_DRVINFO_EROM_VER, "expansion-rom-version");
+ show_string(tb, ETHA_DRVINFO_BUSINFO, "bus-info");
+ show_u32_yn(tb, ETHA_DRVINFO_N_STATS, "supports-statistics");
+ show_u32_yn(tb, ETHA_DRVINFO_TESTINFO_LEN, "supports-test");
+ show_u32_yn(tb, ETHA_DRVINFO_EEDUMP_LEN, "supports-eeprom-access");
+ show_u32_yn(tb, ETHA_DRVINFO_REGDUMP_LEN, "supports-register-dump");
+ show_u32_yn(tb, ETHA_DRVINFO_N_PRIV_FLAGS, "supports-priv-flags");
+
+ return MNL_CB_OK;
+}
+
+int nl_gdrv(struct cmd_context *ctx)
+{
+ int ret;
+
+ ret = ethnl_prep_get_request(ctx, ETHNL_CMD_GET_DRVINFO,
+ ETHA_DRVINFO_DEV);
+ if (ret < 0)
+ return ret;
+ return ethnl_send_get_request(ctx->nlctx, drvinfo_reply_cb);
+}
diff --git a/netlink/extapi.h b/netlink/extapi.h
index 827e3732888a..546090a02a0d 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -13,6 +13,7 @@ struct nl_context;
int netlink_init(struct cmd_context *ctx);
int netlink_done(struct cmd_context *ctx);
+int nl_gdrv(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 d7ed562356f1..ae7d6080e03d 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -66,6 +66,8 @@ static int monitor_event_cb(const struct nlmsghdr *nlhdr, void *data)
return MNL_CB_OK;
}
+int drvinfo_reply_cb(const struct nlmsghdr *nlhdr, void *data);
+
static struct {
uint8_t cmd;
mnl_cb_t cb;
@@ -74,6 +76,10 @@ static struct {
.cmd = ETHNL_CMD_EVENT,
.cb = monitor_event_cb,
},
+ {
+ .cmd = ETHNL_CMD_SET_DRVINFO,
+ .cb = drvinfo_reply_cb,
+ },
};
static int monitor_any_cb(const struct nlmsghdr *nlhdr, void *data)
@@ -103,6 +109,10 @@ static struct monitor_option monitor_opts[] = {
.pattern = "--all",
.cmd = 0,
},
+ {
+ .pattern = "-i|--driver",
+ .cmd = ETHNL_CMD_SET_DRVINFO,
+ },
};
static bool pattern_match(const char *s, const char *pattern)
--
2.18.0
next prev parent reply other threads:[~2018-07-30 12:56 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-30 12:55 [RFC PATCH ethtool v2 00/23] ethtool netlink interface (userspace side) (WiP) Michal Kubecek
2018-07-30 12:55 ` [RFC PATCH ethtool v2 01/23] move UAPI header copies to a separate directory Michal Kubecek
2018-07-30 12:55 ` [RFC PATCH ethtool v2 02/23] update UAPI header copies Michal Kubecek
2018-07-30 12:55 ` [RFC PATCH ethtool v2 03/23] netlink: add netlink interface Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 04/23] netlink: add support for string sets Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 05/23] netlink: add notification monitor Michal Kubecek
2018-07-30 12:56 ` Michal Kubecek [this message]
2018-07-30 12:56 ` [RFC PATCH ethtool v2 07/23] netlink: add netlink handler for gset (no option) Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 08/23] netlink: add helpers for command line parsing Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 09/23] netlink: add netlink handler for sset (-s) Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 10/23] netlink: add netlink handler for gfeatures (-k) Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 11/23] netlink: add netlink handler for sfeatures (-K) Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 12/23] netlink: add netlink handler for gcoalesce (-c) Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 13/23] netlink: add netlink handler for gring (-g) Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 14/23] netlink: add netlink handler for gpause (-a) Michal Kubecek
2018-07-30 12:56 ` [RFC PATCH ethtool v2 15/23] netlink: add netlink handler for gchannels (-l) Michal Kubecek
2018-07-30 12:57 ` [RFC PATCH ethtool v2 16/23] netlink: add netlink handler for geee (--show-eee) Michal Kubecek
2018-07-30 12:57 ` [RFC PATCH ethtool v2 17/23] netlink: add netlink handler for gfec (--show-fec) Michal Kubecek
2018-07-30 12:57 ` [RFC PATCH ethtool v2 18/23] netlink: add netlink handler for scoalesce (-C) Michal Kubecek
2018-07-30 12:57 ` [RFC PATCH ethtool v2 19/23] netlink: add netlink handler for sring (-G) Michal Kubecek
2018-07-30 12:57 ` [RFC PATCH ethtool v2 20/23] netlink: add netlink handler for spause (-A) Michal Kubecek
2018-07-30 12:57 ` [RFC PATCH ethtool v2 21/23] netlink: add netlink handler for schannels (-L) Michal Kubecek
2018-07-30 12:57 ` [RFC PATCH ethtool v2 22/23] netlink: add netlink handler for seee (--set-eee) Michal Kubecek
2018-07-30 12:57 ` [RFC PATCH ethtool v2 23/23] netlink: add netlink handler for sfec (--set-fec) 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=26ffda3b080026f5f0ca1d36dcdee201923b4f33.1532954671.git.mkubecek@suse.cz \
--to=mkubecek@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).