b96ca7
From 10b4bae4d7f2fa4768fbe90cbfa18ed6059e5a5b Mon Sep 17 00:00:00 2001
b96ca7
From: Edward Cree <ecree@solarflare.com>
b96ca7
Date: Fri, 9 Mar 2018 15:04:12 +0000
b96ca7
Subject: [PATCH 16/18] ethtool: add support for extra RSS contexts and RSS
b96ca7
 steering filters
b96ca7
b96ca7
RSS contexts can be created on a device with -X ... context new, modified
b96ca7
 with -X ... context N, and deleted with -X ... context N delete.
b96ca7
N-tuple filters can be directed at those contexts with -N ... context N.
b96ca7
b96ca7
Signed-off-by: Edward Cree <ecree@solarflare.com>
b96ca7
Signed-off-by: John W. Linville <linville@tuxdriver.com>
b96ca7
(cherry picked from commit f5d55b967e0c5757e423805a70d1a298e307e91e)
b96ca7
---
b96ca7
 ethtool.c  | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------
b96ca7
 internal.h |   4 +-
b96ca7
 rxclass.c  |  58 +++++++++++++++++++++----
b96ca7
 3 files changed, 173 insertions(+), 30 deletions(-)
b96ca7
b96ca7
diff --git a/ethtool.c b/ethtool.c
b96ca7
index 2e9ee2c..a276fdb 100644
b96ca7
--- a/ethtool.c
b96ca7
+++ b/ethtool.c
b96ca7
@@ -1513,7 +1513,7 @@ static void dump_features(const struct feature_defs *defs,
b96ca7
 
b96ca7
 static int dump_rxfhash(int fhash, u64 val)
b96ca7
 {
b96ca7
-	switch (fhash) {
b96ca7
+	switch (fhash & ~FLOW_RSS) {
b96ca7
 	case TCP_V4_FLOW:
b96ca7
 		fprintf(stdout, "TCP over IPV4 flows");
b96ca7
 		break;
b96ca7
@@ -3527,11 +3527,20 @@ static int do_srxclass(struct cmd_context *ctx)
b96ca7
 	if (ctx->argc < 2)
b96ca7
 		exit_bad_args();
b96ca7
 
b96ca7
-	if (ctx->argc == 3 && !strcmp(ctx->argp[0], "rx-flow-hash")) {
b96ca7
+	if (!strcmp(ctx->argp[0], "rx-flow-hash")) {
b96ca7
 		int rx_fhash_set;
b96ca7
 		u32 rx_fhash_val;
b96ca7
 		struct ethtool_rxnfc nfccmd;
b96ca7
+		bool flow_rss = false;
b96ca7
 
b96ca7
+		if (ctx->argc == 5) {
b96ca7
+			if (strcmp(ctx->argp[3], "context"))
b96ca7
+				exit_bad_args();
b96ca7
+			flow_rss = true;
b96ca7
+			nfccmd.rss_context = get_u32(ctx->argp[4], 0);
b96ca7
+		} else if (ctx->argc != 3) {
b96ca7
+			exit_bad_args();
b96ca7
+		}
b96ca7
 		rx_fhash_set = rxflow_str_to_type(ctx->argp[1]);
b96ca7
 		if (!rx_fhash_set)
b96ca7
 			exit_bad_args();
b96ca7
@@ -3541,16 +3550,19 @@ static int do_srxclass(struct cmd_context *ctx)
b96ca7
 		nfccmd.cmd = ETHTOOL_SRXFH;
b96ca7
 		nfccmd.flow_type = rx_fhash_set;
b96ca7
 		nfccmd.data = rx_fhash_val;
b96ca7
+		if (flow_rss)
b96ca7
+			nfccmd.flow_type |= FLOW_RSS;
b96ca7
 
b96ca7
 		err = send_ioctl(ctx, &nfccmd);
b96ca7
 		if (err < 0)
b96ca7
 			perror("Cannot change RX network flow hashing options");
b96ca7
 	} else if (!strcmp(ctx->argp[0], "flow-type")) {	
b96ca7
 		struct ethtool_rx_flow_spec rx_rule_fs;
b96ca7
+		__u32 rss_context = 0;
b96ca7
 
b96ca7
 		ctx->argc--;
b96ca7
 		ctx->argp++;
b96ca7
-		if (rxclass_parse_ruleopts(ctx, &rx_rule_fs) < 0)
b96ca7
+		if (rxclass_parse_ruleopts(ctx, &rx_rule_fs, &rss_context) < 0)
b96ca7
 			exit_bad_args();
b96ca7
 
b96ca7
 		/* attempt to add rule via N-tuple specifier */
b96ca7
@@ -3559,7 +3571,7 @@ static int do_srxclass(struct cmd_context *ctx)
b96ca7
 			return 0;
b96ca7
 
b96ca7
 		/* attempt to add rule via network flow classifier */
b96ca7
-		err = rxclass_rule_ins(ctx, &rx_rule_fs);
b96ca7
+		err = rxclass_rule_ins(ctx, &rx_rule_fs, rss_context);
b96ca7
 		if (err < 0) {
b96ca7
 			fprintf(stderr, "Cannot insert"
b96ca7
 				" classification rule\n");
b96ca7
@@ -3588,8 +3600,18 @@ static int do_grxclass(struct cmd_context *ctx)
b96ca7
 	struct ethtool_rxnfc nfccmd;
b96ca7
 	int err;
b96ca7
 
b96ca7
-	if (ctx->argc == 2 && !strcmp(ctx->argp[0], "rx-flow-hash")) {
b96ca7
+	if (ctx->argc > 0 && !strcmp(ctx->argp[0], "rx-flow-hash")) {
b96ca7
 		int rx_fhash_get;
b96ca7
+		bool flow_rss = false;
b96ca7
+
b96ca7
+		if (ctx->argc == 4) {
b96ca7
+			if (strcmp(ctx->argp[2], "context"))
b96ca7
+				exit_bad_args();
b96ca7
+			flow_rss = true;
b96ca7
+			nfccmd.rss_context = get_u32(ctx->argp[3], 0);
b96ca7
+		} else if (ctx->argc != 2) {
b96ca7
+			exit_bad_args();
b96ca7
+		}
b96ca7
 
b96ca7
 		rx_fhash_get = rxflow_str_to_type(ctx->argp[1]);
b96ca7
 		if (!rx_fhash_get)
b96ca7
@@ -3597,11 +3619,17 @@ static int do_grxclass(struct cmd_context *ctx)
b96ca7
 
b96ca7
 		nfccmd.cmd = ETHTOOL_GRXFH;
b96ca7
 		nfccmd.flow_type = rx_fhash_get;
b96ca7
+		if (flow_rss)
b96ca7
+			nfccmd.flow_type |= FLOW_RSS;
b96ca7
 		err = send_ioctl(ctx, &nfccmd);
b96ca7
-		if (err < 0)
b96ca7
+		if (err < 0) {
b96ca7
 			perror("Cannot get RX network flow hashing options");
b96ca7
-		else
b96ca7
+		} else {
b96ca7
+			if (flow_rss)
b96ca7
+				fprintf(stdout, "For RSS context %u:\n",
b96ca7
+					nfccmd.rss_context);
b96ca7
 			dump_rxfhash(rx_fhash_get, nfccmd.data);
b96ca7
+		}
b96ca7
 	} else if (ctx->argc == 2 && !strcmp(ctx->argp[0], "rule")) {
b96ca7
 		int rx_class_rule_get =
b96ca7
 			get_uint_range(ctx->argp[1], 0, INT_MAX);
b96ca7
@@ -3693,10 +3721,23 @@ static int do_grxfh(struct cmd_context *ctx)
b96ca7
 	struct ethtool_rxfh rss_head = {0};
b96ca7
 	struct ethtool_rxnfc ring_count;
b96ca7
 	struct ethtool_rxfh *rss;
b96ca7
+	u32 rss_context = 0;
b96ca7
 	u32 i, indir_bytes;
b96ca7
+	int arg_num = 0;
b96ca7
 	char *hkey;
b96ca7
 	int err;
b96ca7
 
b96ca7
+	while (arg_num < ctx->argc) {
b96ca7
+		if (!strcmp(ctx->argp[arg_num], "context")) {
b96ca7
+			++arg_num;
b96ca7
+			rss_context = get_int_range(ctx->argp[arg_num], 0, 1,
b96ca7
+						    ETH_RXFH_CONTEXT_ALLOC - 1);
b96ca7
+			++arg_num;
b96ca7
+		} else {
b96ca7
+			exit_bad_args();
b96ca7
+		}
b96ca7
+	}
b96ca7
+
b96ca7
 	ring_count.cmd = ETHTOOL_GRXRINGS;
b96ca7
 	err = send_ioctl(ctx, &ring_count);
b96ca7
 	if (err < 0) {
b96ca7
@@ -3705,6 +3746,7 @@ static int do_grxfh(struct cmd_context *ctx)
b96ca7
 	}
b96ca7
 
b96ca7
 	rss_head.cmd = ETHTOOL_GRSSH;
b96ca7
+	rss_head.rss_context = rss_context;
b96ca7
 	err = send_ioctl(ctx, &rss_head);
b96ca7
 	if (err < 0 && errno == EOPNOTSUPP) {
b96ca7
 		return do_grxfhindir(ctx, &ring_count);
b96ca7
@@ -3722,6 +3764,7 @@ static int do_grxfh(struct cmd_context *ctx)
b96ca7
 	}
b96ca7
 
b96ca7
 	rss->cmd = ETHTOOL_GRSSH;
b96ca7
+	rss->rss_context = rss_context;
b96ca7
 	rss->indir_size = rss_head.indir_size;
b96ca7
 	rss->key_size = rss_head.key_size;
b96ca7
 	err = send_ioctl(ctx, rss);
b96ca7
@@ -3882,6 +3925,8 @@ static int do_srxfh(struct cmd_context *ctx)
b96ca7
 	u32 req_hfunc = 0;
b96ca7
 	u32 entry_size = sizeof(rss_head.rss_config[0]);
b96ca7
 	u32 num_weights = 0;
b96ca7
+	u32 rss_context = 0;
b96ca7
+	int delete = 0;
b96ca7
 
b96ca7
 	if (ctx->argc < 1)
b96ca7
 		exit_bad_args();
b96ca7
@@ -3917,6 +3962,18 @@ static int do_srxfh(struct cmd_context *ctx)
b96ca7
 			if (!req_hfunc_name)
b96ca7
 				exit_bad_args();
b96ca7
 			++arg_num;
b96ca7
+		} else if (!strcmp(ctx->argp[arg_num], "context")) {
b96ca7
+			++arg_num;
b96ca7
+			if(!strcmp(ctx->argp[arg_num], "new"))
b96ca7
+				rss_context = ETH_RXFH_CONTEXT_ALLOC;
b96ca7
+			else
b96ca7
+				rss_context = get_int_range(
b96ca7
+						ctx->argp[arg_num], 0, 1,
b96ca7
+						ETH_RXFH_CONTEXT_ALLOC - 1);
b96ca7
+			++arg_num;
b96ca7
+		} else if (!strcmp(ctx->argp[arg_num], "delete")) {
b96ca7
+			++arg_num;
b96ca7
+			delete = 1;
b96ca7
 		} else {
b96ca7
 			exit_bad_args();
b96ca7
 		}
b96ca7
@@ -3940,6 +3997,41 @@ static int do_srxfh(struct cmd_context *ctx)
b96ca7
 		return 1;
b96ca7
 	}
b96ca7
 
b96ca7
+	if (rxfhindir_default && rss_context) {
b96ca7
+		fprintf(stderr,
b96ca7
+			"Default and context options are mutually exclusive\n");
b96ca7
+		return 1;
b96ca7
+	}
b96ca7
+
b96ca7
+	if (delete && !rss_context) {
b96ca7
+		fprintf(stderr, "Delete option requires context option\n");
b96ca7
+		return 1;
b96ca7
+	}
b96ca7
+
b96ca7
+	if (delete && rxfhindir_weight) {
b96ca7
+		fprintf(stderr,
b96ca7
+			"Delete and weight options are mutually exclusive\n");
b96ca7
+		return 1;
b96ca7
+	}
b96ca7
+
b96ca7
+	if (delete && rxfhindir_equal) {
b96ca7
+		fprintf(stderr,
b96ca7
+			"Delete and equal options are mutually exclusive\n");
b96ca7
+		return 1;
b96ca7
+	}
b96ca7
+
b96ca7
+	if (delete && rxfhindir_default) {
b96ca7
+		fprintf(stderr,
b96ca7
+			"Delete and default options are mutually exclusive\n");
b96ca7
+		return 1;
b96ca7
+	}
b96ca7
+
b96ca7
+	if (delete && rxfhindir_key) {
b96ca7
+		fprintf(stderr,
b96ca7
+			"Delete and hkey options are mutually exclusive\n");
b96ca7
+		return 1;
b96ca7
+	}
b96ca7
+
b96ca7
 	ring_count.cmd = ETHTOOL_GRXRINGS;
b96ca7
 	err = send_ioctl(ctx, &ring_count);
b96ca7
 	if (err < 0) {
b96ca7
@@ -3950,7 +4042,7 @@ static int do_srxfh(struct cmd_context *ctx)
b96ca7
 	rss_head.cmd = ETHTOOL_GRSSH;
b96ca7
 	err = send_ioctl(ctx, &rss_head);
b96ca7
 	if (err < 0 && errno == EOPNOTSUPP && !rxfhindir_key &&
b96ca7
-	    !req_hfunc_name) {
b96ca7
+	    !req_hfunc_name && !rss_context) {
b96ca7
 		return do_srxfhindir(ctx, rxfhindir_default, rxfhindir_equal,
b96ca7
 				     rxfhindir_weight, num_weights);
b96ca7
 	} else if (err < 0) {
b96ca7
@@ -3998,14 +4090,19 @@ static int do_srxfh(struct cmd_context *ctx)
b96ca7
 		goto free;
b96ca7
 	}
b96ca7
 	rss->cmd = ETHTOOL_SRSSH;
b96ca7
-	rss->indir_size = rss_head.indir_size;
b96ca7
-	rss->key_size = rss_head.key_size;
b96ca7
+	rss->rss_context = rss_context;
b96ca7
 	rss->hfunc = req_hfunc;
b96ca7
-
b96ca7
-	if (fill_indir_table(&rss->indir_size, rss->rss_config, rxfhindir_default,
b96ca7
-			     rxfhindir_equal, rxfhindir_weight, num_weights)) {
b96ca7
-		err = 1;
b96ca7
-		goto free;
b96ca7
+	if (delete) {
b96ca7
+		rss->indir_size = rss->key_size = 0;
b96ca7
+	} else {
b96ca7
+		rss->indir_size = rss_head.indir_size;
b96ca7
+		rss->key_size = rss_head.key_size;
b96ca7
+		if (fill_indir_table(&rss->indir_size, rss->rss_config,
b96ca7
+				     rxfhindir_default, rxfhindir_equal,
b96ca7
+				     rxfhindir_weight, num_weights)) {
b96ca7
+			err = 1;
b96ca7
+			goto free;
b96ca7
+		}
b96ca7
 	}
b96ca7
 
b96ca7
 	if (hkey)
b96ca7
@@ -4018,6 +4115,8 @@ static int do_srxfh(struct cmd_context *ctx)
b96ca7
 	if (err < 0) {
b96ca7
 		perror("Cannot set RX flow hash configuration");
b96ca7
 		err = 1;
b96ca7
+	} else if (rss_context == ETH_RXFH_CONTEXT_ALLOC) {
b96ca7
+		printf("New RSS context is %d\n", rss->rss_context);
b96ca7
 	}
b96ca7
 
b96ca7
 free:
b96ca7
@@ -4803,12 +4902,12 @@ static const struct option {
b96ca7
 	{ "-n|-u|--show-nfc|--show-ntuple", 1, do_grxclass,
b96ca7
 	  "Show Rx network flow classification options or rules",
b96ca7
 	  "		[ rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|"
b96ca7
-	  "tcp6|udp6|ah6|esp6|sctp6 |\n"
b96ca7
+	  "tcp6|udp6|ah6|esp6|sctp6 [context %d] |\n"
b96ca7
 	  "		  rule %d ]\n" },
b96ca7
 	{ "-N|-U|--config-nfc|--config-ntuple", 1, do_srxclass,
b96ca7
 	  "Configure Rx network flow classification options or rules",
b96ca7
 	  "		rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|"
b96ca7
-	  "tcp6|udp6|ah6|esp6|sctp6 m|v|t|s|d|f|n|r... |\n"
b96ca7
+	  "tcp6|udp6|ah6|esp6|sctp6 m|v|t|s|d|f|n|r... [context %d] |\n"
b96ca7
 	  "		flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4|"
b96ca7
 	  "ip6|tcp6|udp6|ah6|esp6|sctp6\n"
b96ca7
 	  "			[ src %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n"
b96ca7
@@ -4827,17 +4926,21 @@ static const struct option {
b96ca7
 	  "			[ user-def %x [m %x] ]\n"
b96ca7
 	  "			[ dst-mac %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n"
b96ca7
 	  "			[ action %d ]\n"
b96ca7
+	  "			[ context %d ]\n"
b96ca7
 	  "			[ loc %d]] |\n"
b96ca7
 	  "		delete %d\n" },
b96ca7
 	{ "-T|--show-time-stamping", 1, do_tsinfo,
b96ca7
 	  "Show time stamping capabilities" },
b96ca7
 	{ "-x|--show-rxfh-indir|--show-rxfh", 1, do_grxfh,
b96ca7
-	  "Show Rx flow hash indirection table and/or RSS hash key" },
b96ca7
+	  "Show Rx flow hash indirection table and/or RSS hash key",
b96ca7
+	  "		[ context %d ]\n" },
b96ca7
 	{ "-X|--set-rxfh-indir|--rxfh", 1, do_srxfh,
b96ca7
 	  "Set Rx flow hash indirection table and/or RSS hash key",
b96ca7
+	  "		[ context %d|new ]\n"
b96ca7
 	  "		[ equal N | weight W0 W1 ... | default ]\n"
b96ca7
 	  "		[ hkey %x:%x:%x:%x:%x:.... ]\n"
b96ca7
-	  "		[ hfunc FUNC ]\n" },
b96ca7
+	  "		[ hfunc FUNC ]\n"
b96ca7
+	  "		[ delete ]\n" },
b96ca7
 	{ "-f|--flash", 1, do_flash,
b96ca7
 	  "Flash firmware image from the specified file to a region on the device",
b96ca7
 	  "               FILENAME [ REGION-NUMBER-TO-FLASH ]\n" },
b96ca7
diff --git a/internal.h b/internal.h
b96ca7
index 4e658ea..913f4eb 100644
b96ca7
--- a/internal.h
b96ca7
+++ b/internal.h
b96ca7
@@ -332,11 +332,11 @@ int vmxnet3_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs);
b96ca7
 
b96ca7
 /* Rx flow classification */
b96ca7
 int rxclass_parse_ruleopts(struct cmd_context *ctx,
b96ca7
-			   struct ethtool_rx_flow_spec *fsp);
b96ca7
+			   struct ethtool_rx_flow_spec *fsp, __u32 *rss_context);
b96ca7
 int rxclass_rule_getall(struct cmd_context *ctx);
b96ca7
 int rxclass_rule_get(struct cmd_context *ctx, __u32 loc);
b96ca7
 int rxclass_rule_ins(struct cmd_context *ctx,
b96ca7
-		     struct ethtool_rx_flow_spec *fsp);
b96ca7
+		     struct ethtool_rx_flow_spec *fsp, __u32 rss_context);
b96ca7
 int rxclass_rule_del(struct cmd_context *ctx, __u32 loc);
b96ca7
 
b96ca7
 /* Module EEPROM parsing code */
b96ca7
diff --git a/rxclass.c b/rxclass.c
b96ca7
index c7bfeba..39c9eca 100644
b96ca7
--- a/rxclass.c
b96ca7
+++ b/rxclass.c
b96ca7
@@ -94,14 +94,15 @@ static void rxclass_print_nfc_spec_ext(struct ethtool_rx_flow_spec *fsp)
b96ca7
 	}
b96ca7
 }
b96ca7
 
b96ca7
-static void rxclass_print_nfc_rule(struct ethtool_rx_flow_spec *fsp)
b96ca7
+static void rxclass_print_nfc_rule(struct ethtool_rx_flow_spec *fsp,
b96ca7
+				   __u32 rss_context)
b96ca7
 {
b96ca7
 	unsigned char	*smac, *smacm, *dmac, *dmacm;
b96ca7
 	__u32		flow_type;
b96ca7
 
b96ca7
 	fprintf(stdout,	"Filter: %d\n", fsp->location);
b96ca7
 
b96ca7
-	flow_type = fsp->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT);
b96ca7
+	flow_type = fsp->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS);
b96ca7
 
b96ca7
 	invert_flow_mask(fsp);
b96ca7
 
b96ca7
@@ -247,6 +248,9 @@ static void rxclass_print_nfc_rule(struct ethtool_rx_flow_spec *fsp)
b96ca7
 
b96ca7
 	rxclass_print_nfc_spec_ext(fsp);
b96ca7
 
b96ca7
+	if (fsp->flow_type & FLOW_RSS)
b96ca7
+		fprintf(stdout, "\tRSS Context ID: %u\n", rss_context);
b96ca7
+
b96ca7
 	if (fsp->ring_cookie != RX_CLS_FLOW_DISC)
b96ca7
 		fprintf(stdout, "\tAction: Direct to queue %llu\n",
b96ca7
 			fsp->ring_cookie);
b96ca7
@@ -256,10 +260,11 @@ static void rxclass_print_nfc_rule(struct ethtool_rx_flow_spec *fsp)
b96ca7
 	fprintf(stdout, "\n");
b96ca7
 }
b96ca7
 
b96ca7
-static void rxclass_print_rule(struct ethtool_rx_flow_spec *fsp)
b96ca7
+static void rxclass_print_rule(struct ethtool_rx_flow_spec *fsp,
b96ca7
+			       __u32 rss_context)
b96ca7
 {
b96ca7
 	/* print the rule in this location */
b96ca7
-	switch (fsp->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
b96ca7
+	switch (fsp->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS)) {
b96ca7
 	case TCP_V4_FLOW:
b96ca7
 	case UDP_V4_FLOW:
b96ca7
 	case SCTP_V4_FLOW:
b96ca7
@@ -272,11 +277,11 @@ static void rxclass_print_rule(struct ethtool_rx_flow_spec *fsp)
b96ca7
 	case ESP_V6_FLOW:
b96ca7
 	case IPV6_USER_FLOW:
b96ca7
 	case ETHER_FLOW:
b96ca7
-		rxclass_print_nfc_rule(fsp);
b96ca7
+		rxclass_print_nfc_rule(fsp, rss_context);
b96ca7
 		break;
b96ca7
 	case IPV4_USER_FLOW:
b96ca7
 		if (fsp->h_u.usr_ip4_spec.ip_ver == ETH_RX_NFC_IP4)
b96ca7
-			rxclass_print_nfc_rule(fsp);
b96ca7
+			rxclass_print_nfc_rule(fsp, rss_context);
b96ca7
 		else /* IPv6 uses IPV6_USER_FLOW */
b96ca7
 			fprintf(stderr, "IPV4_USER_FLOW with wrong ip_ver\n");
b96ca7
 		break;
b96ca7
@@ -320,7 +325,7 @@ int rxclass_rule_get(struct cmd_context *ctx, __u32 loc)
b96ca7
 	}
b96ca7
 
b96ca7
 	/* display rule */
b96ca7
-	rxclass_print_rule(&nfccmd.fs);
b96ca7
+	rxclass_print_rule(&nfccmd.fs, (__u32)nfccmd.rss_context);
b96ca7
 	return err;
b96ca7
 }
b96ca7
 
b96ca7
@@ -550,7 +555,7 @@ out:
b96ca7
 }
b96ca7
 
b96ca7
 int rxclass_rule_ins(struct cmd_context *ctx,
b96ca7
-		     struct ethtool_rx_flow_spec *fsp)
b96ca7
+		     struct ethtool_rx_flow_spec *fsp, __u32 rss_context)
b96ca7
 {
b96ca7
 	struct ethtool_rxnfc nfccmd;
b96ca7
 	__u32 loc = fsp->location;
b96ca7
@@ -568,6 +573,7 @@ int rxclass_rule_ins(struct cmd_context *ctx,
b96ca7
 
b96ca7
 	/* notify netdev of new rule */
b96ca7
 	nfccmd.cmd = ETHTOOL_SRXCLSRLINS;
b96ca7
+	nfccmd.rss_context = rss_context;
b96ca7
 	nfccmd.fs = *fsp;
b96ca7
 	err = send_ioctl(ctx, &nfccmd);
b96ca7
 	if (err < 0)
b96ca7
@@ -1184,7 +1190,7 @@ static int rxclass_get_mask(char *str, unsigned char *p,
b96ca7
 }
b96ca7
 
b96ca7
 int rxclass_parse_ruleopts(struct cmd_context *ctx,
b96ca7
-			   struct ethtool_rx_flow_spec *fsp)
b96ca7
+			   struct ethtool_rx_flow_spec *fsp, __u32 *rss_context)
b96ca7
 {
b96ca7
 	const struct rule_opts *options;
b96ca7
 	unsigned char *p = (unsigned char *)fsp;
b96ca7
@@ -1273,6 +1279,40 @@ int rxclass_parse_ruleopts(struct cmd_context *ctx,
b96ca7
 	for (i = 1; i < argc;) {
b96ca7
 		const struct rule_opts *opt;
b96ca7
 		int idx;
b96ca7
+
b96ca7
+		/* special handling for 'context %d' as it doesn't go in
b96ca7
+		 * the struct ethtool_rx_flow_spec
b96ca7
+		 */
b96ca7
+		if (!strcmp(argp[i], "context")) {
b96ca7
+			unsigned long long val;
b96ca7
+
b96ca7
+			i++;
b96ca7
+			if (i >= argc) {
b96ca7
+				fprintf(stderr, "'context' missing value\n");
b96ca7
+				return -1;
b96ca7
+			}
b96ca7
+
b96ca7
+			if (rxclass_get_ulong(argp[i], &val, 32)) {
b96ca7
+				fprintf(stderr, "Invalid context value[%s]\n",
b96ca7
+					argp[i]);
b96ca7
+				return -1;
b96ca7
+			}
b96ca7
+
b96ca7
+			/* Can't use the ALLOC special value as the context ID
b96ca7
+			 * of a filter to insert
b96ca7
+			 */
b96ca7
+			if ((__u32)val == ETH_RXFH_CONTEXT_ALLOC) {
b96ca7
+				fprintf(stderr, "Bad context value %x\n",
b96ca7
+					(__u32)val);
b96ca7
+				return -1;
b96ca7
+			}
b96ca7
+
b96ca7
+			*rss_context = (__u32)val;
b96ca7
+			fsp->flow_type |= FLOW_RSS;
b96ca7
+			i++;
b96ca7
+			continue;
b96ca7
+		}
b96ca7
+
b96ca7
 		for (opt = options, idx = 0; idx < n_opts; idx++, opt++) {
b96ca7
 			char mask_name[16];
b96ca7
 
b96ca7
-- 
b96ca7
1.8.3.1
b96ca7