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

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

diff --git a/ethtool.c b/ethtool.c
index c8b8a41..a714b16 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5271,6 +5271,47 @@ static int do_sfec(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
@@ -5471,6 +5512,8 @@ 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-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.34.1

