Skip to contentSkip to conversation

net/mlx5e: PSP cleanups and improvements

PATCH In review Tariq Toukan 6 participants 31 messages Jul 7 – Jul 22

Subsystems (7)
lore
Share & tools
lore

Tariq Toukan

author maintainer
#0 lore raw

cover net/mlx5e: PSP cleanups and improvements

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

Signature · 1 line
2.44.0
author maintainer
#1 lore raw

PATCH 1/15 net/mlx5e: psp: Rename the saved psp_dev to 'psd'

From: Cosmin Ratiu <[email protected]>

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

---
 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(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +4 -4
index d9adb993e64d..4f2fa6756b82 100644
@@ -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)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +1 -1
index 6b62fef0d9a7..a53f90f7c341 100644
@@ -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;
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +1 -1
index ef7f5338540f..c2f9899d23a5 100644
@@ -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;
 
Signature · 1 line
2.44.0
Reviewed-by on v1 1/15
#2 lore raw

RE: [PATCH net-next 01/15] net/mlx5e: psp: Rename the saved psp_dev to 'psd'

Quoted 97 lines

-----Original Message-----
From: Tariq Toukan <[email protected]>
Sent: Tuesday, July 7, 2026 3:09 PM
To: Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]; Paolo Abeni <[email protected]>
Cc: Loktionov, Aleksandr <[email protected]>; Boris Pismenny <[email protected]>; Chris Mi <[email protected]>; Cosmin, Ratiu <[email protected]>; Daniel Zahka <[email protected]>; Dragos Tatulea <[email protected]>; Gal Pressman <[email protected]>; Keller, Jacob E <[email protected]>; Jianbo Liu <[email protected]>; Lama Kayal <[email protected]>; Leon Romanovsky <[email protected]>; [email protected]; [email protected]; Mark Bloch <[email protected]>; Raed Salem <[email protected]>; Rahul Rameshbabu <[email protected]>; Saeed Mahameed <[email protected]>; Stanislav Fomichev <[email protected]>; Stanislav Fomichev <[email protected]>; Tariq Toukan <[email protected]>; Willem de Bruijn <[email protected]>
Subject: [PATCH net-next 01/15] net/mlx5e: psp: Rename the saved psp_dev to 'psd'

From: Cosmin Ratiu <[email protected]>

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

---
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c    | 8 ++++---
(quoted diff) +0 -1
-
 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(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +3 -3
index d9adb993e64d..4f2fa6756b82 100644
@@ -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)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +1 -1
 			      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

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +1 -1
@@ -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

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +1 -2
@@ -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;
 
--
Quoted 1 line

2.44.0

author maintainer
#3 lore raw

PATCH 2/15 net/mlx5e: psp: Remove PSP steering mutexes

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 43 +++----------------
 1 file changed, 7 insertions(+), 36 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +7 -36
index 4f2fa6756b82..d4686b5af776 100644
@@ -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;
Signature · 1 line
2.44.0
Reviewed-by on v1 2/15
#4 lore raw

RE: [PATCH net-next 02/15] net/mlx5e: psp: Remove PSP steering mutexes

Quoted 214 lines

-----Original Message-----
From: Tariq Toukan <[email protected]>
Sent: Tuesday, July 7, 2026 3:09 PM
To: Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]; Paolo Abeni <[email protected]>
Cc: Loktionov, Aleksandr <[email protected]>; Boris Pismenny <[email protected]>; Chris Mi <[email protected]>; Cosmin, Ratiu <[email protected]>; Daniel Zahka <[email protected]>; Dragos Tatulea <[email protected]>; Gal Pressman <[email protected]>; Keller, Jacob E <[email protected]>; Jianbo Liu <[email protected]>; Lama Kayal <[email protected]>; Leon Romanovsky <[email protected]>; [email protected]; [email protected]; Mark Bloch <[email protected]>; Raed Salem <[email protected]>; Rahul Rameshbabu <[email protected]>; Saeed Mahameed <[email protected]>; Stanislav Fomichev <[email protected]>; Stanislav Fomichev <[email protected]>; Tariq Toukan <[email protected]>; Willem de Bruijn <[email protected]>
Subject: [PATCH net-next 02/15] net/mlx5e: psp: Remove PSP steering mutexes

From: Cosmin Ratiu <[email protected]>

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.

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 43 +++---------------
(quoted diff) +0 -1
-
 1 file changed, 7 insertions(+), 36 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +0 -2
index 4f2fa6756b82..d4686b5af776 100644
@@ -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

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +2 -3
 	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

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +1 -3
 	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

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +1 -5
 	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)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +0 -12
 	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) {

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +3 -9
 	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)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +0 -2
 		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;
Quoted 3 lines

return 0;
--
2.44.0

author maintainer
#5 lore raw

PATCH 3/15 net/mlx5e: psp: Remove unneeded ref counting for PSP steering

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 129 +++++-------------
 1 file changed, 33 insertions(+), 96 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +33 -96
index d4686b5af776..a69c4e2821e9 100644
@@ -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)
Signature · 1 line
2.44.0
Reviewed-by on v1 3/15
#6 lore raw

RE: [PATCH net-next 03/15] net/mlx5e: psp: Remove unneeded ref counting for PSP steering

Quoted 49 lines

-----Original Message-----
From: Tariq Toukan <[email protected]>
Sent: Tuesday, July 7, 2026 3:09 PM
To: Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]; Paolo Abeni <[email protected]>
Cc: Loktionov, Aleksandr <[email protected]>; Boris Pismenny <[email protected]>; Chris Mi <[email protected]>; Cosmin, Ratiu <[email protected]>; Daniel Zahka <[email protected]>; Dragos Tatulea <[email protected]>; Gal Pressman <[email protected]>; Keller, Jacob E <[email protected]>; Jianbo Liu <[email protected]>; Lama Kayal <[email protected]>; Leon Romanovsky <[email protected]>; [email protected]; [email protected]; Mark Bloch <[email protected]>; Raed Salem <[email protected]>; Rahul Rameshbabu <[email protected]>; Saeed Mahameed <[email protected]>; Stanislav Fomichev <[email protected]>; Stanislav Fomichev <[email protected]>; Tariq Toukan <[email protected]>; Willem de Bruijn <[email protected]>
Subject: [PATCH net-next 03/15] net/mlx5e: psp: Remove unneeded ref counting for PSP steering

From: Cosmin Ratiu <[email protected]>

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.

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 129 +++++------------
(quoted diff) +0 -1
-
 1 file changed, 33 insertions(+), 96 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +0 -0
index d4686b5af776..a69c4e2821e9 100644
@@ -26,7 +26,6 @@ struct mlx5e_psp_tx {
 	struct mlx5_flow_table *ft;
 	struct mlx5_flow_group *fg;
 	struct mlx5_flow_handle *rule;

...

Quoted 5 lines

}

static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs)
--
2.44.0

author maintainer
#7 lore raw

PATCH 4/15 net/mlx5e: psp: Merge rx_err rule add/delete with ft create/delete

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 78 +++++++------------
 1 file changed, 30 insertions(+), 48 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +30 -48
index a69c4e2821e9..5c34c0be997a 100644
@@ -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)
Signature · 1 line
2.44.0
author maintainer
#8 lore raw

PATCH 5/15 net/mlx5e: psp: Use helpers for steering object manipulation

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 304 +++++++++---------
 1 file changed, 149 insertions(+), 155 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +149 -155
index 5c34c0be997a..a1c7ca4ae722 100644
@@ -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;
Signature · 1 line
2.44.0
author maintainer
#9 lore raw

PATCH 6/15 net/mlx5e: psp: Factor out drop rule creation code

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 65 ++++++++++---------
 1 file changed, 34 insertions(+), 31 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +34 -31
index a1c7ca4ae722..bdf97e373b42 100644
@@ -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;
 
Signature · 1 line
2.44.0
author maintainer
#10 lore raw

PATCH 7/15 net/mlx5e: psp: Remove unused PSP syndrome copy action

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../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(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +1 -29
index bdf97e373b42..534dba678761 100644
@@ -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);
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +0 -11
index c2f9899d23a5..348fd7a96261 100644
@@ -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;
 
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h +1 -2
index 70289c921bd6..2b080c39cc37 100644
@@ -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 {
Signature · 1 line
2.44.0
author maintainer
#11 lore raw

PATCH 8/15 net/mlx5e: psp: Rename and consolidate steering functions

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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}

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 252 +++++++++---------
 1 file changed, 131 insertions(+), 121 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +131 -121
index 534dba678761..c83d62724ff7 100644
@@ -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);
Signature · 1 line
2.44.0
author maintainer
#12 lore raw

PATCH 9/15 net/mlx5e: psp: Adjust rx_check FT size and use a drop_group

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../net/ethernet/mellanox/mlx5/core/en_accel/psp.c  | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +12 -1
index c83d62724ff7..f8b289c50a42 100644
@@ -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 |
Signature · 1 line
2.44.0
author maintainer
#13 lore raw

PATCH 10/15 net/mlx5e: psp: Add an RX steering table

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |   7 +-
 .../mellanox/mlx5/core/en_accel/psp.c         | 149 +++++++++++++++---
 2 files changed, 136 insertions(+), 20 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +6 -1
index 091b80a67189..4973fb473ff0 100644
@@ -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;
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +130 -19

244 lines not on this page · raw message

Signature · 1 line
2.44.0
author maintainer
#14 lore raw

PATCH 11/15 net/mlx5e: psp: Use a single rx_check table

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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).

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 34 +++++++------------
 1 file changed, 12 insertions(+), 22 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +12 -22
index c45241025b16..48bc59045dfe 100644
@@ -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;
Signature · 1 line
2.44.0
author maintainer
#15 lore raw

PATCH 12/15 net/mlx5e: psp: Flatten steering structures

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../mellanox/mlx5/core/en_accel/psp.c         | 257 +++++++-----------
 1 file changed, 97 insertions(+), 160 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +97 -160
index 48bc59045dfe..b713f235a0f7 100644
@@ -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)
Signature · 1 line
2.44.0
author maintainer
#16 lore raw

PATCH 13/15 net/mlx5e: psp: Make PSP steering config dynamic

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 .../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(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +1 -18
index b526b3898c22..3f212e46fc2f 100644
@@ -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);
 }
 
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +52 -21

119 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +0 -12
index a53f90f7c341..57fffcf4a62c 100644
@@ -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)
 {
Signature · 1 line
2.44.0
reviewer
#17 lore raw

Re: [PATCH net-next 13/15] net/mlx5e: psp: Make PSP steering config dynamic

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev
---
--- Patch [13]: [PATCH net-next 13/15] net/mlx5e: psp: Make PSP steering config dynamic --- commit 133d9a32cbf9c1b939ae4ca8473c41624c313951
Author: Cosmin Ratiu <[email protected]>

net/mlx5e: psp: Make PSP steering config dynamic

This commit changes PSP steering tables to only be created when PSP configuration is enabled on a device, instead of at device initialization time. This avoids imposing steering overhead on all UDP packets when PSP is not being used.

Quoted 26 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +1 -12
index b526b3898c22e..3f212e46fc2f9 100644
@@ -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)
 

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv) · line 235

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -6
 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);
 }

[Severity: Critical]
Does removing the unconditional table creation here prevent PSP tables from being restored on device attach or resume?

Since mlx5_accel_psp_fs_cleanup_tx_tables() is still called during device detach or suspend, the PSP steering tables are destroyed. However, because mlx5e_accel_init_tx() no longer recreates them, the tables appear to remain missing after a suspend/resume or detach/attach cycle.

Because software psp_assoc structures remain bound to active sockets, could this leave the device in a state where the hardware TX steering table (which contains the CRYPTO_ENCRYPT action) is missing?

If so, would this cause egress traffic to bypass encryption and be transmitted in plaintext?

#18 lore raw

Re: [PATCH net-next 13/15] net/mlx5e: psp: Make PSP steering config dynamic

Quoted 72 lines · Simon Horman

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
--- Patch [13]: [PATCH net-next 13/15] net/mlx5e: psp: Make PSP steering config dynamic ---
commit 133d9a32cbf9c1b939ae4ca8473c41624c313951
Author: Cosmin Ratiu <[email protected]>

net/mlx5e: psp: Make PSP steering config dynamic

This commit changes PSP steering tables to only be created when PSP configuration is enabled on a device, instead of at device initialization
time. This avoids imposing steering overhead on all UDP packets when PSP
is not being used.

Quoted 38 lines

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 b526b3898c22e..3f212e46fc2f9 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -0
@@ -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) {

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +1 -12
-	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)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -0
@@ -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) {

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -6
-	int err;
-
-	err = mlx5_accel_psp_fs_init_tx_tables(priv);
-	if (err)
-		return err;
-
Quoted 2 lines

  return mlx5e_ktls_init_tx(priv);
 }

[Severity: Critical]
Does removing the unconditional table creation here prevent PSP tables
from being restored on device attach or resume?

Since mlx5_accel_psp_fs_cleanup_tx_tables() is still called during device
detach or suspend, the PSP steering tables are destroyed. However, because
mlx5e_accel_init_tx() no longer recreates them, the tables appear to remain
missing after a suspend/resume or detach/attach cycle.

Quoted 8 lines

Because software psp_assoc structures remain bound to active sockets, could
this leave the device in a state where the hardware TX steering table (which
contains the CRYPTO_ENCRYPT action) is missing?

If so, would this cause egress traffic to bypass encryption and be transmitted in plaintext?

When the device is suspended, 1. all TX keys are released and 2. steering rules are removed. 3. psp state is completely freed, including the configuration intention.

When the device is resumed, psp is reinitialized to a blank state.

Before these changes, psp was also reset to a blank state (no keys, but with steering rules readded). This also broke existing PSP connections.

I guess fixing this behavior during suspend is outside the scope of this series. I don't like it, we should do something about it, but not in this series.

Cosmin.

reviewer
#19 lore raw

Re: [PATCH net-next 13/15] net/mlx5e: psp: Make PSP steering config dynamic

Quoted 86 lines · Cosmin Ratiu
Quoted 72 lines · Simon Horman

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
--- Patch [13]: [PATCH net-next 13/15] net/mlx5e: psp: Make PSP steering config dynamic ---
commit 133d9a32cbf9c1b939ae4ca8473c41624c313951
Author: Cosmin Ratiu <[email protected]>

net/mlx5e: psp: Make PSP steering config dynamic

This commit changes PSP steering tables to only be created when PSP configuration is enabled on a device, instead of at device initialization
time. This avoids imposing steering overhead on all UDP packets when PSP
is not being used.

Quoted 38 lines

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 b526b3898c22e..3f212e46fc2f9 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -0
@@ -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) {

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +1 -12
-	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)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -0
@@ -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) {

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -6
-	int err;
-
-	err = mlx5_accel_psp_fs_init_tx_tables(priv);
-	if (err)
-		return err;
-
Quoted 2 lines

  return mlx5e_ktls_init_tx(priv);
 }

[Severity: Critical]
Does removing the unconditional table creation here prevent PSP tables
from being restored on device attach or resume?

Since mlx5_accel_psp_fs_cleanup_tx_tables() is still called during device
detach or suspend, the PSP steering tables are destroyed. However, because
mlx5e_accel_init_tx() no longer recreates them, the tables appear to remain
missing after a suspend/resume or detach/attach cycle.

Quoted 8 lines

Because software psp_assoc structures remain bound to active sockets, could
this leave the device in a state where the hardware TX steering table (which
contains the CRYPTO_ENCRYPT action) is missing?

If so, would this cause egress traffic to bypass encryption and be transmitted in plaintext?

When the device is suspended, 1. all TX keys are released and 2. steering rules are removed. 3. psp state is completely freed, including the configuration intention.

Quoted 8 lines

When the device is resumed, psp is reinitialized to a blank state.

Before these changes, psp was also reset to a blank state (no keys, but with steering rules readded). This also broke existing PSP connections.

I guess fixing this behavior during suspend is outside the scope of this series. I don't like it, we should do something about it, but not in this series.

Thanks, point taken.
I think we can leave this problem for another time.

author maintainer
#20 lore raw

PATCH 14/15 net/mlx5e: Return errors from profile->enable

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 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(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +1 -1
index 2270e2e550dd..3cc7283b6215 100644
@@ -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);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +11 -4
index 775f0c6e55c9..9eadd0b6f055 100644
@@ -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);
 
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +6 -2
index c8b76d301c92..603051ab1eaa 100644
@@ -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)
Signature · 1 line
2.44.0
author maintainer
#21 lore raw

PATCH 15/15 net/mlx5e: psp: Report PSP dev registration errors

In reply to Tariq Toukan

From: Cosmin Ratiu <[email protected]>

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.

---
 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(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +5 -3
index b3521c3861f6..73b232379263 100644
@@ -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)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +2 -2
index 57fffcf4a62c..3f441e7dd55a 100644
@@ -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) { }
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +7 -1
index 9eadd0b6f055..2cb48b24d5ea 100644
@@ -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)
Signature · 1 line
2.44.0
reviewer
#22 lore raw

Re: [PATCH net-next 15/15] net/mlx5e: psp: Report PSP dev registration errors

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev
---
--- Patch [15]: [PATCH net-next 15/15] net/mlx5e: psp: Report PSP dev registration errors --- commit 76afe7de4d1e708e7c01d267ef1fb9cf946de937
Author: Cosmin Ratiu <[email protected]>

net/mlx5e: psp: Report PSP dev registration errors

This commit updates mlx5e_psp_register() to return an error code instead of void when psp_dev_create() fails. The caller, mlx5e_nic_enable(), is also updated to check this return value and abort if PSP registration fails.

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static int mlx5e_nic_enable(struct mlx5e_priv *priv) · line 6204

Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
@@ -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;

[Severity: High]
Could propagating this error cause the entire network interface to fail if the optional PSP offload fails to register?

If psp_dev_create() fails (e.g., due to memory pressure or ID exhaustion in xa_alloc_cyclic), mlx5e_nic_enable() will now abort, resulting in a complete loss of networking capability for the device.

Notice how the code immediately following this handles MACsec initialization failures by logging the error and allowing the NIC to continue operating:

	err = mlx5e_macsec_init(priv);
	if (err)
		mlx5_core_err(mdev, "MACsec initialization failed, %d\n", err);

Should PSP registration failure fall back gracefully and allow the core NIC to function without the offload, similar to how MACsec is handled?

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -0
 	err = mlx5e_macsec_init(priv);
 	if (err)
 		mlx5_core_err(mdev, "MACsec initialization failed, %d\n", err);
#23 lore raw

Re: [PATCH net-next 15/15] net/mlx5e: psp: Report PSP dev registration errors

Quoted 48 lines · Simon Horman

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
--- Patch [15]: [PATCH net-next 15/15] net/mlx5e: psp: Report PSP dev registration errors ---
commit 76afe7de4d1e708e7c01d267ef1fb9cf946de937
Author: Cosmin Ratiu <[email protected]>

net/mlx5e: psp: Report PSP dev registration errors

This commit updates mlx5e_psp_register() to return an error code instead
of void when psp_dev_create() fails. The caller, mlx5e_nic_enable(), is
also updated to check this return value and abort if PSP registration fails.

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static int mlx5e_nic_enable(struct mlx5e_priv *priv) · line 6204

Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -0
@@ -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);

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
-	mlx5e_psp_register(priv);
+	err = mlx5e_psp_register(priv);
+	if (err)
+		goto out_ipsec_cleanup;

[Severity: High]
Could propagating this error cause the entire network interface to fail if
the optional PSP offload fails to register?

If psp_dev_create() fails (e.g., due to memory pressure or ID exhaustion
in xa_alloc_cyclic), mlx5e_nic_enable() will now abort, resulting in a
complete loss of networking capability for the device.

Notice how the code immediately following this handles MACsec initialization
failures by logging the error and allowing the NIC to continue operating:

Quoted 14 lines
	err = mlx5e_macsec_init(priv);
	if (err)
		mlx5_core_err(mdev, "MACsec initialization failed,

%d\n", err);

Should PSP registration failure fall back gracefully and allow the core NIC
to function without the offload, similar to how MACsec is handled?

Quoted 5 lines


  err = mlx5e_macsec_init(priv);
  if (err)
  mlx5_core_err(mdev, "MACsec initialization failed, %d\n", err);

This is an intentional change, as discussed in this thread with Jakub:

https://lore.kernel.org/netdev/[email protected]/t/#u

We carefully chose to fail device init on the very unlikely event PSP dev creation fails.

Cosmin.

reviewer
#24 lore raw

Re: [PATCH net-next 15/15] net/mlx5e: psp: Report PSP dev registration errors

Quoted 64 lines · Cosmin Ratiu
Quoted 48 lines · Simon Horman

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://sashiko.dev
---
--- Patch [15]: [PATCH net-next 15/15] net/mlx5e: psp: Report PSP dev registration errors ---
commit 76afe7de4d1e708e7c01d267ef1fb9cf946de937
Author: Cosmin Ratiu <[email protected]>

net/mlx5e: psp: Report PSP dev registration errors

This commit updates mlx5e_psp_register() to return an error code instead
of void when psp_dev_create() fails. The caller, mlx5e_nic_enable(), is
also updated to check this return value and abort if PSP registration fails.

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static int mlx5e_nic_enable(struct mlx5e_priv *priv) · line 6204

Quoted 13 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -0
@@ -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);

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
-	mlx5e_psp_register(priv);
+	err = mlx5e_psp_register(priv);
+	if (err)
+		goto out_ipsec_cleanup;

[Severity: High]
Could propagating this error cause the entire network interface to fail if
the optional PSP offload fails to register?

If psp_dev_create() fails (e.g., due to memory pressure or ID exhaustion
in xa_alloc_cyclic), mlx5e_nic_enable() will now abort, resulting in a
complete loss of networking capability for the device.

Notice how the code immediately following this handles MACsec initialization
failures by logging the error and allowing the NIC to continue operating:

Quoted 14 lines
	err = mlx5e_macsec_init(priv);
	if (err)
		mlx5_core_err(mdev, "MACsec initialization failed,

%d\n", err);

Should PSP registration failure fall back gracefully and allow the core NIC
to function without the offload, similar to how MACsec is handled?

Quoted 5 lines


  err = mlx5e_macsec_init(priv);
  if (err)
  mlx5_core_err(mdev, "MACsec initialization failed, %d\n", err);

Quoted 6 lines

This is an intentional change, as discussed in this thread with Jakub:

https://lore.kernel.org/netdev/[email protected]/t/#u

We carefully chose to fail device init on the very unlikely event PSP dev creation fails.

Thanks, sorry for not noticing that discussion earlier.

#25 lore raw
In reply to Tariq Toukan
Quoted 39 lines · Tariq Toukan

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(-)
Quoted 1 line

base-commit: 31816fc5d9acf8cdf226cdd0dc296e8cf15cc033

Thanks. Excited about the support for mlx5e_psp_set_config(). Jakub and I had a test case for psp_dev_ops::set_config() that we were waiting to upstream. I just rebased it onto net-next here: https://github.com/danieldzahka/linux/commit/b58e9a99573cf6b884e5fe3227c9af7a1f0d80b0

I ran it with the series but am seeing an error trying to catch undecrypted PSP-UDP packets after disabling all versions with set_config()

TAP version 13
1..30
ok 1 psp.data_basic_send.v0_ip4 # SKIP Test requires IPv4 connectivity
ok 2 psp.data_basic_send.v0_ip6
ok 3 psp.data_basic_send.v1_ip4 # SKIP Test requires IPv4 connectivity
ok 4 psp.data_basic_send.v1_ip6
ok 5 psp.data_basic_send.v2_ip4 # SKIP Test requires IPv4 connectivity
ok 6 psp.data_basic_send.v2_ip6 # SKIP ('PSP version not supported', 'hdr0-aes-gmac-128') ok 7 psp.data_basic_send.v3_ip4 # SKIP Test requires IPv4 connectivity
ok 8 psp.data_basic_send.v3_ip6 # SKIP ('PSP version not supported', 'hdr0-aes-gmac-256') ok 9 psp.data_mss_adjust.ip4 # SKIP Test requires IPv4 connectivity
ok 10 psp.data_mss_adjust.ip6
ok 11 psp.data_send_off.ip4 # SKIP Test requires IPv4 connectivity

# Exception| Traceback (most recent call last):
# Exception|   File "/root/ksft-psp-set-config/net/lib/py/ksft.py", line 420, in ksft_run
# Exception|     func(*args)
# Exception|   File "/root/./ksft-psp-set-config/drivers/net/psp.py", line 608, in data_send_off
# Exception|     udps.recv(8192, socket.MSG_DONTWAIT)
# Exception| BlockingIOError: [Errno 11] Resource temporarily unavailable
# Exception|

not ok 12 psp.data_send_off.ip6
ok 13 psp.dev_list_devices
ok 14 psp.dev_get_device
ok 15 psp.dev_get_device_bad
ok 16 psp.dev_rotate
ok 17 psp.dev_rotate_spi
ok 18 psp.assoc_basic
ok 19 psp.assoc_bad_dev
ok 20 psp.assoc_sk_only_conn
ok 21 psp.assoc_sk_only_mismatch
ok 22 psp.assoc_sk_only_mismatch_tx
ok 23 psp.assoc_sk_only_unconn
ok 24 psp.assoc_version_mismatch
ok 25 psp.assoc_twice
ok 26 psp.data_send_bad_key
ok 27 psp.data_send_disconnect
ok 28 psp.data_stale_key
ok 29 psp.removal_device_rx # XFAIL Test only works on netdevsim ok 30 psp.removal_device_bi # XFAIL Test only works on netdevsim # Totals: pass:19 fail:1 xfail:2 xpass:0 skip:8 error:0 #
# Responder logs (0):
# STDERR:
# #  Set PSP enable on device 1 to 0x3
# #  Set PSP enable on device 1 to 0x0

I recall this working on an earlier prototype of this feature for mlx5. Are the steering rules setup to drop PSP-UDP packets when the corresponding psp version is disabled?

#26 lore raw
Quoted 113 lines · Daniel Zahka
Quoted 39 lines · Tariq Toukan

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 +-

Quoted 4 lines
  9 files changed, 516 insertions(+), 584 deletions(-)

base-commit: 31816fc5d9acf8cdf226cdd0dc296e8cf15cc033

Thanks. Excited about the support for mlx5e_psp_set_config(). Jakub and
I had a test case for psp_dev_ops::set_config() that we were waiting to
upstream. I just rebased it onto net-next here:
https://github.com/danieldzahka/linux/commit/b58e9a99573cf6b884e5fe3227c9af7a1f0d80b0

I ran it with the series but am seeing an error trying to catch undecrypted PSP-UDP packets after disabling all versions with set_config()

TAP version 13
1..30
ok 1 psp.data_basic_send.v0_ip4 # SKIP Test requires IPv4 connectivity
ok 2 psp.data_basic_send.v0_ip6
ok 3 psp.data_basic_send.v1_ip4 # SKIP Test requires IPv4 connectivity
ok 4 psp.data_basic_send.v1_ip6
ok 5 psp.data_basic_send.v2_ip4 # SKIP Test requires IPv4 connectivity
ok 6 psp.data_basic_send.v2_ip6 # SKIP ('PSP version not supported', 'hdr0-aes-gmac-128')
ok 7 psp.data_basic_send.v3_ip4 # SKIP Test requires IPv4 connectivity
ok 8 psp.data_basic_send.v3_ip6 # SKIP ('PSP version not supported', 'hdr0-aes-gmac-256')
ok 9 psp.data_mss_adjust.ip4 # SKIP Test requires IPv4 connectivity ok 10 psp.data_mss_adjust.ip6
ok 11 psp.data_send_off.ip4 # SKIP Test requires IPv4 connectivity # Exception| Traceback (most recent call last):
# Exception|   File "/root/ksft-psp-set-config/net/lib/py/ksft.py", line
420, in ksft_run
# Exception|     func(*args)
# Exception|   File "/root/./ksft-psp-set-config/drivers/net/psp.py", line 608, in data_send_off
# Exception|     udps.recv(8192, socket.MSG_DONTWAIT)
# Exception| BlockingIOError: [Errno 11] Resource temporarily unavailable
# Exception|
not ok 12 psp.data_send_off.ip6
ok 13 psp.dev_list_devices
ok 14 psp.dev_get_device
ok 15 psp.dev_get_device_bad
ok 16 psp.dev_rotate
ok 17 psp.dev_rotate_spi
ok 18 psp.assoc_basic
ok 19 psp.assoc_bad_dev
ok 20 psp.assoc_sk_only_conn
ok 21 psp.assoc_sk_only_mismatch
ok 22 psp.assoc_sk_only_mismatch_tx
ok 23 psp.assoc_sk_only_unconn
ok 24 psp.assoc_version_mismatch
ok 25 psp.assoc_twice
ok 26 psp.data_send_bad_key
ok 27 psp.data_send_disconnect
ok 28 psp.data_stale_key
ok 29 psp.removal_device_rx # XFAIL Test only works on netdevsim ok 30 psp.removal_device_bi # XFAIL Test only works on netdevsim # Totals: pass:19 fail:1 xfail:2 xpass:0 skip:8 error:0
#
# Responder logs (0):
# STDERR:
# #  Set PSP enable on device 1 to 0x3
# #  Set PSP enable on device 1 to 0x0

Quoted 5 lines

I recall this working on an earlier prototype of this feature for mlx5.
Are the steering rules setup to drop PSP-UDP packets when the corresponding psp version is disabled?

We don't have per-psp version steering rules. If either version is requested, steering rules are configured. When all versions are disabled, steering rules are removed.
With no steering rules installed, UDP traffic should not be affected.

I will take the test and debug what's going on, and get back to you.

Cosmin.

#27 lore raw
Quoted 126 lines · Cosmin Ratiu
Quoted 119 lines · Daniel Zahka
Quoted 41 lines · Tariq Toukan

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 +-

Quoted 4 lines
  9 files changed, 516 insertions(+), 584 deletions(-)

base-commit: 31816fc5d9acf8cdf226cdd0dc296e8cf15cc033

Thanks. Excited about the support for mlx5e_psp_set_config(). Jakub and
I had a test case for psp_dev_ops::set_config() that we were waiting
to
upstream. I just rebased it onto net-next here:
https://github.com/danieldzahka/linux/commit/b58e9a99573cf6b884e5fe3227c9af7a1f0d80b0

I ran it with the series but am seeing an error trying to catch undecrypted PSP-UDP packets after disabling all versions with set_config()

TAP version 13
1..30
ok 1 psp.data_basic_send.v0_ip4 # SKIP Test requires IPv4 connectivity
ok 2 psp.data_basic_send.v0_ip6
ok 3 psp.data_basic_send.v1_ip4 # SKIP Test requires IPv4 connectivity
ok 4 psp.data_basic_send.v1_ip6
ok 5 psp.data_basic_send.v2_ip4 # SKIP Test requires IPv4 connectivity
ok 6 psp.data_basic_send.v2_ip6 # SKIP ('PSP version not supported',
'hdr0-aes-gmac-128')
ok 7 psp.data_basic_send.v3_ip4 # SKIP Test requires IPv4 connectivity
ok 8 psp.data_basic_send.v3_ip6 # SKIP ('PSP version not supported',
'hdr0-aes-gmac-256')
ok 9 psp.data_mss_adjust.ip4 # SKIP Test requires IPv4 connectivity ok 10 psp.data_mss_adjust.ip6
ok 11 psp.data_send_off.ip4 # SKIP Test requires IPv4 connectivity # Exception| Traceback (most recent call last):
# Exception|   File "/root/ksft-psp-set-config/net/lib/py/ksft.py", line
420, in ksft_run
# Exception|     func(*args)
# Exception|   File "/root/./ksft-psp-set- config/drivers/net/psp.py",
line 608, in data_send_off
# Exception|     udps.recv(8192, socket.MSG_DONTWAIT)
# Exception| BlockingIOError: [Errno 11] Resource temporarily unavailable
# Exception|
not ok 12 psp.data_send_off.ip6
ok 13 psp.dev_list_devices
ok 14 psp.dev_get_device
ok 15 psp.dev_get_device_bad
ok 16 psp.dev_rotate
ok 17 psp.dev_rotate_spi
ok 18 psp.assoc_basic
ok 19 psp.assoc_bad_dev
ok 20 psp.assoc_sk_only_conn
ok 21 psp.assoc_sk_only_mismatch
ok 22 psp.assoc_sk_only_mismatch_tx
ok 23 psp.assoc_sk_only_unconn
ok 24 psp.assoc_version_mismatch
ok 25 psp.assoc_twice
ok 26 psp.data_send_bad_key
ok 27 psp.data_send_disconnect
ok 28 psp.data_stale_key
ok 29 psp.removal_device_rx # XFAIL Test only works on netdevsim ok 30 psp.removal_device_bi # XFAIL Test only works on netdevsim # Totals: pass:19 fail:1 xfail:2 xpass:0 skip:8 error:0 #
# Responder logs (0):
# STDERR:
# #  Set PSP enable on device 1 to 0x3
# #  Set PSP enable on device 1 to 0x0

Quoted 5 lines

I recall this working on an earlier prototype of this feature for mlx5.
Are the steering rules setup to drop PSP-UDP packets when the corresponding psp version is disabled?

Quoted 6 lines

We don't have per-psp version steering rules. If either version is requested, steering rules are configured. When all versions are disabled, steering rules are removed.
With no steering rules installed, UDP traffic should not be affected.

I will take the test and debug what's going on, and get back to you.

So the test relies on TCP retransmissions to catch the encrypted echo from the responder on the UDP socket. The timeline seems to be:
1. data_send_off disables PSP on its end.
2. data_send_off opens a UDP socket and binds it to port 1000.
3. data_send_off sends "data echo" to psp_responder on the control connection.
4. psp_responder send "echo" on the now sabotaged PSP connection.
5. psp_responder acks the "echo request" on the control connection.
6. data_send_off receives the ack.
7. data_send_off tries to receive "echo" on the PSP connection but expect_fail==True so stops after 100 ms.
8. data_send_off reenables PSP on its end.
9. data_send_off waits for "echo" to be received now that connectivity is back for up to 350 ms.
10. data_send_off asserts that something is in the UDP socket queue.

So UDP packets could be enqueued if PSP packets are received between steps 4-8.

It seems disabling PSP steering rules isn't as atomic as we thought, and sometimes the first echo is discarded by steering. The default TCP retransmission timeout is 200 ms so there are no retransmissions in the ~150-170 ms between steps 4-8.

With a slightly modified test that directly requests data echoes, the test becomes more reliable. Additionally, you need the UDP_NO_CHECK6_RX
(102) socket options for the ipv6 version, otherwise zero-checksum UDP packets are discarded by the stack. I vaguely remember doing this change for this test in Jakub's repo a few years ago.

Anyway, here's the diff that makes both tests reliably pass:

tools/testing/selftests/drivers/net/psp.py +3 -1
@@ -569,7 +569,8 @@ def _get_psp_ver_ip_variants():
 
 def _get_ip_variants():
     for ipv in ("4", "6"):
-        yield KsftNamedVariant(f"ip{ipv}", ipv)
+        for _ in range(0, 100):
+            yield KsftNamedVariant(f"ip{ipv}", ipv)
 
 
 @ksft_variants(_get_ip_variants())
@@ -604,16 +605,28 @@ def data_send_off(cfg, ipver):
             udps.bind(('0.0.0.0', 1000))
         else:
             udps = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
+            # PSP packets have a zero UDP csum, accept them

(UDP_NO_CHECK6_RX)
+ udps.setsockopt(socket.IPPROTO_UDP, 102, 1)

             udps.bind(('::', 1000))
         wait_port_listen(1000, proto="udp")
 
         _req_echo(cfg, s, expect_fail=True)

+ echoes = 1
+ for _ in range(10):
+ try:
+ udps.recv(8192, socket.MSG_DONTWAIT | socket.MSG_PEEK)
+ break
+ except BlockingIOError:

+                _send_with_ack(cfg, b'data echo\0')
+                echoes += 1
+                time.sleep(0.05)
+
         cfg.pspnl.dev_set({"id": cfg.psp_dev_id,
                          "psp-versions-ena": info['psp-versions-
ena']})
         info = None
-        # We need some more TCP RTOs so lots of rounds
-        _recv_careful(s, 5, rounds=350)
+        # Drain the socket now that connectivity is back
+        _recv_careful(s, 5 * echoes, rounds=1000)

# Will raise BlockingIOError if there are no packets udps.recv(8192, socket.MSG_DONTWAIT)

-------

With this (plus disabling all other test cases), I get:

# ./tools/testing/selftests/drivers/net/psp.py 
TAP version 13
1..200
ok 1 psp.data_send_off.ip4
...
ok 200 psp.data_send_off.ip6
# Totals: pass:200 fail:0 xfail:0 xpass:0 skip:0 error:0

I will continue to dig into what exactly happens in steering when PSP gets disabled and why a packet is eaten with no traces.

Cosmin.

#28 lore raw
Quoted 24 lines · Cosmin Ratiu

So the test relies on TCP retransmissions to catch the encrypted echo from the responder on the UDP socket. The timeline seems to be:
1. data_send_off disables PSP on its end.
2. data_send_off opens a UDP socket and binds it to port 1000.
3. data_send_off sends "data echo" to psp_responder on the control connection.
4. psp_responder send "echo" on the now sabotaged PSP connection.
5. psp_responder acks the "echo request" on the control connection.
6. data_send_off receives the ack.
7. data_send_off tries to receive "echo" on the PSP connection but expect_fail==True so stops after 100 ms.
8. data_send_off reenables PSP on its end.
9. data_send_off waits for "echo" to be received now that connectivity is back for up to 350 ms.
10. data_send_off asserts that something is in the UDP socket queue.

So UDP packets could be enqueued if PSP packets are received between steps 4-8.

It seems disabling PSP steering rules isn't as atomic as we thought, and sometimes the first echo is discarded by steering. The default TCP retransmission timeout is 200 ms so there are no retransmissions in the ~150-170 ms between steps 4-8.

Quoted 7 lines

With a slightly modified test that directly requests data echoes, the test becomes more reliable. Additionally, you need the UDP_NO_CHECK6_RX
(102) socket options for the ipv6 version, otherwise zero-checksum UDP packets are discarded by the stack. I vaguely remember doing this change for this test in Jakub's repo a few years ago.

Anyway, here's the diff that makes both tests reliably pass:

Thanks for taking a look. I suppose the timing and 0 udp checksum explain why I wasn't seeing any packets. I was concerned that we may have entered a state where we were losing some udp packets permanently, as opposed to just some transient drops at the time the device is reconfigured, but it sounds like that isn't the case. So, I think this works ok then.

author maintainer
#29 lore raw
In reply to Tariq Toukan
Quoted 39 lines · Tariq Toukan

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(-)
Quoted 1 line

base-commit: 31816fc5d9acf8cdf226cdd0dc296e8cf15cc033

Hi,
It's been in-flight (still marked New) for ~2 weeks, and is blocking our queue...

I don't see it tracked in Suie anymore...
All comments in the thread were answered, no changes required for now.

How do we progress with this series?

maintainer
#30 lore raw
Quoted 7 lines · On Mon, 20 Jul 2026 09:05:17 +0300 Tariq Toukan wrote:

It's been in-flight (still marked New) for ~2 weeks, and is blocking our queue...

I don't see it tracked in Suie anymore...
All comments in the thread were answered, no changes required for now.

How do we progress with this series?

Cleaning up patchwork -- looks like this has been applied but bot did not respond.