[dpdk-stable] patch 'net/sfc/base: handle manual and auto filter clashes in EF10' has been queued to LTS release 18.11.9

Kevin Traynor ktraynor at redhat.com
Thu May 28 18:22:06 CEST 2020


Hi,

FYI, your patch has been queued to LTS release 18.11.9

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 06/03/20. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/kevintraynor/dpdk-stable-queue

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable-queue/commit/55239b558d3af3efb2c2a81ed1e170a591961bd0

Thanks.

Kevin.

---
>From 55239b558d3af3efb2c2a81ed1e170a591961bd0 Mon Sep 17 00:00:00 2001
From: Igor Romanov <igor.romanov at oktetlabs.ru>
Date: Tue, 10 Mar 2020 09:48:39 +0000
Subject: [PATCH] net/sfc/base: handle manual and auto filter clashes in EF10

[ upstream commit 585c22edb29cc3cfdb3628c41effd8ff3b75f224 ]

Make user filters a priority in EF10 datapath. When a manual
filter with a specification that is equal to an existing auto
filter is inserted, the manual filter:
- replaces auto filter if the specification is exclusive;
- is inserted along existing auto filter otherwise;

In the first case the auto filter that was replaced is saved.
This saved filter can be updated on filter reconfiguration and
is restored on the manual filter removal.

Fixes: e7cd430c864f ("net/sfc/base: import SFN7xxx family support")

Signed-off-by: Igor Romanov <igor.romanov at oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko at solarflare.com>
---
 drivers/net/sfc/base/ef10_filter.c | 519 ++++++++++++++++++++++-------
 drivers/net/sfc/base/ef10_impl.h   |   4 +-
 drivers/net/sfc/base/efx.h         |   7 +
 drivers/net/sfc/base/efx_filter.c  |  17 +-
 drivers/net/sfc/base/efx_impl.h    |  21 +-
 5 files changed, 437 insertions(+), 131 deletions(-)

diff --git a/drivers/net/sfc/base/ef10_filter.c b/drivers/net/sfc/base/ef10_filter.c
index 7c8721a381..38843207f6 100644
--- a/drivers/net/sfc/base/ef10_filter.c
+++ b/drivers/net/sfc/base/ef10_filter.c
@@ -598,4 +598,229 @@ fail1:
 }
 
+enum ef10_filter_add_action_e {
+	/* Insert a new filter */
+	EF10_FILTER_ADD_NEW,
+	/*
+	 * Replace old filter with a new, overriding the old one
+	 * if it has lower priority.
+	 */
+	EF10_FILTER_ADD_REPLACE,
+	/* Store new, lower priority filter as overridden by old filter */
+	EF10_FILTER_ADD_STORE,
+	/* Special case for AUTO filters, remove AUTO_OLD flag */
+	EF10_FILTER_ADD_REFRESH,
+};
+
+static	__checkReturn	efx_rc_t
+ef10_filter_add_lookup_equal_spec(
+	__in		efx_filter_spec_t *spec,
+	__in		efx_filter_spec_t *probe_spec,
+	__in		efx_filter_replacement_policy_t policy,
+	__out		boolean_t *found)
+{
+	efx_rc_t rc;
+
+	/* Refreshing AUTO filter */
+	if (spec->efs_priority == EFX_FILTER_PRI_AUTO &&
+	    probe_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
+		*found = B_TRUE;
+		return (0);
+	}
+
+	/*
+	 * With exclusive filters, higher priority ones
+	 * override lower priority ones, and lower priority
+	 * ones are stored in case the higher priority one
+	 * is removed.
+	 */
+	if (ef10_filter_is_exclusive(spec)) {
+		switch (policy) {
+		case EFX_FILTER_REPLACEMENT_HIGHER_OR_EQUAL_PRIORITY:
+			if (spec->efs_priority == probe_spec->efs_priority) {
+				*found = B_TRUE;
+				break;
+			}
+			/* Fall-through */
+		case EFX_FILTER_REPLACEMENT_HIGHER_PRIORITY:
+			if (spec->efs_priority > probe_spec->efs_priority) {
+				*found = B_TRUE;
+				break;
+			}
+			/* Fall-through */
+		case EFX_FILTER_REPLACEMENT_NEVER:
+			/*
+			 * Lower priority filter needs to be
+			 * stored. It does *not* replace the
+			 * old one. That is why EEXIST is not
+			 * returned in that case.
+			 */
+			if (spec->efs_priority < probe_spec->efs_priority) {
+				*found = B_TRUE;
+				break;
+			} else {
+				rc = EEXIST;
+				goto fail1;
+			}
+		default:
+			EFSYS_ASSERT(0);
+			rc = EEXIST;
+			goto fail2;
+		}
+	} else {
+		*found = B_FALSE;
+	}
+
+	return (0);
+
+fail2:
+	EFSYS_PROBE(fail2);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
+
+static			void
+ef10_filter_add_select_action(
+	__in		efx_filter_spec_t *saved_spec,
+	__in		efx_filter_spec_t *spec,
+	__out		enum ef10_filter_add_action_e *action,
+	__out		efx_filter_spec_t **overridden_spec)
+{
+	efx_filter_spec_t *overridden = NULL;
+
+	if (saved_spec == NULL) {
+		*action = EF10_FILTER_ADD_NEW;
+	} else if (ef10_filter_is_exclusive(spec) == B_FALSE) {
+		/*
+		 * Non-exclusive filters are always stored in separate entries
+		 * in the table. The only case involving a saved spec is
+		 * refreshing an AUTO filter.
+		 */
+		EFSYS_ASSERT(saved_spec->efs_overridden_spec == NULL);
+		EFSYS_ASSERT(spec->efs_priority == EFX_FILTER_PRI_AUTO);
+		EFSYS_ASSERT(saved_spec->efs_priority == EFX_FILTER_PRI_AUTO);
+		*action = EF10_FILTER_ADD_REFRESH;
+	} else {
+		/* Exclusive filters stored in the same entry */
+		if (spec->efs_priority > saved_spec->efs_priority) {
+			/*
+			 * Insert a high priority filter over a lower priority
+			 * one. Only two priority levels are implemented, so
+			 * there must not already be an overridden filter.
+			 */
+			EFX_STATIC_ASSERT(EFX_FILTER_NPRI == 2);
+			EFSYS_ASSERT(saved_spec->efs_overridden_spec == NULL);
+			overridden = saved_spec;
+			*action = EF10_FILTER_ADD_REPLACE;
+		} else if (spec->efs_priority == saved_spec->efs_priority) {
+			/* Replace in-place or refresh an existing filter */
+			if (spec->efs_priority == EFX_FILTER_PRI_AUTO)
+				*action = EF10_FILTER_ADD_REFRESH;
+			else
+				*action = EF10_FILTER_ADD_REPLACE;
+		} else {
+			/*
+			 * Insert a lower priority filter, storing it in case
+			 * the higher priority filter is removed.
+			 *
+			 * Currently there are only two priority levels, so this
+			 * must be an AUTO filter.
+			 */
+			EFX_STATIC_ASSERT(EFX_FILTER_NPRI == 2);
+			EFSYS_ASSERT(spec->efs_priority == EFX_FILTER_PRI_AUTO);
+			if (saved_spec->efs_overridden_spec != NULL) {
+				*action = EF10_FILTER_ADD_REFRESH;
+			} else {
+				overridden = spec;
+				*action = EF10_FILTER_ADD_STORE;
+			}
+		}
+	}
+
+	*overridden_spec = overridden;
+}
+
+static	__checkReturn	efx_rc_t
+ef10_filter_add_execute_action(
+	__in		efx_nic_t *enp,
+	__in		efx_filter_spec_t *saved_spec,
+	__in		efx_filter_spec_t *spec,
+	__in		efx_filter_spec_t *overridden_spec,
+	__in		enum ef10_filter_add_action_e action,
+	__in		int ins_index)
+{
+	ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
+	efsys_lock_state_t state;
+	efx_rc_t rc;
+
+	EFSYS_LOCK(enp->en_eslp, state);
+
+	if (action == EF10_FILTER_ADD_REFRESH) {
+		ef10_filter_set_entry_not_auto_old(eftp, ins_index);
+		goto out_unlock;
+	} else if (action == EF10_FILTER_ADD_STORE) {
+		EFSYS_ASSERT(overridden_spec != NULL);
+		saved_spec->efs_overridden_spec = overridden_spec;
+		goto out_unlock;
+	}
+
+	EFSYS_UNLOCK(enp->en_eslp, state);
+
+	switch (action) {
+	case EF10_FILTER_ADD_REPLACE:
+		/*
+		 * On replacing the filter handle may change after a
+		 * successful replace operation.
+		 */
+		rc = efx_mcdi_filter_op_add(enp, spec,
+		    MC_CMD_FILTER_OP_IN_OP_REPLACE,
+		    &eftp->eft_entry[ins_index].efe_handle);
+		break;
+	case EF10_FILTER_ADD_NEW:
+		if (ef10_filter_is_exclusive(spec)) {
+			rc = efx_mcdi_filter_op_add(enp, spec,
+			    MC_CMD_FILTER_OP_IN_OP_INSERT,
+			    &eftp->eft_entry[ins_index].efe_handle);
+		} else {
+			rc = efx_mcdi_filter_op_add(enp, spec,
+			    MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
+			    &eftp->eft_entry[ins_index].efe_handle);
+		}
+		break;
+	default:
+		rc = EINVAL;
+		EFSYS_ASSERT(0);
+		break;
+	}
+	if (rc != 0)
+		goto fail1;
+
+	EFSYS_LOCK(enp->en_eslp, state);
+
+	if (action == EF10_FILTER_ADD_REPLACE) {
+		/* Update the fields that may differ */
+		saved_spec->efs_priority = spec->efs_priority;
+		saved_spec->efs_flags = spec->efs_flags;
+		saved_spec->efs_rss_context = spec->efs_rss_context;
+		saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
+
+		if (overridden_spec != NULL)
+			saved_spec->efs_overridden_spec = overridden_spec;
+	}
+
+out_unlock:
+	EFSYS_UNLOCK(enp->en_eslp, state);
+
+	return (0);
+
+fail1:
+	EFSYS_PROBE1(fail1, efx_rc_t, rc);
+
+	return (rc);
+}
+
 /*
  * An arbitrary search limit for the software hash table. As per the linux net
@@ -608,15 +833,15 @@ ef10_filter_add_internal(
 	__in		efx_nic_t *enp,
 	__inout		efx_filter_spec_t *spec,
-	__in		boolean_t may_replace,
+	__in		efx_filter_replacement_policy_t policy,
 	__out_opt	uint32_t *filter_id)
 {
 	efx_rc_t rc;
 	ef10_filter_table_t *eftp = enp->en_filter.ef_ef10_filter_table;
+	enum ef10_filter_add_action_e action;
+	efx_filter_spec_t *overridden_spec = NULL;
 	efx_filter_spec_t *saved_spec;
 	uint32_t hash;
 	unsigned int depth;
 	int ins_index;
-	boolean_t replacing = B_FALSE;
-	unsigned int i;
 	efsys_lock_state_t state;
 	boolean_t locked = B_FALSE;
@@ -626,4 +851,6 @@ ef10_filter_add_internal(
 	    enp->en_family == EFX_FAMILY_MEDFORD2);
 
+	EFSYS_ASSERT(spec->efs_overridden_spec == NULL);
+
 	hash = ef10_filter_hash(spec);
 
@@ -645,12 +872,17 @@ retry:
 
 	for (depth = 1; depth <= EF10_FILTER_SEARCH_LIMIT; depth++) {
-		i = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
-		saved_spec = ef10_filter_entry_spec(eftp, i);
+		unsigned int probe_index;
+		efx_filter_spec_t *probe_spec;
 
-		if (saved_spec == NULL) {
+		probe_index = (hash + depth) & (EFX_EF10_FILTER_TBL_ROWS - 1);
+		probe_spec = ef10_filter_entry_spec(eftp, probe_index);
+
+		if (probe_spec == NULL) {
 			if (ins_index < 0)
-				ins_index = i;
-		} else if (ef10_filter_equal(spec, saved_spec)) {
-			if (ef10_filter_entry_is_busy(eftp, i)) {
+				ins_index = probe_index;
+		} else if (ef10_filter_equal(spec, probe_spec)) {
+			boolean_t found;
+
+			if (ef10_filter_entry_is_busy(eftp, probe_index)) {
 				EFSYS_UNLOCK(enp->en_eslp, state);
 				locked = B_FALSE;
@@ -658,20 +890,13 @@ retry:
 			}
 
-			if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
-				ins_index = i;
-				goto found;
-			}
+			rc = ef10_filter_add_lookup_equal_spec(spec,
+			    probe_spec, policy, &found);
+			if (rc != 0)
+				goto fail1;
 
-			if (ef10_filter_is_exclusive(spec)) {
-				if (may_replace) {
-					ins_index = i;
-					goto found;
-				} else {
-					rc = EEXIST;
-					goto fail1;
-				}
+			if (found != B_FALSE) {
+				ins_index = probe_index;
+				break;
 			}
-
-			/* Leave existing */
 		}
 	}
@@ -686,76 +911,59 @@ retry:
 	}
 
-found:
 	/*
-	 * Create a software table entry if necessary, and mark it
-	 * busy.  We might yet fail to insert, but any attempt to
-	 * insert a conflicting filter while we're waiting for the
-	 * firmware must find the busy entry.
+	 * Mark software table entry busy. We might yet fail to insert,
+	 * but any attempt to insert a conflicting filter while we're
+	 * waiting for the firmware must find the busy entry.
 	 */
+	ef10_filter_set_entry_busy(eftp, ins_index);
+
 	saved_spec = ef10_filter_entry_spec(eftp, ins_index);
-	if (saved_spec) {
-		if (saved_spec->efs_priority == EFX_FILTER_PRI_AUTO) {
-			/* This is a filter we are refreshing */
-			ef10_filter_set_entry_not_auto_old(eftp, ins_index);
-			goto out_unlock;
+	ef10_filter_add_select_action(saved_spec, spec, &action,
+	    &overridden_spec);
 
-		}
-		replacing = B_TRUE;
-	} else {
-		EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*spec), saved_spec);
-		if (!saved_spec) {
+	/*
+	 * Allocate a new filter if found entry is empty or
+	 * a filter should be overridden.
+	 */
+	if (overridden_spec != NULL || saved_spec == NULL) {
+		efx_filter_spec_t *new_spec;
+
+		EFSYS_UNLOCK(enp->en_eslp, state);
+		locked = B_FALSE;
+
+		EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*new_spec), new_spec);
+		if (new_spec == NULL) {
 			rc = ENOMEM;
+			overridden_spec = NULL;
 			goto fail3;
 		}
-		*saved_spec = *spec;
-		ef10_filter_set_entry(eftp, ins_index, saved_spec);
+
+		EFSYS_LOCK(enp->en_eslp, state);
+		locked = B_TRUE;
+
+		if (saved_spec == NULL) {
+			*new_spec = *spec;
+			ef10_filter_set_entry(eftp, ins_index, new_spec);
+		} else {
+			*new_spec = *overridden_spec;
+			overridden_spec = new_spec;
+		}
 	}
-	ef10_filter_set_entry_busy(eftp, ins_index);
 
 	EFSYS_UNLOCK(enp->en_eslp, state);
 	locked = B_FALSE;
 
-	/*
-	 * On replacing the filter handle may change after after a successful
-	 * replace operation.
-	 */
-	if (replacing) {
-		rc = efx_mcdi_filter_op_add(enp, spec,
-		    MC_CMD_FILTER_OP_IN_OP_REPLACE,
-		    &eftp->eft_entry[ins_index].efe_handle);
-	} else if (ef10_filter_is_exclusive(spec)) {
-		rc = efx_mcdi_filter_op_add(enp, spec,
-		    MC_CMD_FILTER_OP_IN_OP_INSERT,
-		    &eftp->eft_entry[ins_index].efe_handle);
-	} else {
-		rc = efx_mcdi_filter_op_add(enp, spec,
-		    MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE,
-		    &eftp->eft_entry[ins_index].efe_handle);
-	}
-
+	rc = ef10_filter_add_execute_action(enp, saved_spec, spec,
+	    overridden_spec, action, ins_index);
 	if (rc != 0)
 		goto fail4;
 
-	EFSYS_LOCK(enp->en_eslp, state);
-	locked = B_TRUE;
-
-	if (replacing) {
-		/* Update the fields that may differ */
-		saved_spec->efs_priority = spec->efs_priority;
-		saved_spec->efs_flags = spec->efs_flags;
-		saved_spec->efs_rss_context = spec->efs_rss_context;
-		saved_spec->efs_dmaq_id = spec->efs_dmaq_id;
-	}
-
-	ef10_filter_set_entry_not_busy(eftp, ins_index);
-
-out_unlock:
-
-	EFSYS_UNLOCK(enp->en_eslp, state);
-	locked = B_FALSE;
-
 	if (filter_id)
 		*filter_id = ins_index;
 
+	EFSYS_LOCK(enp->en_eslp, state);
+	ef10_filter_set_entry_not_busy(eftp, ins_index);
+	EFSYS_UNLOCK(enp->en_eslp, state);
+
 	return (0);
 
@@ -763,14 +971,28 @@ fail4:
 	EFSYS_PROBE(fail4);
 
-	if (!replacing) {
-		EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), saved_spec);
-		saved_spec = NULL;
+	EFSYS_ASSERT(locked == B_FALSE);
+	EFSYS_LOCK(enp->en_eslp, state);
+
+	if (action == EF10_FILTER_ADD_NEW) {
+		EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec),
+		    ef10_filter_entry_spec(eftp, ins_index));
+		ef10_filter_set_entry(eftp, ins_index, NULL);
 	}
-	ef10_filter_set_entry_not_busy(eftp, ins_index);
-	ef10_filter_set_entry(eftp, ins_index, NULL);
+
+	EFSYS_UNLOCK(enp->en_eslp, state);
+
+	if (overridden_spec != NULL)
+		EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), overridden_spec);
 
 fail3:
 	EFSYS_PROBE(fail3);
 
+	EFSYS_ASSERT(locked == B_FALSE);
+	EFSYS_LOCK(enp->en_eslp, state);
+
+	ef10_filter_set_entry_not_busy(eftp, ins_index);
+
+	EFSYS_UNLOCK(enp->en_eslp, state);
+
 fail2:
 	EFSYS_PROBE(fail2);
@@ -789,9 +1011,9 @@ ef10_filter_add(
 	__in		efx_nic_t *enp,
 	__inout		efx_filter_spec_t *spec,
-	__in		boolean_t may_replace)
+	__in		enum efx_filter_replacement_policy_e policy)
 {
 	efx_rc_t rc;
 
-	rc = ef10_filter_add_internal(enp, spec, may_replace, NULL);
+	rc = ef10_filter_add_internal(enp, spec, policy, NULL);
 	if (rc != 0)
 		goto fail1;
@@ -805,9 +1027,13 @@ fail1:
 }
 
-
+/*
+ * Delete a filter by index from the filter table with priority
+ * that is not higher than specified.
+ */
 static	__checkReturn	efx_rc_t
 ef10_filter_delete_internal(
 	__in		efx_nic_t *enp,
-	__in		uint32_t filter_id)
+	__in		uint32_t filter_id,
+	__in		efx_filter_priority_t priority)
 {
 	efx_rc_t rc;
@@ -831,5 +1057,6 @@ ef10_filter_delete_internal(
 	}
 	if ((spec = ef10_filter_entry_spec(table, filter_idx)) != NULL) {
-		ef10_filter_set_entry_busy(table, filter_idx);
+		if (spec->efs_priority <= priority)
+			ef10_filter_set_entry_busy(table, filter_idx);
 	}
 	EFSYS_UNLOCK(enp->en_eslp, state);
@@ -840,30 +1067,52 @@ ef10_filter_delete_internal(
 	}
 
-	/*
-	 * Try to remove the hardware filter. This may fail if the MC has
-	 * rebooted (which frees all hardware filter resources).
-	 */
-	if (ef10_filter_is_exclusive(spec)) {
-		rc = efx_mcdi_filter_op_delete(enp,
-		    MC_CMD_FILTER_OP_IN_OP_REMOVE,
-		    &table->eft_entry[filter_idx].efe_handle);
+	if (spec->efs_priority > priority) {
+		/*
+		 * Applied filter stays, but overridden filter is removed since
+		 * next user request to delete the applied filter should not
+		 * restore outdated filter.
+		 */
+		if (spec->efs_overridden_spec != NULL) {
+			EFSYS_ASSERT(spec->efs_overridden_spec->efs_overridden_spec ==
+			    NULL);
+			EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec),
+			    spec->efs_overridden_spec);
+			spec->efs_overridden_spec = NULL;
+		}
 	} else {
-		rc = efx_mcdi_filter_op_delete(enp,
-		    MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
-		    &table->eft_entry[filter_idx].efe_handle);
+		/*
+		 * Try to remove the hardware filter or replace it with the
+		 * saved automatic filter. This may fail if the MC has
+		 * rebooted (which frees all hardware filter resources).
+		 */
+		if (spec->efs_overridden_spec != NULL) {
+			rc = efx_mcdi_filter_op_add(enp,
+			    spec->efs_overridden_spec,
+			    MC_CMD_FILTER_OP_IN_OP_REPLACE,
+			    &table->eft_entry[filter_idx].efe_handle);
+		} else if (ef10_filter_is_exclusive(spec)) {
+			rc = efx_mcdi_filter_op_delete(enp,
+			    MC_CMD_FILTER_OP_IN_OP_REMOVE,
+			    &table->eft_entry[filter_idx].efe_handle);
+		} else {
+			rc = efx_mcdi_filter_op_delete(enp,
+			    MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE,
+			    &table->eft_entry[filter_idx].efe_handle);
+		}
+
+		/* Free the software table entry */
+		EFSYS_LOCK(enp->en_eslp, state);
+		ef10_filter_set_entry_not_busy(table, filter_idx);
+		ef10_filter_set_entry(table, filter_idx,
+		    spec->efs_overridden_spec);
+		EFSYS_UNLOCK(enp->en_eslp, state);
+
+		EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
+
+		/* Check result of hardware filter removal */
+		if (rc != 0)
+			goto fail2;
 	}
 
-	/* Free the software table entry */
-	EFSYS_LOCK(enp->en_eslp, state);
-	ef10_filter_set_entry_not_busy(table, filter_idx);
-	ef10_filter_set_entry(table, filter_idx, NULL);
-	EFSYS_UNLOCK(enp->en_eslp, state);
-
-	EFSYS_KMEM_FREE(enp->en_esip, sizeof (*spec), spec);
-
-	/* Check result of hardware filter removal */
-	if (rc != 0)
-		goto fail2;
-
 	return (0);
 
@@ -877,4 +1126,23 @@ fail1:
 }
 
+static			void
+ef10_filter_delete_auto(
+	__in		efx_nic_t *enp,
+	__in		uint32_t filter_id)
+{
+	ef10_filter_table_t *table = enp->en_filter.ef_ef10_filter_table;
+	uint32_t filter_idx = filter_id % EFX_EF10_FILTER_TBL_ROWS;
+
+	/*
+	 * AUTO_OLD flag is cleared since the auto filter that is to be removed
+	 * may not be the filter at the specified index itself, but the filter
+	 * that is overridden by it.
+	 */
+	ef10_filter_set_entry_not_auto_old(table, filter_idx);
+
+	(void) ef10_filter_delete_internal(enp, filter_idx,
+	    EFX_FILTER_PRI_AUTO);
+}
+
 	__checkReturn	efx_rc_t
 ef10_filter_delete(
@@ -918,5 +1186,5 @@ ef10_filter_delete(
 	locked = B_FALSE;
 
-	rc = ef10_filter_delete_internal(enp, i);
+	rc = ef10_filter_delete_internal(enp, i, EFX_FILTER_PRI_MANUAL);
 	if (rc != 0)
 		goto fail2;
@@ -1143,5 +1411,5 @@ ef10_filter_insert_unicast(
 		goto fail1;
 
-	rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
+	rc = ef10_filter_add_internal(enp, &spec, EFX_FILTER_REPLACEMENT_NEVER,
 	    &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
 	if (rc != 0)
@@ -1177,5 +1445,5 @@ ef10_filter_insert_all_unicast(
 	if (rc != 0)
 		goto fail1;
-	rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
+	rc = ef10_filter_add_internal(enp, &spec, EFX_FILTER_REPLACEMENT_NEVER,
 	    &eftp->eft_unicst_filter_indexes[eftp->eft_unicst_filter_count]);
 	if (rc != 0)
@@ -1247,6 +1515,6 @@ ef10_filter_insert_multicast_list(
 		}
 
-		rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
-					    &filter_index);
+		rc = ef10_filter_add_internal(enp, &spec,
+		    EFX_FILTER_REPLACEMENT_NEVER, &filter_index);
 
 		if (rc == 0) {
@@ -1275,6 +1543,6 @@ ef10_filter_insert_multicast_list(
 		}
 
-		rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
-					    &filter_index);
+		rc = ef10_filter_add_internal(enp, &spec,
+		    EFX_FILTER_REPLACEMENT_NEVER, &filter_index);
 
 		if (rc == 0) {
@@ -1297,5 +1565,5 @@ rollback:
 	i = filter_count;
 	while (i--) {
-		(void) ef10_filter_delete_internal(enp,
+		ef10_filter_delete_auto(enp,
 		    eftp->eft_mulcst_filter_indexes[i]);
 	}
@@ -1325,5 +1593,5 @@ ef10_filter_insert_all_multicast(
 		goto fail1;
 
-	rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
+	rc = ef10_filter_add_internal(enp, &spec, EFX_FILTER_REPLACEMENT_NEVER,
 	    &eftp->eft_mulcst_filter_indexes[0]);
 	if (rc != 0)
@@ -1428,6 +1696,7 @@ ef10_filter_insert_encap_filters(
 			goto fail1;
 
-		rc = ef10_filter_add_internal(enp, &spec, B_TRUE,
-			    &table->eft_encap_filter_indexes[
+		rc = ef10_filter_add_internal(enp, &spec,
+		    EFX_FILTER_REPLACEMENT_NEVER,
+		    &table->eft_encap_filter_indexes[
 				    table->eft_encap_filter_count]);
 		if (rc != 0) {
@@ -1458,5 +1727,5 @@ ef10_filter_remove_old(
 	for (i = 0; i < EFX_ARRAY_SIZE(table->eft_entry); i++) {
 		if (ef10_filter_entry_is_auto_old(table, i)) {
-			(void) ef10_filter_delete_internal(enp, i);
+			ef10_filter_delete_auto(enp, i);
 		}
 	}
@@ -1533,5 +1802,5 @@ ef10_filter_reconfigure(
 		 */
 		for (i = 0; i < table->eft_unicst_filter_count; i++) {
-			(void) ef10_filter_delete_internal(enp,
+			ef10_filter_delete_auto(enp,
 					table->eft_unicst_filter_indexes[i]);
 		}
@@ -1539,5 +1808,5 @@ ef10_filter_reconfigure(
 
 		for (i = 0; i < table->eft_mulcst_filter_count; i++) {
-			(void) ef10_filter_delete_internal(enp,
+			ef10_filter_delete_auto(enp,
 					table->eft_mulcst_filter_indexes[i]);
 		}
@@ -1545,5 +1814,5 @@ ef10_filter_reconfigure(
 
 		for (i = 0; i < table->eft_encap_filter_count; i++) {
-			(void) ef10_filter_delete_internal(enp,
+			ef10_filter_delete_auto(enp,
 					table->eft_encap_filter_indexes[i]);
 		}
diff --git a/drivers/net/sfc/base/ef10_impl.h b/drivers/net/sfc/base/ef10_impl.h
index 6f5d0f9aae..4183325c0f 100644
--- a/drivers/net/sfc/base/ef10_impl.h
+++ b/drivers/net/sfc/base/ef10_impl.h
@@ -1031,4 +1031,6 @@ ef10_rx_fini(
 #if EFSYS_OPT_FILTER
 
+enum efx_filter_replacement_policy_e;
+
 typedef struct ef10_filter_handle_s {
 	uint32_t	efh_lo;
@@ -1100,5 +1102,5 @@ ef10_filter_add(
 	__in		efx_nic_t *enp,
 	__inout		efx_filter_spec_t *spec,
-	__in		boolean_t may_replace);
+	__in		enum efx_filter_replacement_policy_e policy);
 
 	__checkReturn	efx_rc_t
diff --git a/drivers/net/sfc/base/efx.h b/drivers/net/sfc/base/efx.h
index 93d8580d04..9babf8d40b 100644
--- a/drivers/net/sfc/base/efx.h
+++ b/drivers/net/sfc/base/efx.h
@@ -2868,4 +2868,5 @@ typedef uint8_t efx_filter_flags_t;
 typedef uint32_t efx_filter_match_flags_t;
 
+/* Filter priority from lowest to highest */
 typedef enum efx_filter_priority_s {
 	EFX_FILTER_PRI_AUTO = 0,	/* Automatic filter based on device
@@ -2875,4 +2876,5 @@ typedef enum efx_filter_priority_s {
 					 * each NIC type. */
 	EFX_FILTER_PRI_MANUAL,		/* Manually configured filter */
+	EFX_FILTER_NPRI,
 } efx_filter_priority_t;
 
@@ -2889,4 +2891,9 @@ typedef struct efx_filter_spec_s {
 	uint32_t			efs_rss_context;
 	uint32_t			efs_mark;
+	/*
+	 * Saved lower-priority filter. If it is set, it is restored on
+	 * filter delete operation.
+	 */
+	struct efx_filter_spec_s	*efs_overridden_spec;
 	/* Fields below here are hashed for software filter lookup */
 	uint16_t			efs_outer_vid;
diff --git a/drivers/net/sfc/base/efx_filter.c b/drivers/net/sfc/base/efx_filter.c
index 9e53af7538..f70717cbc2 100644
--- a/drivers/net/sfc/base/efx_filter.c
+++ b/drivers/net/sfc/base/efx_filter.c
@@ -29,5 +29,5 @@ siena_filter_add(
 	__in		efx_nic_t *enp,
 	__inout		efx_filter_spec_t *spec,
-	__in		boolean_t may_replace);
+	__in		efx_filter_replacement_policy_t policy);
 
 static	__checkReturn	efx_rc_t
@@ -99,5 +99,6 @@ efx_filter_insert(
 	}
 
-	return (efop->efo_add(enp, spec, B_FALSE));
+	return (efop->efo_add(enp, spec,
+	    EFX_FILTER_REPLACEMENT_HIGHER_PRIORITY));
 
 fail3:
@@ -1445,5 +1446,5 @@ siena_filter_add(
 	__in		efx_nic_t *enp,
 	__inout		efx_filter_spec_t *spec,
-	__in		boolean_t may_replace)
+	__in		efx_filter_replacement_policy_t policy)
 {
 	efx_rc_t rc;
@@ -1486,7 +1487,15 @@ siena_filter_add(
 
 	if (siena_filter_test_used(sftp, filter_idx)) {
-		if (may_replace == B_FALSE) {
+		/* All Siena filter are considered the same priority */
+		switch (policy) {
+		case EFX_FILTER_REPLACEMENT_NEVER:
+		case EFX_FILTER_REPLACEMENT_HIGHER_PRIORITY:
 			rc = EEXIST;
 			goto fail4;
+		case EFX_FILTER_REPLACEMENT_HIGHER_OR_EQUAL_PRIORITY:
+			break;
+		default:
+			EFSYS_ASSERT(0);
+			break;
 		}
 	}
diff --git a/drivers/net/sfc/base/efx_impl.h b/drivers/net/sfc/base/efx_impl.h
index bad23f8198..a61b9460f0 100644
--- a/drivers/net/sfc/base/efx_impl.h
+++ b/drivers/net/sfc/base/efx_impl.h
@@ -241,4 +241,23 @@ typedef struct efx_phy_ops_s {
 
 #if EFSYS_OPT_FILTER
+
+/*
+ * Policy for replacing existing filter when inserting a new one.
+ * Note that all policies allow for storing the new lower priority
+ * filters as overridden by existing higher priority ones. It is needed
+ * to restore the lower priority filters on higher priority ones removal.
+ */
+typedef enum efx_filter_replacement_policy_e {
+	/* Cannot replace existing filter */
+	EFX_FILTER_REPLACEMENT_NEVER,
+	/* Higher priority filters can replace lower priotiry ones */
+	EFX_FILTER_REPLACEMENT_HIGHER_PRIORITY,
+	/*
+	 * Higher priority filters can replace lower priority ones and
+	 * equal priority filters can replace each other.
+	 */
+	EFX_FILTER_REPLACEMENT_HIGHER_OR_EQUAL_PRIORITY,
+} efx_filter_replacement_policy_t;
+
 typedef struct efx_filter_ops_s {
 	efx_rc_t	(*efo_init)(efx_nic_t *);
@@ -246,5 +265,5 @@ typedef struct efx_filter_ops_s {
 	efx_rc_t	(*efo_restore)(efx_nic_t *);
 	efx_rc_t	(*efo_add)(efx_nic_t *, efx_filter_spec_t *,
-				   boolean_t may_replace);
+				   efx_filter_replacement_policy_t policy);
 	efx_rc_t	(*efo_delete)(efx_nic_t *, efx_filter_spec_t *);
 	efx_rc_t	(*efo_supported_filters)(efx_nic_t *, uint32_t *,
-- 
2.21.3

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2020-05-28 17:13:00.157128670 +0100
+++ 0019-net-sfc-base-handle-manual-and-auto-filter-clashes-i.patch	2020-05-28 17:12:59.077556943 +0100
@@ -1 +1 @@
-From 585c22edb29cc3cfdb3628c41effd8ff3b75f224 Mon Sep 17 00:00:00 2001
+From 55239b558d3af3efb2c2a81ed1e170a591961bd0 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 585c22edb29cc3cfdb3628c41effd8ff3b75f224 ]
+
@@ -17 +18,0 @@
-Cc: stable at dpdk.org
@@ -30 +31 @@
-index 5578765ab3..12802a3d13 100644
+index 7c8721a381..38843207f6 100644
@@ -33 +34 @@
-@@ -591,4 +591,229 @@ fail1:
+@@ -598,4 +598,229 @@ fail1:
@@ -263 +264 @@
-@@ -601,15 +826,15 @@ ef10_filter_add_internal(
+@@ -608,15 +833,15 @@ ef10_filter_add_internal(
@@ -282,2 +283,2 @@
-@@ -617,4 +842,6 @@ ef10_filter_add_internal(
- 	EFSYS_ASSERT(EFX_FAMILY_IS_EF10(enp));
+@@ -626,4 +851,6 @@ ef10_filter_add_internal(
+ 	    enp->en_family == EFX_FAMILY_MEDFORD2);
@@ -289 +290 @@
-@@ -636,12 +863,17 @@ retry:
+@@ -645,12 +872,17 @@ retry:
@@ -313 +314 @@
-@@ -649,20 +881,13 @@ retry:
+@@ -658,20 +890,13 @@ retry:
@@ -341 +342 @@
-@@ -677,76 +902,59 @@ retry:
+@@ -686,76 +911,59 @@ retry:
@@ -455 +456 @@
-@@ -754,14 +962,28 @@ fail4:
+@@ -763,14 +971,28 @@ fail4:
@@ -489 +490 @@
-@@ -780,9 +1002,9 @@ ef10_filter_add(
+@@ -789,9 +1011,9 @@ ef10_filter_add(
@@ -501 +502 @@
-@@ -796,9 +1018,13 @@ fail1:
+@@ -805,9 +1027,13 @@ fail1:
@@ -517 +518 @@
-@@ -822,5 +1048,6 @@ ef10_filter_delete_internal(
+@@ -831,5 +1057,6 @@ ef10_filter_delete_internal(
@@ -525 +526 @@
-@@ -831,30 +1058,52 @@ ef10_filter_delete_internal(
+@@ -840,30 +1067,52 @@ ef10_filter_delete_internal(
@@ -601 +602 @@
-@@ -868,4 +1117,23 @@ fail1:
+@@ -877,4 +1126,23 @@ fail1:
@@ -625 +626 @@
-@@ -907,5 +1175,5 @@ ef10_filter_delete(
+@@ -918,5 +1186,5 @@ ef10_filter_delete(
@@ -632 +633 @@
-@@ -1132,5 +1400,5 @@ ef10_filter_insert_unicast(
+@@ -1143,5 +1411,5 @@ ef10_filter_insert_unicast(
@@ -639 +640 @@
-@@ -1166,5 +1434,5 @@ ef10_filter_insert_all_unicast(
+@@ -1177,5 +1445,5 @@ ef10_filter_insert_all_unicast(
@@ -646 +647 @@
-@@ -1236,6 +1504,6 @@ ef10_filter_insert_multicast_list(
+@@ -1247,6 +1515,6 @@ ef10_filter_insert_multicast_list(
@@ -655 +656 @@
-@@ -1264,6 +1532,6 @@ ef10_filter_insert_multicast_list(
+@@ -1275,6 +1543,6 @@ ef10_filter_insert_multicast_list(
@@ -664 +665 @@
-@@ -1286,5 +1554,5 @@ rollback:
+@@ -1297,5 +1565,5 @@ rollback:
@@ -671 +672 @@
-@@ -1314,5 +1582,5 @@ ef10_filter_insert_all_multicast(
+@@ -1325,5 +1593,5 @@ ef10_filter_insert_all_multicast(
@@ -678 +679 @@
-@@ -1417,6 +1685,7 @@ ef10_filter_insert_encap_filters(
+@@ -1428,6 +1696,7 @@ ef10_filter_insert_encap_filters(
@@ -688 +689 @@
-@@ -1447,5 +1716,5 @@ ef10_filter_remove_old(
+@@ -1458,5 +1727,5 @@ ef10_filter_remove_old(
@@ -695 +696 @@
-@@ -1522,5 +1791,5 @@ ef10_filter_reconfigure(
+@@ -1533,5 +1802,5 @@ ef10_filter_reconfigure(
@@ -702 +703 @@
-@@ -1528,5 +1797,5 @@ ef10_filter_reconfigure(
+@@ -1539,5 +1808,5 @@ ef10_filter_reconfigure(
@@ -709 +710 @@
-@@ -1534,5 +1803,5 @@ ef10_filter_reconfigure(
+@@ -1545,5 +1814,5 @@ ef10_filter_reconfigure(
@@ -717 +718 @@
-index 7a00047829..67abf3b853 100644
+index 6f5d0f9aae..4183325c0f 100644
@@ -720 +721 @@
-@@ -1080,4 +1080,6 @@ ef10_rx_fini(
+@@ -1031,4 +1031,6 @@ ef10_rx_fini(
@@ -727 +728 @@
-@@ -1149,5 +1151,5 @@ ef10_filter_add(
+@@ -1100,5 +1102,5 @@ ef10_filter_add(
@@ -735 +736 @@
-index c609c700fa..d94d3c02f7 100644
+index 93d8580d04..9babf8d40b 100644
@@ -738 +739 @@
-@@ -2950,4 +2950,5 @@ typedef uint8_t efx_filter_flags_t;
+@@ -2868,4 +2868,5 @@ typedef uint8_t efx_filter_flags_t;
@@ -744 +745 @@
-@@ -2957,4 +2958,5 @@ typedef enum efx_filter_priority_s {
+@@ -2875,4 +2876,5 @@ typedef enum efx_filter_priority_s {
@@ -750 +751 @@
-@@ -2971,4 +2973,9 @@ typedef struct efx_filter_spec_s {
+@@ -2889,4 +2891,9 @@ typedef struct efx_filter_spec_s {
@@ -761 +762 @@
-index 36332a2801..9949d05bb3 100644
+index 9e53af7538..f70717cbc2 100644
@@ -804 +805 @@
-index 85d984f651..9755f4dfd2 100644
+index bad23f8198..a61b9460f0 100644
@@ -807 +808 @@
-@@ -247,4 +247,23 @@ typedef struct efx_phy_ops_s {
+@@ -241,4 +241,23 @@ typedef struct efx_phy_ops_s {
@@ -831 +832 @@
-@@ -252,5 +271,5 @@ typedef struct efx_filter_ops_s {
+@@ -246,5 +265,5 @@ typedef struct efx_filter_ops_s {



More information about the stable mailing list