diff mbox series

[ethtool] ethtool: Support ntuple rule count change

Message ID 1623847380-16590-1-git-send-email-sgoutham@marvell.com
State New
Headers show
Series [ethtool] ethtool: Support ntuple rule count change | expand

Commit Message

Sunil Kovvuri Goutham June 16, 2021, 12:43 p.m. UTC
From: Sunil Goutham <sgoutham@marvell.com>

Some NICs share resources like packet filters across multiple
interfaces they support, between SRIOV PF and VFs and/or between
multiple PFs. From HW point of view it is allowed to use all
MCAM filters for a single interface. Currently ethtool doesn't
support modifying filter count so that user can allocate more filters
to one interface and less to others. This patch adds ETHTOOL_SRXCLSRLCNT
ioctl command for modifying filter count.

example command:
./ethtool -U eth0 rule-count 256

Signed-off-by: Sunil Goutham <sgoutham@marvell.com>
---
 ethtool.c            | 11 +++++++++++
 internal.h           |  1 +
 rxclass.c            | 15 +++++++++++++++
 uapi/linux/ethtool.h |  1 +
 4 files changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/ethtool.c b/ethtool.c
index 8ed5a33..d4d0dab 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -3797,6 +3797,16 @@  static int do_srxclass(struct cmd_context *ctx)
 				" classification rule\n");
 			return 1;
 		}
+	} else if (!strcmp(ctx->argp[0], "rule-count")) {
+		int count = get_uint_range(ctx->argp[1], 0, INT_MAX);
+
+		err = rxclass_set_rule_count(ctx, count);
+
+		if (err < 0) {
+			fprintf(stderr, "Couldn't set"
+				" the desired ntuple rule count\n");
+			return 1;
+		}
 	} else {
 		exit_bad_args();
 	}
@@ -5818,6 +5828,7 @@  static const struct option args[] = {
 			  "			[ context %d ]\n"
 			  "			[ loc %d]] |\n"
 			  "		delete %d\n"
+			  "		rule-count %d\n"
 	},
 	{
 		.opts	= "-T|--show-time-stamping",
diff --git a/internal.h b/internal.h
index 27da8ea..ce76394 100644
--- a/internal.h
+++ b/internal.h
@@ -372,6 +372,7 @@  int rxclass_rule_get(struct cmd_context *ctx, __u32 loc);
 int rxclass_rule_ins(struct cmd_context *ctx,
 		     struct ethtool_rx_flow_spec *fsp, __u32 rss_context);
 int rxclass_rule_del(struct cmd_context *ctx, __u32 loc);
+int rxclass_set_rule_count(struct cmd_context *ctx, __u32 count);
 
 /* Module EEPROM parsing code */
 void sff8079_show_all(const __u8 *id);
diff --git a/rxclass.c b/rxclass.c
index 6cf81fd..9d29dde 100644
--- a/rxclass.c
+++ b/rxclass.c
@@ -616,6 +616,21 @@  int rxclass_rule_del(struct cmd_context *ctx, __u32 loc)
 	return err;
 }
 
+int rxclass_set_rule_count(struct cmd_context *ctx, __u32 count)
+{
+	struct ethtool_rxnfc nfccmd;
+	int err;
+
+	/* notify netdev of rule count config */
+	nfccmd.cmd = ETHTOOL_SRXCLSRLCNT;
+	nfccmd.rule_cnt = count;
+	err = send_ioctl(ctx, &nfccmd);
+	if (err < 0)
+		perror("rmgr: Cannot set RX class rule count");
+
+	return err;
+}
+
 typedef enum {
 	OPT_NONE = 0,
 	OPT_S32,
diff --git a/uapi/linux/ethtool.h b/uapi/linux/ethtool.h
index c6ec111..a43074a 100644
--- a/uapi/linux/ethtool.h
+++ b/uapi/linux/ethtool.h
@@ -1550,6 +1550,7 @@  enum ethtool_fec_config_bits {
 #define ETHTOOL_PHY_STUNABLE	0x0000004f /* Set PHY tunable configuration */
 #define ETHTOOL_GFECPARAM	0x00000050 /* Get FEC settings */
 #define ETHTOOL_SFECPARAM	0x00000051 /* Set FEC settings */
+#define ETHTOOL_SRXCLSRLCNT	0x00000052 /* Set RX class rule count */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET