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

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
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -90,22 +90,28 @@ enum {
};

struct mlx5e_flow_steering;
struct mlx5e_rx_res;
struct mlx5e_priv;

#ifdef CONFIG_MLX5_EN_ARFS
struct mlx5e_arfs_tables;

int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
int mlx5e_arfs_enable(struct mlx5e_priv *priv);
int mlx5e_arfs_disable(struct mlx5e_priv *priv);
int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
			     struct mlx5e_rx_res *rx_res, bool ntuple);
void mlx5e_arfs_destroy_tables(struct mlx5e_flow_steering *fs, bool ntuple);
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,
			u16 rxq_index, u32 flow_id);
#else
static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv) { return 0; }
static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) {	return -EOPNOTSUPP; }
static inline int mlx5e_arfs_create_tables(struct mlx5e_flow_steering *fs,
					   struct mlx5e_rx_res *rx_res, bool ntuple)
{ return 0; }
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

#ifdef CONFIG_MLX5_EN_TLS
+44 −43
Original line number Diff line number Diff line
@@ -114,16 +114,16 @@ 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;

	for (i = 0; i < ARFS_NUM_TYPES; i++) {
		/* Modify ttc rules destination back to their default */
		err = mlx5_ttc_fwd_default_dest(ttc, arfs_get_tt(i));
		if (err) {
			netdev_err(priv->netdev,
			fs_err(fs,
			       "%s: modify ttc[%d] default destination failed, err(%d)\n",
			       __func__, arfs_get_tt(i), err);
			return err;
@@ -132,19 +132,19 @@ static int arfs_disable(struct mlx5e_priv *priv)
	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 mlx5e_arfs_tables *arfs =  mlx5e_fs_get_arfs(priv->fs);
	struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs, false);
	struct mlx5e_arfs_tables *arfs =  mlx5e_fs_get_arfs(fs);
	struct mlx5_flow_destination dest = {};
	int err, i;

@@ -154,10 +154,9 @@ int mlx5e_arfs_enable(struct mlx5e_priv *priv)
		/* Modify ttc rules destination to point on the aRFS FTs */
		err = mlx5_ttc_fwd_dest(ttc, arfs_get_tt(i), &dest);
		if (err) {
			netdev_err(priv->netdev,
				   "%s: modify ttc[%d] dest to arfs, failed err(%d)\n",
			fs_err(fs, "%s: modify ttc[%d] dest to arfs, failed err(%d)\n",
			       __func__, arfs_get_tt(i), err);
			arfs_disable(priv);
			arfs_disable(fs);
			return err;
		}
	}
@@ -170,12 +169,12 @@ static void arfs_destroy_table(struct arfs_table *arfs_t)
	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;

	arfs_del_rules(priv);
	arfs_del_rules(fs);
	destroy_workqueue(arfs->wq);
	for (i = 0; i < ARFS_NUM_TYPES; i++) {
		if (!IS_ERR_OR_NULL(arfs->arfs_tables[i].ft.t))
@@ -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);
	if (!(priv->netdev->hw_features & NETIF_F_NTUPLE))
	struct mlx5e_arfs_tables *arfs =  mlx5e_fs_get_arfs(fs);

	if (!ntuple)
		return;

	_mlx5e_cleanup_tables(priv);
	mlx5e_fs_set_arfs(priv->fs, NULL);
	_mlx5e_cleanup_tables(fs);
	mlx5e_fs_set_arfs(fs, NULL);
	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)
{
	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 mlx5_flow_destination dest = {};
	MLX5_DECLARE_FLOW_ACT(flow_act);
@@ -207,23 +208,21 @@ static int arfs_add_default_rule(struct mlx5e_priv *priv,
	dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
	tt = arfs_get_tt(type);
	if (tt == -EINVAL) {
		netdev_err(priv->netdev, "%s: bad arfs_type: %d\n",
			   __func__, type);
		fs_err(fs, "%s: bad arfs_type: %d\n", __func__, type);
		return -EINVAL;
	}

	/* FIXME: Must use mlx5_ttc_get_default_dest(),
	 * 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,
						   &flow_act,
						   &dest, 1);
	if (IS_ERR(arfs_t->default_rule)) {
		err = PTR_ERR(arfs_t->default_rule);
		arfs_t->default_rule = NULL;
		netdev_err(priv->netdev, "%s: add rule failed, arfs type=%d\n",
			   __func__, type);
		fs_err(fs, "%s: add rule failed, arfs type=%d\n", __func__, type);
	}

	return err;
@@ -325,11 +324,12 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft,
	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)
{
	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(priv->fs, false);
	struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(priv->fs);
	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs, false);
	struct mlx5e_arfs_tables *arfs = mlx5e_fs_get_arfs(fs);
	struct mlx5e_flow_table *ft = &arfs->arfs_tables[type].ft;
	struct mlx5_flow_table_attr ft_attr = {};
	int err;
@@ -351,7 +351,7 @@ static int arfs_create_table(struct mlx5e_priv *priv,
	if (err)
		goto err;

	err = arfs_add_default_rule(priv, type);
	err = arfs_add_default_rule(fs, rx_res,  type);
	if (err)
		goto err;

@@ -361,13 +361,14 @@ static int arfs_create_table(struct mlx5e_priv *priv,
	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;
	int err = -ENOMEM;
	int i;

	if (!(priv->netdev->hw_features & NETIF_F_NTUPLE))
	if (!ntuple)
		return 0;

	arfs = kvzalloc(sizeof(*arfs), GFP_KERNEL);
@@ -380,19 +381,19 @@ int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
	if (!arfs->wq)
		goto err;

	mlx5e_fs_set_arfs(priv->fs, arfs);
	mlx5e_fs_set_arfs(fs, arfs);

	for (i = 0; i < ARFS_NUM_TYPES; i++) {
		err = arfs_create_table(priv, i);
		err = arfs_create_table(fs, rx_res, i);
		if (err)
			goto err_des;
	}
	return 0;

err_des:
	_mlx5e_cleanup_tables(priv);
	_mlx5e_cleanup_tables(fs);
err:
	mlx5e_fs_set_arfs(priv->fs, NULL);
	mlx5e_fs_set_arfs(fs, NULL);
	kvfree(arfs);
	return err;
}
@@ -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 arfs_rule *rule;
	HLIST_HEAD(del_list);
+2 −2
Original line number Diff line number Diff line
@@ -495,14 +495,14 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,

	arfs_enabled = opened && (priv->netdev->features & NETIF_F_NTUPLE);
	if (arfs_enabled)
		mlx5e_arfs_disable(priv);
		mlx5e_arfs_disable(priv->fs);

	/* Switch to new channels, set new parameters and close old ones */
	err = mlx5e_safe_switch_params(priv, &new_params,
				       mlx5e_num_channels_changed_ctx, NULL, true);

	if (arfs_enabled) {
		int err2 = mlx5e_arfs_enable(priv);
		int err2 = mlx5e_arfs_enable(priv->fs);

		if (err2)
			netdev_err(priv->netdev, "%s: mlx5e_arfs_enable failed: %d\n",
+6 −3
Original line number Diff line number Diff line
@@ -1303,7 +1303,8 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv)
		return -EOPNOTSUPP;

	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) {
		fs_err(fs, "Failed to create arfs tables, err=%d\n", err);
		priv->netdev->hw_features &= ~NETIF_F_NTUPLE;
@@ -1350,7 +1351,8 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv)
err_destroy_inner_ttc_table:
	mlx5e_destroy_inner_ttc_table(priv);
err_destroy_arfs_tables:
	mlx5e_arfs_destroy_tables(priv);
	mlx5e_arfs_destroy_tables(priv->fs,
				  !!(priv->netdev->hw_features & NETIF_F_NTUPLE));

	return err;
}
@@ -1362,7 +1364,8 @@ void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv)
	mlx5e_destroy_l2_table(priv);
	mlx5e_destroy_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);
}

+2 −2
Original line number Diff line number Diff line
@@ -3824,9 +3824,9 @@ static int set_feature_arfs(struct net_device *netdev, bool enable)
	int err;

	if (enable)
		err = mlx5e_arfs_enable(priv);
		err = mlx5e_arfs_enable(priv->fs);
	else
		err = mlx5e_arfs_disable(priv);
		err = mlx5e_arfs_disable(priv->fs);

	return err;
}
Loading