netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Add support for PHY packet generator to ethtool(1)
@ 2016-02-17 20:37 Andrew Lunn
  2016-02-17 20:37 ` [PATCH 1/2] ethtool-copy.h: sync with net Andrew Lunn
  2016-02-17 20:37 ` [PATCH 2/2] ethtool: Add --phy_pkt_gen command Andrew Lunn
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Lunn @ 2016-02-17 20:37 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: Florian Fainelli, netdev, Andrew Lunn

Import the latests ethtool.h and add an option to make use of the
PHY packet generators. 

Andrew Lunn (2):
  ethtool-copy.h: sync with net
  ethtool: Add --phy_pkt_gen command

 ethtool-copy.h | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 ethtool.8.in   |  30 +++++++++++++++
 ethtool.c      |  44 +++++++++++++++++++++
 internal.h     |   3 ++
 4 files changed, 187 insertions(+), 9 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] ethtool-copy.h: sync with net
  2016-02-17 20:37 [PATCH 0/2] Add support for PHY packet generator to ethtool(1) Andrew Lunn
@ 2016-02-17 20:37 ` Andrew Lunn
  2016-02-17 20:37 ` [PATCH 2/2] ethtool: Add --phy_pkt_gen command Andrew Lunn
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2016-02-17 20:37 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: Florian Fainelli, netdev, Andrew Lunn

Additional, add MAX_INT to internal.h, which is now required by
ethtool-copy.h.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 ethtool-copy.h | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 internal.h     |   3 ++
 2 files changed, 113 insertions(+), 9 deletions(-)

diff --git a/ethtool-copy.h b/ethtool-copy.h
index 57fa390..bce6c95 100644
--- a/ethtool-copy.h
+++ b/ethtool-copy.h
@@ -31,7 +31,7 @@
  *	physical connectors and other link features that are
  *	advertised through autonegotiation or enabled for
  *	auto-detection.
- * @speed: Low bits of the speed
+ * @speed: Low bits of the speed, 1Mb units, 0 to INT_MAX or SPEED_UNKNOWN
  * @duplex: Duplex mode; one of %DUPLEX_*
  * @port: Physical connector type; one of %PORT_*
  * @phy_address: MDIO address of PHY (transceiver); 0 or 255 if not
@@ -47,7 +47,7 @@
  *	obsoleted by &struct ethtool_coalesce.  Read-only; deprecated.
  * @maxrxpkt: Historically used to report RX IRQ coalescing; now
  *	obsoleted by &struct ethtool_coalesce.  Read-only; deprecated.
- * @speed_hi: High bits of the speed
+ * @speed_hi: High bits of the speed, 1Mb units, 0 to INT_MAX or SPEED_UNKNOWN
  * @eth_tp_mdix: Ethernet twisted-pair MDI(-X) status; one of
  *	%ETH_TP_MDI_*.  If the status is unknown or not applicable, the
  *	value will be %ETH_TP_MDI_INVALID.  Read-only.
@@ -748,6 +748,56 @@ struct ethtool_usrip4_spec {
 	__u8    proto;
 };
 
+/**
+ * struct ethtool_tcpip6_spec - flow specification for TCP/IPv6 etc.
+ * @ip6src: Source host
+ * @ip6dst: Destination host
+ * @psrc: Source port
+ * @pdst: Destination port
+ * @tclass: Traffic Class
+ *
+ * This can be used to specify a TCP/IPv6, UDP/IPv6 or SCTP/IPv6 flow.
+ */
+struct ethtool_tcpip6_spec {
+	__be32	ip6src[4];
+	__be32	ip6dst[4];
+	__be16	psrc;
+	__be16	pdst;
+	__u8    tclass;
+};
+
+/**
+ * struct ethtool_ah_espip6_spec - flow specification for IPsec/IPv6
+ * @ip6src: Source host
+ * @ip6dst: Destination host
+ * @spi: Security parameters index
+ * @tclass: Traffic Class
+ *
+ * This can be used to specify an IPsec transport or tunnel over IPv6.
+ */
+struct ethtool_ah_espip6_spec {
+	__be32	ip6src[4];
+	__be32	ip6dst[4];
+	__be32	spi;
+	__u8    tclass;
+};
+
+/**
+ * struct ethtool_usrip6_spec - general flow specification for IPv6
+ * @ip6src: Source host
+ * @ip6dst: Destination host
+ * @l4_4_bytes: First 4 bytes of transport (layer 4) header
+ * @tclass: Traffic Class
+ * @l4_proto: Transport protocol number (nexthdr after any Extension Headers)
+ */
+struct ethtool_usrip6_spec {
+	__be32	ip6src[4];
+	__be32	ip6dst[4];
+	__be32	l4_4_bytes;
+	__u8    tclass;
+	__u8    l4_proto;
+};
+
 union ethtool_flow_union {
 	struct ethtool_tcpip4_spec		tcp_ip4_spec;
 	struct ethtool_tcpip4_spec		udp_ip4_spec;
@@ -755,6 +805,12 @@ union ethtool_flow_union {
 	struct ethtool_ah_espip4_spec		ah_ip4_spec;
 	struct ethtool_ah_espip4_spec		esp_ip4_spec;
 	struct ethtool_usrip4_spec		usr_ip4_spec;
+	struct ethtool_tcpip6_spec		tcp_ip6_spec;
+	struct ethtool_tcpip6_spec		udp_ip6_spec;
+	struct ethtool_tcpip6_spec		sctp_ip6_spec;
+	struct ethtool_ah_espip6_spec		ah_ip6_spec;
+	struct ethtool_ah_espip6_spec		esp_ip6_spec;
+	struct ethtool_usrip6_spec		usr_ip6_spec;
 	struct ethhdr				ether_spec;
 	__u8					hdata[52];
 };
@@ -1111,6 +1167,31 @@ struct ethtool_ts_info {
 	__u32	rx_reserved[3];
 };
 
+enum ethtool_phy_pkg_gen_flags {
+	ETH_PKT_RANDOM	= (1 << 0),
+	ETH_PKT_ERROR	= (1 << 1),
+};
+
+/**
+ * struct ethtool_phy_pkt_get - command to request the phy to generate packets.
+ * @cmd: command number = %ETHTOOL_PHY_PKT_GEN
+ * @count: number of packets to generate
+ * @len: length of generated packets
+ * @ipg: inter packet gap in bytes.
+ * @flags: a bitmask of flags from &enum ethtool_phy_pkg_gen_flags
+ *
+ * PHY drivers may not support all of these parameters. If the
+ * requested parameter value cannot be supported an error should be
+ * returned.
+ */
+struct ethtool_phy_pkt_gen {
+	__u32	cmd;
+	__u32	count;
+	__u32	len;
+	__u32	ipg;
+	__u32	flags;
+};
+
 /*
  * %ETHTOOL_SFEATURES changes features present in features[].valid to the
  * values of corresponding bits in features[].requested. Bits in .requested
@@ -1228,6 +1309,7 @@ enum ethtool_sfeatures_retval_bits {
 #define ETHTOOL_GTUNABLE	0x00000048 /* Get tunable configuration */
 #define ETHTOOL_STUNABLE	0x00000049 /* Set tunable configuration */
 #define ETHTOOL_GPHYSTATS	0x0000004a /* get PHY-specific statistics */
+#define ETHTOOL_PHY_PKT_GEN	0x0000004b /* Gnerate packets in the PHY */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET
@@ -1303,7 +1385,7 @@ enum ethtool_sfeatures_retval_bits {
  * it was forced up into this mode or autonegotiated.
  */
 
-/* The forced speed, 10Mb, 100Mb, gigabit, [2.5|5|10|20|25|40|50|56|100]GbE. */
+/* The forced speed, in units of 1Mb. All values 0 to INT_MAX are legal. */
 #define SPEED_10		10
 #define SPEED_100		100
 #define SPEED_1000		1000
@@ -1319,11 +1401,28 @@ enum ethtool_sfeatures_retval_bits {
 
 #define SPEED_UNKNOWN		-1
 
+static inline int ethtool_validate_speed(__u32 speed)
+{
+	return speed <= INT_MAX || speed == SPEED_UNKNOWN;
+}
+
 /* Duplex, half or full. */
 #define DUPLEX_HALF		0x00
 #define DUPLEX_FULL		0x01
 #define DUPLEX_UNKNOWN		0xff
 
+static inline int ethtool_validate_duplex(__u8 duplex)
+{
+	switch (duplex) {
+	case DUPLEX_HALF:
+	case DUPLEX_FULL:
+	case DUPLEX_UNKNOWN:
+		return 1;
+	}
+
+	return 0;
+}
+
 /* Which connector port. */
 #define PORT_TP			0x00
 #define PORT_AUI		0x01
@@ -1367,15 +1466,17 @@ enum ethtool_sfeatures_retval_bits {
 #define	UDP_V4_FLOW	0x02	/* hash or spec (udp_ip4_spec) */
 #define	SCTP_V4_FLOW	0x03	/* hash or spec (sctp_ip4_spec) */
 #define	AH_ESP_V4_FLOW	0x04	/* hash only */
-#define	TCP_V6_FLOW	0x05	/* hash only */
-#define	UDP_V6_FLOW	0x06	/* hash only */
-#define	SCTP_V6_FLOW	0x07	/* hash only */
+#define	TCP_V6_FLOW	0x05	/* hash or spec (tcp_ip6_spec; nfc only) */
+#define	UDP_V6_FLOW	0x06	/* hash or spec (udp_ip6_spec; nfc only) */
+#define	SCTP_V6_FLOW	0x07	/* hash or spec (sctp_ip6_spec; nfc only) */
 #define	AH_ESP_V6_FLOW	0x08	/* hash only */
 #define	AH_V4_FLOW	0x09	/* hash or spec (ah_ip4_spec) */
 #define	ESP_V4_FLOW	0x0a	/* hash or spec (esp_ip4_spec) */
-#define	AH_V6_FLOW	0x0b	/* hash only */
-#define	ESP_V6_FLOW	0x0c	/* hash only */
-#define	IP_USER_FLOW	0x0d	/* spec only (usr_ip4_spec) */
+#define	AH_V6_FLOW	0x0b	/* hash or spec (ah_ip6_spec; nfc only) */
+#define	ESP_V6_FLOW	0x0c	/* hash or spec (esp_ip6_spec; nfc only) */
+#define	IPV4_USER_FLOW	0x0d	/* spec only (usr_ip4_spec) */
+#define	IP_USER_FLOW	IPV4_USER_FLOW
+#define	IPV6_USER_FLOW	0x0e	/* spec only (usr_ip6_spec; nfc only) */
 #define	IPV4_FLOW	0x10	/* hash only */
 #define	IPV6_FLOW	0x11	/* hash only */
 #define	ETHER_FLOW	0x12	/* spec only (ether_spec) */
diff --git a/internal.h b/internal.h
index b5ef646..ce137fe 100644
--- a/internal.h
+++ b/internal.h
@@ -29,6 +29,9 @@ typedef uint16_t u16;
 typedef uint8_t u8;
 typedef int32_t s32;
 
+/* and from <linux/kernel.h> */
+#define INT_MAX ((int)(~0U>>1))
+
 #include "ethtool-copy.h"
 #include "net_tstamp-copy.h"
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] ethtool: Add --phy_pkt_gen command
  2016-02-17 20:37 [PATCH 0/2] Add support for PHY packet generator to ethtool(1) Andrew Lunn
  2016-02-17 20:37 ` [PATCH 1/2] ethtool-copy.h: sync with net Andrew Lunn
@ 2016-02-17 20:37 ` Andrew Lunn
  2016-02-17 21:08   ` Ben Hutchings
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2016-02-17 20:37 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: Florian Fainelli, netdev, Andrew Lunn

This command is used to cause the PHY to generate packets. The count
of packets must always be given. Optionally, the length of the packet,
if the packet should contain random or fixed data, if errored packets should
be sent and the inter packet gap can be configured. However not all PHYs
are expected to support all options.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 ethtool.8.in | 30 ++++++++++++++++++++++++++++++
 ethtool.c    | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/ethtool.8.in b/ethtool.8.in
index 2316556..ec5ca80 100644
--- a/ethtool.8.in
+++ b/ethtool.8.in
@@ -339,6 +339,14 @@ ethtool \- query or control network driver and hardware settings
 .B2 tx-lpi on off
 .BN tx-timer
 .BN advertise
+.HP
+.B ethtool \-\-phy\-pkt\-gen
+.I devname
+.I count
+.B2 random on off
+.BN len
+.B2 error off on
+.BN ipg
 .
 .\" Adjust lines (i.e. full justification) and hyphenate.
 .ad
@@ -885,6 +893,28 @@ Values are as for
 .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 enabled.
+.TP
+.B \-\-phy\-pkt\-get\-eee
+Cause the PHY to generate packets using its in built packet
+generator. PHYs may not support all options and may differ on
+supported packet size, packet contents, etc.
+.TP
+.I count
+Number of packets to send. Typically this can be between 1 and 255.
+.TP
+.A2 random on off
+Send packets with random contents, or fixed. Fixed content packets
+often contain 0x5a,0xa5,0x5a,0xa5,... but may have different contents.
+.TP
+.BI len \ N
+Length of the packet to send, typically 64 or 1518 bytes, but other
+lengths may be supported.
+.TP
+.A2 error off on
+Generate packets with errors.
+.TP
+.BI ipg \ N
+Set the inter packet gap length, in bytes.
 .SH BUGS
 Not supported (in part or whole) on all network drivers.
 .SH AUTHOR
diff --git a/ethtool.c b/ethtool.c
index 480c14c..448395f 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4046,6 +4046,44 @@ static int do_seee(struct cmd_context *ctx)
 	return 0;
 }
 
+static int do_phy_pkt_gen(struct cmd_context *ctx)
+{
+	struct ethtool_phy_pkt_gen cmd;
+	int random, error, changed;
+	struct cmdline_info cmdline_phy_pkt_gen[] = {
+		{ "random",	CMDL_BOOL,	&random,	NULL },
+		{ "len",	CMDL_U32,	&cmd.len,	NULL },
+		{ "error",	CMDL_BOOL,	&error,		NULL },
+		{ "ipg",	CMDL_U32,	&cmd.ipg,	NULL },
+	};
+
+	if (ctx->argc < 1)
+		exit_bad_args();
+
+	memset(&cmd, 0, sizeof(cmd));
+
+	cmd.count = get_uint_range(ctx->argp[0], 0, 0xffffffff);
+	ctx->argc--;
+	ctx->argp++;
+
+	parse_generic_cmdline(ctx, &changed, cmdline_phy_pkt_gen,
+			      ARRAY_SIZE(cmdline_phy_pkt_gen));
+
+	cmd.cmd = ETHTOOL_PHY_PKT_GEN;
+	cmd.flags = 0;
+	if (error)
+		cmd.flags |= ETH_PKT_ERROR;
+	if (random)
+		cmd.flags |= ETH_PKT_RANDOM;
+
+	if (send_ioctl(ctx, &cmd)) {
+		perror("Cannot perform PHY packet generation");
+		return 1;
+	}
+
+	return 0;
+}
+
 #ifndef TEST_ETHTOOL
 int send_ioctl(struct cmd_context *ctx, void *cmd)
 {
@@ -4205,6 +4243,12 @@ static const struct option {
 	  "		[ advertise %x ]\n"
 	  "		[ tx-lpi on|off ]\n"
 	  "		[ tx-timer %d ]\n"},
+	{ "--phy-pkt-gen", 1, do_phy_pkt_gen, "PHY packet generation",
+	  "		count\n"
+	  "		[ random on|off ]\n"
+	  "		[ len N ]\n"
+	  "		[ error off|on ]\n"
+	  "		[ ipg N ]\n" },
 	{ "-h|--help", 0, show_usage, "Show this help" },
 	{ "--version", 0, do_version, "Show version number" },
 	{}
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] ethtool: Add --phy_pkt_gen command
  2016-02-17 20:37 ` [PATCH 2/2] ethtool: Add --phy_pkt_gen command Andrew Lunn
@ 2016-02-17 21:08   ` Ben Hutchings
  0 siblings, 0 replies; 4+ messages in thread
From: Ben Hutchings @ 2016-02-17 21:08 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: Florian Fainelli, netdev

[-- Attachment #1: Type: text/plain, Size: 220 bytes --]

This needs some test cases for the command-line parsing.  Also:

[...]
> --- a/ethtool.8.in
> +++ b/ethtool.8.in
[...]
> +.TP
> +.B \-\-phy\-pkt\-get\-eee
[...]

...is not the name of the new option.

Ben.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-02-17 21:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-17 20:37 [PATCH 0/2] Add support for PHY packet generator to ethtool(1) Andrew Lunn
2016-02-17 20:37 ` [PATCH 1/2] ethtool-copy.h: sync with net Andrew Lunn
2016-02-17 20:37 ` [PATCH 2/2] ethtool: Add --phy_pkt_gen command Andrew Lunn
2016-02-17 21:08   ` Ben Hutchings

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).