Skip to content

Commit

Permalink
net/mlx5e: Added common function for to_ipsec_sa_entry
Browse files Browse the repository at this point in the history
New function for getting driver internal sa entry from xfrm state.
All checks are done in one function.

Signed-off-by: Aviad Yehezkel <aviadye@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
  • Loading branch information
aviadye authored and Saeed Mahameed committed Mar 7, 2018
1 parent 05564d0 commit 75ef3f5
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ struct mlx5e_ipsec_sa_entry {
void *hw_context;
};

static struct mlx5e_ipsec_sa_entry *to_ipsec_sa_entry(struct xfrm_state *x)
{
struct mlx5e_ipsec_sa_entry *sa;

if (!x)
return NULL;

sa = (struct mlx5e_ipsec_sa_entry *)x->xso.offload_handle;
if (!sa)
return NULL;

WARN_ON(sa->x != x);
return sa;
}

struct xfrm_state *mlx5e_ipsec_sadb_rx_lookup(struct mlx5e_ipsec *ipsec,
unsigned int handle)
{
Expand Down Expand Up @@ -312,28 +327,22 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x)

static void mlx5e_xfrm_del_state(struct xfrm_state *x)
{
struct mlx5e_ipsec_sa_entry *sa_entry;
struct mlx5e_ipsec_sa_entry *sa_entry = to_ipsec_sa_entry(x);

if (!x->xso.offload_handle)
if (!sa_entry)
return;

sa_entry = (struct mlx5e_ipsec_sa_entry *)x->xso.offload_handle;
WARN_ON(sa_entry->x != x);

if (x->xso.flags & XFRM_OFFLOAD_INBOUND)
mlx5e_ipsec_sadb_rx_del(sa_entry);
}

static void mlx5e_xfrm_free_state(struct xfrm_state *x)
{
struct mlx5e_ipsec_sa_entry *sa_entry;
struct mlx5e_ipsec_sa_entry *sa_entry = to_ipsec_sa_entry(x);

if (!x->xso.offload_handle)
if (!sa_entry)
return;

sa_entry = (struct mlx5e_ipsec_sa_entry *)x->xso.offload_handle;
WARN_ON(sa_entry->x != x);

if (sa_entry->hw_context) {
mlx5_accel_esp_free_hw_context(sa_entry->hw_context);
mlx5_accel_esp_destroy_xfrm(sa_entry->xfrm);
Expand Down

0 comments on commit 75ef3f5

Please sign in to comment.