Commit 82f7bdba authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Saeed Mahameed

net/mlx5: Clean IPsec FS add/delete rules

Reuse existing struct to pass parameters instead of open code them.
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 b73e6728
...@@ -313,9 +313,7 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x) ...@@ -313,9 +313,7 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x)
if (err) if (err)
goto err_xfrm; goto err_xfrm;
err = mlx5e_accel_ipsec_fs_add_rule(priv, &sa_entry->attrs, err = mlx5e_accel_ipsec_fs_add_rule(priv, sa_entry);
sa_entry->ipsec_obj_id,
&sa_entry->ipsec_rule);
if (err) if (err)
goto err_hw_ctx; goto err_hw_ctx;
...@@ -333,8 +331,7 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x) ...@@ -333,8 +331,7 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x)
goto out; goto out;
err_add_rule: err_add_rule:
mlx5e_accel_ipsec_fs_del_rule(priv, &sa_entry->attrs, mlx5e_accel_ipsec_fs_del_rule(priv, sa_entry);
&sa_entry->ipsec_rule);
err_hw_ctx: err_hw_ctx:
mlx5_ipsec_free_sa_ctx(sa_entry); mlx5_ipsec_free_sa_ctx(sa_entry);
err_xfrm: err_xfrm:
...@@ -357,8 +354,7 @@ static void mlx5e_xfrm_free_state(struct xfrm_state *x) ...@@ -357,8 +354,7 @@ static void mlx5e_xfrm_free_state(struct xfrm_state *x)
struct mlx5e_priv *priv = netdev_priv(x->xso.dev); struct mlx5e_priv *priv = netdev_priv(x->xso.dev);
cancel_work_sync(&sa_entry->modify_work.work); cancel_work_sync(&sa_entry->modify_work.work);
mlx5e_accel_ipsec_fs_del_rule(priv, &sa_entry->attrs, mlx5e_accel_ipsec_fs_del_rule(priv, sa_entry);
&sa_entry->ipsec_rule);
mlx5_ipsec_free_sa_ctx(sa_entry); mlx5_ipsec_free_sa_ctx(sa_entry);
kfree(sa_entry); kfree(sa_entry);
} }
......
...@@ -176,12 +176,9 @@ struct xfrm_state *mlx5e_ipsec_sadb_rx_lookup(struct mlx5e_ipsec *dev, ...@@ -176,12 +176,9 @@ struct xfrm_state *mlx5e_ipsec_sadb_rx_lookup(struct mlx5e_ipsec *dev,
void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec); 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_init(struct mlx5e_ipsec *ipsec);
int mlx5e_accel_ipsec_fs_add_rule(struct mlx5e_priv *priv, int mlx5e_accel_ipsec_fs_add_rule(struct mlx5e_priv *priv,
struct mlx5_accel_esp_xfrm_attrs *attrs, struct mlx5e_ipsec_sa_entry *sa_entry);
u32 ipsec_obj_id,
struct mlx5e_ipsec_rule *ipsec_rule);
void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_priv *priv, void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_priv *priv,
struct mlx5_accel_esp_xfrm_attrs *attrs, struct mlx5e_ipsec_sa_entry *sa_entry);
struct mlx5e_ipsec_rule *ipsec_rule);
int mlx5_ipsec_create_sa_ctx(struct mlx5e_ipsec_sa_entry *sa_entry); int mlx5_ipsec_create_sa_ctx(struct mlx5e_ipsec_sa_entry *sa_entry);
void mlx5_ipsec_free_sa_ctx(struct mlx5e_ipsec_sa_entry *sa_entry); void mlx5_ipsec_free_sa_ctx(struct mlx5e_ipsec_sa_entry *sa_entry);
......
...@@ -454,11 +454,12 @@ static void setup_fte_common(struct mlx5_accel_esp_xfrm_attrs *attrs, ...@@ -454,11 +454,12 @@ static void setup_fte_common(struct mlx5_accel_esp_xfrm_attrs *attrs,
} }
static int rx_add_rule(struct mlx5e_priv *priv, static int rx_add_rule(struct mlx5e_priv *priv,
struct mlx5_accel_esp_xfrm_attrs *attrs, struct mlx5e_ipsec_sa_entry *sa_entry)
u32 ipsec_obj_id,
struct mlx5e_ipsec_rule *ipsec_rule)
{ {
u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {}; u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {};
struct mlx5e_ipsec_rule *ipsec_rule = &sa_entry->ipsec_rule;
struct mlx5_accel_esp_xfrm_attrs *attrs = &sa_entry->attrs;
u32 ipsec_obj_id = sa_entry->ipsec_obj_id;
struct mlx5_modify_hdr *modify_hdr = NULL; struct mlx5_modify_hdr *modify_hdr = NULL;
struct mlx5e_accel_fs_esp_prot *fs_prot; struct mlx5e_accel_fs_esp_prot *fs_prot;
struct mlx5_flow_destination dest = {}; struct mlx5_flow_destination dest = {};
...@@ -532,9 +533,7 @@ static int rx_add_rule(struct mlx5e_priv *priv, ...@@ -532,9 +533,7 @@ static int rx_add_rule(struct mlx5e_priv *priv,
} }
static int tx_add_rule(struct mlx5e_priv *priv, static int tx_add_rule(struct mlx5e_priv *priv,
struct mlx5_accel_esp_xfrm_attrs *attrs, struct mlx5e_ipsec_sa_entry *sa_entry)
u32 ipsec_obj_id,
struct mlx5e_ipsec_rule *ipsec_rule)
{ {
struct mlx5_flow_act flow_act = {}; struct mlx5_flow_act flow_act = {};
struct mlx5_flow_handle *rule; struct mlx5_flow_handle *rule;
...@@ -551,7 +550,8 @@ static int tx_add_rule(struct mlx5e_priv *priv, ...@@ -551,7 +550,8 @@ static int tx_add_rule(struct mlx5e_priv *priv,
goto out; goto out;
} }
setup_fte_common(attrs, ipsec_obj_id, spec, &flow_act); setup_fte_common(&sa_entry->attrs, sa_entry->ipsec_obj_id, spec,
&flow_act);
/* Add IPsec indicator in metadata_reg_a */ /* Add IPsec indicator in metadata_reg_a */
spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2; spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2;
...@@ -566,11 +566,11 @@ static int tx_add_rule(struct mlx5e_priv *priv, ...@@ -566,11 +566,11 @@ static int tx_add_rule(struct mlx5e_priv *priv,
if (IS_ERR(rule)) { if (IS_ERR(rule)) {
err = PTR_ERR(rule); err = PTR_ERR(rule);
netdev_err(priv->netdev, "fail to add ipsec rule attrs->action=0x%x, err=%d\n", netdev_err(priv->netdev, "fail to add ipsec rule attrs->action=0x%x, err=%d\n",
attrs->action, err); sa_entry->attrs.action, err);
goto out; goto out;
} }
ipsec_rule->rule = rule; sa_entry->ipsec_rule.rule = rule;
out: out:
kvfree(spec); kvfree(spec);
...@@ -580,21 +580,25 @@ static int tx_add_rule(struct mlx5e_priv *priv, ...@@ -580,21 +580,25 @@ static int tx_add_rule(struct mlx5e_priv *priv,
} }
static void rx_del_rule(struct mlx5e_priv *priv, static void rx_del_rule(struct mlx5e_priv *priv,
struct mlx5_accel_esp_xfrm_attrs *attrs, struct mlx5e_ipsec_sa_entry *sa_entry)
struct mlx5e_ipsec_rule *ipsec_rule)
{ {
struct mlx5e_ipsec_rule *ipsec_rule = &sa_entry->ipsec_rule;
mlx5_del_flow_rules(ipsec_rule->rule); mlx5_del_flow_rules(ipsec_rule->rule);
ipsec_rule->rule = NULL; ipsec_rule->rule = NULL;
mlx5_modify_header_dealloc(priv->mdev, ipsec_rule->set_modify_hdr); mlx5_modify_header_dealloc(priv->mdev, ipsec_rule->set_modify_hdr);
ipsec_rule->set_modify_hdr = NULL; ipsec_rule->set_modify_hdr = NULL;
rx_ft_put(priv, attrs->is_ipv6 ? ACCEL_FS_ESP6 : ACCEL_FS_ESP4); rx_ft_put(priv,
sa_entry->attrs.is_ipv6 ? ACCEL_FS_ESP6 : ACCEL_FS_ESP4);
} }
static void tx_del_rule(struct mlx5e_priv *priv, static void tx_del_rule(struct mlx5e_priv *priv,
struct mlx5e_ipsec_rule *ipsec_rule) struct mlx5e_ipsec_sa_entry *sa_entry)
{ {
struct mlx5e_ipsec_rule *ipsec_rule = &sa_entry->ipsec_rule;
mlx5_del_flow_rules(ipsec_rule->rule); mlx5_del_flow_rules(ipsec_rule->rule);
ipsec_rule->rule = NULL; ipsec_rule->rule = NULL;
...@@ -602,24 +606,23 @@ static void tx_del_rule(struct mlx5e_priv *priv, ...@@ -602,24 +606,23 @@ static void tx_del_rule(struct mlx5e_priv *priv,
} }
int mlx5e_accel_ipsec_fs_add_rule(struct mlx5e_priv *priv, int mlx5e_accel_ipsec_fs_add_rule(struct mlx5e_priv *priv,
struct mlx5_accel_esp_xfrm_attrs *attrs, struct mlx5e_ipsec_sa_entry *sa_entry)
u32 ipsec_obj_id,
struct mlx5e_ipsec_rule *ipsec_rule)
{ {
if (attrs->action == MLX5_ACCEL_ESP_ACTION_DECRYPT) if (sa_entry->attrs.action == MLX5_ACCEL_ESP_ACTION_ENCRYPT)
return rx_add_rule(priv, attrs, ipsec_obj_id, ipsec_rule); return tx_add_rule(priv, sa_entry);
else
return tx_add_rule(priv, attrs, ipsec_obj_id, ipsec_rule); return rx_add_rule(priv, sa_entry);
} }
void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_priv *priv, void mlx5e_accel_ipsec_fs_del_rule(struct mlx5e_priv *priv,
struct mlx5_accel_esp_xfrm_attrs *attrs, struct mlx5e_ipsec_sa_entry *sa_entry)
struct mlx5e_ipsec_rule *ipsec_rule)
{ {
if (attrs->action == MLX5_ACCEL_ESP_ACTION_DECRYPT) if (sa_entry->attrs.action == MLX5_ACCEL_ESP_ACTION_ENCRYPT) {
rx_del_rule(priv, attrs, ipsec_rule); tx_del_rule(priv, sa_entry);
else return;
tx_del_rule(priv, ipsec_rule); }
rx_del_rule(priv, sa_entry);
} }
void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec) void mlx5e_accel_ipsec_fs_cleanup(struct mlx5e_ipsec *ipsec)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment