netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: John Linville <linville@tuxdriver.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: [PATCH v2 2/4] ethtool: simplify handling of PHY tunable downshift
Date: Fri, 29 Mar 2019 20:15:16 +0100	[thread overview]
Message-ID: <e67a7b61-0813-22ba-cdca-9ba7db9bc3be@gmail.com> (raw)
In-Reply-To: <86b1ab67-fd7e-2789-1218-8c14e8198a60@gmail.com>

In preparation of adding support for Fast Link Down as PHY tunable
let's simplify the handling of PHY tunable downshift a little.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 ethtool.c | 43 +++++++++++++------------------------------
 1 file changed, 13 insertions(+), 30 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 59131e8..f67cd1b 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4818,28 +4818,15 @@ static int do_get_phy_tunable(struct cmd_context *ctx)
 {
 	int argc = ctx->argc;
 	char **argp = ctx->argp;
-	u8 downshift_changed = 0;
-	int i;
 
 	if (argc < 1)
 		exit_bad_args();
-	for (i = 0; i < argc; i++) {
-		if (!strcmp(argp[i], "downshift")) {
-			downshift_changed = 1;
-			i += 1;
-			if (i < argc)
-				exit_bad_args();
-		} else  {
-			exit_bad_args();
-		}
-	}
 
-	if (downshift_changed) {
+	if (!strcmp(argp[0], "downshift")) {
 		struct {
 			struct ethtool_tunable ds;
-			u8 __count;
+			u8 count;
 		} cont;
-		u8 count = 0;
 
 		cont.ds.cmd = ETHTOOL_PHY_GTUNABLE;
 		cont.ds.id = ETHTOOL_PHY_DOWNSHIFT;
@@ -4849,11 +4836,12 @@ static int do_get_phy_tunable(struct cmd_context *ctx)
 			perror("Cannot Get PHY downshift count");
 			return 87;
 		}
-		count = *((u8 *)&cont.ds.data[0]);
-		if (count)
-			fprintf(stdout, "Downshift count: %d\n", count);
+		if (cont.count)
+			fprintf(stdout, "Downshift count: %d\n", cont.count);
 		else
 			fprintf(stdout, "Downshift disabled\n");
+	} else {
+		exit_bad_args();
 	}
 
 	return 0;
@@ -4995,17 +4983,12 @@ static int do_set_phy_tunable(struct cmd_context *ctx)
 	u8 ds_cnt = DOWNSHIFT_DEV_DEFAULT_COUNT;
 	u8 ds_changed = 0, ds_has_cnt = 0, ds_enable = 0;
 
-	if (ctx->argc == 0)
-		exit_bad_args();
-
 	/* Parse arguments */
-	while (ctx->argc) {
-		if (parse_named_bool(ctx, "downshift", &ds_enable)) {
-			ds_changed = 1;
-			ds_has_cnt = parse_named_u8(ctx, "count", &ds_cnt);
-		} else {
-			exit_bad_args();
-		}
+	if (parse_named_bool(ctx, "downshift", &ds_enable)) {
+		ds_changed = 1;
+		ds_has_cnt = parse_named_u8(ctx, "count", &ds_cnt);
+	} else {
+		exit_bad_args();
 	}
 
 	/* Validate parameters */
@@ -5029,14 +5012,14 @@ static int do_set_phy_tunable(struct cmd_context *ctx)
 	if (ds_changed) {
 		struct {
 			struct ethtool_tunable ds;
-			u8 __count;
+			u8 count;
 		} cont;
 
 		cont.ds.cmd = ETHTOOL_PHY_STUNABLE;
 		cont.ds.id = ETHTOOL_PHY_DOWNSHIFT;
 		cont.ds.type_id = ETHTOOL_TUNABLE_U8;
 		cont.ds.len = 1;
-		*((u8 *)&cont.ds.data[0]) = ds_cnt;
+		cont.count = ds_cnt;
 		err = send_ioctl(ctx, &cont.ds);
 		if (err < 0) {
 			perror("Cannot Set PHY downshift count");
-- 
2.21.0




  parent reply	other threads:[~2019-03-29 19:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-29 19:13 [PATCH v2 0/4] ethtool: add support for new PHY tunable Fast Link Down Heiner Kallweit
2019-03-29 19:14 ` [PATCH v2 1/4] ethtool: sync ethtool-copy.h with linux-next from 03/28/2019 Heiner Kallweit
2019-03-29 21:24   ` Florian Fainelli
2019-03-29 19:15 ` Heiner Kallweit [this message]
2019-03-29 21:24   ` [PATCH v2 2/4] ethtool: simplify handling of PHY tunable downshift Florian Fainelli
2019-03-29 19:15 ` [PATCH v2 3/4] ethtool: add support for PHY tunable Fast Link Down Heiner Kallweit
2019-03-29 21:25   ` Florian Fainelli
2019-03-29 19:17 ` [PATCH v2 4/4] ethtool: add PHY Fast Link Down tunable to man page Heiner Kallweit
2019-03-29 21:26   ` Florian Fainelli
2019-03-30  8:39   ` Andrew Lunn
2019-04-09 18:43 ` [PATCH v2 0/4] ethtool: add support for new PHY tunable Fast Link Down John W. Linville

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=e67a7b61-0813-22ba-cdca-9ba7db9bc3be@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --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).