Commit 45b83c6c authored by Lama Kayal's avatar Lama Kayal Committed by Saeed Mahameed

net/mlx5e: Make flow steering arfs independent of priv

Decouple arfs flow steering functionality from priv.
Make all arfs functions defined under fs.h get flow_steering
struct as an argument, thus helping with the process of decoupling the
whole flow steering API from en.h.
Signed-off-by: default avatarLama Kayal <lkayal@nvidia.com>
Reviewed-by: default avatarTariq Toukan <tariqt@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 93a07599
...@@ -90,22 +90,28 @@ enum { ...@@ -90,22 +90,28 @@ enum {
}; };
struct mlx5e_flow_steering; struct mlx5e_flow_steering;
struct mlx5e_rx_res;
struct mlx5e_priv; struct mlx5e_priv;
#ifdef CONFIG_MLX5_EN_ARFS #ifdef CONFIG_MLX5_EN_ARFS
struct mlx5e_arfs_tables; struct mlx5e_arfs_tables;
int mlx5e_arfs_create_tables(struct mlx5e_priv *priv); int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv); struct mlx5e_rx_res *rx_res, bool ntuple);
int mlx5e_arfs_enable(struct mlx5e_priv *priv); void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple);
int mlx5e_arfs_disable(struct mlx5e_priv *priv); int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs);
int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs);
int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
u16 rxq_index, u32 flow_id); u16 rxq_index, u32 flow_id);
#else #else
static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; } static inline int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {} struct mlx5e_rx_res *rx_res, bool ntuple)
static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; } { return 0; }
static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; } static inline void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple) {}
static inline int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs)
{ return -EOPNOTSUPP; }
static inline int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs)
{ return -EOPNOTSUPP; }
#endif #endif
#ifdef CONFIG_MLX5_EN_TLS #ifdef CONFIG_MLX5_EN_TLS
......
...@@ -114,37 +114,37 @@ static enum mlx5_traffic_types arfs_get_tt(enum arfs_type type) ...@@ -114,37 +114,37 @@ static enum mlx5_traffic_types arfs_get_tt(enum arfs_type type)
} }
} }
static int arfs_disable(struct mlx5e_priv *priv) static int arfs_disable(struct mlx5e_flow_steering *fs)
{ {
struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(priv->fs, false); struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs, false);
int err, i; int err, i;
for (i = 0; i < ARFS_NUM_TYPES; i++) { for (i = 0; i < ARFS_NUM_TYPES; i++) {
/* Modify ttc rules destination back to their default */ /* Modify ttc rules destination back to their default */
err = mlx5_ttc_fwd_default_dest(ttc, arfs_get_tt(i)); err = mlx5_ttc_fwd_default_dest(ttc, arfs_get_tt(i));
if (err) { if (err) {
netdev_err(priv->netdev, fs_err(fs,
"%s: modify ttc[%d] default destination failed, err(%d)\n", "%s: modify ttc[%d] default destination failed, err(%d)\n",
__func__, arfs_get_tt(i), err); __func__, arfs_get_tt(i), err);
return err; return err;
} }
} }
return 0; return 0;
} }
static void arfs_del_rules(struct mlx5e_priv *priv); static void arfs_del_rules(struct mlx5e_flow_steering *fs);
int mlx5e_arfs_disable(struct mlx5e_priv *priv) int mlx5e_arfs_disable(struct mlx5e_flow_steering *fs)
{ {
arfs_del_rules(priv); arfs_del_rules(fs);
return arfs_disable(priv); return arfs_disable(fs);
} }
int mlx5e_arfs_enable(struct mlx5e_priv *priv) int mlx5e_arfs_enable(struct mlx5e_flow_steering *fs)
{ {
struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(priv->fs, false); struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs, false);
struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(priv->fs); struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(fs);
struct mlx5_flow_destination dest = {}; struct mlx5_flow_destination dest = {};
int err, i; int err, i;
...@@ -154,10 +154,9 @@ int mlx5e_arfs_enable(struct mlx5e_priv *priv) ...@@ -154,10 +154,9 @@ int mlx5e_arfs_enable(struct mlx5e_priv *priv)
/* Modify ttc rules destination to point on the aRFS FTs */ /* Modify ttc rules destination to point on the aRFS FTs */
err = mlx5_ttc_fwd_dest(ttc, arfs_get_tt(i), &dest); err = mlx5_ttc_fwd_dest(ttc, arfs_get_tt(i), &dest);
if (err) { if (err) {
netdev_err(priv->netdev, fs_err(fs, "%s: modify ttc[%d] dest to arfs, failed err(%d)\n",
"%s: modify ttc[%d] dest to arfs, failed err(%d)\n", __func__, arfs_get_tt(i), err);
__func__, arfs_get_tt(i), err); arfs_disable(fs);
arfs_disable(priv);
return err; return err;
} }
} }
...@@ -170,12 +169,12 @@ static void arfs_destroy_table(struct arfs_table *arfs_t) ...@@ -170,12 +169,12 @@ static void arfs_destroy_table(struct arfs_table *arfs_t)
mlx5e_destroy_flow_table(&arfs_t->ft); mlx5e_destroy_flow_table(&arfs_t->ft);
} }
static void _mlx5e_cleanup_tables(struct mlx5e_priv *priv) static void _mlx5e_cleanup_tables(struct mlx5e_flow_steering *fs)
{ {
struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(priv->fs); struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(fs);
int i; int i;
arfs_del_rules(priv); arfs_del_rules(fs);
destroy_workqueue(arfs->wq); destroy_workqueue(arfs->wq);
for (i = 0; i < ARFS_NUM_TYPES; i++) { for (i = 0; i < ARFS_NUM_TYPES; i++) {
if (!IS_ERR_OR_NULL(arfs->arfs_tables[i].ft.t)) if (!IS_ERR_OR_NULL(arfs->arfs_tables[i].ft.t))
...@@ -183,21 +182,23 @@ static void _mlx5e_cleanup_tables(struct mlx5e_priv *priv) ...@@ -183,21 +182,23 @@ static void _mlx5e_cleanup_tables(struct mlx5e_priv *priv)
} }
} }
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple)
{ {
struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(priv->fs); struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(fs);
if (!(priv->netdev->hw_features & NETIF_F_NTUPLE))
if (!ntuple)
return; return;
_mlx5e_cleanup_tables(priv); _mlx5e_cleanup_tables(fs);
mlx5e_fs_set_arfs(priv->fs, NULL); mlx5e_fs_set_arfs(fs, NULL);
kvfree(arfs); kvfree(arfs);
} }
static int arfs_add_default_rule(struct mlx5e_priv *priv, static int arfs_add_default_rule(struct mlx5e_flow_steering *fs,
struct mlx5e_rx_res *rx_res,
enum arfs_type type) enum arfs_type type)
{ {
struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(priv->fs); struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(fs);
struct arfs_table *arfs_t = &arfs->arfs_tables[type]; struct arfs_table *arfs_t = &arfs->arfs_tables[type];
struct mlx5_flow_destination dest = {}; struct mlx5_flow_destination dest = {};
MLX5_DECLARE_FLOW_ACT(flow_act); MLX5_DECLARE_FLOW_ACT(flow_act);
...@@ -207,23 +208,21 @@ static int arfs_add_default_rule(struct mlx5e_priv *priv, ...@@ -207,23 +208,21 @@ static int arfs_add_default_rule(struct mlx5e_priv *priv,
dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR; dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
tt = arfs_get_tt(type); tt = arfs_get_tt(type);
if (tt == -EINVAL) { if (tt == -EINVAL) {
netdev_err(priv->netdev, "%s: bad arfs_type: %d\n", fs_err(fs, "%s: bad arfs_type: %d\n", __func__, type);
__func__, type);
return -EINVAL; return -EINVAL;
} }
/* FIXME: Must use mlx5_ttc_get_default_dest(), /* FIXME: Must use mlx5_ttc_get_default_dest(),
* but can't since TTC default is not setup yet ! * but can't since TTC default is not setup yet !
*/ */
dest.tir_num = mlx5e_rx_res_get_tirn_rss(priv->rx_res, tt); dest.tir_num = mlx5e_rx_res_get_tirn_rss(rx_res, tt);
arfs_t->default_rule = mlx5_add_flow_rules(arfs_t->ft.t, NULL, arfs_t->default_rule = mlx5_add_flow_rules(arfs_t->ft.t, NULL,
&flow_act, &flow_act,
&dest, 1); &dest, 1);
if (IS_ERR(arfs_t->default_rule)) { if (IS_ERR(arfs_t->default_rule)) {
err = PTR_ERR(arfs_t->default_rule); err = PTR_ERR(arfs_t->default_rule);
arfs_t->default_rule = NULL; arfs_t->default_rule = NULL;
netdev_err(priv->netdev, "%s: add rule failed, arfs type=%d\n", fs_err(fs, "%s: add rule failed, arfs type=%d\n", __func__, type);
__func__, type);
} }
return err; return err;
...@@ -325,11 +324,12 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, ...@@ -325,11 +324,12 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft,
return err; return err;
} }
static int arfs_create_table(struct mlx5e_priv *priv, static int arfs_create_table(struct mlx5e_flow_steering *fs,
struct mlx5e_rx_res *rx_res,
enum arfs_type type) enum arfs_type type)
{ {
struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(priv->fs, false); struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs, false);
struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(priv->fs); struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(fs);
struct mlx5e_flow_table *ft = &arfs->arfs_tables[type].ft; struct mlx5e_flow_table *ft = &arfs->arfs_tables[type].ft;
struct mlx5_flow_table_attr ft_attr = {}; struct mlx5_flow_table_attr ft_attr = {};
int err; int err;
...@@ -351,7 +351,7 @@ static int arfs_create_table(struct mlx5e_priv *priv, ...@@ -351,7 +351,7 @@ static int arfs_create_table(struct mlx5e_priv *priv,
if (err) if (err)
goto err; goto err;
err = arfs_add_default_rule(priv, type); err = arfs_add_default_rule(fs, rx_res, type);
if (err) if (err)
goto err; goto err;
...@@ -361,13 +361,14 @@ static int arfs_create_table(struct mlx5e_priv *priv, ...@@ -361,13 +361,14 @@ static int arfs_create_table(struct mlx5e_priv *priv,
return err; return err;
} }
int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
struct mlx5e_rx_res *rx_res, bool ntuple)
{ {
struct mlx5e_arfs_tables *arfs; struct mlx5e_arfs_tables *arfs;
int err = -ENOMEM; int err = -ENOMEM;
int i; int i;
if (!(priv->netdev->hw_features & NETIF_F_NTUPLE)) if (!ntuple)
return 0; return 0;
arfs = kvzalloc(sizeof(*arfs), GFP_KERNEL); arfs = kvzalloc(sizeof(*arfs), GFP_KERNEL);
...@@ -380,19 +381,19 @@ int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) ...@@ -380,19 +381,19 @@ int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
if (!arfs->wq) if (!arfs->wq)
goto err; goto err;
mlx5e_fs_set_arfs(priv->fs, arfs); mlx5e_fs_set_arfs(fs, arfs);
for (i = 0; i < ARFS_NUM_TYPES; i++) { for (i = 0; i < ARFS_NUM_TYPES; i++) {
err = arfs_create_table(priv, i); err = arfs_create_table(fs, rx_res, i);
if (err) if (err)
goto err_des; goto err_des;
} }
return 0; return 0;
err_des: err_des:
_mlx5e_cleanup_tables(priv); _mlx5e_cleanup_tables(fs);
err: err:
mlx5e_fs_set_arfs(priv->fs, NULL); mlx5e_fs_set_arfs(fs, NULL);
kvfree(arfs); kvfree(arfs);
return err; return err;
} }
...@@ -430,9 +431,9 @@ static void arfs_may_expire_flow(struct mlx5e_priv *priv) ...@@ -430,9 +431,9 @@ static void arfs_may_expire_flow(struct mlx5e_priv *priv)
} }
} }
static void arfs_del_rules(struct mlx5e_priv *priv) static void arfs_del_rules(struct mlx5e_flow_steering *fs)
{ {
struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(priv->fs); struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(fs);
struct hlist_node *htmp; struct hlist_node *htmp;
struct arfs_rule *rule; struct arfs_rule *rule;
HLIST_HEAD(del_list); HLIST_HEAD(del_list);
......
...@@ -495,14 +495,14 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv, ...@@ -495,14 +495,14 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
arfs_enabled = opened && (priv->netdev->features & NETIF_F_NTUPLE); arfs_enabled = opened && (priv->netdev->features & NETIF_F_NTUPLE);
if (arfs_enabled) if (arfs_enabled)
mlx5e_arfs_disable(priv); mlx5e_arfs_disable(priv->fs);
/* Switch to new channels, set new parameters and close old ones */ /* Switch to new channels, set new parameters and close old ones */
err = mlx5e_safe_switch_params(priv, &new_params, err = mlx5e_safe_switch_params(priv, &new_params,
mlx5e_num_channels_changed_ctx, NULL, true); mlx5e_num_channels_changed_ctx, NULL, true);
if (arfs_enabled) { if (arfs_enabled) {
int err2 = mlx5e_arfs_enable(priv); int err2 = mlx5e_arfs_enable(priv->fs);
if (err2) if (err2)
netdev_err(priv->netdev, "%s: mlx5e_arfs_enable failed: %d\n", netdev_err(priv->netdev, "%s: mlx5e_arfs_enable failed: %d\n",
......
...@@ -1303,7 +1303,8 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv) ...@@ -1303,7 +1303,8 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv)
return -EOPNOTSUPP; return -EOPNOTSUPP;
mlx5e_fs_set_ns(priv->fs, ns, false); mlx5e_fs_set_ns(priv->fs, ns, false);
err = mlx5e_arfs_create_tables(priv); err = mlx5e_arfs_create_tables(priv->fs, priv->rx_res,
!!(priv->netdev->hw_features & NETIF_F_NTUPLE));
if (err) { if (err) {
fs_err(fs, "Failed to create arfs tables, err=%d\n", err); fs_err(fs, "Failed to create arfs tables, err=%d\n", err);
priv->netdev->hw_features &= ~NETIF_F_NTUPLE; priv->netdev->hw_features &= ~NETIF_F_NTUPLE;
...@@ -1350,7 +1351,8 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv) ...@@ -1350,7 +1351,8 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv)
err_destroy_inner_ttc_table: err_destroy_inner_ttc_table:
mlx5e_destroy_inner_ttc_table(priv); mlx5e_destroy_inner_ttc_table(priv);
err_destroy_arfs_tables: err_destroy_arfs_tables:
mlx5e_arfs_destroy_tables(priv); mlx5e_arfs_destroy_tables(priv->fs,
!!(priv->netdev->hw_features & NETIF_F_NTUPLE));
return err; return err;
} }
...@@ -1362,7 +1364,8 @@ void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv) ...@@ -1362,7 +1364,8 @@ void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv)
mlx5e_destroy_l2_table(priv); mlx5e_destroy_l2_table(priv);
mlx5e_destroy_ttc_table(priv); mlx5e_destroy_ttc_table(priv);
mlx5e_destroy_inner_ttc_table(priv); mlx5e_destroy_inner_ttc_table(priv);
mlx5e_arfs_destroy_tables(priv); mlx5e_arfs_destroy_tables(priv->fs,
!!(priv->netdev->hw_features & NETIF_F_NTUPLE));
mlx5e_ethtool_cleanup_steering(priv->fs); mlx5e_ethtool_cleanup_steering(priv->fs);
} }
......
...@@ -3824,9 +3824,9 @@ static int set_feature_arfs(struct net_device *netdev, bool enable) ...@@ -3824,9 +3824,9 @@ static int set_feature_arfs(struct net_device *netdev, bool enable)
int err; int err;
if (enable) if (enable)
err = mlx5e_arfs_enable(priv); err = mlx5e_arfs_enable(priv->fs);
else else
err = mlx5e_arfs_disable(priv); err = mlx5e_arfs_disable(priv->fs);
return err; return err;
} }
......
...@@ -330,8 +330,8 @@ static int mlx5i_create_flow_steering(struct mlx5e_priv *priv) ...@@ -330,8 +330,8 @@ static int mlx5i_create_flow_steering(struct mlx5e_priv *priv)
return -EINVAL; return -EINVAL;
mlx5e_fs_set_ns(priv->fs, ns, false); mlx5e_fs_set_ns(priv->fs, ns, false);
err = mlx5e_arfs_create_tables(priv->fs, priv->rx_res,
err = mlx5e_arfs_create_tables(priv); !!(priv->netdev->hw_features & NETIF_F_NTUPLE));
if (err) { if (err) {
netdev_err(priv->netdev, "Failed to create arfs tables, err=%d\n", netdev_err(priv->netdev, "Failed to create arfs tables, err=%d\n",
err); err);
...@@ -350,7 +350,8 @@ static int mlx5i_create_flow_steering(struct mlx5e_priv *priv) ...@@ -350,7 +350,8 @@ static int mlx5i_create_flow_steering(struct mlx5e_priv *priv)
return 0; return 0;
err_destroy_arfs_tables: err_destroy_arfs_tables:
mlx5e_arfs_destroy_tables(priv); mlx5e_arfs_destroy_tables(priv->fs,
!!(priv->netdev->hw_features & NETIF_F_NTUPLE));
return err; return err;
} }
...@@ -358,7 +359,8 @@ static int mlx5i_create_flow_steering(struct mlx5e_priv *priv) ...@@ -358,7 +359,8 @@ static int mlx5i_create_flow_steering(struct mlx5e_priv *priv)
static void mlx5i_destroy_flow_steering(struct mlx5e_priv *priv) static void mlx5i_destroy_flow_steering(struct mlx5e_priv *priv)
{ {
mlx5e_destroy_ttc_table(priv); mlx5e_destroy_ttc_table(priv);
mlx5e_arfs_destroy_tables(priv); mlx5e_arfs_destroy_tables(priv->fs,
!!(priv->netdev->hw_features & NETIF_F_NTUPLE));
mlx5e_ethtool_cleanup_steering(priv->fs); mlx5e_ethtool_cleanup_steering(priv->fs);
} }
......
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