Commit f0da4daa authored by Chris Mi's avatar Chris Mi Committed by Saeed Mahameed

net/mlx5e: Refactor ct to use post action infrastructure

Move post action table management to common library providing
add/del/get API. Refactor the ct action offload to use the common
API.
Signed-off-by: default avatarChris Mi <cmi@nvidia.com>
Reviewed-by: default avatarOz Shlomo <ozsh@nvidia.com>
Reviewed-by: default avatarRoi Dayan <roid@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 6f0b692a
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "mod_hdr.h" #include "mod_hdr.h"
#include "lib/fs_ttc.h" #include "lib/fs_ttc.h"
struct mlx5e_post_act;
enum { enum {
MLX5E_TC_FT_LEVEL = 0, MLX5E_TC_FT_LEVEL = 0,
MLX5E_TC_TTC_FT_LEVEL, MLX5E_TC_TTC_FT_LEVEL,
...@@ -19,6 +21,7 @@ struct mlx5e_tc_table { ...@@ -19,6 +21,7 @@ struct mlx5e_tc_table {
struct mutex t_lock; struct mutex t_lock;
struct mlx5_flow_table *t; struct mlx5_flow_table *t;
struct mlx5_fs_chains *chains; struct mlx5_fs_chains *chains;
struct mlx5e_post_act *post_act;
struct rhashtable ht; struct rhashtable ht;
......
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
// Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved. // Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#include "en_tc.h"
#include "post_act.h" #include "post_act.h"
#include "mlx5_core.h" #include "mlx5_core.h"
...@@ -9,8 +10,20 @@ struct mlx5e_post_act { ...@@ -9,8 +10,20 @@ struct mlx5e_post_act {
struct mlx5_fs_chains *chains; struct mlx5_fs_chains *chains;
struct mlx5_flow_table *ft; struct mlx5_flow_table *ft;
struct mlx5e_priv *priv; struct mlx5e_priv *priv;
struct xarray ids;
}; };
struct mlx5e_post_act_handle {
enum mlx5_flow_namespace_type ns_type;
struct mlx5_flow_attr *attr;
struct mlx5_flow_handle *rule;
u32 id;
};
#define MLX5_POST_ACTION_BITS (mlx5e_tc_attr_to_reg_mappings[FTEID_TO_REG].mlen)
#define MLX5_POST_ACTION_MAX GENMASK(MLX5_POST_ACTION_BITS - 1, 0)
#define MLX5_POST_ACTION_MASK MLX5_POST_ACTION_MAX
struct mlx5e_post_act * struct mlx5e_post_act *
mlx5e_tc_post_act_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains, mlx5e_tc_post_act_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
enum mlx5_flow_namespace_type ns_type) enum mlx5_flow_namespace_type ns_type)
...@@ -43,6 +56,7 @@ mlx5e_tc_post_act_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains, ...@@ -43,6 +56,7 @@ mlx5e_tc_post_act_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
post_act->chains = chains; post_act->chains = chains;
post_act->ns_type = ns_type; post_act->ns_type = ns_type;
post_act->priv = priv; post_act->priv = priv;
xa_init_flags(&post_act->ids, XA_FLAGS_ALLOC1);
return post_act; return post_act;
err_ft: err_ft:
...@@ -57,6 +71,94 @@ mlx5e_tc_post_act_destroy(struct mlx5e_post_act *post_act) ...@@ -57,6 +71,94 @@ mlx5e_tc_post_act_destroy(struct mlx5e_post_act *post_act)
if (IS_ERR_OR_NULL(post_act)) if (IS_ERR_OR_NULL(post_act))
return; return;
xa_destroy(&post_act->ids);
mlx5_chains_destroy_global_table(post_act->chains, post_act->ft); mlx5_chains_destroy_global_table(post_act->chains, post_act->ft);
kfree(post_act); kfree(post_act);
} }
struct mlx5e_post_act_handle *
mlx5e_tc_post_act_add(struct mlx5e_post_act *post_act, struct mlx5_flow_attr *attr)
{
u32 attr_sz = ns_to_attr_sz(post_act->ns_type);
struct mlx5e_post_act_handle *handle = NULL;
struct mlx5_flow_attr *post_attr = NULL;
struct mlx5_flow_spec *spec = NULL;
int err;
handle = kzalloc(sizeof(*handle), GFP_KERNEL);
spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
post_attr = mlx5_alloc_flow_attr(post_act->ns_type);
if (!handle || !spec || !post_attr) {
kfree(post_attr);
kvfree(spec);
kfree(handle);
return ERR_PTR(-ENOMEM);
}
memcpy(post_attr, attr, attr_sz);
post_attr->chain = 0;
post_attr->prio = 0;
post_attr->ft = post_act->ft;
post_attr->inner_match_level = MLX5_MATCH_NONE;
post_attr->outer_match_level = MLX5_MATCH_NONE;
post_attr->action &= ~(MLX5_FLOW_CONTEXT_ACTION_DECAP);
handle->ns_type = post_act->ns_type;
/* Splits were handled before post action */
if (handle->ns_type == MLX5_FLOW_NAMESPACE_FDB)
post_attr->esw_attr->split_count = 0;
err = xa_alloc(&post_act->ids, &handle->id, post_attr,
XA_LIMIT(1, MLX5_POST_ACTION_MAX), GFP_KERNEL);
if (err)
goto err_xarray;
/* Post action rule matches on fte_id and executes original rule's
* tc rule action
*/
mlx5e_tc_match_to_reg_match(spec, FTEID_TO_REG,
handle->id, MLX5_POST_ACTION_MASK);
handle->rule = mlx5_tc_rule_insert(post_act->priv, spec, post_attr);
if (IS_ERR(handle->rule)) {
err = PTR_ERR(handle->rule);
netdev_warn(post_act->priv->netdev, "Failed to add post action rule");
goto err_rule;
}
handle->attr = post_attr;
kvfree(spec);
return handle;
err_rule:
xa_erase(&post_act->ids, handle->id);
err_xarray:
kfree(post_attr);
kvfree(spec);
kfree(handle);
return ERR_PTR(err);
}
void
mlx5e_tc_post_act_del(struct mlx5e_post_act *post_act, struct mlx5e_post_act_handle *handle)
{
mlx5_tc_rule_delete(post_act->priv, handle->rule, handle->attr);
xa_erase(&post_act->ids, handle->id);
kfree(handle->attr);
kfree(handle);
}
struct mlx5_flow_table *
mlx5e_tc_post_act_get_ft(struct mlx5e_post_act *post_act)
{
return post_act->ft;
}
/* Allocate a header modify action to write the post action handle fte id to a register. */
int
mlx5e_tc_post_act_set_handle(struct mlx5_core_dev *dev,
struct mlx5e_post_act_handle *handle,
struct mlx5e_tc_mod_hdr_acts *acts)
{
return mlx5e_tc_match_to_reg_set(dev, acts, handle->ns_type, FTEID_TO_REG, handle->id);
}
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
#include "en.h" #include "en.h"
#include "lib/fs_chains.h" #include "lib/fs_chains.h"
struct mlx5_flow_attr;
struct mlx5e_priv;
struct mlx5e_tc_mod_hdr_acts;
struct mlx5e_post_act * struct mlx5e_post_act *
mlx5e_tc_post_act_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains, mlx5e_tc_post_act_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
enum mlx5_flow_namespace_type ns_type); enum mlx5_flow_namespace_type ns_type);
...@@ -14,4 +18,18 @@ mlx5e_tc_post_act_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains, ...@@ -14,4 +18,18 @@ mlx5e_tc_post_act_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
void void
mlx5e_tc_post_act_destroy(struct mlx5e_post_act *post_act); mlx5e_tc_post_act_destroy(struct mlx5e_post_act *post_act);
struct mlx5e_post_act_handle *
mlx5e_tc_post_act_add(struct mlx5e_post_act *post_act, struct mlx5_flow_attr *attr);
void
mlx5e_tc_post_act_del(struct mlx5e_post_act *post_act, struct mlx5e_post_act_handle *handle);
struct mlx5_flow_table *
mlx5e_tc_post_act_get_ft(struct mlx5e_post_act *post_act);
int
mlx5e_tc_post_act_set_handle(struct mlx5_core_dev *dev,
struct mlx5e_post_act_handle *handle,
struct mlx5e_tc_mod_hdr_acts *acts);
#endif /* __MLX5_POST_ACTION_H__ */ #endif /* __MLX5_POST_ACTION_H__ */
...@@ -92,7 +92,8 @@ struct mlx5_ct_attr { ...@@ -92,7 +92,8 @@ struct mlx5_ct_attr {
struct mlx5_tc_ct_priv * struct mlx5_tc_ct_priv *
mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains, mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
struct mod_hdr_tbl *mod_hdr, struct mod_hdr_tbl *mod_hdr,
enum mlx5_flow_namespace_type ns_type); enum mlx5_flow_namespace_type ns_type,
struct mlx5e_post_act *post_act);
void void
mlx5_tc_ct_clean(struct mlx5_tc_ct_priv *ct_priv); mlx5_tc_ct_clean(struct mlx5_tc_ct_priv *ct_priv);
...@@ -132,7 +133,8 @@ mlx5e_tc_ct_restore_flow(struct mlx5_tc_ct_priv *ct_priv, ...@@ -132,7 +133,8 @@ mlx5e_tc_ct_restore_flow(struct mlx5_tc_ct_priv *ct_priv,
static inline struct mlx5_tc_ct_priv * static inline struct mlx5_tc_ct_priv *
mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains, mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
struct mod_hdr_tbl *mod_hdr, struct mod_hdr_tbl *mod_hdr,
enum mlx5_flow_namespace_type ns_type) enum mlx5_flow_namespace_type ns_type,
struct mlx5e_post_act *post_act)
{ {
return NULL; return NULL;
} }
......
...@@ -60,6 +60,7 @@ struct mlx5e_neigh_update_table { ...@@ -60,6 +60,7 @@ struct mlx5e_neigh_update_table {
struct mlx5_tc_ct_priv; struct mlx5_tc_ct_priv;
struct mlx5e_rep_bond; struct mlx5e_rep_bond;
struct mlx5e_tc_tun_encap; struct mlx5e_tc_tun_encap;
struct mlx5e_post_act;
struct mlx5_rep_uplink_priv { struct mlx5_rep_uplink_priv {
/* Filters DB - instantiated by the uplink representor and shared by /* Filters DB - instantiated by the uplink representor and shared by
...@@ -88,6 +89,7 @@ struct mlx5_rep_uplink_priv { ...@@ -88,6 +89,7 @@ struct mlx5_rep_uplink_priv {
/* maps tun_enc_opts to a unique id*/ /* maps tun_enc_opts to a unique id*/
struct mapping_ctx *tunnel_enc_opts_mapping; struct mapping_ctx *tunnel_enc_opts_mapping;
struct mlx5e_post_act *post_act;
struct mlx5_tc_ct_priv *ct_priv; struct mlx5_tc_ct_priv *ct_priv;
struct mlx5e_tc_psample *tc_psample; struct mlx5e_tc_psample *tc_psample;
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <net/bareudp.h> #include <net/bareudp.h>
#include <net/bonding.h> #include <net/bonding.h>
#include "en.h" #include "en.h"
#include "en/tc/post_act.h"
#include "en_rep.h" #include "en_rep.h"
#include "en/rep/tc.h" #include "en/rep/tc.h"
#include "en/rep/neigh.h" #include "en/rep/neigh.h"
...@@ -4895,8 +4896,9 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv) ...@@ -4895,8 +4896,9 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)
goto err_chains; goto err_chains;
} }
tc->post_act = mlx5e_tc_post_act_init(priv, tc->chains, MLX5_FLOW_NAMESPACE_KERNEL);
tc->ct = mlx5_tc_ct_init(priv, tc->chains, &priv->fs.tc.mod_hdr, tc->ct = mlx5_tc_ct_init(priv, tc->chains, &priv->fs.tc.mod_hdr,
MLX5_FLOW_NAMESPACE_KERNEL); MLX5_FLOW_NAMESPACE_KERNEL, tc->post_act);
tc->netdevice_nb.notifier_call = mlx5e_tc_netdev_event; tc->netdevice_nb.notifier_call = mlx5e_tc_netdev_event;
err = register_netdevice_notifier_dev_net(priv->netdev, err = register_netdevice_notifier_dev_net(priv->netdev,
...@@ -4912,6 +4914,7 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv) ...@@ -4912,6 +4914,7 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)
err_reg: err_reg:
mlx5_tc_ct_clean(tc->ct); mlx5_tc_ct_clean(tc->ct);
mlx5e_tc_post_act_destroy(tc->post_act);
mlx5_chains_destroy(tc->chains); mlx5_chains_destroy(tc->chains);
err_chains: err_chains:
mapping_destroy(chains_mapping); mapping_destroy(chains_mapping);
...@@ -4950,6 +4953,7 @@ void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv) ...@@ -4950,6 +4953,7 @@ void mlx5e_tc_nic_cleanup(struct mlx5e_priv *priv)
mutex_destroy(&tc->t_lock); mutex_destroy(&tc->t_lock);
mlx5_tc_ct_clean(tc->ct); mlx5_tc_ct_clean(tc->ct);
mlx5e_tc_post_act_destroy(tc->post_act);
mapping_destroy(tc->mapping); mapping_destroy(tc->mapping);
mlx5_chains_destroy(tc->chains); mlx5_chains_destroy(tc->chains);
} }
...@@ -4970,10 +4974,13 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht) ...@@ -4970,10 +4974,13 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht)
priv = netdev_priv(rpriv->netdev); priv = netdev_priv(rpriv->netdev);
esw = priv->mdev->priv.eswitch; esw = priv->mdev->priv.eswitch;
uplink_priv->post_act = mlx5e_tc_post_act_init(priv, esw_chains(esw),
MLX5_FLOW_NAMESPACE_FDB);
uplink_priv->ct_priv = mlx5_tc_ct_init(netdev_priv(priv->netdev), uplink_priv->ct_priv = mlx5_tc_ct_init(netdev_priv(priv->netdev),
esw_chains(esw), esw_chains(esw),
&esw->offloads.mod_hdr, &esw->offloads.mod_hdr,
MLX5_FLOW_NAMESPACE_FDB); MLX5_FLOW_NAMESPACE_FDB,
uplink_priv->post_act);
#if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE) #if IS_ENABLED(CONFIG_MLX5_TC_SAMPLE)
uplink_priv->tc_psample = mlx5e_tc_sample_init(esw); uplink_priv->tc_psample = mlx5e_tc_sample_init(esw);
...@@ -5027,6 +5034,7 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht) ...@@ -5027,6 +5034,7 @@ int mlx5e_tc_esw_init(struct rhashtable *tc_ht)
mlx5_tc_ct_clean(uplink_priv->ct_priv); mlx5_tc_ct_clean(uplink_priv->ct_priv);
netdev_warn(priv->netdev, netdev_warn(priv->netdev,
"Failed to initialize tc (eswitch), err: %d", err); "Failed to initialize tc (eswitch), err: %d", err);
mlx5e_tc_post_act_destroy(uplink_priv->post_act);
return err; return err;
} }
...@@ -5046,6 +5054,7 @@ void mlx5e_tc_esw_cleanup(struct rhashtable *tc_ht) ...@@ -5046,6 +5054,7 @@ void mlx5e_tc_esw_cleanup(struct rhashtable *tc_ht)
mlx5e_tc_sample_cleanup(uplink_priv->tc_psample); mlx5e_tc_sample_cleanup(uplink_priv->tc_psample);
#endif #endif
mlx5_tc_ct_clean(uplink_priv->ct_priv); mlx5_tc_ct_clean(uplink_priv->ct_priv);
mlx5e_tc_post_act_destroy(uplink_priv->post_act);
} }
int mlx5e_tc_num_filters(struct mlx5e_priv *priv, unsigned long flags) int mlx5e_tc_num_filters(struct mlx5e_priv *priv, unsigned long flags)
......
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