Skip to contentSkip to conversation

Ethtool: EEE support

PATCH Superseded Yuval Mintz 2 participants 7 messages Jun 5, 2012 – Jun 6, 2012

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Ethtool: EEE support

Hi Ben,

This patch series follows another series sent to net-next which adds EEE support in the Ethtool API.

This series extends the ethtool application and allows it to control the eee feature via the new '--get-eee' and and '--set-eee' commands.

Thanks,
Yuval Mintz

#1 lore raw

PATCH 1/2 Ethtool: Add EEE support

This patch adds 2 new ethtool commands which can be used to manipulate network interfaces' support in EEE.

Output of 'get' has the following form:

EEE Settings for p2p1:
EEE status: enabled - active
Tx LPI: 1000 (u)
Supported EEE link modes: 10000baseT/Full Advertised EEE link modes: 10000baseT/Full Link partner advertised EEE link modes: 10000baseT/Full

Thanks goes to Giuseppe Cavallaro for his original patch.

---
 ethtool-copy.h |   15 ++++++
 ethtool.c      |  139 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 134 insertions(+), 20 deletions(-)
ethtool-copy.h +15 -0
index 9e26a76..1fcc799 100644
@@ -133,6 +133,19 @@ struct ethtool_eeprom {
 	__u8	data[0];
 };
 
+/* EEE settings */
+struct ethtool_eee {
+	__u32	cmd;
+	__u32	supported;
+	__u32	advertised;
+	__u32	lp_advertised;
+	__u32	eee_active;
+	__u32	eee_enabled;
+	__u32	tx_lpi_enabled;
+	__u32	tx_lpi_timer;
+	__u32	reserved[2];
+};
+
 /**
  * struct ethtool_modinfo - plugin module eeprom information
  * @cmd: %ETHTOOL_GMODULEINFO
@@ -848,6 +861,8 @@ enum ethtool_sfeatures_retval_bits {
 #define ETHTOOL_GET_TS_INFO	0x00000041 /* Get time stamping and PHC info */
 #define ETHTOOL_GMODULEINFO	0x00000042 /* Get plug-in module information */
 #define ETHTOOL_GMODULEEEPROM	0x00000043 /* Get plug-in module eeprom */
+#define ETHTOOL_GEEE		0x00000044 /* Get EEE settings */
+#define ETHTOOL_SEEE		0x00000045 /* Set EEE settings */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET
ethtool.c +119 -20

192 lines not on this page · raw message

Signature · 1 line
1.7.9.rc2
#2 lore raw

Re: [PATCH 1/2] Ethtool: Add EEE support

Quoted 14 lines · Yuval Mintz

This patch adds 2 new ethtool commands which can be used to manipulate network interfaces' support in EEE.

Output of 'get' has the following form:

EEE Settings for p2p1:
EEE status: enabled - active
Tx LPI: 1000 (u)
Supported EEE link modes: 10000baseT/Full Advertised EEE link modes: 10000baseT/Full Link partner advertised EEE link modes: 10000baseT/Full

Thanks goes to Giuseppe Cavallaro for his original patch.

[...]

ethtool.c static int do_version(struct cmd_context *ctx) · line 363

Quoted 11 lines
ethtool.c +2 -1
index f18f611..063e72b 100644
@@ -359,7 +359,8 @@ static int do_version(struct cmd_context *ctx)
 	return 0;
 }
 
-static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask);
+static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask,
+			    u8 all);

For now, use int for booleans. At some point I would like to see a thorough cleanup of ethtool to use bool where appropriate - but that's independent of this.

[...]

Quoted 13 lines
ethtool.c +0 -0
 /* Print link capability flags (supported, advertised or lp_advertised).
  * Assumes that the corresponding SUPPORTED and ADVERTISED flags are equal.
  */

static void

ethtool.c +1 -1
-dump_link_caps(const char *prefix, const char *an_prefix, u32 mask)
+dump_link_caps(const char *prefix, const char *an_prefix, u32 mask, u8 all)
 {
 	int indent;
 	int did1;
@@ -456,24 +457,26 @@ dump_link_caps(const char *prefix, const char *an_prefix, u32 mask)
 		 fprintf(stdout, "Not reported");
 	fprintf(stdout, "\n");
 

ethtool.c dump_link_caps(const char *prefix, const char *an_prefix, u32 mask) · line 460

Quoted 10 lines
ethtool.c +1 -9
-	fprintf(stdout, "	%s pause frame use: ", prefix);
-	if (mask & ADVERTISED_Pause) {
-		fprintf(stdout, "Symmetric");
-		if (mask & ADVERTISED_Asym_Pause)
-			fprintf(stdout, " Receive-only");
-		fprintf(stdout, "\n");
-	} else {
-		if (mask & ADVERTISED_Asym_Pause)
-			fprintf(stdout, "Transmit-only\n");
+	if (all) {

It might be clearer to invert this flag and name it something like 'link_mode_only'.

Quoted 28 lines
ethtool.c +16 -6
+		fprintf(stdout, "	%s pause frame use: ", prefix);
+		if (mask & ADVERTISED_Pause) {
+			fprintf(stdout, "Symmetric");
+			if (mask & ADVERTISED_Asym_Pause)
+				fprintf(stdout, " Receive-only");
+			fprintf(stdout, "\n");
+		} else {
+			if (mask & ADVERTISED_Asym_Pause)
+				fprintf(stdout, "Transmit-only\n");
+			else
+				fprintf(stdout, "No\n");
+		}
+
+		fprintf(stdout, "	%s auto-negotiation: ", an_prefix);
+		if (mask & ADVERTISED_Autoneg)
+			fprintf(stdout, "Yes\n");
 		else
 			fprintf(stdout, "No\n");
 	}
-
-	fprintf(stdout, "	%s auto-negotiation: ", an_prefix);
-	if (mask & ADVERTISED_Autoneg)
-		fprintf(stdout, "Yes\n");
-	else
-		fprintf(stdout, "No\n");
 }
 
 static int dump_ecmd(struct ethtool_cmd *ep)

[...]

ethtool.c static int dump_rxfhash(int fhash, u64 val) · line 1123

Quoted 5 lines
ethtool.c +1 -0
@@ -1116,6 +1120,36 @@ static int dump_rxfhash(int fhash, u64 val)
 	return 0;
 }
 
+static int dump_eeecmd(struct ethtool_eee *ep)

Is there any reason for this not to return void?

Quoted 9 lines
ethtool.c +9 -0
+{
+
+	fprintf(stdout, "	EEE status: ");
+	if (!ep->supported) {
+		fprintf(stdout, "not supported\n");
+		return 0;
+	} else if (!ep->eee_enabled) {
+		fprintf(stdout, "disabled\n");
+	} else {

ethtool.c static int dump_rxfhash(int fhash, u64 val) · line 1142

Quoted 10 lines
ethtool.c +10 -0
+		fprintf(stdout, "enabled - ");
+		if (ep->eee_active)
+			fprintf(stdout, "active\n");
+		else
+			fprintf(stdout, "inactive\n");
+	}
+
+	fprintf(stdout, "	Tx LPI:");
+	if (ep->tx_lpi_enabled)
+		fprintf(stdout, " %d (u)\n", ep->tx_lpi_timer);

"us" not "(u)"

Quoted 10 lines
ethtool.c +10 -0
+	else
+		fprintf(stdout, " disabled\n");
+
+	dump_link_caps("Supported EEE", "", ep->supported, 0);
+	dump_link_caps("Advertised EEE", "", ep->advertised, 0);
+	dump_link_caps("Link partner advertised EEE", "", ep->lp_advertised, 0);
+
+	return 0;
+}
+

[...]

Quoted 26 lines
ethtool.c +26 -0
+static int do_seee(struct cmd_context *ctx)
+{
+	int adv_c = -1, lpi_c = -1, lpi_time_c = -1, eee_c = -1;
+	int change = -1, change2 = -1;
+	struct ethtool_eee eeecmd;
+	struct cmdline_info cmdline_eee[] = {
+		{ "advertise",    CMDL_U32,  &adv_c,       &eeecmd.advertised },
+		{ "tx-lpi",       CMDL_BOOL, &lpi_c,   &eeecmd.tx_lpi_enabled },
+		{ "tx-timer",	  CMDL_U32,  &lpi_time_c, &eeecmd.tx_lpi_timer},
+		{ "eee",	  CMDL_BOOL, &eee_c,	   &eeecmd.eee_enabled},
+	};
+
+	if (ctx->argc == 0)
+		exit_bad_args();
+
+	parse_generic_cmdline(ctx, &change, cmdline_eee,
+			      ARRAY_SIZE(cmdline_eee));
+
+	eeecmd.cmd = ETHTOOL_GEEE;
+	if (send_ioctl(ctx, &eeecmd)) {
+		perror("Cannot get EEE settings");
+		return 1;
+	}
+
+	do_generic_set(cmdline_eee, ARRAY_SIZE(cmdline_eee), &change2);
+

ethtool.c static int do_getmodule(struct cmd_context *ctx) · line 3354

Quoted 10 lines
ethtool.c +10 -0
+	if (change2) {
+
+		eeecmd.cmd = ETHTOOL_SEEE;
+		if (send_ioctl(ctx, &eeecmd)) {
+			perror("Cannot set EEE settings");
+			return 1;
+		}
+	}
+
+	return 1;

return 0, I think!

Quoted 6 lines
ethtool.c +2 -0
+}
+
 int send_ioctl(struct cmd_context *ctx, void *cmd)
 {
 #ifndef TEST_ETHTOOL

ethtool.c static const struct option { · line 3524

Quoted 9 lines
ethtool.c +6 -0
@@ -3423,6 +3516,12 @@ static const struct option {
 	  "		[ hex on|off ]\n"
 	  "		[ offset N ]\n"
 	  "		[ length N ]\n" },
+	{ "--get-eee", 1, do_geee, "Get EEE settings"},
+	{ "--set-eee", 1, do_seee, "Set EEE settings",
+	  "		[ eee on|off ]\n"
+	  "		[ advertise %x ]\n"
+	  "		[ tx-lpi on|off ]\n"
+	  "		[ tx-timer %x ]\n"},

The tx-timer value would normally be specified in decimal, so put "%d" here.

ethtool.c static const struct option { · line 3527

Quoted 3 lines
ethtool.c +0 -0
 	{ "-h|--help", 0, show_usage, "Show this help" },
 	{ "--version", 0, do_version, "Show version number" },
 	{}

You also need to add some test cases for the command line parsing in test-cmdline.c.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#3 lore raw

RE: [PATCH 1/2] Ethtool: Add EEE support

Hi Ben,

I stand corrected; I'll supply a new version shortly.

I've got 2 questions though:

Quoted 3 lines

For now, use int for booleans. At some point I would like to see a thorough cleanup of ethtool to use bool where appropriate - but that's independent of this

I've noticed that the 'do_generic_set' function assumes all fields are ints. Is this a convention we should stick to (using __u32 in the ethtool structs)?

I'm asking because I'm "wasting" fields in the ethtool_eee struct as I use __u32 for boolean fields, simply because what seems to be the conventional method won't work with smaller fields (corrupts the following fields).

The seconds question - is there a dependency between your acceptance of this patch series and Dave's acceptance of the kernel's ethtool modification? I'm asking because changes in the ethtool header there should be applied in this patch series as well (in ethtool-copy.h).

Thanks,
Yuval

#4 lore raw

RE: [PATCH 1/2] Ethtool: Add EEE support

Quoted 11 lines · Yuval Mintz

Hi Ben,

I stand corrected; I'll supply a new version shortly.

I've got 2 questions though:

Quoted 3 lines

For now, use int for booleans. At some point I would like to see a thorough cleanup of ethtool to use bool where appropriate - but that's independent of this

I've noticed that the 'do_generic_set' function assumes all fields are ints.

Yes, but that can and should be fixed.

Quoted 1 line

Is this a convention we should stick to (using __u32 in the ethtool structs)?

Yes. It is generally preferable to use explicitly fixed-size types in kernel-userland ABI, even though I wouldn't expect the size of int to change for many decades to come.

Quoted 3 lines

I'm asking because I'm "wasting" fields in the ethtool_eee struct as I use __u32 for boolean fields, simply because what seems to be the conventional method won't work with smaller fields (corrupts the following fields).

It's slightly wasteful but not worth worrying about.

Quoted 4 lines

The seconds question - is there a dependency between your acceptance of this patch series and Dave's acceptance of the kernel's ethtool modification? I'm asking because changes in the ethtool header there should be applied in this patch series as well (in ethtool-copy.h).

There is a dependency, yes. However I generally update ethtool-copy.h as a separate commit myself (as you can see in the git commit log for it) so I won't demand that you refresh the version in your patch.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#5 lore raw

PATCH 2/2 Ethtool: add EEE to ethtool's documentation

In reply to Yuval Mintz

under Synopsis:

	ethtool --get-eee devname
	ethtool --set-eee devname [eee on|off] [tx-lpi on|off] [tx-timer N] [advertise N]

under Options:
--get-eee
Queries the specified network device for its support in Efficient Energy Ethernet (ac- cording to the IEEE 802.3az specifications)
--set-eee
Sets the device EEE behaviour.
eee on|off
Enables/Disables the device support in EEE.
tx-lpi on|off
Determines whether the device should assert its tx lpi.
advertise N
Sets the speeds for which the device would advertise EEE capabliities. Values are as
for --change advertise
tx-timer N
Sets the amount of time the device should stay in idle mode prior to asserting its tx lpi (in microseconds). This has meaning only when tx lpi is on.

---
 ethtool.8.in |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
ethtool.8.in +32 -0
index 523b737..b906d8e 100644
@@ -335,6 +335,16 @@ ethtool \- query or control network driver and hardware settings
 .I devname flag
 .A1 on off
 .RB ...
+.HP
+.B ethtool \-\-get\-eee
+.I devname
+.HP
+.B ethtool \-\-set\-eee
+.I devname
+.B2 eee on off
+.B2 tx-lpi on off
+.BN tx-timer
+.BN advertise
 .
 .\" Adjust lines (i.e. full justification) and hyphenate.
 .ad
@@ -817,6 +827,28 @@ Sets the device's private flags as specified.
 .I flag
 .A1 on off
 Sets the state of the named private flag.
+.TP
+.B \-\-get\-eee
+Queries the specified network device for its support in Efficient Energy
+Ethernet (according to the IEEE 802.3az specifications)
+.TP
+.B \-\-set\-eee
+Sets the device EEE behaviour.
+.TP
+.A2 eee on off
+Enables/Disables the device support in EEE.
+.TP
+.A2 tx-lpi on off
+Determines whether the device should assert its tx lpi.
+.TP
+.BI advertise \ N
+Sets the speeds for which the device would advertise EEE capabliities.
+Values are as for
+.B \-\-change advertise
+.TP
+.BI tx-timer \ N
+Sets the amount of time the device should stay in idle mode prior to asserting
+its tx lpi (in microseconds). This has meaning only when tx lpi is on.
 .SH BUGS
 Not supported (in part or whole) on all network drivers.
 .SH AUTHOR
Signature · 1 line
1.7.9.rc2
#6 lore raw

Re: [PATCH 2/2] Ethtool: add EEE to ethtool's documentation

Quoted 4 lines · Yuval Mintz

under Synopsis:

	ethtool --get-eee devname
	ethtool --set-eee devname [eee on|off] [tx-lpi on|off] [tx-timer N] [advertise N]
Quoted 16 lines

under Options:
--get-eee
Queries the specified network device for its support in Efficient Energy Ethernet (ac- cording to the IEEE 802.3az specifications)
--set-eee
Sets the device EEE behaviour.
eee on|off
Enables/Disables the device support in EEE.
tx-lpi on|off
Determines whether the device should assert its tx lpi.
advertise N
Sets the speeds for which the device would advertise EEE capabliities. Values are as
for --change advertise
tx-timer N
Sets the amount of time the device should stay in idle mode prior to asserting its tx lpi (in microseconds). This has meaning only when tx lpi is on.

Please just fold this change into the patch that adds the options. Also there is no need to repeat the content in the commit message.

Quoted 28 lines
---
 ethtool.8.in |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
ethtool.8.in +10 -0
index 523b737..b906d8e 100644
@@ -335,6 +335,16 @@ ethtool \- query or control network driver and hardware settings
 .I devname flag
 .A1 on off
 .RB ...
+.HP
+.B ethtool \-\-get\-eee
+.I devname
+.HP
+.B ethtool \-\-set\-eee
+.I devname
+.B2 eee on off
+.B2 tx-lpi on off
+.BN tx-timer
+.BN advertise
 .
 .\" Adjust lines (i.e. full justification) and hyphenate.
 .ad

ethtool.8.in Sets the device's private flags as specified. · line 833

Quoted 7 lines
ethtool.8.in +4 -0
@@ -817,6 +827,28 @@ Sets the device's private flags as specified.
 .I flag
 .A1 on off
 Sets the state of the named private flag.
+.TP
+.B \-\-get\-eee
+Queries the specified network device for its support in Efficient Energy
+Ethernet (according to the IEEE 802.3az specifications)

'of', not 'in'

ethtool.8.in Sets the device's private flags as specified. · line 839

Quoted 6 lines
ethtool.8.in +6 -0
+.TP
+.B \-\-set\-eee
+Sets the device EEE behaviour.
+.TP
+.A2 eee on off
+Enables/Disables the device support in EEE.

Lower-case 'd' for 'disables'.
'of', not 'in'

ethtool.8.in Sets the device's private flags as specified. · line 842

Quoted 3 lines
ethtool.8.in +3 -0
+.TP
+.A2 tx-lpi on off
+Determines whether the device should assert its tx lpi.

'TX LPI' should be in upper-case.

ethtool.8.in Sets the device's private flags as specified. · line 845

Quoted 3 lines
ethtool.8.in +3 -0
+.TP
+.BI advertise \ N
+Sets the speeds for which the device would advertise EEE capabliities.

'would', not 'should'
'capabilities', not 'capabliities'

ethtool.8.in Sets the device's private flags as specified. · line 851

Quoted 6 lines
ethtool.8.in +6 -0
+Values are as for
+.B \-\-change advertise
+.TP
+.BI tx-timer \ N
+Sets the amount of time the device should stay in idle mode prior to asserting
+its tx lpi (in microseconds). This has meaning only when tx lpi is on.

Same here.

Ben.

Quoted 3 lines
ethtool.8.in +0 -0
 .SH BUGS
 Not supported (in part or whole) on all network drivers.
 .SH AUTHOR
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.