Commit dfc14664 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'net-make-rss-rxnfc-semantics-more-explicit'

Edward Cree says:

====================
net: make RSS+RXNFC semantics more explicit

The original semantics of ntuple filters with FLOW_RSS were not
 fully understood by all drivers, some ignoring the ring_cookie from
 the flow rule.  Require this support to be explicitly declared by
 the driver for filters relying on it to be inserted, and add self-
 test coverage for this functionality.
Also teach ethtool_check_max_channel() about this.
====================

Link: https://patch.msgid.link/cover.1731499021.git.ecree.xilinx@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents b52a8dee 29a4bc1f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ const struct ethtool_ops ef100_ethtool_ops = {
	.get_rxfh_indir_size	= efx_ethtool_get_rxfh_indir_size,
	.get_rxfh_key_size	= efx_ethtool_get_rxfh_key_size,
	.rxfh_per_ctx_key	= true,
	.cap_rss_rxnfc_adds	= true,
	.rxfh_priv_size		= sizeof(struct efx_rss_context_priv),
	.get_rxfh		= efx_ethtool_get_rxfh,
	.set_rxfh		= efx_ethtool_set_rxfh,
+1 −0
Original line number Diff line number Diff line
@@ -263,6 +263,7 @@ const struct ethtool_ops efx_ethtool_ops = {
	.get_rxfh_indir_size	= efx_ethtool_get_rxfh_indir_size,
	.get_rxfh_key_size	= efx_ethtool_get_rxfh_key_size,
	.rxfh_per_ctx_key	= true,
	.cap_rss_rxnfc_adds	= true,
	.rxfh_priv_size		= sizeof(struct efx_rss_context_priv),
	.get_rxfh		= efx_ethtool_get_rxfh,
	.set_rxfh		= efx_ethtool_set_rxfh,
+4 −0
Original line number Diff line number Diff line
@@ -734,6 +734,9 @@ struct kernel_ethtool_ts_info {
 * @rxfh_per_ctx_key: device supports setting different RSS key for each
 *	additional context. Netlink API should report hfunc, key, and input_xfrm
 *	for every context, not just context 0.
 * @cap_rss_rxnfc_adds: device supports nonzero ring_cookie in filters with
 *	%FLOW_RSS flag; the queue ID from the filter is added to the value from
 *	the indirection table to determine the delivery queue.
 * @rxfh_indir_space: max size of RSS indirection tables, if indirection table
 *	size as returned by @get_rxfh_indir_size may change during lifetime
 *	of the device. Leave as 0 if the table size is constant.
@@ -956,6 +959,7 @@ struct ethtool_ops {
	u32     cap_rss_ctx_supported:1;
	u32	cap_rss_sym_xor_supported:1;
	u32	rxfh_per_ctx_key:1;
	u32	cap_rss_rxnfc_adds:1;
	u32	rxfh_indir_space;
	u16	rxfh_key_space;
	u16	rxfh_priv_size;
+30 −12
Original line number Diff line number Diff line
@@ -538,6 +538,20 @@ static int ethtool_get_rxnfc_rule_count(struct net_device *dev)
	return info.rule_cnt;
}

/* Max offset for one RSS context */
static u32 ethtool_get_rss_ctx_max_channel(struct ethtool_rxfh_context *ctx)
{
	u32 max_ring = 0;
	u32 i, *tbl;

	if (WARN_ON_ONCE(!ctx))
		return 0;
	tbl = ethtool_rxfh_context_indir(ctx);
	for (i = 0; i < ctx->indir_size; i++)
		max_ring = max(max_ring, tbl[i]);
	return max_ring;
}

static int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max)
{
	const struct ethtool_ops *ops = dev->ethtool_ops;
@@ -574,10 +588,18 @@ static int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max)

		if (rule_info.fs.ring_cookie != RX_CLS_FLOW_DISC &&
		    rule_info.fs.ring_cookie != RX_CLS_FLOW_WAKE &&
		    !(rule_info.flow_type & FLOW_RSS) &&
		    !ethtool_get_flow_spec_ring_vf(rule_info.fs.ring_cookie))
			max_ring =
				max_t(u64, max_ring, rule_info.fs.ring_cookie);
		    !ethtool_get_flow_spec_ring_vf(rule_info.fs.ring_cookie)) {
			u64 ring = rule_info.fs.ring_cookie;

			if (rule_info.flow_type & FLOW_RSS) {
				struct ethtool_rxfh_context *ctx;

				ctx = xa_load(&dev->ethtool->rss_ctx,
					      rule_info.rss_context);
				ring += ethtool_get_rss_ctx_max_channel(ctx);
			}
			max_ring = max_t(u64, max_ring, ring);
		}
	}

	kvfree(info);
@@ -589,6 +611,7 @@ static int ethtool_get_max_rxnfc_channel(struct net_device *dev, u64 *max)
	return err;
}

/* Max offset across all of a device's RSS contexts */
static u32 ethtool_get_max_rss_ctx_channel(struct net_device *dev)
{
	struct ethtool_rxfh_context *ctx;
@@ -596,13 +619,8 @@ static u32 ethtool_get_max_rss_ctx_channel(struct net_device *dev)
	u32 max_ring = 0;

	mutex_lock(&dev->ethtool->rss_lock);
	xa_for_each(&dev->ethtool->rss_ctx, context, ctx) {
		u32 i, *tbl;

		tbl = ethtool_rxfh_context_indir(ctx);
		for (i = 0; i < ctx->indir_size; i++)
			max_ring = max(max_ring, tbl[i]);
	}
	xa_for_each(&dev->ethtool->rss_ctx, context, ctx)
		max_ring = max(max_ring, ethtool_get_rss_ctx_max_channel(ctx));
	mutex_unlock(&dev->ethtool->rss_lock);

	return max_ring;
@@ -611,7 +629,7 @@ static u32 ethtool_get_max_rss_ctx_channel(struct net_device *dev)
static u32 ethtool_get_max_rxfh_channel(struct net_device *dev)
{
	struct ethtool_rxfh_param rxfh = {};
	u32 dev_size, current_max;
	u32 dev_size, current_max = 0;
	int ret;

	/* While we do track whether RSS context has an indirection
+5 −0
Original line number Diff line number Diff line
@@ -992,6 +992,11 @@ static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
	if (rc)
		return rc;

	/* Nonzero ring with RSS only makes sense if NIC adds them together */
	if (info.flow_type & FLOW_RSS && !ops->cap_rss_rxnfc_adds &&
	    ethtool_get_flow_spec_ring(info.fs.ring_cookie))
		return -EINVAL;

	if (ops->get_rxfh) {
		struct ethtool_rxfh_param rxfh = {};

Loading