From: Cosmin Ratiu The MACsec protocol marker will soon move to flow_tag and that will make TC offload unusable at the same time as MACsec on the same device. Block TC offload while MACsec RX rules exist on the device. Only RX rules need this: the RX marker will move to flow_tag in the next patches, while TX keeps using WQE metadata and is unaffected. The block is held per RX rule, so TC and MACsec RX decryption cannot be active at the same time, but TX-only MACsec configurations continue to coexist with TC offload. One extra bit of logic is in macsec_upd_secy_hw_address(), where existing macsec rules are drained then readded. During the two loops it's possible a mistimed TC filter add to throw a wrench into things and prevent the 2nd loop from adding anything, since accel rules are now blocked. Fix that by keeping TC blocked across the operation, taken before the first RX rule is drained. Without RX rules, TC isn't blocked. Signed-off-by: Cosmin Ratiu Reviewed-by: Carolina Jubran Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/macsec.c | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c index 13896e9c1d33..146f1036dba4 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c @@ -10,6 +10,7 @@ #include "en.h" #include "lib/aso.h" #include "lib/crypto.h" +#include "en_accel/en_accel.h" #include "en_accel/macsec.h" #define MLX5_MACSEC_EPN_SCOPE_MID 0x80000000L @@ -325,6 +326,8 @@ static void mlx5e_macsec_cleanup_sa_fs(struct mlx5e_macsec *macsec, mlx5_macsec_fs_del_rule(macsec->mdev->macsec_fs, sa->macsec_rule, action, netdev, fs_id); sa->macsec_rule = NULL; + if (!is_tx) + mlx5e_accel_unblock_tc_offload(macsec->mdev); } static void mlx5e_macsec_cleanup_sa(struct mlx5e_macsec *macsec, @@ -344,6 +347,7 @@ static int mlx5e_macsec_init_sa_fs(struct macsec_context *ctx, const struct macsec_tx_sc *tx_sc = &ctx->secy->tx_sc; struct mlx5_macsec_rule_attrs rule_attrs; union mlx5_macsec_rule *macsec_rule; + int err = 0; if (is_tx && tx_sc->encoding_sa != sa->assoc_num) return 0; @@ -354,13 +358,26 @@ static int mlx5e_macsec_init_sa_fs(struct macsec_context *ctx, rule_attrs.action = (is_tx) ? MLX5_ACCEL_MACSEC_ACTION_ENCRYPT : MLX5_ACCEL_MACSEC_ACTION_DECRYPT; + if (!is_tx) { + err = mlx5e_accel_block_tc_offload(priv->mdev); + if (err) + return err; + } + macsec_rule = mlx5_macsec_fs_add_rule(macsec_fs, ctx, &rule_attrs, fs_id); - if (!macsec_rule) - return -ENOMEM; + if (!macsec_rule) { + err = -ENOMEM; + goto out_unblock_tc; + } sa->macsec_rule = macsec_rule; return 0; + +out_unblock_tc: + if (!is_tx) + mlx5e_accel_unblock_tc_offload(priv->mdev); + return err; } static int mlx5e_macsec_init_sa(struct macsec_context *ctx, @@ -1135,10 +1152,11 @@ static int macsec_upd_secy_hw_address(struct macsec_context *ctx, const struct net_device *dev = ctx->secy->netdev; struct mlx5e_macsec *macsec = priv->macsec; struct mlx5e_macsec_rx_sc *rx_sc, *tmp; + struct mlx5_core_dev *mdev = priv->mdev; struct mlx5e_macsec_sa *rx_sa; struct list_head *list; int i, err = 0; - + bool block_tc = false; list = &macsec_device->macsec_rx_sc_list_head; list_for_each_entry_safe(rx_sc, tmp, list, rx_sc_list_element) { @@ -1147,6 +1165,11 @@ static int macsec_upd_secy_hw_address(struct macsec_context *ctx, if (!rx_sa || !rx_sa->macsec_rule) continue; + /* Keep TC blocked while RX rules are rebuilt. Can't + * fail: this SA's rule already holds a TC block. + */ + if (!block_tc) + block_tc = !mlx5e_accel_block_tc_offload(mdev); mlx5e_macsec_cleanup_sa_fs(macsec, rx_sa, false, ctx->secy->netdev, rx_sc->sc_xarray_element->fs_id); } @@ -1169,6 +1192,8 @@ static int macsec_upd_secy_hw_address(struct macsec_context *ctx, memcpy(macsec_device->dev_addr, dev->dev_addr, dev->addr_len); out: + if (block_tc) + mlx5e_accel_unblock_tc_offload(mdev); return err; } -- 2.44.0