Skip to content

Commit e467b28

Browse files
Lior Nahmansondavem330
authored andcommitted
net/mlx5e: Add MACsec TX steering rules
Tx flow steering consists of two flow tables (FTs). The first FT (crypto table) has two fixed rules: One default miss rule so non MACsec offloaded packets bypass the MACSec tables, another rule to make sure that MACsec key exchange (MKE) traffic passes unencrypted as expected (matched of ethertype). On each new MACsec offload flow, a new MACsec rule is added. This rule is matched on metadata_reg_a (which contains the id of the flow) and invokes the MACsec offload action on match. The second FT (check table) has two fixed rules: One rule for verifying that the previous offload actions were finished successfully and packet need to be transmitted. Another default rule for dropping packets that were failed in the offload actions. The MACsec FTs should be created on demand when the first MACsec rule is added and destroyed when the last MACsec rule is deleted. Signed-off-by: Lior Nahmanson <[email protected]> Reviewed-by: Raed Salem <[email protected]> Signed-off-by: Raed Salem <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ee534d7 commit e467b28

File tree

5 files changed

+770
-15
lines changed

5 files changed

+770
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mlx5_core-$(CONFIG_MLX5_CORE_IPOIB) += ipoib/ipoib.o ipoib/ethtool.o ipoib/ipoib
9292
#
9393
mlx5_core-$(CONFIG_MLX5_FPGA) += fpga/cmd.o fpga/core.o fpga/conn.o fpga/sdk.o
9494

95-
mlx5_core-$(CONFIG_MLX5_EN_MACSEC) += en_accel/macsec.o
95+
mlx5_core-$(CONFIG_MLX5_EN_MACSEC) += en_accel/macsec.o en_accel/macsec_fs.o
9696

9797
mlx5_core-$(CONFIG_MLX5_EN_IPSEC) += en_accel/ipsec.o en_accel/ipsec_rxtx.o \
9898
en_accel/ipsec_stats.o en_accel/ipsec_fs.o \

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

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "en.h"
88
#include "lib/mlx5.h"
99
#include "en_accel/macsec.h"
10+
#include "en_accel/macsec_fs.h"
1011

1112
#define MLX5_MACSEC_ASO_INC_SN 0x2
1213
#define MLX5_MACSEC_ASO_REG_C_4_5 0x2
@@ -18,9 +19,12 @@ struct mlx5e_macsec_sa {
1819
u32 enc_key_id;
1920
u32 next_pn;
2021
sci_t sci;
22+
23+
struct mlx5e_macsec_tx_rule *tx_rule;
2124
};
2225

2326
struct mlx5e_macsec {
27+
struct mlx5e_macsec_fs *macsec_fs;
2428
struct mlx5e_macsec_sa *tx_sa[MACSEC_NUM_AN];
2529
struct mutex lock; /* Protects mlx5e_macsec internal contexts */
2630

@@ -90,18 +94,26 @@ static void mlx5e_macsec_destroy_object(struct mlx5_core_dev *mdev, u32 macsec_o
9094
mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
9195
}
9296

93-
static void mlx5e_macsec_cleanup_object(struct mlx5e_macsec *macsec,
94-
struct mlx5e_macsec_sa *sa)
97+
static void mlx5e_macsec_cleanup_sa(struct mlx5e_macsec *macsec, struct mlx5e_macsec_sa *sa)
9598
{
99+
100+
if (!sa->tx_rule)
101+
return;
102+
103+
mlx5e_macsec_fs_del_rule(macsec->macsec_fs, sa->tx_rule,
104+
MLX5_ACCEL_MACSEC_ACTION_ENCRYPT);
96105
mlx5e_macsec_destroy_object(macsec->mdev, sa->macsec_obj_id);
106+
sa->tx_rule = NULL;
97107
}
98108

99-
static int mlx5e_macsec_init_object(struct macsec_context *ctx,
100-
struct mlx5e_macsec_sa *sa,
101-
bool encrypt)
109+
static int mlx5e_macsec_init_sa(struct macsec_context *ctx,
110+
struct mlx5e_macsec_sa *sa,
111+
bool encrypt)
102112
{
103113
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
104114
struct mlx5e_macsec *macsec = priv->macsec;
115+
struct mlx5_macsec_rule_attrs rule_attrs;
116+
struct mlx5e_macsec_tx_rule *tx_rule;
105117
struct mlx5_core_dev *mdev = priv->mdev;
106118
struct mlx5_macsec_obj_attrs obj_attrs;
107119
int err;
@@ -116,7 +128,21 @@ static int mlx5e_macsec_init_object(struct macsec_context *ctx,
116128
if (err)
117129
return err;
118130

131+
rule_attrs.macsec_obj_id = sa->macsec_obj_id;
132+
rule_attrs.action = MLX5_ACCEL_MACSEC_ACTION_ENCRYPT;
133+
134+
tx_rule = mlx5e_macsec_fs_add_rule(macsec->macsec_fs, ctx, &rule_attrs);
135+
if (IS_ERR_OR_NULL(tx_rule))
136+
goto destroy_macsec_object;
137+
138+
sa->tx_rule = tx_rule;
139+
119140
return 0;
141+
142+
destroy_macsec_object:
143+
mlx5e_macsec_destroy_object(mdev, sa->macsec_obj_id);
144+
145+
return err;
120146
}
121147

122148
static int mlx5e_macsec_add_txsa(struct macsec_context *ctx)
@@ -168,7 +194,7 @@ static int mlx5e_macsec_add_txsa(struct macsec_context *ctx)
168194
!tx_sa->active)
169195
goto out;
170196

171-
err = mlx5e_macsec_init_object(ctx, tx_sa, tx_sc->encrypt);
197+
err = mlx5e_macsec_init_sa(ctx, tx_sa, tx_sc->encrypt);
172198
if (err)
173199
goto destroy_encryption_key;
174200

@@ -228,15 +254,17 @@ static int mlx5e_macsec_upd_txsa(struct macsec_context *ctx)
228254
goto out;
229255

230256
if (ctx_tx_sa->active) {
231-
err = mlx5e_macsec_init_object(ctx, tx_sa, tx_sc->encrypt);
257+
err = mlx5e_macsec_init_sa(ctx, tx_sa, tx_sc->encrypt);
232258
if (err)
233259
goto out;
234260
} else {
235-
mlx5e_macsec_cleanup_object(macsec, tx_sa);
261+
if (!tx_sa->tx_rule)
262+
return -EINVAL;
263+
264+
mlx5e_macsec_cleanup_sa(macsec, tx_sa);
236265
}
237266

238267
tx_sa->active = ctx_tx_sa->active;
239-
240268
out:
241269
mutex_unlock(&macsec->lock);
242270

@@ -246,7 +274,6 @@ static int mlx5e_macsec_upd_txsa(struct macsec_context *ctx)
246274
static int mlx5e_macsec_del_txsa(struct macsec_context *ctx)
247275
{
248276
struct mlx5e_priv *priv = netdev_priv(ctx->netdev);
249-
struct mlx5_core_dev *mdev = priv->mdev;
250277
u8 assoc_num = ctx->sa.assoc_num;
251278
struct mlx5e_macsec_sa *tx_sa;
252279
struct mlx5e_macsec *macsec;
@@ -266,10 +293,8 @@ static int mlx5e_macsec_del_txsa(struct macsec_context *ctx)
266293
goto out;
267294
}
268295

269-
mlx5e_macsec_cleanup_object(macsec, tx_sa);
270-
271-
mlx5_destroy_encryption_key(mdev, tx_sa->enc_key_id);
272-
296+
mlx5e_macsec_cleanup_sa(macsec, tx_sa);
297+
mlx5_destroy_encryption_key(macsec->mdev, tx_sa->enc_key_id);
273298
kfree(tx_sa);
274299
macsec->tx_sa[assoc_num] = NULL;
275300

@@ -334,6 +359,7 @@ int mlx5e_macsec_init(struct mlx5e_priv *priv)
334359
{
335360
struct mlx5_core_dev *mdev = priv->mdev;
336361
struct mlx5e_macsec *macsec = NULL;
362+
struct mlx5e_macsec_fs *macsec_fs;
337363
int err;
338364

339365
if (!mlx5e_is_macsec_device(priv->mdev)) {
@@ -359,12 +385,21 @@ int mlx5e_macsec_init(struct mlx5e_priv *priv)
359385

360386
macsec->mdev = mdev;
361387

388+
macsec_fs = mlx5e_macsec_fs_init(mdev, priv->netdev);
389+
if (IS_ERR_OR_NULL(macsec_fs))
390+
goto err_out;
391+
392+
macsec->macsec_fs = macsec_fs;
393+
362394
mlx5_core_dbg(mdev, "MACsec attached to netdevice\n");
363395

364396
return 0;
365397

398+
err_out:
399+
mlx5_core_dealloc_pd(priv->mdev, macsec->aso_pdn);
366400
err_pd:
367401
kfree(macsec);
402+
priv->macsec = NULL;
368403
return err;
369404
}
370405

@@ -375,6 +410,8 @@ void mlx5e_macsec_cleanup(struct mlx5e_priv *priv)
375410
if (!macsec)
376411
return;
377412

413+
mlx5e_macsec_fs_cleanup(macsec->macsec_fs);
414+
378415
priv->macsec = NULL;
379416

380417
mlx5_core_dealloc_pd(priv->mdev, macsec->aso_pdn);

0 commit comments

Comments
 (0)