From: Johan Gunnarsson <johan.gunnarsson@axis.com>
To: <netdev@vger.kernel.org>
Cc: <starvik@axis.com>
Subject: [PATCH] ethtool: don't overwrite useful bits in advertising bitfield
Date: Tue, 14 Aug 2012 16:15:45 +0200 [thread overview]
Message-ID: <1344953745-13208-1-git-send-email-johangu@axis.com> (raw)
There are bits in this bitfield that we want to leave untouched (PAUSE
and ASYM_PAUSE bits) when changing other bits (speed and duplex bits.)
Previously, these were always overwritten to zero when running commands
like "ethtool -s eth0 speed 10 duplex full autoneg off".
Signed-off-by: Johan Gunnarsson <johangu@axis.com>
---
ethtool.c | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/ethtool.c b/ethtool.c
index e573357..efa12c7 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -46,6 +46,18 @@
#define MAX_ADDR_LEN 32
#endif
+#define ALL_ADVERTISED_MODES \
+ (ADVERTISED_10baseT_Half | \
+ ADVERTISED_10baseT_Full | \
+ ADVERTISED_100baseT_Half | \
+ ADVERTISED_100baseT_Full | \
+ ADVERTISED_1000baseT_Half | \
+ ADVERTISED_1000baseT_Full | \
+ ADVERTISED_2500baseX_Full | \
+ ADVERTISED_10000baseT_Full | \
+ ADVERTISED_20000baseMLD2_Full | \
+ ADVERTISED_20000baseKR2_Full)
+
#ifndef HAVE_NETIF_MSG
enum {
NETIF_MSG_DRV = 0x0001,
@@ -2202,6 +2214,7 @@ static int do_sset(struct cmd_context *ctx)
int autoneg_wanted = -1;
int phyad_wanted = -1;
int xcvr_wanted = -1;
+ int full_advertising_wanted = -1;
int advertising_wanted = -1;
int gset_changed = 0; /* did anything in GSET change? */
u32 wol_wanted = 0;
@@ -2277,7 +2290,7 @@ static int do_sset(struct cmd_context *ctx)
i += 1;
if (i >= argc)
exit_bad_args();
- advertising_wanted = get_int(argp[i], 16);
+ full_advertising_wanted = get_int(argp[i], 16);
} else if (!strcmp(argp[i], "phyad")) {
gset_changed = 1;
i += 1;
@@ -2334,7 +2347,10 @@ static int do_sset(struct cmd_context *ctx)
}
}
- if (advertising_wanted < 0) {
+ if (full_advertising_wanted < 0) {
+ /* User didn't supply a full advertisement bitfield:
+ * construct one from the specified speed and duplex.
+ */
if (speed_wanted == SPEED_10 && duplex_wanted == DUPLEX_HALF)
advertising_wanted = ADVERTISED_10baseT_Half;
else if (speed_wanted == SPEED_10 &&
@@ -2405,19 +2421,20 @@ static int do_sset(struct cmd_context *ctx)
}
if (autoneg_wanted == AUTONEG_ENABLE &&
advertising_wanted == 0) {
- ecmd.advertising = ecmd.supported &
- (ADVERTISED_10baseT_Half |
- ADVERTISED_10baseT_Full |
- ADVERTISED_100baseT_Half |
- ADVERTISED_100baseT_Full |
- ADVERTISED_1000baseT_Half |
- ADVERTISED_1000baseT_Full |
- ADVERTISED_2500baseX_Full |
- ADVERTISED_10000baseT_Full |
- ADVERTISED_20000baseMLD2_Full |
- ADVERTISED_20000baseKR2_Full);
+ /* Auto negotation enabled, but with
+ * unspecified speed and duplex: enable all
+ * supported speeds and duplexes.
+ */
+ ecmd.advertising = (ecmd.advertising &
+ ~ALL_ADVERTISED_MODES) |
+ (ALL_ADVERTISED_MODES & ecmd.supported);
} else if (advertising_wanted > 0) {
- ecmd.advertising = advertising_wanted;
+ /* Enable all requested modes */
+ ecmd.advertising = (ecmd.advertising &
+ ~ALL_ADVERTISED_MODES) |
+ (advertising_wanted & ecmd.supported);
+ } else if (full_advertising_wanted > 0) {
+ ecmd.advertising = full_advertising_wanted;
}
/* Try to perform the update. */
--
1.7.10
next reply other threads:[~2012-08-14 14:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-14 14:15 Johan Gunnarsson [this message]
2012-08-20 15:22 ` [PATCH] ethtool: don't overwrite useful bits in advertising bitfield Ben Hutchings
2012-08-21 8:41 ` Johan Gunnarsson
2012-08-21 15:11 ` Ben Hutchings
2012-08-21 16:45 ` Johan Gunnarsson
2012-08-21 17:03 ` Ben Hutchings
2012-08-24 9:50 ` Johan Gunnarsson
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=1344953745-13208-1-git-send-email-johangu@axis.com \
--to=johan.gunnarsson@axis.com \
--cc=netdev@vger.kernel.org \
--cc=starvik@axis.com \
/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).