Skip to content

Commit c062d52

Browse files
Boris PismennySaeed Mahameed
authored andcommitted
net/mlx5e: Receive flow steering framework for accelerated TCP flows
The framework allows creating flow tables to steer incoming traffic of TCP sockets to the acceleration TIRs. This is used in downstream patches for TLS, and will be used in the future for other offloads. Signed-off-by: Boris Pismenny <[email protected]> Signed-off-by: Tariq Toukan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent b8922a7 commit c062d52

File tree

5 files changed

+311
-3
lines changed

5 files changed

+311
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ mlx5_core-$(CONFIG_MLX5_EN_IPSEC) += en_accel/ipsec.o en_accel/ipsec_rxtx.o \
7474
en_accel/ipsec_stats.o
7575

7676
mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/tls.o en_accel/tls_rxtx.o en_accel/tls_stats.o \
77-
en_accel/ktls.o en_accel/ktls_tx.o
77+
en_accel/ktls.o en_accel/ktls_tx.o en_accel/fs_tcp.o
7878

7979
mlx5_core-$(CONFIG_MLX5_SW_STEERING) += steering/dr_domain.o steering/dr_table.o \
8080
steering/dr_matcher.o steering/dr_rule.o \

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ enum {
123123
MLX5E_L2_FT_LEVEL,
124124
MLX5E_TTC_FT_LEVEL,
125125
MLX5E_INNER_TTC_FT_LEVEL,
126+
#ifdef CONFIG_MLX5_EN_TLS
127+
MLX5E_ACCEL_FS_TCP_FT_LEVEL,
128+
#endif
126129
#ifdef CONFIG_MLX5_EN_ARFS
127130
MLX5E_ARFS_FT_LEVEL
128131
#endif
@@ -216,6 +219,10 @@ static inline int mlx5e_arfs_enable(struct mlx5e_priv *priv) { return -EOPNOTSUP
216219
static inline int mlx5e_arfs_disable(struct mlx5e_priv *priv) { return -EOPNOTSUPP; }
217220
#endif
218221

222+
#ifdef CONFIG_MLX5_EN_TLS
223+
struct mlx5e_accel_fs_tcp;
224+
#endif
225+
219226
struct mlx5e_flow_steering {
220227
struct mlx5_flow_namespace *ns;
221228
#ifdef CONFIG_MLX5_EN_RXNFC
@@ -229,6 +236,9 @@ struct mlx5e_flow_steering {
229236
#ifdef CONFIG_MLX5_EN_ARFS
230237
struct mlx5e_arfs_tables arfs;
231238
#endif
239+
#ifdef CONFIG_MLX5_EN_TLS
240+
struct mlx5e_accel_fs_tcp *accel_tcp;
241+
#endif
232242
};
233243

234244
struct ttc_params {
Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
/* Copyright (c) 2020, Mellanox Technologies inc. All rights reserved. */
3+
4+
#include <linux/netdevice.h>
5+
#include "en_accel/fs_tcp.h"
6+
#include "fs_core.h"
7+
8+
enum accel_fs_tcp_type {
9+
ACCEL_FS_IPV4_TCP,
10+
ACCEL_FS_IPV6_TCP,
11+
ACCEL_FS_TCP_NUM_TYPES,
12+
};
13+
14+
struct mlx5e_accel_fs_tcp {
15+
struct mlx5e_flow_table tables[ACCEL_FS_TCP_NUM_TYPES];
16+
struct mlx5_flow_handle *default_rules[ACCEL_FS_TCP_NUM_TYPES];
17+
};
18+
19+
static enum mlx5e_traffic_types fs_accel2tt(enum accel_fs_tcp_type i)
20+
{
21+
switch (i) {
22+
case ACCEL_FS_IPV4_TCP:
23+
return MLX5E_TT_IPV4_TCP;
24+
default: /* ACCEL_FS_IPV6_TCP */
25+
return MLX5E_TT_IPV6_TCP;
26+
}
27+
}
28+
29+
static int accel_fs_tcp_add_default_rule(struct mlx5e_priv *priv,
30+
enum accel_fs_tcp_type type)
31+
{
32+
struct mlx5e_flow_table *accel_fs_t;
33+
struct mlx5_flow_destination dest;
34+
struct mlx5e_accel_fs_tcp *fs_tcp;
35+
MLX5_DECLARE_FLOW_ACT(flow_act);
36+
struct mlx5_flow_handle *rule;
37+
int err = 0;
38+
39+
fs_tcp = priv->fs.accel_tcp;
40+
accel_fs_t = &fs_tcp->tables[type];
41+
42+
dest = mlx5e_ttc_get_default_dest(priv, fs_accel2tt(type));
43+
rule = mlx5_add_flow_rules(accel_fs_t->t, NULL, &flow_act, &dest, 1);
44+
if (IS_ERR(rule)) {
45+
err = PTR_ERR(rule);
46+
netdev_err(priv->netdev,
47+
"%s: add default rule failed, accel_fs type=%d, err %d\n",
48+
__func__, type, err);
49+
return err;
50+
}
51+
52+
fs_tcp->default_rules[type] = rule;
53+
return 0;
54+
}
55+
56+
#define MLX5E_ACCEL_FS_TCP_NUM_GROUPS (2)
57+
#define MLX5E_ACCEL_FS_TCP_GROUP1_SIZE (BIT(16) - 1)
58+
#define MLX5E_ACCEL_FS_TCP_GROUP2_SIZE (BIT(0))
59+
#define MLX5E_ACCEL_FS_TCP_TABLE_SIZE (MLX5E_ACCEL_FS_TCP_GROUP1_SIZE +\
60+
MLX5E_ACCEL_FS_TCP_GROUP2_SIZE)
61+
static int accel_fs_tcp_create_groups(struct mlx5e_flow_table *ft,
62+
enum accel_fs_tcp_type type)
63+
{
64+
int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
65+
void *outer_headers_c;
66+
int ix = 0;
67+
u32 *in;
68+
int err;
69+
u8 *mc;
70+
71+
ft->g = kcalloc(MLX5E_ACCEL_FS_TCP_NUM_GROUPS, sizeof(*ft->g), GFP_KERNEL);
72+
in = kvzalloc(inlen, GFP_KERNEL);
73+
if (!in || !ft->g) {
74+
kvfree(ft->g);
75+
kvfree(in);
76+
return -ENOMEM;
77+
}
78+
79+
mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria);
80+
outer_headers_c = MLX5_ADDR_OF(fte_match_param, mc, outer_headers);
81+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, ip_protocol);
82+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, ip_version);
83+
84+
switch (type) {
85+
case ACCEL_FS_IPV4_TCP:
86+
case ACCEL_FS_IPV6_TCP:
87+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, tcp_dport);
88+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c, tcp_sport);
89+
break;
90+
default:
91+
err = -EINVAL;
92+
goto out;
93+
}
94+
95+
switch (type) {
96+
case ACCEL_FS_IPV4_TCP:
97+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c,
98+
src_ipv4_src_ipv6.ipv4_layout.ipv4);
99+
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, outer_headers_c,
100+
dst_ipv4_dst_ipv6.ipv4_layout.ipv4);
101+
break;
102+
case ACCEL_FS_IPV6_TCP:
103+
memset(MLX5_ADDR_OF(fte_match_set_lyr_2_4, outer_headers_c,
104+
src_ipv4_src_ipv6.ipv6_layout.ipv6),
105+
0xff, 16);
106+
memset(MLX5_ADDR_OF(fte_match_set_lyr_2_4, outer_headers_c,
107+
dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
108+
0xff, 16);
109+
break;
110+
default:
111+
err = -EINVAL;
112+
goto out;
113+
}
114+
115+
MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS);
116+
MLX5_SET_CFG(in, start_flow_index, ix);
117+
ix += MLX5E_ACCEL_FS_TCP_GROUP1_SIZE;
118+
MLX5_SET_CFG(in, end_flow_index, ix - 1);
119+
ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
120+
if (IS_ERR(ft->g[ft->num_groups]))
121+
goto err;
122+
ft->num_groups++;
123+
124+
/* Default Flow Group */
125+
memset(in, 0, inlen);
126+
MLX5_SET_CFG(in, start_flow_index, ix);
127+
ix += MLX5E_ACCEL_FS_TCP_GROUP2_SIZE;
128+
MLX5_SET_CFG(in, end_flow_index, ix - 1);
129+
ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in);
130+
if (IS_ERR(ft->g[ft->num_groups]))
131+
goto err;
132+
ft->num_groups++;
133+
134+
kvfree(in);
135+
return 0;
136+
137+
err:
138+
err = PTR_ERR(ft->g[ft->num_groups]);
139+
ft->g[ft->num_groups] = NULL;
140+
out:
141+
kvfree(in);
142+
143+
return err;
144+
}
145+
146+
static int accel_fs_tcp_create_table(struct mlx5e_priv *priv, enum accel_fs_tcp_type type)
147+
{
148+
struct mlx5e_flow_table *ft = &priv->fs.accel_tcp->tables[type];
149+
struct mlx5_flow_table_attr ft_attr = {};
150+
int err;
151+
152+
ft->num_groups = 0;
153+
154+
ft_attr.max_fte = MLX5E_ACCEL_FS_TCP_TABLE_SIZE;
155+
ft_attr.level = MLX5E_ACCEL_FS_TCP_FT_LEVEL;
156+
ft_attr.prio = MLX5E_NIC_PRIO;
157+
158+
ft->t = mlx5_create_flow_table(priv->fs.ns, &ft_attr);
159+
if (IS_ERR(ft->t)) {
160+
err = PTR_ERR(ft->t);
161+
ft->t = NULL;
162+
return err;
163+
}
164+
165+
netdev_dbg(priv->netdev, "Created fs accel table id %u level %u\n",
166+
ft->t->id, ft->t->level);
167+
168+
err = accel_fs_tcp_create_groups(ft, type);
169+
if (err)
170+
goto err;
171+
172+
err = accel_fs_tcp_add_default_rule(priv, type);
173+
if (err)
174+
goto err;
175+
176+
return 0;
177+
err:
178+
mlx5e_destroy_flow_table(ft);
179+
return err;
180+
}
181+
182+
static int accel_fs_tcp_disable(struct mlx5e_priv *priv)
183+
{
184+
int err, i;
185+
186+
for (i = 0; i < ACCEL_FS_TCP_NUM_TYPES; i++) {
187+
/* Modify ttc rules destination to point back to the indir TIRs */
188+
err = mlx5e_ttc_fwd_default_dest(priv, fs_accel2tt(i));
189+
if (err) {
190+
netdev_err(priv->netdev,
191+
"%s: modify ttc[%d] default destination failed, err(%d)\n",
192+
__func__, fs_accel2tt(i), err);
193+
return err;
194+
}
195+
}
196+
197+
return 0;
198+
}
199+
200+
static int accel_fs_tcp_enable(struct mlx5e_priv *priv)
201+
{
202+
struct mlx5_flow_destination dest = {};
203+
int err, i;
204+
205+
dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
206+
for (i = 0; i < ACCEL_FS_TCP_NUM_TYPES; i++) {
207+
dest.ft = priv->fs.accel_tcp->tables[i].t;
208+
209+
/* Modify ttc rules destination to point on the accel_fs FTs */
210+
err = mlx5e_ttc_fwd_dest(priv, fs_accel2tt(i), &dest);
211+
if (err) {
212+
netdev_err(priv->netdev,
213+
"%s: modify ttc[%d] destination to accel failed, err(%d)\n",
214+
__func__, fs_accel2tt(i), err);
215+
return err;
216+
}
217+
}
218+
return 0;
219+
}
220+
221+
static void accel_fs_tcp_destroy_table(struct mlx5e_priv *priv, int i)
222+
{
223+
struct mlx5e_accel_fs_tcp *fs_tcp;
224+
225+
fs_tcp = priv->fs.accel_tcp;
226+
if (IS_ERR_OR_NULL(fs_tcp->tables[i].t))
227+
return;
228+
229+
mlx5_del_flow_rules(fs_tcp->default_rules[i]);
230+
mlx5e_destroy_flow_table(&fs_tcp->tables[i]);
231+
fs_tcp->tables[i].t = NULL;
232+
}
233+
234+
void mlx5e_accel_fs_tcp_destroy(struct mlx5e_priv *priv)
235+
{
236+
int i;
237+
238+
if (!priv->fs.accel_tcp)
239+
return;
240+
241+
accel_fs_tcp_disable(priv);
242+
243+
for (i = 0; i < ACCEL_FS_TCP_NUM_TYPES; i++)
244+
accel_fs_tcp_destroy_table(priv, i);
245+
246+
kfree(priv->fs.accel_tcp);
247+
priv->fs.accel_tcp = NULL;
248+
}
249+
250+
int mlx5e_accel_fs_tcp_create(struct mlx5e_priv *priv)
251+
{
252+
int i, err;
253+
254+
if (!MLX5_CAP_FLOWTABLE_NIC_RX(priv->mdev, ft_field_support.outer_ip_version))
255+
return -EOPNOTSUPP;
256+
257+
priv->fs.accel_tcp = kzalloc(sizeof(*priv->fs.accel_tcp), GFP_KERNEL);
258+
if (!priv->fs.accel_tcp)
259+
return -ENOMEM;
260+
261+
for (i = 0; i < ACCEL_FS_TCP_NUM_TYPES; i++) {
262+
err = accel_fs_tcp_create_table(priv, i);
263+
if (err)
264+
goto err_destroy_tables;
265+
}
266+
267+
err = accel_fs_tcp_enable(priv);
268+
if (err)
269+
goto err_destroy_tables;
270+
271+
return 0;
272+
273+
err_destroy_tables:
274+
while (--i >= 0)
275+
accel_fs_tcp_destroy_table(priv, i);
276+
277+
kfree(priv->fs.accel_tcp);
278+
priv->fs.accel_tcp = NULL;
279+
return err;
280+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2+
/* Copyright (c) 2020, Mellanox Technologies inc. All rights reserved. */
3+
4+
#ifndef __MLX5E_ACCEL_FS_TCP_H__
5+
#define __MLX5E_ACCEL_FS_TCP_H__
6+
7+
#include "en.h"
8+
9+
#ifdef CONFIG_MLX5_EN_TLS
10+
int mlx5e_accel_fs_tcp_create(struct mlx5e_priv *priv);
11+
void mlx5e_accel_fs_tcp_destroy(struct mlx5e_priv *priv);
12+
#else
13+
static inline int mlx5e_accel_fs_tcp_create(struct mlx5e_priv *priv) { return 0; }
14+
static inline void mlx5e_accel_fs_tcp_destroy(struct mlx5e_priv *priv) {}
15+
#endif
16+
17+
#endif /* __MLX5E_ACCEL_FS_TCP_H__ */
18+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@
105105
#define ETHTOOL_PRIO_NUM_LEVELS 1
106106
#define ETHTOOL_NUM_PRIOS 11
107107
#define ETHTOOL_MIN_LEVEL (KERNEL_MIN_LEVEL + ETHTOOL_NUM_PRIOS)
108-
/* Vlan, mac, ttc, inner ttc, aRFS */
109-
#define KERNEL_NIC_PRIO_NUM_LEVELS 5
108+
/* Vlan, mac, ttc, inner ttc, {aRFS/accel} */
109+
#define KERNEL_NIC_PRIO_NUM_LEVELS 6
110110
#define KERNEL_NIC_NUM_PRIOS 1
111111
/* One more level for tc */
112112
#define KERNEL_MIN_LEVEL (KERNEL_NIC_PRIO_NUM_LEVELS + 1)

0 commit comments

Comments
 (0)