aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2019-03-29 20:15:16 +0100
committerJohn W. Linville <linville@tuxdriver.com>2019-04-09 14:39:04 -0400
commit34a6dce6456e8c42782a2976f70fd2dd9ae3aed0 (patch)
tree3bb809996a168247759f454347b623412aab698c
parente97bcdca3cb1f2fc4ad72fc787ad1670727a1de5 (diff)
downloadethtool-34a6dce6456e8c42782a2976f70fd2dd9ae3aed0.tar.gz
ethtool: simplify handling of PHY tunable downshift
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> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--ethtool.c43
1 files 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");