Skip to content

Commit 6e12526

Browse files
Jianbo Liukuba-moo
Jianbo Liu
authored andcommitted
net/mlx5e: Refactor IPsec RX tables creation and destruction
Add attribute for IPsec RX creation, so rx_create() can be used by eswitch in later patch. And move the code for TTC dest connect/disconnect, which are needed only in NIC mode, to individual functions. Signed-off-by: Jianbo Liu <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Link: https://lore.kernel.org/r/87478d928479b6a4eee41901204546ea05741815.1690802064.git.leon@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f5c5abc commit 6e12526

File tree

2 files changed

+80
-31
lines changed

2 files changed

+80
-31
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ struct mlx5e_ipsec_aso {
169169
spinlock_t lock;
170170
};
171171

172+
struct mlx5e_ipsec_rx_create_attr {
173+
struct mlx5_flow_namespace *ns;
174+
struct mlx5_ttc_table *ttc;
175+
u32 family;
176+
int prio;
177+
int pol_level;
178+
int sa_level;
179+
int status_level;
180+
enum mlx5_flow_namespace_type chains_ns;
181+
};
182+
172183
struct mlx5e_ipsec {
173184
struct mlx5_core_dev *mdev;
174185
struct xarray sadb;

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,19 @@ static int ipsec_miss_create(struct mlx5_core_dev *mdev,
249249
return err;
250250
}
251251

252+
static void ipsec_rx_ft_disconnect(struct mlx5e_ipsec *ipsec, u32 family)
253+
{
254+
struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(ipsec->fs, false);
255+
256+
mlx5_ttc_fwd_default_dest(ttc, family2tt(family));
257+
}
258+
252259
static void rx_destroy(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
253260
struct mlx5e_ipsec_rx *rx, u32 family)
254261
{
255-
struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(ipsec->fs, false);
256262

257263
/* disconnect */
258-
mlx5_ttc_fwd_default_dest(ttc, family2tt(family));
264+
ipsec_rx_ft_disconnect(ipsec, family);
259265

260266
if (rx->chains) {
261267
ipsec_chains_destroy(rx->chains);
@@ -277,41 +283,78 @@ static void rx_destroy(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
277283
mlx5_ipsec_fs_roce_rx_destroy(ipsec->roce, family);
278284
}
279285

286+
static void ipsec_rx_create_attr_set(struct mlx5e_ipsec *ipsec,
287+
struct mlx5e_ipsec_rx *rx,
288+
u32 family,
289+
struct mlx5e_ipsec_rx_create_attr *attr)
290+
{
291+
attr->ns = mlx5e_fs_get_ns(ipsec->fs, false);
292+
attr->ttc = mlx5e_fs_get_ttc(ipsec->fs, false);
293+
attr->family = family;
294+
attr->prio = MLX5E_NIC_PRIO;
295+
attr->pol_level = MLX5E_ACCEL_FS_POL_FT_LEVEL;
296+
attr->sa_level = MLX5E_ACCEL_FS_ESP_FT_LEVEL;
297+
attr->status_level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL;
298+
attr->chains_ns = MLX5_FLOW_NAMESPACE_KERNEL;
299+
}
300+
301+
static int ipsec_rx_status_pass_dest_get(struct mlx5e_ipsec *ipsec,
302+
struct mlx5e_ipsec_rx *rx,
303+
struct mlx5e_ipsec_rx_create_attr *attr,
304+
struct mlx5_flow_destination *dest)
305+
{
306+
struct mlx5_flow_table *ft;
307+
int err;
308+
309+
*dest = mlx5_ttc_get_default_dest(attr->ttc, family2tt(attr->family));
310+
err = mlx5_ipsec_fs_roce_rx_create(ipsec->mdev, ipsec->roce, attr->ns, dest,
311+
attr->family, MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL,
312+
attr->prio);
313+
if (err)
314+
return err;
315+
316+
ft = mlx5_ipsec_fs_roce_ft_get(ipsec->roce, attr->family);
317+
if (ft) {
318+
dest->type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
319+
dest->ft = ft;
320+
}
321+
322+
return 0;
323+
}
324+
325+
static void ipsec_rx_ft_connect(struct mlx5e_ipsec *ipsec,
326+
struct mlx5e_ipsec_rx *rx,
327+
struct mlx5e_ipsec_rx_create_attr *attr)
328+
{
329+
struct mlx5_flow_destination dest = {};
330+
331+
dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
332+
dest.ft = rx->ft.pol;
333+
mlx5_ttc_fwd_dest(attr->ttc, family2tt(attr->family), &dest);
334+
}
335+
280336
static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
281337
struct mlx5e_ipsec_rx *rx, u32 family)
282338
{
283-
struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(ipsec->fs, false);
284-
struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(ipsec->fs, false);
285-
struct mlx5_flow_destination default_dest;
339+
struct mlx5e_ipsec_rx_create_attr attr;
286340
struct mlx5_flow_destination dest[2];
287341
struct mlx5_flow_table *ft;
288342
u32 flags = 0;
289343
int err;
290344

291-
default_dest = mlx5_ttc_get_default_dest(ttc, family2tt(family));
292-
err = mlx5_ipsec_fs_roce_rx_create(mdev, ipsec->roce, ns, &default_dest,
293-
family, MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL,
294-
MLX5E_NIC_PRIO);
345+
ipsec_rx_create_attr_set(ipsec, rx, family, &attr);
346+
347+
err = ipsec_rx_status_pass_dest_get(ipsec, rx, &attr, &dest[0]);
295348
if (err)
296349
return err;
297350

298-
ft = ipsec_ft_create(ns, MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
299-
MLX5E_NIC_PRIO, 1, 0);
351+
ft = ipsec_ft_create(attr.ns, attr.status_level, attr.prio, 1, 0);
300352
if (IS_ERR(ft)) {
301353
err = PTR_ERR(ft);
302354
goto err_fs_ft_status;
303355
}
304-
305356
rx->ft.status = ft;
306357

307-
ft = mlx5_ipsec_fs_roce_ft_get(ipsec->roce, family);
308-
if (ft) {
309-
dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
310-
dest[0].ft = ft;
311-
} else {
312-
dest[0] = default_dest;
313-
}
314-
315358
dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
316359
dest[1].counter_id = mlx5_fc_id(rx->fc->cnt);
317360
err = ipsec_status_rule(mdev, rx, dest);
@@ -323,8 +366,7 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
323366
rx->allow_tunnel_mode = mlx5_eswitch_block_encap(mdev);
324367
if (rx->allow_tunnel_mode)
325368
flags = MLX5_FLOW_TABLE_TUNNEL_EN_REFORMAT;
326-
ft = ipsec_ft_create(ns, MLX5E_ACCEL_FS_ESP_FT_LEVEL, MLX5E_NIC_PRIO, 2,
327-
flags);
369+
ft = ipsec_ft_create(attr.ns, attr.sa_level, attr.prio, 2, flags);
328370
if (IS_ERR(ft)) {
329371
err = PTR_ERR(ft);
330372
goto err_fs_ft;
@@ -337,9 +379,9 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
337379

338380
if (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_PRIO) {
339381
rx->chains = ipsec_chains_create(mdev, rx->ft.sa,
340-
MLX5_FLOW_NAMESPACE_KERNEL,
341-
MLX5E_NIC_PRIO,
342-
MLX5E_ACCEL_FS_POL_FT_LEVEL,
382+
attr.chains_ns,
383+
attr.prio,
384+
attr.pol_level,
343385
&rx->ft.pol);
344386
if (IS_ERR(rx->chains)) {
345387
err = PTR_ERR(rx->chains);
@@ -349,8 +391,7 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
349391
goto connect;
350392
}
351393

352-
ft = ipsec_ft_create(ns, MLX5E_ACCEL_FS_POL_FT_LEVEL, MLX5E_NIC_PRIO,
353-
2, 0);
394+
ft = ipsec_ft_create(attr.ns, attr.pol_level, attr.prio, 2, 0);
354395
if (IS_ERR(ft)) {
355396
err = PTR_ERR(ft);
356397
goto err_pol_ft;
@@ -365,10 +406,7 @@ static int rx_create(struct mlx5_core_dev *mdev, struct mlx5e_ipsec *ipsec,
365406

366407
connect:
367408
/* connect */
368-
memset(dest, 0x00, sizeof(*dest));
369-
dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
370-
dest[0].ft = rx->ft.pol;
371-
mlx5_ttc_fwd_dest(ttc, family2tt(family), &dest[0]);
409+
ipsec_rx_ft_connect(ipsec, rx, &attr);
372410
return 0;
373411

374412
err_pol_miss:

0 commit comments

Comments
 (0)