Skip to content

Commit

Permalink
net/mlx5e: Convert mlx5e_flow_steering member of mlx5e_priv to pointer
Browse files Browse the repository at this point in the history
Make mlx5e_flow_steering member of mlx5e_priv a pointer.
Add dynamic allocation respectively.

Allocate fs for all profiles when initializing profile,
symmetrically deallocate at profile cleanup.

Signed-off-by: Lama Kayal <lkayal@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
  • Loading branch information
Lama Kayal authored and Saeed Mahameed committed Jul 28, 2022
1 parent 454533a commit af8bbf7
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 264 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/en.h
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ struct mlx5e_priv {
struct mlx5e_rx_res *rx_res;
u32 *tx_rates;

struct mlx5e_flow_steering fs;
struct mlx5e_flow_steering *fs;

struct workqueue_struct *wq;
struct work_struct update_carrier_work;
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/ethernet/mellanox/mlx5/core/en/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSU
struct mlx5e_accel_fs_tcp;
#endif

struct mlx5e_profile;
struct mlx5e_fs_udp;
struct mlx5e_fs_any;
struct mlx5e_ptp_fs;
Expand Down Expand Up @@ -177,8 +178,8 @@ void mlx5e_disable_cvlan_filter(struct mlx5e_priv *priv);
int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);

int mlx5e_fs_init(struct mlx5e_priv *priv);
void mlx5e_fs_cleanup(struct mlx5e_priv *priv);
struct mlx5e_flow_steering *mlx5e_fs_init(const struct mlx5e_profile *profile);
void mlx5e_fs_cleanup(struct mlx5e_flow_steering *fs);

int mlx5e_add_vlan_trap(struct mlx5e_priv *priv, int trap_id, int tir_num);
void mlx5e_remove_vlan_trap(struct mlx5e_priv *priv);
Expand Down
72 changes: 36 additions & 36 deletions drivers/net/ethernet/mellanox/mlx5/core/en/fs_tt_redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mlx5e_fs_tt_redirect_udp_add_rule(struct mlx5e_priv *priv,
if (!spec)
return ERR_PTR(-ENOMEM);

fs_udp = priv->fs.udp;
fs_udp = priv->fs->udp;
ft = fs_udp->tables[type].t;

fs_udp_set_dport_flow(spec, type, d_port);
Expand All @@ -121,10 +121,10 @@ static int fs_udp_add_default_rule(struct mlx5e_priv *priv, enum fs_udp_type typ
struct mlx5e_fs_udp *fs_udp;
int err;

fs_udp = priv->fs.udp;
fs_udp = priv->fs->udp;
fs_udp_t = &fs_udp->tables[type];

dest = mlx5_ttc_get_default_dest(priv->fs.ttc, fs_udp2tt(type));
dest = mlx5_ttc_get_default_dest(priv->fs->ttc, fs_udp2tt(type));
rule = mlx5_add_flow_rules(fs_udp_t->t, NULL, &flow_act, &dest, 1);
if (IS_ERR(rule)) {
err = PTR_ERR(rule);
Expand Down Expand Up @@ -208,7 +208,7 @@ static int fs_udp_create_groups(struct mlx5e_flow_table *ft, enum fs_udp_type ty

static int fs_udp_create_table(struct mlx5e_priv *priv, enum fs_udp_type type)
{
struct mlx5e_flow_table *ft = &priv->fs.udp->tables[type];
struct mlx5e_flow_table *ft = &priv->fs->udp->tables[type];
struct mlx5_flow_table_attr ft_attr = {};
int err;

Expand All @@ -218,7 +218,7 @@ static int fs_udp_create_table(struct mlx5e_priv *priv, enum fs_udp_type type)
ft_attr.level = MLX5E_FS_TT_UDP_FT_LEVEL;
ft_attr.prio = MLX5E_NIC_PRIO;

ft->t = mlx5_create_flow_table(priv->fs.ns, &ft_attr);
ft->t = mlx5_create_flow_table(priv->fs->ns, &ft_attr);
if (IS_ERR(ft->t)) {
err = PTR_ERR(ft->t);
ft->t = NULL;
Expand Down Expand Up @@ -259,7 +259,7 @@ static int fs_udp_disable(struct mlx5e_priv *priv)

for (i = 0; i < FS_UDP_NUM_TYPES; i++) {
/* Modify ttc rules destination to point back to the indir TIRs */
err = mlx5_ttc_fwd_default_dest(priv->fs.ttc, fs_udp2tt(i));
err = mlx5_ttc_fwd_default_dest(priv->fs->ttc, fs_udp2tt(i));
if (err) {
netdev_err(priv->netdev,
"%s: modify ttc[%d] default destination failed, err(%d)\n",
Expand All @@ -278,10 +278,10 @@ static int fs_udp_enable(struct mlx5e_priv *priv)

dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
for (i = 0; i < FS_UDP_NUM_TYPES; i++) {
dest.ft = priv->fs.udp->tables[i].t;
dest.ft = priv->fs->udp->tables[i].t;

/* Modify ttc rules destination to point on the accel_fs FTs */
err = mlx5_ttc_fwd_dest(priv->fs.ttc, fs_udp2tt(i), &dest);
err = mlx5_ttc_fwd_dest(priv->fs->ttc, fs_udp2tt(i), &dest);
if (err) {
netdev_err(priv->netdev,
"%s: modify ttc[%d] destination to accel failed, err(%d)\n",
Expand All @@ -294,7 +294,7 @@ static int fs_udp_enable(struct mlx5e_priv *priv)

void mlx5e_fs_tt_redirect_udp_destroy(struct mlx5e_priv *priv)
{
struct mlx5e_fs_udp *fs_udp = priv->fs.udp;
struct mlx5e_fs_udp *fs_udp = priv->fs->udp;
int i;

if (!fs_udp)
Expand All @@ -309,20 +309,20 @@ void mlx5e_fs_tt_redirect_udp_destroy(struct mlx5e_priv *priv)
fs_udp_destroy_table(fs_udp, i);

kfree(fs_udp);
priv->fs.udp = NULL;
priv->fs->udp = NULL;
}

int mlx5e_fs_tt_redirect_udp_create(struct mlx5e_priv *priv)
{
int i, err;

if (priv->fs.udp) {
priv->fs.udp->ref_cnt++;
if (priv->fs->udp) {
priv->fs->udp->ref_cnt++;
return 0;
}

priv->fs.udp = kzalloc(sizeof(*priv->fs.udp), GFP_KERNEL);
if (!priv->fs.udp)
priv->fs->udp = kzalloc(sizeof(*priv->fs->udp), GFP_KERNEL);
if (!priv->fs->udp)
return -ENOMEM;

for (i = 0; i < FS_UDP_NUM_TYPES; i++) {
Expand All @@ -335,16 +335,16 @@ int mlx5e_fs_tt_redirect_udp_create(struct mlx5e_priv *priv)
if (err)
goto err_destroy_tables;

priv->fs.udp->ref_cnt = 1;
priv->fs->udp->ref_cnt = 1;

return 0;

err_destroy_tables:
while (--i >= 0)
fs_udp_destroy_table(priv->fs.udp, i);
fs_udp_destroy_table(priv->fs->udp, i);

kfree(priv->fs.udp);
priv->fs.udp = NULL;
kfree(priv->fs->udp);
priv->fs->udp = NULL;
return err;
}

Expand All @@ -371,7 +371,7 @@ mlx5e_fs_tt_redirect_any_add_rule(struct mlx5e_priv *priv,
if (!spec)
return ERR_PTR(-ENOMEM);

fs_any = priv->fs.any;
fs_any = priv->fs->any;
ft = fs_any->table.t;

fs_any_set_ethertype_flow(spec, ether_type);
Expand All @@ -398,10 +398,10 @@ static int fs_any_add_default_rule(struct mlx5e_priv *priv)
struct mlx5e_fs_any *fs_any;
int err;

fs_any = priv->fs.any;
fs_any = priv->fs->any;
fs_any_t = &fs_any->table;

dest = mlx5_ttc_get_default_dest(priv->fs.ttc, MLX5_TT_ANY);
dest = mlx5_ttc_get_default_dest(priv->fs->ttc, MLX5_TT_ANY);
rule = mlx5_add_flow_rules(fs_any_t->t, NULL, &flow_act, &dest, 1);
if (IS_ERR(rule)) {
err = PTR_ERR(rule);
Expand Down Expand Up @@ -474,7 +474,7 @@ static int fs_any_create_groups(struct mlx5e_flow_table *ft)

static int fs_any_create_table(struct mlx5e_priv *priv)
{
struct mlx5e_flow_table *ft = &priv->fs.any->table;
struct mlx5e_flow_table *ft = &priv->fs->any->table;
struct mlx5_flow_table_attr ft_attr = {};
int err;

Expand All @@ -484,7 +484,7 @@ static int fs_any_create_table(struct mlx5e_priv *priv)
ft_attr.level = MLX5E_FS_TT_ANY_FT_LEVEL;
ft_attr.prio = MLX5E_NIC_PRIO;

ft->t = mlx5_create_flow_table(priv->fs.ns, &ft_attr);
ft->t = mlx5_create_flow_table(priv->fs->ns, &ft_attr);
if (IS_ERR(ft->t)) {
err = PTR_ERR(ft->t);
ft->t = NULL;
Expand Down Expand Up @@ -514,7 +514,7 @@ static int fs_any_disable(struct mlx5e_priv *priv)
int err;

/* Modify ttc rules destination to point back to the indir TIRs */
err = mlx5_ttc_fwd_default_dest(priv->fs.ttc, MLX5_TT_ANY);
err = mlx5_ttc_fwd_default_dest(priv->fs->ttc, MLX5_TT_ANY);
if (err) {
netdev_err(priv->netdev,
"%s: modify ttc[%d] default destination failed, err(%d)\n",
Expand All @@ -530,10 +530,10 @@ static int fs_any_enable(struct mlx5e_priv *priv)
int err;

dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
dest.ft = priv->fs.any->table.t;
dest.ft = priv->fs->any->table.t;

/* Modify ttc rules destination to point on the accel_fs FTs */
err = mlx5_ttc_fwd_dest(priv->fs.ttc, MLX5_TT_ANY, &dest);
err = mlx5_ttc_fwd_dest(priv->fs->ttc, MLX5_TT_ANY, &dest);
if (err) {
netdev_err(priv->netdev,
"%s: modify ttc[%d] destination to accel failed, err(%d)\n",
Expand All @@ -555,7 +555,7 @@ static void fs_any_destroy_table(struct mlx5e_fs_any *fs_any)

void mlx5e_fs_tt_redirect_any_destroy(struct mlx5e_priv *priv)
{
struct mlx5e_fs_any *fs_any = priv->fs.any;
struct mlx5e_fs_any *fs_any = priv->fs->any;

if (!fs_any)
return;
Expand All @@ -568,20 +568,20 @@ void mlx5e_fs_tt_redirect_any_destroy(struct mlx5e_priv *priv)
fs_any_destroy_table(fs_any);

kfree(fs_any);
priv->fs.any = NULL;
priv->fs->any = NULL;
}

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

if (priv->fs.any) {
priv->fs.any->ref_cnt++;
if (priv->fs->any) {
priv->fs->any->ref_cnt++;
return 0;
}

priv->fs.any = kzalloc(sizeof(*priv->fs.any), GFP_KERNEL);
if (!priv->fs.any)
priv->fs->any = kzalloc(sizeof(*priv->fs->any), GFP_KERNEL);
if (!priv->fs->any)
return -ENOMEM;

err = fs_any_create_table(priv);
Expand All @@ -592,14 +592,14 @@ int mlx5e_fs_tt_redirect_any_create(struct mlx5e_priv *priv)
if (err)
goto err_destroy_table;

priv->fs.any->ref_cnt = 1;
priv->fs->any->ref_cnt = 1;

return 0;

err_destroy_table:
fs_any_destroy_table(priv->fs.any);
fs_any_destroy_table(priv->fs->any);

kfree(priv->fs.any);
priv->fs.any = NULL;
kfree(priv->fs->any);
priv->fs->any = NULL;
return err;
}
8 changes: 4 additions & 4 deletions drivers/net/ethernet/mellanox/mlx5/core/en/ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ static int mlx5e_ptp_set_state(struct mlx5e_ptp *c, struct mlx5e_params *params)

static void mlx5e_ptp_rx_unset_fs(struct mlx5e_priv *priv)
{
struct mlx5e_ptp_fs *ptp_fs = priv->fs.ptp_fs;
struct mlx5e_ptp_fs *ptp_fs = priv->fs->ptp_fs;

if (!ptp_fs->valid)
return;
Expand All @@ -641,7 +641,7 @@ static void mlx5e_ptp_rx_unset_fs(struct mlx5e_priv *priv)
static int mlx5e_ptp_rx_set_fs(struct mlx5e_priv *priv)
{
u32 tirn = mlx5e_rx_res_get_tirn_ptp(priv->rx_res);
struct mlx5e_ptp_fs *ptp_fs = priv->fs.ptp_fs;
struct mlx5e_ptp_fs *ptp_fs = priv->fs->ptp_fs;
struct mlx5_flow_handle *rule;
int err;

Expand Down Expand Up @@ -808,13 +808,13 @@ int mlx5e_ptp_alloc_rx_fs(struct mlx5e_priv *priv)
if (!ptp_fs)
return -ENOMEM;

priv->fs.ptp_fs = ptp_fs;
priv->fs->ptp_fs = ptp_fs;
return 0;
}

void mlx5e_ptp_free_rx_fs(struct mlx5e_priv *priv)
{
struct mlx5e_ptp_fs *ptp_fs = priv->fs.ptp_fs;
struct mlx5e_ptp_fs *ptp_fs = priv->fs->ptp_fs;

if (!mlx5e_profile_feature_cap(priv->profile, PTP_RX))
return;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/en/tc/act/goto.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ validate_goto_chain(struct mlx5e_priv *priv,
u32 max_chain;

esw = priv->mdev->priv.eswitch;
chains = is_esw ? esw_chains(esw) : mlx5e_nic_chains(priv->fs.tc);
chains = is_esw ? esw_chains(esw) : mlx5e_nic_chains(priv->fs->tc);
max_chain = mlx5_chains_get_chain_range(chains);
reformat_and_fwd = is_esw ?
MLX5_CAP_ESW_FLOWTABLE_FDB(priv->mdev, reformat_and_fwd_to_table) :
Expand Down
Loading

0 comments on commit af8bbf7

Please sign in to comment.