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 18/21] netlink: add netlink handler for spause (-A)
Date: Fri, 29 May 2020 01:22:38 +0200 (CEST)	[thread overview]
Message-ID: <88d2b52d85af7af8dba230917bfcf28d69e4f52c.1590707335.git.mkubecek@suse.cz> (raw)
In-Reply-To: <cover.1590707335.git.mkubecek@suse.cz>

Implement "ethtool -A <dev> ..." subcommand to set network device pause
parameters using ETHTOOL_MSG_PAUSE_SET netlink message. These are
traditionally set using ETHTOOL_SPAUSEPARAM ioctl request.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 ethtool.c        |  1 +
 netlink/extapi.h |  2 ++
 netlink/pause.c  | 66 +++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/ethtool.c b/ethtool.c
index b5b7ddab813d..2005e9523f93 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5160,6 +5160,7 @@ static const struct option args[] = {
 	{
 		.opts	= "-A|--pause",
 		.func	= do_spause,
+		.nlfunc	= nl_spause,
 		.help	= "Set pause options",
 		.xhelp	= "		[ autoneg on|off ]\n"
 			  "		[ rx on|off ]\n"
diff --git a/netlink/extapi.h b/netlink/extapi.h
index 00ad74010d2c..b86595763c9d 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -31,6 +31,7 @@ int nl_schannels(struct cmd_context *ctx);
 int nl_gcoalesce(struct cmd_context *ctx);
 int nl_scoalesce(struct cmd_context *ctx);
 int nl_gpause(struct cmd_context *ctx);
+int nl_spause(struct cmd_context *ctx);
 int nl_monitor(struct cmd_context *ctx);
 
 void nl_monitor_usage(void);
@@ -66,6 +67,7 @@ static inline void nl_monitor_usage(void)
 #define nl_gcoalesce		NULL
 #define nl_scoalesce		NULL
 #define nl_gpause		NULL
+#define nl_spause		NULL
 
 #endif /* ETHTOOL_ENABLE_NETLINK */
 
diff --git a/netlink/pause.c b/netlink/pause.c
index c9fdaeeaa0bc..48215d29aa34 100644
--- a/netlink/pause.c
+++ b/netlink/pause.c
@@ -1,7 +1,7 @@
 /*
  * pause.c - netlink implementation of pause commands
  *
- * Implementation of "ethtool -a <dev>"
+ * Implementation of "ethtool -a <dev>" and "ethtool -A <dev> ..."
  */
 
 #include <errno.h>
@@ -12,6 +12,7 @@
 #include "../common.h"
 #include "netlink.h"
 #include "bitset.h"
+#include "parser.h"
 
 /* PAUSE_GET */
 
@@ -156,3 +157,66 @@ int nl_gpause(struct cmd_context *ctx)
 		return ret;
 	return nlsock_send_get_request(nlsk, pause_reply_cb);
 }
+
+/* PAUSE_SET */
+
+static const struct param_parser spause_params[] = {
+	{
+		.arg		= "autoneg",
+		.type		= ETHTOOL_A_PAUSE_AUTONEG,
+		.handler	= nl_parse_u8bool,
+		.min_argc	= 1,
+	},
+	{
+		.arg		= "rx",
+		.type		= ETHTOOL_A_PAUSE_RX,
+		.handler	= nl_parse_u8bool,
+		.min_argc	= 1,
+	},
+	{
+		.arg		= "tx",
+		.type		= ETHTOOL_A_PAUSE_TX,
+		.handler	= nl_parse_u8bool,
+		.min_argc	= 1,
+	},
+	{}
+};
+
+int nl_spause(struct cmd_context *ctx)
+{
+	struct nl_context *nlctx = ctx->nlctx;
+	struct nl_msg_buff *msgbuff;
+	struct nl_socket *nlsk;
+	int ret;
+
+	if (netlink_cmd_check(ctx, ETHTOOL_MSG_PAUSE_SET, false))
+		return -EOPNOTSUPP;
+
+	nlctx->cmd = "-A";
+	nlctx->argp = ctx->argp;
+	nlctx->argc = ctx->argc;
+	nlctx->devname = ctx->devname;
+	nlsk = nlctx->ethnl_socket;
+	msgbuff = &nlsk->msgbuff;
+
+	ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_PAUSE_SET,
+		       NLM_F_REQUEST | NLM_F_ACK);
+	if (ret < 0)
+		return 2;
+	if (ethnla_fill_header(msgbuff, ETHTOOL_A_PAUSE_HEADER,
+			       ctx->devname, 0))
+		return -EMSGSIZE;
+
+	ret = nl_parser(nlctx, spause_params, NULL, PARSER_GROUP_NONE);
+	if (ret < 0)
+		return 1;
+
+	ret = nlsock_sendmsg(nlsk, NULL);
+	if (ret < 0)
+		return 76;
+	ret = nlsock_process_reply(nlsk, nomsg_reply_cb, nlctx);
+	if (ret == 0)
+		return 0;
+	else
+		return nlctx->exit_code ?: 76;
+}
-- 
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 ` [PATCH ethtool 15/21] netlink: add netlink handler for gcoalesce (-c) Michal Kubecek
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 ` Michal Kubecek [this message]
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=88d2b52d85af7af8dba230917bfcf28d69e4f52c.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.