Commit 301e0be8 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Saeed Mahameed
Browse files

net/mlx5: Simplify IPsec flow steering init/cleanup functions



Remove multiple function wrappers to make sure that IPsec FS initialization
and cleanup functions present in one place to help with code readability.

Reviewed-by: default avatarRaed Salem <raeds@nvidia.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent f43f0cd2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -424,7 +424,7 @@ int mlx5e_ipsec_init(struct mlx5e_priv *priv)
	}

	priv->ipsec = ipsec;
	mlx5e_accel_ipsec_fs_init(priv);
	mlx5e_accel_ipsec_fs_init(ipsec);
	netdev_dbg(priv->netdev, "IPSec attached to netdevice\n");
	return 0;
}
@@ -436,7 +436,7 @@ void mlx5e_ipsec_cleanup(struct mlx5e_priv *priv)
	if (!ipsec)
		return;

	mlx5e_accel_ipsec_fs_cleanup(priv);
	mlx5e_accel_ipsec_fs_cleanup(ipsec);
	destroy_workqueue(ipsec->wq);

	kfree(ipsec);
+23 −50
Original line number Diff line number Diff line
@@ -632,81 +632,54 @@ void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_priv *priv,
		tx_del_rule(priv, ipsec_rule);
}

static void fs_cleanup_tx(struct mlx5e_priv *priv)
{
	mutex_destroy(&priv->ipsec->tx_fs->mutex);
	WARN_ON(priv->ipsec->tx_fs->refcnt);
	kfree(priv->ipsec->tx_fs);
	priv->ipsec->tx_fs = NULL;
}

static void fs_cleanup_rx(struct mlx5e_priv *priv)
void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec)
{
	struct mlx5e_accel_fs_esp_prot *fs_prot;
	struct mlx5e_accel_fs_esp *accel_esp;
	enum accel_fs_esp_type i;

	accel_esp = priv->ipsec->rx_fs;
	if (!ipsec->rx_fs)
		return;

	mutex_destroy(&ipsec->tx_fs->mutex);
	WARN_ON(ipsec->tx_fs->refcnt);
	kfree(ipsec->tx_fs);

	accel_esp = ipsec->rx_fs;
	for (i = 0; i < ACCEL_FS_ESP_NUM_TYPES; i++) {
		fs_prot = &accel_esp->fs_prot[i];
		mutex_destroy(&fs_prot->prot_mutex);
		WARN_ON(fs_prot->refcnt);
	}
	kfree(priv->ipsec->rx_fs);
	priv->ipsec->rx_fs = NULL;
}

static int fs_init_tx(struct mlx5e_priv *priv)
{
	priv->ipsec->tx_fs =
		kzalloc(sizeof(struct mlx5e_ipsec_tx), GFP_KERNEL);
	if (!priv->ipsec->tx_fs)
		return -ENOMEM;

	mutex_init(&priv->ipsec->tx_fs->mutex);
	return 0;
	kfree(ipsec->rx_fs);
}

static int fs_init_rx(struct mlx5e_priv *priv)
int mlx5e_accel_ipsec_fs_init(struct mlx5e_ipsec *ipsec)
{
	struct mlx5e_accel_fs_esp_prot *fs_prot;
	struct mlx5e_accel_fs_esp *accel_esp;
	enum accel_fs_esp_type i;
	int err = -ENOMEM;

	priv->ipsec->rx_fs =
		kzalloc(sizeof(struct mlx5e_accel_fs_esp), GFP_KERNEL);
	if (!priv->ipsec->rx_fs)
	ipsec->tx_fs = kzalloc(sizeof(*ipsec->tx_fs), GFP_KERNEL);
	if (!ipsec->tx_fs)
		return -ENOMEM;

	accel_esp = priv->ipsec->rx_fs;
	ipsec->rx_fs = kzalloc(sizeof(*ipsec->rx_fs), GFP_KERNEL);
	if (!ipsec->rx_fs)
		goto err_rx;

	mutex_init(&ipsec->tx_fs->mutex);

	accel_esp = ipsec->rx_fs;
	for (i = 0; i < ACCEL_FS_ESP_NUM_TYPES; i++) {
		fs_prot = &accel_esp->fs_prot[i];
		mutex_init(&fs_prot->prot_mutex);
	}

	return 0;
}

void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_priv *priv)
{
	if (!priv->ipsec->rx_fs)
		return;

	fs_cleanup_tx(priv);
	fs_cleanup_rx(priv);
}

int mlx5e_accel_ipsec_fs_init(struct mlx5e_priv *priv)
{
	int err;

	err = fs_init_tx(priv);
	if (err)
		return err;

	err = fs_init_rx(priv);
	if (err)
		fs_cleanup_tx(priv);

err_rx:
	kfree(ipsec->tx_fs);
	return err;
}
+2 −2
Original line number Diff line number Diff line
@@ -9,8 +9,8 @@
#include "ipsec_offload.h"
#include "en/fs.h"

void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_priv *priv);
int mlx5e_accel_ipsec_fs_init(struct mlx5e_priv *priv);
void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec);
int mlx5e_accel_ipsec_fs_init(struct mlx5e_ipsec *ipsec);
int mlx5e_accel_ipsec_fs_add_rule(struct mlx5e_priv *priv,
				  struct mlx5_accel_esp_xfrm_attrs *attrs,
				  u32 ipsec_obj_id,