Skip to content

Commit 45bf454

Browse files
Maor Gottliebdavem330
authored andcommitted
net/mlx5e: Enabling aRFS mechanism
Accelerated RFS requires that ntuple filtering is enabled via ethtool and driver supports ndo_rx_flow_steer. When the ntuple filtering is enabled, we modify the l3_l4 ttc rules to point on the aRFS flow tables and when the filtering is disabled, we modify the l3_l4 ttc rules to point on the RSS TIRs. Signed-off-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 18c908e commit 45bf454

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,21 @@ static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
690690
}
691691

692692
static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
693+
694+
static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv)
695+
{
696+
return -ENOTSUPP;
697+
}
698+
699+
static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv)
700+
{
701+
return -ENOTSUPP;
702+
}
693703
#else
694704
int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
695705
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
706+
int mlx5e_arfs_enable(struct mlx5e_priv *priv);
707+
int mlx5e_arfs_disable(struct mlx5e_priv *priv);
696708
int mlx5e_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb,
697709
u16 rxq_index, u32 flow_id);
698710
#endif

drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,87 @@ struct arfs_rule {
7272
for (j = 0; j < ARFS_HASH_SIZE; j++) \
7373
hlist_for_each_entry_safe(hn, tmp, &hash[j], hlist)
7474

75+
static enum mlx5e_traffic_types arfs_get_tt(enum arfs_type type)
76+
{
77+
switch (type) {
78+
case ARFS_IPV4_TCP:
79+
return MLX5E_TT_IPV4_TCP;
80+
case ARFS_IPV4_UDP:
81+
return MLX5E_TT_IPV4_UDP;
82+
case ARFS_IPV6_TCP:
83+
return MLX5E_TT_IPV6_TCP;
84+
case ARFS_IPV6_UDP:
85+
return MLX5E_TT_IPV6_UDP;
86+
default:
87+
return -EINVAL;
88+
}
89+
}
90+
91+
static int arfs_disable(struct mlx5e_priv *priv)
92+
{
93+
struct mlx5_flow_destination dest;
94+
u32 *tirn = priv->indir_tirn;
95+
int err = 0;
96+
int tt;
97+
int i;
98+
99+
dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
100+
for (i = 0; i < ARFS_NUM_TYPES; i++) {
101+
dest.tir_num = tirn[i];
102+
tt = arfs_get_tt(i);
103+
/* Modify ttc rules destination to bypass the aRFS tables*/
104+
err = mlx5_modify_rule_destination(priv->fs.ttc.rules[tt],
105+
&dest);
106+
if (err) {
107+
netdev_err(priv->netdev,
108+
"%s: modify ttc destination failed\n",
109+
__func__);
110+
return err;
111+
}
112+
}
113+
return 0;
114+
}
115+
116+
static void arfs_del_rules(struct mlx5e_priv *priv);
117+
118+
int mlx5e_arfs_disable(struct mlx5e_priv *priv)
119+
{
120+
arfs_del_rules(priv);
121+
122+
return arfs_disable(priv);
123+
}
124+
125+
int mlx5e_arfs_enable(struct mlx5e_priv *priv)
126+
{
127+
struct mlx5_flow_destination dest;
128+
int err = 0;
129+
int tt;
130+
int i;
131+
132+
dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
133+
for (i = 0; i < ARFS_NUM_TYPES; i++) {
134+
dest.ft = priv->fs.arfs.arfs_tables[i].ft.t;
135+
tt = arfs_get_tt(i);
136+
/* Modify ttc rules destination to point on the aRFS FTs */
137+
err = mlx5_modify_rule_destination(priv->fs.ttc.rules[tt],
138+
&dest);
139+
if (err) {
140+
netdev_err(priv->netdev,
141+
"%s: modify ttc destination failed err=%d\n",
142+
__func__, err);
143+
arfs_disable(priv);
144+
return err;
145+
}
146+
}
147+
return 0;
148+
}
149+
75150
static void arfs_destroy_table(struct arfs_table *arfs_t)
76151
{
77152
mlx5_del_flow_rule(arfs_t->default_rule);
78153
mlx5e_destroy_flow_table(&arfs_t->ft);
79154
}
80155

81-
static void arfs_del_rules(struct mlx5e_priv *priv);
82-
83156
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv)
84157
{
85158
int i;

drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ static int mlx5e_set_channels(struct net_device *dev,
456456
struct mlx5e_priv *priv = netdev_priv(dev);
457457
int ncv = mlx5e_get_max_num_channels(priv->mdev);
458458
unsigned int count = ch->combined_count;
459+
bool arfs_enabled;
459460
bool was_opened;
460461
int err = 0;
461462

@@ -484,13 +485,27 @@ static int mlx5e_set_channels(struct net_device *dev,
484485
if (was_opened)
485486
mlx5e_close_locked(dev);
486487

488+
arfs_enabled = dev->features & NETIF_F_NTUPLE;
489+
if (arfs_enabled)
490+
mlx5e_arfs_disable(priv);
491+
487492
priv->params.num_channels = count;
488493
mlx5e_build_default_indir_rqt(priv->mdev, priv->params.indirection_rqt,
489494
MLX5E_INDIR_RQT_SIZE, count);
490495

491496
if (was_opened)
492497
err = mlx5e_open_locked(dev);
498+
if (err)
499+
goto out;
493500

501+
if (arfs_enabled) {
502+
err = mlx5e_arfs_enable(priv);
503+
if (err)
504+
netdev_err(dev, "%s: mlx5e_arfs_enable failed: %d\n",
505+
__func__, err);
506+
}
507+
508+
out:
494509
mutex_unlock(&priv->state_lock);
495510

496511
return err;

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,21 @@ static int set_feature_rx_vlan(struct net_device *netdev, bool enable)
23082308
return err;
23092309
}
23102310

2311+
#ifdef CONFIG_RFS_ACCEL
2312+
static int set_feature_arfs(struct net_device *netdev, bool enable)
2313+
{
2314+
struct mlx5e_priv *priv = netdev_priv(netdev);
2315+
int err;
2316+
2317+
if (enable)
2318+
err = mlx5e_arfs_enable(priv);
2319+
else
2320+
err = mlx5e_arfs_disable(priv);
2321+
2322+
return err;
2323+
}
2324+
#endif
2325+
23112326
static int mlx5e_handle_feature(struct net_device *netdev,
23122327
netdev_features_t wanted_features,
23132328
netdev_features_t feature,
@@ -2347,6 +2362,10 @@ static int mlx5e_set_features(struct net_device *netdev,
23472362
set_feature_rx_all);
23482363
err |= mlx5e_handle_feature(netdev, features, NETIF_F_HW_VLAN_CTAG_RX,
23492364
set_feature_rx_vlan);
2365+
#ifdef CONFIG_RFS_ACCEL
2366+
err |= mlx5e_handle_feature(netdev, features, NETIF_F_NTUPLE,
2367+
set_feature_arfs);
2368+
#endif
23502369

23512370
return err ? -EINVAL : 0;
23522371
}
@@ -2562,6 +2581,9 @@ static const struct net_device_ops mlx5e_netdev_ops_basic = {
25622581
.ndo_set_features = mlx5e_set_features,
25632582
.ndo_change_mtu = mlx5e_change_mtu,
25642583
.ndo_do_ioctl = mlx5e_ioctl,
2584+
#ifdef CONFIG_RFS_ACCEL
2585+
.ndo_rx_flow_steer = mlx5e_rx_flow_steer,
2586+
#endif
25652587
};
25662588

25672589
static const struct net_device_ops mlx5e_netdev_ops_sriov = {
@@ -2581,6 +2603,9 @@ static const struct net_device_ops mlx5e_netdev_ops_sriov = {
25812603
.ndo_add_vxlan_port = mlx5e_add_vxlan_port,
25822604
.ndo_del_vxlan_port = mlx5e_del_vxlan_port,
25832605
.ndo_features_check = mlx5e_features_check,
2606+
#ifdef CONFIG_RFS_ACCEL
2607+
.ndo_rx_flow_steer = mlx5e_rx_flow_steer,
2608+
#endif
25842609
.ndo_set_vf_mac = mlx5e_set_vf_mac,
25852610
.ndo_set_vf_vlan = mlx5e_set_vf_vlan,
25862611
.ndo_get_vf_config = mlx5e_get_vf_config,

0 commit comments

Comments
 (0)