From 015750d807d3c5ed7a9df9ebf881ce7da137c095 Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Tue, 20 Sep 2022 10:07:39 +0200
Subject: [PATCH 5/6] ethtool: add tx-shaper-config

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

diff --git a/ethtool.c b/ethtool.c
index 0cce671..b7fe84f 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5300,6 +5300,47 @@ static int do_set_mac_mode(struct cmd_context *ctx)
 	return 0;
 }
 
+static int do_set_shaper_params(struct cmd_context *ctx)
+{
+	struct ethtool_shaper_params p;
+	int rv;
+
+	memset(&p, 0, sizeof (p));
+	p.cmd = ETHTOOL_SSHAPER_PARAMS;
+	p.rate = get_u32(ctx->argp[0], 10) * 1000000LL;
+	p.burst = get_u32(ctx->argp[1], 10);
+	p.mtu = get_u32(ctx->argp[2], 10);
+
+	rv = send_ioctl(ctx, &p);
+	if (rv != 0) {
+		perror("Cannot set TX shaper params");
+		return rv;
+	}
+
+	return 0;
+}
+
+static int do_get_shaper_params(struct cmd_context *ctx)
+{
+	struct ethtool_shaper_params p;
+	int rv;
+
+	memset(&p, 0, sizeof (p));
+	p.cmd = ETHTOOL_GSHAPER_PARAMS;
+
+	rv = send_ioctl(ctx, &p);
+	if (rv) {
+		perror("Cannot get TX shaper params");
+		return rv;
+	}
+
+	printf("TX shaper params:\n");
+	printf(" rate:  %u Mbits/s\n", p.rate / 1000000);
+	printf(" burst: %u bits\n", p.burst);
+	printf(" mtu:   %u bits\n", p.mtu);
+	return 0;
+}
+
 static int do_perqueue(struct cmd_context *ctx);
 
 #ifndef TEST_ETHTOOL
@@ -5501,6 +5542,8 @@ static const struct option {
 	  "		[ 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"},
+	{ "--set-tx-shaper-param", 1, do_set_shaper_params, "Set HW TX shaper params" },
+	{ "--get-tx-shaper-param", 1, do_get_shaper_params, "Get HW TX shaper params" },
 	{ "-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

