From 77281e5005b2224867094146091a9eef626f6cd2 Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Sat, 7 Dec 2019 13:49:28 +0100
Subject: [PATCH 4/4] ethtool: add set-mac-mode helper

---
 ethtool.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/ethtool.c b/ethtool.c
index 589c7e2..14ac83f 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5267,6 +5267,35 @@ static int do_sfec(struct cmd_context *ctx)
 	return 0;
 }
 
+static int do_set_mac_mode(struct cmd_context *ctx)
+{
+	struct {
+		struct ethtool_tunable tcmd;
+		uint32_t data;
+	} t;
+	int mac_mode, rv;
+
+	if (ctx->argc != 1)
+		exit_bad_args();
+
+	mac_mode = get_u32(ctx->argp[0], 10);
+
+	memset(&t, 0, sizeof(t));
+	t.tcmd.cmd = ETHTOOL_STUNABLE;
+	t.tcmd.id = ETHTOOL_MAC_MODE;
+	t.tcmd.type_id = ETHTOOL_TUNABLE_U32;
+	t.tcmd.len = sizeof (uint32_t);
+	t.data = mac_mode;
+
+	rv = send_ioctl(ctx, &t);
+	if (rv != 0) {
+		perror("Cannot set mac mode");
+		return rv;
+	}
+
+	return 0;
+}
+
 static int do_perqueue(struct cmd_context *ctx);
 
 #ifndef TEST_ETHTOOL
@@ -5467,6 +5496,7 @@ static const struct option {
 	{ "--set-fec", 1, do_sfec, "Set FEC settings",
 	  "		[ encoding auto|off|rs|baser [...]]\n"},
 	{ "--show-epon-param", 1, do_show_epon_param, "Show EPON params"},
+	{ "--set-mac-mode", 1, do_set_mac_mode, "Change MAC mode"},
 	{ "-Q|--per-queue", 1, do_perqueue, "Apply per-queue command."
 	  "The supported sub commands include --show-coalesce, --coalesce",
 	  "             [queue_mask %x] SUB_COMMAND\n"},
-- 
2.17.1

