linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 17/23] netlink: add netlink handler for gfec (--show-fec)
Date: Mon, 30 Jul 2018 14:57:09 +0200 (CEST)	[thread overview]
Message-ID: <d311802e5604a21e7bc8a87c21dca60cb3a394ef.1532954671.git.mkubecek@suse.cz> (raw)
In-Reply-To: <cover.1532954671.git.mkubecek@suse.cz>

Implement "ethtool --show-fec <dev>" subcommand showing Forward Error
Correction (FEC) settings using netlink interface command
ETHNL_CMD_GET_PARAMS with ETH_PARAMS_IM_FEC mask.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 common.c          | 10 ++++++++++
 common.h          |  2 ++
 ethtool.c         |  3 ++-
 netlink/extapi.h  |  1 +
 netlink/monitor.c |  5 +++++
 netlink/params.c  | 43 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/common.c b/common.c
index db9a360ffae6..085014e895bf 100644
--- a/common.c
+++ b/common.c
@@ -41,6 +41,16 @@ const struct flag_info flags_msglvl[] = {
 };
 const unsigned int n_flags_msglvl = ARRAY_SIZE(flags_msglvl) - 1;
 
+const struct flag_info flags_fecenc[] = {
+	{ "none",	ETHTOOL_FEC_NONE },
+	{ "auto",	ETHTOOL_FEC_AUTO },
+	{ "off",	ETHTOOL_FEC_OFF },
+	{ "RS",		ETHTOOL_FEC_RS },
+	{ "baser",	ETHTOOL_FEC_BASER },
+	{}
+};
+const unsigned int n_flags_fecenc = ARRAY_SIZE(flags_fecenc) - 1;
+
 const char *names_duplex[] = {
 	[DUPLEX_HALF]		= "Half",
 	[DUPLEX_FULL]		= "Full",
diff --git a/common.h b/common.h
index 36f96ddaa3bd..c05e51b645f8 100644
--- a/common.h
+++ b/common.h
@@ -10,6 +10,8 @@ struct flag_info {
 
 extern const struct flag_info flags_msglvl[];
 extern const unsigned int n_flags_msglvl;
+extern const struct flag_info flags_fecenc[];
+extern const unsigned int n_flags_fecenc;
 
 
 enum link_mode_class {
diff --git a/ethtool.c b/ethtool.c
index 1ad0cd10735a..2c838b7c7f53 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4884,6 +4884,7 @@ static int show_usage(struct cmd_context *ctx);
 #define nl_gpause	NULL
 #define nl_gchannels	NULL
 #define nl_geee		NULL
+#define nl_gfec		NULL
 #endif
 
 static const struct option {
@@ -5091,7 +5092,7 @@ static const struct option {
 	  "		[ ap-shared ]\n"
 	  "		[ dedicated ]\n"
 	  "		[ all ]\n"},
-	{ "--show-fec", 1, do_gfec, NULL,
+	{ "--show-fec", 1, do_gfec, nl_gfec,
 	  "Show FEC settings"},
 	{ "--set-fec", 1, do_sfec, NULL,
 	  "Set FEC settings",
diff --git a/netlink/extapi.h b/netlink/extapi.h
index 40d708a4cb85..b40db721a4c5 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -23,6 +23,7 @@ int nl_gring(struct cmd_context *ctx);
 int nl_gpause(struct cmd_context *ctx);
 int nl_gchannels(struct cmd_context *ctx);
 int nl_geee(struct cmd_context *ctx);
+int nl_gfec(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 799371fdebc2..92031052a425 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -163,6 +163,11 @@ static struct monitor_option monitor_opts[] = {
 		.cmd		= ETHNL_CMD_SET_PARAMS,
 		.info_mask	= ETH_PARAMS_IM_EEE,
 	},
+	{
+		.pattern	= "--show-fec|--set-fec",
+		.cmd		= ETHNL_CMD_SET_PARAMS,
+		.info_mask	= ETH_PARAMS_IM_FEC,
+	},
 };
 
 static bool pattern_match(const char *s, const char *pattern)
diff --git a/netlink/params.c b/netlink/params.c
index 55138b6fdc83..c187ca0b37c5 100644
--- a/netlink/params.c
+++ b/netlink/params.c
@@ -185,6 +185,35 @@ static int show_eee(struct nl_context *nlctx, const struct nlattr *nest)
 	return 0;
 }
 
+static int show_fec(struct nl_context *nlctx, const struct nlattr *nest)
+{
+	const struct nlattr *tb[ETHA_FEC_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("FEC parameters for %s:\n", nlctx->devname);
+	if (tb[ETHA_FEC_MODES]) {
+		const struct nla_bitfield32 *fec_encs =
+			mnl_attr_get_payload(tb[ETHA_FEC_MODES]);
+
+		printf("Active FEC encodings:\t");
+		print_flags(flags_fecenc, n_flags_fecenc, fec_encs->value);
+		putchar('\n');
+		printf("Configured FEC encodings:\t");
+		print_flags(flags_fecenc, n_flags_fecenc, fec_encs->selector);
+		putchar('\n');
+	}
+	putchar('\n');
+
+	return 0;
+}
+
 int params_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 {
 	const struct nlattr *tb[ETHA_PARAMS_MAX + 1] = {};
@@ -244,6 +273,15 @@ int params_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 			return MNL_CB_ERROR;
 		}
 	}
+	if (mask_ok(nlctx, ETH_PARAMS_IM_FEC)) {
+		ret = show_fec(nlctx, tb[ETHA_PARAMS_FEC]);
+		if ((ret < 0) && show_only(nlctx, ETH_PARAMS_IM_FEC)) {
+			nlctx->exit_code = 1;
+			errno = -ret;
+			perror("Cannot get device FEC settings");
+			return MNL_CB_ERROR;
+		}
+	}
 
 	return MNL_CB_OK;
 }
@@ -285,3 +323,8 @@ int nl_geee(struct cmd_context *ctx)
 {
 	return params_request(ctx, ETH_PARAMS_IM_EEE);
 }
+
+int nl_gfec(struct cmd_context *ctx)
+{
+	return params_request(ctx, ETH_PARAMS_IM_FEC);
+}
-- 
2.18.0


  parent reply	other threads:[~2018-07-30 12:57 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 ` [RFC PATCH ethtool v2 06/23] netlink: add netlink handler for gdrv (-i) Michal Kubecek
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 ` Michal Kubecek [this message]
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=d311802e5604a21e7bc8a87c21dca60cb3a394ef.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).