Skip to content

Commit 1cabe6b

Browse files
Maor Gottliebdavem330
authored andcommitted
net/mlx5e: Create aRFS flow tables
Create the following four flow tables for aRFS usage: 1. IPv4 TCP - filtering 4-tuple of IPv4 TCP packets. 2. IPv6 TCP - filtering 4-tuple of IPv6 TCP packets. 3. IPv4 UDP - filtering 4-tuple of IPv4 UDP packets. 4. IPv6 UDP - filtering 4-tuple of IPv6 UDP packets. Each flow table has two flow groups: one for the 4-tuple filtering (full match) and the other contains * rule for miss rule. Full match rule means a hit for aRFS and packet will be forwarded to the dedicated RQ/Core, miss rule packets will be forwarded to default RSS hashing. Signed-off-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5a7b27e commit 1cabe6b

File tree

6 files changed

+313
-14
lines changed

6 files changed

+313
-14
lines changed

drivers/net/ethernet/mellanox/mlx5/core/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ mlx5_core-$(CONFIG_MLX5_CORE_EN) += wq.o eswitch.o \
99
en_txrx.o en_clock.o vxlan.o en_tc.o
1010

1111
mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o
12+
mlx5_core-$(CONFIG_RFS_ACCEL) += en_arfs.o

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "mlx5_core.h"
4949
#include "en_stats.h"
5050

51+
#define MLX5_SET_CFG(p, f, v) MLX5_SET(create_flow_group_in, p, f, v)
52+
5153
#define MLX5E_MAX_NUM_TC 8
5254

5355
#define MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE 0x6
@@ -446,12 +448,38 @@ struct mlx5e_ttc_table {
446448
struct mlx5_flow_rule *rules[MLX5E_NUM_TT];
447449
};
448450

451+
struct arfs_table {
452+
struct mlx5e_flow_table ft;
453+
struct mlx5_flow_rule *default_rule;
454+
};
455+
456+
enum arfs_type {
457+
ARFS_IPV4_TCP,
458+
ARFS_IPV6_TCP,
459+
ARFS_IPV4_UDP,
460+
ARFS_IPV6_UDP,
461+
ARFS_NUM_TYPES,
462+
};
463+
464+
struct mlx5e_arfs_tables {
465+
struct arfs_table arfs_tables[ARFS_NUM_TYPES];
466+
};
467+
468+
/* NIC prio FTS */
469+
enum {
470+
MLX5E_VLAN_FT_LEVEL = 0,
471+
MLX5E_L2_FT_LEVEL,
472+
MLX5E_TTC_FT_LEVEL,
473+
MLX5E_ARFS_FT_LEVEL
474+
};
475+
449476
struct mlx5e_flow_steering {
450477
struct mlx5_flow_namespace *ns;
451478
struct mlx5e_tc_table tc;
452479
struct mlx5e_vlan_table vlan;
453480
struct mlx5e_l2_table l2;
454481
struct mlx5e_ttc_table ttc;
482+
struct mlx5e_arfs_tables arfs;
455483
};
456484

457485
struct mlx5e_direct_tir {
@@ -570,6 +598,7 @@ void mlx5e_update_stats(struct mlx5e_priv *priv);
570598
int mlx5e_create_flow_steering(struct mlx5e_priv *priv);
571599
void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv);
572600
void mlx5e_init_l2_addr(struct mlx5e_priv *priv);
601+
void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft);
573602
void mlx5e_set_rx_mode_work(struct work_struct *work);
574603

575604
void mlx5e_fill_hwstamp(struct mlx5e_tstamp *clock, u64 timestamp,
@@ -646,6 +675,18 @@ extern const struct dcbnl_rtnl_ops mlx5e_dcbnl_ops;
646675
int mlx5e_dcbnl_ieee_setets_core(struct mlx5e_priv *priv, struct ieee_ets *ets);
647676
#endif
648677

678+
#ifndef CONFIG_RFS_ACCEL
679+
static inline int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
680+
{
681+
return 0;
682+
}
683+
684+
static inline void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv) {}
685+
#else
686+
int mlx5e_arfs_create_tables(struct mlx5e_priv *priv);
687+
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv);
688+
#endif
689+
649690
u16 mlx5e_get_max_inline_cap(struct mlx5_core_dev *mdev);
650691

651692
#endif /* __MLX5_EN_H__ */
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
/*
2+
* Copyright (c) 2016, Mellanox Technologies. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*/
32+
33+
#include "en.h"
34+
#include <linux/mlx5/fs.h>
35+
36+
static void arfs_destroy_table(struct arfs_table *arfs_t)
37+
{
38+
mlx5_del_flow_rule(arfs_t->default_rule);
39+
mlx5e_destroy_flow_table(&arfs_t->ft);
40+
}
41+
42+
void mlx5e_arfs_destroy_tables(struct mlx5e_priv *priv)
43+
{
44+
int i;
45+
46+
if (!(priv->netdev->hw_features & NETIF_F_NTUPLE))
47+
return;
48+
for (i = 0; i < ARFS_NUM_TYPES; i++) {
49+
if (!IS_ERR_OR_NULL(priv->fs.arfs.arfs_tables[i].ft.t))
50+
arfs_destroy_table(&priv->fs.arfs.arfs_tables[i]);
51+
}
52+
}
53+
54+
static int arfs_add_default_rule(struct mlx5e_priv *priv,
55+
enum arfs_type type)
56+
{
57+
struct arfs_table *arfs_t = &priv->fs.arfs.arfs_tables[type];
58+
struct mlx5_flow_destination dest;
59+
u8 match_criteria_enable = 0;
60+
u32 *tirn = priv->indir_tirn;
61+
u32 *match_criteria;
62+
u32 *match_value;
63+
int err = 0;
64+
65+
match_value = mlx5_vzalloc(MLX5_ST_SZ_BYTES(fte_match_param));
66+
match_criteria = mlx5_vzalloc(MLX5_ST_SZ_BYTES(fte_match_param));
67+
if (!match_value || !match_criteria) {
68+
netdev_err(priv->netdev, "%s: alloc failed\n", __func__);
69+
err = -ENOMEM;
70+
goto out;
71+
}
72+
73+
dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
74+
switch (type) {
75+
case ARFS_IPV4_TCP:
76+
dest.tir_num = tirn[MLX5E_TT_IPV4_TCP];
77+
break;
78+
case ARFS_IPV4_UDP:
79+
dest.tir_num = tirn[MLX5E_TT_IPV4_UDP];
80+
break;
81+
case ARFS_IPV6_TCP:
82+
dest.tir_num = tirn[MLX5E_TT_IPV6_TCP];
83+
break;
84+
case ARFS_IPV6_UDP:
85+
dest.tir_num = tirn[MLX5E_TT_IPV6_UDP];
86+
break;
87+
default:
88+
err = -EINVAL;
89+
goto out;
90+
}
91+
92+
arfs_t->default_rule = mlx5_add_flow_rule(arfs_t->ft.t, match_criteria_enable,
93+
match_criteria, match_value,
94+
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
95+
MLX5_FS_DEFAULT_FLOW_TAG,
96+
&dest);
97+
if (IS_ERR(arfs_t->default_rule)) {
98+
err = PTR_ERR(arfs_t->default_rule);
99+
arfs_t->default_rule = NULL;
100+
netdev_err(priv->netdev, "%s: add rule failed, arfs type=%d\n",
101+
__func__, type);
102+
}
103+
out:
104+
kvfree(match_criteria);
105+
kvfree(match_value);
106+
return err;
107+
}
108+
109+
#define MLX5E_ARFS_NUM_GROUPS 2
110+
#define MLX5E_ARFS_GROUP1_SIZE BIT(12)
111+
#define MLX5E_ARFS_GROUP2_SIZE BIT(0)
112+
#define MLX5E_ARFS_TABLE_SIZE (MLX5E_ARFS_GROUP1_SIZE +\
113+
MLX5E_ARFS_GROUP2_SIZE)
114+
static int arfs_create_groups(struct mlx5e_flow_table *ft,
115+
enum arfs_type type)
116+
{
117+
int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
118+
void *outer_headers_c;
119+
int ix = 0;
120+
u32 *in;
121+
int err;
122+
u8 *mc;
123+
124+
ft->g = kcalloc(MLX5E_ARFS_NUM_GROUPS,
125+
sizeof(*ft->g), GFP_KERNEL);
126+
in = mlx5_vzalloc(inlen);
127+
if (!in || !ft->g) {
128+
kvfree(ft->g);
129+
kvfree(in);
130+
return -ENOMEM;
131+
}
132+
133+
mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
134+
outer_headers_c = MLX5_ADDR_OF(fte_match_param, mc,
135+
outer_headers);
136+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, ethertype);
137+
switch (type) {
138+
case ARFS_IPV4_TCP:
139+
case ARFS_IPV6_TCP:
140+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, tcp_dport);
141+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, tcp_sport);
142+
break;
143+
case ARFS_IPV4_UDP:
144+
case ARFS_IPV6_UDP:
145+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, udp_dport);
146+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, udp_sport);
147+
break;
148+
default:
149+
err = -EINVAL;
150+
goto out;
151+
}
152+
153+
switch (type) {
154+
case ARFS_IPV4_TCP:
155+
case ARFS_IPV4_UDP:
156+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c,
157+
src_ipv4_src_ipv6.ipv4_layout.ipv4);
158+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c,
159+
dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
160+
break;
161+
case ARFS_IPV6_TCP:
162+
case ARFS_IPV6_UDP:
163+
memset(MLX5_ADDR_OF(fte_match_set_lyr_2_4, outer_headers_c,
164+
src_ipv4_src_ipv6.ipv6_layout.ipv6),
165+
0xff, 16);
166+
memset(MLX5_ADDR_OF(fte_match_set_lyr_2_4, outer_headers_c,
167+
dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
168+
0xff, 16);
169+
break;
170+
default:
171+
err = -EINVAL;
172+
goto out;
173+
}
174+
175+
MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
176+
MLX5_SET_CFG(in, start_flow_index, ix);
177+
ix += MLX5E_ARFS_GROUP1_SIZE;
178+
MLX5_SET_CFG(in, end_flow_index, ix - 1);
179+
ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
180+
if (IS_ERR(ft->g[ft->num_groups]))
181+
goto err;
182+
ft->num_groups++;
183+
184+
memset(in, 0, inlen);
185+
MLX5_SET_CFG(in, start_flow_index, ix);
186+
ix += MLX5E_ARFS_GROUP2_SIZE;
187+
MLX5_SET_CFG(in, end_flow_index, ix - 1);
188+
ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
189+
if (IS_ERR(ft->g[ft->num_groups]))
190+
goto err;
191+
ft->num_groups++;
192+
193+
kvfree(in);
194+
return 0;
195+
196+
err:
197+
err = PTR_ERR(ft->g[ft->num_groups]);
198+
ft->g[ft->num_groups] = NULL;
199+
out:
200+
kvfree(in);
201+
202+
return err;
203+
}
204+
205+
static int arfs_create_table(struct mlx5e_priv *priv,
206+
enum arfs_type type)
207+
{
208+
struct mlx5e_arfs_tables *arfs = &priv->fs.arfs;
209+
struct mlx5e_flow_table *ft = &arfs->arfs_tables[type].ft;
210+
int err;
211+
212+
ft->t = mlx5_create_flow_table(priv->fs.ns, MLX5E_NIC_PRIO,
213+
MLX5E_ARFS_TABLE_SIZE, MLX5E_ARFS_FT_LEVEL);
214+
if (IS_ERR(ft->t)) {
215+
err = PTR_ERR(ft->t);
216+
ft->t = NULL;
217+
return err;
218+
}
219+
220+
err = arfs_create_groups(ft, type);
221+
if (err)
222+
goto err;
223+
224+
err = arfs_add_default_rule(priv, type);
225+
if (err)
226+
goto err;
227+
228+
return 0;
229+
err:
230+
mlx5e_destroy_flow_table(ft);
231+
return err;
232+
}
233+
234+
int mlx5e_arfs_create_tables(struct mlx5e_priv *priv)
235+
{
236+
int err = 0;
237+
int i;
238+
239+
if (!(priv->netdev->hw_features & NETIF_F_NTUPLE))
240+
return 0;
241+
242+
for (i = 0; i < ARFS_NUM_TYPES; i++) {
243+
err = arfs_create_table(priv, i);
244+
if (err)
245+
goto err;
246+
}
247+
return 0;
248+
err:
249+
mlx5e_arfs_destroy_tables(priv);
250+
return err;
251+
}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ static int mlx5e_add_l2_flow_rule(struct mlx5e_priv *priv,
4242
static void mlx5e_del_l2_flow_rule(struct mlx5e_priv *priv,
4343
struct mlx5e_l2_rule *ai);
4444

45-
/* NIC prio FTS */
46-
enum {
47-
MLX5E_VLAN_FT_LEVEL = 0,
48-
MLX5E_L2_FT_LEVEL,
49-
MLX5E_TTC_FT_LEVEL
50-
};
51-
52-
#define MLX5_SET_CFG(p, f, v) MLX5_SET(create_flow_group_in, p, f, v)
53-
5445
enum {
5546
MLX5E_FULLMATCH = 0,
5647
MLX5E_ALLMULTI = 1,
@@ -530,7 +521,7 @@ void mlx5e_init_l2_addr(struct mlx5e_priv *priv)
530521
ether_addr_copy(priv->fs.l2.broadcast.addr, priv->netdev->broadcast);
531522
}
532523

533-
static void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft)
524+
void mlx5e_destroy_flow_table(struct mlx5e_flow_table *ft)
534525
{
535526
mlx5e_destroy_groups(ft);
536527
kfree(ft->g);
@@ -1083,11 +1074,18 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv)
10831074
if (!priv->fs.ns)
10841075
return -EINVAL;
10851076

1077+
err = mlx5e_arfs_create_tables(priv);
1078+
if (err) {
1079+
netdev_err(priv->netdev, "Failed to create arfs tables, err=%d\n",
1080+
err);
1081+
priv->netdev->hw_features &= ~NETIF_F_NTUPLE;
1082+
}
1083+
10861084
err = mlx5e_create_ttc_table(priv);
10871085
if (err) {
10881086
netdev_err(priv->netdev, "Failed to create ttc table, err=%d\n",
10891087
err);
1090-
return err;
1088+
goto err_destroy_arfs_tables;
10911089
}
10921090

10931091
err = mlx5e_create_l2_table(priv);
@@ -1110,6 +1108,8 @@ int mlx5e_create_flow_steering(struct mlx5e_priv *priv)
11101108
mlx5e_destroy_l2_table(priv);
11111109
err_destroy_ttc_table:
11121110
mlx5e_destroy_ttc_table(priv);
1111+
err_destroy_arfs_tables:
1112+
mlx5e_arfs_destroy_tables(priv);
11131113

11141114
return err;
11151115
}
@@ -1120,4 +1120,5 @@ void mlx5e_destroy_flow_steering(struct mlx5e_priv *priv)
11201120
mlx5e_destroy_vlan_table(priv);
11211121
mlx5e_destroy_l2_table(priv);
11221122
mlx5e_destroy_ttc_table(priv);
1123+
mlx5e_arfs_destroy_tables(priv);
11231124
}

0 commit comments

Comments
 (0)