Netdev List
 help / color / mirror / Atom feed
* RE: [PATCH net] tipc: serialize udp bearer replicast list updates
From: Tung Quang Nguyen @ 2026-07-07 13:21 UTC (permalink / raw)
  To: Weiming Shi
  Cc: Jon Maloy, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, tipc-discussion@lists.sourceforge.net, Xiang Mei,
	netdev@vger.kernel.org
In-Reply-To: <20260706134716.3879-2-bestswngs@gmail.com>

>Subject: [PATCH net] tipc: serialize udp bearer replicast list updates
>
>tipc_udp_rcast_add() and cleanup_bearer() both update ub->rcast.list with
>list_add_rcu() / list_del_rcu(), but nothing serializes them. The add runs from
>the encap receive softirq (via tipc_udp_rcast_disc()) without rtnl_lock(), so it
>can race the cleanup delete and corrupt the
>list:
>
> list_del corruption. prev->next should be ffff8880298d7ab8,
>   but was ffff88802449ad38. (prev=ffff888027e3ec98)  kernel BUG at
>lib/list_debug.c:62!
> RIP: __list_del_entry_valid_or_report+0x17a/0x200
> Workqueue: events cleanup_bearer
> Call Trace:
>  cleanup_bearer (net/tipc/udp_media.c:811)
>  process_one_work (kernel/workqueue.c:3302)
>  worker_thread (kernel/workqueue.c:3466)
>
>The bearer can be enabled from an unprivileged user namespace, as the
>TIPCv2 generic-netlink ops carry no GENL_ADMIN_PERM.
>
>Add a spinlock and take it around both list updates. Re-check for the peer
>under the lock in the add path so the check-then-add in
>tipc_udp_rcast_disc() cannot insert a duplicate.
>
>Fixes: ef20cd4dd163 ("tipc: introduce UDP replicast")
>Reported-by: Xiang Mei <xmei5@asu.edu>
>Assisted-by: Claude:claude-opus-4-8
>Signed-off-by: Weiming Shi <bestswngs@gmail.com>
>---
> net/tipc/udp_media.c | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
>diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c index
>62ae7f5b5840..601174297a16 100644
>--- a/net/tipc/udp_media.c
>+++ b/net/tipc/udp_media.c
>@@ -94,6 +94,7 @@ struct udp_replicast {
>  * @ifindex:	local address scope
>  * @work:	used to schedule deferred work on a bearer
>  * @rcast:	associated udp_replicast container
>+ * @rcast_lock:	serializes updates to @rcast.list
>  */
> struct udp_bearer {
> 	struct tipc_bearer __rcu *bearer;
>@@ -101,6 +102,7 @@ struct udp_bearer {
> 	u32 ifindex;
> 	struct work_struct work;
> 	struct udp_replicast rcast;
>+	spinlock_t rcast_lock; /* protects rcast.list */
> };
>
> static int tipc_udp_is_mcast_addr(struct udp_media_addr *addr) @@ -301,7
>+303,7 @@ static bool tipc_udp_is_known_peer(struct tipc_bearer *b,  static
>int tipc_udp_rcast_add(struct tipc_bearer *b,
> 			      struct udp_media_addr *addr)
> {
>-	struct udp_replicast *rcast;
>+	struct udp_replicast *rcast, *tmp;
> 	struct udp_bearer *ub;
>
> 	ub = rcu_dereference_rtnl(b->media_ptr);
>@@ -319,6 +321,17 @@ static int tipc_udp_rcast_add(struct tipc_bearer *b,
>
> 	memcpy(&rcast->addr, addr, sizeof(struct udp_media_addr));
>
>+	/* tipc_udp_rcast_disc() adds from softirq without rtnl_lock(). */

Remove above comment because it is vague. Caller of tipc_udp_rcv() already holds rcu_read_lock().

>+	spin_lock_bh(&ub->rcast_lock);

Move 'spin_lock_bh(&ub->rcast_lock)' to above 'list_add_rcu(&rcast->list, &ub->rcast.list);' because only 'ub->rcast.list' needs protection.

>+	list_for_each_entry(tmp, &ub->rcast.list, list) {
>+		if (!memcmp(&tmp->addr, addr, sizeof(struct
>udp_media_addr))) {
>+			spin_unlock_bh(&ub->rcast_lock);
>+			dst_cache_destroy(&rcast->dst_cache);
>+			kfree(rcast);
>+			return 0;
>+		}
>+	}

This is wrong because the code in the loop is never executed. tipc_udp_is_known_peer() already verifies address duplication.
Please remove above code and fix tipc_udp_is_known_peer() as below:

static bool tipc_udp_is_known_peer(struct tipc_bearer *b,
                                   struct udp_media_addr *addr)
 {
-       struct udp_replicast *rcast, *tmp;
+       struct udp_replicast *rcast;
        struct udp_bearer *ub;
 
        ub = rcu_dereference_rtnl(b->media_ptr);
@@ -292,7 +292,7 @@ static bool tipc_udp_is_known_peer(struct tipc_bearer *b,
                return false;
        }
 
-       list_for_each_entry_safe(rcast, tmp, &ub->rcast.list, list) {
+       list_for_each_entry_rcu(rcast, &ub->rcast.list, list) {
                if (!memcmp(&rcast->addr, addr, sizeof(struct udp_media_addr)))
                        return true;
        }

>+
> 	if (ntohs(addr->proto) == ETH_P_IP)
> 		pr_info("New replicast peer: %pI4\n", &rcast->addr.ipv4);  #if
>IS_ENABLED(CONFIG_IPV6) @@ -327,6 +340,7 @@ static int
>tipc_udp_rcast_add(struct tipc_bearer *b,  #endif
> 	b->bcast_addr.broadcast = TIPC_REPLICAST_SUPPORT;
> 	list_add_rcu(&rcast->list, &ub->rcast.list);
>+	spin_unlock_bh(&ub->rcast_lock);
> 	return 0;
> }
>
>@@ -679,6 +693,7 @@ static int tipc_udp_enable(struct net *net, struct
>tipc_bearer *b,
> 		return -ENOMEM;
>
> 	INIT_LIST_HEAD(&ub->rcast.list);
>+	spin_lock_init(&ub->rcast_lock);
>
> 	if (!attrs[TIPC_NLA_BEARER_UDP_OPTS])
> 		goto err;
>@@ -819,10 +834,12 @@ static void cleanup_bearer(struct work_struct
>*work)
> 	struct udp_replicast *rcast, *tmp;
> 	struct tipc_net *tn;
>
>+	spin_lock_bh(&ub->rcast_lock);
> 	list_for_each_entry_safe(rcast, tmp, &ub->rcast.list, list) {
> 		list_del_rcu(&rcast->list);
> 		call_rcu_hurry(&rcast->rcu, rcast_free_rcu);
> 	}
>+	spin_unlock_bh(&ub->rcast_lock);
>
> 	tn = tipc_net(sock_net(ub->sk));
>
>--
>2.43.0
>


^ permalink raw reply

* Re: [PATCH net v4] net: airoha: fix MIB stats collection to be lossless
From: Aniket Negi @ 2026-07-07 13:21 UTC (permalink / raw)
  To: netdev, lorenzo; +Cc: aniket.negi
In-Reply-To: <akwczc23LOGbKfMl@lore-desk>

Hi Lorenzo,
Thanks for the review.

> > +	for (i = AIROHA_GDM1_IDX; i <= AIROHA_GDM4_IDX; i++)
> > +		airoha_fe_set(eth, REG_FE_GDM_MIB_CLEAR(i),
> > +			      FE_GDM_MIB_RX_CLEAR_MASK | FE_GDM_MIB_TX_CLEAR_MASK);
>
> This configuration is not needed since we reset FE at module load.

Agreed. The SCU FE reset clears MIB counters, so the explicit loop
is redundant. Will drop it in v5.

On Mon, 2 Jul 2026 22:59:32 +0000, Sashiko <sashiko@kernel.org> wrote:
> With this patch the driver no longer has any users of
> REG_FE_GDM_MIB_CLEAR, FE_GDM_MIB_RX_CLEAR_MASK or
> FE_GDM_MIB_TX_CLEAR_MASK; grep in drivers/net/ethernet/airoha/
> matches only the definitions in airoha_regs.h. Should these macros
> be removed in the same patch that eliminates their only caller?

What is your suggestions here, I prefer that definitions should 
be retained in airoha_regs.h as register documentation for future 
reference. Only the loop will be dropped.

> nit: tmp is not so meaningful, maybe better something like data?
> nit: I would prefer "+" instead of "|"
> nit: please drop prev and just do:
>       dev->stats.tx_ok_pkts = max(data, dev->stats.tx_ok_pkts);
> please redo it for all the occurrences.

Understood. Will rename tmp to data, and use '+' instead of '|' in v5.

Thanks,
Aniket

^ permalink raw reply

* Re: [PATCH net-next 1/2] geneve: convert config to RCU-protected pointer
From: Paolo Abeni @ 2026-07-07 13:15 UTC (permalink / raw)
  To: Eric Dumazet, David S . Miller, Jakub Kicinski
  Cc: Simon Horman, Kuniyuki Iwashima, Andrew Lunn, netdev,
	eric.dumazet
In-Reply-To: <20260701120454.3533252-2-edumazet@google.com>

On 7/1/26 2:04 PM, Eric Dumazet wrote:
> @@ -1137,21 +1144,22 @@ static int geneve_sock_add(struct geneve_dev *geneve, bool ipv6)
>  static int geneve_open(struct net_device *dev)
>  {
>  	struct geneve_dev *geneve = netdev_priv(dev);
> -	bool dualstack = geneve->cfg.dualstack;
> +	const struct geneve_config *cfg = rtnl_dereference(geneve->cfg);

Minor nit only mentioned because a repost is likely needed: here and in
a few other places the variable declaration order is not respected.

[...]
> @@ -1539,28 +1551,36 @@ static int geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
>  static netdev_tx_t geneve_xmit(struct sk_buff *skb, struct net_device *dev)
>  {
>  	struct geneve_dev *geneve = netdev_priv(dev);
> -	struct ip_tunnel_info *info = NULL;
> +	const struct ip_tunnel_info *info = NULL;
> +	const struct geneve_config *cfg;
>  	int err;
>  
> -	if (geneve->cfg.collect_md) {
> +	rcu_read_lock();
> +	cfg = rcu_dereference(geneve->cfg);
> +	if (unlikely(!cfg)) {

I also *think* the conditional is not needed here.

[...]
> @@ -1717,6 +1790,8 @@ static void geneve_setup(struct net_device *dev)
>  	dev->netdev_ops = &geneve_netdev_ops;
>  	dev->ethtool_ops = &geneve_ethtool_ops;
>  	dev->needs_free_netdev = true;
> +	dev->priv_destructor = geneve_free_dev;

Both sashikos point out this may cause double free.

Side note: I think that ideally it would be good to break this patch into 2:
- passing an explicit `const struct geneve_config *` argument where needed.
- doing the rcu conversion.

/P


^ permalink raw reply

* Re: [PATCH iwl-net v1] ice: use global queue index in TC to-queue offload
From: Simon Horman @ 2026-07-07 13:14 UTC (permalink / raw)
  To: Michal Swiatkowski; +Cc: intel-wired-lan, netdev, Aleksandr Loktionov
In-Reply-To: <20260629091203.36482-1-michal.swiatkowski@linux.intel.com>

On Mon, Jun 29, 2026 at 11:12:03AM +0200, Michal Swiatkowski wrote:
> Previously index within PF was used, which caused rules to fail on any PF
> other than PF0.
> 
> Switch to global queue index by adding first RX queue id from caps.
> 
> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
> Fixes: 143b86f346c7 ("ice: Enable RX queue selection using skbedit action")
> Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply

* [PATCH net-next 15/15] net/mlx5e: psp: Report PSP dev registration errors
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

mlx5e_psp_register() was forced to eat PSP dev registration errors as
the caller was not propagating them. Change this so PSP dev registration
failures get reported back to the caller instead.

After the recent changes in the series, PSP dev registration failures
will just leave some data structs in priv->psp (mostly counters), with
no steering rules and no means to configure them. There's no point
actively cleaning those up on failure, as they'll get removed during
profile->cleanup.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c | 8 +++++---
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h | 4 ++--
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c      | 8 +++++++-
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index b3521c3861f6..73b232379263 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -1028,14 +1028,14 @@ void mlx5e_psp_unregister(struct mlx5e_priv *priv)
 	psp->psd = NULL;
 }
 
-void mlx5e_psp_register(struct mlx5e_priv *priv)
+int mlx5e_psp_register(struct mlx5e_priv *priv)
 {
 	struct mlx5e_psp *psp = priv->psp;
 	struct psp_dev *psd;
 
 	/* FW Caps missing */
 	if (!priv->psp)
-		return;
+		return 0;
 
 	psp->caps.assoc_drv_spc = sizeof(u32);
 	psp->caps.versions = 1 << PSP_VERSION_HDR0_AES_GCM_128;
@@ -1047,9 +1047,11 @@ void mlx5e_psp_register(struct mlx5e_priv *priv)
 	if (IS_ERR(psd)) {
 		mlx5_core_err(priv->mdev, "PSP failed to register due to %pe\n",
 			      psd);
-		return;
+		return PTR_ERR(psd);
 	}
 	psp->psd = psd;
+
+	return 0;
 }
 
 int mlx5e_psp_init(struct mlx5e_priv *priv)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
index 57fffcf4a62c..3f441e7dd55a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
@@ -45,7 +45,7 @@ static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev)
 
 void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv);
 void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv);
-void mlx5e_psp_register(struct mlx5e_priv *priv);
+int mlx5e_psp_register(struct mlx5e_priv *priv);
 void mlx5e_psp_unregister(struct mlx5e_priv *priv);
 int mlx5e_psp_init(struct mlx5e_priv *priv);
 void mlx5e_psp_cleanup(struct mlx5e_priv *priv);
@@ -57,7 +57,7 @@ static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev)
 	return false;
 }
 
-static inline void mlx5e_psp_register(struct mlx5e_priv *priv) { }
+static inline int mlx5e_psp_register(struct mlx5e_priv *priv) { return 0; }
 static inline void mlx5e_psp_unregister(struct mlx5e_priv *priv) { }
 static inline int mlx5e_psp_init(struct mlx5e_priv *priv) { return 0; }
 static inline void mlx5e_psp_cleanup(struct mlx5e_priv *priv) { }
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 9eadd0b6f055..2cb48b24d5ea 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -6199,7 +6199,9 @@ static int mlx5e_nic_enable(struct mlx5e_priv *priv)
 
 	mlx5e_fs_init_l2_addr(priv->fs, netdev);
 	mlx5e_ipsec_init(priv);
-	mlx5e_psp_register(priv);
+	err = mlx5e_psp_register(priv);
+	if (err)
+		goto out_ipsec_cleanup;
 
 	err = mlx5e_macsec_init(priv);
 	if (err)
@@ -6237,6 +6239,10 @@ static int mlx5e_nic_enable(struct mlx5e_priv *priv)
 	rtnl_unlock();
 
 	return 0;
+
+out_ipsec_cleanup:
+	mlx5e_ipsec_cleanup(priv);
+	return err;
 }
 
 static void mlx5e_nic_disable(struct mlx5e_priv *priv)
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 14/15] net/mlx5e: Return errors from profile->enable
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

profile->enable is called before enabling an mlx5 netdevice and
currently doesn't return errors. Code called from it has to either:
1. eat errors and keep going, leaving a netdevice initialized with
   missing functionality
or
2. manually clean up things that other parts of the init flow might have
   set up.

Option 1 might be useful in some cases for optional functionality but
option 2 doesn't make for good design.

Add a 3rd option for code which wants to propagate errors from
profile->enable and fail netdev init. This change is a noop for now, the
first 'user' of this option 3 will be in the next patch.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en.h      |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 15 +++++++++++----
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c  |  8 ++++++--
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index 2270e2e550dd..3cc7283b6215 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -1016,7 +1016,7 @@ struct mlx5e_profile {
 	void	(*cleanup_rx)(struct mlx5e_priv *priv);
 	int	(*init_tx)(struct mlx5e_priv *priv);
 	void	(*cleanup_tx)(struct mlx5e_priv *priv);
-	void	(*enable)(struct mlx5e_priv *priv);
+	int	(*enable)(struct mlx5e_priv *priv);
 	void	(*disable)(struct mlx5e_priv *priv);
 	int	(*update_rx)(struct mlx5e_priv *priv);
 	void	(*update_stats)(struct mlx5e_priv *priv);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 775f0c6e55c9..9eadd0b6f055 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -6191,7 +6191,7 @@ static int mlx5e_init_nic_tx(struct mlx5e_priv *priv)
 	return 0;
 }
 
-static void mlx5e_nic_enable(struct mlx5e_priv *priv)
+static int mlx5e_nic_enable(struct mlx5e_priv *priv)
 {
 	struct net_device *netdev = priv->netdev;
 	struct mlx5_core_dev *mdev = priv->mdev;
@@ -6222,7 +6222,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
 	mlx5e_pcie_cong_event_init(priv);
 	mlx5e_hv_vhca_stats_create(priv);
 	if (netdev->reg_state != NETREG_REGISTERED)
-		return;
+		return 0;
 	mlx5e_dcbnl_init_app(priv);
 
 	mlx5e_nic_set_rx_mode(priv);
@@ -6235,6 +6235,8 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
 	netdev_unlock(netdev);
 	netif_device_attach(netdev);
 	rtnl_unlock();
+
+	return 0;
 }
 
 static void mlx5e_nic_disable(struct mlx5e_priv *priv)
@@ -6616,13 +6618,18 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv)
 	if (err)
 		goto err_cleanup_tx;
 
-	if (profile->enable)
-		profile->enable(priv);
+	if (profile->enable) {
+		err = profile->enable(priv);
+		if (err)
+			goto err_cleanup_rx;
+	}
 
 	mlx5e_update_features(priv->netdev);
 
 	return 0;
 
+err_cleanup_rx:
+	profile->cleanup_rx(priv);
 err_cleanup_tx:
 	profile->cleanup_tx(priv);
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index c8b76d301c92..603051ab1eaa 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -1262,9 +1262,11 @@ static void mlx5e_cleanup_rep_tx(struct mlx5e_priv *priv)
 	mlx5e_rep_neigh_cleanup(rpriv);
 }
 
-static void mlx5e_rep_enable(struct mlx5e_priv *priv)
+static int mlx5e_rep_enable(struct mlx5e_priv *priv)
 {
 	mlx5e_set_netdev_mtu_boundaries(priv);
+
+	return 0;
 }
 
 static void mlx5e_rep_disable(struct mlx5e_priv *priv)
@@ -1322,7 +1324,7 @@ static int uplink_rep_async_event(struct notifier_block *nb, unsigned long event
 	return NOTIFY_DONE;
 }
 
-static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)
+static int mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)
 {
 	struct net_device *netdev = priv->netdev;
 	struct mlx5_core_dev *mdev = priv->mdev;
@@ -1357,6 +1359,8 @@ static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv)
 	netdev_unlock(netdev);
 	netif_device_attach(netdev);
 	rtnl_unlock();
+
+	return 0;
 }
 
 static void mlx5e_uplink_rep_disable(struct mlx5e_priv *priv)
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 13/15] net/mlx5e: psp: Make PSP steering config dynamic
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

Only create PSP steering tables when PSP configuration is enabled on a
PSP device.

Previously, mlx5e_psp_set_config (== .set_config on the PSP device) did
nothing. Steering was created and hooked up to incoming traffic at
device initialization time, via mlx5e_init_nic_rx -> mlx5e_accel_init_rx
-> mlx5_accel_psp_fs_init_rx_tables. Similarly, TX tables were created
and hooked to egress traffic at mlx5e_init_nic_tx -> mlx5e_accel_init_tx
-> mlx5_accel_psp_fs_init_tx_tables

Doing this means both ingress and egress UDP packets go through the
PSP steering tables, causing extra latency and overhead.
A better solution is to let the incoming encrypted PSP packets get
dropped by SW and not impose an overhead on all UDP packets which have
to traverse the PSP steering rules when PSP isn't used.

Additionally, upcoming changes to support HW-GRO need to reconfigure PSP
steering dynamically and this patch is a necessary step in that
direction.

Two new functions are defined:
- accel_psp_fs_create: Creates steering tables and connects RX UDP v4/v6
  traffic to PSP RX tables.
- accel_psp_fs_destroy: Disconnects incoming RX traffic from PSP
  steering and destroys steering tables.

PSP steering cleanup, which happens independently from PSP device
configuration, is unchanged. When the device is going away, steering
tables are destroyed as well.

The netdev lock is now used for proper synchronization between the new
set_config flow and device steering init/cleanup. This will be important
in future patches, when PSP will be able to reconfigure itself
dynamically upon netdev feature changes.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/en_accel.h    | 19 +----
 .../mellanox/mlx5/core/en_accel/psp.c         | 73 +++++++++++++------
 .../mellanox/mlx5/core/en_accel/psp.h         | 12 ---
 3 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h
index b526b3898c22..3f212e46fc2f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h
@@ -220,18 +220,7 @@ static inline void mlx5e_accel_tx_finish(struct mlx5e_txqsq *sq,
 
 static inline int mlx5e_accel_init_rx(struct mlx5e_priv *priv)
 {
-	int err;
-
-	err = mlx5_accel_psp_fs_init_rx_tables(priv);
-	if (err)
-		goto out;
-
-	err = mlx5e_ktls_init_rx(priv);
-	if (err)
-		mlx5_accel_psp_fs_cleanup_rx_tables(priv);
-
-out:
-	return err;
+	return mlx5e_ktls_init_rx(priv);
 }
 
 static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv)
@@ -242,12 +231,6 @@ static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv)
 
 static inline int mlx5e_accel_init_tx(struct mlx5e_priv *priv)
 {
-	int err;
-
-	err = mlx5_accel_psp_fs_init_tx_tables(priv);
-	if (err)
-		return err;
-
 	return mlx5e_ktls_init_tx(priv);
 }
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index b713f235a0f7..b3521c3861f6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -537,18 +537,24 @@ static void accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs)
 	accel_psp_fs_rx_ft_destroy(&fs->rx);
 }
 
-static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs)
+static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs,
+				  struct netlink_ext_ack *extack)
 {
 	struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false);
 	int i, err;
 
 	err = accel_psp_fs_rx_ft_create(fs, &fs->rx);
-	if (err)
+	if (err) {
+		NL_SET_ERR_MSG(extack, "Failed creating RX steering table");
 		return err;
+	}
 
 	err = accel_psp_fs_rx_check_ft_create(fs, &fs->check);
-	if (err)
+	if (err) {
+		NL_SET_ERR_MSG(extack,
+			       "Failed creating RX check steering table");
 		goto err_ft;
+	}
 
 	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
 		struct mlx5_flow_destination dest;
@@ -556,8 +562,11 @@ static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs)
 		dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(i));
 		err = accel_psp_fs_rx_decrypt_ft_create(fs, &fs->decrypt[i],
 							&dest);
-		if (err)
+		if (err) {
+			NL_SET_ERR_MSG(extack,
+				       "Failed creating RX decrypt steering table");
 			goto err_decrypt_ft;
+		}
 
 		dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
 		dest.ft = fs->decrypt[i].ft;
@@ -634,15 +643,9 @@ void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv)
 	if (!priv->psp)
 		return;
 
+	netdev_lock(priv->netdev);
 	accel_psp_fs_rx_destroy(priv->psp->fs);
-}
-
-int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
-{
-	if (!priv->psp)
-		return 0;
-
-	return accel_psp_fs_rx_create(priv->psp->fs);
+	netdev_unlock(priv->netdev);
 }
 
 static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs,
@@ -791,15 +794,9 @@ void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv)
 	if (!priv->psp)
 		return;
 
+	netdev_lock(priv->netdev);
 	accel_psp_fs_tx_ft_destroy(&priv->psp->fs->tx);
-}
-
-int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
-{
-	if (!priv->psp)
-		return 0;
-
-	return accel_psp_fs_tx_ft_create(priv->psp->fs, &priv->psp->fs->tx);
+	netdev_unlock(priv->netdev);
 }
 
 static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs)
@@ -837,11 +834,45 @@ static struct mlx5e_psp_fs *mlx5e_accel_psp_fs_init(struct mlx5e_priv *priv)
 	return ERR_PTR(err);
 }
 
+static int accel_psp_fs_create(struct mlx5e_priv *priv,
+			       struct netlink_ext_ack *extack)
+{
+	int err;
+
+	err = accel_psp_fs_rx_create(priv->psp->fs, extack);
+	if (err)
+		return err;
+
+	err = accel_psp_fs_tx_ft_create(priv->psp->fs, &priv->psp->fs->tx);
+	if (err) {
+		NL_SET_ERR_MSG(extack, "Failed creating TX steering table");
+		accel_psp_fs_rx_destroy(priv->psp->fs);
+	}
+	return err;
+}
+
+static void accel_psp_fs_destroy(struct mlx5e_priv *priv)
+{
+	accel_psp_fs_tx_ft_destroy(&priv->psp->fs->tx);
+	accel_psp_fs_rx_destroy(priv->psp->fs);
+}
+
 static int
 mlx5e_psp_set_config(struct psp_dev *psd, struct psp_dev_config *conf,
 		     struct netlink_ext_ack *extack)
 {
-	return 0; /* TODO: this should actually do things to the device */
+	struct mlx5e_priv *priv = netdev_priv(psd->main_netdev);
+	bool psp_enabled = psd->config.versions;
+	bool enable_psp = conf->versions;
+	int err = 0;
+
+	netdev_lock(priv->netdev);
+	if (!psp_enabled && enable_psp)
+		err = accel_psp_fs_create(priv, extack);
+	else if (psp_enabled && !enable_psp)
+		accel_psp_fs_destroy(priv);
+	netdev_unlock(priv->netdev);
+	return err;
 }
 
 static int
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
index a53f90f7c341..57fffcf4a62c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
@@ -43,26 +43,14 @@ static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev)
 	return true;
 }
 
-int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv);
 void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv);
-int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv);
 void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv);
 void mlx5e_psp_register(struct mlx5e_priv *priv);
 void mlx5e_psp_unregister(struct mlx5e_priv *priv);
 int mlx5e_psp_init(struct mlx5e_priv *priv);
 void mlx5e_psp_cleanup(struct mlx5e_priv *priv);
 #else
-static inline int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
-{
-	return 0;
-}
-
 static inline void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv) { }
-static inline int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
-{
-	return 0;
-}
-
 static inline void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv) { }
 static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev)
 {
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 12/15] net/mlx5e: psp: Flatten steering structures
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

PSP steering code has two dynamically allocated structures to store RX
and TX steering structs. Remove those and flatten out everything into
the parent mlx5e_psp_fs.
The tx_counter was moved out of the TX table as well, because the table
doesn't own it, it outlives TX table destruction.

All table creation/destruction now happens in
accel_psp_fs_{rx,tx}_{create,destroy}. This will be used in subsequent
patches to make PSP configuration dynamic.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 257 +++++++-----------
 1 file changed, 97 insertions(+), 160 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index 48bc59045dfe..b713f235a0f7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -26,7 +26,6 @@ struct mlx5e_psp_tx_table {
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_group *fg;
 	struct mlx5_flow_handle *rule;
-	struct mlx5_fc *tx_counter;
 };
 
 struct mlx5e_psp_rx_check_table {
@@ -46,14 +45,6 @@ struct mlx5e_psp_rx_decrypt_table {
 	struct mlx5_flow_handle *rule;
 };
 
-struct mlx5e_psp_rx {
-	struct mlx5e_psp_rx_decrypt_table decrypt[ACCEL_FS_PSP_NUM_TYPES];
-	struct mlx5_fc *rx_counter;
-	struct mlx5_fc *rx_auth_fail_counter;
-	struct mlx5_fc *rx_err_counter;
-	struct mlx5_fc *rx_bad_counter;
-};
-
 struct mlx5e_psp_rx_table {
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_group *miss_group;
@@ -63,11 +54,17 @@ struct mlx5e_psp_rx_table {
 
 struct mlx5e_psp_fs {
 	struct mlx5_core_dev *mdev;
-	struct mlx5e_psp_tx_table *tx_fs;
-	/* Rx manage */
+	struct mlx5_fc *tx_counter;
+	struct mlx5e_psp_tx_table tx;
+
+	/* Rx */
 	struct mlx5e_flow_steering *fs;
-	struct mlx5e_psp_rx *rx_fs;
+	struct mlx5_fc *rx_counter;
+	struct mlx5_fc *rx_auth_fail_counter;
+	struct mlx5_fc *rx_err_counter;
+	struct mlx5_fc *rx_bad_counter;
 
+	struct mlx5e_psp_rx_decrypt_table decrypt[ACCEL_FS_PSP_NUM_TYPES];
 	struct mlx5e_psp_rx_check_table check;
 	struct mlx5e_psp_rx_table rx;
 };
@@ -217,7 +214,7 @@ static int accel_psp_fs_rx_ft_create(struct mlx5e_psp_fs *fs,
 	dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
 	dest[0].ft = mlx5_get_ttc_flow_table(ttc);
 	dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-	dest[1].counter = fs->rx_fs->rx_counter;
+	dest[1].counter = fs->rx_counter;
 	rule = mlx5_add_flow_rules(rx->ft, NULL, &flow_act, dest, 2);
 	if (IS_ERR(rule)) {
 		err = PTR_ERR(rule);
@@ -245,7 +242,7 @@ static int accel_psp_fs_rx_ft_create(struct mlx5e_psp_fs *fs,
 			 outer_headers.ip_version, version);
 		dest[0] = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(i));
 		dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-		dest[1].counter = fs->rx_fs->rx_counter;
+		dest[1].counter = fs->rx_counter;
 		rule = mlx5_add_flow_rules(rx->ft, spec, &flow_act, dest,
 					   2);
 		if (IS_ERR(rule)) {
@@ -364,7 +361,7 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
 	memset(spec, 0, sizeof(*spec));
 	accel_psp_setup_syndrome_match(spec, PSP_ICV_FAIL);
 	err = accel_psp_add_drop_rule(check->ft, spec,
-				      fs->rx_fs->rx_auth_fail_counter,
+				      fs->rx_auth_fail_counter,
 				      &check->auth_fail_rule);
 	if (err) {
 		mlx5_core_err(mdev,
@@ -376,8 +373,7 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
 	/* add framing drop rule */
 	memset(spec, 0, sizeof(*spec));
 	accel_psp_setup_syndrome_match(spec, PSP_BAD_TRAILER);
-	err = accel_psp_add_drop_rule(check->ft, spec,
-				      fs->rx_fs->rx_err_counter,
+	err = accel_psp_add_drop_rule(check->ft, spec, fs->rx_err_counter,
 				      &check->err_rule);
 	if (err) {
 		mlx5_core_err(mdev,
@@ -388,8 +384,7 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
 
 	/* add misc. errors drop rule */
 	memset(spec, 0, sizeof(*spec));
-	err = accel_psp_add_drop_rule(check->ft, spec,
-				      fs->rx_fs->rx_bad_counter,
+	err = accel_psp_add_drop_rule(check->ft, spec, fs->rx_bad_counter,
 				      &check->bad_rule);
 	if (err) {
 		mlx5_core_err(mdev,
@@ -528,46 +523,66 @@ accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs,
 	return err;
 }
 
-static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs,
-				   enum accel_fs_psp_type type)
+static void accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs)
 {
-	struct mlx5e_psp_rx_decrypt_table *decrypt;
-	struct mlx5e_psp_rx *rx_fs = fs->rx_fs;
-
-	/* The netdev unreg already happened, so all offloaded rule are already removed */
-	decrypt = &rx_fs->decrypt[type];
-
-	accel_psp_fs_rx_decrypt_ft_destroy(fs, decrypt);
+	struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false);
+	int i;
 
-	return 0;
+	/* disconnect */
+	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
+		mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i));
+		accel_psp_fs_rx_decrypt_ft_destroy(fs, &fs->decrypt[i]);
+	}
+	accel_psp_fs_rx_check_ft_destroy(&fs->check);
+	accel_psp_fs_rx_ft_destroy(&fs->rx);
 }
 
-static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type)
+static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs)
 {
 	struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false);
-	struct mlx5e_psp_rx_decrypt_table *decrypt;
-	struct mlx5e_psp_rx *rx_fs = fs->rx_fs;
-	struct mlx5_flow_destination dest = {};
+	int i, err;
+
+	err = accel_psp_fs_rx_ft_create(fs, &fs->rx);
+	if (err)
+		return err;
+
+	err = accel_psp_fs_rx_check_ft_create(fs, &fs->check);
+	if (err)
+		goto err_ft;
+
+	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
+		struct mlx5_flow_destination dest;
 
-	decrypt = &rx_fs->decrypt[type];
+		dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(i));
+		err = accel_psp_fs_rx_decrypt_ft_create(fs, &fs->decrypt[i],
+							&dest);
+		if (err)
+			goto err_decrypt_ft;
+
+		dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
+		dest.ft = fs->decrypt[i].ft;
+		mlx5_ttc_fwd_dest(ttc, fs_psp2tt(i), &dest);
+	}
+
+	return 0;
 
-	dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(type));
-	return accel_psp_fs_rx_decrypt_ft_create(fs, decrypt, &dest);
+err_decrypt_ft:
+	while (--i >= 0) {
+		mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i));
+		accel_psp_fs_rx_decrypt_ft_destroy(fs, &fs->decrypt[i]);
+	}
+	accel_psp_fs_rx_check_ft_destroy(&fs->check);
+err_ft:
+	accel_psp_fs_rx_ft_destroy(&fs->rx);
+	return err;
 }
 
 static void accel_psp_fs_rx_cleanup(struct mlx5e_psp_fs *fs)
 {
-	struct mlx5e_psp_rx *rx_fs = fs->rx_fs;
-
-	if (!rx_fs)
-		return;
-
-	accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_bad_counter);
-	accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_err_counter);
-	accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_auth_fail_counter);
-	accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_counter);
-	kfree(rx_fs);
-	fs->rx_fs = NULL;
+	accel_psp_fs_destroy_counter(fs->mdev, &fs->rx_bad_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &fs->rx_err_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &fs->rx_auth_fail_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &fs->rx_counter);
 }
 
 static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs)
@@ -575,11 +590,7 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs)
 	struct mlx5_core_dev *mdev = fs->mdev;
 	int err;
 
-	fs->rx_fs = kzalloc_obj(*fs->rx_fs);
-	if (!fs->rx_fs)
-		return -ENOMEM;
-
-	err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_counter);
+	err = accel_psp_fs_create_counter(mdev, &fs->rx_counter);
 	if (err) {
 		mlx5_core_warn(mdev,
 			       "fail to create psp rx flow counter err=%d\n",
@@ -587,8 +598,7 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs)
 		goto out_err;
 	}
 
-	err = accel_psp_fs_create_counter(mdev,
-					  &fs->rx_fs->rx_auth_fail_counter);
+	err = accel_psp_fs_create_counter(mdev, &fs->rx_auth_fail_counter);
 	if (err) {
 		mlx5_core_warn(mdev,
 			       "fail to create psp rx auth fail flow counter err=%d\n",
@@ -596,7 +606,7 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs)
 		goto out_err;
 	}
 
-	err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_err_counter);
+	err = accel_psp_fs_create_counter(mdev, &fs->rx_err_counter);
 	if (err) {
 		mlx5_core_warn(mdev,
 			       "fail to create psp rx error flow counter err=%d\n",
@@ -604,7 +614,7 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs)
 		goto out_err;
 	}
 
-	err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_bad_counter);
+	err = accel_psp_fs_create_counter(mdev, &fs->rx_bad_counter);
 	if (err) {
 		mlx5_core_warn(mdev,
 			       "fail to create psp rx bad flow counter err=%d\n",
@@ -621,84 +631,28 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs)
 
 void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv)
 {
-	struct mlx5_ttc_table *ttc;
-	struct mlx5e_psp_fs *fs;
-	int i;
-
 	if (!priv->psp)
 		return;
 
-	fs = priv->psp->fs;
-	ttc = mlx5e_fs_get_ttc(fs->fs, false);
-	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
-		/* disconnect */
-		mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i));
-
-		/* remove FT */
-		accel_psp_fs_rx_destroy(fs, i);
-	}
-	accel_psp_fs_rx_check_ft_destroy(&fs->check);
-	accel_psp_fs_rx_ft_destroy(&priv->psp->fs->rx);
+	accel_psp_fs_rx_destroy(priv->psp->fs);
 }
 
 int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 {
-	struct mlx5_ttc_table *ttc;
-	struct mlx5e_psp_fs *fs;
-	int err, i;
-
 	if (!priv->psp)
 		return 0;
 
-	fs = priv->psp->fs;
-	ttc = mlx5e_fs_get_ttc(fs->fs, false);
-
-	err = accel_psp_fs_rx_ft_create(fs, &fs->rx);
-	if (err)
-		return err;
-
-	err = accel_psp_fs_rx_check_ft_create(fs, &fs->check);
-	if (err)
-		goto err_ft;
-
-	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
-		struct mlx5e_psp_rx_decrypt_table *decrypt;
-		struct mlx5_flow_destination dest = {};
-
-		/* create FT */
-		err = accel_psp_fs_rx_create(fs, i);
-		if (err)
-			goto out_err;
-
-		/* connect */
-		dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
-		decrypt = &fs->rx_fs->decrypt[i];
-		dest.ft = decrypt->ft;
-		mlx5_ttc_fwd_dest(ttc, fs_psp2tt(i), &dest);
-	}
-
-	return 0;
-
-out_err:
-	while (--i >= 0) {
-		mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i));
-		accel_psp_fs_rx_destroy(fs, i);
-	}
-	accel_psp_fs_rx_check_ft_destroy(&fs->check);
-err_ft:
-	accel_psp_fs_rx_ft_destroy(&fs->rx);
-
-	return err;
+	return accel_psp_fs_rx_create(priv->psp->fs);
 }
 
-static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs)
+static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs,
+				     struct mlx5e_psp_tx_table *tx)
 {
 	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
 	struct mlx5_flow_table_attr ft_attr = {};
 	struct mlx5_flow_destination dest = {};
 	struct mlx5_core_dev *mdev = fs->mdev;
 	struct mlx5_flow_act flow_act = {};
-	struct mlx5e_psp_tx_table *tx_fs;
 	u32 *in, *mc, *outer_headers_c;
 	struct mlx5_flow_handle *rule;
 	struct mlx5_flow_spec *spec;
@@ -720,8 +674,7 @@ static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs)
 	ft_attr.level = MLX5E_PSP_LEVEL;
 	ft_attr.autogroup.max_num_groups = 1;
 
-	tx_fs = fs->tx_fs;
-	ft = mlx5_create_flow_table(tx_fs->ns, &ft_attr);
+	ft = mlx5_create_flow_table(tx->ns, &ft_attr);
 	if (IS_ERR(ft)) {
 		err = PTR_ERR(ft);
 		mlx5_core_err(mdev, "PSP: fail to add psp tx flow table, err = %d\n", err);
@@ -747,7 +700,7 @@ static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs)
 			  MLX5_FLOW_CONTEXT_ACTION_CRYPTO_ENCRYPT |
 			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
 	dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-	dest.counter = tx_fs->tx_counter;
+	dest.counter = fs->tx_counter;
 	rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
 	if (IS_ERR(rule)) {
 		err = PTR_ERR(rule);
@@ -755,9 +708,9 @@ static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs)
 		goto err_add_flow_rule;
 	}
 
-	tx_fs->ft = ft;
-	tx_fs->fg = fg;
-	tx_fs->rule = rule;
+	tx->ft = ft;
+	tx->fg = fg;
+	tx->rule = rule;
 	goto out;
 
 err_add_flow_rule:
@@ -770,50 +723,35 @@ static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs)
 	return err;
 }
 
-static void accel_psp_fs_tx_ft_destroy(struct mlx5e_psp_tx_table *tx_fs)
+static void accel_psp_fs_tx_ft_destroy(struct mlx5e_psp_tx_table *tx)
 {
-	accel_psp_fs_del_flow_rule(&tx_fs->rule);
-	accel_psp_fs_destroy_flow_group(&tx_fs->fg);
-	accel_psp_fs_destroy_ft(&tx_fs->ft);
+	accel_psp_fs_del_flow_rule(&tx->rule);
+	accel_psp_fs_destroy_flow_group(&tx->fg);
+	accel_psp_fs_destroy_ft(&tx->ft);
 }
 
 static void accel_psp_fs_tx_cleanup(struct mlx5e_psp_fs *fs)
 {
-	struct mlx5e_psp_tx_table *tx_fs = fs->tx_fs;
-
-	if (!tx_fs)
-		return;
-
-	accel_psp_fs_destroy_counter(fs->mdev, &tx_fs->tx_counter);
-	kfree(tx_fs);
-	fs->tx_fs = NULL;
+	accel_psp_fs_destroy_counter(fs->mdev, &fs->tx_counter);
 }
 
 static int accel_psp_fs_tx_init(struct mlx5e_psp_fs *fs)
 {
 	struct mlx5_core_dev *mdev = fs->mdev;
-	struct mlx5e_psp_tx_table *tx_fs;
-	struct mlx5_flow_namespace *ns;
 	int err;
 
-	ns = mlx5_get_flow_namespace(mdev, MLX5_FLOW_NAMESPACE_EGRESS_IPSEC);
-	if (!ns)
+	fs->tx.ns = mlx5_get_flow_namespace(mdev,
+					    MLX5_FLOW_NAMESPACE_EGRESS_IPSEC);
+	if (!fs->tx.ns)
 		return -EOPNOTSUPP;
 
-	tx_fs = kzalloc_obj(*tx_fs);
-	if (!tx_fs)
-		return -ENOMEM;
-
-	err = accel_psp_fs_create_counter(mdev, &tx_fs->tx_counter);
+	err = accel_psp_fs_create_counter(mdev, &fs->tx_counter);
 	if (err) {
 		mlx5_core_warn(mdev,
 			       "fail to create psp tx flow counter err=%d\n",
 			       err);
-		kfree(tx_fs);
 		return err;
 	}
-	tx_fs->ns = ns;
-	fs->tx_fs = tx_fs;
 	return 0;
 }
 
@@ -821,30 +759,29 @@ static void
 mlx5e_accel_psp_fs_get_stats_fill(struct mlx5e_priv *priv,
 				  struct mlx5e_psp_stats *stats)
 {
-	struct mlx5e_psp_tx_table *tx_fs = priv->psp->fs->tx_fs;
-	struct mlx5e_psp_rx *rx_fs = priv->psp->fs->rx_fs;
+	struct mlx5e_psp_fs *fs = priv->psp->fs;
 	struct mlx5_core_dev *mdev = priv->mdev;
 
-	if (tx_fs->tx_counter)
-		mlx5_fc_query(mdev, tx_fs->tx_counter, &stats->psp_tx_pkts,
+	if (fs->tx_counter)
+		mlx5_fc_query(mdev, fs->tx_counter, &stats->psp_tx_pkts,
 			      &stats->psp_tx_bytes);
 
-	if (rx_fs->rx_counter)
-		mlx5_fc_query(mdev, rx_fs->rx_counter, &stats->psp_rx_pkts,
+	if (fs->rx_counter)
+		mlx5_fc_query(mdev, fs->rx_counter, &stats->psp_rx_pkts,
 			      &stats->psp_rx_bytes);
 
-	if (rx_fs->rx_auth_fail_counter)
-		mlx5_fc_query(mdev, rx_fs->rx_auth_fail_counter,
+	if (fs->rx_auth_fail_counter)
+		mlx5_fc_query(mdev, fs->rx_auth_fail_counter,
 			      &stats->psp_rx_pkts_auth_fail,
 			      &stats->psp_rx_bytes_auth_fail);
 
-	if (rx_fs->rx_err_counter)
-		mlx5_fc_query(mdev, rx_fs->rx_err_counter,
+	if (fs->rx_err_counter)
+		mlx5_fc_query(mdev, fs->rx_err_counter,
 			      &stats->psp_rx_pkts_frame_err,
 			      &stats->psp_rx_bytes_frame_err);
 
-	if (rx_fs->rx_bad_counter)
-		mlx5_fc_query(mdev, rx_fs->rx_bad_counter,
+	if (fs->rx_bad_counter)
+		mlx5_fc_query(mdev, fs->rx_bad_counter,
 			      &stats->psp_rx_pkts_drop,
 			      &stats->psp_rx_bytes_drop);
 }
@@ -854,7 +791,7 @@ void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv)
 	if (!priv->psp)
 		return;
 
-	accel_psp_fs_tx_ft_destroy(priv->psp->fs->tx_fs);
+	accel_psp_fs_tx_ft_destroy(&priv->psp->fs->tx);
 }
 
 int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
@@ -862,7 +799,7 @@ int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
 	if (!priv->psp)
 		return 0;
 
-	return accel_psp_fs_tx_ft_create(priv->psp->fs);
+	return accel_psp_fs_tx_ft_create(priv->psp->fs, &priv->psp->fs->tx);
 }
 
 static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs)
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 11/15] net/mlx5e: psp: Use a single rx_check table
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

PSP uses a check steering table per IP version, but the PSP rules are
IP-version agnostic, so there's no point duplicating these in HW.

This commit makes the rx check steering table independent of the IP
version, with the final table added in the previous patch responsible
for directing packets to the corresponding UDP TIRs (or the TTC table
itself for non-UDP traffic).

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 34 +++++++------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index c45241025b16..48bc59045dfe 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -43,7 +43,6 @@ struct mlx5e_psp_rx_decrypt_table {
 	struct mlx5_flow_group *miss_group;
 	struct mlx5_flow_handle *miss_rule;
 	struct mlx5_modify_hdr *rx_modify_hdr;
-	struct mlx5e_psp_rx_check_table check;
 	struct mlx5_flow_handle *rule;
 };
 
@@ -69,6 +68,7 @@ struct mlx5e_psp_fs {
 	struct mlx5e_flow_steering *fs;
 	struct mlx5e_psp_rx *rx_fs;
 
+	struct mlx5e_psp_rx_check_table check;
 	struct mlx5e_psp_rx_table rx;
 };
 
@@ -267,8 +267,7 @@ static int accel_psp_fs_rx_ft_create(struct mlx5e_psp_fs *fs,
 }
 
 static
-void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_fs *fs,
-				      struct mlx5e_psp_rx_check_table *check)
+void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_rx_check_table *check)
 {
 	accel_psp_fs_del_flow_rule(&check->bad_rule);
 	accel_psp_fs_del_flow_rule(&check->err_rule);
@@ -402,13 +401,12 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
 	goto out_spec;
 
 out_err:
-	accel_psp_fs_rx_check_ft_destroy(fs, check);
+	accel_psp_fs_rx_check_ft_destroy(check);
 out_spec:
 	kfree(spec);
 	return err;
 }
 
-
 static void
 accel_psp_fs_rx_decrypt_ft_destroy(struct mlx5e_psp_fs *fs,
 				   struct mlx5e_psp_rx_decrypt_table *decrypt)
@@ -511,7 +509,7 @@ accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs,
 			  MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
 	flow_act.modify_hdr = modify_hdr;
 	dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
-	dest.ft = decrypt->check.ft;
+	dest.ft = fs->check.ft;
 	rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act, &dest, 1);
 	if (IS_ERR(rule)) {
 		err = PTR_ERR(rule);
@@ -541,8 +539,6 @@ static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs,
 
 	accel_psp_fs_rx_decrypt_ft_destroy(fs, decrypt);
 
-	accel_psp_fs_rx_check_ft_destroy(fs, &decrypt->check);
-
 	return 0;
 }
 
@@ -552,24 +548,11 @@ static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ
 	struct mlx5e_psp_rx_decrypt_table *decrypt;
 	struct mlx5e_psp_rx *rx_fs = fs->rx_fs;
 	struct mlx5_flow_destination dest = {};
-	int err;
 
 	decrypt = &rx_fs->decrypt[type];
 
-	err = accel_psp_fs_rx_check_ft_create(fs, &decrypt->check);
-	if (err)
-		return err;
-
 	dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(type));
-	err = accel_psp_fs_rx_decrypt_ft_create(fs, decrypt, &dest);
-	if (err)
-		goto out_err_ft;
-
-	return 0;
-
-out_err_ft:
-	accel_psp_fs_rx_check_ft_destroy(fs, &decrypt->check);
-	return err;
+	return accel_psp_fs_rx_decrypt_ft_create(fs, decrypt, &dest);
 }
 
 static void accel_psp_fs_rx_cleanup(struct mlx5e_psp_fs *fs)
@@ -654,6 +637,7 @@ void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv)
 		/* remove FT */
 		accel_psp_fs_rx_destroy(fs, i);
 	}
+	accel_psp_fs_rx_check_ft_destroy(&fs->check);
 	accel_psp_fs_rx_ft_destroy(&priv->psp->fs->rx);
 }
 
@@ -673,6 +657,10 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 	if (err)
 		return err;
 
+	err = accel_psp_fs_rx_check_ft_create(fs, &fs->check);
+	if (err)
+		goto err_ft;
+
 	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
 		struct mlx5e_psp_rx_decrypt_table *decrypt;
 		struct mlx5_flow_destination dest = {};
@@ -696,6 +684,8 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 		mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i));
 		accel_psp_fs_rx_destroy(fs, i);
 	}
+	accel_psp_fs_rx_check_ft_destroy(&fs->check);
+err_ft:
 	accel_psp_fs_rx_ft_destroy(&fs->rx);
 
 	return err;
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 09/15] net/mlx5e: psp: Adjust rx_check FT size and use a drop_group
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

The rx_check ft was requesting max_fte == 2, but it created 4 entries.
While this accidentally works, it's not accurate, so change that and use
the correct number of entries. Also use an explicit drop_group for the
last match(*) drop rule.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_accel/psp.c  | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index c83d62724ff7..f8b289c50a42 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -31,6 +31,7 @@ struct mlx5e_psp_tx_table {
 
 struct mlx5e_psp_rx_check_table {
 	struct mlx5_flow_table *ft;
+	struct mlx5_flow_group *drop_group;
 	struct mlx5_flow_handle *rule;
 	struct mlx5_flow_handle *auth_fail_rule;
 	struct mlx5_flow_handle *err_rule;
@@ -165,6 +166,7 @@ void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_fs *fs,
 	accel_psp_fs_del_flow_rule(&check->err_rule);
 	accel_psp_fs_del_flow_rule(&check->auth_fail_rule);
 	accel_psp_fs_del_flow_rule(&check->rule);
+	accel_psp_fs_destroy_flow_group(&check->drop_group);
 	accel_psp_fs_destroy_ft(&check->ft);
 }
 
@@ -218,7 +220,8 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
 	if (!spec)
 		return -ENOMEM;
 
-	ft_attr.max_fte = 2;
+	ft_attr.max_fte = 4;
+	ft_attr.autogroup.num_reserved_entries = 1;
 	ft_attr.autogroup.max_num_groups = 2;
 	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL;
 	ft_attr.prio = MLX5E_NIC_PRIO;
@@ -229,6 +232,14 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
 		goto out_err;
 	}
 
+	err = accel_psp_fs_create_miss_group(check->ft, &check->drop_group);
+	if (err) {
+		mlx5_core_err(fs->mdev,
+			      "fail to create psp rx check drop group err=%d\n",
+			      err);
+		goto out_err;
+	}
+
 	accel_psp_setup_syndrome_match(spec, PSP_OK);
 	/* create fte */
 	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 10/15] net/mlx5e: psp: Add an RX steering table
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

Successfully decrypted PSP traffic is currently forwarded to the UDP
v4/v6 TTC default destination from its respective PSP rx_check table.

In preparation for flattening out RX steering and for decapsulation
support (which needs to handle non-UDP traffic as well), add an RX table
which directs traffic to either the UDP v4/v6 default TTC destinations,
or back to the TTC table itself for further processing. There can be no
loops as non-UDP traffic will not go through PSP processing again.

This is now used as a destination for successfully decrypted PSP
packets. The rx_counter is also incremented there, freeing the rx_check
rule for PSP_OK for atomic destination update in a future patch.

Use this opportunity to separate RX flow table levels from IPsec, as
reusing random IPsec ft levels as PSP isn't clear and now is a good
opportunity to separate them.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |   7 +-
 .../mellanox/mlx5/core/en_accel/psp.c         | 149 +++++++++++++++---
 2 files changed, 136 insertions(+), 20 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
index 091b80a67189..4973fb473ff0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
@@ -88,13 +88,18 @@ enum {
 #ifdef CONFIG_MLX5_EN_ARFS
 	MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
 #endif
-#if defined(CONFIG_MLX5_EN_IPSEC) || defined(CONFIG_MLX5_EN_PSP)
+#if defined(CONFIG_MLX5_EN_IPSEC)
 	MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
 	MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
 	MLX5E_ACCEL_FS_POL_FT_LEVEL,
 	MLX5E_ACCEL_FS_POL_MISS_FT_LEVEL,
 	MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL,
 #endif
+#if defined(CONFIG_MLX5_EN_PSP)
+	MLX5E_ACCEL_FS_PSP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
+	MLX5E_ACCEL_FS_PSP_ERR_FT_LEVEL,
+	MLX5E_ACCEL_FS_PSP_RX_FT_LEVEL,
+#endif
 };
 
 struct mlx5e_flow_steering;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index f8b289c50a42..c45241025b16 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -43,7 +43,6 @@ struct mlx5e_psp_rx_decrypt_table {
 	struct mlx5_flow_group *miss_group;
 	struct mlx5_flow_handle *miss_rule;
 	struct mlx5_modify_hdr *rx_modify_hdr;
-	struct mlx5_flow_destination default_dest;
 	struct mlx5e_psp_rx_check_table check;
 	struct mlx5_flow_handle *rule;
 };
@@ -56,12 +55,21 @@ struct mlx5e_psp_rx {
 	struct mlx5_fc *rx_bad_counter;
 };
 
+struct mlx5e_psp_rx_table {
+	struct mlx5_flow_table *ft;
+	struct mlx5_flow_group *miss_group;
+	struct mlx5_flow_handle *miss_rule;
+	struct mlx5_flow_handle *udp_rules[ACCEL_FS_PSP_NUM_TYPES];
+};
+
 struct mlx5e_psp_fs {
 	struct mlx5_core_dev *mdev;
 	struct mlx5e_psp_tx_table *tx_fs;
 	/* Rx manage */
 	struct mlx5e_flow_steering *fs;
 	struct mlx5e_psp_rx *rx_fs;
+
+	struct mlx5e_psp_rx_table rx;
 };
 
 /* PSP RX flow steering */
@@ -158,6 +166,106 @@ static void accel_psp_fs_destroy_counter(struct mlx5_core_dev *dev,
 	}
 }
 
+static void accel_psp_fs_rx_ft_destroy(struct mlx5e_psp_rx_table *rx)
+{
+	int i;
+
+	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++)
+		accel_psp_fs_del_flow_rule(&rx->udp_rules[i]);
+	accel_psp_fs_del_flow_rule(&rx->miss_rule);
+	accel_psp_fs_destroy_flow_group(&rx->miss_group);
+	accel_psp_fs_destroy_ft(&rx->ft);
+}
+
+static int accel_psp_fs_rx_ft_create(struct mlx5e_psp_fs *fs,
+				     struct mlx5e_psp_rx_table *rx)
+{
+	struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false);
+	struct mlx5_flow_destination dest[2] = {};
+	struct mlx5_flow_table_attr ft_attr = {};
+	struct mlx5_core_dev *mdev = fs->mdev;
+	MLX5_DECLARE_FLOW_ACT(flow_act);
+	struct mlx5_flow_handle *rule;
+	struct mlx5_flow_spec *spec;
+	int i, err = 0;
+
+	spec = kzalloc_obj(*spec);
+	if (!spec)
+		return -ENOMEM;
+
+	ft_attr.max_fte = 1 + ACCEL_FS_PSP_NUM_TYPES;
+	ft_attr.level = MLX5E_ACCEL_FS_PSP_RX_FT_LEVEL;
+	ft_attr.prio = MLX5E_NIC_PRIO;
+	ft_attr.autogroup.num_reserved_entries = 1;
+	err = accel_psp_fs_create_ft(fs, &ft_attr, &rx->ft);
+	if (err) {
+		mlx5_core_err(mdev, "fail to create psp rx ft err=%d\n", err);
+		goto out_err;
+	}
+
+	err = accel_psp_fs_create_miss_group(rx->ft, &rx->miss_group);
+	if (err) {
+		mlx5_core_err(mdev, "fail to create psp rx miss_group err=%d\n",
+			      err);
+		goto out_err;
+	}
+
+	/* Add miss rule */
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
+		MLX5_FLOW_CONTEXT_ACTION_COUNT;
+	flow_act.flags = FLOW_ACT_IGNORE_FLOW_LEVEL;
+	dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
+	dest[0].ft = mlx5_get_ttc_flow_table(ttc);
+	dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
+	dest[1].counter = fs->rx_fs->rx_counter;
+	rule = mlx5_add_flow_rules(rx->ft, NULL, &flow_act, dest, 2);
+	if (IS_ERR(rule)) {
+		err = PTR_ERR(rule);
+		mlx5_core_err(mdev, "fail to create psp rx rule, err=%d\n",
+			      err);
+		goto out_err;
+	}
+	rx->miss_rule = rule;
+
+	/* Add UDP v4/v6 rules */
+	spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
+	MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria,
+			 outer_headers.ip_version);
+	MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, spec->match_criteria,
+			 ip_protocol);
+	MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, ip_protocol,
+		 IPPROTO_UDP);
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
+		MLX5_FLOW_CONTEXT_ACTION_COUNT;
+	flow_act.flags = 0;
+	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
+		int version = i == ACCEL_FS_PSP4 ? 4 : 6;
+
+		MLX5_SET(fte_match_param, spec->match_value,
+			 outer_headers.ip_version, version);
+		dest[0] = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(i));
+		dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
+		dest[1].counter = fs->rx_fs->rx_counter;
+		rule = mlx5_add_flow_rules(rx->ft, spec, &flow_act, dest,
+					   2);
+		if (IS_ERR(rule)) {
+			err = PTR_ERR(rule);
+			mlx5_core_err(mdev,
+				      "fail to create psp rx UDP%d rule err=%d\n",
+				      version, err);
+			goto out_err;
+		}
+		rx->udp_rules[i] = rule;
+	}
+	goto out_spec;
+
+out_err:
+	accel_psp_fs_rx_ft_destroy(rx);
+out_spec:
+	kvfree(spec);
+	return err;
+}
+
 static
 void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_fs *fs,
 				      struct mlx5e_psp_rx_check_table *check)
@@ -205,12 +313,11 @@ static int accel_psp_add_drop_rule(struct mlx5_flow_table *ft,
 
 static
 int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
-				    struct mlx5e_psp_rx_decrypt_table *decrypt,
 				    struct mlx5e_psp_rx_check_table *check)
 {
 	struct mlx5_flow_table_attr ft_attr = {};
+	struct mlx5_flow_destination dest = {};
 	struct mlx5_core_dev *mdev = fs->mdev;
-	struct mlx5_flow_destination dest[2];
 	struct mlx5_flow_act flow_act = {};
 	struct mlx5_flow_handle *fte;
 	struct mlx5_flow_spec *spec;
@@ -223,7 +330,7 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
 	ft_attr.max_fte = 4;
 	ft_attr.autogroup.num_reserved_entries = 1;
 	ft_attr.autogroup.max_num_groups = 2;
-	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL;
+	ft_attr.level = MLX5E_ACCEL_FS_PSP_ERR_FT_LEVEL;
 	ft_attr.prio = MLX5E_NIC_PRIO;
 	err = accel_psp_fs_create_ft(fs, &ft_attr, &check->ft);
 	if (err) {
@@ -242,13 +349,10 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
 
 	accel_psp_setup_syndrome_match(spec, PSP_OK);
 	/* create fte */
-	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
-			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
-	dest[0].type = decrypt->default_dest.type;
-	dest[0].ft = decrypt->default_dest.ft;
-	dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-	dest[1].counter = fs->rx_fs->rx_counter;
-	fte = mlx5_add_flow_rules(check->ft, spec, &flow_act, dest, 2);
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
+	dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
+	dest.ft = fs->rx.ft;
+	fte = mlx5_add_flow_rules(check->ft, spec, &flow_act, &dest, 1);
 	if (IS_ERR(fte)) {
 		err = PTR_ERR(fte);
 		mlx5_core_err(mdev, "fail to add psp rx check ok rule err=%d\n",
@@ -330,7 +434,8 @@ static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port)
 
 static int
 accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs,
-				  struct mlx5e_psp_rx_decrypt_table *decrypt)
+				  struct mlx5e_psp_rx_decrypt_table *decrypt,
+				  struct mlx5_flow_destination *default_dest)
 {
 	u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {};
 	struct mlx5_modify_hdr *modify_hdr = NULL;
@@ -348,7 +453,7 @@ accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs,
 
 	/* Create FT */
 	ft_attr.max_fte = 2;
-	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_LEVEL;
+	ft_attr.level = MLX5E_ACCEL_FS_PSP_FT_LEVEL;
 	ft_attr.autogroup.num_reserved_entries = 1;
 	ft_attr.autogroup.max_num_groups = 1;
 	ft_attr.prio = MLX5E_NIC_PRIO;
@@ -370,8 +475,8 @@ accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs,
 
 	/* Create miss rule */
 	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
-	rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act,
-				   &decrypt->default_dest, 1);
+	rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act, default_dest,
+				   1);
 	if (IS_ERR(rule)) {
 		err = PTR_ERR(rule);
 		mlx5_core_err(mdev,
@@ -446,17 +551,17 @@ static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ
 	struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false);
 	struct mlx5e_psp_rx_decrypt_table *decrypt;
 	struct mlx5e_psp_rx *rx_fs = fs->rx_fs;
+	struct mlx5_flow_destination dest = {};
 	int err;
 
 	decrypt = &rx_fs->decrypt[type];
-	decrypt->default_dest = mlx5_ttc_get_default_dest(ttc,
-							  fs_psp2tt(type));
 
-	err = accel_psp_fs_rx_check_ft_create(fs, decrypt, &decrypt->check);
+	err = accel_psp_fs_rx_check_ft_create(fs, &decrypt->check);
 	if (err)
 		return err;
 
-	err = accel_psp_fs_rx_decrypt_ft_create(fs, decrypt);
+	dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(type));
+	err = accel_psp_fs_rx_decrypt_ft_create(fs, decrypt, &dest);
 	if (err)
 		goto out_err_ft;
 
@@ -549,6 +654,7 @@ void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv)
 		/* remove FT */
 		accel_psp_fs_rx_destroy(fs, i);
 	}
+	accel_psp_fs_rx_ft_destroy(&priv->psp->fs->rx);
 }
 
 int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
@@ -563,6 +669,10 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 	fs = priv->psp->fs;
 	ttc = mlx5e_fs_get_ttc(fs->fs, false);
 
+	err = accel_psp_fs_rx_ft_create(fs, &fs->rx);
+	if (err)
+		return err;
+
 	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
 		struct mlx5e_psp_rx_decrypt_table *decrypt;
 		struct mlx5_flow_destination dest = {};
@@ -586,6 +696,7 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 		mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i));
 		accel_psp_fs_rx_destroy(fs, i);
 	}
+	accel_psp_fs_rx_ft_destroy(&fs->rx);
 
 	return err;
 }
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 08/15] net/mlx5e: psp: Rename and consolidate steering functions
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

There are multiple naming inconsistencies and the code is fragmented and
hard to follow.
For example, the PSP TX steering structure is named 'mlx5e_psp_tx', but
its RX counterpart is 'mlx5e_accel_fs_psp' and its protocol
instantiation 'mlx5e_accel_fs_psp_prot', neither of which make it clear
they relate to RX.

This commit renames things to be more consistent, realigns declarations
to abide by the xmas tree rule, and merges some functions to reduce
fragmentation. Renamed:
mlx5e_accel_fs_psp -> mlx5e_psp_rx
mlx5e_accel_fs_psp_prot -> mlx5e_psp_rx_decrypt_table
fs_prot -> decrypt
accel_psp -> rx_fs
mlx5e_psp_rx_err -> mlx5e_psp_rx_check_table
mlx5e_psp_tx -> mlx5e_psp_tx_table
def_rule -> rule

Also renamed many functions with names of the form
accel_psp_fs_A_B_C_..._verb, with A->B->C->... following a
general->specific hierarchy. Full list:
accel_psp_fs_rx_err_destroy_ft -> accel_psp_fs_rx_check_ft_destroy
accel_psp_fs_rx_err_create_ft -> accel_psp_fs_rx_check_ft_create
accel_psp_fs_rx_fs_destroy -> accel_psp_fs_rx_decrypt_ft_destroy
accel_psp_fs_rx_create_ft -> accel_psp_fs_rx_decrypt_ft_create
accel_psp_fs_tx_create_ft_table -> accel_psp_fs_tx_ft_create
accel_psp_fs_tx_destroy -> accel_psp_fs_tx_ft_destroy
accel_psp_fs_{init,cleanup}_{rx,tx} ->
accel_psp_fs_{rx,tx}_{init,cleanup}

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 252 +++++++++---------
 1 file changed, 131 insertions(+), 121 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index 534dba678761..c83d62724ff7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -21,7 +21,7 @@ enum accel_psp_syndrome {
 	PSP_BAD_TRAILER,
 };
 
-struct mlx5e_psp_tx {
+struct mlx5e_psp_tx_table {
 	struct mlx5_flow_namespace *ns;
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_group *fg;
@@ -29,7 +29,7 @@ struct mlx5e_psp_tx {
 	struct mlx5_fc *tx_counter;
 };
 
-struct mlx5e_psp_rx_err {
+struct mlx5e_psp_rx_check_table {
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_handle *rule;
 	struct mlx5_flow_handle *auth_fail_rule;
@@ -37,18 +37,18 @@ struct mlx5e_psp_rx_err {
 	struct mlx5_flow_handle *bad_rule;
 };
 
-struct mlx5e_accel_fs_psp_prot {
+struct mlx5e_psp_rx_decrypt_table {
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_group *miss_group;
 	struct mlx5_flow_handle *miss_rule;
 	struct mlx5_modify_hdr *rx_modify_hdr;
 	struct mlx5_flow_destination default_dest;
-	struct mlx5e_psp_rx_err rx_err;
-	struct mlx5_flow_handle *def_rule;
+	struct mlx5e_psp_rx_check_table check;
+	struct mlx5_flow_handle *rule;
 };
 
-struct mlx5e_accel_fs_psp {
-	struct mlx5e_accel_fs_psp_prot fs_prot[ACCEL_FS_PSP_NUM_TYPES];
+struct mlx5e_psp_rx {
+	struct mlx5e_psp_rx_decrypt_table decrypt[ACCEL_FS_PSP_NUM_TYPES];
 	struct mlx5_fc *rx_counter;
 	struct mlx5_fc *rx_auth_fail_counter;
 	struct mlx5_fc *rx_err_counter;
@@ -57,10 +57,10 @@ struct mlx5e_accel_fs_psp {
 
 struct mlx5e_psp_fs {
 	struct mlx5_core_dev *mdev;
-	struct mlx5e_psp_tx *tx_fs;
+	struct mlx5e_psp_tx_table *tx_fs;
 	/* Rx manage */
 	struct mlx5e_flow_steering *fs;
-	struct mlx5e_accel_fs_psp *rx_fs;
+	struct mlx5e_psp_rx *rx_fs;
 };
 
 /* PSP RX flow steering */
@@ -157,14 +157,15 @@ static void accel_psp_fs_destroy_counter(struct mlx5_core_dev *dev,
 	}
 }
 
-static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs,
-					   struct mlx5e_psp_rx_err *rx_err)
+static
+void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_fs *fs,
+				      struct mlx5e_psp_rx_check_table *check)
 {
-	accel_psp_fs_del_flow_rule(&rx_err->bad_rule);
-	accel_psp_fs_del_flow_rule(&rx_err->err_rule);
-	accel_psp_fs_del_flow_rule(&rx_err->auth_fail_rule);
-	accel_psp_fs_del_flow_rule(&rx_err->rule);
-	accel_psp_fs_destroy_ft(&rx_err->ft);
+	accel_psp_fs_del_flow_rule(&check->bad_rule);
+	accel_psp_fs_del_flow_rule(&check->err_rule);
+	accel_psp_fs_del_flow_rule(&check->auth_fail_rule);
+	accel_psp_fs_del_flow_rule(&check->rule);
+	accel_psp_fs_destroy_ft(&check->ft);
 }
 
 static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec *spec,
@@ -201,9 +202,9 @@ static int accel_psp_add_drop_rule(struct mlx5_flow_table *ft,
 }
 
 static
-int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
-				  struct mlx5e_accel_fs_psp_prot *fs_prot,
-				  struct mlx5e_psp_rx_err *rx_err)
+int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs,
+				    struct mlx5e_psp_rx_decrypt_table *decrypt,
+				    struct mlx5e_psp_rx_check_table *check)
 {
 	struct mlx5_flow_table_attr ft_attr = {};
 	struct mlx5_core_dev *mdev = fs->mdev;
@@ -221,10 +222,10 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 	ft_attr.autogroup.max_num_groups = 2;
 	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL;
 	ft_attr.prio = MLX5E_NIC_PRIO;
-	err = accel_psp_fs_create_ft(fs, &ft_attr, &rx_err->ft);
+	err = accel_psp_fs_create_ft(fs, &ft_attr, &check->ft);
 	if (err) {
 		mlx5_core_err(fs->mdev,
-			      "fail to create psp rx inline ft err=%d\n", err);
+			      "fail to create psp rx check ft err=%d\n", err);
 		goto out_err;
 	}
 
@@ -232,27 +233,28 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 	/* create fte */
 	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
 			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
-	dest[0].type = fs_prot->default_dest.type;
-	dest[0].ft = fs_prot->default_dest.ft;
+	dest[0].type = decrypt->default_dest.type;
+	dest[0].ft = decrypt->default_dest.ft;
 	dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
 	dest[1].counter = fs->rx_fs->rx_counter;
-	fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 2);
+	fte = mlx5_add_flow_rules(check->ft, spec, &flow_act, dest, 2);
 	if (IS_ERR(fte)) {
 		err = PTR_ERR(fte);
-		mlx5_core_err(mdev, "fail to add psp rx err rule err=%d\n",
+		mlx5_core_err(mdev, "fail to add psp rx check ok rule err=%d\n",
 			      err);
 		goto out_err;
 	}
-	rx_err->rule = fte;
+	check->rule = fte;
 
 	/* add auth fail drop rule */
 	memset(spec, 0, sizeof(*spec));
 	accel_psp_setup_syndrome_match(spec, PSP_ICV_FAIL);
-	err = accel_psp_add_drop_rule(rx_err->ft, spec,
+	err = accel_psp_add_drop_rule(check->ft, spec,
 				      fs->rx_fs->rx_auth_fail_counter,
-				      &rx_err->auth_fail_rule);
+				      &check->auth_fail_rule);
 	if (err) {
-		mlx5_core_err(mdev, "fail to add psp rx auth fail drop rule err=%d\n",
+		mlx5_core_err(mdev,
+			      "fail to add psp rx check auth fail drop rule err=%d\n",
 			      err);
 		goto out_err;
 	}
@@ -260,22 +262,24 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 	/* add framing drop rule */
 	memset(spec, 0, sizeof(*spec));
 	accel_psp_setup_syndrome_match(spec, PSP_BAD_TRAILER);
-	err = accel_psp_add_drop_rule(rx_err->ft, spec,
+	err = accel_psp_add_drop_rule(check->ft, spec,
 				      fs->rx_fs->rx_err_counter,
-				      &rx_err->err_rule);
+				      &check->err_rule);
 	if (err) {
-		mlx5_core_err(mdev, "fail to add psp rx framing drop rule err=%d\n",
+		mlx5_core_err(mdev,
+			      "fail to add psp rx check framing drop rule err=%d\n",
 			      err);
 		goto out_err;
 	}
 
 	/* add misc. errors drop rule */
 	memset(spec, 0, sizeof(*spec));
-	err = accel_psp_add_drop_rule(rx_err->ft, spec,
+	err = accel_psp_add_drop_rule(check->ft, spec,
 				      fs->rx_fs->rx_bad_counter,
-				      &rx_err->bad_rule);
+				      &check->bad_rule);
 	if (err) {
-		mlx5_core_err(mdev, "fail to add psp rx misc. err drop rule err=%d\n",
+		mlx5_core_err(mdev,
+			      "fail to add psp rx check misc. err drop rule err=%d\n",
 			      err);
 		goto out_err;
 	}
@@ -283,24 +287,25 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 	goto out_spec;
 
 out_err:
-	accel_psp_fs_rx_err_destroy_ft(fs, rx_err);
+	accel_psp_fs_rx_check_ft_destroy(fs, check);
 out_spec:
 	kfree(spec);
 	return err;
 }
 
 
-static void accel_psp_fs_rx_fs_destroy(struct mlx5e_psp_fs *fs,
-				       struct mlx5e_accel_fs_psp_prot *fs_prot)
+static void
+accel_psp_fs_rx_decrypt_ft_destroy(struct mlx5e_psp_fs *fs,
+				   struct mlx5e_psp_rx_decrypt_table *decrypt)
 {
-	accel_psp_fs_del_flow_rule(&fs_prot->def_rule);
-	if (fs_prot->rx_modify_hdr) {
-		mlx5_modify_header_dealloc(fs->mdev, fs_prot->rx_modify_hdr);
-		fs_prot->rx_modify_hdr = NULL;
+	accel_psp_fs_del_flow_rule(&decrypt->rule);
+	if (decrypt->rx_modify_hdr) {
+		mlx5_modify_header_dealloc(fs->mdev, decrypt->rx_modify_hdr);
+		decrypt->rx_modify_hdr = NULL;
 	}
-	accel_psp_fs_del_flow_rule(&fs_prot->miss_rule);
-	accel_psp_fs_destroy_flow_group(&fs_prot->miss_group);
-	accel_psp_fs_destroy_ft(&fs_prot->ft);
+	accel_psp_fs_del_flow_rule(&decrypt->miss_rule);
+	accel_psp_fs_destroy_flow_group(&decrypt->miss_group);
+	accel_psp_fs_destroy_ft(&decrypt->ft);
 }
 
 static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port)
@@ -312,8 +317,9 @@ static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port)
 	MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, ip_protocol, IPPROTO_UDP);
 }
 
-static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs,
-				     struct mlx5e_accel_fs_psp_prot *fs_prot)
+static int
+accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs,
+				  struct mlx5e_psp_rx_decrypt_table *decrypt)
 {
 	u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {};
 	struct mlx5_modify_hdr *modify_hdr = NULL;
@@ -335,30 +341,36 @@ static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs,
 	ft_attr.autogroup.num_reserved_entries = 1;
 	ft_attr.autogroup.max_num_groups = 1;
 	ft_attr.prio = MLX5E_NIC_PRIO;
-	err = accel_psp_fs_create_ft(fs, &ft_attr, &fs_prot->ft);
+	err = accel_psp_fs_create_ft(fs, &ft_attr, &decrypt->ft);
 	if (err) {
-		mlx5_core_err(mdev, "fail to create psp rx ft err=%d\n", err);
+		mlx5_core_err(mdev, "fail to create psp rx decrypt ft err=%d\n",
+			      err);
 		goto out_err;
 	}
 
 	/* Create miss_group */
-	err = accel_psp_fs_create_miss_group(fs_prot->ft, &fs_prot->miss_group);
+	err = accel_psp_fs_create_miss_group(decrypt->ft, &decrypt->miss_group);
 	if (err) {
-		mlx5_core_err(mdev, "fail to create psp rx miss_group err=%d\n", err);
+		mlx5_core_err(mdev,
+			      "fail to create psp rx decrypt miss_group err=%d\n",
+			      err);
 		goto out_err;
 	}
 
 	/* Create miss rule */
-	rule = mlx5_add_flow_rules(fs_prot->ft, spec, &flow_act,
-				   &fs_prot->default_dest, 1);
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
+	rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act,
+				   &decrypt->default_dest, 1);
 	if (IS_ERR(rule)) {
 		err = PTR_ERR(rule);
-		mlx5_core_err(mdev, "fail to create psp rx miss_rule err=%d\n", err);
+		mlx5_core_err(mdev,
+			      "fail to create psp rx decrypt miss_rule err=%d\n",
+			      err);
 		goto out_err;
 	}
-	fs_prot->miss_rule = rule;
+	decrypt->miss_rule = rule;
 
-	/* Add default Rx psp rule */
+	/* Add PSP RX decrypt rule */
 	setup_fte_udp_psp(spec, PSP_DEFAULT_UDP_PORT);
 	flow_act.crypto.type = MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_PSP;
 	/* Set bit[31, 30] PSP marker */
@@ -376,46 +388,44 @@ static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs,
 		modify_hdr = NULL;
 		goto out_err;
 	}
-	fs_prot->rx_modify_hdr = modify_hdr;
+	decrypt->rx_modify_hdr = modify_hdr;
 
 	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
 			  MLX5_FLOW_CONTEXT_ACTION_CRYPTO_DECRYPT |
 			  MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
 	flow_act.modify_hdr = modify_hdr;
 	dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
-	dest.ft = fs_prot->rx_err.ft;
-	rule = mlx5_add_flow_rules(fs_prot->ft, spec, &flow_act, &dest, 1);
+	dest.ft = decrypt->check.ft;
+	rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act, &dest, 1);
 	if (IS_ERR(rule)) {
 		err = PTR_ERR(rule);
-		mlx5_core_err(mdev,
-			      "fail to add psp rule Rx decryption, err=%d, flow_act.action = %#04X\n",
-			      err, flow_act.action);
+		mlx5_core_err(mdev, "fail to add psp rx decrypt rule, err=%d\n",
+			      err);
 		goto out_err;
 	}
 
-	fs_prot->def_rule = rule;
+	decrypt->rule = rule;
 	goto out_spec;
 
 out_err:
-	accel_psp_fs_rx_fs_destroy(fs, fs_prot);
+	accel_psp_fs_rx_decrypt_ft_destroy(fs, decrypt);
 out_spec:
 	kvfree(spec);
 	return err;
 }
 
-static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type)
+static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs,
+				   enum accel_fs_psp_type type)
 {
-	struct mlx5e_accel_fs_psp_prot *fs_prot;
-	struct mlx5e_accel_fs_psp *accel_psp;
-
-	accel_psp = fs->rx_fs;
+	struct mlx5e_psp_rx_decrypt_table *decrypt;
+	struct mlx5e_psp_rx *rx_fs = fs->rx_fs;
 
 	/* The netdev unreg already happened, so all offloaded rule are already removed */
-	fs_prot = &accel_psp->fs_prot[type];
+	decrypt = &rx_fs->decrypt[type];
 
-	accel_psp_fs_rx_fs_destroy(fs, fs_prot);
+	accel_psp_fs_rx_decrypt_ft_destroy(fs, decrypt);
 
-	accel_psp_fs_rx_err_destroy_ft(fs, &fs_prot->rx_err);
+	accel_psp_fs_rx_check_ft_destroy(fs, &decrypt->check);
 
 	return 0;
 }
@@ -423,43 +433,45 @@ static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs, enum accel_fs_psp_ty
 static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type)
 {
 	struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false);
-	struct mlx5e_accel_fs_psp_prot *fs_prot;
-	struct mlx5e_accel_fs_psp *accel_psp;
+	struct mlx5e_psp_rx_decrypt_table *decrypt;
+	struct mlx5e_psp_rx *rx_fs = fs->rx_fs;
 	int err;
 
-	accel_psp = fs->rx_fs;
-	fs_prot = &accel_psp->fs_prot[type];
+	decrypt = &rx_fs->decrypt[type];
+	decrypt->default_dest = mlx5_ttc_get_default_dest(ttc,
+							  fs_psp2tt(type));
 
-	fs_prot->default_dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(type));
-
-	err = accel_psp_fs_rx_err_create_ft(fs, fs_prot, &fs_prot->rx_err);
+	err = accel_psp_fs_rx_check_ft_create(fs, decrypt, &decrypt->check);
 	if (err)
 		return err;
 
-	err = accel_psp_fs_rx_create_ft(fs, fs_prot);
+	err = accel_psp_fs_rx_decrypt_ft_create(fs, decrypt);
 	if (err)
-		accel_psp_fs_rx_err_destroy_ft(fs, &fs_prot->rx_err);
+		goto out_err_ft;
+
+	return 0;
 
+out_err_ft:
+	accel_psp_fs_rx_check_ft_destroy(fs, &decrypt->check);
 	return err;
 }
 
-static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs)
+static void accel_psp_fs_rx_cleanup(struct mlx5e_psp_fs *fs)
 {
-	struct mlx5e_accel_fs_psp *accel_psp = fs->rx_fs;
+	struct mlx5e_psp_rx *rx_fs = fs->rx_fs;
 
-	if (!accel_psp)
+	if (!rx_fs)
 		return;
 
-	accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_bad_counter);
-	accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_err_counter);
-	accel_psp_fs_destroy_counter(fs->mdev,
-				     &accel_psp->rx_auth_fail_counter);
-	accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_counter);
-	kfree(accel_psp);
+	accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_bad_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_err_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_auth_fail_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_counter);
+	kfree(rx_fs);
 	fs->rx_fs = NULL;
 }
 
-static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs)
+static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs)
 {
 	struct mlx5_core_dev *mdev = fs->mdev;
 	int err;
@@ -504,7 +516,7 @@ static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs)
 	return 0;
 
 out_err:
-	accel_psp_fs_cleanup_rx(fs);
+	accel_psp_fs_rx_cleanup(fs);
 	return err;
 }
 
@@ -541,7 +553,7 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 	ttc = mlx5e_fs_get_ttc(fs->fs, false);
 
 	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
-		struct mlx5e_accel_fs_psp_prot *fs_prot;
+		struct mlx5e_psp_rx_decrypt_table *decrypt;
 		struct mlx5_flow_destination dest = {};
 
 		/* create FT */
@@ -551,8 +563,8 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 
 		/* connect */
 		dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
-		fs_prot = &fs->rx_fs->fs_prot[i];
-		dest.ft = fs_prot->ft;
+		decrypt = &fs->rx_fs->decrypt[i];
+		dest.ft = decrypt->ft;
 		mlx5_ttc_fwd_dest(ttc, fs_psp2tt(i), &dest);
 	}
 
@@ -567,17 +579,17 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 	return err;
 }
 
-static int accel_psp_fs_tx_create_ft_table(struct mlx5e_psp_fs *fs)
+static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs)
 {
 	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
 	struct mlx5_flow_table_attr ft_attr = {};
 	struct mlx5_flow_destination dest = {};
 	struct mlx5_core_dev *mdev = fs->mdev;
 	struct mlx5_flow_act flow_act = {};
+	struct mlx5e_psp_tx_table *tx_fs;
 	u32 *in, *mc, *outer_headers_c;
 	struct mlx5_flow_handle *rule;
 	struct mlx5_flow_spec *spec;
-	struct mlx5e_psp_tx *tx_fs;
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_group *fg;
 	int err = 0;
@@ -646,16 +658,16 @@ static int accel_psp_fs_tx_create_ft_table(struct mlx5e_psp_fs *fs)
 	return err;
 }
 
-static void accel_psp_fs_tx_destroy(struct mlx5e_psp_tx *tx_fs)
+static void accel_psp_fs_tx_ft_destroy(struct mlx5e_psp_tx_table *tx_fs)
 {
 	accel_psp_fs_del_flow_rule(&tx_fs->rule);
 	accel_psp_fs_destroy_flow_group(&tx_fs->fg);
 	accel_psp_fs_destroy_ft(&tx_fs->ft);
 }
 
-static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs)
+static void accel_psp_fs_tx_cleanup(struct mlx5e_psp_fs *fs)
 {
-	struct mlx5e_psp_tx *tx_fs = fs->tx_fs;
+	struct mlx5e_psp_tx_table *tx_fs = fs->tx_fs;
 
 	if (!tx_fs)
 		return;
@@ -665,11 +677,11 @@ static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs)
 	fs->tx_fs = NULL;
 }
 
-static int accel_psp_fs_init_tx(struct mlx5e_psp_fs *fs)
+static int accel_psp_fs_tx_init(struct mlx5e_psp_fs *fs)
 {
 	struct mlx5_core_dev *mdev = fs->mdev;
+	struct mlx5e_psp_tx_table *tx_fs;
 	struct mlx5_flow_namespace *ns;
-	struct mlx5e_psp_tx *tx_fs;
 	int err;
 
 	ns = mlx5_get_flow_namespace(mdev, MLX5_FLOW_NAMESPACE_EGRESS_IPSEC);
@@ -697,32 +709,30 @@ static void
 mlx5e_accel_psp_fs_get_stats_fill(struct mlx5e_priv *priv,
 				  struct mlx5e_psp_stats *stats)
 {
-	struct mlx5e_psp_tx *tx_fs = priv->psp->fs->tx_fs;
+	struct mlx5e_psp_tx_table *tx_fs = priv->psp->fs->tx_fs;
+	struct mlx5e_psp_rx *rx_fs = priv->psp->fs->rx_fs;
 	struct mlx5_core_dev *mdev = priv->mdev;
-	struct mlx5e_accel_fs_psp *accel_psp;
-
-	accel_psp = (struct mlx5e_accel_fs_psp *)priv->psp->fs->rx_fs;
 
 	if (tx_fs->tx_counter)
 		mlx5_fc_query(mdev, tx_fs->tx_counter, &stats->psp_tx_pkts,
 			      &stats->psp_tx_bytes);
 
-	if (accel_psp->rx_counter)
-		mlx5_fc_query(mdev, accel_psp->rx_counter, &stats->psp_rx_pkts,
+	if (rx_fs->rx_counter)
+		mlx5_fc_query(mdev, rx_fs->rx_counter, &stats->psp_rx_pkts,
 			      &stats->psp_rx_bytes);
 
-	if (accel_psp->rx_auth_fail_counter)
-		mlx5_fc_query(mdev, accel_psp->rx_auth_fail_counter,
+	if (rx_fs->rx_auth_fail_counter)
+		mlx5_fc_query(mdev, rx_fs->rx_auth_fail_counter,
 			      &stats->psp_rx_pkts_auth_fail,
 			      &stats->psp_rx_bytes_auth_fail);
 
-	if (accel_psp->rx_err_counter)
-		mlx5_fc_query(mdev, accel_psp->rx_err_counter,
+	if (rx_fs->rx_err_counter)
+		mlx5_fc_query(mdev, rx_fs->rx_err_counter,
 			      &stats->psp_rx_pkts_frame_err,
 			      &stats->psp_rx_bytes_frame_err);
 
-	if (accel_psp->rx_bad_counter)
-		mlx5_fc_query(mdev, accel_psp->rx_bad_counter,
+	if (rx_fs->rx_bad_counter)
+		mlx5_fc_query(mdev, rx_fs->rx_bad_counter,
 			      &stats->psp_rx_pkts_drop,
 			      &stats->psp_rx_bytes_drop);
 }
@@ -732,7 +742,7 @@ void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv)
 	if (!priv->psp)
 		return;
 
-	accel_psp_fs_tx_destroy(priv->psp->fs->tx_fs);
+	accel_psp_fs_tx_ft_destroy(priv->psp->fs->tx_fs);
 }
 
 int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
@@ -740,13 +750,13 @@ int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
 	if (!priv->psp)
 		return 0;
 
-	return accel_psp_fs_tx_create_ft_table(priv->psp->fs);
+	return accel_psp_fs_tx_ft_create(priv->psp->fs);
 }
 
 static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs)
 {
-	accel_psp_fs_cleanup_rx(fs);
-	accel_psp_fs_cleanup_tx(fs);
+	accel_psp_fs_rx_cleanup(fs);
+	accel_psp_fs_tx_cleanup(fs);
 	kfree(fs);
 }
 
@@ -760,19 +770,19 @@ static struct mlx5e_psp_fs *mlx5e_accel_psp_fs_init(struct mlx5e_priv *priv)
 		return ERR_PTR(-ENOMEM);
 
 	fs->mdev = priv->mdev;
-	err = accel_psp_fs_init_tx(fs);
+	err = accel_psp_fs_tx_init(fs);
 	if (err)
 		goto err_tx;
 
 	fs->fs = priv->fs;
-	err = accel_psp_fs_init_rx(fs);
+	err = accel_psp_fs_rx_init(fs);
 	if (err)
 		goto err_rx;
 
 	return fs;
 
 err_rx:
-	accel_psp_fs_cleanup_tx(fs);
+	accel_psp_fs_tx_cleanup(fs);
 err_tx:
 	kfree(fs);
 	return ERR_PTR(err);
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 07/15] net/mlx5e: psp: Remove unused PSP syndrome copy action
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

The PSP error flow table copies the HW syndrome to metadata register B,
but this value is never used in the RX path. Bad packets (auth fail,
bad trailer) are dropped by HW via explicit drop rules before reaching
software.

Remove the syndrome copy action, the syndrome macro, and the dead
syndrome check in the RX handler.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 30 +------------------
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    | 11 -------
 .../mellanox/mlx5/core/en_accel/psp_rxtx.h    |  3 +-
 3 files changed, 2 insertions(+), 42 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index bdf97e373b42..534dba678761 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -35,7 +35,6 @@ struct mlx5e_psp_rx_err {
 	struct mlx5_flow_handle *auth_fail_rule;
 	struct mlx5_flow_handle *err_rule;
 	struct mlx5_flow_handle *bad_rule;
-	struct mlx5_modify_hdr *copy_modify_hdr;
 };
 
 struct mlx5e_accel_fs_psp_prot {
@@ -165,10 +164,6 @@ static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs,
 	accel_psp_fs_del_flow_rule(&rx_err->err_rule);
 	accel_psp_fs_del_flow_rule(&rx_err->auth_fail_rule);
 	accel_psp_fs_del_flow_rule(&rx_err->rule);
-	if (rx_err->copy_modify_hdr) {
-		mlx5_modify_header_dealloc(fs->mdev, rx_err->copy_modify_hdr);
-		rx_err->copy_modify_hdr = NULL;
-	}
 	accel_psp_fs_destroy_ft(&rx_err->ft);
 }
 
@@ -210,12 +205,10 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 				  struct mlx5e_accel_fs_psp_prot *fs_prot,
 				  struct mlx5e_psp_rx_err *rx_err)
 {
-	u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {};
 	struct mlx5_flow_table_attr ft_attr = {};
 	struct mlx5_core_dev *mdev = fs->mdev;
 	struct mlx5_flow_destination dest[2];
 	struct mlx5_flow_act flow_act = {};
-	struct mlx5_modify_hdr *modify_hdr;
 	struct mlx5_flow_handle *fte;
 	struct mlx5_flow_spec *spec;
 	int err = 0;
@@ -235,30 +228,10 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 		goto out_err;
 	}
 
-	/* Action to copy 7 bit psp_syndrome to regB[23:29] */
-	MLX5_SET(copy_action_in, action, action_type, MLX5_ACTION_TYPE_COPY);
-	MLX5_SET(copy_action_in, action, src_field, MLX5_ACTION_IN_FIELD_PSP_SYNDROME);
-	MLX5_SET(copy_action_in, action, src_offset, 0);
-	MLX5_SET(copy_action_in, action, length, 7);
-	MLX5_SET(copy_action_in, action, dst_field, MLX5_ACTION_IN_FIELD_METADATA_REG_B);
-	MLX5_SET(copy_action_in, action, dst_offset, 23);
-
-	modify_hdr = mlx5_modify_header_alloc(mdev, MLX5_FLOW_NAMESPACE_KERNEL,
-					      1, action);
-	if (IS_ERR(modify_hdr)) {
-		err = PTR_ERR(modify_hdr);
-		mlx5_core_err(mdev,
-			      "fail to alloc psp copy modify_header_id err=%d\n", err);
-		goto out_err;
-	}
-	rx_err->copy_modify_hdr = modify_hdr;
-
 	accel_psp_setup_syndrome_match(spec, PSP_OK);
 	/* create fte */
-	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_MOD_HDR |
-			  MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
 			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
-	flow_act.modify_hdr = modify_hdr;
 	dest[0].type = fs_prot->default_dest.type;
 	dest[0].ft = fs_prot->default_dest.ft;
 	dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
@@ -389,7 +362,6 @@ static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs,
 	setup_fte_udp_psp(spec, PSP_DEFAULT_UDP_PORT);
 	flow_act.crypto.type = MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_PSP;
 	/* Set bit[31, 30] PSP marker */
-	/* Set bit[29-23] psp_syndrome is set in error FT */
 #define MLX5E_PSP_MARKER_BIT (BIT(30) | BIT(31))
 	MLX5_SET(set_action_in, action, action_type, MLX5_ACTION_TYPE_SET);
 	MLX5_SET(set_action_in, action, field, MLX5_ACTION_IN_FIELD_METADATA_REG_B);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
index c2f9899d23a5..348fd7a96261 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
@@ -14,12 +14,6 @@
 #include "en_accel/psp_rxtx.h"
 #include "en_accel/psp.h"
 
-enum {
-	MLX5E_PSP_OFFLOAD_RX_SYNDROME_DECRYPTED,
-	MLX5E_PSP_OFFLOAD_RX_SYNDROME_AUTH_FAILED,
-	MLX5E_PSP_OFFLOAD_RX_SYNDROME_BAD_TRAILER,
-};
-
 static void mlx5e_psp_set_swp(struct sk_buff *skb,
 			      struct mlx5e_accel_tx_psp_state *psp_st,
 			      struct mlx5_wqe_eth_seg *eseg)
@@ -122,16 +116,11 @@ static bool mlx5e_psp_set_state(struct mlx5e_priv *priv,
 bool mlx5e_psp_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff *skb,
 				     struct mlx5_cqe64 *cqe)
 {
-	u32 psp_meta_data = be32_to_cpu(cqe->ft_metadata);
 	struct mlx5e_priv *priv = netdev_priv(netdev);
 	u16 dev_id = priv->psp->psd->id;
 	bool strip_icv = true;
 	u8 generation = 0;
 
-	/* TBD: report errors as SW counters to ethtool, any further handling ? */
-	if (MLX5_PSP_METADATA_SYNDROME(psp_meta_data) != MLX5E_PSP_OFFLOAD_RX_SYNDROME_DECRYPTED)
-		goto drop;
-
 	if (psp_dev_rcv(skb, dev_id, generation, strip_icv))
 		goto drop;
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h
index 70289c921bd6..2b080c39cc37 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h
@@ -10,9 +10,8 @@
 #include "en.h"
 #include "en/txrx.h"
 
-/* Bit30: PSP marker, Bit29-23: PSP syndrome, Bit22-0: PSP obj id */
+/* Bit30: PSP marker, Bit22-0: PSP obj id */
 #define MLX5_PSP_METADATA_MARKER(metadata)  ((((metadata) >> 30) & 0x3) == 0x3)
-#define MLX5_PSP_METADATA_SYNDROME(metadata) (((metadata) >> 23) & GENMASK(6, 0))
 #define MLX5_PSP_METADATA_HANDLE(metadata)  ((metadata) & GENMASK(22, 0))
 
 struct mlx5e_accel_tx_psp_state {
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 06/15] net/mlx5e: psp: Factor out drop rule creation code
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

There are 3 rules added with the same structure. Factor out common code
into a helper function to reduce duplication.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 65 ++++++++++---------
 1 file changed, 34 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index a1c7ca4ae722..bdf97e373b42 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -184,6 +184,27 @@ static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec *spec,
 	MLX5_SET(fte_match_set_misc2, misc_params_2, psp_syndrome, syndrome);
 }
 
+static int accel_psp_add_drop_rule(struct mlx5_flow_table *ft,
+				   struct mlx5_flow_spec *spec,
+				   struct mlx5_fc *counter,
+				   struct mlx5_flow_handle **rule)
+{
+	struct mlx5_flow_destination dest = {};
+	struct mlx5_flow_act flow_act = {};
+	int err = 0;
+
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP |
+			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
+	dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
+	dest.counter = counter;
+	*rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1);
+	if (IS_ERR(*rule)) {
+		err = PTR_ERR(*rule);
+		*rule = NULL;
+	}
+	return err;
+}
+
 static
 int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 				  struct mlx5e_accel_fs_psp_prot *fs_prot,
@@ -253,56 +274,38 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 
 	/* add auth fail drop rule */
 	memset(spec, 0, sizeof(*spec));
-	memset(&flow_act, 0, sizeof(flow_act));
 	accel_psp_setup_syndrome_match(spec, PSP_ICV_FAIL);
-	/* create fte */
-	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP |
-			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
-	dest[0].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-	dest[0].counter = fs->rx_fs->rx_auth_fail_counter;
-	fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 1);
-	if (IS_ERR(fte)) {
-		err = PTR_ERR(fte);
+	err = accel_psp_add_drop_rule(rx_err->ft, spec,
+				      fs->rx_fs->rx_auth_fail_counter,
+				      &rx_err->auth_fail_rule);
+	if (err) {
 		mlx5_core_err(mdev, "fail to add psp rx auth fail drop rule err=%d\n",
 			      err);
 		goto out_err;
 	}
-	rx_err->auth_fail_rule = fte;
 
 	/* add framing drop rule */
 	memset(spec, 0, sizeof(*spec));
-	memset(&flow_act, 0, sizeof(flow_act));
 	accel_psp_setup_syndrome_match(spec, PSP_BAD_TRAILER);
-	/* create fte */
-	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP |
-			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
-	dest[0].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-	dest[0].counter = fs->rx_fs->rx_err_counter;
-	fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 1);
-	if (IS_ERR(fte)) {
-		err = PTR_ERR(fte);
-		mlx5_core_err(mdev, "fail to add psp rx framing err drop rule err=%d\n",
+	err = accel_psp_add_drop_rule(rx_err->ft, spec,
+				      fs->rx_fs->rx_err_counter,
+				      &rx_err->err_rule);
+	if (err) {
+		mlx5_core_err(mdev, "fail to add psp rx framing drop rule err=%d\n",
 			      err);
 		goto out_err;
 	}
-	rx_err->err_rule = fte;
 
 	/* add misc. errors drop rule */
 	memset(spec, 0, sizeof(*spec));
-	memset(&flow_act, 0, sizeof(flow_act));
-	/* create fte */
-	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP |
-			  MLX5_FLOW_CONTEXT_ACTION_COUNT;
-	dest[0].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
-	dest[0].counter = fs->rx_fs->rx_bad_counter;
-	fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 1);
-	if (IS_ERR(fte)) {
-		err = PTR_ERR(fte);
+	err = accel_psp_add_drop_rule(rx_err->ft, spec,
+				      fs->rx_fs->rx_bad_counter,
+				      &rx_err->bad_rule);
+	if (err) {
 		mlx5_core_err(mdev, "fail to add psp rx misc. err drop rule err=%d\n",
 			      err);
 		goto out_err;
 	}
-	rx_err->bad_rule = fte;
 
 	goto out_spec;
 
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 05/15] net/mlx5e: psp: Use helpers for steering object manipulation
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

Add helper functions for creating and destroying PSP steering objects to
reduce code duplication.
This will become more relevant in future patches which add more steering
tables/groups/flows.

One nice side-effect of this is that the cleanup functions become
idempotent and can be used instead of long goto chains. This further
simplifies the code.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 304 +++++++++---------
 1 file changed, 149 insertions(+), 155 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index 5c34c0be997a..a1c7ca4ae722 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -73,38 +73,103 @@ static enum mlx5_traffic_types fs_psp2tt(enum accel_fs_psp_type i)
 	return MLX5_TT_IPV6_UDP;
 }
 
-static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs,
-					   struct mlx5e_psp_rx_err *rx_err)
+static int accel_psp_fs_create_ft(struct mlx5e_psp_fs *fs,
+				  struct mlx5_flow_table_attr *ft_attr,
+				  struct mlx5_flow_table **ft)
 {
-	if (rx_err->bad_rule) {
-		mlx5_del_flow_rules(rx_err->bad_rule);
-		rx_err->bad_rule = NULL;
+	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false);
+	int err = 0;
+
+	*ft = mlx5_create_auto_grouped_flow_table(ns, ft_attr);
+	if (IS_ERR(*ft)) {
+		err = PTR_ERR(*ft);
+		*ft = NULL;
 	}
 
-	if (rx_err->err_rule) {
-		mlx5_del_flow_rules(rx_err->err_rule);
-		rx_err->err_rule = NULL;
+	return err;
+}
+
+static void accel_psp_fs_destroy_ft(struct mlx5_flow_table **table)
+{
+	if (*table) {
+		mlx5_destroy_flow_table(*table);
+		*table = NULL;
+	}
+}
+
+static void accel_psp_fs_del_flow_rule(struct mlx5_flow_handle **rule)
+{
+	if (*rule) {
+		mlx5_del_flow_rules(*rule);
+		*rule = NULL;
 	}
+}
+
+static int accel_psp_fs_create_miss_group(struct mlx5_flow_table *ft,
+					  struct mlx5_flow_group **group)
+{
+	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
+	u32 *in = kvzalloc(inlen, GFP_KERNEL);
+	int err = 0;
+
+	if (!in)
+		return -ENOMEM;
 
-	if (rx_err->auth_fail_rule) {
-		mlx5_del_flow_rules(rx_err->auth_fail_rule);
-		rx_err->auth_fail_rule = NULL;
+	MLX5_SET(create_flow_group_in, in, start_flow_index, ft->max_fte - 1);
+	MLX5_SET(create_flow_group_in, in, end_flow_index, ft->max_fte - 1);
+	*group = mlx5_create_flow_group(ft, in);
+	if (IS_ERR(*group)) {
+		err = PTR_ERR(*group);
+		*group = NULL;
 	}
+	kvfree(in);
+
+	return err;
+}
 
-	if (rx_err->rule) {
-		mlx5_del_flow_rules(rx_err->rule);
-		rx_err->rule = NULL;
+static void accel_psp_fs_destroy_flow_group(struct mlx5_flow_group **group)
+{
+	if (*group) {
+		mlx5_destroy_flow_group(*group);
+		*group = NULL;
 	}
+}
 
+static int accel_psp_fs_create_counter(struct mlx5_core_dev *dev,
+				       struct mlx5_fc **counter)
+{
+	*counter = mlx5_fc_create(dev, false);
+	if (IS_ERR(*counter)) {
+		int err = PTR_ERR(*counter);
+
+		*counter = NULL;
+		return err;
+	}
+
+	return 0;
+}
+
+static void accel_psp_fs_destroy_counter(struct mlx5_core_dev *dev,
+					 struct mlx5_fc **counter)
+{
+	if (*counter) {
+		mlx5_fc_destroy(dev, *counter);
+		*counter = NULL;
+	}
+}
+
+static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs,
+					   struct mlx5e_psp_rx_err *rx_err)
+{
+	accel_psp_fs_del_flow_rule(&rx_err->bad_rule);
+	accel_psp_fs_del_flow_rule(&rx_err->err_rule);
+	accel_psp_fs_del_flow_rule(&rx_err->auth_fail_rule);
+	accel_psp_fs_del_flow_rule(&rx_err->rule);
 	if (rx_err->copy_modify_hdr) {
 		mlx5_modify_header_dealloc(fs->mdev, rx_err->copy_modify_hdr);
 		rx_err->copy_modify_hdr = NULL;
 	}
-
-	if (rx_err->ft) {
-		mlx5_destroy_flow_table(rx_err->ft);
-		rx_err->ft = NULL;
-	}
+	accel_psp_fs_destroy_ft(&rx_err->ft);
 }
 
 static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec *spec,
@@ -124,7 +189,6 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 				  struct mlx5e_accel_fs_psp_prot *fs_prot,
 				  struct mlx5e_psp_rx_err *rx_err)
 {
-	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false);
 	u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {};
 	struct mlx5_flow_table_attr ft_attr = {};
 	struct mlx5_core_dev *mdev = fs->mdev;
@@ -133,7 +197,6 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 	struct mlx5_modify_hdr *modify_hdr;
 	struct mlx5_flow_handle *fte;
 	struct mlx5_flow_spec *spec;
-	struct mlx5_flow_table *ft;
 	int err = 0;
 
 	spec = kzalloc_obj(*spec);
@@ -144,14 +207,12 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 	ft_attr.autogroup.max_num_groups = 2;
 	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL;
 	ft_attr.prio = MLX5E_NIC_PRIO;
-	ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
-	if (IS_ERR(ft)) {
-		err = PTR_ERR(ft);
+	err = accel_psp_fs_create_ft(fs, &ft_attr, &rx_err->ft);
+	if (err) {
 		mlx5_core_err(fs->mdev,
 			      "fail to create psp rx inline ft err=%d\n", err);
-		goto out_spec;
+		goto out_err;
 	}
-	rx_err->ft = ft;
 
 	/* Action to copy 7 bit psp_syndrome to regB[23:29] */
 	MLX5_SET(copy_action_in, action, action_type, MLX5_ACTION_TYPE_COPY);
@@ -167,7 +228,7 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 		err = PTR_ERR(modify_hdr);
 		mlx5_core_err(mdev,
 			      "fail to alloc psp copy modify_header_id err=%d\n", err);
-		goto out_ft;
+		goto out_err;
 	}
 	rx_err->copy_modify_hdr = modify_hdr;
 
@@ -184,8 +245,9 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 	fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 2);
 	if (IS_ERR(fte)) {
 		err = PTR_ERR(fte);
-		mlx5_core_err(mdev, "fail to add psp rx err copy rule err=%d\n", err);
-		goto out_modhdr;
+		mlx5_core_err(mdev, "fail to add psp rx err rule err=%d\n",
+			      err);
+		goto out_err;
 	}
 	rx_err->rule = fte;
 
@@ -203,7 +265,7 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 		err = PTR_ERR(fte);
 		mlx5_core_err(mdev, "fail to add psp rx auth fail drop rule err=%d\n",
 			      err);
-		goto out_drop_rule;
+		goto out_err;
 	}
 	rx_err->auth_fail_rule = fte;
 
@@ -221,7 +283,7 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 		err = PTR_ERR(fte);
 		mlx5_core_err(mdev, "fail to add psp rx framing err drop rule err=%d\n",
 			      err);
-		goto out_drop_auth_fail_rule;
+		goto out_err;
 	}
 	rx_err->err_rule = fte;
 
@@ -238,27 +300,14 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 		err = PTR_ERR(fte);
 		mlx5_core_err(mdev, "fail to add psp rx misc. err drop rule err=%d\n",
 			      err);
-		goto out_drop_error_rule;
+		goto out_err;
 	}
 	rx_err->bad_rule = fte;
 
 	goto out_spec;
 
-out_drop_error_rule:
-	mlx5_del_flow_rules(rx_err->err_rule);
-	rx_err->err_rule = NULL;
-out_drop_auth_fail_rule:
-	mlx5_del_flow_rules(rx_err->auth_fail_rule);
-	rx_err->auth_fail_rule = NULL;
-out_drop_rule:
-	mlx5_del_flow_rules(rx_err->rule);
-	rx_err->rule = NULL;
-out_modhdr:
-	mlx5_modify_header_dealloc(mdev, modify_hdr);
-	rx_err->copy_modify_hdr = NULL;
-out_ft:
-	mlx5_destroy_flow_table(rx_err->ft);
-	rx_err->ft = NULL;
+out_err:
+	accel_psp_fs_rx_err_destroy_ft(fs, rx_err);
 out_spec:
 	kfree(spec);
 	return err;
@@ -268,30 +317,14 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
 static void accel_psp_fs_rx_fs_destroy(struct mlx5e_psp_fs *fs,
 				       struct mlx5e_accel_fs_psp_prot *fs_prot)
 {
-	if (fs_prot->def_rule) {
-		mlx5_del_flow_rules(fs_prot->def_rule);
-		fs_prot->def_rule = NULL;
-	}
-
+	accel_psp_fs_del_flow_rule(&fs_prot->def_rule);
 	if (fs_prot->rx_modify_hdr) {
 		mlx5_modify_header_dealloc(fs->mdev, fs_prot->rx_modify_hdr);
 		fs_prot->rx_modify_hdr = NULL;
 	}
-
-	if (fs_prot->miss_rule) {
-		mlx5_del_flow_rules(fs_prot->miss_rule);
-		fs_prot->miss_rule = NULL;
-	}
-
-	if (fs_prot->miss_group) {
-		mlx5_destroy_flow_group(fs_prot->miss_group);
-		fs_prot->miss_group = NULL;
-	}
-
-	if (fs_prot->ft) {
-		mlx5_destroy_flow_table(fs_prot->ft);
-		fs_prot->ft = NULL;
-	}
+	accel_psp_fs_del_flow_rule(&fs_prot->miss_rule);
+	accel_psp_fs_destroy_flow_group(&fs_prot->miss_group);
+	accel_psp_fs_destroy_ft(&fs_prot->ft);
 }
 
 static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port)
@@ -306,55 +339,42 @@ static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port)
 static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs,
 				     struct mlx5e_accel_fs_psp_prot *fs_prot)
 {
-	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false);
 	u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {};
-	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
 	struct mlx5_modify_hdr *modify_hdr = NULL;
 	struct mlx5_flow_table_attr ft_attr = {};
 	struct mlx5_flow_destination dest = {};
 	struct mlx5_core_dev *mdev = fs->mdev;
-	struct mlx5_flow_group *miss_group;
 	MLX5_DECLARE_FLOW_ACT(flow_act);
 	struct mlx5_flow_handle *rule;
 	struct mlx5_flow_spec *spec;
-	struct mlx5_flow_table *ft;
-	u32 *flow_group_in;
 	int err = 0;
 
-	flow_group_in = kvzalloc(inlen, GFP_KERNEL);
 	spec = kvzalloc_obj(*spec);
-	if (!flow_group_in || !spec) {
-		err = -ENOMEM;
-		goto out;
-	}
+	if (!spec)
+		return -ENOMEM;
 
 	/* Create FT */
 	ft_attr.max_fte = 2;
 	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_LEVEL;
-	ft_attr.prio = MLX5E_NIC_PRIO;
 	ft_attr.autogroup.num_reserved_entries = 1;
 	ft_attr.autogroup.max_num_groups = 1;
-	ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
-	if (IS_ERR(ft)) {
-		err = PTR_ERR(ft);
+	ft_attr.prio = MLX5E_NIC_PRIO;
+	err = accel_psp_fs_create_ft(fs, &ft_attr, &fs_prot->ft);
+	if (err) {
 		mlx5_core_err(mdev, "fail to create psp rx ft err=%d\n", err);
 		goto out_err;
 	}
-	fs_prot->ft = ft;
 
 	/* Create miss_group */
-	MLX5_SET(create_flow_group_in, flow_group_in, start_flow_index, ft->max_fte - 1);
-	MLX5_SET(create_flow_group_in, flow_group_in, end_flow_index, ft->max_fte - 1);
-	miss_group = mlx5_create_flow_group(ft, flow_group_in);
-	if (IS_ERR(miss_group)) {
-		err = PTR_ERR(miss_group);
+	err = accel_psp_fs_create_miss_group(fs_prot->ft, &fs_prot->miss_group);
+	if (err) {
 		mlx5_core_err(mdev, "fail to create psp rx miss_group err=%d\n", err);
 		goto out_err;
 	}
-	fs_prot->miss_group = miss_group;
 
 	/* Create miss rule */
-	rule = mlx5_add_flow_rules(ft, spec, &flow_act, &fs_prot->default_dest, 1);
+	rule = mlx5_add_flow_rules(fs_prot->ft, spec, &flow_act,
+				   &fs_prot->default_dest, 1);
 	if (IS_ERR(rule)) {
 		err = PTR_ERR(rule);
 		mlx5_core_err(mdev, "fail to create psp rx miss_rule err=%d\n", err);
@@ -399,12 +419,11 @@ static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs,
 	}
 
 	fs_prot->def_rule = rule;
-	goto out;
+	goto out_spec;
 
 out_err:
 	accel_psp_fs_rx_fs_destroy(fs, fs_prot);
-out:
-	kvfree(flow_group_in);
+out_spec:
 	kvfree(spec);
 	return err;
 }
@@ -456,82 +475,61 @@ static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs)
 	if (!accel_psp)
 		return;
 
-	mlx5_fc_destroy(fs->mdev, accel_psp->rx_bad_counter);
-	mlx5_fc_destroy(fs->mdev, accel_psp->rx_err_counter);
-	mlx5_fc_destroy(fs->mdev, accel_psp->rx_auth_fail_counter);
-	mlx5_fc_destroy(fs->mdev, accel_psp->rx_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_bad_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_err_counter);
+	accel_psp_fs_destroy_counter(fs->mdev,
+				     &accel_psp->rx_auth_fail_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_counter);
 	kfree(accel_psp);
 	fs->rx_fs = NULL;
 }
 
 static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs)
 {
-	struct mlx5e_accel_fs_psp *accel_psp;
 	struct mlx5_core_dev *mdev = fs->mdev;
-	struct mlx5_fc *flow_counter;
 	int err;
 
-	accel_psp = kzalloc_obj(*accel_psp);
-	if (!accel_psp)
+	fs->rx_fs = kzalloc_obj(*fs->rx_fs);
+	if (!fs->rx_fs)
 		return -ENOMEM;
 
-	flow_counter = mlx5_fc_create(mdev, false);
-	if (IS_ERR(flow_counter)) {
+	err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_counter);
+	if (err) {
 		mlx5_core_warn(mdev,
-			       "fail to create psp rx flow counter err=%pe\n",
-			       flow_counter);
-		err = PTR_ERR(flow_counter);
+			       "fail to create psp rx flow counter err=%d\n",
+			       err);
 		goto out_err;
 	}
-	accel_psp->rx_counter = flow_counter;
 
-	flow_counter = mlx5_fc_create(mdev, false);
-	if (IS_ERR(flow_counter)) {
+	err = accel_psp_fs_create_counter(mdev,
+					  &fs->rx_fs->rx_auth_fail_counter);
+	if (err) {
 		mlx5_core_warn(mdev,
-			       "fail to create psp rx auth fail flow counter err=%pe\n",
-			       flow_counter);
-		err = PTR_ERR(flow_counter);
-		goto out_counter_err;
+			       "fail to create psp rx auth fail flow counter err=%d\n",
+			       err);
+		goto out_err;
 	}
-	accel_psp->rx_auth_fail_counter = flow_counter;
 
-	flow_counter = mlx5_fc_create(mdev, false);
-	if (IS_ERR(flow_counter)) {
+	err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_err_counter);
+	if (err) {
 		mlx5_core_warn(mdev,
-			       "fail to create psp rx error flow counter err=%pe\n",
-			       flow_counter);
-		err = PTR_ERR(flow_counter);
-		goto out_auth_fail_counter_err;
+			       "fail to create psp rx error flow counter err=%d\n",
+			       err);
+		goto out_err;
 	}
-	accel_psp->rx_err_counter = flow_counter;
 
-	flow_counter = mlx5_fc_create(mdev, false);
-	if (IS_ERR(flow_counter)) {
+	err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_bad_counter);
+	if (err) {
 		mlx5_core_warn(mdev,
-			       "fail to create psp rx bad flow counter err=%pe\n",
-			       flow_counter);
-		err = PTR_ERR(flow_counter);
-		goto out_err_counter_err;
+			       "fail to create psp rx bad flow counter err=%d\n",
+			       err);
+		goto out_err;
 	}
-	accel_psp->rx_bad_counter = flow_counter;
-
-	fs->rx_fs = accel_psp;
 
 	return 0;
 
-out_err_counter_err:
-	mlx5_fc_destroy(mdev, accel_psp->rx_err_counter);
-	accel_psp->rx_err_counter = NULL;
-out_auth_fail_counter_err:
-	mlx5_fc_destroy(mdev, accel_psp->rx_auth_fail_counter);
-	accel_psp->rx_auth_fail_counter = NULL;
-out_counter_err:
-	mlx5_fc_destroy(mdev, accel_psp->rx_counter);
-	accel_psp->rx_counter = NULL;
 out_err:
-	kfree(accel_psp);
-	fs->rx_fs = NULL;
-
+	accel_psp_fs_cleanup_rx(fs);
 	return err;
 }
 
@@ -675,12 +673,9 @@ static int accel_psp_fs_tx_create_ft_table(struct mlx5e_psp_fs *fs)
 
 static void accel_psp_fs_tx_destroy(struct mlx5e_psp_tx *tx_fs)
 {
-	if (!tx_fs->ft)
-		return;
-
-	mlx5_del_flow_rules(tx_fs->rule);
-	mlx5_destroy_flow_group(tx_fs->fg);
-	mlx5_destroy_flow_table(tx_fs->ft);
+	accel_psp_fs_del_flow_rule(&tx_fs->rule);
+	accel_psp_fs_destroy_flow_group(&tx_fs->fg);
+	accel_psp_fs_destroy_ft(&tx_fs->ft);
 }
 
 static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs)
@@ -690,7 +685,7 @@ static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs)
 	if (!tx_fs)
 		return;
 
-	mlx5_fc_destroy(fs->mdev, tx_fs->tx_counter);
+	accel_psp_fs_destroy_counter(fs->mdev, &tx_fs->tx_counter);
 	kfree(tx_fs);
 	fs->tx_fs = NULL;
 }
@@ -699,8 +694,8 @@ static int accel_psp_fs_init_tx(struct mlx5e_psp_fs *fs)
 {
 	struct mlx5_core_dev *mdev = fs->mdev;
 	struct mlx5_flow_namespace *ns;
-	struct mlx5_fc *flow_counter;
 	struct mlx5e_psp_tx *tx_fs;
+	int err;
 
 	ns = mlx5_get_flow_namespace(mdev, MLX5_FLOW_NAMESPACE_EGRESS_IPSEC);
 	if (!ns)
@@ -710,15 +705,14 @@ static int accel_psp_fs_init_tx(struct mlx5e_psp_fs *fs)
 	if (!tx_fs)
 		return -ENOMEM;
 
-	flow_counter = mlx5_fc_create(mdev, false);
-	if (IS_ERR(flow_counter)) {
+	err = accel_psp_fs_create_counter(mdev, &tx_fs->tx_counter);
+	if (err) {
 		mlx5_core_warn(mdev,
-			       "fail to create psp tx flow counter err=%pe\n",
-			       flow_counter);
+			       "fail to create psp tx flow counter err=%d\n",
+			       err);
 		kfree(tx_fs);
-		return PTR_ERR(flow_counter);
+		return err;
 	}
-	tx_fs->tx_counter = flow_counter;
 	tx_fs->ns = ns;
 	fs->tx_fs = tx_fs;
 	return 0;
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 04/15] net/mlx5e: psp: Merge rx_err rule add/delete with ft create/delete
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

The rx_err table is different than the others, having separate functions
to create the flow rules in addition to the flow table.
Merge the add/delete rules functions with the ft create/delete functions
for consistency.

Noop change.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 78 +++++++------------
 1 file changed, 30 insertions(+), 48 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index a69c4e2821e9..5c34c0be997a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -73,8 +73,8 @@ static enum mlx5_traffic_types fs_psp2tt(enum accel_fs_psp_type i)
 	return MLX5_TT_IPV6_UDP;
 }
 
-static void accel_psp_fs_rx_err_del_rules(struct mlx5e_psp_fs *fs,
-					  struct mlx5e_psp_rx_err *rx_err)
+static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs,
+					   struct mlx5e_psp_rx_err *rx_err)
 {
 	if (rx_err->bad_rule) {
 		mlx5_del_flow_rules(rx_err->bad_rule);
@@ -100,12 +100,6 @@ static void accel_psp_fs_rx_err_del_rules(struct mlx5e_psp_fs *fs,
 		mlx5_modify_header_dealloc(fs->mdev, rx_err->copy_modify_hdr);
 		rx_err->copy_modify_hdr = NULL;
 	}
-}
-
-static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs,
-					   struct mlx5e_psp_rx_err *rx_err)
-{
-	accel_psp_fs_rx_err_del_rules(fs, rx_err);
 
 	if (rx_err->ft) {
 		mlx5_destroy_flow_table(rx_err->ft);
@@ -125,23 +119,40 @@ static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec *spec,
 	MLX5_SET(fte_match_set_misc2, misc_params_2, psp_syndrome, syndrome);
 }
 
-static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs,
-					struct mlx5e_accel_fs_psp_prot *fs_prot,
-					struct mlx5e_psp_rx_err *rx_err)
+static
+int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
+				  struct mlx5e_accel_fs_psp_prot *fs_prot,
+				  struct mlx5e_psp_rx_err *rx_err)
 {
+	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false);
 	u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {};
+	struct mlx5_flow_table_attr ft_attr = {};
 	struct mlx5_core_dev *mdev = fs->mdev;
 	struct mlx5_flow_destination dest[2];
 	struct mlx5_flow_act flow_act = {};
 	struct mlx5_modify_hdr *modify_hdr;
 	struct mlx5_flow_handle *fte;
 	struct mlx5_flow_spec *spec;
+	struct mlx5_flow_table *ft;
 	int err = 0;
 
 	spec = kzalloc_obj(*spec);
 	if (!spec)
 		return -ENOMEM;
 
+	ft_attr.max_fte = 2;
+	ft_attr.autogroup.max_num_groups = 2;
+	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL;
+	ft_attr.prio = MLX5E_NIC_PRIO;
+	ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
+	if (IS_ERR(ft)) {
+		err = PTR_ERR(ft);
+		mlx5_core_err(fs->mdev,
+			      "fail to create psp rx inline ft err=%d\n", err);
+		goto out_spec;
+	}
+	rx_err->ft = ft;
+
 	/* Action to copy 7 bit psp_syndrome to regB[23:29] */
 	MLX5_SET(copy_action_in, action, action_type, MLX5_ACTION_TYPE_COPY);
 	MLX5_SET(copy_action_in, action, src_field, MLX5_ACTION_IN_FIELD_PSP_SYNDROME);
@@ -156,8 +167,9 @@ static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs,
 		err = PTR_ERR(modify_hdr);
 		mlx5_core_err(mdev,
 			      "fail to alloc psp copy modify_header_id err=%d\n", err);
-		goto out_spec;
+		goto out_ft;
 	}
+	rx_err->copy_modify_hdr = modify_hdr;
 
 	accel_psp_setup_syndrome_match(spec, PSP_OK);
 	/* create fte */
@@ -173,7 +185,7 @@ static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs,
 	if (IS_ERR(fte)) {
 		err = PTR_ERR(fte);
 		mlx5_core_err(mdev, "fail to add psp rx err copy rule err=%d\n", err);
-		goto out;
+		goto out_modhdr;
 	}
 	rx_err->rule = fte;
 
@@ -230,8 +242,6 @@ static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs,
 	}
 	rx_err->bad_rule = fte;
 
-	rx_err->copy_modify_hdr = modify_hdr;
-
 	goto out_spec;
 
 out_drop_error_rule:
@@ -243,45 +253,17 @@ static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs,
 out_drop_rule:
 	mlx5_del_flow_rules(rx_err->rule);
 	rx_err->rule = NULL;
-out:
+out_modhdr:
 	mlx5_modify_header_dealloc(mdev, modify_hdr);
+	rx_err->copy_modify_hdr = NULL;
+out_ft:
+	mlx5_destroy_flow_table(rx_err->ft);
+	rx_err->ft = NULL;
 out_spec:
 	kfree(spec);
 	return err;
 }
 
-static int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
-					 struct mlx5e_accel_fs_psp_prot *fs_prot,
-					 struct mlx5e_psp_rx_err *rx_err)
-{
-	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false);
-	struct mlx5_flow_table_attr ft_attr = {};
-	struct mlx5_flow_table *ft;
-	int err;
-
-	ft_attr.max_fte = 2;
-	ft_attr.autogroup.max_num_groups = 2;
-	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL; // MLX5E_ACCEL_FS_TCP_FT_LEVEL
-	ft_attr.prio = MLX5E_NIC_PRIO;
-	ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
-	if (IS_ERR(ft)) {
-		err = PTR_ERR(ft);
-		mlx5_core_err(fs->mdev, "fail to create psp rx inline ft err=%d\n", err);
-		return err;
-	}
-
-	rx_err->ft = ft;
-	err = accel_psp_fs_rx_err_add_rule(fs, fs_prot, rx_err);
-	if (err)
-		goto out_err;
-
-	return 0;
-
-out_err:
-	mlx5_destroy_flow_table(ft);
-	rx_err->ft = NULL;
-	return err;
-}
 
 static void accel_psp_fs_rx_fs_destroy(struct mlx5e_psp_fs *fs,
 				       struct mlx5e_accel_fs_psp_prot *fs_prot)
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 03/15] net/mlx5e: psp: Remove unneeded ref counting for PSP steering
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

PSP steering uses reference counting for TX and RX steering tables, but
there's only a single reference for each acquired and thus the reference
counting is unnecessary.

Remove it and consolidate functions to simplify the code.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 129 +++++-------------
 1 file changed, 33 insertions(+), 96 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index d4686b5af776..a69c4e2821e9 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -26,7 +26,6 @@ struct mlx5e_psp_tx {
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_group *fg;
 	struct mlx5_flow_handle *rule;
-	u32 refcnt;
 	struct mlx5_fc *tx_counter;
 };
 
@@ -46,7 +45,6 @@ struct mlx5e_accel_fs_psp_prot {
 	struct mlx5_modify_hdr *rx_modify_hdr;
 	struct mlx5_flow_destination default_dest;
 	struct mlx5e_psp_rx_err rx_err;
-	u32 refcnt;
 	struct mlx5_flow_handle *def_rule;
 };
 
@@ -469,75 +467,18 @@ static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ
 	return err;
 }
 
-static int accel_psp_fs_rx_ft_get(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type)
-{
-	struct mlx5e_accel_fs_psp_prot *fs_prot;
-	struct mlx5_flow_destination dest = {};
-	struct mlx5e_accel_fs_psp *accel_psp;
-	struct mlx5_ttc_table *ttc;
-	int err = 0;
-
-	if (!fs || !fs->rx_fs)
-		return -EINVAL;
-
-	ttc = mlx5e_fs_get_ttc(fs->fs, false);
-	accel_psp = fs->rx_fs;
-	fs_prot = &accel_psp->fs_prot[type];
-	if (fs_prot->refcnt++)
-		return 0;
-
-	/* create FT */
-	err = accel_psp_fs_rx_create(fs, type);
-	if (err) {
-		fs_prot->refcnt--;
-		return err;
-	}
-
-	/* connect */
-	dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
-	dest.ft = fs_prot->ft;
-	mlx5_ttc_fwd_dest(ttc, fs_psp2tt(type), &dest);
-
-	return 0;
-}
-
-static void accel_psp_fs_rx_ft_put(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type)
-{
-	struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false);
-	struct mlx5e_accel_fs_psp_prot *fs_prot;
-	struct mlx5e_accel_fs_psp *accel_psp;
-
-	accel_psp = fs->rx_fs;
-	fs_prot = &accel_psp->fs_prot[type];
-	if (--fs_prot->refcnt)
-		return;
-
-	/* disconnect */
-	mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(type));
-
-	/* remove FT */
-	accel_psp_fs_rx_destroy(fs, type);
-}
-
 static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs)
 {
-	struct mlx5e_accel_fs_psp_prot *fs_prot;
-	struct mlx5e_accel_fs_psp *accel_psp;
-	enum accel_fs_psp_type i;
+	struct mlx5e_accel_fs_psp *accel_psp = fs->rx_fs;
 
-	if (!fs->rx_fs)
+	if (!accel_psp)
 		return;
 
-	accel_psp = fs->rx_fs;
 	mlx5_fc_destroy(fs->mdev, accel_psp->rx_bad_counter);
 	mlx5_fc_destroy(fs->mdev, accel_psp->rx_err_counter);
 	mlx5_fc_destroy(fs->mdev, accel_psp->rx_auth_fail_counter);
 	mlx5_fc_destroy(fs->mdev, accel_psp->rx_counter);
-	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
-		fs_prot = &accel_psp->fs_prot[i];
-		WARN_ON(fs_prot->refcnt);
-	}
-	kfree(fs->rx_fs);
+	kfree(accel_psp);
 	fs->rx_fs = NULL;
 }
 
@@ -614,17 +555,27 @@ static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs)
 
 void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv)
 {
+	struct mlx5_ttc_table *ttc;
+	struct mlx5e_psp_fs *fs;
 	int i;
 
 	if (!priv->psp)
 		return;
 
-	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++)
-		accel_psp_fs_rx_ft_put(priv->psp->fs, i);
+	fs = priv->psp->fs;
+	ttc = mlx5e_fs_get_ttc(fs->fs, false);
+	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
+		/* disconnect */
+		mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i));
+
+		/* remove FT */
+		accel_psp_fs_rx_destroy(fs, i);
+	}
 }
 
 int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 {
+	struct mlx5_ttc_table *ttc;
 	struct mlx5e_psp_fs *fs;
 	int err, i;
 
@@ -632,19 +583,30 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
 		return 0;
 
 	fs = priv->psp->fs;
+	ttc = mlx5e_fs_get_ttc(fs->fs, false);
+
 	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
-		err = accel_psp_fs_rx_ft_get(fs, i);
+		struct mlx5e_accel_fs_psp_prot *fs_prot;
+		struct mlx5_flow_destination dest = {};
+
+		/* create FT */
+		err = accel_psp_fs_rx_create(fs, i);
 		if (err)
 			goto out_err;
+
+		/* connect */
+		dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
+		fs_prot = &fs->rx_fs->fs_prot[i];
+		dest.ft = fs_prot->ft;
+		mlx5_ttc_fwd_dest(ttc, fs_psp2tt(i), &dest);
 	}
 
 	return 0;
 
 out_err:
-	i--;
-	while (i >= 0) {
-		accel_psp_fs_rx_ft_put(fs, i);
-		--i;
+	while (--i >= 0) {
+		mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i));
+		accel_psp_fs_rx_destroy(fs, i);
 	}
 
 	return err;
@@ -739,30 +701,6 @@ static void accel_psp_fs_tx_destroy(struct mlx5e_psp_tx *tx_fs)
 	mlx5_destroy_flow_table(tx_fs->ft);
 }
 
-static int accel_psp_fs_tx_ft_get(struct mlx5e_psp_fs *fs)
-{
-	struct mlx5e_psp_tx *tx_fs = fs->tx_fs;
-	int err;
-
-	if (tx_fs->refcnt++)
-		return 0;
-
-	err = accel_psp_fs_tx_create_ft_table(fs);
-	if (err)
-		tx_fs->refcnt--;
-	return err;
-}
-
-static void accel_psp_fs_tx_ft_put(struct mlx5e_psp_fs *fs)
-{
-	struct mlx5e_psp_tx *tx_fs = fs->tx_fs;
-
-	if (--tx_fs->refcnt)
-		return;
-
-	accel_psp_fs_tx_destroy(tx_fs);
-}
-
 static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs)
 {
 	struct mlx5e_psp_tx *tx_fs = fs->tx_fs;
@@ -771,7 +709,6 @@ static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs)
 		return;
 
 	mlx5_fc_destroy(fs->mdev, tx_fs->tx_counter);
-	WARN_ON(tx_fs->refcnt);
 	kfree(tx_fs);
 	fs->tx_fs = NULL;
 }
@@ -844,7 +781,7 @@ void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv)
 	if (!priv->psp)
 		return;
 
-	accel_psp_fs_tx_ft_put(priv->psp->fs);
+	accel_psp_fs_tx_destroy(priv->psp->fs->tx_fs);
 }
 
 int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
@@ -852,7 +789,7 @@ int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
 	if (!priv->psp)
 		return 0;
 
-	return accel_psp_fs_tx_ft_get(priv->psp->fs);
+	return accel_psp_fs_tx_create_ft_table(priv->psp->fs);
 }
 
 static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs)
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 02/15] net/mlx5e: psp: Remove PSP steering mutexes
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

PSP steering uses three mutexes to serialize steering rule init/cleanup.
But init/cleanup are already serialized with the higher level devlink
lock (for both device init and esw mode changes), so there's no need for
multiple additional mutexes.

Remove them to make room for the new changes.
Later in the series, the netdev lock will be used to serialize PSP
steering changes from multiple sources, so don't bother adding
assertions now only for them to be overwritten later.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 43 +++----------------
 1 file changed, 7 insertions(+), 36 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index 4f2fa6756b82..d4686b5af776 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -26,7 +26,6 @@ struct mlx5e_psp_tx {
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_group *fg;
 	struct mlx5_flow_handle *rule;
-	struct mutex mutex; /* Protect PSP TX steering */
 	u32 refcnt;
 	struct mlx5_fc *tx_counter;
 };
@@ -48,7 +47,6 @@ struct mlx5e_accel_fs_psp_prot {
 	struct mlx5_flow_destination default_dest;
 	struct mlx5e_psp_rx_err rx_err;
 	u32 refcnt;
-	struct mutex prot_mutex; /* protect ESP4/ESP6 protocol */
 	struct mlx5_flow_handle *def_rule;
 };
 
@@ -485,15 +483,14 @@ static int accel_psp_fs_rx_ft_get(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ
 	ttc = mlx5e_fs_get_ttc(fs->fs, false);
 	accel_psp = fs->rx_fs;
 	fs_prot = &accel_psp->fs_prot[type];
-	mutex_lock(&fs_prot->prot_mutex);
 	if (fs_prot->refcnt++)
-		goto out;
+		return 0;
 
 	/* create FT */
 	err = accel_psp_fs_rx_create(fs, type);
 	if (err) {
 		fs_prot->refcnt--;
-		goto out;
+		return err;
 	}
 
 	/* connect */
@@ -501,9 +498,7 @@ static int accel_psp_fs_rx_ft_get(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ
 	dest.ft = fs_prot->ft;
 	mlx5_ttc_fwd_dest(ttc, fs_psp2tt(type), &dest);
 
-out:
-	mutex_unlock(&fs_prot->prot_mutex);
-	return err;
+	return 0;
 }
 
 static void accel_psp_fs_rx_ft_put(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type)
@@ -514,18 +509,14 @@ static void accel_psp_fs_rx_ft_put(struct mlx5e_psp_fs *fs, enum accel_fs_psp_ty
 
 	accel_psp = fs->rx_fs;
 	fs_prot = &accel_psp->fs_prot[type];
-	mutex_lock(&fs_prot->prot_mutex);
 	if (--fs_prot->refcnt)
-		goto out;
+		return;
 
 	/* disconnect */
 	mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(type));
 
 	/* remove FT */
 	accel_psp_fs_rx_destroy(fs, type);
-
-out:
-	mutex_unlock(&fs_prot->prot_mutex);
 }
 
 static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs)
@@ -544,7 +535,6 @@ static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs)
 	mlx5_fc_destroy(fs->mdev, accel_psp->rx_counter);
 	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
 		fs_prot = &accel_psp->fs_prot[i];
-		mutex_destroy(&fs_prot->prot_mutex);
 		WARN_ON(fs_prot->refcnt);
 	}
 	kfree(fs->rx_fs);
@@ -553,22 +543,15 @@ static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs)
 
 static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs)
 {
-	struct mlx5e_accel_fs_psp_prot *fs_prot;
 	struct mlx5e_accel_fs_psp *accel_psp;
 	struct mlx5_core_dev *mdev = fs->mdev;
 	struct mlx5_fc *flow_counter;
-	enum accel_fs_psp_type i;
 	int err;
 
 	accel_psp = kzalloc_obj(*accel_psp);
 	if (!accel_psp)
 		return -ENOMEM;
 
-	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
-		fs_prot = &accel_psp->fs_prot[i];
-		mutex_init(&fs_prot->prot_mutex);
-	}
-
 	flow_counter = mlx5_fc_create(mdev, false);
 	if (IS_ERR(flow_counter)) {
 		mlx5_core_warn(mdev,
@@ -623,10 +606,6 @@ static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs)
 	mlx5_fc_destroy(mdev, accel_psp->rx_counter);
 	accel_psp->rx_counter = NULL;
 out_err:
-	for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) {
-		fs_prot = &accel_psp->fs_prot[i];
-		mutex_destroy(&fs_prot->prot_mutex);
-	}
 	kfree(accel_psp);
 	fs->rx_fs = NULL;
 
@@ -763,17 +742,14 @@ static void accel_psp_fs_tx_destroy(struct mlx5e_psp_tx *tx_fs)
 static int accel_psp_fs_tx_ft_get(struct mlx5e_psp_fs *fs)
 {
 	struct mlx5e_psp_tx *tx_fs = fs->tx_fs;
-	int err = 0;
+	int err;
 
-	mutex_lock(&tx_fs->mutex);
 	if (tx_fs->refcnt++)
-		goto out;
+		return 0;
 
 	err = accel_psp_fs_tx_create_ft_table(fs);
 	if (err)
 		tx_fs->refcnt--;
-out:
-	mutex_unlock(&tx_fs->mutex);
 	return err;
 }
 
@@ -781,13 +757,10 @@ static void accel_psp_fs_tx_ft_put(struct mlx5e_psp_fs *fs)
 {
 	struct mlx5e_psp_tx *tx_fs = fs->tx_fs;
 
-	mutex_lock(&tx_fs->mutex);
 	if (--tx_fs->refcnt)
-		goto out;
+		return;
 
 	accel_psp_fs_tx_destroy(tx_fs);
-out:
-	mutex_unlock(&tx_fs->mutex);
 }
 
 static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs)
@@ -798,7 +771,6 @@ static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs)
 		return;
 
 	mlx5_fc_destroy(fs->mdev, tx_fs->tx_counter);
-	mutex_destroy(&tx_fs->mutex);
 	WARN_ON(tx_fs->refcnt);
 	kfree(tx_fs);
 	fs->tx_fs = NULL;
@@ -828,7 +800,6 @@ static int accel_psp_fs_init_tx(struct mlx5e_psp_fs *fs)
 		return PTR_ERR(flow_counter);
 	}
 	tx_fs->tx_counter = flow_counter;
-	mutex_init(&tx_fs->mutex);
 	tx_fs->ns = ns;
 	fs->tx_fs = tx_fs;
 	return 0;
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 01/15] net/mlx5e: psp: Rename the saved psp_dev to 'psd'
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn
In-Reply-To: <20260707130858.969928-1-tariqt@nvidia.com>

From: Cosmin Ratiu <cratiu@nvidia.com>

This is the canonical name used in the core, so try to be consistent.
No-op change.

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c    | 8 ++++----
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h    | 2 +-
 .../net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c   | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
index d9adb993e64d..4f2fa6756b82 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
@@ -1072,11 +1072,11 @@ void mlx5e_psp_unregister(struct mlx5e_priv *priv)
 {
 	struct mlx5e_psp *psp = priv->psp;
 
-	if (!psp || !psp->psp)
+	if (!psp || !psp->psd)
 		return;
 
-	psp_dev_unregister(psp->psp);
-	psp->psp = NULL;
+	psp_dev_unregister(psp->psd);
+	psp->psd = NULL;
 }
 
 void mlx5e_psp_register(struct mlx5e_priv *priv)
@@ -1100,7 +1100,7 @@ void mlx5e_psp_register(struct mlx5e_priv *priv)
 			      psd);
 		return;
 	}
-	psp->psp = psd;
+	psp->psd = psd;
 }
 
 int mlx5e_psp_init(struct mlx5e_priv *priv)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
index 6b62fef0d9a7..a53f90f7c341 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
@@ -23,7 +23,7 @@ struct mlx5e_psp_stats {
 };
 
 struct mlx5e_psp {
-	struct psp_dev *psp;
+	struct psp_dev *psd;
 	struct psp_dev_caps caps;
 	struct mlx5e_psp_fs *fs;
 	atomic_t tx_key_cnt;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
index ef7f5338540f..c2f9899d23a5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
@@ -124,7 +124,7 @@ bool mlx5e_psp_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff *
 {
 	u32 psp_meta_data = be32_to_cpu(cqe->ft_metadata);
 	struct mlx5e_priv *priv = netdev_priv(netdev);
-	u16 dev_id = priv->psp->psp->id;
+	u16 dev_id = priv->psp->psd->id;
 	bool strip_icv = true;
 	u8 generation = 0;
 
-- 
2.44.0


^ permalink raw reply related

* [PATCH net-next 00/15] net/mlx5e: PSP cleanups and improvements
From: Tariq Toukan @ 2026-07-07 13:08 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni
  Cc: Aleksandr Loktionov, Boris Pismenny, Chris Mi, Cosmin Ratiu,
	Daniel Zahka, Dragos Tatulea, Gal Pressman, Jacob Keller,
	Jianbo Liu, Lama Kayal, Leon Romanovsky, linux-kernel, linux-rdma,
	Mark Bloch, Raed Salem, Rahul Rameshbabu, Saeed Mahameed,
	Stanislav Fomichev, Stanislav Fomichev, Tariq Toukan,
	Willem de Bruijn

Hi,

This series by Cosmin refactors mlx5 PSP support in preparation for
HW-GRO support.
There are almost no functionality changes in all but the last two
patches, which address a long-standing TODO in mlx5e_psp_set_config().

Regards,
Tariq

Cosmin Ratiu (15):
  net/mlx5e: psp: Rename the saved psp_dev to 'psd'
  net/mlx5e: psp: Remove PSP steering mutexes
  net/mlx5e: psp: Remove unneeded ref counting for PSP steering
  net/mlx5e: psp: Merge rx_err rule add/delete with ft create/delete
  net/mlx5e: psp: Use helpers for steering object manipulation
  net/mlx5e: psp: Factor out drop rule creation code
  net/mlx5e: psp: Remove unused PSP syndrome copy action
  net/mlx5e: psp: Rename and consolidate steering functions
  net/mlx5e: psp: Adjust rx_check FT size and use a drop_group
  net/mlx5e: psp: Add an RX steering table
  net/mlx5e: psp: Use a single rx_check table
  net/mlx5e: psp: Flatten steering structures
  net/mlx5e: psp: Make PSP steering config dynamic
  net/mlx5e: Return errors from profile->enable
  net/mlx5e: psp: Report PSP dev registration errors

 drivers/net/ethernet/mellanox/mlx5/core/en.h  |    2 +-
 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |    7 +-
 .../mellanox/mlx5/core/en_accel/en_accel.h    |   19 +-
 .../mellanox/mlx5/core/en_accel/psp.c         | 1007 ++++++++---------
 .../mellanox/mlx5/core/en_accel/psp.h         |   18 +-
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    |   13 +-
 .../mellanox/mlx5/core/en_accel/psp_rxtx.h    |    3 +-
 .../net/ethernet/mellanox/mlx5/core/en_main.c |   23 +-
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  |    8 +-
 9 files changed, 516 insertions(+), 584 deletions(-)


base-commit: 31816fc5d9acf8cdf226cdd0dc296e8cf15cc033
-- 
2.44.0


^ permalink raw reply

* Re: [PATCH net] nfc: pn533: hold a reference to the request skb during send_frame
From: Simon Horman @ 2026-07-07 12:55 UTC (permalink / raw)
  To: Yinhao Hu
  Cc: David Heidelberg, Kees Cook, Krzysztof Kozlowski, Dan Carpenter,
	Jakub Kicinski, Samuel Ortiz, Michael Thalmeier, netdev, dzm91,
	hust-os-kernel-patches
In-Reply-To: <20260626073434.3977525-1-dddddd@hust.edu.cn>

On Fri, Jun 26, 2026 at 12:34:34AM -0700, Yinhao Hu wrote:
> __pn533_send_async() publishes the command and then calls
> dev->phy_ops->send_frame(). Once dev->cmd is set, an incoming frame
> can be matched to this command: the I2C threaded IRQ runs
> pn533_recv_frame(), which queues cmd_complete_work, and
> pn533_send_async_complete() frees cmd->req with consume_skb().
> 
> On the I2C transport, pn533_i2c_send_frame() still dereferences the same
> skb after i2c_master_send() returns, so a completion that races the
> send can free the skb while the transport is still using it.
> 
> The request skb is owned by the command object and may be freed by
> command completion at any time after dev->cmd is published, so the
> transport send path must not assume it stays alive. Hold a temporary
> reference to the request skb across the send_frame() call so the
> transport always sees a live skb even if completion races the send.
> Add a pn533_send_cmd_frame() helper and use it from all three send
> paths.
> 
> Fixes: 9815c7cf22da ("NFC: pn533: Separate physical layer from the core implementation")
> Signed-off-by: Yinhao Hu <dddddd@hust.edu.cn>

Reviewed-by: Simon Horman <horms@kernel.org>

There is an AI generated review of this patch available on sashiko.dev.
You may want to consider the issues raised there in the context
of possible follow-up. But I don't think that needs to impede the progress
of this patch.


^ permalink raw reply

* Re: [PATCH net-next 2/6] net: stmmac: mediatek: add PERI_ETH_CTRLx register offset in platform data
From: Andrew Lunn @ 2026-07-07 12:45 UTC (permalink / raw)
  To: Louis-Alexis Eyraud
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Richard Cochran, Matthias Brugger, AngeloGioacchino Del Regno,
	Biao Huang, Maxime Coquelin, Alexandre Torgue, maxime.chevallier,
	rmk+kernel, kernel, netdev, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek, linux-stm32
In-Reply-To: <20260707-dwmac-mediatek-mt8189-v1-2-17f345eaaca3@collabora.com>

> +	.peri_eth_ctrl_offset = MT8195_PERI_ETH_CTRL_BASE,

nitpick:

Could the naming be more consistent? offset vs base?

	Andrew

^ permalink raw reply

* Re: [PATCH net-next 1/6] dt-bindings: net: mediatek-dwmac: add support for MT8189 SoC
From: Andrew Lunn @ 2026-07-07 12:42 UTC (permalink / raw)
  To: Louis-Alexis Eyraud
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Richard Cochran, Matthias Brugger, AngeloGioacchino Del Regno,
	Biao Huang, Maxime Coquelin, Alexandre Torgue, maxime.chevallier,
	rmk+kernel, kernel, netdev, devicetree, linux-kernel,
	linux-arm-kernel, linux-mediatek, linux-stm32
In-Reply-To: <20260707-dwmac-mediatek-mt8189-v1-1-17f345eaaca3@collabora.com>

> +  - if:
> +      properties:
> +        compatible:
> +          contains:
> +            enum:
> +              - mediatek,mt8189-gmac
> +    then:
> +      properties:
> +        clocks:
> +          items:
> +            - description: MAC Main clock
> +            - description: PTP clock
> +            - description: RMII reference clock provided by MAC

Since this is a MAC, it sounds like it is consuming its own clock?

	Andrew

^ permalink raw reply

* Re: [PATCH net-next V4 4/6] devlink: Apply eswitch mode boot defaults
From: Jiri Pirko @ 2026-07-07 12:39 UTC (permalink / raw)
  To: Mark Bloch
  Cc: Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Saeed Mahameed, Leon Romanovsky, Tariq Toukan, Andrew Lunn,
	Jonathan Corbet, Shuah Khan, netdev, linux-rdma, linux-doc
In-Reply-To: <4fa57470-0d4f-43dc-af4d-e66ddb450923@nvidia.com>

Fri, Jul 03, 2026 at 08:27:28PM +0200, mbloch@nvidia.com wrote:
>
>
>On 02/07/2026 10:52, Jiri Pirko wrote:
>> Wed, Jul 01, 2026 at 07:42:57PM +0200, mbloch@nvidia.com wrote:
>>>
>>>
>>> On 01/07/2026 17:09, Jiri Pirko wrote:
>>>> Wed, Jul 01, 2026 at 02:57:21PM +0200, mbloch@nvidia.com wrote:
>>>>>
>>>>>
>>>>> On 01/07/2026 12:48, Jiri Pirko wrote:
>>>>>> Mon, Jun 29, 2026 at 08:20:59PM +0200, mbloch@nvidia.com wrote:
>>>>>>> Apply parsed devlink_eswitch_mode= defaults after devlink registration
>>>>>>> and after successful reload.
>>>>>>>
>>>>>>> devl_register() may still be called before the device is ready for an
>>>>>>
>>>>>> How so? I would assume that driver calls devl_register only after
>>>>>> everything is up and running and ready. If not, isn't it a bug?
>>>>>>
>>>>>
>>>>> You would think so :)
>>>>>
>>>>> Some drivers, mlx5 included, call devl_register() while holding the
>>>>> devlink instance lock and then finish setting up state before releasing
>>>>> the lock.
>>>>>
>>>>> In v3 I tried to enforce exactly that model, move devl_register() to
>>>>> be the last thing the driver does. Jakub pushed back on making that a
>>>>> general rule. So in v4 I changed the approach. devl_register() only
>>>>> schedules the work, and the actual eswitch mode change can run only
>>>>> after the driver releases the devlink lock.
>>>>
>>>> Wouldn't it make sense to use a completion instead of loop-reschedule of
>>>> delayed work?
>>>
>>> Just to make sure I understand the suggestion, this would mean that the
>>> work waits until the devlink lock holder drops the lock, and devl_unlock()
>>> would signal it, something like:
>>>
>>> void devl_unlock(struct devlink *devlink)
>>> {
>>> 	ool complete_apply = devlink->default_esw_mode_apply_pending;
>>>
>>> 	mutex_unlock(&devlink->lock);
>>>
>>> 	if (complete_apply)
>>> 		complete(&devlink->default_esw_mode_apply_ready);
>>> }
>>>
>>> That would avoid the retry loop, but it also means the queued work 
>>> sleeps until the driver drops devl_lock. It does keep one worker
>>> blocked per pending instance and adds this default-esw-mode signalling to
>>> the generic devl_unlock() path.
>>>
>>> The delayed retry was meant to avoid a sleeping worker and keep the
>>> instances independent. If one devlink instance is still locked, we just
>>> try it again later while other instances can progress.
>>>
>>> If you prefer the completion approach I can switch to it, but I don't see
>>> it as simpler overall.
>> 
>> Yeah, I don't have preference. I was just wondering. Feel free to leave
>> it as is.
>> 
>> Maybe, instead of "complete", you can schedule with "0" delay in
>> devl_unlock? Well, it does not really need to be delayed work, right?
>> The only single schedule may be done from devl_unlock. That would help
>> to eliminate the rescheduling. Am I missing something?
>
>Yeah, that can work.
>
>The only part I don't really like is adding default-esw-mode specific
>logic to devl_unlock(). But if you are fine with that, I can switch to

Could be a devl_unlock_x variant? Idk.


>this approach.
>
>There is still a small race between mutex_unlock() and queue_work(), where
>someone else can take devl_lock() first. So the worker may still wait on
>the lock, but the window should be small and we get rid of the delayed
>retry loop.

No problem.

>
>Mark
>
>> 
>> 
>>>
>>> Mark
>>>
>>>>
>>>>>
>>>>> Mark
>>>>>
>>>>>>
>>>>>>> eswitch mode change, so keep a per-devlink delayed work item and pending
>>>>>>> flag for the registration path. Registration queues the work, and the
>>>>>>> worker tries to take the devlink instance lock.
>>>>>>>
>>>>>>> If the lock is busy, the worker requeues itself with a delay.
>>>>>>>
>>>>>>> For successful reloads that performed DRIVER_REINIT, devlink_reload()
>>>>>>> already holds the devlink instance lock and the driver has completed
>>>>>>> reload_up(). Clear pending work and apply the default directly from the
>>>>>>> reload path instead of queueing work.
>>>>>>>
>>>>>>> If a user sets eswitch mode through netlink before the pending
>>>>>>> registration work runs, clear the pending flag so the queued default does
>>>>>>> not override that user request. Cancel pending default apply work when
>>>>>>> freeing the devlink instance.
>>>>>>
>>>>>> These AI generated code descriptive messages are generally not very
>>>>>> useful :(
>>>>>>
>>>>>
>>>
>
>

^ permalink raw reply

* RE: [PATCH ethtool-next 2/2] sfpid: print all compliance codes
From: Danielle Ratson @ 2026-07-07 12:37 UTC (permalink / raw)
  To: Aleksander Jan Bajkowski, mkubecek@suse.cz, andrew@lunn.ch,
	kuba@kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com, netdev@vger.kernel.org
In-Reply-To: <20260705200637.2092534-2-olek2@wp.pl>

> -----Original Message-----
> From: Aleksander Jan Bajkowski <olek2@wp.pl>
> Sent: Sunday, 5 July 2026 23:06
> To: mkubecek@suse.cz; andrew@lunn.ch; Danielle Ratson
> <danieller@nvidia.com>; kuba@kernel.org; davem@davemloft.net;
> edumazet@google.com; pabeni@redhat.com; netdev@vger.kernel.org
> Cc: Aleksander Jan Bajkowski <olek2@wp.pl>
> Subject: [PATCH ethtool-next 2/2] sfpid: print all compliance codes
> 
> SFP modules implement multiple compliance codes. This is common for dual-
> rate modules. Before the `json` option was introduced, all compliance codes
> were displayed. Currently, only the last code is displayed. This commit fixes
> that bug. Compliance codes are represented as array.
> 
> Before:
> $ ethtool -m sfp-lan
> ...
> 	Transceiver codes                         : 0x00 0x00 0x00 0x01 0x20 0x40 0x0c
> 0x15 0x00
> 	Transceiver type                          : FC: 100 MBytes/sec</pre>

</pre>? I think it is a leftover or something?

> ...
> $ ethtool --json -m sfp-wan
> [ {
> ...
>         "transceiver_codes": [ 0,0,0,1,32,64,12,21,0 ],
>         "transceiver_type": "FC: 100 MBytes/sec", ...
>     } ]
> 
> After:
> $ ethtool -m sfp-wan
> ...
> 	Transceiver codes                         : 0x00 0x00 0x00 0x01 0x20 0x40 0x0c
> 0x15 0x00
> 	Transceiver type                          : Ethernet: 1000BASE-SX
> 	Transceiver type                          : FC: intermediate distance (I)
> 	Transceiver type                          : FC: Shortwave laser w/o OFC (SN)
> 	Transceiver type                          : FC: Multimode, 62.5um (M6)
> 	Transceiver type                          : FC: Multimode, 50um (M5)
> 	Transceiver type                          : FC: 400 MBytes/sec
> 	Transceiver type                          : FC: 200 MBytes/sec
> 	Transceiver type                          : FC: 100 MBytes/sec
> ...
> $ ethtool --json -m sfp-wan
> [ {

I am a bit confused by the sfp-lan/sfp-wan examples naming. In the last patch the "Before" used "sfp-wan" and the "After" used "sfp-lan". This patch doesn’t follow the same convention. Maybe it is better to use the same module for both before and after.

> ...
>         "transceiver_codes": [ 0,0,0,1,32,64,12,21,0 ],
>         "transceiver_type": [ "Ethernet: 1000BASE-SX","FC: intermediate distance
> (I)","FC: Shortwave laser w/o OFC (SN)","FC: Multimode, 62.5um (M6)","FC:
> Multimode, 50um (M5)","FC: 400 MBytes/sec","FC: 200 MBytes/sec","FC:
> 100 MBytes/sec" ], ...
>     } ]
> 
> Fixes: 4071862f58d8 ("sfpid: Add JSON output handling to --module-info in
> SFF8079 modules")
> Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
> ---

Thanks for sending this fix! 

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox